List of usage examples for android.util TypedValue applyDimension
public static float applyDimension(int unit, float value, DisplayMetrics metrics)
From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java
/** @hide */ @RestrictTo(LIBRARY_GROUP)// w ww . j a va 2 s . com void setTextSizeInternal(int unit, float size) { Resources res = mContext == null ? Resources.getSystem() : mContext.getResources(); setRawTextSize(TypedValue.applyDimension(unit, size, res.getDisplayMetrics())); }
From source file:com.einzig.ipst2.activities.MainActivity.java
public void setLayoutParamsGraphBars(int height, TextView layout) { ViewGroup.LayoutParams params = layout.getLayoutParams(); params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height + 35, getResources().getDisplayMetrics()); Logger.d("HEIGHT: " + params.height); layout.setLayoutParams(params);/* ww w. j a va 2 s .c o m*/ }
From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java
/** * This will fill the UI elements with information from the database * It also saves information for AsyncTasks to use later and manages the transform/flip button * * @param id the ID of the the card to be displayed * @return true if the UI was filled in, false otherwise *///from w w w. ja v a2 s . c om public void setInfoFromID(final long id) { /* If the views are null, don't attempt to fill them in */ if (mSetTextView == null) { return; } ImageGetter imgGetter = ImageGetterHelper.GlyphGetter(getActivity()); SQLiteDatabase database = DatabaseManager.getInstance(getActivity(), false).openDatabase(false); Cursor cCardById; try { cCardById = CardDbAdapter.fetchCards(new long[] { id }, null, database); } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } /* http://magiccards.info/scans/en/mt/55.jpg */ mCardName = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NAME)); mCardCMC = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_CMC)); mSetCode = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)); /* Start building a description */ addToDescription(getString(R.string.search_name), mCardName); try { mSetName = CardDbAdapter.getSetNameFromCode(mSetCode, database); addToDescription(getString(R.string.search_set), mSetName); } catch (FamiliarDbException e) { /* no set for you */ } try { mMagicCardsInfoSetCode = CardDbAdapter .getCodeMtgi(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)), database); } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } mCardNumber = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER)); switch ((char) cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_RARITY))) { case 'C': case 'c': mSetTextView .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_common))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Common)); break; case 'U': case 'u': mSetTextView.setTextColor( ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_uncommon))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Uncommon)); break; case 'R': case 'r': mSetTextView .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_rare))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Rare)); break; case 'M': case 'm': mSetTextView .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_mythic))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Mythic)); break; case 'T': case 't': mSetTextView.setTextColor( ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_timeshifted))); addToDescription(getString(R.string.search_rarity), getString(R.string.search_Timeshifted)); break; } String sCost = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_MANACOST)); addToDescription(getString(R.string.search_mana_cost), sCost); CharSequence csCost = ImageGetterHelper.formatStringWithGlyphs(sCost, imgGetter); mCostTextView.setText(csCost); String sAbility = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ABILITY)); addToDescription(getString(R.string.search_text), sAbility); CharSequence csAbility = ImageGetterHelper.formatStringWithGlyphs(sAbility, imgGetter); mAbilityTextView.setText(csAbility); mAbilityTextView.setMovementMethod(LinkMovementMethod.getInstance()); String sFlavor = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_FLAVOR)); addToDescription(getString(R.string.search_flavor_text), sFlavor); CharSequence csFlavor = ImageGetterHelper.formatStringWithGlyphs(sFlavor, imgGetter); mFlavorTextView.setText(csFlavor); mNameTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NAME))); mCardType = CardDbAdapter.getTypeLine(cCardById); mTypeTextView.setText(mCardType); mSetTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET))); mArtistTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ARTIST))); String numberAndRarity = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER)) + " (" + (char) cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_RARITY)) + ")"; mNumberTextView.setText(numberAndRarity); addToDescription(getString(R.string.search_type), CardDbAdapter.getTypeLine(cCardById)); addToDescription(getString(R.string.search_artist), cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ARTIST))); addToDescription(getString(R.string.search_collectors_number), cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER))); int loyalty = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_LOYALTY)); float p = cCardById.getFloat(cCardById.getColumnIndex(CardDbAdapter.KEY_POWER)); float t = cCardById.getFloat(cCardById.getColumnIndex(CardDbAdapter.KEY_TOUGHNESS)); if (loyalty != CardDbAdapter.NO_ONE_CARES) { if (loyalty == CardDbAdapter.X) { mPowTouTextView.setText("X"); } else { mPowTouTextView.setText(Integer.valueOf(loyalty).toString()); } } else if (p != CardDbAdapter.NO_ONE_CARES && t != CardDbAdapter.NO_ONE_CARES) { String powTouStr = ""; if (p == CardDbAdapter.STAR) powTouStr += "*"; else if (p == CardDbAdapter.ONE_PLUS_STAR) powTouStr += "1+*"; else if (p == CardDbAdapter.TWO_PLUS_STAR) powTouStr += "2+*"; else if (p == CardDbAdapter.SEVEN_MINUS_STAR) powTouStr += "7-*"; else if (p == CardDbAdapter.STAR_SQUARED) powTouStr += "*^2"; else if (p == CardDbAdapter.X) powTouStr += "X"; else { if (p == (int) p) { powTouStr += (int) p; } else { powTouStr += p; } } powTouStr += "/"; if (t == CardDbAdapter.STAR) powTouStr += "*"; else if (t == CardDbAdapter.ONE_PLUS_STAR) powTouStr += "1+*"; else if (t == CardDbAdapter.TWO_PLUS_STAR) powTouStr += "2+*"; else if (t == CardDbAdapter.SEVEN_MINUS_STAR) powTouStr += "7-*"; else if (t == CardDbAdapter.STAR_SQUARED) powTouStr += "*^2"; else if (t == CardDbAdapter.X) powTouStr += "X"; else { if (t == (int) t) { powTouStr += (int) t; } else { powTouStr += t; } } addToDescription(getString(R.string.search_power), powTouStr); mPowTouTextView.setText(powTouStr); } else { mPowTouTextView.setText(""); } boolean isMultiCard = false; switch (CardDbAdapter.isMultiCard(mCardNumber, cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)))) { case NOPE: isMultiCard = false; mTransformButton.setVisibility(View.GONE); mTransformButtonDivider.setVisibility(View.GONE); break; case TRANSFORM: isMultiCard = true; mTransformButton.setVisibility(View.VISIBLE); mTransformButtonDivider.setVisibility(View.VISIBLE); mTransformButton.setText(R.string.card_view_transform); break; case FUSE: isMultiCard = true; mTransformButton.setVisibility(View.VISIBLE); mTransformButtonDivider.setVisibility(View.VISIBLE); mTransformButton.setText(R.string.card_view_fuse); break; case SPLIT: isMultiCard = true; mTransformButton.setVisibility(View.VISIBLE); mTransformButtonDivider.setVisibility(View.VISIBLE); mTransformButton.setText(R.string.card_view_other_half); break; } if (isMultiCard) { if (mCardNumber.contains("a")) { mTransformCardNumber = mCardNumber.replace("a", "b"); } else if (mCardNumber.contains("b")) { mTransformCardNumber = mCardNumber.replace("b", "a"); } try { mTransformId = CardDbAdapter.getIdFromSetAndNumber(mSetCode, mTransformCardNumber, database); } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } if (mTransformId == -1) { mTransformButton.setVisibility(View.GONE); mTransformButtonDivider.setVisibility(View.GONE); } else { mTransformButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { releaseImageResources(true); mCardNumber = mTransformCardNumber; setInfoFromID(mTransformId); } }); } } mMultiverseId = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_MULTIVERSEID)); /* Do we load the image immediately to the main page, or do it in a dialog later? */ if (mActivity.mPreferenceAdapter.getPicFirst()) { mImageScrollView.setVisibility(View.VISIBLE); mTextScrollView.setVisibility(View.GONE); mActivity.setLoading(); if (mAsyncTask != null) { mAsyncTask.cancel(true); } mAsyncTask = new FetchPictureTask(); ((FetchPictureTask) mAsyncTask).execute(MAIN_PAGE); } else { mImageScrollView.setVisibility(View.GONE); mTextScrollView.setVisibility(View.VISIBLE); } /* Figure out how large the color indicator should be. Medium text is 18sp, with a border its 22sp */ int dimension = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 22, getResources().getDisplayMetrics()); mColorIndicatorLayout.removeAllViews(); ColorIndicatorView civ = new ColorIndicatorView(this.getActivity(), dimension, dimension / 15, cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_COLOR)), sCost); if (civ.shouldInidcatorBeShown()) { mColorIndicatorLayout.setVisibility(View.VISIBLE); mColorIndicatorLayout.addView(civ); } else { mColorIndicatorLayout.setVisibility(View.GONE); } String allLanguageKeys[][] = { { Language.Chinese_Traditional, CardDbAdapter.KEY_NAME_CHINESE_TRADITIONAL, CardDbAdapter.KEY_MULTIVERSEID_CHINESE_TRADITIONAL }, { Language.Chinese_Simplified, CardDbAdapter.KEY_NAME_CHINESE_SIMPLIFIED, CardDbAdapter.KEY_MULTIVERSEID_CHINESE_SIMPLIFIED }, { Language.French, CardDbAdapter.KEY_NAME_FRENCH, CardDbAdapter.KEY_MULTIVERSEID_FRENCH }, { Language.German, CardDbAdapter.KEY_NAME_GERMAN, CardDbAdapter.KEY_MULTIVERSEID_GERMAN }, { Language.Italian, CardDbAdapter.KEY_NAME_ITALIAN, CardDbAdapter.KEY_MULTIVERSEID_ITALIAN }, { Language.Japanese, CardDbAdapter.KEY_NAME_JAPANESE, CardDbAdapter.KEY_MULTIVERSEID_JAPANESE }, { Language.Portuguese_Brazil, CardDbAdapter.KEY_NAME_PORTUGUESE_BRAZIL, CardDbAdapter.KEY_MULTIVERSEID_PORTUGUESE_BRAZIL }, { Language.Russian, CardDbAdapter.KEY_NAME_RUSSIAN, CardDbAdapter.KEY_MULTIVERSEID_RUSSIAN }, { Language.Spanish, CardDbAdapter.KEY_NAME_SPANISH, CardDbAdapter.KEY_MULTIVERSEID_SPANISH }, { Language.Korean, CardDbAdapter.KEY_NAME_KOREAN, CardDbAdapter.KEY_MULTIVERSEID_KOREAN } }; // Clear the translations first mTranslatedNames.clear(); // Add English Card.ForeignPrinting englishPrinting = new Card.ForeignPrinting(); englishPrinting.mLanguageCode = Language.English; englishPrinting.mName = mCardName; englishPrinting.mMultiverseId = mMultiverseId; mTranslatedNames.add(englishPrinting); // Add all the others for (String lang[] : allLanguageKeys) { Card.ForeignPrinting fp = new Card.ForeignPrinting(); fp.mLanguageCode = lang[0]; fp.mName = cCardById.getString(cCardById.getColumnIndex(lang[1])); fp.mMultiverseId = cCardById.getInt(cCardById.getColumnIndex(lang[2])); if (fp.mName != null && !fp.mName.isEmpty()) { mTranslatedNames.add(fp); } } cCardById.close(); /* Find the other sets this card is in ahead of time, so that it can be remove from the menu if there is only one set */ Cursor cCardByName; try { cCardByName = CardDbAdapter.fetchCardByName(mCardName, new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_SET, CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID, CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_NUMBER }, false, database); } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } mPrintings = new LinkedHashSet<>(); mCardIds = new LinkedHashSet<>(); while (!cCardByName.isAfterLast()) { try { String number = cCardByName.getString(cCardByName.getColumnIndex(CardDbAdapter.KEY_NUMBER)); if (!(number == null || number.length() == 0)) { number = " (" + number + ")"; } else { number = ""; } if (mPrintings.add(CardDbAdapter.getSetNameFromCode( cCardByName.getString(cCardByName.getColumnIndex(CardDbAdapter.KEY_SET)), database) + number)) { mCardIds.add(cCardByName.getLong(cCardByName.getColumnIndex(CardDbAdapter.KEY_ID))); } } catch (FamiliarDbException e) { handleFamiliarDbException(true); DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); return; } cCardByName.moveToNext(); } cCardByName.close(); /* If it exists in only one set, remove the button from the menu */ if (mPrintings.size() == 1) { mActivity.supportInvalidateOptionsMenu(); } DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); if (mShouldReportView) { reportAppIndexViewIfAble(); } }
From source file:com.achep.acdisplay.Config.java
/** * @return the size (or height only) of collapsed views. * @see #getIconSizePx()/*from w w w. j a va 2 s . co m*/ * @see #ICON_SIZE_DP * @see #ICON_SIZE_PX */ public int getIconSize(String type) { switch (type) { case ICON_SIZE_PX: DisplayMetrics dm = Resources.getSystem().getDisplayMetrics(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUiIconSize, dm); case ICON_SIZE_DP: return mUiIconSize; default: throw new IllegalArgumentException(type + " is not a valid icon size type."); } }
From source file:self.philbrown.droidQuery.$.java
/** * Interprets the CSS-style String and sets the value * @param view the view that will change. * @param key the name of the attribute//from w w w. j av a 2 s . com * @param _value the end animation value * @return the computed value */ public Number getAnimationValue(View view, String key, String _value) { Number value = null; boolean negativeValue = false; if (_value.startsWith("-")) { negativeValue = true; _value = _value.substring(1); } String[] split = (_value).split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)"); if (negativeValue) split[0] = String.format(Locale.US, "-%s", split[0]); if (split.length == 1) { if (split[0].contains(".")) { value = Float.valueOf(split[0]); } else { value = Integer.valueOf(split[0]); } } else { if (split.length > 2) { Log.w("droidQuery", "parsererror for key " + key); return null; } if (split[1].equalsIgnoreCase("px")) { //this is the default. Just determine if float or int if (split[0].contains(".")) { value = Float.valueOf(split[0]); } else { value = Integer.valueOf(split[0]); } } else if (split[1].equalsIgnoreCase("dip") || split[1].equalsIgnoreCase("dp")) { float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Float.parseFloat(split[0]), context.getResources().getDisplayMetrics()); if (split[0].contains(".")) { value = px; } else { value = (int) px; } } else if (split[1].equalsIgnoreCase("in")) { float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_IN, Float.parseFloat(split[0]), context.getResources().getDisplayMetrics()); if (split[0].contains(".")) { value = px; } else { value = (int) px; } } else if (split[1].equalsIgnoreCase("mm")) { float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, Float.parseFloat(split[0]), context.getResources().getDisplayMetrics()); if (split[0].contains(".")) { value = px; } else { value = (int) px; } } else if (split[1].equalsIgnoreCase("pt")) { float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, Float.parseFloat(split[0]), context.getResources().getDisplayMetrics()); if (split[0].contains(".")) { value = px; } else { value = (int) px; } } else if (split[1].equalsIgnoreCase("sp")) { float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, Float.parseFloat(split[0]), context.getResources().getDisplayMetrics()); if (split[0].contains(".")) { value = px; } else { value = (int) px; } } else if (split[1].equals("%")) { ViewParent parent = view.getParent(); float pixels = 0; if (parent == null || !(parent instanceof View)) { pixels = context.getResources().getDisplayMetrics().widthPixels; //use best guess for width or height dpi if (split[0].equalsIgnoreCase("y") || split[0].equalsIgnoreCase("top") || split[0].equalsIgnoreCase("bottom")) { pixels = context.getResources().getDisplayMetrics().heightPixels; } } else { pixels = ((View) parent).getWidth(); if (split[0].equalsIgnoreCase("y") || split[0].equalsIgnoreCase("top") || split[0].equalsIgnoreCase("bottom")) { pixels = ((View) parent).getHeight(); } } float percent = 0; if (pixels != 0) percent = Float.valueOf(split[0]) / 100 * pixels; if (split[0].contains(".")) { value = percent; } else { value = (int) percent; } } else { Log.w("droidQuery", "invalid units for Object with key " + key); return null; } } return value; }
From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java
private void assignDefaultsIfNeeded() { if (mOuterRadius == 0.0f) { mOuterRadius = Math.max(mOuterRing.getWidth(), mOuterRing.getHeight()) / 2.0f; }//from w w w .j a va 2s .c o m if (mSnapMargin == 0.0f) { mSnapMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, SNAP_MARGIN_DEFAULT, getContext().getResources().getDisplayMetrics()); } if (mInnerRadius == 0.0f) { mInnerRadius = mHandleDrawable.getWidth() / 10.0f; } }
From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java
/** * Convert our DIP units to Pixels//from w w w . j a va 2s .com * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; }
From source file:com.android.launcher3.Utilities.java
public static int pxFromDp(float size, DisplayMetrics metrics) { return (int) Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size, metrics)); }
From source file:com.android.gallery3d.filtershow.FilterShowActivity.java
public float getPixelsFromDip(float value) { Resources r = getResources(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, r.getDisplayMetrics()); }
From source file:com.android.launcher3.Utilities.java
public static int pxFromSp(float size, DisplayMetrics metrics) { return (int) Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, size, metrics)); }