List of usage examples for android.util TypedValue TypedValue
TypedValue
From source file:com.apptentive.android.sdk.util.Util.java
public static int getResourceIdFromAttribute(Resources.Theme theme, int attr) { TypedValue tv = new TypedValue(); if (theme.resolveAttribute(attr, tv, true)) { return tv.resourceId; }/*w w w. j a v a 2 s .c o m*/ return 0; }
From source file:com.achenging.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)}.//from ww w . j a v a 2s. c om */ protected TextView createDefaultTabView(Context context) { AppCompatTextView textView = new AppCompatTextView(context); textView.setGravity(Gravity.CENTER); textView.setBackgroundColor(Color.WHITE); textView.setPadding(mTextPadding, mTextPadding, mTextPadding, mTextPadding); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); if (mAvgSplit) { int screenWidth = getResources().getDisplayMetrics().widthPixels; textView.setWidth(screenWidth / mViewPager.getAdapter().getCount()); } 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); } return textView; }
From source file:com.apptentive.android.sdk.util.Util.java
public static int getThemeColor(Resources.Theme theme, int attr) { TypedValue tv = new TypedValue(); if (theme.resolveAttribute(attr, tv, true)) { return tv.data; }/*from w w w . j ava 2s .co m*/ return 0; }
From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true);//from www. j a v a2s .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.getTitle(); 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); EditText artistTV = (EditText) getActivity().findViewById(R.id.artist); EditText songTV = (EditText) getActivity().findViewById(R.id.song); if (args != null && args.containsKey("editedLyrics")) { EditText editedLyrics = (EditText) layout.findViewById(R.id.edit_lyrics); textSwitcher.setVisibility(View.GONE); editedLyrics.setVisibility(View.VISIBLE); songTV.setInputType(InputType.TYPE_CLASS_TEXT); artistTV.setInputType(InputType.TYPE_CLASS_TEXT); songTV.setBackgroundResource(R.drawable.abc_textfield_search_material); artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material); editedLyrics.setText(args.getCharSequence("editedLyrics"), TextView.BufferType.EDITABLE); songTV.setText(args.getCharSequence("editedTitle"), TextView.BufferType.EDITABLE); artistTV.setText(args.getCharSequence("editedArtist"), TextView.BufferType.EDITABLE); } artistTV.setTypeface(LyricsTextFactory.FontCache.get("regular", getActivity())); songTV.setTypeface(LyricsTextFactory.FontCache.get("medium", getActivity())); 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); } }); 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(); TypedValue accentColor = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true); getActivity().getTheme().resolveAttribute(R.attr.colorAccent, accentColor, true); mRefreshLayout.setColorSchemeResources(primaryColor.resourceId, accentColor.resourceId); float offset = getResources().getDisplayMetrics().density * 64; mRefreshLayout.setProgressViewEndTarget(true, (int) offset); mRefreshLayout.setOnRefreshListener(this); final ImageButton editTagsButton = (ImageButton) getActivity().findViewById(R.id.edit_tags_btn); View.OnClickListener startEditClickListener = new View.OnClickListener() { @Override public void onClick(View v) { startEditTagsMode(); final View.OnClickListener startEditClickListener = this; editTagsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { exitEditTagsMode(); editTagsButton.setOnClickListener(startEditClickListener); } }); } }; editTagsButton.setOnClickListener(startEditClickListener); if (mLyrics == null) { if (!startEmpty) 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.getTitle()); ((TextView) (getActivity().findViewById(R.id.artist))).setText(mLyrics.getArtist()); ((TextView) (getActivity().findViewById(R.id.song))).setText(mLyrics.getTitle()); } 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.app.AppCompatDelegateImplV7.java
private void ensureSubDecor() { if (!mSubDecorInstalled) { final LayoutInflater inflater = LayoutInflater.from(mContext); if (!mWindowNoTitle) { if (mIsFloating) { // If we're floating, inflate the dialog title decor mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_dialog_title_material, null); } else if (mHasActionBar) { /**/*ww w . ja v a 2 s.c o m*/ * This needs some explanation. As we can not use the android:theme attribute * pre-L, we emulate it by manually creating a LayoutInflater using a * ContextThemeWrapper pointing to actionBarTheme. */ TypedValue outValue = new TypedValue(); mContext.getTheme().resolveAttribute(R.attr.actionBarTheme, outValue, true); Context themedContext; if (outValue.resourceId != 0) { themedContext = new ContextThemeWrapper(mContext, outValue.resourceId); } else { themedContext = mContext; } // Now inflate the view using the themed context and set it as the content view mSubDecor = (ViewGroup) LayoutInflater.from(themedContext).inflate(R.layout.abc_screen_toolbar, null); mDecorContentParent = (DecorContentParent) mSubDecor.findViewById(R.id.decor_content_parent); mDecorContentParent.setWindowCallback(getWindowCallback()); /** * Propagate features to DecorContentParent */ if (mOverlayActionBar) { mDecorContentParent.initFeature(FEATURE_ACTION_BAR_OVERLAY); } if (mFeatureProgress) { mDecorContentParent.initFeature(Window.FEATURE_PROGRESS); } if (mFeatureIndeterminateProgress) { mDecorContentParent.initFeature(Window.FEATURE_INDETERMINATE_PROGRESS); } } } else { if (mOverlayActionMode) { mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple_overlay_action_mode, null); } else { mSubDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple, null); } if (Build.VERSION.SDK_INT >= 21) { // If we're running on L or above, we can rely on ViewCompat's // setOnApplyWindowInsetsListener ViewCompat.setOnApplyWindowInsetsListener(mSubDecor, new OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { final int top = insets.getSystemWindowInsetTop(); final int newTop = updateStatusGuard(top); if (top != newTop) { insets = insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), newTop, insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); } // Now apply the insets on our view return ViewCompat.onApplyWindowInsets(v, insets); } }); } else { // Else, we need to use our own FitWindowsViewGroup handling ((FitWindowsViewGroup) mSubDecor) .setOnFitSystemWindowsListener(new FitWindowsViewGroup.OnFitSystemWindowsListener() { @Override public void onFitSystemWindows(Rect insets) { insets.top = updateStatusGuard(insets.top); } }); } } if (mSubDecor == null) { throw new IllegalArgumentException("AppCompat does not support the current theme features"); } if (mDecorContentParent == null) { mTitleView = (TextView) mSubDecor.findViewById(R.id.title); } // Make the decor optionally fit system windows, like the window's decor ViewUtils.makeOptionalFitsSystemWindows(mSubDecor); final ViewGroup decorContent = (ViewGroup) mWindow.findViewById(android.R.id.content); final ViewGroup abcContent = (ViewGroup) mSubDecor.findViewById(R.id.action_bar_activity_content); // There might be Views already added to the Window's content view so we need to // migrate them to our content view while (decorContent.getChildCount() > 0) { final View child = decorContent.getChildAt(0); decorContent.removeViewAt(0); abcContent.addView(child); } // Now set the Window's content view with the decor mWindow.setContentView(mSubDecor); // Change our content FrameLayout to use the android.R.id.content id. // Useful for fragments. decorContent.setId(View.NO_ID); abcContent.setId(android.R.id.content); // The decorContent may have a foreground drawable set (windowContentOverlay). // Remove this as we handle it ourselves if (decorContent instanceof FrameLayout) { ((FrameLayout) decorContent).setForeground(null); } // If a title was set before we installed the decor, propogate it now CharSequence title = getTitle(); if (!TextUtils.isEmpty(title)) { onTitleChanged(title); } applyFixedSizeWindow(); onSubDecorInstalled(mSubDecor); mSubDecorInstalled = true; // Invalidate if the panel menu hasn't been created before this. // Panel menu invalidation is deferred avoiding application onCreateOptionsMenu // being called in the middle of onCreate or similar. // A pending invalidation will typically be resolved before the posted message // would run normally in order to satisfy instance state restoration. PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); if (!isDestroyed() && (st == null || st.menu == null)) { invalidatePanelMenu(FEATURE_ACTION_BAR); } } }
From source file:android.support.v7ox.widget.AppCompatDrawableManager.java
private Drawable loadDrawableFromDelegates(@NonNull Context context, @DrawableRes int resId) { if (mDelegates != null && !mDelegates.isEmpty()) { if (mKnownDrawableIdTags != null) { final String cachedTagName = mKnownDrawableIdTags.get(resId); if (SKIP_DRAWABLE_TAG.equals(cachedTagName) || (cachedTagName != null && mDelegates.get(cachedTagName) == null)) { // If we don't have a delegate for the drawable tag, or we've been set to // skip it, fail fast and return null if (DEBUG) { Log.d(TAG, "[loadDrawableFromDelegates] Skipping drawable: " + context.getResources().getResourceName(resId)); }/*from w w w .j av a 2s. c om*/ return null; } } else { // Create an id cache as we'll need one later mKnownDrawableIdTags = new SparseArray<>(); } if (mTypedValue == null) { mTypedValue = new TypedValue(); } final TypedValue tv = mTypedValue; final Resources res = context.getResources(); res.getValue(resId, tv, true); final long key = (((long) tv.assetCookie) << 32) | tv.data; Drawable dr = getCachedDelegateDrawable(context, key); if (dr != null) { if (DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Returning cached drawable: " + context.getResources().getResourceName(resId)); } // We have a cached drawable, return it! return dr; } if (tv.string != null && tv.string.toString().endsWith(".xml")) { // If the resource is an XML file, let's try and parse it try { final XmlPullParser parser = res.getXml(resId); final AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } final String tagName = parser.getName(); // Add the tag name to the cache mKnownDrawableIdTags.append(resId, tagName); // Now try and find a delegate for the tag name and inflate if found final InflateDelegate delegate = mDelegates.get(tagName); if (delegate != null) { dr = delegate.createFromXmlInner(context, parser, attrs, context.getTheme()); } if (dr != null) { // Add it to the drawable cache dr.setChangingConfigurations(tv.changingConfigurations); if (addCachedDelegateDrawable(context, key, dr) && DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Saved drawable to cache: " + context.getResources().getResourceName(resId)); } } } catch (Exception e) { Log.e(TAG, "Exception while inflating drawable", e); } } if (dr == null) { // If we reach here then the delegate inflation of the resource failed. Mark it as // bad so we skip the id next time mKnownDrawableIdTags.append(resId, SKIP_DRAWABLE_TAG); } return dr; } return null; }
From source file:android.support.v7.app.AlertController.java
/** * @param attrId the attributeId of the theme-specific drawable * to resolve the resourceId for. * * @return resId the resourceId of the theme-specific drawable *//*from w ww .j av a 2 s. com*/ public int getIconAttributeResId(int attrId) { TypedValue out = new TypedValue(); mContext.getTheme().resolveAttribute(attrId, out, true); return out.resourceId; }
From source file:co.codecrunch.musicplayerlite.activities.MusicPlayerBaseActivity.java
private void initiSlidingUpPanel() { mLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout); songAlbumbg = (ImageView) findViewById(R.id.image_songAlbumbg_mid); img_bottom_slideone = (ImageView) findViewById(R.id.img_bottom_slideone); img_bottom_slidetwo = (ImageView) findViewById(R.id.img_bottom_slidetwo); txt_timeprogress = (TextView) findViewById(R.id.slidepanel_time_progress); txt_timetotal = (TextView) findViewById(R.id.slidepanel_time_total); imgbtn_backward = (ImageView) findViewById(R.id.btn_backward); imgbtn_forward = (ImageView) findViewById(R.id.btn_forward); imgbtn_toggle = (ImageView) findViewById(R.id.btn_toggle); imgbtn_suffel = (ImageView) findViewById(R.id.btn_suffel); btn_playpause = (PlayPauseView) findViewById(R.id.btn_play); audio_progress = (Slider) findViewById(R.id.audio_progress_control); btn_playpausePanel = (PlayPauseView) findViewById(R.id.bottombar_play); img_Favorite = (ImageView) findViewById(R.id.bottombar_img_Favorite); TypedValue typedvaluecoloraccent = new TypedValue(); getTheme().resolveAttribute(R.attr.colorAccent, typedvaluecoloraccent, true); final int coloraccent = typedvaluecoloraccent.data; audio_progress.setBackgroundColor(coloraccent); audio_progress.setValue(0);/*from ww w . j av a 2 s .c o m*/ audio_progress.setOnValueChangedListener(this); imgbtn_backward.setOnClickListener(this); imgbtn_forward.setOnClickListener(this); imgbtn_toggle.setOnClickListener(this); imgbtn_suffel.setOnClickListener(this); img_Favorite.setOnClickListener(this); btn_playpausePanel.Pause(); btn_playpause.Pause(); txt_playesongname = (TextView) findViewById(R.id.txt_playesongname); txt_songartistname = (TextView) findViewById(R.id.txt_songartistname); txt_playesongname_slidetoptwo = (TextView) findViewById(R.id.txt_playesongname_slidetoptwo); txt_songartistname_slidetoptwo = (TextView) findViewById(R.id.txt_songartistname_slidetoptwo); slidepanelchildtwo_topviewone = (RelativeLayout) findViewById(R.id.slidepanelchildtwo_topviewone); slidepanelchildtwo_topviewtwo = (RelativeLayout) findViewById(R.id.slidepanelchildtwo_topviewtwo); slidepanelchildtwo_topviewone.setVisibility(View.VISIBLE); slidepanelchildtwo_topviewtwo.setVisibility(View.INVISIBLE); slidepanelchildtwo_topviewone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED); } }); slidepanelchildtwo_topviewtwo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); } }); ((PlayPauseView) findViewById(R.id.bottombar_play)).setOnClickListener(this); ((PlayPauseView) findViewById(R.id.btn_play)).setOnClickListener(this); imgbtn_toggle.setSelected((MusicPreferance.getRepeat(context) == 1) ? true : false); MediaController.getInstance().shuffleMusic = imgbtn_toggle.isSelected() ? true : false; MusicPlayerUtility.changeColorSet(context, (ImageView) imgbtn_toggle, imgbtn_toggle.isSelected()); imgbtn_suffel.setSelected(MusicPreferance.getShuffel(context) ? true : false); MediaController.getInstance().repeatMode = imgbtn_suffel.isSelected() ? 1 : 0; MusicPlayerUtility.changeColorSet(context, (ImageView) imgbtn_suffel, imgbtn_suffel.isSelected()); MediaController.getInstance().shuffleList(MusicPreferance.playlist); mLayout.setPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() { @Override public void onPanelSlide(View panel, float slideOffset) { Log.i(TAG, "onPanelSlide, offset " + slideOffset); if (slideOffset == 0.0f) { isExpand = false; slidepanelchildtwo_topviewone.setVisibility(View.VISIBLE); slidepanelchildtwo_topviewtwo.setVisibility(View.INVISIBLE); } else if (slideOffset > 0.0f && slideOffset < 1.0f) { // if (isExpand) { // slidepanelchildtwo_topviewone.setAlpha(1.0f); // slidepanelchildtwo_topviewtwo.setAlpha(1.0f - // slideOffset); // } else { // slidepanelchildtwo_topviewone.setAlpha(1.0f - // slideOffset); // slidepanelchildtwo_topviewtwo.setAlpha(1.0f); // } } else { isExpand = true; slidepanelchildtwo_topviewone.setVisibility(View.INVISIBLE); slidepanelchildtwo_topviewtwo.setVisibility(View.VISIBLE); } } @Override public void onPanelExpanded(View panel) { Log.i(TAG, "onPanelExpanded"); isExpand = true; } @Override public void onPanelCollapsed(View panel) { Log.i(TAG, "onPanelCollapsed"); isExpand = false; } @Override public void onPanelAnchored(View panel) { Log.i(TAG, "onPanelAnchored"); } @Override public void onPanelHidden(View panel) { Log.i(TAG, "onPanelHidden"); } }); }
From source file:android.support.v7.widget.SuggestionsAdapter.java
private CharSequence formatUrl(CharSequence url) { if (mUrlColor == null) { // Lazily get the URL color from the current theme. TypedValue colorValue = new TypedValue(); mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true); mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId); }/*from w w w . j a va2s . c o m*/ SpannableString text = new SpannableString(url); text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return text; }
From source file:android.support.v7ox.widget.SuggestionsAdapter.java
private CharSequence formatUrl(CharSequence url) { if (mUrlColor == null) { // Lazily get the URL color from the current theme. TypedValue colorValue = new TypedValue(); mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl_ox, colorValue, true); mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId); }//from w w w .j a v a 2 s.c om SpannableString text = new SpannableString(url); text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return text; }