From 0ee5458c88e084ac44216b67b11b8f2e5f826684 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 18 Apr 2022 12:03:32 +0700 Subject: [PATCH 01/26] Update widgets style --- app/src/main/res/drawable/item_widget_round_corner.xml | 2 +- app/src/main/res/layout/layout_used_apps.xml | 6 ++---- app/src/main/res/layout/layout_weather_info.xml | 4 +--- app/src/main/res/values/colors.xml | 2 ++ app/src/main/res/values/strings.xml | 2 +- app/src/main/res/values/styles.xml | 6 ++++++ 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/res/drawable/item_widget_round_corner.xml b/app/src/main/res/drawable/item_widget_round_corner.xml index ff36e70083..91632ae6da 100644 --- a/app/src/main/res/drawable/item_widget_round_corner.xml +++ b/app/src/main/res/drawable/item_widget_round_corner.xml @@ -1,6 +1,6 @@ - + diff --git a/app/src/main/res/layout/layout_used_apps.xml b/app/src/main/res/layout/layout_used_apps.xml index 5b26e9678d..e997a99e74 100755 --- a/app/src/main/res/layout/layout_used_apps.xml +++ b/app/src/main/res/layout/layout_used_apps.xml @@ -4,22 +4,20 @@ android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginBottom="4dp" + android:background="@drawable/item_widget_round_corner" android:animateLayoutChanges="true" android:orientation="vertical"> + style="@style/WidgetTitle" /> + style="@style/WidgetTitle" /> #FFFFFF #0088ED + #4d666666 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d4a471c284..5cc01d9cdb 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,7 +3,7 @@ Search Untitled - APP SUGGESTIONS + Suggestions Enable appusage access to display app suggestions. diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index d25380ce2e..6c97d874d5 100755 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -32,4 +32,10 @@ normal @color/white + + -- GitLab From c61e8b4404b8a774bbcf33761e7331f94723785f Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 18 Apr 2022 12:03:40 +0700 Subject: [PATCH 02/26] Update widget edit button style --- app/src/main/res/drawable/btn_rounded_corner.xml | 4 ++-- app/src/main/res/layout/widgets_page.xml | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/drawable/btn_rounded_corner.xml b/app/src/main/res/drawable/btn_rounded_corner.xml index b1873d9568..e16069a9c2 100644 --- a/app/src/main/res/drawable/btn_rounded_corner.xml +++ b/app/src/main/res/drawable/btn_rounded_corner.xml @@ -3,8 +3,8 @@ android:color="@color/dark_grey"> - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/widgets_page.xml b/app/src/main/res/layout/widgets_page.xml index c1c6b7ad24..19ce2b08b5 100755 --- a/app/src/main/res/layout/widgets_page.xml +++ b/app/src/main/res/layout/widgets_page.xml @@ -39,10 +39,18 @@ android:id="@+id/edit_widgets_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="8dp" + android:layout_marginTop="20dp" android:layout_marginBottom="60dp" + android:minWidth="0dp" + android:minHeight="0dp" + android:paddingLeft="24dp" + android:paddingTop="5dp" + android:paddingRight="24dp" + android:paddingBottom="5dp" android:background="@drawable/btn_rounded_corner" android:fontFamily="sans-serif-medium" + android:textAllCaps="false" + android:textColor="#BD000000" android:text="@string/edit" /> -- GitLab From d601e949a8cf936b658a9282b767bcd32044f3b1 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 18 Apr 2022 12:12:29 +0700 Subject: [PATCH 03/26] Update search bar style --- app/src/main/res/drawable/ic_cancel_white_24dp.xml | 2 +- .../{ic_search_white_24dp.xml => ic_search_black_24dp.xml} | 2 +- app/src/main/res/drawable/search_widget.xml | 4 ++-- app/src/main/res/layout/layout_search_suggestion.xml | 6 ++++-- app/src/main/res/layout/layout_used_apps.xml | 2 +- app/src/main/res/values/colors.xml | 3 +++ 6 files changed, 12 insertions(+), 7 deletions(-) rename app/src/main/res/drawable/{ic_search_white_24dp.xml => ic_search_black_24dp.xml} (89%) diff --git a/app/src/main/res/drawable/ic_cancel_white_24dp.xml b/app/src/main/res/drawable/ic_cancel_white_24dp.xml index d1787e7332..e5edeabe17 100755 --- a/app/src/main/res/drawable/ic_cancel_white_24dp.xml +++ b/app/src/main/res/drawable/ic_cancel_white_24dp.xml @@ -1,4 +1,4 @@ - diff --git a/app/src/main/res/drawable/ic_search_white_24dp.xml b/app/src/main/res/drawable/ic_search_black_24dp.xml similarity index 89% rename from app/src/main/res/drawable/ic_search_white_24dp.xml rename to app/src/main/res/drawable/ic_search_black_24dp.xml index c927d3d226..2c5425454b 100755 --- a/app/src/main/res/drawable/ic_search_white_24dp.xml +++ b/app/src/main/res/drawable/ic_search_black_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/app/src/main/res/drawable/search_widget.xml b/app/src/main/res/drawable/search_widget.xml index a5fcf4ada9..48c355e3e2 100755 --- a/app/src/main/res/drawable/search_widget.xml +++ b/app/src/main/res/drawable/search_widget.xml @@ -3,8 +3,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> - + - + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_search_suggestion.xml b/app/src/main/res/layout/layout_search_suggestion.xml index f6c7213385..1e7987e237 100644 --- a/app/src/main/res/layout/layout_search_suggestion.xml +++ b/app/src/main/res/layout/layout_search_suggestion.xml @@ -18,12 +18,14 @@ android:layout_centerVertical="true" android:layout_toStartOf="@+id/clearSuggestionImageView" android:background="@android:color/transparent" - android:drawableStart="@drawable/ic_search_white_24dp" + android:drawableStart="@drawable/ic_search_black_24dp" android:drawablePadding="8dp" android:hint="@string/search" android:imeOptions="actionSearch" android:inputType="text" - android:maxLines="1" /> + android:maxLines="1" + android:textColor="@color/on_surface_high_emphasis" + android:textColorHint="@color/on_surface_high_emphasis" /> #0088ED #4d666666 + #a1f0f0f0 + + #de000000 -- GitLab From 7853744c3f2229c92c2f2df27173711a8851500a Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 18 Apr 2022 12:39:07 +0700 Subject: [PATCH 04/26] Make suggestions background cover autocomplete items --- .../features/launcher/LauncherActivity.java | 8 ---- .../drawable/ic_search_white_alpha_24dp.xml | 2 +- app/src/main/res/layout/item_suggestion.xml | 37 ++++++++++++------- .../res/layout/layout_search_suggestion.xml | 25 ++++++++----- app/src/main/res/layout/layout_used_apps.xml | 3 -- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java index 8ea1b4ccf6..5a04a43109 100755 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java @@ -1379,9 +1379,6 @@ public class LauncherActivity extends AppCompatActivity implements suggestionRecyclerView.setLayoutManager( new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); suggestionRecyclerView.setAdapter(suggestionAdapter); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, - DividerItemDecoration.VERTICAL); - suggestionRecyclerView.addItemDecoration(dividerItemDecoration); getCompositeDisposable().add(RxTextView.textChanges(mSearchInput) .debounce(300, TimeUnit.MILLISECONDS) .map(CharSequence::toString) @@ -3100,11 +3097,6 @@ public class LauncherActivity extends AppCompatActivity implements suggestionRecyclerView.setAdapter(networkSuggestionAdapter); suggestionRecyclerView.setLayoutManager( new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, - DividerItemDecoration.VERTICAL); - if (suggestionRecyclerView.getItemDecorationCount() == 0) { - suggestionRecyclerView.addItemDecoration(dividerItemDecoration); - } searchEditText.setOnFocusChangeListener((v, hasFocus) -> { if (!hasFocus) { diff --git a/app/src/main/res/drawable/ic_search_white_alpha_24dp.xml b/app/src/main/res/drawable/ic_search_white_alpha_24dp.xml index 6151c59852..15460dd808 100755 --- a/app/src/main/res/drawable/ic_search_white_alpha_24dp.xml +++ b/app/src/main/res/drawable/ic_search_white_alpha_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/app/src/main/res/layout/item_suggestion.xml b/app/src/main/res/layout/item_suggestion.xml index b63d812463..c308b59088 100755 --- a/app/src/main/res/layout/item_suggestion.xml +++ b/app/src/main/res/layout/item_suggestion.xml @@ -1,16 +1,27 @@ - \ No newline at end of file + android:orientation="vertical"> + + + + + diff --git a/app/src/main/res/layout/layout_search_suggestion.xml b/app/src/main/res/layout/layout_search_suggestion.xml index 1e7987e237..8304d6270c 100644 --- a/app/src/main/res/layout/layout_search_suggestion.xml +++ b/app/src/main/res/layout/layout_search_suggestion.xml @@ -37,17 +37,24 @@ android:visibility="gone" /> - - - + android:layout_marginTop="12dp" + android:layout_marginBottom="4dp" + android:background="@drawable/item_widget_round_corner" + android:orientation="vertical"> + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_used_apps.xml b/app/src/main/res/layout/layout_used_apps.xml index f29786f663..f49a7b91c2 100755 --- a/app/src/main/res/layout/layout_used_apps.xml +++ b/app/src/main/res/layout/layout_used_apps.xml @@ -2,9 +2,6 @@ -- GitLab From 067b0587b665886dfd480cff439fba4f4638d307 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 18 Apr 2022 13:03:56 +0700 Subject: [PATCH 05/26] Update folder background colors --- .../e/blisslauncher/core/utils/GraphicsUtil.java | 9 ++++++--- app/src/main/res/drawable/folder_window.xml | 4 ++-- app/src/main/res/values/colors.xml | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/core/utils/GraphicsUtil.java b/app/src/main/java/foundation/e/blisslauncher/core/utils/GraphicsUtil.java index 05296a8c57..305d123981 100755 --- a/app/src/main/java/foundation/e/blisslauncher/core/utils/GraphicsUtil.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/utils/GraphicsUtil.java @@ -29,19 +29,22 @@ import java.util.HashMap; import java.util.Map; import foundation.e.blisslauncher.BlissLauncher; +import foundation.e.blisslauncher.R; import foundation.e.blisslauncher.core.DeviceProfile; import foundation.e.blisslauncher.core.database.model.FolderItem; public class GraphicsUtil { private static final String TAG = "BLISS_GRAPHICS"; - private Context mContext; - private int appIconWidth; + private final Context mContext; + private final int appIconWidth; + private final int mFolderPreviewBackgroundColor; public GraphicsUtil(Context context) { this.mContext = context; DeviceProfile deviceProfile = BlissLauncher.getApplication(context).getDeviceProfile(); this.appIconWidth = deviceProfile.iconSizePx; + mFolderPreviewBackgroundColor = mContext.getColor(R.color.folder_preview_background_color); } /** @@ -129,7 +132,7 @@ public class GraphicsUtil { Bitmap mergedBitmap = Bitmap.createBitmap(width, height, Bitmap .Config.ARGB_8888); Canvas canvas = new Canvas(mergedBitmap); - canvas.drawColor(isFolder ? 0x88D3D3D3 : getDominantColor(bitmap)); + canvas.drawColor(isFolder ? mFolderPreviewBackgroundColor : getDominantColor(bitmap)); Paint paint = new Paint( Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG); diff --git a/app/src/main/res/drawable/folder_window.xml b/app/src/main/res/drawable/folder_window.xml index ca9e4d75f5..a6e5b64f1a 100755 --- a/app/src/main/res/drawable/folder_window.xml +++ b/app/src/main/res/drawable/folder_window.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> - - + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 63cfd9a3c3..5f73f0a248 100755 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -25,5 +25,6 @@ #a1f0f0f0 #de000000 + #4dcbcbcb -- GitLab From 1dfe97249eddcd5562feee3493c10446bdef61be Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 18 Apr 2022 13:09:31 +0700 Subject: [PATCH 06/26] Remove unused import --- .../e/blisslauncher/features/launcher/LauncherActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java index 5a04a43109..851e16d06a 100755 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java @@ -64,7 +64,6 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.view.GestureDetectorCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager.widget.PagerAdapter; -- GitLab From 1a2f399d428eb86de67f3ecd6901f60dcecfd735 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 18 Apr 2022 14:51:14 +0700 Subject: [PATCH 07/26] Override debug suffix and signing key with local props --- .gitignore | 1 + app/build.gradle | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 20ff14c5a3..ee30082981 100755 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,4 @@ lint/tmp/ #ktlint ktlint +keystore/platform.jks diff --git a/app/build.gradle b/app/build.gradle index 2488c2f29a..44138b180c 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,6 +11,17 @@ def versionMajor = 1 def versionMinor = 3 def versionPatch = 2 +Properties localProps = new Properties() +File localPropsFile = project.rootProject.file('local.properties') +if (localPropsFile.exists()) { + localProps.load(localPropsFile.newDataInputStream()) +} +def appendDebugSuffix = (localProps.getProperty('appendDebugSuffix') ?: "true").toBoolean() +def keyStorePath = localProps.getProperty('keyStorePath') ?: "/keystore/debug.keystore" +def keyStorePassword = localProps.getProperty('keyStorePassword') ?: "android" +def signingKeyAlias = localProps.getProperty('keyAlias') ?: "androiddebugkey" +def signingKeyPassword = localProps.getProperty('keyPassword') ?: "android" + android { compileSdkVersion Versions.compile_sdk defaultConfig { @@ -28,9 +39,12 @@ android { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.debug } debug { - applicationIdSuffix '.debug' + if (appendDebugSuffix) { + applicationIdSuffix '.debug' + } signingConfig signingConfigs.debug } @@ -46,10 +60,10 @@ android { signingConfigs { debug { - storeFile file(getRootDir().path + "/keystore/debug.keystore") - storePassword 'android' - keyAlias 'androiddebugkey' - keyPassword 'android' + storeFile file(getRootDir().path + keyStorePath) + storePassword keyStorePassword + keyAlias signingKeyAlias + keyPassword signingKeyPassword } } -- GitLab From 594b9ddd7e14c2c824bd44576603522615a6c1e2 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 18 Apr 2022 16:29:41 +0700 Subject: [PATCH 08/26] Add independent blur renderer for widget cards --- .../e/blisslauncher/core/blur/BlurDrawable.kt | 90 ++++++++++ .../core/blur/BlurViewDelegate.kt | 166 ++++++++++++++++++ .../core/blur/BlurWallpaperProvider.kt | 4 + .../core/customviews/BlurLayout.kt | 38 ++++ .../core/customviews/RoundedWidgetView.java | 20 ++- .../core/customviews/SwipeSearchContainer.kt | 36 ++++ .../core/customviews/WidgetHost.java | 2 +- .../blisslauncher/core/utils/OffsetParent.kt | 32 ++++ .../weather/WeatherWidgetHostView.java | 2 +- app/src/main/res/layout/activity_main.xml | 4 +- .../res/layout/layout_search_suggestion.xml | 89 ++++++---- app/src/main/res/layout/widgets_page.xml | 33 ++-- app/src/main/res/values/attrs.xml | 4 + 13 files changed, 463 insertions(+), 57 deletions(-) create mode 100644 app/src/main/java/foundation/e/blisslauncher/core/blur/BlurDrawable.kt create mode 100644 app/src/main/java/foundation/e/blisslauncher/core/blur/BlurViewDelegate.kt create mode 100644 app/src/main/java/foundation/e/blisslauncher/core/customviews/BlurLayout.kt create mode 100644 app/src/main/java/foundation/e/blisslauncher/core/customviews/SwipeSearchContainer.kt create mode 100644 app/src/main/java/foundation/e/blisslauncher/core/utils/OffsetParent.kt diff --git a/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurDrawable.kt b/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurDrawable.kt new file mode 100644 index 0000000000..4b7786d081 --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurDrawable.kt @@ -0,0 +1,90 @@ +package foundation.e.blisslauncher.core.blur + +import android.graphics.Bitmap +import android.graphics.BitmapShader +import android.graphics.Canvas +import android.graphics.ColorFilter +import android.graphics.Paint +import android.graphics.PixelFormat +import android.graphics.RectF +import android.graphics.Shader +import android.graphics.drawable.Drawable + +class BlurDrawable internal constructor(private val blurWallpaperProvider: BlurWallpaperProvider) : + Drawable(), BlurWallpaperProvider.Listener { + + private var blurAlpha = 255 + private val blurPaint = Paint(Paint.FILTER_BITMAP_FLAG or Paint.ANTI_ALIAS_FLAG) + private var blurBitmap: Bitmap? = null + set(value) { + if (field != value) { + field = value + blurPaint.shader = + value?.let { BitmapShader(it, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP) } + } + } + + private val blurBounds = RectF() + private var offsetX = 0f + private var offsetY = 0f + + override fun draw(canvas: Canvas) { + val width = blurBounds.right.toInt() - blurBounds.left.toInt() + val height = blurBounds.bottom.toInt() - blurBounds.top.toInt() + if (width <= 0 || height <= 0) return + if (blurAlpha == 0) return + blurBitmap = blurWallpaperProvider.wallpaper + + if (blurBitmap == null) { + blurBitmap = blurWallpaperProvider.placeholder + } + + val left = blurBounds.left + offsetX + val top = blurBounds.top + offsetY + val right = blurBounds.right + offsetX + val bottom = blurBounds.bottom + offsetY + canvas.translate(-left, -top) + canvas.drawRect(left, top, right, bottom, blurPaint) + canvas.translate(left, top) + } + + override fun setAlpha(alpha: Int) { + blurAlpha = alpha + blurPaint.alpha = alpha + } + + override fun getAlpha(): Int { + return blurAlpha + } + + override fun setBounds(left: Int, top: Int, right: Int, bottom: Int) = + setBlurBounds(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat()) + + fun setBlurBounds(left: Float, top: Float, right: Float, bottom: Float) { + if (blurBounds.left != left || + blurBounds.top != top || + blurBounds.right != right || + blurBounds.bottom != bottom + ) { + blurBounds.set(left, top, right, bottom) + } + } + + fun setOffsets(offsetX: Float, offsetY: Float) { + this.offsetX = offsetX + this.offsetY = offsetY + } + + override fun getOpacity(): Int = PixelFormat.TRANSLUCENT + + override fun onWallpaperChanged() { + invalidateSelf() + } + + override fun setColorFilter(colorFilter: ColorFilter?) { + } + + fun startListening() = blurWallpaperProvider.addListener(this) + + fun stopListening() = blurWallpaperProvider.removeListener(this) +} diff --git a/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurViewDelegate.kt b/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurViewDelegate.kt new file mode 100644 index 0000000000..eeb514d5e6 --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurViewDelegate.kt @@ -0,0 +1,166 @@ +package foundation.e.blisslauncher.core.blur + +import android.graphics.Canvas +import android.graphics.Outline +import android.graphics.drawable.Drawable +import android.view.View +import android.view.ViewOutlineProvider +import android.view.ViewTreeObserver +import android.widget.ScrollView +import foundation.e.blisslauncher.core.customviews.HorizontalPager +import foundation.e.blisslauncher.core.utils.OffsetParent + +class BlurViewDelegate(private val view: View) : View.OnAttachStateChangeListener, BlurWallpaperProvider.Listener { + + private val context = view.context + private val blurWallpaperProvider by lazy { BlurWallpaperProvider.getInstance(context) } + + private var fullBlurDrawable: BlurDrawable? = null + private var blurAlpha = 255 + + private val blurDrawableCallback by lazy { + object : Drawable.Callback { + override fun unscheduleDrawable(who: Drawable, what: Runnable) { + } + + override fun invalidateDrawable(who: Drawable) { + view.post(view::invalidate) + } + + override fun scheduleDrawable(who: Drawable, what: Runnable, `when`: Long) { + } + } + } + + private var offsetParents = listOf() + set(value) { + field.forEach { it.removeOnOffsetChangeListener(onOffsetChangeListener) } + field = value + field.forEach { it.addOnOffsetChangeListener(onOffsetChangeListener) } + } + private val scrollViews = mutableListOf() + private var isScrolling = false + private var previousScrollX = 0 + private var previousScrollY = 0 + private var offsetX = 0f + private var offsetY = 0f + + private val onGlobalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener { updateBounds() } + private val onScrollChangedListener = ViewTreeObserver.OnScrollChangedListener { + isScrolling = true + view.invalidate() + } + private val onOffsetChangeListener = object : OffsetParent.OnOffsetChangeListener { + override fun onOffsetChange() { + computeOffsets() + } + } + + var blurCornerRadius = 0f + val outlineProvider = object : ViewOutlineProvider() { + override fun getOutline(view: View, outline: Outline) { + outline.setRoundRect(0, 0, view.width, view.height, blurCornerRadius) + } + } + + init { + createFullBlurDrawable() + view.addOnAttachStateChangeListener(this) + } + + override fun onViewAttachedToWindow(v: View) { + BlurWallpaperProvider.getInstance(context).addListener(this) + fullBlurDrawable?.startListening() + view.viewTreeObserver.addOnGlobalLayoutListener(onGlobalLayoutListener) + view.viewTreeObserver.addOnScrollChangedListener(onScrollChangedListener) + onGlobalLayoutListener.onGlobalLayout() + } + + override fun onViewDetachedFromWindow(v: View) { + BlurWallpaperProvider.getInstance(context).removeListener(this) + fullBlurDrawable?.stopListening() + view.viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener) + view.viewTreeObserver.removeOnScrollChangedListener(onScrollChangedListener) + scrollViews.clear() + offsetParents = listOf() + } + + fun draw(canvas: Canvas) { + if (isScrolling) { + computeScrollOffset() + } + fullBlurDrawable?.apply { + alpha = blurAlpha + this.draw(canvas) + } + } + + private fun createFullBlurDrawable() { + fullBlurDrawable?.let { if (view.isAttachedToWindow) it.stopListening() } + fullBlurDrawable = blurWallpaperProvider.createBlurDrawable().apply { + callback = blurDrawableCallback + setBounds(view.left, view.top, view.right, view.bottom) + if (view.isAttachedToWindow) startListening() + } + } + + override fun onEnabledChanged() { + createFullBlurDrawable() + } + + private fun updateBounds() { + scrollViews.clear() + val offsetParents = mutableListOf() + var left = 0 + var top = 0 + var current: View? = view + while (current != null) { + left += current.left + top += current.top + if (current is ScrollView || current is HorizontalPager) { + scrollViews.add(current) + } else if (current is OffsetParent) { + offsetParents.add(current) + } + current = current.parent as? View + } + val right = left + view.width + val bottom = top + view.height + fullBlurDrawable?.setBlurBounds(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat()) + view.invalidate() + this.offsetParents = offsetParents + } + + private fun computeScrollOffset() { + var scrollX = 0 + var scrollY = 0 + scrollViews.forEach { + scrollX -= it.scrollX + scrollY -= it.scrollY + } + if (previousScrollX == scrollX && previousScrollY == scrollY) { + isScrolling = false + return + } + previousScrollX = scrollX + previousScrollY = scrollY + updateOffsets() + } + + private fun computeOffsets() { + var offsetX = 0f + var offsetY = 0f + offsetParents.forEach { + offsetX += it.offsetX + offsetY += it.offsetY + } + this.offsetX = offsetX + this.offsetY = offsetY + updateOffsets() + view.invalidate() + } + + private fun updateOffsets() { + fullBlurDrawable?.setOffsets(previousScrollX.toFloat() + offsetX, previousScrollY.toFloat() + offsetY) + } +} diff --git a/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurWallpaperProvider.kt b/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurWallpaperProvider.kt index 68b5f1ccc7..a812ce2d99 100644 --- a/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurWallpaperProvider.kt +++ b/app/src/main/java/foundation/e/blisslauncher/core/blur/BlurWallpaperProvider.kt @@ -213,6 +213,10 @@ class BlurWallpaperProvider(val context: Context) { return ShaderBlurDrawable(this) } + fun createBlurDrawable(): BlurDrawable { + return BlurDrawable(this) + } + interface Listener { fun onWallpaperChanged() {} fun onEnabledChanged() {} diff --git a/app/src/main/java/foundation/e/blisslauncher/core/customviews/BlurLayout.kt b/app/src/main/java/foundation/e/blisslauncher/core/customviews/BlurLayout.kt new file mode 100644 index 0000000000..a56c120be3 --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/core/customviews/BlurLayout.kt @@ -0,0 +1,38 @@ +package foundation.e.blisslauncher.core.customviews + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import android.view.WindowInsets +import android.widget.FrameLayout +import foundation.e.blisslauncher.R +import foundation.e.blisslauncher.core.blur.BlurViewDelegate +import foundation.e.blisslauncher.core.blur.BlurWallpaperProvider + +open class BlurLayout @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null +) : FrameLayout(context, attrs), Insettable, BlurWallpaperProvider.Listener { + + private val delegate = BlurViewDelegate(this) + + init { + setWillNotDraw(false) + clipToOutline = true + + val a = context.obtainStyledAttributes(attrs, R.styleable.BlurLayout) + delegate.blurCornerRadius = a.getDimension( + R.styleable.BlurLayout_blurCornerRadius, + 0f + ) + a.recycle() + + outlineProvider = delegate.outlineProvider + } + + override fun onDraw(canvas: Canvas) { + delegate.draw(canvas) + super.onDraw(canvas) + } + + override fun setInsets(insets: WindowInsets) {} +} diff --git a/app/src/main/java/foundation/e/blisslauncher/core/customviews/RoundedWidgetView.java b/app/src/main/java/foundation/e/blisslauncher/core/customviews/RoundedWidgetView.java index 101be1547f..f26bd450df 100644 --- a/app/src/main/java/foundation/e/blisslauncher/core/customviews/RoundedWidgetView.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/customviews/RoundedWidgetView.java @@ -15,6 +15,7 @@ import android.widget.ImageView; import androidx.annotation.Nullable; import foundation.e.blisslauncher.R; +import foundation.e.blisslauncher.core.blur.BlurViewDelegate; import foundation.e.blisslauncher.features.widgets.CheckLongPressHelper; public class RoundedWidgetView extends AppWidgetHostView { @@ -33,11 +34,20 @@ public class RoundedWidgetView extends AppWidgetHostView { private boolean activated = false; - public RoundedWidgetView(Context context) { + private BlurViewDelegate mBlurDelegate = null; + + public RoundedWidgetView(Context context, boolean blurBackground) { super(context); this.mContext = context; this.cornerRadius = context.getResources().getDimensionPixelSize(R.dimen.corner_radius); mLongPressHelper = new CheckLongPressHelper(this); + if (blurBackground) { + mBlurDelegate = new BlurViewDelegate(this); + mBlurDelegate.setBlurCornerRadius(cornerRadius); + setWillNotDraw(false); + setOutlineProvider(mBlurDelegate.getOutlineProvider()); + setClipToOutline(true); + } } @Override @@ -59,6 +69,14 @@ public class RoundedWidgetView extends AppWidgetHostView { canvas.restoreToCount(save); } + @Override + protected void onDraw(Canvas canvas) { + if (mBlurDelegate != null) { + mBlurDelegate.draw(canvas); + } + super.onDraw(canvas); + } + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.d(TAG, "onInterceptTouchEvent() called with: ev = [" + ev.getAction() + "]"); diff --git a/app/src/main/java/foundation/e/blisslauncher/core/customviews/SwipeSearchContainer.kt b/app/src/main/java/foundation/e/blisslauncher/core/customviews/SwipeSearchContainer.kt new file mode 100644 index 0000000000..de522e9dc3 --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/core/customviews/SwipeSearchContainer.kt @@ -0,0 +1,36 @@ +package foundation.e.blisslauncher.core.customviews + +import android.content.Context +import android.util.AttributeSet +import android.widget.FrameLayout +import foundation.e.blisslauncher.core.utils.OffsetParent + +class SwipeSearchContainer @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null +) : FrameLayout(context, attrs), OffsetParent { + + private val offsetParentDelegate = OffsetParent.OffsetParentDelegate() + + override val offsetX: Float + get() = translationX + override val offsetY: Float + get() = translationY + + override fun setTranslationX(translationX: Float) { + super.setTranslationX(translationX) + offsetParentDelegate.notifyOffsetChanged() + } + + override fun setTranslationY(translationY: Float) { + super.setTranslationY(translationY) + offsetParentDelegate.notifyOffsetChanged() + } + + override fun addOnOffsetChangeListener(listener: OffsetParent.OnOffsetChangeListener) { + offsetParentDelegate.addOnOffsetChangeListener(listener) + } + + override fun removeOnOffsetChangeListener(listener: OffsetParent.OnOffsetChangeListener) { + offsetParentDelegate.removeOnOffsetChangeListener(listener) + } +} diff --git a/app/src/main/java/foundation/e/blisslauncher/core/customviews/WidgetHost.java b/app/src/main/java/foundation/e/blisslauncher/core/customviews/WidgetHost.java index 50c4f2725b..c7f0521b88 100644 --- a/app/src/main/java/foundation/e/blisslauncher/core/customviews/WidgetHost.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/customviews/WidgetHost.java @@ -19,7 +19,7 @@ public class WidgetHost extends AppWidgetHost { if (appWidget.provider.equals(WeatherAppWidgetProvider.COMPONENT_NAME)) { return new WeatherWidgetHostView(context); } - return new RoundedWidgetView(context); + return new RoundedWidgetView(context, false); } @Override diff --git a/app/src/main/java/foundation/e/blisslauncher/core/utils/OffsetParent.kt b/app/src/main/java/foundation/e/blisslauncher/core/utils/OffsetParent.kt new file mode 100644 index 0000000000..9aa08172e4 --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/core/utils/OffsetParent.kt @@ -0,0 +1,32 @@ +package foundation.e.blisslauncher.core.utils + +import java.util.concurrent.CopyOnWriteArrayList + +interface OffsetParent { + + val offsetX: Float + val offsetY: Float + + fun addOnOffsetChangeListener(listener: OnOffsetChangeListener) + fun removeOnOffsetChangeListener(listener: OnOffsetChangeListener) + + interface OnOffsetChangeListener { + fun onOffsetChange() + } + + class OffsetParentDelegate() { + private val listeners = CopyOnWriteArrayList() + + fun notifyOffsetChanged() { + listeners.forEach { it.onOffsetChange() } + } + + fun addOnOffsetChangeListener(listener: OnOffsetChangeListener) { + listeners.add(listener) + } + + fun removeOnOffsetChangeListener(listener: OnOffsetChangeListener) { + listeners.remove(listener) + } + } +} diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherWidgetHostView.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherWidgetHostView.java index 75987443bf..4dcbdd6721 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherWidgetHostView.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherWidgetHostView.java @@ -10,7 +10,7 @@ import foundation.e.blisslauncher.core.customviews.RoundedWidgetView; public class WeatherWidgetHostView extends RoundedWidgetView { public WeatherWidgetHostView(Context context) { - super(context); + super(context, true); LayoutInflater.from(context).inflate(R.layout.layout_weather_info, this); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e7533658f8..5eaf753db4 100755 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -88,7 +88,7 @@ - - + - + app:blurCornerRadius="100dp"> - - - - + android:background="@drawable/search_widget" + android:focusableInTouchMode="true" + android:padding="8dp"> + + - + + + + - - + app:blurCornerRadius="12dp"> - - + android:background="@drawable/item_widget_round_corner" + android:orientation="vertical"> + - \ No newline at end of file + + + + diff --git a/app/src/main/res/layout/widgets_page.xml b/app/src/main/res/layout/widgets_page.xml index 19ce2b08b5..e9c61aae72 100755 --- a/app/src/main/res/layout/widgets_page.xml +++ b/app/src/main/res/layout/widgets_page.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto" android:animateLayoutChanges="true"> -