android.support.customtabs.CustomTabsSession Java Examples

The following examples show how to use android.support.customtabs.CustomTabsSession. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PwaWrapperSplashScreenStrategy.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
@Override
public void configureTwaBuilder(TrustedWebActivityIntentBuilder builder,
        CustomTabsSession session,
        Runnable onReadyCallback) {
    if (!mProviderSupportsSplashScreens || mSplashImage == null) {
        onReadyCallback.run();
        return;
    }
    if (TextUtils.isEmpty(mFileProviderAuthority)) {
        Log.w(TAG, "FileProvider authority not specified, can't transfer splash image.");
        onReadyCallback.run();
        return;
    }
    mSplashImageTransferTask = new SplashImageTransferTask(mActivity,
            mSplashImage, mFileProviderAuthority, session,
            mProviderPackage);

    mSplashImageTransferTask.execute(
            success -> onSplashImageTransferred(builder, success, onReadyCallback));
}
 
Example #2
Source File: DesignerNewsStory.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #3
Source File: TrustedWebActivityIntentBuilder.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the Intent.
 *
 * @param session The {@link CustomTabsSession} to use for launching a Trusted Web Activity.
 */
public Intent build(CustomTabsSession session) {
    if (session == null) {
        throw new NullPointerException("CustomTabsSession is required for launching a TWA");
    }

    mIntentBuilder.setSession(session);
    Intent intent = mIntentBuilder.build().intent;
    intent.setData(mUri);
    intent.putExtra(TrustedWebUtils.EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true);
    if (mAdditionalTrustedOrigins != null) {
        intent.putExtra(TrustedWebUtils.EXTRA_ADDITIONAL_TRUSTED_ORIGINS,
                new ArrayList<>(mAdditionalTrustedOrigins));
    }

    if (mSplashScreenParams != null) {
        intent.putExtra(TrustedWebUtils.EXTRA_SPLASH_SCREEN_PARAMS, mSplashScreenParams);
    }
    return intent;
}
 
Example #4
Source File: CustomTabConnectionRule.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
/**
 * Binds the CustomTabsService, creates a {@link CustomTabsSession} and returns it.
 */
public CustomTabsSession establishSessionBlocking(Context context) {
    mContext = context;
    if (!CustomTabsClient.bindCustomTabsService(context, context.getPackageName(),
            mConnection)) {
        fail("Failed to bind the service");
        return null;
    }
    boolean success = false;
    try {
        success = mConnectionLatch.await(2, TimeUnit.SECONDS);
    } catch (InterruptedException e) {}
    if (!success) {
        fail("Failed to connect to service");
        return null;
    }
    return mSession;
}
 
Example #5
Source File: BottomBarManager.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #6
Source File: Browser.java    From OsmGo with MIT License 6 votes vote down vote up
@PluginMethod()
public void prefetch(PluginCall call) {
  JSArray urls = call.getArray("urls");
  if (urls == null || urls.length() == 0) {
    call.error("Must provide an array of URLs to prefetch");
    return;
  }

  CustomTabsSession session = getCustomTabsSession();

  if (session == null) {
    call.error("Browser session isn't ready yet");
    return;
  }

  try {
    for (String url : urls.<String>toList()) {
      session.mayLaunchUrl(Uri.parse(url), null, null);
    }
  } catch(JSONException ex) {
    call.error("Unable to process provided urls list. Ensure each item is a string and valid URL", ex);
    return;
  }
}
 
Example #7
Source File: ChromeCustomTabsHelper.java    From Hews with MIT License 5 votes vote down vote up
/**
 * Creates or retrieves an exiting CustomTabsSession
 *
 * @return a CustomTabsSession
 */
public CustomTabsSession getSession() {
    if (mCustomTabsClient == null) {
        mCustomTabsSession = null;
    } else if (mCustomTabsSession == null) {
        mCustomTabsSession = mCustomTabsClient.newSession(null);
    }
    return mCustomTabsSession;
}
 
Example #8
Source File: MainActivity.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
private CustomTabsSession getSession() {
    if (mClient == null) {
        mCustomTabsSession = null;
    } else if (mCustomTabsSession == null) {
        mCustomTabsSession = mClient.newSession(new NavigationCallback());
        SessionHelper.setCurrentSession(mCustomTabsSession);
    }
    return mCustomTabsSession;
}
 
