├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable
│ │ │ │ ├── dialog_privacy_bg.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-zh-rCN
│ │ │ │ └── strings.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_privacy_policy.xml
│ │ │ │ ├── activity_terms.xml
│ │ │ │ └── dialog_privacy.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zfg
│ │ │ │ └── privacyview
│ │ │ │ ├── PrivacyDialog.java
│ │ │ │ ├── PrivacyPolicyActivity.java
│ │ │ │ ├── TermsActivity.java
│ │ │ │ ├── AppUtil.java
│ │ │ │ ├── SPUtil.java
│ │ │ │ └── MainActivity.java
│ │ ├── assets
│ │ │ ├── privacy_policy.html
│ │ │ └── user_agreement.html
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zfg
│ │ │ └── privacyview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zfg
│ │ └── privacyview
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── PrivacyView.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='PrivacyView'
3 |
--------------------------------------------------------------------------------
/PrivacyView.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/PrivacyView.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zfgandroid/PrivacyView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | 博客链接:https://blog.csdn.net/zhongfangguiyishi/article/details/104743448
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Mar 08 17:38:17 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dialog_privacy_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zfg/privacyview/PrivacyDialog.java:
--------------------------------------------------------------------------------
1 | package com.zfg.privacyview;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 |
6 | public class PrivacyDialog extends Dialog {
7 |
8 | public PrivacyDialog(Context context) {
9 | super(context, R.style.PrivacyThemeDialog);
10 |
11 | setContentView(R.layout.dialog_privacy);
12 |
13 | setCancelable(false);
14 | setCanceledOnTouchOutside(false);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zfg/privacyview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zfg.privacyview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 | #FFFFFFFF
7 | #FF000000
8 | #878787
9 | #FFE26C25
10 | #FF036EB8
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PrivacyView
3 | 退出
4 | 同意
5 | 用户须知
6 | 《用户协议》
7 | 《隐私政策》
8 | 欢迎使用PrivacyView!为了保护您的隐私和使用安全,请您务必仔细阅读我们的《用户协议》和《隐私政策》。在确认充分理解并同意后再开始使用此应用。感谢!
9 | 用户须知已确认
10 | 用户协议
11 | 隐私政策
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/assets/privacy_policy.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PrivacyView
3 | Exit
4 | Agree
5 | Users Note
6 | Terms of Use
7 | Privacy Policy
8 | Welcome to PrivacyView! In order to protect your privacy and use security, please read our Terms of Use and Privacy Policy carefully. Do not use this app until you have confirmed your full understanding and agreement. Thank you!
9 | The user note has been confirmed
10 | Terms of Use
11 | Privacy Policy
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zfg/privacyview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zfg.privacyview;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.zfg.privacyview", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/assets/user_agreement.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | defaultConfig {
6 | applicationId "com.zfg.privacyview"
7 | minSdkVersion 15
8 | targetSdkVersion 29
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'androidx.appcompat:appcompat:1.0.2'
24 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'androidx.test.ext:junit:1.1.0'
27 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_privacy_policy.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
17 |
24 |
25 |
26 |
27 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_terms.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
17 |
24 |
25 |
26 |
27 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zfg/privacyview/PrivacyPolicyActivity.java:
--------------------------------------------------------------------------------
1 | package com.zfg.privacyview;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.ViewGroup;
7 | import android.webkit.WebView;
8 | import android.webkit.WebViewClient;
9 | import android.widget.FrameLayout;
10 |
11 | /**
12 | * 隐私政策
13 | *
14 | * @author zhongfg
15 | */
16 | public class PrivacyPolicyActivity extends Activity {
17 |
18 | private static final String TAG = PrivacyPolicyActivity.class.getSimpleName();
19 |
20 | private FrameLayout web_view_container;
21 | private WebView web_view;
22 |
23 | private final String LANGUAGE_CN = "zh-CN";
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 |
29 | setContentView(R.layout.activity_privacy_policy);
30 |
31 | initView();
32 | }
33 |
34 | private void initView() {
35 |
36 | web_view_container = findViewById(R.id.web_view_container);
37 | web_view = new WebView(getApplicationContext());
38 | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
39 | ViewGroup.LayoutParams.MATCH_PARENT,
40 | ViewGroup.LayoutParams.MATCH_PARENT);
41 | web_view.setLayoutParams(params);
42 | web_view.setWebViewClient(new WebViewClient());
43 | //动态添加WebView,解决在xml引用WebView持有Activity的Context对象,导致内存泄露
44 | web_view_container.addView(web_view);
45 |
46 | String language = AppUtil.getLanguage(PrivacyPolicyActivity.this);
47 | Log.i(TAG, "当前语言:" + language);
48 |
49 | if (LANGUAGE_CN.equals(language)) {
50 | web_view.loadUrl("file:///android_asset/privacy_policy.html");
51 | } else {
52 | web_view.loadUrl("file:///android_asset/privacy_policy.html");
53 | }
54 | }
55 |
56 | @Override
57 | protected void onDestroy() {
58 | super.onDestroy();
59 | web_view_container.removeAllViews();
60 | web_view.destroy();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zfg/privacyview/TermsActivity.java:
--------------------------------------------------------------------------------
1 | package com.zfg.privacyview;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.ViewGroup;
7 | import android.webkit.WebView;
8 | import android.webkit.WebViewClient;
9 | import android.widget.FrameLayout;
10 |
11 | /**
12 | * @author zhongfg
13 | */
14 | public class TermsActivity extends Activity {
15 |
16 | private static final String TAG = TermsActivity.class.getSimpleName();
17 |
18 | private FrameLayout web_view_container;
19 | private WebView web_view;
20 |
21 | private final String LANGUAGE_CN = "zh-CN";
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 |
27 | setContentView(R.layout.activity_terms);
28 |
29 | initView();
30 | }
31 |
32 | private void initView() {
33 |
34 | web_view_container = findViewById(R.id.web_view_container);
35 | web_view = new WebView(getApplicationContext());
36 | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
37 | ViewGroup.LayoutParams.MATCH_PARENT,
38 | ViewGroup.LayoutParams.MATCH_PARENT);
39 | web_view.setLayoutParams(params);
40 | web_view.setWebViewClient(new WebViewClient());
41 | //动态添加WebView,解决在xml引用WebView持有Activity的Context对象,导致内存泄露
42 | web_view_container.addView(web_view);
43 |
44 | String language = AppUtil.getLanguage(TermsActivity.this);
45 | Log.i(TAG, "当前语言:" + language);
46 |
47 | if (LANGUAGE_CN.equals(language)) {
48 | web_view.loadUrl("file:///android_asset/user_agreement.html");
49 | } else {
50 | web_view.loadUrl("file:///android_asset/user_agreement.html");
51 | }
52 | }
53 |
54 | @Override
55 | protected void onDestroy() {
56 | super.onDestroy();
57 | web_view_container.removeAllViews();
58 | web_view.destroy();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zfg/privacyview/AppUtil.java:
--------------------------------------------------------------------------------
1 | package com.zfg.privacyview;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 | import android.os.Build;
7 | import android.util.Log;
8 |
9 | import java.util.Locale;
10 |
11 | public class AppUtil {
12 |
13 | private final static String TAG = AppUtil.class.getSimpleName();
14 |
15 | /**
16 | * 获取当前app version code
17 | */
18 | public static long getAppVersionCode(Context context) {
19 | long appVersionCode = 0;
20 | try {
21 | PackageInfo packageInfo = context.getApplicationContext()
22 | .getPackageManager()
23 | .getPackageInfo(context.getPackageName(), 0);
24 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
25 | appVersionCode = packageInfo.getLongVersionCode();
26 | } else {
27 | appVersionCode = packageInfo.versionCode;
28 | }
29 | } catch (PackageManager.NameNotFoundException e) {
30 | Log.e(TAG, "[getAppVersionCode]-error:" + e.getMessage());
31 | }
32 | return appVersionCode;
33 | }
34 |
35 | /**
36 | * 获取当前app version name
37 | */
38 | public static String getAppVersionName(Context context) {
39 | String appVersionName = "";
40 | try {
41 | PackageInfo packageInfo = context.getApplicationContext()
42 | .getPackageManager()
43 | .getPackageInfo(context.getPackageName(), 0);
44 | appVersionName = packageInfo.versionName;
45 | } catch (PackageManager.NameNotFoundException e) {
46 | Log.e(TAG, "[getAppVersionName]-error:" + e.getMessage());
47 | }
48 | return appVersionName;
49 | }
50 |
51 | /**
52 | * 获取当前语言
53 | *
54 | * @param context
55 | * @return
56 | */
57 | public static String getLanguage(Context context) {
58 |
59 | Locale locale;
60 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
61 | locale = context.getResources().getConfiguration().getLocales().get(0);
62 | } else {
63 | locale = context.getResources().getConfiguration().locale;
64 | }
65 |
66 | return locale.getLanguage() + "-" + locale.getCountry();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_privacy.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
32 |
33 |
40 |
41 |
47 |
48 |
61 |
62 |
66 |
67 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zfg/privacyview/SPUtil.java:
--------------------------------------------------------------------------------
1 | package com.zfg.privacyview;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | import java.lang.reflect.InvocationTargetException;
7 | import java.lang.reflect.Method;
8 | import java.util.Map;
9 |
10 | /**
11 | * SharedPreferences操作工具类
12 | *
13 | * Created by zhongfg on 2020/03/08.
14 | */
15 |
16 | public class SPUtil {
17 |
18 | /**
19 | * 保存在手机里面的文件名
20 | */
21 | public static final String FILE_NAME = "share_data";
22 |
23 | /**
24 | * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
25 | *
26 | * @param context 上下文对象
27 | * @param key 保存数据的key值
28 | * @param object 保存数据的类型
29 | */
30 | public static void put(Context context, String key, Object object) {
31 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
32 | SharedPreferences.Editor editor = sp.edit();
33 | if (object instanceof String) {
34 | editor.putString(key, (String) object);
35 | } else if (object instanceof Integer) {
36 | editor.putInt(key, (Integer) object);
37 | } else if (object instanceof Boolean) {
38 | editor.putBoolean(key, (Boolean) object);
39 | } else if (object instanceof Float) {
40 | editor.putFloat(key, (Float) object);
41 | } else if (object instanceof Long) {
42 | editor.putLong(key, (Long) object);
43 | } else {
44 | if (null != object) {
45 | editor.putString(key, object.toString());
46 | }
47 | }
48 | SharedPreferencesCompat.apply(editor);
49 | }
50 |
51 | /**
52 | * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
53 | *
54 | * @param context 上下文对象
55 | * @param key 保存数据的key值
56 | * @param defaultObject 保存数据的类型
57 | * @return 得到保存数据
58 | */
59 | public static Object get(Context context, String key, Object defaultObject) {
60 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
61 | if (defaultObject instanceof String) {
62 | return sp.getString(key, (String) defaultObject);
63 | } else if (defaultObject instanceof Integer) {
64 | return sp.getInt(key, (Integer) defaultObject);
65 | } else if (defaultObject instanceof Boolean) {
66 | return sp.getBoolean(key, (Boolean) defaultObject);
67 | } else if (defaultObject instanceof Float) {
68 | return sp.getFloat(key, (Float) defaultObject);
69 | } else if (defaultObject instanceof Long) {
70 | return sp.getLong(key, (Long) defaultObject);
71 | }
72 | return null;
73 | }
74 |
75 | /**
76 | * 移除某个key值已经对应的值
77 | *
78 | * @param context 上下文对象
79 | * @param key 保存数据的key值
80 | */
81 | public static void remove(Context context, String key) {
82 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
83 | SharedPreferences.Editor editor = sp.edit();
84 | editor.remove(key);
85 | SharedPreferencesCompat.apply(editor);
86 | }
87 |
88 | /**
89 | * 清除所有数据
90 | *
91 | * @param context 上下文对象
92 | */
93 | public static void clear(Context context) {
94 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
95 | SharedPreferences.Editor editor = sp.edit();
96 | editor.clear();
97 | SharedPreferencesCompat.apply(editor);
98 | }
99 |
100 | /**
101 | * 查询某个key是否已经存在
102 | *
103 | * @param context 上下文对象
104 | * @param key 保存数据的key值
105 | * @return key是否已经存在
106 | */
107 | public static boolean contains(Context context, String key) {
108 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
109 | return sp.contains(key);
110 | }
111 |
112 | /**
113 | * 返回所有的键值对
114 | *
115 | * @param context 上下文对象
116 | * @return 所有的键值对
117 | */
118 | public static Map getAll(Context context) {
119 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
120 | return sp.getAll();
121 | }
122 |
123 | /**
124 | * 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类
125 | */
126 | private static class SharedPreferencesCompat {
127 |
128 | private static final Method sApplyMethod = findApplyMethod();
129 |
130 | /**
131 | * 反射查找apply的方法
132 | *
133 | * @return apply的方法
134 | */
135 | @SuppressWarnings({"unchecked", "rawtypes"})
136 | private static Method findApplyMethod() {
137 | try {
138 | Class clz = SharedPreferences.Editor.class;
139 | return clz.getMethod("apply");
140 | } catch (NoSuchMethodException e) {
141 | }
142 | return null;
143 | }
144 |
145 | /**
146 | * 如果找到则使用apply执行,否则使用commit
147 | *
148 | * @param editor
149 | */
150 | public static void apply(SharedPreferences.Editor editor) {
151 | try {
152 | if (sApplyMethod != null) {
153 | sApplyMethod.invoke(editor);
154 | return;
155 | }
156 | } catch (IllegalArgumentException e) {
157 | } catch (IllegalAccessException e) {
158 | } catch (InvocationTargetException e) {
159 | }
160 | editor.commit();
161 | }
162 | }
163 |
164 | }
165 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zfg/privacyview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zfg.privacyview;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.content.Intent;
6 | import android.graphics.Color;
7 | import android.os.Bundle;
8 | import android.text.Spannable;
9 | import android.text.SpannableString;
10 | import android.text.TextPaint;
11 | import android.text.method.LinkMovementMethod;
12 | import android.text.style.AbsoluteSizeSpan;
13 | import android.text.style.ClickableSpan;
14 | import android.text.style.ForegroundColorSpan;
15 | import android.view.Display;
16 | import android.view.View;
17 | import android.view.WindowManager;
18 | import android.widget.Button;
19 | import android.widget.TextView;
20 | import android.widget.Toast;
21 |
22 | public class MainActivity extends AppCompatActivity {
23 |
24 | private String SP_PRIVACY = "sp_privacy";
25 | private String SP_VERSION_CODE = "sp_version_code";
26 | private boolean isCheckPrivacy = false;
27 | private long versionCode;
28 | private long currentVersionCode;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 |
35 | Button btn_reset = findViewById(R.id.btn_reset);
36 | btn_reset.setOnClickListener(new View.OnClickListener() {
37 | @Override
38 | public void onClick(View v) {
39 | SPUtil.put(MainActivity.this, SP_VERSION_CODE, 0L);
40 | SPUtil.put(MainActivity.this, SP_PRIVACY, false);
41 | finish();
42 | }
43 | });
44 |
45 | check();
46 | }
47 |
48 | /**
49 | * 显示隐私政策或跳转到其他界面
50 | */
51 | private void check() {
52 |
53 | //先判断是否显示了隐私政策
54 | currentVersionCode = AppUtil.getAppVersionCode(MainActivity.this);
55 | versionCode = (long) SPUtil.get(MainActivity.this, SP_VERSION_CODE, 0L);
56 | isCheckPrivacy = (boolean) SPUtil.get(MainActivity.this, SP_PRIVACY, false);
57 |
58 | if (!isCheckPrivacy || versionCode != currentVersionCode) {
59 | showPrivacy();
60 | } else {
61 | Toast.makeText(MainActivity.this, getString(R.string.confirmed), Toast.LENGTH_SHORT).show();
62 | }
63 | }
64 |
65 | /**
66 | * 显示用户协议和隐私政策
67 | */
68 | private void showPrivacy() {
69 |
70 | final PrivacyDialog dialog = new PrivacyDialog(MainActivity.this);
71 | TextView tv_privacy_tips = dialog.findViewById(R.id.tv_privacy_tips);
72 | TextView btn_exit = dialog.findViewById(R.id.btn_exit);
73 | TextView btn_enter = dialog.findViewById(R.id.btn_enter);
74 | dialog.show();
75 |
76 | String string = getResources().getString(R.string.privacy_tips);
77 | String key1 = getResources().getString(R.string.privacy_tips_key1);
78 | String key2 = getResources().getString(R.string.privacy_tips_key2);
79 | int index1 = string.indexOf(key1);
80 | int index2 = string.indexOf(key2);
81 |
82 | //需要显示的字串
83 | SpannableString spannedString = new SpannableString(string);
84 | //设置点击字体颜色
85 | ForegroundColorSpan colorSpan1 = new ForegroundColorSpan(getResources().getColor(R.color.colorBlue));
86 | spannedString.setSpan(colorSpan1, index1, index1 + key1.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
87 | ForegroundColorSpan colorSpan2 = new ForegroundColorSpan(getResources().getColor(R.color.colorBlue));
88 | spannedString.setSpan(colorSpan2, index2, index2 + key2.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
89 | //设置点击字体大小
90 | AbsoluteSizeSpan sizeSpan1 = new AbsoluteSizeSpan(18, true);
91 | spannedString.setSpan(sizeSpan1, index1, index1 + key1.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
92 | AbsoluteSizeSpan sizeSpan2 = new AbsoluteSizeSpan(18, true);
93 | spannedString.setSpan(sizeSpan2, index2, index2 + key2.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
94 | //设置点击事件
95 | ClickableSpan clickableSpan1 = new ClickableSpan() {
96 | @Override
97 | public void onClick(View view) {
98 | Intent intent = new Intent(MainActivity.this, TermsActivity.class);
99 | startActivity(intent);
100 | }
101 |
102 | @Override
103 | public void updateDrawState(TextPaint ds) {
104 | //点击事件去掉下划线
105 | ds.setUnderlineText(false);
106 | }
107 | };
108 | spannedString.setSpan(clickableSpan1, index1, index1 + key1.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
109 |
110 | ClickableSpan clickableSpan2 = new ClickableSpan() {
111 | @Override
112 | public void onClick(View view) {
113 | Intent intent = new Intent(MainActivity.this, PrivacyPolicyActivity.class);
114 | startActivity(intent);
115 | }
116 |
117 | @Override
118 | public void updateDrawState(TextPaint ds) {
119 | //点击事件去掉下划线
120 | ds.setUnderlineText(false);
121 | }
122 | };
123 | spannedString.setSpan(clickableSpan2, index2, index2 + key2.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
124 |
125 | //设置点击后的颜色为透明,否则会一直出现高亮
126 | tv_privacy_tips.setHighlightColor(Color.TRANSPARENT);
127 | //开始响应点击事件
128 | tv_privacy_tips.setMovementMethod(LinkMovementMethod.getInstance());
129 |
130 | tv_privacy_tips.setText(spannedString);
131 |
132 | //设置弹框宽度占屏幕的80%
133 | WindowManager m = getWindowManager();
134 | Display defaultDisplay = m.getDefaultDisplay();
135 | final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
136 | params.width = (int) (defaultDisplay.getWidth() * 0.80);
137 | dialog.getWindow().setAttributes(params);
138 |
139 | btn_exit.setOnClickListener(new View.OnClickListener() {
140 | @Override
141 | public void onClick(View v) {
142 | dialog.dismiss();
143 | SPUtil.put(MainActivity.this, SP_VERSION_CODE, currentVersionCode);
144 | SPUtil.put(MainActivity.this, SP_PRIVACY, false);
145 | finish();
146 | }
147 | });
148 |
149 | btn_enter.setOnClickListener(new View.OnClickListener() {
150 | @Override
151 | public void onClick(View v) {
152 | dialog.dismiss();
153 | SPUtil.put(MainActivity.this, SP_VERSION_CODE, currentVersionCode);
154 | SPUtil.put(MainActivity.this, SP_PRIVACY, true);
155 |
156 | Toast.makeText(MainActivity.this, getString(R.string.confirmed), Toast.LENGTH_SHORT).show();
157 | }
158 | });
159 |
160 | }
161 | }
162 |
--------------------------------------------------------------------------------