pangjiao
1.1.34
1.在项目build.gradle
添加
2.在app build.gradle
添加
dependencies {
...
compile 'ljk.android.pangjiao:pangjiao:1.0.2'
annotationProcessor 'ljk.android.pangjiao:pangjiao:1.0.2'
}
android {
compileOptions {
...
sourceCompatibility JavaVersion . VERSION_1_8
targetCompatibility JavaVersion . VERSION_1_8
}
}
###初始化###
public class TESTApplication extends Application {
@ Override
public void onCreate () {
super . onCreate ();
PangJiao . init ( this );
}
}
1.活动中使用
public class MainActivity extends PJAppCompatActivity {
@ InitView ( R . id . tv_title )
public TextView tvTitle ;
@ Override
public int initView () {
return R . layout . activity_main ;
}
@ Override
public void initData () {
tvTitle . setText ( "hello " );
}
@ OnClick ( R . id . tv_title )
public void tvClick () {
Toast . makeText ( this , tvTitle . getText (). toString (), Toast . LENGTH_SHORT ). show ();
}
@ OnClick ( R . id . tv_title )
public View . OnClickListener tvTitle_Click = v -> {
Toast . makeText ( this , tvTitle . getText (). toString (), Toast . LENGTH_SHORT ). show ();
};
@ OnClick ({ R . id . tv_title , R . id . tv_text })
public void onClick ( View view ){
}
或者
PangJiao . inject ( activity );
2.在片段中使用
public class TESTFragment extends PJFragment {
@ InitView ( R . id . btn_test )
public Button btnTest ;
@ Override
protected int initView () {
return R . layout . fragment_test ;
}
@ Override
protected void initData () {
btnTest . setText ( "hello pangjiao" );
}
}
或者
PangJiao . inject ( view , object );
在pangjiao framwork hava @Service @Presenter注解中,了解spring的人都知道@Autowire.at pangjiao hava @Autowire和@AutowireProxy 。 pangjiao建议您将代码分包到以下目录。
ui(包)-activity(包)-fragment(包)
服务-接口(.java)-imp(包)
应用程序-接口(.java)-imp(包)
开始使用胖甲
应用层接口 新接口
public interface IMemberPresent extends IPresenter {
void login ( String name , String pwd );
}
添加小鬼
@ Presenter
public class MemberPresent implements IMemberPresent {
@ Autowire
public IAppService appService ;
@ TargetView
public IMemberView memberView ;
@ Override
public void onDestroy () {
this . memberView = null ;
}
@ Override
public void login ( String name , String pwd ) {
appService . login ( name , pwd );
}
}
用户界面层
public class MainActivity extends PJAppCompatActivity implements IMemberView {
@ AutowireProxy
public IMemberPresent memberPresent ;
@ Override
public int initView () {
return R . layout . activity_main ;
}
@ Override
public void initData () {
memberPresent . login ( "Tom" , "123456" );
}
@ Override
public void refresh ( Object o ) {
}
}
默认POST违规,请求体JSON格式。底层是HttpURLConnection实现。
@ Net ( api = "http://www.baidu.com" , connectTimeOut = 10000 )
public class RequestActive extends NetModel < ResponseActive > {
private String ActiveCode ;
public String getActiveCode () {
return ActiveCode ;
}
public void setActiveCode ( String ActiveCode ) {
this . ActiveCode = ActiveCode ;
}
}
public class ResponseActive extends ResponseBase {
private boolean issuccess ;
private String msg ;
private String data ;
public boolean isIssuccess () {
return issuccess ;
}
public void setIssuccess ( boolean issuccess ) {
this . issuccess = issuccess ;
}
public String getMsg () {
return msg ;
}
public void setMsg ( String msg ) {
this . msg = msg ;
}
public String getData () {
return data ;
}
public void setData ( String data ) {
this . data = data ;
}
}
怎么用? xx.excute();//线程同步
public ResponseActive active ( String activeCode ) {
RequestActive requestActive = new RequestActive ();
requestActive . setActiveCode ( activeCode );
return requestActive . execute ();
}
Entity和@Entity,Public属性,无封装类
@ Entity
public class User {
@ Id
public int id ;
@ Column
public String userName ;
@ Column
public String telPhone ;
}
添加、更新、查询、删除
@ Override
public void queryUser ( String userName ) {
//添加新的:user,更新同样的方法,确保Id不为0
User user = new User ();
user . userName = userName ;
user . telPhone = "1322222222" ;
SQEntity . save ( user );
//查询:构建实体
User userQuery = new User ();
userQuery . userName = userName ;
List < User > search = SQEntity . search ( User . class , userQuery );
//查询:where
List < User > search1 = SQEntity . search ( User . class , "userName = '" + userName + " '" );
//删除:构建实体
User userDelete = new User ();
userDelete . telPhone = "1322222222" ;
SQEntity . deleteWhere ( User . class , userDelete );
//删除:Id
SQEntity . delete ( User . class , 2 );
}
当前支持的不仅仅是关联查询。
将对象注入 UI 层时使用 @Autowireproxy。
@autowireproxy 将注入一个将在线程中执行的代理对象。
所以UI层应用层的网络请求不需要自己启动线程。
需要由 pangjiao 容器管理的对象需要添加到@service或@Presenter 。由 * @service或 ** @presenter ** 修饰的类,没有其他成员变量。