diff --git a/app/src/main/java/com/forrestguice/suntimeswidget/themes/WidgetThemeConfigActivity.java b/app/src/main/java/com/forrestguice/suntimeswidget/themes/WidgetThemeConfigActivity.java index d33f0cbb7..d4f339c81 100644 --- a/app/src/main/java/com/forrestguice/suntimeswidget/themes/WidgetThemeConfigActivity.java +++ b/app/src/main/java/com/forrestguice/suntimeswidget/themes/WidgetThemeConfigActivity.java @@ -28,6 +28,7 @@ import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Typeface; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; @@ -48,6 +49,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CheckBox; @@ -248,6 +250,7 @@ public void onCreate(Bundle icicle) { AppSettings.setTheme(this, AppSettings.loadThemePref(this)); super.onCreate(icicle); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); initLocale(); setResult(RESULT_CANCELED); setContentView(R.layout.layout_themeconfig); @@ -1849,14 +1852,25 @@ protected static boolean validateThemeDisplayText(Context context, EditText edit protected void initWallpaper() { - WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); - if (wallpaperManager != null) + ImageView background = (ImageView)findViewById(R.id.preview_background); + + if (Build.VERSION.SDK_INT > 18) { - ImageView background = (ImageView)findViewById(R.id.preview_background); - Drawable wallpaper = wallpaperManager.getDrawable(); - if (background != null && wallpaper != null) - { - background.setImageDrawable(wallpaper); + background.setVisibility(View.GONE); + getWindow().setBackgroundDrawable(new ColorDrawable(0)); + + } else { + try { + WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); + if (wallpaperManager != null) + { + Drawable wallpaper = wallpaperManager.getDrawable(); + if (background != null && wallpaper != null) { + background.setImageDrawable(wallpaper); + } + } + } catch (Exception e) { + Log.e("initWallpaper", "failed to init wallpaper; " + e); } } } diff --git a/app/src/main/java/com/forrestguice/suntimeswidget/themes/WidgetThemeListActivity.java b/app/src/main/java/com/forrestguice/suntimeswidget/themes/WidgetThemeListActivity.java index 3de7a0cea..3a55ddd48 100644 --- a/app/src/main/java/com/forrestguice/suntimeswidget/themes/WidgetThemeListActivity.java +++ b/app/src/main/java/com/forrestguice/suntimeswidget/themes/WidgetThemeListActivity.java @@ -30,6 +30,7 @@ import android.content.SharedPreferences; import android.content.res.TypedArray; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; @@ -51,6 +52,7 @@ import android.view.MenuItem; import android.view.View; +import android.view.WindowManager; import android.widget.AdapterView; import android.widget.GridView; @@ -127,6 +129,11 @@ public void onCreate(Bundle icicle) { AppSettings.setTheme(this, AppSettings.loadThemePref(this)); super.onCreate(icicle); + if (Build.VERSION.SDK_INT > 18) + { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); + getWindow().setBackgroundDrawable(new ColorDrawable(0)); + } initLocale(); setResult(RESULT_CANCELED); setContentView(R.layout.layout_activity_themelist); @@ -193,6 +200,14 @@ public void onClick(View v) } }); } + + if (Build.VERSION.SDK_INT > 18) + { + ImageView background = (ImageView)findViewById(R.id.themegrid_background); + if (background != null) { + background.setAlpha(1f); + } + } } protected void initActionBar( Context context ) @@ -845,9 +860,10 @@ public void onRestoreInstanceState(@NonNull Bundle savedState) public void onResume() { super.onResume(); - if (useWallpaper) - { + if (useWallpaper) { initWallpaper(false); + } else { + hideWallpaper(); } if (isExporting && exportTask != null) { @@ -874,12 +890,28 @@ public void onResume() * Set activity background to match home screen wallpaper. */ protected void initWallpaper(boolean animate) + { + if (Build.VERSION.SDK_INT > 18) + { + ImageView shade = (ImageView)findViewById(R.id.themegrid_background); + shade.animate().alpha(0f).setDuration(WALLPAPER_DELAY); + + } else { + try { + initWallpaperLegacy(animate); + } catch (Exception e) { + Log.e("initWallpaper", "failed to init wallpaper; " + e); + } + } + } + @Deprecated + protected void initWallpaperLegacy(boolean animate) { WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); if (wallpaperManager != null) { ImageView background = (ImageView)findViewById(R.id.themegrid_background); - Drawable wallpaper = wallpaperManager.getDrawable(); + Drawable wallpaper = wallpaperManager.getDrawable(); // requires MANAGE_EXTERNAL_STORAGE if (background != null && wallpaper != null) { background.setImageDrawable(wallpaper); @@ -903,8 +935,11 @@ protected void hideWallpaper() ImageView background = (ImageView)findViewById(R.id.themegrid_background); if (background != null) { - if (Build.VERSION.SDK_INT >= 12) - { + if (Build.VERSION.SDK_INT > 18) { + ImageView shade = background; + shade.animate().alpha(1f).setDuration(WALLPAPER_DELAY); + + } else if (Build.VERSION.SDK_INT >= 12) { background.animate().alpha(0f).setDuration(WALLPAPER_DELAY); } else if (Build.VERSION.SDK_INT >= 11) { diff --git a/app/src/main/res/layout/layout_themeconfig.xml b/app/src/main/res/layout/layout_themeconfig.xml index 3f5145a1d..2baf2b70f 100644 --- a/app/src/main/res/layout/layout_themeconfig.xml +++ b/app/src/main/res/layout/layout_themeconfig.xml @@ -20,7 +20,7 @@ android:layout_width="match_parent" android:layout_height="match_parent">