|
package com.electric.chargingpile.activity;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.electric.chargingpile.R;
import com.electric.chargingpile.application.MainApplication;
import com.electric.chargingpile.data.Pic;
import com.electric.chargingpile.data.PrivateZhuang;
import com.electric.chargingpile.data.Zhan;
import com.electric.chargingpile.util.BarColorUtil;
import com.electric.chargingpile.util.Bimp;
import com.electric.chargingpile.util.CheckMobileNum;
import com.electric.chargingpile.util.FileUtils;
import com.electric.chargingpile.util.ImageItem;
import com.electric.chargingpile.util.ImageUtils;
import com.electric.chargingpile.util.JsonUtils;
import com.electric.chargingpile.util.OkHttpUtil;
import com.electric.chargingpile.util.PublicWay;
import com.electric.chargingpile.util.Res;
import com.electric.chargingpile.util.ScreenUtils;
import com.electric.chargingpile.util.ToastUtil;
import com.electric.chargingpile.util.UploadUtil;
import com.electric.chargingpile.view.CustomProgressDialog;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.GlideEngine;
import com.zhihu.matisse.internal.entity.CaptureStrategy;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import me.iwf.photopicker.PhotoPicker;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
public class PrivateZhuangInfoActivity extends Activity implements View.OnClickListener, EasyPermissions.PermissionCallbacks {
private static final String TAG = "PrivateZhuangInfoActivi";
private static final int PIC_NUM = 3;
private ImageView ivBack, ivType;
Bitmap bm = null;
private TextView shareList, tvO, tvT, tvTh, tvF, tvFi, zhuangType, costWay, shareNext;
private TimePickerDialog tpd_open = null;
private TimePickerDialog tpd_close = null;
private String camePath;//拍照路径
private static final String PHOTO_FILE_NAME = "android.jpg";
private static final String PHOTO_FILE_PATH = getPath(Environment.getExternalStorageDirectory() + "/" + "cdz");
private File tempFile;
private static final int PHOTO_REQUEST_CAMERA = 1;
private static final int PHOTO_REQUEST_GALLERY = 2;
private static final int PHOTO_REQUEST_CUT = 3;
private ImageView inBtn, outBtn;
private String jing, wei;
private PrivateZhuang privateZhuang;
public static final int REQUSET = 11;
public static boolean isFirstLoc = true;
private Switch sh_cost;
private Button submitLocation;
private ImageView test, iv1, iv2, iv3, iv4, iv_back;
private LinearLayout ll_tvOne, ll_tvTwo, ll_tvThree, ll_tvFour, ll_buchong, ll_type, ll_costWay;
private List<Zhan> list = new ArrayList<Zhan>();
private Zhan zhan;
ToggleButton carType;
private String suit_car2 = "国标";
private static boolean isGetData = false;
private static String location;
private static String city;
private static String district;
private EditText et_telephone;
private TextView et_share_address;
private Button confirmButton;
private Button cancleButton;
private PopupWindow popupWindow;
private View popupWindowView;
private Bitmap bitmap;
Context mContext;
TextView tv;
private Toast toast = null;
private String park = "1";
private ImageView ib_loaction, ib_add, ib_jian;
private RelativeLayout tv_notice;
private EditText zhanName, fastNum, slowNum, parkCost, chargeCost, et_serviceCost, et_remark;
private CustomProgressDialog pd_info;
private RadioButton rb_guo, rb_te, rb_shang, rb_xia;
private RadioGroup rg_claimtype, rg_park;
public static Bitmap bimap;
private GridView noScrollgridview;
private GridAdapter adapter;
private View parentView;
private PopupWindow pop = null;
private LinearLayout ll_popup;
private TextView open_time, close_time, share_list;
private RelativeLayout rl_address;
private String tag, id, zhan_name, zhan_address, poi_jing, poi_wei, fast_num, slow_num,
stop_cost, charge_cost, charge_cost_way, other_cost, telephone, remarks, park_location,
work_open, work_close, suit_car, pic_counts, pic;
private ProgressDialog insertDialog;
private static final int RC_ALBUM_PERM = 123;
public static final int REQUEST_CODE_CHOOSE = 341;
private Handler handler = new Handler() {
// 主线程通过这个方法处理消息
@Override
public void handleMessage(final Message msg) {
switch (msg.what) {
case 1:
Bundle bundle = msg.getData();
String id = bundle.getString("id");
Bitmap bitmap = (Bitmap) msg.obj;
Log.e("bitmap", bitmap + "");
Log.e("bitmap_id", id + "");
ImageItem mImageItem = new ImageItem();
mImageItem.setBitmap(bitmap);
try {
Bimp.tempSelectBitmap.add(Integer.parseInt(id), mImageItem);
} catch (Exception e) {
e.printStackTrace();
}
adapter.update();
break;
case 2:
Toast.makeText(PrivateZhuangInfoActivity.this, "提交信息成功,感谢您的分享", Toast.LENGTH_SHORT).show();
dismissDialog();
startActivity(new Intent(getApplicationContext(), PrivateZhaungListActivity.class));
finish();
break;
case 3:
dismissDialog();
Toast.makeText(PrivateZhuangInfoActivity.this, "服务器处理错误", Toast.LENGTH_SHORT).show();
break;
case 5:
break;
case 6:
try {
Log.e("!!!", msg.toString());
JSONObject jsonObject = new JSONObject(msg.obj.toString());
Log.e("!!!!!!", msg.obj.toString());
String rtnCode = jsonObject.getString("rtnCode");
String rtnMsg = jsonObject.getString("rtnMsg");
if (rtnCode.equals("01")) {
dismissDialog();
String s = "“雷锋同志”您提交的信息已成功";
String s1 = "非常感谢您的支持,我们将尽快审核添加到APP中";
new com.electric.chargingpile.view.AlertDialog(PrivateZhuangInfoActivity.this).builder()
.setMsg(s + "\n" + s1)
.setNegativeButton("确认关闭", new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(PrivateZhuangInfoActivity.this, PrivateZhaungListActivity.class));
finish();
}
}).show();
} else {
dismissDialog();
Toast.makeText(PrivateZhuangInfoActivity.this, "提交失败", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
break;
default:
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initDate();
tempFile = getFile(PHOTO_FILE_PATH + "/" + PHOTO_FILE_NAME);
Res.init(this);
bimap = BitmapFactory.decodeResource(
getResources(),
R.drawable.addpic65);
PublicWay.activityList.add(this);
setContentView(R.layout.activity_private_zhuang_info);
BarColorUtil.initStatusBarColor(PrivateZhuangInfoActivity.this);
list = new ArrayList<>();
mContext = this;
Init();
initView();
}
private void showTextToast(String msg) {
if (toast == null) {
toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
} else {
toast.setText(msg);
}
toast.show();
}
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;
}
}
public void Init() {
pop = new PopupWindow(PrivateZhuangInfoActivity.this);
View view = getLayoutInflater().inflate(R.layout.item_popupwindows, null);
ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup);
pop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
pop.setBackgroundDrawable(new BitmapDrawable());
pop.setFocusable(true);
pop.setOutsideTouchable(true);
pop.setContentView(view);
final RelativeLayout parent = (RelativeLayout) view.findViewById(R.id.parent);
Button bt1 = (Button) view
.findViewById(R.id.item_popupwindows_camera);
Button bt2 = (Button) view
.findViewById(R.id.item_popupwindows_Photo);
Button bt3 = (Button) view
.findViewById(R.id.item_popupwindows_cancel);
parent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pop.dismiss();
ll_popup.clearAnimation();
}
});
bt1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
pop.dismiss();
ll_popup.clearAnimation();
if (MainScanActivity.isCameraUseable()) {
photo();
} else {
ToastUtil.showToast(getApplicationContext(), "您当前关闭了调用摄像头权限", Toast.LENGTH_SHORT);
}
}
});
bt2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(PrivateZhuangInfoActivity.this,
AlbumActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.activity_translate_in, R.anim.activity_translate_out);
pop.dismiss();
ll_popup.clearAnimation();
}
});
bt3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
pop.dismiss();
ll_popup.clearAnimation();
}
});
noScrollgridview = (GridView) findViewById(R.id.noScrollgridview);
noScrollgridview.setSelector(new ColorDrawable(Color.TRANSPARENT));
adapter = new GridAdapter(this);
adapter.update();
noScrollgridview.setAdapter(adapter);
noScrollgridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
if (arg2 == Bimp.tempSelectBitmap.size()) {
permissionTask();
} else {
Intent intent = new Intent(PrivateZhuangInfoActivity.this,
GalleryPrivateActivity.class);
intent.putExtra("position", "1");
intent.putExtra("ID", arg2);
startActivity(intent);
}
}
});
}
/**
* 调用图库选择
*/
private void callGallery() {
Matisse.from(PrivateZhuangInfoActivity.this)
.choose(MimeType.of(MimeType.JPEG, MimeType.PNG, MimeType.GIF))
.countable(true)
.maxSelectable(PIC_NUM - Bimp.tempSelectBitmap.size())
.capture(true)
.captureStrategy(new CaptureStrategy(true, "com.electric.chargingpile.provider"))
.imageEngine(new GlideEngine())
.forResult(REQUEST_CODE_CHOOSE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (data != null) {
if (requestCode == 1) {
//处理调用系统图库
} else if (requestCode == REQUEST_CODE_CHOOSE) {
//异步方式插入图片
insertImagesSync(data);
} else if (requestCode == REQUSET) {
poi_jing = data.getStringExtra("poi_jing");
Log.e("返回==poi_jing", poi_jing);
poi_wei = data.getStringExtra("poi_wei");
Log.e("返回==poi_wei", poi_wei);
et_share_address.setText(data.getStringExtra("address"));
}
}
}
}
/**
* 异步方式插入图片
*
* @param data
*/
private void insertImagesSync(final Intent data) {
insertDialog.show();
Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> subscriber) {
try {
List<Uri> uriList = Matisse.obtainResult(data);
for (Uri uri: uriList) {
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
File file = FileUtils.from(PrivateZhuangInfoActivity.this, uri);
bitmap = FileUtils.rotateIfRequired(file, bitmap);
bitmap = imageZoom(bitmap);
ImageItem takePhoto = new ImageItem();
takePhoto.setBitmap(bitmap);
Bimp.tempSelectBitmap.add(takePhoto);
subscriber.onNext("");
}
subscriber.onComplete();
} catch (Exception e) {
e.printStackTrace();
subscriber.onError(e);
}
}
})
.subscribeOn(Schedulers.io())//生产事件在io
.observeOn(AndroidSchedulers.mainThread())//消费事件在UI线程
.subscribe(new Observer<String>() {
@Override
public void onComplete() {
insertDialog.dismiss();
adapter.update();
}
@Override
public void onError(Throwable e) {
insertDialog.dismiss();
Log.e(TAG, "onError: " + "图片插入失败:" + e.getMessage());
ToastUtil.showToast(getApplicationContext(), "图片插入失败", Toast.LENGTH_SHORT);
}
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(String imagePath) {
}
});
}
private void initView() {
if (tag.equals("edit")) {
TextView titleView = findViewById(R.id.textview);
titleView.setText("编辑个人共享桩");
}
insertDialog = new ProgressDialog(this);
insertDialog.setMessage("正在插入图片...");
insertDialog.setCanceledOnTouchOutside(false);
et_telephone = (EditText) findViewById(R.id.et_telephone);
et_serviceCost = (EditText) findViewById(R.id.et_serviceCost);
inBtn = (ImageView) findViewById(R.id.zoomin1);
outBtn = (ImageView) findViewById(R.id.zoomout1);
inBtn.setOnClickListener(this);
outBtn.setOnClickListener(this);
rl_address = (RelativeLayout) findViewById(R.id.ll_address);
rl_address.setOnClickListener(this);
shareNext = (TextView) findViewById(R.id.share_next);
shareNext.setOnClickListener(this);
et_serviceCost = (EditText) findViewById(R.id.et_serviceCost);
et_remark = (EditText) findViewById(R.id.et_remarkclaim);
et_remark = (EditText) findViewById(R.id.et_remarkclaim);
zhanName = (EditText) findViewById(R.id.et_zhanName);
fastNum = (EditText) findViewById(R.id.et_fastNum);
slowNum = (EditText) findViewById(R.id.et_slowNum);
parkCost = (EditText) findViewById(R.id.et_parkCost);
chargeCost = (EditText) findViewById(R.id.et_chargeCost);
et_serviceCost = (EditText) findViewById(R.id.et_serviceCost);
costWay = (TextView) findViewById(R.id.tv_costtype);
costWay.setOnClickListener(this);
ib_loaction = (ImageView) findViewById(R.id.ib_location);
ib_loaction.setOnClickListener(this);
tv_notice = (RelativeLayout) findViewById(R.id.tv_notice);
tv_notice.setOnClickListener(this);
rg_claimtype = (RadioGroup) findViewById(R.id.rg_claimtype);
rg_claimtype.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == rb_guo.getId()) {
suit_car2 = "国标";
}
if (checkedId == rb_te.getId()) {
suit_car2 = "特斯拉";
}
}
});
rg_park = (RadioGroup) findViewById(R.id.rg_park);
rg_park.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == rb_shang.getId()) {
park = "1";
}
if (checkedId == rb_xia.getId()) {
park = "0";
}
}
});
rb_guo = (RadioButton) findViewById(R.id.rb_guo);
rb_guo.setOnClickListener(this);
rb_te = (RadioButton) findViewById(R.id.rb_te);
rb_te.setOnClickListener(this);
rb_shang = (RadioButton) findViewById(R.id.rb_shang);
rb_shang.setOnClickListener(this);
rb_xia = (RadioButton) findViewById(R.id.rb_xia);
rb_xia.setOnClickListener(this);
ivBack = (ImageView) findViewById(R.id.iv_back);
ivBack.setOnClickListener(this);
open_time = (TextView) findViewById(R.id.tv_prefect_start_time);
open_time.setOnClickListener(this);
close_time = (TextView) findViewById(R.id.tv_ferfect_time);
close_time.setOnClickListener(this);
et_share_address = (TextView) findViewById(R.id.et_share_address);
zhuangType = (TextView) findViewById(R.id.tv_zhuangType);
iv_back = (ImageView) findViewById(R.id.iv_back);
iv_back.setOnClickListener(this);
open_time = (TextView) findViewById(R.id.tv_prefect_start_time);
open_time.setOnClickListener(this);
close_time = (TextView) findViewById(R.id.tv_ferfect_time);
close_time.setOnClickListener(this);
if (tag.equals("edit")) {
fastNum.setText(fast_num);
slowNum.setText(slow_num);
et_telephone.setText(telephone);
zhanName.setText(zhan_name);
et_share_address.setText(zhan_address);
et_remark.setText(remarks);
open_time.setText(work_open);
close_time.setText(work_close);
chargeCost.setText(charge_cost);
parkCost.setText(stop_cost);
et_serviceCost.setText(other_cost);
if (suit_car.equals("国标")) {
rb_guo.setBackgroundResource(R.drawable.icon_guoselected1105);
rb_te.setBackgroundResource(R.drawable.icon_tenormal1105);
} else {
rb_guo.setBackgroundResource(R.drawable.icon_guonormal1105);
rb_te.setBackgroundResource(R.drawable.icon_teselected1105);
}
suit_car2 = suit_car;
costWay.setText(charge_cost_way);
if (park_location.equals("1")) {
rb_shang.setBackgroundResource(R.drawable.icon_shangselected1105);
rb_xia.setBackgroundResource(R.drawable.icon_xianormal1105);
} else {
rb_shang.setBackgroundResource(R.drawable.icon_shangnormal1105);
rb_xia.setBackgroundResource(R.drawable.icon_xiaselected1105);
}
park = park_location;
new Thread(new Runnable() {
@Override
public void run() {
List<Pic> listPic = JsonUtils.parseToObjectList(pic, Pic.class);
Log.e("pic===size", listPic.size() + "");
for (int i = 0; i < listPic.size(); i++) {
try {
bitmap = Bimp.revitionImageSize(MainApplication.url + "/zhannew/uploadfile/" + listPic.get(i).getUrl(), 300);
if (bitmap != null) {
Message mes = new Message();
mes.obj = bitmap;
Log.e("bitmap===", bitmap + "");
mes.what = 1;
Bundle bundle = new Bundle();
bundle.putString("id", String.valueOf(i));
mes.setData(bundle);
handler.sendMessage(mes);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}).start();
}
}
private void initDate() {
tag = getIntent().getStringExtra("tag");
if (tag.equals("edit")) {
fast_num = getIntent().getStringExtra("fast_num");
slow_num = getIntent().getStringExtra("slow_num");
telephone = getIntent().getStringExtra("telephone");
zhan_name = getIntent().getStringExtra("zhan_name");
zhan_address = getIntent().getStringExtra("zhan_address");
remarks = getIntent().getStringExtra("remarks");
work_open = getIntent().getStringExtra("work_open");
work_close = getIntent().getStringExtra("work_close");
charge_cost = getIntent().getStringExtra("charge_cost");
stop_cost = getIntent().getStringExtra("stop_cost");
other_cost = getIntent().getStringExtra("other_cost");
suit_car = getIntent().getStringExtra("suit_car");
charge_cost_way = getIntent().getStringExtra("charge_cost_way");
park_location = getIntent().getStringExtra("park_location");
id = getIntent().getStringExtra("id");
poi_jing = getIntent().getStringExtra("poi_jing");
poi_wei = getIntent().getStringExtra("poi_wei");
pic = getIntent().getStringExtra("pic");
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.ll_address:
Intent intent = new Intent(PrivateZhuangInfoActivity.this, PrivateZhuangMapActivity.class);
if (tag.equals("edit")) {
intent.putExtra("tag", "edit");
intent.putExtra("poi_jing", poi_jing);
Log.e("poi_jing===", poi_jing);
intent.putExtra("poi_wei", poi_wei);
Log.e("poi_wei===", poi_wei);
intent.putExtra("zhan_address", zhan_address);
} else {
intent.putExtra("tag", "add");
}
intent.putExtra("zhan_address", zhan_address);
startActivityForResult(intent, REQUSET);
break;
case R.id.rb_guo:
rb_guo.setBackgroundResource(R.drawable.icon_guoselected1105);
rb_te.setBackgroundResource(R.drawable.icon_tenormal1105);
break;
case R.id.rb_te:
rb_guo.setBackgroundResource(R.drawable.icon_guonormal1105);
rb_te.setBackgroundResource(R.drawable.icon_teselected1105);
break;
case R.id.rb_shang:
rb_shang.setBackgroundResource(R.drawable.icon_shangselected1105);
rb_xia.setBackgroundResource(R.drawable.icon_xianormal1105);
break;
case R.id.rb_xia:
rb_shang.setBackgroundResource(R.drawable.icon_shangnormal1105);
rb_xia.setBackgroundResource(R.drawable.icon_xiaselected1105);
break;
case R.id.tv_notice:
tv_notice.setVisibility(View.GONE);
break;
case R.id.tv_costtype:
LayoutInflater inflater1 = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
popupWindowView = inflater1.inflate(R.layout.popupwindow_privatecostway, null);
popupWindow = new PopupWindow(popupWindowView,
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT,
true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
// 设置PopupWindow的弹出和消失效果
popupWindow.setAnimationStyle(R.style.popupAnimation);
cancleButton = (Button) popupWindowView
.findViewById(R.id.cancleButton);
cancleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
}
});
TextView tvO1 = (TextView) popupWindowView.findViewById(R.id.tvOne);
tvO1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
costWay.setText("微信支付");
popupWindow.dismiss();
}
});
TextView tvT2 = (TextView) popupWindowView.findViewById(R.id.tvTwo);
tvT2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
costWay.setText("支付宝支付");
popupWindow.dismiss();
}
});
TextView tvTh3 = (TextView) popupWindowView.findViewById(R.id.tvThree);
tvTh3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
costWay.setText("现金");
popupWindow.dismiss();
}
});
popupWindow.showAtLocation(cancleButton, Gravity.CENTER, 0, 0);
break;
case R.id.share_next:
if (et_share_address.getText().toString().equals("")) {
Toast.makeText(this, "请选择充电站地址", Toast.LENGTH_SHORT).show();
} else if (zhanName.getText().toString().equals("")) {
Toast.makeText(this, "请填写名称", Toast.LENGTH_SHORT).show();
} else if (fastNum.getText().toString().equals("") && slowNum.getText().toString().equals("")) {
Toast.makeText(this, "请填写桩数量", Toast.LENGTH_SHORT).show();
} else if (et_telephone.getText().toString().equals("")) {
Toast.makeText(this, "请填写联系方式", Toast.LENGTH_SHORT).show();
} else if (CheckMobileNum.isMobileNum(et_telephone.getText().toString()) == false) {
Toast.makeText(this, "请填写正确的联系方式", Toast.LENGTH_SHORT).show();
} else if (chargeCost.getText().toString().equals("")) {
Toast.makeText(this, "请填写充电费", Toast.LENGTH_SHORT).show();
} else if (parkCost.getText().toString().equals("")) {
Toast.makeText(this, "请填写停车费", Toast.LENGTH_SHORT).show();
} else if (et_serviceCost.getText().toString().equals("")) {
Toast.makeText(this, "请填写服务费", Toast.LENGTH_SHORT).show();
} else if (costWay.getText().toString().equals("")) {
Toast.makeText(this, "请选择支付方式", Toast.LENGTH_SHORT).show();
} else if (Bimp.tempSelectBitmap.size() == 0) {
Toast.makeText(this, "请上传图片", Toast.LENGTH_SHORT).show();
} else {
if (fastNum.getText().toString().equals("") && !slowNum.getText().toString().equals("")) {
fastNum.setText("0");
}
if (!fastNum.getText().toString().equals("") && slowNum.getText().toString().equals("")) {
slowNum.setText("0");
}
if (open_time.getText().toString().equals("")) {
open_time.setText("00:00");
}
if (close_time.getText().toString().equals("")) {
close_time.setText("24:00");
}
createDialog();
new Thread(new Runnable() {
@Override
public void run() {
try {
shite("");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
break;
case R.id.tv_prefect_start_time:
if (tpd_open == null) {
TimePickerDialog.OnTimeSetListener otsl = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
open_time.setText(((hourOfDay < 10 ? 0 + "" + hourOfDay : hourOfDay) + ":" + (minute < 10 ? 0 + "" + minute : minute)).toString());
tpd_open.dismiss();
}
};
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
tpd_open = new TimePickerDialog(this, otsl, hourOfDay, minute, true);
}
tpd_open.show();
break;
case R.id.tv_ferfect_time:
if (tpd_close == null) {
TimePickerDialog.OnTimeSetListener otsl = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
close_time.setText(((hourOfDay < 10 ? 0 + "" + hourOfDay : hourOfDay) + ":" + (minute < 10 ? 0 + "" + minute : minute)).toString());
tpd_close.dismiss();
}
};
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
tpd_close = new TimePickerDialog(this, otsl, hourOfDay, minute, true);
}
tpd_close.show();
break;
case R.id.iv_back:
finish();
break;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
}
return false;
}
private void submitShowMap(String sms) {
Request request = new Request.Builder().url(sms).build();
Response response = null;
try {
if (request == null) {
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
return;
}
response = OkHttpUtil.execute(request);
if (response.code() == 200) {
String json = "";
try {
json = response.body().string();
Message msg = new Message();
msg.obj = json;
msg.what = 5;
handler.sendMessage(msg);
Log.e("url", json);
} catch (Exception e) {
e.printStackTrace();
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
}
}
} catch (Exception e) {
e.printStackTrace();
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
}
}
private String bitmapToBase64(Bitmap bitmap) {
String result = null;
ByteArrayOutputStream baos = null;
try {
if (bitmap != null) {
baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
baos.flush();
baos.close();
byte[] bitmapBytes = baos.toByteArray();
result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (baos != null) {
baos.flush();
baos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
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);
}
public void shite(String s) throws Exception {
Map<String, String> par = new HashMap<String, String>();
String file;
long appTime1 = System.currentTimeMillis() / 1000;
Log.i("appTime(long)---", appTime1 + "");
long updatetime = appTime1 - MainMapActivity.cha;
Log.i("updatetime(long)---", updatetime + "");
Log.i("cha---", MainMapActivity.cha + "");
String token = String.valueOf(updatetime);
Log.i("token---", token);
for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) {
try {
bm = imageZoom(Bimp.tempSelectBitmap.get(i).getBitmap());
file = bitmapToBase64(bm);
par.put("file" + (i + 1), file);
Log.i("file--------" + (i + 1), file);
par.put("filename" + (i + 1), "androidapp.jpg");
} catch (Exception e) {
e.printStackTrace();
}
}
// String fast = fastNum
par.put("zhan_name", zhanName.getText().toString());
par.put("zhan_address", et_share_address.getText().toString());
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("suit_car", suit_car2);
par.put("charge_cost", chargeCost.getText().toString());
par.put("charge_cost_way", costWay.getText().toString());
par.put("stop_cost", parkCost.getText().toString());
par.put("telephone", et_telephone.getText().toString());
par.put("other_cost", et_serviceCost.getText().toString());
par.put("park_location", park);
par.put("work_open", open_time.getText().toString());
par.put("work_close", close_time.getText().toString());
par.put("user_id", MainApplication.userId);
par.put("remarks", et_remark.getText().toString());
par.put("fast_num", fastNum.getText().toString());
par.put("slow_num", slowNum.getText().toString());
if (tag.equals("edit")) {
par.put("where", id);
par.put("picid", "a");
}
try {
String u = UploadUtil.post(
MainApplication.url + "/zhannew/basic/web/index.php/applist/createpile",
par, null);
System.err.println(u);
// submit(u);
Message msg = new Message();
msg.obj = u;
msg.what = 2;
handler.sendMessage(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
}
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
}
@AfterPermissionGranted(RC_ALBUM_PERM)
public void permissionTask() {
if (isPermissionOK()) {
callGallery();
} else {
EasyPermissions.requestPermissions(
this, "充电桩想要获取您的图片读取权限,是否允许?",
RC_ALBUM_PERM,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
);
}
}
private boolean isPermissionOK() {
return EasyPermissions.hasPermissions(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
);
}
@SuppressLint("HandlerLeak")
public class GridAdapter extends BaseAdapter {
private LayoutInflater inflater;
private int selectedPosition = -1;
private boolean shape;
public boolean isShape() {
return shape;
}
public void setShape(boolean shape) {
this.shape = shape;
}
public GridAdapter(Context context) {
inflater = LayoutInflater.from(context);
}
public void update() {
loading();
}
public int getCount() {
if (Bimp.tempSelectBitmap.size() == 3) {
return 3;
}
return (Bimp.tempSelectBitmap.size() + 1);
}
public Object getItem(int arg0) {
return null;
}
public long getItemId(int arg0) {
return 0;
}
public void setSelectedPosition(int position) {
selectedPosition = position;
}
public int getSelectedPosition() {
return selectedPosition;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_published_grida,
parent, false);
holder = new ViewHolder();
holder.image = (ImageView) convertView
.findViewById(R.id.item_grida_image);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (position == Bimp.tempSelectBitmap.size()) {
holder.image.setImageBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.icon_defaultadd1105));
if (position == 3) {
holder.image.setVisibility(View.GONE);
}
} else {
holder.image.setImageBitmap(Bimp.tempSelectBitmap.get(position).getBitmap());
}
return convertView;
}
public class ViewHolder {
public ImageView image;
}
Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
adapter.notifyDataSetChanged();
break;
}
super.handleMessage(msg);
}
};
public void loading() {
new Thread(new Runnable() {
public void run() {
while (true) {
if (Bimp.max == Bimp.tempSelectBitmap.size()) {
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
break;
} else {
Bimp.max += 1;
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
}
}
}
}).start();
}
}
public String getString(String s) {
String path = null;
if (s == null)
return "";
for (int i = s.length() - 1; i > 0; i++) {
s.charAt(i);
}
return path;
}
protected void onRestart() {
adapter.update();
super.onRestart();
}
private static final int TAKE_PICTURE = 0x000001;
public void photo() {
if (hasSdcard()) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//���������
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
startActivityForResult(intent, PHOTO_REQUEST_CAMERA);
}
}
@Override
protected void onDestroy() {
Bimp.tempSelectBitmap.clear();
Bimp.max = 0;
super.onDestroy();
}
private Bitmap compressBmpFromBmp(Bitmap image) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int options = 100;
image.compress(Bitmap.CompressFormat.JPEG, 60, baos);
while (baos.toByteArray().length / 1024 > 200) {
baos.reset();
options -= 10;
image.compress(Bitmap.CompressFormat.JPEG, options, baos);
}
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);
return bitmap;
}
private void crop(Uri uri, Uri cutImgUri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("outputFormat", "JPEG");
intent.putExtra("noFaceDetection", true);// ȡ������ʶ��
intent.putExtra("return-data", false);// true:������uri��false������uri
intent.putExtra(MediaStore.EXTRA_OUTPUT, cutImgUri);//д���ȡ��ͼƬ
startActivityForResult(intent, PHOTO_REQUEST_CUT);
}
private boolean hasSdcard() {
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
private static String getPath(String path) {
File f = new File(path);
if (!f.exists()) {
f.mkdirs();
}
return f.getAbsolutePath();
}
private File getFile(String path) {
File f = new File(path);
if (!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return f;
}
public Bitmap decodeUriAsBitmap(Uri uri) {
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri));
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
return bitmap;
}
private Bitmap comp(Bitmap image) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 30, baos);
if (baos.toByteArray().length / 1024 > 1024) {//判断如果图片大于1M,进行压缩避免在生成图片(BitmapFactory.decodeStream)时溢出
baos.reset();//重置baos即清空baos
image.compress(Bitmap.CompressFormat.JPEG, 50, baos);//这里压缩50%,把压缩后的数据存放到baos中
}
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
BitmapFactory.Options newOpts = new BitmapFactory.Options();
//开始读入图片,此时把options.inJustDecodeBounds 设回true了
newOpts.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, newOpts);
newOpts.inJustDecodeBounds = false;
int w = newOpts.outWidth;
int h = newOpts.outHeight;
//现在主流手机比较多是800*480分辨率,所以高和宽我们设置为
float hh = 800f;//这里设置高度为800f
float ww = 480f;//这里设置宽度为480f
//缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
int be = 1;//be=1表示不缩放
if (w > h && w > ww) {//如果宽度大的话根据宽度固定大小缩放
be = (int) (newOpts.outWidth / ww);
} else if (w < h && h > hh) {//如果高度高的话根据宽度固定大小缩放
be = (int) (newOpts.outHeight / hh);
}
if (be <= 0)
be = 1;
newOpts.inSampleSize = be;//设置缩放比例
newOpts.inPreferredConfig = Bitmap.Config.RGB_565;//降低图片从ARGB888到RGB565
//重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了
isBm = new ByteArrayInputStream(baos.toByteArray());
bitmap = BitmapFactory.decodeStream(isBm, null, newOpts);
return compressImage(bitmap);//压缩好比例大小后再进行质量压缩
}
private Bitmap compressImage(Bitmap image) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 80, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
int options = 70;
while (baos.toByteArray().length / 1024 > 300) { //循环判断如果压缩后图片是否大于100kb,大于继续压缩
baos.reset();//重置baos即清空baos
options -= 10;//每次都减少10
image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中
}
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//把压缩后的数据baos存放到ByteArrayInputStream中
Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//把ByteArrayInputStream数据生成图片
return bitmap;
}
private Bitmap imageZoom(Bitmap bm) {
// 图片允许最大空间 单位:KB
double maxSize = 200.00;
// 将bitmap放至数组中,意在bitmap的大小(与实际读取的原文件要大)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
// 将字节换成KB
double mid = b.length / 1024;
// 判断bitmap占用空间是否大于允许最大空间 如果大于则压缩 小于则不压缩
if (mid > maxSize) {
// 获取bitmap大小 是允许最大大小的多少倍
double i = mid / maxSize;
// 开始压缩 此处用到平方根 将宽带和高度压缩掉对应的平方根倍
// (1.保持刻度和高度和原bitmap比率一致,压缩后也达到了最大大小占用空间的大小)
bm = zoomImage(bm, bm.getWidth() / Math.sqrt(i), bm.getHeight()
/ Math.sqrt(i));
}
return bm;
}
public Bitmap zoomImage(Bitmap bgimage, double newWidth, double newHeight) {
// 获取这个图片的宽和高
float width = bgimage.getWidth();
float height = bgimage.getHeight();
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 计算宽高缩放率
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width,
(int) height, matrix, true);
return bitmap;
}
@Override
protected void onResume() {
super.onResume();
}
public Bitmap getHttpBitmap(String url) {
Bitmap bitmap = null;
try {
URL pictureUrl = new URL(url);
InputStream in = pictureUrl.openStream();
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
public void savePicture(Bitmap bitmap) {
String pictureName = "/storage/emulated/0/DCIM/Camera/aaaa.jpg";
File file = new File(pictureName);
FileOutputStream out;
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuItem item = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "Exit");
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
System.exit(0);
return true;
}
});
return true;
}
}
|