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:ru.gkpromtech.exhibition.media.FullImageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_full_image); Bundle extras = getIntent().getExtras(); items = (List<Media>) extras.getSerializable("items"); files = (List<String>) extras.getSerializable("files"); int index = extras.getInt("index"); if (items != null) mode = SHOW_ITEMS_MODE;//from w w w. j ava 2 s .c o m else if (files != null) mode = SHOW_FILES_MODE; final View controlsView = findViewById(R.id.fullscreen_content_controls); final ViewPager pager = (ViewPager) findViewById(R.id.pager); appDirectoryName = getResources().getString(R.string.app_name); imageRoot = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appDirectoryName); // ViewPager and its adapters use support library // fragments, so use getSupportFragmentManager. pager.setAdapter(new FullImagePagerAdapter(getSupportFragmentManager())); pager.setCurrentItem(index); if (mode == SHOW_ITEMS_MODE) setTitle(items.get(index).name); else if (mode == SHOW_FILES_MODE) setTitle(new File(files.get(index)).getName()); else setTitle("Photo"); // Set up an instance of SystemUiHider to control the system UI for // this activity. mSystemUiHider = SystemUiHider.getInstance(this, pager, HIDER_FLAGS); mSystemUiHider.setup(); mSystemUiHider.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() { // Cached values. int mControlsHeight; int mShortAnimTime; @Override public void onVisibilityChange(boolean visible) { // If the ViewPropertyAnimator API is available // (Honeycomb MR2 and later), use it to animate the // in-layout UI controls at the bottom of the // screen. if (mControlsHeight == 0) { mControlsHeight = controlsView.getHeight(); } if (mShortAnimTime == 0) { mShortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); } controlsView.animate().translationY(visible ? 0 : mControlsHeight).setDuration(mShortAnimTime); if (visible && AUTO_HIDE) { // Schedule a hide(). delayedHide(AUTO_HIDE_DELAY_MILLIS); } } }); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i2) { } @Override public void onPageSelected(int index) { if (mode == SHOW_ITEMS_MODE) setTitle(items.get(index).name); else if (mode == SHOW_FILES_MODE) setTitle(new File(files.get(index)).getName()); else setTitle("Photo"); } @Override public void onPageScrollStateChanged(int i) { } }); // Upon interacting with UI controls, delay any scheduled hide() // operations to prevent the jarring behavior of controls going away // while interacting with the UI. pager.setOnTouchListener(mDelayHideTouchListener); }
From source file:com.wallerlab.compcellscope.Image_Gallery.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image__gallery); counter = 0;/*from w w w . j av a 2 s. com*/ final ImageView currPic = new ImageView(this); DisplayMetrics metrics = this.getResources().getDisplayMetrics(); final int screen_width = metrics.widthPixels; SharedPreferences settings = getSharedPreferences(Folder_Chooser.PREFS_NAME, 0); //SharedPreferences.Editor edit = settings.edit(); String path = settings.getString(Folder_Chooser.location_name, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString()); //Log.d(LOG, " | " + path + " | "); TextView text1 = (TextView) findViewById(R.id.text1); final TextView text2 = (TextView) findViewById(R.id.text2); text1.setText(path); File directory = new File(path); // get all the files from a directory File[] dump_files = directory.listFiles(); Log.d(LOG, dump_files.length + " "); final File[] fList = removeElements(dump_files, "info.json"); Log.d(LOG, "Filtered Length: " + fList.length); Arrays.sort(fList, new Comparator<File>() { @Override public int compare(File file, File file2) { String one = file.toString(); String two = file2.toString(); //Log.d(LOG, "one: " + one); //Log.d(LOG, "two: " + two); int num_one = Integer.parseInt(one.substring(one.lastIndexOf("(") + 1, one.lastIndexOf(")"))); int num_two = Integer.parseInt(two.substring(two.lastIndexOf("(") + 1, two.lastIndexOf(")"))); return num_one - num_two; } }); try { writeJsonFile(fList); } catch (JSONException e) { Log.d(LOG, "JSON WRITE FAILED"); } //List names programattically LinearLayout myLinearLayout = (LinearLayout) findViewById(R.id.linear_table); final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, screen_width + 4); myLinearLayout.setOrientation(LinearLayout.VERTICAL); if (fList != null) { File cur_pic = fList[0]; BitmapFactory.Options opts = new BitmapFactory.Options(); Log.d(LOG, "\n File Location: " + cur_pic.getAbsolutePath() + " \n" + " Parent: " + cur_pic.getParent().toString() + "\n"); Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); currPic.setLayoutParams(params); currPic.setImageBitmap(myImage); currPic.setId(View.generateViewId()); text2.setText(cur_pic.getName()); } myLinearLayout.addView(currPic); //Seekbar seekBar = (SeekBar) findViewById(R.id.seekBar); seekBar.setEnabled(true); seekBar.setMax(fList.length - 1); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { int progress = 0; int length = fList.length; @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { setCounter(i); if (getCounter() <= fList.length) { File cur_pic = fList[getCounter()]; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); int image_width = opts.outWidth; int image_height = opts.outHeight; int sampleSize = image_width / screen_width; opts.inSampleSize = sampleSize; text2.setText(cur_pic.getName()); opts.inJustDecodeBounds = false; myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); currPic.setImageBitmap(myImage); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); //Make Button Layout LinearLayout buttonLayout = new LinearLayout(this); buttonLayout.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams LLParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f); buttonLayout.setLayoutParams(LLParams); buttonLayout.setId(View.generateViewId()); //Button Layout Params LinearLayout.LayoutParams param_button = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f); //Prev Pic Button prevPic = new Button(this); prevPic.setText("Previous"); prevPic.setId(View.generateViewId()); prevPic.setLayoutParams(param_button); prevPic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (fList != null) { decrementCounter(); if (getCounter() >= 0) { File cur_pic = fList[getCounter()]; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); int image_width = opts.outWidth; int image_height = opts.outHeight; int sampleSize = image_width / screen_width; opts.inSampleSize = sampleSize; text2.setText(cur_pic.getName()); opts.inJustDecodeBounds = false; myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); //Log.d(LOG, getCounter() + ""); seekBar.setProgress(getCounter()); currPic.setImageBitmap(myImage); } else { setCounter(0); } } else { Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT); setCounter(getCounter() - 1); } } }); buttonLayout.addView(prevPic); // Next Picture Button Button nextPic = new Button(this); nextPic.setText("Next"); nextPic.setId(View.generateViewId()); nextPic.setLayoutParams(param_button); buttonLayout.addView(nextPic); nextPic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (fList != null) { incrementCounter(); if (getCounter() < fList.length) { File cur_pic = fList[getCounter()]; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); int image_width = opts.outWidth; int image_height = opts.outHeight; int sampleSize = image_width / screen_width; opts.inSampleSize = sampleSize; text2.setText(cur_pic.getName()); opts.inJustDecodeBounds = false; myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); //Log.d(LOG, getCounter() + ""); seekBar.setProgress(getCounter()); currPic.setImageBitmap(myImage); } else { setCounter(getCounter() - 1); } } else { Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT); setCounter(getCounter() - 1); } } }); myLinearLayout.addView(buttonLayout); }
From source file:com.example.d062654.faciliman._2_IncidentPicture.java
private File createImageFile() throws IOException { // Create an image file name String timeStamp = null;// www . j ava 2 s .c o m if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); } imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = ll.getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); System.out.println(imageFileName); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = image.getAbsolutePath(); return image; }
From source file:com.example.android.emojify.BitmapUtils.java
/** * Helper method for saving the image.//from w w w . j a va2 s . co m * * @param context The application context. * @param image The image to be saved. * @return The path of the saved image. */ static String saveImage(Context context, Bitmap image) { String savedImagePath = null; // Create the new file in the external storage String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()); String imageFileName = "JPEG_" + timeStamp + ".jpg"; File storageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Emojify"); boolean success = true; if (!storageDir.exists()) { success = storageDir.mkdirs(); } // Save the new Bitmap if (success) { File imageFile = new File(storageDir, imageFileName); savedImagePath = imageFile.getAbsolutePath(); try { OutputStream fOut = new FileOutputStream(imageFile); image.compress(Bitmap.CompressFormat.JPEG, 100, fOut); fOut.close(); } catch (Exception e) { e.printStackTrace(); } // Add the image to the system gallery galleryAddPic(context, savedImagePath); // Show a Toast with the save location String savedMessage = context.getString(R.string.saved_message, savedImagePath); Toast.makeText(context, savedMessage, Toast.LENGTH_SHORT).show(); } return savedImagePath; }
From source file:hochschuledarmstadt.photostream_tools.ImageCacher.java
static void deleteAllCachedImages(Context context) { File file = context.getFilesDir(); internalDeleteAllCachedImages(file); if (isExternalStorageAccessible()) { File pictureDirectory = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); internalDeleteAllCachedImages(pictureDirectory); }//from w w w .ja va 2 s . c om }
From source file:ca.cmput301f13t03.adventure_datetime.view.FullScreen_Image.java
private void setUpView() { if (_fragment == null) return;/*from w w w . j a v a 2 s.c om*/ if (_pageAdapter == null) return; Button gallery = (Button) findViewById(R.id.gallery); Button camera = (Button) findViewById(R.id.camera); Button delete = (Button) findViewById(R.id.action_delete); gallery.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, GALLERY); } }); camera.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { File picDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "adventure.datetime"); if (!picDir.exists()) picDir.mkdirs(); File pic = new File(picDir.getPath(), File.separator + _fragment.getFragmentID().toString() + "-" + _fragment.getStoryMedia().size()); _newImage = Uri.fromFile(pic); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(MediaStore.EXTRA_OUTPUT, _newImage); startActivityForResult(i, CAMERA); } }); _pageAdapter.setIllustrations(_fragment.getStoryMedia(), getIntent().getBooleanExtra(TAG_AUTHOR, false)); /* ArrayList<String> list = new ArrayList<String>(); for (int i=0; i<5; i++) list.add(""+i); _pageAdapter.setIllustrations(list, getIntent(). getBooleanExtra(TAG_AUTHOR, false));*/ }
From source file:org.intakers.intake.helper.SelectImageActivity.java
public void takePhoto(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { // Save the photo taken to a temporary file. File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); try {/*from w w w . j ava 2 s .co m*/ File file = File.createTempFile("IMG_", ".jpg", storageDir); mUriPhotoTaken = Uri.fromFile(file); //mUriPhotoTaken = FileProvider.getUriForFile(SelectImageActivity.this, BuildConfig.APPLICATION_ID + ".provider", file); Log.d("FileName in TakePhoto", file.getAbsolutePath()); intent.putExtra(MediaStore.EXTRA_OUTPUT, mUriPhotoTaken); startActivityForResult(intent, REQUEST_TAKE_PHOTO); } catch (IOException e) { setInfo(e.getMessage()); } } }
From source file:net.pictulog.otgdb.MainActivityFragment.java
private void backupFiles() { Context context = getContext(); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); if (!settings.contains(PreferencesActivity.PREFS_FROM_FILE) || !settings.contains(PreferencesActivity.PREFS_TO_FILE)) { Log.e("MainActivityFragment", "Missing from/to preferences..."); Toast.makeText(context, R.string.missingFromTo, Toast.LENGTH_LONG).show(); btnBackup.setEnabled(false);// ww w . j a v a 2 s . c om return; } File to = new File(settings.getString(PreferencesActivity.PREFS_TO_FILE, "")); if (!to.exists()) { Log.e("MainActivityFragment", "Invalid from/to preferences..."); Toast.makeText(context, R.string.invalidFromTo, Toast.LENGTH_LONG).show(); btnBackup.setEnabled(false); return; } Log.i("MainActivityFragment", "Copying all files from OTG Disk to " + to); try { FsDirectory srcDir = fromDir; File destDir = new File(settings.getString(PreferencesActivity.PREFS_TO_FILE, Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath())); List<String> extensions = Arrays .asList(settings.getString(PreferencesActivity.PREFS_EXTENSION, "").split(",")); boolean delete = settings.getBoolean(PreferencesActivity.PREFS_DELETE, false); boolean overwrite = settings.getBoolean(PreferencesActivity.PREFS_OVERWRITE, false); new BackupTask(this, srcDir, destDir, extensions, delete, overwrite).execute(); } catch (Exception e) { progressDialog.dismiss(); Log.e("MainActivityFragment", e.getMessage(), e); Toast.makeText(context, R.string.backingUpFailed, Toast.LENGTH_LONG).show(); } }
From source file:com.example.shinelon.ocrcamera.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGalleryButton = (ImageButton) findViewById(R.id.gallery_bt); mTxtButton = (ImageButton) findViewById(R.id.txt_bt); mCameraButton = (ImageButton) findViewById(R.id.camera_bt); mCropButton = (ImageButton) findViewById(R.id.crop_bt); mImageView = (myImageView) findViewById(R.id.image_photo); mCropButton.setEnabled(false);// ww w . j ava2s. co m // Load LEADTOOLS libs if (!loadLibs()) { return; } // Set License Support.setLicense(this); if (Support.isKernelExpired()) { Messager.showKernelExpiredMessage(this, new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { finish(); } }); return; } //File?? mFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "capturedImage.jpg"); mUri = Uri.fromFile(mFile); OCR_RUNTIME_DIRECTORY = Environment.getExternalStorageDirectory().getPath() + "/OCRRuntime/"; mGalleryButton.setOnClickListener(this); mTxtButton.setOnClickListener(this); mCameraButton.setOnClickListener(this); mCropButton.setOnClickListener(this); // Start the OCR engine mOcrEngine = OcrEngineManager.createEngine(OcrEngineType.ADVANTAGE); mOcrEngine.startup(null, null, null, OCR_RUNTIME_DIRECTORY); mOcrEngine.getLanguageManager().enableLanguages(new String[] { "en" }); }
From source file:com.xbm.android.matisse.internal.utils.MediaStoreCompat.java
private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()); String imageFileName = String.format("JPEG_%s.jpg", timeStamp); File storageDir;/* ww w. j a v a 2s . c o m*/ if (mCaptureStrategy.isPublic) { storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); } else { storageDir = mContext.get().getExternalFilesDir(Environment.DIRECTORY_PICTURES); } // Avoid joining path components manually File tempFile = new File(storageDir, imageFileName); // Handle the situation that user's external storage is not ready if (!Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(tempFile))) { return null; } return tempFile; }