Go Base classes in Android-extracting public methods

Source: Internet
Author: User

In Android, in general, an application will have dozens of pages, and an application will generally use a specific theme, where the style of the page is consistent, and the page animation effect, page switching effect should also maintain the same style, then need a base class, To complete the basic settings of the page, which is called the base class.

  Interface Unified management reasons   when the interface reaches a certain number of applications, such as dozens of interface, easy to project management to improve the interface processing speed to avoid problems caused by multiple activity interface Unified management of the base when the interface in the application reaches a certain order of magnitude, In order to make it easier for users to get started, the product design will unify the interface display style.   Case-driven:  public abstract class Basesetupactivity extends Activity {     //The abstract classes, as the base class for the four Setup wizards, Define common methods      private sharedpreferences msharedpreferences;     private static String TAG = " Basesetupactivity ";      //declaring a gesture recognizer      private Gesturedetector Mgesturedetector ;       @Override      protected void OnCreate (Bundle savedinstancestate) {       //TODO auto-generated method stub        super.oncreate (savedinstancestate); &nb Sp       msharedpreferences = getsharedpreferences ("config", mode_private);        //Initialize gesture recognizer        //2. Initialize gesture recognizer        //Basic Default Base simple        Mgesturedetector = new Gesturedetector (this,               new Gesturedetector.simpleongesturelis Tener () {                    /**                    * screen matching method. E1 Finger first touch screen E2 finger off screen instantly velocityx horizontal direction of movement speed                     * &LT;SP An style= "text-decoration:underline;" &GT;PX&LT;/SPAN&GT;/S velocityy vertical movement speed                     */  &N Bsp                 @Override                 &N Bsp  public boolean onfling (motionevent E1, motionevent e2,                          float Velocityx, float velocityy) {                &N Bsp     if (Math.Abs (Velocityx) < 100){                          LOG.I (TAG, "too slow to move, illegal to act") &nbs P                         return true;      &NBSP ;              }                   &NB Sp   If ((E2.getrawx ()-e1.getrawx ()) > $) {                          showpre (null);                        &NB Sp Return true;                     }        &NBS P             if ((E1.getrawx ()-e2.getrawx ()) > $) {                          shownext (null);              &N Bsp &nbSp         return true;                     }&NBS P                    //actually return false          &N Bsp           return super.onfling (E1, E2, Velocityx, Velocityy);          & nbsp        }                });       &NB Sp Initialize layout in subclasses         Initview ();      }      //Set the current view layout & nbsp    public abstract void Initview ();      //Show next interface      public abstract void Shownext (view view);      //shows the previous interface      public abstract void Showpre (view view); &nbs p;     //3.activity is touched when the method called, need to be inside this to let the gesture recognizer take effect       @Override      public BooLean Ontouchevent (motionevent event) {       //Let gesture recognizer take effect         Mgesturedetector . Ontouchevent (event);        return super.ontouchevent (event);     }  } Analysis: The main implementation of the case is in the same topic page of the transition effect is unified, initialized the gesture recognizer, and let the gesture recognizer take effect. Next, take a look at the settings for a page that inherits from this base class   public class Mobile_safeactivity1 extends basesetupactivity {      private static String <span style= "text-decoration:underline;" >TAG</span> = "Mobile_safeactivity1";       @Override      public void Initview () {        Setcontentview (r.layout.mobile_safeactivity1);     }        @Override      public void Shownext (view view) {        Intent Inten t = new Intent (this, mobile_safeactivity2.class);        startactivity (Intent);      & nbsp Finish ();        /settingsToggles the animation effect, which will be invoked when the program executes the startactivity and the Finish () method         Overridependingtransition ( R.anim.tran_next_in, R.anim.tran_next_out);     }       @Override      public void Showpre (view view) {      }  } Analysis: Very clearly this mobile_ SafeActivity1 inherits from the previous base class basesetupactivity, so the Shownext () and Showpre () Two methods are triggered when the finger slides on the screen. And when switching through the overriderpendingtransition () to create a screen slide switch effect, here can be set according to the actual needs, and this method will be executed after the finish () method to invoke itself. Nothing is written in Showpre () because there is no previous page.   Excerpt from http://www.2cto.com/kf/201403/288116.html

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.