Android Open Source - demo-app-android Demo 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;
//w w  w.j  a va 2 s . co m
import android.os.Bundle;
import android.util.Log;

import com.sea_monster.core.exception.BaseException;
import com.sea_monster.core.network.AbstractHttpRequest;
import com.sea_monster.core.network.ApiCallback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import io.rong.imkit.RongActivity;
import io.rong.imkit.RongIM;
import io.rong.imkit.demo.model.User;
import io.rong.imlib.RongIMClient;

/**
 * Created by DragonJ on 14/11/4.
 */
public class DemoActivity extends RongActivity {
    FriendCallback mCallback;
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        if(RongIM.getInstance() == null){
            String userName = DemoContext.getInstance().getUsername();
            mCallback = new FriendCallback();
            DemoContext.getInstance().getDemoApi().getFriends(userName, mCallback);
            initGroupInfo();
        }
    }

    class FriendCallback implements ApiCallback<ArrayList<User>>{

        @Override
        public void onComplete(AbstractHttpRequest<ArrayList<User>> arrayListAbstractHttpRequest, ArrayList<User> users) {
            DemoContext.getInstance().setFriends(getFriends(users));
        }

        @Override
        public void onFailure(AbstractHttpRequest<ArrayList<User>> arrayListAbstractHttpRequest, BaseException e) {

        }
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }


    /**
     * ??????????????????????????
     *
     * @param users
     * @return
     */
    public ArrayList<RongIMClient.UserInfo> getFriends(ArrayList<User> users) {

        if (users == null)
            return null;

        ArrayList<RongIMClient.UserInfo> friends = new ArrayList<RongIMClient.UserInfo>();

        for (User user : users) {
            RongIMClient.UserInfo info = new RongIMClient.UserInfo(String.valueOf(user.getId()), user.getUsername(), user.getPortrait());
            friends.add(info);
        }

        return friends;
    }
    HashMap<String, RongIMClient.Group> groupM;
    private void initGroupInfo() {

        RongIMClient.Group group1 = new RongIMClient.Group("group001", "???", "http://docs.rongcloud.cn/assets/img/logo@2x.png");
        RongIMClient.Group group2 = new RongIMClient.Group("group002", "???", "http://cn.bing.com/fd/s/a/k_zh_cn_s2.png");
        RongIMClient.Group group3 = new RongIMClient.Group("group003", "???", "http://www.baidu.com/img/bdlogo.png");
        List<RongIMClient.Group> groups = new ArrayList<RongIMClient.Group>();
        groups.add(group1);
        groups.add(group2);
        groups.add(group3);

        groupM = new HashMap<String, RongIMClient.Group>();
        groupM.put("group001", group1);
        groupM.put("group002", group2);
        groupM.put("group003", group3);

        DemoContext.getInstance().setGroupMap(groupM);
        DemoContext.getInstance().setGroupInfoProvider();
    }

}




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