Java Code Examples for android.app.Activity#getTheme()

The following examples show how to use android.app.Activity#getTheme() . 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: Utility.java    From Instagram-Profile-Downloader with MIT License 6 votes vote down vote up
public static void setActionBarColor(Activity activity) {
    Window window = activity.getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        TypedValue typedValue = new TypedValue();
        Resources.Theme theme = activity.getTheme();
        theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
        @ColorInt int color = typedValue.data;
        window.setStatusBarColor(color);
    }

}
 
Example 2
Source File: GsPreferenceFragmentCompat.java    From memetastic with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Deprecated
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Activity activity = getActivity();
    _appSettings = getAppSettings(activity);
    _cu = new ContextUtils(activity);
    getPreferenceManager().setSharedPreferencesName(getSharedPreferencesName());
    addPreferencesFromResource(getPreferenceResourceForInflation());


    if (activity != null && activity.getTheme() != null) {
        TypedArray array = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground});
        int bgcolor = array.getColor(0, 0xFFFFFFFF);
        _defaultIconTintColor = _cu.shouldColorOnTopBeLight(bgcolor) ? Color.WHITE : Color.BLACK;
    }

    // on bottom
    afterOnCreate(savedInstanceState, activity);
}
 
Example 3
Source File: GsPreferenceFragmentCompat.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
@Override
@Deprecated
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Activity activity = getActivity();
    _appSettings = getAppSettings(activity);
    _cu = new ContextUtils(activity);
    getPreferenceManager().setSharedPreferencesName(getSharedPreferencesName());
    addPreferencesFromResource(getPreferenceResourceForInflation());


    if (activity != null && activity.getTheme() != null) {
        TypedArray array = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground});
        int bgcolor = array.getColor(0, 0xFFFFFFFF);
        _defaultIconTintColor = _cu.shouldColorOnTopBeLight(bgcolor) ? Color.WHITE : Color.BLACK;
    }

    // on bottom
    afterOnCreate(savedInstanceState, activity);
}
 
Example 4
Source File: GsPreferenceFragmentCompat.java    From Stringlate with MIT License 6 votes vote down vote up
@Override
@Deprecated
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Activity activity = getActivity();
    _appSettings = getAppSettings(activity);
    _cu = new ContextUtils(activity);
    getPreferenceManager().setSharedPreferencesName(getSharedPreferencesName());
    addPreferencesFromResource(getPreferenceResourceForInflation());


    if (activity != null && activity.getTheme() != null) {
        TypedArray array = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground});
        int bgcolor = array.getColor(0, 0xFFFFFFFF);
        _defaultIconTintColor = _cu.shouldColorOnTopBeLight(bgcolor) ? Color.WHITE : Color.BLACK;
    }

    // on bottom
    afterOnCreate(savedInstanceState, activity);
}
 
Example 5
Source File: OwlViewContext.java    From NightOwl with Apache License 2.0 6 votes vote down vote up
public void setupWithCurrentActivity(Activity activity){
    Resources.Theme theme = activity.getTheme();
    TypedArray a = theme.obtainStyledAttributes(R.styleable.NightOwl_Theme);
    if (a != null) {
        if ( !checkBeforeLollipop() ){
            if ( a.hasValue(R.styleable.NightOwl_Theme_night_navigationBarColor) )
                registerObserver(new NavBarObserver(activity, a, R.styleable.NightOwl_Theme_night_navigationBarColor));
            if ( a.hasValue(R.styleable.NightOwl_Theme_night_statusBarColor) )
                registerObserver(new StatusBarObserver(activity, a, R.styleable.NightOwl_Theme_night_statusBarColor));
        }

        if ( a.hasValue(R.styleable.NightOwl_Theme_night_additionThemeDay)
                && a.hasValue(R.styleable.NightOwl_Theme_night_additionThemeNight) ){
            int themeDay = a.getResourceId(R.styleable.NightOwl_Theme_night_additionThemeDay,0 );
            int themeNight = a.getResourceId(R.styleable.NightOwl_Theme_night_additionThemeNight,0 );
            registerObserver(new AdditionThemeObserver(themeDay,themeNight));
        }
        a.recycle();
    }
}
 
