Example usage for android.view.inputmethod EditorInfo IME_ACTION_DONE

List of usage examples for android.view.inputmethod EditorInfo IME_ACTION_DONE

Introduction

In this page you can find the example usage for android.view.inputmethod EditorInfo IME_ACTION_DONE.

Prototype

int IME_ACTION_DONE

To view the source code for android.view.inputmethod EditorInfo IME_ACTION_DONE.

Click Source Link

Document

Bits of #IME_MASK_ACTION : the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.

Usage

From source file:com.android.calendar.event.EditEventView.java

public EditEventView(FragmentActivity activity, View view, EditDoneRunnable done,
        boolean timeSelectedWasStartTime, boolean dateSelectedWasStartDate) {

    mActivity = activity;// w w w.j  av  a2s  . c  om
    mView = view;
    mDone = done;

    // cache top level view elements
    mLoadingMessage = (TextView) view.findViewById(R.id.loading_message);
    mScrollView = (ScrollView) view.findViewById(R.id.scroll_view);

    // cache all the widgets
    mCalendarsSpinner = (Spinner) view.findViewById(R.id.calendars_spinner);
    mTitleTextView = (TextView) view.findViewById(R.id.title);
    mLocationTextView = (AutoCompleteTextView) view.findViewById(R.id.location);
    mDescriptionTextView = (TextView) view.findViewById(R.id.description);
    mTimezoneLabel = (TextView) view.findViewById(R.id.timezone_label);
    mStartDateButton = (Button) view.findViewById(R.id.start_date);
    mEndDateButton = (Button) view.findViewById(R.id.end_date);
    mWhenView = (TextView) mView.findViewById(R.id.when);
    mTimezoneTextView = (TextView) mView.findViewById(R.id.timezone_textView);
    mStartTimeButton = (Button) view.findViewById(R.id.start_time);
    mEndTimeButton = (Button) view.findViewById(R.id.end_time);
    mTimezoneButton = (Button) view.findViewById(R.id.timezone_button);
    mTimezoneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTimezoneDialog();
        }
    });
    mTimezoneRow = view.findViewById(R.id.timezone_button_row);
    mStartTimeHome = (TextView) view.findViewById(R.id.start_time_home_tz);
    mStartDateHome = (TextView) view.findViewById(R.id.start_date_home_tz);
    mEndTimeHome = (TextView) view.findViewById(R.id.end_time_home_tz);
    mEndDateHome = (TextView) view.findViewById(R.id.end_date_home_tz);
    mAllDayCheckBox = (CheckBox) view.findViewById(R.id.is_all_day);
    mRruleButton = (Button) view.findViewById(R.id.rrule);
    mAvailabilitySpinner = (Spinner) view.findViewById(R.id.availability);
    mAccessLevelSpinner = (Spinner) view.findViewById(R.id.visibility);
    mCalendarSelectorGroup = view.findViewById(R.id.calendar_selector_group);
    mCalendarSelectorWrapper = view.findViewById(R.id.calendar_selector_wrapper);
    mCalendarStaticGroup = view.findViewById(R.id.calendar_group);
    mRemindersGroup = view.findViewById(R.id.reminders_row);
    mResponseGroup = view.findViewById(R.id.response_row);
    mOrganizerGroup = view.findViewById(R.id.organizer_row);
    mAttendeesGroup = view.findViewById(R.id.add_attendees_row);
    mLocationGroup = view.findViewById(R.id.where_row);
    mDescriptionGroup = view.findViewById(R.id.description_row);
    mStartHomeGroup = view.findViewById(R.id.from_row_home_tz);
    mEndHomeGroup = view.findViewById(R.id.to_row_home_tz);
    mAttendeesList = (MultiAutoCompleteTextView) view.findViewById(R.id.attendees);

    mColorPickerNewEvent = view.findViewById(R.id.change_color_new_event);
    mColorPickerExistingEvent = view.findViewById(R.id.change_color_existing_event);

    mTitleTextView.setTag(mTitleTextView.getBackground());
    mLocationTextView.setTag(mLocationTextView.getBackground());
    mLocationAdapter = new EventLocationAdapter(activity);
    mLocationTextView.setAdapter(mLocationAdapter);
    mLocationTextView.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                // Dismiss the suggestions dropdown. Return false so the
                // other
                // side effects still occur (soft keyboard going away,
                // etc.).
                mLocationTextView.dismissDropDown();
            }
            return false;
        }
    });

    mAvailabilityExplicitlySet = false;
    mAllDayChangingAvailability = false;
    mAvailabilityCurrentlySelected = -1;
    mAvailabilitySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // The spinner's onItemSelected gets called while it is being
            // initialized to the first item, and when we explicitly set it
            // in the allDay checkbox toggling, so we need these checks to
            // find out when the spinner is actually being clicked.

            // Set the initial selection.
            if (mAvailabilityCurrentlySelected == -1) {
                mAvailabilityCurrentlySelected = position;
            }

            if (mAvailabilityCurrentlySelected != position && !mAllDayChangingAvailability) {
                mAvailabilityExplicitlySet = true;
            } else {
                mAvailabilityCurrentlySelected = position;
                mAllDayChangingAvailability = false;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    mDescriptionTextView.setTag(mDescriptionTextView.getBackground());
    mAttendeesList.setTag(mAttendeesList.getBackground());
    mOriginalPadding[0] = mLocationTextView.getPaddingLeft();
    mOriginalPadding[1] = mLocationTextView.getPaddingTop();
    mOriginalPadding[2] = mLocationTextView.getPaddingRight();
    mOriginalPadding[3] = mLocationTextView.getPaddingBottom();
    mEditViewList.add(mTitleTextView);
    mEditViewList.add(mLocationTextView);
    mEditViewList.add(mDescriptionTextView);
    mEditViewList.add(mAttendeesList);

    mViewOnlyList.add(view.findViewById(R.id.when_row));
    mViewOnlyList.add(view.findViewById(R.id.timezone_textview_row));

    mEditOnlyList.add(view.findViewById(R.id.all_day_row));
    mEditOnlyList.add(view.findViewById(R.id.availability_row));
    mEditOnlyList.add(view.findViewById(R.id.visibility_row));
    mEditOnlyList.add(view.findViewById(R.id.from_row));
    mEditOnlyList.add(view.findViewById(R.id.to_row));
    mEditOnlyList.add(mTimezoneRow);
    mEditOnlyList.add(mStartHomeGroup);
    mEditOnlyList.add(mEndHomeGroup);

    mResponseRadioGroup = (RadioGroup) view.findViewById(R.id.response_value);
    mRemindersContainer = (LinearLayout) view.findViewById(R.id.reminder_items_container);

    mTimezone = Utils.getTimeZone(activity, null);
    mIsMultipane = activity.getResources().getBoolean(R.bool.tablet_config);
    mStartTime = new Time(mTimezone);
    mEndTime = new Time(mTimezone);
    mEmailValidator = new Rfc822Validator(null);
    initMultiAutoCompleteTextView((RecipientEditTextView) mAttendeesList);

    // Display loading screen
    setModel(null);

    FragmentManager fm = activity.getSupportFragmentManager();
    RecurrencePickerDialog rpd = (RecurrencePickerDialog) fm.findFragmentByTag(FRAG_TAG_RECUR_PICKER);
    if (rpd != null) {
        rpd.setOnRecurrenceSetListener(this);
    }
    TimeZonePickerDialog tzpd = (TimeZonePickerDialog) fm.findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
    if (tzpd != null) {
        tzpd.setOnTimeZoneSetListener(this);
    }
    TimePickerDialog tpd = (TimePickerDialog) fm.findFragmentByTag(FRAG_TAG_TIME_PICKER);
    if (tpd != null) {
        View v;
        mTimeSelectedWasStartTime = timeSelectedWasStartTime;
        if (timeSelectedWasStartTime) {
            v = mStartTimeButton;
        } else {
            v = mEndTimeButton;
        }
        tpd.setOnTimeSetListener(new TimeListener(v));
    }
    mDatePickerDialog = (DatePickerDialog) fm.findFragmentByTag(FRAG_TAG_DATE_PICKER);
    if (mDatePickerDialog != null) {
        View v;
        mDateSelectedWasStartDate = dateSelectedWasStartDate;
        if (dateSelectedWasStartDate) {
            v = mStartDateButton;
        } else {
            v = mEndDateButton;
        }
        mDatePickerDialog.setOnDateSetListener(new DateListener(v));
    }
}

