Ray Zhang hace 11 años
padre
commit
b3ffd3ad12

+ 2 - 2
RedAnt Photo/src/com/usai/redant/photo/CaptureActivity.java

@@ -181,7 +181,7 @@ public final class CaptureActivity extends Activity implements
 		// PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
 
 
-		Log.e(TAG, "finish oncreate");
+		Log.d(TAG, "finish oncreate");
 	}
 	
 	@Override
@@ -460,7 +460,7 @@ public final class CaptureActivity extends Activity implements
 	{
 		if (holder == null)
 		{
-			Log.e(TAG,
+			Log.d(TAG,
 					"*** WARNING *** surfaceCreated() gave us a null surface!");
 		}
 		if (!hasSurface)

+ 15 - 0
RedAnt Photo/src/com/usai/redant/photo/LoginActivity.java

@@ -163,6 +163,13 @@ public class LoginActivity extends Activity
 		adapter = new ArrayAdapter<String>(this,
 				android.R.layout.simple_list_item_1, dbUtil.get_userlist());
 		m_etName.setAdapter(adapter);
+		
+		if(TextUtils.isEmpty(RedAntApplication.active_address))
+		{
+			Intent intent = new Intent();
+			intent.setClass(LoginActivity.this,ServerSettingActivity.class);
+			startActivity(intent);			
+		}
 	}
 
 	@Override
@@ -185,6 +192,14 @@ public class LoginActivity extends Activity
 				intent.setClass(LoginActivity.this, AboutActivity.class);
 				startActivity(intent);
 
+			}
+				break;
+			case R.id.action_server_settings:
+			{
+				Intent intent = new Intent();
+				intent.setClass(LoginActivity.this,ServerSettingActivity.class);
+				startActivity(intent);
+
 			}
 				break;
 			default:

+ 25 - 15
RedAnt Photo/src/com/usai/redant/photo/MainActivity.java

@@ -118,7 +118,7 @@ public class MainActivity extends Activity
 	@Override
 	protected void onCreate(Bundle savedInstanceState)
 	{
-		Log.e(TAG, "=======================>MainActivity Created!");
+		Log.d(TAG, "=======================>MainActivity Created!");
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.activity_main1);
 
@@ -142,7 +142,7 @@ public class MainActivity extends Activity
 		// m_sName = intent.getStringExtra("user");
 		// m_sPassword = intent.getStringExtra("password");
 
-		Log.e(TAG, "user=" + RedAntApplication.user + ",password="
+		Log.d(TAG, "user=" + RedAntApplication.user + ",password="
 				+ RedAntApplication.password);
 		IntentFilter msgFilter = new IntentFilter();
 		Intent intent = getIntent();
@@ -152,7 +152,7 @@ public class MainActivity extends Activity
 		msgFilter.addAction("REDANT.POP.FINISH_UPLOAD_QUEUE_WITH_ERROR");
 		msgFilter.setPriority(2147483647);
 		registerReceiver(MainActivityReceiver, msgFilter);
-		Log.e(TAG, "=======================>msgFilter registed!");
+		Log.d(TAG, "=======================>msgFilter registed!");
 		if (savedInstanceState != null)
 		{
 			thumbBitmap = getBitmap(savedInstanceState
@@ -168,7 +168,7 @@ public class MainActivity extends Activity
 			if (thumbBitmap != null)
 			{
 				thumbsImageView.setImageBitmap(thumbBitmap);
-				// Log.e(TAG, "load thumbpath==" + thumbpath);
+				// Log.d(TAG, "load thumbpath==" + thumbpath);
 			}
 			// photoFile.delete();
 			TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
@@ -183,7 +183,7 @@ public class MainActivity extends Activity
 			@Override
 			public void onClick(View v)
 			{
-				Log.e(TAG, "==============>Click Scan button");
+				Log.d(TAG, "==============>Click Scan button");
 				Intent intent = new Intent();
 
 				intent.setClass(MainActivity.this, CaptureActivity.class);
@@ -218,6 +218,7 @@ public class MainActivity extends Activity
 
 					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));
@@ -244,9 +245,9 @@ public class MainActivity extends Activity
 	protected void onDestroy()
 	{
 		// TODO Auto-generated method stub
-		Log.e(TAG, "=======================>MainActivity Destroyed!");
+		Log.d(TAG, "=======================>MainActivity Destroyed!");
 		unregisterReceiver(MainActivityReceiver);
-		Log.e(TAG, "=======================>msgFilter unregisted!");
+		Log.d(TAG, "=======================>msgFilter unregisted!");
 		super.onDestroy();
 	}
 
@@ -316,7 +317,7 @@ public class MainActivity extends Activity
 		}
 		catch (Exception e)
 		{
-			Log.e(TAG, e.toString());
+			Log.d(TAG, e.toString());
 		}
 		return ret;
 	}
