Android Xutils 프레임 워 크

28442 단어 AndroidJAVA
xUtils 소개
  • xUtils 는 실 용적 인 안 드 로 이 드 도 구 를 많이 포함 하고 있 습 니 다
  • xUtils 는 Afinal 프레임 워 크 에서 기원 되 었 고 Afinal 에 대해 대량의 재 구성 을 실시 하여 xUtils 는 큰 파일 업로드,더욱 전면적 인 http 요청 프로 토 콜 지원,더욱 유연 한 ORM,더 많은 이벤트 주석 지원 과 혼동 의 영향 을 받 지 않 습 니 다.
    xUitls 최저 호 환 안 드 로 이 드 2.2(api level 8)
  • 현재 xUtils 는 주로 4 대 모듈 이 있 습 니 다.
    DbUtils 모듈:
  • 안 드 로 이 드 의 orm 프레임 워 크 는 한 줄 의 코드 를 추가 삭제 하고 수정 할 수 있 습 니 다
  • 사 무 를 지원 하고 기본적으로 닫 습 니 다
  • 사용자 정의 표 이름,열 이름,외 키,유일 성 제약,NOT NULL 제약,CHECK 제약 등 을 주석 할 수 있 습 니 다(헷 갈 릴 때 표 이름과 열 이름 을 주석 하 십시오)

  • 4.567917.바 인 딩 외 키 를 지원 하고 실 체 를 저장 할 때 외 키 관련 실 체 를 자동 으로 저장 하거나 업데이트 합 니 다
  • 외부 키 관련 실 체 를 자동 으로 불 러 오고 지연 로 딩 을 지원 합 니 다

  • 4.567917.체인 표현 조 회 를 지원 하고 더욱 직관 적 인 조회 의 미 를 지원 하 며 아래 의 소개 나 sample 중의 예 를 참고 합 니 다

    ViewUtils 모듈:
  • 안 드 로 이 드 의 ioc 프레임 워 크 는 완전히 주석 방식 으로 UI 바 인 딩 과 이벤트 바 인 딩 을 할 수 있 습 니 다
  • 새로운 이벤트 바 인 딩 방식 은 헷 갈 리 는 도 구 를 사용 하여 헷 갈 린 후에 도 정상적으로 작업 할 수 있 습 니 다
  • 현재 자주 사용 하 는 11 가지 이벤트 바 인 딩 을 지원 합 니 다.ViewCommonEventListener 류 와 가방 com.lidroid.xutils.view.annotation.event 를 참조 하 십시오


  • HttpUtils 모듈:
  • 동기 화,비동기 방식 의 요청 을 지원 합 니 다
  • 큰 파일 업로드 지원,큰 파일 업로드 하지 않 음 oom;

  • GET,POST,PUT,MOVE,COPY,DELETE,HEAD 요청 을 지원 합 니 다
  • 다운 로드 는 301/302 리 셋 을 지원 하 며,Content-Disposition 에 따라 다운 로드 된 파일 의 이름 을 바 꿀 지 여 부 를 설정 할 수 있 습 니 다
  • 텍스트 내용 을 되 돌려 주 는 GET 요청 은 캐 시 를 지원 합 니 다.기본 만 료 시간 과 현재 요청 에 대한 만 료 시간 을 설정 할 수 있 습 니 다


  • BitmapUtils 모듈:
  • bitmap 를 불 러 올 때 bitmap 불 러 오 는 과정 에서 나타 나 는 oom 과 android 용기 가 빠르게 미 끄 러 질 때 나타 나 는 그림 오류 등 을 고려 하지 않 아 도 됩 니 다

  • 네트워크 그림 과 로 컬 그림 을 불 러 오 는 것 을 지원 합 니 다
    4.567917.메모리 관 리 는 lru 알고리즘 을 사용 하여 bitmap 메모 리 를 더욱 잘 관리 합 니 다
  • 스 레 드 로 딩 스 레 드 수량,캐 시 크기,캐 시 경로,로 딩 디 스 플레이 애니메이션 등 을 설정 할 수 있 습 니 다

  • xUtils 빠 른 개발 프레임 워 크 를 사용 하려 면 다음 과 같은 권한 이 필요 합 니 다.
     android:name="android.permission.INTERNET" />  android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    혼동 시 주의사항:
  • xUtils 의 주석 형식 을 헷 갈 리 지 말고 헷 갈 리 는 설정 을 추가 하 십시오.-keep class*extends java.lang.annotation.annotation{*;}

  • DbUtils 모듈 을 사용 하여 오래 지속 되 는 실체 클래스 를 혼동 하거나 모든 표 와 열 이름@Table(name="xxx"),@Id(column="xxx"),@Column(column="xxx"),@Foreign(column="xxx",foreign="xxx")을 주석 하지 마 십시오
    DbUtils 사용법:
    DbUtils db = DbUtils.create(this); User user = new User(); //        User     id  ,     @ID      user.setEmail("[email protected]"); user.setName("wyouflf"); db.save(user); //   saveBindingId          id   ... //    Parent entity = db.findById(Parent.class, parent.getId()); Parent entity = db.findFirst(entity);//  entity      List<Parent> list = db.findAll(entity);//  entity      Parent Parent = db.findFirst(Selector.from(Parent.class).where("name","=","test")); List<Parent> list = db.findAll(Selector.from(Parent.class) .where("id",",54) .and("age",">",30) .or("age",",20) .orderBy("id") .limit(10) .offset(0)); DbModel dbModel = db.findDbModelAll(Selector.from(Parent.class).select("name"));//select("name")   name  List<DbModel> dbModels = db.findDbModelAll(Selector.from(Parent.class).groupBy("name").select("name", "count(name)")); ... 

    ViewUtils 사용 방법
    4.567917.완전 주해 방식 으로 UI 바 인 딩 과 이벤트 바 인 딩 을 할 수 있 습 니 다
  • findViewById 와 setClickListener 등 이 필요 없습니다
  • @ViewInject(R.id.textView) TextView textView; //                  ,  id         @OnClick(R.id.test_button) public void testButtonClick(View v) { ... } ... //           ( onCreate ): @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ViewUtils.inject(this); ... textView.setText("some text..."); ... } 

    HttpUtils 사용 방법:
    일반 get 방법
    HttpUtils http = new HttpUtils(); http.send(HttpRequest.HttpMethod.GET, "http://www.lidroid.com", new RequestCallBack<String>(){ @Override public void onLoading(long total, long current) { testTextView.setText(current + "/" + total); } @Override public void onSuccess(String result) { textView.setText(result); } @Override public void onStart() { } @Override public void onFailure((HttpException error, String msg) { } }); 

    HttpUtils 를 사용 하여 파일 을 업로드 하거나 서버 에 데 이 터 를 제출 합 니 다(post 방법)
    RequestParams params = new RequestParams(); params.addHeader("name", "value"); params.addQueryStringParameter("name", "value"); //              BodyParamsEntity, //    UrlEncodedFormEntity("application/x-www-form-urlencoded")。 params.addBodyParameter("name", "value"); //            MultipartEntity("multipart/form-data"), //   "multipart/related",xUtils    MultipartEntity    subType "related"。 //   params.setBodyEntity(httpEntity)        HttpEntity( : // MultipartEntity,BodyParamsEntity,FileUploadEntity,InputStreamUploadEntity,StringEntity)。 params.addBodyParameter("file", new File("path")); ... HttpUtils http = new HttpUtils(); http.send(HttpRequest.HttpMethod.POST, "uploadUrl....", params, new RequestCallBack<String>() { @Override public void onStart() { testTextView.setText("conn..."); } @Override public void onLoading(long total, long current) { testTextView.setText(current + "/" + total); } @Override public void onSuccess(String result) { testTextView.setText("upload response:" + result.getPath()); } @Override public void onFailure(HttpException error, String msg) { testTextView.setText(error.getExceptionCode() + ":" + msg); } }); 

    HttpUtils 로 파일 다운로드:
  • 정지점 전송 지원,수시로 다운로드 작업 중단,퀘 스 트 시작
  • HttpUtils http = new HttpUtils(); HttpHandler handler = http.download("http://apache.dataguru.cn/httpcomponents/httpclient/source/httpcomponents-client-4.2.5-src.zip", "/sdcard/httpcomponents-client-4.2.5-src.zip", true, //         ,            。 true, //                 ,          。 new RequestCallBack<File>() { @Override public void onStart() { testTextView.setText("conn..."); } @Override public void onLoading(long total, long current) { testTextView.setText(current + "/" + total); } @Override public void onSuccess(File result) { testTextView.setText("downloaded:" + result.getPath()); } @Override public void onFailure(HttpException error, String msg) { testTextView.setText(msg); } }); ... //  stop()       handler.stop(); ... 

    BitmapUtils 사용 방법
    BitmapUtils.create(this).display(testImageView, "http://bbs.lidroid.com/static/image/common/logo.png"); //BitmapUtils.create(this).display(testImageView, "/sdcard/test.jpg"); //         //   ListView           PauseOnScrollListener                     listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils, false, true)); listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils, false, true), customListener); 

    기타(**더 많은 예제 코드 는 sample 폴 더 의 코드**참조)
    출력 로그 LogUtils
    //     TAG,  : className[methodName, lineNumber] //       allowD,allowE...,      log。 LogUtils.d("wyouflf"); 

    좋은 웹페이지 즐겨찾기