Widget loading working
This commit is contained in:
parent
647a392d30
commit
e5e0fb3daa
|
@ -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);
|
||||
Log.i(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);
|
||||
if (uriString.equals("")) {
|
||||
views.setImageViewResource(R.id.frameImage, R.drawable.frame_default);
|
||||
} else {
|
||||
views
|
||||
.setImageViewResource(R.id.frameImage, R.drawable.frame_default);
|
||||
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();
|
||||
}
|
||||
|
||||
// Instruct the widget manager to update the widget
|
||||
}
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.4\nAuthor: Tim Van Baak</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue