List of usage examples for android.content.res TypedArray getResourceId
@AnyRes public int getResourceId(@StyleableRes int index, int defValue)
From source file:com.cheikh.lazywaimai.widget.SlidingTabLayout.java
public SlidingTabLayout(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);//from w ww. j av a 2 s .c o m mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density); mTabStrip = new SlidingTabStrip(context); addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout); if (a.hasValue(R.styleable.SlidingTabLayout_indicatorHeight)) { mTabStrip.setSelectedIndicatorHeight( a.getDimensionPixelSize(R.styleable.SlidingTabLayout_indicatorHeight, 0)); } if (a.hasValue(R.styleable.SlidingTabLayout_selectedColor)) { mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.SlidingTabLayout_selectedColor, 0)); } mTabViewTextAppearance = a.getResourceId(R.styleable.SlidingTabLayout_android_textAppearance, 0); mTitleOffset = a.getDimensionPixelSize(R.styleable.SlidingTabLayout_contentInsetStart, mTitleOffset); mTabStrip.setPadding(mTitleOffset, 0, 0, 0); a.recycle(); }
From source file:com.h6ah4i.android.materialshadowninepatch.MaterialShadowContainerView.java
private int[] getResourceIdArray(Resources resources, int id) { if (id == 0) { return null; }//from ww w. j a va2 s. c o m if (isInEditMode()) { return null; } TypedArray ta = resources.obtainTypedArray(id); int[] array = new int[ta.length()]; for (int i = 0; i < array.length; i++) { array[i] = ta.getResourceId(i, 0); } ta.recycle(); return array; }
From source file:com.example.xusoku.dragtopviewdemo.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, true); a.recycle();/*from www .j ava2 s. c o m*/ }
From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java
private void init(Context context, AttributeSet attrs) { Resources resources = getResources(); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner); int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit); setGravity(Gravity.CENTER_VERTICAL | Gravity.START); setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding, defaultPadding);//from ww w. jav a 2 s . c om setClickable(true); backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector, R.drawable.selector); setBackgroundResource(backgroundSelector); textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context)); setTextColor(textColor); listView = new ListView(context); // Set the spinner's id into the listview to make it pretend to be the right parent in // onItemClick listView.setId(getId()); listView.setDivider(new ColorDrawable(Color.GRAY)); listView.setDividerHeight(1); listView.setItemsCanFocus(true); //hide vertical and horizontal scrollbars listView.setVerticalScrollBarEnabled(false); listView.setHorizontalScrollBarEnabled(false); listView.setOverScrollMode(OVER_SCROLL_NEVER); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectedIndex = position; if (onItemClickListener != null) { onItemClickListener.onItemClick(parent, view, position, id); } if (onItemSelectedListener != null) { onItemSelectedListener.onItemSelected(parent, view, position, id); } adapter.setSelectedIndex(position); setTextInternal(adapter.getItemInDataset(position).toString()); dismissDropDown(); } }); popupWindow = new PopupWindow(context); popupWindow.setContentView(listView); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { popupWindow.setElevation(DEFAULT_ELEVATION); popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.spinner_drawable)); } else { popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.drop_down_shadow)); } popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { if (!isArrowHidden) { animateArrow(false); } } }); isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false); arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, Integer.MAX_VALUE); arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow); dropDownListPaddingBottom = typedArray .getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0); typedArray.recycle(); measureDisplayHeight(); }
From source file:com.github.hobbe.android.openkarotz.activity.MainActivity.java
/** * Put everything in place to provide the drawer: drawer layout, drawer toggle and drawer list. *///from w w w . j a v a 2 s.c o m private void initializeDrawer() { drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerList = (ListView) findViewById(R.id.drawer_list); drawerToggle = new DrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close); // Set the drawer shadow drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // Set the drawer toggle as the DrawerListener drawerLayout.setDrawerListener(drawerToggle); // Load page icons from resources TypedArray menuIcons = getResources().obtainTypedArray(R.array.pages_icons); // Create a drawer item per page ArrayList<DrawerItem> drawerItems = new ArrayList<DrawerItem>(); for (int i = 0; i < pageTitles.length; i++) { drawerItems.add(new DrawerItem(pageTitles[i], menuIcons.getResourceId(i, -1))); } // Recycle the typed array menuIcons.recycle(); // Creating the adapter to add items to the drawer list view DrawerListAdapter adapter = new DrawerListAdapter(getApplicationContext(), drawerItems); // Setting the adapter on drawerList drawerList.setAdapter(adapter); // Setting item click listener for the drawer list view drawerList.setOnItemClickListener(new DrawerItemClickListener()); }
From source file:com.android.inputmethod.keyboard.EmojiPalettesView.java
public EmojiPalettesView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView); mKeyBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_keyBackground, 0); mEmojiFunctionalKeyBackgroundId = keyboardViewAttr .getResourceId(R.styleable.KeyboardView_keyBackgroundEmojiFunctional, 0); keyboardViewAttr.recycle();/*from w w w.j av a 2 s . co m*/ final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs, R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView); mTabLabelColor = emojiPalettesViewAttr.getColorStateList(R.styleable.EmojiPalettesView_emojiTabLabelColor); emojiPalettesViewAttr.recycle(); final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(context, null /* editorInfo */); final Resources res = context.getResources(); final EmojiLayoutParams emojiLp = new EmojiLayoutParams(res); builder.setSubtype(SubtypeSwitcher.getInstance().getEmojiSubtype()); builder.setKeyboardGeometry(ResourceUtils.getDefaultKeyboardWidth(res), emojiLp.mEmojiKeyboardHeight); builder.setOptions(false, false, false /* lanuageSwitchKeyEnabled */); mLayoutSet = builder.build(); mEmojiCategory = new EmojiCategory(PreferenceManager.getDefaultSharedPreferences(context), context.getResources(), builder.build()); mDeleteKeyOnTouchListener = new DeleteKeyOnTouchListener(context); }
From source file:com.chibatching.imgindicatortab.ImgIndicatorTab.java
public ImgIndicatorTab(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) { return;/*from w w w . j a v a 2 s . c o m*/ } // Load default value float defaultTextSize = getResources().getDimension(R.dimen.iit_default_text_size); int defaultSelectedColor = getResources().getColor(R.color.iit_default_selected_text_color); int defaultDeselectedColor = getResources().getColor(R.color.iit_default_deselected_text_color); boolean defaultFitIndicator = getResources().getBoolean(R.bool.iit_default_fit_indicator_with_tab); // Load style attributes TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ImgIndicatorTab, defStyle, 0); setSelectedTextColor(ta.getColor(R.styleable.ImgIndicatorTab_selectedTextColor, defaultSelectedColor)); setDeselectedTextColor( ta.getColor(R.styleable.ImgIndicatorTab_deselectedTextColor, defaultDeselectedColor)); setIndicatorDrawable(ta.getDrawable(R.styleable.ImgIndicatorTab_indicatorDrawable)); setTextSize(ta.getDimension(R.styleable.ImgIndicatorTab_android_textSize, defaultTextSize)); setFitIndicator(ta.getBoolean(R.styleable.ImgIndicatorTab_fitIndicatorWithTabWidth, defaultFitIndicator)); int background = ta.getResourceId(R.styleable.ImgIndicatorTab_android_background, 0); if (background != 0) { setBackgroundResource(background); } ta.recycle(); }
From source file:android.support.v7.preference.PreferenceController.java
@Override @NonNull// w w w . java2 s. c o m public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container, @Nullable Bundle savedInstanceState) { mInitDone = false; mHavePrefs = false; final TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true); final int theme = tv.resourceId; if (theme == 0) { throw new IllegalStateException("Must specify preferenceTheme in theme"); } mStyledContext = new ContextThemeWrapper(getActivity(), theme); mPreferenceManager = new PreferenceManager(mStyledContext); final String rootKey = getArgs().getString(ARG_PREFERENCE_ROOT); onCreatePreferences(savedInstanceState, rootKey); TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat, R.attr.preferenceFragmentCompatStyle, 0); mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId); mDividerDecoration = new DividerDecoration(); final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider); final int dividerHeight = a .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1); final boolean allowDividerAfterLastItem = a .getBoolean(R.styleable.PreferenceFragmentCompat_allowDividerAfterLastItem, true); a.recycle(); 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); } mDividerDecoration.setAllowDividerAfterLastItem(allowDividerAfterLastItem); listContainer.addView(mList); mHandler.post(mRequestFocus); onViewCreated(view, savedInstanceState); return view; }
From source file:android.support.wear.widget.drawer.WearableDrawerView.java
private void parseAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { if (attrs == null) { return;// w ww. jav a 2 s. co m } TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.WearableDrawerView, defStyleAttr, R.style.Widget_Wear_WearableDrawerView); Drawable background = getDrawable(context, typedArray, R.styleable.WearableDrawerView_android_background); int elevation = typedArray.getDimensionPixelSize(R.styleable.WearableDrawerView_android_elevation, 0); setBackground(background); setElevation(elevation); mContentResId = typedArray.getResourceId(R.styleable.WearableDrawerView_drawerContent, 0); mPeekResId = typedArray.getResourceId(R.styleable.WearableDrawerView_peekView, 0); mCanAutoPeek = typedArray.getBoolean(R.styleable.WearableDrawerView_enableAutoPeek, mCanAutoPeek); typedArray.recycle(); }
From source file:com.community.yuequ.bottombar.BottomBar.java
private void populateAttributes(Context context, AttributeSet attrs) { primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary); screenWidth = MiscUtils.getScreenWidth(getContext()); tenDp = MiscUtils.dpToPixel(getContext(), 10); maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168); TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0); try {/*from w w w . j ava 2 s. co m*/ tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0); isTabletMode = ta.getBoolean(R.styleable.BottomBar_bb_tabletMode, false); behaviors = ta.getInteger(R.styleable.BottomBar_bb_behavior, BEHAVIOR_NONE); inActiveTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_inActiveTabAlpha, isShiftingMode() ? DEFAULT_INACTIVE_SHIFTING_TAB_ALPHA : 1); activeTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_activeTabAlpha, 1); @ColorInt int defaultInActiveColor = isShiftingMode() ? Color.WHITE : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor); int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor; inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor); activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor); badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED); titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0); titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace)); showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true); } finally { ta.recycle(); } }