List of usage examples for android.app Activity openFileOutput
@Override public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException
From source file:jahirfiquitiva.iconshowcase.fragments.WallpapersFragment.java
private static void setupLayout(final boolean fromTask, final Activity context, final ImageView noConnection) { if (WallpapersList.getWallpapersList() != null && WallpapersList.getWallpapersList().size() > 0) { context.runOnUiThread(new Runnable() { @Override/*from w w w .ja va 2 s.c om*/ public void run() { mAdapter = new WallpapersAdapter(context, new WallpapersAdapter.ClickListener() { @Override public void onClick(WallpapersAdapter.WallsHolder view, int position, boolean longClick) { if ((longClick && !ShowcaseActivity.wallsPicker) || ShowcaseActivity.wallsPicker) { final MaterialDialog dialog = new MaterialDialog.Builder(context) .content(R.string.downloading_wallpaper).progress(true, 0).cancelable(false) .show(); WallpaperItem wallItem = WallpapersList.getWallpapersList().get(position); Glide.with(context).load(wallItem.getWallURL()).asBitmap() .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { if (resource != null) { new ApplyWallpaper(context, dialog, resource, ShowcaseActivity.wallsPicker, layout).execute(); } } }); } else { final Intent intent = new Intent(context, ViewerActivity.class); intent.putExtra("item", WallpapersList.getWallpapersList().get(position)); intent.putExtra("transitionName", ViewCompat.getTransitionName(view.wall)); Bitmap bitmap; if (view.wall.getDrawable() != null) { bitmap = Utils.drawableToBitmap(view.wall.getDrawable()); try { String filename = "temp.png"; FileOutputStream stream = context.openFileOutput(filename, Context.MODE_PRIVATE); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); stream.close(); intent.putExtra("image", filename); } catch (Exception e) { Utils.showLog(context, "Error getting drawable " + e.getLocalizedMessage()); } ActivityOptionsCompat options = ActivityOptionsCompat .makeSceneTransitionAnimation(context, view.wall, ViewCompat.getTransitionName(view.wall)); context.startActivity(intent, options.toBundle()); } else { context.startActivity(intent); } } } }); mAdapter.setData(WallpapersList.getWallpapersList()); mRecyclerView.setAdapter(mAdapter); fastScroller = (RecyclerFastScroller) layout.findViewById(R.id.rvFastScroller); fastScroller.attachRecyclerView(mRecyclerView); if (fastScroller.getVisibility() != View.VISIBLE) { fastScroller.setVisibility(View.VISIBLE); } if (Utils.hasNetwork(context)) { hideProgressBar(); noConnection.setVisibility(View.GONE); mRecyclerView.setVisibility(View.VISIBLE); fastScroller.setVisibility(View.VISIBLE); mSwipeRefreshLayout.setEnabled(false); mSwipeRefreshLayout.setRefreshing(false); } else { hideStuff(noConnection); } } }); } else { context.runOnUiThread(new Runnable() { @Override public void run() { if (layout != null) { noConnection.setVisibility(View.GONE); showProgressBar(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { context.runOnUiThread(new Runnable() { @Override public void run() { hideStuff(noConnection); } }); } }, 7500); } } }); } }