List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:run.ace.NativeHost.java
byte[] readXbf(String uri) throws IOException { Context context = _activity.getApplicationContext(); AssetManager am = context.getAssets(); InputStream is = am.open(uri); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int numRead;/* w ww. jav a 2s. c o m*/ byte[] data = new byte[16384]; while ((numRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, numRead); } buffer.flush(); return buffer.toByteArray(); }
From source file:ca.bitwit.postcard.PostcardAdaptor.java
public String loadJSONFile(String file) { try {/*w ww. jav a 2 s . c o m*/ String jsonString; Context context = this.activity.getApplicationContext(); InputStream is = context.getAssets().open(file); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); jsonString = new String(buffer, "UTF-8"); return jsonString; } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:com.alexdisler.inapppurchases.InAppBillingV3.java
private JSONObject getManifestContents() { if (manifestObject != null) return manifestObject; Context context = this.cordova.getActivity(); InputStream is;// w w w . j a v a 2 s . co m try { is = context.getAssets().open("www/manifest.json"); Scanner s = new Scanner(is).useDelimiter("\\A"); String manifestString = s.hasNext() ? s.next() : ""; Log.d(TAG, "manifest:" + manifestString); 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; }
From source file:com.tr4android.support.extension.typeface.TypefaceCompat.java
/** * Creates a typeface object that best matches the specified typeface and the specified style. * Use this call if you want to pick a new style from the same family of an typeface object. * If family is null, this selects from the default font's family. * * @param ctx A context.//from w w w . j a va2 s . c o m * @param familyName May be null. The name of the font family. * @param style The style (normal, bold, italic) of the typeface, e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC. * @return The best matching typeface. * @since 0.1.1 * @deprecated */ @Deprecated public static Typeface create(Context ctx, String familyName, int style) { if (!mInitialized) initialize(); if (isSupported(familyName) || familyName == null) { boolean styleAfterwards = false; String fileName = FONT_FAMILY_FILE_PREFIX.get(familyName == null ? "sans-serif" : familyName); if (fileName.endsWith("-")) { // All styles are supported. fileName += STYLE_SUFFIX[style]; } else { switch (style) { case Typeface.NORMAL: break; case Typeface.BOLD: case Typeface.BOLD_ITALIC: // These styles are not supported by default. Therefore force style after retrieving normal font. styleAfterwards = true; break; case Typeface.ITALIC: fileName += STYLE_SUFFIX[style]; break; } } fileName += TTF_SUFFIX; // Retrieve Typeface from cache. Typeface tf = TYPEFACE_CACHE.get(fileName); if (tf == null) { // Create Typeface and cache it for later. String fontPath = "fonts/" + fileName; tf = Typeface.createFromAsset(ctx.getAssets(), fontPath); if (tf != null) { TYPEFACE_CACHE.put(fileName, tf); } } if (tf != null) { return styleAfterwards ? Typeface.create(tf, style) : tf; } } // Let the default implementation of Typeface try. return Typeface.create(familyName, style); }
From source file:com.dictionary.codebhak.LangTextView.java
/** * Sets the typeface to the value selected in the preference. * @param context the {@link Context} to use *///from w ww . j a v a 2 s. c o m private void setTypeface(Context context) { if (robotoTypefacePreferenceSet(context)) { setTypeface(Typeface.DEFAULT); } else if (!isInEditMode() && !TextUtils.isEmpty(NOTO_SERIF)) { Typeface typeface = sTypefaceCache.get(NOTO_SERIF); if (typeface == null) { typeface = Typeface.createFromAsset(context.getAssets(), "fonts/" + NOTO_SERIF); // Cache the Typeface object sTypefaceCache.put(NOTO_SERIF, typeface); } setTypeface(typeface); // Note: This flag is required for proper typeface rendering setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); } }
From source file:com.mindprotectionkit.freephone.signaling.SignalingSocket.java
private Socket constructSSLSocket(Context context, String host, int port) throws SignalingException { try {// w ww . j a v a 2 s.com AssetManager assetManager = context.getAssets(); InputStream keyStoreInputStream = assetManager.open("whisper.store"); KeyStore trustStore = KeyStore.getInstance("BKS"); trustStore.load(keyStoreInputStream, "whisper".toCharArray()); SSLSocketFactory sslSocketFactory = new SSLSocketFactory(trustStore); if (Release.SSL) { sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); } else { Log.w("SignalingSocket", "Disabling hostname verification..."); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } return timeoutHackConnect(sslSocketFactory, host, port); } catch (IOException ioe) { throw new SignalingException(ioe); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } catch (KeyStoreException e) { throw new IllegalArgumentException(e); } catch (CertificateException e) { throw new IllegalArgumentException(e); } catch (KeyManagementException e) { throw new IllegalArgumentException(e); } catch (UnrecoverableKeyException e) { throw new IllegalArgumentException(e); } }
From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java
public static View inflateName(Context context, String name, ViewGroup parent) { if (name.startsWith("<")) { // Assume it's XML return DynamicLayoutInflator.inflate(context, name, parent); } else {// w ww . jav a2s. co m File savedFile = context.getFileStreamPath(name + ".xml"); try { InputStream fileStream = new FileInputStream(savedFile); return DynamicLayoutInflator.inflate(context, fileStream, parent); } catch (FileNotFoundException e) { } try { InputStream assetStream = context.getAssets().open(name + ".xml"); return DynamicLayoutInflator.inflate(context, assetStream, parent); } catch (IOException e) { } int id = context.getResources().getIdentifier(name, "layout", context.getPackageName()); if (id > 0) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); return inflater.inflate(id, parent, false); } } return null; }
From source file:com.traderacademy.supprot.view.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 w w . j av 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 typeFace = Typeface.createFromAsset(context.getAssets(), "fonts/NORMAL_GBK.TTF"); textView.setTypeface(typeFace); 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:org.lol.reddit.views.PostListingHeader.java
public PostListingHeader(final Context context, final String titleText, final String subtitleText) { 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.setText(StringUtils.abbreviate(titleText, 33)); title.setTextSize(22.0f);/* w w w. j av a 2 s.com*/ title.setTypeface(tf); title.setTextColor(Color.WHITE); addView(title); final TextView subtitle = new TextView(context); subtitle.setTextSize(14.0f); subtitle.setText(StringUtils.abbreviate(subtitleText, 50)); subtitle.setTextColor(Color.rgb(200, 200, 200)); addView(subtitle); setBackgroundColor(Color.rgb(50, 50, 50)); // TODO theme color }