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


Java CustomTabsServiceConnection類代碼示例

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

示例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());
}
 
開發者ID:openid,項目名稱:AppAuth-Android,代碼行數:22,代碼來源:AuthorizationServiceTest.java

示例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;
}
 
開發者ID:pumpkinz,項目名稱:pumpkin-reader,代碼行數:23,代碼來源:ActionUtil.java

示例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;
}
 
開發者ID:eliseomartelli,項目名稱:SimpleCustomTabs,代碼行數:26,代碼來源:CustomTabs.java

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

示例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();
}
 
開發者ID:pennlabs,項目名稱:penn-mobile-android,代碼行數:20,代碼來源:NewsFragment.java

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

示例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
}
 
開發者ID:MaximilianKeppeler,項目名稱:Places,代碼行數:32,代碼來源:Utils.java

示例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);
}
 
開發者ID:Aptoide,項目名稱:aptoide-client-v8,代碼行數:15,代碼來源:CustomTabsHelper.java

示例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)));
}
 
開發者ID:auth0,項目名稱:Auth0.Android,代碼行數:12,代碼來源:CustomTabsControllerTest.java

示例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.");
    }
}
 
開發者ID:tjyu1040,項目名稱:GallyShuttle,代碼行數:40,代碼來源:CustomTabsWarmUpService.java

示例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);
}
 
開發者ID:openid,項目名稱:AppAuth-Android,代碼行數:7,代碼來源:CustomTabManagerTest.java

示例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));
}
 
開發者ID:auth0,項目名稱:Auth0.Android,代碼行數:7,代碼來源:CustomTabsControllerTest.java

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

        }
    });


}
 
開發者ID:Suleiman19,項目名稱:Marshmallow-Sample,代碼行數:54,代碼來源:CustomTabsActivity.java


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