androidInject


Source link: https://github.com/wangjiegulu/androidInject

androidInject

###???????android??
(Use annotations inject to simplify the development of android)

###??:

???????Library AndroidBucket????????????util??

??fragment??????android-support-v4.jar???????????

?????????????????????????? gson.jar???

???????????? httpmime.jar???

###Gadle( Check newest version) compile 'com.github.wangjiegulu:AndroidInject:x.x.x' ###Maven( Check newest version) com.github.wangjiegulu AndroidInject x.x.x

###??1?Android??
@AIFullScreen @AINoTitle @AILayout(R.layout.main) public class MainActivity extends AIActivity{



  @AIView(id = R.id.insertBtn, clickMethod = "onClickCallback", longClickMethod = "onLongClickCallback")

private Button insertBtn;

  @AIView(clickMethod = "onClickCallback", longClickMethod = "onLongClickCallback")

private Button queryBtn;

 //
 @AIView(id = R.id.btn3)
  //
 private Button btn3;

 //
 @AIView(id = R.id.listView, itemClickMethod = "onItemClickCallback", itemLongClickMethod = "onItemLongClickCallbackForListView")

@AIView(R.id.listView)

private ListView listView;

  @AIBean

private Person person;

  @AISystemService

private AlarmManager alarmManager;

@AISystemService

private LocationManager locationManager;

@AISystemService

private LayoutInflater inflater;

@AIScreenSize

private Point sSize;

@AINetWorker

private PersonWorker personWorker;

  @Override

public void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);

 List<Map<String, String>> list = new ArrayList<Map<String, String>>();

 Map<String, String> map;

 for(int i = 0; i < 10; i++){

  map = new HashMap<String, String>();

  map.put("title", "item_" + i);

  list.add(map);

 
}

SimpleAdapter adapter = new SimpleAdapter(context, list, R.layout.list_item, new String[]{
"title"
}
, new int[]{
R.id.list_item_title_tv
}
);

 listView.setAdapter(adapter);

person.setName("wangjie");

 person.setAge(23);

 System.out.println(person.toString());

System.out.println("alarmManager: " + alarmManager + ", locationManager: " + locationManager + ", inflater: " + inflater);

System.out.println("screen size --> width: " + sSize.x + ", height: " + sSize.y);

 ThreadPool.go(new Runtask<Object, Object>() {

  @Override

  public Object runInBackground() {

try {

  //

 RetMessage<Person> retMsg = personWorker.getPersonsForGet("a1", "b1", "c1");

 RetMessage<Person> retMsg = personWorker.getPersonsForGet2(new Params().add("aa", "a1").add("bb", "b1").add("cc", "c1"));

 //

  RetMessage<Person> retMsg = personWorker.getPersonsForPost2(new Params().add("aa", "a1").add("bb", "b1").add("cc", "c1"));

 System.out.println("getPersonsForGet2: " + retMsg.getList().toString());

}
 catch (Exception ex) {

 ex.printStackTrace();

}

return null;

  
}

 
}
);

  ThreadPool.go(new Runtask<Object, Object>() {

  @Override

  public Object runInBackground() {

try {

 String jsonStr = personWorker.getPersonsForGetToString(new Params().add("aa", "a1").add("bb", "b1").add("cc", "c1"));

 System.out.println("getPersonsForGetToString: " + jsonStr);

}
 catch (Exception e) {

 e.printStackTrace();

}

return null;

  
}

 
}
);

  ThreadPool.go(new Runtask<Object, Object>() {

  @Override

  public Object runInBackground() {

try{

 // ??????

 /*

 List<File> files = new ArrayList<File>();

 files.add(new File("/storage/emulated/0/DCIM/Camera/20140130_132710.jpg"));

 files.add(new File("/storage/emulated/0/DCIM/Camera/20140130_132559.jpg"));

 files.add(new File("/storage/emulated/0/DCIM/Camera/20140130_132533.jpg"));

 files.add(new File("/storage/emulated/0/DCIM/Camera/20140130_132508.jpg"));

 RetMessage<UploadFile> retMsg = personWorker.uploadFile(files);

 System.out.println(retMsg.getList().toString());

 */

 // ??????

 RetMessage<UploadFile> retMsg = personWorker.uploadFile2(new File("/storage/emulated/0/DCIM/Camera/20140130_132710.jpg"));

 System.out.println(retMsg.getList().toString());

  
}
catch(Exception ex){

 ex.printStackTrace();

}

return null;

  
}

 
}
);

 userExecutor = new DbExecutor<User>(context);

}

  DbExecutor<User> userExecutor = null;

