編輯:關於Android編程
private static final int MAX_INTERVAL_FOR_CLICK = 250; private static final int MAX_DISTANCE_FOR_CLICK = 100; private static final int MAX_DOUBLE_CLICK_INTERVAL = 500; int mDownX = 0; int mDownY = 0; int mTempX = 0; int mTempY = 0; boolean mIsWaitUpEvent = false; boolean mIsWaitDoubleClick = false; Runnable mTimerForUpEvent = new Runnable() { public void run() { if (mIsWaitUpEvent) { Log.d(LOG_TAG, "The mTimerForUpEvent has executed, so set the mIsWaitUpEvent as false"); mIsWaitUpEvent = false; } else { Log.d(LOG_TAG, "The mTimerForUpEvent has executed, mIsWaitUpEvent is false,so do nothing"); } } }; @Override public boolean onTouchEvent(MotionEvent event) { if (!mIsWaitUpEvent && event.getAction() != MotionEvent.ACTION_DOWN) { return super.onTouchEvent(event); } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mDownX = (int) event.getX(); mDownY = (int) event.getY(); mIsWaitUpEvent = true; postDelayed(mTimerForUpEvent, MAX_INTERVAL_FOR_CLICK); break; case MotionEvent.ACTION_MOVE: mTempX = (int) event.getX(); mTempY = (int) event.getY(); if (Math.abs(mTempX - mDownX) > MAX_DISTANCE_FOR_CLICK || Math.abs(mTempY - mDownY) > MAX_DISTANCE_FOR_CLICK) { mIsWaitUpEvent = false; removeCallbacks(mTimerForUpEvent); Log.d(LOG_TAG, "The move distance too far:cancel the click"); } break; case MotionEvent.ACTION_UP: mTempX = (int) event.getX(); mTempY = (int) event.getY(); if (Math.abs(mTempX - mDownX) > MAX_DISTANCE_FOR_CLICK || Math.abs(mTempY - mDownY) > MAX_DISTANCE_FOR_CLICK) { mIsWaitUpEvent = false; removeCallbacks(mTimerForUpEvent); Log.d(LOG_TAG, "The touch down and up distance too far:cancel the click"); break; } else { mIsWaitUpEvent = false; removeCallbacks(mTimerForUpEvent); onSingleClick(); return super.onTouchEvent(event); } case MotionEvent.ACTION_CANCEL: mIsWaitUpEvent = false; removeCallbacks(mTimerForUpEvent); Log.d(LOG_TAG, "The touch cancel state:cancel the click"); break; default: Log.d(LOG_TAG, "irrelevant MotionEvent state:" + event.getAction()); } return super.onTouchEvent(event); } Runnable mTimerForSecondClick = new Runnable() { @Override public void run() { if (mIsWaitDoubleClick) { Log.d(LOG_TAG, "The mTimerForSecondClick has executed,so as a singleClick"); mIsWaitDoubleClick = false; // at here can do something for singleClick!! } else { Log.d(LOG_TAG, "The mTimerForSecondClick has executed, the doubleclick has executed ,so do thing"); } } }; public void onSingleClick() { if (mIsWaitDoubleClick) { onDoubleClick(); mIsWaitDoubleClick = false; removeCallbacks(mTimerForSecondClick); } else { mIsWaitDoubleClick = true; postDelayed(mTimerForSecondClick, MAX_DOUBLE_CLICK_INTERVAL); } } public void onDoubleClick() { Log.d(LOG_TAG,"we can do sth for double click here"); }
需求分析:很多時候,我們需要在視圖中顯示不同樣式的文字,但是為了減少viewgroup層級,不想新增很多個TextView控件來實現不同樣式的文字。那麼有沒有一種方式能夠
1.首先先去下載需要的jar包2.將jar包復制到Project下的app–>libs目錄下(沒有libs目錄就新建一個)如下圖所示位置:3.右鍵該ja
本文主要介紹Android應用程序簽名的相關理論知識以及如何發布Android應用程序。 1.簽名的概念 為大家所熟知的日常生活中的簽名,它是代表某個人的特殊標記,用
出於性能優化考慮,android的UI操作並不是線程安全的,這意味著意味著如果有多個線程並發操作UI組件,可能導致線程安全問題,未解決此問題, 從開發的角度來說, Han