import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
/**
* 他画面から戻ってきたとき...
- * @param requestCode
- * @param resultCode
- * @param data
+ *
*/
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
// 取得したuri を preferenceに記録する
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(parent);
Uri backgroundUri = data.getData();
- SharedPreferences.Editor editor = preferences.edit();
- editor.putString("backgroundUri", backgroundUri.toString());
- editor.commit();
-
- // 背景画像イメージの更新処理
- updateBackgroundImage(backgroundUri.toString());
-
+ if (backgroundUri != null)
+ {
+ try
+ {
+ if (Build.VERSION.SDK_INT >= 19) {
+ final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ parent.getContentResolver().takePersistableUriPermission(backgroundUri, takeFlags);
+ }
+ SharedPreferences.Editor editor = preferences.edit();
+ editor.putString("backgroundUri", backgroundUri.toString());
+ editor.apply();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ // 背景画像イメージの更新処理
+ updateBackgroundImage(backgroundUri.toString());
+ }
System.gc();
}
catch (Exception ex)
break;
case android.R.id.home:
- /** アイコンが押された時の処理... **/
+ // アイコンが押された時の処理...
// テキスト編集ダイアログを表示する
showInfoMessageEditDialog();
result = true;
*/
private void insertPicture()
{
- Intent intent = new Intent();
- intent.setType("image/*");
- intent.setAction(Intent.ACTION_GET_CONTENT);
+ Intent intent;
+ if (Build.VERSION.SDK_INT >= 19) {
+ intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+ intent.setType("image/*");
+ //intent.setAction(Intent.ACTION_GET_CONTENT);
+ } else {
+ intent = new Intent();
+ intent.setType("image/*");
+ intent.setAction(Intent.ACTION_GET_CONTENT);
+ }
parent.startActivityForResult(intent, MENU_ID_INSERT_PICTURE);
}
/**
* 画面キャプチャの実施
*
- * @param isShare
+ *
*/
private void doCapture(boolean isShare)
{
/**
* アイテム選択ダイアログの表示を準備する
*
- * @param dialog
+ *
*/
private void prepareItemSelectionDialog(Dialog dialog)
{
catch (Exception e)
{
// 例外発生...なにもしない。
+ e.printStackTrace();
//updater.showMessage("ERROR", MainUpdater.SHOWMETHOD_DONTCARE);
}
}
/**
* オブジェクトを本当に削除して良いか確認した後に、オブジェクトを削除する。
*
- * @param key
+ *
*/
private void removeObject(Integer key)
{
// ダイアログを表示する
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
-
- return;
}
/**
* オブジェクトを複製する
*
- * @param key
+ *
*/
private void duplicateObject(Integer key)
{
/**
* オブジェクトを拡大する
*
- * @param key
+ *
*/
private void expandObject(Integer key)
{
/**
* オブジェクトを縮小する
*
- * @param key
+ *
*/
private void shrinkObject(Integer key)
{
try
{
BitmapDrawable btnBackgroundShape = (BitmapDrawable)button.getBackground();
- if (isHighlight == true)
+ if (isHighlight)
{
// btnBackgroundShape.setColorFilter(Color.rgb(51, 181, 229), Mode.LIGHTEN);
btnBackgroundShape.setColorFilter(Color.BLUE, Mode.LIGHTEN);
/**
*
- * @param uri
+ *
*/
public void updateBackgroundBitmap(String uri, int width, int height)
{
// とりあえず、背景画像をクリアしてガベコレする。
backgroundBitmap = null;
System.gc();
- if (uri.isEmpty() == true)
+ if (uri.isEmpty())
{
// 背景画像の指定がなかったので、ここでリターンする。
return;
backgroundBitmap = null;
backgroundBitmapUri = "";
System.gc();
- }
- return;
+ }
}
/**
import java.io.InputStream;
import android.app.ProgressDialog;
import android.content.Context;
+import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
+import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
*/
public class ImageLoader
{
- ProgressDialog loadingDialog = null;
- Context parent = null;
+ ProgressDialog loadingDialog;
+ Context parent;
// 画像を表示する
String imageFile = null;
/**
* URIから変換
- *
- * @param imageFile
- * @return
+ *
*/
public static Uri parseUri(String imageFile)
{
- if (imageFile.startsWith("content://") == true)
+ if (imageFile.startsWith("content://"))
{
return (Uri.parse(imageFile));
}
-
File picFile = new File(imageFile);
return (Uri.fromFile(picFile));
}
public static void setImage(Context context, ImageView view, String imageFile)
{
// 画像を表示する
- Bitmap bitmap = null;
+ Bitmap bitmap;
int width = view.getWidth();
int height = view.getHeight();
- if (imageFile.startsWith("content://") == true)
+ if (imageFile.startsWith("content://"))
{
// URIから画像を設定する...OutOfMemory対策付き
bitmap = getBitmapFromUri(context, Uri.parse(imageFile), width, height);
imageBitmap = null;
imageWidth = view.getWidth();
imageHeight = view.getHeight();
-
- /**
- * ダイアログ表示中の処理
- *
- */
+
+ // ダイアログ表示中の処理
Thread thread = new Thread(new Runnable()
{
public void run()
{
try
{
- if (imageFile.startsWith("content://") == true)
+ if (imageFile.startsWith("content://"))
{
// URIから画像を設定する...OutOfMemory対策付き
imageBitmap = getBitmapFromUri(parent, Uri.parse(imageFile), imageWidth, imageHeight);
catch (Exception ex)
{
handler.sendEmptyMessage(0);
+ ex.printStackTrace();
}
}
imageHeight = 1;
loadingDialog.dismiss();
-
}
};
});
}
catch (Exception ex)
{
-
+ ex.printStackTrace();
}
}
/**
* URI経由でビットマップデータを取得する
*
- * @param context
- * @param uri
- * @param width
- * @param height
- * @return
*/
public static Bitmap getBitmapFromUri(Context context, Uri uri, int width, int height)
{
InputStream input = null;
try
- {
- input = context.getContentResolver().openInputStream(uri);
- BitmapFactory.decodeStream(input, null, opt);
- input.close();
+ {
+ if (Build.VERSION.SDK_INT >= 19)
+ {
+ context.getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ }
+ input = context.getContentResolver().openInputStream(uri);
+ if (input != null)
+ {
+ BitmapFactory.decodeStream(input, null, opt);
+ input.close();
+ }
}
catch (Exception ex)
{
- Log.v(Main.APP_IDENTIFIER, "Ex(1): " + ex.toString());
+ Log.v(Main.APP_IDENTIFIER, "Ex(1): " + ex.toString() + " URI : " + uri);
+ ex.printStackTrace();
if (input != null)
{
try
catch (Exception e)
{
//
+ e.printStackTrace();
}
}
}
catch (Exception e)
{
//
+ e.printStackTrace();
}
}
+ ex.printStackTrace();
}
return (retBitmap);
}
/**
* ビットマップデータを取得する
- *
- * @param pictureString
- * @param width
- * @param height
+ *
* @return ビットマップデータ
*/
public static Bitmap getBitmap(String pictureString, int width, int height)