GuideMap 登陆界面 详细文档(一)

来源:互联网 发布:js 日期格式化 编辑:程序博客网 时间:2024/06/07 09:44

登录界面文档
参考:http://blog.csdn.net/chenguang79/article/details/49444787
http://blog.csdn.net/mypanlong/article/details/44802697

主要类:LoginActivity   登录类    RegisterActivity    注册类     untils/VolleyIO     Volley工具类    untils/VolleyInterface  Volley接口    untils/UserLoginSave   保存账户名类    MyApplication 封装volley队列    Bean/User   User数据类型    Bean/LoginUser  静态数据存储用户信息,与界面显示关联   设计思路是将volley读取和传送json数据的方法封装在volley工具类和接口里。   通过gson将读取到的数据放入根据返回json值确定好的bean(user)里,然后存入静态的UserLoginSave类,该类与显示界面绑定。   具体在LoginActivity/RegisterActivity中执行。同时以UserLoginSave为主实现记录登陆过的账户名。      

封装volley队列

public class MyApplication extends Application {    public static RequestQueue queues;    @Override    public void onCreate() {        super.onCreate();        queues = Volley.newRequestQueue(getApplicationContext());    }    //获取请求队列    public static RequestQueue getHttpQueues()    {        return queues;    }}

一、VolleyIO
//volley工具类

1、从服务器获取Json数据
 public static void JsonGet(String url,VolleyInterface vif) {        JsonObjectRequest request=new JsonObjectRequest(Request.Method.GET, url, null,vif.loadingListener(),vif.errorListener());        //为这个请求设置Tag        request.setTag("GetJSOB001");        //将请求添加入全局队列        MyApplication.getHttpQueues().add(request);    }
2、向服务器传送Json数据
public static void JSonPost(String url,String account,String password,String name,String phone,String mail,VolleyInterface vif){        HashMap<String, String> hashMap=new HashMap<String,String>();        hashMap.put("account",account);        hashMap.put("password",password);        hashMap.put("name",name);        hashMap.put("phone",phone);        hashMap.put("mail",mail);        String RegisterUrl=url+ "account=" + account + "&" + "password=" + password+ "&"+"mail=" + mail + "&" + "phone=" + phone+  "&"+ "name=" + name;        Log.e("tony", RegisterUrl);        JSONObject jsonParams =new JSONObject(hashMap);        JsonObjectRequest request=new JsonObjectRequest(Request.Method.POST, RegisterUrl, jsonParams , vif.loadingListener(),vif.errorListener());        //为这个请求设置Tag        request.setTag("PostJSOB001");        //将请求添加入全局队列        MyApplication.getHttpQueues().add(request);    }

二、VolleyInterface 虚类
//Volley接口
1、接口构造
public VolleyInterface(Context context,Listener listener,ErrorListener errorListener)
2、成功和失败的回调
public abstract void onMySuccess(JSONObject result)
public abstract void onMyError(VolleyError error)

public Listener loadingListener(){
onMySuccess()
}
public ErrorListener errorListener(){
onMyError()
}

public abstract class VolleyInterface {    public Context mContext;      public static Listener<JSONObject> mListener;    public static ErrorListener mErrorListener;    public VolleyInterface(Context context,Listener<JSONObject> listener,ErrorListener errorListener){          this.mContext=context;          this.mErrorListener=errorListener;          this.mListener=listener;    }    public abstract void onMySuccess(JSONObject result);    public abstract void onMyError(VolleyError error);    public Listener<JSONObject> loadingListener(){      mListener=new Listener<JSONObject>(){          @Override          public void onResponse(JSONObject response) {              onMySuccess(response);          }      };        return mListener;    }    public ErrorListener errorListener(){        mErrorListener=new ErrorListener() {            @Override            public void onErrorResponse(VolleyError error) {                onMyError(error);            }        };              return mErrorListener;          }}
0 0
原创粉丝点击