├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── stay4it
│ │ └── retrofit
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── stay4it
│ │ │ └── retrofit
│ │ │ ├── MainActivity.java
│ │ │ ├── activity
│ │ │ └── MultipleTypeFileUploadActivity.java
│ │ │ ├── api
│ │ │ ├── APIService.java
│ │ │ ├── APIWrapper.java
│ │ │ └── util
│ │ │ │ ├── IntegerDefaultAdapter.java
│ │ │ │ └── RetrofitUtil.java
│ │ │ ├── base
│ │ │ └── BaseActivity.java
│ │ │ ├── bean
│ │ │ └── HttpResponse.java
│ │ │ ├── interfs
│ │ │ └── BaseViewInterface.java
│ │ │ └── util
│ │ │ ├── AppToast.java
│ │ │ └── TLog.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_pic_and_text_upload.xml
│ │ └── list_item_text.xml
│ │ ├── menu
│ │ └── menu_setion.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-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── array.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── stay4it
│ └── retrofit
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | tng-customsuite.xml
2 | **pom.xml.releaseBackup
3 | release.properties
4 | gen
5 | */seed.txt
6 | notes
7 | logs
8 | gen-external-apklibs
9 | .idea
10 | *.iml
11 | .DS_Store
12 | *.swp
13 | out
14 | .gradle
15 | /local.properties
16 | /build
17 |
18 | ###OSX###
19 |
20 | .DS_Store
21 | .AppleDouble
22 | .LSOverride
23 |
24 | # Icon must ends with two \r.
25 | Icon
26 |
27 |
28 | # Thumbnails
29 | ._*
30 |
31 | # Files that might appear on external disk
32 | .Spotlight-V100
33 | .Trashes
34 |
35 |
36 | ###Linux###
37 |
38 | *~
39 |
40 | # KDE directory preferences
41 | .directory
42 |
43 |
44 | ###Android###
45 |
46 | # Built application files
47 | *.apk
48 | *.ap_
49 |
50 | # Files for ART and Dalvik VM
51 | *.dex
52 |
53 | # Java class files
54 | *.class
55 |
56 | # Generated files
57 | bin/
58 | gen/
59 |
60 | # Gradle files
61 | .gradle/
62 | .gradletasknamecache
63 | build/
64 |
65 | # Local configuration file (sdk path, etc)
66 | local.properties
67 |
68 | # Proguard folder generated by Eclipse
69 | proguard/
70 |
71 | # Lint
72 | lint-report.html
73 | lint-report_files/
74 | lint_result.txt
75 |
76 | # Mobile Tools for Java (J2ME)
77 | .mtj.tmp/
78 |
79 | # Package Files #
80 | *.war
81 | *.ear
82 |
83 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
84 | hs_err_pid*
85 |
86 |
87 | ###IntelliJ###
88 |
89 | *.iml
90 | *.ipr
91 | *.iws
92 | .idea/
93 |
94 |
95 | ###Eclipse###
96 |
97 | *.pydevproject
98 | .metadata
99 | tmp/
100 | *.tmp
101 | *.bak
102 | *.swp
103 | *~.nib
104 | .settings/
105 | .loadpath
106 |
107 | # External tool builders
108 | .externalToolBuilders/
109 |
110 | # Locally stored "Eclipse launch configurations"
111 | *.launch
112 |
113 | # CDT-specific
114 | .cproject
115 |
116 | # PDT-specific
117 | .buildpath
118 |
119 | # sbteclipse plugin
120 | .target
121 |
122 | # TeXlipse plugin
123 | .texlipseXml version="1.0" encoding="UTF-8"?>
124 | gradle.properties
125 | sign.properties
126 |
127 | captures/*
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # stay4it_retrofit
2 |
3 | stay4it_retrofit
4 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.neenbedankt.android-apt'
3 |
4 | android {
5 | compileSdkVersion 24
6 | buildToolsVersion "24.0.0"
7 | defaultConfig {
8 | applicationId "com.stay4it.retrofit"
9 | minSdkVersion 16
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26 | exclude group: 'com.android.support', module: 'support-annotations'
27 | })
28 | compile 'com.android.support:appcompat-v7:24.1.1'
29 | testCompile 'junit:junit:4.12'
30 | compile 'com.android.support:design:24.1.1'
31 | compile 'com.android.support:cardview-v7:24.1.1'
32 | compile 'com.github.bumptech.glide:glide:3.7.0'
33 | compile 'com.squareup.okhttp3:okhttp:3.3.1'
34 | compile 'com.squareup.retrofit2:retrofit:2.1.0'
35 | compile 'com.squareup.retrofit2:converter-gson:2.1.0'
36 | compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
37 | compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
38 | compile 'io.reactivex:rxandroid:1.1.0'
39 | compile 'io.reactivex:rxjava:1.1.0'
40 | compile 'com.jakewharton:butterknife:8.2.1'
41 | apt 'com.jakewharton:butterknife-compiler:8.2.1'
42 | }
43 |
--------------------------------------------------------------------------------
/app/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/lizhixian/Documents/Android/studio_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 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/stay4it/retrofit/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.stay4it.retrofit", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.LayoutInflater;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.widget.TextView;
17 |
18 | import com.stay4it.retrofit.activity.MultipleTypeFileUploadActivity;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | public class MainActivity extends AppCompatActivity {
24 |
25 | private static final Class>[] ACTIVITY = {MultipleTypeFileUploadActivity.class};
26 | private String[] TITLE ;
27 |
28 | private RecyclerView mRecyclerView = null;
29 |
30 | private DataAdapter mDataAdapter = null;
31 | private ArrayList mDataList = null;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_main);
37 |
38 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
39 | setSupportActionBar(toolbar);
40 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
41 | toolbar.setTitle("Retrofit");
42 |
43 | TITLE = getResources().getStringArray(R.array.main_item);
44 |
45 | mRecyclerView = (RecyclerView) findViewById(R.id.list);
46 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
47 |
48 | mDataList = new ArrayList<>();
49 | for (int i = 0; i < TITLE.length; i++) {
50 |
51 | ListItem item = new ListItem();
52 | item.title = TITLE[i];
53 | item.activity = ACTIVITY[i];
54 | mDataList.add(item);
55 | }
56 |
57 | mDataAdapter = new DataAdapter(this);
58 | mDataAdapter.setData(mDataList);
59 | mRecyclerView.setAdapter(mDataAdapter);
60 |
61 | }
62 |
63 | private static class ListItem {
64 | public String title;
65 | public Class> activity;
66 | }
67 |
68 | private class DataAdapter extends RecyclerView.Adapter {
69 |
70 | private LayoutInflater mLayoutInflater;
71 | private ArrayList mDataList = new ArrayList<>();
72 |
73 | public DataAdapter(Context context) {
74 | mLayoutInflater = LayoutInflater.from(context);
75 | }
76 |
77 | public void setData(ArrayList list) {
78 | this.mDataList = list;
79 | notifyDataSetChanged();
80 | }
81 |
82 | @Override
83 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
84 | return new ViewHolder(mLayoutInflater.inflate(R.layout.list_item_text, parent, false));
85 | }
86 |
87 | @Override
88 | public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
89 |
90 | ListItem listItem = mDataList.get(position);
91 |
92 | ViewHolder viewHolder = (ViewHolder) holder;
93 | viewHolder.textView.setText(listItem.title);
94 |
95 | viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
96 | @Override
97 | public void onClick(View v) {
98 |
99 | ListItem listItem = mDataList.get(position);
100 | startActivity(new Intent(MainActivity.this, listItem.activity));
101 | }
102 | });
103 | }
104 |
105 | @Override
106 | public int getItemCount() {
107 | return mDataList.size();
108 | }
109 |
110 | public List getDataList() {
111 | return mDataList;
112 | }
113 |
114 | private class ViewHolder extends RecyclerView.ViewHolder {
115 |
116 | private TextView textView;
117 |
118 | public ViewHolder(View itemView) {
119 | super(itemView);
120 | textView = (TextView) itemView.findViewById(R.id.info_text);
121 | }
122 | }
123 | }
124 |
125 | @Override
126 | public boolean onCreateOptionsMenu(Menu menu) {
127 | this.getMenuInflater().inflate(R.menu.menu_setion, menu);
128 | return true;
129 | }
130 |
131 | @Override
132 | public boolean onOptionsItemSelected(MenuItem item) {
133 | if (item.getItemId() == R.id.action_about) {
134 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/jdsjlzx/LRecyclerView"));
135 | this.startActivity(intent);
136 | return true;
137 | } else if (item.getItemId() == android.R.id.home) {
138 | finish();
139 | }
140 |
141 | return super.onOptionsItemSelected(item);
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/activity/MultipleTypeFileUploadActivity.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.activity;
2 |
3 | import android.os.Environment;
4 | import android.widget.Button;
5 |
6 | import com.stay4it.retrofit.R;
7 | import com.stay4it.retrofit.api.APIWrapper;
8 | import com.stay4it.retrofit.base.BaseActivity;
9 | import com.stay4it.retrofit.bean.HttpResponse;
10 | import com.stay4it.retrofit.util.TLog;
11 |
12 | import java.io.File;
13 | import java.util.ArrayList;
14 | import java.util.HashMap;
15 | import java.util.List;
16 | import java.util.Map;
17 |
18 | import butterknife.BindView;
19 | import butterknife.OnClick;
20 | import okhttp3.MediaType;
21 | import okhttp3.RequestBody;
22 | import rx.Subscriber;
23 | import rx.android.schedulers.AndroidSchedulers;
24 | import rx.schedulers.Schedulers;
25 |
26 | public class MultipleTypeFileUploadActivity extends BaseActivity {
27 |
28 | @BindView(R.id.action_btn)
29 | Button mActionBtn;
30 |
31 | @Override
32 | protected int getLayoutId() {
33 | return R.layout.activity_pic_and_text_upload;
34 | }
35 |
36 | @Override
37 | public void initView() {
38 | mActionBtn.setText("点我发送朋友圈");
39 | }
40 |
41 | @Override
42 | public void initData() {
43 |
44 | }
45 |
46 | @OnClick({R.id.action_btn})
47 | public void uploadFile() {
48 | String path1 = Environment.getExternalStorageDirectory() + File.separator + "test.png";
49 | String path2 = Environment.getExternalStorageDirectory() + File.separator + "test.jpg";
50 | ArrayList pathList = new ArrayList<>();
51 | pathList.add(path1);
52 | pathList.add(path2);
53 |
54 | Map bodyMap = new HashMap<>();
55 | if(pathList.size() > 0) {
56 | for (int i = 0; i < pathList.size(); i++) {
57 | File file = new File(pathList.get(i));
58 | bodyMap.put("file"+i+"\"; filename=\""+file.getName(), RequestBody.create(MediaType.parse("image/png"),file));
59 | }
60 | }
61 |
62 | APIWrapper.getInstance().uploadMultipleTypeFile("jdsjlzx",bodyMap)
63 | .subscribeOn(Schedulers.io())
64 | .observeOn(AndroidSchedulers.mainThread())
65 | .subscribe(new Subscriber>>() {
66 | @Override
67 | public void onCompleted() {
68 |
69 | }
70 |
71 | @Override
72 | public void onError(Throwable e) {
73 | TLog.error("onError " + e.toString());
74 | }
75 |
76 | @Override
77 | public void onNext(HttpResponse> response) {
78 | TLog.error("onNext " + response.toString());
79 |
80 | }
81 | });
82 |
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/api/APIService.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.api;
2 |
3 | import com.stay4it.retrofit.bean.HttpResponse;
4 |
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import okhttp3.RequestBody;
9 | import retrofit2.http.Multipart;
10 | import retrofit2.http.POST;
11 | import retrofit2.http.Part;
12 | import retrofit2.http.PartMap;
13 | import rx.Observable;
14 |
15 | /**
16 | * 接口定义
17 | * @author lizhixian
18 | * @time 16/8/18 21:46
19 | */
20 | public interface APIService {
21 |
22 | @Multipart
23 | @POST("v1/public/core/?service=user.updateAvatar")
24 | Observable>> uploadMultipleTypeFile(@Part("data") String des, @PartMap Map params);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/api/APIWrapper.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.api;
2 |
3 |
4 | import com.stay4it.retrofit.api.util.RetrofitUtil;
5 | import com.stay4it.retrofit.bean.HttpResponse;
6 |
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | import okhttp3.RequestBody;
11 | import rx.Observable;
12 |
13 | public class APIWrapper extends RetrofitUtil {
14 |
15 | private static APIWrapper mAPIWrapper;
16 |
17 | public APIWrapper() {
18 | }
19 |
20 | public static APIWrapper getInstance() {
21 | if (mAPIWrapper == null) {
22 | mAPIWrapper = new APIWrapper();
23 | }
24 | return mAPIWrapper;
25 | }
26 |
27 | public Observable>> uploadMultipleTypeFile(String des, Map params) {
28 | return getAPIService().uploadMultipleTypeFile(des, params);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/api/util/IntegerDefaultAdapter.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.api.util;
2 |
3 | import com.google.gson.JsonDeserializationContext;
4 | import com.google.gson.JsonDeserializer;
5 | import com.google.gson.JsonElement;
6 | import com.google.gson.JsonParseException;
7 | import com.google.gson.JsonPrimitive;
8 | import com.google.gson.JsonSerializationContext;
9 | import com.google.gson.JsonSerializer;
10 |
11 | import java.lang.reflect.Type;
12 |
13 | /**
14 | * 空字符转换为0
15 | * @author lizhixian
16 | * @time 16/8/18 21:47
17 | */
18 |
19 | public class IntegerDefaultAdapter implements JsonSerializer,JsonDeserializer {
20 | @Override
21 | public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
22 |
23 | if(json.getAsString().equals("")) {
24 | return 0;
25 | }
26 |
27 | return json.getAsInt();
28 | }
29 |
30 | @Override
31 | public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
32 | return new JsonPrimitive(src);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/api/util/RetrofitUtil.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.api.util;
2 |
3 |
4 | import com.google.gson.Gson;
5 | import com.google.gson.GsonBuilder;
6 | import com.stay4it.retrofit.api.APIService;
7 |
8 | import okhttp3.OkHttpClient;
9 | import okhttp3.logging.HttpLoggingInterceptor;
10 | import retrofit2.Retrofit;
11 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
12 | import retrofit2.converter.gson.GsonConverterFactory;
13 |
14 | public class RetrofitUtil {
15 | /**
16 | * 服务器地址
17 | */
18 | private static final String API_HOST = "http://api.stay4it.com/";
19 |
20 | private static Retrofit mRetrofit;
21 | private static APIService mAPIService;
22 |
23 | private static Retrofit getRetrofit() {
24 | if (mRetrofit == null) {
25 | OkHttpClient.Builder builder = new OkHttpClient.Builder();
26 | // Log
27 | HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
28 | logging.setLevel(HttpLoggingInterceptor.Level.BODY);
29 | OkHttpClient client = builder.addInterceptor(logging)
30 | .build();
31 |
32 | mRetrofit = new Retrofit.Builder()
33 | .baseUrl(API_HOST)
34 | .addConverterFactory(GsonConverterFactory.create(buildGson()))
35 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
36 | .client(client)
37 | .build();
38 | }
39 | return mRetrofit;
40 | }
41 |
42 | public static APIService getAPIService() {
43 | if (mAPIService == null) {
44 | mAPIService = getRetrofit().create(APIService.class);
45 | }
46 | return mAPIService;
47 | }
48 |
49 |
50 | public static Gson buildGson() {
51 | return new GsonBuilder()
52 | .setDateFormat("yyyy-MM-dd HH:mm:ss")
53 | .registerTypeAdapter(Integer.class, new IntegerDefaultAdapter())
54 | .registerTypeAdapter(int.class, new IntegerDefaultAdapter())
55 | .create();
56 | }
57 |
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.base;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.inputmethod.InputMethodManager;
12 | import android.widget.EditText;
13 |
14 | import com.stay4it.retrofit.R;
15 | import com.stay4it.retrofit.interfs.BaseViewInterface;
16 |
17 | import butterknife.BindView;
18 | import butterknife.ButterKnife;
19 |
20 | public abstract class BaseActivity extends AppCompatActivity implements BaseViewInterface {
21 |
22 | @BindView(R.id.toolbar)
23 | Toolbar toolbar;
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | if (getLayoutId() != 0) {
28 | setContentView(getLayoutId());
29 | }
30 | ButterKnife.bind(this);
31 |
32 | setSupportActionBar(toolbar);
33 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
34 | toolbar.setTitle("SwipeMenu汇总");
35 |
36 | initView();
37 | initData();
38 | }
39 |
40 | protected int getLayoutId() {
41 | return 0;
42 | }
43 |
44 | // 隐藏虚拟键盘
45 | protected void hideKeyboard(EditText editText) {
46 | InputMethodManager imm = (InputMethodManager) (getApplicationContext()).getSystemService(Context.INPUT_METHOD_SERVICE);
47 | if (imm.isActive()) {
48 | imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
49 | }
50 | }
51 |
52 | @Override
53 | public boolean onCreateOptionsMenu(Menu menu) {
54 | this.getMenuInflater().inflate(R.menu.menu_setion, menu);
55 | return true;
56 | }
57 |
58 | @Override
59 | public boolean onOptionsItemSelected(MenuItem item) {
60 | if (item.getItemId() == R.id.action_about) {
61 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/jdsjlzx/LRecyclerView"));
62 | this.startActivity(intent);
63 | return true;
64 | } else if (item.getItemId() == android.R.id.home) {
65 | finish();
66 | }
67 |
68 | return super.onOptionsItemSelected(item);
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/bean/HttpResponse.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.bean;
2 |
3 | /**
4 | *
5 | * @author lizhixian
6 | * @time 16/8/18 21:54
7 | */
8 | public class HttpResponse {
9 |
10 | public int ret;
11 | public T data;
12 | public String msg;
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/interfs/BaseViewInterface.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.interfs;
2 |
3 | /**
4 | *
5 | * @author lizhixian
6 | * @time 16/8/18 22:43
7 | */
8 | public interface BaseViewInterface {
9 |
10 | public void initView();
11 |
12 | public void initData();
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/util/AppToast.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.util;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | public class AppToast {
7 |
8 | protected static final String TAG = "AppToast";
9 | public static Toast toast;
10 | /**
11 | * 信息提示
12 | *
13 | * @param context
14 | * @param content
15 | */
16 | public static void makeToast(Context context, String content) {
17 | if(context==null)return;
18 | if(toast != null)
19 | toast.cancel();
20 | toast = Toast.makeText(context, content, Toast.LENGTH_LONG);
21 | toast.show();
22 | }
23 |
24 | public static void makeShortToast(Context context, String content) {
25 | if(context==null)return;
26 | if(toast != null)
27 | toast.cancel();
28 | toast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
29 | toast.show();
30 | }
31 |
32 | public static void showShortText(Context context, int resId) {
33 | try {
34 | if(context==null)return;
35 | if(toast != null)
36 | toast.cancel();
37 | toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
38 | toast.show();
39 | } catch (Exception e) {
40 | }
41 | }
42 |
43 | public static void showShortText(Context context, CharSequence text) {
44 | if(context==null)return;
45 | if(toast != null)
46 | toast.cancel();
47 | toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
48 | toast.show();
49 | }
50 |
51 | public static void showLongText(Context context, int resId) {
52 | try {
53 | if(context==null)return;
54 | if(toast != null)
55 | toast.cancel();
56 | toast = Toast.makeText(context, resId, Toast.LENGTH_LONG);
57 | toast.show();
58 |
59 | } catch (Exception e) {
60 | }
61 | }
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/stay4it/retrofit/util/TLog.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit.util;
2 |
3 | import android.util.Log;
4 |
5 | public class TLog {
6 | public static final String LOG_TAG = "lizhixian";
7 | public static boolean DEBUG = true;
8 |
9 | public TLog() {
10 | }
11 |
12 | public static final void analytics(String log) {
13 | if (DEBUG)
14 | Log.d(LOG_TAG, log);
15 | }
16 |
17 | public static final void error(String log) {
18 | if (DEBUG)
19 | Log.e(LOG_TAG, "" + log);
20 | }
21 |
22 | public static final void log(String log) {
23 | if (DEBUG)
24 | Log.i(LOG_TAG, log);
25 | }
26 |
27 | public static final void log(String tag, String log) {
28 | if (DEBUG)
29 | Log.i(tag, log);
30 | }
31 |
32 | public static final void logv(String log) {
33 | if (DEBUG)
34 | Log.v(LOG_TAG, log);
35 | }
36 |
37 | public static final void warn(String log) {
38 | if (DEBUG)
39 | Log.w(LOG_TAG, log);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
22 |
23 |
24 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_pic_and_text_upload.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
22 |
23 |
24 |
25 |
29 |
30 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_setion.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stay4it/RetrofitTutorial/ecda2a30726ce37b3d8a2332ca36df588eec2b08/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stay4it/RetrofitTutorial/ecda2a30726ce37b3d8a2332ca36df588eec2b08/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stay4it/RetrofitTutorial/ecda2a30726ce37b3d8a2332ca36df588eec2b08/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stay4it/RetrofitTutorial/ecda2a30726ce37b3d8a2332ca36df588eec2b08/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stay4it/RetrofitTutorial/ecda2a30726ce37b3d8a2332ca36df588eec2b08/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/array.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - 仿朋友圈上传图片和文字
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Stay4it_retrofit
3 | 关于我
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/test/java/com/stay4it/retrofit/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.stay4it.retrofit;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/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 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.0-beta1'
9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stay4it/RetrofitTutorial/ecda2a30726ce37b3d8a2332ca36df588eec2b08/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------