Example usage for android.view KeyEvent getAction

List of usage examples for android.view KeyEvent getAction

Introduction

In this page you can find the example usage for android.view KeyEvent getAction.

Prototype

public final int getAction() 

Source Link

Document

Retrieve the action of this key event.

Usage

From source file:VerticalViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.//from ww  w  .j a  v  a2  s  . c o  m
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            handled = arrowScroll(FOCUS_UP);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            handled = arrowScroll(FOCUS_DOWN);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:com.nuwa.widgets.LoopViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy./*from w w w.j  av  a2 s.  c om*/
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (event.hasNoModifiers()) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:com.suning.boxcontroller.control.ExViewPager.java

/**
 * You can call this function yourself to have the scroll view perform scrolling from a key event, just as if the
 * event had been dispatched to it by the view hierarchy.
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 *//*from   w  w w .j a v  a 2s  .  co m*/
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;

        default:
            break;
        }
    }
    return handled;
}

From source file:com.ichi2.anki.AbstractFlashcardViewer.java

protected void initControls() {
    mCardFrame.setVisibility(View.VISIBLE);
    if (mShowRemainingCardCount) {
        mTextBarNew.setVisibility(View.VISIBLE);
        mTextBarLearn.setVisibility(View.VISIBLE);
        mTextBarReview.setVisibility(View.VISIBLE);
    }//from   www  . jav  a2 s.c o m
    mChosenAnswer.setVisibility(View.VISIBLE);
    mFlipCardLayout.setVisibility(View.VISIBLE);

    mAnswerField.setVisibility(typeAnswer() ? View.VISIBLE : View.GONE);
    mAnswerField.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                displayCardAnswer();
                return true;
            }
            return false;
        }
    });
    mAnswerField.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP
                    && (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER)) {
                displayCardAnswer();
                return true;
            }
            return false;
        }
    });
}

