List of usage examples for android.content.res TypedArray getString
@Nullable public String getString(@StyleableRes int index)
From source file:rikka.materialpreference.RingtonePreference.java
public RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RingtonePreference, defStyleAttr, defStyleRes);// w ww .j av a 2s . co m mRingtoneType = TypedArrayUtils.getInt(a, R.styleable.RingtonePreference_ringtoneType, R.styleable.RingtonePreference_android_ringtoneType, RingtoneManager.TYPE_RINGTONE); mShowDefault = TypedArrayUtils.getBoolean(a, R.styleable.RingtonePreference_showDefault, R.styleable.RingtonePreference_android_showDefault, true); mShowSilent = TypedArrayUtils.getBoolean(a, R.styleable.RingtonePreference_showSilent, R.styleable.RingtonePreference_android_showSilent, true); mSummaryNone = a.getString(R.styleable.RingtonePreference_summaryNone); a.recycle(); /* Retrieve the Preference summary attribute since it's private * in the Preference class. */ a = context.obtainStyledAttributes(attrs, R.styleable.Preference, defStyleAttr, defStyleRes); mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary, R.styleable.Preference_android_summary); a.recycle(); }
From source file:com.zzb.mynew.view.ExpandableTextView.java
/** * ?//from www .j a v a2 s .c o m * @param attrs */ private void init(AttributeSet attrs) { mCollapsedStatus = new SparseBooleanArray(); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView); mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines, MAX_COLLAPSED_LINES); mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION); mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable); mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable); textCollapse = typedArray.getString(R.styleable.ExpandableTextView_textCollapse); textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand); showExpandCollapseDrawable = typedArray .getBoolean(R.styleable.ExpandableTextView_showExpandCollapseDrawable, true); if (showExpandCollapseDrawable) { if (mExpandDrawable == null) { mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down); } if (mCollapseDrawable == null) { mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up); } } if (TextUtils.isEmpty(textCollapse)) { textCollapse = getContext().getString(R.string.shink); } if (TextUtils.isEmpty(textExpand)) { textExpand = getContext().getString(R.string.expand); } contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor, ContextCompat.getColor(getContext(), R.color.light_gray)); contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize, DisplayUtil.sp2px(14)); collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor, ContextCompat.getColor(getContext(), R.color.main_color)); collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize, DisplayUtil.sp2px(14)); grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT); typedArray.recycle(); // enforces vertical orientation setOrientation(LinearLayout.VERTICAL); // default visibility is gone setVisibility(GONE); }
From source file:de.grobox.liberario.ui.LocationView.java
public LocationView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LocationView, 0, 0); boolean onlyIDs = a.getBoolean(R.styleable.LocationView_onlyIds, true); boolean includeHome = a.getBoolean(R.styleable.LocationView_homeLocation, false); boolean includeFavs = a.getBoolean(R.styleable.LocationView_favLocation, false); boolean includeMap = a.getBoolean(R.styleable.LocationView_mapLocation, false); hint = a.getString(R.styleable.LocationView_hint); a.recycle();//www.j ava 2 s .c om setOrientation(LinearLayout.HORIZONTAL); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.location_view, this, true); ui = new LocationViewHolder(this); if (!isInEditMode() && context instanceof FragmentActivity) { initialize((FragmentActivity) context); } ui.location.setHint(hint); ui.location.setAdapter(new LocationAdapter(context, onlyIDs)); ui.location.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) { WrapLocation loc = getAdapter().getItem(position); if (loc != null) onLocationItemClick(loc, view); } }); ui.location.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { LocationView.this.onFocusChange(v, hasFocus); } }); ui.location.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { LocationView.this.onClick(); } }); setHome(includeHome); setFavs(includeFavs); setMap(includeMap); ui.status.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getAdapter().setDefaultLocations(false); LocationView.this.onClick(); } }); if (!isInEditMode()) { ui.status.setImageDrawable(getTintedDrawable(context, R.drawable.ic_location)); ui.clear.setImageDrawable(getTintedDrawable(context, ui.clear.getDrawable())); } else { ui.status.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_location)); } // clear text button ui.clear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { clearLocationAndShowDropDown(); } }); // From text input changed ui.location.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if ((count == 1 && before == 0) || (count == 0 && before == 1)) handleTextChanged(s); } public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } }); }
From source file:recycle.com.example.nandy.dynamicdemo.widget.dynamic.ExpandableTextView.java
/** * ?//from w ww . ja v a 2 s.c om * @param attrs */ private void init(AttributeSet attrs) { mCollapsedStatus = new SparseBooleanArray(); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView); mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines, MAX_COLLAPSED_LINES); mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION); mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable); mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable); textCollapse = typedArray.getString(R.styleable.ExpandableTextView_textCollapse); textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand); showExpandCollapseDrawable = typedArray .getBoolean(R.styleable.ExpandableTextView_showExpandCollapseDrawable, true); if (showExpandCollapseDrawable) { if (mExpandDrawable == null) { mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down); } if (mCollapseDrawable == null) { mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up); } } if (TextUtils.isEmpty(textCollapse)) { textCollapse = getContext().getString(R.string.shink); } if (TextUtils.isEmpty(textExpand)) { textExpand = getContext().getString(R.string.expand); } contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor, ContextCompat.getColor(getContext(), R.color.white)); contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize, DensityUtil.sp2px(14)); collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor, ContextCompat.getColor(getContext(), R.color.black)); collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize, DensityUtil.sp2px(14)); grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT); typedArray.recycle(); // enforces vertical orientation setOrientation(LinearLayout.VERTICAL); // default visibility is gone setVisibility(GONE); }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
/** * Applies the specified text appearance resource to a paint, returning the * text color if one is set in the text appearance. * * @param p the paint to modify//from ww w .j a v a 2s. com * @param resId the resource ID of the text appearance * @return the text color, if available */ private ColorStateList applyTextAppearance(Paint p, int resId) { final TypedArray ta = getContext().obtainStyledAttributes(null, R.styleable.TextAppearance, 0, resId); final String fontFamily = ta.getString(R.styleable.TextAppearance_android_fontFamily); if (fontFamily != null) { p.setTypeface(Typeface.create(fontFamily, 0)); } p.setTextSize(ta.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, (int) p.getTextSize())); final ColorStateList textColor = ta.getColorStateList(R.styleable.TextAppearance_android_textColor); if (textColor != null) { final int enabledColor = textColor.getColorForState(ENABLED_STATE_SET, 0); p.setColor(enabledColor); } ta.recycle(); return textColor; }
From source file:com.viewsforandroid.foundry.sample.indicators.NumericPageIndicator.java
@SuppressWarnings("deprecation") public NumericPageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) { return;//w ww . ja v a2s. c o m } // Load defaults from resources final Resources res = getResources(); final int defaultTextColor = res.getColor(R.color.default_page_number_indicator_text_color); final int defaultPageNumberTextColor = res .getColor(R.color.default_page_number_indicator_page_number_text_color); final boolean defaultPageNumberTextBold = res .getBoolean(R.bool.default_page_number_indicator_page_number_text_bold); final int defaultButtonPressedColor = res .getColor(R.color.default_page_number_indicator_pressed_button_color); final float defaultTopPadding = res.getDimension(R.dimen.default_page_number_indicator_top_padding); final float defaultBottomPadding = res.getDimension(R.dimen.default_page_number_indicator_bottom_padding); final float defaultTextSize = res.getDimension(R.dimen.default_page_number_indicator_text_size); final boolean defaultShowChangePageButtons = res .getBoolean(R.bool.default_page_number_indicator_show_change_page_buttons); final boolean defaultShowStartEndButtons = res .getBoolean(R.bool.default_page_number_indicator_show_start_end_buttons); // Retrieve styles attributes final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumericPageIndicator, defStyle, 0); mTextTemplate = a.getString(R.styleable.NumericPageIndicator_textTemplate); if (mTextTemplate == null) { mTextTemplate = res.getString(R.string.default_page_number_indicator_text_template); ; } parseTextTemplate(); mTextStartButton = a.getString(R.styleable.NumericPageIndicator_startButtonText); if (mTextStartButton == null) { mTextStartButton = res.getString(R.string.default_page_number_indicator_start_button_text); } mTextEndButton = a.getString(R.styleable.NumericPageIndicator_endButtonText); if (mTextEndButton == null) { mTextEndButton = res.getString(R.string.default_page_number_indicator_end_button_text); } mTextPreviousButton = a.getString(R.styleable.NumericPageIndicator_previousButtonText); if (mTextPreviousButton == null) { mTextPreviousButton = res.getString(R.string.default_page_number_indicator_previous_button_text); } mTextNextButton = a.getString(R.styleable.NumericPageIndicator_nextButtonText); if (mTextNextButton == null) { mTextNextButton = res.getString(R.string.default_page_number_indicator_next_button_text); } mColorText = a.getColor(R.styleable.NumericPageIndicator_android_textColor, defaultTextColor); mColorPageNumberText = a.getColor(R.styleable.NumericPageIndicator_pageNumberTextColor, defaultPageNumberTextColor); mPageNumberTextBold = a.getBoolean(R.styleable.NumericPageIndicator_pageNumberTextBold, defaultPageNumberTextBold); mColorPressedButton = a.getColor(R.styleable.NumericPageIndicator_pressedButtonColor, defaultButtonPressedColor); mPaddingTop = a.getDimension(R.styleable.NumericPageIndicator_android_paddingTop, defaultTopPadding); mPaddingBottom = a.getDimension(R.styleable.NumericPageIndicator_android_paddingBottom, defaultBottomPadding); mPaintText.setColor(mColorText); mShowChangePageButtons = a.getBoolean(R.styleable.NumericPageIndicator_showChangePageButtons, defaultShowChangePageButtons); mShowStartEndButtons = a.getBoolean(R.styleable.NumericPageIndicator_showStartEndButtons, defaultShowStartEndButtons); mPaintButtonBackground.setColor(mColorPressedButton); final float textSize = a.getDimension(R.styleable.NumericPageIndicator_android_textSize, defaultTextSize); mPaintText.setTextSize(textSize); mPaintText.setAntiAlias(true); mPaintPageNumberText.setColor(mColorPageNumberText); mPaintPageNumberText.setTextSize(textSize); mPaintPageNumberText.setAntiAlias(true); if (mPageNumberTextBold) { mPaintPageNumberText.setTypeface(Typeface.DEFAULT_BOLD); } final Drawable background = a.getDrawable(R.styleable.NumericPageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); }
From source file:com.appsimobile.appsii.module.appsiagenda.MonthView.java
public MonthView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MonthView, 0, R.style.MonthViewStyle); mDayOfWeekTypeface = a.getString(R.styleable.MonthView_monthview_dayOfWeekTypeface); mMonthTitleTypeface = a.getString(R.styleable.MonthView_monthview_monthTitleTypeface); mDayTextColor = a.getColor(R.styleable.MonthView_monthview_dayTextColor, 0xFF999999); mTodayNumberColor = a.getColor(R.styleable.MonthView_monthview_todayNumberColor, 0xFF33b5e5); mDisabledDayTextColor = a.getColor(R.styleable.MonthView_monthview_disabledDayTextColor, 0xFFcccccc); mMonthTitleColor = a.getColor(R.styleable.MonthView_monthview_monthTitleColor, 0xFFFFFFFF); mMonthTitleBGColor = a.getColor(R.styleable.MonthView_monthview_monthTitleBGColor, 0xFFF2F2F2); MINI_DAY_NUMBER_TEXT_SIZE = a.getDimensionPixelSize(R.styleable.MonthView_monthview_miniDayNumberTextSize, 24);// w w w. jav a 2 s. c o m MONTH_LABEL_TEXT_SIZE = a.getDimensionPixelSize(R.styleable.MonthView_monthview_monthLabelTextSize, 24); MONTH_DAY_LABEL_TEXT_SIZE = a.getDimensionPixelSize(R.styleable.MonthView_monthview_monthDayLabelTextSize, 24); MONTH_HEADER_SIZE = a.getDimensionPixelOffset(R.styleable.MonthView_monthview_headerSize, 24); DAY_SELECTED_CIRCLE_SIZE = a.getDimensionPixelSize(R.styleable.MonthView_monthview_daySelectedCircleSize, 24); mRowHeight = (a.getDimensionPixelOffset(R.styleable.MonthView_monthview_viewHeight, 24) - getMonthHeaderSize()) / MAX_NUM_ROWS; a.recycle(); mStringBuilder = new StringBuilder(50); mFormatter = new Formatter(mStringBuilder, Locale.getDefault()); if (!isInEditMode()) { // Set up accessibility components. mTouchHelper = getMonthViewTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); mLockAccessibilityDelegate = true; } else { mTouchHelper = null; } // Sets up any standard paints that will be used initView(); }
From source file:com.github.snowdream.android.widget.NotFoundWebView.java
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) private void init(Context context, AttributeSet attrs, int defStyle) { if (context == null) { return;/* w w w . j ava 2 s. c om*/ } // enable JavaScript WebSettings settings = this.getSettings(); settings.setJavaScriptEnabled(true); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setLoadWithOverviewMode(true); settings.setDefaultZoom(ZoomDensity.FAR); //settings.setUseWideViewPort(true); //webView.setInitialScale(1); // init attrs TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomWebView); try { int type = a.getInteger(R.styleable.CustomWebView_type, 0); switch (type) { case 0: script = context.getString(R.string.html_notfound); break; case 1: script = context.getString(R.string.html_qq_narrow); break; case 2: script = context.getString(R.string.html_qq_narrow); break; case 3: script = context.getString(R.string.html_qq_wide); break; case 4: script = context.getString(R.string.html_yibo); break; default: script = a.getString(R.styleable.CustomWebView_script); break; } } finally { a.recycle(); } }
From source file:com.facebook.LikeView.java
private void parseAttributes(AttributeSet attrs) { if (attrs == null || getContext() == null) { return;/*from w w w.java 2s . c o m*/ } TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_like_view); if (a == null) { return; } objectId = Utility.coerceValueIfNullOrEmpty( a.getString(R.styleable.com_facebook_like_view_com_facebook_object_id), null); objectType = ObjectType.fromInt(a.getInt(R.styleable.com_facebook_like_view_com_facebook_object_type, ObjectType.DEFAULT.getValue())); likeViewStyle = Style .fromInt(a.getInt(R.styleable.com_facebook_like_view_com_facebook_style, Style.DEFAULT.getValue())); if (likeViewStyle == null) { throw new IllegalArgumentException("Unsupported value for LikeView 'style'"); } auxiliaryViewPosition = AuxiliaryViewPosition .fromInt(a.getInt(R.styleable.com_facebook_like_view_com_facebook_auxiliary_view_position, AuxiliaryViewPosition.DEFAULT.getValue())); if (auxiliaryViewPosition == null) { throw new IllegalArgumentException("Unsupported value for LikeView 'auxiliary_view_position'"); } horizontalAlignment = HorizontalAlignment .fromInt(a.getInt(R.styleable.com_facebook_like_view_com_facebook_horizontal_alignment, HorizontalAlignment.DEFAULT.getValue())); if (horizontalAlignment == null) { throw new IllegalArgumentException("Unsupported value for LikeView 'horizontal_alignment'"); } foregroundColor = a.getColor(R.styleable.com_facebook_like_view_com_facebook_foreground_color, NO_FOREGROUND_COLOR); a.recycle(); }
From source file:com.li.utils.ui.mdbottom.BottomNavigation.java
private void initialize(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { typeface = new SoftReference<>(Typeface.DEFAULT); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.BottomNavigation, defStyleAttr, defStyleRes);/* w w w. j a va 2 s . c om*/ final int menuResId = array.getResourceId(R.styleable.BottomNavigation_bbn_entries, 0); pendingMenu = MenuParser.inflateMenu(context, menuResId); badgeProvider = parseBadgeProvider(this, context, array.getString(R.styleable.BottomNavigation_bbn_badgeProvider)); array.recycle(); backgroundColorAnimation = getResources().getInteger(R.integer.bbn_background_animation_duration); defaultSelectedIndex = 0; defaultHeight = getResources().getDimensionPixelSize(R.dimen.bbn_bottom_navigation_height); defaultWidth = getResources().getDimensionPixelSize(R.dimen.bbn_bottom_navigation_width); shadowHeight = getResources().getDimensionPixelOffset(R.dimen.bbn_top_shadow_height); // check if the bottom navigation is translucent // if (!isInEditMode()) { // final Activity activity = MiscUtils.getActivity(context); // if (null != activity) { // final SystemBarTintManager systembarTint = new SystemBarTintManager(activity); // if (MiscUtils.hasTranslucentNavigation(activity) // && systembarTint.getConfig().isNavigationAtBottom() // && systembarTint.getConfig().hasNavigtionBar()) { // bottomInset = systembarTint.getConfig().getNavigationBarHeight(); // } else { // bottomInset = 0; // } // topInset = systembarTint.getConfig().getStatusBarHeight(); // } // } LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT); backgroundOverlay = new View(getContext()); backgroundOverlay.setLayoutParams(params); addView(backgroundOverlay); }