From 5586c8f1898e726d368115a113bf05a03d7c488e Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sun, 19 Jan 2020 16:05:05 +0800 Subject: [PATCH] android:add mask for DoricActivity,show loading view --- .../main/java/pub/doric/DoricFragment.java | 10 +++++++ .../java/pub/doric/DoricPanelFragment.java | 28 +++++++++++++++++++ .../src/main/res/layout/doric_activity.xml | 17 +++++++++-- .../src/main/res/layout/doric_fragment.xml | 17 ++++++----- 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/DoricFragment.java b/doric-android/doric/src/main/java/pub/doric/DoricFragment.java index 3d7f5661..24a21c4c 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricFragment.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricFragment.java @@ -19,6 +19,7 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.FrameLayout; import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; @@ -43,6 +44,8 @@ public class DoricFragment extends Fragment { return fragment; } + private View maskView = null; + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -69,6 +72,13 @@ public class DoricFragment extends Fragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + if (this.maskView != null) { + FrameLayout maskView = view.findViewById(R.id.doric_mask); + maskView.addView(this.maskView); + } } + public void setMaskView(View view) { + this.maskView = view; + } } diff --git a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java index adc9c57e..b02682b2 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java @@ -16,6 +16,8 @@ package pub.doric; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -26,6 +28,9 @@ import androidx.fragment.app.Fragment; import androidx.navigation.NavController; import androidx.navigation.Navigation; +import java.util.concurrent.Callable; + +import pub.doric.async.AsyncCall; import pub.doric.async.AsyncResult; import pub.doric.loader.DoricJSLoaderManager; import pub.doric.navbar.BaseDoricNavBar; @@ -39,6 +44,7 @@ import pub.doric.utils.DoricLog; */ public class DoricPanelFragment extends Fragment implements IDoricNavigator { private DoricPanel doricPanel; + private Handler uiHandler = new Handler(Looper.getMainLooper()); @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -50,6 +56,7 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (doricPanel == null) { + showLoadingMask(); doricPanel = view.findViewById(R.id.doric_panel); Bundle argument = getArguments(); if (argument == null) { @@ -72,6 +79,7 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { context.setDoricNavigator(DoricPanelFragment.this); BaseDoricNavBar navBar = requireActivity().getWindow().getDecorView().findViewById(R.id.doric_nav_bar); context.setDoricNavBar(navBar); + hideLoadingMask(); } @Override @@ -135,4 +143,24 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { doricPanel.onActivityDestroy(); } } + + private void hideLoadingMask() { + AsyncCall.ensureRunInHandler(uiHandler, new Callable() { + @Override + public Object call() { + requireActivity().getWindow().getDecorView().findViewById(R.id.doric_mask).setVisibility(View.GONE); + return null; + } + }); + } + + private void showLoadingMask() { + AsyncCall.ensureRunInHandler(uiHandler, new Callable() { + @Override + public Object call() { + requireActivity().getWindow().getDecorView().findViewById(R.id.doric_mask).setVisibility(View.VISIBLE); + return null; + } + }); + } } diff --git a/doric-android/doric/src/main/res/layout/doric_activity.xml b/doric-android/doric/src/main/res/layout/doric_activity.xml index 54b71a1b..11345c56 100644 --- a/doric-android/doric/src/main/res/layout/doric_activity.xml +++ b/doric-android/doric/src/main/res/layout/doric_activity.xml @@ -1,5 +1,16 @@ - \ No newline at end of file + android:layout_height="match_parent" + android:orientation="vertical"> + + + + + \ No newline at end of file diff --git a/doric-android/doric/src/main/res/layout/doric_fragment.xml b/doric-android/doric/src/main/res/layout/doric_fragment.xml index 539a884b..7b6d46f5 100644 --- a/doric-android/doric/src/main/res/layout/doric_fragment.xml +++ b/doric-android/doric/src/main/res/layout/doric_fragment.xml @@ -1,14 +1,8 @@ - - - + android:layout_height="match_parent"> - \ No newline at end of file + + \ No newline at end of file