Android Open Source - demo-app-android Main 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;
/*from   ww w. jav  a  2  s  . com*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Process;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;


import io.rong.imkit.RongIM;
import io.rong.imkit.view.ActionBar;
import io.rong.imkit.view.AlterDialog;
import io.rong.imlib.RongIMClient;
import io.rong.message.RichContentMessage;

public class MainActivity extends BaseActivity implements AdapterView.OnItemClickListener, View.OnClickListener {

    private static final String TAG = "FunctionListActivity";
    private ListView mListView;
    private FunctionListAdapter mFunctionListAdapter;
    private Button mLogout;
    private ActionBar mAction;
    private int numbermessage = 0;
    private ImageView mImageView;

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

    @Override
    protected void initView() {
        numbermessage = RongIM.getInstance().getTotalUnreadCount();
        DemoContext.getInstance().receiveMessage();

        mListView = getViewById(android.R.id.list);
        View headerView = LayoutInflater.from(this).inflate(
                R.layout.view_list_header, null);
        mListView.addHeaderView(headerView);
        mLogout = getViewById(android.R.id.button1);
        mLogout.setOnClickListener(this);
        mAction = getViewById(R.id.action_bar);
        mImageView = mAction.getBackView();
        mImageView.setVisibility(View.GONE);

    }

    @Override
    public void onResume() {
        super.onResume();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("send_noread_message");
        this.registerReceiver(new MyBroadcastReciver(), intentFilter);

        numbermessage = RongIM.getInstance().getTotalUnreadCount();
        initData();
    }

    private class MyBroadcastReciver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals("send_noread_message")) {
                numbermessage = intent.getIntExtra("rongCloud", -1);
                initData();
            }
        }

    }

    @Override
    protected void initData() {

        String[] titleNameArray = this.getResources().getStringArray(
                R.array.function_list);
        mFunctionListAdapter = new FunctionListAdapter(this, titleNameArray,
                numbermessage);
        mListView.setAdapter(mFunctionListAdapter);
        mFunctionListAdapter.notifyDataSetChanged();

        mListView.setOnItemClickListener(this);
        mAction.setOnBackClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        if (position == 1) {

            /**
             * ???????
             *
             * ?????????????????????????????????????????????????????????????????????????????
             *
             * API??? http://docs.rongcloud.cn/android.html
             */
            if (RongIM.getInstance() != null) {
                RongIM.getInstance().startConversationList(this);
            }

        } else if (position == 2) {
            RongIM.getInstance().startCustomerServiceChat(this, "kefu114", "???");

        } else if (position == 3) {


            String content = "????????10?14?? ????????????14??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????6???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????";
            String title = "????????10?14??,????????????????????????????";
            String url = "http://img2.cache.netease.com/photo/0003/2014-10-15/900x600_A8J6CVA400AJ0003.jpg";
            RichContentMessage imageTextMessage = new RichContentMessage(title, content, url);
            imageTextMessage.setExtra("????????????????????URI,????????????????????????????");

            RongIM.getInstance().sendMessage(RongIMClient.ConversationType.PRIVATE, "11", imageTextMessage, new RongIMClient.SendMessageCallback() {

                        @Override
                        public void onSuccess(int messageId) {

                        }

                        @Override
                        public void onError(int messageId, ErrorCode errorCode) {

                        }

                        @Override
                        public void onProgress(int messageId, int percent) {

                        }
                    }
            );

            RongIM.getInstance().sendMessage(RongIMClient.ConversationType.CUSTOMER_SERVICE, "kefu114", imageTextMessage, new RongIMClient.SendMessageCallback() {

                        @Override
                        public void onSuccess(int messageId) {

                        }

                        @Override
                        public void onError(int messageId, ErrorCode errorCode) {

                        }

                        @Override
                        public void onProgress(int messageId, int percent) {

                        }
                    }
            );

            RongIM.getInstance().startCustomerServiceChat(this, "kefu114", "???");

        } else if (position == 4) {
            /**
             * ???????????
             *
             * API??? http://docs.rongcloud.cn/android.html
             */
            RongIM.getInstance().startPrivateChat(this, DemoContext.getInstance().getCurrentUser().getUserId(), "???");

        } else if (position == 5) {
            startActivity(new Intent(this, GroupListActivity.class));
        } else if (position == 6) {
            RongIM.getInstance().startConversation(this, RongIMClient.ConversationType.CHATROOM, "chatroom002", "?????");
        } else if (position == 7) {
            startActivity(new Intent(this, TestFragmentActivity.class));
        } else if (position == 8) {
            startActivity(new Intent(this, TestFragment2Activity.class));
        }else if(position == 9){
            startActivity(new Intent(this, BlackListActivity.class));
        }
    }

    @Override
    public void onClick(View v) {

        if (v == mLogout) {

            /**
             * ??????????
             *
             * API??? http://docs.rongcloud.cn/android.html
             */

            if (RongIM.getInstance() != null)
                RongIM.getInstance().disconnect(false);

            finish();
        }

    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (KeyEvent.KEYCODE_BACK == event.getKeyCode()) {

            final AlterDialog alterDialog = new AlterDialog(this);
            alterDialog.setTitle("???????", true);

            alterDialog.setButton1("??", new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (RongIM.getInstance() != null) RongIM.getInstance().disconnect(true);
                    Process.killProcess(Process.myPid());
                }
            });

            alterDialog.setButton2("????", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alterDialog.dismiss();
                }
            });

            alterDialog.show();
        }

        return false;
    }



}




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