first commit

This commit is contained in:
2026-02-16 18:24:19 +08:00
commit c458f3c707
472 changed files with 61558 additions and 0 deletions

85
app/build.gradle Normal file
View File

@@ -0,0 +1,85 @@
apply plugin: 'com.android.application'
android {
signingConfigs { release {
storeFile file('./keystore/gamehall.keystore')
storePassword 'tswl2015'
keyPassword 'tswl2015'
keyAlias = 'gamehall'
v1SigningEnabled true
v2SigningEnabled true
}
debug {
storeFile file('./keystore/gamehall.keystore')
storePassword 'tswl2015'
keyPassword 'tswl2015'
keyAlias = 'gamehall'
v1SigningEnabled true
v2SigningEnabled true
}
}
compileSdk 33
buildToolsVersion '33.0.0'
defaultConfig {
applicationId "com.jx.jyhd"
minSdkVersion 21
targetSdkVersion 32
versionCode= 3
versionName="3.6.3"
multiDexEnabled true
ndk {
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'//, 'mips', 'mips64'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
dependencies {
//noinspection GradleCompatible
implementation 'com.android.support:support-v4:28.0.0'
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.yanzhenjie.nohttp:nohttp:1.1.2'
implementation 'com.orhanobut:logger:2.2.0'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.tencent.bugly:crashreport:3.4.4'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.umeng.sdk:common:1.5.0'
implementation 'com.umeng.sdk:analytics:7.5.0'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.squareup.okio:okio:3.6.0'
implementation 'org.nanohttpd:nanohttpd:2.3.1'
implementation 'com.qiniu:happy-dns:2.0.0'
implementation ('com.qiniu:qiniu-android-sdk:8.5.0'){
exclude (group: 'com.squareup.okhttp3', module: 'okhttp')
}
implementation('com.qiniu:qiniu-java-sdk:7.7.0') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
implementation 'android.arch.lifecycle:extensions:1.1.1'
api 'com.tencent.tbs:tbssdk:44286'
api 'com.tencent.mm.opensdk:wechat-sdk-android:6.8.11'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/AMap2DMap_5.2.0_AMapSearch_6.9.2_AMapLocation_4.7.2_20191009.jar')
}

BIN
app/libs/agora-rtc-sdk.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
app/libs/andserver1.0.1.jar Normal file

Binary file not shown.

BIN
app/libs/ddmlib.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
app/libs/xUtils-2.6.14.jar Normal file

Binary file not shown.

BIN
app/libs/zxing.jar Normal file

Binary file not shown.

View File

@@ -0,0 +1,18 @@
{
"version": 2,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.jx.jyhd",
"variantName": "processReleaseResources",
"elements": [
{
"type": "SINGLE",
"filters": [],
"versionCode": 3,
"versionName": "3.6.3",
"outputFile": "app-release.apk"
}
]
}

View File

@@ -0,0 +1,243 @@
<?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="com.jx.jyhd"
android:versionCode="3"
android:versionName="3.6.3">
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="32"
tools:ignore="GradleOverrides" />
<queries>
<!-- 微信 -->
<package android:name="com.tencent.mm" />
<!-- QQ -->
<package android:name="com.tencent.mobileqq" />
<package android:name="com.tencent.tim" />
<package android:name="com.tencent.qqlite" />
<package android:name="com.tencent.mobileqqi" />
<!-- 抖音 -->
<package android:name="com.ss.android.ugc.aweme" />
<package android:name="com.ss.android.ugc.aweme.lite" />
<package android:name="com.zhiliaoapp.musically" />
</queries>
<!-- 已移除未使用的通讯录权限 -->
<!-- <uses-permission android:name="android.permission.READ_CONTACTS" /> -->
<!-- <uses-permission android:name="android.permission.WRITE_CONTACTS" /> -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.CAMERA" />
<!-- APK安装权限Android 8.0+需要 -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<!-- 用于进行网络定位 -->
<!--<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />-->
<!-- 用于访问GPS定位 -->
<!--<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />-->
<!-- 用于获取运营商信息,用于支持提供运营商信息相关的接口 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- 用于访问wifi网络信息wifi信息会用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- 用于获取wifi的获取权限wifi信息会用来进行网络定位 -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- 用于读取手机当前的状态 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- 用于写入缓存数据到扩展存储卡 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.READ_SETTINGS" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK" >
</uses-permission>
<application
android:name="com.tsgame.tsgame_niuniu.system.Myapplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/logo6"
android:label="@string/app_name6"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="m">
<!-- 添加FileProvider配置使用Support库版本 -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<activity
android:name="com.tagmae.tsgame_erwang.weclomeactivity1"
android:screenOrientation="landscape"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="gamepaywelcome" />
</intent-filter>
</activity>
<activity android:name="com.xys.libzxing.zxing.activity.CaptureActivity" />
<activity
android:name="com.tagmae.tsgame_erwang.webviewActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true"
android:hardwareAccelerated="true"
android:screenOrientation="sensorLandscape"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<!--微信appID-->
<data android:scheme="wxd2bd650e06bdfe58" />
</intent-filter>
</activity>
<activity
android:name="com.tagmae.tsgame_erwang.Mainwebactivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="sensorLandscape"
android:windowSoftInputMode="stateHidden|adjustResize" >
</activity>
<activity
android:name="com.tagmae.tsgame_erwang.NewwebviewActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="sensorLandscape"
android:windowSoftInputMode="stateHidden|adjustResize"
android:hardwareAccelerated="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<!--微信appID-->
<data android:scheme="wxd2bd650e06bdfe58" />
</intent-filter>
</activity>
<activity
android:name="com.tagmae.tsgame_erwang.openwebActivity1"
android:configChanges="orientation|keyboardHidden|screenSize"
android:hardwareAccelerated="true"
android:screenOrientation="landscape"
android:launchMode="singleTop"
android:windowSoftInputMode="stateHidden|adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
<!--微信appID-->
<data android:scheme="gamepaywxd2bd650e06bdfe58" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.smtt.sdk.VideoActivity"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|screenSize|keyboardHidden"
android:exported="false"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="com.tencent.smtt.tbs.video.PLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.jx.jyhd.wxapi.WXPayEntryActivity"
android:exported="true"
android:launchMode="singleTop" >
<intent-filter>
<!--微信appID-->
<data android:scheme="wxd2bd650e06bdfe58" />
</intent-filter>
</activity>
<activity
android:name=".wxapi.WXEntryActivity"
android:exported="true"
android:taskAffinity="com.jx.jyhd"
android:launchMode="singleTask" />
<receiver
android:name="com.jx.jyhd.simcpux.AppRegister"
android:exported="false"
android:permission="com.tencent.mm.plugin.permission.SEND">
<intent-filter>
<action android:name="com.tencent.mm.plugin.openapi.Intent.ACTION_REFRESH_WXAPP" />
</intent-filter>
</receiver>
<receiver
android:name="com.tsgame.tsgame_niuniu.receiver.PhoneStateBroadCastReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<!-- 高德地图 -->
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="6bb9e6dcc10358040b9d20cf70044b57" />
<!-- 配置APP ID -->
<meta-data
android:name="BUGLY_APPID"
android:value="4e3658499c" />
<!-- 配置APP版本号 -->
<meta-data
android:name="BUGLY_APP_VERSION"
android:value="3.4.4" />
<!-- 配置APP渠道号 -->
<meta-data
android:name="BUGLY_APP_CHANNEL"
android:value="dhxj" />
<!-- 配置Bugly调试模式true或者false-->
<meta-data
android:name="BUGLY_ENABLE_DEBUG"
android:value="true" />
</application>
<queries>
<package android:name="com.tencent.mm"/>
<!-- 添加QQ包查询 -->
<package android:name="com.tencent.mobileqq"/>
<!-- 添加抖音包查询 -->
<package android:name="com.ss.android.ugc.aweme"/>
</queries>
</manifest>

View File

@@ -0,0 +1,145 @@
//notation: js file can only use this kind of comments
//since comments will cause error when use in webview.loadurl,
//comments will be remove by java use regexp
(function() {
if (window.WebViewJavascriptBridge) {
return;
}
var messagingIframe;
var sendMessageQueue = [];
var receiveMessageQueue = [];
var messageHandlers = {};
var CUSTOM_PROTOCOL_SCHEME = 'yy';
var QUEUE_HAS_MESSAGE = '__QUEUE_MESSAGE__/';
var responseCallbacks = {};
var uniqueId = 1;
// 创建队列iframe
function _createQueueReadyIframe(doc) {
messagingIframe = doc.createElement('iframe');
messagingIframe.style.display = 'none';
doc.documentElement.appendChild(messagingIframe);
}
//set default messageHandler 初始化默认的消息线程
function init(messageHandler) {
if (WebViewJavascriptBridge._messageHandler) {
throw new Error('WebViewJavascriptBridge.init called twice');
}
WebViewJavascriptBridge._messageHandler = messageHandler;
var receivedMessages = receiveMessageQueue;
receiveMessageQueue = null;
for (var i = 0; i < receivedMessages.length; i++) {
_dispatchMessageFromNative(receivedMessages[i]);
}
}
// 发送
function send(data, responseCallback) {
_doSend({
data: data
}, responseCallback);
}
// 注册线程 往数组里面添加值
function registerHandler(handlerName, handler) {
messageHandlers[handlerName] = handler;
}
// 调用线程
function callHandler(handlerName, data, responseCallback) {
_doSend({
handlerName: handlerName,
data: data
}, responseCallback);
}
//sendMessage add message, 触发native处理 sendMessage
function _doSend(message, responseCallback) {
if (responseCallback) {
var callbackId = 'cb_' + (uniqueId++) + '_' + new Date().getTime();
responseCallbacks[callbackId] = responseCallback;
message.callbackId = callbackId;
}
sendMessageQueue.push(message);
messagingIframe.src = CUSTOM_PROTOCOL_SCHEME + '://' + QUEUE_HAS_MESSAGE;
}
// 提供给native调用,该函数作用:获取sendMessageQueue返回给native,由于android不能直接获取返回的内容,所以使用url shouldOverrideUrlLoading 的方式返回内容
function _fetchQueue() {
var messageQueueString = JSON.stringify(sendMessageQueue);
sendMessageQueue = [];
//android can't read directly the return data, so we can reload iframe src to communicate with java
messagingIframe.src = CUSTOM_PROTOCOL_SCHEME + '://return/_fetchQueue/' + encodeURIComponent(messageQueueString);
}
//提供给native使用,
function _dispatchMessageFromNative(messageJSON) {
setTimeout(function() {
var message = JSON.parse(messageJSON);
var responseCallback;
//java call finished, now need to call js callback function
if (message.responseId) {
responseCallback = responseCallbacks[message.responseId];
if (!responseCallback) {
return;
}
responseCallback(message.responseData);
delete responseCallbacks[message.responseId];
} else {
//直接发送
if (message.callbackId) {
var callbackResponseId = message.callbackId;
responseCallback = function(responseData) {
_doSend({
responseId: callbackResponseId,
responseData: responseData
});
};
}
var handler = WebViewJavascriptBridge._messageHandler;
if (message.handlerName) {
handler = messageHandlers[message.handlerName];
}
//查找指定handler
try {
handler(message.data, responseCallback);
} catch (exception) {
if (typeof console != 'undefined') {
console.log("WebViewJavascriptBridge: WARNING: javascript handler threw.", message, exception);
}
}
}
});
}
//提供给native调用,receiveMessageQueue 在会在页面加载完后赋值为null,所以
function _handleMessageFromNative(messageJSON) {
console.log(messageJSON);
if (receiveMessageQueue) {
receiveMessageQueue.push(messageJSON);
}
_dispatchMessageFromNative(messageJSON);
}
var WebViewJavascriptBridge = window.WebViewJavascriptBridge = {
init: init,
send: send,
registerHandler: registerHandler,
callHandler: callHandler,
_fetchQueue: _fetchQueue,
_handleMessageFromNative: _handleMessageFromNative
};
var doc = document;
_createQueueReadyIframe(doc);
var readyEvent = doc.createEvent('Events');
readyEvent.initEvent('WebViewJavascriptBridgeReady');
readyEvent.bridge = WebViewJavascriptBridge;
doc.dispatchEvent(readyEvent);
})();

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,146 @@
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>
js调用java
</title>
</head>
<body>
<p>
<xmp id="show">
</xmp>
</p>
<p>
<xmp id="init">
</xmp>
</p>
<p>
<input type="text" id="text1" value="用户名" />
</p>
<p>
<input type="text" id="text2" value="密码" />
</p>
<p>
<input type="button" id="enter" value="发消息给Native" onclick="testClick();"
/>
</p>
<p>
<input type="button" id="enter1" value="调用Native方法" onclick="testClick1();"
/>
</p>
<!--<p>-->
<!--<input type="button" id="enter2" value="显示html" onclick="testDiv();" />-->
<!--</p>-->
<!--<p>-->
<!--<input type="file" value="打开文件" />-->
<!--</p>-->
</body>
<script>
function testDiv() {
document.getElementById("show").innerHTML = document.getElementsByTagName("html")[0].innerHTML;
}
function testClick() {
var str1 = document.getElementById("text1").value;
var str2 = document.getElementById("text2").value;
//send message to native
var data = {id: 1, content: "这是一个图片 <img src=\"a.png\"/> test\r\nhahaha"};
var tp=1;
window.WebViewJavascriptBridge.callHandler('accreditlogin',tp,function(resp){
}
);
}
function testClick1() {
var str1 = document.getElementById("text1").value;
var str2 = document.getElementById("text2").value;
//call native method
var arrayObj = new Array(); 
var salesInfoDetail3 ={title:'',desc:'',data:'',type:''};
salesInfoDetail3.title="你好";
salesInfoDetail3.type=2;
arrayObj.push(salesInfoDetail3);
var salesInfoDetail4 ={title:'',desc:'',data:'',type:''};
salesInfoDetail4.title="---------------------------------------";
arrayObj.push(salesInfoDetail4);
var salesInfoDetail ={title:'',desc:'',data:'',type:''};
salesInfoDetail.title="你好";
salesInfoDetail.desc="你好";
salesInfoDetail.data="你好";
salesInfoDetail.type=1;
arrayObj.push(salesInfoDetail);
var salesInfoDetail2 ={title:'',desc:'',data:'',type:''};
salesInfoDetail2.title="你好";
salesInfoDetail2.desc="你好";
salesInfoDetail2.type=0;
arrayObj.push(salesInfoDetail2);
var json = JSON.stringify(arrayObj);
alert(json);
window.WebViewJavascriptBridge.callHandler(
'daying'
,json
, function(responseData) {
alert(responseData);
}
);
}
function bridgeLog(logContent) {
document.getElementById("show").innerHTML = logContent;
}
function connectWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) {
callback(WebViewJavascriptBridge)
} else {
document.addEventListener(
'WebViewJavascriptBridgeReady'
, function() {
callback(WebViewJavascriptBridge)
},
false
);
}
}
connectWebViewJavascriptBridge(function(bridge) {
bridge.init(function(message, responseCallback) {
console.log('JS got a message', message);
var data = {
'Javascript Responds': '测试中文!'
};
if (responseCallback) {
console.log('JS responding with', data);
responseCallback(data);
}
});
bridge.registerHandler("functionInJs", function(data, responseCallback) {
document.getElementById("show").innerHTML = ("data from Java: = " + data);
if (responseCallback) {
var responseData = "Javascript Says Right back aka!";
responseCallback(responseData);
}
});
})
</script>
</html>

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<game>
<agent id="00bA05haB0d9ZC0fwGD09Q2OA30insbQ" name="天盛网络"/>
<game id="G2hw0ubng0zcoI0r4mx3H2yr4GejidwO" name="友乐游戏"/>
<channel id="frdt0C1GG0t91P0McFo0rbA1he5yurbS" name="友乐互动游戏"/>
<version value="42" name="1.42"/>
</game>

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,24 @@
import java.util.Scanner;
public class BoolTest {
public static void main (String[]args){
Scanner input= new Scanner(System.in);
System.out.println("我行我素购物管理系统》客户管理系统》添加客户信息\n");
System.out.print("请输入会员号4位整数:");
int huiyuan=input.nextInt();
System.out.print("请输入会员生日(月/日两位数表示):");
int shenri=input.nextInt();
System.out.print("请输入积分:");
int jifen=input.nextInt();
if(huiyuan>=1000){
System.out.println("已录入的信息是");
System.out.print("\t"+huiyuan);
System.out.print("\t"+shenri);
System.out.print("\t"+jifen);
}
else{
System.out.print("登入信息失败");
}
}
}

View File

@@ -0,0 +1,516 @@
/*
* Copyright (c) 2014 Badoo Trading Limited
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Portions of documentation in this code are modifications based on work created and
* shared by Android Open Source Project and used according to terms described in the
* Apache License, Version 2.0
*/
package com.badoo.mobile.util;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import java.lang.ref.WeakReference;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* Memory safer implementation of android.os.Handler
* <p/>
* Original implementation of Handlers always keeps hard reference to handler in queue of execution.
* If you create anonymous handler and post delayed message into it, it will keep all parent class
* for that time in memory even if it could be cleaned.
* <p/>
* This implementation is trickier, it will keep WeakReferences to runnables and messages,
* and GC could collect them once WeakHandler instance is not referenced any more
* <p/>
*
* @see android.os.Handler
*
* Created by Dmytro Voronkevych on 17/06/2014.
*/
@SuppressWarnings("unused")
public class WeakHandler {
private final Handler.Callback mCallback; // hard reference to Callback. We need to keep callback in memory
private final ExecHandler mExec;
private Lock mLock = new ReentrantLock();
@SuppressWarnings("ConstantConditions")
@VisibleForTesting
final ChainedRef mRunnables = new ChainedRef(mLock, null);
/**
* Default constructor associates this handler with the {@link Looper} for the
* current thread.
*
* If this thread does not have a looper, this handler won't be able to receive messages
* so an exception is thrown.
*/
public WeakHandler() {
mCallback = null;
mExec = new ExecHandler();
}
/**
* Constructor associates this handler with the {@link Looper} for the
* current thread and takes a callback interface in which you can handle
* messages.
*
* If this thread does not have a looper, this handler won't be able to receive messages
* so an exception is thrown.
*
* @param callback The callback interface in which to handle messages, or null.
*/
public WeakHandler(@Nullable Handler.Callback callback) {
mCallback = callback; // Hard referencing body
mExec = new ExecHandler(new WeakReference<>(callback)); // Weak referencing inside ExecHandler
}
/**
* Use the provided {@link Looper} instead of the default one.
*
* @param looper The looper, must not be null.
*/
public WeakHandler(@NonNull Looper looper) {
mCallback = null;
mExec = new ExecHandler(looper);
}
/**
* Use the provided {@link Looper} instead of the default one and take a callback
* interface in which to handle messages.
*
* @param looper The looper, must not be null.
* @param callback The callback interface in which to handle messages, or null.
*/
public WeakHandler(@NonNull Looper looper, @NonNull Handler.Callback callback) {
mCallback = callback;
mExec = new ExecHandler(looper, new WeakReference<>(callback));
}
/**
* Causes the Runnable r to be added to the message queue.
* The runnable will be run on the thread to which this handler is
* attached.
*
* @param r The Runnable that will be executed.
*
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean post(@NonNull Runnable r) {
return mExec.post(wrapRunnable(r));
}
/**
* Causes the Runnable r to be added to the message queue, to be run
* at a specific time given by <var>uptimeMillis</var>.
* <b>The time-base is {@link android.os.SystemClock#uptimeMillis}.</b>
* The runnable will be run on the thread to which this handler is attached.
*
* @param r The Runnable that will be executed.
* @param uptimeMillis The absolute time at which the callback should run,
* using the {@link android.os.SystemClock#uptimeMillis} time-base.
*
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public final boolean postAtTime(@NonNull Runnable r, long uptimeMillis) {
return mExec.postAtTime(wrapRunnable(r), uptimeMillis);
}
/**
* Causes the Runnable r to be added to the message queue, to be run
* at a specific time given by <var>uptimeMillis</var>.
* <b>The time-base is {@link android.os.SystemClock#uptimeMillis}.</b>
* The runnable will be run on the thread to which this handler is attached.
*
* @param r The Runnable that will be executed.
* @param uptimeMillis The absolute time at which the callback should run,
* using the {@link android.os.SystemClock#uptimeMillis} time-base.
*
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*
* @see android.os.SystemClock#uptimeMillis
*/
public final boolean postAtTime(Runnable r, Object token, long uptimeMillis) {
return mExec.postAtTime(wrapRunnable(r), token, uptimeMillis);
}
/**
* Causes the Runnable r to be added to the message queue, to be run
* after the specified amount of time elapses.
* The runnable will be run on the thread to which this handler
* is attached.
*
* @param r The Runnable that will be executed.
* @param delayMillis The delay (in milliseconds) until the Runnable
* will be executed.
*
* @return Returns true if the Runnable was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the Runnable will be processed --
* if the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public final boolean postDelayed(Runnable r, long delayMillis) {
return mExec.postDelayed(wrapRunnable(r), delayMillis);
}
/**
* Posts a message to an object that implements Runnable.
* Causes the Runnable r to executed on the next iteration through the
* message queue. The runnable will be run on the thread to which this
* handler is attached.
* <b>This method is only for use in very special circumstances -- it
* can easily starve the message queue, cause ordering problems, or have
* other unexpected side-effects.</b>
*
* @param r The Runnable that will be executed.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean postAtFrontOfQueue(Runnable r) {
return mExec.postAtFrontOfQueue(wrapRunnable(r));
}
/**
* Remove any pending posts of Runnable r that are in the message queue.
*/
public final void removeCallbacks(Runnable r) {
final WeakRunnable runnable = mRunnables.remove(r);
if (runnable != null) {
mExec.removeCallbacks(runnable);
}
}
/**
* Remove any pending posts of Runnable <var>r</var> with Object
* <var>token</var> that are in the message queue. If <var>token</var> is null,
* all callbacks will be removed.
*/
public final void removeCallbacks(Runnable r, Object token) {
final WeakRunnable runnable = mRunnables.remove(r);
if (runnable != null) {
mExec.removeCallbacks(runnable, token);
}
}
/**
* Pushes a message onto the end of the message queue after all pending messages
* before the current time. It will be received in callback,
* in the thread attached to this handler.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendMessage(Message msg) {
return mExec.sendMessage(msg);
}
/**
* Sends a Message containing only the what value.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendEmptyMessage(int what) {
return mExec.sendEmptyMessage(what);
}
/**
* Sends a Message containing only the what value, to be delivered
* after the specified amount of time elapses.
* @see #sendMessageDelayed(android.os.Message, long)
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendEmptyMessageDelayed(int what, long delayMillis) {
return mExec.sendEmptyMessageDelayed(what, delayMillis);
}
/**
* Sends a Message containing only the what value, to be delivered
* at a specific time.
* @see #sendMessageAtTime(android.os.Message, long)
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendEmptyMessageAtTime(int what, long uptimeMillis) {
return mExec.sendEmptyMessageAtTime(what, uptimeMillis);
}
/**
* Enqueue a message into the message queue after all pending messages
* before (current time + delayMillis). You will receive it in
* callback, in the thread attached to this handler.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the message will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public final boolean sendMessageDelayed(Message msg, long delayMillis) {
return mExec.sendMessageDelayed(msg, delayMillis);
}
/**
* Enqueue a message into the message queue after all pending messages
* before the absolute time (in milliseconds) <var>uptimeMillis</var>.
* <b>The time-base is {@link android.os.SystemClock#uptimeMillis}.</b>
* You will receive it in callback, in the thread attached
* to this handler.
*
* @param uptimeMillis The absolute time at which the message should be
* delivered, using the
* {@link android.os.SystemClock#uptimeMillis} time-base.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting. Note that a
* result of true does not mean the message will be processed -- if
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
return mExec.sendMessageAtTime(msg, uptimeMillis);
}
/**
* Enqueue a message at the front of the message queue, to be processed on
* the next iteration of the message loop. You will receive it in
* callback, in the thread attached to this handler.
* <b>This method is only for use in very special circumstances -- it
* can easily starve the message queue, cause ordering problems, or have
* other unexpected side-effects.</b>
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendMessageAtFrontOfQueue(Message msg) {
return mExec.sendMessageAtFrontOfQueue(msg);
}
/**
* Remove any pending posts of messages with code 'what' that are in the
* message queue.
*/
public final void removeMessages(int what) {
mExec.removeMessages(what);
}
/**
* Remove any pending posts of messages with code 'what' and whose obj is
* 'object' that are in the message queue. If <var>object</var> is null,
* all messages will be removed.
*/
public final void removeMessages(int what, Object object) {
mExec.removeMessages(what, object);
}
/**
* Remove any pending posts of callbacks and sent messages whose
* <var>obj</var> is <var>token</var>. If <var>token</var> is null,
* all callbacks and messages will be removed.
*/
public final void removeCallbacksAndMessages(Object token) {
mExec.removeCallbacksAndMessages(token);
}
/**
* Check if there are any pending posts of messages with code 'what' in
* the message queue.
*/
public final boolean hasMessages(int what) {
return mExec.hasMessages(what);
}
/**
* Check if there are any pending posts of messages with code 'what' and
* whose obj is 'object' in the message queue.
*/
public final boolean hasMessages(int what, Object object) {
return mExec.hasMessages(what, object);
}
public final Looper getLooper() {
return mExec.getLooper();
}
private WeakRunnable wrapRunnable(@NonNull Runnable r) {
//noinspection ConstantConditions
if (r == null) {
throw new NullPointerException("Runnable can't be null");
}
final ChainedRef hardRef = new ChainedRef(mLock, r);
mRunnables.insertAfter(hardRef);
return hardRef.wrapper;
}
private static class ExecHandler extends Handler {
private final WeakReference<Handler.Callback> mCallback;
ExecHandler() {
mCallback = null;
}
ExecHandler(WeakReference<Handler.Callback> callback) {
mCallback = callback;
}
ExecHandler(Looper looper) {
super(looper);
mCallback = null;
}
ExecHandler(Looper looper, WeakReference<Handler.Callback> callback) {
super(looper);
mCallback = callback;
}
@Override
public void handleMessage(@NonNull Message msg) {
if (mCallback == null) {
return;
}
final Handler.Callback callback = mCallback.get();
if (callback == null) { // Already disposed
return;
}
callback.handleMessage(msg);
}
}
static class WeakRunnable implements Runnable {
private final WeakReference<Runnable> mDelegate;
private final WeakReference<ChainedRef> mReference;
WeakRunnable(WeakReference<Runnable> delegate, WeakReference<ChainedRef> reference) {
mDelegate = delegate;
mReference = reference;
}
@Override
public void run() {
final Runnable delegate = mDelegate.get();
final ChainedRef reference = mReference.get();
if (reference != null) {
reference.remove();
}
if (delegate != null) {
delegate.run();
}
}
}
static class ChainedRef {
@Nullable
ChainedRef next;
@Nullable
ChainedRef prev;
@NonNull
final Runnable runnable;
@NonNull
final WeakRunnable wrapper;
@NonNull
Lock lock;
public ChainedRef(@NonNull Lock lock, @NonNull Runnable r) {
this.runnable = r;
this.lock = lock;
this.wrapper = new WeakRunnable(new WeakReference<>(r), new WeakReference<>(this));
}
public WeakRunnable remove() {
lock.lock();
try {
if (prev != null) {
prev.next = next;
}
if (next != null) {
next.prev = prev;
}
prev = null;
next = null;
} finally {
lock.unlock();
}
return wrapper;
}
public void insertAfter(@NonNull ChainedRef candidate) {
lock.lock();
try {
if (this.next != null) {
this.next.prev = candidate;
}
candidate.next = this.next;
this.next = candidate;
candidate.prev = this;
} finally {
lock.unlock();
}
}
@Nullable
public WeakRunnable remove(Runnable obj) {
lock.lock();
try {
ChainedRef curr = this.next; // Skipping head
while (curr != null) {
if (curr.runnable == obj) { // We do comparison exactly how Handler does inside
return curr.remove();
}
curr = curr.next;
}
} finally {
lock.unlock();
}
return null;
}
}
}

View File

@@ -0,0 +1,21 @@
package com.bytedance.sdk.open.aweme.common.handler;
import com.bytedance.sdk.open.aweme.common.model.BaseReq;
import com.bytedance.sdk.open.aweme.common.model.BaseResp;
/**
* 模拟抖音SDK的接口用于处理抖音分享请求和响应
*/
public interface IApiEventHandler {
/**
* 处理抖音SDK的请求
* @param req 请求对象
*/
void onReq(BaseReq req);
/**
* 处理抖音SDK的响应
* @param resp 响应对象
*/
void onResp(BaseResp resp);
}

View File

@@ -0,0 +1,16 @@
package com.bytedance.sdk.open.aweme.common.model;
/**
* 模拟抖音SDK的请求基类
*/
public class BaseReq {
private int type;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}

View File

@@ -0,0 +1,29 @@
package com.bytedance.sdk.open.aweme.common.model;
/**
* 模拟抖音SDK的响应基类
*/
public class BaseResp {
private int errorCode;
private String errorMsg;
public static final int SUCCESS = 0;
public static final int ERROR = -1;
public static final int CANCEL = -2;
public int getErrorCode() {
return errorCode;
}
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
}

View File

@@ -0,0 +1,21 @@
package com.ceshi.tsgame.shake;
import android.content.Context;
public class DensityUtil {
/**
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
*/
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
/**
* 根据手机的分辨率从 px(像素) 的单位 转成为 dp
*/
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
}

View File

@@ -0,0 +1,74 @@
package com.ceshi.tsgame.shake;
import java.util.HashMap;
import com.jx.jyhd.R;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
/**
* 声音所需工具
* @author wangyue
* */
public class NeedForSound {
/** 摇一摇需要的声音池view */
private SoundPool sndPool = null;
private HashMap<Integer, Integer> soundPoolMap = null;
private static NeedForSound needForSound = null;
public static NeedForSound getInstance() {
if (needForSound == null) {
needForSound = new NeedForSound();
}
return needForSound;
}
/** 添加声音 */
public void addSound(final Context context) {
soundPoolMap = new HashMap<Integer, Integer>();
//第一个参数指定支持多少个声音;第二个参数指定声音类型:第三个参数指定声音品质。
sndPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 5);
new Thread() {
public void run() {
try {
//http://www.tuicool.com/articles/yuyQ3a
soundPoolMap.put(0, sndPool.load(context.getResources().openRawResourceFd(R.raw.shake_sound_male), 1));
soundPoolMap.put(1, sndPool.load(context.getResources().openRawResourceFd(R.raw.shake_match), 1));
soundPoolMap.put(2, sndPool.load(context.getResources().openRawResourceFd(R.raw.shake_nomatch), 1));
} catch (NullPointerException e) {
}
}
}.start();
}
/** 播放摇一摇开始声音 */
public void playStartSound() {
try {
sndPool.play(soundPoolMap.get(0), (float) 1, (float) 1, 1, 0, (float) 1.2);// 播放摇一摇过程声音
} catch (NullPointerException e) {
} catch (IndexOutOfBoundsException e) {
}
}
/** 播放摇一摇结束声音 */
public void playEndSound() {
try {
//该方法的第一个参数指定播放哪个声音; leftVolume 、 rightVolume 指定左、右的音量: priority 指定播放声音的优先级,数值越大,优先级越高; loop 指定是否循环, 0 为不循环, -1 为循环; rate 指定播放的比率,数值可从 0.5 到 2 1 为正常比率。
sndPool.play(soundPoolMap.get(1), (float) 1, (float) 1, 0, 0, (float) 1.0);// 播放摇一摇结果声音
} catch (NullPointerException e) {
} catch (IndexOutOfBoundsException e) {
}
}
/** 什么都没摇到 */
public void playNothingSound() {
try {
sndPool.play(soundPoolMap.get(2), (float) 1, (float) 1, 0, 0, (float) 1.0);// 播放摇一摇结果声音
} catch (NullPointerException e) {
} catch (IndexOutOfBoundsException e) {
}
}
}

