List of usage examples for android.util TypedValue TypedValue
TypedValue
From source file:com.github.shareme.gwsdiscreteseekbar.library.DiscreteSeekBar.java
public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setFocusable(true);// w w w. ja v a 2s . c o m setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; mTrackHeight = (int) (1 * density); mScrubberHeight = (int) (4 * density); int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP); //Extra pixels for a touch area of 48dp int touchBounds = (int) (density * 32); mAddedTouchBounds = (touchBounds - thumbSize) / 2; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, defStyleAttr, R.style.Widget_DiscreteSeekBar); int max = 100; int min = 0; int value = 0; mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick); mIndicatorPopupEnabled = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_indicatorPopupEnabled, mIndicatorPopupEnabled); int indexMax = R.styleable.DiscreteSeekBar_dsb_max; int indexMin = R.styleable.DiscreteSeekBar_dsb_min; int indexValue = R.styleable.DiscreteSeekBar_dsb_value; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mIndicatorFormatter = a.getString(R.styleable.DiscreteSeekBar_dsb_indicatorFormatter); ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_rippleColor); boolean editMode = isInEditMode(); if (editMode || rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode || trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode || progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { DEFAULT_THUMB_COLOR }); } mRipple = SeekBarCompat.getRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); mThumb = new ThumbDrawable(progressColor, thumbSize); mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax)); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); }
From source file:com.geecko.QuickLyric.AboutActivity.java
@TargetApi(21) public void setStatusBarColor(Integer color) { if (Build.VERSION.SDK_INT >= 21) { if (color == null) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = getTheme(); theme.resolveAttribute(android.R.attr.colorPrimaryDark, typedValue, true); color = typedValue.data;/* ww w . j a v a 2s. c o m*/ } getWindow().setStatusBarColor(color); } }
From source file:com.af.synapse.MainActivity.java
private void setPaddingDimensions() { int resourceId; topPadding = 0;/* www. ja va 2 s .c om*/ resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) topPadding += getResources().getDimensionPixelSize(resourceId); TypedValue tv = new TypedValue(); if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) topPadding += TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); View v; v = findViewById(R.id.activity_loading); if (v != null) v.setPadding(0, topPadding, 0, 0); v = findViewById(R.id.activity_main); if (v != null) v.setPadding(0, topPadding, 0, 0); if (Utils.appStarted && Utils.hasSoftKeys(getWindowManager())) { bottomPadding = 0; resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) bottomPadding += getResources().getDimensionPixelSize(resourceId); if (bottomPadding == 0) return; for (TabSectionFragment f : fragments) { if (f != null && f.fragmentView != null) f.fragmentView.findViewById(R.id.section_container_linear_layout).setPadding(0, 0, 0, bottomPadding); } } }
From source file:com.google.android.gms.common.C0270e.java
private static Dialog m3391b(int i, Activity activity, Fragment fragment, int i2, OnCancelListener onCancelListener) { Builder builder;//from w w w . jav a 2 s . com Intent a; OnClickListener c0420i; CharSequence c; if (C0516u.m4166a((Context) activity) && i == 2) { i = 42; } if (C0519x.m4174c()) { TypedValue typedValue = new TypedValue(); activity.getTheme().resolveAttribute(16843529, typedValue, true); if ("Theme.Dialog.Alert".equals(activity.getResources().getResourceEntryName(typedValue.resourceId))) { builder = new Builder(activity, 5); if (builder == null) { builder = new Builder(activity); } builder.setMessage(C0270e.m3392b(activity, i)); if (onCancelListener != null) { builder.setOnCancelListener(onCancelListener); } a = C0270e.m3382a(i); c0420i = fragment != null ? new C0420i(activity, a, i2) : new C0420i(fragment, a, i2); c = C0270e.m3397c(activity, i); if (c != null) { builder.setPositiveButton(c, c0420i); } switch (i) { case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoPanelHeight /*0*/: return null; case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoShadowHeight /*1*/: return builder.setTitle(R.common_google_play_services_install_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoParalaxOffset /*2*/: return builder.setTitle(R.common_google_play_services_update_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoFadeColor /*3*/: return builder.setTitle(R.common_google_play_services_enable_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoFlingVelocity /*4*/: case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoOverlay /*6*/: return builder.create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoDragView /*5*/: Log.e("GooglePlayServicesUtil", "An invalid account was specified when connecting. Please provide a valid account."); return builder.setTitle(R.common_google_play_services_invalid_account_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoClipPanel /*7*/: Log.e("GooglePlayServicesUtil", "Network error occurred. Please retry request later."); return builder.setTitle(R.common_google_play_services_network_error_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoAnchorPoint /*8*/: Log.e("GooglePlayServicesUtil", "Internal error occurred. Please see logs for detailed information"); return builder.create(); case HTTP.HT /*9*/: Log.e("GooglePlayServicesUtil", "Google Play services is invalid. Cannot recover."); return builder.setTitle(R.common_google_play_services_unsupported_title).create(); case HTTP.LF /*10*/: Log.e("GooglePlayServicesUtil", "Developer error occurred. Please see logs for detailed information"); return builder.create(); case com.olacabs.customer.R.R.MapM4bAttrs_m4b_uiZoomControls /*11*/: Log.e("GooglePlayServicesUtil", "The application is not licensed to the user."); return builder.create(); case Constants.DEFAULT_MAP_ZOOM_LEVEL /*16*/: Log.e("GooglePlayServicesUtil", "One of the API components you attempted to connect to is not available."); return builder.create(); case LangUtils.HASH_SEED /*17*/: Log.e("GooglePlayServicesUtil", "The specified account could not be signed in."); return builder.setTitle(R.common_google_play_services_sign_in_failed_title).create(); case 42: return builder.setTitle(R.common_android_wear_update_title).create(); default: Log.e("GooglePlayServicesUtil", "Unexpected error code " + i); return builder.create(); } } } builder = null; if (builder == null) { builder = new Builder(activity); } builder.setMessage(C0270e.m3392b(activity, i)); if (onCancelListener != null) { builder.setOnCancelListener(onCancelListener); } a = C0270e.m3382a(i); if (fragment != null) { } c = C0270e.m3397c(activity, i); if (c != null) { builder.setPositiveButton(c, c0420i); } switch (i) { case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoPanelHeight /*0*/: return null; case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoShadowHeight /*1*/: return builder.setTitle(R.common_google_play_services_install_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoParalaxOffset /*2*/: return builder.setTitle(R.common_google_play_services_update_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoFadeColor /*3*/: return builder.setTitle(R.common_google_play_services_enable_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoFlingVelocity /*4*/: case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoOverlay /*6*/: return builder.create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoDragView /*5*/: Log.e("GooglePlayServicesUtil", "An invalid account was specified when connecting. Please provide a valid account."); return builder.setTitle(R.common_google_play_services_invalid_account_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoClipPanel /*7*/: Log.e("GooglePlayServicesUtil", "Network error occurred. Please retry request later."); return builder.setTitle(R.common_google_play_services_network_error_title).create(); case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoAnchorPoint /*8*/: Log.e("GooglePlayServicesUtil", "Internal error occurred. Please see logs for detailed information"); return builder.create(); case HTTP.HT /*9*/: Log.e("GooglePlayServicesUtil", "Google Play services is invalid. Cannot recover."); return builder.setTitle(R.common_google_play_services_unsupported_title).create(); case HTTP.LF /*10*/: Log.e("GooglePlayServicesUtil", "Developer error occurred. Please see logs for detailed information"); return builder.create(); case com.olacabs.customer.R.R.MapM4bAttrs_m4b_uiZoomControls /*11*/: Log.e("GooglePlayServicesUtil", "The application is not licensed to the user."); return builder.create(); case Constants.DEFAULT_MAP_ZOOM_LEVEL /*16*/: Log.e("GooglePlayServicesUtil", "One of the API components you attempted to connect to is not available."); return builder.create(); case LangUtils.HASH_SEED /*17*/: Log.e("GooglePlayServicesUtil", "The specified account could not be signed in."); return builder.setTitle(R.common_google_play_services_sign_in_failed_title).create(); case 42: return builder.setTitle(R.common_android_wear_update_title).create(); default: Log.e("GooglePlayServicesUtil", "Unexpected error code " + i); return builder.create(); } }
From source file:android.support.v7.preference.PreferenceController.java
@Override @NonNull//from ww w.j a v a2 s .com 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.v7.preference.PreferenceFragmentCompat.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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"); }/*from w w w .j a va 2 s. c o m*/ mStyledContext = new ContextThemeWrapper(getActivity(), theme); mPreferenceManager = new PreferenceManager(mStyledContext); mPreferenceManager.setOnNavigateToScreenListener(this); final Bundle args = getArguments(); final String rootKey; if (args != null) { rootKey = getArguments().getString(ARG_PREFERENCE_ROOT); } else { rootKey = null; } onCreatePreferences(savedInstanceState, rootKey); }
From source file:com.evandroid.musica.fragment.LyricsViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true);/*ww w . j a v a 2 s. com*/ setHasOptionsMenu(true); View layout = inflater.inflate(R.layout.lyrics_view, container, false); if (savedInstanceState != null) try { Lyrics l = Lyrics.fromBytes(savedInstanceState.getByteArray("lyrics")); if (l != null) this.mLyrics = l; mSearchQuery = savedInstanceState.getString("searchQuery"); mSearchFocused = savedInstanceState.getBoolean("searchFocused"); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } else { Bundle args = getArguments(); if (args != null) try { Lyrics lyrics = Lyrics.fromBytes(args.getByteArray("lyrics")); this.mLyrics = lyrics; if (lyrics != null && lyrics.getText() == null && lyrics.getArtist() != null) { String artist = lyrics.getArtist(); String track = lyrics.getTrack(); String url = lyrics.getURL(); fetchLyrics(artist, track, url); mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout); startRefreshAnimation(); } } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } if (layout != null) { Bundle args = savedInstanceState != null ? savedInstanceState : getArguments(); boolean screenOn = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getBoolean("pref_force_screen_on", false); TextSwitcher textSwitcher = (TextSwitcher) layout.findViewById(R.id.switcher); textSwitcher.setFactory(new LyricsTextFactory(layout.getContext())); ActionMode.Callback callback = new CustomSelectionCallback(getActivity()); ((TextView) textSwitcher.getChildAt(0)).setCustomSelectionActionModeCallback(callback); ((TextView) textSwitcher.getChildAt(1)).setCustomSelectionActionModeCallback(callback); textSwitcher.setKeepScreenOn(screenOn); layout.findViewById(R.id.lrc_view).setKeepScreenOn(screenOn); TextView id3TV = (TextView) layout.findViewById(R.id.id3_tv); SpannableString text = new SpannableString(id3TV.getText()); text.setSpan(new UnderlineSpan(), 1, text.length() - 1, 0); id3TV.setText(text); final RefreshIcon refreshFab = (RefreshIcon) getActivity().findViewById(R.id.refresh_fab); refreshFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!mRefreshLayout.isRefreshing()) fetchCurrentLyrics(true); } }); FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class); startActivity(settingsIntent); } }); if (args != null) refreshFab.setEnabled(args.getBoolean("refreshFabEnabled", true)); mScrollView = (NestedScrollView) layout.findViewById(R.id.scrollview); mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout); TypedValue primaryColor = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true); mRefreshLayout.setColorSchemeResources(primaryColor.resourceId, R.color.accent); float offset = getResources().getDisplayMetrics().density * 64; mRefreshLayout.setProgressViewEndTarget(true, (int) offset); mRefreshLayout.setOnRefreshListener(this); if (mLyrics == null) { if (!startEmtpy) fetchCurrentLyrics(false); } else if (mLyrics.getFlag() == Lyrics.SEARCH_ITEM) { mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout); startRefreshAnimation(); if (mLyrics.getArtist() != null) fetchLyrics(mLyrics.getArtist(), mLyrics.getTrack()); } else //Rotation, resume update(mLyrics, layout, false); } if (broadcastReceiver == null) broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { searchResultLock = false; String artist = intent.getStringExtra("artist"); String track = intent.getStringExtra("track"); if (artist != null && track != null && mRefreshLayout.isEnabled()) { startRefreshAnimation(); new ParseTask(LyricsViewFragment.this, false, true).execute(mLyrics); } } }; return layout; }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
private Drawable createDrawableIfNeeded(@NonNull Context context, @DrawableRes final int resId) { if (mTypedValue == null) { mTypedValue = new TypedValue(); }/*from w ww. j a va 2s . c o m*/ final TypedValue tv = mTypedValue; context.getResources().getValue(resId, tv, true); final long key = createCacheKey(tv); Drawable dr = getCachedDrawable(context, key); if (dr != null) { // If we got a cached drawable, return it return dr; } // Else we need to try and create one... if (resId == R.drawable.abc_cab_background_top_material) { dr = new LayerDrawable(new Drawable[] { getDrawable(context, R.drawable.abc_cab_background_internal_bg), getDrawable(context, R.drawable.abc_cab_background_top_mtrl_alpha) }); } if (dr != null) { dr.setChangingConfigurations(tv.changingConfigurations); // If we reached here then we created a new drawable, add it to the cache addDrawableToCache(context, key, dr); } return dr; }
From source file:android.support.v7ox.widget.ShareActionProvider.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s . com*/ */ @Override public View onCreateActionView() { // Create the view and set its data model. ActivityChooserView activityChooserView = new ActivityChooserView(mContext); if (!activityChooserView.isInEditMode()) { ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName); activityChooserView.setActivityChooserModel(dataModel); } // Lookup and set the expand action icon. TypedValue outTypedValue = new TypedValue(); mContext.getTheme().resolveAttribute(R.attr.actionModeShareDrawable_ox, outTypedValue, true); Drawable drawable = AppCompatDrawableManager.get().getDrawable(mContext, outTypedValue.resourceId); activityChooserView.setExpandActivityOverflowButtonDrawable(drawable); activityChooserView.setProvider(this); // Set content description. activityChooserView .setDefaultActionButtonContentDescription(R.string.abc_shareactionprovider_share_with_application); activityChooserView .setExpandActivityOverflowButtonContentDescription(R.string.abc_shareactionprovider_share_with); return activityChooserView; }
From source file:com.greenorange.gooutdoor.framework.widget.dialogs.core.BaseDialogFragment.java
/** * This method resolves the current theme declared in the manifest *///from ww w .j a v a 2s . co m private void resolveTheme() { try { TypedValue val = new TypedValue(); //Reading attr value from current theme getActivity().getTheme().resolveAttribute(R.attr.isLightTheme, val, true); //Passing the resource ID to TypedArray to get the attribute value TypedArray arr = getActivity().obtainStyledAttributes(val.data, new int[] { R.attr.isLightTheme }); darkTheme = !arr.getBoolean(0, false); arr.recycle(); } catch (RuntimeException e) { //Resource not found , so sticking to light theme darkTheme = false; } }