List of usage examples for android.view KeyEvent KEYCODE_ENTER
int KEYCODE_ENTER
To view the source code for android.view KeyEvent KEYCODE_ENTER.
Click Source Link
From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java
/** * For keyboard mode, processes key events. * * @param keyCode the pressed key./*from w ww. jav a 2 s. co m*/ * @return true if the key was successfully processed, false otherwise. */ private boolean processKeyUp(int keyCode) { if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) { dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_TAB) { if (mInKbMode) { if (isTypedTimeFullyLegal()) { finishKbMode(true); } return true; } } else if (keyCode == KeyEvent.KEYCODE_ENTER) { if (mInKbMode) { if (!isTypedTimeFullyLegal()) { return true; } finishKbMode(false); } doneClickValidateAndCallback(); return true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { if (mInKbMode) { if (!mTypedTimes.isEmpty()) { int deleted = deleteLastTypedKey(); String deletedKeyStr; if (deleted == getAmOrPmKeyCode(AM)) { deletedKeyStr = mAmText; } else if (deleted == getAmOrPmKeyCode(PM)) { deletedKeyStr = mPmText; } else { deletedKeyStr = String.format("%d", getValFromKeyCode(deleted)); } Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr)); updateDisplay(true); } } } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5 || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9 || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) { if (!mInKbMode) { if (mTimePicker == null) { // Something's wrong, because time picker should definitely not be null. Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null."); return true; } mTypedTimes.clear(); tryStartingKbMode(keyCode); return true; } // We're already in keyboard mode. if (addKeyIfLegal(keyCode)) { updateDisplay(false); } return true; } return false; }
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 ava 2s. 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; }
From source file:com.sentaroh.android.Utilities.Dialog.FileSelectDialogFragment.java
private void initViewWidget() { if (mDebugEnable) Log.v(APPLICATION_TAG, "initViewWidget"); if (mDebugEnable) Log.v(APPLICATION_TAG, "Create=" + mDialogEnableCreate + ", Title=" + mDialogTitle + ", lurl=" + mDialogLocalUrl + ", ldir=" + mDialogLocalDir + ", file name=" + mDialogFileName); mThemeColorList = ThemeUtil.getThemeColorList(getActivity()); mDialog.setContentView(R.layout.file_select_edit_dlg); LinearLayout title_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_title_view); title_view.setBackgroundColor(mThemeColorList.dialog_title_background_color); TextView title = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_title); title.setTextColor(mThemeColorList.text_color_dialog_title); title.setText(mDialogTitle);/* w ww. j a v a2 s .c o m*/ final TextView dlg_msg = (TextView) mDialog.findViewById(R.id.file_select_edit_dlg_msg); final Button btnHome = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_home_dir_btn); btnHome.setTextColor(mThemeColorList.text_color_primary); btnHome.setVisibility(Button.VISIBLE); final Button btnCreate = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_create_btn); btnCreate.setTextColor(mThemeColorList.text_color_primary); final Button btnOk = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_ok_btn); // btnOk.setTextColor(mThemeColorList.text_color_primary); final Button btnCancel = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_cancel_btn); btnCancel.setTextColor(mThemeColorList.text_color_primary); final Button btnRefresh = (Button) mDialog.findViewById(R.id.file_select_edit_dlg_refresh_btn); btnRefresh.setTextColor(mThemeColorList.text_color_primary); LinearLayout ll_dlg_view = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_view); ll_dlg_view.setBackgroundColor(mThemeColorList.dialog_msg_background_color); final Activity activity = getActivity(); final Context context = activity.getApplicationContext(); if (mDialogEnableCreate) { btnCreate.setVisibility(TextView.VISIBLE); } mLocalMountPointSpinner = (Spinner) mDialog.findViewById(R.id.file_select_edit_dlg_rdir); setSpinnerBackground(context, mLocalMountPointSpinner, mThemeColorList.theme_is_light); mLocalMountPointSpinner.setVisibility(Spinner.VISIBLE); // Root directory spinner CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(activity, R.layout.custom_simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLocalMountPointSpinner.setPrompt(context.getString(R.string.msgs_file_select_edit_local_mount_point)); mLocalMountPointSpinner.setAdapter(adapter); int a_no = -1; ArrayList<String> ml = LocalMountPoint.getLocalMountPointList(context); mLocalMountPointSpinner.setOnItemSelectedListener(null); if (mDialogMpLimitInternalAndSdcard) { adapter.add(Environment.getExternalStorageDirectory().toString()); File[] fl = ContextCompat.getExternalFilesDirs(context, null); for (File item : fl) { if (!item.getPath().startsWith(Environment.getExternalStorageDirectory().toString())) { adapter.add(item.getPath().substring(0, item.getPath().indexOf("/Android"))); break; } } mLocalMountPointSpinner.setEnabled(true); for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).equals(mDialogLocalUrl)) { a_no = i; break; } } mLocalMountPointSpinner.setSelection(a_no); } else { if (ml.size() == 0) { if (mDialogIncludeRoot) adapter.add("/"); adapter.add(mDialogLocalUrl); mLocalMountPointSpinner.setEnabled(false); } else { mLocalMountPointSpinner.setEnabled(true); if (mDialogIncludeRoot) adapter.add("/"); for (int i = 0; i < ml.size(); i++) adapter.add(ml.get(i)); for (int i = 0; i < ml.size(); i++) { if (mDialogLocalUrl.startsWith(ml.get(i))) { a_no = i; break; } } mLocalMountPointSpinner.setSelection(a_no); } } LinearLayout ll_mp = (LinearLayout) mDialog.findViewById(R.id.file_select_edit_dlg_mp_view); if (mDialogHideMp) ll_mp.setVisibility(LinearLayout.GONE); else ll_mp.setVisibility(LinearLayout.VISIBLE); // ll_mp.setVisibility(LinearLayout.GONE); // final TextView v_spacer=(TextView)mDialog.findViewById(R.id.file_select_edit_dlg_spacer); mTreeFileListView = (ListView) mDialog.findViewById(android.R.id.list); final CustomTextView dir_name = (CustomTextView) mDialog.findViewById(R.id.file_select_edit_dlg_dir_name); dir_name.setTextColor(mThemeColorList.text_color_primary); final EditText file_name = (EditText) mDialog.findViewById(R.id.file_select_edit_dlg_file_name); if (!mDialogSingleSelect) file_name.setVisibility(EditText.GONE); else file_name.setVisibility(EditText.VISIBLE); if (mDialogFileOnly) { file_name.setVisibility(EditText.VISIBLE); file_name.setEnabled(true); dir_name.setVisibility(EditText.VISIBLE); } else { if (mDialogDirectoryOnly) { file_name.setVisibility(EditText.GONE); file_name.setEnabled(false); dir_name.setVisibility(EditText.VISIBLE); btnHome.setVisibility(EditText.VISIBLE); } else { file_name.setVisibility(EditText.VISIBLE); file_name.setEnabled(true); dir_name.setVisibility(EditText.VISIBLE); btnHome.setVisibility(EditText.VISIBLE); } } file_name.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View arg0, int keyCode, KeyEvent event) { if (//event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { return true; } return false; } }); // if (dirs.size()<=2) v_spacer.setVisibility(TextView.VISIBLE); mTreeFilelistAdapter = new TreeFilelistAdapter(activity, mDialogSingleSelect, true); mTreeFileListView.setAdapter(mTreeFilelistAdapter); if (mDialogLocalUrl.equals("")) mDialogLocalUrl = ml.get(0); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mDialogLocalUrl, ""); if (tfl.size() == 0) { tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty))); } else { mTreeFilelistAdapter.setDataList(tfl); if (!mDialogLocalDir.equals("")) { String sel_dir = mDialogLocalDir; String n_dir = "", e_dir = ""; if (sel_dir.startsWith("/")) n_dir = sel_dir.substring(1); else n_dir = sel_dir; if (n_dir.endsWith("/")) e_dir = n_dir.substring(0, n_dir.length() - 1); else e_dir = n_dir; // Log.v("","mp="+mDialogLocalUrl+", se;_dir="+sel_dir+", e_dir="+e_dir); selectLocalDirTree(e_dir); } if (!mDialogFileName.equals("")) selectLocalDirTreeFile(mDialogFileName); } mTreeFileListView.setScrollingCacheEnabled(false); mTreeFileListView.setScrollbarFadingEnabled(false); if (mSavedViewContentsValue != null && mSavedViewContentsValue.mainDialogFilename != null) { file_name.setText(mSavedViewContentsValue.mainDialogFilename); file_name.setSelection(mSavedViewContentsValue.mainDialogFilenameSelStart, mSavedViewContentsValue.mainDialogFilenameTextSelEnd); dir_name.setText(mSavedViewContentsValue.mainDialogDirName); } else { String d_name = mDialogLocalDir.equals("") ? mDialogLocalUrl + "/" : mDialogLocalUrl + mDialogLocalDir + "/"; dir_name.setText(d_name); file_name.setText(mDialogFileName); } if (!mDialogSingleSelect) btnOk.setEnabled(false); NotifyEvent cb_ntfy = new NotifyEvent(context); // set file list thread response listener cb_ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { int p = (Integer) o[0]; boolean p_chk = (Boolean) o[1]; String turl = (String) mLocalMountPointSpinner.getSelectedItem(); if (mDialogSingleSelect) { if (mTreeFilelistAdapter.getDataItem(p).isChecked() && !p_chk) { if (p != -1) { if (mTreeFilelistAdapter.getDataItem(p).isChecked()) { if (mTreeFilelistAdapter.getDataItem(p).isDir()) { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath() + mTreeFilelistAdapter.getDataItem(p).getName() + "/"); // file_name.setText(""); } else { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()); file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName()); } } } } if (mDialogFileOnly) { if (file_name.getText().length() > 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } } else { if (mTreeFilelistAdapter.isDataItemIsSelected() || file_name.getText().length() > 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_directory_not_selected)); btnOk.setEnabled(false); } } } else { if (mTreeFilelistAdapter.getDataItem(p).isDir()) { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath() + mTreeFilelistAdapter.getDataItem(p).getName() + "/"); // file_name.setText(""); } else { dir_name.setText(turl + mTreeFilelistAdapter.getDataItem(p).getPath()); file_name.setText(mTreeFilelistAdapter.getDataItem(p).getName()); } putDlgMsg(dlg_msg, ""); btnOk.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { boolean checked = false; // int p=(Integer) o[0]; boolean p_chk = (Boolean) o[1]; if (mDialogSingleSelect) { if (p_chk) { for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) { if (mTreeFilelistAdapter.getDataItem(i).isChecked()) { checked = true; break; } } if (checked) btnOk.setEnabled(true); else btnOk.setEnabled(false); } } else { // Log.v("","sel="+p_chk); btnOk.setEnabled(false); for (int i = 0; i < mTreeFilelistAdapter.getDataItemCount(); i++) { if (mTreeFilelistAdapter.getDataItem(i).isChecked()) { btnOk.setEnabled(true); break; } } } } }); mTreeFilelistAdapter.setCbCheckListener(cb_ntfy); if (mDialogLocalUrl.equals(file_name.getText().toString())) btnOk.setEnabled(false); if (mDialogFileOnly && mDialogFileName.equals("")) { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } file_name.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { if (mDialogSingleSelect) { if (s.length() != 0) { btnOk.setEnabled(true); putDlgMsg(dlg_msg, ""); } else { btnOk.setEnabled(false); putDlgMsg(dlg_msg, context.getString(R.string.msgs_file_select_edit_dlg_filename_not_specified)); } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); NotifyEvent ntfy_expand_close = new NotifyEvent(context); ntfy_expand_close.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { int idx = (Integer) o[0]; final int pos = mTreeFilelistAdapter.getItem(idx); final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos); if (tfi.getName().startsWith("---")) return; String turl = (String) mLocalMountPointSpinner.getSelectedItem(); if (tfi.isDir()) processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter); else { mTreeFilelistAdapter.setDataItemIsSelected(pos); dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath())); file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName()); if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly) btnOk.setEnabled(false); else btnOk.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { } }); mTreeFilelistAdapter.setExpandCloseListener(ntfy_expand_close); mTreeFileListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> items, View view, int idx, long id) { final int pos = mTreeFilelistAdapter.getItem(idx); final TreeFilelistItem tfi = mTreeFilelistAdapter.getDataItem(pos); if (tfi.getName().startsWith("---")) return; String turl = (String) mLocalMountPointSpinner.getSelectedItem(); if (tfi.isDir()) processLocalDirTree(mDialogFileOnly, turl, pos, tfi, mTreeFilelistAdapter); else { mTreeFilelistAdapter.setDataItemIsSelected(pos); dir_name.setText((turl + mTreeFilelistAdapter.getDataItem(pos).getPath())); file_name.setText(mTreeFilelistAdapter.getDataItem(pos).getName()); if (mTreeFilelistAdapter.getDataItem(pos).isDir() && mDialogFileOnly) btnOk.setEnabled(false); else btnOk.setEnabled(true); } } }); mTreeFileListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) { return true; } }); btnHome.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dir_name.setText(mLocalMountPointSpinner.getSelectedItem().toString() + "/"); } }); //Create button btnCreate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { NotifyEvent ntfy = new NotifyEvent(context); // set file list thread response listener ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { // btnRefresh.performClick(); } @Override public void negativeResponse(Context c, Object[] o) { } }); fileSelectEditDialogCreateBtn(activity, context, dir_name.getText().substring(0, dir_name.getText().length() - 1), "", mLocalMountPointSpinner.getSelectedItem().toString(), mTreeFilelistAdapter, ntfy, mTreeFileListView); } }); //Refresh button btnRefresh.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String mp = mLocalMountPointSpinner.getSelectedItem().toString(); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, mp, "");//mDialogLocalUrl,""); if (tfl.size() < 1) tfl.add(new TreeFilelistItem(context.getString(R.string.msgs_file_select_edit_dir_empty))); mTreeFilelistAdapter.setDataList(tfl); } }); //OK button // btnOk.setEnabled(false); btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (mDialogSingleSelect) { String[] sl_array = new String[] { dir_name.getText() + file_name.getText().toString() }; if (mNotifyEvent != null) mNotifyEvent.notifyToListener(true, sl_array); } else { ArrayList<String> sl = new ArrayList<String>(); ArrayList<TreeFilelistItem> tfl = mTreeFilelistAdapter.getDataList(); for (TreeFilelistItem li : tfl) { if (li.isChecked()) { if (li.isDir()) sl.add(li.getPath() + li.getName()); else sl.add(li.getPath() + li.getName()); } } String[] sl_array = new String[sl.size()]; String mp = mLocalMountPointSpinner.getSelectedItem().toString(); for (int i = 0; i < sl.size(); i++) { if (mDialogSelectedFilePathWithMountPoint) sl_array[i] = mp + sl.get(i); else sl_array[i] = sl.get(i); // Log.v("","sel="+sl_array[i]); } if (mNotifyEvent != null) mNotifyEvent.notifyToListener(true, sl_array); } // mDialog.dismiss(); mFragment.dismiss(); } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // mDialog.dismiss(); mFragment.dismiss(); if (mNotifyEvent != null) mNotifyEvent.notifyToListener(false, null); } }); Handler hndl = new Handler(); hndl.postDelayed(new Runnable() { @Override public void run() { mLocalMountPointSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Log.v("","MP selected="+position); Spinner spinner = (Spinner) parent; String turl = (String) spinner.getSelectedItem(); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(mDialogFileOnly, turl, ""); if (tfl.size() < 1) tfl.add(new TreeFilelistItem( context.getString(R.string.msgs_file_select_edit_dir_empty))); mTreeFilelistAdapter.setDataList(tfl); mTreeFilelistAdapter.notifyDataSetChanged(); if (turl.startsWith(mSafFileMgr.getExternalSdcardPath())) { if (mSafFileMgr.getSdcardSafFile() == null) btnCreate.setEnabled(false); else btnCreate.setEnabled(true); } else btnCreate.setEnabled(true); dir_name.setText(turl + "/"); Handler hndl_sel = new Handler(); hndl_sel.post(new Runnable() { @Override public void run() { mTreeFileListView.setSelection(0); } }); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); } }, 100); }
From source file:com.googlecode.eyesfree.brailleback.IMENavigationModeTest.java
/** * Tests the behaviour of the "modal editor" mode. *//*from w ww . j a v a 2 s.co m*/ public void testModalEditorMode() { mIMENavMode.onActivate(); verify(mNext).onActivate(); EditorInfo ei = new EditorInfo(); // Mock out the AccessibilityNodeInfo. // The class actually uses the compat variant, but on recent API // releases (including the test environment) they should call through. AccessibilityNodeInfo rawNode = mock(AccessibilityNodeInfo.class); when(mAccessibilityService.getRootInActiveWindow()).thenReturn(rawNode); when(rawNode.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY)).thenReturn(rawNode); when(rawNode.getClassName()).thenReturn(EditText.class.getName()); when(rawNode.isFocused()).thenReturn(true); mIMENavMode.onCreateIME(); mIMENavMode.onBindInput(); mIMENavMode.onStartInput(ei, false /* restarting */); mIMENavMode.onStartInputView(ei, false /* restarting */); verify(mNext, times(1)).onDeactivate(); assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator()); assertEquals(mDisplayManager, mIMENavMode.getDisplayManager()); assertEquals(mFeedbackManager, mIMENavMode.getFeedbackManager()); AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain(); try { mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext).onObserveAccessibilityEvent(accessibilityEvent); } finally { accessibilityEvent.recycle(); } accessibilityEvent = AccessibilityEvent.obtain(); try { mIMENavMode.onAccessibilityEvent(accessibilityEvent); verify(mNext, never()).onAccessibilityEvent(accessibilityEvent); } finally { accessibilityEvent.recycle(); } AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain(); try { mIMENavMode.onInvalidateAccessibilityNode(node); verify(mNext, never()).onInvalidateAccessibilityNode(node); } finally { node.recycle(); } // Move input focus away and back again. when(rawNode.isFocused()).thenReturn(false); accessibilityEvent = AccessibilityEvent.obtain(); accessibilityEvent.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED); try { mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext, times(2)).onActivate(); when(rawNode.isFocused()).thenReturn(true); mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent); verify(mNext, times(2)).onDeactivate(); } finally { accessibilityEvent.recycle(); } DisplayManager.Content content = new DisplayManager.Content(""); mIMENavMode.onPanLeftOverflow(content); verify(mNext).onPanLeftOverflow(content); mIMENavMode.onPanRightOverflow(content); verify(mNext).onPanRightOverflow(content); BrailleInputEvent inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_ENTER, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_ENTER); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_DEL, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_DEL); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_BRAILLE_KEY, 0x1b, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).handleBrailleKey(0x1b); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_NAV_ITEM_NEXT, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).moveCursor(BrailleIME.DIRECTION_FORWARD, AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ACTIVATE_CURRENT, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).sendDefaultAction(); inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ROUTE, 0, 0); mIMENavMode.onMappedInputEvent(inputEvent, content); verify(mNext, never()).onMappedInputEvent(inputEvent, content); verify(mIME).route(0, content); // Finishing and unbinding the input should activate the next nav mode // again. mIMENavMode.onFinishInputView(true); mIMENavMode.onFinishInput(); mIMENavMode.onUnbindInput(); verify(mNext, times(3)).onActivate(); mIMENavMode.onDestroyIME(); // Deactivate, but make sure it didn't happen too early. verify(mNext, times(2)).onDeactivate(); mIMENavMode.onDeactivate(); verify(mNext, times(3)).onDeactivate(); }
From source file:com.jamiealtizer.cordova.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/*from w w w. j a v a 2 s . co m*/ */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; showZoomControls = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean zoom = features.get(ZOOM); if (zoom != null) { showZoomControls = zoom.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON); if (hardwareBack != null) { hadwareBackButton = hardwareBack.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } @SuppressLint("NewApi") public void run() { // Let's create the main dialog final Context ctx = cordova.getActivity(); dialog = new InAppBrowserDialog(ctx, android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setInAppBroswer(getInAppBrowser()); // Main container layout LinearLayout main = new LinearLayout(ctx); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(ctx); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); // JAMIE REVIEW toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.CENTER_VERTICAL); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(ctx); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button final ButtonAwesome back = new ButtonAwesome(ctx); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); back.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground")); back.setTextColor(ExternalResourceHelper.getColor(ctx, "gray")); back.setText(ExternalResourceHelper.getStrings(ctx, "fa_chevron_left")); back.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); // if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) // { // back.setBackgroundDrawable(backIcon); // } // else // { // back.setBackground(backIcon); // } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button final ButtonAwesome forward = new ButtonAwesome(ctx); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); forward.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground")); forward.setTextColor(ExternalResourceHelper.getColor(ctx, "gray")); forward.setText(ExternalResourceHelper.getStrings(ctx, "fa_chevron_right")); forward.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); // if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) // { // forward.setBackgroundDrawable(fwdIcon); // } // else // { // forward.setBackground(fwdIcon); // } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // external button ButtonAwesome external = new ButtonAwesome(ctx); RelativeLayout.LayoutParams externalLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); externalLayoutParams.addRule(RelativeLayout.RIGHT_OF, 3); external.setLayoutParams(externalLayoutParams); external.setContentDescription("Back Button"); external.setId(7); external.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground")); external.setTextColor(ExternalResourceHelper.getColor(ctx, "white")); external.setText(ExternalResourceHelper.getStrings(ctx, "fa_external_link")); external.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); external.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { openExternal(edittext.getText().toString()); closeDialog(); } }); // Edit Text Box edittext = new EditText(ctx); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { if (s.length() > 0) { if (inAppWebView.canGoBack()) { back.setTextColor(ExternalResourceHelper.getColor(ctx, "white")); } else { back.setTextColor(ExternalResourceHelper.getColor(ctx, "gray")); } if (inAppWebView.canGoForward()) { forward.setTextColor(ExternalResourceHelper.getColor(ctx, "white")); } else { forward.setTextColor(ExternalResourceHelper.getColor(ctx, "gray")); } } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); edittext.setOnKeyListener(new View.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)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close/Done button ButtonAwesome close = new ButtonAwesome(ctx); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); close.setContentDescription("Close Button"); close.setId(5); close.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground")); close.setText(ExternalResourceHelper.getStrings(ctx, "fa_times")); close.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); close.setTextColor(ExternalResourceHelper.getColor(ctx, "white")); // if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) // { // close.setBackgroundDrawable(closeIcon); // } // else // { // close.setBackground(closeIcon); // } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new WebView(ctx); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(showZoomControls); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = ctx.getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE) .getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { CookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { CookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); actionButtonContainer.addView(external); // Add the views to our toolbar toolbar.addView(actionButtonContainer); if (getShowLocationBar()) { toolbar.addView(edittext); } toolbar.setBackgroundColor(ExternalResourceHelper.getColor(ctx, "green")); toolbar.addView(close); // Don't add the toolbar if its been disabled //if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); //} // Add our webview to our main view/layout main.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:info.guardianproject.otr.app.im.app.ChatView.java
@Override protected void onFinishInflate() { // mStatusIcon = (ImageView) findViewById(R.id.statusIcon); // mDeliveryIcon = (ImageView) findViewById(R.id.deliveryIcon); // mTitle = (TextView) findViewById(R.id.title); mHistory = (ListView) findViewById(R.id.history); mComposeMessage = (EditText) findViewById(R.id.composeMessage); mSendButton = (ImageButton) findViewById(R.id.btnSend); mHistory.setOnItemClickListener(mOnItemClickListener); mButtonAttach = (ImageButton) findViewById(R.id.btnAttach); mViewAttach = findViewById(R.id.attachPanel); mStatusWarningView = findViewById(R.id.warning); mWarningText = (TextView) findViewById(R.id.warningText); mProgressTransfer = (ProgressBar) findViewById(R.id.progressTransfer); // mOtrSwitch = (CompoundButton)findViewById(R.id.otrSwitch); mProgressBarOtr = (ProgressBar) findViewById(R.id.progressBarOtr); mButtonAttach.setOnClickListener(new OnClickListener() { @Override//w ww .j a v a 2s .c o m public void onClick(View v) { if (mViewAttach.getVisibility() == View.GONE) mViewAttach.setVisibility(View.VISIBLE); else mViewAttach.setVisibility(View.GONE); } }); ((ImageButton) findViewById(R.id.btnAttachAudio)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.startAudioPicker(); } }); ((ImageButton) findViewById(R.id.btnAttachPicture)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.startImagePicker(); } }); ((ImageButton) findViewById(R.id.btnTakePicture)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.startPhotoTaker(); } }); ((ImageButton) findViewById(R.id.btnAttachFile)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.startFilePicker(); } }); mHistory.setOnItemLongClickListener(new OnItemLongClickListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { if (arg1 instanceof MessageView) { String textToCopy = ((MessageView) arg1).getLastMessage(); int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mNewChatActivity .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(textToCopy); // } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mNewChatActivity .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("chat", textToCopy); clipboard.setPrimaryClip(clip); // } Toast.makeText(mNewChatActivity, mContext.getString(R.string.toast_chat_copied_to_clipboard), Toast.LENGTH_SHORT).show(); return true; } return false; } }); mWarningText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showVerifyDialog(); } }); //mOtrSwitch.setOnCheckedChangeListener(mOtrListener); mComposeMessage.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: sendMessage(); return true; case KeyEvent.KEYCODE_ENTER: if (event.isAltPressed()) { mComposeMessage.append("\n"); return true; } } } return false; } }); mComposeMessage.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null) { if (event.isAltPressed()) { return false; } } InputMethodManager imm = (InputMethodManager) mContext .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null && imm.isActive(v)) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } sendMessage(); return true; } }); // TODO: this is a hack to implement BUG #1611278, when dispatchKeyEvent() works with // the soft keyboard, we should remove this hack. mComposeMessage.addTextChangedListener(new TextWatcher() { public void beforeTextChanged(CharSequence s, int start, int before, int after) { } public void onTextChanged(CharSequence s, int start, int before, int after) { //log("TextWatcher: " + s); userActionDetected(); } public void afterTextChanged(Editable s) { } }); mSendButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { sendMessage(); } }); Button btnApproveSubscription = (Button) findViewById(R.id.btnApproveSubscription); btnApproveSubscription.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mNewChatActivity.approveSubscription(mProviderId, mRemoteAddress); mHandler.postDelayed(new Runnable() { public void run() { bindChat(mLastChatId); } }, 2000); } }); Button btnDeclineSubscription = (Button) findViewById(R.id.btnDeclineSubscription); btnDeclineSubscription.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mHandler.postDelayed(new Runnable() { public void run() { mNewChatActivity.declineSubscription(mProviderId, mRemoteAddress); } }, 500); } }); /* mActionBox = (View)findViewById(R.id.actionBox); ImageButton btnActionBox = (ImageButton)findViewById(R.id.btnActionBox); btnActionBox.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { mEmojiPager.setVisibility(View.GONE); if (mActionBox.getVisibility() == View.GONE) mActionBox.setVisibility(View.VISIBLE); else mActionBox.setVisibility(View.GONE); } }); View btnEndChat = findViewById(R.id.btnEndChat); btnEndChat.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { ChatView.this.closeChatSession(); } }); View btnProfile = findViewById(R.id.btnProfile); btnProfile.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { viewProfile(); } }); View btnSharePicture = findViewById(R.id.btnSendPicture); btnSharePicture.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { if (mLastSessionStatus != null && mLastSessionStatus == SessionStatus.ENCRYPTED) { mNewChatActivity.startImagePicker(); } else { mHandler.showServiceErrorAlert(getContext().getString(R.string.please_enable_chat_encryption_to_share_files)); } } }); View btnShareFile = findViewById(R.id.btnSendFile); btnShareFile.setOnClickListener(new OnClickListener () { @Override public void onClick(View v) { if (mLastSessionStatus != null && mLastSessionStatus == SessionStatus.ENCRYPTED) { mNewChatActivity.startFilePicker(); } else { mHandler.showServiceErrorAlert(getContext().getString(R.string.please_enable_chat_encryption_to_share_files)); } } }); */ initEmoji(); mMessageAdapter = new MessageAdapter(mNewChatActivity, null); mHistory.setAdapter(mMessageAdapter); }
From source file:info.bartowski.easteregg.MLand.java
@Override public boolean onKeyDown(int keyCode, KeyEvent ev) { L("keyDown: %d", keyCode); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_SPACE: case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_BUTTON_A: int player = getControllerPlayer(ev.getDeviceId()); poke(player);//from w w w .j ava2s. c om return true; } return false; }
From source file:org.telegram.ui.ChatActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (fragmentView == null) { fragmentView = inflater.inflate(R.layout.chat_layout, container, false); sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout) fragmentView.findViewById(R.id.chat_layout); sizeNotifierRelativeLayout.delegate = this; contentView = sizeNotifierRelativeLayout; emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView); chatListView = (LayoutListView) fragmentView.findViewById(R.id.chat_list_view); chatListView.setAdapter(chatAdapter = new ChatAdapter(parentActivity)); topPanel = fragmentView.findViewById(R.id.top_panel); topPlaneClose = (ImageView) fragmentView.findViewById(R.id.top_plane_close); topPanelText = (TextView) fragmentView.findViewById(R.id.top_panel_text); bottomOverlay = fragmentView.findViewById(R.id.bottom_overlay); bottomOverlayText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_text); View bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat); progressView = fragmentView.findViewById(R.id.progressLayout); pagedownButton = fragmentView.findViewById(R.id.pagedown_button); audioSendButton = (ImageButton) fragmentView.findViewById(R.id.chat_audio_send_button); View progressViewInner = progressView.findViewById(R.id.progressLayoutInner); updateContactStatus();// w w w. jav a2 s . c o m ImageView backgroundImage = (ImageView) fragmentView.findViewById(R.id.background_image); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); int selectedColor = preferences.getInt("selectedColor", 0); if (selectedColor != 0) { backgroundImage.setBackgroundColor(selectedColor); chatListView.setCacheColorHint(selectedColor); } else { chatListView.setCacheColorHint(0); if (selectedBackground == 1000001) { backgroundImage.setImageResource(R.drawable.background_hd); } else { File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); if (toFile.exists()) { if (ApplicationLoader.cachedWallpaper != null) { backgroundImage.setImageBitmap(ApplicationLoader.cachedWallpaper); } else { backgroundImage.setImageURI(Uri.fromFile(toFile)); if (backgroundImage.getDrawable() instanceof BitmapDrawable) { ApplicationLoader.cachedWallpaper = ((BitmapDrawable) backgroundImage.getDrawable()) .getBitmap(); } } isCustomTheme = true; } else { backgroundImage.setImageResource(R.drawable.background_hd); } } } if (currentEncryptedChat != null) { secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder); if (isCustomTheme) { secretChatPlaceholder.setBackgroundResource(R.drawable.system_black); } else { secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue); } secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text); secretChatPlaceholder.setPadding(Utilities.dp(16), Utilities.dp(12), Utilities.dp(16), Utilities.dp(12)); View v = contentView.findViewById(R.id.secret_placeholder); v.setVisibility(View.VISIBLE); if (currentEncryptedChat.admin_id == UserConfig.clientUserId) { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(String.format(getStringEntry(R.string.EncryptedPlaceholderTitleOutgoing), currentUser.first_name)); } else { secretViewStatusTextView.setText(String.format( getStringEntry(R.string.EncryptedPlaceholderTitleOutgoing), currentUser.last_name)); } } else { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(String.format(getStringEntry(R.string.EncryptedPlaceholderTitleIncoming), currentUser.first_name)); } else { secretViewStatusTextView.setText(String.format( getStringEntry(R.string.EncryptedPlaceholderTitleIncoming), currentUser.last_name)); } } updateSecretStatus(); } if (isCustomTheme) { progressViewInner.setBackgroundResource(R.drawable.system_loader2); emptyView.setBackgroundResource(R.drawable.system_black); } else { progressViewInner.setBackgroundResource(R.drawable.system_loader1); emptyView.setBackgroundResource(R.drawable.system_blue); } emptyView.setPadding(Utilities.dp(7), Utilities.dp(1), Utilities.dp(7), Utilities.dp(1)); if (currentUser != null && currentUser.id == 333000) { emptyView.setText(R.string.GotAQuestion); } chatListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapter, View view, int position, long id) { if (mActionMode == null) { createMenu(view, false); } return true; } }); chatListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (visibleItemCount > 0) { if (firstVisibleItem <= 4) { if (!endReached && !loading) { if (messagesByDays.size() != 0) { MessagesController.Instance.loadMessages(dialog_id, 0, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false); } else { MessagesController.Instance.loadMessages(dialog_id, 0, 20, 0, !cacheEndReaced, minDate, classGuid, false, false); } loading = true; } } if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) { if (!unread_end_reached && !loadingForward) { MessagesController.Instance.loadMessages(dialog_id, 0, 20, minMessageId, true, maxDate, classGuid, false, true); loadingForward = true; } } if (firstVisibleItem + visibleItemCount == totalItemCount && unread_end_reached) { showPagedownButton(false, true); } } else { showPagedownButton(false, false); } } }); messsageEditText = (EditText) fragmentView.findViewById(R.id.chat_text_edit); sendButton = (ImageButton) fragmentView.findViewById(R.id.chat_send_button); sendButton.setEnabled(false); sendButton.setVisibility(View.INVISIBLE); emojiButton = (ImageView) fragmentView.findViewById(R.id.chat_smile_button); if (loading && messages.isEmpty()) { progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); } else { progressView.setVisibility(View.GONE); if (currentEncryptedChat == null) { chatListView.setEmptyView(emptyView); } else { chatListView.setEmptyView(secretChatPlaceholder); } } emojiButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (emojiPopup == null) { showEmojiPopup(true); } else { showEmojiPopup(!emojiPopup.isShowing()); } } }); messsageEditText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if (i == 4 && !keyboardVisible && emojiPopup != null && emojiPopup.isShowing()) { if (keyEvent.getAction() == 1) { showEmojiPopup(false); } return true; } else if (i == KeyEvent.KEYCODE_ENTER && sendByEnter && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { sendMessage(); return true; } return false; } }); messsageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEND) { sendMessage(); return true; } else if (sendByEnter) { if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { sendMessage(); return true; } } return false; } }); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { sendMessage(); } }); audioSendButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { startRecording(); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { stopRecording(); } return false; } }); pagedownButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (unread_end_reached || first_unread_id == 0) { chatListView.setSelectionFromTop(messages.size() - 1, -10000 - chatListView.getPaddingTop()); } else { messages.clear(); messagesByDays.clear(); messagesDict.clear(); progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); maxMessageId = Integer.MAX_VALUE; minMessageId = Integer.MIN_VALUE; maxDate = Integer.MIN_VALUE; minDate = 0; MessagesController.Instance.loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true, false); loading = true; chatAdapter.notifyDataSetChanged(); } } }); checkSendButton(); messsageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { String message = charSequence.toString().trim(); message = message.replaceAll("\n\n+", "\n\n"); message = message.replaceAll(" +", " "); sendButton.setEnabled(message.length() != 0); checkSendButton(); if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) { int currentTime = ConnectionsManager.Instance.getCurrentTime(); if (currentUser != null && currentUser.status != null && currentUser.status.expires < currentTime && currentUser.status.was_online < currentTime) { return; } lastTypingTimeSend = System.currentTimeMillis(); MessagesController.Instance.sendTyping(dialog_id, classGuid); } } @Override public void afterTextChanged(Editable editable) { if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') { sendMessage(); } int i = 0; ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class); int j = arrayOfImageSpan.length; while (true) { if (i >= j) { Emoji.replaceEmoji(editable); return; } editable.removeSpan(arrayOfImageSpan[i]); i++; } } }); bottomOverlayChat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (currentChat != null) { MessagesController.Instance.deleteDialog(-currentChat.id, 0, false); finishFragment(); } } }); chatListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (mActionMode != null) { processRowSelect(view); return; } if (!spanClicked(chatListView, view, R.id.chat_message_text)) { createMenu(view, true); } } }); chatListView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeRight() { try { if (visibleDialog != null) { visibleDialog.dismiss(); visibleDialog = null; } } catch (Exception e) { FileLog.e("tmessages", e); } finishFragment(true); } public void onSwipeLeft() { if (swipeOpening) { return; } try { if (visibleDialog != null) { visibleDialog.dismiss(); visibleDialog = null; } } catch (Exception e) { FileLog.e("tmessages", e); } if (avatarImageView != null) { swipeOpening = true; avatarImageView.performClick(); } } @Override public void onTouchUp(MotionEvent event) { mLastTouch.right = (int) event.getX(); mLastTouch.bottom = (int) event.getY(); } }); emptyView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeRight() { finishFragment(true); } public void onSwipeLeft() { if (swipeOpening) { return; } if (avatarImageView != null) { swipeOpening = true; avatarImageView.performClick(); } } }); if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left)) { bottomOverlayChat.setVisibility(View.VISIBLE); } else { bottomOverlayChat.setVisibility(View.GONE); } } else { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { parent.removeView(fragmentView); } } return fragmentView; }
From source file:org.telegram.ui.Components.ChatActivityEnterView.java
public ChatActivityEnterView(Activity context, SizeNotifierFrameLayout parent, ChatActivity fragment, final boolean isChat) { super(context); dotPaint = new Paint(Paint.ANTI_ALIAS_FLAG); dotPaint.setColor(Theme.getColor(Theme.key_chat_emojiPanelNewTrending)); setFocusable(true);//from w ww. ja v a 2 s . c om setFocusableInTouchMode(true); setWillNotDraw(false); NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStarted); NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStartError); NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStopped); NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordProgressChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidSent); NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioRouteChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.featuredStickersDidLoaded); parentActivity = context; parentFragment = fragment; sizeNotifierLayout = parent; sizeNotifierLayout.setDelegate(this); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); sendByEnter = preferences.getBoolean("send_by_enter", false); textFieldContainer = new LinearLayout(context); textFieldContainer.setOrientation(LinearLayout.HORIZONTAL); addView(textFieldContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 2, 0, 0)); FrameLayout frameLayout = new FrameLayout(context); textFieldContainer.addView(frameLayout, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1.0f)); emojiButton = new ImageView(context) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (attachLayout != null && (emojiView == null || emojiView.getVisibility() != VISIBLE) && !StickersQuery.getUnreadStickerSets().isEmpty() && dotPaint != null) { int x = canvas.getWidth() / 2 + AndroidUtilities.dp(4 + 5); int y = canvas.getHeight() / 2 - AndroidUtilities.dp(13 - 5); canvas.drawCircle(x, y, AndroidUtilities.dp(5), dotPaint); } } }; emojiButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY)); emojiButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); emojiButton.setPadding(0, AndroidUtilities.dp(1), 0, 0); // if (Build.VERSION.SDK_INT >= 21) { // emojiButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR)); // } setEmojiButtonImage(); frameLayout.addView(emojiButton, LayoutHelper.createFrame(48, 48, Gravity.BOTTOM | Gravity.LEFT, 3, 0, 0, 0)); emojiButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (!isPopupShowing() || currentPopupContentType != 0) { showPopup(1, 0); emojiView.onOpen(messageEditText.length() > 0 && !messageEditText.getText().toString().startsWith("@gif")); } else { openKeyboardInternal(); removeGifFromInputField(); } } }); messageEditText = new EditTextCaption(context) { @Override public InputConnection onCreateInputConnection(EditorInfo editorInfo) { final InputConnection ic = super.onCreateInputConnection(editorInfo); EditorInfoCompat.setContentMimeTypes(editorInfo, new String[] { "image/gif", "image/*", "image/jpg", "image/png" }); final InputConnectionCompat.OnCommitContentListener callback = new InputConnectionCompat.OnCommitContentListener() { @Override public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) { if (BuildCompat.isAtLeastNMR1() && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) { try { inputContentInfo.requestPermission(); } catch (Exception e) { return false; } } ClipDescription description = inputContentInfo.getDescription(); if (description.hasMimeType("image/gif")) { SendMessagesHelper.prepareSendingDocument(null, null, inputContentInfo.getContentUri(), "image/gif", dialog_id, replyingMessageObject, inputContentInfo); } else { SendMessagesHelper.prepareSendingPhoto(null, inputContentInfo.getContentUri(), dialog_id, replyingMessageObject, null, null, inputContentInfo); } if (delegate != null) { delegate.onMessageSend(null); } return true; } }; return InputConnectionCompat.createWrapper(ic, editorInfo, callback); } @Override public boolean onTouchEvent(MotionEvent event) { if (isPopupShowing() && event.getAction() == MotionEvent.ACTION_DOWN) { showPopup(AndroidUtilities.usingHardwareInput ? 0 : 2, 0); openKeyboardInternal(); } try { return super.onTouchEvent(event); } catch (Exception e) { FileLog.e(e); } return false; } }; updateFieldHint(); messageEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); messageEditText.setInputType(messageEditText.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE); messageEditText.setSingleLine(false); messageEditText.setMaxLines(4); messageEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); messageEditText.setGravity(Gravity.BOTTOM); messageEditText.setPadding(0, AndroidUtilities.dp(11), 0, AndroidUtilities.dp(12)); messageEditText.setBackgroundDrawable(null); messageEditText.setTextColor(Theme.getColor(Theme.key_chat_messagePanelText)); messageEditText.setHintColor(Theme.getColor(Theme.key_chat_messagePanelHint)); messageEditText.setHintTextColor(Theme.getColor(Theme.key_chat_messagePanelHint)); frameLayout.addView(messageEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 52, 0, isChat ? 50 : 2, 0)); messageEditText.setOnKeyListener(new OnKeyListener() { boolean ctrlPressed = false; @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if (i == KeyEvent.KEYCODE_BACK && !keyboardVisible && isPopupShowing()) { if (keyEvent.getAction() == 1) { if (currentPopupContentType == 1 && botButtonsMessageObject != null) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); preferences.edit().putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId()) .commit(); } showPopup(0, 0); removeGifFromInputField(); } return true; } else if (i == KeyEvent.KEYCODE_ENTER && (ctrlPressed || sendByEnter) && keyEvent.getAction() == KeyEvent.ACTION_DOWN && editingMessageObject == null) { sendMessage(); return true; } else if (i == KeyEvent.KEYCODE_CTRL_LEFT || i == KeyEvent.KEYCODE_CTRL_RIGHT) { ctrlPressed = keyEvent.getAction() == KeyEvent.ACTION_DOWN; return true; } return false; } }); messageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { boolean ctrlPressed = false; @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEND) { sendMessage(); return true; } else if (keyEvent != null && i == EditorInfo.IME_NULL) { if ((ctrlPressed || sendByEnter) && keyEvent.getAction() == KeyEvent.ACTION_DOWN && editingMessageObject == null) { sendMessage(); return true; } else if (i == KeyEvent.KEYCODE_CTRL_LEFT || i == KeyEvent.KEYCODE_CTRL_RIGHT) { ctrlPressed = keyEvent.getAction() == KeyEvent.ACTION_DOWN; return true; } } return false; } }); messageEditText.addTextChangedListener(new TextWatcher() { boolean processChange = false; @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int start, int before, int count) { if (innerTextChange == 1) { return; } checkSendButton(true); CharSequence message = AndroidUtilities.getTrimmedString(charSequence.toString()); if (delegate != null) { if (!ignoreTextChange) { if (count > 2 || charSequence == null || charSequence.length() == 0) { messageWebPageSearch = true; } delegate.onTextChanged(charSequence, before > count + 1 || (count - before) > 2); } } if (innerTextChange != 2 && before != count && (count - before) > 1) { processChange = true; } if (editingMessageObject == null && !canWriteToChannel && message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) { int currentTime = ConnectionsManager.getInstance().getCurrentTime(); TLRPC.User currentUser = null; if ((int) dialog_id > 0) { currentUser = MessagesController.getInstance().getUser((int) dialog_id); } if (currentUser != null && (currentUser.id == UserConfig.getClientUserId() || currentUser.status != null && currentUser.status.expires < currentTime && !MessagesController.getInstance().onlinePrivacy .containsKey(currentUser.id))) { return; } lastTypingTimeSend = System.currentTimeMillis(); if (delegate != null) { delegate.needSendTyping(); } } } @Override public void afterTextChanged(Editable editable) { if (innerTextChange != 0) { return; } if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n' && editingMessageObject == null) { sendMessage(); } if (processChange) { ImageSpan[] spans = editable.getSpans(0, editable.length(), ImageSpan.class); for (int i = 0; i < spans.length; i++) { editable.removeSpan(spans[i]); } Emoji.replaceEmoji(editable, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false); processChange = false; } } }); if (isChat) { attachLayout = new LinearLayout(context); attachLayout.setOrientation(LinearLayout.HORIZONTAL); attachLayout.setEnabled(false); attachLayout.setPivotX(AndroidUtilities.dp(48)); frameLayout.addView(attachLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 48, Gravity.BOTTOM | Gravity.RIGHT)); botButton = new ImageView(context); botButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY)); botButton.setImageResource(R.drawable.bot_keyboard2); botButton.setScaleType(ImageView.ScaleType.CENTER); botButton.setVisibility(GONE); // if (Build.VERSION.SDK_INT >= 21) { // botButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR)); // } attachLayout.addView(botButton, LayoutHelper.createLinear(48, 48)); botButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (botReplyMarkup != null) { if (!isPopupShowing() || currentPopupContentType != 1) { showPopup(1, 1); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); preferences.edit().remove("hidekeyboard_" + dialog_id).commit(); } else { if (currentPopupContentType == 1 && botButtonsMessageObject != null) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); preferences.edit() .putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId()) .commit(); } openKeyboardInternal(); } } else if (hasBotCommands) { setFieldText("/"); messageEditText.requestFocus(); openKeyboard(); } } }); notifyButton = new ImageView(context); notifyButton.setImageResource(silent ? R.drawable.notify_members_off : R.drawable.notify_members_on); notifyButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY)); notifyButton.setScaleType(ImageView.ScaleType.CENTER); notifyButton.setVisibility(canWriteToChannel ? VISIBLE : GONE); // if (Build.VERSION.SDK_INT >= 21) { // notifyButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR)); // } attachLayout.addView(notifyButton, LayoutHelper.createLinear(48, 48)); notifyButton.setOnClickListener(new OnClickListener() { private Toast visibleToast; @Override public void onClick(View v) { silent = !silent; notifyButton.setImageResource( silent ? R.drawable.notify_members_off : R.drawable.notify_members_on); ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE).edit() .putBoolean("silent_" + dialog_id, silent).commit(); NotificationsController.updateServerNotificationsSettings(dialog_id); try { if (visibleToast != null) { visibleToast.cancel(); } } catch (Exception e) { FileLog.e(e); } if (silent) { visibleToast = Toast.makeText(parentActivity, LocaleController .getString("ChannelNotifyMembersInfoOff", R.string.ChannelNotifyMembersInfoOff), Toast.LENGTH_SHORT); } else { visibleToast = Toast.makeText(parentActivity, LocaleController .getString("ChannelNotifyMembersInfoOn", R.string.ChannelNotifyMembersInfoOn), Toast.LENGTH_SHORT); } visibleToast.show(); updateFieldHint(); } }); attachButton = new ImageView(context); attachButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY)); attachButton.setImageResource(R.drawable.ic_ab_attach); attachButton.setScaleType(ImageView.ScaleType.CENTER); // if (Build.VERSION.SDK_INT >= 21) { // attachButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR)); // } attachLayout.addView(attachButton, LayoutHelper.createLinear(48, 48)); attachButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { delegate.didPressedAttachButton(); } }); } recordedAudioPanel = new FrameLayout(context); recordedAudioPanel.setVisibility(audioToSend == null ? GONE : VISIBLE); recordedAudioPanel.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground)); recordedAudioPanel.setFocusable(true); recordedAudioPanel.setFocusableInTouchMode(true); recordedAudioPanel.setClickable(true); frameLayout.addView(recordedAudioPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM)); recordDeleteImageView = new ImageView(context); recordDeleteImageView.setScaleType(ImageView.ScaleType.CENTER); recordDeleteImageView.setImageResource(R.drawable.ic_ab_delete); recordDeleteImageView.setColorFilter(new PorterDuffColorFilter( Theme.getColor(Theme.key_chat_messagePanelVoiceDelete), PorterDuff.Mode.MULTIPLY)); recordedAudioPanel.addView(recordDeleteImageView, LayoutHelper.createFrame(48, 48)); recordDeleteImageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { MessageObject playing = MediaController.getInstance().getPlayingMessageObject(); if (playing != null && playing == audioToSendMessageObject) { MediaController.getInstance().cleanupPlayer(true, true); } if (audioToSendPath != null) { new File(audioToSendPath).delete(); } hideRecordedAudioPanel(); checkSendButton(true); } }); recordedAudioBackground = new View(context); recordedAudioBackground.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(16), Theme.getColor(Theme.key_chat_recordedVoiceBackground))); recordedAudioPanel.addView(recordedAudioBackground, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 32, Gravity.CENTER_VERTICAL | Gravity.LEFT, 48, 0, 0, 0)); recordedAudioSeekBar = new SeekBarWaveformView(context); recordedAudioPanel.addView(recordedAudioSeekBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 32, Gravity.CENTER_VERTICAL | Gravity.LEFT, 48 + 44, 0, 52, 0)); playDrawable = Theme.createSimpleSelectorDrawable(context, R.drawable.s_play, Theme.getColor(Theme.key_chat_recordedVoicePlayPause), Theme.getColor(Theme.key_chat_recordedVoicePlayPausePressed)); pauseDrawable = Theme.createSimpleSelectorDrawable(context, R.drawable.s_pause, Theme.getColor(Theme.key_chat_recordedVoicePlayPause), Theme.getColor(Theme.key_chat_recordedVoicePlayPausePressed)); recordedAudioPlayButton = new ImageView(context); recordedAudioPlayButton.setImageDrawable(playDrawable); recordedAudioPlayButton.setScaleType(ImageView.ScaleType.CENTER); recordedAudioPanel.addView(recordedAudioPlayButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.BOTTOM, 48, 0, 0, 0)); recordedAudioPlayButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (audioToSend == null) { return; } if (MediaController.getInstance().isPlayingAudio(audioToSendMessageObject) && !MediaController.getInstance().isAudioPaused()) { MediaController.getInstance().pauseAudio(audioToSendMessageObject); recordedAudioPlayButton.setImageDrawable(playDrawable); } else { recordedAudioPlayButton.setImageDrawable(pauseDrawable); MediaController.getInstance().playAudio(audioToSendMessageObject); } } }); recordedAudioTimeTextView = new TextView(context); recordedAudioTimeTextView.setTextColor(Theme.getColor(Theme.key_chat_messagePanelVoiceDuration)); recordedAudioTimeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); recordedAudioPanel.addView(recordedAudioTimeTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL, 0, 0, 13, 0)); recordPanel = new FrameLayout(context); recordPanel.setVisibility(GONE); recordPanel.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground)); frameLayout.addView(recordPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM)); slideText = new LinearLayout(context); slideText.setOrientation(LinearLayout.HORIZONTAL); recordPanel.addView(slideText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 30, 0, 0, 0)); recordCancelImage = new ImageView(context); recordCancelImage.setImageResource(R.drawable.slidearrow); recordCancelImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_recordVoiceCancel), PorterDuff.Mode.MULTIPLY)); slideText.addView(recordCancelImage, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 0, 1, 0, 0)); recordCancelText = new TextView(context); recordCancelText.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel)); recordCancelText.setTextColor(Theme.getColor(Theme.key_chat_recordVoiceCancel)); recordCancelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); slideText.addView(recordCancelText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 6, 0, 0, 0)); recordTimeContainer = new LinearLayout(context); recordTimeContainer.setOrientation(LinearLayout.HORIZONTAL); recordTimeContainer.setPadding(AndroidUtilities.dp(13), 0, 0, 0); recordTimeContainer.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground)); recordPanel.addView(recordTimeContainer, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL)); recordDot = new RecordDot(context); recordTimeContainer.addView(recordDot, LayoutHelper.createLinear(11, 11, Gravity.CENTER_VERTICAL, 0, 1, 0, 0)); recordTimeText = new TextView(context); recordTimeText.setText("00:00"); recordTimeText.setTextColor(Theme.getColor(Theme.key_chat_recordTime)); recordTimeText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); recordTimeContainer.addView(recordTimeText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 6, 0, 0, 0)); sendButtonContainer = new FrameLayout(context); textFieldContainer.addView(sendButtonContainer, LayoutHelper.createLinear(48, 48, Gravity.BOTTOM)); audioVideoButtonContainer = new FrameLayout(context); audioVideoButtonContainer.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground)); audioVideoButtonContainer.setSoundEffectsEnabled(false); sendButtonContainer.addView(audioVideoButtonContainer, LayoutHelper.createFrame(48, 48)); audioVideoButtonContainer.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { if (hasRecordVideo) { recordAudioVideoRunnableStarted = true; AndroidUtilities.runOnUIThread(recordAudioVideoRunnable, 150); } else { recordAudioVideoRunnable.run(); } } else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) { if (recordAudioVideoRunnableStarted) { AndroidUtilities.cancelRunOnUIThread(recordAudioVideoRunnable); setRecordVideoButtonVisible(videoSendButton.getTag() == null, true); } else { startedDraggingX = -1; if (hasRecordVideo && videoSendButton.getTag() != null) { delegate.needStartRecordVideo(1); } else { MediaController.getInstance().stopRecording(1); } recordingAudioVideo = false; updateRecordIntefrace(); } } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudioVideo) { float x = motionEvent.getX(); if (x < -distCanMove) { if (hasRecordVideo && videoSendButton.getTag() != null) { delegate.needStartRecordVideo(2); } else { MediaController.getInstance().stopRecording(0); } recordingAudioVideo = false; updateRecordIntefrace(); } x = x + audioVideoButtonContainer.getX(); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText.getLayoutParams(); if (startedDraggingX != -1) { float dist = (x - startedDraggingX); recordCircle.setTranslationX(dist); params.leftMargin = AndroidUtilities.dp(30) + (int) dist; slideText.setLayoutParams(params); float alpha = 1.0f + dist / distCanMove; if (alpha > 1) { alpha = 1; } else if (alpha < 0) { alpha = 0; } slideText.setAlpha(alpha); } if (x <= slideText.getX() + slideText.getWidth() + AndroidUtilities.dp(30)) { if (startedDraggingX == -1) { startedDraggingX = x; distCanMove = (recordPanel.getMeasuredWidth() - slideText.getMeasuredWidth() - AndroidUtilities.dp(48)) / 2.0f; if (distCanMove <= 0) { distCanMove = AndroidUtilities.dp(80); } else if (distCanMove > AndroidUtilities.dp(80)) { distCanMove = AndroidUtilities.dp(80); } } } if (params.leftMargin > AndroidUtilities.dp(30)) { params.leftMargin = AndroidUtilities.dp(30); recordCircle.setTranslationX(0); slideText.setLayoutParams(params); slideText.setAlpha(1); startedDraggingX = -1; } } view.onTouchEvent(motionEvent); return true; } }); audioSendButton = new ImageView(context); audioSendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); audioSendButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY)); audioSendButton.setImageResource(R.drawable.mic); audioSendButton.setPadding(0, 0, AndroidUtilities.dp(4), 0); audioVideoButtonContainer.addView(audioSendButton, LayoutHelper.createFrame(48, 48)); if (hasRecordVideo) { videoSendButton = new ImageView(context); videoSendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); videoSendButton.setColorFilter(new PorterDuffColorFilter( Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY)); videoSendButton.setImageResource(R.drawable.ic_msg_panel_video); videoSendButton.setPadding(0, 0, AndroidUtilities.dp(4), 0); audioVideoButtonContainer.addView(videoSendButton, LayoutHelper.createFrame(48, 48)); } recordCircle = new RecordCircle(context); recordCircle.setVisibility(GONE); sizeNotifierLayout.addView(recordCircle, LayoutHelper.createFrame(124, 124, Gravity.BOTTOM | Gravity.RIGHT, 0, 0, -36, -38)); cancelBotButton = new ImageView(context); cancelBotButton.setVisibility(INVISIBLE); cancelBotButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); cancelBotButton.setImageDrawable(progressDrawable = new CloseProgressDrawable2()); progressDrawable.setColorFilter(new PorterDuffColorFilter( Theme.getColor(Theme.key_chat_messagePanelCancelInlineBot), PorterDuff.Mode.MULTIPLY)); cancelBotButton.setSoundEffectsEnabled(false); cancelBotButton.setScaleX(0.1f); cancelBotButton.setScaleY(0.1f); cancelBotButton.setAlpha(0.0f); sendButtonContainer.addView(cancelBotButton, LayoutHelper.createFrame(48, 48)); cancelBotButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { String text = messageEditText.getText().toString(); int idx = text.indexOf(' '); if (idx == -1 || idx == text.length() - 1) { setFieldText(""); } else { setFieldText(text.substring(0, idx + 1)); } } }); sendButton = new ImageView(context); sendButton.setVisibility(INVISIBLE); sendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); sendButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelSend), PorterDuff.Mode.MULTIPLY)); sendButton.setImageResource(R.drawable.ic_send); sendButton.setSoundEffectsEnabled(false); sendButton.setScaleX(0.1f); sendButton.setScaleY(0.1f); sendButton.setAlpha(0.0f); sendButtonContainer.addView(sendButton, LayoutHelper.createFrame(48, 48)); sendButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { sendMessage(); } }); doneButtonContainer = new FrameLayout(context); doneButtonContainer.setVisibility(GONE); textFieldContainer.addView(doneButtonContainer, LayoutHelper.createLinear(48, 48, Gravity.BOTTOM)); // if (Build.VERSION.SDK_INT >= 21) { // doneButtonContainer.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR)); // } doneButtonContainer.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { doneEditingMessage(); } }); doneButtonImage = new ImageView(context); doneButtonImage.setScaleType(ImageView.ScaleType.CENTER); doneButtonImage.setImageResource(R.drawable.edit_done); doneButtonImage.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_editDoneIcon), PorterDuff.Mode.MULTIPLY)); doneButtonContainer.addView(doneButtonImage, LayoutHelper.createFrame(48, 48)); doneButtonProgress = new ContextProgressView(context, 0); doneButtonProgress.setVisibility(View.INVISIBLE); doneButtonContainer.addView(doneButtonProgress, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("emoji", Context.MODE_PRIVATE); keyboardHeight = sharedPreferences.getInt("kbd_height", AndroidUtilities.dp(200)); keyboardHeightLand = sharedPreferences.getInt("kbd_height_land3", AndroidUtilities.dp(200)); setRecordVideoButtonVisible(false, false); checkSendButton(false); }
From source file:info.bartowski.easteregg.MLand.java
@Override public boolean onKeyUp(int keyCode, KeyEvent ev) { L("keyDown: %d", keyCode); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_SPACE: case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_BUTTON_A: int player = getControllerPlayer(ev.getDeviceId()); unpoke(player);/* w ww . j a va 2 s. c o m*/ return true; } return false; }