List of usage examples for android.util TypedValue TypedValue
TypedValue
From source file:com.gh4a.BaseActivity.java
private ColorStateList createDefaultNavigationColorStateList(int baseColorThemeAttr) { TypedValue value = new TypedValue(); if (!getTheme().resolveAttribute(baseColorThemeAttr, value, true)) { return null; }/*from ww w.j a va 2s . c o m*/ ColorStateList baseColor = ContextCompat.getColorStateList(this, value.resourceId); if (!getTheme().resolveAttribute(android.support.design.R.attr.colorAccent, value, true)) { return null; } int colorAccent = value.data; int defaultColor = baseColor.getDefaultColor(); final int[] disabledStateSet = { -android.R.attr.state_enabled }; final int[] checkedStateSet = { android.R.attr.state_checked }; final int[][] states = { disabledStateSet, checkedStateSet, { 0 } }; final int[] colors = { baseColor.getColorForState(disabledStateSet, defaultColor), colorAccent, defaultColor }; return new ColorStateList(states, colors); }
From source file:com.heinrichreimersoftware.materialintro.app.IntroActivity.java
private void updateTaskDescription() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { String title = getTitle().toString(); Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager()); Bitmap icon = iconDrawable instanceof BitmapDrawable ? ((BitmapDrawable) iconDrawable).getBitmap() : null;// w w w . ja v a 2s. c o m int colorPrimary; if (position < getCount()) { try { colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position)); } catch (Resources.NotFoundException e) { colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackground(position)); } } else { TypedValue typedValue = new TypedValue(); TypedArray a = obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorPrimary }); colorPrimary = a.getColor(0, 0); a.recycle(); } colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF); setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary)); } }
From source file:android.com.example.contactslist.ui.ContactsListFragment.java
/** * Gets the preferred height for each item in the ListView, in pixels, after accounting for * screen density. ImageLoader uses this value to resize thumbnail images to match the ListView * item height./*from w ww. ja v a 2 s. c o m*/ * * @return The preferred height in pixels, based on the current theme. */ private int getListPreferredItemHeight() { final TypedValue typedValue = new TypedValue(); // Resolve list item preferred height theme attribute into typedValue getActivity().getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, typedValue, true); // Create a new DisplayMetrics object final DisplayMetrics metrics = new DisplayMetrics(); // Populate the DisplayMetrics getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); // Return theme value based on DisplayMetrics return (int) typedValue.getDimension(metrics); }
From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java
private CharSequence generateFastForwardOrRewindTxt(long changingTime) { long duration = player == null ? 0 : player.getDuration(); String result = stringForTime(changingTime) + " / " + stringForTime(duration); int index = result.indexOf("/"); SpannableString spannableString = new SpannableString(result); TypedValue typedValue = new TypedValue(); TypedArray a = getContext().obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent }); int color = a.getColor(0, 0); a.recycle();/*from w w w.ja va2s . co m*/ spannableString.setSpan(new ForegroundColorSpan(color), 0, index, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:com.miz.functions.MizLib.java
public static int getActionBarHeight(Context c) { int actionBarHeight = 0; TypedValue tv = new TypedValue(); if (c.getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics()); else// www .java 2s .c o m actionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme) return actionBarHeight; }
From source file:br.com.mybaby.contatos.ContactsListFragment.java
/** * Gets the preferred height for each item in the ListView, in pixels, after accounting for * screen density. ImageLoader uses this value to resize thumbnail images to match the ListView * item height.// w ww . j ava2 s.c om * * @return The preferred height in pixels, based on the current theme. */ private int getListPreferredItemHeight() { final TypedValue typedValue = new TypedValue(); // Resolve list item preferred height theme attribute into typedValue getActivity().getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, typedValue, true); // Create a new DisplayMetrics object final DisplayMetrics metrics = new android.util.DisplayMetrics(); // Populate the DisplayMetrics getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); // Return theme value based on DisplayMetrics return (int) typedValue.getDimension(metrics); }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
@Override ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) { if (mActionMode != null) { mActionMode.finish();//w w w . j av a 2s . c om } final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback); final Context context = getActionBarThemedContext(); if (mActionModeView == null) { if (mIsFloating) { mActionModeView = new ActionBarContextView(context); mActionModePopup = new PopupWindow(context, null, R.attr.actionModePopupWindowStyle); mActionModePopup.setContentView(mActionModeView); mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); TypedValue heightValue = new TypedValue(); mContext.getTheme().resolveAttribute(R.attr.actionBarSize, heightValue, true); final int height = TypedValue.complexToDimensionPixelSize(heightValue.data, mContext.getResources().getDisplayMetrics()); mActionModeView.setContentHeight(height); mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mShowActionModePopup = new Runnable() { public void run() { mActionModePopup.showAtLocation(mActionModeView, Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0); } }; } else { ViewStubCompat stub = (ViewStubCompat) mSubDecor.findViewById(R.id.action_mode_bar_stub); if (stub != null) { // Set the layout inflater so that it is inflated with the action bar's context stub.setLayoutInflater(LayoutInflater.from(context)); mActionModeView = (ActionBarContextView) stub.inflate(); } } } if (mActionModeView != null) { mActionModeView.killMode(); ActionMode mode = new StandaloneActionMode(context, mActionModeView, wrappedCallback, mActionModePopup == null); if (callback.onCreateActionMode(mode, mode.getMenu())) { mode.invalidate(); mActionModeView.initForMode(mode); mActionModeView.setVisibility(View.VISIBLE); mActionMode = mode; if (mActionModePopup != null) { mWindow.getDecorView().post(mShowActionModePopup); } mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); if (mActionModeView.getParent() != null) { ViewCompat.requestApplyInsets((View) mActionModeView.getParent()); } } else { mActionMode = null; } } if (mActionMode != null && mAppCompatCallback != null) { mAppCompatCallback.onSupportActionModeStarted(mActionMode); } return mActionMode; }
From source file:co.codecrunch.musicplayerlite.activities.MusicPlayerBaseActivity.java
private void systembartiteniam() { try {/*from w w w .jav a 2s .c o m*/ setTranslucentStatus(true); TypedValue typedValueStatusBarColor = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValueStatusBarColor, true); final int colorStatusBar = typedValueStatusBarColor.data; SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor(colorStatusBar); } catch (Exception e) { e.printStackTrace(); } }