Ejemplo n.º 1
0
  // 聊天对话框显示
  private void identityJudge() {
    BmobQuery<MyUser> query = new BmobQuery<MyUser>();
    // 判断是否有缓存,该方法必须放在查询条件(如果有的话)都设置完之后再来调用才有效,就像这里一样。
    //        boolean isCache = query.hasCachedResult(mycontext, MyUser.class);
    //        if (isCache) {
    //            query.setCachePolicy(BmobQuery.CachePolicy.CACHE_ELSE_NETWORK);    //
    // 如果有缓存的话,则设置策略为CACHE_ELSE_NETWORK
    //        } else {
    //            query.setCachePolicy(BmobQuery.CachePolicy.NETWORK_ELSE_CACHE);    //
    // 如果没有缓存的话,则设置策略为NETWORK_ELSE_CACHE
    //        }
    query.getObject(
        mycontext,
        BmobUser.getCurrentUser(mycontext).getObjectId(),
        new GetListener<MyUser>() {

          @Override
          public void onSuccess(MyUser object) {
            // TODO Auto-generated method stub
            if (object.getType().equals("2")) {
              container_tochat.setVisibility(View.VISIBLE);
              btn_beaugur.setVisibility(View.GONE);
            } else {
              container_tochat.setVisibility(View.GONE);
              //                    btn_beaugur.setVisibility(View.VISIBLE);
            }
          }

          @Override
          public void onFailure(int code, String arg0) {}
        });
  }
Ejemplo n.º 2
0
  private void loadDataByNet() {
    BmobQuery<Content> query = new BmobQuery<>();
    query.getObject(
        DetailActivity.this,
        mContent.getObjectId(),
        new GetListener<Content>() {
          @Override
          public void onSuccess(Content content) {
            setData(content);
            // 把数据缓存到本地
            SaveCacheAsyncTask savecaheTask =
                new SaveCacheAsyncTask(
                    DetailActivity.this,
                    content,
                    CacheHelper.CONTENT_CACHE_KEY + mContent.getObjectId());
            savecaheTask.execute();
            mLoadingLayout.setLoadingLayout(LoadingLayout.HIDE_LAYOUT);
            mScrollViewEx.setVisibility(View.VISIBLE);
          }

          @Override
          public void onFailure(int i, String s) {
            if (mLoadingLayout.getState() == LoadingLayout.STATE_REFRESH) {
              mLoadingLayout.setLoadingLayout(LoadingLayout.NETWORK_ERROR);
            }
          }
        });
  }
Ejemplo n.º 3
0
  private void initData() {
    if (null != objectId) {
      BmobQuery<BUser> query = new BmobQuery<>();
      query.getObject(
          this,
          objectId,
          new GetListener<BUser>() {
            @Override
            public void onSuccess(BUser bUser) {
              if (bUser != null) {

                bundle = new Bundle();
                bundle.putSerializable("bUser", bUser);

                if (TextUtils.isEmpty(bUser.getFigureurl())) {
                  ImageLoader.getInstance()
                      .displayImage(
                          bUser.getUserPhoto().getFileUrl(UserInfoActivity.this), iv_userphoto);
                } else {
                  ImageLoader.getInstance().displayImage(bUser.getFigureurl(), iv_userphoto);
                }

                tv_nick.setText(bUser.getNick());
                tv_nick.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/test.ttf"));
                tv_depart.setText(bUser.getDepart());
                tv_depart.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/test.ttf"));

                if (!TextUtils.isEmpty(bUser.getEmail())) {
                  tv_email.setText(bUser.getEmail());
                } else {
                  tv_email.setText("请完善邮箱信息");
                }

                if (!TextUtils.isEmpty(bUser.getMobilePhoneNumber())) {
                  tv_tel.setText(bUser.getMobilePhoneNumber());
                } else {
                  tv_tel.setText("请完善手机号信息");
                }
                tv_name.setText(bUser.getUsername());
              }
            }

            @Override
            public void onFailure(int i, String s) {}
          });
    }
  }
Ejemplo n.º 4
0
  public void serachDate() {
    // 查找Person表里面id为6b6c11c537的数据
    BmobQuery<Person> bmobQuery = new BmobQuery<Person>();
    bmobQuery.getObject(
        this,
        "f36c5e3a36",
        new GetListener<Person>() {
          @Override
          public void onSuccess(Person object) {
            ToastUtils.setToastLong(MainActivity.this, "查询成功" + object.getName());
          }

          @Override
          public void onFailure(int code, String msg) {
            ToastUtils.setToastLong(MainActivity.this, "查询失败:" + msg);
          }
        });
  }
