Common knowledge of Android Application Development
1. Recently opened applications are not displayed in the list of recent tasks.
Android: excludeFromRecents = "true"
If this parameter is set to true, it is excluded from the latest task list and not displayed in the latest task list.
2. Determine whether a String str is NULL or empty.
TextUtils. isEmpty (str)
3. android: imeOptions = "actionSearch | flagNoFullscreen" Usage
When you set the EditText attribute to android: imeOptions = "actionSearch" when placing EditText in the ActionBar as the search box, you may encounter a problem, the EditText width will fill out the areas on the screen except the soft keyboard, which is inconsistent with the requirement. After changing to android: imeOptions = "actionSearch | flagNoFullscreen", it will be OK.
4. How to change the brightness of an image
1. Use image. setColorFilter (Color. GRAY, PorterDuff. Mode. MULTIPLY) to darken the image, and then use image. clearColorFilter (); clear the filter to restore the original brightness;
2. Use
Int brightness =-80;
ColorMatrix matrix = new ColorMatrix ();
Matrix. set (new float [] {1, 0, 0, 0, brightness, 0, 1, 0, 0,
Brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 });
V. setColorFilter (new ColorMatrixColorFilter (matrix ));
However, this method will make the color abnormal and the image has a black edge;
5. Use Handler to determine existing time interval events
In Android, GestureDetector. java uses the following code to perform a gesture click and double-click judgment:
public boolean onTouchEvent(MotionEvent ev) {…… case MotionEvent.ACTION_DOWN: if (mDoubleTapListener != null) { boolean hadTapMessage = mHandler.hasMessages(TAP); if (hadTapMessage) mHandler.removeMessages(TAP); if ((mCurrentDownEvent != null) && (mPreviousUpEvent != null) && hadTapMessage && isConsideredDoubleTap(mCurrentDownEvent, mPreviousUpEvent, ev)) { // This is a second tap mIsDoubleTapping = true; // Give a callback with the first tap of the double-tap handled |= mDoubleTapListener.onDoubleTap(mCurrentDownEvent); // Give a callback with down event of the double-tap handled |= mDoubleTapListener.onDoubleTapEvent(ev); } else { // This is a first tap mHandler.sendEmptyMessageDelayed(TAP, DOUBLE_TAP_TIMEOUT); } }……} private boolean isConsideredDoubleTap(MotionEvent firstDown, MotionEvent firstUp, MotionEvent secondDown) { if (!mAlwaysInBiggerTapRegion) { return false; } final long deltaTime = secondDown.getEventTime() - firstUp.getEventTime(); if (deltaTime > DOUBLE_TAP_TIMEOUT || deltaTime < DOUBLE_TAP_MIN_TIME) { return false; } int deltaX = (int) firstDown.getX() - (int) secondDown.getX(); int deltaY = (int) firstDown.getY() - (int) secondDown.getY(); return (deltaX * deltaX + deltaY * deltaY < mDoubleTapSlopSquare); } private class GestureHandler extends Handler { GestureHandler() { super(); } GestureHandler(Handler handler) { super(handler.getLooper()); } @Override public void handleMessage(Message msg) { switch (msg.what) { case SHOW_PRESS: mListener.onShowPress(mCurrentDownEvent); break; case LONG_PRESS: dispatchLongPress(); break; case TAP: // If the user's finger is still down, do not count it as a tap if (mDoubleTapListener != null) { if (!mStillDown) { mDoubleTapListener.onSingleTapConfirmed(mCurrentDownEvent); } else { mDeferConfirmSingleTap = true; } } break; default: throw new RuntimeException("Unknown message " + msg); //never } }
For details, refer to the source code. Here mHandler is a wonderful use. sendEmptyMessageDelayed: If the mHandler sends the TAP message within the DOUBLE_TAP_TIMEOUT time, it means to click the time. If the TAP message is not sent within the time, double-click the event.