|
|
@@ -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();
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
|
|
|
}
|
|
|
}
|