first commit
This commit is contained in:
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
87
.gitignore
vendored
Normal file
87
.gitignore
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
# Mac 忽略文件
|
||||
.DS_Store
|
||||
# Built application files
|
||||
*.apk
|
||||
*.aar
|
||||
*.ap_
|
||||
*.aab
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
out/
|
||||
# Uncomment the following line in case you need and you don't have the release build type files in your app
|
||||
# release/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
# Android Studio Navigation editor temp files
|
||||
.navigation/
|
||||
|
||||
# Android Studio captures folder
|
||||
captures/
|
||||
|
||||
# IntelliJ
|
||||
*.iml
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/gradle.xml
|
||||
.idea/assetWizardSettings.xml
|
||||
.idea/dictionaries
|
||||
.idea/libraries
|
||||
# Android Studio 3 in .gitignore file.
|
||||
.idea/caches
|
||||
.idea/modules.xml
|
||||
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
|
||||
.idea/navEditor.xml
|
||||
|
||||
# Keystore files
|
||||
# Uncomment the following lines if you do not want to check your keystore files in.
|
||||
#*.jks
|
||||
#*.keystore
|
||||
|
||||
# External native build folder generated in Android Studio 2.2 and later
|
||||
.externalNativeBuild
|
||||
.cxx/
|
||||
|
||||
# Google Services (e.g. APIs or Firebase)
|
||||
# google-services.json
|
||||
|
||||
# Freeline
|
||||
freeline.py
|
||||
freeline/
|
||||
freeline_project_description.json
|
||||
|
||||
# fastlane
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots
|
||||
fastlane/test_output
|
||||
fastlane/readme.md
|
||||
|
||||
# Version control
|
||||
vcs.xml
|
||||
|
||||
# lint
|
||||
lint/intermediates/
|
||||
lint/generated/
|
||||
lint/outputs/
|
||||
lint/tmp/
|
||||
# lint/reports/
|
||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
6
.idea/AndroidProjectSystem.xml
generated
Normal file
6
.idea/AndroidProjectSystem.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AndroidProjectSystem">
|
||||
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
|
||||
</component>
|
||||
</project>
|
||||
113
.idea/codeStyles/Project.xml
generated
Normal file
113
.idea/codeStyles/Project.xml
generated
Normal file
@@ -0,0 +1,113 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<codeStyleSettings language="XML">
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/deploymentTargetDropDown.xml
generated
Normal file
10
.idea/deploymentTargetDropDown.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<value>
|
||||
<entry key="app">
|
||||
<State />
|
||||
</entry>
|
||||
</value>
|
||||
</component>
|
||||
</project>
|
||||
18
.idea/deploymentTargetSelector.xml
generated
Normal file
18
.idea/deploymentTargetSelector.xml
generated
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetSelector">
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2025-06-18T12:41:30.439347200Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=badd8304" />
|
||||
</handle>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
<DialogSelection />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/encodings.xml
generated
Normal file
6
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
30
.idea/jarRepositories.xml
generated
Normal file
30
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="BintrayJCenter" />
|
||||
<option name="name" value="BintrayJCenter" />
|
||||
<option name="url" value="https://jcenter.bintray.com/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="Google" />
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/migrations.xml
generated
Normal file
10
.idea/migrations.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectMigrations">
|
||||
<option name="MigrateToGradleLocalJavaHome">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
60
.idea/misc.xml
generated
Normal file
60
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,60 @@
|
||||
<project version="4">
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="18">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
|
||||
<item index="7" class="java.lang.String" itemvalue="android.annotation.Nullable" />
|
||||
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
|
||||
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
|
||||
<item index="10" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
|
||||
<item index="11" class="java.lang.String" itemvalue="com.android.annotations.Nullable" />
|
||||
<item index="12" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" />
|
||||
<item index="13" class="java.lang.String" itemvalue="io.reactivex.annotations.Nullable" />
|
||||
<item index="14" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.Nullable" />
|
||||
<item index="15" class="java.lang.String" itemvalue="org.jspecify.nullness.Nullable" />
|
||||
<item index="16" class="java.lang.String" itemvalue="jakarta.annotation.Nullable" />
|
||||
<item index="17" class="java.lang.String" itemvalue="org.jspecify.annotations.Nullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="18">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
|
||||
<item index="6" class="java.lang.String" itemvalue="android.annotation.NonNull" />
|
||||
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
|
||||
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
|
||||
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
|
||||
<item index="10" class="java.lang.String" itemvalue="com.android.annotations.NonNull" />
|
||||
<item index="11" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.NonNull" />
|
||||
<item index="12" class="java.lang.String" itemvalue="io.reactivex.annotations.NonNull" />
|
||||
<item index="13" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.NonNull" />
|
||||
<item index="14" class="java.lang.String" itemvalue="lombok.NonNull" />
|
||||
<item index="15" class="java.lang.String" itemvalue="jakarta.annotation.Nonnull" />
|
||||
<item index="16" class="java.lang.String" itemvalue="org.jspecify.nullness.NonNull" />
|
||||
<item index="17" class="java.lang.String" itemvalue="org.jspecify.annotations.NonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
||||
17
.idea/runConfigurations.xml
generated
Normal file
17
.idea/runConfigurations.xml
generated
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
|
||||
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
|
||||
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
|
||||
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
236
HarmonyOS_官方资源快速参考.md
Normal file
236
HarmonyOS_官方资源快速参考.md
Normal file
@@ -0,0 +1,236 @@
|
||||
# HarmonyOS 5.0 官方开发者资源快速参考手册
|
||||
|
||||
## 🎯 使用说明
|
||||
|
||||
本文档为"进贤聚友棋牌 (HarmonyOS版)"项目提供官方开发者资源的快速索引和使用指导。**开发过程中必须优先参考官方文档**,本文档仅作为导航和补充。
|
||||
|
||||
---
|
||||
|
||||
## 📚 一、核心官方文档(优先级排序)
|
||||
|
||||
### ⭐⭐⭐⭐⭐ 最高优先级 - 日常开发必备
|
||||
|
||||
#### 1. **HarmonyOS API参考文档**
|
||||
- **官方链接**: https://developer.huawei.com/consumer/cn/doc/harmonyos-references/development-intro-api
|
||||
- **使用场景**: 所有API调用前必须查阅
|
||||
- **重点关注**:
|
||||
- Web组件API: `ts-basic-components-web`
|
||||
- WebviewController: `js-apis-webview`
|
||||
- 文件管理: `js-apis-file-fs`
|
||||
- 网络请求: `js-apis-http`
|
||||
- **开发建议**: 收藏并设为浏览器首页,开发过程中随时查阅
|
||||
|
||||
#### 2. **HarmonyOS应用开发指南**
|
||||
- **官方链接**: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/application-dev-guide
|
||||
- **使用场景**: 项目架构设计、功能实现方案设计
|
||||
- **重点关注**:
|
||||
- 应用工程结构: `application-project-structure`
|
||||
- WebView开发: `webview-js-interaction`
|
||||
- 数据管理: `data-mgmt-overview`
|
||||
- 网络管理: `network-connection-overview`
|
||||
- **开发建议**: 项目启动前通读相关章节,设计阶段重点参考
|
||||
|
||||
### ⭐⭐⭐⭐ 高优先级 - 技术决策参考
|
||||
|
||||
#### 3. **HarmonyOS最佳实践**
|
||||
- **官方链接**: https://developer.huawei.com/consumer/cn/doc/best-practices/bpta-best-practices-overview
|
||||
- **使用场景**: 架构设计、性能优化、代码质量提升
|
||||
- **重点关注**:
|
||||
- WebView性能优化: `bpta-webview-performance`
|
||||
- 网络请求优化: `bpta-network-request`
|
||||
- 内存管理: `bpta-memory-management`
|
||||
- ArkTS开发规范: `bpta-arkts-guidelines`
|
||||
- **开发建议**: 每个功能模块设计前查阅相关最佳实践
|
||||
|
||||
#### 4. **HarmonyOS版本发布说明**
|
||||
- **官方链接**: https://developer.huawei.com/consumer/cn/doc/harmonyos-releases/overview-allversion
|
||||
- **使用场景**: 版本兼容性确认、API变更跟踪
|
||||
- **重点关注**:
|
||||
- API 12新特性和变更
|
||||
- 兼容性要求
|
||||
- 废弃API列表
|
||||
- **开发建议**: 项目开始前确认目标版本,定期检查更新
|
||||
|
||||
### ⭐⭐⭐ 中等优先级 - 问题解决工具
|
||||
|
||||
#### 5. **HarmonyOS开发FAQ**
|
||||
- **官方链接**: https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-ux-design
|
||||
- **使用场景**: 遇到问题时的第一参考资料
|
||||
- **重点关注**:
|
||||
- WebView相关FAQ
|
||||
- ArkTS编译错误FAQ
|
||||
- 性能问题FAQ
|
||||
- **开发建议**: 遇到问题先查FAQ,再搜索或提问
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ 二、开发工具官方资源
|
||||
|
||||
### DevEco Studio
|
||||
- **官方下载**: https://developer.huawei.com/consumer/cn/deveco-studio/
|
||||
- **文档**: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ide-guide
|
||||
- **版本要求**: 支持HarmonyOS 5.0的最新版本
|
||||
- **关键功能**: 代码编辑、调试、模拟器、性能分析
|
||||
|
||||
### SDK管理
|
||||
- **官方指南**: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ide-sdk-manager
|
||||
- **版本选择**: API 12+ for HarmonyOS 5.0
|
||||
- **更新策略**: 定期检查更新,关注兼容性变更
|
||||
|
||||
---
|
||||
|
||||
## 🎯 三、项目关键功能的官方资源映射
|
||||
|
||||
### WebView与JSBridge开发
|
||||
```
|
||||
功能需求 → 官方资源
|
||||
├── WebView基础配置 → Web组件API参考
|
||||
├── JSBridge通信 → JavaScript与应用交互指南
|
||||
├── WebView控制器 → WebviewController API参考
|
||||
├── 性能优化 → WebView性能优化最佳实践
|
||||
└── 问题排查 → WebView FAQ专区
|
||||
```
|
||||
|
||||
### 资源管理与文件操作
|
||||
```
|
||||
功能需求 → 官方资源
|
||||
├── 文件读写 → 文件管理API参考
|
||||
├── 网络下载 → 网络请求API + 最佳实践
|
||||
├── 资源解压 → 文件系统API + ZIP处理示例
|
||||
├── 缓存管理 → 数据管理指南
|
||||
└── 权限申请 → 权限管理指南
|
||||
```
|
||||
|
||||
### 应用架构与状态管理
|
||||
```
|
||||
功能需求 → 官方资源
|
||||
├── 页面导航 → 页面路由开发指南
|
||||
├── 状态管理 → ArkUI状态管理
|
||||
├── 组件通信 → 组件化开发指南
|
||||
├── 生命周期 → 应用/组件生命周期
|
||||
└── 数据持久化 → 数据管理overview
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📋 四、开发阶段的官方资源使用计划
|
||||
|
||||
### 第一阶段:环境搭建
|
||||
**主要参考**:
|
||||
1. DevEco Studio安装指南
|
||||
2. SDK管理文档
|
||||
3. 项目创建向导
|
||||
4. 开发环境配置FAQ
|
||||
|
||||
**使用策略**: 严格按照官方指南操作,遇到问题优先查阅FAQ
|
||||
|
||||
### 第二阶段:核心功能开发
|
||||
**主要参考**:
|
||||
1. API参考文档(日常查阅)
|
||||
2. 开发指南(设计参考)
|
||||
3. 最佳实践(质量保证)
|
||||
4. 示例代码(快速上手)
|
||||
|
||||
**使用策略**: API文档作为编码标准,最佳实践指导架构设计
|
||||
|
||||
### 第三阶段:功能完善
|
||||
**主要参考**:
|
||||
1. 性能优化最佳实践
|
||||
2. 用户体验设计指南
|
||||
3. 兼容性测试指南
|
||||
4. 错误处理最佳实践
|
||||
|
||||
**使用策略**: 对照最佳实践优化代码质量和用户体验
|
||||
|
||||
### 第四阶段:测试与优化
|
||||
**主要参考**:
|
||||
1. 测试框架文档
|
||||
2. 性能分析工具指南
|
||||
3. 调试技巧文档
|
||||
4. 发布前检查清单
|
||||
|
||||
**使用策略**: 使用官方工具进行全面测试和性能优化
|
||||
|
||||
---
|
||||
|
||||
## 🔍 五、快速查找指南
|
||||
|
||||
### 常见问题快速定位
|
||||
|
||||
#### WebView相关问题
|
||||
```
|
||||
问题类型 → 查找路径
|
||||
├── 类型错误 → API参考文档 → WebviewController
|
||||
├── 通信失败 → 开发指南 → JavaScript交互
|
||||
├── 性能问题 → 最佳实践 → WebView性能优化
|
||||
├── 兼容性 → 版本说明 → API变更列表
|
||||
└── 其他 → FAQ → WebView专区
|
||||
```
|
||||
|
||||
#### ArkTS编译错误
|
||||
```
|
||||
问题类型 → 查找路径
|
||||
├── 语法错误 → 开发指南 → ArkTS语法
|
||||
├── 类型错误 → API参考 → 具体API类型定义
|
||||
├── 装饰器错误 → 开发指南 → 状态管理
|
||||
├── 导入错误 → 开发指南 → 模块化开发
|
||||
└── 其他 → FAQ → 编译错误专区
|
||||
```
|
||||
|
||||
### 搜索关键词建议
|
||||
|
||||
#### 中文搜索
|
||||
- "HarmonyOS WebView"
|
||||
- "ArkTS WebviewController"
|
||||
- "HarmonyOS JSBridge"
|
||||
- "HarmonyOS 文件管理"
|
||||
- "ArkTS 类型检查"
|
||||
|
||||
#### 英文搜索
|
||||
- "HarmonyOS Web Component"
|
||||
- "ArkTS WebviewController API"
|
||||
- "HarmonyOS JavaScript Proxy"
|
||||
- "HarmonyOS File System"
|
||||
- "ArkTS Type System"
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ 重要提醒
|
||||
|
||||
### 优先级原则
|
||||
1. **官方文档 > 第三方资料**:当存在冲突时,以官方文档为准
|
||||
2. **API参考 > 示例代码**:编码时优先查阅API文档确保参数正确
|
||||
3. **最新版本 > 历史版本**:确保使用与目标版本一致的文档
|
||||
|
||||
### 版本一致性
|
||||
- 确保查阅的文档版本与项目目标版本(HarmonyOS 5.0 API 12+)一致
|
||||
- 关注API变更和废弃通知
|
||||
- 定期检查文档更新
|
||||
|
||||
### 问题反馈
|
||||
- 通过官方开发者社区反馈技术问题
|
||||
- 利用DevEco Studio内置的问题报告功能
|
||||
- 参与官方技术交流群获得及时支持
|
||||
|
||||
---
|
||||
|
||||
## 📞 官方支持渠道
|
||||
|
||||
### 开发者社区
|
||||
- **HarmonyOS开发者论坛**: https://developer.huawei.com/consumer/cn/forum/block/harmonyos
|
||||
- **用途**: 技术讨论、问题求助、经验分享
|
||||
|
||||
### 官方技术支持
|
||||
- **在线客服**: DevEco Studio → Help → Contact Support
|
||||
- **用途**: 紧急技术问题、工具bug反馈
|
||||
|
||||
### 官方培训资源
|
||||
- **在线课程**: https://developer.huawei.com/consumer/cn/training/
|
||||
- **用途**: 系统学习HarmonyOS开发技能
|
||||
|
||||
---
|
||||
|
||||
**最后更新**: 2024年12月19日
|
||||
**文档版本**: v1.0
|
||||
**适用项目**: 进贤聚友棋牌 (HarmonyOS版)
|
||||
**目标平台**: HarmonyOS 5.0 (API 12+)
|
||||
1529
TSGame_HarmonyOS开发指南.md
Normal file
1529
TSGame_HarmonyOS开发指南.md
Normal file
File diff suppressed because it is too large
Load Diff
2535
TSGame_应用启动流程详解.md
Normal file
2535
TSGame_应用启动流程详解.md
Normal file
File diff suppressed because it is too large
Load Diff
85
app/build.gradle
Normal file
85
app/build.gradle
Normal 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')
|
||||
}
|
||||
Binary file not shown.
BIN
app/libs/agora-rtc-sdk.jar
Normal file
BIN
app/libs/agora-rtc-sdk.jar
Normal file
Binary file not shown.
BIN
app/libs/android-async-http-1.4.9.jar
Normal file
BIN
app/libs/android-async-http-1.4.9.jar
Normal file
Binary file not shown.
BIN
app/libs/android-support-percent.jar
Normal file
BIN
app/libs/android-support-percent.jar
Normal file
Binary file not shown.
BIN
app/libs/andserver1.0.1.jar
Normal file
BIN
app/libs/andserver1.0.1.jar
Normal file
Binary file not shown.
BIN
app/libs/ddmlib.jar
Normal file
BIN
app/libs/ddmlib.jar
Normal file
Binary file not shown.
BIN
app/libs/org.apache.http.legacy.jar
Normal file
BIN
app/libs/org.apache.http.legacy.jar
Normal file
Binary file not shown.
BIN
app/libs/xUtils-2.6.14.jar
Normal file
BIN
app/libs/xUtils-2.6.14.jar
Normal file
Binary file not shown.
BIN
app/libs/zxing.jar
Normal file
BIN
app/libs/zxing.jar
Normal file
Binary file not shown.
18
app/release/output-metadata.json
Normal file
18
app/release/output-metadata.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
243
app/src/main/AndroidManifest.xml
Normal file
243
app/src/main/AndroidManifest.xml
Normal 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>
|
||||
145
app/src/main/assets/WebViewJavascriptBridge.js
Normal file
145
app/src/main/assets/WebViewJavascriptBridge.js
Normal 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);
|
||||
})();
|
||||
24
app/src/main/assets/agent/BoolTest.java
Normal file
24
app/src/main/assets/agent/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/appversion/1/BoolTest.java
Normal file
24
app/src/main/assets/appversion/1/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/appversion/BoolTest.java
Normal file
24
app/src/main/assets/appversion/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/channel/BoolTest.java
Normal file
24
app/src/main/assets/channel/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
146
app/src/main/assets/demo.html
Normal file
146
app/src/main/assets/demo.html
Normal 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>
|
||||
|
||||
24
app/src/main/assets/gameconfig/BoolTest.java
Normal file
24
app/src/main/assets/gameconfig/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/gamedir/BoolTest.java
Normal file
24
app/src/main/assets/gamedir/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BIN
app/src/main/assets/gamehall/gamehall_42_0527.zip
Normal file
BIN
app/src/main/assets/gamehall/gamehall_42_0527.zip
Normal file
Binary file not shown.
7
app/src/main/assets/gamehall/version.xml
Normal file
7
app/src/main/assets/gamehall/version.xml
Normal 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>
|
||||
24
app/src/main/assets/gameid/BoolTest.java
Normal file
24
app/src/main/assets/gameid/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/gameserver/BoolTest.java
Normal file
24
app/src/main/assets/gameserver/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/gamestart/BoolTest.java
Normal file
24
app/src/main/assets/gamestart/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/gamestart/gamehall/BoolTest.java
Normal file
24
app/src/main/assets/gamestart/gamehall/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/market/4/BoolTest.java
Normal file
24
app/src/main/assets/market/4/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/market/BoolTest.java
Normal file
24
app/src/main/assets/market/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/other/BoolTest.java
Normal file
24
app/src/main/assets/other/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/servertype/BoolTest.java
Normal file
24
app/src/main/assets/servertype/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/src/main/assets/weburl/BoolTest.java
Normal file
24
app/src/main/assets/weburl/BoolTest.java
Normal 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("登入信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
516
app/src/main/java/com/badoo/mobile/util/WeakHandler.java
Normal file
516
app/src/main/java/com/badoo/mobile/util/WeakHandler.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
21
app/src/main/java/com/ceshi/tsgame/shake/DensityUtil.java
Normal file
21
app/src/main/java/com/ceshi/tsgame/shake/DensityUtil.java
Normal 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);
|
||||
}
|
||||
}
|
||||
74
app/src/main/java/com/ceshi/tsgame/shake/NeedForSound.java
Normal file
74
app/src/main/java/com/ceshi/tsgame/shake/NeedForSound.java
Normal 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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
108
app/src/main/java/com/ceshi/tsgame/shake/ShakeListener.java
Normal file
108
app/src/main/java/com/ceshi/tsgame/shake/ShakeListener.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
317
app/src/main/java/com/game/webgame/network/HttpUtil.java
Normal file
317
app/src/main/java/com/game/webgame/network/HttpUtil.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
134
app/src/main/java/com/game/webgame/network/ImageLoader.java
Normal file
134
app/src/main/java/com/game/webgame/network/ImageLoader.java
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
39
app/src/main/java/com/game/webgame/network/httpxutils.java
Normal file
39
app/src/main/java/com/game/webgame/network/httpxutils.java
Normal 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) {
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
150
app/src/main/java/com/game/webgame/network/register.java
Normal file
150
app/src/main/java/com/game/webgame/network/register.java
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <-> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
39
app/src/main/java/com/game/webgame/view/ListViewUtils.java
Normal file
39
app/src/main/java/com/game/webgame/view/ListViewUtils.java
Normal 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;
|
||||
|
||||
}
|
||||
}
|
||||
72
app/src/main/java/com/game/webgame/view/SpUtil.java
Normal file
72
app/src/main/java/com/game/webgame/view/SpUtil.java
Normal 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
58
app/src/main/java/com/game/webgame/view/dialogexit.java
Normal file
58
app/src/main/java/com/game/webgame/view/dialogexit.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
38
app/src/main/java/com/game/webgame/view/exitTitle.java
Normal file
38
app/src/main/java/com/game/webgame/view/exitTitle.java
Normal 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);
|
||||
}
|
||||
}
|
||||
12
app/src/main/java/com/game/webgame/view/gameutil.java
Normal file
12
app/src/main/java/com/game/webgame/view/gameutil.java
Normal 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;
|
||||
|
||||
|
||||
|
||||
}
|
||||
60
app/src/main/java/com/game/webgame/view/getAppinfo.java
Normal file
60
app/src/main/java/com/game/webgame/view/getAppinfo.java
Normal 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 "";
|
||||
}
|
||||
|
||||
}
|
||||
63
app/src/main/java/com/game/webgame/view/pmutil.java
Normal file
63
app/src/main/java/com/game/webgame/view/pmutil.java
Normal 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());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.http.xml.callback;
|
||||
|
||||
public interface MyHttpCallBack {
|
||||
|
||||
void success(String result);
|
||||
void failed(String result);
|
||||
|
||||
}
|
||||
40
app/src/main/java/com/jx/jyhd/MainActivity.java
Normal file
40
app/src/main/java/com/jx/jyhd/MainActivity.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
119
app/src/main/java/com/jx/jyhd/sgapi/SGEntryActivity.java
Normal file
119
app/src/main/java/com/jx/jyhd/sgapi/SGEntryActivity.java
Normal 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();
|
||||
// }
|
||||
//}
|
||||
9
app/src/main/java/com/jx/jyhd/sgapi/XLConstants.java
Normal file
9
app/src/main/java/com/jx/jyhd/sgapi/XLConstants.java
Normal 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";
|
||||
}
|
||||
19
app/src/main/java/com/jx/jyhd/simcpux/AppRegister.java
Normal file
19
app/src/main/java/com/jx/jyhd/simcpux/AppRegister.java
Normal 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);
|
||||
}
|
||||
}
|
||||
27
app/src/main/java/com/jx/jyhd/simcpux/Constants.java
Normal file
27
app/src/main/java/com/jx/jyhd/simcpux/Constants.java
Normal 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";
|
||||
|
||||
|
||||
}
|
||||
28
app/src/main/java/com/jx/jyhd/simcpux/MD5.java
Normal file
28
app/src/main/java/com/jx/jyhd/simcpux/MD5.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
app/src/main/java/com/jx/jyhd/simcpux/MD5Util.java
Normal file
43
app/src/main/java/com/jx/jyhd/simcpux/MD5Util.java
Normal 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" };
|
||||
|
||||
}
|
||||
393
app/src/main/java/com/jx/jyhd/simcpux/Util.java
Normal file
393
app/src/main/java/com/jx/jyhd/simcpux/Util.java
Normal 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;
|
||||
}
|
||||
}
|
||||
12
app/src/main/java/com/jx/jyhd/simcpux/Wxistrue.java
Normal file
12
app/src/main/java/com/jx/jyhd/simcpux/Wxistrue.java
Normal 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 朋友圈
|
||||
|
||||
}
|
||||
358
app/src/main/java/com/jx/jyhd/simcpux/util/WeChatShareUtil.java
Normal file
358
app/src/main/java/com/jx/jyhd/simcpux/util/WeChatShareUtil.java
Normal 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();
|
||||
}
|
||||
}
|
||||
421
app/src/main/java/com/jx/jyhd/wxapi/WXEntryActivity.java
Normal file
421
app/src/main/java/com/jx/jyhd/wxapi/WXEntryActivity.java
Normal 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) {
|
||||
|
||||
}
|
||||
}
|
||||
94
app/src/main/java/com/jx/jyhd/wxapi/WXPayEntryActivity.java
Normal file
94
app/src/main/java/com/jx/jyhd/wxapi/WXPayEntryActivity.java
Normal 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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
190
app/src/main/java/com/nickming/view/AudioManager.java
Normal file
190
app/src/main/java/com/nickming/view/AudioManager.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
127
app/src/main/java/com/nickming/view/DialogManager.java
Normal file
127
app/src/main/java/com/nickming/view/DialogManager.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
410
app/src/main/java/com/nickming/view/Falcon.java
Normal file
410
app/src/main/java/com/nickming/view/Falcon.java
Normal 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
|
||||
}
|
||||
77
app/src/main/java/com/nickming/view/ScreenShoddmlib.java
Normal file
77
app/src/main/java/com/nickming/view/ScreenShoddmlib.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
153
app/src/main/java/com/nickming/view/Screenshot.java
Normal file
153
app/src/main/java/com/nickming/view/Screenshot.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.nickming.view.listener;
|
||||
|
||||
public interface savelistener {
|
||||
public void save(String bitmappath);
|
||||
|
||||
}
|
||||
7
app/src/main/java/com/tagmae/jsbridge/BridgeHandler.java
Normal file
7
app/src/main/java/com/tagmae/jsbridge/BridgeHandler.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.tagmae.jsbridge;
|
||||
|
||||
public interface BridgeHandler {
|
||||
|
||||
void handler(String data, CallBackFunction function);
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user