List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:com.sythealth.fitness.util.Utils.java
public static void setTypeface2(Context context, TextView tv) { Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/shishanghei.ttf"); tv.setTypeface(typeface);/*from ww w . j a v a2 s .c o m*/ }
From source file:me.zhang.bingo.Utility.java
public static void applyCustomFont(Context context, TextView targetView) { Typeface font = Typeface.createFromAsset(context.getAssets(), "IndieFlower.ttf"); targetView.setTypeface(font);/*from ww w .ja v a 2 s. co m*/ }
From source file:org.lol.reddit.common.General.java
public static Typeface getMonoTypeface(Context context) { if (monoTypeface == null) { monoTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/VeraMono.ttf"); }//from w ww . j av a 2 s . c om return monoTypeface; }
From source file:org.zywx.wbpalmstar.platform.certificates.Http.java
private static InputStream getInputStream(String cPath, Context ctx) throws IOException, FileNotFoundException { InputStream inStream;/*from w ww. j ava2 s . c o m*/ String assertFile = "file:///android_asset/"; String sdcardFile = "/sdcard/"; String wgtFile = "widget/"; String file = "file://"; if (cPath.contains(assertFile)) { cPath = cPath.substring(assertFile.length()); AssetManager asset = ctx.getAssets(); inStream = asset.open(cPath); } else if (cPath.contains(sdcardFile)) { if (cPath.contains(file)) { cPath = cPath.substring("file://".length()); } inStream = new FileInputStream(cPath); } else if (cPath.startsWith(wgtFile)) { AssetManager asset = ctx.getAssets(); inStream = asset.open(cPath); } else { inStream = new FileInputStream(cPath); } return inStream; }
From source file:Main.java
/** * Show a level//ww w .j a v a 2 s . c om * * @param context The context * @param level The level */ public static void showLevel(Context context, int level) { String filename; switch (level) { case 1: { filename = "ground_floor.png"; break; } case 2: { filename = "talks_floor.png"; break; } default: { return; } } File f = new File(context.getFilesDir() + "/" + filename); try { if (f.exists() == false) { InputStream is = context.getAssets().open(filename); FileOutputStream fos = context.openFileOutput(filename, Context.MODE_WORLD_READABLE); byte[] buffer = new byte[is.available()]; is.read(buffer); // write the stream to file fos.write(buffer, 0, buffer.length); fos.close(); is.close(); } // Prepare the intent //TODO - create an activity for this instead. Internal viewers might be quite heavy Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(f), "image/png"); context.startActivity(intent); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.quarterfull.newsAndroid.NewsDetailFragment.java
static String getTextFromAssets(String fileName, Context context) { InputStream input;//from w w w. j av a2 s . c o m try { input = context.getAssets().open(fileName); int size = input.available(); byte[] buffer = new byte[size]; input.read(buffer); input.close(); // byte buffer into a string return new String(buffer); } catch (Exception ex) { ex.printStackTrace(); } return ""; }
From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java
public static void extractAsset(Context context, String src, File dest) throws IOException { InputStream i = null;/*from w w w. j av a 2 s . c o m*/ FileOutputStream o = null; try { i = context.getAssets().open(src); o = new FileOutputStream(dest); IOUtils.copy(i, o); } finally { IOUtils.closeQuietly(i); IOUtils.closeQuietly(o); } }
From source file:com.brewcrewfoo.performance.util.Helpers.java
public synchronized static void get_assetsBinary(String fn, Context c) { byte[] buffer; final AssetManager assetManager = c.getAssets(); try {//from w ww. j a v a 2 s. c o m InputStream f = assetManager.open(fn); buffer = new byte[f.available()]; f.read(buffer); f.close(); try { FileOutputStream fos; fos = c.openFileOutput(fn, Context.MODE_PRIVATE); fos.write(buffer); fos.close(); } catch (IOException e) { Log.d(TAG, "error write " + fn + " file"); e.printStackTrace(); } } catch (IOException e) { Log.d(TAG, "error read " + fn + " file"); e.printStackTrace(); } }
From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.SR167TollRatesFragment.java
/** * Returns a view for the toll trip provided by the tripItem. * A tripItem holds information about the trip destination and toll rate * * @param tripItem//from www. j a v a 2 s .c o m * @param context * @return */ public static View makeTripView(TollTripEntity tripItem, TollRateSignEntity sign, Context context) { Typeface tfb = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Bold.ttf"); LayoutInflater li = LayoutInflater.from(context); View cv = li.inflate(R.layout.trip_view, null); cv.findViewById(R.id.title).setVisibility(View.GONE); ((TextView) cv.findViewById(R.id.subtitle)).setText("Show on map"); ((TextView) cv.findViewById(R.id.subtitle)) .setTextColor(context.getResources().getColor(R.color.primary_default)); cv.findViewById(R.id.subtitle).setOnClickListener(v -> { Bundle b = new Bundle(); b.putDouble("startLat", sign.getStartLatitude()); b.putDouble("startLong", sign.getStartLongitude()); b.putDouble("endLat", tripItem.getEndLatitude()); b.putDouble("endLong", tripItem.getEndLongitude()); b.putString("title", sign.getLocationName()); b.putString("text", String.format("Travel as far as %s.", tripItem.getEndLocationName())); Intent intent = new Intent(context, TollRatesRouteActivity.class); intent.putExtras(b); context.startActivity(intent); }); ((TextView) cv.findViewById(R.id.content)).setText("Carpools and motorcycles free"); // set updated label ((TextView) cv.findViewById(R.id.updated)) .setText(ParserUtils.relativeTime(tripItem.getUpdated(), "MMMM d, yyyy h:mm a", false)); // set toll TextView currentTimeTextView = cv.findViewById(R.id.current_value); currentTimeTextView.setTypeface(tfb); currentTimeTextView.setText(String.format(Locale.US, "$%.2f", tripItem.getTollRate() / 100)); // set message if there is one if (!tripItem.getMessage().equals("null")) { currentTimeTextView.setText(tripItem.getMessage()); } return cv; }
From source file:com.android.build.gradle.internal.incremental.fixture.ClassEnhancement.java
private static Map<String, List<String>> findEnhancedClasses(final Map<String, File> compileOutputFolders) { final Context context = InstrumentationRegistry.getContext(); return Maps.transformEntries(compileOutputFolders, new Maps.EntryTransformer<String, File, List<String>>() { @Override//from ww w . ja v a2s . c o m public List<String> transformEntry(@Nullable String patch, @Nullable File outputFolder) { try { InputStream classesIS = context.getAssets().open(outputFolder.getPath() + "/classes.txt"); try { Iterable<String> classPaths = Splitter.on('\n').omitEmptyStrings() .split(CharStreams.toString(new InputStreamReader(classesIS, Charsets.UTF_8))); return Lists.newArrayList(Iterables.transform(classPaths, new Function<String, String>() { @Override public String apply(@Nullable String relativePath) { return relativePath.substring(0, relativePath.length() - 6 /*.class */).replace('/', '.'); } })); } finally { classesIS.close(); } } catch (IOException e) { throw new IllegalArgumentException("Could not open patch classes.dex", e); } } }); }