List of usage examples for android.util TypedValue TypedValue
TypedValue
From source file:com.miz.functions.MizLib.java
/** * Add a padding with a combined height of the ActionBar and Status bar to the top of a given View * @param c/*from w w w. jav a 2s .c o m*/ * @param v */ public static void addActionBarAndStatusBarPadding(Context c, View v) { int mActionBarHeight = 0, mStatusBarHeight = 0; TypedValue tv = new TypedValue(); if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics()); else mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme) if (hasKitKat()) mStatusBarHeight = convertDpToPixels(c, 25); v.setPadding(0, mActionBarHeight + mStatusBarHeight, 0, 0); }
From source file:com.github.howeyc.slideshow.activities.SettingsActivity.java
/************************************************************************************ * needed because else the nested preference screen don't have a actionbar/toolbar * * see the fix and the given problem here: http://stackoverflow.com/a/27455363 * ************************************************************************************/ public void setUpNestedScreen(PreferenceScreen preferenceScreen) { final Dialog dialog = preferenceScreen.getDialog(); //ViewGroup list; Toolbar bar;/*from w w w.ja v a 2 s .c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { //list = (ViewGroup) dialog.findViewById(android.R.id.list); LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent(); bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); root.addView(bar, 0); // insert at top } else { ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content); ListView content = (ListView) root.getChildAt(0); //list = content; root.removeAllViews(); bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); int height; TypedValue tv = new TypedValue(); if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) { height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); } else { height = bar.getHeight(); } content.setPadding(0, height, 0, 0); root.addView(content); root.addView(bar); } //list.addView(detailsPrefScreenToAdd.getStatusViewGroup(), 1); //TODO bar.setTitle(preferenceScreen.getTitle()); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogI) { if (AppData.getLoginSuccessful()) { dialogI.dismiss(); } else { showNotConnectedDialog(dialog); } } }); bar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (AppData.getLoginSuccessful()) { dialog.dismiss(); } else { showNotConnectedDialog(dialog); } } }); }
From source file:com.hctrom.romcontrol.MainViewActivity.java
private void getAvisoBackupDialog() { View checkBoxView = View.inflate(this, R.layout.aviso_backup_text, null); final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkBoxAvisoBackup); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override//from ww w . ja v a 2 s . c om public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (checkBox.isChecked()) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit() .putInt("aviso_backup", 1).commit(); } else { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit() .putInt("aviso_backup", 0).commit(); } } }); AlertDialog.Builder b = new AlertDialog.Builder(this); b.setView(checkBoxView).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); AlertDialog d = b.create(); d.show(); TypedValue typedValue = new TypedValue(); Resources.Theme theme = this.getTheme(); theme.resolveAttribute(R.attr.colorAccent, typedValue, true); Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE); cancel.setTextColor(typedValue.data); Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE); ok.setTextColor(typedValue.data); d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg); }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
private void applyFixedSizeWindow() { TypedArray a = mContext.obtainStyledAttributes(R.styleable.Theme); TypedValue mFixedWidthMajor = null;//from ww w .j a va2s . c o m TypedValue mFixedWidthMinor = null; TypedValue mFixedHeightMajor = null; TypedValue mFixedHeightMinor = null; if (a.hasValue(R.styleable.Theme_windowFixedWidthMajor)) { if (mFixedWidthMajor == null) mFixedWidthMajor = new TypedValue(); a.getValue(R.styleable.Theme_windowFixedWidthMajor, mFixedWidthMajor); } if (a.hasValue(R.styleable.Theme_windowFixedWidthMinor)) { if (mFixedWidthMinor == null) mFixedWidthMinor = new TypedValue(); a.getValue(R.styleable.Theme_windowFixedWidthMinor, mFixedWidthMinor); } if (a.hasValue(R.styleable.Theme_windowFixedHeightMajor)) { if (mFixedHeightMajor == null) mFixedHeightMajor = new TypedValue(); a.getValue(R.styleable.Theme_windowFixedHeightMajor, mFixedHeightMajor); } if (a.hasValue(R.styleable.Theme_windowFixedHeightMinor)) { if (mFixedHeightMinor == null) mFixedHeightMinor = new TypedValue(); a.getValue(R.styleable.Theme_windowFixedHeightMinor, mFixedHeightMinor); } final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); final boolean isPortrait = metrics.widthPixels < metrics.heightPixels; int w = ViewGroup.LayoutParams.MATCH_PARENT; int h = ViewGroup.LayoutParams.MATCH_PARENT; final TypedValue tvw = isPortrait ? mFixedWidthMinor : mFixedWidthMajor; if (tvw != null && tvw.type != TypedValue.TYPE_NULL) { if (tvw.type == TypedValue.TYPE_DIMENSION) { w = (int) tvw.getDimension(metrics); } else if (tvw.type == TypedValue.TYPE_FRACTION) { w = (int) tvw.getFraction(metrics.widthPixels, metrics.widthPixels); } } final TypedValue tvh = isPortrait ? mFixedHeightMajor : mFixedHeightMinor; if (tvh != null && tvh.type != TypedValue.TYPE_NULL) { if (tvh.type == TypedValue.TYPE_DIMENSION) { h = (int) tvh.getDimension(metrics); } else if (tvh.type == TypedValue.TYPE_FRACTION) { h = (int) tvh.getFraction(metrics.heightPixels, metrics.heightPixels); } } if (w != ViewGroup.LayoutParams.MATCH_PARENT || h != ViewGroup.LayoutParams.MATCH_PARENT) { mWindow.setLayout(w, h); } a.recycle(); }
From source file:com.battlelancer.seriesguide.util.Utils.java
/** * Resolves the given attribute to the resource id for the given theme. *//* www.j a v a2 s. c om*/ public static int resolveAttributeToResourceId(Resources.Theme theme, int attributeResId) { TypedValue outValue = new TypedValue(); theme.resolveAttribute(attributeResId, outValue, true); return outValue.resourceId; }
From source file:com.evandroid.musica.fragment.LyricsViewFragment.java
private void showFirstStart() { stopRefreshAnimation();// w ww.j av a 2s .co m LayoutInflater inflater = LayoutInflater.from(getActivity()); ViewGroup parent = (ViewGroup) ((ViewGroup) getActivity().findViewById(R.id.scrollview)).getChildAt(0); if (parent.findViewById(R.id.tracks_msg) == null) inflater.inflate(R.layout.no_tracks, parent); TypedValue typedValue = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.firstLaunchCoverDrawable, typedValue, true); ((TextSwitcher) getActivity().findViewById(R.id.switcher)).setText(""); getActivity().findViewById(R.id.error_msg).setVisibility(View.INVISIBLE); }
From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java
/** * Creates a view appropriate for displaying a list of GuidedActions, using the provided * inflater and container.//from w w w . ja v a2 s . co m * <p> * <i>Note: Does not actually add the created view to the container; the caller should do * this.</i> * @param inflater The layout inflater to be used when constructing the view. * @param container The view group to be passed in the call to * <code>LayoutInflater.inflate</code>. * @return The view to be added to the caller's view hierarchy. */ public View onCreateView(LayoutInflater inflater, final ViewGroup container) { TypedArray ta = inflater.getContext().getTheme() .obtainStyledAttributes(R.styleable.LeanbackGuidedStepTheme); float keylinePercent = ta.getFloat(R.styleable.LeanbackGuidedStepTheme_guidedStepKeyline, 40); mMainView = (ViewGroup) inflater.inflate(onProvideLayoutId(), container, false); mContentView = mMainView .findViewById(mButtonActions ? R.id.guidedactions_content2 : R.id.guidedactions_content); mBgView = mMainView.findViewById( mButtonActions ? R.id.guidedactions_list_background2 : R.id.guidedactions_list_background); if (mMainView instanceof VerticalGridView) { mActionsGridView = (VerticalGridView) mMainView; } else { mActionsGridView = (VerticalGridView) mMainView .findViewById(mButtonActions ? R.id.guidedactions_list2 : R.id.guidedactions_list); if (mActionsGridView == null) { throw new IllegalStateException("No ListView exists."); } mActionsGridView.setWindowAlignmentOffsetPercent(keylinePercent); mActionsGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE); if (!mButtonActions) { mSubActionsGridView = (VerticalGridView) mMainView.findViewById(R.id.guidedactions_sub_list); } } mActionsGridView.setFocusable(false); mActionsGridView.setFocusableInTouchMode(false); // Cache widths, chevron alpha values, max and min text lines, etc Context ctx = mMainView.getContext(); TypedValue val = new TypedValue(); mEnabledChevronAlpha = getFloat(ctx, val, R.attr.guidedActionEnabledChevronAlpha); mDisabledChevronAlpha = getFloat(ctx, val, R.attr.guidedActionDisabledChevronAlpha); mTitleMinLines = getInteger(ctx, val, R.attr.guidedActionTitleMinLines); mTitleMaxLines = getInteger(ctx, val, R.attr.guidedActionTitleMaxLines); mDescriptionMinLines = getInteger(ctx, val, R.attr.guidedActionDescriptionMinLines); mVerticalPadding = getDimension(ctx, val, R.attr.guidedActionVerticalPadding); mDisplayHeight = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getHeight(); mEnabledTextAlpha = Float .valueOf(ctx.getResources().getString(R.string.lb_guidedactions_item_unselected_text_alpha)); mDisabledTextAlpha = Float .valueOf(ctx.getResources().getString(R.string.lb_guidedactions_item_disabled_text_alpha)); mEnabledDescriptionAlpha = Float.valueOf( ctx.getResources().getString(R.string.lb_guidedactions_item_unselected_description_text_alpha)); mDisabledDescriptionAlpha = Float.valueOf( ctx.getResources().getString(R.string.lb_guidedactions_item_disabled_description_text_alpha)); return mMainView; }
From source file:com.miz.functions.MizLib.java
/** * Add a margin with a combined height of the ActionBar and Status bar to the top of a given View contained in a FrameLayout * @param c/* w w w . j a v a 2s . com*/ * @param v */ public static void addActionBarAndStatusBarMargin(Context c, View v) { int mActionBarHeight = 0, mStatusBarHeight = 0; TypedValue tv = new TypedValue(); if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, c.getResources().getDisplayMetrics()); else mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme) if (hasKitKat()) mStatusBarHeight = convertDpToPixels(c, 25); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.setMargins(0, mActionBarHeight + mStatusBarHeight, 0, 0); v.setLayoutParams(params); }
From source file:com.hctrom.romcontrol.MainViewActivity.java
private void showThemeChooserDialog() { AlertDialog.Builder b = new AlertDialog.Builder(this); Adapter adapter = new ArrayAdapter<>(this, R.layout.simple_list_item_single_choice, getResources().getStringArray(R.array.theme_items)); b.setIcon(R.drawable.ic_htc_personalize).setTitle(getString(R.string.theme_chooser_dialog_title)) .setSingleChoiceItems((ListAdapter) adapter, PreferenceManager.getDefaultSharedPreferences(this).getInt("theme_prefs", 0), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Invokes method initTheme(int) - next method based on chosen theme initTheme(which); }/*www . j av a 2 s . c om*/ }); AlertDialog d = b.create(); d.show(); TypedValue typedValue = new TypedValue(); Resources.Theme theme = this.getTheme(); theme.resolveAttribute(R.attr.colorAccent, typedValue, true); Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE); cancel.setTextColor(typedValue.data); Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE); ok.setTextColor(typedValue.data); d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg); ListView lv = d.getListView(); int paddingTop = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_top_padding)); int paddingBottom = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_bottom_padding)); lv.setPadding(0, paddingTop, 0, paddingBottom); }
From source file:com.evandroid.musica.fragment.LocalLyricsFragment.java
@Override public void onActivityCreated(Bundle onSavedInstanceState) { super.onActivityCreated(onSavedInstanceState); if (megaListView != null) { View fragmentView = getView(); TypedValue typedValue = new TypedValue(); getActivity().getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true); if (fragmentView != null) fragmentView.setBackgroundColor(typedValue.data); megaListView.setDividerHeight(0); megaListView.setFastScrollEnabled(true); megaListView.setDrawSelectorOnTop(true); }/*ww w .j a v a 2 s . c o m*/ }