List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:com.ryan.ryanreader.views.SubredditHeader.java
public SubredditHeader(final Context context, final RedditSubreddit subreddit) { super(context); final float dpScale = context.getResources().getDisplayMetrics().density; setOrientation(LinearLayout.VERTICAL); final int sidesPadding = (int) (15.0f * dpScale); final int topPadding = (int) (10.0f * dpScale); setPadding(sidesPadding, topPadding, sidesPadding, topPadding); final Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Light.ttf"); final TextView title = new TextView(context); title.setTextSize(22.0f);/*from w ww. j a v a 2s .c o m*/ title.setTypeface(tf); title.setText(StringEscapeUtils.unescapeHtml4(subreddit.title)); title.setTextColor(Color.WHITE); addView(title); final TextView subs = new TextView(context); subs.setTextSize(14.0f); if (subreddit.subscribers == null) { subs.setText("Subscriber count is unknown"); } else { subs.setText(NumberFormat.getNumberInstance(Locale.getDefault()).format(subreddit.subscribers) + " subscribers"); } subs.setTextColor(Color.rgb(200, 200, 200)); addView(subs); setBackgroundColor(Color.rgb(50, 50, 50)); // TODO theme color }
From source file:com.mindgames.dailylaw.external.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 w ww .j a v a 2s . c om*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); Typeface tf1 = Typeface.createFromAsset(context.getAssets(), "fonts/proxima_nova.otf"); textView.setTypeface(tf1); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:dev.vision.shopping.center.Splash.java
private void overrideFonts(final Context context, final View v) { try {/* ww w. j ava2 s .c om*/ if (v instanceof ViewGroup) { ViewGroup vg = (ViewGroup) v; for (int i = 0; i < vg.getChildCount(); i++) { View child = vg.getChildAt(i); overrideFonts(context, child); } } else if (v instanceof TextView) { ((TextView) v) .setTypeface(Typeface.createFromAsset(context.getAssets(), "AvantGardeITCbyBTBook.otf")); } } catch (Exception e) { } }
From source file:ar.com.lapotoca.resiliencia.gallery.util.ImageWorker.java
protected ImageWorker(Context context) { mResources = context.getResources(); mAssets = context.getAssets(); }
From source file:ac.robinson.paperchains.SoundCloudUploadTask.java
private File getAppIconCacheFile(Context context) { if (context == null) { return null; }/* ww w . j av a 2s .com*/ // if we've already created the file, just return it File cacheFile = new File(context.getCacheDir(), "paperchains.png"); if (cacheFile.exists()) { return cacheFile; } // otherwise, load from assets try { InputStream inputStream = context.getAssets().open("paperchains.png"); // suppressed as it requires API level 19 //noinspection TryFinallyCanBeTryWithResources try { FileOutputStream outputStream = new FileOutputStream(cacheFile); //noinspection TryFinallyCanBeTryWithResources try { byte[] buf = new byte[1024]; int len; while ((len = inputStream.read(buf)) > 0) { outputStream.write(buf, 0, len); } } finally { outputStream.close(); } } finally { inputStream.close(); } } catch (IOException e) { return null; } return cacheFile; }
From source file:com.netpace.expressit.android.ui.TypefaceEditText.java
public TypefaceEditText(Context context, AttributeSet attrs) { super(context, attrs); // Get our custom attributes TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TypefaceTextView, 0, 0); try {//www.ja v a 2 s. c o m String typefaceName = a.getString(R.styleable.TypefaceTextView_typeface); if (!isInEditMode() && !TextUtils.isEmpty(typefaceName)) { Typeface typeface = sTypefaceCache.get(typefaceName); if (typeface == null) { typeface = Typeface.createFromAsset(context.getAssets(), String.format("fonts/%s_0.otf", typefaceName)); // Cache the Typeface object sTypefaceCache.put(typefaceName, typeface); } setTypeface(typeface); // Note: This flag is required for proper typeface rendering setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); } } finally { a.recycle(); } }
From source file:zuo.biao.library.manager.HttpManager.java
private HttpManager(Context context) { this.context = context; try {/*from w ww . ja v a 2 s . co m*/ //TODO ???demo.cerdemo.cer?????assets????? socketFactory = SSLUtil.getSSLSocketFactory(context.getAssets().open("demo.cer")); } catch (Exception e) { Log.e(TAG, "HttpManager try {" + " socketFactory = SSLUtil.getSSLSocketFactory(context.getAssets().open(\"demo.cer\"));\n" + "\t\t} catch (Exception e) {\n" + e.getMessage()); } }
From source file:com.ipa.Tools.TypefaceTextView.java
public TypefaceTextView(Context context, AttributeSet attrs) { super(context, attrs); // Get our custom attributes TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TypefaceTextView, 0, 0); try {/*from w ww . j a v a 2 s .co m*/ String typefaceName = a.getString(R.styleable.TypefaceTextView_typeface); if (!isInEditMode() && !TextUtils.isEmpty(typefaceName)) { Typeface typeface = sTypefaceCache.get(typefaceName); if (typeface == null) { typeface = Typeface.createFromAsset(context.getAssets(), String.format("fonts/%s-Family.otf", typefaceName)); // Cache the Typeface object sTypefaceCache.put(typefaceName, typeface); } setTypeface(typeface); // Note: This flag is required for proper typeface rendering setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); } } finally { a.recycle(); } }
From source file:se.frikod.payday.TypefaceTextView.java
public TypefaceTextView(Context context, AttributeSet attrs) { super(context, attrs); // Get our custom attributes TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TypefaceTextView, 0, 0); try {//from w w w .j av a 2 s . c o m String typefaceName = a.getString(R.styleable.TypefaceTextView_typeface); if (!isInEditMode() && !TextUtils.isEmpty(typefaceName)) { Typeface typeface = sTypefaceCache.get(typefaceName); if (typeface == null) { typeface = Typeface.createFromAsset(context.getAssets(), String.format("%s", typefaceName)); // Cache the Typeface object sTypefaceCache.put(typefaceName, typeface); } setTypeface(typeface); // Note: This flag is required for proper typeface rendering setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); } } finally { a.recycle(); } }