Search in sources :

Example 36 with InputMethodManager

use of android.view.inputmethod.InputMethodManager 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 37 with InputMethodManager

use of android.view.inputmethod.InputMethodManager in project XobotOS by xamarin.

the class SearchDialog method onBackPressed.

@Override
public void onBackPressed() {
    // If the input method is covering the search dialog completely,
    // e.g. in landscape mode with no hard keyboard, dismiss just the input method
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null && imm.isFullscreenMode() && imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0)) {
        return;
    }
    // Close search dialog
    cancel();
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 38 with InputMethodManager

use of android.view.inputmethod.InputMethodManager in project XobotOS by xamarin.

the class SearchDialog method hide.

@Override
public void hide() {
    if (!isShowing())
        return;
    // We made sure the IME was displayed, so also make sure it is closed
    // when we go away.
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
    }
    super.hide();
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 39 with InputMethodManager

use of android.view.inputmethod.InputMethodManager in project XobotOS by xamarin.

the class View method onAttachedToWindow.

/**
     * This is called when the view is attached to a window.  At this point it
     * has a Surface and will start drawing.  Note that this function is
     * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)},
     * however it may be called any time before the first onDraw -- including
     * before or after {@link #onMeasure(int, int)}.
     *
     * @see #onDetachedFromWindow()
     */
protected void onAttachedToWindow() {
    if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) {
        mParent.requestTransparentRegion(this);
    }
    if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) {
        initialAwakenScrollBars();
        mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH;
    }
    jumpDrawablesToCurrentState();
    // Order is important here: LayoutDirection MUST be resolved before Padding
    // and TextDirection
    resolveLayoutDirectionIfNeeded();
    resolvePadding();
    resolveTextDirection();
    if (isFocused()) {
        InputMethodManager imm = InputMethodManager.peekInstance();
        imm.focusIn(this);
    }
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 40 with InputMethodManager

use of android.view.inputmethod.InputMethodManager in project XobotOS by xamarin.

the class ViewRootImpl method handleMessage.

