Loading app/src/main/java/org/lineageos/backgrounds/adapters/WallsAdapter.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -50,6 +50,7 @@ public final class WallsAdapter extends RecyclerView.Adapter<WallpaperHolder> { switch (type) { switch (type) { case BUILT_IN: case BUILT_IN: case DEFAULT: case DEFAULT: case GRADIENT: case MONO: case MONO: return buildDefaultHolder(parent); return buildDefaultHolder(parent); default: default: Loading app/src/main/java/org/lineageos/backgrounds/bundle/WallpaperType.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ package org.lineageos.backgrounds.bundle; public enum WallpaperType { public enum WallpaperType { BUILT_IN, BUILT_IN, DEFAULT, DEFAULT, GRADIENT, MONO, MONO, USER USER } } app/src/main/java/org/lineageos/backgrounds/factory/GradientWallpaperFactory.java 0 → 100644 +38 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2019 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.lineageos.backgrounds.factory; import android.content.res.Resources; import android.graphics.drawable.Drawable; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import org.lineageos.backgrounds.bundle.WallpaperBundle; import org.lineageos.backgrounds.bundle.WallpaperType; public final class GradientWallpaperFactory { private GradientWallpaperFactory() { } public static WallpaperBundle build(@NonNull final String name, @NonNull final Resources res, @DrawableRes final int drawableRes) { Drawable drawable = res.getDrawable(drawableRes, res.newTheme()); return new WallpaperBundle(name, drawable, drawableRes, WallpaperType.GRADIENT); } } app/src/main/java/org/lineageos/backgrounds/task/FetchDataImpl.java +17 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ import androidx.annotation.NonNull; import org.lineageos.backgrounds.R; import org.lineageos.backgrounds.R; import org.lineageos.backgrounds.bundle.WallpaperBundle; import org.lineageos.backgrounds.bundle.WallpaperBundle; import org.lineageos.backgrounds.factory.BuiltInWallpaperFactory; import org.lineageos.backgrounds.factory.BuiltInWallpaperFactory; import org.lineageos.backgrounds.factory.GradientWallpaperFactory; import org.lineageos.backgrounds.factory.MonoWallpaperFactory; import org.lineageos.backgrounds.factory.MonoWallpaperFactory; import org.lineageos.backgrounds.factory.UserWallpaperFactory; import org.lineageos.backgrounds.factory.UserWallpaperFactory; Loading @@ -45,6 +46,7 @@ final class FetchDataImpl { addUser(); addUser(); addBuiltIn(); addBuiltIn(); addColors(); addColors(); addGradients(); return mData; return mData; } } Loading Loading @@ -86,6 +88,21 @@ final class FetchDataImpl { colors.recycle(); colors.recycle(); } } private void addGradients() { Resources res = mCallbacks.getResources(); String[] names = res.getStringArray(R.array.wallpaper_gradient_names); TypedArray gradients = res.obtainTypedArray(R.array.wallpaper_gradient_drawables); for (int i = 0; i < gradients.length(); i++) { final TypedValue value = new TypedValue(); gradients.getValue(i, value); if (value.resourceId != 0) { mData.add(GradientWallpaperFactory.build(names[i], res, value.resourceId)); } } gradients.recycle(); } public interface Callback { public interface Callback { @NonNull @NonNull Resources getResources(); Resources getResources(); Loading app/src/main/java/org/lineageos/backgrounds/ui/ApplyActivity.java +23 −0 Original line number Original line Diff line number Diff line Loading @@ -39,6 +39,7 @@ import org.lineageos.backgrounds.bundle.WallpaperBundle; import org.lineageos.backgrounds.task.ApplyWallpaperTask; import org.lineageos.backgrounds.task.ApplyWallpaperTask; import org.lineageos.backgrounds.task.LoadDrawableFromUriTask; import org.lineageos.backgrounds.task.LoadDrawableFromUriTask; import org.lineageos.backgrounds.util.ColorUtils; import org.lineageos.backgrounds.util.ColorUtils; import org.lineageos.backgrounds.util.TypeConverter; import org.lineageos.backgrounds.util.UiUtils; import org.lineageos.backgrounds.util.UiUtils; public final class ApplyActivity extends AppCompatActivity { public final class ApplyActivity extends AppCompatActivity { Loading Loading @@ -90,6 +91,9 @@ public final class ApplyActivity extends AppCompatActivity { case DEFAULT: case DEFAULT: setupDefault(); setupDefault(); break; break; case GRADIENT: setupGradient(wallpaperBundle); break; case MONO: case MONO: setupMono(wallpaperBundle); setupMono(wallpaperBundle); break; break; Loading Loading @@ -122,6 +126,25 @@ public final class ApplyActivity extends AppCompatActivity { displayPreview(drawable); displayPreview(drawable); } } private void setupGradient(@NonNull final WallpaperBundle bundle) { /* * Welcome to HackLand pt2: GradientDrawable doesn't play nicely with * shared element transitions, so we have to make some magic: * 1. Get the OG drawable * 2. Convert to a Bitmap * 3. Convert the Bitmap to a BitmapDrawable * 4. Apply the BitmapDrawable */ final Drawable origDrawable = ContextCompat.getDrawable(this, bundle.getDescriptor()); if (origDrawable == null) { return; } final Bitmap bm = TypeConverter.drawableToBitmap(origDrawable); final BitmapDrawable bmd = new BitmapDrawable(getResources(), bm); displayPreview(bmd); } private void setupUser(@Nullable final String wallpaperUri) { private void setupUser(@Nullable final String wallpaperUri) { if (wallpaperUri == null) { if (wallpaperUri == null) { finish(); finish(); Loading Loading
app/src/main/java/org/lineageos/backgrounds/adapters/WallsAdapter.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -50,6 +50,7 @@ public final class WallsAdapter extends RecyclerView.Adapter<WallpaperHolder> { switch (type) { switch (type) { case BUILT_IN: case BUILT_IN: case DEFAULT: case DEFAULT: case GRADIENT: case MONO: case MONO: return buildDefaultHolder(parent); return buildDefaultHolder(parent); default: default: Loading
app/src/main/java/org/lineageos/backgrounds/bundle/WallpaperType.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ package org.lineageos.backgrounds.bundle; public enum WallpaperType { public enum WallpaperType { BUILT_IN, BUILT_IN, DEFAULT, DEFAULT, GRADIENT, MONO, MONO, USER USER } }
app/src/main/java/org/lineageos/backgrounds/factory/GradientWallpaperFactory.java 0 → 100644 +38 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2019 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.lineageos.backgrounds.factory; import android.content.res.Resources; import android.graphics.drawable.Drawable; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import org.lineageos.backgrounds.bundle.WallpaperBundle; import org.lineageos.backgrounds.bundle.WallpaperType; public final class GradientWallpaperFactory { private GradientWallpaperFactory() { } public static WallpaperBundle build(@NonNull final String name, @NonNull final Resources res, @DrawableRes final int drawableRes) { Drawable drawable = res.getDrawable(drawableRes, res.newTheme()); return new WallpaperBundle(name, drawable, drawableRes, WallpaperType.GRADIENT); } }
app/src/main/java/org/lineageos/backgrounds/task/FetchDataImpl.java +17 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ import androidx.annotation.NonNull; import org.lineageos.backgrounds.R; import org.lineageos.backgrounds.R; import org.lineageos.backgrounds.bundle.WallpaperBundle; import org.lineageos.backgrounds.bundle.WallpaperBundle; import org.lineageos.backgrounds.factory.BuiltInWallpaperFactory; import org.lineageos.backgrounds.factory.BuiltInWallpaperFactory; import org.lineageos.backgrounds.factory.GradientWallpaperFactory; import org.lineageos.backgrounds.factory.MonoWallpaperFactory; import org.lineageos.backgrounds.factory.MonoWallpaperFactory; import org.lineageos.backgrounds.factory.UserWallpaperFactory; import org.lineageos.backgrounds.factory.UserWallpaperFactory; Loading @@ -45,6 +46,7 @@ final class FetchDataImpl { addUser(); addUser(); addBuiltIn(); addBuiltIn(); addColors(); addColors(); addGradients(); return mData; return mData; } } Loading Loading @@ -86,6 +88,21 @@ final class FetchDataImpl { colors.recycle(); colors.recycle(); } } private void addGradients() { Resources res = mCallbacks.getResources(); String[] names = res.getStringArray(R.array.wallpaper_gradient_names); TypedArray gradients = res.obtainTypedArray(R.array.wallpaper_gradient_drawables); for (int i = 0; i < gradients.length(); i++) { final TypedValue value = new TypedValue(); gradients.getValue(i, value); if (value.resourceId != 0) { mData.add(GradientWallpaperFactory.build(names[i], res, value.resourceId)); } } gradients.recycle(); } public interface Callback { public interface Callback { @NonNull @NonNull Resources getResources(); Resources getResources(); Loading
app/src/main/java/org/lineageos/backgrounds/ui/ApplyActivity.java +23 −0 Original line number Original line Diff line number Diff line Loading @@ -39,6 +39,7 @@ import org.lineageos.backgrounds.bundle.WallpaperBundle; import org.lineageos.backgrounds.task.ApplyWallpaperTask; import org.lineageos.backgrounds.task.ApplyWallpaperTask; import org.lineageos.backgrounds.task.LoadDrawableFromUriTask; import org.lineageos.backgrounds.task.LoadDrawableFromUriTask; import org.lineageos.backgrounds.util.ColorUtils; import org.lineageos.backgrounds.util.ColorUtils; import org.lineageos.backgrounds.util.TypeConverter; import org.lineageos.backgrounds.util.UiUtils; import org.lineageos.backgrounds.util.UiUtils; public final class ApplyActivity extends AppCompatActivity { public final class ApplyActivity extends AppCompatActivity { Loading Loading @@ -90,6 +91,9 @@ public final class ApplyActivity extends AppCompatActivity { case DEFAULT: case DEFAULT: setupDefault(); setupDefault(); break; break; case GRADIENT: setupGradient(wallpaperBundle); break; case MONO: case MONO: setupMono(wallpaperBundle); setupMono(wallpaperBundle); break; break; Loading Loading @@ -122,6 +126,25 @@ public final class ApplyActivity extends AppCompatActivity { displayPreview(drawable); displayPreview(drawable); } } private void setupGradient(@NonNull final WallpaperBundle bundle) { /* * Welcome to HackLand pt2: GradientDrawable doesn't play nicely with * shared element transitions, so we have to make some magic: * 1. Get the OG drawable * 2. Convert to a Bitmap * 3. Convert the Bitmap to a BitmapDrawable * 4. Apply the BitmapDrawable */ final Drawable origDrawable = ContextCompat.getDrawable(this, bundle.getDescriptor()); if (origDrawable == null) { return; } final Bitmap bm = TypeConverter.drawableToBitmap(origDrawable); final BitmapDrawable bmd = new BitmapDrawable(getResources(), bm); displayPreview(bmd); } private void setupUser(@Nullable final String wallpaperUri) { private void setupUser(@Nullable final String wallpaperUri) { if (wallpaperUri == null) { if (wallpaperUri == null) { finish(); finish(); Loading