├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── demo ├── .gitignore ├── build.gradle ├── debug.keystore ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── test.gif │ ├── java │ └── org │ │ └── xutils │ │ └── demo │ │ ├── BaseActivity.java │ │ ├── BaseFragment.java │ │ ├── BigImageActivity.java │ │ ├── DbFragment.java │ │ ├── DownloadActivity.java │ │ ├── HttpFragment.java │ │ ├── ImageFragment.java │ │ ├── MainActivity.java │ │ ├── MyApplication.java │ │ ├── db │ │ ├── Child.java │ │ └── Parent.java │ │ ├── download │ │ ├── DefaultDownloadViewHolder.java │ │ ├── DownloadCallback.java │ │ ├── DownloadInfo.java │ │ ├── DownloadManager.java │ │ ├── DownloadState.java │ │ ├── DownloadStateConverter.java │ │ └── DownloadViewHolder.java │ │ └── http │ │ ├── JsonDemoParams.java │ │ ├── JsonDemoResponse.java │ │ ├── JsonParamsBuilder.java │ │ └── JsonResponseParser.java │ └── res │ ├── layout │ ├── activity_big_image.xml │ ├── activity_download.xml │ ├── activity_main.xml │ ├── download_item.xml │ ├── fragment_db.xml │ ├── fragment_http.xml │ ├── fragment_image.xml │ └── image_item.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── gradle.properties ├── settings.gradle └── xutils ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── docs ├── 1.快速使用.md ├── 2.任务和回调.md ├── 3.网络请求.md ├── 4.图片绑定.md ├── 5.Sqlite数据库使用.md └── 6.View注入.md └── src └── main ├── AndroidManifest.xml └── java └── org └── xutils ├── DbManager.java ├── HttpManager.java ├── ImageManager.java ├── ViewInjector.java ├── cache ├── DiskCacheEntity.java ├── DiskCacheFile.java ├── LruCache.java └── LruDiskCache.java ├── common ├── Callback.java ├── TaskController.java ├── task │ ├── AbsTask.java │ ├── Priority.java │ ├── PriorityExecutor.java │ ├── PriorityRunnable.java │ ├── TaskControllerImpl.java │ └── TaskProxy.java └── util │ ├── DensityUtil.java │ ├── DoubleKeyValueMap.java │ ├── FileUtil.java │ ├── IOUtil.java │ ├── KeyValue.java │ ├── LogUtil.java │ ├── MD5.java │ ├── ParameterizedTypeUtil.java │ └── ProcessLock.java ├── config └── DbConfigs.java ├── db ├── CursorUtils.java ├── DbManagerImpl.java ├── DbModelSelector.java ├── Selector.java ├── annotation │ ├── Column.java │ └── Table.java ├── converter │ ├── BooleanColumnConverter.java │ ├── ByteArrayColumnConverter.java │ ├── ByteColumnConverter.java │ ├── CharColumnConverter.java │ ├── ColumnConverter.java │ ├── ColumnConverterFactory.java │ ├── DateColumnConverter.java │ ├── DoubleColumnConverter.java │ ├── FloatColumnConverter.java │ ├── IntegerColumnConverter.java │ ├── LongColumnConverter.java │ ├── ShortColumnConverter.java │ ├── SqlDateColumnConverter.java │ └── StringColumnConverter.java ├── sqlite │ ├── ColumnDbType.java │ ├── SqlInfo.java │ ├── SqlInfoBuilder.java │ └── WhereBuilder.java └── table │ ├── ColumnEntity.java │ ├── ColumnUtils.java │ ├── DbBase.java │ ├── DbModel.java │ ├── TableEntity.java │ └── TableUtils.java ├── ex ├── BaseException.java ├── DbException.java ├── FileLockedException.java ├── HttpException.java └── HttpRedirectException.java ├── http ├── BaseParams.java ├── HttpManagerImpl.java ├── HttpMethod.java ├── HttpTask.java ├── ProgressHandler.java ├── RequestParams.java ├── RequestParamsHelper.java ├── RequestTrackerWrapper.java ├── annotation │ ├── HttpRequest.java │ └── HttpResponse.java ├── app │ ├── DefaultParamsBuilder.java │ ├── DefaultRedirectHandler.java │ ├── HttpRetryHandler.java │ ├── ParamsBuilder.java │ ├── RedirectHandler.java │ ├── RequestInterceptListener.java │ ├── RequestTracker.java │ └── ResponseParser.java ├── body │ ├── FileBody.java │ ├── InputStreamBody.java │ ├── MultipartBody.java │ ├── ProgressBody.java │ ├── RequestBody.java │ ├── StringBody.java │ └── UrlEncodedBody.java ├── cookie │ ├── CookieEntity.java │ └── DbCookieStore.java ├── loader │ ├── BooleanLoader.java │ ├── ByteArrayLoader.java │ ├── FileLoader.java │ ├── InputStreamLoader.java │ ├── IntegerLoader.java │ ├── JSONArrayLoader.java │ ├── JSONObjectLoader.java │ ├── Loader.java │ ├── LoaderFactory.java │ ├── ObjectLoader.java │ └── StringLoader.java └── request │ ├── AssetsRequest.java │ ├── HttpRequest.java │ ├── LocalFileRequest.java │ ├── ResRequest.java │ ├── UriRequest.java │ └── UriRequestFactory.java ├── image ├── AsyncDrawable.java ├── GifDrawable.java ├── ImageAnimationHelper.java ├── ImageDecoder.java ├── ImageLoader.java ├── ImageManagerImpl.java ├── ImageOptions.java ├── MemCacheKey.java ├── ReusableBitmapDrawable.java └── ReusableDrawable.java ├── view ├── EventListenerManager.java ├── ViewFinder.java ├── ViewInfo.java ├── ViewInjectorImpl.java └── annotation │ ├── ContentView.java │ ├── Event.java │ └── ViewInject.java └── x.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | gradle/ 19 | build/ 20 | gradlew* 21 | # gradle.properties 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | # Eclipse project files 33 | .classpath 34 | .project 35 | project.properties 36 | 37 | # IDEA project files 38 | *.iml 39 | .idea/ 40 | 41 | # OS generated files 42 | .DS_Store 43 | .DS_Store? 44 | ._* 45 | .Spotlight-V100 46 | .Trashes 47 | ehthumbs.db 48 | Thumbs.db 49 | 50 | # others 51 | ant.properties 52 | build.xml 53 | map.txt -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014-2015 wyouflf 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.0.1' 10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' 11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Eclipse project files 30 | .classpath 31 | .project 32 | project.properties 33 | 34 | # IDEA project files 35 | *.iml 36 | .idea/ 37 | 38 | # OS generated files 39 | .DS_Store 40 | .DS_Store? 41 | ._* 42 | .Spotlight-V100 43 | .Trashes 44 | ehthumbs.db 45 | Thumbs.db 46 | 47 | # others 48 | ant.properties 49 | build.xml 50 | map.txt -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion '29.0.3' 6 | 7 | defaultConfig { 8 | applicationId "org.xutils.demo" 9 | minSdkVersion 14 10 | targetSdkVersion 29 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | signingConfigs { 16 | debugConfig { 17 | storeFile file("debug.keystore") 18 | storePassword "android" 19 | keyAlias "androiddebugkey" 20 | keyPassword "android" 21 | } 22 | } 23 | buildTypes { 24 | release { 25 | debuggable false 26 | minifyEnabled true 27 | signingConfig signingConfigs.debugConfig 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | } 32 | 33 | dependencies { 34 | implementation fileTree(include: ['*.jar'], dir: 'libs') 35 | implementation 'androidx.appcompat:appcompat:1.1.0' 36 | implementation project(':xutils') 37 | } 38 | -------------------------------------------------------------------------------- /demo/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyouflf/xUtils3/c8e6fd6623e916ceb22ad37cd9cef2e5344ffc70/demo/debug.keystore -------------------------------------------------------------------------------- /demo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wyouflf/develop/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /demo/src/main/assets/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyouflf/xUtils3/c8e6fd6623e916ceb22ad37cd9cef2e5344ffc70/demo/src/main/assets/test.gif -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo; 2 | 3 | import android.Manifest; 4 | import android.content.pm.PackageManager; 5 | import android.os.Bundle; 6 | 7 | import androidx.appcompat.app.AppCompatActivity; 8 | import androidx.core.app.ActivityCompat; 9 | 10 | import org.xutils.x; 11 | 12 | /** 13 | * Created by wyouflf on 15/11/4. 14 | */ 15 | public class BaseActivity extends AppCompatActivity { 16 | 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | x.view().inject(this); 22 | showPermissions(); 23 | } 24 | 25 | 26 | private static final int PERMISSION_REQ_CODE = 100; 27 | 28 | //请求权限 29 | public void showPermissions() { 30 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.INTERNET) 31 | != PackageManager.PERMISSION_GRANTED 32 | || ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) 33 | != PackageManager.PERMISSION_GRANTED 34 | || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) 35 | != PackageManager.PERMISSION_GRANTED 36 | || ActivityCompat.checkSelfPermission(this, Manifest.permission.CHANGE_NETWORK_STATE) 37 | != PackageManager.PERMISSION_GRANTED) { 38 | ActivityCompat.requestPermissions(this, new String[]{ 39 | Manifest.permission.INTERNET, 40 | Manifest.permission.WRITE_EXTERNAL_STORAGE, 41 | Manifest.permission.ACCESS_NETWORK_STATE, 42 | Manifest.permission.CHANGE_NETWORK_STATE, 43 | }, PERMISSION_REQ_CODE); 44 | } else { 45 | // PERMISSION_GRANTED 46 | } 47 | } 48 | 49 | //Android6.0申请权限的回调方法 50 | @Override 51 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 52 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 53 | switch (requestCode) { 54 | case PERMISSION_REQ_CODE: 55 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 56 | // PERMISSION_GRANTED 57 | } 58 | break; 59 | default: 60 | break; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo; 2 | 3 | import android.os.Bundle; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import androidx.fragment.app.Fragment; 9 | 10 | import org.xutils.x; 11 | 12 | /** 13 | * Created by wyouflf on 15/11/4. 14 | */ 15 | public class BaseFragment extends Fragment { 16 | 17 | private boolean injected = false; 18 | 19 | @Override 20 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 21 | injected = true; 22 | return x.view().inject(this, inflater, container); 23 | } 24 | 25 | @Override 26 | public void onViewCreated(View view, Bundle savedInstanceState) { 27 | super.onViewCreated(view, savedInstanceState); 28 | if (!injected) { 29 | x.view().inject(this, this.getView()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/BigImageActivity.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo; 2 | 3 | import android.os.Bundle; 4 | import android.widget.ImageView; 5 | 6 | import org.xutils.image.ImageOptions; 7 | import org.xutils.view.annotation.ContentView; 8 | import org.xutils.view.annotation.ViewInject; 9 | import org.xutils.x; 10 | 11 | @ContentView(R.layout.activity_big_image) 12 | public class BigImageActivity extends BaseActivity { 13 | 14 | @ViewInject(R.id.iv_big_img) 15 | private ImageView iv_big_img; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | 21 | ImageOptions imageOptions = new ImageOptions.Builder() 22 | // 加载中或错误图片的ScaleType 23 | //.setPlaceholderScaleType(ImageView.ScaleType.MATRIX) 24 | // 默认自动适应大小 25 | // .setSize(...) 26 | .setIgnoreGif(false) 27 | // 如果使用本地文件url, 添加这个设置可以在本地文件更新后刷新立即生效. 28 | //.setUseMemCache(false) 29 | .setImageScaleType(ImageView.ScaleType.CENTER).build(); 30 | 31 | x.image().bind(iv_big_img, getIntent().getStringExtra("url"), imageOptions); 32 | 33 | // assets file 34 | //x.image().bind(iv_big_img, "assets://test.gif", imageOptions); 35 | 36 | // local file 37 | //x.image().bind(iv_big_img, new File("/sdcard/test.gif").toURI().toString(), imageOptions); 38 | //x.image().bind(iv_big_img, "/sdcard/test.jpg", imageOptions); 39 | //x.image().bind(iv_big_img, "file:///sdcard/test.gif", imageOptions); 40 | //x.image().bind(iv_big_img, "file:/sdcard/test.gif", imageOptions); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo; 2 | 3 | import android.os.Bundle; 4 | import android.view.Menu; 5 | import android.view.MenuItem; 6 | 7 | import androidx.fragment.app.Fragment; 8 | import androidx.fragment.app.FragmentManager; 9 | import androidx.fragment.app.FragmentPagerAdapter; 10 | import androidx.viewpager.widget.ViewPager; 11 | 12 | import org.xutils.view.annotation.ContentView; 13 | import org.xutils.view.annotation.ViewInject; 14 | 15 | @ContentView(R.layout.activity_main) 16 | public class MainActivity extends BaseActivity { 17 | 18 | @ViewInject(R.id.container) 19 | private ViewPager mViewPager; 20 | 21 | private SectionsPagerAdapter mSectionsPagerAdapter; 22 | 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); 28 | mViewPager.setAdapter(mSectionsPagerAdapter); 29 | } 30 | 31 | 32 | @Override 33 | public boolean onCreateOptionsMenu(Menu menu) { 34 | // Inflate the menu; this adds items to the action bar if it is present. 35 | getMenuInflater().inflate(R.menu.menu_main, menu); 36 | return true; 37 | } 38 | 39 | @Override 40 | public boolean onOptionsItemSelected(MenuItem item) { 41 | // Handle action bar item clicks here. The action bar will 42 | // automatically handle clicks on the Home/Up button, so long 43 | // as you specify a parent activity in AndroidManifest.xml. 44 | int id = item.getItemId(); 45 | 46 | //noinspection SimplifiableIfStatement 47 | if (id == R.id.action_settings) { 48 | return true; 49 | } 50 | 51 | return super.onOptionsItemSelected(item); 52 | } 53 | 54 | /** 55 | * A {@link FragmentPagerAdapter} that returns a fragment corresponding to 56 | * one of the sections/tabs/pages. 57 | */ 58 | public class SectionsPagerAdapter extends FragmentPagerAdapter { 59 | 60 | public SectionsPagerAdapter(FragmentManager fm) { 61 | super(fm); 62 | } 63 | 64 | @Override 65 | public Fragment getItem(int position) { 66 | switch (position) { 67 | case 0: { 68 | return new HttpFragment(); 69 | } 70 | case 1: { 71 | return new DbFragment(); 72 | } 73 | case 2: { 74 | return new ImageFragment(); 75 | } 76 | } 77 | return null; 78 | } 79 | 80 | @Override 81 | public int getCount() { 82 | return 3; 83 | } 84 | 85 | @Override 86 | public CharSequence getPageTitle(int position) { 87 | switch (position) { 88 | case 0: 89 | return "Http"; 90 | case 1: 91 | return "Database"; 92 | case 2: 93 | return "Image"; 94 | } 95 | return null; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/MyApplication.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo; 2 | 3 | import android.app.Application; 4 | 5 | import org.xutils.x; 6 | 7 | import javax.net.ssl.HostnameVerifier; 8 | import javax.net.ssl.SSLSession; 9 | 10 | /** 11 | * Created by wyouflf on 15/10/28. 12 | */ 13 | public class MyApplication extends Application { 14 | 15 | @Override 16 | public void onCreate() { 17 | super.onCreate(); 18 | x.Ext.init(this); 19 | x.Ext.setDebug(BuildConfig.DEBUG); // 开启debug会影响性能 20 | 21 | // 全局默认信任所有https域名 或 仅添加信任的https域名 22 | // 使用RequestParams#setHostnameVerifier(...)方法可设置单次请求的域名校验 23 | x.Ext.setDefaultHostnameVerifier(new HostnameVerifier() { 24 | @Override 25 | public boolean verify(String hostname, SSLSession session) { 26 | return true; // 这样是不安全的, 仅做示例. 27 | } 28 | }); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/db/Child.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013. wyouflf (wyouflf@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package org.xutils.demo.db; 17 | 18 | 19 | import org.xutils.DbManager; 20 | import org.xutils.db.annotation.Column; 21 | import org.xutils.db.annotation.Table; 22 | import org.xutils.ex.DbException; 23 | 24 | /** 25 | * Author: wyouflf 26 | * Date: 13-7-29 27 | * Time: 下午5:04 28 | */ 29 | @Table(name = "child") 30 | public class Child { 31 | 32 | @Column(name = "id", isId = true) 33 | private int id; 34 | 35 | @Column(name = "name") 36 | private String name; 37 | 38 | @Column(name = "email") 39 | private String email; 40 | 41 | @Column(name = "parentId" /*, property = "UNIQUE"//如果是一对一加上唯一约束*/) 42 | private long parentId; // 外键表id 43 | 44 | // 这个属性被忽略,不存入数据库 45 | private String willIgnore; 46 | 47 | @Column(name = "text") 48 | private String text; 49 | 50 | public Parent getParent(DbManager db) throws DbException { 51 | return db.findById(Parent.class, parentId); 52 | } 53 | 54 | public long getParentId() { 55 | return parentId; 56 | } 57 | 58 | public void setParentId(long parentId) { 59 | this.parentId = parentId; 60 | } 61 | 62 | public int getId() { 63 | return id; 64 | } 65 | 66 | public void setId(int id) { 67 | this.id = id; 68 | } 69 | 70 | public String getName() { 71 | return name; 72 | } 73 | 74 | public void setName(String name) { 75 | this.name = name; 76 | } 77 | 78 | public String getEmail() { 79 | return email; 80 | } 81 | 82 | public void setEmail(String email) { 83 | this.email = email; 84 | } 85 | 86 | public String getWillIgnore() { 87 | return willIgnore; 88 | } 89 | 90 | public void setWillIgnore(String willIgnore) { 91 | this.willIgnore = willIgnore; 92 | } 93 | 94 | public String getText() { 95 | return text; 96 | } 97 | 98 | public void setText(String text) { 99 | this.text = text; 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return "Child{" + 105 | "id=" + id + 106 | ", name='" + name + '\'' + 107 | ", email='" + email + '\'' + 108 | ", parentId=" + parentId + 109 | ", willIgnore='" + willIgnore + '\'' + 110 | ", text='" + text + '\'' + 111 | '}'; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/db/Parent.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.db; 2 | 3 | import org.xutils.DbManager; 4 | import org.xutils.db.annotation.Column; 5 | import org.xutils.db.annotation.Table; 6 | import org.xutils.ex.DbException; 7 | 8 | import java.util.Date; 9 | import java.util.List; 10 | 11 | /** 12 | * Author: wyouflf 13 | * Date: 13-7-25 14 | * Time: 下午7:06 15 | */ 16 | @Table(name = "parent", onCreated = "CREATE UNIQUE INDEX index_name ON parent(name,email)") 17 | public class Parent { 18 | 19 | @Column(name = "id", isId = true) 20 | private int id; 21 | 22 | @Column(name = "name") 23 | public String name; 24 | 25 | @Column(name = "email") 26 | private String email; 27 | 28 | @Column(name = "isAdmin") 29 | private boolean isAdmin; 30 | 31 | @Column(name = "time") 32 | private Date time; 33 | 34 | @Column(name = "date") 35 | private java.sql.Date date; 36 | 37 | public List getChildren(DbManager db) throws DbException { 38 | return db.selector(Child.class).where("parentId", "=", this.id).findAll(); 39 | } 40 | 41 | // 一对一 42 | //public Child getChild(DbManager db) throws DbException { 43 | // return db.selector(Child.class).where("parentId", "=", this.id).findFirst(); 44 | //} 45 | 46 | public int getId() { 47 | return id; 48 | } 49 | 50 | public void setId(int id) { 51 | this.id = id; 52 | } 53 | 54 | public boolean isAdmin() { 55 | return isAdmin; 56 | } 57 | 58 | public void setAdmin(boolean admin) { 59 | isAdmin = admin; 60 | } 61 | 62 | public Date getTime() { 63 | return time; 64 | } 65 | 66 | public void setTime(Date time) { 67 | this.time = time; 68 | } 69 | 70 | public java.sql.Date getDate() { 71 | return date; 72 | } 73 | 74 | public void setDate(java.sql.Date date) { 75 | this.date = date; 76 | } 77 | 78 | public String getEmail() { 79 | return email; 80 | } 81 | 82 | public void setEmail(String email) { 83 | this.email = email; 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | return "Parent{" + 89 | "id=" + id + 90 | ", name='" + name + '\'' + 91 | ", email='" + email + '\'' + 92 | ", isAdmin=" + isAdmin + 93 | ", time=" + time + 94 | ", date=" + date + 95 | '}'; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/download/DefaultDownloadViewHolder.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.download; 2 | 3 | import android.view.View; 4 | import android.widget.Toast; 5 | 6 | import org.xutils.common.Callback; 7 | import org.xutils.x; 8 | 9 | import java.io.File; 10 | 11 | /** 12 | * Created by wyouflf on 15/11/11. 13 | */ 14 | public class DefaultDownloadViewHolder extends DownloadViewHolder { 15 | 16 | public DefaultDownloadViewHolder(View view, DownloadInfo downloadInfo) { 17 | super(view, downloadInfo); 18 | } 19 | 20 | @Override 21 | public void onWaiting() { 22 | 23 | } 24 | 25 | @Override 26 | public void onStarted() { 27 | 28 | } 29 | 30 | @Override 31 | public void onLoading(long total, long current) { 32 | 33 | } 34 | 35 | @Override 36 | public void onSuccess(File result) { 37 | Toast.makeText(x.app(), "下载完成", Toast.LENGTH_LONG).show(); 38 | } 39 | 40 | @Override 41 | public void onError(Throwable ex, boolean isOnCallback) { 42 | Toast.makeText(x.app(), "下载失败", Toast.LENGTH_LONG).show(); 43 | } 44 | 45 | @Override 46 | public void onCancelled(Callback.CancelledException cex) { 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/download/DownloadInfo.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.download; 2 | 3 | import org.xutils.db.annotation.Column; 4 | import org.xutils.db.annotation.Table; 5 | 6 | /** 7 | * Author: wyouflf 8 | * Date: 13-11-10 9 | * Time: 下午8:11 10 | */ 11 | @Table(name = "download", onCreated = "CREATE UNIQUE INDEX index_name ON download(label,fileSavePath)") 12 | public class DownloadInfo { 13 | 14 | public DownloadInfo() { 15 | } 16 | 17 | @Column(name = "id", isId = true) 18 | private long id; 19 | 20 | @Column(name = "state") 21 | private DownloadState state = DownloadState.STOPPED; 22 | 23 | @Column(name = "url") 24 | private String url; 25 | 26 | @Column(name = "label") 27 | private String label; 28 | 29 | @Column(name = "fileSavePath") 30 | private String fileSavePath; 31 | 32 | @Column(name = "progress") 33 | private int progress; 34 | 35 | @Column(name = "fileLength") 36 | private long fileLength; 37 | 38 | @Column(name = "autoResume") 39 | private boolean autoResume; 40 | 41 | @Column(name = "autoRename") 42 | private boolean autoRename; 43 | 44 | public long getId() { 45 | return id; 46 | } 47 | 48 | public void setId(long id) { 49 | this.id = id; 50 | } 51 | 52 | public DownloadState getState() { 53 | return state; 54 | } 55 | 56 | public void setState(DownloadState state) { 57 | this.state = state; 58 | } 59 | 60 | public String getUrl() { 61 | return url; 62 | } 63 | 64 | public void setUrl(String url) { 65 | this.url = url; 66 | } 67 | 68 | public String getLabel() { 69 | return label; 70 | } 71 | 72 | public void setLabel(String label) { 73 | this.label = label; 74 | } 75 | 76 | public String getFileSavePath() { 77 | return fileSavePath; 78 | } 79 | 80 | public void setFileSavePath(String fileSavePath) { 81 | this.fileSavePath = fileSavePath; 82 | } 83 | 84 | public int getProgress() { 85 | return progress; 86 | } 87 | 88 | public void setProgress(int progress) { 89 | this.progress = progress; 90 | } 91 | 92 | public long getFileLength() { 93 | return fileLength; 94 | } 95 | 96 | public void setFileLength(long fileLength) { 97 | this.fileLength = fileLength; 98 | } 99 | 100 | public boolean isAutoResume() { 101 | return autoResume; 102 | } 103 | 104 | public void setAutoResume(boolean autoResume) { 105 | this.autoResume = autoResume; 106 | } 107 | 108 | public boolean isAutoRename() { 109 | return autoRename; 110 | } 111 | 112 | public void setAutoRename(boolean autoRename) { 113 | this.autoRename = autoRename; 114 | } 115 | 116 | @Override 117 | public boolean equals(Object o) { 118 | if (this == o) return true; 119 | if (!(o instanceof DownloadInfo)) return false; 120 | 121 | DownloadInfo that = (DownloadInfo) o; 122 | 123 | if (id != that.id) return false; 124 | 125 | return true; 126 | } 127 | 128 | @Override 129 | public int hashCode() { 130 | return (int) (id ^ (id >>> 32)); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/download/DownloadState.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.download; 2 | 3 | /** 4 | * Created by wyouflf on 15/11/10. 5 | */ 6 | public enum DownloadState { 7 | WAITING(0), STARTED(1), FINISHED(2), STOPPED(3), ERROR(4); 8 | 9 | private final int value; 10 | 11 | DownloadState(int value) { 12 | this.value = value; 13 | } 14 | 15 | public int value() { 16 | return value; 17 | } 18 | 19 | public static DownloadState valueOf(int value) { 20 | switch (value) { 21 | case 0: 22 | return WAITING; 23 | case 1: 24 | return STARTED; 25 | case 2: 26 | return FINISHED; 27 | case 3: 28 | return STOPPED; 29 | case 4: 30 | return ERROR; 31 | default: 32 | return STOPPED; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/download/DownloadStateConverter.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.download; 2 | 3 | import android.database.Cursor; 4 | 5 | import org.xutils.db.converter.ColumnConverter; 6 | import org.xutils.db.sqlite.ColumnDbType; 7 | 8 | /** 9 | * Created by wyouflf on 15/11/10. 10 | */ 11 | public class DownloadStateConverter implements ColumnConverter { 12 | 13 | @Override 14 | public DownloadState getFieldValue(Cursor cursor, int index) { 15 | int dbValue = cursor.getInt(index); 16 | return DownloadState.valueOf(dbValue); 17 | } 18 | 19 | @Override 20 | public Object fieldValue2DbValue(DownloadState fieldValue) { 21 | return fieldValue.value(); 22 | } 23 | 24 | @Override 25 | public ColumnDbType getColumnDbType() { 26 | return ColumnDbType.INTEGER; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/download/DownloadViewHolder.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.download; 2 | 3 | import android.view.View; 4 | 5 | import org.xutils.common.Callback; 6 | import org.xutils.x; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * Created by wyouflf on 15/11/10. 12 | */ 13 | public abstract class DownloadViewHolder { 14 | 15 | protected DownloadInfo downloadInfo; 16 | 17 | public DownloadViewHolder(View view, DownloadInfo downloadInfo) { 18 | this.downloadInfo = downloadInfo; 19 | x.view().inject(this, view); 20 | } 21 | 22 | public final DownloadInfo getDownloadInfo() { 23 | return downloadInfo; 24 | } 25 | 26 | public void update(DownloadInfo downloadInfo) { 27 | this.downloadInfo = downloadInfo; 28 | } 29 | 30 | public abstract void onWaiting(); 31 | 32 | public abstract void onStarted(); 33 | 34 | public abstract void onLoading(long total, long current); 35 | 36 | public abstract void onSuccess(File result); 37 | 38 | public abstract void onError(Throwable ex, boolean isOnCallback); 39 | 40 | public abstract void onCancelled(Callback.CancelledException cex); 41 | } 42 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/http/JsonDemoParams.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.http; 2 | 3 | import org.xutils.http.RequestParams; 4 | import org.xutils.http.annotation.HttpRequest; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by wyouflf on 16/1/23. 10 | */ 11 | @HttpRequest( 12 | host = JsonParamsBuilder.SERVER_A, 13 | path = "query/test", 14 | builder = JsonParamsBuilder.class 15 | ) 16 | public class JsonDemoParams extends RequestParams { 17 | 18 | public String paramStr; 19 | 20 | public int paramInt; 21 | 22 | public List paramList; 23 | 24 | // 可以在这里定义pb属性,在ParamsBuilder中将pb数据设置为请求内容. 25 | // private CLASS_PB pbFiled; 26 | 27 | 28 | // 发送请求的示例 29 | // 参数被JsonDemoParamsBuilder重新加工成json的形式发送. 30 | // 示例项目的混淆配置会使这个类的字段不被混淆, 字段名作为参数名. 31 | /*public static Callback.Cancelable send(Callback.CommonCallback callback) { 32 | JsonDemoParams params = new JsonDemoParams(); 33 | params.paramStr = "test"; 34 | params.paramInt = 10; 35 | params.paramList = new ArrayList(); 36 | params.paramList.add("test"); 37 | return x.http().post(params, callback); 38 | }*/ 39 | } 40 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/http/JsonDemoResponse.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.http; 2 | 3 | import org.xutils.http.annotation.HttpResponse; 4 | 5 | /** 6 | * Created by wyouflf on 15/11/5. 7 | * json 返回值示例, 如果JsonDemoResponse作为Callback的泛型, 8 | * 那么xUtils将自动调用JsonResponseParser将字符串转换为JsonDemoResponse. 9 | * 10 | * @HttpResponse 注解结合 ResponseParser接口非常适合做json, xml, protobuf等类型数据的解析, 11 | * 当然也可以通过PrepareCallback来实现自定义数据类型的转换, 参考: 12 | * {@link org.xutils.http.loader.LoaderFactory} 13 | * 和 {@link org.xutils.common.Callback.PrepareCallback}. 14 | * LoaderFactory提供PrepareCallback第一个泛型参数类型的自动转换, 15 | * 第二个泛型参数需要在prepare方法中实现. 16 | * (LoaderFactory中已经默认提供了部分常用类型的转换实现, 其他类型需要自己注册.) 17 | */ 18 | @HttpResponse(parser = JsonResponseParser.class) 19 | public class JsonDemoResponse { 20 | // some properties 21 | 22 | private String test; 23 | 24 | public String getTest() { 25 | return test; 26 | } 27 | 28 | public void setTest(String test) { 29 | this.test = test; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return test; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/http/JsonParamsBuilder.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.http; 2 | 3 | import android.text.TextUtils; 4 | 5 | import org.xutils.http.HttpMethod; 6 | import org.xutils.http.RequestParams; 7 | import org.xutils.http.annotation.HttpRequest; 8 | import org.xutils.http.app.ParamsBuilder; 9 | import org.xutils.x; 10 | 11 | import java.util.HashMap; 12 | 13 | import javax.net.ssl.SSLSocketFactory; 14 | 15 | /** 16 | * Created by wyouflf on 16/1/23. 17 | * 添加在params对象的注解参数中. 18 | */ 19 | public class JsonParamsBuilder implements ParamsBuilder { 20 | 21 | public static final String SERVER_A = "a"; 22 | public static final String SERVER_B = "b"; 23 | 24 | private static final HashMap SERVER_MAP = new HashMap(); 25 | 26 | private static final HashMap DEBUG_SERVER_MAP = new HashMap(); 27 | 28 | static { 29 | SERVER_MAP.put(SERVER_A, "https://www.baidu.com"); 30 | SERVER_MAP.put(SERVER_B, "https://www.baidu.com"); 31 | DEBUG_SERVER_MAP.put(SERVER_A, "https://www.baidu.com"); 32 | DEBUG_SERVER_MAP.put(SERVER_B, "https://www.baidu.com"); 33 | } 34 | 35 | @Override 36 | public String buildUri(RequestParams params, HttpRequest httpRequest) { 37 | String url = getHost(httpRequest.host()); 38 | // url += "/" + httpRequest.path(); 39 | return url; 40 | } 41 | 42 | @Override 43 | public String buildCacheKey(RequestParams params, String[] cacheKeys) { 44 | return null; 45 | } 46 | 47 | @Override 48 | public SSLSocketFactory getSSLSocketFactory() { 49 | return null; 50 | } 51 | 52 | @Override 53 | public void buildParams(RequestParams params) throws Throwable { 54 | // 添加额外公共参数 55 | params.addParameter("common_a", "xxxx"); 56 | params.addParameter("common_b", "xxxx"); 57 | 58 | 59 | // 将post请求的body参数以json形式提交 60 | // params.setAsJsonContent(true); 61 | 62 | // 或者query参数和body参数都json形式 63 | String json = params.toJSONString(); 64 | params.clearParams();// 清空参数 65 | if (params.getMethod() == HttpMethod.GET) { 66 | params.addQueryStringParameter("wd", json); 67 | } else { 68 | params.setBodyContent(json); 69 | } 70 | 71 | // 也可以将参数对象转为pb 72 | //byte[] pbData = convertPbData(pbFiled); 73 | //params.setMultipart(false); 74 | // 非multipart表单,key被忽略,只上传pbData 75 | //params.addBodyParameter("data", pbData, "application/octet-stream"); 76 | } 77 | 78 | @Override 79 | public void buildSign(RequestParams params, String[] signs) { 80 | // params.addHeader("xxx_sign", "xxxx"); 81 | } 82 | 83 | 84 | private String getHost(String host) { 85 | String result = null; 86 | if (x.isDebug()) { 87 | result = DEBUG_SERVER_MAP.get(host); 88 | } else { 89 | result = SERVER_MAP.get(host); 90 | } 91 | return TextUtils.isEmpty(result) ? host : result; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /demo/src/main/java/org/xutils/demo/http/JsonResponseParser.java: -------------------------------------------------------------------------------- 1 | package org.xutils.demo.http; 2 | 3 | import org.xutils.common.util.LogUtil; 4 | import org.xutils.http.app.ResponseParser; 5 | import org.xutils.http.request.UriRequest; 6 | 7 | import java.lang.reflect.Type; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by wyouflf on 15/11/5. 13 | * 添加在params对象的注解参数中. 14 | * 如果泛型为 byte[] 或 InputStream, 可以方便的转换protobuf对象. 15 | */ 16 | public class JsonResponseParser implements ResponseParser { 17 | 18 | @Override 19 | public void beforeRequest(UriRequest request) throws Throwable { 20 | // custom check params? 21 | LogUtil.d(request.getParams().toString()); 22 | } 23 | 24 | @Override 25 | public void afterRequest(UriRequest request) throws Throwable { 26 | // custom check response Headers? 27 | LogUtil.d("response code:" + request.getResponseCode()); 28 | } 29 | 30 | /** 31 | * 转换result为resultType类型的对象 32 | * 33 | * @param resultType 返回值类型(可能带有泛型信息) 34 | * @param resultClass 返回值类型 35 | * @param result 网络返回数据(支持String, byte[], JSONObject, JSONArray, InputStream) 36 | * @return 请求结果, 类型为resultType 37 | */ 38 | @Override 39 | public Object parse(Type resultType, Class resultClass, String result) throws Throwable { 40 | // TODO: json to java bean 41 | if (resultClass == List.class) { 42 | // 这里只是个示例, 不做json转换. 43 | List list = new ArrayList(); 44 | JsonDemoResponse baiduResponse = new JsonDemoResponse(); 45 | baiduResponse.setTest(result); 46 | list.add(baiduResponse); 47 | return list; 48 | // fastJson 解析示例: 49 | // return JSON.parseArray(result, (Class) ParameterizedTypeUtil.getParameterizedType(resultType, List.class, 0)); 50 | } else { 51 | // 这里只是个示例, 不做json转换. 52 | JsonDemoResponse baiduResponse = new JsonDemoResponse(); 53 | baiduResponse.setTest(result); 54 | return baiduResponse; 55 | // fastjson 解析示例: 56 | // return JSON.parseObject(result, resultType); 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_big_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_download.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/download_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 17 | 18 | 26 | 27 | 34 | 35 |