View File

@@ -0,0 +1,108 @@
package com.ceshi.tsgame.shake;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
/**
* 检测手机摇晃的监听器
*/
public class ShakeListener implements SensorEventListener {
// 速度阈值,当摇晃速度达到这值后产生作用
private static final int SPEED_SHRESHOLD = 3500;
// 两次检测的时间间隔
private static final int UPTATE_INTERVAL_TIME = 70;
// 传感器管理器
private SensorManager sensorManager;
// 重力传感器
private Sensor sensor;
// 重力感应监听器
private OnShakeListenerCallBack onShakeListener;
// 上下文
private Context mContext;
// 手机上一个位置时重力感应坐标
private float lastX;
private float lastY;
private float lastZ;
// 上次检测时间
private long lastUpdateTime;
// 构造器
public ShakeListener(Context context) {
// 获得监听对象
mContext = context;
start();
}
/**开始重力传感器的检测*/
public void start() {
// 获得传感器管理器
sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
if (sensorManager != null) {
// 获得重力传感器
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
// 注册
if (sensor != null) {
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
}
}
/**停止检测*/
public void stop() {
sensorManager.unregisterListener(this);
}
/**重力感应器感应获得变化数据*/
@Override
public void onSensorChanged(SensorEvent event) {
// 现在检测时间
long currentUpdateTime = System.currentTimeMillis();
// 两次检测的时间间隔
long timeInterval = currentUpdateTime - lastUpdateTime;
// 判断是否达到了检测时间间隔
if (timeInterval < UPTATE_INTERVAL_TIME)
return;
// 现在的时间变成last时间
lastUpdateTime = currentUpdateTime;
// 获得x,y,z坐标
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
// 获得x,y,z的变化值
float deltaX = x - lastX;
float deltaY = y - lastY;
float deltaZ = z - lastZ;
// 将现在的坐标变成last坐标
lastX = x;
lastY = y;
lastZ = z;
double speed = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / timeInterval * 10000;
// 达到速度阀值,发出提示
if (speed >= SPEED_SHRESHOLD) {
onShakeListener.onShake();
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
/**摇晃监听接口*/
public interface OnShakeListenerCallBack {
public void onShake();
}
/**设置重力感应监听器*/
public void setOnShakeListener(OnShakeListenerCallBack listener) {
onShakeListener = listener;
}
}

View File

@@ -0,0 +1,50 @@
package com.game.webgame.network;
import java.util.HashMap;
import java.util.Map;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
/**
* Created by Administrator on 2017/4/24.
*/
public class CustomStringRequest extends Request<String>{
private Map<String, String> mHeaders=new HashMap<String, String>();
public CustomStringRequest(String url, ErrorListener listener) {
super(url, listener);
}
public CustomStringRequest(int method, String url, ErrorListener listener) {
super(method, url, listener);
}
@Override
protected void deliverResponse(String arg0) {
}
@Override
protected Response<String> parseNetworkResponse(NetworkResponse Response) {
//在这里可以的到 response 对象, 然后从response的header中获取cookie信息
return null;
}
public void setCookie(String cookie) {
mHeaders.put("Cookie", cookie);
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return mHeaders;
}
}

View File

@@ -0,0 +1,317 @@
package com.game.webgame.network;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.util.EntityUtils;
import com.http.xml.callback.MyHttpCallBack;
import android.accounts.NetworkErrorException;
import android.os.AsyncTask;
import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
* Created by Administrator on 2017/4/24.
*/
public class HttpUtil {
private MyHttpCallBack callback;
private String method;
private Map<String, String> map;
private String path;
@SuppressWarnings(value = "deprecation")
private static HttpClient client;
private static OkHttpClient okHttpClient;
public static HttpClient gethttp(){
if(client==null){
client=new DefaultHttpClient();
}
return client;
}
public static OkHttpClient getOkHttpClientttp(){
if(okHttpClient==null){
okHttpClient=new OkHttpClient.Builder().readTimeout(5, TimeUnit.SECONDS).build();
}
return okHttpClient;
}
private HttpUtil() {
// TODO Auto-generated constructor stub
}
public HttpUtil(MyHttpCallBack callback,String method,String path,Map<String,String> map) {
this.callback = callback;
this.method = method;
this.path = path;
this.map = map;
}
public void startRequest(){
HttpAsyncTask task = new HttpAsyncTask();
task.execute();
}
/**
* http网络请求
* 两种方式GET/POST
* 方法很多1原生的请求,androidsdk自带的java网络请求类--HttpUrlConnection
* 2第三方封装的请求HttpClient(android自带的); NoHttp;volley;OkHttp;XUtil;
* @throws Exception
*/
public String doGetByHttpUrlConnection(String path,Map<String,String> map) throws Exception{
String params = getParamsFromMap(map);
path = path + "?"+params;
URL url = new URL(path);
//打开连接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//设置连接超时时间
conn.setConnectTimeout(5000);
//设置请求方式
conn.setRequestMethod("GET");
//判断是否能够连接成功--响应码(200成功300没有权限;400没有资源--可能是路径不对;
//500服务器内部错误----一般是传参名字或者类型出错了or是服务器本身报错)
int responseCode = conn.getResponseCode();
System.out.println("responseCode:"+responseCode);
if(responseCode==200){//ok
InputStream is = conn.getInputStream();
String result = getStringFromStream(is);
return result;
}else{//连接出错
throw new NetworkErrorException();
}
}
private String getStringFromStream(InputStream is) throws Exception{
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while((len = is.read(buffer))!=-1){
baos.write(buffer, 0, len);
}
String result = baos.toString();
baos.close();
is.close();
return result;
}
public String doPostByHttpUrlConnection(String path,Map<String,String> map) throws Exception{
URL url = new URL(path);
//打开连接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//设置连接超时时间
conn.setConnectTimeout(5000);
//设置请求方式
conn.setRequestMethod("POST");
//将参数一起通过post方式传过去然后再拿响应
OutputStream os = conn.getOutputStream();
//username=yolanda&pwd=nohttp
String params = getParamsFromMap(map);
os.write(params.getBytes());
int responseCode = conn.getResponseCode();
System.out.println("responseCode:"+responseCode);
if(responseCode==200){//ok
InputStream is = conn.getInputStream();
String result = getStringFromStream(is);
return result;
}else{//连接出错
throw new NetworkErrorException();
}
}
private String getParamsFromMap(Map<String,String> map){
StringBuffer buffer = new StringBuffer();
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
buffer.append(key).append("=").append(value).append("&");
}
buffer.deleteCharAt(buffer.length()-1);
return buffer.toString();
}
/**
* 第二种方式 HTTPCLIENT
* @return
* @throws Exception
* @throws ClientProtocolException
*/
@SuppressWarnings("deprecation")
public String doGetByHttpClient(String path,Map<String,String> map) throws ClientProtocolException, Exception{
if(map!=null){
String params = getParamsFromMap(map);
System.out.println("path:"+path);
path = path + "?"+params;
}
System.out.println(path);
//得到一个get请求
HttpGet get = new HttpGet(path);
//得到一个http请求客户端
HttpClient client =new DefaultHttpClient();
//设置请求超时时间5s
get.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
HttpResponse response = client.execute(get);
System.out.println("-----"+path);
//状态码--响应码
int statusCode = response.getStatusLine().getStatusCode();
System.out.println(statusCode);
if(statusCode==200){//ok
// InputStream is = response.getEntity().getContent();
// String result = getStringFromStream(is);
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity);
System.out.println(result);
return result;
}else{//连接出错
throw new NetworkErrorException();
}
}
@SuppressWarnings("deprecation")
public String doPostByHttpClient(String path,Map<String,String> map) throws Exception{
//得到一个http请求客户端
HttpClient client = gethttp();
HttpPost post = new HttpPost(path);
//设置post请求参数
List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>();
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
BasicNameValuePair pair = new BasicNameValuePair(key, value);
parameters.add(pair );
}
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters, "utf-8");
post.setEntity(entity);
HttpResponse response = client.execute(post);
//状态码--响应码
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode==200){//ok
// InputStream is = response.getEntity().getContent();
// String result = getStringFromStream(is);
HttpEntity responseEntity = response.getEntity();
String result = EntityUtils.toString(responseEntity);
return result;
}else{//连接出错
throw new NetworkErrorException();
}
}
public String doPostByOkHttpClient(String path,Map<String,String> map) throws Exception{
//得到一个http请求客户端
OkHttpClient client = getOkHttpClientttp();
// HttpPost post = new HttpPost(path);
FormBody.Builder builder = new FormBody.Builder();
// FormBody body = new FormBody.Builder();
//设置post请求参数
List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>();
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
BasicNameValuePair pair = new BasicNameValuePair(key, value);
parameters.add(pair );
builder.add(key,value);
}
RequestBody requestBodyPost = builder.build();
Request requestPost = new Request.Builder()
.url(path)
.post(requestBodyPost)
.build();
// UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters, "utf-8");
// post.setEntity(entity);
// HttpResponse response = client.execute(post);
Call call = client.newCall(requestPost);
Response response = call.execute();
//状态码--响应码
// int statusCode = response.getStatusLine().getStatusCode();
int statusCode = response.code();
if(statusCode==200){//ok
// InputStream is = response.getEntity().getContent();
// String result = getStringFromStream(is);
// HttpEntity responseEntity = response.getEntity();
// String result = EntityUtils.toString(responseEntity);
return response.body().string();
}else{//连接出错
throw new NetworkErrorException();
}
}
class HttpAsyncTask extends AsyncTask<Void, Void, String>{
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Void... params) {
//登陆
try {
String result = null;
if("GET".equals(method)){
System.out.println("path:"+path);
result = doGetByHttpClient(path, map);
}else{
// Ayni OkHttp doPostByOkHttpClient
// result = doPostByHttpClient(path, map);
result = doPostByOkHttpClient(path, map);
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if(result!=null){
if("failed".equals(result)){
callback.failed(result);
}else{
callback.success(result);
}
}
}
}
}

View File

@@ -0,0 +1,134 @@
package com.game.webgame.network;
import com.android.volley.toolbox.ImageLoader.ImageListener;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.util.LruCache;
import android.widget.ImageView;
public class ImageLoader {
// 导包记得使用v4兼容包会兼容低版本
/**
* 图片缓存核心类(将最近不怎么使用的图片回收;尽量保持最近使用比较多的)
*/
private static LruCache<String, Bitmap> mMemoryCache;
private static ImageLoader mImageLoader;
private ImageLoader() {
// 获取系统分配给每个应用程序的最大内存每个应用系统分配32M
// int maxMemory = (int) Runtime.getRuntime().maxMemory();
// int mCacheSize = maxMemory / 8;
// 给LruCache分配1/8 4M
// maxSize最多缓存多大内存(获得应用程序最大可用内存/8)
int maxMemory = (int) Runtime.getRuntime().maxMemory();//返回 Java
// 虚拟机试图使用的最大内存量
System.out.println("Runtime.getRuntime().maxMemory()=="
+ Runtime.getRuntime().maxMemory());
System.out.println("Runtime.getRuntime().freeMemory()=="
+ Runtime.getRuntime().freeMemory());// kb返回 Java 虚拟机中的空闲内存量
int maxSize = maxMemory / 8;
mMemoryCache = new LruCache<String, Bitmap>(maxSize) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {
// 重写此方法来衡量每一张图片的大小,默认返回图片的数量大小
return bitmap.getRowBytes() * bitmap.getHeight() / 1024;// 这里是按多少KB来算
// 之前是B
// byte
}
};
}
// 单例模式防止mMemoryCache出现多个
public static ImageLoader getIntance() {
if (mImageLoader == null) {
mImageLoader = new ImageLoader();
}
return mImageLoader;
}
/**
* 将一张图片缓存到LruCache中 将图片的路径作为图片缓存的key
*/
public void addBitmapToMemoryCache(String path, Bitmap bitmap) {
if (getBitmapFromMemoryCache(path) == null) {
mMemoryCache.put(path, bitmap);
}
}
/**
* 从LrcCache里面取一张图片 读需要图片的路径作为key
*/
public Bitmap getBitmapFromMemoryCache(String path) {
return mMemoryCache.get(path);
}
/**
* 图片压缩 读取一个图片文件通过压缩算法压缩后生成一个Bitmap返回
*/
public static Bitmap decodeBitmapFromResource(String iconPath, int reqWidth) {
BitmapFactory.Options options = new BitmapFactory.Options();
// 1.得到原始图片的宽度
// 不读取图片本身而是只解析图片的宽高。只是读图片大小不申请bitmap内存 在decode时将会返回null,
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(iconPath, options);
//BitmapFactory.decodeResource(context.getResources(), id)
//BitmapFactory.decodeResource(context.getResources(), R.drawable.applogo, options);
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
// if( baos.toByteArray().length / 1024>1024)
// {//判断如果图片大于1M,进行压缩避免在生成图片BitmapFactory.decodeStream时溢出
// baos.reset();//重置baos即清空baos
// image.compress(Bitmap.CompressFormat.JPEG, 50,
// baos);//这里压缩50%把压缩后的数据存放到baos中
// }
// ByteArrayInputStream isBm = new
// ByteArrayInputStream(baos.toByteArray());
// BitmapFactory.decodeStream(is, outPadding, opts);
int width = options.outWidth;
int height = options.outHeight;
int inSampleSize = 1;
if (width > reqWidth) {
// 计算出实际宽度和目标宽度的比率
int widthRatio = Math.round((float) width / (float) reqWidth);
inSampleSize = widthRatio;
}
// 2.压缩后的图片宽度reqWidth
// 开始压缩图片
// 读图片本身了//设为false这次不是预读取图片大小而是返回申请内存bitmap数据
options.inJustDecodeBounds = false;
// 设置压缩比例比如2宽和高一起压缩1/2
options.inSampleSize = inSampleSize;// 倍数缩放
return BitmapFactory.decodeFile(iconPath, options);
}
/**
* 图片压缩 读取一个图片文件通过压缩算法压缩后生成一个Bitmap返回
*/
public static Bitmap decodeBitmapFromResource(Context context,int id, int reqWidth) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(context.getResources(), id, options);
int width = options.outWidth;
int height = options.outHeight;
int inSampleSize = 1;
if (width > reqWidth) {
int widthRatio = Math.round((float) width / (float) reqWidth);
inSampleSize = widthRatio;
}
options.inJustDecodeBounds = false;
// 设置压缩比例比如2宽和高一起压缩1/2
options.inSampleSize = inSampleSize;// 倍数缩放
return BitmapFactory.decodeResource(context.getResources(), id, options);
}
}

View File

@@ -0,0 +1,98 @@
package com.game.webgame.network;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
import com.android.volley.toolbox.HttpHeaderParser;
public class JsonObjectPostRequest extends Request<JSONObject> {
// public JsonObjectPostRequest(String url, ErrorListener listener) {
// super(url, listener);
// // TODO Auto-generated constructor stub
// }
//
// public JsonObjectPostRequest(int method, String url, ErrorListener listener) {
// super(method, url, listener);
// // TODO Auto-generated constructor stub
// }
public JsonObjectPostRequest(String url,
Response.Listener<JSONObject> listener,
Response.ErrorListener errorListener, Map map) {
super(Request.Method.POST, url, errorListener);
mListener = listener;
mMap = map;
}
private Map<String, String> mMap;
private Response.Listener<JSONObject> mListener;
public String cookieFromResponse;
private String mHeader;
private Map<String, String> sendHeader = new HashMap<String, String>(1);
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return mMap;
}
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers));
mHeader = response.headers.toString();
Log.w("LOG", "get headers in parseNetworkResponse "
+ response.headers.toString());
Pattern pattern = Pattern.compile("Set-Cookie.*?;");
Matcher m = pattern.matcher(mHeader);
if (m.find()) {
cookieFromResponse = m.group();
Log.w("LOG", "cookie from server " + cookieFromResponse);
}
cookieFromResponse = cookieFromResponse.substring(11,
cookieFromResponse.length() - 1);
Log.w("LOG", "cookie substring " + cookieFromResponse);
JSONObject jsonObject = new JSONObject(jsonString);
jsonObject.put("Cookie", cookieFromResponse);
Log.w("LOG", "jsonObject " + jsonObject.toString());
return Response.success(jsonObject,
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
@Override
protected void deliverResponse(JSONObject response) {
mListener.onResponse(response);
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return sendHeader;
}
public void setSendCookie(String cookie) {
sendHeader.put("Cookie", cookie);
}
}

View File

@@ -0,0 +1,218 @@
package com.game.webgame.network;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.cookie.BasicClientCookie;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
/**
* Created by Administrator on 2017/4/24.
*/
public class PreferencesCookieStore implements CookieStore{
private static final String COOKIE_PREFS = "CookiePrefsFile";
private static final String COOKIE_NAME_STORE = "names";
private static final String COOKIE_NAME_PREFIX = "cookie_";
private final ConcurrentHashMap<String, Cookie> cookies;
private final SharedPreferences cookiePrefs;
/**
* Construct a persistent cookie store.
*/
public PreferencesCookieStore(Context context) {
cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, 0);
cookies = new ConcurrentHashMap<String, Cookie>();
// Load any previously stored cookies into the store
String storedCookieNames = cookiePrefs.getString(COOKIE_NAME_STORE, null);
if(storedCookieNames != null) {
String[] cookieNames = TextUtils.split(storedCookieNames, ",");
for(String name : cookieNames) {
String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
if(encodedCookie != null) {
Cookie decodedCookie = decodeCookie(encodedCookie);
if(decodedCookie != null) {
cookies.put(name, decodedCookie);
}
}
}
// Clear out expired cookies
clearExpired(new Date());
}
}
@Override
public void addCookie(Cookie cookie) {
String name = cookie.getName();
// Save cookie into local store, or remove if expired
if(!cookie.isExpired(new Date())) {
cookies.put(name, cookie);
} else {
cookies.remove(name);
}
// Save cookie into persistent store
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
prefsWriter.commit();
}
@Override
public void clear() {
// Clear cookies from local store
cookies.clear();
// Clear cookies from persistent store
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
for(String name : cookies.keySet()) {
prefsWriter.remove(COOKIE_NAME_PREFIX + name);
}
prefsWriter.remove(COOKIE_NAME_STORE);
prefsWriter.commit();
}
@Override
public boolean clearExpired(Date date) {
boolean clearedAny = false;
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
for(ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
String name = entry.getKey();
Cookie cookie = entry.getValue();
if(cookie.isExpired(date)) {
// <20><><EFBFBD>cookies
cookies.remove(name);
// Clear cookies from persistent store
prefsWriter.remove(COOKIE_NAME_PREFIX + name);
// We've cleared at least one
clearedAny = true;
}
}
// Update names in persistent store
if(clearedAny) {
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
}
prefsWriter.commit();
return clearedAny;
}
@Override
public List<Cookie> getCookies() {
return new ArrayList<Cookie>(cookies.values());
}
protected String encodeCookie(SerializableCookie cookie) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ObjectOutputStream outputStream = new ObjectOutputStream(os);
outputStream.writeObject(cookie);
} catch (Exception e) {
return null;
}
return byteArrayToHexString(os.toByteArray());
}
protected Cookie decodeCookie(String cookieStr) {
byte[] bytes = hexStringToByteArray(cookieStr);
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
Cookie cookie = null;
try {
ObjectInputStream ois = new ObjectInputStream(is);
cookie = ((SerializableCookie)ois.readObject()).getCookie();
} catch (Exception e) {
e.printStackTrace();
}
return cookie;
}
// Using some super basic byte array <-> hex conversions so we don't have
// to rely on any large Base64 libraries. Can be overridden if you like!
protected String byteArrayToHexString(byte[] b) {
StringBuffer sb = new StringBuffer(b.length * 2);
for (byte element : b) {
int v = element & 0xff;
if(v < 16) {
sb.append('0');
}
sb.append(Integer.toHexString(v));
}
return sb.toString().toUpperCase();
}
protected byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for(int i=0; i<len; i+=2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16));
}
return data;
}
public class SerializableCookie implements Serializable {
private static final long serialVersionUID = 6374381828722046732L;
private transient final Cookie cookie;
private transient BasicClientCookie clientCookie;
public SerializableCookie(Cookie cookie) {
this.cookie = cookie;
}
public Cookie getCookie() {
Cookie bestCookie = cookie;
if(clientCookie != null) {
bestCookie = clientCookie;
}
return bestCookie;
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(cookie.getName());
out.writeObject(cookie.getValue());
out.writeObject(cookie.getComment());
out.writeObject(cookie.getDomain());
out.writeObject(cookie.getExpiryDate());
out.writeObject(cookie.getPath());
out.writeInt(cookie.getVersion());
out.writeBoolean(cookie.isSecure());
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
String name = (String)in.readObject();
String value = (String)in.readObject();
clientCookie = new BasicClientCookie(name, value);
clientCookie.setComment((String)in.readObject());
clientCookie.setDomain((String)in.readObject());
clientCookie.setExpiryDate((Date)in.readObject());
clientCookie.setPath((String)in.readObject());
clientCookie.setVersion(in.readInt());
clientCookie.setSecure(in.readBoolean());
}
}
}