From source file:eu.kanade.tachiyomi.ui.reader.viewer.pager.vertical.VerticalViewPagerImpl.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.//from  w w  w.j  a  v  a 2 s  .  c  o  m
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        default:
            break;
        }
    }
    return handled;
}

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   www.j  av a  2 s  . c o m*/
protected Dialog onCreateDialog(int id, final Bundle retrievedBundle) {

    // przypisanie kontekstu do dialog
    final Context mContext = this; // wane w oficjalnej dokumentacji jest bd
    Dialog dialog = new Dialog(mContext);
    dialog_FIRST_TIME_RUNING = new Dialog(mContext);
    dialog_GIVE_ME_A_APP_PASSWORD = new Dialog(mContext);
    dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE = new Dialog(
            mContext);
    dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST = new Dialog(
            mContext);
    dialog_GIVE_ME_A_SERVER_PASSWORD = new Dialog(mContext);
    dialog_ADD_NEW_SERVER_CRYPTO_ENABLED = new Dialog(mContext);
    dialog_ADD_NEW_SERVER_CRYPTO_DISABLED = new Dialog(mContext);
    dialog_DELETE_SERVER = new Dialog(mContext);
    dialog_CHOSE_SERVER_TO_EDIT = new Dialog(mContext);
    dialog_EDIT_SERVER_CRYPTO_ENABLED = new Dialog(mContext);
    dialog_EDIT_SERVER_CRYPTO_DISABLED = new Dialog(mContext);
    dialog_DO_DELATE = new Dialog(mContext);
    dialog_LICENSE = new Dialog(mContext);

    switch (id) {
    case DIALOG_FIRST_TIME_RUNING:

        //dialog_FIRST_TIME_RUNING.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog_FIRST_TIME_RUNING.setContentView(R.layout.layout_for_dialog_first_time_runing);
        dialog_FIRST_TIME_RUNING.setTitle(R.string.tile_for_dialog_FIRST_TIME_RUNING);
        dialog_FIRST_TIME_RUNING.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                finish();

            }
        });

        if (appPasswordcharArray != null) { //appPasswordcharArray == null on first start for example
            try {
                serverListArrayList = aXMLReaderWriter
                        .decryptFileWithXMLAndParseItToServerList(appPasswordcharArray);

            } catch (WrongPasswordException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        final EditText set_app_passwordEditText = (EditText) dialog_FIRST_TIME_RUNING
                .findViewById(R.id.set_app_passswordEditText);
        set_app_passwordEditText.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on key press
                    return true;
                }
                return false;
            }
        });

        final TextView explanation_set_a_password_for_this_appTextView = (TextView) dialog_FIRST_TIME_RUNING
                .findViewById(R.id.explanation_set_a_password_for_this_app);
        final ColorStateList explanation_set_a_password_for_this_appTextViewColorStateList = explanation_set_a_password_for_this_appTextView
                .getTextColors();
        final CheckBox use_encryption_checkBox = (CheckBox) dialog_FIRST_TIME_RUNING
                .findViewById(R.id.use_encryption_checkBox);
        use_encryption_checkBox.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                if (use_encryption_checkBox.isChecked() == true) {
                    set_app_passwordEditText.setVisibility(View.VISIBLE);
                    explanation_set_a_password_for_this_appTextView.setVisibility(View.VISIBLE);
                    /*
                    //explanation_set_a_password_for_this_appTextView.setTextColor(explanation_set_a_password_for_this_appTextViewColorStateList);
                    set_app_passwordEditText.setClickable(true);
                    set_app_passwordEditText.setFocusable(true);
                    set_app_passwordEditText.setFocusableInTouchMode(true);
                    set_app_passwordEditText.setCursorVisible(true);
                    set_app_passwordEditText.setLongClickable(true);
                    set_app_passwordEditText.setBackgroundResource(android.R.drawable.edit_text);
                    set_app_passwordEditText.setTextColor(android.graphics.Color.BLACK);
                    */
                } else {
                    set_app_passwordEditText.setVisibility(View.INVISIBLE);
                    explanation_set_a_password_for_this_appTextView.setVisibility(View.INVISIBLE);
                    /*
                    //explanation_set_a_password_for_this_appTextView.setTextColor(0);
                    set_app_passwordEditText.setClickable(false);
                    set_app_passwordEditText.setFocusable(false);
                    set_app_passwordEditText.setFocusableInTouchMode(false);
                    set_app_passwordEditText.setCursorVisible(false);
                    set_app_passwordEditText.setLongClickable(false);
                    set_app_passwordEditText.setBackgroundColor(android.graphics.Color.GRAY);
                    set_app_passwordEditText.setTextColor(android.graphics.Color.GRAY);
                    */
                }

            }

        });

        final Button exit_dialog_first_time_runing_button = (Button) dialog_FIRST_TIME_RUNING
                .findViewById(R.id.exit_dialog_first_time_runing_button);
        exit_dialog_first_time_runing_button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                if (set_app_passwordEditText.getText().length() == 0
                        && use_encryption_checkBox.isChecked() == true) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces,
                            Toast.LENGTH_LONG).show();

                } else {

                    if (use_encryption_checkBox.isChecked() == true) {
                        isCryptoEnabledboolean = true;
                    } else {
                        isCryptoEnabledboolean = false;
                    }

                    SharedPreferences settings_for_APP = getSharedPreferences("settings_for_APP", 0);
                    SharedPreferences.Editor editor = settings_for_APP.edit();
                    editor.putBoolean("is_this_first_run", false);
                    editor.putBoolean("is_crypto_enabled", isCryptoEnabledboolean);
                    // Commit the edits!
                    editor.commit();

                    //a new salt should be created for every new app passwort. Watch a XMLReaderWriter.createKey and SettingsForAPP.
                    File file = mContext.getFileStreamPath("salt");
                    if (file.exists()) {
                        file.delete(); //Usuwanie salt dla poprzedniego hasa aplikacji.
                        Log.v(TAG, "Usuwam stary salt");
                    }

                    if (isCryptoEnabledboolean == true) {
                        appPasswordcharArray = set_app_passwordEditText.getText().toString().toCharArray();
                        aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList,
                                appPasswordcharArray);
                    } else {
                        appPasswordcharArray = "default_password".toCharArray();
                        aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList,
                                appPasswordcharArray);
                    }
                    if (serverListArrayList != null) {
                        for (int i = 0; i < serverListArrayList.size(); i++) {

                            createConnectButtons(i);

                        }
                    }
                    dismissdialog_FIRST_TIME_RUNING();
                }
            }
        });
        break;
    case DIALOG_GIVE_ME_A_APP_PASSWORD:

        dialog_GIVE_ME_A_APP_PASSWORD.setContentView(R.layout.layout_for_dialog_give_me_a_app_password);
        dialog_GIVE_ME_A_APP_PASSWORD.setTitle(R.string.title_for_dialog_GIVE_ME_A_APP_PASSWORD);
        dialog_GIVE_ME_A_APP_PASSWORD.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                finish();

            }
        });
        final Button check_app_passwordButton = (Button) dialog_GIVE_ME_A_APP_PASSWORD
                .findViewById(R.id.check_app_password_Button);
        check_app_passwordButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                EditText app_password_EditText = (EditText) dialog_GIVE_ME_A_APP_PASSWORD
                        .findViewById(R.id.app_password_EditText);
                if (app_password_EditText.getText().length() == 0) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces,
                            Toast.LENGTH_LONG).show();
                } else {
                    app_password_EditText.setOnKeyListener(new OnKeyListener() {
                        public boolean onKey(View v, int keyCode, KeyEvent event) {
                            // If the event is a key-down event on the "enter" button
                            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                                // Perform action on key press
                                return true;
                            }
                            return false;
                        }
                    });
                    appPasswordcharArray = (app_password_EditText.getText().toString()).toCharArray();

                    try {
                        serverListArrayList = aXMLReaderWriter
                                .decryptFileWithXMLAndParseItToServerList(appPasswordcharArray);

                        if (serverListArrayList != null) {
                            for (int i = 0; i < serverListArrayList.size(); i++) {

                                createConnectButtons(i);

                            }
                        }
                        final CheckBox remember_app_password_in_sesion_CheckBox = (CheckBox) dialog_GIVE_ME_A_APP_PASSWORD
                                .findViewById(R.id.remember_app_password_in_sesion_CheckBox);
                        if (remember_app_password_in_sesion_CheckBox.isChecked() == true) {
                            rememberAppPasswordInSesionboolean = true;
                            SharedPreferences settings_for_APP = getSharedPreferences("settings_for_APP", 0);
                            SharedPreferences.Editor editor = settings_for_APP.edit();
                            editor.putBoolean("remember_app_password_in_sesion_boolean",
                                    rememberAppPasswordInSesionboolean);
                            // Commit the edits!
                            editor.commit();
                        } else {
                            Arrays.fill(appPasswordcharArray, '0');
                            appPasswordcharArray = null;
                            rememberAppPasswordInSesionboolean = false;
                            SharedPreferences settings_for_APP = getSharedPreferences("settings_for_APP", 0);
                            SharedPreferences.Editor editor = settings_for_APP.edit();
                            editor.putBoolean("remember_app_password_in_sesion_boolean",
                                    rememberAppPasswordInSesionboolean);
                            // Commit the edits!
                            editor.commit();
                        }
                        dismissdialog_GIVE_ME_A_APP_PASSWORD();
                    } catch (WrongPasswordException e) {
                        appPasswordcharArray = null;
                        Toast.makeText(getApplicationContext(), R.string.wrong_app_password_exeption,
                                Toast.LENGTH_SHORT).show();
                        showdialog_GIVE_ME_A_APP_PASSWORD();
                    }

                }
            }
        });

        break;
    //called in dialogs DIALOG_ADD_NEW_SERVER... and DIALOG_EDIT_SERVER.. 
    case DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE:
        dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE.setContentView(
                R.layout.layout_for_dialog__because_remember_app_password_in_sesion_boolean_is_false);
        dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE.setTitle(
                R.string.title_for_dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE);
        Button continue_with_given_app_password_Button = (Button) dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE
                .findViewById(R.id.continue_with_given_app_password_Button);
        continue_with_given_app_password_Button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                EditText app_password_EditText = (EditText) dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE
                        .findViewById(
                                R.id.app_password_EditText_in_layout_for_dialog__because_remember_app_password_in_sesion_boolean_is_false);
                if (app_password_EditText.getText().length() == 0) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces,
                            Toast.LENGTH_LONG).show();
                } else {
                    app_password_EditText.setOnKeyListener(new OnKeyListener() {
                        public boolean onKey(View v, int keyCode, KeyEvent event) {
                            // If the event is a key-down event on the "enter" button
                            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                                // Perform action on key press
                                return true;
                            }
                            return false;
                        }
                    });
                    Log.v(TAG,
                            "app_password przez odczytaniem z app_password_EditText w: DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE"
                                    + appPasswordcharArray);
                    appPasswordcharArray = (app_password_EditText.getText().toString()).toCharArray();
                    Log.v(TAG,
                            "app_password po odczytaniu z app_password_EditText w: DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE"
                                    + appPasswordcharArray.toString());
                    try {
                        List<Server> test_input_server_list = new ArrayList<Server>();
                        test_input_server_list = aXMLReaderWriter
                                .decryptFileWithXMLAndParseItToServerList(appPasswordcharArray); //catch if password is wrong
                        aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList,
                                appPasswordcharArray);
                        //Log.v(TAG,server.getServer_name());
                        //Log.v(TAG,server.getIP_address());
                        //Log.v(TAG,server.getUsername());
                        //Log.v(TAG,new String(server.getPassword())); 

                        //removeDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE);
                        Arrays.fill(appPasswordcharArray, '0');
                        appPasswordcharArray = null;
                        finish();
                        Intent intent = new Intent(mContext, ServerList.class);
                        startActivity(intent);
                    } catch (WrongPasswordException e) {
                        appPasswordcharArray = null;
                        Toast.makeText(getApplicationContext(), R.string.wrong_app_password_exeption,
                                Toast.LENGTH_SHORT).show();
                        //showDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE);
                    }
                }
            }
        });
        break;

    case DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST:
        dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST
                .setContentView(
                        R.layout.layout_for_dialog__because_remember_app_password_in_sesion_boolean_is_false);
        dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST
                .setTitle(
                        R.string.title_for_dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE);
        Button continue_with_given_app_password_Button2 = (Button) dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST
                .findViewById(R.id.continue_with_given_app_password_Button);
        continue_with_given_app_password_Button2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                EditText app_password_EditText = (EditText) dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST
                        .findViewById(
                                R.id.app_password_EditText_in_layout_for_dialog__because_remember_app_password_in_sesion_boolean_is_false);
                if (app_password_EditText.getText().length() == 0) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces,
                            Toast.LENGTH_LONG).show();
                } else {
                    app_password_EditText.setOnKeyListener(new OnKeyListener() {
                        public boolean onKey(View v, int keyCode, KeyEvent event) {
                            // If the event is a key-down event on the "enter" button
                            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                                // Perform action on key press
                                return true;
                            }
                            return false;
                        }
                    });
                    Log.v(TAG,
                            "app_password przez odczytaniem z app_password_EditText w: DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST"
                                    + appPasswordcharArray);
                    appPasswordcharArray = (app_password_EditText.getText().toString()).toCharArray();
                    Log.v(TAG,
                            "app_password po odczytaniu z app_password_EditText w: DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST"
                                    + appPasswordcharArray.toString());
                    try {
                        List<Server> test_input_server_list = new ArrayList<Server>();
                        test_input_server_list = aXMLReaderWriter
                                .decryptFileWithXMLAndParseItToServerList(appPasswordcharArray); //catch if password is wrong
                        aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList,
                                appPasswordcharArray);

                        final Intent intent_start_settings_activity_for_ServerList = new Intent(
                                getApplicationContext(), SettingsForAPP.class);
                        intent_start_settings_activity_for_ServerList.putExtra("app_password",
                                appPasswordcharArray);
                        startActivity(intent_start_settings_activity_for_ServerList);
                        finish();

                        //removeDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE);
                        Arrays.fill(appPasswordcharArray, '0');
                        appPasswordcharArray = null;

                    } catch (WrongPasswordException e) {
                        appPasswordcharArray = null;
                        Toast.makeText(getApplicationContext(), R.string.wrong_app_password_exeption,
                                Toast.LENGTH_SHORT).show();
                        //showDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE);
                    }
                }
            }
        });
        break;

    case DIALOG_GIVE_ME_A_SERVER_PASSWORD:

        dialog_GIVE_ME_A_SERVER_PASSWORD.setContentView(R.layout.layout_for_dialog_give_me_a_server_password);
        dialog_GIVE_ME_A_SERVER_PASSWORD.setTitle(R.string.title_for_dialog_GIVE_ME_A_SERVER_PASSWORD);

        final Button connect_to_server_button_in_DIALOG_GIVE_ME_A_SERVER_PASSWORD = (Button) dialog_GIVE_ME_A_SERVER_PASSWORD
                .findViewById(R.id.connect_to_server_Button_in_dialog_give_me_a_server_password);
        connect_to_server_button_in_DIALOG_GIVE_ME_A_SERVER_PASSWORD.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                EditText server_password_EditText = (EditText) dialog_GIVE_ME_A_SERVER_PASSWORD
                        .findViewById(R.id.server_password_EditText);
                if (server_password_EditText.getText().length() == 0) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces,
                            Toast.LENGTH_LONG).show();
                } else {
                    server_password_EditText.setOnKeyListener(new OnKeyListener() {
                        public boolean onKey(View v, int keyCode, KeyEvent event) {
                            // If the event is a key-down event on the "enter" button
                            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                                // Perform action on key press
                                return true;
                            }
                            return false;
                        }
                    });
                    char[] server_password = (server_password_EditText.getText().toString().toCharArray());
                    Log.v(TAG, "server_password przeczytane z server_password_EditText: "
                            + new String(server_password));
                    int id_of_clicked_button = retrievedBundle.getInt("clicked_button");
                    Log.v(TAG, "id of clicked button: " + id_of_clicked_button);
                    Intent intent_start_ConnectToServer = new Intent(getApplicationContext(),
                            ConnectToServer.class);
                    final Intent intent_start_ConnectAndPlayService = new Intent(getApplicationContext(),
                            ConnectAndPlayService.class);
                    intent_start_ConnectAndPlayService.putExtra("server_name",
                            serverListArrayList.get(id_of_clicked_button).getServerName());
                    intent_start_ConnectAndPlayService.putExtra("IP_address",
                            serverListArrayList.get(id_of_clicked_button).getIPAddress());
                    intent_start_ConnectAndPlayService.putExtra("username",
                            serverListArrayList.get(id_of_clicked_button).getUsername());
                    intent_start_ConnectAndPlayService.putExtra("password", server_password);
                    startService(intent_start_ConnectAndPlayService);

                    connectingToSshProgressDialog = ProgressDialog.show(ServerList.this, "",
                            getString(R.string.text_for_progressdialog_from_connecttoserver), true, true);

                    removeDialog(DIALOG_GIVE_ME_A_SERVER_PASSWORD);
                    Arrays.fill(server_password, '0');
                }
            }
        });
        break;
    case DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED:
        dialog_ADD_NEW_SERVER_CRYPTO_ENABLED
                .setContentView(R.layout.layout_for_dialog_add_new_server_crypto_enabled);
        dialog_ADD_NEW_SERVER_CRYPTO_ENABLED.setTitle(R.string.title_for_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED);

        //Buttons
        final Button saveButton_in_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED = (Button) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED
                .findViewById(R.id.saveButton_crypto_enabled);
        final Button cancelButton_in_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED = (Button) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED
                .findViewById(R.id.cancelButton_crypto_enabled);
        saveButton_in_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                EditText server_nameEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED
                        .findViewById(R.id.server_nameEditText_crypto_enabled);
                server_nameEditText.setOnKeyListener(new OnKeyListener() {
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        // If the event is a key-down event on the "enter" button
                        if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                            // Perform action on key press
                            return true;
                        }
                        return false;
                    }
                });
                EditText IP_addressEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED
                        .findViewById(R.id.IP_addressEditText_crypto_enabled);
                IP_addressEditText.setOnKeyListener(new OnKeyListener() {
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        // If the event is a key-down event on the "enter" button
                        if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                            // Perform action on key press
                            return true;
                        }
                        return false;
                    }
                });
                EditText usernameEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED
                        .findViewById(R.id.usernameEditText_crypto_enabled);
                usernameEditText.setOnKeyListener(new OnKeyListener() {
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        // If the event is a key-down event on the "enter" button
                        if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                            // Perform action on key press
                            return true;
                        }
                        return false;
                    }
                });
                EditText passwordEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_ENABLED
                        .findViewById(R.id.passwordEditText_crypto_enabled);
                passwordEditText.setOnKeyListener(new OnKeyListener() {
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        // If the event is a key-down event on the "enter" button
                        if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                            // Perform action on key press
                            return true;
                        }
                        return false;
                    }
                });

                Log.v(TAG, "obecna ilosc zapisanych serverow wynosi: " + serverListArrayList.size());

                if (server_nameEditText.getText().length() == 0 || IP_addressEditText.getText().length() == 0
                        || usernameEditText.getText().length() == 0
                        || passwordEditText.getText().length() == 0) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces,
                            Toast.LENGTH_LONG).show();
                    //}else if(!validateIP(IP_addressEditText.getText().toString())){
                    //Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address, Toast.LENGTH_LONG).show();
                    //}else if (server_nameEditText.getText().toString().matches(".*\\s+.*") || IP_addressEditText.getText().toString().matches(".*\\s+.*") || usernameEditText.getText().toString().matches(".*\\s+.*") || passwordEditText.getText().toString().matches(".*\\s+.*")){   
                    //Toast.makeText(getApplicationContext(), R.string.text_for_toast_fields_should_not_contain_a_whitespace_character, Toast.LENGTH_LONG).show();
                } else if (!(isIPv4OrIPv6(IP_addressEditText.getText().toString()))) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address,
                            Toast.LENGTH_LONG).show();

                } else {
                    Server server = new Server();
                    server.setServerName(server_nameEditText.getText().toString());
                    server.setIPAddress(IP_addressEditText.getText().toString());
                    server.setUsername(usernameEditText.getText().toString());
                    server.setPassword(passwordEditText.getText().toString().toCharArray());

                    serverListArrayList.add(server);
                    if (appPasswordcharArray == null) {
                        showDialog(
                                DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE);
                        //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password);   //sprawdzi czy bdzie dziaa bez tego e niby w onPause() wystarczy
                        removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED);

                    } else {
                        Log.v(TAG, server.getServerName());
                        Log.v(TAG, server.getIPAddress());
                        Log.v(TAG, server.getUsername());
                        Log.v(TAG, new String(server.getPassword()));

                        removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED);
                        finish();
                        Intent intent = new Intent(mContext, ServerList.class);
                        startActivity(intent);
                    }
                }

            }

        });

        cancelButton_in_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED);
            }

        });
        dialog_ADD_NEW_SERVER_CRYPTO_ENABLED.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                // TODO Auto-generated method stub

            }
        });
        break;
    case DIALOG_ADD_NEW_SERVER_CRYPTO_DISABLED:
        dialog_ADD_NEW_SERVER_CRYPTO_DISABLED
                .setContentView(R.layout.layout_for_dialog_add_new_server_crypto_disabled);
        dialog_ADD_NEW_SERVER_CRYPTO_DISABLED.setTitle(R.string.title_for_dialog_ADD_NEW_SERVER_CRYPTO_ENABLED); //title is the same

        //Buttons
        final Button saveButton_in_dialog_ADD_NEW_SERVER_CRYPTO_DISABLED = (Button) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED
                .findViewById(R.id.saveButton_crypto_disabled);
        final Button cancelButton_in_dialog_ADD_NEW_SERVER_CRYPTO_DISABLED = (Button) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED
                .findViewById(R.id.cancelButton_crypto_disabled);
        saveButton_in_dialog_ADD_NEW_SERVER_CRYPTO_DISABLED.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                EditText server_nameEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED
                        .findViewById(R.id.server_nameEditText_crypto_disabled);
                server_nameEditText.setOnKeyListener(new OnKeyListener() {
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        // If the event is a key-down event on the "enter" button
                        if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                            // Perform action on key press
                            return true;
                        }
                        return false;
                    }
                });
                EditText IP_addressEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED
                        .findViewById(R.id.IP_addressEditText_crypto_disabled);
                IP_addressEditText.setOnKeyListener(new OnKeyListener() {
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        // If the event is a key-down event on the "enter" button
                        if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                            // Perform action on key press
                            return true;
                        }
                        return false;
                    }
                });
                EditText usernameEditText = (EditText) dialog_ADD_NEW_SERVER_CRYPTO_DISABLED
                        .findViewById(R.id.usernameEditText_crypto_disabled);
                usernameEditText.setOnKeyListener(new OnKeyListener() {
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        // If the event is a key-down event on the "enter" button
                        if ((event.getAction() == KeyEvent.ACTION_DOWN)
                                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                            // Perform action on key press
                            return true;
                        }
                        return false;
                    }
                });

                Log.v(TAG, "obecna ilosc zapisanych serverow wynosi: " + serverListArrayList.size());
                if (server_nameEditText.getText().length() == 0 || IP_addressEditText.getText().length() == 0
                        || usernameEditText.getText().length() == 0) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces,
                            Toast.LENGTH_LONG).show();
                    //}else if(!validateIP(IP_addressEditText.getText().toString())){
                    //Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address, Toast.LENGTH_LONG).show();
                    //}else if (server_nameEditText.getText().toString().matches(".*\\s+.*") || IP_addressEditText.getText().toString().matches(".*\\s+.*") || usernameEditText.getText().toString().matches(".*\\s+.*") || passwordEditText.getText().toString().matches(".*\\s+.*")){   
                    //Toast.makeText(getApplicationContext(), R.string.text_for_toast_fields_should_not_contain_a_whitespace_character, Toast.LENGTH_LONG).show();
                } else if (!(isIPv4OrIPv6(IP_addressEditText.getText().toString()))) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address,
                            Toast.LENGTH_LONG).show();

                } else {
                    Server server = new Server();

                    server.setServerName(server_nameEditText.getText().toString());
                    server.setIPAddress(IP_addressEditText.getText().toString());
                    server.setUsername(usernameEditText.getText().toString());
                    server.setPassword("a_blank_password".toCharArray());

                    serverListArrayList.add(server);

                    //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password);

                    Log.v(TAG, server.getServerName());
                    Log.v(TAG, server.getIPAddress());
                    Log.v(TAG, server.getUsername());
                    Log.v(TAG, new String(server.getPassword()));

                    removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_DISABLED);

                    finish();
                    Intent intent = new Intent(mContext, ServerList.class);
                    startActivity(intent);
                }
            }
        });

        cancelButton_in_dialog_ADD_NEW_SERVER_CRYPTO_DISABLED.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                removeDialog(DIALOG_ADD_NEW_SERVER_CRYPTO_DISABLED);
            }

        });

        break;

    case DIALOG_CHOOSE_SERVER_TO_EDIT:
        Log.v(TAG, "Wszedem do onCreate DIALOG_CHOOSE_SERVER_TO_EDIT");
        itemsFor_DIALOG_EDIT_SERVER = new CharSequence[serverListArrayList.size()];
        for (int i = 0; i < serverListArrayList.size(); i++) {

            itemsFor_DIALOG_EDIT_SERVER[i] = serverListArrayList.get(i).getServerName();
            Log.v(TAG, "Server_name :" + itemsFor_DIALOG_EDIT_SERVER[i]);
        }
        AlertDialog.Builder builder_for_DIALOG_CHOSE_SERVER_TO_EDIT = new AlertDialog.Builder(this);
        builder_for_DIALOG_CHOSE_SERVER_TO_EDIT.setTitle(R.string.title_for_dialog_CHOSE_SERVER_TO_EDIT);
        builder_for_DIALOG_CHOSE_SERVER_TO_EDIT.setItems(itemsFor_DIALOG_EDIT_SERVER,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog_CHOSE_SERVER_TO_EDIT, int item) {
                        //Toast.makeText(getApplicationContext(), items_for_DIALOG_EDIT_SERVER[item], Toast.LENGTH_SHORT).show();
                        serverToEditint = item;
                        Log.v(TAG, "server do edycji ma numer: " + item);
                        removeDialog(DIALOG_CHOOSE_SERVER_TO_EDIT);
                        if (isCryptoEnabledboolean == true) {
                            showDialog(DIALOG_EDIT_SERVER_CRYPTO_ENABLED);
                        } else {
                            showDialog(DIALOG_EDIT_SERVER_CRYPTO_DISABLED);
                        }
                    }
                });
        dialog_CHOSE_SERVER_TO_EDIT = builder_for_DIALOG_CHOSE_SERVER_TO_EDIT.create();

        break;
    case DIALOG_EDIT_SERVER_CRYPTO_ENABLED:

        dialog_EDIT_SERVER_CRYPTO_ENABLED.setContentView(R.layout.layout_for_dialog_edit_server_crypto_enabled);
        dialog_EDIT_SERVER_CRYPTO_ENABLED.setTitle(R.string.title_for_dialog_EDIT_SERVER_CRYPTO_ENABLED);

        //Buttons
        final Button saveButton_from_DIALOG_EDIT_SERVER = (Button) dialog_EDIT_SERVER_CRYPTO_ENABLED
                .findViewById(R.id.saveButton_in_dialog_edit_server_crypto_enabled);
        final Button cancelButton_from_DIALOG_EDIT_SERVER = (Button) dialog_EDIT_SERVER_CRYPTO_ENABLED
                .findViewById(R.id.cancelButton_in_dialog_edit_server_crypto_enabled);

        final EditText server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED = (EditText) dialog_EDIT_SERVER_CRYPTO_ENABLED
                .findViewById(R.id.server_name_in_dialog_edit_server_EditText_crypto_enabled_from_edit_server);
        server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED
                .setText(serverListArrayList.get(serverToEditint).getServerName());
        server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on key press
                    return true;
                }
                return false;
            }
        });
        final EditText IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED = (EditText) dialog_EDIT_SERVER_CRYPTO_ENABLED
                .findViewById(R.id.IP_address_in_dialog_EditText_crypto_enabled_from_edit_server);
        IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED
                .setText(serverListArrayList.get(serverToEditint).getIPAddress());
        IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on key press
                    return true;
                }
                return false;
            }
        });
        final EditText usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED = (EditText) dialog_EDIT_SERVER_CRYPTO_ENABLED
                .findViewById(R.id.username_in_dialog_edit_server_EditText_crypto_enabled_from_edit_server);
        usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED
                .setText(serverListArrayList.get(serverToEditint).getUsername());
        usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on key press
                    return true;
                }
                return false;
            }
        });

        final EditText passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED = (EditText) dialog_EDIT_SERVER_CRYPTO_ENABLED
                .findViewById(R.id.password_in_dialog_edit_server_EditText_crypto_enabled_from_edit_server);
        passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED
                .setText(new String(serverListArrayList.get(serverToEditint).getPassword()));
        passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on key press
                    return true;
                }
                return false;
            }
        });

        saveButton_from_DIALOG_EDIT_SERVER.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Log.v(TAG, "obecna ilosc zapisanych serverow wynosi: " + serverListArrayList.size());
                if (server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().length() == 0
                        || IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().length() == 0
                        || usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().length() == 0
                        || passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().length() == 0) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces,
                            Toast.LENGTH_LONG).show();
                } else if (!(isIPv4OrIPv6(
                        IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().toString()))) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address,
                            Toast.LENGTH_LONG).show();

                } else {
                    Server server = new Server();

                    server.setServerName(
                            server_nameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().toString());
                    server.setIPAddress(
                            IP_addressEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().toString());
                    server.setUsername(
                            usernameEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText().toString());
                    server.setPassword(passwordEditText_in_dialog_EDIT_SERVER_CRYPTO_ENABLED.getText()
                            .toString().toCharArray()); //server_nameEditText.getText().toString() to nazwa pliku

                    serverListArrayList.set(serverToEditint, server);
                    if (appPasswordcharArray == null) {
                        showDialog(
                                DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE);
                        //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password);   //sprawdzi czy bdzie dziaa bez tego e niby w onPause() wystarczy
                        removeDialog(DIALOG_EDIT_SERVER_CRYPTO_ENABLED);

                    } else {
                        Log.v(TAG, server.getServerName());
                        Log.v(TAG, server.getIPAddress());
                        Log.v(TAG, server.getUsername());
                        Log.v(TAG, new String(server.getPassword()));

                        removeDialog(DIALOG_EDIT_SERVER_CRYPTO_ENABLED);
                        finish();
                        Intent intent = new Intent(mContext, ServerList.class);
                        startActivity(intent);
                    }
                }
            }

        });

        cancelButton_from_DIALOG_EDIT_SERVER.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                removeDialog(DIALOG_EDIT_SERVER_CRYPTO_ENABLED);
            }

        });
        dialog_EDIT_SERVER_CRYPTO_ENABLED.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                // TODO Auto-generated method stub

            }
        });
        break;

    case DIALOG_EDIT_SERVER_CRYPTO_DISABLED:

        dialog_EDIT_SERVER_CRYPTO_DISABLED
                .setContentView(R.layout.layout_for_dialog_edit_server_crypto_disabled);
        dialog_EDIT_SERVER_CRYPTO_DISABLED.setTitle(R.string.title_for_dialog_EDIT_SERVER_CRYPTO_ENABLED);

        //Buttons
        final Button saveButton_in_dialog_EDIT_SERVER_CRYPTO_DISABLED = (Button) dialog_EDIT_SERVER_CRYPTO_DISABLED
                .findViewById(R.id.saveButton_in_dialog_edit_server_crypto_disabled);
        final Button cancelButton_in_dialog_EDIT_SERVER_CRYPTO_DISABLED = (Button) dialog_EDIT_SERVER_CRYPTO_DISABLED
                .findViewById(R.id.cancelButton_in_dialog_edit_server_crypto_disabled);

        final EditText server_nameEditText = (EditText) dialog_EDIT_SERVER_CRYPTO_DISABLED
                .findViewById(R.id.server_name_in_dialog_edit_server_EditText_crypto_disabled_from_edit_server);
        server_nameEditText.setText(serverListArrayList.get(serverToEditint).getServerName());
        server_nameEditText.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on key press
                    return true;
                }
                return false;
            }
        });
        final EditText IP_addressEditText = (EditText) dialog_EDIT_SERVER_CRYPTO_DISABLED
                .findViewById(R.id.IP_address_in_dialog_edit_server_EditText_crypto_disabled_from_edit_server);
        IP_addressEditText.setText(serverListArrayList.get(serverToEditint).getIPAddress());
        IP_addressEditText.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on key press
                    return true;
                }
                return false;
            }
        });
        final EditText usernameEditText = (EditText) dialog_EDIT_SERVER_CRYPTO_DISABLED
                .findViewById(R.id.username_in_dialog_edit_server_EditText_crypto_disabled_from_edit_server);
        usernameEditText.setText(serverListArrayList.get(serverToEditint).getUsername());
        usernameEditText.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    // Perform action on key press
                    return true;
                }
                return false;
            }
        });

        saveButton_in_dialog_EDIT_SERVER_CRYPTO_DISABLED.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Log.v(TAG, "obecna ilosc zapisanych serverow wynosi: " + serverListArrayList.size());
                if (server_nameEditText.getText().length() == 0 || IP_addressEditText.getText().length() == 0
                        || usernameEditText.getText().length() == 0) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_fill_up_the_empty_spaces,
                            Toast.LENGTH_LONG).show();
                } else if (!(isIPv4OrIPv6(IP_addressEditText.getText().toString()))) {
                    Toast.makeText(getApplicationContext(), R.string.text_for_toast_correct_IP_address,
                            Toast.LENGTH_LONG).show();

                } else {
                    Server server = new Server();

                    server.setServerName(server_nameEditText.getText().toString());
                    server.setIPAddress(IP_addressEditText.getText().toString());
                    server.setUsername(usernameEditText.getText().toString());
                    server.setPassword("a_blank_password".toCharArray());

                    serverListArrayList.set(serverToEditint, server);
                    //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password);

                    Log.v(TAG, server.getServerName());
                    Log.v(TAG, server.getIPAddress());
                    Log.v(TAG, server.getUsername());
                    Log.v(TAG, new String(server.getPassword()));

                    removeDialog(DIALOG_EDIT_SERVER_CRYPTO_DISABLED);
                    finish();
                    Intent intent = new Intent(mContext, ServerList.class);
                    startActivity(intent);
                }
            }

        });

        cancelButton_in_dialog_EDIT_SERVER_CRYPTO_DISABLED.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                removeDialog(DIALOG_EDIT_SERVER_CRYPTO_DISABLED);
            }

        });

        break;

    case DIALOG_DELETE_SERVER:
        Log.v(TAG, "Wszedem do onCreate DIALOG_DELETE_SERVER");
        itemsFor_DIALOG_DELETE_SERVER = new CharSequence[serverListArrayList.size()];
        for (int i = 0; i < serverListArrayList.size(); i++) {

            itemsFor_DIALOG_DELETE_SERVER[i] = serverListArrayList.get(i).getServerName();
            Log.v(TAG, "Server_name :" + itemsFor_DIALOG_DELETE_SERVER[i]);
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle(R.string.title_for_dialog_DELETE_SERVER);
        builder.setItems(itemsFor_DIALOG_DELETE_SERVER, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog_DELETE_SERVER, int item) {

                serverToDelete = item;
                showDialog(DIALOG_DO_DELATE);
                /*
                 serverListArrayList.remove(item);
                 if (appPasswordcharArray == null){
                showDialog(DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE);
                //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password);   //sprawdzi czy bdzie dziaa bez tego e niby w onPause() wystarczy
                            
                }else{   
                                  
                 finish();
                  Intent intent = new Intent(mContext, ServerList.class);
                    startActivity(intent);
                }
                */
            }
        });

        dialog_DELETE_SERVER = builder.create();

        break;

    case DIALOG_DO_DELATE:
        Log.v(TAG, "Wszedem do onCreate DIALOG_DO_DELATE");
        AlertDialog.Builder builderDIALOG_DO_DELATE = new AlertDialog.Builder(mContext);
        builderDIALOG_DO_DELATE.setTitle(getResources().getString(R.string.title_for_dialog_DO_DELETE));
        builderDIALOG_DO_DELATE.setMessage(getResources().getString(R.string.message_in_dialog_DO_DELATE) + " "
                + itemsFor_DIALOG_DELETE_SERVER[serverToDelete] + "?");
        // Add the buttons
        builderDIALOG_DO_DELATE.setPositiveButton(R.string.text_for_do_delete_button,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User clicked OK button
                        serverListArrayList.remove(serverToDelete);
                        if (appPasswordcharArray == null) {
                            showDialog(
                                    DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE);
                            //a_XMLReaderWrriter.create_encrypted_XMLFile_with_server_list(server_list, app_password);   //sprawdzi czy bdzie dziaa bez tego e niby w onPause() wystarczy
                            removeDialog(DIALOG_DO_DELATE);
                        } else {

                            finish();
                            Intent intent = new Intent(mContext, ServerList.class);
                            startActivity(intent);
                            removeDialog(DIALOG_DO_DELATE);
                        }

                    }
                });
        builderDIALOG_DO_DELATE.setNegativeButton(R.string.text_for_cancel_button,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User cancelled the dialog
                        removeDialog(DIALOG_DO_DELATE);
                    }
                });
        // Set other dialog properties

        // Create the AlertDialog
        dialog_DO_DELATE = builderDIALOG_DO_DELATE.create();

        break;

    case DIALOG_LICENSE:
        // EULA title
        String title = getResources().getString(R.string.app_name);

        // EULA text
        String message = getResources().getString(R.string.Licences_text);

        AlertDialog.Builder builderDIALOG_LICENSE = new AlertDialog.Builder(mContext).setTitle(title)
                .setMessage(message)
                .setPositiveButton(R.string.text_for_cancel_button, new Dialog.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                        dialogInterface.dismiss();

                    }
                });

        // Create the AlertDialog
        dialog_LICENSE = builderDIALOG_LICENSE.create();

        break;

    default:
        dialog = null;
    }
    if (id == DIALOG_FIRST_TIME_RUNING) {
        dialog = dialog_FIRST_TIME_RUNING;
    }
    if (id == DIALOG_GIVE_ME_A_APP_PASSWORD) {
        dialog = dialog_GIVE_ME_A_APP_PASSWORD;
    }
    if (id == DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE) {
        dialog = dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOILEAN_IS_FALSE;
    }
    if (id == DIALOG_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST) {
        dialog = dialog_GIVE_ME_A_APP_PASSWORD_BECAUSE_REMEMBER_APP_PASSWORD_IN_SESION_BOOLEAN_IS_FALSE_AND_I_NEED_IT_TO_START_SETTINGSFORSERVERLIST;
    }
    if (id == DIALOG_GIVE_ME_A_SERVER_PASSWORD) {
        dialog = dialog_GIVE_ME_A_SERVER_PASSWORD;
    }
    if (id == DIALOG_ADD_NEW_SERVER_CRYPTO_ENABLED) {
        dialog = dialog_ADD_NEW_SERVER_CRYPTO_ENABLED;
    }
    if (id == DIALOG_ADD_NEW_SERVER_CRYPTO_DISABLED) {
        dialog = dialog_ADD_NEW_SERVER_CRYPTO_DISABLED;
    }
    if (id == DIALOG_DELETE_SERVER) {
        dialog = dialog_DELETE_SERVER;
    }
    if (id == DIALOG_DO_DELATE) {
        dialog = dialog_DO_DELATE;
    }
    if (id == DIALOG_CHOOSE_SERVER_TO_EDIT) {
        dialog = dialog_CHOSE_SERVER_TO_EDIT;
    }
    if (id == DIALOG_EDIT_SERVER_CRYPTO_ENABLED) {
        dialog = dialog_EDIT_SERVER_CRYPTO_ENABLED;
    }
    if (id == DIALOG_EDIT_SERVER_CRYPTO_DISABLED) {
        dialog = dialog_EDIT_SERVER_CRYPTO_DISABLED;
    }
    if (id == DIALOG_LICENSE) {
        dialog = dialog_LICENSE;
    }

    return dialog;
}

