MainActivity.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. package com.usai.redant.photo;
  2. import java.io.ByteArrayOutputStream;
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.Serializable;
  8. import java.text.SimpleDateFormat;
  9. import java.util.ArrayList;
  10. import java.util.Date;
  11. import com.usai.util.Network;
  12. import com.usai.util.dbUtil;
  13. import com.usai.util.dbgUtil;
  14. import android.graphics.Bitmap;
  15. import android.graphics.BitmapFactory;
  16. import android.location.Location;
  17. import android.location.LocationListener;
  18. import android.location.LocationManager;
  19. import android.media.ThumbnailUtils;
  20. import android.net.Uri;
  21. import android.os.Bundle;
  22. import android.os.Environment;
  23. import android.provider.MediaStore;
  24. import android.app.Activity;
  25. import android.app.AlertDialog;
  26. import android.content.BroadcastReceiver;
  27. import android.content.ContentValues;
  28. import android.content.Context;
  29. import android.content.DialogInterface;
  30. import android.content.Intent;
  31. import android.content.IntentFilter;
  32. import android.content.SharedPreferences;
  33. import android.database.sqlite.SQLiteDatabase;
  34. import android.text.Editable;
  35. import android.text.TextWatcher;
  36. import android.util.Log;
  37. import android.view.KeyEvent;
  38. import android.view.Menu;
  39. import android.view.MenuItem;
  40. import android.view.View;
  41. import android.widget.EditText;
  42. import android.widget.ImageButton;
  43. import android.widget.ImageView;
  44. import android.widget.TextView;
  45. public class MainActivity extends Activity
  46. {
  47. // static final int ACTIVITY_CAMERA = 0;
  48. // static final int ACTIVITY_VIEW = 1;
  49. // static final String serverurl = "http://192.168.23.1/xampp/";
  50. static final String TAG = "MainActivity";
  51. static final int REQUEST_TAKE_PHOTO = 1;
  52. static final int REQUEST_PREVIEW = 4;
  53. static final int REQUEST_SCAN_BARCODE = 2;
  54. static final int REQUEST_LOCKER = 3;
  55. // HashMap<String, String> hashMap = new HashMap<String, String>();
  56. // ArrayList<String> pic_file = new ArrayList<String>();
  57. // ArrayList<bitmap>
  58. // ArrayList<>
  59. // private String thumbpath = null;
  60. private int iwidth = 640;
  61. private int iheight = 480;
  62. private File photoFile = null;
  63. Bitmap thumbBitmap = null;
  64. // private int iPhotoCount = 0;
  65. public String LastFileName = "";
  66. private boolean m_blocked = false;
  67. TextView m_tvalert;
  68. // private String user;
  69. // private String password;
  70. // String m_sName;
  71. // String m_sPassword;
  72. ArrayList<String> photoList = new ArrayList<String>();
  73. // @Override
  74. // protected void onResume()
  75. // {
  76. // //sendBroadcast(new Intent("REDANT.POP.REQUEST_LOCATION_CHANGED"));
  77. // super.onResume();
  78. // }
  79. private void StartCamera()
  80. {
  81. Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  82. // Ensure that there's a camera activity to handle the intent
  83. if (takePictureIntent.resolveActivity(getPackageManager()) != null)
  84. {
  85. // Create the File where the photo should go
  86. // File photoFile = null;
  87. if (photoFile != null)
  88. photoFile = null;
  89. try
  90. {
  91. photoFile = createImageFile();
  92. }
  93. catch (IOException ex)
  94. {
  95. // Error occurred while creating the File
  96. // ...
  97. }
  98. // Continue only if the File was successfully created
  99. Log.i(TAG, photoFile.toString());
  100. if (photoFile != null)
  101. {
  102. Log.i(TAG, "start system camera====================>");
  103. takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
  104. Uri.fromFile(photoFile));
  105. startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
  106. }
  107. }
  108. }
  109. @Override
  110. public boolean onKeyDown(int keyCode, KeyEvent event)
  111. {
  112. if (keyCode == KeyEvent.KEYCODE_BACK)
  113. {
  114. dbgUtil.fileLog("back button click , clear&exit");
  115. clear();
  116. }
  117. return super.onKeyDown(keyCode, event);
  118. }
  119. @Override
  120. protected void onResume()
  121. {
  122. sendBroadcast(new Intent("REDANT.POP.GPS_ON"));
  123. super.onResume();
  124. }
  125. @Override
  126. protected void onPause()
  127. {
  128. sendBroadcast(new Intent("REDANT.POP.GPS_OFF"));
  129. // TODO Auto-generated method stub
  130. super.onPause();
  131. }
  132. @Override
  133. protected void onCreate(Bundle savedInstanceState)
  134. {
  135. Log.d(TAG, "=======================>MainActivity Created!");
  136. super.onCreate(savedInstanceState);
  137. setContentView(R.layout.activity_main1);
  138. setTitle(getTitle() + "(" + RedAntApplication.station_name + ")");
  139. ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
  140. thumbsImageView.setOnClickListener(new View.OnClickListener()
  141. {
  142. @Override
  143. public void onClick(View v)
  144. {
  145. if (photoList.size() < 1)
  146. return;
  147. Intent intent = new Intent(MainActivity.this,
  148. PhotoPreviewActivity.class);
  149. intent.putExtra("pic_list", (Serializable) photoList);
  150. startActivityForResult(intent, REQUEST_PREVIEW);
  151. }
  152. });
  153. // m_sName = intent.getStringExtra("user");
  154. // m_sPassword = intent.getStringExtra("password");
  155. Log.d(TAG, "user=" + RedAntApplication.user + ",password="
  156. + RedAntApplication.password);
  157. IntentFilter msgFilter = new IntentFilter();
  158. Intent intent = getIntent();
  159. msgFilter.addAction("android.intent.action.SCREEN_OFF");
  160. msgFilter.addAction("REDANT.POP.STATION_CHANGE");
  161. msgFilter.addAction("REDANT.POP.STATION_NOT_CHANGE");
  162. msgFilter.addAction("REDANT.POP.FINISH_UPLOAD_QUEUE");
  163. msgFilter.addAction("REDANT.POP.FINISH_UPLOAD_QUEUE_WITH_ERROR");
  164. msgFilter.setPriority(2147483647);
  165. registerReceiver(MainActivityReceiver, msgFilter);
  166. Log.d(TAG, "=======================>msgFilter registed!");
  167. if (savedInstanceState != null)
  168. {
  169. thumbBitmap = getBitmap(savedInstanceState
  170. .getByteArray("thumbBitmap"));
  171. photoList.clear();
  172. // ArrayList list = (ArrayList)
  173. // Arrays.asList(savedInstanceState.getStringArray("arrayLabel"));
  174. photoList = savedInstanceState.getStringArrayList("photoList");
  175. TextView pidval = (TextView) findViewById(R.id.pidval);
  176. pidval.setText(savedInstanceState.getString("PIID"));
  177. // photoList = A
  178. // savedInstanceState.getStringArrayList("photoList");
  179. photoFile = (File) savedInstanceState.getSerializable("photoFile");
  180. if (thumbBitmap != null)
  181. {
  182. thumbsImageView.setImageBitmap(thumbBitmap);
  183. // Log.d(TAG, "load thumbpath==" + thumbpath);
  184. }
  185. // photoFile.delete();
  186. TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
  187. countTextView.setText(photoList.size() + " Photos");
  188. }
  189. ImageButton ibtnscan = (ImageButton) findViewById(R.id.ibtnScan);
  190. ibtnscan.setOnClickListener(new View.OnClickListener()
  191. {
  192. @Override
  193. public void onClick(View v)
  194. {
  195. Log.d(TAG, "==============>Click Scan button");
  196. Intent intent = new Intent();
  197. intent.setClass(MainActivity.this, CaptureActivity.class);
  198. startActivityForResult(intent, REQUEST_SCAN_BARCODE);
  199. }
  200. });
  201. ImageButton captureButton = (ImageButton) findViewById(R.id.ibtnCapture);
  202. captureButton.setOnClickListener(new View.OnClickListener()
  203. {
  204. @Override
  205. public void onClick(View v)
  206. {
  207. StartCamera();
  208. }
  209. });
  210. ImageButton uploadButton = (ImageButton) findViewById(R.id.ibtnOk);
  211. uploadButton.setOnClickListener(new View.OnClickListener()
  212. {
  213. @Override
  214. public void onClick(View v)
  215. {
  216. sendBroadcast(new Intent("REDANT.POP.REQUEST_LOCATION"));
  217. return;
  218. }
  219. });
  220. m_tvalert = (TextView) findViewById(R.id.tvalert);
  221. m_tvalert.setSelected(true);
  222. // Intent intent = ;
  223. sendBroadcast(new Intent("REDANT.POP.MODIFY_QUEUE"));
  224. updateUploadButton();
  225. }
  226. @Override
  227. protected void onDestroy()
  228. {
  229. // sendBroadcast(new Intent("REDANT.POP.GPS_OFF"));
  230. Log.d(TAG, "=======================>MainActivity Destroyed!");
  231. unregisterReceiver(MainActivityReceiver);
  232. Log.d(TAG, "=======================>msgFilter unregisted!");
  233. super.onDestroy();
  234. }
  235. @Override
  236. public boolean onCreateOptionsMenu(Menu menu)
  237. {
  238. // Inflate the menu; this adds items to the action bar if it is present.
  239. getMenuInflater().inflate(R.menu.main, menu);
  240. return true;
  241. }
  242. private File createImageFile() throws IOException
  243. {
  244. // Create an image file name
  245. String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
  246. .format(new Date());
  247. String imageFileName = "JPEG_" + timeStamp + "_";
  248. File storageDir = new File(Environment.getExternalStorageDirectory()
  249. .getPath() + "/redant/pop/temp/");
  250. File dir1 = new File(Environment.getExternalStorageDirectory()
  251. .getPath() + "/redant");
  252. File dir2 = new File(Environment.getExternalStorageDirectory()
  253. .getPath() + "/redant/pop");
  254. File dir3 = new File(Environment.getExternalStorageDirectory()
  255. .getPath() + "/redant/pop/temp");
  256. if (!dir1.exists())
  257. {
  258. boolean b = dir1.mkdir();
  259. }
  260. if (!dir2.exists())
  261. {
  262. boolean b = dir2.mkdir();
  263. }
  264. if (!dir3.exists())
  265. {
  266. boolean b = dir3.mkdir();
  267. }
  268. // Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
  269. // Log.d(TAG, "DIR:" + storageDir);
  270. LastFileName = storageDir + imageFileName + ".jpg";
  271. Log.d(TAG, "File:" + LastFileName);
  272. File image = File.createTempFile(imageFileName, /* prefix */
  273. ".jpg", /* suffix */
  274. storageDir /* directory */
  275. );
  276. // Save a file: path for use with ACTION_VIEW intents
  277. // mCurrentPhotoPath = "file:" + image.getAbsolutePath();
  278. return image;
  279. }
  280. boolean createDir(String path)
  281. {
  282. Log.i(TAG, "readFile:createDir=" + path);
  283. boolean ret = false;
  284. try
  285. {
  286. File file = new File(path);
  287. if (!file.exists())
  288. file.mkdirs();
  289. if (!file.isDirectory())
  290. {
  291. ret = file.mkdirs();
  292. }
  293. }
  294. catch (Exception e)
  295. {
  296. Log.d(TAG, e.toString());
  297. }
  298. return ret;
  299. }
  300. void updateUploadButton()
  301. {
  302. TextView pidval = (TextView) findViewById(R.id.pidval);
  303. ImageButton ibtnUpload = (ImageButton) findViewById(R.id.ibtnOk);
  304. if (photoList.size() > 0 && pidval.getText().length() > 0)
  305. {
  306. ibtnUpload.setVisibility(View.VISIBLE);
  307. }
  308. else
  309. {
  310. ibtnUpload.setVisibility(View.INVISIBLE);
  311. }
  312. }
  313. /*
  314. * (non-Javadoc)
  315. *
  316. * @see android.app.Activity#onActivityResult(int, int,
  317. * android.content.Intent)
  318. */
  319. @Override
  320. public void onActivityResult(int requestCode, int resultCode, Intent data)
  321. {
  322. if (requestCode == REQUEST_TAKE_PHOTO)
  323. // ������������յ�ͼƬ
  324. if (resultCode == Activity.RESULT_OK) // ��������
  325. {
  326. Log.d(TAG, photoFile.toString());
  327. photoList.add(photoFile.toString());
  328. StartCamera();
  329. // iPhotoCount++;
  330. super.onActivityResult(requestCode, resultCode, data);
  331. }
  332. else
  333. {
  334. ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
  335. if (photoList.size() > 0)
  336. {
  337. thumbBitmap = ThumbnailUtils.extractThumbnail(BitmapFactory
  338. .decodeFile(photoList.get(photoList.size() - 1)),
  339. iwidth, iheight);
  340. if (thumbBitmap != null)
  341. thumbsImageView.setImageBitmap(thumbBitmap);
  342. }
  343. photoFile.delete();
  344. TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
  345. countTextView.setText(photoList.size() + " Photos");
  346. // ImageButton ibtnUpload = (ImageButton)
  347. // findViewById(R.id.ibtnOk);
  348. updateUploadButton();
  349. }
  350. else if (requestCode == REQUEST_LOCKER)
  351. {
  352. if (resultCode == Activity.RESULT_OK)
  353. m_blocked = false;
  354. }
  355. else if (requestCode == REQUEST_PREVIEW)
  356. {
  357. for (int i = 0; i < photoList.size(); i++)
  358. {
  359. File file = new File(photoList.get(i));
  360. if (!file.exists())
  361. {
  362. photoList.remove(i);
  363. i--;
  364. }
  365. }
  366. TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
  367. countTextView.setText(photoList.size() + " Photos");
  368. if (photoList.size() == 0)
  369. {
  370. ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
  371. thumbsImageView.setImageResource(R.drawable.no_pic);
  372. thumbBitmap = null;
  373. }
  374. }
  375. else if (requestCode == REQUEST_SCAN_BARCODE)
  376. {
  377. if (resultCode == Activity.RESULT_OK)
  378. {
  379. Bundle bundle = data.getExtras();
  380. String pid = bundle.getString("pid");
  381. Log.d(TAG,
  382. "REQUEST_SCAN_BARCODE==========>pid="
  383. + bundle.getString("pid"));
  384. TextView pidval = (TextView) findViewById(R.id.pidval);
  385. pidval.setText(pid);
  386. updateUploadButton();
  387. }
  388. }
  389. super.onActivityResult(requestCode, resultCode, data);
  390. }
  391. public void saveMyBitmap(String bitName, Bitmap mBitmap)
  392. {
  393. File f = new File("/sdcard/" + bitName + ".png");
  394. try
  395. {
  396. f.createNewFile();
  397. }
  398. catch (IOException e)
  399. {
  400. // TODO Auto-generated catch block
  401. // DebugMessage.put("�ڱ���ͼƬʱ����" + e.toString());
  402. }
  403. FileOutputStream fOut = null;
  404. try
  405. {
  406. fOut = new FileOutputStream(f);
  407. }
  408. catch (FileNotFoundException e)
  409. {
  410. e.printStackTrace();
  411. }
  412. mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
  413. try
  414. {
  415. fOut.flush();
  416. }
  417. catch (IOException e)
  418. {
  419. e.printStackTrace();
  420. }
  421. try
  422. {
  423. fOut.close();
  424. }
  425. catch (IOException e)
  426. {
  427. e.printStackTrace();
  428. }
  429. }
  430. // boolean confirm_upload()
  431. // {
  432. // boolean bret = false;
  433. // final Boolean b;
  434. //
  435. // return bret;
  436. // }
  437. @Override
  438. public boolean onOptionsItemSelected(MenuItem item)
  439. {
  440. // TODO Auto-generated method stub
  441. switch (item.getItemId())
  442. {
  443. case R.id.action_clear:
  444. dbgUtil.fileLog("menu item clear click , clear...");
  445. clear();
  446. break;
  447. case R.id.action_type_pid:
  448. {
  449. final View edit = new EditText(this);
  450. new AlertDialog.Builder(this)
  451. .setIconAttribute(android.R.attr.alertDialogIcon)
  452. .setTitle(R.string.title_input_pid)
  453. .setView(edit)
  454. .setPositiveButton(android.R.string.ok,
  455. new DialogInterface.OnClickListener()
  456. {
  457. public void onClick(DialogInterface dialog,
  458. int whichButton)
  459. {
  460. String pid = ((EditText) edit)
  461. .getText().toString();
  462. TextView pidval = (TextView) findViewById(R.id.pidval);
  463. pidval.setText(pid);
  464. updateUploadButton();
  465. /* User clicked OK so do some stuff */
  466. }
  467. })
  468. .setNegativeButton(android.R.string.cancel,
  469. new DialogInterface.OnClickListener()
  470. {
  471. public void onClick(DialogInterface dialog,
  472. int whichButton)
  473. {
  474. updateUploadButton();
  475. /* User clicked cancel so do some stuff */
  476. }
  477. }).create().show();
  478. }
  479. break;
  480. case R.id.action_server_settings:
  481. {
  482. Intent intent = new Intent();
  483. intent.setClass(MainActivity.this, ServerSettingActivity.class);
  484. startActivity(intent);
  485. }
  486. break;
  487. case R.id.action_view_queue:
  488. {
  489. Intent intent = new Intent();
  490. intent.setClass(MainActivity.this, UploadQueueActivity.class);
  491. startActivity(intent);
  492. break;
  493. }
  494. default:
  495. break;
  496. }
  497. return super.onOptionsItemSelected(item);
  498. }
  499. @Override
  500. protected void onSaveInstanceState(Bundle outState)
  501. {
  502. // TODO Auto-generated method stub
  503. super.onSaveInstanceState(outState);
  504. if (photoFile != null)
  505. outState.putSerializable("photoFile", photoFile);
  506. if (thumbBitmap != null)
  507. outState.putByteArray("thumbBitmap", getBytes(thumbBitmap));// ("thumbBitmap",
  508. // (Object)thumbBitmap);
  509. // outState.putString("thumbpath",
  510. // thumbpath);
  511. // outState.putString("m_sName", m_sName);
  512. // outState.putString("m_sPassword", m_sPassword);
  513. outState.putStringArrayList("photoList", photoList);
  514. // Log.d(TAG, "save thumbpath==" + thumbpath);
  515. //outState.putInt("iPhotoCount", photoList.size());
  516. TextView pidval = (TextView) findViewById(R.id.pidval);
  517. outState.putString("PIID", pidval.getText().toString());
  518. }
  519. public static byte[] getBytes(Bitmap bitmap)
  520. {
  521. // ʵ�����ֽ����������
  522. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  523. bitmap.compress(Bitmap.CompressFormat.PNG, 0, baos);// ѹ��λͼ
  524. return baos.toByteArray();// ���������ֽ�����
  525. }
  526. public static Bitmap getBitmap(byte[] data)
  527. {
  528. if (data == null)
  529. return null;
  530. return BitmapFactory.decodeByteArray(data, 0, data.length);// ���ֽ��������λͼ
  531. }
  532. private void clear()
  533. {
  534. for (int i = 0; i < photoList.size(); i++)
  535. {
  536. String timeStamp = new SimpleDateFormat("yyyy_MM_dd")
  537. .format(new Date());
  538. File storageDir = new File(Environment.getExternalStorageDirectory()
  539. .getPath() + "/redant/pop/clear/"+timeStamp);
  540. if (!storageDir.exists())
  541. storageDir.mkdirs();
  542. // File dir1 = new File(Environment.getExternalStorageDirectory()
  543. // .getPath() + "/redant");
  544. // File dir2 = new File(Environment.getExternalStorageDirectory()
  545. // .getPath() + "/redant/pop");
  546. // File dir3 = new File(Environment.getExternalStorageDirectory()
  547. // .getPath() + "/redant/pop/clear");
  548. //
  549. //
  550. // if (!dir1.exists())
  551. // {
  552. // boolean b = dir1.mkdir();
  553. // }
  554. // if (!dir2.exists())
  555. // {
  556. // boolean b = dir2.mkdir();
  557. // }
  558. // if (!dir3.exists())
  559. // {
  560. // boolean b = dir3.mkdir();
  561. // }
  562. //
  563. // if (!storageDir.exists())
  564. // {
  565. // boolean b = storageDir.mkdir();
  566. // }
  567. File srcFile = new File(photoList.get(i));
  568. // file.delete();
  569. dbgUtil.fileLog("move file "+srcFile.getName()+" to "+Environment.getExternalStorageDirectory()
  570. .getPath() + "/redant/pop/clear/"+timeStamp + File.separator);
  571. srcFile.renameTo(new File(Environment.getExternalStorageDirectory()
  572. .getPath() + "/redant/pop/clear/"+timeStamp + File.separator + srcFile.getName()));
  573. // // Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
  574. // // Log.d(TAG, "DIR:" + storageDir);
  575. // LastFileName = storageDir + imageFileName + ".jpg";
  576. // Log.d(TAG, "File:" + LastFileName);
  577. // File image = File.createTempFile(imageFileName, /* prefix */
  578. // ".jpg", /* suffix */
  579. // storageDir /* directory */
  580. // );
  581. }
  582. photoList.clear();
  583. TextView pidval = (TextView) findViewById(R.id.pidval);
  584. pidval.setText("");
  585. updateUploadButton();
  586. ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
  587. thumbsImageView.setImageResource(R.drawable.no_pic);
  588. thumbBitmap = null;
  589. TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
  590. countTextView.setText("no photo");
  591. }
  592. private void clearfornew()
  593. {
  594. photoList.clear();
  595. TextView pidval = (TextView) findViewById(R.id.pidval);
  596. pidval.setText("");
  597. updateUploadButton();
  598. ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
  599. thumbsImageView.setImageResource(R.drawable.no_pic);
  600. thumbBitmap = null;
  601. TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
  602. countTextView.setText("no photo");
  603. }
  604. private final BroadcastReceiver MainActivityReceiver = new BroadcastReceiver()
  605. {
  606. public void onReceive(
  607. Context context,
  608. Intent intent)
  609. {
  610. String action = intent
  611. .getAction();
  612. // 如果捕捉到的action是ACTION_BATTERY_CHANGED
  613. if ("REDANT.POP.USER_CHECK_FAILED"
  614. .equals(action))
  615. {
  616. m_tvalert
  617. .setTextColor(getResources()
  618. .getColor(
  619. R.color.message_fail));
  620. m_tvalert
  621. .setText("Upload failed:user verify failure.");
  622. }
  623. else if ("REDANT.POP.STATION_NOT_CHANGE"
  624. .equals(action))
  625. {
  626. new AlertDialog.Builder(
  627. MainActivity.this)
  628. .setIconAttribute(
  629. android.R.attr.alertDialogIcon)
  630. .setTitle(
  631. R.string.confirm_to_upload)
  632. .setMessage(
  633. "Upload to station "
  634. + RedAntApplication.station_name)
  635. .setPositiveButton(
  636. android.R.string.ok,
  637. new DialogInterface.OnClickListener()
  638. {
  639. public void onClick(
  640. DialogInterface dialog,
  641. int whichButton)
  642. {
  643. SQLiteDatabase db = dbUtil
  644. .OpenDB(MainActivity.this,
  645. null,
  646. true);
  647. TextView pidval = (TextView) findViewById(R.id.pidval);
  648. String pid = pidval
  649. .getText()
  650. .toString();
  651. for (int i = 0; i < photoList
  652. .size(); i++)
  653. {
  654. ContentValues cv = new ContentValues();
  655. cv.put("picker",
  656. RedAntApplication.user);
  657. cv.put("server",
  658. RedAntApplication.active_address);
  659. cv.put("err_code",
  660. Network.STATUS_WAIT);
  661. cv.put("pid",
  662. pid);
  663. cv.put("local_path",
  664. photoList
  665. .get(i));
  666. db.insert(
  667. "pics",
  668. null,
  669. cv);
  670. }
  671. dbUtil.CloseDB(db);
  672. // new
  673. // UploadTask().execute((Void)
  674. // null);
  675. clearfornew();
  676. sendBroadcast(new Intent(
  677. "REDANT.POP.RESET_LOCATION"));
  678. Intent intent = new Intent(
  679. "REDANT.POP.MODIFY_QUEUE");
  680. sendBroadcast(intent);
  681. }
  682. })
  683. .setNegativeButton(
  684. android.R.string.cancel,
  685. new DialogInterface.OnClickListener()
  686. {
  687. public void onClick(
  688. DialogInterface dialog,
  689. int whichButton)
  690. {
  691. // debug
  692. // update_location();
  693. }
  694. })
  695. .create()
  696. .show();
  697. }
  698. else if ("REDANT.POP.STATION_CHANGE"
  699. .equals(action))
  700. {
  701. sendBroadcast(new Intent(
  702. "REDANT.POP.RESET_LOCATION"));
  703. new AlertDialog.Builder(
  704. MainActivity.this)
  705. .setIconAttribute(
  706. android.R.attr.alertDialogIcon)
  707. .setTitle(
  708. R.string.location_changed)
  709. .setMessage(
  710. "We have detected that your position has changed,do you want to modify the server setting? ")
  711. .setPositiveButton(
  712. android.R.string.ok,
  713. new DialogInterface.OnClickListener()
  714. {
  715. public void onClick(
  716. DialogInterface dialog,
  717. int whichButton)
  718. {
  719. Intent intent = new Intent();
  720. intent.setClass(
  721. MainActivity.this,
  722. ServerSettingActivity.class);
  723. startActivity(intent);
  724. }
  725. })
  726. .setNegativeButton(
  727. android.R.string.cancel,
  728. new DialogInterface.OnClickListener()
  729. {
  730. public void onClick(
  731. DialogInterface dialog,
  732. int whichButton)
  733. {
  734. // debug
  735. // update_location();
  736. }
  737. })
  738. .create()
  739. .show();
  740. }
  741. else if ("REDANT.POP.FINISH_UPLOAD_QUEUE"
  742. .equals(action))
  743. {
  744. m_tvalert
  745. .setTextColor(getResources()
  746. .getColor(
  747. R.color.message_success));
  748. m_tvalert
  749. .setText("Upload successes!");
  750. }
  751. else if ("REDANT.POP.FINISH_UPLOAD_QUEUE_WITH_ERROR"
  752. .equals(action))
  753. {
  754. m_tvalert
  755. .setTextColor(getResources()
  756. .getColor(
  757. R.color.message_fail));
  758. m_tvalert
  759. .setText("Upload finish with some error!");
  760. }
  761. else if (action
  762. .equals(Intent.ACTION_SCREEN_OFF))
  763. {
  764. Log.d("hg",
  765. "�յ��㲥!!!=======>m_blocked="
  766. + m_blocked);
  767. if (m_blocked == true)
  768. return;
  769. SharedPreferences pref = RedAntApplication
  770. .getInstance()
  771. .getSharedPreferences(
  772. "POP",
  773. 0);
  774. boolean autologin = pref
  775. .getBoolean(
  776. "kepppass",
  777. false);
  778. if (autologin)
  779. return;
  780. Intent activityintent = new Intent();
  781. activityintent
  782. .setClass(
  783. MainActivity.this,
  784. LockerActivity.class);
  785. startActivityForResult(
  786. activityintent,
  787. REQUEST_LOCKER);
  788. Log.d(TAG,
  789. "===================>start locker");
  790. m_blocked = true;
  791. }
  792. }
  793. };
  794. }