List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:com.netpace.expressit.android.ui.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. ja 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_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:com.mjaworski.myQuotes.Utils.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 {/*ww w .j ava2s .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", typefaceName)); // Cache the Typeface object sTypefaceCache.put(typefaceName, typeface); } setTypeface(typeface); } } finally { a.recycle(); } }
From source file:interactivespaces.controller.android.InteractiveSpacesFrameworkAndroidBootstrap.java
/** * Start the framework up.//from w w w . jav a 2s . co m * * @param context * the Android context to start the framework up in. */ public void startup(Map<String, String> config, Context context) { AssetManager assetManager = context.getAssets(); try { createCoreServices(context); copyInitialBootstrapAssets(assetManager, context.getFilesDir()); getBootstrapBundleJars(assetManager, BUNDLE_DIRECTORY_BOOTSTRAP); // If no bundle JAR files are in the directory, then exit. if (initialBundles.isEmpty() && finalBundles.isEmpty()) { System.out.println("No bundles to install."); } createAndStartFramework(config, context); registerCoreServices(); List<Bundle> bundleList = new ArrayList<Bundle>(); // Install bundle JAR files and remember the bundle objects. BundleContext ctxt = framework.getBundleContext(); ctxt.addBundleListener(new BundleListener() { @Override public void bundleChanged(BundleEvent event) { bundleChangeEvent(event); } }); isSystemActivator = new GeneralInteractiveSpacesSupportActivator(); isSystemActivator.start(framework.getBundleContext()); OsgiControllerActivator isControllerActivator = new OsgiControllerActivator(); isControllerActivator.start(framework.getBundleContext()); startBundles(assetManager, ctxt, bundleList, initialBundles, false); startBundles(assetManager, ctxt, bundleList, finalBundles, true); } catch (Exception ex) { System.err.println("Error starting framework: " + ex); ex.printStackTrace(); System.exit(0); } }
From source file:de.schildbach.wallet.data.DynamicFeeLoader.java
public DynamicFeeLoader(final Context context) { super(context); final PackageInfo packageInfo = WalletApplication.packageInfoFromContext(context); final int versionNameSplit = packageInfo.versionName.indexOf('-'); this.dynamicFeesUrl = HttpUrl.parse(Constants.DYNAMIC_FEES_URL + (versionNameSplit >= 0 ? packageInfo.versionName.substring(versionNameSplit) : "")); this.userAgent = WalletApplication.httpUserAgent(packageInfo.versionName); this.assets = context.getAssets(); }
From source file:com.google.android.apps.santatracker.map.cardstream.CardAdapter.java
public CardAdapter(Context context, CardAdapterListener listener, DestinationCardKeyListener destCardListener, boolean isTv) { mContext = context;//from w w w . jav a 2s . c om mTypefaceLabel = Typeface.createFromAsset(context.getAssets(), context.getResources().getString(R.string.typeface_roboto_black)); mTypefaceBody = Typeface.createFromAsset(context.getAssets(), context.getResources().getString(R.string.typeface_roboto_light)); mListener = listener; mDestinationCardListener = destCardListener; TrackerCard.Dashboard dashboard = TrackerCard.Dashboard.getInstance(); mDashboardId = dashboard.id; mCards.add(DASHBOARD_POSITION, dashboard); mThumbnailListener = new ThumbnailListener(); mYouTubeApiDeveloperKey = context.getString(R.string.config_maps_api_key); mIsTv = isTv; setHasStableIds(true); }
From source file:com.zivacare.android.sdk.ZivaCareConfig.java
private void readConfig(Context context) { try {/*from w ww . j a va2s. c o m*/ final Properties prop = new Properties(); prop.load(context.getAssets().open(CONFIG_FILE)); mDevUrl = prop.getProperty("ZIVA-DEV-URL"); mApiUrl = prop.getProperty("ZIVA-API-URL"); } catch (IOException e) { Log.e(getClass().getSimpleName(), e.toString()); } }
From source file:com.ichi2.libanki.Utils.java
/** Returns a list of files for the installed custom fonts. */ public static List<AnkiFont> getCustomFonts(Context context) { String deckPath = CollectionHelper.getCurrentAnkiDroidDirectory(context); String fontsPath = deckPath + "/fonts/"; File fontsDir = new File(fontsPath); int fontsCount = 0; File[] fontsList = null;/*from w w w.j av a2 s. c om*/ if (fontsDir.exists() && fontsDir.isDirectory()) { fontsCount = fontsDir.listFiles().length; fontsList = fontsDir.listFiles(); } String[] ankiDroidFonts = null; try { ankiDroidFonts = context.getAssets().list("fonts"); } catch (IOException e) { Timber.e(e, "Error on retrieving ankidroid fonts"); } List<AnkiFont> fonts = new ArrayList<AnkiFont>(); for (int i = 0; i < fontsCount; i++) { String filePath = fontsList[i].getAbsolutePath(); String filePathExtension = getFileExtension(filePath); for (String fontExtension : FONT_FILE_EXTENSIONS) { // Go through the list of allowed extensios. if (filePathExtension.equalsIgnoreCase(fontExtension)) { // This looks like a font file. AnkiFont font = AnkiFont.createAnkiFont(context, filePath, false); if (font != null) { fonts.add(font); } break; // No need to look for other file extensions. } } } if (ankiDroidFonts != null) { for (int i = 0; i < ankiDroidFonts.length; i++) { // Assume all files in the assets directory are actually fonts. AnkiFont font = AnkiFont.createAnkiFont(context, ankiDroidFonts[i], true); if (font != null) { fonts.add(font); } } } return fonts; }
From source file:com.creativeongreen.imageeffects.MainActivity.java
private static Bitmap getBitmapFromAsset(Context context, String file) { InputStream is = null;/* www.j a va2 s .c o m*/ Bitmap bitmap = null; try { is = context.getAssets().open(file); bitmap = BitmapFactory.decodeStream(is); } catch (final IOException e) { bitmap = null; } finally { if (is != null) { try { is.close(); } catch (IOException ignored) { } } } return bitmap; }
From source file:cl.smartcities.isci.transportinspector.adapters.dialogAdapters.IncomingBusesAdapter.java
public IncomingBusesAdapter(Context pContext, ArrayList<Service> pServices, String busStop) { super(pContext, R.layout.bus_list_row); this.busStop = busStop; originalServices = pServices;//www . ja va 2s . com loadViewState(); this.typeface = Typeface.createFromAsset(pContext.getAssets(), pContext.getString(R.string.icon_font)); this.mInflater = (LayoutInflater) pContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.context = pContext; this.next = ContextCompat.getDrawable(this.context, R.drawable.ic_navigate_next_black_36dp); this.prev = ContextCompat.getDrawable(this.context, R.drawable.ic_navigate_before_black_36dp); this.scale = getContext().getResources().getDisplayMetrics().density; this.onIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_location_on_28dp); this.onOffIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_location_on_28dp); this.offIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_location_off_28dp); this.onIconColor = ContextCompat.getColor(getContext(), R.color.green_button); this.offIconColor = ContextCompat.getColor(getContext(), R.color.color_grey_off); this.onOffIconColor = ContextCompat.getColor(getContext(), R.color.background_white); }
From source file:com.golfmarin.golf.JsonParser.java
public JSONArray getJSONFromFile(Context ctx, String filename, String objects, String object) { // This could be a general parser that expects a file containing an objects/object hierarchy // This code uses names specific to golfcourses InputStream input;// w ww . jav a2s . c o m String jsonString = null; JSONObject golfcoursesJson = null; JSONObject golfcourseJson = null; JSONArray golfcourseJsonArray = null; Log.v("mytag", "Started getJSONFromFile:" + filename); // Read the file to a string try { input = ctx.getAssets().open(filename); int size = input.available(); byte[] buffer = new byte[size]; input.read(buffer); input.close(); jsonString = new String(buffer); } catch (Exception e) { Log.i("mytag", "Couldn't read json file " + e.toString()); } // Extract JSONArray from string try { golfcoursesJson = new JSONObject(jsonString); golfcourseJson = golfcoursesJson.getJSONObject(objects); golfcourseJsonArray = golfcourseJson.getJSONArray(object); } catch (JSONException e) { Log.i("mytag", "Couldn't parse JSON string." + e); } return golfcourseJsonArray; }