Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

Commit 81eadc8

Browse files
committed
Merge pull request #10 from Manabu-GT/develop
Develop
2 parents 17d4976 + 112d48e commit 81eadc8

6 files changed

Lines changed: 80 additions & 12 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ android {
3333
applicationId "com.ms_square.android.design.overlay"
3434
minSdkVersion project.ANDROID_BUILD_MIN_SDK_VERSION
3535
targetSdkVersion project.ANDROID_BUILD_TARGET_SDK_VERSION
36-
versionCode 2
37-
versionName "1.0.1"
36+
versionCode 3
37+
versionName "1.0.2"
3838
}
3939

4040
signingConfigs {

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<!-- To overlay view above all the application UIs -->
77
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
88

9+
<!-- Looks this is needed to read Google+ photos -->
10+
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS"/>
11+
912
<application
1013
android:name=".app.DesignOverlayApplication"
1114
android:allowBackup="true"
@@ -24,9 +27,6 @@
2427
</intent-filter>
2528
</activity>
2629

27-
<!-- to remove sample activity from the library -->
28-
<activity android:name="net.margaritov.preference.colorpicker.Test" tools:node="remove"/>
29-
3030
<service android:name=".service.DesignOverlayService" />
3131

3232
</application>

app/src/main/java/com/ms_square/android/design/overlay/fragment/SettingsFragment.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
import android.content.Context;
55
import android.content.Intent;
66
import android.graphics.Bitmap;
7-
import android.graphics.BitmapFactory;
87
import android.net.Uri;
98
import android.os.Build;
109
import android.os.Bundle;
1110
import android.preference.ListPreference;
1211
import android.preference.Preference;
1312
import android.preference.PreferenceFragment;
1413
import android.preference.PreferenceManager;
14+
import android.util.TypedValue;
1515
import android.widget.Toast;
1616

1717
import com.ms.square.android.util.AppUtil;
1818
import com.ms.square.android.util.ToastMaster;
1919
import com.ms_square.android.design.overlay.BuildConfig;
2020
import com.ms_square.android.design.overlay.R;
2121
import com.ms_square.android.design.overlay.task.SafeAsyncTask;
22+
import com.ms_square.android.design.overlay.util.ImageUtil;
2223
import com.ms_square.android.design.overlay.util.PrefUtil;
2324
import com.ms_square.android.design.overlay.view.ImagePreference;
2425

@@ -36,6 +37,8 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
3637

3738
private ImagePreference mImagePreference;
3839

40+
private int mImageSize;
41+
3942
public static SettingsFragment newInstance() {
4043
SettingsFragment fragment = new SettingsFragment();
4144
//Bundle args = new Bundle();
@@ -56,6 +59,11 @@ public void onCreate(Bundle savedInstanceState) {
5659

5760
mAppContext = getActivity().getApplicationContext();
5861

62+
// get listPreferredItemHeight value in pixel and set it to mImageSize
63+
TypedValue value = new TypedValue();
64+
getActivity().getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true);
65+
mImageSize = (int) value.getDimension(getResources().getDisplayMetrics());
66+
5967
mImagePreference = (ImagePreference) findPreference(PrefUtil.PREF_DESIGN_IMAGE_URI);
6068
mImagePreference.setOnPreferenceClickListener(this);
6169
// load image if already set
@@ -113,7 +121,7 @@ protected Bitmap onRun(Uri... params) {
113121
InputStream stream = null;
114122
try {
115123
stream = mAppContext.getContentResolver().openInputStream(params[0]);
116-
bitmap = BitmapFactory.decodeStream(stream);
124+
bitmap = ImageUtil.decodeSampledBitmapFromStream(stream, mImageSize, mImageSize);
117125
} catch (FileNotFoundException fe) {
118126
Timber.w("File was not found:" + fe);
119127
} finally {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.ms_square.android.design.overlay.util;
2+
3+
import android.graphics.Bitmap;
4+
import android.graphics.BitmapFactory;
5+
6+
import java.io.BufferedInputStream;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
10+
import timber.log.Timber;
11+
12+
public class ImageUtil {
13+
14+
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
15+
16+
// Raw height and width of image
17+
final int height = options.outHeight;
18+
final int width = options.outWidth;
19+
int inSampleSize = 1;
20+
21+
if (height > reqHeight || width > reqWidth) {
22+
23+
final int halfHeight = height / 2;
24+
final int halfWidth = width / 2;
25+
26+
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
27+
// height and width larger than the requested height and width.
28+
while ((halfHeight / inSampleSize) > reqHeight
29+
&& (halfWidth / inSampleSize) > reqWidth) {
30+
inSampleSize *= 2;
31+
}
32+
}
33+
34+
return inSampleSize;
35+
}
36+
37+
public static Bitmap decodeSampledBitmapFromStream(InputStream inputStream,
38+
int reqWidth, int reqHeight) {
39+
final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
40+
bufferedInputStream.mark(Integer.MAX_VALUE);
41+
42+
// First decode with inJustDecodeBounds = true to check dimensions
43+
final BitmapFactory.Options options = new BitmapFactory.Options();
44+
options.inJustDecodeBounds = true;
45+
BitmapFactory.decodeStream(bufferedInputStream, null, options);
46+
47+
// Calculate inSampleSize
48+
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
49+
50+
try {
51+
bufferedInputStream.reset();
52+
} catch (IOException e) {
53+
Timber.w("Could not reposition the stream:" + e);
54+
}
55+
56+
// Decode bitmap with inSampleSize set
57+
options.inJustDecodeBounds = false;
58+
return BitmapFactory.decodeStream(bufferedInputStream, null, options);
59+
}
60+
}

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.0.0'
8+
classpath 'com.android.tools.build:gradle:1.1.0'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
@@ -21,11 +21,11 @@ allprojects {
2121

2222
// http://www.gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html
2323
project.ext {
24-
ANDROID_BUILD_SDK_VERSION = 21
25-
ANDROID_BUILD_TOOLS_VERSION = "21.1.2"
24+
ANDROID_BUILD_SDK_VERSION = 22
25+
ANDROID_BUILD_TOOLS_VERSION = "22"
2626

2727
ANDROID_BUILD_MIN_SDK_VERSION = 14
28-
ANDROID_BUILD_TARGET_SDK_VERSION = 21
28+
ANDROID_BUILD_TARGET_SDK_VERSION = 22
2929

3030
// Google Stuffs
3131
supportPackageVersion = "21.0.3"

0 commit comments

Comments
 (0)