Compare commits

...

4 Commits

Author SHA1 Message Date
wnm b532c6d17c code\Detail.java
code\About2.java
code\Detail.java
code\ExpressSensor.java
code\GlobalInfo.java
code\SettingsActivity2.java
code\About.java
code\LoginActivity2.java
code\SettingsActivity.java
code\WiFi.java

code\WorkStatistics.java
2018-06-03 23:11:47 +08:00
wnm 46d10c4f83 code\ExpressSensorClient.java
code\LoginActivity2.java
code\PersonInfo.java
code\SettingsActivity.java
code\TradeStatus.java
code\WiFi.java
2018-06-02 21:46:33 +08:00
wnm b3c02dcf9b code\About.java 2018-06-02 21:43:14 +08:00
wnm d5c3e21745 code 2018-05-09 08:43:31 +08:00
14 changed files with 2294 additions and 0 deletions

117
code/About.java Normal file
View File

@ -0,0 +1,117 @@
package info.ericyue.es.activity;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
import info.ericyue.es.R;
import info.ericyue.es.util.HttpUtil;
public class About extends Activity {
private String VERSION="(客户版)";
private ListView listView;
private String[] str=new String[8];
public static void launch(Context c,Bundle bundle){
Intent intent = new Intent(c, About.class);
intent.putExtras(bundle);
c.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.about);
listView=(ListView) findViewById(R.id.aboutList);
listView.setCacheColorHint(0);
fillItemList();
}
private void fillItemList(){
queryDatabase();
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
String[] itemStr={"软件简介","软件作者","联系方式","项目主页","提交BUG","客户端当前版本","软件用户数量","最近更新"};
for(int i=0;i<8;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemTitle", itemStr[i]);
map.put("ItemText", str[i]);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.aboutlist,
new String[] {"ItemTitle","ItemText"},
new int[] {R.id.ItemTitle,R.id.ItemText}
);
listView.setAdapter(listItemAdapter);
listView.setOnItemClickListener(itemListener);
}
public void queryDatabase(){
str[0]="Express Sensor是一款基于Android平台的智能物流管理系统.特色在于让用户通过GPS来实时定位自己的包裹.并且采用\"类NFC\"的概念来实现包裹自动感应签收";
str[1]="岳斌(Eric Yue@Moonlight)\n河北工业大学,计算机学院 软件091班";
str[2]="E-mail:hi.moonlight@gmail.com";
str[3]="http://es.ericyue.info";
str[4]="点击发送邮件提交BUG";
//String stream=HttpUtil.QuerySystemInfo("1");
//String[] sys=stream.split(",");
/* str[5]="当前软件版本: "+VersionStatus(sys[0])+VERSION;
str[6]="当前用户数量: "+sys[1] +"";
str[7]="最近一次更新时间: "+sys[2];*/
}
public String VersionStatus(String version){
String[] tmp=version.split("\\.");
if(tmp[0].compareTo("3")>=0){
return version+=" Release";
}
else if(tmp[0].compareTo("2")>=0){
return version+=" Release Candidate";
}
else{
return version+=" Alpha";
}
}
public void openURL(String url){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
public void mailToEricyue(boolean bug){
Uri uri=Uri.parse("mailto:hi.moonlight@gmail.com");
Intent mail= new Intent(Intent.ACTION_SENDTO,uri);
if(bug)
mail.putExtra(Intent.EXTRA_SUBJECT, "[Express Sensor]BUG提交");
startActivity(mail);
}
private OnItemClickListener itemListener = new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) {
switch(position){
case 0:
break;
case 1:
openURL("http://www.ericyue.info");
break;
case 2:
mailToEricyue(false);
break;
case 3:
openURL("http://es.ericyue.info");
break;
case 4:
mailToEricyue(true);
break;
case 5:
break;
}
}
};
}

109
code/About2.java Normal file
View File

@ -0,0 +1,109 @@
package info.ericyue.es.activity;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
import info.ericyue.es.R;
public class About extends Activity {
private ListView listView;
private String[] str=new String[8];
public static void launch(Context c,Bundle bundle){
Intent intent = new Intent(c, About.class);
intent.putExtras(bundle);
c.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.about);
listView=(ListView) findViewById(R.id.aboutlist);
listView.setCacheColorHint(0);
fillItemList();
}
private void fillItemList(){
queryDatabase();
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
String[] itemStr={"软件简介","软件作者","联系方式","提交BUG","客户端当前版本"};
for(int i=0;i<5;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemTitle", itemStr[i]);
map.put("ItemText", str[i]);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.aboutlist,
new String[] {"ItemTitle","ItemText"},
new int[] {R.id.ItemTitle,R.id.ItemText}
);
listView.setAdapter(listItemAdapter);
listView.setOnItemClickListener(itemListener);
}
public void queryDatabase(){
str[0]="Express Sensor是一款基于Android平台的智能物流管理系统.特色在于让用户通过GPS来实时定位自己的包裹.并且采用\"类NFC\"的概念来实现包裹自动感应签收";
str[1]="岳斌(Eric Yue@Moonlight)\n河北工业大学,计算机学院 软件091班";
str[2]="E-mail:hi.moonlight@gmail.com";
str[3]="点击发送邮件提交BUG";
str[4]="当前软件版本: ";
}
public String VersionStatus(String version){
String[] tmp=version.split("\\.");
if(tmp[0].compareTo("3")>=0){
return version+=" Release";
}
else if(tmp[0].compareTo("2")>=0){
return version+=" Release Candidate";
}
else{
return version+=" Alpha";
}
}
public void openURL(String url){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
public void mailToEricyue(boolean bug){
Uri uri=Uri.parse("mailto:hi.moonlight@gmail.com");
Intent mail= new Intent(Intent.ACTION_SENDTO,uri);
if(bug)
mail.putExtra(Intent.EXTRA_SUBJECT, "[Express Sensor]BUG提交");
startActivity(mail);
}
private OnItemClickListener itemListener = new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) {
switch(position){
case 0:
break;
case 1:
break;
case 2:
mailToEricyue(false);
break;
case 3:
mailToEricyue(true);
break;
case 4:
break;
}
}
};
}

178
code/Detail.java Normal file
View File

