Example usage for android.view KeyEvent ACTION_DOWN

List of usage examples for android.view KeyEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

To view the source code for android.view KeyEvent ACTION_DOWN.

Click Source Link

Document

#getAction value: the key has been pressed down.

Usage

From source file:org.bombusim.lime.fragments.ChatFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.chat, container, false);

    contactBar = (ContactBar) v.findViewById(R.id.contact_head);
    mMessageBox = (ChatEditText) v.findViewById(R.id.messageBox);
    mSendButton = (ImageButton) v.findViewById(R.id.sendButton);
    mSmileButton = (ImageButton) v.findViewById(R.id.smileButton);
    chatListView = (ListView) v.findViewById(R.id.chatListView);

    mChatActive = v.findViewById(R.id.chatActive);
    mChatInactive = v.findViewById(R.id.chatInactive);

    if (!getChatFragmentListener().isTabMode()) {
        contactBar.setVisibility(View.GONE);

        View abCustomView = getSherlockActivity().getSupportActionBar().getCustomView();

        contactBar = (ContactBar) abCustomView.findViewById(R.id.contactHeadActionbar);
        contactBar.removeBackground();/*  w w  w  .  j  ava  2s  .  c o m*/
    }

    registerForContextMenu(chatListView);
    enableTrackballTraversing();

    mSendButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            sendMessage();
        }
    });

    mSmileButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mMessageBox.showAddSmileDialog();
        }
    });

    //TODO: optional
    mMessageBox.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() != KeyEvent.ACTION_DOWN)
                return false; //filtering only KEY_DOWN

            if (keyCode != KeyEvent.KEYCODE_ENTER)
                return false;
            //if (event.isShiftPressed()) return false; //typing multiline messages with SHIFT+ENTER
            sendMessage();
            return true; //Key was processed
        }
    });

    mMessageBox.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() > 0)
                sendChatState(ChatStates.COMPOSING);
        }
    });

    //TODO: optional behavior
    //messageBox.setImeActionLabel("Send", EditorInfo.IME_ACTION_SEND); //Keeps IME opened
    mMessageBox.setImeActionLabel(getString(R.string.sendMessage), EditorInfo.IME_ACTION_DONE); //Closes IME

    mMessageBox.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            switch (actionId) {
            case EditorInfo.IME_ACTION_SEND:
                sendMessage();
                return true;
            case EditorInfo.IME_ACTION_DONE:
                sendMessage();
                return false; //let IME to be closed
            }
            return false;
        }
    });

    contactBar.getContactIconView().setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new ContactResourceSwitcher().showResources(getActivity(), visavis);
        }
    });

    return v;
}

From source file:com.itude.mobile.mobbl.core.controller.util.MBBasicViewController.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    _isDialogClosable = getArguments().getBoolean("closable", false);
    _isDialogFullscreen = getArguments().getBoolean("fullscreen", false);
    _isDialogCancelable = getArguments().getBoolean("cancelable", false) || _isDialogCancelable;

    if (_isDialogClosable) {
        ViewGroup view = buildInitialView(LayoutInflater.from(getActivity()));

        /*//from   ww  w  . ja  v a 2s.c o m
         * Add this view and a close button to a wrapper view that will be used as the content view of our AlertDialog
         */

        // unable to use the holo light theme as pre honeycomb doesn't know AlertDialog.Builder(context, theme) 
        AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
        AlertDialog dialog = adb.create();

        View content = addCloseButtonToClosableDialogView(view, dialog);

        dialog.setView(content);

        dialog.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
                    return onBackKeyPressed();
                }

                return false;
            }
        });

        return dialog;
    }

    if (_isDialogFullscreen) {
        setStyle(STYLE_NO_TITLE, android.R.style.Theme);
    }

    return super.onCreateDialog(savedInstanceState);
}

From source file:org.dmfs.tasks.InputTextDialogFragment.java

@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    // if the user clicks the back button
    if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) {
        // filter only the touch down event
        if (event.getAction() != KeyEvent.ACTION_DOWN) {
            // we assume that he don't want to save his input
            handleCancel();//from  ww w .  ja v  a2  s. co  m
        } else {
            return false;
        }
    }
    return false;
}

