本文整理汇总了Java中android.support.customtabs.CustomTabsIntent类的典型用法代码示例。如果您正苦于以下问题:Java CustomTabsIntent类的具体用法?Java CustomTabsIntent怎么用?Java CustomTabsIntent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CustomTabsIntent类属于android.support.customtabs包,在下文中一共展示了CustomTabsIntent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openCustomTab
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
/**
* Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
*
* @param activity The host activity.
* @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available.
* @param uri the Uri to be opened.
* @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
*/
public static void openCustomTab(Activity activity,
CustomTabsIntent customTabsIntent,
Uri uri,
CustomTabFallback fallback) {
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
//If we cant find a package name, it means theres no browser that supports
//Chrome Custom Tabs installed. So, we fallback to the webview
if (packageName == null) {
if (fallback != null) {
fallback.openUri(activity, uri);
}
} else {
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(activity, uri);
}
}
示例2: onExternalPageRequest
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
@Override
public void onExternalPageRequest(String url) {
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setShowTitle(true);
intentBuilder.setToolbarColor(ContextCompat.getColor(fActivity, R.color.colorPrimary));
Intent actionIntent = new Intent(Intent.ACTION_SEND);
actionIntent.setType("text/plain");
actionIntent.putExtra(Intent.EXTRA_TEXT, url);
PendingIntent menuItemPendingIntent = PendingIntent.getActivity(fActivity, 0, actionIntent, 0);
intentBuilder.setActionButton(BitmapFactory.decodeResource(getResources(), R.drawable.ic_share), (fActivity.getString(R.string.update_share)), menuItemPendingIntent);
intentBuilder.addMenuItem(fActivity.getString(R.string.update_share), menuItemPendingIntent);
intentBuilder.build().launchUrl(fActivity, Uri.parse(url));
}
示例3: openCustomTabs
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
private void openCustomTabs(String url) {
if (null == getActivity()) return;
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setToolbarColor(Color.WHITE);
intentBuilder.setSecondaryToolbarColor(Color.BLACK);
intentBuilder.addDefaultShareMenuItem();
intentBuilder.setShowTitle(true);
intentBuilder.enableUrlBarHiding();
CustomTabsIntent customTabsIntent = intentBuilder.build();
String packageName = CustomTabsHelper.getPackageNameToUse(getActivity());
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(getActivity(), Uri.parse(url));
dismissAllowingStateLoss();
}
示例4: onOptionsItemSelected
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case android.R.id.home:
startActivity(new Intent(getActivity(), SettingsActivity.class));
return true;
case R.id.action_send_feedback:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
builder.addDefaultShareMenuItem();
final CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(getContext(), Uri.parse(sendFeedbackUrl));
return true;
case R.id.action_help:
// TODO: Add some stuff
return true;
}
return super.onOptionsItemSelected(item);
}
示例5: onCreateViewHolder
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final RecipeViewHolder recipeViewHolder = new RecipeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.recipe_list_item, parent, false));
recipeViewHolder.recipeImageCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final LikedRecipe likedRecipe = getItem(recipeViewHolder.getAdapterPosition());
if (likedRecipe != null) {
if (likedRecipe.getImageUrl() != null) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.setShowTitle(true)
.setToolbarColor(ContextCompat.getColor(recipeViewHolder.itemView.getContext(), R.color.color_primary))
.setSecondaryToolbarColor(ContextCompat.getColor(recipeViewHolder.itemView.getContext(), R.color.color_primary_dark))
.build();
customTabsIntent.launchUrl(recipeViewHolder.itemView.getContext(), Uri.parse(likedRecipe.getSourceUrl()));
}
}
}
});
return recipeViewHolder;
}
示例6: createRecipeViewHolder
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
private RecyclerView.ViewHolder createRecipeViewHolder(ViewGroup parent) {
final RecipeViewHolder recipeViewHolder = new RecipeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.search_list_item, parent, false));
recipeViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Recipe recipe = getItem(recipeViewHolder.getAdapterPosition());
if (recipe != null) {
if (recipe.getSourceUrl() != null) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.setShowTitle(true)
.setToolbarColor(ContextCompat.getColor(recipeViewHolder.itemView.getContext(), R.color.color_primary))
.setSecondaryToolbarColor(ContextCompat.getColor(recipeViewHolder.itemView.getContext(), R.color.color_primary_dark))
.addDefaultShareMenuItem()
.build();
customTabsIntent.launchUrl(recipeViewHolder.itemView.getContext(), Uri.parse(recipe.getSourceUrl()));
}
}
}
});
return recipeViewHolder;
}
示例7: getResetText
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
private SpannableString getResetText() {
final Context context = getActivity();
return SpanApplier.applySpans(
context.getString(R.string.sync_passphrase_encryption_reset_instructions),
new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
@Override
public void onClick(View view) {
Uri syncDashboardUrl = Uri.parse(
context.getText(R.string.sync_dashboard_url).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
intent.setPackage(BuildInfo.getPackageName(context));
IntentUtils.safePutBinderExtra(
intent, CustomTabsIntent.EXTRA_SESSION, null);
context.startActivity(intent);
}
}));
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:18,代码来源:PassphraseTypeDialogFragment.java
示例8: getResetText
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
private SpannableString getResetText() {
final Context context = getActivity();
return SpanApplier.applySpans(
context.getString(R.string.sync_passphrase_reset_instructions),
new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
@Override
public void onClick(View view) {
recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
Uri syncDashboardUrl = Uri.parse(
context.getText(R.string.sync_dashboard_url).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
intent.setPackage(BuildInfo.getPackageName(context));
IntentUtils.safePutBinderExtra(
intent, CustomTabsIntent.EXTRA_SESSION, null);
context.startActivity(intent);
}
}));
}
示例9: openCustomTab
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
/**
* Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
*
* @param activity The host activity.
* @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available.
* @param uri the Uri to be opened.
* @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
*/
public static void openCustomTab(Activity activity,
CustomTabsIntent customTabsIntent,
Uri uri,
CustomTabFallback fallback) {
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
//If we cant find a package name, it means theres no browser that supports
//Chrome Custom Tabs installed. So, we fallback to the webview
if (packageName == null) {
if (fallback != null) {
fallback.openUri(activity, uri);
}
} else {
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(activity, uri);
}
}
示例10: startCustomTab
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
public static void startCustomTab(@NonNull Activity context, @NonNull Uri url) {
String packageNameToUse = CustomTabsHelper.getPackageNameToUse(context);
if (packageNameToUse != null) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.setToolbarColor(ViewHelper.getPrimaryColor(context))
.setShowTitle(true)
.build();
customTabsIntent.intent.setPackage(packageNameToUse);
try {
customTabsIntent.launchUrl(context, url);
} catch (ActivityNotFoundException ignored) {
openChooser(context, url, true);
}
} else {
openChooser(context, url, true);
}
}
示例11: startUserAuth
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
private void startUserAuth() {
Log.i(TAG, "Starting user auth");
loginListener.onEvent(AuthRepo.this, AUTH_USER_AUTH_START);
// may need to do this off UI thread?
AuthorizationRequest.Builder authRequestBuilder = new AuthorizationRequest.Builder(
authState.getAuthorizationServiceConfiguration(),
clientId,
ResponseTypeValues.CODE,
Uri.parse(redirectUri))
.setScope(authScope);
AuthorizationRequest authRequest = authRequestBuilder.build();
CustomTabsIntent.Builder intentBuilder =
authService.createCustomTabsIntentBuilder(authRequest.toUri());
intentBuilder.setToolbarColor(app.getColorValue(R.color.colorAccent));
CustomTabsIntent authIntent = intentBuilder.build();
Intent intent = authService.getAuthorizationRequestIntent(authRequest, authIntent);
loginListener.onUserAgentRequest(AuthRepo.this, intent);
}
示例12: checkForLink
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
private void checkForLink(String message, SpannableStringBuilder spanbuilder) {
linkMatcher = linkPattern.matcher(message);
while(linkMatcher.find()) {
final String url = linkMatcher.group(1);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View view) {
CustomTabsIntent.Builder mTabs = new CustomTabsIntent.Builder();
mTabs.setStartAnimations(context, R.anim.slide_in_bottom_anim, R.anim.fade_out_semi_anim);
mTabs.setExitAnimations(context, R.anim.fade_in_semi_anim, R.anim.slide_out_bottom_anim);
mTabs.build().launchUrl(context, Uri.parse(url));
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(25);
}
};
int start = message.indexOf(url);
spanbuilder.setSpan(clickableSpan, start, start + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
示例13: openLinkInCustomTab
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
/**
* tries to open a link in a custom tab
* falls back to browser if not possible
*
* @param uri the uri to open
* @param context context
*/
public static void openLinkInCustomTab(Uri uri, Context context) {
boolean lightTheme = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("lightTheme", false);
int toolbarColor = ContextCompat.getColor(context, lightTheme ? R.color.custom_tab_toolbar_light : R.color.custom_tab_toolbar_dark);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(toolbarColor);
CustomTabsIntent customTabsIntent = builder.build();
try {
String packageName = CustomTabsHelper.getPackageNameToUse(context);
//If we cant find a package name, it means theres no browser that supports
//Chrome Custom Tabs installed. So, we fallback to the webview
if (packageName == null) {
openLinkInBrowser(uri, context);
} else {
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(context, uri);
}
} catch (ActivityNotFoundException e) {
Log.w("URLSpan", "Activity was not found for intent, " + customTabsIntent.toString());
}
}
示例14: createCustomTabIntent
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
private Intent createCustomTabIntent() {
final Context appContext = InstrumentationRegistry.getInstrumentation()
.getTargetContext()
.getApplicationContext();
final PendingIntent pendingIntent = PendingIntent.getActivity(appContext, 0, new Intent(), 0);
final CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.addMenuItem(MENU_ITEM_LABEL, pendingIntent)
.addDefaultShareMenuItem()
.setActionButton(createTestBitmap(), ACTION_BUTTON_DESCRIPTION, pendingIntent, true)
.setToolbarColor(Color.MAGENTA)
.build();
customTabsIntent.intent.setData(Uri.parse(webServer.url("/").toString()));
return customTabsIntent.intent;
}
示例15: testCustomTabIntent
import android.support.customtabs.CustomTabsIntent; //导入依赖的package包/类
@Test
public void testCustomTabIntent() {
final SessionManager sessionManager = SessionManager.getInstance();
final SafeIntent intent = new SafeIntent(new CustomTabsIntent.Builder()
.setToolbarColor(Color.GREEN)
.addDefaultShareMenuItem()
.build()
.intent
.setData(Uri.parse(TEST_URL)));
sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
final List<Session> sessions = sessionManager.getSessions().getValue();
assertNotNull(sessions);
assertEquals(1, sessions.size());
final Session session = sessions.get(0);
assertEquals(TEST_URL, session.getUrl().getValue());
assertTrue(sessionManager.hasSession());
}