Example 6
Source File: FloatingActionMenu.java    From android-floating-action-menu with Apache License 2.0 6 votes vote down vote up
public Builder(Activity context, int styleId) {
    this.activity = context;
    this.res = activity.getResources();

    Resources.Theme theme = context.getTheme();
    TypedArray array = theme.obtainStyledAttributes(styleId, R.styleable.FloatingActionMenu);

    this.threshold = array.getDimensionPixelSize(R.styleable.FloatingActionMenu_fam_threshold, 36);
    this.gap = array.getDimensionPixelSize(R.styleable.FloatingActionMenu_fam_gap, 12);
    this.horitontalPadding = array.getDimensionPixelSize(R.styleable.FloatingActionMenu_fam_horizontalPadding, 0);
    this.verticalPadding = array.getDimensionPixelSize(R.styleable.FloatingActionMenu_fam_verticalPadding, 0);
    this.gravity = array.getInt(R.styleable.FloatingActionMenu_fam_gravity, Gravity.RIGHT);
    this.direction = Direction.values()[array.getInt(
        R.styleable.FloatingActionMenu_fam_direction,
        Direction.Horizontal.ordinal())];
    this.animationDuration = array.getInt(R.styleable.FloatingActionMenu_android_animationDuration, 200);

    int resId = array.getResourceId(
        R.styleable.FloatingActionMenu_android_interpolator,
        android.R.anim.anticipate_overshoot_interpolator);
    this.interpolator = AnimationUtils.loadInterpolator(activity, resId);
    array.recycle();

    this.visible = true;
}
 
Example 7
Source File: GsPreferenceFragmentCompat.java    From kimai-android with MIT License 6 votes vote down vote up
@Override
@Deprecated
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Activity activity = getActivity();
    _appSettings = getAppSettings(activity);
    _cu = new ContextUtils(activity);
    getPreferenceManager().setSharedPreferencesName(getSharedPreferencesName());
    addPreferencesFromResource(getPreferenceResourceForInflation());


    if (activity != null && activity.getTheme() != null) {
        TypedArray array = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground});
        int bgcolor = array.getColor(0, 0xFFFFFFFF);
        _defaultIconTintColor = _cu.shouldColorOnTopBeLight(bgcolor) ? Color.WHITE : Color.BLACK;
    }

    // on bottom
    afterOnCreate(savedInstanceState, activity);
}
 
Example 8
Source File: ChangeModeController.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
/**
 * 获取某个属性的TypedValue
 * @param ctx 上下文
 * @param attr  属性id
 * @return
 */
public static TypedValue getAttrTypedValue(Activity ctx,int attr){
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = ctx.getTheme();
    theme.resolveAttribute(attr, typedValue, true);
    return typedValue;
}
 
Example 9
Source File: ChangeModeController.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
/**
 * 刷新 StatusBar
 * @param ctx  上下文
 */
private static void refreshStatusBar(Activity ctx) {
	if (Build.VERSION.SDK_INT >= 21) {
		TypedValue typedValue = new TypedValue();
		Resources.Theme theme = ctx.getTheme();
		theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
        ctx.getWindow().setStatusBarColor(ctx.getResources().getColor(typedValue.resourceId));
    }
}
 
Example 10
Source File: ResourceUtil.java    From JReadHub with GNU General Public License v3.0 4 votes vote down vote up
public static int getResource(@NonNull Activity activity, @AttrRes int resourceId) {
    Resources.Theme theme = activity.getTheme();
    TypedValue ta = new TypedValue();
    theme.resolveAttribute(resourceId, ta, true);
    return ta.resourceId;
}