From source file:com.aliyun.homeshell.Folder.java

public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        // YUNOS BEGIN
        // ##date:2014/09/16 ##author:hongchao.ghc ##BugID:5236250
        int start = mFolderName.getSelectionStart();
        int oldLength = mFolderName.getText().length();
        dismissEditingName();/*from   w  w w. j a va  2s.  com*/
        int length = mFolderName.getText().length();
        if (oldLength != length) {
            if (start == oldLength) {
                start = length;
            } else {
                start = 0;
            }
        }
        if (start < 0) {
            start = 0;
        }
        mFolderName.setSelection(start);
        // YUNOS END
        return true;
    }
    return false;
}

From source file:com.mobicage.rogerthat.AddFriendsActivity.java

private void configureMailView() {
    T.UI();/*from  w  w w  . jav  a 2s.  c om*/
    final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.add_via_email_text_field);
    emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>()));
    emailText.setThreshold(1);

    if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) {
        mService.postAtFrontOfBIZZHandler(new SafeRunnable() {

            @SuppressWarnings("unchecked")
            @Override
            protected void safeRun() throws Exception {
                L.d("AddFriendsActivity getEmailAddresses");
                List<String> emailList = ContactListHelper.getEmailAddresses(AddFriendsActivity.this);
                ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter();
                for (int i = 0; i < emailList.size(); i++) {
                    a.add(emailList.get(i));
                }
                a.notifyDataSetChanged();
                L.d("AddFriendsActivity gotEmailAddresses");
            }
        });
    }

    final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            String email = emailText.getText().toString().trim();
            if (RegexPatterns.EMAIL.matcher(email).matches()) {
                if (mFriendsPlugin.inviteFriend(email, null, null, true)) {
                    emailText.setText(null);
                    UIUtils.hideKeyboard(AddFriendsActivity.this, emailText);
                } else {
                    UIUtils.showLongToast(AddFriendsActivity.this, getString(R.string.friend_invite_failed));
                }
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(AddFriendsActivity.this);
                builder.setMessage(R.string.registration_email_not_valid);
                builder.setPositiveButton(R.string.rogerthat, null);
                builder.create().show();
            }
        }
    };
    ((Button) findViewById(R.id.add_via_email_button)).setOnClickListener(onClickListener);

    emailText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                onClickListener.onClick(view);
                return true;
            }
            return false;
        }
    });
}

From source file:com.ywesee.amiko.MainActivity.java

/**
 *
 *///from  w  w w.j  a va2 s .co m
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // Inflate the menu. Add items to the action bar if present.
    getMenuInflater().inflate(R.menu.actionbar, menu);

    mSearchItem = menu.findItem(R.id.menu_search);
    mSearchItem.expandActionView();
    mSearchItem.setVisible(true);
    mSearch = (EditText) mSearchItem.getActionView().findViewById(R.id.search_box);
    if (!Utilities.isTablet(this)) {
        float textSize = 16.0f; // in [sp] = scaled pixels
        mSearch.setTextSize(textSize);
    }
    mSearch.setFocusable(true);

    if (mSearch != null) {
        if (mSearchInteractions == false)
            mSearch.setHint(getString(R.string.search) + " " + mActionName);
        else
            mSearch.setHint(getString(R.string.search) + " " + getString(R.string.interactions_search));
    }

    mSearchHitsCntView = (TextView) mSearchItem.getActionView().findViewById(R.id.hits_counter);
    mSearchHitsCntView.setVisibility(View.GONE);

    mSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE) {
                if (mCurrentView == mSuggestView) {
                    // Hide keyboard
                    hideSoftKeyboard(500);
                } else if (mCurrentView == mShowView) {
                    // Searches forward
                    mWebView.findNext(true);
                }
                return true;
            }
            return false;
        }
    });

    mSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                showSoftKeyboard(100);
            }
        }
    });

    mSearch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(100);
            if (!mSQLiteDBInitialized) {
                runOnUiThread(new Runnable() {
                    public void run() {
                        showDownloadAlert(0);
                    }
                });
            }
        }
    });

    // Action listener for search_box
    mSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Do nothing
        }

        @Override
        public void onTextChanged(CharSequence cs, int start, int before, int count) {
            // Do nothing
        }

        @Override
        public void afterTextChanged(Editable s) {
            String text = mSearch.getText().toString();
            if (text.length() > 0) {
                if (!mSQLiteDBInitialized) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            showDownloadAlert(0);
                        }
                    });
                    return;
                }
            }
            if (!mRestoringState) {
                if (text.length() > 0)
                    performSearch(text);
            }
            mDelete.setVisibility(s.length() > 0 ? View.VISIBLE : View.GONE);
        }
    });

    mDelete = (Button) mSearchItem.getActionView().findViewById(R.id.delete);
    mDelete.setVisibility(mSearch.getText().length() > 0 ? View.VISIBLE : View.GONE);

    mDelete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mSearch.length() > 0)
                mSearch.getText().clear();
            if (mCurrentView == mShowView) {
                mSearchHitsCntView.setVisibility(View.GONE);
                mWebView.clearMatches();
            } else if (mCurrentView == mSuggestView) {
                showSoftKeyboard(300);
            }
        }
    });

    return true;
}

