Add lens shortcut in overview actions

This commit is contained in:
Suphon Thanakornpakapong
2021-10-18 12:06:07 +07:00
parent e05cdf2b6c
commit 3c571e77df
8 changed files with 232 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M6,2H18A4,4 0 0,1 22,6V12H20V6A2,2 0 0,0 18,4H6A2,2 0 0,0 4,6V18A2,2 0 0,0 6,20H12V22H6A4,4 0 0,1 2,18V6A4,4 0 0,1 6,2M12,8A4,4 0 0,1 16,12A4,4 0 0,1 12,16A4,4 0 0,1 8,12A4,4 0 0,1 12,8M18,16A2,2 0 0,1 20,18A2,2 0 0,1 18,20A2,2 0 0,1 16,18A2,2 0 0,1 18,16Z" />
</vector>

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2020 The Android Open Source 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.
-->
<!-- NOTE! don't add dimensions for margins / gravity to root view in this file, they need to be
loaded at runtime. -->
<app.lawnchair.overview.LawnchairOverviewActionsView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/action_buttons"
android:layout_width="match_parent"
android:layout_height="@dimen/overview_actions_height"
android:layout_gravity="bottom|center_horizontal"
android:orientation="horizontal">
<Space
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<app.lawnchair.views.CustomButton
android:id="@+id/action_screenshot"
style="@style/OverviewActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_screenshot"
android:text="@string/action_screenshot"
android:theme="@style/ThemeControlHighlightWorkspaceColor"
android:visibility="gone" />
<Space
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"
android:visibility="gone" />
<app.lawnchair.views.CustomButton
android:id="@+id/action_share"
style="@style/OverviewActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_share"
android:text="@string/action_share"
android:theme="@style/ThemeControlHighlightWorkspaceColor" />
<Space
android:id="@+id/oav_three_button_space"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<app.lawnchair.views.CustomButton
android:id="@+id/action_lens"
style="@style/OverviewActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_lens"
android:text="@string/action_lens"
android:theme="@style/ThemeControlHighlightWorkspaceColor" />
<Space
android:id="@+id/lens_space"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"
android:visibility="gone" />
<app.lawnchair.views.CustomButton
style="@style/OverviewActionButton"
android:id="@+id/action_clear_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/recents_clear_all"
android:theme="@style/ThemeControlHighlightWorkspaceColor"
android:drawableStart="@drawable/ic_clear_all_recents"
android:visibility="gone"
/>
<Space
android:id="@+id/clear_all_space"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
</app.lawnchair.overview.LawnchairOverviewActionsView>

View File

@@ -21,6 +21,8 @@
<string name="clock_component_name" translatable="false">com.google.android.deskclock/com.android.deskclock.DeskClock</string>
<string name="launcher_activity_logic_class" translatable="false">app.lawnchair.LauncherActivityCachingLogic</string>
<string name="task_overlay_factory_class" translatable="false">app.lawnchair.overview.TaskOverlayFactoryImpl</string>
<string-array name="filtered_components">
<!-- Voice search -->
<item>com.google.android.googlequicksearchbox/.VoiceSearchActivity</item>

View File

@@ -158,4 +158,5 @@
<string name="customize_button_text">Customize</string>
<string name="app_title_label">Title</string>
<string name="hide_from_drawer">Hide from Drawer</string>
<string name="action_lens">Lens</string>
</resources>

View File

@@ -0,0 +1,33 @@
package app.lawnchair.overview
import android.content.Context
import android.util.AttributeSet
import android.widget.Button
import android.widget.Space
import androidx.core.view.ViewCompat
import androidx.core.view.isVisible
import com.android.launcher3.R
import com.android.quickstep.views.OverviewActionsView
class LawnchairOverviewActionsView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : OverviewActionsView<TaskOverlayFactoryImpl.OverlayUICallbacks>(context, attrs, defStyleAttr) {
override fun onFinishInflate() {
super.onFinishInflate()
val lensIntent = context.packageManager.getLaunchIntentForPackage("com.google.ar.lens")
val lensAvailable = lensIntent != null
val lensButton = ViewCompat.requireViewById<Button>(this, R.id.action_lens)
lensButton.setOnClickListener {
mCallbacks?.onLens()
}
lensButton.isVisible = lensAvailable
val lensSpace = ViewCompat.requireViewById<Space>(this, R.id.lens_space)
lensSpace.isVisible = lensAvailable
}
}