@ -0,0 +1,178 @@
package info.ericyue.es.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import info.ericyue.es.R;
public class Detail extends Activity {
private ListView listView;
private String[] str=new String[7];
private Bundle bundle;
private String paytype="";
private String number="";
private String name="";
private String address="";
private String postcode="";
private String tel="";
private String cash="";
private String id="";
public static void launch(Context c,Bundle bundle){
Intent intent = new Intent(c, Detail.class);
intent.putExtras(bundle);
c.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.detailinfo);
listView=(ListView) findViewById(R.id.detaillist);
listView.setCacheColorHint(0);
bundle=this.getIntent().getExtras();
id=bundle.getString("id");
number=bundle.getString("detail");
Toast.makeText(this, number, Toast.LENGTH_LONG).show();
try {
QueryDatabase();
} catch (InterruptedException e) {
e.printStackTrace();
}
fillItemList();
}
private String query_detail(String id) throws InterruptedException {
Detail.NetThread sockethread = new Detail.NetThread();
sockethread.setValue(number);
sockethread.start();
sockethread.join();
return sockethread.result;
}
class NetThread extends Thread
{
private PrintWriter pw=null;
private BufferedReader br=null;
private String Number;
public String result;
public void run(){
try {
pw=LoginActivity.pw;
br=LoginActivity.br;
pw.println("detail");
pw.println(Number);
pw.flush();
result=br.readLine();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setValue(String mynumber) {
Number = mynumber;
}
}
public void QueryDatabase() throws InterruptedException {
String tmp = query_detail(id);
String[] item=tmp.split("/");
/*name = "zai";
address = "gfkd";
postcode = "13450";
tel = "13991111";
cash = "128";
String s = "2";*/
name =item[0];
address =item[4];
postcode = item[5];
tel =item[6];
cash =item[8];
String s = item[7];
switch(Integer.parseInt(s)){
case 0:
paytype="未指定";
break;
case 1:
paytype="网银支付";
break;
case 2:
paytype="货到付款";
break;
case 3:
paytype="支付宝";
break;
case 4:
paytype="财付通";
break;
case 5:
paytype="信用卡";
break;
case 6:
paytype="邮局汇款";
break;
}
str[0]=number;
str[1]=name;
str[2]=address;
str[3]=postcode;
str[4]=tel;
str[5]=paytype;
str[6]=cash;
}
private void fillItemList(){
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
String[] itemStr={"邮包编号","收件人姓名","收件人地址","收件人邮编","收件人电话","支付类型","应支付金额"};
for(int i=0;i<7;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemTitle", itemStr[i]);
map.put("ItemText", str[i]);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.detaillist,
new String[] {"ItemTitle","ItemText"},
new int[] {R.id.ItemTitle,R.id.ItemText}
);
listView.setAdapter(listItemAdapter);
listView.setOnItemClickListener(itemListener);
}
private OnItemClickListener itemListener = new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) {
if(position==4){
try{
String strInput = bundle.getString("phone");
if (strInput.length()==11){
Intent myIntentDial = new Intent("android.intent.action.CALL",Uri.parse("tel:"+strInput));
startActivity(myIntentDial);
}
else{
Toast.makeText(Detail.this, "电话格式不符", Toast.LENGTH_LONG).show();
}
}
catch(Exception e){
e.printStackTrace();
}
}
}
};
}

317
code/ExpressSensor.java Normal file
View File

