List of usage examples for android.util TypedValue TypedValue
TypedValue
From source file:com.cocosw.framework.core.Base.java
@SuppressWarnings("deprecation") @Override/*from www .j ava 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.cyanogenmod.eleven.ui.activities.BaseActivity.java
/** * {@inheritDoc}// w w w .ja v a2s. co m */ @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Fade it in overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); // Control the media volume setVolumeControlStream(AudioManager.STREAM_MUSIC); // Bind Apollo's service mToken = MusicUtils.bindToService(this, this); // Initialize the broadcast receiver mPlaybackStatus = new PlaybackStatus(this); // Calculate ActionBar height TypedValue value = new TypedValue(); if (getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true)) { mActionBarHeight = TypedValue.complexToDimensionPixelSize(value.data, getResources().getDisplayMetrics()); } // Set the layout setContentView(setContentView()); mToolBar = (Toolbar) findViewById(R.id.toolbar); setActionBar(mToolBar); getActionBar().setTitle(getString(R.string.app_name).toUpperCase()); // set the background on the root view getWindow().getDecorView().getRootView() .setBackgroundColor(getResources().getColor(R.color.background_color)); // Initialze the bottom action bar initBottomActionBar(); // listen to changes to the cache status ImageFetcher.getInstance(this).addCacheListener(this); }
From source file:com.jaredrummler.android.colorpicker.ColorPanelView.java
private void init(Context context, AttributeSet attrs) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPanelView); shape = a.getInt(R.styleable.ColorPanelView_cpv_colorShape, ColorShape.CIRCLE); showOldColor = a.getBoolean(R.styleable.ColorPanelView_cpv_showOldColor, false); if (showOldColor && shape != ColorShape.CIRCLE) { throw new IllegalStateException("Color preview is only available in circle mode"); }/*from w w w . j a v a 2s .c o m*/ borderColor = a.getColor(R.styleable.ColorPanelView_cpv_borderColor, DEFAULT_BORDER_COLOR); a.recycle(); if (borderColor == DEFAULT_BORDER_COLOR) { // If no specific border color has been set we take the default secondary text color as border/slider color. // Thus it will adopt to theme changes automatically. final TypedValue value = new TypedValue(); TypedArray typedArray = context.obtainStyledAttributes(value.data, new int[] { android.R.attr.textColorSecondary }); borderColor = typedArray.getColor(0, borderColor); typedArray.recycle(); } borderWidthPx = DrawingUtils.dpToPx(context, 1); borderPaint = new Paint(); borderPaint.setAntiAlias(true); colorPaint = new Paint(); colorPaint.setAntiAlias(true); if (showOldColor) { originalPaint = new Paint(); } if (shape == ColorShape.CIRCLE) { Bitmap bitmap = ((BitmapDrawable) context.getResources().getDrawable(R.drawable.cpv_alpha)).getBitmap(); alphaPaint = new Paint(); alphaPaint.setAntiAlias(true); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); alphaPaint.setShader(shader); } }
From source file:com.conferenceengineer.android.iosched.ui.AnnouncementsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final ListView listView = getListView(); if (!UIUtils.isTablet(getActivity())) { view.setBackgroundColor(getResources().getColor(R.color.stream_spacer_color)); }/*from w ww. j a v a 2 s . c o m*/ if (getArguments() != null && getArguments().getBoolean(EXTRA_ADD_VERTICAL_MARGINS, false)) { int verticalMargin = getResources().getDimensionPixelSize(R.dimen.social_stream_padding_vertical); if (verticalMargin > 0) { listView.setClipToPadding(false); listView.setPadding(0, verticalMargin, 0, verticalMargin); } } listView.setOnScrollListener(this); listView.setDrawSelectorOnTop(true); listView.setDivider(getResources().getDrawable(android.R.color.transparent)); listView.setDividerHeight(getResources().getDimensionPixelSize(R.dimen.page_margin_width)); TypedValue v = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground, v, true); listView.setSelector(v.resourceId); setListAdapter(mStreamAdapter); }
From source file:com.bw.luzz.monkeyapplication.View.DateTimePicker.Utils.java
/** * Gets the colorAccent from the current context, if possible/available * @param context The context to use as reference for the color * @return the accent color of the current context *//*w w w . ja va2 s .co m*/ public static int getAccentColorFromThemeIfAvailable(Context context) { TypedValue typedValue = new TypedValue(); // First, try the android:colorAccent if (Build.VERSION.SDK_INT >= 21) { context.getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true); return typedValue.data; } // Next, try colorAccent from support lib int colorAccentResId = context.getResources().getIdentifier("colorAccent", "attr", context.getPackageName()); if (colorAccentResId != 0 && context.getTheme().resolveAttribute(colorAccentResId, typedValue, true)) { return typedValue.data; } // Return the value in mdtp_accent_color return ContextCompat.getColor(context, R.color.mdtp_accent_color); }
From source file:com.todoroo.astrid.notes.EditNoteActivity.java
private int getDefaultCameraButton() { TypedValue typedValue = new TypedValue(); fragment.getActivity().getTheme().resolveAttribute(R.attr.ic_action_camera, typedValue, true); return typedValue.resourceId; }
From source file:android.support.v7.widget.TintTypedArray.java
/** * Retrieve the Typeface for the attribute at <var>index</var>. * <p>/*from w w w. ja v a2 s . com*/ * This method will throw an exception if the attribute is defined but is * not a font. * * @param index Index of attribute to retrieve. * @param style A style value used for selecting best match font from the list of family. Note * that this value will be ignored if the platform supports font family (API 24 or later). * @param fontCallback A callback to receive async fetching of this font. If async loading is * specified in XML, this callback will be triggered. * * @return Typeface for the attribute, or {@code null} if not defined. * @throws RuntimeException if the TypedArray has already been recycled. * @throws UnsupportedOperationException if the attribute is defined but is * not a font resource. */ @Nullable public Typeface getFont(@StyleableRes int index, int style, @Nullable ResourcesCompat.FontCallback fontCallback) { final int resourceId = mWrapped.getResourceId(index, 0); if (resourceId == 0) { return null; } if (mTypedValue == null) { mTypedValue = new TypedValue(); } return ResourcesCompat.getFont(mContext, resourceId, mTypedValue, style, fontCallback); }
From source file:android.support.v7.content.res.AppCompatResources.java
@NonNull private static TypedValue getTypedValue() { TypedValue tv = TL_TYPED_VALUE.get(); if (tv == null) { tv = new TypedValue(); TL_TYPED_VALUE.set(tv);// w w w . ja va 2 s . c o m } return tv; }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.AnnouncementsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final ListView listView = getListView(); if (!UIUtils.isTablet(getActivity())) { view.setBackgroundColor(getResources().getColor(R.color.plus_stream_spacer_color)); }//from www . j av a 2 s . c om if (getArguments() != null && getArguments().getBoolean(EXTRA_ADD_VERTICAL_MARGINS, false)) { int verticalMargin = getResources().getDimensionPixelSize(R.dimen.plus_stream_padding_vertical); if (verticalMargin > 0) { listView.setClipToPadding(false); listView.setPadding(0, verticalMargin, 0, verticalMargin); } } listView.setOnScrollListener(this); listView.setDrawSelectorOnTop(true); listView.setDivider(getResources().getDrawable(android.R.color.transparent)); listView.setDividerHeight(getResources().getDimensionPixelSize(R.dimen.page_margin_width)); TypedValue v = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.activatableItemBackground, v, true); listView.setSelector(v.resourceId); setListAdapter(mStreamAdapter); }
From source file:com.android.datetimepicker.Utils.java
/** * Gets the colorAccent from the current context, if possible/available * @param context The context to use as reference for the color * @return the accent color of the current context *///from w w w . j av a2 s. co m // Source from MDTP public static int getAccentColorFromThemeIfAvailable(Context context) { TypedValue typedValue = new TypedValue(); // First, try the android:colorAccent if (Build.VERSION.SDK_INT >= 21) { context.getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true); return typedValue.data; } // Next, try colorAccent from support lib int colorAccentResId = context.getResources().getIdentifier("colorAccent", "attr", context.getPackageName()); if (colorAccentResId != 0 && context.getTheme().resolveAttribute(colorAccentResId, typedValue, true)) { return typedValue.data; } return ContextCompat.getColor(context, R.color.accent_color); }