android.support.v7.view.ContextThemeWrapper Java Examples

The following examples show how to use android.support.v7.view.ContextThemeWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PreferenceActivity.java    From Color-picker-library with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //apply activity's theme if dark theme is enabled
    themeWrapper = new ContextThemeWrapper(getBaseContext(), this.getTheme());

    Preferences.applyTheme(themeWrapper, getBaseContext());

    setContentView(R.layout.preference_activity);

    //provide back navigation
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    if (getFragmentManager().findFragmentById(R.id.content_frame) == null) {

        SettingsFragment settingsFragment = new SettingsFragment();
        getFragmentManager().beginTransaction().replace(R.id.content_frame, settingsFragment).commit();
    }

}
 
Example #2
Source File: SubredditListView.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), new ColorPreferences(inflater.getContext()).getThemeSubreddit(where));
    View v = ((LayoutInflater) contextThemeWrapper.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.fragment_verticalcontent, container, false);

    rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final RecyclerView.LayoutManager mLayoutManager = new PreCachingLayoutManager(getActivity());

    rv.setLayoutManager(mLayoutManager);
    rv.setItemAnimator(new SlideUpAlphaAnimator().withInterpolator(new LinearOutSlowInInterpolator()));

    mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("no sub", getContext()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    doAdapter();

    return v;
}
 
Example #3
Source File: CommentPage.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = this.getArguments();
    subreddit = bundle.getString("subreddit", "");
    fullname = bundle.getString("id", "");
    page = bundle.getInt("page", 0);
    single = bundle.getBoolean("single", false);
    context = bundle.getString("context", "");
    contextNumber = bundle.getInt("contextNumber", 5);
    np = bundle.getBoolean("np", false);
    archived = bundle.getBoolean("archived", false);
    locked = bundle.getBoolean("locked", false);
    contest = bundle.getBoolean("contest", false);

    loadMore = (!context.isEmpty() && !context.equals(Reddit.EMPTY_STRING));
    if (!single) loadMore = false;
    int subredditStyle = new ColorPreferences(getActivity()).getThemeSubreddit(subreddit);
    contextThemeWrapper = new ContextThemeWrapper(getActivity(), subredditStyle);
    mLayoutManager = new PreCachingLayoutManagerComments(getActivity());
}
 
Example #4
Source File: ChooserDialog.java    From android-file-chooser with Apache License 2.0 6 votes vote down vote up
private void init(@Nullable @StyleRes Integer fileChooserTheme) {
    _onBackPressed = new defBackPressed(this);

    if (fileChooserTheme == null) {
        TypedValue typedValue = new TypedValue();
        if (!this._context.getTheme().resolveAttribute(
            R.attr.fileChooserStyle, typedValue, true)) {
            this._context = new ContextThemeWrapper(this._context, R.style.FileChooserStyle);
        } else {
            this._context = new ContextThemeWrapper(this._context, typedValue.resourceId);
        }
    } else {
        //noinspection UnnecessaryUnboxing
        this._context = new ContextThemeWrapper(this._context, fileChooserTheme.intValue());
    }
}
 
Example #5
Source File: PandroidCompatViewFactory.java    From pandroid with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressLint("RestrictedApi")
public View onCreateView(String name, Context context, AttributeSet attrs) {
    final Resources.Theme theme = context.getTheme();
    switch (name) {
        case "Button":
            return new PandroidCompatButton(new ContextThemeWrapper(context, theme), attrs);
        case "EditText":
            return new PandroidCompatEditText(new ContextThemeWrapper(context, theme), attrs);
        case "RadioButton":
            return new PandroidCompatEditText(new ContextThemeWrapper(context, theme), attrs);
        case "Switch":
            return new PandroidCompatSwitch(new ContextThemeWrapper(context, theme), attrs);
        case "TextView":
            return new PandroidCompatTextView(new ContextThemeWrapper(context, theme), attrs);
        case "ToggleButton":
            return new ToggleButton(new ContextThemeWrapper(context, theme), attrs);
        default:
            return null;
    }
}
 
