|
package com.electric.chargingpile.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.electric.chargingpile.R;
import com.electric.chargingpile.application.MainApplication;
import com.electric.chargingpile.util.CheckMobileNum;
import com.electric.chargingpile.util.DES3;
import com.electric.chargingpile.util.NetUtil;
import com.electric.chargingpile.util.UploadUtil;
import com.electric.chargingpile.view.CustomProgressDialog;
import com.umeng.analytics.MobclickAgent;
import org.json.JSONObject;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
public class BuildInfoActivity extends Activity implements View.OnClickListener {
private EditText et_condition,et_name,et_telephone,et_park,et_cdtel,et_addressbuchong;
private ImageView iv_edit,iv_back;
private TextView tv_submit ,tv_address;
private Toast toast = null;
private String buildAddress,poi_jing,poi_wei;
private Context mContext;
private CustomProgressDialog pd_info;
private LinearLayout ll_openyes,ll_openno,ll_jiekouyes,ll_jiekouno;
private ImageView iv_openyes,iv_openno,iv_jiekouyes,iv_jiekouno;
private String open= "";
private String jiekou = "";
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
try{
JSONObject jsonObj = new JSONObject(msg.obj.toString());
String status=jsonObj.getString("rtnCode");
String info=jsonObj.getString("rtnMsg");
if (status.equals("01")) {
dismissDialog();
SharedPreferences mySharedPreferences= getSharedPreferences("userHotData",
Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.putString("name", et_name.getText().toString());
editor.putString("tel", et_telephone.getText().toString());
editor.commit();
// startActivity(new Intent(getApplication(),HotHistoryActivity.class));
Intent intent = new Intent(getApplication(),ShowBuildLocationActivity.class);
intent.putExtra("poi_jing",poi_jing);
intent.putExtra("poi_wei",poi_wei);
startActivity(intent);
//
Toast.makeText(mContext,"提交成功,我们的工作人员将会尽快与您联系",Toast.LENGTH_SHORT).show();
finish();
}else if(status.equals("03")){
dismissDialog();
Toast.makeText(BuildInfoActivity.this,"提交超时",Toast.LENGTH_SHORT).show();
}
}catch (Exception e){
e.printStackTrace();
}
break;
default:
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_build_info);
mContext=this;
initDatas();
initViews();
spUserData();
}
private void initViews(){
et_addressbuchong = (EditText) findViewById(R.id.et_addressbuchong);
//建桩条件输入框
et_condition = (EditText) findViewById(R.id.et_condition);
//地址输入框
tv_address = (TextView) findViewById(R.id.tv_address1);
tv_address.setText(buildAddress);
//姓名输入框
et_name = (EditText) findViewById(R.id.et_name);
//手机号输入框
et_telephone = (EditText) findViewById(R.id.et_telephone);
//地址可编辑图标
iv_edit = (ImageView) findViewById(R.id.iv_edit);
iv_edit.setOnClickListener(this);
//返回键
iv_back = (ImageView) findViewById(R.id.iv_back);
iv_back.setOnClickListener(this);
//提交按键
tv_submit = (TextView) findViewById(R.id.tv_submit);
tv_submit.setOnClickListener(this);
ll_openno = (LinearLayout) findViewById(R.id.ll_no);
ll_openno.setOnClickListener(this);
ll_openyes = (LinearLayout) findViewById(R.id.ll_yes);
ll_openyes.setOnClickListener(this);
ll_jiekouno = (LinearLayout) findViewById(R.id.ll_jiekou_no);
ll_jiekouno.setOnClickListener(this);
ll_jiekouyes = (LinearLayout) findViewById(R.id.ll_jiekou_yes);
ll_jiekouyes.setOnClickListener(this);
iv_openyes = (ImageView) findViewById(R.id.iv_open_yes);
iv_openno = (ImageView) findViewById(R.id.iv_open_no);
selectOpen();
iv_jiekouyes = (ImageView) findViewById(R.id.iv_jiekou_yes);
iv_jiekouno = (ImageView) findViewById(R.id.iv_jiekou_no);
selectJieKou();
et_cdtel = (EditText) findViewById(R.id.et_cdtel);
et_park = (EditText) findViewById(R.id.et_park);
}
private void initDatas(){
buildAddress = getIntent().getStringExtra("address");
poi_jing = getIntent().getStringExtra("poi_jing");
poi_wei = getIntent().getStringExtra("poi_wei");
}
private void spUserData(){
//取出用户建桩的缓存数据
SharedPreferences sharedPreferences= getSharedPreferences("userHotData",
Activity.MODE_PRIVATE);
String user_name =sharedPreferences.getString("name", "");
String tel =sharedPreferences.getString("tel", "");
et_name.setText(user_name);
et_telephone.setText(tel);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.iv_edit:
tv_address.setEnabled(true);
CharSequence text = tv_address.getText();
if (text instanceof Spannable) {
Spannable spanText = (Spannable)text;
Selection.setSelection(spanText, text.length());
}
InputMethodManager inputManager =
(InputMethodManager)tv_address.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(tv_address, 0);
break;
case R.id.iv_back:
finish();
// startActivity(new Intent(getApplication(),BuildMapActivity.class));
// overridePendingTransition(0, 0);
break;
case R.id.tv_submit:
if (checkTextSubmit()){
addPHoto("");
}
break;
case R.id.ll_yes:
open = "1";
selectOpen();
break;
case R.id.ll_no:
open = "0";
selectOpen();
break;
case R.id.ll_jiekou_yes:
jiekou = "1";
selectJieKou();
break;
case R.id.ll_jiekou_no:
jiekou = "0";
selectJieKou();
break;
}
}
//将半角字符转换为全角字符
public static String ToSBC(String input) {
char c[] = input.toCharArray();
for (int i = 0; i < c.length; i++) {
if (c[i] == ' ') {
c[i] = '\u3000';
} else if (c[i] < '\177') {
c[i] = (char) (c[i] + 65248);
}
}
return new String(c);
}
//判断输入框是否为空
private boolean checkTextSubmit() {
String address = tv_address.getText().toString().trim();
String telephone = et_telephone.getText().toString().trim();
String name = et_name.getText().toString().trim();
String condition = et_condition.getText().toString().trim();
String park = et_park.getText().toString().trim();
String cdtel = et_cdtel.getText().toString().trim();
if (TextUtils.isEmpty(address)) {
Toast.makeText(this, "请填写建桩地址", Toast.LENGTH_SHORT).show();
return false;
}
if (TextUtils.isEmpty(name)) {
Toast.makeText(this, "请填写真实姓名", Toast.LENGTH_SHORT).show();
return false;
}
if (TextUtils.isEmpty(telephone)) {
Toast.makeText(this, "请填写手机号码", Toast.LENGTH_SHORT).show();
return false;
}
if (CheckMobileNum.isMobileNum(telephone) == false) {
Toast.makeText(this, "请填写正确的电话号码", Toast.LENGTH_SHORT).show();
return false;
}
if (TextUtils.isEmpty(park)) {
Toast.makeText(this, "请填写停车位个数", Toast.LENGTH_SHORT).show();
return false;
}
if (open.equals("")){
Toast.makeText(this, "请选择场地是否对完开放", Toast.LENGTH_SHORT).show();
return false;
}
if (jiekou.equals("")){
Toast.makeText(this, "请选择场地是否有电力接口", Toast.LENGTH_SHORT).show();
return false;
}
if (TextUtils.isEmpty(cdtel)) {
Toast.makeText(this, "请填写场地方负责人电话", Toast.LENGTH_SHORT).show();
return false;
}
// if (TextUtils.isEmpty(condition)) {
// Toast.makeText(this, "请填写场地条件", Toast.LENGTH_SHORT).show();
// return false;
// }
return true;
}
private void showTextToast(String msg) {
if (toast == null) {
toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
} else {
toast.setText(msg);
}
toast.show();
}
public static String roundByScale(double v, int scale) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
if(scale == 0){
return new DecimalFormat("0").format(v);
}
String formatStr = "0.";
for(int i=0;i<scale;i++){
formatStr = formatStr + "0";
}
return new DecimalFormat(formatStr).format(v);
}
private void addPHoto(final String s) {
if (!NetUtil.CheckNetwork(this)) {
Toast.makeText(this, "请检查网络", Toast.LENGTH_SHORT).show();
return;
}
new Thread(new Runnable() {
@Override
public void run() {
long appTime1 = System.currentTimeMillis()/1000;
Log.i("appTime(long)---", appTime1 + "");
long updatetime = appTime1 - MainMapActivity.cha -1;
Log.i("updatetime(long)---", updatetime+"");
Log.i("cha---", MainMapActivity.cha+"");
String token = String.valueOf(updatetime);
Log.i("token---", token);
try {
Map<String, String> par = new HashMap<String, String>();
par.put("file", s);
par.put("filename","androidapp.jpg");
par.put("zhan_address",tv_address.getText().toString()+et_addressbuchong.getText().toString());
par.put("user_name", et_name.getText().toString());
par.put("user_id", MainApplication.userId);
String jing = roundByScale(Double.parseDouble(poi_jing),16);;
String wei = roundByScale(Double.parseDouble(poi_wei),16);
par.put("poi_jing", jing);
par.put("poi_wei", wei);
// Log.e("poi_jing",jing);
// Log.e("poi_wei",wei);
par.put("telephone", et_telephone.getText().toString());
par.put("suit_car", "");
par.put("parking_num", et_park.getText().toString());
par.put("is_siteopen", open);
par.put("has_socket", jiekou);
par.put("site_phone", et_cdtel.getText().toString());
par.put("note", et_condition.getText().toString());
par.put("token", DES3.encode(token));
//如果是热点标注部分图片ishot为1
Log.i("++++++++@","user_id:"+MainApplication.userId);
String u = UploadUtil.post(MainApplication.url+"/zhannew/basic/web/index.php/zhuanrdbz/add",
par, null);
Message msg = new Message();
msg.obj = u;
msg.what=1;
handler.sendMessage(msg);
Log.e("url", u);
} catch (Exception e) {
e.printStackTrace();
Message msg = new Message();
msg.what=3;
handler.sendMessage(msg);
}
}
}).start();
}
public void createDialog() {
if (pd_info == null) {
pd_info = CustomProgressDialog.createDialog(mContext);
pd_info.setMessage(mContext.getResources().getString(
R.string.version_updating));
pd_info.show();
}
}
public void dismissDialog() {
if (pd_info != null) {
pd_info.dismiss();
pd_info = null;
}
}
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}
private void selectOpen(){
if (open.equals("")){
iv_openyes.setImageResource(R.drawable.icon_no);
iv_openno.setImageResource(R.drawable.icon_no);
}else if (open.equals("1")){
iv_openyes.setImageResource(R.drawable.icon_yes);
iv_openno.setImageResource(R.drawable.icon_no);
}else if (open.equals("0")){
iv_openyes.setImageResource(R.drawable.icon_no);
iv_openno.setImageResource(R.drawable.icon_yes);
}
}
private void selectJieKou(){
if (jiekou.equals("")){
iv_jiekouyes.setImageResource(R.drawable.icon_no);
iv_jiekouno.setImageResource(R.drawable.icon_no);
}else if (jiekou.equals("1")){
iv_jiekouyes.setImageResource(R.drawable.icon_yes);
iv_jiekouno.setImageResource(R.drawable.icon_no);
}else if (jiekou.equals("0")){
iv_jiekouyes.setImageResource(R.drawable.icon_no);
iv_jiekouno.setImageResource(R.drawable.icon_yes);
}
}
}
|