├── .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 |