Example #6
Source File: SettingsFragment.java    From TvAppRepo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    if (preference.getKey().equals("delete_all")) {
        File myDownloads = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DOWNLOADS);
        // Add them to a list first before we sort them.
        deleteApks(myDownloads);
        Toast.makeText(getActivity(), R.string.downloaded_files_deleted, Toast.LENGTH_SHORT).show();
    } else if (preference.getKey().equals("build_variant")) {
        new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.dialog_theme))
                .setTitle(R.string.title_app_variants)
                .setMessage(R.string.build_variant_explanation)
                .show();
    }
    return super.onPreferenceTreeClick(preference);
}
 
Example #7
Source File: TintManager.java    From timecat with Apache License 2.0 6 votes vote down vote up
public static TintManager get(Context context) {
    if (context == null) return null;

    if (context instanceof ContextThemeWrapper) {
        context = ((ContextThemeWrapper) context).getBaseContext();
    }
    if (context instanceof android.view.ContextThemeWrapper) {
        context = ((android.view.ContextThemeWrapper) context).getBaseContext();
    }
    TintManager tm = INSTANCE_CACHE.get(context);
    if (tm == null) {
        tm = new TintManager(context);
        INSTANCE_CACHE.put(context, tm);
        printLog("[get TintManager] create new TintManager.");
    }
    return tm;
}
 
Example #8
Source File: TintManager.java    From MagicaSakura with Apache License 2.0 6 votes vote down vote up
public static TintManager get(Context context) {
    if (context == null) return null;

    if (context instanceof ContextThemeWrapper) {
        context = ((ContextThemeWrapper) context).getBaseContext();
    }
    if (context instanceof android.view.ContextThemeWrapper) {
        context = ((android.view.ContextThemeWrapper) context).getBaseContext();
    }
    TintManager tm = INSTANCE_CACHE.get(context);
    if (tm == null) {
        tm = new TintManager(context);
        INSTANCE_CACHE.put(context, tm);
        printLog("[get TintManager] create new TintManager.");
    }
    return tm;
}
 
Example #9
Source File: InputExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 6 votes vote down vote up
private TextView getNewTextView(CharSequence text) {
    final TextView textView = new TextView(new ContextThemeWrapper(this.editorCore.getContext(), R.style.WysiwygEditText));
    addEditableStyling(textView);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    textView.setLayoutParams(params);
    if (!TextUtils.isEmpty(text)) {
        Spanned __ = Html.fromHtml(text.toString());
        CharSequence toReplace = noTrailingwhiteLines(__);
        textView.setText(toReplace);
        Linkify.addLinks(textView,Linkify.ALL);
    }

    if(this.lineSpacing != -1) {
        setLineSpacing(textView, this.lineSpacing);
    }
    return textView;
}
 
Example #10
Source File: BaseBottomSheetDialog.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final Context contextThemeWrapper = new ContextThemeWrapper(getContext(), getContext().getTheme());
    LayoutInflater themeAwareInflater = inflater.cloneInContext(contextThemeWrapper);
    View view = themeAwareInflater.inflate(layoutRes(), container, false);
    unbinder = ButterKnife.bind(this, view);
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override public void onGlobalLayout() {
            view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            View parent = getDialog().findViewById(R.id.design_bottom_sheet);
            if (parent != null) {
                bottomSheetBehavior = BottomSheetBehavior.from(parent);
                if (bottomSheetBehavior != null) {
                    bottomSheetBehavior.setBottomSheetCallback(bottomSheetCallback);
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                }
            }
        }
    });
    return view;
}
 
Example #11
Source File: JCUtils.java    From JCVideoPlayer with MIT License 5 votes vote down vote up
/**
 * Get AppCompatActivity from context
 *
 * @param context
 * @return AppCompatActivity if it's not null
 */
public static AppCompatActivity getAppCompActivity(Context context) {
    if (context == null) return null;
    if (context instanceof AppCompatActivity) {
        return (AppCompatActivity) context;
    } else if (context instanceof ContextThemeWrapper) {
        return getAppCompActivity(((ContextThemeWrapper) context).getBaseContext());
    }
    return null;
}
 
Example #12
Source File: ContextHelper.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
@NonNull
static Context getBaseContext(@NonNull View view) {
    Context context = view.getContext();
    if (context instanceof ContextThemeWrapper) {
        context = ((ContextThemeWrapper) view.getContext()).getBaseContext();
    } else if (context instanceof CalligraphyContextWrapper) {
        context = ((CalligraphyContextWrapper) view.getContext()).getBaseContext();
    }
    return context;
}
 
