use of android.support.customtabs.CustomTabsClient in project LeafPic by HoraApps.
the class CustomTabService method init.
private void init() {
mCustomTabsServiceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
mCustomTabsClient = customTabsClient;
mCustomTabsClient.warmup(0L);
mCustomTabsSession = mCustomTabsClient.newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mCustomTabsClient = null;
}
};
CustomTabsClient.bindCustomTabsService(activity, activity.getPackageName(), mCustomTabsServiceConnection);
mCustomTabsIntent = new CustomTabsIntent.Builder(mCustomTabsSession).setShowTitle(true).setToolbarColor(color).build();
}
use of android.support.customtabs.CustomTabsClient in project OneSignal-Android-SDK by OneSignal.
the class ShadowCustomTabsClient method bindCustomTabsService.
public static boolean bindCustomTabsService(Context context, String packageName, final CustomTabsServiceConnection connection) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Constructor<CustomTabsClient> constructor = CustomTabsClient.class.getDeclaredConstructor(ICustomTabsService.class, ComponentName.class);
constructor.setAccessible(true);
CustomTabsClient inst = constructor.newInstance(null, null);
bindCustomTabsServiceCalled = true;
connection.onCustomTabsServiceConnected(null, inst);
} catch (Throwable t) {
// Catch any errors and make it interrupt all other threads to force the unit test to fail.
t.printStackTrace();
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
for (Thread thread : threadSet) {
if (thread.getId() != Thread.currentThread().getId())
thread.interrupt();
}
}
}
}, "OS_SHADOW_BIND_CUSTOM_TABS").start();
return true;
}
use of android.support.customtabs.CustomTabsClient in project LeafPic by HoraApps.
the class ChromeCustomTabs method initService.
private void initService() {
serviceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
customTabsClient.warmup(0L);
}
@Override
public void onServiceDisconnected(ComponentName name) {
// NO-OP
}
};
// Bind the Chrome Custom Tabs service
CustomTabsClient.bindCustomTabsService(context, ApplicationUtils.getPackageName(), serviceConnection);
mCustomTabsIntent = new CustomTabsIntent.Builder().setShowTitle(true).setToolbarColor(toolbarColor).build();
}
use of android.support.customtabs.CustomTabsClient in project plaid by nickbutcher.
the class CustomTabActivityHelper method bindCustomTabsService.
/**
* Binds the Activity to the Custom Tabs Service
* @param activity the activity to be bound to the service
*/
public void bindCustomTabsService(Activity activity) {
if (mClient != null)
return;
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
if (packageName == null)
return;
mConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
mClient = client;
mClient.warmup(0L);
if (mConnectionCallback != null)
mConnectionCallback.onCustomTabsConnected();
//Initialize a session as soon as possible.
getSession();
}
@Override
public void onServiceDisconnected(ComponentName name) {
mClient = null;
if (mConnectionCallback != null)
mConnectionCallback.onCustomTabsDisconnected();
}
};
CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
use of android.support.customtabs.CustomTabsClient in project Reader by TheKeeperOfPie.
the class ActivityMain method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
componentActivity = (ComponentActivity) getLastCustomNonConfigurationInstance();
if (componentActivity == null) {
componentActivity = CustomApplication.getComponentMain().componentActivity();
}
componentActivity.inject(this);
themer = new Themer(this);
int colorResourcePrimary = UtilsColor.showOnWhite(themer.getColorPrimary()) ? R.color.darkThemeIconFilter : R.color.lightThemeIconFilter;
int resourceIcon = UtilsColor.showOnWhite(themer.getColorPrimary()) ? R.mipmap.app_icon_white_outline : R.mipmap.app_icon_dark_outline;
colorFilterPrimary = new CustomColorFilter(ContextCompat.getColor(this, colorResourcePrimary), PorterDuff.Mode.MULTIPLY);
/**
* Required for {@link YouTubePlayerSupportFragment} to inflate proper UI
*/
getLayoutInflater().setFactory(this);
super.onCreate(savedInstanceState);
handler = new Handler();
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
inflateNavigationDrawer();
Receiver.setAlarm(this);
layoutDrawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerClosed(View drawerView) {
if (loadId != 0) {
selectNavigationItem(loadId, null, true);
}
setAccountsVisible(false);
}
});
eventListenerBase = new EventListenerBase(componentActivity) {
@Override
public void onClickComments(Link link, AdapterLink.ViewHolderLink viewHolderLink, Source source) {
int color = viewHolderLink.getBackgroundColor();
FragmentBase fragment = (FragmentBase) getSupportFragmentManager().findFragmentById(R.id.frame_fragment);
fragment.onWindowTransitionStart();
FragmentComments fragmentComments = FragmentComments.newInstance(viewHolderLink, color);
fragmentComments.setFragmentToHide(fragment, viewHolderLink.itemView);
getSupportFragmentManager().beginTransaction().add(R.id.frame_fragment, fragmentComments, FragmentComments.TAG).addToBackStack(null).commit();
controllerCommentsTop.setLink(link, source);
}
@Override
public void loadUrl(String urlString) {
if (sharedPreferences.getBoolean(AppSettings.PREF_EXTERNAL_BROWSER, false)) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(urlString));
startActivity(intent);
return;
}
Log.d(TAG, "loadUrl: " + loadId);
URL url = null;
try {
url = new URL(urlString);
} catch (MalformedURLException e) {
e.printStackTrace();
}
if (url != null && url.getHost().contains("reddit.com")) {
Intent intent = new Intent(ActivityMain.this, ActivityMain.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(REDDIT_PAGE, urlString);
startActivity(intent);
return;
}
launchUrl(urlString, false);
}
@Override
public void downloadImage(String title, String fileName, String url) {
imageDownload = new ImageDownload(title, fileName, url);
ActivityCompat.requestPermissions(ActivityMain.this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE);
}
@Override
public void editLink(Link link) {
FragmentNewPost fragmentNewPost = FragmentNewPost.newInstanceEdit(controllerUser.getUser().getName(), link);
getSupportFragmentManager().beginTransaction().hide(getSupportFragmentManager().findFragmentById(R.id.frame_fragment)).add(R.id.frame_fragment, fragmentNewPost, FragmentNewPost.TAG).addToBackStack(null).commit();
}
@Override
public void showReplyEditor(Replyable replyable) {
FragmentReply fragmentReply = FragmentReply.newInstance(replyable);
fragmentReply.setFragmentToHide(getSupportFragmentManager().findFragmentById(R.id.frame_fragment));
getSupportFragmentManager().beginTransaction().add(R.id.frame_fragment, fragmentReply, FragmentReply.TAG).addToBackStack(null).commit();
}
@Override
public void loadWebFragment(String url) {
launchUrl(url, false);
}
@Override
public void launchScreen(Intent intent) {
startActivity(intent);
}
};
eventListenerComment = (comment, subreddit, linkId) -> {
if (comment.getCount() == 0) {
Intent intentCommentThread = new Intent(ActivityMain.this, ActivityMain.class);
intentCommentThread.setAction(Intent.ACTION_VIEW);
// Double slashes used to trigger parseUrl correctly
intentCommentThread.putExtra(REDDIT_PAGE, Reddit.BASE_URL + "/r/" + subreddit + "/comments/" + linkId + "/title/" + comment.getParentId() + "/");
startActivity(intentCommentThread);
return true;
}
return false;
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Reader", BitmapFactory.decodeResource(getResources(), resourceIcon), themer.getColorPrimary());
setTaskDescription(taskDescription);
}
customTabsServiceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
customTabsClient.warmup(0);
customTabsSession = customTabsClient.newSession(new CustomTabsCallback() {
@Override
public void onNavigationEvent(int navigationEvent, Bundle extras) {
super.onNavigationEvent(navigationEvent, extras);
Log.d(TAG, "onNavigationEvent() called with: " + "navigationEvent = [" + navigationEvent + "], extras = [" + extras + "]");
}
@Override
public void extraCallback(String callbackName, Bundle args) {
super.extraCallback(callbackName, args);
Log.d(TAG, "extraCallback() called with: " + "callbackName = [" + callbackName + "], args = [" + args + "]");
}
});
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
};
CustomTabsClient.bindCustomTabsService(this, getPackageName(), customTabsServiceConnection);
handleFirstLaunch(savedInstanceState);
showBetaNotice();
loadAccount();
UtilsImage.checkMaxTextureSize(handler, () -> {
});
}
Aggregations