From source file:net.zorgblub.typhon.activity.ReadingActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {

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

    if (action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK && isDrawerOpen()) {
        closeNavigationDrawer();/*w  w w .j av a 2  s . c om*/
        return true;
    }

    if (readingFragment.dispatchKeyEvent(event)) {
        return true;
    }

    return super.dispatchKeyEvent(event);
}

From source file:org.profeda.dictionary.SearchActivity.java

/**
 * Called when the activity is first created.
 *//*from   w  w  w .j a v a  2s.  c  om*/
@Override
public void onCreate(Bundle savedInstanceState) {
    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(SearchActivity.this);

    if (pref.getBoolean("show_changelog", true) == true) {
        MessageBox.showChangeLog(this);
    }

    loadDictionaries(pref);

    if (pref.getBoolean("p_invert_colors", false) == true) {
        setTheme(R.style.Light);
    } else {
        setTheme(R.style.Dark);
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    dict = new Dict(this, pref.getString("dictFile", null));

    updateTitleBar();
    readMRU();

    final EditText searchbox = (EditText) findViewById(R.id.searchbox);
    final Button dictselectbutton = (Button) findViewById(R.id.dictselectbutton);
    final ListView listview = (ListView) findViewById(R.id.contentlist);

    listview.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView l, View v, int position, long id) {
            ListAdapter la = ((ListView) l).getAdapter();
            if (la instanceof GenericStringAdapter) {
                final String data = (String) la.getItem(position);
                if (data.startsWith("> ")) {
                    searchbox.setText(data.substring(2));
                    doSearch(true);
                }
            } else if (la instanceof DictListAdapter) {
                final String[] data = (String[]) la.getItem(position);

                final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, null);

                String[] menu = new String[langs.size() + 1];
                menu[0] = getString(R.string.copy_translation_to_clipboard);
                for (int i = 1; i < menu.length; i++)
                    menu[i] = String.format(getString(R.string.search_translation_in_language),
                            langs.get(i - 1).toLang);

                Matcher m = Pattern.compile("<b>(.*)<\\/b>.*").matcher(data[1]);
                if (!m.matches())
                    return;
                final String translation = m.group(1).trim();

                new AlertDialog.Builder(SearchActivity.this).setIcon(android.R.drawable.ic_dialog_info)
                        .setTitle(translation).setItems(menu, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                switch (arg1) {
                                case 0:
                                    ClipboardManager cm = (ClipboardManager) getSystemService(
                                            CLIPBOARD_SERVICE);
                                    cm.setText(translation);
                                    break;
                                default:
                                    dict = langs.get(arg1 - 1);
                                    readMRU();
                                    updateTitleBar();
                                    searchbox.setText(translation);
                                    doSearch(true);
                                }
                            }
                        }).show();
            }
        }
    });

    searchbox.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE
                    || event.getAction() == KeyEvent.ACTION_DOWN
                            && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                doSearch(true);
                return true;
            } else {
                return false;
            }
        }
    });

    final Drawable deleteIcon = getResources().getDrawable(R.drawable.textbox_clear);
    //deleteIcon.setBounds(0, 0, deleteIcon.getIntrinsicWidth(), deleteIcon.getIntrinsicHeight());
    deleteIcon.setBounds(0, 0, 51, 30); // wtf??? die Zahlen sind empirisch ermittelt... ab right>=52 springt die hhe des editText

    searchbox.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            searchbox.setCompoundDrawables(null, null, s.toString().equals("") ? null : deleteIcon, null);
            //searchbox.setCompoundDrawablesWithIntrinsicBounds(null, null, s.toString().equals("") ? null : deleteIcon, null);
            searchbox.setCompoundDrawablePadding(0);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (enableLivesearch && s.length() > 1 && dict.filePrefix != null && dictSearchInAction == false) {
                DictionarySearcher ds = new DictionarySearcher();
                ds.targetList = (ListView) findViewById(R.id.contentlist);
                ds.execute(dict.filePrefix, s.toString());
            }
            if (s.length() == 0) {
                displayMRU();
            }
        }
    });

    //searchbox.setCompoundDrawables(null, null, deleteIcon, null);
    searchbox.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (searchbox.getCompoundDrawables()[2] == null) {
                return false;
            }
            if (event.getAction() != MotionEvent.ACTION_UP) {
                return false;
            }
            if (event.getX() > searchbox.getWidth() - searchbox.getPaddingRight()
                    - deleteIcon.getIntrinsicWidth()) {
                searchbox.setText("");
                searchbox.setCompoundDrawables(null, null, null, null);
            }
            return false;
        }
    });

    dictselectbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            selectDictionary();
        }
    });

    ((Button) findViewById(R.id.dictswapbutton)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, dict.fromLang);
            if (langs.size() > 0) {
                dict = langs.get(0);
                readMRU();
                updateTitleBar();
                searchbox.setText("");
            } else {
                MessageBox.alert(SearchActivity.this, getString(R.string.no_reverse_dict_found));
            }
        }
    });

}