Example #13
Source File: ViewHelper.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
public static void setFastScrollColor(@Nullable RecyclerFastScroller fastScroll) {
    if (fastScroll == null) return;

    Context context = fastScroll.getContext();
    if (context instanceof ContextThemeWrapper) {
        context = ((ContextThemeWrapper) context).getBaseContext();
    }

    int accent = ColorHelper.getAttributeColor(context, R.attr.colorAccent);

    fastScroll.setBarColor(ColorHelper.setColorAlpha(accent, 0.8f));
    fastScroll.setHandleNormalColor(accent);
    fastScroll.setHandlePressedColor(ColorHelper.getDarkerColor(accent, 0.7f));
}
 
Example #14
Source File: ThemeOptionViewHolder.java    From Theming-Android with Apache License 2.0 5 votes vote down vote up
public void bind(final AppTheme appTheme, final OnThemeSelectedListener onThemeSelectedListener) {
    themeNameView.setText(appTheme.themeName());
    ContextThemeWrapper themedContext = new ContextThemeWrapper(this.context, appTheme.resId());

    int primaryColor = extractor.extractPrimaryColorFrom(themedContext);
    themeNameView.getBackground().setColorFilter(primaryColor, PorterDuff.Mode.MULTIPLY);

    themeNameView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onThemeSelectedListener.onThemeSelected(appTheme);
        }
    });

}
 
Example #15
Source File: TopListActivity.java    From ratebeer with GNU General Public License v3.0 5 votes vote down vote up
private <T> void setupAutoComplete(List<T> items, Action1<T> onClick) {
	SimpleAutoCompleteAdapter<T> adapter = new SimpleAutoCompleteAdapter<>(new ContextThemeWrapper(this, R.style.AppTheme_Dark), items);
	filterEdit.setAdapter(adapter);
	RxView.focusChanges(filterEdit)
			.filter(hasFocus -> hasFocus)
			.subscribe(f -> filterEdit.showDropDown());
	RxAutoCompleteTextView.itemClickEvents(filterEdit)
			.doOnNext(click -> ImeUtils.hideIme(filterEdit))
			.map(click -> adapter.getItem(click.position()))
			.subscribe(onClick);
	RxTextView.textChanges(filterEdit)
			.map(text -> text.length() > 0)
			.subscribe(RxView.visibility(clearFilterButton));
}
 
Example #16
Source File: StepperLayout.java    From android-material-stepper with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("RestrictedApi")
private void init(AttributeSet attrs, @AttrRes int defStyleAttr) {
    initDefaultValues();
    extractValuesFromAttributes(attrs, defStyleAttr);

    final Context context = getContext();

    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(context, context.getTheme());
    contextThemeWrapper.setTheme(mStepperLayoutTheme);

    LayoutInflater.from(contextThemeWrapper).inflate(R.layout.ms_stepper_layout, this, true);

    setOrientation(VERTICAL);

    bindViews();

    mPager.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return true;
        }
    });

    initNavigation();

    mDottedProgressBar.setVisibility(GONE);
    mProgressBar.setVisibility(GONE);
    mTabsContainer.setVisibility(GONE);
    mStepNavigation.setVisibility(mShowBottomNavigation ? View.VISIBLE : View.GONE);

    mStepperType = StepperTypeFactory.createType(mTypeIdentifier, this);
    mStepperFeedbackType = StepperFeedbackTypeFactory.createType(mFeedbackTypeMask, this);
}
 
Example #17
Source File: PreferencesChannelsSystemFragment.java    From notification-channel-compat with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstance, String rootPreferenceKey) {
    Context activityContext = getActivity();

    PreferenceManager preferenceManager = getPreferenceManager();
    preferenceManager.setSharedPreferencesName(NotificationChannelManagerHelper.SHARED_PREFERENCE_NAME);
    PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(activityContext);
    setPreferenceScreen(preferenceScreen);

    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(activityContext, R.style.PreferenceThemeOverlay);

    // We instance each Preference using our ContextThemeWrapper object
    PreferenceCategory preferenceCategory = new PreferenceCategory(contextThemeWrapper);
    getPreferenceScreen().addPreference(preferenceCategory);

    Preference systemPref = new Preference(contextThemeWrapper);
    systemPref.setTitle(R.string.notification_importance_blocked);
    systemPref.setSummary(R.string.write_settings);
    systemPref.setLayoutResource(R.layout.preference_goto_target);
    systemPref.setIcon(R.drawable.ic_error_outline);
    systemPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            NotificationChannelPreference.launchSystemNotificationsSettings(getContext(), null);
            return true;
        }
    });
    preferenceCategory.addPreference(systemPref);
}
 
