android:add api for costomization of DoricActivity

This commit is contained in:
pengfei.zhou 2020-01-21 10:45:55 +08:00 committed by osborn
parent 93a207db9f
commit 7c2af8d1aa
2 changed files with 29 additions and 5 deletions

View File

@ -26,17 +26,38 @@ import androidx.appcompat.app.AppCompatActivity;
* @CreateDate: 2019-11-19
*/
public class DoricActivity extends AppCompatActivity {
protected DoricFragment mDoricFragment;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.doric_activity);
if (savedInstanceState == null) {
String scheme = getIntent().getStringExtra("scheme");
String alias = getIntent().getStringExtra("alias");
DoricFragment doricFragment = DoricFragment.newInstance(scheme, alias);
mDoricFragment = DoricFragment.newInstance(getScheme(), getAlias(), getExtra());
getSupportFragmentManager().beginTransaction()
.add(R.id.container, doricFragment)
.add(R.id.container, mDoricFragment)
.commit();
}
}
/**
* @return Scheme for DoricFragment to load.
*/
protected String getScheme() {
return getIntent().getStringExtra("scheme");
}
/**
* @return Alias used for JS error message.
*/
protected String getAlias() {
return getIntent().getStringExtra("alias");
}
/**
* @return Extra data used for JS Panel in JSON format.
*/
protected String getExtra() {
return getIntent().getStringExtra("extra");
}
}

View File

@ -35,10 +35,11 @@ import androidx.navigation.Navigation;
*/
public class DoricFragment extends Fragment {
public static DoricFragment newInstance(String scheme, String alias) {
public static DoricFragment newInstance(String scheme, String alias, String extra) {
Bundle args = new Bundle();
args.putString("scheme", scheme);
args.putString("alias", alias);
args.putString("extra", extra);
DoricFragment fragment = new DoricFragment();
fragment.setArguments(args);
return fragment;
@ -73,6 +74,8 @@ public class DoricFragment extends Fragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host);
navController.setGraph(R.navigation.doric_navigation, getArguments());
FrameLayout maskView = view.findViewById(R.id.doric_mask);
if (this.loadingView != null) {
maskView.addView(this.loadingView);