Better policy to show PIN Code
authorDavid A. Velasco <dvelasco@solidgear.es>
Mon, 9 Jul 2012 13:10:26 +0000 (15:10 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Mon, 9 Jul 2012 13:10:26 +0000 (15:10 +0200)
AndroidManifest.xml
res/layout/pincodelock.xml
res/values/strings.xml
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
src/eu/alefzero/owncloud/ui/activity/PinCodeActivity.java
src/eu/alefzero/owncloud/ui/activity/Preferences.java

index 1fb2075..6639300 100644 (file)
@@ -18,7 +18,7 @@
  -->\r
 <manifest package="eu.alefzero.owncloud"\r
     android:versionCode="1"\r
-    android:versionName="0.1.152B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+    android:versionName="0.1.153B" xmlns:android="http://schemas.android.com/apk/res/android">\r
 \r
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
index 9e0205a..d1555c9 100644 (file)
@@ -1,63 +1,63 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  ownCloud Android client application
-
-  This program is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
--->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:oc="http://schemas.android.com/apk/res/eu.alefzero.owncloud"
-    android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-    android:gravity="center_horizontal"
-    android:orientation="vertical"
-    android:padding="20dp" >
-
-
-    <TextView
-        android:id="@+id/pinHdr"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="Enter pin code"
-        android:textColor="@android:color/black"
-         />
-
-    <LinearLayout
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
-      >
-
-        <EditText
-            android:id="@+id/txt1"
-            android:focusable="true"
-            style="@style/PassCodeStyle" />
-
-        <EditText
-            android:id="@+id/txt2"
-            style="@style/PassCodeStyle" />
-
-        <EditText
-            android:id="@+id/txt3"
-            style="@style/PassCodeStyle" />
-
-        <EditText
-            android:id="@+id/txt4"
-            style="@style/PassCodeStyle" />
-    </LinearLayout>
-
-    <Button android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="Cancel"
-        android:textColor="@android:color/black"
-        android:id="@+id/cancel"/>
+<?xml version="1.0" encoding="utf-8"?>\r
+<!--\r
+  ownCloud Android client application\r
+\r
+  This program is free software: you can redistribute it and/or modify\r
+  it under the terms of the GNU General Public License as published by\r
+  the Free Software Foundation, either version 3 of the License, or\r
+  (at your option) any later version.\r
+\r
+  This program is distributed in the hope that it will be useful,\r
+  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+  GNU General Public License for more details.\r
+\r
+  You should have received a copy of the GNU General Public License\r
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+-->\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+    xmlns:oc="http://schemas.android.com/apk/res/eu.alefzero.owncloud"\r
+    android:layout_width="fill_parent"\r
+    android:layout_height="fill_parent"\r
+    android:gravity="center_horizontal"\r
+    android:orientation="vertical"\r
+    android:padding="20dp" >\r
+\r
+\r
+    <TextView\r
+        android:id="@+id/pinHdr"\r
+        android:layout_width="wrap_content"\r
+        android:layout_height="wrap_content"\r
+        android:text="@string/pincode_enter_pin_code"\r
+        android:textColor="@android:color/black"\r
+         />\r
+\r\r
+    <LinearLayout\r
+        android:layout_width="fill_parent"\r
+        android:layout_height="wrap_content"\r
+        android:gravity="center_horizontal" >\r
+\r
+        <EditText\r
+            android:id="@+id/txt1"\r
+            android:focusable="true"\r
+            style="@style/PassCodeStyle" />\r
+\r
+        <EditText\r
+            android:id="@+id/txt2"\r
+            style="@style/PassCodeStyle" />\r
+\r
+        <EditText\r
+            android:id="@+id/txt3"\r
+            style="@style/PassCodeStyle" />\r
+\r
+        <EditText\r
+            android:id="@+id/txt4"\r
+            style="@style/PassCodeStyle" />\r
+    </LinearLayout>\r
+\r
+    <Button android:layout_width="wrap_content"\r
+        android:layout_height="wrap_content"\r
+        android:text="@android:string/cancel"\r
+        android:textColor="@android:color/black"\r
+        android:id="@+id/cancel"/>\r
 </LinearLayout>
\ No newline at end of file
index e28d058..08cbbc8 100644 (file)
@@ -75,6 +75,8 @@
     <string name="use_ssl">Use Secure Connection</string>
     <string name="location_no_provider">ownCloud cannot track your device. Please check your location settings</string>
     
+    <string name="pincode_enter_pin_code">Enter pin code</string>
+    
     <string-array name="prefs_trackmydevice_intervall_keys">
        <item>15 Minutes</item>
        <item>30 Minutes</item>
index 3412af8..a5b1fc8 100644 (file)
@@ -131,18 +131,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
             \r
             initDelayedTilAccountAvailabe();\r
             \r
-            // PIN CODE request\r
-            // best location is to decide; let's try this first\r
-            boolean pinStart = false;\r
-            SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());\r
-            pinStart = appPrefs.getBoolean("set_passcode", false);\r
-            \r
-            if (pinStart) {\r
-                Intent i = new Intent(getApplicationContext(), PinCodeActivity.class);\r
-                i.putExtra("activity", "splash");\r
-                startActivity(i);\r
+            // PIN CODE request ;  best location is to decide, let's try this first\r
+            //if (savedInstanceState == null) {\r
+            if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) {\r
+                requestPinCode();\r
             }\r
             \r
