de.mrapp.android.util.ThemeUtil Java Examples

The following examples show how to use de.mrapp.android.util.ThemeUtil. 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: TabSwitcherDrawable.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new drawable, which allows to display the number of tabs, which are currently
 * contained by a {@link TabSwitcher}.
 *
 * @param context
 *         The context, which should be used by the drawable, as an instance of the class {@link
 *         Context}. The context may not be null
 */
public TabSwitcherDrawable(@NonNull final Context context) {
    Condition.INSTANCE.ensureNotNull(context, "The context may not be null");
    Resources resources = context.getResources();
    size = resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_size);
    textSizeNormal =
            resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_normal);
    textSizeSmall =
            resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_small);
    background = ContextCompat.getDrawable(context, R.drawable.tab_switcher_drawable_background)
            .mutate();
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.WHITE);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(textSizeNormal);
    paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
    label = Integer.toString(0);
    int tint = ThemeUtil.getColor(context, android.R.attr.textColorPrimary);
    setColorFilter(tint, PorterDuff.Mode.MULTIPLY);
}
 
Example #2
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the resource id of the theme, which is used when using a specific layout. The theme
 * is obtained from a theme's attributes. If the theme is not specified, the resource id of the
 * default theme is returned.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @param themeResourceId
 *         The resource id of the theme, the resource id should be obtained from, as an {@link
 *         Integer} value or -1, if the global app theme should be used
 * @return The resource id of the theme, which is used when using the given layout, as an {@link
 * Integer} value
 */
private int obtainThemeFromThemeAttributes(@NonNull final Layout layout,
                                           final int themeResourceId) {
    int resourceId = layout == Layout.TABLET ? R.attr.tabSwitcherThemeTablet :
            R.attr.tabSwitcherThemePhone;
    int result = ThemeUtil.getResId(context, themeResourceId, resourceId, 0);

    if (result == 0) {
        result = ThemeUtil.getResId(context, R.attr.tabSwitcherThemeGlobal, 0);

        if (result == 0) {
            result = R.style.TabSwitcher_Light;
        }
    }

    return result;
}
 
Example #3
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the color, which corresponds to a specific theme attribute, regarding the theme,
 * which is used when using a specific layout.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @param resourceId
 *         The resource id of the theme attribute, the color should be obtained from, as an
 *         {@link Integer} value. The resource id must correspond to a valid theme attribute
 * @return The color, which has been obtained, as an {@link Integer} value
 */
@ColorInt
public int getColor(@NonNull final Layout layout, @AttrRes final int resourceId) {
    try {
        return ThemeUtil.getColor(context, resourceId);
    } catch (NotFoundException e1) {
        int themeResourceId = getThemeResourceId(layout);

        try {
            return ThemeUtil.getColor(context, themeResourceId, resourceId);
        } catch (NotFoundException e) {
            themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId);
            return ThemeUtil.getColor(context, themeResourceId, resourceId);
        }
    }
}
 
Example #4
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the color state list, which corresponds to a specific theme attribute, regarding the
 * theme, which is used when using a specific layout.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @param resourceId
 *         The resource id of the theme attribute, the color state list should be obtained from,
 *         as an {@link Integer} value. The resource id must correspond to a valid theme
 *         attribute
 * @return The color state list, which has been obtained, as an instance of the class {@link
 * ColorStateList}
 */
public ColorStateList getColorStateList(@NonNull final Layout layout,
                                        @AttrRes final int resourceId) {
    try {
        return ThemeUtil.getColorStateList(context, resourceId);
    } catch (NotFoundException e1) {
        int themeResourceId = getThemeResourceId(layout);

        try {
            return ThemeUtil.getColorStateList(context, themeResourceId, resourceId);
        } catch (NotFoundException e) {
            themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId);
            return ThemeUtil.getColorStateList(context, themeResourceId, resourceId);
        }
    }
}
 
Example #5
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the resource id, which corresponds to a specific theme attribute, regarding the
 * theme, which is used when using a specific layout.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @param resourceId
 *         The resource id of the theme attribute, the resource id should be obtained from, as
 *         an {@link Integer} value. The resource id must correspond to a valid theme attribute
 * @param defaultValue
 *         The default value, which should be returned, if the given resource id is invalid, as
 *         an {@link Integer} value
 * @return The resource id, which has been obtained, as an {@link Integer} value
 */
public int getResourceId(@NonNull final Layout layout, @AttrRes final int resourceId,
                         final int defaultValue) {
    int result = ThemeUtil.getResId(context, resourceId, 0);

    if (result == 0) {
        int themeResourceId = getThemeResourceId(layout);
        result = ThemeUtil.getResId(context, themeResourceId, resourceId, 0);

        if (result == 0) {
            themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId);
            return ThemeUtil.getResId(context, themeResourceId, resourceId, defaultValue);
        }
    }

    return result;
}
 
