summaryrefslogtreecommitdiff
path: root/java/src/com
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2023-01-31 19:36:27 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-01-31 19:36:27 +0000
commitd250d1dabc19f0ec5bdddd11bb1caa04bdcbe3d7 (patch)
treef5b0f9503ad91845553bc5b396f7c77c2e8ab006 /java/src/com
parent87b60f339678674d5986e19cb084a1f9201ad2f2 (diff)
parentce9a21b2540f14478d326875f13b4156327f1fe4 (diff)
Merge "A simple UI for Image + Text sharing" into tm-qpr-dev
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/android/intentresolver/ChooserContentPreviewUi.java23
-rw-r--r--java/src/com/android/intentresolver/HttpUriMatcher.kt29
-rw-r--r--java/src/com/android/intentresolver/flags/Flags.kt6
3 files changed, 57 insertions, 1 deletions
diff --git a/java/src/com/android/intentresolver/ChooserContentPreviewUi.java b/java/src/com/android/intentresolver/ChooserContentPreviewUi.java
index 26c08e36..553a36c6 100644
--- a/java/src/com/android/intentresolver/ChooserContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/ChooserContentPreviewUi.java
@@ -32,6 +32,7 @@ import android.provider.DocumentsContract;
import android.provider.Downloads;
import android.provider.OpenableColumns;
import android.text.TextUtils;
+import android.text.util.Linkify;
import android.util.Log;
import android.util.PluralsMessageFormatter;
import android.view.LayoutInflater;
@@ -350,7 +351,7 @@ public final class ChooserContentPreviewUi {
return actions;
}
- private static ViewGroup displayImageContentPreview(
+ private ViewGroup displayImageContentPreview(
Intent targetIntent,
LayoutInflater layoutInflater,
List<ActionRow.Action> actions,
@@ -389,12 +390,32 @@ public final class ChooserContentPreviewUi {
return contentPreviewLayout;
}
+ setTextInImagePreviewVisibility(
+ contentPreviewLayout,
+ targetIntent.getCharSequenceExtra(Intent.EXTRA_TEXT));
imagePreview.setTransitionElementStatusCallback(transitionElementStatusCallback);
imagePreview.setImages(imageUris, imageLoader);
return contentPreviewLayout;
}
+ private void setTextInImagePreviewVisibility(
+ ViewGroup contentPreview, CharSequence text) {
+ int visibility = mFeatureFlagRepository.isEnabled(Flags.SHARESHEET_IMAGE_AND_TEXT_PREVIEW)
+ && !TextUtils.isEmpty(text)
+ ? View.VISIBLE
+ : View.GONE;
+
+ TextView textView = contentPreview
+ .requireViewById(com.android.internal.R.id.content_preview_text);
+ textView.setVisibility(visibility);
+ int linkMask = visibility == View.VISIBLE && HttpUriMatcher.isHttpUri(text.toString())
+ ? Linkify.WEB_URLS
+ : 0;
+ textView.setAutoLinkMask(linkMask);
+ textView.setText(text);
+ }
+
private static List<ActionRow.Action> createImagePreviewActions(
ActionFactory buttonFactory) {
ArrayList<ActionRow.Action> actions = new ArrayList<>(2);
diff --git a/java/src/com/android/intentresolver/HttpUriMatcher.kt b/java/src/com/android/intentresolver/HttpUriMatcher.kt
new file mode 100644
index 00000000..0f59df2b
--- /dev/null
+++ b/java/src/com/android/intentresolver/HttpUriMatcher.kt
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+@file:JvmName("HttpUriMatcher")
+package com.android.intentresolver
+
+import com.android.internal.annotations.VisibleForTesting
+import java.net.URI
+
+@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
+fun String.isHttpUri() =
+ kotlin.runCatching {
+ URI(this).scheme.takeIf { scheme ->
+ "http".compareTo(scheme, true) == 0 || "https".compareTo(scheme, true) == 0
+ }
+ }.getOrNull() != null \ No newline at end of file
diff --git a/java/src/com/android/intentresolver/flags/Flags.kt b/java/src/com/android/intentresolver/flags/Flags.kt
index 6962b1c3..92ee5115 100644
--- a/java/src/com/android/intentresolver/flags/Flags.kt
+++ b/java/src/com/android/intentresolver/flags/Flags.kt
@@ -29,6 +29,12 @@ object Flags {
@JvmField
val SHARESHEET_RESELECTION_ACTION = unreleasedFlag(1502, "sharesheet_reselection_action")
+ // TODO(b/266983474) Tracking Bug
+ @JvmField
+ val SHARESHEET_IMAGE_AND_TEXT_PREVIEW = unreleasedFlag(
+ id = 1503, name = "sharesheet_image_text_preview"
+ )
+
private fun unreleasedFlag(id: Int, name: String, teamfood: Boolean = false) =
UnreleasedFlag(id, name, "systemui", teamfood)
}