androidx.annotation.StyleRes Java Examples

The following examples show how to use androidx.annotation.StyleRes. 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: Component.java    From litho with Apache License 2.0 6 votes vote down vote up
protected void init(
    ComponentContext c,
    @AttrRes int defStyleAttr,
    @StyleRes int defStyleRes,
    Component component) {
  mResourceResolver = c.getResourceResolver();
  mComponent = component;
  mContext = c;

  final Component owner = getOwner();
  if (owner != null) {
    mComponent.mOwnerGlobalKey = owner.getGlobalKey();
  }

  if (defStyleAttr != 0 || defStyleRes != 0) {
    mComponent.getOrCreateCommonProps().setStyle(defStyleAttr, defStyleRes);
    component.loadStyle(c, defStyleAttr, defStyleRes);
  }
  mComponent.setBuilderContext(c.getAndroidContext());
}
 
Example #2
Source File: ThemeUtils.java    From call_manage with MIT License 6 votes vote down vote up
public static @StyleRes
int themeTransparentStatusBarFromId(String themeId) {
    switch (themeId) {
        case "light;pink":
            return R.style.AppTheme_Light_Pink_TransparentStatusBar;
        case "light;green":
            return R.style.AppTheme_Light_Green_TransparentStatusBar;
        case "light;cream":
            return R.style.AppTheme_Light_Cream_TransparentStatusBar;
        case "dark;pink":
            return R.style.AppTheme_Dark_Pink_TransparentStatusBar;
        case "dark;green":
            return R.style.AppTheme_Dark_Green_TransparentStatusBar;
        case "dark;cream":
            return R.style.AppTheme_Dark_Cream_TransparentStatusBar;
        case "amoled;pink":
            return R.style.AppTheme_AMOLED_Pink_TransparentStatusBar;
        case "amoled;green":
            return R.style.AppTheme_AMOLED_Green_TransparentStatusBar;
        case "amoled;cream":
            return R.style.AppTheme_AMOLED_Cream_TransparentStatusBar;
    }
    return R.style.AppTheme_Light_Pink_TransparentStatusBar;
}
 
Example #3
Source File: DatePickerDialog.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
private DatePickerDialog(@NonNull Context context, @StyleRes int themeResId,
                         @Nullable OnDateSetListener listener, @Nullable Calendar calendar, int year,
                         int monthOfYear, int dayOfMonth) {
    super(context, resolveDialogTheme(context, themeResId));

    final Context themeContext = getContext();
    final LayoutInflater inflater = LayoutInflater.from(themeContext);
    final View view = inflater.inflate(R.layout.date_picker_dialog, null);
    setView(view);

    setButton(BUTTON_POSITIVE, themeContext.getString(android.R.string.ok), this);
    setButton(BUTTON_NEGATIVE, themeContext.getString(android.R.string.cancel), this);
    // FIXME ? setButtonPanelLayoutHint(LAYOUT_HINT_SIDE);

    if (calendar != null) {
        year = calendar.get(Calendar.YEAR);
        monthOfYear = calendar.get(Calendar.MONTH);
        dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
    }

    mDatePicker = view.findViewById(R.id.datePicker);
    mDatePicker.init(year, monthOfYear, dayOfMonth, this);
    mDatePicker.setValidationCallback(mValidationCallback);

    mDateSetListener = listener;
}
 
Example #4
Source File: CalendarView.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CalendarView(@NonNull Context context, @Nullable AttributeSet attrs,
                    @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    attrHandler(context, attrs, defStyleAttr, defStyleRes);
    /*final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.CalendarView, defStyleAttr, defStyleRes);
    final int mode = a.getInt(R.styleable.CalendarView_calendarViewMode, MODE_HOLO);
    a.recycle();

    switch (mode) {
        case MODE_HOLO:
            mDelegate = new CalendarViewLegacyDelegate(
                    this, context, attrs, defStyleAttr, defStyleRes);
            break;
        case MODE_MATERIAL:
            mDelegate = new CalendarViewMaterialDelegate(
                    this, context, attrs, defStyleAttr, defStyleRes);
            break;
        default:
            throw new IllegalArgumentException("invalid calendarViewMode attribute");
    }*/
}
 