@@ -354,7 +355,7 @@ public class MainActivity extends Activity
 
 			{
 
-				Log.e(TAG, photoFile.toString());
+				Log.d(TAG, photoFile.toString());
 				photoList.add(photoFile.toString());
 
 				StartCamera();
@@ -416,12 +417,12 @@ public class MainActivity extends Activity
 			{
 				Bundle bundle = data.getExtras();
 				String pid = bundle.getString("pid");
-				Log.e(TAG,
+				Log.d(TAG,
 						"REQUEST_SCAN_BARCODE==========>pid="
 								+ bundle.getString("pid"));
 				TextView pidval = (TextView) findViewById(R.id.pidval);
 				pidval.setText(pid);
-				// updateUploadButton();
+				 updateUploadButton();
 			}
 		}
 		super.onActivityResult(requestCode, resultCode, data);
@@ -493,6 +494,7 @@ public class MainActivity extends Activity
 												.getText().toString();
 										TextView pidval = (TextView) findViewById(R.id.pidval);
 										pidval.setText(pid);
+										updateUploadButton();
 
 										/* User clicked OK so do some stuff */
 									}
@@ -503,12 +505,20 @@ public class MainActivity extends Activity
 									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();
@@ -539,7 +549,7 @@ public class MainActivity extends Activity
 		// outState.putString("m_sPassword", m_sPassword);
 
 		outState.putStringArrayList("photoList", photoList);
-		// Log.e(TAG, "save thumbpath==" + thumbpath);
+		// Log.d(TAG, "save thumbpath==" + thumbpath);
 		outState.putInt("iPhotoCount", photoList.size());
 	}
 
