List of usage examples for android.os Environment DIRECTORY_PICTURES
String DIRECTORY_PICTURES
To view the source code for android.os Environment DIRECTORY_PICTURES.
Click Source Link
From source file:com.example.carsharing.LongWayActivity.java
@Override public void onResume() { super.onResume(); // Always call the superclass method first // Get the Camera instance as the activity achieves full user focus Context phonenumber = LongWayActivity.this; SharedPreferences filename = phonenumber.getSharedPreferences(getString(R.string.PreferenceDefaultName), Context.MODE_PRIVATE); UserPhoneNumber = filename.getString("refreshfilename", "0"); drawernum.setText(UserPhoneNumber);/*from www . ja v a2 s. com*/ Context context = LongWayActivity.this; SharedPreferences sharedPref = context.getSharedPreferences(UserPhoneNumber, Context.MODE_PRIVATE); String fullname = sharedPref.getString("refreshname", ""); drawername.setText(fullname); File photoFile = new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), UserPhoneNumber); if (photoFile.exists()) { photouri = Uri.fromFile(photoFile); drawericon.setImageURI(photouri); } else { drawericon.setImageResource(R.drawable.ic_launcher); } }
From source file:es.upv.riromu.arbre.main.MainActivity.java
/** * CreateImageFile//from w ww . j a va 2s.com */ private File createImageFile() throws IOException { // Create an image file name String timeStamp = String.valueOf(System.currentTimeMillis() / 1000L); String imageFileName = "PLATANUS" + timeStamp; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; }
From source file:es.upv.riromu.arbre.main.MainActivity.java
private File createImageFile(Bitmap bm) throws IOException { // Create an image file name String timeStamp = String.valueOf(System.currentTimeMillis() / 1000L); String imageFileName = "PLATANUS" + timeStamp; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ );/*w w w .ja va 2s .c om*/ OutputStream os; try { os = new FileOutputStream(image); bm.compress(Bitmap.CompressFormat.JPEG, 100, os); os.flush(); os.close(); } catch (Exception e) { Log.e(TAG, "Error writing bitmap", e); } return image; }
From source file:com.example.zf_android.trade.ApplyDetailActivity.java
private void setupItem(LinearLayout item, int itemType, final String key, final String value) { switch (itemType) { case ITEM_EDIT: { TextView tvKey = (TextView) item.findViewById(R.id.apply_detail_key); EditText etValue = (EditText) item.findViewById(R.id.apply_detail_value); if (!TextUtils.isEmpty(key)) tvKey.setText(key);/*from www . j a v a 2s . c o m*/ if (!TextUtils.isEmpty(value)) etValue.setText(value); break; } case ITEM_CHOOSE: { TextView tvKey = (TextView) item.findViewById(R.id.apply_detail_key); TextView tvValue = (TextView) item.findViewById(R.id.apply_detail_value); if (!TextUtils.isEmpty(key)) tvKey.setText(key); if (!TextUtils.isEmpty(value)) tvValue.setText(value); break; } case ITEM_UPLOAD: { TextView tvKey = (TextView) item.findViewById(R.id.apply_detail_key); final TextView tvValue = (TextView) item.findViewById(R.id.apply_detail_value); if (!TextUtils.isEmpty(key)) tvKey.setText(key); tvValue.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { uploadingTextView = tvValue; AlertDialog.Builder builder = new AlertDialog.Builder(ApplyDetailActivity.this); final String[] items = getResources().getStringArray(R.array.apply_detail_upload); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, REQUEST_UPLOAD_IMAGE); break; } case 1: { String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File outDir = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (!outDir.exists()) { outDir.mkdirs(); } File outFile = new File(outDir, System.currentTimeMillis() + ".jpg"); photoPath = outFile.getAbsolutePath(); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outFile)); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult(intent, REQUEST_TAKE_PHOTO); } else { CommonUtil.toastShort(ApplyDetailActivity.this, getString(R.string.toast_no_sdcard)); } break; } } } }); builder.show(); } }); break; } case ITEM_VIEW: { TextView tvKey = (TextView) item.findViewById(R.id.apply_detail_key); ImageButton ibView = (ImageButton) item.findViewById(R.id.apply_detail_view); if (!TextUtils.isEmpty(key)) tvKey.setText(key); ibView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(ApplyDetailActivity.this, ImageViewer.class); i.putExtra("url", value); i.putExtra("justviewer", true); startActivity(i); } }); } } }
From source file:com.creativeongreen.imageeffects.MainActivity.java
private static Bitmap getBitmapFromExternalStorage(OnItemClickListener onItemClickListener, String file) { Bitmap bitmap = null;// w ww .jav a2 s.c om String fullPathFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) .getAbsolutePath().toString() + File.separator + DIR_STORAGE_IMAGE + File.separator + file; // take action to prevent OutOfMemoryError: bitmap sized VM budget // when executing BitmapFactory // Runtime.getRuntime().gc(); // not work on this // solution: down size sampling BitmapFactory.Options bmFactoryOptions = new BitmapFactory.Options(); bmFactoryOptions.inJustDecodeBounds = true; // the decoder will return null (no bitmap) bitmap = BitmapFactory.decodeFile(fullPathFile, bmFactoryOptions); // calculate the down size scale factor int inSampleSize = 1; int targetWidth = 360; int targetHeight = 480; if (bmFactoryOptions.outHeight > targetHeight || bmFactoryOptions.outWidth > targetWidth) { // Calculate ratios of height and width to requested height and // width final int heightRatio = Math.round((float) bmFactoryOptions.outHeight / (float) targetHeight); final int widthRatio = Math.round((float) bmFactoryOptions.outWidth / (float) targetWidth); // Choose the smallest ratio as inSampleSize value, this will // guarantee // a final image with both dimensions larger than or equal to the // requested height and width. inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } // configure scale size bmFactoryOptions = new BitmapFactory.Options(); bmFactoryOptions.inJustDecodeBounds = false; // the decoder will return bitmap bmFactoryOptions.inSampleSize = inSampleSize; bitmap = BitmapFactory.decodeFile(fullPathFile, bmFactoryOptions); return bitmap; }
From source file:com.example.carsharing.ShortWayActivity.java
@Override public void onResume() { super.onResume(); // Always call the superclass method first shortway.setBackgroundDrawable(getResources().getDrawable(R.color.blue_0099cc)); // Get the Camera instance as the activity achieves full user focus Context phonenumber = ShortWayActivity.this; SharedPreferences filename = phonenumber.getSharedPreferences(getString(R.string.PreferenceDefaultName), Context.MODE_PRIVATE); UserPhoneNumber = filename.getString("refreshfilename", "0"); drawernum.setText(UserPhoneNumber);/*from w ww. j a v a2 s. c o m*/ Context context = ShortWayActivity.this; SharedPreferences sharedPref = context.getSharedPreferences(UserPhoneNumber, Context.MODE_PRIVATE); String fullname = sharedPref.getString("refreshname", ""); drawername.setText(fullname); File photoFile = new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), UserPhoneNumber); if (photoFile.exists()) { photouri = Uri.fromFile(photoFile); drawericon.setImageURI(photouri); } else { drawericon.setImageResource(R.drawable.ic_launcher); } }
From source file:com.affectiva.affdexme.MainActivity.java
private void processScreenshot(Bitmap drawingViewBitmap, boolean alsoSaveRaw) { if (mostRecentFrame == null) { Toast.makeText(getApplicationContext(), "No frame detected, aborting screenshot", Toast.LENGTH_SHORT) .show();// www . j ava 2 s .c o m return; } if (!storagePermissionsAvailable) { checkForStoragePermissions(); return; } Bitmap faceBitmap = ImageHelper.getBitmapFromFrame(mostRecentFrame); if (faceBitmap == null) { Log.e(LOG_TAG, "Unable to generate bitmap for frame, aborting screenshot"); return; } metricViewLayout.setDrawingCacheEnabled(true); Bitmap metricsBitmap = Bitmap.createBitmap(metricViewLayout.getDrawingCache()); metricViewLayout.setDrawingCacheEnabled(false); Bitmap finalScreenshot = Bitmap.createBitmap(faceBitmap.getWidth(), faceBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(finalScreenshot); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(faceBitmap, 0, 0, paint); float scaleFactor = ((float) faceBitmap.getWidth()) / ((float) drawingViewBitmap.getWidth()); int scaledHeight = Math.round(drawingViewBitmap.getHeight() * scaleFactor); canvas.drawBitmap(drawingViewBitmap, null, new Rect(0, 0, faceBitmap.getWidth(), scaledHeight), paint); scaleFactor = ((float) faceBitmap.getWidth()) / ((float) metricsBitmap.getWidth()); scaledHeight = Math.round(metricsBitmap.getHeight() * scaleFactor); canvas.drawBitmap(metricsBitmap, null, new Rect(0, 0, faceBitmap.getWidth(), scaledHeight), paint); metricsBitmap.recycle(); drawingViewBitmap.recycle(); Date now = new Date(); String timestamp = DateFormat.format("yyyy-MM-dd_hh-mm-ss", now).toString(); File pictureFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "AffdexMe"); if (!pictureFolder.exists()) { if (!pictureFolder.mkdir()) { Log.e(LOG_TAG, "Unable to create directory: " + pictureFolder.getAbsolutePath()); return; } } String screenshotFileName = timestamp + ".png"; File screenshotFile = new File(pictureFolder, screenshotFileName); try { ImageHelper.saveBitmapToFileAsPng(finalScreenshot, screenshotFile); } catch (IOException e) { String msg = "Unable to save screenshot"; Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); Log.e(LOG_TAG, msg, e); return; } ImageHelper.addPngToGallery(getApplicationContext(), screenshotFile); if (alsoSaveRaw) { String rawScreenshotFileName = timestamp + "_raw.png"; File rawScreenshotFile = new File(pictureFolder, rawScreenshotFileName); try { ImageHelper.saveBitmapToFileAsPng(faceBitmap, rawScreenshotFile); } catch (IOException e) { String msg = "Unable to save screenshot"; Log.e(LOG_TAG, msg, e); } ImageHelper.addPngToGallery(getApplicationContext(), rawScreenshotFile); } faceBitmap.recycle(); finalScreenshot.recycle(); String fileSavedMessage = "Screenshot saved to: " + screenshotFile.getPath(); Toast.makeText(getApplicationContext(), fileSavedMessage, Toast.LENGTH_SHORT).show(); Log.d(LOG_TAG, fileSavedMessage); }
From source file:com.fa.mastodon.activity.ComposeActivity.java
private File createNewImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date()); String imageFileName = "Tusky_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); return File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ );/*from w w w .j a va2 s . c o m*/ }
From source file:com.juce.JuceAppActivity.java
public static final String getPicturesFolder() { return getFileLocation (Environment.DIRECTORY_PICTURES); }
From source file:com.vanco.abplayer.BiliVideoViewActivity.java
@SuppressLint("SimpleDateFormat") @Override// ww w .j a v a 2 s. co m public void snapshot() { if (!com.vanco.abplayer.view.FileUtils.sdAvailable()) { ToastUtils.showToast(R.string.file_explorer_sdcard_not_available); } else { Uri imgUri = null; Bitmap bitmap = vPlayer.getCurrentFrame(); if (bitmap != null) { File screenshotsDirectory = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + VP.SNAP_SHOT_PATH); if (!screenshotsDirectory.exists()) { screenshotsDirectory.mkdirs(); } File savePath = new File(screenshotsDirectory.getPath() + "/" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".jpg"); if (ImageUtils.saveBitmap(savePath.getPath(), bitmap)) { imgUri = Uri.fromFile(savePath); } } if (imgUri != null) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, imgUri)); ToastUtils.showLongToast(getString(R.string.video_screenshot_save_in, imgUri.getPath())); } else { ToastUtils.showToast(R.string.video_screenshot_failed); } } }