From source file:org.telegram.ui.ThemeActivity.java

private void openThemeCreate() {
    final EditTextBoldCursor editText = new EditTextBoldCursor(getParentActivity());
    editText.setBackgroundDrawable(Theme.createEditTextDrawable(getParentActivity(), true));

    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("NewTheme", R.string.NewTheme));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> {

    });/*  www  . j  a va2  s  .c  o m*/

    LinearLayout linearLayout = new LinearLayout(getParentActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    final TextView message = new TextView(getParentActivity());
    message.setText(LocaleController.formatString("EnterThemeName", R.string.EnterThemeName));
    message.setTextSize(16);
    message.setPadding(AndroidUtilities.dp(23), AndroidUtilities.dp(12), AndroidUtilities.dp(23),
            AndroidUtilities.dp(6));
    message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    linearLayout.addView(message,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    editText.setGravity(Gravity.LEFT | Gravity.TOP);
    editText.setSingleLine(true);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setCursorSize(AndroidUtilities.dp(20));
    editText.setCursorWidth(1.5f);
    editText.setPadding(0, AndroidUtilities.dp(4), 0, 0);
    linearLayout.addView(editText,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 24, 6, 24, 0));
    editText.setOnEditorActionListener((textView, i, keyEvent) -> {
        AndroidUtilities.hideKeyboard(textView);
        return false;
    });
    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialog -> AndroidUtilities.runOnUIThread(() -> {
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
    }));
    showDialog(alertDialog);
    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
        if (editText.length() == 0) {
            Vibrator vibrator = (Vibrator) ApplicationLoader.applicationContext
                    .getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator != null) {
                vibrator.vibrate(200);
            }
            AndroidUtilities.shakeView(editText, 2, 0);
            return;
        }
        ThemeEditorView themeEditorView = new ThemeEditorView();
        String name = editText.getText().toString() + ".attheme";
        themeEditorView.show(getParentActivity(), name);
        Theme.saveCurrentTheme(name, true);
        updateRows();
        alertDialog.dismiss();

        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
        if (preferences.getBoolean("themehint", false)) {
            return;
        }
        preferences.edit().putBoolean("themehint", true).commit();
        try {
            Toast.makeText(getParentActivity(),
                    LocaleController.getString("CreateNewThemeHelp", R.string.CreateNewThemeHelp),
                    Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}

From source file:org.de.jmg.learn._MainActivity.java

public void getVokabel(final boolean showBeds, boolean LoadNext, boolean requestFocusEdWord, boolean DontPrompt)
        throws Exception {

    if (iv != null) {
        iv.setVisibility(View.GONE);
    }//  w w w.j av  a2 s . com
    if (iv2 != null)
        iv2.setVisibility(View.GONE);
    try {
        if (_btnRight == null)
            return;
        EndEdit(DontPrompt);
        setBtnsEnabled(true);
        if (showBeds && _vok.getIndex() >= 1) {
            _btnRight.setEnabled(true);
            _btnWrong.setEnabled(true);
            _btnEdit.setEnabled(true);
            _btnSkip.setEnabled(true);
            _btnView.setEnabled(true);
        } else {
            _btnRight.setEnabled(false);
            _btnWrong.setEnabled(false);
            if (_vok.getIndex() < 1) {
                _btnEdit.setEnabled(false);
                _btnSkip.setEnabled(false);
                _btnView.setEnabled(false);
            }
        }
        if (LoadNext)
            _vok.setLernIndex((short) (_vok.getLernIndex() + 1));

        View v;
        TextView t;
        String txtBed = getString(R.string.cloze);

        if (showBeds) {
            v = findViewById(R.id.txtMeaning1);
            t = (TextView) v;
            assert t != null;
            t.setText(lib.getSpanableString(_vok.getBedeutung1()));
            txtBed = t.getText().toString();
        }

        v = findViewById(R.id.word);
        t = (TextView) v;
        assert t != null;
        String txtWord = getString(R.string.cloze);
        if (!_vok.reverse || showBeds) {
            t.setText(lib.getSpanableString(_vok.getWort()), TextView.BufferType.SPANNABLE);
            txtWord = t.getText().toString();
            txtWord = replaceClozes(txtWord, txtBed);
            speak(txtWord, _vok.getLangWord(), "word", true);
        } else {
            t.setText("");
        }

        if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch
                || (_vok.getFontWort().getName().equalsIgnoreCase("Cardo"))) {
            t.setTypeface(_vok.TypefaceCardo);
            _txtedWord.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
            _txtedWord.setTypeface(Typeface.DEFAULT);
        }
        t.scrollTo(0, 0);

        v = findViewById(R.id.Comment);
        t = (TextView) v;
        assert t != null;
        t.setVisibility(View.VISIBLE);

        SpannableString tspanKom = lib.getSpanableString(_vok.getKommentar());
        URLSpan[] urlSpans = tspanKom.getSpans(0, tspanKom.length(), URLSpan.class);
        for (final URLSpan span : urlSpans) {
            int start = tspanKom.getSpanStart(span);
            int end = tspanKom.getSpanEnd(span);
            String txt = tspanKom.toString().substring(start, end);
            if (txtIsPicture(txt)) {
                tspanKom.removeSpan(span);
                tspanKom.setSpan(new urlclickablespan(span.getURL()) {
                    @Override
                    public void onClick(View widget) {
                        Bitmap b;
                        try {
                            b = lib.downloadpicture(this.url);
                        } catch (Exception ex) {
                            b = null;
                        }
                        if (b != null) {
                            if (iv == null) {
                                iv = new ImageView(context);
                                SetTouchListener(iv);
                            }
                            b = resizeBM(b);
                            iv.setImageBitmap(b);
                            if (iv.getParent() == null) {
                                try {
                                    LayoutParams p = _txtMeaning1.getLayoutParams();
                                    //p.width = LayoutParams.WRAP_CONTENT;
                                    //p.height = LayoutParams.WRAP_CONTENT;
                                    rellayoutMain.addView(iv, p);
                                } catch (Exception ex) {
                                    Log.e("addImageView", ex.getMessage(), ex);
                                }
                            } else {
                                Log.d("ImageView", "exists");
                            }
                            _txtMeaning1.setVisibility(View.GONE);
                            iv.setVisibility(View.VISIBLE);
                        }
                    }
                }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        t.setText(tspanKom, TextView.BufferType.SPANNABLE);

        if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch
                || (_vok.getFontKom().getName().equalsIgnoreCase("Cardo"))) {
            t.setTypeface(_vok.TypefaceCardo);
            _txtedKom.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
            _txtedKom.setTypeface(Typeface.DEFAULT);
        }
        if (_isSmallDevice && libString.IsNullOrEmpty(t.getText().toString())) {
            t.setVisibility(View.GONE);
        } else {
            t.setVisibility(View.VISIBLE);
        }
        t.scrollTo(0, 0);

        v = findViewById(R.id.txtMeaning1);
        t = (TextView) v;
        assert t != null;
        if (!libString.IsNullOrEmpty(_vok.getBedeutung2())) {
            t.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        }
        if (_vok.reverse || showBeds) {
            SpannableString tspan = lib.getSpanableString(_vok.getBedeutung1());
            //final String picname = _main.getString(R.string.picture);
            t.setVisibility(View.VISIBLE);
            if (txtIsPicture(tspan.toString())) {
                URLSpan urlspn[] = tspan.getSpans(0, tspan.length(), URLSpan.class);
                for (URLSpan url : urlspn) {
                    Bitmap b;
                    try {
                        b = lib.downloadpicture(url.getURL());
                    } catch (Exception ex) {
                        b = null;
                    }
                    if (b != null) {
                        if (iv == null) {
                            iv = new ImageView(context);
                            SetTouchListener(iv);
                        }
                        b = resizeBM(b);
                        iv.setImageBitmap(b);
                        if (iv.getParent() == null) {
                            try {
                                LayoutParams p = t.getLayoutParams();
                                //p.width = LayoutParams.WRAP_CONTENT;
                                //p.height = LayoutParams.WRAP_CONTENT;
                                rellayoutMain.addView(iv, p);
                            } catch (Exception ex) {
                                Log.e("Imagview", ex.getMessage(), ex);
                            }
                        } else {
                            Log.d("ImageView", "exists");
                        }
                        t.setVisibility(View.GONE);
                        iv.setVisibility(View.VISIBLE);
                    }
                }

            } else {
                // iv.setVisibility(View.GONE);
                t.setVisibility(View.VISIBLE);
            }

            t.setText(tspan);
        } else {
            t.setText(Vokabel.getComment(_vok.getBedeutung1()));
        }
        if (_vok.reverse || showBeds) {
            String txt = t.getText().toString();
            txt = replaceClozes(txt, txtWord);
            speak(txt, _vok.getLangMeaning(), "meaning1", _vok.reverse);
        }
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        t.setOnFocusChangeListener(FocusListenerMeaning1);
        t.scrollTo(0, 0);

        v = findViewById(R.id.txtMeaning2);
        t = (TextView) v;
        assert t != null;
        t.setText((_vok.reverse || showBeds ? _vok.getBedeutung2() : Vokabel.getComment(_vok.getBedeutung2())));
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        if (libString.IsNullOrEmpty(_vok.getBedeutung2()) || _vok.getCardMode()) {
            t.setVisibility(View.GONE);
            _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_DONE);
        } else {
            t.setVisibility(View.VISIBLE);
            _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            if (_vok.reverse || showBeds) {
                String txt = t.getText().toString();
                //if (txtWord != null)
                //   txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord);
                speak(txt, _vok.getLangMeaning(), "meaning2");
            }
        }

        v = findViewById(R.id.txtMeaning3);
        t = (TextView) v;
        assert t != null;
        t.setText((_vok.reverse || showBeds ? _vok.getBedeutung3() : Vokabel.getComment(_vok.getBedeutung3())));
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        if (libString.IsNullOrEmpty(_vok.getBedeutung3()) || _vok.getCardMode()) {
            t.setVisibility(View.GONE);
            _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_DONE);
        } else {
            t.setVisibility(View.VISIBLE);
            _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            _txtMeaning3.setImeOptions(EditorInfo.IME_ACTION_DONE);
            if (_vok.reverse || showBeds) {
                String txt = t.getText().toString();
                //if (txtWord != null)
                //   txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord);
                speak(txt, _vok.getLangMeaning(), "meaning3");
            }
        }

        if (_vok.reverse && showBeds)
            speak(txtWord, _vok.getLangWord(), "word");

        lib.setBgEditText(_txtMeaning1, _MeaningBG);
        lib.setBgEditText(_txtMeaning2, _MeaningBG);
        lib.setBgEditText(_txtMeaning3, _MeaningBG);
        if (!_isSmallDevice && !requestFocusEdWord) {
            _txtMeaning1.requestFocus();
        } else {
            if (!requestFocusEdWord)
                _txtWord.requestFocus();
            else
                _txtedWord.requestFocus();
        }
        SetActionBarTitle();

        _scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {

                lib.removeLayoutListener(_scrollView.getViewTreeObserver(), this);
                hideKeyboard();
                if (showBeds) {
                    _scrollView.scrollTo(0, _txtMeaning1.getTop());
                } else {
                    _txtWord.requestFocus();
                    _scrollView.fullScroll(View.FOCUS_UP);
                }
            }
        });

    } catch (Exception e) {

        lib.ShowException(_main, e);
    }

}

