From fe8b389e7e4ae2310bbda9233c26cc0c7ac747d8 Mon Sep 17 00:00:00 2001 From: Jaculabilis Date: Sat, 15 Oct 2016 22:40:20 -0500 Subject: [PATCH] Widget loading working --- .../horse/jaeil/microframe/FrameWidget.java | 39 +++++++++++++------ .../FrameWidgetConfigureActivity.java | 13 ++++--- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/horse/jaeil/microframe/FrameWidget.java b/app/src/main/java/horse/jaeil/microframe/FrameWidget.java index c5aa083..f6fc4b6 100644 --- a/app/src/main/java/horse/jaeil/microframe/FrameWidget.java +++ b/app/src/main/java/horse/jaeil/microframe/FrameWidget.java @@ -3,7 +3,9 @@ package horse.jaeil.microframe; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; +import android.graphics.Bitmap; import android.net.Uri; +import android.provider.MediaStore; import android.util.Log; import android.widget.RemoteViews; @@ -18,20 +20,33 @@ public class FrameWidget extends AppWidgetProvider { int appWidgetId) { String uriString = FrameWidgetConfigureActivity.loadImgRef(context, appWidgetId); - Log.d(TAG, "Widget updating with uriString=" + uriString); - RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.frame_widget); - // Depending on the URI string, set the widget image - if (!uriString.equals("")) { - Uri uri = Uri.parse(uriString); - views - .setImageViewUri(R.id.frameImage, uri); - } else { - views - .setImageViewResource(R.id.frameImage, R.drawable.frame_default); - } + Log.i(TAG, "Widget updating with uriString = \"" + uriString + "\""); - // Instruct the widget manager to update the widget + RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.frame_widget); + if (uriString.equals("")) { + views.setImageViewResource(R.id.frameImage, R.drawable.frame_default); + } else { + Uri uri = Uri.parse(uriString); + try { + Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri); + views.setImageViewBitmap(R.id.frameImage, bitmap); + } catch (Exception e) { + e.printStackTrace(); + } + + } appWidgetManager.updateAppWidget(appWidgetId, views); + + // Depending on the URI string, set the widget image +// if (!uriString.equals("")) { +// Uri uri = Uri.parse(uriString); +// Log.i(TAG, "Parsed URI: " + uri.toString()); +// views +// .setImageViewUri(R.id.frameImage, uri); +// } else { +// views +// .setImageViewResource(R.id.frameImage, R.drawable.frame_default); +// } } @Override diff --git a/app/src/main/java/horse/jaeil/microframe/FrameWidgetConfigureActivity.java b/app/src/main/java/horse/jaeil/microframe/FrameWidgetConfigureActivity.java index 65f8c1a..4a2bf55 100644 --- a/app/src/main/java/horse/jaeil/microframe/FrameWidgetConfigureActivity.java +++ b/app/src/main/java/horse/jaeil/microframe/FrameWidgetConfigureActivity.java @@ -50,7 +50,7 @@ public class FrameWidgetConfigureActivity extends Activity { // Get the URI of the preview image TextView textView = (TextView) findViewById(R.id.previewUri); String uriString = textView.getText().toString(); - Log.d(TAG, "Finish clicked with URI " + uriString); + Log.i(TAG, "Finish clicked with URI = \"" + uriString + "\""); // Send an update to the widget so it can load the image saveImgRef(context, mAppWidgetId, uriString); @@ -74,14 +74,17 @@ public class FrameWidgetConfigureActivity extends Activity { if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) { // Parse the URI into a drawable Uri fullPhotoUri = data.getData(); - Log.i(TAG, "URI selected: " + fullPhotoUri); + Log.i(TAG, "URI selected: \"" + fullPhotoUri + "\""); + String uriString = fullPhotoUri.toString(); + Uri uri = Uri.parse(uriString); + Log.i(TAG, "URI reread : \"" + uri + "\""); Drawable drawable; TextView previewText = (TextView) findViewById(R.id.previewUri); try { - InputStream inputStream = getContentResolver().openInputStream(fullPhotoUri); - drawable = Drawable.createFromStream(inputStream, fullPhotoUri.toString()); + InputStream inputStream = getContentResolver().openInputStream(uri); + drawable = Drawable.createFromStream(inputStream, uri.toString()); // If the Drawable was successfully loaded, then store the URI for the widget - previewText.setText(fullPhotoUri.toString()); + previewText.setText(uriString); } catch (FileNotFoundException e) { Log.e(TAG, "Selected image not found!"); drawable = getResources().getDrawable(R.drawable.frame_default, null); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 668a630..7be73fd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,5 +2,5 @@ MicroFrame Select an Image Finish - Version: 0.3.3\nAuthor: Tim Van Baak + Version: 0.3.4\nAuthor: Tim Van Baak