From source file:com.miz.mizuu.fragments.IdentifyMovieFragment.java

public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    mToolbar = (Toolbar) v.findViewById(R.id.toolbar);
    ((MizActivity) getActivity()).setSupportActionBar(mToolbar);

    mListView = (ListView) v.findViewById(R.id.listView1);
    mQuery = (EditText) v.findViewById(R.id.editText1);
    mSpinner = (Spinner) v.findViewById(R.id.spinner1);
    mProgress = (ProgressBar) v.findViewById(R.id.progressBar1);

    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from w w w .  j ava 2s . co  m*/
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            updateMovie(arg2);
        }
    });
    mListView.setEmptyView(v.findViewById(R.id.no_results));
    v.findViewById(R.id.no_results).setVisibility(View.GONE); // Manually make it gone to begin with

    mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mLocale = mSpinnerAdapter.getItem(position).getLanguage();
            searchForMovies();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mSpinnerAdapter = new LanguageAdapter();
    mSpinner.setAdapter(mSpinnerAdapter);
    String language = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getString(LANGUAGE_PREFERENCE, "en");
    mSpinner.setSelection(mSpinnerAdapter.getIndexForLocale(language));

    mQuery.setText(mMovieStructure.getDecryptedFilename());
    mQuery.setSelection(mQuery.length());
    mQuery.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.toString().length() > 0)
                searchForMovies();
            else {
                mMovieSearch.cancel(true);
                mAdapter.clearItems();
                mAdapter.notifyDataSetChanged();
            }
        }
    });
    mQuery.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                    || actionId == EditorInfo.IME_ACTION_SEARCH)
                searchForMovies();
            return true;
        }
    });

    if (mMovieSearch == null) {
        if (MizLib.isOnline(getActivity())) {
            mMovieSearch = new MovieSearch(getActivity(), mQuery.getText().toString());
        } else {
            Toast.makeText(getActivity(), getString(R.string.noInternet), Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.sentaroh.android.BluetoothWidget.Log.LogFileListDialogFragment.java

@Override
public void onStart() {
    CommonDialog.setDlgBoxSizeLimit(mDialog, true);
    super.onStart();
    if (DEBUG_ENABLE)
        Log.v(APPLICATION_TAG, "onStart");
    if (mTerminateRequired)
        mDialog.cancel();/*from  ww  w. j  a va  2s . c o  m*/
    else {
        mDialog.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                // disable search button action
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
                    if (mLogFileManagementAdapter.isShowCheckBox()) {
                        for (int i = 0; i < mLogFileManagementAdapter.getCount(); i++) {
                            mLogFileManagementAdapter.getItem(i).isChecked = false;
                        }
                        mLogFileManagementAdapter.setShowCheckBox(false);
                        mLogFileManagementAdapter.notifyDataSetChanged();
                        setContextButtonNormalMode(mLogFileManagementAdapter);
                        return true;
                    }
                }
                return false;
            }
        });
    }
}

From source file:com.miz.mizuu.fragments.IdentifyTvShowEpisodeFragment.java

