Search in sources :

Example 61 with EditText

use of android.widget.EditText 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 62 with EditText

use of android.widget.EditText in project WordPress-Android by wordpress-mobile.

the class LinkDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.dialog_link, null);
    final EditText urlEditText = (EditText) view.findViewById(R.id.linkURL);
    final EditText linkEditText = (EditText) view.findViewById(R.id.linkText);
    builder.setView(view).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent();
            intent.putExtra(LINK_DIALOG_ARG_URL, urlEditText.getText().toString());
            intent.putExtra(LINK_DIALOG_ARG_TEXT, linkEditText.getText().toString());
            getTargetFragment().onActivityResult(getTargetRequestCode(), getTargetRequestCode(), intent);
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            LinkDialogFragment.this.getDialog().cancel();
        }
    });
    // If updating an existing link, add a 'Delete' button
    if (getTargetRequestCode() == LINK_DIALOG_REQUEST_CODE_UPDATE) {
        builder.setNeutralButton(R.string.delete, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                getTargetFragment().onActivityResult(getTargetRequestCode(), LINK_DIALOG_REQUEST_CODE_DELETE, null);
            }
        });
    }
    // Prepare initial state of EditTexts
    Bundle bundle = getArguments();
    if (bundle != null) {
        linkEditText.setText(bundle.getString(LINK_DIALOG_ARG_TEXT));
        String url = bundle.getString(LINK_DIALOG_ARG_URL);
        if (url != null) {
            urlEditText.setText(url);
        }
        urlEditText.selectAll();
    }
    AlertDialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) Intent(android.content.Intent) View(android.view.View) LayoutInflater(android.view.LayoutInflater)

Example 63 with EditText

use of android.widget.EditText in project android-priority-jobqueue by yigit.

the class SampleTwitterClient method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    dataDirty = true;
    setContentView(R.layout.main);
    jobManager = TwitterApplication.getInstance().getJobManager();
    ListView listView = (ListView) findViewById(R.id.tweet_list);
    tweetAdapter = new TweetAdapter(getLayoutInflater());
    findViewById(R.id.send_tweet).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            EditText text = (EditText) findViewById(R.id.edit_status);
            if (text.getText().toString().trim().length() > 0) {
                sendTweet(text.getText().toString());
                text.setText("");
            }
        }
    });
    listView.setAdapter(tweetAdapter);
    EventBus.getDefault().register(this);
}
Also used : EditText(android.widget.EditText) ListView(android.widget.ListView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView)

Example 64 with EditText

use of android.widget.EditText in project TourGuide by worker8.

the class AdjustPaddingOverlayActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mActivity = this;
    setContentView(R.layout.activity_overlay_customization);
    final Button button = (Button) findViewById(R.id.button);
    Button next_button = (Button) findViewById(R.id.next_button);
    TextInputLayout textInputLayout = (TextInputLayout) findViewById(R.id.input_layout);
    final EditText paddingET = (EditText) findViewById(R.id.padding_edit_text);
    paddingET.setText(String.valueOf(10));
    textInputLayout.setVisibility(View.VISIBLE);
    next_button.setVisibility(View.GONE);
    final ToolTip toolTip = new ToolTip().setTitle("Hello!").setDescription(String.format("Current OVERLAY Padding: %s", paddingET.getText().toString()));
    final Overlay overlay = new Overlay().setBackgroundColor(Color.parseColor("#AAFF0000")).disableClick(false).disableClickThroughHole(false).setStyle(Overlay.Style.ROUNDED_RECTANGLE).setHolePadding(Integer.valueOf(paddingET.getText().toString())).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mTutorialHandler.cleanUp();
        }
    });
    // the return handler is used to manipulate the cleanup of all the tutorial elements
    mTutorialHandler = TourGuide.init(this).with(TourGuide.Technique.CLICK).setPointer(null).setToolTip(toolTip).setOverlay(overlay).playOn(button);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mTutorialHandler.cleanUp();
            mTutorialHandler.playOn(button);
        }
    });
    button.setText("   show   ");
    paddingET.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            overlay.setHolePadding((charSequence.length() > 0 && TextUtils.isDigitsOnly(charSequence)) ? Integer.valueOf(charSequence.toString()) : 10);
            toolTip.setDescription(String.format("Current Overlay Padding: %s", charSequence));
            mTutorialHandler.setOverlay(overlay);
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
}
Also used : EditText(android.widget.EditText) ToolTip(tourguide.tourguide.ToolTip) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout) Overlay(tourguide.tourguide.Overlay) View(android.view.View)

Example 65 with EditText

use of android.widget.EditText in project Hummingbird-for-Android by xiprox.

the class MainFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, null);
    final EditText mId = (EditText) rootView.findViewById(R.id.anime_id);
    Button mGo = (Button) rootView.findViewById(R.id.load_by_id);
    mGo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getActivity(), AnimeDetailsActivity.class);
            intent.putExtra(AnimeDetailsActivity.ARG_ID, Integer.parseInt(mId.getText().toString()));
            startActivity(intent);
        }
    });
    return rootView;
}
Also used : EditText(android.widget.EditText) Button(android.widget.Button) Intent(android.content.Intent) View(android.view.View)

Aggregations

EditText (android.widget.EditText)655 View (android.view.View)309 TextView (android.widget.TextView)220 DialogInterface (android.content.DialogInterface)143 AlertDialog (android.app.AlertDialog)126 Button (android.widget.Button)126 Intent (android.content.Intent)99 LinearLayout (android.widget.LinearLayout)79 ImageView (android.widget.ImageView)61 AlertDialog (android.support.v7.app.AlertDialog)54 ScrollView (android.widget.ScrollView)52 LayoutInflater (android.view.LayoutInflater)48 AdapterView (android.widget.AdapterView)46 ViewGroup (android.view.ViewGroup)42 Editable (android.text.Editable)41 Context (android.content.Context)40 RecyclerView (android.support.v7.widget.RecyclerView)40 ListView (android.widget.ListView)39 Dialog (android.app.Dialog)36 Bundle (android.os.Bundle)36