** * 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(); } } }
我的include和activity的使用
最新推荐文章于 2020-03-03 09:46:47 发布