View File

@@ -0,0 +1,60 @@
package com.game.webgame.network;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.HttpCookie;
import android.annotation.SuppressLint;
public class SerializableHttpCookie implements Serializable{
private static final long serialVersionUID = 1L;
private transient final HttpCookie cookie;
private transient HttpCookie clientCookie;
public SerializableHttpCookie(HttpCookie cookie) {
this.cookie = cookie;
}
@SuppressLint("NewApi")
public HttpCookie getCookie() {
HttpCookie bestCookie = cookie;
if (clientCookie != null) {
bestCookie = clientCookie;
}
return bestCookie;
}
@SuppressLint("NewApi")
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(cookie.getName());
out.writeObject(cookie.getValue());
out.writeObject(cookie.getComment());
out.writeObject(cookie.getCommentURL());
out.writeObject(cookie.getDomain());
out.writeLong(cookie.getMaxAge());
out.writeObject(cookie.getPath());
out.writeObject(cookie.getPortlist());
out.writeInt(cookie.getVersion());
out.writeBoolean(cookie.getSecure());
out.writeBoolean(cookie.getDiscard());
}
@SuppressLint("NewApi")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
String name = (String) in.readObject();
String value = (String) in.readObject();
clientCookie = new HttpCookie(name, value);
clientCookie.setComment((String) in.readObject());
clientCookie.setCommentURL((String) in.readObject());
clientCookie.setDomain((String) in.readObject());
clientCookie.setMaxAge(in.readLong());
clientCookie.setPath((String) in.readObject());
clientCookie.setPortlist((String) in.readObject());
clientCookie.setVersion(in.readInt());
clientCookie.setSecure(in.readBoolean());
clientCookie.setDiscard(in.readBoolean());
}
}

View File

@@ -0,0 +1,52 @@
package com.game.webgame.network;
import org.json.JSONObject;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import android.content.Context;
public abstract class Volleyinterface {
public Context mcontext;
public static Listener<JSONObject> mlistener;
public static ErrorListener mErrorLisener;
public Volleyinterface(Context context, Listener<JSONObject> mlistener,
ErrorListener errorlisener) {
this.mcontext = context;
this.mErrorLisener = errorlisener;
this.mlistener = mlistener;
}
public abstract void onsuccess(String result);
public abstract void onerror(VolleyError arg0);
public Listener<JSONObject> loadinglisener() {
mlistener = new Listener<JSONObject>() {
@Override
public void onResponse(JSONObject arg0) {
//System.out.println(arg0);
onsuccess(arg0.toString());
}
};
return mlistener;
}
public ErrorListener errorListener() {
mErrorLisener = new ErrorListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
// System.out.println(arg0.toString());
onerror(arg0);
}
};
return mErrorLisener;
}
}

View File

@@ -0,0 +1,44 @@
package com.game.webgame.network;
import android.content.Context;
import com.android.volley.VolleyError;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
public abstract class Volleyinterface1 {
public Context mcontext;
public static Listener<String> mlistener;
public static ErrorListener mErrorLisener;
public Volleyinterface1(Context context, Listener<String> mlistener,
ErrorListener errorlisener) {
this.mcontext = context;
this.mErrorLisener = errorlisener;
this.mlistener = mlistener;
}
public abstract void onsuccess(String result);
public abstract void onerror(VolleyError arg0);
public Listener<String> loadinglisener() {
mlistener = new Listener<String>() {
@Override
public void onResponse(String arg0) {
onsuccess(arg0.toString());
}
};
return mlistener;
}
public ErrorListener errorListener() {
mErrorLisener = new ErrorListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
onerror(arg0);
}
};
return mErrorLisener;
}
}

View File

@@ -0,0 +1,39 @@
package com.game.webgame.network;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.tsgame.tsgame_niuniu.system.Myapplication;
public class httpxutils {
public void xutils(){
HttpUtils http = new HttpUtils();
http.configCookieStore(new PreferencesCookieStore(Myapplication.application));
http.send(HttpRequest.HttpMethod.POST, "", new RequestCallBack<String>() {
@Override
public void onLoading(long total, long current, boolean isUploading) {
super.onLoading(total, current, isUploading);
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onFailure(HttpException arg0, String arg1) {
}
@Override
public void onSuccess(ResponseInfo<String> arg0) {
}
});
}
}

View File

@@ -0,0 +1,150 @@
package com.game.webgame.network;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import com.android.volley.Request.Method;
import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
public class register {
public static void PostJsonrequest(Map<String, String> map, String url,
Volleyinterface inface) {
JSONObject jsonObject = new JSONObject(map);
System.out.println(jsonObject.toString());
JsonObjectRequest JsonObject1 = new JsonObjectRequest(Method.POST, url,
jsonObject, inface.loadinglisener(), inface.errorListener());
JsonObject1.setShouldCache(false);
volleymanager.getInstance().getmRequestQueue().getCache().remove(url);
volleymanager.getInstance().getmRequestQueue().add(JsonObject1);
}
public static void PostJsonrequest1(String json, String url,
Volleyinterface inface) {
JSONObject jsonObject=null;
try {
if(json!=null){
jsonObject = new JSONObject(json);
}
JsonObjectRequest JsonObject1 = new JsonObjectRequest(Method.POST, url,
jsonObject, inface.loadinglisener(), inface.errorListener());
JsonObject1.setShouldCache(false);
volleymanager.getInstance().getmRequestQueue().getCache().remove(url);
JsonObject1.setRetryPolicy(new DefaultRetryPolicy(
12000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
volleymanager.getInstance().getmRequestQueue().add(JsonObject1);
} catch (JSONException e) {
e.printStackTrace();
}
//JSONObject jsonObject = new JSONObject(map);
}
public static void webservers(Map<String, String> map, String url,
Volleyinterface inface) {
JsonObjectRequest JsonObject;
if (map != null) {
JSONObject jsonObject = new JSONObject(map);
JsonObject = new JsonObjectRequest(Method.POST, url, jsonObject,
inface.loadinglisener(), inface.errorListener());
} else {
JsonObject = new JsonObjectRequest(Method.POST, url, null,
inface.loadinglisener(), inface.errorListener());
}
JsonObject.setShouldCache(false);
volleymanager.getInstance().getmRequestQueue().getCache().remove(url);
volleymanager.getInstance().getmRequestQueue().add(JsonObject);
}
public static void Stringpostrequest(final Map<String, String> map,
String url) {
StringRequest string = new StringRequest(Method.POST, url,
new Listener<String>() {
@Override
public void onResponse(String arg0) {
System.out.println(arg0);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return map;
}
};
string.setShouldCache(false);
volleymanager.getInstance().getmRequestQueue().add(string);
}
public static void StringGETrequest(final Map<String, String> map,
String url,Volleyinterface1 inface) {
if(map!=null){
url = url + "?" + getParamsFromMap(map);
}
StringRequest string = new StringRequest(Method.GET, url,inface.loadinglisener(), inface.errorListener());
string.setShouldCache(false);
volleymanager.getInstance().getmRequestQueue().add(string);
}
public static void Getjsonrequest(Map<String, String> map, String url) {
url = url + "?" + getParamsFromMap(map);
System.out.println(url);
JsonObjectRequest JsonObject = new JsonObjectRequest(Method.GET, url,
null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject1) {
if (jsonObject1 == null) {
System.out.println("返回值为空");
}
System.out.println(jsonObject1.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
}
});
JsonObject.setShouldCache(false);
// Myapplication.getqueue().getCache().remove(url);
volleymanager.getInstance().getmRequestQueue().add(JsonObject);
}
private static String getParamsFromMap(Map<String, String> map) {
StringBuffer buffer = new StringBuffer();
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
buffer.append(key).append("=").append(value).append("&");
}
buffer.deleteCharAt(buffer.length() - 1);
return buffer.toString();
}
}

View File

@@ -0,0 +1,83 @@
package com.game.webgame.network;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.util.prefs.Preferences;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.HttpParams;
import android.annotation.SuppressLint;
import android.content.Context;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.HttpClientStack;
import com.android.volley.toolbox.HttpStack;
import com.android.volley.toolbox.Volley;
import com.tsgame.tsgame_niuniu.system.Myapplication;
import okhttp3.OkHttpClient;
public class volleymanager {
private static volleymanager mInstance = null;
private static RequestQueue mRequestQueue;
@SuppressLint("NewApi") @SuppressWarnings("deprecation")
private volleymanager(Context context) {
// DefaultHttpClient httpclient = new DefaultHttpClient();
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
//<2F>dz־û<D6BE><C3BB>洢(<28>ڴ<EFBFBD>洢) BasicCookieStore | <20>־û<D6BE><C3BB>洢 PreferencesCookieStore
// CookieStore cookieStore = new BasicCookieStore();
// httpclient.setCookieStore(cookieStore);
// HttpStack httpStack = new HttpClientStack(httpclient);
// mRequestQueue = Volley.newRequestQueue(context.getApplicationContext(),httpStack);
CookieManager manager= new CookieManager(new volleypreferencesCookie(context), CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);
// DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
// ClientConnectionManager mClientConnectionManager = defaultHttpClient.getConnectionManager();
// HttpParams mHttpParams = defaultHttpClient.getParams();
// ThreadSafeClientConnManager mThreadSafeClientConnManager = new ThreadSafeClientConnManager( mHttpParams,
// mClientConnectionManager.getSchemeRegistry() );
// defaultHttpClient = new DefaultHttpClient( mThreadSafeClientConnManager, mHttpParams );
// CookieStore cookieStore = new PreferencesCookieStore( context );
// defaultHttpClient.setCookieStore( cookieStore );
// HttpStack httpStack = new HttpClientStack( defaultHttpClient );
mRequestQueue =
Volley.newRequestQueue(context.getApplicationContext());
}
public static synchronized volleymanager getInstance() {
if (mInstance == null) {
mInstance = new volleymanager(Myapplication.application);
}
return mInstance;
}
public RequestQueue getmRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(Myapplication.application
.getApplicationContext());
}
return mRequestQueue;
}
}

View File

@@ -0,0 +1,227 @@
package com.game.webgame.network;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@SuppressLint("NewApi") public class volleypreferencesCookie implements CookieStore{
private static final String LOG_TAG = "PersistentCookieStore";
private static final String COOKIE_PREFS = "CookiePrefsFile";
private static final String COOKIE_NAME_PREFIX = "cookie_";
private final HashMap<String, ConcurrentHashMap<String, HttpCookie>> cookies;
private final SharedPreferences cookiePrefs;
/**
* Construct a persistent cookie store.
*
* @param context Context to attach cookie store to
*/
public volleypreferencesCookie(Context context) {
cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, 0);
cookies = new HashMap<String, ConcurrentHashMap<String, HttpCookie>>();
// Load any previously stored cookies into the store
Map<String, ?> prefsMap = cookiePrefs.getAll();
for(Map.Entry<String, ?> entry : prefsMap.entrySet()) {
if (((String)entry.getValue()) != null && !((String)entry.getValue()).startsWith(COOKIE_NAME_PREFIX)) {
String[] cookieNames = TextUtils.split((String)entry.getValue(), ",");
for (String name : cookieNames) {
String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
if (encodedCookie != null) {
HttpCookie decodedCookie = decodeCookie(encodedCookie);
if (decodedCookie != null) {
if(!cookies.containsKey(entry.getKey()))
cookies.put(entry.getKey(), new ConcurrentHashMap<String, HttpCookie>());
cookies.get(entry.getKey()).put(name, decodedCookie);
}
}
}
}
}
}
@Override
public void add(URI uri, HttpCookie cookie) {
String name = getCookieToken(uri, cookie);
if (!cookie.hasExpired()) {
if(!cookies.containsKey(uri.getHost()))
cookies.put(uri.getHost(), new ConcurrentHashMap<String, HttpCookie>());
cookies.get(uri.getHost()).put(name, cookie);
} else {
if(cookies.containsKey(uri.toString()))
cookies.get(uri.getHost()).remove(name);
}
// Save cookie into persistent store
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
prefsWriter.putString(uri.getHost(), TextUtils.join(",", cookies.get(uri.getHost()).keySet()));
prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie)));
prefsWriter.apply();
}
protected String getCookieToken(URI uri, HttpCookie cookie) {
return cookie.getName() + cookie.getDomain();
}
@Override
public List<HttpCookie> get(URI uri) {
ArrayList<HttpCookie> ret = new ArrayList<HttpCookie>();
if(cookies.containsKey(uri.getHost()))
ret.addAll(cookies.get(uri.getHost()).values());
return ret;
}
@Override
public boolean removeAll() {
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
prefsWriter.clear();
prefsWriter.apply();
cookies.clear();
return true;
}
@Override
public boolean remove(URI uri, HttpCookie cookie) {
String name = getCookieToken(uri, cookie);
if(cookies.containsKey(uri.getHost()) && cookies.get(uri.getHost()).containsKey(name)) {
cookies.get(uri.getHost()).remove(name);
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
if(cookiePrefs.contains(COOKIE_NAME_PREFIX + name)) {
prefsWriter.remove(COOKIE_NAME_PREFIX + name);
}
prefsWriter.putString(uri.getHost(), TextUtils.join(",", cookies.get(uri.getHost()).keySet()));
prefsWriter.apply();
return true;
} else {
return false;
}
}
@Override
public List<HttpCookie> getCookies() {
ArrayList<HttpCookie> ret = new ArrayList<HttpCookie>();
for (String key : cookies.keySet())
ret.addAll(cookies.get(key).values());
return ret;
}
@Override
public List<URI> getURIs() {
ArrayList<URI> ret = new ArrayList<URI>();
for (String key : cookies.keySet())
try {
ret.add(new URI(key));
} catch (URISyntaxException e) {
e.printStackTrace();
}
return ret;
}
/**
* Serializes Cookie object into String
*
* @param cookie cookie to be encoded, can be null
* @return cookie encoded as String
*/
protected String encodeCookie(SerializableHttpCookie cookie) {
if (cookie == null)
return null;
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ObjectOutputStream outputStream = new ObjectOutputStream(os);
outputStream.writeObject(cookie);
} catch (IOException e) {
Log.d(LOG_TAG, "IOException in encodeCookie " + e.toString());
return null;
}
return byteArrayToHexString(os.toByteArray());
}
/**
* Returns cookie decoded from cookie string
*
* @param cookieString string of cookie as returned from http request
* @return decoded cookie or null if exception occured
*/
protected HttpCookie decodeCookie(String cookieString) {
byte[] bytes = hexStringToByteArray(cookieString);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
HttpCookie cookie = null;
try {
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
cookie = ((SerializableHttpCookie) objectInputStream.readObject()).getCookie();
} catch (IOException e) {
Log.d(LOG_TAG, "IOException in decodeCookie " + e.toString());
} catch (ClassNotFoundException e) {
Log.d(LOG_TAG, "ClassNotFoundException in decodeCookie " + e.toString());
}
return cookie;
}
/**
* Using some super basic byte array &lt;-&gt; hex conversions so we don't have to rely on any
* large Base64 libraries. Can be overridden if you like!
*
* @param bytes byte array to be converted
* @return string containing hex values
*/
protected String byteArrayToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (byte element : bytes) {
int v = element & 0xff;
if (v < 16) {
sb.append('0');
}
sb.append(Integer.toHexString(v));
}
return sb.toString().toUpperCase(Locale.US);
}
/**
* Converts hex values from strings to byte arra
*
* @param hexString string of hex-encoded values
* @return decoded byte array
*/
protected byte[] hexStringToByteArray(String hexString) {
int len = hexString.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16));
}
return data;
}
}

View File

@@ -0,0 +1,39 @@
package com.game.webgame.view;
import android.view.View;
import android.widget.Adapter;
import android.widget.ListView;
/**
* Created by Administrator on 2017/4/24.
*/
public class ListViewUtils {
//TODO 解决ScollView、GridView及Expandlistview嵌套ListView显示不全问题
/*******************************************************************/
private int totalHeight = 0;
public int setListViewHeight(ListView listView){
/*得到适配器*/
Adapter adapter = listView.getAdapter();
/*遍历控件*/
for (int i = 0; i < adapter .getCount(); i++) {
View view = adapter.getView(i, null, listView);
/*测量一下子控件的高度*/
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
totalHeight+=view.getMeasuredHeight();
}
/*控件之间的间隙*/
totalHeight+=listView.getDividerHeight()*(listView.getCount()-1);
// /*2、赋值给ListView的LayoutParams对象*/
// ViewGroup.LayoutParams params = listView.getLayoutParams();
// params.height = totalHeight;
//
// listView.setLayoutParams(params);
return totalHeight;
}
}

View File

@@ -0,0 +1,72 @@
package com.game.webgame.view;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
public class SpUtil {
private static final String NAME = "erqiwang";
private static SpUtil instance;
static {
instance = new SpUtil();
}
public static SpUtil getInstance() {
if (instance == null) {
instance = new SpUtil();
}
return instance;
}
public static SharedPreferences getSharePerference(Context context) {
return context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
}
public static boolean isFirst(SharedPreferences sp) {
return sp.getBoolean("isFirst", false);
}
public static void setStringSharedPerference(SharedPreferences sp,
String key, String value) {
Editor editor = sp.edit();
editor.putString(key, value);
editor.commit();
}
public static void setLongSharedPerference(SharedPreferences sp,
String key, Long value) {
Editor editor = sp.edit();
editor.putLong(key, value);
editor.commit();
}
public static void setIntSharedPerference(SharedPreferences sp,
String key, int value) {
Editor editor = sp.edit();
editor.putInt(key, value);
editor.commit();
}
public static int getIntSharedPerference(SharedPreferences sp,
String key) {
return sp.getInt(key, 0);
}
public static String getStringSharedPerference(SharedPreferences sp,
String key) {
return sp.getString(key, null);
}
public static Long getLongSharedPerference(SharedPreferences sp,
String key) {
return sp.getLong(key, 0);
}
public static void setBooleanSharedPerference(SharedPreferences sp,
String key, boolean value) {
Editor editor = sp.edit();
editor.putBoolean(key, value);
editor.commit();
}
}

View File

@@ -0,0 +1,58 @@
package com.game.webgame.view;
import com.jx.jyhd.R;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class dialogexit {
public interface onexitlistener {
public void paylistener();
public void cancellistener();
};
public static void show(Context con, String content,
final onexitlistener listener) {
View v = View.inflate(con,R.layout.titledialog, null);
TextView content1 = (TextView) v.findViewById(R.id.text);
if (!pmutil.isnullorEmpty(content)) {
content1.setText(content);
}
TextView confim = (TextView) v.findViewById(R.id.confim);
TextView cancel = (TextView) v.findViewById(R.id.cancel);
final AlertDialog dialog = new AlertDialog.Builder(con).create();
dialog.setCancelable(false);
dialog.show();
dialog.setContentView(v);
confim.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
listener.paylistener();
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
listener.cancellistener();
}
});
dialog.getWindow().setLayout(pmutil.pmw() / 3 * 2,
LayoutParams.WRAP_CONTENT);
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialogexit);
}
}

View File

@@ -0,0 +1,38 @@
package com.game.webgame.view;
import com.jx.jyhd.R;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
public class exitTitle {
public static void show(Context con, String content) {
View v = View.inflate(con, R.layout.hintdialog, null);
TextView content1 = (TextView) v.findViewById(R.id.confim);
if (!pmutil.isnullorEmpty(content)) {
content1.setText(content);
}
TextView cancel = (TextView) v.findViewById(R.id.exit);
final AlertDialog dialog = new AlertDialog.Builder(con).create();
dialog.setCancelable(false);
dialog.show();
dialog.setContentView(v);
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.getWindow().setLayout(pmutil.pmw() / 3 * 2,
LayoutParams.WRAP_CONTENT);
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialogexit);
}
}

View File

@@ -0,0 +1,12 @@
package com.game.webgame.view;
import com.android.volley.RequestQueue;
public class gameutil {
public static Boolean isAuto=true;
public static Boolean islogin=true;
}

View File

@@ -0,0 +1,60 @@
package com.game.webgame.view;
import com.tsgame.tsgame_niuniu.system.Myapplication;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
public class getAppinfo {
public static String getAppVersionName() {
PackageInfo packageInfo;
try {
packageInfo = Myapplication.application.getPackageManager()
.getPackageInfo(Myapplication.application.getPackageName(),
0);
return packageInfo.versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return "1.0";
}
public static String getAppName() {
PackageInfo packageInfo;
try {
packageInfo = Myapplication.application.getPackageManager()
.getPackageInfo(Myapplication.application.getPackageName(),
0);
return packageInfo.applicationInfo.loadLabel(Myapplication.application.getPackageManager()).toString();
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return "1.0";
}
public static int getAppVersioncode() {
PackageInfo packageInfo;
try {
packageInfo = Myapplication.application.getPackageManager().getPackageInfo(Myapplication.application.getPackageName(),0);
return packageInfo.versionCode;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return 1;
}
public static String getAppos() {
return "ANDROID";
}
public static Long getTimeStamp() {
return System.currentTimeMillis();
}
public static String getSign() {
return "";
}
}

View File

@@ -0,0 +1,63 @@
package com.game.webgame.view;
import com.tsgame.tsgame_niuniu.system.Myapplication;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.WindowManager;
public class pmutil {
static String userid;
static SharedPreferences sp;
public static int pmw() {
WindowManager manager = (WindowManager) Myapplication.application
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(dm);
int width2 = dm.widthPixels;
return width2;
}
public static int pmh() {
WindowManager manager = (WindowManager) Myapplication.application
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(dm);
int height2 = dm.heightPixels;
return height2;
}
public static String Appname(){
return getAppinfo.getAppName();
}
public static boolean isnullorEmpty(String name){
boolean isflag=false;
if(name==null||name.trim().length()==0){
isflag=true;
}
return isflag;
}
public static int dp2px(int dpval,Context context) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dpval, context.getResources().getDisplayMetrics());
}
public static int sp2px(int spval,Context context) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
spval, context.getResources().getDisplayMetrics());
}
}

View File

@@ -0,0 +1,8 @@
package com.http.xml.callback;
public interface MyHttpCallBack {
void success(String result);
void failed(String result);
}

View File

