forked from mirror/monocles_chat
complete customTabs for links
https://developers.google.com/web/android/custom-tabs
This commit is contained in:
parent
b4361f0c8d
commit
816fb7d94d
2 changed files with 41 additions and 9 deletions
|
@ -64,9 +64,9 @@ import eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested;
|
|||
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
||||
import eu.siacs.conversations.ui.adapter.PresenceTemplateAdapter;
|
||||
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
||||
import eu.siacs.conversations.ui.util.CustomTab;
|
||||
import eu.siacs.conversations.ui.util.PendingItem;
|
||||
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
|
||||
import eu.siacs.conversations.utils.CharSequenceUtils;
|
||||
import eu.siacs.conversations.utils.CryptoHelper;
|
||||
import eu.siacs.conversations.utils.EasyOnboardingInvite;
|
||||
import eu.siacs.conversations.utils.MenuDoubleTabUtil;
|
||||
|
@ -169,8 +169,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
URL url = connection != null && redirectionWorthyStatus ? connection.getRedirectionUrl() : null;
|
||||
if (url != null && !wasDisabled) {
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString())));
|
||||
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
|
||||
CustomTab.openTab(EditAccountActivity.this, Uri.parse(url.toString()), isDarkTheme());
|
||||
return;
|
||||
} catch (ActivityNotFoundException e) {
|
||||
ToastCompat.makeText(EditAccountActivity.this, R.string.application_found_to_open_website, Toast.LENGTH_SHORT).show();
|
||||
|
@ -667,13 +666,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
}
|
||||
this.binding.showPrivacyPolicy.setOnClickListener(view -> {
|
||||
final Uri uri = Uri.parse("https://jabber.pix-art.de/privacy/");
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
startActivity(browserIntent);
|
||||
CustomTab.openTab(EditAccountActivity.this, uri, isDarkTheme());
|
||||
});
|
||||
this.binding.showTermsOfUse.setOnClickListener(view -> {
|
||||
final Uri uri = Uri.parse("https://jabber.pix-art.de/termsofuse/");
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
startActivity(browserIntent);
|
||||
CustomTab.openTab(EditAccountActivity.this, uri, isDarkTheme());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -960,8 +957,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
|
||||
try {
|
||||
Uri uri = Uri.parse(getSupportSite(mAccount.getJid().getDomain().toEscapedString()));
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
startActivity(intent);
|
||||
CustomTab.openTab(EditAccountActivity.this, uri, isDarkTheme());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
36
src/main/java/eu/siacs/conversations/ui/util/CustomTab.java
Normal file
36
src/main/java/eu/siacs/conversations/ui/util/CustomTab.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package eu.siacs.conversations.ui.util;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.provider.Browser;
|
||||
|
||||
import androidx.browser.customtabs.CustomTabColorSchemeParams;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
|
||||
import eu.siacs.conversations.R;
|
||||
|
||||
import static eu.siacs.conversations.utils.Compatibility.runsTwentyOne;
|
||||
|
||||
public class CustomTab {
|
||||
public static void openTab(Context context, Uri uri, boolean dark) throws ActivityNotFoundException {
|
||||
CustomTabsIntent.Builder tabBuilder = new CustomTabsIntent.Builder();
|
||||
tabBuilder.setShowTitle(true);
|
||||
tabBuilder.setUrlBarHidingEnabled(false);
|
||||
tabBuilder.setDefaultColorSchemeParams(new CustomTabColorSchemeParams.Builder()
|
||||
.setToolbarColor(StyledAttributes.getColor(context, R.attr.colorPrimary))
|
||||
.setSecondaryToolbarColor(StyledAttributes.getColor(context, R.attr.colorPrimaryDark))
|
||||
.setNavigationBarColor(Color.BLUE)
|
||||
.build());
|
||||
tabBuilder.setColorScheme(dark ? CustomTabsIntent.COLOR_SCHEME_DARK : CustomTabsIntent.COLOR_SCHEME_LIGHT);
|
||||
tabBuilder.setShareState(CustomTabsIntent.SHARE_STATE_ON);
|
||||
CustomTabsIntent customTabsIntent = tabBuilder.build();
|
||||
if (runsTwentyOne()) {
|
||||
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
}
|
||||
customTabsIntent.intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
|
||||
customTabsIntent.launchUrl(context, uri);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue