Widget loading working

This commit is contained in:
Jaculabilis 2016-10-15 22:40:20 -05:00
parent 647a392d30
commit e5e0fb3daa
3 changed files with 36 additions and 18 deletions

View File

@ -3,7 +3,9 @@ package horse.jaeil.microframe;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider; import android.appwidget.AppWidgetProvider;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log; import android.util.Log;
import android.widget.RemoteViews; import android.widget.RemoteViews;
@ -18,20 +20,33 @@ public class FrameWidget extends AppWidgetProvider {
int appWidgetId) { int appWidgetId) {
String uriString = FrameWidgetConfigureActivity.loadImgRef(context, appWidgetId); String uriString = FrameWidgetConfigureActivity.loadImgRef(context, appWidgetId);
Log.d(TAG, "Widget updating with uriString=" + uriString); Log.i(TAG, "Widget updating with uriString = \"" + uriString + "\"");
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.frame_widget); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.frame_widget);
// Depending on the URI string, set the widget image if (uriString.equals("")) {
if (!uriString.equals("")) { views.setImageViewResource(R.id.frameImage, R.drawable.frame_default);
Uri uri = Uri.parse(uriString);
views
.setImageViewUri(R.id.frameImage, uri);
} else { } else {
views Uri uri = Uri.parse(uriString);
.setImageViewResource(R.id.frameImage, R.drawable.frame_default); try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
views.setImageViewBitmap(R.id.frameImage, bitmap);
} catch (Exception e) {
e.printStackTrace();
} }
// Instruct the widget manager to update the widget }
appWidgetManager.updateAppWidget(appWidgetId, views); 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 @Override

View File

@ -50,7 +50,7 @@ public class FrameWidgetConfigureActivity extends Activity {
// Get the URI of the preview image // Get the URI of the preview image
TextView textView = (TextView) findViewById(R.id.previewUri); TextView textView = (TextView) findViewById(R.id.previewUri);
String uriString = textView.getText().toString(); 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 // Send an update to the widget so it can load the image
saveImgRef(context, mAppWidgetId, uriString); saveImgRef(context, mAppWidgetId, uriString);
@ -74,14 +74,17 @@ public class FrameWidgetConfigureActivity extends Activity {
if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) { if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) {
// Parse the URI into a drawable // Parse the URI into a drawable
Uri fullPhotoUri = data.getData(); 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; Drawable drawable;
TextView previewText = (TextView) findViewById(R.id.previewUri); TextView previewText = (TextView) findViewById(R.id.previewUri);
try { try {
InputStream inputStream = getContentResolver().openInputStream(fullPhotoUri); InputStream inputStream = getContentResolver().openInputStream(uri);
drawable = Drawable.createFromStream(inputStream, fullPhotoUri.toString()); drawable = Drawable.createFromStream(inputStream, uri.toString());
// If the Drawable was successfully loaded, then store the URI for the widget // If the Drawable was successfully loaded, then store the URI for the widget
previewText.setText(fullPhotoUri.toString()); previewText.setText(uriString);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(TAG, "Selected image not found!"); Log.e(TAG, "Selected image not found!");
drawable = getResources().getDrawable(R.drawable.frame_default, null); drawable = getResources().getDrawable(R.drawable.frame_default, null);

View File

@ -2,5 +2,5 @@
<string name="app_name">MicroFrame</string> <string name="app_name">MicroFrame</string>
<string name="select_an_image">Select an Image</string> <string name="select_an_image">Select an Image</string>
<string name="finish">Finish</string> <string name="finish">Finish</string>
<string name="about">Version: 0.3.3\nAuthor: Tim Van Baak</string> <string name="about">Version: 0.4\nAuthor: Tim Van Baak</string>
</resources> </resources>