List of usage examples for android.content Context getFileStreamPath
public abstract File getFileStreamPath(String name);
From source file:com.android.leanlauncher.LauncherTransitionable.java
private static void writeConfiguration(Context context, LocaleConfiguration configuration) { DataOutputStream out = null;// ww w.ja v a 2s . c om try { out = new DataOutputStream(context.openFileOutput(LauncherFiles.LAUNCHER_PREFERENCES, MODE_PRIVATE)); out.writeUTF(configuration.locale); out.writeInt(configuration.mcc); out.writeInt(configuration.mnc); out.flush(); } catch (FileNotFoundException e) { // Ignore } catch (IOException e) { //noinspection ResultOfMethodCallIgnored context.getFileStreamPath(LauncherFiles.LAUNCHER_PREFERENCES).delete(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { // Ignore } } } }
From source file:com.android.launcher2.Launcher.java
private static void writeConfiguration(Context context, LocaleConfiguration configuration) { DataOutputStream out = null;//w w w . jav a 2 s .c o m try { out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); out.writeUTF(configuration.locale); out.writeInt(configuration.mcc); out.writeInt(configuration.mnc); out.flush(); } catch (FileNotFoundException e) { // Ignore } catch (IOException e) { //noinspection ResultOfMethodCallIgnored context.getFileStreamPath(PREFERENCES).delete(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { // Ignore } } } }
From source file:com.cognizant.trumobi.PersonaLauncher.java
private static void writeConfiguration(Context context, LocaleConfiguration configuration) { DataOutputStream out = null;/* w ww .ja v a 2 s. c om*/ try { out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); out.writeUTF(configuration.locale); out.writeInt(configuration.mcc); out.writeInt(configuration.mnc); out.flush(); } catch (FileNotFoundException e) { // Ignore } catch (IOException e) { // noinspection ResultOfMethodCallIgnored context.getFileStreamPath(PREFERENCES).delete(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { // Ignore } } } }
From source file:RhodesService.java
private File downloadPackage(String url) throws IOException { final Context ctx = RhodesActivity.getContext(); final Thread thisThread = Thread.currentThread(); final Runnable cancelAction = new Runnable() { public void run() { thisThread.interrupt();//from w ww.j a v a2s . c om } }; BroadcastReceiver downloadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(ACTION_ASK_CANCEL_DOWNLOAD)) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setMessage("Cancel download?"); AlertDialog dialog = builder.create(); dialog.setButton(AlertDialog.BUTTON_POSITIVE, ctx.getText(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { cancelAction.run(); } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, ctx.getText(android.R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Nothing } }); dialog.show(); } else if (action.equals(ACTION_CANCEL_DOWNLOAD)) { cancelAction.run(); } } }; IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_ASK_CANCEL_DOWNLOAD); filter.addAction(ACTION_CANCEL_DOWNLOAD); ctx.registerReceiver(downloadReceiver, filter); File tmpFile = null; InputStream is = null; OutputStream os = null; try { updateDownloadNotification(url, -1, 0); /* List<File> folders = new ArrayList<File>(); folders.add(Environment.getDownloadCacheDirectory()); folders.add(Environment.getDataDirectory()); folders.add(ctx.getCacheDir()); folders.add(ctx.getFilesDir()); try { folders.add(new File(ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), 0).dataDir)); } catch (NameNotFoundException e1) { // Ignore } folders.add(Environment.getExternalStorageDirectory()); for (File folder : folders) { File tmpRootFolder = new File(folder, "rhodownload"); File tmpFolder = new File(tmpRootFolder, ctx.getPackageName()); if (tmpFolder.exists()) deleteFilesInFolder(tmpFolder.getAbsolutePath()); else tmpFolder.mkdirs(); File of = new File(tmpFolder, UUID.randomUUID().toString() + ".apk"); Logger.D(TAG, "Check path " + of.getAbsolutePath() + "..."); try { os = new FileOutputStream(of); } catch (FileNotFoundException e) { Logger.D(TAG, "Can't open file " + of.getAbsolutePath() + ", check next path"); continue; } Logger.D(TAG, "File " + of.getAbsolutePath() + " succesfully opened for write, start download app"); tmpFile = of; break; } */ tmpFile = ctx.getFileStreamPath(UUID.randomUUID().toString() + ".apk"); os = ctx.openFileOutput(tmpFile.getName(), Context.MODE_WORLD_READABLE); Logger.D(TAG, "Download " + url + " to " + tmpFile.getAbsolutePath() + "..."); URL u = new URL(url); URLConnection conn = u.openConnection(); int totalBytes = -1; if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) conn; totalBytes = httpConn.getContentLength(); } is = conn.getInputStream(); int downloaded = 0; updateDownloadNotification(url, totalBytes, downloaded); long prevProgress = 0; byte[] buf = new byte[65536]; for (;;) { if (thisThread.isInterrupted()) { tmpFile.delete(); Logger.D(TAG, "Download of " + url + " was canceled"); return null; } int nread = is.read(buf); if (nread == -1) break; //Logger.D(TAG, "Downloading " + url + ": got " + nread + " bytes..."); os.write(buf, 0, nread); downloaded += nread; if (totalBytes > 0) { // Update progress view only if current progress is greater than // previous by more than 10%. Otherwise, if update it very frequently, // user will no have chance to click on notification view and cancel if need long progress = downloaded * 10 / totalBytes; if (progress > prevProgress) { updateDownloadNotification(url, totalBytes, downloaded); prevProgress = progress; } } } Logger.D(TAG, "File stored to " + tmpFile.getAbsolutePath()); return tmpFile; } catch (IOException e) { if (tmpFile != null) tmpFile.delete(); throw e; } finally { try { if (is != null) is.close(); } catch (IOException e) { } try { if (os != null) os.close(); } catch (IOException e) { } mNM.cancel(DOWNLOAD_PACKAGE_ID); ctx.unregisterReceiver(downloadReceiver); } }
From source file:cn.ttyhuo.view.UserView.java
public void setupViews(JSONObject jsonObject, final Context context) throws JSONException { JSONObject jObject;/*from w ww. j ava2 s . c o m*/ if (jsonObject.has("user")) jObject = jsonObject.getJSONObject("user"); else jObject = jsonObject.getJSONObject("userWithLatLng"); String userStatus = JSONUtil.getStringFromJson(jObject, "status", ""); if (!userStatus.equals("")) { if (tv_userStatus != null) tv_userStatus.setText("(" + userStatus + ")"); } else { if (tv_userStatus != null) tv_userStatus.setText(""); } if (tv_userTypeStr != null) tv_userTypeStr.setText(JSONUtil.getStringFromJson(jsonObject, "userTypeStr", "")); String userName = JSONUtil.getStringFromJson(jObject, "userName", "??"); String imgUrl = JSONUtil.getStringFromJson(jObject, "imgUrl", ""); int verifyFlag = 0; if (JSONUtil.getBoolFromJson(jObject, "sfzVerify")) { verifyFlag = 1; iv_userVerify.setVisibility(View.VISIBLE); imgUrl = JSONUtil.getStringFromJson(jObject, "faceImgUrl", imgUrl); userName = JSONUtil.getStringFromJson(jObject, "identityName", userName); } else { iv_userVerify.setVisibility(View.GONE); } tv_userName.setText(userName); int gender = JSONUtil.getIntFromJson(jsonObject, "gender", 0); if (gender == 2) { iv_gender.setImageResource(R.drawable.icon_nv_big); ll_gender.setBackgroundResource(R.drawable.bg_nv); } else if (gender == 1) { iv_gender.setImageResource(R.drawable.icon_nan_big); ll_gender.setBackgroundResource(R.drawable.bg_nan); } else { //TODO:?? } Integer age = JSONUtil.getIntFromJson(jsonObject, "age", 0); tv_userAge.setText(age.toString()); double lat = JSONUtil.getDoubleFromJson(jObject, "lat", 0.0); double lng = JSONUtil.getDoubleFromJson(jObject, "lng", 0.0); String distance = ((MyApplication) ((Activity) context).getApplication()).getDistance(lat, lng); //TODO: tv_lastPlace.setText(distance + "km"); JSONUtil.setValueFromJson(tv_lastTime, jObject, "latlngDate", ""); if (tv_mobileNo != null) { String mobileNo = JSONUtil.getStringFromJson(jObject, "mobileNo", ""); if (mobileNo.length() > 7) { mobileNo = mobileNo.substring(0, 3) + "****" + mobileNo.substring(7); } tv_mobileNo.setText(mobileNo); } int thumbUpCount = jObject.getInt("thumbUpCount"); int favoriteUserCount = jObject.getInt("favoriteUserCount"); boolean alreadyFavorite = jObject.getBoolean("alreadyFavorite"); final int userID = jObject.getInt("userID"); setFavoriteAndThumbUp(userID, thumbUpCount, favoriteUserCount, alreadyFavorite, context, jObject); if (JSONUtil.getBoolFromJson(jsonObject, "hasProduct")) { iv_hasProduct.setVisibility(View.GONE); tv_hasProduct.setVisibility(View.VISIBLE); View.OnClickListener theClick = new View.OnClickListener() { // ? ? @Override public void onClick(View v) { switch (v.getId()) { case R.id.iv_hasProduct: case R.id.tv_hasProduct: Intent intent = new Intent(context, MainPage.class); intent.putExtra("contentFragment", "UserProductFragment"); intent.putExtra("windowTitle", "?"); intent.putExtra("hasWindowTitle", true); intent.putExtra("extraID", userID); context.startActivity(intent); break; default: break; } } }; iv_hasProduct.setOnClickListener(theClick); tv_hasProduct.setOnClickListener(theClick); } else { iv_hasProduct.setVisibility(View.GONE); tv_hasProduct.setVisibility(View.GONE); } verifyFlag = setupTruckInfo(context, jObject, jsonObject, verifyFlag); if (fl_title != null) { JSONUtil.setFieldValueFromJson(fl_title, jsonObject, "title", ""); JSONUtil.setFieldValueFromJson(fl_description, jsonObject, "description", ""); JSONUtil.setFieldValueFromJson(fl_hobby, jsonObject, "hobby", ""); JSONUtil.setFieldValueFromJson(fl_homeTown, jsonObject, "homeTown", ""); JSONUtil.setFieldValueFromJson(fl_createDate, jObject, "createDate", ""); } verifyFlag = setupCompanyInfo(jsonObject, jObject, verifyFlag); setupUserVerifyImg(jObject, verifyFlag); setupFaceImg(context, imgUrl); if (iv_qrcode != null) { Map<String, String> params = new HashMap<String, String>(); StringBuilder buf = new StringBuilder("http://qr.liantu.com/api.php"); params.put("text", "http://ttyh.aliapp.com/mvc/viewUser_" + userID); params.put("bg", "ffffff"); params.put("fg", "cc0000"); params.put("fg", "gc0000"); params.put("el", "h"); params.put("w", "300"); params.put("m", "10"); params.put("pt", "00ff00"); params.put("inpt", "000000"); params.put("logo", "http://ttyh-document.oss-cn-qingdao.aliyuncs.com/ic_launcher.jpg"); try { // GET?URL if (params != null && !params.isEmpty()) { buf.append("?"); for (Map.Entry<String, String> entry : params.entrySet()) { buf.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")) .append("&"); } buf.deleteCharAt(buf.length() - 1); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } final String qrcodeUrl = buf.toString(); ImageLoader.getInstance().displayImage(qrcodeUrl, iv_qrcode, new DisplayImageOptions.Builder() .resetViewBeforeLoading(true).cacheInMemory(true).cacheOnDisc(true).build()); iv_qrcode.setOnClickListener(new View.OnClickListener() { // ? ? @Override public void onClick(View v) { try { FileOutputStream fos = context.openFileOutput("qrcode.png", Context.MODE_WORLD_READABLE); FileInputStream fis = new FileInputStream( ImageLoader.getInstance().getDiscCache().get(qrcodeUrl)); byte[] buf = new byte[1024]; int len = 0; while ((len = fis.read(buf)) != -1) { fos.write(buf, 0, len); } fis.close(); fos.close(); shareMsg(context, "?", "?", "??: ", context.getFileStreamPath("qrcode.png")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } }); } final String mobile = JSONUtil.getStringFromJson(jObject, "mobileNo", ""); if (!mobile.isEmpty()) { if (tv_footer_call_btn != null) { tv_footer_call_btn.setOnClickListener(new View.OnClickListener() { // ? ? @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction("android.intent.action.CALL"); intent.setData(Uri.parse("tel:" + mobile));//mobile?????? context.startActivity(intent); } }); } if (iv_phoneIcon != null) { iv_phoneIcon.setOnClickListener(new View.OnClickListener() { // ? ? @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction("android.intent.action.CALL"); intent.setData(Uri.parse("tel:" + mobile));//mobile?????? context.startActivity(intent); } }); } } else { if (tv_footer_call_btn != null) tv_footer_call_btn.setOnClickListener(null); if (iv_phoneIcon != null) iv_phoneIcon.setOnClickListener(null); } }
From source file:processing.core.PApplet.java
/** * Prepend the sketch folder path to the filename (or path) that is passed * in. External libraries should use this function to save to the sketch * folder./*from w w w .j a v a 2s . co m*/ * <p/> * Note that when running as an applet inside a web browser, the sketchPath * will be set to null, because security restrictions prevent applets from * accessing that information. * <p/> * This will also cause an error if the sketch is not inited properly, * meaning that init() was never called on the PApplet when hosted my some * other main() or by other code. For proper use of init(), see the examples * in the main description text for PApplet. */ public String sketchPath(String where) { if (sketchPath == null) { return where; // throw new RuntimeException("The applet was not inited properly, " // + // "or security restrictions prevented " + // "it from determining its path."); } // isAbsolute() could throw an access exception, but so will writing // to the local disk using the sketch path, so this is safe here. // for 0120, added a try/catch anyways. try { if (new File(where).isAbsolute()) return where; } catch (Exception e) { } Context context = this.getActivity().getApplicationContext(); return context.getFileStreamPath(where).getAbsolutePath(); }
From source file:com.processing.core.PApplet.java
/** * Prepend the sketch folder path to the filename (or path) that is * passed in. External libraries should use this function to save to * the sketch folder.//from w w w. j av a 2 s . c o m * <p/> * Note that when running as an applet inside a web browser, * the sketchPath will be set to null, because security restrictions * prevent applets from accessing that information. * <p/> * This will also cause an error if the sketch is not inited properly, * meaning that init() was never called on the PApplet when hosted * my some other main() or by other code. For proper use of init(), * see the examples in the main description text for PApplet. */ public String sketchPath(String where) { if (sketchPath == null) { return where; // throw new RuntimeException("The applet was not inited properly, " + // "or security restrictions prevented " + // "it from determining its path."); } // isAbsolute() could throw an access exception, but so will writing // to the local disk using the sketch path, so this is safe here. // for 0120, added a try/catch anyways. try { if (new File(where).isAbsolute()) return where; } catch (Exception e) { } Context context = getApplicationContext(); return context.getFileStreamPath(where).getAbsolutePath(); }
From source file:com.mplayer_remote.ServerList.java
/** * Metoda odpowiedzialna za tworzenie okien dialogowych wywietlanych przez aktywno. * @see android.app.Activity#onCreateDialog(int, android.os.Bundle) *//*from w w w . j av a 2 s . c o m*/ protected Dialog onCreateDialog(int id, final Bundle retrievedBundle) { // przypisanie kontekstu do dialog final Context mContext = this; // wane w oficjalnej dokumentacji jest bd Dialog dialog = new Dialog(mContext); dialog_FIRST_TIME_RUNING = new Dialog(mContext); dialog_GIVE_ME_A_APP_PASSWORD = new Dialog(mContext); dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE = new Dialog( mContext); dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST = new Dialog( mContext); dialog_GIVE_ME_A_SERVER_PASSWORD = new Dialog(mContext); dialog_ADD_NEW_SERVER_CRYPTO_ENABLED = new Dialog(mContext); dialog_ADD_NEW_SERVER_CRYPTO_DISABLED = new Dialog(mContext); dialog_DELETE_SERVER = new Dialog(mContext); dialog_CHOSE_SERVER_TO_EDIT = new Dialog(mContext); dialog_EDIT_SERVER_CRYPTO_ENABLED = new Dialog(mContext); dialog_EDIT_SERVER_CRYPTO_DISABLED = new Dialog(mContext); dialog_DO_DELATE = new Dialog(mContext); dialog_LICENSE = new Dialog(mContext); switch (id) { case DIALOG_FIRST_TIME_RUNING: //dialog_FIRST_TIME_RUNING.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog_FIRST_TIME_RUNING.setContentView(R.layout.layout_for_dialog_first_time_runing); dialog_FIRST_TIME_RUNING.setTitle(R.string.tile_for_dialog_FIRST_TIME_RUNING); dialog_FIRST_TIME_RUNING.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }); if (appPasswordcharArray != null) { //appPasswordcharArray == null on first start for example try { serverListArrayList = aXMLReaderWriter .decryptFileWithXMLAndParseItToServerList(appPasswordcharArray); } catch (WrongPasswordException e) { // TODO Auto-generated catch block e.printStackTrace(); } } final EditText set_app_passwordEditText = (EditText) dialog_FIRST_TIME_RUNING .findViewById(R.id.set_app_passswordEditText); set_app_passwordEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); final TextView explanation_set_a_password_for_this_appTextView = (TextView) dialog_FIRST_TIME_RUNING .findViewById(R.id.explanation_set_a_password_for_this_app); final ColorStateList explanation_set_a_password_for_this_appTextViewColorStateList = explanation_set_a_password_for_this_appTextView .getTextColors(); final CheckBox use_encryption_checkBox = (CheckBox) dialog_FIRST_TIME_RUNING .findViewById(R.id.use_encryption_checkBox); use_encryption_checkBox.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (use_encryption_checkBox.isChecked() == true) { set_app_passwordEditText.setVisibility(View.VISIBLE); explanation_set_a_password_for_this_appTextView.setVisibility(View.VISIBLE); /* //explanation_set_a_password_for_this_appTextView.setTextColor(explanation_set_a_password_for_this_appTextViewColorStateList); set_app_passwordEditText.setClickable(true); set_app_passwordEditText.setFocusable(true); set_app_passwordEditText.setFocusableInTouchMode(true); set_app_passwordEditText.setCursorVisible(true); set_app_passwordEditText.setLongClickable(true); set_app_passwordEditText.setBackgroundResource(android.R.drawable.edit_text); set_app_passwordEditText.setTextColor(android.graphics.Color.BLACK); */ } else { set_app_passwordEditText.setVisibility(View.INVISIBLE); explanation_set_a_password_for_this_appTextView.setVisibility(View.INVISIBLE); /* //explanation_set_a_password_for_this_appTextView.setTextColor(0); set_app_passwordEditText.setClickable(false); set_app_passwordEditText.setFocusable(false); set_app_passwordEditText.setFocusableInTouchMode(false); set_app_passwordEditText.setCursorVisible(false); set_app_passwordEditText.setLongClickable(false); set_app_passwordEditText.setBackgroundColor(android.graphics.Color.GRAY); set_app_passwordEditText.setTextColor(android.graphics.Color.GRAY); */ } } }); final Button exit_dialog_first_time_runing_button = (Button) dialog_FIRST_TIME_RUNING .findViewById(R.id.exit_dialog_first_time_runing_button); exit_dialog_first_time_runing_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (set_app_passwordEditText.getText().length() == 0 && use_encryption_checkBox.isChecked() == true) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces, Toast.LENGTH_LONG).show(); } else { if (use_encryption_checkBox.isChecked() == true) { isCryptoEnabledboolean = true; } else { isCryptoEnabledboolean = false; } SharedPreferences settings_for_APP = getSharedPreferences("settings_for_APP", 0); SharedPreferences.Editor editor = settings_for_APP.edit(); editor.putBoolean("is_this_first_run", false); editor.putBoolean("is_crypto_enabled", isCryptoEnabledboolean); // Commit the edits! editor.commit(); //a new salt should be created for every new app passwort. Watch a XMLReaderWriter.createKey and SettingsForAPP. File file = mContext.getFileStreamPath("salt"); if (file.exists()) { file.delete(); //Usuwanie salt dla poprzedniego hasa aplikacji. Log.v(TAG, "Usuwam stary salt"); } if (isCryptoEnabledboolean == true) { appPasswordcharArray = set_app_passwordEditText.getText().toString().toCharArray(); aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList, appPasswordcharArray); } else { appPasswordcharArray = "default_password".toCharArray(); aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList, appPasswordcharArray); } if (serverListArrayList != null) { for (int i = 0; i < serverListArrayList.size(); i++) { createConnectButtons(i); } } dismissdialog_FIRST_TIME_RUNING(); } } }); break; case DIALOG_GIVE_ME_A_APP_PASSWORD: dialog_GIVE_ME_A_APP_PASSWORD.setContentView(R.layout.layout_for_dialog_give_me_a_app_password); dialog_GIVE_ME_A_APP_PASSWORD.setTitle(R.string.title_for_dialog_GIVE_ME_A_APP_PASSWORD); dialog_GIVE_ME_A_APP_PASSWORD.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }); final Button check_app_passwordButton = (Button) dialog_GIVE_ME_A_APP_PASSWORD .findViewById(R.id.check_app_password_Button); check_app_passwordButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText app_password_EditText = (EditText) dialog_GIVE_ME_A_APP_PASSWORD .findViewById(R.id.app_password_EditText); if (app_password_EditText.getText().length() == 0) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces, Toast.LENGTH_LONG).show(); } else { app_password_EditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); appPasswordcharArray = (app_password_EditText.getText().toString()).toCharArray(); try { serverListArrayList = aXMLReaderWriter .decryptFileWithXMLAndParseItToServerList(appPasswordcharArray); if (serverListArrayList != null) { for (int i = 0; i < serverListArrayList.size(); i++) { createConnectButtons(i); } } final CheckBox remember_app_password_in_sesion_CheckBox = (CheckBox) dialog_GIVE_ME_A_APP_PASSWORD .findViewById(R.id.remember_app_password_in_sesion_CheckBox); if (remember_app_password_in_sesion_CheckBox.isChecked() == true) { rememberAppPasswordInSesionboolean = true; SharedPreferences settings_for_APP = getSharedPreferences("settings_for_APP", 0); SharedPreferences.Editor editor = settings_for_APP.edit(); editor.putBoolean("remember_app_password_in_sesion_boolean", rememberAppPasswordInSesionboolean); // Commit the edits! editor.commit(); } else { Arrays.fill(appPasswordcharArray, '0'); appPasswordcharArray = null; rememberAppPasswordInSesionboolean = false; SharedPreferences settings_for_APP = getSharedPreferences("settings_for_APP", 0); SharedPreferences.Editor editor = settings_for_APP.edit(); editor.putBoolean("remember_app_password_in_sesion_boolean", rememberAppPasswordInSesionboolean); // Commit the edits! editor.commit(); } dismissdialog_GIVE_ME_A_APP_PASSWORD(); } catch (WrongPasswordException e) { appPasswordcharArray = null; Toast.makeText(getApplicationContext(), R.string.wrong_app_password_exeption, Toast.LENGTH_SHORT).show(); showdialog_GIVE_ME_A_APP_PASSWORD(); } } } }); break; //called in dialogs DIALOG_ADD_NEW_SERVER... and DIALOG_EDIT_SERVER.. case DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE: dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE.setContentView( R.layout.layout_for_dialog__because_remember_app_password_in_sesion_boolean_is_false); dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE.setTitle( R.string.title_for_dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE); Button continue_with_given_app_password_Button = (Button) dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE .findViewById(R.id.continue_with_given_app_password_Button); continue_with_given_app_password_Button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText app_password_EditText = (EditText) dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE .findViewById( R.id.app_password_EditText_in_layout_for_dialog__because_remember_app_password_in_sesion_boolean_is_false); if (app_password_EditText.getText().length() == 0) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces, Toast.LENGTH_LONG).show(); } else { app_password_EditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); Log.v(TAG, "app_password przez odczytaniem z app_password_EditText w: DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE" + appPasswordcharArray); appPasswordcharArray = (app_password_EditText.getText().toString()).toCharArray(); Log.v(TAG, "app_password po odczytaniu z app_password_EditText w: DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE" + appPasswordcharArray.toString()); try { List<Server> test_input_server_list = new ArrayList<Server>(); test_input_server_list = aXMLReaderWriter .decryptFileWithXMLAndParseItToServerList(appPasswordcharArray); //catch if password is wrong aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList, appPasswordcharArray); //Log.v(TAG,server.getServer_name()); //Log.v(TAG,server.getIP_address()); //Log.v(TAG,server.getUsername()); //Log.v(TAG,new String(server.getPassword())); //removeDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE); Arrays.fill(appPasswordcharArray, '0'); appPasswordcharArray = null; finish(); Intent intent = new Intent(mContext, ServerList.class); startActivity(intent); } catch (WrongPasswordException e) { appPasswordcharArray = null; Toast.makeText(getApplicationContext(), R.string.wrong_app_password_exeption, Toast.LENGTH_SHORT).show(); //showDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE); } } } }); break; case DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST: dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST .setContentView( R.layout.layout_for_dialog__because_remember_app_password_in_sesion_boolean_is_false); dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST .setTitle( R.string.title_for_dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE); Button continue_with_given_app_password_Button2 = (Button) dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST .findViewById(R.id.continue_with_given_app_password_Button); continue_with_given_app_password_Button2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText app_password_EditText = (EditText) dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST .findViewById( R.id.app_password_EditText_in_layout_for_dialog__because_remember_app_password_in_sesion_boolean_is_false); if (app_password_EditText.getText().length() == 0) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces, Toast.LENGTH_LONG).show(); } else { app_password_EditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); Log.v(TAG, "app_password przez odczytaniem z app_password_EditText w: DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST" + appPasswordcharArray); appPasswordcharArray = (app_password_EditText.getText().toString()).toCharArray(); Log.v(TAG, "app_password po odczytaniu z app_password_EditText w: DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST" + appPasswordcharArray.toString()); try { List<Server> test_input_server_list = new ArrayList<Server>(); test_input_server_list = aXMLReaderWriter .decryptFileWithXMLAndParseItToServerList(appPasswordcharArray); //catch if password is wrong aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList, appPasswordcharArray); final Intent intent_start_settings_activity_for_ServerList = new Intent( getApplicationContext(), SettingsForAPP.class); intent_start_settings_activity_for_ServerList.putExtra("app_password", appPasswordcharArray); startActivity(intent_start_settings_activity_for_ServerList); finish(); //removeDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE); Arrays.fill(appPasswordcharArray, '0'); appPasswordcharArray = null; } catch (WrongPasswordException e) { appPasswordcharArray = null; Toast.makeText(getApplicationContext(), R.string.wrong_app_password_exeption, Toast.LENGTH_SHORT).show(); //showDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE); } } } }); break; case DIALOG_GIVE_ME_A_SERVER_PASSWORD: dialog_GIVE_ME_A_SERVER_PASSWORD.setContentView(R.layout.layout_for_dialog_give_me_a_server_password); dialog_GIVE_ME_A_SERVER_PASSWORD.setTitle(R.string.title_for_dialog_GIVE_ME_A_SERVER_PASSWORD); final Button connect_to_server_button_in_DIALOG_GIVE_ME_A_SERVER_PASSWORD = (Button) dialog_GIVE_ME_A_SERVER_PASSWORD .findViewById(R.id.connect_to_server_Button_in_dialog_give_me_a_server_password); connect_to_server_button_in_DIALOG_GIVE_ME_A_SERVER_PASSWORD.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText server_password_EditText = (EditText) dialog_GIVE_ME_A_SERVER_PASSWORD .findViewById(R.id.server_password_EditText); if (server_password_EditText.getText().length() == 0) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces, Toast.LENGTH_LONG).show(); } else { server_password_EditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); char[] server_password = (server_password_EditText.getText().toString().toCharArray()); Log.v(TAG, "server_password przeczytane z server_password_EditText: " + new String(server_password)); int id_of_clicked_button = retrievedBundle.getInt("clicked_button"); Log.v(TAG, "id of clicked button: " + id_of_clicked_button); Intent intent_start_ConnectToServer = new Intent(getApplicationContext(), ConnectToServer.class); final Intent intent_start_ConnectAndPlayService = new Intent(getApplicationContext(), ConnectAndPlayService.class); intent_start_ConnectAndPlayService.putExtra("server_name", serverListArrayList.get(id_of_clicked_button).getServerName()); intent_start_ConnectAndPlayService.putExtra("IP_address", serverListArrayList.get(id_of_clicked_button).getIPAddress()); intent_start_ConnectAndPlayService.putExtra("username", serverListArrayList.get(id_of_clicked_button).getUsername()); intent_start_ConnectAndPlayService.putExtra("password", server_password); startService(intent_start_ConnectAndPlayService); connectingToSshProgressDialog = ProgressDialog.show(ServerList.this, "", getString(R.string.text_for_progressdialog_from_connecttoserver), true, true); removeDialog(DIALOG_GIVE_ME_A_SERVER_PASSWORD); Arrays.fill(server_password, '0'); } } }); break; case DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED: dialog_ADD_NEW_SERVER_CRYPTO_ENABLED .setContentView(R.layout.layout_for_dialog_add_new_server_crypto_enabled); dialog_ADD_NEW_SERVER_CRYPTO_ENABLED.setTitle(R.string.title_for_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED); //Buttons final Button saveButton_in_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED = (Button) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED .findViewById(R.id.saveButton_crypto_enabled); final Button cancelButton_in_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED = (Button) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED .findViewById(R.id.cancelButton_crypto_enabled); saveButton_in_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText server_nameEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED .findViewById(R.id.server_nameEditText_crypto_enabled); server_nameEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); EditText IP_addressEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED .findViewById(R.id.IP_addressEditText_crypto_enabled); IP_addressEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); EditText usernameEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED .findViewById(R.id.usernameEditText_crypto_enabled); usernameEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); EditText passwordEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED .findViewById(R.id.passwordEditText_crypto_enabled); passwordEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); Log.v(TAG, "obecna ilosc zapisanych serverow wynosi: " + serverListArrayList.size()); if (server_nameEditText.getText().length() == 0 || IP_addressEditText.getText().length() == 0 || usernameEditText.getText().length() == 0 || passwordEditText.getText().length() == 0) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces, Toast.LENGTH_LONG).show(); //}else if(!validateIP(IP_addressEditText.getText().toString())){ //Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address, Toast.LENGTH_LONG).show(); //}else if (server_nameEditText.getText().toString().matches(".*\\s+.*") || IP_addressEditText.getText().toString().matches(".*\\s+.*") || usernameEditText.getText().toString().matches(".*\\s+.*") || passwordEditText.getText().toString().matches(".*\\s+.*")){ //Toast.makeText(getApplicationContext(), R.string.text_for_toast_fields_should_not_contain_a_whitespace_character, Toast.LENGTH_LONG).show(); } else if (!(isIPv4OrIPv6(IP_addressEditText.getText().toString()))) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address, Toast.LENGTH_LONG).show(); } else { Server server = new Server(); server.setServerName(server_nameEditText.getText().toString()); server.setIPAddress(IP_addressEditText.getText().toString()); server.setUsername(usernameEditText.getText().toString()); server.setPassword(passwordEditText.getText().toString().toCharArray()); serverListArrayList.add(server); if (appPasswordcharArray == null) { showDialog( DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE); //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password); //sprawdzi czy bdzie dziaa bez tego e niby w onPause() wystarczy removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED); } else { Log.v(TAG, server.getServerName()); Log.v(TAG, server.getIPAddress()); Log.v(TAG, server.getUsername()); Log.v(TAG, new String(server.getPassword())); removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED); finish(); Intent intent = new Intent(mContext, ServerList.class); startActivity(intent); } } } }); cancelButton_in_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED); } }); dialog_ADD_NEW_SERVER_CRYPTO_ENABLED.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { // TODO Auto-generated method stub } }); break; case DIALOG_ADD_NEW_SERVER_CRYPTO_DISABLED: dialog_ADD_NEW_SERVER_CRYPTO_DISABLED .setContentView(R.layout.layout_for_dialog_add_new_server_crypto_disabled); dialog_ADD_NEW_SERVER_CRYPTO_DISABLED.setTitle(R.string.title_for_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED); //title is the same //Buttons final Button saveButton_in_dialog_ADD_NEW_SERVER_CRYPTO_DISABLED = (Button) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED .findViewById(R.id.saveButton_crypto_disabled); final Button cancelButton_in_dialog_ADD_NEW_SERVER_CRYPTO_DISABLED = (Button) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED .findViewById(R.id.cancelButton_crypto_disabled); saveButton_in_dialog_ADD_NEW_SERVER_CRYPTO_DISABLED.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText server_nameEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED .findViewById(R.id.server_nameEditText_crypto_disabled); server_nameEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); EditText IP_addressEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED .findViewById(R.id.IP_addressEditText_crypto_disabled); IP_addressEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); EditText usernameEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED .findViewById(R.id.usernameEditText_crypto_disabled); usernameEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); Log.v(TAG, "obecna ilosc zapisanych serverow wynosi: " + serverListArrayList.size()); if (server_nameEditText.getText().length() == 0 || IP_addressEditText.getText().length() == 0 || usernameEditText.getText().length() == 0) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces, Toast.LENGTH_LONG).show(); //}else if(!validateIP(IP_addressEditText.getText().toString())){ //Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address, Toast.LENGTH_LONG).show(); //}else if (server_nameEditText.getText().toString().matches(".*\\s+.*") || IP_addressEditText.getText().toString().matches(".*\\s+.*") || usernameEditText.getText().toString().matches(".*\\s+.*") || passwordEditText.getText().toString().matches(".*\\s+.*")){ //Toast.makeText(getApplicationContext(), R.string.text_for_toast_fields_should_not_contain_a_whitespace_character, Toast.LENGTH_LONG).show(); } else if (!(isIPv4OrIPv6(IP_addressEditText.getText().toString()))) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address, Toast.LENGTH_LONG).show(); } else { Server server = new Server(); server.setServerName(server_nameEditText.getText().toString()); server.setIPAddress(IP_addressEditText.getText().toString()); server.setUsername(usernameEditText.getText().toString()); server.setPassword("a_blank_password".toCharArray()); serverListArrayList.add(server); //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password); Log.v(TAG, server.getServerName()); Log.v(TAG, server.getIPAddress()); Log.v(TAG, server.getUsername()); Log.v(TAG, new String(server.getPassword())); removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_DISABLED); finish(); Intent intent = new Intent(mContext, ServerList.class); startActivity(intent); } } }); cancelButton_in_dialog_ADD_NEW_SERVER_CRYPTO_DISABLED.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_DISABLED); } }); break; case DIALOG_CHOOSE_SERVER_TO_EDIT: Log.v(TAG, "Wszedem do onCreate DIALOG_CHOOSE_SERVER_TO_EDIT"); itemsFor_DIALOG_EDIT_SERVER = new CharSequence[serverListArrayList.size()]; for (int i = 0; i < serverListArrayList.size(); i++) { itemsFor_DIALOG_EDIT_SERVER[i] = serverListArrayList.get(i).getServerName(); Log.v(TAG, "Server_name :" + itemsFor_DIALOG_EDIT_SERVER[i]); } AlertDialog.Builder builder_for_DIALOG_CHOSE_SERVER_TO_EDIT = new AlertDialog.Builder(this); builder_for_DIALOG_CHOSE_SERVER_TO_EDIT.setTitle(R.string.title_for_dialog_CHOSE_SERVER_TO_EDIT); builder_for_DIALOG_CHOSE_SERVER_TO_EDIT.setItems(itemsFor_DIALOG_EDIT_SERVER, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog_CHOSE_SERVER_TO_EDIT, int item) { //Toast.makeText(getApplicationContext(), items_for_DIALOG_EDIT_SERVER[item], Toast.LENGTH_SHORT).show(); serverToEditint = item; Log.v(TAG, "server do edycji ma numer: " + item); removeDialog(DIALOG_CHOOSE_SERVER_TO_EDIT); if (isCryptoEnabledboolean == true) { showDialog(DIALOG_EDIT_SERVER_CRYPTO_ENABLED); } else { showDialog(DIALOG_EDIT_SERVER_CRYPTO_DISABLED); } } }); dialog_CHOSE_SERVER_TO_EDIT = builder_for_DIALOG_CHOSE_SERVER_TO_EDIT.create(); break; case DIALOG_EDIT_SERVER_CRYPTO_ENABLED: dialog_EDIT_SERVER_CRYPTO_ENABLED.setContentView(R.layout.layout_for_dialog_edit_server_crypto_enabled); dialog_EDIT_SERVER_CRYPTO_ENABLED.setTitle(R.string.title_for_dialog_EDIT_SERVER_CRYPTO_ENABLED); //Buttons final Button saveButton_from_DIALOG_EDIT_SERVER = (Button) dialog_EDIT_SERVER_CRYPTO_ENABLED .findViewById(R.id.saveButton_in_dialog_edit_server_crypto_enabled); final Button cancelButton_from_DIALOG_EDIT_SERVER = (Button) dialog_EDIT_SERVER_CRYPTO_ENABLED .findViewById(R.id.cancelButton_in_dialog_edit_server_crypto_enabled); final EditText server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED = (EditText) dialog_EDIT_SERVER_CRYPTO_ENABLED .findViewById(R.id.server_name_in_dialog_edit_server_EditText_crypto_enabled_from_edit_server); server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED .setText(serverListArrayList.get(serverToEditint).getServerName()); server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); final EditText IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED = (EditText) dialog_EDIT_SERVER_CRYPTO_ENABLED .findViewById(R.id.IP_address_in_dialog_EditText_crypto_enabled_from_edit_server); IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED .setText(serverListArrayList.get(serverToEditint).getIPAddress()); IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); final EditText usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED = (EditText) dialog_EDIT_SERVER_CRYPTO_ENABLED .findViewById(R.id.username_in_dialog_edit_server_EditText_crypto_enabled_from_edit_server); usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED .setText(serverListArrayList.get(serverToEditint).getUsername()); usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); final EditText passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED = (EditText) dialog_EDIT_SERVER_CRYPTO_ENABLED .findViewById(R.id.password_in_dialog_edit_server_EditText_crypto_enabled_from_edit_server); passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED .setText(new String(serverListArrayList.get(serverToEditint).getPassword())); passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); saveButton_from_DIALOG_EDIT_SERVER.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Log.v(TAG, "obecna ilosc zapisanych serverow wynosi: " + serverListArrayList.size()); if (server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().length() == 0 || IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().length() == 0 || usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().length() == 0 || passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().length() == 0) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces, Toast.LENGTH_LONG).show(); } else if (!(isIPv4OrIPv6( IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().toString()))) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address, Toast.LENGTH_LONG).show(); } else { Server server = new Server(); server.setServerName( server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().toString()); server.setIPAddress( IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().toString()); server.setUsername( usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().toString()); server.setPassword(passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText() .toString().toCharArray()); //server_nameEditText.getText().toString() to nazwa pliku serverListArrayList.set(serverToEditint, server); if (appPasswordcharArray == null) { showDialog( DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE); //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password); //sprawdzi czy bdzie dziaa bez tego e niby w onPause() wystarczy removeDialog(DIALOG_EDIT_SERVER_CRYPTO_ENABLED); } else { Log.v(TAG, server.getServerName()); Log.v(TAG, server.getIPAddress()); Log.v(TAG, server.getUsername()); Log.v(TAG, new String(server.getPassword())); removeDialog(DIALOG_EDIT_SERVER_CRYPTO_ENABLED); finish(); Intent intent = new Intent(mContext, ServerList.class); startActivity(intent); } } } }); cancelButton_from_DIALOG_EDIT_SERVER.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { removeDialog(DIALOG_EDIT_SERVER_CRYPTO_ENABLED); } }); dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { // TODO Auto-generated method stub } }); break; case DIALOG_EDIT_SERVER_CRYPTO_DISABLED: dialog_EDIT_SERVER_CRYPTO_DISABLED .setContentView(R.layout.layout_for_dialog_edit_server_crypto_disabled); dialog_EDIT_SERVER_CRYPTO_DISABLED.setTitle(R.string.title_for_dialog_EDIT_SERVER_CRYPTO_ENABLED); //Buttons final Button saveButton_in_dialog_EDIT_SERVER_CRYPTO_DISABLED = (Button) dialog_EDIT_SERVER_CRYPTO_DISABLED .findViewById(R.id.saveButton_in_dialog_edit_server_crypto_disabled); final Button cancelButton_in_dialog_EDIT_SERVER_CRYPTO_DISABLED = (Button) dialog_EDIT_SERVER_CRYPTO_DISABLED .findViewById(R.id.cancelButton_in_dialog_edit_server_crypto_disabled); final EditText server_nameEditText = (EditText) dialog_EDIT_SERVER_CRYPTO_DISABLED .findViewById(R.id.server_name_in_dialog_edit_server_EditText_crypto_disabled_from_edit_server); server_nameEditText.setText(serverListArrayList.get(serverToEditint).getServerName()); server_nameEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); final EditText IP_addressEditText = (EditText) dialog_EDIT_SERVER_CRYPTO_DISABLED .findViewById(R.id.IP_address_in_dialog_edit_server_EditText_crypto_disabled_from_edit_server); IP_addressEditText.setText(serverListArrayList.get(serverToEditint).getIPAddress()); IP_addressEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); final EditText usernameEditText = (EditText) dialog_EDIT_SERVER_CRYPTO_DISABLED .findViewById(R.id.username_in_dialog_edit_server_EditText_crypto_disabled_from_edit_server); usernameEditText.setText(serverListArrayList.get(serverToEditint).getUsername()); usernameEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press return true; } return false; } }); saveButton_in_dialog_EDIT_SERVER_CRYPTO_DISABLED.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Log.v(TAG, "obecna ilosc zapisanych serverow wynosi: " + serverListArrayList.size()); if (server_nameEditText.getText().length() == 0 || IP_addressEditText.getText().length() == 0 || usernameEditText.getText().length() == 0) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces, Toast.LENGTH_LONG).show(); } else if (!(isIPv4OrIPv6(IP_addressEditText.getText().toString()))) { Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address, Toast.LENGTH_LONG).show(); } else { Server server = new Server(); server.setServerName(server_nameEditText.getText().toString()); server.setIPAddress(IP_addressEditText.getText().toString()); server.setUsername(usernameEditText.getText().toString()); server.setPassword("a_blank_password".toCharArray()); serverListArrayList.set(serverToEditint, server); //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password); Log.v(TAG, server.getServerName()); Log.v(TAG, server.getIPAddress()); Log.v(TAG, server.getUsername()); Log.v(TAG, new String(server.getPassword())); removeDialog(DIALOG_EDIT_SERVER_CRYPTO_DISABLED); finish(); Intent intent = new Intent(mContext, ServerList.class); startActivity(intent); } } }); cancelButton_in_dialog_EDIT_SERVER_CRYPTO_DISABLED.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { removeDialog(DIALOG_EDIT_SERVER_CRYPTO_DISABLED); } }); break; case DIALOG_DELETE_SERVER: Log.v(TAG, "Wszedem do onCreate DIALOG_DELETE_SERVER"); itemsFor_DIALOG_DELETE_SERVER = new CharSequence[serverListArrayList.size()]; for (int i = 0; i < serverListArrayList.size(); i++) { itemsFor_DIALOG_DELETE_SERVER[i] = serverListArrayList.get(i).getServerName(); Log.v(TAG, "Server_name :" + itemsFor_DIALOG_DELETE_SERVER[i]); } AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(R.string.title_for_dialog_DELETE_SERVER); builder.setItems(itemsFor_DIALOG_DELETE_SERVER, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog_DELETE_SERVER, int item) { serverToDelete = item; showDialog(DIALOG_DO_DELATE); /* serverListArrayList.remove(item); if (appPasswordcharArray == null){ showDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE); //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password); //sprawdzi czy bdzie dziaa bez tego e niby w onPause() wystarczy }else{ finish(); Intent intent = new Intent(mContext, ServerList.class); startActivity(intent); } */ } }); dialog_DELETE_SERVER = builder.create(); break; case DIALOG_DO_DELATE: Log.v(TAG, "Wszedem do onCreate DIALOG_DO_DELATE"); AlertDialog.Builder builderDIALOG_DO_DELATE = new AlertDialog.Builder(mContext); builderDIALOG_DO_DELATE.setTitle(getResources().getString(R.string.title_for_dialog_DO_DELETE)); builderDIALOG_DO_DELATE.setMessage(getResources().getString(R.string.message_in_dialog_DO_DELATE) + " " + itemsFor_DIALOG_DELETE_SERVER[serverToDelete] + "?"); // Add the buttons builderDIALOG_DO_DELATE.setPositiveButton(R.string.text_for_do_delete_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button serverListArrayList.remove(serverToDelete); if (appPasswordcharArray == null) { showDialog( DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE); //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password); //sprawdzi czy bdzie dziaa bez tego e niby w onPause() wystarczy removeDialog(DIALOG_DO_DELATE); } else { finish(); Intent intent = new Intent(mContext, ServerList.class); startActivity(intent); removeDialog(DIALOG_DO_DELATE); } } }); builderDIALOG_DO_DELATE.setNegativeButton(R.string.text_for_cancel_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog removeDialog(DIALOG_DO_DELATE); } }); // Set other dialog properties // Create the AlertDialog dialog_DO_DELATE = builderDIALOG_DO_DELATE.create(); break; case DIALOG_LICENSE: // EULA title String title = getResources().getString(R.string.app_name); // EULA text String message = getResources().getString(R.string.Licences_text); AlertDialog.Builder builderDIALOG_LICENSE = new AlertDialog.Builder(mContext).setTitle(title) .setMessage(message) .setPositiveButton(R.string.text_for_cancel_button, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }); // Create the AlertDialog dialog_LICENSE = builderDIALOG_LICENSE.create(); break; default: dialog = null; } if (id == DIALOG_FIRST_TIME_RUNING) { dialog = dialog_FIRST_TIME_RUNING; } if (id == DIALOG_GIVE_ME_A_APP_PASSWORD) { dialog = dialog_GIVE_ME_A_APP_PASSWORD; } if (id == DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE) { dialog = dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE; } if (id == DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST) { dialog = dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST; } if (id == DIALOG_GIVE_ME_A_SERVER_PASSWORD) { dialog = dialog_GIVE_ME_A_SERVER_PASSWORD; } if (id == DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED) { dialog = dialog_ADD_NEW_SERVER_CRYPTO_ENABLED; } if (id == DIALOG_ADD_NEW_SERVER_CRYPTO_DISABLED) { dialog = dialog_ADD_NEW_SERVER_CRYPTO_DISABLED; } if (id == DIALOG_DELETE_SERVER) { dialog = dialog_DELETE_SERVER; } if (id == DIALOG_DO_DELATE) { dialog = dialog_DO_DELATE; } if (id == DIALOG_CHOOSE_SERVER_TO_EDIT) { dialog = dialog_CHOSE_SERVER_TO_EDIT; } if (id == DIALOG_EDIT_SERVER_CRYPTO_ENABLED) { dialog = dialog_EDIT_SERVER_CRYPTO_ENABLED; } if (id == DIALOG_EDIT_SERVER_CRYPTO_DISABLED) { dialog = dialog_EDIT_SERVER_CRYPTO_DISABLED; } if (id == DIALOG_LICENSE) { dialog = dialog_LICENSE; } return dialog; }