@@ -0,0 +1,40 @@
package com.jx.jyhd;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.jx.jyhd.simcpux.Util;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Util.verifyStoragePermissions(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@@ -0,0 +1,119 @@
//package com.jx.jyhd.sgapi;
//
//import android.app.Activity;
//import android.content.Intent;
//import android.os.Bundle;
//import android.os.Handler;
//import android.widget.Toast;
//
////import org.xianliao.im.sdk.api.ISGAPI;
////import org.xianliao.im.sdk.api.ISGAPIEventHandler;
////import org.xianliao.im.sdk.api.SGAPIFactory;
////import org.xianliao.im.sdk.constants.SGConstants;
////import org.xianliao.im.sdk.modelbase.BaseReq;
////import org.xianliao.im.sdk.modelbase.BaseResp;
////import org.xianliao.im.sdk.modelmsg.SendAuth;
//
//
//
///**
// * Created by nickyang on 2017/1/18.
// *
// * 此类用于接收从闲聊返回到应用的返回值
// *
// * 注意: "sgapi" 目录名和 "SGEntryActivity" 类名都不能改动
// *
// */
//public class SGEntryActivity extends Activity implements ISGAPIEventHandler {
//
// ISGAPI api;
// public static Handler sharehandler;
// // 分享成功
// public static final int sharesucces = 2;
// // 分享失败
// public static final int sharecancel = 3;
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
//
// //Constants.SG_APPID 修改成自己申请的appId
// api = SGAPIFactory.createSGAPI(this, XLConstants.SG_APPID);
//
// api.handleIntent(getIntent(),this);
// }
//
// @Override
// protected void onNewIntent(Intent intent) {
// super.onNewIntent(intent);
// setIntent(intent);
// api.handleIntent(intent, this);
// }
// public static void setshareHandler(Handler handler) {
// sharehandler = handler;
// }
// @Override
// public void onReq(BaseReq req) {
//
// }
//
// @Override
// public void onResp(BaseResp resp) {
// switch (resp.getType()){
// case SGConstants.COMMAND_AUTH: { //授权登陆
// SendAuth.Resp respAuth = (SendAuth.Resp) resp;
// if (resp.errCode == SGConstants.ERR_OK) {
// Toast.makeText(this, "授权登录成功!" + resp.errCode + "\ncode: " + respAuth.code, Toast.LENGTH_SHORT).show();
// } else if (resp.errCode == SGConstants.ERR_CANCEL) {
// Toast.makeText(this, "授权登录取消!" + resp.errCode, Toast.LENGTH_SHORT).show();
// } else if (resp.errCode == SGConstants.ERR_FAIL) {
// Toast.makeText(this, "授权登录失败!" + resp.errCode, Toast.LENGTH_SHORT).show();
// }
//
// //传递code到其他页面 (可选)
//// Intent intent = new Intent(this, MainActivity.class);
//// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
//// intent.putExtra("code", respAuth.code);
//// startActivity(intent);
//
// break;
// }
// case SGConstants.COMMAND_SHARE: { //分享文本,图片,邀请
// if (resp.errCode == SGConstants.ERR_OK) {
// sharehandler.sendEmptyMessage(sharesucces);
//
// Toast.makeText(this, "分享成功!", Toast.LENGTH_SHORT).show();
// } else if (resp.errCode == SGConstants.ERR_CANCEL) {
// sharehandler.sendEmptyMessage(sharecancel);
// Toast.makeText(this, "分享取消!" , Toast.LENGTH_SHORT).show();
// } else if (resp.errCode == SGConstants.ERR_FAIL) {
// sharehandler.sendEmptyMessage(sharecancel);
// Toast.makeText(this, "分享失败!" , Toast.LENGTH_SHORT).show();
// }
// break;
// }
// case SGConstants.COMMAND_INVITE: { //从闲聊点击邀请进入应用,
// /**
// * 需要Manifest里面配置特殊 intent-filter 才有用,详情参见AndroidManifest
// */
//// InvitationResp invitationResp = (InvitationResp) resp;
//// Toast.makeText(this, "邀请进入: roomId: " + invitationResp.roomId + " roomToken: " + invitationResp.roomToken, Toast.LENGTH_LONG).show();
////
//// //传递roomId roomToken到其他页面
//// Intent intent = new Intent(this, SDKDemoActivity.class);
//// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
//// intent.putExtra("roomId", invitationResp.roomId);
//// intent.putExtra("roomToken", invitationResp.roomToken);
//// intent.putExtra("openId", invitationResp.openId);
//// startActivity(intent);
// break;
// }
// }
// finish();
// }
//
// @Override
// protected void onResume() {
// super.onResume();
// }
//}

View File

@@ -0,0 +1,9 @@
package com.jx.jyhd.sgapi;
/**
* Created by nickyang on 2017/3/17.
*/
public class XLConstants {
public static final String SG_APPID = "DaxGcxAYUJbcDmiK";
}

View File

@@ -0,0 +1,19 @@
package com.jx.jyhd.simcpux;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
public class AppRegister extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final IWXAPI api = WXAPIFactory.createWXAPI(context, null);
// 注册
api.registerApp(Constants.APP_ID);
}
}

View File

@@ -0,0 +1,27 @@
package com.jx.jyhd.simcpux;
public class Constants {
public static class ShowMsgActivity {
public static final String STitle = "showmsg_title";
public static final String SMessage = "showmsg_message";
public static final String BAThumbData = "showmsg_thumb_data";
}
//appid
public static final String APP_ID = "wxd2bd650e06bdfe58";
public static final int PERMISSIONS_REQUEST_STORAGE = 1;
//商户号
public static final String MCH_ID = "1448669802";
//API密钥在商户平台设置
public static final String API_KEY="ClMrQsAcidRa7uJT4TgHgVAOHbzQjdPa";
//app 微信AppSecret 秘钥 b2792724b9565be23e8f5ba548f117cf
public static final String AppSecret="1934a281c82ad1a059130fe51341b74b";
}

View File

@@ -0,0 +1,28 @@
package com.jx.jyhd.simcpux;
import java.security.MessageDigest;
public class MD5 {
private MD5() {}
public final static String getMessageDigest(byte[] buffer) {
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try {
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(buffer);
byte[] md = mdTemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
return null;
}
}
}

View File

@@ -0,0 +1,43 @@
package com.jx.jyhd.simcpux;
import java.security.MessageDigest;
public class MD5Util {
private static String byteArrayToHexString(byte b[]) {
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.length; i++)
resultSb.append(byteToHexString(b[i]));
return resultSb.toString();
}
private static String byteToHexString(byte b) {
int n = b;
if (n < 0)
n += 256;
int d1 = n / 16;
int d2 = n % 16;
return hexDigits[d1] + hexDigits[d2];
}
public static String MD5Encode(String origin, String charsetname) {
String resultString = null;
try {
resultString = new String(origin);
MessageDigest md = MessageDigest.getInstance("MD5");
if (charsetname == null || "".equals(charsetname))
resultString = byteArrayToHexString(md.digest(resultString
.getBytes()));
else
resultString = byteArrayToHexString(md.digest(resultString
.getBytes(charsetname)));
} catch (Exception exception) {
}
return resultString;
}
private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
}

View File

@@ -0,0 +1,393 @@
package com.jx.jyhd.simcpux;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import com.tsgame.tsgame_niuniu.system.Myapplication;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class Util {
public static final String TAG = "Util";
private static final String[] PERMISSIONS_STORAGE = {
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE" };
public static void verifyStoragePermissions(Activity activity) {
try {
//检测是否有写的权限
int permission = ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// 没有写的权限,去申请写的权限,会弹出对话框
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,
Constants.PERMISSIONS_REQUEST_STORAGE);
}
if (Build.VERSION.SDK_INT >= 23) {
String[] permissions = PERMISSIONS_STORAGE;
//验证是否许可权限
for (String str : permissions) {
if (activity.checkSelfPermission(str) != PackageManager.PERMISSION_GRANTED) {
//申请权限
activity.requestPermissions(permissions, Constants.PERMISSIONS_REQUEST_STORAGE);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static String GetFileAbsolutePath(){
return Objects.requireNonNull(Myapplication.application.getExternalFilesDir(null)).getAbsolutePath();
}
public static File GetDirectory(){
return Myapplication.application.getExternalFilesDir(null);
}
public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, output);
if (needRecycle) {
bmp.recycle();
}
byte[] result = output.toByteArray();
try {
output.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static byte[] httpGet(final String url) {
if (url == null || url.length() == 0) {
Log.e(TAG, "httpGet, url is null");
return null;
}
HttpClient httpClient = getNewHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse resp = httpClient.execute(httpGet);
if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
Log.e(TAG, "httpGet fail, status code = " + resp.getStatusLine().getStatusCode());
return null;
}
return EntityUtils.toByteArray(resp.getEntity());
} catch (Exception e) {
Log.e(TAG, "httpGet exception, e = " + e.getMessage());
e.printStackTrace();
return null;
}
}
public static byte[] httpPost(String url, String entity) {
if (url == null || url.length() == 0) {
Log.e(TAG, "httpPost, url is null");
return null;
}
HttpClient httpClient = getNewHttpClient();
HttpPost httpPost = new HttpPost(url);
try {
httpPost.setEntity(new StringEntity(entity));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse resp = httpClient.execute(httpPost);
if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
Log.e(TAG, "httpGet fail, status code = " + resp.getStatusLine().getStatusCode());
return null;
}
return EntityUtils.toByteArray(resp.getEntity());
} catch (Exception e) {
Log.e(TAG, "httpPost exception, e = " + e.getMessage());
e.printStackTrace();
return null;
}
}
private static class SSLSocketFactoryEx extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");
public SSLSocketFactoryEx(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
};
sslContext.init(null, new TrustManager[] { tm }, null);
}
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
@Override
public Socket createSocket() throws IOException {
return sslContext.getSocketFactory().createSocket();
}
}
private static HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
public static byte[] readFromFile(String fileName, int offset, int len) {
if (fileName == null) {
return null;
}
File file = new File(fileName);
if (!file.exists()) {
Log.i(TAG, "readFromFile: file not found");
return null;
}
if (len == -1) {
len = (int) file.length();
}
Log.d(TAG, "readFromFile : offset = " + offset + " len = " + len + " offset + len = " + (offset + len));
if(offset <0){
Log.e(TAG, "readFromFile invalid offset:" + offset);
return null;
}
if(len <=0 ){
Log.e(TAG, "readFromFile invalid len:" + len);
return null;
}
if(offset + len > (int) file.length()){
Log.e(TAG, "readFromFile invalid file len:" + file.length());
return null;
}
byte[] b = null;
try {
RandomAccessFile in = new RandomAccessFile(fileName, "r");
b = new byte[len]; // ´´½¨ºÏÊÊÎļþ´óСµÄÊý×é
in.seek(offset);
in.readFully(b);
in.close();
} catch (Exception e) {
Log.e(TAG, "readFromFile : errMsg = " + e.getMessage());
e.printStackTrace();
}
return b;
}
private static final int MAX_DECODE_PICTURE_SIZE = 1920 * 1440;
public static Bitmap extractThumbNail(final String path, final int height, final int width, final boolean crop) {
// Assert.assertTrue(path != null && !path.equals("") && height > 0 && width > 0);
BitmapFactory.Options options = new BitmapFactory.Options();
try {
options.inJustDecodeBounds = true;
Bitmap tmp = BitmapFactory.decodeFile(path, options);
if (tmp != null) {
tmp.recycle();
tmp = null;
}
Log.d(TAG, "extractThumbNail: round=" + width + "x" + height + ", crop=" + crop);
final double beY = options.outHeight * 1.0 / height;
final double beX = options.outWidth * 1.0 / width;
Log.d(TAG, "extractThumbNail: extract beX = " + beX + ", beY = " + beY);
options.inSampleSize = (int) (crop ? (beY > beX ? beX : beY) : (beY < beX ? beX : beY));
if (options.inSampleSize <= 1) {
options.inSampleSize = 1;
}
// NOTE: out of memory error
while (options.outHeight * options.outWidth / options.inSampleSize > MAX_DECODE_PICTURE_SIZE) {
options.inSampleSize++;
}
int newHeight = height;
int newWidth = width;
if (crop) {
if (beY > beX) {
newHeight = (int) (newWidth * 1.0 * options.outHeight / options.outWidth);
} else {
newWidth = (int) (newHeight * 1.0 * options.outWidth / options.outHeight);
}
} else {
if (beY < beX) {
newHeight = (int) (newWidth * 1.0 * options.outHeight / options.outWidth);
} else {
newWidth = (int) (newHeight * 1.0 * options.outWidth / options.outHeight);
}
}
options.inJustDecodeBounds = false;
Log.i(TAG, "bitmap required size=" + newWidth + "x" + newHeight + ", orig=" + options.outWidth + "x" + options.outHeight + ", sample=" + options.inSampleSize);
Bitmap bm = BitmapFactory.decodeFile(path, options);
if (bm == null) {
Log.e(TAG, "bitmap decode failed");
return null;
}
Log.i(TAG, "bitmap decoded size=" + bm.getWidth() + "x" + bm.getHeight());
final Bitmap scale = Bitmap.createScaledBitmap(bm, newWidth, newHeight, true);
if (scale != null) {
bm.recycle();
bm = scale;
}
if (crop) {
final Bitmap cropped = Bitmap.createBitmap(bm, (bm.getWidth() - width) >> 1, (bm.getHeight() - height) >> 1, width, height);
if (cropped == null) {
return bm;
}
bm.recycle();
bm = cropped;
Log.i(TAG, "bitmap croped size=" + bm.getWidth() + "x" + bm.getHeight());
}
return bm;
} catch (final OutOfMemoryError e) {
Log.e(TAG, "decode bitmap failed: " + e.getMessage());
options = null;
}
return null;
}
public static String sha1(String str) {
if (str == null || str.length() == 0) {
return null;
}
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try {
MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
mdTemp.update(str.getBytes());
byte[] md = mdTemp.digest();
int j = md.length;
char buf[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
buf[k++] = hexDigits[byte0 & 0xf];
}
return new String(buf);
} catch (Exception e) {
return null;
}
}
public static List<String> stringsToList(final String[] src) {
if (src == null || src.length == 0) {
return null;
}
final List<String> result = new ArrayList<String>();
for (int i = 0; i < src.length; i++) {
result.add(src[i]);
}
return result;
}
}

View File

@@ -0,0 +1,12 @@
package com.jx.jyhd.simcpux;
public class Wxistrue {
public static boolean islogin=true;
public static boolean isshare=true;
public static boolean isphotoshare=true;
public static int sharetype=1;//分享类型1 好友 2 朋友圈
}

View File

@@ -0,0 +1,358 @@
package com.jx.jyhd.simcpux.util;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.Toast;
import com.jx.jyhd.simcpux.Constants;
import com.jx.jyhd.simcpux.Util;
import com.jx.jyhd.wxapi.WXEntryActivity;
import com.tagmae.tsgame_erwang.utils.Base64ImageUtil;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXImageObject;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import java.io.File;
/**
* 微信分享工具类
*/
public class WeChatShareUtil {
private static final int THUMB_SIZE = 150;
private static WeChatShareUtil instance;
private final Context mContext;
private final IWXAPI mWxApi;
private WeChatShareCallback mCallback;
private WeChatShareUtil(Context context) {
this.mContext = context.getApplicationContext();
// 初始化微信API
mWxApi = WXAPIFactory.createWXAPI(mContext, Constants.APP_ID, true);
mWxApi.registerApp(Constants.APP_ID);
}
/**
* 获取实例
* @param context 上下文
* @return WeChatShareUtil实例
*/
public static WeChatShareUtil getInstance(Context context) {
if (instance == null && context != null) {
instance = new WeChatShareUtil(context);
}
return instance;
}
/**
* 检查微信是否已安装
* @return 是否安装
*/
public boolean isWeChatInstalled() {
try {
return mWxApi.isWXAppInstalled();
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 设置分享回调
* @param callback 分享回调
*/
public void setShareCallback(WeChatShareCallback callback) {
this.mCallback = callback;
}
/**
* 获取分享回调
* @return 分享回调
*/
public WeChatShareCallback getShareCallback() {
return mCallback;
}
/**
* 分享网页到微信
* @param activity 活动
* @param webpageUrl 网页链接
* @param title 标题
* @param description 描述
* @param scene 分享场景(0:好友, 1:朋友圈)
*/
public void shareWebPage(Activity activity, String webpageUrl, String title, String description, int scene) {
if (!isWeChatInstalled()) {
Toast.makeText(activity, "请先安装微信客户端", Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-1, "未安装微信客户端");
}
return;
}
try {
// 设置分享回调处理
// 创建Handler来接收微信分享结果
final Handler shareHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
// 处理微信分享回调
if (mCallback != null) {
if (msg.what == 0) { // 成功
mCallback.onSuccess();
} else if (msg.what == -2) { // 取消
mCallback.onCancel();
} else { // 错误
mCallback.onError(msg.what, "微信分享失败,错误码:" + msg.what);
}
}
}
};
// 设置分享回调
WXEntryActivity.setshareHandler(shareHandler);
// 创建网页消息对象
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = webpageUrl;
// 创建多媒体消息
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = title;
msg.description = description;
// 设置缩略图 - 使用应用的启动图标 logo6 而不是 ic_launcher
Bitmap thumbBmp = BitmapFactory.decodeResource(mContext.getResources(),
mContext.getResources().getIdentifier("logo6", "drawable", mContext.getPackageName()));
// 如果找不到logo6则退回到使用ic_launcher
if (thumbBmp == null) {
thumbBmp = BitmapFactory.decodeResource(mContext.getResources(),
com.jx.jyhd.R.mipmap.ic_launcher);
}
if (thumbBmp != null) {
Bitmap thumbBitmap = Bitmap.createScaledBitmap(thumbBmp, THUMB_SIZE, THUMB_SIZE, true);
thumbBmp.recycle();
msg.thumbData = Util.bmpToByteArray(thumbBitmap, true);
}
// 构建发送请求
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = scene == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
// 发送请求
boolean result = mWxApi.sendReq(req);
if (!result) {
Toast.makeText(activity, "微信分享请求发送失败", Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-2, "微信分享请求发送失败");
}
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(activity, "微信分享失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-3, "微信分享失败: " + e.getMessage());
}
}
}
/**
* 分享图片到微信
* @param activity 活动
* @param imagePath 图片路径
* @param scene 分享场景(0:好友, 1:朋友圈)
*/
public void shareImage(Activity activity, String imagePath, int scene) {
if (!isWeChatInstalled()) {
Toast.makeText(activity, "请先安装微信客户端", Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-1, "未安装微信客户端");
}
return;
}
// 使用新的图片处理工具类检查图片是否存在,不存在时可以尝试使用其他备用方案
Uri imageFile = Base64ImageUtil.base64ToImageFile(activity,imagePath,null);
//Uri imageFile = Uri.parse(imagePath);
if (imageFile == null) {
//Toast.makeText(activity, "分享图片不存在,尝试创建临时图片", Toast.LENGTH_SHORT).show();
// 如果是Bitmap对象可以使用ImageProcessUtils保存
if (imagePath.startsWith("data:image/") || imagePath.startsWith("base64,")) {
// 对于Base64编码的图片使用ImageProcessUtils保存
com.tagmae.tsgame_erwang.utils.ImageProcessUtils.saveBase64ImageToCache(
activity,
imagePath,
new com.tagmae.tsgame_erwang.utils.ImageProcessUtils.ImageSaveCallback() {
@Override
public void onSuccess(String savedImagePath) {
// 保存成功,使用新路径进行分享
shareImageInternal(activity, savedImagePath, scene);
}
@Override
public void onError(String errorMsg) {
Toast.makeText(activity, errorMsg, Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-2, errorMsg);
}
}
}
);
return;
} else {
// 图片不存在且不能处理
if (mCallback != null) {
mCallback.onError(-2, "图片文件不存在");
}
return;
}
}
// 直接使用现有图片路径分享
shareImageInternal(activity, imageFile.getPath(), scene);
}
/**
* 内部图片分享实现
*/
private void shareImageInternal(Activity activity, String imagePath, int scene) {
try {
// 设置分享回调处理
// 创建Handler来接收微信分享结果
final Handler shareHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
// 处理微信分享回调
if (mCallback != null) {
if (msg.what == 0) { // 成功
mCallback.onSuccess();
} else if (msg.what == -2) { // 取消
mCallback.onCancel();
} else { // 错误
mCallback.onError(msg.what, "微信分享失败,错误码:" + msg.what);
}
}
}
};
// 设置分享回调
WXEntryActivity.setshareHandler(shareHandler);
// 加载要分享的图片
Bitmap bmp = BitmapFactory.decodeFile(imagePath);
if (bmp == null) {
Toast.makeText(activity, "图片加载失败", Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-3, "图片加载失败");
}
return;
}
// 创建图片对象
WXImageObject imgObj = new WXImageObject(bmp);
// 创建多媒体消息
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = imgObj;
// 设置缩略图
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
bmp.recycle();
msg.thumbData = Util.bmpToByteArray(thumbBmp, true);
// 构建发送请求
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("img");
req.message = msg;
req.scene = scene == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
// 发送请求
boolean result = mWxApi.sendReq(req);
if (!result) {
Toast.makeText(activity, "微信分享请求发送失败", Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-4, "微信分享请求发送失败");
}
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(activity, "微信分享失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-5, "微信分享失败: " + e.getMessage());
}
}
}
/**
* 分享Bitmap到微信
* @param activity 活动
* @param bitmap 位图对象
* @param scene 分享场景(0:好友, 1:朋友圈)
*/
public void shareBitmap(Activity activity, Bitmap bitmap, int scene) {
if (bitmap == null) {
Toast.makeText(activity, "分享图片为空", Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-1, "分享图片为空");
}
return;
}
// 使用ImageProcessUtils保存Bitmap
com.tagmae.tsgame_erwang.utils.ImageProcessUtils.saveBitmapToCache(
activity,
bitmap,
new com.tagmae.tsgame_erwang.utils.ImageProcessUtils.ImageSaveCallback() {
@Override
public void onSuccess(String imagePath) {
// 保存成功,使用生成的图片路径分享
shareImageInternal(activity, imagePath, scene);
}
@Override
public void onError(String errorMsg) {
Toast.makeText(activity, errorMsg, Toast.LENGTH_SHORT).show();
if (mCallback != null) {
mCallback.onError(-2, errorMsg);
}
}
}
);
}
/**
* 构建交易ID
*/
private String buildTransaction(String type) {
return type + System.currentTimeMillis();
}
/**
* 微信分享回调接口
*/
public interface WeChatShareCallback {
void onSuccess();
void onError(int code, String message);
void onCancel();
}
}

View File

