Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f64325f2b | |||
| de9c9cbdcb | |||
| 1fe9e259b4 | |||
| 6b4f68128b | |||
| 8b637fbeec | |||
| 7267535ccf | |||
| 8f99987696 | |||
| 515473e5dc | |||
| 8b83e939ce | |||
| c71bd36de2 | |||
| 9fdc8f0da3 | |||
| 8ba099024e | |||
| e656acec1d | |||
| 6fa4994e04 | |||
| a929706219 | |||
| 62effd1cc1 | |||
| 417b597d1d | |||
| 2fabb9013a | |||
| 835dcc6446 | |||
| fba0a6ec71 | |||
| 9a2f4c984c | |||
| d870e68001 | |||
| 8e7fcfb746 | |||
| a995e132f3 | |||
| 6b9921c5a7 | |||
| 75695812ee | |||
| eae0414cb4 | |||
| 7b203bedfc | |||
| da20b817d2 | |||
| ef1f2251b5 | |||
| c907835ce7 | |||
| 3be623dd63 | |||
| 045c1e0305 | |||
| c292e79d94 | |||
| cb54d87daf | |||
| a29c0bd466 | |||
| 575ba33e43 |
13
.gitignore
vendored
13
.gitignore
vendored
@ -1,9 +1,8 @@
|
||||
/.idea
|
||||
.idea/misc.xml
|
||||
.idea/
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
.gradle/
|
||||
local.properties
|
||||
# sign.properties
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
/PushSDK/build
|
||||
captures/
|
||||
build/
|
||||
@ -1,51 +0,0 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 22
|
||||
buildToolsVersion "23.0.2"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 11
|
||||
targetSdkVersion 22
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
debug {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
manifest.srcFile 'AndroidManifest.xml'
|
||||
java.srcDirs = ['src']
|
||||
resources.srcDirs = ['src']
|
||||
aidl.srcDirs = ['src']
|
||||
renderscript.srcDirs = ['src']
|
||||
res.srcDirs = ['res']
|
||||
assets.srcDirs = ['assets']
|
||||
jniLibs.srcDirs = ['libs']
|
||||
}
|
||||
|
||||
// Move the tests to tests/java, tests/res, etc...
|
||||
instrumentTest.setRoot('tests')
|
||||
|
||||
// Move the build types to build-types/<type>
|
||||
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
|
||||
// This moves them out of them default location under src/<type>/... which would
|
||||
// conflict with src/ being used by the main source set.
|
||||
// Adding new build types or product flavors should be accompanied
|
||||
// by a similar customization.
|
||||
debug.setRoot('build-types/debug')
|
||||
release.setRoot('build-types/release')
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
||||
@ -1,156 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.umeng.message.lib.test" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="11"
|
||||
android:targetSdkVersion="22" />
|
||||
|
||||
<instrumentation
|
||||
android:name="android.test.InstrumentationTestRunner"
|
||||
android:functionalTest="false"
|
||||
android:handleProfiling="false"
|
||||
android:label="Tests for com.umeng.message.lib.test"
|
||||
android:targetPackage="com.umeng.message.lib.test" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" />
|
||||
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
|
||||
<application>
|
||||
<uses-library android:name="android.test.runner" />
|
||||
|
||||
<service
|
||||
android:name="com.taobao.accs.ChannelService"
|
||||
android:exported="true"
|
||||
android:process=":channel" >
|
||||
<intent-filter>
|
||||
<action android:name="com.taobao.accs.intent.action.SERVICE" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.taobao.accs.intent.action.ELECTION" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service
|
||||
android:name="com.taobao.accs.data.MsgDistributeService"
|
||||
android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="com.taobao.accs.intent.action.RECEIVE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name="com.taobao.accs.EventReceiver"
|
||||
android:process=":channel" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_REMOVED" />
|
||||
|
||||
<data android:scheme="package" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.USER_PRESENT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name="com.taobao.accs.ServiceReceiver"
|
||||
android:exported="false"
|
||||
android:process=":channel" >
|
||||
<intent-filter>
|
||||
<action android:name="com.taobao.accs.intent.action.COMMAND" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.taobao.accs.intent.action.START_FROM_AGOO" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name="com.taobao.accs.ChannelService$KernelService"
|
||||
android:process=":channel" >
|
||||
</service>
|
||||
<service
|
||||
android:name="org.android.agoo.accs.AgooService"
|
||||
android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="com.taobao.accs.intent.action.RECEIVE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service
|
||||
android:name="com.umeng.message.UmengIntentService"
|
||||
android:exported="true"
|
||||
android:process=":channel" >
|
||||
<intent-filter>
|
||||
<action android:name="org.agoo.android.intent.action.RECEIVE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name="com.taobao.agoo.AgooCommondReceiver"
|
||||
android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="com.gh.gamecenter.intent.action.COMMAND" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_REMOVED" />
|
||||
|
||||
<data android:scheme="package" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name="com.umeng.message.NotificationProxyBroadcastReceiver"
|
||||
android:exported="false" />
|
||||
|
||||
<service
|
||||
android:name="com.umeng.message.UmengMessageCallbackHandlerService"
|
||||
android:exported="false" >
|
||||
<intent-filter>
|
||||
<action android:name="com.umeng.messge.registercallback.action" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.umeng.message.enablecallback.action" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.umeng.message.disablecallback.action" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.umeng.message.message.handler.action" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service
|
||||
android:name="com.umeng.message.UmengDownloadResourceService"
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name="com.umeng.message.UmengMessageIntentReceiverService"
|
||||
android:exported="true"
|
||||
android:process=":channel" >
|
||||
<intent-filter>
|
||||
<action android:name="org.android.agoo.client.MessageReceiverService" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<provider
|
||||
android:name="com.umeng.message.provider.MessageProvider"
|
||||
android:authorities="com.gh.gamecenter.umeng.message"
|
||||
android:exported="false" >
|
||||
<grant-uri-permission android:pathPattern=".*" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -1,12 +0,0 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-19
|
||||
android.library=true
|
||||
1
app/.gitignore
vendored
1
app/.gitignore
vendored
@ -1 +0,0 @@
|
||||
/build
|
||||
111
app/build.gradle
111
app/build.gradle
@ -1,39 +1,55 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
//butterknife
|
||||
apply plugin: 'com.neenbedankt.android-apt'
|
||||
|
||||
android {
|
||||
compileSdkVersion 21
|
||||
buildToolsVersion "23.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.gh.gamecenter"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 21
|
||||
versionCode 18
|
||||
versionName "2.3"
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
// 默认的渠道
|
||||
// manifestPlaceholders = [CHANNEL_VALUE: "GH_TEST"]
|
||||
dexOptions {
|
||||
jumboMode = true
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名设置
|
||||
* 定位编译出错的图片
|
||||
*/
|
||||
aaptOptions.cruncherEnabled = false
|
||||
aaptOptions.useNewCruncher = false
|
||||
|
||||
defaultConfig {
|
||||
// jackOptions {
|
||||
// enabled true
|
||||
// }
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
applicationId rootProject.ext.applicationId
|
||||
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
debug {
|
||||
}
|
||||
release {
|
||||
storeFile file("gh.keystore")
|
||||
keyAlias "gh.keystore"
|
||||
keyPassword "20150318"
|
||||
storePassword "20150318"
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
zipAlignEnabled false
|
||||
// versionNameSuffix "-debug"
|
||||
}
|
||||
release {
|
||||
debuggable false
|
||||
minifyEnabled false
|
||||
zipAlignEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
@ -80,21 +96,13 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
//butterknife
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||
}
|
||||
}
|
||||
apply plugin: 'com.neenbedankt.android-apt'
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:21.0.0'
|
||||
|
||||
compile fileTree(dir: 'libs', include: '*.jar')
|
||||
|
||||
compile 'com.android.support:appcompat-v7:23.2.1'
|
||||
// compile 'com.android.support:cardview-v7:21.0.0'
|
||||
// fresco图片框架
|
||||
compile 'com.facebook.fresco:fresco:0.12.0'
|
||||
@ -124,9 +132,48 @@ dependencies {
|
||||
compile 'com.jakewharton.rxbinding:rxbinding:0.3.0'
|
||||
// compile 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:0.3.0'
|
||||
// compile 'com.jakewharton.rxbinding:rxbinding-design:0.3.0'
|
||||
//添加友盟依赖工程
|
||||
compile project(':PushSDK')
|
||||
|
||||
// zxing 二维码扫描以及生成
|
||||
compile 'com.google.zxing:core:3.2.1'
|
||||
compile 'com.google.zxing:android-core:3.2.1'
|
||||
}
|
||||
//tinker
|
||||
// compile("com.tencent.tinker:tinker-android-lib:${TINKER_VERSION}") { changing = true }
|
||||
// compile "com.android.support:multidex:1.0.1"
|
||||
|
||||
compile project(':libraries:EventBus')
|
||||
compile project(':libraries:MiPush')
|
||||
compile project(':libraries:MTA')
|
||||
compile project(':libraries:QQShare')
|
||||
compile project(':libraries:TalkingData')
|
||||
compile project(':libraries:UmengPush')
|
||||
compile project(':libraries:WechatShare')
|
||||
compile project(':libraries:WeiboShare')
|
||||
|
||||
}
|
||||
File propFile = file('sign.properties');
|
||||
if (propFile.exists()) {
|
||||
def Properties props = new Properties()
|
||||
props.load(new FileInputStream(propFile))
|
||||
|
||||
if (props.containsKey('keyAlias') && props.containsKey('keyPassword') &&
|
||||
props.containsKey('storeFile') && props.containsKey('storePassword')) {
|
||||
android.signingConfigs {
|
||||
// debug {
|
||||
// keyAlias props.get('keyAlias')
|
||||
// keyPassword props.get('keyPassword')
|
||||
// storeFile file(props.get('storeFile'))
|
||||
// storePassword props.get('storePassword')
|
||||
// }
|
||||
release {
|
||||
keyAlias props.get('keyAlias')
|
||||
keyPassword props.get('keyPassword')
|
||||
storeFile file(props.get('storeFile'))
|
||||
storePassword props.get('storePassword')
|
||||
}
|
||||
}
|
||||
} else {
|
||||
android.buildTypes.release.signingConfig = null
|
||||
}
|
||||
} else {
|
||||
android.buildTypes.release.signingConfig = null
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
4
app/proguard-rules.pro
vendored
4
app/proguard-rules.pro
vendored
@ -15,3 +15,7 @@
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
|
||||
-dontwarn InnerClasses
|
||||
-dontoptimize
|
||||
4
app/sign.properties
Normal file
4
app/sign.properties
Normal file
@ -0,0 +1,4 @@
|
||||
storeFile=gh.keystore
|
||||
storePassword=20150318
|
||||
keyAlias=gh.keystore
|
||||
keyPassword=20150318
|
||||
@ -38,6 +38,8 @@
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<!-- 小米推送需要的权限 -->
|
||||
<uses-permission android:name="com.gh.gamecenter.permission.MIPUSH_RECEIVE" />
|
||||
<!-- 修改系统设置的权限 -->
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
|
||||
|
||||
<permission
|
||||
android:name="com.gh.gamecenter.permission.MIPUSH_RECEIVE"
|
||||
@ -64,23 +66,18 @@
|
||||
android:value="GH_TEST"/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<!-- MTA -->
|
||||
<meta-data
|
||||
android:name="TA_APPKEY"
|
||||
android:value="APV567FTBS7J"/>
|
||||
<meta-data
|
||||
android:name="InstallChannel"
|
||||
android:value="GH_TEST"/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
|
||||
<!-- 友盟推送 -->
|
||||
<meta-data
|
||||
android:name="UMENG_APPKEY"
|
||||
android:value="585a29fa8f4a9d327600023e">
|
||||
android:value="58e5b0b9c62dca35a00005e6">
|
||||
<!-- TODO 585a29fa8f4a9d327600023e -->
|
||||
</meta-data>
|
||||
<meta-data
|
||||
android:name="UMENG_MESSAGE_SECRET"
|
||||
android:value="8bcce6bed547ee624f5c2cc64d39a9e9">
|
||||
android:value="ca08596492f8a7fde2ab48dceab8c1f3">
|
||||
<!-- TODO 8bcce6bed547ee624f5c2cc64d39a9e9 -->
|
||||
</meta-data>
|
||||
|
||||
<activity
|
||||
@ -109,20 +106,13 @@
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SearchActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateVisible" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.GameDetailActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
android:configChanges="keyboardHidden" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.NewsDetailActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SettingActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SuggestionActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateVisible" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.ConcernActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
@ -153,15 +143,65 @@
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.MessageDetailActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.StrategyActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.LibaoActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.LibaoDetailActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.ShareGhWfifActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.ShareGhActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.CleanApkActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.KcSelectGameActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.ChooseReceiverActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.ReceiverWaitingActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.FileSenderActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.FileReceiverActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SelectUserIconActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.AboutActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.NewsNormalActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.KaiFuActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.CommentDetailActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.GameDetailActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SuggestSelectActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name=".SuggestionActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateHidden|adjustResize" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.VoteActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SkipActivity"
|
||||
android:theme="@android:style/Theme.Translucent">
|
||||
@ -299,8 +339,12 @@
|
||||
<service
|
||||
android:name="com.gh.download.DownloadService" />
|
||||
|
||||
<!--<service-->
|
||||
<!--android:name="com.gh.base.AppTinkerResultService"-->
|
||||
<!--android:exported="false" />-->
|
||||
|
||||
<service
|
||||
android:name=".statistics.AppStaticService" />
|
||||
android:name="com.gh.gamecenter.statistics.AppStaticService" />
|
||||
|
||||
<service
|
||||
android:name="com.xiaomi.push.service.XMJobService"
|
||||
|
||||
67
app/src/main/assets/Home.html
Normal file
67
app/src/main/assets/Home.html
Normal file
@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>光环助手</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<style>
|
||||
body {
|
||||
font: 100%/1.0 'Microsoft YaHei','Helvetica Neue',Helvetica,Arial,sans-serif;
|
||||
background-color: #fff;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
header {
|
||||
}
|
||||
|
||||
article {
|
||||
width:100%;
|
||||
max-width:720px;
|
||||
clear: both;
|
||||
margin: 0 auto;
|
||||
margin-top: 20%;
|
||||
text-align: center;
|
||||
margin-bottom:20%;
|
||||
}
|
||||
.title{margin-top: 4%;font-size:1.7em;color:#191919;text-align:center;}
|
||||
.info{margin-top: 18%;font-size:1.0em;color:#191919;line-height:1.3em;}
|
||||
.download {text-align: center;}
|
||||
.download a{font-size:1.8em;padding:0.2em; text-align:center;color:#ffffff;margin: 0 auto;width:56%;background-color:#2999f9;border-radius:8px; text-decoration:none;display:block;line-height:1.8em;}
|
||||
|
||||
@media only screen and (min-width: 1080px) {
|
||||
article {
|
||||
width:100%;
|
||||
max-width:720px;
|
||||
clear: both;
|
||||
margin: 0 auto;
|
||||
margin-top: 5%;
|
||||
text-align: center;
|
||||
margin-bottom:20%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
</header>
|
||||
|
||||
<article>
|
||||
<img src="http://192.168.43.1:3100/image/gh_icon.png" width="28%">
|
||||
<p class="title">光环助手</p>
|
||||
<br class="info">乐于分享的人是最帅的^_^ </p>
|
||||
<div class="download">
|
||||
<a href="http://192.168.43.1:3100/download/ghzs.apk">免流量下载</a>
|
||||
</div>
|
||||
<p class="title"><font color="#9A9A9A" size="3em">仅限安卓系统 </font></p>
|
||||
</article>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@ -23,14 +23,17 @@ import com.xiaomi.mipush.sdk.MiPushClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class AppController extends Application {
|
||||
//public class AppController extends TinkerApplication {
|
||||
|
||||
public static final String TAG = AppController.class.getSimpleName();
|
||||
// xiaomi push appid
|
||||
public static final String APP_ID = "2882303761517352993";
|
||||
// xiaomi push appkey
|
||||
public static final String APP_KEY = "5451735292993";
|
||||
// TODO xiaomi push appid 2882303761517352993
|
||||
public static final String APP_ID = "2882303761517564447";
|
||||
// TODO xiaomi push appkey 5451735292993
|
||||
public static final String APP_KEY = "5761756481447";
|
||||
|
||||
private static AppController mInstance;
|
||||
private static ArrayMap<String, Object> objectMap = new ArrayMap<>();
|
||||
@ -39,6 +42,17 @@ public class AppController extends Application {
|
||||
|
||||
private boolean isFinish = false;
|
||||
|
||||
//快传文件发送单线程
|
||||
public static Executor FILE_SENDER_EXECUTOR = Executors.newSingleThreadExecutor();
|
||||
|
||||
//快传文件发送主要的线程池
|
||||
public static Executor MAIN_EXECUTOR = Executors.newFixedThreadPool(5);
|
||||
|
||||
// public AppController() {
|
||||
// super(ShareConstants.TINKER_ENABLE_ALL, "com.gh.base.AppControllerLike",
|
||||
// "com.tencent.tinker.loader.TinkerLoader", false);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
51
app/src/main/java/com/gh/base/AppControllerLike.java
Normal file
51
app/src/main/java/com/gh/base/AppControllerLike.java
Normal file
@ -0,0 +1,51 @@
|
||||
//package com.gh.base;
|
||||
//
|
||||
//
|
||||
//import android.annotation.TargetApi;
|
||||
//import android.app.Application;
|
||||
//import android.content.Context;
|
||||
//import android.content.Intent;
|
||||
//import android.os.Build;
|
||||
//import android.support.multidex.MultiDex;
|
||||
//
|
||||
//import com.tencent.tinker.lib.listener.DefaultPatchListener;
|
||||
//import com.tencent.tinker.lib.listener.PatchListener;
|
||||
//import com.tencent.tinker.lib.patch.AbstractPatch;
|
||||
//import com.tencent.tinker.lib.patch.UpgradePatch;
|
||||
//import com.tencent.tinker.lib.reporter.DefaultLoadReporter;
|
||||
//import com.tencent.tinker.lib.reporter.DefaultPatchReporter;
|
||||
//import com.tencent.tinker.lib.reporter.LoadReporter;
|
||||
//import com.tencent.tinker.lib.reporter.PatchReporter;
|
||||
//import com.tencent.tinker.lib.tinker.TinkerInstaller;
|
||||
//import com.tencent.tinker.loader.app.DefaultApplicationLike;
|
||||
//
|
||||
//public class AppControllerLike extends DefaultApplicationLike {
|
||||
//
|
||||
// public AppControllerLike(Application application, int tinkerFlags, boolean tinkerLoadVerifyFlag,
|
||||
// long applicationStartElapsedTime, long applicationStartMillisTime,
|
||||
// Intent tinkerResultIntent) {
|
||||
// super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime,
|
||||
// applicationStartMillisTime, tinkerResultIntent);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onBaseContextAttached(Context base) {
|
||||
// super.onBaseContextAttached(base);
|
||||
// MultiDex.install(base);
|
||||
//
|
||||
// LoadReporter loadReporter = new DefaultLoadReporter(getApplication());
|
||||
// PatchReporter patchReporter = new DefaultPatchReporter(getApplication());
|
||||
// PatchListener patchListener = new DefaultPatchListener(getApplication());
|
||||
// AbstractPatch upgradePatchProcessor = new UpgradePatch();
|
||||
//
|
||||
// TinkerInstaller.install(this, loadReporter, patchReporter, patchListener,
|
||||
// AppTinkerResultService.class, upgradePatchProcessor);
|
||||
//// TinkerInstaller.install(this);
|
||||
// }
|
||||
//
|
||||
// @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
// public void registerActivityLifecycleCallbacks(Application.ActivityLifecycleCallbacks callback) {
|
||||
// getApplication().registerActivityLifecycleCallbacks(callback);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
29
app/src/main/java/com/gh/base/AppTinkerResultService.java
Normal file
29
app/src/main/java/com/gh/base/AppTinkerResultService.java
Normal file
@ -0,0 +1,29 @@
|
||||
//package com.gh.base;
|
||||
//
|
||||
//import com.gh.common.util.Utils;
|
||||
//import com.tencent.tinker.lib.service.DefaultTinkerResultService;
|
||||
//import com.tencent.tinker.lib.service.PatchResult;
|
||||
//import com.tencent.tinker.lib.util.TinkerServiceInternals;
|
||||
//
|
||||
//import java.io.File;
|
||||
//
|
||||
//
|
||||
//public class AppTinkerResultService extends DefaultTinkerResultService {
|
||||
//
|
||||
// @Override
|
||||
// public void onPatchResult(PatchResult result) {
|
||||
// if (result == null) {
|
||||
// return;
|
||||
// }
|
||||
// Utils.log(result);
|
||||
//
|
||||
// //first, we want to kill the recover process
|
||||
// TinkerServiceInternals.killTinkerPatchServiceProcess(getApplicationContext());
|
||||
//
|
||||
// if (result.isSuccess) {
|
||||
// Utils.log("Tinkder Success");
|
||||
// deleteRawPatchFile(new File(result.rawPatchFilePath));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@ -3,6 +3,7 @@ package com.gh.base;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
@ -68,7 +69,7 @@ public class BaseActivity extends Activity implements OnCallBackListener {
|
||||
setTranslucentStatus(true);
|
||||
tintManager = new SystemBarTintManager(this);
|
||||
tintManager.setStatusBarTintEnabled(true);
|
||||
tintManager.setStatusBarTintResource(R.color.theme);
|
||||
tintManager.setStatusBarTintColor(Color.BLACK);
|
||||
SystemBarConfig config = tintManager.getConfig();
|
||||
contentView.setPadding(0, config.getPixelInsetTop(false), 0,
|
||||
config.getPixelInsetBottom());
|
||||
@ -80,7 +81,7 @@ public class BaseActivity extends Activity implements OnCallBackListener {
|
||||
|
||||
int actionbar_height = getSharedPreferences(Config.PREFERENCE,
|
||||
Context.MODE_PRIVATE).getInt("actionbar_height",
|
||||
DisplayUtils.dip2px(getApplicationContext(), 48));
|
||||
DisplayUtils.dip2px(getApplicationContext(), 55));
|
||||
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) findViewById(R.id.reuse_actionbar);
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
@ -140,7 +141,7 @@ public class BaseActivity extends Activity implements OnCallBackListener {
|
||||
}
|
||||
}
|
||||
|
||||
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin);
|
||||
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin, true);
|
||||
|
||||
if (newsTitle == null) {
|
||||
DataUtils.onEvent(this, "内容分享", gameName);
|
||||
|
||||
@ -344,6 +344,7 @@ public abstract class BaseDetailActivity extends BaseActivity implements View.On
|
||||
String str = detail_tv_per.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
Intent intent = new Intent(this, DownloadManagerActivity.class);
|
||||
intent.putExtra("currentItem", 1);
|
||||
intent.putExtra("url", gameEntity.getApk().get(0).getUrl());
|
||||
intent.putExtra("entrance", entrance + "+(" + name + "[" + title + "])");
|
||||
startActivity(intent);
|
||||
|
||||
@ -2,6 +2,7 @@ package com.gh.base;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
@ -65,7 +66,7 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
setTranslucentStatus(true);
|
||||
SystemBarTintManager tintManager = new SystemBarTintManager(this);
|
||||
tintManager.setStatusBarTintEnabled(true);
|
||||
tintManager.setStatusBarTintResource(R.color.theme);
|
||||
tintManager.setStatusBarTintColor(Color.BLACK);
|
||||
SystemBarConfig config = tintManager.getConfig();
|
||||
contentView.setPadding(0, config.getPixelInsetTop(false), 0,
|
||||
config.getPixelInsetBottom());
|
||||
@ -133,7 +134,7 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
}
|
||||
}
|
||||
|
||||
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin);
|
||||
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin, true);
|
||||
|
||||
if (newsTitle == null){
|
||||
DataUtils.onEvent(this, "内容分享", gameName);
|
||||
|
||||
@ -8,10 +8,12 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.ScaleAnimation;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -28,6 +30,8 @@ import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
@ -43,13 +47,16 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
private TextView downloadHint;
|
||||
private TextView searchHint;
|
||||
|
||||
private String hint;
|
||||
private AlphaAnimation mAlphaAnimation;
|
||||
|
||||
private ArrayList<String> hintList;
|
||||
private int hintIndex;
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
outState.putString("hint", hint);
|
||||
if (hintList != null && !hintList.isEmpty()) {
|
||||
outState.putStringArrayList("hint", hintList);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,17 +65,18 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
hint = savedInstanceState.getString("hint");
|
||||
hintList = savedInstanceState.getStringArrayList("hint");
|
||||
}
|
||||
|
||||
hintIndex = 0;
|
||||
|
||||
view = View.inflate(getActivity(), R.layout.fragment_home, null);
|
||||
|
||||
SharedPreferences sp = getActivity().getSharedPreferences(
|
||||
Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
LinearLayout home_actionbar = (LinearLayout) view.findViewById(R.id.home_actionbar);
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT, sp.getInt("actionbar_height",
|
||||
DisplayUtils.dip2px(getActivity(), 48)));
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,DisplayUtils.dip2px(getActivity(), 55));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
int top = DisplayUtils.getStatusBarHeight(getResources());
|
||||
@ -79,6 +87,70 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
initActionBar();
|
||||
|
||||
final ScaleAnimation scaleAnimation = new ScaleAnimation(0.4f, 1.0f, 0.4f, 1.0f
|
||||
, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
|
||||
scaleAnimation.setDuration(500);
|
||||
|
||||
mAlphaAnimation = new AlphaAnimation(1f, 0.2f);
|
||||
mAlphaAnimation.setDuration(300);
|
||||
mAlphaAnimation.setStartOffset(5000);
|
||||
|
||||
scaleAnimation.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
if (mAlphaAnimation != null) {
|
||||
searchHint.setAnimation(mAlphaAnimation);
|
||||
mAlphaAnimation.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
mAlphaAnimation.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
// 切换数据
|
||||
if (hintIndex > hintList.size() - 1) {
|
||||
hintIndex = 0;
|
||||
}
|
||||
searchHint.setHint(hintList.get(hintIndex));
|
||||
hintIndex ++;
|
||||
|
||||
if (scaleAnimation != null) {
|
||||
searchHint.setAnimation(scaleAnimation);
|
||||
scaleAnimation.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (hintList != null && hintList.size() > 0) {
|
||||
if (hintList.size() > 1) {
|
||||
searchHint.setAnimation(mAlphaAnimation);
|
||||
} else {
|
||||
String hint = hintList.get(0);
|
||||
searchHint.setHint(hint);
|
||||
}
|
||||
}
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@ -96,6 +168,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
view.findViewById(R.id.actionbar_rl_download).setOnClickListener(this);
|
||||
view.findViewById(R.id.actionbar_iv_search).setOnClickListener(this);
|
||||
view.findViewById(R.id.actionbar_notification).setOnClickListener(this);
|
||||
view.findViewById(R.id.actionbar_search_rl).setOnClickListener(this);
|
||||
|
||||
if (Config.isShow(getActivity())) {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE);
|
||||
@ -118,9 +191,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
searchHint = (TextView) view.findViewById(R.id.actionbar_search_input);
|
||||
searchHint.setOnClickListener(this);
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
searchHint.setHint(hint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -132,6 +202,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
Intent intent = new Intent(getActivity(), DownloadManagerActivity.class);
|
||||
intent.putExtra("entrance", "(工具栏)");
|
||||
intent.putExtra("currentItem", 0);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.actionbar_iv_search) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "搜索图标");
|
||||
@ -139,16 +210,16 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
Intent intent = new Intent(getActivity(), SearchActivity.class);
|
||||
intent.putExtra("clicked", true);
|
||||
intent.putExtra("hint", hint);
|
||||
intent.putExtra("hint", searchHint.getHint().toString());
|
||||
intent.putExtra("entrance", "(工具栏)");
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.actionbar_search_input) {
|
||||
} else if (id == R.id.actionbar_search_input || id == R.id.actionbar_search_rl) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "搜索框");
|
||||
DataCollectionUtils.uploadClick(getActivity(), "搜索框", "主页");
|
||||
|
||||
Intent intent = new Intent(getActivity(), SearchActivity.class);
|
||||
intent.putExtra("clicked", false);
|
||||
intent.putExtra("hint", hint);
|
||||
intent.putExtra("hint", searchHint.getHint().toString());
|
||||
intent.putExtra("entrance", "(工具栏)");
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.actionbar_notification) {
|
||||
@ -172,11 +243,13 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void setHint(String hint) {
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
this.hint = hint;
|
||||
if (searchHint != null) {
|
||||
searchHint.setHint(hint);
|
||||
public void setHint(ArrayList<String> hint) {
|
||||
if (hint != null && hint.size() > 0) {
|
||||
hintList = hint;
|
||||
if (hint.size() == 1 && searchHint != null) {
|
||||
searchHint.setHint(hintList.get(0));
|
||||
} else if (mAlphaAnimation != null && searchHint != null) {
|
||||
searchHint.setAnimation(mAlphaAnimation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,11 +6,11 @@ import android.content.SharedPreferences;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static final String HOST = "http://api.ghzhushou.com/v2d3/";
|
||||
public static final String USER_HOST = "http://user.ghzhushou.com/v1d1/";
|
||||
public static final String COMMENT_HOST = "http://comment.ghzhushou.com/v1d1/";
|
||||
public static final String HOST = "http://dev.api2.ghzhushou.com/v2d5/";
|
||||
public static final String USER_HOST = "http://dev.user2.ghzhushou.com/v1d2/";
|
||||
public static final String COMMENT_HOST = "http://dev.comment2.ghzhushou.com/v1d2/";
|
||||
public static final String DATA_HOST = "http://data.ghzhushou.com/";
|
||||
public static final String LIBAO_HOST = "http://libao.ghzhushou.com/v1d0/";
|
||||
public static final String LIBAO_HOST = "http://dev.libao2.ghzhushou.com/v1d2/";
|
||||
public static final String PREFERENCE = "ghzhushou";
|
||||
|
||||
public static boolean isShow(Context context) {
|
||||
|
||||
@ -22,5 +22,7 @@ public class ItemViewType {
|
||||
public static final int LOADING = 14; // 加载布局
|
||||
public static final int LIBAO_NORMAL = 15; // 礼包正常布局
|
||||
public static final int LIBAO_SKIP_CONCERN = 16; // 跳转关注管理页面布局
|
||||
public static final int KC_HINT = 16;
|
||||
public static final int ZIXUNTOP_TOP = 7; // 有料顶部布局
|
||||
|
||||
}
|
||||
|
||||
@ -2,7 +2,10 @@ package com.gh.common.util;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.ExifInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -84,4 +87,30 @@ public class BitmapUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drawable转Bitmap
|
||||
*
|
||||
*/
|
||||
public static Bitmap drawableToBitmap(Drawable drawable){
|
||||
if(drawable == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
// 取 drawable 的长宽
|
||||
int w = drawable.getIntrinsicWidth();
|
||||
int h = drawable.getIntrinsicHeight();
|
||||
// 取 drawable 的颜色格式
|
||||
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
|
||||
: Bitmap.Config.RGB_565;
|
||||
//建立对应的Bitmap
|
||||
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
|
||||
// 建立对应 bitmap 的画布
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, w, h);
|
||||
// 把 drawable 内容画到画布中
|
||||
drawable.draw(canvas);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
206
app/src/main/java/com/gh/common/util/CommentUtils.java
Normal file
206
app/src/main/java/com/gh/common/util/CommentUtils.java
Normal file
@ -0,0 +1,206 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.gamecenter.CommentDetailActivity;
|
||||
import com.gh.gamecenter.MessageDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.MessageDetailAdapter;
|
||||
import com.gh.gamecenter.db.CommentDao;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/22.
|
||||
*/
|
||||
public class CommentUtils {
|
||||
|
||||
public static void setCommentTime(TextView textView, long time) {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
|
||||
try {
|
||||
long today = format.parse(format.format(new Date())).getTime();
|
||||
long day = time * 1000;
|
||||
if (day >= today && day < today + 86400 * 1000) {
|
||||
long min = new Date().getTime()/1000 - day/1000;
|
||||
int hour = (int) (min/ (60 * 60));
|
||||
if (hour == 0) {
|
||||
if (min < 60) {
|
||||
textView.setText("刚刚");
|
||||
} else {
|
||||
textView.setText(String.format(Locale.getDefault(), "%d分钟前", (int) (min / 60)));
|
||||
}
|
||||
} else {
|
||||
textView.setText(String.format(Locale.getDefault(), "%d小时前", hour));
|
||||
}
|
||||
} else if (day >= today - 86400 * 1000 && day < today) {
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText("昨天 ");
|
||||
} else {
|
||||
format.applyPattern("yyyy-MM-dd");
|
||||
textView.setText(format.format(day));
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
format.applyPattern("yyyy-MM-dd");
|
||||
textView.setText(format.format(time * 1000));
|
||||
}
|
||||
}
|
||||
|
||||
public static void showReportDialog(final CommentEntity commentEntity, final Context mContext
|
||||
, final MessageDetailAdapter.OnCommentCallBackListener mCallBackListener, final String newsId) {
|
||||
|
||||
CommentDao commentDao = new CommentDao(mContext);
|
||||
|
||||
final Dialog dialog = new Dialog(mContext);
|
||||
|
||||
LinearLayout container = new LinearLayout(mContext);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setBackgroundColor(Color.WHITE);
|
||||
container.setPadding(0, DisplayUtils.dip2px(mContext, 12), 0, DisplayUtils.dip2px(mContext, 12));
|
||||
|
||||
List<String> dialogType = new ArrayList<>();
|
||||
|
||||
if (!commentDao.isMyComment(commentEntity.getId())) {
|
||||
dialogType.add("回复");
|
||||
}
|
||||
|
||||
dialogType.add("复制");
|
||||
dialogType.add("举报");
|
||||
|
||||
if (commentEntity.getParent() != null) {
|
||||
dialogType.add("查看对话");
|
||||
}
|
||||
|
||||
for (String s : dialogType) {
|
||||
final TextView reportTv = new TextView(mContext);
|
||||
reportTv.setPadding(DisplayUtils.dip2px(mContext, 20), DisplayUtils.dip2px(mContext, 12),
|
||||
0, DisplayUtils.dip2px(mContext, 12));
|
||||
reportTv.setText(s);
|
||||
reportTv.setTextSize(17);
|
||||
reportTv.setTextColor(mContext.getResources().getColor(R.color.title));
|
||||
reportTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
int widthPixels = mContext.getResources().getDisplayMetrics().widthPixels;
|
||||
reportTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9)/10,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
container.addView(reportTv);
|
||||
|
||||
reportTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
switch (reportTv.getText().toString()) {
|
||||
case "回复":
|
||||
if (mCallBackListener != null) {
|
||||
mCallBackListener.showSoftInput(commentEntity);
|
||||
} else if (!TextUtils.isEmpty(newsId)){
|
||||
Intent intent = new Intent(mContext, MessageDetailActivity.class);
|
||||
AppController.put("CommentEntity", commentEntity);
|
||||
intent.putExtra("commentNum", -1);
|
||||
intent.putExtra("newsId", newsId);
|
||||
intent.putExtra("openSoftInput", true);
|
||||
mContext.startActivity(intent);
|
||||
} else {
|
||||
Utils.toast(mContext, "缺少关键属性");
|
||||
}
|
||||
|
||||
break;
|
||||
case "复制":
|
||||
LibaoUtils.copyLink(commentEntity.getContent(), mContext);
|
||||
break;
|
||||
case "举报":
|
||||
showReportTypeDialog(commentEntity, mContext);
|
||||
break;
|
||||
case "查看对话":
|
||||
Intent intent = new Intent(mContext, CommentDetailActivity.class);
|
||||
intent.putExtra("commentId", commentEntity.getId());
|
||||
mContext.startActivity(intent);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(container);
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
private static void showReportTypeDialog(final CommentEntity commentEntity, final Context mContext) {
|
||||
final String[] arrReportType = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息",
|
||||
"违法有害信息", "其它"};
|
||||
int widthPixels = mContext.getResources().getDisplayMetrics().widthPixels;
|
||||
|
||||
final Dialog reportTypeDialog = new Dialog(mContext);
|
||||
LinearLayout container = new LinearLayout(mContext);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setPadding(0, DisplayUtils.dip2px(mContext, 12), 0, DisplayUtils.dip2px(mContext, 12));
|
||||
container.setBackgroundColor(Color.WHITE);
|
||||
|
||||
for (final String s : arrReportType) {
|
||||
TextView reportTypeTv = new TextView(mContext);
|
||||
reportTypeTv.setText(s);
|
||||
reportTypeTv.setTextSize(17);
|
||||
reportTypeTv.setTextColor(mContext.getResources().getColor(R.color.title));
|
||||
reportTypeTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
reportTypeTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9)/10,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
reportTypeTv.setPadding(DisplayUtils.dip2px(mContext, 20), DisplayUtils.dip2px(mContext, 12),
|
||||
0, DisplayUtils.dip2px(mContext, 12));
|
||||
container.addView(reportTypeTv);
|
||||
|
||||
reportTypeTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("comment_id", commentEntity.getId());
|
||||
jsonObject.put("reason", s);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
PostCommentUtils.addReportData(mContext, jsonObject.toString(), true,
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSucced(JSONObject response) {
|
||||
Utils.toast(mContext, "感谢您的举报");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable error) {
|
||||
Utils.toast(mContext, "举报失败,请检查网络设置");
|
||||
}
|
||||
});
|
||||
reportTypeDialog.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
reportTypeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
reportTypeDialog.setContentView(container);
|
||||
reportTypeDialog.show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -2,14 +2,17 @@ package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
@ -59,7 +62,19 @@ public class ConcernUtils {
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
.subscribe(new Response<ResponseBody>(){
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
super.onResponse(response);
|
||||
EventBus.getDefault().post(new EBReuse("UpdateConcernSuccess"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
EventBus.getDefault().post(new EBReuse("UpdateConcernFailure"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -133,15 +133,37 @@ public class DataCollectionUtils {
|
||||
|
||||
// 上传搜索数据
|
||||
public static void uploadSearch(Context context, String... args) {
|
||||
if (args.length < 2) {
|
||||
if (args.length != 5) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("from", args[2]);
|
||||
map.put("search_type", args[1]);
|
||||
map.put("key", args[0]);
|
||||
map.put("from", args[1]);
|
||||
if (args.length == 3) {
|
||||
map.put("click", args[2]);
|
||||
map.put("game_id", args[3]);
|
||||
map.put("game_name", args[4]);
|
||||
map.put("netword", NetworkUtils.getConnectedType(context));
|
||||
map.put("type", "search");
|
||||
map.put("device_type", android.os.Build.MODEL);
|
||||
map.put("device_system", android.os.Build.VERSION.SDK_INT + "=" + android.os.Build.VERSION.RELEASE);
|
||||
DataCollectionManager.onEvent(context, "search", map);
|
||||
}
|
||||
|
||||
// 上传搜索点击数据
|
||||
public static void uploadSearchClick(Context context, String... args) {
|
||||
if (args.length != 5) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("from", args[2]);
|
||||
map.put("search_type", args[1]);
|
||||
map.put("key", args[0]);
|
||||
map.put("game_id", args[3]);
|
||||
map.put("game_name", args[4]);
|
||||
map.put("netword", NetworkUtils.getConnectedType(context));
|
||||
map.put("type", "click");
|
||||
map.put("device_type", android.os.Build.MODEL);
|
||||
map.put("device_system", android.os.Build.VERSION.SDK_INT + "=" + android.os.Build.VERSION.RELEASE);
|
||||
DataCollectionManager.onEvent(context, "search", map);
|
||||
}
|
||||
|
||||
@ -157,4 +179,16 @@ public class DataCollectionUtils {
|
||||
DataCollectionManager.onEvent(context, "concern", map);
|
||||
}
|
||||
|
||||
//上传推荐位数据
|
||||
public static void uploadPosition(Context context, String... args) {
|
||||
if (args.length < 3) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("page", args[0]);
|
||||
map.put("location", args[1]);
|
||||
map.put("name", args[2]);
|
||||
DataCollectionManager.onEvent(context, "position", map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,20 +1,38 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class DialogUtils {
|
||||
|
||||
@ -32,6 +50,168 @@ public class DialogUtils {
|
||||
|
||||
private static boolean isShow = false;
|
||||
|
||||
// 快传成绩单
|
||||
public static void showKuaiChuanResult(final Activity activity, Handler handler, int requestCode, final String picName) {
|
||||
|
||||
AppController.remove("FileInfo");
|
||||
|
||||
List<Map<String, String>> mapList = (List<Map<String, String>>) AppController.get("sendData", true);
|
||||
if (mapList == null || mapList.size() == 0) return;
|
||||
|
||||
WifiMgr.getInstance(activity).disconnectCurrentNetwork(); // 断开当前WiFi
|
||||
|
||||
// int heightPixels = getContext().getResources().getDisplayMetrics().heightPixels;
|
||||
// int widthPixels = getContext().getResources().getDisplayMetrics().widthPixels;
|
||||
|
||||
int filesCount = mapList.size();
|
||||
int filesSize = 0;
|
||||
int sendTime = 0;
|
||||
|
||||
View view = View.inflate(activity
|
||||
, R.layout.dialog_kuaichuan, null);
|
||||
final LinearLayout mShareLl = (LinearLayout) view.findViewById(R.id.kuaichuan_dialog_ll);
|
||||
final LinearLayout mShareBottomLl = (LinearLayout) view.findViewById(R.id.kuaichuan_dialog_share_rl);
|
||||
RelativeLayout content = (RelativeLayout) view.findViewById(R.id.kuaichuan_dialog);
|
||||
LinearLayout shareIconLl = (LinearLayout) view.findViewById(R.id.kuaichuan_icon_ll);
|
||||
ImageView qrCode = (ImageView) view.findViewById(R.id.kuaichuan_qrcode);
|
||||
TextView dateTv = (TextView) view.findViewById(R.id.kuaichuan_dialog_date);
|
||||
TextView countTv = (TextView) view.findViewById(R.id.kuaichuan_send_count);
|
||||
TextView sizeTv = (TextView) view.findViewById(R.id.kuaichuan_send_size);
|
||||
TextView speedTv = (TextView) view.findViewById(R.id.kuaichuan_send_speed);
|
||||
TextView timeCount = (TextView) view.findViewById(R.id.kuaichuan_time_count);
|
||||
TextView timeTv = (TextView) view.findViewById(R.id.kuaichuan_time_tv);
|
||||
TextView sendCountTv = (TextView) view.findViewById(R.id.dialog_send_tv);
|
||||
ImageView closeIv = (ImageView) view.findViewById(R.id.kuaichuan_dialog_colse);
|
||||
// content.setLayoutParams(new LinearLayout.LayoutParams((int)(((float)heightPixels)*0.85), (int)((float)widthPixels*0.81)));
|
||||
|
||||
final Dialog dialog = new Dialog(activity);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
Window dialogWindow = dialog.getWindow();
|
||||
WindowManager m = activity.getWindowManager();
|
||||
Display d = m.getDefaultDisplay();
|
||||
WindowManager.LayoutParams p = dialogWindow.getAttributes();
|
||||
p.height = (int) (d.getHeight() * 0.82);
|
||||
p.width = (int) (d.getWidth() * 0.80);
|
||||
dialogWindow.setAttributes(p);
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日", Locale.getDefault());
|
||||
dateTv.setText(format.format(new Date().getTime()));
|
||||
|
||||
for (Map<String, String> map : mapList) {
|
||||
int size = Integer.parseInt(map.get("apkSize"));
|
||||
int time = 10;
|
||||
try {
|
||||
time = Integer.parseInt(map.get("sendTime"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String apkPath = map.get("apkPath");
|
||||
filesSize = filesSize + size;
|
||||
sendTime = sendTime + time;
|
||||
|
||||
if (shareIconLl.getChildCount() >= 5) continue;
|
||||
|
||||
android.content.pm.PackageManager pm = activity.getPackageManager();
|
||||
PackageInfo info = pm.getPackageArchiveInfo(apkPath,
|
||||
android.content.pm.PackageManager.GET_ACTIVITIES);
|
||||
if (info != null) {
|
||||
ApplicationInfo appInfo = info.applicationInfo;
|
||||
appInfo.sourceDir = apkPath;
|
||||
appInfo.publicSourceDir = apkPath;
|
||||
Bitmap bitmap = BitmapUtils.drawableToBitmap(appInfo.loadIcon(pm));
|
||||
|
||||
ImageView imageView = new ImageView(activity);
|
||||
imageView.setLayoutParams(new LinearLayout.LayoutParams(DisplayUtils.dip2px(activity, 25)
|
||||
, DisplayUtils.dip2px(activity, 24)));
|
||||
imageView.setImageBitmap(bitmap);
|
||||
shareIconLl.addView(imageView);
|
||||
}
|
||||
}
|
||||
|
||||
if (requestCode == 0x170) { // 发送
|
||||
qrCode.setImageResource(R.drawable.kc_qrcode_120);
|
||||
sendCountTv.setText("成功传送游戏");
|
||||
} else {
|
||||
qrCode.setImageResource(R.drawable.kc_qrcode_110);
|
||||
sendCountTv.setText("成功接收游戏");
|
||||
}
|
||||
|
||||
double size = (((float)filesSize/1024)/1024);
|
||||
String sizeName;
|
||||
if (size > 1024) {
|
||||
DecimalFormat df = new DecimalFormat("#.0");
|
||||
sizeName = df.format(size/1024) + "GB";
|
||||
} else {
|
||||
DecimalFormat df = new DecimalFormat("#.0");
|
||||
sizeName = df.format(size) + "MB";
|
||||
}
|
||||
|
||||
|
||||
int i = (filesSize / 1024) / (sendTime / 1000);
|
||||
String speed ;
|
||||
if (i >= 1000) {
|
||||
float mSpeed = i / 1024f;
|
||||
DecimalFormat df = new DecimalFormat("#.0");
|
||||
String str = df.format(mSpeed);
|
||||
if (str.length() > 4) {
|
||||
str = str.substring(0, 4);
|
||||
}
|
||||
speed = str + "MB/s";
|
||||
} else {
|
||||
speed = i + "KB/s";
|
||||
}
|
||||
|
||||
if (sendTime > 60000) {
|
||||
timeCount.setText(String.valueOf(sendTime/1000/60));
|
||||
timeTv.setText("分钟传送完成");
|
||||
} else {
|
||||
timeCount.setText(String.valueOf(sendTime/1000));
|
||||
timeTv.setText("秒传送完成");
|
||||
}
|
||||
|
||||
sizeTv.setText(sizeName);
|
||||
speedTv.setText(speed);
|
||||
countTv.setText(filesCount + "个");
|
||||
|
||||
// 延迟操作,等待截图部分绘制完成
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mShareLl.setDrawingCacheEnabled(true);
|
||||
mShareLl.buildDrawingCache();
|
||||
Bitmap drawingCache = mShareLl.getDrawingCache();
|
||||
saveBitmap(drawingCache, activity, picName);
|
||||
MessageShareUtils.getInstance(activity).showShareWindows(mShareBottomLl, drawingCache, picName, 2);
|
||||
mShareBottomLl.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}, 200);
|
||||
|
||||
closeIv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void saveBitmap(Bitmap bm, Activity activity, String picName) {
|
||||
File file = new File(activity.getExternalCacheDir().getPath() + "/ShareImg");
|
||||
if (!file.isDirectory()) {
|
||||
file.delete();
|
||||
file.mkdirs();
|
||||
}
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
MessageShareUtils.getInstance(activity).writeBitmap(file.getPath(), picName, bm, false);
|
||||
|
||||
}
|
||||
|
||||
public static void showWarningDialog(Context context, String title, CharSequence msg, String cancel, String confirm,
|
||||
final ConfiremListener cmListener, final CancelListener clListener) {
|
||||
|
||||
@ -169,6 +349,8 @@ public class DialogUtils {
|
||||
|
||||
TextView hintdialog_confirm = (TextView) view.findViewById(R.id.hintdialog_confirm);
|
||||
|
||||
hintdialog_confirm.setText(confirm);
|
||||
|
||||
hintdialog_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@ -9,8 +9,6 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -22,6 +20,7 @@ import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameViewHolder;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
@ -87,14 +86,7 @@ public class DownloadItemUtils {
|
||||
}
|
||||
|
||||
// 更新正常的条目,只有一个apk包
|
||||
public static void updateNormalItem(Context context,
|
||||
TextView textView,
|
||||
ProgressBar game_progressbar,
|
||||
LinearLayout game_ll_info,
|
||||
TextView download_speed,
|
||||
TextView download_percentage,
|
||||
TextView downloadBtn,
|
||||
GameEntity gameEntity,
|
||||
public static void updateNormalItem(Context context, GameViewHolder holder, GameEntity gameEntity,
|
||||
boolean isShowPlatform) {
|
||||
|
||||
ArrayMap<String, DownloadEntity> entryMap = gameEntity.getEntryMap();
|
||||
@ -102,71 +94,63 @@ public class DownloadItemUtils {
|
||||
DownloadEntity downloadEntity = entryMap.get(gameEntity.getApk().get(0).getPlatform());
|
||||
if (downloadEntity != null) {
|
||||
// 更改进度条和提示文本的状态
|
||||
changeStatus(context, textView, game_progressbar, game_ll_info, download_speed, download_percentage, downloadBtn,
|
||||
downloadEntity, isShowPlatform, true);
|
||||
changeStatus(context, holder, downloadEntity, isShowPlatform, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
holder.gameDes.setVisibility(View.VISIBLE);
|
||||
holder.gameProgressbar.setVisibility(View.GONE);
|
||||
holder.gameInfo.setVisibility(View.GONE);
|
||||
|
||||
downloadBtn.setTextColor(Color.WHITE);
|
||||
holder.gameDownloadBtn.setTextColor(Color.WHITE);
|
||||
if (gameEntity.isPluggable()) {
|
||||
downloadBtn.setText("插件化");
|
||||
holder.gameDownloadBtn.setText("插件化");
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(context).getByPackage(
|
||||
gameEntity.getApk().get(0).getPackageName());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getUrl().equals(gameEntity.getApk().get(0).getUrl())) {
|
||||
downloadBtn.setClickable(true);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
holder.gameDownloadBtn.setClickable(true);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
downloadBtn.setClickable(false);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_up);
|
||||
holder.gameDownloadBtn.setClickable(false);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_up);
|
||||
}
|
||||
} else if (PackageManager.isInstalled(gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (PackageManager.isCanUpdate(gameEntity.getId(), gameEntity.getApk().get(0).getPackageName())) {
|
||||
downloadBtn.setText("更新");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
holder.gameDownloadBtn.setText("更新");
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
} else {
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(gameEntity.getApk().get(0).getGhVersion())
|
||||
&& !PackageUtils.isSignature(context, gameEntity.getApk().get(0).getPackageName())) {
|
||||
downloadBtn.setText("插件化");
|
||||
holder.gameDownloadBtn.setText("插件化");
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(context).getByPackage(
|
||||
gameEntity.getApk().get(0).getPackageName());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getUrl().equals(gameEntity.getApk().get(0).getUrl())) {
|
||||
downloadBtn.setClickable(true);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
holder.gameDownloadBtn.setClickable(true);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
downloadBtn.setClickable(false);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_up);
|
||||
holder.gameDownloadBtn.setClickable(false);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_up);
|
||||
}
|
||||
} else {
|
||||
downloadBtn.setText("启动");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
holder.gameDownloadBtn.setText("启动");
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
downloadBtn.setText("下载");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
holder.gameDownloadBtn.setText("下载");
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新插件的条目,有多个apk包
|
||||
public static void updatePluginItem(Context context,
|
||||
TextView textView,
|
||||
ProgressBar game_progressbar,
|
||||
LinearLayout game_ll_info,
|
||||
TextView download_speed,
|
||||
TextView download_percentage,
|
||||
TextView downloadBtn,
|
||||
GameEntity gameEntity,
|
||||
public static void updatePluginItem(Context context, GameViewHolder holder, GameEntity gameEntity,
|
||||
boolean isShowPlatform) {
|
||||
|
||||
GameUtils.setDownloadBtnStatus(context, gameEntity, downloadBtn);
|
||||
GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn);
|
||||
|
||||
ArrayMap<String, DownloadEntity> entryMap = gameEntity.getEntryMap();
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
@ -182,31 +166,22 @@ public class DownloadItemUtils {
|
||||
|
||||
if (downloadEntity != null) {
|
||||
// 更改进度条和提示文本的状态
|
||||
changeStatus(context, textView, game_progressbar, game_ll_info, download_speed,
|
||||
download_percentage, downloadBtn, downloadEntity, isShowPlatform, false);
|
||||
changeStatus(context, holder, downloadEntity, isShowPlatform, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
holder.gameDes.setVisibility(View.VISIBLE);
|
||||
holder.gameProgressbar.setVisibility(View.GONE);
|
||||
holder.gameInfo.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// 更改进度条和提示文本的状态
|
||||
public static void changeStatus(Context context,
|
||||
TextView textView,
|
||||
ProgressBar game_progressbar,
|
||||
LinearLayout game_ll_info,
|
||||
TextView download_speed,
|
||||
TextView download_percentage,
|
||||
TextView downloadBtn,
|
||||
DownloadEntity downloadEntity,
|
||||
boolean isShowPlatform,
|
||||
boolean isNormal) {
|
||||
textView.setVisibility(View.GONE);
|
||||
game_progressbar.setVisibility(View.VISIBLE);
|
||||
game_ll_info.setVisibility(View.VISIBLE);
|
||||
public static void changeStatus(Context context, GameViewHolder holder, DownloadEntity downloadEntity,
|
||||
boolean isShowPlatform, boolean isNormal) {
|
||||
holder.gameDes.setVisibility(View.GONE);
|
||||
holder.gameProgressbar.setVisibility(View.VISIBLE);
|
||||
holder.gameInfo.setVisibility(View.VISIBLE);
|
||||
|
||||
String platform = PlatformUtils.getInstance(context)
|
||||
.getPlatformName(downloadEntity.getPlatform());
|
||||
@ -214,213 +189,191 @@ public class DownloadItemUtils {
|
||||
DownloadStatus status = downloadEntity.getStatus();
|
||||
if (status.equals(DownloadStatus.downloading)) {
|
||||
if (!"pause".equals(DownloadManager.getInstance(context).getStatus(downloadEntity.getUrl()))) {
|
||||
game_progressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
holder.gameProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
if (isShowPlatform && platform != null) {
|
||||
download_speed.setText(String.format("%s - %s(剩%s)", platform,
|
||||
holder.gameDownloadSpeed.setText(String.format("%s - %s(剩%s)", platform,
|
||||
SpeedUtils.getSpeed(downloadEntity.getSpeed()),
|
||||
SpeedUtils.getRemainTime(downloadEntity.getSize(), downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
|
||||
} else {
|
||||
download_speed.setText(String.format("%s(剩%s)", SpeedUtils.getSpeed(downloadEntity.getSpeed()),
|
||||
holder.gameDownloadSpeed.setText(String.format("%s(剩%s)", SpeedUtils.getSpeed(downloadEntity.getSpeed()),
|
||||
SpeedUtils.getRemainTime(downloadEntity.getSize(), downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
|
||||
}
|
||||
download_percentage.setText(downloadEntity.getPercent() + "%");
|
||||
holder.gameDownloadPercentage.setText(downloadEntity.getPercent() + "%");
|
||||
}
|
||||
|
||||
if (isNormal) {
|
||||
downloadBtn.setText("下载中");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
downloadBtn.setTextColor(context.getResources().getColorStateList(R.color.text_downloading_style));
|
||||
holder.gameDownloadBtn.setText("下载中");
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
holder.gameDownloadBtn.setTextColor(context.getResources().getColorStateList(R.color.text_downloading_style));
|
||||
}
|
||||
} else if (status.equals(DownloadStatus.waiting)) {
|
||||
game_progressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
holder.gameProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
if (isShowPlatform && platform != null) {
|
||||
download_speed.setText(String.format("%s - 等待", platform));
|
||||
holder.gameDownloadSpeed.setText(String.format("%s - 等待", platform));
|
||||
} else {
|
||||
download_speed.setText("等待");
|
||||
holder.gameDownloadSpeed.setText("等待");
|
||||
}
|
||||
download_percentage.setText(downloadEntity.getPercent() + "%");
|
||||
holder.gameDownloadPercentage.setText(downloadEntity.getPercent() + "%");
|
||||
|
||||
if (isNormal) {
|
||||
downloadBtn.setText("下载中");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
downloadBtn.setTextColor(context.getResources().getColorStateList(R.color.text_downloading_style));
|
||||
holder.gameDownloadBtn.setText("下载中");
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
holder.gameDownloadBtn.setTextColor(context.getResources().getColorStateList(R.color.text_downloading_style));
|
||||
}
|
||||
} else if (status.equals(DownloadStatus.pause)
|
||||
|| status.equals(DownloadStatus.timeout)
|
||||
|| status.equals(DownloadStatus.neterror)) {
|
||||
game_progressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
holder.gameProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
if (isShowPlatform && platform != null) {
|
||||
download_speed.setText(String.format("%s - 暂停", platform));
|
||||
holder.gameDownloadSpeed.setText(String.format("%s - 暂停", platform));
|
||||
} else {
|
||||
download_speed.setText("暂停");
|
||||
holder.gameDownloadSpeed.setText("暂停");
|
||||
}
|
||||
download_percentage.setText(downloadEntity.getPercent() + "%");
|
||||
holder.gameDownloadPercentage.setText(downloadEntity.getPercent() + "%");
|
||||
|
||||
if (isNormal) {
|
||||
downloadBtn.setText("下载中");
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
downloadBtn.setTextColor(context.getResources().getColorStateList(R.color.text_downloading_style));
|
||||
holder.gameDownloadBtn.setText("下载中");
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
holder.gameDownloadBtn.setTextColor(context.getResources().getColorStateList(R.color.text_downloading_style));
|
||||
}
|
||||
} else if (status.equals(DownloadStatus.done)) {
|
||||
game_progressbar.setProgress(1000);
|
||||
holder.gameProgressbar.setProgress(1000);
|
||||
if (isShowPlatform && platform != null) {
|
||||
download_speed.setText(String.format("%s - 下载完成", platform));
|
||||
holder.gameDownloadSpeed.setText(String.format("%s - 下载完成", platform));
|
||||
} else {
|
||||
download_speed.setText("下载完成");
|
||||
holder.gameDownloadSpeed.setText("下载完成");
|
||||
}
|
||||
download_percentage.setText(R.string.hundred_percent);
|
||||
holder.gameDownloadPercentage.setText(R.string.hundred_percent);
|
||||
|
||||
if (isNormal) {
|
||||
downloadBtn.setText("安装");
|
||||
downloadBtn.setTextColor(Color.WHITE);
|
||||
holder.gameDownloadBtn.setText("安装");
|
||||
holder.gameDownloadBtn.setTextColor(Color.WHITE);
|
||||
if (downloadEntity.isPluggable()
|
||||
&& PackageManager.isInstalled(downloadEntity.getPackageName())) {
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateItem(Context context,
|
||||
TextView textView,
|
||||
ProgressBar game_progressbar,
|
||||
LinearLayout game_ll_info,
|
||||
TextView download_speed,
|
||||
TextView download_percentage,
|
||||
TextView downloadBtn,
|
||||
GameEntity entity,
|
||||
boolean isShowPlatform) {
|
||||
public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform) {
|
||||
|
||||
// 控制是否显示下载按钮
|
||||
if (!Config.isShow(context) || "光环助手".equals(entity.getName())) {
|
||||
downloadBtn.setVisibility(View.GONE);
|
||||
if (!Config.isShow(context) || "光环助手".equals(gameEntity.getName())) {
|
||||
holder.gameDownloadBtn.setVisibility(View.GONE);
|
||||
} else {
|
||||
downloadBtn.setVisibility(View.VISIBLE);
|
||||
holder.gameDownloadBtn.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (entity.getApk() == null || entity.getApk().isEmpty()) {
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
downloadBtn.setText("暂无");
|
||||
downloadBtn.setClickable(false);
|
||||
} else if (entity.getApk().size() == 1) {
|
||||
updateNormalItem(context, textView, game_progressbar, game_ll_info, download_speed,
|
||||
download_percentage, downloadBtn, entity, isShowPlatform);
|
||||
if (gameEntity.isLibaoExists()) {
|
||||
holder.gameLibaoIcon.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
updatePluginItem(context, textView, game_progressbar, game_ll_info, download_speed,
|
||||
download_percentage, downloadBtn, entity, isShowPlatform);
|
||||
holder.gameLibaoIcon.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// LibaoDao libaoDao = new LibaoDao(context);
|
||||
// if (libaoDao.isExist(gameEntity.getId())) {
|
||||
// holder.gameLibaoIcon.setVisibility(View.VISIBLE);
|
||||
// } else {
|
||||
//
|
||||
// }
|
||||
|
||||
if (gameEntity.getApk() == null || gameEntity.getApk().isEmpty()) {
|
||||
holder.gameDes.setVisibility(View.VISIBLE);
|
||||
holder.gameProgressbar.setVisibility(View.GONE);
|
||||
holder.gameInfo.setVisibility(View.GONE);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
holder.gameDownloadBtn.setText("暂无");
|
||||
holder.gameDownloadBtn.setClickable(false);
|
||||
} else if (gameEntity.getApk().size() == 1) {
|
||||
updateNormalItem(context, holder, gameEntity, isShowPlatform);
|
||||
} else {
|
||||
updatePluginItem(context, holder, gameEntity, isShowPlatform);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void updateItem(Context context,
|
||||
TextView textView,
|
||||
ProgressBar game_progressbar,
|
||||
LinearLayout game_ll_info,
|
||||
TextView download_speed,
|
||||
TextView download_percentage,
|
||||
TextView downloadBtn,
|
||||
GameEntity entity) {
|
||||
updateItem(context, textView, game_progressbar, game_ll_info, download_speed,
|
||||
download_percentage, downloadBtn, entity, true);
|
||||
}
|
||||
public static void onNormalClick(final Context context,
|
||||
final TextView downloadBtn,
|
||||
final GameEntity gameEntity,
|
||||
final int position,
|
||||
final RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
|
||||
final String entrance,
|
||||
final String location) {
|
||||
|
||||
private static void setNormalOnClickListener(final Context context,
|
||||
final TextView downloadBtn,
|
||||
final GameEntity gameEntity,
|
||||
final int position,
|
||||
final RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
|
||||
final String entrance,
|
||||
final String location) {
|
||||
downloadBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String str = downloadBtn.getText().toString();
|
||||
if ("下载".equals(str)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
String str = downloadBtn.getText().toString();
|
||||
if ("下载".equals(str)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
download(context, gameEntity, downloadBtn, entrance, location);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
download(context, gameEntity, downloadBtn, entrance, location);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
download(context, gameEntity, downloadBtn, entrance, location);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if ("插件化".equals(str)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
});
|
||||
}
|
||||
} else if ("插件化".equals(str)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
plugin(context, gameEntity, downloadBtn, entrance, location);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
plugin(context, gameEntity, downloadBtn, entrance, location);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
plugin(context, gameEntity, downloadBtn, entrance, location);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if ("安装".equals(str)) {
|
||||
install(context, gameEntity, position, adapter);
|
||||
} else if ("启动".equals(str)) {
|
||||
DataUtils.onGameLaunchEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), location);
|
||||
});
|
||||
}
|
||||
} else if ("安装".equals(str)) {
|
||||
install(context, gameEntity, position, adapter);
|
||||
} else if ("启动".equals(str)) {
|
||||
DataUtils.onGameLaunchEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), location);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(context, gameEntity.getApk().get(0).getPackageName());
|
||||
} else if ("下载中".equals(str)) {
|
||||
Intent intent = new Intent(context, DownloadManagerActivity.class);
|
||||
intent.putExtra("url", gameEntity.getApk().get(0).getUrl());
|
||||
intent.putExtra("entrance", entrance + "+(" + location.split(":")[0] + ")");
|
||||
context.startActivity(intent);
|
||||
} else if ("更新".equals(str)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
PackageUtils.launchApplicationByPackageName(context, gameEntity.getApk().get(0).getPackageName());
|
||||
} else if ("下载中".equals(str)) {
|
||||
Intent intent = new Intent(context, DownloadManagerActivity.class);
|
||||
intent.putExtra("currentItem", 1);
|
||||
intent.putExtra("url", gameEntity.getApk().get(0).getUrl());
|
||||
intent.putExtra("entrance", entrance + "+(" + location.split(":")[0] + ")");
|
||||
context.startActivity(intent);
|
||||
} else if ("更新".equals(str)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
update(context, gameEntity, entrance, location);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
update(context, gameEntity, entrance, location);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
update(context, gameEntity, entrance, location);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void setPluginOnClickListener(final Context context,
|
||||
final TextView downloadBtn,
|
||||
final GameEntity entity,
|
||||
final String entrance,
|
||||
final String location,
|
||||
final boolean isCloseSoftInput) {
|
||||
downloadBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
if (isCloseSoftInput) {
|
||||
InputMethodManager imm = (InputMethodManager) context
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
}
|
||||
DownloadDialog.getInstance(context).showPopupWindow(v, entity, entrance, location);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setOnClickListener(Context context,
|
||||
TextView downloadBtn,
|
||||
GameEntity gameEntity,
|
||||
int position,
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
|
||||
String entrance,
|
||||
String location,
|
||||
boolean isCloseSoftInput) {
|
||||
public static void setOnClickListener(final Context context,
|
||||
final TextView downloadBtn,
|
||||
final GameEntity gameEntity,
|
||||
final int position,
|
||||
final RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
|
||||
final String entrance,
|
||||
final String location) {
|
||||
|
||||
if (gameEntity.getApk().size() == 1) {
|
||||
setNormalOnClickListener(context, downloadBtn, gameEntity, position, adapter, entrance, location);
|
||||
downloadBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onNormalClick(context, downloadBtn, gameEntity, position, adapter, entrance, location);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setPluginOnClickListener(context, downloadBtn, gameEntity, entrance, location, isCloseSoftInput);
|
||||
downloadBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DownloadDialog.getInstance(context).showPopupWindow(v, gameEntity, entrance, location);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
@ -31,17 +34,24 @@ public class GameViewUtils {
|
||||
if (tag == null || tag.isEmpty()) {
|
||||
labelLayout.addView(getGameTagView(context, "官方版", 0));
|
||||
} else {
|
||||
for (int i = 0, size = tag.size() > 3 ? 3 : tag.size(); i < size; i++) {
|
||||
for (int i = 0, size = tag.size(); i < size; i++) {
|
||||
View view;
|
||||
if (i == size - 1) {
|
||||
labelLayout.addView(getGameTagView(context, tag.get(i), 0));
|
||||
view = getGameTagView(context, tag.get(i), 0);
|
||||
} else {
|
||||
labelLayout.addView(getGameTagView(context, tag.get(i), DisplayUtils.dip2px(context, 5)));
|
||||
view = getGameTagView(context, tag.get(i), DisplayUtils.dip2px(context, 6));
|
||||
}
|
||||
if (view != null) {
|
||||
labelLayout.addView(view);
|
||||
}
|
||||
if (labelLayout.getChildCount() == 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TextView getGameTagView(Context context, String tagStr, int rightMargin) {
|
||||
private static TextView getGameTagView(Context context, String tagStr, int rightMargin) {
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
lparams.rightMargin = rightMargin;
|
||||
@ -53,8 +63,17 @@ public class GameViewUtils {
|
||||
tag.setBackgroundResource(R.drawable.border_green_bg);
|
||||
tag.setTextColor(context.getResources().getColor(R.color.tag_green));
|
||||
} else {
|
||||
tag.setBackgroundResource(R.drawable.border_blue_bg);
|
||||
tag.setTextColor(context.getResources().getColor(R.color.theme));
|
||||
String colorStr = TagUtils.getInstance(context).getColor(tagStr);
|
||||
if (colorStr == null) {
|
||||
return null;
|
||||
}
|
||||
int color = Color.parseColor(colorStr);
|
||||
GradientDrawable gradientDrawable = new GradientDrawable();
|
||||
gradientDrawable.setColor(Color.TRANSPARENT);
|
||||
gradientDrawable.setStroke(DisplayUtils.dip2px(context, 0.6f), color);
|
||||
tag.setBackgroundDrawable(gradientDrawable);
|
||||
// tag.setBackgroundResource(R.drawable.border_blue_bg);
|
||||
tag.setTextColor(color);
|
||||
}
|
||||
tag.setLayoutParams(lparams);
|
||||
tag.setPadding(DisplayUtils.dip2px(context, 3),
|
||||
|
||||
@ -85,7 +85,7 @@ public class HttpsUtils {
|
||||
private static KeyStore getHttpsKeyStore(Context context) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = context.getResources().openRawResource(R.raw.download);
|
||||
is = context.getResources().openRawResource(R.raw.cacert);
|
||||
//读取证书
|
||||
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
|
||||
certificateFactory.generateCertificate(is);
|
||||
@ -111,23 +111,15 @@ public class HttpsUtils {
|
||||
|
||||
public static HttpsURLConnection getHttpsURLConnection(URL url) throws Exception {
|
||||
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
|
||||
if ("apk2.ghzhushou.com".equals(url.getHost())
|
||||
|| "download.ghzhushou.com".equals(url.getHost())) {
|
||||
if (mSSLSocketFactory == null || mHostnameVerifier == null) {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, TRUST_MANAGERS, null);
|
||||
mSSLSocketFactory = sslContext.getSocketFactory();
|
||||
|
||||
mHostnameVerifier = HOSTNAME_VERIFIER;
|
||||
}
|
||||
httpsURLConnection.setSSLSocketFactory(mSSLSocketFactory);
|
||||
httpsURLConnection.setHostnameVerifier(mHostnameVerifier);
|
||||
} else {
|
||||
if (mSSLSocketFactory == null || mHostnameVerifier == null) {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, TRUST_MANAGERS, null);
|
||||
httpsURLConnection.setSSLSocketFactory(sslContext.getSocketFactory());
|
||||
httpsURLConnection.setHostnameVerifier(HOSTNAME_VERIFIER);
|
||||
mSSLSocketFactory = sslContext.getSocketFactory();
|
||||
|
||||
mHostnameVerifier = HOSTNAME_VERIFIER;
|
||||
}
|
||||
httpsURLConnection.setSSLSocketFactory(mSSLSocketFactory);
|
||||
httpsURLConnection.setHostnameVerifier(mHostnameVerifier);
|
||||
return httpsURLConnection;
|
||||
}
|
||||
|
||||
|
||||
@ -36,6 +36,13 @@ public class ImageUtils {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public static void display(SimpleDraweeView simpleDraweeView, String url) {
|
||||
// if (url.startsWith("http://image.ghzhushou.com") && url.endsWith(".jpg")) {
|
||||
// url = url + "?x-oss-process=image/format,webp";
|
||||
// }
|
||||
simpleDraweeView.setImageURI(url);
|
||||
}
|
||||
|
||||
// 自适应图片宽高
|
||||
public void display(final SimpleDraweeView simpleDraweeView, String url, final int width) {
|
||||
ControllerListener<ImageInfo> listener = new BaseControllerListener<ImageInfo>(){
|
||||
@ -66,7 +73,8 @@ public class ImageUtils {
|
||||
.setBackground(new ColorDrawable(resources.getColor(R.color.placeholder_bg)))
|
||||
.setActualImageScaleType(scaleType)
|
||||
.build());
|
||||
simpleDraweeView.setImageURI(url);
|
||||
// simpleDraweeView.setImageURI(url);
|
||||
display(simpleDraweeView, url);
|
||||
}
|
||||
|
||||
// 设置占位符
|
||||
@ -77,7 +85,8 @@ public class ImageUtils {
|
||||
.setBackground(new ColorDrawable(resources.getColor(R.color.placeholder_bg)))
|
||||
.setPlaceholderImage(placeholderImage)
|
||||
.build());
|
||||
simpleDraweeView.setImageURI(url);
|
||||
// simpleDraweeView.setImageURI(url);
|
||||
display(simpleDraweeView, url);
|
||||
}
|
||||
|
||||
// 图片下载监听和设置低高分辨率图片
|
||||
|
||||
148
app/src/main/java/com/gh/common/util/InstallUtils.java
Normal file
148
app/src/main/java/com/gh/common/util/InstallUtils.java
Normal file
@ -0,0 +1,148 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.manager.CommentManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
*
|
||||
* 下载完成跳安装,
|
||||
*/
|
||||
public class InstallUtils {
|
||||
|
||||
private static final int MAX_TIME = 5 * 60 * 1000;
|
||||
|
||||
private static Map<String, Long> installMap;
|
||||
private static Map<String, Long> uninstallMap;
|
||||
|
||||
private static InstallUtils mInstance;
|
||||
|
||||
public static InstallUtils getInstance(Context context) {
|
||||
if (mInstance == null) {
|
||||
synchronized (CommentManager.class) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new InstallUtils(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
private PackageManager packageManager;
|
||||
|
||||
private Handler handler;
|
||||
|
||||
private boolean isRunning;
|
||||
|
||||
private InstallUtils(Context context) {
|
||||
isRunning = false;
|
||||
|
||||
packageManager = context.getPackageManager();
|
||||
|
||||
handler = new Handler(context.getMainLooper()) {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what == 0x123 && packageManager != null) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
|
||||
for (PackageInfo packageInfo : packageInfos) {
|
||||
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
|
||||
list.add(packageInfo.packageName);
|
||||
}
|
||||
}
|
||||
if (installMap != null && installMap.size() != 0) {
|
||||
ArrayList<String> keys = new ArrayList<>();
|
||||
for (String packageName : installMap.keySet()) {
|
||||
long time = installMap.get(packageName);
|
||||
if (System.currentTimeMillis() - time >= MAX_TIME) {
|
||||
keys.add(packageName);
|
||||
} else if (list.contains(packageName)) {
|
||||
keys.add(packageName);
|
||||
EventBus.getDefault().post(new EBPackage("安装", packageName));
|
||||
}
|
||||
}
|
||||
for (String key : keys) {
|
||||
installMap.remove(key);
|
||||
}
|
||||
}
|
||||
if (uninstallMap != null && uninstallMap.size() != 0) {
|
||||
ArrayList<String> keys = new ArrayList<>();
|
||||
for (String packageName : uninstallMap.keySet()) {
|
||||
long time = uninstallMap.get(packageName);
|
||||
if (System.currentTimeMillis() - time >= MAX_TIME) {
|
||||
keys.add(packageName);
|
||||
} else if (list.contains(packageName)) {
|
||||
keys.add(packageName);
|
||||
EventBus.getDefault().post(new EBPackage("卸载", packageName));
|
||||
}
|
||||
}
|
||||
for (String key : keys) {
|
||||
uninstallMap.remove(key);
|
||||
}
|
||||
}
|
||||
if ((installMap != null && installMap.size() != 0)
|
||||
|| (uninstallMap != null && uninstallMap.size() != 0)) {
|
||||
sendEmptyMessageDelayed(0x123, 3000);
|
||||
} else {
|
||||
isRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void addInstall(String packageName) {
|
||||
if (installMap == null) {
|
||||
installMap = Collections.synchronizedMap(new HashMap<String, Long>());
|
||||
}
|
||||
installMap.put(packageName, System.currentTimeMillis());
|
||||
run();
|
||||
}
|
||||
|
||||
public void removeInstall(String packageName) {
|
||||
if (installMap != null) {
|
||||
installMap.remove(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
public void addUninstall(String packageName) {
|
||||
if (uninstallMap == null) {
|
||||
uninstallMap = Collections.synchronizedMap(new HashMap<String, Long>());
|
||||
}
|
||||
uninstallMap.put(packageName, System.currentTimeMillis());
|
||||
run();
|
||||
}
|
||||
|
||||
public void removeUninstall(String packageName) {
|
||||
if (uninstallMap != null) {
|
||||
uninstallMap.remove(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if ((installMap == null || installMap.isEmpty()) && (uninstallMap == null || uninstallMap.isEmpty())) {
|
||||
return;
|
||||
}
|
||||
if (isRunning) {
|
||||
return;
|
||||
}
|
||||
isRunning = true;
|
||||
handler.sendEmptyMessageDelayed(0x123, 10000);
|
||||
}
|
||||
|
||||
}
|
||||
78
app/src/main/java/com/gh/common/util/KaiFuUtils.java
Normal file
78
app/src/main/java/com/gh/common/util/KaiFuUtils.java
Normal file
@ -0,0 +1,78 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/19.
|
||||
*/
|
||||
public class KaiFuUtils {
|
||||
|
||||
public static void setKaiFuTime(TextView textView, long time) {
|
||||
time = time * 1000;
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
|
||||
try {
|
||||
long today = format.parse(format.format(new Date())).getTime();
|
||||
if (time >= today && time < today + 86400 * 1000) {
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("今天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.border_white_bg);
|
||||
textView.setTextColor(Color.parseColor("#ffb13c"));
|
||||
} else if (time >= today - 86400 * 1000 && time < today) {
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("昨天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
|
||||
textView.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
} else if (time > today && time < today + 86400 * 1000 * 2){
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("明天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.border_white_bg);
|
||||
textView.setTextColor(Color.parseColor("#ffb13c"));
|
||||
} else if (time >= today - 86400 * 1000 * 2 && time < today){
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("前天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
|
||||
textView.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
} else if (time > today && time < today + 86400 * 1000 * 3){
|
||||
format.applyPattern("HH:mm");
|
||||
textView.setText(String.format("后天 %s", format.format(time)));
|
||||
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
|
||||
textView.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
} else {
|
||||
format.applyPattern("MM-dd HH:mm");
|
||||
textView.setText(format.format(time));
|
||||
textView.setBackgroundResource(R.drawable.kaifu_time_tag_gray);
|
||||
textView.setTextColor(Color.parseColor("#c7c7c7"));
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
format.applyPattern("yyyy年MM月dd日 HH:mm");
|
||||
textView.setText(format.format(time));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setKaiFuType(TextView textView, String type) {
|
||||
textView.setText(type);
|
||||
switch (type) {
|
||||
case "不删档内测":
|
||||
textView.setBackgroundColor(Color.parseColor("#c7c7c7"));
|
||||
break;
|
||||
case "删档内测":
|
||||
textView.setBackgroundColor(Color.parseColor("#c7c7c7"));
|
||||
break;
|
||||
case "公测":
|
||||
textView.setBackgroundColor(Color.parseColor("#06d0a8"));
|
||||
break;
|
||||
default:
|
||||
textView.setBackgroundColor(Color.parseColor("#06d0a8"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,15 @@ public class LibaoUtils {
|
||||
@Override
|
||||
public void onResponse(List<LibaoEntity> response) {
|
||||
LibaoDao libaoDao = new LibaoDao(context);
|
||||
libaoDao.deleteAll(); // 清空之前所有数据
|
||||
for (LibaoEntity libaoEntity : response) {
|
||||
|
||||
if ("ling".equals(libaoEntity.getStatus())) {
|
||||
libaoEntity.setStatus("linged");
|
||||
} else {
|
||||
libaoEntity.setStatus("taoed");
|
||||
}
|
||||
|
||||
LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity);
|
||||
libaoInfo.setActive(libaoEntity.isActive());
|
||||
libaoDao.add(libaoInfo);
|
||||
@ -124,8 +132,6 @@ public class LibaoUtils {
|
||||
return;
|
||||
} else if (e.code() == 410) { // 该接口已废弃
|
||||
Utils.toast(context, "领取失败,请安装最新版本的光环助手");
|
||||
} else if (e.code() == 412) {
|
||||
//TODO 需要验证码
|
||||
}
|
||||
listener.postFailed(e);
|
||||
}
|
||||
@ -213,7 +219,9 @@ public class LibaoUtils {
|
||||
final boolean isInstallRequired, final LibaoDetailAdapter adapter, final String entrance) {
|
||||
|
||||
libaoBtn.setTextColor(Color.WHITE);
|
||||
switch (libaoEntity.getStatus()) {
|
||||
String status = libaoEntity.getStatus();
|
||||
if (TextUtils.isEmpty(status)) return;
|
||||
switch (status) {
|
||||
case "coming":
|
||||
libaoBtn.setText("未开抢");
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
@ -321,20 +329,32 @@ public class LibaoUtils {
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(libaoCode)) {
|
||||
Utils.toast(libaoBtn.getContext(), "淘号异常");
|
||||
try {
|
||||
String detail = responseBody.getString("detail");
|
||||
if ("maintaining".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "网络状态异常,请稍后再试");
|
||||
} else if ("fail to compete".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "淘号失败,稍后重试");
|
||||
} else {
|
||||
Utils.toast(libaoBtn.getContext(), "淘号异常");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Utils.toast(libaoBtn.getContext(), "淘号成功");
|
||||
|
||||
libaoEntity.setStatus("taoed");
|
||||
|
||||
LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity);
|
||||
libaoInfo.setCode(libaoCode);
|
||||
// libaoInfo.setTime(String.valueOf(new Date().getTime()));
|
||||
libaoInfo.setTime(Utils.getTime(libaoBtn.getContext()));
|
||||
libaoDao.add(libaoInfo);
|
||||
|
||||
EventBus.getDefault().post(new EBReuse("libaoChanged"));
|
||||
|
||||
libaoEntity.setStatus("taoed");
|
||||
adapter.initLibaoDao();
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
@ -374,7 +394,7 @@ public class LibaoUtils {
|
||||
try {
|
||||
JSONObject errorJson = new JSONObject(exception.response().errorBody().string());
|
||||
String detail = errorJson.getString("detail");
|
||||
|
||||
Utils.toast(libaoBtn.getContext(), "返回::" + detail);
|
||||
if ("coming".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "礼包领取时间未开始");
|
||||
} else if ("finish".equals(detail)) {
|
||||
@ -396,7 +416,7 @@ public class LibaoUtils {
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Utils.toast(libaoBtn.getContext(),"礼包处理异常");
|
||||
Utils.toast(libaoBtn.getContext(),"礼包处理异常"+ ex.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -432,13 +452,15 @@ public class LibaoUtils {
|
||||
}
|
||||
libaoEntity.setAvailable(libaoEntity.getAvailable() - 1);
|
||||
|
||||
libaoEntity.setStatus("linged");
|
||||
|
||||
LibaoInfo libaoInfo = LibaoInfo.createLibaoInfo(libaoEntity);
|
||||
libaoInfo.setTime(Utils.getTime(libaoBtn.getContext()));
|
||||
libaoInfo.setCode(libaoCode);
|
||||
libaoDao.add(libaoInfo);
|
||||
|
||||
EventBus.getDefault().post(new EBReuse("libaoChanged"));
|
||||
|
||||
libaoEntity.setStatus("linged");
|
||||
adapter.initLibaoDao();
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
@ -474,8 +496,8 @@ public class LibaoUtils {
|
||||
HttpException exception = (HttpException) error;
|
||||
if (exception.code() == 403) {
|
||||
try {
|
||||
Utils.log("----403" + exception.response().errorBody().string());
|
||||
JSONObject errorJson = new JSONObject(exception.response().errorBody().string());
|
||||
String string = exception.response().errorBody().string();
|
||||
JSONObject errorJson = new JSONObject(string);
|
||||
String detail = errorJson.getString("detail");
|
||||
|
||||
if ("coming".equals(detail)) {
|
||||
@ -485,7 +507,7 @@ public class LibaoUtils {
|
||||
} else if ("fetched".equals(detail)) {
|
||||
Utils.toast(libaoBtn.getContext(), "你已领过这个礼包了");
|
||||
getCunHaoXiang(libaoBtn.getContext(), true);
|
||||
libaoBtn.setText("复制");
|
||||
libaoBtn.setText("复制");// TODO
|
||||
libaoBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
|
||||
} else if ("try tao".equals(detail) || "used up".equals(detail)) {
|
||||
|
||||
@ -72,6 +72,15 @@ public class MessageShareUtils {
|
||||
|
||||
private Activity activity; // 用来关闭分享页面
|
||||
|
||||
// 适配快传成绩单分享
|
||||
private int contentSize;
|
||||
private int paddTop;
|
||||
private int picSize;
|
||||
private int itemSize;
|
||||
private int gridCount;
|
||||
private int marImg;
|
||||
private int shareType;
|
||||
|
||||
public static MessageShareUtils getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = new MessageShareUtils();
|
||||
@ -82,22 +91,40 @@ public class MessageShareUtils {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void showShareWindows(View view, Bitmap bitmap, String picName, boolean ispopupWindow){
|
||||
public void showShareWindows(View view, Bitmap bitmap, String picName, int shareType){
|
||||
this.shareBm = bitmap;
|
||||
this.picName = picName;
|
||||
this.shareType = shareType;
|
||||
this.activity= (Activity) context;
|
||||
|
||||
if (shareType == 2) {
|
||||
contentSize = 75;
|
||||
paddTop = 0;
|
||||
gridCount = 4;
|
||||
picSize = 30;
|
||||
itemSize = 75;
|
||||
marImg = 10;
|
||||
} else {
|
||||
contentSize = 100;
|
||||
paddTop = 10;
|
||||
gridCount = 5;
|
||||
picSize = 43;
|
||||
itemSize = 90;
|
||||
marImg = 13;
|
||||
|
||||
}
|
||||
|
||||
RelativeLayout contentView = new RelativeLayout(context);
|
||||
contentView.setBackgroundColor(0x8c000000);
|
||||
contentView.setFocusable(true);
|
||||
contentView.setFocusableInTouchMode(true);
|
||||
|
||||
RecyclerView shareRecyclerView = new RecyclerView(context);
|
||||
shareRecyclerView.setPadding(DisplayUtils.dip2px(context, 10), DisplayUtils.dip2px(context, 10), DisplayUtils.dip2px(context, 10), 0);
|
||||
shareRecyclerView.setPadding(DisplayUtils.dip2px(context, 10), DisplayUtils.dip2px(context, paddTop), DisplayUtils.dip2px(context, 10), 0);
|
||||
shareRecyclerView.setBackgroundColor(Color.WHITE);
|
||||
|
||||
//RecyclerView禁止滑动
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 5){
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, gridCount){
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
@ -107,10 +134,10 @@ public class MessageShareUtils {
|
||||
shareRecyclerView.setLayoutManager(gridLayoutManager);
|
||||
shareRecyclerView.setAdapter(new ShareRecyclerViewAdapter());
|
||||
|
||||
if (!ispopupWindow) {
|
||||
if (shareType == 0 || shareType == 2) {
|
||||
LinearLayout llBottom = (LinearLayout) view;
|
||||
ViewGroup.LayoutParams layoutParams = llBottom.getLayoutParams();
|
||||
layoutParams.height = DisplayUtils.dip2px(context, 100);
|
||||
layoutParams.height = DisplayUtils.dip2px(context, contentSize);
|
||||
llBottom.addView(shareRecyclerView);
|
||||
return;
|
||||
}
|
||||
@ -151,13 +178,13 @@ public class MessageShareUtils {
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
LinearLayout linearLayout = new LinearLayout(context);
|
||||
linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, DisplayUtils.dip2px(context, 90)));
|
||||
linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, DisplayUtils.dip2px(context, itemSize)));
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
linearLayout.setBackgroundResource(R.drawable.cardview_item_style);
|
||||
|
||||
ImageView shareLogo = new ImageView(context);
|
||||
LinearLayout.LayoutParams logoParams = new LinearLayout.LayoutParams(DisplayUtils.dip2px(context, 43), DisplayUtils.dip2px(context, 43));
|
||||
LinearLayout.LayoutParams logoParams = new LinearLayout.LayoutParams(DisplayUtils.dip2px(context, picSize), DisplayUtils.dip2px(context, picSize));
|
||||
logoParams.setMargins(0, DisplayUtils.dip2px(context, 10), 0, 0);
|
||||
shareLogo.setLayoutParams(logoParams);
|
||||
|
||||
@ -167,7 +194,7 @@ public class MessageShareUtils {
|
||||
shareLabel.setLayoutParams(layoutParams);
|
||||
shareLabel.setGravity(Gravity.CENTER);
|
||||
shareLabel.setTextColor(Color.parseColor("#3a3a3a"));
|
||||
shareLabel.setTextSize(13);
|
||||
shareLabel.setTextSize(marImg);
|
||||
|
||||
linearLayout.addView(shareLogo);
|
||||
linearLayout.addView(shareLabel);
|
||||
@ -185,11 +212,15 @@ public class MessageShareUtils {
|
||||
switch (holder.getPosition()){
|
||||
case 0:
|
||||
wechatSahre();
|
||||
activity.finish();
|
||||
if (shareType != 2) {
|
||||
activity.finish();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
wechatMomentsSahre();
|
||||
activity.finish();
|
||||
if (shareType != 2) {
|
||||
activity.finish();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
qqSahre();
|
||||
@ -213,7 +244,7 @@ public class MessageShareUtils {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return arrLogo.length;
|
||||
return gridCount;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder{
|
||||
@ -416,11 +447,7 @@ public class MessageShareUtils {
|
||||
if (isToast) {
|
||||
Utils.toast(context,"成功保存到相册");
|
||||
//刷新手机图片库
|
||||
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
||||
Uri uri = Uri.fromFile(_file);
|
||||
intent.setData(uri);
|
||||
context.sendBroadcast(intent);
|
||||
Utils.log("保存分享图片路径:" + _file.getAbsolutePath());
|
||||
refreshImage(_file, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -438,4 +465,12 @@ public class MessageShareUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshImage(File _file, Context context) {
|
||||
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
||||
Uri uri = Uri.fromFile(_file);
|
||||
intent.setData(uri);
|
||||
context.sendBroadcast(intent);
|
||||
Utils.log("保存分享图片路径:" + _file.getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,10 +3,12 @@ package com.gh.common.util;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.WebActivity;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
@ -33,6 +35,8 @@ public class NewsUtils {
|
||||
return R.drawable.textview_orange_up;
|
||||
} else if ("新游".equals(type)) {
|
||||
return R.drawable.textview_green_up;
|
||||
} else if ("热门".equals(type) || "置顶".equals(type)) {
|
||||
return R.drawable.textview_all_red_up;
|
||||
} else {
|
||||
return R.drawable.textview_blue_up;
|
||||
}
|
||||
@ -42,13 +46,23 @@ public class NewsUtils {
|
||||
* 启动新闻详情页面
|
||||
*/
|
||||
public static void startNewsDetailActivity(Context context, NewsEntity newsEntity, String entrance) {
|
||||
Intent intent = new Intent(context, NewsDetailActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("id", newsEntity.getId());
|
||||
intent.putExtra("title", newsEntity.getTitle());
|
||||
intent.putExtra("type", newsEntity.getType());
|
||||
intent.putExtra("entrance", entrance);
|
||||
context.startActivity(intent);
|
||||
if (!TextUtils.isEmpty(newsEntity.getLink())) {
|
||||
Intent intent = new Intent(context, WebActivity.class);
|
||||
intent.putExtra("url", newsEntity.getLink());
|
||||
intent.putExtra("gameName", newsEntity.getGameName());
|
||||
intent.putExtra("newsId", newsEntity.getId());
|
||||
intent.putExtra("entrance", entrance + "+(消息详情[" + newsEntity.getGameName() + "])");
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(context, NewsDetailActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("id", newsEntity.getId());
|
||||
intent.putExtra("title", newsEntity.getTitle());
|
||||
intent.putExtra("type", newsEntity.getType());
|
||||
intent.putExtra("entrance", entrance);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,8 +100,17 @@ public class NewsUtils {
|
||||
/**
|
||||
* 设置新闻类型
|
||||
*/
|
||||
public static void setNewsType(TextView textView, String type) {
|
||||
textView.setText(type);
|
||||
public static void setNewsType(TextView textView, String type, int priority, int position) {
|
||||
if (priority != 0) {
|
||||
if (position == 0) {
|
||||
textView.setText("置顶");
|
||||
} else {
|
||||
textView.setText("热门");
|
||||
}
|
||||
} else {
|
||||
textView.setText(type);
|
||||
}
|
||||
|
||||
textView.setTextColor(Color.WHITE);
|
||||
if ("活动".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
@ -99,6 +122,10 @@ public class NewsUtils {
|
||||
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
} else if ("专题".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
} else if ("置顶".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_all_red_style);
|
||||
} else if ("热门".equals(type)){
|
||||
textView.setBackgroundResource(R.drawable.textview_all_red_style);
|
||||
} else {
|
||||
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
}
|
||||
|
||||
@ -17,6 +17,27 @@ import com.gh.gamecenter.R;
|
||||
*/
|
||||
public class NotificationUtils {
|
||||
|
||||
// 快传传输完成消息
|
||||
public static void showKuaiChuanDoneNotification(Context context, String apkPath, String apkName, String packName) {
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("path", apkPath);
|
||||
intent.setAction("com.gh.gamecenter.INSTALL");
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0x321,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
String title = "接收完成,点击立即安装";
|
||||
String text = apkName;
|
||||
|
||||
Notification notification = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.logo)
|
||||
.setTicker(title)
|
||||
.setContentTitle(text)
|
||||
.setContentText(title)
|
||||
.setContentIntent(pendingIntent).build();
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL; // // FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。
|
||||
nManager.notify(packName,0x321, notification);
|
||||
}
|
||||
|
||||
public static void showDownloadDoneNotification(Context context, DownloadEntity downloadEntity, int flag) {
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Intent intent = new Intent();
|
||||
|
||||
@ -13,7 +13,6 @@ import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
@ -124,7 +123,7 @@ public class PackageUtils {
|
||||
*/
|
||||
public static void launchSetup(final Context context, final String path) {
|
||||
if (isCanLaunchSetup(context, path)) {
|
||||
context.startActivity(PackageUtils.getInstallIntent(path));
|
||||
context.startActivity(PackageUtils.getInstallIntent(context, path));
|
||||
} else {
|
||||
DialogUtils.showPluginDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
@ -212,15 +211,12 @@ public class PackageUtils {
|
||||
* 获取所有已安装的软件的包名、版本(非系统应用)
|
||||
*/
|
||||
public static ArrayList<String> getAllPackageName(Context context) {
|
||||
FilterManager filterManager = new FilterManager(context);
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
List<PackageInfo> packageInfos = context.getPackageManager().getInstalledPackages(0);
|
||||
for (PackageInfo packageInfo : packageInfos) {
|
||||
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
|
||||
if (!context.getPackageName().equals(packageInfo.packageName)) {
|
||||
if (!filterManager.isFilter(packageInfo.packageName)) {
|
||||
list.add(packageInfo.packageName);
|
||||
}
|
||||
list.add(packageInfo.packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -232,11 +228,16 @@ public class PackageUtils {
|
||||
*/
|
||||
public static void launchApplicationByPackageName(Context context,
|
||||
String packageName) {
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(
|
||||
packageName);
|
||||
if (intent != null) {
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
try {
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(
|
||||
packageName);
|
||||
if (intent != null) {
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
Toast.makeText(context, "启动失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(context, "启动失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@ -272,19 +273,21 @@ public class PackageUtils {
|
||||
Intent uninstallIntent = new Intent();
|
||||
uninstallIntent.setAction("android.intent.action.DELETE");
|
||||
uninstallIntent.addCategory("android.intent.category.DEFAULT");
|
||||
uninstallIntent.setData(Uri.parse("package:"
|
||||
+ getPackageNameByPath(context, path)));
|
||||
String packageName = getPackageNameByPath(context, path);
|
||||
uninstallIntent.setData(Uri.parse("package:" + packageName));
|
||||
InstallUtils.getInstance(context).addUninstall(packageName);
|
||||
return uninstallIntent;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据路径,获取安装游戏的意图
|
||||
*/
|
||||
public static Intent getInstallIntent(String path) {
|
||||
public static Intent getInstallIntent(Context context, String path) {
|
||||
Uri uri = Uri.fromFile(new File(path));
|
||||
Intent installIntent = new Intent(Intent.ACTION_VIEW);
|
||||
installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
installIntent.setDataAndType(uri, "application/vnd.android.package-archive");
|
||||
InstallUtils.getInstance(context).addInstall(getPackageNameByPath(context, path));
|
||||
return installIntent;
|
||||
}
|
||||
|
||||
|
||||
@ -16,9 +16,12 @@ import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
@ -251,7 +254,7 @@ public class PlatformUtils {
|
||||
return platformName;
|
||||
}
|
||||
|
||||
boolean isUpdate = false;
|
||||
private boolean isUpdate = false;
|
||||
|
||||
public void getPlatform() {
|
||||
if (isUpdate) {
|
||||
@ -273,6 +276,9 @@ public class PlatformUtils {
|
||||
initMap();
|
||||
EventBus.getDefault().post(new EBReuse("PlatformChanged"));
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||
String today = format.format(new Date());
|
||||
sp.edit().putString("refresh_time", today).apply();
|
||||
isUpdate = false;
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
@ -24,13 +25,19 @@ import rx.schedulers.Schedulers;
|
||||
public class PostCommentUtils {
|
||||
|
||||
public static void addCommentData(final Context context, final String newsId, final String content,
|
||||
final boolean isCheck, final PostCommentListener listener) {
|
||||
final boolean isCheck, final CommentEntity commentEntity,
|
||||
final PostCommentListener listener) {
|
||||
TokenUtils.getToken(context, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), content);
|
||||
return RetrofitManager.getComment().postNewsComment(token, newsId, body);
|
||||
|
||||
if (commentEntity != null) {
|
||||
return RetrofitManager.getComment().postReplyComment(token, commentEntity.getId(), body);
|
||||
} else {
|
||||
return RetrofitManager.getComment().postNewsComment(token, newsId, body);
|
||||
}
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -47,10 +54,16 @@ public class PostCommentUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
Utils.log("======" + e.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
if (e != null && e.code() == 401) {
|
||||
addCommentData(context, newsId, content, false, listener);
|
||||
addCommentData(context, newsId, content, false, commentEntity, listener);
|
||||
return;
|
||||
}
|
||||
if (listener != null){
|
||||
|
||||
38
app/src/main/java/com/gh/common/util/QQUtils.java
Normal file
38
app/src/main/java/com/gh/common/util/QQUtils.java
Normal file
@ -0,0 +1,38 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/30.
|
||||
*/
|
||||
public class QQUtils {
|
||||
|
||||
public static void startQQSession(Context context, String qq) {
|
||||
if (ShareUtils.isQQClientAvailable(context)) {
|
||||
//安装了QQ会直接调用QQ,打开手机QQ进行会话 QQ号:2586716223
|
||||
String str = "mqqwpa://im/chat?chat_type=wpa&uin=" + qq + "&version=1&src_type=web&web_src=oicqzone.com";
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
|
||||
} else {
|
||||
//没有安装QQ 复制账号
|
||||
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setText(qq);
|
||||
Utils.toast(context, "已复制" + qq);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean joinQQGroup(Context context, String key) {
|
||||
Intent intent = new Intent();
|
||||
intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + key));
|
||||
// 此Flag可根据具体产品需要自定义,如设置,则在加群界面按返回,返回手Q主界面,不设置,按返回会返回到呼起产品界面 //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
try {
|
||||
context. startActivity(intent);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
// 未安装手Q或安装的版本不支持
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,6 @@ import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.Gravity;
|
||||
@ -63,7 +62,7 @@ public class ShareUtils {
|
||||
private static IWXAPI api;
|
||||
private static Tencent mTencent;
|
||||
|
||||
private Handler handler;
|
||||
private Boolean ispopupWindow;
|
||||
|
||||
private int[] arrLogo = {R.drawable.share_wechat_logo, R.drawable.share_wechatmoments_logo, R.drawable.share_qq_logo
|
||||
, R.drawable.share_qzone_logo, R.drawable.share_sinaweibo_logo, R.drawable.share_shortmessage_logo
|
||||
@ -74,7 +73,8 @@ public class ShareUtils {
|
||||
|
||||
private Context context;
|
||||
|
||||
public static ShareUtils getInstance(Context context) {
|
||||
|
||||
public static ShareUtils getInstance(Activity context) {
|
||||
if (instance == null) {
|
||||
instance = new ShareUtils();
|
||||
mTencent = Tencent.createInstance("1104659243", context); //初始化QQ分享
|
||||
@ -84,21 +84,31 @@ public class ShareUtils {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void showShareWindows(View view, String url, String gameName, String icon ,String newsTitle, boolean isPlugin){
|
||||
/**
|
||||
*
|
||||
* @param view ispopupWindow-true是绑定的布局, ispopupWindow-false 则是嵌套的父控件
|
||||
* @param url 分享链接
|
||||
* @param gameName 游戏名 与 新闻标题区分
|
||||
* @param icon 分享图标
|
||||
* @param newsTitle 新闻标题 与 游戏名区分
|
||||
* @param isPlugin 判断游戏是否是插件
|
||||
* @param ispopupWindow 判断是否是 PopupWindow false可直接嵌套进布局(分享光环),view是父控件
|
||||
*/
|
||||
public void showShareWindows(View view, String url, String gameName, String icon ,String newsTitle,
|
||||
boolean isPlugin, boolean ispopupWindow){
|
||||
this.shareIcon = icon;
|
||||
this.shareGameName = gameName;
|
||||
this.shareUrl = url;
|
||||
this.shareNewsTitle = newsTitle;
|
||||
this.isPlugin = isPlugin;
|
||||
this.ispopupWindow = ispopupWindow;
|
||||
|
||||
RelativeLayout contentView = new RelativeLayout(context);
|
||||
contentView.setBackgroundColor(0x8c000000);
|
||||
contentView.setFocusable(true);
|
||||
contentView.setFocusableInTouchMode(true);
|
||||
|
||||
RecyclerView shareRecyclerView = new RecyclerView(context);
|
||||
shareRecyclerView.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 10), DisplayUtils.dip2px(context, 20), 0);
|
||||
shareRecyclerView.setBackgroundColor(Color.WHITE);
|
||||
|
||||
//RecyclerView禁止滑动
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 4){
|
||||
@ -116,6 +126,23 @@ public class ShareUtils {
|
||||
rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
contentView.addView(shareRecyclerView,rlParams);
|
||||
|
||||
if (!ispopupWindow) {
|
||||
RelativeLayout layout = (RelativeLayout) view;
|
||||
layout.addView(contentView);
|
||||
arrLabel[6] = "邮件";
|
||||
arrLogo[6] = R.drawable.share_email_logo;
|
||||
arrLabel[7] = "复制链接";
|
||||
arrLogo[7] = R.drawable.share_copyfont_logo;
|
||||
return;
|
||||
} else {
|
||||
arrLabel[6] = "复制链接";
|
||||
arrLogo[6] = R.drawable.share_copyfont_logo;
|
||||
arrLabel[7] = "取消";
|
||||
arrLogo[7] = R.drawable.share_cancel_logo;
|
||||
}
|
||||
contentView.setBackgroundColor(0x8c000000);
|
||||
shareRecyclerView.setBackgroundColor(Color.WHITE);
|
||||
|
||||
popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
||||
, LinearLayout.LayoutParams.MATCH_PARENT, true);
|
||||
popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
|
||||
@ -198,10 +225,28 @@ public class ShareUtils {
|
||||
shortMessageSahre();
|
||||
break;
|
||||
case 6:
|
||||
copyLink(shareUrl);
|
||||
if (ispopupWindow) {
|
||||
copyLink(shareUrl);
|
||||
} else {
|
||||
Intent data=new Intent(Intent.ACTION_SENDTO);
|
||||
data.setData(Uri.parse("mailto:"));
|
||||
data.putExtra(Intent.EXTRA_SUBJECT, "快来试试光环助手");
|
||||
data.putExtra(Intent.EXTRA_TEXT, "我用光环助手一段时间了,在里面可以下载各种热门卡牌手游的加速版,绿色安全,超级省心,做日常效率提高3-5倍!\n" +
|
||||
"\n" +
|
||||
"不用肝的感觉真好,快来试试。\n" +
|
||||
"\n" +
|
||||
"光环助手官网地址:\n" +
|
||||
"\n" +
|
||||
"http://www.ghzhushou.com/link?source=appshare333");
|
||||
context.startActivity(data);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
popupWindow.dismiss();
|
||||
if (ispopupWindow) {
|
||||
popupWindow.dismiss();
|
||||
} else {
|
||||
copyLink("推荐光环助手,绿色安全的手游加速助手:" + shareUrl);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -228,22 +273,31 @@ public class ShareUtils {
|
||||
}
|
||||
|
||||
//QQ分享
|
||||
private void qqSahre(){
|
||||
private void qqSahre() {
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
Bundle params = new Bundle();
|
||||
|
||||
if (shareNewsTitle != null){
|
||||
params.putString(QQShare.SHARE_TO_QQ_TITLE, shareNewsTitle);
|
||||
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, "来自光环助手(最强卡牌神器)");
|
||||
}else {
|
||||
params.putString(QQShare.SHARE_TO_QQ_TITLE, "向你推荐:");
|
||||
if (isPlugin){
|
||||
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, shareGameName + "(光环加速版)");
|
||||
}else {
|
||||
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, shareGameName);
|
||||
}
|
||||
}
|
||||
String title;
|
||||
String summary;
|
||||
|
||||
if (ispopupWindow) {
|
||||
if (shareNewsTitle != null) {
|
||||
title = shareNewsTitle;
|
||||
summary = "来自光环助手(最强卡牌神器)";
|
||||
} else {
|
||||
title = "向你推荐:";
|
||||
if (isPlugin) {
|
||||
summary = shareGameName + "(光环加速版)";
|
||||
} else {
|
||||
summary = shareGameName;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
title = "玩手游不用肝的感觉真好";
|
||||
summary = "绿色安全的手游加速助手";
|
||||
}
|
||||
params.putString(QQShare.SHARE_TO_QQ_TITLE, title);
|
||||
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, summary);
|
||||
params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
|
||||
params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, shareUrl);
|
||||
params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, shareIcon);
|
||||
@ -251,57 +305,84 @@ public class ShareUtils {
|
||||
|
||||
mTencent.shareToQQ(
|
||||
(Activity) context, params,QqShareListener);
|
||||
popupWindow.dismiss();
|
||||
|
||||
if (ispopupWindow) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
//微信好友分享
|
||||
private void wechatSahre(){
|
||||
private void wechatSahre() {
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
WXWebpageObject webpage = new WXWebpageObject();
|
||||
WXMediaMessage msg = new WXMediaMessage(webpage);
|
||||
webpage.webpageUrl = shareUrl;
|
||||
|
||||
if (shareNewsTitle != null){
|
||||
msg.title = shareNewsTitle;
|
||||
msg.description = "来自光环助手(最强卡牌神器)";
|
||||
}else {
|
||||
if (isPlugin){
|
||||
msg.title = "向你推荐";
|
||||
msg.description = shareGameName + "(光环加速版)";
|
||||
}else {
|
||||
msg.title = "向你推荐";
|
||||
msg.description = shareGameName;
|
||||
String title;
|
||||
String summary;
|
||||
|
||||
if (ispopupWindow) {
|
||||
if (shareNewsTitle != null) {
|
||||
title = shareNewsTitle;
|
||||
summary = "来自光环助手(最强卡牌神器)";
|
||||
} else {
|
||||
title = "向你推荐";
|
||||
if (isPlugin){
|
||||
summary = shareGameName + "(光环加速版)";
|
||||
} else {
|
||||
summary = shareGameName;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
title = "玩手游不用肝的感觉真好";
|
||||
summary = "绿色安全的手游加速助手";
|
||||
}
|
||||
|
||||
msg.title = title;
|
||||
msg.description = summary;
|
||||
|
||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
||||
req.transaction = buildTransaction("webpage");
|
||||
req.message = msg;
|
||||
req.scene = SendMessageToWX.Req.WXSceneSession;
|
||||
|
||||
loadBitMap(shareIcon, msg, req);
|
||||
popupWindow.dismiss();
|
||||
if (ispopupWindow) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
//QQ空间分享
|
||||
private void qZoneSahre(){
|
||||
private void qZoneSahre() {
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
Bundle params = new Bundle();
|
||||
|
||||
if (shareNewsTitle != null){
|
||||
params.putString(QzoneShare.SHARE_TO_QQ_TITLE, shareNewsTitle);
|
||||
}else {
|
||||
params.putString(QzoneShare.SHARE_TO_QQ_TITLE, "向你推荐:");
|
||||
if (isPlugin){
|
||||
params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, shareGameName + "(光环加速版)");
|
||||
}else {
|
||||
params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, shareGameName);
|
||||
String title;
|
||||
String summary = null;
|
||||
|
||||
if (ispopupWindow) {
|
||||
if (shareNewsTitle != null) {
|
||||
title = shareNewsTitle;
|
||||
} else {
|
||||
title = "向你推荐:";
|
||||
if (isPlugin) {
|
||||
summary = shareGameName + "(光环加速版)";
|
||||
} else {
|
||||
summary = shareGameName;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
title = "玩手游不用肝的感觉真好";
|
||||
summary = "绿色安全的手游加速助手";
|
||||
}
|
||||
|
||||
ArrayList<String> imageUrls = new ArrayList<String>();
|
||||
imageUrls.add(shareIcon);
|
||||
|
||||
if (summary != null) {
|
||||
params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, summary);
|
||||
}
|
||||
params.putString(QzoneShare.SHARE_TO_QQ_TITLE, title);
|
||||
params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_NO_TYPE);
|
||||
params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, shareUrl);
|
||||
params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, imageUrls);
|
||||
@ -309,26 +390,36 @@ public class ShareUtils {
|
||||
|
||||
mTencent.shareToQzone(
|
||||
(Activity) context, params,QqShareListener);
|
||||
popupWindow.dismiss();
|
||||
if (ispopupWindow) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
//微信朋友圈分享
|
||||
private void wechatMomentsSahre(){
|
||||
private void wechatMomentsSahre() {
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
WXWebpageObject webpage = new WXWebpageObject();
|
||||
WXMediaMessage msg = new WXMediaMessage(webpage);
|
||||
|
||||
webpage.webpageUrl = shareUrl;
|
||||
if (shareNewsTitle != null){
|
||||
msg.title = shareNewsTitle;
|
||||
}else {
|
||||
if (isPlugin){
|
||||
msg.title = "向你推荐:" + shareGameName + "(光环加速版)";
|
||||
}else {
|
||||
msg.title = "向你推荐:" + shareGameName;
|
||||
|
||||
String title;
|
||||
|
||||
if (ispopupWindow) {
|
||||
if (shareNewsTitle != null) {
|
||||
title = shareNewsTitle;
|
||||
} else {
|
||||
if (isPlugin){
|
||||
title = shareGameName + "(光环加速版)";
|
||||
} else {
|
||||
title = shareGameName;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
title = "玩手游不用肝的感觉真好";
|
||||
}
|
||||
|
||||
msg.title = title;
|
||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
||||
|
||||
req.transaction = buildTransaction("webpage");
|
||||
@ -336,12 +427,14 @@ public class ShareUtils {
|
||||
req.scene = SendMessageToWX.Req.WXSceneTimeline;
|
||||
|
||||
loadBitMap(shareIcon, msg, req);
|
||||
popupWindow.dismiss();
|
||||
if (ispopupWindow) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//新浪微博分享
|
||||
private void sinaWeiboSahre(){
|
||||
private void sinaWeiboSahre() {
|
||||
Intent intent = new Intent(context, WeiBoShareActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("shareNewsTitle", shareNewsTitle);
|
||||
@ -349,23 +442,31 @@ public class ShareUtils {
|
||||
bundle.putString("shareGameName", shareGameName);
|
||||
bundle.putString("shareUrl", shareUrl);
|
||||
bundle.putBoolean("isPlugin",isPlugin);
|
||||
bundle.putBoolean("ispopupWindow", ispopupWindow);
|
||||
intent.putExtras(bundle);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
|
||||
popupWindow.dismiss();
|
||||
if (ispopupWindow) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
//短信分享
|
||||
private void shortMessageSahre(){
|
||||
private void shortMessageSahre() {
|
||||
String smsBody;
|
||||
if (shareNewsTitle != null){
|
||||
smsBody = shareNewsTitle + shareUrl;
|
||||
}else {
|
||||
if (isPlugin){
|
||||
smsBody = "向你推荐:" + shareGameName + "(光环加速版)" + shareUrl;
|
||||
if (ispopupWindow) {
|
||||
if (shareNewsTitle != null){
|
||||
smsBody = shareNewsTitle + shareUrl;
|
||||
}else {
|
||||
smsBody = "向你推荐:" + shareGameName + shareUrl;
|
||||
if (isPlugin){
|
||||
smsBody = "向你推荐:" + shareGameName + "(光环加速版)" + shareUrl;
|
||||
}else {
|
||||
smsBody = "向你推荐:" + shareGameName + shareUrl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
smsBody = "这个App可以下载各种热门卡牌手游的加速版,绿色安全,超级省心,做日常效率提高3-5倍!光环助手官网地址:" + shareUrl;
|
||||
}
|
||||
|
||||
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:"));
|
||||
@ -373,13 +474,16 @@ public class ShareUtils {
|
||||
sendIntent.setType("vnd.android-dir/mms-sms");
|
||||
|
||||
try {
|
||||
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(sendIntent);
|
||||
} catch (Exception e) {
|
||||
Utils.toast(context, "系统异常,分享失败");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
popupWindow.dismiss();
|
||||
if (ispopupWindow) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private String buildTransaction(final String type) {
|
||||
@ -390,9 +494,12 @@ public class ShareUtils {
|
||||
private void copyLink(String copyContent) {
|
||||
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setText(copyContent);
|
||||
popupWindow.dismiss();
|
||||
|
||||
Utils.toast(context,"复制成功");
|
||||
if (ispopupWindow != null && ispopupWindow) {
|
||||
Utils.toast(context,"复制成功");
|
||||
popupWindow.dismiss();
|
||||
} else {
|
||||
Utils.toast(context,"复制成功,请到微信/QQ粘贴分享");
|
||||
}
|
||||
}
|
||||
|
||||
private void loadBitMap(final String iconUrl, final WXMediaMessage msg, final SendMessageToWX.Req req){
|
||||
|
||||
94
app/src/main/java/com/gh/common/util/TagUtils.java
Normal file
94
app/src/main/java/com/gh/common/util/TagUtils.java
Normal file
@ -0,0 +1,94 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
|
||||
import com.gh.gamecenter.entity.TagEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public class TagUtils {
|
||||
|
||||
private static TagUtils mInstance;
|
||||
|
||||
private Context context;
|
||||
|
||||
private ArrayMap<String, String> colorMap;
|
||||
|
||||
private TagUtils(Context con) {
|
||||
this.context = con.getApplicationContext();
|
||||
initTag();
|
||||
}
|
||||
|
||||
public static TagUtils getInstance(Context context) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new TagUtils(context);
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
private void initTag() {
|
||||
colorMap = new ArrayMap<>();
|
||||
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences("gh_tag", Context.MODE_PRIVATE);
|
||||
Set<String> set = sharedPreferences.getStringSet("tag", null);
|
||||
if (set == null) {
|
||||
getTag();
|
||||
} else {
|
||||
for (String str : set) {
|
||||
String[] platform = str.split("=");
|
||||
colorMap.put(platform[0], platform[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getColor(String tag) {
|
||||
String color = colorMap.get(tag);
|
||||
if (color == null) {
|
||||
getTag();
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private boolean isUpdate = false;
|
||||
|
||||
public void getTag() {
|
||||
if (isUpdate) {
|
||||
return;
|
||||
}
|
||||
isUpdate = true;
|
||||
RetrofitManager.getApi().getTags()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<TagEntity>>() {
|
||||
@Override
|
||||
public void onResponse(List<TagEntity> response) {
|
||||
Set<String> tagSet = new HashSet<>();
|
||||
for (TagEntity tagEntity : response) {
|
||||
tagSet.add(tagEntity.getName() + "=" + tagEntity.getColor());
|
||||
}
|
||||
SharedPreferences sp = context.getSharedPreferences("gh_tag", Context.MODE_PRIVATE);
|
||||
sp.edit().putStringSet("tag", tagSet).apply();
|
||||
initTag();
|
||||
|
||||
isUpdate = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
isUpdate = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -134,7 +134,7 @@ public class TokenUtils {
|
||||
}).onErrorResumeNext(new Func1<Throwable, Observable<? extends String>>() {
|
||||
@Override
|
||||
public Observable<? extends String> call(Throwable throwable) {
|
||||
return Observable.empty();
|
||||
return Observable.error(throwable);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -142,7 +142,7 @@ public class TokenUtils {
|
||||
}
|
||||
|
||||
// 检查设备信息是否已经上传完整
|
||||
public static synchronized void checkDeviceInfo(final Context context) {
|
||||
public static synchronized void checkDeviceInfo(Context context, String token) {
|
||||
final SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
final HashMap<String, String> params = new HashMap<>();
|
||||
if (!sp.getBoolean("isUploadExtra", false)) {
|
||||
@ -165,15 +165,10 @@ public class TokenUtils {
|
||||
}
|
||||
}
|
||||
if (params.size() != 0) {
|
||||
TokenUtils.getToken(context, true)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
return RetrofitManager.getUser().postDevice(token, body, TokenUtils.getDeviceId(context));
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getUser().postDevice(token, body, TokenUtils.getDeviceId(context))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
|
||||
60
app/src/main/java/com/gh/common/util/UserIconUtils.java
Normal file
60
app/src/main/java/com/gh/common/util/UserIconUtils.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/13.
|
||||
* 获取用户默认头像工具类
|
||||
*/
|
||||
public class UserIconUtils {
|
||||
|
||||
/**
|
||||
* @param i 默认图片位置(第几个)
|
||||
* @return fresco 能解析的url
|
||||
*/
|
||||
public static String getUserIcon(int i){
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "res:///" + R.drawable.user_default_icon1;
|
||||
case 2:
|
||||
return "res:///" + R.drawable.user_default_icon2;
|
||||
case 3:
|
||||
return "res:///" + R.drawable.user_default_icon3;
|
||||
case 4:
|
||||
return "res:///" + R.drawable.user_default_icon4;
|
||||
case 5:
|
||||
return "res:///" + R.drawable.user_default_icon5;
|
||||
case 6:
|
||||
return "res:///" + R.drawable.user_default_icon6;
|
||||
case 7:
|
||||
return "res:///" + R.drawable.user_default_icon7;
|
||||
case 8:
|
||||
return "res:///" + R.drawable.user_default_icon8;
|
||||
default:
|
||||
return "res:///" + R.drawable.user_default_icon1;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUserIconUrl(int i) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "http://image.ghzhushou.com/pic/default_icon_1.png";
|
||||
case 2:
|
||||
return "http://image.ghzhushou.com/pic/default_icon_2.png";
|
||||
case 3:
|
||||
return "http://image.ghzhushou.com/pic/default_icon_3.png";
|
||||
case 4:
|
||||
return "http://image.ghzhushou.com/pic/default_icon_4.png";
|
||||
case 5:
|
||||
return "http://image.ghzhushou.com/pic/default_icon_5.png";
|
||||
case 6:
|
||||
return "http://image.ghzhushou.com/pic/default_icon_6.png";
|
||||
case 7:
|
||||
return "http://image.ghzhushou.com/pic/default_icon_7.png";
|
||||
case 8:
|
||||
return "http://image.ghzhushou.com/pic/default_icon_8.png";
|
||||
default:
|
||||
return "http://image.ghzhushou.com/pic/default_icon_1.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -250,6 +250,8 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
}
|
||||
}
|
||||
|
||||
apkList.add(new ApkEntity()); // 添加一个跳转投票
|
||||
|
||||
dialog_ll_hint.removeAllViews();
|
||||
int size = (int) Math.ceil(apkList.size() / (double) (row * column));
|
||||
addHintPoint(dialog_ll_hint, size);
|
||||
|
||||
134
app/src/main/java/com/gh/common/view/GridDivider.java
Normal file
134
app/src/main/java/com/gh/common/view/GridDivider.java
Normal file
@ -0,0 +1,134 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/28.
|
||||
*/
|
||||
public class GridDivider extends RecyclerView.ItemDecoration {
|
||||
private Drawable mDividerDarwable;
|
||||
private int mDividerHight = 1;
|
||||
private Paint mColorPaint;
|
||||
|
||||
|
||||
public final int[] ATRRS = new int[]{android.R.attr.listDivider};
|
||||
|
||||
public GridDivider(Context context) {
|
||||
final TypedArray ta = context.obtainStyledAttributes(ATRRS);
|
||||
this.mDividerDarwable = ta.getDrawable(0);
|
||||
ta.recycle();
|
||||
}
|
||||
|
||||
/*
|
||||
int dividerHight 分割线的线宽
|
||||
int dividerColor 分割线的颜色
|
||||
*/
|
||||
public GridDivider(Context context, int dividerHight, int dividerColor) {
|
||||
this(context);
|
||||
mDividerHight = dividerHight;
|
||||
mColorPaint = new Paint();
|
||||
mColorPaint.setColor(dividerColor);
|
||||
}
|
||||
|
||||
/*
|
||||
int dividerHight 分割线的线宽
|
||||
Drawable dividerDrawable 图片分割线
|
||||
*/
|
||||
public GridDivider(Context context, int dividerHight, Drawable dividerDrawable) {
|
||||
this(context);
|
||||
mDividerHight = dividerHight;
|
||||
mDividerDarwable = dividerDrawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
super.onDraw(c, parent, state);
|
||||
//画水平和垂直分割线
|
||||
drawHorizontalDivider(c, parent);
|
||||
drawVerticalDivider(c, parent);
|
||||
}
|
||||
|
||||
public void drawVerticalDivider(Canvas c, RecyclerView parent) {
|
||||
final int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
|
||||
final int top = child.getTop() - params.topMargin;
|
||||
final int bottom = child.getBottom() + params.bottomMargin;
|
||||
|
||||
int left = 0;
|
||||
int right = 0;
|
||||
|
||||
//左边第一列
|
||||
if ((i % 7) == 0) {
|
||||
//item左边分割线
|
||||
left = child.getLeft();
|
||||
right = left + mDividerHight;
|
||||
mDividerDarwable.setBounds(left, top, right, bottom);
|
||||
mDividerDarwable.draw(c);
|
||||
if (mColorPaint != null) {
|
||||
c.drawRect(left, top, right, bottom, mColorPaint);
|
||||
}
|
||||
//item右边分割线
|
||||
left = child.getRight() + params.rightMargin - mDividerHight;
|
||||
right = left + mDividerHight;
|
||||
} else {
|
||||
//非左边第一列
|
||||
left = child.getRight() + params.rightMargin - mDividerHight;
|
||||
right = left + mDividerHight;
|
||||
}
|
||||
//画分割线
|
||||
mDividerDarwable.setBounds(left, top, right, bottom);
|
||||
mDividerDarwable.draw(c);
|
||||
if (mColorPaint != null) {
|
||||
c.drawRect(left, top, right, bottom, mColorPaint);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHorizontalDivider(Canvas c, RecyclerView parent) {
|
||||
|
||||
final int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
|
||||
|
||||
final int left = child.getLeft() - params.leftMargin - mDividerHight;
|
||||
final int right = child.getRight() + params.rightMargin;
|
||||
int top = 0;
|
||||
int bottom = 0;
|
||||
|
||||
// 最上面一行
|
||||
if ((i / 7) == 0) {
|
||||
//当前item最上面的分割线
|
||||
top = child.getTop();
|
||||
//当前item下面的分割线
|
||||
bottom = top + mDividerHight;
|
||||
mDividerDarwable.setBounds(left, top, right, bottom);
|
||||
mDividerDarwable.draw(c);
|
||||
if (mColorPaint != null) {
|
||||
c.drawRect(left, top, right, bottom, mColorPaint);
|
||||
}
|
||||
top = child.getBottom() + params.bottomMargin;
|
||||
bottom = top + mDividerHight;
|
||||
} else {
|
||||
top = child.getBottom() + params.bottomMargin;
|
||||
bottom = top + mDividerHight;
|
||||
}
|
||||
//画分割线
|
||||
mDividerDarwable.setBounds(left, top, right, bottom);
|
||||
mDividerDarwable.draw(c);
|
||||
if (mColorPaint != null) {
|
||||
c.drawRect(left, top, right, bottom, mColorPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
138
app/src/main/java/com/gh/common/view/MarqueeView.java
Normal file
138
app/src/main/java/com/gh/common/view/MarqueeView.java
Normal file
@ -0,0 +1,138 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ViewFlipper;
|
||||
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/29.
|
||||
*/
|
||||
public class MarqueeView extends ViewFlipper {
|
||||
|
||||
private Context mContext;
|
||||
private List<String> notices;
|
||||
private boolean isSetAnimDuration = false;
|
||||
|
||||
private int interval = 2000;
|
||||
private int animDuration = 500;
|
||||
private int textSize = 14;
|
||||
private int textColor = 0xffffffff;
|
||||
|
||||
public MarqueeView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
this.mContext = context;
|
||||
if (notices == null) {
|
||||
notices = new ArrayList<>();
|
||||
}
|
||||
|
||||
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.MarqueeViewStyle, defStyleAttr, 0);
|
||||
interval = typedArray.getInteger(R.styleable.MarqueeViewStyle_mvInterval, interval);
|
||||
isSetAnimDuration = typedArray.hasValue(R.styleable.MarqueeViewStyle_mvAnimDuration);
|
||||
animDuration = typedArray.getInteger(R.styleable.MarqueeViewStyle_mvAnimDuration, animDuration);
|
||||
if (typedArray.hasValue(R.styleable.MarqueeViewStyle_mvTextSize)) {
|
||||
textSize = (int) typedArray.getDimension(R.styleable.MarqueeViewStyle_mvTextSize, textSize);
|
||||
textSize = DisplayUtils.px2sp(mContext, textSize);
|
||||
}
|
||||
textColor = typedArray.getColor(R.styleable.MarqueeViewStyle_mvTextColor, textColor);
|
||||
typedArray.recycle();
|
||||
|
||||
setFlipInterval(interval);
|
||||
|
||||
Animation animIn = AnimationUtils.loadAnimation(mContext, R.anim.anim_marquee_in);
|
||||
if (isSetAnimDuration) animIn.setDuration(animDuration);
|
||||
setInAnimation(animIn);
|
||||
|
||||
Animation animOut = AnimationUtils.loadAnimation(mContext, R.anim.anim_marquee_out);
|
||||
if (isSetAnimDuration) animOut.setDuration(animDuration);
|
||||
setOutAnimation(animOut);
|
||||
}
|
||||
|
||||
// 根据公告字符串启动轮播
|
||||
public void startWithText(final String notice) {
|
||||
if (TextUtils.isEmpty(notice)) return;
|
||||
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
startWithFixedWidth(notice, getWidth());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 根据公告字符串列表启动轮播
|
||||
public void startWithList(List<String> notices) {
|
||||
setNotices(notices);
|
||||
start();
|
||||
}
|
||||
|
||||
// 根据宽度和公告字符串启动轮播
|
||||
private void startWithFixedWidth(String notice, int width) {
|
||||
int noticeLength = notice.length();
|
||||
int dpW = DisplayUtils.px2dip(mContext, width);
|
||||
int limit = dpW/textSize;
|
||||
if (dpW == 0) {
|
||||
throw new RuntimeException("Please set MarqueeView width !");
|
||||
}
|
||||
|
||||
if (noticeLength <= limit) {
|
||||
notices.add(notice);
|
||||
} else {
|
||||
int size = noticeLength/limit + (noticeLength%limit != 0? 1:0);
|
||||
for (int i=0; i<size; i++) {
|
||||
int startIndex = i*limit;
|
||||
int endIndex = ((i+1)*limit >= noticeLength? noticeLength:(i+1)*limit);
|
||||
notices.add(notice.substring(startIndex, endIndex));
|
||||
}
|
||||
}
|
||||
start();
|
||||
}
|
||||
|
||||
// 启动轮播
|
||||
public boolean start() {
|
||||
if (notices == null || notices.size() == 0) return false;
|
||||
removeAllViews();
|
||||
for (String notice:notices) {
|
||||
addView(createTextView(notice));
|
||||
}
|
||||
if (notices.size() > 1) {
|
||||
startFlipping();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 创建ViewFlipper下的TextView
|
||||
private TextView createTextView(String text) {
|
||||
TextView tv = new TextView(mContext);
|
||||
tv.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
|
||||
tv.setText(text);
|
||||
tv.setTextColor(textColor);
|
||||
tv.setTextSize(textSize);
|
||||
return tv;
|
||||
}
|
||||
|
||||
public List<String> getNotices() {
|
||||
return notices;
|
||||
}
|
||||
|
||||
public void setNotices(List<String> notices) {
|
||||
this.notices = notices;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/30.
|
||||
*/
|
||||
public class MeasureLinearLayoutManager extends LinearLayoutManager {
|
||||
int height;
|
||||
|
||||
public MeasureLinearLayoutManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private int[] mMeasuredDimension = new int[1];
|
||||
|
||||
@Override
|
||||
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state,
|
||||
int widthSpec, int heightSpec) {
|
||||
super.onMeasure(recycler, state, widthSpec, heightSpec);
|
||||
height = 0;
|
||||
|
||||
try {
|
||||
for (int i = 0; i < getItemCount(); i++) {
|
||||
measureScrapChild(recycler, i,
|
||||
View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
|
||||
View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
|
||||
mMeasuredDimension);
|
||||
height = height + mMeasuredDimension[0];
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
|
||||
int heightSpec, int[] measuredDimension) throws Exception {
|
||||
View view = recycler.getViewForPosition(position);
|
||||
if (view.getVisibility() == View.GONE) {
|
||||
measuredDimension[0] = 0;
|
||||
return;
|
||||
}
|
||||
super.measureChildWithMargins(view, 0, 0);
|
||||
RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
|
||||
int childHeightSpec = ViewGroup.getChildMeasureSpec(
|
||||
heightSpec,
|
||||
getPaddingTop() + getPaddingBottom() + getDecoratedTop(view) + getDecoratedBottom(view),
|
||||
p.height);
|
||||
|
||||
view.measure(0, childHeightSpec);
|
||||
measuredDimension[0] = getDecoratedMeasuredHeight(view) + p.bottomMargin + p.topMargin;
|
||||
recycler.recycleView(view);
|
||||
}
|
||||
|
||||
public int getRvHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/24.
|
||||
* 控制是否可以左右滑动
|
||||
*/
|
||||
public class NoScrollableViewPager extends ViewPager {
|
||||
|
||||
private boolean isScrollable;
|
||||
|
||||
public NoScrollableViewPager(Context context) {
|
||||
super(context);
|
||||
isScrollable = true;
|
||||
}
|
||||
|
||||
public NoScrollableViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
isScrollable = true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
return isScrollable && super.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
return isScrollable && super.onInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
public void setScrollable(boolean scrollable) {
|
||||
isScrollable = scrollable;
|
||||
}
|
||||
}
|
||||
255
app/src/main/java/com/gh/common/view/RadarLayout.java
Normal file
255
app/src/main/java/com/gh/common/view/RadarLayout.java
Normal file
@ -0,0 +1,255 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/16.
|
||||
* 快传接收方 的雷达动画
|
||||
*/
|
||||
public class RadarLayout extends FrameLayout {
|
||||
|
||||
public static final int INFINITE = 0;
|
||||
|
||||
private static final int DEFAULT_COUNT = 4;
|
||||
private static final int DEFAULT_COLOR = Color.rgb(0, 116, 193);
|
||||
private static final int DEFAULT_DURATION = 7000;
|
||||
private static final int DEFAULT_REPEAT = INFINITE;
|
||||
private static final int DEFAULT_STROKE_WIDTH = 2;
|
||||
|
||||
private int mCount;
|
||||
private int mDuration;
|
||||
private int mRepeat;
|
||||
|
||||
private AnimatorSet mAnimatorSet;
|
||||
|
||||
private Paint mPaint;
|
||||
private int mColor;
|
||||
private float mRadius;
|
||||
private float mCenterX;
|
||||
private float mCenterY;
|
||||
private int mStrokeWidth;
|
||||
private boolean mIsStarted;
|
||||
private boolean mUseRing;
|
||||
|
||||
public RadarLayout(Context context) {
|
||||
super(context);
|
||||
initGlobalparams();
|
||||
}
|
||||
|
||||
public RadarLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initGlobalparams();
|
||||
}
|
||||
|
||||
public RadarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
initGlobalparams();
|
||||
}
|
||||
|
||||
private void initGlobalparams() {
|
||||
mColor = DEFAULT_COLOR;
|
||||
mCount = DEFAULT_COUNT;
|
||||
mDuration = DEFAULT_DURATION;
|
||||
mRepeat = DEFAULT_REPEAT;
|
||||
mUseRing = false;
|
||||
mStrokeWidth = dip2px(DEFAULT_STROKE_WIDTH);
|
||||
|
||||
build();
|
||||
}
|
||||
|
||||
public synchronized void start() {
|
||||
if (mAnimatorSet == null || mIsStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
mAnimatorSet.start();
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
if (mAnimatorSet == null || !mIsStarted) {
|
||||
return;
|
||||
}
|
||||
mAnimatorSet.end();
|
||||
}
|
||||
|
||||
public synchronized boolean isStarted() {
|
||||
return (mAnimatorSet != null && mIsStarted);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return mCount;
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
return mDuration;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
if (count < 0) {
|
||||
throw new IllegalArgumentException("Count cannot be negative");
|
||||
}
|
||||
|
||||
if (count != mCount) {
|
||||
mCount = count;
|
||||
reset();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDuration(int millis) {
|
||||
if (millis < 0) {
|
||||
throw new IllegalArgumentException("Duration cannot be negative");
|
||||
}
|
||||
|
||||
if (millis != mDuration) {
|
||||
mDuration = millis;
|
||||
reset();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
if (mColor != color) {
|
||||
mColor = color;
|
||||
reset();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUseRing(boolean useRing) {
|
||||
if (mUseRing != useRing) {
|
||||
mUseRing = useRing;
|
||||
reset();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
int width = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
|
||||
int height = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
|
||||
|
||||
// 确定圆的圆点坐标及半径
|
||||
mCenterX = width * 0.5f;
|
||||
mCenterY = height * 0.5f;
|
||||
mRadius = Math.min(width, height) * 0.5f;
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
stop();
|
||||
removeAllViews();
|
||||
}
|
||||
|
||||
private void build() {
|
||||
|
||||
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
|
||||
int repeatCount = (mRepeat == INFINITE) ? ObjectAnimator.INFINITE : mRepeat;
|
||||
|
||||
List animators = new ArrayList();
|
||||
for (int index = 0; index < mCount; index++) {
|
||||
RadarView radarView = new RadarView(getContext());
|
||||
radarView.setScaleX(0);
|
||||
radarView.setScaleY(0);
|
||||
radarView.setAlpha(1);
|
||||
|
||||
addView(radarView, index, params);
|
||||
|
||||
// 计算时间间隔
|
||||
long delay = index * mDuration / mCount;
|
||||
|
||||
// 属性动画
|
||||
animators.add(create(radarView, "scaleX", repeatCount, delay, 0, 1));
|
||||
animators.add(create(radarView, "scaleY", repeatCount, delay, 0, 1));
|
||||
animators.add(create(radarView, "alpha", repeatCount, delay, 1, 0));
|
||||
}
|
||||
|
||||
mAnimatorSet = new AnimatorSet();
|
||||
mAnimatorSet.playTogether(animators);
|
||||
mAnimatorSet.setInterpolator(new LinearInterpolator());
|
||||
mAnimatorSet.setDuration(mDuration);
|
||||
mAnimatorSet.addListener(mAnimatorListener);
|
||||
}
|
||||
|
||||
private ObjectAnimator create(View target, String propertyName, int repeatCount, long delay, float from, float to) {
|
||||
ObjectAnimator animator = ObjectAnimator.ofFloat(target, propertyName, from, to);
|
||||
animator.setRepeatCount(repeatCount);
|
||||
animator.setRepeatMode(ObjectAnimator.RESTART);
|
||||
animator.setStartDelay(delay);
|
||||
return animator;
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
boolean isStarted = isStarted();
|
||||
|
||||
clear();
|
||||
build();
|
||||
|
||||
if (isStarted) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
private class RadarView extends View {
|
||||
|
||||
public RadarView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if (null == mPaint) {
|
||||
mPaint = new Paint();
|
||||
mPaint.setColor(mColor);
|
||||
mPaint.setAntiAlias(true);
|
||||
// 注意Style的用法,【STROKE:画环】【FILL:画圆】
|
||||
mPaint.setStyle(mUseRing ? Paint.Style.STROKE : Paint.Style.FILL);
|
||||
mPaint.setStrokeWidth(mUseRing ? mStrokeWidth : 0);
|
||||
}
|
||||
// 画圆或环
|
||||
canvas.drawCircle(mCenterX, mCenterY, mUseRing ? mRadius - mStrokeWidth : mRadius, mPaint);
|
||||
}
|
||||
}
|
||||
|
||||
private int dip2px(float dpValue) {
|
||||
final float scale = getResources().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f);
|
||||
}
|
||||
|
||||
private final Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
mIsStarted = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
mIsStarted = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animator) {
|
||||
mIsStarted = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animator) {
|
||||
}
|
||||
};
|
||||
}
|
||||
1701
app/src/main/java/com/gh/common/view/SwipeLayout.java
Normal file
1701
app/src/main/java/com/gh/common/view/SwipeLayout.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -14,30 +14,42 @@ public class VerticalItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private Paint paint;
|
||||
private int mInterval = 0;
|
||||
private boolean isShowIntervalTop;
|
||||
|
||||
public VerticalItemDecoration(Context context, int interval) {
|
||||
public VerticalItemDecoration(Context context, int interval, boolean isShowIntervalTop) {
|
||||
paint = new Paint();
|
||||
paint.setColor(context.getResources().getColor(R.color.background));
|
||||
paint.setColor(context.getResources().getColor(R.color.background ));
|
||||
mInterval = DisplayUtils.dip2px(context, interval);
|
||||
this.isShowIntervalTop = isShowIntervalTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
int left = parent.getPaddingLeft();
|
||||
int right = parent.getMeasuredWidth() - parent.getPaddingRight();
|
||||
for (int i = 0, size = parent.getChildCount() - 1; i < size; i++) {
|
||||
for (int i = 0, size = parent.getChildCount(); i < size; i++) {
|
||||
View child = parent.getChildAt(i);
|
||||
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child
|
||||
.getLayoutParams();
|
||||
int top = child.getBottom() + layoutParams.bottomMargin;
|
||||
int bottom = top + mInterval;
|
||||
c.drawRect(left, top, right, bottom, paint);
|
||||
|
||||
if (i == 0 && isShowIntervalTop) {
|
||||
c.drawRect(left, 0, right, bottom, paint);
|
||||
} else {
|
||||
c.drawRect(left, top, right, bottom, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
|
||||
RecyclerView.State state) {
|
||||
outRect.set(0, 0, 0, mInterval);
|
||||
int position = parent.getChildPosition(view);
|
||||
if (position == 0 && isShowIntervalTop) {
|
||||
outRect.set(0, mInterval, 0, mInterval);
|
||||
} else {
|
||||
outRect.set(0, 0, 0, mInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ public class ZoomSimpleDraweeView extends SimpleDraweeView {
|
||||
private float mCurrentScale = 1f;
|
||||
private Matrix mCurrentMatrix;
|
||||
private setOnSingleClickListener mClickListener;
|
||||
private setOnLongClickListener mLongClickListener;
|
||||
|
||||
private float imgagePro = -1; // 图片宽高比
|
||||
|
||||
@ -82,6 +83,14 @@ public class ZoomSimpleDraweeView extends SimpleDraweeView {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
super.onLongPress(e);
|
||||
if (mLongClickListener != null) {
|
||||
mLongClickListener.onLongClick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||
if (mCurrentScale > 1f) {
|
||||
@ -273,6 +282,14 @@ public class ZoomSimpleDraweeView extends SimpleDraweeView {
|
||||
mClickListener = listener;
|
||||
}
|
||||
|
||||
public void setOnLongClickListener(setOnLongClickListener listener) {
|
||||
mLongClickListener = listener;
|
||||
}
|
||||
|
||||
public interface setOnLongClickListener {
|
||||
void onLongClick();
|
||||
}
|
||||
|
||||
public interface setOnSingleClickListener {
|
||||
void onClick();
|
||||
}
|
||||
|
||||
@ -97,8 +97,12 @@ public class DownloadTask implements DownloadListener {
|
||||
|
||||
// 计算下载速度
|
||||
if (System.currentTimeMillis() - lastTime > Constants.SPEED_CHECK_INTERVAL) {
|
||||
entry.setSpeed(intervalDownloadedSize
|
||||
/ (Constants.SPEED_CHECK_INTERVAL));
|
||||
long speed = intervalDownloadedSize / (Constants.SPEED_CHECK_INTERVAL);
|
||||
if (speed < 0) {
|
||||
entry.setSpeed(0);
|
||||
} else {
|
||||
entry.setSpeed(speed);
|
||||
}
|
||||
lastTime = System.currentTimeMillis();
|
||||
intervalDownloadedSize = 0;
|
||||
DownloadDao.getInstance(context).newOrUpdate(entry);
|
||||
|
||||
66
app/src/main/java/com/gh/gamecenter/AboutActivity.java
Normal file
66
app/src/main/java/com/gh/gamecenter/AboutActivity.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.gamecenter.manager.UpdateManager;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/28.
|
||||
*/
|
||||
public class AboutActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.about_version_tv) TextView mAboutVersion;
|
||||
@BindView(R.id.about_version_pb) ProgressBar mAboutPb;
|
||||
|
||||
Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.what == 0) {
|
||||
String version = (String) msg.obj;
|
||||
mAboutVersion.setText("发现新版本 V" + version);
|
||||
mAboutPb.setVisibility(View.GONE);
|
||||
} else if (msg.what ==1) {
|
||||
mAboutVersion.setText("已是最新版本");
|
||||
mAboutPb.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View view = View.inflate(this, R.layout.activity_about, null);
|
||||
init(view, "关于");
|
||||
|
||||
((TextView) findViewById(R.id.about_tv_version)).setText("V" + PackageUtils.getVersionName(this));
|
||||
|
||||
UpdateManager.getInstance(this).checkUpdate(false, handler); // 自动检出更新
|
||||
}
|
||||
|
||||
@OnClick({R.id.about_version_tv, R.id.about_shengming})
|
||||
public void OnClick(View view) {
|
||||
if (view.getId() == R.id.about_version_tv) {
|
||||
String content = mAboutVersion.getText().toString();
|
||||
if (content.startsWith("发现新版本")) {
|
||||
UpdateManager.getInstance(this).checkUpdate(false, handler); // 自动检出更新
|
||||
}
|
||||
} else if (view.getId() == R.id.about_shengming) {
|
||||
Intent intent = new Intent(AboutActivity.this, WebActivity.class);
|
||||
intent.putExtra("gameName", "使用条款与免责声明");
|
||||
intent.putExtra("url","http://api.ghzhushou.com/disclaimer");
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
613
app/src/main/java/com/gh/gamecenter/ChooseReceiverActivity.java
Normal file
613
app/src/main/java/com/gh/gamecenter/ChooseReceiverActivity.java
Normal file
@ -0,0 +1,613 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.Html;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.ScaleAnimation;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.kuaichuan.BaseTransfer;
|
||||
import com.gh.gamecenter.kuaichuan.Constant;
|
||||
import com.gh.gamecenter.kuaichuan.FileInfo;
|
||||
import com.gh.gamecenter.kuaichuan.HotspotManager;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.gh.gamecenter.kuaichuan.WifiUtils;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/20.
|
||||
*/
|
||||
public class ChooseReceiverActivity extends BaseActivity implements View.OnClickListener{
|
||||
|
||||
@BindView(R.id.choosereceiver_user1_name) TextView choosereceiver_user1_name;
|
||||
@BindView(R.id.choosereceiver_user2_name) TextView choosereceiver_user2_name;
|
||||
@BindView(R.id.choosereceiver_user3_name) TextView choosereceiver_user3_name;
|
||||
@BindView(R.id.choosereceiver_user4_name) TextView choosereceiver_user4_name;
|
||||
@BindView(R.id.choosereceiver_user1) LinearLayout choosereceiver_user1;
|
||||
@BindView(R.id.choosereceiver_user2) LinearLayout choosereceiver_user2;
|
||||
@BindView(R.id.choosereceiver_user3) LinearLayout choosereceiver_user3;
|
||||
@BindView(R.id.choosereceiver_user4) LinearLayout choosereceiver_user4;
|
||||
@BindView(R.id.choosereceiver_user1_icon) SimpleDraweeView userIcon1;
|
||||
@BindView(R.id.choosereceiver_user2_icon) SimpleDraweeView userIcon2;
|
||||
@BindView(R.id.choosereceiver_user3_icon) SimpleDraweeView userIcon3;
|
||||
@BindView(R.id.choosereceiver_user4_icon) SimpleDraweeView userIcon4;
|
||||
@BindView(R.id.scan_gif) SimpleDraweeView mScanGif;
|
||||
@BindView(R.id.scan_user) TextView mScanUser;
|
||||
@BindView(R.id.scan_user_des) TextView mScanUserDes;
|
||||
@BindView(R.id.reuse_actionbar) RelativeLayout mActionbar;
|
||||
@BindView(R.id.scan_hint) TextView mScanHint;
|
||||
@BindView(R.id.choosereceiver_roket_anim) RelativeLayout mRoketAnimRl;
|
||||
@BindView(R.id.choosereceiver_ready_rl) RelativeLayout mRoketRl;
|
||||
@BindView(R.id.choosereceiver_roket_anim_bottom) LinearLayout mRoketAnimBottom;
|
||||
@BindView(R.id.choosereceiver_roket_anim_top) ImageView mRoketTop;
|
||||
@BindView(R.id.choosereceiver_roket_left) ImageView mRoketAnimLeft;
|
||||
@BindView(R.id.choosereceiver_roket_right) ImageView mRoketAnimRight;
|
||||
@BindView(R.id.actionbar_iv_back) ImageView mBackIv;
|
||||
@BindView(R.id.actionbar_tv_title) TextView mTitleTv;
|
||||
|
||||
|
||||
private List<ScanResult> mScanResultList;
|
||||
|
||||
private DatagramSocket mDatagramSocket;
|
||||
|
||||
private boolean isStopScan;
|
||||
|
||||
private boolean isDestroy;
|
||||
|
||||
private int conUserIconTag;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private ScaleAnimation mScaleAnimation; // 火箭喷火动画
|
||||
|
||||
private TranslateAnimation mTranslateAnimation; // 整个火箭移动页面
|
||||
|
||||
Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.what == 0 && !isStopScan) {
|
||||
updateWifiScanResult();
|
||||
handler.sendEmptyMessageDelayed(0, 2000);
|
||||
} else if (msg.what == 2) {
|
||||
isStopScan = false;
|
||||
handler.sendEmptyMessage(0);
|
||||
connFailedAnimView();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_choosereceiver, null);
|
||||
init(contentView, "发送游戏");
|
||||
|
||||
mTitleTv.setTextColor(Color.WHITE);
|
||||
mBackIv.setImageResource(R.drawable.reuse_kc_back);
|
||||
|
||||
|
||||
// 添加分享图标
|
||||
TextView hintTv = new TextView(this);
|
||||
hintTv.setText("操作说明");
|
||||
hintTv.setTextColor(Color.WHITE);
|
||||
hintTv.setGravity(Gravity.CENTER);
|
||||
hintTv.setPadding(DisplayUtils.dip2px(this, 13),0 ,DisplayUtils.dip2px(this, 13),0);
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT );
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) contentView.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(hintTv, params);
|
||||
|
||||
//修改沉浸栏以及ActionBar 颜色
|
||||
mActionbar.setBackgroundColor(getResources().getColor(R.color.scan_bg));
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setStatusBarTintResource(R.color.scan_bg);
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
hintTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showConnHintDialog();
|
||||
}
|
||||
});
|
||||
|
||||
boolean showConnHintDialog = sp.getBoolean("showConnHintDialog", true);
|
||||
if (showConnHintDialog || (getIntent() != null && getIntent().getExtras() != null
|
||||
&& getIntent().getExtras().getBoolean("showConnHintDialog"))) {
|
||||
if (showConnHintDialog) {
|
||||
sp.edit().putBoolean("showConnHintDialog", false).apply();
|
||||
}
|
||||
showConnHintDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void showConnHintDialog() {
|
||||
DialogUtils.showHintDialog(ChooseReceiverActivity.this, "请告诉你的好友这样操作:", "1.请好友拿出手机,打开光环助手 " +
|
||||
"\n2.点击首页左上角“↓”按钮 \n3.点击“我要接收”", "确定");
|
||||
}
|
||||
|
||||
@OnClick(R.id.scan_hint)
|
||||
public void onScanHintListener() {
|
||||
// DialogUtils.showHintDialog(this, "请告诉你的好友这样操作:", "1.拿出手机,打开光环助手 " +
|
||||
// "\n2.点击首页左上角,进入下载管理 \n3.点击“零流量传送”,再点击“我要接收”",
|
||||
// "确定");
|
||||
|
||||
// TODO 关闭扫描??
|
||||
|
||||
Intent intent = new Intent(this, ShareGhActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
conUserIconTag = 1;
|
||||
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setUri("res:///" + R.drawable.scan_receiver)
|
||||
.setAutoPlayAnimations(true)
|
||||
.build();
|
||||
mScanGif.setController(controller);
|
||||
|
||||
mScanHint.setText(Html.fromHtml("<u>"+"好友还没安装光环助手?请点这里"+"</u>"));
|
||||
|
||||
isStopScan = false;
|
||||
isDestroy = false;
|
||||
|
||||
if (HotspotManager.isApOn(this)) {
|
||||
HotspotManager.disableAp(this);
|
||||
}
|
||||
|
||||
if(!WifiMgr.getInstance(this).isWifiEnable()) { //wifi未打开的情况
|
||||
WifiMgr.getInstance(this).openWifi();
|
||||
}
|
||||
|
||||
updateWifiScanResult();
|
||||
handler.sendEmptyMessageDelayed(0, 2000);
|
||||
}
|
||||
|
||||
private void updateWifiScanResult () {
|
||||
|
||||
if (mScanResultList != null && mScanResultList.size() > 0) {
|
||||
mScanUser.setText("点击头像开始发送");
|
||||
mScanUserDes.setVisibility(View.GONE);
|
||||
} else {
|
||||
mScanUserDes.setVisibility(View.VISIBLE);
|
||||
mScanUser.setText("正在寻找周围的小伙伴...");
|
||||
}
|
||||
|
||||
if (mScanResultList != null) {
|
||||
mScanResultList.clear();
|
||||
}
|
||||
|
||||
choosereceiver_user1.setVisibility(View.GONE);
|
||||
choosereceiver_user2.setVisibility(View.GONE);
|
||||
choosereceiver_user3.setVisibility(View.GONE);
|
||||
choosereceiver_user4.setVisibility(View.GONE);
|
||||
choosereceiver_user1.setEnabled(true);
|
||||
choosereceiver_user2.setEnabled(true);
|
||||
choosereceiver_user3.setEnabled(true);
|
||||
choosereceiver_user4.setEnabled(true);
|
||||
|
||||
WifiMgr.getInstance(this).startScan();
|
||||
mScanResultList = WifiMgr.getInstance(this).getScanResultList();
|
||||
Utils.log("======WifiCount::" + mScanResultList.size());
|
||||
mScanResultList = WifiUtils.filterWithNoPassword(mScanResultList);
|
||||
if(mScanResultList != null){
|
||||
for (int i = 0; i < mScanResultList.size(); i++) {
|
||||
ScanResult scanResult = mScanResultList.get(i);
|
||||
Utils.log(i + "=====" + scanResult.SSID );
|
||||
|
||||
int icon = 1;
|
||||
try {
|
||||
icon = Integer.parseInt(scanResult.SSID.substring(scanResult.SSID.length() - 1));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
choosereceiver_user1.setVisibility(View.VISIBLE);
|
||||
choosereceiver_user1_name.setText(scanResult.SSID);
|
||||
choosereceiver_user1.setOnClickListener(this);
|
||||
userIcon1.setImageURI(UserIconUtils.getUserIcon(icon));
|
||||
break;
|
||||
case 1:
|
||||
choosereceiver_user2.setVisibility(View.VISIBLE);
|
||||
choosereceiver_user2_name.setText(scanResult.SSID);
|
||||
choosereceiver_user2.setOnClickListener(this);
|
||||
userIcon2.setImageURI(UserIconUtils.getUserIcon(icon));
|
||||
break;
|
||||
case 2:
|
||||
choosereceiver_user3.setVisibility(View.VISIBLE);
|
||||
choosereceiver_user3_name.setText(scanResult.SSID);
|
||||
choosereceiver_user3.setOnClickListener(this);
|
||||
userIcon3.setImageURI(UserIconUtils.getUserIcon(icon));
|
||||
break;
|
||||
case 3:
|
||||
choosereceiver_user4.setVisibility(View.VISIBLE);
|
||||
choosereceiver_user4_name.setText(scanResult.SSID);
|
||||
choosereceiver_user4.setOnClickListener(this);
|
||||
userIcon4.setImageURI(UserIconUtils.getUserIcon(icon));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == choosereceiver_user1) {
|
||||
connReceiverWifi(0);
|
||||
} else if (v == choosereceiver_user2) {
|
||||
connReceiverWifi(1);
|
||||
} else if (v == choosereceiver_user3) {
|
||||
connReceiverWifi(2);
|
||||
} else if (v == choosereceiver_user4) {
|
||||
connReceiverWifi(3);
|
||||
}
|
||||
}
|
||||
|
||||
//1.连接网络
|
||||
private void connReceiverWifi(int connPosition) {
|
||||
|
||||
if (isStopScan) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 进入动画页面
|
||||
readyAnimView();
|
||||
|
||||
handler.sendEmptyMessageDelayed(2, 30000);
|
||||
|
||||
Utils.log("======开始连接热点");
|
||||
mScanUser.setText("开始连接对方设备...");
|
||||
isStopScan = true;
|
||||
// choosereceiver_user1.setEnabled(false);
|
||||
// choosereceiver_user2.setEnabled(false);
|
||||
// choosereceiver_user3.setEnabled(false);
|
||||
// choosereceiver_user4.setEnabled(false);
|
||||
|
||||
// handler.postAtTime(new Runnable() { // 5s后还收不到接收者的回馈消息 重新回到扫描页面
|
||||
// @Override
|
||||
// public void run() {
|
||||
// Utils.log("==========aa" + isConnSuccess);
|
||||
// if (!isConnSuccess) {
|
||||
// isStopScan = false;
|
||||
// updateWifiScanResult();
|
||||
// }
|
||||
// }
|
||||
// }, 5000);
|
||||
|
||||
String ssid = "ghzs";
|
||||
ssid = mScanResultList.get(connPosition).SSID;
|
||||
WifiMgr.getInstance(this).openWifi();
|
||||
WifiMgr.getInstance(this).addNetwork(WifiMgr.createWifiCfg(ssid, null, WifiMgr.WIFICIPHER_NOPASS));
|
||||
|
||||
try {
|
||||
conUserIconTag = Integer.parseInt(ssid.substring(ssid.length() - 1));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
createSendMsgToServerRunnable(WifiMgr.getInstance(this).getIpAddressFromHotspot());
|
||||
}
|
||||
|
||||
//发送UDP通知信息到 文件接收方 开启ServerSocketRunnable
|
||||
private void createSendMsgToServerRunnable(final String ipAddress) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
startFileSenderServer(ipAddress);
|
||||
} catch (Exception e) {
|
||||
isStopScan = false;
|
||||
handler.sendEmptyMessage(0);
|
||||
Utils.log("UDP通信异常--startFileSenderServer" + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void startFileSenderServer(String ipAddress) throws Exception {
|
||||
int serverPort = Constant.DEFAULT_SERVER_COM_PORT;
|
||||
|
||||
// 确保Wifi连接上之后获取得到IP地址
|
||||
int count = 0;
|
||||
while(ipAddress.equals(Constant.DEFAULT_UNKOWN_IP) && count < Constant.DEFAULT_TRY_TIME) {
|
||||
Thread.sleep(1000);
|
||||
ipAddress = WifiMgr.getInstance(ChooseReceiverActivity.this).getIpAddressFromHotspot();
|
||||
count ++;
|
||||
}
|
||||
|
||||
// 即使获取到连接的热点wifi的IP地址也是无法连接网络 所以采取此策略
|
||||
count = 0;
|
||||
while(!WifiUtils.pingIpAddress(ipAddress) && count < Constant.DEFAULT_TRY_TIME) {
|
||||
Thread.sleep(500);
|
||||
count ++;
|
||||
}
|
||||
|
||||
if (mDatagramSocket == null) {
|
||||
mDatagramSocket = new DatagramSocket(null);
|
||||
mDatagramSocket.setReuseAddress(true);
|
||||
mDatagramSocket.bind(new InetSocketAddress(serverPort));
|
||||
}
|
||||
// mDatagramSocket = new DatagramSocket(serverPort);
|
||||
byte[] receiveData = new byte[1024];
|
||||
byte[] sendData;
|
||||
Utils.log("=====ip::" + ipAddress);
|
||||
if (!ipAddress.equals("192.168.43.1")) {
|
||||
// 连接失败,可能是连接的热点已经关闭, 关闭动画,开启扫描
|
||||
isStopScan = false;
|
||||
handler.sendEmptyMessage(0);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
connFailedAnimView();
|
||||
}
|
||||
});
|
||||
}
|
||||
InetAddress ipAddressName = InetAddress.getByName(ipAddress); // 转译
|
||||
|
||||
//发送 即将发送的文件列表 到文件接收方
|
||||
sendFileInfoListToFileReceiverWithUdp(serverPort, ipAddressName);
|
||||
|
||||
//发送 文件接收方 初始化
|
||||
|
||||
JSONObject senderData = new JSONObject();
|
||||
senderData.put(Constant.MSG_FILE_RECEIVER_INIT, sp.getString("user_name", "光环用户"));
|
||||
senderData.put("UserIcon", sp.getInt("default_user_icon", 1));
|
||||
|
||||
sendData = senderData.toString().getBytes(BaseTransfer.UTF_8);
|
||||
DatagramPacket sendPacket =
|
||||
new DatagramPacket(sendData, sendData.length, ipAddressName, serverPort);
|
||||
mDatagramSocket.send(sendPacket);
|
||||
|
||||
while(!isDestroy) {
|
||||
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
|
||||
mDatagramSocket.receive(receivePacket);
|
||||
String response = new String(receivePacket.getData(), 0, receivePacket.getLength()).trim();
|
||||
Utils.log("ChooseReceiverActivity:: 接收UDP请求" + response);
|
||||
|
||||
if(response != null && response.contains(Constant.MSG_FILE_RECEIVER_INIT_SUCCESS)) {
|
||||
JSONObject jsonObject = new JSONObject(response);
|
||||
Utils.log("ChooseReceiverActivity:: 收到UDP请求::SUCCESS=" + jsonObject.getString(Constant.MSG_FILE_RECEIVER_INIT_SUCCESS));
|
||||
|
||||
Map<String, String> userMap = new HashMap<>();
|
||||
userMap.put("receiverName", jsonObject.getString(Constant.MSG_FILE_RECEIVER_INIT_SUCCESS));
|
||||
userMap.put("usericon", String.valueOf(conUserIconTag));
|
||||
|
||||
AppController.put("userMap", userMap);
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
connSuccessAnimView();
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void sendFileInfoListToFileReceiverWithUdp(int serverPort, InetAddress ipAddress) {
|
||||
List<FileInfo> fileInfos = (List<FileInfo>) AppController.get("FileInfo", false);
|
||||
|
||||
for (FileInfo fileInfo : fileInfos) {
|
||||
String fileInfoJson = FileInfo.toJsonStr(fileInfo);
|
||||
Utils.log("ChooseReceiverActivity:: 发送的文件列表::" + fileInfoJson);
|
||||
DatagramPacket sendFileInfoListPacket =
|
||||
new DatagramPacket(fileInfoJson.getBytes(), fileInfoJson.getBytes().length, ipAddress, serverPort);
|
||||
try{
|
||||
mDatagramSocket.send(sendFileInfoListPacket);
|
||||
Utils.log("ChooseReceiverActivity:: UDP通知 Success::" + ipAddress + "==" + serverPort);
|
||||
} catch (Exception e) {
|
||||
Utils.log("ChooseReceiverActivity:: UDP通知 Failure!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 连接中-动画
|
||||
private void readyAnimView() {
|
||||
mActionbar.setVisibility(View.GONE);
|
||||
mRoketRl.setVisibility(View.VISIBLE);
|
||||
mRoketRl.animate()
|
||||
.alpha(1f)
|
||||
.setDuration(1000)
|
||||
.setListener(null);
|
||||
|
||||
mScaleAnimation = new ScaleAnimation(0.5f, 0.8f, 0.5f, 0.8f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
|
||||
mScaleAnimation.setDuration(250);
|
||||
mScaleAnimation.setRepeatCount(Animation.INFINITE);
|
||||
mScaleAnimation.setRepeatMode(Animation.REVERSE);
|
||||
|
||||
mRoketAnimLeft.startAnimation(mScaleAnimation);
|
||||
mRoketAnimRight.startAnimation(mScaleAnimation);
|
||||
}
|
||||
|
||||
// 连接成功-动画
|
||||
private void connSuccessAnimView() {
|
||||
handler.removeMessages(2);
|
||||
|
||||
if (mScaleAnimation != null) {
|
||||
mScaleAnimation.cancel();
|
||||
}
|
||||
AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0.6f);
|
||||
alphaAnimation.setDuration(250);
|
||||
alphaAnimation.setRepeatCount(Animation.INFINITE);
|
||||
alphaAnimation.setRepeatMode(Animation.REVERSE);
|
||||
mRoketAnimLeft.startAnimation(alphaAnimation);
|
||||
mRoketAnimRight.startAnimation(alphaAnimation);
|
||||
|
||||
mScaleAnimation = new ScaleAnimation(0.5f, 0.8f, 0.5f, 0.8f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
|
||||
mScaleAnimation.setDuration(250);
|
||||
mScaleAnimation.setRepeatCount(Animation.INFINITE);
|
||||
mScaleAnimation.setRepeatMode(Animation.REVERSE);
|
||||
|
||||
mRoketAnimLeft.setImageResource(R.drawable.kuaichuan_rocket_fire);
|
||||
mRoketAnimRight.setImageResource(R.drawable.kuaichuan_rocket_fire);
|
||||
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mRoketAnimRight.getLayoutParams();
|
||||
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.width = DisplayUtils.dip2px(this, 25);
|
||||
|
||||
mRoketAnimRight.setLayoutParams(layoutParams);
|
||||
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) mRoketAnimLeft.getLayoutParams();
|
||||
layoutParams2.height = LinearLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams2.width = DisplayUtils.dip2px(this, 25);
|
||||
|
||||
layoutParams2.setMargins(0, 0, DisplayUtils.dip2px(ChooseReceiverActivity.this, 14), 0);
|
||||
mRoketAnimLeft.setLayoutParams(layoutParams2);
|
||||
|
||||
|
||||
if (mScaleAnimation == null) {
|
||||
mScaleAnimation.cancel();
|
||||
}
|
||||
|
||||
mTranslateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1000);
|
||||
mTranslateAnimation.setDuration(1000);
|
||||
mTranslateAnimation.setInterpolator(new AccelerateInterpolator(2.0f));
|
||||
// mTranslateAnimation.setFillAfter(true);
|
||||
|
||||
mRoketAnimRl.startAnimation(mTranslateAnimation);
|
||||
|
||||
mTranslateAnimation.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
mRoketAnimRl.setVisibility(View.GONE);
|
||||
Intent intent = new Intent(ChooseReceiverActivity.this, FileSenderActivity.class);
|
||||
startActivity(intent);
|
||||
closeSocket();
|
||||
Intent resultIntent= new Intent();
|
||||
resultIntent.putExtra("isFinish", true);
|
||||
setResult(0x123, resultIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 连接失败-动画
|
||||
private void connFailedAnimView() {
|
||||
mActionbar.setVisibility(View.VISIBLE);
|
||||
Utils.toast(ChooseReceiverActivity.this, "连接失败");
|
||||
if (mScaleAnimation == null) {
|
||||
mScaleAnimation.cancel();
|
||||
}
|
||||
mRoketRl.animate()
|
||||
.alpha(0f)
|
||||
.setDuration(1000)
|
||||
.setListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mRoketRl.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
closeSocket();
|
||||
AppController.remove("FileInfo");
|
||||
}
|
||||
|
||||
@OnClick(R.id.actionbar_rl_back)
|
||||
public void onBackListener() {
|
||||
closeSocket();
|
||||
AppController.remove("FileInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
isStopScan = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭UDP Socket 流
|
||||
*/
|
||||
private void closeSocket(){
|
||||
isStopScan = true;
|
||||
if(mDatagramSocket != null) {
|
||||
// mDatagramSocket.disconnect();
|
||||
mDatagramSocket.close();
|
||||
mDatagramSocket = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
224
app/src/main/java/com/gh/gamecenter/CleanApkActivity.java
Normal file
224
app/src/main/java/com/gh/gamecenter/CleanApkActivity.java
Normal file
@ -0,0 +1,224 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.CleanApkAdapter;
|
||||
import com.gh.gamecenter.entity.InstallGameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/24.
|
||||
*/
|
||||
public class CleanApkActivity extends BaseActivity implements CleanApkAdapter.OnScanListener {
|
||||
|
||||
@BindView(R.id.apk_count) TextView mApkCount;
|
||||
@BindView(R.id.apk_rv) RecyclerView mApkRv;
|
||||
@BindView(R.id.delete_btn) TextView mApkDeleteBtn;
|
||||
@BindView(R.id.select_game_all) CheckBox mApkSelectAll;
|
||||
@BindView(R.id.scan_pb) ProgressBar mScanPb;
|
||||
@BindView(R.id.reuse_nodata_skip_tv_hint) TextView mNodataSkipTv;
|
||||
@BindView(R.id.reuse_nodata_skip_tv_btn) TextView mNodataSkipBtn;
|
||||
@BindView(R.id.reuse_nodata_skip) LinearLayout mNodataSkipLl;
|
||||
@BindView(R.id.delete_bottom) LinearLayout mDeleteBottom;
|
||||
@BindView(R.id.select_game_installed_ll) RelativeLayout mInstallAllData;
|
||||
|
||||
private CleanApkAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_clean_apk, null);
|
||||
init(contentView, "安装包清理");
|
||||
|
||||
mNodataSkipLl.setVisibility(View.GONE);
|
||||
|
||||
mAdapter = new CleanApkAdapter(this, mApkDeleteBtn, mApkSelectAll);
|
||||
mApkRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
mApkRv.addItemDecoration(new VerticalItemDecoration(this, 8, true));
|
||||
mApkRv.setAdapter(mAdapter);
|
||||
|
||||
mApkSelectAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
ArrayMap<Integer, Boolean> selectPosition = new ArrayMap<>();
|
||||
ArrayMap<Integer, Boolean> selectPosition1 = mAdapter.getSelectPosition();
|
||||
int itemCount = mAdapter.getItemCount();
|
||||
if (isChecked) {
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
selectPosition.put(i, true);
|
||||
}
|
||||
} else {
|
||||
int selectCount = 0;
|
||||
for (Integer integer : selectPosition1.keySet()) {
|
||||
if (selectPosition1.get(integer)) {
|
||||
selectCount ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectCount != itemCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
selectPosition.put(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
mAdapter.setSelectPosition(selectPosition);
|
||||
mAdapter.notifyItemRangeChanged(0, itemCount);
|
||||
mAdapter.checkBoxControl(isChecked, 0);
|
||||
}
|
||||
});
|
||||
|
||||
mNodataSkipBtn.setText("去首页看看");
|
||||
mNodataSkipTv.setText("安装包已清理干净\n快去发现更多好玩的游戏吧!");
|
||||
mNodataSkipTv.setLineSpacing(0, 1.5f);
|
||||
|
||||
}
|
||||
|
||||
@OnClick({R.id.delete_btn, R.id.reuse_nodata_skip_tv_btn})
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.delete_btn: {
|
||||
String s = mApkDeleteBtn.getText().toString();
|
||||
if ("停止扫描".equals(s)) {
|
||||
mAdapter.isStopScan();
|
||||
} else {
|
||||
if (s.equals("一键删除")) {
|
||||
Utils.toast(CleanApkActivity.this, "请选择需要删除的安装包");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<InstallGameEntity> apkList = mAdapter.getApkList();
|
||||
final ArrayMap<Integer, Boolean> selectPosition = mAdapter.getSelectPosition();
|
||||
|
||||
for (int i = 0; i < apkList.size(); i++) {
|
||||
if (selectPosition.get(i) && apkList.get(i).getInstallStatus() == 1) {
|
||||
DialogUtils.showWarningDialog(CleanApkActivity.this, "删除安装包"
|
||||
, Html.fromHtml("你选择的安装包中包含"+ "<font color=\"#ff0000\">未安装</font>"
|
||||
+"的应用,确定删除吗?"), "取消 ", "确定"
|
||||
, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
deleteApk(apkList, selectPosition);
|
||||
}
|
||||
}, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
deleteApk(apkList, selectPosition);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case R.id.reuse_nodata_skip_tv_btn: {
|
||||
Intent intent = new Intent(CleanApkActivity.this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
EventBus.getDefault().post(new EBSkip("GameFragment", 0));
|
||||
}
|
||||
}.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteApk(List<InstallGameEntity> apkList, ArrayMap<Integer, Boolean> selectPosition) {
|
||||
long size = 0;
|
||||
for (int i = 0; i < apkList.size(); i++) {
|
||||
if (selectPosition.get(i)) {
|
||||
InstallGameEntity installGameEntity = apkList.get(i);
|
||||
size = size + installGameEntity.getGameSize();
|
||||
File file = new File(installGameEntity.getGamePath());
|
||||
if (file.isFile() && file.exists()) {
|
||||
file.delete();
|
||||
mAdapter.deleteApk(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double allSize = (((float)size/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
String sizeName = df.format(allSize) + "MB";
|
||||
Utils.toast(CleanApkActivity.this, "删除成功,已为您节省" + sizeName + "空间");
|
||||
mApkDeleteBtn.setText("一键删除");
|
||||
mAdapter.notifyDataSetChanged(); // 刷新Adapter position
|
||||
|
||||
updateScanData();
|
||||
|
||||
if (apkList.size() == 0) { // 全部删除
|
||||
mNodataSkipLl.setVisibility(View.VISIBLE);
|
||||
mInstallAllData.setVisibility(View.GONE);
|
||||
mDeleteBottom.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateScanData(){
|
||||
long allSize = 0;
|
||||
List<InstallGameEntity> apkList = mAdapter.getApkList();
|
||||
for (InstallGameEntity installGameEntity : apkList) {
|
||||
allSize = allSize + installGameEntity.getGameSize();
|
||||
}
|
||||
|
||||
double size = (((float)allSize/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String sizeName = df.format(size) + "MB";
|
||||
|
||||
mApkCount.setText(Html.fromHtml("找到" + apkList.size() + "个安装包,占用"
|
||||
+ "<font color=\"#ff4147\">" + sizeName + "</font>"+ "空间"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanOver() {
|
||||
mApkDeleteBtn.setText("立即删除");
|
||||
mApkDeleteBtn.setBackgroundResource(R.drawable.game_item_btn_red_style);
|
||||
|
||||
updateScanData();
|
||||
|
||||
mScanPb.setVisibility(View.GONE);
|
||||
mApkSelectAll.setVisibility(View.VISIBLE);
|
||||
mApkSelectAll.setChecked(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noData() {
|
||||
mNodataSkipBtn.setText("去首页看看");
|
||||
mNodataSkipTv.setText("暂无安装包");
|
||||
mNodataSkipLl.setVisibility(View.VISIBLE);
|
||||
mInstallAllData.setVisibility(View.GONE);
|
||||
mDeleteBottom.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.gamecenter.adapter.CommentDetailAdapter;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/22.
|
||||
*/
|
||||
public class CommentDetailActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.comment_detail_rv) RecyclerView mRecyclerView;
|
||||
|
||||
private CommentDetailAdapter mAdapter;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View view = View.inflate(this, R.layout.activity_comment_detail, null);
|
||||
init(view, "查看对话");
|
||||
|
||||
String commentId = getIntent().getExtras().getString("commentId");
|
||||
|
||||
mAdapter = new CommentDetailAdapter(this, commentId);
|
||||
mLayoutManager = new LinearLayoutManager(this);
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE && !mAdapter.isOver() && !mAdapter.isLoading()) {
|
||||
mAdapter.loadData(mAdapter.getItemCount());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -117,8 +117,8 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
concernInfo.setConcern(true);
|
||||
concernInfo.setIcon(gameEntity.getIcon());
|
||||
concernInfo.setId(gameEntity.getId());
|
||||
concernAdapter.getConcernList().add(concernInfo);
|
||||
concernAdapter.getConcernGameList().add(gameEntity);
|
||||
concernAdapter.getConcernList().add(0, concernInfo);
|
||||
concernAdapter.getConcernGameList().add(0, gameEntity);
|
||||
if (reuse_none_data.getVisibility() == View.VISIBLE) {
|
||||
reuse_none_data.setVisibility(View.GONE);
|
||||
concern_rv_show.setVisibility(View.VISIBLE);
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
@ -28,6 +31,8 @@ import org.json.JSONObject;
|
||||
import java.io.File;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import butterknife.BindView;
|
||||
import rx.Observable;
|
||||
@ -42,6 +47,8 @@ public class CropImageActivity extends BaseActivity {
|
||||
|
||||
private SoftReference<Bitmap> reference;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
@ -63,6 +70,8 @@ public class CropImageActivity extends BaseActivity {
|
||||
|
||||
init(contentView, "图片裁剪");
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) findViewById(R.id.reuse_actionbar);
|
||||
|
||||
TextView confirm = new TextView(this);
|
||||
@ -135,11 +144,36 @@ public class CropImageActivity extends BaseActivity {
|
||||
try {
|
||||
int statusCode = result.getInt("statusCode");
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
handler.sendEmptyMessage(0);
|
||||
|
||||
String iconCount = sp.getString("updateIconCount", null);
|
||||
|
||||
long l = System.currentTimeMillis();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
||||
String time = format.format(new Date(l));
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("time", time);
|
||||
|
||||
if (TextUtils.isEmpty(iconCount)) {
|
||||
jsonObject.put("count", 1);
|
||||
} else {
|
||||
JSONObject json = new JSONObject(iconCount);
|
||||
String lastTime = json.getString("time");
|
||||
if (lastTime.equals(time)) {
|
||||
jsonObject.put("count", json.getInt("count") + 1);
|
||||
} else {
|
||||
jsonObject.put("count", 1);
|
||||
}
|
||||
}
|
||||
|
||||
sp.edit().putString("updateIconCount", jsonObject.toString()).apply();
|
||||
|
||||
Intent data = new Intent();
|
||||
data.putExtra("url", result.getString("icon"));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
handler.sendEmptyMessage(0);
|
||||
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN
|
||||
&& "too frequent".equals(result.getString("detail"))) {
|
||||
handler.sendEmptyMessage(2);
|
||||
|
||||
@ -15,6 +15,7 @@ import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.FragmentAdapter;
|
||||
import com.gh.gamecenter.download.FileSendFragment;
|
||||
import com.gh.gamecenter.download.GameDownLoadFragment;
|
||||
import com.gh.gamecenter.download.GameUpdateFragment;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
@ -42,8 +43,10 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
@BindView(R.id.downloadmanager_tv_download) TextView downloadmanager_tv_download;
|
||||
@BindView(R.id.downloadmanager_tv_update) TextView downloadmanager_tv_update;
|
||||
@BindView(R.id.downloadmanager_download_number) TextView downloadmanager_download_number;
|
||||
@BindView(R.id.downloadmanager_tv_send) TextView downloadmanager_tv_send;
|
||||
@BindView(R.id.downloadmanager_update_number) TextView downloadmanager_update_number;
|
||||
@BindView(R.id.downloadmanager_ll_download) LinearLayout downloadmanager_ll_download;
|
||||
@BindView(R.id.downloadmanager_ll_send) LinearLayout downloadmanager_ll_send;
|
||||
@BindView(R.id.downloadmanager_ll_update) LinearLayout downloadmanager_ll_update;
|
||||
@BindView(R.id.downloadmanager_slide_line) View downloadmanager_slide_line;
|
||||
|
||||
@ -68,6 +71,7 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
|
||||
downloadmanager_ll_download.setOnClickListener(this);
|
||||
downloadmanager_ll_update.setOnClickListener(this);
|
||||
downloadmanager_ll_send.setOnClickListener(this);
|
||||
|
||||
int updateSize = PackageManager.getUpdateList().size();
|
||||
if (updateSize != 0) {
|
||||
@ -95,21 +99,19 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
}
|
||||
if (currentItem == -1) {
|
||||
if (updateSize != 0 && downloadSize == 0) {
|
||||
currentItem = 1;
|
||||
} else {
|
||||
currentItem = 0;
|
||||
}
|
||||
currentItem = 1; //默认游戏下载页面
|
||||
}
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / 2;
|
||||
lparams = new LinearLayout.LayoutParams(width / 2, DisplayUtils.dip2px(getApplicationContext(), 2));
|
||||
lparams.leftMargin = (int) (width * (currentItem + 0.25f));
|
||||
width = outMetrics.widthPixels / 3;
|
||||
lparams = new LinearLayout.LayoutParams((int)(width * 0.7),
|
||||
DisplayUtils.dip2px(getApplicationContext(), 2));
|
||||
lparams.leftMargin = (int) (width * (currentItem + 0.17f));
|
||||
downloadmanager_slide_line.setLayoutParams(lparams);
|
||||
|
||||
List<Fragment> list = new ArrayList<>();
|
||||
list.add(new FileSendFragment());
|
||||
list.add(new GameDownLoadFragment());
|
||||
list.add(new GameUpdateFragment());
|
||||
downloadmanager_viewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), list));
|
||||
@ -119,21 +121,27 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
if (position == 0) {
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 0));
|
||||
if (position == 1) {
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 1));
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.theme));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.title));
|
||||
} else {
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 1));
|
||||
downloadmanager_tv_send.setTextColor(getResources().getColor(R.color.title));
|
||||
} else if (position == 2){
|
||||
EventBus.getDefault().post(new EBUISwitch("DownloadManagerActivity", 2));
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.theme));
|
||||
downloadmanager_tv_send.setTextColor(getResources().getColor(R.color.title));
|
||||
} else {
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_send.setTextColor(getResources().getColor(R.color.theme));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
lparams.leftMargin = (int) (width * (positionOffset + 0.25f));
|
||||
lparams.leftMargin = (int) (width * (position + positionOffset + 0.17f));
|
||||
downloadmanager_slide_line.setLayoutParams(lparams);
|
||||
}
|
||||
}
|
||||
@ -149,9 +157,11 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
if (id == R.id.actionbar_rl_back) {
|
||||
finish();
|
||||
} else if (id == R.id.downloadmanager_ll_download) {
|
||||
downloadmanager_viewPager.setCurrentItem(0);
|
||||
} else if (id == R.id.downloadmanager_ll_update) {
|
||||
downloadmanager_viewPager.setCurrentItem(1);
|
||||
} else if (id == R.id.downloadmanager_ll_update) {
|
||||
downloadmanager_viewPager.setCurrentItem(2);
|
||||
} else if (id == R.id.downloadmanager_ll_send) {
|
||||
downloadmanager_viewPager.setCurrentItem(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,7 +208,7 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
|
||||
public void onEventMainThread(EBSkip skip) {
|
||||
if ("DownloadManagerActivity".equals(skip.getType())) {
|
||||
if (skip.getCurrentItem() == 0) {
|
||||
if (skip.getCurrentItem() == 1) {
|
||||
handler.postDelayed(runnable, 300);
|
||||
}
|
||||
}
|
||||
|
||||
634
app/src/main/java/com/gh/gamecenter/FileReceiverActivity.java
Normal file
634
app/src/main/java/com/gh/gamecenter/FileReceiverActivity.java
Normal file
@ -0,0 +1,634 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.NotificationUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadDao;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.adapter.FileReceiverAdapter;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.kuaichuan.BaseTransfer;
|
||||
import com.gh.gamecenter.kuaichuan.Constant;
|
||||
import com.gh.gamecenter.kuaichuan.FileInfo;
|
||||
import com.gh.gamecenter.kuaichuan.FileReceiver;
|
||||
import com.gh.gamecenter.kuaichuan.HotspotManager;
|
||||
import com.gh.gamecenter.kuaichuan.IpPortInfo;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/20.
|
||||
*/
|
||||
public class FileReceiverActivity extends BaseActivity implements FileReceiverAdapter.OnReceiverCancelListener{
|
||||
|
||||
@BindView(R.id.sender_rv) RecyclerView mReceiverRv;
|
||||
@BindView(R.id.sender_user_icon) SimpleDraweeView mSenderUserIcon;
|
||||
@BindView(R.id.sender_user_name) TextView mSenderUserName;
|
||||
@BindView(R.id.sender_user_send_des) TextView mSenderUserDes;
|
||||
@BindView(R.id.sender_hint) TextView mSenderHint;
|
||||
@BindView(R.id.sender_bottom) LinearLayout mReceiverBottom;
|
||||
@BindView(R.id.sender_keep_send) RelativeLayout mKeepReceiver;
|
||||
@BindView(R.id.sender_keep_send_tv) TextView mKeepReceiverTv;
|
||||
@BindView(R.id.sender_bottom_hint) TextView mReceiverBottomHint;
|
||||
@BindView(R.id.sender_bottom_control) LinearLayout mReceiverControl;
|
||||
|
||||
private FileReceiverAdapter mFileReceiverAdapter;
|
||||
|
||||
private FileInfo mCurFileInfo;
|
||||
|
||||
private List<FileInfo> mFileInfos;
|
||||
|
||||
private List<Map<String, String>> sendData; // 传送成绩单数据
|
||||
|
||||
private IpPortInfo mIpPortInfo;
|
||||
|
||||
private ServerRunnable mReceiverServer;
|
||||
|
||||
private FileReceiver mFileReceiver;
|
||||
|
||||
private DatagramSocket mDatagramSocket;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private boolean isReceivesOver;
|
||||
private boolean isOpenWifi; //记录开热点前的WiFi状态
|
||||
private boolean isDestroy;
|
||||
|
||||
|
||||
Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (mFileInfos == null) {
|
||||
Utils.log("接收器出现异常");
|
||||
return;
|
||||
}
|
||||
|
||||
int index = getCurrentFileInfoIndex();
|
||||
if (index == -100) {
|
||||
Utils.toast(FileReceiverActivity.this, "接收失败");
|
||||
colsePage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (index == -1) {
|
||||
// Utils.toast(FileReceiverActivity.this, " 获取刷新位置异常");
|
||||
return;
|
||||
}
|
||||
FileInfo fileInfo = mFileInfos.get(index);
|
||||
if (msg.what == FileInfo.FLAG_DEFAULT) { // 传输中更新界面
|
||||
long progress = (long) msg.obj;
|
||||
fileInfo.setProgress(progress);
|
||||
fileInfo.setResult(FileInfo.FLAG_DEFAULT);
|
||||
} else if (msg.what == FileInfo.FLAG_SUCCESS) { // 传输成功更新界面
|
||||
fileInfo.setResult(FileInfo.FLAG_SUCCESS);
|
||||
if (index == mFileInfos.size() -1) initSenderHint(false);
|
||||
} else if (msg.what == FileInfo.FLAG_FAILURE) { // 传输失败更新界面
|
||||
fileInfo.setResult(FileInfo.FLAG_FAILURE);
|
||||
if (index == mFileInfos.size() -1) initSenderHint(false);
|
||||
} else if (msg.what == FileInfo.FLAG_CANCEL) { // 传输取消更新界面
|
||||
fileInfo.setResult(FileInfo.FLAG_CANCEL);
|
||||
if (index == mFileInfos.size() -1) initSenderHint(false);
|
||||
} else if (msg.what == FileInfo.FLAG_NO_MEMORY) {
|
||||
Utils.toast(FileReceiverActivity.this, "手机空间不足");
|
||||
fileInfo.setResult(FileInfo.FLAG_NO_MEMORY); // 接收方内存不足
|
||||
if (index == mFileInfos.size() -1) initSenderHint(true);
|
||||
}
|
||||
|
||||
Utils.log("FileReceiverActivity:: 刷新位置::" + index + "刷新状态::" + msg.what);
|
||||
mFileReceiverAdapter.notifyItemChanged(index);
|
||||
}
|
||||
};
|
||||
|
||||
private int getCurrentFileInfoIndex() {
|
||||
for (int i = 0; i < mFileInfos.size(); i++) {
|
||||
FileInfo fileInfo = mFileInfos.get(i);
|
||||
if (mCurFileInfo == null) {
|
||||
return -100;
|
||||
}
|
||||
Utils.log("===============" + fileInfo.getFileTag() + "====" + mCurFileInfo.getFileTag());
|
||||
Utils.log("===============" + fileInfo.getName() + "====" + mCurFileInfo.getName());
|
||||
if (fileInfo.getFileTag().equals(mCurFileInfo.getFileTag())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Utils.log("FileReceiverActivity:: 获取刷新位置异常" + mFileInfos.size());
|
||||
mFileInfos.add(mCurFileInfo);
|
||||
|
||||
return mFileInfos.size() - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_file_sender, null);
|
||||
init(contentView, "接收游戏");
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
// mFileInfos = (List<FileInfo>) AppController.get("FileInfo", false);
|
||||
|
||||
sendData = new ArrayList<>();
|
||||
|
||||
mIpPortInfo = (IpPortInfo) getIntent().getSerializableExtra(Constant.KEY_IP_PORT_INFO);
|
||||
isOpenWifi = getIntent().getBooleanExtra("isOpenWifi", false);
|
||||
ArrayList<Parcelable> list = getIntent().getParcelableArrayListExtra(Constant.KEY_IP_FILE_INFO);
|
||||
mFileInfos = (List<FileInfo>) list.get(0);
|
||||
|
||||
mFileReceiverAdapter = new FileReceiverAdapter(this, mFileInfos);
|
||||
mReceiverRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
mReceiverRv.setAdapter(mFileReceiverAdapter);
|
||||
|
||||
|
||||
mKeepReceiverTv.setText("继续接收");
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
initUserData();
|
||||
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 200);
|
||||
} else {
|
||||
initServer(); //启动接收服务
|
||||
}
|
||||
|
||||
findViewById(R.id.actionbar_rl_back).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
backHint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initUserData() {
|
||||
isReceivesOver = false;
|
||||
|
||||
long allGameSize = 0;
|
||||
for (FileInfo mFileInfo : mFileInfos) {
|
||||
allGameSize = allGameSize + mFileInfo.getSize();
|
||||
}
|
||||
|
||||
double size = (((float)allGameSize/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
String sizeName = df.format(size) + "MB";
|
||||
|
||||
mSenderUserDes.setText(mFileInfos.size() + "个游戏,共" + sizeName);
|
||||
mSenderUserName.setText("来自 " + mIpPortInfo.getSenderName());
|
||||
mSenderUserIcon.setImageURI(UserIconUtils.getUserIcon(mIpPortInfo.getSenderIcon()));
|
||||
|
||||
mReceiverBottom.setVisibility(View.GONE);
|
||||
|
||||
mSenderHint.setText("已连接");
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启文件接收端服务
|
||||
*/
|
||||
private void initServer() {
|
||||
mReceiverServer = new ServerRunnable(Constant.DEFAULT_SERVER_PORT);
|
||||
new Thread(mReceiverServer).start();
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
receiverData();
|
||||
} catch (Exception e) {
|
||||
Utils.log("FileReceiverActivity:: UDP请求异常" + e.toString() );
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
private void receiverData() throws Exception {
|
||||
if (mDatagramSocket == null) {
|
||||
mDatagramSocket = new DatagramSocket(Constant.DEFAULT_SERVER_SENDING_PORT);
|
||||
mDatagramSocket.setBroadcast(true);
|
||||
}
|
||||
|
||||
byte[] receiveData = new byte[1024];
|
||||
|
||||
Utils.log("FileReceiverActivity:: 开始接收UDP请求::" + Constant.DEFAULT_SERVER_SENDING_PORT + "::" +mDatagramSocket.getInetAddress());
|
||||
while (!isDestroy) {
|
||||
Utils.log("FileReceiverActivity:: 开始接收UDP请求" );
|
||||
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
|
||||
mDatagramSocket.receive(receivePacket);
|
||||
String response = new String(receivePacket.getData(), 0, receivePacket.getLength()).trim();
|
||||
Utils.log("FileReceiverActivity:: 接收UDP请求" + response);
|
||||
if (response != null && response.equals(Constant.MSG_ADD_DATA_OVER)) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mFileReceiverAdapter.update();
|
||||
initUserData();
|
||||
}
|
||||
});
|
||||
|
||||
sendMessageToSender(Constant.MSG_ADD_DATA_OVER);
|
||||
Utils.log("FileReceiverActivity:: 回复信息" + Constant.MSG_ADD_DATA_OVER);
|
||||
} else if (response != null) {
|
||||
parseFileInfo(response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析FileInfo
|
||||
* @param msg
|
||||
*/
|
||||
private void parseFileInfo(String msg) {
|
||||
// mFileInfos = (List<FileInfo>) AppController.get("FileInfo", false); // mFileInfos 数据异常 需要重新获取
|
||||
FileInfo fileInfo = FileInfo.toObject(msg);
|
||||
if(fileInfo != null && fileInfo.getFilePath() != null){
|
||||
mFileInfos.add(fileInfo);
|
||||
Utils.log("FileReceiverActivity 添加一条数据::" + msg);
|
||||
// AppController.put("FileInfo", mFileInfos);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnCancelPosition(final int position) {
|
||||
// if (position == getCurrentFileInfoIndex()) {
|
||||
// mFileReceiver.cancel();
|
||||
// } else {
|
||||
// Utils.toast(this, "在传送中的游戏才可以取消");
|
||||
// }
|
||||
|
||||
|
||||
Utils.log("接收方发送取消消息 让发送方取消");
|
||||
|
||||
|
||||
try {
|
||||
// 接收方更改界面
|
||||
FileInfo fileInfo = mFileInfos.get(position);
|
||||
fileInfo.setResult(FileInfo.FLAG_CANCEL);
|
||||
mFileReceiverAdapter.notifyItemChanged(position);
|
||||
|
||||
// 发消息让发送方取消
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("controlStatus", Constant.MSG_RECEIVER_CANCEL);
|
||||
jsonObject.put("controlTag", position);
|
||||
|
||||
sendMessageToSender(jsonObject.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//安装事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
for (int i = 0; i < mFileInfos.size(); i++) {
|
||||
FileInfo fileInfo = mFileInfos.get(i);
|
||||
if (fileInfo.getResult() == FileInfo.FLAG_SUCCESS &&
|
||||
fileInfo.getPackageName().equals(busFour.getPackageName())) {
|
||||
fileInfo.setResult(FileInfo.FLAG_INSTALLED);
|
||||
mFileReceiverAdapter.notifyItemChanged(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMessageToSender(final String sendData) throws Exception {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
byte[] bytes = sendData.getBytes(BaseTransfer.UTF_8);
|
||||
DatagramPacket sendPacket = new DatagramPacket(bytes, bytes.length, mIpPortInfo.getInetAddress(), Constant.DEFAULT_SERVER_SENDING_PORT);
|
||||
mDatagramSocket.send(sendPacket);
|
||||
|
||||
Utils.log("接收方消息已发送至接收方:" + sendData + "==" + mIpPortInfo.getInetAddress() + "==" + Constant.DEFAULT_SERVER_SENDING_PORT);
|
||||
} catch (Exception e) {
|
||||
Utils.log("接收方发送消息异常。。" + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* ServerSocket启动线程
|
||||
*/
|
||||
class ServerRunnable implements Runnable {
|
||||
ServerSocket serverSocket;
|
||||
private int port;
|
||||
|
||||
|
||||
public ServerRunnable(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Utils.log("接收线程:Socket已经开启");
|
||||
try {
|
||||
serverSocket = new ServerSocket(Constant.DEFAULT_SERVER_PORT);
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()){
|
||||
Socket socket = serverSocket.accept();
|
||||
|
||||
mFileReceiver = new FileReceiver(socket, FileReceiverActivity.this);
|
||||
mFileReceiver.setOnReceiveListener(new FileReceiver.OnReceiveListener() {
|
||||
private long mStartTime;
|
||||
private long mNormalStartTime;
|
||||
@Override
|
||||
public void onStart() {
|
||||
Utils.log("快传文件接收::onStart");
|
||||
mStartTime = Utils.getTime(FileReceiverActivity.this);
|
||||
mNormalStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetFileInfo(FileInfo fileInfo) { // 获取FileInfo
|
||||
mCurFileInfo = fileInfo;
|
||||
for (int i = 0; i < mFileInfos.size(); i++) {
|
||||
FileInfo info = mFileInfos.get(i);
|
||||
if (info.getName(). //NullPointerException
|
||||
equals(mCurFileInfo.getName())) {
|
||||
info.setBitmap(fileInfo.getBitmap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(long progress, long total) { // 获取传输进度
|
||||
// Utils.log("快传文件接收中..." + progress + "==" + total);
|
||||
Message message = new Message();
|
||||
message.what = FileInfo.FLAG_DEFAULT;
|
||||
message.obj = progress;
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() { // 获取传输成功
|
||||
handler.sendEmptyMessage(FileInfo.FLAG_SUCCESS);
|
||||
|
||||
String ghVersion = (String) PackageUtils.getMetaData(FileReceiverActivity.this
|
||||
, mCurFileInfo.getPackageName(), "gh_version");
|
||||
if (TextUtils.isEmpty(ghVersion)) {
|
||||
ghVersion = "";
|
||||
}
|
||||
|
||||
long sendTime = Utils.getTime(FileReceiverActivity.this) - mStartTime;
|
||||
|
||||
Map<String, Object> hashMap = new HashMap<>();
|
||||
hashMap.put("send_time", mStartTime);
|
||||
hashMap.put("receive_time", Utils.getTime(FileReceiverActivity.this));
|
||||
hashMap.put("game_name", mCurFileInfo.getName());
|
||||
hashMap.put("package_name", mCurFileInfo.getPackageName());
|
||||
hashMap.put("package_size", mCurFileInfo.getSize());
|
||||
hashMap.put("expend_time", sendTime);
|
||||
hashMap.put("send_nickname", mIpPortInfo.getSenderName());
|
||||
hashMap.put("receive_nickname", mIpPortInfo.getReceiverName());
|
||||
hashMap.put("receive_token", sp.getString("token", null));
|
||||
hashMap.put("package_gh_version", ghVersion);
|
||||
DataCollectionManager.onEvent(FileReceiverActivity.this, "transfer", hashMap, false);
|
||||
|
||||
|
||||
Utils.log("快传文件接收成功::onSuccess:: 发送事件::" + sendTime);
|
||||
|
||||
long sendNormalTime = System.currentTimeMillis() - mNormalStartTime;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("sendTime", String.valueOf(sendNormalTime));
|
||||
map.put("apkPath",Environment.getExternalStorageDirectory() + "/GH-KC/" + mCurFileInfo.getName() + ".apk");
|
||||
map.put("apkSize", String.valueOf(mCurFileInfo.getSize()));
|
||||
sendData.add(map);
|
||||
|
||||
NotificationUtils.showKuaiChuanDoneNotification(FileReceiverActivity.this,
|
||||
Environment.getExternalStorageDirectory() + "/GH-KC/" + mCurFileInfo.getName() + ".apk",
|
||||
mCurFileInfo.getName(), mCurFileInfo.getPackageName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) { // 获取传输失败
|
||||
Utils.log("快传文件接收失败::onFailure");
|
||||
handler.sendEmptyMessage(FileInfo.FLAG_FAILURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() { // 获取传输取消
|
||||
Utils.log("快传文件接收取消::onCancel");
|
||||
handler.sendEmptyMessage(FileInfo.FLAG_CANCEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoMemory() {
|
||||
handler.sendEmptyMessage(FileInfo.FLAG_NO_MEMORY);
|
||||
}
|
||||
});
|
||||
|
||||
AppController.MAIN_EXECUTOR.execute(mFileReceiver);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭Socket 通信
|
||||
*/
|
||||
public void close(){
|
||||
if(serverSocket != null){
|
||||
try {
|
||||
serverSocket.close();
|
||||
serverSocket = null;
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initSenderHint(boolean isNoMemory) {
|
||||
for (FileInfo mFileInfo : mFileInfos) {
|
||||
if (mFileInfo.getResult() == 0 || mFileInfo.getResult() == 1) { // 还有没完成的任务
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mReceiverBottom.setVisibility(View.VISIBLE);
|
||||
mReceiverControl.setVisibility(View.VISIBLE);
|
||||
|
||||
|
||||
isReceivesOver = true;
|
||||
int sendSuccess = 0;
|
||||
for (FileInfo mFileInfo : mFileInfos) {
|
||||
if (mFileInfo.getResult() == FileInfo.FLAG_SUCCESS) {
|
||||
sendSuccess ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (isNoMemory) {
|
||||
mKeepReceiverTv.setText("手机空间清理");
|
||||
}
|
||||
|
||||
if (sendSuccess > 0) {
|
||||
mSenderHint.setVisibility(View.VISIBLE);
|
||||
mSenderHint.setText("传输结束,成功接收" + sendSuccess + "个游戏");
|
||||
} else {
|
||||
if (mFileInfos.get(mFileInfos.size() - 1).getResult() == FileInfo.FLAG_CANCEL) {
|
||||
mSenderHint.setVisibility(View.VISIBLE);
|
||||
mSenderHint.setText("传输已取消");
|
||||
} else if (mFileInfos.get(mFileInfos.size() - 1).getResult() == FileInfo.FLAG_FAILURE) {
|
||||
mSenderHint.setVisibility(View.VISIBLE);
|
||||
mSenderHint.setText("传输失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
backHint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
}
|
||||
|
||||
@OnClick({R.id.actionbar_rl_back, R.id.sender_keep_send, R.id.sender_back})
|
||||
public void back(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.actionbar_rl_back:
|
||||
backHint();
|
||||
break;
|
||||
case R.id.sender_back:
|
||||
backHint();
|
||||
break;
|
||||
case R.id.sender_keep_send:
|
||||
if ("继续接收".equals(mKeepReceiverTv.getText())) {
|
||||
// mReceiverControl.setVisibility(View.GONE);
|
||||
mKeepReceiverTv.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
Utils.toast(FileReceiverActivity.this, "无需操作,请让对方继续发送即可");
|
||||
} else { // 跳转安装包清理
|
||||
Intent intent = new Intent(this, CleanApkActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void colsePage() {
|
||||
|
||||
if(mDatagramSocket != null) {
|
||||
// mDatagramSocket.disconnect();
|
||||
mDatagramSocket.close();
|
||||
mDatagramSocket = null;
|
||||
}
|
||||
|
||||
//关闭热点
|
||||
HotspotManager.initUserAp(this);
|
||||
|
||||
if (isOpenWifi) {
|
||||
WifiMgr.getInstance(this).openWifi();
|
||||
}
|
||||
|
||||
for (FileInfo fileInfo : mFileInfos) {
|
||||
if (fileInfo.getResult() == FileInfo.FLAG_SUCCESS) {
|
||||
DownloadEntity entry = new DownloadEntity();
|
||||
entry.setName(fileInfo.getName());
|
||||
entry.setSize(fileInfo.getSize());
|
||||
entry.setPackageName(fileInfo.getPackageName());
|
||||
entry.setPath(Environment.getExternalStorageDirectory() + "/GH-KC/" + fileInfo.getName() + ".apk");
|
||||
entry.setPercent(100.0);
|
||||
entry.setUrl(fileInfo.getFilePath()); //url拿 路径替代
|
||||
entry.setStatus(DownloadStatus.done);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("KuaiChuanIcon", Environment.getExternalStorageDirectory() + "/GH-KC/" + fileInfo.getName() + ".apk");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
entry.setIcon(jsonObject.toString());
|
||||
DownloadDao.getInstance(this).newOrUpdate(entry);
|
||||
}
|
||||
}
|
||||
List<DownloadEntity> all = DownloadDao.getInstance(this).getAll();
|
||||
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE, all.size()));
|
||||
EventBus.getDefault().post(new EBDownloadStatus("download"));
|
||||
|
||||
mReceiverServer.close();
|
||||
// AppController.remove("FileInfo");
|
||||
mFileInfos.clear();
|
||||
|
||||
AppController.put("sendData", sendData);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
private void backHint() {
|
||||
if (isReceivesOver) {
|
||||
colsePage();
|
||||
} else {
|
||||
DialogUtils.showWarningDialog(FileReceiverActivity.this, "退出提示", "退出会中断接收,确定要退出吗?"
|
||||
, "取消", "确定"
|
||||
, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
colsePage();
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
464
app/src/main/java/com/gh/gamecenter/FileSenderActivity.java
Normal file
464
app/src/main/java/com/gh/gamecenter/FileSenderActivity.java
Normal file
@ -0,0 +1,464 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.adapter.FileSenderAdapter;
|
||||
import com.gh.gamecenter.kuaichuan.Constant;
|
||||
import com.gh.gamecenter.kuaichuan.FileInfo;
|
||||
import com.gh.gamecenter.kuaichuan.FileSender;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/20.
|
||||
*/
|
||||
public class FileSenderActivity extends BaseActivity implements FileSenderAdapter.OnCancelListener {
|
||||
|
||||
@BindView(R.id.sender_rv) RecyclerView mSenderRv;
|
||||
@BindView(R.id.sender_user_icon) SimpleDraweeView mSenderUserIcon;
|
||||
@BindView(R.id.sender_user_name) TextView mSenderUserName;
|
||||
@BindView(R.id.sender_user_send_des) TextView mSenderUserDes;
|
||||
@BindView(R.id.sender_hint) TextView mSenderHint;
|
||||
@BindView(R.id.sender_keep_send) RelativeLayout mKeepSend;
|
||||
@BindView(R.id.sender_bottom) LinearLayout mSenderBottom;
|
||||
|
||||
private FileSenderAdapter mSenderAdapter;
|
||||
|
||||
private DatagramSocket mDatagramSocket;
|
||||
|
||||
private List<FileInfo> mFileInfos;
|
||||
private List<Map<String, String>> sendData; // 传送成绩单数据
|
||||
private List<FileSender> mFileSenderList;
|
||||
|
||||
private boolean isSendOver;
|
||||
private boolean isDestroy;
|
||||
|
||||
private long mStartTime;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.what == FileInfo.FLAG_DEFAULT) {
|
||||
int position = (int) msg.obj;
|
||||
mFileInfos.get(position).setResult(FileInfo.FLAG_DEFAULT);
|
||||
mSenderAdapter.notifyItemChanged(position);
|
||||
} else if (msg.what == FileInfo.FLAG_SUCCESS) {
|
||||
int position = (int) msg.obj;
|
||||
mFileInfos.get(position).setResult(FileInfo.FLAG_SUCCESS);
|
||||
mSenderAdapter.notifyItemChanged(position);
|
||||
if (position == mFileInfos.size() -1) initSenderHint();
|
||||
} else if (msg.what == FileInfo.FLAG_FAILURE) {
|
||||
int position = (int) msg.obj;
|
||||
mFileInfos.get(position).setResult(FileInfo.FLAG_FAILURE);
|
||||
mSenderAdapter.notifyItemChanged(position);
|
||||
if (position == mFileInfos.size() -1) initSenderHint();
|
||||
} else if (msg.what == FileInfo.FLAG_CANCEL) {
|
||||
int position = (int) msg.obj;
|
||||
mFileInfos.get(position).setResult(FileInfo.FLAG_CANCEL);
|
||||
mSenderAdapter.notifyItemChanged(position);
|
||||
if (position == mFileInfos.size() -1) initSenderHint();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_file_sender, null);
|
||||
init(contentView, "发送游戏");
|
||||
|
||||
mFileInfos = (List<FileInfo>) AppController.get("FileInfo", false);
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
sendData = new ArrayList<>();
|
||||
mFileSenderList = new ArrayList<>();
|
||||
mSenderAdapter = new FileSenderAdapter(this, mFileInfos);
|
||||
mSenderRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
mSenderRv.setAdapter(mSenderAdapter);
|
||||
|
||||
init();
|
||||
|
||||
findViewById(R.id.actionbar_rl_back).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
backHint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == 0x130 && requestCode == 0x178) {
|
||||
mSenderAdapter.notifyDataSetChanged();
|
||||
initUserData();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sendFileInfo();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendFileInfo() throws Exception {
|
||||
if (mDatagramSocket == null) {
|
||||
mDatagramSocket = new DatagramSocket(null);
|
||||
mDatagramSocket.setReuseAddress(true);
|
||||
mDatagramSocket.bind(new InetSocketAddress(Constant.DEFAULT_SERVER_SENDING_PORT));
|
||||
}
|
||||
String ipAddress = WifiMgr.getInstance(this).getIpAddressFromHotspot();
|
||||
InetAddress ipAddressName = InetAddress.getByName(ipAddress); // 转译
|
||||
//发送apk列表
|
||||
for (FileInfo fileInfo : mFileInfos) {
|
||||
if (fileInfo.getResult() == 0) { // 过滤已发送过的列表
|
||||
String fileInfoJson = FileInfo.toJsonStr(fileInfo);
|
||||
Utils.log("FileSenderActivity:: 发送的文件列表::" + fileInfoJson );
|
||||
DatagramPacket sendFileInfoListPacket = new DatagramPacket(fileInfoJson.getBytes()
|
||||
, fileInfoJson.getBytes().length, ipAddressName, Constant.DEFAULT_SERVER_SENDING_PORT);
|
||||
mDatagramSocket.send(sendFileInfoListPacket);
|
||||
Utils.log("FileSenderActivity:: 发送的文件列表完成::" + ipAddressName + "==" + Constant.DEFAULT_SERVER_SENDING_PORT);
|
||||
}
|
||||
}
|
||||
|
||||
DatagramPacket sendFileInfoListPacket = new DatagramPacket(Constant.MSG_ADD_DATA_OVER.getBytes()
|
||||
, Constant.MSG_ADD_DATA_OVER.getBytes().length, ipAddressName, Constant.DEFAULT_SERVER_SENDING_PORT);
|
||||
mDatagramSocket.send(sendFileInfoListPacket);
|
||||
Utils.log("FileSenderActivity:: 发送结束请求完成");
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
|
||||
Utils.log("FileSenderActivity == init()");
|
||||
|
||||
initUserData();
|
||||
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Constant.REQUEST_CODE_WRITE_FILE);
|
||||
} else{
|
||||
Utils.log("FileSenderActivity == initSendServer()" + mFileInfos.size());
|
||||
try {
|
||||
initSendServer();//开启传送文件
|
||||
startReceiver();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startReceiver() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
initTestReceiverData();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void initTestReceiverData() throws Exception {
|
||||
if (mDatagramSocket == null) {
|
||||
mDatagramSocket = new DatagramSocket(null);
|
||||
mDatagramSocket.setReuseAddress(true);
|
||||
mDatagramSocket.bind(new InetSocketAddress(Constant.DEFAULT_SERVER_SENDING_PORT));
|
||||
}
|
||||
Utils.log("接收方取消Socket端口" + Constant.DEFAULT_SERVER_SENDING_PORT);
|
||||
byte[] receiveData = new byte[1024];
|
||||
// 主要接收 接收方取消操作
|
||||
while (!isDestroy) {
|
||||
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
|
||||
mDatagramSocket.receive(receivePacket);
|
||||
String response = new String( receivePacket.getData(),0 , receivePacket.getLength()).trim();
|
||||
Utils.log("====接收取消消息中。。。" + response);
|
||||
if(response != null && response.contains(Constant.MSG_RECEIVER_CANCEL)){
|
||||
Utils.log("====接收取消消息完毕。。。" + response);
|
||||
|
||||
// 进入文件发送列表界面 (并且通知文件接收方进入文件接收列表界面)
|
||||
JSONObject jsonObject = new JSONObject(response);
|
||||
int cancelPosition = (int) jsonObject.get("controlTag");
|
||||
FileSender fileSender = mFileSenderList.get(cancelPosition);
|
||||
Message message = new Message();
|
||||
message.what = FileInfo.FLAG_CANCEL;
|
||||
message.obj = cancelPosition;
|
||||
handler.sendMessage(message);
|
||||
if (fileSender != null && fileSender.isRunning()) {
|
||||
Utils.log("接收方取消发送");
|
||||
fileSender.cancel();
|
||||
}
|
||||
} else if (response != null && response.contains(Constant.MSG_ADD_DATA_OVER)) {
|
||||
try {
|
||||
Utils.log("====收到UDP结束请求 开始传送文件");
|
||||
initSendServer();//开启传送文件
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//初始化用户数据
|
||||
private void initUserData() {
|
||||
isSendOver = false;
|
||||
|
||||
Map<String, String> map = (Map<String, String>) AppController.get("userMap", false);
|
||||
|
||||
long allGameSize = 0;
|
||||
for (FileInfo mFileInfo : mFileInfos) {
|
||||
allGameSize = allGameSize + mFileInfo.getSize();
|
||||
}
|
||||
|
||||
double size = (((float)allGameSize/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
String sizeName = df.format(size) + "MB";
|
||||
|
||||
mSenderUserDes.setText(mFileInfos.size() + "个游戏,共" + sizeName);
|
||||
mSenderUserName.setText("发给 " + map.get("receiverName"));
|
||||
mSenderUserIcon.setImageURI(UserIconUtils.getUserIcon(Integer.parseInt(map.get("usericon"))));
|
||||
|
||||
mSenderBottom.setVisibility(View.GONE);
|
||||
|
||||
mSenderHint.setText("已连接");
|
||||
}
|
||||
|
||||
private void initSendServer() throws Exception {
|
||||
String serverIp = WifiMgr.getInstance(this).getIpAddressFromHotspot();
|
||||
|
||||
Utils.log("====FileSenderActivity传送个数::" + mFileInfos.size());
|
||||
|
||||
|
||||
// TODO: 发送的首个游戏 socket被拒绝的概率较大 延迟0.5秒发送试试
|
||||
Thread.sleep(500); //test
|
||||
|
||||
for (final FileInfo fileInfo : mFileInfos) {
|
||||
Utils.log("FileSenderActivity == initSendServer()===" + fileInfo.getName() + "==" + fileInfo.getResult());
|
||||
|
||||
if (fileInfo.getResult() != 0) continue; // result != 0 是已经传送过的apk
|
||||
|
||||
FileSender fileSender = new FileSender(this, fileInfo, serverIp, Constant.DEFAULT_SERVER_PORT);
|
||||
fileSender.setOnSendListener(new FileSender.OnSendListener() {
|
||||
@Override
|
||||
public void onStart() {
|
||||
mStartTime = System.currentTimeMillis();
|
||||
Utils.log("快传文件发送::onStart" + "==" + fileInfo.getName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(long progress, long total) {
|
||||
// Utils.log("快传文件发送中..." + progress + "==" + total + "==" + fileInfo.getName());
|
||||
fileInfo.setProgress(progress);
|
||||
Message message = new Message();
|
||||
message.what = FileInfo.FLAG_DEFAULT;
|
||||
message.obj = getCurrentFileInfoIndex(fileInfo);
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(FileInfo fileInfo) {
|
||||
Utils.log("快传文件发送成功::onSuccess" + "==" + fileInfo.getName());
|
||||
Message message = new Message();
|
||||
message.what = FileInfo.FLAG_SUCCESS;
|
||||
message.obj = getCurrentFileInfoIndex(fileInfo);
|
||||
handler.sendMessage(message);
|
||||
|
||||
long sendTime = System.currentTimeMillis() - mStartTime;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("sendTime", String.valueOf(sendTime));
|
||||
map.put("apkPath", fileInfo.getFilePath());
|
||||
map.put("apkSize", String.valueOf(fileInfo.getSize()));
|
||||
sendData.add(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t, FileInfo fileInfo) {
|
||||
Utils.log("快传文件发送失败::onFailure" + "==" + fileInfo.getName());
|
||||
Message message = new Message();
|
||||
message.what = FileInfo.FLAG_FAILURE;
|
||||
message.obj = getCurrentFileInfoIndex(fileInfo);
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(FileInfo fileInfo) {
|
||||
Utils.log("快传文件用户主动取消::onCancel" + "==" + fileInfo.getName());
|
||||
Message message = new Message();
|
||||
message.what = FileInfo.FLAG_CANCEL;
|
||||
message.obj = getCurrentFileInfoIndex(fileInfo);
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
|
||||
});
|
||||
mFileSenderList.add(fileSender);
|
||||
AppController.FILE_SENDER_EXECUTOR.execute(fileSender);
|
||||
}
|
||||
}
|
||||
|
||||
private int getCurrentFileInfoIndex(FileInfo curFileInfo) {
|
||||
for (int i = 0; i < mFileInfos.size(); i++) {
|
||||
FileInfo fileInfo = mFileInfos.get(i);
|
||||
if (curFileInfo == null) {
|
||||
return -100;
|
||||
}
|
||||
if (fileInfo.getFileTag().equals(curFileInfo.getFileTag())) {
|
||||
Utils.log("FileSenderActivity === index::" + i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Utils.log("FileReceiverActivity:: 获取刷新位置异常");
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void initSenderHint(){
|
||||
for (FileInfo mFileInfo : mFileInfos) {
|
||||
if (mFileInfo.getResult() == 0 || mFileInfo.getResult() == 1) { // 还有没完成的任务
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mSenderBottom.setVisibility(View.VISIBLE);
|
||||
|
||||
int sendSuccess = 0;
|
||||
isSendOver = true;
|
||||
for (FileInfo mFileInfo : mFileInfos) {
|
||||
if (mFileInfo.getResult() == FileInfo.FLAG_SUCCESS) {
|
||||
sendSuccess ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (sendSuccess > 0) {
|
||||
mSenderHint.setVisibility(View.VISIBLE);
|
||||
mSenderHint.setText("传输结束,成功分享" + sendSuccess + "个游戏");
|
||||
} else {
|
||||
if (mFileInfos.get(mFileInfos.size() - 1).getResult() == FileInfo.FLAG_CANCEL) {
|
||||
mSenderHint.setVisibility(View.VISIBLE);
|
||||
mSenderHint.setText("传输已取消");
|
||||
} else if (mFileInfos.get(mFileInfos.size() - 1).getResult() == FileInfo.FLAG_FAILURE) {
|
||||
mSenderHint.setVisibility(View.VISIBLE);
|
||||
mSenderHint.setText("传输失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnCancelPosition(int position) {
|
||||
FileSender fileSender = mFileSenderList.get(position);
|
||||
Utils.log("发送方准备取消发送" + position);
|
||||
if (fileSender != null && fileSender.isRunning()) {
|
||||
Utils.log("发送方取消发送");
|
||||
fileSender.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
backHint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
}
|
||||
|
||||
@OnClick({R.id.actionbar_rl_back, R.id.sender_keep_send, R.id.sender_back})
|
||||
public void onClick(View view) {
|
||||
if (view.getId() == R.id.actionbar_rl_back || view.getId() == R.id.sender_back) {
|
||||
backHint();
|
||||
} else if (view.getId() == R.id.sender_keep_send) {
|
||||
Intent intent = new Intent(this, KcSelectGameActivity.class);
|
||||
intent.putExtra("isConn", true);
|
||||
startActivityForResult(intent, 0x178);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 停止所有的文件发送任务
|
||||
*/
|
||||
private void stopAllFileSendingTask(){
|
||||
for(FileSender fileSender : mFileSenderList){
|
||||
if(fileSender != null){
|
||||
fileSender.cancel();
|
||||
fileSender.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void colsePage() {
|
||||
if(mDatagramSocket != null) {
|
||||
// mDatagramSocket.disconnect();
|
||||
mDatagramSocket.close();
|
||||
mDatagramSocket = null;
|
||||
}
|
||||
|
||||
stopAllFileSendingTask();
|
||||
AppController.remove("FileInfo");
|
||||
AppController.put("sendData", sendData);
|
||||
|
||||
FileSenderActivity.this.finish();
|
||||
}
|
||||
|
||||
private void backHint() {
|
||||
if(!isSendOver){
|
||||
DialogUtils.showWarningDialog(FileSenderActivity.this, "退出传送", "退出会中断所有游戏的传送,确定要退出吗?"
|
||||
, "取消", "确定"
|
||||
, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
colsePage();
|
||||
|
||||
}
|
||||
}, null);
|
||||
} else {
|
||||
colsePage();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,248 +1,624 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import android.widget.*;
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseDetailActivity;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.gamecenter.changeskin.ChangeSkinUtils;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.gamedetail.GameDetailAdapter;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.*;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.common.view.NoScrollableViewPager;
|
||||
import com.gh.download.*;
|
||||
import com.gh.gamecenter.adapter.FragmentAdapter;
|
||||
import com.gh.gamecenter.entity.*;
|
||||
import com.gh.gamecenter.eventbus.*;
|
||||
import com.gh.gamecenter.gamedetail.FuliFragment;
|
||||
import com.gh.gamecenter.gamedetail.XinXiFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.jakewharton.rxbinding.view.RxView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import butterknife.BindView;
|
||||
import com.tencent.tauth.Tencent;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/8/12.
|
||||
*
|
||||
* Created by khy on 2017/3/24.
|
||||
* 游戏详情适配器
|
||||
*/
|
||||
public class GameDetailActivity extends BaseDetailActivity implements View.OnClickListener{
|
||||
public class GameDetailActivity extends BaseFragmentActivity {
|
||||
|
||||
private GameDetailAdapter adapter;
|
||||
@BindView(R.id.gamedetail_vp) NoScrollableViewPager mViewPager;
|
||||
@BindView(R.id.gamedetail_top) RelativeLayout mTopLl;
|
||||
@BindView(R.id.gamedetail_tabbar_rl) RelativeLayout mTabBarRl;
|
||||
@BindView(R.id.reuse_ll_loading) LinearLayout mLoading;
|
||||
@BindView(R.id.reuse_no_connection) LinearLayout mNoConnection;
|
||||
@BindView(R.id.actionbar_tv_title) TextView mTitle;
|
||||
@BindView(R.id.gamedetail_iv_thumb) SimpleDraweeView mGameIcon;
|
||||
@BindView(R.id.gamedetail_tv_name) TextView mGameName;
|
||||
@BindView(R.id.gamedetail_tv_info) TextView mGameInfo;
|
||||
@BindView(R.id.gamedetail_tv_concern) TextView mGameConcern;
|
||||
@BindView(R.id.gamedetail_tabbar) LinearLayout mTabBar;
|
||||
@BindView(R.id.gamedetail_tabbar_fuli) TextView mTanBarFuLi;
|
||||
@BindView(R.id.gamedetail_tabbar_xinxi) TextView mTanBarXinXi;
|
||||
@BindView(R.id.gamedetail_tabbar_fuli_tv) TextView mTanBarFuLiTv;
|
||||
@BindView(R.id.gamedetail_tabbar_xinxi_tv) TextView mTanBarXinXiTv;
|
||||
@BindView(R.id.gamedetail_share) ImageView mShareIv;
|
||||
|
||||
@BindView(R.id.detail_ll_bottom) LinearLayout mDownloadBottom;
|
||||
@BindView(R.id.detail_tv_download) TextView mDownloadTv;
|
||||
@BindView(R.id.detail_tv_per) TextView mDownloadPer;
|
||||
@BindView(R.id.detail_pb_progressbar) ProgressBar mDownloadPb;
|
||||
|
||||
private String gameId;
|
||||
private RelativeLayout.LayoutParams top_rparams;
|
||||
|
||||
private long start;
|
||||
private ConcernManager mConcernManager;
|
||||
|
||||
private boolean isSentReport;
|
||||
private String mGameId;
|
||||
|
||||
@BindView(R.id.actionbar_rl_back) RelativeLayout actionbar_rl_back;
|
||||
private GameEntity mGameEntity;
|
||||
private DownloadEntity mDownloadEntity;
|
||||
|
||||
private String downloadAddWord;
|
||||
private String downloadOffText;
|
||||
|
||||
private String name;
|
||||
private String title;
|
||||
private String shareCode;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
if (mGameEntity != null && mGameEntity.getApk().size() == 1) {
|
||||
String url = mGameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(downloadEntity.getUrl())) {
|
||||
if (!"pause".equals(DownloadManager.getInstance(GameDetailActivity.this).
|
||||
getStatus(downloadEntity.getUrl()))) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//接收QQ或者QQ空间分享回调
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == com.tencent.connect.common.Constants.REQUEST_QQ_SHARE
|
||||
|| requestCode == com.tencent.connect.common.Constants.REQUEST_QZONE_SHARE) {
|
||||
Tencent.onActivityResultData(requestCode, resultCode, data, ShareUtils.getInstance(this).QqShareListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View view = View.inflate(GameDetailActivity.this, R.layout.activity_game_detail, null);
|
||||
init(view);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
mViewPager.setScrollable(false);
|
||||
|
||||
mConcernManager = new ConcernManager(GameDetailActivity.this);
|
||||
|
||||
name = "游戏详情";
|
||||
isSentReport = false;
|
||||
|
||||
gameId = getIntent().getStringExtra("gameId");
|
||||
mGameId = getIntent().getStringExtra("gameId");
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
gameId = getIntent().getBundleExtra("data").getString("gameId");
|
||||
mGameId = getIntent().getBundleExtra("data").getString("gameId");
|
||||
}
|
||||
if (gameId == null) {
|
||||
gameEntity = (GameEntity) AppController.get("GameEntity", true);
|
||||
if (gameEntity != null) {
|
||||
title = gameEntity.getName();
|
||||
actionbar_tv_title.setText(gameEntity.getName());
|
||||
|
||||
if (mGameId == null) {
|
||||
mGameEntity = (GameEntity) AppController.get("GameEntity", false);
|
||||
if (mGameEntity != null) {
|
||||
mGameId = mGameEntity.getId();
|
||||
mTitle.setText(mGameEntity.getName());
|
||||
name = mGameEntity.getName();
|
||||
}
|
||||
}
|
||||
|
||||
adapter = new GameDetailAdapter(this, entrance);
|
||||
detail_rv_show.setLayoutManager(new LinearLayoutManager(this));
|
||||
detail_rv_show.setAdapter(adapter);
|
||||
|
||||
detail_ll_bottom.setOnClickListener(this);
|
||||
detail_tv_download.setOnClickListener(this);
|
||||
detail_tv_per.setOnClickListener(this);
|
||||
reuse_no_connection.setOnClickListener(this);
|
||||
actionbar_rl_back.setOnClickListener(this);
|
||||
|
||||
if (gameEntity != null) {
|
||||
adapter.setGameEntity(gameEntity);
|
||||
adapter.getGameDetail();
|
||||
} else if (gameId != null) {
|
||||
if (mGameEntity != null) {
|
||||
getGameDetail();
|
||||
} else if (mGameId != null) {
|
||||
getGameDigest();
|
||||
} else {
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
mLoading.setVisibility(View.GONE);
|
||||
mNoConnection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
// 防抖处理
|
||||
RxView.clicks(iv_share)
|
||||
.throttleFirst(1, TimeUnit.SECONDS)
|
||||
.subscribe(new Action1<Void>() {
|
||||
@Override
|
||||
public void call(Void aVoid) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("点击", "分享");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", gameEntity.getName(), kv);
|
||||
|
||||
DataCollectionUtils.uploadClick(GameDetailActivity.this, "分享", "游戏详情", gameEntity.getName());
|
||||
|
||||
String url = "http://www.ghzhushou.com/game/" + adapter.getGameDetailEntity().getShareCode();
|
||||
showShare(url, gameEntity.getName(), gameEntity.getIcon(), null, gameEntity.getTag());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initGameDetailTop() {
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
if (reuse_ll_loading.getVisibility() == View.VISIBLE) {
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
mLoading.setVisibility(View.GONE);
|
||||
mTopLl.setVisibility(View.VISIBLE);
|
||||
|
||||
top_rparams = (RelativeLayout.LayoutParams) mTopLl.getLayoutParams();
|
||||
|
||||
if (mConcernManager.isConcern(mGameEntity.getId())) {
|
||||
mGameConcern.setText("取消关注");
|
||||
mGameConcern.setBackgroundResource(R.drawable.border_red_bg);
|
||||
mGameConcern.setTextColor(Color.parseColor("#ff4147"));
|
||||
} else {
|
||||
mGameConcern.setText("关注");
|
||||
mGameConcern.setBackgroundResource(R.drawable.textview_concern_red_style);
|
||||
mGameConcern.setTextColor(0xffffffff);
|
||||
}
|
||||
if (!TextUtils.isEmpty(adapter.getGameDetailEntity().getShareCode())) {
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
|
||||
mGameName.setText(mGameEntity.getName());
|
||||
ImageUtils.display(mGameIcon, mGameEntity.getIcon());
|
||||
if (mGameEntity.getApk() == null || mGameEntity.getApk().isEmpty()) {
|
||||
mGameInfo.setText("");
|
||||
} else {
|
||||
ApkEntity apkEntity = mGameEntity.getApk().get(0);
|
||||
mGameInfo.setText(String.format("V%s | %s", apkEntity.getVersion(), apkEntity.getSize()));
|
||||
}
|
||||
downloadAddWord = adapter.getGameDetailEntity().getDownloadAddWord();
|
||||
downloadOffText = adapter.getGameDetailEntity().getDownloadOffText();
|
||||
initDownload(true);
|
||||
}
|
||||
mGameConcern.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final TextView concern = (TextView) v;
|
||||
if ("关注".equals(concern.getText().toString())) {
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "关注");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "游戏关注", mGameEntity.getName(), kv);
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
super.onClick(v);
|
||||
if (v == reuse_no_connection) {
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
reuse_ll_loading.setVisibility(View.VISIBLE);
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (gameEntity != null) {
|
||||
adapter.getGameDetail();
|
||||
} else if (gameId != null) {
|
||||
getGameDigest();
|
||||
} else {
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("点击", "关注");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", mGameEntity.getName(), kv2);
|
||||
|
||||
DataCollectionUtils.uploadConcern(GameDetailActivity.this, mGameEntity.getName(), mGameEntity.getId(), "关注");
|
||||
|
||||
mConcernManager.addByEntity(mGameEntity);
|
||||
concern.setText("取消关注");
|
||||
concern.setBackgroundResource(R.drawable.border_red_bg);
|
||||
concern.setTextColor(Color.parseColor("#ff4147"));
|
||||
|
||||
Toast.makeText(GameDetailActivity.this, "关注成功", Toast.LENGTH_SHORT).show();
|
||||
|
||||
// 添加关注
|
||||
ConcernUtils.postConcernGameId(GameDetailActivity.this, mGameEntity.getId());
|
||||
} else {
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("点击", "取消关注");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", mGameEntity.getName(), kv2);
|
||||
|
||||
DialogUtils.showCancelDialog(GameDetailActivity.this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "取消关注");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "游戏关注", mGameEntity.getName(), kv);
|
||||
|
||||
DataCollectionUtils.uploadConcern(GameDetailActivity.this,
|
||||
mGameEntity.getName(), mGameEntity.getId(), "取消关注");
|
||||
|
||||
mConcernManager.deleteConcern(mGameEntity.getId());
|
||||
concern.setText("关注");
|
||||
concern.setBackgroundResource(R.drawable.textview_concern_red_style);
|
||||
concern.setTextColor(0xffffffff);
|
||||
|
||||
// 取消关注
|
||||
ConcernUtils.deleteConcernData(GameDetailActivity.this, mGameEntity.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 1000);
|
||||
} else if (v == actionbar_rl_back) {
|
||||
if (ChangeSkinUtils.isChecking) {
|
||||
DialogUtils.showWarningDialog(GameDetailActivity.this, "退出提示",
|
||||
"素材更新还在检测中,如果强行退出会中断所有进度,确定退出?",
|
||||
"取消", "强行退出", new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
finish();
|
||||
}
|
||||
}, null);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 获取游戏摘要
|
||||
private void getGameDigest() {
|
||||
RetrofitManager.getApi().getGameDigest(gameId)
|
||||
RetrofitManager.getApi().getGameDigest(mGameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onResponse(GameEntity response) {
|
||||
gameEntity = response;
|
||||
mGameEntity = response;
|
||||
AppController.put("GameEntity", response);
|
||||
|
||||
title = gameEntity.getName();
|
||||
actionbar_tv_title.setText(gameEntity.getName());
|
||||
adapter.setGameEntity(gameEntity);
|
||||
adapter.getGameDetail();
|
||||
mTitle.setText(mGameEntity.getName());
|
||||
mGameId = response.getId();
|
||||
name = mGameEntity.getName();
|
||||
getGameDetail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
Utils.log("=======onError::getGameDetail" );
|
||||
mLoading.setVisibility(View.GONE);
|
||||
mNoConnection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
if (!TextUtils.isEmpty(gameId) && changed.isSingle() && changed.getGameId().equals(gameId)) {
|
||||
adapter.notifyItemChanged(0);
|
||||
// 获取游戏详情
|
||||
public void getGameDetail() {
|
||||
RetrofitManager.getApi().getGameDetail(mGameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameDetailEntity>() {
|
||||
@Override
|
||||
public void onResponse(GameDetailEntity response) {
|
||||
// 过滤过期公告
|
||||
if (response.getNotice() != null && response.getNotice().size() > 0) {
|
||||
long l = System.currentTimeMillis();
|
||||
for (int i = 0; i < response.getNotice().size(); i++) {
|
||||
if (l > (response.getNotice().get(i).getOvertime()*1000)) {
|
||||
response.getNotice().remove(i);
|
||||
i --;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AppController.put("GameDetailEntity", response);
|
||||
|
||||
downloadAddWord = response.getDownloadAddWord();
|
||||
downloadOffText = response.getDownloadOffText();
|
||||
shareCode = response.getShareCode();
|
||||
|
||||
List<Fragment> list = new ArrayList<>();
|
||||
if (mGameEntity != null && !mGameEntity.isLibaoExists()
|
||||
&& TextUtils.isEmpty(response.getFulishuoming())
|
||||
&& (response.getKaiFuServer() == null
|
||||
|| (response.getKaiFuServer() != null
|
||||
&& response.getKaiFuServer().size() == 0))) {
|
||||
XinXiFragment xinXiFragment = new XinXiFragment();
|
||||
xinXiFragment.setIsTabBar(true);
|
||||
list.add(xinXiFragment);
|
||||
mTabBar.setVisibility(View.GONE);
|
||||
} else {
|
||||
list.add(new FuliFragment());
|
||||
list.add(new XinXiFragment());
|
||||
}
|
||||
|
||||
mViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), list));
|
||||
initGameDetailTop();
|
||||
|
||||
initDownload(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
Utils.log("=======onError::getGameDetail" + e.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBMoveTop moveTop) {
|
||||
if (moveTop.getType().equals("top")) {
|
||||
if (moveTop.getVisibility() == View.VISIBLE && mTabBar.getVisibility() == View.VISIBLE) {
|
||||
mTabBarRl.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mTabBarRl.setVisibility( View.GONE);
|
||||
}
|
||||
int topMargin = moveTop.getTopMargin();
|
||||
if (top_rparams != null && top_rparams.topMargin != topMargin) {
|
||||
if (topMargin > -120) {
|
||||
mTitle.setVisibility(View.GONE);
|
||||
} else {
|
||||
mTitle.setVisibility(View.VISIBLE);
|
||||
}
|
||||
top_rparams.topMargin = moveTop.getTopMargin();
|
||||
mTopLl.setLayoutParams(top_rparams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 接收下载被删除消息
|
||||
public void onEvent(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())
|
||||
&& mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
String url = mGameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(status.getUrl())) {
|
||||
initDownload(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 接受安装、卸载消息
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
if (mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
String packageName = mGameEntity.getApk().get(0).getPackageName();
|
||||
if (packageName.equals(busFour.getPackageName())) {
|
||||
initDownload(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
initDownload(true);
|
||||
}
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (!isSentReport) {
|
||||
long end = System.currentTimeMillis();
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
int seconds = (int) ((end - start) / 1000);
|
||||
|
||||
String cost;
|
||||
if (seconds < 5) {
|
||||
cost = "小于5秒";
|
||||
} else if (seconds < 30) {
|
||||
cost = "5秒-30秒";
|
||||
} else if (seconds < 60) {
|
||||
cost = "30秒-60秒";
|
||||
@OnClick({R.id.detail_tv_download, R.id.detail_pb_progressbar
|
||||
, R.id.detail_tv_per, R.id.gamedetail_tabbar_xinxi, R.id.gamedetail_tabbar_xinxi_tv
|
||||
, R.id.gamedetail_tabbar_fuli, R.id.gamedetail_tabbar_fuli_tv, R.id.gamedetail_share})
|
||||
public void onClick(View v) {
|
||||
if (v == mDownloadTv) {
|
||||
if (mGameEntity != null && !mGameEntity.getApk().isEmpty()) {
|
||||
if (mGameEntity.getApk().size() == 1) {
|
||||
if (NetworkUtils.isWifiConnected(this)) {
|
||||
download();
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
download();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
DownloadDialog.getInstance(this).showPopupWindow(v, mGameEntity, entrance, name + ":" + title);
|
||||
}
|
||||
} else {
|
||||
cost = "大于60秒";
|
||||
toast("稍等片刻~!游戏正在上传中...");
|
||||
}
|
||||
} else if (v == mDownloadPb || v == mDownloadPer) {
|
||||
String str = mDownloadPer.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
Intent intent = new Intent(this, DownloadManagerActivity.class);
|
||||
intent.putExtra("currentItem", 1);
|
||||
intent.putExtra("url", mGameEntity.getApk().get(0).getUrl());
|
||||
intent.putExtra("entrance", entrance + "+(" + name + "[" + title + "])");
|
||||
startActivity(intent);
|
||||
} else if ("安装".equals(str)) {
|
||||
PackageUtils.launchSetup(this, mDownloadEntity.getPath());
|
||||
}
|
||||
} else if (v == mTanBarFuLi || v == mTanBarFuLiTv) {
|
||||
mTanBarFuLi.setTextColor(Color.WHITE);
|
||||
mTanBarFuLiTv.setTextColor(Color.WHITE);
|
||||
mTanBarFuLi.setBackgroundResource(R.drawable.gamedetail_tag_select_bg);
|
||||
mTanBarFuLiTv.setBackgroundResource(R.drawable.gamedetail_tag_select_bg);
|
||||
mTanBarXinXi.setTextColor(Color.BLACK);
|
||||
mTanBarXinXiTv.setTextColor(Color.BLACK);
|
||||
mTanBarXinXi.setBackgroundDrawable(new ColorDrawable(0));
|
||||
mTanBarXinXiTv.setBackgroundDrawable(new ColorDrawable(0));
|
||||
mViewPager.setCurrentItem(0);
|
||||
|
||||
if (gameEntity != null && !TextUtils.isEmpty(gameEntity.getName())) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("停留时长", cost);
|
||||
DataUtils.onEvent(this, "插件数据", gameEntity.getName(), kv);
|
||||
} else if (v == mTanBarXinXi || v == mTanBarXinXiTv) {
|
||||
mTanBarXinXiTv.setTextColor(Color.WHITE);
|
||||
mTanBarXinXi.setTextColor(Color.WHITE);
|
||||
mTanBarXinXiTv.setBackgroundResource(R.drawable.gamedetail_tag_unselect_bg);
|
||||
mTanBarXinXi.setBackgroundResource(R.drawable.gamedetail_tag_unselect_bg);
|
||||
mTanBarFuLi.setTextColor(Color.BLACK);
|
||||
mTanBarFuLiTv.setTextColor(Color.BLACK);
|
||||
mTanBarFuLi.setBackgroundDrawable(new ColorDrawable(0));
|
||||
mTanBarFuLiTv.setBackgroundDrawable(new ColorDrawable(0));
|
||||
mViewPager.setCurrentItem(1);
|
||||
} else if (v == mShareIv) {
|
||||
if (TextUtils.isEmpty(shareCode)) return;
|
||||
// 防抖处理
|
||||
RxView.clicks(mShareIv)
|
||||
.throttleFirst(1, TimeUnit.SECONDS)
|
||||
.subscribe(new Action1<Void>() {
|
||||
@Override
|
||||
public void call(Void aVoid) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("点击", "分享");
|
||||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", mGameEntity.getName(), kv);
|
||||
|
||||
if (seconds > 0) {
|
||||
DataCollectionUtils.uploadGame(this, gameEntity, seconds, entrance);
|
||||
DataCollectionUtils.uploadClick(GameDetailActivity.this, "分享", "游戏详情", mGameEntity.getName());
|
||||
|
||||
String url = "http://www.ghzhushou.com/game/" + shareCode;
|
||||
showShare(url, mGameEntity.getName(), mGameEntity.getIcon(), null, mGameEntity.getTag());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void download() {
|
||||
String str = mDownloadTv.getText().toString();
|
||||
if (str.contains("启动")) {
|
||||
DataUtils.onGameLaunchEvent(this, mGameEntity.getName(), mGameEntity.getApk().get(0).getPlatform(), name);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(this, mGameEntity.getApk().get(0).getPackageName());
|
||||
} else {
|
||||
String method;
|
||||
if (str.contains("更新")) {
|
||||
method = "更新";
|
||||
} else if (str.contains("插件化")) {
|
||||
method = "插件化";
|
||||
} else {
|
||||
method = "下载";
|
||||
}
|
||||
ApkEntity apkEntity = mGameEntity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(this, apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
DataUtils.onGameDownloadEvent(this, mGameEntity.getName(), apkEntity.getPlatform(), entrance, "下载开始");
|
||||
|
||||
DownloadManager.createDownload(this, apkEntity, mGameEntity, method, entrance, name + ":" + title);
|
||||
|
||||
mDownloadTv.setVisibility(View.GONE);
|
||||
mDownloadPb.setVisibility(View.VISIBLE);
|
||||
mDownloadPer.setVisibility(View.VISIBLE);
|
||||
mDownloadPb.setProgress(0);
|
||||
mDownloadPer.setText("0.0%");
|
||||
|
||||
DownloadManager.getInstance(GameDetailActivity.this).putStatus(apkEntity.getUrl(), "downloading");
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
mDownloadPb.setProgress((int) (mDownloadEntity.getPercent() * 10));
|
||||
mDownloadPer.setTextColor(0xFFFFFFFF);
|
||||
switch (mDownloadEntity.getStatus()) {
|
||||
case downloading:
|
||||
case pause:
|
||||
case timeout:
|
||||
case neterror:
|
||||
case waiting:
|
||||
mDownloadPer.setText("下载中");
|
||||
break;
|
||||
case done:
|
||||
mDownloadPer.setText("安装");
|
||||
if (mDownloadEntity.isPluggable()
|
||||
&& PackageManager.isInstalled(mDownloadEntity.getPackageName())) {
|
||||
mDownloadPb.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_plugin_radius_style));
|
||||
} else {
|
||||
mDownloadPb.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_normal_radius_style));
|
||||
}
|
||||
break;
|
||||
case cancel:
|
||||
case hijack:
|
||||
case notfound:
|
||||
initDownload(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void initDownload(boolean isCheck) {
|
||||
if (Config.isShow(this)) {
|
||||
mDownloadBottom.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mDownloadBottom.setVisibility(View.GONE);
|
||||
}
|
||||
if (mGameEntity != null && "光环助手".equals(mGameEntity.getName())) {
|
||||
mDownloadBottom.setVisibility(View.GONE);
|
||||
} else if (mGameEntity == null || mGameEntity.getApk().isEmpty()) {
|
||||
mDownloadTv.setVisibility(View.VISIBLE);
|
||||
mDownloadPb.setVisibility(View.GONE);
|
||||
mDownloadPer.setVisibility(View.GONE);
|
||||
if (TextUtils.isEmpty(downloadOffText)) {
|
||||
mDownloadTv.setText("暂无下载");
|
||||
} else {
|
||||
mDownloadTv.setText(downloadOffText);
|
||||
}
|
||||
mDownloadTv.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
mDownloadTv.setTextColor(0xFF999999);
|
||||
mDownloadTv.setClickable(false);
|
||||
} else {
|
||||
mDownloadTv.setVisibility(View.VISIBLE);
|
||||
mDownloadPb.setVisibility(View.GONE);
|
||||
mDownloadPer.setVisibility(View.GONE);
|
||||
boolean isInstalled = false;
|
||||
if (mGameEntity.getApk() != null && mGameEntity.getApk().size() == 1
|
||||
&& PackageManager.isInstalled(mGameEntity.getApk().get(0).getPackageName())) {
|
||||
isInstalled = true;
|
||||
}
|
||||
if (isInstalled) {
|
||||
if (PackageManager.isCanUpdate(mGameEntity.getId(), mGameEntity.getApk().get(0).getPackageName())) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
mDownloadTv.setText(String.format("更新《%s》",
|
||||
mGameEntity.getName()));
|
||||
} else {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
mDownloadTv.setText(String.format("更新《%s》%s",
|
||||
mGameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
} else {
|
||||
if (mGameEntity.getTag() != null && mGameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(mGameEntity.getApk().get(0).getGhVersion())
|
||||
&& !PackageUtils.isSignature(this, mGameEntity.getApk().get(0).getPackageName())) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
mDownloadTv.setText(String.format("插件化《%s》",
|
||||
mGameEntity.getName()));
|
||||
} else {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
mDownloadTv.setText(String.format("插件化《%s》%s",
|
||||
mGameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
} else {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
mDownloadTv.setText(String.format("启动《%s》",
|
||||
mGameEntity.getName()));
|
||||
} else {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
mDownloadTv.setText(String.format("启动《%s》%s",
|
||||
mGameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String status = GameUtils.getDownloadBtnText(this, mGameEntity);
|
||||
if ("插件化".equals(status)) {
|
||||
mDownloadTv.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else if ("打开".equals(status)) {
|
||||
mDownloadTv.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
} else {
|
||||
mDownloadTv.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
mDownloadTv.setText(String.format(status + "《%s》",
|
||||
mGameEntity.getName()));
|
||||
} else {
|
||||
mDownloadTv.setText(String.format(status + "《%s》%s",
|
||||
mGameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
}
|
||||
|
||||
isSentReport = true;
|
||||
}
|
||||
if (isCheck && mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
String url = mGameEntity.getApk().get(0).getUrl();
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(getApplicationContext()).get(url);
|
||||
if (downloadEntity != null) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
mDownloadTv.setVisibility(View.GONE);
|
||||
mDownloadPb.setVisibility(View.VISIBLE);
|
||||
mDownloadPer.setVisibility(View.VISIBLE);
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && ChangeSkinUtils.isChecking) {
|
||||
DialogUtils.showWarningDialog(GameDetailActivity.this, "退出提示",
|
||||
"素材更新还在检测中,如果强行退出会中断所有进度,确定退出?",
|
||||
"取消", "强行退出", new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
finish();
|
||||
}
|
||||
}, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -16,10 +17,16 @@ import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.gamecenter.adapter.GameNewsAdapter;
|
||||
import com.gh.gamecenter.adapter.GameNewsTypeListAdapter;
|
||||
import com.gh.gamecenter.eventbus.EBTypeChange;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/29.
|
||||
@ -37,7 +44,7 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
|
||||
private ArrayMap<String, GameNewsAdapter> adapterMap;
|
||||
|
||||
private ArrayList<String> typeList;
|
||||
private List<String> typeList;
|
||||
|
||||
private String gameId;
|
||||
private String entrance;
|
||||
@ -71,17 +78,14 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
|
||||
adapterMap = new ArrayMap<>();
|
||||
|
||||
typeList = getIntent().getStringArrayListExtra("articleTypes");
|
||||
typeList.add(0, "全部");
|
||||
typeList = new ArrayList<>();
|
||||
|
||||
gameId = getIntent().getStringExtra("gameId");
|
||||
|
||||
game_news_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
game_news_list.setLayoutManager(layoutManager);
|
||||
adapter = new GameNewsAdapter(this, typeList, game_news_list, gameId, "全部", entrance);
|
||||
adapterMap.put("全部", adapter);
|
||||
game_news_list.setAdapter(adapter);
|
||||
|
||||
game_news_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
@ -100,7 +104,7 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
if (adapter != null && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() == adapter.getItemCount() - 1) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading() && !adapter.isNetworkError()) {
|
||||
adapter.addList(adapter.getNewsList().size());
|
||||
@ -111,12 +115,6 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
|
||||
game_news_top_type_list.setHasFixedSize(true);
|
||||
game_news_top_type_list.setLayoutManager(new GridLayoutManager(this, 5));
|
||||
typeListAdapter = new GameNewsTypeListAdapter(typeList, "全部");
|
||||
game_news_top_type_list.setAdapter(typeListAdapter);
|
||||
|
||||
ViewGroup.LayoutParams params = game_news_top_type_list.getLayoutParams();
|
||||
params.height = (int) Math.ceil(typeList.size() / 5f) * DisplayUtils.dip2px(this, 35)+ DisplayUtils.dip2px(this, 12);
|
||||
game_news_top_type_list.setLayoutParams(params);
|
||||
|
||||
//禁止由于滑动出现的阴影
|
||||
game_news_top_type_list.setOnTouchListener(new View.OnTouchListener() {
|
||||
@ -132,12 +130,47 @@ public class GameNewsActivity extends BaseActivity implements View.OnClickListen
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!TextUtils.isEmpty(gameId)) {
|
||||
getGameArticleType();
|
||||
}
|
||||
}
|
||||
|
||||
private void getGameArticleType() {
|
||||
RetrofitManager.getApi()
|
||||
.getGameArticleType(gameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<String>>(){
|
||||
@Override
|
||||
public void onResponse(List<String> response) {
|
||||
super.onResponse(response);
|
||||
typeList = response;
|
||||
typeList.add(0, "全部");
|
||||
adapter = new GameNewsAdapter(GameNewsActivity.this, typeList, game_news_list, gameId, "全部", entrance);
|
||||
adapterMap.put("全部", adapter);
|
||||
game_news_list.setAdapter(adapter);
|
||||
|
||||
typeListAdapter = new GameNewsTypeListAdapter(typeList, "全部");
|
||||
game_news_top_type_list.setAdapter(typeListAdapter);
|
||||
|
||||
ViewGroup.LayoutParams params = game_news_top_type_list.getLayoutParams();
|
||||
params.height = (int) Math.ceil(typeList.size() / 5f) * DisplayUtils.dip2px(GameNewsActivity.this, 35)
|
||||
+ DisplayUtils.dip2px(GameNewsActivity.this, 12);
|
||||
game_news_top_type_list.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBTypeChange change) {
|
||||
adapter = adapterMap.get(change.getType());
|
||||
if (adapter == null) {
|
||||
adapter = new GameNewsAdapter(this, typeList, game_news_list, gameId, change.getType(), entrance);
|
||||
adapter = new GameNewsAdapter(GameNewsActivity.this, typeList, game_news_list, gameId, change.getType(), entrance);
|
||||
adapterMap.put(change.getType(), adapter);
|
||||
}
|
||||
game_news_list.setAdapter(adapter);
|
||||
|
||||
411
app/src/main/java/com/gh/gamecenter/KaiFuActivity.java
Normal file
411
app/src/main/java/com/gh/gamecenter/KaiFuActivity.java
Normal file
@ -0,0 +1,411 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.MeasureHeightLayoutManager;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.KaiFuAdapter;
|
||||
import com.gh.gamecenter.adapter.KaiFuDialogAdapter;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.jakewharton.rxbinding.view.RxView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import butterknife.BindView;
|
||||
import rx.functions.Action1;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/16.
|
||||
* 首页-开服表
|
||||
*/
|
||||
public class KaiFuActivity extends BaseActivity implements KaiFuDialogAdapter.OnKaiFuDialogCallBackListener
|
||||
, KaiFuAdapter.OnScrollToKaiFuIndex, SwipeRefreshLayout.OnRefreshListener{
|
||||
|
||||
@BindView(R.id.kaifu_rv) RecyclerView mRecyclerView;
|
||||
@BindView(R.id.kaifu_pb) ProgressBarCircularIndeterminate mPbLoading;
|
||||
@BindView(R.id.kaifu_refresh) SwipeRefreshLayout mRefreshLayout;
|
||||
@BindView(R.id.kaifu_game_name) TextView mGameName;
|
||||
@BindView(R.id.popup_bg) View mPopupBg;
|
||||
@BindView(R.id.kaifu_select_game_rl) RelativeLayout mSelectGameRl;
|
||||
@BindView(R.id.reuse_no_connection) LinearLayout mNoConnection;
|
||||
|
||||
private PopupWindow mPopupWindow;
|
||||
|
||||
private KaiFuAdapter mAdapter;
|
||||
|
||||
private LinearLayoutManager layoutManager;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
|
||||
private String kaifuType;
|
||||
|
||||
private int mDialogGamePosition; // 顶部弹窗过滤位置
|
||||
private int kaifuOffset = 0;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
ArrayList<Integer> locationList = mAdapter.getLocationMap().get(downloadEntity.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
gameEntity = mAdapter.getSubjectList().get(location - getGameEntityIndex());
|
||||
if (gameEntity != null) {
|
||||
DownloadItemUtils.processDate(KaiFuActivity.this, gameEntity, downloadEntity,
|
||||
mAdapter, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private int getGameEntityIndex() {
|
||||
if (kaifuOffset != 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAdapter = new KaiFuAdapter(KaiFuActivity.this, kaifuType);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View view = View.inflate(this, R.layout.activity_kaifu, null);
|
||||
init(view, "开服表");
|
||||
|
||||
kaifuType = "全部";
|
||||
|
||||
mRefreshLayout.setColorSchemeResources(R.color.theme);
|
||||
mRefreshLayout.setOnRefreshListener(this);
|
||||
mRefreshLayout.setEnabled(false);
|
||||
|
||||
mAdapter = new KaiFuAdapter(this, kaifuType);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(this, 8, false));
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
//上拉加载
|
||||
if (mAdapter.isLoadedBottom() && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& mAdapter.getItemCount() == layoutManager.findLastVisibleItemPosition() + 1){
|
||||
mAdapter.initListBottom(kaifuOffset + mAdapter.loadCountBottom());
|
||||
}
|
||||
//下拉加载
|
||||
if (kaifuOffset >0 && mAdapter.isLoadedTop() && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findFirstVisibleItemPosition() == 0) {
|
||||
int countTop = mAdapter.loadCountTop();
|
||||
if (countTop%20 == 0) { // 不是20的倍数 证明加载完毕
|
||||
int offset = kaifuOffset - countTop;
|
||||
int limit = 20;
|
||||
if (offset < 0) {
|
||||
limit = limit + offset;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
if (limit == 0) return;
|
||||
|
||||
mAdapter.initListTop(offset, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 防抖处理
|
||||
RxView.clicks(mSelectGameRl)
|
||||
.throttleFirst(1, TimeUnit.SECONDS)
|
||||
.subscribe(new Action1<Void>() {
|
||||
@Override
|
||||
public void call(Void aVoid) {
|
||||
initSelectGameDialog();
|
||||
}
|
||||
});
|
||||
|
||||
mNoConnection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mAdapter.initKaiFuOffset();
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
mPbLoading.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initSelectGameDialog() {
|
||||
isShowPopupBg(true);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.dialog_kaifu_select_game, null);
|
||||
RecyclerView selectGameRv = (RecyclerView) contentView.findViewById(R.id.dialog_kaifu_select_game_rv);
|
||||
final TextView selectGameTitle = (TextView) contentView.findViewById(R.id.dialog_kaifu_title);
|
||||
|
||||
final MeasureHeightLayoutManager layout = new MeasureHeightLayoutManager(this);
|
||||
selectGameRv.setLayoutManager(layout);
|
||||
selectGameRv.setAdapter(new KaiFuDialogAdapter(this, mDialogGamePosition));
|
||||
|
||||
|
||||
mPopupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
||||
, LinearLayout.LayoutParams.MATCH_PARENT, true);
|
||||
mPopupWindow.setAnimationStyle(R.style.scale_popwindow_anim_style);
|
||||
mPopupWindow.showAtLocation(mSelectGameRl, 0, 0, 0);
|
||||
|
||||
selectGameRv.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
if (layout.findFirstVisibleItemPosition() >= 5) {
|
||||
selectGameTitle.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
selectGameTitle.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
selectGameRv.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK
|
||||
&& event.getRepeatCount() == 0
|
||||
&& mPopupWindow != null
|
||||
&& mPopupWindow.isShowing()) {
|
||||
isShowPopupBg(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
contentView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isShowPopupBg(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPosition(int position, String tag, String gameName) {
|
||||
mDialogGamePosition = position;
|
||||
if (!TextUtils.isEmpty(gameName)) {
|
||||
mGameName.setText(gameName);
|
||||
} else {
|
||||
mGameName.setText(tag);
|
||||
}
|
||||
isShowPopupBg(false);
|
||||
|
||||
kaifuOffset = 0;
|
||||
kaifuType = tag;
|
||||
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mPbLoading.setVisibility(View.VISIBLE);
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
|
||||
mAdapter = new KaiFuAdapter(this, kaifuType);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
public void isShowPopupBg(boolean isShow) {
|
||||
if(isShow) {
|
||||
mPopupBg.setVisibility(View.VISIBLE);
|
||||
mPopupBg.animate()
|
||||
.alpha(1f)
|
||||
.setDuration(300)
|
||||
.setListener(null);
|
||||
} else {
|
||||
mPopupWindow.dismiss();
|
||||
mPopupBg.animate()
|
||||
.alpha(0f)
|
||||
.setDuration(300)
|
||||
.setListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mPopupBg.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
if (mPbLoading != null && mPbLoading.getVisibility() == View.VISIBLE) {
|
||||
mPbLoading.setVisibility(View.GONE);
|
||||
}
|
||||
toast("加载失败,请检查网络状态");
|
||||
mPbLoading.setVisibility(View.GONE);
|
||||
mNoConnection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
if (mPbLoading != null && mPbLoading.getVisibility() == View.VISIBLE) {
|
||||
mPbLoading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (mRefreshLayout.isRefreshing()) {
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
super.loadDone(obj);
|
||||
|
||||
kaifuOffset = (int) obj;
|
||||
|
||||
if (kaifuOffset == 0) {
|
||||
mRefreshLayout.setEnabled(true);
|
||||
} else {
|
||||
mRefreshLayout.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
// 下载被删除事件
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(this).removePlatform(status.getName(), status.getPlatform());
|
||||
|
||||
ArrayList<Integer> locationList = mAdapter.getLocationMap().get(status.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
|
||||
gameEntity = mAdapter.getSubjectList().get(location - getGameEntityIndex());
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
mAdapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
ArrayList<Integer> locationList = mAdapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (locationList != null) {
|
||||
GameEntity gameEntity;
|
||||
for (int location : locationList) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
gameEntity = mAdapter.getSubjectList().get(location - getGameEntityIndex());
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(busFour.getPackageName())) {
|
||||
if (gameEntity.getEntryMap() != null) {
|
||||
gameEntity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
}
|
||||
mAdapter.notifyItemChanged(location + getGameEntityIndex());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
mAdapter.notifyItemChanged(location + getGameEntityIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (mNoConnection.getVisibility() == View.VISIBLE) {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mPbLoading.setVisibility(View.VISIBLE);
|
||||
mNoConnection.setVisibility(View.GONE);
|
||||
mAdapter = new KaiFuAdapter(KaiFuActivity.this, kaifuType);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
for (GameEntity entity : mAdapter.getSubjectList()) {
|
||||
entity.setEntryMap(DownloadManager.getInstance(this).getEntryMap(entity.getName()));
|
||||
}
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getApplicationContext()).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
private void moveToPosition(int n) {
|
||||
int firstItem = layoutManager.findFirstVisibleItemPosition();
|
||||
int lastItem = layoutManager.findLastVisibleItemPosition();
|
||||
if (n <= firstItem ){
|
||||
mRecyclerView.scrollToPosition(n);
|
||||
}else if ( n <= lastItem ){
|
||||
int top = mRecyclerView.getChildAt(n - firstItem).getTop();
|
||||
mRecyclerView.scrollBy(0, top);
|
||||
}else{
|
||||
mRecyclerView.scrollToPosition(n);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(int scrollPosition) {
|
||||
moveToPosition(scrollPosition + getGameEntityIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
mRecyclerView.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
176
app/src/main/java/com/gh/gamecenter/KcSelectGameActivity.java
Normal file
176
app/src/main/java/com/gh/gamecenter/KcSelectGameActivity.java
Normal file
@ -0,0 +1,176 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.KcSelectGameAdapter;
|
||||
import com.gh.gamecenter.kuaichuan.FileInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/20.
|
||||
* 快传-选择游戏
|
||||
*/
|
||||
public class KcSelectGameActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.select_game_rv) RecyclerView mSelectRv;
|
||||
@BindView(R.id.select_game_send) TextView mSelectSend;
|
||||
@BindView(R.id.select_game_all) CheckBox selectAll;
|
||||
@BindView(R.id.install_count) TextView installCount;
|
||||
@BindView(R.id.select_game_installed_ll) RelativeLayout installRl;
|
||||
@BindView(R.id.select_game_pb) ProgressBar mSelectPb;
|
||||
|
||||
private KcSelectGameAdapter mAdapter;
|
||||
|
||||
private boolean mIsConn;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == 0x123) {
|
||||
if (data != null && data.getExtras()!= null && data.getExtras().getBoolean("isFinish")) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_kc_select_game, null);
|
||||
init(contentView, "选择游戏");
|
||||
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
mIsConn = getIntent().getExtras().getBoolean("isConn");
|
||||
} else {
|
||||
mIsConn = false;
|
||||
}
|
||||
|
||||
selectAll.setVisibility(View.GONE);
|
||||
|
||||
mAdapter = new KcSelectGameAdapter(this, mSelectSend, installCount, installRl, mSelectPb);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
mSelectRv.setLayoutManager(layoutManager);
|
||||
mSelectRv.addItemDecoration(new VerticalItemDecoration(this, 8, false));
|
||||
mSelectRv.setAdapter(mAdapter);
|
||||
|
||||
rparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
DisplayUtils.dip2px(this, 40));
|
||||
|
||||
mSelectSend.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
List<FileInfo> selectData = mAdapter.getSelectData();
|
||||
if (selectData.size() == 0) {
|
||||
Utils.toast(KcSelectGameActivity.this, "请选择要发送的游戏");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mIsConn) {
|
||||
List<FileInfo> oldInfo = (List<FileInfo>) AppController.get("FileInfo", false);
|
||||
for (FileInfo fileInfo : selectData) {
|
||||
oldInfo.add(fileInfo);
|
||||
}
|
||||
setResult(0x130);
|
||||
finish();
|
||||
} else {
|
||||
AppController.put("FileInfo", selectData);
|
||||
Intent intent = new Intent(KcSelectGameActivity.this, ChooseReceiverActivity.class);
|
||||
startActivityForResult(intent, 0x123);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
selectAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
HashMap<Integer, Boolean> selectPosition = new HashMap<>();
|
||||
int itemCount = mAdapter.getItemCount();
|
||||
if (isChecked) {
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
selectPosition.put(i, true);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
selectPosition.put(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
mAdapter.setSelectPosition(selectPosition);
|
||||
mAdapter.notifyItemRangeChanged(0, itemCount);
|
||||
}
|
||||
});
|
||||
|
||||
mSelectRv.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
int position = layoutManager.findFirstVisibleItemPosition();
|
||||
int gameSize = mAdapter.getGameSize();
|
||||
|
||||
if (gameSize == 0) { // 游戏列表为空
|
||||
if (position == gameSize) {
|
||||
int buttom = layoutManager.findViewByPosition(position).getBottom();
|
||||
int i = installRl.getHeight() + DisplayUtils.dip2px(KcSelectGameActivity.this, 43);
|
||||
if (buttom <= i && i/2 < buttom) {
|
||||
rparams.topMargin = buttom - installRl.getHeight() - DisplayUtils.dip2px(KcSelectGameActivity.this, 43);
|
||||
installRl.setLayoutParams(rparams);
|
||||
installCount.setText("已安装的游戏(" + gameSize +")");
|
||||
} else {
|
||||
installCount.setText("已安装的应用(" + mAdapter.getAppSize() +")");
|
||||
rparams.topMargin = 0;
|
||||
installRl.setLayoutParams(rparams);
|
||||
}
|
||||
} else {
|
||||
installCount.setText("已安装的应用(" + mAdapter.getAppSize() +")");
|
||||
rparams.topMargin = 0;
|
||||
installRl.setLayoutParams(rparams);
|
||||
}
|
||||
} else {
|
||||
if (position >= gameSize) {
|
||||
installCount.setText("已安装的应用(" + mAdapter.getAppSize() +")");
|
||||
} else {
|
||||
installCount.setText("已安装的游戏(" + mAdapter.getGameSize() +")");
|
||||
}
|
||||
|
||||
if (position == gameSize - 1) {
|
||||
int buttom = layoutManager.findViewByPosition(position).getBottom();
|
||||
if (buttom <= installRl.getHeight()) {
|
||||
rparams.topMargin = buttom - installRl.getHeight();
|
||||
installRl.setLayoutParams(rparams);
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
installRl.setLayoutParams(rparams);
|
||||
}
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
installRl.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@ -11,7 +11,9 @@ import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.view.NoScrollableViewPager;
|
||||
import com.gh.gamecenter.adapter.FragmentAdapter;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.libao.Libao1Fragment;
|
||||
import com.gh.gamecenter.libao.Libao2Fragment;
|
||||
@ -30,9 +32,11 @@ import de.greenrobot.event.EventBus;
|
||||
public class LibaoActivity extends BaseFragmentActivity implements View.OnClickListener,
|
||||
ViewPager.OnPageChangeListener {
|
||||
|
||||
@BindView(R.id.libao_vp_content) ViewPager mLibaoVp;
|
||||
@BindView(R.id.libao_vp_content) NoScrollableViewPager mLibaoVp;
|
||||
@BindView(R.id.libao_ll_top) LinearLayout mLibaoTopLl;
|
||||
@BindView(R.id.libao_slide_line) View mLibaoLine;
|
||||
@BindView(R.id.vp_tab) LinearLayout mTabLl;
|
||||
@BindView(R.id.libao_history_title) TextView mHistoryTitle;
|
||||
|
||||
private TextView mZuixinTv;
|
||||
private TextView mGuanzhuTv;
|
||||
@ -164,4 +168,20 @@ public class LibaoActivity extends BaseFragmentActivity implements View.OnClickL
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
|
||||
// 页面切换事件(查看历史礼包的页面)
|
||||
public void onEventMainThread(EBReuse reuse) {
|
||||
if ("openPage".equals(reuse.getType())) { //TODO 设置新的TAB
|
||||
mLibaoTopLl.setVisibility(View.GONE);
|
||||
mLibaoLine.setVisibility(View.GONE);
|
||||
mHistoryTitle.setVisibility(View.VISIBLE);
|
||||
mHistoryTitle.setTextColor(getResources().getColor(R.color.hint));
|
||||
mLibaoVp.setScrollable(false);
|
||||
} else if ("closePage".equals(reuse.getType())) {
|
||||
mLibaoTopLl.setVisibility(View.VISIBLE);
|
||||
mLibaoLine.setVisibility(View.VISIBLE);
|
||||
mHistoryTitle.setVisibility(View.GONE);
|
||||
mLibaoVp.setScrollable(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,24 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseDetailActivity;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.LibaoDetailAdapter;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.LibaoEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
@ -20,12 +27,35 @@ import rx.schedulers.Schedulers;
|
||||
* Created by khy on 2016/12/13.
|
||||
*
|
||||
*/
|
||||
public class LibaoDetailActivity extends BaseDetailActivity {
|
||||
public class LibaoDetailActivity extends BaseDetailActivity implements LibaoDetailAdapter.OnCodeScrollListener{
|
||||
|
||||
private LibaoDetailAdapter mAdapter;
|
||||
|
||||
private LibaoEntity mLibaoEntity;
|
||||
|
||||
private boolean mIsScroll;
|
||||
|
||||
Handler handler = new Handler(){
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.what == 0) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 24);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
long targetTime = calendar.getTimeInMillis()/1000;
|
||||
long delayedTime = (targetTime - Utils.getTime(LibaoDetailActivity.this)) * 1000;
|
||||
Utils.log("=======" + delayedTime);
|
||||
handler.sendEmptyMessageDelayed(1, 5000);
|
||||
} else if (msg.what == 1) {
|
||||
mLibaoEntity.setStatus(mLibaoEntity.getBeforeStatus());
|
||||
mAdapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@ -42,15 +72,32 @@ public class LibaoDetailActivity extends BaseDetailActivity {
|
||||
|
||||
iv_share.setVisibility(View.GONE);
|
||||
|
||||
mIsScroll = true;
|
||||
|
||||
mAdapter = new LibaoDetailAdapter(this, mLibaoEntity, detail_tv_download);
|
||||
detail_rv_show.setLayoutManager(new LinearLayoutManager(this));
|
||||
detail_rv_show.setLayoutManager(new LinearLayoutManager(this){
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return mIsScroll;
|
||||
}
|
||||
});
|
||||
detail_rv_show.addItemDecoration(new VerticalItemDecoration(this, 8, true));
|
||||
detail_rv_show.setAdapter(mAdapter);
|
||||
|
||||
if (mLibaoEntity.getGame().getId() != null) {
|
||||
if (mLibaoEntity!= null && mLibaoEntity.getGame() != null
|
||||
&& mLibaoEntity.getGame().getId() != null) {
|
||||
title = mLibaoEntity.getName();
|
||||
getGameDigest();
|
||||
Utils.log( mLibaoEntity.getBeforeStatus() + "===========" + mLibaoEntity.getStatus());
|
||||
String status = mLibaoEntity.getStatus();
|
||||
if (mLibaoEntity.isReuse() && (status.equals("linged") || status.equals("taoed"))) {
|
||||
TokenUtils.getTime(LibaoDetailActivity.this);
|
||||
handler.sendEmptyMessageDelayed(0, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
handler.sendEmptyMessageDelayed(0, 5000);
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -120,4 +167,15 @@ public class LibaoDetailActivity extends BaseDetailActivity {
|
||||
reuse_tv_none_data.setText("天了噜~页面不见了");
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isScroll(boolean isScroll) {
|
||||
mIsScroll = isScroll;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,19 +38,22 @@ import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.LibaoUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.TrafficUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.db.MessageMarkReadDao;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.db.info.MessageMarkReadInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameDigestEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.entity.SuggestionTypeEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
@ -63,6 +66,7 @@ import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.manager.UpdateManager;
|
||||
import com.gh.gamecenter.message.MessageFragment;
|
||||
import com.gh.gamecenter.news.NewsFragment;
|
||||
import com.gh.gamecenter.personal.PersonalFragment;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
@ -71,7 +75,6 @@ import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -80,6 +83,7 @@ import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
@ -101,23 +105,29 @@ import rx.schedulers.Schedulers;
|
||||
public class MainActivity extends BaseFragmentActivity implements OnClickListener {
|
||||
|
||||
private NewsFragment newsFragment;
|
||||
private MessageFragment messageFragment;
|
||||
// private WenDaFragment wenDaFragment;
|
||||
// private ZiXunFragment ziXunFragment;
|
||||
private PersonalFragment personalFragment;
|
||||
private GameFragment gameFragment;
|
||||
private ImageView ivGame;
|
||||
private ImageView ivNews;
|
||||
// private ImageView ivWenDa;
|
||||
private ImageView ivMessage;
|
||||
private ImageView ivPersonal;
|
||||
private TextView tvGame;
|
||||
private TextView tvNews;
|
||||
// private TextView tvWenDa;
|
||||
private TextView tvMessage;
|
||||
private TextView tvPersonal;
|
||||
|
||||
private SharedPreferences sp;
|
||||
private ConcernManager concernManager;
|
||||
|
||||
private String searchHint;
|
||||
private ArrayList<String> searchHint;
|
||||
|
||||
private int currentTab;
|
||||
|
||||
private boolean isNewFirstLaunch;
|
||||
private boolean isSkipped;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
@ -145,7 +155,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
|
||||
if (downloadEntity.getName().contains("光环助手")) {
|
||||
DataUtils.onEvent(MainActivity.this, "软件更新", "下载完成");
|
||||
startActivity(PackageUtils.getInstallIntent(downloadEntity.getPath()));
|
||||
startActivity(PackageUtils.getInstallIntent(MainActivity.this, downloadEntity.getPath()));
|
||||
DataLogUtils.uploadUpgradeLog(MainActivity.this, "install"); //上传更新安装数据
|
||||
} else {
|
||||
statDoneEvent(downloadEntity);
|
||||
@ -172,7 +182,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
DownloadManager.getInstance(MainActivity.this).cancel(downloadEntity.getUrl());
|
||||
} else {
|
||||
if (PackageUtils.isCanLaunchSetup(getApplicationContext(), downloadEntity.getPath())) {
|
||||
startActivity(PackageUtils.getInstallIntent(downloadEntity.getPath()));
|
||||
startActivity(PackageUtils.getInstallIntent(MainActivity.this, downloadEntity.getPath()));
|
||||
} else {
|
||||
// 弹出卸载提示框
|
||||
EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntity.getPath()));
|
||||
@ -227,25 +237,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
DataCollectionUtils.uploadDownload(this, downloadEntity, "完成");
|
||||
|
||||
if (downloadEntity.getEntrance().matches("^" + "\\(游戏\\-插件:滚动图\\[.+\\]\\)" + "$")
|
||||
|| downloadEntity.getEntrance().matches("^" + "\\(游戏\\-专题:滚动图\\[.+\\]\\)" + "$")) {
|
||||
// 首页轮播图数据统计
|
||||
statLunbotuData(downloadEntity.getEntrance());
|
||||
}
|
||||
}
|
||||
|
||||
// 首页轮播图数据统计
|
||||
private void statLunbotuData(String entrance) {
|
||||
int start = entrance.indexOf("[");
|
||||
int end = entrance.indexOf("]");
|
||||
if (start != -1 && end != -1) {
|
||||
entrance = entrance.substring(start + 1, end);
|
||||
String[] values = entrance.split("=");
|
||||
if (values.length == 3) {
|
||||
DataLogUtils.uploadLunbotuLog(this, values[1], values[0], values[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processHijack(DownloadEntity downloadEntity) {
|
||||
@ -346,7 +337,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
setContentView(contentView);
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getApplicationContext()), true);
|
||||
boolean isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getApplicationContext()), true);
|
||||
|
||||
isSkipped = false;
|
||||
|
||||
@ -365,16 +356,13 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
if (!isNewFirstLaunch && sp.getBoolean("autoupdate", true)) {
|
||||
// 检查助手更新
|
||||
UpdateManager.getInstance(this).checkUpdate(true);
|
||||
UpdateManager.getInstance(this).checkUpdate(true, null);
|
||||
}
|
||||
if (isNewFirstLaunch) {
|
||||
getPluginUpdate();
|
||||
sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getApplicationContext()), false).apply();
|
||||
}
|
||||
|
||||
// 获取免责声明
|
||||
getDisclaimer(isNewFirstLaunch);
|
||||
|
||||
// 初始化PlatformUtils
|
||||
PlatformUtils.getInstance(getApplicationContext());
|
||||
|
||||
@ -390,23 +378,152 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
public void run() {
|
||||
// 注册设备
|
||||
TokenUtils.register(MainActivity.this);
|
||||
TokenUtils.getToken(MainActivity.this, false);
|
||||
TokenUtils.checkDeviceInfo(MainActivity.this);
|
||||
TokenUtils.getToken(MainActivity.this, false)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<String>() {
|
||||
@Override
|
||||
public void onResponse(String token) {
|
||||
TokenUtils.checkDeviceInfo(MainActivity.this, token);
|
||||
}
|
||||
});
|
||||
updateUserGhzs();
|
||||
initConcern(); // 初始化关注
|
||||
LibaoUtils.getCunHaoXiang(MainActivity.this, true);
|
||||
}
|
||||
}.start();
|
||||
} else {
|
||||
updateUserGhzs();
|
||||
}
|
||||
|
||||
// 更新用户使用的助手信息
|
||||
updateUserGhzs();
|
||||
|
||||
// 执行跳转事件
|
||||
handler.postDelayed(skipRun, 500);
|
||||
|
||||
Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
|
||||
if (sp.getBoolean("changeDefaultIcon", false) && sp.getInt("default_user_icon", 0) != 0) {
|
||||
postDefaultIcon(true, sp.getInt("default_user_icon", 0));
|
||||
}
|
||||
|
||||
getSuggestionType();
|
||||
|
||||
checkMarkRead(); // 检查是否有记录已读消息
|
||||
}
|
||||
|
||||
private void checkMarkRead() {
|
||||
MessageMarkReadDao readDao = new MessageMarkReadDao(MainActivity.this);
|
||||
List<MessageMarkReadInfo> readInfos = readDao.getAll();
|
||||
if (readInfos == null || readInfos.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MessageMarkReadInfo readInfo = readInfos.get(0);
|
||||
HashMap<String, Boolean> kefuIds = readInfo.getKefuIds();
|
||||
HashMap<String, Boolean> noticeIds = readInfo.getNoticeIds();
|
||||
|
||||
if (kefuIds != null && kefuIds.size() > 0) {
|
||||
Utils.log("======提交已读客服消息");
|
||||
JSONArray array = new JSONArray();
|
||||
for (String s : kefuIds.keySet()) {
|
||||
array.put(s);
|
||||
}
|
||||
Utils.log("======客服id::" + array.toString());
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), array.toString());
|
||||
postMarkRead("kefu", true, body, readDao);
|
||||
}
|
||||
|
||||
if (noticeIds != null && noticeIds.size() > 0) {
|
||||
Utils.log("======提交已读公告消息");
|
||||
JSONArray array = new JSONArray();
|
||||
for (String s : noticeIds.keySet()) {
|
||||
array.put(s);
|
||||
}
|
||||
Utils.log("======客服id::" + array.toString());
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), array.toString());
|
||||
postMarkRead("notice", true, body, readDao);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void postMarkRead(final String type, boolean isCkeck, final RequestBody body, final MessageMarkReadDao readDao) {
|
||||
TokenUtils
|
||||
.getToken(MainActivity.this, isCkeck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
if ("kefu".equals(type)){
|
||||
return RetrofitManager.getApi().postMarkKeFuRead(body, token);
|
||||
} else {
|
||||
return RetrofitManager.getApi().postMarkNoticeRead(body, token);
|
||||
}
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>(){
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
super.onResponse(response);
|
||||
Utils.log("=========postMarkRead::" + type);
|
||||
// if ("kefu".equals(type)) {
|
||||
// readDao.cleanKeFu();
|
||||
// } else {
|
||||
// readDao.cleanNotice();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (e != null && e.code() == 401) {
|
||||
postMarkRead(type, false, body, readDao);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void getSuggestionType() {
|
||||
RetrofitManager
|
||||
.getApi()
|
||||
.getSuggestionType()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<SuggestionTypeEntity>(){
|
||||
@Override
|
||||
public void onResponse(SuggestionTypeEntity response) {
|
||||
super.onResponse(response);
|
||||
Set<String> suggestionGame = response.getGame();
|
||||
Set<String> suggestionLibao = response.getLibao();
|
||||
Set<String> suggestionPlugin = response.getPlugin();
|
||||
Set<String> suggestionService = response.getService();
|
||||
SharedPreferences.Editor edit = sp.edit();
|
||||
if (suggestionGame.size() != 0) {
|
||||
edit.putStringSet("suggestionGame", suggestionGame);
|
||||
}
|
||||
if (suggestionLibao.size() != 0) {
|
||||
edit.putStringSet("suggestionLibao", suggestionLibao);
|
||||
}
|
||||
if (suggestionPlugin.size() != 0) {
|
||||
edit.putStringSet("suggestionPlugin", suggestionPlugin);
|
||||
}
|
||||
if (suggestionService.size() != 0) {
|
||||
edit.putStringSet("suggestionService", suggestionService);
|
||||
}
|
||||
edit.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
Utils.log("反馈的问题选项::ERROR::" + e.toString());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// 更新用户使用的助手信息
|
||||
private void updateUserGhzs() {
|
||||
String version_code = sp.getString("version_code", null);
|
||||
String version_name = sp.getString("version_name", null);
|
||||
@ -525,12 +642,18 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
private void initViews() {
|
||||
findViewById(R.id.main_ll_game).setOnClickListener(this);
|
||||
findViewById(R.id.main_ll_news).setOnClickListener(this);
|
||||
// findViewById(R.id.main_ll_wenda).setOnClickListener(this);
|
||||
findViewById(R.id.main_ll_message).setOnClickListener(this);
|
||||
findViewById(R.id.main_ll_personal).setOnClickListener(this);
|
||||
ivGame = (ImageView) findViewById(R.id.main_iv_game);
|
||||
ivNews = (ImageView) findViewById(R.id.main_iv_news);
|
||||
// ivWenDa = (ImageView) findViewById(R.id.main_iv_wenda);
|
||||
ivMessage = (ImageView) findViewById(R.id.main_iv_message);
|
||||
ivPersonal = (ImageView) findViewById(R.id.main_iv_personal);
|
||||
tvGame = (TextView) findViewById(R.id.main_tv_game);
|
||||
tvNews = (TextView) findViewById(R.id.main_tv_news);
|
||||
// tvWenDa = (TextView) findViewById(R.id.main_tv_wenda);
|
||||
tvMessage = (TextView) findViewById(R.id.main_tv_message);
|
||||
tvPersonal = (TextView) findViewById(R.id.main_tv_personal);
|
||||
}
|
||||
|
||||
@ -574,15 +697,24 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
PackageManager.init(list);
|
||||
|
||||
final CountDownLatch latch = ObservableUtil.latch(list.size(), new Action1<Object>() {
|
||||
// 过滤助手收录的包
|
||||
ArrayList<String> localList = new ArrayList<>();
|
||||
FilterManager filterManager = new FilterManager(this);
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
if (filterManager.isFilter(list.get(i))) {
|
||||
localList.add(list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
final CountDownLatch latch = ObservableUtil.latch(localList.size(), new Action1<Object>() {
|
||||
@Override
|
||||
public void call(Object o) {
|
||||
updateConcern();
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
final String packageName = list.get(i);
|
||||
for (int i = 0, size = localList.size(); i < size; i++) {
|
||||
final String packageName = localList.get(i);
|
||||
RetrofitManager.getApi().getGameDigestByPackageName(packageName)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -848,33 +980,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
// 获取免责声明
|
||||
private void getDisclaimer(final boolean isFirst) {
|
||||
RetrofitManager.getApi().getDisclaimer()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
boolean isShow = response.getBoolean("isShow");
|
||||
sp.edit().putBoolean("isShowDisclaimer", isShow).apply();
|
||||
if (isShow) {
|
||||
String content = response.getString("content");
|
||||
sp.edit().putString("disclaimer", content).apply();
|
||||
if (isFirst) {
|
||||
DialogUtils.showDisclaimerDialog(MainActivity.this, content);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Runnable skipRun = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -910,15 +1015,17 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
RetrofitManager.getApi().getSearchHints()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<String>>() {
|
||||
.subscribe(new Response<ArrayList<String>>() {
|
||||
@Override
|
||||
public void onResponse(List<String> response) {
|
||||
public void onResponse(ArrayList<String> response) {
|
||||
if (response.size() != 0) {
|
||||
if (response.size() == 1) {
|
||||
searchHint = response.get(0);
|
||||
} else {
|
||||
searchHint = response.get(RandomUtils.nextInt(response.size()));
|
||||
}
|
||||
// if (response.size() == 1) {
|
||||
// searchHint = response.get(0);
|
||||
// } else {
|
||||
// searchHint = response.get(RandomUtils.nextInt(response.size()));
|
||||
// }
|
||||
|
||||
searchHint = response;
|
||||
if (gameFragment != null) {
|
||||
gameFragment.setHint(searchHint);
|
||||
}
|
||||
@ -973,9 +1080,15 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
} else if (id == R.id.main_ll_news) {
|
||||
EventBus.getDefault().post(new EBUISwitch("MainActivity", 1));
|
||||
setTabSelection(1);
|
||||
}
|
||||
// else if (id == R.id.main_ll_wenda) {
|
||||
// setTabSelection(2);
|
||||
// }
|
||||
else if (id == R.id.main_ll_message){
|
||||
setTabSelection(2);
|
||||
} else if (id == R.id.main_ll_personal) {
|
||||
EventBus.getDefault().post(new EBUISwitch("MainActivity", 2));
|
||||
setTabSelection(2);
|
||||
setTabSelection(3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1000,7 +1113,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
if (gameFragment == null) {
|
||||
gameFragment = new GameFragment();
|
||||
if (!TextUtils.isEmpty(searchHint)) {
|
||||
if (searchHint != null && searchHint.size() > 0) {
|
||||
gameFragment.setHint(searchHint);
|
||||
}
|
||||
transaction.add(R.id.main_content, gameFragment);
|
||||
@ -1026,7 +1139,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
if (newsFragment == null) {
|
||||
newsFragment = new NewsFragment();
|
||||
if (!TextUtils.isEmpty(searchHint)) {
|
||||
if (searchHint != null && searchHint.size() > 0) {
|
||||
newsFragment.setHint(searchHint);
|
||||
}
|
||||
transaction.add(R.id.main_content, newsFragment);
|
||||
@ -1036,7 +1149,55 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
currentTab = 1;
|
||||
break;
|
||||
// case 2:
|
||||
// ivWenDa.setImageResource(R.drawable.ic_wenda_select);
|
||||
// tvWenDa.setTextColor(getResources().getColor(R.color.theme));
|
||||
// if (wenDaFragment == null) {
|
||||
// List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
// if (list != null) {
|
||||
// for (Fragment fragment : list) {
|
||||
// if (fragment.getClass().equals(WenDaFragment.class)) {
|
||||
// wenDaFragment = (WenDaFragment) fragment;
|
||||
// transaction.show(wenDaFragment);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (wenDaFragment == null) {
|
||||
// wenDaFragment = new WenDaFragment();
|
||||
// transaction.add(R.id.main_content, wenDaFragment);
|
||||
// }
|
||||
// } else {
|
||||
// transaction.show(wenDaFragment);
|
||||
// }
|
||||
// currentTab = 2;
|
||||
// break;
|
||||
|
||||
case 2:
|
||||
ivMessage.setImageResource(R.drawable.ic_message_select);
|
||||
tvMessage.setTextColor(getResources().getColor(R.color.theme));
|
||||
if (messageFragment == null) {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
if (fragment.getClass().equals(MessageFragment.class)) {
|
||||
messageFragment = (MessageFragment) fragment;
|
||||
transaction.show(messageFragment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (messageFragment == null) {
|
||||
messageFragment = new MessageFragment();
|
||||
transaction.add(R.id.main_content, messageFragment);
|
||||
}
|
||||
} else {
|
||||
transaction.show(messageFragment);
|
||||
}
|
||||
currentTab = 2;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
ivPersonal.setImageResource(R.drawable.ic_user_select);
|
||||
tvPersonal.setTextColor(getResources().getColor(R.color.theme));
|
||||
if (personalFragment == null) {
|
||||
@ -1057,7 +1218,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
} else {
|
||||
transaction.show(personalFragment);
|
||||
}
|
||||
currentTab = 2;
|
||||
currentTab = 3;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -1069,9 +1230,13 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
private void clearSelection() {
|
||||
ivGame.setImageResource(R.drawable.ic_game_unselect);
|
||||
ivNews.setImageResource(R.drawable.ic_news_unselect);
|
||||
// ivWenDa.setImageResource(R.drawable.ic_wenda_unselect);
|
||||
ivMessage.setImageResource(R.drawable.ic_message_unselect);
|
||||
ivPersonal.setImageResource(R.drawable.ic_user_unselect);
|
||||
tvGame.setTextColor(Color.parseColor("#a7a8b2"));
|
||||
tvNews.setTextColor(Color.parseColor("#a7a8b2"));
|
||||
// tvWenDa.setTextColor(Color.parseColor("#a7a8b2"));
|
||||
tvMessage.setTextColor(Color.parseColor("#a7a8b2"));
|
||||
tvPersonal.setTextColor(Color.parseColor("#a7a8b2"));
|
||||
}
|
||||
|
||||
@ -1083,6 +1248,12 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
if (gameFragment != null) {
|
||||
transaction.hide(gameFragment);
|
||||
}
|
||||
// if (wenDaFragment != null) {
|
||||
// transaction.hide(wenDaFragment);
|
||||
// }
|
||||
if (messageFragment != null) {
|
||||
transaction.hide(messageFragment);
|
||||
}
|
||||
if (newsFragment != null) {
|
||||
transaction.hide(newsFragment);
|
||||
}
|
||||
@ -1127,17 +1298,17 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
DataUtils.onEvent(this, "插件化", mDownloadEntity.getName(), kv6);
|
||||
}
|
||||
|
||||
if (!mDownloadEntity.isPlugin() // 不是插件游戏,自己删除数据库数据和安装包
|
||||
|| PackageUtils.isSignature(this, packageName)) {// 是插件游戏,判断签名是否相同,是才删除数据库数据和安装包
|
||||
// if (!mDownloadEntity.isPlugin() // 不是插件游戏,自己删除数据库数据和安装包
|
||||
// || PackageUtils.isSignature(this, packageName)) {// 是插件游戏,判断签名是否相同,是才删除数据库数据和安装包
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(
|
||||
mDownloadEntity.getUrl(), sp.getBoolean("autodelete", true));
|
||||
}
|
||||
// }
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
kv6.put("安装或卸载", "卸载完成");
|
||||
DataUtils.onEvent(this, "插件化", mDownloadEntity.getName(), kv6);
|
||||
|
||||
startActivity(PackageUtils.getInstallIntent(mDownloadEntity.getPath()));
|
||||
startActivity(PackageUtils.getInstallIntent(this, mDownloadEntity.getPath()));
|
||||
}
|
||||
}
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
@ -1148,7 +1319,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
if (!filterManager.isFilter(packageName)) {
|
||||
if (filterManager.isFilter(packageName)) {
|
||||
concernManager.updateByPackageName(packageName);
|
||||
}
|
||||
}
|
||||
@ -1249,6 +1420,46 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
|
||||
if (sp.getBoolean("changeDefaultIcon", false) && sp.getInt("default_user_icon", 0) != 0) {
|
||||
postDefaultIcon(true, sp.getInt("default_user_icon", 0));
|
||||
}
|
||||
}
|
||||
|
||||
// 提交默认头像
|
||||
private void postDefaultIcon(boolean isCheck, final int i) {
|
||||
TokenUtils.getToken(this, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("icon_key" , "icon" + i);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
return RetrofitManager.getUser().postDefaultIcon(token, body);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse(){
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
super.onResponse(response);
|
||||
sp.edit().putBoolean("changeDefaultIcon", false);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (e != null) {
|
||||
if (e.code() == 401) {
|
||||
postDefaultIcon(true, i);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
@ -27,6 +28,7 @@ import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.PostCommentUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
@ -55,7 +57,6 @@ import butterknife.OnClick;
|
||||
import butterknife.OnTouch;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
@ -88,6 +89,7 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
private CommentDao mCommentDao;
|
||||
|
||||
private ConcernEntity mConcernEntity;
|
||||
private CommentEntity mCommentEntity; // 回复评论的实体 用完马上清空
|
||||
|
||||
private String newsId;
|
||||
|
||||
@ -105,6 +107,8 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
|
||||
mConcernEntity = (ConcernEntity) AppController.get("ConcernEntity", true);
|
||||
|
||||
mCommentEntity = (CommentEntity) AppController.get("CommentEntity", true); // 来自新闻详情-评论回复
|
||||
|
||||
Intent intent = getIntent();
|
||||
newsId = intent.getExtras().getString("newsId");
|
||||
commentNum = intent.getExtras().getInt("commentNum");
|
||||
@ -152,13 +156,12 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
MessageDetailActivity.this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (sp.getString("user_icon", "res:///"+
|
||||
R.drawable.user_default_icon_comment).isEmpty()) {
|
||||
mMessageDetailIconDv.setImageURI("res:///" +
|
||||
R.drawable.user_default_icon_comment);
|
||||
String icon = sp.getString("user_icon", null);
|
||||
if (TextUtils.isEmpty(icon)) {
|
||||
mMessageDetailIconDv.setImageURI(
|
||||
Uri.parse("res:///" + R.drawable.user_default_icon_comment));
|
||||
} else {
|
||||
mMessageDetailIconDv.setImageURI(sp.getString("user_icon", "res:///"+
|
||||
R.drawable.user_default_icon_comment));
|
||||
ImageUtils.display(mMessageDetailIconDv, icon);
|
||||
}
|
||||
mMessageDetailUserNameTv.setText(sp.getString("user_name", "光环用户"));
|
||||
}
|
||||
@ -166,11 +169,12 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
}
|
||||
}).start();
|
||||
} else {
|
||||
if (sp.getString("user_icon", "res:///"+ R.drawable.user_default_icon_comment).isEmpty()) {
|
||||
mMessageDetailIconDv.setImageURI("res:///" + R.drawable.user_default_icon_comment);
|
||||
String icon = sp.getString("user_icon", null);
|
||||
if (TextUtils.isEmpty(icon)) {
|
||||
mMessageDetailIconDv.setImageURI(
|
||||
Uri.parse("res:///" + R.drawable.user_default_icon_comment));
|
||||
} else {
|
||||
mMessageDetailIconDv.setImageURI(sp.getString("user_icon", "res:///"+
|
||||
R.drawable.user_default_icon_comment));
|
||||
ImageUtils.display(mMessageDetailIconDv, icon);
|
||||
}
|
||||
mMessageDetailUserNameTv.setText(sp.getString("user_name", "光环用户"));
|
||||
}
|
||||
@ -209,8 +213,8 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
.subscribe(new com.gh.gamecenter.retrofit.Response<List<CommentnumEntity>>(){
|
||||
|
||||
@Override
|
||||
public void onNext(List<CommentnumEntity> response) {
|
||||
super.onNext(response);
|
||||
public void onResponse(List<CommentnumEntity> response) {
|
||||
super.onResponse(response);
|
||||
if (response.size() > 0) {
|
||||
if (!TextUtils.isEmpty(mConcernEntity.getId())){
|
||||
commentNum = response.get(0).getNum();
|
||||
@ -258,9 +262,9 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
.getNewsViews(newsId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Action1<List<ViewsEntity>>() {
|
||||
.subscribe(new Response<List<ViewsEntity>>(){
|
||||
@Override
|
||||
public void call(List<ViewsEntity> viewsEntities) {
|
||||
public void onResponse(List<ViewsEntity> viewsEntities) {
|
||||
if (viewsEntities.size() > 0) {
|
||||
mConcernEntity.setViews(viewsEntities.get(0).getViews());
|
||||
adapter.notifyItemChanged(0);
|
||||
@ -345,14 +349,13 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
newsId = mConcernEntity.getId();
|
||||
}
|
||||
|
||||
PostCommentUtils.addCommentData(MessageDetailActivity.this, newsId, jsonObject.toString(), true,
|
||||
PostCommentUtils.addCommentData(MessageDetailActivity.this, newsId, jsonObject.toString(), true, mCommentEntity,
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSucced(JSONObject response) {
|
||||
mSendingDialog.dismiss();
|
||||
toast("发表成功");
|
||||
mMessageDetailEt.setText("");
|
||||
setSoftInput(false);
|
||||
|
||||
try {
|
||||
mCommentDao.add(new CommentInfo(response.getString("_id")));//添加评论id到数据库, 后续判断是否是自身评论
|
||||
@ -367,6 +370,15 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
cacheObject.put("vote", 0);
|
||||
cacheObject.put("user", cacheUser);
|
||||
|
||||
if (mCommentEntity != null) {
|
||||
JSONObject cacheParent = new JSONObject();
|
||||
JSONObject cacheParentUser = new JSONObject();
|
||||
cacheParentUser.put("_id", mCommentEntity.getId());
|
||||
cacheParentUser.put("name", mCommentEntity.getUser().getName());
|
||||
cacheParent.put("user", cacheParentUser);
|
||||
cacheObject.put("parent", cacheParent);
|
||||
}
|
||||
|
||||
CommentEntity commentEntity = new Gson().fromJson(cacheObject.toString(), CommentEntity.class);
|
||||
if (mConcernEntity != null) {
|
||||
adapter.addNormalComment(commentEntity);
|
||||
@ -389,6 +401,8 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
showNoConnection(false);
|
||||
}
|
||||
|
||||
setSoftInput(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -479,6 +493,12 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
mMessageDetailEt.requestFocus();
|
||||
mColseCommentV.setVisibility(View.VISIBLE);
|
||||
|
||||
if (mCommentEntity != null && mCommentEntity.getUser() != null) {
|
||||
mMessageDetailEt.setHint("回复 " + mCommentEntity.getUser().getName() + ":");
|
||||
} else {
|
||||
mMessageDetailEt.setHint("优质评论会被优先展示");
|
||||
}
|
||||
|
||||
} else {
|
||||
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
|
||||
mMessageDetailCommentHintRl.setVisibility(View.VISIBLE);
|
||||
@ -486,11 +506,18 @@ public class MessageDetailActivity extends BaseActivity implements MessageDetail
|
||||
mMessageDetailCommentRl.setVisibility(View.GONE);
|
||||
mMessageDetailUserRl.setVisibility(View.GONE);
|
||||
mColseCommentV.setVisibility(View.GONE);
|
||||
|
||||
if (mCommentEntity != null) {
|
||||
mCommentEntity = null; // 清空当前评论实体
|
||||
mMessageDetailEt.setHint("优质评论会被优先展示");
|
||||
mMessageDetailEt.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showSoftInput() {
|
||||
public void showSoftInput(CommentEntity entity) {
|
||||
mCommentEntity = entity;
|
||||
setSoftInput(true);
|
||||
}
|
||||
|
||||
|
||||
647
app/src/main/java/com/gh/gamecenter/NewGameDetailActivity.java
Normal file
647
app/src/main/java/com/gh/gamecenter/NewGameDetailActivity.java
Normal file
@ -0,0 +1,647 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.common.view.NoScrollableViewPager;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.FragmentAdapter;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameDetailEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBMoveTop;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.gamedetail.FuliFragment;
|
||||
import com.gh.gamecenter.gamedetail.XinXiFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.jakewharton.rxbinding.view.RxView;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/24.
|
||||
* 游戏详情适配器
|
||||
*/
|
||||
public class NewGameDetailActivity extends BaseFragmentActivity {
|
||||
|
||||
@BindView(R.id.gamedetail_vp) NoScrollableViewPager mViewPager;
|
||||
@BindView(R.id.gamedetail_top) RelativeLayout mTopLl;
|
||||
@BindView(R.id.gamedetail_tabbar_rl) RelativeLayout mTabBarRl;
|
||||
@BindView(R.id.reuse_ll_loading) LinearLayout mLoading;
|
||||
@BindView(R.id.reuse_no_connection) LinearLayout mNoConnection;
|
||||
@BindView(R.id.actionbar_tv_title) TextView mTitle;
|
||||
@BindView(R.id.gamedetail_iv_thumb) SimpleDraweeView mGameIcon;
|
||||
@BindView(R.id.gamedetail_tv_name) TextView mGameName;
|
||||
@BindView(R.id.gamedetail_tv_info) TextView mGameInfo;
|
||||
@BindView(R.id.gamedetail_tv_concern) TextView mGameConcern;
|
||||
@BindView(R.id.gamedetail_tabbar) LinearLayout mTabBar;
|
||||
@BindView(R.id.gamedetail_tabbar_fuli) TextView mTanBarFuLi;
|
||||
@BindView(R.id.gamedetail_tabbar_xinxi) TextView mTanBarXinXi;
|
||||
@BindView(R.id.gamedetail_tabbar_fuli_tv) TextView mTanBarFuLiTv;
|
||||
@BindView(R.id.gamedetail_tabbar_xinxi_tv) TextView mTanBarXinXiTv;
|
||||
@BindView(R.id.gamedetail_share) ImageView mShareIv;
|
||||
|
||||
@BindView(R.id.detail_ll_bottom) LinearLayout mDownloadBottom;
|
||||
@BindView(R.id.detail_tv_download) TextView mDownloadTv;
|
||||
@BindView(R.id.detail_tv_per) TextView mDownloadPer;
|
||||
@BindView(R.id.detail_pb_progressbar) ProgressBar mDownloadPb;
|
||||
|
||||
private RelativeLayout.LayoutParams top_rparams;
|
||||
|
||||
private ConcernManager mConcernManager;
|
||||
|
||||
private String mGameId;
|
||||
|
||||
private GameEntity mGameEntity;
|
||||
private DownloadEntity mDownloadEntity;
|
||||
|
||||
private String downloadAddWord;
|
||||
private String downloadOffText;
|
||||
|
||||
private String name;
|
||||
private String title;
|
||||
private String shareCode;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
if (mGameEntity != null && mGameEntity.getApk().size() == 1) {
|
||||
String url = mGameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(downloadEntity.getUrl())) {
|
||||
if (!"pause".equals(DownloadManager.getInstance(NewGameDetailActivity.this).
|
||||
getStatus(downloadEntity.getUrl()))) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//接收QQ或者QQ空间分享回调
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == com.tencent.connect.common.Constants.REQUEST_QQ_SHARE
|
||||
|| requestCode == com.tencent.connect.common.Constants.REQUEST_QZONE_SHARE) {
|
||||
Tencent.onActivityResultData(requestCode, resultCode, data, ShareUtils.getInstance(this).QqShareListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View view = View.inflate(NewGameDetailActivity.this, R.layout.activity_game_detail, null);
|
||||
init(view);
|
||||
|
||||
mViewPager.setScrollable(false);
|
||||
|
||||
mConcernManager = new ConcernManager(NewGameDetailActivity.this);
|
||||
|
||||
name = "游戏详情";
|
||||
|
||||
mGameId = getIntent().getStringExtra("gameId");
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
mGameId = getIntent().getBundleExtra("data").getString("gameId");
|
||||
}
|
||||
|
||||
if (mGameId == null) {
|
||||
mGameEntity = (GameEntity) AppController.get("GameEntity", false);
|
||||
if (mGameEntity != null) {
|
||||
mGameId = mGameEntity.getId();
|
||||
mTitle.setText(mGameEntity.getName());
|
||||
name = mGameEntity.getName();
|
||||
}
|
||||
}
|
||||
if (mGameEntity != null) {
|
||||
getGameDetail();
|
||||
} else if (mGameId != null) {
|
||||
getGameDigest();
|
||||
} else {
|
||||
mLoading.setVisibility(View.GONE);
|
||||
mNoConnection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initGameDetailTop() {
|
||||
|
||||
mLoading.setVisibility(View.GONE);
|
||||
mTopLl.setVisibility(View.VISIBLE);
|
||||
|
||||
top_rparams = (RelativeLayout.LayoutParams) mTopLl.getLayoutParams();
|
||||
|
||||
if (mConcernManager.isConcern(mGameEntity.getId())) {
|
||||
mGameConcern.setText("取消关注");
|
||||
mGameConcern.setBackgroundResource(R.drawable.border_red_bg);
|
||||
mGameConcern.setTextColor(Color.parseColor("#ff4147"));
|
||||
} else {
|
||||
mGameConcern.setText("关注");
|
||||
mGameConcern.setBackgroundResource(R.drawable.textview_concern_red_style);
|
||||
mGameConcern.setTextColor(0xffffffff);
|
||||
}
|
||||
|
||||
mGameName.setText(mGameEntity.getName());
|
||||
ImageUtils.display(mGameIcon, mGameEntity.getIcon());
|
||||
if (mGameEntity.getApk() == null || mGameEntity.getApk().isEmpty()) {
|
||||
mGameInfo.setText("");
|
||||
} else {
|
||||
ApkEntity apkEntity = mGameEntity.getApk().get(0);
|
||||
mGameInfo.setText(String.format("V%s | %s", apkEntity.getVersion(), apkEntity.getSize()));
|
||||
}
|
||||
mGameConcern.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final TextView concern = (TextView) v;
|
||||
if ("关注".equals(concern.getText().toString())) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "关注");
|
||||
DataUtils.onEvent(NewGameDetailActivity.this, "游戏关注", mGameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("点击", "关注");
|
||||
DataUtils.onEvent(NewGameDetailActivity.this, "插件数据", mGameEntity.getName(), kv2);
|
||||
|
||||
DataCollectionUtils.uploadConcern(NewGameDetailActivity.this, mGameEntity.getName(), mGameEntity.getId(), "关注");
|
||||
|
||||
mConcernManager.addByEntity(mGameEntity);
|
||||
concern.setText("取消关注");
|
||||
concern.setBackgroundResource(R.drawable.border_red_bg);
|
||||
concern.setTextColor(Color.parseColor("#ff4147"));
|
||||
|
||||
Toast.makeText(NewGameDetailActivity.this, "关注成功", Toast.LENGTH_SHORT).show();
|
||||
|
||||
// 添加关注
|
||||
ConcernUtils.postConcernGameId(NewGameDetailActivity.this, mGameEntity.getId());
|
||||
} else {
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("点击", "取消关注");
|
||||
DataUtils.onEvent(NewGameDetailActivity.this, "插件数据", mGameEntity.getName(), kv2);
|
||||
|
||||
DialogUtils.showCancelDialog(NewGameDetailActivity.this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("状态", "取消关注");
|
||||
DataUtils.onEvent(NewGameDetailActivity.this, "游戏关注", mGameEntity.getName(), kv);
|
||||
|
||||
DataCollectionUtils.uploadConcern(NewGameDetailActivity.this,
|
||||
mGameEntity.getName(), mGameEntity.getId(), "取消关注");
|
||||
|
||||
mConcernManager.deleteConcern(mGameEntity.getId());
|
||||
concern.setText("关注");
|
||||
concern.setBackgroundResource(R.drawable.textview_concern_red_style);
|
||||
concern.setTextColor(0xffffffff);
|
||||
|
||||
// 取消关注
|
||||
ConcernUtils.deleteConcernData(NewGameDetailActivity.this, mGameEntity.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// 获取游戏摘要
|
||||
private void getGameDigest() {
|
||||
RetrofitManager.getApi().getGameDigest(mGameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onResponse(GameEntity response) {
|
||||
mGameEntity = response;
|
||||
AppController.put("GameEntity", response);
|
||||
|
||||
mTitle.setText(mGameEntity.getName());
|
||||
mGameId = response.getId();
|
||||
name = mGameEntity.getName();
|
||||
getGameDetail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
mLoading.setVisibility(View.GONE);
|
||||
mNoConnection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 获取游戏详情
|
||||
public void getGameDetail() {
|
||||
RetrofitManager.getApi().getGameDetail(mGameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameDetailEntity>() {
|
||||
@Override
|
||||
public void onResponse(GameDetailEntity response) {
|
||||
// 过滤过期公告
|
||||
if (response.getNotice() != null && response.getNotice().size() > 0) {
|
||||
long l = System.currentTimeMillis();
|
||||
for (int i = 0; i < response.getNotice().size(); i++) {
|
||||
if (l > (response.getNotice().get(i).getOvertime()*1000)) {
|
||||
response.getNotice().remove(i);
|
||||
i --;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AppController.put("GameDetailEntity", response);
|
||||
|
||||
downloadAddWord = response.getDownloadAddWord();
|
||||
downloadOffText = response.getDownloadOffText();
|
||||
shareCode = response.getShareCode();
|
||||
|
||||
List<Fragment> list = new ArrayList<>();
|
||||
if (mGameEntity != null && !mGameEntity.isLibaoExists()
|
||||
&& TextUtils.isEmpty(response.getFulishuoming())
|
||||
&& (response.getKaiFuServer() == null
|
||||
|| (response.getKaiFuServer() != null
|
||||
&& response.getKaiFuServer().size() == 0))) {
|
||||
XinXiFragment xinXiFragment = new XinXiFragment();
|
||||
xinXiFragment.setIsTabBar(true);
|
||||
list.add(xinXiFragment);
|
||||
mTabBar.setVisibility(View.GONE);
|
||||
} else {
|
||||
list.add(new FuliFragment());
|
||||
list.add(new XinXiFragment());
|
||||
}
|
||||
|
||||
mViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), list));
|
||||
initGameDetailTop();
|
||||
|
||||
initDownload(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBMoveTop moveTop) {
|
||||
if (moveTop.getType().equals("top")) {
|
||||
if (moveTop.getVisibility() == View.VISIBLE && mTabBar.getVisibility() == View.VISIBLE) {
|
||||
mTabBarRl.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mTabBarRl.setVisibility( View.GONE);
|
||||
}
|
||||
int topMargin = moveTop.getTopMargin();
|
||||
if (top_rparams != null && top_rparams.topMargin != topMargin) {
|
||||
if (topMargin > -120) {
|
||||
mTitle.setVisibility(View.GONE);
|
||||
} else {
|
||||
mTitle.setVisibility(View.VISIBLE);
|
||||
}
|
||||
top_rparams.topMargin = moveTop.getTopMargin();
|
||||
mTopLl.setLayoutParams(top_rparams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 接收下载被删除消息
|
||||
public void onEvent(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())
|
||||
&& mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
String url = mGameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(status.getUrl())) {
|
||||
initDownload(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 接受安装、卸载消息
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
if (mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
String packageName = mGameEntity.getApk().get(0).getPackageName();
|
||||
if (packageName.equals(busFour.getPackageName())) {
|
||||
initDownload(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
initDownload(true);
|
||||
}
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
|
||||
@OnClick({R.id.detail_tv_download, R.id.detail_pb_progressbar
|
||||
, R.id.detail_tv_per, R.id.gamedetail_tabbar_xinxi, R.id.gamedetail_tabbar_xinxi_tv
|
||||
, R.id.gamedetail_tabbar_fuli, R.id.gamedetail_tabbar_fuli_tv, R.id.gamedetail_share})
|
||||
public void onClick(View v) {
|
||||
if (v == mDownloadTv) {
|
||||
if (mGameEntity != null && !mGameEntity.getApk().isEmpty()) {
|
||||
if (mGameEntity.getApk().size() == 1) {
|
||||
if (NetworkUtils.isWifiConnected(this)) {
|
||||
download();
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(this, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
download();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
DownloadDialog.getInstance(this).showPopupWindow(v, mGameEntity, entrance, name + ":" + title);
|
||||
}
|
||||
} else {
|
||||
toast("稍等片刻~!游戏正在上传中...");
|
||||
}
|
||||
} else if (v == mDownloadPb || v == mDownloadPer) {
|
||||
String str = mDownloadPer.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
Intent intent = new Intent(this, DownloadManagerActivity.class);
|
||||
intent.putExtra("currentItem", 1);
|
||||
intent.putExtra("url", mGameEntity.getApk().get(0).getUrl());
|
||||
intent.putExtra("entrance", entrance + "+(" + name + "[" + title + "])");
|
||||
startActivity(intent);
|
||||
} else if ("安装".equals(str)) {
|
||||
PackageUtils.launchSetup(this, mDownloadEntity.getPath());
|
||||
}
|
||||
} else if (v == mTanBarFuLi || v == mTanBarFuLiTv) {
|
||||
mTanBarFuLi.setTextColor(Color.WHITE);
|
||||
mTanBarFuLiTv.setTextColor(Color.WHITE);
|
||||
mTanBarFuLi.setBackgroundResource(R.drawable.gamedetail_tag_select_bg);
|
||||
mTanBarFuLiTv.setBackgroundResource(R.drawable.gamedetail_tag_select_bg);
|
||||
mTanBarXinXi.setTextColor(Color.BLACK);
|
||||
mTanBarXinXiTv.setTextColor(Color.BLACK);
|
||||
mTanBarXinXi.setBackgroundDrawable(new ColorDrawable(0));
|
||||
mTanBarXinXiTv.setBackgroundDrawable(new ColorDrawable(0));
|
||||
mViewPager.setCurrentItem(0);
|
||||
|
||||
} else if (v == mTanBarXinXi || v == mTanBarXinXiTv) {
|
||||
mTanBarXinXiTv.setTextColor(Color.WHITE);
|
||||
mTanBarXinXi.setTextColor(Color.WHITE);
|
||||
mTanBarXinXiTv.setBackgroundResource(R.drawable.gamedetail_tag_unselect_bg);
|
||||
mTanBarXinXi.setBackgroundResource(R.drawable.gamedetail_tag_unselect_bg);
|
||||
mTanBarFuLi.setTextColor(Color.BLACK);
|
||||
mTanBarFuLiTv.setTextColor(Color.BLACK);
|
||||
mTanBarFuLi.setBackgroundDrawable(new ColorDrawable(0));
|
||||
mTanBarFuLiTv.setBackgroundDrawable(new ColorDrawable(0));
|
||||
mViewPager.setCurrentItem(1);
|
||||
} else if (v == mShareIv) {
|
||||
if (TextUtils.isEmpty(shareCode)) return;
|
||||
// 防抖处理
|
||||
RxView.clicks(mShareIv)
|
||||
.throttleFirst(1, TimeUnit.SECONDS)
|
||||
.subscribe(new Action1<Void>() {
|
||||
@Override
|
||||
public void call(Void aVoid) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("点击", "分享");
|
||||
DataUtils.onEvent(NewGameDetailActivity.this, "插件数据", mGameEntity.getName(), kv);
|
||||
|
||||
DataCollectionUtils.uploadClick(NewGameDetailActivity.this, "分享", "游戏详情", mGameEntity.getName());
|
||||
|
||||
String url = "http://www.ghzhushou.com/game/" + shareCode;
|
||||
showShare(url, mGameEntity.getName(), mGameEntity.getIcon(), null, mGameEntity.getTag());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void download() {
|
||||
String str = mDownloadTv.getText().toString();
|
||||
if (str.contains("启动")) {
|
||||
DataUtils.onGameLaunchEvent(this, mGameEntity.getName(), mGameEntity.getApk().get(0).getPlatform(), name);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(this, mGameEntity.getApk().get(0).getPackageName());
|
||||
} else {
|
||||
String method;
|
||||
if (str.contains("更新")) {
|
||||
method = "更新";
|
||||
} else if (str.contains("插件化")) {
|
||||
method = "插件化";
|
||||
} else {
|
||||
method = "下载";
|
||||
}
|
||||
ApkEntity apkEntity = mGameEntity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(this, apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
DataUtils.onGameDownloadEvent(this, mGameEntity.getName(), apkEntity.getPlatform(), entrance, "下载开始");
|
||||
|
||||
DownloadManager.createDownload(this, apkEntity, mGameEntity, method, entrance, name + ":" + title);
|
||||
|
||||
mDownloadTv.setVisibility(View.GONE);
|
||||
mDownloadPb.setVisibility(View.VISIBLE);
|
||||
mDownloadPer.setVisibility(View.VISIBLE);
|
||||
mDownloadPb.setProgress(0);
|
||||
mDownloadPer.setText("0.0%");
|
||||
|
||||
DownloadManager.getInstance(NewGameDetailActivity.this).putStatus(apkEntity.getUrl(), "downloading");
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
mDownloadPb.setProgress((int) (mDownloadEntity.getPercent() * 10));
|
||||
mDownloadPer.setTextColor(0xFFFFFFFF);
|
||||
switch (mDownloadEntity.getStatus()) {
|
||||
case downloading:
|
||||
case pause:
|
||||
case timeout:
|
||||
case neterror:
|
||||
case waiting:
|
||||
mDownloadPer.setText("下载中");
|
||||
break;
|
||||
case done:
|
||||
mDownloadPer.setText("安装");
|
||||
if (mDownloadEntity.isPluggable()
|
||||
&& PackageManager.isInstalled(mDownloadEntity.getPackageName())) {
|
||||
mDownloadPb.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_plugin_radius_style));
|
||||
} else {
|
||||
mDownloadPb.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_normal_radius_style));
|
||||
}
|
||||
break;
|
||||
case cancel:
|
||||
case hijack:
|
||||
case notfound:
|
||||
initDownload(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void initDownload(boolean isCheck) {
|
||||
if (Config.isShow(this)) {
|
||||
mDownloadBottom.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mDownloadBottom.setVisibility(View.GONE);
|
||||
}
|
||||
if (mGameEntity != null && "光环助手".equals(mGameEntity.getName())) {
|
||||
mDownloadBottom.setVisibility(View.GONE);
|
||||
} else if (mGameEntity == null || mGameEntity.getApk().isEmpty()) {
|
||||
mDownloadTv.setVisibility(View.VISIBLE);
|
||||
mDownloadPb.setVisibility(View.GONE);
|
||||
mDownloadPer.setVisibility(View.GONE);
|
||||
if (TextUtils.isEmpty(downloadOffText)) {
|
||||
mDownloadTv.setText("暂无下载");
|
||||
} else {
|
||||
mDownloadTv.setText(downloadOffText);
|
||||
}
|
||||
mDownloadTv.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
mDownloadTv.setTextColor(0xFF999999);
|
||||
mDownloadTv.setClickable(false);
|
||||
} else {
|
||||
mDownloadTv.setVisibility(View.VISIBLE);
|
||||
mDownloadPb.setVisibility(View.GONE);
|
||||
mDownloadPer.setVisibility(View.GONE);
|
||||
boolean isInstalled = false;
|
||||
if (mGameEntity.getApk() != null && mGameEntity.getApk().size() == 1
|
||||
&& PackageManager.isInstalled(mGameEntity.getApk().get(0).getPackageName())) {
|
||||
isInstalled = true;
|
||||
}
|
||||
if (isInstalled) {
|
||||
if (PackageManager.isCanUpdate(mGameEntity.getId(), mGameEntity.getApk().get(0).getPackageName())) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
mDownloadTv.setText(String.format("更新《%s》",
|
||||
mGameEntity.getName()));
|
||||
} else {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
mDownloadTv.setText(String.format("更新《%s》%s",
|
||||
mGameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
} else {
|
||||
if (mGameEntity.getTag() != null && mGameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(mGameEntity.getApk().get(0).getGhVersion())
|
||||
&& !PackageUtils.isSignature(this, mGameEntity.getApk().get(0).getPackageName())) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
mDownloadTv.setText(String.format("插件化《%s》",
|
||||
mGameEntity.getName()));
|
||||
} else {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
mDownloadTv.setText(String.format("插件化《%s》%s",
|
||||
mGameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
} else {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
mDownloadTv.setText(String.format("启动《%s》",
|
||||
mGameEntity.getName()));
|
||||
} else {
|
||||
mDownloadTv.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
mDownloadTv.setText(String.format("启动《%s》%s",
|
||||
mGameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String status = GameUtils.getDownloadBtnText(this, mGameEntity);
|
||||
if ("插件化".equals(status)) {
|
||||
mDownloadTv.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else if ("打开".equals(status)) {
|
||||
mDownloadTv.setBackgroundResource(R.drawable.game_item_btn_launch_style);
|
||||
} else {
|
||||
mDownloadTv.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
mDownloadTv.setText(String.format(status + "《%s》",
|
||||
mGameEntity.getName()));
|
||||
} else {
|
||||
mDownloadTv.setText(String.format(status + "《%s》%s",
|
||||
mGameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isCheck && mGameEntity != null
|
||||
&& mGameEntity.getApk() != null
|
||||
&& mGameEntity.getApk().size() == 1) {
|
||||
String url = mGameEntity.getApk().get(0).getUrl();
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(getApplicationContext()).get(url);
|
||||
if (downloadEntity != null) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
mDownloadTv.setVisibility(View.GONE);
|
||||
mDownloadPb.setVisibility(View.VISIBLE);
|
||||
mDownloadPer.setVisibility(View.VISIBLE);
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -34,6 +34,7 @@ import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
@ -157,6 +158,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener
|
||||
|
||||
detail_rv_show.setHasFixedSize(true);
|
||||
detail_rv_show.setLayoutManager(new LinearLayoutManager(this));
|
||||
detail_rv_show.addItemDecoration(new VerticalItemDecoration(this, 8, false));
|
||||
adapter = new NewsDetailAdapter(this, entrance);
|
||||
detail_rv_show.setAdapter(adapter);
|
||||
|
||||
@ -423,6 +425,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener
|
||||
String str = detail_tv_per.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
Intent intent = new Intent(this, DownloadManagerActivity.class);
|
||||
intent.putExtra("currentItem", 1);
|
||||
intent.putExtra("url", gameEntity.getApk().get(0).getUrl());
|
||||
intent.putExtra("entrance", entrance + "(新闻详情[" + adapter.getTitle() + "])");
|
||||
startActivity(intent);
|
||||
|
||||
123
app/src/main/java/com/gh/gamecenter/NewsNormalActivity.java
Normal file
123
app/src/main/java/com/gh/gamecenter/NewsNormalActivity.java
Normal file
@ -0,0 +1,123 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.NewsNormalAdapter;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/15.
|
||||
*
|
||||
* 原创 + 资讯
|
||||
*/
|
||||
public class NewsNormalActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener{
|
||||
|
||||
@BindView(R.id.newsnormal_srl)
|
||||
SwipeRefreshLayout mRefreshLayout;
|
||||
@BindView(R.id.newsnormal_rv)
|
||||
RecyclerView mRecyclerView;
|
||||
@BindView(R.id.newsnormal_pb)
|
||||
ProgressBarCircularIndeterminate loadingLayout;
|
||||
@BindView(R.id.reuse_no_connection) LinearLayout mNoConnectionLayout;
|
||||
|
||||
private LinearLayoutManager layoutManager;
|
||||
private NewsNormalAdapter mAdapter;
|
||||
|
||||
private String mNewsType;
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAdapter = new NewsNormalAdapter(NewsNormalActivity.this, mNewsType);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mNewsType = getIntent().getExtras().getString("newsType");
|
||||
|
||||
View view = View.inflate(this, R.layout.activity_newsnormal, null);
|
||||
|
||||
if ("yuanchuang".equals(mNewsType)) {
|
||||
init(view, "原创");
|
||||
} else {
|
||||
init(view, "资讯");
|
||||
}
|
||||
|
||||
mRefreshLayout.setColorSchemeResources(R.color.theme);
|
||||
mRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
mAdapter = new NewsNormalAdapter(NewsNormalActivity.this, mNewsType);
|
||||
mRecyclerView.addItemDecoration(new VerticalItemDecoration(this, 8, true));
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() + 1 == mAdapter.getItemCount()) {
|
||||
if (!mAdapter.isOver() && !mAdapter.isLoading() && !mAdapter.isNetworkError()) {
|
||||
mAdapter.addList(mAdapter.getNewsListSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@OnClick(R.id.reuse_no_connection)
|
||||
public void reconnection() { // 重新连接
|
||||
mRefreshLayout.setRefreshing(true);
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
loadingLayout.setVisibility(View.VISIBLE);
|
||||
mNoConnectionLayout.setVisibility(View.GONE);
|
||||
mRecyclerView.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() { // 数据加载成功回调
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
loadingLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() { // 数据加载失败回调
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
loadingLayout.setVisibility(View.GONE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
mNoConnectionLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
// 连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (mNoConnectionLayout.getVisibility() == View.VISIBLE) {
|
||||
reconnection();
|
||||
} else if (mAdapter.isNetworkError()) {
|
||||
mAdapter.setNetworkError(false);
|
||||
mAdapter.notifyItemChanged(mAdapter.getItemCount() - 1);
|
||||
mAdapter.addList(mAdapter.getNewsListSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
mRecyclerView.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
@ -2,10 +2,10 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -17,15 +17,13 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.MeasureHeightLayoutManager;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.NewsTextViewHolder;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
@ -53,7 +51,6 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
@BindView(R.id.et_search) EditText et_search;
|
||||
@BindView(R.id.gamedetail_news_ll_loading) LinearLayout gamedetail_news_ll_loading;
|
||||
@BindView(R.id.reuse_no_connection) LinearLayout reuse_no_connection;
|
||||
@BindView(R.id.gamedetail_news_cardView) CardLinearLayout gamedetail_news_cardView;
|
||||
|
||||
private MeasureHeightLayoutManager layoutManager;
|
||||
private List<NewsEntity> newsEntities;
|
||||
@ -88,14 +85,6 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
|
||||
ViewGroup.LayoutParams params = gamedetail_news_cardView.getLayoutParams();
|
||||
params.height = outMetrics.heightPixels
|
||||
- DisplayUtils.dip2px(this, 38 + 16 + 8 + 8)
|
||||
- getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE).getInt("actionbar_height",
|
||||
DisplayUtils.dip2px(getApplicationContext(), 48))
|
||||
- DisplayUtils.getStatusBarHeight(getResources());
|
||||
gamedetail_news_cardView.setLayoutParams(params);
|
||||
|
||||
newsEntities = new ArrayList<>();
|
||||
searchAdapter = new NewsSearchAdapter();
|
||||
|
||||
@ -103,7 +92,7 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
|
||||
gamedetail_news_rv.setLayoutManager(layoutManager);
|
||||
gamedetail_news_rv.setAdapter(searchAdapter);
|
||||
gamedetail_news_rv.addItemDecoration(new VerticalItemDecoration(NewsSearchActivity.this, 1));
|
||||
gamedetail_news_rv.addItemDecoration(new VerticalItemDecoration(NewsSearchActivity.this, 1, false));
|
||||
|
||||
et_search.setText(searchKey);
|
||||
|
||||
@ -123,7 +112,6 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
searchAdapter.notifyDataSetChanged();
|
||||
gamedetail_news_ll_loading.setVisibility(View.VISIBLE);
|
||||
reuse_none_data.setVisibility(View.GONE);
|
||||
gamedetail_news_cardView.setVisibility(View.GONE);
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
handler.postDelayed(new Runnable() {
|
||||
@ -159,7 +147,6 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
public void onClick(View v) {
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
gamedetail_news_ll_loading.setVisibility(View.VISIBLE);
|
||||
gamedetail_news_cardView.setVisibility(View.GONE);
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -172,8 +159,8 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void loadNewsData(final int page) {
|
||||
DataUtils.onEvent(this, "游戏新闻搜索", searchKey);
|
||||
DataCollectionUtils.uploadSearch(this, searchKey, "游戏新闻搜索");
|
||||
// DataUtils.onEvent(this, "游戏新闻搜索", searchKey);
|
||||
// DataCollectionUtils.uploadSearch(this, searchKey, "游戏新闻搜索");
|
||||
|
||||
RetrofitManager.getApi().getSearchNews(gameId, searchKey, page, 20)
|
||||
.map(new Func1<List<NewsEntity>, List<NewsEntity>>() {
|
||||
@ -190,7 +177,6 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
public void onResponse(List<NewsEntity> response) {
|
||||
isLoadOver = true;
|
||||
gamedetail_news_ll_loading.setVisibility(View.GONE);
|
||||
gamedetail_news_cardView.setVisibility(View.VISIBLE);
|
||||
reuse_none_data.setVisibility(View.GONE);
|
||||
|
||||
if (response.size() != 0) {
|
||||
@ -198,13 +184,16 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
searchAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
if (page == 1) {
|
||||
gamedetail_news_cardView.setVisibility(View.GONE);
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
isRemove = true;
|
||||
searchAdapter.notifyItemChanged(searchAdapter.getItemCount() - 1);
|
||||
}
|
||||
|
||||
if (response.size() < 20) {
|
||||
isRemove = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -238,31 +227,20 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
} else {
|
||||
LinearLayout linearLayout = new LinearLayout(parent.getContext());
|
||||
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
linearLayout.setBackgroundResource(R.drawable.cardview_item_style);
|
||||
|
||||
TextView textView = new TextView(parent.getContext());
|
||||
textView.setPadding(DisplayUtils.dip2px(NewsSearchActivity.this,10),DisplayUtils.dip2px(NewsSearchActivity.this,10)
|
||||
,0, DisplayUtils.dip2px(NewsSearchActivity.this,10));
|
||||
textView.setTextColor(Color.parseColor("#3a3a3a"));
|
||||
textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
textView.setSingleLine();
|
||||
textView.setTextSize(15);
|
||||
|
||||
linearLayout.addView(textView);
|
||||
|
||||
return new ViewHolder(linearLayout);
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.news_text_item, parent, false);
|
||||
return new NewsTextViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof ViewHolder){
|
||||
ViewHolder viewHolder = (ViewHolder) holder;
|
||||
viewHolder.tvTitle.setText(newsEntities.get(position).getTitle());
|
||||
viewHolder.linearLayout.setOnClickListener(new View.OnClickListener() {
|
||||
if (holder instanceof NewsTextViewHolder){
|
||||
NewsTextViewHolder viewHolder = (NewsTextViewHolder) holder;
|
||||
viewHolder.title.setText(Html.fromHtml(newsEntities.get(position).getTitle()));
|
||||
viewHolder.type.setVisibility(View.GONE);
|
||||
viewHolder.line.setVisibility(View.GONE);
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
NewsEntity newsEntity = newsEntities.get(holder.getPosition());
|
||||
@ -316,14 +294,5 @@ public class NewsSearchActivity extends BaseActivity {
|
||||
return newsEntities.size() + 1;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder{
|
||||
LinearLayout linearLayout;
|
||||
TextView tvTitle;
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
linearLayout = (LinearLayout) itemView;
|
||||
tvTitle = (TextView) linearLayout.getChildAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
412
app/src/main/java/com/gh/gamecenter/ReceiverWaitingActivity.java
Normal file
412
app/src/main/java/com/gh/gamecenter/ReceiverWaitingActivity.java
Normal file
@ -0,0 +1,412 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.RadarLayout;
|
||||
import com.gh.gamecenter.kuaichuan.BaseTransfer;
|
||||
import com.gh.gamecenter.kuaichuan.Constant;
|
||||
import com.gh.gamecenter.kuaichuan.FileInfo;
|
||||
import com.gh.gamecenter.kuaichuan.HotspotManager;
|
||||
import com.gh.gamecenter.kuaichuan.IpPortInfo;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
import com.gh.gamecenter.receiver.WifiAPBroadcastReceiver;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/20.
|
||||
*/
|
||||
public class ReceiverWaitingActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.waiting_user_icon) SimpleDraweeView mUserIcon;
|
||||
@BindView(R.id.waiting_user_name) TextView mUserName;
|
||||
@BindView(R.id.waiting_user_status) TextView mUserStatus;
|
||||
@BindView(R.id.waiting_conn) TextView mWaitingConn;
|
||||
@BindView(R.id.waiting_radar_layout) RadarLayout mRadarLayout;
|
||||
@BindView(R.id.waiting_hint) TextView mWaitingHint;
|
||||
@BindView(R.id.reuse_actionbar) RelativeLayout mActionbar;
|
||||
@BindView(R.id.waiting_gprs_hint) TextView mGPRSHint;
|
||||
@BindView(R.id.waiting_no_conn_hint) TextView mNoConnHint;
|
||||
@BindView(R.id.actionbar_iv_back) ImageView mBackIv;
|
||||
@BindView(R.id.actionbar_tv_title) TextView mTitleTv;
|
||||
|
||||
|
||||
private WifiAPBroadcastReceiver mWifiAPBroadcastReceiver;
|
||||
|
||||
private List<FileInfo> mFileInfos; // 接收到的文件列表
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private boolean mIsInitialized;
|
||||
private boolean isOpenWifi; //记录开热点前的WiFi状态
|
||||
private boolean isDestroy;
|
||||
|
||||
private String mySsid;
|
||||
|
||||
/**
|
||||
* 与 文件发送方 通信的 线程
|
||||
*/
|
||||
Runnable mUdpServerRuannable;
|
||||
|
||||
Handler mHandler = new Handler(){
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if(msg.what == 0){
|
||||
if (mFileInfos.size() == 0) {
|
||||
Utils.toast(ReceiverWaitingActivity.this, "接收异常::ReceiverWaitingActivity");
|
||||
return;
|
||||
}
|
||||
ArrayList list = new ArrayList();
|
||||
list.add(mFileInfos);
|
||||
IpPortInfo ipPortInfo = (IpPortInfo) msg.obj;
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(Constant.KEY_IP_PORT_INFO, ipPortInfo);
|
||||
bundle.putSerializable(Constant.KEY_IP_FILE_INFO, (Serializable) mFileInfos);
|
||||
bundle.putParcelableArrayList(Constant.KEY_IP_FILE_INFO, list);
|
||||
bundle.putBoolean("isOpenWifi", isOpenWifi);
|
||||
|
||||
Intent intent = new Intent(ReceiverWaitingActivity.this, FileReceiverActivity.class);
|
||||
intent.putExtras(bundle);
|
||||
startActivity(intent);
|
||||
|
||||
colsePage();
|
||||
} else if (msg.what == 1) {
|
||||
mNoConnHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_receiver_waiting, null);
|
||||
init(contentView, "接收游戏");
|
||||
|
||||
mTitleTv.setTextColor(Color.WHITE);
|
||||
mBackIv.setImageResource(R.drawable.reuse_kc_back);
|
||||
|
||||
// 添加分享图标
|
||||
TextView hintTv = new TextView(this);
|
||||
hintTv.setText("操作说明");
|
||||
hintTv.setTextColor(Color.WHITE);
|
||||
hintTv.setGravity(Gravity.CENTER);
|
||||
hintTv.setPadding(DisplayUtils.dip2px(this, 13),0 ,DisplayUtils.dip2px(this, 13),0);
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT );
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) contentView.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(hintTv, params);
|
||||
|
||||
//修改沉浸栏以及ActionBar 颜色
|
||||
mActionbar.setBackgroundColor(getResources().getColor(R.color.scan_bg));
|
||||
SystemBarTintManager tintManager = getTintManager();
|
||||
if (tintManager != null) {
|
||||
tintManager.setStatusBarTintResource(R.color.scan_bg);
|
||||
}
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
mIsInitialized = false;
|
||||
isDestroy = false;
|
||||
isOpenWifi = WifiMgr.getInstance(this).isWifiEnable();
|
||||
|
||||
mUserName.setText(sp.getString("user_name", "光环用户"));
|
||||
|
||||
if (isOpenWifi) {
|
||||
WifiMgr.getInstance(this).closeWifi();
|
||||
}
|
||||
|
||||
mUserStatus.setText("正在初始化...");
|
||||
mRadarLayout.setUseRing(true);
|
||||
mRadarLayout.setColor(Color.WHITE);
|
||||
mRadarLayout.setCount(4);
|
||||
mRadarLayout.start();
|
||||
|
||||
|
||||
mFileInfos = new ArrayList<>();
|
||||
|
||||
HotspotManager.initApData(this); // 记录原始热点信息
|
||||
|
||||
//初始化热点
|
||||
if(HotspotManager.isApOn(this)){
|
||||
HotspotManager.disableAp(this);
|
||||
}
|
||||
|
||||
mWifiAPBroadcastReceiver = new WifiAPBroadcastReceiver() {
|
||||
@Override
|
||||
public void onWifiApEnabled() {
|
||||
if(!mIsInitialized) {
|
||||
mUdpServerRuannable = createSendMsgToFileSenderRunnable();
|
||||
AppController.MAIN_EXECUTOR.execute(mUdpServerRuannable);
|
||||
mIsInitialized = true;
|
||||
|
||||
mWaitingConn.setVisibility(View.VISIBLE);
|
||||
mUserStatus.setText(Html.fromHtml("成功创建热点:" + "<font color=\"#fff500\">" + mySsid + "</font>"));
|
||||
mWaitingHint.setVisibility(View.GONE);
|
||||
mUserName.setVisibility(View.GONE);
|
||||
mGPRSHint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
IntentFilter filter = new IntentFilter(WifiAPBroadcastReceiver.ACTION_WIFI_AP_STATE_CHANGED);
|
||||
registerReceiver(mWifiAPBroadcastReceiver, filter);
|
||||
|
||||
HotspotManager.isApOn(this);
|
||||
|
||||
mySsid = sp.getString("hotspotName", null);
|
||||
if (TextUtils.isEmpty(mySsid)) {
|
||||
String chars = "abcdefghijklmnopqrstuvwxyz";
|
||||
int[] randomArray = RandomUtils.getRandomArray(2, 25);
|
||||
|
||||
mySsid = "ghZS-";
|
||||
for (int i : randomArray) {
|
||||
mySsid = mySsid + chars.charAt(i);
|
||||
}
|
||||
|
||||
int default_user_icon = sp.getInt("default_user_icon", 0);
|
||||
if (default_user_icon == 0) {
|
||||
default_user_icon = RandomUtils.nextInt(8) + 1;
|
||||
sp.edit().putInt("default_user_icon", default_user_icon).apply();
|
||||
}
|
||||
|
||||
mySsid = mySsid + default_user_icon;
|
||||
sp.edit().putString("hotspotName", mySsid).apply();
|
||||
}
|
||||
mUserIcon.setImageURI(UserIconUtils.getUserIcon(sp.getInt("default_user_icon", 1)));
|
||||
|
||||
HotspotManager.configApState(this, mySsid); // change Ap state :boolean
|
||||
|
||||
findViewById(R.id.actionbar_rl_back).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
colsePage();
|
||||
//关闭热点
|
||||
HotspotManager.initUserAp(ReceiverWaitingActivity.this);
|
||||
|
||||
if (isOpenWifi) {
|
||||
WifiMgr.getInstance(ReceiverWaitingActivity.this).openWifi();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mHandler.sendEmptyMessageDelayed(1, 300000);
|
||||
|
||||
hintTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showConnHintDialog();
|
||||
}
|
||||
});
|
||||
|
||||
boolean showConnHintReceiver = sp.getBoolean("showConnHintReceiver", true);
|
||||
|
||||
if (showConnHintReceiver) {
|
||||
showConnHintDialog();
|
||||
sp.edit().putBoolean("showConnHintReceiver", false).apply();
|
||||
}
|
||||
}
|
||||
|
||||
private void showConnHintDialog() {
|
||||
DialogUtils.showHintDialog(ReceiverWaitingActivity.this, "请告诉你的好友这样操作:", "1.请好友拿出手机,打开光环助手 " +
|
||||
"\n2.点击首页左上角“↓”按钮 \n3.点击“我要发送”", "确定");
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建发送UDP消息到 文件发送方 的服务线程
|
||||
*/
|
||||
private Runnable createSendMsgToFileSenderRunnable(){
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
startFileReceiverServer(Constant.DEFAULT_SERVER_COM_PORT);
|
||||
} catch (Exception e) {
|
||||
Utils.log("发送UDP消息到 文件发送方 异常" + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启 文件接收方 通信服务 (必须在子线程执行)
|
||||
* @param serverPort
|
||||
* @throws Exception
|
||||
*/
|
||||
DatagramSocket mDatagramSocket;
|
||||
private void startFileReceiverServer(int serverPort) throws Exception{
|
||||
//网络连接上,无法获取IP的问题
|
||||
int count = 0;
|
||||
String localAddress = WifiMgr.getInstance(ReceiverWaitingActivity.this).getHotspotLocalIpAddress();
|
||||
Utils.log("开启 文件接收方 通信服务 " + localAddress);
|
||||
|
||||
//ip地址无效 重新获取
|
||||
while(localAddress.equals(Constant.DEFAULT_UNKOWN_IP) && count < Constant.DEFAULT_TRY_TIME){
|
||||
Thread.sleep(1000);
|
||||
localAddress = WifiMgr.getInstance(ReceiverWaitingActivity.this).getHotspotLocalIpAddress();
|
||||
count ++;
|
||||
}
|
||||
|
||||
if (mDatagramSocket == null) {
|
||||
mDatagramSocket = new DatagramSocket(null);
|
||||
mDatagramSocket.setReuseAddress(true);
|
||||
mDatagramSocket.bind(new InetSocketAddress(serverPort));
|
||||
}
|
||||
|
||||
byte[] receiveData = new byte[1024];
|
||||
byte[] sendData;
|
||||
Utils.log("接收接受信息 ");
|
||||
while (!isDestroy) {
|
||||
//接收 文件发送方的消息
|
||||
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
|
||||
mDatagramSocket.receive(receivePacket);
|
||||
String msg = new String( receivePacket.getData(), 0, receivePacket.getLength()).trim();
|
||||
InetAddress inetAddress = receivePacket.getAddress();
|
||||
|
||||
int port = receivePacket.getPort();
|
||||
Utils.log("接收信息中。。。" + msg );
|
||||
if(msg != null && msg.contains(Constant.MSG_FILE_RECEIVER_INIT)) {
|
||||
Utils.log("接收方初始化完毕准备进去传输页面 并回馈消息给发送者" + inetAddress);
|
||||
|
||||
// AppController.put("FileInfo", mFileInfos); //保存数据列表 启用改为Intent传输
|
||||
|
||||
// 反馈 文件发送方的消息
|
||||
// sendData = Constant.MSG_FILE_RECEIVER_INIT_SUCCESS.getBytes(BaseTransfer.UTF_8);
|
||||
JSONObject receiverData = new JSONObject();
|
||||
receiverData.put(Constant.MSG_FILE_RECEIVER_INIT_SUCCESS, sp.getString("user_name", "光环用户"));
|
||||
sendData = receiverData.toString().getBytes(BaseTransfer.UTF_8);
|
||||
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, inetAddress, port);
|
||||
mDatagramSocket.send(sendPacket);
|
||||
|
||||
Message message = new Message();
|
||||
message.what = 0;
|
||||
JSONObject jsonObject = new JSONObject(msg);
|
||||
message.obj = new IpPortInfo(inetAddress, port, jsonObject.getString(Constant.MSG_FILE_RECEIVER_INIT),
|
||||
sp.getString("user_name", "光环用户"),jsonObject.getInt("UserIcon"));
|
||||
mHandler.sendMessage(message);
|
||||
|
||||
} else {
|
||||
if(msg != null){
|
||||
Utils.log("保存文件列表数据" + msg);
|
||||
parseFileInfo(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析FileInfo
|
||||
* @param msg
|
||||
*/
|
||||
private void parseFileInfo(String msg) {
|
||||
FileInfo fileInfo = FileInfo.toObject(msg);
|
||||
if(fileInfo != null && fileInfo.getFilePath() != null){
|
||||
mFileInfos.add(fileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭UDP Socket 流
|
||||
*/
|
||||
private void closeSocket(){
|
||||
if(mDatagramSocket != null){
|
||||
// mDatagramSocket.disconnect();
|
||||
mDatagramSocket.close();
|
||||
mDatagramSocket = null;
|
||||
}
|
||||
}
|
||||
|
||||
// @OnClick(R.id.actionbar_rl_back)
|
||||
// public void onBackListener() {
|
||||
// Utils.log("=========back");
|
||||
// colsePage();
|
||||
// //关闭热点
|
||||
// HotspotManager.disableAp(this);
|
||||
//
|
||||
// if (isOpenWifi) {
|
||||
// WifiMgr.getInstance(this).openWifi();
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
colsePage();
|
||||
|
||||
//关闭热点
|
||||
HotspotManager.initUserAp(ReceiverWaitingActivity.this);
|
||||
|
||||
if (isOpenWifi) {
|
||||
WifiMgr.getInstance(this).openWifi();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭广播并关闭Socket流
|
||||
*/
|
||||
private void colsePage() {
|
||||
mRadarLayout.stop();
|
||||
|
||||
mHandler.removeMessages(1); // 取消无人连接消息
|
||||
|
||||
try {
|
||||
if(mWifiAPBroadcastReceiver != null){
|
||||
unregisterReceiver(mWifiAPBroadcastReceiver);
|
||||
mWifiAPBroadcastReceiver = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Utils.log("接收方d等待连接异常-关闭广播");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
closeSocket();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -44,6 +44,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
private SearchHistoryDao dao;
|
||||
|
||||
private String searchKey;
|
||||
private String searchType;
|
||||
|
||||
private int currentTab;
|
||||
|
||||
@ -53,7 +54,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what == 1){
|
||||
setResultPresentModel(1);
|
||||
search("auto", searchKey);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -63,6 +64,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentTab", currentTab);
|
||||
outState.putString("searchKey", searchKey);
|
||||
outState.putString("searchType", searchType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,7 +77,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
setTranslucentStatus(true);
|
||||
SystemBarTintManager tintManager = new SystemBarTintManager(this);
|
||||
tintManager.setStatusBarTintEnabled(true);
|
||||
tintManager.setStatusBarTintResource(R.color.theme);
|
||||
tintManager.setStatusBarTintResource(R.color.back);
|
||||
SystemBarConfig config = tintManager.getConfig();
|
||||
contentView.setPadding(0, config.getPixelInsetTop(false), 0,
|
||||
config.getPixelInsetBottom());
|
||||
@ -87,30 +89,32 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
boolean isFromHome = getIntent().getBooleanExtra("clicked", false);
|
||||
String hint = getIntent().getStringExtra("hint");
|
||||
|
||||
setActionBarLayout(hint, isFromHome);
|
||||
setActionBarLayout();
|
||||
|
||||
currentTab = 0;
|
||||
if (savedInstanceState != null) {
|
||||
currentTab = savedInstanceState.getInt("currentTab", 0);
|
||||
searchKey = savedInstanceState.getString("searchKey", null);
|
||||
if (TextUtils.isEmpty(searchKey)) {
|
||||
currentTab = 0;
|
||||
} else {
|
||||
isSearchDetail = true;
|
||||
searchInput.setText(searchKey);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
searchType = savedInstanceState.getString("searchType", null);
|
||||
if (currentTab != 0 && !TextUtils.isEmpty(searchKey)) {
|
||||
search(searchType, searchKey);
|
||||
}
|
||||
} else if (!TextUtils.isEmpty(hint)) {
|
||||
searchInput.setHint(hint);
|
||||
if (isFromHome) {
|
||||
currentTab = 2;
|
||||
search("default", hint);
|
||||
}
|
||||
} else {
|
||||
currentTab = 0;
|
||||
if (isFromHome && !TextUtils.isEmpty(hint)) {
|
||||
searchKey = hint;
|
||||
currentTab = 2;
|
||||
}
|
||||
searchInput.setHint("搜索游戏...");
|
||||
}
|
||||
|
||||
setResultPresentModel(currentTab);
|
||||
if (currentTab == 0) {
|
||||
setResultPresentModel(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setActionBarLayout(final String hint, final boolean isFromHome) {
|
||||
public void setActionBarLayout() {
|
||||
int actionbar_height = getSharedPreferences(Config.PREFERENCE,
|
||||
Context.MODE_PRIVATE).getInt("actionbar_height",
|
||||
DisplayUtils.dip2px(getApplicationContext(), 48));
|
||||
@ -127,24 +131,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
String newSearchKey = searchInput.getText().toString().trim();
|
||||
if (newSearchKey.length() < 1) {
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
newSearchKey = searchInput.getHint().toString();
|
||||
isSearchDetail = true;
|
||||
searchInput.setText(hint);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
}
|
||||
}
|
||||
if (!newSearchKey.equals(searchKey) || currentTab != 2) {
|
||||
searchKey = newSearchKey;
|
||||
if (!TextUtils.isEmpty(searchKey)) {
|
||||
setResultPresentModel(2);
|
||||
dao.add(searchKey);
|
||||
} else {
|
||||
toast("请输入搜索内容");
|
||||
}
|
||||
}
|
||||
search("initiative", null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -152,40 +139,12 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
searchButton = (TextView) findViewById(R.id.btnSearch);
|
||||
searchCancel = (ImageView) findViewById(R.id.ivDeleteText);
|
||||
|
||||
if (isFromHome && !TextUtils.isEmpty(hint)) {
|
||||
isSearchDetail = true;
|
||||
searchInput.setText(hint);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
} else if (!TextUtils.isEmpty(hint)) {
|
||||
searchInput.setHint(hint);
|
||||
} else {
|
||||
searchInput.setHint("搜索游戏...");
|
||||
}
|
||||
|
||||
searchButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
String newSearchKey = searchInput.getText().toString().trim();
|
||||
if (newSearchKey.length() < 1) {
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
newSearchKey = searchInput.getHint().toString();
|
||||
isSearchDetail = true;
|
||||
searchInput.setText(hint);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
}
|
||||
}
|
||||
if (!newSearchKey.equals(searchKey) || currentTab != 2) {
|
||||
searchKey = newSearchKey;
|
||||
if (!TextUtils.isEmpty(searchKey)) {
|
||||
setResultPresentModel(2);
|
||||
dao.add(searchKey);
|
||||
isSearchDetail = false;
|
||||
} else {
|
||||
toast("请输入搜索内容");
|
||||
}
|
||||
}
|
||||
search("initiative", null);
|
||||
}
|
||||
});
|
||||
|
||||
@ -195,7 +154,6 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
searchCancel.setVisibility(View.GONE);
|
||||
searchInput.setText("");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
searchInput.addTextChangedListener(new TextWatcher() {
|
||||
@ -234,7 +192,57 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void search(String type, String key) {
|
||||
searchType = type;
|
||||
if ("auto".equals(type)) {
|
||||
//自动搜索
|
||||
searchKey = key;
|
||||
setResultPresentModel(1);
|
||||
} else if ("default".equals(type)) {
|
||||
//默认搜索
|
||||
isSearchDetail = true;
|
||||
searchKey = key;
|
||||
searchInput.setText(key);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
setResultPresentModel(2);
|
||||
isSearchDetail = false;
|
||||
} else if ("remen".equals(type)) {
|
||||
//热门搜索
|
||||
isSearchDetail = true;
|
||||
searchKey = key;
|
||||
searchInput.setText(key);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
setResultPresentModel(2);
|
||||
isSearchDetail = false;
|
||||
} else if ("history".equals(type)) {
|
||||
//历史搜索
|
||||
isSearchDetail = true;
|
||||
searchKey = key;
|
||||
searchInput.setText(key);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
setResultPresentModel(2);
|
||||
isSearchDetail = false;
|
||||
} else if ("initiative".equals(type)) {
|
||||
//主动搜索
|
||||
String newSearchKey = searchInput.getText().toString().trim();
|
||||
if (newSearchKey.length() < 1) {
|
||||
String hint = searchInput.getHint().toString();
|
||||
if (!TextUtils.isEmpty(hint) && !"搜索游戏...".equals(hint)) {
|
||||
dao.add(hint);
|
||||
search("default", hint);
|
||||
}
|
||||
} else if (!newSearchKey.equals(searchKey) || currentTab != 2) {
|
||||
searchKey = newSearchKey;
|
||||
if (!TextUtils.isEmpty(searchKey)) {
|
||||
dao.add(searchKey);
|
||||
setResultPresentModel(2);
|
||||
} else {
|
||||
toast("请输入搜索内容");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setResultPresentModel(int model) {
|
||||
@ -247,16 +255,13 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
break;
|
||||
case 1:
|
||||
SearchGameListFragment game_list_fragment = new SearchGameListFragment();
|
||||
game_list_fragment.setKey(searchKey);
|
||||
game_list_fragment.setParams(searchKey, searchType);
|
||||
transaction.replace(R.id.search_result, game_list_fragment);
|
||||
currentTab = 1;
|
||||
break;
|
||||
case 2:
|
||||
DataUtils.onEvent(SearchActivity.this, "搜索页面", searchKey);
|
||||
DataCollectionUtils.uploadSearch(this, searchKey, "搜索页面");
|
||||
|
||||
SearchGameDetailFragment game_detail_fragment = new SearchGameDetailFragment();
|
||||
game_detail_fragment.setKey(searchKey);
|
||||
game_detail_fragment.setParams(searchKey, searchType);
|
||||
transaction.replace(R.id.search_result, game_detail_fragment);
|
||||
currentTab = 2;
|
||||
break;
|
||||
@ -267,22 +272,17 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
}
|
||||
|
||||
public void onEvent(EBSearch search) {
|
||||
isSearchDetail = true;
|
||||
String str = search.getKey();
|
||||
searchInput.setText(str);
|
||||
searchInput.setFocusable(true);
|
||||
searchInput.requestFocus();
|
||||
searchInput.setSelection(str.length());
|
||||
if (search.isSearch()) {
|
||||
searchButton.performClick();
|
||||
if ("history".equals(search.getType())) {
|
||||
search("history", search.getKey());
|
||||
} else if ("remen".equals(search.getType())) {
|
||||
search("remen", search.getKey());
|
||||
} else if ("click".equals(search.getType())) {
|
||||
DataCollectionUtils.uploadSearchClick(this, searchKey, searchType, "搜索页面",
|
||||
search.getGameId(), search.getGameName());
|
||||
} else if ("search".equals(search.getType())) {
|
||||
DataCollectionUtils.uploadSearch(this, searchKey, searchType, "搜索页面",
|
||||
search.getGameId(), search.getGameName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
DataUtils.onEvent(this, "搜索页面", searchKey);
|
||||
DataCollectionUtils.uploadSearch(this, searchKey, "搜索页面");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
165
app/src/main/java/com/gh/gamecenter/SelectUserIconActivity.java
Normal file
165
app/src/main/java/com/gh/gamecenter/SelectUserIconActivity.java
Normal file
@ -0,0 +1,165 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/10.
|
||||
*/
|
||||
public class SelectUserIconActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.skip_media_store) TextView mSkipMediaStore;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_select_user_icon, null);
|
||||
init(contentView, "选择头像");
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (data != null && requestCode == 0x123) {
|
||||
Uri selectedImage = data.getData();
|
||||
if (selectedImage == null) {
|
||||
return;
|
||||
}
|
||||
String[] filePathColumn = { MediaStore.Images.Media.DATA };
|
||||
|
||||
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
||||
if (cursor == null) {
|
||||
return;
|
||||
}
|
||||
cursor.moveToFirst();
|
||||
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String picturePath = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
|
||||
Utils.log("picturePath = " + picturePath);
|
||||
// 上传头像
|
||||
Intent intent = new Intent(this, CropImageActivity.class);
|
||||
intent.putExtra("path", picturePath);
|
||||
intent.putExtra("entrance", "(我的光环)");
|
||||
startActivityForResult(intent, 0x124);
|
||||
} else if (data != null && requestCode == 0x124) {
|
||||
String url = data.getExtras().getString("url");
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("url", url);
|
||||
setResult(0x125, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick({R.id.user_default_icon_1, R.id.user_default_icon_2, R.id.user_default_icon_3 ,R.id.user_default_icon_4,
|
||||
R.id.user_default_icon_5, R.id.user_default_icon_6, R.id.user_default_icon_7, R.id.user_default_icon_8, R.id.skip_media_store})
|
||||
public void onClick(View view){
|
||||
switch (view.getId()) {
|
||||
case R.id.user_default_icon_1:
|
||||
postUserIocn(1);
|
||||
break;
|
||||
case R.id.user_default_icon_2:
|
||||
postUserIocn(2);
|
||||
break;
|
||||
case R.id.user_default_icon_3:
|
||||
postUserIocn(3);
|
||||
break;
|
||||
case R.id.user_default_icon_4:
|
||||
postUserIocn(4);
|
||||
break;
|
||||
case R.id.user_default_icon_5:
|
||||
postUserIocn(5);
|
||||
break;
|
||||
case R.id.user_default_icon_6:
|
||||
postUserIocn(6);
|
||||
break;
|
||||
case R.id.user_default_icon_7:
|
||||
postUserIocn(7);
|
||||
break;
|
||||
case R.id.user_default_icon_8:
|
||||
postUserIocn(8);
|
||||
break;
|
||||
case R.id.skip_media_store:
|
||||
|
||||
String iconCount = sp.getString("updateIconCount", null);
|
||||
if (!TextUtils.isEmpty(iconCount)) {
|
||||
long l = System.currentTimeMillis();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
||||
String time = format.format(new Date(l));
|
||||
|
||||
JSONObject json = null;
|
||||
try {
|
||||
json = new JSONObject(iconCount);
|
||||
String lastTime = json.getString("time");
|
||||
if (lastTime.equals(time) && json.getInt("count") == 2) {
|
||||
Utils.toast(SelectUserIconActivity.this, "每天最多只能上传2次头像");
|
||||
return;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(intent, 0x123);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void postUserIocn(int i) {
|
||||
postDefaultIcon(i);
|
||||
}
|
||||
|
||||
public void postDefaultIcon(final int i) {
|
||||
String iconUrl = UserIconUtils.getUserIconUrl(i);
|
||||
|
||||
//初始化热点名称
|
||||
String chars = "abcdefghijklmnopqrstuvwxyz";
|
||||
int[] randomArray = RandomUtils.getRandomArray(2, 25);
|
||||
|
||||
String mySsid = "ghZS-";
|
||||
for (int j : randomArray) {
|
||||
mySsid = mySsid + chars.charAt(j);
|
||||
}
|
||||
mySsid = mySsid + i;
|
||||
sp.edit().putString("hotspotName", mySsid).apply();
|
||||
|
||||
sp.edit().putInt("default_user_icon", i).apply();
|
||||
|
||||
sp.edit().putBoolean("changeDefaultIcon", true).apply();
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("url", iconUrl);
|
||||
setResult(0x125, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
@ -8,7 +8,6 @@ import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
@ -21,10 +20,8 @@ import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.manager.UpdateManager;
|
||||
import com.kyleduo.switchbutton.SwitchButton;
|
||||
|
||||
import java.io.File;
|
||||
@ -43,9 +40,7 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
@BindView(R.id.setting_sb_autoinstall) SwitchButton setting_sb_autoinstall;
|
||||
@BindView(R.id.setting_sb_autodelete) SwitchButton setting_sb_autodelete;
|
||||
@BindView(R.id.setting_sb_deletedata) SwitchButton setting_sb_deletedata;
|
||||
@BindView(R.id.setting_sb_autoupdate) SwitchButton setting_sb_autoupdate;
|
||||
@BindView(R.id.setting_sb_concerngame) SwitchButton setting_sb_concerngame;
|
||||
@BindView(R.id.setting_tv_version) TextView setting_tv_version;
|
||||
@BindView(R.id.setting_tv_cache) TextView setting_tv_cache;
|
||||
@BindView(R.id.setting_tv_size) TextView setting_tv_size;
|
||||
|
||||
@ -76,14 +71,11 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
findViewById(R.id.setting_rl_autoinstall).setOnClickListener(this);
|
||||
findViewById(R.id.setting_rl_autodelete).setOnClickListener(this);
|
||||
findViewById(R.id.setting_rl_deletedata).setOnClickListener(this);
|
||||
findViewById(R.id.setting_rl_autoupdate).setOnClickListener(this);
|
||||
findViewById(R.id.setting_rl_update).setOnClickListener(this);
|
||||
findViewById(R.id.setting_rl_feedback).setOnClickListener(this);
|
||||
// findViewById(R.id.setting_rl_feedback).setOnClickListener(this);
|
||||
findViewById(R.id.setting_rl_cache).setOnClickListener(this);
|
||||
findViewById(R.id.setting_cv_font_size).setOnClickListener(this);
|
||||
findViewById(R.id.setting_rl_concerngame).setOnClickListener(this);
|
||||
|
||||
setting_tv_version.setText(String.format("当前版本:V%s", PackageUtils.getVersionName(getApplicationContext())));
|
||||
findViewById(R.id.setting_rl_about).setOnClickListener(this);
|
||||
|
||||
setting_tv_cache.setText(getCacheSize());
|
||||
|
||||
@ -98,16 +90,8 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
setting_sb_autoinstall.setChecked(sp.getBoolean("autoinstall", true));
|
||||
setting_sb_autodelete.setChecked(sp.getBoolean("autodelete", true));
|
||||
setting_sb_deletedata.setChecked(sp.getBoolean("deletedata", true));
|
||||
setting_sb_autoupdate.setChecked(sp.getBoolean("autoupdate", true));
|
||||
setting_sb_concerngame.setChecked(sp.getBoolean("concerngame", true));
|
||||
|
||||
if (sp.getBoolean("isShowDisclaimer", false)) {
|
||||
TextView setting_tv_disclaimer = (TextView) findViewById(R.id.setting_tv_disclaimer);
|
||||
findViewById(R.id.setting_disclaimer_line).setVisibility(View.VISIBLE);
|
||||
setting_tv_disclaimer.setVisibility(View.VISIBLE);
|
||||
setting_tv_disclaimer.setOnClickListener(this);
|
||||
}
|
||||
|
||||
checkSizeIndex = sp.getInt("fontsize", 1);
|
||||
if (checkSizeIndex == 0){
|
||||
checkSizeIndex = 1;
|
||||
@ -155,7 +139,6 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
mEditor.putBoolean("autoinstall", setting_sb_autoinstall.isChecked());
|
||||
mEditor.putBoolean("autodelete", setting_sb_autodelete.isChecked());
|
||||
mEditor.putBoolean("deletedata", setting_sb_deletedata.isChecked());
|
||||
mEditor.putBoolean("autoupdate", setting_sb_autoupdate.isChecked());
|
||||
mEditor.putBoolean("concerngame", setting_sb_concerngame.isChecked());
|
||||
mEditor.putInt("fontsize",checkSizeIndex);
|
||||
mEditor.apply();
|
||||
@ -196,12 +179,6 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
case R.id.setting_rl_deletedata:
|
||||
setting_sb_deletedata.performClick();
|
||||
break;
|
||||
case R.id.setting_rl_autoupdate:
|
||||
setting_sb_autoupdate.performClick();
|
||||
break;
|
||||
case R.id.setting_rl_update:
|
||||
UpdateManager.getInstance(this).checkUpdate(false);
|
||||
break;
|
||||
case R.id.setting_rl_cache:
|
||||
DialogUtils.showWarningDialog(this, "清除缓存", "清空缓存后未安装的游戏可能需要重新下载,确定清空?",
|
||||
new DialogUtils.ConfiremListener() {
|
||||
@ -212,20 +189,18 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.id.setting_rl_feedback:
|
||||
Intent intent = new Intent(SettingActivity.this, SuggestionActivity.class);
|
||||
intent.putExtra("entrance", "(设置)");
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.setting_tv_disclaimer:
|
||||
String content = sp.getString("disclaimer", null);
|
||||
if (!TextUtils.isEmpty(content)) {
|
||||
DialogUtils.showDisclaimerDialog(this, content);
|
||||
}
|
||||
break;
|
||||
// case R.id.setting_rl_feedback:
|
||||
// Intent intent = new Intent(SettingActivity.this, SuggestionActivity.class);
|
||||
// intent.putExtra("entrance", "(设置)");
|
||||
// startActivity(intent);
|
||||
// break;
|
||||
case R.id.setting_cv_font_size:
|
||||
fontSize();
|
||||
break;
|
||||
case R.id.setting_rl_about:
|
||||
Intent intentAbout = new Intent(this, AboutActivity.class);
|
||||
startActivity(intentAbout);
|
||||
break;
|
||||
case R.id.setting_rl_concerngame:
|
||||
setting_sb_concerngame.performClick();
|
||||
default:
|
||||
|
||||
@ -15,6 +15,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.MessageShareUtils;
|
||||
import com.gh.common.util.QRCodeUtils;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
@ -80,7 +81,8 @@ public class ShareCardActivity extends BaseActivity {
|
||||
|
||||
mShareGameNameTv.setText(gameName);
|
||||
mShareContentTv.setText(Html.fromHtml(shareContent));
|
||||
mShareGameIconDv.setImageURI(gameIconUrl);
|
||||
// mShareGameIconDv.setImageURI(gameIconUrl);
|
||||
ImageUtils.display(mShareGameIconDv, gameIconUrl);
|
||||
mShareQrCodeDv.setImageResource(R.drawable.test_qrcode);
|
||||
|
||||
// 延迟操作,等待截图部分绘制完成
|
||||
@ -91,7 +93,7 @@ public class ShareCardActivity extends BaseActivity {
|
||||
mShareScreenshotLl.buildDrawingCache();
|
||||
Bitmap drawingCache = mShareScreenshotLl.getDrawingCache();
|
||||
saveBitmap(drawingCache);
|
||||
MessageShareUtils.getInstance(ShareCardActivity.this).showShareWindows(mShareBottomLl, drawingCache, picName, false);
|
||||
MessageShareUtils.getInstance(ShareCardActivity.this).showShareWindows(mShareBottomLl, drawingCache, picName, 0);
|
||||
}
|
||||
}, 200);
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.facebook.imagepipeline.image.ImageInfo;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.MessageShareUtils;
|
||||
import com.gh.common.util.QRCodeUtils;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
@ -128,7 +129,8 @@ public class ShareCardPicActivity extends BaseActivity {
|
||||
|
||||
mShareGameNameTv.setText(gameName);
|
||||
mShareContentTv.setText(Html.fromHtml(shareContent));
|
||||
mShareGameIconDv.setImageURI(gameIconUrl);
|
||||
// mShareGameIconDv.setImageURI(gameIconUrl);
|
||||
ImageUtils.display(mShareGameIconDv, gameIconUrl);
|
||||
mShareQrCodeDv.setImageResource(R.drawable.test_qrcode);
|
||||
|
||||
if (shareArrImg.size() > 1) {
|
||||
@ -223,7 +225,7 @@ public class ShareCardPicActivity extends BaseActivity {
|
||||
|
||||
shareBm = getBitmapByView(mShareScreenshotRl);
|
||||
saveBitmap(shareBm);
|
||||
MessageShareUtils.getInstance(ShareCardPicActivity.this).showShareWindows(new View(ShareCardPicActivity.this), shareBm, picName, true);
|
||||
MessageShareUtils.getInstance(ShareCardPicActivity.this).showShareWindows(new View(ShareCardPicActivity.this), shareBm, picName, 1);
|
||||
}
|
||||
|
||||
@OnClick(R.id.sharecard_chang_img)
|
||||
|
||||
82
app/src/main/java/com/gh/gamecenter/ShareGhActivity.java
Normal file
82
app/src/main/java/com/gh/gamecenter/ShareGhActivity.java
Normal file
@ -0,0 +1,82 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.QRCodeUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/6.
|
||||
*/
|
||||
public class ShareGhActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.gh_address_qrcode) ImageView mGhQrcode;
|
||||
@BindView(R.id.gh_address_tv) TextView mGhAddress;
|
||||
@BindView(R.id.wifi_share_btn) Button mWifiShareBtn;
|
||||
@BindView(R.id.content_ll) LinearLayout mContentLl;
|
||||
@BindView(R.id.share_rl) RelativeLayout mShareRl;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_share_gh, null);
|
||||
init(contentView, "分享光环");
|
||||
ButterKnife.bind(this);
|
||||
|
||||
mGhAddress.setText(Html.fromHtml("<u>"+"www.ghzhushou.com"+"</u>"));
|
||||
createQrCode();
|
||||
ShareUtils.getInstance(this).showShareWindows(mShareRl, "http://www.ghzhushou.com/link?source=appshare300", "光环助手"
|
||||
, "http://image.ghzhushou.com/pic/57d604808ab49e467d8b4568.png", null, false, false);
|
||||
}
|
||||
|
||||
@OnClick(R.id.wifi_share_btn)
|
||||
public void skipWifiShare() {
|
||||
Intent intent = new Intent(this, ShareGhWfifActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@OnClick(R.id.gh_address_tv)
|
||||
public void copyAddress() {
|
||||
ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setText("http://www.ghzhushou.com/link?source=appshare100");
|
||||
|
||||
Utils.toast(this, "网址复制成功,请到微信/QQ粘贴分享");
|
||||
}
|
||||
|
||||
|
||||
private void createQrCode() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String filePath = getExternalCacheDir().getPath() + "/ShareImg/ShareQRCode.jpg";
|
||||
boolean success = QRCodeUtils.createQRImage("http://www.ghzhushou.com/link?source=appshare100"
|
||||
, 200, 200, filePath, ShareGhActivity.this);
|
||||
if (success) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mGhQrcode.setImageBitmap(BitmapFactory.decodeFile(filePath));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
348
app/src/main/java/com/gh/gamecenter/ShareGhWfifActivity.java
Normal file
348
app/src/main/java/com/gh/gamecenter/ShareGhWfifActivity.java
Normal file
@ -0,0 +1,348 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.entity.KcWebRequestEntity;
|
||||
import com.gh.gamecenter.kuaichuan.Constant;
|
||||
import com.gh.gamecenter.kuaichuan.DownloadUriHandler;
|
||||
import com.gh.gamecenter.kuaichuan.HotspotManager;
|
||||
import com.gh.gamecenter.kuaichuan.HtmlUriHandler;
|
||||
import com.gh.gamecenter.kuaichuan.ImageUriHandler;
|
||||
import com.gh.gamecenter.kuaichuan.KcUriHandler;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.gh.gamecenter.receiver.WifiAPBroadcastReceiver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/6.
|
||||
*/
|
||||
public class ShareGhWfifActivity extends BaseActivity {
|
||||
|
||||
// @BindView(R.id.hotspot_name) TextView mHotSpotName;
|
||||
@BindView(R.id.init_hotpost_pb) ProgressBar mInitHotspostPb;
|
||||
@BindView(R.id.init_status_icon) ImageView mInitStatusIcon;
|
||||
@BindView(R.id.init_status_tv) TextView mInitStatusTv;
|
||||
@BindView(R.id.init_hotpost_hint) TextView mInitHotpostHint;
|
||||
@BindView(R.id.init_success_ll) LinearLayout mInitSuccessLl;
|
||||
@BindView(R.id.init_conn_hint) TextView initConnHint;
|
||||
|
||||
private ServerSocket mServerSocket;
|
||||
|
||||
private WifiAPBroadcastReceiver mWifiAPBroadcastReceiver;
|
||||
|
||||
private boolean mIsInitialized = false;
|
||||
|
||||
private List<KcUriHandler> mUriHandlers;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private boolean isColseActivity;
|
||||
|
||||
private boolean isOpenWifi; //记录开热点前的WiFi状态
|
||||
|
||||
private boolean initSuccess;
|
||||
|
||||
private String mySsid;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_share_gh_wifi, null);
|
||||
init(contentView, "免流量分享");
|
||||
ButterKnife.bind(this);
|
||||
|
||||
mUriHandlers = new ArrayList<>();
|
||||
mUriHandlers.add(new HtmlUriHandler(this));
|
||||
mUriHandlers.add(new ImageUriHandler(this));
|
||||
mUriHandlers.add(new DownloadUriHandler(this));
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
isColseActivity = false;
|
||||
initSuccess = false;
|
||||
|
||||
if (WifiMgr.getInstance(this).isWifiEnable()) {
|
||||
isOpenWifi = true;
|
||||
WifiMgr.getInstance(this).closeWifi();
|
||||
}
|
||||
|
||||
HotspotManager.initApData(this); // 记录原始热点信息
|
||||
|
||||
initHotSpotView(0);
|
||||
initHotSpot();
|
||||
}
|
||||
|
||||
private void initHotSpot() {
|
||||
|
||||
mWifiAPBroadcastReceiver = new WifiAPBroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onWifiApEnabled() {
|
||||
if(!mIsInitialized){
|
||||
Utils.log("===初始化热点成功");
|
||||
AppController.MAIN_EXECUTOR.execute(checkHotSpot());
|
||||
mIsInitialized = true;
|
||||
// mHotSpotName.setText(mySsid);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
IntentFilter filter = new IntentFilter(WifiAPBroadcastReceiver.ACTION_WIFI_AP_STATE_CHANGED);
|
||||
registerReceiver(mWifiAPBroadcastReceiver, filter);
|
||||
|
||||
HotspotManager.isApOn(this);
|
||||
|
||||
mySsid = sp.getString("hotspotName", null);
|
||||
if (TextUtils.isEmpty(mySsid)) {
|
||||
String chars = "abcdefghijklmnopqrstuvwxyz";
|
||||
int[] randomArray = RandomUtils.getRandomArray(2, 25);
|
||||
|
||||
mySsid = "ghZS-";
|
||||
for (int i : randomArray) {
|
||||
mySsid = mySsid + chars.charAt(i);
|
||||
}
|
||||
|
||||
int default_user_icon = sp.getInt("default_user_icon", 0);
|
||||
if (default_user_icon == 0) {
|
||||
default_user_icon = RandomUtils.nextInt(8) + 1;
|
||||
sp.edit().putInt("default_user_icon", default_user_icon).apply();
|
||||
}
|
||||
|
||||
mySsid = mySsid + default_user_icon;
|
||||
sp.edit().putString("hotspotName", mySsid).apply();
|
||||
}
|
||||
HotspotManager.configApState(this, mySsid); // change Ap state :boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化创建热点View
|
||||
* @param i i=0 初始化中, i=1 初始化成功, i=2 初始化失败
|
||||
*/
|
||||
|
||||
public void initHotSpotView(int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
mInitHotspostPb.setVisibility(View.VISIBLE);
|
||||
mInitStatusIcon.setVisibility(View.GONE);
|
||||
mInitStatusTv.setText("正在创建热点...");
|
||||
mInitStatusTv.setTextColor(getResources().getColor(R.color.title));
|
||||
mInitHotpostHint.setVisibility(View.VISIBLE);
|
||||
mInitHotpostHint.setText("如果出现获取权限的提示,请点击允许");
|
||||
break;
|
||||
case 1:
|
||||
mInitStatusIcon.setVisibility(View.VISIBLE);
|
||||
mInitStatusIcon.setImageResource(R.drawable.kc_checkbox_select);
|
||||
mInitStatusTv.setText(Html.fromHtml("热点创建成功:" + "<font color=\"#00B7FA\">" + mySsid + "</font>"));
|
||||
mInitHotpostHint.setVisibility(View.VISIBLE);
|
||||
mInitHotpostHint.setText("为了避免消耗流量,请关闭你手机的移动网络");
|
||||
mInitHotspostPb.setVisibility(View.GONE);
|
||||
|
||||
initConnHint.setText(Html.fromHtml("请好友打开Wi-Fi设置,连接我的热点:" + "<font color=\"#00B7FA\">" + mySsid + "</font>"));
|
||||
mInitSuccessLl.setVisibility(View.VISIBLE);
|
||||
initSuccess = true;
|
||||
break;
|
||||
case 2:
|
||||
mInitStatusIcon.setVisibility(View.VISIBLE);
|
||||
mInitStatusIcon.setImageResource(R.drawable.hotspot_failed_icon);
|
||||
mInitStatusTv.setText("初始化失败, 请退出重试");
|
||||
mInitStatusTv.setTextColor(Color.parseColor("#ff4147"));
|
||||
mInitHotpostHint.setVisibility(View.VISIBLE);
|
||||
mInitHotspostPb.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable checkHotSpot() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
// 确保热点开启之后获取得到IP地址
|
||||
String hotspotIpAddr = WifiMgr.getInstance(ShareGhWfifActivity.this).getHotspotLocalIpAddress();
|
||||
int count = 0;
|
||||
while(hotspotIpAddr.equals(Constant.DEFAULT_UNKOWN_IP) && count < Constant.DEFAULT_TRY_TIME){
|
||||
Thread.sleep(1000);
|
||||
hotspotIpAddr = WifiMgr.getInstance(ShareGhWfifActivity.this).getIpAddressFromHotspot();
|
||||
count ++;
|
||||
}
|
||||
|
||||
// 即使热点wifi的IP地址也是无法连接网络 所以采取此策略
|
||||
// count = 0;
|
||||
// while(!WifiUtils.pingIpAddress(hotspotIpAddr) && count < Constant.DEFAULT_TRY_TIME){
|
||||
// Thread.sleep(500);
|
||||
// count ++;
|
||||
// }
|
||||
} catch(Exception e) {
|
||||
Utils.log("==热点启动异常::" + e.toString());
|
||||
}
|
||||
|
||||
Utils.log("===热点可用");
|
||||
|
||||
initMicroServer();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void initMicroServer() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Utils.log("===准备开启微型服务器");
|
||||
if (mServerSocket == null) {
|
||||
mServerSocket = new ServerSocket();
|
||||
mServerSocket.setReuseAddress(true);
|
||||
mServerSocket.bind(new InetSocketAddress(Constant.DEFAULT_MICRO_SERVER_PORT));
|
||||
}
|
||||
|
||||
while (!isColseActivity) {
|
||||
if (!initSuccess) {
|
||||
mInitStatusTv.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initHotSpotView(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Utils.log("===循环等待客户端请求");
|
||||
Socket socket = mServerSocket.accept();
|
||||
KcWebRequestEntity requestEntity = hanlderSocket(socket);
|
||||
for (KcUriHandler uriHandler : mUriHandlers) {
|
||||
if (!uriHandler.matches(requestEntity.getUri())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Utils.log("====请求处理::" + requestEntity.getUri() + "==" + uriHandler.getClass().toString());
|
||||
uriHandler.handler(requestEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Utils.log("===网页传下载出现异常" + e.toString());
|
||||
e.printStackTrace();
|
||||
|
||||
if (!e.toString().contains("Socket closed")) {
|
||||
mInitStatusTv.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initHotSpotView(2);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private KcWebRequestEntity hanlderSocket(Socket socket) {
|
||||
KcWebRequestEntity requestEntity = new KcWebRequestEntity();
|
||||
|
||||
requestEntity.setSocket(socket);
|
||||
|
||||
try {
|
||||
InputStream is = socket.getInputStream();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int a = 0, b = 0;
|
||||
while((b != -1) && !(a == '\r' && b == '\n')){
|
||||
a = b;
|
||||
b = is.read();
|
||||
sb.append((char)(b));
|
||||
}
|
||||
String[] split = sb.toString().split(" ");
|
||||
if (split.length > 1) {
|
||||
String requestUri = split[1];
|
||||
requestEntity.setUri(requestUri);
|
||||
Utils.log("===客户端请求链接::" + requestUri);
|
||||
} else {
|
||||
requestEntity.setUri("/ERROR");
|
||||
Utils.log("===客户端请求链接异常::" + sb.toString());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return requestEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
backActivity();
|
||||
}
|
||||
|
||||
@OnClick(R.id.actionbar_rl_back)
|
||||
public void OnBackClikListener() {
|
||||
backActivity();
|
||||
}
|
||||
|
||||
private void backActivity() {
|
||||
DialogUtils.showWarningDialog(this, "退出分享", "退出本页面即会关闭分享热点,确定退出吗?"
|
||||
, "取消", "确定"
|
||||
, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
isColseActivity = true;
|
||||
unregisterReceiver(mWifiAPBroadcastReceiver);
|
||||
try {
|
||||
if(mWifiAPBroadcastReceiver != null){
|
||||
unregisterReceiver(mWifiAPBroadcastReceiver);
|
||||
mWifiAPBroadcastReceiver = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Utils.log("网页传发送异常-关闭广播");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
for (KcUriHandler uriHandler : mUriHandlers) {
|
||||
uriHandler.destroy();
|
||||
}
|
||||
|
||||
if (mServerSocket != null) {
|
||||
try {
|
||||
mServerSocket.close();
|
||||
mServerSocket = null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
HotspotManager.initUserAp(ShareGhWfifActivity.this);
|
||||
if (isOpenWifi) {
|
||||
WifiMgr.getInstance(ShareGhWfifActivity.this).openWifi();
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
}, null);
|
||||
|
||||
}
|
||||
}
|
||||
@ -47,6 +47,7 @@ public class SkipActivity extends BaseActivity {
|
||||
+ "-" + PlatformUtils.getInstance(this).getPlatformName(uri.getQueryParameter("platform"))
|
||||
+ "-V" + uri.getQueryParameter("version") + "】";
|
||||
intent.putExtra("content", content);
|
||||
intent.putExtra("suggestHintType", "plugin");
|
||||
intent.setClass(this, SuggestionActivity.class);
|
||||
} else if ("download".equals(host)) {
|
||||
intent.setClass(this, DownloadManagerActivity.class);
|
||||
|
||||
@ -23,6 +23,7 @@ import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TagUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
@ -178,28 +179,24 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
isFirst = false;
|
||||
|
||||
// 第一次启动,把package.txt文件内容加载进数据库
|
||||
FilterManager filterManager = null;
|
||||
if (!sp.getBoolean("isLoadFilter", false)) {
|
||||
filterManager = new FilterManager(getApplicationContext());
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
if (!sp.getBoolean("isLoadFilterV2d4", false)) {
|
||||
filterManager.loadFilter();
|
||||
}
|
||||
// 获取过滤包
|
||||
filterManager.getFilterFromServer(0);
|
||||
|
||||
// 检查是否存在旧版本光环助手包
|
||||
checkOldGhFile();
|
||||
|
||||
// 更新过滤表,获取自动刷新的cd,获取版本对应表
|
||||
String time = sp.getString("filter_time", null);
|
||||
String time = sp.getString("refresh_time", null);
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||
String today = format.format(new Date());
|
||||
if (!today.equals(time)) {
|
||||
// 获取过滤包
|
||||
if (filterManager == null) {
|
||||
filterManager = new FilterManager(getApplicationContext());
|
||||
}
|
||||
filterManager.getFilterFromServer(today);
|
||||
|
||||
// 获取版本代码、名称
|
||||
PlatformUtils.getInstance(getApplicationContext()).getPlatform();
|
||||
TagUtils.getInstance(getApplicationContext()).getTag();
|
||||
}
|
||||
|
||||
// 获取下载按钮状态、开启or关闭
|
||||
|
||||
@ -1,205 +0,0 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.MeasureHeightLayoutManager;
|
||||
import com.gh.gamecenter.adapter.StrategyAdapter;
|
||||
import com.gh.gamecenter.adapter.StrategyDialogAdapter;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.jakewharton.rxbinding.view.RxView;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import butterknife.BindView;
|
||||
import rx.functions.Action1;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/12/5.
|
||||
*
|
||||
*/
|
||||
public class StrategyActivity extends BaseActivity implements StrategyDialogAdapter.OnStrategyDialogCallBackListener{
|
||||
|
||||
@BindView(R.id.strategy_game_name) TextView mGameName;
|
||||
@BindView(R.id.strategy_select_game_rl) RelativeLayout mSelectGameRl;
|
||||
@BindView(R.id.strategy_rv) RecyclerView mStrategyRv;
|
||||
@BindView(R.id.popup_bg) View popupBg;
|
||||
@BindView(R.id.reuse_none_data) LinearLayout mNoData;
|
||||
|
||||
private StrategyAdapter mStrategyAdapter;
|
||||
|
||||
private PopupWindow mPopupWindow;
|
||||
|
||||
private static int mDialogGamePosition = -1;
|
||||
private static String gameId;
|
||||
private static String gameName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View contentView = View.inflate(this, R.layout.activity_strategy, null);
|
||||
init(contentView, "攻略");
|
||||
|
||||
mStrategyAdapter = new StrategyAdapter(this, gameId, mNoData);
|
||||
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
mStrategyRv.setLayoutManager(layoutManager);
|
||||
mStrategyRv.setAdapter(mStrategyAdapter);
|
||||
|
||||
mStrategyRv.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if(layoutManager.findLastVisibleItemPosition() + 1 == mStrategyAdapter.getItemCount()
|
||||
&& newState == RecyclerView.SCROLL_STATE_IDLE && mStrategyAdapter.isCanLoading()) {
|
||||
mStrategyAdapter.addList(mStrategyAdapter.getItemCount()-1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
List<ConcernInfo> concernGame = concernManager.getConcernGame();
|
||||
if (concernGame.size() >1 || (concernGame.size() == 1
|
||||
&& !concernGame.get(0).getId().equals("5618b86e8ab49e17088b4575"))) {
|
||||
mSelectGameRl.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(gameName)) {
|
||||
mGameName.setText(gameName);
|
||||
}
|
||||
|
||||
// 防抖处理
|
||||
RxView.clicks(mSelectGameRl)
|
||||
.throttleFirst(1, TimeUnit.SECONDS)
|
||||
.subscribe(new Action1<Void>() {
|
||||
@Override
|
||||
public void call(Void aVoid) {
|
||||
OnSelectGameClickListener();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void OnSelectGameClickListener() {
|
||||
isShowPopupBg(true);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.dialog_strategy_select_game, null);
|
||||
RecyclerView selectGameRv = (RecyclerView) contentView.findViewById(R.id.dialog_strategy_select_game_rv);
|
||||
ImageView selectIcon = (ImageView) contentView.findViewById(R.id.dialog_strategy_select_game_icon);
|
||||
RelativeLayout allGameRl = (RelativeLayout) contentView.findViewById(R.id.dialog_strategy_select_game_rl);
|
||||
|
||||
allGameRl.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mGameName.setText("全部游戏");
|
||||
mDialogGamePosition = -1;
|
||||
gameId = null;
|
||||
isShowPopupBg(false);
|
||||
mStrategyAdapter = new StrategyAdapter(StrategyActivity.this, gameId, mNoData);
|
||||
mStrategyRv.setAdapter(mStrategyAdapter);
|
||||
}
|
||||
});
|
||||
|
||||
if (mDialogGamePosition == -1) {
|
||||
selectIcon.setImageResource(R.drawable.strategy_game_select);
|
||||
} else {
|
||||
selectIcon.setImageDrawable(new ColorDrawable(0));
|
||||
}
|
||||
|
||||
selectGameRv.setLayoutManager(new MeasureHeightLayoutManager(this));
|
||||
selectGameRv.setAdapter(new StrategyDialogAdapter(this, mDialogGamePosition));
|
||||
|
||||
mPopupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
||||
, LinearLayout.LayoutParams.MATCH_PARENT, true);
|
||||
mPopupWindow.setAnimationStyle(R.style.scale_popwindow_anim_style);
|
||||
mPopupWindow.showAtLocation(mSelectGameRl, 0, 0, 0);
|
||||
|
||||
selectGameRv.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK
|
||||
&& event.getRepeatCount() == 0
|
||||
&& mPopupWindow != null
|
||||
&& mPopupWindow.isShowing()) {
|
||||
isShowPopupBg(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
contentView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isShowPopupBg(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void isShowPopupBg(boolean isShow) {
|
||||
if(isShow) {
|
||||
popupBg.setVisibility(View.VISIBLE);
|
||||
popupBg.animate()
|
||||
.alpha(1f)
|
||||
.setDuration(300)
|
||||
.setListener(null);
|
||||
} else {
|
||||
mPopupWindow.dismiss();
|
||||
popupBg.animate()
|
||||
.alpha(0f)
|
||||
.setDuration(300)
|
||||
.setListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
popupBg.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean selectRlIsVisible() {
|
||||
return mSelectGameRl.getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPosition(int position, ConcernInfo concernInfo) {
|
||||
gameId = concernInfo.getId();
|
||||
gameName = concernInfo.getGameName();
|
||||
mNoData.setVisibility(View.GONE);
|
||||
mDialogGamePosition = position;
|
||||
|
||||
mGameName.setText(gameName);
|
||||
isShowPopupBg(false);
|
||||
|
||||
mStrategyAdapter = new StrategyAdapter(this, gameId, mNoData);
|
||||
mStrategyRv.setAdapter(mStrategyAdapter);
|
||||
}
|
||||
}
|
||||
@ -1,20 +1,26 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.SubjectAdapter;
|
||||
import com.gh.gamecenter.adapter.SubjectTypeAdapter;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
@ -32,9 +38,10 @@ import butterknife.BindView;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public class SubjectActivity extends BaseActivity {
|
||||
public class SubjectActivity extends BaseActivity implements SubjectTypeAdapter.OnSelectTypeListener {
|
||||
|
||||
@BindView(R.id.subject_list) RecyclerView subject_list;
|
||||
@BindView(R.id.subject_type_list) RecyclerView subject_type_list;
|
||||
@BindView(R.id.subject_pb_loading) ProgressBarCircularIndeterminate subject_pb_loading;
|
||||
@BindView(R.id.reuse_no_connection) LinearLayout reuse_no_connection;
|
||||
|
||||
@ -43,6 +50,8 @@ public class SubjectActivity extends BaseActivity {
|
||||
|
||||
private int page = 1;
|
||||
|
||||
private String type;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
@ -76,40 +85,52 @@ public class SubjectActivity extends BaseActivity {
|
||||
}
|
||||
init(contentView, name);
|
||||
|
||||
type = "全部";
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this, type);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
|
||||
subject_list.addItemDecoration(new VerticalItemDecoration(this, 8, true));
|
||||
subject_list.setHasFixedSize(true);
|
||||
subject_list.setLayoutManager(layoutManager);
|
||||
adapter = new SubjectAdapter(this);
|
||||
adapter = new SubjectAdapter(this, type);
|
||||
subject_list.setAdapter(adapter);
|
||||
|
||||
subject_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (adapter.isLoaded() && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
if (!adapter.isRemove() && adapter.isLoaded() && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& adapter.getItemCount() == layoutManager.findLastVisibleItemPosition() + 1){
|
||||
page++;
|
||||
adapter.initList(page);
|
||||
adapter.initList(page, type);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GridLayoutManager layout = new GridLayoutManager(this, 4){
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
subject_type_list.setLayoutManager(layout);
|
||||
|
||||
if (TextUtils.isEmpty(name) && !TextUtils.isEmpty(id)) {
|
||||
getSubjectName(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void getSubjectName(String id) {
|
||||
@ -145,6 +166,22 @@ public class SubjectActivity extends BaseActivity {
|
||||
if (subject_pb_loading != null && subject_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
subject_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
page ++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
super.loadDone(obj);
|
||||
// 初始化顶部分类标签
|
||||
if (!type.equals("全部")) return;
|
||||
|
||||
ArrayList<String> gameType = (ArrayList<String>) obj;
|
||||
gameType.add(0, "全部");
|
||||
ViewGroup.LayoutParams params = subject_type_list.getLayoutParams();
|
||||
params.height = (int) Math.ceil(gameType.size() / 4f) * DisplayUtils.dip2px(this, 37);
|
||||
subject_type_list.setLayoutParams(params);
|
||||
SubjectTypeAdapter adapter = new SubjectTypeAdapter(SubjectActivity.this, gameType);
|
||||
subject_type_list.setAdapter(adapter);
|
||||
}
|
||||
|
||||
// 下载被删除事件
|
||||
@ -196,7 +233,7 @@ public class SubjectActivity extends BaseActivity {
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this, type);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
@ -221,4 +258,15 @@ public class SubjectActivity extends BaseActivity {
|
||||
DownloadManager.getInstance(getApplicationContext()).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectType(String type) {
|
||||
Utils.toast(this, type);
|
||||
page = 1;
|
||||
this.type = type;
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(this, type);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.QQUtils;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/31.
|
||||
*/
|
||||
public class SuggestSelectActivity extends BaseActivity {
|
||||
@BindView(R.id.suggest_type1) RelativeLayout mType1;
|
||||
@BindView(R.id.suggest_type2) RelativeLayout mType2;
|
||||
@BindView(R.id.suggest_type3) RelativeLayout mType3;
|
||||
@BindView(R.id.suggest_type4) RelativeLayout mType4;
|
||||
@BindView(R.id.suggest_type5) RelativeLayout mType5;
|
||||
@BindView(R.id.suggest_type6) RelativeLayout mType6;
|
||||
@BindView(R.id.suggest_qqun) TextView mQqun;
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == 0x121 && resultCode == 0x122) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View view = View.inflate(this, R.layout.activity_suggest_select, null);
|
||||
init(view, "意见反馈");
|
||||
}
|
||||
|
||||
@OnClick({R.id.suggest_type1, R.id.suggest_type2, R.id.suggest_type3
|
||||
, R.id.suggest_type4, R.id.suggest_type5, R.id.suggest_type6, R.id.suggest_qqun_rl})
|
||||
public void OnClick(View view){
|
||||
int type = 1;
|
||||
switch (view.getId()) {
|
||||
case R.id.suggest_type1:
|
||||
type = 1;
|
||||
break;
|
||||
case R.id.suggest_type2:
|
||||
type = 2;
|
||||
break;
|
||||
case R.id.suggest_type3:
|
||||
type = 3;
|
||||
break;
|
||||
case R.id.suggest_type4:
|
||||
type = 4;
|
||||
break;
|
||||
case R.id.suggest_type5:
|
||||
type = 5;
|
||||
break;
|
||||
case R.id.suggest_type6:
|
||||
type = 6;
|
||||
break;
|
||||
case R.id.suggest_qqun_rl:
|
||||
QQUtils.joinQQGroup(SuggestSelectActivity.this, "vd754P2_uNUJqDcgX4V-pyXEGZZVH0DE");
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, SuggestionActivity.class);
|
||||
intent.putExtra("suggestType", type);
|
||||
intent.putExtra("suggestHintType", "Normal");
|
||||
startActivityForResult(intent, 0x121);
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,224 +2,684 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.Window;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.view.CardLinearLayout;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.entity.InstallGameEntity;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.gh.gamecenter.suggest.SuggestPicAdapter;
|
||||
import com.gh.gamecenter.suggest.SuggestSelectGameAdapter;
|
||||
import com.gh.gamecenter.suggest.SuggestTypeAdapter;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.Observer;
|
||||
import rx.Subscriber;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @from SettingActivity
|
||||
* @function 填写反馈页面
|
||||
*
|
||||
* */
|
||||
public class SuggestionActivity extends BaseActivity implements OnClickListener {
|
||||
* Created by khy on 2017/3/31.
|
||||
*/
|
||||
public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapter.OnSelectTypeListener {
|
||||
|
||||
@BindView(R.id.tv_suggest_connectway) TextView tv_suggest_connectway;
|
||||
@BindView(R.id.et_suggest_content) EditText et_suggest_content;
|
||||
@BindView(R.id.et_suggest_connectway) EditText et_suggest_connectway;
|
||||
@BindView(R.id.btn_suggest_post) CardLinearLayout btn_suggest_post;
|
||||
@BindView(R.id.suggest_content_et)
|
||||
EditText mSuggestContentEt;
|
||||
@BindView(R.id.suggest_pic_rv)
|
||||
RecyclerView mSuggestPicRv;
|
||||
@BindView(R.id.suggest_news_link_et)
|
||||
EditText mSuggestNewsLinkEt;
|
||||
@BindView(R.id.suggest_news_link_ll)
|
||||
LinearLayout mSuggestNewsLinkLl;
|
||||
@BindView(R.id.suggest_email_et)
|
||||
EditText mSuggestEmailEt;
|
||||
@BindView(R.id.suggest_post_btn)
|
||||
TextView mSuggestPostBtn;
|
||||
@BindView(R.id.suggest_post_ll)
|
||||
LinearLayout suggestPostLl;
|
||||
@BindView(R.id.suggest_type_rv)
|
||||
RecyclerView mTypeRv;
|
||||
@BindView(R.id.suggest_select_game)
|
||||
TextView mSuggestSelectGame;
|
||||
@BindView(R.id.suggest_game_text)
|
||||
TextView mSuggestGameText;
|
||||
@BindView(R.id.suggest_game_ll)
|
||||
LinearLayout mSuggestGameLl;
|
||||
@BindView(R.id.suggest_scrollview)
|
||||
ScrollView mScrollView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
private SuggestPicAdapter mAdapter;
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_suggest, null);
|
||||
private Dialog selectGameDialog;
|
||||
private Dialog postDialog;
|
||||
|
||||
init(contentView, "意见反馈");
|
||||
private String[] arrType = {"普通反馈", "功能建议", "发生闪退", "游戏问题", "游戏收录", "文章投稿"};
|
||||
|
||||
btn_suggest_post.setOnClickListener(this);
|
||||
btn_suggest_post.setClickable(false);
|
||||
private int curType = -1;
|
||||
|
||||
et_suggest_content.requestFocus();
|
||||
private SharedPreferences sp;
|
||||
|
||||
tv_suggest_connectway.setText("邮箱");
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (data != null && requestCode == 0x233) {
|
||||
Uri selectedImage = data.getData();
|
||||
if (selectedImage == null) {
|
||||
return;
|
||||
}
|
||||
String[] filePathColumn = { MediaStore.Images.Media.DATA };
|
||||
|
||||
et_suggest_content.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||
int after) {
|
||||
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
||||
if (cursor == null) {
|
||||
return;
|
||||
}
|
||||
cursor.moveToFirst();
|
||||
|
||||
}
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String picturePath = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before,
|
||||
int count) {
|
||||
if (s.length() > 0) {
|
||||
btn_suggest_post.setClickable(true);
|
||||
} else {
|
||||
btn_suggest_post.setClickable(false);
|
||||
}
|
||||
}
|
||||
Utils.log("picturePath = " + picturePath);
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
mAdapter.addFileList(picturePath);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
String content = getIntent().getStringExtra("content");
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
content = getIntent().getBundleExtra("data").getString("content");
|
||||
}
|
||||
if (!TextUtils.isEmpty(content)) {
|
||||
et_suggest_content.setText(content);
|
||||
et_suggest_content.setSelection(et_suggest_content.getText().length());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
View view = View.inflate(this, R.layout.activity_suggest, null);
|
||||
init(view, "意见反馈");
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.actionbar_rl_back:
|
||||
finish();
|
||||
break;
|
||||
case R.id.btn_suggest_post:
|
||||
String email = et_suggest_connectway.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
showConfirmDialog(email);
|
||||
} else if (isEmailAddress(email)) {
|
||||
Dialog dialog = new Dialog(this);
|
||||
View view = View.inflate(this, R.layout.set_wait_dialog, null);
|
||||
TextView message = (TextView) view
|
||||
.findViewById(R.id.set_wait_message);
|
||||
message.setText("正在反馈...");
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
sendSuggestion(dialog, email);
|
||||
} else {
|
||||
toast("邮箱错误");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
curType = getIntent().getExtras().getInt("suggestType");
|
||||
String suggestContent = getIntent().getExtras().getString("content");
|
||||
String suggestHintType = getIntent().getExtras().getString("suggestHintType");
|
||||
|
||||
// 弹出确认对话框
|
||||
private void showConfirmDialog(final String email) {
|
||||
DialogUtils.showWarningDialog(this, "温馨提示", "填写联系方式有助于我们更好地一对一解决您的问题,确定不填写吗?",
|
||||
"直接提交", "我要填写",
|
||||
new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
et_suggest_connectway.requestFocus();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
if (getIntent().getBundleExtra("data") != null) {
|
||||
suggestContent = getIntent().getBundleExtra("data").getString("content");
|
||||
}
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(et_suggest_connectway, 0);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
},
|
||||
new DialogUtils.CancelListener() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
Dialog dialog = new Dialog(SuggestionActivity.this);
|
||||
View view = View.inflate(SuggestionActivity.this,
|
||||
R.layout.set_wait_dialog, null);
|
||||
TextView message = (TextView) view
|
||||
.findViewById(R.id.set_wait_message);
|
||||
message.setText("正在反馈...");
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
sendSuggestion(dialog, email);
|
||||
}
|
||||
});
|
||||
}
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
private void sendSuggestion(final Dialog dialog, String email) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("message", et_suggest_content.getText().toString().trim());
|
||||
params.put("from", email);
|
||||
params.put("ghversion", PackageUtils.getVersionName(this));
|
||||
params.put("channel", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
params.put("type", android.os.Build.MODEL);
|
||||
params.put("sdk", String.valueOf(android.os.Build.VERSION.SDK_INT));
|
||||
params.put("version", android.os.Build.VERSION.RELEASE);
|
||||
params.put("imei", ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId());
|
||||
// 意见反馈类型
|
||||
mTypeRv.setLayoutManager(new GridLayoutManager(this, 2){
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
mTypeRv.setAdapter(new SuggestTypeAdapter(this, curType, arrType));
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getApi().postSuggestion(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
dialog.dismiss();
|
||||
// 意见反馈上传图片列表
|
||||
mSuggestPicRv.setLayoutManager(new GridLayoutManager(this, 5){
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
mAdapter = new SuggestPicAdapter(this);
|
||||
mSuggestPicRv.setAdapter(mAdapter);
|
||||
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
if ("ok".equals(response.getString("status"))) {
|
||||
toast("提交成功,感谢您的反馈!");
|
||||
finish();
|
||||
} else {
|
||||
toast("提交失败,请稍后尝试!");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
toast("提交失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
//解决透明沉浸栏和软键盘冲突(重置ScrollView高度)
|
||||
final View decorView=getWindow().getDecorView();
|
||||
decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
Rect rect=new Rect();
|
||||
decorView.getWindowVisibleDisplayFrame(rect);
|
||||
int screenHeight = decorView.getRootView().getHeight();
|
||||
int heightDifference = screenHeight-rect.bottom;//计算软键盘占有的高度 = 屏幕高度 - 视图可见高度
|
||||
RelativeLayout.LayoutParams layoutParams= (RelativeLayout.LayoutParams) mScrollView.getLayoutParams();
|
||||
layoutParams.setMargins(0,0,0,heightDifference);//设置ScrollView的marginBottom的值为软键盘占有的高度即可
|
||||
mScrollView.requestLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
dialog.dismiss();
|
||||
if (!TextUtils.isEmpty(suggestContent)) {
|
||||
mSuggestContentEt.setText(suggestContent);
|
||||
}
|
||||
|
||||
toast("提交失败,请检查网络状态");
|
||||
}
|
||||
});
|
||||
}
|
||||
if (curType == 5) {
|
||||
mSuggestGameLl.setVisibility(View.GONE);
|
||||
mSuggestContentEt.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
initSuggest(curType);
|
||||
}
|
||||
|
||||
private boolean isEmailAddress(String email) {
|
||||
Pattern p = Pattern
|
||||
.compile("^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$");
|
||||
Matcher m = p.matcher(email);
|
||||
return m.matches();
|
||||
}
|
||||
if (TextUtils.isEmpty(suggestHintType)) {
|
||||
suggestHintType = "plugin";
|
||||
}
|
||||
|
||||
switch (suggestHintType) {
|
||||
case "plugin":
|
||||
Set<String> plugin = sp.getStringSet("suggestionPlugin", null);
|
||||
if (plugin != null) {
|
||||
showHintDialog(plugin);
|
||||
}
|
||||
break;
|
||||
case "game":
|
||||
Set<String> game = sp.getStringSet("suggestionGame", null);
|
||||
if (game != null) {
|
||||
showHintDialog(game);
|
||||
}
|
||||
break;
|
||||
case "libao":
|
||||
Set<String> libao = sp.getStringSet("suggestionLibao", null);
|
||||
if (libao != null) {
|
||||
showHintDialog(libao);
|
||||
}
|
||||
break;
|
||||
case "service":
|
||||
Set<String> service = sp.getStringSet("suggestionService", null);
|
||||
if (service != null) {
|
||||
showHintDialog(service);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void showHintDialog(Set<String> dialogType) {
|
||||
final Dialog dialog = new Dialog(SuggestionActivity.this);
|
||||
|
||||
LinearLayout container = new LinearLayout(SuggestionActivity.this);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setBackgroundColor(Color.WHITE);
|
||||
container.setPadding(0, DisplayUtils.dip2px(SuggestionActivity.this, 12), 0, DisplayUtils.dip2px(SuggestionActivity.this, 12));
|
||||
|
||||
for (String s : dialogType) {
|
||||
final TextView reportTv = new TextView(SuggestionActivity.this);
|
||||
reportTv.setPadding(DisplayUtils.dip2px(SuggestionActivity.this, 20), DisplayUtils.dip2px(SuggestionActivity.this, 12),
|
||||
0, DisplayUtils.dip2px(SuggestionActivity.this, 12));
|
||||
reportTv.setText(s);
|
||||
reportTv.setTextSize(17);
|
||||
reportTv.setTextColor(SuggestionActivity.this.getResources().getColor(R.color.title));
|
||||
reportTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
int widthPixels = SuggestionActivity.this.getResources().getDisplayMetrics().widthPixels;
|
||||
reportTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9)/10,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
container.addView(reportTv);
|
||||
|
||||
reportTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
mSuggestContentEt.setText(mSuggestContentEt.getText().toString() + reportTv.getText().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(container);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@OnClick({ R.id.suggest_post_btn, R.id.suggest_select_game, R.id.suggest_game_text})
|
||||
public void onViewClicked(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.suggest_post_btn:
|
||||
if (TextUtils.isEmpty(mSuggestContentEt.getText().toString())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String email = mSuggestEmailEt.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
showConfirmDialog(email);
|
||||
} else if (isEmailAddress(email)) {
|
||||
postDialog = new Dialog(SuggestionActivity.this);
|
||||
View content = View.inflate(SuggestionActivity.this, R.layout.set_wait_dialog, null);
|
||||
TextView message = (TextView) content
|
||||
.findViewById(R.id.set_wait_message);
|
||||
message.setText("正在反馈...");
|
||||
postDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
postDialog.setContentView(content);
|
||||
postDialog.setCanceledOnTouchOutside(false);
|
||||
postDialog.setCancelable(false);
|
||||
postDialog.show();
|
||||
|
||||
List<String> fileList = mAdapter.getFileList();
|
||||
if (fileList != null && fileList.size() > 0) {
|
||||
postPic(email);
|
||||
} else {
|
||||
initPostData(email, null);
|
||||
}
|
||||
} else {
|
||||
toast("邮箱错误");
|
||||
}
|
||||
break;
|
||||
case R.id.suggest_select_game:
|
||||
showSelectDialog();
|
||||
break;
|
||||
case R.id.suggest_game_text:
|
||||
mSuggestGameLl.setVisibility(View.GONE);
|
||||
mSuggestContentEt.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 弹出确认对话框
|
||||
private void showConfirmDialog(final String email) {
|
||||
|
||||
DialogUtils.showWarningDialog(this, "温馨提示", "填写联系方式有助于我们更好地一对一解决您的问题,确定不填写吗?",
|
||||
"直接提交", "我要填写",
|
||||
new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
mSuggestEmailEt.requestFocus();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(mSuggestEmailEt, 0);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
},
|
||||
new DialogUtils.CancelListener() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
postDialog = new Dialog(SuggestionActivity.this);
|
||||
View view = View.inflate(SuggestionActivity.this,
|
||||
R.layout.set_wait_dialog, null);
|
||||
TextView message = (TextView) view
|
||||
.findViewById(R.id.set_wait_message);
|
||||
message.setText("正在反馈...");
|
||||
postDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
postDialog.setContentView(view);
|
||||
postDialog.setCanceledOnTouchOutside(false);
|
||||
postDialog.setCancelable(false);
|
||||
postDialog.show();
|
||||
|
||||
List<String> fileList = mAdapter.getFileList();
|
||||
if (fileList != null && fileList.size() > 0) {
|
||||
postPic(email);
|
||||
} else {
|
||||
initPostData(email, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean savePicture(String newPath, String filePath) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
// options.inSampleSize = 2;
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
|
||||
|
||||
File file = new File(newPath);
|
||||
int quality = 80;
|
||||
do {
|
||||
try {
|
||||
BufferedOutputStream bos = new BufferedOutputStream(
|
||||
new FileOutputStream(file));
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos);
|
||||
bos.flush();
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
file.delete();
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
quality -= 10;
|
||||
} while (file.length() > 81920);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void postPic(final String email) {
|
||||
|
||||
final JSONArray picArray = new JSONArray();
|
||||
Observable.create(new Observable.OnSubscribe<JSONObject>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super JSONObject> subscriber) {
|
||||
String path;
|
||||
int index = 0;
|
||||
for (String s : mAdapter.getFileList()) {
|
||||
path = getCacheDir() + File.separator + System.currentTimeMillis() + index + ".jpg";
|
||||
if (savePicture(path, s)) {
|
||||
subscriber.onNext(FileUtils.uploadFile(Config.HOST + "support/user/suggestion/img", path, null));
|
||||
index ++;
|
||||
} else {
|
||||
subscriber.onNext(FileUtils.uploadFile(Config.HOST + "support/user/suggestion/img", s, null));
|
||||
}
|
||||
}
|
||||
subscriber.onCompleted();
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<JSONObject>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
Utils.log("=========完成" );
|
||||
initPostData(email, picArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Utils.log("=========错误" + e.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(JSONObject result) {
|
||||
if (result != null) {
|
||||
try {
|
||||
Utils.log("===========" + result);
|
||||
int statusCode = result.getInt("statusCode");
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
picArray.put(result.getString("img"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initPostData(String email, JSONArray picArray) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("message", mSuggestContentEt.getText().toString().trim());
|
||||
params.put("from", email);
|
||||
params.put("ghversion", PackageUtils.getVersionName(this));
|
||||
params.put("channel", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
params.put("type", android.os.Build.MODEL);
|
||||
params.put("sdk", String.valueOf(android.os.Build.VERSION.SDK_INT));
|
||||
params.put("version", android.os.Build.VERSION.RELEASE);
|
||||
params.put("source", "光环助手");
|
||||
params.put("imei", ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId());
|
||||
|
||||
if (curType == 6 && !TextUtils.isEmpty(mSuggestNewsLinkEt.getText().toString())) {
|
||||
params.put("url", mSuggestNewsLinkEt.getText().toString().trim());
|
||||
}
|
||||
if (curType > 0) {
|
||||
params.put("suggestion_type", arrType[curType - 1]);
|
||||
}
|
||||
if (curType == 3) {
|
||||
params.put("log", readFromFile());
|
||||
}
|
||||
|
||||
JSONObject jsonObject = new JSONObject(params);
|
||||
|
||||
if (picArray != null && picArray.length() > 0) {
|
||||
try {
|
||||
jsonObject.put("pic", picArray);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
jsonObject.toString());
|
||||
|
||||
Utils.log("=======postBody" + jsonObject.toString());
|
||||
|
||||
sendSuggestion(body, true);
|
||||
}
|
||||
|
||||
|
||||
private void sendSuggestion(final RequestBody body, boolean isCheck) {
|
||||
|
||||
TokenUtils.getToken(SuggestionActivity.this, isCheck).flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
return RetrofitManager.getApi().postSuggestion(body, token);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse(){
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (postDialog != null) {
|
||||
postDialog.dismiss();
|
||||
}
|
||||
Utils.log("======onResponse" + response.toString());
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
if ("ok".equals(response.getString("status"))) {
|
||||
|
||||
toast("感谢您的反馈!");
|
||||
setResult(0x122);
|
||||
finish();
|
||||
} else {
|
||||
toast("提交失败,请稍后尝试!");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
toast("提交失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
Utils.log("======ERROR" + e.toString());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
try {
|
||||
if (e != null) {
|
||||
String string = e.response().errorBody().string();
|
||||
Utils.log("===========onFailure" + string);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
if (e != null && e.code() == 401) {
|
||||
sendSuggestion(body, false);
|
||||
return;
|
||||
} else {
|
||||
if (postDialog != null) {
|
||||
postDialog.dismiss();
|
||||
}
|
||||
|
||||
toast("提交失败,请检查网络状态");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void showSelectDialog() {
|
||||
View view = View.inflate(this, R.layout.dialog_suggest_select_game, null);
|
||||
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.dialog_suggest_game_rv);
|
||||
TextView back = (TextView) view.findViewById(R.id.dialog_suggest_game_back);
|
||||
ProgressBar pb = (ProgressBar) view.findViewById(R.id.dialog_suggest_game_load);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
|
||||
recyclerView.setAdapter(new SuggestSelectGameAdapter(this, pb));
|
||||
|
||||
selectGameDialog = new Dialog(this);
|
||||
selectGameDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
selectGameDialog.setCanceledOnTouchOutside(false);
|
||||
selectGameDialog.setContentView(view);
|
||||
selectGameDialog.show();
|
||||
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
selectGameDialog.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onType(int type) {
|
||||
curType = type;
|
||||
|
||||
mSuggestPicRv.postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
//将ScrollView滚动到底
|
||||
mScrollView.fullScroll(View.FOCUS_DOWN);
|
||||
}
|
||||
}, 100);
|
||||
initSuggest(type);
|
||||
}
|
||||
|
||||
private void initSuggest(int type) {
|
||||
switch (type) {
|
||||
case 1:
|
||||
mSuggestContentEt.setHint("请详细描述你遇到的问题... \n ↓↓你还可以上传截图");
|
||||
mSuggestNewsLinkLl.setVisibility(View.GONE);
|
||||
mSuggestContentEt.setVisibility(View.VISIBLE);
|
||||
mSuggestGameLl.setVisibility(View.GONE);
|
||||
break;
|
||||
case 2:
|
||||
mSuggestContentEt.setHint("请详细描述你的建议... \n ↓↓你还可以上传截图");
|
||||
mSuggestNewsLinkLl.setVisibility(View.GONE);
|
||||
mSuggestContentEt.setVisibility(View.VISIBLE);
|
||||
mSuggestGameLl.setVisibility(View.GONE);
|
||||
break;
|
||||
case 3:
|
||||
mSuggestContentEt.setHint("请详细描述闪退之前你所进行的操作... \n ↓↓你还可以上传截图");
|
||||
mSuggestNewsLinkLl.setVisibility(View.GONE);
|
||||
mSuggestContentEt.setVisibility(View.VISIBLE);
|
||||
mSuggestGameLl.setVisibility(View.GONE);
|
||||
break;
|
||||
case 4:
|
||||
mSuggestContentEt.setHint("请写上游戏名字,以及具体遇到的问题... \n ↓↓你还可以上传截图");
|
||||
mSuggestNewsLinkLl.setVisibility(View.GONE);
|
||||
mSuggestContentEt.setVisibility(View.VISIBLE);
|
||||
mSuggestGameLl.setVisibility(View.GONE);
|
||||
break;
|
||||
case 5:
|
||||
mSuggestNewsLinkLl.setVisibility(View.GONE);
|
||||
mSuggestGameLl.setVisibility(View.VISIBLE);
|
||||
mSuggestContentEt.setVisibility(View.GONE);
|
||||
break;
|
||||
case 6:
|
||||
mSuggestContentEt.setHint("简单介绍文章内容,然后在下面填写文章链接... \n ↓↓你还可以上传截图");
|
||||
mSuggestNewsLinkLl.setVisibility(View.VISIBLE);
|
||||
mSuggestContentEt.setVisibility(View.VISIBLE);
|
||||
mSuggestGameLl.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
super.loadDone(obj);
|
||||
if (selectGameDialog != null) {
|
||||
selectGameDialog.cancel();
|
||||
}
|
||||
|
||||
mSuggestGameLl.setVisibility(View.GONE);
|
||||
mSuggestContentEt.setVisibility(View.VISIBLE);
|
||||
InstallGameEntity entity = (InstallGameEntity) obj;
|
||||
mSuggestContentEt.setText("推荐收录:" + entity.getGameName() + "(" + entity.getPackageName() + ", " + entity.getGameVersion() + ")");
|
||||
}
|
||||
|
||||
public String readFromFile(){
|
||||
|
||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
|
||||
File file = new File(getExternalFilesDir(null).getPath() + "/log");
|
||||
if (file.isFile()) return "检测log文件夹是文件";
|
||||
|
||||
File[] files = file.listFiles();
|
||||
if (files == null || files.length == 0) return "log文件夹为空" + file.getPath();
|
||||
File targetFile = files[files.length - 1];
|
||||
|
||||
try{
|
||||
if(!targetFile.exists()){
|
||||
targetFile.createNewFile();
|
||||
return "No File error ";
|
||||
}else{
|
||||
InputStream in = new BufferedInputStream(new FileInputStream(targetFile));
|
||||
BufferedReader br= new BufferedReader(new InputStreamReader(in, "UTF-8"));
|
||||
String tmp;
|
||||
StringBuffer string = new StringBuffer();
|
||||
while((tmp=br.readLine())!=null){
|
||||
string.append(tmp);
|
||||
}
|
||||
br.close();
|
||||
in.close();
|
||||
return string.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return e.toString();
|
||||
}
|
||||
}else{
|
||||
return "SD Card error";
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEmailAddress(String email) {
|
||||
Pattern p = Pattern
|
||||
.compile("^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$");
|
||||
Matcher m = p.matcher(email);
|
||||
return m.matches();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
@ -11,23 +15,37 @@ import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.common.executors.CallerThreadExecutor;
|
||||
import com.facebook.common.references.CloseableReference;
|
||||
import com.facebook.datasource.DataSource;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.drawee.controller.BaseControllerListener;
|
||||
import com.facebook.drawee.drawable.ScalingUtils;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.imagepipeline.core.ImagePipeline;
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.facebook.imagepipeline.image.ImageInfo;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.MessageShareUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.Gh_RelativeLayout;
|
||||
import com.gh.common.view.Gh_RelativeLayout.OnSingleTapListener;
|
||||
import com.gh.common.view.Gh_ViewPager;
|
||||
import com.gh.common.view.ZoomSimpleDraweeView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
@ -188,11 +206,110 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
}
|
||||
});
|
||||
|
||||
//长按
|
||||
imageView.setOnLongClickListener(new ZoomSimpleDraweeView.setOnLongClickListener() {
|
||||
@Override
|
||||
public void onLongClick() {
|
||||
final Dialog dialog = new Dialog(ViewImageActivity.this);
|
||||
|
||||
LinearLayout container = new LinearLayout(ViewImageActivity.this);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setBackgroundColor(Color.WHITE);
|
||||
|
||||
final TextView reportTv = new TextView(ViewImageActivity.this);
|
||||
reportTv.setPadding(DisplayUtils.dip2px(ViewImageActivity.this, 20), DisplayUtils.dip2px(ViewImageActivity.this, 12),
|
||||
0, DisplayUtils.dip2px(ViewImageActivity.this, 12));
|
||||
reportTv.setText("保存图片");
|
||||
reportTv.setTextSize(17);
|
||||
reportTv.setTextColor(ViewImageActivity.this.getResources().getColor(R.color.title));
|
||||
reportTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
int widthPixels = ViewImageActivity.this.getResources().getDisplayMetrics().widthPixels;
|
||||
reportTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9)/10,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
container.addView(reportTv);
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(container);
|
||||
dialog.show();
|
||||
|
||||
reportTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
findImageBM();
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
view.setTag(position);
|
||||
container.addView(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void findImageBM() {
|
||||
String key = urls.get(viewimage_vp_show.getCurrentItem());
|
||||
String hdKey = "http://image.ghzhushou.com/pic/hq" + key.substring(key.lastIndexOf("/"));
|
||||
ImagePipeline imagePipeline = Fresco.getImagePipeline();
|
||||
String curUrl = null;
|
||||
|
||||
if (imagePipeline.isInBitmapMemoryCache(Uri.parse(hdKey))) {
|
||||
curUrl = hdKey;
|
||||
} else if (imagePipeline.isInBitmapMemoryCache(Uri.parse(key))){
|
||||
curUrl = key;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
ImageRequest imageRequest = ImageRequestBuilder
|
||||
.newBuilderWithSource(Uri.parse(key))
|
||||
.setProgressiveRenderingEnabled(true)
|
||||
.build();
|
||||
|
||||
DataSource<CloseableReference<CloseableImage>>
|
||||
dataSource = imagePipeline.fetchDecodedImage(imageRequest, ViewImageActivity.this);
|
||||
final String finalCurUrl = curUrl;
|
||||
dataSource.subscribe(new BaseBitmapDataSubscriber() {
|
||||
@Override
|
||||
protected void onNewResultImpl(Bitmap bitmap) {
|
||||
saveImage(bitmap, finalCurUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
|
||||
|
||||
}
|
||||
}, CallerThreadExecutor.getInstance());
|
||||
}
|
||||
|
||||
private void saveImage(Bitmap bitmap, String curUrl) {
|
||||
|
||||
String fileName = curUrl.substring(curUrl.lastIndexOf("/"));
|
||||
String savePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/ghzhushou/";
|
||||
|
||||
try {
|
||||
File file = new File(savePath);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
|
||||
File f = new File(savePath, fileName);
|
||||
if (f.exists()) {
|
||||
f.delete();
|
||||
}
|
||||
|
||||
FileOutputStream out = new FileOutputStream(f);
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
|
||||
out.flush();
|
||||
out.close();
|
||||
Utils.log("========保存成功");
|
||||
MessageShareUtils.refreshImage(new File(savePath), ViewImageActivity.this);
|
||||
} catch (IOException e) {
|
||||
Utils.log("========保存失败" + e.toString());
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
@ -250,7 +367,8 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
.build();
|
||||
imageView.setController(controller);
|
||||
}else {
|
||||
imageView.setImageURI(url);
|
||||
// imageView.setImageURI(url);
|
||||
ImageUtils.display(imageView, url);
|
||||
// ImageUtils.getInstance(getApplicationContext()).display(url, imageView, new BaseControllerListener(){
|
||||
// @Override
|
||||
// public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
|
||||
|
||||
172
app/src/main/java/com/gh/gamecenter/VoteActivity.java
Normal file
172
app/src/main/java/com/gh/gamecenter/VoteActivity.java
Normal file
@ -0,0 +1,172 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.gamecenter.adapter.VoteAdapter;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/4/11.
|
||||
* 求版本投票页面
|
||||
*/
|
||||
public class VoteActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.vote_rv)
|
||||
RecyclerView mVoteRv;
|
||||
@BindView(R.id.vote_refresh)
|
||||
SwipeRefreshLayout mVoteRefresh;
|
||||
@BindView(R.id.vote_loading)
|
||||
ProgressBarCircularIndeterminate mVoteLoading;
|
||||
@BindView(R.id.reuse_no_connection)
|
||||
LinearLayout mNoConnection;
|
||||
@BindView(R.id.vote_add_tv)
|
||||
TextView mAddTv;
|
||||
|
||||
private ImageView addVote;
|
||||
|
||||
private VoteAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
String gameName = getIntent().getExtras().getString("gameName");
|
||||
|
||||
View view = View.inflate(this, R.layout.activity_vote, null);
|
||||
|
||||
// 添加添加图标
|
||||
addVote = new ImageView(this);
|
||||
addVote.setImageResource(R.drawable.add_vote_icon);
|
||||
addVote.setPadding(DisplayUtils.dip2px(this, 13), DisplayUtils.dip2px(this, 15)
|
||||
, DisplayUtils.dip2px(this, 15), DisplayUtils.dip2px(this, 15));
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
||||
DisplayUtils.dip2px(this, 48), DisplayUtils.dip2px(this, 48));
|
||||
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) view.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(addVote, params);
|
||||
init(view, gameName + " - 求版本");
|
||||
|
||||
|
||||
addVote.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showAddVoteDialog();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mVoteRv.setLayoutManager(new LinearLayoutManager(this));
|
||||
mAdapter = new VoteAdapter(this);
|
||||
mVoteRv.setAdapter(mAdapter);
|
||||
|
||||
mAddTv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showAddVoteDialog();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void showAddVoteDialog() {
|
||||
final Dialog dialog = new Dialog(VoteActivity.this);
|
||||
|
||||
View view = View.inflate(VoteActivity.this, R.layout.dialog_modify_nickname, null);
|
||||
|
||||
TextView title = (TextView) view.findViewById(R.id.dialog_nickname_title);
|
||||
title.setText("输入选项名字");
|
||||
|
||||
final EditText input = (EditText) view.findViewById(R.id.dialog_nickname_input);
|
||||
input.setHint("");
|
||||
input.setSelection(input.getText().length());
|
||||
|
||||
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
String nickname = input.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(nickname)) {
|
||||
Toast.makeText(VoteActivity.this, "请输入名字", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
dialog.dismiss();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// 取消按钮
|
||||
TextView cancel = (TextView) view.findViewById(R.id.dialog_nickname_cannel);
|
||||
cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
// 确定按钮
|
||||
TextView confirm = (TextView) view.findViewById(R.id.dialog_nickname_confirm);
|
||||
confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String nickname = input.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(nickname)) {
|
||||
Toast.makeText(VoteActivity.this, "请输入名字", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
InputMethodManager imm = (InputMethodManager) VoteActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) VoteActivity.this
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(input, InputMethodManager.SHOW_FORCED);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
@ -105,7 +105,7 @@ public class WebActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onReceivedTitle(WebView view, String title) {
|
||||
super.onReceivedTitle(view, title);
|
||||
if (TextUtils.isEmpty(newsId)) {
|
||||
if (TextUtils.isEmpty(newsId) && TextUtils.isEmpty(newsTitle.getText().toString())) {
|
||||
newsTitle.setEllipsize(TextUtils.TruncateAt.END);
|
||||
newsTitle.setPadding(DisplayUtils.dip2px(getApplication(), 30), 0,DisplayUtils.dip2px(getApplication(), 30), 0);
|
||||
newsTitle.setSingleLine();
|
||||
@ -117,9 +117,9 @@ public class WebActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
progressBar.setProgress(newProgress);
|
||||
if (newProgress == 100 && newsId != null){
|
||||
if (newProgress == 100){
|
||||
progressBar.setVisibility(View.GONE);
|
||||
if (newsBottom.getVisibility() == View.GONE) {
|
||||
if (newsBottom.getVisibility() == View.GONE && newsId != null) {
|
||||
newsBottom.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -43,6 +43,7 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon
|
||||
private String shareNewsTitle; // shareNewsTitle不为空就是新闻分享,否则是游戏分享
|
||||
|
||||
private boolean isPlugin;
|
||||
private boolean ispopupWindow;
|
||||
|
||||
private IWeiboShareAPI mWeiboShareAPI;
|
||||
|
||||
@ -55,6 +56,7 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon
|
||||
shareIcon = extras.getString("shareIcon");
|
||||
shareNewsTitle = extras.getString("shareNewsTitle");
|
||||
isPlugin = extras.getBoolean("isPlugin");
|
||||
ispopupWindow = extras.getBoolean("ispopupWindow");
|
||||
|
||||
Utils.toast(this, "分享跳转中...");
|
||||
|
||||
@ -94,17 +96,21 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon
|
||||
protected void onNewResultImpl(Bitmap bitmap) {
|
||||
Utils.log("分享获取bitmap成功,准备分享");
|
||||
|
||||
Bitmap bgBitmap = ShareUtils.getInstance(getApplication()).addBackGround(bitmap);
|
||||
Bitmap bgBitmap = ShareUtils.getInstance(WeiBoShareActivity.this).addBackGround(bitmap);
|
||||
|
||||
TextObject textObject = new TextObject();
|
||||
if (shareNewsTitle != null){
|
||||
textObject.text = shareNewsTitle + "@光环助手";
|
||||
}else {
|
||||
if (isPlugin){
|
||||
textObject.text ="向你推荐:" + shareGameName + "(光环加速版)" + " @光环助手 ";
|
||||
if (ispopupWindow) {
|
||||
if (shareNewsTitle != null){
|
||||
textObject.text = shareNewsTitle + "@光环助手";
|
||||
}else {
|
||||
textObject.text ="向你推荐:" + shareGameName + " @光环助手 " ;
|
||||
if (isPlugin){
|
||||
textObject.text ="向你推荐:" + shareGameName + "(光环加速版)" + " @光环助手 ";
|
||||
}else {
|
||||
textObject.text ="向你推荐:" + shareGameName + " @光环助手 " ;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
textObject.text = "这个App可以下载各种热门卡牌手游的加速版,绿色安全,超级省心,做日常效率提高3-5倍!不用肝的感觉真好! @光环助手";
|
||||
}
|
||||
|
||||
ImageObject imageObject = new ImageObject();
|
||||
|
||||
383
app/src/main/java/com/gh/gamecenter/adapter/CleanApkAdapter.java
Normal file
383
app/src/main/java/com/gh/gamecenter/adapter/CleanApkAdapter.java
Normal file
@ -0,0 +1,383 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.common.util.BitmapUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.CleanApkActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.KcSelectGameViewHolder;
|
||||
import com.gh.gamecenter.entity.InstallGameEntity;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/24.
|
||||
*/
|
||||
public class CleanApkAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private CheckBox mApkSelectAll;
|
||||
|
||||
private TextView mApkDeleteBtn;
|
||||
|
||||
private List<InstallGameEntity> mApkList;
|
||||
|
||||
private OnScanListener scanListener;
|
||||
|
||||
private ArrayMap<Integer, Boolean> mSelectPosition;
|
||||
|
||||
private List<String> mApkPath;
|
||||
|
||||
private static int INSTALLED = 0; // 表示已经安装
|
||||
private static int UNINSTALLED = 1; // 表示未安装
|
||||
|
||||
private int cardMargin;
|
||||
|
||||
private boolean isStopScan;
|
||||
|
||||
private boolean isScanOver;
|
||||
|
||||
|
||||
Handler handler = new Handler();
|
||||
|
||||
public CleanApkAdapter(CleanApkActivity activity, TextView apkDeleteBtn, CheckBox apkSelectAll) {
|
||||
this.mContext = activity;
|
||||
this.mApkDeleteBtn = apkDeleteBtn;
|
||||
this.mApkSelectAll = apkSelectAll;
|
||||
|
||||
scanListener = activity;
|
||||
|
||||
mApkList = new ArrayList<>();
|
||||
mSelectPosition = new ArrayMap<>();
|
||||
mApkPath = new ArrayList<>();
|
||||
isStopScan = false;
|
||||
isScanOver = false;
|
||||
|
||||
cardMargin = (int) mContext.getResources().getDimension(R.dimen.cardview_margin);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 扫描和获取apk数据 分步操作 尽量避免 StackoverflowError
|
||||
FindAllAPKPath(Environment.getExternalStorageDirectory());
|
||||
LoadApkData();
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
isScanOver = true;
|
||||
scanListener.onScanOver();
|
||||
if (mApkList.size() == 0) {
|
||||
scanListener.noData();
|
||||
}
|
||||
notifyItemRangeChanged(0, getItemCount());
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据apk文件路径检查可用的apk和获取apk数据
|
||||
*/
|
||||
private void LoadApkData() {
|
||||
for (String apk_path : mApkPath) {
|
||||
InstallGameEntity apkEntity = new InstallGameEntity();
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
PackageInfo packageInfo = pm.getPackageArchiveInfo(apk_path, PackageManager.GET_ACTIVITIES);
|
||||
if (packageInfo == null) continue;
|
||||
|
||||
ApplicationInfo appInfo = packageInfo.applicationInfo;
|
||||
|
||||
|
||||
/**获取apk的图标 */
|
||||
appInfo.sourceDir = apk_path;
|
||||
appInfo.publicSourceDir = apk_path;
|
||||
Drawable apk_icon = appInfo.loadIcon(pm);
|
||||
apkEntity.setGameBm(BitmapUtils.drawableToBitmap(apk_icon));
|
||||
/** apk的绝对路劲 */
|
||||
apkEntity.setGamePath(apk_path);
|
||||
/** apk的版本名称 String */
|
||||
String versionName = packageInfo.versionName;
|
||||
apkEntity.setGameVersion(versionName);
|
||||
|
||||
String apkName = packageInfo.applicationInfo.loadLabel(pm).toString();
|
||||
apkEntity.setGameName(apkName);
|
||||
|
||||
File file = new File(apk_path);
|
||||
apkEntity.setGameSize(file.length());
|
||||
|
||||
/**安装处理类型*/
|
||||
/** 得到包名 */
|
||||
String packageName = packageInfo.packageName;
|
||||
int type = doType(pm, packageName);
|
||||
apkEntity.setInstallStatus(type);
|
||||
|
||||
mApkList.add(apkEntity);
|
||||
mSelectPosition.put((mApkList.size() - 1), false);
|
||||
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
notifyItemChanged((mApkList.size() - 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描内存卡 获取apk文件路径
|
||||
* @param file 文件路径
|
||||
*/
|
||||
public void FindAllAPKPath(File file) {
|
||||
|
||||
if (isStopScan) {
|
||||
return;
|
||||
}
|
||||
if (file.isFile()) {
|
||||
// Utils.log("===== 是文件" + file.getAbsolutePath().toString());
|
||||
String name_s = file.getName();
|
||||
String apk_path = null;
|
||||
if (name_s.toLowerCase().endsWith(".apk")) {
|
||||
apk_path = file.getAbsolutePath();// apk文件的绝对路劲
|
||||
mApkPath.add(apk_path);
|
||||
}
|
||||
} else {
|
||||
// Utils.log("===== 是文件夹" + file.getAbsolutePath().toString());
|
||||
File[] files = file.listFiles();
|
||||
if (files != null && files.length > 0) {
|
||||
for (File file_str : files) {
|
||||
FindAllAPKPath(file_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int doType(PackageManager pm, String packageName) {
|
||||
List<PackageInfo> pakageinfos = pm.getInstalledPackages(0);
|
||||
for (PackageInfo pi : pakageinfos) {
|
||||
if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
|
||||
String pi_packageName = pi.packageName;
|
||||
//如果这个包名在系统已经安装过的应用中存在
|
||||
if(packageName.endsWith(pi_packageName)){
|
||||
return INSTALLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return UNINSTALLED;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.kc_game_select_item, parent, false);
|
||||
return new KcSelectGameViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
|
||||
final InstallGameEntity gameEntity = mApkList.get(position);
|
||||
if (viewHolder instanceof KcSelectGameViewHolder) {
|
||||
final KcSelectGameViewHolder holder = (KcSelectGameViewHolder) viewHolder;
|
||||
// // 第一个
|
||||
// if (position == 0) {
|
||||
// ((CardLinearLayout) holder.itemView).setmTop(cardMargin);
|
||||
// } else {
|
||||
// ((CardLinearLayout) holder.itemView).setmTop(0);
|
||||
// }
|
||||
//
|
||||
// // 最后一个
|
||||
// if (position == mApkList.size() - 1) {
|
||||
// ((CardLinearLayout) holder.itemView).setBottom(true);
|
||||
// } else {
|
||||
// ((CardLinearLayout) holder.itemView).setBottom(false);
|
||||
// }
|
||||
|
||||
double size = (((float)gameEntity.getGameSize()/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
String sizeName = df.format(size) + "MB";
|
||||
|
||||
// Spanned spanned = Html.fromHtml("大小:" + "<font color=\"#00B7FA\">" + sizeName + "</font>");
|
||||
// holder.gameSize.setText(spanned);
|
||||
holder.checkBoxRl.setVisibility(View.VISIBLE);
|
||||
holder.selectCB.setVisibility(View.VISIBLE);
|
||||
if (mSelectPosition.get(position)) {
|
||||
holder.selectCB.setChecked(true);
|
||||
} else {
|
||||
holder.selectCB.setChecked(false);
|
||||
}
|
||||
|
||||
Utils.log(gameEntity.getGamePath() + "=========" + gameEntity.getGameName());
|
||||
holder.gameNameAndSize.setText(gameEntity.getGameName());
|
||||
holder.gameDes.setText("版本:V" + gameEntity.getGameVersion() + " | " + sizeName);
|
||||
holder.gameDes.setTextColor(mContext.getResources().getColor(R.color.content));
|
||||
|
||||
holder.gameThumb.setImageBitmap(gameEntity.getGameBm());
|
||||
|
||||
if (gameEntity.getInstallStatus() == INSTALLED) {
|
||||
holder.gameSize.setText("已安装");
|
||||
holder.gameSize.setTextColor(mContext.getResources().getColor(R.color.theme));
|
||||
} else {
|
||||
holder.gameSize.setText("未安装");
|
||||
holder.gameSize.setTextColor(Color.parseColor("#ff4147"));
|
||||
}
|
||||
|
||||
if (isScanOver) {
|
||||
holder.selectCB.setEnabled(true);
|
||||
} else {
|
||||
holder.selectCB.setEnabled(false);
|
||||
}
|
||||
|
||||
holder.checkBoxRl.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mSelectPosition.get(position)) {
|
||||
checkBoxControl(false, position);
|
||||
holder.selectCB.setChecked(false);
|
||||
} else {
|
||||
checkBoxControl(true, position);
|
||||
holder.selectCB.setChecked(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
holder.selectCB.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mSelectPosition.get(position)) {
|
||||
checkBoxControl(false, position);
|
||||
holder.selectCB.setChecked(false);
|
||||
} else {
|
||||
checkBoxControl(true, position);
|
||||
holder.selectCB.setChecked(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isScanOver) {
|
||||
PackageUtils.launchSetup(mContext, gameEntity.getGamePath());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public void checkBoxControl(boolean isChecked, int position) {
|
||||
if (isChecked) {
|
||||
mSelectPosition.put(position, true);
|
||||
} else {
|
||||
mSelectPosition.put(position, false);
|
||||
}
|
||||
|
||||
long gameSize = 0;
|
||||
int i = 0;
|
||||
|
||||
if (mApkList.size() == 0) return;
|
||||
for (Integer integer : mSelectPosition.keySet()) {
|
||||
if (mSelectPosition.get(integer)) {
|
||||
gameSize = gameSize + mApkList.get(integer).getGameSize();
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == mApkList.size()) {
|
||||
mApkSelectAll.setChecked(true);
|
||||
} else {
|
||||
mApkSelectAll.setChecked(false);
|
||||
}
|
||||
|
||||
if (gameSize == 0) {
|
||||
mApkDeleteBtn.setText("一键删除");
|
||||
} else {
|
||||
double size = (((float)gameSize/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String sizeName = df.format(size) + "MB";
|
||||
mApkDeleteBtn.setText("一键删除("+ i + "个,释放" + sizeName +")");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mApkList.size();
|
||||
}
|
||||
|
||||
public List<InstallGameEntity> getApkList() {
|
||||
return mApkList;
|
||||
}
|
||||
|
||||
public ArrayMap<Integer, Boolean> getSelectPosition() {
|
||||
return mSelectPosition;
|
||||
}
|
||||
|
||||
public void setSelectPosition(ArrayMap<Integer, Boolean> selectPosition) {
|
||||
this.mSelectPosition = selectPosition;
|
||||
}
|
||||
|
||||
public void isStopScan () {
|
||||
this.isStopScan = true;
|
||||
}
|
||||
|
||||
public void deleteApk(int position) {
|
||||
mApkList.remove(position);
|
||||
|
||||
Iterator<Map.Entry<Integer, Boolean>> iterator = mSelectPosition.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<Integer, Boolean> entry = iterator.next();
|
||||
Integer key = entry.getKey();
|
||||
|
||||
if (key == position) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
ArrayMap<Integer, Boolean> newMap = new ArrayMap<>(mSelectPosition);
|
||||
for (Integer integer : newMap.keySet()) {
|
||||
if (integer > position) {
|
||||
int newPosition = integer - 1;
|
||||
mSelectPosition.put(newPosition, mSelectPosition.get(integer));
|
||||
}
|
||||
}
|
||||
|
||||
if (mSelectPosition.size() > mApkList.size()) {
|
||||
mSelectPosition.removeAt(mSelectPosition.size() - 1);
|
||||
}
|
||||
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
|
||||
public interface OnScanListener {
|
||||
void onScanOver();
|
||||
void noData();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,259 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.ItemViewType;
|
||||
import com.gh.common.util.CommentUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.PostCommentUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.CommentViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.db.CommentDao;
|
||||
import com.gh.gamecenter.db.VoteDao;
|
||||
import com.gh.gamecenter.db.info.VoteInfo;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/22.
|
||||
*/
|
||||
public class CommentDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private SharedPreferences sp;
|
||||
|
||||
private List<CommentEntity> mCommentList;
|
||||
|
||||
private VoteDao mVoteDao;
|
||||
private CommentDao mCommentDao;
|
||||
|
||||
private String userName; //用户名
|
||||
private String userIcon; //用户icon
|
||||
|
||||
private String commentId;
|
||||
|
||||
private boolean isOver;
|
||||
private boolean isLoading;
|
||||
private boolean isNetworkError;
|
||||
|
||||
public CommentDetailAdapter(Context context, String commentId) {
|
||||
this.mContext = context;
|
||||
this.commentId = commentId;
|
||||
|
||||
mVoteDao = new VoteDao(context);
|
||||
mCommentDao = new CommentDao(context);
|
||||
|
||||
sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
userName = sp.getString("user_name", null);
|
||||
userIcon = sp.getString("user_icon", null);
|
||||
|
||||
mCommentList = new ArrayList<>();
|
||||
|
||||
loadData(0);
|
||||
}
|
||||
|
||||
public void loadData(int offset) {
|
||||
isLoading = true;
|
||||
RetrofitManager.getComment()
|
||||
.getCommentTrace(commentId, 20, offset)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<CommentEntity>>(){
|
||||
@Override
|
||||
public void onResponse(List<CommentEntity> response) {
|
||||
super.onResponse(response);
|
||||
mCommentList.addAll(response);
|
||||
|
||||
if (response.size() < 20) {
|
||||
isOver = true;
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
notifyItemRangeChanged(0, getItemCount() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
Utils.toast(mContext, "评论加载失败, 请检查网络设置");
|
||||
isNetworkError = true;
|
||||
isLoading = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == getItemCount() - 1) {
|
||||
return ItemViewType.LOADING;
|
||||
}
|
||||
|
||||
return 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == ItemViewType.LOADING) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.refresh_footerview, parent, false);
|
||||
return new FooterViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.comment_item, parent, false);
|
||||
return new CommentViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof CommentViewHolder) {
|
||||
initCommentViewHolder((CommentViewHolder) holder, position);
|
||||
} else if (holder instanceof FooterViewHolder) {
|
||||
initFooterViewHolder((FooterViewHolder) holder);
|
||||
}
|
||||
}
|
||||
|
||||
private void initFooterViewHolder(FooterViewHolder holder) {
|
||||
if(isNetworkError) {
|
||||
holder.loading.setVisibility(View.GONE);
|
||||
holder.hint.setText("网络错误,点击重试!");
|
||||
}else if (!isOver) {
|
||||
holder.hint.setText("加载中...");
|
||||
holder.loading.setVisibility(View.VISIBLE);
|
||||
} else if (mCommentList.size() == 0) {
|
||||
holder.loading.setVisibility(View.GONE);
|
||||
holder.hint.setText("目前还没有评论");
|
||||
} else {
|
||||
holder.hint.setText("没有更多评论啦");
|
||||
holder.loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initCommentViewHolder(final CommentViewHolder holder, int position) {
|
||||
final CommentEntity commentEntity = mCommentList.get(position);
|
||||
|
||||
ImageUtils.display(holder.commentUserIconDv, commentEntity.getUser().getIcon());
|
||||
|
||||
holder.commentLikeCountTv.setTextColor(mContext.getResources().getColor(R.color.hint));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.ic_like_unselect);
|
||||
|
||||
if (commentEntity.getVote() == 0) {
|
||||
holder.commentLikeCountTv.setVisibility(View.GONE);
|
||||
} else { // 检查是否已点赞
|
||||
if (mVoteDao.isVote(commentEntity.getId()) && commentEntity.getVote() >= 1) {
|
||||
holder.commentLikeCountTv.setTextColor(mContext.getResources().getColor(R.color.theme));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.ic_like_select);
|
||||
}
|
||||
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
holder.commentLikeCountTv.setText(String.valueOf(commentEntity.getVote()));
|
||||
}
|
||||
|
||||
//检查是否是自身评论
|
||||
if (userName != null && userIcon != null && !userIcon.isEmpty()&&
|
||||
!userIcon.isEmpty() && mCommentDao.isMyComment(commentEntity.getId())){
|
||||
holder.commentUserNameTv.setText(sp.getString("user_name", null));
|
||||
ImageUtils.display(holder.commentUserIconDv, sp.getString("user_icon", null));
|
||||
} else {
|
||||
holder.commentUserNameTv.setText(commentEntity.getUser().getName());
|
||||
if(commentEntity.getUser().getIcon().isEmpty()) {
|
||||
holder.commentUserIconDv.setImageURI(Uri.parse("res:///" + R.drawable.user_default_icon_comment));
|
||||
} else {
|
||||
ImageUtils.display(holder.commentUserIconDv, commentEntity.getUser().getIcon());
|
||||
}
|
||||
}
|
||||
|
||||
CommentUtils.setCommentTime(holder.commentTimeTv, commentEntity.getTime());
|
||||
if (commentEntity.getParent() != null) {
|
||||
holder.commentContentTv.setText("@"+ commentEntity.getParent().getUser().getName() + ": " + commentEntity.getContent());
|
||||
} else {
|
||||
holder.commentContentTv.setText(commentEntity.getContent());
|
||||
}
|
||||
|
||||
holder.commentLikeIv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (holder.commentLikeCountTv.getCurrentTextColor() == mContext.getResources().getColor(R.color.theme)) {
|
||||
Utils.toast(mContext, "已经点过赞啦!");
|
||||
return;
|
||||
}
|
||||
commentEntity.setVote(commentEntity.getVote() + 1);
|
||||
holder.commentLikeCountTv.setTextColor(mContext.getResources().getColor(R.color.theme));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.ic_like_select);
|
||||
holder.commentLikeCountTv.setText(String.valueOf(commentEntity.getVote()));
|
||||
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
|
||||
PostCommentUtils.addCommentVoto(mContext, commentEntity.getId(), true,
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSucced(JSONObject response) {
|
||||
mVoteDao.add(new VoteInfo(commentEntity.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable error) {
|
||||
commentEntity.setVote(commentEntity.getVote() - 1);
|
||||
holder.commentLikeCountTv.setTextColor(mContext.getResources().getColor(R.color.hint));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.ic_like_unselect);
|
||||
holder.commentLikeCountTv.setText(String.valueOf(commentEntity.getVote()));
|
||||
if (commentEntity.getVote() == 0) {
|
||||
holder.commentLikeCountTv.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (error instanceof HttpException) {
|
||||
HttpException exception = (HttpException) error;
|
||||
if (exception.code() == 403) {
|
||||
try {
|
||||
if (new JSONObject(exception.response().errorBody().string())
|
||||
.getString("detail").equals("voted")) {
|
||||
Utils.toast(mContext, "已经点过赞啦!");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
Utils.toast(mContext, "网络异常,点赞失败");
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mCommentList.size() + 1;
|
||||
}
|
||||
|
||||
public boolean isOver() {
|
||||
return isOver;
|
||||
}
|
||||
|
||||
public boolean isLoading() {
|
||||
return isLoading;
|
||||
}
|
||||
}
|
||||
@ -2,15 +2,9 @@ package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.*;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.*;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.ConcernViewHolder;
|
||||
@ -20,16 +14,12 @@ import com.gh.gamecenter.listener.OnCallBackListener;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/20.
|
||||
*
|
||||
@ -64,6 +54,14 @@ public class ConcernAdapter extends RecyclerView.Adapter<ConcernViewHolder> {
|
||||
}
|
||||
|
||||
private void initConcernGame() {
|
||||
|
||||
// 按时间排序
|
||||
Collections.sort(concernList, new Comparator<ConcernInfo>() {
|
||||
@Override
|
||||
public int compare(ConcernInfo lhs, ConcernInfo rhs) {
|
||||
return String.valueOf(rhs.getTime()).compareTo(String.valueOf(lhs.getTime()));
|
||||
}
|
||||
});
|
||||
final List<GameEntity> result = new ArrayList<>();
|
||||
List<Observable<GameEntity>> sequences = new ArrayList<>();
|
||||
for (ConcernInfo concernInfo : concernList) {
|
||||
@ -108,6 +106,19 @@ public class ConcernAdapter extends RecyclerView.Adapter<ConcernViewHolder> {
|
||||
@Override
|
||||
public void onBindViewHolder(final ConcernViewHolder holder, int position) {
|
||||
ConcernInfo concernInfo = concernList.get(position);
|
||||
// holder.concern_item_icon.setImageURI(concernInfo.getIcon());
|
||||
ImageUtils.display(holder.concern_item_icon, concernInfo.getIcon());
|
||||
|
||||
if (concernGameList != null) {
|
||||
GameEntity gameEntity = concernGameList.get(position);
|
||||
|
||||
if (gameEntity.isLibaoExists()) {
|
||||
holder.concern_libao_icon.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.concern_libao_icon.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
// ImageUtils.getInstance(context).display(concernInfo.getIcon(), holder.concern_item_icon);
|
||||
holder.concern_item_icon.setImageURI(concernInfo.getIcon());
|
||||
holder.concern_item_name.setText(concernInfo.getGameName());
|
||||
|
||||
@ -10,6 +10,7 @@ import android.widget.Toast;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.ConcernViewHolder;
|
||||
@ -128,8 +129,17 @@ public class ConcernRecommendAdapter extends RecyclerView.Adapter<ConcernViewHol
|
||||
@Override
|
||||
public void onBindViewHolder(final ConcernViewHolder holder, int position) {
|
||||
GameEntity gameEntity = recommendGameList.get(position);
|
||||
// holder.concern_item_icon.setImageURI(gameEntity.getIcon());
|
||||
ImageUtils.display(holder.concern_item_icon, gameEntity.getIcon());
|
||||
// ImageUtils.getInstance(context).display(
|
||||
// gameEntity.getIcon(), holder.concern_item_icon);
|
||||
|
||||
if (gameEntity.isLibaoExists()) {
|
||||
holder.concern_libao_icon.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.concern_libao_icon.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
holder.concern_item_icon.setImageURI(gameEntity.getIcon());
|
||||
holder.concern_item_name.setText(gameEntity.getName());
|
||||
holder.concern_item_concern.setText("关注");
|
||||
|
||||
@ -0,0 +1,181 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Environment;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.SpeedUtils;
|
||||
import com.gh.gamecenter.FileReceiverActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.KcSelectGameViewHolder;
|
||||
import com.gh.gamecenter.kuaichuan.FileInfo;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/1/22.
|
||||
*/
|
||||
public class FileReceiverAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context mContext;
|
||||
private List<FileInfo> mFileInfos;
|
||||
|
||||
private long lastProgress;
|
||||
|
||||
private OnReceiverCancelListener cancelListener;
|
||||
|
||||
|
||||
public FileReceiverAdapter(FileReceiverActivity activity, List<FileInfo> infos) {
|
||||
this.mContext = activity;
|
||||
this.cancelListener = activity;
|
||||
|
||||
mFileInfos = infos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*/
|
||||
public void update(){
|
||||
// mFileInfos = (List<FileInfo>) AppController.get("FileInfo", false);
|
||||
notifyItemRangeChanged(0, getItemCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.kc_game_select_item, parent, false);
|
||||
return new KcSelectGameViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
final FileInfo fileInfo = mFileInfos.get(position);
|
||||
|
||||
if (holder instanceof KcSelectGameViewHolder) {
|
||||
final KcSelectGameViewHolder viewHolder = (KcSelectGameViewHolder) holder;
|
||||
viewHolder.gameNameAndSize.setText(fileInfo.getName());
|
||||
viewHolder.downloadStatus.setVisibility(View.VISIBLE);
|
||||
viewHolder.sendOverIcon.setVisibility(View.GONE);
|
||||
viewHolder.gameProgressbar.setMax(100);
|
||||
viewHolder.gameProgressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.gameLlInfo.setVisibility(View.VISIBLE);
|
||||
viewHolder.gameSize.setVisibility(View.GONE);
|
||||
viewHolder.gameNameAndSize.setPadding(0, 0, 0, DisplayUtils.dip2px(mContext, 5));
|
||||
if (fileInfo.getBitmap() != null) {
|
||||
viewHolder.gameThumb.setImageBitmap(fileInfo.getBitmap());
|
||||
} else {
|
||||
viewHolder.gameThumb.setImageResource(R.drawable.ocupy);
|
||||
}
|
||||
|
||||
viewHolder.downloadSpeed.setText("等待中");
|
||||
viewHolder.downloadSpeed.setTextColor(mContext.getResources().getColor(R.color.content));
|
||||
viewHolder.gameProgressbar.setProgress(0);
|
||||
viewHolder.sendOverIcon.setVisibility(View.GONE);
|
||||
viewHolder.downloadStatus.setText("取消");
|
||||
viewHolder.downloadStatus.setTextColor(mContext.getResources().getColor(R.color.content));
|
||||
viewHolder.downloadStatus.setBackgroundResource(R.drawable.kuaichuan_cancel_bg);
|
||||
|
||||
int percent = (int)(fileInfo.getProgress() * 100 / fileInfo.getSize());
|
||||
viewHolder.downloadPercentage.setText(percent + "%");
|
||||
|
||||
if (fileInfo.getResult() == FileInfo.FLAG_SUCCESS || fileInfo.getResult() == FileInfo.FLAG_INSTALLED) { // 传输完成...
|
||||
viewHolder.gameProgressbar.setProgress(100);
|
||||
viewHolder.downloadPercentage.setText("100%");
|
||||
|
||||
if (fileInfo.getResult() == FileInfo.FLAG_SUCCESS) {
|
||||
viewHolder.downloadStatus.setText("安装");
|
||||
viewHolder.downloadStatus.setTextColor(Color.WHITE);
|
||||
viewHolder.downloadStatus.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
} else {
|
||||
viewHolder.downloadStatus.setText("已安装");
|
||||
viewHolder.downloadStatus.setTextColor(mContext.getResources().getColor(R.color.theme));
|
||||
viewHolder.downloadStatus.setBackgroundDrawable(new ColorDrawable(0));
|
||||
}
|
||||
|
||||
double size = (((float)fileInfo.getSize()/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String sizeName = df.format(size) + "MB";
|
||||
viewHolder.downloadSpeed.setTextColor(mContext.getResources().getColor(R.color.content));
|
||||
viewHolder.downloadSpeed.setText(sizeName + "/" + sizeName);
|
||||
} else if (fileInfo.getResult() == FileInfo.FLAG_FAILURE || fileInfo.getResult() == FileInfo.FLAG_NO_MEMORY) { // 传输失败...
|
||||
double sizeMb = (((float)fileInfo.getSize()/1024)/1024);
|
||||
double curSizeMb = (((float)fileInfo.getProgress()/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String sizeName = df.format(sizeMb) + "MB";
|
||||
String curSizeName = df.format(curSizeMb) + "MB";
|
||||
viewHolder.downloadSpeed.setTextColor(mContext.getResources().getColor(R.color.content));
|
||||
viewHolder.downloadSpeed.setText(curSizeName + "/" + sizeName);
|
||||
viewHolder.downloadStatus.setTextColor(mContext.getResources().getColor(R.color.type_huodong));
|
||||
viewHolder.downloadStatus.setBackgroundDrawable(new ColorDrawable(0));
|
||||
viewHolder.gameProgressbar.setProgress(percent);
|
||||
// viewHolder.downloadPercentage.setText(percent + "%");
|
||||
if (fileInfo.getResult() == FileInfo.FLAG_FAILURE) {
|
||||
viewHolder.downloadStatus.setText("传输失败");
|
||||
} else {
|
||||
viewHolder.downloadStatus.setText("空间不足");
|
||||
}
|
||||
} else if (fileInfo.getResult() == FileInfo.FLAG_CANCEL) { // 取消传输
|
||||
double sizeMb = (((float)fileInfo.getSize()/1024)/1024);
|
||||
double curSizeMb = (((float)fileInfo.getProgress()/1024)/1024);
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String sizeName = df.format(sizeMb) + "MB";
|
||||
String curSizeName = df.format(curSizeMb) + "MB";
|
||||
viewHolder.downloadSpeed.setTextColor(mContext.getResources().getColor(R.color.content));
|
||||
viewHolder.downloadSpeed.setText(curSizeName + "/" + sizeName);
|
||||
viewHolder.downloadStatus.setText("已取消");
|
||||
viewHolder.downloadStatus.setBackgroundDrawable(new ColorDrawable(0));
|
||||
|
||||
viewHolder.gameProgressbar.setProgress(percent);
|
||||
// viewHolder.downloadPercentage.setText(percent + "%");
|
||||
} else if (fileInfo.getResult() == FileInfo.FLAG_DEFAULT){ // 传输中...
|
||||
viewHolder.gameProgressbar.setProgress(percent);
|
||||
viewHolder.downloadStatus.setText("取消");
|
||||
viewHolder.downloadStatus.setTextColor(mContext.getResources().getColor(R.color.content));
|
||||
viewHolder.downloadStatus.setBackgroundResource(R.drawable.kuaichuan_cancel_bg);
|
||||
|
||||
long speed = (fileInfo.getProgress() - lastProgress) / 1024;
|
||||
if (speed < 0) {
|
||||
speed = 0;
|
||||
}
|
||||
|
||||
// viewHolder.downloadPercentage.setText(percent + "%");
|
||||
viewHolder.downloadSpeed.setTextColor(mContext.getResources().getColor(R.color.theme));
|
||||
viewHolder.downloadSpeed.setText(String.format("%s(剩%s)",
|
||||
SpeedUtils.getSpeed(speed),
|
||||
SpeedUtils.getRemainTime(fileInfo.getSize(), fileInfo.getProgress(), speed * 1024)));
|
||||
lastProgress = fileInfo.getProgress();
|
||||
}
|
||||
|
||||
viewHolder.downloadStatus.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String s = viewHolder.downloadStatus.getText().toString();
|
||||
if ("取消".equals(s)) {
|
||||
cancelListener.OnCancelPosition(position);
|
||||
} else if ("安装".equals(s)) {
|
||||
PackageUtils.launchSetup(mContext, Environment.getExternalStorageDirectory() + "/GH-KC/" + fileInfo.getName() + ".apk");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mFileInfos == null) {
|
||||
return 0;
|
||||
}
|
||||
return mFileInfos.size();
|
||||
}
|
||||
|
||||
public interface OnReceiverCancelListener {
|
||||
void OnCancelPosition(int position);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user