Search in sources :

Example 41 with KeyEvent

use of android.view.KeyEvent in project FluxyAndroidTodo by armueller.

the class TodoListArrayAdapter method setHolderListeners.

private void setHolderListeners(final ViewHolder holder, final TodoItem item) {
    holder.todoDescription.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            DialogFragment editOrDeleteDialog = new EditOrDeleteDialogFragment();
            Bundle args = new Bundle();
            args.putLong("todoItemId", item.getId());
            editOrDeleteDialog.setArguments(args);
            editOrDeleteDialog.show(activity.getFragmentManager(), String.valueOf(item.getId()));
            return true;
        }
    });
    holder.todoEditDescription.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                actionCreator.createEditTodoAction(item.getId(), v.getText().toString());
                handled = true;
            }
            return handled;
        }
    });
    holder.todoCheckBox.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            actionCreator.createToggleTodoCompleteAction(item.getId());
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) Bundle(android.os.Bundle) DialogFragment(android.app.DialogFragment) TextView(android.widget.TextView) InjectView(butterknife.InjectView) TextView(android.widget.TextView) View(android.view.View)

Example 42 with KeyEvent

use of android.view.KeyEvent in project coursera-android by aporter.

the class SamplerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // 
    final ImageButton button = (ImageButton) findViewById(R.id.button);
    button.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Show Toast message 
            Toast.makeText(SamplerActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
        }
    });
    final EditText edittext = (EditText) findViewById(R.id.edittext);
    edittext.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "Done" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Show Toast message 
                Toast.makeText(SamplerActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                return true;
            }
            return false;
        }
    });
    final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
    checkbox.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Show Toast message indicating the CheckBox's Checked state
            if (((CheckBox) v).isChecked()) {
                Toast.makeText(SamplerActivity.this, "CheckBox checked", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(SamplerActivity.this, "CheckBox not checked", Toast.LENGTH_SHORT).show();
            }
        }
    });
    final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
    final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
    radio_red.setOnClickListener(radio_listener);
    radio_blue.setOnClickListener(radio_listener);
    final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
    togglebutton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Perform action on clicks
            if (togglebutton.isChecked()) {
                Toast.makeText(SamplerActivity.this, "ToggleButton checked", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(SamplerActivity.this, "ToggleButton not checked", Toast.LENGTH_SHORT).show();
            }
        }
    });
    final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
    ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            Toast.makeText(SamplerActivity.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : EditText(android.widget.EditText) ToggleButton(android.widget.ToggleButton) OnRatingBarChangeListener(android.widget.RatingBar.OnRatingBarChangeListener) RadioButton(android.widget.RadioButton) View(android.view.View) RatingBar(android.widget.RatingBar) KeyEvent(android.view.KeyEvent) ImageButton(android.widget.ImageButton) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) OnKeyListener(android.view.View.OnKeyListener)

Example 43 with KeyEvent

use of android.view.KeyEvent in project FBReaderJ by geometer.

the class FileChooserActivity method doCreateNewDir.

// doSwitchViewType()
/**
     * Confirms user to create new directory.
     */
private void doCreateNewDir() {
    if (mFileProvider instanceof LocalFileProvider && !Utils.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        Dlg.toast(this, R.string.afc_msg_app_doesnot_have_permission_to_create_files, Dlg._LengthShort);
        return;
    }
    if ((getLocation() instanceof File)) {
        if (!((File) getLocation()).canWrite()) {
            Dlg.toast(this, R.string.afc_msg_app_cant_create_folder, Dlg._LengthShort);
            return;
        }
    }
    final AlertDialog _dlg = Dlg.newDlg(this);
    View view = getLayoutInflater().inflate(R.layout.afc_simple_text_input_view, null);
    final EditText _textFile = (EditText) view.findViewById(R.id.afc_simple_text_input_view_text1);
    _textFile.setHint(mTextResources.get("folderNameHint"));
    _textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                Ui.hideSoftKeyboard(FileChooserActivity.this, _textFile.getWindowToken());
                _dlg.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
                return true;
            }
            return false;
        }
    });
    _dlg.setView(view);
    _dlg.setTitle(mTextResources.get("newFolder"));
    _dlg.setIcon(android.R.drawable.ic_menu_add);
    _dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String name = _textFile.getText().toString().trim();
            if (!FileUtils.isFilenameValid(name)) {
                Dlg.toast(FileChooserActivity.this, getString(R.string.afc_pmsg_filename_is_invalid, name), Dlg._LengthShort);
                return;
            }
            final IFileProvider fileProvider = mFileProvider;
            final IFile location = getLocation();
            if (fileProvider == null || location == null) {
                return;
            }
            IFile dir = fileProvider.fromPath(String.format("%s/%s", location.getAbsolutePath(), name));
            if (dir.mkdir()) {
                Dlg.toast(FileChooserActivity.this, getString(R.string.afc_msg_done), Dlg._LengthShort);
                setLocation(getLocation(), null);
            } else
                Dlg.toast(FileChooserActivity.this, getString(R.string.afc_pmsg_cannot_create_folder, name), Dlg._LengthShort);
        }
    });
    _dlg.show();
    final Button _btnOk = _dlg.getButton(DialogInterface.BUTTON_POSITIVE);
    _btnOk.setEnabled(false);
    _textFile.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            _btnOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim()));
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) IFileProvider(group.pals.android.lib.ui.filechooser.services.IFileProvider) IFile(group.pals.android.lib.ui.filechooser.io.IFile) DialogInterface(android.content.DialogInterface) LocalFileProvider(group.pals.android.lib.ui.filechooser.services.LocalFileProvider) GridView(android.widget.GridView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) IFile(group.pals.android.lib.ui.filechooser.io.IFile) File(java.io.File)

