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) {
}
}
});
}
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);
}
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());
}
}
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;
}
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();
}
});
}
}
Aggregations