Fix for Kitkat devices by copy the custom wallpaper on local directory to bypass the external file security imposed by Android
This commit is contained in:
parent
803fa8cb6c
commit
528ff2254d
@ -1,5 +1,7 @@
|
|||||||
package com.derpfish.pinkielive;
|
package com.derpfish.pinkielive;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -12,7 +14,6 @@ import com.derpfish.pinkielive.download.PonyDownloader;
|
|||||||
|
|
||||||
import android.app.WallpaperManager;
|
import android.app.WallpaperManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
@ -22,7 +23,6 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.service.wallpaper.WallpaperService;
|
import android.service.wallpaper.WallpaperService;
|
||||||
@ -96,7 +96,7 @@ public class PinkiePieLiveWallpaper extends WallpaperService
|
|||||||
drawFrame();
|
drawFrame();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private boolean mVisible;
|
private boolean mVisible;
|
||||||
private final SharedPreferences mPreferences;
|
private final SharedPreferences mPreferences;
|
||||||
private final BroadcastReceiver broadcastReceiver;
|
private final BroadcastReceiver broadcastReceiver;
|
||||||
@ -155,7 +155,7 @@ public class PinkiePieLiveWallpaper extends WallpaperService
|
|||||||
{
|
{
|
||||||
final WallpaperManager wmMan = WallpaperManager.getInstance(getApplicationContext());
|
final WallpaperManager wmMan = WallpaperManager.getInstance(getApplicationContext());
|
||||||
final AssetManager assetManager = getAssets();
|
final AssetManager assetManager = getAssets();
|
||||||
|
|
||||||
InputStream istr = assetManager.open("defaultbg.jpg");
|
InputStream istr = assetManager.open("defaultbg.jpg");
|
||||||
final int sampleSize = BitmapLoader.getSampleSizeFromInputStream(istr,
|
final int sampleSize = BitmapLoader.getSampleSizeFromInputStream(istr,
|
||||||
wmMan.getDesiredMinimumWidth(), wmMan.getDesiredMinimumHeight());
|
wmMan.getDesiredMinimumWidth(), wmMan.getDesiredMinimumHeight());
|
||||||
@ -176,7 +176,7 @@ public class PinkiePieLiveWallpaper extends WallpaperService
|
|||||||
defaultBg.recycle();
|
defaultBg.recycle();
|
||||||
defaultBg = null;
|
defaultBg = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String imageUriStr = prefs.getString("livewallpaper_image", null);
|
final String imageUriStr = prefs.getString("livewallpaper_image", null);
|
||||||
if (imageUriStr != null)
|
if (imageUriStr != null)
|
||||||
{
|
{
|
||||||
@ -185,22 +185,20 @@ public class PinkiePieLiveWallpaper extends WallpaperService
|
|||||||
selectedBg.recycle();
|
selectedBg.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Uri bgImage = Uri.parse(imageUriStr);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final ContentResolver contentResolver = getContentResolver();
|
File bg = new File(getApplicationContext().getFilesDir(), imageUriStr);
|
||||||
final WallpaperManager wmMan = WallpaperManager.getInstance(getApplicationContext());
|
final WallpaperManager wmMan = WallpaperManager.getInstance(getApplicationContext());
|
||||||
|
FileInputStream istr = new FileInputStream(bg);
|
||||||
InputStream istr = contentResolver.openInputStream(bgImage);
|
|
||||||
final int sampleSize = BitmapLoader.getSampleSizeFromInputStream(istr,
|
final int sampleSize = BitmapLoader.getSampleSizeFromInputStream(istr,
|
||||||
wmMan.getDesiredMinimumWidth(), wmMan.getDesiredMinimumHeight());
|
wmMan.getDesiredMinimumWidth(), wmMan.getDesiredMinimumHeight());
|
||||||
istr.close();
|
istr.close();
|
||||||
|
|
||||||
istr = contentResolver.openInputStream(bgImage);
|
istr = new FileInputStream(bg);
|
||||||
selectedBg = BitmapLoader.decodeSampledBitmapFromInputStream(istr, sampleSize);
|
selectedBg = BitmapLoader.decodeSampledBitmapFromInputStream(istr, sampleSize);
|
||||||
istr.close();
|
istr.close();
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
selectedBg = null;
|
selectedBg = null;
|
||||||
Log.w("PinkieLive", e);
|
Log.w("PinkieLive", e);
|
||||||
@ -376,7 +374,7 @@ public class PinkiePieLiveWallpaper extends WallpaperService
|
|||||||
final float bgScale = Math.min(((float)actualBg.getWidth()) / ((float)minWidth), ((float)actualBg.getHeight()) / ((float)minHeight));
|
final float bgScale = Math.min(((float)actualBg.getWidth()) / ((float)minWidth), ((float)actualBg.getHeight()) / ((float)minHeight));
|
||||||
final int centeringOffsetX = (int)((float)actualBg.getWidth() - bgScale*minWidth)/2;
|
final int centeringOffsetX = (int)((float)actualBg.getWidth() - bgScale*minWidth)/2;
|
||||||
final int centeringOffsetY = (int)((float)actualBg.getHeight() - bgScale*minHeight)/2;
|
final int centeringOffsetY = (int)((float)actualBg.getHeight() - bgScale*minHeight)/2;
|
||||||
|
|
||||||
c.drawBitmap(actualBg,
|
c.drawBitmap(actualBg,
|
||||||
new Rect(centeringOffsetX - (int)(offsetX*bgScale),
|
new Rect(centeringOffsetX - (int)(offsetX*bgScale),
|
||||||
centeringOffsetY - (int)(offsetY*bgScale),
|
centeringOffsetY - (int)(offsetY*bgScale),
|
||||||
|
@ -146,9 +146,8 @@ public class PinkieAnimation implements PonyAnimation
|
|||||||
lastAnim = (lastAnim + 1) % NUM_ANIMATIONS;
|
lastAnim = (lastAnim + 1) % NUM_ANIMATIONS;
|
||||||
if (bmAnimation != null)
|
if (bmAnimation != null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < bmAnimation.length; i++)
|
for (Bitmap aBmAnimation : bmAnimation) {
|
||||||
{
|
aBmAnimation.recycle();
|
||||||
bmAnimation[i].recycle();
|
|
||||||
}
|
}
|
||||||
bmAnimation = null;
|
bmAnimation = null;
|
||||||
}
|
}
|
||||||
@ -157,7 +156,7 @@ public class PinkieAnimation implements PonyAnimation
|
|||||||
final InputStream istr = assetManager.open("jump" + (lastAnim + 1) + ".zip");
|
final InputStream istr = assetManager.open("jump" + (lastAnim + 1) + ".zip");
|
||||||
final ZipInputStream zis = new ZipInputStream(istr);
|
final ZipInputStream zis = new ZipInputStream(istr);
|
||||||
final Map<String, Bitmap> bitmaps = new HashMap<String, Bitmap>();
|
final Map<String, Bitmap> bitmaps = new HashMap<String, Bitmap>();
|
||||||
ZipEntry zipEntry = null;
|
ZipEntry zipEntry;
|
||||||
while ((zipEntry = zis.getNextEntry()) != null)
|
while ((zipEntry = zis.getNextEntry()) != null)
|
||||||
{
|
{
|
||||||
bitmaps.put(zipEntry.getName(), BitmapFactory.decodeStream(zis));
|
bitmaps.put(zipEntry.getName(), BitmapFactory.decodeStream(zis));
|
||||||
@ -198,9 +197,8 @@ public class PinkieAnimation implements PonyAnimation
|
|||||||
{
|
{
|
||||||
if (bmAnimation != null)
|
if (bmAnimation != null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < bmAnimation.length; i++)
|
for (Bitmap aBmAnimation : bmAnimation) {
|
||||||
{
|
aBmAnimation.recycle();
|
||||||
bmAnimation[i].recycle();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.derpfish.pinkielive.preference;
|
package com.derpfish.pinkielive.preference;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import com.derpfish.pinkielive.PinkiePieLiveWallpaper;
|
import com.derpfish.pinkielive.PinkiePieLiveWallpaper;
|
||||||
import com.derpfish.pinkielive.R;
|
import com.derpfish.pinkielive.R;
|
||||||
|
|
||||||
@ -12,6 +13,8 @@ import android.preference.Preference;
|
|||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
public class PinkiePieLiveWallpaperSettings extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener, OnPreferenceClickListener
|
public class PinkiePieLiveWallpaperSettings extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener, OnPreferenceClickListener
|
||||||
{
|
{
|
||||||
private static final int SELECT_PICTURE = 1;
|
private static final int SELECT_PICTURE = 1;
|
||||||
@ -25,13 +28,13 @@ public class PinkiePieLiveWallpaperSettings extends PreferenceActivity implement
|
|||||||
|
|
||||||
getPreferenceManager().setSharedPreferencesName(PinkiePieLiveWallpaper.SHARED_PREFS_NAME);
|
getPreferenceManager().setSharedPreferencesName(PinkiePieLiveWallpaper.SHARED_PREFS_NAME);
|
||||||
addPreferencesFromResource(R.xml.livewallpaper_settings);
|
addPreferencesFromResource(R.xml.livewallpaper_settings);
|
||||||
|
|
||||||
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
setDefaultBgEnabled();
|
setDefaultBgEnabled();
|
||||||
|
|
||||||
findPreference("livewallpaper_image").setOnPreferenceClickListener(this);
|
findPreference("livewallpaper_image").setOnPreferenceClickListener(this);
|
||||||
|
|
||||||
gallery = new Intent();
|
gallery = new Intent();
|
||||||
gallery.setType("image/*");
|
gallery.setType("image/*");
|
||||||
gallery.setAction(Intent.ACTION_GET_CONTENT);
|
gallery.setAction(Intent.ACTION_GET_CONTENT);
|
||||||
@ -82,11 +85,33 @@ public class PinkiePieLiveWallpaperSettings extends PreferenceActivity implement
|
|||||||
if (requestCode == SELECT_PICTURE)
|
if (requestCode == SELECT_PICTURE)
|
||||||
{
|
{
|
||||||
Uri selectedImageUri = data.getData();
|
Uri selectedImageUri = data.getData();
|
||||||
SharedPreferences.Editor editor = getPreferenceManager().getSharedPreferences().edit();
|
try {
|
||||||
editor.putString("livewallpaper_image", selectedImageUri.toString());
|
// Delete old image
|
||||||
editor.putBoolean("livewallpaper_defaultbg", false);
|
String oldLocation = getPreferenceManager().getSharedPreferences().getString("livewallpaper_image", null);
|
||||||
editor.commit();
|
if (oldLocation != null) {
|
||||||
((CheckBoxPreference) findPreference("livewallpaper_defaultbg")).setChecked(false);
|
File oldFile = new File(getApplicationContext().getFilesDir(), oldLocation);
|
||||||
|
if (oldFile.exists()) oldFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the new one
|
||||||
|
FileOutputStream fos = openFileOutput(selectedImageUri.getLastPathSegment(), Context.MODE_PRIVATE);
|
||||||
|
InputStream fis = getContentResolver().openInputStream(selectedImageUri);
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = fis.read(buf)) != -1) {
|
||||||
|
fos.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
fis.close();
|
||||||
|
fos.close();
|
||||||
|
|
||||||
|
SharedPreferences.Editor editor = getPreferenceManager().getSharedPreferences().edit();
|
||||||
|
editor.putString("livewallpaper_image", selectedImageUri.getLastPathSegment());
|
||||||
|
editor.putBoolean("livewallpaper_defaultbg", false);
|
||||||
|
editor.commit();
|
||||||
|
((CheckBoxPreference) findPreference("livewallpaper_defaultbg")).setChecked(false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user