From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java

private void addInterfaceListeners() {

    final OnMapClickListener onMapClickListener = new OnMapClickListener() {
        @Override/*from www  . ja va2s  .  c  om*/
        public void onMapClick(LatLng latlng) {
            InputMethodManager imm = (InputMethodManager) MainFragment.this.getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mTbEndLocation.getWindowToken(), 0);
            imm.hideSoftInputFromWindow(mTbStartLocation.getWindowToken(), 0);

            if (mTbStartLocation.hasFocus()) {
                setMarker(true, latlng, true);
            } else {
                setMarker(false, latlng, true);
            }
        }
    };
    mMap.setOnMapClickListener(onMapClickListener);

    OnMarkerDragListener onMarkerDragListener = new OnMarkerDragListener() {

        @Override
        public void onMarkerDrag(Marker marker) {
        }

        @Override
        public void onMarkerDragEnd(Marker marker) {
            LatLng markerLatlng = marker.getPosition();

            if (((mOTPApp.getSelectedServer() != null) && LocationUtil.checkPointInBoundingBox(markerLatlng,
                    mOTPApp.getSelectedServer(), OTPApp.CHECK_BOUNDS_ACCEPTABLE_ERROR))
                    || (mOTPApp.getSelectedServer() == null)) {
                if ((mStartMarker != null) && (marker.hashCode() == mStartMarker.hashCode())) {
                    if (mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_USE_INTELLIGENT_MARKERS, true)) {
                        updateMarkerPosition(markerLatlng, true);
                    } else {
                        mIsStartLocationGeocodingCompleted = true;
                        removeFocus(true);
                        setMarker(true, markerLatlng, false);
                    }
                    mStartMarkerPosition = markerLatlng;
                } else if ((mEndMarker != null) && (marker.hashCode() == mEndMarker.hashCode())) {
                    if (mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_USE_INTELLIGENT_MARKERS, true)) {
                        updateMarkerPosition(markerLatlng, false);
                    } else {
                        mIsEndLocationGeocodingCompleted = true;
                        removeFocus(false);
                        setMarker(false, markerLatlng, false);
                    }
                    mEndMarkerPosition = markerLatlng;
                }
            } else {

                if ((mStartMarker != null) && (marker.hashCode() == mStartMarker.hashCode())) {
                    marker.setPosition(mStartMarkerPosition);
                } else {
                    marker.setPosition(mEndMarkerPosition);
                }
                Toast.makeText(mApplicationContext,
                        mApplicationContext.getResources().getString(
                                R.string.toast_map_markers_marker_out_of_boundaries),
                        Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onMarkerDragStart(Marker marker) {
            InputMethodManager imm = (InputMethodManager) MainFragment.this.getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mTbEndLocation.getWindowToken(), 0);
            imm.hideSoftInputFromWindow(mTbStartLocation.getWindowToken(), 0);
        }
    };
    mMap.setOnMarkerDragListener(onMarkerDragListener);

    OnMapLongClickListener onMapLongClickListener = new OnMapLongClickListener() {
        @Override
        public void onMapLongClick(LatLng latlng) {
            InputMethodManager imm = (InputMethodManager) MainFragment.this.getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mTbEndLocation.getWindowToken(), 0);
            imm.hideSoftInputFromWindow(mTbStartLocation.getWindowToken(), 0);

            final LatLng latLngFinal = latlng;
            final CharSequence[] items = {
                    mApplicationContext.getResources()
                            .getString(R.string.point_type_selector_start_marker_option),
                    mApplicationContext.getResources()
                            .getString(R.string.point_type_selector_end_marker_option) };

            AlertDialog.Builder builder = new AlertDialog.Builder(MainFragment.this.getActivity());
            builder.setTitle(getResources().getString(R.string.point_type_selector_title));
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    if (item == 0) {
                        setMarker(true, latLngFinal, true);
                    } else {
                        setMarker(false, latLngFinal, true);
                    }
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    };
    mMap.setOnMapLongClickListener(onMapLongClickListener);

    OnClickListener onClickListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            mDrawerLayout.openDrawer(Gravity.LEFT);
        }
    };
    mBtnHandle.setOnClickListener(onClickListener);

    OnInfoWindowClickListener onInfoWindowClickListener = new OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker modeMarker) {
            saveOTPBundle();
            OTPBundle otpBundle = getFragmentListener().getOTPBundle();
            Matcher matcher = Pattern.compile("\\d+").matcher(modeMarker.getTitle());
            if (matcher.find()) {
                String numberString = modeMarker.getTitle().substring(0, matcher.end());
                //Step indexes shown to the user are in a scale starting by 1 but instructions steps internally start by 0
                int currentStepIndex = Integer.parseInt(numberString) - 1;
                otpBundle.setCurrentStepIndex(currentStepIndex);
                otpBundle.setFromInfoWindow(true);
                getFragmentListener().setOTPBundle(otpBundle);
                getFragmentListener().onSwitchedToDirectionFragment();
            }

        }
    };
    mMap.setOnInfoWindowClickListener(onInfoWindowClickListener);

    DrawerListener dl = new DrawerListener() {
        @Override
        public void onDrawerStateChanged(int arg0) {
        }

        @Override
        public void onDrawerSlide(View arg0, float arg1) {

            InputMethodManager imm = (InputMethodManager) MainFragment.this.getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mTbEndLocation.getWindowToken(), 0);
            imm.hideSoftInputFromWindow(mTbStartLocation.getWindowToken(), 0);
        }

        @Override
        public void onDrawerOpened(View arg0) {
        }

        @Override
        public void onDrawerClosed(View arg0) {
        }
    };
    mDrawerLayout.setDrawerListener(dl);

    OnTouchListener otlStart = new RightDrawableOnTouchListener(mTbStartLocation) {
        @Override
        public boolean onDrawableTouch(final MotionEvent event) {

            final CharSequence[] items = {
                    getResources().getString(R.string.text_box_dialog_location_type_current_location),
                    getResources().getString(R.string.text_box_dialog_location_type_contact),
                    getResources().getString(R.string.text_box_dialog_location_type_map_point) };

            AlertDialog.Builder builder = new AlertDialog.Builder(MainFragment.this.getActivity());
            builder.setTitle(getResources().getString(R.string.text_box_dialog_choose_location_type_start));
            builder.setItems(items, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {
                    if (items[item].equals(getResources()
                            .getString(R.string.text_box_dialog_location_type_current_location))) {
                        LatLng mCurrentLatLng = getLastLocation();
                        if (mCurrentLatLng != null) {
                            SharedPreferences.Editor prefsEditor = mPrefs.edit();
                            setTextBoxLocation(getResources().getString(R.string.text_box_my_location), true);
                            prefsEditor.putBoolean(OTPApp.PREFERENCE_KEY_ORIGIN_IS_MY_LOCATION, true);

                            if (mStartMarker != null) {
                                mStartMarker.remove();
                                mStartMarker = null;
                            }

                            prefsEditor.commit();
                        } else {
                            Toast.makeText(MainFragment.this.mApplicationContext,
                                    mApplicationContext.getResources()
                                            .getString(R.string.toast_tripplanner_current_location_error),
                                    Toast.LENGTH_LONG).show();
                        }

                    } else if (items[item]
                            .equals(getResources().getString(R.string.text_box_dialog_location_type_contact))) {
                        Intent intent = new Intent(Intent.ACTION_PICK);
                        intent.setType(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_TYPE);
                        ((MyActivity) MainFragment.this.getActivity()).setButtonStartLocation(true);

                        MainFragment.this.getActivity().startActivityForResult(intent,
                                OTPApp.CHOOSE_CONTACT_REQUEST_CODE);

                    } else { // Point on Map
                        if (mStartMarker != null) {
                            updateMarkerPosition(mStartMarker.getPosition(), true);
                        } else {
                            setTextBoxLocation("", true);
                            mTbStartLocation
                                    .setHint(getResources().getString(R.string.text_box_need_to_place_marker));
                            mTbStartLocation.requestFocus();
                        }
                    }
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
            return true;
        }

    };

    mTbStartLocation.setOnTouchListener(otlStart);

    OnTouchListener otlEnd = new RightDrawableOnTouchListener(mTbEndLocation) {
        @Override
        public boolean onDrawableTouch(final MotionEvent event) {

            final CharSequence[] items = {
                    getResources().getString(R.string.text_box_dialog_location_type_current_location),
                    getResources().getString(R.string.text_box_dialog_location_type_contact),
                    getResources().getString(R.string.text_box_dialog_location_type_map_point) };

            AlertDialog.Builder builder = new AlertDialog.Builder(MainFragment.this.getActivity());
            builder.setTitle(getResources().getString(R.string.text_box_dialog_choose_location_type_end));
            builder.setItems(items, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {
                    if (items[item].equals(getResources()
                            .getString(R.string.text_box_dialog_location_type_current_location))) {
                        LatLng mCurrentLatLng = getLastLocation();
                        if (mCurrentLatLng != null) {
                            SharedPreferences.Editor prefsEditor = mPrefs.edit();
                            setTextBoxLocation(getResources().getString(R.string.text_box_my_location), false);
                            prefsEditor.putBoolean(OTPApp.PREFERENCE_KEY_DESTINATION_IS_MY_LOCATION, true);

                            if (mEndMarker != null) {
                                mEndMarker.remove();
                                mEndMarker = null;
                            }

                            prefsEditor.commit();
                        } else {
                            Toast.makeText(MainFragment.this.mApplicationContext,
                                    mApplicationContext.getResources()
                                            .getString(R.string.toast_tripplanner_current_location_error),
                                    Toast.LENGTH_LONG).show();
                        }

                    } else if (items[item]
                            .equals(getResources().getString(R.string.text_box_dialog_location_type_contact))) {
                        Intent intent = new Intent(Intent.ACTION_PICK);
                        intent.setType(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_TYPE);
                        ((MyActivity) MainFragment.this.getActivity()).setButtonStartLocation(false);

                        MainFragment.this.getActivity().startActivityForResult(intent,
                                OTPApp.CHOOSE_CONTACT_REQUEST_CODE);

                    } else { // Point on Map
                        if (mEndMarker != null) {
                            updateMarkerPosition(mEndMarker.getPosition(), false);
                        } else {
                            setTextBoxLocation("", false);
                            mTbEndLocation
                                    .setHint(getResources().getString(R.string.text_box_need_to_place_marker));
                            mTbEndLocation.requestFocus();
                        }
                    }
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
            return true;
        }

    };

    mTbEndLocation.setOnTouchListener(otlEnd);

    mBtnPlanTrip.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            processRequestTrip();
        }
    });

    OnFocusChangeListener tbLocationOnFocusChangeListener = new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            if (hasFocus) {
                mMap.setOnMapClickListener(onMapClickListener);
            }

            TextView tv = (TextView) v;
            if (!hasFocus) {
                CharSequence tvCharSequence = tv.getText();

                if (tvCharSequence != null) {
                    String text = tvCharSequence.toString();

                    if (!TextUtils.isEmpty(text)) {
                        if (v.getId() == R.id.tbStartLocation && !mIsStartLocationGeocodingCompleted
                                && !mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_ORIGIN_IS_MY_LOCATION, true)) {
                            processAddress(true, text, false);
                        } else if (v.getId() == R.id.tbEndLocation && !mIsEndLocationGeocodingCompleted
                                && !mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_DESTINATION_IS_MY_LOCATION, true)) {
                            processAddress(false, text, false);
                        }
                    } else {
                        if (v.getId() == R.id.tbStartLocation) {
                            tv.setHint(getResources().getString(R.string.text_box_start_location_hint));
                        } else if (v.getId() == R.id.tbEndLocation) {
                            tv.setHint(getResources().getString(R.string.text_box_end_location_hint));
                        }
                    }
                } else {
                    Log.w(OTPApp.TAG,
                            "Focus has changed, but was not possible to obtain start/end" + " textbox text");
                }
            }
        }
    };
    mTbStartLocation.setOnFocusChangeListener(tbLocationOnFocusChangeListener);
    mTbEndLocation.setOnFocusChangeListener(tbLocationOnFocusChangeListener);

    TextWatcher textWatcherStart = 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 (mIsStartLocationChangedByUser) {
                SharedPreferences.Editor prefsEditor = mPrefs.edit();
                prefsEditor.putBoolean(OTPApp.PREFERENCE_KEY_ORIGIN_IS_MY_LOCATION, false);
                prefsEditor.commit();
                mIsStartLocationGeocodingCompleted = false;
            } else {
                mIsStartLocationChangedByUser = true;
            }
        }
    };

    TextWatcher textWatcherEnd = 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 (mIsEndLocationChangedByUser) {
                SharedPreferences.Editor prefsEditor = mPrefs.edit();
                prefsEditor.putBoolean(OTPApp.PREFERENCE_KEY_DESTINATION_IS_MY_LOCATION, false);
                prefsEditor.commit();
                mIsEndLocationGeocodingCompleted = false;
            } else {
                mIsEndLocationChangedByUser = true;
            }
        }
    };

    mTbStartLocation.addTextChangedListener(textWatcherStart);
    mTbEndLocation.addTextChangedListener(textWatcherEnd);

    OnEditorActionListener tbLocationOnEditorActionListener = new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (v.getId() == R.id.tbStartLocation) {
                if (actionId == EditorInfo.IME_ACTION_NEXT
                        || (event != null && event.getAction() == KeyEvent.ACTION_DOWN
                                && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                    if (!mIsStartLocationGeocodingCompleted
                            && !mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_ORIGIN_IS_MY_LOCATION, true)) {
                        CharSequence tvCharSequence = v.getText();
                        if (tvCharSequence != null) {
                            processAddress(true, tvCharSequence.toString(), false);
                        } else {
                            Log.w(OTPApp.TAG, "User switched to next input, but was not possible to"
                                    + "obtain start/end textbox text");
                        }
                    }
                }
            } else if (v.getId() == R.id.tbEndLocation) {
                if (actionId == EditorInfo.IME_ACTION_DONE
                        || (event != null && event.getAction() == KeyEvent.ACTION_DOWN
                                && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                    processRequestTrip();
                }
            }
            return false;
        }
    };

    mTbStartLocation.setOnEditorActionListener(tbLocationOnEditorActionListener);
    mTbEndLocation.setOnEditorActionListener(tbLocationOnEditorActionListener);

    OnClickListener oclDisplayDirection = new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            saveOTPBundle();
            getFragmentListener().onSwitchedToDirectionFragment();
        }
    };
    mBtnDisplayDirection.setOnClickListener(oclDisplayDirection);

    // Do NOT show direction icon if there is no direction yet
    toggleItinerarySelectionSpinner(!getFragmentListener().getCurrentItinerary().isEmpty());

    OnClickListener oclMyLocation = new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            LatLng mCurrentLatLng = getLastLocation();

            if (mCurrentLatLng == null) {
                Toast.makeText(mApplicationContext, mApplicationContext.getResources()
                        .getString(R.string.toast_tripplanner_current_location_error), Toast.LENGTH_LONG)
                        .show();
            } else {
                if (mMap.getCameraPosition().zoom < OTPApp.defaultMyLocationZoomLevel) {
                    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mCurrentLatLng,
                            OTPApp.defaultMyLocationZoomLevel));
                } else {
                    mMap.animateCamera(CameraUpdateFactory.newLatLng(getLastLocation()));
                }
            }
        }
    };
    mBtnMyLocation.setOnClickListener(oclMyLocation);

    OnClickListener oclDateDialog = new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            FragmentTransaction ft = MainFragment.this.getActivity().getSupportFragmentManager()
                    .beginTransaction();
            Fragment prev = MainFragment.this.getActivity().getSupportFragmentManager()
                    .findFragmentByTag(OTPApp.TAG_FRAGMENT_DATE_TIME_DIALOG);
            if (prev != null) {
                ft.remove(prev);
            }
            ft.addToBackStack(null);

            // Create and show the dialog.
            DateTimeDialog newFragment = new DateTimeDialog();

            Date dateDialogDate;
            if (mTripDate == null) {
                dateDialogDate = Calendar.getInstance().getTime();
            } else {
                dateDialogDate = mTripDate;
            }

            Bundle bundle = new Bundle();
            bundle.putSerializable(OTPApp.BUNDLE_KEY_TRIP_DATE, dateDialogDate);
            bundle.putBoolean(OTPApp.BUNDLE_KEY_ARRIVE_BY, mArriveBy);
            newFragment.setArguments(bundle);
            ft.commit();

            newFragment.show(MainFragment.this.getActivity().getSupportFragmentManager(),
                    OTPApp.TAG_FRAGMENT_DATE_TIME_DIALOG);
        }
    };
    mBtnDateDialog.setOnClickListener(oclDateDialog);

    AdapterView.OnItemSelectedListener itinerarySpinnerListener = new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mFragmentListener.onItinerarySelected(position);

            if (!mAppResumed) {
                showRouteOnMap(mFragmentListener.getCurrentItinerary(), true);
            } else {
                showRouteOnMap(mFragmentListener.getCurrentItinerary(), false);
                mAppResumed = false;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    };
    int currentItineraryIndex = mFragmentListener.getCurrentItineraryIndex();

    mItinerarySelectionSpinner.setSelection(currentItineraryIndex);
    mItinerarySelectionSpinner.setOnItemSelectedListener(itinerarySpinnerListener);

    mBikeTriangleParameters.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Double>() {
        @Override
        public void onRangeSeekBarValuesChanged(RangeSeekBar<?> rangeSeekBar, Double minValue,
                Double maxValue) {
            // handle changed range values
            Log.i(OTPApp.TAG, "User selected new range values: MIN=" + minValue + ", MAX=" + maxValue);
        }

    });

    mDdlTravelMode.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            TraverseModeSpinnerItem traverseModeSpinnerItem = (TraverseModeSpinnerItem) mDdlTravelMode
                    .getItemAtPosition(position);
            if (traverseModeSpinnerItem != null) {
                if (traverseModeSpinnerItem.getTraverseModeSet().contains(TraverseMode.BICYCLE)) {
                    setBikeOptimizationAdapter(true);
                    showBikeParameters(true);
                } else {
                    setBikeOptimizationAdapter(false);
                    showBikeParameters(false);
                }

                mBtnPlanTrip.setImageBitmap(BitmapFactory.decodeResource(getResources(),
                        DirectionsGenerator.getModeIcon(traverseModeSpinnerItem.getTraverseModeSet())));
            }
            Log.e(OTPApp.TAG, "Not possible to change travel mode because traverse mode is unknown"
                    + "for selected transport medium");
        }
    });

    mDdlOptimization.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            OptimizeSpinnerItem optimizeSpinnerItem = (OptimizeSpinnerItem) mDdlOptimization
                    .getItemAtPosition(position);
            if (optimizeSpinnerItem != null) {
                showBikeParameters(optimizeSpinnerItem.getOptimizeType().equals(OptimizeType.TRIANGLE));
            } else {
                Log.e(OTPApp.TAG, "Not possible to change optimization mode because selected"
                        + "optimization is unknown");
            }
        }
    });

    mBikeTriangleParameters.setOnRangeSeekBarChangeListener(this);
}

