Java tutorial
/* * Copyright (c) 2005, 2014, EVECOM Technology Co.,Ltd. All rights reserved. * EVECOM PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */ package net.evecom.android; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import net.evecom.android.bean.FileManageBean; import net.evecom.android.bean.FileManageBean1; import net.evecom.android.bean.OpinionPerson; import net.evecom.android.gps.GPSActivity; import net.evecom.android.gps.tdt.TDTLocation; import net.evecom.android.util.HttpUtil; import net.evecom.android.util.UiUtil; import net.tsz.afinal.FinalDb; import net.tsz.afinal.FinalHttp; import net.tsz.afinal.http.AjaxCallBack; import net.tsz.afinal.http.AjaxParams; import android.app.Activity; import android.app.AlertDialog; import android.app.DatePickerDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.app.TimePickerDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.DatePicker; import android.widget.EditText; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; /** * * PublicOpinionLookActivity * @author Mars zhang * @created 2014-11-5 11:01:14 */ public class PublicOpinionLookActivity extends Activity { /** MemberVariables */ private static final int MESSAGETYPE_01 = 0x0001;// /** MemberVariables */ private static final int MESSAGETYPE_02 = 0x0002; /** */ private EditText ztEditText; // public_opinion_add_bt /** */ private EditText fsddEditText; // public_opinion_add_fsdd /** */ private Button lylxButton; // public_opinion_add_lylx /** */ private String[] lylxs; /** */ private int sourceway; /** */ private Button lysjButton; // public_opinion_add_lysj_btn /** */ private Button ztButton; // public_opinion_look_zt /** */ private String[] zt; /** */ private String zt1 = ""; /** */ private EditText lyrEditText; // public_opinion_add_lyr /** */ private EditText lxdhEditText; // public_opinion_add_lxdh /** */ private EditText xxnrEditText; // public_opinion_add_xxnr /** sss */ private String sss = ""; /** MemberVariables */ String listopinionPerson = ""; /** */ private FinalDb db; /** */ private List<FileManageBean> fileListg; /** */ private ListView fileListView; // add_hidden_atdanger_picture_list /** */ private ListView fileListView1; // add_hidden_atdanger_picture_list /** */ private UploadPictureAdapter uploadPictureAdapter; /** PIC */ private static final String FILE_TYPE_PIC_01 = "1"; /** VIDEO */ private static final String FILE_TYPE_VIDEO_02 = "2"; /** AUDIO */ private static final String FILE_TYPE_AUDIO_03 = "3"; /** MemberVariables */ boolean isprogressDialogCanClose = false; /** MemberVariables */ Message msg_listData2 = null; /** MemberVariables */ Message msg_listData = null; /** Id */ private String Id; /** handler */ private Handler handler = null; /** */ private List<OpinionPerson> opinionPerson = new ArrayList<OpinionPerson>(); /** */ private List<FileManageBean1> fileManageBean1 = new ArrayList<FileManageBean1>(); /** */ private ProgressDialog progressDialog; /** uaid */ private String uaid = ""; /** */ private FileManageBeanAdapter fileManageBeanAdapter = null; /** Calendar */ private Calendar calendar = null; /** */ private String lysj = ""; /** */ private int years; /** */ private int month; /** */ private int day; /** */ private int hours; /** */ private int minutes; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.public_opinion_look_activity); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); Intent intent = getIntent(); Id = intent.getStringExtra("Id"); init(); init1(); initView(); getXmlAndSetList(); // adapter(); } /** * */ private void init() { lylxs = new String[] { "", "", "", "", "", "" }; zt = new String[] { "", "", "", "" }; } /** * */ private void init1() { /** */ db = FinalDb.create(this); db.deleteAll(FileManageBean.class); } /** * */ private void initView() { ztEditText = (EditText) findViewById(R.id.public_opinion_look_bt); fsddEditText = (EditText) findViewById(R.id.public_opinion_look_fsdd); lylxButton = (Button) findViewById(R.id.public_opinion_look_lylx); lysjButton = (Button) findViewById(R.id.public_opinion_look_lysj_btn); lyrEditText = (EditText) findViewById(R.id.public_opinion_look_lyr); lxdhEditText = (EditText) findViewById(R.id.public_opinion_look_lxdh); xxnrEditText = (EditText) findViewById(R.id.public_opinion_look_xxnr); ztButton = (Button) findViewById(R.id.public_opinion_look_zt); // fileListView = (ListView) findViewById(R.id.event_add_file_list); fileListView1 = (ListView) findViewById(R.id.event_add_file_list1); calendar = Calendar.getInstance();// listener(); } /** * */ private void listener() { lysjButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog dialog = new AlertDialog.Builder(PublicOpinionLookActivity.this).setTitle("") .setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Dialog dialog1 = new DatePickerDialog(PublicOpinionLookActivity.this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String MonthOfYear = ""; String DayOfMonth = ""; years = year; month = monthOfYear + 1; day = dayOfMonth; if (monthOfYear < 9) { MonthOfYear = "0" + month; } else { MonthOfYear = "" + month; } if (dayOfMonth < 9) { DayOfMonth = "0" + dayOfMonth; } else { DayOfMonth = "" + dayOfMonth; } lysjButton.setText("" + year + "-" + MonthOfYear + "-" + DayOfMonth + " " + hours + ":" + minutes + ":" + calendar.get(Calendar.SECOND)); // lysjButton.setText("" + years // + "-" // + month // + "-" + day +" " // + hours +":" // + minutes+":" // + // calendar.get(Calendar.SECOND)); lysj = years + "-" + month + "-" + day + "+" + hours + "%3A" + minutes + "%3A" + calendar.get(Calendar.SECOND); } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));// dialog1.show(); } }).setNeutralButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Dialog dialog2 = new TimePickerDialog(PublicOpinionLookActivity.this, new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hour, int minute) { lysjButton.setText("" + years + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + calendar.get(Calendar.SECOND)); hours = hour; minutes = minute; lysj = years + "-" + month + "-" + day + "+" + hours + "%3A" + minutes + "%3A" + calendar.get(Calendar.SECOND); } }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true);// dialog2.show(); } }).setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { lysjButton.setText(""); lysj = ""; } }).show(); } }); // lylxButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Dialog schDia = new AlertDialog.Builder(PublicOpinionLookActivity.this) .setIcon(R.drawable.login_error_icon).setTitle("") .setItems(lylxs, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dia, int which) { lylxButton.setText(lylxs[which]); sourceway = which + 1; } }).setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dia, int which) { dia.dismiss(); } }).create(); schDia.show(); } }); } /** * */ private void adapter() { fileListg = new ArrayList<FileManageBean>(); uploadPictureAdapter = new UploadPictureAdapter(getApplicationContext(), fileListg); fileListView.setAdapter(uploadPictureAdapter); } /** * */ private void getXmlAndSetList() { Runnable runnable = new Runnable() { public void run() { // Message msg_listData3 = new Message(); String strUrl = HttpUtil.BASE_URL + "teventAndroid/detailSocialAndroid?" + "Id=" + Id; try { sss = connServerForResult(strUrl); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } listopinionPerson = sss; handler.sendMessage(handler.obtainMessage(0, listopinionPerson)); } }; try { // new Thread(runnable).start(); // handler handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 0) { BinderListData(listopinionPerson); } } }; } catch (Exception e) { e.printStackTrace(); } } /** * * * @param listopinionPerson2 * @throws JSONException */ public void BinderListData(String listopinionPerson2) { try { JSONArray jsonArray = null; jsonArray = new JSONArray(listopinionPerson2); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject2 = jsonArray.getJSONObject(i); ztEditText.setText(jsonObject2.getString("eventname")); fsddEditText.setText(jsonObject2.getString("occuraddr")); if ("1".equals(jsonObject2.getString("sourceway"))) { lylxButton.setText(lylxs[0]); sourceway = 1; } else if ("2".equals(jsonObject2.getString("sourceway"))) { lylxButton.setText(lylxs[1]); sourceway = 2; } else if ("3".equals(jsonObject2.getString("sourceway"))) { lylxButton.setText(lylxs[2]); sourceway = 3; } else if ("4".equals(jsonObject2.getString("sourceway"))) { lylxButton.setText(lylxs[3]); sourceway = 4; } else if ("5".equals(jsonObject2.getString("sourceway"))) { lylxButton.setText(lylxs[4]); sourceway = 5; } else if ("6".equals(jsonObject2.getString("sourceway"))) { lylxButton.setText(lylxs[5]); sourceway = 6; } zt1 = jsonObject2.getString("eventstatus"); if ("1".equals(jsonObject2.getString("eventstatus"))) { ztButton.setText(zt[0]); } else if ("2".equals(jsonObject2.getString("eventstatus"))) { ztButton.setText(zt[1]); } else if ("3".equals(jsonObject2.getString("eventstatus"))) { ztButton.setText(zt[2]); } else if ("4".equals(jsonObject2.getString("eventstatus"))) { ztButton.setText(zt[3]); } lysjButton.setText(jsonObject2.getString("occurtime")); lyrEditText.setText(jsonObject2.getString("sourcepeople")); lxdhEditText.setText(jsonObject2.getString("phone")); xxnrEditText.setText(jsonObject2.getString("news")); if (lysjButton.getText().length() > 1) { String[] s = Pattern.compile(":").split(lysjButton.getText().toString().trim()); lysj = s[0] + "%3A" + s[1] + "%3A" + s[2]; } else { lysj = ""; } uaid = jsonObject2.getString("photourl"); getURI(uaid); } } catch (JSONException e) { e.printStackTrace(); } } /** */ private void getURI(final String Uaid) { // Runnable runnable = new Runnable() { public void run() { String path = HttpUtil.BASE_URL + "teventAndroid/fileList?" + "ids=" + Uaid; try { sss = connServerForResult(path); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String listfileManageBean = sss; try { fileManageBean1 = getPersons(listfileManageBean); } catch (JSONException e) { e.printStackTrace(); } handler.sendMessage(handler.obtainMessage(0, opinionPerson)); } }; try { // new Thread(runnable).start(); // handler handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 0) { BinderListData1(fileManageBean1); } } }; } catch (Exception e) { e.printStackTrace(); } } /** * * * @param list */ public void BinderListData1(List<FileManageBean1> list) { fileManageBeanAdapter = new FileManageBeanAdapter(getApplicationContext(), list); fileListView1.setAdapter(fileManageBeanAdapter); if (null != fileListView1) { UiUtil.setListViewHeightBasedOnChildren(fileListView1); } } /** * json * */ public static List<FileManageBean1> getPersons(String jsonString) throws JSONException { List<FileManageBean1> list = new ArrayList<FileManageBean1>(); JSONArray jsonArray = null; jsonArray = new JSONArray(jsonString); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject2 = jsonArray.getJSONObject(i); FileManageBean1 fileManageBean1 = new FileManageBean1(); if (isImagePicture(jsonObject2.getString("UA_TYPE"))) { fileManageBean1.setFile_ID(jsonObject2.getInt("UA_ID")); // fileManageBean.setFile_DESCRIP(jsonObject2.getString("eventname")); // fileManageBean.setFile_Time(jsonObject2.getString("occurtime")); fileManageBean1.setFile_URL(jsonObject2.getString("UA_PATH")); fileManageBean1.setFile_Flag(jsonObject2.getString("UA_TYPE")); // fileManageBean.setFile_by1(jsonObject2.getString("sourcepeople")); fileManageBean1.setFile_Name(jsonObject2.getString("UA_OLDNAME")); fileManageBean1.setName(jsonObject2.getString("UA_NAME")); list.add(fileManageBean1); } } return list; } /** * * @param strUrl * @return * @throws IOException * @throws ClientProtocolException */ private String connServerForResult(String strUrl) throws ClientProtocolException, IOException { // HttpGet HttpGet httpRequest = new HttpGet(strUrl); String strResult = ""; // HttpClient BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 5000);// HttpClient httpClient = new DefaultHttpClient(httpParams); // HttpResponse HttpResponse httpResponse = httpClient.execute(httpRequest); if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // strResult = EntityUtils.toString(httpResponse.getEntity()); } return strResult; } /** * * * @param v */ // public void opinionxg(View v) { // finish(); // Intent intent = new Intent(getApplicationContext(), // PublicOpinionXiugaiActivity.class); // intent.putExtra("Id", Id); // intent.putExtra("eventname", ztEditText.getText().toString()); // intent.putExtra("occuraddr", fsddEditText.getText().toString()); // intent.putExtra("sourceway", lylxButton.getText().toString()); // intent.putExtra("occurtime", lysjButton.getText().toString()); // intent.putExtra("sourcepeople", lyrEditText.getText().toString()); // intent.putExtra("phone", lxdhEditText.getText().toString()); // intent.putExtra("news", xxnrEditText.getText().toString()); // // startActivity(intent); // } // // /** // * // * // * @param v // */ public void opinionxg(View v) { submit(); } /** * */ private String submit() { /** */ if (ztEditText.getText().toString().trim().length() < 1) { DialogToast(""); return ""; } else if (fsddEditText.getText().toString().trim().length() < 1) { DialogToast(""); return ""; } else if (lylxButton.getText().toString().trim().length() < 1) { DialogToast(""); return ""; } else if (years == 0 || month == 0 || day == 0) { DialogToast(""); return ""; } else if (lyrEditText.getText().toString().trim().length() < 1) { DialogToast(""); return ""; } else if (xxnrEditText.getText().toString().trim().length() < 1) { DialogToast(""); return ""; } else if (lxdhEditText.getText().toString().trim().length() >= 1) { if (isCellphone(lxdhEditText.getText().toString().trim()) == false) { DialogToast(""); return ""; } } if ("4".equals(zt1)) { DialogToast(""); return ""; } else if ("2".equals(zt1)) { DialogToast(""); return ""; } else if ("3".equals(zt1)) { DialogToast(""); return ""; } final AlertDialog.Builder builder = new AlertDialog.Builder(PublicOpinionLookActivity.this); builder.setTitle(""); builder.setIcon(R.drawable.qq_dialog_default_icon);// builder.setMessage(""); builder.setPositiveButton("", new DialogInterface.OnClickListener() { // @Override public void onClick(DialogInterface dialog, int which) { progressDialog = ProgressDialog.show(PublicOpinionLookActivity.this, "", "..."); formSubmit1(); } }); builder.setNegativeButton("", new DialogInterface.OnClickListener() { // @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); return "1"; } /** * */ private void formSubmit1() { new Thread(new Runnable() { @Override public void run() { try { Message msg_listData = new Message(); String a = HttpUtil.BASE_URL + "teventAndroid/updateInfoAndroid"; String b = "Id=" + Id + "&social.EVENTNM=" + ztEditText.getText().toString().trim() // +"&social.LATITUDE="+ShareUtil.getString(getApplicationContext(),"GPS", // "GPS_longitude", "0.0") // +"&social.LONGITUDE="+ShareUtil.getString(getApplicationContext(),"GPS", // "GPS_latitude", "0.0") + "&social.OCCURADDR=" + fsddEditText.getText().toString().trim() + "&social.SOURCEWAY=" + sourceway + "&social.OCCURTIME=" + lysj + "&social.SOURCEPEOPLE=" + lyrEditText.getText().toString().trim() + "&social.PHONE=" + lxdhEditText.getText().toString().trim() + "&social.NEWS=" + xxnrEditText.getText().toString().trim() + "&uploadFile="; // +"&attachId_="; // System.out.println(furl); try { sss = connServerForResultPost(a, b); // sss = connServerForResult(furl); } catch (Exception e) { msg_listData.what = MESSAGETYPE_02; } if (sss == null || "".equals(sss) || sss.contains("failure")) { msg_listData.what = MESSAGETYPE_02; } else { msg_listData.what = MESSAGETYPE_01; } handler2.sendMessage(msg_listData); } catch (Exception e) { if (null != e) { e.printStackTrace(); } } } }).start(); } /** */ Handler handler4 = new Handler() { public void handleMessage(Message message) { switch (message.what) { case MESSAGETYPE_01: if (null != progressDialog) { progressDialog.dismiss(); } PublicOpinionLookActivity.this.finish(); Toast.makeText(getApplicationContext(), "", 0).show(); break; case MESSAGETYPE_02: if (null != progressDialog) { progressDialog.dismiss(); } Toast.makeText(getApplicationContext(), "", 0).show(); break; default: break; } } }; /** */ Handler handler2 = new Handler() { public void handleMessage(Message message) { switch (message.what) { case MESSAGETYPE_01: // UI String[] s = Pattern.compile("@").split(sss); // fileSubmitAfterForm(s[1]); Intent intent = new Intent(getApplicationContext(), PublicOpinionlistActivity.class); intent.putExtra("Id", Id); startActivity(intent); Toast.makeText(getApplicationContext(), "", 0).show(); finish(); break; case MESSAGETYPE_02: if (null != progressDialog) { progressDialog.dismiss(); } Toast.makeText(getApplicationContext(), "", 0).show(); break; default: break; } } }; /** * */ private void fileSubmitAfterForm(String table_id) { msg_listData2 = new Message(); if (fileListg.size() == 0) { if (null != progressDialog) { progressDialog.dismiss(); // } return; } for (int i = 0; i < fileListg.size(); i++) { if (i == fileListg.size() - 1) { isprogressDialogCanClose = true; } AjaxParams params = new AjaxParams(); try { params.put("profile_picture", new File(fileListg.get(i).getFile_URL())); params.put("uatable_id", table_id); } catch (FileNotFoundException e) { if (null != e) { e.printStackTrace(); } } // FinalHttp fh = new FinalHttp(); String furl = HttpUtil.BASE_URL + "teventAndroid/uploadSocial"; fh.post(furl, params, new AjaxCallBack<String>() { @Override public void onLoading(long count, long current) { System.out.println(current + "/" + count); } @Override public void onFailure(Throwable t, int errorNo, String strMsg) { msg_listData2.what = MESSAGETYPE_02; handler4.sendMessage(msg_listData2); super.onFailure(t, errorNo, strMsg); Toast.makeText(getApplicationContext(), "", 0).show(); } @Override public void onSuccess(String t) { super.onSuccess(t); toast("" + t); if (isprogressDialogCanClose) { msg_listData2.what = MESSAGETYPE_01; handler4.sendMessage(msg_listData2); } } }); } } /** * * * @param v */ public void findpicture_onclick(View v) { String[] filetypes = new String[] { "", "", "" }; Dialog schDia = new AlertDialog.Builder(PublicOpinionLookActivity.this).setIcon(R.drawable.login_error_icon) .setTitle("").setItems(filetypes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dia, int which) { Intent intent = null; switch (which) { case 0: intent = new Intent(getApplicationContext(), UploadPictureActivity.class); startActivityForResult(intent, 2); break; case 1: intent = new Intent(getApplicationContext(), UploadVideoActivity.class); startActivityForResult(intent, 3); break; case 2: intent = new Intent(getApplicationContext(), UploadAudioActivity.class); startActivityForResult(intent, 5); break; default: break; } } }).setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dia, int which) { dia.dismiss(); } }).create(); schDia.show(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case 1: // gps if (resultCode == RESULT_OK) { SharedPreferences sp = getApplicationContext().getSharedPreferences("GPS", MODE_PRIVATE); String GPS_latitude = sp.getString("GPS_latitude", "0.0"); String GPS_longitude = sp.getString("GPS_longitude", "0.0"); // DialogToast("GPS_latitude="+GPS_latitude+"\nGPS_latitude"+GPS_longitude); Toast.makeText(getApplicationContext(), "GPS_latitude=" + GPS_latitude + "\nGPS_latitude" + GPS_longitude, 1); } break; case 2: String filePath = data.getStringExtra("filePath"); db = FinalDb.create(this); FileManageBean bean = new FileManageBean(); bean.setFile_URL(filePath); bean.setFile_Flag(FILE_TYPE_PIC_01); /** */ List<FileManageBean> temp_pictures = db.findAllByWhere(FileManageBean.class, "File_URL=\"" + filePath + "\""); toast(filePath); if ("".equals(bean.getFile_URL()) || "none".equals(bean.getFile_URL()) || null == bean.getFile_URL()) {// toast(""); return; } else if (null == temp_pictures || temp_pictures.size() == 0) {// db.save(bean); } else { DialogToast(""); } fileListg.removeAll(fileListg); List<FileManageBean> pictures_temp = db.findAll(FileManageBean.class);// List for (FileManageBean picture : pictures_temp) { if (null != picture.getFile_URL() && picture.getFile_URL().length() > 4 && (isImagePicture(picture.getFile_URL()) || isVideoFile(picture.getFile_URL()) || isAudioFile(picture.getFile_URL()))) { fileListg.add(picture); } } uploadPictureAdapter.notifyDataSetChanged(); if (null != fileListView) { UiUtil.setListViewHeightBasedOnChildren(fileListView); } break; case 3: String videoPath = data.getStringExtra("filePath"); db = FinalDb.create(this); FileManageBean videoBean = new FileManageBean(); videoBean.setFile_URL(videoPath); videoBean.setFile_Flag(FILE_TYPE_VIDEO_02); /** */ List<FileManageBean> temp_videos = db.findAllByWhere(FileManageBean.class, "File_URL=\"" + videoPath + "\""); toast(videoPath); if ("".equals(videoBean.getFile_URL()) || "none".equals(videoBean.getFile_URL()) || null == videoBean.getFile_URL()) {// toast(""); return; } else if (null == temp_videos || temp_videos.size() == 0) {// db.save(videoBean); } else { DialogToast(""); } fileListg.removeAll(fileListg); List<FileManageBean> videos_temp = db.findAll(FileManageBean.class);// List for (FileManageBean video : videos_temp) { if (null != video.getFile_URL() && video.getFile_URL().length() > 4 && (isImagePicture(video.getFile_URL()) || isVideoFile(video.getFile_URL()) || isAudioFile(video.getFile_URL()))) { fileListg.add(video); } } uploadPictureAdapter.notifyDataSetChanged(); if (null != fileListView) { UiUtil.setListViewHeightBasedOnChildren(fileListView); } break; case 4: // List db = FinalDb.create(this); fileListg.removeAll(fileListg); List<FileManageBean> files_temp = db.findAll(FileManageBean.class);// List for (FileManageBean file : files_temp) { if (null != file.getFile_URL() && file.getFile_URL().length() > 4 && (isImagePicture(file.getFile_URL()) || isVideoFile(file.getFile_URL()) || isAudioFile(file.getFile_URL()))) { fileListg.add(file); } } uploadPictureAdapter.notifyDataSetChanged(); if (null != fileListView) { UiUtil.setListViewHeightBasedOnChildren(fileListView); } break; case 5: // String audioPath = data.getStringExtra("filePath"); db = FinalDb.create(this); FileManageBean audioBean = new FileManageBean(); audioBean.setFile_URL(audioPath); audioBean.setFile_Flag(FILE_TYPE_AUDIO_03); /** */ List<FileManageBean> temp_audios = db.findAllByWhere(FileManageBean.class, "File_URL=\"" + audioPath + "\""); toast(audioPath); if (null == audioBean.getFile_URL() || "".equals(audioBean.getFile_URL()) || "none".equals(audioBean.getFile_URL())) {// toast(""); return; } else if (null == temp_audios || temp_audios.size() == 0) {// db.save(audioBean); } else { DialogToast(""); } fileListg.removeAll(fileListg); List<FileManageBean> audios_temp = db.findAll(FileManageBean.class);// List for (FileManageBean audio : audios_temp) { if (null != audio.getFile_URL() && audio.getFile_URL().length() > 4 && (isImagePicture(audio.getFile_URL()) || isVideoFile(audio.getFile_URL()) || isAudioFile(audio.getFile_URL()))) { fileListg.add(audio); } } uploadPictureAdapter.notifyDataSetChanged(); if (null != fileListView) { UiUtil.setListViewHeightBasedOnChildren(fileListView); } break; default: break; } super.onActivityResult(requestCode, resultCode, data); } /** * * * @param v */ public void opinion_more_delete(View v) { final AlertDialog.Builder builder = new AlertDialog.Builder(PublicOpinionLookActivity.this); builder.setTitle(""); builder.setIcon(R.drawable.qq_dialog_default_icon);// builder.setMessage(""); builder.setPositiveButton("", new DialogInterface.OnClickListener() { // @Override public void onClick(DialogInterface dialog, int which) { progressDialog = ProgressDialog.show(PublicOpinionLookActivity.this, "", "..."); formSubmit(); } }); builder.setNegativeButton("", new DialogInterface.OnClickListener() { // @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } /** * */ private void formSubmit() { new Thread(new Runnable() { @Override public void run() { try { Message msg_listData = new Message(); String a = HttpUtil.BASE_URL + "teventAndroid/deleteAndroid"; String b = "Id=" + Id; try { sss = connServerForResultPost(a, b); } catch (Exception e) { msg_listData.what = MESSAGETYPE_02; } if (sss == null || "".equals(sss) || sss.contains("failure")) { msg_listData.what = MESSAGETYPE_02; } else { msg_listData.what = MESSAGETYPE_01; } handler1.sendMessage(msg_listData); } catch (Exception e) { if (null != e) { e.printStackTrace(); } } } }).start(); } /** * connServerForResultPost * * @param strUrl * @return * @throws IOException * @throws ClientProtocolException */ private String connServerForResultPost(String strUrl, String entity_str) throws ClientProtocolException, IOException { String strResult = ""; URL url = new URL(strUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); byte[] entity = entity_str.getBytes(); conn.setConnectTimeout(5000); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Content-Length", String.valueOf(entity.length)); conn.getOutputStream().write(entity); if (conn.getResponseCode() == 200) { InputStream inputstream = conn.getInputStream(); StringBuffer buffer = new StringBuffer(); byte[] b = new byte[4096]; for (int n; (n = inputstream.read(b)) != -1;) { buffer.append(new String(b, 0, n)); } strResult = buffer.toString(); } return strResult; } /** */ Handler handler1 = new Handler() { public void handleMessage(Message message) { switch (message.what) { case MESSAGETYPE_01: // UI finish(); Intent intent = new Intent(getApplicationContext(), PublicOpinionlistActivity.class); startActivity(intent); Toast.makeText(getApplicationContext(), "", 0).show(); break; case MESSAGETYPE_02: if (null != progressDialog) { progressDialog.dismiss(); } Toast.makeText(getApplicationContext(), "", 0).show(); break; default: break; } } }; /** * * * @param v */ public void event_look_gps_btn(View v) { // Intent intent = new Intent(getApplicationContext(), // GPSActivity.class); // startActivityForResult(intent, 1); Intent intent = new Intent(getApplicationContext(), TDTLocation.class); startActivityForResult(intent, 1); } /** * * * @param v */ public void opinionfh(View v) { final AlertDialog.Builder builder = new AlertDialog.Builder(PublicOpinionLookActivity.this); builder.setTitle(""); builder.setIcon(R.drawable.qq_dialog_default_icon);// builder.setMessage(""); builder.setPositiveButton("", new DialogInterface.OnClickListener() { // @Override public void onClick(DialogInterface dialog, int which) { finish(); Intent intent = new Intent(getApplicationContext(), PublicOpinionlistActivity.class); startActivity(intent); } }); builder.setNegativeButton("", new DialogInterface.OnClickListener() { // @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } /** * ListView * * @author SLQ shen */ public class FileManageBeanAdapter extends BaseAdapter implements ListAdapter { /** MemberVariables */ private Context context; /** MemberVariables */ private LayoutInflater inflater; /** MemberVariables */ private List<FileManageBean1> list; public FileManageBeanAdapter(Context context, List<FileManageBean1> list) { this.context = context; inflater = LayoutInflater.from(context); this.list = list; } @Override public int getCount() { return list == null ? 0 : list.size(); } @Override public Object getItem(int item) { return this.list.get(item); } @Override public long getItemId(int itemId) { return itemId; } @Override public View getView(final int i, View view, ViewGroup viewGroup) { if (null == view) { view = inflater.inflate(R.layout.file_list_item, null); } TextView textViewTitle = (TextView) view.findViewById(R.id.file_list_item_tv); textViewTitle.setText(list.get(i).getFile_Name()); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String file_URL = list.get(i).getFile_URL(); String Name = list.get(i).getName(); // int file_ID = list.get(i).getFile_ID(); downLoadDialog(Name); } }); return view; } } /** */ private void downLoadDialog(final String Name) { // Dialog dialog = new AlertDialog.Builder(this).setTitle("") // .setMessage("") // .setPositiveButton("", new OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // getdownLoadFileURI(file_URL,file_Name,file_ID); // dialog.dismiss(); // // } // }).setNegativeButton("", new OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // dialog.dismiss(); // } // }).create(); // dialog.show(); // String p="\\"; // String[] s=Pattern.compile(p).split(Name); String urlDownloadAll = HttpUtil.BASE_URL + "upload/social/" + Name; Intent intent = new Intent(getApplicationContext(), AfnailPictureFromWebActivity.class); intent.putExtra("URI", urlDownloadAll); startActivity(intent); } /** */ private void getdownLoadFileURI(String file_URL, String file_Name, final int file_ID) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {// SD FinalHttp fh = new FinalHttp(); String newFilename = Environment.getExternalStorageDirectory() + "/" + file_Name; File temp = new File(newFilename); if (temp.exists()) { temp.delete(); } String urlDownloadAll = HttpUtil.BASE_URL + "upload/social/" + file_Name; try { // URL URL url = new URL(urlDownloadAll); // URLConnection con = url.openConnection(); // // int contentLength = con.getContentLength(); // System.out.println(" :"+contentLength); // InputStream is = con.getInputStream(); // 1K byte[] bs = new byte[1024]; // int len; // OutputStream os = new FileOutputStream(newFilename); // while ((len = is.read(bs)) != -1) { os.write(bs, 0, len); } // os.close(); is.close(); } catch (Exception e) { e.printStackTrace(); } replace(newFilename, file_ID); } else { toast("SD"); } } /** * */ private void replace(String newFilename, int file_ID) { Intent intent = new Intent(getApplicationContext(), AfnailPictureActivity.class); intent.putExtra("URI", newFilename); intent.putExtra("File_Id", file_ID); startActivityForResult(intent, 4); } /** */ private void toast(String strMsg) { Toast.makeText(getApplicationContext(), strMsg, 0).show(); } /** * * * @param errorMsg */ private void DialogToast(String errorMsg) { AlertDialog.Builder builder1 = new AlertDialog.Builder(PublicOpinionLookActivity.this); builder1.setTitle(""); builder1.setIcon(R.drawable.qq_dialog_default_icon);// builder1.setMessage("" + errorMsg); builder1.setPositiveButton("", new DialogInterface.OnClickListener() { // @Override public void onClick(DialogInterface dialog, int which) { } }); builder1.show(); } /** * 2014-4-1 "jpg","png","gif","jpeg" * * @param filePath * * @return Boolean */ private static Boolean isImagePicture(String filePath) { if (null == filePath || filePath.length() <= 3) { return false; } String[] imageFormatSet = new String[] { "jpg", "png", "gif", "peg" }; String endPath = filePath.substring(filePath.length() - 3, filePath.length()); for (String item : imageFormatSet) { if (endPath.equals(item)) { return true; } } return false; } /** * 2014-4-1 .asf .mp4 .3gp .rm .rmvb .avi * * @param filePath * * @return Boolean */ private Boolean isVideoFile(String filePath) { // String[] imageFormatSet = new String[] { "mp4","asf", "3gp", ".rm" // ,"mvb","avi"}; if (null == filePath || filePath.length() < 4) { return false; } String[] imageFormatSet = new String[] { "mp4", "3gp" }; String endPath = filePath.substring(filePath.length() - 3, filePath.length()); System.out.println(endPath); for (String item : imageFormatSet) { if (endPath.equals(item)) { return true; } } return false; } /** * 2014-4-1 .mp3 * * @param filePath * * @return Boolean */ private Boolean isAudioFile(String filePath) { // String[] imageFormatSet = new String[] { "mp3","asf", "3gp", ".rm" // ,"mvb","avi"}; if (null == filePath || filePath.length() < 4) { return false; } String[] imageFormatSet = new String[] { "3gp" }; String endPath = filePath.substring(filePath.length() - 3, filePath.length()); System.out.println(endPath); for (String item : imageFormatSet) { if (endPath.equals(item)) { return true; } } return false; } /** * * 2014-7-225:13:01 UploadPictureAdapter * * @author Mars zhang * */ public class UploadPictureAdapter extends BaseAdapter implements ListAdapter { /** MemberVariables */ private Context context; /** MemberVariables */ private LayoutInflater inflater; /** MemberVariables */ private List<FileManageBean> list; public UploadPictureAdapter(Context context, List<FileManageBean> list) { this.context = context; inflater = LayoutInflater.from(context); this.list = list; } @Override public int getCount() { return list == null ? 0 : list.size(); } @Override public Object getItem(int item) { return this.list.get(item); } @Override public long getItemId(int itemId) { return itemId; } @Override public View getView(final int i, View view, ViewGroup viewGroup) { if (null == view) { view = inflater.inflate(R.layout.file_list_item, null); } TextView textViewTitle = (TextView) view.findViewById(R.id.file_list_item_tv); String s[] = Pattern.compile("/").split(list.get(i).getFile_URL()); textViewTitle.setText("" + s[s.length - 1]); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { toast(list.get(i).getFile_URL() + "" + list.get(i).getFile_Flag()); if (FILE_TYPE_PIC_01.equals(list.get(i).getFile_Flag())) { Intent intent = new Intent(getApplicationContext(), AfnailPictureActivity.class); intent.putExtra("URI", list.get(i).getFile_URL()); intent.putExtra("File_Id", list.get(i).getFile_ID()); startActivityForResult(intent, 4); } else if (FILE_TYPE_VIDEO_02.equals(list.get(i).getFile_Flag())) { Intent intent = new Intent(getApplicationContext(), AfinalVideoActivity.class); intent.putExtra("URI", list.get(i).getFile_URL()); intent.putExtra("File_Id", list.get(i).getFile_ID()); startActivityForResult(intent, 4); } else if (FILE_TYPE_AUDIO_03.equals(list.get(i).getFile_Flag())) { Intent intent = new Intent(getApplicationContext(), AfinalAudioActivity.class); intent.putExtra("URI", list.get(i).getFile_URL()); intent.putExtra("File_Id", list.get(i).getFile_ID()); startActivityForResult(intent, 4); } } }); return view; } } /** * */ public static boolean isCellphone(String str) { Pattern pattern = Pattern.compile("^0?(13[0-9]|15[012356789]|18[01256789]|14[7])[0-9]{8}$"); Matcher matcher = pattern.matcher(str); if (matcher.matches()) { return true; } else { return false; } } }