X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/a70c4c658fa261a1944c7ca12ee3cea3e58e7ad5..c6b553f635c7cbb4f21d41a6fa82e204447c16cf:/src/eu/alefzero/owncloud/ui/activity/PinCodeActivity.java diff --git a/src/eu/alefzero/owncloud/ui/activity/PinCodeActivity.java b/src/eu/alefzero/owncloud/ui/activity/PinCodeActivity.java index bd81913a..6c65bbb5 100644 --- a/src/eu/alefzero/owncloud/ui/activity/PinCodeActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/PinCodeActivity.java @@ -17,11 +17,12 @@ */ package eu.alefzero.owncloud.ui.activity; +import java.util.Arrays; + import com.actionbarsherlock.app.SherlockFragmentActivity; import eu.alefzero.owncloud.R; -import android.app.ActionBar.LayoutParams; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; @@ -61,7 +62,7 @@ public class PinCodeActivity extends SherlockFragmentActivity { boolean pinCodeChecked = false; boolean newPasswordEntered = false; boolean bChange = true; // to control that only one blocks jump - int tCounter ; // Count the number of attempts an user could introduce de PIN code + int tCounter ; // Count the number of attempts an user could introduce the PIN code protected void onCreate(Bundle savedInstanceState) { @@ -75,7 +76,7 @@ public class PinCodeActivity extends SherlockFragmentActivity { mPinHdr = (TextView) findViewById(R.id.pinHdr); mText1 = (EditText) findViewById(R.id.txt1); mText1.requestFocus(); - getWindow().setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + getWindow().setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); mText2 = (EditText) findViewById(R.id.txt2); mText3 = (EditText) findViewById(R.id.txt3); mText4 = (EditText) findViewById(R.id.txt4); @@ -84,22 +85,50 @@ public class PinCodeActivity extends SherlockFragmentActivity { SharedPreferences appPrefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); - // Not PIN Code defined yet - if ( appPrefs.getString("PrefPinCode1", null) == null ){ - setChangePincodeView(); + + // Not PIN Code defined yet. + // In a previous version settings is allow from start + if ( (appPrefs.getString("PrefPinCode1", null) == null ) ){ + setInitView(); pinCodeChecked = true; newPasswordEntered = true; - } else { - setInitView(); - } + }else{ + + if (appPrefs.getBoolean("set_pincode", false)){ + // pincode activated + if (activity.equals("preferences")){ + // PIN has been activated yet + mPinHdr.setText(R.string.pincode_configure_your_pin); + pinCodeChecked = true ; // No need to check it + setChangePincodeView(true); + }else{ + // PIN active + bCancel.setVisibility(View.INVISIBLE); + bCancel.setVisibility(View.GONE); + mPinHdr.setText(R.string.pincode_enter_pin_code); + setChangePincodeView(false); + } + + }else { + // pincode removal + mPinHdr.setText(R.string.pincode_enter_pin_code); + pinCodeChecked = false; + setChangePincodeView(true); + } - + } setTextListeners(); } - + + protected void setInitVars(){ + confirmingPinCode = false; + pinCodeChecked = false; + newPasswordEntered = false; + + } protected void setInitView(){ bCancel.setVisibility(View.INVISIBLE); @@ -107,20 +136,34 @@ public class PinCodeActivity extends SherlockFragmentActivity { mPinHdr.setText(R.string.pincode_enter_pin_code); } - - - protected void setChangePincodeView(){ - mPinHdr.setText(R.string.pincode_configure_your_pin); + + protected void setChangePincodeView(boolean state){ + + if(state){ + bCancel.setVisibility(View.VISIBLE); bCancel.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - finish(); + @Override + public void onClick(View v) { + + SharedPreferences.Editor appPrefsE = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()).edit(); + + SharedPreferences appPrefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()); + + boolean state = appPrefs.getBoolean("set_pincode", false); + appPrefsE.putBoolean("set_pincode",!state); + appPrefsE.commit(); + setInitVars(); + finish(); } }); + } } + + /* * */ @@ -141,7 +184,9 @@ public class PinCodeActivity extends SherlockFragmentActivity { tempText[0] = mText1.getText().toString(); } + mText2.requestFocus(); + } } @@ -174,7 +219,9 @@ public class PinCodeActivity extends SherlockFragmentActivity { if (!confirmingPinCode){ tempText[1] = mText2.getText().toString(); } + mText3.requestFocus(); + } } @@ -202,7 +249,8 @@ public class PinCodeActivity extends SherlockFragmentActivity { mText1.setText(""); mText1.requestFocus(); - tempText[0] = ""; + if (!confirmingPinCode) + tempText[0] = ""; bChange= false; }else if(!bChange){ @@ -220,6 +268,8 @@ public class PinCodeActivity extends SherlockFragmentActivity { // TODO Auto-generated method stub if (mText1.getText().toString().equals("")){ mText1.requestFocus(); + }else { + mText1.append(""); } } @@ -240,6 +290,7 @@ public class PinCodeActivity extends SherlockFragmentActivity { tempText[2] = mText3.getText().toString(); } mText4.requestFocus(); + } } @@ -265,7 +316,8 @@ public class PinCodeActivity extends SherlockFragmentActivity { if (keyCode == KeyEvent.KEYCODE_DEL && bChange) { mText2.requestFocus(); - tempText[1] = ""; + if (!confirmingPinCode) + tempText[1] = ""; mText2.setText(""); bChange= false; @@ -323,18 +375,15 @@ public class PinCodeActivity extends SherlockFragmentActivity { .getDefaultSharedPreferences(getApplicationContext()).edit(); appPrefs.putBoolean("set_pincode",false); appPrefs.commit(); - // TODO Alert Message que salte y vuelva a la pantalla anterior - finish(); + setInitVars(); + pinCodeEnd(false); }else{ - if (!confirmingPinCode && !newPasswordEntered){ + if (!confirmingPinCode){ pinCodeChangeRequest(); - } else if (newPasswordEntered && !confirmingPinCode){ - mPinHdr.setText(R.string.pincode_confirm_your_pincode); - confirmingPinCode = true; - clearBoxes(); + } else { confirmPincode(); } @@ -370,7 +419,8 @@ public class PinCodeActivity extends SherlockFragmentActivity { if (keyCode == KeyEvent.KEYCODE_DEL && bChange) { mText3.requestFocus(); - tempText[2]=""; + if (!confirmingPinCode) + tempText[2]=""; mText3.setText(""); bChange= false; @@ -404,37 +454,9 @@ public class PinCodeActivity extends SherlockFragmentActivity { protected void pinCodeChangeRequest(){ - AlertDialog.Builder aBuilder = new AlertDialog.Builder(this); - aBuilder.setMessage("Do yo want to set a new PIN Code") - .setCancelable(false) - .setPositiveButton("Yes", new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - // TODO Auto-generated method stub - setChangePincodeView(); - mPinHdr.setText(R.string.pincode_enter_new_pin_code); - clearBoxes(); - newPasswordEntered = true; - } - }) - .setNegativeButton("No", new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - // TODO Auto-generated method stub - SharedPreferences.Editor appPrefs = PreferenceManager - .getDefaultSharedPreferences(getApplicationContext()).edit(); - appPrefs.putBoolean("set_pincode",false); - appPrefs.commit(); - finish(); - } - }); - - AlertDialog alert =aBuilder.create(); - - alert.show(); - + clearBoxes(); + mPinHdr.setText(R.string.pincode_reenter_your_pincode); + confirmingPinCode =true; } @@ -459,9 +481,11 @@ public class PinCodeActivity extends SherlockFragmentActivity { }else { + Arrays.fill(tempText, null); AlertDialog aDialog = new AlertDialog.Builder(this).create(); aDialog.setTitle("ERROR"); - aDialog.setMessage("Wrong PIN"); + CharSequence cseq = getString(R.string.pincode_wrong); + aDialog.setMessage(cseq); aDialog.setButton("OK", new DialogInterface.OnClickListener(){ @Override @@ -473,7 +497,7 @@ public class PinCodeActivity extends SherlockFragmentActivity { }); aDialog.show(); clearBoxes(); - mPinHdr.setText(R.string.pincode_configure_your_pin); + mPinHdr.setText(R.string.pincode_enter_pin_code); newPasswordEntered = true; confirmingPinCode = false; @@ -501,9 +525,11 @@ public class PinCodeActivity extends SherlockFragmentActivity { } else { + Arrays.fill(tempText, null); AlertDialog aDialog = new AlertDialog.Builder(this).create(); aDialog.setTitle("ERROR"); - aDialog.setMessage("PIN Code Mismatch"); + CharSequence cseq = getString(R.string.pincode_mismatch); + aDialog.setMessage(cseq); aDialog.setButton("OK", new DialogInterface.OnClickListener(){ @Override @@ -520,6 +546,31 @@ public class PinCodeActivity extends SherlockFragmentActivity { } + + protected void pinCodeEnd(boolean state){ + AlertDialog aDialog = new AlertDialog.Builder(this).create(); + + if (state){ + aDialog.setTitle("SAVE & EXIT"); + aDialog.setMessage("PIN Code Activated"); + }else{ + aDialog.setTitle("SAVE & EXIT"); + aDialog.setMessage("PIN Code Removed"); + } + + aDialog.setButton("OK", new DialogInterface.OnClickListener(){ + + @Override + public void onClick(DialogInterface dialog, int which) { + // TODO Auto-generated method stub(""); + finish(); + return; + } + + }); + aDialog.show(); + } + protected void savePincodeAndExit(){ SharedPreferences.Editor appPrefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()).edit(); @@ -531,7 +582,10 @@ public class PinCodeActivity extends SherlockFragmentActivity { appPrefs.putBoolean("set_pincode",true); appPrefs.commit(); - finish(); + pinCodeEnd(true); + + + } @@ -543,6 +597,33 @@ public class PinCodeActivity extends SherlockFragmentActivity { mText4.setText(""); mText1.requestFocus(); } + + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event){ + if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount()== 0){ + + if (activity.equals("preferences")){ + SharedPreferences.Editor appPrefsE = PreferenceManager + + .getDefaultSharedPreferences(getApplicationContext()).edit(); + + SharedPreferences appPrefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()); + + boolean state = appPrefs.getBoolean("set_pincode", false); + appPrefsE.putBoolean("set_pincode",!state); + appPrefsE.commit(); + setInitVars(); + finish(); + } + return true; + + } + + return super.onKeyDown(keyCode, event); + } + }