List of usage examples for android.util TypedValue TypedValue
TypedValue
From source file:com.github.shareme.gwsmaterialdrawer.library.DrawerView.java
private void updateDrawerWidth() { Log.d(TAG, "updateDrawerWidth()"); int viewportWidth = getContext().getResources().getDisplayMetrics().widthPixels; int viewportHeight = getContext().getResources().getDisplayMetrics().heightPixels; //Minus the width of the vertical nav bar if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { int navigationBarWidthResId = getResources().getIdentifier("navigation_bar_width", "dimen", "android"); if (navigationBarWidthResId > 0) { viewportWidth -= getResources().getDimensionPixelSize(navigationBarWidthResId); }// w w w . j av a2s .com } int viewportMin = Math.min(viewportWidth, viewportHeight); //App bar size TypedValue typedValue = new TypedValue(); getContext().getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true); int actionBarSize = TypedValue.complexToDimensionPixelSize(typedValue.data, getResources().getDisplayMetrics()); int width = viewportMin - actionBarSize; getLayoutParams().width = Math.min(width, drawerMaxWidth); updateProfileSpacing(); }
From source file:android.support.design.widget.BottomNavigationView.java
private ColorStateList createDefaultColorStateList(int baseColorThemeAttr) { final TypedValue value = new TypedValue(); if (!getContext().getTheme().resolveAttribute(baseColorThemeAttr, value, true)) { return null; }//from w w w .j a v a2s. c om ColorStateList baseColor = AppCompatResources.getColorStateList(getContext(), value.resourceId); if (!getContext().getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.colorPrimary, value, true)) { return null; } int colorPrimary = value.data; int defaultColor = baseColor.getDefaultColor(); return new ColorStateList(new int[][] { DISABLED_STATE_SET, CHECKED_STATE_SET, EMPTY_STATE_SET }, new int[] { baseColor.getColorForState(DISABLED_STATE_SET, defaultColor), colorPrimary, defaultColor }); }
From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java
private void setDefaultDrawerBackground() { TypedValue value = new TypedValue(); if (mContext.getTheme().resolveAttribute(android.R.attr.colorBackground, value, true)) { mDrawerBackground = new ColorDrawable(value.data); } else {//from www. j a v a 2s . c om mDrawerBackground = new ColorDrawable(mDefaultTheme == DefaultTheme.LIGHT ? mContext.getResources().getColor(R.color.snv_background_material_light) : mContext.getResources().getColor(R.color.snv_background_material_dark)); } }
From source file:com.it520.activity.main.wight.SmartTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.//from www . j av a2s . c o m */ protected TextView createDefaultTabView(CharSequence title) { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(title); textView.setTextColor(tabViewTextColors); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (tabViewBackgroundResId != NO_ID) { textView.setBackgroundResource(tabViewBackgroundResId); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(tabViewTextAllCaps); } textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { textView.setMinWidth(tabViewTextMinWidth); } return textView; }
From source file:android.support.v7.internal.app.ToolbarActionBar.java
private void ensureListMenuPresenter(Menu menu) { if (mListMenuPresenter == null && (menu instanceof MenuBuilder)) { MenuBuilder mb = (MenuBuilder) menu; Context context = mDecorToolbar.getContext(); final TypedValue outValue = new TypedValue(); final Resources.Theme widgetTheme = context.getResources().newTheme(); widgetTheme.setTo(context.getTheme()); // Apply the panelMenuListTheme widgetTheme.resolveAttribute(R.attr.panelMenuListTheme, outValue, true); if (outValue.resourceId != 0) { widgetTheme.applyStyle(outValue.resourceId, true); } else {//www .j av a 2 s .c om widgetTheme.applyStyle(R.style.Theme_AppCompat_CompactMenu, true); } context = new ContextThemeWrapper(context, 0); context.getTheme().setTo(widgetTheme); // Finally create the list menu presenter mListMenuPresenter = new ListMenuPresenter(context, R.layout.abc_list_menu_item_layout); mListMenuPresenter.setCallback(new PanelMenuPresenterCallback()); mb.addMenuPresenter(mListMenuPresenter); } }
From source file:com.albedinsky.android.ui.navigation.NavigationLayout.java
/** * Ensures that a toolbar widget is contained within the current view hierarchy of this navigation * layout. If not it will be inflated from a layout resource presented within the current theme * and inserted into this layout at the proper place. *//*from ww w. j ava2 s . c o m*/ private void ensureToolbarWithinLayout() { final View toolbar = findViewById(R.id.ui_toolbar); if (toolbar == null) { final ViewGroup contentLayout = (ViewGroup) findViewById(R.id.ui_navigation_layout_content); if (contentLayout != null) { final Context context = getContext(); final TypedValue typedValue = new TypedValue(); if (context.getTheme().resolveAttribute(R.attr.uiNavigationToolbarLayout, typedValue, true)) { // Insert the Toolbar above the content container. contentLayout.addView(mLayoutInflater.inflate(typedValue.resourceId, contentLayout, false), 0); } } } }
From source file:com.albedinsky.android.ui.widget.SearchView.java
/** * Called from one of constructors of this view to perform its initialization. * <p>// w ww. ja v a2 s. c o m * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this view specific data from it that can be used to configure this new view instance. The * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data * from the current theme provided by the specified <var>context</var>. */ @SuppressWarnings("ResourceType") private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { this.mContext = context; setOrientation(HORIZONTAL); setGravity(Gravity.CENTER_VERTICAL); this.inflateHierarchy(context, R.layout.ui_search_view); this.mProgressBarAnimator = createProgressBarAnimator(); this.mDefaultRevealAnimationHandler = createRevealAnimationHandler(); ColorStateList tintList = null; PorterDuff.Mode tintMode = PorterDuff.Mode.SRC_IN; /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SearchView, defStyleAttr, defStyleRes); if (typedArray != null) { final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_SearchView_android_queryHint) { setQueryHint(typedArray.getText(index)); } else if (index == R.styleable.Ui_SearchView_uiTint) { tintList = typedArray.getColorStateList(index); } else if (index == R.styleable.Ui_SearchView_uiTintMode) { tintMode = TintManager.parseTintMode(typedArray.getInt(R.styleable.Ui_SearchView_uiTintMode, 0), tintList != null ? PorterDuff.Mode.SRC_IN : null); } else if (index == R.styleable.Ui_SearchView_uiRevealDuration) { mDefaultRevealAnimationHandler.revealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiConcealDuration) { mDefaultRevealAnimationHandler.concealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiRevealInterpolator) { final int resId = typedArray.getResourceId(index, 0); if (resId != 0) { mDefaultRevealAnimationHandler.interpolator = AnimationUtils.loadInterpolator(context, resId); } } } typedArray.recycle(); } if (tintList != null || tintMode != null) { this.mTintInfo = new SearchTintInfo(); this.mTintInfo.tintList = tintList; this.mTintInfo.hasTintList = tintList != null; this.mTintInfo.tintMode = tintMode; this.mTintInfo.hasTintMode = tintMode != null; } final Resources.Theme theme = context.getTheme(); final TypedValue typedValue = new TypedValue(); if (theme.resolveAttribute(R.attr.uiSearchSelectHandleColor, typedValue, true)) { if (mTintInfo == null) { this.mTintInfo = new SearchTintInfo(); } if (typedValue.resourceId > 0) { mTintInfo.textSelectHandleTintList = ResourceUtils.getColorStateList(getResources(), typedValue.resourceId, theme); } else { mTintInfo.textSelectHandleTintList = ColorStateList.valueOf(typedValue.data); } mTintInfo.hasTextSelectHandleTintList = mTintInfo.textSelectHandleTintList != null; } this.applyTint(); this.mRevealAnimationHandler = mDefaultRevealAnimationHandler; }
From source file:com.evandroid.musica.MainLyricActivity.java
@TargetApi(21) public void setStatusBarColor(Integer color) { if (Build.VERSION.SDK_INT >= 20) { if (color == null) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = getTheme(); theme.resolveAttribute(android.R.attr.statusBarColor, typedValue, true); color = typedValue.data;/*from w w w .ja v a2s .c om*/ } getWindow().setStatusBarColor(color); } }
From source file:cn.scujcc.bug.bitcoinplatformandroid.view.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab * view is not set via {@link #setCustomTabView(int, int)}. *//*w w w . j a v a 2 s . c o m*/ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setWidth(screenX); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the // Theme's // selectableItemBackground to ensure that the View has a pressed // state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the // Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:android.support.v7.app.ToolbarActionBar.java
private void ensureListMenuPresenter(Menu menu) { if (mListMenuPresenter == null && (menu instanceof MenuBuilder)) { MenuBuilder mb = (MenuBuilder) menu; Context context = mDecorToolbar.getContext(); final TypedValue outValue = new TypedValue(); final Resources.Theme widgetTheme = context.getResources().newTheme(); widgetTheme.setTo(context.getTheme()); // First apply the actionBarPopupTheme widgetTheme.resolveAttribute(R.attr.actionBarPopupTheme, outValue, true); if (outValue.resourceId != 0) { widgetTheme.applyStyle(outValue.resourceId, true); }//from www . j a v a 2s . c om // Apply the panelMenuListTheme widgetTheme.resolveAttribute(R.attr.panelMenuListTheme, outValue, true); if (outValue.resourceId != 0) { widgetTheme.applyStyle(outValue.resourceId, true); } else { widgetTheme.applyStyle(R.style.Theme_AppCompat_CompactMenu, true); } context = new ContextThemeWrapper(context, 0); context.getTheme().setTo(widgetTheme); // Finally create the list menu presenter mListMenuPresenter = new ListMenuPresenter(context, R.layout.abc_list_menu_item_layout); mListMenuPresenter.setCallback(new PanelMenuPresenterCallback()); mb.addMenuPresenter(mListMenuPresenter); } }