gt:                 Log.e("PAINTROID", "URI ERROR ", e);
context: /**
   * Paintroid: An image manipulation application for Android.
   * Copyright (C) 2010-2015 The Catrobat Team
   * (<http://developer.catrobat.org/credits>)
   * <p/>
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Affero General Public License as
   * published by the Free Software Foundation, either version 3 of the
   * License, or (at your option) any later version.
   * <p/>
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU Affero General Public License for more details.
   * <p/>
   * You should have received a copy of the GNU Affero General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  
  package com.liwn.zzl.markbit;
  
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.content.ContentUris;
  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.DatabaseUtils;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.net.Uri;
  import android.os.Build;
  import android.os.Environment;
  import android.provider.DocumentsContract;
  import android.provider.MediaStore;
  import android.util.DisplayMetrics;
  import android.util.Log;
  import android.view.Display;
  import android.view.WindowManager;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.FilenameFilter;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.net.URISyntaxException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  
  @SuppressLint("NewApi")
  public abstract class FileIO {
  
      private static final String TAG = FileIO.class.getSimpleName();
      private static File MEDIA_FILE = null;
      private static final int BUFFER_SIZE = 1024;
      public static final String default_prefix = "mark";
      public static final String default_num = "-1";
      public static final String default_date = "date";
      public static final String default_tag = "tag";
      public static String default_file_name = default_prefix + "_" + default_num + "_" + default_date + "_" + default_tag;
      private static final String DEFAULT_FILENAME_TIME_FORMAT = "yyyy-MM-dd-hhmmss";
      private static final String ENDING = ".png";
  
      private FileIO() {
      }
  
      public static void deleteAllFiles() {
          for (File file : getFiles()) {
              file.delete();
          }
      }
  
      public static String getMediaFolderName() {
          if(MEDIA_FILE == null){
              if(initialisePaintroidMediaDirectory() == true) {
                  return MEDIA_FILE.getAbsolutePath();
              } else {
                  return null;
              }
          }
          return MEDIA_FILE.getAbsolutePath();
      }
  
      public static Uri getBaseUri() {
          return MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
      }
  
      public static boolean saveBitmap(Context context, Bitmap bitmap) {
          return saveBitmap(context, bitmap, null);
      }
  
      public static boolean saveBitmap(Context context, Bitmap bitmap, String path) {
          if (initialisePaintroidMediaDirectory() == false) {
              return false;
          }
  
          final int QUALITY = 100;
          final Bitmap.CompressFormat FORMAT = Bitmap.CompressFormat.PNG;
          OutputStream outputStream = null;
          File file = null;
  
          try {
              if (bitmap == null || bitmap.isRecycled()) {
                  Log.e(MarkBitApplication.TAG, "ERROR saving bitmap. ");
                  return false;
              } else if (path != null) {
                  file = new File(path);
                  outputStream = new FileOutputStream(file);
              } else if (MarkBitApplication.savedPictureUri != null
                      && !MarkBitApplication.saveCopy) {
                  outputStream = context.getContentResolver().openOutputStream(
                          MarkBitApplication.savedPictureUri);
              } else {
                  file = createNewEmptyPictureFile(context);
                  outputStream = new FileOutputStream(file);
              }
          } catch (FileNotFoundException e) {
              Log.e(MarkBitApplication.TAG,
                      "ERROR writing image file. File not found. Path: " + path,
                      e);
              return false;
          }
  
          if (outputStream != null) {
              boolean isSaved = bitmap.compress(FORMAT, QUALITY, outputStream);
              try {
                  outputStream.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              if (isSaved) {
                  if (file != null) {
                      ContentValues contentValues = new ContentValues();
                      contentValues.put(MediaStore.MediaColumns.DATA,
                              file.getAbsolutePath());
  
                      MarkBitApplication.savedPictureUri = context
                              .getContentResolver().insert(getBaseUri(),
                                      contentValues);
                  }
              } else {
                  Log.e(MarkBitApplication.TAG,
                          "ERROR writing image file. Bitmap compress didn't work. ");
                  return false;
              }
  
          }
          return true;
      }
  
      public static String getDefaultFileNameByPrefix(String fileName) {
          String preFileName = fileName.split("\\.")[0];
  
          StringBuilder stringBuilder = new StringBuilder(preFileName);
  
          SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DEFAULT_FILENAME_TIME_FORMAT);
          stringBuilder.append("_");
          stringBuilder.append(simpleDateFormat.format(new Date()));
          stringBuilder.append("_");
          stringBuilder.append(default_tag);
  
          return stringBuilder.toString() + ENDING;
      }
  
      public static String getDefaultFileName() {
          StringBuilder stringBuilder = new StringBuilder();
          SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                  DEFAULT_FILENAME_TIME_FORMAT);
          String[] fileNameSplit = default_file_name.split("_");
          for (String nameSplit : fileNameSplit) {
              if (nameSplit.equals(default_date)) {
                  stringBuilder.append(simpleDateFormat.format(new Date()));
              } else {
                  stringBuilder.append(nameSplit);
              }
              stringBuilder.append("_");
          }
          if (stringBuilder.length() >= 1)
              stringBuilder.deleteCharAt(stringBuilder.length() - 1);
          return stringBuilder.toString() + ENDING;
      }
  
      public static File createNewEmptyPictureFile(Context context,
                                                   String filename) {
          if (initialisePaintroidMediaDirectory() == true) {
              if (!filename.toLowerCase().endsWith(ENDING.toLowerCase())) {
                  filename += ENDING;
              }
              return new File(MEDIA_FILE, filename);
          } else {
              return null;
          }
      }
  
      public static File createNewEmptyPictureFile(Context context) {
          return createNewEmptyPictureFile(context, getDefaultFileName());
      }
  
      public static String getRealPathFromURI(Context context, Uri imageUri) {
          String path = null;
          String[] filePathColumn = {MediaStore.Images.Media.DATA};
          Cursor cursor = context.getContentResolver().query(imageUri,
                  filePathColumn, null, null, null);
  
          if (cursor != null) {
              cursor.moveToFirst();
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              path = cursor.getString(columnIndex);
          } else {
              try {
                  File file = new File(new java.net.URI(imageUri.toString()));
                  path = file.getAbsolutePath();
              } catch (URISyntaxException e) {
  