From 7a957840748766345f0180b2a3f8dee761161be4 Mon Sep 17 00:00:00 2001 From: Bhargav Golla Date: Tue, 4 Mar 2014 22:37:56 -0500 Subject: [PATCH 1/3] Adding a min date not to go below creation date --- .../org/sufficientlysecure/keychain/ui/widget/KeyEditor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 6c265057e..b8bb547ee 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -106,7 +106,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mDeleteButton.setOnClickListener(this); setExpiryDate(null); - + String creationDate = mCreationDate.getText().toString(); + Date date = DateFormat.getDateInstance().parse(creationDate); mExpiryDateButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { GregorianCalendar date = mExpiryDate; @@ -129,6 +130,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } } }); + dialog.getDatePicker().setMinDate(date.getTime()); dialog.show(); } }); From 92ba91de1483e64d173b135c73012851bd372cbe Mon Sep 17 00:00:00 2001 From: Bhargav Golla Date: Wed, 5 Mar 2014 12:48:24 -0500 Subject: [PATCH 2/3] Set min date to one day after Created Date. Works on Honeycomb and above --- .../keychain/ui/widget/KeyEditor.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index b8bb547ee..7344248f7 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -34,6 +34,7 @@ import android.app.DatePickerDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.text.format.DateUtils; import android.util.AttributeSet; import android.view.View; import android.view.View.OnClickListener; @@ -58,6 +59,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { Spinner mUsage; TextView mCreationDate; BootstrapButton mExpiryDateButton; + GregorianCalendar mCreatedDate; GregorianCalendar mExpiryDate; private int mDatePickerResultCount = 0; @@ -106,8 +108,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mDeleteButton.setOnClickListener(this); setExpiryDate(null); - String creationDate = mCreationDate.getText().toString(); - Date date = DateFormat.getDateInstance().parse(creationDate); + mExpiryDateButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { GregorianCalendar date = mExpiryDate; @@ -130,7 +131,18 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { } } }); - dialog.getDatePicker().setMinDate(date.getTime()); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { + if ( dialog != null && mCreatedDate != null ) { + dialog.getDatePicker().setMinDate(mCreatedDate.getTime().getTime()+ DateUtils.DAY_IN_MILLIS); + android.util.Log.w("Date picker", "Date min set"); + } else { + //When created date isn't available + dialog.getDatePicker().setMinDate(date.getTime().getTime()+ DateUtils.DAY_IN_MILLIS); + android.util.Log.w("Date picker", "Date min set using current time"); + } + } else { + android.util.Log.w("Date picker", "API Level < 11 so not restricting date range..."); + } dialog.show(); } }); @@ -207,7 +219,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.setTime(PgpKeyHelper.getCreationDate(key)); - mCreationDate.setText(DateFormat.getDateInstance().format(cal.getTime())); + setCreatedDate(cal); cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); Date expiryDate = PgpKeyHelper.getExpiryDate(key); if (expiryDate == null) { @@ -237,6 +249,15 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mEditorListener = listener; } + private void setCreatedDate(GregorianCalendar date) { + mCreatedDate = date; + if (date == null) { + mCreationDate.setText(getContext().getString(R.string.none)); + } else { + mCreationDate.setText(DateFormat.getDateInstance().format(date.getTime())); + } + } + private void setExpiryDate(GregorianCalendar date) { mExpiryDate = date; if (date == null) { From 42fc15e66e3efbb98fa0587569dc8b1f426c0b8a Mon Sep 17 00:00:00 2001 From: Bhargav Golla Date: Wed, 5 Mar 2014 14:46:38 -0500 Subject: [PATCH 3/3] Removed log statements as per Dominik's suggestions --- .../org/sufficientlysecure/keychain/ui/widget/KeyEditor.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 7344248f7..b9d8eb81c 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -134,14 +134,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { if ( dialog != null && mCreatedDate != null ) { dialog.getDatePicker().setMinDate(mCreatedDate.getTime().getTime()+ DateUtils.DAY_IN_MILLIS); - android.util.Log.w("Date picker", "Date min set"); } else { //When created date isn't available dialog.getDatePicker().setMinDate(date.getTime().getTime()+ DateUtils.DAY_IN_MILLIS); - android.util.Log.w("Date picker", "Date min set using current time"); } - } else { - android.util.Log.w("Date picker", "API Level < 11 so not restricting date range..."); } dialog.show(); }