Example #5
Source File: ThemeUtils.java    From call_manage with MIT License 6 votes vote down vote up
public static @StyleRes
int themeNoActionBarFromId(String themeId) {
    switch (themeId) {
        case "light;pink":
            return R.style.AppTheme_Light_Pink_NoActionBar;
        case "light;green":
            return R.style.AppTheme_Light_Green_NoActionBar;
        case "light;cream":
            return R.style.AppTheme_Light_Cream_NoActionBar;
        case "dark;pink":
            return R.style.AppTheme_Dark_Pink_NoActionBar;
        case "dark;green":
            return R.style.AppTheme_Dark_Green_NoActionBar;
        case "dark;cream":
            return R.style.AppTheme_Dark_Cream_NoActionBar;
        case "amoled;pink":
            return R.style.AppTheme_AMOLED_Pink_NoActionBar;
        case "amoled;green":
            return R.style.AppTheme_AMOLED_Green_NoActionBar;
        case "amoled;cream":
            return R.style.AppTheme_AMOLED_Cream_NoActionBar;
    }
    return R.style.AppTheme_Light_Pink_NoActionBar;
}
 
Example #6
Source File: ThemeUtils.java    From call_manage with MIT License 6 votes vote down vote up
public static @StyleRes
int themeNormalFromId(String themeId) {
    switch (themeId) {
        case "light;pink":
            return R.style.AppTheme_Light_Pink;
        case "light;cream":
            return R.style.AppTheme_Light_Cream;
        case "light;green":
            return R.style.AppTheme_Light_Green;
        case "dark;pink":
            return R.style.AppTheme_Dark_Pink;
        case "dark;green":
            return R.style.AppTheme_Dark_Green;
        case "dark;cream":
            return R.style.AppTheme_Dark_Cream;
        case "amoled;pink":
            return R.style.AppTheme_AMOLED_Pink;
        case "amoled;green":
            return R.style.AppTheme_AMOLED_Green;
        case "amoled;cream":
            return R.style.AppTheme_AMOLED_Cream;
    }
    return R.style.AppTheme_Light_Pink;
}
 
Example #7
Source File: InternalNodeUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
static void applyStyles(InternalNode node, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
  if (defStyleAttr != 0 || defStyleRes != 0) {
    ComponentContext c = node.getContext();

    // TODO: (T55170222) Pass the styles through the InternalNode instead of mutating the context.
    c.setDefStyle(defStyleAttr, defStyleRes);

    final TypedArray typedArray =
        c.getAndroidContext()
            .obtainStyledAttributes(null, R.styleable.ComponentLayout, defStyleAttr, defStyleRes);
    node.applyAttributes(typedArray);
    typedArray.recycle();

    // TODO: (T55170222) Not required if styles are passed through the InternalNode.
    c.setDefStyle(0, 0);
  }
}
 
Example #8
Source File: TestDrawableComponent.java    From litho with Apache License 2.0 6 votes vote down vote up
public static Builder create(
    ComponentContext context,
    @AttrRes int defStyleAttr,
    @StyleRes int defStyleRes,
    boolean callsShouldUpdateOnMount,
    boolean isPureRender,
    boolean canMeasure,
    boolean implementsAccessibility) {
  return create(
      context,
      defStyleAttr,
      defStyleRes,
      callsShouldUpdateOnMount,
      isPureRender,
      canMeasure,
      implementsAccessibility,
      false);
}
 
Example #9
Source File: DynamicTheme.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize colors from the supplied local dynamic app theme.
 *
 * @param localTheme The local theme resource to initialize colors.
 * @param dynamicLocalTheme The local dynamic app theme to initialize colors.
 *
 * @return The {@link DynamicTheme} object to allow for chaining of calls to set methods.
 */
public @NonNull DynamicTheme setLocalTheme(@StyleRes int localTheme,
        @Nullable DynamicAppTheme dynamicLocalTheme) {
    if (dynamicLocalTheme != null) {
        if (dynamicLocalTheme.getThemeRes() == DynamicResourceUtils.ADS_DEFAULT_RESOURCE_ID) {
            throw new IllegalStateException("Dynamic app theme style resource " +
                    "id is not found for the application theme.");
        }

        setLocalThemeRes(dynamicLocalTheme.getThemeRes(), dynamicLocalTheme);
    } else {
        setLocalThemeRes(localTheme, null);
    }

    return this;
}
 