@ -0,0 +1,317 @@
package info.ericyue.es.activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.location.LocationManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import info.ericyue.es.R;
import info.ericyue.es.util.TutorialDialog;
import info.ericyue.es.zxing.client.android.CaptureActivity;
public class ExpressSensor extends Activity{
private ListView listView;
private Bundle bundle;
private TextView infoWall;
private ProgressBar progressbar;
private serviceReceiver receiver;
private LocationManager locationManager;
//private int id;
private String id;
private boolean show_tutorial;
private long exitTime = 0; //确定是短时间按下了两次返回键
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){
if((System.currentTimeMillis()-exitTime) > 2000){
Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
}
else{
Intent location = new Intent( ExpressSensor.this, LocationService.class );
Intent record = new Intent( ExpressSensor.this, TraceRecordService.class );
/* 以stopService方法关闭Intent */
stopService(location);
stopService(record);
finish();
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//不显示标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
progressbar=(ProgressBar) findViewById(R.id.ProgressBar);
infoWall=(TextView) findViewById(R.id.infoWall);
show_tutorial = SettingsActivity.getShowTutorial(this);
headInfo(true,"欢迎进入Express Sensor(快递版)");
listView = (ListView)findViewById(R.id.HomeListView);
bundle=this.getIntent().getExtras();
id=bundle.getString("username");
bundle.putString("id",id);
if(!isClient()){
showDialog("账户类型与该版本客户端不匹配");
}
fillItemList();
/**
* 开启系统服务 监听用户与送货员人的位置直线距离
*/
Intent i = new Intent(this, LocationService.class );
i.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
i.putExtras(bundle);
startService(i);
if(show_tutorial){
showTutorial();
}
/*if(SettingsActivity.getTraceRecord(this)){
Intent tr = new Intent(this, TraceRecordService.class );
tr.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
tr.putExtras(bundle);
startService(tr);
}
else{
Toast.makeText(this, "轨迹记录服务关闭", Toast.LENGTH_LONG).show();
}*/
// }
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {}
/**
* MenuInflater 用来解析定义在menu目录下的菜单布局文件
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.home, menu);
return super.onCreateOptionsMenu(menu);
}
/**
* 按下菜单后的响应
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.about_menu_item:
About.launch(ExpressSensor.this,bundle);
break;
case R.id.about_menu_min:
Intent i= new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
break;
case R.id.settings_menu_item:
SettingsActivity.launch(ExpressSensor.this,bundle);
break;
}
return super.onOptionsItemSelected(item);
}
private void showDialog(String msg){
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("错误").setMessage(msg).setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
});
AlertDialog alert=builder.create();
alert.show();
}
class NetThread extends Thread
{
private PrintWriter pw=null;
private BufferedReader br=null;
private String id;
private String result;
public void run(){
try {
pw=LoginActivity.pw;
br=LoginActivity.br;
pw.println("client");
pw.println(id);
pw.flush();
result=br.readLine();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setId(String myname) {
id = myname;
}
public String getRole() {
return result;
}
}
//判断是否为客户端身份
public boolean isClient(){
return queryRole(id).equals("0");
}
//查询用户角色
public String queryRole(String id) {
NetThread sockethread = new ExpressSensor.NetThread();
sockethread.setId(id);
sockethread.start();
try {
sockethread.join();
}catch (Exception e) {
e.printStackTrace();
}
return sockethread.getRole();
}
final void showTutorial() {
boolean showTutorial = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("show_tutorial", true);
if (showTutorial) {
final TutorialDialog dlg = new TutorialDialog(this);
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
CheckBox cb = (CheckBox) dlg.findViewById(R.id.show_tutorial);
if (cb != null && cb.isChecked()) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ExpressSensor.this);
prefs.edit().putBoolean("show_tutorial", false).commit();
}
}
});
dlg.show();
} else {
}
}
private void fillItemList(){
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
String[] itemStr={"全局信息","快递投递","工作统计","查看轨迹","二维码识别","关于产品"};
Integer[] iconBag={R.drawable.globalinfo,R.drawable.send,R.drawable.workstatistics,R.drawable.trace,R.drawable.qrcode,R.drawable.about};
for(int i=0;i<6;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", iconBag[i]);//图像资源的ID
map.put("ItemTitle", itemStr[i]);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.purple_row,
//动态数组与ImageItem对应的子项
new String[] {"ItemImage","ItemTitle"},
//ImageItem的XML文件里面的一个ImageView,两个TextView ID
new int[] {R.id.leftHead,R.id.PurpleRowTextView}
);
listView.setAdapter(listItemAdapter);
listView.setOnItemClickListener(itemListener);
}
public void headInfo(boolean run,String msg){
if(!run)
progressbar.setVisibility(View.GONE);
else
progressbar.setVisibility(View.VISIBLE);
infoWall.setText(msg);
}
private OnItemClickListener itemListener = new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) {
switch(position){
case 0:
GlobalInfo.launch(ExpressSensor.this,bundle);
break;
case 1:
ExpressDelivery.launch(ExpressSensor.this,bundle);
break;
case 2:
WorkStatistics.launch(ExpressSensor.this,bundle);
break;
case 3:
TraceRecord.launch(ExpressSensor.this,bundle);
break;
case 4:
CaptureActivity.launch(ExpressSensor.this,bundle);
break;
case 5:
About.launch(ExpressSensor.this,bundle);
break;
}
}
};
public class serviceReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
try{
/* 取并来自后台服务所Broadcast的参数 */
Bundle b = intent.getExtras();
String message = b.getString("MESSAGE");
Toast.makeText(ExpressSensor.this, message, Toast.LENGTH_LONG).show();
}catch(Exception e){
e.getStackTrace();
}
}
}
@Override
protected void onResume(){
// TODO Auto-generated method stub
try{
/* 前景程序生命周期开始 */
IntentFilter filter;
/* 自定义要过滤的广播讯息(DavidLanz) */
filter = new IntentFilter("SENT");
receiver = new serviceReceiver();
registerReceiver(receiver, filter);
}catch(Exception e){
e.getStackTrace();
}
super.onResume();
}
@Override
protected void onPause(){
// TODO Auto-generated method stub
/* 前景程序生命周期结束解除刚守系统注册的Receiver */
unregisterReceiver(receiver);
super.onPause();
}
}

View File