From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java

public boolean dispatchKeyEvent(KeyEvent event) {

    int action = event.getAction();
    int keyCode = event.getKeyCode();

    LOG.debug("Got key event: " + keyCode + " with action " + action);

    if (searchMenuItem != null && searchMenuItem.isActionViewExpanded()) {
        boolean result = searchMenuItem.getActionView().dispatchKeyEvent(event);

        if (result) {
            return true;
        }/*from  w  ww.  j  a va2 s.c o  m*/
    }

    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP = 92;
    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM = 93;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP = 94;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM = 95;

    boolean nook_touch_up_press = false;

    if (isAnimating() && action == KeyEvent.ACTION_DOWN) {
        stopAnimating();
        return true;
    }

    /*
     * Tricky bit of code here: if we are NOT running TTS,
     * we want to be able to start it using the play/pause button.
     *
     * When we ARE running TTS, we'll get every media event twice:
     * once through the receiver and once here if focused.
     *
     * So, we only try to read media events here if tts is running.
     */
    if (!ttsIsRunning() && dispatchMediaKeyEvent(event)) {
        return true;
    }

    LOG.debug("Key event is NOT a media key event.");

    switch (keyCode) {

    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        return handleVolumeButtonEvent(event);

    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageDown(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageUp(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_BACK:
        if (action == KeyEvent.ACTION_DOWN) {

            if (titleBarLayout.getVisibility() == View.VISIBLE) {
                hideTitleBar();
                updateFromPrefs();
                return true;
            } else if (bookView.hasPrevPosition()) {
                bookView.goBackInHistory();
                return true;
            }
        }

        return false;

    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP:
        nook_touch_up_press = true;
    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM:
        if (action == KeyEvent.ACTION_UP)
            return false;
        if (nook_touch_up_press == config.isNookUpButtonForward())
            pageDown(Orientation.HORIZONTAL);
        else
            pageUp(Orientation.HORIZONTAL);
        return true;
    }

    LOG.debug("Not handling key event: returning false.");
    return false;
}

From source file:org.ednovo.goorusearchwidget.SearchResults_resource.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_results_resource);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    Bundle extra = getIntent().getExtras();

    if (extra != null) {
        searchKeyword = extra.getString("keyWord").trim();
    }/*from   w  ww.  ja  va 2  s .co m*/
    prefsPrivate = getSharedPreferences(PREFS_PRIVATE, Context.MODE_PRIVATE);

    token = prefsPrivate.getString("token", "");

    imageViewClose = (ImageView) findViewById(R.id.imageViewClose);
    imageViewSearch = (ImageView) findViewById(R.id.imageViewSearch);
    editTextSearchResults = (EditText) findViewById(R.id.textViewSearch);
    switchResColl = (Switch) findViewById(R.id.switchResColl);
    dialog1 = new Dialog(this);
    editTextSearchResults.setText(searchKeyword);
    imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
    dialog = new ProgressDialog(this);
    dialog.setTitle("gooru");
    dialog.setMessage("Please wait while loading...");
    dialog.setCancelable(false);
    dialog.show();

    if (checkInternetConnection()) {
        new getResources().execute();
    } else {
        showDialog("Please Check Internet connection");
        new getResources().execute();
    }

    // scroll views

    videoScroll = (HorizontalScrollView) findViewById(R.id.videoScroll);
    interactiveScroll = (HorizontalScrollView) findViewById(R.id.interactiveScroll);
    websiteScroll = (HorizontalScrollView) findViewById(R.id.websiteScroll);
    textbookScroll = (HorizontalScrollView) findViewById(R.id.textbookScroll);
    examScroll = (HorizontalScrollView) findViewById(R.id.examScroll);
    handoutScroll = (HorizontalScrollView) findViewById(R.id.handoutScroll);
    slideScroll = (HorizontalScrollView) findViewById(R.id.slideScroll);
    lessonScroll = (HorizontalScrollView) findViewById(R.id.lessonScroll);
    // category image load more resources
    videoRight = (ImageView) findViewById(R.id.videoRight);
    interactiveRight = (ImageView) findViewById(R.id.interactiveRight);
    websiteRight = (ImageView) findViewById(R.id.websiteRight);
    textbookRight = (ImageView) findViewById(R.id.textbookRight);
    examRight = (ImageView) findViewById(R.id.examRight);
    handoutRight = (ImageView) findViewById(R.id.handoutRight);
    slideRight = (ImageView) findViewById(R.id.slideRight);
    lessonRight = (ImageView) findViewById(R.id.lessonRight);

    videoRight.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (checkInternetConnection()) {
                videoCount++;
                dialog.setTitle("gooru");
                dialog.setMessage("Please wait while loading...");
                dialog.setCancelable(false);
                dialog.show();
                new getNext5Videos().execute();
            } else {
                showDialog("Please Check Internet connection");
            }

        }
    });
    interactiveRight.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (checkInternetConnection()) {
                interactiveCount++;
                dialog.setTitle("gooru");
                dialog.setMessage("Please wait while loading...");
                dialog.setCancelable(false);
                dialog.show();
                new getNext5interactive().execute();
            } else {
                showDialog("Please Check Internet connection");
            }

        }
    });

    imageViewSearch.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String searchKeyword = editTextSearchResults.getText().toString().trim();

            if (searchKeyword.length() > 0) {

                Intent intentResResults = new Intent(getBaseContext(), SearchResults_resource.class);
                searchKeyword = editTextSearchResults.getText().toString().trim();
                Log.i("Search :", searchKeyword);
                Bundle extras = new Bundle();
                extras.putString("keyWord", searchKeyword);
                intentResResults.putExtras(extras);
                startActivity(intentResResults);
                finish();

            } else {
                dialog1.setTitle("Please enter a Search keyword");
                dialog1.show();
            }
        }
    });

    websiteRight.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (checkInternetConnection()) {
                websiteCount++;
                dialog.setTitle("gooru");
                dialog.setMessage("Please wait while loading...");
                dialog.setCancelable(false);
                dialog.show();
                new getNext5website().execute();
            } else {
                showDialog("Please Check Internet connection");
            }

        }
    });
    textbookRight.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (checkInternetConnection()) {
                textbookCount++;
                dialog.setTitle("gooru");
                dialog.setMessage("Please wait while loading...");
                dialog.setCancelable(false);
                dialog.show();
                new getNext5textbook().execute();
            } else {
                showDialog("Please Check Internet connection");
            }

        }
    });
    examRight.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (checkInternetConnection()) {
                examCount++;
                dialog.setTitle("gooru");
                dialog.setMessage("Please wait while loading...");
                dialog.setCancelable(false);
                dialog.show();
                new getNext5exam().execute();
            } else {
                showDialog("Please Check Internet connection");
            }

        }
    });
    handoutRight.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (checkInternetConnection()) {
                handoutCount++;
                dialog.setTitle("gooru");
                dialog.setMessage("Please wait while loading...");
                dialog.setCancelable(false);
                dialog.show();
                new getNext5handout().execute();
            } else {
                showDialog("Please Check Internet connection");
            }

        }
    });
    slideRight.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (checkInternetConnection()) {
                slideCount++;
                dialog.setTitle("gooru");
                dialog.setMessage("Please wait while loading...");
                dialog.setCancelable(false);
                dialog.show();
                new getNext5slide().execute();
            } else {
                showDialog("Please Check Internet connection");
            }

        }
    });
    lessonRight.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (checkInternetConnection()) {
                lessonCount++;
                dialog.setTitle("gooru");
                dialog.setMessage("Please wait while loading...");
                dialog.setCancelable(false);
                dialog.show();
                new getNext5lesson().execute();
            } else {
                showDialog("Please Check Internet connection");
            }

        }
    });

    editTextSearchResults.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    String searchKeyword = editTextSearchResults.getText().toString().trim();

                    if (searchKeyword.length() > 0) {

                        Log.i("Resources", searchKeyword);
                        Intent intentResResults = new Intent(getBaseContext(), SearchResults_resource.class);

                        Bundle extras = new Bundle();
                        extras.putString("keyWord", searchKeyword);

                        intentResResults.putExtras(extras);
                        startActivity(intentResResults);
                        finish();
                    } else {
                        dialog1.setTitle("Please enter a Search keyword");
                        dialog1.show();
                    }
                    return true;
                default:
                    break;
                }
            }
            return false;
        }
    });

    imageViewClose.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            finish();
        }
    });

}