Example #6
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the integer value, which corresponds to a specific theme attribute, regarding the
 * theme, which is used when using a specific layout.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @param resourceId
 *         The resource id of the theme attribute, the integer value should be obtained from, as
 *         an {@link Integer} value. The resource id must correspond to a valid theme attribute
 * @param defaultValue
 *         The default value, which should be returned, if the given resource id is invalid, as
 *         an {@link Integer} value
 * @return The integer value, which has been obtained, as an {@link Integer} value
 */
public int getInteger(@NonNull final Layout layout, @AttrRes final int resourceId,
                      final int defaultValue) {
    int result = ThemeUtil.getInt(context, resourceId, 0);

    if (result == 0) {
        int themeResourceId = getThemeResourceId(layout);
        result = ThemeUtil.getInt(context, themeResourceId, resourceId, 0);

        if (result == 0) {
            themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId);
            return ThemeUtil.getInt(context, themeResourceId, resourceId, defaultValue);
        }
    }

    return result;
}
 
Example #7
Source File: PreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the background of the button bar from the activity's current theme.
 */
private void obtainButtonBarBackground() {
    try {
        int color =
                ThemeUtil.getColor(getActivity(), R.attr.restoreDefaultsButtonBarBackground);
        setButtonBarBackgroundColor(color);
    } catch (NotFoundException e) {
        int resourceId = ThemeUtil
                .getResId(getActivity(), R.attr.restoreDefaultsButtonBarBackground, -1);

        if (resourceId != -1) {
            setButtonBarBackground(resourceId);
        } else {
            setButtonBarBackgroundColor(
                    ContextCompat.getColor(getActivity(), R.color.button_bar_background_light));
        }
    }
}
 
Example #8
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the color of the dividers, which are contained by the navigation.
 */
private void obtainNavigationDividerColor() {
    int color;

    try {
        color = ThemeUtil.getColor(this, R.attr.navigationDividerColor);
    } catch (NotFoundException e) {
        color = ContextCompat.getColor(this, R.color.preference_divider_color_light);
    }

    setNavigationDividerColor(color);
}
 
Example #9
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the string, which is used to format the progress, which is shown, when the activity
 * is used as a wizard, from the activity's theme.
 */
private void obtainProgressFormat() {
    String progressFormat;

    try {
        progressFormat = ThemeUtil.getString(this, R.attr.progressFormat);
    } catch (NotFoundException e) {
        progressFormat = getString(R.string.progress_format);
    }

    setProgressFormat(progressFormat);
}
 
Example #10
Source File: RecyclerViewAdapterWrapper.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public final ViewHolderWrapper<VH> onCreateViewHolder(@NonNull final ViewGroup parent,
                                                      final int viewType) {
    VH viewHolder = wrappedAdapter.createViewHolder(parent, viewType);
    Context context = parent.getContext();
    FrameLayout frameLayout = new FrameLayout(context);
    frameLayout.setForeground(ThemeUtil.getDrawable(context, R.attr.selectableItemBackground));
    frameLayout.addView(viewHolder.itemView);
    frameLayout.setLayoutParams(
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT));
    return new ViewHolderWrapper<>(frameLayout, viewHolder);
}
 
Example #11
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the elevation of the activity's toolbar from the activity's theme.
 */
private void obtainToolbarElevation() {
    int elevation;

    try {
        elevation = ThemeUtil.getDimensionPixelSize(this, R.attr.toolbarElevation);
    } catch (NotFoundException e) {
        elevation = getResources().getDimensionPixelSize(R.dimen.toolbar_elevation);
    }

    setToolbarElevation(pixelsToDp(this, elevation));
}
 
Example #12
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the elevation of the toolbar, which is used to show the bread crumb of the currently
 * selected preference fragment, when using the split screen layout.
 */
private void obtainBreadcrumbElevation() {
    int elevation;

    try {
        elevation = ThemeUtil.getDimensionPixelSize(this, R.attr.breadCrumbElevation);
    } catch (NotFoundException e) {
        elevation = getResources().getDimensionPixelSize(R.dimen.bread_crumb_toolbar_elevation);
    }

    setBreadCrumbElevation(pixelsToDp(this, elevation));
}
 
Example #13
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the elevation of the card view, which contains the currently shown preference
 * fragment, when using the split screen layout, from the activity's theme.
 */
private void obtainCardViewElevation() {
    int elevation;

    try {
        elevation = ThemeUtil.getDimensionPixelSize(this, R.attr.cardViewElevation);
    } catch (NotFoundException e) {
        elevation = getResources().getDimensionPixelSize(R.dimen.card_view_elevation);
    }

    setCardViewElevation(pixelsToDp(this, elevation));
}
 
