|
package com.electric.chargingpile.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.blankj.utilcode.util.EmptyUtils;
import com.blankj.utilcode.util.LogUtils;
import com.electric.chargingpile.R;
import com.electric.chargingpile.application.MainApplication;
import com.electric.chargingpile.constant.BaseConstants;
import com.electric.chargingpile.data.ChargingBean;
import com.electric.chargingpile.util.BarColorUtil;
import com.electric.chargingpile.util.DES3;
import com.electric.chargingpile.util.JsonUtils;
import com.electric.chargingpile.util.Md5Util;
import com.electric.chargingpile.view.RatingBarView;
import com.umeng.analytics.MobclickAgent;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.TimeZone;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;
import okhttp3.Call;
public class OderDetailsActivity extends Activity implements View.OnClickListener, PlatformActionListener {
private ImageView iv_back, iv_hongbao, iv;
private PopupWindow popupWindow;
private View popupWindowView;
private TextView tv_service_cost, tv_zhuang_no, tv_tishi, tv_charging_time, tv_charging_liang, tv_charging_cost, tv_charging_hongbao, tv_charging_shifu;
private String activeUrl, time, hongbao, jine, shifu, liang, end_info, zhuang_id, zhan_idc, order_id, out_order_id, settlement, powerCharge, serviceCharge;
private String url = "1", icon = "", title = "", text = " ", star_level = "";
private RatingBar ratingBar;
private EditText et_pinglun;
private TextView tv_submit, tv_pinglun, tv_name;
private RatingBarView ratingBarView;
private LinearLayout ll_order;
private TextView tv_gocomment;
private LinearLayout red_paper_bag_bottom;
private RelativeLayout rl_end_info;
private String name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_oder_details);
BarColorUtil.initStatusBarColor(OderDetailsActivity.this);
getIntentData();
initViews();
initData();
// showHongBao();
}
private void initViews() {
tv_service_cost = (TextView) findViewById(R.id.tv_service_cost);
ll_order = (LinearLayout) findViewById(R.id.ll_order);
et_pinglun = (EditText) findViewById(R.id.et_pinglun);
tv_pinglun = (TextView) findViewById(R.id.tv_pinglun);
tv_gocomment = (TextView) findViewById(R.id.tv_gocomment);
red_paper_bag_bottom = findViewById(R.id.red_paper_bag_bottom);
iv = (ImageView) findViewById(R.id.iv);
tv_gocomment.setOnClickListener(this);
iv_back = (ImageView) findViewById(R.id.iv_back);
iv_back.setOnClickListener(this);
tv_name = (TextView) findViewById(R.id.tv_name);
tv_name.setText(name);
tv_zhuang_no = (TextView) findViewById(R.id.tv_zhuang_no);
tv_zhuang_no.setText(zhuang_id);
// iv_hongbao = (ImageView) findViewById(R.id.iv_hongbao);
// iv_hongbao.setOnClickListener(this);
tv_charging_time = (TextView) findViewById(R.id.tv_charging_time);
if (!time.equals("")) {
tv_charging_time.setText(time);
}
tv_charging_liang = (TextView) findViewById(R.id.tv_charging_liang);
tv_charging_liang.setText(liang + "度");
tv_charging_cost = (TextView) findViewById(R.id.tv_charging_cost);
tv_charging_cost.setText(powerCharge + "元");
tv_charging_hongbao = (TextView) findViewById(R.id.tv_charging_hongbao);
tv_charging_hongbao.setText("-" + hongbao + "元");
tv_charging_shifu = (TextView) findViewById(R.id.tv_charging_shifu);
tv_charging_shifu.setText(shifu);
tv_service_cost.setText(serviceCharge + "元");
tv_tishi = (TextView) findViewById(R.id.tv_tishi);
rl_end_info = (RelativeLayout) findViewById(R.id.rl_end_info);
// if (ChargingStatusActivity.no == 0){
// tv_tishi.setVisibility(View.GONE);
// }else{
if (end_info.equals("")) {
rl_end_info.setVisibility(View.GONE);
} else {
rl_end_info.setVisibility(View.VISIBLE);
tv_tishi.setText(end_info);
}
// tv_tishi.setVisibility(View.VISIBLE);
// tv_tishi.setText(end_info);
// }
if (EmptyUtils.isNotEmpty(activeUrl)) {
// ToastUtil.showToast(getApplicationContext(),activeUrl,Toast.LENGTH_LONG);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(getApplication(), MyWebViewActivity.class);
intent.putExtra("url", activeUrl);
startActivity(intent);
}
}, 1000);
}
}
private void getIntentData() {
ChargingBean chargingBean = (ChargingBean) getIntent().getSerializableExtra(BaseConstants.CHARGING_DATA);
if (chargingBean.getTimeCharge() != null) {
time = chargingBean.getTimeCharge();
}
jine = chargingBean.getTotalMoney();
hongbao = chargingBean.getRedMoney();
// shifu = getIntent().getStringExtra("money");
shifu = chargingBean.getUserMoney();
liang = chargingBean.getPower();
// url = getIntent().getStringExtra("url");
end_info = chargingBean.getEndInfo();
zhuang_id = chargingBean.getStubId();
zhan_idc = chargingBean.getZhanID();
order_id = chargingBean.getOrderId();
out_order_id = chargingBean.getOutOrderId();
// settlement = getIntent().getStringExtra("settlement");
name = chargingBean.getZhanname();
serviceCharge = chargingBean.getServiceMoney();
powerCharge = chargingBean.getElecMoney();
activeUrl = getIntent().getStringExtra(BaseConstants.ACTIVITY_URL);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_back:
finish();
// MainScanActivity.tag = "";
break;
case R.id.tv_gocomment:
Intent intent = new Intent(getApplicationContext(), ChargingCommentActivity.class);
intent.putExtra("zhan_id", zhan_idc);
intent.putExtra("order_id", out_order_id);
intent.putExtra("zhuang_id", zhuang_id);
// intent.putExtra("bean",chargingShareBean);
// intent.putExtra("show",showHongBao);
startActivity(intent);
finish();
// ActivityManagerApplication.addDestoryActivity(this,"OderDetailsActivity");
break;
}
}
private void showHongBaoView() {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
popupWindowView = inflater.inflate(R.layout.view_share_hongbao, null);
popupWindow = new PopupWindow(popupWindowView,
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT,
true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
// 设置PopupWindow的弹出和消失效果
popupWindow.setAnimationStyle(R.style.popupAnimation);
TextView tv_share_weixin = (TextView) popupWindowView.findViewById(R.id.tv_share_wechat);
tv_share_weixin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShareParams wechat = new ShareParams();
wechat.setTitle(title);
wechat.setText(text);
wechat.setImageUrl(MainApplication.url + "/zhannew/uploadfile/" + icon);
wechat.setUrl(url);
wechat.setShareType(Platform.SHARE_WEBPAGE);
Platform weixin = ShareSDK.getPlatform(Wechat.NAME);
weixin.setPlatformActionListener(OderDetailsActivity.this);
weixin.share(wechat);
popupWindow.dismiss();
}
});
TextView tv_share_friend = (TextView) popupWindowView.findViewById(R.id.tv_share_friend);
tv_share_friend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShareParams wechatMoments = new ShareParams();
wechatMoments.setTitle(title);
// wechatMoments.setText("分享文本");
wechatMoments.setUrl(url);
wechatMoments.setImageUrl(MainApplication.url + "/zhannew/uploadfile/" + icon);
// wechatMoments.setMusicUrl("http://www.zhlongyin.com/UploadFiles/xrxz/2011/5/201105051307513619.mp3");
wechatMoments.setShareType(Platform.SHARE_WEBPAGE);
Platform weixin1 = ShareSDK.getPlatform(WechatMoments.NAME);
weixin1.setPlatformActionListener(OderDetailsActivity.this);
weixin1.share(wechatMoments);
popupWindow.dismiss();
}
});
TextView tv_cancle = (TextView) popupWindowView.findViewById(R.id.tv_cancle);
tv_cancle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// iv_hongbao.setVisibility(View.VISIBLE);
popupWindow.dismiss();
}
});
popupWindow.showAtLocation(tv_share_weixin, Gravity.CENTER, 0, 0);
}
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}
private void initData() {
OkHttpUtils.get()
.url(MainApplication.url + "/zhannew/basic/web/index.php/fenxiang/show?thirdId=" + out_order_id)
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
}
@Override
public void onResponse(String response) {
LogUtils.e(response);
String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
if ("01".equals(rtnCode)) {
String data = JsonUtils.getKeyResult(response, "data");
String is_share = JsonUtils.getKeyResult(data, "is_share");
if (EmptyUtils.isNotEmpty(data) && is_share.equals("1")) {
tv_gocomment.setText("发表评论领红包");
red_paper_bag_bottom.setVisibility(View.VISIBLE);
} else {
red_paper_bag_bottom.setVisibility(View.GONE);
}
String is_print = JsonUtils.getKeyResult(data, "is_print");
if (EmptyUtils.isNotEmpty(data) && is_print.equals("1")) {
final String print_url = JsonUtils.getKeyResult(data, "print_url");
iv.setVisibility(View.VISIBLE);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MyWebViewActivity.class);
intent.putExtra("url", print_url);
startActivity(intent);
}
});
}
}
}
});
}
@Override
public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
// Toast.makeText(getApplicationContext(),"分享成功",Toast.LENGTH_SHORT).show();
// iv_hongbao.setVisibility(View.VISIBLE);
}
@Override
public void onError(Platform platform, int i, Throwable throwable) {
// iv_hongbao.setVisibility(View.VISIBLE);
}
@Override
public void onCancel(Platform platform, int i) {
// Toast.makeText(getApplicationContext(),"分享成功",Toast.LENGTH_SHORT).show();
// iv_hongbao.setVisibility(View.VISIBLE);
}
private void showHongBao() {
if (!url.equals("") || !title.equals("") || !text.equals("") || !icon.equals("")) {
new Handler().postDelayed(new Runnable() {
public void run() {
showHongBaoView();
}
}, 500);
}
}
public String getStandardTime(long timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
sdf.setTimeZone(TimeZone.getTimeZone("GMT+0"));
Date date = new Date(timestamp * 1000);
sdf.format(date);
return sdf.format(date);
}
private void submitPF() {
long appTime1 = System.currentTimeMillis() / 1000;
long updatetime = appTime1 - MainMapActivity.cha - 3;
String token = String.valueOf(updatetime);
String url = "http://123.57.6.131/zhannew/basic/web/index.php/zhanstar/staradd" +
"?order_id=" + order_id + "&star_level=" + star_level + "&supplier=星星充电&timer=" + token + "&user_id=" + MainApplication.userId + "&ver=1.0&zhuang_id=" + zhuang_id + "&zhan_id=" + zhan_idc + "&sign="
+ Md5Util.md5("order_id=" + order_id + "&star_level=" + star_level + "&supplier=星星充电&timer=" + token + "&user_id=" + MainApplication.userId + "&zhan_id=" + zhan_idc + "&zhuang_id=" + zhuang_id + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a");
Log.e("url====pf", url);
OkHttpUtils.get()
.url(url)
.build()
.connTimeOut(10000)
.readTimeOut(10000)
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
}
@Override
public void onResponse(String response) {
Log.e("response===pf", response);
}
});
}
private void submitComment() throws Exception {
long appTime1 = System.currentTimeMillis() / 1000;
Log.i("appTime(long)---", appTime1 + "");
long updatetime = appTime1 - MainMapActivity.cha - 2;
Log.i("updatetime(long)---", updatetime + "");
Log.i("cha---", MainMapActivity.cha + "");
String token = String.valueOf(updatetime);
String url = MainApplication.url + "/zhannew/basic/web/index.php/tpappcomments/add?userid=" + MainApplication.userId + "&zhanid=" + zhan_idc + "&comment=" + URLEncoder.encode(et_pinglun.getText().toString()) + "&tel=" + MainApplication.userPhone + "&token=" + URLEncoder.encode(DES3.encode(token)) + "&order_id=";
OkHttpUtils.get()
.url(url)
.build()
.connTimeOut(10000)
.readTimeOut(10000)
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
}
@Override
public void onResponse(String response) {
Log.e("response===comment", response);
}
});
}
}
|