當前位置: 首頁>>代碼示例>>Java>>正文


Java CustomTabsIntent類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:CustomTabActivityHelper.java

示例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));
}
 
開發者ID:sfilmak,項目名稱:MakiLite,代碼行數:18,代碼來源:MakiListener.java

示例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();
}
 
開發者ID:alphater,項目名稱:garras,代碼行數:17,代碼來源:LicensesDialog.java

示例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);
}
 
開發者ID:Chan4077,項目名稱:StudyBuddy,代碼行數:21,代碼來源:SettingsActivity.java

示例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;
}
 
開發者ID:vicky7230,項目名稱:Paprika,代碼行數:22,代碼來源:LikesAdapter.java

示例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;
}
 
開發者ID:vicky7230,項目名稱:Paprika,代碼行數:24,代碼來源:SearchAdapter.java

示例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);
                }
            }));
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:19,代碼來源:PassphraseDialogFragment.java

示例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);
  }
}
 
開發者ID:tomoya92,項目名稱:android-apps,代碼行數:26,代碼來源:CustomTabActivityHelper.java

示例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);
    }
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:18,代碼來源:ActivityHelper.java

示例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);
}
 
開發者ID:approov,項目名稱:AppAuth-OAuth2-Books-Demo,代碼行數:25,代碼來源:AuthRepo.java

示例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);
	}
}
 
開發者ID:SebastianRask,項目名稱:Pocket-Plays-for-Twitch,代碼行數:23,代碼來源:ChatAdapter.java

示例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());
    }

}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:30,代碼來源:LinkHelper.java

示例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;
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:19,代碼來源:CustomTabTest.java

示例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());
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:23,代碼來源:SessionManagerTest.java


注:本文中的android.support.customtabs.CustomTabsIntent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。