1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 12:22:08 +01:00

Preference option - Chrome Custom Tab

This commit is contained in:
Gregor Santner 2016-09-18 23:17:18 +02:00
parent ef0e1b792a
commit 67c416f870
11 changed files with 89 additions and 49 deletions

View file

@ -256,6 +256,10 @@ public class AppSettings {
return getBoolean(prefApp, R.string.pref_key__intellihide_toolbars, true); return getBoolean(prefApp, R.string.pref_key__intellihide_toolbars, true);
} }
public boolean isChromeCustomTabsEnabled() {
return getBoolean(prefApp, R.string.pref_key__chrome_custom_tabs_enabled, true);
}
public boolean isVisibleInNavExit() { public boolean isVisibleInNavExit() {
return getBoolean(prefApp, R.string.pref_key__visibility_nav__exit, false); return getBoolean(prefApp, R.string.pref_key__visibility_nav__exit, false);
} }

View file

@ -7,14 +7,15 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.support.customtabs.CustomTabsIntent; import android.support.customtabs.CustomTabsIntent;
import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.activity.MainActivity; import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback; import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback;
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper; import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.Log; import com.github.dfa.diaspora_android.util.Log;
/** /**
@ -29,22 +30,38 @@ public class OpenExternalLinkReceiver extends BroadcastReceiver {
} }
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context c, Intent receiveIntent) {
String url = intent.getStringExtra(MainActivity.EXTRA_URL); AppSettings settings = new AppSettings(c);
Log.v(App.TAG, "OpenExternalLinkReceiver.onReceive(): url"); Log.v(App.TAG, "OpenExternalLinkReceiver.onReceive(): url");
if(url != null) {
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder(); Uri url = null;
if(Build.VERSION.SDK_INT >= 23) { try {
intentBuilder.setToolbarColor(context.getResources().getColor(R.color.colorPrimary, context.getTheme())); String sUrl = receiveIntent.getStringExtra(MainActivity.EXTRA_URL);
} else { url = Uri.parse(sUrl);
intentBuilder.setToolbarColor(context.getResources().getColor(R.color.colorPrimary)); } catch (Exception _ignored) {
Log.v(App.TAG, "Could not open Chrome Custom Tab (bad URL)");
return;
} }
intentBuilder.setStartAnimations(context, android.R.anim.slide_in_left, android.R.anim.fade_out);
intentBuilder.setExitAnimations(context, android.R.anim.fade_in, android.R.anim.slide_out_right); if (settings.isChromeCustomTabsEnabled()) {
Bitmap backButtonIcon = BitmapFactory.decodeResource(context.getResources(), // Setup Chrome Custom Tab
R.drawable.ic_arrow_back_white_24px); CustomTabsIntent.Builder customTab = new CustomTabsIntent.Builder();
intentBuilder.setCloseButtonIcon(backButtonIcon); customTab.setToolbarColor(Helpers.getColorFromRessource(c, R.color.colorPrimary));
CustomTabActivityHelper.openCustomTab(parent, intentBuilder.build(), Uri.parse(url), new BrowserFallback()); customTab.setStartAnimations(c, android.R.anim.slide_in_left, android.R.anim.fade_out);
customTab.setExitAnimations(c, android.R.anim.fade_in, android.R.anim.slide_out_right);
customTab.addDefaultShareMenuItem();
Bitmap backButtonIcon = BitmapFactory.decodeResource(c.getResources(), R.drawable.chrome_custom_tab__back);
customTab.setCloseButtonIcon(backButtonIcon);
// Launch Chrome Custom Tab
CustomTabActivityHelper.openCustomTab(parent, customTab.build(), url, new BrowserFallback());
} else {
// Open in normal browser (via intent)
Intent openBrowserIntent = new Intent(Intent.ACTION_VIEW, url);
openBrowserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
c.startActivity(openBrowserIntent);
} }
} }
} }

View file

@ -21,10 +21,11 @@ package com.github.dfa.diaspora_android.util;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import com.github.dfa.diaspora_android.util.Log;
import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.R;
@ -37,7 +38,6 @@ import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
public class Helpers { public class Helpers {
@ -51,6 +51,15 @@ public class Helpers {
} }
} }
public static int getColorFromRessource(Context context, int ressourceId) {
Resources res = context.getResources();
if (Build.VERSION.SDK_INT >= 23) {
return res.getColor(ressourceId, context.getTheme());
} else {
return res.getColor(ressourceId);
}
}
public static void loadUrlInExternalBrowser(Context context, String url) { public static void loadUrlInExternalBrowser(Context context, String url) {
try { try {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
@ -66,7 +75,7 @@ public class Helpers {
Log.d(App.TAG, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()); Log.d(App.TAG, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
File storageDir = Environment.getExternalStoragePublicDirectory( File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES); Environment.DIRECTORY_PICTURES);
return new File ( return new File(
imageFileName + /* prefix */ imageFileName + /* prefix */
".jpg", /* suffix */ ".jpg", /* suffix */
storageDir.getAbsolutePath() /* directory */ storageDir.getAbsolutePath() /* directory */
@ -100,22 +109,22 @@ public class Helpers {
return sb.toString(); return sb.toString();
} }
public static String hexColorFromRessourceColor(Context context, int idColor){ public static String hexColorFromRessourceColor(Context context, int idColor) {
return "#" + Integer.toHexString(context.getResources().getColor(idColor) & 0x00ffffff); return "#" + Integer.toHexString(context.getResources().getColor(idColor) & 0x00ffffff);
} }
public static void printBundle(Bundle savedInstanceState, String k) { public static void printBundle(Bundle savedInstanceState, String k) {
if(savedInstanceState != null) { if (savedInstanceState != null) {
for (String key : savedInstanceState.keySet()) { for (String key : savedInstanceState.keySet()) {
Log.d("SAVED", key + " is a key in the bundle "+k); Log.d("SAVED", key + " is a key in the bundle " + k);
Object bun = savedInstanceState.get(key); Object bun = savedInstanceState.get(key);
if(bun != null) { if (bun != null) {
if (bun instanceof Bundle) { if (bun instanceof Bundle) {
printBundle((Bundle) bun, k + "." + key); printBundle((Bundle) bun, k + "." + key);
} else if (bun instanceof byte[]) { } else if (bun instanceof byte[]) {
Log.d("SAVED", "Key: "+k + "." + key+": "+ Arrays.toString((byte[])bun)); Log.d("SAVED", "Key: " + k + "." + key + ": " + Arrays.toString((byte[]) bun));
} else { } else {
Log.d("SAVED", "Key: "+k + "." + key+": "+ bun.toString()); Log.d("SAVED", "Key: " + k + "." + key + ": " + bun.toString());
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

View file

@ -14,6 +14,7 @@
<string name="pref_catkey__network" translatable="false">pref_key_category_network</string> <string name="pref_catkey__network" translatable="false">pref_key_category_network</string>
<string name="pref_key__load_images" translatable="false">pref_key_load_images</string> <string name="pref_key__load_images" translatable="false">pref_key_load_images</string>
<string name="pref_key__clear_cache" translatable="false">pref_key_clear_cache</string> <string name="pref_key__clear_cache" translatable="false">pref_key_clear_cache</string>
<string name="pref_key__chrome_custom_tabs_enabled">pref_key__chrome_custom_tabs_enabled</string>
<string name="pref_key__append_shared_via_app" translatable="false">pref_key_append_shared_via_app</string> <string name="pref_key__append_shared_via_app" translatable="false">pref_key_append_shared_via_app</string>
<string name="pref_key__proxy_enabled" translatable="false">pref_key_proxy_enabled</string> <string name="pref_key__proxy_enabled" translatable="false">pref_key_proxy_enabled</string>
@ -82,6 +83,10 @@
<string name="pref_title__proxy_port">Port</string> <string name="pref_title__proxy_port">Port</string>
<!-- Chrome custom tabs -->
<string name="pref_title__chrome_custom_tabs_enabled">Chrome Custom Tabs</string>
<string name="pref_desc__chrome_custom_tabs_enabled">Open external links with Chrome Custom Tabs. Chromium or Google Chrome needs to be installed for this feature</string>
<!-- Diaspora Settings --> <!-- Diaspora Settings -->
<string name="pref_title__personal_settings">Personal settings</string> <string name="pref_title__personal_settings">Personal settings</string>
<string name="pref_desc__personal_settings">Open your Diaspora account settings</string> <string name="pref_desc__personal_settings">Open your Diaspora account settings</string>

View file

@ -103,5 +103,4 @@
Diaspora. In the permissions section you can grant the \"write storage permission\".</string> Diaspora. In the permissions section you can grant the \"write storage permission\".</string>
<string name="permission_denied">Permission denied.</string> <string name="permission_denied">Permission denied.</string>
<string name="permission_granted_try_again">Permission granted. Please try again.</string> <string name="permission_granted_try_again">Permission granted. Please try again.</string>
</resources> </resources>

View file

@ -16,43 +16,43 @@
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__profile" android:key="@string/pref_key__visibility_nav__profile"
android:title="@string/nav_profile" /> android:title="@string/nav_profile"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__followed_tags" android:key="@string/pref_key__visibility_nav__followed_tags"
android:title="@string/nav_followed_tags" /> android:title="@string/nav_followed_tags"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__aspects" android:key="@string/pref_key__visibility_nav__aspects"
android:title="@string/nav_aspects" /> android:title="@string/nav_aspects"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__activities" android:key="@string/pref_key__visibility_nav__activities"
android:title="@string/nav_activities" /> android:title="@string/nav_activities"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__liked" android:key="@string/pref_key__visibility_nav__liked"
android:title="@string/nav_liked" /> android:title="@string/nav_liked"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__commented" android:key="@string/pref_key__visibility_nav__commented"
android:title="@string/nav_commented" /> android:title="@string/nav_commented"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__mentions" android:key="@string/pref_key__visibility_nav__mentions"
android:title="@string/nav_mentions" /> android:title="@string/nav_mentions"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__public_activities" android:key="@string/pref_key__visibility_nav__public_activities"
android:title="@string/nav_public_activities" /> android:title="@string/nav_public_activities"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__exit" android:key="@string/pref_key__visibility_nav__exit"
android:title="@string/action_exit_app" /> android:title="@string/action_exit_app"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__help_license" android:key="@string/pref_key__visibility_nav__help_license"
android:title="@string/nav_help_license" /> android:title="@string/nav_help_license"/>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>
@ -63,19 +63,25 @@
android:entryValues="@array/pref_entries_values__font_size" android:entryValues="@array/pref_entries_values__font_size"
android:key="@string/pref_key__font_size" android:key="@string/pref_key__font_size"
android:summary="%s" android:summary="%s"
android:title="@string/pref_title__font_size" /> android:title="@string/pref_title__font_size"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/pref_key__intellihide_toolbars" android:key="@string/pref_key__intellihide_toolbars"
android:summary="@string/pref_desc__intellihide_toolbars" android:summary="@string/pref_desc__intellihide_toolbars"
android:title="@string/pref_title__intellihide_toolbars" /> android:title="@string/pref_title__intellihide_toolbars"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key__append_shared_via_app" android:key="@string/pref_key__append_shared_via_app"
android:summary="@string/pref_desc__append_shared_via_app" android:summary="@string/pref_desc__append_shared_via_app"
android:title="@string/pref_title__append_shared_via_app" /> android:title="@string/pref_title__append_shared_via_app"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__chrome_custom_tabs_enabled"
android:summary="@string/pref_desc__chrome_custom_tabs_enabled"
android:title="@string/pref_title__chrome_custom_tabs_enabled"/>
</PreferenceCategory> </PreferenceCategory>
@ -86,22 +92,22 @@
<Preference <Preference
android:key="@string/pref_key__personal_settings" android:key="@string/pref_key__personal_settings"
android:summary="@string/pref_desc__personal_settings" android:summary="@string/pref_desc__personal_settings"
android:title="@string/pref_title__personal_settings" /> android:title="@string/pref_title__personal_settings"/>
<Preference <Preference
android:key="@string/pref_key__manage_tags" android:key="@string/pref_key__manage_tags"
android:summary="@string/pref_desc__manage_tags" android:summary="@string/pref_desc__manage_tags"
android:title="@string/pref_title__manage_tags" /> android:title="@string/pref_title__manage_tags"/>
<Preference <Preference
android:key="@string/pref_key__manage_contacts" android:key="@string/pref_key__manage_contacts"
android:summary="@string/pref_desc__manage_contacts" android:summary="@string/pref_desc__manage_contacts"
android:title="@string/pref_title__manage_contacts" /> android:title="@string/pref_title__manage_contacts"/>
<Preference <Preference
android:key="@string/pref_key__change_account" android:key="@string/pref_key__change_account"
android:summary="@string/pref_desc__change_account" android:summary="@string/pref_desc__change_account"
android:title="@string/pref_title__change_account" /> android:title="@string/pref_title__change_account"/>
</PreferenceCategory> </PreferenceCategory>
<!-- Networking --> <!-- Networking -->
@ -112,27 +118,27 @@
android:defaultValue="true" android:defaultValue="true"
android:key="@string/pref_key__load_images" android:key="@string/pref_key__load_images"
android:summary="@string/pref_desc__load_images" android:summary="@string/pref_desc__load_images"
android:title="@string/pref_title__load_images" /> android:title="@string/pref_title__load_images"/>
<Preference <Preference
android:key="@string/pref_key__clear_cache" android:key="@string/pref_key__clear_cache"
android:summary="@string/pref_desc__clear_cache" android:summary="@string/pref_desc__clear_cache"
android:title="@string/pref_title__clear_cache" /> android:title="@string/pref_title__clear_cache"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/pref_key__proxy_enabled" android:key="@string/pref_key__proxy_enabled"
android:summary="@string/pref_desc__proxy_enabled" android:summary="@string/pref_desc__proxy_enabled"
android:title="@string/pref_title__proxy_enabled" /> android:title="@string/pref_title__proxy_enabled"/>
<EditTextPreference <EditTextPreference
android:dependency="@string/pref_key__proxy_enabled" android:dependency="@string/pref_key__proxy_enabled"
android:inputType="textNoSuggestions" android:inputType="textNoSuggestions"
android:key="@string/pref_key__proxy_host" android:key="@string/pref_key__proxy_host"
android:title="@string/pref_title__proxy_host" /> android:title="@string/pref_title__proxy_host"/>
<EditTextPreference <EditTextPreference
android:dependency="@string/pref_key__proxy_enabled" android:dependency="@string/pref_key__proxy_enabled"
android:inputType="number" android:inputType="number"
android:key="@string/pref_key__proxy_port" android:key="@string/pref_key__proxy_port"
android:title="@string/pref_title__proxy_port" /> android:title="@string/pref_title__proxy_port"/>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>