X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/f692bf7ae67b050345c14ec5e914cb3b1c0a950b..91b1728493397437b37a03740260f43fdd82f173:/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..d9ae73c5 100644 --- a/src/eu/alefzero/owncloud/ui/activity/PinCodeActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/PinCodeActivity.java @@ -21,7 +21,6 @@ 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 +60,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 +74,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 +83,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 +134,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(); } }); + } } + + /* * */ @@ -323,16 +364,16 @@ 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){ pinCodeChangeRequest(); } else if (newPasswordEntered && !confirmingPinCode){ - mPinHdr.setText(R.string.pincode_confirm_your_pincode); + mPinHdr.setText(R.string.pincode_reenter_your_pincode); confirmingPinCode = true; clearBoxes(); } else { @@ -404,37 +445,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; } @@ -461,7 +474,8 @@ public class PinCodeActivity extends SherlockFragmentActivity { }else { 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 +487,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; @@ -503,7 +517,8 @@ public class PinCodeActivity extends SherlockFragmentActivity { 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 +535,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 +571,10 @@ public class PinCodeActivity extends SherlockFragmentActivity { appPrefs.putBoolean("set_pincode",true); appPrefs.commit(); - finish(); + pinCodeEnd(true); + + + } @@ -543,6 +586,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); + } + }