public static LayoutInflater inject(Context context) { LayoutInflater inflater; if (context instanceof Activity) { inflater = ((Activity) context).getLayoutInflater(); } else { inflater = LayoutInflater.from(context); } BackgroundFactory factory = new BackgroundFactory(); if (context instanceof AppCompatActivity) { final AppCompatDelegate delegate = ((AppCompatActivity) context).getDelegate(); factory.setInterceptFactory(new LayoutInflater.Factory() { @Override public View onCreateView(String name, Context context, AttributeSet attrs) { return delegate.createView(null, name, context, attrs); } }); } inflater.setFactory2(factory); return inflater; }
@Override public void setContentView(View view, ViewGroup.LayoutParams params) { getDelegate().setContentView(view, params); }
@Nullable @Override public ActionBarDrawerToggle.Delegate getDrawerToggleDelegate() { return getDelegate().getDrawerToggleDelegate(); }
/** * Support library version of {@link android.app.Activity#getActionBar}. * * <p>Retrieve a reference to this activity's ActionBar. * * @return The Activity's ActionBar, or null if it does not have one. */ @Nullable public ActionBar getSupportActionBar() { return getDelegate().getSupportActionBar(); }
@SuppressWarnings("TypeParameterUnusedInFormals") @Override public <T extends View> T findViewById(@IdRes int id) { return getDelegate().findViewById(id); }
/** * Start an action mode. * * @param callback Callback that will manage lifecycle events for this context mode * @return The ContextMode that was started, or null if it was canceled */ @Nullable public ActionMode startSupportActionMode(@NonNull ActionMode.Callback callback) { return getDelegate().startSupportActionMode(callback); }
@Override public void setContentView(@LayoutRes int layoutResID) { getDelegate().setContentView(layoutResID); }
@Override protected void onPostCreate(@Nullable Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getDelegate().onPostCreate(savedInstanceState); }
@Override protected void onPostResume() { super.onPostResume(); getDelegate().onPostResume(); }
@Override protected void onTitleChanged(CharSequence title, int color) { super.onTitleChanged(title, color); getDelegate().setTitle(title); }
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); getDelegate().onSaveInstanceState(outState); }
@Override protected void onStart() { super.onStart(); getDelegate().onStart(); }
@Override protected void onStop() { super.onStop(); getDelegate().onStop(); }
public static void setInflaterFactory(LayoutInflater li, Activity activity) { LayoutInflaterCompat.setFactory(li, new InflationInterceptor( activity instanceof ATEActivity ? (ATEActivity) activity : null, li, activity instanceof AppCompatActivity ? ((AppCompatActivity) activity).getDelegate() : null)); }
@Override protected void onDestroy() { super.onDestroy(); getDelegate().onDestroy(); }
public static void setActionBarTextColor(AppCompatActivity activity, int color) { try { Object actionbar = ReflectionUtils.getField(activity.getDelegate(), "mActionBar"); View actionBarContent = (View) ReflectionUtils.getField(actionbar, "mContainerView"); View actionBarView = (View) ReflectionUtils.getField(actionBarContent, "mActionBarView"); TextView textView = (TextView) ReflectionUtils.getField(actionBarView, "mTitleTextView"); textView.setTextColor(color); } catch (Throwable e) { e.printStackTrace(); } } }
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); getDelegate().onConfigurationChanged(newConfig); if (mResources != null) { // The real (and thus managed) resources object was already updated // by ResourcesManager, so pull the current metrics from there. final DisplayMetrics newMetrics = super.getResources().getDisplayMetrics(); mResources.updateConfiguration(newConfig, newMetrics); } }
public static boolean isNightMode(AppCompatActivity activity) { int uiMode = activity.getResources().getConfiguration().uiMode; int dayNightUiMode = uiMode & Configuration.UI_MODE_NIGHT_MASK; if (SPUtils.getBoolean(MainActivity.CURRENT_NIGHT_MODE) && dayNightUiMode != Configuration.UI_MODE_NIGHT_YES) { activity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); activity.recreate(); return true; } return false; } }
public void applyNightModel(AppCompatActivity activity){ invokeResources(activity); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); activity.getDelegate().applyDayNight(); applyNewModel(); PersistenceUtils.setNightModel(activity.getApplicationContext(), true); ModelChangeManager.getInstance().notifyChange(true); }
public void applyDayModel(AppCompatActivity activity) { invokeResources(activity); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); activity.getDelegate().applyDayNight(); applyNewModel(); PersistenceUtils.setNightModel(activity.getApplicationContext(), false); ModelChangeManager.getInstance().notifyChange(false); }