Skip to content

Commit 289fc9e

Browse files
committed
Move BitmapFactory.Options Code to decodeUri()
1 parent 9adf397 commit 289fc9e

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="__PACKAGE__"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
7+
<supports-screens
8+
android:smallScreens="true"
9+
android:normalScreens="true"
10+
android:largeScreens="true"
11+
android:xlargeScreens="true"/>
12+
13+
<uses-sdk
14+
android:minSdkVersion="17"
15+
android:targetSdkVersion="__APILEVEL__"/>
16+
17+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
18+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
19+
<uses-permission android:name="android.permission.INTERNET"/>
20+
21+
<application
22+
android:name="com.tns.NativeScriptApplication"
23+
android:allowBackup="true"
24+
android:icon="@drawable/icon"
25+
android:label="@string/app_name"
26+
android:theme="@style/AppTheme" >
27+
<activity
28+
android:name="com.tns.NativeScriptActivity"
29+
android:label="@string/title_activity_kimera"
30+
android:configChanges="keyboardHidden|orientation|screenSize">
31+
32+
<intent-filter>
33+
<action android:name="android.intent.action.MAIN" />
34+
35+
<category android:name="android.intent.category.LAUNCHER" />
36+
</intent-filter>
37+
</activity>
38+
<activity android:name="com.tns.ErrorReportActivity"/>
39+
</application>
40+
</manifest>

examples/ExampleImgPick/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
},
1919
"dependencies": {
20-
"nativescript-imagepicker": "file:../../dist/package",
20+
"nativescript-imagepicker": "file:..\\..\\dist\\package",
2121
"tns-core-modules": "1.5.0"
2222
}
2323
}

source/viewmodel.android.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class SelectedAsset extends observable.Observable {
2929
return Promise.reject(new Error("Not implemented."));
3030
}
3131

32-
getImage(options?): Promise<imagesource.ImageSource> {
32+
getImage(options?: { maxWidth: number, maxHeight: number }): Promise<imagesource.ImageSource> {
3333
return new Promise<imagesource.ImageSource>((resolve, reject) => {
3434
try {
3535
resolve(this.decodeUri(this._uri, options));
@@ -123,9 +123,7 @@ export class SelectedAsset extends observable.Observable {
123123
};
124124

125125
// Decode with scale
126-
var downsampleOptions = new BitmapFactory.Options();
127-
downsampleOptions.inSampleSize = this.getSampleSize(this._uri, REQUIRED_SIZE);
128-
this._thumb = this.decodeUri(this._uri, downsampleOptions);
126+
this._thumb = this.decodeUri(this._uri, REQUIRED_SIZE);
129127
this.notifyPropertyChange("thumb", this._thumb);
130128
}
131129

@@ -135,7 +133,7 @@ export class SelectedAsset extends observable.Observable {
135133
* @param uri The URI of the image that should be scaled.
136134
* @param options The options that should be used to produce the correct image scale.
137135
*/
138-
private getSampleSize(uri: android.net.Uri, options?): number {
136+
private getSampleSize(uri: android.net.Uri, options?: { maxWidth: number, maxHeight: number }): number {
139137
var boundsOptions = new BitmapFactory.Options();
140138
boundsOptions.inJustDecodeBounds = true;
141139
BitmapFactory.decodeStream(this.openInputStream(uri), null, boundsOptions);
@@ -168,8 +166,10 @@ export class SelectedAsset extends observable.Observable {
168166
* @param uri The URI that should be decoded into an ImageSource.
169167
* @param options The options that should be used to decode the image.
170168
*/
171-
private decodeUri(uri: android.net.Uri, options: android.graphics.BitmapFactory.Options): imagesource.ImageSource {
172-
var bitmap = BitmapFactory.decodeStream(this.openInputStream(uri), null, options);
169+
private decodeUri(uri: android.net.Uri, options?: { maxWidth: number, maxHeight: number }): imagesource.ImageSource {
170+
var downsampleOptions = new BitmapFactory.Options();
171+
downsampleOptions.inSampleSize = this.getSampleSize(uri, options);
172+
var bitmap = BitmapFactory.decodeStream(this.openInputStream(uri), null, downsampleOptions);
173173
var image = new imagesource.ImageSource();
174174
image.setNativeSource(bitmap);
175175
return image;

0 commit comments

Comments
 (0)