@@ -639,7 +649,7 @@ public class MainActivity extends Activity
 																	else if (action
 																			.equals(Intent.ACTION_SCREEN_OFF))
 																	{
-																		Log.e("hg",
+																		Log.d("hg",
 																				"�յ��㲥!!!=======>m_blocked="
 																						+ m_blocked);
 																		if (m_blocked == true)
@@ -659,7 +669,7 @@ public class MainActivity extends Activity
 																		startActivityForResult(
 																				activityintent,
 																				REQUEST_LOCKER);
-																		Log.e(TAG,
+																		Log.d(TAG,
 																				"===================>start locker");
 																		m_blocked = true;
 																	}

+ 14 - 0
RedAnt Photo/src/com/usai/redant/photo/RedAntApplication.java

@@ -6,6 +6,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import android.app.Application;
 import android.content.Intent;
+import android.content.SharedPreferences;
+import android.text.TextUtils;
 
 public class RedAntApplication extends Application
 {
@@ -14,6 +16,7 @@ public class RedAntApplication extends Application
     public static Lock writeLock   = lock.writeLock();   
     public static String user;
     public static String password;
+    public static String active_address;
     public static RedAntApplication getInstance() {  
         return instance;  
     }  
@@ -24,6 +27,14 @@ public class RedAntApplication extends Application
         super.onCreate();  
         instance = this;  
         
+		SharedPreferences pref = RedAntApplication.getInstance()
+				.getSharedPreferences("POP", 0);
+
+		String aa = pref.getString("aa", null);
+		if(!TextUtils.isEmpty(aa))
+			active_address = aa;
+        
+        
 		Intent intentservice = new Intent();
 		intentservice.setClass( this, UploadService.class);
 //		if (intent.getExtras() != null)
@@ -31,5 +42,8 @@ public class RedAntApplication extends Application
 //		intentservice.setAction(intent.getAction());
 		startService(intentservice);
 		
+		
+		
+		
     }  
 }

+ 238 - 0
RedAnt Photo/src/com/usai/redant/photo/ServerSettingActivity.java

@@ -0,0 +1,238 @@
+package com.usai.redant.photo;
+
+import java.io.File;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.usai.util.Network;
+
+import android.R.string;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.graphics.BitmapFactory;
+import android.media.ThumbnailUtils;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.EditText;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.RadioGroup;
+import android.widget.TextView;
+
+public class ServerSettingActivity extends Activity
+{
+	static final int	REQUEST_SCAN_BARCODE	= 2;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState)
+	{
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_service_setting);
+
+		SharedPreferences pref = RedAntApplication.getInstance()
+				.getSharedPreferences("POP", 0);
+
+		String ia = pref.getString("ia", null);
+		String ea = pref.getString("ea", null);
+		String aa = pref.getString("aa", null);
+		RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
+
+		if (!TextUtils.isEmpty(aa) && aa.equals(ia))
+			rg.check(R.id.radio0);
+
+		if (!TextUtils.isEmpty(aa) && aa.equals(ea))
+			rg.check(R.id.radio1);
+
+		EditText et_ia = (EditText) findViewById(R.id.et_ia);
+		EditText et_ea = (EditText) findViewById(R.id.et_ea);
+		et_ea.setText(ea);
+		et_ia.setText(ia);
+
+		ImageButton ibtn = (ImageButton) findViewById(R.id.ibtn_scan);
+		ibtn.setOnClickListener(new OnClickListener()
+		{
+
+			@Override
+			public void onClick(View v)
+			{
+			//	Log.d(TAG, "==============>Click Scan button");
+				Intent intent = new Intent();
+
+				intent.setClass(ServerSettingActivity.this,
+						CaptureActivity.class);
+				startActivityForResult(intent, REQUEST_SCAN_BARCODE);
+
+			}
+		});
+	}
+
+	@Override
+	public boolean onCreateOptionsMenu(Menu menu)
+	{
+		// Inflate the menu; this adds items to the action bar if it is present.
+		getMenuInflater().inflate(R.menu.server_setting, menu);
+		return true;
+	}
+
+	@Override
+	public void onActivityResult(int requestCode, int resultCode, Intent data)
+	{
+
+		if (requestCode == REQUEST_SCAN_BARCODE)
+		{
+			if (resultCode == Activity.RESULT_OK)
+			{
+				Bundle bundle = data.getExtras();
+				String jstr = bundle.getString("pid");
+				
+				if (jstr == null || jstr.length() <= 0)
+				{
+					//Log.d(TAG, "json is wrong");
+					return ;//Network.RESULT_NET_ERROR;
+				}	
+				String address[]=jstr.split(";");
+				if (address.length<2)
+					return;
+				EditText et_ia = (EditText) findViewById(R.id.et_ia);
+				EditText et_ea = (EditText) findViewById(R.id.et_ea);
+				et_ea.setText(address[1].trim());
+				et_ia.setText(address[0].trim());
+//				JSONObject jsobj;
+//				try
+//				{
+//					jsobj = new JSONObject(jstr);
+//					if (jsobj.length() > 0)
+//					{
+//						String name = jsobj.getString("name");
+//						String ia = jsobj.getString("ia");
+//						String ea = jsobj.getString("ea");
+//						EditText et_ia = (EditText) findViewById(R.id.et_ia);
+//						EditText et_ea = (EditText) findViewById(R.id.et_ea);
+//						et_ea.setText(ea);
+//						et_ia.setText(ia);
+////						int iresult = jsobj.getInt("result");
+////						if (iresult == Network.AP_USER_AUTH)
+////						{
+////							return ;//RESULT_TRUE;
+////						}
+////
+////						else
+////						{
+////
+////							return ;//RESULT_FALSE;
+////						}
+//					}
+//					return ;
+//				}
+//				catch (JSONException e)
+//				{
+//					// TODO Auto-generated catch block
+//					e.printStackTrace();
+//					return ;
+//				}
+				//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);
+	}
+
+	@Override
+	public boolean onOptionsItemSelected(MenuItem item)
+	{
+		// Handle action bar item clicks here. The action bar will
+		// automatically handle clicks on the Home/Up button, so long
+		// as you specify a parent activity in AndroidManifest.xml.
+		int id = item.getItemId();
+		if (id == R.id.action_save)
+		{
+			EditText et_ia = (EditText) findViewById(R.id.et_ia);
+			EditText et_ea = (EditText) findViewById(R.id.et_ea);
+			String ia = et_ia.getText().toString();
+			String ea = et_ea.getText().toString();
+			if (TextUtils.isEmpty(ia) && TextUtils.isEmpty(ea))
+			{
+				showdialog();
+				return true;
+			}
+			SharedPreferences pref = RedAntApplication.getInstance()
+					.getSharedPreferences("POP", 0);
+			SharedPreferences.Editor editor = pref.edit();
+
+			if (!TextUtils.isEmpty(ia))
+			{
+
+				if (!ia.substring(ia.length() - 1).equals("/"))
+					ia = ia + "/";
+				editor.putString("ia", ia);
+			}
+			if (!TextUtils.isEmpty(ea))
+			{
+				if (!ea.substring(ea.length() - 1).equals("/"))
+					ea = ea + "/";
+				editor.putString("ea", ea);
+			}
+			RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
+			if (rg.getCheckedRadioButtonId() == R.id.radio0)
+			{
+				if (!TextUtils.isEmpty(ia))
+				{
+					editor.putString("aa", ia);
+					RedAntApplication.active_address = ia;
+				}
+				else
+				{
+					showdialog();
+					return true;
+				}
+			}
+			else
+			{
+				if (!TextUtils.isEmpty(ea))
+				{
+					editor.putString("aa", ea);
+					RedAntApplication.active_address = ea;
+				}
+				else
+				{
+					showdialog();
+					return true;
+				}
+			}
+
+			editor.commit();
+			finish();
+			return true;
+		}
+		return super.onOptionsItemSelected(item);
+	}
+
+	private void showdialog()
+	{
+		new AlertDialog.Builder(ServerSettingActivity.this)
+				.setIcon(android.R.drawable.ic_dialog_info).setTitle("Error!")
+				.setMessage("Active server address can not be empty!")
+				.setPositiveButton("OK", new DialogInterface.OnClickListener()
+				{
+					public void onClick(DialogInterface dialog, int whichButton)
+					{
+
+						// finish();
+						/* User clicked OK so do some stuff */
+					}
+				}).show();
+	}
+}

+ 118 - 63
RedAnt Photo/src/com/usai/redant/photo/UploadService.java

@@ -2,7 +2,6 @@ package com.usai.redant.photo;
 
 import java.io.File;
 
-
 import com.usai.util.Crypto;
 import com.usai.util.Network;
 import com.usai.util.dbUtil;
@@ -14,14 +13,17 @@ import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.text.TextUtils;
 import android.util.Log;
 import android.widget.EditText;
+import android.widget.RadioGroup;
 
 public class UploadService extends Service
 {
@@ -41,25 +43,24 @@ public class UploadService extends Service
 	public void onCreate()
 	{
 
-		Log.e("", "create upload Service!!!");
+		Log.d("", "create upload Service!!!");
 		if (uploadThread == null)
 		{
 			uploadThread = new UploadThread();
-			Log.e("", "create upload thread!!!");
+			Log.d("", "create upload thread!!!");
 			// upleadThread.start();
 
 		}
-		
+
 		IntentFilter msgFilter = new IntentFilter();
-		
+
 		msgFilter.addAction("REDANT.POP.MODIFY_QUEUE");
 		msgFilter.addAction("REDANT.POP.QUERY_UPLOAD_STATE");
 		msgFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
 
-		
 		registerReceiver(uploadReceiver, msgFilter);
-//		registerReceiver(uploadReceiver,
-//				new IntentFilter("modify upload queue"));
+		// registerReceiver(uploadReceiver,
+		// new IntentFilter("modify upload queue"));
 		super.onCreate();
 
 	}
@@ -75,11 +76,11 @@ public class UploadService extends Service
 		public void run()
 		{
 
-			Log.e("", "upload thread running");
+			Log.d("", "upload thread running");
 
 			super.run();
 			doupload();
-			Log.e("", "upload thread stop");
+			Log.d("", "upload thread stop");
 
 		}
 
@@ -93,7 +94,7 @@ public class UploadService extends Service
 			// {
 			SQLiteDatabase dbr = dbUtil.OpenDB(UploadService.this, null, false);
 			Cursor cursor = dbr.query("pics", new String[] { "_id", "pid",
-					"local_path", "picker" }, "err_code!="
+					"local_path", "picker","server" }, "err_code!="
 					+ Network.AP_UPLOAD_SUCCESS, null, null, null, "_id", null);
 			while (cursor.moveToNext())
 			{
@@ -103,7 +104,7 @@ public class UploadService extends Service
 					queue_changed = false;
 					dbUtil.CloseCursor(cursor);
 					cursor = dbr.query("pics", new String[] { "_id", "pid",
-							"local_path", "picker" }, "err_code!="
+							"local_path", "picker","server" }, "err_code!="
 							+ Network.AP_UPLOAD_SUCCESS, null, null, null,
 							"_id", null);
 					if (!cursor.moveToNext())
@@ -114,24 +115,24 @@ public class UploadService extends Service
 				String pid = cursor.getString(1);
 				String path = cursor.getString(2);
 				String picker = cursor.getString(3);
-				
-				
-				String encryptUser="";
-				
+				String server = cursor.getString(4);
+
+				String encryptUser = "";
+
 				try
 				{
-					encryptUser=Crypto.encrypt("apexu", picker);
-					
+					encryptUser = Crypto.encrypt("apexu", picker);
+
 				}
 				catch (Exception e1)
 				{
 					// TODO Auto-generated catch block
 					e1.printStackTrace();
 				}
-				
+
 				Cursor cursor_user = dbr.query("users",
-						new String[] { "pass" }, "name='" + encryptUser + "'", null,
-						null, null, "_id", null);
+						new String[] { "pass" }, "name='" + encryptUser + "'",
+						null, null, null, "_id", null);
 				String pass = "";
 				if (cursor_user.moveToNext())
 					pass = cursor_user.getString(0);
