|
|
@@ -20,8 +20,10 @@ import android.os.Bundle;
|
|
|
import android.os.Environment;
|
|
|
import android.provider.MediaStore;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
+import android.text.Editable;
|
|
|
import android.text.InputType;
|
|
|
import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.Menu;
|
|
|
@@ -44,6 +46,8 @@ import com.usai.util.Network;
|
|
|
import com.usai.util.RAUtil;
|
|
|
import com.usai.util.dbgUtil;
|
|
|
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
@@ -61,6 +65,9 @@ public class MainActivity extends AppCompatActivity
|
|
|
{
|
|
|
|
|
|
private VerifyCodeTask verifytask=null;
|
|
|
+ private QueryManufacturer qmtask=null;
|
|
|
+ private JSONArray manufacture_arr=null;
|
|
|
+ private AlertDialog qmdialog =null;
|
|
|
public void verifyandupload(Bundle params)
|
|
|
{
|
|
|
if (verifytask != null)
|
|
|
@@ -74,7 +81,191 @@ public class MainActivity extends AppCompatActivity
|
|
|
verifytask.execute(params);
|
|
|
|
|
|
}
|
|
|
+ public void querymanufacturer(Bundle params)
|
|
|
+ {
|
|
|
+ if (qmtask != null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ qmdialog=new AlertDialog.Builder(MainActivity.this)
|
|
|
+ .setTitle("Searching manufacturer")
|
|
|
+ .setMessage("Please Wait")
|
|
|
+
|
|
|
+ .show();
|
|
|
+ qmtask = new QueryManufacturer();
|
|
|
+ qmtask.execute(params);
|
|
|
+
|
|
|
+ }
|
|
|
+ public class QueryManufacturer extends AsyncTask<Bundle, Void, Boolean>
|
|
|
+ {
|
|
|
+
|
|
|
+ JSONObject json = null;
|
|
|
+
|
|
|
+ // int netconnect;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Boolean doInBackground(Bundle... params)
|
|
|
+ {
|
|
|
+ json = Network.Query_Manufacturer(params[0]);
|
|
|
+ try {
|
|
|
+ if (json.getInt("result") == Network.RESULT_TRUE)
|
|
|
+ return true;
|
|
|
+ else
|
|
|
+ return false;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPostExecute(final Boolean success)
|
|
|
+ {
|
|
|
+
|
|
|
+ Log.i("onPostExecute", "entry");
|
|
|
+ qmtask = null;
|
|
|
+ qmdialog.hide();
|
|
|
+// showProgress(false);
|
|
|
+
|
|
|
+ if (success)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ manufacture_arr=json.getJSONArray("manufacturer");
|
|
|
+ if(manufacture_arr.length()==1) {
|
|
|
+ String manufacture = manufacture_arr.getString(0);
|
|
|
+ setManufacture(manufacture);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ setManufacture("");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //验证成功
|
|
|
+
|
|
|
+
|
|
|
+// Intent intent = new Intent("REDANT.RAImage.ADD_TASK");
|
|
|
+//
|
|
|
+// ArrayList<Bundle> taskArr = new ArrayList<Bundle>();
|
|
|
+// String name = "POP";
|
|
|
+//
|
|
|
+//// if(MainActivity.this instanceof ModelActivity)
|
|
|
+//// name=name = "Model";
|
|
|
+// if (MainActivity.this.getClass().equals(ModelActivity.class)) {
|
|
|
+// name = "Model";
|
|
|
+// }
|
|
|
+// for (String path : photoList) {
|
|
|
+// Bundle task = new Bundle();
|
|
|
+//
|
|
|
+// task.putString("path",path);
|
|
|
+// task.putString("file",RAUtil.lastPathComponent(path));
|
|
|
+// task.putString("url",RedAntApplication.active_address);
|
|
|
+//
|
|
|
+// String md5 = MD5.md5sum(path);
|
|
|
+// String encryptUser = AES.encrypt("usai",RedAntApplication.user);
|
|
|
+// String encryptPwd = AES.encrypt("usai",RedAntApplication.password);
|
|
|
+//
|
|
|
+// Bundle params = new Bundle();
|
|
|
+// params.putString("user",encryptUser);
|
|
|
+// params.putString("password",encryptPwd);
|
|
|
+// params.putString("mode",name);
|
|
|
+// params.putString("barcode",pidval.getText().toString());
|
|
|
+// params.putString("_operate","upload");
|
|
|
+// params.putString("platform","android");
|
|
|
+// params.putString("md5",md5);
|
|
|
+//
|
|
|
+//
|
|
|
+// if (MainActivity.this.getClass().equals(ModelActivity.class)) {
|
|
|
+//
|
|
|
+// if (!TextUtils.isEmpty(manufacture)) {
|
|
|
+// params.putString("manufacturer",manufacture);
|
|
|
+// }
|
|
|
+// if (!TextUtils.isEmpty(noteTextView.getText().toString())) {
|
|
|
+// params.putString("note",noteTextView.getText().toString());
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// task.putBundle("params",params);
|
|
|
+//
|
|
|
+// taskArr.add(task);
|
|
|
+// }
|
|
|
+//
|
|
|
+// intent.putParcelableArrayListExtra("tasks",taskArr);
|
|
|
+//
|
|
|
+// sendBroadcast(intent);
|
|
|
+// clearfornew();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int result = 0;
|
|
|
+ try {
|
|
|
+ result = json.getInt("result");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ result = Network.RESULT_NET_ERROR;
|
|
|
+
|
|
|
+ }
|
|
|
+ switch (result)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ {
|
|
|
+ // model , piid not exist
|
|
|
+
|
|
|
+
|
|
|
+ String msg = "User / password does not match.";
|
|
|
+
|
|
|
+// if (MainActivity.this.getClass().equals(ModelActivity.class)) {
|
|
|
+// msg = "Model does not exist.";
|
|
|
+// }
|
|
|
+ Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
+ msg,
|
|
|
+ Toast.LENGTH_LONG);
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
+ toast.show();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+// case 1:
|
|
|
+// {
|
|
|
+// //model / manufacturer not match
|
|
|
+// Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
+// "Model/Manufacturer does not match.",
|
|
|
+// Toast.LENGTH_LONG);
|
|
|
+// toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
+// toast.show();
|
|
|
+// break;
|
|
|
+// }
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ // net error.
|
|
|
+ Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
+ "Can not get manufacturer information.",
|
|
|
+ Toast.LENGTH_LONG);
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
+ toast.show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCancelled()
|
|
|
+ {
|
|
|
+ verifytask = null;
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
public class VerifyCodeTask extends AsyncTask<Bundle, Void, Boolean>
|
|
|
{
|
|
|
|
|
|
@@ -329,6 +520,53 @@ public class MainActivity extends AppCompatActivity
|
|
|
thumbsImageView = (ImageView)findViewById(R.id.photo_iv);
|
|
|
countTextView = (TextView)findViewById(R.id.photo_count_lb);
|
|
|
pidval = (EditText)findViewById(R.id.barcode_et);
|
|
|
+
|
|
|
+ if (MainActivity.this.getClass().equals(ModelActivity.class)) { // model
|
|
|
+
|
|
|
+ pidval.addTextChangedListener(new TextWatcher() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
+ // 输入的内容变化的监听
|
|
|
+// Log.e("输入过程中执行该方法", "文字变化");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence s, int start, int count,
|
|
|
+ int after) {
|
|
|
+ // 输入前的监听
|
|
|
+// Log.e("输入前确认执行该方法", "开始输入");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable s) {
|
|
|
+ // 输入后的监听
|
|
|
+
|
|
|
+ String model = s.toString();
|
|
|
+ if(TextUtils.isEmpty(model))
|
|
|
+ return;
|
|
|
+ Log.e("输入结束执行该方法", "输入结束"+ s.toString());
|
|
|
+
|
|
|
+ String encryptUser = AES.encrypt("usai",RedAntApplication.user);
|
|
|
+ String encryptPwd = AES.encrypt("usai",RedAntApplication.password);
|
|
|
+
|
|
|
+ Bundle params = new Bundle();
|
|
|
+ params.putString("user",encryptUser);
|
|
|
+ params.putString("password",encryptPwd);
|
|
|
+ params.putString("barcode",model);
|
|
|
+ params.putString("type","model");
|
|
|
+ params.putString("_operate","handset_get_manufacturer");
|
|
|
+ params.putString("platform","android");
|
|
|
+
|
|
|
+
|
|
|
+ querymanufacturer(params);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
noteTextView = (EditText)findViewById(R.id.note_et);
|
|
|
ibtnscan = (ImageButton)findViewById(R.id.scan_btn);
|
|
|
captureButton = (ImageButton)findViewById(R.id.camera_btn);
|
|
|
@@ -625,6 +863,39 @@ public class MainActivity extends AppCompatActivity
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
Intent intent = new Intent(MainActivity.this, ManufactureListActivity.class);
|
|
|
+
|
|
|
+ JSONArray manufactureArr = manufacture_arr;
|
|
|
+
|
|
|
+ if(manufactureArr==null||manufactureArr.length()==0)
|
|
|
+ {
|
|
|
+
|
|
|
+ try {
|
|
|
+ JSONArray modeArr = RedAntApplication.server_info.getJSONArray("modellist");
|
|
|
+ for (int i = 0;i < modeArr.length(); i++) {
|
|
|
+ JSONObject obj = modeArr.getJSONObject(i);
|
|
|
+ String name = obj.getString("name");
|
|
|
+ if (name.equals("Model")) {
|
|
|
+ manufactureArr = obj.getJSONArray("manifacturer");
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ArrayList<String> mlist = new ArrayList<String>();
|
|
|
+ for (int j = 0; j < manufactureArr.length(); j++) {
|
|
|
+ String manufacture = null;
|
|
|
+ try {
|
|
|
+ manufacture = manufactureArr.getString(j);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ mlist.add(manufacture);
|
|
|
+ }
|
|
|
+
|
|
|
+ intent.putStringArrayListExtra("mlist",mlist);
|
|
|
startActivityForResult(intent,REQUEST_MANUFACTURE);
|
|
|
}
|
|
|
});
|
|
|
@@ -1532,6 +1803,8 @@ public class MainActivity extends AppCompatActivity
|
|
|
// TextView countTextView = (TextView) findViewById(R.id.tvPhotoCount);
|
|
|
countTextView.setText("no photo");
|
|
|
|
|
|
+ manufacture_arr=null;
|
|
|
+ setManufacture("");
|
|
|
if(noteTextView!=null)
|
|
|
noteTextView.setText("");
|
|
|
|