List of usage examples for android.content ContextWrapper ContextWrapper
public ContextWrapper(Context base)
From source file:Main.java
/** * Copy IP channel list/* ww w. ja va2 s . co m*/ * * @param filename File name of IP channel list in assets directory */ private static void copyFile(String filename) { ContextWrapper contextWrapper = new ContextWrapper(mContext); String file = contextWrapper.getFilesDir().getPath() + "/" + filename; File fl = new File(file); if (!fl.exists()) copyAssetToData(fl); }
From source file:Main.java
/** * Method to save save user image in internal storage for the device * * @param bitmapImage the downloaded bitmap * @param context//from w ww .ja v a 2 s . c o m * @param name the image name (the last segment) * @return the saved path for th image */ public static String saveImageIntoInternalStorage(Bitmap bitmapImage, Context context, String name) { // path to /data/data/adas/app_data/imageDir ContextWrapper contextWrapper = new ContextWrapper(context); //Folder name in device android/data/ String folderName = "UserImages"; File directory = contextWrapper.getDir(folderName, Context.MODE_PRIVATE); //Create imageDir File imagePath = new File(directory, name); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(imagePath); // Use the compress method on the BitMap object to write image to the OutputStream bitmapImage.compress(Bitmap.CompressFormat.JPEG, 50, fileOutputStream); fileOutputStream.close(); } catch (Exception e) { } return directory.getAbsolutePath(); }
From source file:Main.java
public static SharedPreferences getPreferences(Context context) { return new ContextWrapper(context).getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); }
From source file:com.example.mediastock.util.Utilities.java
/** * It saves the image into the internal storage of the app. * * @param context the context// w ww . j av a 2 s.c o m * @param type the directory type: video or image * @param bitmap the image * @param id the id of the image * @return the path of the image */ public static String saveImageToInternalStorage(Context context, String type, Bitmap bitmap, int id) { ContextWrapper cw = new ContextWrapper(context.getApplicationContext()); File imageDir = cw.getDir("imageDir", Context.MODE_PRIVATE); // Create file image File file = new File(imageDir, type + id); FileOutputStream fos; try { fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (Exception e) { e.printStackTrace(); } return file.getName(); }
From source file:bolts.AppLinkTest.java
@Override protected void setUp() throws Exception { super.setUp(); openedIntents = new ArrayList<>(); activityInterceptor = new ContextWrapper(getInstrumentation().getTargetContext()) { @Override/*from w ww. jav a 2s . c o m*/ public void startActivity(Intent intent) { openedIntents.add(intent); } }; }
From source file:com.sareen.squarelabs.techrumors.HTMLParser.HtmlLocalImageGetter.java
public Drawable getDrawable(String source) { Context context = container.getContext(); Drawable d;// w ww . ja v a 2s .co m if ((imagePathList != null) && (count < imagePathList.size())) { ContextWrapper cw = new ContextWrapper(context.getApplicationContext()); File imageDir = cw.getDir("imageDir", Context.MODE_PRIVATE); String fileName = imagePathList.get(count); File imagePath = new File(imageDir, fileName + ".jpg"); Bitmap bitmap = BitmapFactory.decodeFile(imagePath.toString()); d = new BitmapDrawable(context.getResources(), bitmap); float scale = getScale(d); d.setBounds(0, 0, (int) (d.getIntrinsicWidth() * scale), (int) (d.getIntrinsicHeight() * scale)); } else { d = ContextCompat.getDrawable(context, R.mipmap.ic_launcher); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } count++; return d; /*Context context = container.getContext(); int id = context.getResources().getIdentifier(source, "drawable", context.getPackageName()); if (id == 0) { // the drawable resource wasn't found in our package, maybe it is a stock android drawable? id = context.getResources().getIdentifier(source, "drawable", "android"); } if (id == 0) { // prevent a crash if the resource still can't be found Log.e(HtmlTextView.TAG, "source could not be found: " + source); return null; } else { Drawable d = context.getResources().getDrawable(id); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); return d; }*/ }
From source file:com.example.mediastock.util.Utilities.java
/** * Method to save a media file inside the directory typeDir. It writes the bytes of the stream into the file * @param type the directory type: music, video or image * @param context the context//w ww . j a va 2s . com * @param inputStream the stream * @param id the id of the media file * @return the path of the media file */ public static String saveMediaToInternalStorage(String type, Context context, InputStream inputStream, int id) { ContextWrapper cw = new ContextWrapper(context.getApplicationContext()); File dir = cw.getDir(type + "Dir", Context.MODE_PRIVATE); // Create media file File file; if (type.equals(Utilities.MUSIC_DIR)) file = new File(dir, type + id + ".mp3"); else file = new File(dir, type + id); FileOutputStream fos; try { fos = new FileOutputStream(file); fos.write(Utilities.covertStreamToByte(inputStream)); fos.flush(); fos.close(); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return file.getName(); }
From source file:com.oasisfeng.nevo.decorators.media.MediaPlayerDecorator.java
@Override protected void apply(final StatusBarNotificationEvo evolving) throws Exception { if (evolving.isClearable()) return; // Just sticky notification, to reduce the overhead. final INotification n = evolving.notification(); RemoteViews content_view = n.getBigContentView(); // Prefer big content view since it usually contains more actions if (content_view == null) content_view = n.getContentView(); if (content_view == null) return;/*from ww w. ja v a 2 s . co m*/ final AtomicReference<IntentSender> sender_holder = new AtomicReference<>(); final View views = content_view.apply(new ContextWrapper(this) { @Override public void startIntentSender(final IntentSender intent, final Intent fillInIntent, final int flagsMask, final int flagsValues, final int extraFlags) throws IntentSender.SendIntentException { startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, null); } @Override public void startIntentSender(final IntentSender intent, final Intent fillInIntent, final int flagsMask, final int flagsValues, final int extraFlags, final Bundle options) throws IntentSender.SendIntentException { sender_holder.set(intent); } }, null); if (!(views instanceof ViewGroup)) return; final List<NotificationCompat.Action> actions = new ArrayList<>(8); findClickable((ViewGroup) views, new Predicate<View>() { @Override public boolean apply(final View v) { sender_holder.set(null); v.performClick(); // trigger startIntentSender() above final IntentSender sender = sender_holder.get(); if (sender == null) { Log.w(TAG, v + " has OnClickListener but no PendingIntent in it."); return true; } final PendingIntent pending_intent = getPendingIntent(sender); if (v instanceof TextView) { final CharSequence text = ((TextView) v).getText(); actions.add(new NotificationCompat.Action(0, text, pending_intent)); } else if (v instanceof ImageView) { final int res = getImageViewResource((ImageView) v); CharSequence title = v.getContentDescription(); if (title == null) title = "<" + System.identityHashCode(v); actions.add(new NotificationCompat.Action(res, title, pending_intent)); } else { CharSequence title = v.getContentDescription(); if (title == null) title = "<" + System.identityHashCode(v); actions.add(new NotificationCompat.Action(0, title, pending_intent)); } return true; } }); final Notification mirror; final String pkg = evolving.getPackageName(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { final Notification.Builder b = new Notification.Builder(createPackageContext(pkg, 0)) .setContentTitle(n.extras().getCharSequence(NotificationCompat.EXTRA_TITLE)) .setLargeIcon(n.getLargeIcon()).setSmallIcon(fixIconPkg(n.getSmallIcon(), pkg)); for (final NotificationCompat.Action action : actions) b.addAction(new Action.Builder(Icon.createWithResource(pkg, action.getIcon()), action.getTitle(), action.getActionIntent()).build()); mirror = b.build(); } else { final NotificationCompat.Builder b = new NotificationCompat.Builder(createPackageContext(pkg, 0)) .setContentTitle(n.extras().getCharSequence(NotificationCompat.EXTRA_TITLE)) .setLargeIcon(n.extras().getParcelable(NotificationCompat.EXTRA_LARGE_ICON).<Bitmap>get()) .setSmallIcon(android.R.drawable.ic_media_play); for (final NotificationCompat.Action action : actions) b.addAction(action); mirror = b.build(); } final NotificationManagerCompat nm = NotificationManagerCompat.from(this); nm.notify("M<" + evolving.getPackageName() + (evolving.getTag() != null ? ">" + evolving.getTag() : ">"), evolving.getId(), mirror); }
From source file:org.opensilk.music.playback.control.PlaybackController.java
@Inject public PlaybackController(@ForApplication Context mAppContext) { this.mAppContext = new ContextWrapper(mAppContext); }
From source file:com.iwedia.activities.DTVActivity.java
/** * Copy configuration file.//from w w w . j a v a 2 s.c om */ private void copyFile(String filename) { ContextWrapper contextWrapper = new ContextWrapper(this); String file = contextWrapper.getFilesDir().getPath() + "/" + filename; File fl = new File(file); if (!fl.exists()) copyAssetToData(fl); }