Example #10
Source File: StarkSpinner.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
public StarkSpinner(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    mContext = context;
    getAttributeSet(attrs, defStyleAttr, defStyleRes);

    final LayoutInflater factory = LayoutInflater.from(context);
    factory.inflate(R.layout.view_stark_spinner, this, true);

    mSpinnerListContainer = (LinearLayout) factory.inflate(R.layout.view_list, this, false);
    mSpinnerListView = (ListView) mSpinnerListContainer.findViewById(R.id.LstVw_SpinnerListView);
    if (mListItemDivider != null) {
        mSpinnerListView.setDivider(mListItemDivider);
        mSpinnerListView.setDividerHeight(mListDividerSize);
    }
    mEmptyTextView = (TextView) mSpinnerListContainer.findViewById(R.id.TxtVw_EmptyText);
    mSpinnerListView.setEmptyView(mEmptyTextView);
}
 
Example #11
Source File: StarkSpinner.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
private void getAttributeSet(@Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    if (attrs != null) {
        try {
            TypedArray attributes = mContext.getTheme().obtainStyledAttributes(attrs, R.styleable.StarkSpinner, defStyleAttr, defStyleRes);
            mRevealViewBackgroundColor = attributes.getColor(R.styleable.StarkSpinner_RevealViewBackgroundColor, Color.WHITE);
            mStartEditTintColor = attributes.getColor(R.styleable.StarkSpinner_StartSearchTintColor, Color.GRAY);
            mEditViewBackgroundColor = attributes.getColor(R.styleable.StarkSpinner_SearchViewBackgroundColor, Color.WHITE);
            mEditViewTextColor = attributes.getColor(R.styleable.StarkSpinner_SearchViewTextColor, Color.BLACK);
            mDoneEditTintColor = attributes.getColor(R.styleable.StarkSpinner_DoneSearchTintColor, Color.GRAY);
            mBordersSize = attributes.getDimensionPixelSize(R.styleable.StarkSpinner_BordersSize, 4);
            mExpandSize = attributes.getDimensionPixelSize(R.styleable.StarkSpinner_SpinnerExpandHeight, 0);
            mShowBorders = attributes.getBoolean(R.styleable.StarkSpinner_ShowBorders, false);
            mBoarderColor = attributes.getColor(R.styleable.StarkSpinner_BoarderColor, Color.GRAY);
            mAnimDuration = attributes.getColor(R.styleable.StarkSpinner_AnimDuration, DefaultAnimationDuration);
            mKeepLastSearch = attributes.getBoolean(R.styleable.StarkSpinner_KeepLastSearch, false);
            mRevealEmptyText = attributes.getString(R.styleable.StarkSpinner_RevealEmptyText);
            mSearchHintText = attributes.getString(R.styleable.StarkSpinner_SearchHintText);
            mNoItemsFoundText = attributes.getString(R.styleable.StarkSpinner_NoItemsFoundText);
            mListItemDivider = attributes.getDrawable(R.styleable.StarkSpinner_ItemsDivider);
            mListDividerSize = attributes.getDimensionPixelSize(R.styleable.StarkSpinner_DividerHeight, 0);
        } catch (UnsupportedOperationException e) {
            Log.e("SearchableSpinner", "getAttributeSet --> " + e.getLocalizedMessage());
        }
    }
}
 
Example #12
Source File: TestLayoutComponent.java    From litho with Apache License 2.0 5 votes vote down vote up
public static Builder create(
    ComponentContext context,
    @AttrRes int defStyleAttr,
    @StyleRes int defStyleRes,
    boolean callsShouldUpdateOnMount,
    boolean isPureRender,
    boolean hasMountSpecChild,
    boolean isDelegate) {
  return newBuilder(
      context,
      defStyleAttr,
      defStyleRes,
      new TestLayoutComponent(
          callsShouldUpdateOnMount, isPureRender, hasMountSpecChild, isDelegate));
}
 
Example #13
Source File: DatePickerDialog.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
static @StyleRes
int resolveDialogTheme(@NonNull Context context, @StyleRes int themeResId) {
    if (themeResId == 0) {
        final TypedValue outValue = new TypedValue();
        if (context.getTheme().resolveAttribute(R.attr.datePickerDialogTheme, outValue, true)) {
            return outValue.resourceId;
        } else {
            return R.style.ThemeOverlay_Material_Dialog_DatePicker;
        }
    } else {
        return themeResId;
    }
}
 
