List of usage examples for android.app Dialog Dialog
public Dialog(@NonNull Context context)
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display the list of Spotlight web apps: * https://www.google.com/tv/spotlight-gallery.html Allow the user to launch * a web app in the browser./*from www . j av a2s. c o m*/ * * @param context */ public static void displayAllSpotlight(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.spotlight_grid); final GridView gridView = (GridView) dialog.findViewById(R.id.grid); final ArrayList<SpotlightInfo> spotlights = SpotlightTable.getAllSpotlights(context); gridView.setAdapter(new AllSpotlightAdapter(context, spotlights)); gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SpotlightInfo spotlightInfo = (SpotlightInfo) parent.getAdapter().getItem(position); spotlightInfo.invoke(context); context.showCover(false); dialog.dismiss(); Analytics.logEvent(Analytics.INVOKE_SPOTLIGHT_WEB_APP); } }); gridView.setDrawingCacheEnabled(true); gridView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_SPOTLIGHT_WEB_APPS); }
From source file:com.corporatetaxi.TaxiOntheWay_Activity.java
private void initiatePopupWindowsendmesage() { try {/*from ww w. j a v a 2 s .c o m*/ dialog = new Dialog(TaxiOntheWay_Activity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // before dialog.setContentView(R.layout.sendmesssage_popup); Button mbtn_sendmesssage = (Button) dialog.findViewById(R.id.btn_acceptor); Button mbtn_cancel = (Button) dialog.findViewById(R.id.btn_cancel); rd4 = (RadioButton) dialog.findViewById(R.id.radioButton1); rd5 = (RadioButton) dialog.findViewById(R.id.radioButton2); rd6 = (RadioButton) dialog.findViewById(R.id.radioButton3); mcross = (ImageButton) dialog.findViewById(R.id.cross); txt_header = (TextView) dialog.findViewById(R.id.popup_text); mcross.setOnClickListener(cancle_btn_click_listener); mbtn_cancel.setOnClickListener(cancle_btn_click_listener); Typeface tf = Typeface.createFromAsset(this.getAssets(), "Montserrat-Regular.ttf"); rd4.setTypeface(tf); rd5.setTypeface(tf); rd6.setTypeface(tf); mbtn_sendmesssage.setTypeface(tf); txt_header.setTypeface(tf); mbtn_cancel.setTypeface(tf); mbtn_sendmesssage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (rd4.isChecked()) { sendmessage = getResources().getString(R.string.prompt_message_one); } else if (rd5.isChecked()) { sendmessage = getResources().getString(R.string.prompt_message_two); } else if (rd6.isChecked()) { sendmessage = getResources().getString(R.string.prompt_message_three); } Allbeans allbeans = new Allbeans(); allbeans.setSendmessage(sendmessage); new SendmessageAsynch(allbeans).execute(); } }); dialog.show(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
private void confirmSendLog() { mGlblParms.util.flushLog();/*w ww . ja v a 2 s.c om*/ createTempLogFile(); final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.confirm_send_log_dlg); final Button btn_ok = (Button) dialog.findViewById(R.id.confirm_send_log_dlg_ok_btn); final Button btn_cancel = (Button) dialog.findViewById(R.id.confirm_send_log_dlg_cancel_btn); final Button btn_preview = (Button) dialog.findViewById(R.id.confirm_send_log_dlg_preview); CommonDialog.setDlgBoxSizeLimit(dialog, false); btn_preview.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + mEnvParms.settingLogMsgDir + "temp_log.txt"), "text/plain"); startActivity(intent); } }); btn_ok.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mGlblParms.util.sendLogFileToDeveloper(mEnvParms.settingLogMsgDir + "temp_log.txt"); dialog.dismiss(); } }); btn_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); dialog.show(); }
From source file:com.usertaxi.TaxiOntheWay_Activity.java
private void initiatePopupWindowcanceltaxi() { try {//from w w w. j av a2 s. c om dialog = new Dialog(TaxiOntheWay_Activity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // before dialog.setContentView(R.layout.canceltaxi_popup); cross = (ImageButton) dialog.findViewById(R.id.cross); cross.setOnClickListener(cancle_btn_click_listener); rd1 = (RadioButton) dialog.findViewById(R.id.radioButton); rd2 = (RadioButton) dialog.findViewById(R.id.radioButton2); rd3 = (RadioButton) dialog.findViewById(R.id.radioButton3); btn_cancel = (Button) dialog.findViewById(R.id.btn_acceptor); TextView txt = (TextView) dialog.findViewById(R.id.textView); textheader = (TextView) dialog.findViewById(R.id.popup_text); Typeface tf = Typeface.createFromAsset(this.getAssets(), "Montserrat-Regular.ttf"); rd1.setTypeface(tf); rd2.setTypeface(tf); rd3.setTypeface(tf); btn_cancel.setTypeface(tf); txt.setTypeface(tf); textheader.setTypeface(tf); btn_cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (rd1.isChecked()) { canceltaxirequest = getResources().getString(R.string.prompt_canceltaxione); } else if (rd2.isChecked()) { canceltaxirequest = getResources().getString(R.string.prompt_cancel_reason_two); } else if (rd3.isChecked()) { canceltaxirequest = getResources().getString(R.string.prompt_cancel_reason_three); } Allbeans allbeans = new Allbeans(); allbeans.setCanceltaxirequest(canceltaxirequest); new CancelTaxiAsynch(allbeans).execute(); } }); dialog.show(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.nononsenseapps.notepad.MainActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DELETE_LIST: final Dialog deleteDialog = new Dialog(this); deleteDialog.setContentView(R.layout.delete_list_dialog); deleteDialog.setTitle(R.string.menu_deletelist); Button dYesButton = (Button) deleteDialog.findViewById(R.id.d_dialog_yes); dYesButton.setOnClickListener(new OnClickListener() { @Override/* w w w . jav a 2 s. c o m*/ public void onClick(View v) { deleteCurrentList(); deleteDialog.dismiss(); } }); Button dNoButton = (Button) deleteDialog.findViewById(R.id.d_dialog_no); dNoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { deleteDialog.cancel(); } }); return deleteDialog; case CREATE_LIST: final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.create_list_dialog); dialog.setTitle(R.string.menu_createlist); EditText title = (EditText) dialog.findViewById(R.id.editTitle); title.setText(""); Button yesButton = (Button) dialog.findViewById(R.id.dialog_yes); yesButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText title = (EditText) dialog.findViewById(R.id.editTitle); createList(title.getText().toString()); title.setText(""); dialog.dismiss(); } }); Button noButton = (Button) dialog.findViewById(R.id.dialog_no); noButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActionBar().setSelectedNavigationItem(currentListPos); dialog.cancel(); } }); return dialog; case RENAME_LIST: final Dialog renameDialog = new Dialog(this); renameDialog.setContentView(R.layout.rename_list_dialog); renameDialog.setTitle(R.string.menu_renamelist); CharSequence currentTitle = ""; if (mSectionsPagerAdapter != null) currentTitle = mSectionsPagerAdapter.getPageTitle(currentListPos); EditText renameTitle = (EditText) renameDialog.findViewById(R.id.renameTitle); renameTitle.setText(currentTitle); Button rYesButton = (Button) renameDialog.findViewById(R.id.r_dialog_yes); rYesButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText renameTitle = (EditText) renameDialog.findViewById(R.id.renameTitle); renameList(renameTitle.getText().toString()); renameTitle.setText(""); renameDialog.dismiss(); } }); Button rNoButton = (Button) renameDialog.findViewById(R.id.r_dialog_no); rNoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { renameDialog.cancel(); } }); return renameDialog; default: return null; } }
From source file:com.vkassin.mtrade.Common.java
public static void login(final Context ctx) { // ctx = Common.app_ctx; Common.connected = false;/*from w w w . ja v a 2 s . c o m*/ if (inLogin) return; inLogin = true; if (Common.mainActivity != null) Common.mainActivity.handler.sendMessage( Message.obtain(Common.mainActivity.handler, Common.mainActivity.DISMISS_PROGRESS_DIALOG)); // while(true) { final Dialog dialog = new Dialog(ctx); dialog.setContentView(R.layout.login_dialog); dialog.setTitle(R.string.LoginDialogTitle); dialog.setCancelable(false); final EditText nametxt = (EditText) dialog.findViewById(R.id.loginnameedit); final EditText passtxt = (EditText) dialog.findViewById(R.id.passwordedit); final EditText passtxt1 = (EditText) dialog.findViewById(R.id.passwordedit1); final EditText passtxt2 = (EditText) dialog.findViewById(R.id.passwordedit2); final EditText mailtxt = (EditText) dialog.findViewById(R.id.emailedit2); String nam = myaccount.get("name"); Common.oldName = nam; if (nam != null) { nametxt.setText(nam); passtxt.requestFocus(); } Button customDialog_Register = (Button) dialog.findViewById(R.id.goregister); customDialog_Register.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { dialog.setTitle(R.string.LoginDialogTitle1); final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354); layreg.setVisibility(View.VISIBLE); final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543); laylog.setVisibility(View.GONE); } }); Button customDialog_Register1 = (Button) dialog.findViewById(R.id.goregister1); customDialog_Register1.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { if (mailtxt.getText().length() < 1) { Toast toast = Toast.makeText(mainActivity, R.string.CorrectEmail, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return; } if (passtxt1.getText().length() < 1) { Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return; } if (!passtxt2.getText().toString().equals(passtxt1.getText().toString())) { Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword1, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return; } try { Socket sock = new Socket(ip_addr, port_register); JSONObject msg = new JSONObject(); msg.put("objType", Common.MSG_REGISTER); msg.put("time", Calendar.getInstance().getTimeInMillis()); msg.put("user", mailtxt.getText().toString()); msg.put("passwd", passtxt1.getText().toString()); msg.put("version", Common.PROTOCOL_VERSION); msg.put("sign", sign(mailtxt.getText().toString(), passtxt1.getText().toString())); byte[] array = msg.toString().getBytes(); ByteBuffer buff = ByteBuffer.allocate(array.length + 4); buff.putInt(array.length); buff.put(array); sock.getOutputStream().write(buff.array()); ByteBuffer buff1 = ByteBuffer.allocate(4); buff1.put(readMsg(sock.getInputStream(), 4)); buff1.position(0); int pkgSize = buff1.getInt(); // Log.i(TAG, "size = "+pkgSize); String s = new String(readMsg(sock.getInputStream(), pkgSize)); sock.close(); JSONObject jo = new JSONObject(s); Log.i(TAG, "register answer = " + jo); int t = jo.getInt("status"); switch (t) { case 1: Toast toast = Toast.makeText(mainActivity, R.string.RegisterStatus1, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); dialog.setTitle(R.string.LoginDialogTitle); final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354); layreg.setVisibility(View.GONE); final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543); laylog.setVisibility(View.VISIBLE); nametxt.setText(mailtxt.getText()); break; case -2: Toast toast1 = Toast.makeText(mainActivity, R.string.RegisterStatus3, Toast.LENGTH_LONG); toast1.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast1.show(); break; default: Toast toast2 = Toast.makeText(mainActivity, R.string.RegisterStatus2, Toast.LENGTH_LONG); toast2.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast2.show(); break; } } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "Error in registration process!!", e); Toast toast = Toast.makeText(mainActivity, R.string.ConnectError, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); } } }); Button customDialog_CancelReg = (Button) dialog.findViewById(R.id.cancelreg); customDialog_CancelReg.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { dialog.setTitle(R.string.LoginDialogTitle); final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354); layreg.setVisibility(View.GONE); final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543); laylog.setVisibility(View.VISIBLE); } }); Button customDialog_Dismiss = (Button) dialog.findViewById(R.id.gologin); customDialog_Dismiss.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.lradio0); Common.isSSL = bu0.isChecked(); inLogin = false; JSONObject msg = new JSONObject(); try { msg.put("objType", Common.LOGOUT); msg.put("time", Calendar.getInstance().getTimeInMillis()); msg.put("version", Common.PROTOCOL_VERSION); msg.put("status", 1); mainActivity.writeJSONMsg(msg); } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "Error! Cannot create JSON logout object", e); } myaccount.put("name", nametxt.getText().toString()); myaccount.put("password", passtxt.getText().toString()); Log.i(TAG, "myaccount username: " + myaccount.get("name") + " password: " + myaccount.get("password")); dialog.dismiss(); mainActivity.stop(); // saveAccountDetails(); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } loginFromDialog = true; // mainActivity.refresh(); Common.keypassword(ctx); } }); dialog.show(); // Common.confChanged = false; // }//while(true); }
From source file:de.mkrtchyan.recoverytools.RecoveryTools.java
public void createBackup(final boolean RecoveryBackup) { String prefix;/* ww w . j a va2s.c om*/ String CurrentName; String EXT; if (RecoveryBackup) { prefix = "recovery"; EXT = mDevice.getRecoveryExt(); CurrentName = mDevice.getRecoveryVersion(); } else { prefix = "kernel"; EXT = mDevice.getKernelExt(); CurrentName = mDevice.getKernelVersion(); } final Dialog dialog = new Dialog(mContext); dialog.setTitle(R.string.setname); dialog.setContentView(R.layout.dialog_input); final Button bGoBackup = (Button) dialog.findViewById(R.id.bGoBackup); final EditText etFileName = (EditText) dialog.findViewById(R.id.etFileName); final CheckBox optName = (CheckBox) dialog.findViewById(R.id.cbOptInput); final String NameHint = prefix + "-from-" + Calendar.getInstance().get(Calendar.DATE) + "-" + Calendar.getInstance().get(Calendar.MONTH) + "-" + Calendar.getInstance().get(Calendar.YEAR) + "-" + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE) + EXT; optName.setText(CurrentName); optName.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { etFileName.setEnabled(!optName.isChecked()); } }); etFileName.setHint(NameHint); bGoBackup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String EXT; File Path; final int JOB; if (RecoveryBackup) { EXT = mDevice.getRecoveryExt(); Path = PathToRecoveryBackups; JOB = FlashUtil.JOB_BACKUP_RECOVERY; } else { EXT = mDevice.getKernelExt(); Path = PathToKernelBackups; JOB = FlashUtil.JOB_BACKUP_KERNEL; } String Name = ""; if (optName.isChecked()) { Name = optName.getText().toString() + EXT; } else { if (etFileName.getText() != null && !etFileName.getText().toString().equals("")) { Name = etFileName.getText().toString(); } if (Name.equals("")) { Name = String.valueOf(etFileName.getHint()); } if (!Name.endsWith(EXT)) { Name = Name + EXT; } } final File fBACKUP = new File(Path, Name); Runnable rBackup = new Runnable() { @Override public void run() { FlashUtil BackupCreator = new FlashUtil(mShell, mContext, mDevice, fBACKUP, JOB); BackupCreator.setRunAtEnd(ReloadBackupDrawer); BackupCreator.execute(); } }; if (fBACKUP.exists()) { Toast.makeText(mContext, R.string.backupalready, Toast.LENGTH_SHORT).show(); } else { rBackup.run(); } dialog.dismiss(); } }); dialog.show(); }
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) *///w w w. ja va 2s .co 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; }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to allow user to add an app to a row. The user can add the * app to an existing row or a new row./* w ww. j a va2 s . c om*/ * * @param context * @param applications */ public static void displayAddApps(final Launcher context, final ArrayList<ApplicationInfo> applications) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.add_apps_grid); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); } }); final GridView gridView = (GridView) dialog.findViewById(R.id.grid); gridView.setAdapter(new AllItemAdapter(context, getApplications(context, applications, true))); gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // if the new row radio button is selected, the user must enter // a name for the new row String name = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && name.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position); boolean currentRow = !newRadioButton.isChecked(); context.addItem(itemInfo, currentRow ? null : name); context.showCover(false); dialog.dismiss(); if (currentRow) { Analytics.logEvent(Analytics.DIALOG_ADD_APP); } else { Analytics.logEvent(Analytics.ADD_APP_WITH_ROW); } } }); gridView.setDrawingCacheEnabled(true); gridView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_APP); }
From source file:com.pimp.companionforband.activities.main.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sContext = getApplicationContext();/*w w w . j a v a2 s. co m*/ sActivity = this; sharedPreferences = getApplicationContext().getSharedPreferences("MyPrefs", 0); editor = sharedPreferences.edit(); bandSensorData = new BandSensorData(); mDestinationUri = Uri.fromFile(new File(getCacheDir(), SAMPLE_CROPPED_IMAGE_NAME)); SectionsPagerAdapter mSectionsPagerAdapter; ViewPager mViewPager; if (!checkCameraPermission(true)) requestCameraPermission(true); if (!checkCameraPermission(false)) requestCameraPermission(false); FiveStarsDialog fiveStarsDialog = new FiveStarsDialog(this, "pimplay69@gmail.com"); fiveStarsDialog.setTitle(getString(R.string.rate_dialog_title)) .setRateText(getString(R.string.rate_dialog_text)).setForceMode(false).setUpperBound(4) .setNegativeReviewListener(this).showAfter(5); AnalyticsApplication application = (AnalyticsApplication) getApplication(); mTracker = application.getDefaultTracker(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOffscreenPageLimit(2); mViewPager.setPageTransformer(true, new ZoomOutPageTransformer()); mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { String name; switch (position) { case 0: name = "THEME"; break; case 1: name = "SENSORS"; break; case 2: name = "EXTRAS"; break; default: name = "CfB"; } mTracker.setScreenName("Image~" + name); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); logSwitch = (Switch) findViewById(R.id.log_switch); backgroundLogSwitch = (Switch) findViewById(R.id.backlog_switch); logStatus = (TextView) findViewById(R.id.logStatus); backgroundLogStatus = (TextView) findViewById(R.id.backlogStatus); } @Override public void onPageScrollStateChanged(int state) { } }); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); Drawable headerBackground = null; String encoded = sharedPreferences.getString("me_tile_image", "null"); if (!encoded.equals("null")) { byte[] imageAsBytes = Base64.decode(encoded.getBytes(), Base64.DEFAULT); headerBackground = new BitmapDrawable( BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)); } AccountHeader accountHeader = new AccountHeaderBuilder().withActivity(this).withCompactStyle(true) .withHeaderBackground((headerBackground == null) ? getResources().getDrawable(R.drawable.pipboy) : headerBackground) .addProfiles(new ProfileDrawerItem() .withName(sharedPreferences.getString("device_name", "Companion For Band")) .withEmail(sharedPreferences.getString("device_mac", "pimplay69@gmail.com")) .withIcon(getResources().getDrawable(R.drawable.band))) .build(); result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withActionBarDrawerToggleAnimated(true) .withAccountHeader(accountHeader) .addDrawerItems( new PrimaryDrawerItem().withName(getString(R.string.drawer_cloud)) .withIcon(GoogleMaterial.Icon.gmd_cloud).withIdentifier(1), new DividerDrawerItem(), new PrimaryDrawerItem().withName(getString(R.string.rate)) .withIcon(GoogleMaterial.Icon.gmd_rate_review).withIdentifier(2), new PrimaryDrawerItem().withName(getString(R.string.feedback)) .withIcon(GoogleMaterial.Icon.gmd_feedback).withIdentifier(3), new DividerDrawerItem(), new PrimaryDrawerItem().withName(getString(R.string.share)) .withIcon(GoogleMaterial.Icon.gmd_share).withIdentifier(4), new PrimaryDrawerItem().withName(getString(R.string.other)) .withIcon(GoogleMaterial.Icon.gmd_apps).withIdentifier(5), new DividerDrawerItem(), new PrimaryDrawerItem().withName(getString(R.string.report)) .withIcon(GoogleMaterial.Icon.gmd_bug_report).withIdentifier(6), new PrimaryDrawerItem().withName(getString(R.string.translate)) .withIcon(GoogleMaterial.Icon.gmd_translate).withIdentifier(9), new DividerDrawerItem(), new PrimaryDrawerItem().withName(getString(R.string.support)) .withIcon(GoogleMaterial.Icon.gmd_attach_money).withIdentifier(7), new PrimaryDrawerItem().withName(getString(R.string.aboutLib)) .withIcon(GoogleMaterial.Icon.gmd_info).withIdentifier(8)) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { boolean flag; if (drawerItem != null) { flag = true; switch ((int) drawerItem.getIdentifier()) { case 1: mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction("Cloud").build()); if (!sharedPreferences.getString("access_token", "hi").equals("hi")) startActivity(new Intent(getApplicationContext(), CloudActivity.class)); else startActivity(new Intent(getApplicationContext(), WebviewActivity.class)); break; case 2: mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction("Rate and Review").build()); String MARKET_URL = "https://play.google.com/store/apps/details?id="; String PlayStoreListing = getPackageName(); Intent rate = new Intent(Intent.ACTION_VIEW, Uri.parse(MARKET_URL + PlayStoreListing)); startActivity(rate); break; case 3: mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction("Feedback").build()); final StringBuilder emailBuilder = new StringBuilder(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:pimplay69@gmail.com")); intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.app_name)); emailBuilder.append("\n \n \nOS Version: ").append(System.getProperty("os.version")) .append("(").append(Build.VERSION.INCREMENTAL).append(")"); emailBuilder.append("\nOS API Level: ").append(Build.VERSION.SDK_INT); emailBuilder.append("\nDevice: ").append(Build.DEVICE); emailBuilder.append("\nManufacturer: ").append(Build.MANUFACTURER); emailBuilder.append("\nModel (and Product): ").append(Build.MODEL).append(" (") .append(Build.PRODUCT).append(")"); PackageInfo appInfo = null; try { appInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } assert appInfo != null; emailBuilder.append("\nApp Version Name: ").append(appInfo.versionName); emailBuilder.append("\nApp Version Code: ").append(appInfo.versionCode); intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString()); startActivity(Intent.createChooser(intent, "Send via")); break; case 4: mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction("Share").build()); Intent i = new AppInviteInvitation.IntentBuilder( getString(R.string.invitation_title)) .setMessage(getString(R.string.invitation_message)) .setCallToActionText(getString(R.string.invitation_cta)).build(); startActivityForResult(i, REQUEST_INVITE); break; case 5: mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction("Other Apps").build()); String PlayStoreDevAccount = "https://play.google.com/store/apps/developer?id=P.I.M.P."; Intent devPlay = new Intent(Intent.ACTION_VIEW, Uri.parse(PlayStoreDevAccount)); startActivity(devPlay); break; case 6: mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction("Report Bugs").build()); startActivity(new Intent(MainActivity.this, GittyActivity.class)); break; case 7: mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction("Donate").build()); String base64EncodedPublicKey = getString(R.string.base64); mHelper = new IabHelper(getApplicationContext(), base64EncodedPublicKey); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { Toast.makeText(MainActivity.this, "Problem setting up In-app Billing: " + result, Toast.LENGTH_LONG).show(); } } }); final Dialog dialog = new Dialog(MainActivity.this); dialog.setContentView(R.layout.dialog_donate); dialog.setTitle("Donate"); String[] title = { "Coke", "Coffee", "Burger", "Pizza", "Meal" }; String[] price = { "Rs. 10.00", "Rs. 50.00", "Rs. 100.00", "Rs. 500.00", "Rs. 1,000.00" }; ListView listView = (ListView) dialog.findViewById(R.id.list); listView.setAdapter(new DonateListAdapter(MainActivity.this, title, price)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: mHelper.launchPurchaseFlow(MainActivity.this, SKU_COKE, 1, mPurchaseFinishedListener, "payload"); break; case 1: mHelper.launchPurchaseFlow(MainActivity.this, SKU_COFFEE, 1, mPurchaseFinishedListener, "payload"); break; case 2: mHelper.launchPurchaseFlow(MainActivity.this, SKU_BURGER, 1, mPurchaseFinishedListener, "payload"); break; case 3: mHelper.launchPurchaseFlow(MainActivity.this, SKU_PIZZA, 1, mPurchaseFinishedListener, "payload"); break; case 4: mHelper.launchPurchaseFlow(MainActivity.this, SKU_MEAL, 1, mPurchaseFinishedListener, "payload"); break; } } }); dialog.show(); break; case 8: mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction("About").build()); new LibsBuilder().withLicenseShown(true).withVersionShown(true) .withActivityStyle(Libs.ActivityStyle.DARK).withAboutVersionShown(true) .withActivityTitle(getString(R.string.app_name)).withAboutIconShown(true) .withListener(libsListener).start(MainActivity.this); break; case 9: mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction("Translate").build()); Intent translate = new Intent(Intent.ACTION_VIEW, Uri.parse("https://poeditor.com/join/project/AZQxDV2440")); startActivity(translate); break; default: break; } } else { flag = false; } return flag; } }).withSavedInstance(savedInstanceState).build(); AppUpdater appUpdater = new AppUpdater(this); appUpdater.start(); final DirectoryChooserConfig config = DirectoryChooserConfig.builder() .allowNewDirectoryNameModification(true).newDirectoryName("CfBCamera") .initialDirectory( sharedPreferences.getString("pic_location", "/storage/emulated/0/CompanionForBand/Camera")) .build(); mDialog = DirectoryChooserFragment.newInstance(config); new BandUtils().execute(); CustomActivityOnCrash.install(this); }