User dbUser = null;

List<User> users = null;

Random rd = new Random();

@AIClick({
R.id.deletebtn, R.id.updateBtn
}
)

public void onClickCallback(View view) throws Exception{

 if(view instanceof Button){

  Toast.makeText(context, "onClickCallback: " + ((Button)view).getText(), Toast.LENGTH_SHORT).show();

 
}

 switch(view.getId()){

  case R.id.insertBtn: // ??user???user?

dbUser = new User("wangjie" + rd.nextInt(10000), String.valueOf(rd.nextInt(10000) + 10000), System.currentTimeMillis(), rd.nextInt(80) + 120, rd.nextInt(80) + 120, "aaaa");

userExecutor.executeSave(dbUser);

break;

 case R.id.queryBtn: // ??user?

users = userExecutor.executeQuery("select * from user where uid > ?", new String[]{
"4"
}
, User.class);

System.out.println("[queryBtn]users: " + users);

break;

 case R.id.deletebtn: // ??user??????

if(null == users || users.size() <= 0){

 break;

}

userExecutor.executeDelete(users.get(0));

break;

 case R.id.updateBtn: // ??user??????

if(null == users || users.size() <= 0){

 break;

}

User user = users.get(0);

user.setUsername(user.getUsername().startsWith("wangjie") ? "jiewang" + rd.nextInt(10000) : "wangjie" + rd.nextInt(10000));

user.setPassword(user.getPassword().startsWith("123456") ? "abcdef" : "123456");

user.setCreatemillis(System.currentTimeMillis());

user.setHeight(rd.nextInt(80) + 120);

user.setWeight(rd.nextInt(80) + 120);

user.setNotCol("bbb");

userExecutor.executeUpdate(user, null, new String[]{
"createmillis"
}
);

break;

}

  
}

  public void onLongClickCallback(View view){

 if(view instanceof Button){

  Toast.makeText(context, "onLongClickCallback: " + ((Button)view).getText(), Toast.LENGTH_SHORT).show();

 
}

}

  public void onItemClickCallback(AdapterView<?> adapterView, View view, int i, long l) {

 Toast.makeText(context, "onItemClickCallback: " + ((Map<String, String>)adapterView.getAdapter().getItem(i)).get("title"), Toast.LENGTH_SHORT).show();

}

  @AIClick({
R.id.toFragmentBtn
}
)

public void onClickCallbackForBtn3(View view){

 if(view instanceof Button){

  Toast.makeText(context, "onClickForUpdateBtn: " + ((Button)view).getText(), Toast.LENGTH_SHORT).show();

 
}

if(view.getId() == R.id.toFragmentBtn){

  startActivity(new Intent(context, SecendActivity.class));

 
}

 
}

  @AILongClick({
R.id.updateBtn
}
)

public void onLongClickCallbackForBtn3(View view){

 if(view instanceof Button){

  Toast.makeText(context, "onLongClickCallbackForBtn3: " + ((Button)view).getText(), Toast.LENGTH_SHORT).show();

 
}

}

  @AIItemClick({
R.id.listView
}
)

public void onItemClickCallbackForListView(AdapterView<?> adapterView, View view, int i, long l){

 Toast.makeText(context, "onItemClickCallbackForListView: " + ((Map<String, String>)adapterView.getAdapter().getItem(i)).get("title"), Toast.LENGTH_SHORT).show();

}

  @AIItemLongClick(R.id.listView)

