Open Source Library fab-transformation Simple usage parsing

Source: Internet
Author: User

Reprint please indicate the source of Wang 亟亟 's Daniel Road

Similar to the operation of the iphone hover button, but is fixed, of course, after their own changes can be moved, this is just to reach the party a well-being, plus some of their own understanding, so that we can take the use, read to understand, nonsense not much to say, first on!!

The author's implementation is roughly the same, and I'm going to do a little experiment on some of it after I've read the sample I'm using, and that will be done.
Directory structure

Gradle Build the project, (git all this, you know) a smplemodule a lib, for the hand party, we are more concerned about the specific operation of the Code, the implementation of the method has time to see it.

Paste before the name of the Gradle content, because the author used a similar to Java web development with a lot of tags to solve the trouble Findviewbyid and a series of onclicklistener operations, hey Oh is full of provincial code, I paste it. (also a third-party library, have seen before, but there is no time to study carefully)

Apply plugin:' Com.android.application 'Android {compilesdkversion compile_sdk_version as intBuildtoolsversion build_tools_version defaultconfig {minsdkversion min_sdk_version as intTargetsdkversion target_sdk_version as intVersioncode Version_code as intVersionname version_name Renderscripttargetapi Renderscript_target_api as intRenderscriptsupportmodeenabledtrue} buildtypes {release {minifyenabledfalseProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}}}dependencies {Compile project (': Fab-transformation ') Compile"Com.android.support:appcompat-v7:${support_package_version}"Compile"Com.android.support:cardview-v7:${support_package_version}"Compile' de.hdodenhof:circleimageview:1.3.0 'Compile' com.android.support:design:22.2.1 'Compile' com.jakewharton:butterknife:6.1.0 '}

is compile ' com.jakewharton:butterknife:6.1.0 ' everyone can search the git on this library, quite practical, very recommended

The Models,adapters two package in the catalogue does not explain the fact that the original author's layered understanding is fine for purely populating the data and building the page.

Apputil,baseactivity is only auxiliary class, also do not post, the specific content of the usual network disk see! (recently considering if you want to store git or csdn.) )

Main activity

 Public  class mainactivity extends baseactivity {    Private Static FinalString Spec_url ="http://www.google.com/design/spec/components/buttons-floating-action-button.html#";@InjectView(R.id.list_view) ListView ListView;PrivateMenuarrayadapter adapter;Private Static void Showwebpage(String URL, context context) {if(Textutils.isempty (URL))return;        Uri uri = uri.parse (URL); Intent Intent =NewIntent (Intent.action_view, URI);    Context.startactivity (Intent); }@Override    intGetlayoutresid () {returnR.layout.activity_main; }@Override    protected void Initview() {adapter =NewMenuarrayadapter ( This);        Listview.setadapter (adapter);    Adapter.addall (Createmenulist ()); }/ * Populate home ListView Data source * /    PrivateList<samplemenu>createmenulist() {list<samplemenu> menulist =NewArraylist<> (2); Menulist.add (NewSamplemenu (GetString (R.string.description_sheet), r.drawable.img_thumb_sheet)); Menulist.add (NewSamplemenu (GetString (R.string.description_toolbar), R.drawable.img_thumb_toolbar)); Menulist.add (NewSamplemenu (GetString (R.string.description_player), R.drawable.img_thumb_player));returnMenulist; }@OnItemClick(R.id.list_view)voidOnitemclicklistview (intPosition) {Samplemenu Samplemenu = Adapter.getitem (position);Switch(position) { Case 0: Transformtosheetactivity.start ( This, Samplemenu.gettitle ()); Break; Case 1: Transformtotoolbaractivity.start ( This, Samplemenu.gettitle ()); Break; Case 2: Transformtoplayeractivity.start ( This, Samplemenu.gettitle ()); Break; }    }@Override     Public Boolean Oncreateoptionsmenu(Menu menu) {Getmenuinflater (). Inflate (R.menu.menu_main, menu);return true; }@Override     Public Boolean onoptionsitemselected(MenuItem Item) {intid = item.getitemid ();Switch(ID) { CaseR.id.action_link:showwebpage (Spec_url, This); Break; }return Super. onoptionsitemselected (item); }}

Analysis:
The 1.spec_url constant is just a url,menu function in the menu to access the network, and simply opens a connection, which can be ignored.
2.createMenuList () populates the data source for item, and the title of each page thereafter is also derived from this
3. Here is useful to @onitemclick, @InjectView such a label to replace some of the original complex code, it is highly recommended for this operation, readability is also easy.
4. The author has Intent some jumps to the start () method of each small class, and then does some jump operation, which is much leaner than 3 new Intent () operations appear in mainactivity.