@ -0,0 +1,316 @@
package info.ericyue.es.activity;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import info.ericyue.es.R;
import info.ericyue.es.util.HttpUtil;
import info.ericyue.es.util.TutorialDialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class ExpressSensorClient extends Activity{
//private int id;
private String id;
private Bundle bundle;
private Intent i;
private ListView listView;
private TextView infoWall;
private ProgressBar progressbar;
private serviceReceiver receiver;
private boolean show_tutorial;
private long exitTime = 0;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){
if((System.currentTimeMillis()-exitTime) > 2000){
Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis();
}
else{
finish();
Intent i = new Intent( ExpressSensorClient.this, LocationListenService.class );
/* 以stopService方法关闭Intent */
stopService(i);
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
final void showTutorial() {
boolean showTutorial = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("show_tutorial", true);
if (showTutorial) {
final TutorialDialog dlg = new TutorialDialog(this);
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
CheckBox cb = (CheckBox) dlg.findViewById(R.id.show_tutorial);
if (cb != null && cb.isChecked()) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ExpressSensorClient.this);
prefs.edit().putBoolean("show_tutorial", false).commit();
}
}
});
dlg.show();
} else {
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//不显示标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
show_tutorial = SettingsActivity.getShowTutorial(this);
progressbar=(ProgressBar) findViewById(R.id.ProgressBar);
infoWall=(TextView) findViewById(R.id.infoWall);
headInfo(false,"欢迎进入Express Sensor(客户版)");
listView = (ListView)findViewById(R.id.HomeListView);
listView.setCacheColorHint(0);
bundle=this.getIntent().getExtras();
//数据库查询id
//id=Integer.parseInt(getIdByUsername(bundle.getString("username")));
try {
id=getIdByUsername(bundle.getString("username"));
} catch (InterruptedException e) {
e.printStackTrace();
}
// bundle.putString("id", id+"");//用户的ID
bundle.putString("id+",id);
/* if(!isClient()){
showDialog("账户类型与该版本客户端不匹配");
}*/
// else{
//填充ListView
fillItemList();
if(show_tutorial){
showTutorial();
}
/**
* 开启系统服务 监听用户与送货员人的位置直线距离
*/
i = new Intent(this, LocationListenService.class );
i.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
i.putExtras(bundle);
startService(i);
// }
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {}
/**
* MenuInflater 用来解析定义在menu目录下的菜单布局文件
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.home, menu);
return super.onCreateOptionsMenu(menu);
}
/**
* 按下菜单后的响应
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.about_menu_item:
About.launch(ExpressSensorClient.this,bundle);
break;
case R.id.about_menu_min:
Intent i= new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
break;
case R.id.settings_menu_item:
SettingsActivity.launch(ExpressSensorClient.this,bundle);
break;
}
return super.onOptionsItemSelected(item);
}
private void showDialog(String msg){
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("身份错误").setMessage(msg).setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Intent intent = new Intent(ExpressSensorClient.this, LoginActivity.class);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
});
AlertDialog alert=builder.create();
alert.show();
}
private void fillItemList(){
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
String[] itemStr={"包裹跟踪","个人信息","WIFI辅助签收开关","系统设置","关于"};
Integer[] iconBag={R.drawable.trace,R.drawable.nfc,R.drawable.qrcode,R.drawable.settings,R.drawable.about};
for(int i=0;i<5;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", iconBag[i]);//图像资源的ID
map.put("ItemTitle", itemStr[i]);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.purple_row,
//动态数组与ImageItem对应的子项
new String[] {"ItemImage","ItemTitle"},
//ImageItem的XML文件里面的一个ImageView,两个TextView ID
new int[] {R.id.leftHead,R.id.PurpleRowTextView}
);
listView.setAdapter(listItemAdapter);
listView.setOnItemClickListener(itemListener);
}
private String getIdByUsername(String username) throws InterruptedException{
/*String queryString="username="+username;
String url=HttpUtil.BASE_URL+"servlet/QueryUser?"+queryString;
String id=HttpUtil.queryStringForPost(url);*/
ExpressSensorClient.NetThread sockethread = new ExpressSensorClient.NetThread();
sockethread.setValue(username);
sockethread.start();
sockethread.join();
return sockethread.result;
}
class NetThread extends Thread
{
private PrintWriter pw=null;
private BufferedReader br=null;
private String Username;
public String result;
public void run(){
try {
// Socket s=new Socket("192.168.43.235",6666);
//Socket s = LoginActivity.s;
/*pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
br=new BufferedReader(new InputStreamReader(s.getInputStream()));*/
pw=LoginActivity.pw;
br=LoginActivity.br;
pw.println("username="+Username);
pw.flush();
result=br.readLine();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setValue(String myname) {
Username = myname;
}
}
public boolean isClient(){
int id_int=Integer.parseInt(id);
return HttpUtil.queryRole(id_int).equals("0");
}
public void headInfo(boolean run,String msg){
if(!run)
progressbar.setVisibility(View.GONE);
else
progressbar.setVisibility(View.VISIBLE);
infoWall.setText(msg);
}
private OnItemClickListener itemListener = new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) {
switch(position){
case 0:
TraceRecord.launch(ExpressSensorClient.this,bundle);
break;
case 1:
PersonInfo.launch(ExpressSensorClient.this,bundle);
break;
case 2:
boolean wifi=SettingsActivity.getWIFIReceive(ExpressSensorClient.this);
SettingsActivity.setWIFIReceive(ExpressSensorClient.this,!wifi);
Toast.makeText(ExpressSensorClient.this, "WIFI辅助签收"+ (!wifi==true?"开启":"关闭"), Toast.LENGTH_SHORT).show();
break;
case 3:
SettingsActivity.launch(ExpressSensorClient.this,bundle);
break;
case 4:
About.launch(ExpressSensorClient.this,bundle);
break;
}
}
};
public void turnWIFI(){
}
public class serviceReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
try{
/* 取并来自后台服务所Broadcast的参数 */
Bundle b = intent.getExtras();
String message = b.getString("MESSAGE");
Toast.makeText(ExpressSensorClient.this, message, Toast.LENGTH_LONG).show();
stopService(i);
HttpUtil.DeleteCurrentUserLocation(id+"");
}catch(Exception e){
e.getStackTrace();
}
}
}
@Override
protected void onResume(){
// TODO Auto-generated method stub
try{
/* 前景程序生命周期开始 */
IntentFilter filter;
/* 自定义要过滤的广播讯息(DavidLanz) */
filter = new IntentFilter("SENT");
receiver = new serviceReceiver();
registerReceiver(receiver, filter);
}catch(Exception e){
e.getStackTrace();
}
super.onResume();
}
@Override
protected void onPause(){
// TODO Auto-generated method stub
/* 前景程序生命周期结束解除刚守系统注册的Receiver */
unregisterReceiver(receiver);
super.onPause();
}
}

222
code/GlobalInfo.java Normal file
View File

@ -0,0 +1,222 @@
package info.ericyue.es.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import com.baidu.location.BDLocation;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import info.ericyue.es.R;
public class GlobalInfo extends Activity {
/** Called when the activity is first created. */
private TextView infoWall;
private LocationManager locationManager;
private double lat;
private double lng;
private String id;
private int updateSecond=5000;//刷新信息线程的间隔
private Bundle bundle;
private final static String M24 = "kk:mm";
private String timeStr;
private ListView listView;
private String[] str=new String[7];
private Handler objHandler = new Handler();
private Runnable updateInfo= new Runnable(){
@Override
public void run() {
if(SettingsActivity.getAutoUpdate(GlobalInfo.this)){
try {
refreshInfo();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
objHandler.postDelayed(updateInfo, updateSecond);
}
};
public static void launch(Context c,Bundle bundle){
Intent intent = new Intent(c, GlobalInfo.class);
intent.putExtras(bundle);
c.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState );
this.setContentView(R.layout.globalinfo);
bundle=this.getIntent().getExtras();
listView=(ListView) findViewById(R.id.globalList);
listView.setCacheColorHint(0);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
//从XML中读取配置信息
updateSecond=Integer.parseInt(SettingsActivity.getUpdateTime(GlobalInfo.this));
id=bundle.getString("username");
objHandler.postDelayed(updateInfo, updateSecond);
timeStr ="最近一次更新数据: "+(String) DateFormat.format(M24,System.currentTimeMillis());
infoWall=(TextView) findViewById(R.id.infoWall);
locate();
try {
queryDatabase();
} catch (InterruptedException e) {
e.printStackTrace();
}
fillItemList();
headInfo(timeStr);
}
public void headInfo(String msg){
infoWall.setText(msg);
}
private void fillItemList(){
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
String[] itemStr={"当前用户","今日总委派数","今日完成派送",
"今日拒绝签收","今日投递失败(无人签收)","今日收入总额","当前坐标"};
for(int i=0;i<7;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemTitle", itemStr[i]);
map.put("ItemText", str[i]);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.globallist,
new String[] {"ItemTitle","ItemText"},
new int[] {R.id.ItemTitle,R.id.ItemText}
);
listView.setAdapter(listItemAdapter);
listView.setOnItemClickListener(itemListener);
}
private void queryDatabase() throws InterruptedException {
String tmp=query_global(id);
String[] item=tmp.split("/");
str[0]="当前用户:"+id;
str[1]="今日总委派数"+item[0];
str[2]="今日完成派送"+item[1];
str[3]="拒绝签收共 "+item[2]+"";
str[4]="投递失败共 "+item[3]+"";
str[5]="今日收入总额 "+item[4]+"";
}
private String query_global(String id) throws InterruptedException {
GlobalInfo.NetThread sockethread = new GlobalInfo.NetThread();
sockethread.setValue(id);
sockethread.start();
sockethread.join();
return sockethread.result;
}
class NetThread extends Thread
{
private PrintWriter pw=null;
private BufferedReader br=null;
private String Id;
public String result;
public void run(){
try {
pw=LoginActivity.pw;
br=LoginActivity.br;
pw.println("globalinfo");
pw.println(Id);
pw.flush();
result=br.readLine();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setValue(String myid) {
Id = myid;
}
}
public void refreshInfo() throws InterruptedException {
timeStr = "最近一次更新数据: "+ (String) DateFormat.format(M24,System.currentTimeMillis());
headInfo(timeStr);
locate();
queryDatabase();
fillItemList();
}
private void updateWithNewLocation(Location location) {
String latLongString;
double lat =TraceRecord.mLatitude ;
double lng =TraceRecord.mlongitude;
if (lat != 0) {
BDLocation bdlocation;
latLongString = "纬度:" + lat + "\n经度:" + lng + "\n位置" + TraceRecord.mAddrStr;
} else {
latLongString = "无法获取地理信息";
}
str[6]=(latLongString);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};
public void locate(){
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 2000, 10,
locationListener);
}
private OnItemClickListener itemListener = new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position,
long ids) {
switch(position){
case 1:
case 2:
TraceRecord.launch(GlobalInfo.this, bundle);
break;
case 6:
break;
default:
break;
}
}
};
}

