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     &NBSP;  //2. Initialize gesture recognizer        //Basic Default Base simple        Mgesturedetector = New Gesturedetector (this,               new Gesturedetector.simpleongesturelistener () {                    /* *                    * 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) {                      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 ()) > $) {            &nbsp             shownext (null);                  &N Bsp       return true;                     }  &nbs P                  //return is false            &N Bsp         return super.onfling (E1, E2, Velocityx, Velocityy);            & nbsp      }                });        // Initialize layout in subclasses         Initview ();      }      //set Current view layout      public abstract void Initview ();      //Show next interface      public Abstra CT void Shownext (view view);      //shows the previous interface      public abstract void showpre (view view );      //3.activity is touched by the method called when it needs to be inside the gesture recognizer to take effect       @Override      public bo Olean Ontouchevent (motionevent event) {       //Let gesture recognizer take effect         Mgesturedetecto R.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); &nbsP       startactivity (intent);        finish ();        //Set switch Animation effect that 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: It is very obvious that this mobile_safeactivity1 inherits from the previous base class Basesetupactivity , so when the finger on the screen to slide, will trigger Shownext () and Showpre () two methods, and in the switch through the overriderpendingtransition () to create a screen slide switch effect, here can be set according to the actual needs, And this method will be called by itself after the finish () method is executed. 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.