Java Code Examples for android.content.res.TypedArray#getType()
The following examples show how to use
android.content.res.TypedArray#getType() .
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: ShortcutParser.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static String parseCategories(ShortcutService service, AttributeSet attrs) { final TypedArray sa = service.mContext.getResources().obtainAttributes(attrs, R.styleable.ShortcutCategories); try { if (sa.getType(R.styleable.ShortcutCategories_name) == TypedValue.TYPE_STRING) { return sa.getNonResourceString(R.styleable.ShortcutCategories_name); } else { Log.w(TAG, "android:name for shortcut category must be string literal."); return null; } } finally { sa.recycle(); } }
Example 2
Source File: RadioGroupSetting.java From FirefoxReality with Mozilla Public License 2.0 | 5 votes |
public RadioGroupSetting(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.RadioGroupSetting, defStyleAttr, 0); mLayout = attributes.getResourceId(R.styleable.RadioGroupSetting_layout, R.layout.setting_radio_group); mDescription = attributes.getString(R.styleable.RadioGroupSetting_description); mOptions = attributes.getTextArray(R.styleable.RadioGroupSetting_options); mDescriptions = attributes.getTextArray(R.styleable.RadioGroupSetting_descriptions); mMargin = attributes.getDimension(R.styleable.RadioGroupSetting_itemMargin, getDefaultMargin()); int id = attributes.getResourceId(R.styleable.RadioGroupSetting_values, 0); try { TypedArray array = context.getResources().obtainTypedArray(id); if (array.getType(0) == TypedValue.TYPE_STRING) { mValues = getResources().getStringArray(id); } else if (array.getType(0) == TypedValue.TYPE_INT_HEX || array.getType(0) == TypedValue.TYPE_INT_DEC) { int [] values = getResources().getIntArray(id); mValues = new Integer[values.length]; for (int i=0; i<values.length; i++) { mValues[i] = values[i]; } } array.recycle(); } catch (Resources.NotFoundException ignored) { } attributes.recycle(); initialize(context, attrs, defStyleAttr, mLayout); }
Example 3
Source File: ImageRadioGroupSetting.java From FirefoxReality with Mozilla Public License 2.0 | 5 votes |
public ImageRadioGroupSetting(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.RadioGroupSetting, defStyleAttr, 0); mOptions = new ArrayList<>(Arrays.asList(attributes.getTextArray(R.styleable.RadioGroupSetting_options))); int id = attributes.getResourceId(R.styleable.RadioGroupSetting_values, 0); TypedArray array = context.getResources().obtainTypedArray(id); if (array.getType(0) == TypedValue.TYPE_STRING) { mValues = new ArrayList<>(Arrays.asList(getResources().getStringArray(id))); } else if (array.getType(0) == TypedValue.TYPE_INT_HEX || array.getType(0) == TypedValue.TYPE_INT_DEC) { int [] values = getResources().getIntArray(id); mValues = new ArrayList<>(Arrays.asList(new Integer[values.length])); for (int value : values) { mValues.add(value); } } array.recycle(); id = attributes.getResourceId(R.styleable.RadioGroupSetting_images, 0); array = context.getResources().obtainTypedArray(id); mImages = new Drawable[mOptions.size()]; for (int i = 0; i < mOptions.size(); ++i) { mImages[i] = array.getDrawable(i); } array.recycle(); attributes.recycle(); initialize(context); }
Example 4
Source File: ThemeUtil.java From timecat with Apache License 2.0 | 5 votes |
public static int getType(TypedArray array, int index) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return array.getType(index); else { TypedValue value = array.peekValue(index); return value == null ? TypedValue.TYPE_NULL : value.type; } }
Example 5
Source File: ThemeUtil.java From MDPreference with Apache License 2.0 | 5 votes |
public static int getType(TypedArray array, int index) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return array.getType(index); else { TypedValue value = array.peekValue(index); return value == null ? TypedValue.TYPE_NULL : value.type; } }
Example 6
Source File: ThemeUtils.java From ticdesign with Apache License 2.0 | 5 votes |
public static int getType(TypedArray array, int index){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return array.getType(index); else{ TypedValue value = array.peekValue(index); return value == null ? TypedValue.TYPE_NULL : value.type; } }
Example 7
Source File: LayoutManager.java From toktok-android with GNU General Public License v3.0 | 5 votes |
@Override public RecyclerView.LayoutParams generateLayoutParams(@NonNull Context c, AttributeSet attrs) { // Just so we don't build layout params multiple times. boolean isString; TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.superslim_LayoutManager); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { TypedValue value = new TypedValue(); a.getValue(R.styleable.superslim_LayoutManager_slm_section_sectionManager, value); isString = value.type == TypedValue.TYPE_STRING; } else { isString = a.getType(R.styleable.superslim_LayoutManager_slm_section_sectionManager) == TypedValue.TYPE_STRING; } String sectionManager = null; int sectionManagerKind; if (isString) { sectionManager = a .getString(R.styleable.superslim_LayoutManager_slm_section_sectionManager); if (TextUtils.isEmpty(sectionManager)) { sectionManagerKind = SECTION_MANAGER_LINEAR; } else { sectionManagerKind = SECTION_MANAGER_CUSTOM; } } else { sectionManagerKind = a .getInt(R.styleable.superslim_LayoutManager_slm_section_sectionManager, SECTION_MANAGER_LINEAR); } a.recycle(); return getSLM(sectionManagerKind, sectionManager).generateLayoutParams(c, attrs); }
Example 8
Source File: ThemeUtil.java From material with Apache License 2.0 | 5 votes |
public static int getType(TypedArray array, int index){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return array.getType(index); else{ TypedValue value = array.peekValue(index); return value == null ? TypedValue.TYPE_NULL : value.type; } }
Example 9
Source File: ShortcutParser.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static ShortcutInfo parseShortcutAttributes(ShortcutService service, AttributeSet attrs, String packageName, ComponentName activity, @UserIdInt int userId, int rank) { final TypedArray sa = service.mContext.getResources().obtainAttributes(attrs, R.styleable.Shortcut); try { if (sa.getType(R.styleable.Shortcut_shortcutId) != TypedValue.TYPE_STRING) { Log.w(TAG, "android:shortcutId must be string literal. activity=" + activity); return null; } final String id = sa.getNonResourceString(R.styleable.Shortcut_shortcutId); final boolean enabled = sa.getBoolean(R.styleable.Shortcut_enabled, true); final int iconResId = sa.getResourceId(R.styleable.Shortcut_icon, 0); final int titleResId = sa.getResourceId(R.styleable.Shortcut_shortcutShortLabel, 0); final int textResId = sa.getResourceId(R.styleable.Shortcut_shortcutLongLabel, 0); final int disabledMessageResId = sa.getResourceId( R.styleable.Shortcut_shortcutDisabledMessage, 0); if (TextUtils.isEmpty(id)) { Log.w(TAG, "android:shortcutId must be provided. activity=" + activity); return null; } if (titleResId == 0) { Log.w(TAG, "android:shortcutShortLabel must be provided. activity=" + activity); return null; } return createShortcutFromManifest( service, userId, id, packageName, activity, titleResId, textResId, disabledMessageResId, rank, iconResId, enabled); } finally { sa.recycle(); } }
Example 10
Source File: LayoutManager.java From toktok-android with GNU General Public License v3.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public LayoutParams(@NonNull Context c, AttributeSet attrs) { super(c, attrs); TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.superslim_LayoutManager); isHeader = a.getBoolean( R.styleable.superslim_LayoutManager_slm_isHeader, false); //noinspection ResourceType headerDisplay = a.getInt( R.styleable.superslim_LayoutManager_slm_headerDisplay, DEFAULT_HEADER_DISPLAY); mFirstPosition = a.getInt( R.styleable.superslim_LayoutManager_slm_section_firstPosition, NO_FIRST_POSITION); // Header margin types can be dimension or integer (enum). if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { TypedValue value = new TypedValue(); a.getValue(R.styleable.superslim_LayoutManager_slm_section_headerMarginStart, value); loadHeaderStartMargin(a, value.type == TypedValue.TYPE_DIMENSION); a.getValue(R.styleable.superslim_LayoutManager_slm_section_headerMarginEnd, value); loadHeaderEndMargin(a, value.type == TypedValue.TYPE_DIMENSION); a.getValue(R.styleable.superslim_LayoutManager_slm_section_sectionManager, value); loadSlm(a, value.type == TypedValue.TYPE_STRING); } else { boolean isDimension; isDimension = a.getType(R.styleable.superslim_LayoutManager_slm_section_headerMarginStart) == TypedValue.TYPE_DIMENSION; loadHeaderStartMargin(a, isDimension); isDimension = a.getType(R.styleable.superslim_LayoutManager_slm_section_headerMarginEnd) == TypedValue.TYPE_DIMENSION; loadHeaderEndMargin(a, isDimension); boolean isString = a.getType(R.styleable.superslim_LayoutManager_slm_section_sectionManager) == TypedValue.TYPE_STRING; loadSlm(a, isString); } a.recycle(); }