+            \r
         } else {\r
             \r
             setContentView(R.layout.no_account_available);\r
@@ -769,6 +764,21 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
         }\r
 \r
     }\r
+    \r
+\r
+    /**\r
+     * Launch an intent to request the PIN code to the user before letting him use the app\r
+     */\r
+    private void requestPinCode() {\r
+        boolean pinStart = false;\r
+        SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());\r
+        pinStart = appPrefs.getBoolean("set_pincode", false);\r
+        if (pinStart) {\r
+            Intent i = new Intent(getApplicationContext(), PinCodeActivity.class);\r
+            i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "FileDisplayActivity");\r
+            startActivity(i);\r
+        }\r
+    }\r
 \r
     \r
 }\r
index c620952..84fe259 100644 (file)
@@ -42,6 +42,8 @@ import android.widget.TextView;
 public class PinCodeActivity extends SherlockFragmentActivity {
 
   
+    public final static String EXTRA_ACTIVITY = "eu.alefzero.owncloud.ui.activity.PinCodeActivity.ACTIVITY";
+    public final static String EXTRA_NEW_STATE = "eu.alefzero.owncloud.ui.activity.PinCodeActivity.NEW_STATE";
     
     Button bCancel;
     TextView mPinHdr;
@@ -66,7 +68,7 @@ public class PinCodeActivity extends SherlockFragmentActivity {
         setContentView(R.layout.pincodelock); 
         
         Intent intent = getIntent();
-        activity = intent.getStringExtra("activity");
+        activity = intent.getStringExtra(EXTRA_ACTIVITY);
      
         bCancel = (Button) findViewById(R.id.cancel);
         mPinHdr = (TextView) findViewById(R.id.pinHdr);
@@ -111,7 +113,6 @@ public class PinCodeActivity extends SherlockFragmentActivity {
 
             @Override
             public void onClick(View v) {
-                // TODO Auto-generated method stub
                 finish();
             }
         });
@@ -296,7 +297,7 @@ public class PinCodeActivity extends SherlockFragmentActivity {
             @Override
             public void onTextChanged(CharSequence s, int start, int before,
                     int count) {
-                // TODO Auto-generated method stub
+                
                 if (s.length() > 0) {
                    
                    if (!confirmingPinCode){
@@ -308,33 +309,31 @@ public class PinCodeActivity extends SherlockFragmentActivity {
                        pinCodeChecked = checkPincode();
                    }
                    
-                   if (pinCodeChecked && activity.equals("splash")){
+                   if (pinCodeChecked && activity.equals("FileDisplayActivity")){
                        finish();
                    } else if (pinCodeChecked){
                        
                        Intent intent = getIntent();
-                       String newState = intent.getStringExtra("pinNewState");
+                       String newState = intent.getStringExtra(EXTRA_NEW_STATE);
                        
                        if (newState.equals("false")){
                            SharedPreferences.Editor appPrefs = PreferenceManager
                                    .getDefaultSharedPreferences(getApplicationContext()).edit();
                            appPrefs.putBoolean("set_pincode",false);
                            appPrefs.commit();
-                           
                            // TODO Alert Message que salte y vuelva a la pantalla anterior
                            
                            finish();
                            
-                           
                        }else{
                        
                            if (!confirmingPinCode && !newPasswordEntered){
                                pinCodeChangeRequest();
-                           }else if (newPasswordEntered && !confirmingPinCode){
+                           } else if (newPasswordEntered && !confirmingPinCode){
                                mPinHdr.setText("Confirm your PINCode, please");
                                confirmingPinCode = true;
                                clearBoxes();
-                           }else {
+                           } else {
                                confirmPincode();
                            }
                        }
index 603466b..ffc1397 100644 (file)
@@ -45,6 +45,7 @@ import eu.alefzero.owncloud.OwnCloudSession;
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
 import eu.alefzero.owncloud.db.DbHandler;\r
+import eu.alefzero.owncloud.syncadapter.FileSyncAdapter;\r
 \r
 /**\r
  * An Activity that allows the user to change the application's settings.\r
@@ -94,8 +95,8 @@ public class Preferences extends SherlockPreferenceActivity implements
                     \r
                                         \r
                     Intent i = new Intent(getApplicationContext(), PinCodeActivity.class);\r
-                    i.putExtra("activity", "preferences");\r
-                    i.putExtra("pinNewState",newValue.toString());\r
+                    i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, "preferences");\r
+                    i.putExtra(PinCodeActivity.EXTRA_NEW_STATE, newValue.toString());\r
                     startActivity(i);\r
                     \r
                     return true;\r