| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973 |
- 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 android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- 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.database.sqlite.SQLiteDatabase;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.util.Log;
- 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_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>();
- // private SurfaceView picSV;
- // private Camera camera;
- //
- // private final BroadcastReceiver m_lockedReceiver = new BroadcastReceiver()
- // {
- // @Override
- // public void onReceive(
- // Context context,
- // Intent intent)
- // {
- // String action = intent
- // .getAction();
- // if (action
- // .equals(Intent.ACTION_SCREEN_OFF))
- // {
- // Log.e("hg",
- // "�յ��㲥!!!=======>m_blocked="
- // + m_blocked);
- // if (m_blocked == true)
- // return;
- // Intent activityintent = new Intent();
- // activityintent
- // .setClass(
- // MainActivity.this,
- // LockerActivity.class);
- // startActivityForResult(
- // activityintent,
- // REQUEST_LOCKER);
- // Log.e(TAG,
- // "===================>start locker");
- // m_blocked = true;
- // }
- // // if
- // // (action.equals(Intent.ACTION_USER_PRESENT))
- // // {
- // //
- // // Log.e("hg",
- // // "�յ��㲥!!!=======>m_blocked="
- // // +
- // // m_blocked);
- // // if
- // // (m_blocked
- // // == true)
- // // return;
- // // Intent
- // // activityintent
- // // = new
- // // Intent();
- // // activityintent
- // // .setClass(MainActivity.this,
- // // LockerActivity.class);
- // // startActivityForResult(activityintent,
- // // REQUEST_LOCKER);
- // // Log.e(TAG,
- // // "===================>start locker");
- // // m_blocked
- // // = true;
- // // }
- // }
- // };
- // @Override
- // protected void onStart() {
- // Log.i(TAG, "onStart========>m_blocked="+m_blocked);
- // // TODO Auto-generated method stub
- //
- // if (m_blocked) {
- //
- // }
- // super.onStart();
- // }
- //
- // @Override
- // protected void onStop() {
- // Log.i(TAG, "onStop========>");
- // // TODO Auto-generated method stub
- //
- // super.onStop();
- // }
- 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
- protected void onCreate(Bundle savedInstanceState)
- {
- Log.e(TAG, "=======================>MainActivity Created!");
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main1);
- ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
- thumbsImageView.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- Intent intent = new Intent(MainActivity.this,
- PhotoPreviewActivity.class);
- intent.putExtra("pic_list", (Serializable) photoList);
- startActivity(intent);
- // File folder = new
- // File(Environment.getExternalStorageDirectory().getPath()+"/redant/pop/temp");
- // File[] allFiles = folder.listFiles();
- // new SingleMediaScanner(MainActivity.this, allFiles[0]);
- // Intent intent = new Intent();
- // // Intent.ACTION_PICK,
- // //
- // android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
- // // startActivityForResult(intent, REQUEST_SCAN_BARCODE);
- //
- // intent.setClass(MainActivity.this, CaptureActivity.class);
- // startActivityForResult(intent, REQUEST_SCAN_BARCODE);
- }
- });
- // m_sName = intent.getStringExtra("user");
- // m_sPassword = intent.getStringExtra("password");
- Log.e(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.USER_CHECK_FAILED");
- msgFilter.addAction("REDANT.POP.FINISH_UPLOAD_QUEUE");
- msgFilter.addAction("REDANT.POP.FINISH_UPLOAD_QUEUE_WITH_ERROR");
- msgFilter.setPriority(2147483647);
- registerReceiver(MainActivityReceiver, msgFilter);
- Log.e(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");
- // photoList = A
- // savedInstanceState.getStringArrayList("photoList");
- photoFile = (File) savedInstanceState.getSerializable("photoFile");
- // iPhotoCount = savedInstanceState.getInt("iPhotoCount");
- // thumbpath = savedInstanceState.getString("thumbpath");
- // if (savedInstanceState.getString("m_sName") != null)
- // m_sName = savedInstanceState.getString("m_sName");
- // if (savedInstanceState.getString("m_sPassword") != null)
- // m_sPassword = savedInstanceState.getString("m_sPassword");
- // ImageView thumbsImageView = (ImageView)
- // findViewById(R.id.ivThumbs);
- if (thumbBitmap != null)
- {
- thumbsImageView.setImageBitmap(thumbBitmap);
- // Log.e(TAG, "load thumbpath==" + thumbpath);
- }
- // photoFile.delete();
- TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
- countTextView.setText(photoList.size() + " Photos");
- }
- // EditText edit = (EditText) findViewById(R.id.pidval);
- // edit.addTextChangedListener(new TextWatcher()
- // {
- // @Override
- // public void onTextChanged(CharSequence s, int start, int before,
- // int count)
- // {
- //
- // }
- //
- // @Override
- // public void beforeTextChanged(CharSequence s, int start, int count,
- // int after)
- // {
- // }
- //
- // @Override
- // public void afterTextChanged(Editable s)
- // {
- // // EditText edit = (EditText) findViewById(R.id.edit);
- // ImageButton ibtnUpload = (ImageButton) findViewById(R.id.ibtnOk);
- // if (photoList.size() > 0 && s.length() > 0)
- // {
- // ibtnUpload.setVisibility(View.VISIBLE);
- //
- // }
- // else
- // {
- // ibtnUpload.setVisibility(View.INVISIBLE);
- //
- // }
- // }
- // });
- // if (getRequestedOrientation() ==
- // ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
- // LinearLayout landLayout = (LinearLayout) findViewById(R.id.land);
- // landLayout.setVisibility(View.VISIBLE);
- // } else {
- // LinearLayout portLayout = (LinearLayout) findViewById(R.id.port);
- // portLayout.setVisibility(View.VISIBLE);
- // }
- ImageButton ibtnscan = (ImageButton) findViewById(R.id.ibtnScan);
- ibtnscan.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- Log.e(TAG,"==============>Click Scan button");
- Intent intent = new Intent();
- // Intent.ACTION_PICK,
- // android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
- // startActivityForResult(intent, REQUEST_SCAN_BARCODE);
- 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)
- {
- 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("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();
- Intent intent = new Intent("REDANT.POP.MODIFY_QUEUE");
- sendBroadcast(intent);
- }
- });
- m_tvalert = (TextView) findViewById(R.id.tvalert);
- m_tvalert.setSelected(true);
- // Intent intent = ;
- sendBroadcast(new Intent("REDANT.POP.MODIFY_QUEUE"));
- }
- @Override
- protected void onDestroy()
- {
- // TODO Auto-generated method stub
- Log.e(TAG, "=======================>MainActivity Destroyed!");
- unregisterReceiver(MainActivityReceiver);
- Log.e(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;
- }
- // public static void savePic(Bitmap b, String strFileName)
- // {
- // FileOutputStream fos = null;
- // try
- // {
- // fos = new FileOutputStream(strFileName);
- // if (null != fos)
- // {
- //
- // b.compress(Bitmap.CompressFormat.PNG, 90, fos);
- // fos.flush();
- // fos.close();
- // }
- // }
- // catch (FileNotFoundException e)
- // {
- // e.printStackTrace();
- // }
- // catch (IOException e)
- // {
- // e.printStackTrace();
- // }
- // }
- 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.e(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.e(TAG, msg)
- // Bundle bundle = data.getExtras();
- // if(thumbBitmap!=null)
- // thumbBitmap=null;
- // thumbBitmap = (Bitmap) bundle.get("data");
- // // ��ȡ������ص����ݣ���ת��ΪBitmapͼƬ��ʽ
- // Bitmap thumbBitmap = BitmapFactory.decodeFile(photoFile
- // .toString());
- // CreateThumb(photoFile);
- Log.e(TAG, photoFile.toString());
- photoList.add(photoFile.toString());
- // Bitmap.createScaledBitmap(
- // thumbBitmap, thumbsImageView.getWidth(),
- // thumbsImageView.getHeight(), false));
- // Log.i(TAG, "thumb size" + thumbBitmap.getHeight() + "x"
- // + thumbBitmap.getWidth());
- // thumbpath = photoFile.toString();
- // Log.e(TAG, "get thumbpath==" + thumbpath);
- StartCamera();
- // iPhotoCount++;
- super.onActivityResult(requestCode, resultCode, data);
- }
- else
- {
- // �˳�����
- // File emptyFile = new File(LastFileName);
- // boolean b=emptyFile.delete();
- // Log.i(TAG, "lastpicPath: " + thumbpath);
- ImageView thumbsImageView = (ImageView) findViewById(R.id.ivThumbs);
- // LayerDrawable
- // thumbsImageView.setImageDrawable(drawable);
- // thumbBitmap=getImageThumbnail(thumbpath, iwidth,iheight);
- if (photoList.size() > 0)
- {
- thumbBitmap = ThumbnailUtils.extractThumbnail(BitmapFactory
- .decodeFile(photoList.get(photoList.size() - 1)),
- iwidth, iheight);
- if (thumbBitmap != null)
- thumbsImageView.setImageBitmap(thumbBitmap);
- }
- // thumbBitmap = ThumbnailUtils.extractThumbnail(
- // BitmapFactory.decodeFile(thumbpath), iwidth, iheight);
- // saveMyBitmap("thumbtest",thumbBitmap);
- // 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_SCAN_BARCODE)
- {
- if (resultCode == Activity.RESULT_OK)
- {
- Bundle bundle = data.getExtras();
- String pid = bundle.getString("pid");
- Log.e(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();
- }
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- // TODO Auto-generated method stub
- switch (item.getItemId())
- {
- case R.id.action_clear:
- clearfornew();
- 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);
-
- /* User clicked OK so do some stuff */
- }
- })
- .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- /* User clicked cancel so do some stuff */
- }
- })
- .create().show();
- }
- 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.e(TAG, "save thumbpath==" + thumbpath);
- outState.putInt("iPhotoCount", photoList.size());
- }
- 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 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");
- }
- // public class UploadTask extends AsyncTask<Void, Void, Boolean>
- // {
- // String err_msg="";
- // @Override
- // protected Boolean doInBackground(Void... params)
- // {
- // boolean bret=true;
- //
- //
- // SQLiteDatabase db = dbUtil.OpenDB(MainActivity.this, null, true);
- // EditText edit = (EditText) findViewById(R.id.edit);
- // String pid = edit.getText().toString();
- //
- // if (Network.NetworkIsAvailable(MainActivity.this))
- // {
- // int verifyresult = Network.VerifyUser(m_sName, m_sPassword);
- // if (verifyresult == Network.RESULT_TRUE)
- // {
- // /* user is authorized */
- // for (int i = 0; i < photoList.size(); i++)
- // {
- // int uploadresult = Network.UploadFile(photoList.get(i),
- // m_sName, m_sPassword, pid);
- // if (uploadresult != Network.RESULT_TRUE)
- // {
- // /*
- // * upload failed write to local db upload when
- // * connect to network next time;
- // */
- //
- // /*
- // * serious error occur must notify user
- // * immediately
- // */
- // if (uploadresult == Network.RESULT_LOCALFILE_ERROR)
- // err_msg+="Warring! Local picture file not found! ";
- // if( uploadresult == Network.RESULT_USERAUTH_ERROR)
- // err_msg+="Warring! Authorize check failed when uploading photos! ";
- //
- // ContentValues cv = new ContentValues();
- // cv.put("picker", m_sName);
- // cv.put("err_code", uploadresult);
- // cv.put("pid", pid);
- // cv.put("local_path", photoList.get(i));
- // db.insert("pics", null, cv);
- // bret=false;
- // }
- // else
- // {
- // /* upload success delete file */
- // File file = new File(photoList.get(i));
- // file.delete();
- // }
- //
- // }
- //
- // }
- // else
- // if (verifyresult == Network.RESULT_FALSE)
- // {
- // /*
- // * user is not authorized serious error occur must
- // * notify user
- // */
- // Log.e(TAG, "notification====================>");
- // // String text=m_tvalert.getText().toString();
- // err_msg+="Warring! Authorize check failed when uploading photos!";
- // bret=false;
- // for (int i = 0; i < photoList.size(); i++)
- // {
- // ContentValues cv = new ContentValues();
- // cv.put("picker", m_sName);
- // cv.put("err_code", Network.RESULT_USERAUTH_ERROR);
- // cv.put("pid", pid);
- // cv.put("local_path", photoList.get(i));
- // db.insert("pics", null, cv);
- // }
- //
- // }
- // else
- // {
- // /* an error occur */
- // for (int i = 0; i < photoList.size(); i++)
- // {
- // ContentValues cv = new ContentValues();
- // cv.put("picker", m_sName);
- // cv.put("err_code", Network.RESULT_NET_ERROR);
- // cv.put("pid", pid);
- // cv.put("local_path", photoList.get(i));
- // db.insert("pics", null, cv);
- // }
- // bret = false;
- // }
- // }
- // else
- // {
- // /*
- // * net work is not available store into local DB it will auto
- // * upload when connect to network next time;
- // */
- //
- // for (int i = 0; i < photoList.size(); i++)
- // {
- // ContentValues cv = new ContentValues();
- // cv.put("picker", m_sName);
- // cv.put("err_code", Network.RESULT_NET_ERROR);
- // cv.put("pid", pid);
- // cv.put("local_path", photoList.get(i));
- // db.insert("pics", null, cv);
- // }
- // bret=false;
- // // m_tvalert.setText("Upload failed when uploading photos!");
- //
- // }
- //
- // dbUtil.CloseDB(db);
- // return bret;
- // }
- //
- // @Override
- // protected void onPostExecute(final Boolean success)
- // {
- // if(success)
- // {
- // m_tvalert.setTextColor(getResources().getColor(R.color.message_success));
- // m_tvalert.setText("Upload successed!");
- // }
- // else
- // {
- // m_tvalert.setTextColor(getResources().getColor(R.color.message_fail));
- // m_tvalert.setText(err_msg);
- // }
- //
- //
- // // mAuthTask = null;
- // // showProgress(false);
- // //
- // // if (success) {
- // //
- // // // SharedPreferences.Editor editor = RunOnce.edit();
- // // // editor.putBoolean("FirstRun"+globalUtil.getVerName(this),
- // // false);
- // // // // Don't forget to commit your edits!!!
- // // // editor.commit();
- // // Intent intent = new Intent();
- // // intent.setClass(LoginActivity.this, MainActivity.class);
- // // startActivity(intent);
- // // finish();
- // // } else {
- // // m_etPassword
- // // .setError(getString(R.string.error_incorrect_password));
- // // m_etPassword.requestFocus();
- // // }
- // }
- //
- // @Override
- // protected void onCancelled()
- // {
- // // mAuthTask = null;
- // // showProgress(false);
- // }
- // }
- // public class SingleMediaScanner implements MediaScannerConnectionClient {
- //
- // private MediaScannerConnection mMs;
- // private File mFile;
- //
- // public SingleMediaScanner(Context context, File f) {
- // mFile = f;
- // mMs = new MediaScannerConnection(context, this);
- // mMs.connect();
- // }
- //
- // public void onMediaScannerConnected() {
- // Log.d(null, ""+mFile.getAbsolutePath());
- // Log.d(null,
- // ""+Environment.getExternalStorageDirectory().getPath()+"/photo/");
- // Log.d(null, new
- // File(Environment.getExternalStorageDirectory().getPath()+"/photo/").getAbsolutePath());
- //
- // mMs.scanFile(mFile.getAbsolutePath(), null);
- // }
- //
- // public void onScanCompleted(String path, Uri uri) {
- // Intent intent = new Intent(Intent.ACTION_VIEW);
- // intent.setData(uri);
- // startActivity(intent);
- // mMs.disconnect();
- // }
- //
- // }
- 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.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.e("hg",
- "�յ��㲥!!!=======>m_blocked="
- + m_blocked);
- if (m_blocked == true)
- return;
- Intent activityintent = new Intent();
- activityintent
- .setClass(
- MainActivity.this,
- LockerActivity.class);
- startActivityForResult(
- activityintent,
- REQUEST_LOCKER);
- Log.e(TAG,
- "===================>start locker");
- m_blocked = true;
- }
- }
- };
- }
|