package com.esri.activity;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.IOException;import java.util.Date;import java.util.HashMap;import java.util.Map;import android.app.Activity;import android.app.ProgressDialog;import android.content.ContentValues;import android.content.Intent;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.net.Uri;import android.os.AsyncTask;import android.os.Bundle;import android.os.Environment;import android.provider.MediaStore;import android.util.Log;import android.view.Gravity;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.EditText;import android.widget.ImageView;import android.widget.LinearLayout.LayoutParams;import android.widget.Spinner;import android.widget.TextView;import android.widget.Toast;import com.esri.android.map.ags.ArcGISFeatureLayer;import com.esri.android.map.ags.ArcGISFeatureLayer.MODE;import com.esri.core.geometry.Point;import com.esri.core.map.CallbackListener;import com.esri.core.map.FeatureEditResult;import com.esri.core.map.FeatureSet;import com.esri.core.map.Graphic;import com.esri.core.tasks.ags.query.Query;import com.esri.core.tasks.ags.query.QueryTask;import com.esri.geometry.utils.GeometryUtils;import com.esri.modle.Enterprise;import com.esri.modle.LawEnforcement;import com.esri.sql.MySQLiteHelper;import com.esri.utils.FeatureUtils;import com.esri.utils.FileOpreateUtils;public class LawEnforcementActivity extends Activity {public static final int NONE = 0;        public static final int PHOTOHRAPH = 1;// 拍照        public static final int PHOTOZOOM = 2; // 缩放        public static final int PHOTORESOULT = 3;// 结果        public static final int CODE_VIDEO = 4;//录像    public static final String IMAGE_UNSPECIFIED = "image/*";          LawEnforcement law = null;    String  filePhotoName = "";    String  fileVideoName = "";Intent intent = null;Spinner law_spinner = null;EditText edit_Enterprisename;EditText enterpris_remarksEdit;ImageView imageView = null;boolean isform = false;ArcGISFeatureLayer featureLayer = null;private MySQLiteHelper msh  = null;//数据库操作类ProgressDialog prog;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubgetWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);requestWindowFeature(Window.FEATURE_NO_TITLE);super.onCreate(savedInstanceState);setContentView(R.layout.law_enforcement);featureLayer = new ArcGISFeatureLayer(FeatureUtils.LAWENFORCEMENT_URL, MODE.SELECTION);law_spinner = (Spinner)findViewById(R.id.law_spinner);edit_Enterprisename = (EditText)findViewById(R.id.edit_Enterprisename);enterpris_remarksEdit = (EditText)findViewById(R.id.enterpris_remarksEdit);imageView = (ImageView)findViewById(R.id.imgView);setValues();setEdites();msh = new MySQLiteHelper(this,"YDZF");}public void onLocation(View v){law.setEnterpris_illegal_type(((TextView)law_spinner.getSelectedView()).getText().toString());law.setEnterpris_Name(edit_Enterprisename.getText().toString());law.setRemarks(enterpris_remarksEdit.getText().toString());law.setFilePhotoName(filePhotoName);law.setFileVideoName(fileVideoName);Bundle bd = new Bundle();    bd.putSerializable("lawenforcement", law);    intent.putExtras(bd);    setResult(1003,intent);finish();}private void setValues(){ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.violatetypes, android.R.layout.simple_list_item_1);spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);law_spinner.setAdapter(spinnerAdapter);law_spinner.setPromptId(R.string.enterpriseviolatetypes);law_spinner.setOnItemSelectedListener(spinnerListener);intent = getIntent();Bundle bd =  intent.getExtras();law = (LawEnforcement)bd.getSerializable("lawenforcement");if(intent.getSerializableExtra("geo") != null){Point geo = (Point)intent.getSerializableExtra("geo");law.setGeo(geo);}//设置spinner的选项law_spinner.setSelection(getSelectCode(law.getEnterpris_illegal_type(),spinnerAdapter));edit_Enterprisename.setText(law.getEnterpris_Name());enterpris_remarksEdit.setText(law.getRemarks());filePhotoName = law.getFilePhotoName();if(filePhotoName != null && !filePhotoName.equals("")){ Bitmap img = BitmapFactory.decodeFile(filePhotoName);             imageView.setImageBitmap(img);             imageView.setLayoutParams(new LayoutParams(100, 100));}}private int getSelectCode(String name,ArrayAdapter<CharSequence> temp){int postion=0;if(temp == null){return 0;}for(int i=0;i<temp.getCount();i++){if(name.equalsIgnoreCase(temp.getItem(i).toString())){postion = i;break;}}return postion;}private AdapterView.OnItemSelectedListener spinnerListener =new  AdapterView.OnItemSelectedListener() {@Overridepublic void onItemSelected(AdapterView<?> arg0, View v,int arg2, long arg3) {// TODO Auto-generated method stubTextView tv = (TextView)v;tv.setTextColor(getResources().getColor(R.color.black));tv.setTextSize(12);tv.setGravity(Gravity.CENTER_HORIZONTAL);}@Overridepublic void onNothingSelected(AdapterView<?> arg0) {// TODO Auto-generated method stub}};public void doTakePhoto(View v){filePhotoName  =  Environment.getExternalStorageDirectory  ().getAbsolutePath()+"/MyMediaStore/";File out = new File(filePhotoName);if(!out.exists()){out.mkdirs();}filePhotoName = filePhotoName+new Date().getTime()+".jpg"; out = new File(filePhotoName); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);             intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));          intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);             startActivityForResult(intent, PHOTOHRAPH);  }public void doTakeVideo(View v) throws IOException{ fileVideoName  =  Environment.getExternalStorageDirectory  ().getAbsolutePath()+"/MyMediaStore/"; Intent videoCaptureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);// File out = new File(fileVideoName);//if(!out.exists()){//out.mkdirs();//}//out = new File(fileVideoName, new Date().getTime()+".mp4");// if(!out.exists()){// out.createNewFile();// }// videoCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out)); videoCaptureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); videoCaptureIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,"2000");          startActivityForResult(videoCaptureIntent, CODE_VIDEO); } @Override         protected void onActivityResult(int requestCode, int resultCode, Intent data) {                 if (resultCode == NONE)                         return;                 // 拍照                 if (requestCode == PHOTOHRAPH) {                         //设置文件保存路径这里放在跟目录下                        // File picture = new File(filePhotoName);                       // startPhotoZoom(Uri.fromFile(picture));                         Bitmap img = BitmapFactory.decodeFile(filePhotoName);                     imageView.setImageBitmap(img);                     imageView.setLayoutParams(new LayoutParams(100, 100));                                  }                                  if (data == null)                         return;                                  // 读取相册缩放图片                 if (requestCode == PHOTOZOOM) {                         startPhotoZoom(data.getData());                 }                 // 处理结果                 if (requestCode == PHOTORESOULT) {                         Bundle extras = data.getExtras();                         if (extras != null) {                                 Bitmap photo = extras.getParcelable("data");                                 ByteArrayOutputStream stream = new ByteArrayOutputStream();                                 photo.compress(Bitmap.CompressFormat.JPEG, 75, stream);// (0 - 100)压缩文件                                 imageView.setImageBitmap(photo);                         }                  }               if(requestCode == CODE_VIDEO)             {             Uri uri = data.getData();             String[] proj = { MediaStore.Video.Media.DATA };             Cursor actualimagecursor = managedQuery(uri,proj,null,null,null);             int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);             actualimagecursor.moveToFirst();             String img_path = actualimagecursor.getString(actual_image_column_index);             File file = new File(img_path);             fileVideoName  =  Environment.getExternalStorageDirectory  ().getAbsolutePath()+"/MyMediaStore/";         File out = new File(fileVideoName);        if(!out.exists()){        out.mkdirs();        }        out = new File(fileVideoName, new Date().getTime()+".mp4");                FileOpreateUtils.copyfile(file, out, true);        if(file.exists()){        file.delete();        }        //         if(!out.exists()){//         try {//out.createNewFile();//} catch (IOException e) {//// TODO Auto-generated catch block//e.printStackTrace();//}//         }//             //             FileOutputStream outStream = null;//try {//outStream = new FileOutputStream(out);//outStream.write(videoBytes);//                outStream.close();//} catch (FileNotFoundException e) {//// TODO Auto-generated catch block//e.printStackTrace();//} catch (IOException e) {//// TODO Auto-generated catch block//e.printStackTrace();//}                          }              super.onActivityResult(requestCode, resultCode, data);         }          public void startPhotoZoom(Uri uri) {                     Intent intent = new Intent("com.android.camera.action.CROP");                 intent.setDataAndType(uri, IMAGE_UNSPECIFIED);                 intent.putExtra("crop", "true");                 // aspectX aspectY 是宽高的比例                 intent.putExtra("aspectX", 1);                 intent.putExtra("aspectY", 1);                 // outputX outputY 是裁剪图片宽高                 intent.putExtra("outputX", 64);                 intent.putExtra("outputY", 64);                 intent.putExtra("return-data", true);                 startActivityForResult(intent, PHOTORESOULT);         }                 public void editForm(View v){ setEdites(); }  private void setEdites(){  law_spinner.setEnabled(isform); //edit_Enterprisename.setEnabled(isform);enterpris_remarksEdit.setEnabled(isform); if(isform){ isform =false; }else{ isform = true; } }  public void submitBtn(View v){ Button btn = (Button)v;btn.setEnabled(false); if(law.getGeo() == null){Toast.makeText(LawEnforcementActivity.this, "没有定位信息,请先定位再提交!", Toast.LENGTH_LONG).show();return;} SQLiteDatabase db = msh.getWritableDatabase();ContentValues values = new ContentValues();values.put("OBJECTID", law.getObjectid());values.put("ENTERPRIS_NAME",  edit_Enterprisename.getText().toString());values.put("ENTERPRIS_ILLEGAL_TYPE",((TextView)law_spinner.getSelectedView()).getText().toString());values.put("EXAMINE_PERSONNAME", law.getExamine_personName());values.put("EQUIPMENT_NUMBER", law.getEquipment_number());values.put("REMARKS",enterpris_remarksEdit.getText().toString());values.put("FILEPHOTONAME",filePhotoName);values.put("FILEVIDEONAME",fileVideoName);String shape = GeometryUtils.GeometryToWKT(law.getGeo());values.put("SHAPE", shape);values.put("MARK", 1);db.update(MySQLiteHelper.LAW_ENFOREMENT, values, "OBJECTID=?", new String[]{law.getObjectid().toString()});  Map<String,Object> attrs = new HashMap<String, Object>(); attrs.put("OBJECTID", law.getObjectid()); attrs.put("ENTERPRIS_NAME", edit_Enterprisename.getText().toString()); attrs.put("ENTERPRIS_ILLEGAL_TYPE", ((TextView)law_spinner.getSelectedView()).getText().toString()); attrs.put("EXAMINE_PERSONNAME", law.getExamine_personName()); attrs.put("EQUIPMENT_NUMBER",law.getEquipment_number()); attrs.put("REMARKS", enterpris_remarksEdit.getText().toString());if(law.getGeo() != null){Point pt = (Point)law.getGeo();attrs.put("X", pt.getX());attrs.put("Y", pt.getY());} Graphic gp = new Graphic(null, null, attrs,null); if(filePhotoName != null && !filePhotoName.equals("")) featureLayer.addAttachment(law.getObjectid(), new File(filePhotoName), new CallbackListener<FeatureEditResult>() {@Overridepublic void onCallback(FeatureEditResult objs) {// TODO Auto-generated method stubLog.i("image", String.valueOf(objs.isSuccess()));}@Overridepublic void onError(Throwable e) {// TODO Auto-generated method stub}}); //featureLayer.addAttachment(law.getObjectid(), new File(filePhotoName), null);  prog = ProgressDialog.show(LawEnforcementActivity.this, "提示信息", "数据正在提交中...."); prog.setCanceledOnTouchOutside(true); featureLayer.applyEdits(null, null, new Graphic[] { gp }, createEditCallbackListener(true));  }  CallbackListener<FeatureEditResult[][]> createEditCallbackListener(final boolean updateLayer) {     return new CallbackListener<FeatureEditResult[][]>() {       public void onCallback(FeatureEditResult[][] result) {           if (updateLayer) {           featureLayer.refresh();          LawEnforcementActivity.this.runOnUiThread(new Runnable() {  @Override public void run() { // TODO Auto-generated method stub prog.dismiss();          Toast.makeText(LawEnforcementActivity.this, "数据提交成功", Toast.LENGTH_LONG).show();          finish(); } });                     }       }       public void onError(Throwable e) {      prog.dismiss();       }     };   }   public void enterpriseView(View v){  //featureQuery(FeatureUtils.ENTERPRISE_URL,MySQLiteHelper.ENTERPRISE_EXAMINE); MyQueryTask myquery = new MyQueryTask(); myquery.execute();  }    private void featureQuery(String url,String tabletemp){    Query query = new Query();query.setWhere("ENTERPRISE_ID = '"+law.getEnterpries_id()+"' order by objectid asc");query.setOutFields(new String[] { "*" });query.setReturnGeometry(false);//query.setInSpatialReference(temp.getSpatialReference());QueryTask qTask = new QueryTask(url);try {FeatureSet queryResults = qTask.execute(query);Map<String, Object> attu = null;if(queryResults != null){attu = queryResults.getGraphics()[0].getAttributes();}else{return ;}Intent intent = new Intent();    Enterprise enterprise = new Enterprise();        enterprise.setEnterprise_Name(attu.get("ENTERPRISE_NAME").toString());        if(attu.get("ENTERPRISE_ADDRESS") != null){    enterprise.setEnterprise_Address(attu.get("ENTERPRISE_ADDRESS").toString());        }    if(attu.get("ENTERPRISE_CONTAMINATION")!=null){        enterprise.setEnterprise_contamination(attu.get("ENTERPRISE_CONTAMINATION").toString());    }    if(attu.get("ENTERPRISE_ILLEGAL_RECORDS") != null){        enterprise.setEnterprise_illegal_records(attu.get("ENTERPRISE_ILLEGAL_RECORDS").toString());    }    if(attu.get("ENTERPRISE_LAST_EXAMINE_TIMES") != null){        enterprise.setEnterprise_last_query_times(attu.get("ENTERPRISE_LAST_EXAMINE_TIMES").toString());    }    if(attu.get("ENTERPRISE_LEGAL_PERSON") != null){        enterprise.setEnterprise_legal_person(attu.get("ENTERPRISE_LEGAL_PERSON").toString());    }        Bundle bd = new Bundle();    bd.putSerializable("enterprise", enterprise);        intent.putExtras(bd);        intent.setClass(LawEnforcementActivity.this, EnterpriseActivity.class);    startActivityForResult(intent, 1002);} catch (Exception e1) {// TODO Auto-generated catch block//e1.printStackTrace();Toast.makeText(LawEnforcementActivity.this, "查询时出现问题,查看网络是否连接正常", Toast.LENGTH_LONG);}    }    class MyQueryTask extends AsyncTask<String, Void, FeatureSet>{@Overrideprotected FeatureSet doInBackground(String... params) {// TODO Auto-generated method stub featureQuery(FeatureUtils.ENTERPRISE_URL,MySQLiteHelper.ENTERPRISE_EXAMINE);return null;}@Overrideprotected void onPostExecute(FeatureSet result) {// TODO Auto-generated method stubprog.dismiss();}@Overrideprotected void onPreExecute() {// TODO Auto-generated method stubeprog = ProgressDialog.show(LawEnforcementActivity.this, "提示信息", "正在查询....");}        }          }

更多相关文章

  1. android 根据Bitmap bitmap 保存图片到手机上
  2. TextView实现中间文字两侧图片的样式 和 左侧图片右侧文字
  3. Android 异步加载一张网络图片
  4. Android实验七之SQLite数据库存储
  5. Android ContentProviders数据共享

随机推荐

  1. Android中ScrollView中嵌套RecyclerView
  2. android怎么做单元调式
  3. Android常用方法总结
  4. Android:Android(安卓)Failed to install
  5. Android(安卓)下拉刷新 ListRefresh 从网
  6. 为Android写的WebService调用组件
  7. Android(安卓)project structure
  8. android 保存和读取文件
  9. Android(安卓)中RecyclerView使用详解(一)
  10. android中colors.xml中用到的主要颜色的