package com.electric.chargingpile.view; import android.content.Context; import android.text.Html; import android.text.TextUtils; import android.util.Log; import android.view.Display; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; import com.electric.chargingpile.R; import static android.text.Html.FROM_HTML_MODE_LEGACY; /** * Created by demon on 2017/5/26. */ public class SignInDialog { private Context context; private android.app.Dialog dialog; private Display display; private TextView tv_num, tv_third, tv_second, tv_first, tv_now_temperature, tv_du, tv_w, tv_pm, tv_city,tv_2; private LinearLayout dialog_bg; public SignInDialog(Context context) { this.context = context; WindowManager windowManager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); display = windowManager.getDefaultDisplay(); } public SignInDialog builder() { // 获取Dialog布局 View view = LayoutInflater.from(context).inflate( R.layout.item_signin, null); // 获取自定义Dialog布局中的控件 dialog_bg = (LinearLayout) view.findViewById(R.id.dialog_bg); tv_num = (TextView) view.findViewById(R.id.tv_num); tv_2 = (TextView) view.findViewById(R.id.tv_2); tv_third = (TextView) view.findViewById(R.id.tv_third); tv_second = (TextView) view.findViewById(R.id.tv_second); tv_first = (TextView) view.findViewById(R.id.tv_first); tv_now_temperature = (TextView) view.findViewById(R.id.tv_now_temperature); tv_du = (TextView) view.findViewById(R.id.tv_du); tv_w = (TextView) view.findViewById(R.id.tv_w); tv_pm = (TextView) view.findViewById(R.id.tv_pm); tv_pm.setVisibility(View.GONE); tv_city = (TextView) view.findViewById(R.id.tv_city); // 定义Dialog布局和参数 dialog = new android.app.Dialog(context, R.style.AlertDialogStyle); dialog.setContentView(view); // 调整dialog背景大小 dialog_bg.setLayoutParams(new FrameLayout.LayoutParams((int) (display .getWidth() * 0.85), LinearLayout.LayoutParams.WRAP_CONTENT)); return this; } public SignInDialog setTitle(String log_day, String score, String city) { String third = "", second = "", first = ""; if (TextUtils.isEmpty(log_day)){ log_day="1"; } int length = log_day.length(); char words[] = log_day.toCharArray(); if (length == 1) { third = ""; second = ""; first = String.valueOf(words[0]); } else if (length == 2) { third = ""; second = String.valueOf(words[0]); first = String.valueOf(words[1]); } else if (length == 3) { third = String.valueOf(words[0]); second = String.valueOf(words[1]); first = String.valueOf(words[2]); } if (third.equals("")) { tv_third.setText("0"); } else { tv_third.setText(third); } if (second.equals("")) { tv_second.setText("0"); } else { tv_second.setText(second); } tv_city.setText(city); tv_city.setVisibility(View.VISIBLE); if (first.equals("")) { tv_first.setText("0"); } else { tv_first.setText(first); } int intLogDay = Integer.parseInt(log_day); int i1 = intLogDay / 7;//获取倍数 i1 = i1 * 7 ; if (i1 < intLogDay){ i1 += 7; } int i2 = i1 - intLogDay; //差值 if (score != null && !score.equals("")) { tv_num.setText(Html.fromHtml("今天签到获得 "+score+" 个充电币", FROM_HTML_MODE_LEGACY)); if ( i2 > 0 ){ tv_2.setText("还有"+ i2 +"天获得充电优惠哦~"); } } else { tv_num.setText(""); } if (i2 == 0){ tv_num.setText("充电订单折扣优惠券已到账"); tv_2.setText("充电订单八折"); } return this; } public SignInDialog setCancelable(boolean cancel) { dialog.setCancelable(cancel); dialog.setCanceledOnTouchOutside(cancel); return this; } public SignInDialog setWeatherUI(String now_temperature, String now_weather, String temperature) { tv_now_temperature.setText(now_temperature); tv_du.setText("℃"); tv_w.setText(now_weather + " " + temperature + " ℃"); return this; } private String pmLevel(int pm) { String pmString = ""; if (pm < 35) { pmString = "优"; } else if (pm < 75) { pmString = "良"; } else if (pm < 115) { pmString = "轻度污染"; } else if (pm < 150) { pmString = "中度污染"; } else if (pm < 250) { pmString = "重度污染"; } else { pmString = "严重污染"; } return pmString; } public void show() { dialog.show(); } }