diff --git a/app/src/main/java/com/gh/base/BaseActivity.java b/app/src/main/java/com/gh/base/BaseActivity.java index 212e03dd31..5fca77f8de 100644 --- a/app/src/main/java/com/gh/base/BaseActivity.java +++ b/app/src/main/java/com/gh/base/BaseActivity.java @@ -123,40 +123,9 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Easy @Override public void setContentView(View view) { if (BuildConfig.DEBUG || BuildConfig.BUILD_TIME != 0) { - RelativeLayout screenRootView = new RelativeLayout(this); - screenRootView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); - - LinearLayout ll = new LinearLayout(this); - TextView tv = new TextView(this); - String envText = "正式环境"; - if (BuildConfig.FLAVOR.equals("internal")) { - envText = "测试环境"; - } - tv.setText(envText); - tv.setGravity(Gravity.CENTER); - tv.setTextColor(Color.WHITE); - tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13); - tv.setBackground(ContextCompat.getDrawable(this, R.color.red)); - tv.measure(0, 0); - tv.setAlpha(0.15F); - int height = tv.getMeasuredHeight(); - int width = tv.getMeasuredWidth(); - tv.setPadding(DisplayUtils.dip2px(20), 0, DisplayUtils.dip2px(20), 0); - ll.setTranslationX(DisplayUtils.dip2px(20)); - ll.setRotation(45); - ll.addView(tv); - ll.setPadding(0, (width - height) / 2, 0, (width - height) / 2); - - screenRootView.addView(view); - screenRootView.addView(ll); - - RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) ll.getLayoutParams(); - lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - - super.setContentView(screenRootView); - } else { - super.setContentView(view); + view = getRootViewWithEnvIndicator(view); } + super.setContentView(view); } @Override @@ -193,6 +162,40 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Easy } } + private View getRootViewWithEnvIndicator(View view) { + RelativeLayout screenRootView = new RelativeLayout(this); + screenRootView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); + + LinearLayout ll = new LinearLayout(this); + TextView tv = new TextView(this); + String envText = "正式环境"; + if (BuildConfig.FLAVOR.equals("internal")) { + envText = "测试环境"; + } + tv.setText(envText); + tv.setGravity(Gravity.CENTER); + tv.setTextColor(Color.WHITE); + tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13); + tv.setBackground(ContextCompat.getDrawable(this, R.color.red)); + tv.measure(0, 0); + tv.setAlpha(0.15F); + int height = tv.getMeasuredHeight(); + int width = tv.getMeasuredWidth(); + tv.setPadding(DisplayUtils.dip2px(20), 0, DisplayUtils.dip2px(20), 0); + ll.setTranslationX(DisplayUtils.dip2px(20)); + ll.setRotation(45); + ll.addView(tv); + ll.setPadding(0, (width - height) / 2, 0, (width - height) / 2); + + screenRootView.addView(view); + screenRootView.addView(ll); + + RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) ll.getLayoutParams(); + lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); + return screenRootView; + } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(final EBShowDialog showDialog) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)