@@ -0,0 +1,421 @@
package com.jx.jyhd.wxapi;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.volley.VolleyError;
import com.game.webgame.network.Volleyinterface1;
import com.game.webgame.network.register;
import com.game.webgame.view.SpUtil;
import com.jx.jyhd.R;
import com.jx.jyhd.simcpux.Constants;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.jx.jyhd.R;
import com.jx.jyhd.simcpux.Constants;
import com.tsgame.tsgame_niuniu.system.WX_Myurl;
import com.tsgame.tsgame_niuniu.util.apputil;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
public static final String TAG = "WXEntryActivity";
private IWXAPI api;
TextView text;
ImageView image;
public static Handler sharehandler;
SharedPreferences sp;
// 分享成功
public static final int sharesucces = 2;
// 分享失败
public static final int sharecancel = 3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wxuserinfo);
api = WXAPIFactory.createWXAPI(this, Constants.APP_ID, false);
try {
Intent intent = getIntent();
api.handleIntent(intent, this);
} catch (Exception e) {
e.printStackTrace();
}
sp = SpUtil.getSharePerference(WXEntryActivity.this);
initview();
}
private void initview() {
text = (TextView) findViewById(R.id.user);
image = (ImageView) findViewById(R.id.image);
}
public static void setshareHandler(Handler handler) {
sharehandler = handler;
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
api.handleIntent(intent, this);
}
// 微信发送请求到第三方应用时,会回调到该方法
@Override
public void onReq(BaseReq req) {
switch (req.getType()) {
case ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX:
// goToGetMsg();
break;
case ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:
// goToShowMsg((ShowMessageFromWX.Req) req);
break;
default:
break;
}
}
// 第三方应用发送到微信的请求处理后的响应结果,会回调到该方法
@Override
public void onResp(BaseResp resp) {
int result = 0;
switch (resp.errCode){
case BaseResp.ErrCode.ERR_OK:
if (apputil.wxtype == 1) {// 分享
sharehandler.sendEmptyMessage(sharesucces);
}
result = R.string.errcode_success;
break;
case BaseResp.ErrCode.ERR_USER_CANCEL:
result = R.string.errcode_cancel;
break;
case BaseResp.ErrCode.ERR_AUTH_DENIED:
result = R.string.errcode_deny;
break;
case BaseResp.ErrCode.ERR_UNSUPPORT:
result = R.string.errcode_unsupport;
break;
default:
result = R.string.errcode_unknown;
break;
}
Log.e(TAG, getString(result) + ", type=" + resp.getType());
if (resp.getType() == ConstantsAPI.COMMAND_SENDAUTH) {
SendAuth.Resp authResp = (SendAuth.Resp)resp;
final String code = authResp.code;
getaccess_token(code);
}
finish();
}
private void getaccess_token(String code) {
Map<String, String> map = new HashMap<String, String>();
map.put("appid", Constants.APP_ID);
map.put("secret", Constants.AppSecret);
map.put("code", code);
map.put("grant_type", "authorization_code");
register.StringGETrequest(map, WX_Myurl.getwxaccess_token,
new Volleyinterface1(this, Volleyinterface1.mlistener,
Volleyinterface1.mErrorLisener) {
@Override
public void onsuccess(String result) {
try {
JSONObject object = new JSONObject(result);
String access_token = object
.optString("access_token");
SpUtil.setStringSharedPerference(sp,
"access_token", access_token);
int expires_in = object.optInt("expires_in");
String refresh_token = object
.optString("refresh_token");
SpUtil.setStringSharedPerference(sp,
"refresh_token", refresh_token);
String openid = object.optString("openid");
// getuserinfo(access_token,openid);
SpUtil.setStringSharedPerference(sp, "openid",
openid);
getUserInfo(access_token, openid);
// Toast.makeText(
// WXEntryActivity.this,
// "access_token+=" + expires_in
// + "refresh_token" + refresh_token,
// Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onerror(VolleyError arg0) {
Log.i("WxError","Start");
arg0.printStackTrace();
Log.i("WxError",arg0.toString());
Log.i("WxError",arg0.getMessage());
Log.i("WxError","End");
}
});
}
protected void getuserinfo(String access_token, String openid) {
Map<String, String> map = new HashMap<String, String>();
map.put("access_token", access_token);
map.put("openid", openid);
register.StringGETrequest(map, WX_Myurl.getwxuserinfo,
new Volleyinterface1(this, Volleyinterface1.mlistener,
Volleyinterface1.mErrorLisener) {
@Override
public void onsuccess(String result) {
String str = null;
try {
try {
// URLEncoder、URLDecoder进行URL参数的转码与解码
URLEncoder.encode(result, "utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// EntityUtils.toString(response.getEntity(),HTTP.UTF_8);//在这里转换
JSONObject object = new JSONObject(result);
// Toast.makeText(WXEntryActivity.this,
// "result=" + str, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onerror(VolleyError arg0) {
}
});
}
@SuppressWarnings("deprecation")
public static String getWeixinUserinfo(String access_token, String openid) {
String URLs = WX_Myurl.getwxuserinfo;// 微信登录地址
String result = "";
List<NameValuePair> list = new ArrayList<NameValuePair>();
NameValuePair pairappid = new BasicNameValuePair("access_token",
access_token);
NameValuePair pairsecret = new BasicNameValuePair("openid", openid);
list.add(pairappid);
list.add(pairsecret);
try {
HttpEntity requestHttpEntity = new UrlEncodedFormEntity(list,
HTTP.UTF_8);
URL url = new URL(URLs);
URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(),
url.getQuery(), null);
HttpPost httpPost = new HttpPost(uri);
httpPost.setEntity(requestHttpEntity);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(httpPost);
if (response.getStatusLine().getStatusCode() == 200) {
result = EntityUtils.toString(response.getEntity(), HTTP.UTF_8);// 在这里转换
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public interface OnGetUserInfoListener {
void onGetUserInfo(String userInfo); // json字符串
void onNetError();
}
static class GetUserInfoTask extends AsyncTask<Object, Void, String> {
private OnGetUserInfoListener mListener;
private String mUrl;
public GetUserInfoTask(OnGetUserInfoListener listener,
String getUserInfoUrl) {
mListener = listener;
mUrl = getUserInfoUrl;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Object... params) {
HttpURLConnection conn = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try {
conn = (HttpURLConnection) new URL(mUrl).openConnection();
in = new BufferedReader(new InputStreamReader(
conn.getInputStream(), "UTF-8"));
String buf;
while ((buf = in.readLine()) != null)
result.append(buf);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (conn != null)
conn.disconnect();
// FileUtils.close(in);
}
return result.toString();
}
@Override
protected void onPostExecute(String s) {
Log.d("", "onPostExecute " + s);
mListener.onGetUserInfo(s);
}
}
private void getUserInfo(String accessToken, String openId) {
String url = "https://api.weixin.qq.com/sns/userinfo?"
+ "access_token=" + accessToken + "&openid=" + openId;
GetUserInfoTask mGetUserInfoTask = new GetUserInfoTask(
new OnGetUserInfoListener() {
@Override
public void onNetError() {
}
@Override
public void onGetUserInfo(String userInfo) {
// text.setText(userInfo);
JSONObject object;
try {
object = new JSONObject(userInfo);
System.out.println(userInfo);
String url = object.optString("headimgurl");
String unionid = object.optString("unionid");
String openid = object.optString("openid");
String nickname = object.optString("nickname");
String sex = object.optString("sex");
String country = object.optString("country");
SpUtil.setStringSharedPerference(sp, "country",
country);
String city = object.optString("city");
SpUtil.setStringSharedPerference(sp, "city", city);
String province = object.optString("province");
SpUtil.setStringSharedPerference(sp, "province",
province);
SpUtil.setStringSharedPerference(sp, "unionid",
unionid);
SpUtil.setStringSharedPerference(sp, "headimgurl",
url);
SpUtil.setStringSharedPerference(sp, "openid",
openid);
SpUtil.setStringSharedPerference(sp, "nickname",
nickname);
SpUtil.setStringSharedPerference(sp, "sex", sex);
// ImageListener in1 = ImageLoader.getImageListener(
// image, R.drawable.ic_launcher,
// R.drawable.ic_launcher);
// ImageCacheManager.loadImage(url, in1);
sharehandler.sendEmptyMessage(1);
finish();
} catch (JSONException e) {
e.printStackTrace();
}
// Toast.makeText(WXEntryActivity.this,
// "result=" + userInfo, Toast.LENGTH_LONG).show();
}
}, url); // this代表WXEntryActivity.this
mGetUserInfoTask.execute();
}
private void goToGetMsg() {
}
private void goToShowMsg(ShowMessageFromWX.Req showReq) {
}
}

View File

@@ -0,0 +1,94 @@
package com.jx.jyhd.wxapi;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.jx.jyhd.R;
import com.jx.jyhd.simcpux.Constants;
import com.jx.jyhd.simcpux.Util;
import com.tsgame.tsgame_niuniu.util.Settingutil;
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
private IWXAPI api;
public static Handler handler;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pay_result);
api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
api.handleIntent(getIntent(), this);
Util.verifyStoragePermissions(this);
}
public void setHandler(Handler handler) {
this.handler = handler;
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
api.handleIntent(intent, this);
}
@Override
public void onReq(BaseReq baseReq) {
}
@Override
public void onResp(BaseResp baseResp) {
int what = 0;
Log.d(TAG, "onPayFinish, errCode = " + baseResp.errCode);
if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
// Toast.makeText(this, "进入", 1).show();
switch (baseResp.errCode) {
case BaseResp.ErrCode.ERR_OK:
Toast.makeText(this, "您支付成功", Toast.LENGTH_SHORT).show();
what = 1;
System.out.println("-----------------------");
break;
case BaseResp.ErrCode.ERR_USER_CANCEL:
Toast.makeText(this, "您取消支付", Toast.LENGTH_SHORT).show();
break;
case BaseResp.ErrCode.ERR_AUTH_DENIED:
Toast.makeText(this, "支付失败", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
if (Settingutil.iswxpay) {
Settingutil.iswxpay = false;
handler.sendEmptyMessage(what);
}
finish();
}
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
}

View File

@@ -0,0 +1,428 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* 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.lsjwzh.widget.materialloadingprogressbar;
import com.jx.jyhd.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.widget.ImageView;
/**
* Private class created to work around issues with AnimationListeners being
* called before the animation is actually complete and support shadows on older
* platforms.
*
*/
@SuppressLint("AppCompatCustomView")
public class CircleProgressBar extends ImageView {
private static final int KEY_SHADOW_COLOR = 0x1E000000;
private static final int FILL_SHADOW_COLOR = 0x3D000000;
// PX
private static final float X_OFFSET = 0f;
private static final float Y_OFFSET = 1.75f;
private static final float SHADOW_RADIUS = 3.5f;
private static final int SHADOW_ELEVATION = 4;
private static final int DEFAULT_CIRCLE_BG_LIGHT = 0xFFFAFAFA;
private static final int DEFAULT_CIRCLE_DIAMETER = 56;
private static final int STROKE_WIDTH_LARGE = 3;
public static final int DEFAULT_TEXT_SIZE = 9;
private Animation.AnimationListener mListener;
private int mShadowRadius;
private int mBackGroundColor;
private int mProgressColor;
private int mProgressStokeWidth;
private int mArrowWidth;
private int mArrowHeight;
private int mProgress;
private int mMax;
private int mDiameter;
private int mInnerRadius;
private Paint mTextPaint;
private int mTextColor;
private int mTextSize;
private boolean mIfDrawText;
private boolean mShowArrow;
private MaterialProgressDrawable mProgressDrawable;
private ShapeDrawable mBgCircle;
private boolean mCircleBackgroundEnabled;
private int[] mColors = new int[]{Color.BLACK};
Context context;
public CircleProgressBar(Context context) {
super(context);
init(context, null, 0);
}
public CircleProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public CircleProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
}
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.CircleProgressBar, defStyleAttr,0);
this.context=context;
// <attr name="mlpb_inner_radius" format="dimension"/>
// <attr name="mlpb_background_color" format="color"/>
// <attr name="mlpb_progress_color" format="color"/>
// <attr name="mlpb_progress_stoke_width" format="dimension"/>
// <attr name="mlpb_arrow_width" format="dimension"/>
// <attr name="mlpb_arrow_height" format="dimension"/>
//
// <attr name="mlpb_progress" format="integer"/>
// <attr name="mlpb_max" format="integer"/>
//
//
// <attr name="mlpb_progress_text_size" format="dimension"/>
// <attr name="mlpb_progress_text_color" format="color"/>
//
// <attr name="mlpb_progress_text_offset" format="dimension"/>
//
// <attr name="mlpb_progress_text_visibility" format="enum">
// <enum name="visible" value="0"/>
// <enum name="invisible" value="1"/>
// </attr>
final float density = getContext().getResources().getDisplayMetrics().density;
mBackGroundColor = a.getColor(
R.styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT);
mProgressColor = a.getColor(
R.styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT);//ToDO 默认颜色
mInnerRadius = a.getDimensionPixelOffset(
R.styleable.CircleProgressBar_mlpb_inner_radius, -1);
mProgressStokeWidth = a.getDimensionPixelOffset(
R.styleable.CircleProgressBar_mlpb_progress_stoke_width, (int) (STROKE_WIDTH_LARGE*density));
mArrowWidth = a.getDimensionPixelOffset(
R.styleable.CircleProgressBar_mlpb_arrow_width, -1);
mArrowHeight = a.getDimensionPixelOffset(
R.styleable.CircleProgressBar_mlpb_arrow_height, -1);
mTextSize = a.getDimensionPixelOffset(
R.styleable.CircleProgressBar_mlpb_progress_text_size, (int)(DEFAULT_TEXT_SIZE *density));
mTextColor = a.getColor(
R.styleable.CircleProgressBar_mlpb_progress_text_color, Color.BLACK);
mShowArrow = a.getBoolean(R.styleable.CircleProgressBar_mlpb_show_arrow,false);
mCircleBackgroundEnabled = a.getBoolean(R.styleable.CircleProgressBar_mlpb_enable_circle_background,true);
mProgress = a.getInt(R.styleable.CircleProgressBar_mlpb_progress, 0);
mMax = a.getInt(R.styleable.CircleProgressBar_mlpb_max, 100);
int textVisible = a.getInt(R.styleable.CircleProgressBar_mlpb_progress_text_visibility,1);
if(textVisible != 1){
mIfDrawText = true;
}
mTextPaint = new Paint();
mTextPaint.setStyle(Paint.Style.FILL);
mTextPaint.setColor(mTextColor);
mTextPaint.setTextSize(mTextSize);
mTextPaint.setAntiAlias(true);
a.recycle();
mProgressDrawable = new MaterialProgressDrawable(getContext(), this);
super.setImageDrawable(mProgressDrawable);
}
private boolean elevationSupported() {
return android.os.Build.VERSION.SDK_INT >= 21;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (!elevationSupported()) {
setMeasuredDimension(getMeasuredWidth() + mShadowRadius * 2, getMeasuredHeight()
+ mShadowRadius * 2);
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
final float density = getContext().getResources().getDisplayMetrics().density;
mDiameter = Math.min(getMeasuredWidth(),getMeasuredHeight());
if(mDiameter <=0){
mDiameter = (int)density*DEFAULT_CIRCLE_DIAMETER;
}
if(getBackground()==null&& mCircleBackgroundEnabled){
final int shadowYOffset = (int) (density * Y_OFFSET);
final int shadowXOffset = (int) (density * X_OFFSET);
mShadowRadius = (int) (density * SHADOW_RADIUS);
if (elevationSupported()) {
mBgCircle = new ShapeDrawable(new OvalShape());
ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
} else {
OvalShape oval = new OvalShadow(mShadowRadius, mDiameter);
mBgCircle = new ShapeDrawable(oval);
ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset,
KEY_SHADOW_COLOR);
final int padding = (int) mShadowRadius;
// set padding so the inner image sits correctly within the shadow.
setPadding(padding, padding, padding, padding);
}
mBgCircle.getPaint().setColor(mBackGroundColor);
setBackgroundDrawable(mBgCircle);
}
mProgressDrawable.setBackgroundColor(mBackGroundColor);
mProgressDrawable.setColorSchemeColors(mColors);
mProgressDrawable.setSizeParameters(mDiameter, mDiameter,
mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius,
mProgressStokeWidth,
mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth,
mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
if(isShowArrow()){
mProgressDrawable.setArrowScale(1f);
mProgressDrawable.showArrow(true);
}
super.setImageDrawable(null);
super.setImageDrawable(mProgressDrawable);
mProgressDrawable.setAlpha(255);
mProgressDrawable.start();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(mIfDrawText) {
String text = String.format("%s%%", mProgress);
int x = getWidth() / 2 - text.length() * mTextSize / 4;
int y = getHeight() / 2 + mTextSize / 4;
canvas.drawText(text, x, y, mTextPaint);
}
}
@Override
final public void setImageResource(int resId) {
}
public boolean isShowArrow() {
return mShowArrow;
}
public void setShowArrow(boolean showArrow) {
this.mShowArrow = showArrow;
}
@Override
final public void setImageURI(Uri uri) {
super.setImageURI(uri);
}
@Override
final public void setImageDrawable(Drawable drawable) {
}
public void setAnimationListener(Animation.AnimationListener listener) {
mListener = listener;
}
@Override
public void onAnimationStart() {
super.onAnimationStart();
if (mListener != null) {
mListener.onAnimationStart(getAnimation());
}
}
@Override
public void onAnimationEnd() {
super.onAnimationEnd();
if (mListener != null) {
mListener.onAnimationEnd(getAnimation());
}
}
/**
* Set the color resources used in the progress animation from color resources.
* The first color will also be the color of the bar that grows in response
* to a user swipe gesture.
*
* @param colorResIds
*/
@SuppressWarnings("deprecation")
public void setColorSchemeResources(int... colorResIds) {
final Resources res = getResources();
int[] colorRes = new int[colorResIds.length];
for (int i = 0; i < colorResIds.length; i++) {
colorRes[i] = (ContextCompat.getColor(context, colorResIds[i]));
}
setColorSchemeColors(colorRes);
}
/**
* Set the colors used in the progress animation. The first
* color will also be the color of the bar that grows in response to a user
* swipe gesture.
*
* @param colors
*/
public void setColorSchemeColors(int... colors) {
mColors = colors;
if(mProgressDrawable!=null) {
mProgressDrawable.setColorSchemeColors(colors);
}
}
/**
* Update the background color of the mBgCircle image view.
*/
public void setBackgroundColor(int colorRes) {
if (getBackground() instanceof ShapeDrawable) {
final Resources res = getResources();
((ShapeDrawable) getBackground()).getPaint().setColor(ContextCompat.getColor(context, colorRes));
}
}
public boolean isShowProgressText() {
return mIfDrawText;
}
public void setShowProgressText(boolean mIfDrawText) {
this.mIfDrawText = mIfDrawText;
}
public int getMax() {
return mMax;
}
public void setMax(int max) {
mMax = max;
}
public int getProgress() {
return mProgress;
}
public void setProgress(int progress) {
if (getMax() > 0) {
mProgress = progress;
}
}
public boolean circleBackgroundEnabled() {
return mCircleBackgroundEnabled;
}
public void setCircleBackgroundEnabled(boolean enableCircleBackground) {
this.mCircleBackgroundEnabled = enableCircleBackground;
}
@Override
public int getVisibility() {
return super.getVisibility();
}
@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
if (mProgressDrawable != null) {
if(visibility!=VISIBLE) {
mProgressDrawable.stop();
}
mProgressDrawable.setVisible(visibility == VISIBLE, false);
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mProgressDrawable != null) {
mProgressDrawable.stop();
mProgressDrawable.setVisible(getVisibility() == VISIBLE, false);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mProgressDrawable != null) {
mProgressDrawable.stop();
mProgressDrawable.setVisible(false, false);
}
}
private class OvalShadow extends OvalShape {
private RadialGradient mRadialGradient;
private int mShadowRadius;
private Paint mShadowPaint;
private int mCircleDiameter;
public OvalShadow(int shadowRadius, int circleDiameter) {
super();
mShadowPaint = new Paint();
mShadowRadius = shadowRadius;
mCircleDiameter = circleDiameter;
mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
mShadowRadius, new int[] {
FILL_SHADOW_COLOR, Color.TRANSPARENT
}, null, Shader.TileMode.CLAMP);
mShadowPaint.setShader(mRadialGradient);
}
@Override
public void draw(Canvas canvas, Paint paint) {
final int viewWidth = CircleProgressBar.this.getWidth();
final int viewHeight = CircleProgressBar.this.getHeight();
canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2 + mShadowRadius),
mShadowPaint);
canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2), paint);
}
}
}

View File

@@ -0,0 +1,723 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* 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.lsjwzh.widget.materialloadingprogressbar;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
/**
* Fancy progress indicator for Material theme.
*
* @hide
*/
public class MaterialProgressDrawable extends Drawable implements Animatable {
// Maps to ProgressBar.Large style
public static final int LARGE = 0;
// Maps to ProgressBar default style
public static final int DEFAULT = 1;
private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
private static final Interpolator END_CURVE_INTERPOLATOR = new EndCurveInterpolator();
private static final Interpolator START_CURVE_INTERPOLATOR = new StartCurveInterpolator();
private static final Interpolator EASE_INTERPOLATOR = new AccelerateDecelerateInterpolator();
// Maps to ProgressBar default style
private static final int CIRCLE_DIAMETER = 40;
private static final float CENTER_RADIUS = 8.75f; //should add up to 10 when + stroke_width
private static final float STROKE_WIDTH = 2.5f;
// Maps to ProgressBar.Large style
private static final int CIRCLE_DIAMETER_LARGE = 56;
private static final float CENTER_RADIUS_LARGE = 12.5f;
static final float STROKE_WIDTH_LARGE = 3f;
/**
* The duration of a single progress spin in milliseconds.
*/
private static final int ANIMATION_DURATION = 1000 * 80 / 60;
/**
* The number of points in the progress "star".
*/
private static final float NUM_POINTS = 5f;
/**
* Layout info for the arrowhead in dp
*/
private static final int ARROW_WIDTH = 10;
private static final int ARROW_HEIGHT = 5;
private static final float ARROW_OFFSET_ANGLE = 0;
/**
* Layout info for the arrowhead for the large spinner in dp
*/
static final int ARROW_WIDTH_LARGE = 12;
static final int ARROW_HEIGHT_LARGE = 6;
private static final float MAX_PROGRESS_ARC = .8f;
private final int[] COLORS = new int[]{
Color.BLACK
};
/**
* The list of animators operating on this drawable.
*/
private final ArrayList<Animation> mAnimators = new ArrayList<Animation>();
/**
* The indicator ring, used to manage animation state.
*/
private final Ring mRing;
private final Callback mCallback = new Callback() {
@Override
public void invalidateDrawable(Drawable d) {
invalidateSelf();
}
@Override
public void scheduleDrawable(Drawable d, Runnable what, long when) {
scheduleSelf(what, when);
}
@Override
public void unscheduleDrawable(Drawable d, Runnable what) {
unscheduleSelf(what);
}
};
boolean mFinishing;
/**
* Canvas rotation in degrees.
*/
private float mRotation;
private Resources mResources;
private View mAnimExcutor;
private Animation mAnimation;
private float mRotationCount;
private double mWidth;
private double mHeight;
public MaterialProgressDrawable(Context context, View animExcutor) {
mAnimExcutor = animExcutor;
mResources = context.getResources();
mRing = new Ring(mCallback);
mRing.setColors(COLORS);
updateSizes(DEFAULT);
setupAnimators();
}
public void setSizeParameters(double progressCircleWidth, double progressCircleHeight,
double centerRadius, double strokeWidth, float arrowWidth, float arrowHeight) {
final Ring ring = mRing;
mWidth = progressCircleWidth;
mHeight = progressCircleHeight ;
ring.setStrokeWidth((float) strokeWidth );
ring.setCenterRadius(centerRadius);
ring.setColorIndex(0);
ring.setArrowDimensions(arrowWidth , arrowHeight );
ring.setInsets((int) mWidth, (int) mHeight);
}
/**
* Set the overall size for the progress spinner. This updates the radius
* and stroke width of the ring.
*
* @param size One of {@link MaterialProgressDrawable.LARGE} or
* {@link MaterialProgressDrawable.DEFAULT}
*/
public void updateSizes(@ProgressDrawableSize int size) {
final DisplayMetrics metrics = mResources.getDisplayMetrics();
final float screenDensity = metrics.density;
if (size == LARGE) {
setSizeParameters(CIRCLE_DIAMETER_LARGE*screenDensity, CIRCLE_DIAMETER_LARGE*screenDensity, CENTER_RADIUS_LARGE*screenDensity,
STROKE_WIDTH_LARGE*screenDensity, ARROW_WIDTH_LARGE*screenDensity, ARROW_HEIGHT_LARGE*screenDensity);
} else {
setSizeParameters(CIRCLE_DIAMETER*screenDensity, CIRCLE_DIAMETER*screenDensity, CENTER_RADIUS*screenDensity, STROKE_WIDTH*screenDensity,
ARROW_WIDTH*screenDensity, ARROW_HEIGHT*screenDensity);
}
}
/**
* @param show Set to true to display the arrowhead on the progress spinner.
*/
public void showArrow(boolean show) {
mRing.setShowArrow(show);
}
/**
* @param scale Set the scale of the arrowhead for the spinner.
*/
public void setArrowScale(float scale) {
mRing.setArrowScale(scale);
}
/**
* Set the start and end trim for the progress spinner arc.
*
* @param startAngle start angle
* @param endAngle end angle
*/
public void setStartEndTrim(float startAngle, float endAngle) {
mRing.setStartTrim(startAngle);
mRing.setEndTrim(endAngle);
}
/**
* Set the amount of rotation to apply to the progress spinner.
*
* @param rotation Rotation is from [0..1]
*/
public void setProgressRotation(float rotation) {
mRing.setRotation(rotation);
}
/**
* Update the background color of the circle image view.
*/
public void setBackgroundColor(int color) {
mRing.setBackgroundColor(color);
}
/**
* Set the colors used in the progress animation from color resources.
* The first color will also be the color of the bar that grows in response
* to a user swipe gesture.
*
* @param colors
*/
public void setColorSchemeColors(int... colors) {
mRing.setColors(colors);
mRing.setColorIndex(0);
}
@Override
public int getIntrinsicHeight() {
return (int) mHeight;
}
@Override
public int getIntrinsicWidth() {
return (int) mWidth;
}
@Override
public void draw(Canvas c) {
final Rect bounds = getBounds();
final int saveCount = c.save();
c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
mRing.draw(c, bounds);
c.restoreToCount(saveCount);
}
public int getAlpha() {
return mRing.getAlpha();
}
@Override
public void setAlpha(int alpha) {
mRing.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
mRing.setColorFilter(colorFilter);
}
@SuppressWarnings("unused")
private float getRotation() {
return mRotation;
}
@SuppressWarnings("unused")
void setRotation(float rotation) {
mRotation = rotation;
invalidateSelf();
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
@Override
public boolean isRunning() {
final ArrayList<Animation> animators = mAnimators;
final int N = animators.size();
for (int i = 0; i < N; i++) {
final Animation animator = animators.get(i);
if (animator.hasStarted() && !animator.hasEnded()) {
return true;
}
}
return false;
}
@Override
public void start() {
mAnimation.reset();
mRing.storeOriginals();
// Already showing some part of the ring
if (mRing.getEndTrim() != mRing.getStartTrim()) {
mFinishing = true;
mAnimation.setDuration(ANIMATION_DURATION / 2);
mAnimExcutor.startAnimation(mAnimation);
} else {
mRing.setColorIndex(0);
mRing.resetOriginals();
mAnimation.setDuration(ANIMATION_DURATION);
mAnimExcutor.startAnimation(mAnimation);
}
}
@Override
public void stop() {
mAnimExcutor.clearAnimation();
setRotation(0);
mRing.setShowArrow(false);
mRing.setColorIndex(0);
mRing.resetOriginals();
}
private void applyFinishTranslation(float interpolatedTime, Ring ring) {
// shrink back down and complete a full rotation before
// starting other circles
// Rotation goes between [0..1].
float targetRotation = (float) (Math.floor(ring.getStartingRotation() / MAX_PROGRESS_ARC)
+ 1f);
final float startTrim = ring.getStartingStartTrim()
+ (ring.getStartingEndTrim() - ring.getStartingStartTrim()) * interpolatedTime;
ring.setStartTrim(startTrim);
final float rotation = ring.getStartingRotation()
+ ((targetRotation - ring.getStartingRotation()) * interpolatedTime);
ring.setRotation(rotation);
}
private void setupAnimators() {
final Ring ring = mRing;
final Animation animation = new Animation() {
@Override
public void applyTransformation(float interpolatedTime, Transformation t) {
if (mFinishing) {
applyFinishTranslation(interpolatedTime, ring);
} else {
// The minProgressArc is calculated from 0 to create an
// angle that
// matches the stroke width.
final float minProgressArc = (float) Math.toRadians(
ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius()));
final float startingEndTrim = ring.getStartingEndTrim();
final float startingTrim = ring.getStartingStartTrim();
final float startingRotation = ring.getStartingRotation();
// Offset the minProgressArc to where the endTrim is
// located.
final float minArc = MAX_PROGRESS_ARC - minProgressArc;
float endTrim = startingEndTrim + (minArc
* START_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
float startTrim = startingTrim + (MAX_PROGRESS_ARC
* END_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
final float sweepTrim = endTrim-startTrim;
//Avoid the ring to be a full circle
if(Math.abs(sweepTrim)>=1){
endTrim = startTrim+0.5f;
}
ring.setEndTrim(endTrim);
ring.setStartTrim(startTrim);
final float rotation = startingRotation + (0.25f * interpolatedTime);
ring.setRotation(rotation);
float groupRotation = ((720.0f / NUM_POINTS) * interpolatedTime)
+ (720.0f * (mRotationCount / NUM_POINTS));
setRotation(groupRotation);
}
}
};
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.RESTART);
animation.setInterpolator(LINEAR_INTERPOLATOR);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
mRotationCount = 0;
}
@Override
public void onAnimationEnd(Animation animation) {
// do nothing
}
@Override
public void onAnimationRepeat(Animation animation) {
ring.storeOriginals();
ring.goToNextColor();
ring.setStartTrim(ring.getEndTrim());
if (mFinishing) {
// finished closing the last ring from the swipe gesture; go
// into progress mode
mFinishing = false;
animation.setDuration(ANIMATION_DURATION);
ring.setShowArrow(false);
} else {
mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
}
}
});
mAnimation = animation;
}
@Retention(RetentionPolicy.CLASS)
@IntDef({LARGE, DEFAULT})
public @interface ProgressDrawableSize {
}
private static class Ring {
private final RectF mTempBounds = new RectF();
private final Paint mPaint = new Paint();
private final Paint mArrowPaint = new Paint();
private final Callback mCallback;
private final Paint mCirclePaint = new Paint();
private float mStartTrim = 0.0f;
private float mEndTrim = 0.0f;
private float mRotation = 0.0f;
private float mStrokeWidth = 5.0f;
private float mStrokeInset = 2.5f;
private int[] mColors;
// mColorIndex represents the offset into the available mColors that the
// progress circle should currently display. As the progress circle is
// animating, the mColorIndex moves by one to the next available color.
private int mColorIndex;
private float mStartingStartTrim;
private float mStartingEndTrim;
private float mStartingRotation;
private boolean mShowArrow;
private Path mArrow;
private float mArrowScale;
private double mRingCenterRadius;
private int mArrowWidth;
private int mArrowHeight;
private int mAlpha;
private int mBackgroundColor;
public Ring(Callback callback) {
mCallback = callback;
mPaint.setStrokeCap(Paint.Cap.SQUARE);
mPaint.setAntiAlias(true);
mPaint.setStyle(Style.STROKE);
mArrowPaint.setStyle(Paint.Style.FILL);
mArrowPaint.setAntiAlias(true);
}
public void setBackgroundColor(int color) {
mBackgroundColor = color;
}
/**
* Set the dimensions of the arrowhead.
*
* @param width Width of the hypotenuse of the arrow head
* @param height Height of the arrow point
*/
public void setArrowDimensions(float width, float height) {
mArrowWidth = (int) width;
mArrowHeight = (int) height;
}
/**
* Draw the progress spinner
*/
public void draw(Canvas c, Rect bounds) {
final RectF arcBounds = mTempBounds;
arcBounds.set(bounds);
arcBounds.inset(mStrokeInset, mStrokeInset);
final float startAngle = (mStartTrim + mRotation) * 360;
final float endAngle = (mEndTrim + mRotation) * 360;
float sweepAngle = endAngle - startAngle;
mPaint.setColor(mColors[mColorIndex]);
c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint);
drawTriangle(c, startAngle, sweepAngle, bounds);
if (mAlpha < 255) {
mCirclePaint.setColor(mBackgroundColor);
mCirclePaint.setAlpha(255 - mAlpha);
c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2,
mCirclePaint);
}
}
private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) {
if (mShowArrow) {
if (mArrow == null) {
mArrow = new android.graphics.Path();
mArrow.setFillType(android.graphics.Path.FillType.EVEN_ODD);
} else {
mArrow.reset();
}
// Adjust the position of the triangle so that it is inset as
// much as the arc, but also centered on the arc.
float x = (float) (mRingCenterRadius * Math.cos(0) + bounds.exactCenterX());
float y = (float) (mRingCenterRadius * Math.sin(0) + bounds.exactCenterY());
// Update the path each time. This works around an issue in SKIA
// where concatenating a rotation matrix to a scale matrix
// ignored a starting negative rotation. This appears to have
// been fixed as of API 21.
mArrow.moveTo(0, 0);
mArrow.lineTo((mArrowWidth) * mArrowScale, 0);
mArrow.lineTo(((mArrowWidth) * mArrowScale / 2), (mArrowHeight
* mArrowScale));
mArrow.offset(x-((mArrowWidth) * mArrowScale / 2), y);
mArrow.close();
// draw a triangle
mArrowPaint.setColor(mColors[mColorIndex]);
//when sweepAngle < 0 adjust the position of the arrow
c.rotate(startAngle + (sweepAngle<0?0:sweepAngle) - ARROW_OFFSET_ANGLE, bounds.exactCenterX(),
bounds.exactCenterY());
c.drawPath(mArrow, mArrowPaint);
}
}
/**
* Set the colors the progress spinner alternates between.
*
* @param colors Array of integers describing the colors. Must be non-<code>null</code>.
*/
public void setColors(@NonNull int[] colors) {
mColors = colors;
// if colors are reset, make sure to reset the color index as well
setColorIndex(0);
}
/**
* @param index Index into the color array of the color to display in
* the progress spinner.
*/
public void setColorIndex(int index) {
mColorIndex = index;
}
/**
* Proceed to the next available ring color. This will automatically
* wrap back to the beginning of colors.
*/
public void goToNextColor() {
mColorIndex = (mColorIndex + 1) % (mColors.length);
}
public void setColorFilter(ColorFilter filter) {
mPaint.setColorFilter(filter);
invalidateSelf();
}
/**
* @return Current alpha of the progress spinner and arrowhead.
*/
public int getAlpha() {
return mAlpha;
}
/**
* @param alpha Set the alpha of the progress spinner and associated arrowhead.
*/
public void setAlpha(int alpha) {
mAlpha = alpha;
}
@SuppressWarnings("unused")
public float getStrokeWidth() {
return mStrokeWidth;
}
/**
* @param strokeWidth Set the stroke width of the progress spinner in pixels.
*/
public void setStrokeWidth(float strokeWidth) {
mStrokeWidth = strokeWidth;
mPaint.setStrokeWidth(strokeWidth);
invalidateSelf();
}
@SuppressWarnings("unused")
public float getStartTrim() {
return mStartTrim;
}
@SuppressWarnings("unused")
public void setStartTrim(float startTrim) {
mStartTrim = startTrim;
invalidateSelf();
}
public float getStartingStartTrim() {
return mStartingStartTrim;
}
public float getStartingEndTrim() {
return mStartingEndTrim;
}
@SuppressWarnings("unused")
public float getEndTrim() {
return mEndTrim;
}
@SuppressWarnings("unused")
public void setEndTrim(float endTrim) {
mEndTrim = endTrim;
invalidateSelf();
}
@SuppressWarnings("unused")
public float getRotation() {
return mRotation;
}
@SuppressWarnings("unused")
public void setRotation(float rotation) {
mRotation = rotation;
invalidateSelf();
}
public void setInsets(int width, int height) {
final float minEdge = (float) Math.min(width, height);
float insets;
if (mRingCenterRadius <= 0 || minEdge < 0) {
insets = (float) Math.ceil(mStrokeWidth / 2.0f);
} else {
insets = (float) (minEdge / 2.0f - mRingCenterRadius);
}
mStrokeInset = insets;
}
@SuppressWarnings("unused")
public float getInsets() {
return mStrokeInset;
}
public double getCenterRadius() {
return mRingCenterRadius;
}
/**
* @param centerRadius Inner radius in px of the circle the progress
* spinner arc traces.
*/
public void setCenterRadius(double centerRadius) {
mRingCenterRadius = centerRadius;
}
/**
* @param show Set to true to show the arrow head on the progress spinner.
*/
public void setShowArrow(boolean show) {
if (mShowArrow != show) {
mShowArrow = show;
invalidateSelf();
}
}
/**
* @param scale Set the scale of the arrowhead for the spinner.
*/
public void setArrowScale(float scale) {
if (scale != mArrowScale) {
mArrowScale = scale;
invalidateSelf();
}
}
/**
* @return The amount the progress spinner is currently rotated, between [0..1].
*/
public float getStartingRotation() {
return mStartingRotation;
}
/**
* If the start / end trim are offset to begin with, store them so that
* animation starts from that offset.
*/
public void storeOriginals() {
mStartingStartTrim = mStartTrim;
mStartingEndTrim = mEndTrim;
mStartingRotation = mRotation;
}
/**
* Reset the progress spinner to default rotation, start and end angles.
*/
public void resetOriginals() {
mStartingStartTrim = 0;
mStartingEndTrim = 0;
mStartingRotation = 0;
setStartTrim(0);
setEndTrim(0);
setRotation(0);
}
private void invalidateSelf() {
mCallback.invalidateDrawable(null);
}
}
/**
* Squishes the interpolation curve into the second half of the animation.
*/
private static class EndCurveInterpolator extends AccelerateDecelerateInterpolator {
@Override
public float getInterpolation(float input) {
return super.getInterpolation(Math.max(0, (input - 0.5f) * 2.0f));
}
}
/**
* Squishes the interpolation curve into the first half of the animation.
*/
private static class StartCurveInterpolator extends AccelerateDecelerateInterpolator {
@Override
public float getInterpolation(float input) {
return super.getInterpolation(Math.min(1, input * 2.0f));
}
}
}

