本文整理汇总了Java中android.support.customtabs.CustomTabsSession类的典型用法代码示例。如果您正苦于以下问题:Java CustomTabsSession类的具体用法?Java CustomTabsSession怎么用?Java CustomTabsSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CustomTabsSession类属于android.support.customtabs包,在下文中一共展示了CustomTabsSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: launchCustomTabsWithSessionBottombar
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
public void launchCustomTabsWithSessionBottombar(Activity activity, String url, @Nullable CustomTabsSession session) {
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
if (TextUtils.isEmpty(packageName)) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
CustomTabsIntent.Builder builder;
if (session == null) {
builder = new CustomTabsIntent.Builder();
} else {
builder = new CustomTabsIntent.Builder(session);
}
// Intent hacked
Intent cctIntent = new CustomTabsIntent.Builder(session).build().intent;
cctIntent.setData(Uri.parse(url));
PendingIntent cctPendingIntent = PendingIntent.getActivity(activity, 124, cctIntent, PendingIntent.FLAG_UPDATE_CURRENT);
addSessionBottombar(builder, activity, cctPendingIntent);
CustomTabsIntent customTabsIntent = builder
.setToolbarColor(Color.WHITE)
.build();
CustomTabsHelper.addKeepAliveExtra(activity, customTabsIntent.intent);
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(activity, Uri.parse(url));
}
示例2: createSession
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
/**
* Creates a {@link android.support.customtabs.CustomTabsSession custom tab session} for
* use with a custom tab intent, with optional callbacks and optional list of URIs that may
* be requested. The URI list should be ordered such that the most likely URI to be requested
* is first. If no custom tab supporting browser is available, this will return {@code null}.
*/
@WorkerThread
@Nullable
public CustomTabsSession createSession(
@Nullable CustomTabsCallback callbacks,
@Nullable Uri... possibleUris) {
CustomTabsClient client = getClient();
if (client == null) {
return null;
}
CustomTabsSession session = client.newSession(callbacks);
if (possibleUris != null && possibleUris.length > 0) {
List<Bundle> additionalUris = UriUtil.toCustomTabUriBundle(possibleUris, 1);
session.mayLaunchUrl(possibleUris[0], null, additionalUris);
}
return session;
}
示例3: getCustomTabIntent
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
public static CustomTabsIntent.Builder getCustomTabIntent(@NonNull Context context,
@NonNull Story story,
@Nullable CustomTabsSession session) {
Intent upvoteStory = new Intent(context, UpvoteStoryService.class);
upvoteStory.setAction(UpvoteStoryService.ACTION_UPVOTE);
upvoteStory.putExtra(UpvoteStoryService.EXTRA_STORY_ID, story.id);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, upvoteStory, 0);
return new CustomTabsIntent.Builder(session)
.setToolbarColor(ContextCompat.getColor(context, R.color.designer_news))
.setActionButton(ImageUtils.vectorToBitmap(context,
R.drawable.ic_upvote_filled_24dp_white),
context.getString(R.string.upvote_story),
pendingIntent,
false)
.setShowTitle(true)
.enableUrlBarHiding()
.addDefaultShareMenuItem();
}
示例4: openExternal
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
public static void openExternal(@NonNull final Context context,
@NonNull PopupMenu popupMenu,
@NonNull View anchor,
@NonNull final WebItem item,
final CustomTabsSession session) {
if (TextUtils.isEmpty(item.getUrl()) ||
item.getUrl().startsWith(HackerNewsClient.BASE_WEB_URL)) {
openWebUrlExternal(context,
item, String.format(HackerNewsClient.WEB_ITEM_PATH, item.getId()),
session);
return;
}
popupMenu.create(context, anchor, GravityCompat.END)
.inflate(R.menu.menu_share)
.setOnMenuItemClickListener(menuItem -> {
openWebUrlExternal(context, item, menuItem.getItemId() == R.id.menu_article ?
item.getUrl() :
String.format(HackerNewsClient.WEB_ITEM_PATH, item.getId()), session);
return true;
})
.show();
}
示例5: createViewIntent
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
@NonNull
private static Intent createViewIntent(Context context, @Nullable WebItem item,
String url, @Nullable CustomTabsSession session) {
if (Preferences.customTabsEnabled(context)) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(session)
.setToolbarColor(ContextCompat.getColor(context,
AppUtils.getThemedResId(context, R.attr.colorPrimary)))
.setShowTitle(true)
.enableUrlBarHiding()
.addDefaultShareMenuItem();
if (item != null) {
builder.addMenuItem(context.getString(R.string.comments),
PendingIntent.getActivity(context, 0,
new Intent(context, ItemActivity.class)
.putExtra(ItemActivity.EXTRA_ITEM, item)
.putExtra(ItemActivity.EXTRA_OPEN_COMMENTS, true),
PendingIntent.FLAG_ONE_SHOT));
}
return builder.build().intent.setData(Uri.parse(url));
} else {
return new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}
}
示例6: onReceive
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
int clickedId = intent.getIntExtra(CustomTabsIntent.EXTRA_REMOTEVIEWS_CLICKED_ID, -1);
Toast.makeText(context, "Current URL " + intent.getDataString() + "\nClicked id "
+ clickedId, Toast.LENGTH_SHORT).show();
CustomTabsSession session = SessionHelper.getCurrentSession();
if (session == null) return;
if (clickedId == R.id.play_pause) {
MediaPlayer player = sMediaPlayerWeakRef.get();
if (player != null) {
boolean isPlaying = player.isPlaying();
if (isPlaying) player.pause();
else player.start();
// Update the play/stop icon to respect the current state.
session.setSecondaryToolbarViews(createRemoteViews(context, isPlaying), getClickableIDs(),
getOnClickPendingIntent(context));
}
} else if (clickedId == R.id.cover) {
// Clicking on the cover image will dismiss the bottom bar.
session.setSecondaryToolbarViews(null, null, null);
}
}
示例7: getCustomTabIntent
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
public static CustomTabsIntent.Builder getCustomTabIntent(@NonNull Context context,
@NonNull Story story,
@Nullable CustomTabsSession session) {
Intent upvoteStory = new Intent(context, UpvoteStoryService.class);
upvoteStory.setAction(UpvoteStoryService.ACTION_UPVOTE);
upvoteStory.putExtra(UpvoteStoryService.EXTRA_STORY_ID, story.id);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, upvoteStory, 0);
return new CustomTabsIntent.Builder(session)
.setToolbarColor(ContextCompat.getColor(context, R.color.designer_news))
.setActionButton(DrawableUtils.drawableToBitmap(context,
R.drawable.ic_upvote_filled_24dp_white),
context.getString(R.string.upvote_story),
pendingIntent,
false)
.setShowTitle(true)
.enableUrlBarHiding()
.addDefaultShareMenuItem();
}
示例8: preload
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
/** Caller must unbind the returned ServiceConnection when leaving the scope. */
public static @CheckResult @Nullable ServiceConnection preload(final Context context, final Uri uri, final @Nullable OnSessionReadyListener listener) {
final CustomTabsServiceConnection connection;
if (! CustomTabsClient.bindCustomTabsService(context, KChromePackageName, connection = new CustomTabsServiceConnection() {
@Override public void onCustomTabsServiceConnected(final ComponentName componentName, final CustomTabsClient client) {
Log.d(TAG, "Warming up Chrome custom tabs");
if (client.warmup(0)) {
final CustomTabsSession session = client.newSession(null);
if (session != null) {
session.mayLaunchUrl(uri, null, null);
if (listener != null) listener.onSessionReady(session);
}
}
}
@Override public void onServiceDisconnected(final ComponentName name) {}
})) return null;
return connection;
}
示例9: getSession
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
/**
* Creates or retrieves an exiting CustomTabsSession.
*
* @return a CustomTabsSession.
*/
public CustomTabsSession getSession() {
if (mClient == null) {
mCustomTabsSession = null;
} else if (mCustomTabsSession == null) {
mCustomTabsSession = mClient.newSession(null);
}
return mCustomTabsSession;
}
示例10: mayLaunchUrl
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
/**
* @see {@link CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)}.
* @return true if call to mayLaunchUrl was accepted.
*/
public boolean mayLaunchUrl(Uri uri, Bundle extras, List<Bundle> otherLikelyBundles) {
if (mClient == null) return false;
CustomTabsSession session = getSession();
if (session == null) return false;
return session.mayLaunchUrl(uri, extras, otherLikelyBundles);
}
示例11: getSession
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
/**
* Creates or retrieves an exiting CustomTabsSession.
*
* @return a CustomTabsSession.
*/
public CustomTabsSession getSession() {
if (mClient == null) {
mCustomTabsSession = null;
} else if (mCustomTabsSession == null) {
mCustomTabsSession = mClient.newSession(null);
}
return mCustomTabsSession;
}
示例12: mayLaunchUrl
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
/**
* @return true if call to mayLaunchUrl was accepted.
* @see {@link CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)}.
*/
public boolean mayLaunchUrl(Uri uri, Bundle extras, List<Bundle> otherLikelyBundles) {
if (mClient == null) return false;
CustomTabsSession session = getSession();
if (session == null) return false;
return session.mayLaunchUrl(uri, extras, otherLikelyBundles);
}
示例13: getSession
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
public static CustomTabsSession getSession() {
if (mClient == null) {
mCustomTabsSession = null;
} else if (mCustomTabsSession == null) {
mCustomTabsSession = mClient.newSession(new CustomTabsCallback() {
@Override
public void onNavigationEvent(int navigationEvent, Bundle extras) {
Log.w(LogUtil.getTag(), "onNavigationEvent: Code = " + navigationEvent);
}
});
}
return mCustomTabsSession;
}
示例14: getSession
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
/**
* Creates or retrieves an exiting CustomTabsSession
*
* @return a CustomTabsSession
*/
public CustomTabsSession getSession() {
if (client == null) {
customTabsSession = null;
} else if (customTabsSession == null) {
customTabsSession = client.newSession(null);
}
return customTabsSession;
}
示例15: mayLaunchUrl
import android.support.customtabs.CustomTabsSession; //导入依赖的package包/类
public boolean mayLaunchUrl(final Uri uri, final Bundle extras, final List<Bundle> otherLikelyBundles) {
if (client == null) {
return false;
}
CustomTabsSession session = getSession();
return session != null && session.mayLaunchUrl(uri, extras, otherLikelyBundles);
}