forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🛃 Move Custom Tabs example into Chromium.
This CL moves the custom_tabs_client_example_apk target into the Chromium repo. This means that we can remove the third_party/custom_tabs_client dependency. While moving the custom_tabs_client_example_apk target, it was updated to depend on androidx.browser instead of the Android Support Library. Support for browser actions was also removed as Chrome discontinued support that feature half a year ago. Bug: 980567 Change-Id: I716658d3407ef28630dea94d75e9f672eca797d2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2120724 Auto-Submit: Peter Conn <peconn@chromium.org> Reviewed-by: Dominick Ng <dominickn@chromium.org> Reviewed-by: Theresa <twellington@chromium.org> Reviewed-by: Peter Conn <peconn@chromium.org> Reviewed-by: Andrew Grieve <agrieve@chromium.org> Reviewed-by: Yaron Friedman <yfriedman@chromium.org> Commit-Queue: Peter Conn <peconn@chromium.org> Cr-Commit-Position: refs/heads/master@{#756593}
- Loading branch information
Peter E Conn
authored and
Commit Bot
committed
Apr 6, 2020
1 parent
5f59f88
commit d7a0142
Showing
55 changed files
with
1,071 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
chrome/browser/android/examples/custom_tabs_client/BUILD.gn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2015 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//build/config/android/rules.gni") | ||
|
||
android_resources("chrome_tabs_client_example_apk_resources") { | ||
sources = [ | ||
"src/res/anim/slide_in_left.xml", | ||
"src/res/anim/slide_in_right.xml", | ||
"src/res/anim/slide_out_left.xml", | ||
"src/res/anim/slide_out_right.xml", | ||
"src/res/drawable-hdpi/ic_arrow_back.png", | ||
"src/res/drawable-hdpi/ic_launcher.png", | ||
"src/res/drawable-hdpi/ic_notification_icon.png", | ||
"src/res/drawable-hdpi/ic_play.png", | ||
"src/res/drawable-hdpi/ic_share.png", | ||
"src/res/drawable-hdpi/ic_stop.png", | ||
"src/res/drawable-mdpi/ic_arrow_back.png", | ||
"src/res/drawable-mdpi/ic_launcher.png", | ||
"src/res/drawable-mdpi/ic_notification_icon.png", | ||
"src/res/drawable-mdpi/ic_play.png", | ||
"src/res/drawable-mdpi/ic_share.png", | ||
"src/res/drawable-mdpi/ic_stop.png", | ||
"src/res/drawable-xhdpi/ic_arrow_back.png", | ||
"src/res/drawable-xhdpi/ic_launcher.png", | ||
"src/res/drawable-xhdpi/ic_notification_icon.png", | ||
"src/res/drawable-xhdpi/ic_play.png", | ||
"src/res/drawable-xhdpi/ic_share.png", | ||
"src/res/drawable-xhdpi/ic_stop.png", | ||
"src/res/drawable-xxhdpi/cover.jpg", | ||
"src/res/drawable-xxhdpi/ic_arrow_back.png", | ||
"src/res/drawable-xxhdpi/ic_launcher.png", | ||
"src/res/drawable-xxhdpi/ic_notification_icon.png", | ||
"src/res/drawable-xxhdpi/ic_play.png", | ||
"src/res/drawable-xxhdpi/ic_share.png", | ||
"src/res/drawable-xxhdpi/ic_stop.png", | ||
"src/res/drawable-xxxhdpi/ic_arrow_back.png", | ||
"src/res/drawable-xxxhdpi/ic_launcher.png", | ||
"src/res/drawable-xxxhdpi/ic_share.png", | ||
"src/res/layout/main.xml", | ||
"src/res/layout/remote_view.xml", | ||
"src/res/raw/amazing_grace.mp3", | ||
"src/res/values/strings.xml", | ||
] | ||
android_manifest = "src/AndroidManifest.xml" | ||
custom_package = "org.chromium.customtabsclient" | ||
deps = [ "//third_party/android_deps:android_support_v7_appcompat_java" ] | ||
} | ||
|
||
android_apk("custom_tabs_client_example_apk") { | ||
sources = [ | ||
"src/java/org/chromium/customtabsclient/BottomBarManager.java", | ||
"src/java/org/chromium/customtabsclient/BrowserActionsReceiver.java", | ||
"src/java/org/chromium/customtabsclient/MainActivity.java", | ||
"src/java/org/chromium/customtabsclient/SessionHelper.java", | ||
"src/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java", | ||
"src/java/org/chromium/customtabsclient/shared/KeepAliveService.java", | ||
"src/java/org/chromium/customtabsclient/shared/ServiceConnection.java", | ||
"src/java/org/chromium/customtabsclient/shared/ServiceConnectionCallback.java", | ||
] | ||
|
||
android_manifest = "src/AndroidManifest.xml" | ||
min_sdk_version = 19 | ||
target_sdk_version = 21 | ||
apk_name = "CustomTabsClientExample" | ||
|
||
deps = [ | ||
":chrome_tabs_client_example_apk_resources", | ||
"//third_party/android_deps:android_support_v7_appcompat_java", | ||
"//third_party/android_deps:androidx_annotation_annotation_java", | ||
"//third_party/android_deps:androidx_appcompat_appcompat_java", | ||
"//third_party/android_deps:androidx_lifecycle_lifecycle_common_java", | ||
"//third_party/android_sdk/androidx_browser:androidx_browser_java", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
file://chrome/android/java/src/org/chromium/chrome/browser/customtabs/OWNERS | ||
|
||
# COMPONENT: UI>Browser>Mobile>CustomTabs | ||
# OS: Android |
72 changes: 72 additions & 0 deletions
72
chrome/browser/android/examples/custom_tabs_client/src/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2015 Google Inc. All Rights Reserved. | ||
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. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.chromium.customtabsclient" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk | ||
android:minSdkVersion="19" | ||
android:targetSdkVersion="21" /> | ||
|
||
<application | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" | ||
android:allowBackup="false" | ||
android:theme="@style/Theme.AppCompat.Light" > | ||
|
||
<activity | ||
android:name="org.chromium.customtabsclient.MainActivity" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
|
||
<intent-filter> | ||
<action android:name="android.intent.action.VIEW"/> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
<category android:name="android.intent.category.BROWSABLE"/> | ||
<data android:scheme="https" | ||
android:host="www.example.com" | ||
android:pathPrefix="/notifications"/> | ||
</intent-filter> | ||
|
||
</activity> | ||
<service | ||
android:name=".shared.KeepAliveService" | ||
android:exported="true"/> | ||
<receiver | ||
android:name="org.chromium.customtabsclient.BrowserActionsReceiver" | ||
android:exported="true"/> | ||
<receiver android:name=".BottomBarManager"/> | ||
|
||
|
||
<service | ||
android:name="android.support.customtabs.trusted.TrustedWebActivityService" | ||
android:enabled="true" | ||
android:exported="true"> | ||
|
||
<meta-data android:name="android.support.customtabs.trusted.SMALL_ICON" | ||
android:resource="@drawable/ic_notification_icon" /> | ||
|
||
<intent-filter> | ||
<action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE"/> | ||
<category android:name="android.intent.category.DEFAULT"/> | ||
</intent-filter> | ||
</service> | ||
</application> | ||
</manifest> |
86 changes: 86 additions & 0 deletions
86
.../examples/custom_tabs_client/src/java/org/chromium/customtabsclient/BottomBarManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.customtabsclient; | ||
|
||
import android.app.PendingIntent; | ||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.media.MediaPlayer; | ||
import android.widget.RemoteViews; | ||
import android.widget.Toast; | ||
|
||
import androidx.browser.customtabs.CustomTabsIntent; | ||
import androidx.browser.customtabs.CustomTabsSession; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
/** | ||
* A {@link BroadcastReceiver} that manages the interaction with the active Custom Tab. | ||
*/ | ||
public class BottomBarManager extends BroadcastReceiver { | ||
private static WeakReference<MediaPlayer> sMediaPlayerWeakRef; | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
int clickedId = intent.getIntExtra(CustomTabsIntent.EXTRA_REMOTEVIEWS_CLICKED_ID, -1); | ||
Toast.makeText(context, "Current URL " + intent.getDataString() + "\nClicked id " | ||
+ clickedId, Toast.LENGTH_SHORT).show(); | ||
|
||
CustomTabsSession session = SessionHelper.getCurrentSession(); | ||
if (session == null) return; | ||
|
||
if (clickedId == R.id.play_pause) { | ||
MediaPlayer player = sMediaPlayerWeakRef.get(); | ||
if (player != null) { | ||
boolean isPlaying = player.isPlaying(); | ||
if (isPlaying) player.pause(); | ||
else player.start(); | ||
// Update the play/stop icon to respect the current state. | ||
session.setSecondaryToolbarViews(createRemoteViews(context, isPlaying), | ||
getClickableIDs(), getOnClickPendingIntent(context)); | ||
} | ||
} else if (clickedId == R.id.cover) { | ||
// Clicking on the cover image will dismiss the bottom bar. | ||
session.setSecondaryToolbarViews(null, null, null); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a RemoteViews that will be shown as the bottom bar of the custom tab. | ||
* @param showPlayIcon If true, a play icon will be shown, otherwise show a pause icon. | ||
* @return The created RemoteViews instance. | ||
*/ | ||
public static RemoteViews createRemoteViews(Context context, boolean showPlayIcon) { | ||
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.remote_view); | ||
|
||
int iconRes = showPlayIcon ? R.drawable.ic_play : R.drawable.ic_stop; | ||
remoteViews.setImageViewResource(R.id.play_pause, iconRes); | ||
return remoteViews; | ||
} | ||
|
||
/** | ||
* @return A list of View ids, the onClick event of which is handled by Custom Tab. | ||
*/ | ||
public static int[] getClickableIDs() { | ||
return new int[]{R.id.play_pause, R.id.cover}; | ||
} | ||
|
||
/** | ||
* @return The PendingIntent that will be triggered when the user clicks on the Views listed by | ||
* {@link BottomBarManager#getClickableIDs()}. | ||
*/ | ||
public static PendingIntent getOnClickPendingIntent(Context context) { | ||
Intent broadcastIntent = new Intent(context, BottomBarManager.class); | ||
return PendingIntent.getBroadcast(context, 0, broadcastIntent, 0); | ||
} | ||
|
||
/** | ||
* Sets the {@link MediaPlayer} to be used when the user clicks on the RemoteViews. | ||
*/ | ||
public static void setMediaPlayer(MediaPlayer player) { | ||
sMediaPlayerWeakRef = new WeakReference<>(player); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...les/custom_tabs_client/src/java/org/chromium/customtabsclient/BrowserActionsReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.customtabsclient; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.widget.Toast; | ||
|
||
/** | ||
* A {@link BroadcastReceiver} that handles the callback if default menu items are chosen from | ||
* Browser Actions. | ||
*/ | ||
public class BrowserActionsReceiver extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
String toastMsg = "Chosen item Id: " + intent.getDataString(); | ||
Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show(); | ||
} | ||
} |
Oops, something went wrong.