Example #9
Source File: ChromeCustomTabsHelper.java    From Hews with MIT License 5 votes vote down vote up
public boolean mayLaunchUrl(Uri uri, Bundle extras, List<Bundle> otherLikelyBundles) {
    if (mCustomTabsClient == null) return false;

    CustomTabsSession session = getSession();
    if (session == null) return false;

    return session.mayLaunchUrl(uri, extras, otherLikelyBundles);
}
 
Example #10
Source File: CustomTabServiceHelper.java    From cordova-plugin-safariviewcontroller with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: CustomTabActivityHelper.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #12
Source File: SplashImageTransferTask.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
/**
 * @param context {@link Context} to use.
 * @param bitmap image to transfer.
 * @param authority {@link FileProvider} authority.
 * @param session {@link CustomTabsSession} to use for transferring the file.
 * @param providerPackage Package name of the Custom Tabs provider.
 */
public SplashImageTransferTask(Context context, Bitmap bitmap, String authority,
        CustomTabsSession session, String providerPackage) {
    mContext = context.getApplicationContext();
    mBitmap = bitmap;
    mAuthority = authority;
    mSession = session;
    mProviderPackage = providerPackage;
}
 
Example #13
Source File: CustomTabServiceHelper.java    From cordova-plugin-safariviewcontroller with MIT License 5 votes vote down vote up
/**
 * @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);
}
 
Example #14
Source File: CustomTabActivityHelper.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #15
Source File: CustomTabActivityHelper.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #16
Source File: CustomTabsClientHelper.java    From azure-mobile-apps-android-client with Apache License 2.0 5 votes vote down vote up
CustomTabsIntent.Builder createCustomTabsIntentBuilder() {
    CustomTabsSession session = null;
    if (mCustomTabsClient != null) {
        session = mCustomTabsClient.newSession(null);
    }

    return new CustomTabsIntent.Builder(session);
}
 
Example #17
Source File: CustomTabActivityHelper.java    From droidddle with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #18
Source File: CustomTabActivityHelper.java    From droidddle with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: CustomTabActivityHelper.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #20
Source File: CustomTabActivityHelper.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #21
Source File: ChromeCustomTabPlugin.java    From cordova-plugin-safariviewcontroller with MIT License 5 votes vote down vote up
private boolean mayLaunchUrl(String url){
    boolean success = false;
    if (mCustomTabPluginHelper.getClient() != null) {
        CustomTabsSession session = getSession();
        success = session.mayLaunchUrl(Uri.parse(url), null, null);
    }

    return success;
}
 
Example #22
Source File: CustomTabsOptions.java    From Auth0.Android with MIT License 5 votes vote down vote up
@SuppressLint("ResourceType")
Intent toIntent(Context context, CustomTabsSession session) {
    final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(session)
            .setShowTitle(showTitle);
    if (toolbarColor > 0) {
        //Resource exists
        builder.setToolbarColor(ContextCompat.getColor(context, toolbarColor));
    }
    return builder.build().intent;
}
 
Example #23
Source File: CustomTabActivityHelper.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #24
Source File: CustomTabActivityHelper.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #25
Source File: CustomTabActivityHelper.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #26
Source File: Browser.java    From OsmGo with MIT License 5 votes vote down vote up
public CustomTabsSession getCustomTabsSession() {
  if (customTabsClient == null) {
    return null;
  }

  if (currentSession == null) {
    currentSession = customTabsClient.newSession(new CustomTabsCallback(){
      @Override
      public void onNavigationEvent(int navigationEvent, Bundle extras) {
        switch (navigationEvent) {
          case NAVIGATION_FINISHED:
            notifyListeners("browserPageLoaded", new JSObject());
            break;
        }
      }
    });
  }

  return currentSession;
}
 
Example #27
Source File: CustomTabActivityHelper.java    From materialup with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #28
Source File: CustomTabActivityHelper.java    From materialup with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #29
Source File: ChromeCustomTabsManager.java    From Anecdote with Apache License 2.0 5 votes vote down vote up
private CustomTabsSession getSession() {
    if (mClient == null) {
        mCustomTabsSession = null;
    } else if (mCustomTabsSession == null) {
        mCustomTabsSession = mClient.newSession(new CustomTabsCallback());
    }
    return mCustomTabsSession;
}
 
Example #30
Source File: ChromeCustomTabsManager.java    From Anecdote with Apache License 2.0 5 votes vote down vote up
/**
 * Prevent the Chrome client that the given url may be opened.
 */
public void mayLaunch(String url) {
    if (mClient == null || url == null) {
        return;
    }
    Log.i(TAG, "mayLaunch " + url);
    CustomTabsSession session = getSession();
    session.mayLaunchUrl(Uri.parse(url), null, null);
}