From source file:org.cm.podd.report.activity.ReportActivity.java

@Override
public boolean onSoftKeyAction(TextView view, int actionId, KeyEvent event) {
    switch (actionId) {
    case EditorInfo.IME_ACTION_NEXT:
        Log.d(TAG, "action NEXT");
        View nextTextView = view.focusSearch(View.FOCUS_DOWN);
        if (nextTextView != null) {
            nextTextView.requestFocus();
            if (!(nextTextView instanceof EditText)) {
                hideKeyboard();//from   w w  w.  j  a v  a2 s.  c  o  m
            }
            return true;
        }
    case EditorInfo.IME_ACTION_DONE:
        Log.d(TAG, "action DONE");
        nextScreen();
        hideKeyboard();
        return true;
    }
    return false;
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * Confirms user to create new directory.
 *//*from w w w .j  a v a  2  s. com*/
private void showNewDirectoryCreationDialog() {
    final AlertDialog dialog = Dlg.newAlertDlg(getActivity());

    View view = getLayoutInflater(null).inflate(R.layout.afc_simple_text_input_view, null);
    final EditText textFile = (EditText) view.findViewById(R.id.afc_text1);
    textFile.setHint(R.string.afc_hint_folder_name);
    textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                Ui.showSoftKeyboard(v, false);
                dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
                return true;
            }
            return false;
        }
    });

    dialog.setView(view);
    dialog.setTitle(R.string.afc_cmd_new_folder);
    dialog.setIcon(android.R.drawable.ic_menu_add);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final String name = textFile.getText().toString().trim();
                    if (!FileUtils.isFilenameValid(name)) {
                        Dlg.toast(getActivity(), getString(R.string.afc_pmsg_filename_is_invalid, name),
                                Dlg.LENGTH_SHORT);
                        return;
                    }

                    new LoadingDialog<Void, Void, Uri>(getActivity(), false) {

                        @Override
                        protected Uri doInBackground(Void... params) {
                            return getActivity().getContentResolver().insert(
                                    BaseFile.genContentUriBase(getCurrentLocation().getAuthority()).buildUpon()
                                            .appendPath(getCurrentLocation().getLastPathSegment())
                                            .appendQueryParameter(BaseFile.PARAM_NAME, name)
                                            .appendQueryParameter(BaseFile.PARAM_FILE_TYPE,
                                                    Integer.toString(BaseFile.FILE_TYPE_DIRECTORY))
                                            .build(),
                                    null);
                        }// doInBackground()

                        @Override
                        protected void onPostExecute(Uri result) {
                            super.onPostExecute(result);

                            if (result != null) {
                                Dlg.toast(getActivity(), getString(R.string.afc_msg_done), Dlg.LENGTH_SHORT);
                            } else
                                Dlg.toast(getActivity(),
                                        getString(R.string.afc_pmsg_cannot_create_folder, name),
                                        Dlg.LENGTH_SHORT);
                        }// onPostExecute()

                    }.execute();
                }// onClick()
            });
    dialog.show();
    Ui.showSoftKeyboard(textFile, true);

    final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    buttonOk.setEnabled(false);

    textFile.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            /*
             * Do nothing.
             */
        }// onTextChanged()

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            /*
             * Do nothing.
             */
        }// beforeTextChanged()

        @Override
        public void afterTextChanged(Editable s) {
            buttonOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim()));
        }// afterTextChanged()
    });
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Confirms user to create new directory.
 *///from   ww w . j a v  a 2  s  . co m
