Commit 4912f2ed51d5c06a47ea46cd09e0c2bebcad02ab
1 parent
7b881e316b
Exists in
master
Gson
Showing
8 changed files
with
58 additions
and
49 deletions
Show diff stats
PersonalCenter/.idea/misc.xml
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <project version="4"> | 2 | <project version="4"> |
3 | <component name="EntryPointsManager"> | 3 | <component name="EntryPointsManager"> |
4 | <entry_points version="2.0" /> | 4 | <entry_points version="2.0" /> |
5 | </component> | 5 | </component> |
6 | <component name="NullableNotNullManager"> | 6 | <component name="NullableNotNullManager"> |
7 | <option name="myDefaultNullable" value="android.support.annotation.Nullable" /> | 7 | <option name="myDefaultNullable" value="android.support.annotation.Nullable" /> |
8 | <option name="myDefaultNotNull" value="android.support.annotation.NonNull" /> | 8 | <option name="myDefaultNotNull" value="android.support.annotation.NonNull" /> |
9 | <option name="myNullables"> | 9 | <option name="myNullables"> |
10 | <value> | 10 | <value> |
11 | <list size="4"> | 11 | <list size="4"> |
12 | <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" /> | 12 | <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" /> |
13 | <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" /> | 13 | <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" /> |
14 | <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" /> | 14 | <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" /> |
15 | <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" /> | 15 | <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" /> |
16 | </list> | 16 | </list> |
17 | </value> | 17 | </value> |
18 | </option> | 18 | </option> |
19 | <option name="myNotNulls"> | 19 | <option name="myNotNulls"> |
20 | <value> | 20 | <value> |
21 | <list size="4"> | 21 | <list size="4"> |
22 | <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" /> | 22 | <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" /> |
23 | <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" /> | 23 | <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" /> |
24 | <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" /> | 24 | <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" /> |
25 | <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" /> | 25 | <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" /> |
26 | </list> | 26 | </list> |
27 | </value> | 27 | </value> |
28 | </option> | 28 | </option> |
29 | </component> | 29 | </component> |
30 | <component name="ProjectInspectionProfilesVisibleTreeState"> | ||
31 | <entry key="Project Default"> | ||
32 | <profile-state> | ||
33 | <expanded-state> | ||
34 | <State> | ||
35 | <id /> | ||
36 | </State> | ||
37 | <State> | ||
38 | <id>Class structureJava</id> | ||
39 | </State> | ||
40 | <State> | ||
41 | <id>Code maturity issuesJava</id> | ||
42 | </State> | ||
43 | <State> | ||
44 | <id>Java</id> | ||
45 | </State> | ||
46 | <State> | ||
47 | <id>Java language level migration aidsJava</id> | ||
48 | </State> | ||
49 | <State> | ||
50 | <id>Javadoc issuesJava</id> | ||
51 | </State> | ||
52 | <State> | ||
53 | <id>Performance issuesJava</id> | ||
54 | </State> | ||
55 | <State> | ||
56 | <id>TestNGJava</id> | ||
57 | </State> | ||
58 | <State> | ||
59 | <id>Threading issuesJava</id> | ||
60 | </State> | ||
61 | </expanded-state> | ||
62 | <selected-state> | ||
63 | <State> | ||
64 | <id>Android</id> | ||
65 | </State> | ||
66 | </selected-state> | ||
67 | </profile-state> | ||
68 | </entry> | ||
69 | </component> | ||
70 | <component name="ProjectLevelVcsManager" settingsEditedManually="false"> | 30 | <component name="ProjectLevelVcsManager" settingsEditedManually="false"> |
71 | <OptionsSetting value="true" id="Add" /> | 31 | <OptionsSetting value="true" id="Add" /> |
72 | <OptionsSetting value="true" id="Remove" /> | 32 | <OptionsSetting value="true" id="Remove" /> |
73 | <OptionsSetting value="true" id="Checkout" /> | 33 | <OptionsSetting value="true" id="Checkout" /> |
74 | <OptionsSetting value="true" id="Update" /> | 34 | <OptionsSetting value="true" id="Update" /> |
75 | <OptionsSetting value="true" id="Status" /> | 35 | <OptionsSetting value="true" id="Status" /> |
76 | <OptionsSetting value="true" id="Edit" /> | 36 | <OptionsSetting value="true" id="Edit" /> |
77 | <ConfirmationsSetting value="0" id="Add" /> | 37 | <ConfirmationsSetting value="0" id="Add" /> |
78 | <ConfirmationsSetting value="0" id="Remove" /> | 38 | <ConfirmationsSetting value="0" id="Remove" /> |
79 | </component> | 39 | </component> |
80 | <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | 40 | <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> |
81 | <output url="file://$PROJECT_DIR$/build/classes" /> | 41 | <output url="file://$PROJECT_DIR$/build/classes" /> |
82 | </component> | 42 | </component> |
83 | <component name="ProjectType"> | 43 | <component name="ProjectType"> |
84 | <option name="id" value="Android" /> | 44 | <option name="id" value="Android" /> |
85 | </component> | 45 | </component> |
86 | </project> | 46 | </project> |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/activity/RegisterInfoActivity.java
1 | package com.hjx.personalcenter.activity; | 1 | package com.hjx.personalcenter.activity; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
5 | import android.support.v7.app.AppCompatActivity; | 5 | import android.support.v7.app.AppCompatActivity; |
6 | import android.view.View; | 6 | import android.view.View; |
7 | import android.widget.Button; | 7 | import android.widget.Button; |
8 | import android.widget.EditText; | 8 | import android.widget.EditText; |
9 | import android.widget.TextView; | 9 | import android.widget.TextView; |
10 | 10 | ||
11 | import com.hjx.personalcenter.R; | 11 | import com.hjx.personalcenter.R; |
12 | import com.hjx.personalcenter.customdialog.GradeListDialog; | 12 | import com.hjx.personalcenter.customdialog.GradeListDialog; |
13 | import com.hjx.personalcenter.customdialog.ProvinceListDialog; | 13 | import com.hjx.personalcenter.customdialog.ProvinceListDialog; |
14 | import com.hjx.personalcenter.http.HttpManager; | 14 | import com.hjx.personalcenter.http.HttpManager; |
15 | 15 | ||
16 | /**填写注册信息 熊巍 | 16 | /**填写注册信息 熊巍 |
17 | * Created by h on 2017/8/9. | 17 | * Created by h on 2017/8/9. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | public class RegisterInfoActivity extends AppCompatActivity implements View.OnClickListener { | 20 | public class RegisterInfoActivity extends AppCompatActivity implements View.OnClickListener { |
21 | private EditText et_username; | 21 | private EditText et_username; |
22 | private TextView et_region,et_grade,et_school; | 22 | private TextView et_region,et_grade,et_school; |
23 | private Button btn_ok; | 23 | private Button btn_ok; |
24 | String[] items; | 24 | String[] items; |
25 | 25 | ||
26 | @Override | 26 | @Override |
27 | protected void onCreate(Bundle savedInstanceState) { | 27 | protected void onCreate(Bundle savedInstanceState) { |
28 | super.onCreate(savedInstanceState); | 28 | super.onCreate(savedInstanceState); |
29 | setContentView(R.layout.activity_registerinfo); | 29 | setContentView(R.layout.activity_registerinfo); |
30 | initView(); | 30 | initView(); |
31 | initData(); | 31 | initData(); |
32 | initLister(); | 32 | initLister(); |
33 | } | 33 | } |
34 | 34 | ||
35 | private void initView() { | 35 | private void initView() { |
36 | et_username = (EditText) findViewById(R.id.et_username); | 36 | et_username = (EditText) findViewById(R.id.et_username); |
37 | et_region = (TextView) findViewById(R.id.et_region); | 37 | et_region = (TextView) findViewById(R.id.et_region); |
38 | et_grade = (TextView) findViewById(R.id.et_grade); | 38 | et_grade = (TextView) findViewById(R.id.et_grade); |
39 | et_school = (TextView) findViewById(R.id.et_school); | 39 | et_school = (TextView) findViewById(R.id.et_school); |
40 | btn_ok = (Button) findViewById(R.id.btn_ok); | 40 | btn_ok = (Button) findViewById(R.id.btn_ok); |
41 | 41 | ||
42 | 42 | ||
43 | } | 43 | } |
44 | 44 | ||
45 | private void initData() { | 45 | private void initData() { |
46 | items = new String[] { "魏", "蜀", "吴" }; | 46 | items = new String[] { "魏", "蜀", "吴" }; |
47 | 47 | ||
48 | } | 48 | } |
49 | 49 | ||
50 | private void initLister() { | 50 | private void initLister() { |
51 | et_region.setOnClickListener(this); | 51 | et_region.setOnClickListener(this); |
52 | et_grade.setOnClickListener(this); | 52 | et_grade.setOnClickListener(this); |
53 | et_school.setOnClickListener(this); | 53 | et_school.setOnClickListener(this); |
54 | btn_ok.setOnClickListener(this); | 54 | btn_ok.setOnClickListener(this); |
55 | 55 | ||
56 | 56 | ||
57 | } | 57 | } |
58 | 58 | ||
59 | @Override | 59 | @Override |
60 | public void onClick(View v) { | 60 | public void onClick(View v) { |
61 | switch (v.getId()){ | 61 | switch (v.getId()){ |
62 | case R.id.et_region: | 62 | case R.id.et_region: |
63 | choiseregion(); | 63 | choiseregion(); |
64 | break; | 64 | break; |
65 | case R.id.et_grade: | 65 | case R.id.et_grade: |
66 | choisegrade(); | 66 | choisegrade(); |
67 | break; | 67 | break; |
68 | case R.id.et_school: | 68 | case R.id.et_school: |
69 | break; | 69 | break; |
70 | case R.id.btn_ok: | 70 | case R.id.btn_ok: |
71 | Intent intent = new Intent(); | 71 | Intent intent = new Intent(); |
72 | intent.setClass(RegisterInfoActivity.this,ChoiseTextBookActivity.class); | 72 | intent.setClass(RegisterInfoActivity.this,ChoiseTextBookActivity.class); |
73 | startActivity(intent); | 73 | startActivity(intent); |
74 | overridePendingTransition(R.anim.rightin, R.anim.rightout); | 74 | overridePendingTransition(R.anim.rightin, R.anim.rightout); |
75 | break; | 75 | break; |
76 | } | 76 | } |
77 | 77 | ||
78 | } | 78 | } |
79 | //选择地区 | 79 | //选择地区 |
80 | private void choiseregion() { | 80 | private void choiseregion() { |
81 | HttpManager.getInstance().countyinfo(RegisterInfoActivity.this,210300); | 81 | HttpManager.getInstance().provices(RegisterInfoActivity.this); |
82 | ProvinceListDialog.getInstance().show(getSupportFragmentManager(), "ProvinceListDialog"); | 82 | ProvinceListDialog.getInstance().show(getSupportFragmentManager(), "ProvinceListDialog"); |
83 | } | 83 | } |
84 | //选择年级 | 84 | //选择年级 |
85 | private void choisegrade() { | 85 | private void choisegrade() { |
86 | GradeListDialog.getInstance().show(getSupportFragmentManager(), "GradeListDialog"); | 86 | GradeListDialog.getInstance().show(getSupportFragmentManager(), "GradeListDialog"); |
87 | 87 | ||
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/ProvinceListDialog.java
1 | package com.hjx.personalcenter.customdialog; | 1 | package com.hjx.personalcenter.customdialog; |
2 | 2 | ||
3 | import android.content.Context; | 3 | import android.content.Context; |
4 | import android.graphics.Color; | 4 | import android.graphics.Color; |
5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
6 | import android.view.Gravity; | 6 | import android.view.Gravity; |
7 | import android.view.LayoutInflater; | 7 | import android.view.LayoutInflater; |
8 | import android.view.View; | 8 | import android.view.View; |
9 | import android.view.ViewGroup; | 9 | import android.view.ViewGroup; |
10 | import android.widget.AdapterView; | 10 | import android.widget.AdapterView; |
11 | import android.widget.ArrayAdapter; | 11 | import android.widget.ArrayAdapter; |
12 | import android.widget.ListView; | 12 | import android.widget.ListView; |
13 | import android.widget.Toast; | 13 | import android.widget.Toast; |
14 | 14 | ||
15 | import com.hjx.personalcenter.R; | 15 | import com.hjx.personalcenter.R; |
16 | import com.hjx.personalcenter.db.SaveParam; | ||
16 | import com.mylhyl.circledialog.BaseCircleDialog; | 17 | import com.mylhyl.circledialog.BaseCircleDialog; |
17 | import com.mylhyl.circledialog.res.values.CircleDimen; | 18 | import com.mylhyl.circledialog.res.values.CircleDimen; |
18 | 19 | ||
19 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
20 | 21 | ||
21 | /**自定义年级列表对话框 | 22 | /**自定义年级列表对话框 |
22 | * Created by h on 2017/8/10. | 23 | * Created by h on 2017/8/10. |
23 | */ | 24 | */ |
24 | 25 | ||
25 | public class ProvinceListDialog extends BaseCircleDialog implements AdapterView.OnItemClickListener { | 26 | public class ProvinceListDialog extends BaseCircleDialog implements AdapterView.OnItemClickListener { |
26 | ArrayAdapter listadapter; | 27 | ArrayAdapter listadapter; |
27 | ListView listView; | 28 | ListView listView; |
28 | ArrayList<String> data = new ArrayList<>(); | 29 | ArrayList<String> data = new ArrayList<>(); |
29 | public static ProvinceListDialog getInstance() { | 30 | public static ProvinceListDialog getInstance() { |
30 | ProvinceListDialog dialogFragment = new ProvinceListDialog(); | 31 | ProvinceListDialog dialogFragment = new ProvinceListDialog(); |
31 | dialogFragment.setCanceledBack(true); | 32 | dialogFragment.setCanceledBack(true); |
32 | dialogFragment.setCanceledOnTouchOutside(true); | 33 | dialogFragment.setCanceledOnTouchOutside(true); |
33 | dialogFragment.setRadius(CircleDimen.RADIUS); | 34 | dialogFragment.setRadius(CircleDimen.RADIUS); |
34 | dialogFragment.setWidth(0.5f); | 35 | dialogFragment.setWidth(0.5f); |
35 | dialogFragment.setGravity(Gravity.CENTER); | 36 | dialogFragment.setGravity(Gravity.CENTER); |
36 | dialogFragment.setBackgroundColor(Color.WHITE); | 37 | dialogFragment.setBackgroundColor(Color.WHITE); |
37 | return dialogFragment; | 38 | return dialogFragment; |
38 | } | 39 | } |
39 | @Override | 40 | @Override |
40 | public View createView(Context context, LayoutInflater inflater, ViewGroup container) { | 41 | public View createView(Context context, LayoutInflater inflater, ViewGroup container) { |
41 | return inflater.inflate(R.layout.custom_adilog_provicelist, container, false); | 42 | return inflater.inflate(R.layout.custom_adilog_provicelist, container, false); |
42 | } | 43 | } |
43 | @Override | 44 | @Override |
44 | public void onActivityCreated(Bundle savedInstanceState) { | 45 | public void onActivityCreated(Bundle savedInstanceState) { |
45 | super.onActivityCreated(savedInstanceState); | 46 | super.onActivityCreated(savedInstanceState); |
46 | listView = (ListView) getView().findViewById(R.id.listadapter); | 47 | listView = (ListView) getView().findViewById(R.id.listadapter); |
47 | 48 | String ranging = SaveParam.getInstance().getCustomizeParam(getActivity(),SaveParam.PROVINCES); | |
48 | for (int i =0 ; i<50;i++){ | 49 | for (int i =0 ; i<ranging.split(",").length;i++){ |
49 | data.add("sss"+1); | 50 | data.add(i,ranging.replaceAll(",","省")); |
50 | 51 | ||
51 | } | 52 | } |
52 | 53 | ||
53 | listadapter = new ArrayAdapter(getActivity(),R.layout.custom_adilog_list_item,R.id.list_items,data); | 54 | listadapter = new ArrayAdapter(getActivity(),R.layout.custom_adilog_list_item,R.id.list_items,data); |
54 | listView.setAdapter(listadapter); | 55 | listView.setAdapter(listadapter); |
55 | listView.setOnItemClickListener(this); | 56 | listView.setOnItemClickListener(this); |
56 | 57 | ||
57 | } | 58 | } |
58 | 59 | ||
59 | @Override | 60 | @Override |
60 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | 61 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
61 | Toast.makeText(getActivity(),"你点击了第"+position+"个",Toast.LENGTH_LONG).show(); | 62 | Toast.makeText(getActivity(),"你点击了第"+position+"个",Toast.LENGTH_LONG).show(); |
62 | 63 | ||
63 | dismiss(); | 64 | dismiss(); |
64 | 65 | ||
65 | } | 66 | } |
66 | } | 67 | } |
67 | 68 |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/db/SaveParam.java
1 | package com.hjx.personalcenter.db; | 1 | package com.hjx.personalcenter.db; |
2 | 2 | ||
3 | import android.app.Activity; | 3 | import android.app.Activity; |
4 | import android.content.Context; | 4 | import android.content.Context; |
5 | import android.content.SharedPreferences; | 5 | import android.content.SharedPreferences; |
6 | 6 | ||
7 | public class SaveParam { | 7 | public class SaveParam { |
8 | 8 | ||
9 | private static SaveParam instance; | 9 | private static SaveParam instance; |
10 | public static SaveParam getInstance(){ | 10 | public static SaveParam getInstance(){ |
11 | if (instance==null){ | 11 | if (instance==null){ |
12 | instance = new SaveParam(); | 12 | instance = new SaveParam(); |
13 | } | 13 | } |
14 | return instance; | 14 | return instance; |
15 | } | 15 | } |
16 | public static String PROVINCES = "provinces";//省 | ||
17 | public static String OBJECTIVE = "objective"; | ||
16 | 18 | ||
17 | 19 | ||
18 | public void saveLoginParam(Context context,String spname, String spstr) { | 20 | public void saveLoginParam(Context context,String spname, String spstr) { |
19 | SharedPreferences sp = context.getSharedPreferences("loginparam", | 21 | SharedPreferences sp = context.getSharedPreferences("loginparam", |
20 | Activity.MODE_PRIVATE); | 22 | Activity.MODE_PRIVATE); |
21 | 23 | ||
22 | sp.edit().putString(spname, spstr).commit(); | 24 | sp.edit().putString(spname, spstr).commit(); |
23 | } | 25 | } |
24 | 26 | ||
25 | public String getLoginParam(Context context,String spname) { | 27 | public String getLoginParam(Context context,String spname) { |
26 | SharedPreferences sp = context.getSharedPreferences("loginparam", | 28 | SharedPreferences sp = context.getSharedPreferences("loginparam", |
27 | Activity.MODE_PRIVATE); | 29 | Activity.MODE_PRIVATE); |
28 | String param = sp.getString(spname, null); | 30 | String param = sp.getString(spname, null); |
29 | return param; | 31 | return param; |
30 | } | 32 | } |
31 | public void clearData(Context context) { | 33 | public void clearData(Context context) { |
32 | SharedPreferences sp = context.getSharedPreferences("loginparam", | 34 | SharedPreferences sp = context.getSharedPreferences("loginparam", |
33 | Activity.MODE_PRIVATE); | 35 | Activity.MODE_PRIVATE); |
34 | sp.edit().clear().commit(); | 36 | sp.edit().clear().commit(); |
35 | } | 37 | } |
36 | 38 | ||
37 | public void saveCustomizeParam(Context context,String spname, String spstr) { | 39 | public void saveCustomizeParam(Context context,String spname, String spstr) { |
38 | SharedPreferences sp = context.getSharedPreferences("presoninfo", | 40 | SharedPreferences sp = context.getSharedPreferences("presoninfo", |
39 | Activity.MODE_PRIVATE); | 41 | Activity.MODE_PRIVATE); |
40 | 42 | ||
41 | sp.edit().putString(spname, spstr).commit(); | 43 | sp.edit().putString(spname, spstr).commit(); |
42 | 44 | ||
43 | } | 45 | } |
44 | 46 | ||
45 | public String getCustomizeParam(Context context,String spname) { | 47 | public String getCustomizeParam(Context context,String spname) { |
46 | SharedPreferences sp = context.getSharedPreferences("presoninfo", | 48 | SharedPreferences sp = context.getSharedPreferences("presoninfo", |
47 | Activity.MODE_PRIVATE); | 49 | Activity.MODE_PRIVATE); |
48 | String param = sp.getString(spname, null); | 50 | String param = sp.getString(spname, null); |
49 | return param; | 51 | return param; |
50 | } | 52 | } |
51 | 53 | ||
52 | public void clearCustomizeParam(Context context ){ | 54 | public void clearCustomizeParam(Context context ){ |
53 | SharedPreferences sp = context.getSharedPreferences("presoninfo", | 55 | SharedPreferences sp = context.getSharedPreferences("presoninfo", |
54 | Activity.MODE_PRIVATE); | 56 | Activity.MODE_PRIVATE); |
55 | sp.edit().clear().commit(); | 57 | sp.edit().clear().commit(); |
56 | } | 58 | } |
57 | } | 59 | } |
58 | 60 |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/gson/GsonTool.java
File was created | 1 | package com.hjx.personalcenter.gson; | |
2 | |||
3 | import java.util.ArrayList; | ||
4 | import java.util.List; | ||
5 | |||
6 | import com.google.gson.Gson; | ||
7 | import com.google.gson.reflect.TypeToken; | ||
8 | |||
9 | public class GsonTool { | ||
10 | |||
11 | public GsonTool() { | ||
12 | // TODO Auto-generated constructor stub | ||
13 | } | ||
14 | |||
15 | //使用Gson进行解析Person | ||
16 | public static <T> T getPerson(String jsonString, Class<T> cls) { | ||
17 | T t = null; | ||
18 | try { | ||
19 | Gson gson = new Gson(); | ||
20 | t = gson.fromJson(jsonString, cls); | ||
21 | } catch (Exception e) { | ||
22 | // TODO: handle exception | ||
23 | } | ||
24 | return t; | ||
25 | } | ||
26 | |||
27 | |||
28 | // 使用Gson进行解析 List<Person> | ||
29 | public static <T> List<T> getPersons(String jsonString, Class<T> cls) { | ||
30 | List<T> list = new ArrayList<T>(); | ||
31 | try { | ||
32 | Gson gson = new Gson(); | ||
33 | list = gson.fromJson(jsonString, new TypeToken<List<T>>() { | ||
34 | }.getType()); | ||
35 | } catch (Exception e) { | ||
36 | } | ||
37 | return list; | ||
38 | } | ||
39 | |||
40 | } |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/http/HttpManager.java
1 | package com.hjx.personalcenter.http; | 1 | package com.hjx.personalcenter.http; |
2 | 2 | ||
3 | import android.app.Activity; | 3 | import android.app.Activity; |
4 | import android.app.ProgressDialog; | 4 | import android.app.ProgressDialog; |
5 | import android.content.Context; | 5 | import android.content.Context; |
6 | import android.content.Intent; | 6 | import android.content.Intent; |
7 | import android.os.Handler; | 7 | import android.os.Handler; |
8 | import android.os.Message; | 8 | import android.os.Message; |
9 | import android.util.Log; | 9 | import android.util.Log; |
10 | import android.widget.Toast; | 10 | import android.widget.Toast; |
11 | 11 | ||
12 | import com.google.gson.Gson; | 12 | import com.google.gson.Gson; |
13 | import com.hjx.personalcenter.activity.LoginAndRegisterActivity; | 13 | import com.hjx.personalcenter.activity.LoginAndRegisterActivity; |
14 | import com.hjx.personalcenter.db.SaveParam; | 14 | import com.hjx.personalcenter.db.SaveParam; |
15 | import com.hjx.personalcenter.gson.GsonTool; | ||
15 | import com.hjx.personalcenter.model.CityInfo; | 16 | import com.hjx.personalcenter.model.CityInfo; |
16 | import com.hjx.personalcenter.model.CountyInfo; | 17 | import com.hjx.personalcenter.model.CountyInfo; |
17 | import com.hjx.personalcenter.model.ProvinceInfo; | 18 | import com.hjx.personalcenter.model.ProvinceInfo; |
18 | import com.hjx.personalcenter.util.DialogPermission; | 19 | import com.hjx.personalcenter.util.DialogPermission; |
19 | import com.loopj.android.http.AsyncHttpResponseHandler; | 20 | import com.loopj.android.http.AsyncHttpResponseHandler; |
20 | import com.loopj.android.http.JsonHttpResponseHandler; | 21 | import com.loopj.android.http.JsonHttpResponseHandler; |
21 | import com.loopj.android.http.RequestParams; | 22 | import com.loopj.android.http.RequestParams; |
22 | 23 | ||
23 | import org.apache.http.Header; | 24 | import org.apache.http.Header; |
24 | import org.apache.http.entity.ByteArrayEntity; | 25 | import org.apache.http.entity.ByteArrayEntity; |
25 | import org.apache.http.message.BasicHeader; | 26 | import org.apache.http.message.BasicHeader; |
26 | import org.apache.http.protocol.HTTP; | 27 | import org.apache.http.protocol.HTTP; |
27 | import org.json.JSONException; | 28 | import org.json.JSONException; |
28 | import org.json.JSONObject; | 29 | import org.json.JSONObject; |
29 | 30 | ||
30 | import java.io.UnsupportedEncodingException; | 31 | import java.io.UnsupportedEncodingException; |
31 | 32 | ||
32 | public class HttpManager { | 33 | public class HttpManager { |
33 | private static HttpManager instance; | 34 | private static HttpManager instance; |
34 | private ProgressDialog mProgress = null; | 35 | private ProgressDialog mProgress = null; |
35 | public static HttpManager getInstance() { | 36 | public static HttpManager getInstance() { |
36 | if (instance == null) { | 37 | if (instance == null) { |
37 | instance = new HttpManager(); | 38 | instance = new HttpManager(); |
38 | } | 39 | } |
39 | return instance; | 40 | return instance; |
40 | } | 41 | } |
41 | 42 | ||
42 | 43 | ||
43 | //登录接口 | 44 | //登录接口 |
44 | 45 | ||
45 | public void login(final String username, final String password, final Context mContext) { | 46 | public void login(final String username, final String password, final Context mContext) { |
46 | mProgress = DialogPermission.showProgress(mContext, null, "正在登录...", | 47 | mProgress = DialogPermission.showProgress(mContext, null, "正在登录...", |
47 | false, true, null); | 48 | false, true, null); |
48 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); | 49 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); |
49 | HttpClient.getInstance().get(HttpUrl.loginUrl + "?username=" + username + "&password=" + password, new AsyncHttpResponseHandler() { | 50 | HttpClient.getInstance().get(HttpUrl.loginUrl + "?username=" + username + "&password=" + password, new AsyncHttpResponseHandler() { |
50 | @Override | 51 | @Override |
51 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { | 52 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { |
52 | 53 | ||
53 | String str = new String(arg2); | 54 | String str = new String(arg2); |
54 | JSONObject jsonObject = null; | 55 | JSONObject jsonObject = null; |
55 | try { | 56 | try { |
56 | jsonObject = new JSONObject(new String(arg2)); | 57 | jsonObject = new JSONObject(new String(arg2)); |
57 | String status = jsonObject.getString("status"); | 58 | String status = jsonObject.getString("status"); |
58 | if (status.equals("100")) { | 59 | if (status.equals("100")) { |
59 | String access_token = jsonObject.getString("access_token"); | 60 | String access_token = jsonObject.getString("access_token"); |
60 | String userId = jsonObject.getString("userId"); | 61 | String userId = jsonObject.getString("userId"); |
61 | // //登录成功,保存登录数据并且获取个人信息 | 62 | // //登录成功,保存登录数据并且获取个人信息 |
62 | saveLoginInfo(mContext,username, password, access_token, "true", userId); | 63 | saveLoginInfo(mContext,username, password, access_token, "true", userId); |
63 | //HttpManager.getInstance().getuserinfo(username,mContext); | 64 | //HttpManager.getInstance().getuserinfo(username,mContext); |
64 | 65 | ||
65 | }else if (status.equals("200")) { | 66 | }else if (status.equals("200")) { |
66 | closeProgress(); | 67 | closeProgress(); |
67 | Toast.makeText(mContext, "用户名不存在!", Toast.LENGTH_LONG).show(); | 68 | Toast.makeText(mContext, "用户名不存在!", Toast.LENGTH_LONG).show(); |
68 | return; | 69 | return; |
69 | } else if(status.equals("204")){ | 70 | } else if(status.equals("204")){ |
70 | closeProgress(); | 71 | closeProgress(); |
71 | Toast.makeText(mContext, "密码错误!", Toast.LENGTH_LONG).show(); | 72 | Toast.makeText(mContext, "密码错误!", Toast.LENGTH_LONG).show(); |
72 | }else{ | 73 | }else{ |
73 | closeProgress(); | 74 | closeProgress(); |
74 | Toast.makeText(mContext, "登录失败!请检查网络", Toast.LENGTH_LONG).show(); | 75 | Toast.makeText(mContext, "登录失败!请检查网络", Toast.LENGTH_LONG).show(); |
75 | 76 | ||
76 | 77 | ||
77 | 78 | ||
78 | } | 79 | } |
79 | } catch (JSONException e) { | 80 | } catch (JSONException e) { |
80 | e.printStackTrace(); | 81 | e.printStackTrace(); |
81 | } | 82 | } |
82 | 83 | ||
83 | 84 | ||
84 | } | 85 | } |
85 | 86 | ||
86 | @Override | 87 | @Override |
87 | public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { | 88 | public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { |
88 | closeProgress(); | 89 | closeProgress(); |
89 | Toast.makeText(mContext, "请检查网络。。"+arg3 , Toast.LENGTH_LONG).show(); | 90 | Toast.makeText(mContext, "请检查网络。。"+arg3 , Toast.LENGTH_LONG).show(); |
90 | } | 91 | } |
91 | }); | 92 | }); |
92 | } | 93 | } |
93 | 94 | ||
94 | //注册接口 | 95 | //注册接口 |
95 | public void register(final Context context, String username, String password, String smscode, String source, final Handler handler) { | 96 | public void register(final Context context, String username, String password, String smscode, String source, final Handler handler) { |
96 | mProgress = DialogPermission.showProgress(context, null, "正在注册...", | 97 | mProgress = DialogPermission.showProgress(context, null, "正在注册...", |
97 | false, true, null); | 98 | false, true, null); |
98 | JSONObject jsonObject = new JSONObject(); | 99 | JSONObject jsonObject = new JSONObject(); |
99 | ByteArrayEntity entity = null; | 100 | ByteArrayEntity entity = null; |
100 | try { | 101 | try { |
101 | jsonObject.put(HttpKey.USERNAME, username); | 102 | jsonObject.put(HttpKey.USERNAME, username); |
102 | jsonObject.put(HttpKey.PASSWORD, password); | 103 | jsonObject.put(HttpKey.PASSWORD, password); |
103 | jsonObject.put(HttpKey.SMSCODE, smscode); | 104 | jsonObject.put(HttpKey.SMSCODE, smscode); |
104 | jsonObject.put(HttpKey.SOURCE, source); | 105 | jsonObject.put(HttpKey.SOURCE, source); |
105 | Log.e("test", "jsonObject" + jsonObject); | 106 | Log.e("test", "jsonObject" + jsonObject); |
106 | entity = new ByteArrayEntity(jsonObject.toString().getBytes("UTF-8")); | 107 | entity = new ByteArrayEntity(jsonObject.toString().getBytes("UTF-8")); |
107 | entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); | 108 | entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); |
108 | } catch (JSONException e) { | 109 | } catch (JSONException e) { |
109 | e.printStackTrace(); | 110 | e.printStackTrace(); |
110 | } catch (UnsupportedEncodingException e) { | 111 | } catch (UnsupportedEncodingException e) { |
111 | e.printStackTrace(); | 112 | e.printStackTrace(); |
112 | } | 113 | } |
113 | HttpClient.getInstance().addHeader("Accept", "*/*"); | 114 | HttpClient.getInstance().addHeader("Accept", "*/*"); |
114 | HttpClient.getInstance().post(context, HttpUrl.registeredUrl, entity, "application/json", new JsonHttpResponseHandler() { | 115 | HttpClient.getInstance().post(context, HttpUrl.registeredUrl, entity, "application/json", new JsonHttpResponseHandler() { |
115 | @Override | 116 | @Override |
116 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { | 117 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { |
117 | super.onSuccess(statusCode, headers, response); | 118 | super.onSuccess(statusCode, headers, response); |
118 | closeProgress(); | 119 | closeProgress(); |
119 | Log.e("test", "onSuccess" + response); | 120 | Log.e("test", "onSuccess" + response); |
120 | Message msg = Message.obtain(); | 121 | Message msg = Message.obtain(); |
121 | msg.what = HttpCode.REGISTERED_SUCESS; | 122 | msg.what = HttpCode.REGISTERED_SUCESS; |
122 | msg.obj = response; | 123 | msg.obj = response; |
123 | handler.sendMessage(msg); | 124 | handler.sendMessage(msg); |
124 | 125 | ||
125 | } | 126 | } |
126 | 127 | ||
127 | @Override | 128 | @Override |
128 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { | 129 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { |
129 | super.onFailure(statusCode, headers, throwable, errorResponse); | 130 | super.onFailure(statusCode, headers, throwable, errorResponse); |
130 | closeProgress(); | 131 | closeProgress(); |
131 | Log.e("test", "onFailure" + errorResponse); | 132 | Log.e("test", "onFailure" + errorResponse); |
132 | Toast.makeText(context, "请检查网络。。", Toast.LENGTH_LONG).show(); | 133 | Toast.makeText(context, "请检查网络。。", Toast.LENGTH_LONG).show(); |
133 | } | 134 | } |
134 | 135 | ||
135 | }); | 136 | }); |
136 | } | 137 | } |
137 | 138 | ||
138 | //注册验证码 | 139 | //注册验证码 |
139 | public void authCode(final String type, final String mobile, final Handler handler, final Context mContext) { | 140 | public void authCode(final String type, final String mobile, final Handler handler, final Context mContext) { |
140 | RequestParams params = new RequestParams(); | 141 | RequestParams params = new RequestParams(); |
141 | params.put(HttpKey.TYPE, type); | 142 | params.put(HttpKey.TYPE, type); |
142 | params.put(HttpKey.MOBIL, mobile); | 143 | params.put(HttpKey.MOBIL, mobile); |
143 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); | 144 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); |
144 | HttpClient.getInstance().post(HttpUrl.authCodedUrl, params, new JsonHttpResponseHandler() { | 145 | HttpClient.getInstance().post(HttpUrl.authCodedUrl, params, new JsonHttpResponseHandler() { |
145 | 146 | ||
146 | @Override | 147 | @Override |
147 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { | 148 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { |
148 | Log.e("test", "onSuccess-----" + response); | 149 | Log.e("test", "onSuccess-----" + response); |
149 | Message msg = Message.obtain(); | 150 | Message msg = Message.obtain(); |
150 | msg.what = HttpCode.AUTHCODE_SUCESS; | 151 | msg.what = HttpCode.AUTHCODE_SUCESS; |
151 | msg.obj = response; | 152 | msg.obj = response; |
152 | handler.sendMessage(msg); | 153 | handler.sendMessage(msg); |
153 | } | 154 | } |
154 | 155 | ||
155 | @Override | 156 | @Override |
156 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { | 157 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { |
157 | Toast.makeText(mContext, "请检查网络。。" + errorResponse, Toast.LENGTH_LONG).show(); | 158 | Toast.makeText(mContext, "请检查网络。。" + errorResponse, Toast.LENGTH_LONG).show(); |
158 | } | 159 | } |
159 | }); | 160 | }); |
160 | } | 161 | } |
161 | 162 | ||
162 | //验证码 | 163 | //验证码 |
163 | public void forgetauthCode(final String type, final String mobile, final Handler handler, final Context mContext) { | 164 | public void forgetauthCode(final String type, final String mobile, final Handler handler, final Context mContext) { |
164 | RequestParams params = new RequestParams(); | 165 | RequestParams params = new RequestParams(); |
165 | params.put("type", type); | 166 | params.put("type", type); |
166 | params.put("mobile", mobile); | 167 | params.put("mobile", mobile); |
167 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); | 168 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); |
168 | HttpClient.getInstance().post(HttpUrl.authCodedUrl, params, new JsonHttpResponseHandler() { | 169 | HttpClient.getInstance().post(HttpUrl.authCodedUrl, params, new JsonHttpResponseHandler() { |
169 | 170 | ||
170 | @Override | 171 | @Override |
171 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { | 172 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { |
172 | Log.e("test", "onSuccess-----" + response); | 173 | Log.e("test", "onSuccess-----" + response); |
173 | Message msg = Message.obtain(); | 174 | Message msg = Message.obtain(); |
174 | msg.what = HttpCode.AUTHCODE_SUCESS1; | 175 | msg.what = HttpCode.AUTHCODE_SUCESS1; |
175 | msg.obj = response; | 176 | msg.obj = response; |
176 | handler.sendMessage(msg); | 177 | handler.sendMessage(msg); |
177 | } | 178 | } |
178 | 179 | ||
179 | @Override | 180 | @Override |
180 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { | 181 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { |
181 | Toast.makeText(mContext, "请检查网络。。" + errorResponse, Toast.LENGTH_LONG).show(); | 182 | Toast.makeText(mContext, "请检查网络。。" + errorResponse, Toast.LENGTH_LONG).show(); |
182 | } | 183 | } |
183 | }); | 184 | }); |
184 | } | 185 | } |
185 | 186 | ||
186 | //手机号是否注册 | 187 | //手机号是否注册 |
187 | public void isregistered(final String mobile, final Handler handler, final Context mContext) { | 188 | public void isregistered(final String mobile, final Handler handler, final Context mContext) { |
188 | RequestParams params = new RequestParams(); | 189 | RequestParams params = new RequestParams(); |
189 | params.put(HttpKey.USERNAME, mobile); | 190 | params.put(HttpKey.USERNAME, mobile); |
190 | HttpClient.getInstance().get(HttpUrl.isRegiterUrl + "?mobile=" + mobile, new JsonHttpResponseHandler() { | 191 | HttpClient.getInstance().get(HttpUrl.isRegiterUrl + "?mobile=" + mobile, new JsonHttpResponseHandler() { |
191 | @Override | 192 | @Override |
192 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { | 193 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { |
193 | Log.e("test", "isregistered" + response.toString()); | 194 | Log.e("test", "isregistered" + response.toString()); |
194 | Message msg = Message.obtain(); | 195 | Message msg = Message.obtain(); |
195 | msg.what = HttpCode.IS_REFISTER; | 196 | msg.what = HttpCode.IS_REFISTER; |
196 | msg.obj = response; | 197 | msg.obj = response; |
197 | handler.sendMessage(msg); | 198 | handler.sendMessage(msg); |
198 | 199 | ||
199 | } | 200 | } |
200 | 201 | ||
201 | @Override | 202 | @Override |
202 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { | 203 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { |
203 | Toast.makeText(mContext, "失敗" + errorResponse, Toast.LENGTH_LONG).show(); | 204 | Toast.makeText(mContext, "失敗" + errorResponse, Toast.LENGTH_LONG).show(); |
204 | 205 | ||
205 | } | 206 | } |
206 | }); | 207 | }); |
207 | } | 208 | } |
208 | 209 | ||
209 | //修改密码 | 210 | //修改密码 |
210 | public void changepwd(final Context context, String username, String old_pwd1, String newpassword3) { | 211 | public void changepwd(final Context context, String username, String old_pwd1, String newpassword3) { |
211 | RequestParams params = new RequestParams(); | 212 | RequestParams params = new RequestParams(); |
212 | params.put(HttpKey.USERNAME, username); | 213 | params.put(HttpKey.USERNAME, username); |
213 | params.put(HttpKey.OLDPASS, old_pwd1); | 214 | params.put(HttpKey.OLDPASS, old_pwd1); |
214 | params.put(HttpKey.NEWPASS, newpassword3); | 215 | params.put(HttpKey.NEWPASS, newpassword3); |
215 | HttpClient.getInstance().addHeader("Accept", "*/*"); | 216 | HttpClient.getInstance().addHeader("Accept", "*/*"); |
216 | HttpClient.getInstance().setTimeout(10 * 1000); | 217 | HttpClient.getInstance().setTimeout(10 * 1000); |
217 | HttpClient.getInstance().post(HttpUrl.changepassword, params, new AsyncHttpResponseHandler() { | 218 | HttpClient.getInstance().post(HttpUrl.changepassword, params, new AsyncHttpResponseHandler() { |
218 | @Override | 219 | @Override |
219 | public void onSuccess(int i, Header[] headers, byte[] bytes) { | 220 | public void onSuccess(int i, Header[] headers, byte[] bytes) { |
220 | try { | 221 | try { |
221 | JSONObject jsonObject = new JSONObject(new String(bytes)); | 222 | JSONObject jsonObject = new JSONObject(new String(bytes)); |
222 | String status = jsonObject.optString("status"); | 223 | String status = jsonObject.optString("status"); |
223 | if (status.equals("100")) { | 224 | if (status.equals("100")) { |
224 | Log.e("test", "onSuccess" + new String(bytes)); | 225 | Log.e("test", "onSuccess" + new String(bytes)); |
225 | Toast.makeText(context, "密码修改成功!", Toast.LENGTH_LONG).show(); | 226 | Toast.makeText(context, "密码修改成功!", Toast.LENGTH_LONG).show(); |
226 | SaveParam.getInstance().clearData((Activity) context); | 227 | SaveParam.getInstance().clearData((Activity) context); |
227 | Intent intent = new Intent(); | 228 | Intent intent = new Intent(); |
228 | intent.setClass(context, LoginAndRegisterActivity.class); | 229 | intent.setClass(context, LoginAndRegisterActivity.class); |
229 | ((Activity) context).startActivity(intent); | 230 | ((Activity) context).startActivity(intent); |
230 | ((Activity) context).finish(); | 231 | ((Activity) context).finish(); |
231 | } | 232 | } |
232 | } catch (JSONException e) { | 233 | } catch (JSONException e) { |
233 | e.printStackTrace(); | 234 | e.printStackTrace(); |
234 | } | 235 | } |
235 | } | 236 | } |
236 | 237 | ||
237 | @Override | 238 | @Override |
238 | public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { | 239 | public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { |
239 | Log.e("test", "onFailure" + new String(bytes)); | 240 | Log.e("test", "onFailure" + new String(bytes)); |
240 | Toast.makeText(context, "密码修改失败,请检查网络!", Toast.LENGTH_LONG).show(); | 241 | Toast.makeText(context, "密码修改失败,请检查网络!", Toast.LENGTH_LONG).show(); |
241 | onFinish(); | 242 | onFinish(); |
242 | } | 243 | } |
243 | }); | 244 | }); |
244 | 245 | ||
245 | } | 246 | } |
246 | 247 | ||
247 | //忘记密码 | 248 | //忘记密码 |
248 | public void forgetpassword(final Context context, String forot_pwd_phone1, String forot_pwd_pwd3, String forot_pwd_anthcode1, Handler handler) { | 249 | public void forgetpassword(final Context context, String forot_pwd_phone1, String forot_pwd_pwd3, String forot_pwd_anthcode1, Handler handler) { |
249 | RequestParams params = new RequestParams(); | 250 | RequestParams params = new RequestParams(); |
250 | params.put(HttpKey.USERNAME, forot_pwd_phone1); | 251 | params.put(HttpKey.USERNAME, forot_pwd_phone1); |
251 | params.put(HttpKey.PASSWORD, forot_pwd_pwd3); | 252 | params.put(HttpKey.PASSWORD, forot_pwd_pwd3); |
252 | params.put(HttpKey.AUTHCODE, forot_pwd_anthcode1); | 253 | params.put(HttpKey.AUTHCODE, forot_pwd_anthcode1); |
253 | HttpClient.getInstance().addHeader("Accept", "*/*"); | 254 | HttpClient.getInstance().addHeader("Accept", "*/*"); |
254 | HttpClient.getInstance().post(HttpUrl.forgetpassword, params, new AsyncHttpResponseHandler() { | 255 | HttpClient.getInstance().post(HttpUrl.forgetpassword, params, new AsyncHttpResponseHandler() { |
255 | @Override | 256 | @Override |
256 | public void onSuccess(int i, Header[] headers, byte[] bytes) { | 257 | public void onSuccess(int i, Header[] headers, byte[] bytes) { |
257 | try { | 258 | try { |
258 | JSONObject jsonObject = new JSONObject(new String(bytes)); | 259 | JSONObject jsonObject = new JSONObject(new String(bytes)); |
259 | String status = jsonObject.optString("status"); | 260 | String status = jsonObject.optString("status"); |
260 | if (status.equals("100")) { | 261 | if (status.equals("100")) { |
261 | Log.e("test", "onSuccess" + new String(bytes)); | 262 | Log.e("test", "onSuccess" + new String(bytes)); |
262 | Toast.makeText(context, "密码修改成功!", Toast.LENGTH_LONG).show(); | 263 | Toast.makeText(context, "密码修改成功!", Toast.LENGTH_LONG).show(); |
263 | ((Activity) context).finish(); | 264 | ((Activity) context).finish(); |
264 | } | 265 | } |
265 | } catch (JSONException e) { | 266 | } catch (JSONException e) { |
266 | e.printStackTrace(); | 267 | e.printStackTrace(); |
267 | } | 268 | } |
268 | } | 269 | } |
269 | 270 | ||
270 | @Override | 271 | @Override |
271 | public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { | 272 | public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { |
272 | Log.e("test", "onFailure" + new String(bytes)); | 273 | Log.e("test", "onFailure" + new String(bytes)); |
273 | Toast.makeText(context, "忘记密码修改失败,请检查网络!", Toast.LENGTH_LONG).show(); | 274 | Toast.makeText(context, "忘记密码修改失败,请检查网络!", Toast.LENGTH_LONG).show(); |
274 | } | 275 | } |
275 | }); | 276 | }); |
276 | 277 | ||
277 | } | 278 | } |
278 | 279 | ||
279 | //保存用户登录信息 | 280 | //保存用户登录信息 |
280 | public void saveLoginInfo(Context context,String username, String password, String access_token, String loginStatus, String userId) { | 281 | public void saveLoginInfo(Context context,String username, String password, String access_token, String loginStatus, String userId) { |
281 | SaveParam.getInstance().saveLoginParam(context,"username", username); | 282 | SaveParam.getInstance().saveLoginParam(context,"username", username); |
282 | SaveParam.getInstance().saveLoginParam(context,"password", password); | 283 | SaveParam.getInstance().saveLoginParam(context,"password", password); |
283 | SaveParam.getInstance().saveLoginParam(context,"access_token", access_token); | 284 | SaveParam.getInstance().saveLoginParam(context,"access_token", access_token); |
284 | SaveParam.getInstance().saveLoginParam(context,"login", loginStatus); | 285 | SaveParam.getInstance().saveLoginParam(context,"login", loginStatus); |
285 | SaveParam.getInstance().saveLoginParam(context,"userId", userId); | 286 | SaveParam.getInstance().saveLoginParam(context,"userId", userId); |
286 | 287 | ||
287 | 288 | ||
288 | } | 289 | } |
289 | 290 | ||
290 | //保存用户个人信息 | 291 | //保存用户个人信息 |
291 | public void savePresonInfo(Context context,String lastname, String gender, String mobilePortrait) { | 292 | public void savePresonInfo(Context context,String lastname, String gender, String mobilePortrait) { |
292 | SaveParam.getInstance().saveLoginParam(context,"lastname", lastname); | 293 | SaveParam.getInstance().saveLoginParam(context,"lastname", lastname); |
293 | SaveParam.getInstance().saveLoginParam(context,"gender", gender); | 294 | SaveParam.getInstance().saveLoginParam(context,"gender", gender); |
294 | SaveParam.getInstance().saveLoginParam(context,"mobilePortrait", mobilePortrait); | 295 | SaveParam.getInstance().saveLoginParam(context,"mobilePortrait", mobilePortrait); |
295 | } | 296 | } |
296 | ///省级接口 | 297 | ///省级接口 |
297 | public void provices(final Context mContext) { | 298 | public void provices(final Context mContext) { |
298 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); | 299 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); |
299 | HttpClient.getInstance().get(HttpUrl.provinceUrl, new AsyncHttpResponseHandler() { | 300 | HttpClient.getInstance().get(HttpUrl.provinceUrl, new AsyncHttpResponseHandler() { |
300 | @Override | 301 | @Override |
301 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { | 302 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { |
302 | Log.e("test", "省" + new String(arg2)); | 303 | Log.e("test", "省" + new String(arg2)); |
303 | Gson gson = new Gson(); | 304 | ProvinceInfo provinceInfo = GsonTool.getPerson(new String(arg2), ProvinceInfo.class);//解析json数据 |
304 | ProvinceInfo provinceInfo = gson.fromJson(new String(arg2),ProvinceInfo.class); | 305 | Log.e("test", "状态码" +provinceInfo.getStatus()); |
306 | StringBuffer sb = new StringBuffer(); | ||
305 | for (int i =0 ; i<provinceInfo.getProvinces().size();i++){ | 307 | for (int i =0 ; i<provinceInfo.getProvinces().size();i++){ |
306 | Log.e("test", "省" +provinceInfo.getProvinces().get(i) | 308 | Log.e("test", "省" +provinceInfo.getProvinces().get(i) |
307 | .getParentId()); | 309 | .getParentId()); |
308 | Log.e("test", "省" +provinceInfo.getProvinces().get(i) | 310 | Log.e("test", "省" +provinceInfo.getProvinces().get(i) |
309 | .getRegionId()); | 311 | .getRegionId()); |
310 | Log.e("test", "省" +provinceInfo.getProvinces().get(i).getRegionName()+""); | 312 | Log.e("test", "省" +provinceInfo.getProvinces().get(i).getRegionName()); |
313 | sb.append(provinceInfo.getProvinces().get(i).getRegionName()+","); | ||
311 | 314 | ||
312 | } | 315 | } |
316 | Log.e("test", "省" +sb.toString()); | ||
317 | SaveParam.getInstance().saveCustomizeParam(mContext,SaveParam.PROVINCES, "" + sb.toString()); | ||
313 | 318 | ||
314 | 319 | ||
315 | } | 320 | } |
316 | 321 | ||
317 | @Override | 322 | @Override |
318 | public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { | 323 | public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { |
319 | Toast.makeText(mContext, "请检查网络。。"+arg3 , Toast.LENGTH_LONG).show(); | 324 | Toast.makeText(mContext, "请检查网络。。"+arg3 , Toast.LENGTH_LONG).show(); |
320 | } | 325 | } |
321 | }); | 326 | }); |
322 | } | 327 | } |
323 | //市级接口 | 328 | //市级接口 |
324 | public void cityinfo(final Context mContext,int regionId) { | 329 | public void cityinfo(final Context mContext,int regionId) { |
325 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); | 330 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); |
326 | HttpClient.getInstance().get(HttpUrl.cityUrl + "?regionId=" + regionId, new AsyncHttpResponseHandler() { | 331 | HttpClient.getInstance().get(HttpUrl.cityUrl + "?regionId=" + regionId, new AsyncHttpResponseHandler() { |
327 | @Override | 332 | @Override |
328 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { | 333 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { |
329 | Log.e("test", "市" + new String(arg2)); | 334 | Log.e("test", "市" + new String(arg2)); |
330 | Gson gson = new Gson(); | 335 | Gson gson = new Gson(); |
331 | CityInfo cityInfo = gson.fromJson(new String(arg2),CityInfo.class); | 336 | CityInfo cityInfo = gson.fromJson(new String(arg2),CityInfo.class); |
332 | for (int i =0 ; i<cityInfo.getCities().size();i++){ | 337 | for (int i =0 ; i<cityInfo.getCities().size();i++){ |
333 | Log.e("test", "市" +cityInfo.getCities().get(i) | 338 | Log.e("test", "市" +cityInfo.getCities().get(i) |
334 | .getParentId()); | 339 | .getParentId()); |
335 | Log.e("test", "市" +cityInfo.getCities().get(i) | 340 | Log.e("test", "市" +cityInfo.getCities().get(i) |
336 | .getRegionId()); | 341 | .getRegionId()); |
337 | Log.e("test", "市" +cityInfo.getCities().get(i).getRegionName()+""); | 342 | Log.e("test", "市" +cityInfo.getCities().get(i).getRegionName()+""); |
338 | 343 | ||
339 | } | 344 | } |
340 | 345 | ||
341 | 346 | ||
342 | } | 347 | } |
343 | 348 | ||
344 | @Override | 349 | @Override |
345 | public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { | 350 | public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { |
346 | Toast.makeText(mContext, "请检查网络。。"+arg3 , Toast.LENGTH_LONG).show(); | 351 | Toast.makeText(mContext, "请检查网络。。"+arg3 , Toast.LENGTH_LONG).show(); |
347 | } | 352 | } |
348 | }); | 353 | }); |
349 | } | 354 | } |
350 | //区县级接口 | 355 | //区县级接口 |
351 | public void countyinfo(final Context mContext,int parentId) { | 356 | public void countyinfo(final Context mContext,int parentId) { |
352 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); | 357 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); |
353 | HttpClient.getInstance().get(HttpUrl.countyUrl + "?regionId=" + parentId, new AsyncHttpResponseHandler() { | 358 | HttpClient.getInstance().get(HttpUrl.countyUrl + "?regionId=" + parentId, new AsyncHttpResponseHandler() { |
354 | @Override | 359 | @Override |
355 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { | 360 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { |
356 | Log.e("test", "区" + new String(arg2)); | 361 | Log.e("test", "区" + new String(arg2)); |
357 | Gson gson = new Gson(); | 362 | Gson gson = new Gson(); |
358 | CountyInfo countyInfo = gson.fromJson(new String(arg2),CountyInfo.class); | 363 | CountyInfo countyInfo = gson.fromJson(new String(arg2),CountyInfo.class); |
359 | for (int i =0 ; i<countyInfo.getCounties().size();i++){ | 364 | for (int i =0 ; i<countyInfo.getCounties().size();i++){ |
360 | Log.e("test", "区" +countyInfo.getCounties().get(i) | 365 | Log.e("test", "区" +countyInfo.getCounties().get(i) |
361 | .getParentId()); | 366 | .getParentId()); |
362 | Log.e("test", "区" +countyInfo.getCounties().get(i) | 367 | Log.e("test", "区" +countyInfo.getCounties().get(i) |
363 | .getRegionId()); | 368 | .getRegionId()); |
364 | Log.e("test", "区" +countyInfo.getCounties().get(i).getRegionName()+""); | 369 | Log.e("test", "区" +countyInfo.getCounties().get(i).getRegionName()+""); |
365 | 370 | ||
366 | } | 371 | } |
367 | 372 | ||
368 | 373 | ||
369 | } | 374 | } |
370 | 375 | ||
371 | @Override | 376 | @Override |
372 | public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { | 377 | public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { |
373 | Toast.makeText(mContext, "请检查网络。。"+arg3 , Toast.LENGTH_LONG).show(); | 378 | Toast.makeText(mContext, "请检查网络。。"+arg3 , Toast.LENGTH_LONG).show(); |
374 | } | 379 | } |
375 | }); | 380 | }); |
376 | } | 381 | } |
377 | 382 | ||
378 | 383 | ||
379 | private void closeProgress() { | 384 | private void closeProgress() { |
380 | try { | 385 | try { |
381 | if (mProgress != null) { | 386 | if (mProgress != null) { |
382 | mProgress.dismiss(); | 387 | mProgress.dismiss(); |
383 | mProgress = null; | 388 | mProgress = null; |
384 | } | 389 | } |
385 | } catch (Exception e) { | 390 | } catch (Exception e) { |
386 | e.printStackTrace(); | 391 | e.printStackTrace(); |
387 | } | 392 | } |
388 | } | 393 | } |
389 | 394 | ||
390 | } | 395 | } |
391 | 396 |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/model/ProvinceInfo.java
1 | package com.hjx.personalcenter.model; | 1 | package com.hjx.personalcenter.model; |
2 | 2 | ||
3 | import java.io.Serializable; | ||
3 | import java.util.List; | 4 | import java.util.List; |
4 | 5 | ||
5 | /** | 6 | /** |
6 | * Created by h on 2017/8/16. | 7 | * Created by h on 2017/8/16. |
7 | */ | 8 | */ |
8 | 9 | ||
9 | public class ProvinceInfo { | 10 | public class ProvinceInfo implements Serializable{ |
10 | 11 | ||
11 | /** | 12 | /** |
12 | * status : 100 | 13 | * status : 100 |
13 | * message : success | 14 | * message : success |
14 | * provinces : [{"parentId":0,"regionId":110000,"regionName":"北京"},{"parentId":0,"regionId":120000,"regionName":"天津"},{"parentId":0,"regionId":130000,"regionName":"河北"},{"parentId":0,"regionId":140000,"regionName":"山西"},{"parentId":0,"regionId":150000,"regionName":"内蒙古"},{"parentId":0,"regionId":210000,"regionName":"辽宁"},{"parentId":0,"regionId":220000,"regionName":"吉林"},{"parentId":0,"regionId":230000,"regionName":"黑龙江"},{"parentId":0,"regionId":310000,"regionName":"上海"},{"parentId":0,"regionId":320000,"regionName":"江苏"},{"parentId":0,"regionId":330000,"regionName":"浙江"},{"parentId":0,"regionId":340000,"regionName":"安徽"},{"parentId":0,"regionId":350000,"regionName":"福建"},{"parentId":0,"regionId":360000,"regionName":"江西"},{"parentId":0,"regionId":370000,"regionName":"山东"},{"parentId":0,"regionId":410000,"regionName":"河南"},{"parentId":0,"regionId":420000,"regionName":"湖北"},{"parentId":0,"regionId":430000,"regionName":"湖南"},{"parentId":0,"regionId":440000,"regionName":"广东"},{"parentId":0,"regionId":450000,"regionName":"广西"},{"parentId":0,"regionId":460000,"regionName":"海南"},{"parentId":0,"regionId":500000,"regionName":"重庆"},{"parentId":0,"regionId":510000,"regionName":"四川"},{"parentId":0,"regionId":520000,"regionName":"贵州"},{"parentId":0,"regionId":530000,"regionName":"云南"},{"parentId":0,"regionId":540000,"regionName":"西藏"},{"parentId":0,"regionId":610000,"regionName":"陕西"},{"parentId":0,"regionId":620000,"regionName":"甘肃"},{"parentId":0,"regionId":630000,"regionName":"青海"},{"parentId":0,"regionId":640000,"regionName":"宁夏"},{"parentId":0,"regionId":650000,"regionName":"新疆"},{"parentId":0,"regionId":710000,"regionName":"台湾"},{"parentId":0,"regionId":810000,"regionName":"香港"},{"parentId":0,"regionId":820000,"regionName":"澳门"}] | 15 | * provinces : [{"parentId":0,"regionId":110000,"regionName":"北京"},{"parentId":0,"regionId":120000,"regionName":"天津"},{"parentId":0,"regionId":130000,"regionName":"河北"},{"parentId":0,"regionId":140000,"regionName":"山西"},{"parentId":0,"regionId":150000,"regionName":"内蒙古"},{"parentId":0,"regionId":210000,"regionName":"辽宁"},{"parentId":0,"regionId":220000,"regionName":"吉林"},{"parentId":0,"regionId":230000,"regionName":"黑龙江"},{"parentId":0,"regionId":310000,"regionName":"上海"},{"parentId":0,"regionId":320000,"regionName":"江苏"},{"parentId":0,"regionId":330000,"regionName":"浙江"},{"parentId":0,"regionId":340000,"regionName":"安徽"},{"parentId":0,"regionId":350000,"regionName":"福建"},{"parentId":0,"regionId":360000,"regionName":"江西"},{"parentId":0,"regionId":370000,"regionName":"山东"},{"parentId":0,"regionId":410000,"regionName":"河南"},{"parentId":0,"regionId":420000,"regionName":"湖北"},{"parentId":0,"regionId":430000,"regionName":"湖南"},{"parentId":0,"regionId":440000,"regionName":"广东"},{"parentId":0,"regionId":450000,"regionName":"广西"},{"parentId":0,"regionId":460000,"regionName":"海南"},{"parentId":0,"regionId":500000,"regionName":"重庆"},{"parentId":0,"regionId":510000,"regionName":"四川"},{"parentId":0,"regionId":520000,"regionName":"贵州"},{"parentId":0,"regionId":530000,"regionName":"云南"},{"parentId":0,"regionId":540000,"regionName":"西藏"},{"parentId":0,"regionId":610000,"regionName":"陕西"},{"parentId":0,"regionId":620000,"regionName":"甘肃"},{"parentId":0,"regionId":630000,"regionName":"青海"},{"parentId":0,"regionId":640000,"regionName":"宁夏"},{"parentId":0,"regionId":650000,"regionName":"新疆"},{"parentId":0,"regionId":710000,"regionName":"台湾"},{"parentId":0,"regionId":810000,"regionName":"香港"},{"parentId":0,"regionId":820000,"regionName":"澳门"}] |
15 | */ | 16 | */ |
16 | 17 | ||
17 | private int status; | 18 | private int status; |
18 | private String message; | 19 | private String message; |
19 | private List<ProvincesBean> provinces; | 20 | private List<ProvincesBean> provinces; |
20 | 21 | ||
21 | public int getStatus() { | 22 | public int getStatus() { |
22 | return status; | 23 | return status; |
23 | } | 24 | } |
24 | 25 | ||
25 | public void setStatus(int status) { | 26 | public void setStatus(int status) { |
26 | this.status = status; | 27 | this.status = status; |
27 | } | 28 | } |
28 | 29 | ||
29 | public String getMessage() { | 30 | public String getMessage() { |
30 | return message; | 31 | return message; |
31 | } | 32 | } |
32 | 33 | ||
33 | public void setMessage(String message) { | 34 | public void setMessage(String message) { |
34 | this.message = message; | 35 | this.message = message; |
35 | } | 36 | } |
36 | 37 | ||
37 | public List<ProvincesBean> getProvinces() { | 38 | public List<ProvincesBean> getProvinces() { |
38 | return provinces; | 39 | return provinces; |
39 | } | 40 | } |
40 | 41 | ||
41 | public void setProvinces(List<ProvincesBean> provinces) { | 42 | public void setProvinces(List<ProvincesBean> provinces) { |
42 | this.provinces = provinces; | 43 | this.provinces = provinces; |
43 | } | 44 | } |
44 | 45 | ||
45 | public static class ProvincesBean { | 46 | public static class ProvincesBean { |
46 | /** | 47 | /** |
47 | * parentId : 0 | 48 | * parentId : 0 |
48 | * regionId : 110000 | 49 | * regionId : 110000 |
49 | * regionName : 北京 | 50 | * regionName : 北京 |
50 | */ | 51 | */ |
51 | 52 | ||
52 | private int parentId; | 53 | private int parentId; |
53 | private int regionId; | 54 | private int regionId; |
54 | private String regionName; | 55 | private String regionName; |
55 | 56 | ||
56 | public int getParentId() { | 57 | public int getParentId() { |
57 | return parentId; | 58 | return parentId; |
58 | } | 59 | } |
59 | 60 | ||
60 | public void setParentId(int parentId) { | 61 | public void setParentId(int parentId) { |
61 | this.parentId = parentId; | 62 | this.parentId = parentId; |
62 | } | 63 | } |
63 | 64 | ||
64 | public int getRegionId() { | 65 | public int getRegionId() { |
65 | return regionId; | 66 | return regionId; |
66 | } | 67 | } |
67 | 68 | ||
68 | public void setRegionId(int regionId) { | 69 | public void setRegionId(int regionId) { |
69 | this.regionId = regionId; | 70 | this.regionId = regionId; |
70 | } | 71 | } |
71 | 72 | ||
72 | public String getRegionName() { | 73 | public String getRegionName() { |
73 | return regionName; | 74 | return regionName; |
74 | } | 75 | } |
75 | 76 | ||
76 | public void setRegionName(String regionName) { | 77 | public void setRegionName(String regionName) { |
77 | this.regionName = regionName; | 78 | this.regionName = regionName; |
78 | } | 79 | } |
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 |
PersonalCenter/build.gradle
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. | 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. |
2 | 2 | ||
3 | buildscript { | 3 | buildscript { |
4 | repositories { | 4 | repositories { |
5 | jcenter() | 5 | jcenter() |
6 | } | 6 | } |
7 | dependencies { | 7 | dependencies { |
8 | classpath 'com.android.tools.build:gradle:2.2.2' | 8 | classpath 'com.android.tools.build:gradle:2.2.3' |
9 | 9 | ||
10 | // NOTE: Do not place your application dependencies here; they belong | 10 | // NOTE: Do not place your application dependencies here; they belong |
11 | // in the individual module build.gradle files | 11 | // in the individual module build.gradle files |
12 | classpath 'com.novoda:bintray-release:0.3.4' | 12 | classpath 'com.novoda:bintray-release:0.3.4' |
13 | } | 13 | } |
14 | } | 14 | } |
15 | 15 | ||
16 | allprojects { | 16 | allprojects { |
17 | repositories { | 17 | repositories { |
18 | jcenter() | 18 | jcenter() |
19 | } | 19 | } |
20 | } | 20 | } |
21 | 21 | ||
22 | task clean(type: Delete) { | 22 | task clean(type: Delete) { |
23 | delete rootProject.buildDir | 23 | delete rootProject.buildDir |
24 | } | 24 | } |
25 | 25 |