欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Android自定義view倒計(jì)時(shí)60秒

一個(gè)簡單的自定義view。在里面封裝了時(shí)間的倒計(jì)時(shí),以及距離現(xiàn)在時(shí)間的時(shí)間計(jì)算

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信平臺(tái)小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了西陵免費(fèi)建站歡迎大家使用!

public class TimerTextView extends LinearLayout{
  // 時(shí)間變量
  private long second;
  private TextView tv_Time;
  private TextView tv_Unit;
  RefreshCallBack refreshCallBack;
 
  public TimerTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    initView(context);
  }
 
  public TimerTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initView(context);
  }
 
  public TimerTextView(Context context) {
    super(context);
    initView(context);
  }
 
  private void initView(Context context) {
    // 加載布局
    LayoutInflater.from(context).inflate(R.layout.timer_text_view, this);
    tv_Time = (TextView) findViewById(R.id.countdown_time);
    tv_Unit = (TextView) findViewById(R.id.countdown_unit);
  }
 
  @Override
  protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    // 在控件被銷毀時(shí)移除消息
    handler.removeMessages(0);
  }
 
  private boolean isRun = true; // 是否啟動(dòng)了
  private Handler handler = new Handler(Looper.getMainLooper()) {
    @Override
    public void handleMessage(Message msg) {
      switch (msg.what) {
        case 0:
          if (isRun) {
            if (second > 0) {
              second = second - 1;
              handler.sendEmptyMessageDelayed(0, 1000);
            }else{
              if(null != refreshCallBack){
                refreshCallBack.refreshCallBack(true);
                isRun = false;
              }
            }
          }
          break;
      }
    }
  };
 
 
  public boolean isRun() {
    return isRun;
  }
 
  /**
   * 開始計(jì)時(shí)
   */
  public void start() {
    isRun = true;
    handler.removeMessages(0);
    handler.sendEmptyMessage(0);
  }
 
  /**
   * 結(jié)束計(jì)時(shí)
   */
  public void stop() {
    isRun = false;
  }
 
  public void diffTime(String endTime) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
    String startTime = sdf.format(new Date());
    String format = "yyyy-MM-dd hh:mm:ss";
    //按照傳入的格式生成一個(gè)simpledateformate對(duì)象
    SimpleDateFormat sd = new SimpleDateFormat(format);
 
    long nd = 1000 * 24 * 60 * 60;//一天的毫秒數(shù)
    long nh = 1000 * 60 * 60;//一小時(shí)的毫秒數(shù)
    long nm = 1000 * 60;//一分鐘的毫秒數(shù)
    long ns = 1000;//一秒鐘的毫秒數(shù)long diff;try {
    //獲得兩個(gè)時(shí)間的毫秒時(shí)間差異
    long diff = 0;
    try {
      diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
    } catch (ParseException e) {
      e.printStackTrace();
    }
    if (diff < 0) {
      if(null != refreshCallBack){
        refreshCallBack.showCallBack(false);
      }
      return ;
    } else {
      if(null != refreshCallBack){
        refreshCallBack.showCallBack(true);
      }
      long day = diff / nd;//計(jì)算差多少天
      if (day > 0) {
        tv_Time.setText(String.valueOf(day));
        tv_Unit.setText("天");
      } else {
        long hour = diff % nd / nh;//計(jì)算差多少小時(shí)
        if (hour > 0) {
          tv_Time.setText(String.valueOf(hour));
          tv_Unit.setText("小時(shí)");
        } else {
          long min = diff % nd % nh / nm;//計(jì)算差多少分鐘
          if (min > 0) {
            tv_Time.setText(String.valueOf(min));
            tv_Unit.setText("分鐘");
          } else {
            second = diff%nd%nh%nm/ns;//計(jì)算差多少秒//輸出結(jié)果
//            if(min > 0){
//              stringBuffer.append(sec+"秒");
//            }
            handler.removeMessages(0);
            handler.sendEmptyMessage(0);
 
            tv_Unit.setText("即將開始");
            tv_Time.setVisibility(GONE);
          }
        }
      }
    }
  }
 
  public void setTextViewSize(int size){
    if(null != tv_Time){
      tv_Time.setTextSize(size);
    }
    if(null != tv_Unit){
      tv_Unit.setTextSize(size);
    }
  }
 
  public void setTextViewSpace(String type){
    if("Big".equals(type)){
      LinearLayout.LayoutParams lp2 = (LayoutParams) tv_Time.getLayoutParams();
      lp2.setMargins(0, 0, DensityUtil.dip2px(tv_Time.getContext(), 12), 0);
      tv_Time.setLayoutParams(lp2);     
    tv_Time.setBackground(getResources().getDrawable(R.drawable.bg_video_count_down));
    }else if("Middle".equals(type)){
      tv_Time.setPadding(12, 0, 12, 0);
      LinearLayout.LayoutParams lp2 = (LayoutParams) tv_Time.getLayoutParams();
      lp2.setMargins(0, 0,12, 0);
      tv_Time.setLayoutParams(lp2);
    }else {
      tv_Time.setPadding(8, 0, 8, 0);
      LinearLayout.LayoutParams lp2 = (LayoutParams) tv_Time.getLayoutParams();
      lp2.setMargins(0, 0, 8, 0);
      tv_Time.setLayoutParams(lp2);
    }
  }
 
  public void setRefreshCallBack(RefreshCallBack refreshCallBack){
    this.refreshCallBack = refreshCallBack;
  }
 
  public interface RefreshCallBack {
    public void refreshCallBack(boolean flag);
    public void showCallBack(boolean flag);
  }
 
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。 

標(biāo)題名稱:Android自定義view倒計(jì)時(shí)60秒
網(wǎng)站URL:http://aaarwkj.com/article46/jjhihg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈微信小程序、虛擬主機(jī)、服務(wù)器托管用戶體驗(yàn)、全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)
亚洲一区成人精品在线| 国产欧美一区二区另类精品| 在线蜜臀av中文字幕| 成人av免费高清在线| 午夜精品三级一区二区三区| 日韩夫妻精品熟妇人妻一区| 国产成人精品一二三四区| 色综合一区二区日本韩国亚洲| 麻豆亚洲av熟女国产| 最新免费观看男女啪啪视频 | 成人午夜激情在线观看| 中文字幕在线五月婷婷| 少妇欧美日韩精品在线观看| 国产免费一区二区福利| 欧美高清成人一区二区三区| 加藤桃香中文字幕在线| 91激情黑丝在线观看| 成人精品国产一区二区| 国产日韩欧美另类专区| 国产一级黄色免费大片| 精品亚洲第一区二区免费在线| 成人爱爱免费观看视频| 亚洲美女高潮久久久久久久久| 国产欧美激情一区二区| 女同欲望一区二区三区久久| 成人福利在线观看免费视频| 亚洲精品aa片在线观看国产| 欧美另类不卡在线观看| 欧美性色黄大片人与善| 国产夫妻自拍在线视频| 欧美一级黄色免费电影| 中文字幕二区三区av| 久久国产精品99亚洲| 亚洲天堂国产成人精品| 久久亚洲中文字幕精品一区四区| 国产偷自一区二区三区| 久久精品人妻麻豆尤物| 欧美日韩电影一区二区三区| 狠狠综爱五月天的婷婷| 少妇人妻精品一区三区二区| 四虎国产最新在线免费|