dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.0.1' testCompile 'junit:junit:4.12' compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.facebook.fresco:fresco:1.5.0'
}
xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.bwie.d.liqiwen1509d20171212"> <uses-permission android:name="android.permission.INTERNET"/> <application android:name=".app.MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> intent-filter> activity> <activity android:name=".SesondActivity" /> <activity android:name=".ThreadActivity">activity> application> manifest>
AndroidManifest.xml
xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:fresco="http://schemas.android.com/apk/res-auto" android:id="@+id/activity_thread" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.bwie.d.liqiwen1509d20171212.ThreadActivity"> <TextView android:layout_width="match_parent" android:layout_height="60dp" android:text="个人信息" android:gravity="center"/> <LinearLayout android:layout_marginTop="20dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="头像"/> <ImageView android:id="@+id/sim" android:layout_width="100dp" android:layout_height="100dp" /> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="20dp"> <TextView android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="用户名"/> <TextView android:id="@+id/yonghuming" android:text="111" android:layout_weight="0" android:layout_width="wrap_content" android:layout_height="wrap_content" /> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="20dp"> <TextView android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:text="昵称"/> <TextView android:id="@+id/nicheng" android:text="111" android:layout_weight="0" android:layout_width="wrap_content" android:layout_height="wrap_content" /> LinearLayout> <Button android:layout_marginTop="20dp" android:text="退出登陆" android:layout_width="match_parent" android:layout_height="wrap_content" /> LinearLayout>
activity_thre
xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_sesond" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.bwie.d.liqiwen1509d20171212.SesondActivity"> <TextView android:layout_width="match_parent" android:layout_height="60dp" android:text="注册" android:gravity="center"/> <EditText android:id="@+id/zhuce_name" android:layout_marginTop="30dp" android:hint="请输入用户名" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/zhuce_pass" android:layout_marginTop="30dp" android:hint="请输入密码号" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/zhuce_btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册"/> LinearLayout>
activity_sesond.xml
xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.bwie.d.liqiwen1509d20171212.MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="60dp" android:text="登录" android:gravity="center"/> <EditText android:id="@+id/name" android:layout_marginTop="30dp" android:hint="请输入用户名" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/pass" android:layout_marginTop="30dp" android:hint="请输入密码号" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/deng" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="登录"/> <Button android:id="@+id/tiao" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="注册"/> LinearLayout> LinearLayout>
activity_main.xml
package com.bwie.d.liqiwen1509d20171212; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ImageView; import android.widget.TextView; import com.bwie.d.liqiwen1509d20171212.bean.GeRenBean; import com.bwie.d.liqiwen1509d20171212.okhttp.AbstractUiCallBack; import com.bwie.d.liqiwen1509d20171212.okhttp.OkhttpUtils; public class ThreadActivity extends AppCompatActivity { private TextView yonghuming; private TextView nicheng; private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_thread); yonghuming = (TextView) findViewById(R.id.yonghuming); nicheng = (TextView) findViewById(R.id.nicheng); imageView = (ImageView) findViewById(R.id.sim); Intent intent = getIntent(); String uid = intent.getStringExtra("uid"); OkhttpUtils.getInstance().asy(null, "http://120.27.23.105/user/getUserInfo?uid=" + uid, new AbstractUiCallBack() { @Override public void success(GeRenBean geRenBean) { yonghuming.setText(geRenBean.getData().getUsername()); nicheng.setText(geRenBean.getData().getToken()); imageView.setImageResource(R.drawable.minus2); } @Override public void failure(Exception e) { } }); } }
ThreadActivity
package com.bwie.d.liqiwen1509d20171212; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.bwie.d.liqiwen1509d20171212.bean.ZhuBean; import com.bwie.d.liqiwen1509d20171212.presenter.ZhuPresenter; public class SesondActivity extends AppCompatActivity implements ZhuPresenter.ZhuCallBack{ private Button zhuce_btn; private EditText zhuce_name; private EditText zhuce_pass; private ZhuPresenter presenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sesond); zhuce_btn = (Button) findViewById(R.id.zhuce_btn); zhuce_name = (EditText) findViewById(R.id.zhuce_name); zhuce_pass = (EditText) findViewById(R.id.zhuce_pass); presenter = new ZhuPresenter(this); zhuce_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { presenter.getzhudata(zhuce_name.getText().toString(),zhuce_pass.getText().toString()); } }); } @Override public void phoneEmpty() { //已经受presenter的loginPanduan方法里面逻辑代码的调用,吐司 Toast.makeText(this, "phone is empty", Toast.LENGTH_SHORT).show(); } @Override public void passwordEmpty() { //已经受presenter的loginPanduan方法里面逻辑代码的调用,吐司 Toast.makeText(this, "password is empty", Toast.LENGTH_SHORT).show(); } @Override public void success(ZhuBean zhuBean) { String msg = zhuBean.getMsg(); if(msg.equals("注册成功")){ Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show(); finish(); } } @Override public void failure() { } }
SesondActivity
package com.bwie.d.liqiwen1509d20171212; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.bwie.d.liqiwen1509d20171212.bean.DengBean; import com.bwie.d.liqiwen1509d20171212.jiekou.LoginCallBack; import com.bwie.d.liqiwen1509d20171212.presenter.LoginPresenter; public class MainActivity extends AppCompatActivity implements LoginCallBack{ private EditText name; private EditText pass; private Button deng; private Button tiao; private LoginPresenter presenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); name = (EditText) findViewById(R.id.name); pass = (EditText) findViewById(R.id.pass); deng = (Button) findViewById(R.id.deng); tiao = (Button) findViewById(R.id.tiao); tiao.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this,SesondActivity.class); startActivity(intent); } }); presenter = new LoginPresenter(this); deng.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { presenter.loginPanduan(name.getText().toString(),pass.getText().toString()); } }); } @Override public void phoneEmpty() { //已经受presenter的loginPanduan方法里面逻辑代码的调用,吐司 Toast.makeText(this, "phone is empty", Toast.LENGTH_SHORT).show(); } @Override public void passwordEmpty() { //已经受presenter的loginPanduan方法里面逻辑代码的调用,吐司 Toast.makeText(this, "password is empty", Toast.LENGTH_SHORT).show(); } @Override public void loginSuccess(DengBean dengBean) { String msg = dengBean.getMsg(); Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); int uid = dengBean.getData().getUid(); if(msg.equals("登录成功")){ Intent intent = new Intent(MainActivity.this,ThreadActivity.class); intent.putExtra("uid",uid+""); startActivity(intent); } } @Override public void loginFailed(int code) { } }
MainActivity
package com.bwie.d.liqiwen1509d20171212.presenter; import com.bwie.d.liqiwen1509d20171212.bean.ZhuBean; import com.bwie.d.liqiwen1509d20171212.model.ZhuModel; /** * Created by d on 2017/12/12. */ public class ZhuPresenter { ZhuCallBack callBack; public ZhuPresenter(ZhuCallBack callBack){ this.callBack = callBack; } ZhuModel zhuModel = new ZhuModel(); public void getzhudata(String mobile,String pass){ zhuModel.getzhudata(mobile, pass, new ZhuModel.ModelZhuCallBack() { @Override public void success(ZhuBean zhuBean) { callBack.success(zhuBean); } @Override public void failed(int code) { } }); } public interface ZhuCallBack{ //手机号码为空 public void phoneEmpty(); //密码为空 public void passwordEmpty(); public void success(ZhuBean zhuBean); public void failure(); } }
ZhuPresenter
package com.bwie.d.liqiwen1509d20171212.presenter; import android.text.TextUtils; import com.bwie.d.liqiwen1509d20171212.bean.DengBean; import com.bwie.d.liqiwen1509d20171212.jiekou.LoginCallBack; import com.bwie.d.liqiwen1509d20171212.model.LoginModel; /** * Created by d on 2017/12/12. */ public class LoginPresenter { //new出来model对象,presenter可以和model取得联系,model里面是请求网络数据的,数据库等等 private LoginModel loginModel = new LoginModel(); //当前传来的 参数是上下文,实现了接口以后,传来的就是接口 LoginCallBack loginCallBack; public LoginPresenter(LoginCallBack loginCallBack) { this.loginCallBack = loginCallBack; } //presenter里面的方法 public void loginPanduan(String phone, String password) { //这里面是逻辑代码,判断输入框是否合法 if(TextUtils.isEmpty(phone)){ //接口回调,调用avtivity也就是view里面已经实现了的接口的方法 loginCallBack.phoneEmpty(); return; } if(TextUtils.isEmpty(password)){ loginCallBack.passwordEmpty(); return; } //请求网络数据的方法在model里面,,类名·调用 loginModel.getData(phone,password, new LoginModel.ModelCallBack() { @Override public void success(DengBean dengBean) { loginCallBack.loginSuccess(dengBean); } @Override public void failed(int code) { } }); } //防止内存泄露 public void detach(){ this.loginCallBack = null; } }
LoginPresenter
package com.bwie.d.liqiwen1509d20171212.okhttp; import java.io.File; import java.util.Map; import java.util.concurrent.TimeUnit; import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; /** * Created by muhanxi on 17/11/10. * * * Okhttp 单例 范型的封装 */ public class OkhttpUtils { private static OkhttpUtils okhttpUtils = null ; private OkhttpUtils(){ } public static OkhttpUtils getInstance(){ if(okhttpUtils == null){ okhttpUtils = new OkhttpUtils(); client = new OkHttpClient.Builder() .readTimeout(20, TimeUnit.SECONDS) .writeTimeout(20,TimeUnit.SECONDS) .connectTimeout(20,TimeUnit.SECONDS) //添加拦截器 .addInterceptor(new LoggingInterceptor()) .build(); } return okhttpUtils ; } private static OkHttpClient client ; /** * 发起异步请求 * @param params * @param url * @param callBack */ public void asy(Mapparams,String url,AbstractUiCallBack callBack){ Request request = null ; if(params != null){ // post 请求 FormBody.Builder builder = new FormBody.Builder() ; for(Map.Entry entry : params.entrySet()){ builder.add(entry.getKey(),entry.getValue()); } FormBody body = builder.build(); request = new Request.Builder() .url(url) .post(body) .build(); } else { // get 请求 request = new Request.Builder() .url(url) .build(); } client.newCall(request).enqueue(callBack); } private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png"); public static void postFile(Map map, String url, File file,AbstractUiCallBack callBack){ String [] array = file.getAbsolutePath().split("\\/"); MultipartBody.Builder builder = new MultipartBody.Builder(); builder.setType(MultipartBody.FORM); for(Map.Entry entry : map.entrySet()){ builder.addFormDataPart(entry.getKey(),entry.getValue()); } builder.addFormDataPart("imageFileName",array[array.length-1]); if(file.exists() && file.length() > 0){ builder.addFormDataPart("image",array[array.length-1], RequestBody.create(MEDIA_TYPE_PNG,file)); } MultipartBody body = builder.build() ; Request request = new Request.Builder() .url(url) .post(body) .build(); client.newCall(request).enqueue(callBack); } }
OkhttpUtils
package com.bwie.d.liqiwen1509d20171212.okhttp; import java.io.IOException; import okhttp3.FormBody; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; /** * 可以实现 添加公共请求参数 */ public class LoggingInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { //首先取到Request Request request = chain.request(); Response response = null; Request requestProcess = null ; if("GET".equals(request.method())){ String url = request.url().toString() + "&source=android"; Request.Builder builder = request.newBuilder() ; builder.get().url(url); requestProcess = builder.build(); response = chain.proceed(requestProcess); } else { FormBody.Builder builder = new FormBody.Builder() ; RequestBody requestBody = request.body() ; if(requestBody instanceof FormBody){ FormBody formBody = (FormBody)requestBody ; for (int i=0;i"source","android"); } requestProcess = request.newBuilder().url(request.url().toString()).post(builder.build()).build() ; response = chain.proceed(requestProcess); } return response; } }
LoggingInterceptor
package com.bwie.d.liqiwen1509d20171212.okhttp; import android.os.Handler; import android.os.Looper; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import java.io.IOException; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * Created by muhanxi on 17/11/10. * * * Okhttp 单例 范型的封装 */ public abstract class AbstractUiCallBack<T> implements Callback { /** * 成功回调 * @param t */ public abstract void success(T t); /** * 失败回调 * @param e */ public abstract void failure(Exception e); private Handler handler = null ; private Class clazz ; public AbstractUiCallBack(){ handler = new Handler(Looper.getMainLooper()); // 得到的是一个 AbstractUiCallBack的Type Type type = getClass().getGenericSuperclass() ; // 得到的是T的实际Type Type [] arr = ((ParameterizedType)type).getActualTypeArguments() ; clazz = (Class) arr[0] ; } @Override public void onFailure(Call call, IOException e) { failure(e); } @Override public void onResponse(Call call, Response response) throws IOException { try { String result = response.body().string(); System.out.println("result = " + result); Gson gson = new Gson(); final T t = (T) gson.fromJson(result,clazz); handler.post(new Runnable() { @Override public void run() { success(t); } }); } catch (IOException e) { e.printStackTrace(); failure(e); } catch (JsonSyntaxException e) { e.printStackTrace(); failure(e); } } }
AbstractUiCallBack
package com.bwie.d.liqiwen1509d20171212.model; import com.bwie.d.liqiwen1509d20171212.app.MyApplication; import com.bwie.d.liqiwen1509d20171212.bean.ZhuBean; import java.util.Hashtable; import java.util.Map; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; /** * Created by d on 2017/12/12. */ public class ZhuModel { public void getzhudata(String mobile, String pass, final ModelZhuCallBack callBack){ Mapmap = new Hashtable<>(); map.put("mobile",mobile); map.put("password",pass); Call call = MyApplication.tiGetModel.doGetzhu(map); call.enqueue(new Callback () { @Override public void onResponse(Call call, Response response) { ZhuBean zhuBean = response.body(); callBack.success(zhuBean); } @Override public void onFailure(Call call, Throwable t) { } }); } public interface ModelZhuCallBack { //model的接口., public void success(ZhuBean zhuBean); public void failed(int code); } }
ZhuModel
package com.bwie.d.liqiwen1509d20171212.model; import com.bwie.d.liqiwen1509d20171212.app.MyApplication; import com.bwie.d.liqiwen1509d20171212.bean.DengBean; import java.util.Hashtable; import java.util.Map; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; /** * Created by d on 2017/12/12. */ public class LoginModel { //model里面是请求网络数据的方法,,,getData public void getData(String phone, String password, final ModelCallBack modelCallBack) { Mapmap = new Hashtable<>(); map.put("mobile",phone); map.put("password",password); Call call = MyApplication.tiGetModel.doGetDeng(map); call.enqueue(new Callback () { @Override public void onResponse(Call call, Response response) { DengBean dengBean = response.body(); modelCallBack.success(dengBean); } @Override public void onFailure(Call call, Throwable t) { } }); } public interface ModelCallBack { //model的接口., public void success(DengBean dengBean); public void failed(int code); } }
LoginModel
package com.bwie.d.liqiwen1509d20171212.jiekou; import com.bwie.d.liqiwen1509d20171212.bean.DengBean; import com.bwie.d.liqiwen1509d20171212.bean.ZhuBean; import java.util.Map; import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.QueryMap; /** * Created by d on 2017/12/12. */ public interface TiGetModel { @GET("/user/login") CalldoGetDeng(@QueryMap Map map); @GET("/user/reg") Call doGetzhu(@QueryMap Map map); @GET("/user/getUserInfo") Call doGetxiang(@QueryMap Map map); }
TiGetModel
package com.bwie.d.liqiwen1509d20171212.jiekou; import com.bwie.d.liqiwen1509d20171212.bean.DengBean; /** * Created by d on 2017/12/12. */ public interface LoginCallBack { //手机号码为空 public void phoneEmpty(); //密码为空 public void passwordEmpty(); //登录为空 public void loginSuccess(DengBean dengBean); //登录失败 public void loginFailed(int code); }
LoginCallBack
package com.bwie.d.liqiwen1509d20171212.bean; /** * Created by d on 2017/12/12. */ public class ZhuBean { /** * msg : 注册成功 * code : 0 */ private String msg; private String code; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }
ZhuBean
package com.bwie.d.liqiwen1509d20171212.bean; /** * Created by d on 2017/12/12. */ public class GeRenBean { /** * msg : 获取用户信息成功 * code : 0 * data : {"age":null,"appkey":"7307f2c2f372acaf","appsecret":"0B598BF9CBFEDE9284D22701B8C943DA","createtime":"2017-12-12T09:36:05","email":null,"fans":0,"follow":0,"gender":null,"icon":null,"latitude":null,"longitude":null,"mobile":"13555025485","money":null,"nickname":null,"password":"29B2504F76D2E9C177B4A8D2263921B9","praiseNum":null,"token":"0B6C8E548C65855B5B425113772361C8","uid":3839,"userId":null,"username":"13555025485"} */ private String msg; private String code; private DataBean data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public DataBean getData() { return data; } public void setData(DataBean data) { this.data = data; } public static class DataBean { /** * age : null * appkey : 7307f2c2f372acaf * appsecret : 0B598BF9CBFEDE9284D22701B8C943DA * createtime : 2017-12-12T09:36:05 * email : null * fans : 0 * follow : 0 * gender : null * icon : null * latitude : null * longitude : null * mobile : 13555025485 * money : null * nickname : null * password : 29B2504F76D2E9C177B4A8D2263921B9 * praiseNum : null * token : 0B6C8E548C65855B5B425113772361C8 * uid : 3839 * userId : null * username : 13555025485 */ private Object age; private String appkey; private String appsecret; private String createtime; private Object email; private int fans; private int follow; private Object gender; private Object icon; private Object latitude; private Object longitude; private String mobile; private Object money; private Object nickname; private String password; private Object praiseNum; private String token; private int uid; private Object userId; private String username; public Object getAge() { return age; } public void setAge(Object age) { this.age = age; } public String getAppkey() { return appkey; } public void setAppkey(String appkey) { this.appkey = appkey; } public String getAppsecret() { return appsecret; } public void setAppsecret(String appsecret) { this.appsecret = appsecret; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public Object getEmail() { return email; } public void setEmail(Object email) { this.email = email; } public int getFans() { return fans; } public void setFans(int fans) { this.fans = fans; } public int getFollow() { return follow; } public void setFollow(int follow) { this.follow = follow; } public Object getGender() { return gender; } public void setGender(Object gender) { this.gender = gender; } public Object getIcon() { return icon; } public void setIcon(Object icon) { this.icon = icon; } public Object getLatitude() { return latitude; } public void setLatitude(Object latitude) { this.latitude = latitude; } public Object getLongitude() { return longitude; } public void setLongitude(Object longitude) { this.longitude = longitude; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public Object getMoney() { return money; } public void setMoney(Object money) { this.money = money; } public Object getNickname() { return nickname; } public void setNickname(Object nickname) { this.nickname = nickname; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Object getPraiseNum() { return praiseNum; } public void setPraiseNum(Object praiseNum) { this.praiseNum = praiseNum; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public int getUid() { return uid; } public void setUid(int uid) { this.uid = uid; } public Object getUserId() { return userId; } public void setUserId(Object userId) { this.userId = userId; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } }
GeRenBean
package com.bwie.d.liqiwen1509d20171212.bean; /** * Created by d on 2017/12/12. */ public class DengBean { /** * msg : 登录成功 * code : 0 * data : {"age":null,"appkey":"7307f2c2f372acaf","appsecret":"0B598BF9CBFEDE9284D22701B8C943DA","createtime":"2017-12-12T08:52:31","email":null,"fans":null,"follow":null,"gender":null,"icon":null,"latitude":null,"longitude":null,"mobile":"13555025485","money":null,"nickname":null,"password":"29B2504F76D2E9C177B4A8D2263921B9","praiseNum":null,"token":"0B6C8E548C65855B5B425113772361C8","uid":3839,"userId":null,"username":"13555025485"} */ private String msg; private String code; private DataBean data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public DataBean getData() { return data; } public void setData(DataBean data) { this.data = data; } public static class DataBean { /** * age : null * appkey : 7307f2c2f372acaf * appsecret : 0B598BF9CBFEDE9284D22701B8C943DA * createtime : 2017-12-12T08:52:31 * email : null * fans : null * follow : null * gender : null * icon : null * latitude : null * longitude : null * mobile : 13555025485 * money : null * nickname : null * password : 29B2504F76D2E9C177B4A8D2263921B9 * praiseNum : null * token : 0B6C8E548C65855B5B425113772361C8 * uid : 3839 * userId : null * username : 13555025485 */ private Object age; private String appkey; private String appsecret; private String createtime; private Object email; private Object fans; private Object follow; private Object gender; private Object icon; private Object latitude; private Object longitude; private String mobile; private Object money; private Object nickname; private String password; private Object praiseNum; private String token; private int uid; private Object userId; private String username; public Object getAge() { return age; } public void setAge(Object age) { this.age = age; } public String getAppkey() { return appkey; } public void setAppkey(String appkey) { this.appkey = appkey; } public String getAppsecret() { return appsecret; } public void setAppsecret(String appsecret) { this.appsecret = appsecret; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public Object getEmail() { return email; } public void setEmail(Object email) { this.email = email; } public Object getFans() { return fans; } public void setFans(Object fans) { this.fans = fans; } public Object getFollow() { return follow; } public void setFollow(Object follow) { this.follow = follow; } public Object getGender() { return gender; } public void setGender(Object gender) { this.gender = gender; } public Object getIcon() { return icon; } public void setIcon(Object icon) { this.icon = icon; } public Object getLatitude() { return latitude; } public void setLatitude(Object latitude) { this.latitude = latitude; } public Object getLongitude() { return longitude; } public void setLongitude(Object longitude) { this.longitude = longitude; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public Object getMoney() { return money; } public void setMoney(Object money) { this.money = money; } public Object getNickname() { return nickname; } public void setNickname(Object nickname) { this.nickname = nickname; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Object getPraiseNum() { return praiseNum; } public void setPraiseNum(Object praiseNum) { this.praiseNum = praiseNum; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public int getUid() { return uid; } public void setUid(int uid) { this.uid = uid; } public Object getUserId() { return userId; } public void setUserId(Object userId) { this.userId = userId; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } }
DengBean
package com.bwie.d.liqiwen1509d20171212.app; import android.app.Application; import com.bwie.d.liqiwen1509d20171212.jiekou.TiGetModel; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; /** * Created by d on 2017/12/12. */ public class MyApplication extends Application{ public static TiGetModel tiGetModel; @Override public void onCreate() { super.onCreate(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://120.27.23.105") .addConverterFactory(GsonConverterFactory.create()) .build(); tiGetModel = retrofit.create(TiGetModel.class); } }
MyApplication