Image previews essentially finished

This commit is contained in:
Jaculabilis 2016-10-15 18:31:15 -05:00
parent c599db86bd
commit 9fa545fcd0
5 changed files with 36 additions and 8 deletions

View File

@ -5,7 +5,7 @@ android {
buildToolsVersion "24.0.3" buildToolsVersion "24.0.3"
defaultConfig { defaultConfig {
applicationId "horse.jaeil.microframe" applicationId "horse.jaeil.microframe"
minSdkVersion 15 minSdkVersion 23
targetSdkVersion 23 targetSdkVersion 23
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@ -17,10 +17,12 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
productFlavors {
}
} }
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })

View File

@ -5,11 +5,17 @@ import android.appwidget.AppWidgetManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import java.io.FileNotFoundException;
import java.io.InputStream;
/** /**
* The configuration screen for the {@link FrameWidget FrameWidget} AppWidget. * The configuration screen for the {@link FrameWidget FrameWidget} AppWidget.
*/ */
@ -17,6 +23,7 @@ public class FrameWidgetConfigureActivity extends Activity {
// private static final String PREFS_NAME = "horse.jaeil.microframe.FrameWidget"; // private static final String PREFS_NAME = "horse.jaeil.microframe.FrameWidget";
// private static final String PREF_PREFIX_KEY = "appwidget_"; // private static final String PREF_PREFIX_KEY = "appwidget_";
private static final String TAG = "FrameWidgetConfigure";
private static final int REQUEST_IMAGE_GET = 1; private static final int REQUEST_IMAGE_GET = 1;
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
View.OnClickListener mSelectClickListener = new View.OnClickListener() { View.OnClickListener mSelectClickListener = new View.OnClickListener() {
@ -30,8 +37,9 @@ public class FrameWidgetConfigureActivity extends Activity {
.setType("image/*"); .setType("image/*");
if (intent.resolveActivity(context.getPackageManager()) != null) { if (intent.resolveActivity(context.getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_IMAGE_GET); startActivityForResult(intent, REQUEST_IMAGE_GET);
Log.d(TAG, "Started selector activity");
} }
//
// // When the button is clicked, store the string locally // // When the button is clicked, store the string locally
// String widgetText = mAppWidgetText.getText().toString(); // String widgetText = mAppWidgetText.getText().toString();
// saveTitlePref(context, mAppWidgetId, widgetText); // saveTitlePref(context, mAppWidgetId, widgetText);
@ -57,13 +65,29 @@ public class FrameWidgetConfigureActivity extends Activity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "Received Activity result");
if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) { if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) {
Bitmap thumbnail = data.getParcelableExtra("data"); // Bitmap thumbnail = data.getParcelableExtra("data");
Uri fullPhotoUri = data.getData(); Uri fullPhotoUri = data.getData();
// Set the preview image Log.i(TAG, fullPhotoUri.toString());
Drawable drawable;
try {
InputStream inputStream = getContentResolver().openInputStream(fullPhotoUri);
drawable = Drawable.createFromStream(inputStream, fullPhotoUri.toString());
} catch (FileNotFoundException e) {
Log.e(TAG, "Selected image was not found! Now it's going to crash...");
drawable = null;
}
ImageView preview = (ImageView) findViewById(R.id.previewImageView); ImageView preview = (ImageView) findViewById(R.id.previewImageView);
preview.setImageBitmap(thumbnail); // Drawable drawable = new BitmapDrawable(getResources(), thumbnail);
// drawable = Drawable.createFromPath(fullPhotoUri.getPath());
preview.setImageDrawable(drawable);
Log.d(TAG, "Set preview image");
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -18,9 +18,11 @@
android:id="@+id/previewImageView" android:id="@+id/previewImageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxHeight="300dp"
android:adjustViewBounds="true"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
app:srcCompat="@android:drawable/ic_menu_gallery" android:src="@drawable/example_appwidget_preview"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<Button <Button

View File

@ -3,5 +3,5 @@
<string name="appwidget_text">EXAMPLE</string> <string name="appwidget_text">EXAMPLE</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.2.3\nAuthor: Tim Van Baak</string> <string name="about">Version: 0.2.21\nAuthor: Tim Van Baak</string>
</resources> </resources>