知行合一

博客园 首页 新随笔 联系 订阅 管理
  371 随笔 :: 25 文章 :: 4 评论 :: 15万 阅读

1.基类定义

复制代码
View Code
/**
 * activity基类 提供退出方法,页面标题
 * 
 * @author 
 */
public class BaseActivity extends Activity {

    public Button bt_exit;
    public TextView tv_title;
    protected AlertDialog exitDialog;// 退出提示

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        CallbinApplication.addActivity(this);
        requestWindowFeature(Window.FEATURE_NO_TITLE); //去掉标题栏
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        CallbinApplication.deleteActivity(this);
        super.onDestroy();
    }

    /**
     * 通过文字设置标题
     * 
     * @param activity
     * @param title
     */
    public void setTitle(Activity activity, String title) {
        tv_title = (TextView) activity.findViewById(R.id.tv_meeting_title);
        tv_title.setText(title);
    }

    /**
     * 通过id设置标题
     * 
     * @param activity
     * @param id
     */
    public void setTitle(Activity activity, int id) {
        tv_title = (TextView) activity.findViewById(R.id.tv_meeting_title);
        tv_title.setText(id);
    }

    /**
     * 退出应用程序方法
     * 
     * @param activity
     */
    public void exitAppcation(final Activity activity) {
        bt_exit = (Button) activity.findViewById(R.id.bt_exit);
        // 退出程序
        bt_exit.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                exitAlert(activity);
            }
        });
    }

    /**
     * 弹出退出应用对话框
     * 
     * @param activity
     */
    public void exitAlert(Activity activity) {
        AlertDialog.Builder buider = new AlertDialog.Builder(activity);
        buider.setTitle(R.string.exit_alert_title);
        buider.setMessage(R.string.exit_alert_message);
        // 点击否是什么都不做只是把对话框去掉
        buider.setNegativeButton(R.string.no_string,
                new android.content.DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        exitDialog.dismiss();
                    }
                });
        // 点击是时去掉对话框并做退出处理
        buider.setPositiveButton(R.string.yes_string,
                new android.content.DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        exitDialog.dismiss();
                        CallbinApplication.instance.onTerminate();
                    }

                });
        exitDialog = buider.create();
        exitDialog.show();
    }
    
    /**
     * Http请求返回值与处理是否是服务器正常相应回来的值
     * @param result 返回值的String字符串
     * @return result的返回值不是Http抛异常返回的 即result不等于null,“” “timeOut” ,"error"返回ture
     */
    protected boolean CheckHttpResponseJson(Context context,String result){
        if(result==null){
            Toast.makeText(context,
                    R.string.response_fail,
                    Toast.LENGTH_SHORT).show();
            return false;
        }else if(Constant.HTTPPARAMSNULL.equals(result)){
            Toast.makeText(context, R.string.url_null_error, 0).show();
        }else if(Constant.HTTPTIMEOUT.equals(result)){
            Toast.makeText(context, R.string.connect_timeout_exception,
                    Toast.LENGTH_SHORT).show();
            return false;
        }else if(Constant.HTTPERROR.equals(result)){
             Toast.makeText(context, R.string.sys_net_exception,
                     Toast.LENGTH_SHORT).show();
            return false;
        }else if(Constant.HTTP404.equals(result)){
             Toast.makeText(context, R.string.http_404,
                     Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }
}
复制代码


 

posted on   callbin  阅读(1095)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示