Example 44 with KeyEvent

use of android.view.KeyEvent in project WordPress-Android by wordpress-mobile.

the class LegacyEditorFragment method onTouch.

@Override
public boolean onTouch(View v, MotionEvent event) {
    float pos = event.getY();
    if (event.getAction() == 0)
        mLastYPos = pos;
    if (event.getAction() > 1) {
        int scrollThreshold = DisplayUtils.dpToPx(getActivity(), 2);
        if (((mLastYPos - pos) > scrollThreshold) || ((pos - mLastYPos) > scrollThreshold))
            mScrollDetected = true;
    }
    mLastYPos = pos;
    if (event.getAction() == MotionEvent.ACTION_UP) {
        ActionBar actionBar = getActionBar();
        if (actionBar != null && actionBar.isShowing()) {
            setContentEditingModeVisible(true);
            return false;
        }
    }
    if (event.getAction() == MotionEvent.ACTION_UP && !mScrollDetected) {
        Layout layout = ((TextView) v).getLayout();
        int x = (int) event.getX();
        int y = (int) event.getY();
        x += v.getScrollX();
        y += v.getScrollY();
        if (layout != null) {
            int line = layout.getLineForVertical(y);
            int charPosition = layout.getOffsetForHorizontal(line, x);
            Spannable spannable = mContentEditText.getText();
            if (spannable == null) {
                return false;
            }
            // check if image span was tapped
            WPImageSpan[] imageSpans = spannable.getSpans(charPosition, charPosition, WPImageSpan.class);
            if (imageSpans.length != 0) {
                final WPImageSpan imageSpan = imageSpans[0];
                MediaFile mediaFile = imageSpan.getMediaFile();
                if (mediaFile == null)
                    return false;
                if (!mediaFile.isVideo()) {
                    LayoutInflater factory = LayoutInflater.from(getActivity());
                    final View alertView = factory.inflate(R.layout.alert_image_options, null);
                    if (alertView == null)
                        return false;
                    final EditText imageWidthText = (EditText) alertView.findViewById(R.id.imageWidthText);
                    final EditText titleText = (EditText) alertView.findViewById(R.id.title);
                    final EditText caption = (EditText) alertView.findViewById(R.id.caption);
                    final CheckBox featuredCheckBox = (CheckBox) alertView.findViewById(R.id.featuredImage);
                    final CheckBox featuredInPostCheckBox = (CheckBox) alertView.findViewById(R.id.featuredInPost);
                    // show featured image checkboxes if supported
                    if (mFeaturedImageSupported) {
                        featuredCheckBox.setVisibility(View.VISIBLE);
                        featuredInPostCheckBox.setVisibility(View.VISIBLE);
                    }
                    featuredCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            if (isChecked) {
                                featuredInPostCheckBox.setVisibility(View.VISIBLE);
                            } else {
                                featuredInPostCheckBox.setVisibility(View.GONE);
                            }
                        }
                    });
                    final SeekBar seekBar = (SeekBar) alertView.findViewById(R.id.imageWidth);
                    final Spinner alignmentSpinner = (Spinner) alertView.findViewById(R.id.alignment_spinner);
                    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.alignment_array, android.R.layout.simple_spinner_item);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    alignmentSpinner.setAdapter(adapter);
                    seekBar.setProgress(mediaFile.getWidth());
                    titleText.setText(mediaFile.getTitle());
                    caption.setText(mediaFile.getCaption());
                    featuredCheckBox.setChecked(mediaFile.isFeatured());
                    if (mediaFile.isFeatured()) {
                        featuredInPostCheckBox.setVisibility(View.VISIBLE);
                    } else {
                        featuredInPostCheckBox.setVisibility(View.GONE);
                    }
                    featuredInPostCheckBox.setChecked(mediaFile.isFeaturedInPost());
                    alignmentSpinner.setSelection(mediaFile.getHorizontalAlignment(), true);
                    final int maxWidth = MediaUtils.getMaximumImageWidth(getActivity(), imageSpan.getImageSource(), mBlogSettingMaxImageWidth);
                    seekBar.setMax(maxWidth / 10);
                    imageWidthText.setText(String.format(Locale.US, "%dpx", maxWidth));
                    if (mediaFile.getWidth() != 0) {
                        seekBar.setProgress(mediaFile.getWidth() / 10);
                    }
                    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {
                        }

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                            if (progress == 0) {
                                progress = 1;
                            }
                            imageWidthText.setText(String.format(Locale.US, "%dpx", progress * 10));
                        }
                    });
                    imageWidthText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

                        @Override
                        public void onFocusChange(View v, boolean hasFocus) {
                            if (hasFocus) {
                                imageWidthText.setText("");
                            }
                        }
                    });
                    imageWidthText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

                        @Override
                        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                            int width = getEditTextIntegerClamped(imageWidthText, 10, maxWidth);
                            seekBar.setProgress(width / 10);
                            imageWidthText.setSelection((String.valueOf(width).length()));
                            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.hideSoftInputFromWindow(imageWidthText.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
                            return true;
                        }
                    });
                    showImageSettings(alertView, titleText, caption, imageWidthText, featuredCheckBox, featuredInPostCheckBox, maxWidth, alignmentSpinner, imageSpan);
                    mScrollDetected = false;
                    return true;
                }
            } else {
                mContentEditText.setMovementMethod(ArrowKeyMovementMethod.getInstance());
                int selectionStart = mContentEditText.getSelectionStart();
                if (selectionStart >= 0 && mContentEditText.getSelectionEnd() >= selectionStart)
                    mContentEditText.setSelection(selectionStart, mContentEditText.getSelectionEnd());
            }
            // get media gallery spans
            MediaGalleryImageSpan[] gallerySpans = spannable.getSpans(charPosition, charPosition, MediaGalleryImageSpan.class);
            if (gallerySpans.length > 0) {
                final MediaGalleryImageSpan gallerySpan = gallerySpans[0];
                Intent intent = new Intent(ACTION_MEDIA_GALLERY_TOUCHED);
                intent.putExtra(EXTRA_MEDIA_GALLERY, gallerySpan.getMediaGallery());
                getActivity().sendBroadcast(intent);
            }
        }
    } else if (event.getAction() == 1) {
        mScrollDetected = false;
    }
    return false;
}
Also used : Spinner(android.widget.Spinner) InputMethodManager(android.view.inputmethod.InputMethodManager) KeyEvent(android.view.KeyEvent) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) MediaFile(org.wordpress.android.util.helpers.MediaFile) WPEditText(org.wordpress.android.util.widgets.WPEditText) EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) WPImageSpan(org.wordpress.android.util.helpers.WPImageSpan) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) Layout(android.text.Layout) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) MediaGalleryImageSpan(org.wordpress.android.util.helpers.MediaGalleryImageSpan) Spannable(android.text.Spannable) CompoundButton(android.widget.CompoundButton)

