Search in sources :

Example 1 with Province

use of com.shiqkuangsan.mycustomviews.bean.Province in project CustomViews by AndroidStudy233.

the class XUtilsActivity method sendGetUseArr.

/**
 * 演示
 * 如果一个接口需要传一个对象或者一个数组. 就得把它转成json数据, 然后用setBodyContent
 */
private void sendGetUseArr() {
    SimpleRequestParams params = new SimpleRequestParams.Builder(Constant.mlnx_province_url).build();
    params.setAsJsonContent(true);
    String jsonString = JSON.toJSONString(new Province());
    String jString1 = JSON.toJSONString(new ArrayList<Province>());
    String jString2 = JSON.toJSONString(new String[] { "233" });
    params.setBodyContent(jsonString);
    MySimplexUtil.sendGet(params, new MySimplexUtil.SimpleRequstCallBack<List<Province>>() {

        @Override
        public void onSuccess(List<Province> result) {
            if (!isDbInited)
                list = result;
            if (result != null && result.size() > 0)
                showToast(result.get(new Random().nextInt(result.size() - 1)).toString());
        }

        @Override
        public void onError(Throwable ex, boolean isOnCallback) {
            super.onError(ex, isOnCallback);
        }
    });
}
Also used : SimpleRequestParams(com.shiqkuangsan.mycustomviews.utils.MySimplexUtil.SimpleRequestParams) Province(com.shiqkuangsan.mycustomviews.bean.Province) Random(java.util.Random) MySimplexUtil(com.shiqkuangsan.mycustomviews.utils.MySimplexUtil) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Province

use of com.shiqkuangsan.mycustomviews.bean.Province in project CustomViews by AndroidStudy233.

the class XUtilsActivity method processOnclick.

// 事件注解,记住方法修饰必须为private, 默认type为OnClickListener,你可以自定义
// @Event(value = {R.id.btn_xutils_sendget, R.id.btn_xutils_sendpost}, type = View.OnClickListener.class)
@Event(value = { R.id.btn_xutils_sendget, R.id.btn_xutils_sendpost, R.id.btn_xutils_upload, R.id.btn_xutils_download, R.id.btn_xutils_image, R.id.btn_xutils_circle, R.id.btn_xutils_gif, btn_xutils_db, R.id.btn_xutils_dbadd, R.id.btn_xutils_dbupdate, R.id.btn_xutils_dbdelete, R.id.btn_xutils_dbquery })
private void processOnclick(View view) {
    switch(view.getId()) {
        // xUtils发送get请求
        case R.id.btn_xutils_sendget:
            sendGetRequest();
            break;
        case R.id.btn_xutils_sendpost:
            showToast("和get请求使用起来都一样");
            break;
        // 上传文件
        case R.id.btn_xutils_upload:
            upploadFile();
            break;
        // 下载文件
        case R.id.btn_xutils_download:
            downloadFile();
            break;
        // 展示图片
        case R.id.btn_xutils_image:
            MySimplexUtil.loadImage(iv_xutils_display, Constant.display_image_url, MySimplexUtil.getSimpleImageOptions(8), null);
            // MySimplexUtil.getSimpleImageOptions(), null);// 加载本地图片,记得前缀file://,最好用Enviroment.get表示sdcard
            break;
        // 展示圆形图片
        case R.id.btn_xutils_circle:
            MySimplexUtil.loadImage(iv_xutils_display, Constant.display_circlr_image_url, MySimplexUtil.getSimpleCircleImageOptions(), null);
            break;
        // 展示gif图片
        case R.id.btn_xutils_gif:
            MySimplexUtil.loadImage(iv_xutils_display, Constant.display_gif_url, MySimplexUtil.getSimpleImageOptions(8), null);
            break;
        // 创建数据库
        case btn_xutils_db:
            manager = SimpleDbHelper.getInstance(this, "xutils.db");
            if (list == null)
                showToast("请先get一波数据");
            else
                isDbInited = true;
            break;
        case R.id.btn_xutils_dbadd:
            if (isDbInited)
                x.task().post(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            // 先删除所有再存入
                            manager.delete(Province.class);
                            for (int i = 0; i < list.size(); i++) {
                                Province province = list.get(i);
                                manager.save(province);
                                MyLogUtil.debug("存入省: " + province.name);
                            }
                            showToast("你重新存入了" + list.size() + "个省");
                        } catch (DbException e1) {
                            e1.printStackTrace();
                        }
                    }
                });
            break;
        case R.id.btn_xutils_dbupdate:
            if (isDbInited) {
                try {
                    Province last = manager.selector(Province.class).where("id", "=", "30").findFirst();
                    MyLogUtil.debug("原名: " + last.name);
                    // 方式1:找到bean类设置新属性,然后告诉manager你改了那些属性
                    last.name = "日本省";
                    manager.update(last, "name");
                    // 方式2:你想改谁?键值对告诉我怎么改
                    // manager.update(Province.class, WhereBuilder.b("id", "=", "30"), new KeyValue("name", "日本省"));
                    Province now = manager.selector(Province.class).where("id", "=", "30").findFirst();
                    MyLogUtil.debug("改完后的名字: " + now.name);
                    showToast("成功改掉了一个省的名字");
                } catch (DbException e1) {
                    e1.printStackTrace();
                }
            }
            break;
        case R.id.btn_xutils_dbquery:
            if (isDbInited) {
                x.task().post(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            List<Province> provinces = manager.selector(Province.class).where("id", ">=", 30).findAll();
                            showToast("你查到了" + provinces.size() + "个省");
                            for (int i = 0; i < provinces.size(); i++) {
                                Province province = provinces.get(i);
                                MyLogUtil.debug(province.toString());
                            }
                        } catch (DbException e1) {
                            e1.printStackTrace();
                        }
                    }
                });
            }
            break;
        case R.id.btn_xutils_dbdelete:
            if (isDbInited)
                try {
                    manager.delete(Province.class);
                    showToast("全部删干净了,重新初始化吧");
                    // 删完数据为了防止瞎几把按finish
                    finish();
                } catch (DbException e1) {
                    e1.printStackTrace();
                }
            break;
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Province(com.shiqkuangsan.mycustomviews.bean.Province) DbException(org.xutils.ex.DbException) Event(org.xutils.view.annotation.Event)

Aggregations

Province (com.shiqkuangsan.mycustomviews.bean.Province)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MySimplexUtil (com.shiqkuangsan.mycustomviews.utils.MySimplexUtil)1 SimpleRequestParams (com.shiqkuangsan.mycustomviews.utils.MySimplexUtil.SimpleRequestParams)1 Random (java.util.Random)1 DbException (org.xutils.ex.DbException)1 Event (org.xutils.view.annotation.Event)1