Example #14
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the elevation of the button bar, which is shown when using the activity as a wizard,
 * from the activity's theme.
 */
private void obtainButtonBarElevation() {
    int elevation;

    try {
        elevation = ThemeUtil.getDimensionPixelSize(this, R.attr.buttonBarElevation);
    } catch (NotFoundException e) {
        elevation = getResources().getDimensionPixelSize(R.dimen.button_bar_elevation);
    }

    setButtonBarElevation(pixelsToDp(this, elevation));
}
 
Example #15
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the background color of the card view, which contains the currently shown preference
 * fragment, when using the split screen layout, from the activity's theme.
 */
private void obtainCardViewBackgroundColor() {
    int color;

    try {
        color = ThemeUtil.getColor(this, R.attr.cardViewBackgroundColor);
    } catch (NotFoundException e) {
        color = ContextCompat.getColor(this, R.color.card_view_background_light);
    }

    setCardViewBackgroundColor(color);
}
 
Example #16
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the background color of the toolbar, which is used to show the bread crumb of the
 * currently selected navigation preference, when using the split screen layout, from the
 * activity's theme.
 */
private void obtainBreadCrumbBackgroundColor() {
    int color;

    try {
        color = ThemeUtil.getColor(this, R.attr.breadCrumbBackgroundColor);
    } catch (NotFoundException e) {
        color = ContextCompat.getColor(this, R.color.bread_crumb_background_light);
    }

    setBreadCrumbBackgroundColor(color);
}
 
Example #17
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the background of the button bar from the activity's theme.
 */
private void obtainButtonBarBackground() {
    try {
        setButtonBarBackgroundColor(ThemeUtil.getColor(this, R.attr.buttonBarBackground));
    } catch (NotFoundException e) {
        int resourceId = ThemeUtil.getResId(this, R.attr.buttonBarBackground, -1);

        if (resourceId != -1) {
            setButtonBarBackground(resourceId);
        } else {
            setButtonBarBackground(null);
        }
    }
}
 
Example #18
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the background of the navigation from the activity's theme.
 */
private void obtainNavigationBackground() {
    try {
        setNavigationBackgroundColor(ThemeUtil.getColor(this, R.attr.navigationBackground));
    } catch (NotFoundException e) {
        int resourceId = ThemeUtil.getResId(this, R.attr.navigationBackground, -1);

        if (resourceId != -1) {
            setNavigationBackground(resourceId);
        } else {
            setNavigationBackground(null);
        }
    }
}
 
Example #19
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the background color of the currently selected navigation preference from the
 * activity's theme.
 */
private void obtainNavigationSelectionColor() {
    int color;

    try {
        color = ThemeUtil.getColor(this, R.attr.navigationSelectionColor);
    } catch (NotFoundException e) {
        color = ContextCompat.getColor(this, R.color.preference_selection_color_light);
    }

    setNavigationSelectionColor(color);
}
 
Example #20
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the text of the next button from the activity's theme.
 */
private void obtainNextButtonText() {
    CharSequence text;

    try {
        text = ThemeUtil.getText(this, R.attr.nextButtonText);
    } catch (NotFoundException e) {
        text = getText(R.string.next_button_text);
    }

    setNextButtonText(text);
}
 
Example #21
Source File: WizardDialog.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the color of the tab indicator from a specific theme.
 *
 * @param themeResourceId
 *         The resource id of the theme, the color should be obtained from, as an {@link
 *         Integer} value
 */
private void obtainTabIndicatorColor(@StyleRes final int themeResourceId) {
    TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId,
            new int[]{R.attr.materialDialogTabIndicatorColor});
    int defaultColor =
            ThemeUtil.getColor(getContext(), themeResourceId, R.attr.colorAccent);
    setTabIndicatorColor(typedArray.getColor(0, defaultColor));
}
 
Example #22
Source File: WizardDialog.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the text color of the tabs from a specific theme.
 *
 * @param themeResourceId
 *         The resource id of the theme, the text color should be obtained from, as an
 *         {@link Integer} value
 */
private void obtainTabTextColor(@StyleRes final int themeResourceId) {
    TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId,
            new int[]{R.attr.materialDialogTabTextColor});
    int defaultColor = ThemeUtil
            .getColor(getContext(), themeResourceId, android.R.attr.textColorSecondary);
    setTabTextColor(typedArray.getColor(0, defaultColor));
}
 
Example #23
Source File: WizardDialog.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the selected text color of the tabs from a specific theme.
 *
 * @param themeResourceId
 *         The resource id of the theme, the text color should be obtained from, as an
 *         {@link Integer} value
 */