Example 45 with KeyEvent

use of android.view.KeyEvent in project WordPress-Android by wordpress-mobile.

the class LegacyEditorFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_edit_post_content, container, false);
    mFormatBar = (LinearLayout) rootView.findViewById(R.id.format_bar);
    mTitleEditText = (EditText) rootView.findViewById(R.id.post_title);
    mTitleEditText.setText(mTitle);
    mTitleEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // Go to full screen editor when 'next' button is tapped on soft keyboard
            ActionBar actionBar = getActionBar();
            if (actionId == EditorInfo.IME_ACTION_NEXT && actionBar != null && actionBar.isShowing()) {
                setContentEditingModeVisible(true);
            }
            return false;
        }
    });
    mContentEditText = (WPEditText) rootView.findViewById(R.id.post_content);
    mContentEditText.setText(mContent);
    mPostContentLinearLayout = (LinearLayout) rootView.findViewById(R.id.post_content_wrapper);
    mPostSettingsLinearLayout = (LinearLayout) rootView.findViewById(R.id.post_settings_wrapper);
    Button postSettingsButton = (Button) rootView.findViewById(R.id.post_settings_button);
    postSettingsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mEditorFragmentListener.onSettingsClicked();
        }
    });
    mBoldToggleButton = (ToggleButton) rootView.findViewById(R.id.bold);
    mEmToggleButton = (ToggleButton) rootView.findViewById(R.id.em);
    mBquoteToggleButton = (ToggleButton) rootView.findViewById(R.id.bquote);
    mUnderlineToggleButton = (ToggleButton) rootView.findViewById(R.id.underline);
    mStrikeToggleButton = (ToggleButton) rootView.findViewById(R.id.strike);
    mAddPictureButton = (Button) rootView.findViewById(R.id.addPictureButton);
    Button linkButton = (Button) rootView.findViewById(R.id.link);
    Button moreButton = (Button) rootView.findViewById(R.id.more);
    registerForContextMenu(mAddPictureButton);
    mContentEditText = (WPEditText) rootView.findViewById(R.id.post_content);
    mContentEditText.setOnSelectionChangedListener(this);
    mContentEditText.setOnTouchListener(this);
    mContentEditText.addTextChangedListener(this);
    mContentEditText.setOnEditTextImeBackListener(new WPEditText.EditTextImeBackListener() {

        @Override
        public void onImeBack(WPEditText ctrl, String text) {
            // Go back to regular editor if IME keyboard is dismissed
            // Bottom comparison is there to ensure that the keyboard is actually showing
            ActionBar actionBar = getActionBar();
            if (mRootView.getBottom() < mFullViewBottom && actionBar != null && !actionBar.isShowing()) {
                setContentEditingModeVisible(false);
            }
        }
    });
    mAddPictureButton.setOnClickListener(mFormatBarButtonClickListener);
    mBoldToggleButton.setOnClickListener(mFormatBarButtonClickListener);
    linkButton.setOnClickListener(mFormatBarButtonClickListener);
    mEmToggleButton.setOnClickListener(mFormatBarButtonClickListener);
    mUnderlineToggleButton.setOnClickListener(mFormatBarButtonClickListener);
    mStrikeToggleButton.setOnClickListener(mFormatBarButtonClickListener);
    mBquoteToggleButton.setOnClickListener(mFormatBarButtonClickListener);
    moreButton.setOnClickListener(mFormatBarButtonClickListener);
    mEditorFragmentListener.onEditorFragmentInitialized();
    if (savedInstanceState != null) {
        Parcelable[] spans = savedInstanceState.getParcelableArray(KEY_IMAGE_SPANS);
        mContent = savedInstanceState.getString(KEY_CONTENT, "");
        mContentEditText.setText(mContent);
        mContentEditText.setSelection(savedInstanceState.getInt(KEY_START, 0), savedInstanceState.getInt(KEY_END, 0));
        if (spans != null && spans.length > 0) {
            for (Parcelable s : spans) {
                WPImageSpan editSpan = (WPImageSpan) s;
                addMediaFile(editSpan.getMediaFile(), editSpan.getMediaFile().getFilePath(), mImageLoader, editSpan.getStartPosition(), editSpan.getEndPosition());
            }
        }
    }
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) Parcelable(android.os.Parcelable) WPImageSpan(org.wordpress.android.util.helpers.WPImageSpan) View(android.view.View) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) CompoundButton(android.widget.CompoundButton) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) WPEditText(org.wordpress.android.util.widgets.WPEditText)

Aggregations

KeyEvent (android.view.KeyEvent)513 View (android.view.View)145 TextView (android.widget.TextView)109 Intent (android.content.Intent)53 ImageView (android.widget.ImageView)38 DialogInterface (android.content.DialogInterface)36 EditText (android.widget.EditText)36 KeyCharacterMap (android.view.KeyCharacterMap)35 Editable (android.text.Editable)34 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)32 Instrumentation (android.app.Instrumentation)30 OnClickListener (android.view.View.OnClickListener)30 Paint (android.graphics.Paint)27 Button (android.widget.Button)27 TextWatcher (android.text.TextWatcher)24 InputMethodManager (android.view.inputmethod.InputMethodManager)22 AlertDialog (android.app.AlertDialog)21 Message (android.os.Message)21 LayoutInflater (android.view.LayoutInflater)21 Test (org.junit.Test)20