diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b09b10 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.iml +.gradle +/local.properties +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild +/.idea/caches/build_file_checksums.ser +/app/release/ +/.idea/misc.xml +/gradle2/ +/patternlockview/build +/patternlockview-reactive/build +/app/build \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..6168269 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index a07896e..e5e6629 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ This library is available in **jCenter** which is the default Maven repository u dependencies { // other dependencies here - compile 'com.andrognito.patternlockview:patternlockview:1.0.0' + implementation 'com.andrognito.patternlockview:patternlockview:1.0.0' // Optional, for RxJava2 adapter - compile 'com.andrognito.patternlockview:patternlockview-reactive:1.0.0' + implementation 'com.andrognito.patternlockview:patternlockview-reactive:1.0.0' } ``` @@ -71,13 +71,13 @@ private PatternLockViewListener mPatternLockViewListener = new PatternLockViewLi @Override public void onProgress(List progressPattern) { Log.d(getClass().getName(), "Pattern progress: " + - PatternLockUtils.patternToString(mPatternLockView, progressPattern)); + PatternLockUtils.patternToIntArray(mPatternLockView, progressPattern)); } @Override public void onComplete(List pattern) { Log.d(getClass().getName(), "Pattern complete: " + - PatternLockUtils.patternToString(mPatternLockView, pattern)); + PatternLockUtils.patternToIntArray(mPatternLockView, pattern)); } @Override @@ -103,10 +103,10 @@ RxPatternLockView.patternChanges(mPatternLockView) Log.d(getClass().getName(), "Pattern drawing started"); } else if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_PROGRESS) { Log.d(getClass().getName(), "Pattern progress: " + - PatternLockUtils.patternToString(mPatternLockView, event.getPattern())); + PatternLockUtils.patternToIntArray(mPatternLockView, event.getPattern())); } else if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_COMPLETE) { Log.d(getClass().getName(), "Pattern complete: " + - PatternLockUtils.patternToString(mPatternLockView, event.getPattern())); + PatternLockUtils.patternToIntArray(mPatternLockView, event.getPattern())); } else if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_CLEARED) { Log.d(getClass().getName(), "Pattern has been cleared"); } diff --git a/app/build.gradle b/app/build.gradle index f8891fc..c05ed1c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.application' android { compileSdkVersion rootProject.ext.compileSdkVersion - buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion @@ -13,8 +12,8 @@ android { } dependencies { - compile project(':patternlockview') - compile project(':patternlockview-reactive') - compile rootProject.ext.supportV7 - compile rootProject.ext.rxJava + implementation project(':patternlockview') + implementation project(':patternlockview-reactive') + implementation rootProject.ext.appcompat + implementation rootProject.ext.rxJava } diff --git a/app/src/main/java/com/andrognito/patternlockdemo/MainActivity.java b/app/src/main/java/com/andrognito/patternlockdemo/MainActivity.java index a1657e1..d9002ac 100644 --- a/app/src/main/java/com/andrognito/patternlockdemo/MainActivity.java +++ b/app/src/main/java/com/andrognito/patternlockdemo/MainActivity.java @@ -1,7 +1,7 @@ package com.andrognito.patternlockdemo; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; import android.util.Log; import android.view.Window; import android.view.WindowManager; @@ -14,6 +14,7 @@ import com.andrognito.rxpatternlockview.events.PatternLockCompleteEvent; import com.andrognito.rxpatternlockview.events.PatternLockCompoundEvent; +import java.util.Arrays; import java.util.List; import io.reactivex.functions.Consumer; @@ -31,13 +32,13 @@ public void onStarted() { @Override public void onProgress(List progressPattern) { Log.d(getClass().getName(), "Pattern progress: " + - PatternLockUtils.patternToString(mPatternLockView, progressPattern)); + Arrays.toString(PatternLockUtils.patternToIntArray(mPatternLockView, progressPattern))); } @Override public void onComplete(List pattern) { Log.d(getClass().getName(), "Pattern complete: " + - PatternLockUtils.patternToString(mPatternLockView, pattern)); + Arrays.toString(PatternLockUtils.patternToIntArray(mPatternLockView, pattern))); } @Override @@ -86,10 +87,10 @@ public void accept(PatternLockCompoundEvent event) throws Exception { Log.d(getClass().getName(), "Pattern drawing started"); } else if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_PROGRESS) { Log.d(getClass().getName(), "Pattern progress: " + - PatternLockUtils.patternToString(mPatternLockView, event.getPattern())); + Arrays.toString(PatternLockUtils.patternToIntArray(mPatternLockView, event.getPattern()))); } else if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_COMPLETE) { Log.d(getClass().getName(), "Pattern complete: " + - PatternLockUtils.patternToString(mPatternLockView, event.getPattern())); + Arrays.toString(PatternLockUtils.patternToIntArray(mPatternLockView, event.getPattern()))); } else if (event.getEventType() == PatternLockCompoundEvent.EventType.PATTERN_CLEARED) { Log.d(getClass().getName(), "Pattern has been cleared"); } diff --git a/build.gradle b/build.gradle index bdfa4f8..3e01653 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:4.0.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' } @@ -14,17 +15,18 @@ buildscript { allprojects { repositories { jcenter() + google() } } ext { minSdkVersion = 14 - targetSdkVersion = 25 - compileSdkVersion = 25 - buildToolsVersion = '25.0.2' + targetSdkVersion = 29 + compileSdkVersion = 29 // dependencies - supportV7 = 'com.android.support:appcompat-v7:25.3.0' + appcompat = 'androidx.appcompat:appcompat:1.0.0' + annotation = 'androidx.annotation:annotation:1.1.0' rxJava = 'io.reactivex.rxjava2:rxjava:2.0.2' rxAndroid = 'io.reactivex.rxjava2:rxandroid:2.0.0' } diff --git a/gradle.properties b/gradle.properties index 84c9771..543eeb7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,5 @@ VERSION_NAME=1.0.0 VERSION_CODE=1 GROUP=com.andrognito.patternlockview +android.useAndroidX=true +android.enableJetifier=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3c326ac..80a840a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Mar 19 20:13:42 IST 2017 +#Tue Jun 02 11:53:03 JST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/patternlockview-reactive/build.gradle b/patternlockview-reactive/build.gradle index 517b05b..c33b78b 100644 --- a/patternlockview-reactive/build.gradle +++ b/patternlockview-reactive/build.gradle @@ -27,7 +27,6 @@ ext { android { compileSdkVersion rootProject.ext.compileSdkVersion - buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion @@ -38,9 +37,10 @@ android { } dependencies { - compile project(':patternlockview') - compile rootProject.ext.rxJava - compile rootProject.ext.rxAndroid + implementation project(':patternlockview') + implementation rootProject.ext.annotation + implementation rootProject.ext.rxJava + implementation rootProject.ext.rxAndroid } apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' diff --git a/patternlockview-reactive/src/main/java/com/andrognito/rxpatternlockview/events/BasePatternLockEvent.java b/patternlockview-reactive/src/main/java/com/andrognito/rxpatternlockview/events/BasePatternLockEvent.java index 80d064e..25ded95 100644 --- a/patternlockview-reactive/src/main/java/com/andrognito/rxpatternlockview/events/BasePatternLockEvent.java +++ b/patternlockview-reactive/src/main/java/com/andrognito/rxpatternlockview/events/BasePatternLockEvent.java @@ -1,6 +1,6 @@ package com.andrognito.rxpatternlockview.events; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import com.andrognito.patternlockview.PatternLockView; diff --git a/patternlockview-reactive/src/main/java/com/andrognito/rxpatternlockview/events/PatternLockCompoundEvent.java b/patternlockview-reactive/src/main/java/com/andrognito/rxpatternlockview/events/PatternLockCompoundEvent.java index 3633ad0..6572525 100644 --- a/patternlockview-reactive/src/main/java/com/andrognito/rxpatternlockview/events/PatternLockCompoundEvent.java +++ b/patternlockview-reactive/src/main/java/com/andrognito/rxpatternlockview/events/PatternLockCompoundEvent.java @@ -1,6 +1,6 @@ package com.andrognito.rxpatternlockview.events; -import android.support.annotation.IntDef; +import androidx.annotation.IntDef; import com.andrognito.patternlockview.PatternLockView; diff --git a/patternlockview/build.gradle b/patternlockview/build.gradle index 0b75fb7..bae8e52 100644 --- a/patternlockview/build.gradle +++ b/patternlockview/build.gradle @@ -27,7 +27,6 @@ ext { android { compileSdkVersion rootProject.ext.compileSdkVersion - buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion @@ -38,7 +37,8 @@ android { } dependencies { - compile rootProject.ext.supportV7 + implementation rootProject.ext.appcompat + implementation rootProject.ext.annotation } apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' diff --git a/patternlockview/src/main/java/com/andrognito/patternlockview/PatternLockView.java b/patternlockview/src/main/java/com/andrognito/patternlockview/PatternLockView.java index 1624fd0..b967bbc 100755 --- a/patternlockview/src/main/java/com/andrognito/patternlockview/PatternLockView.java +++ b/patternlockview/src/main/java/com/andrognito/patternlockview/PatternLockView.java @@ -14,9 +14,9 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; -import android.support.annotation.ColorInt; -import android.support.annotation.Dimension; -import android.support.annotation.IntDef; +import androidx.annotation.ColorInt; +import androidx.annotation.Dimension; +import androidx.annotation.IntDef; import android.util.AttributeSet; import android.view.HapticFeedbackConstants; import android.view.MotionEvent; @@ -391,7 +391,7 @@ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) protected Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); return new SavedState(superState, - PatternLockUtils.patternToString(this, mPattern), + PatternLockUtils.patternToIntArray(this, mPattern), mPatternViewMode, mInputEnabled, mInStealthMode, mEnableHapticFeedback); } @@ -401,7 +401,7 @@ protected void onRestoreInstanceState(Parcelable state) { final SavedState savedState = (SavedState) state; super.onRestoreInstanceState(savedState.getSuperState()); setPattern(CORRECT, - PatternLockUtils.stringToPattern(this, savedState.getSerializedPattern())); + PatternLockUtils.intArrayToPattern(this, savedState.getSerializedPattern())); mPatternViewMode = savedState.getDisplayMode(); mInputEnabled = savedState.isInputEnabled(); mInStealthMode = savedState.isInStealthMode(); @@ -1264,7 +1264,7 @@ private Dot(Parcel in) { */ private static class SavedState extends BaseSavedState { - private final String mSerializedPattern; + private final int[] mSerializedPattern; private final int mDisplayMode; private final boolean mInputEnabled; private final boolean mInStealthMode; @@ -1273,7 +1273,7 @@ private static class SavedState extends BaseSavedState { /** * Constructor called from {@link PatternLockView#onSaveInstanceState()} */ - private SavedState(Parcelable superState, String serializedPattern, + private SavedState(Parcelable superState, int[] serializedPattern, int displayMode, boolean inputEnabled, boolean inStealthMode, boolean tactileFeedbackEnabled) { super(superState); @@ -1291,14 +1291,14 @@ private SavedState(Parcelable superState, String serializedPattern, private SavedState(Parcel in) { super(in); - mSerializedPattern = in.readString(); + mSerializedPattern = in.createIntArray(); mDisplayMode = in.readInt(); mInputEnabled = (Boolean) in.readValue(null); mInStealthMode = (Boolean) in.readValue(null); mTactileFeedbackEnabled = (Boolean) in.readValue(null); } - public String getSerializedPattern() { + public int[] getSerializedPattern() { return mSerializedPattern; } @@ -1321,7 +1321,7 @@ public boolean isTactileFeedbackEnabled() { @Override public void writeToParcel(Parcel dest, int flags) { super.writeToParcel(dest, flags); - dest.writeString(mSerializedPattern); + dest.writeIntArray(mSerializedPattern); dest.writeInt(mDisplayMode); dest.writeValue(mInputEnabled); dest.writeValue(mInStealthMode); diff --git a/patternlockview/src/main/java/com/andrognito/patternlockview/utils/PatternLockUtils.java b/patternlockview/src/main/java/com/andrognito/patternlockview/utils/PatternLockUtils.java index 545785b..30a4a37 100755 --- a/patternlockview/src/main/java/com/andrognito/patternlockview/utils/PatternLockUtils.java +++ b/patternlockview/src/main/java/com/andrognito/patternlockview/utils/PatternLockUtils.java @@ -28,10 +28,6 @@ public class PatternLockUtils { - private static final String UTF8 = "UTF-8"; - private static final String SHA1 = "SHA-1"; - private static final String MD5 = "MD5"; - private PatternLockUtils() { throw new AssertionError("You can not instantiate this class. Use its static utility " + "methods instead"); @@ -44,87 +40,38 @@ private PatternLockUtils() { * @param pattern The actual pattern * @return The pattern in its string form */ - public static String patternToString(PatternLockView patternLockView, - List pattern) { + + public static int[] patternToIntArray(PatternLockView patternLockView, + List pattern) { if (pattern == null) { - return ""; + return new int[0]; } int patternSize = pattern.size(); - StringBuilder stringBuilder = new StringBuilder(); - + int[] patternIntArray = new int[patternSize]; for (int i = 0; i < patternSize; i++) { PatternLockView.Dot dot = pattern.get(i); - stringBuilder.append((dot.getRow() * patternLockView.getDotCount() + dot.getColumn())); + patternIntArray[i] = (dot.getRow() * patternLockView.getDotCount() + dot.getColumn()); } - return stringBuilder.toString(); + return patternIntArray; } /** * De-serializes a given string to its equivalent pattern representation * - * @param string The pattern serialized with {@link #patternToString} + * @param int[] The pattern serialized with {@link #patternToIntArray} * @return The actual pattern */ - public static List stringToPattern(PatternLockView patternLockView, - String string) { + public static List intArrayToPattern(PatternLockView patternLockView, + int[] combination) { List result = new ArrayList<>(); - for (int i = 0; i < string.length(); i++) { - int number = Character.getNumericValue(string.charAt(i)); - result.add(PatternLockView.Dot.of(number / patternLockView.getDotCount(), - number % patternLockView.getDotCount())); + for (int i = 0; i < combination.length; i++) { + result.add(PatternLockView.Dot.of(combination[i] / patternLockView.getDotCount(), + combination[i] % patternLockView.getDotCount())); } return result; } - /** - * Serializes a given pattern to its equivalent SHA-1 representation. You can store this string - * in any persistence storage or send it to the server for verification - * - * @param pattern The actual pattern - * @return The SHA-1 string of the pattern - */ - public static String patternToSha1(PatternLockView patternLockView, - List pattern) { - try { - MessageDigest messageDigest = MessageDigest.getInstance(SHA1); - messageDigest.update(patternToString(patternLockView, pattern).getBytes(UTF8)); - - byte[] digest = messageDigest.digest(); - BigInteger bigInteger = new BigInteger(1, digest); - return String.format((Locale) null, - "%0" + (digest.length * 2) + "x", bigInteger).toLowerCase(); - } catch (NoSuchAlgorithmException e) { - return null; - } catch (UnsupportedEncodingException e) { - return null; - } - } - - /** - * Serializes a given pattern to its equivalent MD5 representation. You can store this string - * in any persistence storage or send it to the server for verification - * - * @param pattern The actual pattern - * @return The MD5 string of the pattern - */ - public static String patternToMD5(PatternLockView patternLockView, - List pattern) { - try { - MessageDigest messageDigest = MessageDigest.getInstance(MD5); - messageDigest.update(patternToString(patternLockView, pattern).getBytes(UTF8)); - - byte[] digest = messageDigest.digest(); - BigInteger bigInteger = new BigInteger(1, digest); - return String.format((Locale) null, - "%0" + (digest.length * 2) + "x", bigInteger).toLowerCase(); - } catch (NoSuchAlgorithmException e) { - return null; - } catch (UnsupportedEncodingException e) { - return null; - } - } - /** * Generates a random "CAPTCHA" pattern. The generated pattern is easy for the user to re-draw. *

diff --git a/patternlockview/src/main/java/com/andrognito/patternlockview/utils/ResourceUtils.java b/patternlockview/src/main/java/com/andrognito/patternlockview/utils/ResourceUtils.java index 83d64e9..01acdf6 100755 --- a/patternlockview/src/main/java/com/andrognito/patternlockview/utils/ResourceUtils.java +++ b/patternlockview/src/main/java/com/andrognito/patternlockview/utils/ResourceUtils.java @@ -17,11 +17,11 @@ package com.andrognito.patternlockview.utils; import android.content.Context; -import android.support.annotation.ColorRes; -import android.support.annotation.DimenRes; -import android.support.annotation.NonNull; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; +import androidx.annotation.ColorRes; +import androidx.annotation.DimenRes; +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; +import androidx.core.content.ContextCompat; public class ResourceUtils {