充电桩app代码

DetailsFragment.java 93KB

    package com.electric.chargingpile.fragment; import android.Manifest; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.text.SpannableString; import android.text.Spanned; import android.text.TextUtils; import android.text.style.ForegroundColorSpan; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.Space; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import com.amap.api.maps.AMapUtils; import com.amap.api.maps.model.LatLng; import com.blankj.utilcode.util.LogUtils; import com.bumptech.glide.Glide; import com.electric.chargingpile.BuildConfig; import com.electric.chargingpile.R; import com.electric.chargingpile.activity.AlterOneActivity; import com.electric.chargingpile.activity.ChargingQianDaoActivity; import com.electric.chargingpile.activity.CommentVideoDetailActivity; import com.electric.chargingpile.activity.ImagePagerActivity; import com.electric.chargingpile.activity.LoginActivity; import com.electric.chargingpile.activity.MainMapActivity; import com.electric.chargingpile.activity.NewZhanDetailsActivity; import com.electric.chargingpile.activity.PriceDetailsActivity; import com.electric.chargingpile.activity.ZhanDetailsNew; import com.electric.chargingpile.adapter.ZhanCommentsAapter; import com.electric.chargingpile.application.MainApplication; import com.electric.chargingpile.data.ChartData; import com.electric.chargingpile.data.MyOtto; import com.electric.chargingpile.data.PileData; import com.electric.chargingpile.data.RankinglistRefreshEvent; import com.electric.chargingpile.data.Zhan; import com.electric.chargingpile.util.CarTypeUtil; import com.electric.chargingpile.util.CircleTransform; import com.electric.chargingpile.util.DES; import com.electric.chargingpile.util.DES3; import com.electric.chargingpile.util.DES3S; import com.electric.chargingpile.util.JsonUtils; import com.electric.chargingpile.util.LoadingDialog; import com.electric.chargingpile.util.Md5Util; import com.electric.chargingpile.util.OkHttpUtil; import com.electric.chargingpile.util.Util; import com.electric.chargingpile.view.CircleImageView; import com.electric.chargingpile.view.CustomProgressDialog; import com.electric.chargingpile.view.CustomScrollView; import com.github.mikephil.charting.charts.CombinedChart; import com.github.mikephil.charting.components.AxisBase; import com.github.mikephil.charting.components.Legend; import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.CombinedData; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; import com.squareup.otto.Subscribe; import com.squareup.picasso.Picasso; import com.umeng.analytics.MobclickAgent; import com.zhy.http.okhttp.OkHttpUtils; import com.zhy.http.okhttp.callback.StringCallback; import com.zhy.view.flowlayout.FlowLayout; import com.zhy.view.flowlayout.TagAdapter; import com.zhy.view.flowlayout.TagFlowLayout; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Socket; import java.net.URLEncoder; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import me.codeboy.android.aligntextview.AlignTextView; import okhttp3.Call; import pub.devrel.easypermissions.AfterPermissionGranted; import pub.devrel.easypermissions.AppSettingsDialog; import pub.devrel.easypermissions.EasyPermissions; public class DetailsFragment extends Fragment implements View.OnClickListener, OnChartValueSelectedListener, EasyPermissions.PermissionCallbacks { private static final String TAG = "DetailsFragment"; private static final int RC_TELL_PERM = 124; private Zhan zhan = null; private CombinedChart mChart; public static ArrayList<JSONObject> datas; private LinearLayout rl_claimer, ll_claimer, ll_phone, ll_juli, ll_juli1; private RelativeLayout rl_charging_qiandao, rl_grade; public static ImageView ssv; public static CustomScrollView sv; private String gd_jing, gd_wei; private CustomProgressDialog pd_info; public static TextView tv_picnum; private Socket socket; Context mContext; private TextView tv_claimer, tv_grade; String zhan_name, zhan_id, tid, zhan_address, supplier, total_num, fast_num, slow_num, stop_cost, charge_cost, telephone, remarks, suit_car, claimer, belong_attribute, poi_jing, poi_wei, charge_cost_way, other_cost, work_open, work_close; private TextView current_time_slot, tv_detail_charging_enter; private LinearLayout tv_cost_info; private LinearLayout ll_no_fenshi, ll_yes_fenshi; private TextView tv_today_num; private ImageView collect, iv_fast, iv_slow, type, share, iv_call, zhi, iv_zhanpic, iv_grade; private TextView tv_yunyingshang, fast, slow, open_object, tv_work_open, tv_work_close, holiday_open, holiday_close, belong_name, chargeDetail, tv_submit, parkCost, tv_total, distance1, distance, address, tv_remark, tvcostNum, other; String key = "aSU4wsxf"; public final static String NOENCRYPT = "noencrypt"; public final static String ENCRYPTMD5 = "aCveopDHgZnMnaYx1TFCV49R2lhJlB5e"; String client_id = "teldd0d40hq2hcuidt2j";// 商户ID String client_secret = "yw9gsl33ri";// 商户密码 String grant_type = "client_credentials";// 表示使用的授权模式 String token_url = "http://open.teld.cn/OAuth/Token";// 表示使用的授权模式 String postSta_url = "http://open.teld.cn/api/Sta/PostStaDetail";// 表示使用的授权模式 String acNum, dcNum, acableNum, dcableNum; private String[] stringArr; private RelativeLayout rlclaimer; private View detail_view; private OnDetailsFragmentListener detailsFragmentListener; private String vacancyCode; private String freeStatus; private LoadingDialog loadingDialog; private TextView tv_pdelete, tv_pname, tv_sname, tv_ptime, tv_stime, tv_pcontext, tv_scontext, tv_preply, tv_pcar, tv_more, tv_pzan; private ImageView iv_picon, certified_icon, high_grade_comment_icon; private LinearLayout ll_pzan; private ImageView iv_havemessage ,imgTwo,imgThree,imgVideo,imgStart,iv_commentPic; private ImageView iv_pgrade, iv_pzan, iv_level_img; private TagFlowLayout fl_ptag; private ListView lv_scomment; private RelativeLayout parent,imgLayout; private Handler handler = new Handler() { // 主线程通过这个方法处理消息 @TargetApi(Build.VERSION_CODES.KITKAT) @Override public void handleMessage(Message msg) { switch (msg.what) { case 1: try { final JSONObject object = new JSONObject(msg.obj.toString()); String info = JsonUtils.getKeyResult(msg.obj.toString(), "info"); String info_decode = DES3S.decode(info); JSONArray jsonArray = null; try { jsonArray = object.getJSONArray("pic"); } catch (JSONException e) { e.printStackTrace(); } String[] strArray = new String[jsonArray.length()]; StringBuffer strbuf = new StringBuffer(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.opt(i); String s = null; try { s = jsonObject.getString("url"); } catch (JSONException e) { e.printStackTrace(); } Log.e("!!!", MainApplication.url + "/zhannew//uploadfile/" + s); strbuf.append("|").append(MainApplication.url + "/zhannew//uploadfile/" + s); } String str = ""; if (jsonArray.length() > 0) { String result; str = strbuf.deleteCharAt(0).toString(); if (str.contains("|")) { result = str.substring(0, str.indexOf("|")); } else { result = str; } final String[] s = str.split("\\|"); detail_picnum.setText(s.length + ""); Picasso.with(MainApplication.context) .load(result) .error(R.drawable.bg_banner2_0) .placeholder(R.drawable.bg_banner2_0) .into(detail_zhan_pic); detail_zhan_pic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getContext(), ImagePagerActivity.class); // 图片url,为了演示这里使用常量,一般从数据库中或网络中获取 intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, s); intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, 0); startActivity(intent); } }); } else { detail_zhan_pic.setBackgroundResource(R.drawable.bg_upload_details); detail_picnum.setVisibility(View.GONE); detail_zhan_pic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!MainApplication.isLogin()) { Toast.makeText(getContext(), "请先登录", Toast.LENGTH_SHORT).show(); startActivity(new Intent(getContext(), LoginActivity.class)); } else { Intent intent = new Intent(getContext(), AlterOneActivity.class); intent.putExtra("zhanname", NewZhanDetailsActivity.zhanname); intent.putExtra("zhanid", NewZhanDetailsActivity.zhan_id); intent.putExtra("title", "添加站点图片"); startActivity(intent); } } }); } zhan_id = JsonUtils.getKeyResult(info_decode, "id"); zhan_name = JsonUtils.getKeyResult(info_decode, "zhan_name"); zhan_address = JsonUtils.getKeyResult(info_decode, "zhan_address"); supplier = JsonUtils.getKeyResult(info_decode, "supplier"); total_num = JsonUtils.getKeyResult(info_decode, "total_num"); fast_num = JsonUtils.getKeyResult(info_decode, "fast_num"); slow_num = JsonUtils.getKeyResult(info_decode, "slow_num"); tid = JsonUtils.getKeyResult(info_decode, "zhan_id"); stop_cost = JsonUtils.getKeyResult(info_decode, "stop_cost"); charge_cost = JsonUtils.getKeyResult(info_decode, "charge_cost"); telephone = JsonUtils.getKeyResult(info_decode, "telephone"); remarks = JsonUtils.getKeyResult(info_decode, "remarks"); claimer = JsonUtils.getKeyResult(info_decode, "claimer"); belong_attribute = JsonUtils.getKeyResult(info_decode, "belong_attribute"); poi_jing = JsonUtils.getKeyResult(info_decode, "poi_jing"); poi_wei = JsonUtils.getKeyResult(info_decode, "poi_wei"); charge_cost_way = JsonUtils.getKeyResult(info_decode, "charge_cost_way2"); other_cost = JsonUtils.getKeyResult(info_decode, "other_cost"); work_open = JsonUtils.getKeyResult(info_decode, "work_open"); work_close = JsonUtils.getKeyResult(info_decode, "work_close"); zongjia = JsonUtils.getKeyResult(info_decode, "zongjia"); String park_location = JsonUtils.getKeyResult(info_decode, "park_location"); String own_pay = JsonUtils.getKeyResult(info_decode, "own_pay"); if (detailsFragmentListener != null) { detailsFragmentListener.updateScanCharge(own_pay); } if ("1".equals(own_pay)) { scan_charge_btn.setVisibility(View.VISIBLE); scan_charge_space.setVisibility(View.VISIBLE); } else { scan_charge_btn.setVisibility(View.GONE); scan_charge_space.setVisibility(View.GONE); } String fenshi_info = JsonUtils.getKeyResult(info_decode, "fenshi_info"); String fenshi_is = JsonUtils.getKeyResult(info_decode, "fenshi_is"); Log.e("@@@", fenshi_info); if ("1".equals(own_pay)) { getChartData(); red_paper_bag_top.setVisibility(View.VISIBLE); } else { mChart.setVisibility(View.GONE); red_paper_bag_top.setVisibility(View.GONE); } JSONArray ja = new JSONArray(fenshi_info); datas = new ArrayList<JSONObject>(); for (int j = 0; j < ja.length(); j++) { JSONObject jsonObject = (JSONObject) ja.opt(j); datas.add(jsonObject); } // Log.e(TAG, "handleMessage: ja.size()="+ja.length() ); if (null != fenshi_is) { if (fenshi_is.equals("0")) { ll_no_fenshi.setVisibility(View.VISIBLE); ll_yes_fenshi.setVisibility(View.GONE); } else { ll_no_fenshi.setVisibility(View.GONE); ll_yes_fenshi.setVisibility(View.VISIBLE); Calendar calendar = Calendar.getInstance(); int hours = calendar.get(Calendar.HOUR_OF_DAY); int minutes = calendar.get(Calendar.MINUTE); int totalMinutes = hours * 60 + minutes; for (JSONObject obj : DetailsFragment.datas) { PileData.FenshiInfoBean bean = JsonUtils.parseToObjectBean(obj.toString(), PileData.FenshiInfoBean.class); if (totalMinutes >= bean.getStartTotalMinutes() && totalMinutes <= bean.getEndTotalMinutes()) { current_time_slot.setText("当前时间段 " + bean.getStart() + "-" + bean.getEnd()); break; } } total_price.setText(zongjia); } } else { ll_no_fenshi.setVisibility(View.VISIBLE); ll_yes_fenshi.setVisibility(View.GONE); } NewZhanDetailsActivity.isCollect(zhan_name); NewZhanDetailsActivity.zhanname = zhan_name; NewZhanDetailsActivity.zhan_address = zhan_address; NewZhanDetailsActivity.jingdu = poi_jing; NewZhanDetailsActivity.weidu = poi_wei; if (MainApplication.details_flag.equals("1") || MainApplication.details_flag.equals("2") || MainApplication.details_flag.equals("8")) { NewZhanDetailsActivity.jingdu = poi_jing; NewZhanDetailsActivity.weidu = poi_wei; } if (JsonUtils.getKeyResult(info_decode, "acNum") != null) { acNum = JsonUtils.getKeyResult(info_decode, "acNum"); dcNum = JsonUtils.getKeyResult(info_decode, "dcNum"); acableNum = JsonUtils.getKeyResult(info_decode, "acableNum"); dcableNum = JsonUtils.getKeyResult(info_decode, "dcableNum"); freeStatus = "1"; // 有状态的站点 } else { freeStatus = "0"; // 无状态的站点 } detail_zhan_name.setText(zhan_name); if (supplier.equals("")) { detail_supplier.setText("暂无"); } else { detail_supplier.setText(supplier); } if (null != acableNum && null != acNum && null != dcableNum && null != dcNum && !acableNum.equals("") && !acNum.equals("") && !dcableNum.equals("") && !dcNum.equals("")) { window_tv_fast_total_num.setText("/" + dcNum); // 快充总桩数 window_tv_fast_free_num.setText(dcableNum); // 快充空闲桩数 window_tv_fast_total_num.setVisibility(View.VISIBLE); window_tv_fast_free_label.setVisibility(View.VISIBLE); window_tv_slow_total_num.setText("/" + acNum); window_tv_slow_free_num.setText(acableNum); window_tv_slow_total_num.setVisibility(View.VISIBLE); window_tv_slow_free_label.setVisibility(View.VISIBLE); } else { if ("".equals(fast_num)) { window_tv_fast_free_num.setText("0"); } else { window_tv_fast_free_num.setText(fast_num); } window_tv_fast_total_num.setVisibility(View.GONE); window_tv_fast_free_label.setVisibility(View.GONE); if ("".equals(slow_num)) { window_tv_slow_free_num.setText("0"); } else { window_tv_slow_free_num.setText(slow_num); } window_tv_slow_total_num.setVisibility(View.GONE); window_tv_slow_free_label.setVisibility(View.GONE); } if (!telephone.equals("")) { detail_tel.setVisibility(View.VISIBLE); } else { detail_tel.setVisibility(View.GONE); } int position_jing = poi_jing.length() - poi_jing.indexOf(".") + 1; int position_wei = poi_wei.length() - poi_wei.indexOf(".") + 1; LatLng ll; if (position_jing > 13 || position_wei > 13) { ll = new LatLng(Double.parseDouble(poi_wei), Double.parseDouble(poi_jing)); } else { double dwei = Double.parseDouble(poi_wei); double djing = Double.parseDouble(poi_jing); getGaode(djing, dwei); ll = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing)); } try { double d = AMapUtils.calculateLineDistance(MainMapActivity.center, ll); detail_zhan_distance.setText(Util.getDistance(d)); } catch (NullPointerException e) { e.printStackTrace(); } if (belong_attribute.equals("公共")) { detail_private_or_public.setImageResource(R.drawable.icon_detail_public); } else if (belong_attribute.equals("私人")) { detail_private_or_public.setImageResource(R.drawable.icon_detail_private); } detail_address.setText(zhan_address); if (charge_cost.equals("")) { detail_charge_cost.setText("暂无"); } else { detail_charge_cost.setText(charge_cost); ViewTreeObserver vto = detail_charge_cost.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { detail_charge_cost.getViewTreeObserver().removeGlobalOnLayoutListener(this); detail_charge_cost.getHeight(); double w0 = detail_charge_cost.getWidth();//控件宽度 double w1 = detail_charge_cost.getPaint().measureText(detail_charge_cost.getText().toString());//文本宽度 if (w1 >= w0) { // detail_charge_cost.setGravity(Gravity.LEFT); detail_charge_cost.setAlign(AlignTextView.Align.ALIGN_LEFT); }//需要换行就显示该控件 } }); } // Log.e(TAG, "handleMessage: own_pay="+own_pay ); if (own_pay.equals("1")) { detail_cost.setText("可使用本APP扫码支付"); } else { if (charge_cost_way.equals("")) { detail_cost.setText("暂无"); } else if (charge_cost_way.equals("请选择支付方式")) { detail_cost.setText("暂无"); } else { detail_cost.setText(charge_cost_way); } } if (stop_cost.equals("")) { detail_park_cost.setText("暂无"); } else { // Log.e(TAG, "handleMessage: sss"+stop_cost ); detail_park_cost.setText(stop_cost); ViewTreeObserver vto = detail_park_cost.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { detail_park_cost.getViewTreeObserver().removeGlobalOnLayoutListener(this); detail_park_cost.getHeight(); double w0 = detail_park_cost.getWidth();//控件宽度 double w1 = detail_park_cost.getPaint().measureText(detail_park_cost.getText().toString());//文本宽度 if (w1 >= w0) { // detail_park_cost.setGravity(Gravity.LEFT); detail_park_cost.setAlign(AlignTextView.Align.ALIGN_LEFT); }//需要换行就显示该控件 } }); } if (other_cost.equals("")) { detail_serve_cost.setText("暂无"); } else { detail_serve_cost.setText(other_cost); } if (work_close.equals("") && work_open.equals("")) { detail_time.setText("暂无"); } else { if (work_open.equals("")) { work_open = "暂无"; } if (work_close.equals("")) { work_close = "暂无"; } detail_time.setText(work_open + "-" + work_close); ViewTreeObserver vto = detail_time.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { detail_time.getViewTreeObserver().removeGlobalOnLayoutListener(this); detail_time.getHeight(); double w0 = detail_time.getWidth();//控件宽度 double w1 = detail_time.getPaint().measureText(detail_time.getText().toString());//文本宽度 if (w1 >= w0) { // detail_park_cost.setGravity(Gravity.LEFT); detail_time.setAlign(AlignTextView.Align.ALIGN_LEFT); }//需要换行就显示该控件 } }); } if (remarks.equals("") || remarks.equals(" ") || remarks.equals(" ")) { detail_claimer_remark.setVisibility(View.GONE); detail_view.setVisibility(View.GONE); } else { detail_claimer_remark.setVisibility(View.VISIBLE); detail_view.setVisibility(View.VISIBLE); detail_remark.setText(remarks); } if (park_location.equals("0")) { detail_up_or_down.setImageDrawable(getResources().getDrawable(R.drawable.icon_detail_down)); } else if (park_location.equals("1")) { detail_up_or_down.setImageDrawable(getResources().getDrawable(R.drawable.icon_detail_up)); } } catch (Exception e) { e.printStackTrace(); } break; case 2: try { JSONObject object = new JSONObject(msg.obj.toString()); JSONArray jsonArray = object.getJSONArray("pic"); // Log.e("jsonarray",jsonArray.length()+""); // String a[] = new String[jsonArray.length()]; // Pattern p = Pattern.compile("p"); // Matcher m;s String[] strArray = new String[jsonArray.length()]; StringBuffer strbuf = new StringBuffer(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.opt(i); String s = jsonObject.getString("url"); strbuf.append("|").append(MainApplication.url + "/zhannew//uploadfile/" + s); // Log.e("url===", s); } String str = ""; if (jsonArray.length() > 0) { str = strbuf.deleteCharAt(0).toString(); // Log.e("data===",str); // ssv.initData(str); } else { ssv.setBackgroundResource(R.drawable.bg_banner2_0); } } catch (JSONException e) { e.printStackTrace(); } break; case 111: try { String mssg = DES.decrypt(msg.obj.toString(), key); setViewValues(mssg); } catch (Exception e) { e.printStackTrace(); } break; case 6: // if (null != msg.obj) { // JSONArray jsonArray = null; // String s = null; // try { // jsonArray = new JSONArray(msg.obj.toString()); // //// Log.e("s==",s); // } catch (JSONException e) { // e.printStackTrace(); // } // if (null != jsonArray) { // if (jsonArray.length() > 0) { // rl_new_comment.setVisibility(View.VISIBLE); // try { // s = jsonArray.get(0).toString(); // } catch (JSONException e) { // e.printStackTrace(); // } // String nickname = JsonUtils.getKeyResult(s, "nickname"); // String tel = JsonUtils.getKeyResult(s, "tel"); // String chexing = JsonUtils.getKeyResult(s, "chexing"); // String star_level = JsonUtils.getKeyResult(s, "star_level"); // String userpic = JsonUtils.getKeyResult(s, "userpic"); // String addtime = JsonUtils.getKeyResult(s, "addtime"); // String tag = JsonUtils.getKeyResult(s, "tag"); // String thumUrl = JsonUtils.getKeyResult(s, "thumUrl"); // String fileUrl = JsonUtils.getKeyResult(s, "fileUrl"); //1 // // if (thumUrl != null && fileUrl != null && !thumUrl.equals("") && !fileUrl.equals("")) { // iv_commentPic.setVisibility(View.VISIBLE); // final String url = MainApplication.url + "/zhannew/uploadfile/" + thumUrl; // final String file_url = MainApplication.url + "/zhannew/uploadfile/" + fileUrl; // final String[] ss = {file_url}; // Picasso.with(MainApplication.context) // .load(url) // .into(iv_commentPic); // iv_commentPic.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // Intent intent = new Intent(getContext(), ImagePagerActivity.class); // // 图片url,为了演示这里使用常量,一般从数据库中或网络中获取 // intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, ss); // intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, 0); // getContext().startActivity(intent); // } // }); // } else { // iv_commentPic.setVisibility(View.GONE); // } // if (tag != null && tag.equals("")) { // mFlowLayout.setVisibility(View.GONE); // } else { // if (null == getActivity()) { // mFlowLayout.setVisibility(View.GONE); // } else { // if (null != getActivity()) { // mFlowLayout.setVisibility(View.VISIBLE); // final LayoutInflater mInflater = LayoutInflater.from(getActivity()); // stringArr = tag.split(","); // mFlowLayout.setClickable(false); // mFlowLayout.setEnabled(false); // mFlowLayout.setAdapter(new TagAdapter<String>(stringArr) { // @Override // public View getView(FlowLayout parent, int position, String s) { // TextView tv = (TextView) mInflater.inflate(R.layout.tv1, // mFlowLayout, false); // tv.setText(s); // return tv; // } // }); // } // } // } // tv_new_time.setText(TimeStamp2Date(addtime, "yyyy-MM-dd")); // String url = MainApplication.url + "/zhannew/uploadfile/" + userpic; // // Picasso.with(MainApplication.context) // .load(url) // .error(R.drawable.icon_user1118) // .placeholder(R.drawable.icon_user1118) // .into(iv_new_icon); // // // // // tv_new_name.setText(nickname); // if (!nickname.equals("") && !nickname.equals("null")) { // tv_new_name.setText(nickname); // } else { // tv_new_name.setText(Util.handlePhoneComment(tel)); // } // // if ("待购".equals(chexing)) { // tv_new_car.setText("待购"); // } else { // String[] strarray = chexing.split("\\$\\$"); // String name0 = null, name1 = null; // if (strarray.length > 1) { // name0 = strarray[0];//江淮 // name1 = strarray[1];//iEV3 // } // if (chexing.equals("nullnull") || chexing == null || chexing.equals("") || chexing.equals("null") || chexing.equals("品牌$$车型") || chexing.equals("null$$null")) { // tv_new_car.setText(""); // } else { // tv_new_car.setText(name0 + name1); // } // } // if (star_level.equals("")) { // star_level = "0"; // } // double d = Double.parseDouble(star_level); // if (d == 0) { // iv_new_pingfen.setVisibility(View.GONE); // } else { // if (d > 0 && d < 1) { // iv_new_pingfen.setImageResource(R.drawable.icon_05xing); // iv_new_pingfen.setVisibility(View.VISIBLE); // } else if (d >= 1 && d < 1.5) { // iv_new_pingfen.setVisibility(View.VISIBLE); // iv_new_pingfen.setImageResource(R.drawable.icon_1xing); // } else if (d >= 1.5 && d < 2) { // iv_new_pingfen.setVisibility(View.VISIBLE); // iv_new_pingfen.setImageResource(R.drawable.icon_15xing); // } else if (d >= 2 && d < 2.5) { // iv_new_pingfen.setVisibility(View.VISIBLE); // iv_new_pingfen.setImageResource(R.drawable.icon_2xing); // } else if (d >= 2.5 && d < 3) { // iv_new_pingfen.setVisibility(View.VISIBLE); // iv_new_pingfen.setImageResource(R.drawable.icon_25xing); // } else if (d >= 3 && d < 3.5) { // iv_new_pingfen.setVisibility(View.VISIBLE); // iv_new_pingfen.setImageResource(R.drawable.icon_3xing); // } else if (d >= 3.5 && d < 4) { // iv_new_pingfen.setVisibility(View.VISIBLE); // iv_new_pingfen.setImageResource(R.drawable.icon_35xing); // } else if (d >= 4 && d < 4.5) { // iv_new_pingfen.setVisibility(View.VISIBLE); // iv_new_pingfen.setImageResource(R.drawable.icon_4xing); // } else if (d >= 4.5 && d < 5) { // iv_new_pingfen.setVisibility(View.VISIBLE); // iv_new_pingfen.setImageResource(R.drawable.icon_45xing); // } else { // iv_new_pingfen.setVisibility(View.VISIBLE); // iv_new_pingfen.setImageResource(R.drawable.icon_5xing); // } // } // // } else { // rl_new_comment.setVisibility(View.GONE); // } // } // } break; default: break; } } }; private String zongjia; private ImageView scan_charge_btn; private Space scan_charge_space; private String telNum; private RelativeLayout rl_new_comment; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragmen_details_new, null); initView(v); MyOtto.getInstance().register(this); loadingDialog = new LoadingDialog(getContext()); loadingDialog.setCanceledOnTouchOutside(false); return v; } @Override public void onStart() { super.onStart(); getPic(); detail_zhan_pic.setBackgroundResource(R.color.hui); new Handler().postDelayed(new Runnable() { @Override public void run() { if (isAdded()) { zhanGrade(NewZhanDetailsActivity.zhan_id); } } }, 500); rl_new_comment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NewZhanDetailsActivity.viewPager.setCurrentItem(2); ZhanCommentFragment.index = 1; NewZhanDetailsActivity.reFreshUi(); MobclickAgent.onEvent(getActivity(), "0210"); } }); //eteCityTime(null); } public String TimeStamp2Date(String timestampString, String formats) { Long timestamp = Long.parseLong(timestampString) * 1000; String date = new java.text.SimpleDateFormat(formats).format(new java.util.Date(timestamp)); return date; } public void setViewValues(String json) { try { String acNum = JsonUtils.getKeyResult(json, "acNum"); String dcNum = JsonUtils.getKeyResult(json, "dcNum"); String acableNum = JsonUtils.getKeyResult(json, "acableNum"); String dcableNum = JsonUtils.getKeyResult(json, "dcableNum"); fast.setText("空闲" + acableNum + "/共" + acNum + "个"); slow.setText("空闲" + dcableNum + "/共" + dcNum + "个"); } catch (Exception e) { e.printStackTrace(); } } private TextView detail_address, detail_grade, detail_picnum, detail_zhan_distance, window_tv_fast_total_num, window_tv_fast_free_label, window_tv_fast_free_num, window_tv_slow_total_num, window_tv_slow_free_label, window_tv_slow_free_num, detail_supplier, detail_cost, detail_serve_cost, total_price, details_claimer; private AlignTextView detail_charge_cost; private AlignTextView detail_park_cost; private AlignTextView detail_remark; private AlignTextView detail_zhan_name; private LinearLayout red_paper_bag_top; private AlignTextView detail_time; public static TextView detail_list_num; public static TextView detail_go_list; private ImageView detail_private_or_public, detail_up_or_down, detail_zhan_pic; private RelativeLayout detail_tel; private LinearLayout detail_claimer_remark; private void initView(View v) { tv_today_num = v.findViewById(R.id.tv_today_num); mChart = (CombinedChart) v.findViewById(R.id.chart1); mChart.setNoDataText("正在加载数据..."); mChart.setNoDataTextColor(getActivity().getResources().getColor(R.color.ui_68)); ll_no_fenshi = (LinearLayout) v.findViewById(R.id.ll_no_fenshi); ll_yes_fenshi = (LinearLayout) v.findViewById(R.id.ll_yes_fenshi); tv_cost_info = v.findViewById(R.id.tv_cost_info); tv_cost_info.setOnClickListener(this); current_time_slot = (TextView) v.findViewById(R.id.current_time_slot); detail_view = v.findViewById(R.id.detail_view); detail_claimer_remark = (LinearLayout) v.findViewById(R.id.detail_claimer_remark); detail_tel = (RelativeLayout) v.findViewById(R.id.detail_tel); detail_tel.setOnClickListener(this); detail_private_or_public = (ImageView) v.findViewById(R.id.detail_private_or_public); detail_up_or_down = (ImageView) v.findViewById(R.id.detail_up_or_down); detail_zhan_pic = (ImageView) v.findViewById(R.id.detail_zhan_pic); detail_zhan_name = (AlignTextView) v.findViewById(R.id.detail_zhan_name); red_paper_bag_top = v.findViewById(R.id.red_paper_bag_top); detail_grade = (TextView) v.findViewById(R.id.detail_grade); detail_picnum = (TextView) v.findViewById(R.id.detail_picnum); detail_address = (TextView) v.findViewById(R.id.detail_address); detail_zhan_distance = (TextView) v.findViewById(R.id.detail_zhan_distance); window_tv_fast_total_num = (TextView) v.findViewById(R.id.window_tv_fast_total_num); window_tv_fast_free_label = (TextView) v.findViewById(R.id.window_tv_fast_free_label); window_tv_fast_free_num = (TextView) v.findViewById(R.id.window_tv_fast_free_num); window_tv_slow_total_num = (TextView) v.findViewById(R.id.window_tv_slow_total_num); window_tv_slow_free_label = (TextView) v.findViewById(R.id.window_tv_slow_free_label); window_tv_slow_free_num = (TextView) v.findViewById(R.id.window_tv_slow_free_num); detail_supplier = (TextView) v.findViewById(R.id.detail_supplier); detail_cost = (TextView) v.findViewById(R.id.detail_cost); detail_charge_cost = (AlignTextView) v.findViewById(R.id.detail_charge_cost); detail_serve_cost = (TextView) v.findViewById(R.id.detail_serve_cost); total_price = (TextView) v.findViewById(R.id.total_price); detail_park_cost = (AlignTextView) v.findViewById(R.id.detail_park_cost); detail_time = (AlignTextView) v.findViewById(R.id.detail_time); detail_list_num = (TextView) v.findViewById(R.id.detail_list_num); details_claimer = (TextView) v.findViewById(R.id.details_claimer); detail_remark = (AlignTextView) v.findViewById(R.id.detail_remark); detail_go_list = (TextView) v.findViewById(R.id.detail_charging_enter); detail_go_list.setOnClickListener(this); scan_charge_btn = v.findViewById(R.id.scan_charge_btn); scan_charge_btn.setOnClickListener(this); scan_charge_space = v.findViewById(R.id.scan_charge_space); rl_new_comment = v.findViewById(R.id.rl_new_comment); tv_pname = (TextView) v.findViewById(R.id.tv_pname); tv_pdelete = (TextView) v.findViewById(R.id.tv_pdelete); tv_ptime = (TextView) v.findViewById(R.id.tv_ptime); tv_pcontext = (TextView) v.findViewById(R.id.tv_pcontext); tv_pcar = (TextView) v.findViewById(R.id.tv_pcar); tv_preply = (TextView) v.findViewById(R.id.tv_preply); tv_pzan = (TextView) v.findViewById(R.id.tv_pzan); tv_more = (TextView) v.findViewById(R.id.tv_more); lv_scomment = (ListView) v.findViewById(R.id.lv_scomment); iv_picon = (ImageView) v.findViewById(R.id.iv_picon); certified_icon = (ImageView) v.findViewById(R.id.certified_icon); high_grade_comment_icon = (ImageView) v.findViewById(R.id.high_grade_comment_icon); iv_pgrade = (ImageView) v.findViewById(R.id.iv_pgrade); iv_commentPic = (ImageView) v.findViewById(R.id.iv_commentPic); imgTwo = (ImageView) v.findViewById(R.id.imgTwo); imgThree = (ImageView) v.findViewById(R.id.imgThree); imgStart = (ImageView) v.findViewById(R.id.imgStart); imgVideo = (ImageView) v.findViewById(R.id.imgVideo); iv_level_img = (ImageView) v.findViewById(R.id.iv_level_img); iv_pzan = (ImageView) v.findViewById(R.id.iv_pzan); ll_pzan = (LinearLayout) v.findViewById(R.id.ll_pzan); fl_ptag = (TagFlowLayout) v.findViewById(R.id.fl_ptag); parent = (RelativeLayout) v.findViewById(R.id.parent); imgLayout = (RelativeLayout) v.findViewById(R.id.imgLayout); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.tv_cost_info: if (datas != null && datas.size() > 0) { getActivity().startActivity(new Intent(getActivity(), PriceDetailsActivity.class)); } MobclickAgent.onEvent(MainApplication.context, "0208"); break; case R.id.detail_tel: new com.electric.chargingpile.view.AlertDialog(getActivity()).builder() .setMsg(zhan_name + " " + telephone) .setPositiveButton("呼叫", new View.OnClickListener() { @Override public void onClick(View v) { telNum = telephone.toString(); tellTask(); } }).setNegativeButton("取消", new View.OnClickListener() { @Override public void onClick(View v) { } }).show(); MobclickAgent.onEvent(getActivity(), "0207"); break; case R.id.detail_charging_enter: MobclickAgent.onEvent(getActivity(), "0209"); startActivity(new Intent(getActivity(), ChargingQianDaoActivity.class)); break; case R.id.scan_charge_btn: if (detailsFragmentListener != null) { detailsFragmentListener.scanCharge(); } break; } } private void getPic() { new Thread(new Runnable() { @Override public void run() { String url = MainApplication.url + "/zhannew/basic/web/index.php/zhanlist/zhan-info2?zhan_id=" + NewZhanDetailsActivity.zhan_id + "&version=" + MainApplication.current_code; submitPic(url); } }).start(); } private void submitPic(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 = 1; 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 void submitPic1(String sms) { // Log.e("url", 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 = 2; 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); } } @Override public void onResume() { super.onResume(); // NewZhanDetailsActivity.resetViewPagerHeight(0); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } public void createDialog() { if (pd_info == null) { pd_info = CustomProgressDialog.createDialog(DetailsFragment.this.getContext()); pd_info.setMessage("数据加载中..."); pd_info.show(); } } public void dismissDialog() { if (pd_info != null) { pd_info.dismiss(); pd_info = null; } } private void getGaode(Double jing, Double wei) { // Log.e("jing", jing + ""); // Log.e("wei", wei + ""); double x_pi = 3.14159265358979324 * 3000.0 / 180.0; double gg_lon; double gg_lat; double x = jing - 0.0065, y = wei - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi); gg_lon = z * Math.cos(theta); gd_jing = String.valueOf(gg_lon); // Log.e("gg_lon", gg_lon + ""); gg_lat = z * Math.sin(theta); gd_wei = String.valueOf(gg_lat); // Log.e("gg_lat", gg_lat + ""); } /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dp2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } private void zhanGrade(String zhan_id) { long appTime1 = System.currentTimeMillis() / 1000; long updatetime = appTime1 - MainMapActivity.cha - 3; String token = String.valueOf(updatetime); String url = MainApplication.url + "/zhannew/basic/web/index.php/zhanstar/getstar" + "?supplier=星星充电&timer=" + token + "&ver=1.0&zhan_id=" + zhan_id + "&sign=" + Md5Util.md5("supplier=星星充电&timer=" + token + "&zhan_id=" + zhan_id + "&key=661f9efdcb4f46fe7ab5f2e78a705a2a"); // Log.e("zhanGrade===",url); OkHttpUtils.get() .url(url) .build() .execute(new StringCallback() { @Override public void onError(Call call, Exception e) { } @Override public void onResponse(String response) { if (null != response) { // Log.e("zhanGrade===", response); String code = JsonUtils.getKeyResult(response, "code"); String star_level = JsonUtils.getKeyResult(response, "star_level"); double d; if (star_level != null) { if (star_level.equals("")) { d = Double.parseDouble("0"); } else { d = Double.parseDouble(star_level); } if (code.equals("200")) { if (d == 0) { detail_grade.setText("暂无评分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_0xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } else { if (d > 0 && d < 1) { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_05xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } else if (d >= 1 && d < 1.5) { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_1xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } else if (d >= 1.5 && d < 2) { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_15xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } else if (d >= 2 && d < 2.5) { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_2xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } else if (d >= 2.5 && d < 3) { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_25xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } else if (d >= 3 && d < 3.5) { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_3xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } else if (d >= 3.5 && d < 4) { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_35xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); } } else if (d >= 4 && d < 4.5) { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_4xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } else if (d >= 4.5 && d < 5) { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_45xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } else { try { detail_grade.setText(d + "分"); if (isAdded()) { Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_5xing); rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight()); detail_grade.setCompoundDrawables(rightDrawable, null, null, null); detail_grade.setCompoundDrawablePadding(dp2px(MainApplication.context, 6)); } } catch (Exception e) { e.printStackTrace(); } } } } } } } }); } @Subscribe public void eteCityTime(RankinglistRefreshEvent rankinglistRefreshEvent) { String url = MainApplication.url + "/zhannew/basic/web/index.php/tpappcomments/get-comments?zhanid=" + NewZhanDetailsActivity.zhan_id + "&page=1"+"&version_code=" + BuildConfig.VERSION_CODE; OkHttpUtils.get().url(url).build().execute(new StringCallback() { @Override public void onError(Call call, Exception e) { } @Override public void onResponse(String response) { String rtnCode = JsonUtils.getKeyResult(response, "rtnCode"); if (null != rtnCode && rtnCode.equals("01")) { try { JSONObject responseJson = new JSONObject(response); String commentData = responseJson.getString("data"); JSONArray jsonArray = new JSONArray(commentData); ArrayList<JSONObject> datasJson = new ArrayList<JSONObject>(); for (int j = 0; j < jsonArray.length(); j++) { JSONObject jsonObject = (JSONObject) jsonArray.opt(j); datasJson.add(jsonObject); } if(datasJson.size()>0){ rl_new_comment.setVisibility(View.VISIBLE); JSONObject jsonObject = datasJson.get(0); String title = jsonObject.optString("title"); String name = jsonObject.optString("nickname"); String tel = jsonObject.optString("tel"); String content = jsonObject.optString("content"); String theme= jsonObject.optString("theme"); String addtime =jsonObject.optString("addtime"); String chexing = jsonObject.optString("hascar"); int isCertifiedOwner =jsonObject.optInt("is_certified_owner"); final String pic_url = MainApplication.url + "/zhannew/uploadfile/" + jsonObject.optString("userpic"); String fine = jsonObject.optString("fine"); if (title.equals("")) { iv_level_img.setVisibility(View.GONE); } else if (title.equals("V0")) { iv_level_img.setVisibility(View.GONE); } else if (title.equals("V1")) { iv_level_img.setVisibility(View.VISIBLE); iv_level_img.setImageResource(R.drawable.icon_qingtong); } else if (title.equals("V2")) { iv_level_img.setVisibility(View.VISIBLE); iv_level_img.setImageResource(R.drawable.icon_baiyin); } else if (title.equals("V3")) { iv_level_img.setVisibility(View.VISIBLE); iv_level_img.setImageResource(R.drawable.icon_huangjin); } else if (title.equals("V4")) { iv_level_img.setVisibility(View.VISIBLE); iv_level_img.setImageResource(R.drawable.icon_bojin); } else if (title.equals("V5")) { iv_level_img.setVisibility(View.VISIBLE); iv_level_img.setImageResource(R.drawable.icon_zuanshi); } if (!TextUtils.isEmpty(theme.trim())){ content= "#"+theme+"#"+content; } if (content.equals("") || content.equals(" ")) { tv_pcontext.setVisibility(View.GONE); } else { tv_pcontext.setVisibility(View.VISIBLE); SpannableString ss = new SpannableString(content); Pattern pattern = Pattern.compile("#[0-9a-zA-Z,\\u4e00-\\u9fa5]+#"); Matcher matcher = pattern.matcher(ss); while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); ss.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.topic_green)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } tv_pcontext.setText(ss); } //父级头像 iv_picon.setImageResource(R.drawable.icon_user1118); Picasso.with(getActivity()) .load(pic_url) .error(R.drawable.icon_user1118) .placeholder(R.drawable.icon_user1118) .transform(new CircleTransform()) .into(iv_picon); //父级显示名称 if (!name.equals("") && !name.equals("null")) { tv_pname.setText(name); } else { tv_pname.setText(Util.handlePhoneComment(tel)); } //父级评论时间 tv_ptime.setText(TimeStamp2Date(addtime, "yyyy-MM-dd")); //父级评论人车型 tv_pcar.setText(CarTypeUtil.getCarType(chexing)); if (isCertifiedOwner == 1) { certified_icon.setVisibility(View.VISIBLE); } else { certified_icon.setVisibility(View.GONE); } if ("1".equals(fine)) { high_grade_comment_icon.setVisibility(View.VISIBLE); } else { high_grade_comment_icon.setVisibility(View.GONE); } String tag =jsonObject.optString("tag"); if (tag.equals("")) { fl_ptag.setVisibility(View.GONE); } else { fl_ptag.setVisibility(View.VISIBLE); stringArr = tag.split(","); fl_ptag.setClickable(false); fl_ptag.setEnabled(false); fl_ptag.setAdapter(new TagAdapter<String>(stringArr) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.tv_comment, fl_ptag, false); tv.setText(s); return tv; } }); } //父级点赞 String agree_num = jsonObject.optString("agree_num"); if (agree_num.equals("0")) { tv_pzan.setText("赞"); } else { tv_pzan.setText(agree_num); } //父级评论图片 String fileUrl = jsonObject.optString("fileUrl"); String file2Url = jsonObject.optString("file2Url"); String file3Url = jsonObject.optString("file3Url"); String is_play =jsonObject.optString("is_play"); //0 审核未通过 item隐藏,1 审核通过,item显示 String type = jsonObject.optString("type"); //23 视频,24 图片 if (type.equals("23")){ if (is_play.equals("0")) { imgLayout.setVisibility(View.GONE); }else{ imgVideo.setVisibility(View.VISIBLE); imgStart.setVisibility(View.VISIBLE); imgLayout.setVisibility(View.VISIBLE); iv_commentPic.setVisibility(View.GONE); imgTwo.setVisibility(View.GONE); imgThree.setVisibility(View.GONE); imgLayout.setVisibility(View.VISIBLE); } String thumUrl = jsonObject.optString("thumUrl"); if (!TextUtils.isEmpty(thumUrl) && !TextUtils.isEmpty(fileUrl)){ Glide.with(MainApplication.context) .load(MainApplication.CDN +thumUrl) .into(imgVideo); imgVideo.setOnClickListener(v->{ CommentVideoDetailActivity.actioinStart(getContext(),jsonObject.optString("id")); }); } }else { imgVideo.setVisibility(View.GONE); imgStart.setVisibility(View.GONE); if (!fileUrl.equals("")) { iv_commentPic.setVisibility(View.VISIBLE); imgLayout.setVisibility(View.VISIBLE); Picasso.with(MainApplication.context) .load(MainApplication.url + "/zhannew/uploadfile/"+fileUrl) .into(iv_commentPic); } else { iv_commentPic.setVisibility(View.GONE); imgLayout.setVisibility(View.GONE); } if (!file2Url.equals("")) { imgTwo.setVisibility(View.VISIBLE); Picasso.with(MainApplication.context) .load(MainApplication.url + "/zhannew/uploadfile/"+file2Url) .into(imgTwo); } else { imgTwo.setVisibility(View.GONE); } if (!file3Url.equals("")) { imgThree.setVisibility(View.VISIBLE); Picasso.with(MainApplication.context) .load(MainApplication.url + "/zhannew/uploadfile/"+file3Url) .into(imgThree); } else { imgThree.setVisibility(View.GONE); } String[] fileUrlArray = null; if (!TextUtils.isEmpty(fileUrl) && !TextUtils.isEmpty(file2Url) &&!TextUtils.isEmpty(file3Url)){ fileUrlArray =new String[]{ MainApplication.url + "/zhannew/uploadfile/"+fileUrl, MainApplication.url + "/zhannew/uploadfile/"+file2Url, MainApplication.url + "/zhannew/uploadfile/"+file3Url }; }else if (!TextUtils.isEmpty(fileUrl) && !TextUtils.isEmpty(file2Url)){ fileUrlArray =new String[]{ MainApplication.url + "/zhannew/uploadfile/"+fileUrl, MainApplication.url + "/zhannew/uploadfile/"+file2Url }; }else if (!TextUtils.isEmpty(fileUrl)){ fileUrlArray =new String[]{ MainApplication.url + "/zhannew/uploadfile/"+fileUrl}; } String[] finalFileUrlArray = fileUrlArray; iv_commentPic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getContext(), ImagePagerActivity.class); // 图片url,为了演示这里使用常量,一般从数据库中或网络中获取 intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, finalFileUrlArray); intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, 0); startActivity(intent); } }); imgTwo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getContext(), ImagePagerActivity.class); // 图片url,为了演示这里使用常量,一般从数据库中或网络中获取 intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, finalFileUrlArray); intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, 1); startActivity(intent); } }); imgThree.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getContext(), ImagePagerActivity.class); // 图片url,为了演示这里使用常量,一般从数据库中或网络中获取 intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, finalFileUrlArray); intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, 2); startActivity(intent); } }); } //父级评分 String grade = jsonObject.optString("star_level"); if (grade.equals("")) { iv_pgrade.setVisibility(View.GONE); } else { double d = Double.parseDouble(grade); if (d == 0) { iv_pgrade.setVisibility(View.GONE); } else { if (d > 0 && d < 1) { iv_pgrade.setImageResource(R.drawable.icon_05xing); iv_pgrade.setVisibility(View.VISIBLE); } else if (d >= 1 && d < 1.5) { iv_pgrade.setVisibility(View.VISIBLE); iv_pgrade.setImageResource(R.drawable.icon_1xing); } else if (d >= 1.5 && d < 2) { iv_pgrade.setVisibility(View.VISIBLE); iv_pgrade.setImageResource(R.drawable.icon_15xing); } else if (d >= 2 && d < 2.5) { iv_pgrade.setVisibility(View.VISIBLE); iv_pgrade.setImageResource(R.drawable.icon_2xing); } else if (d >= 2.5 && d < 3) { iv_pgrade.setVisibility(View.VISIBLE); iv_pgrade.setImageResource(R.drawable.icon_25xing); } else if (d >= 3 && d < 3.5) { iv_pgrade.setVisibility(View.VISIBLE); iv_pgrade.setImageResource(R.drawable.icon_3xing); } else if (d >= 3.5 && d < 4) { iv_pgrade.setVisibility(View.VISIBLE); iv_pgrade.setImageResource(R.drawable.icon_35xing); } else if (d >= 4 && d < 4.5) { iv_pgrade.setVisibility(View.VISIBLE); iv_pgrade.setImageResource(R.drawable.icon_4xing); } else if (d >= 4.5 && d < 5) { iv_pgrade.setVisibility(View.VISIBLE); iv_pgrade.setImageResource(R.drawable.icon_45xing); } else { iv_pgrade.setVisibility(View.VISIBLE); iv_pgrade.setImageResource(R.drawable.icon_5xing); } } } }else{ rl_new_comment.setVisibility(View.GONE); } } catch (Exception e) { } } } }); } @Override public void onDestroy() { super.onDestroy(); MyOtto.getInstance().unregister(this); handler.removeCallbacksAndMessages(null); // Glide.with(mContext).onDestroy(); } @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); if (isVisibleToUser == true) { eteCityTime(null); } } private void getZhanInfo() { String url = MainApplication.url + "/zhannew/basic/web/index.php/zhanlist/getzhan?zhan_id=" + NewZhanDetailsActivity.zhan_id; OkHttpUtils.get().url(url).build().execute(new StringCallback() { @Override public void onError(Call call, Exception e) { } @Override public void onResponse(String response) { // Log.e(TAG, "onResponse: getZhanInfo="+response ); } }); } public String transport(String inputStr) { char arr[] = inputStr.toCharArray(); for (int i = 0; i < arr.length; i++) { if (arr[i] == ' ') { arr[i] = '\u3000'; } else if (arr[i] < '\177') { arr[i] = (char) (arr[i] + 65248); } } return new String(arr); } public static String ToDBC(String input) { char[] c = input.toCharArray(); for (int i = 0; i < c.length; i++) { if (c[i] == 12288) { c[i] = (char) 32; continue; } if (c[i] > 65280 && c[i] < 65375) c[i] = (char) (c[i] - 65248); } return new String(c); } public static String StringFilter(String str) throws PatternSyntaxException { str = str.replaceAll("【", "[").replaceAll("】", "]").replaceAll("!", "!").replace(":", ":").replace(";", ";");//替换中文标号 String regEx = "[『』]"; // 清除掉特殊字符 Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(str); return m.replaceAll("").trim(); } private static String fullWidth2halfWidth(String fullWidthStr) { if (null == fullWidthStr || fullWidthStr.length() <= 0) { return ""; } char[] charArray = fullWidthStr.toCharArray(); //对全角字符转换的char数组遍历 for (int i = 0; i < charArray.length; ++i) { int charIntValue = (int) charArray[i]; //如果符合转换关系,将对应下标之间减掉偏移量65248;如果是空格的话,直接做转换 if (charIntValue >= 65281 && charIntValue <= 65374) { charArray[i] = (char) (charIntValue - 65248); } else if (charIntValue == 12288) { charArray[i] = (char) 32; } } return new String(charArray); } @Override public void onValueSelected(Entry e, Highlight h) { } @Override public void onNothingSelected() { } private void initChart(List<ChartData> list) { mChart.getDescription().setEnabled(false); mChart.setBackgroundColor(Color.WHITE); mChart.setDrawGridBackground(false); mChart.setDrawBarShadow(false); mChart.setHighlightFullBarEnabled(false); mChart.setTouchEnabled(false); mChart.getDescription().setEnabled(false); mChart.getXAxis().setAxisLineColor(R.color.grey); mChart.getLegend().setTextColor(MainApplication.context.getResources().getColor(R.color.ui_68)); // draw bars behind lines mChart.setDrawOrder(new CombinedChart.DrawOrder[]{ CombinedChart.DrawOrder.BAR, CombinedChart.DrawOrder.BUBBLE, CombinedChart.DrawOrder.CANDLE, CombinedChart.DrawOrder.LINE, CombinedChart.DrawOrder.SCATTER }); Legend l = mChart.getLegend(); l.setWordWrapEnabled(true); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setDrawGridLines(true); leftAxis.setAxisLineColor(R.color.grey); leftAxis.setTextColor(MainApplication.context.getResources().getColor(R.color.ui_68)); leftAxis.setAxisMinimum(0); // this replaces setStartAtZero(true) leftAxis.setGranularity(1); mChart.getAxisRight().setEnabled(false); XAxis xAxis = mChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setAxisLineColor(R.color.grey); xAxis.setTextColor(MainApplication.context.getResources().getColor(R.color.ui_68)); xAxis.setAxisMinimum(0f); xAxis.setAxisMaximum(8f); xAxis.setGranularity(1); List<String> date = new ArrayList<>(); List<Integer> num = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { date.add(list.get(i).getStart_time()); num.add(Integer.parseInt(list.get(i).getCount())); } final String[] mDays = (String[]) date.toArray(new String[list.size()]); xAxis.setValueFormatter(new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { return mDays[(int) value % mDays.length]; } }); CombinedData data = new CombinedData(); data.setData(generateLineData(num)); xAxis.setAxisMaximum(data.getXMax()); mChart.setData(data); mChart.invalidate(); } private LineData generateLineData(List<Integer> num) { LineData d = new LineData(); Integer[] datas = (Integer[]) num.toArray(new Integer[num.size()]); ArrayList<Entry> entries = new ArrayList<Entry>(); for (int index = 0; index < datas.length; index++) entries.add(new Entry(index, datas[index])); LineDataSet set = new LineDataSet(entries, "该站点7日内充电情况(单位:次)"); set.setColor(MainApplication.context.getResources().getColor(R.color.lvse)); set.setLineWidth(2.5f); set.setCircleColor(MainApplication.context.getResources().getColor(R.color.lvse)); set.setCircleRadius(5f); set.setFillColor(MainApplication.context.getResources().getColor(R.color.lvse)); set.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER); set.setDrawValues(false); // set.setCircleHoleRadius(5f); set.setAxisDependency(YAxis.AxisDependency.LEFT); d.addDataSet(set); return d; } private void getChartData() { String url = MainApplication.url + "/zhannew/basic/web/index.php/present/site?id=" + NewZhanDetailsActivity.zhan_id; OkHttpUtils.get().url(url).build().execute(new StringCallback() { @Override public void onError(Call call, Exception e) { } @Override public void onResponse(String response) { List<ChartData> data = JsonUtils.parseToObjectList(response, ChartData.class); if (data.size() > 0) { initChart(data); String todayCount = data.get(6).getCount(); tv_today_num.setText("今日已充电 " + todayCount + "次"); } } }); } public interface OnDetailsFragmentListener { void updateScanCharge(String ownPay); void scanCharge(); } public void setOnUpdateScanChargeFragmentListener(OnDetailsFragmentListener listener) { this.detailsFragmentListener = listener; } @Override public void onDestroyView() { try { loadingDialog.dismiss(); } catch (Exception e) { e.printStackTrace(); } super.onDestroyView(); } @AfterPermissionGranted(RC_TELL_PERM) public void tellTask() { if (hasTellPermission()) { // Have permission, do the thing! // Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show(); Intent intent = new Intent(); intent.setAction("android.intent.action.CALL"); intent.addCategory("android.intent.category.DEFAULT"); intent.setData(Uri.parse("tel:" + telNum)); DetailsFragment.this.startActivity(intent); } else { LogUtils.e("@@@@@@@"); // Ask for one permission EasyPermissions.requestPermissions( this, "该功能需要开启拨号权限,是否前往开启?", RC_TELL_PERM, Manifest.permission.CALL_PHONE); } } private boolean hasTellPermission() { return EasyPermissions.hasPermissions(getActivity(), Manifest.permission.CALL_PHONE); } @Override public void onPermissionsGranted(int requestCode, @NonNull @NotNull List<String> perms) { } @Override public void onPermissionsDenied(int requestCode, List<String> perms) { if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) { // TODO add by hyg20200525 new AppSettingsDialog.Builder(DetailsFragment.this).build().show(); // new AppSettingsDialog.Builder(InputCodeActivity.this, // "该功能需要开启拨号权限,是否前往开启??").build().show(); } } public static String getMD5(String content) { try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(content.getBytes()); return getHashString(digest); } catch (Exception e) { } return null; } private static String getHashString(MessageDigest digest) { StringBuilder builder = new StringBuilder(); for (byte b : digest.digest()) { builder.append(Integer.toHexString((b >> 4) & 0xf)); builder.append(Integer.toHexString(b & 0xf)); } return builder.toString().toLowerCase(); } }