Android Open Source - demo-app-android User Info Activity






From Project

Back to project page demo-app-android.

License

The source code is released under:

MIT License

If you think the Android project demo-app-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package io.rong.imkit.demo;
//www . jav  a2  s .co m
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import io.rong.imkit.RongIM;
import io.rong.imkit.view.ActionBar;
import io.rong.imlib.RongIMClient;

public class UserInfoActivity extends BaseActivity implements OnClickListener {
  private String TAG = "UserInfoActivity";
  ActionBar mActionBar;
  private Button mAddBlack;
  private TextView mUserInfo;
  String title = null;
  String userId = null;
  private Button mRemoveBlack;

    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 1:
                    mAddBlack.setVisibility(View.GONE);
                    mRemoveBlack.setVisibility(View.VISIBLE);
                    mUserInfo.setText(title+"???????????????????????" );
                    break;
                case 2:
                    mAddBlack.setVisibility(View.VISIBLE);
                    mRemoveBlack.setVisibility(View.GONE);
                    mUserInfo.setText(title );
                    break;

            }
        }
    };
  @Override
  protected int setContentViewResId() {
    return R.layout.user_info;
  }

  @Override
  protected void initView() {

    mActionBar = (ActionBar) findViewById(android.R.id.custom);
    mUserInfo = (TextView) findViewById(R.id.user_name_tv);
    mAddBlack = (Button) findViewById(R.id.add_black);
    mRemoveBlack = (Button) findViewById(R.id.remove_black);
    mActionBar.setOnBackClick(new OnClickListener() {
      @Override
      public void onClick(View v) {
        finish();
      }
    });

    if (getIntent().getExtras() != null) {
      title = getIntent().getExtras().getString("user_name");
      userId = getIntent().getExtras().getString("user_id");
      mActionBar.getTitleTextView().setText(title + "????");
    } else {
      mActionBar.getTitleTextView().setText("????");
    }

  }

  @Override
  protected void initData() {
    mAddBlack.setOnClickListener(this);
    mRemoveBlack.setOnClickListener(this);

    if (RongIM.getInstance() != null) {
            if(userId.equals(LoginActivity.mUserID) ){
                mUserInfo.setVisibility(View.GONE);
            }else {
                RongIM.getInstance().getBlacklistStatus(userId,
                        new RongIM.GetUserBlacklistCallback() {

                            @Override
                            public void onError(ErrorCode errorCode) {
                                Log.e(TAG,
                                        "-------getBlacklistStatus onError---------:"
                                                + errorCode.getMessage() + ",:" + errorCode.getValue());
                                mUserInfo.setText(errorCode + "");
                            }

                            @Override
                            public void onSuccess(RongIMClient.BlacklistStatus status) {
                                Log.e(TAG,
                                        "-------getBlacklistStatus onSuccess---------:"
                                                + status);
                                if (status == RongIMClient.BlacklistStatus.NOT_EXIT_BLACK_LIST) {
                                    mUserInfo.setText(title );

                                    mAddBlack.setVisibility(View.VISIBLE);
                                } else if (status == RongIMClient.BlacklistStatus.EXIT_BLACK_LIST) {
                                    mUserInfo.setText(title + "???????????????????????");
                                    mRemoveBlack.setVisibility(View.VISIBLE);
                                }

                            }

                        });
            }
    }
  }

  @Override
  public void onClick(View v) {
    switch (v.getId()) {
    case R.id.add_black:
      if (RongIM.getInstance() != null) {
        RongIM.getInstance().addToBlacklist(userId,
            new RongIM.OperationCallback() {

              @Override
              public void onError(ErrorCode errorCode) {
                Log.e(TAG,
                    "-------addToBlacklist onError----------:"
                        + errorCode.getMessage());  
                Log.e(TAG,
                            "-------addToBlacklist onError---------:"
                                + errorCode.getValue());
              }

              @Override
              public void onSuccess() {
                Log.e(TAG, "-------??????????--------:");

                               Message msg = Message.obtain();
                                msg.what = 1;
                                mHandler.sendMessage(msg);

                            }

            });
      }
      break;
    case R.id.remove_black:
      if (RongIM.getInstance() != null) {
        RongIM.getInstance().removeFromBlacklist(userId,
            new RongIM.OperationCallback() {

              @Override
              public void onError(ErrorCode errorCode) {
                Log.e(TAG,
                    "------- removeFromBlacklist onError-------:"
                        + errorCode);
              }

              @Override
              public void onSuccess() {
                Log.e(TAG, "-------??????????-------:");
                                Message msg = Message.obtain();
                                msg.what = 2;
                                mHandler.sendMessage(msg);
              }

            });
      }
      break;
    default:
      break;
    }

  }

}




Java Source Code List

io.rong.imkit.demo.BaseActivity.java
io.rong.imkit.demo.BaseApiActivity.java
io.rong.imkit.demo.BlackListActivity.java
io.rong.imkit.demo.BlackListAdapter.java
io.rong.imkit.demo.DefaultExceptionHandler.java
io.rong.imkit.demo.DemoActivity.java
io.rong.imkit.demo.DemoApplication.java
io.rong.imkit.demo.DemoContext.java
io.rong.imkit.demo.FunctionListAdapter.java
io.rong.imkit.demo.GroupListActivity.java
io.rong.imkit.demo.GroupListAdapter.java
io.rong.imkit.demo.LocationActivity.java
io.rong.imkit.demo.LoginActivity.java
io.rong.imkit.demo.MainActivity.java
io.rong.imkit.demo.ParcelUtils.java
io.rong.imkit.demo.RegisterActivity.java
io.rong.imkit.demo.TestFragment2Activity.java
io.rong.imkit.demo.TestFragmentActivity.java
io.rong.imkit.demo.UserInfoActivity.java
io.rong.imkit.demo.common.DemoApi.java
io.rong.imkit.demo.model.CustomerService.java
io.rong.imkit.demo.model.Status.java
io.rong.imkit.demo.model.User.java
io.rong.imkit.demo.parser.GsonArrayParser.java
io.rong.imkit.demo.parser.GsonParser.java
io.rong.imkit.demo.parser.JsonObjectParser.java
io.rong.imkit.demo.parser.RegisterParser.java
io.rong.imkit.demo.ui.BaseFrameLayout.java
io.rong.imkit.demo.ui.LoadingDialog.java
io.rong.imkit.demo.ui.WinToast.java