private void obtainTabSelectedTextColor(@StyleRes final int themeResourceId) {
    TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId,
            new int[]{R.attr.materialDialogTabSelectedTextColor});
    int defaultColor = ThemeUtil
            .getColor(getContext(), themeResourceId, android.R.attr.textColorSecondary);
    setTabSelectedTextColor(typedArray.getColor(0, defaultColor));
}
 
Example #24
Source File: WizardDialog.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the button text color from a specific theme.
 *
 * @param themeResourceId
 *         The resource id of the theme, the text color should be obtained from, as an
 *         {@link Integer} value
 */
private void obtainButtonTextColor(@StyleRes final int themeResourceId) {
    TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId,
            new int[]{R.attr.materialDialogButtonTextColor});
    int defaultColor =
            ThemeUtil.getColor(getContext(), themeResourceId, R.attr.colorAccent);
    setButtonTextColor(typedArray.getColor(0, defaultColor));
}
 
Example #25
Source File: ProgressDialog.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the color of the dialog's progress bar from a specific theme.
 *
 * @param themeResourceId
 *         The resource id of the theme, the color should be obtained from, as an {@link
 *         Integer} value
 */
private void obtainProgressBarColor(@StyleRes final int themeResourceId) {
    TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId,
            new int[]{R.attr.materialDialogProgressBarColor});
    int defaultColor =
            ThemeUtil.getColor(getContext(), themeResourceId, R.attr.colorAccent);
    setProgressBarColor(typedArray.getColor(0, defaultColor));
}
 
Example #26
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the text of the finish button from the activity's theme.
 */
private void obtainFinishButtonText() {
    CharSequence text;

    try {
        text = ThemeUtil.getText(this, R.attr.finishButtonText);
    } catch (NotFoundException e) {
        text = getText(R.string.finish_button_text);
    }

    setFinishButtonText(text);
}
 
Example #27
Source File: TabSwitcherButton.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the view.
 */
private void initialize() {
    drawable = new TabSwitcherDrawable(getContext());
    setImageDrawable(drawable);
    ViewUtil.setBackground(this,
            ThemeUtil.getDrawable(getContext(), R.attr.selectableItemBackgroundBorderless));
    setContentDescription(null);
    setClickable(true);
    setFocusable(true);
}
 
Example #28
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the drawable, which corresponds to a specific theme attribute, regarding the theme,
 * which is used when using a specific layout.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @param resourceId
 *         The resource id of the theme attribute, the drawable should be obtained from, as an
 *         {@link Integer} value. The resource id must correspond to a valid theme attribute
 * @return The color state list, which has been obtained, as an instance of the class {@link
 * ColorStateList}
 */
public Drawable getDrawable(@NonNull final Layout layout, @AttrRes final int resourceId) {
    try {
        return ThemeUtil.getDrawable(context, resourceId);
    } catch (NotFoundException e1) {
        int themeResourceId = getThemeResourceId(layout);

        try {
            return ThemeUtil.getDrawable(context, themeResourceId, resourceId);
        } catch (NotFoundException e) {
            themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId);
            return ThemeUtil.getDrawable(context, themeResourceId, resourceId);
        }
    }
}
 
Example #29
Source File: ThemeHelper.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the text, which corresponds to a specific theme attribute, regarding the theme, which
 * is used when using a specific layout.
 *
 * @param layout
 *         The layout as a value of the enum {@link Layout}. The layout may not be null
 * @param resourceId
 *         The resource id of the theme attribute, the text should be obtained from, as an
 *         {@link Integer} value. The resource id must correspond to a valid theme attribute
 * @return The text, which has been obtained, as an instance of the type {@link CharSequence}
 */
public CharSequence getText(@NonNull final Layout layout, @AttrRes final int resourceId) {
    try {
        return ThemeUtil.getText(context, resourceId);
    } catch (NotFoundException e1) {
        int themeResourceId = getThemeResourceId(layout);

        try {
            return ThemeUtil.getText(context, themeResourceId, resourceId);
        } catch (NotFoundException e) {
            themeResourceId = obtainThemeFromThemeAttributes(layout, themeResourceId);
            return ThemeUtil.getText(context, themeResourceId, resourceId);
        }
    }
}
 
Example #30
Source File: AbstractPreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the appearance of the dividers, which are shown above preference categories, from the
 * activity's theme.
 */
private void obtainDividerDecoration() {
    int dividerColor;

    try {
        dividerColor = ThemeUtil.getColor(getActivity(), R.attr.dividerColor);
    } catch (NotFoundException e) {
        dividerColor =
                ContextCompat.getColor(getActivity(), R.color.preference_divider_color_light);
    }

    this.dividerDecoration.setDividerColor(dividerColor);
    this.dividerDecoration.setDividerHeight(DisplayUtil.dpToPixels(getActivity(), 1));
}