Example usage for android.widget TextView getTextColors

List of usage examples for android.widget TextView getTextColors

Introduction

In this page you can find the example usage for android.widget TextView getTextColors.

Prototype

public final ColorStateList getTextColors() 

Source Link

Document

Gets the text colors for the different states (normal, selected, focused) of the TextView.

Usage

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)
  */// ww w  . ja  va  2s. c om
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:me.zchang.onchart.ui.adapter.CourseListAdapter.java

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
    if (holder instanceof ViewHolder) {
        ViewHolder viewHolder = (ViewHolder) holder;
        final LabelCourse course = (LabelCourse) courses.get(bitmap[position]);
        final TextView nameText = viewHolder.nameText;
        final TextView roomText = viewHolder.roomText;
        final TextView timeText = viewHolder.timeText;
        final ImageView nabImg = viewHolder.nabImg;
        final CardView cardView = viewHolder.cardView;
        final TextView backgroundIndicator = viewHolder.backgroundIndicator;
        nameText.setText(course.getName());
        roomText.setText(course.getClassroom());
        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        timeText.setText(dateFormat.format(course.getStartTime()));

        ViewGroup.LayoutParams params = ((ViewHolder) holder).frame.getLayoutParams();
        params.height = (viewHolder.cardHeight >> 1)
                * (((int) course.getEndTime() - (int) course.getStartTime()) / Utils.MILLISECONDS_IN_ONE_CLASS
                        + 1);/*from  w w  w.j  a v a2  s  .com*/
        ((ViewHolder) holder).frame.setLayoutParams(params);

        nabImg.setImageResource(ConfigManager.labelImgIndices[course.getLabelImgIndex()]);

        Drawable nab = nabImg.getDrawable();
        if (nab != null) {
            if ((course.getThemeColor() | course.getTimeColor() | course.getTitleColor()
                    | course.getSubTitleColor()) == 0) {
                new Palette.Builder(((BitmapDrawable) nab).getBitmap())
                        .generate(new Palette.PaletteAsyncListener() {
                            @Override
                            public void onGenerated(Palette palette) {
                                Palette.Swatch lightVibrant = palette.getLightVibrantSwatch();
                                Palette.Swatch vibrant = palette.getVibrantSwatch();
                                if (cardView != null) {
                                    if (lightVibrant != null) {
                                        cardView.setCardBackgroundColor(lightVibrant.getRgb());
                                        backgroundIndicator.setTextColor(lightVibrant.getRgb());
                                        nameText.setTextColor(lightVibrant.getTitleTextColor());
                                        roomText.setTextColor(lightVibrant.getBodyTextColor());

                                        course.setThemeColor(lightVibrant.getRgb())
                                                .setTitleColor(lightVibrant.getTitleTextColor())
                                                .setSubTitleColor(lightVibrant.getBodyTextColor());
                                    } else if (vibrant != null) {
                                        cardView.setCardBackgroundColor(vibrant.getRgb());
                                        backgroundIndicator.setTextColor(vibrant.getRgb());
                                        nameText.setTextColor(vibrant.getTitleTextColor());
                                        roomText.setTextColor(vibrant.getBodyTextColor());

                                        course.setThemeColor(vibrant.getRgb())
                                                .setTitleColor(vibrant.getTitleTextColor())
                                                .setSubTitleColor(vibrant.getBodyTextColor());
                                    } else {
                                        int defaultColor = ContextCompat.getColor(context,
                                                R.color.cardview_light_background);
                                        cardView.setCardBackgroundColor(defaultColor);
                                        backgroundIndicator.setTextColor(defaultColor);
                                        nameText.setTextColor(defaultColor);
                                        roomText.setTextColor(defaultColor);

                                        course.setThemeColor(defaultColor).setTitleColor(defaultColor)
                                                .setSubTitleColor(defaultColor);
                                    }
                                    if (vibrant != null) {
                                        timeText.setTextColor(vibrant.getRgb());
                                        course.setTimeColor(vibrant.getRgb());
                                    } else {
                                        timeText.setTextColor(
                                                ContextCompat.getColor(context, R.color.default_title));
                                        course.setTimeColor(
                                                ContextCompat.getColor(context, R.color.default_title));
                                    }
                                }
                            }

                        });
            } else if (cardView != null) {
                cardView.setCardBackgroundColor(course.getThemeColor());
                backgroundIndicator.setTextColor(course.getThemeColor());
                nameText.setTextColor(course.getTitleColor());
                roomText.setTextColor(course.getSubTitleColor());
                timeText.setTextColor(course.getTimeColor());
            }

        }

        if (cardView != null) {
            cardView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, DetailActivity.class);
                    intent.putExtra(context.getString(R.string.intent_frag_index), fragId);
                    intent.putExtra(context.getString(R.string.intent_position), position);
                    intent.putExtra(context.getString(R.string.intent_lesson), course);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                        intent.putExtra("color", backgroundIndicator.getTextColors().getDefaultColor());
                    else
                        intent.putExtra("color", 0xffffff);
                    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
                            (Activity) context, Pair.create(v, context.getString(R.string.trans_detail_item)),
                            Pair.create(v.findViewById(R.id.iv_label),
                                    context.getString(R.string.trans_detail_img)));
                    ((Activity) context).startActivityForResult(intent, MainActivity.REQ_POSITION,
                            options.toBundle());
                }
            });
        }
    } else if (holder instanceof SubtitleViewHolder) {
        if (MORNING_FLAG == bitmap[position]) {
            ((SubtitleViewHolder) holder).subTitle
                    .setText(context.getResources().getString(me.zchang.onchart.R.string.subtitle_morning));
        } else if (AFTERNOON_FLAG == bitmap[position]) {
            ((SubtitleViewHolder) holder).subTitle
                    .setText(context.getResources().getString(me.zchang.onchart.R.string.subtitle_afternoon));
        } else if (EVENING_FLAG == bitmap[position]) {
            ((SubtitleViewHolder) holder).subTitle
                    .setText(context.getResources().getString(me.zchang.onchart.R.string.subtitle_evening));
        }
    }
}