258
code/LoginActivity2.java Normal file
View File

@ -0,0 +1,258 @@
package info.ericyue.es.activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.net.Socket;
import info.ericyue.es.R;
import info.ericyue.es.util.EncryptString;
public class LoginActivity extends Activity {
/** Called when the activity is first created. */
public ProgressDialog welcomeDialog=null;
public AlertDialog dialogBuilder;
public EditText userName,passWord;
public LayoutInflater li;
public View myView;
private String pwd_md5;
private boolean cancel=false;
public static PrintWriter pw=null;
public static BufferedReader br=null;
Handler handler=new Handler();
Runnable runnable=new Runnable(){
@Override
public void run() {
if(cancel)
showDialog("远程服务器未就绪!",true);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.welcome);
li=LayoutInflater.from(LoginActivity.this);
myView=li.inflate(R.layout.login_dialog, null);
userName=(EditText) myView.findViewById(R.id.userEditText);
passWord=(EditText) myView.findViewById(R.id.pwdEditText);
userName.setText("111111");
passWord.setText("111111");
loginDialog();
}
private void showDialog(String msg,final boolean close){
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setMessage(msg).setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
if(close){
finish();
}
}
});
AlertDialog alert=builder.create();
alert.show();
}
private void showDialog(String msg){
showDialog(msg,false);
}
private boolean login() throws Exception{
String username=userName.getText().toString();
String pwd=passWord.getText().toString();
pwd= EncryptString.encryptString(pwd, "MD5");//To Upper Case
pwd_md5=pwd;
//查询结果
String result=query(username,pwd);
Log.d("TAG","result = "+result);
//String result = "1";
cancel=false;
handler.removeCallbacks(runnable);
if(result!=null&&result.equals("1")){
return true;
}
else {
return false;
}
}
private boolean validate(){
String username=userName.getText().toString();
String pwd=passWord.getText().toString();
if(username.equals("")&&!pwd.equals("")){
showDialog("用户名必填!");
return false;
}
if(pwd.equals("")&&!username.equals("")){
showDialog("密码必填!");
return false;
}
if(username.equals("")&&pwd.equals("")){
showDialog("用户名和密码必填!");
return false;
}
return true;
}
private String query(String username,String password) throws InterruptedException {
NetThread sockethread = new NetThread();
sockethread.setValue(username, password);
sockethread.start();
sockethread.join();
return sockethread.result;
/*
String queryString="username="+username+"&password="+password;
String url=HttpUtil.BASE_URL+"servlet/LoginVerify?"+queryString;
return HttpUtil.queryStringForPost(url);
*/
}
class NetThread extends Thread
{
private String username;
private String password;
public String result;
private Socket s;
public void run(){
try {
s=new Socket("192.168.43.235",6666);
pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
pw.println(username);
pw.println(password);
pw.flush();
result=br.readLine();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setValue(String uname, String pword) {
username = uname;
password = pword;
/*username=userName.toString();
password=passWord.toString();*/
}
}
private void loginDialog(){
dialogBuilder=new AlertDialog.Builder(this)
.setView(myView)
.setCancelable(false).setNegativeButton("退出",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
})
.setPositiveButton("登陆",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
if(validate()){
cancel=true;
handler.postDelayed(runnable, 5000);
LoginThread loginthread=new LoginThread();
loginthread.execute();
}
}
}).create();
try{
Field field = dialogBuilder.getClass().getDeclaredField("mAlert");
field.setAccessible(true);
Object obj = field.get(dialogBuilder);
field = obj.getClass().getDeclaredField("mHandler");
field.setAccessible(true);
field.set(obj,new ButtonHandler(dialogBuilder));
}catch(Exception e){
e.printStackTrace();
}
dialogBuilder.show();
}
/**
* Login Dialog Defend Close
* @author Ericyue@Moonlight
*
*/
class ButtonHandler extends Handler{
private WeakReference <DialogInterface> mDialog;
public ButtonHandler(DialogInterface dialog){
mDialog = new WeakReference <DialogInterface> (dialog);
}
@Override
public void handleMessage(Message msg){
switch (msg.what){
case DialogInterface.BUTTON_POSITIVE:
case DialogInterface.BUTTON_NEGATIVE:
case DialogInterface.BUTTON_NEUTRAL:
((DialogInterface.OnClickListener) msg.obj).onClick(mDialog.get(), msg.what);
break;
}
}
}
/**
* 登陆线程
* @author Moonlight
*/
class LoginThread extends AsyncTask<Void, Void, Void> {
ProgressDialog d = new ProgressDialog(LoginActivity.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
d.setMessage("正在验证用户信息...");
d.setTitle("请稍后...");
d.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
if(login()){
Intent intent = new Intent(LoginActivity.this,ExpressSensorClient.class);
Bundle bundle=new Bundle();
bundle.putString("username",userName.getText().toString());
bundle.putString("password",pwd_md5);
intent.putExtras(bundle);
startActivityForResult(intent,0);
finish();
}
else{
Toast.makeText(LoginActivity.this, "用户名或密码错误,请核对", Toast.LENGTH_LONG);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
d.dismiss();
} catch (IllegalArgumentException e) {
e.printStackTrace();
};
}
}
}

88
code/MainActivity.java Normal file
View File

@ -0,0 +1,88 @@
/*package com.android.socketdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
*/
package com.android.socketdemo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
import android.app.Activity;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
public class MainActivity extends AppCompatActivity {
private static PrintWriter pw=null;
private static BufferedReader br=null;
private static Socket s;
static Scanner scanner=new Scanner(System.in);
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Socket s=new Socket("172.20.10.6",6666);
pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
while(true){
System.out.println("Client端请输入");
String str = scanner.next();
pw.println(str);
pw.flush();
String string=br.readLine();
System.out.println("Client读到"+string);
if(str.equals("exit")){
break;
}
}
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
br.close();
pw.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}

129
code/PersonInfo.java Normal file
View File

@ -0,0 +1,129 @@
package info.ericyue.es.activity;
import info.ericyue.es.R;
import info.ericyue.es.util.HttpUtil;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class PersonInfo extends Activity {
private ListView listView;
private String[] str=new String[9];
private String id;
private Bundle bundle;
public static void launch(Context c,Bundle bundle){
Intent intent = new Intent(c, PersonInfo.class);
intent.putExtras(bundle);
c.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.userinfo);
listView=(ListView) findViewById(R.id.aboutList);
listView.setCacheColorHint(0);
bundle=this.getIntent().getExtras();
//id=bundle.getString("id");
try {
fillItemList();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void fillItemList() throws InterruptedException {
queryDatabase();
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
String[] itemStr={"ID","用户名","密码(MD5加密)","姓名","性别","角色","联系电话","电子邮箱","联系地址"};
for(int i=0;i<9;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemTitle", itemStr[i]);
map.put("ItemText", str[i]);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.aboutlist,
new String[] {"ItemTitle","ItemText"},
new int[] {R.id.ItemTitle,R.id.ItemText}
);
listView.setAdapter(listItemAdapter);
}
public void queryDatabase() throws InterruptedException {
// 2/admin/96e79218965eb72c92a549dd5a330112//1/151233336075/359512860@qq.com/gfkd大学 计算机学院/某某
//String tmp=HttpUtil.QueryUserInfo(id);
//id = "2";
String tmp=query_person(id);
String[] item=tmp.split("/");
str[0]="用户ID:"+item[0];
str[1]="用户登录名:"+item[1];
str[2]=item[2];
str[3]="用户姓名:"+item[8];
str[4]="用户性别:"+item[3];
str[5]="账户类型:"+item[4].equals("1") != null?"快递员":"用户";
str[6]="联系电话:"+item[5];
str[7]="电子邮箱:"+item[6];
str[8]="联系地址:"+item[7];
/* str[0]="用户ID:";
str[1]="用户登录名:";
str[2]="第一佳大鸡排";
str[3]="用户姓名:";
str[4]="用户性别:";
str[5]="账户类型:用户";
str[6]="联系电话:";
str[7]="电子邮箱:";
str[8]="联系地址:";*/
}
private String query_person(String id) throws InterruptedException {
PersonInfo.NetThread sockethread = new PersonInfo.NetThread();
sockethread.setValue(id);
sockethread.start();
sockethread.join();
return sockethread.result;
/*
String queryString="username="+username+"&password="+password;
String url=HttpUtil.BASE_URL+"servlet/LoginVerify?"+queryString;
return HttpUtil.queryStringForPost(url);
*/
}
class NetThread extends Thread
{
private PrintWriter pw=null;
private BufferedReader br=null;
private String Id;
public String result;
public void run(){
try {
// Socket s=new Socket("192.168.43.235",6666);
//Socket s = LoginActivity.s;
/*pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
br=new BufferedReader(new InputStreamReader(s.getInputStream()));*/
pw=LoginActivity.pw;
br=LoginActivity.br;
pw.println(Id);
pw.flush();
result=br.readLine();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setValue(String myid) {
Id = myid;
}
}
}

View File

@ -0,0 +1,56 @@
package info.ericyue.es.activity;
import info.ericyue.es.R;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.view.Window;
public class SettingsActivity extends PreferenceActivity {
public static final String RESET_FIRST_RUN_PREFERENCE = "reset_firstrun";
public static void launch(Context c,Bundle bundle){
Intent intent = new Intent(c, SettingsActivity.class);
intent.putExtras(bundle);
c.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
setContentView(R.layout.settings);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
public static boolean getShowTutorial(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_tutorial", true);
}
public static String getReceiveNetWork(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getString("receive_network","GSM");
}
public static String getUpdateTime(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getString("auto_update","10000");
}
public static boolean getAutoUpdate(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("switch_autorefresh",false);
}
public static boolean setAutoUpdate(Context context,boolean status){
return PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("switch_autorefresh", status).commit();
}
public static boolean getWIFIReceive(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("wifi_receive",false);
}
public static boolean setWIFIReceive(Context context,boolean status){
return PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("wifi_receive", status).commit();
}
}

View File

@ -0,0 +1,65 @@
/**
* Copyright: Moonlight(Eric yue)
* Email: hi.moonlight@gmail.com
* Website: www.ericyue.info
* File name: SettingsActivity.java
* Project Name:ExpressSensor
* Create Date: 2011-8-13
*/
package info.ericyue.es.activity;
import info.ericyue.es.R;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.view.Window;
public class SettingsActivity extends PreferenceActivity {
public static void launch(Context c,Bundle bundle){
Intent intent = new Intent(c, SettingsActivity.class);
intent.putExtras(bundle);
c.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
setContentView(R.layout.settings);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
public static boolean getShowTutorial(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_tutorial", true);
}
public static String getUpdateTime(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getString("auto_update","10000");
}
public static String getTraceTime(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getString("gps_record","10000");
}
public static boolean getAutoUpdate(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("switch_autorefresh",false);
}
public static boolean setAutoUpdate(Context context,boolean status){
return PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("switch_autorefresh", status).commit();
}
public static boolean getTraceRecord(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("trace_record",false);
}
public static boolean setTraceRecord(Context context,boolean status){
return PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("trace_record", status).commit();
}
public static boolean getWIFIReceive(Context context){
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("wifi_receive",false);
}
}

147
code/TradeStatus.java Normal file
View File

@ -0,0 +1,147 @@
package info.ericyue.es.activity;
import info.ericyue.es.R;
import info.ericyue.es.util.HttpUtil;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class TradeStatus extends Activity {
private ListView listView;
private TextView infoWall;
private ProgressBar progressbar;
private Bundle bundle;
private String trade_number,user_id;
private NotificationManager m_NotificationManager;
private String[] str=new String[8];
public static void launch(Context c,Bundle bundle){
Intent intent = new Intent(c, TradeStatus.class);
intent.putExtras(bundle);
c.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.about);
bundle=this.getIntent().getExtras();
trade_number=bundle.getString("trade_number");
user_id=bundle.getString("user_id");
m_NotificationManager=(NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);
m_NotificationManager.cancel(0);
progressbar=(ProgressBar) findViewById(R.id.ProgressBar);
infoWall=(TextView) findViewById(R.id.infoWall);
listView=(ListView) findViewById(R.id.aboutList);
listView.setCacheColorHint(0);
headInfo(true,"邮单"+trade_number+"签收完毕");
try {
fillItemList();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void headInfo(boolean run,String msg){
if(!run)
progressbar.setVisibility(View.GONE);
else
progressbar.setVisibility(View.VISIBLE);
infoWall.setText(msg);
}
private void fillItemList() throws InterruptedException {
queryDatabase();
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
String[] itemStr={"邮包编号","签收人","签收人电话","拒签"};
for(int i=0;i<4;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemTitle", itemStr[i]);
map.put("ItemText", str[i]);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.aboutlist,
new String[] {"ItemTitle","ItemText"},
new int[] {R.id.ItemTitle,R.id.ItemText}
);
listView.setAdapter(listItemAdapter);
listView.setOnItemClickListener(itemListener);
}
public void queryDatabase() throws InterruptedException {
// 邮包编号 /签收人/签收人电话
String tmp=query_trade(trade_number);
String[] item=tmp.split("/");
str[0]="邮包编号: "+trade_number;
// str[1]="包裹签收人: "+HttpUtil.queryTradeInfo("trade_number", trade_number, "receiver_name");
// str[2]="包裹签收人: "+HttpUtil.queryTradeInfo("trade_number", trade_number, "receiver_phone");
str[3]="改设拒签";
str[1]="包裹签收人: "+item[1];
str[2]="签收人电话: "+item[2];
}
private String query_trade(String tradenumber) throws InterruptedException {
TradeStatus.NetThread sockethread = new TradeStatus.NetThread();
sockethread.setValue(trade_number);
sockethread.start();
sockethread.join();
return sockethread.result;
/*
String queryString="username="+username+"&password="+password;
String url=HttpUtil.BASE_URL+"servlet/LoginVerify?"+queryString;
return HttpUtil.queryStringForPost(url);
*/
}
class NetThread extends Thread
{
private PrintWriter pw=null;
private BufferedReader br=null;
private String Tradenumber;
public String result;
public void run(){
try {
// Socket s=new Socket("192.168.43.235",6666);
//Socket s = LoginActivity.s;
/*pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
br=new BufferedReader(new InputStreamReader(s.getInputStream()));*/
pw=LoginActivity.pw;
br=LoginActivity.br;
pw.println(Tradenumber);
pw.flush();
result=br.readLine();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setValue(String mytrade) {
Tradenumber = mytrade;
}
}
private OnItemClickListener itemListener = new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) {
switch(position){
case 3:
HttpUtil.UpdateTradeStatus(trade_number, "3");
Toast.makeText(TradeStatus.this, "拒签修改成功!", Toast.LENGTH_LONG).show();
break;
}
}
};
}

184
code/WiFi.java Normal file
View File

@ -0,0 +1,184 @@
package info.ericyue.es.activity;
import java.lang.reflect.Method;
import android.app.ProgressDialog;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
public class WiFi{
private Context context;
/**
* WIFI-AP状态码
*/
private static final int WIFI_AP_STATE_UNKNOWN = -1;
private static final int WIFI_AP_STATE_DISABLING = 0;
private static final int WIFI_AP_STATE_DISABLED = 1;
private static final int WIFI_AP_STATE_ENABLING = 2;
private static final int WIFI_AP_STATE_ENABLED = 3;
private static final int WIFI_AP_STATE_FAILED = 4;
/**
* APNAME中计划加入用户ID
*
*/
private static String ESCLIENTAPNAME ="\"ESCLIENTAP\"";
private static String ESCLIENTAPPASSWORD ="11111111";
private static String ESAPNAME ="\"MOONLIGHT\"";
private static String ESAPPASSWORD ="\"12345678\"";
private final String[] WIFI_STATE_TEXTSTATE = new String[] {
"DISABLING","DISABLED","ENABLING","ENABLED","FAILED"
};
private WifiManager wifi;
public WiFi(Context context){
this.context=context;
}
public void connectWiFi(){
wifi=(WifiManager) context.getSystemService(Context.WIFI_SERVICE);
connectToESMobile();
}
// getWindow().addFlags(
// WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD//解除非加锁的锁屏状态
// |WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON// 当此窗口为用户可见时保持设备常开并保持亮度不变
// |WindowManager.LayoutParams.FLAG_DIM_BEHIND//亮度变暗
// );
/**
*
* @param v
*/
public void toggleWifi(View v) {
boolean wifiApIsOn = getWifiAPState()==WIFI_AP_STATE_ENABLED || getWifiAPState()==WIFI_AP_STATE_ENABLING;
new SetWifiAPTask(!wifiApIsOn,false).execute();
}
public void close(View v) {
boolean wifiApIsOn = getWifiAPState()==WIFI_AP_STATE_ENABLED || getWifiAPState()==WIFI_AP_STATE_ENABLING;
if (wifiApIsOn) {
new SetWifiAPTask(false,true).execute();
} else {
}
}
/**
* Endable/disable wifi
* @param enabled
* @return WifiAP state
*/
private int setWifiApEnabled(boolean enabled) {
if (enabled && null!=wifi.getConnectionInfo()) {
wifi.setWifiEnabled(false);
try {Thread.sleep(1500);} catch (Exception e) {}
}
int state = WIFI_AP_STATE_UNKNOWN;
try {
wifi.setWifiEnabled(false);
Method method1 = wifi.getClass().getMethod("setWifiApEnabled",WifiConfiguration.class, boolean.class);
WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID =ESCLIENTAPNAME;
netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
netConfig.preSharedKey = ESCLIENTAPPASSWORD ;
method1.invoke(wifi, netConfig, enabled);
Method method2 = wifi.getClass().getMethod("getWifiApState");
state = (Integer) method2.invoke(wifi);
} catch (Exception e) {
Log.e("WiFi监听服务", e.getMessage());
}
if (!enabled) {
int loopMax = 10;
while (loopMax>0 && (getWifiAPState()==WIFI_AP_STATE_DISABLING
|| getWifiAPState()==WIFI_AP_STATE_ENABLED
|| getWifiAPState()==WIFI_AP_STATE_FAILED)) {
try {Thread.sleep(500);loopMax--;} catch (Exception e) {}
}
wifi.setWifiEnabled(true);
} else if (enabled) {
int loopMax = 10;
while (loopMax>0 && (getWifiAPState()==WIFI_AP_STATE_ENABLING
|| getWifiAPState()==WIFI_AP_STATE_DISABLED
|| getWifiAPState()==WIFI_AP_STATE_FAILED)) {
try {Thread.sleep(500);loopMax--;} catch (Exception e) {}
}
}
return state;
}
private int getWifiAPState() {
int state = WIFI_AP_STATE_UNKNOWN;
try {
Method method2 = wifi.getClass().getMethod("getWifiApState");
state = (Integer) method2.invoke(wifi);
} catch (Exception e) {}
Log.d("Wifi", "getWifiAPState.state " + (-1==state?"UNKNOWN":WIFI_STATE_TEXTSTATE[state]));
return state;
}
private void updateStatusDisplay() {
if (getWifiAPState()==WIFI_AP_STATE_ENABLED || getWifiAPState()==WIFI_AP_STATE_ENABLING) {
Log.i("WIFI","Turn off");
} else {
Log.i("WiFi","Turn on");
}
}
public boolean connectToESMobile(){
WifiManager wifi = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = ESAPNAME;
wc.preSharedKey = ESAPPASSWORD ;
wc.hiddenSSID = true;
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res = wifi.addNetwork(wc);
return wifi.enableNetwork(res, true);
}
/**
* 开启WIFIAP线程
* @author Moonlight
*/
class SetWifiAPTask extends AsyncTask<Void, Void, Void> {
boolean mMode;
boolean mFinish;
public SetWifiAPTask(boolean mode, boolean finish) {
mMode = mode;
mFinish = finish;
}
ProgressDialog d = new ProgressDialog(context);
@Override
protected void onPreExecute() {
super.onPreExecute();
d.setMessage("正在"+(mMode?"打开":"关闭") +"WiFi无线接入点"+"...");
d.setTitle("请稍后...");
d.show();
}
@Override
protected Void doInBackground(Void... params) {
setWifiApEnabled(mMode);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
d.dismiss();
} catch (IllegalArgumentException e) {
e.printStackTrace();
};
updateStatusDisplay();
if (mFinish) ;
}
}
}

108
code/WorkStatistics.java Normal file
View File

@ -0,0 +1,108 @@
package info.ericyue.es.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import info.ericyue.es.R;
public class WorkStatistics extends Activity {
private ListView listView;
private String pid;
private String[] str=new String[3];
private Bundle bundle;
// private WebView webview;
public static void launch(Context c,Bundle bundle){
Intent intent = new Intent(c, WorkStatistics.class);
intent.putExtras(bundle);
c.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.workstatistics);
bundle=this.getIntent().getExtras();
listView=(ListView) findViewById(R.id.statList);
listView.setCacheColorHint(0);
listView.setAlwaysDrawnWithCacheEnabled(true);
pid = bundle.getString("username");
try {
queryDatebase();
} catch (InterruptedException e) {
e.printStackTrace();
}
fillItemList();
}
public void queryDatebase() throws InterruptedException {
String tmp = query_work(pid);
String[] item=tmp.split("/");
str[0]="今日共投递件"+item[0];
str[1]="本周共投递件"+item[1];
str[2]="本月共投递件"+item[2];
}
private String query_work(String id) throws InterruptedException {
WorkStatistics.NetThread sockethread = new WorkStatistics.NetThread();
sockethread.setValue(id);
sockethread.start();
sockethread.join();
return sockethread.result;
}
class NetThread extends Thread
{
private PrintWriter pw=null;
private BufferedReader br=null;
private String Id;
public String result;
public void run(){
try {
pw=LoginActivity.pw;
br=LoginActivity.br;
pw.println("workstatistics");
pw.println(Id);
pw.flush();
result=br.readLine();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setValue(String myid) {
Id = myid;
}
}
private void fillItemList(){
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
String[] itemStr={"今日投递总数","本周投递总数","本月投递总数"};
for(int i=0;i<3;i++){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemTitle", itemStr[i]);
map.put("ItemText", str[i]);
listItem.add(map);
}
SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
R.layout.worklist,
new String[] {"ItemTitle","ItemText"},
new int[] {R.id.ItemTitle,R.id.ItemText}
);
listView.setAdapter(listItemAdapter);
}
}