DemoApplication.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package com.baidu.lbs.duanzu;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import org.apache.http.HttpResponse;
  6. import org.apache.http.HttpStatus;
  7. import org.apache.http.client.HttpClient;
  8. import org.apache.http.client.methods.HttpGet;
  9. import org.apache.http.impl.client.DefaultHttpClient;
  10. import android.app.Application;
  11. import android.content.Context;
  12. import android.net.ConnectivityManager;
  13. import android.net.NetworkInfo;
  14. import android.os.AsyncTask;
  15. import android.os.Handler;
  16. import com.baidu.lbs.duanzu.LBSListActivity.ContentAdapter;
  17. import com.baidu.lbs.duanzu.bdapi.LBSLocation;
  18. import com.baidu.lbs.duanzu.bdapi.LBSMapActivity;
  19. import com.baidu.location.BDLocation;
  20. /**
  21. * 小猪短租应用类,用来共享定位结果,列表与地图检索结果数据
  22. *
  23. * @author Lu.Jian
  24. *
  25. */
  26. public class DemoApplication extends Application {
  27. private static DemoApplication mInstance = null;
  28. public static final String strKey = "63418012748CD126610D926A0546374D0BFC86D5";
  29. // 定位结果
  30. public BDLocation currlocation = null;
  31. // 检索结果
  32. private List<ContentModel> list = new ArrayList<ContentModel>();
  33. // 用于更新检索结果后,刷新列表
  34. private ContentAdapter adapter;
  35. public static String networkType;
  36. private Handler handler;
  37. //云检索参数
  38. private HashMap<String, String> filterParams;
  39. private LBSListActivity listActivity;
  40. private LBSMapActivity mapActivity;
  41. @Override
  42. public void onCreate() {
  43. super.onCreate();
  44. mInstance = this;
  45. networkType = setNetworkType();
  46. // 启动定位
  47. LBSLocation.getInstance(this).startLocation();
  48. }
  49. public static DemoApplication getInstance() {
  50. return mInstance;
  51. }
  52. public LBSMapActivity getMapActivity() {
  53. return mapActivity;
  54. }
  55. public void setMapActivity(LBSMapActivity mapActivity) {
  56. this.mapActivity = mapActivity;
  57. }
  58. public LBSListActivity getListActivity() {
  59. return listActivity;
  60. }
  61. public void setListActivity(LBSListActivity listActivity) {
  62. this.listActivity = listActivity;
  63. }
  64. public ContentAdapter getAdapter() {
  65. return adapter;
  66. }
  67. public void setAdapter(ContentAdapter adapter) {
  68. this.adapter = adapter;
  69. }
  70. public void setList(List<ContentModel> list) {
  71. this.list = list;
  72. }
  73. public List<ContentModel> getList() {
  74. return list;
  75. }
  76. public Handler getHandler() {
  77. return handler;
  78. }
  79. public void setHandler(Handler handler) {
  80. this.handler = handler;
  81. }
  82. public HashMap<String, String> getFilterParams() {
  83. return filterParams;
  84. }
  85. public void setFilterParams(HashMap<String, String> filterParams) {
  86. this.filterParams = filterParams;
  87. }
  88. /**
  89. * 设置手机网络类型,wifi,cmwap,ctwap,用于联网参数选择
  90. * @return
  91. */
  92. static String setNetworkType() {
  93. String networkType = "wifi";
  94. ConnectivityManager manager = (ConnectivityManager) mInstance
  95. .getSystemService(Context.CONNECTIVITY_SERVICE);
  96. NetworkInfo netWrokInfo = manager.getActiveNetworkInfo();
  97. if (netWrokInfo == null || !netWrokInfo.isAvailable()) {
  98. // 当前网络不可用
  99. return "";
  100. }
  101. String info = netWrokInfo.getExtraInfo();
  102. if ((info != null)
  103. && ((info.trim().toLowerCase().equals("cmwap"))
  104. || (info.trim().toLowerCase().equals("uniwap"))
  105. || (info.trim().toLowerCase().equals("3gwap")) || (info
  106. .trim().toLowerCase().equals("ctwap")))) {
  107. // 上网方式为wap
  108. if (info.trim().toLowerCase().equals("ctwap")) {
  109. // 电信
  110. networkType = "ctwap";
  111. } else {
  112. networkType = "cmwap";
  113. }
  114. }
  115. return networkType;
  116. }
  117. public void callStatistics(){
  118. StatisticsTask task = new StatisticsTask();
  119. task.execute("http://api.map.baidu.com/images/blank.gif?t=92248538&platform=android&logname=lbsyunduanzu");
  120. }
  121. /*
  122. * 百度统计
  123. */
  124. class StatisticsTask extends AsyncTask<String, Integer, String> {
  125. // 可变长的输入参数,与AsyncTask.exucute()对应
  126. @Override
  127. protected String doInBackground(String... params) {
  128. try {
  129. HttpClient client = new DefaultHttpClient();
  130. // params[0] 代表连接的url
  131. HttpGet get = new HttpGet(params[0]);
  132. HttpResponse response = client.execute(get);
  133. int status = response.getStatusLine().getStatusCode();
  134. if(status == HttpStatus.SC_OK){
  135. }
  136. // 返回结果
  137. return null;
  138. } catch (Exception e) {
  139. e.printStackTrace();
  140. }
  141. return null;
  142. }
  143. @Override
  144. protected void onCancelled() {
  145. super.onCancelled();
  146. }
  147. @Override
  148. protected void onPostExecute(String result) {
  149. }
  150. @Override
  151. protected void onPreExecute() {
  152. }
  153. @Override
  154. protected void onProgressUpdate(Integer... values) {
  155. }
  156. }
  157. }