From source file:com.igniva.filemanager.activities.MainActivity.java

void initialiseViews() {
    appBarLayout = (AppBarLayout) findViewById(R.id.lin);

    if (!ImageLoader.getInstance().isInited()) {

        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));
    }/*from  w  ww.  j  a v a2  s  .  c  o m*/
    displayImageOptions = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.amaze_header)
            .showImageForEmptyUri(R.drawable.amaze_header).showImageOnFail(R.drawable.amaze_header)
            .cacheInMemory(true).cacheOnDisk(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565)
            .build();

    mScreenLayout = (CoordinatorLayout) findViewById(R.id.main_frame);
    buttonBarFrame = (FrameLayout) findViewById(R.id.buttonbarframe);

    //buttonBarFrame.setBackgroundColor(Color.parseColor(currentTab==1 ? skinTwo : skin));
    drawerHeaderLayout = getLayoutInflater().inflate(R.layout.drawerheader, null);
    drawerHeaderParent = (RelativeLayout) drawerHeaderLayout.findViewById(R.id.drawer_header_parent);
    drawerHeaderView = (View) drawerHeaderLayout.findViewById(R.id.drawer_header);
    mFabBackground = findViewById(R.id.fab_bg);
    drawerHeaderView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Intent intent;
            if (Build.VERSION.SDK_INT < 19) {
                intent = new Intent();
                intent.setAction(Intent.ACTION_GET_CONTENT);
            } else {
                intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

            }
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            startActivityForResult(intent, image_selector_request_code);
            return false;
        }
    });
    drawerProfilePic = (RoundedImageView) drawerHeaderLayout.findViewById(R.id.profile_pic);
    mGoogleName = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_name);
    mGoogleId = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_email);
    toolbar = (Toolbar) findViewById(R.id.action_bar);
    /* For SearchView, see onCreateOptionsMenu(Menu menu)*/
    TOOLBAR_START_INSET = toolbar.getContentInsetStart();
    setSupportActionBar(toolbar);
    frameLayout = (FrameLayout) findViewById(R.id.content_frame);
    indicator_layout = findViewById(R.id.indicator_layout);
    mDrawerLinear = (ScrimInsetsRelativeLayout) findViewById(R.id.left_drawer);
    if (theme1 == 1)
        mDrawerLinear.setBackgroundColor(Color.parseColor("#303030"));
    else
        mDrawerLinear.setBackgroundColor(Color.WHITE);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    //mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    mDrawerList = (ListView) findViewById(R.id.menu_drawer);
    drawerHeaderView.setBackgroundResource(R.drawable.amaze_header);
    //drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    if (findViewById(R.id.tab_frame) != null) {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerLinear);
        mDrawerLayout.openDrawer(mDrawerLinear);
        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
        isDrawerLocked = true;
    } else if (findViewById(R.id.tab_frame) == null) {

        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerLinear);
        mDrawerLayout.closeDrawer(mDrawerLinear);
        isDrawerLocked = false;
    }
    mDrawerList.addHeaderView(drawerHeaderLayout);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    View v = findViewById(R.id.fab_bg);
    /*if (theme1 != 1)
    v.setBackgroundColor(Color.parseColor("#a6ffffff"));*/
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            floatingActionButton.close(true);
            utils.revealShow(view, false);
            if (isSearchViewEnabled)
                hideSearchView();
        }
    });

    pathbar = (LinearLayout) findViewById(R.id.pathbar);
    buttons = (LinearLayout) findViewById(R.id.buttons);
    scroll = (HorizontalScrollView) findViewById(R.id.scroll);
    scroll1 = (HorizontalScrollView) findViewById(R.id.scroll1);
    scroll.setSmoothScrollingEnabled(true);
    scroll1.setSmoothScrollingEnabled(true);
    ImageView divider = (ImageView) findViewById(R.id.divider1);
    if (theme1 == 0)
        divider.setImageResource(R.color.divider);
    else
        divider.setImageResource(R.color.divider_dark);

    setDrawerHeaderBackground();
    View settingsbutton = findViewById(R.id.settingsbutton);
    if (theme1 == 1) {
        settingsbutton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) settingsbutton.findViewById(R.id.settingicon))
                .setImageResource(R.drawable.ic_settings_white_48dp);
        ((TextView) settingsbutton.findViewById(R.id.settingtext))
                .setTextColor(getResources().getColor(android.R.color.white));
    }
    settingsbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent in = new Intent(MainActivity.this, Preferences.class);
            finish();
            final int enter_anim = android.R.anim.fade_in;
            final int exit_anim = android.R.anim.fade_out;
            Activity s = MainActivity.this;
            s.overridePendingTransition(exit_anim, enter_anim);
            s.finish();
            s.overridePendingTransition(enter_anim, exit_anim);
            s.startActivity(in);
        }

    });
    View appbutton = findViewById(R.id.appbutton);
    if (theme1 == 1) {
        appbutton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) appbutton.findViewById(R.id.appicon)).setImageResource(R.drawable.ic_doc_apk_white);
        ((TextView) appbutton.findViewById(R.id.apptext))
                .setTextColor(getResources().getColor(android.R.color.white));
    }
    appbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager()
                    .beginTransaction();
            transaction2.replace(R.id.content_frame, new AppsList());
            findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2))
                    .start();
            pending_fragmentTransaction = transaction2;
            if (!isDrawerLocked)
                mDrawerLayout.closeDrawer(mDrawerLinear);
            else
                onDrawerClosed();
            select = -2;
            adapter.toggleChecked(false);
        }
    });

    View ftpButton = findViewById(R.id.ftpbutton);
    if (theme1 == 1) {
        ftpButton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) ftpButton.findViewById(R.id.ftpicon)).setImageResource(R.drawable.ic_ftp_dark);
        ((TextView) ftpButton.findViewById(R.id.ftptext))
                .setTextColor(getResources().getColor(android.R.color.white));
    }
    ftpButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager()
                    .beginTransaction();
            transaction2.replace(R.id.content_frame, new FTPServerFragment());
            findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2))
                    .start();
            pending_fragmentTransaction = transaction2;
            if (!isDrawerLocked)
                mDrawerLayout.closeDrawer(mDrawerLinear);
            else
                onDrawerClosed();
            select = -2;
            adapter.toggleChecked(false);
        }
    });
    //getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor((currentTab==1 ? skinTwo : skin))));

    // status bar0
    sdk = Build.VERSION.SDK_INT;

    if (sdk == 20 || sdk == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        //tintManager.setStatusBarTintColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.drawer_layout)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        if (!isDrawerLocked)
            p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (Build.VERSION.SDK_INT >= 21) {

        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        //window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (isDrawerLocked) {
            window.setStatusBarColor((skinStatusBar));
        } else
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (colourednavigation)
            window.setNavigationBarColor(skinStatusBar);
    }

    searchViewLayout = (RelativeLayout) findViewById(R.id.search_view);
    searchViewEditText = (AppCompatEditText) findViewById(R.id.search_edit_text);
    ImageView clear = (ImageView) findViewById(R.id.search_close_btn);
    clear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchViewEditText.setText("");
        }
    });
    findViewById(R.id.img_view_back).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideSearchView();
        }
    });
    searchViewEditText.setOnKeyListener(new TextView.OnKeyListener() {
        @Override
        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)) {
                // Perform action on key press
                mainActivityHelper.search(searchViewEditText.getText().toString());
                hideSearchView();
                return true;
            }
            return false;
        }
    });

    //    searchViewEditText.setTextColor(getResources().getColor(android.R.color.black));
    //     searchViewEditText.setHintTextColor(Color.parseColor(BaseActivity.accentSkin));
}

