好的插件能加快项目的开发速度,尤其是一些针对重复性的代码的插件,所以在这里向大家推荐2款不错的插件,如果以后发现新的好的插件,还会继续推荐,同时欢迎大家推荐
GsonFormat

GsonFormat是一款将json直接转换成JavaBean的工具,这样就避免了我们经常需要照着接口文档来写实体类bean,而且还要看着不要写错,同时也节省了大量的时间

第一步:安装

首先点击设置按钮,通过File菜单进入设置也行点击设置

然后选择Plugins 选择Plugins

在上面输入框输入GsonFormat或者gson都行 输入GsonFormat或者gson都行 然后点击browse

选择GsonFormat 选择GsonFormat点击右边的install,然后就等待安装完成并且重启

第二步:使用

首先我们创建一个类(类名不限),然后在类中按下alt+insert 或者右键点击generate也行,选择选择gsonformat,选择GsonFormat或者完全可以直接按快捷键alt+s会弹出一个框弹框,吧得到的json复制进输入框点击okok

在点击ok就能直接生成bean了

我是用以下json生成的bean

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. {  
  2.     "people":[  
  3.         {"firstName":"Brett","lastName":"McLaughlin","email":"aaaa"},  
  4.         {"firstName":"Jason","lastName":"Hunter","email":"bbbb"},  
  5.         {"firstName":"Elliotte","lastName":"Harold","email":"cccc"}  
  6.     ]  
  7. }  


JavaBean

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package wang.raye.viewdemo.bean;  
  2.   
  3. import java.util.List;  
  4.   
  5. /** 
  6.  * Created by Raye on 2016/3/28. 
  7.  */  
  8. public class JsonBean {  
  9.   
  10.     /** 
  11.      * firstName : Brett 
  12.      * lastName : McLaughlin 
  13.      * email : aaaa 
  14.      */  
  15.   
  16.     private List<PeopleBean> people;  
  17.   
  18.     public List<PeopleBean> getPeople() {  
  19.         return people;  
  20.     }  
  21.   
  22.     public void setPeople(List<PeopleBean> people) {  
  23.         this.people = people;  
  24.     }  
  25.   
  26.     public static class PeopleBean {  
  27.         private String firstName;  
  28.         private String lastName;  
  29.         private String email;  
  30.   
  31.         public String getFirstName() {  
  32.             return firstName;  
  33.         }  
  34.   
  35.         public void setFirstName(String firstName) {  
  36.             this.firstName = firstName;  
  37.         }  
  38.   
  39.         public String getLastName() {  
  40.             return lastName;  
  41.         }  
  42.   
  43.         public void setLastName(String lastName) {  
  44.             this.lastName = lastName;  
  45.         }  
  46.   
  47.         public String getEmail() {  
  48.             return email;  
  49.         }  
  50.   
  51.         public void setEmail(String email) {  
  52.             this.email = email;  
  53.         }  
  54.     }  
  55. }  


怎么样很方便吧,下面介绍PreIOC

PreIOC

PreIOC是针对PreIOC框架的一个插件,PreIOC是一个预编译的注解框架,关于详细的PreIOC相关资料可以去主页查看git.oschina或者github

第一步:安装

同前面gsonFormat的安装差不多,不过搜索的时候需要搜索PreIOC,目前关于PreIOC的结果只有一个,所以可以选择安装

第二步:使用

使用PreIOC有个前提,就是项目必须要使用了PreIOC 1.0.6版本,之前的老版本不予支持,同时为了避免Bug建议切换到新版,使用PreIOC 1.0.6

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. compile 'wang.raye.preioc:preioccore:1.0.6'  


同时好一个布局,在需要在Activity、Fragment、Adapter需要使用的控件设置好id,然后在布局名称处右键点击generate 选择Generate PreIOC Injections

选择Generate PreIOC Injections

弹框在弹出的框中判断是否有需要修改的属性名称和不要引用的id(去掉勾选),如果需要点击事件则勾选OnClick列的checkbox,如果是创建ViewHolder则选择ViewHolder(用于Adapter),点击confirm就能自动生成了,建议打开自动导入,这样Android Studio就会自动导入类中的引用和去掉没用的引用 自动导入

