Commit a90d72a4 authored by fallenstardust's avatar fallenstardust

合并mycard为共有渠道

parent 724464ff
......@@ -27,11 +27,11 @@ android {
//assets.srcDirs = ['assets_en']
}
ko {
applicationId "cn.garymb.ygomobile.ko"
applicationId "cn.garymb.ygomobile.KO"
versionName "KO3.3.3"
//assets.srcDirs = ['assets_ko']
}
mycard {
cn {
}
}
buildTypes {
......
......@@ -6,11 +6,8 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.webkit.WebView;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.plus.DefWebChromeClient;
import cn.garymb.ygomobile.ui.widget.WebViewPlus;
public class WebActivity extends BaseActivity {
......
......@@ -50,7 +50,7 @@ import cn.garymb.ygomobile.ui.adapters.ServerListAdapter;
import cn.garymb.ygomobile.ui.adapters.SimpleListAdapter;
import cn.garymb.ygomobile.ui.cards.CardSearchAcitivity;
import cn.garymb.ygomobile.ui.cards.DeckManagerActivity;
import cn.garymb.ygomobile.ui.online.MyCardActivity;
import cn.garymb.ygomobile.ui.mycard.MyCardActivity;
import cn.garymb.ygomobile.ui.plus.DefaultOnBoomListener;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant;
......
package cn.garymb.ygomobile.ui.online;
package cn.garymb.ygomobile.ui.mycard;
import android.annotation.SuppressLint;
import android.app.Activity;
......@@ -9,7 +9,6 @@ import android.net.Uri;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.webkit.JavascriptInterface;
import com.tencent.smtt.sdk.WebView;
......
package cn.garymb.ygomobile.ui.online;
package cn.garymb.ygomobile.ui.mycard;
import android.content.Intent;
import android.net.Uri;
......@@ -30,7 +30,7 @@ import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.activities.BaseActivity;
import cn.garymb.ygomobile.ui.cards.DeckManagerActivity;
import cn.garymb.ygomobile.ui.online.mcchat.SplashActivity;
import cn.garymb.ygomobile.ui.mycard.mcchat.SplashActivity;
public class MyCardActivity extends BaseActivity implements MyCard.MyCardListener, NavigationView.OnNavigationItemSelectedListener {
......
package cn.garymb.ygomobile.ui.online;
package cn.garymb.ygomobile.ui.mycard;
import android.content.Context;
import android.util.AttributeSet;
import cn.garymb.ygomobile.ui.plus.X5WebView;
public class MyCardWebView extends X5WebView {
public MyCardWebView(Context context) {
super(context);
......
package cn.garymb.ygomobile.ui.plus;
package cn.garymb.ygomobile.ui.mycard;
import android.annotation.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.util.*;
import android.view.*;
import android.widget.*;
import com.tencent.smtt.sdk.*;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
public class X5WebView extends WebView {
private WebViewClient client = new WebViewClient() {
/**
* 防止加载网页时调起系统浏览器
*/
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
};
private WebViewClient client = new WebViewClient() {
/**
* 防止加载网页时调起系统浏览器
*/
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
};
@SuppressLint("SetJavaScriptEnabled")
public X5WebView(Context arg0, AttributeSet arg1) {
super(arg0, arg1);
this.setWebViewClient(client);
// this.setWebChromeClient(chromeClient);
// WebStorage webStorage = WebStorage.getInstance();
initWebViewSettings();
this.getView().setClickable(true);
}
@SuppressLint("SetJavaScriptEnabled")
public X5WebView(Context arg0, AttributeSet arg1) {
super(arg0, arg1);
this.setWebViewClient(client);
// this.setWebChromeClient(chromeClient);
// WebStorage webStorage = WebStorage.getInstance();
initWebViewSettings();
this.getView().setClickable(true);
}
private void initWebViewSettings() {
WebSettings webSetting = this.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
webSetting.setAllowFileAccess(true);
//webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
webSetting.setSupportZoom(true);
webSetting.setBuiltInZoomControls(true);
webSetting.setUseWideViewPort(true);
//禁止多窗口
webSetting.setSupportMultipleWindows(false);
// webSetting.setLoadWithOverviewMode(true);
webSetting.setAppCacheEnabled(true);
// webSetting.setDatabaseEnabled(true);
webSetting.setDomStorageEnabled(true);
webSetting.setGeolocationEnabled(true);
webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
// webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
// webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
private void initWebViewSettings() {
WebSettings webSetting = this.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
webSetting.setAllowFileAccess(true);
//webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
webSetting.setSupportZoom(true);
webSetting.setBuiltInZoomControls(true);
webSetting.setUseWideViewPort(true);
//禁止多窗口
webSetting.setSupportMultipleWindows(false);
// webSetting.setLoadWithOverviewMode(true);
webSetting.setAppCacheEnabled(true);
// webSetting.setDatabaseEnabled(true);
webSetting.setDomStorageEnabled(true);
webSetting.setGeolocationEnabled(true);
webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
// webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
// webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
// this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
// settings 的设计
// this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
// settings 的设计
webSetting.setSaveFormData(true);
webSetting.setDatabaseEnabled(true);
webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
......@@ -61,10 +62,10 @@ public class X5WebView extends WebView {
setHorizontalScrollBarEnabled(false);
webSetting.setAllowContentAccess(true);
webSetting.setMixedContentMode(WebSettings.LOAD_NORMAL);
}
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
/*boolean ret = super.drawChild(canvas, child, drawingTime);
canvas.save();
Paint paint = new Paint();
......@@ -86,13 +87,13 @@ public class X5WebView extends WebView {
canvas.drawText(Build.MODEL, 10, 200, paint);
canvas.restore();
return ret;*/
return super.drawChild(canvas,child,drawingTime);
}
return super.drawChild(canvas, child, drawingTime);
}
public X5WebView(Context arg0) {
super(arg0);
setBackgroundColor(85621);
}
public X5WebView(Context arg0) {
super(arg0);
setBackgroundColor(85621);
}
}
package cn.garymb.ygomobile.ui.mycard.mcchat;
import org.jivesoftware.smack.packet.Message;
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;
package cn.garymb.ygomobile.ui.mycard.mcchat;
import org.jivesoftware.smack.packet.Message;
import cn.garymb.ygomobile.ui.online.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.ServiceManagement;
public class ChatMessage {
private String name;
......
package cn.garymb.ygomobile.ui.online.mcchat;
package cn.garymb.ygomobile.ui.mycard.mcchat;
import android.app.Activity;
import android.os.Bundle;
......@@ -14,10 +14,10 @@ import android.widget.TextView;
import org.jivesoftware.smack.packet.Message;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.online.mcchat.adapter.ChatAdapter;
import cn.garymb.ygomobile.ui.online.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.ui.online.mcchat.management.UserManagement;
import cn.garymb.ygomobile.ui.online.mcchat.util.Util;
import cn.garymb.ygomobile.ui.mycard.mcchat.adapter.ChatAdapter;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.UserManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.Util;
public class McchatActivity extends Activity implements ChatListener {
......
package cn.garymb.ygomobile.ui.online.mcchat;
package cn.garymb.ygomobile.ui.mycard.mcchat;
import android.app.Activity;
import android.content.Context;
......@@ -14,10 +14,10 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.online.MyCardActivity;
import cn.garymb.ygomobile.ui.online.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.ui.online.mcchat.management.UserManagement;
import cn.garymb.ygomobile.ui.online.mcchat.util.Util;
import cn.garymb.ygomobile.ui.mycard.MyCardActivity;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.UserManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.Util;
public class SplashActivity extends Activity {
......
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.*;
package cn.garymb.ygomobile.ui.mycard.mcchat.adapter;
import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.List;
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 cn.garymb.ygomobile.ui.mycard.mcchat.ChatMessage;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.UserManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.ImageUtil;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.Util;
import android.app.*;
public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ViewHolder> {
private List<ChatMessage> data;
......@@ -74,8 +80,8 @@ public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ViewHolder> {
@Override
public boolean onLongClick(View p1) {
Util.fzMessage(context,cm.getMessage());
Util.show(context,"已复制到剪贴板");
Util.fzMessage(context, cm.getMessage());
Util.show(context, "已复制到剪贴板");
// TODO: Implement this method
return true;
}
......
package cn.garymb.ygomobile.ui.mycard.mcchat.management;
import android.os.Handler;
import android.util.Log;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.muc.MultiUserChatException;
import org.jivesoftware.smackx.muc.MultiUserChatManager;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import cn.garymb.ygomobile.ui.mycard.mcchat.ChatListener;
import cn.garymb.ygomobile.ui.mycard.mcchat.ChatMessage;
import cn.garymb.ygomobile.ui.mycard.mcchat.util.TaxiConnectionListener;
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)
.setHost("chat.mycard.moe")
.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.mycard.mcchat.management;
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;
package cn.garymb.ygomobile.ui.mycard.mcchat.util;
import android.net.Uri;
import android.widget.*;
import com.bumptech.glide.*;
......
package cn.garymb.ygomobile.ui.mycard.mcchat.util;
/**
* 连接监听类
*/
import android.util.Log;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.XMPPConnection;
import java.util.Timer;
import java.util.TimerTask;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.ServiceManagement;
import cn.garymb.ygomobile.ui.mycard.mcchat.management.UserManagement;
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.mycard.mcchat.util;
import android.app.Activity;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
public class Util {
//提示
public static void show(Context context, String message) {
Toast.makeText(context, 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(Context context, String message) {
ClipboardManager cmb = (ClipboardManager) context.getSystemService(context.CLIPBOARD_SERVICE);
cmb.setText(message);//复制命令
}
}
package cn.garymb.ygomobile.ui.online.mcchat.view;
package cn.garymb.ygomobile.ui.mycard.mcchat.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
......@@ -12,15 +12,13 @@ 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;
......@@ -43,7 +41,7 @@ public class YuanImage extends android.support.v7.widget.AppCompatImageView {
@Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable() ;
Drawable drawable = getDrawable();
if (drawable == null) {
return;
}
......@@ -68,6 +66,7 @@ public class YuanImage extends android.support.v7.widget.AppCompatImageView {
/**
* 获取裁剪后的圆形图片
*
* @param radius 半径
*/
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
......@@ -89,31 +88,31 @@ public class YuanImage extends android.support.v7.widget.AppCompatImageView {
squareWidth = squareHeight = bmpHeight;
x = (bmpWidth - bmpHeight) / 2;
y = 0;
squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth,squareHeight);
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);
scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);
} else {
scaledSrcBmp = squareBitmap;
}
Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(),
scaledSrcBmp.getHeight(),
Config.ARGB_8888);
scaledSrcBmp.getHeight(),
Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(),scaledSrcBmp.getHeight());
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);
scaledSrcBmp.getHeight() / 2,
scaledSrcBmp.getWidth() / 2,
paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
bmp = null;
......
......@@ -183,6 +183,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
public void onNoUpdateAvailable() {
Toast.makeText(getContext(), R.string.Already_Lastest, Toast.LENGTH_SHORT).show();
}
@Override
public void onUpdateAvailable(AppBean appBean) {
PgyUpdateManager.downLoadApk(appBean.getDownloadURL());
......
......@@ -3,7 +3,7 @@ package cn.garymb.ygomobile.ui.widget;
import android.content.Context;
import android.util.AttributeSet;
import cn.garymb.ygomobile.ui.plus.X5WebView;
import cn.garymb.ygomobile.ui.mycard.X5WebView;
public class WebViewPlus extends X5WebView {
......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="cn.garymb.ygomobile.lite">
<application>
<activity
android:name="cn.garymb.ygomobile.ui.online.MyCardActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:launchMode="singleTop"
android:theme="@style/AppTheme.Mycard"
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 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.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)
.setHost("chat.mycard.moe")
.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;
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.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.*;
public class Util
{
//提示
public static void show(Context context,String message){
Toast.makeText(context,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(Context context,String message){
ClipboardManager cmb = (ClipboardManager) context.getSystemService(context.CLIPBOARD_SERVICE);
cmb.setText(message);//复制命令
}
}
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