Android afinal Framework Learning (ii) finalactivity an IOC framework

Source: Internet
Author: User

Frame Address: https://github.com/yangfuhai/afinal

The corresponding source code:

net.tsz.afinal.annotation.view.*

Finalactivity

Finalactivity is a basic class, with annotations implemented, Dependency injection (view resource ID, Common listener), using set method to inject

UI binding and event binding can be done in a fully annotated manner without the need for Findviewbyid and set event Listener

This process: Initinjectedview>findviewbyid, Setlistener (activity, Activity.field, Eventlocalmethod, EventType) >

1. Get the View object according to the ID, set to the field in the activity corresponding

2. Switch (eventtype) {

Case event:

View.set Event Listener (new EventListener (activity, Eventlocalmethod));

EventListener implements many event listener>

In the overridden method of the corresponding event, the reflection call Eventlocalmethod

The parameters of these eventlocalmethod need to be consistent with the parameters of the corresponding system event method

...

}

What types of annotations are available:

@Target (Elementtype.field) @Retention (retentionpolicy.runtime) public @interface viewinject {public int id ();p ublic String click () Default "";p ublic string Longclick () default "";p ublic string ItemClick () default "";p ublic string Itemlong Click () Default "";p ublic Select Select () Default @Select (selected= "");}

Invoke Annotations:

Package Com.stone.afinal;import Net.tsz.afinal.finalactivity;import Net.tsz.afinal.annotation.view.select;import Net.tsz.afinal.annotation.view.viewinject;import Android.os.bundle;import Android.view.view;import Android.widget.adapterview;import Android.widget.imageview;import Android.widget.listview;public Class Mainactivity extends Finalactivity {@ViewInject (id = r.id.imageview, click = "Myclick", Longclick = "Mylongclick") ImageView ImageView; @ViewInject (id = r.id.listview, click = "Myclick", Itemlongclick = "Myitemlongclick", ItemClick = " Myitemclick ", Longclick =" Mylongclick ", select = @Select (selected=" myitemselected ", noselected=" mynoselected ")) ListView listview; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main);//inherited Finalactivity,setcontentview initialized in} public void Myclick (View v) { System.out.println ("--myclick--");} public void Mylongclick (View v) {System.out.println ("--mylongclick--");} public void MyitemlongclicK (adapterview<?> arg0, View arg1, int arg2,long arg3) {System.out.println ("--myitemlongclick--");} public void Myitemclick (adapterview<?> arg0, View arg1, int arg2, long arg3) {System.out.println ("--myitemclick--" );} public void myitemselected (adapterview<?> arg0, View arg1, int arg2,long arg3) {System.out.println ("-- myitemselected--");} public void mynoselected (adapterview<?> arg0) {System.out.println ("--mynoselected--");}}

Used in other intrusive frameworks (e.g. Actionbarshelock)

     protected void onCreate(Bundle savedinstancestate) {       Super.onCreate(savedinstancestate);        Setcontentview(View);        finalactivity.Initinjectedview( This);     }

Use in Fragment

      Public View Oncreateview(Layoutinflater Inflater, ViewGroup Container,          Bundle savedinstancestate) {       View Viewroot = Inflater.Inflate(R.Layout.Map_frame, Container, false);       finalactivity.Initinjectedview( This,Viewroot);    }

Related Article

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.