public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    mToolbar = (Toolbar) v.findViewById(R.id.toolbar);
    ((MizActivity) getActivity()).setSupportActionBar(mToolbar);

    mListView = (ListView) v.findViewById(R.id.listView1);
    mQuery = (EditText) v.findViewById(R.id.editText1);
    mSpinner = (Spinner) v.findViewById(R.id.spinner1);
    mProgress = (ProgressBar) v.findViewById(R.id.progressBar1);

    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from  w  w  w .  ja va  2 s . c om*/
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            updateShow(arg2);
        }
    });
    mListView.setEmptyView(v.findViewById(R.id.no_results));
    v.findViewById(R.id.no_results).setVisibility(View.GONE); // Manually make it gone to begin with

    mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mLocale = mSpinnerAdapter.getItem(position).getLanguage();
            searchForShows();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mSpinnerAdapter = new LanguageAdapter();
    mSpinner.setAdapter(mSpinnerAdapter);
    String language = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getString(LANGUAGE_PREFERENCE, "en");
    mSpinner.setSelection(mSpinnerAdapter.getIndexForLocale(language));

    mQuery.setText(mShowTitle);
    mQuery.setSelection(mQuery.length());
    mQuery.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.toString().length() > 0)
                searchForShows();
            else {
                mTvShowSearch.cancel(true);
                mAdapter.clearItems();
                mAdapter.notifyDataSetChanged();
            }
        }
    });
    mQuery.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                    || actionId == EditorInfo.IME_ACTION_SEARCH)
                searchForShows();
            return true;
        }
    });

    if (mTvShowSearch == null) {
        if (MizLib.isOnline(getActivity())) {
            mTvShowSearch = new TvShowSearch(getActivity(), mQuery.getText().toString());
        } else {
            Toast.makeText(getActivity(), getString(R.string.noInternet), Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.activiti.android.ui.fragments.form.picker.IdmPickerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getArguments() != null) {
        onRetrieveParameters(getArguments());
    }/*ww  w  .  j a  v a2  s .  c om*/

    // Create View
    setRootView(inflater.inflate(R.layout.fr_idm_picker, container, false));

    // Init list
    init(getRootView(), emptyListMessageId);
    gv.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
    setListShown(true);

    searchView = UIUtils.setActionBarCustomView(getActivity(), R.layout.person_picker_header, true);

    View searchBack = searchView.findViewById(R.id.search_back);
    searchBack.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().getSupportFragmentManager().popBackStackImmediate();
        }
    });

    if (keywords != null && !keywords.isEmpty()) {
        search(keywords);
    } else {
        // Speech to Text
        hasTextToSpeech = FeatureUtils.hasSpeechToText(getActivity());
        speechToText = (ImageButton) searchView.findViewById(R.id.search_microphone);
        if (hasTextToSpeech) {
            speechToText.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    speechToText();
                }
            });
        } else {
            speechToText.setVisibility(View.GONE);
        }

        searchAction = (ImageButton) searchView.findViewById(R.id.search_start);
        searchAction.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (searchForm.getText().length() > 0) {
                    keywords = searchForm.getText().toString();
                    search(keywords);
                } else {
                    // TODO Snackbar
                }
            }
        });
        searchAction.setVisibility(View.GONE);

        // Init form search
        searchForm = (EditText) searchView.findViewById(R.id.search_query);
        searchForm.requestFocus();
        UIUtils.showKeyboard(getActivity(), searchForm);
        searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
        searchForm.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() == 0) {
                    searchAction.setVisibility(View.GONE);
                    if (hasTextToSpeech) {
                        speechToText.setVisibility(View.VISIBLE);
                    }
                } else {
                    speechToText.setVisibility(View.GONE);
                    searchAction.setVisibility(View.VISIBLE);
                }
            }
        });

        searchForm.setOnEditorActionListener(new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                        && ((actionId == EditorInfo.IME_ACTION_SEARCH)
                                || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
                                || (actionId == EditorInfo.IME_ACTION_DONE))) {
                    if (searchForm.getText().length() > 0) {
                        keywords = searchForm.getText().toString();
                        search(keywords);
                    } else {
                        // TODO Snackbar
                    }
                    return true;
                }
                return false;
            }
        });
    }

    if (getMode() == MODE_PICK) {
        Button cancel = UIUtils.initCancel(getRootView(), R.string.general_action_cancel);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getDialog() != null) {
                    getDialog().dismiss();
                } else {
                    getFragmentManager().popBackStack();
                }
            }
        });
    } else {
        hide(R.id.validation_panel);
    }

    return getRootView();
}