Example #18
Source File: MxUtils.java    From MxVideoPlayer with Apache License 2.0 5 votes vote down vote up
static AppCompatActivity getAppComptActivity(Context context) {
    if (context == null) {
        return null;
    }
    if (context instanceof AppCompatActivity) {
        return (AppCompatActivity) context;
    } else if (context instanceof ContextThemeWrapper) {
        return getAppComptActivity(((ContextThemeWrapper)context).getBaseContext());
    }
    return null;
}
 
Example #19
Source File: SideFragment.java    From StarWars.Android with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootView = inflater.cloneInContext(new ContextThemeWrapper(getContext(), getTheme()))
            .inflate(R.layout.fragment_side, container, false);
    final Bundle args = getArguments();
    if (args != null) {
        mRootView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                                       int oldRight, int oldBottom) {
                v.removeOnLayoutChangeListener(this);
                int cx = args.getInt("cx");
                int cy = args.getInt("cy");
                // get the hypothenuse so the mRadius is from one corner to the other
                float radius = (float) Math.hypot(right, bottom);

                // Hardware-supported clipPath()
                // http://developer.android.com/guide/topics/graphics/hardware-accel.html
                if (Build.VERSION.SDK_INT >= 18) {
                    Animator reveal = createCheckoutRevealAnimator((ClipRevealFrame) v, cx, cy, 28f, radius);
                    reveal.start();
                } else {
                    removeOldSideFragment();
                }
            }
        });
    }

    ButterKnife.bind(this, mRootView);
    return mRootView;
}
 
Example #20
Source File: VideoDetailsFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
private Drawable getRemoteIndicatorDrawable(){
    Context castContext = new ContextThemeWrapper(getContext(), android.support.v7.mediarouter.R.style.Theme_MediaRouter);
    TypedArray a = castContext.obtainStyledAttributes(null,
            android.support.v7.mediarouter.R.styleable.MediaRouteButton, android.support.v7.mediarouter.R.attr.mediaRouteButtonStyle, 0);
    Drawable remoteIndicatorDrawable = a.getDrawable(
            android.support.v7.mediarouter.R.styleable.MediaRouteButton_externalRouteEnabledDrawable);
    a.recycle();
    return remoteIndicatorDrawable;
}
 
Example #21
Source File: SuggestionsRecyclerView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public SuggestionsRecyclerView(Context context, AttributeSet attrs) {
    super(new ContextThemeWrapper(context, R.style.NewTabPageRecyclerView), attrs);

    Resources res = getContext().getResources();
    setBackgroundColor(ApiCompatibilityUtils.getColor(res, R.color.ntp_bg));
    setLayoutParams(new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    setFocusable(true);
    setFocusableInTouchMode(true);
    setContentDescription(res.getString(R.string.accessibility_new_tab_page));

    mGestureDetector =
            new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    boolean retVal = super.onSingleTapUp(e);
                    requestFocus();
                    return retVal;
                }
            });
    mLayoutManager = new LinearLayoutManager(getContext());
    setLayoutManager(mLayoutManager);
    setHasFixedSize(true);

    ItemTouchHelper helper = new ItemTouchHelper(new ItemTouchCallbacks());
    helper.attachToRecyclerView(this);

    mScrollEventReporter = new SuggestionsMetrics.ScrollEventReporter();
    addOnScrollListener(mScrollEventReporter);
}
 
Example #22
Source File: SubredditView.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    //Hide the "Submit" menu item if the currently viewed sub is the frontpage or /r/all.
    if (subreddit.equals("frontpage") || subreddit.equals("all") || subreddit.equals("popular") || subreddit.equals("friends") || subreddit.equals("mod")) {
        menu.findItem(R.id.submit).setVisible(false);
        menu.findItem(R.id.sidebar).setVisible(false);
    }

    mToolbar.getMenu()
            .findItem(R.id.theme)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    int style = new ColorPreferences(SubredditView.this).getThemeSubreddit(
                            subreddit);
                    final Context contextThemeWrapper =
                            new ContextThemeWrapper(SubredditView.this, style);
                    LayoutInflater localInflater =
                            getLayoutInflater().cloneInContext(contextThemeWrapper);
                    final View dialoglayout = localInflater.inflate(R.layout.colorsub, null);
                    ArrayList<String> arrayList = new ArrayList<>();
                    arrayList.add(subreddit);
                    SettingsSubAdapter.showSubThemeEditor(arrayList, SubredditView.this,
                            dialoglayout);
                    return false;
                }
            });
    return true;
}
 