Example #14
Source File: S.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
@StyleRes
public static int getTheme(@NonNull Context context) {
    @StyleRes int theme = BPrefs.Themes.THEMES[context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE).getInt(BPrefs.THEME_KEY, BPrefs.THEME_DEFAULT_VALUE)];
    if (theme == -1) {
        int hour = DateTime.now().getHourOfDay();
        if (hour > 6 && hour < 19)
            return BPrefs.Themes.THEMES[BPrefs.Themes.LIGHT];
        return BPrefs.Themes.THEMES[BPrefs.Themes.DARK];
    }
    return theme;
}
 
Example #15
Source File: CalendarView.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
private void attrHandler(@NonNull Context context, @Nullable AttributeSet attrs,
                         @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.CalendarView, defStyleAttr, defStyleRes);
    a.recycle();

    mDelegate = new CalendarViewMaterialDelegate(this, context, attrs, defStyleAttr, defStyleRes);
}
 
Example #16
Source File: TestDrawableComponent.java    From litho with Apache License 2.0 5 votes vote down vote up
private void init(
    ComponentContext context,
    @AttrRes int defStyleAttr,
    @StyleRes int defStyleRes,
    TestDrawableComponent component) {
  super.init(context, defStyleAttr, defStyleRes, component);
  mComponent = component;
}
 
Example #17
Source File: SkinMaterialTextInputLayout.java    From Android-skin-support with MIT License 5 votes vote down vote up
private void loadErrorTextColorResFromAttributes(@StyleRes int resId) {
    if (resId != INVALID_ID) {
        TypedArray errorTA = getContext().obtainStyledAttributes(resId, skin.support.R.styleable.SkinTextAppearance);
        if (errorTA.hasValue(skin.support.R.styleable.SkinTextAppearance_android_textColor)) {
            mErrorTextColorResId = errorTA.getResourceId(skin.support.R.styleable.SkinTextAppearance_android_textColor, INVALID_ID);
        }
        errorTA.recycle();
    }
    applyErrorTextColorResource();
}
 
Example #18
Source File: TestLayoutComponent.java    From litho with Apache License 2.0 5 votes vote down vote up
private static Builder newBuilder(
    ComponentContext context,
    @AttrRes int defStyleAttr,
    @StyleRes int defStyleRes,
    TestLayoutComponent state) {
  final Builder builder = new Builder();
  builder.init(context, defStyleAttr, defStyleRes, state);
  return builder;
}
 
Example #19
Source File: CustomProfilesAdapter.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
public CustomProfilesAdapter(Context context, List<MultiProfile> profiles, @StyleRes int overrideStyle, DrawerManager.ProfilesDrawerListener<MultiProfile> listener) {
    super(context, profiles, listener);
    if (overrideStyle == 0) this.inflater = LayoutInflater.from(context);
    else this.inflater = LayoutInflater.from(new ContextThemeWrapper(context, overrideStyle));

    forceWhite = overrideStyle == R.style.ForceWhite;
}
 
Example #20
Source File: BasePopupWindow.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 设置动画,已经封装好几种样式,具体可见{@link AnimAction}类
 */
public B setAnimStyle(@StyleRes int id) {
    mAnimations = id;
    if (isCreated()) {
        mPopupWindow.setAnimationStyle(id);
    }
    return (B) this;
}
 
Example #21
Source File: BaseDialog.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 设置动画,已经封装好几种样式,具体可见{@link AnimAction}类
 */
public B setAnimStyle(@StyleRes int id) {
    mAnimations = id;
    if (isCreated()) {
        mDialog.setWindowAnimations(id);
    }
    return (B) this;
}
 
Example #22
Source File: SkinMaterialNavigationView.java    From Android-skin-support with MIT License 5 votes vote down vote up
@Override
public void setItemTextAppearance(@StyleRes int resId) {
    super.setItemTextAppearance(resId);
    if (resId != INVALID_ID) {
        TypedArray a = getContext().obtainStyledAttributes(resId, R.styleable.SkinTextAppearance);
        if (a.hasValue(R.styleable.SkinTextAppearance_android_textColor)) {
            mTextColorResId = a.getResourceId(R.styleable.SkinTextAppearance_android_textColor, INVALID_ID);
        }
        a.recycle();
        applyItemTextColorResource();
    }
}
 
