差點嚇死我了,好不容易寫的博客沒有了,還好有自動保存功能,不然我真的是嗚嗚。。。
---恢復內容開始---
開學一個月了,終於可以看見自己的作品雛形了。
從一個小白到現在半年了,覺得日子過得比較充實,回頭看看滿是值得紀念的。大一的時候覺得大學就是一個讓人會變的頹廢的地方,除了睡覺恐怕都是在扣手機。很幸運的是我,在辦公室值班得到了加入工作室一起學習的機會。雖然剛開始入門的時候就像是一只無頭蒼蠅一樣亂撞。沒有任何的方向,雖然看似是在學習,但是卻沒有做出來任何的東西。一個學期過去了,除了會做一些簡單的頁面之外,連一個登錄的功能都沒有實現。曾經想過要放棄,覺得自己可能不是一個編程的料。但是一想到機會失去了就恐怕再也找不到這樣的優越的條件了。暑假就又重新把Android的基礎視頻又看了一遍,重新穩固了老師說的知識點,發現了以前沒有注意到的細節。雖然看視頻可能是一件浪費時間的學習途徑。但是我覺得這個途徑還是很有效的,因為除了可以獲得課本知識以外還可以聽一些課本上沒有講到過得東西。暑假的時候一次偶然的機會,在寫博客的時候,收到了一個消息。讓加入一個IT交流群,抱着試試的態度可以認識到幾個大神的心態加入了其中,也許真的是太幸運了。真的讓我遇到了這樣的幾個人。雖然不是Android開發,但是在他們的幫助下,覺得IT的大門一點點向我打開了。一個暑假讓我覺得自己成長了,以前是一遇到問題就去找別人解決,現在終於可以自己學會試着解決一些問題了。我把這個群分享給大家,期待可以有更多的人從中受益。
順便分享一點我在群里面的心得,如果你是一個女生就換一個比較女生化點的頭像,這樣的話你會發現會有很多人主動跟你解決問題的。這群里面的群主是特別厲害的任務之一,基本上我遇到問題在他的指點就會迎刃而解的。現在的我已經打算加入到這個神奇的行業當中了。
2016年還有兩個月就要結束了,我想我的那個目標可以快實現了。我要加油!
不說了,開始粘代碼嘍:布局文件我就不粘了,實在是太多了。我相信你們一定看着界面會做出來的。
這個類我就不粘代碼了,設計一些信息,就截圖了,相信你能看的懂。
package cn.edu.aynu.rjxy.activity; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.TextView; public class HomeActivity extends Activity { private GridView gv_Home; private String[] settingText = {"全部題目","我的選題","個人信息","修改密碼"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); gv_Home = (GridView) findViewById(R.id.gv_icons); gv_Home.setAdapter(new MyAdapter()); gv_Home.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { System.out.println(position); switch (position) { case 0: //查看全部題目 Intent intent = new Intent(HomeActivity.this,SetlectActivity.class); startActivity(intent); break; case 1: //我的選題 Intent intent01 = new Intent(HomeActivity.this,MineActivity.class); startActivity(intent01); break; case 2: //個人信息 Intent intent02 = new Intent(HomeActivity.this,ReMessageActivity.class); startActivity(intent02); break; case 3: //修改密碼 Intent intent03 = new Intent(HomeActivity.this,RePasswordActivity.class); startActivity(intent03); break; default: break; } } }); } class MyAdapter extends BaseAdapter{ @Override public int getCount() { return settingText.length; } @Override public Object getItem(int position) { return settingText[position]; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = View.inflate(getApplicationContext(), R.layout.item_gridview, null); TextView tv_Home = (TextView) view.findViewById(R.id.tv_icons); tv_Home.setText(settingText[position]); return view; } } }
package cn.edu.aynu.rjxy.activity; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.Map; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.text.TextUtils; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Spinner; import android.widget.Toast; import cn.edu.aynu.rjxu.path.Paths; import cn.edu.aynu.rjxy.tactivity.THomeActivity; import cn.edu.aynu.rjxy.utils.SharedPreferencesUtils; import cn.edu.aynu.rjxy.utils.StreamTools; public class LoginActivity extends Activity { protected static final int ERROR = 2; protected static final int SUCCESS = 1; protected static String path = null; //身份下拉框 教師、學生、管理員 private Spinner spin_id = null; private String[] ids = new String[]{"教師","學生","管理員"}; ArrayAdapter<String> idAdapter = null; //賬號和密碼控件 private EditText et_name; private EditText et_psw; private String name ; private String psw; private String spinnerId; private String ID; private Handler handler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what) { case SUCCESS: String str = (String)msg.obj; System.out.println(str); if (str.equals("登錄成功")) { boolean isSaveSuccess = SharedPreferencesUtils.saveUserInfo02(LoginActivity.this, name, psw,spinnerId); Intent intent = new Intent(LoginActivity.this,HomeActivity.class); startActivity(intent); }else if (str.equals("老師登錄成功")) { Intent intent = new Intent(LoginActivity.this,THomeActivity.class); startActivity(intent); }else{ Toast.makeText(LoginActivity.this,"登錄失敗,請核對你的賬號密碼是否正確", 1).show(); } break; case ERROR: Toast.makeText(LoginActivity.this,"登錄失敗,可能身份不對", 1).show(); break; } }; }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); et_name = (EditText) findViewById(R.id.et_name); et_psw = (EditText) findViewById(R.id.et_psw); spin_id = (Spinner) findViewById(R.id.spin_id); //設置下拉框 setSpinner(); //取出賬號和密碼 Map<String,String> userInfo = SharedPreferencesUtils.getUserInfo(this); if (userInfo != null) { //顯示在界面上 et_name.setText(userInfo.get("sno")); et_psw.setText(userInfo.get("password")); spinnerId = userInfo.get("spinnerId"); System.out.println("....."+spinnerId); } } /* * 設置下拉框 */ private void setSpinner() { spin_id = (Spinner) findViewById(R.id.spin_id); //綁定適配器和值 idAdapter = new ArrayAdapter<String>(LoginActivity.this, android.R.layout.simple_spinner_item,ids); spin_id.setAdapter(idAdapter); spin_id.setSelection(0,true);//設置默認選項,此處默認的是第二個選項,即學生 spin_id.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) { spinnerId = ids[position]; System.out.println("spinnerId"+spinnerId); boolean isSaveSuccess = SharedPreferencesUtils.saveUserInfo02(LoginActivity.this, name, psw,spinnerId); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); } /* * 學生登錄 */ public void student(View view){ name = et_name.getText().toString().trim(); psw = et_psw.getText().toString().trim(); //判斷賬號和密碼是否為空 if (TextUtils.isEmpty(name)||TextUtils.isEmpty(psw)) { Toast.makeText(this, "賬號或者密碼不能為空!", 0).show(); } //子線程更新UI new Thread(){ public void run(){ try { //http://localhost/xampp/android/login.php //區別1、url的路徑不同 if (spinnerId.equals("學生")) { URL url = new URL(Paths.loginPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//請求的類型 表單數據 String data = "sno="+name+"&passwd="+psw; conn.setRequestProperty("Content-Length", data.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); System.out.println(code); if(code == 200){ InputStream is = conn.getInputStream(); String result = StreamTools.readStream(is); Message mas= Message.obtain(); mas.what = SUCCESS; mas.obj = result; handler.sendMessage(mas); }else{ Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } }else if (spinnerId.equals("教師")) { //http://localhost/xampp/android/login.php //區別1、url的路徑不同 URL url = new URL(Paths.tLoginPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//請求的類型 表單數據 String data = "tno="+name+"&tpasswd="+psw; conn.setRequestProperty("Content-Length", data.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); System.out.println(code); if(code == 200){ InputStream is = conn.getInputStream(); String result = StreamTools.readStream(is); Message mas= Message.obtain(); mas.what = SUCCESS; mas.obj = result; handler.sendMessage(mas); }else{ Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } } }catch (IOException e) { // TODO Auto-generated catch block Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } } }.start(); } }
package cn.edu.aynu.rjxy.activity; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import cn.edu.aynu.rjxu.path.Paths; import cn.edu.aynu.rjxy.entity.Data; import cn.edu.aynu.rjxy.utils.SharedPreferencesUtils; import cn.edu.aynu.rjxy.utils.StreamTools; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MineActivity extends Activity { private static final int CHANGE_UI = 1; private static final int SUCCESS = 3; private static final int ERROR = 2; private ListView lv; private List<Data> datas = new ArrayList<Data>(); Data data; //主線程創建消息處理器 private Handler handler = new Handler(){ public void handleMessage(android.os.Message msg) { if (msg.what == CHANGE_UI) { try { String json = (String)msg.obj; if (json.equals("你還沒有選題")) { Toast.makeText(MineActivity.this, json, 0).show(); }else{ JSONArray arr = new JSONArray(json); for (int i = 0; i < arr.length(); i++) { JSONObject temp = (JSONObject) arr.get(i); // Log.d("json", temp.getInt("id")+temp.getString("exp_name")+temp.getString("exp_tech")); data = new Data(); data.setId(temp.getInt("id")); data.setExp_name(temp.getString("exp_name")); data.setExp_tech(temp.getString("exp_tech")); data.setExp_source(temp.getString("exp_source")); data.setExp_type(temp.getString("exp_type")); data.setExp_tno(temp.getString("tname")); data.setIstate(temp.getString("istate")); //這個地方可以獲取到值但是適配器那位0 datas.add(data); } lv.setAdapter(new MyAdapter()); } }catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else if (msg.what == SUCCESS) { String s =(String)msg.obj; Toast.makeText(MineActivity.this, s, 0).show(); } }; }; protected String sno; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mine); lv = (ListView) findViewById(R.id.lv); select(); //取出賬號和密碼 Map<String,String> userInfo = SharedPreferencesUtils.getUserInfo(this); if (userInfo != null) { sno = userInfo.get("sno"); } } //退選功能 public void reselect(View view){ //子線程更新UI new Thread(){ public void run(){ try { //http://localhost/xampp/android/login.php //區別1、url的路徑不同 URL url = new URL(Paths.reselectPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//請求的類型 表單數據 String data01 = "id="+ data.getId(); conn.setRequestProperty("Content-Length", data01.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data01.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); System.out.println(code); if(code == 200){ InputStream is = conn.getInputStream(); String result = StreamTools.readStream(is); Message mas= Message.obtain(); mas.what = SUCCESS; mas.obj = result; handler.sendMessage(mas); }else{ Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } }catch (IOException e) { // TODO Auto-generated catch block Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } } }.start(); } private void select(){ //子線程更新UI new Thread(){ public void run(){ try { StringBuilder builder = new StringBuilder(); URL url = new URL(Paths.selectPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//請求的類型 表單數據 //System.out.println(sno); String data = "sno="+sno; conn.setRequestProperty("Content-Length", data.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); if (code == 200) { InputStream is = conn.getInputStream(); BufferedReader reader = new BufferedReader (new InputStreamReader(is,"UTF-8")); for(String s=reader.readLine();s!=null;s=reader.readLine()) { builder.append(s); } String content = builder.toString(); //通知主線程更新UI Message message = new Message(); message.what = CHANGE_UI; message.obj = content; handler.sendMessage(message); }else{ Log.e(HomeActivity.class.toString(), "Failed"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }; }.start(); } class MyAdapter extends BaseAdapter{ @Override public int getCount() { Log.d("AAA", ""+datas.size()); return datas.size(); } @Override public Object getItem(int position) { return datas.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = View.inflate(MineActivity.this, R.layout.ui_setting_select, null); TextView exp_name = (TextView) view.findViewById(R.id.tv_name); TextView exp_tech = (TextView) view.findViewById(R.id.tv_tech); TextView exp_type = (TextView) view.findViewById(R.id.tv_type); TextView exp_source = (TextView) view.findViewById(R.id.tv_source); TextView exp_tno = (TextView) view.findViewById(R.id.tv_tno); Data data = datas.get(position); Log.d("aaaaa",datas.get(position).getExp_name() ); exp_name.setText(datas.get(position).getExp_name()); //Log.i("exp_name", datas.get(position).getExp_name()); exp_tech.setText(datas.get(position).getExp_tech()); exp_type.setText(datas.get(position).getExp_type()); exp_source.setText(datas.get(position).getExp_source()); exp_tno.setText(datas.get(position).getExp_tno()); return view; } } }
package cn.edu.aynu.rjxy.activity; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.http.client.ClientProtocolException; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import cn.edu.aynu.rjxu.path.Paths; import cn.edu.aynu.rjxy.entity.Data; import cn.edu.aynu.rjxy.utils.SharedPreferencesUtils; import cn.edu.aynu.rjxy.utils.StreamTools; public class ReMessageActivity extends Activity { protected static final int ERROR = 2; protected static final int CHANGE_UI = 1; protected static final int CHANGE_REMESSAGE = 3; protected static final int SUCCESS = 4; //賬號和密碼控件 private EditText et_cellphone; private EditText et_qq; private EditText et_email; private TextView tv_sno; private TextView tv_name; private TextView tv_grade; private TextView tv_class; private String cellphone ; private String qq; private String email; private Handler handler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what) { case CHANGE_UI: try { JSONArray arr = new JSONArray((String)msg.obj); for (int i = 0; i < arr.length(); i++) { JSONObject temp = (JSONObject) arr.get(i); tv_sno.setText(temp.getString("sno")); System.out.println(temp.getString("sname")); tv_name.setText(temp.getString("sname")); tv_grade.setText(temp.getString("school")); tv_class.setText(temp.getString("spec")); et_cellphone.setText(temp.getString("cellphone")); et_qq.setText(temp.getString("qq")); et_email.setText(temp.getString("email")); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case ERROR: Toast.makeText(ReMessageActivity.this,"操作失敗", 1).show(); break; case SUCCESS: String s = (String)msg.obj; if (s.equals("完善信息成功")) { Toast.makeText(ReMessageActivity.this, "修改信息成功", 0).show(); }else{ Toast.makeText(ReMessageActivity.this, "修改信息失敗", 0).show(); } } }; }; protected String sno; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_remessage); et_cellphone = (EditText) findViewById(R.id.et_cellphone); et_qq = (EditText) findViewById(R.id.et_qq); et_email = (EditText) findViewById(R.id.et_email); tv_class =(TextView) findViewById(R.id.tv_class); tv_sno =(TextView) findViewById(R.id.tv_sno); tv_name =(TextView) findViewById(R.id.tv_name); tv_grade =(TextView) findViewById(R.id.tv_grade); //取出賬號和密碼 Map<String,String> userInfo = SharedPreferencesUtils.getUserInfo(this); if (userInfo != null) { sno = userInfo.get("sno"); } select(); } /* * 完善信息 */ public void remessage(View view){ cellphone = et_cellphone.getText().toString().trim(); qq = et_qq.getText().toString().trim(); email = et_email.getText().toString().trim(); //判斷信息是否為空 if (TextUtils.isEmpty(cellphone)||TextUtils.isEmpty(qq)||TextUtils.isEmpty(email)) { Toast.makeText(this, "輸入信息不能為空", 0).show(); } //子線程更新UI new Thread(){ public void run(){ try { StringBuilder builder = new StringBuilder(); URL url = new URL(Paths.remessagePath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//請求的類型 表單數據 System.out.println("-------"+sno); String data = "sno="+sno+"&cellphone="+cellphone+"&qq="+qq+"&email="+email; conn.setRequestProperty("Content-Length", data.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); System.out.println("code----"+code); if (code == 200) { InputStream is = conn.getInputStream(); BufferedReader reader = new BufferedReader (new InputStreamReader(is,"UTF-8")); for(String s=reader.readLine();s!=null;s=reader.readLine()) { builder.append(s); } String content = builder.toString(); //通知主線程更新UI Message message = new Message(); message.what = SUCCESS; message.obj = content; handler.sendMessage(message); }else{ Log.e(HomeActivity.class.toString(), "Failed"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }.start(); } private void select(){ //子線程更新UI new Thread(){ public void run(){ try { StringBuilder builder = new StringBuilder(); URL url = new URL(Paths.messagePath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//請求的類型 表單數據 System.out.println("-------"+sno); String data = "sno="+sno; conn.setRequestProperty("Content-Length", data.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); System.out.println("code----"+code); if (code == 200) { InputStream is = conn.getInputStream(); BufferedReader reader = new BufferedReader (new InputStreamReader(is,"UTF-8")); for(String s=reader.readLine();s!=null;s=reader.readLine()) { builder.append(s); } String content = builder.toString(); //通知主線程更新UI Message message = new Message(); message.what = CHANGE_UI; message.obj = content; handler.sendMessage(message); }else{ Log.e(HomeActivity.class.toString(), "Failed"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }; }.start(); } }
package cn.edu.aynu.rjxy.activity; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; import cn.edu.aynu.rjxu.path.Paths; import cn.edu.aynu.rjxy.utils.SharedPreferencesUtils; import cn.edu.aynu.rjxy.utils.StreamTools; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.text.TextUtils; import android.view.View; import android.widget.EditText; import android.widget.Toast; public class RePasswordActivity extends Activity { protected static final int ERROR = 2; protected static final int SUCCESS = 1; private EditText et_oldPassword; private EditText et_newPassword; private EditText et_confirmPasseord; private Handler handler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what) { case SUCCESS: Toast.makeText(RePasswordActivity.this,(String)msg.obj, 1).show(); break; case ERROR: Toast.makeText(RePasswordActivity.this,"修改密碼失敗", 1).show(); break; } }; }; protected String sno; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_repassword); et_oldPassword = (EditText) findViewById(R.id.et_oldPassword); et_newPassword = (EditText) findViewById(R.id.et_newPassword); et_confirmPasseord = (EditText) findViewById(R.id.et_confirmPasseord); //取出賬號和密碼 Map<String,String> userInfo = SharedPreferencesUtils.getUserInfo(this); if (userInfo != null) { sno = userInfo.get("sno"); } } /* * 學生登錄 */ public void repassword(View view){ final String oldPassword = et_oldPassword.getText().toString().trim(); final String newPassword = et_newPassword.getText().toString().trim(); final String confirmPasseord = et_confirmPasseord.getText().toString().trim(); //判斷賬號和密碼是否為空 if (TextUtils.isEmpty(oldPassword)||TextUtils.isEmpty(newPassword)||TextUtils.isEmpty(confirmPasseord)) { Toast.makeText(this, "舊密碼或者新密碼或確認密碼不能為空!", 0).show(); }else if(newPassword.equals(confirmPasseord)){ Toast.makeText(this, "兩次密碼輸入的不一致!", 0); } //子線程更新UI new Thread(){ public void run(){ try { //http://localhost/xampp/android/login.php //區別1、url的路徑不同 URL url = new URL(Paths.repasswordPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//請求的類型 表單數據 String data = "sno="+sno+"&old_passwd="+oldPassword+"&new_passed1="+newPassword; conn.setRequestProperty("Content-Length", data.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); System.out.println(code); if(code == 200){ InputStream is = conn.getInputStream(); String result = StreamTools.readStream(is); Message mas= Message.obtain(); mas.what = SUCCESS; mas.obj = result; handler.sendMessage(mas); }else{ Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } }catch (IOException e) { // TODO Auto-generated catch block Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } } }.start(); } }
package cn.edu.aynu.rjxy.activity; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import cn.edu.aynu.rjxu.path.Paths; import cn.edu.aynu.rjxy.entity.Data; import cn.edu.aynu.rjxy.utils.SharedPreferencesUtils; import cn.edu.aynu.rjxy.utils.StreamTools; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class SearchActivity extends Activity { protected static final int ERROR = 2; protected static final int SEARCH = 3; protected static final int SUCCESS = 1; private EditText et_search; private String name; private ListView lv; private List<Data> datas = new ArrayList<Data>(); Data data; private Handler handler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what) { case SUCCESS: try { JSONArray arr = new JSONArray((String)msg.obj); System.out.println((String)msg.obj); for (int i = 0; i < arr.length(); i++) { JSONObject temp = (JSONObject) arr.get(i); // Log.d("json", temp.getInt("id")+temp.getString("exp_name")+temp.getString("exp_tech")); data = new Data(); data.setId(temp.getInt("id")); data.setExp_name(temp.getString("exp_name")); data.setTname(temp.getString("tname")); //這個地方可以獲取到值但是適配器那位0 datas.add(data); } lv.setAdapter(new MyAdapter()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case ERROR: Toast.makeText(SearchActivity.this,"失敗", 1).show(); break; case SEARCH: Toast.makeText(SearchActivity.this,(String)msg.obj, 1).show(); } }; }; private String sno; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); lv = (ListView) findViewById(R.id.lv); et_search = (EditText) findViewById(R.id.et_search); //取出賬號和密碼 Map<String,String> userInfo = SharedPreferencesUtils.getUserInfo(this); if (userInfo != null) { sno = userInfo.get("sno"); } } //搜索功能 public void search(View view){ name = et_search.getText().toString().trim(); //子線程更新UI new Thread(){ public void run(){ try { //http://localhost/xampp/android/login.php //區別1、url的路徑不同 URL url = new URL(Paths.searchPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type" , "application/x-www-form-urlencoded");//請求的類型 表單數據 String data = "exp_tname="+URLEncoder.encode(name, "UTF-8"); System.out.println(name); conn.setRequestProperty("Content-Length", data.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); System.out.println(code); if(code == 200){ InputStream is = conn.getInputStream(); String result = StreamTools.readStream(is); Message mas= Message.obtain(); mas.what = SUCCESS; mas.obj = result; handler.sendMessage(mas); }else{ Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } }catch (IOException e) { // TODO Auto-generated catch block Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } } }.start(); } class MyAdapter extends BaseAdapter{ @Override public int getCount() { Log.d("AAA", ""+datas.size()); return datas.size(); } @Override public Object getItem(int position) { return datas.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { View view = View.inflate(SearchActivity.this, R.layout.item_search, null); TextView id = (TextView) view.findViewById(R.id.tv_id); TextView exp_name = (TextView) view.findViewById(R.id.tv_name); TextView tname = (TextView) view.findViewById(R.id.tv_tname); Button bt_selectquestion = (Button) view.findViewById(R.id.bt_select); bt_selectquestion.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //子線程更新UI new Thread(){ public void run(){ try { //http://localhost/xampp/android/login.php //區別1、url的路徑不同 URL url = new URL(Paths.clickPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//請求的類型 表單數據 String data01 = "sno="+sno+"&id="+String.valueOf(datas.get(position).getId()); System.out.println(sno+String.valueOf(datas.get(position).getId())); conn.setRequestProperty("Content-Length", data01.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data01.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); System.out.println(code); if(code == 200){ InputStream is = conn.getInputStream(); String result = StreamTools.readStream(is); Message mas= Message.obtain(); mas.what = SEARCH; mas.obj = result; handler.sendMessage(mas); }else{ Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } }catch (IOException e) { // TODO Auto-generated catch block Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } } }.start(); } }); data = datas.get(position); Log.d("aaaaa",data.getExp_name() ); id.setText(String.valueOf(data.getId())); exp_name.setText(data.getExp_name()); tname.setText(data.getTname()); return view; } } }
package cn.edu.aynu.rjxy.activity; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import cn.edu.aynu.rjxu.path.Paths; import cn.edu.aynu.rjxy.entity.Data; import cn.edu.aynu.rjxy.utils.SharedPreferencesUtils; import cn.edu.aynu.rjxy.utils.StreamTools; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class SetlectActivity extends Activity { private static final int CHANGE_UI = 1; private static final int SUCCESS = 2; private static final int ERROR = 0; private ListView lv; private List<Data> datas = new ArrayList<Data>(); Data data; //主線程創建消息處理器 private Handler handler = new Handler(){ public void handleMessage(android.os.Message msg) { if (msg.what == CHANGE_UI) { try { JSONArray arr = new JSONArray((String)msg.obj); for (int i = 0; i < arr.length(); i++) { JSONObject temp = (JSONObject) arr.get(i); // Log.d("json", temp.getInt("id")+temp.getString("exp_name")+temp.getString("exp_tech")); data = new Data(); data.setId(temp.getInt("id")); data.setExp_name(temp.getString("exp_name")); data.setExp_tech(temp.getString("exp_tech")); data.setTname(temp.getString("tname")); //這個地方可以獲取到值但是適配器那位0 datas.add(data); } lv.setAdapter(new MyAdapter()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else if (msg.what == SUCCESS) { Toast.makeText(SetlectActivity.this,(String)msg.obj, 1).show(); } }; }; private String sno; private String spinnerId; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_select); lv = (ListView) findViewById(R.id.lv); select(); //取出賬號和密碼 Map<String,String> userInfo = SharedPreferencesUtils.getUserInfo(this); if (userInfo != null) { sno = userInfo.get("sno"); } } //搜獲功能 public void search(View view){ Intent intent03 = new Intent(SetlectActivity.this,SearchActivity.class); startActivity(intent03); } private void select(){ //子線程更新UI new Thread(){ public void run(){ StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(Paths.alselectPath); try { HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { BufferedReader reader = new BufferedReader (new InputStreamReader(response.getEntity().getContent(),"UTF-8")); for(String s=reader.readLine();s!=null;s=reader.readLine()) { builder.append(s); } String content = builder.toString(); System.out.println(content); //通知主線程更新UI Message message = new Message(); message.what = CHANGE_UI; message.obj = content; handler.sendMessage(message); }else{ Log.e(HomeActivity.class.toString(), "Failed"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }; }.start(); } class MyAdapter extends BaseAdapter{ @Override public int getCount() { Log.d("AAA", ""+datas.size()); return datas.size(); } @Override public Object getItem(int position) { return datas.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { View view = View.inflate(SetlectActivity.this, R.layout.item_listview, null); TextView id = (TextView) view.findViewById(R.id.tv_id); TextView exp_name = (TextView) view.findViewById(R.id.tv_name); TextView tname = (TextView) view.findViewById(R.id.tv_tname); Button bt_selectquestion = (Button) view.findViewById(R.id.bt_select); data = datas.get(position); Log.d("aaaaa",data.getExp_name() ); id.setText(String.valueOf(data.getId())); exp_name.setText(data.getExp_name()); tname.setText(data.getTname()); exp_name.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { boolean isSaveSuccess = SharedPreferencesUtils.saveUserInfo02(SetlectActivity.this, sno, String.valueOf(datas.get(position).getId()),spinnerId); Toast.makeText(SetlectActivity.this, datas.get(position).getExp_tech(),0).show(); } }); bt_selectquestion.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //子線程更新UI new Thread(){ public void run(){ try { //http://localhost/xampp/android/login.php //區別1、url的路徑不同 URL url = new URL(Paths.clickPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //區別2、請求方式post conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)"); //區別3、必須指定兩個請求的參數 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//請求的類型 表單數據 String data01 = "sno="+sno+"&id="+String.valueOf(datas.get(position).getId()); System.out.println(sno+String.valueOf(datas.get(position).getId())); conn.setRequestProperty("Content-Length", data01.length()+"");//數據的長度 //區別4、記得設置把數據寫給服務器 conn.setDoOutput(true);//設置向服務器寫數據 byte[] bytes = data01.getBytes(); conn.getOutputStream().write(bytes);//把數據以流的方式寫給服務器 int code = conn.getResponseCode(); System.out.println(code); if(code == 200){ InputStream is = conn.getInputStream(); String result = StreamTools.readStream(is); Message mas= Message.obtain(); mas.what = SUCCESS; mas.obj = result; handler.sendMessage(mas); }else{ Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } }catch (IOException e) { // TODO Auto-generated catch block Message mas = Message.obtain(); mas.what = ERROR; handler.sendMessage(mas); } } }.start(); } }); return view; } } }
package cn.edu.aynu.rjxy.activity; import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.view.View; import android.widget.TextView; import cn.edu.aynu.rjxy.utils.StreamUtils; import cn.edu.aynu.rjxy.utils.ToastUtils; import com.lidroid.xutils.HttpUtils; import com.lidroid.xutils.exception.HttpException; import com.lidroid.xutils.http.ResponseInfo; import com.lidroid.xutils.http.callback.RequestCallBack; /* * 展示品牌---->初始化數據---->檢查版本---->校驗合法性 */ public class SplashActivity extends Activity { private static final int UPDATE_DIALOG = 1;//更新提醒 private static final int NETWORK_ERROR = 2;//網絡異常 private static final int JSON_ERROR = 3;//數據解析失敗 private static final int URL_ERROR = 4;//網絡異常 private static final int ENTER_HOME = 5;//跳轉主頁面 //控件初始化 private TextView tvVersion; private TextView tvProgress; //服務器的返回值 private String mVersionName;//成員變量 private int mVersionCode; private String mDescription; private String mDownloadUrl; //消息傳遞 private Handler mHandler = new Handler(){ public void handleMessage(android.os.Message msg) { switch (msg.what) { case UPDATE_DIALOG: showUpdateDialog(); break; case NETWORK_ERROR: //ToastUtils.showToast(getApplicationContext(), "網絡異常"); enterHome(); break; case JSON_ERROR: ToastUtils.showToast(getApplicationContext(), "數據解析失敗"); enterHome(); break; case URL_ERROR: ToastUtils.showToast(getApplicationContext(), "網絡連接異常"); enterHome(); break; case ENTER_HOME: enterHome(); default: break; } }; }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); tvVersion = (TextView)findViewById(R.id.tv_version); tvVersion.setText("出版單位:DATA工作室"); checkVersion();//檢查版本 } /* * 檢查版本更新 */ private void checkVersion() { // TODO Auto-generated method stub new Thread(){ long startTime = System.currentTimeMillis();//開始時間 Message msg = Message.obtain();//獲取消息 public void run(){ try { // URL url = new URL("http://10.0.2.2:8080/versionCode.json"); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setConnectTimeout(2000);//連接網絡超時 conn.setReadTimeout(2000);//讀取超時 conn.setRequestMethod("GET");//訪問方法 conn.connect();//連接網絡 int responseCode = conn.getResponseCode(); if(responseCode == 200){ String result = StreamUtils.streamToString(conn.getInputStream()); System.out.println("訪問成功--->"+result); //json數據解析 JSONObject jo = new JSONObject(result); mVersionName = jo.getString("versionName"); mVersionCode = jo.getInt("versionCode"); mDescription = jo.getString("description"); mDownloadUrl = jo.getString("downloadUrl"); System.out.println("versionCode--->"+mVersionCode); if (getVersionCode()<mVersionCode) {//如果軟件的版本與網絡中的版本號不一致,提示用戶更新版本 System.out.println("有新版本!!!"); msg.what = UPDATE_DIALOG; }else{ System.out.println("沒有新版本!!!"); //跳轉到主頁面 msg.what = ENTER_HOME; } } } catch (MalformedURLException e) { //url異常 // TODO Auto-generated catch block msg.what = URL_ERROR; e.printStackTrace(); } catch (IOException e) { //網絡異常 // TODO Auto-generated catch block msg.what = NETWORK_ERROR; e.printStackTrace(); }catch (JSONException e) { //json異常 // TODO Auto-generated catch block e.printStackTrace(); msg.what = JSON_ERROR; }finally{ long endTime = System.currentTimeMillis();//訪問網絡結束時間 long timeUsed = endTime - startTime;//訪問網絡總的用時 if (timeUsed<2000) {//如果訪問網絡的時間小於2秒,就展示閃屏頁面。目的是湊夠兩秒,來展示軟件的品牌。 try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } mHandler.sendMessage(msg);//發送消息 } } }.start(); } /* * 用於提醒用戶更新的提示窗 */ protected void showUpdateDialog() { // TODO Auto-generated method stub AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("發現新版本:"+mVersionName); builder.setMessage(mDescription);//新版本的描述 builder.setPositiveButton("立即升級", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub System.out.println("發現新版本"); downloadApk(); } }); builder.setNegativeButton("以后再說", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub enterHome(); } }); builder.show(); } /* * 下載安裝包 */ protected void downloadApk(){ String target = Environment.getExternalStorageDirectory().getAbsolutePath()+"/mobilesafe.apk"; tvProgress.setVisibility(View.VISIBLE); HttpUtils utils = new HttpUtils(); utils.download(mDownloadUrl, target, new RequestCallBack<File>() { //下載成功 @Override public void onSuccess(ResponseInfo<File> responseInfo) { // TODO Auto-generated method stub System.out.println("下載成功!!!!"); File result = responseInfo.result; tvProgress.setVisibility(View.GONE); enterHome(); } /* * 正在下載 * total 文件總大小 * current 當前下載的大小 * isUploading 是否正在上傳 * (non-Javadoc) * @see com.lidroid.xutils.http.callback.RequestCallBack#onLoading(long, long, boolean) */ public void onLoading(long total, long current, boolean isUploading) { // TODO Auto-generated method stub super.onLoading(total, current, isUploading); } //下載失敗 @Override public void onFailure(HttpException error, String msg) { // TODO Auto-generated method stub System.out.println("下載失敗!!!!"); //ToastUtils.showToast(getApplicationContext(),"下載失敗!!"); error.printStackTrace(); } }); } /* * 獲取版本名 */ private String getVersionName() { // TODO Auto-generated method stub //獲取包管理器 PackageManager pm = getPackageManager(); try { PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0); int versionCode = packageInfo.versionCode;//獲取版本號 String versionName = packageInfo.versionName;//獲取版本名 System.out.println("versionName"+versionName+",versionCode"+versionCode); return versionName; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; } /* * 獲取版本號 */ private int getVersionCode() { // TODO Auto-generated method stub //獲取包管理器 PackageManager pm = getPackageManager(); try { PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0); int versionCode = packageInfo.versionCode;//獲取版本號 return versionCode; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; } //跳轉到主頁面 private void enterHome(){ startActivity(new Intent(this,LoginActivity.class));//開啟的新的頁面 finish();//結束原來的頁面 } }
package cn.edu.aynu.rjxy.entity; public class Data { private int id; private String exp_name; private String exp_tech; private String exp_type; private String exp_source; private String exp_tno; private String istate; private String sno; private String sname; private String passwd; private String grade; private String school; private String qq; private String clas; private String cellphone; private String email; private String spec; private String tname; public String getTname() { return tname; } public void setTname(String tname) { this.tname = tname; } public String getSpec() { return spec; } public void setSpec(String spec) { this.spec = spec; } public String getSno() { return sno; } public void setSno(String sno) { this.sno = sno; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public String getPasswd() { return passwd; } public void setPasswd(String passwd) { this.passwd = passwd; } public String getGrade() { return grade; } public void setGrade(String grade) { this.grade = grade; } public String getSchool() { return school; } public void setSchool(String school) { this.school = school; } public String getQq() { return qq; } public void setQq(String qq) { this.qq = qq; } public String getClas() { return clas; } public void setClas(String clas) { this.clas = clas; } public String getCellphone() { return cellphone; } public void setCellphone(String cellphone) { this.cellphone = cellphone; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getExp_type() { return exp_type; } public void setExp_type(String exp_type) { this.exp_type = exp_type; } public String getExp_source() { return exp_source; } public void setExp_source(String exp_source) { this.exp_source = exp_source; } public String getExp_tno() { return exp_tno; } public void setExp_tno(String exp_tno) { this.exp_tno = exp_tno; } public String getIstate() { return istate; } public void setIstate(String istate) { this.istate = istate; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getExp_name() { return exp_name; } public void setExp_name(String exp_name) { this.exp_name = exp_name; } public String getExp_tech() { return exp_tech; } public void setExp_tech(String exp_tech) { this.exp_tech = exp_tech; } @Override public String toString() { return "Data [id=" + id + ", exp_name=" + exp_name + ", exp_tech=" + exp_tech + "]"; } }
package cn.edu.aynu.rjxy.utils; import java.util.HashMap; import java.util.Map; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; public class SharedPreferencesUtils { //保存賬號和密碼到minemessage.xml public static boolean saveUserInfo(Context context,String cellphone,String qq,String email){ SharedPreferences sp = context.getSharedPreferences("minemessage", Context.MODE_PRIVATE); Editor edit = sp.edit(); edit.putString("cellphone", cellphone); edit.putString("qq", qq); edit.putString("email", email); edit.commit(); return true; } //保存賬號和密碼到data.xml public static boolean saveUserInfo02(Context context,String sno,String password,String spinnerId){ SharedPreferences sp = context.getSharedPreferences("data", Context.MODE_PRIVATE); Editor edit = sp.edit(); edit.putString("sno", sno); edit.putString("password", password); edit.putString("spinnerId", spinnerId); edit.commit(); return true; } //保存賬號和密碼到select.xml public static boolean saveUserInfo03(Context context,String sno,String id){ SharedPreferences sp = context.getSharedPreferences("select", Context.MODE_PRIVATE); Editor edit = sp.edit(); edit.putString("sno", sno); edit.putString("id", id); edit.commit(); return true; } //從data.xml文件中獲取存貯的賬號和密碼 public static Map<String,String> getUserInfo(Context context){ SharedPreferences sp = context.getSharedPreferences("data", Context.MODE_PRIVATE); String sno = sp.getString("sno", null); String password = sp.getString("password", null); String spinnerId = sp.getString("spinnerId", null); Map<String,String> userMap = new HashMap<String, String>(); userMap.put("sno", sno); userMap.put("password", password); userMap.put("spinnerId", spinnerId); return userMap; } //從minemessage.xml文件中獲取存貯的賬號和密碼 public static Map<String,String> getUserInfo02(Context context){ SharedPreferences sp = context.getSharedPreferences("minemessage", Context.MODE_PRIVATE); String cellphone = sp.getString("cellphone", null); String qq = sp.getString("qq", null); String email = sp.getString("email", null); Map<String,String> userMap = new HashMap<String, String>(); userMap.put("cellphone", cellphone); userMap.put("qq", qq); userMap.put("email", email); return userMap; } //從select.xml文件中獲取存貯的賬號和密碼 public static Map<String,String> getUserInfo03(Context context){ SharedPreferences sp = context.getSharedPreferences("select", Context.MODE_PRIVATE); String sno = sp.getString("sno", null); String id = sp.getString("id", null); Map<String,String> userMap = new HashMap<String, String>(); userMap.put("sno", sno); return userMap; } }
package cn.edu.aynu.rjxy.utils; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class StreamUtils { public static String streamToString(InputStream in) throws IOException{ ByteArrayOutputStream out = new ByteArrayOutputStream(); int len = 0; byte[] buffer = new byte[1024]; while((len = in.read(buffer))!=-1){ out.write(buffer,0,len); } String result = out.toString(); in.close(); out.close(); return result; } }
---恢復內容結束---