Example #23
Source File: SettingsSubAdapter.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
private void prepareAndShowSubEditor(String subreddit) {
    int style = new ColorPreferences(context).getThemeSubreddit(subreddit);
    final Context contextThemeWrapper = new ContextThemeWrapper(context, style);
    LayoutInflater localInflater = context.getLayoutInflater().cloneInContext(contextThemeWrapper);
    final View dialoglayout = localInflater.inflate(R.layout.colorsub, null);

    ArrayList<String> arrayList = new ArrayList<>();
    arrayList.add(subreddit);
    showSubThemeEditor(arrayList, context, dialoglayout);
}
 
Example #24
Source File: CafeBar.java    From cafebar with Apache License 2.0 5 votes vote down vote up
@NonNull
public static CafeBar make(@NonNull View to, @NonNull String content, @Duration int duration) {
    Context context = to.getContext();
    if (context instanceof ContextThemeWrapper) {
        context = ((ContextThemeWrapper) context).getBaseContext();
    }
    return create(context, to, content, duration);
}
 
Example #25
Source File: CafeBar.java    From cafebar with Apache License 2.0 5 votes vote down vote up
@NonNull
public static CafeBar make(@NonNull View to, @StringRes int res, @Duration int duration) {
    Context context = to.getContext();
    if (context instanceof ContextThemeWrapper) {
        context = ((ContextThemeWrapper) context).getBaseContext();
    }
    String string = context.getResources().getString(res);
    return create(context, to, string, duration);
}
 
Example #26
Source File: SettingsActivity.java    From Gallery-example with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    contextThemeWrapper = new ContextThemeWrapper(getBaseContext(), this.getTheme());
    Preferences.applyTheme(contextThemeWrapper, getBaseContext());

    setContentView(R.layout.preference_activity);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
            overridePendingTransition(0, 0);
        }
    });

    if (getFragmentManager().findFragmentById(R.id.content_frame) == null) {
        getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit();
    }
}
 
Example #27
Source File: ActivityUtils.java    From v9porn with MIT License 5 votes vote down vote up
private static AppCompatActivity getAppCompActivity(Context context) {
    if (context == null) {
        return null;
    }
    if (context instanceof AppCompatActivity) {
        return (AppCompatActivity) context;
    } else if (context instanceof ContextThemeWrapper) {
        return getAppCompActivity(((ContextThemeWrapper) context).getBaseContext());
    }
    return null;
}
 
Example #28
Source File: JZUtils.java    From JZVideoDemo with MIT License 5 votes vote down vote up
/**
 * Get AppCompatActivity from context
 *
 * @param context context
 * @return AppCompatActivity if it's not null
 */
public static AppCompatActivity getAppCompActivity(Context context) {
    if (context == null) return null;
    if (context instanceof AppCompatActivity) {
        return (AppCompatActivity) context;
    } else if (context instanceof ContextThemeWrapper) {
        return getAppCompActivity(((ContextThemeWrapper) context).getBaseContext());
    }
    return null;
}
 
Example #29
Source File: WindowUtil.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
/**
 * Get AppCompatActivity from context
 */
public static AppCompatActivity getAppCompActivity(Context context) {
    if (context == null) return null;
    if (context instanceof AppCompatActivity) {
        return (AppCompatActivity) context;
    } else if (context instanceof ContextThemeWrapper) {
        return getAppCompActivity(((ContextThemeWrapper) context).getBaseContext());
    }
    return null;
}
 
Example #30
Source File: JZUtils.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * Get AppCompatActivity from context
 *
 * @param context context
 * @return AppCompatActivity if it's not null
 */
public static AppCompatActivity getAppCompActivity(Context context) {
    if (context == null) return null;
    if (context instanceof AppCompatActivity) {
        return (AppCompatActivity) context;
    } else if (context instanceof ContextThemeWrapper) {
        return getAppCompActivity(((ContextThemeWrapper) context).getBaseContext());
    }
    return null;
}