From d07dc49dc7ba7c94d97484361bee514e52e53d2a Mon Sep 17 00:00:00 2001 From: seven332 Date: Thu, 5 May 2016 01:05:00 +0800 Subject: [PATCH] Add cellular network warning --- .../java/com/hippo/ehviewer/Settings.java | 7 ++++ .../com/hippo/ehviewer/ui/MainActivity.java | 11 ++++++ .../main/java/com/hippo/network/Network.java | 35 +++++++++++++++++++ app/src/main/res/values-zh-rCN/strings.xml | 3 ++ app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 3 ++ app/src/main/res/xml/eh_settings.xml | 5 +++ 8 files changed, 66 insertions(+) create mode 100644 app/src/main/java/com/hippo/network/Network.java diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.java b/app/src/main/java/com/hippo/ehviewer/Settings.java index 89be8bd14..e6edaf61e 100644 --- a/app/src/main/java/com/hippo/ehviewer/Settings.java +++ b/app/src/main/java/com/hippo/ehviewer/Settings.java @@ -412,6 +412,13 @@ public class Settings { putString(KEY_HATH_PASSKEY, value); } + private static final String KEY_CELLULAR_NETWORK_WARNING = "cellular_network_warning"; + private static final boolean DEFAULT_CELLULAR_NETWORK_WARNING = false; + + public static boolean getCellularNetworkWarning() { + return getBoolean(KEY_CELLULAR_NETWORK_WARNING, DEFAULT_CELLULAR_NETWORK_WARNING); + } + /******************** ****** Read ********************/ diff --git a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java index b31b8ffd4..91e1a982d 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java @@ -20,6 +20,7 @@ import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; +import android.net.ConnectivityManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -70,6 +71,7 @@ import com.hippo.ehviewer.ui.scene.WarningScene; import com.hippo.ehviewer.ui.scene.WebViewSignInScene; import com.hippo.ehviewer.widget.EhDrawerLayout; import com.hippo.io.UniFileInputStreamPipe; +import com.hippo.network.Network; import com.hippo.scene.Announcer; import com.hippo.scene.SceneFragment; import com.hippo.scene.StageActivity; @@ -392,6 +394,9 @@ public final class MainActivity extends StageActivity onInit(); CommonOperations.checkUpdate(this, false); checkDownloadLocation(); + if (Settings.getCellularNetworkWarning()) { + checkCellularNetwork(); + } } else { onRestore(savedInstanceState); } @@ -410,6 +415,12 @@ public final class MainActivity extends StageActivity .show(); } + private void checkCellularNetwork() { + if (Network.getActiveNetworkType(this) == ConnectivityManager.TYPE_MOBILE) { + showTip(R.string.cellular_network_warning, BaseScene.LENGTH_SHORT); + } + } + private void onInit() { // Check permission PermissionRequester.request(this, Manifest.permission.WRITE_EXTERNAL_STORAGE, diff --git a/app/src/main/java/com/hippo/network/Network.java b/app/src/main/java/com/hippo/network/Network.java new file mode 100644 index 000000000..b00c10d95 --- /dev/null +++ b/app/src/main/java/com/hippo/network/Network.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2014 Hippo Seven + * + * 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.network; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; + +public final class Network { + private Network() {} + + public static int getActiveNetworkType(Context context) { + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + if (activeNetwork != null) { + return activeNetwork.getType(); + } else { + return -1; + } + } +} diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 9f8a608fc..247bf1c27 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -50,6 +50,8 @@ 似乎下载路径不可用。请到重新设置下载路径。 + 正在使用移动网络 + 错误的状态码:%d 超时 未知主机 @@ -385,6 +387,7 @@ 显示默认标题。一般是英文标题 过滤 过滤标题,上传者,标签和标签组 + 移动网络警告 阅读 屏幕方向 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 05d773f5c..5821cc4bf 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -385,6 +385,7 @@ 顯示默認標題。一般是英文標題 過濾 過濾標題,上傳者,標籤和標籤組 + 移動網絡警告 閲讀 屏幕方向 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 51aed953f..94b2c1966 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -385,6 +385,7 @@ 顯示預設標題。一般是英文標題 過濾 過濾標題,上傳者,標籤和標籤組 + 行動網路警告 閱讀 螢幕方向 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b331fbeb..9c71ef707 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,6 +66,8 @@ It seems download location is not available. Please set it in Settings. + Connected to cellular networks + Bad Request Unauthorized Payment Required @@ -427,6 +429,7 @@ Show default title. It is usually English title Filter Filter by title, uploader, tag and tag namespace + Cellular network warning Read Screen orientation diff --git a/app/src/main/res/xml/eh_settings.xml b/app/src/main/res/xml/eh_settings.xml index 5f9bcd2da..c634dbbc1 100644 --- a/app/src/main/res/xml/eh_settings.xml +++ b/app/src/main/res/xml/eh_settings.xml @@ -97,4 +97,9 @@ android:summary="@string/settings_eh_filter_summary" app:activity="com.hippo.ehviewer.ui.FilterActivity"/> + +