List of usage examples for android.util TypedValue COMPLEX_UNIT_SP
int COMPLEX_UNIT_SP
To view the source code for android.util TypedValue COMPLEX_UNIT_SP.
Click Source Link
From source file:Main.java
public static TextPaint setTextSize(Context c, TextPaint paint, float size) { Resources r;/*from www . j a va2 s . com*/ if (c == null) { r = Resources.getSystem(); } else { r = c.getResources(); } if (r != null) { paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, size, r.getDisplayMetrics())); } return paint; }
From source file:Main.java
/** * sp to px//w w w .j a v a2 s. c o m * @param context * @param px * @return */ public static int sp2px(Context context, int px) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, px, context.getResources().getDisplayMetrics()); }
From source file:Main.java
public static int sp2px(Context context, float spValue) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, context.getResources().getDisplayMetrics()); }
From source file:Main.java
public static int sp2dip(Context c, float spValue) { return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, c.getResources().getDisplayMetrics())); }
From source file:Main.java
public static int getPixelsFromSp(Context context, int sp) { Resources r = context.getResources(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, r.getDisplayMetrics()); }
From source file:Main.java
public static float applyDimension(int unit, float value, DisplayMetrics metrics) { switch (unit) { case TypedValue.COMPLEX_UNIT_PX: return value; case TypedValue.COMPLEX_UNIT_DIP: return value * metrics.density; case TypedValue.COMPLEX_UNIT_SP: return value * metrics.scaledDensity; case TypedValue.COMPLEX_UNIT_PT: return value * metrics.xdpi * (1.0f / 72); case TypedValue.COMPLEX_UNIT_IN: return value * metrics.xdpi; case TypedValue.COMPLEX_UNIT_MM: return value * metrics.xdpi * (1.0f / 25.4f); }//from ww w .j a v a 2 s.co m return 0; }
From source file:Main.java
/** * Set the original text size of the View. * * @see TextView#setTextSize(float)/*from ww w.j a va2 s .com*/ */ public void setTextSize(float size) { setTextSize(TypedValue.COMPLEX_UNIT_SP, size); }
From source file:com.ruenzuo.through.activities.LicensesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.licenses_activity_layout); getActionBar().setDisplayHomeAsUpEnabled(true); AssetManager assetManager = getAssets(); try {/*w ww .jav a2s .c o m*/ InputStream inputStream = assetManager.open("licenses/licenses.txt"); StringWriter stringWriter = new StringWriter(); IOUtils.copy(inputStream, stringWriter); String licenses = stringWriter.toString(); TextView txtViewLicenses = (TextView) findViewById(R.id.txtViewLicenses); txtViewLicenses.setText(licenses); txtViewLicenses.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.ruenzuo.pokeffective.activities.InfoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.info_activity); getActionBar().setDisplayHomeAsUpEnabled(true); Uri data = getIntent().getData();/*from ww w . j ava2 s . c o m*/ if (data != null) { getActionBar().setTitle("License"); AssetManager assetManager = getAssets(); try { InputStream inputStream = assetManager.open("licenses/licenses.txt"); StringWriter stringWriter = new StringWriter(); IOUtils.copy(inputStream, stringWriter); String licenses = stringWriter.toString(); TextView txtViewLicenses = (TextView) findViewById(R.id.txtViewLicenses); txtViewLicenses.setText(licenses); txtViewLicenses.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.achillesrasquinha.biblegenerator.ImageGenerator.java
public ImageGenerator(Context context) { mContext = context;//from w w w . j a v a2 s. c o m DisplayMetrics m = mContext.getResources().getDisplayMetrics(); mImageSize = new Point(); mImageSize.x = m.widthPixels; mImageSize.y = mImageSize.x; mX = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, m)); mSizeTitle = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 24, m); mYTitle = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, m) + mSizeTitle); mSizeSubtitle = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14, m); mYSubtitle = Math .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, m) + mYTitle + mSizeSubtitle); mLineSpacing = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, m); mTextPaint = new TextPaint(); mTextPaint.setAntiAlias(true); mTextPaint.setTextAlign(TextPaint.Align.LEFT); mTextPaint.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "fonts/Roboto/Roboto-Medium.ttf")); mColor1 = ContextCompat.getColor(mContext, R.color.primary_text_default_material_light); mColor2 = ContextCompat.getColor(mContext, R.color.primary_text_disabled_material_light); mColor3 = ContextCompat.getColor(mContext, R.color.secondary_text_default_material_light); }