Skip to content

Commit

Permalink
Redesign: Add Large/Small PIN and Upgrade Support (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-ludek authored and HashEngineering committed Feb 13, 2020
1 parent e237a37 commit 89b0e1d
Show file tree
Hide file tree
Showing 17 changed files with 477 additions and 55 deletions.
11 changes: 9 additions & 2 deletions common/src/main/java/org/dash/wallet/common/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class Configuration {
private static final String PREFS_ENABLE_FINGERPRINT = "enable_fingerprint";
public static final String PREFS_RESTORING_BACKUP = "restoring_backup";
public static final String PREFS_V7_REDESIGN_TUTORIAL_COMPLETED = "v7_tutorial_completed";

public static final String PREFS_PIN_LENGTH = "pin_length";

private static final int PREFS_DEFAULT_BTC_SHIFT = 0;
private static final int PREFS_DEFAULT_BTC_PRECISION = 4;
Expand Down Expand Up @@ -415,5 +415,12 @@ public boolean getEnableFingerprint() {
public void setEnableFingerprint(boolean remind) {
prefs.edit().putBoolean(PREFS_ENABLE_FINGERPRINT, remind).apply();
}


public int getPinLength() {
return prefs.getInt(PREFS_PIN_LENGTH, 4);
}

public void setPinLength(int pinLength) {
prefs.edit().putInt(PREFS_PIN_LENGTH, pinLength).apply();
}
}
4 changes: 4 additions & 0 deletions wallet/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@
android:screenOrientation="portrait"
android:theme="@style/My.Theme.ChildActivity" />

<activity android:name="de.schildbach.wallet.ui.AppUpgradeActivity"
android:screenOrientation="portrait"
android:theme="@style/LockScreenActivity.Theme" />

<provider
android:name="de.schildbach.wallet.data.AddressBookProvider"
android:authorities="${applicationId}.address_book"
Expand Down
14 changes: 14 additions & 0 deletions wallet/res/drawable/custom_pin_preview_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="@color/dash_white" />

<corners android:radius="10dp" />

<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />

</shape>
14 changes: 14 additions & 0 deletions wallet/res/drawable/custom_pin_preview_background_gray.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="@color/dash_light_gray" />

<corners android:radius="10dp" />

<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />

</shape>
15 changes: 15 additions & 0 deletions wallet/res/drawable/custom_pin_preview_item_dot.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid android:color="#000000" />

<size
android:width="24dp"
android:height="24dp" />

<stroke
android:width="10dp"
android:color="@android:color/transparent" />

</shape>
72 changes: 72 additions & 0 deletions wallet/res/layout/activity_app_update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tool="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tool:background="@drawable/splash_activity_background">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/logo_guideline"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.10" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/v_center_guideline"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.50" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/h_center_guideline"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.50" />

<ImageView
android:id="@+id/dash_logo"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/logo_guideline"
app:layout_constraintEnd_toEndOf="@id/v_center_guideline"
app:layout_constraintStart_toStartOf="@id/v_center_guideline"
app:layout_constraintTop_toTopOf="@id/logo_guideline"
app:layout_constraintWidth_percent="0.4"
app:srcCompat="@drawable/ic_dash_logo_white"
tool:ignore="ContentDescription" />

<LinearLayout
android:id="@+id/title_pane"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/lock_screen_content_margin_bottom"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@id/h_center_guideline"
app:layout_constraintTop_toTopOf="@id/h_center_guideline">

<TextView
android:id="@+id/action_title"
style="@style/MontserratMedium.PageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lock_unlock_with_fingerprint"
android:textColor="@color/dash_white" />

<TextView
android:id="@+id/action_subtitle"
style="@style/MontserratMedium.BodyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/wallet_lock_try_again"
android:textColor="@color/dash_white" />

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions wallet/res/layout/activity_lock_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
app:layout_constraintGuide_percent="0.80" />

<ImageView
android:id="@+id/dash_logo"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/logo_guideline"
Expand Down
4 changes: 3 additions & 1 deletion wallet/res/layout/fragment_enter_pin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:fitsSystemWindows="true"
android:background="@android:color/transparent"
android:orientation="vertical">

Expand All @@ -17,7 +18,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="32dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:background="@color/dash_white">

<LinearLayout
Expand Down
17 changes: 16 additions & 1 deletion wallet/res/layout/pin_preview_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
tools:parentTag="android.widget.LinearLayout">

<LinearLayout
android:id="@+id/items"
android:id="@+id/standard_pin_preview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
Expand Down Expand Up @@ -49,6 +49,21 @@

</LinearLayout>

<LinearLayout
android:id="@+id/custom_pin_preview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/custom_pin_preview_background_gray"
android:gravity="center"
android:minWidth="256dp"
android:minHeight="50dp"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:textColor="@color/dash_black"
android:visibility="gone"
tools:visibility="visible" />

<TextView
android:id="@+id/forgot_pin"
style="@style/MontserratSemiBold"
Expand Down
103 changes: 103 additions & 0 deletions wallet/src/de/schildbach/wallet/ui/AppUpgradeActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright 2020 Dash Core Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.schildbach.wallet.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import de.schildbach.wallet.WalletApplication
import de.schildbach.wallet.ui.preference.PinRetryController
import de.schildbach.wallet.ui.security.SecurityGuard
import de.schildbach.wallet.ui.widget.PinPreviewView
import de.schildbach.wallet_test.R
import kotlinx.android.synthetic.main.activity_app_update.*
import org.dash.wallet.common.Configuration
import java.util.concurrent.TimeUnit

class AppUpgradeActivity : AppCompatActivity() {

companion object {
@JvmStatic
fun createIntent(context: Context): Intent {
return Intent(context, AppUpgradeActivity::class.java)
}
}

lateinit var configuration: Configuration
private lateinit var pinRetryController: PinRetryController

private val temporaryLockCheckHandler = Handler()
private val temporaryLockCheckInterval = TimeUnit.SECONDS.toMillis(10)
private val temporaryLockCheckRunnable = Runnable {
if (pinRetryController.isLocked) {
walletLocked()
} else {
askForPin()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_app_update)

configuration = WalletApplication.getInstance().configuration
configuration.pinLength = PinPreviewView.CUSTOM_PIN_LENGTH

pinRetryController = PinRetryController.getInstance()

temporaryLockCheckRunnable.run()
}

private fun askForPin() {
title_pane.visibility = View.INVISIBLE
dash_logo.visibility = View.INVISIBLE
val checkPinSharedModel = ViewModelProviders.of(this)[CheckPinSharedModel::class.java]
checkPinSharedModel.onCorrectPinCallback.observe(this, Observer<Pair<Int?, String?>> { (_, pin) ->
onCorrectPin(pin!!)
})
checkPinSharedModel.onCancelCallback.observe(this, Observer<Void> {
temporaryLockCheckRunnable.run()
})
CheckPinDuringUpgradeDialog.show(this, 0)
}

private fun onCorrectPin(pin: String) {
val securityGuard = SecurityGuard()
securityGuard.savePin(pin)
securityGuard.savePassword(pin)
configuration.pinLength = pin.length
startActivity(WalletActivity.createIntent(this))
}

private fun walletLocked() {
title_pane.visibility = View.VISIBLE
dash_logo.visibility = View.VISIBLE
temporaryLockCheckHandler.postDelayed(temporaryLockCheckRunnable, temporaryLockCheckInterval)
action_title.setText(R.string.wallet_lock_wallet_disabled)
action_subtitle.text = pinRetryController.getWalletTemporaryLockedMessage(this)
}

override fun finish() {
super.finish()
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
}
}
Loading

0 comments on commit 89b0e1d

Please sign in to comment.