public boolean onItemLongClickCallbackForListView(AdapterView<?> adapterView, View view, int i, long l) {

 Toast.makeText(context, "onItemLongClickCallbackForListView: " + ((Map<String, String>)adapterView.getAdapter().getItem(i)).get("title"), Toast.LENGTH_SHORT).show();

 return true;

}

  
}
 

###??2???????
@AIMapper(" http://192.168.2.198:8080/HelloSpringMVC") public interface PersonWorker { @AIGet("/person/findPersons?aa=#{ a3 } &bb=#{ b3 } &cc=#{ c3 } ") public RetMessage getPersonsForGet(@AIParam("a3")String a2, @AIParam("b3") String b2, @AIParam("c3") String c2) throws Exception;



  @AIPost("/person/findPersons")

public RetMessage<Person> getPersonsForPost(@AIParam("aa")String a2, @AIParam("bb") String b2, @AIParam("cc") String c2) throws Exception;

  @AIGet(value = "/person/findPersons", connTimeout = 12345, soTimeout = 54321)

public RetMessage<Person> getPersonsForGet2(Params params) throws Exception;

  @AIPost(value = "/person/findPersons", connTimeout = 30000, soTimeout = 25000)

public RetMessage<Person> getPersonsForPost2(Params params) throws Exception;

  @AIUpload("/upload/uploadFiles")

public RetMessage<UploadFile> uploadFile(List<File> files) throws Exception;

  @AIUpload("/upload/uploadFiles")

public RetMessage<UploadFile> uploadFile2(File file) throws Exception;

  @AIGet(value = "/person/findPersons", connTimeout = 12345, soTimeout = 54321)

public String getPersonsForGetToString(Params params) throws Exception;

 
}
 

###??3????????
@AITable public class User implements Serializable{ @AIColumn @AIPrimaryKey(insertable = false) private int uid; @AIColumn("username") private String username; @AIColumn private String password; @AIColumn private long createmillis; @AIColumn private float height; @AIColumn private double weight;



  private String notCol;

  public User() {

}

  public User(String username, String password, long createmillis, float height, double weight, String notCol) {

 this.username = username;

 this.password = password;

 this.createmillis = createmillis;

 this.height = height;

 this.weight = weight;

 this.notCol = notCol;

}

// ... getter/setter
  
}
 

###????(Annotations):


 @AINoTitle: ???, ????Activity(????AIActivity), ??Activity???Title

@AIFullScreen: ???, ????Activity(????AIActivity), ??Activity??

@AILayout: ???

value[int]: ?????Activity??? ---- setContentView(resId);

 @AIView: ????

value[int]: ?????? ---- findViewById(resId);
(default identifier[R.id.{
field name
}
] if did not set id)

id[int]: ?value,???????????value?

clickMethod[String]: ???????????????, ??, ??????, ?????(View view)

longClickMethod[String]: ?????????????, ??, ?????, ?????(View view)

itemClickMethod[String]: ??????item???????, ??, ?????, ?????(AdapterView, View, int, long)

itemLongClickMethod[String]: ??????item???????, ??, ?????, ?????(AdapterView, View, int, long)

@AIBean: ????, ?????????????, ???????????????????

@AISystemService: ?????????????????

 @AIClick: ????

value[int[], ???????id]: ???????????????, ??????, ?????(View view)

@AIItemClick: ????

value[int[], ???????id]: ??????item?????????, ??????, ?????(AdapterView, View, int, long)

@AILongClick: ????

value[int[], ???????id]: ???????????????, ??????, ?????(View view)

@AIItemLongClick: ????

value[int[], ???????id]: ??????item?????????, ??????, ?????(AdapterView, View, int, long)

@AIScreenSize: ????

?????????????????

@AIMapper????????NetWorker????

value?value?????????????????url??

@AIGet: ????

value[String, ?????url]????GET???url

connTimeout[int, ??????]?????url???????

soTimeout[int, response??????]??????url???response???????

@AIPost: ????

value[String, ?????url]????Post???url

connTimeout[int, ??????]?????url???????

soTimeout[int, response??????]??????url???response???????

