adding a pattern protection to the toggle button
This commit is contained in:
parent
d9056ed057
commit
fff519b521
|
@ -39,6 +39,7 @@ dependencies {
|
|||
compile 'com.google.code.gson:gson:2.8.0'
|
||||
compile 'com.github.chrisbanes:PhotoView:2.1.2'
|
||||
compile 'it.sephiroth.android.exif:library:1.0.1'
|
||||
compile 'com.andrognito.patternlockview:patternlockview:1.0.0'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
|||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.dialogs.PatternDialog
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.helpers.*
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
|
@ -141,10 +142,19 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun setupPasswordProtection() {
|
||||
settings_password_protection.isChecked = config.passwordProtection
|
||||
settings_password_protection.isChecked = config.isPasswordProtectionOn
|
||||
settings_password_protection_holder.setOnClickListener {
|
||||
settings_password_protection.toggle()
|
||||
config.passwordProtection = settings_password_protection.isChecked
|
||||
PatternDialog(this) {
|
||||
if (config.isPasswordProtectionOn) {
|
||||
settings_password_protection.isChecked = false
|
||||
config.isPasswordProtectionOn = false
|
||||
config.passwordHash = ""
|
||||
} else {
|
||||
settings_password_protection.isChecked = true
|
||||
config.isPasswordProtectionOn = true
|
||||
config.passwordHash = it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.simplemobiletools.gallery.dialogs
|
||||
|
||||
import android.os.Handler
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import com.andrognito.patternlockview.PatternLockView
|
||||
import com.andrognito.patternlockview.listener.PatternLockViewListener
|
||||
import com.andrognito.patternlockview.utils.PatternLockUtils
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import kotlinx.android.synthetic.main.dialog_pattern.view.*
|
||||
|
||||
class PatternDialog(val activity: SimpleActivity, val callback: (hash: String) -> Unit) {
|
||||
var dialog: AlertDialog? = null
|
||||
|
||||
init {
|
||||
var hash = ""
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_pattern, null)
|
||||
view.apply {
|
||||
pattern_lock_view.correctStateColor = activity.config.primaryColor
|
||||
pattern_lock_view.normalStateColor = activity.config.textColor
|
||||
pattern_lock_view.addPatternLockListener(object : PatternLockViewListener {
|
||||
override fun onComplete(pattern: MutableList<PatternLockView.Dot>?) {
|
||||
if (hash.isEmpty()) {
|
||||
hash = PatternLockUtils.patternToSha1(pattern_lock_view, pattern)
|
||||
pattern_lock_view.clearPattern()
|
||||
pattern_dialog_title.setText(R.string.repeat_pattern)
|
||||
} else {
|
||||
val newHash = PatternLockUtils.patternToSha1(pattern_lock_view, pattern)
|
||||
if (hash == newHash) {
|
||||
pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.CORRECT)
|
||||
Handler().postDelayed({
|
||||
callback(hash)
|
||||
dialog!!.dismiss()
|
||||
}, 300)
|
||||
} else {
|
||||
pattern_lock_view.setViewMode(PatternLockView.PatternViewMode.WRONG)
|
||||
activity.toast(R.string.wrong_pattern)
|
||||
Handler().postDelayed({
|
||||
hash = ""
|
||||
pattern_lock_view.clearPattern()
|
||||
pattern_dialog_title.setText(R.string.select_pattern)
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
}
|
||||
|
||||
override fun onStarted() {
|
||||
}
|
||||
|
||||
override fun onProgress(progressPattern: MutableList<PatternLockView.Dot>?) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -233,7 +233,11 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
get() = prefs.getBoolean(REPLACE_SHARE_WITH_ROTATE, false)
|
||||
set(replaceShare) = prefs.edit().putBoolean(REPLACE_SHARE_WITH_ROTATE, replaceShare).apply()
|
||||
|
||||
var passwordProtection: Boolean
|
||||
get() = prefs.getBoolean(PASSWORD_PROTECTION, false)
|
||||
set(passwordProtection) = prefs.edit().putBoolean(PASSWORD_PROTECTION, passwordProtection).apply()
|
||||
var isPasswordProtectionOn: Boolean
|
||||
get() = prefs.getBoolean(IS_PASSWORD_PROTECTION, false)
|
||||
set(passwordProtection) = prefs.edit().putBoolean(IS_PASSWORD_PROTECTION, passwordProtection).apply()
|
||||
|
||||
var passwordHash: String
|
||||
get() = prefs.getString(PASSWORD_HASH, "")
|
||||
set(passwordHash) = prefs.edit().putString(PASSWORD_HASH, passwordHash).apply()
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ val ALBUM_COVERS = "album_covers"
|
|||
val SCROLL_HORIZONTALLY = "scroll_horizontally"
|
||||
val HIDE_SYSTEM_UI = "hide_system_ui"
|
||||
val REPLACE_SHARE_WITH_ROTATE = "replace_share_with_rotate"
|
||||
val PASSWORD_PROTECTION = "password_protection"
|
||||
val IS_PASSWORD_PROTECTION = "password_protection"
|
||||
val PASSWORD_HASH = "password_hash"
|
||||
|
||||
val NOMEDIA = ".nomedia"
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/pattern_dialog_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/pattern_dialog_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:text="@string/select_pattern"/>
|
||||
|
||||
<com.andrognito.patternlockview.PatternLockView
|
||||
android:id="@+id/pattern_lock_view"
|
||||
android:layout_width="280dp"
|
||||
android:layout_height="280dp"
|
||||
android:layout_below="@+id/pattern_dialog_title"
|
||||
android:layout_centerInParent="true"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Zadajte PIN</string>
|
||||
<string name="wrong_pin">Nesprávny PIN</string>
|
||||
<string name="repeat_pin">Zopakujte PIN</string>
|
||||
<string name="pattern">Vzor</string>
|
||||
<string name="select_pattern">Zvoľte vzor</string>
|
||||
<string name="wrong_pattern">Nesprávny vzor</string>
|
||||
<string name="repeat_pattern">Zopakujte vzor</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
|
||||
<!-- Password protection -->
|
||||
<string name="pin">PIN</string>
|
||||
<string name="enter_pin">Enter PIN</string>
|
||||
<string name="wrong_pin">Wrong PIN</string>
|
||||
<string name="repeat_pin">Repeat PIN</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="select_pattern">Select pattern</string>
|
||||
<string name="wrong_pattern">Wrong pattern</string>
|
||||
<string name="repeat_pattern">Repeat pattern</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue