Search in sources :

Example 56 with KeyEvent

use of android.view.KeyEvent in project platform_frameworks_base by android.

the class TextView method onKeyMultiple.

@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
    KeyEvent down = KeyEvent.changeAction(event, KeyEvent.ACTION_DOWN);
    final int which = doKeyDown(keyCode, down, event);
    if (which == KEY_EVENT_NOT_HANDLED) {
        // Go through default dispatching.
        return super.onKeyMultiple(keyCode, repeatCount, event);
    }
    if (which == KEY_EVENT_HANDLED) {
        // Consumed the whole thing.
        return true;
    }
    repeatCount--;
    // We are going to dispatch the remaining events to either the input
    // or movement method.  To do this, we will just send a repeated stream
    // of down and up events until we have done the complete repeatCount.
    // It would be nice if those interfaces had an onKeyMultiple() method,
    // but adding that is a more complicated change.
    KeyEvent up = KeyEvent.changeAction(event, KeyEvent.ACTION_UP);
    if (which == KEY_DOWN_HANDLED_BY_KEY_LISTENER) {
        // mEditor and mEditor.mInput are not null from doKeyDown
        mEditor.mKeyListener.onKeyUp(this, (Editable) mText, keyCode, up);
        while (--repeatCount > 0) {
            mEditor.mKeyListener.onKeyDown(this, (Editable) mText, keyCode, down);
            mEditor.mKeyListener.onKeyUp(this, (Editable) mText, keyCode, up);
        }
        hideErrorIfUnchanged();
    } else if (which == KEY_DOWN_HANDLED_BY_MOVEMENT_METHOD) {
        // mMovement is not null from doKeyDown
        mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
        while (--repeatCount > 0) {
            mMovement.onKeyDown(this, (Spannable) mText, keyCode, down);
            mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
        }
    }
    return true;
}
Also used : KeyEvent(android.view.KeyEvent) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Spannable(android.text.Spannable)

Example 57 with KeyEvent

use of android.view.KeyEvent in project platform_frameworks_base by android.

the class PasswordEntryKeyboardHelper method sendDownUpKeyEvents.

public void sendDownUpKeyEvents(int keyEventCode) {
    long eventTime = SystemClock.uptimeMillis();
    ViewRootImpl viewRootImpl = mTargetView.getViewRootImpl();
    viewRootImpl.dispatchKeyFromIme(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
    viewRootImpl.dispatchKeyFromIme(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
}
Also used : ViewRootImpl(android.view.ViewRootImpl) KeyEvent(android.view.KeyEvent)

Example 58 with KeyEvent

use of android.view.KeyEvent in project weiciyuan by qii.

the class BrowserWebFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.browserwebfragment_layout, container, false);
    if (mWebView != null) {
        mWebView.destroy();
    }
    mWebView = (WebView) view.findViewById(R.id.webView);
    mProgressBar = (ProgressBar) view.findViewById(R.id.progressbar);
    mWebView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
            return false;
        }
    });
    mWebView.setWebViewClient(new InnerWebViewClient());
    mWebView.setWebChromeClient(new InnerWebChromeClient());
    mIsWebViewAvailable = true;
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    return view;
}
Also used : KeyEvent(android.view.KeyEvent) WebSettings(android.webkit.WebSettings) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView)

Example 59 with KeyEvent

use of android.view.KeyEvent in project weiciyuan by qii.

the class UserAvatarDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    String path = getArguments().getString("path");
    final Rect ori = getArguments().getParcelable("rect");
    Bitmap bitmap = BitmapFactory.decodeFile(path);
    final View content = getActivity().getLayoutInflater().inflate(R.layout.useravatardialog_layout, null);
    final ImageView avatar = ((ImageView) content.findViewById(R.id.imageview));
    avatar.setImageBitmap(bitmap);
    avatar.setClickable(true);
    content.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            animateClose(avatar, ori);
        }
    });
    Dialog dialog = new Dialog(getActivity(), R.style.UserAvatarDialog) {

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                animateClose(avatar, ori);
                return true;
            }
            return super.onKeyDown(keyCode, event);
        }
    };
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(content);
    content.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            content.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            if (ori == null) {
                return;
            }
            int[] avatarLocation = new int[2];
            avatar.getLocationOnScreen(avatarLocation);
            final int transX = ori.left - avatarLocation[0];
            final int transY = ori.top - avatarLocation[1];
            final float scaleX = (float) ori.width() / (float) avatar.getWidth();
            final float scaleY = (float) ori.height() / (float) avatar.getHeight();
            avatar.setTranslationX(transX);
            avatar.setTranslationY(transY);
            avatar.setPivotX(0);
            avatar.setPivotY(0);
            avatar.setScaleX(scaleX);
            avatar.setScaleY(scaleY);
            avatar.animate().translationX(0).translationY(0).scaleY(1).scaleX(1).alpha(1.0f).setDuration(300).withEndAction(new Runnable() {

                @Override
                public void run() {
                }
            });
        }
    });
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    return dialog;
}
Also used : KeyEvent(android.view.KeyEvent) Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) Dialog(android.app.Dialog) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) ViewTreeObserver(android.view.ViewTreeObserver)

Example 60 with KeyEvent

use of android.view.KeyEvent in project roboguice by roboguice.

the class AstroboyMasterConsole method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    // @Inject, @InjectResource, and @InjectExtra injection happens during super.onCreate()
    super.onCreate(savedInstanceState);
    sayText.setOnEditorActionListener(new OnEditorActionListener() {

        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            // Have the remoteControl tell Astroboy to say something
            remoteControl.say(textView.getText().toString());
            textView.setText(null);
            return true;
        }
    });
    brushTeethButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {
            remoteControl.brushTeeth();
        }
    });
    selfDestructButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {
            // Self destruct the remoteControl
            vibrator.vibrate(2000);
            remoteControl.selfDestruct();
        }
    });
    // Fighting the forces of evil deserves its own activity
    fightEvilButton.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {
            startActivity(new Intent(AstroboyMasterConsole.this, FightForcesOfEvilActivity.class));
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView) Intent(android.content.Intent) ContentView(roboguice.inject.ContentView) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) View(android.view.View)

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