From b1770331f8b2c2971d3307189a671935d88a7826 Mon Sep 17 00:00:00 2001 From: NekoInverter <7741672-nekoinverter@users.noreply.gitlab.com> Date: Thu, 7 Jan 2021 15:25:06 +0800 Subject: [PATCH] Make custom tabs follow app theme --- TMessagesProj/build.gradle | 5 +- .../telegram/messenger/browser/Browser.java | 26 +- .../customtabs/CustomTabsCallback.java | 100 ---- .../support/customtabs/CustomTabsClient.java | 245 -------- .../support/customtabs/CustomTabsIntent.java | 566 ------------------ .../support/customtabs/CustomTabsService.java | 271 --------- .../CustomTabsServiceConnection.java | 45 -- .../support/customtabs/CustomTabsSession.java | 204 ------- .../customtabs/CustomTabsSessionToken.java | 150 ----- .../customtabs/ICustomTabsCallback.java | 226 ------- .../customtabs/ICustomTabsService.java | 377 ------------ .../customtabs/IPostMessageService.java | 155 ----- .../customtabs/PostMessageService.java | 40 -- .../PostMessageServiceConnection.java | 118 ---- .../shared/ServiceConnection.java | 4 +- .../shared/ServiceConnectionCallback.java | 2 +- 16 files changed, 25 insertions(+), 2509 deletions(-) delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsCallback.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsClient.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsIntent.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsService.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsServiceConnection.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsSession.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsSessionToken.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/ICustomTabsCallback.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/ICustomTabsService.java delete mode 100644 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/IPostMessageService.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/PostMessageService.java delete mode 100755 TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/PostMessageServiceConnection.java diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 538ff18b9..af3eeb03e 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -51,6 +51,7 @@ repositories { dependencies { + implementation "androidx.browser:browser:1.3.0" implementation 'androidx.core:core-ktx:1.5.0-alpha05' implementation 'androidx.palette:palette-ktx:1.0.0' implementation 'androidx.viewpager:viewpager:1.0.0' @@ -341,8 +342,8 @@ android { if (set.name.matches("(mini|full).*")) { if (set.name.contains("Apple")) { set.assets.srcDirs = ["src/main/assets", "src/emojis/apple"] - /*} else if (set.name.contains("Twitter")) { - set.assets.srcDirs = ["src/main/assets", "src/emojis/twitter"]*/ + /*} else if (set.name.contains("Twitter")) { + set.assets.srcDirs = ["src/main/assets", "src/emojis/twitter"]*/ } else { set.assets.srcDirs = ["src/main/assets", "src/emojis/twitter"] } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java index c5018990f..5f1a83cc3 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java @@ -19,6 +19,13 @@ import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; +import androidx.browser.customtabs.CustomTabColorSchemeParams; +import androidx.browser.customtabs.CustomTabsCallback; +import androidx.browser.customtabs.CustomTabsClient; +import androidx.browser.customtabs.CustomTabsIntent; +import androidx.browser.customtabs.CustomTabsServiceConnection; +import androidx.browser.customtabs.CustomTabsSession; + import org.telegram.messenger.AndroidUtilities; import org.telegram.messenger.ApplicationLoader; import org.telegram.messenger.BuildVars; @@ -30,11 +37,6 @@ import org.telegram.messenger.R; import org.telegram.messenger.ShareBroadcastReceiver; import org.telegram.messenger.SharedConfig; import org.telegram.messenger.UserConfig; -import org.telegram.messenger.support.customtabs.CustomTabsCallback; -import org.telegram.messenger.support.customtabs.CustomTabsClient; -import org.telegram.messenger.support.customtabs.CustomTabsIntent; -import org.telegram.messenger.support.customtabs.CustomTabsServiceConnection; -import org.telegram.messenger.support.customtabs.CustomTabsSession; import org.telegram.messenger.support.customtabsclient.shared.CustomTabsHelper; import org.telegram.messenger.support.customtabsclient.shared.ServiceConnection; import org.telegram.messenger.support.customtabsclient.shared.ServiceConnectionCallback; @@ -295,11 +297,21 @@ public class Browser { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getSession()); builder.addMenuItem(LocaleController.getString("CopyLink", R.string.CopyLink), copy); - builder.setToolbarColor(Theme.getColor(Theme.key_actionBarBrowser)); + boolean dark = false; + if (Theme.getActiveTheme().isDark()) { + dark = true; + } else if (AndroidUtilities.computePerceivedBrightness(Theme.getColor(Theme.key_windowBackgroundWhite)) < 0.721f) { + dark = true; + } + builder.setColorScheme(dark ? CustomTabsIntent.COLOR_SCHEME_DARK : CustomTabsIntent.COLOR_SCHEME_LIGHT); + CustomTabColorSchemeParams params = new CustomTabColorSchemeParams.Builder() + .setToolbarColor(Theme.getColor(Theme.key_actionBarBrowser)) + .build(); + builder.setDefaultColorSchemeParams(params); builder.setShowTitle(true); builder.setActionButton(BitmapFactory.decodeResource(context.getResources(), R.drawable.abc_ic_menu_share_mtrl_alpha), LocaleController.getString("ShareFile", R.string.ShareFile), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, share, 0), true); CustomTabsIntent intent = builder.build(); - intent.setUseNewTask(); + intent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.launchUrl(context, uri); return; } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsCallback.java b/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsCallback.java deleted file mode 100755 index 80cc01eb8..000000000 --- a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsCallback.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2015 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. - */ - -package org.telegram.messenger.support.customtabs; - -import android.os.Bundle; - -/** - * A callback class for custom tabs client to get messages regarding events in their custom tabs. - */ -public class CustomTabsCallback { - /** - * Sent when the tab has started loading a page. - */ - public static final int NAVIGATION_STARTED = 1; - - /** - * Sent when the tab has finished loading a page. - */ - public static final int NAVIGATION_FINISHED = 2; - - /** - * Sent when the tab couldn't finish loading due to a failure. - */ - public static final int NAVIGATION_FAILED = 3; - - /** - * Sent when loading was aborted by a user action before it finishes like clicking on a link - * or refreshing the page. - */ - public static final int NAVIGATION_ABORTED = 4; - - /** - * Sent when the tab becomes visible. - */ - public static final int TAB_SHOWN = 5; - - /** - * Sent when the tab becomes hidden. - */ - public static final int TAB_HIDDEN = 6; - - /** - * To be called when a navigation event happens. - * - * @param navigationEvent The code corresponding to the navigation event. - * @param extras Reserved for future use. - */ - public void onNavigationEvent(int navigationEvent, Bundle extras) {} - - /** - * Unsupported callbacks that may be provided by the implementation. - * - *
- * Note:Clients should never rely on this callback to be - * called and/or to have a defined behavior, as it is entirely implementation-defined and not - * supported. - * - *
This can be used by implementations to add extra callbacks, for testing or experimental
- * purposes.
- *
- * @param callbackName Name of the extra callback.
- * @param args Arguments for the calback
- */
- public void extraCallback(String callbackName, Bundle args) {}
-
- /**
- * Called when {@link CustomTabsSession} has requested a postMessage channel through
- * {@link CustomTabsService#requestPostMessageChannel(
- * CustomTabsSessionToken, android.net.Uri)} and the channel
- * is ready for sending and receiving messages on both ends.
- *
- * @param extras Reserved for future use.
- */
- public void onMessageChannelReady(Bundle extras) {}
-
- /**
- * Called when a tab controlled by this {@link CustomTabsSession} has sent a postMessage.
- * If postMessage() is called from a single thread, then the messages will be posted in the
- * same order. When received on the client side, it is the client's responsibility to preserve
- * the ordering further.
- *
- * @param message The message sent.
- * @param extras Reserved for future use.
- */
- public void onPostMessage(String message, Bundle extras) {}
-}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsClient.java b/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsClient.java
deleted file mode 100755
index 666c0a2b1..000000000
--- a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsClient.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-package org.telegram.messenger.support.customtabs;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.RemoteException;
-import androidx.annotation.Nullable;
-import android.text.TextUtils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class CustomTabsClient {
- private final ICustomTabsService mService;
- private final ComponentName mServiceComponentName;
-
- CustomTabsClient(ICustomTabsService service, ComponentName componentName) {
- mService = service;
- mServiceComponentName = componentName;
- }
-
- /**
- * Bind to a {@link CustomTabsService} using the given package name and
- * {@link ServiceConnection}.
- * @param context {@link Context} to use while calling
- * {@link Context#bindService(Intent, ServiceConnection, int)}
- * @param packageName Package name to set on the {@link Intent} for binding.
- * @param connection {@link CustomTabsServiceConnection} to use when binding. This will
- * return a {@link CustomTabsClient} on
- * {@link CustomTabsServiceConnection
- * #onCustomTabsServiceConnected(ComponentName, CustomTabsClient)}
- * @return Whether the binding was successful.
- */
- public static boolean bindCustomTabsService(Context context,
- String packageName, CustomTabsServiceConnection connection) {
- Intent intent = new Intent(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
- if (!TextUtils.isEmpty(packageName)) intent.setPackage(packageName);
- return context.bindService(intent, connection,
- Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY);
- }
-
- /**
- * Returns the preferred package to use for Custom Tabs, preferring the default VIEW handler.
- *
- * @see #getPackageName(Context, List
- * Note: The constants below are public for the browser implementation's benefit.
- * You are strongly encouraged to use {@link CustomTabsIntent.Builder}.
- * If an application provides a mechanism for users to opt out of Custom Tabs, this extra should
- * be provided with {@link Intent#FLAG_ACTIVITY_NEW_TASK} to ensure the browser does not attempt
- * to trigger any Custom Tab-like experiences as a result of the VIEW intent.
- *
- * If this extra is present with {@link Intent#FLAG_ACTIVITY_NEW_TASK}, all Custom Tabs
- * customizations will be ignored.
- */
- private static final String EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS =
- "android.support.customtabs.extra.user_opt_out";
-
- /**
- * Extra used to match the session. This has to be included in the intent to open in
- * a custom tab. This is the same IBinder that gets passed to ICustomTabsService#newSession.
- * Null if there is no need to match any service side sessions with the intent.
- */
- public static final String EXTRA_SESSION = "android.support.customtabs.extra.SESSION";
-
- /**
- * Extra that changes the background color for the toolbar. colorRes is an int that specifies a
- * {@link Color}, not a resource id.
- */
- public static final String EXTRA_TOOLBAR_COLOR =
- "android.support.customtabs.extra.TOOLBAR_COLOR";
-
- /**
- * Boolean extra that enables the url bar to hide as the user scrolls down the page
- */
- public static final String EXTRA_ENABLE_URLBAR_HIDING =
- "android.support.customtabs.extra.ENABLE_URLBAR_HIDING";
-
- /**
- * Extra bitmap that specifies the icon of the back button on the toolbar. If the client chooses
- * not to customize it, a default close button will be used.
- */
- public static final String EXTRA_CLOSE_BUTTON_ICON =
- "android.support.customtabs.extra.CLOSE_BUTTON_ICON";
-
- /**
- * Extra (int) that specifies state for showing the page title. Default is {@link #NO_TITLE}.
- */
- public static final String EXTRA_TITLE_VISIBILITY_STATE =
- "android.support.customtabs.extra.TITLE_VISIBILITY";
-
- /**
- * Don't show any title. Shows only the domain.
- */
- public static final int NO_TITLE = 0;
-
- /**
- * Shows the page title and the domain.
- */
- public static final int SHOW_PAGE_TITLE = 1;
-
- /**
- * Bundle used for adding a custom action button to the custom tab toolbar. The client should
- * provide a description, an icon {@link Bitmap} and a {@link PendingIntent} for the button.
- * All three keys must be present.
- */
- public static final String EXTRA_ACTION_BUTTON_BUNDLE =
- "android.support.customtabs.extra.ACTION_BUTTON_BUNDLE";
-
- /**
- * List
- * Note that Custom Tabs will override the default onClick behavior of the listed {@link View}s.
- * If you do not care about the current url, you can safely ignore this extra and use
- * {@link RemoteViews#setOnClickPendingIntent(int, PendingIntent)} instead.
- * @see CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).
- */
- public static final String EXTRA_REMOTEVIEWS_VIEW_IDS =
- "android.support.customtabs.extra.EXTRA_REMOTEVIEWS_VIEW_IDS";
-
- /**
- * Extra that specifies the {@link PendingIntent} to be sent when the user clicks on the
- * {@link View}s that is listed by {@link #EXTRA_REMOTEVIEWS_VIEW_IDS}.
- *
- * Note when this {@link PendingIntent} is triggered, it will have the current url as data
- * field, also the id of the clicked {@link View}, specified by
- * {@link #EXTRA_REMOTEVIEWS_CLICKED_ID}.
- * @see CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).
- */
- public static final String EXTRA_REMOTEVIEWS_PENDINGINTENT =
- "android.support.customtabs.extra.EXTRA_REMOTEVIEWS_PENDINGINTENT";
-
- /**
- * Extra that specifies which {@link View} has been clicked. This extra will be put to the
- * {@link PendingIntent} sent from Custom Tabs when a view in the {@link RemoteViews} is clicked
- * @see CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).
- */
- public static final String EXTRA_REMOTEVIEWS_CLICKED_ID =
- "android.support.customtabs.extra.EXTRA_REMOTEVIEWS_CLICKED_ID";
-
- /**
- * Extra that specifies whether Instant Apps is enabled.
- */
- public static final String EXTRA_ENABLE_INSTANT_APPS =
- "android.support.customtabs.extra.EXTRA_ENABLE_INSTANT_APPS";
-
- /**
- * Key that specifies the unique ID for an action button. To make a button to show on the
- * toolbar, use {@link #TOOLBAR_ACTION_BUTTON_ID} as its ID.
- */
- public static final String KEY_ID = "android.support.customtabs.customaction.ID";
-
- /**
- * The ID allocated to the custom action button that is shown on the toolbar.
- */
- public static final int TOOLBAR_ACTION_BUTTON_ID = 0;
-
- /**
- * The maximum allowed number of toolbar items.
- */
- private static final int MAX_TOOLBAR_ITEMS = 5;
-
- /**
- * An {@link Intent} used to start the Custom Tabs Activity.
- */
- @NonNull public final Intent intent;
-
- /**
- * A {@link Bundle} containing the start animation for the Custom Tabs Activity.
- */
- @Nullable public final Bundle startAnimationBundle;
-
- /**
- * Convenience method to launch a Custom Tabs Activity.
- * @param context The source Context.
- * @param url The URL to load in the Custom Tab.
- */
- public void launchUrl(Context context, Uri url) {
- intent.setData(url);
- ContextCompat.startActivity(context, intent, startAnimationBundle);
- }
-
- private CustomTabsIntent(Intent intent, Bundle startAnimationBundle) {
- this.intent = intent;
- this.startAnimationBundle = startAnimationBundle;
- }
-
- /**
- * Builder class for {@link CustomTabsIntent} objects.
- */
- public static final class Builder {
- private final Intent mIntent = new Intent(Intent.ACTION_VIEW);
- private ArrayList
- * This is equivalent to calling
- * {@link CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent)}
- * with {@link #TOOLBAR_ACTION_BUTTON_ID} as id.
- *
- * @param icon The icon.
- * @param description The description for the button. To be used for accessibility.
- * @param pendingIntent pending intent delivered when the button is clicked.
- * @param shouldTint Whether the action button should be tinted.
- *
- * @see CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent)
- */
- public Builder setActionButton(@NonNull Bitmap icon, @NonNull String description,
- @NonNull PendingIntent pendingIntent, boolean shouldTint) {
- Bundle bundle = new Bundle();
- bundle.putInt(KEY_ID, TOOLBAR_ACTION_BUTTON_ID);
- bundle.putParcelable(KEY_ICON, icon);
- bundle.putString(KEY_DESCRIPTION, description);
- bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent);
- mIntent.putExtra(EXTRA_ACTION_BUTTON_BUNDLE, bundle);
- mIntent.putExtra(EXTRA_TINT_ACTION_BUTTON, shouldTint);
- return this;
- }
-
- /**
- * Sets the action button that is displayed in the Toolbar with default tinting behavior.
- *
- * @see CustomTabsIntent.Builder#setActionButton(
- * Bitmap, String, PendingIntent, boolean)
- */
- public Builder setActionButton(@NonNull Bitmap icon, @NonNull String description,
- @NonNull PendingIntent pendingIntent) {
- return setActionButton(icon, description, pendingIntent, false);
- }
-
- /**
- * Adds an action button to the custom tab. Multiple buttons can be added via this method.
- * If the given id equals {@link #TOOLBAR_ACTION_BUTTON_ID}, the button will be placed on
- * the toolbar; if the bitmap is too wide, it will be put to the bottom bar instead. If
- * the id is not {@link #TOOLBAR_ACTION_BUTTON_ID}, it will be directly put on secondary
- * toolbar. The maximum number of allowed toolbar items in a single intent is
- * {@link CustomTabsIntent#getMaxToolbarItems()}. Throws an
- * {@link IllegalStateException} when that number is exceeded per intent.
- *
- * @param id The unique id of the action button. This should be non-negative.
- * @param icon The icon.
- * @param description The description for the button. To be used for accessibility.
- * @param pendingIntent The pending intent delivered when the button is clicked.
- *
- * @see CustomTabsIntent#getMaxToolbarItems()
- * @deprecated Use
- * CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).
- */
- @Deprecated
- public Builder addToolbarItem(int id, @NonNull Bitmap icon, @NonNull String description,
- PendingIntent pendingIntent) throws IllegalStateException {
- if (mActionButtons == null) {
- mActionButtons = new ArrayList<>();
- }
- if (mActionButtons.size() >= MAX_TOOLBAR_ITEMS) {
- throw new IllegalStateException(
- "Exceeded maximum toolbar item count of " + MAX_TOOLBAR_ITEMS);
- }
- Bundle bundle = new Bundle();
- bundle.putInt(KEY_ID, id);
- bundle.putParcelable(KEY_ICON, icon);
- bundle.putString(KEY_DESCRIPTION, description);
- bundle.putParcelable(KEY_PENDING_INTENT, pendingIntent);
- mActionButtons.add(bundle);
- return this;
- }
-
- /**
- * Sets the color of the secondary toolbar.
- * @param color The color for the secondary toolbar.
- */
- public Builder setSecondaryToolbarColor(@ColorInt int color) {
- mIntent.putExtra(EXTRA_SECONDARY_TOOLBAR_COLOR, color);
- return this;
- }
-
- /**
- * Sets the remote views displayed in the secondary toolbar in a custom tab.
- *
- * @param remoteViews The {@link RemoteViews} that will be shown on the secondary toolbar.
- * @param clickableIDs The IDs of clickable views. The onClick event of these views will be
- * handled by custom tabs.
- * @param pendingIntent The {@link PendingIntent} that will be sent when the user clicks on
- * one of the {@link View}s in clickableIDs. When the
- * {@link PendingIntent} is sent, it will have the current URL as its
- * intent data.
- * @see CustomTabsIntent#EXTRA_REMOTEVIEWS
- * @see CustomTabsIntent#EXTRA_REMOTEVIEWS_VIEW_IDS
- * @see CustomTabsIntent#EXTRA_REMOTEVIEWS_PENDINGINTENT
- * @see CustomTabsIntent#EXTRA_REMOTEVIEWS_CLICKED_ID
- */
- public Builder setSecondaryToolbarViews(@NonNull RemoteViews remoteViews,
- @Nullable int[] clickableIDs, @Nullable PendingIntent pendingIntent) {
- mIntent.putExtra(EXTRA_REMOTEVIEWS, remoteViews);
- mIntent.putExtra(EXTRA_REMOTEVIEWS_VIEW_IDS, clickableIDs);
- mIntent.putExtra(EXTRA_REMOTEVIEWS_PENDINGINTENT, pendingIntent);
- return this;
- }
-
- /**
- * Sets whether Instant Apps is enabled for this Custom Tab.
-
- * @param enabled Whether Instant Apps should be enabled.
- */
- public Builder setInstantAppsEnabled(boolean enabled) {
- mInstantAppsEnabled = enabled;
- return this;
- }
-
- /**
- * Sets the start animations.
- *
- * @param context Application context.
- * @param enterResId Resource ID of the "enter" animation for the browser.
- * @param exitResId Resource ID of the "exit" animation for the application.
- */
- public Builder setStartAnimations(
- @NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) {
- mStartAnimationBundle = ActivityOptionsCompat.makeCustomAnimation(
- context, enterResId, exitResId).toBundle();
- return this;
- }
-
- /**
- * Sets the exit animations.
- *
- * @param context Application context.
- * @param enterResId Resource ID of the "enter" animation for the application.
- * @param exitResId Resource ID of the "exit" animation for the browser.
- */
- public Builder setExitAnimations(
- @NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) {
- Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(
- context, enterResId, exitResId).toBundle();
- mIntent.putExtra(EXTRA_EXIT_ANIMATION_BUNDLE, bundle);
- return this;
- }
-
- /**
- * Combines all the options that have been set and returns a new {@link CustomTabsIntent}
- * object.
- */
- public CustomTabsIntent build() {
- if (mMenuItems != null) {
- mIntent.putParcelableArrayListExtra(CustomTabsIntent.EXTRA_MENU_ITEMS, mMenuItems);
- }
- if (mActionButtons != null) {
- mIntent.putParcelableArrayListExtra(EXTRA_TOOLBAR_ITEMS, mActionButtons);
- }
- mIntent.putExtra(EXTRA_ENABLE_INSTANT_APPS, mInstantAppsEnabled);
- return new CustomTabsIntent(mIntent, mStartAnimationBundle);
- }
- }
-
- /**
- * @return The maximum number of allowed toolbar items for
- * {@link CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent)} and
- * {@link CustomTabsIntent#EXTRA_TOOLBAR_ITEMS}.
- */
- public static int getMaxToolbarItems() {
- return MAX_TOOLBAR_ITEMS;
- }
-
- /**
- * Adds the necessary flags and extras to signal any browser supporting custom tabs to use the
- * browser UI at all times and avoid showing custom tab like UI. Calling this with an intent
- * will override any custom tabs related customizations.
- * @param intent The intent to modify for always showing browser UI.
- * @return The same intent with the necessary flags and extras added.
- */
- public static Intent setAlwaysUseBrowserUI(Intent intent) {
- if (intent == null) intent = new Intent(Intent.ACTION_VIEW);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS, true);
- return intent;
- }
-
- public void setUseNewTask() {
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- }
-
- /**
- * Whether a browser receiving the given intent should always use browser UI and avoid using any
- * custom tabs UI.
- *
- * @param intent The intent to check for the required flags and extras.
- * @return Whether the browser UI should be used exclusively.
- */
- public static boolean shouldAlwaysUseBrowserUI(Intent intent) {
- return intent.getBooleanExtra(EXTRA_USER_OPT_OUT_FROM_CUSTOM_TABS, false)
- && (intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0;
- }
-}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsService.java b/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsService.java
deleted file mode 100755
index 9217ee09d..000000000
--- a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsService.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-package org.telegram.messenger.support.customtabs;
-
-import android.app.Service;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.IBinder.DeathRecipient;
-import android.os.RemoteException;
-import androidx.annotation.IntDef;
-import androidx.collection.ArrayMap;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-/**
- * Abstract service class for implementing Custom Tabs related functionality. The service should
- * be responding to the action ACTION_CUSTOM_TABS_CONNECTION. This class should be used by
- * implementers that want to provide Custom Tabs functionality, not by clients that want to launch
- * Custom Tabs.
- */
-public abstract class CustomTabsService extends Service {
- /**
- * The Intent action that a CustomTabsService must respond to.
- */
- public static final String ACTION_CUSTOM_TABS_CONNECTION =
- "android.support.customtabs.action.CustomTabsService";
-
- /**
- * For {@link CustomTabsService#mayLaunchUrl} calls that wants to specify more than one url,
- * this key can be used with {@link Bundle#putParcelable(String, android.os.Parcelable)}
- * to insert a new url to each bundle inside list of bundles.
- */
- public static final String KEY_URL =
- "android.support.customtabs.otherurls.URL";
-
- @Retention(RetentionPolicy.SOURCE)
- @IntDef({RESULT_SUCCESS, RESULT_FAILURE_DISALLOWED,
- RESULT_FAILURE_REMOTE_ERROR, RESULT_FAILURE_MESSAGING_ERROR})
- public @interface Result {
- }
-
- /**
- * Indicates that the postMessage request was accepted.
- */
- public static final int RESULT_SUCCESS = 0;
- /**
- * Indicates that the postMessage request was not allowed due to a bad argument or requesting
- * at a disallowed time like when in background.
- */
- public static final int RESULT_FAILURE_DISALLOWED = -1;
- /**
- * Indicates that the postMessage request has failed due to a {@link RemoteException} .
- */
- public static final int RESULT_FAILURE_REMOTE_ERROR = -2;
- /**
- * Indicates that the postMessage request has failed due to an internal error on the browser
- * message channel.
- */
- public static final int RESULT_FAILURE_MESSAGING_ERROR = -3;
-
- private final Map
- * The method {@link CustomTabsService#warmup(long)} has to be called beforehand.
- * The most likely URL has to be specified explicitly. Optionally, a list of
- * other likely URLs can be provided. They are treated as less likely than
- * the first one, and have to be sorted in decreasing priority order. These
- * additional URLs may be ignored.
- * All previous calls to this method will be deprioritized.
- *
- * @param sessionToken The unique identifier for the session. Can not be null.
- * @param url Most likely URL.
- * @param extras Reserved for future use.
- * @param otherLikelyBundles Other likely destinations, sorted in decreasing
- * likelihood order. Each Bundle has to provide a url.
- * @return Whether the call was successful.
- */
- protected abstract boolean mayLaunchUrl(CustomTabsSessionToken sessionToken, Uri url,
- Bundle extras, List
- *
- * Note:Clients should never rely on this method to have a
- * defined behavior, as it is entirely implementation-defined and not supported.
- *
- * This call can be used by implementations to add extra commands, for testing or
- * experimental purposes.
- *
- * @param commandName Name of the extra command to execute.
- * @param args Arguments for the command
- * @return The result {@link Bundle}, or null.
- */
- protected abstract Bundle extraCommand(String commandName, Bundle args);
-
- /**
- * Updates the visuals of custom tabs for the given session. Will only succeed if the given
- * session matches the currently active one.
- *
- * @param sessionToken The currently active session that the custom tab belongs to.
- * @param bundle The action button configuration bundle. This bundle should be constructed
- * with the same structure in {@link CustomTabsIntent.Builder}.
- * @return Whether the operation was successful.
- */
- protected abstract boolean updateVisuals(CustomTabsSessionToken sessionToken,
- Bundle bundle);
-
- /**
- * Sends a request to create a two way postMessage channel between the client and the browser
- * linked with the given {@link CustomTabsSession}.
- *
- * @param sessionToken The unique identifier for the session. Can not be null.
- * @param postMessageOrigin A origin that the client is requesting to be identified as
- * during the postMessage communication.
- * @return Whether the implementation accepted the request. Note that returning true
- * here doesn't mean an origin has already been assigned as the validation is
- * asynchronous.
- */
- protected abstract boolean requestPostMessageChannel(CustomTabsSessionToken sessionToken,
- Uri postMessageOrigin);
-
- /**
- * Sends a postMessage request using the origin communicated via
- * {@link CustomTabsService#requestPostMessageChannel(
- *CustomTabsSessionToken, Uri)}. Fails when called before
- * {@link PostMessageServiceConnection#notifyMessageChannelReady(Bundle)} is received on the
- * client side.
- *
- * @param sessionToken The unique identifier for the session. Can not be null.
- * @param message The message that is being sent.
- * @param extras Reserved for future use.
- * @return An integer constant about the postMessage request result. Will return
- * {@link CustomTabsService#RESULT_SUCCESS} if successful.
- */
- @Result
- protected abstract int postMessage(
- CustomTabsSessionToken sessionToken, String message, Bundle extras);
-}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsServiceConnection.java b/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsServiceConnection.java
deleted file mode 100755
index 8b20e3a51..000000000
--- a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsServiceConnection.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-package org.telegram.messenger.support.customtabs;
-
-import android.content.ComponentName;
-import android.content.ServiceConnection;
-import android.os.IBinder;
-
-/**
- * Abstract {@link ServiceConnection} to use while binding to a {@link CustomTabsService}. Any
- * client implementing this is responsible for handling changes related with the lifetime of the
- * connection like rebinding on disconnect.
- */
-public abstract class CustomTabsServiceConnection implements ServiceConnection {
-
- @Override
- public final void onServiceConnected(ComponentName name, IBinder service) {
- onCustomTabsServiceConnected(name, new CustomTabsClient(
- ICustomTabsService.Stub.asInterface(service), name) {
- });
- }
-
- /**
- * Called when a connection to the {@link CustomTabsService} has been established.
- * @param name The concrete component name of the service that has been connected.
- * @param client {@link CustomTabsClient} that contains the {@link IBinder} with which the
- * connection have been established. All further communication should be initiated
- * using this client.
- */
- public abstract void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client);
-}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsSession.java b/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsSession.java
deleted file mode 100755
index 454746c09..000000000
--- a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsSession.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-package org.telegram.messenger.support.customtabs;
-
-import android.app.PendingIntent;
-import android.content.ComponentName;
-import android.graphics.Bitmap;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import android.view.View;
-import android.widget.RemoteViews;
-
-import java.util.List;
-
-/**
- * A class to be used for Custom Tabs related communication. Clients that want to launch Custom Tabs
- * can use this class exclusively to handle all related communication.
- */
-public final class CustomTabsSession {
- private static final String TAG = "CustomTabsSession";
- private final Object mLock = new Object();
- private final ICustomTabsService mService;
- private final ICustomTabsCallback mCallback;
- private final ComponentName mComponentName;
-
- /**
- * Provides browsers a way to generate a dummy {@link CustomTabsSession} for testing
- * purposes.
- *
- * @param componentName The component the session should be created for.
- * @return A dummy session with no functionality.
- */
- public static CustomTabsSession createDummySessionForTesting(ComponentName componentName) {
- return new CustomTabsSession(null, new CustomTabsSessionToken.DummyCallback(), componentName);
- }
-
- /* package */ CustomTabsSession(
- ICustomTabsService service, ICustomTabsCallback callback, ComponentName componentName) {
- mService = service;
- mCallback = callback;
- mComponentName = componentName;
- }
-
- /**
- * Tells the browser of a likely future navigation to a URL.
- * The most likely URL has to be specified first. Optionally, a list of
- * other likely URLs can be provided. They are treated as less likely than
- * the first one, and have to be sorted in decreasing priority order. These
- * additional URLs may be ignored.
- * All previous calls to this method will be deprioritized.
- *
- * @param url Most likely URL.
- * @param extras Reserved for future use.
- * @param otherLikelyBundles Other likely destinations, sorted in decreasing
- * likelihood order. Inside each Bundle, the client should provide a
- * {@link Uri} using {@link CustomTabsService#KEY_URL} with
- * {@link Bundle#putParcelable(String, android.os.Parcelable)}.
- * @return true for success.
- */
- public boolean mayLaunchUrl(Uri url, Bundle extras, ListignoreDefault
to true and give a
- * non empty list of package names in packages
.
- *
- * @param context {@link Context} to use for querying the packages.
- * @param packages Ordered list of packages to test for Custom Tabs support, in
- * decreasing order of priority.
- * @param ignoreDefault If set, the default VIEW handler won't get priority over other browsers.
- * @return The preferred package name for handling Custom Tabs, or null
.
- */
- public static String getPackageName(
- Context context, @Nullable Listwarmup()
and create a session. In this case, calling this method is not
- * necessary.
- *
- * @param context {@link Context} to use to connect to the remote service.
- * @param packageName Package name of the target implementation.
- * @return Whether the binding was successful.
- */
- public static boolean connectAndInitialize(Context context, String packageName) {
- if (packageName == null) return false;
- final Context applicationContext = context.getApplicationContext();
- CustomTabsServiceConnection connection = new CustomTabsServiceConnection() {
- @Override
- public final void onCustomTabsServiceConnected(
- ComponentName name, CustomTabsClient client) {
- client.warmup(0);
- // Unbinding immediately makes the target process "Empty", provided that it is
- // not used by anyone else, and doesn't contain any Activity. This makes it
- // likely to get killed, but is preferable to keeping the connection around.
- applicationContext.unbindService(this);
- }
-
- @Override
- public final void onServiceDisconnected(ComponentName componentName) { }
- };
- try {
- return bindCustomTabsService(applicationContext, packageName, connection);
- } catch (SecurityException e) {
- return false;
- }
- }
-
- /**
- * Warm up the browser process.
- *
- * Allows the browser application to pre-initialize itself in the background. Significantly
- * speeds up URL opening in the browser. This is asynchronous and can be called several times.
- *
- * @param flags Reserved for future use.
- * @return Whether the warmup was successful.
- */
- public boolean warmup(long flags) {
- try {
- return mService.warmup(flags);
- } catch (RemoteException e) {
- return false;
- }
- }
-
- /**
- * Creates a new session through an ICustomTabsService with the optional callback. This session
- * can be used to associate any related communication through the service with an intent and
- * then later with a Custom Tab. The client can then send later service calls or intents to
- * through same session-intent-Custom Tab association.
- * @param callback The callback through which the client will receive updates about the created
- * session. Can be null. All the callbacks will be received on the UI thread.
- * @return The session object that was created as a result of the transaction. The client can
- * use this to relay session specific calls.
- * Null on error.
- */
- public CustomTabsSession newSession(final CustomTabsCallback callback) {
- ICustomTabsCallback.Stub wrapper = new ICustomTabsCallback.Stub() {
- private Handler mHandler = new Handler(Looper.getMainLooper());
-
- @Override
- public void onNavigationEvent(final int navigationEvent, final Bundle extras) {
- if (callback == null) return;
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- callback.onNavigationEvent(navigationEvent, extras);
- }
- });
- }
-
- @Override
- public void extraCallback(final String callbackName, final Bundle args)
- throws RemoteException {
- if (callback == null) return;
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- callback.extraCallback(callbackName, args);
- }
- });
- }
-
- @Override
- public void onMessageChannelReady(final Bundle extras)
- throws RemoteException {
- if (callback == null) return;
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- callback.onMessageChannelReady(extras);
- }
- });
- }
-
- @Override
- public void onPostMessage(final String message, final Bundle extras)
- throws RemoteException {
- if (callback == null) return;
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- callback.onPostMessage(message, extras);
- }
- });
- }
- };
-
- try {
- if (!mService.newSession(wrapper)) return null;
- } catch (RemoteException e) {
- return null;
- }
- return new CustomTabsSession(mService, wrapper, mServiceComponentName);
- }
-
- public Bundle extraCommand(String commandName, Bundle args) {
- try {
- return mService.extraCommand(commandName, args);
- } catch (RemoteException e) {
- return null;
- }
- }
-}
diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsIntent.java b/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsIntent.java
deleted file mode 100755
index 6aa5b161f..000000000
--- a/TMessagesProj/src/main/java/org/telegram/messenger/support/customtabs/CustomTabsIntent.java
+++ /dev/null
@@ -1,566 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-package org.telegram.messenger.support.customtabs;
-
-import android.app.Activity;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.Color;
-import android.net.Uri;
-import android.os.Bundle;
-import androidx.annotation.AnimRes;
-import androidx.annotation.ColorInt;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.core.app.ActivityOptionsCompat;
-import androidx.core.app.BundleCompat;
-import androidx.core.content.ContextCompat;
-import android.view.View;
-import android.widget.RemoteViews;
-
-import java.util.ArrayList;
-
-/**
- * Class holding the {@link Intent} and start bundle for a Custom Tabs Activity.
- *
- *