List of usage examples for android.content.res TypedArray getResourceId
@AnyRes public int getResourceId(@StyleableRes int index, int defValue)
From source file:com.boha.malengagolf.library.util.PagerTitleStrip22.java
public PagerTitleStrip22(Context context, AttributeSet attrs) { super(context, attrs); addView(mPrevText = new TextView(context)); addView(mCurrText = new TextView(context)); addView(mNextText = new TextView(context)); final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); final int textAppearance = a.getResourceId(0, 0); if (textAppearance != 0) { mPrevText.setTextAppearance(context, textAppearance); mCurrText.setTextAppearance(context, textAppearance); mNextText.setTextAppearance(context, textAppearance); }/*from w w w.j av a 2 s . co m*/ final int textSize = a.getDimensionPixelSize(1, 0); if (textSize != 0) { setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); } if (a.hasValue(2)) { final int textColor = a.getColor(2, 0); mPrevText.setTextColor(textColor); mCurrText.setTextColor(textColor); mNextText.setTextColor(textColor); } mGravity = a.getInteger(3, Gravity.BOTTOM); a.recycle(); mTextColor = mCurrText.getTextColors().getDefaultColor(); setNonPrimaryAlpha(SIDE_ALPHA); mPrevText.setEllipsize(TruncateAt.END); mCurrText.setEllipsize(TruncateAt.END); mNextText.setEllipsize(TruncateAt.END); boolean allCaps = false; if (textAppearance != 0) { final TypedArray ta = context.obtainStyledAttributes(textAppearance, TEXT_ATTRS); allCaps = ta.getBoolean(0, false); ta.recycle(); } if (allCaps) { setSingleLineAllCaps(mPrevText); setSingleLineAllCaps(mCurrText); setSingleLineAllCaps(mNextText); } else { mPrevText.setSingleLine(); mCurrText.setSingleLine(); mNextText.setSingleLine(); } final float density = context.getResources().getDisplayMetrics().density; mScaledTextSpacing = (int) (TEXT_SPACING * density); }
From source file:com.iangclifton.android.floatlabel.FloatLabel.java
private void init(Context context, AttributeSet attrs, int defStyle) { // Load custom attributes final int layout; final CharSequence text; final CharSequence hint; final ColorStateList hintColor; final int floatLabelColor; final int inputType; if (attrs == null) { layout = R.layout.float_label; text = null;/*from w w w . j a v a 2s.co m*/ hint = null; hintColor = null; floatLabelColor = 0; inputType = 0; } else { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabel, defStyle, 0); layout = a.getResourceId(R.styleable.FloatLabel_android_layout, R.layout.float_label); text = a.getText(R.styleable.FloatLabel_android_text); hint = a.getText(R.styleable.FloatLabel_android_hint); hintColor = a.getColorStateList(R.styleable.FloatLabel_android_textColorHint); floatLabelColor = a.getColor(R.styleable.FloatLabel_floatLabelColor, 0); inputType = a.getInt(R.styleable.FloatLabel_android_inputType, InputType.TYPE_CLASS_TEXT); a.recycle(); } inflate(context, layout, this); mEditText = (EditText) findViewById(R.id.edit_text); if (mEditText == null) { throw new RuntimeException("Your layout must have an EditText whose ID is @id/edit_text"); } mEditText.setHint(hint); mEditText.setText(text); if (hintColor != null) { mEditText.setHintTextColor(hintColor); } if (inputType != 0) { mEditText.setInputType(inputType); } mLabel = (TextView) findViewById(R.id.float_label); if (mLabel == null) { throw new RuntimeException("Your layout must have a TextView whose ID is @id/float_label"); } mLabel.setText(mEditText.getHint()); if (floatLabelColor != 0) mLabel.setTextColor(floatLabelColor); // Listen to EditText to know when it is empty or nonempty mEditText.addTextChangedListener(new EditTextWatcher()); // Check current state of EditText if (mEditText.getText().length() == 0) { ViewHelper.setAlpha(mLabel, 0); mLabelShowing = false; } else { mLabel.setVisibility(View.VISIBLE); mLabelShowing = true; } // Mark init as complete to prevent accidentally breaking the view by // adding children mInitComplete = true; }
From source file:app.newbee.lib.swipeback.SwipeBackLayout.java
public void attachToActivity(Activity activity) { mActivity = activity;/*from ww w . j ava 2 s . c om*/ 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().findViewById(Window.ID_ANDROID_CONTENT); ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); decorChild.setBackgroundResource(background); decor.removeView(decorChild); addView(decorChild); setContentView(decorChild); decor.addView(this); }
From source file:com.mikecorrigan.trainscorekeeper.FragmentSummary.java
@SuppressLint("NewApi") @Override//from w w w . j av a 2 s . c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState)); View rootView = inflater.inflate(R.layout.fragment_summary, container, false); final MainActivity activity = (MainActivity) getActivity(); final Context context = activity; final Resources resources = context.getResources(); // Get the model and attach a listener. game = activity.getGame(); if (game != null) { game.addListener(mGameListener); } players = activity.getPlayers(); // Get resources. String[] playerNames = resources.getStringArray(R.array.playerNames); TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables); TypedArray playerTextColorsArray = resources.obtainTypedArray(R.array.playerTextColors); int[] playerTextColorsIds = new int[playerTextColorsArray.length()]; for (int i = 0; i < playerTextColorsArray.length(); i++) { playerTextColorsIds[i] = playerTextColorsArray.getResourceId(i, -1); } // Get root view. ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.scroll_view); // Create table. tableLayout = new TableLayout(context); TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); tableLayout.setLayoutParams(tableLayoutParams); scrollView.addView(tableLayout); // Add header. { TableRow row = new TableRow(context); row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tableLayout.addView(row); TextView tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.player)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.trains)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.contracts)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); tv.setText(resources.getString(R.string.bonuses)); tv.setTypeface(null, Typeface.BOLD); row.addView(tv); } // Add rows. for (int i = 0; i < players.getNum(); i++) { TableRow row = new TableRow(context); row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); tableLayout.addView(row); ToggleButton toggleButton = new ToggleButton(context); toggleButton.setGravity(Gravity.CENTER); toggleButton.setPadding(10, 10, 10, 10); toggleButton.setText(playerNames[i]); toggleButton.setClickable(false); Drawable drawable = drawablesArray.getDrawable(i); int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { toggleButton.setBackgroundDrawable(drawable); } else { toggleButton.setBackground(drawable); } toggleButton.setTextColor(resources.getColor(playerTextColorsIds[i])); row.addView(toggleButton); TextView tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); tv = new TextView(context); tv.setGravity(Gravity.CENTER); tv.setPadding(10, 10, 10, 10); row.addView(tv); } Bundle args = getArguments(); if (args == null) { Log.e(TAG, "onCreateView: missing arguments"); return rootView; } drawablesArray.recycle(); playerTextColorsArray.recycle(); // final int index = args.getInt(ARG_INDEX); // final String tabSpec = args.getString(ARG_TAB_SPEC); return rootView; }
From source file:com.cocosw.framework.core.Base.java
@SuppressWarnings("deprecation") @Override// w w w.j a va 2 s .c o m protected void onCreate(final Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); } catch (Exception e) { //workround for V7 appcompact } LifecycleDispatcher.get().onActivityCreated(this, savedInstanceState); q = q == null ? new CocoQuery(this) : q; setContentView(layoutId()); tintManager = new SystemBarTintManager(this); ActionBar ab = getSupportActionBar(); if (ab != null) { ab.setDisplayHomeAsUpEnabled(true); } // enable status bar tint tintManager.setStatusBarTintEnabled(true); // enable navigation bar tint tintManager.setNavigationBarTintEnabled(true); if (UIUtils.hasKitKat()) { TypedValue typedValue = new TypedValue(); try { getTheme().resolveAttribute( getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA).theme, typedValue, true); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } int[] attribute = new int[] { R.attr.colorPrimary, R.attr.colorPrimaryDark, R.attr.navigationBarColor, R.attr.statusBarColor }; TypedArray array = this.obtainStyledAttributes(typedValue.resourceId, attribute); int colorPrimary = array.getResourceId(0, R.color.black); int colorPrimaryDark = array.getResourceId(1, -1); int navigationBarColor = array.getResourceId(2, -1); int statusBarColor = array.getResourceId(3, -1); colorPrimaryDark = colorPrimaryDark < 0 ? colorPrimary : colorPrimaryDark; navigationBarColor = navigationBarColor < 0 ? colorPrimaryDark : navigationBarColor; statusBarColor = statusBarColor < 0 ? colorPrimaryDark : statusBarColor; tintManager.setStatusBarTintResource(statusBarColor); tintManager.setNavigationBarTintResource(navigationBarColor); } ButterKnife.inject(this); // use Retained Fragment to handle runtime changes if (hasRetainData()) { FragmentManager fm = getSupportFragmentManager(); retainedFragment = (RetainedFragment) fm.findFragmentByTag(TAG_RETAINED_STATE_FRAGMENT); // create the fragment and data the first time if (retainedFragment == null) { // add the fragment retainedFragment = new RetainedFragment(); fm.beginTransaction().add(retainedFragment, TAG_RETAINED_STATE_FRAGMENT).commit(); } } try { init(savedInstanceState); } catch (final RuntimeException e) { ExceptionManager.error(e, this); return; } catch (final Exception e) { ExceptionManager.error(e, this); finish(); return; } onStartLoading(); getSupportLoaderManager().initLoader(this.hashCode(), getIntent().getExtras(), this); }
From source file:com.android.inputmethod.keyboard.emoji.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); final int keyBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_keyBackground, 0); mFunctionalKeyBackgroundId = keyboardViewAttr .getResourceId(R.styleable.KeyboardView_functionalKeyBackground, keyBackgroundId); mSpacebarBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_spacebarBackground, keyBackgroundId);/* w ww. jav a 2s. co m*/ keyboardViewAttr.recycle(); final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(context, null /* editorInfo */); final Resources res = context.getResources(); mEmojiLayoutParams = new EmojiLayoutParams(res); builder.setSubtype(RichInputMethodSubtype.getEmojiSubtype()); builder.setKeyboardGeometry(ResourceUtils.getDefaultKeyboardWidth(res), mEmojiLayoutParams.mEmojiKeyboardHeight); final KeyboardLayoutSet layoutSet = builder.build(); final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs, R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView); mEmojiCategory = new EmojiCategory(PreferenceManager.getDefaultSharedPreferences(context), res, layoutSet, emojiPalettesViewAttr); mCategoryIndicatorEnabled = emojiPalettesViewAttr .getBoolean(R.styleable.EmojiPalettesView_categoryIndicatorEnabled, false); mCategoryIndicatorDrawableResId = emojiPalettesViewAttr .getResourceId(R.styleable.EmojiPalettesView_categoryIndicatorDrawable, 0); mCategoryIndicatorBackgroundResId = emojiPalettesViewAttr .getResourceId(R.styleable.EmojiPalettesView_categoryIndicatorBackground, 0); mCategoryPageIndicatorColor = emojiPalettesViewAttr .getColor(R.styleable.EmojiPalettesView_categoryPageIndicatorColor, 0); mCategoryPageIndicatorBackground = emojiPalettesViewAttr .getColor(R.styleable.EmojiPalettesView_categoryPageIndicatorBackground, 0); emojiPalettesViewAttr.recycle(); mDeleteKeyOnTouchListener = new DeleteKeyOnTouchListener(); }
From source file:com.jinzht.pro.smarttablayout.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);/*from w w w .j a va 2 s. co m*/ final DisplayMetrics dm = getResources().getDisplayMetrics(); final float density = dm.density; int tabBackgroundResId = NO_ID; boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS; ColorStateList textColors; 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; 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); a.recycle(); this.titleOffset = (int) (TITLE_OFFSET_DIPS * density); 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.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"); } addView(tabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); }
From source file:com.bupt.booktrade.activity.MainActivity.java
private void initNavDrawerItems() { // load slide menu items navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items); // nav drawer icons from resources TypedArray navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons); ArrayList<NavDrawerItem> navDrawerItems = new ArrayList<>(); // Posts List navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1))); // New Post/*from ww w.j ava 2 s . com*/ navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1))); // Message navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1))); // Setting navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1))); // About navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1))); // Recycle the typed array navMenuIcons.recycle(); // setting the nav drawer list adapter NavDrawerListAdapter adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems); mDrawerList.setAdapter(adapter); }
From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java
public SwipeMenuLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwipeMenuLayout); mLeftViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_leftViewId, mLeftViewId); mContentViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_contentViewId, mContentViewId); mRightViewId = typedArray.getResourceId(R.styleable.SwipeMenuLayout_rightViewId, mRightViewId); typedArray.recycle();/* w ww . java 2s . c o m*/ ViewConfiguration mViewConfig = ViewConfiguration.get(getContext()); mScaledTouchSlop = mViewConfig.getScaledTouchSlop(); mScroller = new OverScroller(getContext()); mScaledMinimumFlingVelocity = mViewConfig.getScaledMinimumFlingVelocity(); mScaledMaximumFlingVelocity = mViewConfig.getScaledMaximumFlingVelocity(); }
From source file:android.support.wear.widget.CircularProgressLayout.java
public CircularProgressLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); mProgressDrawable = new CircularProgressDrawable(context); mProgressDrawable.setProgressRotation(DEFAULT_ROTATION); mProgressDrawable.setStrokeCap(Paint.Cap.BUTT); setBackground(mProgressDrawable);//from ww w . ja va 2 s . co m // If a child view is added, make it center aligned so it fits in the progress drawable. setOnHierarchyChangeListener(new OnHierarchyChangeListener() { @Override public void onChildViewAdded(View parent, View child) { // Ensure that child view is aligned in center LayoutParams params = (LayoutParams) child.getLayoutParams(); params.gravity = Gravity.CENTER; child.setLayoutParams(params); } @Override public void onChildViewRemoved(View parent, View child) { } }); mController = new CircularProgressLayoutController(this); Resources r = context.getResources(); TypedArray a = r.obtainAttributes(attrs, R.styleable.CircularProgressLayout); if (a.getType(R.styleable.CircularProgressLayout_colorSchemeColors) == TypedValue.TYPE_REFERENCE || !a.hasValue(R.styleable.CircularProgressLayout_colorSchemeColors)) { int arrayResId = a.getResourceId(R.styleable.CircularProgressLayout_colorSchemeColors, R.array.circular_progress_layout_color_scheme_colors); setColorSchemeColors(getColorListFromResources(r, arrayResId)); } else { setColorSchemeColors(a.getColor(R.styleable.CircularProgressLayout_colorSchemeColors, Color.BLACK)); } setStrokeWidth(a.getDimensionPixelSize(R.styleable.CircularProgressLayout_strokeWidth, r.getDimensionPixelSize(R.dimen.circular_progress_layout_stroke_width))); setBackgroundColor(a.getColor(R.styleable.CircularProgressLayout_backgroundColor, ContextCompat.getColor(context, R.color.circular_progress_layout_background_color))); setIndeterminate(a.getBoolean(R.styleable.CircularProgressLayout_indeterminate, false)); a.recycle(); }