List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:org.zywx.wbpalmstar.engine.EUtil.java
public static void testDecode(Context ctx) { String url = "up.html"; AssetManager asset = ctx.getAssets(); InputStream pinput = null;/*www . j a v a 2 s. co m*/ ByteArrayBuffer buffer = new ByteArrayBuffer(1024 * 8); try { pinput = asset.open(url); int lenth = 0; while (lenth != -1) { byte[] buf = new byte[2048]; lenth = pinput.read(buf, 0, buf.length); if (lenth != -1) { buffer.append(buf, 0, lenth); } } } catch (IOException e) { e.printStackTrace(); } byte[] bt = buffer.toByteArray(); long begin = System.currentTimeMillis(); String dec = htmlDecode(bt, "up"); long end = System.currentTimeMillis(); Log.e("ldx", "use time: " + (end - begin)); Log.e("ldx", dec); }
From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.I405TollRatesFragment.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 ww w .j a v a 2 s . c om * @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); // set end location label ((TextView) cv.findViewById(R.id.title)).setText("to ".concat(tripItem.getEndLocationName())); ((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); }); cv.findViewById(R.id.content).setVisibility(View.GONE); // 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.aegiswallet.utils.BasicUtils.java
public static boolean isPasswordInDictionary(Context context, String password) { boolean resultBool = false; if (password == null) return false; try {//from w w w . j a v a 2 s . c o m AssetFileDescriptor descriptor = context.getAssets().openFd("commonpasswords.xmf"); FileReader reader = new FileReader(descriptor.getFileDescriptor()); // create a case sensitive word list and sort it ArrayWordList awl = WordLists.createFromReader(new FileReader[] { reader }, true, new ArraysSort()); WordListDictionary dict = new WordListDictionary(awl); DictionarySubstringRule dictRule = new DictionarySubstringRule(dict); dictRule.setWordLength(6); // size of words to check in the password dictRule.setMatchBackwards(true); // match dictionary words backwards List<Rule> ruleList = new ArrayList<Rule>(); ruleList.add(dictRule); PasswordValidator validator = new PasswordValidator(ruleList); PasswordData passwordData = new PasswordData(new Password(password.toLowerCase())); RuleResult result = validator.validate(passwordData); if (result.isValid()) { Log.d(TAG, "Valid password"); resultBool = true; } else { Log.d(TAG, "Invalid password"); } } catch (FileNotFoundException e) { Log.d(TAG, e.getMessage()); } catch (IOException e) { Log.d(TAG, e.getMessage()); } return resultBool; }
From source file:com.owncloud.android.lib.testclient.TestActivity.java
/** * Extracts file from AssetManager to cache folder. * //from w w w . java 2s. co m * @param fileName Name of the asset file to extract. * @param context Android context to access assets and file system. * @return File instance of the extracted file. */ public static File extractAsset(String fileName, Context context) throws IOException { File extractedFile = new File(context.getCacheDir() + File.separator + fileName); if (!extractedFile.exists()) { InputStream in = null; FileOutputStream out = null; in = context.getAssets().open(fileName); out = new FileOutputStream(extractedFile); byte[] buffer = new byte[BUFFER_SIZE]; int readCount; while ((readCount = in.read(buffer)) != -1) { out.write(buffer, 0, readCount); } out.flush(); out.close(); in.close(); } return extractedFile; }
From source file:com.brewcrewfoo.performance.util.Helpers.java
public static void get_assetsScript(String fn, Context c, String prefix, String postfix) { byte[] buffer; final AssetManager assetManager = c.getAssets(); try {//from w w w.j a v a 2 s .c o m InputStream f = assetManager.open(fn); buffer = new byte[f.available()]; f.read(buffer); f.close(); final String s = new String(buffer); final StringBuilder sb = new StringBuilder(s); if (!postfix.equals("")) { sb.append("\n\n").append(postfix); } if (!prefix.equals("")) { sb.insert(0, prefix + "\n"); } sb.insert(0, "#!" + Helpers.binExist("sh") + "\n\n"); try { FileOutputStream fos; fos = c.openFileOutput(fn, Context.MODE_PRIVATE); fos.write(sb.toString().getBytes()); 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:com.android.settings.util.Helpers2.java
public static void get_assetsBinary(String fn, Context c) { byte[] buffer; final AssetManager assetManager = c.getAssets(); try {//from w w w . java2s . c om 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:run.ace.Utils.java
public static Bitmap getBitmapAsset(android.content.Context context, String url) { InputStream inputStream = null; Bitmap b = null;// www. j av a 2 s . co m try { if (url.contains("{platform}")) { url = url.replace("{platform}", "android"); } AssetManager assetManager = context.getAssets(); inputStream = assetManager.open(url); } catch (IOException ex) { } if (inputStream != null) { b = BitmapFactory.decodeStream(inputStream); try { inputStream.close(); } catch (IOException ex) { } } return b; }
From source file:mx.klozz.xperience.tweaker.helpers.Helpers.java
public static void get_assetsScript(String fn, Context c, String prefix, String postfix) { byte[] buffer; final AssetManager assetManager = c.getAssets(); try {/*from ww w . j av a 2 s . com*/ InputStream f = assetManager.open(fn); buffer = new byte[f.available()]; f.read(buffer); f.close(); final String s = new String(buffer); final StringBuilder sb = new StringBuilder(s); if (!postfix.equals("")) { sb.append("\n\n").append(postfix); } if (!prefix.equals("")) { sb.insert(0, prefix + "\n"); } sb.insert(0, "#!" + Helpers.BinExist("sh") + "\n\n"); try { FileOutputStream fos; fos = c.openFileOutput(fn, Context.MODE_PRIVATE); fos.write(sb.toString().getBytes()); 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:com.android.settings.util.Helpers2.java
public static void get_assetsScript(String fn, Context c, String prefix, String postfix) { byte[] buffer; final AssetManager assetManager = c.getAssets(); try {/*from w w w.j av a 2 s . co m*/ InputStream f = assetManager.open(fn); buffer = new byte[f.available()]; f.read(buffer); f.close(); final String s = new String(buffer); final StringBuilder sb = new StringBuilder(s); if (!postfix.equals("")) { sb.append("\n\n").append(postfix); } if (!prefix.equals("")) { sb.insert(0, prefix + "\n"); } sb.insert(0, "#!" + Helpers2.binExist("sh") + "\n\n"); try { FileOutputStream fos; fos = c.openFileOutput(fn, Context.MODE_PRIVATE); fos.write(sb.toString().getBytes()); 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:com.entertailion.android.slideshow.utils.Utils.java
public static final String readAssetFile(Context context, String filename) { StringBuffer buffer = new StringBuffer(); try {//from w w w. j a v a 2s . co m InputStream is = context.getAssets().open(filename); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = null; while ((line = reader.readLine()) != null) { buffer.append(line).append('\n'); } is.close(); } catch (Throwable x) { } return buffer.toString(); }