List of usage examples for android.content.res TypedArray getResourceId
@AnyRes public int getResourceId(@StyleableRes int index, int defValue)
From source file:alexander.martinz.libs.materialpreferences.MaterialPreference.java
protected TypedArray parseAttrs(Context context, AttributeSet attrs) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialPreference); if (a == null) { Log.e(this.getClass().getSimpleName(), "Could not obtain typed array!"); return null; }//from w w w . ja v a 2s . co m mPrefKey = a.getString(R.styleable.MaterialPreference_prefKey); mPrefAsCard = a.getBoolean(R.styleable.MaterialPreference_prefAsCard, false); mResIdIcon = a.getResourceId(R.styleable.MaterialPreference_prefIcon, -1); mIconTintColor = a.getColor(R.styleable.MaterialPreference_prefIconTint, Integer.MIN_VALUE); mResIdTitle = a.getResourceId(R.styleable.MaterialPreference_prefTitle, -1); mResIdSummary = a.getResourceId(R.styleable.MaterialPreference_prefSummary, -1); mCardBackgroundColor = a.getColor(R.styleable.MaterialPreference_prefCardBackgroundColor, Integer.MIN_VALUE); return a; }
From source file:com.artemchep.horario.ui.fragments.master.LessonsFragment.java
@Override protected void setupToolbar() { super.setupToolbar(); CustomAppBar appBar = getMainActivity().mAppBar; appBar.setTitle(getString(R.string.nav_lessons)); Toolbar toolbar = appBar.getToolbarSpecific(); toolbar.inflateMenu(R.menu.master_lessons_week); toolbar.setOnMenuItemClickListener(this); // Load week icon TypedArray a = getActivity().getTheme() .obtainStyledAttributes(new int[] { R.attr.icon_calendar_empty_grey, R.attr.is_dark_theme }); int iconDrawableRes = a.getResourceId(0, 0); boolean isDarkTheme = a.getBoolean(1, false); a.recycle();//from www . j a va2s. co m float density = getResources().getDisplayMetrics().density; mWeekDrawable = new TextDrawable(); mWeekDrawable.setTranslationY(density * 2); mWeekDrawable.setTextSize(density * 10); mWeekDrawable.setColor(isDarkTheme ? Color.WHITE : Color.GRAY); mWeekCompositeDrawable = new LayerDrawable( new Drawable[] { ContextCompat.getDrawable(getContext(), iconDrawableRes), mWeekDrawable }); Menu menu = toolbar.getMenu(); mWeekMenuItem = menu.findItem(R.id.action_switch_week); mWeekMenuItem.setIcon(mWeekCompositeDrawable); mWeekMenuItem.setVisible(mWeekCycle > 1); updateWeekNumberMenuItemText(); }
From source file:com.antew.redditinpictures.library.widget.SwipeListView.java
private void initialize(AttributeSet attrs) { // If we are in an IDE Preview, don't initialize. if (isInEditMode()) { return;//from w ww . ja v a2s .c om } if (attrs != null) { TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView); mFrontViewId = styled.getResourceId(R.styleable.SwipeListView_frontViewId, 0); mBackViewId = styled.getResourceId(R.styleable.SwipeListView_backViewId, 0); mCloseAllWhenScrolling = styled.getBoolean(R.styleable.SwipeListView_closeAllWhenScrolling, true); mOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_openOnLongPress, true); setSwipeDirection(styled.getInt(R.styleable.SwipeListView_swipeDirection, SWIPE_DIRECTION_BOTH)); } if (mFrontViewId == 0 || mBackViewId == 0) { throw new RuntimeException("You must specify a Front View and Back View"); } ViewConfiguration viewConfig = ViewConfiguration.get(getContext()); mTouchSlop = viewConfig.getScaledTouchSlop(); mMinFlingVelocity = viewConfig.getScaledMinimumFlingVelocity(); mMaxFlingVelocity = viewConfig.getScaledMaximumFlingVelocity(); mAnimationTime = getResources().getInteger(android.R.integer.config_shortAnimTime); super.setOnScrollListener(mInternalOnScrollListener); super.setOnItemLongClickListener(mInternalOnItemLongClickListener); }
From source file:com.ternup.caddisfly.fragment.DetailsFragment.java
private void displayResult() { String[] projection = { TestTable.TABLE_TEST + "." + TestTable.COLUMN_ID, TestTable.TABLE_TEST + "." + TestTable.COLUMN_DATE, TestTable.COLUMN_RESULT, TestTable.COLUMN_TYPE, TestTable.COLUMN_FOLDER, LocationTable.COLUMN_NAME, LocationTable.COLUMN_STREET, LocationTable.COLUMN_TOWN, LocationTable.COLUMN_CITY, LocationTable.COLUMN_STATE, LocationTable.COLUMN_COUNTRY, LocationTable.COLUMN_STREET, LocationTable.COLUMN_SOURCE }; Log.d("Result", mId + " test"); Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId); Cursor cursor = mContext.getContentResolver().query(uri, projection, null, null, null); cursor.moveToFirst();/*from w ww .ja v a 2s . com*/ if (cursor.getCount() > 0) { mAddressText.setText(cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_NAME)) + ", " + cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_STREET))); mAddress2Text.setText(cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_TOWN)) + ", " + cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_CITY))); mAddress3Text.setText(cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_STATE)) + ", " + cursor.getString(cursor.getColumnIndex(LocationTable.COLUMN_COUNTRY))); if (mAddress2Text.getText().equals(", ")) { mAddress2Text.setVisibility(View.GONE); } else { mAddress2Text.setVisibility(View.VISIBLE); } if (mAddress3Text.getText().equals(", ")) { mAddress3Text.setVisibility(View.GONE); } else { mAddress3Text.setVisibility(View.VISIBLE); } String[] sourceArray = getResources().getStringArray(R.array.source_types); int sourceType = cursor.getInt(cursor.getColumnIndex(LocationTable.COLUMN_SOURCE)); if (sourceType > -1) { mSourceText.setText(sourceArray[sourceType]); mSourceText.setVisibility(View.VISIBLE); } else { mSourceText.setVisibility(View.GONE); } Date date = new Date(cursor.getLong(cursor.getColumnIndex(TestTable.COLUMN_DATE))); SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy"); DateFormat tf = android.text.format.DateFormat.getTimeFormat(getActivity()); // Gets system TF String dateString = df.format(date.getTime()) + ", " + tf.format(date.getTime()); mTestType = DataHelper.getTestTitle(getActivity(), cursor.getInt(cursor.getColumnIndex(TestTable.COLUMN_TYPE))); mTestTypeId = cursor.getInt(cursor.getColumnIndex(TestTable.COLUMN_TYPE)); mTitleView.setText(mTestType); mDateView.setText(dateString); Double resultPpm = cursor.getDouble(cursor.getColumnIndex(TestTable.COLUMN_RESULT)); if (mTestTypeId == Globals.PH_INDEX) { mPpmText.setText(""); } else { mPpmText.setText(R.string.ppm); } if (resultPpm < 0) { mResultTextView.setText("0.0"); //mResultIcon.setVisibility(View.GONE); mPpmText.setVisibility(View.GONE); } else { mResultTextView.setText(String.format("%.2f", resultPpm)); Context context = getActivity().getApplicationContext(); int resourceAttribute; if (resultPpm <= Globals.FLUORIDE_MAX_DRINK) { resourceAttribute = R.attr.drink; } else if (resultPpm <= Globals.FLUORIDE_MAX_COOK) { resourceAttribute = R.attr.cook; } else if (resultPpm <= Globals.FLUORIDE_MAX_BATHE) { resourceAttribute = R.attr.bath; } else { resourceAttribute = R.attr.wash; } TypedArray a = context.getTheme().obtainStyledAttributes( ((MainApp) context.getApplicationContext()).CurrentTheme, new int[] { resourceAttribute }); int attributeResourceId = a.getResourceId(0, 0); //mResultIcon.setImageResource(attributeResourceId); //mResultIcon.setVisibility(View.VISIBLE); mPpmText.setVisibility(View.VISIBLE); } } cursor.close(); }
From source file:co.mrktplaces.android.ui.views.smarttablayout.SmartTabLayout.java
public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); final DisplayMetrics dm = getResources().getDisplayMetrics(); final float density = dm.density; int tabBackgroundResId = NO_ID; int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density); int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density); boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY; int customTabLayoutId = NO_ID; int customTabTextViewId = NO_ID; boolean clickable = TAB_CLICKABLE; int titleOffset = (int) (TITLE_OFFSET_DIPS * density); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0); tabBackgroundResId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_defaultTabBackground, tabBackgroundResId);/*from w w w. ja v a 2 s.c o m*/ textHorizontalPadding = a.getDimensionPixelSize( R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding); textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth, textMinWidth); customTabLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, customTabLayoutId); customTabTextViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, customTabTextViewId); distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly); clickable = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_clickable, clickable); titleOffset = a.getLayoutDimension(R.styleable.stl_SmartTabLayout_stl_titleOffset, titleOffset); a.recycle(); this.titleOffset = titleOffset; this.tabViewBackgroundResId = tabBackgroundResId; this.tabViewTextHorizontalPadding = textHorizontalPadding; this.tabViewTextMinWidth = textMinWidth; this.internalTabClickListener = clickable ? new InternalTabClickListener() : null; this.distributeEvenly = distributeEvenly; if (customTabLayoutId != NO_ID) { setCustomTabView(customTabLayoutId, customTabTextViewId); } this.tabStrip = new SmartTabStrip(context, attrs); if (distributeEvenly && tabStrip.isIndicatorAlwaysInCenter()) { throw new UnsupportedOperationException( "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support"); } // Make sure that the Tab Strips fills this View setFillViewport(!tabStrip.isIndicatorAlwaysInCenter()); addView(tabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); }
From source file:com.it520.activity.main.wight.SmartTabLayout.java
public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); final DisplayMetrics dm = getResources().getDisplayMetrics(); final float density = dm.density; int tabBackgroundResId = NO_ID; boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS; ColorStateList textColors;//from w w w .j a va 2 s. co m 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 customTabLayoutId = NO_ID; int customTabTextViewId = NO_ID; boolean clickable = TAB_CLICKABLE; int titleOffset = (int) (TITLE_OFFSET_DIPS * density); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0); tabBackgroundResId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_defaultTabBackground, tabBackgroundResId); textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps); textColors = a.getColorStateList(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor); 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); customTabLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, customTabLayoutId); customTabTextViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, customTabTextViewId); distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly); clickable = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_clickable, clickable); titleOffset = a.getLayoutDimension(R.styleable.stl_SmartTabLayout_stl_titleOffset, titleOffset); a.recycle(); this.titleOffset = titleOffset; this.tabViewBackgroundResId = tabBackgroundResId; this.tabViewTextAllCaps = textAllCaps; this.tabViewTextColors = (textColors != null) ? textColors : ColorStateList.valueOf(TAB_VIEW_TEXT_COLOR); this.tabViewTextSize = textSize; this.tabViewTextHorizontalPadding = textHorizontalPadding; this.tabViewTextMinWidth = textMinWidth; this.internalTabClickListener = clickable ? new InternalTabClickListener() : null; this.distributeEvenly = distributeEvenly; if (customTabLayoutId != NO_ID) { setCustomTabView(customTabLayoutId, customTabTextViewId); } this.tabStrip = new SmartTabStrip(context, attrs); if (distributeEvenly && tabStrip.isIndicatorAlwaysInCenter()) { throw new UnsupportedOperationException( "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support"); } // Make sure that the Tab Strips fills this View setFillViewport(!tabStrip.isIndicatorAlwaysInCenter()); addView(tabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); }
From source file:com.forrestguice.suntimeswidget.EquinoxView.java
private void initColors(Context context) { int[] colorAttrs = { android.R.attr.textColorPrimary }; //, R.attr.springColor, R.attr.summerColor, R.attr.fallColor, R.attr.winterColor }; TypedArray typedArray = context.obtainStyledAttributes(colorAttrs); int def = R.color.transparent; noteColor = ContextCompat.getColor(context, typedArray.getResourceId(0, def)); //springColor = ContextCompat.getColor(context, typedArray.getResourceId(1, def)); //summerColor = ContextCompat.getColor(context, typedArray.getResourceId(2, def)); //fallColor = ContextCompat.getColor(context, typedArray.getResourceId(3, def)); //winterColor = ContextCompat.getColor(context, typedArray.getResourceId(4, def)); typedArray.recycle();/*from w w w . j a v a 2s . c o m*/ }
From source file:android.support.graphics.drawable.AnimatedVectorDrawableCompat.java
@Override public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { if (mDelegateDrawable != null) { DrawableCompat.inflate(mDelegateDrawable, res, parser, attrs, theme); return;/*from w ww . j av a 2 s . c om*/ } int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { final String tagName = parser.getName(); if (DBG_ANIMATION_VECTOR_DRAWABLE) { Log.v(LOGTAG, "tagName is " + tagName); } if (ANIMATED_VECTOR.equals(tagName)) { final TypedArray a = obtainAttributes(res, theme, attrs, AndroidResources.styleable_AnimatedVectorDrawable); int drawableRes = a.getResourceId(AndroidResources.styleable_AnimatedVectorDrawable_drawable, 0); if (DBG_ANIMATION_VECTOR_DRAWABLE) { Log.v(LOGTAG, "drawableRes is " + drawableRes); } if (drawableRes != 0) { VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(res, drawableRes, theme); vectorDrawable.setAllowCaching(false); vectorDrawable.setCallback(mCallback); if (mAnimatedVectorState.mVectorDrawable != null) { mAnimatedVectorState.mVectorDrawable.setCallback(null); } mAnimatedVectorState.mVectorDrawable = vectorDrawable; } a.recycle(); } else if (TARGET.equals(tagName)) { final TypedArray a = res.obtainAttributes(attrs, AndroidResources.styleable_AnimatedVectorDrawableTarget); final String target = a.getString(AndroidResources.styleable_AnimatedVectorDrawableTarget_name); int id = a.getResourceId(AndroidResources.styleable_AnimatedVectorDrawableTarget_animation, 0); if (id != 0) { if (mContext != null) { Animator objectAnimator = AnimatorInflater.loadAnimator(mContext, id); setupAnimatorsForTarget(target, objectAnimator); } else { throw new IllegalStateException("Context can't be null when inflating" + " animators"); } } a.recycle(); } } eventType = parser.next(); } }
From source file:com.gitstudy.rili.liarbry.CalendarLayout.java
public CalendarLayout(Context context, AttributeSet attrs) { super(context, attrs); setOrientation(LinearLayout.VERTICAL); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CalendarLayout); mContentViewId = array.getResourceId(R.styleable.CalendarLayout_calendar_content_view_id, 0); mDefaultStatus = array.getInt(R.styleable.CalendarLayout_default_status, STATUS_EXPAND); mCalendarShowMode = array.getInt(R.styleable.CalendarLayout_calendar_show_mode, CALENDAR_SHOW_MODE_BOTH_MONTH_WEEK_VIEW); mGestureMode = array.getInt(R.styleable.CalendarLayout_gesture_mode, GESTURE_MODE_DEFAULT); array.recycle();// ww w .j a v a 2 s . c o m mVelocityTracker = VelocityTracker.obtain(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = configuration.getScaledTouchSlop(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
From source file:com.gu.baselibrary.view.dragtoplayout.DragTopLayout.java
private void init(AttributeSet attrs) { dragHelper = ViewDragHelper.create(this, 1.0f, callback); // init from attrs TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DragTopLayout); //setCollapseOffset(a.getDimensionPixelSize(R.styleable.DragTopLayout_dtlCollapseOffset, collapseOffset)); overDrag = a.getBoolean(R.styleable.DragTopLayout_dtlOverDrag, overDrag); dragContentViewId = a.getResourceId(R.styleable.DragTopLayout_dtlDragContentView, -1); topViewId = a.getResourceId(R.styleable.DragTopLayout_dtlTopView, -1); initOpen(a.getBoolean(R.styleable.DragTopLayout_dtlOpen, true)); captureTop = a.getBoolean(R.styleable.DragTopLayout_dtlCaptureTop, false); topDistance = a.getInt(R.styleable.DragTopLayout_topDistance, 250); a.recycle();//from w w w .ja va 2 s.c om }