Search in sources :

Example 6 with CustomTabsIntent

use of android.support.customtabs.CustomTabsIntent in project muzei by romannurik.

the class AboutActivity method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about_activity);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    ((Toolbar) findViewById(R.id.app_bar)).setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onNavigateUp();
        }
    });
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.demo_view_container, MuzeiRendererFragment.createInstance(true, false)).commit();
    }
    // Get app version
    PackageManager pm = getPackageManager();
    String packageName = getPackageName();
    String versionName;
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionName = VERSION_UNAVAILABLE;
    }
    // Build the about body view and append the link to see OSS licenses
    TextView versionView = (TextView) findViewById(R.id.app_version);
    versionView.setText(Html.fromHtml(getString(R.string.about_version_template, versionName)));
    TextView aboutBodyView = (TextView) findViewById(R.id.about_body);
    aboutBodyView.setText(Html.fromHtml(getString(R.string.about_body)));
    aboutBodyView.setMovementMethod(new LinkMovementMethod());
    findViewById(R.id.android_experiment_link).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CustomTabsIntent cti = new CustomTabsIntent.Builder().setShowTitle(true).setToolbarColor(ContextCompat.getColor(AboutActivity.this, R.color.theme_primary)).build();
            try {
                cti.launchUrl(AboutActivity.this, Uri.parse("https://www.androidexperiments.com/experiment/muzei"));
            } catch (ActivityNotFoundException ignored) {
            }
        }
    });
}
Also used : PackageInfo(android.content.pm.PackageInfo) LinkMovementMethod(android.text.method.LinkMovementMethod) TextView(android.widget.TextView) View(android.view.View) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PackageManager(android.content.pm.PackageManager) ActivityNotFoundException(android.content.ActivityNotFoundException) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar)

Example 7 with CustomTabsIntent

use of android.support.customtabs.CustomTabsIntent in project facebook-android-sdk by facebook.

the class CustomTab method openCustomTab.

public void openCustomTab(Activity activity, String packageName) {
    CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
    customTabsIntent.intent.setPackage(packageName);
    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    customTabsIntent.launchUrl(activity, uri);
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent)

Example 8 with CustomTabsIntent

use of android.support.customtabs.CustomTabsIntent in project Tusky by Vavassor.

the class CustomTabURLSpan method onClick.

@Override
public void onClick(View widget) {
    Uri uri = Uri.parse(getURL());
    Context context = widget.getContext();
    boolean lightTheme = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("lightTheme", false);
    int toolbarColor = ContextCompat.getColor(context, lightTheme ? R.color.custom_tab_toolbar_light : R.color.custom_tab_toolbar_dark);
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(toolbarColor);
    CustomTabsIntent customTabsIntent = builder.build();
    try {
        String packageName = CustomTabsHelper.getPackageNameToUse(context);
        //Chrome Custom Tabs installed. So, we fallback to the webview
        if (packageName == null) {
            super.onClick(widget);
        } else {
            customTabsIntent.intent.setPackage(packageName);
            customTabsIntent.launchUrl(context, uri);
        }
    } catch (ActivityNotFoundException e) {
        Log.w("URLSpan", "Activity was not found for intent, " + customTabsIntent.toString());
    }
}
Also used : Context(android.content.Context) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) ActivityNotFoundException(android.content.ActivityNotFoundException) Uri(android.net.Uri)

Example 9 with CustomTabsIntent

use of android.support.customtabs.CustomTabsIntent in project Tusky by Vavassor.

the class LoginActivity method openInCustomTab.

