List of usage examples for android.content.res TypedArray getResourceId
@AnyRes public int getResourceId(@StyleableRes int index, int defValue)
From source file:com.bowyoung.enhancelibrary.libs.swipeback.SwipeBackLayout.java
public void attachToActivity(BaseEnhanceActivity activity) { mActivity = activity;/*w ww .j a v a 2 s. co m*/ TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground }); int background = a.getResourceId(0, 0); a.recycle(); ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView(); ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); decorChild.setBackgroundResource(background); decor.removeView(decorChild); addView(decorChild); setContentView(decorChild); decor.addView(this); }
From source file:ccv.checkhelzio.nuevaagendacucsh.transitions.FabTransition.java
public FabTransition(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = null; try {//from w w w. j a v a 2 s.c o m a = context.obtainStyledAttributes(attrs, R.styleable.FabTransition); if (!a.hasValue(R.styleable.FabTransition_fabColor) || !a.hasValue(R.styleable.FabTransition_fabIcon)) { throw new IllegalArgumentException("Must provide both color & icon."); } color = a.getColor(R.styleable.FabTransition_fabColor, Color.TRANSPARENT); icon = a.getResourceId(R.styleable.FabTransition_fabIcon, 0); setPathMotion(new GravityArcMotion()); if (getDuration() < 0) { setDuration(DEFAULT_DURATION); } } finally { if (a != null) { a.recycle(); } } }
From source file:com.actionbarsherlock.internal.widget.ActionBarContextView.java
public ActionBarContextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionMode, defStyle, 0); setBackgroundDrawable(a.getDrawable(R.styleable.SherlockActionMode_background)); mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionMode_titleTextStyle, 0); mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionMode_subtitleTextStyle, 0); mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionMode_height, 0); mSplitBackground = a.getDrawable(R.styleable.SherlockActionMode_backgroundSplit); a.recycle();/*from ww w . ja v a2s .c om*/ }
From source file:com.hadis.mylunbo.carrousel.CircleIndicator.java
private void handleTypedArray(Context context, AttributeSet attrs) { if (attrs == null) { return;//from ww w .j ava2s. c o m } TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleIndicator); mIndicatorWidth = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_width, -1); mIndicatorHeight = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_height, -1); mIndicatorMargin = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_margin, -1); mAnimatorResId = typedArray.getResourceId(R.styleable.CircleIndicator_ci_animator, R.animator.scale_with_alpha); mAnimatorReverseResId = typedArray.getResourceId(R.styleable.CircleIndicator_ci_animator_reverse, 0); mIndicatorBackgroundResId = typedArray.getResourceId(R.styleable.CircleIndicator_ci_drawable, R.drawable.white_radius); mIndicatorUnselectedBackgroundResId = typedArray .getResourceId(R.styleable.CircleIndicator_ci_drawable_unselected, mIndicatorBackgroundResId); int orientation = typedArray.getInt(R.styleable.CircleIndicator_ci_orientation, -1); setOrientation(orientation == VERTICAL ? VERTICAL : HORIZONTAL); int gravity = typedArray.getInt(R.styleable.CircleIndicator_ci_gravity, -1); setGravity(gravity >= 0 ? gravity : Gravity.CENTER); typedArray.recycle(); }
From source file:com.github.ppamorim.dragger.DraggerView.java
/** * Map the layout attributes, the dragView and shadowView, after, find the view by id. * * @param attributes/*ww w . j av a 2s. com*/ */ private void mapGUI(TypedArray attributes) { if (getChildCount() == 2) { int dragViewId = attributes.getResourceId(R.styleable.dragger_layout_drag_view_id, R.id.drag_view); int shadowViewId = attributes.getResourceId(R.styleable.dragger_layout_shadow_view_id, R.id.shadow_view); if (dragViewId > 0) { dragView = findViewById(dragViewId); } if (shadowViewId > 0) { shadowView = findViewById(shadowViewId); } } else { throw new IllegalStateException("DraggerView must contains only two direct child"); } }
From source file:com.dycody.android.idealnote.async.MainMenuTask.java
private List<NavigationItem> buildMainMenu() { if (!isAlive()) { return new ArrayList<>(); }/* w ww . j av a2s .c o m*/ String[] mNavigationArray = mainActivity.getResources() .getStringArray(com.dycody.android.idealnote.R.array.navigation_list); TypedArray mNavigationIconsArray = mainActivity.getResources() .obtainTypedArray(com.dycody.android.idealnote.R.array.navigation_list_icons); TypedArray mNavigationIconsSelectedArray = mainActivity.getResources() .obtainTypedArray(com.dycody.android.idealnote.R.array.navigation_list_icons_selected); final List<NavigationItem> items = new ArrayList<>(); for (int i = 0; i < mNavigationArray.length; i++) { if (!checkSkippableItem(i)) { NavigationItem item = new NavigationItem(i, mNavigationArray[i], mNavigationIconsArray.getResourceId(i, 0), mNavigationIconsSelectedArray.getResourceId(i, 0)); items.add(item); } } return items; }
From source file:com.github.ppamorim.cult.CultView.java
/** * Initialize some attributes to provide * the height, padding and content to CultView */// w w w . jav a 2 s . c om private void getStyle(Context context, AttributeSet attrs, int defStyleAttr) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.cult_view, defStyleAttr, 0); toolbarHeight = (int) a.getDimension(R.styleable.cult_view_toolbar_height, DEFAULT_HEIGHT); innerPadding = (int) a.getDimension(R.styleable.cult_view_inner_padding, DEFAULT_PADDING); contentResId = a.getResourceId(R.styleable.cult_view_content_view, 0); a.recycle(); } }
From source file:com.ternup.caddisfly.fragment.ResultFragment.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 ww w.j a va 2 s . c o m 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:com.appeaser.sublimepickerlibrary.datepicker.DayPickerView.java
public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(SUtils.createThemeWrapper(context, R.attr.sublimePickerStyle, R.style.SublimePickerStyleLight, defStyleAttr, R.style.DayPickerViewStyle), attrs); context = getContext();/*from w w w. j a v a 2s . c o m*/ mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView, defStyleAttr, R.style.DayPickerViewStyle); final int monthTextAppearanceResId = a.getResourceId(R.styleable.DayPickerView_spMonthTextAppearance, R.style.SPMonthLabelTextAppearance); // verified final int dayOfWeekTextAppearanceResId = a.getResourceId(R.styleable.DayPickerView_spWeekDayTextAppearance, R.style.SPWeekDayLabelTextAppearance); // verified final int dayTextAppearanceResId = a.getResourceId(R.styleable.DayPickerView_spDateTextAppearance, R.style.SPDayTextAppearance); final ColorStateList daySelectorColor = a.getColorStateList(R.styleable.DayPickerView_spDaySelectorColor); a.recycle(); if (Config.DEBUG) { Log.i(TAG, "MDayPickerView_spmMonthTextAppearance: " + monthTextAppearanceResId); Log.i(TAG, "MDayPickerView_spmWeekDayTextAppearance: " + dayOfWeekTextAppearanceResId); Log.i(TAG, "MDayPickerView_spmDateTextAppearance: " + dayTextAppearanceResId); } // Set up adapter. mAdapter = new DayPickerPagerAdapter(context, R.layout.date_picker_month_item, R.id.month_view); mAdapter.setMonthTextAppearance(monthTextAppearanceResId); mAdapter.setDayOfWeekTextAppearance(dayOfWeekTextAppearanceResId); mAdapter.setDayTextAppearance(dayTextAppearanceResId); mAdapter.setDaySelectorColor(daySelectorColor); final LayoutInflater inflater = LayoutInflater.from(context); int layoutIdToUse, viewPagerIdToUse; if (getTag() != null && getTag() instanceof String && getResources().getString(R.string.recurrence_end_date_picker_tag).equals(getTag())) { layoutIdToUse = R.layout.day_picker_content_redp; viewPagerIdToUse = R.id.redp_view_pager; } else { layoutIdToUse = R.layout.day_picker_content_sdp; viewPagerIdToUse = R.id.sdp_view_pager; } inflater.inflate(layoutIdToUse, this, true); OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(View v) { final int direction; if (v == mPrevButton) { direction = -1; } else if (v == mNextButton) { direction = 1; } else { return; } // Animation is expensive for accessibility services since it sends // lots of scroll and content change events. final boolean animate = !mAccessibilityManager.isEnabled(); // ViewPager clamps input values, so we don't need to worry // about passing invalid indices. final int nextItem = mViewPager.getCurrentItem() + direction; mViewPager.setCurrentItem(nextItem, animate); } }; mPrevButton = (ImageButton) findViewById(R.id.prev); mPrevButton.setOnClickListener(onClickListener); mNextButton = (ImageButton) findViewById(R.id.next); mNextButton.setOnClickListener(onClickListener); ViewPager.OnPageChangeListener onPageChangedListener = new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { final float alpha = Math.abs(0.5f - positionOffset) * 2.0f; mPrevButton.setAlpha(alpha); mNextButton.setAlpha(alpha); } @Override public void onPageScrollStateChanged(int state) { } @Override public void onPageSelected(int position) { updateButtonVisibility(position); } }; mViewPager = (DayPickerViewPager) findViewById(viewPagerIdToUse); mViewPager.setAdapter(mAdapter); mViewPager.addOnPageChangeListener(onPageChangedListener); // Proxy the month text color into the previous and next buttons. if (monthTextAppearanceResId != 0) { final TypedArray ta = context.obtainStyledAttributes(null, ATTRS_TEXT_COLOR, 0, monthTextAppearanceResId); final ColorStateList monthColor = ta.getColorStateList(0); if (monthColor != null) { SUtils.setImageTintList(mPrevButton, monthColor); SUtils.setImageTintList(mNextButton, monthColor); } ta.recycle(); } // Proxy selection callbacks to our own listener. mAdapter.setDaySelectionEventListener(new DayPickerPagerAdapter.DaySelectionEventListener() { @Override public void onDaySelected(DayPickerPagerAdapter adapter, Calendar day) { if (mProxyDaySelectionEventListener != null) { mProxyDaySelectionEventListener.onDaySelected(DayPickerView.this, day); } } @Override public void onDateRangeSelectionStarted(@NonNull SelectedDate selectedDate) { if (mProxyDaySelectionEventListener != null) { mProxyDaySelectionEventListener.onDateRangeSelectionStarted(selectedDate); } } @Override public void onDateRangeSelectionEnded(@Nullable SelectedDate selectedDate) { if (mProxyDaySelectionEventListener != null) { mProxyDaySelectionEventListener.onDateRangeSelectionEnded(selectedDate); } } @Override public void onDateRangeSelectionUpdated(@NonNull SelectedDate selectedDate) { if (mProxyDaySelectionEventListener != null) { mProxyDaySelectionEventListener.onDateRangeSelectionUpdated(selectedDate); } } }); }
From source file:com.hippo.vector.AnimatedVectorDrawable.java
public void inflate(Context context, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { final AnimatedVectorDrawableState state = mAnimatedVectorState; int eventType = parser.getEventType(); float pathErrorScale = 1; while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { final String tagName = parser.getName(); if (ANIMATED_VECTOR.equals(tagName)) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedVectorDrawable); int drawableRes = a.getResourceId(R.styleable.AnimatedVectorDrawable_drawable, 0); if (drawableRes != 0) { VectorDrawable vectorDrawable = VectorDrawable.create(context, drawableRes); if (vectorDrawable != null) { vectorDrawable.setAllowCaching(false); vectorDrawable.setCallback(mCallback); pathErrorScale = vectorDrawable.getPixelSize(); if (state.mVectorDrawable != null) { state.mVectorDrawable.setCallback(null); }/*w ww . ja va 2 s. c om*/ state.mVectorDrawable = vectorDrawable; } } a.recycle(); } else if (TARGET.equals(tagName)) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedVectorDrawableTarget); final String target = a.getString(R.styleable.AnimatedVectorDrawableTarget_name); final int animResId = a.getResourceId(R.styleable.AnimatedVectorDrawableTarget_animation, 0); if (animResId != 0) { state.addTargetAnimator(target, AnimatorInflater.loadAnimator(context, animResId, pathErrorScale)); } a.recycle(); } } eventType = parser.next(); } }