View File

@@ -0,0 +1,60 @@
package app.lawnchair.overview
import android.content.Context
import android.graphics.Matrix
import androidx.annotation.Keep
import com.android.quickstep.TaskOverlayFactory
import com.android.quickstep.views.OverviewActionsView
import com.android.quickstep.views.TaskThumbnailView
import com.android.systemui.shared.recents.model.Task
import com.android.systemui.shared.recents.model.ThumbnailData
@Keep
class TaskOverlayFactoryImpl(@Suppress("UNUSED_PARAMETER") context: Context) : TaskOverlayFactory() {
override fun createOverlay(thumbnailView: TaskThumbnailView) = TaskOverlay(thumbnailView)
class TaskOverlay(
taskThumbnailView: TaskThumbnailView
) : TaskOverlayFactory.TaskOverlay<LawnchairOverviewActionsView>(taskThumbnailView) {
override fun initOverlay(
task: Task,
thumbnail: ThumbnailData?,
matrix: Matrix,
rotated: Boolean
) {
actionsView.updateDisabledFlags(
OverviewActionsView.DISABLED_NO_THUMBNAIL,
thumbnail == null
)
if (thumbnail != null) {
actionsView.updateDisabledFlags(OverviewActionsView.DISABLED_ROTATED, rotated)
val isAllowedByPolicy = mThumbnailView.isRealSnapshot
actionsView.setCallbacks(OverlayUICallbacksImpl(isAllowedByPolicy, task))
}
}
private inner class OverlayUICallbacksImpl(
isAllowedByPolicy: Boolean,
task: Task
) : TaskOverlayFactory.TaskOverlay<LawnchairOverviewActionsView>.OverlayUICallbacksImpl(
isAllowedByPolicy,
task
), OverlayUICallbacks {
override fun onLens() {
if (mIsAllowedByPolicy) {
endLiveTileMode { mImageApi.startLensActivity() }
} else {
showBlockedByPolicyMessage()
}
}
}
}
interface OverlayUICallbacks : TaskOverlayFactory.OverlayUICallbacks {
fun onLens()
}
}

View File

@@ -31,6 +31,7 @@ import android.graphics.Insets;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.Log;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
@@ -103,6 +104,11 @@ public class ImageActionsApi {
ImageActionUtils.startShareActivity(mContext, mBitmapSupplier, crop, null, TAG);
}
@UiThread
public void startLensActivity() {
ImageActionUtils.startLensActivity(mContext, mBitmapSupplier, null, null, TAG);
}
/**
* @param screenshot to be saved to the media store.
* @param screenshotBounds the location of where the bitmap was laid out on the screen in

View File

@@ -147,6 +147,19 @@ public class ImageActionUtils {
bitmapSupplier.get(), crop, intent, ImageActionUtils::getShareIntentForImageUri,
tag, sharedElement));
}
@UiThread
public static void startLensActivity(Context context, Supplier<Bitmap> bitmapSupplier,
Rect crop, Intent intent, String tag) {
if (bitmapSupplier.get() == null) {
Log.e(tag, "No snapshot available, not starting share.");
return;
}
UI_HELPER_EXECUTOR.execute(() -> persistBitmapAndStartActivity(context,
bitmapSupplier.get(), crop, intent, ImageActionUtils::getLensIntentForImageUri,
tag));
}
/**
* Starts activity based on given intent created from image uri.
@@ -272,6 +285,15 @@ public class ImageActionUtils {
.setClipData(clipdata);
return new Intent[]{Intent.createChooser(intent, null).addFlags(FLAG_ACTIVITY_NEW_TASK)};
}
@WorkerThread
private static Intent[] getLensIntentForImageUri(Uri uri, Intent intent) {
if (intent == null) {
intent = new Intent();
}
intent.setPackage("com.google.ar.lens");
return getShareIntentForImageUri(uri, intent);
}
private static void clearOldCacheFiles(Context context) {
THREAD_POOL_EXECUTOR.execute(() -> {