Commit c4d7c7f3 authored by fallenstardust's avatar fallenstardust

添加聊天室

parent 69a45483
......@@ -4,9 +4,10 @@ buildscript {
repositories {
jcenter()
maven { url "https://jitpack.io" }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}
......
#Thu Mar 16 14:05:33 CST 2017
#Sun May 13 10:11:00 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
......@@ -2,11 +2,11 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
targetSdkVersion 22
flavorDimensions "versionCode"
/* ndk {
moduleName "YGOMobile"
abiFilters "armeabi-v7a","x86"
......@@ -22,8 +22,9 @@ android {
jniLibs.srcDirs 'libs'
}
}
buildToolsVersion '27.0.3'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
......@@ -3,17 +3,17 @@ apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "cn.garymb.ygomobile"
minSdkVersion 16
targetSdkVersion 22
versionCode 32000506
versionName "3.2.0"
versionCode 32010513
versionName "3.2.1"
flavorDimensions "versionCode"
vectorDrawables.useSupportLibrary = true
ndk {
abiFilters "armeabi-v7a", "x86"
abiFilters "armeabi-v7a","armeabi"
}
}
compileOptions {
......@@ -46,14 +46,6 @@ android {
jniLibs.srcDirs = ['libs']
}
}
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk false
}
}
lintOptions {
ignoreWarnings true
}
......@@ -61,6 +53,7 @@ android {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
}
buildToolsVersion '27.0.3'
}
repositories {
......@@ -70,24 +63,43 @@ android {
}
dependencies {
testCompile 'junit:junit:4.12'
compile project(':libcore')
compile 'org.jdeferred:jdeferred-android-aar:1.2.4'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.chrisbanes.photoview:library:1.2.4'
implementation 'junit:junit:4.12'
implementation project(':libcore')
implementation 'org.jdeferred:jdeferred-android-aar:1.2.4'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.github.chrisbanes.photoview:library:1.2.4'
//
compile 'com.android.support:support-annotations:' + rootProject.ext.supportVersion
compile 'com.android.support:recyclerview-v7:' + rootProject.ext.supportVersion
compile 'com.android.support:design:' + rootProject.ext.supportVersion
compile 'com.android.support:appcompat-v7:' + rootProject.ext.supportVersion
compile 'com.android.support:support-vector-drawable:' + rootProject.ext.supportVersion
implementation 'com.android.support:support-annotations:' + rootProject.ext.supportVersion
implementation 'com.android.support:recyclerview-v7:' + rootProject.ext.supportVersion
implementation 'com.android.support:design:' + rootProject.ext.supportVersion
implementation 'com.android.support:appcompat-v7:' + rootProject.ext.supportVersion
implementation 'com.android.support:support-vector-drawable:' + rootProject.ext.supportVersion
//
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.tubb.smrv:swipemenu-recyclerview:5.4.0'
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'com.tubb.smrv:swipemenu-recyclerview:5.4.0'
//
mycardCompile(name: 'xwalk_core_library-22.52.561.4', ext: 'aar')
compile 'com.nightonke:boommenu:2.1.0'
implementation(name: 'xwalk_core_library-22.52.561.4', ext: 'aar')
implementation 'org.igniterealtime.smack:smack-android-extensions:4.2.0'
implementation 'org.igniterealtime.smack:smack-tcp:4.2.0'
implementation 'org.igniterealtime.smack:smack-android:4.2.0'
implementation 'org.igniterealtime.smack:smack-core:4.2.0'
implementation 'org.igniterealtime.smack:smack-extensions:4.2.0'
implementation 'org.igniterealtime.smack:smack-im:4.2.0'
implementation 'org.igniterealtime.smack:smack-resolver-minidns:4.2.0'
implementation 'org.igniterealtime.smack:smack-sasl-provided:4.2.0'
//implementation 'xpp3:xpp3:1.1.4c'
implementation 'org.jxmpp:jxmpp-core:0.5.0'
implementation 'org.jxmpp:jxmpp-jid:0.5.0'
implementation 'org.jxmpp:jxmpp-util-cache:0.5.0'
implementation 'de.measite.minidns:minidns-hla:0.2.4'
implementation 'de.measite.minidns:minidns-core:0.2.4'
implementation 'de.measite.minidns:minidns-dnssec:0.2.4'
implementation 'de.measite.minidns:minidns-iterative-resolver:0.2.4'
implementation 'com.github.bumptech.glide:glide:3.7.0'
//
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.nightonke:boommenu:2.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
......@@ -9,6 +9,12 @@
android:launchMode="singleTop"
android:theme="@style/AppTheme.Translucent"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"/>
<activity
android:name="cn.garymb.ygomobile.ui.online.mcchat.McchatActivity"
android:windowSoftInputMode="stateHidden|adjustResize"
android:label="@string/app_name"/>
<activity
android:name="cn.garymb.ygomobile.ui.online.mcchat.SplashActivity"/>
</application>
</manifest>
\ No newline at end of file
package cn.garymb.ygomobile.ui.online.mcchat;
import android.app.*;
import android.content.*;
public class ChatApplication extends Application
{
private static Context context;
@Override
public void onCreate()
{
// TODO: Implement this method
super.onCreate();
context=getApplicationContext();
}
public static Context getContext(){
return context;
}
}
package cn.garymb.ygomobile.ui.online.mcchat;
import org.jivesoftware.smack.packet.*;
public interface ChatListener
{
void addMessage(Message message);
void removeMessage(Message message);
void reLogin(boolean state);
void reJoin(boolean state);
}
package cn.garymb.ygomobile.ui.online.mcchat;
import org.jivesoftware.smack.packet.Message;
import cn.garymb.ygomobile.ui.online.mcchat.management.*;
public class ChatMessage
{
private String name;
//private String time;
private String message;
private String avatar;
public void setAvatar(String avatar)
{
this.avatar = avatar;
}
public String getAvatar()
{
return avatar;
}
public void setMessage(String message)
{
this.message = message;
}
public String getMessage()
{
return message;
}
public void setName(String name)
{
this.name = name;
this.avatar=getAvatarUrl(name);
}
public String getName()
{
return name;
}
/*
public void setTime(String time)
{
this.time = time;
}
public String getTime()
{
return time;
}
*/
public static ChatMessage toChatMessage(Message message){
if(message.getBody()!=null)
{
String xs=message.toXML().toString();
int cc=xs.indexOf("stamp='");
if(cc!=-1){
String ss=xs.substring(cc+7,xs.indexOf("'",cc+7));
}else{
}
String names=message.getFrom().toString();
String name=names.substring(names.indexOf(ServiceManagement.GROUP_ADDRESS)+ServiceManagement.GROUP_ADDRESS.length()+1,names.length());
ChatMessage cm=new ChatMessage();
cm.setName(name);
//cm.setTime(ss);
cm.setMessage(message.getBody());
return cm;
}
return null;
}
public String getAvatarUrl(String userName){
return "https://api.moecube.com/accounts/users/"+userName+".png";
}
}
package cn.garymb.ygomobile.ui.online.mcchat;
import android.app.*;
import android.os.*;
import android.util.*;
import org.jivesoftware.smack.packet.Message;
import android.widget.*;
import android.support.v7.widget.*;
import android.view.View.*;
import android.view.*;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.online.mcchat.adapter.*;
import cn.garymb.ygomobile.ui.online.mcchat.util.*;
import cn.garymb.ygomobile.ui.online.mcchat.management.*;
public class McchatActivity extends Activity implements ChatListener
{
@Override
public void reLogin(boolean state)
{
main_bottom_bar.setVisibility(View.GONE);
if(state){
main_title.setText("登录成功");
}else{
main_title.setText("连接断开,重新登录中……");
}
// TODO: Implement this method
}
@Override
public void reJoin(boolean state)
{
if(state){
main_bottom_bar.setVisibility(View.VISIBLE);
main_title.setText(getResources().getString(R.string.app_name));
}else{
main_bottom_bar.setVisibility(View.GONE);
main_title.setText("重新加入聊天室中……");
}
// TODO: Implement this method
}
@Override
public void addMessage(Message message)
{
cadp.sx();
main_rec.smoothScrollToPosition(su.getData().size()-1);
// TODO: Implement this method
}
@Override
public void removeMessage(Message message)
{
// TODO: Implement this method
}
private EditText main_send_message;
private ImageButton main_send;
private RecyclerView main_rec;
private TextView main_title;
private LinearLayout main_bottom_bar;
private ChatAdapter cadp;
private ServiceManagement su;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initView();
}
private void initView()
{
main_rec=(RecyclerView) findViewById(R.id.main_rec);
main_send=(ImageButton) findViewById(R.id.main_send);
main_send_message=(EditText) findViewById(R.id.main_send_message);
main_title=(TextView) findViewById(R.id.main_title);
main_bottom_bar=(LinearLayout) findViewById(R.id.main_bottom_bar);
su=ServiceManagement.getDx();
cadp=new ChatAdapter(this,su.getData());
su.addListener(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(McchatActivity.this, LinearLayoutManager.VERTICAL, false);
linearLayoutManager.setStackFromEnd(true); //关键 设置此项,当软键盘弹出时,布局会自动顶上去,在结合AndroidManifest.xml设置属性
main_rec.setLayoutManager(linearLayoutManager);
main_rec.setAdapter(cadp);
initListener();
// TODO: Implement this method
}
private void initListener()
{
main_send.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View p1)
{
String message=main_send_message.getText().toString().trim();
if(message.equals("")){
Util.show("发送内容不能为空");
}else{
try
{
su.sendMessage(message);
main_send_message.setText("");
}catch (Exception e){
Util.show("发送失败");
Log.e("错误","错误为"+e);
}
}
// TODO: Implement this method
}
});
// TODO: Implement this method
}
@Override
protected void onDestroy()
{
// TODO: Implement this method
super.onDestroy();
su.disClass();
UserManagement.setUserName(null);
UserManagement.setUserPassword(null);
finish();
}
}
package cn.garymb.ygomobile.ui.online.mcchat;
import android.app.*;
import android.os.*;
import android.content.*;
import android.util.*;
import android.widget.*;
import android.view.*;
import android.view.View.*;
import cn.garymb.ygomobile.ui.online.MyCardActivity;
import cn.garymb.ygomobile.ui.online.mcchat.util.*;
import cn.garymb.ygomobile.ui.online.mcchat.management.*;
public class SplashActivity extends Activity
{
ServiceManagement su;
ProgressBar sp_jz;
TextView sp_tv;
LinearLayout sp_li;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO: Implement this method
super.onCreate(savedInstanceState);
setContentView(layout.activity_splash);
initView();
/*String name=getIntent().getStringExtra("name");
String password=getIntent().getStringExtra("password");
UserManagement.setUserName(name);
UserManagement.setUserPassword(password);*/
//UserManagement.setUserName("废话多");
//UserManagement.setUserPassword("19709");
/*
SharedPreferences lastModified = getSharedPreferences("MyCardUser", Context.MODE_PRIVATE);
UserManagement.setUserName(lastModified.getString("name",null));
UserManagement.setUserPassword(lastModified.getString("id",null));
*/
su = ServiceManagement.getDx();
join();
}
private void join()
{
if (!su.isListener())
{
new Thread(new Runnable(){
@Override
public void run()
{
if (!su.isConnected()){
han.sendEmptyMessage(4);
login();
}
if(su.isConnected()){
han.sendEmptyMessage(3);
try
{
su.joinChat();
han.sendEmptyMessage(1);
}
catch (Exception e)
{
han.sendEmptyMessage(2);
}
}
// TODO: Implement this method
}
}).start();
}else{
han.sendEmptyMessage(1);
}
// TODO: Implement this method
}
private void initView()
{
sp_jz=findViewById(R.id.sp_jz);
sp_tv=findViewById(R.id.sp_tv);
sp_li=findViewById(R.id.sp_li);
sp_li.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View p1)
{
join();
// TODO: Implement this method
}
});
// TODO: Implement this method
}
private void login()
{
String name=UserManagement.getUserName();
String password =UserManagement.getUserPassword();
if (name != null && password != null)
{
try
{
su.login(name, password);
}catch (Exception e){
Log.e("登录失败","登录失败"+e);
Message me=new Message();
me.obj=e;
me.what=0;
han.sendMessage(me);
}
}else{
han.sendEmptyMessage(5);
}
// TODO: Implement this method
}
Handler han=new Handler(){
@Override
public void handleMessage(Message msg)
{
// TODO: Implement this method
super.handleMessage(msg);
switch(msg.what){
case 0:
su.setIsConnected(false);
sp_jz.setVisibility(View.GONE);
sp_tv.setText("登录失败,点击重新登录");
Util.show("登录失败,原因为"+msg.obj);
break;
case 1:
startActivity(new Intent(SplashActivity.this,McchatActivity.class));
finish();
break;
case 2:
su.setIsListener(false);
sp_jz.setVisibility(View.GONE);
sp_tv.setText("加入聊天室失败,点击重新加入");
break;
case 3:
sp_jz.setVisibility(View.VISIBLE);
sp_tv.setText("正在加入聊天室,请稍等");
break;
case 4:
sp_jz.setVisibility(View.VISIBLE);
sp_tv.setText("登录中,请稍等");
break;
case 5:
/*sp_jz.setVisibility(View.GONE);
sp_tv.setText("用户名或密码为空");*/
startActivity(new Intent(SplashActivity.this,MyCardActivity.class));
finish();
break;
}
}
};
}
package cn.garymb.ygomobile.ui.online.mcchat.adapter;
import android.content.*;
import android.support.v7.widget.*;
import android.view.*;
import android.widget.*;
import android.view.View.*;
import java.util.*;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.online.mcchat.*;
import cn.garymb.ygomobile.ui.online.mcchat.util.*;
import cn.garymb.ygomobile.ui.online.mcchat.management.*;
import android.app.*;
public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ViewHolder> {
private List<ChatMessage> data;
private Context context;
private static final int CHAT = 0;
private static final int CHAT_ME = 1;
@Override
public ChatAdapter.ViewHolder onCreateViewHolder(ViewGroup p1, int p2) {
View v = null;
switch (p2) {
case CHAT:
v = LayoutInflater.from(p1.getContext()).inflate(R.layout.item_chat, p1, false);
break;
case CHAT_ME:
v = LayoutInflater.from(p1.getContext()).inflate(R.layout.item_chat_me, p1, false);
break;
}
ViewHolder viewHolder = new ViewHolder(v, p2);
// TODO: Implement this method
return viewHolder;
}
@Override
public int getItemViewType(int position) {
if (data.get(position).getName().equals(UserManagement.getUserName())) {
return CHAT_ME;
} else {
return CHAT;
}
}
@Override
public void onBindViewHolder(ChatAdapter.ViewHolder vh, int position) {
final ChatMessage cm = data.get(position);
vh.ic_name.setText(cm.getName());
//vh.ic_time.setText(cm.getTime());
vh.ic_message.setText(cm.getMessage());
ImageUtil.tuxian(context, cm.getAvatar(), vh.ic_avatar);
if (position != 0) {
if (cm.getName().equals(data.get(position - 1).getName())) {
vh.ic_name.setVisibility(View.GONE);
vh.ic_avatar.setVisibility(View.INVISIBLE);
} else {
vh.ic_name.setVisibility(View.VISIBLE);
vh.ic_avatar.setVisibility(View.VISIBLE);
}
} else {
vh.ic_name.setVisibility(View.VISIBLE);
vh.ic_avatar.setVisibility(View.VISIBLE);
}
vh.ic_dialog.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View p1) {
Util.fzMessage(cm.getMessage());
Util.show("已复制到剪贴板");
// TODO: Implement this method
return true;
}
});
vh.vh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View p1) {
Util.closeKeyboard((Activity) context);
// TODO: Implement this method
}
});
// TODO: Implement this method
}
@Override
public int getItemCount() {
// TODO: Implement this method
return data.size();
}
public ChatAdapter(Context context, List<ChatMessage> data) {
this.context = context;
this.data = data;
}
class ViewHolder extends RecyclerView.ViewHolder {
TextView ic_name, ic_message;
ImageView ic_avatar;
LinearLayout ic_dialog;
View vh;
public ViewHolder(View v, int position) {
super(v);
vh = v;
if (position == CHAT) {
ic_dialog = (LinearLayout) v.findViewById(R.id.ic_dialog);
ic_name = (TextView) v.findViewById(R.id.ic_name);
ic_avatar = (ImageView) v.findViewById(R.id.ic_avatar);
ic_message = (TextView) v.findViewById(R.id.ic_message);
} else {
ic_name = (TextView) v.findViewById(R.id.icm_name);
ic_avatar = (ImageView) v.findViewById(R.id.icm_avatar);
ic_message = (TextView) v.findViewById(R.id.icm_message);
ic_dialog = (LinearLayout) v.findViewById(R.id.icm_dialog);
}
}
}
public void sx() {
notifyDataSetChanged();
}
}
package cn.garymb.ygomobile.ui.online.mcchat.management;
import android.util.*;
import java.util.*;
import java.io.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.tcp.*;
import org.jivesoftware.smackx.muc.*;
import org.jxmpp.jid.impl.*;
import org.jxmpp.jid.parts.*;
import org.jxmpp.stringprep.*;
import android.os.Handler;
import cn.garymb.ygomobile.ui.online.mcchat.util.*;
import cn.garymb.ygomobile.ui.online.mcchat.*;
public class ServiceManagement
{
public static final String GROUP_ADDRESS="ygopro_china_north@conference.mycard.moe";
private static ServiceManagement su=new ServiceManagement();
private XMPPTCPConnection con;
private MultiUserChat muc;
private boolean isConnected=false;
private boolean isListener=false;
private List<ChatMessage> data=new ArrayList<ChatMessage>();
private List<ChatListener> cl=new ArrayList<ChatListener>();
private ServiceManagement(){
}
public void addListener(ChatListener c){
cl.add(c);
}
public List<ChatMessage> getData()
{
return data;
}
public void setIsListener(boolean isListener)
{
this.isListener = isListener;
}
public boolean isListener()
{
return isListener;
}
public void setIsConnected(boolean isConnected)
{
this.isConnected = isConnected;
}
public boolean isConnected()
{
return isConnected;
}
public XMPPTCPConnection getCon()
{
return con;
}
private XMPPTCPConnection getConnextion(String name,String password) throws XmppStringprepException{
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(name, password)
.setXmppDomain("mycard.moe")
.setKeystoreType(null)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.build();
con= new XMPPTCPConnection(config);
return con;
}
public boolean login(String name,String password) throws IOException, SmackException, XMPPException, InterruptedException{
XMPPTCPConnection con= getConnextion(name,password);
con.connect();
if(con.isConnected()){
con.login();
con.addConnectionListener(new TaxiConnectionListener());
setIsConnected(true);
return true;
}
setIsConnected(false);
return false;
}
public void sendMessage(String message) throws SmackException.NotConnectedException, InterruptedException{
muc.sendMessage(message);
}
public void joinChat() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, MultiUserChatException.NotAMucServiceException, SmackException.NotConnectedException, XmppStringprepException, MultiUserChatException.MucAlreadyJoinedException, InterruptedException{
if(!isListener){
MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(getCon());
muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(GROUP_ADDRESS));
muc.createOrJoin(Resourcepart.from(UserManagement.getUserName()));
data.clear();
muc.addMessageListener(new MessageListener() {
@Override
public void processMessage(Message message) {
Log.e("接收消息","接收"+message);
ChatMessage cm=ChatMessage.toChatMessage(message);
if(cm!=null){
data.add(cm);
han.sendEmptyMessage(0);
}
}
});
setIsListener(true);
}
}
Handler han=new Handler(){
@Override
public void handleMessage(android.os.Message msg)
{
// TODO: Implement this method
super.handleMessage(msg);
switch(msg.what){
case 0:
for(ChatListener c:cl){
if(c!=null){
c.addMessage((Message)msg.obj);
}else{
cl.remove(c);
}
}
break;
case 1:
for(ChatListener c:cl){
if(c!=null){
c.reLogin((boolean)msg.obj);
}else{
cl.remove(c);
}
}
break;
case 2:
for(ChatListener c:cl){
if(c!=null){
c.reJoin((boolean)msg.obj);
}else{
cl.remove(c);
}
}
break;
}
}
};
public void setreLogin(boolean state){
android.os.Message me=new android.os.Message();
me.what=1;
me.obj=state;
han.sendMessage(me);
}
public void setreJoin(boolean state){
android.os.Message me=new android.os.Message();
me.what=2;
me.obj=state;
han.sendMessage(me);
}
public static ServiceManagement getDx(){
return su;
}
public void disSerVice(){
con.disconnect();
setIsConnected(false);
}
public void disClass(){
disSerVice();
setIsConnected(false);
setIsListener(false);
data.clear();
cl.clear();
}
}
package cn.garymb.ygomobile.ui.online.mcchat.management;
import android.content.*;
import cn.garymb.ygomobile.ui.online.mcchat.*;
public class UserManagement
{
private static UserManagement um=new UserManagement();
private static String userName,userPassword;
private UserManagement(){
}
public static String getUserName(){
return userName;
}
public static String getUserPassword(){
return userPassword;
}
public static void setUserName(String name){
userName=name;
}
public static void setUserPassword(String password){
userPassword=password;
}
public static UserManagement getDx(){
return um;
}
}
package cn.garymb.ygomobile.ui.online.mcchat.util;
import android.widget.*;
import com.bumptech.glide.*;
import android.net.*;
import android.content.*;
import com.bumptech.glide.load.engine.*;
import cn.garymb.ygomobile.lite.R;
public class ImageUtil
{
public static void tuxian(Context context,String url,final ImageView im){
if(url!=null){
Glide.with(context)
.load(Uri.parse(url))
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(R.drawable.avatar)
.into(im);
}
}
}
package cn.garymb.ygomobile.ui.online.mcchat.util;
/**
* 连接监听类
*
*
*/
import android.util.*;
import cn.garymb.ygomobile.ui.online.mcchat.*;
import java.util.*;
//import org.apache.commons.codec.net.*;
import org.jivesoftware.smack.*;
import cn.garymb.ygomobile.ui.online.mcchat.management.*;
import java.io.*;
import org.jivesoftware.smack.SmackException.*;
import org.jivesoftware.smack.XMPPException.*;
import org.jivesoftware.smackx.muc.MultiUserChatException.*;
import org.jxmpp.stringprep.*;
import android.os.*;
public class TaxiConnectionListener implements ConnectionListener
{
@Override
public void connected(XMPPConnection p1)
{
Log.e("TaxiConnectionListener","开始连接");
//连接
// TODO: Implement this method
}
@Override
public void authenticated(XMPPConnection p1, boolean p2)
{
Log.e("TaxiConnectionListener","通过身份验证");
//通过身份验证
// TODO: Implement this method
}
@Override
public void reconnectionSuccessful()
{
//重新连接成功
Log.e("TaxiConnectionListener","重连成功");
// TODO: Implement this method
}
@Override
public void reconnectingIn(int p1)
{
//正在重连
Log.e("TaxiConnectionListener","正在重连"+p1);
// TODO: Implement this method
}
@Override
public void reconnectionFailed(Exception p1)
{
//重新连接失败
Log.e("重连失败","失败"+p1);
// TODO: Implement this method
}
private Timer tExit;
private String username;
private String password;
private int logintime = 2000;
private ServiceManagement sm=ServiceManagement.getDx();
@Override
public void connectionClosed() {
//正常关闭连接
Log.e("TaxiConnectionListener", "连接关闭");
// 重连服务器
//tExit = new Timer();
//tExit.schedule(new timetask(), logintime);
}
@Override
public void connectionClosedOnError(Exception e) {
//非正常关闭连接
Log.e("TaxiConnectionListener", "连接关闭异常"+e);
sm.setIsListener(false);
// 重连服务器
tExit = new Timer();
tExit.schedule(new timetask(), logintime);
}
class timetask extends TimerTask {
@Override
public void run() {
username = UserManagement.getUserName();
password = UserManagement.getUserPassword();
if (username != null && password != null) {
sm.setreLogin(false);
Log.e("TaxiConnectionListener", "尝试登录");
// 连接服务器
try
{
if (sm.login(username, password))
{
sm.setreLogin(true);
Log.e("TaxiConnectionListener", "登录成功");
tExit.schedule(new timeJoin(), logintime);
}else{
Log.e("TaxiConnectionListener", "重新登录");
tExit.schedule(new timetask(), logintime);
}
}catch (Exception e){
tExit.schedule(new timetask(), logintime);
}
}
}
class timeJoin extends TimerTask
{
@Override
public void run()
{
sm.setreJoin(false);
Log.e("TaxiConnectionListener", "尝试加入房间");
try
{
sm.joinChat();
sm.setreJoin(true);
Log.e("TaxiConnectionListener", "加入房间成功");
}catch (Exception e){
Log.e("TaxiConnectionListener", "重新加入房间");
tExit.schedule(new timeJoin(), logintime);
}
// TODO: Implement this method
}
}
}
}
package cn.garymb.ygomobile.ui.online.mcchat.util;
import android.app.*;
import android.content.*;
import android.view.inputmethod.*;
import android.widget.*;
import cn.garymb.ygomobile.ui.online.mcchat.*;
public class Util
{
//提示
public static void show(String message){
Toast.makeText(ChatApplication.getContext(),message,Toast.LENGTH_SHORT).show();
}
//关闭输入法
public static void closeKeyboard(Activity activity){
InputMethodManager inputMethodManager = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow((activity).getCurrentFocus().getWindowToken()
,InputMethodManager.HIDE_NOT_ALWAYS);
}
//复制字符串到剪贴板
public static void fzMessage(String message){
ClipboardManager cmb = (ClipboardManager) ChatApplication.getContext().getSystemService(ChatApplication.getContext().CLIPBOARD_SERVICE);
cmb.setText(message);//复制命令
}
}
package cn.garymb.ygomobile.ui.online.mcchat.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
/*
* 圆形ImageView
*/
public class YuanImage extends android.support.v7.widget.AppCompatImageView {
private Context mContext;
// 控件默认长、宽
private int defaultWidth = 0;
private int defaultHeight = 0;
public YuanImage(Context context) {
super(context);
mContext = context;
}
public YuanImage(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
}
public YuanImage(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
}
@Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable() ;
if (drawable == null) {
return;
}
if (getWidth() == 0 || getHeight() == 0) {
return;
}
this.measure(0, 0);
if (drawable.getClass() == NinePatchDrawable.class)
return;
Bitmap b = ((BitmapDrawable) drawable).getBitmap();
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
if (defaultWidth == 0) {
defaultWidth = getWidth();
}
if (defaultHeight == 0) {
defaultHeight = getHeight();
}
int radius = (defaultWidth < defaultHeight ? defaultWidth : defaultHeight) / 2;
Bitmap roundBitmap = getCroppedRoundBitmap(bitmap, radius);
canvas.drawBitmap(roundBitmap, defaultWidth / 2 - radius, defaultHeight / 2 - radius, null);
}
/**
* 获取裁剪后的圆形图片
* @param radius 半径
*/
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
Bitmap scaledSrcBmp;
int diameter = radius * 2;
// 为了防止宽高不相等,造成圆形图片变形,因此截取长方形中处于中间位置最大的正方形图片
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
int squareWidth = 0, squareHeight = 0;
int x = 0, y = 0;
Bitmap squareBitmap;
if (bmpHeight > bmpWidth) {// 高大于宽
squareWidth = squareHeight = bmpWidth;
x = 0;
y = (bmpHeight - bmpWidth) / 2;
// 截取正方形图片
squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
} else if (bmpHeight < bmpWidth) {// 宽大于高
squareWidth = squareHeight = bmpHeight;
x = (bmpWidth - bmpHeight) / 2;
y = 0;
squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth,squareHeight);
} else {
squareBitmap = bmp;
}
if (squareBitmap.getWidth() != diameter || squareBitmap.getHeight() != diameter) {
scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter,diameter, true);
} else {
scaledSrcBmp = squareBitmap;
}
Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(),
scaledSrcBmp.getHeight(),
Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(),scaledSrcBmp.getHeight());
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawCircle(scaledSrcBmp.getWidth() / 2,
scaledSrcBmp.getHeight() / 2,
scaledSrcBmp.getWidth() / 2,
paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
bmp = null;
squareBitmap = null;
scaledSrcBmp = null;
return output;
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape>
<corners android:radius="8dp"/>
<solid android:color="#FF2E5920"/>
</shape>
</item>
<item>
<shape>
<corners android:radius="8dp"/>
<solid android:color="@android:color/white"/>
</shape>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<corners android:radius="5dp"/>
<solid android:color="#ffffffff"/>
</shape>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape>
<corners android:radius="5dp"/>
<solid android:color="#E3F2FD"/>
</shape>
</item>
<item>
<shape>
<corners android:radius="5dp"/>
<solid android:color="@color/white"/>
</shape>
</item>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape>
<corners android:radius="5dp"/>
<solid android:color="#B0BEC5"/>
</shape>
</item>
<item>
<shape>
<corners android:radius="5dp"/>
<solid android:color="#cfd8dc"/>
</shape>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape>
<corners android:radius="5dp"/>
<solid android:color="#1183F3"/>
</shape>
</item>
<item>
<shape>
<corners android:radius="5dp"/>
<solid android:color="#FF11B7F3"/>
</shape>
</item>
</selector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#1976D2"
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center"
android:id="@+id/sp_li">
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/sp_jz"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="登录中,请稍等"
android:textSize="18sp"
android:id="@+id/sp_tv"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<com.mcchat.feihua.view.YuanImage
android:layout_height="35dp"
android:layout_width="35dp"
android:id="@+id/ic_avatar"
android:scaleType="centerCrop"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"/>
<LinearLayout
android:layout_alignTop="@id/ic_avatar"
android:layout_toRightOf="@id/ic_avatar"
android:descendantFocusability="blocksDescendants"
android:padding="8dp"
android:background="@drawable/chat_message_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/ic_dialog"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp">
<TextView
android:id="@+id/ic_name"
android:text="name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:textSize="13sp"
android:textColor="#B8630C"
android:textStyle="bold"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="message"
android:textColor="#000000"
android:id="@+id/ic_message"
android:textSize="16sp"/>
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<com.mcchat.feihua.view.YuanImage
android:id="@+id/icm_avatar"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:scaleType="centerCrop" />
<LinearLayout
android:id="@+id/icm_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/icm_avatar"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@id/icm_avatar"
android:background="@drawable/chat_message_me_background"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/icm_name"
android:layout_width="0px"
android:layout_height="0px"
android:paddingBottom="4dp"
android:text="name"
android:textColor="#B8630C"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="@+id/icm_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="message"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/background"
android:gravity="center">
<RelativeLayout
android:background="@color/colorMain"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:textColor="@color/white"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/app_name"
android:layout_margin="10dp"
android:textSize="20sp"
android:id="@+id/main_title"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/main_rec"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1000"/>
<LinearLayout
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal"
android:padding="7dp"
android:id="@+id/main_bottom_bar">
<EditText
android:background="@drawable/chat_edittext_background"
android:padding="7dp"
android:id="@+id/main_send_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_weight="10"
android:maxEms="3"/>
<LinearLayout
android:layout_marginLeft="7dp"
android:layout_width="0dp"
android:layout_height="33dp"
android:gravity="center"
android:layout_weight="2"
android:orientation="vertical">
<ImageButton
android:background="@drawable/chat_message_background"
android:src="@drawable/ic_send_black_24dp"
android:id="@+id/main_send"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/send"
android:gravity="center"
android:textSize="12sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
......@@ -5,6 +5,10 @@
android:icon="@drawable/ic_home"
android:title="@string/mc_home"
/>
<item
android:id="@+id/action_chat"
android:icon="?android:attr/textSelectHandleLeft"
android:title="@string/mc_chat" />
<item
android:id="@+id/action_bbs"
android:icon="@drawable/ic_forum"
......
......@@ -177,6 +177,8 @@
<string name="delete">删除</string>
<string name="mycard">萌卡平台</string>
<string name="arena">决斗数据库</string>
<string name="mc_chat">聊天室</string>
<string name="send">发送</string>
<string name="mc_home">大厅</string>
<string name="bbs">社区</string>
<string name="settings_pref_settings_only_game">直接启动游戏</string>
......
......@@ -23,4 +23,7 @@
<color name="holo_blue_light">#ff33b5e5</color>
<color name="holo_green_bright">#95d389</color>
<color name="holo_orange_bright">#ff982a</color>
<color name="colorMain">#2196F3</color>
<color name="background">#ECEFF1</color>
</resources>
\ No newline at end of file
......@@ -180,6 +180,8 @@
<string name="mycard">MyCard</string>
<string name="arena">Duelist DataBase</string>
<string name="mc_home">Home</string>
<string name="mc_chat">Chat</string>
<string name="send">Send</string>
<string name="bbs">Community</string>
<string name="settings_pref_settings_only_game">Only start game</string>
<string name="only_game_tip">reset this setting, need clean data of app</string>
......
......@@ -66,6 +66,8 @@ public class MyCard {
mDefWebViewClient = new DefWebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
UserManagement.setUserName(mUser.username);
UserManagement.setUserPassword(mUser.external_id+"");
if (url.startsWith(return_sso_url)) {
String sso = Uri.parse(url).getQueryParameter("sso");
String data = new String(Base64.decode(Uri.parse(url).getQueryParameter("sso"), Base64.NO_WRAP), UTF_8);
......
......@@ -167,6 +167,9 @@ public class MyCardActivity extends BaseActivity implements MyCard.MyCardListene
case R.id.action_bbs:
mWebViewPlus.loadUrl(mMyCard.getBBSUrl());
break;
case android.R.id.action_chat:
startActivity(new Intent(context,SplashActivity.class));
break;
default:
return false;
}
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center"
android:id="@+id/sp_li">
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/sp_jz"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="登录中,请稍等"
android:textSize="18sp"
android:id="@+id/sp_tv"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<com.mcchat.feihua.view.YuanImage
android:layout_height="35dp"
android:layout_width="35dp"
android:id="@+id/ic_avatar"
android:scaleType="centerCrop"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"/>
<LinearLayout
android:layout_alignTop="@id/ic_avatar"
android:layout_toRightOf="@id/ic_avatar"
android:descendantFocusability="blocksDescendants"
android:padding="8dp"
android:background="@drawable/chat_message_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/ic_dialog"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp">
<TextView
android:id="@+id/ic_name"
android:text="name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:textSize="13sp"
android:textColor="#B8630C"
android:textStyle="bold"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="message"
android:textColor="#000000"
android:id="@+id/ic_message"
android:textSize="16sp"/>
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<com.mcchat.feihua.view.YuanImage
android:id="@+id/icm_avatar"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:scaleType="centerCrop" />
<LinearLayout
android:id="@+id/icm_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/icm_avatar"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@id/icm_avatar"
android:background="@drawable/chat_message_me_background"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/icm_name"
android:layout_width="0px"
android:layout_height="0px"
android:paddingBottom="4dp"
android:text="name"
android:textColor="#B8630C"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="@+id/icm_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="message"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/background"
android:gravity="center">
<RelativeLayout
android:background="@color/mediumPurpleLight"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:textColor="@color/white"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/app_name"
android:layout_margin="10dp"
android:textSize="20sp"
android:id="@+id/main_title"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/main_rec"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1000"/>
<LinearLayout
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal"
android:padding="7dp"
android:id="@+id/main_bottom_bar">
<EditText
android:background="@drawable/chat_edittext_background"
android:padding="7dp"
android:id="@+id/main_send_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_weight="10"
android:maxEms="3"/>
<LinearLayout
android:layout_marginLeft="7dp"
android:layout_width="0dp"
android:layout_height="33dp"
android:gravity="center"
android:layout_weight="2"
android:orientation="vertical">
<ImageButton
android:background="@drawable/chat_message_background"
android:src="@drawable/ic_send_black_24dp"
android:id="@+id/main_send"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/send"
android:gravity="center"
android:textSize="12sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment