| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897 |
- package com.usai.redant.photo;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.Serializable;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import com.usai.util.Network;
- import com.usai.util.dbUtil;
- import com.usai.util.dbgUtil;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.location.Location;
- import android.location.LocationListener;
- import android.location.LocationManager;
- import android.media.ThumbnailUtils;
- import android.net.Uri;
- import android.os.Bundle;
- import android.os.Environment;
- import android.provider.MediaStore;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.BroadcastReceiver;
- import android.content.ContentValues;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.content.SharedPreferences;
- import android.database.sqlite.SQLiteDatabase;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.ImageButton;
- import android.widget.ImageView;
- import android.widget.TextView;
- public class MainActivity extends Activity
- {
- // static final int ACTIVITY_CAMERA = 0;
- // static final int ACTIVITY_VIEW = 1;
- // static final String serverurl = "http://192.168.23.1/xampp/";
- static final String TAG = "MainActivity";
- static final int REQUEST_TAKE_PHOTO = 1;
- static final int REQUEST_PREVIEW = 4;
- static final int REQUEST_SCAN_BARCODE = 2;
- static final int REQUEST_LOCKER = 3;
- // HashMap<String, String> hashMap = new HashMap<String, String>();
- // ArrayList<String> pic_file = new ArrayList<String>();
- // ArrayList<bitmap>
- // ArrayList<>
- // private String thumbpath = null;
- private int iwidth = 640;
- private int iheight = 480;
- private File photoFile = null;
- Bitmap thumbBitmap = null;
- // private int iPhotoCount = 0;
- public String LastFileName = "";
- private boolean m_blocked = false;
- TextView m_tvalert;
- // private String user;
- // private String password;
- // String m_sName;
- // String m_sPassword;
- ArrayList<String> photoList = new ArrayList<String>();
- // @Override
- // protected void onResume()
- // {
- // //sendBroadcast(new Intent("REDANT.POP.REQUEST_LOCATION_CHANGED"));
- // super.onResume();
- // }
- private void StartCamera()
- {
- Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- // Ensure that there's a camera activity to handle the intent
- if (takePictureIntent.resolveActivity(getPackageManager()) != null)
- {
- // Create the File where the photo should go
- // File photoFile = null;
- if (photoFile != null)
- photoFile = null;
- try
- {
- photoFile = createImageFile();
- }
- catch (IOException ex)
- {
- // Error occurred while creating the File
- // ...
- }
- // Continue only if the File was successfully created
- Log.i(TAG, photoFile.toString());
- if (photoFile != null)
- {
- Log.i(TAG, "start system camera====================>");
- takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
- Uri.fromFile(photoFile));
- startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
- }
- }
- }
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK)
- {
- dbgUtil.fileLog("back button click , clear&exit");
- clear();
- }
- return super.onKeyDown(keyCode, event);
- }
- @Override
- protected void onResume()
- {
- sendBroadcast(new Intent("REDANT.POP.GPS_ON"));
- super.onResume();
- }
- @Override
- protected void onPause()
- {
- sendBroadcast(new Intent("REDANT.POP.GPS_OFF"));
- // TODO Auto-generated method stub
- super.onPause();
- }
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- Log.d(TAG, "=======================>MainActivity Created!");
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.activity_main1);
- setTitle(getTitle() + "(" + RedAntApplication.station_name + ")");
- ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
- thumbsImageView.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- if (photoList.size() < 1)
- return;
- Intent intent = new Intent(MainActivity.this,
- PhotoPreviewActivity.class);
- intent.putExtra("pic_list", (Serializable) photoList);
- startActivityForResult(intent, REQUEST_PREVIEW);
- }
- });
- // m_sName = intent.getStringExtra("user");
- // m_sPassword = intent.getStringExtra("password");
- Log.d(TAG, "user=" + RedAntApplication.user + ",password="
- + RedAntApplication.password);
- IntentFilter msgFilter = new IntentFilter();
- Intent intent = getIntent();
- msgFilter.addAction("android.intent.action.SCREEN_OFF");
- msgFilter.addAction("REDANT.POP.STATION_CHANGE");
- msgFilter.addAction("REDANT.POP.STATION_NOT_CHANGE");
- msgFilter.addAction("REDANT.POP.FINISH_UPLOAD_QUEUE");
- msgFilter.addAction("REDANT.POP.FINISH_UPLOAD_QUEUE_WITH_ERROR");
- msgFilter.setPriority(2147483647);
- registerReceiver(MainActivityReceiver, msgFilter);
- Log.d(TAG, "=======================>msgFilter registed!");
- if (savedInstanceState != null)
- {
- thumbBitmap = getBitmap(savedInstanceState
- .getByteArray("thumbBitmap"));
- photoList.clear();
- // ArrayList list = (ArrayList)
- // Arrays.asList(savedInstanceState.getStringArray("arrayLabel"));
- photoList = savedInstanceState.getStringArrayList("photoList");
-
- TextView pidval = (TextView) findViewById(R.id.pidval);
- pidval.setText(savedInstanceState.getString("PIID"));
- // photoList = A
- // savedInstanceState.getStringArrayList("photoList");
- photoFile = (File) savedInstanceState.getSerializable("photoFile");
- if (thumbBitmap != null)
- {
- thumbsImageView.setImageBitmap(thumbBitmap);
- // Log.d(TAG, "load thumbpath==" + thumbpath);
- }
- // photoFile.delete();
- TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
- countTextView.setText(photoList.size() + " Photos");
- }
- ImageButton ibtnscan = (ImageButton) findViewById(R.id.ibtnScan);
- ibtnscan.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- Log.d(TAG, "==============>Click Scan button");
- Intent intent = new Intent();
- intent.setClass(MainActivity.this, CaptureActivity.class);
- startActivityForResult(intent, REQUEST_SCAN_BARCODE);
- }
- });
- ImageButton captureButton = (ImageButton) findViewById(R.id.ibtnCapture);
- captureButton.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- StartCamera();
- }
- });
- ImageButton uploadButton = (ImageButton) findViewById(R.id.ibtnOk);
- uploadButton.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- sendBroadcast(new Intent("REDANT.POP.REQUEST_LOCATION"));
- return;
- }
- });
- m_tvalert = (TextView) findViewById(R.id.tvalert);
- m_tvalert.setSelected(true);
- // Intent intent = ;
- sendBroadcast(new Intent("REDANT.POP.MODIFY_QUEUE"));
- updateUploadButton();
- }
- @Override
- protected void onDestroy()
- {
- // sendBroadcast(new Intent("REDANT.POP.GPS_OFF"));
- Log.d(TAG, "=======================>MainActivity Destroyed!");
- unregisterReceiver(MainActivityReceiver);
- Log.d(TAG, "=======================>msgFilter unregisted!");
- super.onDestroy();
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- private File createImageFile() throws IOException
- {
- // Create an image file name
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
- .format(new Date());
- String imageFileName = "JPEG_" + timeStamp + "_";
- File storageDir = new File(Environment.getExternalStorageDirectory()
- .getPath() + "/redant/pop/temp/");
- File dir1 = new File(Environment.getExternalStorageDirectory()
- .getPath() + "/redant");
- File dir2 = new File(Environment.getExternalStorageDirectory()
- .getPath() + "/redant/pop");
- File dir3 = new File(Environment.getExternalStorageDirectory()
- .getPath() + "/redant/pop/temp");
-
- if (!dir1.exists())
- {
- boolean b = dir1.mkdir();
- }
- if (!dir2.exists())
- {
- boolean b = dir2.mkdir();
- }
- if (!dir3.exists())
- {
- boolean b = dir3.mkdir();
- }
- // Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
- // Log.d(TAG, "DIR:" + storageDir);
- LastFileName = storageDir + imageFileName + ".jpg";
- Log.d(TAG, "File:" + LastFileName);
- File image = File.createTempFile(imageFileName, /* prefix */
- ".jpg", /* suffix */
- storageDir /* directory */
- );
- // Save a file: path for use with ACTION_VIEW intents
- // mCurrentPhotoPath = "file:" + image.getAbsolutePath();
- return image;
- }
- boolean createDir(String path)
- {
- Log.i(TAG, "readFile:createDir=" + path);
- boolean ret = false;
- try
- {
- File file = new File(path);
- if (!file.exists())
- file.mkdirs();
- if (!file.isDirectory())
- {
- ret = file.mkdirs();
- }
- }
- catch (Exception e)
- {
- Log.d(TAG, e.toString());
- }
- return ret;
- }
- void updateUploadButton()
- {
- TextView pidval = (TextView) findViewById(R.id.pidval);
- ImageButton ibtnUpload = (ImageButton) findViewById(R.id.ibtnOk);
- if (photoList.size() > 0 && pidval.getText().length() > 0)
- {
- ibtnUpload.setVisibility(View.VISIBLE);
- }
- else
- {
- ibtnUpload.setVisibility(View.INVISIBLE);
- }
- }
- /*
- * (non-Javadoc)
- *
- * @see android.app.Activity#onActivityResult(int, int,
- * android.content.Intent)
- */
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- if (requestCode == REQUEST_TAKE_PHOTO)
- // ������������յ�ͼƬ
- if (resultCode == Activity.RESULT_OK) // ��������
- {
- Log.d(TAG, photoFile.toString());
- photoList.add(photoFile.toString());
- StartCamera();
- // iPhotoCount++;
- super.onActivityResult(requestCode, resultCode, data);
- }
- else
- {
- ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
- if (photoList.size() > 0)
- {
- thumbBitmap = ThumbnailUtils.extractThumbnail(BitmapFactory
- .decodeFile(photoList.get(photoList.size() - 1)),
- iwidth, iheight);
- if (thumbBitmap != null)
- thumbsImageView.setImageBitmap(thumbBitmap);
- }
- photoFile.delete();
- TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
- countTextView.setText(photoList.size() + " Photos");
- // ImageButton ibtnUpload = (ImageButton)
- // findViewById(R.id.ibtnOk);
- updateUploadButton();
- }
- else if (requestCode == REQUEST_LOCKER)
- {
- if (resultCode == Activity.RESULT_OK)
- m_blocked = false;
- }
- else if (requestCode == REQUEST_PREVIEW)
- {
- for (int i = 0; i < photoList.size(); i++)
- {
- File file = new File(photoList.get(i));
- if (!file.exists())
- {
- photoList.remove(i);
- i--;
- }
- }
- TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
- countTextView.setText(photoList.size() + " Photos");
- if (photoList.size() == 0)
- {
- ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
- thumbsImageView.setImageResource(R.drawable.no_pic);
- thumbBitmap = null;
- }
- }
- else if (requestCode == REQUEST_SCAN_BARCODE)
- {
- if (resultCode == Activity.RESULT_OK)
- {
- Bundle bundle = data.getExtras();
- String pid = bundle.getString("pid");
- Log.d(TAG,
- "REQUEST_SCAN_BARCODE==========>pid="
- + bundle.getString("pid"));
- TextView pidval = (TextView) findViewById(R.id.pidval);
- pidval.setText(pid);
- updateUploadButton();
- }
- }
- super.onActivityResult(requestCode, resultCode, data);
- }
- public void saveMyBitmap(String bitName, Bitmap mBitmap)
- {
- File f = new File("/sdcard/" + bitName + ".png");
- try
- {
- f.createNewFile();
- }
- catch (IOException e)
- {
- // TODO Auto-generated catch block
- // DebugMessage.put("�ڱ���ͼƬʱ����" + e.toString());
- }
- FileOutputStream fOut = null;
- try
- {
- fOut = new FileOutputStream(f);
- }
- catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
- try
- {
- fOut.flush();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- try
- {
- fOut.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- // boolean confirm_upload()
- // {
- // boolean bret = false;
- // final Boolean b;
- //
- // return bret;
- // }
- @Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- // TODO Auto-generated method stub
- switch (item.getItemId())
- {
- case R.id.action_clear:
- dbgUtil.fileLog("menu item clear click , clear...");
- clear();
- break;
- case R.id.action_type_pid:
- {
- final View edit = new EditText(this);
- new AlertDialog.Builder(this)
- .setIconAttribute(android.R.attr.alertDialogIcon)
- .setTitle(R.string.title_input_pid)
- .setView(edit)
- .setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog,
- int whichButton)
- {
- String pid = ((EditText) edit)
- .getText().toString();
- TextView pidval = (TextView) findViewById(R.id.pidval);
- pidval.setText(pid);
- updateUploadButton();
- /* User clicked OK so do some stuff */
- }
- })
- .setNegativeButton(android.R.string.cancel,
- new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog,
- int whichButton)
- {
- updateUploadButton();
- /* User clicked cancel so do some stuff */
- }
- }).create().show();
- }
- break;
- case R.id.action_server_settings:
- {
- Intent intent = new Intent();
- intent.setClass(MainActivity.this, ServerSettingActivity.class);
- startActivity(intent);
- }
- break;
- case R.id.action_view_queue:
- {
- Intent intent = new Intent();
- intent.setClass(MainActivity.this, UploadQueueActivity.class);
- startActivity(intent);
- break;
- }
- default:
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- @Override
- protected void onSaveInstanceState(Bundle outState)
- {
- // TODO Auto-generated method stub
- super.onSaveInstanceState(outState);
- if (photoFile != null)
- outState.putSerializable("photoFile", photoFile);
- if (thumbBitmap != null)
- outState.putByteArray("thumbBitmap", getBytes(thumbBitmap));// ("thumbBitmap",
- // (Object)thumbBitmap);
- // outState.putString("thumbpath",
- // thumbpath);
- // outState.putString("m_sName", m_sName);
- // outState.putString("m_sPassword", m_sPassword);
- outState.putStringArrayList("photoList", photoList);
- // Log.d(TAG, "save thumbpath==" + thumbpath);
- //outState.putInt("iPhotoCount", photoList.size());
- TextView pidval = (TextView) findViewById(R.id.pidval);
- outState.putString("PIID", pidval.getText().toString());
- }
- public static byte[] getBytes(Bitmap bitmap)
- {
- // ʵ�����ֽ����������
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.PNG, 0, baos);// ѹ��λͼ
- return baos.toByteArray();// ���������ֽ�����
- }
- public static Bitmap getBitmap(byte[] data)
- {
- if (data == null)
- return null;
- return BitmapFactory.decodeByteArray(data, 0, data.length);// ���ֽ��������λͼ
- }
- private void clear()
- {
- for (int i = 0; i < photoList.size(); i++)
- {
-
-
-
-
- String timeStamp = new SimpleDateFormat("yyyy_MM_dd")
- .format(new Date());
-
- File storageDir = new File(Environment.getExternalStorageDirectory()
- .getPath() + "/redant/pop/clear/"+timeStamp);
-
- if (!storageDir.exists())
- storageDir.mkdirs();
- // File dir1 = new File(Environment.getExternalStorageDirectory()
- // .getPath() + "/redant");
- // File dir2 = new File(Environment.getExternalStorageDirectory()
- // .getPath() + "/redant/pop");
- // File dir3 = new File(Environment.getExternalStorageDirectory()
- // .getPath() + "/redant/pop/clear");
- //
- //
- // if (!dir1.exists())
- // {
- // boolean b = dir1.mkdir();
- // }
- // if (!dir2.exists())
- // {
- // boolean b = dir2.mkdir();
- // }
- // if (!dir3.exists())
- // {
- // boolean b = dir3.mkdir();
- // }
- //
- // if (!storageDir.exists())
- // {
- // boolean b = storageDir.mkdir();
- // }
-
- File srcFile = new File(photoList.get(i));
- // file.delete();
- dbgUtil.fileLog("move file "+srcFile.getName()+" to "+Environment.getExternalStorageDirectory()
- .getPath() + "/redant/pop/clear/"+timeStamp + File.separator);
- srcFile.renameTo(new File(Environment.getExternalStorageDirectory()
- .getPath() + "/redant/pop/clear/"+timeStamp + File.separator + srcFile.getName()));
-
-
- // // Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
- // // Log.d(TAG, "DIR:" + storageDir);
- // LastFileName = storageDir + imageFileName + ".jpg";
- // Log.d(TAG, "File:" + LastFileName);
- // File image = File.createTempFile(imageFileName, /* prefix */
- // ".jpg", /* suffix */
- // storageDir /* directory */
- // );
-
-
- }
- photoList.clear();
- TextView pidval = (TextView) findViewById(R.id.pidval);
- pidval.setText("");
- updateUploadButton();
- ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
- thumbsImageView.setImageResource(R.drawable.no_pic);
- thumbBitmap = null;
- TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
- countTextView.setText("no photo");
- }
- private void clearfornew()
- {
- photoList.clear();
- TextView pidval = (TextView) findViewById(R.id.pidval);
- pidval.setText("");
- updateUploadButton();
- ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
- thumbsImageView.setImageResource(R.drawable.no_pic);
- thumbBitmap = null;
- TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
- countTextView.setText("no photo");
- }
- private final BroadcastReceiver MainActivityReceiver = new BroadcastReceiver()
- {
- public void onReceive(
- Context context,
- Intent intent)
- {
- String action = intent
- .getAction();
- // 如果捕捉到的action是ACTION_BATTERY_CHANGED
- if ("REDANT.POP.USER_CHECK_FAILED"
- .equals(action))
- {
- m_tvalert
- .setTextColor(getResources()
- .getColor(
- R.color.message_fail));
- m_tvalert
- .setText("Upload failed:user verify failure.");
- }
- else if ("REDANT.POP.STATION_NOT_CHANGE"
- .equals(action))
- {
- new AlertDialog.Builder(
- MainActivity.this)
- .setIconAttribute(
- android.R.attr.alertDialogIcon)
- .setTitle(
- R.string.confirm_to_upload)
- .setMessage(
- "Upload to station "
- + RedAntApplication.station_name)
- .setPositiveButton(
- android.R.string.ok,
- new DialogInterface.OnClickListener()
- {
- public void onClick(
- DialogInterface dialog,
- int whichButton)
- {
- SQLiteDatabase db = dbUtil
- .OpenDB(MainActivity.this,
- null,
- true);
- TextView pidval = (TextView) findViewById(R.id.pidval);
- String pid = pidval
- .getText()
- .toString();
- for (int i = 0; i < photoList
- .size(); i++)
- {
- ContentValues cv = new ContentValues();
- cv.put("picker",
- RedAntApplication.user);
- cv.put("server",
- RedAntApplication.active_address);
- cv.put("err_code",
- Network.STATUS_WAIT);
- cv.put("pid",
- pid);
- cv.put("local_path",
- photoList
- .get(i));
- db.insert(
- "pics",
- null,
- cv);
- }
- dbUtil.CloseDB(db);
- // new
- // UploadTask().execute((Void)
- // null);
- clearfornew();
- sendBroadcast(new Intent(
- "REDANT.POP.RESET_LOCATION"));
- Intent intent = new Intent(
- "REDANT.POP.MODIFY_QUEUE");
- sendBroadcast(intent);
- }
- })
- .setNegativeButton(
- android.R.string.cancel,
- new DialogInterface.OnClickListener()
- {
- public void onClick(
- DialogInterface dialog,
- int whichButton)
- {
- // debug
- // update_location();
- }
- })
- .create()
- .show();
- }
- else if ("REDANT.POP.STATION_CHANGE"
- .equals(action))
- {
-
- sendBroadcast(new Intent(
- "REDANT.POP.RESET_LOCATION"));
- new AlertDialog.Builder(
- MainActivity.this)
- .setIconAttribute(
- android.R.attr.alertDialogIcon)
- .setTitle(
- R.string.location_changed)
- .setMessage(
- "We have detected that your position has changed,do you want to modify the server setting? ")
- .setPositiveButton(
- android.R.string.ok,
- new DialogInterface.OnClickListener()
- {
- public void onClick(
- DialogInterface dialog,
- int whichButton)
- {
- Intent intent = new Intent();
- intent.setClass(
- MainActivity.this,
- ServerSettingActivity.class);
- startActivity(intent);
- }
- })
- .setNegativeButton(
- android.R.string.cancel,
- new DialogInterface.OnClickListener()
- {
- public void onClick(
- DialogInterface dialog,
- int whichButton)
- {
- // debug
- // update_location();
- }
- })
- .create()
- .show();
- }
- else if ("REDANT.POP.FINISH_UPLOAD_QUEUE"
- .equals(action))
- {
- m_tvalert
- .setTextColor(getResources()
- .getColor(
- R.color.message_success));
- m_tvalert
- .setText("Upload successes!");
- }
- else if ("REDANT.POP.FINISH_UPLOAD_QUEUE_WITH_ERROR"
- .equals(action))
- {
- m_tvalert
- .setTextColor(getResources()
- .getColor(
- R.color.message_fail));
- m_tvalert
- .setText("Upload finish with some error!");
- }
- else if (action
- .equals(Intent.ACTION_SCREEN_OFF))
- {
- Log.d("hg",
- "�յ��㲥!!!=======>m_blocked="
- + m_blocked);
- if (m_blocked == true)
- return;
- SharedPreferences pref = RedAntApplication
- .getInstance()
- .getSharedPreferences(
- "POP",
- 0);
- boolean autologin = pref
- .getBoolean(
- "kepppass",
- false);
- if (autologin)
- return;
- Intent activityintent = new Intent();
- activityintent
- .setClass(
- MainActivity.this,
- LockerActivity.class);
- startActivityForResult(
- activityintent,
- REQUEST_LOCKER);
- Log.d(TAG,
- "===================>start locker");
- m_blocked = true;
- }
- }
- };
- }
|