private static boolean openInCustomTab(Uri uri, Context context) {
    boolean lightTheme = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("lightTheme", false);
    int toolbarColorRes;
    if (lightTheme) {
        toolbarColorRes = R.color.custom_tab_toolbar_light;
    } else {
        toolbarColorRes = R.color.custom_tab_toolbar_dark;
    }
    int toolbarColor = ContextCompat.getColor(context, toolbarColorRes);
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(toolbarColor);
    CustomTabsIntent customTabsIntent = builder.build();
    try {
        String packageName = CustomTabsHelper.getPackageNameToUse(context);
        /* If we cant find a package name, it means theres no browser that supports
             * Chrome Custom Tabs installed. So, we fallback to the webview */
        if (packageName == null) {
            return false;
        } else {
            customTabsIntent.intent.setPackage(packageName);
            customTabsIntent.launchUrl(context, uri);
        }
    } catch (ActivityNotFoundException e) {
        Log.w("URLSpan", "Activity was not found for intent, " + customTabsIntent.toString());
        return false;
    }
    return true;
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 10 with CustomTabsIntent

use of android.support.customtabs.CustomTabsIntent in project muzei by romannurik.

the class FeaturedArtSource method onCustomCommand.

@Override
protected void onCustomCommand(int id) {
    super.onCustomCommand(id);
    if (COMMAND_ID_SHARE == id) {
        Artwork currentArtwork = getCurrentArtwork();
        if (currentArtwork == null) {
            Log.w(TAG, "No current artwork, can't share.");
            new Handler(Looper.getMainLooper()).post(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(FeaturedArtSource.this, R.string.featuredart_source_error_no_artwork_to_share, Toast.LENGTH_SHORT).show();
                }
            });
            return;
        }
        String detailUrl = ("initial".equals(currentArtwork.getToken())) ? "http://www.wikipaintings.org/en/vincent-van-gogh/the-starry-night-1889" : currentArtwork.getViewIntent().getDataString();
        String artist = currentArtwork.getByline().replaceFirst("\\.\\s*($|\\n).*", "").trim();
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, "My Android wallpaper today is '" + currentArtwork.getTitle().trim() + "' by " + artist + ". #MuzeiFeaturedArt\n\n" + detailUrl);
        shareIntent = Intent.createChooser(shareIntent, "Share artwork");
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(shareIntent);
    } else if (COMMAND_ID_VIEW_ARCHIVE == id) {
        CustomTabsIntent cti = new CustomTabsIntent.Builder().setShowTitle(true).setToolbarColor(ContextCompat.getColor(this, R.color.featuredart_color)).build();
        Intent intent = cti.intent;
        intent.setData(ARCHIVE_URI);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    } else if (COMMAND_ID_DEBUG_INFO == id) {
        long nextUpdateTimeMillis = getSharedPreferences().getLong("scheduled_update_time_millis", 0);
        final String nextUpdateTime;
        if (nextUpdateTimeMillis > 0) {
            Date d = new Date(nextUpdateTimeMillis);
            nextUpdateTime = SimpleDateFormat.getDateTimeInstance().format(d);
        } else {
            nextUpdateTime = "None";
        }
        new Handler(Looper.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(FeaturedArtSource.this, "Next update time: " + nextUpdateTime, Toast.LENGTH_LONG).show();
            }
        });
    }
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Artwork(com.google.android.apps.muzei.api.Artwork) Handler(android.os.Handler) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) Date(java.util.Date)

Aggregations

CustomTabsIntent (android.support.customtabs.CustomTabsIntent)12 Intent (android.content.Intent)7 PendingIntent (android.app.PendingIntent)3 ActivityNotFoundException (android.content.ActivityNotFoundException)3 Context (android.content.Context)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)1 Toolbar (android.support.v7.widget.Toolbar)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 LinkMovementMethod (android.text.method.LinkMovementMethod)1 View (android.view.View)1 TextView (android.widget.TextView)1 BillingActivity (com.battlelancer.seriesguide.billing.BillingActivity)1 AmazonBillingActivity (com.battlelancer.seriesguide.billing.amazon.AmazonBillingActivity)1 Artwork (com.google.android.apps.muzei.api.Artwork)1 Date (java.util.Date)1