Widget loading working

This commit is contained in:
Jaculabilis 2016-10-15 22:40:20 -05:00
parent 647a392d30
commit fe8b389e7e
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.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

View File

@ -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);

View File

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