From source file:org.sipdroid.sipua.ui.Sipdroid.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.sipdroid);/*from w  w  w. ja va 2  s  .  co  m*/
    sip_uri_box = (AutoCompleteTextView) findViewById(R.id.txt_callee);
    sip_uri_box2 = (AutoCompleteTextView) findViewById(R.id.txt_callee2);
    sip_uri_box.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                call_menu(sip_uri_box);
                return true;
            }
            return false;
        }
    });
    sip_uri_box.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            call_menu(sip_uri_box);
        }
    });
    sip_uri_box2.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                call_menu(sip_uri_box2);
                return true;
            }
            return false;
        }
    });
    sip_uri_box2.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            call_menu(sip_uri_box2);
        }
    });
    on(this, true);

    Button contactsButton = (Button) findViewById(R.id.contacts_button);
    contactsButton.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            Intent myIntent = new Intent(Intent.ACTION_DIAL);
            startActivity(myIntent);
        }
    });

    final Context mContext = this;

    Button settingsButton = (Button) findViewById(R.id.settings_button);
    settingsButton.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            Intent myIntent = new Intent(mContext, org.sipdroid.sipua.ui.Settings.class);
            startActivity(myIntent);
        }
    });

    final OnDismissListener listener = this;

    createButton = (Button) findViewById(R.id.create_button);
    createButton.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            CreateAccount createDialog = new CreateAccount(mContext);
            createDialog.setOnDismissListener(listener);
            createDialog.show();
        }
    });

    if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Settings.PREF_NOPORT,
            Settings.DEFAULT_NOPORT)) {
        boolean ask = false;
        for (int i = 0; i < SipdroidEngine.LINES; i++) {
            String j = (i != 0 ? "" + i : "");
            if (PreferenceManager.getDefaultSharedPreferences(this)
                    .getString(Settings.PREF_SERVER + j, Settings.DEFAULT_SERVER)
                    .equals(Settings.DEFAULT_SERVER)
                    && PreferenceManager.getDefaultSharedPreferences(this)
                            .getString(Settings.PREF_USERNAME + j, Settings.DEFAULT_USERNAME).length() != 0
                    && PreferenceManager.getDefaultSharedPreferences(this)
                            .getString(Settings.PREF_PORT + j, Settings.DEFAULT_PORT)
                            .equals(Settings.DEFAULT_PORT))
                ask = true;
        }
        if (ask)
            new AlertDialog.Builder(this).setMessage(R.string.dialog_port)
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Editor edit = PreferenceManager.getDefaultSharedPreferences(mContext).edit();
                            for (int i = 0; i < SipdroidEngine.LINES; i++) {
                                String j = (i != 0 ? "" + i : "");
                                if (PreferenceManager.getDefaultSharedPreferences(mContext)
                                        .getString(Settings.PREF_SERVER + j, Settings.DEFAULT_SERVER)
                                        .equals(Settings.DEFAULT_SERVER)
                                        && PreferenceManager.getDefaultSharedPreferences(mContext)
                                                .getString(Settings.PREF_USERNAME + j,
                                                        Settings.DEFAULT_USERNAME)
                                                .length() != 0
                                        && PreferenceManager.getDefaultSharedPreferences(mContext)
                                                .getString(Settings.PREF_PORT + j, Settings.DEFAULT_PORT)
                                                .equals(Settings.DEFAULT_PORT))
                                    edit.putString(Settings.PREF_PORT + j, "5061");
                            }
                            edit.commit();
                            Receiver.engine(mContext).halt();
                            Receiver.engine(mContext).StartEngine();
                        }
                    }).setNeutralButton(R.string.no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                        }
                    }).setNegativeButton(R.string.dontask, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Editor edit = PreferenceManager.getDefaultSharedPreferences(mContext).edit();
                            edit.putBoolean(Settings.PREF_NOPORT, true);
                            edit.commit();
                        }
                    }).show();
    } else if (PreferenceManager.getDefaultSharedPreferences(this)
            .getString(Settings.PREF_PREF, Settings.DEFAULT_PREF).equals(Settings.VAL_PREF_PSTN)
            && !PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Settings.PREF_NODEFAULT,
                    Settings.DEFAULT_NODEFAULT))
        new AlertDialog.Builder(this).setMessage(R.string.dialog_default)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Editor edit = PreferenceManager.getDefaultSharedPreferences(mContext).edit();
                        edit.putString(Settings.PREF_PREF, Settings.VAL_PREF_SIP);
                        edit.commit();
                    }
                }).setNeutralButton(R.string.no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                }).setNegativeButton(R.string.dontask, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Editor edit = PreferenceManager.getDefaultSharedPreferences(mContext).edit();
                        edit.putBoolean(Settings.PREF_NODEFAULT, true);
                        edit.commit();
                    }
                }).show();
}