/**
* Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.easemob.chatuidemo;
import java.util.Map;
import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import cn.jpush.android.api.JPushInterface;
import com.easemob.EMCallBack;
import com.easemob.chatuidemo.domain.User;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
public class DemoApplication extends Application {
public final static String TAG = "VLC/VLCApplication";
public static Context applicationContext;
private static DemoApplication instance;
// login user name
public final String PREF_USERNAME = "username";
public final static String SLEEP_INTENT = "org.videolan.vlc.SleepIntent";
/**
* 当前用户nickname,为了苹果推送不是userid而是昵称
*/
public static String currentUserNick = "";
public static DemoHXSDKHelper hxSDKHelper = new DemoHXSDKHelper();
@Override
public void onCreate() {
super.onCreate();
applicationContext = this;
instance = this;
ImageLoaderConfiguration configuration = ImageLoaderConfiguration.createDefault(this);
ImageLoader.getInstance().init(configuration);
JPushInterface.setDebugMode(true);
JPushInterface.init(this);
/**
* this function will initialize the HuanXin SDK
*
* @return boolean true if caller can continue to call HuanXin related APIs after calling onInit, otherwise false.
*
* 环信初始化SDK帮助函数
* 返回true如果正确初始化,否则false,如果返回为false,请在后续的调用中不要调用任何和环信相关的代码
*
* for example:
* 例子:
*
* public class DemoHXSDKHelper extends HXSDKHelper
*
* HXHelper = new DemoHXSDKHelper();
* if(HXHelper.onInit(context)){
* // do HuanXin related work
* }
*/
hxSDKHelper.onInit(applicationContext);
}
public static DemoApplication getInstance() {
return instance;
}
/**
* 获取内存中好友user list
*
* @return
*/
public Map<String, User> getContactList() {
return hxSDKHelper.getContactList();
}
/**
* 设置好友user list到内存中
*
* @param contactList
*/
public void setContactList(Map<String, User> contactList) {
hxSDKHelper.setContactList(contactList);
}
/**
* 获取当前登陆用户名
*
* @return
*/
public String getUserName() {
return hxSDKHelper.getHXId();
}
/**
* 获取密码
*
* @return
*/
public String getPassword() {
return hxSDKHelper.getPassword();
}
/**
* 设置用户名
*
* @param user
*/
public void setUserName(String username) {
hxSDKHelper.setHXId(username);
}
/**
* 设置密码 下面的实例代码 只是demo,实际的应用中需要加password 加密后存入 preference 环信sdk
* 内部的自动登录需要的密码,已经加密存储了
*
* @param pwd
*/
public void setPassword(String pwd) {
hxSDKHelper.setPassword(pwd);
}
/**
* 退出登录,清空数据
*/
public void logout(final EMCallBack emCallBack) {
// 先调用sdk logout,在清理app中自己的数据
hxSDKHelper.logout(emCallBack);
}
/**
* @return the main context of the Application
*/
public static Context getAppContext() {
return instance;
}
/**
* @return the main resources from the Application
*/
public static Resources getAppResources() {
if (instance == null)
return null;
return instance.getResources();
}
}