diff --git a/app/build.gradle b/app/build.gradle index d58b0f366..f18fad5ad 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { applicationId "com.hippo.ehviewer" - minSdkVersion 15 + minSdkVersion 14 targetSdkVersion 23 versionCode 58 versionName "1.0.5" @@ -82,7 +82,6 @@ dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.3.0' - compile 'com.android.support:customtabs:23.3.0' compile 'com.android.support:design:23.3.0' compile 'com.github.amlcurran.showcaseview:library:5.4.1' compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.7' diff --git a/app/src/main/java/com/hippo/ehviewer/UrlOpener.java b/app/src/main/java/com/hippo/ehviewer/UrlOpener.java index 360fe6916..56a80f177 100644 --- a/app/src/main/java/com/hippo/ehviewer/UrlOpener.java +++ b/app/src/main/java/com/hippo/ehviewer/UrlOpener.java @@ -16,14 +16,12 @@ package com.hippo.ehviewer; -import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.provider.Browser; import android.support.annotation.NonNull; -import android.support.customtabs.CustomTabsIntent; import android.text.TextUtils; import android.widget.Toast; @@ -31,14 +29,13 @@ import com.hippo.ehviewer.client.EhUrlOpener; import com.hippo.ehviewer.ui.MainActivity; import com.hippo.scene.Announcer; import com.hippo.scene.StageActivity; -import com.hippo.util.CustomTabsHelper; public final class UrlOpener { private UrlOpener() { } - public static void openUrl(@NonNull Context context, String url, boolean ehUrl, boolean customTabs) { + public static void openUrl(@NonNull Context context, String url, boolean ehUrl) { if (TextUtils.isEmpty(url)) { return; } @@ -59,20 +56,6 @@ public final class UrlOpener { } } - // CustomTabs - if (customTabs && context instanceof Activity) { - Activity activity = (Activity) context; - String packageName = CustomTabsHelper.getPackageNameToUseFixed(activity); - if (packageName != null) { - new CustomTabsIntent.Builder() - .setToolbarColor(activity.getResources().getColor(R.color.colorPrimary)) - .setShowTitle(true) - .build() - .launchUrl(activity, uri); - return; - } - } - // Intent.ACTION_VIEW intent = new Intent(Intent.ACTION_VIEW, uri); intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java index 5a0b8be14..217515f92 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java @@ -117,7 +117,7 @@ public final class CommonOperations { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - UrlOpener.openUrl(mActivity, url, false, false); + UrlOpener.openUrl(mActivity, url, false); } }).show(); } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java index 762120283..60254da93 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java @@ -400,7 +400,7 @@ public final class GalleryCommentsScene extends ToolbarScene commentHolder.comment.clearCurrentSpan(); if (span instanceof URLSpan) { - UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true, true); + UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true); return true; } } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java index 3de1d3c60..dba98b07e 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java @@ -988,7 +988,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene String url = getGalleryDetailUrl(false); Activity activity = getActivity2(); if (null != url && null != activity) { - UrlOpener.openUrl(activity, url, false, false); + UrlOpener.openUrl(activity, url, false); } break; case R.id.action_refresh: @@ -1294,7 +1294,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: - UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(tag2), false, true); + UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(tag2), false); break; case 1: addTagFilter(tag); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java index d5d053214..c24c9b212 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java @@ -217,7 +217,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct } if (mRegister == v) { - UrlOpener.openUrl(activity, EhUrl.URL_REGISTER, false, true); + UrlOpener.openUrl(activity, EhUrl.URL_REGISTER, false); } else if (mSignIn == v) { signIn(); } else if (mSignInViaWebView == v) { diff --git a/app/src/main/java/com/hippo/preference/UrlPreference.java b/app/src/main/java/com/hippo/preference/UrlPreference.java index c1e033b42..b5bba3f42 100644 --- a/app/src/main/java/com/hippo/preference/UrlPreference.java +++ b/app/src/main/java/com/hippo/preference/UrlPreference.java @@ -60,6 +60,6 @@ public class UrlPreference extends Preference { @Override protected void onClick() { - UrlOpener.openUrl(getContext(), mUrl, true, true); + UrlOpener.openUrl(getContext(), mUrl, true); } } diff --git a/app/src/main/java/com/hippo/text/LinkMovementMethod2.java b/app/src/main/java/com/hippo/text/LinkMovementMethod2.java index afbba0672..3dfdb9902 100644 --- a/app/src/main/java/com/hippo/text/LinkMovementMethod2.java +++ b/app/src/main/java/com/hippo/text/LinkMovementMethod2.java @@ -223,7 +223,7 @@ public class LinkMovementMethod2 extends ScrollingMovementMethod { if (action == MotionEvent.ACTION_UP) { ClickableSpan span = link[0]; if (span instanceof URLSpan) { - UrlOpener.openUrl(widget.getContext(), ((URLSpan) span).getURL(), true, true); + UrlOpener.openUrl(widget.getContext(), ((URLSpan) span).getURL(), true); } else { span.onClick(widget); } diff --git a/app/src/main/java/com/hippo/util/CustomTabsHelper.java b/app/src/main/java/com/hippo/util/CustomTabsHelper.java deleted file mode 100644 index 5378004b1..000000000 --- a/app/src/main/java/com/hippo/util/CustomTabsHelper.java +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright 2015 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.hippo.util; - -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.net.Uri; -import android.text.TextUtils; -import android.util.Log; - -import java.util.ArrayList; -import java.util.List; - -/** - * Helper class for Custom Tabs. - */ -public class CustomTabsHelper { - private static final String TAG = "CustomTabsHelper"; - static final String STABLE_PACKAGE = "com.android.chrome"; - static final String BETA_PACKAGE = "com.chrome.beta"; - static final String DEV_PACKAGE = "com.chrome.dev"; - static final String LOCAL_PACKAGE = "com.google.android.apps.chrome"; - private static final String ACTION_CUSTOM_TABS_CONNECTION = - "android.support.customtabs.action.CustomTabsService"; - private static final String UNINITIALIZED = "UNINITIALIZED"; - - private static String sPackageNameToUse = UNINITIALIZED; - - private CustomTabsHelper() {} - - /** - * The browser of smartisan is terrible - */ - public static String getPackageNameToUseFixed(Context context) { - if (!UNINITIALIZED.equals(sPackageNameToUse)) return sPackageNameToUse; - - PackageManager pm = context.getPackageManager(); - - // Get all apps that can handle VIEW intents. - Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); - List resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); - List packagesSupportingCustomTabs = new ArrayList<>(); - for (ResolveInfo info : resolvedActivityList) { - Intent serviceIntent = new Intent(); - serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); - serviceIntent.setPackage(info.activityInfo.packageName); - if (pm.resolveService(serviceIntent, 0) != null) { - packagesSupportingCustomTabs.add(info.activityInfo.packageName); - } - } - - // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents - // and service calls. - if (packagesSupportingCustomTabs.isEmpty()) { - sPackageNameToUse = null; - } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { - sPackageNameToUse = STABLE_PACKAGE; - } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { - sPackageNameToUse = BETA_PACKAGE; - } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { - sPackageNameToUse = DEV_PACKAGE; - } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { - sPackageNameToUse = LOCAL_PACKAGE; - } else { - sPackageNameToUse = null; - } - return sPackageNameToUse; - } - - /** - * Goes through all apps that handle VIEW intents and have a warmup service. Picks - * the one chosen by the user if there is one, otherwise makes a best effort to return a - * valid package name. - * - * This is not threadsafe. - * - * @param context {@link Context} to use for accessing {@link PackageManager}. - * @return The package name recommended to use for connecting to custom tabs related components. - */ - public static String getPackageNameToUse(Context context) { - if (sPackageNameToUse != null) return sPackageNameToUse; - - PackageManager pm = context.getPackageManager(); - // Get default VIEW intent handler. - Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); - ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); - String defaultViewHandlerPackageName = null; - if (defaultViewHandlerInfo != null) { - defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; - } - - // Get all apps that can handle VIEW intents. - List resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); - List packagesSupportingCustomTabs = new ArrayList<>(); - for (ResolveInfo info : resolvedActivityList) { - Intent serviceIntent = new Intent(); - serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); - serviceIntent.setPackage(info.activityInfo.packageName); - if (pm.resolveService(serviceIntent, 0) != null) { - packagesSupportingCustomTabs.add(info.activityInfo.packageName); - } - } - - // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents - // and service calls. - if (packagesSupportingCustomTabs.isEmpty()) { - sPackageNameToUse = null; - } else if (packagesSupportingCustomTabs.size() == 1) { - sPackageNameToUse = packagesSupportingCustomTabs.get(0); - } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName) - && !hasSpecializedHandlerIntents(context, activityIntent) - && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) { - sPackageNameToUse = defaultViewHandlerPackageName; - } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { - sPackageNameToUse = STABLE_PACKAGE; - } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { - sPackageNameToUse = BETA_PACKAGE; - } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { - sPackageNameToUse = DEV_PACKAGE; - } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { - sPackageNameToUse = LOCAL_PACKAGE; - } - return sPackageNameToUse; - } - - /** - * Used to check whether there is a specialized handler for a given intent. - * @param intent The intent to check with. - * @return Whether there is a specialized handler for the given intent. - */ - private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) { - try { - PackageManager pm = context.getPackageManager(); - List handlers = pm.queryIntentActivities( - intent, - PackageManager.GET_RESOLVED_FILTER); - if (handlers == null || handlers.size() == 0) { - return false; - } - for (ResolveInfo resolveInfo : handlers) { - IntentFilter filter = resolveInfo.filter; - if (filter == null) continue; - if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue; - if (resolveInfo.activityInfo == null) continue; - return true; - } - } catch (RuntimeException e) { - Log.e(TAG, "Runtime exception while getting specialized handlers"); - } - return false; - } -}