@@ -144,8 +145,8 @@ public class UploadService extends Service
 					// TODO Auto-generated catch block
 					e.printStackTrace();
 				}
-				
-				int uploadresult = Network.UploadFile(path, picker, pass, pid);
+
+				int uploadresult = Network.UploadImage(path, picker, pass, pid,server);
 				if (uploadresult == Network.RESULT_TRUE)
 				{
 					RedAntApplication.writeLock.lock();
@@ -192,7 +193,7 @@ public class UploadService extends Service
 			// }
 			// else
 			// {
-			// Log.e("upload thread", "user check failed!");
+			// Log.d("upload thread", "user check failed!");
 			//
 			// sendBroadcast(new Intent("REDANT.POP.USER_CHECK_FAILED"));
 			// }
@@ -227,7 +228,7 @@ public class UploadService extends Service
 														if ("REDANT.POP.MODIFY_QUEUE"
 																.equals(action))
 														{
-															Log.e("uploadservice",
+															Log.d("uploadservice",
 																	"recieve upload queue change");
 															if (uploadThread != null)
 															{
@@ -235,12 +236,12 @@ public class UploadService extends Service
 																		.isAlive())
 																{
 
-																	Log.e("uploadReceiver",
+																	Log.d("uploadReceiver",
 																			"upload thread alive");
 																}
 																else
 																{
-																	Log.e("uploadReceiver",
+																	Log.d("uploadReceiver",
 																			"start upload thread");
 																	uploadThread = new UploadThread();
 																	uploadThread
@@ -254,70 +255,124 @@ public class UploadService extends Service
 															if (uploadThread
 																	.isAlive())
 															{
-																sendBroadcast(new Intent("REDANT.POP.UPLOAD_STATE_TRUE"));
+																sendBroadcast(new Intent(
+																		"REDANT.POP.UPLOAD_STATE_TRUE"));
 															}
-															else {
-																sendBroadcast(new Intent("REDANT.POP.UPLOAD_STATE_FALSE"));
+															else
+															{
+																sendBroadcast(new Intent(
+																		"REDANT.POP.UPLOAD_STATE_FALSE"));
 															}
 														}
-														else if (intent.getAction().equals(
-																ConnectivityManager.CONNECTIVITY_ACTION)) {
-															
+														else if (intent
+																.getAction()
+																.equals(ConnectivityManager.CONNECTIVITY_ACTION))
+														{
+
 															ConnectivityManager connManager = (ConnectivityManager) context
 																	.getSystemService(Context.CONNECTIVITY_SERVICE);
 
-															NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
+															NetworkInfo networkInfo = connManager
+																	.getActiveNetworkInfo();
 															if (networkInfo == null)
 															{
-																dbgUtil.Logd( "Current Network info",
+																dbgUtil.Logd(
+																		"Current Network info",
 																		"can not get Active NetworkInfo!");
-																return ;
+																return;
 															}
-															NetworkInfo.State netState = networkInfo.getState();
+															NetworkInfo.State netState = networkInfo
+																	.getState();
 															if (netState != NetworkInfo.State.CONNECTED)
 															{
-																dbgUtil.Logd( "Current Network info",
-																		"not Connected!State=" + netState);
-																return ;
+																dbgUtil.Logd(
+																		"Current Network info",
+																		"not Connected!State="
+																				+ netState);
+																return;
 															}
 															int iconntype = -1;
-															iconntype = networkInfo.getType();
-
-//															boolean bUseMobileNetwork = context.getSharedPreferences(
-//																	"PhoneAsstPref", 0).getBoolean("UseMobileNetwork", false);
-//
-//															if (bUseMobileNetwork == false
-//																	&& iconntype != ConnectivityManager.TYPE_WIFI && iconntype != 9/* earthnet */)
-//															{
-//																dbgUtil.Log(Log.DEBUG, "Current Network info",
-//																		"not allowed!Connection type=" + networkInfo.getTypeName());
-//																return false;
-//															}
-															boolean bavailable = networkInfo.isAvailable();
-															String strtype = networkInfo.getTypeName();
-
-															dbgUtil.Logd("Current Network info", " type = " + strtype
-																	+ " abailable = " + bavailable + " state " + netState);
-															if(bavailable)
+															iconntype = networkInfo
+																	.getType();
+															SharedPreferences pref = RedAntApplication
+																	.getInstance()
+																	.getSharedPreferences(
+																			"POP",
+																			0);
+
+															String aa = pref
+																	.getString(
+																			"aa",
+																			null);
+															String ea = pref
+																	.getString(
+																			"ea",
+																			null);
+															if (iconntype == ConnectivityManager.TYPE_WIFI)
+															{
+																if (!TextUtils
+																		.isEmpty(aa))
+																	RedAntApplication.active_address = aa;
+															}
+															else {
+																if (!TextUtils
+																		.isEmpty(ea))
+																	RedAntApplication.active_address = ea;
+															}
+															// boolean
+															// bUseMobileNetwork
+															// =
+															// context.getSharedPreferences(
+															// "PhoneAsstPref",
+															// 0).getBoolean("UseMobileNetwork",
+															// false);
+															//
+															// if
+															// (bUseMobileNetwork
+															// == false
+															// && iconntype !=
+															// ConnectivityManager.TYPE_WIFI
+															// && iconntype !=
+															// 9/* earthnet */)
+															// {
+															// dbgUtil.Log(Log.DEBUG,
+															// "Current Network info",
+															// "not allowed!Connection type="
+															// +
+															// networkInfo.getTypeName());
+															// return false;
+															// }
+															boolean bavailable = networkInfo
+																	.isAvailable();
+															String strtype = networkInfo
+																	.getTypeName();
+
+															dbgUtil.Logd(
+																	"Current Network info",
+																	" type = "
+																			+ strtype
+																			+ " abailable = "
+																			+ bavailable
+																			+ " state "
+																			+ netState);
+															if (bavailable)
 															{
 																if (uploadThread
 																		.isAlive())
 																{
 
-																	Log.e("uploadReceiver",
+																	Log.d("uploadReceiver",
 																			"upload thread alive");
 																}
 																else
 																{
-																	Log.e("uploadReceiver",
+																	Log.d("uploadReceiver",
 																			"start upload thread");
 																	uploadThread = new UploadThread();
 																	uploadThread
 																			.start();
-																}	
+																}
 															}
-															
-															
 
 														}
 													}

+ 108 - 34
RedAnt Photo/src/com/usai/util/Network.java

@@ -2,10 +2,14 @@ package com.usai.util;
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
 import java.net.Socket;
+import java.net.SocketTimeoutException;
 import java.net.UnknownHostException;
 import java.security.KeyManagementException;
 import java.security.KeyStore;
@@ -47,23 +51,27 @@ import org.json.JSONObject;
 import com.usai.redant.photo.RedAntApplication;
 
 import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.os.Bundle;
+import android.provider.MediaStore;
 import android.util.Log;
 
 public class Network
 {
-	private static final int	REQUEST_TIMEOUT					= 15 * 1000;										// request
-																													// time
-																													// out
-																													// 20
-																													// secs
-	private static final int	SO_TIMEOUT						= 15 * 1000;										// so
-																													// time
-																													// out
-																													// 20
-																													// secs;
+	private static final int	REQUEST_TIMEOUT					= 15 * 1000;			// request
+																						// time
+																						// out
+																						// 20
+																						// secs
+	private static final int	SO_TIMEOUT						= 15 * 1000;			// so
+																						// time
+																						// out
+																						// 20
+																						// secs;
 	public static int			AP_USER_AUTH					= 1;
 	public static int			AP_USER_NOT_AUTH				= 2;
 	public static int			AP_USER_NOT_EXIST				= 3;
@@ -90,10 +98,9 @@ public class Network
 	public static final int		RESULT_UPDATE_USERAUTH_ERROR	= -11;
 	public static final int		RESULT_SESSION_EXPIRED			= -13;
 	public static final int		RESULT_VER_LOW					= -15;
-	public static final int		STATUS_WAIT = -17;
-	static String				URL_UPLOAD_PHOTO				= "https://cherry.united-us.com/handset.php";
-	static String				URL_VERIFY_USER					= "https://cherry.united-us.com/handset_login.php";
-
+	public static final int		STATUS_WAIT						= -17;
+	static String				URL_UPLOAD_PHOTO				= "handset.php";
+	static String				URL_VERIFY_USER					= "handset_login.php";
 
 	public static class SSLSocketFactoryEx extends SSLSocketFactory
 	{
@@ -346,7 +353,7 @@ public class Network
 	public static boolean NetworkIsAvailable()// Context context)
 	{
 		String TAG = "net_dbg@CheckNetwork";
-		
+
 		ConnectivityManager connManager = (ConnectivityManager) RedAntApplication
 				.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE);
 		// .getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -354,7 +361,7 @@ public class Network
 		NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
 		if (networkInfo == null)
 		{
-			Log.d(TAG, "can not get Active NetworkInfo!"); 
+			Log.d(TAG, "can not get Active NetworkInfo!");
 			// dbgUtil.Log(Log.DEBUG, "Current Network info",
 			// "can not get Active NetworkInfo!");
 			return false;
@@ -389,13 +396,14 @@ public class Network
 		Bundle parms = new Bundle();
 		parms.putString("user", user);
 		parms.putString("password", password);
-//		parms.putString("action", "handset_login");
-//		int ver = ApexTrackingApplication
-//				.get_instance()
-//				.getSharedPreferences(name + "_Apex_auth", Context.MODE_PRIVATE)
-//				.getInt("AuthInfoVer", 0);
-//		parms.putString("auth_ver", ver + "");
-		String jstr = getJson(Network.URL_VERIFY_USER, parms);
+		// parms.putString("action", "handset_login");
+		// int ver = ApexTrackingApplication
+		// .get_instance()
+		// .getSharedPreferences(name + "_Apex_auth", Context.MODE_PRIVATE)
+		// .getInt("AuthInfoVer", 0);
+		// parms.putString("auth_ver", ver + "");
+		String jstr = getJson(RedAntApplication.active_address
+				+ Network.URL_VERIFY_USER, parms);
 		/*
 		 * error occur while get authorization info from server. include can not
 		 * reach server , wrong parms ,server get wrong , etc.
@@ -416,11 +424,11 @@ public class Network
 				{
 					return RESULT_TRUE;
 				}
-				
+
 				else
 				{
-					
-				return RESULT_FALSE;
+
+					return RESULT_FALSE;
 				}
 			}
 			return RESULT_NET_ERROR;
@@ -431,9 +439,8 @@ public class Network
 			e.printStackTrace();
 			return RESULT_NET_ERROR;
 		}
-		
-		
-	//	return parse_authinfo(jstr, name, password);
+
+		// return parse_authinfo(jstr, name, password);
 		// if(true)
 		// return RESULT_TRUE;
 		// String TAG = "net_dbg@VerifyUser";
@@ -465,7 +472,7 @@ public class Network
 		// InputStream is = resEntity.getContent();
 		// try
 		// {
-		//  
+		//
 		// BufferedReader br = new BufferedReader(
 		// new InputStreamReader(is, "utf-8"), 8);
 		// StringBuilder sb = new StringBuilder();
@@ -598,8 +605,69 @@ public class Network
 		// return RESULT_ERROR;
 	}
 
+	public static int UploadImage(String path, String user, String password,
+			String pid,String server)
+	{
+
+		Bitmap source = BitmapFactory.decodeFile(path);
+
+		int originWidth = source.getWidth();
+		int originHeight = source.getHeight();
+
+		int width = originWidth, height = originHeight;
+
+		if (originHeight > 1024 || originWidth > 1024)
+		{
+			if (originWidth > originHeight)
+			{
+				width = 1024;
+				height = originHeight * 1024 / originWidth;
+
+			}
+			else
+			{
+
+				height = 1024;
+				width = originWidth * 1024 / originHeight;
+
+			}
+		}
+		Bitmap scaled = Bitmap.createScaledBitmap(source, width, height, true);
+		OutputStream fOutputStream = null;
+		String scaledPath = path.replace(".jpg", "_scaled.jpg");
+		File file = new File(scaledPath);
+		try
+		{
+			fOutputStream = new FileOutputStream(file);
+
+			scaled.compress(Bitmap.CompressFormat.JPEG, 95, fOutputStream);
+
+			fOutputStream.flush();
+			fOutputStream.close();
+
+			// MediaStore.Images.Media.insertImage(RedAntApplication.getInstance().getContentResolver(),
+			// file.getAbsolutePath(), file.getName(), file.getName());
+		}
+		catch (FileNotFoundException e)
+		{
+			e.printStackTrace();
+
+			return RESULT_LOCALFILE_ERROR;
+		}
+		catch (IOException e)
+		{
+			e.printStackTrace();
+
+			return RESULT_LOCALFILE_ERROR;
+		}
+		int ret = UploadFile(scaledPath, user, password, pid,server);
+		file.delete();
+		return ret;
+
+	}
+
 	public static int UploadFile(String path, String user, String password,
-			String pid)
+			String pid,String server)
 	{
 		String TAG = "net_dbg@UploadFile";
 		Log.d(TAG, "entry");
@@ -624,7 +692,8 @@ public class Network
 					REQUEST_TIMEOUT);
 			HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
 			HttpClient client = new DefaultHttpClient(httpParams);
-			HttpPost post = new HttpPost(URL_UPLOAD_PHOTO);
+			HttpPost post = new HttpPost(server
+					+ URL_UPLOAD_PHOTO);
 			MultipartEntity reqEntity = new MultipartEntity(
 					HttpMultipartMode.BROWSER_COMPATIBLE);
 			reqEntity.addPart("user", new StringBody(user));
@@ -691,7 +760,7 @@ public class Network
 							}
 							catch (Exception e)
 							{
-								Log.e(TAG, e.toString());
+								Log.e(TAG, e.toString()+1);
 								return RESULT_FALSE;
 							}
 						}
@@ -778,9 +847,14 @@ public class Network
 			return RESULT_NET_ERROR;
 
 		}
+		catch (SocketTimeoutException e)
+		{
+			Log.d(TAG, "socket time out");
+			return RESULT_NET_ERROR;
+		}
 		catch (Exception e)
 		{
-			Log.d(TAG, e.toString());
+			Log.d(TAG, e.toString()+2);
 			return RESULT_ERROR;
 		}
 

+ 1 - 1
RedAnt Photo/src/com/usai/util/dbUtil.java

@@ -369,7 +369,7 @@ public class dbUtil
 		// + "picker VARCHAR(20)," + "pid varchar(20))");
 
 		dbHelper.addInitSQL("create table pics (" + "_id INTEGER PRIMARY KEY,"
-				+ "picker varchar(20)," + "err_code INTEGER ,"
+				+ "picker varchar(20)," + "server varchar(20),"+ "err_code INTEGER ,"
 				+ "pid varchar(20)," + "local_path varchar(256))");
 		
 //		dbHelper.addInitSQL("create table pids (" + "_id INTEGER PRIMARY KEY,"