@AIParam: ??????

value[String, ???????]???@AIGet?@AIPost?????????

@AINetWorker: ????

????????

@AIUpload: ????????????????????????

value[String, ?????url]???????url????post????????@AIPost???

connTimeout[int, ??????]?????url???????

soTimeout[int, response??????]??????url???response???????

?????????????????Collection<File>??????? ????File?? ?????????

@AIColumn: ???????????????

value[String]??????????????????????????????

@AIPrimaryKey: ??????????????

insertable[boolean]???????????????????????false?????????????

@AITable: ???????????

value[String]: ?????????????????????????????????

@AIPresenter????????MVP??????????Activity???Presenter????Presenter???Viewer?Interactor?? 

###????(Commit Logs):


 2014-7-18:
  1. ??@AIPresenter?????MVP??????????Activity???Presenter????Presenter???Viewer?Interactor??

2014-4-15:
  1. ??@AIMapper?????????NetWorker?????value?????????????????url??

2014-4-13:
  1. ??Gson????bug

2014-3-27:
  1. ?????????AndroidBucket??????????Library[AndroidBucket??](https://github.com/wangjiegulu/AndroidBucket)??????????util??
  2. ??Gson DateFormat?yyyy-MM-dd HH:mm:ss:SSS

2014-3-25:
  1. ????????

2014-3-25:
  1. AIDbExecutor??????????sql

2014-3-25:
  1. ???sqlite3????orm???????@AIColumn?@AIPrimaryKey?@AITable???????????????
  2. ????

2014-3-24?
  1. build androidInject_1.3.jar

2014-3-11:
  1. netWorker???????????String???????????String

2014-2-26:
  1. ??@AIView???value?id??????redId?????AIView?????@AIView(R.id.listView)????????????value?
  2. ??AIActivity?AISupportFragment?AISupportFragmentActivity??Annotations???????log

2014-2-10:
  1. ????????@AIUpload
  2. ????

2014-2-10:
  1. @AIGet?@AIPost??connTimeout?????url?????????soTimeout????????url???response????????

2014-2-10:
  1. Worker???????

2014-2-8:
  1. ??GET?POST??????????Params????????

2014-2-8:
  1. ??@AIScreenSize??????????????????????????
  2. ????????????????????@AIGet??????????????GET???url?@AIPost??????????????POST???url?@AIParam?????????
  3. ??@AINetWorker???????????????????
  4. ????

2013-12-17:
  1. refactor source

2013-12-5:
  1. build androidInject_1.0.jar

2013-12-5:
  1. add fragment support(need android-support-v4.jar)

2013-12-4:
  1. add typeList annotations: @AINoTitle, @AIFullScreen
  2. modify field annotation ---- @AIView: default identifier[R.id.{
field name
}
] if did not set id

2013-12-2:
  1. add field annotations: @AIBean, @AISystemService

2013-12-1:
  1. add method annotations: @AIItemLongClick
  2. add annotations(itemLongClickMethod) of @AIView

2013-12-1:
  1. RENAME @InitLayout, @InitView TO @AILayout, @AIView
  2. ADD method annotations: @AIClick, @AILongClick, @AIItemClick
  3. refactor source 

License

Copyright 2013 Wang Jie  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing blacklist and limitations under the License. 

Resources

NaturalLenguageProcessor is an Android library that wraps text-processing.com API and gives you the possibility to stem, to tag and to analyze sentimentally the text you want.

Layout that contains a ViewPager and can slide vertically between 2 states (expanded and collapsed).

NodeFlow is an Android library that provides a simple way to visualize hierarchical content. Perfect for displaying items that are organized in categories / subcategories.

Android library for boilerplate destruction - "Just code what is worth coding"

  • Generates boilerplate code based on used annotations and lets you focus on what matters.
  • Generated code is fully traceable.
  • Everything is generated during compile time.
  • No reflection used!
  • Consists of modules.

Android Library for checking the current uploaded version on the Google Play.

ProperDroid is a gradle plugin and an Android library that simplifies the way that config different variant on your project.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes