├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── icon.png
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── icon.png
│ │ │ │ ├── logo.png
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── icon.png
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── button_passdelete.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-v21
│ │ │ │ └── bg_btn_number.xml
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── colors.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── drawable
│ │ │ │ └── bg_btn_number.xml
│ │ │ └── layout
│ │ │ │ ├── activity_sample3.xml
│ │ │ │ ├── activity_sample4.xml
│ │ │ │ ├── activity_sample1.xml
│ │ │ │ ├── activity_sample2.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_input_pass_code.xml
│ │ │ │ └── activity_confirm_pass_code.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── u_nation
│ │ │ │ └── passcodelocksample
│ │ │ │ ├── util
│ │ │ │ ├── ShowToast.java
│ │ │ │ └── PrefUtil.java
│ │ │ │ ├── Constants.java
│ │ │ │ ├── sample_activities
│ │ │ │ ├── Sample4Activity.java
│ │ │ │ ├── Sample2Activity.java
│ │ │ │ ├── Sample3Activity.java
│ │ │ │ ├── Sample1Activity.java
│ │ │ │ └── MainActivity.java
│ │ │ │ ├── MyApplication.java
│ │ │ │ ├── PassCodeConfirmationActivity.java
│ │ │ │ └── PassCodeSetActivity.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── u_nation
│ │ └── passcodelocksample
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── art
└── passcodelock.gif
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── .gitignore
├── LICENSE
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/art/passcodelock.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/art/passcodelock.gif
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/mipmap-xhdpi/icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/mipmap-xxhdpi/icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/mipmap-xxhdpi/logo.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/mipmap-xxxhdpi/icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/button_passdelete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/u-nation/PassCodeLockSample/HEAD/app/src/main/res/drawable-hdpi/button_passdelete.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/bg_btn_number.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Dec 02 21:16:36 JST 2017
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/util/ShowToast.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample.util;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | public class ShowToast {
7 | public static void show(String text, Context context) {
8 | Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/Constants.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample;
2 |
3 | public class Constants {
4 | // プリファレンス用のキー
5 | public static final String PREF_KEY_PASSWORD = "password";
6 | public static final String PREF_KEY_IS_LOCKED = "isLocked";
7 | public static final String PREF_KEY_APPLICATION_BACKGROUND = "background";
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/u_nation/passcodelocksample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/endo-ex/Android/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_btn_number.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 | -
15 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 | 45dip
8 | 37dip
9 | 50dip
10 | 5dip
11 | 12sp
12 | 14sp
13 | 16sp
14 | 18sp
15 | 22sp
16 | 26sp
17 | 36sp
18 |
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Intellij project files
26 | *.iml
27 | *.ipr
28 | *.iws
29 | .idea
30 |
31 | project.properties
32 | .DS_Store
33 | tests/.settings/org.eclipse.jdt.core.prefs
34 | org.eclipse.jdt.core.prefs
35 | /.apt_generated/
36 |
37 | .settings/
38 | release/
39 | build/
40 |
41 | .gradle/
42 | gradle.properties
43 |
44 | local.properties
45 |
46 | .mtj.tmp/
47 |
48 | # Package Files #
49 | *.jar
50 | *.war
51 | *.ear
52 |
53 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
54 | hs_err_pid*
55 |
56 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion '26.0.2'
6 |
7 | defaultConfig {
8 | applicationId "com.example.u_nation.passcodelocksample"
9 | minSdkVersion 15
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | ext {
23 | supportLibraryVersion = '26.0.1'
24 | }
25 |
26 | dependencies {
27 | compile fileTree(dir: 'libs', include: ['*.jar'])
28 | compile "com.android.support:design:$supportLibraryVersion"
29 | compile "com.android.support:support-v4:$supportLibraryVersion"
30 | compile "com.android.support:appcompat-v7:$supportLibraryVersion"
31 | compile 'com.jakewharton.timber:timber:4.5.1'
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sample3.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sample4.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 u_nation
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PassCodeLockSample
5 |
6 | image
7 | Cancel
8 | Enter passcode
9 | Passcode Lock
10 | Please set up passcode
11 | Please enter passcode
12 | 0
13 | 1
14 | 2
15 | 3
16 | 4
17 | 5
18 | 6
19 | 7
20 | 8
21 | 9
22 | .
23 |
24 |
25 |
26 | SampleActivity1
27 | SampleActivity2
28 | SampleActivity3
29 | SampleActivity4
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sample1.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sample2.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/sample_activities/Sample4Activity.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample.sample_activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.KeyEvent;
8 | import android.view.View;
9 |
10 | import com.example.u_nation.passcodelocksample.R;
11 |
12 | import timber.log.Timber;
13 |
14 | public class Sample4Activity extends AppCompatActivity {
15 |
16 | public static Intent createIntent(Context context) {
17 | return new Intent(context, Sample4Activity.class);
18 | }
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | Timber.d("onCreate");
24 | setContentView(R.layout.activity_sample4);
25 | setTitle(this.getClass().getSimpleName());
26 | }
27 |
28 | @Override
29 | protected void onResume() {
30 | super.onResume();
31 | Timber.d("onResume");
32 | }
33 |
34 | @Override
35 | protected void onPause() {
36 | super.onPause();
37 | Timber.d("onPause");
38 | }
39 |
40 | @Override
41 | protected void onStop() {
42 | super.onStop();
43 | Timber.d("onStop");
44 | }
45 |
46 | @Override
47 | protected void onUserLeaveHint() {
48 | super.onUserLeaveHint();
49 | Timber.d("onUserLeaveHint");
50 | }
51 |
52 | @Override
53 | protected void onDestroy() {
54 | super.onDestroy();
55 | Timber.i("onDestroy");
56 | }
57 |
58 | public void onBack(View view) {
59 | finish();
60 | }
61 |
62 | @Override
63 | public boolean onKeyDown(int keyCode, KeyEvent event) {
64 | if (keyCode == KeyEvent.KEYCODE_BACK) {
65 | Timber.i("KeyEvent.KEYCODE_BACK");
66 | finish();
67 | }
68 | return super.onKeyDown(keyCode, event);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.content.ComponentCallbacks2;
6 | import android.os.Bundle;
7 |
8 | import com.example.u_nation.passcodelocksample.util.PrefUtil;
9 |
10 | import timber.log.Timber;
11 |
12 | import static com.example.u_nation.passcodelocksample.Constants.PREF_KEY_IS_LOCKED;
13 |
14 | public class MyApplication extends Application implements Application.ActivityLifecycleCallbacks {
15 |
16 | private boolean isNeedPassCodeConfirmation = true;
17 | private static MyApplication app;
18 |
19 | public static MyApplication getInstance() {
20 | if (app == null) app = new MyApplication();
21 | return app;
22 | }
23 |
24 | @Override public void onCreate() {
25 | super.onCreate();
26 | Timber.plant(new Timber.DebugTree());
27 | PrefUtil.setSharedPreferences(getApplicationContext());
28 | registerActivityLifecycleCallbacks(this);
29 | }
30 |
31 | @Override public void onTrimMemory(int level) {
32 | super.onTrimMemory(level);
33 | if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
34 | isNeedPassCodeConfirmation = true;
35 | }
36 | }
37 |
38 | @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
39 | }
40 |
41 | @Override public void onActivityStarted(Activity activity) {
42 | if (isNeedPassCodeConfirmation && PrefUtil.getBoolean(PREF_KEY_IS_LOCKED)) {
43 | activity.startActivity(PassCodeConfirmationActivity.createIntent(getApplicationContext()));
44 | }
45 | isNeedPassCodeConfirmation = false;
46 | }
47 |
48 | @Override public void onActivityResumed(Activity activity) {
49 | }
50 |
51 | @Override public void onActivityPaused(Activity activity) {
52 |
53 | }
54 |
55 | @Override public void onActivityStopped(Activity activity) {
56 | }
57 |
58 | @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
59 | }
60 |
61 | @Override public void onActivityDestroyed(Activity activity) {
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/sample_activities/Sample2Activity.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample.sample_activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.KeyEvent;
8 | import android.view.View;
9 |
10 | import com.example.u_nation.passcodelocksample.R;
11 |
12 | import timber.log.Timber;
13 |
14 | public class Sample2Activity extends AppCompatActivity {
15 |
16 | public static Intent createIntent(Context context) {
17 | Intent intent = new Intent(context, Sample2Activity.class);
18 | return intent;
19 | }
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | Timber.d("onCreate");
25 | setContentView(R.layout.activity_sample2);
26 | setTitle(this.getClass().getSimpleName());
27 | }
28 |
29 | @Override
30 | protected void onResume() {
31 | super.onResume();
32 | Timber.d("onResume");
33 | }
34 |
35 | @Override
36 | protected void onPause() {
37 | super.onPause();
38 | Timber.d("onPause");
39 | }
40 |
41 | @Override
42 | protected void onStop() {
43 | super.onStop();
44 | Timber.d("onStop");
45 | }
46 |
47 | @Override
48 | protected void onUserLeaveHint() {
49 | super.onUserLeaveHint();
50 | Timber.d("onUserLeaveHint");
51 | }
52 |
53 | @Override
54 | protected void onDestroy() {
55 | super.onDestroy();
56 | Timber.i("onDestroy");
57 | }
58 |
59 | public void onSample4(View view) {
60 | startActivity(Sample4Activity.createIntent(getApplicationContext()));
61 | }
62 |
63 | public void onBack(View view) {
64 | finish();
65 | }
66 |
67 | @Override
68 | public boolean onKeyDown(int keyCode, KeyEvent event) {
69 | if (keyCode == KeyEvent.KEYCODE_BACK) {
70 | Timber.i("KeyEvent.KEYCODE_BACK");
71 | finish();
72 | }
73 | return super.onKeyDown(keyCode, event);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/sample_activities/Sample3Activity.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample.sample_activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.KeyEvent;
8 | import android.view.View;
9 |
10 | import com.example.u_nation.passcodelocksample.R;
11 |
12 | import timber.log.Timber;
13 |
14 | public class Sample3Activity extends AppCompatActivity {
15 |
16 | public static Intent createIntent(Context context) {
17 | Intent intent = new Intent(context, Sample3Activity.class);
18 | return intent;
19 | }
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | Timber.d("onCreate");
25 | setContentView(R.layout.activity_sample3);
26 | setTitle(this.getClass().getSimpleName());
27 | }
28 |
29 | @Override
30 | protected void onResume() {
31 | super.onResume();
32 | Timber.d("onResume");
33 | }
34 |
35 | @Override
36 | protected void onPause() {
37 | super.onPause();
38 | Timber.d("onPause");
39 | }
40 |
41 | @Override
42 | protected void onStop() {
43 | super.onStop();
44 | Timber.d("onStop");
45 | }
46 |
47 | @Override
48 | protected void onUserLeaveHint() {
49 | super.onUserLeaveHint();
50 | Timber.d("onUserLeaveHint");
51 | }
52 |
53 | @Override
54 | protected void onDestroy() {
55 | super.onDestroy();
56 | Timber.i("onDestroy");
57 | }
58 |
59 | public void onBack(View view) {
60 | startActivity(Sample1Activity.createIntent(getApplicationContext()));
61 | finish();
62 | }
63 |
64 | @Override
65 | public boolean onKeyDown(int keyCode, KeyEvent event) {
66 | if (keyCode == KeyEvent.KEYCODE_BACK) {
67 | Timber.d("KeyEvent.KEYCODE_BACK");
68 | startActivity(Sample1Activity.createIntent(getApplicationContext()));
69 | finish();
70 | }
71 | return super.onKeyDown(keyCode, event);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/sample_activities/Sample1Activity.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample.sample_activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.KeyEvent;
8 | import android.view.View;
9 |
10 | import com.example.u_nation.passcodelocksample.R;
11 |
12 | import timber.log.Timber;
13 |
14 | public class Sample1Activity extends AppCompatActivity {
15 |
16 | public static Intent createIntent(Context context) {
17 | return new Intent(context, Sample1Activity.class);
18 | }
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | Timber.d("onCreate");
24 | setContentView(R.layout.activity_sample1);
25 | setTitle(this.getClass().getSimpleName());
26 | }
27 |
28 | @Override
29 | protected void onResume() {
30 | super.onResume();
31 | Timber.d("onResume");
32 | }
33 |
34 | @Override
35 | protected void onPause() {
36 | super.onPause();
37 | Timber.d("onPause");
38 | }
39 |
40 | @Override
41 | protected void onStop() {
42 | super.onStop();
43 | Timber.d("onStop");
44 | }
45 |
46 | @Override
47 | protected void onUserLeaveHint() {
48 | super.onUserLeaveHint();
49 | Timber.d("onUserLeaveHint");
50 | }
51 |
52 | @Override
53 | protected void onDestroy() {
54 | super.onDestroy();
55 | Timber.i("onDestroy");
56 | }
57 |
58 | public void onSample3(View view) {
59 | startActivity(Sample3Activity.createIntent(getApplicationContext()));
60 | finish();
61 | }
62 |
63 | public void onBack(View view) {
64 | startActivity(MainActivity.createIntent(getApplicationContext()));
65 | finish();
66 | }
67 |
68 | @Override
69 | public boolean onKeyDown(int keyCode, KeyEvent event) {
70 | if (keyCode == KeyEvent.KEYCODE_BACK) {
71 | Timber.d("KeyEvent.KEYCODE_BACK");
72 | startActivity(MainActivity.createIntent(getApplicationContext()));
73 | finish();
74 | }
75 | return super.onKeyDown(keyCode, event);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PassCodeLockSample
2 | 
3 |
4 | ## Description
5 | This is a sample program of *passcode lock* looks like iOS.
6 | ****
7 | ## Usage
8 | ***API 15~~***
9 |
10 | You need implement Application.ActivityLifecycleCallbacks to your Application class and override **ComponentCallbacks2#onTrimMemory** which tell you UI hidden.
11 |
12 | ```java
13 | public class MyApplication extends Application implements Application.ActivityLifecycleCallbacks {
14 | private boolean isNeedPassCodeConfirmation = true;
15 |
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 | registerActivityLifecycleCallbacks(this);
20 | }
21 |
22 | @Override public void onTrimMemory(int level) {
23 | super.onTrimMemory(level);
24 | if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
25 | isNeedPassCodeConfirmation = true;
26 | }
27 | }
28 |
29 | @Override
30 | public void onActivityStarted(Activity activity) {
31 | if (isNeedPassCodeConfirmation && PrefUtil.getBoolean(PREF_KEY_IS_LOCKED)) {
32 | activity.startActivity(/*Activity for entering passcode*/);
33 | }
34 | isNeedPassCodeConfirmation = false;
35 | }
36 | ~~~~
37 | }
38 | ```
39 |
40 | ***Activity for entering passcode***
41 | ```java
42 | @Override
43 | protected void onPause() {
44 | super.onPause();
45 | finish(); //remove this Activity's stack
46 | }
47 |
48 | @Override
49 | public boolean onKeyDown(int keyCode, KeyEvent event) {
50 | if (keyCode == KeyEvent.KEYCODE_BACK) {
51 | moveTaskToBack(true); //Application will be background without regard for Activity stack
52 | return true;
53 | }
54 | return super.onKeyDown(keyCode, event);
55 | }
56 | ```
57 | ## License
58 |
59 | ```
60 | Copyright 2016 Takukya Endo
61 |
62 | Licensed under the Apache License, Version 2.0 (the "License");
63 | you may not use this file except in compliance with the License.
64 | You may obtain a copy of the License at
65 |
66 | http://www.apache.org/licenses/LICENSE-2.0
67 |
68 | Unless required by applicable law or agreed to in writing, software
69 | distributed under the License is distributed on an "AS IS" BASIS,
70 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
71 | See the License for the specific language governing permissions and
72 | limitations under the License.
73 | ```
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/util/PrefUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample.util;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | import com.example.u_nation.passcodelocksample.MyApplication;
7 |
8 | public class PrefUtil {
9 |
10 | private static SharedPreferences shPref;
11 | private static SharedPreferences.Editor editor;
12 |
13 | private static SharedPreferences.Editor getEditor() {
14 | if (editor == null) editor = getSharedPreferences().edit();
15 | return editor;
16 | }
17 |
18 | private static SharedPreferences getSharedPreferences() {
19 | if (shPref == null) shPref = MyApplication.getInstance().getSharedPreferences(MyApplication.getInstance().getPackageName(), Context.MODE_PRIVATE);
20 | return shPref;
21 | }
22 |
23 | public static void setSharedPreferences(Context context) {
24 | if (shPref == null) shPref = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
25 | }
26 |
27 | /**
28 | * @param key default -1
29 | */
30 | public static int getInt(String key) {
31 | return getSharedPreferences().getInt(key, -1);
32 | }
33 |
34 | /**
35 | * @param key default -1L
36 | */
37 | public static long getLong(String key) {
38 | return getSharedPreferences().getLong(key, -1L);
39 | }
40 |
41 | /**
42 | * @param key default false
43 | */
44 | public static boolean getBoolean(String key) {
45 | return getSharedPreferences().getBoolean(key, false);
46 | }
47 |
48 | /**
49 | * @param key default ""
50 | */
51 | public static String getString(String key) {
52 | return getSharedPreferences().getString(key, "");
53 | }
54 |
55 |
56 | public static void putInt(String key, int value) {
57 | getEditor().putInt(key, value).apply();
58 | }
59 |
60 | public static void putLong(String key, long value) {
61 | getEditor().putLong(key, value).apply();
62 | }
63 |
64 | public static void putBoolean(String key, boolean value) {
65 | getEditor().putBoolean(key, value).apply();
66 | }
67 |
68 | public static void putString(String key, String value) {
69 | getEditor().putString(key, value).apply();
70 | }
71 |
72 | public static boolean isEmpty(String key) {
73 | return getString(key).equals("");
74 | }
75 |
76 | public static synchronized void removeValue(String key) {
77 | getEditor().remove(key).apply();
78 | }
79 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/sample_activities/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample.sample_activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 |
9 | import com.example.u_nation.passcodelocksample.Constants;
10 | import com.example.u_nation.passcodelocksample.PassCodeSetActivity;
11 | import com.example.u_nation.passcodelocksample.R;
12 | import com.example.u_nation.passcodelocksample.util.PrefUtil;
13 | import com.example.u_nation.passcodelocksample.util.ShowToast;
14 |
15 | import timber.log.Timber;
16 |
17 |
18 | public class MainActivity extends AppCompatActivity {
19 |
20 | public static Intent createIntent(Context context) {
21 | return new Intent(context, MainActivity.class);
22 | }
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | Timber.d("onCreate");
28 | setContentView(R.layout.activity_main);
29 | setTitle(this.getClass().getSimpleName());
30 | }
31 |
32 | @Override
33 | protected void onResume() {
34 | super.onResume();
35 | Timber.d("onResume");
36 | }
37 |
38 | @Override
39 | protected void onPause() {
40 | super.onPause();
41 | Timber.d("onPause");
42 | }
43 |
44 | @Override
45 | protected void onStop() {
46 | super.onStop();
47 | Timber.d("onStop");
48 | }
49 |
50 | @Override
51 | protected void onUserLeaveHint() {
52 | super.onUserLeaveHint();
53 | Timber.d("onUserLeaveHint");
54 | }
55 |
56 | @Override
57 | protected void onDestroy() {
58 | super.onDestroy();
59 | Timber.i("onDestroy");
60 | }
61 |
62 | /*no stack*/
63 | public void onSample1(View view) {
64 | startActivity(Sample1Activity.createIntent(getApplicationContext()));
65 | finish();
66 | }
67 |
68 | /*remain stack*/
69 | public void onSample2(View view) {
70 | startActivity(Sample2Activity.createIntent(getApplicationContext()));
71 | }
72 |
73 | public void onLock(View view) {
74 | startActivity(PassCodeSetActivity.createIntent(getApplicationContext()));
75 | }
76 |
77 | public void onUnlock(View view) {
78 | PrefUtil.putBoolean(Constants.PREF_KEY_IS_LOCKED, false);
79 | PrefUtil.putInt(Constants.PREF_KEY_PASSWORD, 0);
80 | ShowToast.show("Unlock passcode!", this);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
36 |
37 |
44 |
45 |
46 |
54 |
55 |
60 |
61 |
66 |
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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/PassCodeConfirmationActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.os.Bundle;
10 | import android.os.Handler;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.util.SparseArray;
13 | import android.view.KeyEvent;
14 | import android.view.View;
15 | import android.widget.ImageView;
16 | import android.widget.TextView;
17 |
18 | import com.example.u_nation.passcodelocksample.util.PrefUtil;
19 |
20 | import timber.log.Timber;
21 |
22 | public class PassCodeConfirmationActivity extends AppCompatActivity implements View.OnClickListener {
23 | private final String TEXT_SUB_MISTAKE = "Wrong passcode.Please try it again";
24 | private TextView text_sub_pass;
25 | private ImageView[] array_image_view;
26 | private StringBuilder stringBuilder = new StringBuilder();
27 | private SparseArray array_box = new SparseArray<>();
28 | private Bitmap bitmapBlack = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
29 | private Bitmap bitmapGrey = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
30 |
31 | public static Intent createIntent(Context context) {
32 | return new Intent(context, PassCodeConfirmationActivity.class);
33 | }
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_confirm_pass_code);
39 | initViews();
40 | initCircleCanvas();
41 | }
42 |
43 | private void initViews() {
44 | text_sub_pass = (TextView) findViewById(R.id.text_sub_pass);
45 | array_image_view = new ImageView[]{(ImageView) findViewById(R.id.circle1), (ImageView) findViewById(R.id.circle2), (ImageView) findViewById(R.id.circle3), (ImageView) findViewById(R.id.circle4)};
46 |
47 | int[] array_id = {R.id.box0, R.id.box1, R.id.box2, R.id.box3, R.id.box4, R.id.box5, R.id.box6, R.id.box7, R.id.box8, R.id.box9};
48 | for (int i = 0; i <= 9; i++) {
49 | findViewById(array_id[i]).setOnClickListener(this);
50 | array_box.put(array_id[i], String.valueOf(i));
51 | }
52 | }
53 |
54 | private void initCircleCanvas() {
55 | // black circle
56 | Canvas canvas;
57 | canvas = new Canvas(bitmapBlack);
58 | Paint paint;
59 | paint = new Paint();
60 | paint.setColor(Color.BLACK);
61 | paint.setStyle(Paint.Style.FILL);
62 | paint.setAntiAlias(true);
63 | canvas.drawCircle(150, 150, 148, paint);
64 | // grey circle
65 | Canvas canvas2;
66 | canvas2 = new Canvas(bitmapGrey);
67 | Paint paint2;
68 | paint2 = new Paint();
69 | paint2.setColor(Color.parseColor("#f5f5f5"));
70 | paint2.setStyle(Paint.Style.FILL);
71 | paint2.setAntiAlias(true);
72 | canvas2.drawCircle(150, 150, 148, paint2);
73 | }
74 |
75 | private void initStringBuilder() {
76 | stringBuilder.setLength(0);
77 | stringBuilder.trimToSize();
78 | }
79 |
80 | private void initCircleColor() {
81 | for (ImageView circle : array_image_view) circle.setImageBitmap(bitmapGrey);
82 | }
83 |
84 | @Override
85 | public void onClick(View v) {
86 | if (array_box.indexOfKey(v.getId()) >= 0) inputPassword(array_box.get(v.getId()));
87 | }
88 |
89 | public void onDelete(View view) {
90 | int length = stringBuilder.length();
91 | deleteCircleColor(length);
92 | if (length != 0) stringBuilder.deleteCharAt(length - 1);
93 | }
94 |
95 | private void deleteCircleColor(int length) {
96 | if (length > 0) array_image_view[length - 1].setImageBitmap(bitmapGrey);
97 | }
98 |
99 | private void inputPassword(String password) {
100 | Timber.d(password);
101 | int length = stringBuilder.length();
102 | if (length > 3) return;
103 | array_image_view[length].setImageBitmap(bitmapBlack);
104 | stringBuilder.append(password);
105 | if (length == 3) new Handler().postDelayed(new Runnable() {
106 | @Override
107 | public void run() {
108 | confirmPassword();
109 | }
110 | }, 200);
111 | }
112 |
113 | private void confirmPassword() {
114 | if (Integer.parseInt(stringBuilder.toString()) == PrefUtil.getInt(Constants.PREF_KEY_PASSWORD)) {
115 | finish();
116 | } else {
117 | text_sub_pass.setText(TEXT_SUB_MISTAKE);
118 | initStringBuilder();
119 | initCircleColor();
120 | }
121 | }
122 |
123 | @Override
124 | protected void onPause() {
125 | super.onPause();
126 | finish(); //remove stack
127 | }
128 |
129 | @Override
130 | public boolean onKeyDown(int keyCode, KeyEvent event) {
131 | if (keyCode == KeyEvent.KEYCODE_BACK) {
132 | moveTaskToBack(true); //Application will be background without regard for Activity stack
133 | return true;
134 | }
135 | return super.onKeyDown(keyCode, event);
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/u_nation/passcodelocksample/PassCodeSetActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.u_nation.passcodelocksample;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.os.Bundle;
10 | import android.os.Handler;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.util.SparseArray;
13 | import android.view.KeyEvent;
14 | import android.view.View;
15 | import android.widget.ImageView;
16 | import android.widget.TextView;
17 |
18 | import com.example.u_nation.passcodelocksample.util.PrefUtil;
19 | import com.example.u_nation.passcodelocksample.util.ShowToast;
20 |
21 | import timber.log.Timber;
22 |
23 | public class PassCodeSetActivity extends AppCompatActivity implements View.OnClickListener {
24 |
25 | private final String TEXT_MAIN_CONFIRM = "Confirm passcode";
26 | private final String TEXT_SUB_CONFIRM = "Please re-enter passcode";
27 | private final String TEXT_MAIN_MISTAKE = "Passcode Lock";
28 | private final String TEXT_SUB_MISTAKE = "Wrong passcode.Please try it again";
29 | private TextView text_main_pass;
30 | private TextView text_sub_pass;
31 | private ImageView[] array_image_view;
32 | private StringBuilder stringBuilder = new StringBuilder();
33 | private SparseArray array_box = new SparseArray<>();
34 | private Bitmap bitmapBlack = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
35 | private Bitmap bitmapGrey = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
36 | private int password;
37 | private boolean isDoubleCheck = false;
38 |
39 | public static Intent createIntent(Context context) {
40 | return new Intent(context, PassCodeSetActivity.class);
41 | }
42 |
43 | @Override protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_input_pass_code);
46 | initViews();
47 | initCircleCanvas();
48 | }
49 |
50 | private void initViews() {
51 | text_main_pass = findViewById(R.id.text_main_pass);
52 | text_sub_pass = findViewById(R.id.text_sub_pass);
53 | array_image_view = new ImageView[] {
54 | findViewById(R.id.circle1), findViewById(R.id.circle2), findViewById(R.id.circle3),
55 | findViewById(R.id.circle4)
56 | };
57 |
58 | int[] array_id = {
59 | R.id.box0, R.id.box1, R.id.box2, R.id.box3, R.id.box4, R.id.box5, R.id.box6, R.id.box7,
60 | R.id.box8, R.id.box9
61 | };
62 | for (int i = 0; i <= 9; i++) {
63 | findViewById(array_id[i]).setOnClickListener(this);
64 | array_box.put(array_id[i], String.valueOf(i));
65 | }
66 | }
67 |
68 | private void initCircleCanvas() {
69 | Canvas canvas;
70 | canvas = new Canvas(bitmapBlack);
71 | Paint paint;
72 | paint = new Paint();
73 | paint.setColor(Color.BLACK);
74 | paint.setStyle(Paint.Style.FILL);
75 | paint.setAntiAlias(true);
76 | canvas.drawCircle(150, 150, 148, paint);
77 |
78 | Canvas canvas2;
79 | canvas2 = new Canvas(bitmapGrey);
80 | Paint paint2;
81 | paint2 = new Paint();
82 | paint2.setColor(Color.parseColor("#f5f5f5"));
83 | paint2.setStyle(Paint.Style.FILL);
84 | paint2.setAntiAlias(true);
85 | canvas2.drawCircle(150, 150, 148, paint2);
86 | }
87 |
88 | private void initStringBuilder() {
89 | stringBuilder.setLength(0);
90 | stringBuilder.trimToSize();
91 | }
92 |
93 | private void initCircleColor() {
94 | for (ImageView circle : array_image_view) circle.setImageBitmap(bitmapGrey);
95 | }
96 |
97 | @Override public void onClick(View v) {
98 | if (array_box.indexOfKey(v.getId()) >= 0) inputPassword(array_box.get(v.getId()));
99 | }
100 |
101 | public void onDelete(View view) {
102 | int length = stringBuilder.length();
103 | deleteCircleColor(length);
104 | if (length != 0) stringBuilder.deleteCharAt(length - 1);
105 | }
106 |
107 | private void deleteCircleColor(int length) {
108 | if (length > 0) array_image_view[length - 1].setImageBitmap(bitmapGrey);
109 | }
110 |
111 | private void inputPassword(String password) {
112 | Timber.d(password);
113 | int length = stringBuilder.length();
114 | if (length > 3) return;
115 | array_image_view[length].setImageBitmap(bitmapBlack);
116 | stringBuilder.append(password);
117 | if (length == 3) {
118 | new Handler().postDelayed(new Runnable() {
119 | @Override public void run() {
120 | confirmPassword();
121 | }
122 | }, 200);
123 | }
124 | }
125 |
126 | private void confirmPassword() {
127 | if (isDoubleCheck) {
128 | if (password == Integer.parseInt(stringBuilder.toString())) {
129 | ShowToast.show("Locked!", this);
130 | PrefUtil.putInt(Constants.PREF_KEY_PASSWORD, password);
131 | PrefUtil.putBoolean(Constants.PREF_KEY_IS_LOCKED, true);
132 | finish();
133 | } else {
134 | text_main_pass.setText(TEXT_MAIN_MISTAKE);
135 | text_sub_pass.setText(TEXT_SUB_MISTAKE);
136 | isDoubleCheck = false;
137 | initStringBuilder();
138 | initCircleColor();
139 | }
140 | } else {
141 | isDoubleCheck = true;
142 | text_main_pass.setText(TEXT_MAIN_CONFIRM);
143 | text_sub_pass.setText(TEXT_SUB_CONFIRM);
144 | password = Integer.parseInt(stringBuilder.toString());
145 | initStringBuilder();
146 | initCircleColor();
147 | }
148 | }
149 |
150 | public void onCancel(View view) {
151 | finish();
152 | }
153 |
154 | @Override public boolean onKeyDown(int keyCode, KeyEvent event) {
155 | if (keyCode == KeyEvent.KEYCODE_BACK) {
156 | finish();
157 | return true;
158 | }
159 | return super.onKeyDown(keyCode, event);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_input_pass_code.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
17 |
18 |
28 |
29 |
38 |
39 |
40 |
47 |
48 |
52 |
53 |
62 |
63 |
72 |
73 |
82 |
83 |
92 |
93 |
97 |
98 |
99 |
106 |
107 |
111 |
112 |
117 |
118 |
119 |
126 |
127 |
133 |
134 |
147 |
148 |
160 |
161 |
173 |
174 |
175 |
181 |
182 |
194 |
195 |
207 |
208 |
220 |
221 |
222 |
228 |
229 |
241 |
242 |
254 |
255 |
267 |
268 |
269 |
275 |
276 |
289 |
290 |
302 |
303 |
307 |
308 |
317 |
318 |
319 |
320 |
321 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_confirm_pass_code.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
17 |
18 |
28 |
29 |
38 |
39 |
40 |
47 |
48 |
52 |
53 |
62 |
63 |
72 |
73 |
82 |
83 |
92 |
93 |
97 |
98 |
99 |
106 |
107 |
111 |
112 |
117 |
118 |
119 |
126 |
127 |
133 |
134 |
147 |
148 |
160 |
161 |
173 |
174 |
175 |
181 |
182 |
194 |
195 |
207 |
208 |
220 |
221 |
222 |
228 |
229 |
241 |
242 |
254 |
255 |
267 |
268 |
269 |
275 |
276 |
290 |
291 |
303 |
304 |
308 |
309 |
318 |
319 |
320 |
321 |
322 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #64cda2
4 | #5ab891
5 | #7484bf
6 | #eee780
7 | #679fc8
8 |
9 | #ffffff
10 | #ffffff
11 |
12 |
13 | #000000
14 | #ffffff
15 |
16 | #FFEBEE
17 | #FFCDD2
18 | #EF9A9A
19 | #E57373
20 | #EF5350
21 | #F44336
22 | #E53935
23 | #D32F2F
24 | #C62828
25 | #B71C1C
26 |
27 |
28 | #FCE4EC
29 | #F8BBD0
30 | #F48FB1
31 | #F06292
32 | #EC407A
33 | #E91E63
34 | #D81B60
35 | #C2185B
36 | #AD1457
37 | #880E4F
38 | #FF80AB
39 | #FF4081
40 | #F50057
41 | #C51162
42 |
43 | #F3E5F5
44 | #E1BEE7
45 | #CE93D8
46 | #BA68C8
47 | #AB47BC
48 | #9C27B0
49 | #8E24AA
50 | #7B1FA2
51 | #6A1B9A
52 | #4A148C
53 | #EA80FC
54 | #E040FB
55 | #D500F9
56 | #AA00FF
57 |
58 | #EDE7F6
59 | #D1C4E9
60 | #B39DDB
61 | #9575CD
62 | #7E57C2
63 | #673AB7
64 | #5E35B1
65 | #512DA8
66 | #4527A0
67 | #311B92
68 | #B388FF
69 | #7C4DFF
70 | #651FFF
71 | #6200EA
72 |
73 | #E8EAF6
74 | #C5CAE9
75 | #9FA8DA
76 | #7986CB
77 | #5C6BC0
78 | #3F51B5
79 | #3949AB
80 | #303F9F
81 | #283593
82 | #1A237E
83 | #8C9EFF
84 | #536DFE
85 | #3D5AFE
86 | #304FFE
87 |
88 | #E3F2FD
89 | #BBDEFB
90 | #90CAF9
91 | #64B5F6
92 | #42A5F5
93 | #2196F3
94 | #1E88E5
95 | #1976D2
96 | #1565C0
97 | #0D47A1
98 | #82B1FF
99 | #448AFF
100 | #2979FF
101 | #2962FF
102 |
103 | #E1F5FE
104 | #B3E5FC
105 | #81D4FA
106 | #4FC3F7
107 | #29B6F6
108 | #03A9F4
109 | #039BE5
110 | #0288D1
111 | #0277BD
112 | #01579B
113 | #80D8FF
114 | #40C4FF
115 | #00B0FF
116 | #0091EA
117 |
118 | #E0F7FA
119 | #B2EBF2
120 | #80DEEA
121 | #4DD0E1
122 | #26C6DA
123 | #00BCD4
124 | #00ACC1
125 | #0097A7
126 | #00838F
127 | #006064
128 | #84FFFF
129 | #18FFFF
130 | #00E5FF
131 | #00B8D4
132 |
133 | #E0F2F1
134 | #B2DFDB
135 | #80CBC4
136 | #4DB6AC
137 | #26A69A
138 | #009688
139 | #00897B
140 | #00796B
141 | #00695C
142 | #004D40
143 | #A7FFEB
144 | #64FFDA
145 | #1DE9B6
146 | #00BFA5
147 |
148 | #E8F5E9
149 | #C8E6C9
150 | #A5D6A7
151 | #81C784
152 | #66BB6A
153 | #4CAF50
154 | #43A047
155 | #388E3C
156 | #2E7D32
157 | #1B5E20
158 | #B9F6CA
159 | #69F0AE
160 | #00E676
161 | #00C853
162 |
163 | #F1F8E9
164 | #DCEDC8
165 | #C5E1A5
166 | #AED581
167 | #9CCC65
168 | #8BC34A
169 | #7CB342
170 | #689F38
171 | #558B2F
172 | #33691E
173 | #CCFF90
174 | #B2FF59
175 | #76FF03
176 | #64DD17
177 |
178 | #F9FBE7
179 | #F0F4C3
180 | #E6EE9C
181 | #DCE775
182 | #D4E157
183 | #CDDC39
184 | #C0CA33
185 | #AFB42B
186 | #9E9D24
187 | #827717
188 | #F4FF81
189 | #EEFF41
190 | #C6FF00
191 | #AEEA00
192 |
193 | #FFFDE7
194 | #FFF9C4
195 | #FFF59D
196 | #FFF176
197 | #FFEE58
198 | #FFEB3B
199 | #FDD835
200 | #FBC02D
201 | #F9A825
202 | #F57F17
203 | #FFFF8D
204 | #FFFF00
205 | #FFEA00
206 | #FFD600
207 |
208 | #FFF8E1
209 | #FFECB3
210 | #FFE082
211 | #FFD54F
212 | #FFCA28
213 | #FFC107
214 | #FFB300
215 | #FFA000
216 | #FF8F00
217 | #FF6F00
218 | #FFE57F
219 | #FFD740
220 | #FFC400
221 | #FFAB00
222 |
223 | #FFF3E0
224 | #FFE0B2
225 | #FFCC80
226 | #FFB74D
227 | #FFA726
228 | #FF9800
229 | #FB8C00
230 | #F57C00
231 | #EF6C00
232 | #E65100
233 | #FFD180
234 | #FFAB40
235 | #FF9100
236 | #FF6D00
237 |
238 | #FBE9E7
239 | #FFCCBC
240 | #FFAB91
241 | #FF8A65
242 | #FF7043
243 | #FF5722
244 | #F4511E
245 | #E64A19
246 | #D84315
247 | #BF360C
248 | #FF9E80
249 | #FF6E40
250 | #FF3D00
251 | #DD2C00
252 |
253 | #EFEBE9
254 | #D7CCC8
255 | #BCAAA4
256 | #A1887F
257 | #8D6E63
258 | #795548
259 | #6D4C41
260 | #5D4037
261 | #4E342E
262 | #3E2723
263 |
264 | #FAFAFA
265 | #F5F5F5
266 | #EEEEEE
267 | #E0E0E0
268 | #BDBDBD
269 | #9E9E9E
270 | #757575
271 | #616161
272 | #424242
273 | #212121
274 |
275 | #ECEFF1
276 | #CFD8DC
277 | #B0BEC5
278 | #90A4AE
279 | #78909C
280 | #607D8B
281 | #546E7A
282 | #455A64
283 | #37474F
284 | #263238
285 |
286 |
--------------------------------------------------------------------------------