View File

@@ -0,0 +1,52 @@
package com.lsjwzh.widget.materialloadingprogressbar;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import com.jx.jyhd.R;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
public class WebviewProgressDialog extends Dialog {
static CircleProgressBar progress1;
private static WebviewProgressDialog customProgressDialog = null;
public WebviewProgressDialog(Context context, int themeResId) {
super(context, themeResId);
// TODO Auto-generated constructor stub
}
public WebviewProgressDialog(Context context) {
super(context);
}
@SuppressLint("InlinedApi")
public static WebviewProgressDialog createDialog(Context context) {
customProgressDialog = new WebviewProgressDialog(context,
R.style.CustomProgressDialog);
customProgressDialog.setContentView(R.layout.webviewdialog);
progress1 = (CircleProgressBar) customProgressDialog
.findViewById(R.id.progress1);
progress1.setColorSchemeResources(android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
return customProgressDialog;
}
public void setProgress(int Progress) {
progress1.setProgress(Progress);
}
}

View File

@@ -0,0 +1,190 @@
package com.nickming.view;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
import android.media.MediaRecorder;
public class AudioManager {
private MediaRecorder mRecorder;
private String mDirString;//
private String mCurrentFilePathString;
public boolean isPrepared = false;// 是否准备好了
/**
* 单例化的方法 1 先声明一个static 类型的变量a 2 在声明默认的构造函数 3 再用public synchronized static
* 类名 getInstance() { if(a==null) { a=new 类();} return a; } 或者用以下的方法
*/
/**
* 单例化这个类
*/
private static AudioManager mInstance;
private AudioManager(String dir) {
mDirString = dir;
}
public static AudioManager getInstance(String dir) {
if (mInstance == null) {
// 同步
synchronized (AudioManager.class) {
if (mInstance == null) {
mInstance = new AudioManager(dir);
}
}
}
return mInstance;
}
/**
* 回调函数准备完毕准备好后button才会开始显示录音框
*
* @author nickming
*
*/
public interface AudioStageListener {
void wellPrepared();
void resetPrepared();
}
public AudioStageListener mListener;
public void setOnAudioStageListener(AudioStageListener listener) {
mListener = listener;
}
// 准备方法
public void prepareAudio() {
try {
// 一开始应该是false的
isPrepared = false;
File dir = new File(mDirString);
if (!dir.exists()) {
dir.mkdirs();
}
String fileNameString = generalFileName();
File file = new File(dir, fileNameString);
mCurrentFilePathString = file.getAbsolutePath();
mRecorder = new MediaRecorder();
// 设置输出文件
mRecorder.setOutputFile(file.getAbsolutePath());
// 设置meidaRecorder的音频源是麦克风
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
// 设置文件音频的输出格式为amr
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
// 设置音频的编码格式为amr
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
// 严格遵守google官方api给出的mediaRecorder的状态流程图
mRecorder.prepare();
System.out.println("prepare()");
mRecorder.start();
System.out.println("start()");
// 准备结束
isPrepared = true;
// 已经准备好了,可以录制了
if (mListener != null) {
mListener.wellPrepared();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("音频==" + e.toString());
// 已经准备好了,可以录制了
if (mListener != null) {
mListener.resetPrepared();
}
}
}
/**
* 随机生成文件的名称
*
* @return
*/
private String generalFileName() {
// TODO Auto-generated method stub
return UUID.randomUUID().toString() + ".amr";// javaJDK提供的一个自动生成主键的方法。UUID(Universally
// Unique
// Identifier)全局唯一标识符,是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的,是由一个十六位的数字组成,表现出来的
// 形式
}
// 获得声音的level
public int getVoiceLevel(int maxLevel) {
// mRecorder.getMaxAmplitude()这个是音频的振幅范围值域是1-32767
if (isPrepared) {
try {
// 取证+1否则去不到7
return maxLevel * mRecorder.getMaxAmplitude() / 32768 + 1;
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
return 1;
}
// 释放资源
public void release() {
// 严格按照api流程进行
try {
mRecorder.setOnErrorListener(null);
mRecorder.setOnInfoListener(null);
mRecorder.setPreviewDisplay(null);
// 防止某些手机崩溃,例如联想
mRecorder.stop();
mRecorder.release();
mRecorder = null;
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (RuntimeException e) {
// TODO: handle exception
} catch (Exception e) {
// TODO: handle exception
}
}
// 取消,因为prepare时产生了一个文件所以cancel方法应该要删除这个文件
// 这是与release的方法的区别
public void cancel() {
if(mRecorder!=null){
release();
}
if (mCurrentFilePathString != null) {
File file = new File(mCurrentFilePathString);
file.delete();
mCurrentFilePathString = null;
}
}
public String getCurrentFilePath() {
// TODO Auto-generated method stub
return mCurrentFilePathString;
}
}

View File

@@ -0,0 +1,127 @@
package com.nickming.view;
import com.jx.jyhd.R;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class DialogManager {
private Dialog mDialog;
private ImageView mIcon;
private ImageView mVoice;
private TextView mLable;
private Context mContext;
public DialogManager(Context context) {
// TODO Auto-generated constructor stub
mContext = context;
}
public void showRecordingDialog() {
// TODO Auto-generated method stub
if(mContext==null){
System.out.println("上下文mContext为空");
}
mDialog = new Dialog(mContext,R.style.Theme_audioDialog);
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.dialog_manager, null);
mDialog.setContentView(view);
mIcon = (ImageView) mDialog.findViewById(R.id.dialog_icon);
mVoice = (ImageView) mDialog.findViewById(R.id.dialog_voice);
mLable = (TextView) mDialog.findViewById(R.id.recorder_dialogtext);
try {
mDialog.show();
} catch (Exception e) {
System.out.println("mDialog没有显示");
}
}
public void recording() {
if (mDialog != null && mDialog.isShowing()) {
mIcon.setVisibility(View.VISIBLE);
mVoice.setVisibility(View.VISIBLE);
mLable.setVisibility(View.VISIBLE);
mIcon.setImageResource(R.drawable.recorder);
mLable.setText(R.string.shouzhishanghua);
}
}
public void wantToCancel() {
// TODO Auto-generated method stub
if (mDialog != null && mDialog.isShowing()) {
mIcon.setVisibility(View.VISIBLE);
mVoice.setVisibility(View.GONE);
mLable.setVisibility(View.VISIBLE);
mIcon.setImageResource(R.drawable.cancel);
mLable.setText(R.string.want_to_cancle);
}
}
// ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>
public void tooShort() {
// TODO Auto-generated method stub
if (mDialog != null && mDialog.isShowing()) {
mIcon.setVisibility(View.VISIBLE);
mVoice.setVisibility(View.GONE);
mLable.setVisibility(View.VISIBLE);
mIcon.setImageResource(R.drawable.voice_to_short);
mLable.setText(R.string.tooshort);
}
}
public void dimissDialog() {
// TODO Auto-generated method stub
if (mDialog != null && mDialog.isShowing()) {
mDialog.dismiss();
mDialog = null;
}
}
public void updateVoiceLevel(int level) {
// TODO Auto-generated method stub
if (mDialog != null && mDialog.isShowing()) {
//<2F>Ȳ<EFBFBD><C8B2>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>״̬
// mIcon.setVisibility(View.VISIBLE);
// mVoice.setVisibility(View.VISIBLE);
// mLable.setVisibility(View.VISIBLE);
//ͨ<><CDA8>level<65><6C><EFBFBD>ҵ<EFBFBD>ͼƬ<CDBC><C6AC>id<69><64>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>switch<63><68>Ѱַ<D1B0><D6B7><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD><EFBFBD>ܻ<EFBFBD>Ƚϳ<C8BD>
int resId = mContext.getResources().getIdentifier("v" + level,
"drawable", mContext.getPackageName());
mVoice.setImageResource(resId);
}
}
}

View File

@@ -0,0 +1,410 @@
package com.nickming.view;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Build;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import java.io.*;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import static android.graphics.Bitmap.Config.ARGB_8888;
import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
/**
* Utility class to take screenshots of activity screen
*/
public final class Falcon {
//region Constants
private static final String TAG = "Falcon";
//endregion
//region Public API
/**
* Takes screenshot of provided activity and saves it to provided file.
* File content will be overwritten if there is already some content.
*
* @param activity Activity of which the screenshot will be taken.
* @param toFile File where the screenshot will be saved.
* If there is some content it will be overwritten
* @throws UnableToTakeScreenshotException When there is unexpected error during taking screenshot
*/
public static void takeScreenshot(Activity activity, final File toFile) {
if (activity == null) {
throw new IllegalArgumentException("Parameter activity cannot be null.");
}
if (toFile == null) {
throw new IllegalArgumentException("Parameter toFile cannot be null.");
}
Bitmap bitmap = null;
try {
bitmap = takeBitmapUnchecked(activity);
writeBitmap(bitmap, toFile);
} catch (Exception e) {
String message = "Unable to take screenshot to file " + toFile.getAbsolutePath()
+ " of activity " + activity.getClass().getName();
Log.e(TAG, message, e);
throw new UnableToTakeScreenshotException(message, e);
} finally {
if (bitmap != null) {
bitmap.recycle();
}
}
Log.d(TAG, "Screenshot captured to " + toFile.getAbsolutePath());
}
/**
* Takes screenshot of provided activity and puts it into bitmap.
*
* @param activity Activity of which the screenshot will be taken.
* @return Bitmap of what is displayed in activity.
* @throws UnableToTakeScreenshotException When there is unexpected error during taking screenshot
*/
public static Bitmap takeScreenshotBitmap(Activity activity) {
if (activity == null) {
throw new IllegalArgumentException("Parameter activity cannot be null.");
}
try {
return takeBitmapUnchecked(activity);
} catch (Exception e) {
String message = "Unable to take screenshot to bitmap of activity "
+ activity.getClass().getName();
Log.e(TAG, message, e);
throw new UnableToTakeScreenshotException(message, e);
}
}
//endregion
//region Methods
private static Bitmap takeBitmapUnchecked(Activity activity) throws InterruptedException {
final List<ViewRootData> viewRoots = getRootViews(activity);
if (viewRoots.isEmpty()) {
throw new UnableToTakeScreenshotException("Unable to capture any view data in " + activity);
}
int maxWidth = Integer.MIN_VALUE;
int maxHeight = Integer.MIN_VALUE;
for (ViewRootData viewRoot : viewRoots) {
if (viewRoot._winFrame.right > maxWidth) {
maxWidth = viewRoot._winFrame.right;
}
if (viewRoot._winFrame.bottom > maxHeight) {
maxHeight = viewRoot._winFrame.bottom;
}
}
final Bitmap bitmap = Bitmap.createBitmap(maxWidth, maxHeight, Bitmap.Config.ARGB_8888);
// We need to do it in main thread
if (Looper.myLooper() == Looper.getMainLooper()) {
drawRootsToBitmap(viewRoots, bitmap);
} else {
final CountDownLatch latch = new CountDownLatch(1);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
drawRootsToBitmap(viewRoots, bitmap);
} finally {
latch.countDown();
}
}
});
latch.await();
}
return bitmap;
}
private static void drawRootsToBitmap(List<ViewRootData> viewRoots, Bitmap bitmap) {
for (ViewRootData rootData : viewRoots) {
drawRootToBitmap(rootData, bitmap);
}
}
private static void drawRootToBitmap(ViewRootData config, Bitmap bitmap) {
// now only dim supported
if ((config._layoutParams.flags & FLAG_DIM_BEHIND) == FLAG_DIM_BEHIND) {
Canvas dimCanvas = new Canvas(bitmap);
int alpha = (int) (255 * config._layoutParams.dimAmount);
dimCanvas.drawARGB(alpha, 0, 0, 0);
}
Canvas canvas = new Canvas(bitmap);
canvas.translate(config._winFrame.left, config._winFrame.top);
config._view.draw(canvas);
}
private static void writeBitmap(Bitmap bitmap, File toFile) throws IOException {
OutputStream outputStream = null;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(toFile));
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
} finally {
closeQuietly(outputStream);
}
}
private static void closeQuietly(Closeable closable) {
if (closable != null) {
try {
closable.close();
} catch (IOException e) {
// Do nothing
}
}
}
@SuppressWarnings("unchecked") // no way to check
private static List<ViewRootData> getRootViews(Activity activity) {
List<ViewRootData> rootViews = new ArrayList<ViewRootData>();
Object globalWindowManager;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
globalWindowManager = getFieldValue("mWindowManager", activity.getWindowManager());
} else {
globalWindowManager = getFieldValue("mGlobal", activity.getWindowManager());
}
Object rootObjects = getFieldValue("mRoots", globalWindowManager);
Object paramsObject = getFieldValue("mParams", globalWindowManager);
Object[] roots;
LayoutParams[] params;
// There was a change to ArrayList implementation in 4.4
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
roots = ((List) rootObjects).toArray();
List<LayoutParams> paramsList = (List<LayoutParams>) paramsObject;
params = paramsList.toArray(new LayoutParams[paramsList.size()]);
} else {
roots = (Object[]) rootObjects;
params = (LayoutParams[]) paramsObject;
}
for (int i = 0; i < roots.length; i++) {
Object root = roots[i];
View view = (View) getFieldValue("mView", root);
// fixes https://github.com/jraska/Falcon/issues/10
if (view == null) {
Log.e(TAG, "null View stored as root in Global window manager, skipping");
continue;
}
Object attachInfo = getFieldValue("mAttachInfo", root);
int top =(Integer) getFieldValue("mWindowTop", attachInfo);
int left = (Integer) getFieldValue("mWindowLeft", attachInfo);
Rect winFrame = (Rect) getFieldValue("mWinFrame", root);
Rect area = new Rect(left, top, left + winFrame.width(), top + winFrame.height());
rootViews.add(new ViewRootData(view, area, params[i]));
}
if (rootViews.isEmpty()) {
return Collections.emptyList();
}
offsetRootsTopLeft(rootViews);
ensureDialogsAreAfterItsParentActivities(rootViews);
return rootViews;
}
private static void offsetRootsTopLeft(List<ViewRootData> rootViews) {
int minTop = Integer.MAX_VALUE;
int minLeft = Integer.MAX_VALUE;
for (ViewRootData rootView : rootViews) {
if (rootView._winFrame.top < minTop) {
minTop = rootView._winFrame.top;
}
if (rootView._winFrame.left < minLeft) {
minLeft = rootView._winFrame.left;
}
}
for (ViewRootData rootView : rootViews) {
rootView._winFrame.offset(-minLeft, -minTop);
}
}
// This fixes issue #11. It is not perfect solution and maybe there is another case
// of different type of view, but it works for most common case of dialogs.
private static void ensureDialogsAreAfterItsParentActivities(List<ViewRootData> viewRoots) {
if (viewRoots.size() <= 1) {
return;
}
for (int dialogIndex = 0; dialogIndex < viewRoots.size() - 1; dialogIndex++) {
ViewRootData viewRoot = viewRoots.get(dialogIndex);
if (!viewRoot.isDialogType()) {
continue;
}
Activity dialogOwnerActivity = ownerActivity(viewRoot.context());
if (dialogOwnerActivity == null) {
// make sure we will never compare null == null
return;
}
for (int parentIndex = dialogIndex + 1; parentIndex < viewRoots.size(); parentIndex++) {
ViewRootData possibleParent = viewRoots.get(parentIndex);
if (possibleParent.isActivityType()
&& ownerActivity(possibleParent.context()) == dialogOwnerActivity) {
viewRoots.remove(possibleParent);
viewRoots.add(dialogIndex, possibleParent);
break;
}
}
}
}
private static Activity ownerActivity(Context context) {
Context currentContext = context;
while (currentContext != null) {
if (currentContext instanceof Activity) {
return (Activity) currentContext;
}
if (currentContext instanceof ContextWrapper && !(currentContext instanceof Application)) {
currentContext = ((ContextWrapper) currentContext).getBaseContext();
} else {
break;
}
}
return null;
}
private static Object getFieldValue(String fieldName, Object target) {
try {
return getFieldValueUnchecked(fieldName, target);
} catch (Exception e) {
throw new UnableToTakeScreenshotException(e);
}
}
private static Object getFieldValueUnchecked(String fieldName, Object target)
throws NoSuchFieldException, IllegalAccessException {
Field field = findField(fieldName, target.getClass());
field.setAccessible(true);
return field.get(target);
}
private static Field findField(String name, Class clazz) throws NoSuchFieldException {
Class currentClass = clazz;
while (currentClass != Object.class) {
for (Field field : currentClass.getDeclaredFields()) {
if (name.equals(field.getName())) {
return field;
}
}
currentClass = currentClass.getSuperclass();
}
throw new NoSuchFieldException("Field " + name + " not found for class " + clazz);
}
//endregion
//region Constructors
// No instances
private Falcon() {
}
//endregion
//region Nested classes
/**
* Custom exception thrown if there is some exception thrown during
* screenshot capturing to enable better client code exception handling.
*/
public static class UnableToTakeScreenshotException extends RuntimeException {
private UnableToTakeScreenshotException(String detailMessage) {
super(detailMessage);
}
private UnableToTakeScreenshotException(String detailMessage, Exception exception) {
super(detailMessage, extractException(exception));
}
private UnableToTakeScreenshotException(Exception ex) {
super(extractException(ex));
}
/**
* Method to avoid multiple wrapping. If there is already our exception,
* just wrap the cause again
*/
private static Throwable extractException(Exception ex) {
if (ex instanceof UnableToTakeScreenshotException) {
return ex.getCause();
}
return ex;
}
}
private static class ViewRootData {
private final View _view;
private final Rect _winFrame;
private final LayoutParams _layoutParams;
ViewRootData(View view, Rect winFrame, LayoutParams layoutParams) {
_view = view;
_winFrame = winFrame;
_layoutParams = layoutParams;
}
boolean isDialogType() {
return _layoutParams.type == LayoutParams.TYPE_APPLICATION;
}
boolean isActivityType() {
return _layoutParams.type == LayoutParams.TYPE_BASE_APPLICATION;
}
Context context() {
return _view.getContext();
}
}
//endregion
}

