我的include和activity的使用

**
 * Activity基类
 *
 * @author zy
 *
 */
public class BaseActivity extends Activity {

    private Handler handler = new Handler(Looper.getMainLooper());

    private ImageView leftIe;
    private ImageView rightIe;
    private TextView  midIe;
    private ProgressDialog waitDialog;
    private AlertDialog take_phone_dlg;//call_dialog

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        take_phone_dlg = new AlertDialog.Builder(this).create();
    }

    @Override
    protected void onResume() {
        super.onResume();
        initTopLayout(this);
        setTop(leftIe,rightIe);
       // showToast("baseActivity,--->onResume");
    }
    /**
     *@author ace
     *对bar按钮操作和显示
     */
    private void setTop(ImageView leftIe, ImageView rightIe) {
        //返回按钮
        leftIe.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
        //电话按钮
        rightIe.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                showCallPhoneDlg("取消","确定");
            }
        });
    }

    /**
     *
     *@author ace
     *加载include布局
     */
    private void initTopLayout(BaseActivity bat) {
        LinearLayout layout = (LinearLayout) bat.findViewById(R.id.include_titleBar);
        if (layout==null){
            throw new RuntimeException("please inlucde layout common_title in Ur layout,and make sure the include id is @+id/include_titleBar");
        }
        this.leftIe= (ImageView) layout.findViewById(R.id.include_back_button);
        this.rightIe= (ImageView) layout.findViewById(R.id.include_phone_button);
        this.midIe= (TextView) layout.findViewById(R.id.include_header_content);
    }

    /**
     * 设置标题
     */
    public void setTitle(String text) {
        ((TextView) findViewById(R.id.include_header_content)).setText(text);
    }

    /**
     * 设置标题
     */
    public void setTitle(int resId) {
        setTitle(getResources().getString(resId));
    }
    @Override
    public void onBackPressed() {
        setResult(RESULT_OK, new Intent());
        super.onBackPressed();
    }
    /**
     *打电话
     *@author ace
     */
    private void showCallPhoneDlg(String cancle, String sure) {
        take_phone_dlg.show();
        String title = "确认拨打电话: 400-181-0011 吗?";
        take_phone_dlg.getWindow().setContentView(R.layout.dialog_photo_source);
        ((TextView) (take_phone_dlg.getWindow().findViewById(R.id.photo_source_info))).setText(title);
        ((TextView) (take_phone_dlg.getWindow().findViewById(R.id.photo_source_taking_picture))).setText(cancle);
        ((TextView) (take_phone_dlg.getWindow().findViewById(R.id.photo_source_photo_graph))).setText(sure);
        take_phone_dlg.getWindow().findViewById(R.id.photo_source_taking_picture).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                take_phone_dlg.dismiss();
            }
        });//灰

        take_phone_dlg.getWindow().findViewById(R.id.photo_source_photo_graph).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                take_phone_dlg.show();
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:4001810011"));
                if (ActivityCompat.checkSelfPermission(getApplication(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }
                startActivity(intent);
                take_phone_dlg.dismiss();
            }
        });
    }//蓝

    protected String getTextString(int resId) {
        return ((TextView) findViewById(resId)).getText().toString();
    }

    protected void setTextString(int resId, String text) {
        ((TextView) findViewById(resId)).setText(text);
    }

    public void showToast(final String message) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(BaseActivity.this, message, Toast.LENGTH_LONG).show();
            }
        });
    }
    
    public boolean isWaitDialogShow(){
      return waitDialog.isShowing();
    }
    
    public void showWaitDialog(String text) {
        waitDialog.setMessage(text);
        waitDialog.show();
    }
    
    public void showWaitDialog() {
       if(isWaitDialogShow()){
          return;
       }
        waitDialog.setMessage(getString(R.string.loading));
        waitDialog.show();
    }

    public void dismissWaitDialog() {
       if(isWaitDialogShow()){
          waitDialog.dismiss();         
       }
    }


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值