本文整理匯總了Java中android.support.customtabs.CustomTabsServiceConnection類的典型用法代碼示例。如果您正苦於以下問題:Java CustomTabsServiceConnection類的具體用法?Java CustomTabsServiceConnection怎麽用?Java CustomTabsServiceConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CustomTabsServiceConnection類屬於android.support.customtabs包,在下文中一共展示了CustomTabsServiceConnection類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: warm
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
private Warmer warm(){
mCustomTabServiceConnection =
new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName,
CustomTabsClient customTabsClient) {
mCustomTabsClient = customTabsClient;
mCustomTabsClient.warmup(0);
mCustomTabsSession = mCustomTabsClient.newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mCustomTabsClient = null;
}
};
packageNameToUse = ChromePackageHelper.getPackageNameToUse(context);
if (packageNameToUse != null){
CustomTabsClient.bindCustomTabsService(context, packageNameToUse,
mCustomTabServiceConnection);
}
return this;
}
示例2: setUp
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
@Before
@SuppressWarnings("ResourceType")
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mAuthCallback = new AuthorizationCallback();
mRegistrationCallback = new RegistrationCallback();
mService = new AuthorizationService(
mContext,
new Builder()
.setConnectionBuilder(mConnectionBuilder)
.build(),
Browsers.Chrome.customTab("46"),
mCustomTabManager);
mOutputStream = new ByteArrayOutputStream();
when(mConnectionBuilder.openConnection(any(Uri.class))).thenReturn(mHttpConnection);
when(mHttpConnection.getOutputStream()).thenReturn(mOutputStream);
when(mContext.bindService(serviceIntentEq(), any(CustomTabsServiceConnection.class),
anyInt())).thenReturn(true);
when(mCustomTabManager.createTabBuilder())
.thenReturn(new CustomTabsIntent.Builder());
}
示例3: getChromePackages
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
private static List<String> getChromePackages(Context ctx) {
CustomTabsServiceConnection conn = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
};
String[] packages = {"com.android.chrome", "com.chrome.beta", "com.chrome.dev"};
List<String> availablePkgs = new ArrayList<>();
for (String pkg : packages) {
if (CustomTabsClient.bindCustomTabsService(ctx, pkg, conn)) {
availablePkgs.add(pkg);
}
}
return availablePkgs;
}
示例4: warm
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
private Warmer warm(){
mCustomTabServiceConnection =
new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName,
CustomTabsClient customTabsClient) {
mCustomTabsClient = customTabsClient;
mCustomTabsClient.warmup(0);
mCustomTabsSession = mCustomTabsClient.newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mCustomTabsClient = null;
}
};
packageNameToUse = ChromePackageHelper.getPackageNameToUse(context);
if (packageNameToUse != null){
CustomTabsClient.bindCustomTabsService(context, packageNameToUse,
mCustomTabServiceConnection);
}
return this;
}
示例5: onCreate
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mCustomTabsServiceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
mClient = customTabsClient;
mClient.warmup(0L);
mCustomTabsSession = mClient.newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mClient = null;
}
};
CustomTabsClient.bindCustomTabsService(MainActivity.this, CUSTOM_TAB_PACKAGE_NAME, mCustomTabsServiceConnection);
customTabsIntent = new CustomTabsIntent.Builder(mCustomTabsSession)
.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setShowTitle(true)
.build();
}
示例6: onActivityCreated
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
CustomTabsServiceConnection connection = new NewsCustomTabsServiceConnection();
isCustomTabsSupported = isChromeCustomTabsSupported(getContext());
setHasOptionsMenu(true);
mListView = getListView();
builder = new CustomTabsIntent.Builder();
share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
builder.setToolbarColor(0x3E50B4);
builder.setStartAnimations(getContext(),
android.support.design.R.anim.abc_popup_enter,
android.support.design.R.anim.abc_popup_exit);
CustomTabsClient.bindCustomTabsService(getContext(),
NewsCustomTabsServiceConnection.CUSTOM_TAB_PACKAGE_NAME, connection);
addNews();
}
示例7: preload
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的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;
}
示例8: openChromeTab
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
public static void openChromeTab(Context context, String link, int color) {
final CustomTabsClient[] mClient = new CustomTabsClient[1];
final CustomTabsSession[] mCustomTabsSession = new CustomTabsSession[1];
CustomTabsServiceConnection mCustomTabsServiceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
mClient[0] = customTabsClient;
mClient[0].warmup(0L);
mCustomTabsSession[0] = mClient[0].newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mClient[0] = null;
}
};
if (color == 0) color = ContextCompat.getColor(context, R.color.cardBackground);
CustomTabsClient.bindCustomTabsService(context, "com.android.chrome", mCustomTabsServiceConnection);
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder(mCustomTabsSession[0])
.setToolbarColor(color)
.setShowTitle(true)
.addDefaultShareMenuItem()
.build();
customTabsIntent.launchUrl((Activity) context, Uri.parse(link));
context.unbindService(mCustomTabsServiceConnection); // important
}
示例9: setUpCustomTabsService
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
public void setUpCustomTabsService(String url, Context context) {
ctConnection = new CustomTabsServiceConnection() {
@Override public void onCustomTabsServiceConnected(ComponentName componentName,
CustomTabsClient customTabsClient) {
customTabsClient.warmup(0);
customTabsSession = getSession(customTabsClient);
customTabsSession.mayLaunchUrl(Uri.parse(url), null, null);
}
@Override public void onServiceDisconnected(ComponentName name) {
}
};
CustomTabsClient.bindCustomTabsService(context, CHROME_PACKAGE, ctConnection);
}
示例10: shouldUnbind
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
@Test
public void shouldUnbind() throws Exception {
bindService(true);
connectBoundService();
controller.unbindService();
verify(context).unbindService(serviceConnectionCaptor.capture());
final CustomTabsServiceConnection connection = serviceConnectionCaptor.getValue();
CustomTabsServiceConnection controllerConnection = controller;
assertThat(connection, is(equalTo(controllerConnection)));
}
示例11: bindCustomTabsService
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
/**
* Binds the activity to the Custom Tabs service.
*
* @param activity Activity to be connected to Custom Tabs service.
* @param callback Connection callback to be bound.
*/
public void bindCustomTabsService(Activity activity, CustomTabsConnectionCallback callback) {
if (client == null) {
String packageName = CustomTabsUtils.getPackageNameToUse(activity);
if (packageName != null) {
connectionCallback = callback;
connection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
client = customTabsClient;
if (client.warmup(0)) {
Timber.d("Client warmed up.");
} else {
Timber.d("Client not warmed up.");
}
getSession();
if (connectionCallback != null) {
connectionCallback.onCustomTabsConnected();
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
client = null;
if (connectionCallback != null) {
connectionCallback.onCustomTabsDisconnected();
}
}
};
CustomTabsClient.bindCustomTabsService(activity, packageName, connection);
}
Timber.d("Bound Custom Tabs service.");
}
}
示例12: provideClient
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
private void provideClient() {
CustomTabsServiceConnection conn = mConnectionCaptor.getValue();
conn.onCustomTabsServiceConnected(
new ComponentName(BROWSER_PACKAGE_NAME, BROWSER_PACKAGE_NAME + ".CustomTabsService"),
mClient);
}
示例13: connectBoundService
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
private void connectBoundService() {
CustomTabsServiceConnection conn = serviceConnectionCaptor.getValue();
conn.onCustomTabsServiceConnected(new ComponentName(DEFAULT_BROWSER_PACKAGE, DEFAULT_BROWSER_PACKAGE + ".CustomTabsService"), customTabsClient);
verify(customTabsClient).newSession(Matchers.<CustomTabsCallback>eq(null));
verify(customTabsClient).warmup(eq(0L));
}
示例14: onCreate
import android.support.customtabs.CustomTabsServiceConnection; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_tabs);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
/*
Setup Chrome Custom Tabs
*/
mCustomTabsServiceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
//Pre-warming
mClient = customTabsClient;
mClient.warmup(0L);
//Initialize a session as soon as possible.
mCustomTabsSession = mClient.newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mClient = null;
}
};
CustomTabsClient.bindCustomTabsService(CustomTabsActivity.this, CUSTOM_TAB_PACKAGE_NAME, mCustomTabsServiceConnection);
customTabsIntent = new CustomTabsIntent.Builder(mCustomTabsSession)
.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setShowTitle(true)
.build();
/*
End custom tabs setup
*/
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Launch Chrome Custom Tabs on click
customTabsIntent.launchUrl(CustomTabsActivity.this, Uri.parse(URL));
}
});
}