View File

@@ -0,0 +1,77 @@
package com.nickming.view;
import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by Administrator on 2017/4/24.
*/
public class ScreenShoddmlib {
//private BufferedImage image = null;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
AndroidDebugBridge.init(false); //
ScreenShoddmlib screenshot = new ScreenShoddmlib();
IDevice device = screenshot.getDevice();
for (int i = 0; i < 10; i++) {
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("MM-dd-HH-mm-ss");
String nowTime = df.format(date);
// screenshot.getScreenShot(device, "Robotium" + nowTime);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* 获取得到device对象
*
* @return
*/
private IDevice getDevice() {
IDevice device;
AndroidDebugBridge bridge = AndroidDebugBridge
.createBridge("adb", true);// 如果代码有问题请查看API修改此处的参数值试一下
waitDevicesList(bridge);
IDevice devices[] = bridge.getDevices();
device = devices[0];
return device;
}
/**
* 等待查找device
*
* @param bridge
*/
private void waitDevicesList(AndroidDebugBridge bridge) {
int count = 0;
while (bridge.hasInitialDeviceList() == false) {
try {
Thread.sleep(500);
count++;
} catch (InterruptedException e) {
}
if (count > 240) {
System.err.print("等待获取设备超时");
break;
}
}
}
}

View File

@@ -0,0 +1,153 @@
package com.nickming.view;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import com.jx.jyhd.simcpux.Util;
/**
* 通过读取文件 /dev/graphics/fb0获取屏幕截图
* 截图获取bitmap只需<E58FAA>?100ms左右
*
* @author gudh
* @data 2014-1-17
*/
public class Screenshot {
final static String FB0FILE1 = "/dev/graphics/fb0";
final static String FB0FILE2 = "/dev/fb0";
static File fbFile;
static FileInputStream graphics = null;
static int screenWidth = 480; // 屏幕宽像素<EFBC8C>?480px<70>?
static int screenHeight = 800; // 屏幕高像素<EFBC8C>?800p<30>?
static byte[] piex;
/**
* 初始化基本信<E69CAC>?
*
* @param context
*/
public static void init(Activity context) {
fbFile = new File(FB0FILE1);
if (!fbFile.exists()) {
File nFile = new File(FB0FILE2);
if (nFile.exists()) {
fbFile = nFile;
}
}
// 初始化事件文件的权限
try {
Process sh = Runtime.getRuntime().exec("su", null, null);
OutputStream os = sh.getOutputStream();
os.write(("chmod 777 " + fbFile.getAbsolutePath()).getBytes());
os.flush();
os.close();
sh.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
DisplayMetrics dm = new DisplayMetrics();
Display display = context.getWindowManager().getDefaultDisplay();
display.getMetrics(dm);
screenWidth = dm.widthPixels; // 屏幕宽像素<EFBC8C>?480px<70>?
screenHeight = dm.heightPixels; // 屏幕高像素<EFBC8C>?800p<30>?
PixelFormat pixelFormat = new PixelFormat();
PixelFormat.getPixelFormatInfo(PixelFormat.RGBA_8888, pixelFormat);
int deepth = pixelFormat.bytesPerPixel; // 位深
piex = new byte[screenHeight * screenWidth * deepth]; // 像素
}
/**
* 测试截图
*/
@SuppressLint("SdCardPath")
public static void testShot() {
long start = System.currentTimeMillis();
try {
Bitmap bm = getScreenBitmap();
File file;
// if (Environment.getExternalStorageState().equals(
// Environment.MEDIA_MOUNTED)) {
// // sd卡存储/mnt/sdcard/cache
// file = Environment.getExternalStorageDirectory();// 获取跟目录
// } else {
// // 没有SD卡缓存到系统存储
// file = Environment.getDataDirectory();
// }
file = Util.GetDirectory();
saveMyBitmap(bm, file.getAbsolutePath() + File.separator + "ws.png");
} catch (IOException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
Log.i("Screenshot", "time cost:" + (end - start));
}
/**
* 保存bitmap到文<E588B0>?
*
* @param bitmap
* @param bitName
* @throws IOException
*/
public static void saveMyBitmap(Bitmap bitmap, String bitName)
throws IOException {
File f = new File(bitName);
f.createNewFile();
FileOutputStream fOut = new FileOutputStream(f);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
}
/**
* 获取当前屏幕截图一定要先init
*
* @return
* @throws IOException
*/
public synchronized static Bitmap getScreenBitmap() throws IOException {
try {
graphics = new FileInputStream(fbFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
DataInputStream dStream = new DataInputStream(graphics);
dStream.readFully(piex);
dStream.close();
int[] colors = new int[screenHeight * screenWidth];
// 将rgb转为色<E4B8BA>??
for (int m = 0; m < colors.length; m++) {
int r = (piex[m * 4] & 0xFF);
int g = (piex[m * 4 + 1] & 0xFF);
int b = (piex[m * 4 + 2] & 0xFF);
int a = (piex[m * 4 + 3] & 0xFF);
colors[m] = (a << 24) + (r << 16) + (g << 8) + b;
}
return Bitmap.createBitmap(colors, screenWidth, screenHeight,
Bitmap.Config.ARGB_8888);
}
}

View File

@@ -0,0 +1,6 @@
package com.nickming.view.listener;
public interface savelistener {
public void save(String bitmappath);
}

View File

@@ -0,0 +1,7 @@
package com.tagmae.jsbridge;
public interface BridgeHandler {
void handler(String data, CallBackFunction function);
}

View File

@@ -0,0 +1,126 @@
package com.tagmae.jsbridge;
import android.content.Context;
import com.tencent.smtt.sdk.WebView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class BridgeUtil {
final static String YY_OVERRIDE_SCHEMA = "yy://";
final static String YY_RETURN_DATA = YY_OVERRIDE_SCHEMA + "return/";//格式为 yy://return/{function}/returncontent
final static String YY_FETCH_QUEUE = YY_RETURN_DATA + "_fetchQueue/";
final static String EMPTY_STR = "";
final static String UNDERLINE_STR = "_";
final static String SPLIT_MARK = "/";
final static String CALLBACK_ID_FORMAT = "JAVA_CB_%s";
final static String JS_HANDLE_MESSAGE_FROM_JAVA = "javascript:WebViewJavascriptBridge._handleMessageFromNative('%s');";
final static String JS_FETCH_QUEUE_FROM_JAVA = "javascript:WebViewJavascriptBridge._fetchQueue();";
public final static String JAVASCRIPT_STR = "javascript:";
// 例子 javascript:WebViewJavascriptBridge._fetchQueue(); --> _fetchQueue
public static String parseFunctionName(String jsUrl){
return jsUrl.replace("javascript:WebViewJavascriptBridge.", "").replaceAll("\\(.*\\);", "");
}
// 获取到传递信息的body值
// url = yy://return/_fetchQueue/[{"responseId":"JAVA_CB_2_3957","responseData":"Javascript Says Right back aka!"}]
public static String getDataFromReturnUrl(String url) {
if(url.startsWith(YY_FETCH_QUEUE)) {
// return = [{"responseId":"JAVA_CB_2_3957","responseData":"Javascript Says Right back aka!"}]
return url.replace(YY_FETCH_QUEUE, EMPTY_STR);
}
// temp = _fetchQueue/[{"responseId":"JAVA_CB_2_3957","responseData":"Javascript Says Right back aka!"}]
String temp = url.replace(YY_RETURN_DATA, EMPTY_STR);
String[] functionAndData = temp.split(SPLIT_MARK);
if(functionAndData.length >= 2) {
StringBuilder sb = new StringBuilder();
for (int i = 1; i < functionAndData.length; i++) {
sb.append(functionAndData[i]);
}
// return = [{"responseId":"JAVA_CB_2_3957","responseData":"Javascript Says Right back aka!"}]
return sb.toString();
}
return null;
}
// 获取到传递信息的方法
// url = yy://return/_fetchQueue/[{"responseId":"JAVA_CB_1_360","responseData":"Javascript Says Right back aka!"}]
public static String getFunctionFromReturnUrl(String url) {
// temp = _fetchQueue/[{"responseId":"JAVA_CB_1_360","responseData":"Javascript Says Right back aka!"}]
String temp = url.replace(YY_RETURN_DATA, EMPTY_STR);
String[] functionAndData = temp.split(SPLIT_MARK);
if(functionAndData.length >= 1){
// functionAndData[0] = _fetchQueue
return functionAndData[0];
}
return null;
}
/**
* js 文件将注入为第一个script引用
* @param view WebView
* @param url url
*/
public static void webViewLoadJs(WebView view, String url){
String js = "var newscript = document.createElement(\"script\");";
js += "newscript.src=\"" + url + "\";";
js += "document.scripts[0].parentNode.insertBefore(newscript,document.scripts[0]);";
view.loadUrl("javascript:" + js);
}
/**
* 这里只是加载lib包中assets中的 WebViewJavascriptBridge.js
* @param view webview
* @param path 路径
*/
public static void webViewLoadLocalJs(WebView view, String path){
String jsContent = assetFile2Str(view.getContext(), path);
view.loadUrl("javascript:" + jsContent);
}
/**
* 解析assets文件夹里面的代码,去除注释,取可执行的代码
* @param c context
* @param urlStr 路径
* @return 可执行代码
*/
public static String assetFile2Str(Context c, String urlStr){
InputStream in = null;
try{
in = c.getAssets().open(urlStr);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
String line = null;
StringBuilder sb = new StringBuilder();
do {
line = bufferedReader.readLine();
if (line != null && !line.matches("^\\s*\\/\\/.*")) { // 去除注释
sb.append(line);
}
} while (line != null);
bufferedReader.close();
in.close();
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
} finally {
if(in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
return null;
}
}

View File

@@ -0,0 +1,267 @@
package com.tagmae.jsbridge;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.Looper;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.AttributeSet;
import com.tencent.smtt.sdk.WebView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@SuppressLint("SetJavaScriptEnabled")
public class BridgeWebView extends WebView implements WebViewJavascriptBridge {
private final String TAG = "BridgeWebView";
public static final String toLoadJs = "WebViewJavascriptBridge.js";
Map<String, CallBackFunction> responseCallbacks = new HashMap<String, CallBackFunction>();
Map<String, BridgeHandler> messageHandlers = new HashMap<String, BridgeHandler>();
BridgeHandler defaultHandler = new DefaultHandler();
private List<Message> startupMessage = new ArrayList<Message>();
public List<Message> getStartupMessage() {
return startupMessage;
}
public void setStartupMessage(List<Message> startupMessage) {
this.startupMessage = startupMessage;
}
private long uniqueId = 0;
public BridgeWebView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public BridgeWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public BridgeWebView(Context context) {
super(context);
init();
}
/**
*
* @param handler
* default handler,handle messages send by js without assigned handler name,
* if js message has handler name, it will be handled by named handlers registered by native
*/
public void setDefaultHandler(BridgeHandler handler) {
this.defaultHandler = handler;
}
private void init() {
this.setVerticalScrollBarEnabled(false);
this.setHorizontalScrollBarEnabled(false);
this.getSettings().setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
this.setWebViewClient(generateBridgeWebViewClient());
}
protected BridgeWebViewClient generateBridgeWebViewClient() {
return new BridgeWebViewClient(this);
}
/**
* 获取到CallBackFunction data执行调用并且从数据集移除
* @param url
*/
void handlerReturnData(String url) {
String functionName = BridgeUtil.getFunctionFromReturnUrl(url);
CallBackFunction f = responseCallbacks.get(functionName);
String data = BridgeUtil.getDataFromReturnUrl(url);
if (f != null) {
f.onCallBack(data);
responseCallbacks.remove(functionName);
return;
}
}
@Override
public void send(String data) {
send(data, null);
}
@Override
public void send(String data, CallBackFunction responseCallback) {
doSend(null, data, responseCallback);
}
/**
* 保存message到消息队列
* @param handlerName handlerName
* @param data data
* @param responseCallback CallBackFunction
*/
private void doSend(String handlerName, String data, CallBackFunction responseCallback) {
Message m = new Message();
if (!TextUtils.isEmpty(data)) {
m.setData(data);
}
if (responseCallback != null) {
String callbackStr = String.format(BridgeUtil.CALLBACK_ID_FORMAT, ++uniqueId + (BridgeUtil.UNDERLINE_STR + SystemClock.currentThreadTimeMillis()));
responseCallbacks.put(callbackStr, responseCallback);
m.setCallbackId(callbackStr);
}
if (!TextUtils.isEmpty(handlerName)) {
m.setHandlerName(handlerName);
}
queueMessage(m);
}
/**
* list<message> != null 添加到消息集合否则分发消息
* @param m Message
*/
private void queueMessage(Message m) {
if (startupMessage != null) {
startupMessage.add(m);
} else {
dispatchMessage(m);
}
}
/**
* 分发message 必须在主线程才分发成功
* @param m Message
*/
void dispatchMessage(Message m) {
String messageJson = m.toJson();
if(messageJson!=null){
//escape special characters for json string 为json字符串转义特殊字符
messageJson = messageJson.replaceAll("(\\\\)([^utrn])", "\\\\\\\\$1$2");
messageJson = messageJson.replaceAll("(?<=[^\\\\])(\")", "\\\\\"");
String javascriptCommand = String.format(BridgeUtil.JS_HANDLE_MESSAGE_FROM_JAVA, messageJson);
// 必须要找主线程才会将数据传递出去 --- 划重点
if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
this.loadUrl(javascriptCommand);
}
}
}
/**
* 刷新消息队列
*/
void flushMessageQueue() {
if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
loadUrl(BridgeUtil.JS_FETCH_QUEUE_FROM_JAVA, new CallBackFunction() {
@Override
public void onCallBack(String data) {
// deserializeMessage 反序列化消息
List<Message> list = null;
try {
list = Message.toArrayList(data);
} catch (Exception e) {
e.printStackTrace();
return;
}
if (list == null || list.size() == 0) {
return;
}
for (int i = 0; i < list.size(); i++) {
Message m = list.get(i);
String responseId = m.getResponseId();
// 是否是response CallBackFunction
if (!TextUtils.isEmpty(responseId)) {
CallBackFunction function = responseCallbacks.get(responseId);
String responseData = m.getResponseData();
Objects.requireNonNull(function).onCallBack(responseData);
responseCallbacks.remove(responseId);
} else {
CallBackFunction responseFunction = null;
// if had callbackId 如果有回调Id
final String callbackId = m.getCallbackId();
if (!TextUtils.isEmpty(callbackId)) {
responseFunction = new CallBackFunction() {
@Override
public void onCallBack(String data) {
Message responseMsg = new Message();
responseMsg.setResponseId(callbackId);
responseMsg.setResponseData(data);
queueMessage(responseMsg);
}
};
} else {
responseFunction = new CallBackFunction() {
@Override
public void onCallBack(String data) {
// do nothing
}
};
}
// BridgeHandler执行
BridgeHandler handler;
if (!TextUtils.isEmpty(m.getHandlerName())) {
handler = messageHandlers.get(m.getHandlerName());
} else {
handler = defaultHandler;
}
if (handler != null){
handler.handler(m.getData(), responseFunction);
}
}
}
}
});
}
}
public void loadUrl(String jsUrl, CallBackFunction returnCallback) {
this.loadUrl(jsUrl);
// 添加至 Map<String, CallBackFunction>
responseCallbacks.put(BridgeUtil.parseFunctionName(jsUrl), returnCallback);
}
/**
* register handler,so that javascript can call it
* 注册处理程序,以便javascript调用它
* @param handlerName handlerName
* @param handler BridgeHandler
*/
public void registerHandler(String handlerName, BridgeHandler handler) {
if (handler != null) {
// 添加至 Map<String, BridgeHandler>
messageHandlers.put(handlerName, handler);
}
}
/**
* unregister handler
*
* @param handlerName
*/
public void unregisterHandler(String handlerName) {
if (handlerName != null) {
messageHandlers.remove(handlerName);
}
}
/**
* call javascript registered handler
* 调用javascript处理程序注册
* @param handlerName handlerName
* @param data data
* @param callBack CallBackFunction
*/
public void callHandler(String handlerName, String data, CallBackFunction callBack) {
doSend(handlerName, data, callBack);
}
}

View File

@@ -0,0 +1,87 @@
package com.tagmae.jsbridge;
import android.graphics.Bitmap;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
/**
* 如果要自定义WebViewClient必须要集成此类
* Created by bruce on 10/28/15.
*/
public class BridgeWebViewClient extends WebViewClient {
private BridgeWebView webView;
public BridgeWebViewClient(BridgeWebView webView) {
this.webView = webView;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
url = URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (url.startsWith(BridgeUtil.YY_RETURN_DATA)) { // 如果是返回数据
webView.handlerReturnData(url);
return true;
} else if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) { //
webView.flushMessageQueue();
return true;
} else {
return super.shouldOverrideUrlLoading(view, url);
}
}
// // 增加shouldOverrideUrlLoading在api》=24时
// @Override
// public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
//
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// String url = request.getUrl().toString();
// try {
// url = URLDecoder.decode(url, "UTF-8");
// } catch (UnsupportedEncodingException ex) {
// ex.printStackTrace();
// }
// if (url.startsWith(BridgeUtil.YY_RETURN_DATA)) { // 如果是返回数据
// webView.handlerReturnData(url);
// return true;
// } else if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) { //
// webView.flushMessageQueue();
// return true;
// } else {
// return super.shouldOverrideUrlLoading(view, request);
// }
// }else {
// return super.shouldOverrideUrlLoading(view, request);
// }
// }
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (BridgeWebView.toLoadJs != null) {
BridgeUtil.webViewLoadLocalJs(view, BridgeWebView.toLoadJs);
}
//
if (webView.getStartupMessage() != null) {
for (Message m : webView.getStartupMessage()) {
webView.dispatchMessage(m);
}
webView.setStartupMessage(null);
}
}
}

View File

@@ -0,0 +1,7 @@
package com.tagmae.jsbridge;
public interface CallBackFunction {
public void onCallBack(String data);
}

View File

@@ -0,0 +1,14 @@
package com.tagmae.jsbridge;
public class DefaultHandler implements BridgeHandler{
String TAG = "DefaultHandler";
@Override
public void handler(String data, CallBackFunction function) {
if(function != null){
function.onCallBack("DefaultHandler response data");
}
}
}

View File

@@ -0,0 +1,119 @@
package com.tagmae.jsbridge;
import android.text.TextUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.util.ArrayList;
import java.util.List;
/**
* data of bridge
* @author haoqing
*
*/
public class Message {
private String callbackId; //callbackId
private String responseId; //responseId
private String responseData; //responseData
private String data; //data of message
private String handlerName; //name of handler
private final static String CALLBACK_ID_STR = "callbackId";
private final static String RESPONSE_ID_STR = "responseId";
private final static String RESPONSE_DATA_STR = "responseData";
private final static String DATA_STR = "data";
private final static String HANDLER_NAME_STR = "handlerName";
public String getResponseId() {
return responseId;
}
public void setResponseId(String responseId) {
this.responseId = responseId;
}
public String getResponseData() {
return responseData;
}
public void setResponseData(String responseData) {
this.responseData = responseData;
}
public String getCallbackId() {
return callbackId;
}
public void setCallbackId(String callbackId) {
this.callbackId = callbackId;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getHandlerName() {
return handlerName;
}
public void setHandlerName(String handlerName) {
this.handlerName = handlerName;
}
public String toJson() {
JSONObject jsonObject= new JSONObject();
try {
jsonObject.put(CALLBACK_ID_STR, getCallbackId());
jsonObject.put(DATA_STR, getData());
jsonObject.put(HANDLER_NAME_STR, getHandlerName());
String data = getResponseData();
if (TextUtils.isEmpty(data)) {
jsonObject.put(RESPONSE_DATA_STR, data);
} else {
jsonObject.put(RESPONSE_DATA_STR, new JSONTokener(data).nextValue());
}
jsonObject.put(RESPONSE_DATA_STR, getResponseData());
jsonObject.put(RESPONSE_ID_STR, getResponseId());
return jsonObject.toString();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
public static Message toObject(String jsonStr) {
Message m = new Message();
try {
JSONObject jsonObject = new JSONObject(jsonStr);
m.setHandlerName(jsonObject.has(HANDLER_NAME_STR) ? jsonObject.getString(HANDLER_NAME_STR):null);
m.setCallbackId(jsonObject.has(CALLBACK_ID_STR) ? jsonObject.getString(CALLBACK_ID_STR):null);
m.setResponseData(jsonObject.has(RESPONSE_DATA_STR) ? jsonObject.getString(RESPONSE_DATA_STR):null);
m.setResponseId(jsonObject.has(RESPONSE_ID_STR) ? jsonObject.getString(RESPONSE_ID_STR):null);
m.setData(jsonObject.has(DATA_STR) ? jsonObject.getString(DATA_STR):null);
return m;
} catch (JSONException e) {
e.printStackTrace();
}
return m;
}
public static List<Message> toArrayList(String jsonStr){
List<Message> list = new ArrayList<Message>();
try {
JSONArray jsonArray = new JSONArray(jsonStr);
for(int i = 0; i < jsonArray.length(); i++){
Message m = new Message();
JSONObject jsonObject = jsonArray.getJSONObject(i);
m.setHandlerName(jsonObject.has(HANDLER_NAME_STR) ? jsonObject.getString(HANDLER_NAME_STR):null);
m.setCallbackId(jsonObject.has(CALLBACK_ID_STR) ? jsonObject.getString(CALLBACK_ID_STR):null);
m.setResponseData(jsonObject.has(RESPONSE_DATA_STR) ? jsonObject.getString(RESPONSE_DATA_STR):null);
m.setResponseId(jsonObject.has(RESPONSE_ID_STR) ? jsonObject.getString(RESPONSE_ID_STR):null);
m.setData(jsonObject.has(DATA_STR) ? jsonObject.getString(DATA_STR):null);
list.add(m);
}
} catch (JSONException e) {
e.printStackTrace();
}
return list;
}
}

View File

@@ -0,0 +1,11 @@
package com.tagmae.jsbridge;
public interface WebViewJavascriptBridge {
public void send(String data);
public void send(String data, CallBackFunction responseCallback);
}

View File

@@ -0,0 +1,216 @@
package com.tagmae.tsgame_erwang;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Base64;
import com.nickming.view.listener.savelistener;
import com.jx.jyhd.simcpux.Util;
import com.jx.jyhd.simcpux.Wxistrue;
import com.yanzhenjie.andserver.AndServerRequestHandler;
import com.yanzhenjie.andserver.util.HttpRequestParser;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.entity.StringEntity;
import org.apache.http.protocol.HttpContext;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.InvalidParameterException;
import java.util.Map;
public class AndServerTestHandle implements AndServerRequestHandler {
private static savelistener listener1;
public static Handler hanler;
private static String bitmappath;
public static void setPhotoListerer(savelistener listener){
listener1=listener;
}
public static void setPhotohandler(Handler hanler1){
hanler=hanler1;
}
@SuppressWarnings("deprecation")
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext arg2)
throws HttpException, IOException {
if(Wxistrue.isphotoshare){//避免重复点击
System.out.println("8888888888");
if(HttpRequestParser.isPosterMethod(request)){
if(hanler!=null){
hanler.postDelayed(new Runnable() {
@Override
public void run() {
Wxistrue.isphotoshare=true;
Wxistrue.isphotoshare=true;
}
},3000);
}
Wxistrue.isphotoshare=false;
String name=HttpRequestParser.getContentForPost(request);
System.out.println(name);
String photo="";
String type=name.substring(name.indexOf("data")-1, name.indexOf("data"));
//type="3";
System.out.println(type);
try {
JSONObject object=new JSONObject(name);
photo=object.optString("name");
photo=deleteheard(photo);
System.out.println("json格式");
} catch (JSONException e) {
photo=deleteheard(name);
System.out.println("不是json格式");
e.printStackTrace();
}
saveBase64(photo);
Message msg=new Message();
//listener1.save(bitmappath);
Bundle data=new Bundle();
data.putString("bitpath", bitmappath);
data.putString("type", type);
System.out.println(type);
msg.setData(data);
hanler.sendMessage(msg);
}else{
// 拿到客户端参数key-value。
Map<String, String> params = HttpRequestParser.parse(request);
StringBuilder stringBuilder = new StringBuilder();
for (Map.Entry<String, String> entry : params.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
stringBuilder.append(entry.getKey() + ": " + entry.getValue() + "\r\n");
}
System.out.println("客户端提交的参数:" + stringBuilder.toString());
}
response.setEntity(new StringEntity("请求成功。", "utf-8"));
}
}
private String deleteheard(String photo) {
int start=photo.indexOf(",");
photo=photo.substring(start+1, photo.length());
System.out.println(photo);
return photo;
}
public void saveBase64(String iconBase64){
File file;
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
// sd卡存储/mnt/sdcard/cache
file = Environment.getExternalStorageDirectory();// 获取跟目录
} else {
// 没有SD卡缓存到系统存储
file = Environment.getDataDirectory();
}
file = Util.GetDirectory();
bitmappath = file.getAbsolutePath() + File.separator + "photo.png";
Bitmap bit1=stringtoBitmap(iconBase64);
if(bit1==null){
System.out.println("图片为空");
}
getScreenHot(bit1,bitmappath);
}
private void getScreenHot(Bitmap b1,String filePath) {
System.out.println(filePath);
if(b1==null){
System.out.println("-----");
}
File file1 = new File(filePath);
try {
file1.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
try {
try {
FileOutputStream fos = new FileOutputStream(file1);
b1.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
throw new InvalidParameterException();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public Bitmap stringtoBitmap(String string) {
// 将字符串转换成Bitmap类型
Bitmap bitmap = null;
try {
byte[] bitmapArray;
System.out.println(string);
bitmapArray = Base64.decode(string, Base64.DEFAULT);
bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0,
bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
public String bitmaptoString(Bitmap bitmap) {
// 将Bitmap转换成字符串
String string = null;
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 100, bStream);
byte[] bytes = bStream.toByteArray();
string = Base64.encodeToString(bytes, Base64.DEFAULT);
return string;
}
interface savePhotoListener{
void success();
}
}

View File

@@ -0,0 +1,56 @@
package com.tagmae.tsgame_erwang;
import android.app.Activity;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
/**
* 作者YMI on 2017/12/4 10:18
* 邮箱18702631465@163.com
* QQ:1078561230
*/
public class AndroidBug5497Workaround {
// For more information, see https://code.google.com/p/android/issues/detail?id=5497
// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.
public static void assistActivity (Activity activity) {
new AndroidBug5497Workaround(activity);
}
private View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;
private AndroidBug5497Workaround(Activity activity) {
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
possiblyResizeChildOfContent();
}
});
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != usableHeightPrevious) {
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
if (heightDifference > (usableHeightSansKeyboard/4)) {
// keyboard probably just became visible
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
} else {
// keyboard probably just became hidden
frameLayoutParams.height = usableHeightSansKeyboard;
}
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);// 全屏模式下: return r.bottom
}
}

View File

@@ -0,0 +1,26 @@
package com.tagmae.tsgame_erwang;
import java.io.File;
/**
* 作者YMI on 2018/4/16 12:31
* 邮箱18702631465@163.com
* QQ:1078561230
*/
public class BrowserUtil {
/**
* 浏览器应用是否安装
* @return
*/
public static boolean isQQBrowserInstalled(){
return isInstallPackage("com.tencent.mtt");
}
public static boolean isUCBrowserInstalled(){
return isInstallPackage("com.UCMobile");
}
private static boolean isInstallPackage(String packageName) {
return new File("/data/data/" + packageName).exists();
}
}

View File

@@ -0,0 +1,190 @@
package com.tagmae.tsgame_erwang;
import android.util.Log;
import com.tagmae.jsbridge.BridgeWebView;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
/**
* Canvas转Base64使用示例
* 展示如何使用WebViewScreenshotUtil中的Canvas相关功能
*/
public class CanvasBase64Example {
private static final String TAG = "CanvasBase64Example";
/**
* 示例1获取指定ID的Canvas内容
*/
public static void captureCanvasById(BridgeWebView webView, String canvasId) {
WebViewScreenshotUtil.getCanvasBase64FromWebView(webView, canvasId,
new WebViewScreenshotUtil.CanvasToBase64Callback() {
@Override
public void onSuccess(String base64Data) {
Log.d(TAG, "Canvas captured successfully! Base64 length: " + base64Data.length());
// 在这里处理获取到的base64数据
// 例如保存到文件、上传到服务器、显示在ImageView中等
handleBase64Data(base64Data);
}
@Override
public void onError(String error) {
Log.e(TAG, "Failed to capture canvas: " + error);
}
});
}
/**
* 示例2获取页面中第一个Canvas内容
*/
public static void captureFirstCanvas(BridgeWebView webView) {
WebViewScreenshotUtil.getCanvasBase64FromWebView(webView, null,
new WebViewScreenshotUtil.CanvasToBase64Callback() {
@Override
public void onSuccess(String base64Data) {
Log.d(TAG, "First canvas captured! Base64 length: " + base64Data.length());
handleBase64Data(base64Data);
}
@Override
public void onError(String error) {
Log.e(TAG, "Failed to capture first canvas: " + error);
}
});
}
/**
* 示例3获取页面中所有Canvas内容
*/
public static void captureAllCanvas(BridgeWebView webView) {
WebViewScreenshotUtil.getAllCanvasBase64FromWebView(webView,
new WebViewScreenshotUtil.CanvasToBase64Callback() {
@Override
public void onSuccess(String jsonResult) {
Log.d(TAG, "All canvas captured! JSON result: " + jsonResult);
// jsonResult是一个JSON字符串包含所有Canvas的信息
handleAllCanvasData(jsonResult);
}
@Override
public void onError(String error) {
Log.e(TAG, "Failed to capture all canvas: " + error);
}
});
}
/**
* 示例4高级Canvas截图 - 自动回退机制
*/
public static void captureCanvasAdvanced(BridgeWebView webView, String canvasId) {
WebViewScreenshotUtil.captureCanvasAdvanced(webView, canvasId,
new WebViewScreenshotUtil.CanvasToBase64Callback() {
@Override
public void onSuccess(String base64Data) {
Log.d(TAG, "Advanced canvas capture succeeded! Base64 length: " + base64Data.length());
handleBase64Data(base64Data);
}
@Override
public void onError(String error) {
Log.e(TAG, "Advanced canvas capture failed: " + error);
}
});
}
/**
* 示例5传统WebView截图转base64
*/
public static void captureWebViewToBase64(BridgeWebView webView) {
// 同步方法直接返回base64字符串
String base64 = WebViewScreenshotUtil.captureWebViewToBase64(webView);
if (base64 != null) {
Log.d(TAG, "WebView captured to base64! Length: " + base64.length());
handleBase64Data(base64);
} else {
Log.e(TAG, "Failed to capture WebView to base64");
}
}
/**
* 示例6自定义质量的WebView截图转base64
*/
public static void captureWebViewToBase64WithQuality(BridgeWebView webView, int quality) {
String base64 = WebViewScreenshotUtil.captureWebViewToBase64(webView, quality);
if (base64 != null) {
Log.d(TAG, "WebView captured with quality " + quality + "! Base64 length: " + base64.length());
handleBase64Data(base64);
} else {
Log.e(TAG, "Failed to capture WebView with quality " + quality);
}
}
/**
* 处理单个Canvas的base64数据
*/
private static void handleBase64Data(String base64Data) {
// 在这里实现你的业务逻辑
// 例如:
// 1. 保存到本地文件
// 2. 上传到服务器
// 3. 转换为Bitmap显示
// 4. 分享给其他应用等
Log.d(TAG, "Processing base64 data of length: " + base64Data.length());
// 示例如果需要转换回Bitmap
// Bitmap bitmap = base64ToBitmap(base64Data);
}
/**
* 处理所有Canvas的JSON数据
*/
private static void handleAllCanvasData(String jsonResult) {
// jsonResult格式示例
// [{"index":0,"id":"gameCanvas","width":800,"height":600,"dataUrl":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."}]
Log.d(TAG, "Processing all canvas data: " + jsonResult);
// 可以使用JSON解析库如Gson来解析结果
// 然后分别处理每个Canvas的数据
}
/**
* 工具方法将base64转换回Bitmap如果需要的话
*/
public static android.graphics.Bitmap base64ToBitmap(String base64) {
try {
byte[] decodedBytes = android.util.Base64.decode(base64, android.util.Base64.DEFAULT);
return android.graphics.BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
} catch (Exception e) {
Log.e(TAG, "Error converting base64 to bitmap: " + e.getMessage());
return null;
}
}
/**
* 在Activity中的完整使用示例
*/
public static class ActivityExample {
public void onWebViewReady(BridgeWebView webView) {
// 等待WebView加载完成后再进行截图
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// 页面加载完成后稍微延迟一下确保Canvas渲染完成
view.postDelayed(new Runnable() {
@Override
public void run() {
// 尝试获取特定Canvas
captureCanvasById(webView, "gameCanvas");
// 或者使用高级方法(推荐)
captureCanvasAdvanced(webView, "gameCanvas");
}
}, 1000); // 延迟1秒
}
});
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
package com.tagmae.tsgame_erwang;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
public class Fileutils {
public static void deleteDir(final String pPath) {
File dir = new File(pPath);
deleteDirWihtFile(dir);
}
public static void deleteDirWihtFile(File dir) {
if (dir == null || !dir.exists() || !dir.isDirectory())
return;
for (File file : dir.listFiles()) {
if (file.isFile())
file.delete(); // 删除所有文件
else if (file.isDirectory())
deleteDirWihtFile(file); // 递规的方式删除文件夹
}
dir.delete();// 删除目录本身
}
/** *向文件中添加内容 *
* * @param strcontent 内容
* * @param filePath 地址
* * @param fileName 文件名 */
public static void writeToFile(String strcontent, String filePath) {
//生成文件夹之后,再生成文件,不然会出错
String strFilePath = filePath;
// 每次写入时,都换行写
String strContent = strcontent + "\t\n";
File subfile = new File(strFilePath);
RandomAccessFile raf = null;
try {
/** 构造函数 第二个是读写方式 */
raf = new RandomAccessFile(subfile, "rw");
/** 将记录指针移动到该文件的最后 */
raf.seek(subfile.length());
/** 向文件末尾追加内容 */
raf.write(strContent.getBytes());
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/** * 修改文件内容(覆盖或者添加) *
* * @param path 文件地址
* * @param content 覆盖内容
* * @param append 指定了写入的方式,是覆盖写还是追加写(true=追加)(false=覆盖) */
public static void modifyFile(String path, String content, boolean append) {
try {
FileWriter fileWriter = new FileWriter(path, append);
BufferedWriter writer = new BufferedWriter(fileWriter);
writer.append(content);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 读文件
* @param fileName
* @return
*/
public static String readFile(String fileName){
StringBuffer sb = new StringBuffer("");
FileReader input = null;
BufferedReader reader = null;
try{
input = new FileReader(fileName);
reader = new BufferedReader(input);
String line = null;
while((line = reader.readLine()) != null){
sb.append(line);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(null != reader){
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(null != input){
try {
input.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return sb.toString();
}
}

View File

@@ -0,0 +1,218 @@
package com.tagmae.tsgame_erwang;
import com.game.webgame.view.pmutil;
import com.orhanobut.logger.Logger;
import com.tsgame.tsgame_niuniu.Bean1.Agentlist;
import com.tsgame.tsgame_niuniu.Bean1.Channellist;
import com.tsgame.tsgame_niuniu.Bean1.ConfigData;
import com.tsgame.tsgame_niuniu.Bean1.Gamelist;
import com.tsgame.tsgame_niuniu.Bean1.Marketlist;
import com.tsgame.tsgame_niuniu.Bean1.gameversionUtil;
import com.tsgame.tsgame_niuniu.util.apputil;
public class GameupdateUtil {
public gameversionUtil agentUtil(ConfigData mconfigData, Agentlist magentlist, Gamelist Ygamelist){
gameversionUtil mgameversionutil=new gameversionUtil();
if(magentlist!=null){
if(!pmutil.isnullorEmpty(magentlist.getAgentid())){
if(magentlist.getAgentid().equals(mconfigData.getAgentid())){
setshowmessage(magentlist.getShowmessage());
if(magentlist.getChannellist()!=null){
for(int i=0;i<magentlist.getChannellist().size();i++){
Channellist mChannellist=magentlist.getChannellist().get(i);
if(!pmutil.isnullorEmpty(mChannellist.getChannelid())){
if(mChannellist.getChannelid().equals(mconfigData.getChannelid())){
setshowmessage(mChannellist.getShowmessage());
if(mChannellist.getMarketlist()!=null){
for(int j=0;j<mChannellist.getMarketlist().size();j++){
Marketlist marketlist=mChannellist.getMarketlist().get(j);
if(!pmutil.isnullorEmpty(marketlist.getMarketid())){
if(marketlist.getMarketid().equals(mconfigData.getMarketid())){
setshowmessage(marketlist.getShowmessage());
if(!pmutil.isnullorEmpty(marketlist.getApp_download())&&!pmutil.isnullorEmpty(marketlist.getApp_version())){
Logger.v("代理市场层配置app升级");
mgameversionutil.setApp_download(marketlist.getApp_download());
mgameversionutil.setApp_version(marketlist.getApp_version());
}
if(marketlist.getGamelist()!=null){
for(int k=0;k<marketlist.getGamelist().size();k++){
Gamelist mgamelist=marketlist.getGamelist().get(k);
if(!pmutil.isnullorEmpty(mgamelist.getGameid())){
if(mgamelist.getGameid().equals(mconfigData.getGameid())){
setshowmessage(mgamelist.getShowmessage());
if(!pmutil.isnullorEmpty(mgamelist.getApp_download())&&!pmutil.isnullorEmpty(mgamelist.getApp_version())){
mgameversionutil.setApp_download(mgamelist.getApp_download());
mgameversionutil.setApp_version(mgamelist.getApp_version());
Logger.v("代理游戏层配置app升级");
}
if(!pmutil.isnullorEmpty(mgamelist.getGame_download())&&!pmutil.isnullorEmpty(mgamelist.getGame_version())){
Logger.v("代理游戏层配置游戏升级");
mgameversionutil.setGame_download(mgamelist.getGame_download());
mgameversionutil.setGame_version(mgamelist.getGame_version());
}
}
}
}
}
}
}
}
}
break;
}
}
}
}
Logger.v("代理配置文件完成");
}else{
Logger.v("代理配置文件不匹配");
}
}else{
Logger.v("没有配置代理ID");
}
}
if(Ygamelist!=null){
if(!pmutil.isnullorEmpty(Ygamelist.getGameid())){
if(Ygamelist.getGameid().equals(mconfigData.getGameid())){
mgameversionutil=new gameversionUtil();
setshowmessage(Ygamelist.getShowmessage());
if(!pmutil.isnullorEmpty(Ygamelist.getGame_download())&&!pmutil.isnullorEmpty(Ygamelist.getGame_version())){
Logger.t("chulipeizhiGame").v("游戏层配置游戏升级");
mgameversionutil.setGame_download(Ygamelist.getGame_download());
mgameversionutil.setGame_version(Ygamelist.getGame_version());
}
if(Ygamelist.getAgentlist()!=null){
for(int i=0;i<Ygamelist.getAgentlist().size();i++){
Agentlist mAgentlist=Ygamelist.getAgentlist().get(i);
if(!pmutil.isnullorEmpty(mAgentlist.getAgentid())){
if(mAgentlist.getAgentid().equals(mconfigData.getAgentid())){
setshowmessage(mAgentlist.getShowmessage());
if(!pmutil.isnullorEmpty(mAgentlist.getGame_download())&&!pmutil.isnullorEmpty(mAgentlist.getGame_version())){
Logger.t("chulipeizhiGame").v("游戏代理层配置游戏升级");
mgameversionutil.setGame_download(mAgentlist.getGame_download());
mgameversionutil.setGame_version(mAgentlist.getGame_version());
}
if(mAgentlist.getChannellist()!=null){
for(int j=0;j<mAgentlist.getChannellist().size();j++){
Channellist mChannellist=mAgentlist.getChannellist().get(j);
if(!pmutil.isnullorEmpty(mChannellist.getChannelid())){
if(mChannellist.getChannelid().equals(mconfigData.getChannelid())){
setshowmessage(mChannellist.getShowmessage());
if(!pmutil.isnullorEmpty(mChannellist.getGame_download())&&!pmutil.isnullorEmpty(mChannellist.getGame_version())){
Logger.t("chulipeizhiGame").v("游戏渠道层配置游戏升级");
mgameversionutil.setGame_download(mChannellist.getGame_download());
mgameversionutil.setGame_version(mChannellist.getGame_version());
}
if(mChannellist.getMarketlist()!=null){
for(int k=0;k<mChannellist.getMarketlist().size();k++){
Marketlist mMarketlist=mChannellist.getMarketlist().get(k);
if(!pmutil.isnullorEmpty(mMarketlist.getMarketid())){
if(mMarketlist.getMarketid().equals(mconfigData.getMarketid())){
setshowmessage(mMarketlist.getShowmessage());
if(!pmutil.isnullorEmpty(mMarketlist.getGame_download())&&!pmutil.isnullorEmpty(mMarketlist.getGame_version())){
Logger.t("chulipeizhiGame").v("游戏市场层配置游戏升级");
mgameversionutil.setGame_download(mMarketlist.getGame_download());
mgameversionutil.setGame_version(mMarketlist.getGame_version());
}
if(!pmutil.isnullorEmpty(mMarketlist.getApp_download())&&!pmutil.isnullorEmpty(mMarketlist.getApp_version())){
Logger.t("chulipeizhiGame").v("游戏市场层配置app升级");
mgameversionutil.setApp_download(mMarketlist.getApp_download());
mgameversionutil.setApp_version(mMarketlist.getApp_version());
}
}
}
}
}
}
}
}
}
break;
}
}
}
}
Logger.t("chulipeizhiGame").v("游戏配置文件完成");
}else{
Logger.t("chulipeizhiGame").v("游戏配置文件不匹配");
}
}
}
return mgameversionutil;
}
public void setshowmessage(String Showmessage) {
System.out.println("----" + Showmessage);
if (!pmutil.isnullorEmpty(Showmessage)) {
apputil.Showmessage = Showmessage;
}
}
}

View File

@@ -0,0 +1,84 @@
package com.tagmae.tsgame_erwang;
import android.util.Log;
import com.tagmae.jsbridge.BridgeWebView;
/**
* 全局WebView辅助类
* 提供访问和操作全局WebView的便捷方法
*/
public class GlobalWebViewHelper {
private static final String TAG = "GlobalWebViewHelper";
/**
* 获取全局WebView实例
* @return WebView实例如果未初始化则返回null
*/
public static BridgeWebView getWebView() {
return NewwebviewActivity.getWebView();
}
/**
* 检查全局WebView是否可用
* @return true如果WebView可用false否则
*/
public static boolean isWebViewAvailable() {
return NewwebviewActivity.x5webview != null;
}
/**
* 在WebView中执行JavaScript代码
* @param script 要执行的JavaScript代码
*/
public static void executeJavaScript(String script) {
BridgeWebView webView = getWebView();
if (webView != null) {
webView.loadUrl("javascript:" + script);
Log.d(TAG, "Executed JavaScript: " + script);
} else {
Log.w(TAG, "Cannot execute JavaScript: WebView is not available");
}
}
/**
* 获取WebView当前URL
* @return 当前URL如果WebView不可用则返回null
*/
public static String getCurrentUrl() {
BridgeWebView webView = getWebView();
if (webView != null) {
return webView.getUrl();
}
return null;
}
/**
* 重新加载WebView
*/
public static void reload() {
BridgeWebView webView = getWebView();
if (webView != null) {
webView.reload();
Log.d(TAG, "WebView reloaded");
} else {
Log.w(TAG, "Cannot reload: WebView is not available");
}
}
/**
* 获取Canvas的base64数据便捷方法
* @param canvasId Canvas元素IDnull表示获取第一个Canvas
* @param callback 回调接口
*/
public static void getCanvasBase64(String canvasId, WebViewScreenshotUtil.CanvasToBase64Callback callback) {
WebViewScreenshotUtil.getCanvasBase64FromGlobalWebView(canvasId, callback);
}
/**
* 获取第一个Canvas的base64数据便捷方法
* @param callback 回调接口
*/
public static void getCanvasBase64(WebViewScreenshotUtil.CanvasToBase64Callback callback) {
getCanvasBase64(null, callback);
}
}

View File

@@ -0,0 +1,244 @@
package com.tagmae.tsgame_erwang;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import kr.co.namee.permissiongen.PermissionGen;
import kr.co.namee.permissiongen.PermissionSuccess;
import com.jx.jyhd.R;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
/**
* 调用手机拍照将拍照的图片放在指定文件夹中注意AndroidManifest.xml中添加权限
*/
public class Main extends Activity {
// 界面控件
private Button btn;
private ImageView img;
// 对象
Uri originalUri;// 获取用户选择图片的Uri
Bitmap bm = null;
Handler h = new Handler();
// 变量
/* 用来标识请求照相功能的activity */
private static final int CAMERA_WITH_DATA = 3023;
/* 用来标识请求gallery的activity */
private static final int PHOTO_PICKED_WITH_DATA = 3021;
/* 拍照的照片存储位置 */
private static final File PHOTO_DIR = new File(
Environment.getExternalStorageDirectory() + "/TestPhotoPic");
private String picName = "";// 用户拍照后保存的图片名称
String imgName = "";// 图片名称类似于20121212.jpg
private String userSelectPath = "";
@SuppressLint("InlinedApi") public String[] carpermission = new String[] {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
btn.setOnClickListener(new btn_OnClick());
}
// 按钮点击事件
private class btn_OnClick implements OnClickListener {
@Override
public void onClick(View v) {
String status = Environment.getExternalStorageState();
// 判断是否有SD卡
if (status.equals(Environment.MEDIA_MOUNTED)) {
if (!hasPermission(carpermission)) {
PermissionGen.needPermission(Main.this, 18,
carpermission);
} else {
doTakePhoto();// 用户点击了从照相机获取
}
} else {
Toast.makeText(Main.this, "没有SD卡", Toast.LENGTH_LONG).show();
}
}
};
@PermissionSuccess(requestCode = 18)
public void succes() {
doTakePhoto();// 用户点击了从照相机获取
}
/**
* 为子类提供一个检查权限的方法
*
* @param permissions
* @return
*/
public boolean hasPermission(String... permissions) {
for (String permission : permissions) {
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
/**
* 从照片文件夹中选择完图片后会调用这个方法
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK)
return;
switch (requestCode) {
case PHOTO_PICKED_WITH_DATA: {// 调用(相册)Gallery返回的
try {
// 获得图片的uri
originalUri = data.getData();
} catch (Exception e) {
System.out.println(e.getMessage());
}
// 获取路径---------------------------
String[] proj = { MediaStore.Images.Media.DATA };
// 好像是android多媒体数据库的封装接口具体的看Android文档
@SuppressWarnings("deprecation")
Cursor cursor = managedQuery(originalUri, proj, null, null, null);
// 按我个人理解 这个是获得用户选择的图片的索引值
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
// 将光标移至开头 ,这个很重要,不小心很容易引起越界
cursor.moveToFirst();
// 最后根据索引值获取图片路径
userSelectPath = cursor.getString(column_index);
if (userSelectPath.indexOf("/") != -1) {
imgName = userSelectPath.substring(userSelectPath
.lastIndexOf("/") + 1);
}
try {
BitmapFactory.Options options = new BitmapFactory.Options();
// 先设置为TRUE不加载到内存中但可以得到宽和高
options.inJustDecodeBounds = true;
bm = BitmapFactory.decodeFile(userSelectPath, options); // 此时返回bm为空
options.inJustDecodeBounds = false;
// 计算缩放比
int be = (int) (options.outHeight / (float) 200);
if (be <= 0)
be = 1;
options.inSampleSize = be;
// 这样就不会内存溢出了
bm = BitmapFactory.decodeFile(userSelectPath, options);
h.post(new Runnable() {
@Override
public void run() {
img.setImageBitmap(bm);
}
});
} catch (Exception e) {
System.out
.println("PHOTO_PICKED_WITH_DATA:e=" + e.getMessage());
}
break;
}
// 照相机程序返回的,再次调用图片剪辑程序去修剪图片
case CAMERA_WITH_DATA: {
try {
userSelectPath = PHOTO_DIR + "/" + picName;
bm=BitmapFactory.decodeFile(userSelectPath);
img.setImageBitmap(bm);
// imgName = picName;
// BitmapFactory.Options options = new BitmapFactory.Options();
// // 先设置为TRUE不加载到内存中但可以得到宽和高
// options.inJustDecodeBounds = true;
// bm = BitmapFactory.decodeFile(userSelectPath, options); // 此时返回bm为空
// options.inJustDecodeBounds = false;
// // 计算缩放比
// int be = (int) (options.outHeight / (float) 200);
// if (be <= 0)
// be = 1;
// options.inSampleSize = be;
// // 这样就不会内存溢出了
// bm = BitmapFactory.decodeFile(userSelectPath, options);
//
// h.post(new Runnable() {
// @Override
// public void run() {
// img.setImageBitmap(bm);
// }
// });
} catch (Exception e) {
System.out.println("CAMERA_WITH_DATA:e=" + e.getMessage());
}
break;
}
}
}
/**
* 拍照获取图片
*
*/
protected void doTakePhoto() {
try {
PHOTO_DIR.mkdirs();// 创建照片的存储目录
Intent imageCaptureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
// 重新分解图片名称将-:的符号去掉
picName = getPhotoFileName();
picName = picName.replace("-", "");
picName = picName.replace(":", "");
File out = new File(PHOTO_DIR, picName);
Uri uri = Uri.fromFile(out);
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
imageCaptureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(imageCaptureIntent, CAMERA_WITH_DATA);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "doTakePhotoe=" + e, Toast.LENGTH_LONG)
.show();
}
}
/**
* 用当前时间给取得的图片命名
*
*/
private String getPhotoFileName() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");
return dateFormat.format(date) + ".jpg";
}
// 初始化界面控件
private void init() {
btn = (Button) findViewById(R.id.btn);
img = (ImageView) findViewById(R.id.img);
}
}

Some files were not shown because too many files have changed in this diff Show More