Example #23
Source File: DynamicDialog.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
static int resolveDialogTheme(@NonNull Context context, @StyleRes int resid) {
    // Check to see if this resourceId has a valid package ID.
    if (((resid >>> 24) & 0x000000ff) >= 0x00000001) {   // start of real resource IDs.
        return resid;
    } else {
        TypedValue outValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.alertDialogTheme, outValue, true);
        return outValue.resourceId;
    }
}
 
Example #24
Source File: DynamicResourceUtils.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Extract the supplied integer attribute value from the theme.
 *
 * @param theme The theme to get the styled attributes.
 * @param attr The integer attribute whose value should be extracted.
 * @param defaultValue The value to return if the attribute is not defined or not a resource.
 *
 * @return The value of the supplied attribute.
 */
public static int resolveInteger(@NonNull Context context,
        @StyleRes int theme, @AttrRes int attr, int defaultValue) {
    TypedArray a = context.getTheme().obtainStyledAttributes(theme, new int[] { attr });

    try {
        return a.getInteger(0, defaultValue);
    } catch (Exception e) {
        return defaultValue;
    } finally {
        a.recycle();
    }
}
 
Example #25
Source File: TestTransitionComponent.java    From litho with Apache License 2.0 5 votes vote down vote up
private void init(
    ComponentContext context,
    @AttrRes int defStyleAttr,
    @StyleRes int defStyleRes,
    TestTransitionComponent state) {
  super.init(context, defStyleAttr, defStyleRes, state);
  mState = state;
}
 
Example #26
Source File: DynamicResourceUtils.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Extract the supplied dimension attribute value from the theme.
 *
 * @param theme The theme to get the styled attributes.
 * @param attr The dimension attribute whose value should be extracted.
 * @param defaultValue The value to return if the attribute is not defined or not a resource.
 *
 * @return The value of the supplied attribute.
 */
public static float resolveDimension(@NonNull Context context,
        @StyleRes int theme, @AttrRes int attr, float defaultValue) {
    TypedArray a = context.getTheme().obtainStyledAttributes(theme, new int[] { attr });

    try {
        return a.getDimension(0, defaultValue);
    } catch (Exception e) {
        return defaultValue;
    } finally {
        a.recycle();
    }
}
 
Example #27
Source File: DynamicResourceUtils.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Extract the supplied dimension attribute value from the theme.
 * <p>The extracted value will be converted into the integer pixels.
 *
 * @param theme The theme to get the styled attributes.
 * @param attr The dimension attribute whose value to be extracted.
 * @param defaultValue The value to return if the attribute is not defined or not a resource.
 *
 * @return The value of the supplied attribute.
 */
public static int resolveDimensionPixelOffSet(@NonNull Context context,
        @StyleRes int theme, @AttrRes int attr, int defaultValue) {
    TypedArray a = context.getTheme().obtainStyledAttributes(theme, new int[] { attr });

    try {
        return a.getDimensionPixelOffset(0, defaultValue);
    } catch (Exception e) {
        return defaultValue;
    } finally {
        a.recycle();
    }
}
 
Example #28
Source File: ConfigurationAdapter.java    From pspdfkit-flutter with Apache License 2.0 5 votes vote down vote up
private void configureDarkThemeRes(@NonNull String darkThemeResource, @NonNull Context context) {
    requireNotNullNotEmpty(darkThemeResource, "darkThemeResource");
    checkNotNull(context);

    @StyleRes int darkThemeId = getStyleResourceId(darkThemeResource, context);
    if (darkThemeId != 0) {
        configuration.themeDark(darkThemeId);
    }
}
 
Example #29
Source File: DynamicTheme.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private @StyleRes int getSelectedTheme(Activity activity) {
  if (isDarkTheme(activity)) {
    return getDarkThemeStyle();
  } else {
    return getLightThemeStyle();
  }
}
 
Example #30
Source File: DynamicDarkToolbarTheme.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
protected @StyleRes int getDarkThemeStyle() {
  return R.style.TextSecure_DarkNoActionBar_DarkToolbar;
}