Transformtoplayeractivity

 Public  class transformtoplayeractivity extends baseactivity {    @InjectView(R.id.fab) Floatingactionbutton fab;@InjectView(R.id.container_player) View Containerplayer; Public Static void Start(context context, String title) {Intent Intent =NewIntent (context, transformtoplayeractivity.class);        Intent.putextra (Extra_title, TITLE);    Context.startactivity (Intent); }@Override    intGetlayoutresid () {returnR.layout.activity_transform_to_player; }@Override    protected void Initview() {//}@OnClick(R.id.fab)voidOnclickfab () {if(fab.getvisibility () = = view.visible)        {Fabtransformation.with (FAB). Transformto (Containerplayer); }    }@OnClick(R.id.container_player)voidOnclicksheet () {if(Fab.getvisibility ()! = view.visible)        {Fabtransformation.with (FAB). Transformfrom (Containerplayer); }    }@Override     Public void onbackpressed() {if(Fab.getvisibility ()! = view.visible) {Fabtransformation.with (FAB). Transformfrom (Containerplayer);return; }Super. onbackpressed (); }}

Analysis:
1.getLayoutResId (), Initview (), etc. are the methods that can be used after inheriting baseactivity, used to do some initialization operations, this side of the Getlayoutresid () Equivalent to our usual setcontentview (), he only carried out a round of encapsulation, such as Setcontentview (Getlayoutresid ());
2. All operations that activate fab or hide fab require only fabtransformation.with (FAB). Transformto (Containerplayer); Encapsulation of the more thorough the first parameter is the penalty effect of the view, the second parameter is to render the view, if you want to continue operation in view only need to @OnClick (r.id. Specific controls), and even do not need to @injectview (r.id. Specific controls) , very simple and practical.

Transformtosheetactivity

 Public  class transformtosheetactivity extends baseactivity {    @InjectView(R.id.fab) Floatingactionbutton fab;@InjectView(r.id.sheet) View sheet;@InjectView(r.id.overlay) View overlay; Public Static void Start(context context, String title) {Intent Intent =NewIntent (context, transformtosheetactivity.class);        Intent.putextra (Extra_title, TITLE);    Context.startactivity (Intent); }@Override    intGetlayoutresid () {returnR.layout.activity_transform_to_sheet; }@Override    protected void Initview() {//}@OnClick(R.id.fab)voidOnclickfab () {if(fab.getvisibility () = = view.visible)        {Fabtransformation.with (FAB). Setoverlay (overlay). Transformto (sheet); }    }@OnClick(r.id.row_1)voidOnClickRow1 () {Apputil.showtoast ("Row 1 clicked!", This); }@OnClick(r.id.row_2)voidOnClickRow2 () {Apputil.showtoast ("Row 2 clicked!", This); }@OnClick(R.id.row_3)voidOnClickRow3 () {Apputil.showtoast ("Row 3 clicked!", This); }@OnClick(R.id.row_4)voidOnClickRow4 () {Apputil.showtoast ("Row 4 clicked!", This); }@OnClick(r.id.row_5)voidOnClickRow5 () {Apputil.showtoast ("Row 5 clicked!", This); }@OnClick(R.id.overlay)voidOnclickoverlay () {if(Fab.getvisibility ()! = view.visible)        {Fabtransformation.with (FAB). Setoverlay (overlay). Transformfrom (sheet); }    }@Override     Public void onbackpressed() {if(Fab.getvisibility ()! = view.visible) {Fabtransformation.with (FAB). Setoverlay (overlay). Transformfrom (sheet);return; }Super. onbackpressed (); }}

Analysis:
The difference between this class and the previous class is that it's good to add the specific things we just said, and we just need to @OnClick (r.id.row_1)
void OnClickRow1 () {Specific business} just fine, the point is simple.

Transformtotoolbaractivity

 Public  class transformtotoolbaractivity extends baseactivity {    @InjectView(R.id.fab) Floatingactionbutton fab;@InjectView(R.id.toolbar_footer) View Toolbarfooter;@InjectView(R.id.scroll_view) ScrollView ScrollView;Private Booleanistransforming; Public Static void Start(context context, String title) {Intent Intent =NewIntent (context, transformtotoolbaractivity.class);        Intent.putextra (Extra_title, TITLE);    Context.startactivity (Intent); }@Override    intGetlayoutresid () {returnR.layout.activity_transform_to_toolbar; }@Override    protected void Initview() {scrollview.getviewtreeobserver (). Addonscrollchangedlistener (NewViewtreeobserver.onscrollchangedlistener () {@Override                     Public void onscrollchanged() {if(Fab.getvisibility ()! = view.visible &&!istransforming) {Fabtransformation.with (FAB). Setlistener (NewFabtransformation.ontransformlistener () {@Override                                         Public void Onstarttransform() {istransforming =true; }@Override                                         Public void Onendtransform() {istransforming =false;                        }}). Transformfrom (Toolbarfooter);    }                    }                }); }@OnClick(R.id.fab)voidOnclickfab () {if(fab.getvisibility () = = view.visible)        {Fabtransformation.with (FAB). Transformto (Toolbarfooter); }    }@OnClick(R.id.imagebutton)voidOnclickimagebutton () {Toast.maketext (transformtotoolbaractivity. This,"Xu X has a hole in his brain.", Toast.length_short). Show (); }@Override     Public void onbackpressed() {if(Fab.getvisibility ()! = view.visible) {Fabtransformation.with (FAB). Transformfrom (Toolbarfooter);return; }Super. onbackpressed (); }}

Analysis:
1. Because this section of the scene in a ScrollView, so when the user has to move up and down the time will also have an impact on our toolbarfooter this menu, so added the corresponding monitoring event to deal with the business.
2. Try to add the onclick event to the first image of this toolbarfooter to see if there is any toast, the effect is yes, then our mission is done.

Wrote a day, a little tired, hehe.
Source Address: Http://yunpan.cn/cdmBGVw4PfFry access password 135e
Have a question or cooperation welcome QQ 452270579 Contact, thank you

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Open Source Library fab-transformation Simple usage parsing

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.