List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:com.liken.customviews.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); Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Aaargh.ttf"); // Cache the Typeface object // sTypefaceCache.put(typefaceName, typeface); setTypeface(typeface);//from www . j av a2 s. c om /* try { String typefaceName = a.getString( R.styleable.TypefaceTextView_Aaargh); if (!isInEditMode() && !TextUtils.isEmpty(typefaceName)) { Typeface typeface = sTypefaceCache.get(typefaceName); if (typeface == null) { typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Aaargh.ttf"); // 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:com.benlinskey.greekreference.GreekTextView.java
/** * Class constructor./*from www. j a v a 2s . c o m*/ * * @param context * @param attrs */ @SuppressWarnings("JavaDoc") public GreekTextView(Context context, AttributeSet attrs) { super(context, attrs); if (!isInEditMode() && !TextUtils.isEmpty(TYPEFACE_NAME)) { Typeface typeface = sTypefaceCache.get(TYPEFACE_NAME); if (typeface == null) { typeface = Typeface.createFromAsset(context.getAssets(), "fonts/" + TYPEFACE_NAME); // Cache the Typeface object sTypefaceCache.put(TYPEFACE_NAME, typeface); } setTypeface(typeface); int textColor = getResources() .getColor(android.support.v7.appcompat.R.color.primary_text_default_material_light); setTextColor(textColor); // Note: This flag is required for proper typeface rendering setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); } }
From source file:com.javielinux.utils.Utils.java
public static String getAsset(Context cnt, String file) { AssetManager assetManager = cnt.getAssets(); InputStream inputStream = null; try {// w w w . ja va 2s. co m inputStream = assetManager.open(file); } catch (IOException e) { Log.d(TAG, "No se ha podido cargar el fichero " + file); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte buf[] = new byte[1024]; int len; try { while ((len = inputStream.read(buf)) != -1) { outputStream.write(buf, 0, len); } outputStream.close(); inputStream.close(); } catch (IOException e) { } return outputStream.toString(); }
From source file:org.exobel.routerkeygen.ui.WifiListAdapter.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public WifiListAdapter(Context context) { this.listNetworks = new ArrayList<>(); try {//w w w.j ava 2 s .c o m typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Light.ttf"); } catch (Exception e) { // Rarely some devices have a problem creating this typeface } final Resources resources = context.getResources(); inflater = LayoutInflater.from(context); wifiSignal = new Drawable[4]; wifiSignalLocked = new Drawable[4]; final int currentApiVersion = android.os.Build.VERSION.SDK_INT; for (int i = 0; i < 4; ++i) { switch (i) { case 0: wifiSignal[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_1_bar_black_24dp); wifiSignalLocked[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_1_bar_lock_black_24dp); break; case 1: wifiSignal[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_2_bar_black_24dp); wifiSignalLocked[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_2_bar_lock_black_24dp); break; case 2: wifiSignal[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_3_bar_black_24dp); wifiSignalLocked[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_3_bar_lock_black_24dp); break; case 3: wifiSignal[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_4_bar_black_24dp); wifiSignalLocked[i] = ContextCompat.getDrawable(context, R.drawable.ic_signal_wifi_4_bar_lock_black_24dp); break; } if (currentApiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { wifiSignal[i].setTint(resources.getColor(R.color.wifi_icons)); wifiSignalLocked[i].setTint(resources.getColor(R.color.wifi_icons)); } else { wifiSignal[i].setColorFilter(resources.getColor(R.color.wifi_icons), PorterDuff.Mode.SRC_IN); wifiSignalLocked[i].setColorFilter(resources.getColor(R.color.wifi_icons), PorterDuff.Mode.SRC_IN); } } }
From source file:org.onepf.opfmaps.osmdroid.model.BitmapDescriptor.java
@NonNull private InputStream createStream(@NonNull final Context context) throws IOException { if (path == null) { throw new IllegalArgumentException("Path can't be null"); }/*from w ww .j a v a 2 s . c o m*/ switch (source) { case ASSET: return context.getAssets().open(path); case FILE_NAME: return context.openFileInput(path); } throw new IllegalArgumentException("Wrong source : " + source); }
From source file:edu.mit.mobile.android.imagecache.test.ImageCacheJunitTest.java
/** * Loads a file from the assets and saves it to a public location. * * @return/*from w w w . j av a 2 s . c om*/ * @throws IOException */ private Uri loadLocalFile() throws IOException { final String testfile = "logo_locast.png"; final Context contextInst = getInstrumentation().getContext(); final Context context = getInstrumentation().getTargetContext(); final InputStream is = contextInst.getAssets().open(testfile); assertNotNull(is); final FileOutputStream fos = context.openFileOutput(testfile, Context.MODE_PRIVATE); assertNotNull(fos); int read = 0; final byte[] bytes = new byte[1024]; while ((read = is.read(bytes)) != -1) { fos.write(bytes, 0, read); } is.close(); fos.close(); final File outFile = context.getFileStreamPath(testfile); final Uri fileUri = Uri.fromFile(outFile); assertNotNull(fileUri); return fileUri; }
From source file:com.sogrey.sinaweibo.utils.FileUtil.java
/** * ???Asset?./*from ww w . j av a2s. co m*/ * * @param context * the context * @param fileName * the file name * @return Bitmap */ public static Bitmap getBitmapFromAsset(Context context, String fileName) { Bitmap bit = null; try { AssetManager assetManager = context.getAssets(); InputStream is = assetManager.open(fileName); bit = BitmapFactory.decodeStream(is); } catch (Exception e) { LogUtil.d(FileUtil.class, "?" + e.getMessage()); } return bit; }
From source file:com.sogrey.sinaweibo.utils.FileUtil.java
/** * ???Asset?.//from w w w . j a va 2 s. c o m * * @param context * the context * @param fileName * the file name * @return Drawable */ public static Drawable getDrawableFromAsset(Context context, String fileName) { Drawable drawable = null; try { AssetManager assetManager = context.getAssets(); InputStream is = assetManager.open(fileName); drawable = Drawable.createFromStream(is, null); } catch (Exception e) { LogUtil.d(FileUtil.class, "?" + e.getMessage()); } return drawable; }
From source file:com.gnuroot.rsinstaller.RSLauncherMain.java
/** * Renames assets from .mp3 to .tar.gz./*from w ww . j a va2s . c o m*/ * @param packageName */ private void copyAssets(String packageName) { Context friendContext = null; try { friendContext = this.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); } catch (NameNotFoundException e1) { return; } AssetManager assetManager = friendContext.getAssets(); String[] files = null; try { files = assetManager.list(""); } catch (IOException e) { Log.e("tag", "Failed to get asset file list.", e); } for (String filename : files) { Log.i("files ", filename); InputStream in = null; OutputStream out = null; try { in = assetManager.open(filename); filename = filename.replace(".mp3", ".tar.gz"); out = openFileOutput(filename, MODE_PRIVATE); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } catch (IOException e) { Log.e("tag", "Failed to copy asset file: " + filename, e); } } }
From source file:com.google.payments.InAppBillingV3.java
private JSONObject getManifestContents() { if (manifestObject != null) return manifestObject; Context context = this.cordova.getActivity(); InputStream is;/*w w w.j a va 2 s. c o m*/ try { is = context.getAssets().open("www/manifest.json"); Scanner s = new Scanner(is).useDelimiter("\\A"); String manifestString = s.hasNext() ? s.next() : ""; manifestObject = new JSONObject(manifestString); } catch (IOException e) { Log.d(TAG, "Unable to read manifest file:" + e.toString()); manifestObject = null; } catch (JSONException e) { Log.d(TAG, "Unable to parse manifest file:" + e.toString()); manifestObject = null; } return manifestObject; }