List of usage examples for android.app Activity getAssets
@Override
public AssetManager getAssets()
From source file:typical_if.android.fragment.LicenseFragment.java
private String getStringFromAssetFile(Activity activity) { String text = "licenses.xml"; byte[] buffer = null; InputStream is;//from w ww . j a v a 2 s . c o m try { is = activity.getAssets().open(text); int size = is.available(); buffer = new byte[size]; is.read(buffer); is.close(); } catch (IOException e) { e.printStackTrace(); } String str_data = new String(buffer); return Html.fromHtml(str_data).toString(); }
From source file:com.docd.purefm.adapters.BrowserListAdapter.java
public BrowserListAdapter(@NonNull final Activity context) { super(context); mTypefaceMonospace = Typeface.createFromAsset(context.getAssets(), "DroidSansMono.ttf"); }
From source file:com.mousebird.maply.MaplyStarModel.java
public MaplyStarModel(String fileName, String imageName, Activity activity) throws IOException { AssetManager assetMgr = activity.getAssets(); InputStream inputStream = null; String[] paths = assetMgr.list("maplystarmodel"); for (String path : paths) { if (path.equals(imageName)) { //image BufferedInputStream bufferedInputStream = null; try { inputStream = assetMgr.open("maplystarmodel/" + path); bufferedInputStream = new BufferedInputStream(inputStream); image = BitmapFactory.decodeStream(bufferedInputStream); } finally { if (bufferedInputStream != null) { try { bufferedInputStream.close(); } catch (IOException e) { }/*from ww w .j a va2 s. c o m*/ } } } if (path.equals(fileName)) { //data Matcher m; try { inputStream = assetMgr.open("maplystarmodel/" + path); String stars = IOUtils.toString(inputStream, Charset.defaultCharset()); Pattern p = Pattern.compile("[-]?[0-9]*\\.?[0-9]+"); m = p.matcher(stars); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } } this.stars = new ArrayList<SingleStar>(); if (m.groupCount() % 3 == 0) { int i = 0; SingleStar s = null; while (m.find()) { switch (i) { case 0: s = new SingleStar(); s.ra = Float.valueOf(m.group()); i++; break; case 1: s.dec = Float.valueOf(m.group()); i++; break; case 2: s.mag = Float.valueOf(m.group()); this.stars.add(s); i = 0; break; default: break; } } } } } }
From source file:org.thbz.hanguldrill.HelpDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Activity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); // Initialiser le texte de l'aide partir d'un fichier inclu dans l'APK StringBuilder htmlHelpText = new StringBuilder(); try {// w w w. j a v a2s . c o m BufferedReader in = new BufferedReader( new InputStreamReader(activity.getAssets().open("help_contents.html"))); String line; int state = 0; while ((line = in.readLine()) != null) { if (line.contains("<!-- START APP CONTENTS -->")) state = 1; else if (state == 1) { if (line.contains("<!-- END APP CONTENTS -->")) state = 2; else htmlHelpText.append(line); } } } catch (IOException exc) { htmlHelpText.setLength(0); htmlHelpText.append("Help is not available (").append(exc.getMessage()).append(")"); } LayoutInflater inflater = activity.getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialog_help, null); TextView helpTextView = (TextView) dialogView.findViewById(R.id.dialog_help_text); helpTextView.setText(Html.fromHtml(htmlHelpText.toString())); // Allow for external hyperlinks in the HTML text helpTextView.setMovementMethod(LinkMovementMethod.getInstance()); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(dialogView) // Add action buttons .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); return builder.create(); }
From source file:org.gluu.super_gluu.app.fragments.SettingsFragment.SettingsList.SettingsListFragmentAdapter.java
public SettingsListFragmentAdapter(Activity activity, List<Map<String, Integer>> listContact, SettingsListFragment.SettingsListListener settingsListListener) { list = listContact;//ww w . j a v a 2s . co m this.activity = activity; this.context = activity.getApplicationContext(); mInflater = LayoutInflater.from(activity); mListener = settingsListListener; face = Typeface.createFromAsset(activity.getAssets(), "ProximaNova-Regular.otf"); initIAPurchaseService(); }
From source file:usbong.android.utils.UsbongUtils.java
public static String readTextFileInAssetsFolder(Activity a, String filename) { //READ A FILE //Reference: Jeffrey Jongko, Aug. 31, 2010 try {// w ww. j a va2s. co m // byte[] b = new byte[100]; AssetManager myAssetManager = a.getAssets(); InputStream is = myAssetManager.open(filename); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String currLineString = ""; String finalString = ""; while ((currLineString = br.readLine()) != null) { finalString = finalString + currLineString + "\n"; } is.close(); return finalString; } catch (Exception e) { System.out.println("ERROR in reading FILE in readTextFileInAssetsFolder(...)."); e.printStackTrace(); } return null; }
From source file:com.adobe.plugins.FastCanvasRenderer.java
private void flushQueue() { synchronized (this) { if (!FastCanvas.copyMessageQueue(mLocalQueue)) { // Tear down. if any to be done. return; }//from w ww. j a v a 2 s. c om } mRenderCommands = ""; FastCanvasMessage m; while (mLocalQueue.size() > 0) { m = mLocalQueue.remove(); if (m.type == FastCanvasMessage.Type.LOAD) { Activity theActivity = FastCanvas.getActivity(); if (theActivity != null) { // If we are re-using a texture ID, unload the old texture for (int i = 0; i < mTextures.size(); i++) { if (mTextures.get(i).id == m.textureID) { unloadTexture(m.textureID); break; } } // Load and track the texture String path = "www/" + m.url; boolean success = false; FastCanvasTextureDimension dim = new FastCanvasTextureDimension(); // See the following for why PNG files with premultiplied alpha and GLUtils don't get along // http://stackoverflow.com/questions/3921685/issues-with-glutils-teximage2d-and-alpha-in-textures if (path.toLowerCase(Locale.US).endsWith(".png")) { success = FastCanvasJNI.addPngTexture(theActivity.getAssets(), path, m.textureID, dim); if (success == false) { Log.i("CANVAS", "CanvasRenderer loadTexture failed to load PNG in native code, falling back to GLUtils."); } } if (success == false) { try { InputStream instream = theActivity.getAssets().open(path); final Bitmap bmp = BitmapFactory.decodeStream(instream); loadTexture(bmp, m.textureID); dim.width = bmp.getWidth(); dim.height = bmp.getHeight(); success = true; } catch (IOException e) { Log.i("CANVAS", "CanvasRenderer loadTexture error=", e); m.callbackContext.error(e.getMessage()); } } if (success == true) { FastCanvasTexture t = new FastCanvasTexture(m.url, m.textureID); mTextures.add(t); JSONArray args = new JSONArray(); args.put(dim.width); args.put(dim.height); m.callbackContext.success(args); } } } else if (m.type == FastCanvasMessage.Type.UNLOAD) { // Stop tracking the texture for (int i = 0; i < mTextures.size(); i++) { if (mTextures.get(i).id == m.textureID) { mTextures.remove(i); break; } } unloadTexture(m.textureID); } else if (m.type == FastCanvasMessage.Type.RELOAD) { Activity theActivity = FastCanvas.getActivity(); if (theActivity != null) { // Reload the texture String path = "www/" + m.url; boolean success = false; if (path.toLowerCase(Locale.US).endsWith(".png")) { success = FastCanvasJNI.addPngTexture(theActivity.getAssets(), path, m.textureID, null); } if (success == false) { try { InputStream instream = theActivity.getAssets().open(path); final Bitmap bmp = BitmapFactory.decodeStream(instream); loadTexture(bmp, m.textureID); } catch (IOException e) { Log.i("CANVAS", "CanvasRenderer reloadTexture error=", e); } } } } else if (m.type == FastCanvasMessage.Type.RENDER) { mRenderCommands = m.drawCommands; while (!mCaptureQueue.isEmpty()) { FastCanvasMessage captureMessage = mCaptureQueue.get(0); FastCanvasJNI.captureGLLayer(captureMessage.callbackContext.getCallbackId(), captureMessage.x, captureMessage.y, captureMessage.width, captureMessage.height, captureMessage.url); mCaptureQueue.remove(0); } } else if (m.type == FastCanvasMessage.Type.SET_ORTHO) { Log.i("CANVAS", "CanvasRenderer setOrtho width=" + m.width + ", height=" + m.height); FastCanvasJNI.setOrtho(m.width, m.height); } else if (m.type == FastCanvasMessage.Type.CAPTURE) { Log.i("CANVAS", "CanvasRenderer capture"); mCaptureQueue.add(m); } else if (m.type == FastCanvasMessage.Type.SET_BACKGROUND) { Log.i("CANVAS", "CanvasRenderer setBackground color=" + m.drawCommands); // Some validation of the background color string is // done in JS, but the format of m.drawCommands cannot // be fully validated so we're going to give this a shot // and simply fail silently if an error occurs in parsing try { int red = Integer.valueOf(m.drawCommands.substring(0, 2), 16); int green = Integer.valueOf(m.drawCommands.substring(2, 4), 16); int blue = Integer.valueOf(m.drawCommands.substring(4, 6), 16); FastCanvasJNI.setBackgroundColor(red, green, blue); } catch (Exception e) { Log.e("CANVAS", "Parsing background color: \"" + m.drawCommands + "\"", e); } } } }
From source file:com.native5.plugins.ActionBarPlugin.java
private Drawable getDrawableForURI(String uri_string) { Uri uri = Uri.parse(uri_string);//from w ww .j ava 2s .c o m Activity ctx = (Activity) cordova; // Special case - TrueType fonts if (uri_string.endsWith(".ttf")) { /*for(String base: bases) { String path = base + uri; // TODO: Font load / glyph rendering ("/blah/fontawesome.ttf:\f1234") }*/ } // General bitmap else { if (uri.isAbsolute()) { if (uri.getScheme().startsWith("http")) { try { URL url = new URL(uri_string); InputStream stream = url.openConnection().getInputStream(); return new BitmapDrawable(ctx.getResources(), stream); } catch (MalformedURLException e) { return null; } catch (IOException e) { return null; } catch (Exception e) { return null; } } else { try { InputStream stream = ctx.getContentResolver().openInputStream(uri); return new BitmapDrawable(ctx.getResources(), stream); } catch (FileNotFoundException e) { return null; } } } else { for (String base : bases) { String path = base + uri; // Asset if (base.startsWith("file:///android_asset/")) { path = path.substring(22); try { InputStream stream = ctx.getAssets().open(path); return new BitmapDrawable(ctx.getResources(), stream); } catch (IOException e) { continue; } } // General URI else { try { InputStream stream = ctx.getContentResolver().openInputStream(Uri.parse(path)); return new BitmapDrawable(ctx.getResources(), stream); } catch (FileNotFoundException e) { continue; } } } } } return null; }