List of usage examples for android.content.res TypedArray getString
@Nullable public String getString(@StyleableRes int index)
From source file:com.github.fountaingeyser.typefacecompat.FactoryTypefaceCompat.java
@Override public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { View result = null;/*from w w w .j a va 2s .c om*/ // Allow base factory to try and create a view first if (mBaseFactory != null) { result = mBaseFactory.onCreateView(parent, name, context, attrs); } if (result instanceof TextView) { TextView textView = (TextView) result; String fontFamily = null; int style = 0; Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TextViewAppearance, 0, 0); TypedArray appearance = null; int ap = a.getResourceId(R.styleable.TextViewAppearance_android_textAppearance, -1); a.recycle(); if (ap != -1) { appearance = theme.obtainStyledAttributes(ap, R.styleable.TextAppearance); } if (appearance != null) { fontFamily = appearance.getString(R.styleable.TextAppearance_android_fontFamily); style = appearance.getInt(R.styleable.TextAppearance_android_textStyle, 0); appearance.recycle(); } a = theme.obtainStyledAttributes(attrs, R.styleable.TextAppearance, 0, 0); if (a.hasValue(R.styleable.TextAppearance_android_fontFamily)) { fontFamily = a.getString(R.styleable.TextAppearance_android_fontFamily); style = a.getInt(R.styleable.TextAppearance_android_textStyle, 0); } a.recycle(); if (fontFamily != null && TypefaceCompat.isSupported(fontFamily)) { Typeface tf = TypefaceCompat.create(textView.getContext(), fontFamily, style); if (tf != null) { textView.setTypeface(tf); } } } return result; }
From source file:com.github.andrewlord1990.materialandroid.component.list.ListItemView.java
private void loadText(TypedArray typedAttrs) { String primaryText = typedAttrs.getString(R.styleable.MDListItemView_md_list_text_primary); setPrimaryText(primaryText);/* w w w . j a v a2 s. c o m*/ String secondaryText = typedAttrs.getString(R.styleable.MDListItemView_md_list_text_secondary); setSecondaryText(secondaryText); String tertiaryText = typedAttrs.getString(R.styleable.MDListItemView_md_list_text_tertiary); setTertiaryText(tertiaryText); }
From source file:com.stfalcon.chatkit.messages.MessageInputStyle.java
static MessageInputStyle parse(Context context, AttributeSet attrs) { MessageInputStyle style = new MessageInputStyle(context, attrs); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MessageInput); style.inputButtonBackground = typedArray.getDrawable(R.styleable.MessageInput_inputButtonBackground); if (style.inputButtonBackground == null) { style.inputButtonBackground = ContextCompat.getDrawable(context, R.drawable.selector_bg_send); }/*from ww w.j a v a 2 s. co m*/ style.inputButtonIcon = typedArray.getDrawable(R.styleable.MessageInput_inputButtonIcon); if (style.inputButtonIcon == null) { style.inputButtonIcon = ContextCompat.getDrawable(context, R.drawable.selector_icon_send); } style.inputButtonWidth = typedArray.getDimensionPixelSize(R.styleable.MessageInput_inputButtonWidth, style.getDimension(R.dimen.input_button_width)); style.inputButtonHeight = typedArray.getDimensionPixelSize(R.styleable.MessageInput_inputButtonHeight, style.getDimension(R.dimen.input_button_height)); style.inputButtonMargin = typedArray.getDimensionPixelSize(R.styleable.MessageInput_inputButtonMargin, style.getDimension(R.dimen.input_button_margin)); style.inputMaxLines = typedArray.getInt(R.styleable.MessageInput_inputMaxLines, DEFAULT_MAX_LINES); style.inputHint = typedArray.getString(R.styleable.MessageInput_inputHint); style.inputText = typedArray.getString(R.styleable.MessageInput_inputText); style.inputTextSize = typedArray.getDimensionPixelSize(R.styleable.MessageInput_inputTextSize, style.getDimension(R.dimen.input_text_size)); style.inputTextColor = typedArray.getColor(R.styleable.MessageInput_inputTextColor, ContextCompat.getColor(context, R.color.dark_grey_two)); style.inputHintColor = typedArray.getColor(R.styleable.MessageInput_inputHintColor, ContextCompat.getColor(context, R.color.warm_grey_three)); style.inputBackground = typedArray.getDrawable(R.styleable.MessageInput_inputBackground); style.inputCursorDrawable = typedArray.getDrawable(R.styleable.MessageInput_inputCursorDrawable); typedArray.recycle(); style.inputDefaultPaddingLeft = style.getDimension(R.dimen.input_padding_left); style.inputDefaultPaddingRight = style.getDimension(R.dimen.input_padding_right); style.inputDefaultPaddingTop = style.getDimension(R.dimen.input_padding_top); style.inputDefaultPaddingBottom = style.getDimension(R.dimen.input_padding_bottom); return style; }
From source file:com.rong.library.widget.mapsearchbar.MapSearchBar.java
private void init(AttributeSet attrs) { inflate(getContext(), R.layout.search_bar, this); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MapSearchBar); hint = a.getString(R.styleable.MapSearchBar_ms_searchHint); emptyHistory = a.getString(R.styleable.MapSearchBar_ms_defaultHistoryEmptyString); elevation = a.getDimensionPixelSize(R.styleable.MapSearchBar_ms_elevation, -1); margin = a.getDimensionPixelSize(R.styleable.MapSearchBar_ms_margin, -1); navType = a.getInt(R.styleable.MapSearchBar_ms_mapType, -1); a.recycle();//from w w w . j av a 2 s . c o m // default settings if (hint == null) hint = getContext().getString(R.string.ms_default_edit_hint); if (emptyHistory == null) emptyHistory = ""; if (elevation == -1) elevation = getResources().getDimensionPixelSize(R.dimen.ms_default_search_bar_elevation); if (margin == -1) margin = getResources().getDimensionPixelSize(R.dimen.ms_default_search_bar_margin); if (navType == -1) navType = NAV_MAP_AUTO_NAV; findViews(); setupViews(); DisplayMetrics displaymetrics = new DisplayMetrics(); ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); screenHeight = displaymetrics.heightPixels; }
From source file:com.waz.zclient.views.menus.ConfirmationMenu.java
private void initAttributes(AttributeSet attrs) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ConfirmationMenu); header = a.getString(R.styleable.ConfirmationMenu_header); text = a.getString(R.styleable.ConfirmationMenu_text); negativeButtonText = a.getString(R.styleable.ConfirmationMenu_negative); positiveButtonText = a.getString(R.styleable.ConfirmationMenu_positive); cancelVisible = a.getBoolean(R.styleable.ConfirmationMenu_cancelVisible, false); checkboxLabelText = a.getString(R.styleable.ConfirmationMenu_checkboxLabel); checkboxSelectedByDefault = a.getBoolean(R.styleable.ConfirmationMenu_checkboxIsSelected, false); headerIconRes = a.getResourceId(R.styleable.ConfirmationMenu_headerIcon, 0); backgroundImage = a.getResourceId(R.styleable.ConfirmationMenu_backgroundImage, 0); a.recycle();//from w ww . ja va 2s . com }
From source file:org.connectbot.EditHostActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHostDb = HostDatabase.get(this); mPubkeyDb = PubkeyDatabase.get(this); mTerminalConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { TerminalManager bound = ((TerminalManager.TerminalBinder) service).getService(); mBridge = bound.getConnectedBridge(mHost); }/*from ww w.ja v a 2s. com*/ public void onServiceDisconnected(ComponentName name) { mBridge = null; } }; long hostId = getIntent().getLongExtra(EXTRA_EXISTING_HOST_ID, NO_HOST_ID); mIsCreating = hostId == NO_HOST_ID; mHost = mIsCreating ? null : mHostDb.findHostById(hostId); // Note that the lists must be explicitly declared as ArrayLists because Bundle only accepts // ArrayLists of Strings. ArrayList<String> pubkeyNames = new ArrayList<>(); ArrayList<String> pubkeyValues = new ArrayList<>(); // First, add default pubkey names and values (e.g., "use any" and "don't use any"). TypedArray defaultPubkeyNames = getResources().obtainTypedArray(R.array.list_pubkeyids); for (int i = 0; i < defaultPubkeyNames.length(); i++) { pubkeyNames.add(defaultPubkeyNames.getString(i)); } TypedArray defaultPubkeyValues = getResources().obtainTypedArray(R.array.list_pubkeyids_value); for (int i = 0; i < defaultPubkeyValues.length(); i++) { pubkeyValues.add(defaultPubkeyValues.getString(i)); } // Now, add pubkeys which have been added by the user. for (CharSequence cs : mPubkeyDb.allValues(PubkeyDatabase.FIELD_PUBKEY_NICKNAME)) { pubkeyNames.add(cs.toString()); } for (CharSequence cs : mPubkeyDb.allValues("_id")) { pubkeyValues.add(cs.toString()); } setContentView(R.layout.activity_edit_host); FragmentManager fm = getSupportFragmentManager(); HostEditorFragment fragment = (HostEditorFragment) fm.findFragmentById(R.id.fragment_container); if (fragment == null) { fragment = HostEditorFragment.newInstance(mHost, pubkeyNames, pubkeyValues); getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, fragment).commit(); } defaultPubkeyNames.recycle(); defaultPubkeyValues.recycle(); }
From source file:de.mrapp.android.preference.AbstractValidateableDialogPreference.java
/** * Obtains the helper text from a specific typed array. * * @param typedArray/*from ww w . ja v a 2 s . c om*/ * The typed array, the helper text should be obtained from, as an instance of the class * {@link TypedArray}. The typed array may not be null */ private void obtainHelperText(@NonNull final TypedArray typedArray) { setHelperText(typedArray.getString(R.styleable.AbstractValidateableView_helperText)); }
From source file:com.tr4android.support.extension.typeface.TypefaceCompatFactory.java
/** * This method is responsible for creating the correct subclass of View given the xml element name * via AppCompat's layout inflater and afterwards sets the correct typeface if needed. * * @param parent The future parent of the returned view. Note that this may be null. * @param name The fully qualified class name of the View to be create. * @param context The context the view is being created in. * @param attrs An AttributeSet of attributes to apply to the View. * @return The newly created view./* ww w . j av a 2 s . c om*/ * @since 0.1.1 * @deprecated */ @Deprecated @Override public View onCreateView(View parent, String name, Context context, AttributeSet attrs) { View result = null; // Allow base factory to try and create a view first if (mBaseFactory != null) { result = mBaseFactory.onCreateView(parent, name, context, attrs); } if (result instanceof TextView) { TextView textView = (TextView) result; String fontFamily = null; int style = 0; Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TextViewAppearance, 0, 0); TypedArray appearance = null; int ap = a.getResourceId(R.styleable.TextViewAppearance_android_textAppearance, -1); a.recycle(); if (ap != -1) { appearance = theme.obtainStyledAttributes(ap, R.styleable.TextAppearance); } if (appearance != null) { fontFamily = appearance.getString(R.styleable.TextAppearance_android_fontFamily); style = appearance.getInt(R.styleable.TextAppearance_android_textStyle, 0); appearance.recycle(); } a = theme.obtainStyledAttributes(attrs, R.styleable.TextAppearance, 0, 0); if (a.hasValue(R.styleable.TextAppearance_android_fontFamily)) { fontFamily = a.getString(R.styleable.TextAppearance_android_fontFamily); style = a.getInt(R.styleable.TextAppearance_android_textStyle, 0); } a.recycle(); if (fontFamily != null && TypefaceCompat.isSupported(fontFamily)) { Typeface tf = TypefaceCompat.create(textView.getContext(), fontFamily, style); if (tf != null) { textView.setTypeface(tf); } } } return result; }
From source file:jp.co.ipublishing.esnavi.views.MarqueeView.java
/** * (XML??)//from www .j a v a 2s . c om * * @param context * @param attrs XML??? */ public MarqueeView(Context context, AttributeSet attrs) { super(context, attrs); initMarqueeView(); // XML?? final TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.MarqueeView); final String marqueeText = attributes.getString(R.styleable.MarqueeView_marquee_text); if (marqueeText != null) { setText(marqueeText); } final int textSize = attributes.getDimensionPixelOffset(R.styleable.MarqueeView_marquee_textSize, 0); if (textSize > 0) { setTextSize(textSize); } final int padding = attributes.getDimensionPixelOffset(R.styleable.MarqueeView_marquee_padding, 0); if (padding > 0) { setPadding(padding, padding, padding, padding); } setTextColor(attributes.getColor(R.styleable.MarqueeView_marquee_textColor, 0xFFFFFFFF)); setBackgroundColor(attributes.getColor(R.styleable.MarqueeView_marquee_background, 0xFF000000)); setRepeatLimit(attributes.getInteger(R.styleable.MarqueeView_marquee_repeatLimit, 1)); setTextMoveSpeed(attributes.getInteger(R.styleable.MarqueeView_marquee_textMoveSpeed, 5)); attributes.recycle(); }
From source file:com.dirkgassen.wator.ui.view.RollingGraphView.java
/** * Read out the attributes from the given attribute set and initialize whatever they represent. * * @param attributeArray typed array containing the attribute values from the XML file *///from w ww .j a va2 s. c om private void setupAttributes(TypedArray attributeArray) { String series1Name = attributeArray.getString(R.styleable.RollingGraphView_series1name); if (series1Name == null) { seriesNames = null; } else { String series2Name = attributeArray.getString(R.styleable.RollingGraphView_series2name); if (series2Name == null) { seriesNames = new String[] { series1Name }; } else { String series3Name = attributeArray.getString(R.styleable.RollingGraphView_series3name); if (series3Name == null) { seriesNames = new String[] { series1Name, series2Name }; } else { String series4Name = attributeArray.getString(R.styleable.RollingGraphView_series4name); if (series4Name == null) { seriesNames = new String[] { series1Name, series2Name, series3Name }; } else { seriesNames = new String[] { series1Name, series2Name, series3Name, series4Name }; } } } maxValues = attributeArray.getInt(R.styleable.RollingGraphView_maxValues, -1); seriesPaints = new Paint[seriesNames.length]; seriesPaints[0] = new Paint(Paint.ANTI_ALIAS_FLAG); seriesPaints[0] .setColor(attributeArray.getColor(R.styleable.RollingGraphView_series1color, 0xFFFF0000)); seriesPaints[0].setStrokeWidth(attributeArray .getDimension(R.styleable.RollingGraphView_series1thickness, 1 /* dp */ * displayDensity)); seriesPaints[0].setTextSize( attributeArray.getDimension(R.styleable.RollingGraphView_label1textSize, 14 * displayDensity)); if (seriesPaints.length > 1) { seriesPaints[1] = new Paint(Paint.ANTI_ALIAS_FLAG); seriesPaints[1] .setColor(attributeArray.getColor(R.styleable.RollingGraphView_series2color, 0xFFFF0000)); seriesPaints[1].setStrokeWidth(attributeArray .getDimension(R.styleable.RollingGraphView_series2thickness, 1 /* dp */ * displayDensity)); seriesPaints[1].setTextSize(attributeArray.getDimension(R.styleable.RollingGraphView_label2textSize, 14 * displayDensity)); if (seriesPaints.length > 2) { seriesPaints[2] = new Paint(Paint.ANTI_ALIAS_FLAG); seriesPaints[2].setColor( attributeArray.getColor(R.styleable.RollingGraphView_series3color, 0xFFFF0000)); seriesPaints[2].setStrokeWidth(attributeArray.getDimension( R.styleable.RollingGraphView_series3thickness, 1 /* dp */ * displayDensity)); seriesPaints[2].setTextSize(attributeArray .getDimension(R.styleable.RollingGraphView_label3textSize, 14 * displayDensity)); if (seriesPaints.length > 3) { seriesPaints[3] = new Paint(Paint.ANTI_ALIAS_FLAG); seriesPaints[3].setColor( attributeArray.getColor(R.styleable.RollingGraphView_series4color, 0xFFFF0000)); seriesPaints[3].setStrokeWidth(attributeArray.getDimension( R.styleable.RollingGraphView_series4thickness, 1 /* dp */ * displayDensity)); seriesPaints[3].setTextSize(attributeArray .getDimension(R.styleable.RollingGraphView_label4textSize, 14 * displayDensity)); } } } background = getBackground(); if (background == null) { background = new ColorDrawable(ContextCompat.getColor(getContext(), android.R.color.white)); } } horizontal = attributeArray.getInt(R.styleable.RollingGraphView_android_orientation, 0) == 0; }