use CustomTabColorSchemeParams instead of deprecated methods (#2049)
This commit is contained in:
parent
520353f8dd
commit
46468b8a78
2 changed files with 22 additions and 17 deletions
|
@ -20,7 +20,6 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.method.LinkMovementMethod
|
import android.text.method.LinkMovementMethod
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -28,6 +27,7 @@ import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
import androidx.browser.customtabs.CustomTabsIntent
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.keylesspalace.tusky.di.Injectable
|
import com.keylesspalace.tusky.di.Injectable
|
||||||
|
@ -346,16 +346,19 @@ class LoginActivity : BaseActivity(), Injectable {
|
||||||
private fun openInCustomTab(uri: Uri, context: Context): Boolean {
|
private fun openInCustomTab(uri: Uri, context: Context): Boolean {
|
||||||
|
|
||||||
val toolbarColor = ThemeUtils.getColor(context, R.attr.colorSurface)
|
val toolbarColor = ThemeUtils.getColor(context, R.attr.colorSurface)
|
||||||
val customTabsIntentBuilder = CustomTabsIntent.Builder()
|
val navigationbarColor = ThemeUtils.getColor(context, android.R.attr.navigationBarColor)
|
||||||
|
val navigationbarDividerColor = ThemeUtils.getColor(context, R.attr.dividerColor)
|
||||||
|
|
||||||
|
val colorSchemeParams = CustomTabColorSchemeParams.Builder()
|
||||||
.setToolbarColor(toolbarColor)
|
.setToolbarColor(toolbarColor)
|
||||||
|
.setNavigationBarColor(navigationbarColor)
|
||||||
|
.setNavigationBarDividerColor(navigationbarDividerColor)
|
||||||
|
.build()
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
val customTabsIntent = CustomTabsIntent.Builder()
|
||||||
customTabsIntentBuilder.setNavigationBarColor(
|
.setDefaultColorSchemeParams(colorSchemeParams)
|
||||||
ThemeUtils.getColor(context, android.R.attr.navigationBarColor)
|
.build()
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val customTabsIntent = customTabsIntentBuilder.build()
|
|
||||||
try {
|
try {
|
||||||
customTabsIntent.launchUrl(context, uri)
|
customTabsIntent.launchUrl(context, uri)
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
|
|
@ -19,7 +19,6 @@ import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
|
@ -31,6 +30,7 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.browser.customtabs.CustomTabColorSchemeParams;
|
||||||
import androidx.browser.customtabs.CustomTabsIntent;
|
import androidx.browser.customtabs.CustomTabsIntent;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
@ -229,18 +229,20 @@ public class LinkHelper {
|
||||||
*/
|
*/
|
||||||
public static void openLinkInCustomTab(Uri uri, Context context) {
|
public static void openLinkInCustomTab(Uri uri, Context context) {
|
||||||
int toolbarColor = ThemeUtils.getColor(context, R.attr.colorSurface);
|
int toolbarColor = ThemeUtils.getColor(context, R.attr.colorSurface);
|
||||||
|
int navigationbarColor = ThemeUtils.getColor(context, android.R.attr.navigationBarColor);
|
||||||
|
int navigationbarDividerColor = ThemeUtils.getColor(context, R.attr.dividerColor);
|
||||||
|
|
||||||
CustomTabsIntent.Builder customTabsIntentBuilder = new CustomTabsIntent.Builder()
|
CustomTabColorSchemeParams colorSchemeParams = new CustomTabColorSchemeParams.Builder()
|
||||||
.setToolbarColor(toolbarColor)
|
.setToolbarColor(toolbarColor)
|
||||||
.setShowTitle(true);
|
.setNavigationBarColor(navigationbarColor)
|
||||||
|
.setNavigationBarDividerColor(navigationbarDividerColor)
|
||||||
|
.build();
|
||||||
|
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
|
||||||
customTabsIntentBuilder.setNavigationBarColor(
|
.setDefaultColorSchemeParams(colorSchemeParams)
|
||||||
ThemeUtils.getColor(context, android.R.attr.navigationBarColor)
|
.setShowTitle(true)
|
||||||
);
|
.build();
|
||||||
}
|
|
||||||
|
|
||||||
CustomTabsIntent customTabsIntent = customTabsIntentBuilder.build();
|
|
||||||
try {
|
try {
|
||||||
customTabsIntent.launchUrl(context, uri);
|
customTabsIntent.launchUrl(context, uri);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
|
|
Loading…
Reference in a new issue