List of usage examples for android.content.res TypedArray getResourceId
@AnyRes public int getResourceId(@StyleableRes int index, int defValue)
From source file:com.todoroo.astrid.taskrabbit.TaskRabbitActivity.java
private void setUpControls() { TypedArray arrays = getResources().obtainTypedArray(R.array.tr_default_set); TypedArray arrayType = getResources().obtainTypedArray(R.array.tr_default_array); for (int i = 0; i < arrays.length(); i++) { int titleID = arrays.getResourceId(i, 0); int arrayID = arrayType.getResourceId(i, 0); if (arrayID == R.string.tr_set_key_location) { TaskRabbitLocationControlSet set = new TaskRabbitLocationControlSet(this, R.layout.task_rabbit_row, titleID, i);/* ww w .j ava2 s. c om*/ set.location = currentLocation; controls.add(set); } else if (arrayID == R.string.tr_set_key_deadline) { TaskRabbitDeadlineControlSet deadlineControl = new TaskRabbitDeadlineControlSet(this, R.layout.control_set_deadline, R.layout.task_rabbit_row); controls.add(deadlineControl); deadlineControl.readFromTask(model); } else if (arrayID == R.string.tr_set_key_name) { TaskRabbitNameControlSet nameControlSet = new TaskRabbitNameControlSet(this, R.layout.control_set_notes, R.layout.task_rabbit_row, titleID); controls.add(nameControlSet); } else if (arrayID == R.string.tr_set_key_description) { TaskRabbitNameControlSet descriptionControlSet = new TaskRabbitNameControlSet(this, R.layout.control_set_notes, R.layout.task_rabbit_row_description, titleID); try { descriptionControlSet.readFromModel( new JSONObject().put(getString(arrayID), model.getValue(Task.NOTES)), getString(arrayID), currentSelectedItem); } catch (JSONException e) { e.printStackTrace(); } controls.add(descriptionControlSet); } else { TaskRabbitSpinnerControlSet set = new TaskRabbitSpinnerControlSet(this, R.layout.task_rabbit_spinner, titleID, i); controls.add(set); } } if (TextUtils.isEmpty(taskTitle.getText())) { taskTitle.setText(model.getValue(Task.TITLE)); } populateFields(taskRabbitTask); displayViewsForMode(currentSelectedItem); }
From source file:com.fuzz.indicator.CutoutViewIndicator.java
@SuppressWarnings("ResourceType") protected void init(Context context, AttributeSet attrs, int defStyleAttr) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CutoutViewIndicator); setIndicatorDrawableId(a.getResourceId(R.styleable.CutoutViewIndicator_rcv_drawable, 0)); setInternalSpacing(a.getDimensionPixelOffset(R.styleable.CutoutViewIndicator_rcv_internal_margin, 0)); // The superclass will have resolved orientation by now. if (getOrientation() == HORIZONTAL) { setPerpendicularLength(//from w w w .j av a2 s . c om a.getDimensionPixelSize(R.styleable.CutoutViewIndicator_rcv_height, WRAP_CONTENT)); setCellLength(a.getDimensionPixelOffset(R.styleable.CutoutViewIndicator_rcv_width, WRAP_CONTENT)); } else { setPerpendicularLength( a.getDimensionPixelSize(R.styleable.CutoutViewIndicator_rcv_width, WRAP_CONTENT)); setCellLength(a.getDimensionPixelOffset(R.styleable.CutoutViewIndicator_rcv_height, WRAP_CONTENT)); } if (isInEditMode()) { editModePageCount = a.getInteger(R.styleable.CutoutViewIndicator_rcv_tools_indicator_count, 2); } String generatorName = a.getString(R.styleable.CutoutViewIndicator_rcv_generator_class_name); if (generatorName != null) { CCGFactory.constructGeneratorFrom(context, attrs, defStyleAttr, generatorName, new ConstructorCallback() { @Override public void onGenerated(@NonNull CutoutCellGenerator generated) { CutoutViewIndicator.this.generator = generated; } @Override public void onFailed(@NonNull String message) { if (!message.isEmpty()) { Log.e(TAG, message); if (isInEditMode()) { String tag = "resources.invalid"; logger.logToLayoutLib(tag, message); } } } }); } setCellBackgroundId(a.getResourceId(R.styleable.CutoutViewIndicator_rcv_drawable_unselected, 0)); a.recycle(); } if (isInEditMode()) { setStateProxy(EDIT_MODE_PROXY); } }
From source file:github.popeen.dsub.activity.SubsonicFragmentActivity.java
@Override public void onStateUpdate(DownloadFile downloadFile, PlayerState playerState) { int[] attrs = new int[] { (playerState == PlayerState.STARTED) ? R.attr.actionbar_pause : R.attr.actionbar_start }; TypedArray typedArray = this.obtainStyledAttributes(attrs); startButton.setImageResource(typedArray.getResourceId(0, 0)); typedArray.recycle();/*w ww. j a v a 2 s. co m*/ }
From source file:com.ch.ch_library.smartlayout.SmartTabLayout.java
public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true);//ww w .ja v a 2 s . co m setOverScrollMode(OVER_SCROLL_NEVER); final DisplayMetrics dm = getResources().getDisplayMetrics(); final float density = dm.density; boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS; int textColor = TAB_VIEW_TEXT_COLOR; float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm); int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density); int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density); boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY; int textLayoutId = NO_ID; int textViewId = NO_ID; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0); textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps); textColor = a.getColor(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor, textColor); textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize); textHorizontalPadding = a.getDimensionPixelSize( R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding); textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth, textMinWidth); textLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, textLayoutId); textViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, textViewId); distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly); a.recycle(); mTitleOffset = (int) (TITLE_OFFSET_DIPS * density); mTabViewTextAllCaps = textAllCaps; mTabViewTextColor = textColor; mTabViewTextSize = textSize; mTabViewTextHorizontalPadding = textHorizontalPadding; mTabViewTextMinWidth = textMinWidth; mTabViewLayoutId = textLayoutId; mTabViewTextViewId = textViewId; mDistributeEvenly = distributeEvenly; mTabStrip = new SmartTabStrip(context, attrs); if (distributeEvenly && mTabStrip.isIndicatorAlwaysInCenter()) { throw new UnsupportedOperationException( "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support"); } addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); }
From source file:br.liveo.navigationliveo.NavigationLiveoAWizard.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.navigation_main); if (savedInstanceState != null) { setCurrentPosition(savedInstanceState.getInt(CURRENT_POSITION)); //FORM WIZARD mWizardModel.load(savedInstanceState.getBundle("model")); mDataChanged = savedInstanceState.getBoolean("dataChanged"); }// w ww . j av a 2 s .com mList = (ListView) findViewById(R.id.list); mList.setOnItemClickListener(new DrawerItemClickListener()); mToolbar = (Toolbar) findViewById(R.id.toolbar); // mToolbar.inflateMenu(R.menu.menu); ALVIN TEST mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); mDrawerToggle = new ActionBarDrawerToggleCompat(this, mDrawerLayout, mToolbar); mDrawerLayout.setDrawerListener(mDrawerToggle); mTitleFooter = (TextView) this.findViewById(R.id.titleFooter); mIconFooter = (ImageView) this.findViewById(R.id.iconFooter); mFooterDrawer = (RelativeLayout) this.findViewById(R.id.footerDrawer); mFooterDrawer.setOnClickListener(onClickFooterDrawer); mRelativeDrawer = (FrameLayout) this.findViewById(R.id.relativeDrawer); //alvin temp comments this.setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setIcon(R.drawable.ic_launcher); getSupportActionBar().setTitle(""); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { Resources.Theme theme = this.getTheme(); TypedArray typedArray = theme.obtainStyledAttributes(new int[] { android.R.attr.colorPrimary }); mDrawerLayout.setStatusBarBackground(typedArray.getResourceId(0, 0)); } catch (Exception e) { e.getMessage(); } this.setElevationToolBar(15); } if (mList != null) { mountListNavigation(savedInstanceState); } if (savedInstanceState == null) { mNavigationListener.onItemClickNavigation(mCurrentPosition, R.id.container); } setCheckedItemNavigation(mCurrentPosition, true); }
From source file:android.support.v14.preference.PreferenceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragment, TypedArrayUtils.getAttr(mStyledContext, android.support.v7.preference.R.attr.preferenceFragmentStyle, AndroidResources.ANDROID_R_PREFERENCE_FRAGMENT_STYLE), 0);/*from www . ja va 2 s . c om*/ mLayoutResId = a.getResourceId(R.styleable.PreferenceFragment_android_layout, mLayoutResId); final Drawable divider = a.getDrawable(R.styleable.PreferenceFragment_android_divider); final int dividerHeight = a.getDimensionPixelSize(R.styleable.PreferenceFragment_android_dividerHeight, -1); a.recycle(); // Need to theme the inflater to pick up the preferenceFragmentListStyle final TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(android.support.v7.preference.R.attr.preferenceTheme, tv, true); final int theme = tv.resourceId; final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme); final LayoutInflater themedInflater = inflater.cloneInContext(themedContext); final View view = themedInflater.inflate(mLayoutResId, container, false); final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER); if (!(rawListContainer instanceof ViewGroup)) { throw new RuntimeException("Content has view with id attribute " + "'android.R.id.list_container' that is not a ViewGroup class"); } final ViewGroup listContainer = (ViewGroup) rawListContainer; final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState); if (listView == null) { throw new RuntimeException("Could not create RecyclerView"); } mList = listView; listView.addItemDecoration(mDividerDecoration); setDivider(divider); if (dividerHeight != -1) { setDividerHeight(dividerHeight); } listContainer.addView(mList); mHandler.post(mRequestFocus); return view; }
From source file:com.github.shareme.gwsmaterialuikit.library.material.app.SimpleDialog.java
@Override public Dialog applyStyle(int resId) { super.applyStyle(resId); if (resId == 0) return this; TypedArray a = getContext().obtainStyledAttributes(resId, R.styleable.SimpleDialog); int textAppearance = 0; int textColor = 0; boolean textColorDefined = false; for (int i = 0, count = a.getIndexCount(); i < count; i++) { int attr = a.getIndex(i); if (attr == R.styleable.SimpleDialog_di_messageTextAppearance) textAppearance = a.getResourceId(attr, 0); else if (attr == R.styleable.SimpleDialog_di_messageTextColor) { textColor = a.getColor(attr, 0); textColorDefined = true;/*w w w. j a va 2s .co m*/ } else if (attr == R.styleable.SimpleDialog_di_radioButtonStyle) radioButtonStyle(a.getResourceId(attr, 0)); else if (attr == R.styleable.SimpleDialog_di_checkBoxStyle) checkBoxStyle(a.getResourceId(attr, 0)); else if (attr == R.styleable.SimpleDialog_di_itemHeight) itemHeight(a.getDimensionPixelSize(attr, 0)); else if (attr == R.styleable.SimpleDialog_di_itemTextAppearance) itemTextAppearance(a.getResourceId(attr, 0)); } a.recycle(); if (textAppearance != 0) messageTextAppearance(textAppearance); if (textColorDefined) messageTextColor(textColor); return this; }
From source file:com.aqtx.app.common.ui.viewpager.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/* w ww . j a va2s.co m*/ setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); a.recycle(); // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); checkedTextColor = a.getResourceId(R.styleable.TwoTextView_ttLeftTextColor, R.color.color_blue_0888ff); unCheckedTextColor = a.getResourceId(R.styleable.TwoTextView_ttLeftTextColor, R.color.action_bar_tittle_color_555555); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); tabViewLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:com.github.johnpersano.supertoasts.demo.views.TabStrip.java
public TabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/* w w w .ja va 2 s . c om*/ setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); indicatorPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, indicatorPadding, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(0, tabTextSize); a.recycle(); a = context.obtainStyledAttributes(attrs, R.styleable.TabStrip); indicatorColor = a.getColor(R.styleable.TabStrip_TabStripIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.TabStrip_TabStripUnderlineColor, underlineColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripUnderlineHeight, underlineHeight); tabPadding = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.TabStrip_TabStripTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.TabStrip_TabStripShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripScrollOffset, scrollOffset); tabSwitch = a.getBoolean(R.styleable.TabStrip_TabStripTabSwitch, tabSwitch); tabTextColor = a.getColor(R.styleable.TabStrip_TabStripActivateTextColor, tabTextColor); tabDeactivateTextColor = a.getColor(R.styleable.TabStrip_TabStripDeactivateTextColor, tabDeactivateTextColor); indicatorPadding = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripIndicatorPadding, indicatorPadding); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } }
From source file:com.h6ah4i.android.materialshadowninepatch.MaterialShadowContainerView.java
public MaterialShadowContainerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr); final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ms9_MaterialShadowContainerView, defStyleAttr, defStyleRes);//from w w w . j ava 2 s .co m final float shadowTranslationZ = ta.getDimension( R.styleable.ms9_MaterialShadowContainerView_ms9_shadowTranslationZ, mShadowTranslationZ); final float shadowElevation = ta .getDimension(R.styleable.ms9_MaterialShadowContainerView_ms9_shadowElevation, mShadowElevation); final int spotShadowLevelListResId = ta .getResourceId(R.styleable.ms9_MaterialShadowContainerView_ms9_spotShadowDrawablesList, 0); final int ambientShadowLevelListResId = ta .getResourceId(R.styleable.ms9_MaterialShadowContainerView_ms9_ambientShadowDrawablesList, 0); final boolean forceUseCompatShadow = ta.getBoolean( R.styleable.ms9_MaterialShadowContainerView_ms9_forceUseCompatShadow, mForceUseCompatShadow); final boolean affectsXYPosition = ta.getBoolean( R.styleable.ms9_MaterialShadowContainerView_ms9_affectsDisplayedPosition, mAffectsDisplayedPosition); final boolean useAmbientShadow = ta .getBoolean(R.styleable.ms9_MaterialShadowContainerView_ms9_useAmbientShadow, mUseAmbientShadow); final boolean useSpotShadow = ta.getBoolean(R.styleable.ms9_MaterialShadowContainerView_ms9_useSpotShadow, mUseSpotShadow); ta.recycle(); mSpotShadowResourcesIdList = getResourceIdArray(getResources(), spotShadowLevelListResId); mAmbientShadowResourcesIdList = getResourceIdArray(getResources(), ambientShadowLevelListResId); mMaxSpotShadowLevel = getMaxShadowLevel(mSpotShadowResourcesIdList); mMaxAmbientShadowLevel = getMaxShadowLevel(mAmbientShadowResourcesIdList); mDisplayDensity = getResources().getDisplayMetrics().density; mInvDisplayDensity = 1.0f / mDisplayDensity; mShadowTranslationZ = shadowTranslationZ; mShadowElevation = shadowElevation; mForceUseCompatShadow = forceUseCompatShadow; mAffectsDisplayedPosition = affectsXYPosition; mUseAmbientShadow = useAmbientShadow; mUseSpotShadow = useSpotShadow; updateShadowLevel(true); }