From source file:com.koma.music.service.MusicService.java

private void setUpMediaSession() {
    mSession = new MediaSession(this, "KomaMusic");
    mSession.setCallback(new MediaSession.Callback() {
        @Override//from  w  w w. ja  v  a  2s.c o  m
        public void onPause() {
            pause();
            mPausedByTransientLossOfFocus = false;
        }

        @Override
        public void onPlay() {
            play();
        }

        @Override
        public void onSeekTo(long pos) {
            seek(pos);
        }

        @Override
        public void onSkipToNext() {
            gotoNext(true);
        }

        @Override
        public void onSkipToPrevious() {
            prev(false);
        }

        @Override
        public void onStop() {
            pause();
            mPausedByTransientLossOfFocus = false;
            seek(0);
            releaseServiceUiAndStop();
        }

        @Override
        public void onSkipToQueueItem(long id) {
            setQueuePosition((int) id);
        }

        @Override
        public boolean onMediaButtonEvent(@NonNull Intent mediaButtonIntent) {
            if (Intent.ACTION_MEDIA_BUTTON.equals(mediaButtonIntent.getAction())) {
                KeyEvent ke = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
                if (ke != null && ke.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK) {
                    if (ke.getAction() == KeyEvent.ACTION_UP) {
                        handleHeadsetHookClick(ke.getEventTime());
                    }
                    return true;
                }
            }
            return super.onMediaButtonEvent(mediaButtonIntent);
        }
    });

    PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(this, MediaButtonIntentReceiver.class),
            PendingIntent.FLAG_UPDATE_CURRENT);
    mSession.setMediaButtonReceiver(pi);

    mSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS);
}