以下是我的xml布局和生成的类文件

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  4.     xmlns:tools="http://schemas.android.com/tools"  
  5.     android:layout_width="300dp"  
  6.     android:layout_height="match_parent"  
  7.     android:orientation="vertical">  
  8.   
  9.     <android.support.v7.widget.CardView  
  10.         android:layout_width="match_parent"  
  11.         android:layout_height="wrap_content"  
  12.         app:cardBackgroundColor="#ffffff"  
  13.         android:layout_marginTop="10dp"  
  14.         app:cardElevation="3dp"  
  15.         app:cardMaxElevation="3dp">  
  16.   
  17.         <RelativeLayout  
  18.             android:layout_width="300dp"  
  19.             android:layout_height="match_parent">  
  20.   
  21.             <ImageView  
  22.                 android:id="@+id/iv_head"  
  23.                 android:layout_width="match_parent"  
  24.                 android:layout_height="300dp"  
  25.                 android:layout_margin="5dp"  
  26.                 android:src="@mipmap/b"  
  27.                 android:scaleType="fitXY"/>  
  28.   
  29.             <RelativeLayout  
  30.                 android:layout_width="match_parent"  
  31.                 android:layout_height="wrap_content"  
  32.                 android:layout_alignBottom="@id/iv_head"  
  33.                 android:background="#30000000"  
  34.                 android:padding="5dp"  
  35.                 android:layout_marginLeft="5dp"  
  36.                 android:layout_marginRight="5dp">  
  37.   
  38.                 <TextView  
  39.                     android:id="@+id/tv_age"  
  40.                     android:layout_width="wrap_content"  
  41.                     android:layout_height="wrap_content"  
  42.                     android:textColor="#ffffff"/>  
  43.   
  44.                 <TextView  
  45.                     android:id="@+id/tv_height"  
  46.                     android:layout_width="wrap_content"  
  47.                     android:layout_height="wrap_content"  
  48.                     android:layout_marginLeft="15dp"  
  49.                     android:layout_toRightOf="@id/tv_age"  
  50.                     android:textColor="#ffffff"/>  
  51.                 <TextView  
  52.                     android:layout_width="wrap_content"  
  53.                     android:layout_height="wrap_content"  
  54.                     android:textColor="#ffffff"  
  55.                     android:id="@+id/tv_info"  
  56.                     android:layout_alignParentRight="true"/>  
  57.             </RelativeLayout>  
  58.   
  59.             <TextView  
  60.                 android:layout_width="match_parent"  
  61.                 android:layout_height="wrap_content"  
  62.                 android:maxLines="2"  
  63.                 android:layout_below="@id/iv_head"  
  64.                 android:layout_margin="10dp"  
  65.                 android:textSize="22sp"  
  66.                 android:minLines="2"  
  67.                 android:ellipsize="end"  
  68.                 android:id="@+id/tv_desc"  
  69.                 android:textColor="#666666"/>  
  70.         </RelativeLayout>  
  71.   
  72.     </android.support.v7.widget.CardView>  
  73.   
  74.     <TextView  
  75.         android:layout_width="90dp"  
  76.         android:layout_height="36dp"  
  77.         android:layout_gravity="top|center_horizontal"  
  78.         android:background="@drawable/test_bg"  
  79.         android:gravity="center"  
  80.         android:textSize="22sp"  
  81.         android:elevation="6dp"  
  82.         android:id="@+id/tv_name"  
  83.         android:textColor="#333333"/>  
  84. </FrameLayout>    


类文件

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package wang.raye.viewdemo.ui;  
  2.   
  3. import android.os.Bundle;    
  4. import android.support.v4.app.FragmentActivity;    
  5. import android.widget.ImageView;    
  6. import android.widget.TextView;  
  7.   
  8. import wang.raye.preioc.PreIOC;    
  9. import wang.raye.preioc.annotation.BindById;    
  10. import wang.raye.preioc.annotation.OnClick;    
  11. import wang.raye.viewdemo.R;  
  12.   
  13. public class Test extends FragmentActivity {  
  14.   
  15.     @BindById(R.id.iv_head)  
  16.     ImageView ivHead;  
  17.     @BindById(R.id.tv_age)  
  18.     TextView tvAge;  
  19.     @BindById(R.id.tv_height)  
  20.     TextView tvHeight;  
  21.     @BindById(R.id.tv_info)  
  22.     TextView tvInfo;  
  23.     @BindById(R.id.tv_desc)  
  24.     TextView tvDesc;  
  25.     @BindById(R.id.tv_name)  
  26.     TextView tvName;  
  27.   
  28.     @Override  
  29.     protected void onCreate(Bundle savedInstanceState) {  
  30.         super.onCreate(savedInstanceState);  
  31.         setContentView(R.layout.activity_test);  
  32.         PreIOC.binder(this);  
  33.     }  
  34.   
  35.   
  36.     @OnClick(R.id.iv_head)  
  37.     public void onClick() {  
  38.     }  
  39. }  
posted on 2016-03-30 15:40  0代码狂人0  阅读(528)  评论(0编辑  收藏  举报