private void showNewDirectoryCreationDialog() {
    final AlertDialog dialog = Dlg.newAlertDlg(getActivity());

    View view = getLayoutInflater(null).inflate(R.layout.anhuu_f5be488d_simple_text_input_view, null);
    final EditText textFile = (EditText) view.findViewById(R.id.anhuu_f5be488d_text1);
    textFile.setHint(R.string.anhuu_f5be488d_hint_folder_name);
    textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                UI.showSoftKeyboard(v, false);
                dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
                return true;
            }
            return false;
        }
    });

    dialog.setView(view);
    dialog.setTitle(R.string.anhuu_f5be488d_cmd_new_folder);
    dialog.setIcon(android.R.drawable.ic_menu_add);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final String name = textFile.getText().toString().trim();
                    if (!FileUtils.isFilenameValid(name)) {
                        Dlg.toast(getActivity(),
                                getString(R.string.anhuu_f5be488d_pmsg_filename_is_invalid, name),
                                Dlg.LENGTH_SHORT);
                        return;
                    }

                    new LoadingDialog<Void, Void, Uri>(getActivity(), false) {

                        @Override
                        protected Uri doInBackground(Void... params) {
                            return getActivity().getContentResolver().insert(
                                    BaseFile.genContentUriBase(getCurrentLocation().getAuthority()).buildUpon()
                                            .appendPath(getCurrentLocation().getLastPathSegment())
                                            .appendQueryParameter(BaseFile.PARAM_NAME, name)
                                            .appendQueryParameter(BaseFile.PARAM_FILE_TYPE,
                                                    Integer.toString(BaseFile.FILE_TYPE_DIRECTORY))
                                            .build(),
                                    null);
                        }// doInBackground()

                        @Override
                        protected void onPostExecute(Uri result) {
                            super.onPostExecute(result);

                            if (result != null) {
                                Dlg.toast(getActivity(), getString(R.string.anhuu_f5be488d_msg_done),
                                        Dlg.LENGTH_SHORT);
                            } else
                                Dlg.toast(getActivity(),
                                        getString(R.string.anhuu_f5be488d_pmsg_cannot_create_folder, name),
                                        Dlg.LENGTH_SHORT);
                        }// onPostExecute()

                    }.execute();
                }// onClick()
            });
    dialog.show();
    UI.showSoftKeyboard(textFile, true);

    final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    buttonOk.setEnabled(false);

    textFile.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            /*
             * Do nothing.
             */
        }// onTextChanged()

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            /*
             * Do nothing.
             */
        }// beforeTextChanged()

        @Override
        public void afterTextChanged(Editable s) {
            buttonOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim()));
        }// afterTextChanged()
    });
}