Ejemplo n.º 5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dstu);
    imageview = (ImageView) findViewById(R.id.stuimage);
    stuname = (TextView) findViewById(R.id.stuname);
    stusex = (TextView) findViewById(R.id.stusex);
    stuphone = (TextView) findViewById(R.id.stuphone);
    stuaddress = (TextView) findViewById(R.id.stuaddress);
    sturole = (TextView) findViewById(R.id.sturole);
    stuintro = (TextView) findViewById(R.id.stuintro);
    stuid = (TextView) findViewById(R.id.stuid);
    Intent intent = getIntent();
    String id = intent.getStringExtra("id");
    BmobQuery<Student> query = new BmobQuery<Student>();
    query.getObject(
        DstuActivity.this,
        id,
        new GetListener<Student>() {
          @Override
          public void onFailure(int arg0, String arg1) {
            // 班级中没有该学生
          }

          @Override
          public void onSuccess(Student arg0) {
            if (arg0.getIcon() != null) {
              // 下载头像
              arg0.getIcon().loadImage(DstuActivity.this, imageview);
            }
            // 加载基本信息
            stuname.setText("姓名:" + arg0.getUsername());
            String sex = arg0.isSex() ? "男" : "女";
            stusex.setText("性别:" + sex);
            stuid.setText("学号:" + arg0.getStudentId());
            stuaddress.setText("籍贯:" + arg0.getAddress());
            stuphone.setText(arg0.getPhone());
            stuintro.setText("个人简介:\n" + arg0.getIntro());
            sturole.setText("角色:" + (arg0.getRole() == 0 ? "普通用户" : "管理员"));
          }
        });
  }
Ejemplo n.º 6
0
  private void judgeAugur() {
    BmobQuery<MyUser> query = new BmobQuery<MyUser>();
    query.setCachePolicy(BmobQuery.CachePolicy.CACHE_THEN_NETWORK);
    query.getObject(
        mycontext,
        BmobUser.getCurrentUser(mycontext).getObjectId(),
        new GetListener<MyUser>() {

          @Override
          public void onSuccess(MyUser object) {
            // TODO Auto-generated method stub
            if (object.getType().equals("2")) {
              // 不能重复申请成为大师
              mycontext.toast("您已经是大师,不能重复申请");
              Log.e("datas", "MeFragment 判断type" + object.getType());
              btn_beaugur.setClickable(false);
            }
          }

          @Override
          public void onFailure(int code, String arg0) {}
        });
    initDatas();
  }
Ejemplo n.º 7
0
  @Override
  public View bindView(int arg0, View convertView, ViewGroup arg2) {
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.item_friendsstatus, null);
    }

    final String[] islike = new String[1]; // 用来记录是否赞过这条微博
    islike[0] = "false";
    final Blog blog = getList().get(arg0);
    final Context context = convertView.getContext();
    TextView brief = ViewHolder.get(convertView, R.id.edittext);
    TextView time = ViewHolder.get(convertView, R.id.time);
    final TextView name = ViewHolder.get(convertView, R.id.name);
    final TextView num = ViewHolder.get(convertView, R.id.num);
    final RoundImageView head = ViewHolder.get(convertView, R.id.head);
    ImageView photo = ViewHolder.get(convertView, R.id.photo);
    final ImageView like = ViewHolder.get(convertView, R.id.like);
    final User user = BmobUser.getCurrentUser(context, User.class);
    like.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            if (islike[0].equals("false")) {
              // 将当前用户添加到Blog表中的likes字段值中,表明当前用户喜欢该帖子
              BmobRelation relation = new BmobRelation();
              // 将当前用户添加到多对多关联中
              relation.add(user);
              // 多对多关联指向`blog`的`likes`字段
              blog.setLikes(relation);
              blog.update(
                  context,
                  new UpdateListener() {

                    @Override
                    public void onSuccess() {
                      likesnum++;
                      islike[0] = "true";
                      num.setText(likesnum + "");
                    }

                    @Override
                    public void onFailure(int arg0, String arg1) {}
                  });
            } else {
              showTag("你已赞过这条动态!", Effects.standard, R.id.friends_status);
            }
          }
        });

    String photouri = blog.getPhoto().getFileUrl(convertView.getContext());
    if (photouri != null && !photouri.equals("")) {
      ImageLoader.getInstance().displayImage(photouri, photo, ImageLoadOptions.getOptions());
    } else {
      photo.setImageResource(R.drawable.defalutimage);
    }

    // 因为无法直接get到user的头像,所以需要到网络去拿
    String uID = blog.getAuthor().getObjectId();

    BmobQuery<User> query = new BmobQuery<User>();
    query.getObject(
        convertView.getContext(),
        uID,
        new GetListener<User>() {

          @Override
          public void onFailure(int arg0, String arg1) {}

          @Override
          public void onSuccess(User arg0) {
            headuri = arg0.getAvatar();
            if (headuri != null && !headuri.equals("")) {
              ImageLoader.getInstance().displayImage(headuri, head, ImageLoadOptions.getOptions());
            } else {
              head.setImageResource(R.drawable.default_head);
            }
            name.setText(arg0.getUsername());
          }
        });
    // 查询喜欢这个帖子的所有用户,因此查询的是用户表
    BmobQuery<User> query2 = new BmobQuery<User>();
    // likes是Blog表中的字段,用来存储所有喜欢该帖子的用户
    query2.addWhereRelatedTo("likes", new BmobPointer(blog));
    query2.findObjects(
        convertView.getContext(),
        new FindListener<User>() {

          @Override
          public void onSuccess(List<User> object) {
            likesnum = object.size();
            num.setText(likesnum + "");
            for (int i = 0; i < object.size(); i++) {
              if (object.get(i).getObjectId().equals(user.getObjectId())) {
                islike[0] = "true";
                like.setImageResource(R.drawable.youlike);
              }
            }
          }

          @Override
          public void onError(int code, String msg) {}
        });
    brief.setText(blog.getBrief());
    time.setText(blog.getCreatedAt());
    return convertView;
  }