Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. package de.neriel.imagetest;
  2.  
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.os.Environment;
  6. import android.util.Log;
  7.  
  8.  
  9.  
  10. public class ImageOperationHelper {
  11.     /** Get TAG for debugging messages */
  12.     public static final boolean DEBUG = StartupActivity.DEBUG;
  13.  
  14.     /** Tag for LogCat */
  15.     public static final String TAG = ImageOperationHelper.class.getSimpleName();
  16.    
  17.     private CharSequence fileName;
  18.     boolean mExternalStorageAvailable = false;
  19.     boolean mExternalStorageWriteable = false;
  20.     ImageOperationHelper(CharSequence argfileName){
  21.         this.fileName=argfileName;
  22.     }
  23.    
  24.    
  25.     //Gets Bitmap Test.png from storage if available
  26.     private Bitmap getImage(){
  27.         checkSDCardStatus();
  28.         if (this.mExternalStorageAvailable) {
  29.            
  30.             if (DEBUG)
  31.                 Log.d(TAG, "Filename: " + this.fileName);
  32.             Bitmap mBitmap = BitmapFactory.decodeFile((String)this.fileName);
  33.            
  34.             return mBitmap;
  35.         }
  36.         return null;
  37.     }
  38.    
  39.    
  40.     //@TODO
  41.     public void drawLineOnBitMapAndSaveItOnSDCard(){
  42.         Bitmap mBitmap; //do something with that bastard bitmap
  43.         mBitmap = getImage();
  44.         if(mBitmap!=null){
  45.             //todo
  46.         }
  47.         if (mBitmap == null){
  48.             Log.d(TAG,"File on storage available?");
  49.         }
  50.     }
  51.    
  52.    
  53.     private void checkSDCardStatus() {
  54.         String state = Environment.getExternalStorageState();
  55.         if (Environment.MEDIA_MOUNTED.equals(state)) {
  56.             // We can read and write the media
  57.             mExternalStorageAvailable = mExternalStorageWriteable = true;
  58.         } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
  59.             // We can only read the media
  60.             mExternalStorageAvailable = true;
  61.             mExternalStorageWriteable = false;
  62.         } else {
  63.             // Something else is wrong. It may be one of many other states, but
  64.             // all we need
  65.             // to know is we can neither read nor write
  66.             mExternalStorageAvailable = mExternalStorageWriteable = false;
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement