基于android系统的快递查询应用(一)
程序员文章站
2024-02-01 22:16:28
...
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.xiangxm.cls.cls_companyinfo;
import com.xiangxm.cls.cls_savehistory;
import com.xiangxm.myapp.MyApplication;
import com.xiangxm.myapp.aboutme;
import com.xiangxm.myapp.location;
import com.xiangxm.utils.Common;
public class MainActivity extends Activity implements
android.view.View.OnClickListener {
private LinearLayout selectCompanyLayout;
private Button searchBtn;
private Button historyBtn;
private EditText order_numTxt;
private TextView companynameTxt;
private TextView helpinfotext;
private Button locationbtn;
private Button aboutmebtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setUiOptions(
ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
setContentView(R.layout.activity_main);
myApplication = MyApplication.getInstance();
initView();
Common.closeWhenOncreate(MainActivity.this);// 进入界面关闭软键盘
}
/**
* 初始化界面
*/
public void initView() {
title = (TextView) findViewById(R.id.title);
phonenumber = (TextView) findViewById(R.id.phonenumbertxt);
helpinfotext = (TextView) findViewById(R.id.helpinfotext);
companynameTxt = (TextView) findViewById(R.id.companynametxt);
companynameTxt.setText("");
selectCompanyLayout = (LinearLayout) findViewById(R.id.companyname_layout);
searchBtn = (Button) findViewById(R.id.searchbtn);
historyBtn = (Button) findViewById(R.id.historybtn);
order_numTxt = (EditText) findViewById(R.id.order_numtxt);
locationbtn = (Button)findViewById(R.id.locationbtn);
aboutmebtn = (Button)findViewById(R.id.aboutmebtn);
selectCompanyLayout.setOnClickListener(this);
searchBtn.setOnClickListener(this);
historyBtn.setOnClickListener(this);
progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("正在为您查询...");
progressDialog.setCancelable(true);
progressDialog.setTitle("提示信息");
changeBtnBackground();
if (!Common.hasShortcut(this)) { // 创建快捷方式
Common.addShortcut(this);
}
if (!Common.onlineFlag(MainActivity.this)) {
Toast.makeText(this, "离线使用中,非联网状态不能查询订单信息!", Toast.LENGTH_SHORT)
.show();
}
}
private MyApplication myApplication;
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = null;
if (v.getId() == R.id.searchbtn) {
if (TextUtils.isEmpty(companynameTxt.getText())) {
Animation shakeAnim = AnimationUtils.loadAnimation(
MainActivity.this, R.anim.shake_x);
this.companynameTxt.startAnimation(shakeAnim);
Toast.makeText(MainActivity.this, "您还未选择快递公司!",
Toast.LENGTH_SHORT).show();
return;
} else if (TextUtils.isEmpty(order_numTxt.getText())) {
Animation shakeAnim = AnimationUtils.loadAnimation(
MainActivity.this, R.anim.shake_x);
this.order_numTxt.startAnimation(shakeAnim);
Toast.makeText(MainActivity.this, "您还未输入订单号!",
Toast.LENGTH_SHORT).show();
return;
}
String order_num = order_numTxt.getText().toString().trim();
Pattern p = Pattern.compile("[\\da-zA-Z]+?");
Matcher m = p.matcher(order_num);
if (!m.matches()) {
Toast.makeText(MainActivity.this, "您的订单号不符合标准,请检查!",
Toast.LENGTH_SHORT).show();
return;
}
infoMap.put("order_num", order_num);
infoMap.put("mark", "");// 备注信息暂时存为空
new MyThread(infoMap).start();
} else if (v.getId() == R.id.companyname_layout) {
intent = new Intent();
intent.setClass(MainActivity.this, SelectCompanyActivity.class);
startActivityForResult(intent, 6);
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
} else if (v.getId() == R.id.historybtn) {
boolean bol = cls_savehistory.checkHasDataOrNot(Common.dbh);
if (bol) {
// 可伸缩的listview
intent = new Intent();
intent.setClass(MainActivity.this,
CheckPackageHisActivity.class);
overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
startActivity(intent);
} else {
Toast.makeText(MainActivity.this, "暂无历史记录!", Toast.LENGTH_SHORT)
.show();
}
}
}
HashMap<String, String> infoMap = new HashMap<String, String>();
// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
// // MenuItem item = menu.add(0, SETTINGS_ID, 0, "settings");
// // item.setIcon(R.drawable.ic_setting);
// // item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
// // return true;
// MenuInflater inflater = getMenuInflater();
// inflater.inflate(R.menu.activity_main, menu);
//
// return super.onCreateOptionsMenu(menu);
// }
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {// 处理点击事件 最下面
// switch (item.getItemId()) {
// /*
// * case R.id.menu_settings: startActivity(new Intent(this,
// * SettingActivity.class)); break;
// */
//
// case R.id.menu_delete:
//
// new AlertDialog.Builder(this).setTitle("Action Menu Item")
// .setPositiveButton("确认", null)
// .setNegativeButton("取消", null).show();
//
// break;
// default:
// break;
// }
//
// return super.onOptionsItemSelected(item);
// }
/**
* 修改按钮背景图片
*/
public void changeBtnBackground() {
class MyBtnOnTouch implements OnTouchListener {
int drawable[] = null;
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.searchbtn) {
drawable = new int[] { R.drawable.searchbtn,
R.drawable.searchbtn_pressed };
} else if (v.getId() == R.id.historybtn) {
drawable = new int[] { R.drawable.history_btn_normal,
R.drawable.history_btn_pressed };
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
v.setBackgroundResource(drawable[1]);
break;
case MotionEvent.ACTION_UP:
v.setBackgroundResource(drawable[0]);
break;
}
return false;
}
}
searchBtn.setOnTouchListener(new MyBtnOnTouch());
historyBtn.setOnTouchListener(new MyBtnOnTouch());
}
private static final int WAITTING = 0;
private static final int FINISHED = 1;
private static final int ERROR = 2;
private ProgressDialog progressDialog;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case WAITTING:
progressDialog.show();
break;
case ERROR:
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
break;
case FINISHED:
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
Common.closeKeyboardCommAct(MainActivity.this);// 关闭键盘
break;
case 10:
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
Toast.makeText(MainActivity.this, "未获取到相关信息,请验证查询条件!",
Toast.LENGTH_SHORT).show();
break;
}
super.handleMessage(msg);
}
};
/**
* 用于存放结果的map key:timeList value: infoList
* **/
private HashMap<List<String>, List<String>> resultMap = new HashMap<List<String>, List<String>>();
/**
* 子线程联网获取数据
*
* @author xiangxm
*
*/
class MyThread extends Thread {
private HashMap<String, String> threadMap = null;
public MyThread(HashMap<String, String> map) {
threadMap = new HashMap<String, String>();
this.threadMap = map;
}
@Override
public void run() {
int rand = (int) Math.random() * 1000 + 1000;
String strurl = "http://wap.kuaidi100.com/q.jsp?rand=" + rand
+ "&id=" + threadMap.get("companyId") + "&postid="
+ threadMap.get("order_num") + "&fromWeb=null";
Message msg = new Message();
msg.what = WAITTING;
mHandler.sendMessage(msg);// http://wap.kuaidi100.com/q.jsp?rand=1000&id=aae&postid=987654321&fromWeb=null
String result = getData(strurl);// http://m.kuaidi100.com/index_all.html?type=yuantong&postid=7409440775
if (result.equals("")) {
msg = new Message();
msg.what = 10;
mHandler.sendMessage(msg);
return;
}
org.jsoup.nodes.Document doc = Jsoup.parse(result);// 7409440775
Elements element = doc.body().getElementsByTag("p");
Object[] objArr = element.toArray();
Pattern p = Pattern.compile("<.+?>|\\>|\\·",
Pattern.DOTALL);
String tempStr = null;
ArrayList<String> timeList = new ArrayList<String>();// 存放快递的时间
ArrayList<String> infoList = new ArrayList<String>();// 存放快递的对应时间点的信息
for (int i = 3; i < objArr.length - 2; i++) {
Matcher m = p.matcher(objArr[i].toString());
tempStr = m.replaceAll("");
if (TextUtils.isEmpty(tempStr)) {
continue;
} else if (tempStr.startsWith("建议操作")) {
msg = new Message();
msg.what = 10;
mHandler.sendMessage(msg);
return;
}
// 2013-11-17 00:25:57 福建省泉州市石狮市公司 已收件 操作员:包叶明
timeList.add(new String(tempStr.substring(0, 19)));
infoList.add(new String(tempStr.substring(20)));
}
Log.e("----------时间---------最后结果", timeList.toString());
Log.e("----------物流的详细信息---------最后结果", infoList.toString());
msg = new Message();
msg.what = FINISHED;
mHandler.sendMessage(msg);
if (timeList.isEmpty() || infoList.isEmpty()) {
msg = new Message();
msg.what = 10;
mHandler.sendMessage(msg);
return;
}
Intent intent = new Intent();
intent.setClass(MainActivity.this, PackageDetailInfoActivity.class);
intent.putStringArrayListExtra("timeList", timeList);
intent.putStringArrayListExtra("infoList", infoList);
Bundle bundle = new Bundle();
bundle.putString("companyName", infoMap.get("companyName"));// 公司名称
bundle.putString("companyId", infoMap.get("companyId"));
bundle.putString("order_num", infoMap.get("order_num"));// 运单号
intent.putExtras(bundle);
startActivity(intent);
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
}
}
/**
*
* @param strurl
* @return
*/
public String getData(String strurl) {
String output = "";
URL url;
try {
url = new URL(strurl);
InputStream is = url.openStream();
BufferedReader buffer = new BufferedReader(new InputStreamReader(
is, "UTF-8"));
String tem = "";
while ((tem = buffer.readLine()) != null) {
output += tem;
}
return output;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
// 点击空白处 软键盘消失
@Override
public boolean onTouchEvent(MotionEvent event) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if (imm != null && imm.isActive()) {
return imm.hideSoftInputFromWindow(this.getCurrentFocus()
.getWindowToken(), 0);
}
return false;
}
long waitTime = 2000;
long touchTime = 0;
@Override
public void onBackPressed() {
long currentTime = System.currentTimeMillis();
if ((currentTime - touchTime) >= waitTime) {
Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
touchTime = currentTime;
} else {
finish();
}
}
private TextView title;
private TextView phonenumber;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode == 8 && requestCode == 6) {
Bundle bundle = data.getExtras();
if (bundle == null) {
Toast.makeText(MainActivity.this, "获取数据失败!", Toast.LENGTH_SHORT)
.show();
return;
}
infoMap = new HashMap<String, String>();
String name = bundle.getString("companyName");
String str = bundle.getString("companyId");
String id = TextUtils.isEmpty(str) ? "" : str;
infoMap.put("companyName", name);
infoMap.put("companyId", id);
List<String> resultList = cls_companyinfo.getCompanyName(
Common.dbh, id);
if (resultList.get(0).equals("")) {
helpinfotext.setVisibility(View.GONE);
title.setVisibility(View.GONE);
title.setText("");
} else {
title.setText("温馨提示:");
helpinfotext.setText("查询须知:" + resultList.get(0));
}
if (resultList.get(1).equals("")) {
phonenumber.setVisibility(View.GONE);
title.setVisibility(View.GONE);
title.setText("");
} else {
title.setText("温馨提示:");
phonenumber.setText("查询电话:" + resultList.get(1));
}
companynameTxt.setText(TextUtils.isEmpty(name) ? "" : name);
}
super.onActivityResult(requestCode, resultCode, data);
}
/*public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = getMenuInflater() ;
inflater.inflate(R.menu.mainactivity_menu, menu) ;
return super.onCreateOptionsMenu(menu);
}*/
public void main_aboutme(View v) {
Intent intent1 = new Intent();
intent1.setClass(MainActivity.this,aboutme.class);
startActivity(intent1);
}
public void main_location(View v) {
Intent intent1 = new Intent();
intent1.setClass(MainActivity.this,location.class);
startActivity(intent1);
}
}
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* <p>
* 关于画面
* </p>
*
* @author xiangxm 2013-12-8
*
*
*/
public class AboutActivity extends Activity implements OnTouchListener {
private TextView textView1;
private LinearLayout aboutLayout_1;
private LinearLayout aboutLayout_2;
private LinearLayout aboutLayout_3;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setUiOptions(
ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
setContentView(R.layout.activity_main);
setContentView(R.layout.aboutapplayout);
// textView1 = (TextView) findViewById(R.id.textView1);
textView1.setText("设置");
aboutLayout_1 = (LinearLayout) findViewById(R.id.aboutlayout_1);
aboutLayout_2 = (LinearLayout) findViewById(R.id.aboutlayout_2);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (v.getId()) {
case R.id.aboutlayout_1:
break;
case R.id.aboutlayout_2:
break;
}
return false;
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.xiangxm.cls.cls_companyinfo;
import com.xiangxm.myapp.MyApplication;
import com.xiangxm.sortlistview.CharacterParser;
import com.xiangxm.sortlistview.ClearEditText;
import com.xiangxm.sortlistview.PinyinComparator;
import com.xiangxm.sortlistview.SideBar;
import com.xiangxm.sortlistview.SideBar.OnTouchingLetterChangedListener;
import com.xiangxm.sortlistview.SortAdapter;
import com.xiangxm.sortlistview.SortModel;
import com.xiangxm.utils.Common;
/**
* 选择快递公司
* @author
*
*/
public class SelectCompanyActivity extends Activity implements OnClickListener {
private ListView sortListView;
private SideBar sideBar;
private TextView dialog;
private SortAdapter adapter;
private ClearEditText mClearEditText;
/**
* 汉字转换成拼音的类
*/
private CharacterParser characterParser;
private List<SortModel> SourceDateList;
/**
* 根据拼音来排列ListView里面的数据类
*/
private PinyinComparator pinyinComparator;
private Button backBtn;
private Context mcontext;
List<cls_companyinfo> companyInfoList = null;
private itemOnclickCallBack onclickCallBack;
private MyApplication myApplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.selectcompany_layout);
myApplication = MyApplication.getInstance();
companyInfoList = new ArrayList<cls_companyinfo>();
mcontext = this;
initViews();
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0:
// 刷新UI
break;
}
}
};
private void initViews() {
backBtn = (Button) findViewById(R.id.backBtn);
backBtn.setOnClickListener(this);
// 实例化汉字转拼音类
characterParser = CharacterParser.getInstance();
pinyinComparator = new PinyinComparator();
sideBar = (SideBar) findViewById(R.id.sidrbar);
dialog = (TextView) findViewById(R.id.dialog);
sideBar.setTextView(dialog);
// 设置右侧触摸监听
sideBar.setOnTouchingLetterChangedListener(new OnTouchingLetterChangedListener() {
@Override
public void onTouchingLetterChanged(String s) {
if (s != null) {
// 该字母首次出现的位置
int position = adapter.getPositionForSection(s.charAt(0));
if (position != -1) {
sortListView.setSelection(position);
}
}
}
});
sortListView = (ListView) findViewById(R.id.country_lvcountry);
sortListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// 这里要利用adapter.getItem(position)来获取当前position所对应的对象
Toast.makeText(getApplication(),
((SortModel) adapter.getItem(position)).getName(),
Toast.LENGTH_SHORT).show();
// view.setBackgroundColor(Color.parseColor("#E0EEEE"));
SortModel model = (SortModel) adapter.getItem(position);
Bundle bundle = new Bundle();
bundle.putString("companyName", model.getName());
bundle.putString("companyId", model.getCompanyId());
Intent intent = new Intent();
intent.putExtras(bundle);
setResult(8, intent);
overridePendingTransition(R.anim.push_left_out,
R.anim.push_left_in);
SelectCompanyActivity.this.finish();
}
});
// 动画效果
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(50);
set.addAnimation(animation);
animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
animation.setDuration(100);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(
set, 0.5f);
sortListView.setLayoutAnimation(controller);
mClearEditText = (ClearEditText) findViewById(R.id.filter_edit);
// 根据输入框输入值的改变来过滤搜索
mClearEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// 当输入框里面的值为空,更新为原来的列表,否则为过滤数据列表
filterData(s.toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
companyInfoList = cls_companyinfo.getCompanyInfoList(Common.dbh);
// companyInfoList.addAll(myApplication.getCompanyInfoList()) ;
SourceDateList = filledData(companyInfoList);// 数据源
// 根据a-z进行排序源数据
Collections.sort(SourceDateList, pinyinComparator);
adapter = new SortAdapter(SelectCompanyActivity.this, SourceDateList);
sortListView.setAdapter(adapter);
changeBtnBackground();// 修改按钮背景色
}
/**
* 为ListView填充数据
*
* @param date
* @return
*/
private List<SortModel> filledData(List<cls_companyinfo> list) {
List<SortModel> mSortList = new ArrayList<SortModel>();
int size = list.size();
for (int i = 0; i < size; i++) {
SortModel sortModel = new SortModel();
sortModel.setName(list.get(i).name);
sortModel.setCompanyId(list.get(i).id);
// 汉字转换成拼音
String pinyin = characterParser.getSelling(list.get(i).name);
String sortString = pinyin.substring(0, 1).toUpperCase();
// 正则表达式,判断首字母是否是英文字母
if (sortString.matches("[A-Z]")) {
sortModel.setSortLetters(sortString.toUpperCase());
} else {
sortModel.setSortLetters("#");
}
mSortList.add(sortModel);
}
return mSortList;
}
/**
* 根据输入框中的值来过滤数据并更新ListView
*
* @param filterStr
*/
private void filterData(String filterStr) {
List<SortModel> filterDateList = new ArrayList<SortModel>();
if (TextUtils.isEmpty(filterStr)) {
filterDateList = SourceDateList;
} else {
filterDateList.clear();
for (SortModel sortModel : SourceDateList) {
String name = sortModel.getName();
if (name.indexOf(filterStr.toString()) != -1
|| characterParser.getSelling(name).startsWith(
filterStr.toString())) {
filterDateList.add(sortModel);
}
}
}
// 根据a-z进行排序
Collections.sort(filterDateList, pinyinComparator);
adapter.updateListView(filterDateList);
}
public void setOnclickCallBack(itemOnclickCallBack onclickCallBack) {
this.onclickCallBack = onclickCallBack;
}
/**
* 接口用于回调
*
* @author
*
*/
public interface itemOnclickCallBack {
void itemOnClick(HashMap<String, String> map);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.backBtn) {// 回退
this.finish();
// overridePendingTransition(R.anim.push_left_out,
// R.anim.push_left_in);
}
}
/**
* 修改按钮背景图片
*/
public void changeBtnBackground() {
class MyBtnOnTouch implements OnTouchListener {
int drawable[] = null;
@Override
public boolean onTouch(View v, MotionEvent event) {
drawable = new int[] { R.drawable.back_button_selected,
R.drawable.back_button_normal };
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
v.setBackgroundResource(drawable[0]);
break;
case MotionEvent.ACTION_UP:
v.setBackgroundResource(drawable[1]);
break;
}
return false;
}
}
backBtn.setOnTouchListener(new MyBtnOnTouch());
}
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
/**
* <p>
* 父Activity 解决startActivityForResult() ,onActivityResult()不被调用问题
* </p>
*
* @author xiangxm 2013-12-8
*
*
*/
public class ParentActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
private setResultCallBack resultCallBack;
public void setResultCallBack(setResultCallBack resultCallBack) {
this.resultCallBack = resultCallBack;
}
/**
* 接口用于回调
*
* @author xiangxm
*
*/
public interface setResultCallBack {
void setResult(int requestCode, int resonseCode,Intent srcIntent);
// void getResult(int requestCode ,int resonseCode,Intent resultIntent) ;
}
}
以上是几个主要的程序,下一篇将介绍布局文件
转载于:https://my.oschina.net/tomcater/blog/222196
上一篇: 【C】16进制高4位低4位转ASCII码