1.en el proyecto build.gradle
agregar
2.en la aplicación build.gradle
agregar
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
}
}
###inicializar ###
public class TESTApplication extends Application {
@ Override
public void onCreate () {
super . onCreate ();
PangJiao . init ( this );
}
}
1.uso en actividad
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 ){
}
O
PangJiao . inject ( activity );
2.uso en fragmento
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" );
}
}
O
PangJiao . inject ( view , object );
en pangjiao framwork hava @Service @Presenter anotación, las personas que saben sobre la primavera conocen @Autowire.at pangjiao hava @Autowire y @AutowireProxy . pangjiao recomienda que subcontrate su código al siguiente directorio.
ui (paquete) -actividad (paquete) -fragmento (paquete)
servicio -interfaz(.java) -imp (paquete)
aplicación -interfaz(.java) -imp (paquete)
Empezar a utilizar pangjia
interfaz de nivel de aplicación nueva interfaz
public interface IMemberPresent extends IPresenter {
void login ( String name , String pwd );
}
agregar diablillo
@ 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 );
}
}
nivel de interfaz de usuario
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 ) {
}
}
Infracción POST predeterminada, formato JSON del cuerpo de la solicitud. La capa subyacente es la implementación de 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 ;
}
}
¿Cómo uso? xx.excute();//Sincronización de subprocesos
public ResponseActive active ( String activeCode ) {
RequestActive requestActive = new RequestActive ();
requestActive . setActiveCode ( activeCode );
return requestActive . execute ();
}
Entidad y @Entity, atributo público, sin clase de encapsulación
@ Entity
public class User {
@ Id
public int id ;
@ Column
public String userName ;
@ Column
public String telPhone ;
}
agregar, actualizar datos, consultar, eliminar
@ 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 );
}
Actualmente no sólo se admiten consultas asociativas.
Utilice @Autowireproxy al inyectar objetos en la capa de la interfaz de usuario.
@autowireproxy inyectará un objeto proxy que se ejecutará en el hilo .
Por lo tanto, las solicitudes de red en la capa de aplicación de la capa de interfaz de usuario no necesitan iniciar los subprocesos por sí mismas.
El objeto que debe ser administrado por el contenedor pangjiao debe agregarse a @service o @Presenter . La clase decorada por * @service o ** *@presenter**, no tiene otras variables miembro.