PromptDialog.java 3.07 KB
package com.cnlive.goldenline.ui.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cnlive.goldenline.R;

/**
 * <br/> ****************************************************
 * <br/> Project Name : goldenline-android3.0
 * <br/> Create Date : 2017/3/18 0018
 * <br/> Author : MaChao
 * <br/> Msg :
 * <br/> Remark :
 * <br/> ****************************************************
 */
public class PromptDialog extends Dialog implements View.OnClickListener {

    private Context mContext;
    private ClickListener listener;
    private TextView mVoteResult;
    private TextView mVoteInfo;
    private ImageButton mBtnRoger;

    private LinearLayout mPromptLayout;

    private boolean isVoteSuccess;

    private String mVoteInfoStr;

    public PromptDialog(Context context) {
        super(context);
        this.mContext = context;
    }

    public PromptDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
    }

    protected PromptDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.mContext = context;
    }

    public interface ClickListener {
        void onOk();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_dialog_prompt);
        initView();
        if (isVoteSuccess){
            voteSuccessView();
        }else {
            voteFailerView(mVoteInfoStr);
        }
    }

    private void voteFailerView(String voteInfo) {
        mPromptLayout.setBackgroundResource(R.mipmap.vote_failer);
        mVoteResult.setText(mContext.getResources().getString(R.string.vote_failer));
        mVoteInfo.setText(voteInfo);
    }

    private void voteSuccessView() {
        mPromptLayout.setBackgroundResource(R.mipmap.vote_success);
        mVoteResult.setText(mContext.getResources().getString(R.string.vote_success));
        mVoteInfo.setText(mContext.getResources().getString(R.string.vote_success_info));

    }

    private void initView() {
        mVoteResult = (TextView) findViewById(R.id.act_vote_result);
        mVoteInfo = (TextView) findViewById(R.id.act_vote_info);
        mBtnRoger = (ImageButton) findViewById(R.id.btn_roger);
        mPromptLayout = (LinearLayout) findViewById(R.id.prompt_layput);
        mBtnRoger.setOnClickListener(this);

    }


    public void setVoteStatus(boolean isVoteSuccess,String voteInfo) {
        this.isVoteSuccess = isVoteSuccess;
        this.mVoteInfoStr = voteInfo;
    }

    public void setClickListener(ClickListener listener) {
        this.listener = listener;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_roger:
                if (listener != null)
                    listener.onOk();
                break;
        }
        dismiss();
    }
}