List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:fr.cobaltians.cobalt.fragments.CobaltFragment.java
protected void setWebViewSettings(Object javascriptInterface) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD) mWebView.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS); mWebView.setScrollListener(this); mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); // Enables JS WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); // Enables and setups JS local storage webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); //@deprecated since API 19. But calling this method have simply no effect for API 19+ webSettings.setDatabasePath(mContext.getFilesDir().getParentFile().getPath() + "/databases/"); // Enables cross-domain calls for Ajax allowAjax();//from w w w . ja va 2 s.co m // Fix some focus issues on old devices like HTC Wildfire // keyboard was not properly showed on input touch. mWebView.requestFocus(View.FOCUS_DOWN); mWebView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!view.hasFocus()) { view.requestFocus(); } break; default: break; } return false; } }); // Add JavaScript interface so JavaScript can call native functions. mWebView.addJavascriptInterface(javascriptInterface, "Android"); mWebView.addJavascriptInterface(new LocalStorageJavaScriptInterface(mContext), "LocalStorage"); WebViewClient webViewClient = new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { executeWaitingCalls(); } }; mWebView.setWebViewClient(webViewClient); }
From source file:android.widget.PinnedHeaderListView.java
@Override public boolean onInterceptTouchEvent(final MotionEvent ev) { mHeaderTouched = false;/*w ww . ja v a 2 s . c om*/ if (super.onInterceptTouchEvent(ev)) return true; if (mScrollState == SCROLL_STATE_IDLE) { final int y = (int) ev.getY(); final int x = (int) ev.getX(); for (int i = mSize; --i >= 0;) { final PinnedHeader header = mHeaders[i]; // For RTL layouts, this also takes into account that the scrollbar is on the left // side. final int padding = getPaddingLeft(); if (header.visible && header.y <= y && header.y + header.height > y && x >= padding && padding + header.view.getWidth() >= x) { mHeaderTouched = true; if (mScrollToSectionOnHeaderTouch && ev.getAction() == MotionEvent.ACTION_DOWN) return smoothScrollToPartition(i); else return true; } } } return false; }
From source file:android.support.v7.widget.SwitchCompat.java
/** * Called from onTouchEvent to end a drag operation. * * @param ev Event that triggered the end of drag mode - ACTION_UP or ACTION_CANCEL *//* www. j a va 2 s .c om*/ private void stopDrag(MotionEvent ev) { mTouchMode = TOUCH_MODE_IDLE; // Commit the change if the event is up and not canceled and the switch // has not been disabled during the drag. final boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP && isEnabled(); final boolean oldState = isChecked(); final boolean newState; if (commitChange) { mVelocityTracker.computeCurrentVelocity(1000); final float xvel = mVelocityTracker.getXVelocity(); if (Math.abs(xvel) > mMinFlingVelocity) { newState = ViewUtils.isLayoutRtl(this) ? (xvel < 0) : (xvel > 0); } else { newState = getTargetCheckedState(); } } else { newState = oldState; } if (newState != oldState) { playSoundEffect(SoundEffectConstants.CLICK); setChecked(newState); } cancelSuperTouch(ev); }
From source file:com.aretha.slidemenu.SlideMenu.java
@Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); final float x = event.getX(); final float y = event.getY(); final int currentState = mCurrentState; final boolean isTapContent = mIsTapContent; mVelocityTracker.addMovement(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mPressedX = mLastMotionX = x;// w w w.java2s . com mIsTapContent = isTapContent(x, y); if (mIsTapContent) { mScroller.abortAnimation(); } mVelocityTracker = VelocityTracker.obtain(); break; case MotionEvent.ACTION_MOVE: if (Math.abs(x - mPressedX) >= mTouchSlop && isTapContent && currentState != STATE_DRAG) { setCurrentState(STATE_DRAG); } if (STATE_DRAG != currentState) { mLastMotionX = x; return false; } drag(mLastMotionX, x); mLastMotionX = x; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: if (STATE_DRAG == currentState) { mVelocityTracker.computeCurrentVelocity(1000); endDrag(x, mVelocityTracker.getXVelocity()); } else if (isTapContent) { performContentClick(); } mVelocityTracker.recycle(); mIsTapContent = false; break; } return true; }
From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java
@Override public boolean onTouchEvent(@NonNull MotionEvent ev) { if (!mCanSlide) { return super.onTouchEvent(ev); }// w w w .j a v a 2s. c o m mDragHelper.processTouchEvent(ev); final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_UP: { if (isDimmed(mSlideableView)) { final float x = ev.getX(); final float y = ev.getY(); final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mDragHelper.getTouchSlop(); if (dx * dx + dy * dy < slop * slop && mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y)) { // Taps close a dimmed open pane. closePane(); break; } } break; } } return true; }
From source file:com.insthub.O2OMobile.Activity.C1_PublishOrderActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.c1_publish_order); mFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); File file = new File(newFileName()); if (file.exists()) { file.delete();/*from w w w . j a v a2 s . co m*/ } Intent intent = getIntent(); mServiceType = (SERVICE_TYPE) intent.getSerializableExtra(O2OMobileAppConst.SERVICE_TYPE); mDefaultReceiverId = intent.getIntExtra(DEFAULT_RECEIVER_ID, 0); service_list = intent.getStringExtra("service_list"); mBack = (ImageView) findViewById(R.id.top_view_back); mTitle = (TextView) findViewById(R.id.top_view_title); mBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub finish(); } }); mArrowImage = (ImageView) findViewById(R.id.top_view_arrow_image); mClose = (ImageView) findViewById(R.id.top_view_right_close); mTitleView = (LinearLayout) findViewById(R.id.top_view_title_view); mServiceTypeView = (FrameLayout) findViewById(R.id.c1_publish_order_service_type_view); mServiceTypeListview = (ListView) findViewById(R.id.c1_publish_order_service_type_list); mPrice = (EditText) findViewById(R.id.c1_publish_order_price); mTime = (TextView) findViewById(R.id.c1_publish_order_time); mLocation = (EditText) findViewById(R.id.c1_publish_order_location); mText = (EditText) findViewById(R.id.c1_publish_order_text); mVoice = (Button) findViewById(R.id.c1_publish_order_voice); mVoicePlay = (Button) findViewById(R.id.c1_publish_order_voicePlay); mVoiceReset = (ImageView) findViewById(R.id.c1_publish_order_voiceReset); mPublish = (Button) findViewById(R.id.c1_publish_order_publish); mVoiceView = (FrameLayout) findViewById(R.id.c1_publish_order_voice_view); mVoiceAnim = (ImageView) findViewById(R.id.c1_publish_order_voice_anim); mVoiceAnim.setImageResource(R.anim.voice_animation); mAnimationDrawable = (AnimationDrawable) mVoiceAnim.getDrawable(); mAnimationDrawable.setOneShot(false); mTitleView.setEnabled(false); mServiceTypeView.setOnClickListener(null); mServiceTypeListview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub if (mDefaultReceiverId == 0) { mTitle.setText(mHomeModel.publicServiceTypeList.get(position).title); mServiceTypeId = mHomeModel.publicServiceTypeList.get(position).id; mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this, mHomeModel.publicServiceTypeList, position); mServiceTypeListview.setAdapter(mC1PublishOrderAdapter); mClose.setVisibility(View.GONE); mArrowImage.setImageResource(R.drawable.b3_arrow_down); AnimationUtil.backAnimationFromBottom(mServiceTypeListview); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); mServiceTypeView.setVisibility(View.GONE); } }; mHandler.sendEmptyMessageDelayed(0, 200); } else { mTitle.setText(mServiceTypeList.get(position).title); mServiceTypeId = mServiceTypeList.get(position).id; mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this, mServiceTypeList, position); mServiceTypeListview.setAdapter(mC1PublishOrderAdapter); mClose.setVisibility(View.GONE); mArrowImage.setImageResource(R.drawable.b3_arrow_down); AnimationUtil.backAnimationFromBottom(mServiceTypeListview); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); mServiceTypeView.setVisibility(View.GONE); } }; mHandler.sendEmptyMessageDelayed(0, 200); } } }); mTitleView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mServiceTypeView.getVisibility() == View.GONE) { mServiceTypeView.setVisibility(View.VISIBLE); mClose.setVisibility(View.VISIBLE); mArrowImage.setImageResource(R.drawable.b4_arrow_up); AnimationUtil.showAnimationFromTop(mServiceTypeListview); closeKeyBoard(); } else { mClose.setVisibility(View.GONE); mArrowImage.setImageResource(R.drawable.b3_arrow_down); AnimationUtil.backAnimationFromBottom(mServiceTypeListview); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); mServiceTypeView.setVisibility(View.GONE); } }; mHandler.sendEmptyMessageDelayed(0, 200); } } }); mClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mClose.setVisibility(View.GONE); mArrowImage.setImageResource(R.drawable.b3_arrow_down); AnimationUtil.backAnimationFromBottom(mServiceTypeListview); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); mServiceTypeView.setVisibility(View.GONE); } }; mHandler.sendEmptyMessageDelayed(0, 200); } }); mPrice.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if (s.toString().length() > 0) { if (s.toString().substring(0, 1).equals(".")) { s = s.toString().substring(1, s.length()); mPrice.setText(s); } } if (s.toString().length() > 1) { if (s.toString().substring(0, 1).equals("0")) { if (!s.toString().substring(1, 2).equals(".")) { s = s.toString().substring(1, s.length()); mPrice.setText(s); CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } boolean flag = false; for (int i = 0; i < s.toString().length() - 1; i++) { String getstr = s.toString().substring(i, i + 1); if (getstr.equals(".")) { flag = true; break; } } if (flag) { int i = s.toString().indexOf("."); if (s.toString().length() - 3 > i) { String getstr = s.toString().substring(0, i + 3); mPrice.setText(getstr); CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); initData(); mHomeModel = new HomeModel(this); mHomeModel.addResponseListener(this); if (mDefaultReceiverId == 0) { mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0); mHomeData = mShared.getString("home_data", ""); if ("".equals(mHomeData)) { mHomeModel.getServiceTypeList(); } else { try { servicetypelistResponse response = new servicetypelistResponse(); response.fromJson(new JSONObject(mHomeData)); mHomeModel.publicServiceTypeList = response.services; setServiceTypeAdater(); } catch (JSONException e) { e.printStackTrace(); } } } else { if (service_list != null && !"".equals(service_list)) { try { JSONObject userJson = new JSONObject(service_list); myservicelistResponse response = new myservicelistResponse(); response.fromJson(userJson); for (int i = 0; i < response.services.size(); i++) { SERVICE_TYPE service = new SERVICE_TYPE(); service = response.services.get(i).service_type; mServiceTypeList.add(service); } if (mServiceTypeList.size() > 0) { mTitleView.setEnabled(true); mArrowImage.setVisibility(View.VISIBLE); if (mServiceType != null) { for (int i = 0; i < mServiceTypeList.size(); i++) { if (mServiceType.id == mServiceTypeList.get(i).id) { mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList, i); mServiceTypeListview.setAdapter(mC1PublishOrderAdapter); mTitle.setText(mServiceTypeList.get(i).title); mServiceTypeId = mServiceTypeList.get(i).id; break; } } } else { mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList); mServiceTypeListview.setAdapter(mC1PublishOrderAdapter); mTitle.setText(getString(R.string.select_service)); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0); mHomeData = mShared.getString("home_data", ""); if ("".equals(mHomeData)) { mHomeModel.getServiceTypeList(); } else { try { servicetypelistResponse response = new servicetypelistResponse(); response.fromJson(new JSONObject(mHomeData)); mHomeModel.publicServiceTypeList = response.services; setServiceTypeAdater(); } catch (JSONException e) { e.printStackTrace(); } } } } mLocationInfoModel = new LocationInfoModel(this); mLocationInfoModel.addResponseListener(this); mLocationInfoModel.get(); mOrderPublishModel = new OrderPublishModel(this); mOrderPublishModel.addResponseListener(this); //?? CharSequence charSequencePirce = mPrice.getText(); if (charSequencePirce instanceof Spannable) { Spannable spanText = (Spannable) charSequencePirce; Selection.setSelection(spanText, charSequencePirce.length()); } CharSequence charSequenceLocation = mLocation.getText(); if (charSequenceLocation instanceof Spannable) { Spannable spanText = (Spannable) charSequenceLocation; Selection.setSelection(spanText, charSequenceLocation.length()); } mVoice.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if (event.getAction() == MotionEvent.ACTION_DOWN) { closeKeyBoard(); mVoice.setKeepScreenOn(true); mMaxTime = MAX_TIME; mVoiceView.setVisibility(View.VISIBLE); mAnimationDrawable.start(); startRecording(); } else if (event.getAction() == MotionEvent.ACTION_UP) { mVoice.setKeepScreenOn(false); mVoiceView.setVisibility(View.GONE); mAnimationDrawable.stop(); if (mMaxTime > 28) { mVoice.setEnabled(false); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); stopRecording(); mVoice.setEnabled(true); } }; mHandler.sendEmptyMessageDelayed(0, 500); } else { stopRecording(); } } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { mVoice.setKeepScreenOn(false); mVoiceView.setVisibility(View.GONE); mAnimationDrawable.stop(); if (mMaxTime > 28) { mVoice.setEnabled(false); Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); stopRecording(); mVoice.setEnabled(true); } }; mHandler.sendEmptyMessageDelayed(0, 500); } else { stopRecording(); } } else if (event.getAction() == MotionEvent.ACTION_MOVE) { mVoice.getParent().requestDisallowInterceptTouchEvent(true); } return false; } }); mVoicePlay.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mPlayer == null) { File file = new File(mFileName); if (file.exists()) { mPlayer = new MediaPlayer(); mVoicePlay.setBackgroundResource(R.anim.record_animation); mAnimationDrawable2 = (AnimationDrawable) mVoicePlay.getBackground(); mAnimationDrawable2.setOneShot(false); mAnimationDrawable2.start(); try { mPlayer.setDataSource(mFileName); mPlayer.prepare(); mPlayer.start(); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.reset(); mPlayer = null; mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn); mAnimationDrawable2.stop(); } }); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Toast.makeText(C1_PublishOrderActivity.this, getString(R.string.file_does_not_exist), Toast.LENGTH_SHORT).show(); } } else { mPlayer.release(); mPlayer = null; mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn); mAnimationDrawable2.stop(); } } }); mVoiceReset.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mPlayer != null) { mPlayer.release(); mPlayer = null; mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn); mAnimationDrawable2.stop(); } File file = new File(mFileName); if (file.exists()) { file.delete(); } mVoice.setVisibility(View.VISIBLE); mVoicePlay.setVisibility(View.GONE); mVoiceReset.setVisibility(View.GONE); } }); mPublish.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub File file = new File(newFileName()); int duration = 0; if (file.exists()) { MediaPlayer mp = MediaPlayer.create(C1_PublishOrderActivity.this, Uri.parse(mFileName)); if (null != mp) { duration = mp.getDuration();//? ms mp.release(); } if (duration % 1000 > 500) { duration = duration / 1000 + 1; } else { duration = duration / 1000; } } else { file = null; } int num = 0; try { // ?? Date date = new Date(); Date date1 = mFormat.parse(mFormat.format(date)); Date date2 = mFormat.parse(mTime.getText().toString()); num = date2.compareTo(date1); if (num < 0) { long diff = date1.getTime() - date2.getTime(); long mins = diff / (1000 * 60); if (mins < 3) { num = 1; } } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (mServiceTypeId == 0) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.select_service)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (mPrice.getText().toString().equals("")) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.price_range)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (mPrice.getText().toString().equals("0.")) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.right_price)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (mTime.getText().toString().equals("")) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.appoint_time)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (num < 0) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.wrong_appoint_time_hint)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else if (mLocation.getText().toString().equals("")) { ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.appoint_location_hint)); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } else { mOrderPublishModel.publish(mPrice.getText().toString(), mTime.getText().toString(), mLocation.getText().toString(), mText.getText().toString(), file, mServiceTypeId, mDefaultReceiverId, duration); } } }); }
From source file:com.undatech.opaque.RemoteCanvasActivity.java
/** * Initializes the on-screen keys for meta keys and arrow keys. *///ww w. j ava 2 s.c om private void initializeOnScreenKeys() { layoutKeys = (RelativeLayout) findViewById(R.id.layoutKeys); keyStow = (ImageButton) findViewById(R.id.keyStow); setKeyStowDrawableAndVisibility(); keyStow.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (layoutKeys.getVisibility() == View.VISIBLE) { extraKeysHidden = true; setExtraKeysVisibility(View.GONE, false); } else { extraKeysHidden = false; setExtraKeysVisibility(View.VISIBLE, true); } layoutKeys.offsetTopAndBottom(prevBottomOffset); setKeyStowDrawableAndVisibility(); } }); // Define action of tab key and meta keys. keyTab = (ImageButton) findViewById(R.id.keyTab); keyTab.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_TAB; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyTab.setImageResource(R.drawable.tabon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyTab.setImageResource(R.drawable.taboff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyEsc = (ImageButton) findViewById(R.id.keyEsc); keyEsc.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = 111; /* KEYCODE_ESCAPE */ if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyEsc.setImageResource(R.drawable.escon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyEsc.setImageResource(R.drawable.escoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyCtrl = (ImageButton) findViewById(R.id.keyCtrl); keyCtrl.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = false; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); } }); keyCtrl.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = true; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); return true; } }); keySuper = (ImageButton) findViewById(R.id.keySuper); keySuper.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = false; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); } }); keySuper.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = true; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); return true; } }); keyAlt = (ImageButton) findViewById(R.id.keyAlt); keyAlt.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = false; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); } }); keyAlt.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = true; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); return true; } }); keyShift = (ImageButton) findViewById(R.id.keyShift); keyShift.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = false; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); } }); keyShift.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = true; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); return true; } }); // Define action of arrow keys. keyUp = (ImageButton) findViewById(R.id.keyUpArrow); keyUp.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_UP; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyUp.setImageResource(R.drawable.upon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyUp.setImageResource(R.drawable.upoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyDown = (ImageButton) findViewById(R.id.keyDownArrow); keyDown.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_DOWN; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyDown.setImageResource(R.drawable.downon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyDown.setImageResource(R.drawable.downoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyLeft = (ImageButton) findViewById(R.id.keyLeftArrow); keyLeft.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_LEFT; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyLeft.setImageResource(R.drawable.lefton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyLeft.setImageResource(R.drawable.leftoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyRight = (ImageButton) findViewById(R.id.keyRightArrow); keyRight.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_RIGHT; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyRight.setImageResource(R.drawable.righton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyRight.setImageResource(R.drawable.rightoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mRoots = DocumentsApplication.getRootsCache(this); virtualIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); virtualIntent.addCategory(Intent.CATEGORY_OPENABLE); virtualIntent.setType("*/*"); virtualIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); setResult(Activity.RESULT_CANCELED); setContentView(R.layout.activity);/*from w w w .java 2s. co m*/ final Resources res = getResources(); mShowAsDialog = res.getBoolean(R.bool.show_as_dialog); if (mShowAsDialog) { // backgroundDimAmount from theme isn't applied; do it manually final WindowManager.LayoutParams a = getWindow().getAttributes(); a.dimAmount = 0.6f; getWindow().setAttributes(a); getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND); // Inset ourselves to look like a dialog final Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x); final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y); final int insetX = (size.x - width) / 2; final int insetY = (size.y - height) / 2; final Drawable before = getWindow().getDecorView().getBackground(); final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY); getWindow().getDecorView().setBackground(after); // Dismiss when touch down in the dimmed inset area getWindow().getDecorView().setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { final float x = event.getX(); final float y = event.getY(); if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) { finish(); return true; } } return false; } }); } else { // Non-dialog means we have a drawer mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerListener); mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START); mRootsContainer = findViewById(R.id.container_roots); } mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory); if (icicle != null) { mState = icicle.getParcelable(EXTRA_STATE); } else { if (DEBUG) { Log.i(TAG, "mState"); } buildDefaultState(); } // Hide roots when we're managing a specific root if (mState.action == ACTION_MANAGE) { if (mShowAsDialog) { findViewById(R.id.dialog_roots).setVisibility(View.GONE); } else { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } } if (mState.action == ACTION_CREATE) { final String mimeType = virtualIntent.getType(); final String title = virtualIntent.getStringExtra(Intent.EXTRA_TITLE); SaveFragment.show(getFragmentManager(), mimeType, title); } if (mState.action == ACTION_GET_CONTENT) { final Intent moreApps = new Intent(virtualIntent); moreApps.setComponent(null); moreApps.setPackage(null); RootsFragment.show(getFragmentManager(), moreApps); } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) { RootsFragment.show(getFragmentManager(), null); } if (!mState.restored) { if (mState.action == ACTION_MANAGE) { final Uri rootUri = virtualIntent.getData(); new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor()); } else { new RestoreStackTask().execute(); } } else { onCurrentDirectoryChanged(ANIM_NONE); } }
From source file:android.support.v7ox.widget.SwitchCompat.java
/** * Called from onTouchEvent to end a drag operation. * * @param ev Event that triggered the end of drag mode - ACTION_UP or ACTION_CANCEL *//*from ww w . j a va 2s . c o m*/ private void stopDrag(MotionEvent ev) { mTouchMode = TOUCH_MODE_IDLE; // Commit the change if the event is up and not canceled and the switch // has not been disabled during the drag. final boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP && isEnabled(); final boolean oldState = isChecked(); final boolean newState; if (commitChange) { mVelocityTracker.computeCurrentVelocity(1000); final float xvel = mVelocityTracker.getXVelocity(); if (Math.abs(xvel) > mMinFlingVelocity) { newState = ViewUtils.isLayoutRtl(this) ? (xvel < 0) : (xvel > 0); } else { newState = getTargetCheckedState(); } } else { newState = oldState; } if (newState != oldState) { playSoundEffect(SoundEffectConstants.CLICK); } // Always call setChecked so that the thumb is moved back to the correct edge setChecked(newState); cancelSuperTouch(ev); }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanSlide || !mIsSlidingEnabled) { return super.onTouchEvent(ev); }//w w w . j a v a2s . c o m mDragHelper.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_UP: { final float x = ev.getX(); final float y = ev.getY(); final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mDragHelper.getTouchSlop(); View dragView = mDragView != null ? mDragView : mSlideableView; if (dx * dx + dy * dy < slop * slop && isDragViewUnder((int) x, (int) y)) { dragView.playSoundEffect(SoundEffectConstants.CLICK); if (!isExpanded() && !isAnchored()) { expandPane(mAnchorPoint); } else { collapsePane(); } break; } break; } } return wantTouchEvents; }