@Override
public void handleMessage(Message msg) {
    switch(msg.what) {
        case View.AttachInfo.INVALIDATE_MSG:
            ((View) msg.obj).invalidate();
            break;
        case View.AttachInfo.INVALIDATE_RECT_MSG:
            final View.AttachInfo.InvalidateInfo info = (View.AttachInfo.InvalidateInfo) msg.obj;
            info.target.invalidate(info.left, info.top, info.right, info.bottom);
            info.release();
            break;
        case DO_TRAVERSAL:
            if (mProfile) {
                Debug.startMethodTracing("ViewAncestor");
            }
            final long traversalStartTime;
            if (ViewDebug.DEBUG_LATENCY) {
                traversalStartTime = System.nanoTime();
                mLastDrawDurationNanos = 0;
            }
            performTraversals();
            if (ViewDebug.DEBUG_LATENCY) {
                long now = System.nanoTime();
                Log.d(TAG, "Latency: Spent " + ((now - traversalStartTime) * 0.000001f) + "ms in performTraversals(), with " + (mLastDrawDurationNanos * 0.000001f) + "ms of that time in draw()");
                mLastTraversalFinishedTimeNanos = now;
            }
            if (mProfile) {
                Debug.stopMethodTracing();
                mProfile = false;
            }
            break;
        case FINISHED_EVENT:
            handleFinishedEvent(msg.arg1, msg.arg2 != 0);
            break;
        case DISPATCH_KEY:
            deliverKeyEvent((KeyEvent) msg.obj, msg.arg1 != 0);
            break;
        case DISPATCH_POINTER:
            deliverPointerEvent((MotionEvent) msg.obj, msg.arg1 != 0);
            break;
        case DISPATCH_TRACKBALL:
            deliverTrackballEvent((MotionEvent) msg.obj, msg.arg1 != 0);
            break;
        case DISPATCH_GENERIC_MOTION:
            deliverGenericMotionEvent((MotionEvent) msg.obj, msg.arg1 != 0);
            break;
        case DISPATCH_APP_VISIBILITY:
            handleAppVisibility(msg.arg1 != 0);
            break;
        case DISPATCH_GET_NEW_SURFACE:
            handleGetNewSurface();
            break;
        case RESIZED:
            ResizedInfo ri = (ResizedInfo) msg.obj;
            if (mWinFrame.width() == msg.arg1 && mWinFrame.height() == msg.arg2 && mPendingContentInsets.equals(ri.coveredInsets) && mPendingVisibleInsets.equals(ri.visibleInsets) && ((ResizedInfo) msg.obj).newConfig == null) {
                break;
            }
        // fall through...
        case RESIZED_REPORT:
            if (mAdded) {
                Configuration config = ((ResizedInfo) msg.obj).newConfig;
                if (config != null) {
                    updateConfiguration(config, false);
                }
                mWinFrame.left = 0;
                mWinFrame.right = msg.arg1;
                mWinFrame.top = 0;
                mWinFrame.bottom = msg.arg2;
                mPendingContentInsets.set(((ResizedInfo) msg.obj).coveredInsets);
                mPendingVisibleInsets.set(((ResizedInfo) msg.obj).visibleInsets);
                if (msg.what == RESIZED_REPORT) {
                    mReportNextDraw = true;
                }
                if (mView != null) {
                    forceLayout(mView);
                }
                requestLayout();
            }
            break;
        case WINDOW_FOCUS_CHANGED:
            {
                if (mAdded) {
                    boolean hasWindowFocus = msg.arg1 != 0;
                    mAttachInfo.mHasWindowFocus = hasWindowFocus;
                    profileRendering(hasWindowFocus);
                    if (hasWindowFocus) {
                        boolean inTouchMode = msg.arg2 != 0;
                        ensureTouchModeLocally(inTouchMode);
                        if (mAttachInfo.mHardwareRenderer != null && mSurface != null && mSurface.isValid()) {
                            mFullRedrawNeeded = true;
                            try {
                                mAttachInfo.mHardwareRenderer.initializeIfNeeded(mWidth, mHeight, mAttachInfo, mHolder);
                            } catch (Surface.OutOfResourcesException e) {
                                Log.e(TAG, "OutOfResourcesException locking surface", e);
                                try {
                                    if (!sWindowSession.outOfMemory(mWindow)) {
                                        Slog.w(TAG, "No processes killed for memory; killing self");
                                        Process.killProcess(Process.myPid());
                                    }
                                } catch (RemoteException ex) {
                                }
                                // Retry in a bit.
                                sendMessageDelayed(obtainMessage(msg.what, msg.arg1, msg.arg2), 500);
                                return;
                            }
                        }
                    }
                    mLastWasImTarget = WindowManager.LayoutParams.mayUseInputMethod(mWindowAttributes.flags);
                    InputMethodManager imm = InputMethodManager.peekInstance();
                    if (mView != null) {
                        if (hasWindowFocus && imm != null && mLastWasImTarget) {
                            imm.startGettingWindowFocus(mView);
                        }
                        mAttachInfo.mKeyDispatchState.reset();
                        mView.dispatchWindowFocusChanged(hasWindowFocus);
                    }
                    // so all of the view state is set up correctly.
                    if (hasWindowFocus) {
                        if (imm != null && mLastWasImTarget) {
                            imm.onWindowFocus(mView, mView.findFocus(), mWindowAttributes.softInputMode, !mHasHadWindowFocus, mWindowAttributes.flags);
                        }
                        // Clear the forward bit.  We can just do this directly, since
                        // the window manager doesn't care about it.
                        mWindowAttributes.softInputMode &= ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                        ((WindowManager.LayoutParams) mView.getLayoutParams()).softInputMode &= ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
                        mHasHadWindowFocus = true;
                    }
                    if (hasWindowFocus && mView != null) {
                        sendAccessibilityEvents();
                    }
                }
            }
            break;
        case DIE:
            doDie();
            break;
        case DISPATCH_KEY_FROM_IME:
            {
                if (LOCAL_LOGV)
                    Log.v(TAG, "Dispatching key " + msg.obj + " from IME to " + mView);
                KeyEvent event = (KeyEvent) msg.obj;
                if ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) != 0) {
                    // The IME is trying to say this event is from the
                    // system!  Bad bad bad!
                    //noinspection UnusedAssignment
                    event = KeyEvent.changeFlags(event, event.getFlags() & ~KeyEvent.FLAG_FROM_SYSTEM);
                }
                deliverKeyEventPostIme((KeyEvent) msg.obj, false);
            }
            break;
        case FINISH_INPUT_CONNECTION:
            {
                InputMethodManager imm = InputMethodManager.peekInstance();
                if (imm != null) {
                    imm.reportFinishInputConnection((InputConnection) msg.obj);
                }
            }
            break;
        case CHECK_FOCUS:
            {
                InputMethodManager imm = InputMethodManager.peekInstance();
                if (imm != null) {
                    imm.checkFocus();
                }
            }
            break;
        case CLOSE_SYSTEM_DIALOGS:
            {
                if (mView != null) {
                    mView.onCloseSystemDialogs((String) msg.obj);
                }
            }
            break;
        case DISPATCH_DRAG_EVENT:
        case DISPATCH_DRAG_LOCATION_EVENT:
            {
                DragEvent event = (DragEvent) msg.obj;
                // only present when this app called startDrag()
                event.mLocalState = mLocalDragState;
                handleDragEvent(event);
            }
            break;
        case DISPATCH_SYSTEM_UI_VISIBILITY:
            {
                handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo) msg.obj);
            }
            break;
        case UPDATE_CONFIGURATION:
            {
                Configuration config = (Configuration) msg.obj;
                if (config.isOtherSeqNewer(mLastConfiguration)) {
                    config = mLastConfiguration;
                }
                updateConfiguration(config, false);
            }
            break;
        case DO_FIND_ACCESSIBLITY_NODE_INFO_BY_ACCESSIBILITY_ID:
            {
                if (mView != null) {
                    getAccessibilityInteractionController().findAccessibilityNodeInfoByAccessibilityIdUiThread(msg);
                }
            }
            break;
        case DO_PERFORM_ACCESSIBILITY_ACTION:
            {
                if (mView != null) {
                    getAccessibilityInteractionController().perfromAccessibilityActionUiThread(msg);
                }
            }
            break;
        case DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_ID:
            {
                if (mView != null) {
                    getAccessibilityInteractionController().findAccessibilityNodeInfoByViewIdUiThread(msg);
                }
            }
            break;
        case DO_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_TEXT:
            {
                if (mView != null) {
                    getAccessibilityInteractionController().findAccessibilityNodeInfosByViewTextUiThread(msg);
                }
            }
            break;
    }
}
Also used : Configuration(android.content.res.Configuration) InputMethodManager(android.view.inputmethod.InputMethodManager) InputConnection(android.view.inputmethod.InputConnection) RemoteException(android.os.RemoteException)

Aggregations

InputMethodManager (android.view.inputmethod.InputMethodManager)631 View (android.view.View)120 TextView (android.widget.TextView)67 Paint (android.graphics.Paint)43 Spannable (android.text.Spannable)34 Editable (android.text.Editable)33 EditText (android.widget.EditText)33 ImageView (android.widget.ImageView)31 Intent (android.content.Intent)29 RemoteException (android.os.RemoteException)23 KeyEvent (android.view.KeyEvent)22 TextPaint (android.text.TextPaint)21 Point (android.graphics.Point)18 InputMethodInfo (android.view.inputmethod.InputMethodInfo)18 AdapterView (android.widget.AdapterView)18 Button (android.widget.Button)16 RemoteView (android.widget.RemoteViews.RemoteView)16 Resources (android.content.res.Resources)15 ListView (android.widget.ListView)15 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)14