Modify the launcher source code for Quick Start

Source: Internet
Author: User
Tags gety xdiff home screen

Recently, I am writing a speed dial-up app. The app is very simple. It mainly needs to highlight a fast feature and start quickly. It is best to start it from home screen, of course, the first response was to create a new shortcut on the desktop, but I decided to use another special method, that is, when the user starts the application on the home screen, the left and right touch screens switch between desktops. Let's talk about how to implement it:

1. Compile and run the launcher Source Code. For details, refer to the relevant online introduction. I was going to attach the modified source code. However, the file is too large. If you need it, contact me. We recommend that you compile it by yourself based on the network information.

2. Modify the launcher source code. Modify the onintercepttouchevent method of the workspace class to rank the Women's brand.

Workspace is equivalent to a desktop. The onintercepttouchevent method is executed before the touch-screen event arrives at the ontouchevent.

If you want to start your application by using Touch Screen events in the blank area of the desktop, you can use this method, but you may not accept your custom launcher.

Public Boolean onintercepttouchevent (motionevent eV ){

/****************** Omit the relevantCode***********/

Final float x = eV. getx ();
Final float y = eV. Gety ();
Log. D ("workspace", "Enter onintercepttouchevent ");
Switch (Action ){
Case motionevent. action_move:
/*
* Misbeingdragged = false, otherwise the shortcut wowould have caught it.
* Check
* Whether the user has moved far enough from his original down touch.
*/

/*
* Locally do absolute value. mlastmotionx is set to the Y value
* Of the Down event.
*/
Final int xdiff = (INT) math. Abs (X-mlastmotionx );
Final int ydiff = (INT) math. Abs (Y-mlastmotiony );

Final int touchslop = mtouchslop;
Boolean xmoved = xdiff> touchslop;
Boolean ymoved = ydiff> touchslop;

If (xmoved | ymoved ){

If (xmoved ){
// Scroll if the user moved far enough along the X axis
Mtouchstate = touch_state_scrolling;
Enablechildrencache ();
}
/********************************** Added code *** *************************************/
If (ymoved) {// vertical movement
Log. D ("workspace", "Start your application here Program ! ");

Intent intent = new intent ();
// Set the application package name and Class Name
Intent. setclassname ("com. Tek. QD", "com. Tek. QD. quickdialer ");
// Start the application
Mcontext. startactivity (intent );

Mtouchstate = touch_state_scrolling;
Enablechildrencache ();
}
**** ************************************/
// Either way, cancel any pending longpress
If (mallowlongpress ){
Mallowlongpress = false;
// Try canceling the long press. It cocould also have been scheduled
// By a distant descendant, so use the mallowlongpress flag
// Block
// Everything
Final view currentscreen = getchildat (mcurrentscreen );
Currentscreen. cancellongpress ();
}
}
Break;

Case motionevent. action_down:
// Remember location of down touch
Mlastmotionx = X;
Mlastmotiony = y;
Mallowlongpress = true;

/*
* If being flinged and user touches the screen, initiate drag;
* Otherwise don't. mscroller. isfinished shoshould be false when
* Being flinged.
*/

Mtouchstate = mscroller. isfinished ()?
Touch_state_rest: touch_state_scrolling;
Break;

Case motionevent. action_cancel:
Case motionevent. action_up:

If (mtouchstate! = Touch_state_scrolling ){
Final celllayout currentscreen = (celllayout) getchildat (
Mcurrentscreen );
If (! Currentscreen. lastdownonoccupiedcell ()){
Getlocationonscreen (mtempcell );
// Send a tap to the wallpaper if the last down was on
// Empty space
Mwallpapermanager. sendwallpapercommand (getwindowtoken (),
"Android. wallpaper. Tap ",
Mtempcell [0] + (INT) eV. getx (),
Mtempcell [1] + (INT) eV. Gety (), 0, null );
}
}

// Release the drag
Clearchildrencache ();
Mtouchstate = touch_state_rest;
Mallowlongpress = false;
Break;
}

/*
* The only time we want to intercept motion events is if we are in
* Drag mode.
*/
Return mtouchstate! = Touch_state_rest;
} Wind fashion Java-JavaScript mogujie.com women's clothing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.