Compare commits
235 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de3ab708e9 | |||
| 52f2dd22f2 | |||
| 8aa90935d8 | |||
| b8ae608d79 | |||
| 15070aab45 | |||
| 9fb2da406a | |||
| 4488726b12 | |||
| 6ade459c40 | |||
| 47914f94ac | |||
| e5e6a07e24 | |||
| dda8fe032c | |||
| 09a0eabc48 | |||
| 6546b580e9 | |||
| 93521840bc | |||
| 5f2b84d88c | |||
| 794784e253 | |||
| 96bfeda954 | |||
| ada909ec8a | |||
| 5064a76aa5 | |||
| 20cc2f478f | |||
| f818e4033d | |||
| 0736fc6b91 | |||
| 7bef401e6a | |||
| ea51e5e443 | |||
| eccc0eb167 | |||
| afa3f1d705 | |||
| ce94de1214 | |||
| 3d3b596962 | |||
| b42e0df218 | |||
| 7da78b6e4a | |||
| 0b63f8d4a2 | |||
| 1aa9ddbb48 | |||
| 5e44460112 | |||
| 39350b2cfb | |||
| 154f7b5a54 | |||
| 94adc2c922 | |||
| 80e8ca0c36 | |||
| 358a3f84e6 | |||
| 7629d9f429 | |||
| da87e974f4 | |||
| 6cd2397b27 | |||
| d053fc9fea | |||
| 979a4b808b | |||
| bdfda12d68 | |||
| c8211dbdd8 | |||
| 4a0332a948 | |||
| c17f13d467 | |||
| 9efa6f163d | |||
| 560dee201f | |||
| f6371537ed | |||
| 5a31813a45 | |||
| 384af8a9db | |||
| 186f594d1d | |||
| 497cd6a494 | |||
| 471afcf0be | |||
| 8724d3eff7 | |||
| 29ba7a512e | |||
| 9fbd5ee72b | |||
| ed867884b0 | |||
| 8019b22fc4 | |||
| 0bcef534d0 | |||
| 69033c0657 | |||
| 63c86bbacb | |||
| 251e19d751 | |||
| 12279501b4 | |||
| 3c512273f0 | |||
| 597651248a | |||
| a80c577f1f | |||
| a09c8e329a | |||
| 2174451e97 | |||
| ee562eb3b7 | |||
| 03e05b3e35 | |||
| 385a206f6b | |||
| 202a78526c | |||
| eb7fe78410 | |||
| e0f79490eb | |||
| 1acf79baae | |||
| 405056cbd3 | |||
| fc68b9add5 | |||
| d95d5d5e6b | |||
| 69d86affd0 | |||
| 9f5374f4fd | |||
| f858ba0b70 | |||
| b9a2374f8f | |||
| 73c0af47db | |||
| 72f62b595d | |||
| 5316164f00 | |||
| a14646d2e2 | |||
| 1135334a95 | |||
| 5462167d85 | |||
| b7c3856785 | |||
| 92ad0838e7 | |||
| ae405d54d5 | |||
| d9ea9cf1ba | |||
| 5c4a65d278 | |||
| cbc543b981 | |||
| a22f59aab6 | |||
| 9b7c5e7756 | |||
| e2591a54d6 | |||
| 9180089787 | |||
| bd892a4cf1 | |||
| 1dd895ebef | |||
| c416adc980 | |||
| 6737b17e43 | |||
| 3300d61a53 | |||
| defbbc7b44 | |||
| a77e1ebf61 | |||
| 6834be0909 | |||
| 9d3640f6b9 | |||
| 4e392eeb14 | |||
| 4ce778f76f | |||
| 160bb20eed | |||
| 27c73369da | |||
| 6cbb033326 | |||
| bfd31516ba | |||
| da664e5869 | |||
| cae1f78025 | |||
| 8b282eaf8a | |||
| b5b65ecd41 | |||
| 87b47a9c31 | |||
| 6dd0c75cdc | |||
| 5f3f2139c1 | |||
| ef97c913cf | |||
| b1df05ea47 | |||
| a270946ce2 | |||
| efc19441cd | |||
| 803ec482fb | |||
| dac71dfd55 | |||
| 85b7ebdcc7 | |||
| 800bc52c0e | |||
| d4498fb573 | |||
| 2bd6c38bf6 | |||
| 5dfbfe6cf5 | |||
| f47768b8db | |||
| 2ba951bb42 | |||
| 39733689c6 | |||
| c97bdbe203 | |||
| 6cfe7ff889 | |||
| d5763ddbd6 | |||
| 59ac399f9e | |||
| 094a96ab78 | |||
| 26b5d00a72 | |||
| 74e281b0c4 | |||
| c6bd6e4b0c | |||
| e3fc761414 | |||
| 16a65ffa93 | |||
| 63f0b0528c | |||
| 000c97881c | |||
| 20e9fcf172 | |||
| 04851d5df3 | |||
| 9c29be3378 | |||
| 9d1c5a1184 | |||
| 56f7fd9a31 | |||
| 8d9d28e1c9 | |||
| 47a14dfd40 | |||
| 9d0e0f4f2d | |||
| 2543736e82 | |||
| 84f8008167 | |||
| 11676bff83 | |||
| a7c9ec51ed | |||
| d077b6d880 | |||
| 4ce9e8be3f | |||
| b2ee32b4ab | |||
| 0b705bd311 | |||
| 9ae9f307bc | |||
| 83cbb60cb7 | |||
| 43d476786f | |||
| 322f13072c | |||
| 0861208b64 | |||
| e08b9469d0 | |||
| c9a7379847 | |||
| b211d15b17 | |||
| 99cfa2080f | |||
| 39fecb09a7 | |||
| 42cbb4f6ec | |||
| 335dac3481 | |||
| 24014feef0 | |||
| f74ae2a8cf | |||
| 8eca878a8b | |||
| 33ce47b438 | |||
| d2702c9d4a | |||
| cbc7a144a4 | |||
| a9f078865e | |||
| 18330df2f0 | |||
| b0e401bbbd | |||
| 1b03e434a7 | |||
| 87c5c5a0d8 | |||
| b915ea01be | |||
| f0f12cf8ff | |||
| 303f5b8f58 | |||
| bff4d80c27 | |||
| 7cbdf69188 | |||
| 58c6a9a5d5 | |||
| e0c08e94f3 | |||
| 15ad3e7d39 | |||
| 4ce8d1ea95 | |||
| 37af534904 | |||
| 8de6a6a789 | |||
| e033e20dbf | |||
| 42d0d9c60b | |||
| 5559a47f80 | |||
| c37c50d0c1 | |||
| 5b5341f9e1 | |||
| 848b4e44d5 | |||
| fa6cc8dfaf | |||
| 3c83b4ad5c | |||
| 6c3e042edc | |||
| 4feff1600e | |||
| e7f510941f | |||
| 2a4c8a01b9 | |||
| b3d6148c8c | |||
| d4dac2d681 | |||
| 02599ad7cc | |||
| bb790ad579 | |||
| 6ec976ccb6 | |||
| 84c30364fc | |||
| 8df31781e9 | |||
| 380d38073e | |||
| 78e295ce7e | |||
| 627a896ddb | |||
| 929f12fa18 | |||
| c0550746b1 | |||
| 602c30d87c | |||
| e7ff7a3083 | |||
| d86155383b | |||
| 4074ae5452 | |||
| bf87e7187d | |||
| 5c09b03d60 | |||
| b3b7641959 | |||
| b0a9a52288 | |||
| 35a915dda1 | |||
| 1210911a3a | |||
| b7bc0efe28 | |||
| b31131a00b | |||
| 228d0394c3 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,8 +1,8 @@
|
||||
/.idea
|
||||
.idea/misc.xml
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
/captures
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -37,7 +37,7 @@
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@ -3,6 +3,7 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/GH-ASSISTv1.45.iml" filepath="$PROJECT_DIR$/GH-ASSISTv1.45.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/GH-ASSISTv1.50.iml" filepath="$PROJECT_DIR$/GH-ASSISTv1.50.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/buildSrc/buildSrc.iml" filepath="$PROJECT_DIR$/buildSrc/buildSrc.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/hackdex/hackdex.iml" filepath="$PROJECT_DIR$/hackdex/hackdex.iml" />
|
||||
|
||||
@ -6,6 +6,9 @@ task('processWithJavassist') << {
|
||||
.absolutePath + '/intermediates/classes/debug')//第二个参数是hackdex的class所在目录
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出jar包
|
||||
*/
|
||||
task buildJar(dependsOn: ['compileReleaseJavaWithJavac'], type: Jar) {
|
||||
|
||||
baseName = "news"
|
||||
@ -31,15 +34,15 @@ task buildJar(dependsOn: ['compileReleaseJavaWithJavac'], type: Jar) {
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 19
|
||||
compileSdkVersion 21
|
||||
buildToolsVersion "23.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.gh.gamecenter"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 19
|
||||
versionCode 12
|
||||
versionName "1.46"
|
||||
targetSdkVersion 21
|
||||
versionCode 15
|
||||
versionName "2.0"
|
||||
|
||||
// 默认的渠道
|
||||
// manifestPlaceholders = [CHANNEL_VALUE: "GH_TEST"]
|
||||
@ -65,7 +68,7 @@ android {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
// signingConfig signingConfigs.release
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,22 +77,47 @@ android {
|
||||
// }
|
||||
|
||||
/**
|
||||
* 渠道打包
|
||||
* 多渠道打包
|
||||
*/
|
||||
// productFlavors {
|
||||
// "GH_200"{
|
||||
// manifestPlaceholders = [CHANNEL_VALUE: "GH_200"]
|
||||
// }
|
||||
// }
|
||||
// productFlavors {
|
||||
// GH_200 {}
|
||||
// }
|
||||
// productFlavors.all { flavor ->
|
||||
// flavor.manifestPlaceholders = [CHANNEL_VALUE: name]//命令 gradlew assembleRelease
|
||||
// }
|
||||
productFlavors {
|
||||
GH_100 {}
|
||||
GH_101 {}
|
||||
GH_102 {}
|
||||
GH_103 {}
|
||||
GH_104 {}
|
||||
GH_106 {}
|
||||
GH_107 {}
|
||||
GH_109 {}
|
||||
GH_110 {}
|
||||
GH_111 {}
|
||||
GH_113 {}
|
||||
GH_114 {}
|
||||
GH_115 {}
|
||||
GH_116 {}
|
||||
GH_118 {}
|
||||
GH_119 {}
|
||||
GH_120 {}
|
||||
GH_121 {}
|
||||
GH_123 {}
|
||||
GH_127 {}
|
||||
GH_200 {}
|
||||
GH_201 {}
|
||||
GH_202 {}
|
||||
GH_203 {}
|
||||
GH_204 {}
|
||||
GH_205 {}
|
||||
GH_222 {}
|
||||
GH_307 {}
|
||||
GH_TEST {}
|
||||
}
|
||||
productFlavors.all { flavor ->
|
||||
flavor.manifestPlaceholders = [CHANNEL_VALUE: name]//命令 gradlew assembleRelease
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.16'
|
||||
compile 'com.android.support:cardview-v7:21.0.0'
|
||||
}
|
||||
BIN
app/libs/ShareSDK-ShortMessage-2.7.2.jar
Normal file
BIN
app/libs/ShareSDK-ShortMessage-2.7.2.jar
Normal file
Binary file not shown.
BIN
app/libs/ShareSDK-Wechat-2.7.2.jar
Normal file
BIN
app/libs/ShareSDK-Wechat-2.7.2.jar
Normal file
Binary file not shown.
BIN
app/libs/libammsdk.jar
Normal file
BIN
app/libs/libammsdk.jar
Normal file
Binary file not shown.
BIN
app/libs/open_sdk_r5756.jar
Normal file
BIN
app/libs/open_sdk_r5756.jar
Normal file
Binary file not shown.
BIN
app/libs/utdid4all-1.0.4.jar
Normal file
BIN
app/libs/utdid4all-1.0.4.jar
Normal file
Binary file not shown.
@ -38,15 +38,6 @@
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<!-- 小米推送需要的权限 -->
|
||||
<uses-permission android:name="com.gh.gamecenter.permission.MIPUSH_RECEIVE" />
|
||||
<!-- 添加权限 -->
|
||||
<!-- 允许程序发送SMS短信 -->
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<!-- 允许程序监控一个将收到短信息,记录或处理 -->
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<!-- 允许程序读取短信息 -->
|
||||
<uses-permission android:name="android.permission.READ_SMS" />
|
||||
<!-- 请求访问使用照相设备 -->
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<permission
|
||||
android:name="com.gh.gamecenter.permission.MIPUSH_RECEIVE"
|
||||
@ -71,7 +62,9 @@
|
||||
android:value="81DB144D555386A38A70B833537EC256" />
|
||||
<meta-data
|
||||
android:name="TD_CHANNEL_ID"
|
||||
android:value="GH_200" />
|
||||
android:value="${CHANNEL_VALUE}"
|
||||
/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<!-- MTA -->
|
||||
<meta-data
|
||||
@ -79,7 +72,8 @@
|
||||
android:value="APV567FTBS7J"/>
|
||||
<meta-data
|
||||
android:name="InstallChannel"
|
||||
android:value="GH_127"/>
|
||||
android:value="${CHANNEL_VALUE}"/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SplashScreenActivity"
|
||||
@ -93,6 +87,52 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.MainActivity"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.DownloadManagerActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.ViewImageActivity"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SearchActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateVisible" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.GameDetailActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<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" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SubjectActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.PluginActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.NewsSearchActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.GameNewsActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.CropImageActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.mob.tools.MobUIShell"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
@ -109,53 +149,35 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".WXEntryActivity"
|
||||
android:name="com.gh.gamecenter.wxapi.WXEntryActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:exported="true"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.MainActivity"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait" />
|
||||
android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:scheme="sdksample"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- QQ 分享 -->
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.DownloadManagerActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
android:name="com.tencent.tauth.AuthActivity"
|
||||
android:launchMode="singleTask"
|
||||
android:noHistory="true" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="tencent1104659243" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.ViewImageActivity"
|
||||
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SearchActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateVisible" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.NewsOrRaidersActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.GameDetailsActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.NewsActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.GameActivity"
|
||||
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" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.HotCardActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.OriginalActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
android:name="com.tencent.connect.common.AssistActivity"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||
|
||||
<receiver android:name="com.gh.gamecenter.receiver.InstallAndUninstallReceiver" >
|
||||
<intent-filter>
|
||||
@ -216,20 +238,15 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name="com.xiaomi.push.service.receivers.PingReceiver"
|
||||
android:exported="false"
|
||||
android:process=":pushservice" >
|
||||
android:name="com.gh.gamecenter.receiver.ActivitySkipReceiver"
|
||||
android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="com.xiaomi.push.PING_TIMER" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name="com.gh.gamecenter.receiver.SmsReceiver" >
|
||||
<intent-filter android:priority="1000" >
|
||||
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
|
||||
<action android:name="com.gh.gamecenter.ACTIVITYSKIP" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service android:name="com.gh.download.DownloadService" />
|
||||
<service
|
||||
android:name="com.gh.download.DownloadService" />
|
||||
<service
|
||||
android:name="com.xiaomi.push.service.XMPushService"
|
||||
android:enabled="true"
|
||||
|
||||
@ -51,7 +51,6 @@
|
||||
Line http://media.line.me/zh-hant/
|
||||
Pocket http://getpocket.com/developer/apps/new
|
||||
-->
|
||||
|
||||
<ShareSDK
|
||||
AppKey = "6f286c8a261a"/> <!-- 修改成你在sharesdk后台注册的应用的appkey"-->
|
||||
|
||||
@ -85,9 +84,8 @@
|
||||
<!--
|
||||
Wechat微信和WechatMoments微信朋友圈的appid是一样的;
|
||||
|
||||
注意:开发者不能用我们这两个平台的appid,否则分享不了
|
||||
|
||||
微信测试的时候,微信测试需要先签名打包出apk,
|
||||
注意:开发者不能用我们这两个平台的appid,否则分享不了
|
||||
微信测试的时候,微信测试需要先签名打包出apk,
|
||||
sample测试微信,要先签名打包,keystore在sample项目中,密码123456
|
||||
|
||||
BypassApproval是绕过审核的标记,设置为true后AppId将被忽略,故不经过
|
||||
@ -97,24 +95,24 @@
|
||||
<Wechat
|
||||
Id="4"
|
||||
SortId="4"
|
||||
AppId="wx4868b35061f87885"
|
||||
AppSecret="64020361b8ec4c99936c0e3999a9f249"
|
||||
BypassApproval="true"
|
||||
AppId="wx3ffd0785fad18396"
|
||||
AppSecret="368b49e8471857575a033b206218f9fb"
|
||||
BypassApproval="false"
|
||||
Enable="true" />
|
||||
|
||||
<WechatMoments
|
||||
Id="5"
|
||||
SortId="5"
|
||||
AppId="wx4868b35061f87885"
|
||||
AppSecret="64020361b8ec4c99936c0e3999a9f249"
|
||||
BypassApproval="true"
|
||||
AppId="wx3ffd0785fad18396"
|
||||
AppSecret="368b49e8471857575a033b206218f9fb"
|
||||
BypassApproval="false"
|
||||
Enable="true" />
|
||||
|
||||
<WechatFavorite
|
||||
Id="6"
|
||||
SortId="6"
|
||||
AppId="wx4868b35061f87885"
|
||||
AppSecret="64020361b8ec4c99936c0e3999a9f249"
|
||||
AppId="wx3ffd0785fad18396"
|
||||
AppSecret="368b49e8471857575a033b206218f9fb"
|
||||
Enable="true" />
|
||||
|
||||
<!-- ShareByAppClient标识是否使用微博客户端分享,默认是false -->
|
||||
|
||||
@ -429,7 +429,9 @@ class AdapterHelper implements OpReorderer.Callback {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "postponing " + op);
|
||||
}
|
||||
// Utils.log("add UpdateOp to PostponedList");
|
||||
mPostponedList.add(op);
|
||||
// Utils.log("op" + op.positionStart + "=" + op.itemCount);
|
||||
switch (op.cmd) {
|
||||
case UpdateOp.ADD:
|
||||
mCallback.offsetPositionsForAdd(op.positionStart, op.itemCount);
|
||||
|
||||
@ -3296,10 +3296,16 @@ public class RecyclerView extends ViewGroup {
|
||||
}
|
||||
if (holder == null) {
|
||||
final int offsetPosition = mAdapterHelper.findPositionOffset(position);
|
||||
// final int offsetPosition = position;
|
||||
// Utils.log("offsetPosition position = " + position);
|
||||
// Utils.log("offsetPosition = " + offsetPosition);
|
||||
// Utils.log("offsetPosition count = " + mAdapter.getItemCount());
|
||||
// Utils.log("offsetPosition count = " + mState.getItemCount());
|
||||
if (offsetPosition < 0 || offsetPosition >= mAdapter.getItemCount()) {
|
||||
throw new IndexOutOfBoundsException("Inconsistency detected. Invalid item "
|
||||
+ "position " + position + "(offset:" + offsetPosition + ")."
|
||||
+ "state:" + mState.getItemCount());
|
||||
+ "state:" + mState.getItemCount()
|
||||
+ "adpter:" + mAdapter.getClass().getName());
|
||||
}
|
||||
|
||||
final int type = mAdapter.getItemViewType(offsetPosition);
|
||||
|
||||
@ -19,6 +19,8 @@ package com.android.volley;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.gh.common.util.Utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@ -204,6 +206,9 @@ public class RequestQueue {
|
||||
cancelAll(new RequestFilter() {
|
||||
@Override
|
||||
public boolean apply(Request<?> request) {
|
||||
Utils.log("111" + request.getTag().toString());
|
||||
Utils.log("111" + tag);
|
||||
Utils.log("111" + (request.getTag() == tag));
|
||||
return request.getTag() == tag;
|
||||
}
|
||||
});
|
||||
|
||||
@ -106,7 +106,7 @@ public class BasicNetwork implements Network {
|
||||
responseHeaders = convertHeaders(httpResponse.getAllHeaders());
|
||||
// Handle cache validation.
|
||||
if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
|
||||
if (request.getUrl().startsWith(Config.HOST + "v2/version")) {
|
||||
if (request.getUrl().startsWith(Config.HOST + "v2d0/support/upgrade")) {
|
||||
if (request.getCacheEntry() != null) {
|
||||
return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED,
|
||||
request.getCacheEntry().data, responseHeaders, true);
|
||||
|
||||
@ -5,7 +5,6 @@ import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningAppProcessInfo;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Process;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.TextUtils;
|
||||
@ -14,41 +13,100 @@ import android.util.Log;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
import com.gh.base.GHPushMessageReceiver.PushHandler;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DexUtils;
|
||||
import com.gh.common.util.HotFix;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.xiaomi.channel.commonutils.logger.LoggerInterface;
|
||||
import com.xiaomi.mipush.sdk.Logger;
|
||||
import com.xiaomi.mipush.sdk.MiPushClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AppController extends Application {
|
||||
|
||||
public static final String TAG = AppController.class.getSimpleName();
|
||||
|
||||
private RequestQueue mRequestQueue;
|
||||
|
||||
private static AppController mInstance;
|
||||
|
||||
// xiaomi push appid
|
||||
public static final String APP_ID = "2882303761517352993";
|
||||
// xiaomi push appkey
|
||||
public static final String APP_KEY = "5451735292993";
|
||||
|
||||
private static PushHandler handler = null;
|
||||
private static AppController mInstance;
|
||||
private static ArrayMap<String, Object> objectMap = new ArrayMap<>();
|
||||
|
||||
private static ArrayMap<String, Object> objectMap = new ArrayMap<String, Object>();
|
||||
private RequestQueue mRequestQueue;
|
||||
|
||||
private ArrayList<Activity> list = new ArrayList<>();
|
||||
|
||||
private boolean isFinish = false;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
// File dexPath = new File(getDir("dex", Context.MODE_PRIVATE), "hackdex_dex.jar");
|
||||
// DexUtils.prepareAssetsDex(this, dexPath, "hackdex_dex.jar");
|
||||
// HotFix.patch(this, dexPath.getAbsolutePath(), "dodola.hackdex.AntilazyLoad");
|
||||
|
||||
// SharedPreferences sp = this.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
// File directory = new File(this.getFilesDir().getAbsolutePath() + File.separator + "hotfix");
|
||||
// if (directory.exists()) {
|
||||
// File[] files = directory.listFiles();
|
||||
// for (File file : files) {
|
||||
// Utils.log("dex file = " + file.getName());
|
||||
// String clazz = sp.getString(file.getName(), null);
|
||||
// if (clazz != null) {
|
||||
// dexPath = new File(getDir("dex", Context.MODE_PRIVATE), file.getName());
|
||||
// DexUtils.prepareDex(this, dexPath, file);
|
||||
// HotFix.patch(this, dexPath.getAbsolutePath(), clazz);
|
||||
// Utils.log(file.getName() + " patch success");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
DataUtils.init(this);
|
||||
|
||||
AppUncaHandler uncaHandler = new AppUncaHandler(this);
|
||||
Thread.setDefaultUncaughtExceptionHandler(uncaHandler);
|
||||
mInstance = this;
|
||||
|
||||
// 注册push服务,注册成功后会向GHPushMessageReceiver发送广播
|
||||
// 可以从GHPushMessageReceiver的onCommandResult方法中MiPushCommandMessage对象参数中获取注册信息
|
||||
if (shouldInit()) {
|
||||
MiPushClient.registerPush(this, APP_ID, APP_KEY);
|
||||
}
|
||||
|
||||
LoggerInterface newLogger = new LoggerInterface() {
|
||||
|
||||
@Override
|
||||
public void setTag(String tag) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String content, Throwable t) {
|
||||
Log.d(TAG, content, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String content) {
|
||||
Log.d(TAG, content);
|
||||
}
|
||||
};
|
||||
Logger.setLogger(this, newLogger);
|
||||
|
||||
}
|
||||
|
||||
public static void put(String key, Object object) {
|
||||
if (objectMap == null) {
|
||||
objectMap = new ArrayMap<>();
|
||||
}
|
||||
objectMap.put(key, object);
|
||||
}
|
||||
|
||||
public static Object get(String key, boolean isRemove) {
|
||||
if (objectMap == null) {
|
||||
return null;
|
||||
}
|
||||
if (isRemove) {
|
||||
return objectMap.remove(key);
|
||||
} else {
|
||||
@ -57,13 +115,12 @@ public class AppController extends Application {
|
||||
}
|
||||
|
||||
public static void remove(String key) {
|
||||
if (objectMap == null) {
|
||||
return;
|
||||
}
|
||||
objectMap.remove(key);
|
||||
}
|
||||
|
||||
private ArrayList<Activity> list = new ArrayList<Activity>();
|
||||
|
||||
private boolean isFinish = false;
|
||||
|
||||
/**
|
||||
* Activity关闭时,删除Activity列表中的Activity对象
|
||||
*/
|
||||
@ -98,66 +155,6 @@ public class AppController extends Application {
|
||||
Process.killProcess(Process.myPid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
File dexPath = new File(getDir("dex", Context.MODE_PRIVATE), "hackdex_dex.jar");
|
||||
DexUtils.prepareAssetsDex(this, dexPath, "hackdex_dex.jar");
|
||||
HotFix.patch(this, dexPath.getAbsolutePath(), "dodola.hackdex.AntilazyLoad");
|
||||
|
||||
SharedPreferences sp = this.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
File directory = new File(this.getFilesDir().getAbsolutePath() + File.separator + "hotfix");
|
||||
if (directory.exists()) {
|
||||
File[] files = directory.listFiles();
|
||||
for (File file : files) {
|
||||
Utils.log("dex file = " + file.getName());
|
||||
String clazz = sp.getString(file.getName(), null);
|
||||
if (clazz != null) {
|
||||
dexPath = new File(getDir("dex", Context.MODE_PRIVATE), file.getName());
|
||||
DexUtils.prepareDex(this, dexPath, file);
|
||||
HotFix.patch(this, dexPath.getAbsolutePath(), clazz);
|
||||
Utils.log(file.getName() + " patch success");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataUtils.init(this);
|
||||
|
||||
AppUncaHandler uncaHandler = new AppUncaHandler(this);
|
||||
Thread.setDefaultUncaughtExceptionHandler(uncaHandler);
|
||||
mInstance = this;
|
||||
|
||||
// 注册push服务,注册成功后会向GHPushMessageReceiver发送广播
|
||||
// 可以从GHPushMessageReceiver的onCommandResult方法中MiPushCommandMessage对象参数中获取注册信息
|
||||
if (shouldInit()) {
|
||||
MiPushClient.registerPush(this, APP_ID, APP_KEY);
|
||||
}
|
||||
|
||||
LoggerInterface newLogger = new LoggerInterface() {
|
||||
|
||||
@Override
|
||||
public void setTag(String tag) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String content, Throwable t) {
|
||||
Log.d(TAG, content, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String content) {
|
||||
Log.d(TAG, content);
|
||||
}
|
||||
};
|
||||
Logger.setLogger(this, newLogger);
|
||||
if (handler == null) {
|
||||
handler = new PushHandler(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getProcessName(Context cxt, int pid) {
|
||||
ActivityManager am = (ActivityManager) cxt
|
||||
.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
@ -177,6 +174,26 @@ public class AppController extends Application {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public static <T> void addToRequestQueue(Request<T> request) {
|
||||
request.setTag(TAG);
|
||||
getInstance().addRequest(request);
|
||||
}
|
||||
|
||||
public static <T> void addToRequestQueue(Request<T> request, String tag) {
|
||||
if (TextUtils.isEmpty(tag)) {
|
||||
tag = TAG;
|
||||
}
|
||||
request.setTag(tag);
|
||||
getInstance().addRequest(request);
|
||||
}
|
||||
|
||||
public static void canclePendingRequests(String tag) {
|
||||
if (TextUtils.isEmpty(tag)) {
|
||||
tag = TAG;
|
||||
}
|
||||
getInstance().cancleRequest(tag);
|
||||
}
|
||||
|
||||
public <T> void addRequest(Request<T> request) {
|
||||
if (mRequestQueue == null) {
|
||||
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
|
||||
@ -189,50 +206,6 @@ public class AppController extends Application {
|
||||
mRequestQueue.cancelAll(tag);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void addToRequestQueue(Request<T> request) {
|
||||
request.setTag(TAG);
|
||||
getInstance().addRequest(request);
|
||||
}
|
||||
|
||||
public static <T> void addToRequestQueue(Request<T> request, String tag) {
|
||||
request.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
|
||||
getInstance().addRequest(request);
|
||||
}
|
||||
|
||||
public static <T> void addToRequestQueue(Request<T> request, Object obj) {
|
||||
String tag = null;
|
||||
if (obj != null) {
|
||||
tag = obj.getClass().getSimpleName();
|
||||
}
|
||||
addToRequestQueue(request, tag);
|
||||
}
|
||||
|
||||
public static <T> void addToRequestQueue(Request<T> request, Class<?> clazz) {
|
||||
String tag = null;
|
||||
if (clazz != null) {
|
||||
tag = clazz.getSimpleName();
|
||||
}
|
||||
addToRequestQueue(request, tag);
|
||||
}
|
||||
|
||||
public static void canclePendingRequests(String tag) {
|
||||
if (tag != null) {
|
||||
getInstance().cancleRequest(tag);
|
||||
}
|
||||
}
|
||||
|
||||
public static void canclePendingRequests(Object obj) {
|
||||
if (obj != null) {
|
||||
getInstance().cancleRequest(obj.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
public static void canclePendingRequests(Class<?> clazz) {
|
||||
if (clazz != null) {
|
||||
getInstance().cancleRequest(clazz.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldInit() {
|
||||
ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));
|
||||
@ -248,8 +221,4 @@ public class AppController extends Application {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static PushHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ public class AppUncaHandler implements UncaughtExceptionHandler {
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
PendingIntent restartIntent = PendingIntent.getActivity(
|
||||
appController.getApplicationContext(), 0, intent,
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
// 退出程序并重启
|
||||
AlarmManager mgr = (AlarmManager) appController
|
||||
.getSystemService(Context.ALARM_SERVICE);
|
||||
@ -78,9 +78,8 @@ public class AppUncaHandler implements UncaughtExceptionHandler {
|
||||
// MTA主动上传错误
|
||||
StatService.reportError(appController.getApplicationContext(), errorMsg);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("content", errorMsg);
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
map.put("type", android.os.Build.MODEL);
|
||||
map.put("system", android.os.Build.VERSION.SDK_INT + "="
|
||||
+ android.os.Build.VERSION.RELEASE);
|
||||
@ -89,8 +88,7 @@ public class AppUncaHandler implements UncaughtExceptionHandler {
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss",
|
||||
Locale.getDefault());
|
||||
File file = new File(FileUtils.getLogPath(
|
||||
appController.getApplicationContext(),
|
||||
File file = new File(FileUtils.getLogPath(appController.getApplicationContext(),
|
||||
format.format(new Date()) + "_gh_assist" + ".log"));
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
|
||||
@ -5,7 +5,6 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
@ -20,32 +19,33 @@ import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
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.util.RunningUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.listener.OnCallBackListener;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cn.sharesdk.framework.ShareSDK;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import onekeyshare.OnekeyShare;
|
||||
import onekeyshare.themes.classic.PlatformPage;
|
||||
|
||||
public class BaseActivity extends Activity {
|
||||
private String LOG = this.getClass().getName();
|
||||
private boolean LOG_ON = true;
|
||||
public class BaseActivity extends Activity implements OnCallBackListener {
|
||||
|
||||
private SystemBarTintManager tintManager;
|
||||
|
||||
private boolean isPause;
|
||||
|
||||
private SystemBarTintManager tintManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
AppLog("onCreate");
|
||||
Utils.log(this.getClass().getSimpleName());
|
||||
AppController.getInstance().addActivity(this);
|
||||
EventBus.getDefault().register(this);
|
||||
@ -63,7 +63,7 @@ public class BaseActivity extends Activity {
|
||||
setTranslucentStatus(true);
|
||||
tintManager = new SystemBarTintManager(this);
|
||||
tintManager.setStatusBarTintEnabled(true);
|
||||
tintManager.setStatusBarTintResource(R.color.theme_colors);
|
||||
tintManager.setStatusBarTintResource(R.color.theme);
|
||||
SystemBarConfig config = tintManager.getConfig();
|
||||
contentView.setPadding(0, config.getPixelInsetTop(false), 0,
|
||||
config.getPixelInsetBottom());
|
||||
@ -118,12 +118,6 @@ public class BaseActivity extends Activity {
|
||||
AppController.getInstance().removeActivity(this);
|
||||
}
|
||||
|
||||
public void AppLog(String str) {
|
||||
if (LOG_ON) {
|
||||
Log.i(LOG, str);
|
||||
}
|
||||
}
|
||||
|
||||
public void toast(String msg) {
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@ -145,60 +139,46 @@ public class BaseActivity extends Activity {
|
||||
window.setAttributes(winParams);
|
||||
}
|
||||
|
||||
public void showShare(String url, String title, String icon, String entrance, String type) {
|
||||
|
||||
if (isShowShare){
|
||||
return;
|
||||
}
|
||||
//如果是游戏分享,newsTitle默认为空
|
||||
public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList<String> tag, String entrance, String type) {
|
||||
|
||||
ShareSDK.initSDK(this);
|
||||
OnekeyShare oks = new OnekeyShare();
|
||||
// 关闭sso授权
|
||||
oks.disableSSOWhenAuthorize();
|
||||
|
||||
// 分享时Notification的图标和文字 2.5.9以后的版本不调用此方法
|
||||
// oks.setNotification(R.drawable.ic_launcher,
|
||||
// getString(R.string.app_name));
|
||||
// title标题,印象笔记、邮箱、信息、微信、人人网和QQ空间使用
|
||||
oks.setTitle(title);
|
||||
// titleUrl是标题的网络链接,仅在人人网和QQ空间使用
|
||||
oks.setTitleUrl(url);
|
||||
// text是分享文本,所有平台都需要这个字段
|
||||
oks.setText(title + " " + url);
|
||||
// imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
|
||||
// oks.setImagePath(icon);//确保SDcard下面存在此张图片
|
||||
oks.setImageUrl(icon);
|
||||
// url仅在微信(包括好友和朋友圈)中使用
|
||||
oks.setUrl(url);
|
||||
// comment是我对这条分享的评论,仅在人人网和QQ空间使用
|
||||
oks.setComment("精彩尽在" + url);
|
||||
// site是分享此内容的网站名称,仅在QQ空间使用
|
||||
oks.setSite(this.getString(R.string.app_name));
|
||||
// siteUrl是分享此内容的网站地址,仅在QQ空间使用
|
||||
oks.setSiteUrl(url);
|
||||
|
||||
oks.setOnFinishListener(new PlatformPage.OnFinishListener() {
|
||||
@Override
|
||||
public void onFinish() {
|
||||
Utils.log("onFinish");
|
||||
isShowShare = false;
|
||||
//判断是否是官方版
|
||||
boolean isPlugin = false;
|
||||
if (tag != null){
|
||||
for (String s : tag) {
|
||||
if (!"官方版".equals(s)){
|
||||
isPlugin = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 启动分享GUI
|
||||
oks.show(this);
|
||||
DataUtils.onEvent(this, "内容分享", title);
|
||||
isShowShare = true;
|
||||
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin);
|
||||
|
||||
if (newsTitle == null){
|
||||
DataUtils.onEvent(this, "内容分享", gameName);
|
||||
}else {
|
||||
DataUtils.onEvent(this, "内容分享", newsTitle);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isShowShare = false;
|
||||
|
||||
public void onEventMainThread(EBShowDialog showDialog) {
|
||||
public void onEventMainThread(final EBShowDialog showDialog) {
|
||||
if (!isPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) {
|
||||
if ("hijack".equals(showDialog.getType())) {
|
||||
DialogUtils.showHijackDialog(this);
|
||||
} else if ("delete".equals(showDialog.getType())) {
|
||||
DialogUtils.showDeleteDialog(this, showDialog.getPath());
|
||||
} else if ("plugin".equals(showDialog.getType())) {
|
||||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener(){
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
if (FileUtils.isEmptyFile(showDialog.getPath())) {
|
||||
Toast.makeText(BaseActivity.this, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
startActivity(PackageUtils.getUninstallIntent(BaseActivity.this, showDialog.getPath()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,35 +192,35 @@ public class BaseActivity extends Activity {
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
AppLog("onPause");
|
||||
DataUtils.onPause(this);
|
||||
isPause = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
AppLog("onRestart");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
AppLog("onResume");
|
||||
DataUtils.onResume(this);
|
||||
isPause = false;
|
||||
DownloadManager.getInstance(this).initGameMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
AppLog("onStart");
|
||||
public void loadDone() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
AppLog("onStop");
|
||||
public void loadDone(Object obj) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadEmpty() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
88
app/src/main/java/com/gh/base/BaseFragment.java
Normal file
88
app/src/main/java/com/gh/base/BaseFragment.java
Normal file
@ -0,0 +1,88 @@
|
||||
package com.gh.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.listener.OnCallBackListener;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/4.
|
||||
*/
|
||||
public class BaseFragment extends Fragment implements OnCallBackListener {
|
||||
|
||||
protected View view;
|
||||
|
||||
protected void init(int layout) {
|
||||
view = View.inflate(getActivity(), layout, null);
|
||||
|
||||
//简化findViewById
|
||||
try {
|
||||
Class<?> clazz = this.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
int id = Utils.getId(field.getName());
|
||||
if (id != -1) {
|
||||
Utils.log("reflect name = " + field.getName());
|
||||
field.setAccessible(true);
|
||||
Class<?> fieldType = field.getType();
|
||||
Object injectedValue = fieldType.cast(view.findViewById(id));
|
||||
field.set(this, injectedValue);
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if(container != null){
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadEmpty() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,6 @@ import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
@ -20,30 +19,30 @@ import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
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.util.RunningUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cn.sharesdk.framework.ShareSDK;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import onekeyshare.OnekeyShare;
|
||||
import onekeyshare.themes.classic.PlatformPage;
|
||||
|
||||
public class BaseFragmentActivity extends FragmentActivity {
|
||||
private String LOG = this.getClass().getName();
|
||||
private boolean LOG_ON = false;
|
||||
|
||||
private boolean isPause;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
AppLog("onCreate");
|
||||
Utils.log(this.getClass().getSimpleName());
|
||||
AppController.getInstance().addActivity(this);
|
||||
EventBus.getDefault().register(this);
|
||||
@ -61,7 +60,7 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
setTranslucentStatus(true);
|
||||
SystemBarTintManager tintManager = new SystemBarTintManager(this);
|
||||
tintManager.setStatusBarTintEnabled(true);
|
||||
tintManager.setStatusBarTintResource(R.color.theme_colors);
|
||||
tintManager.setStatusBarTintResource(R.color.theme);
|
||||
SystemBarConfig config = tintManager.getConfig();
|
||||
contentView.setPadding(0, config.getPixelInsetTop(false), 0,
|
||||
config.getPixelInsetBottom());
|
||||
@ -111,12 +110,6 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
AppController.getInstance().removeActivity(this);
|
||||
}
|
||||
|
||||
public void AppLog(String str) {
|
||||
if (LOG_ON) {
|
||||
Log.i(LOG, str);
|
||||
}
|
||||
}
|
||||
|
||||
public void toast(String msg) {
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@ -138,60 +131,45 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
window.setAttributes(winParams);
|
||||
}
|
||||
|
||||
public void showShare(String url, String title, String icon, String entrance, String type) {
|
||||
|
||||
if (isShowShare){
|
||||
return;
|
||||
}
|
||||
//如果是游戏分享,newsTitle默认为空
|
||||
public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList<String> tag, String entrance, String type) {
|
||||
|
||||
ShareSDK.initSDK(this);
|
||||
OnekeyShare oks = new OnekeyShare();
|
||||
// 关闭sso授权
|
||||
oks.disableSSOWhenAuthorize();
|
||||
|
||||
// 分享时Notification的图标和文字 2.5.9以后的版本不调用此方法
|
||||
// oks.setNotification(R.drawable.ic_launcher,
|
||||
// getString(R.string.app_name));
|
||||
// title标题,印象笔记、邮箱、信息、微信、人人网和QQ空间使用
|
||||
oks.setTitle(title);
|
||||
// titleUrl是标题的网络链接,仅在人人网和QQ空间使用
|
||||
oks.setTitleUrl(url);
|
||||
// text是分享文本,所有平台都需要这个字段
|
||||
oks.setText(title + " " + url);
|
||||
// imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
|
||||
// oks.setImagePath(icon);//确保SDcard下面存在此张图片
|
||||
oks.setImageUrl(icon);
|
||||
// url仅在微信(包括好友和朋友圈)中使用
|
||||
oks.setUrl(url);
|
||||
// comment是我对这条分享的评论,仅在人人网和QQ空间使用
|
||||
oks.setComment("精彩尽在" + url);
|
||||
// site是分享此内容的网站名称,仅在QQ空间使用
|
||||
oks.setSite(this.getString(R.string.app_name));
|
||||
// siteUrl是分享此内容的网站地址,仅在QQ空间使用
|
||||
oks.setSiteUrl(url);
|
||||
|
||||
oks.setOnFinishListener(new PlatformPage.OnFinishListener() {
|
||||
@Override
|
||||
public void onFinish() {
|
||||
Utils.log("onFinish");
|
||||
isShowShare = false;
|
||||
//判断是否是官方版
|
||||
boolean isPlugin = false;
|
||||
if (tag != null){
|
||||
for (String s : tag) {
|
||||
if (!"官方版".equals(s)){
|
||||
isPlugin = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 启动分享GUI
|
||||
oks.show(this);
|
||||
DataUtils.onEvent(this, "内容分享", title);
|
||||
isShowShare = true;
|
||||
ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin);
|
||||
|
||||
if (newsTitle == null){
|
||||
DataUtils.onEvent(this, "内容分享", gameName);
|
||||
}else {
|
||||
DataUtils.onEvent(this, "内容分享", newsTitle);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isShowShare = false;
|
||||
|
||||
public void onEventMainThread(EBShowDialog showDialog) {
|
||||
public void onEventMainThread(final EBShowDialog showDialog) {
|
||||
if (!isPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) {
|
||||
if ("hijack".equals(showDialog.getType())) {
|
||||
DialogUtils.showHijackDialog(this);
|
||||
} else if ("delete".equals(showDialog.getType())) {
|
||||
DialogUtils.showDeleteDialog(this, showDialog.getPath());
|
||||
} else if ("plugin".equals(showDialog.getType())) {
|
||||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfiremListener(){
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
if (FileUtils.isEmptyFile(showDialog.getPath())) {
|
||||
Toast.makeText(BaseFragmentActivity.this, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
startActivity(PackageUtils.getUninstallIntent(BaseFragmentActivity.this, showDialog.getPath()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -205,34 +183,16 @@ public class BaseFragmentActivity extends FragmentActivity {
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
AppLog("onPause");
|
||||
DataUtils.onPause(this);
|
||||
isPause = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
AppLog("onRestart");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
AppLog("onResume");
|
||||
DataUtils.onResume(this);
|
||||
isPause = false;
|
||||
DownloadManager.getInstance(this).initGameMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
AppLog("onStart");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
AppLog("onStop");
|
||||
}
|
||||
}
|
||||
|
||||
409
app/src/main/java/com/gh/base/DetailActivity.java
Normal file
409
app/src/main/java/com/gh/base/DetailActivity.java
Normal file
@ -0,0 +1,409 @@
|
||||
package com.gh.base;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
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 com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.ShareUtils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.tencent.tauth.Tencent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2016/9/19.
|
||||
*/
|
||||
public abstract class DetailActivity extends BaseActivity implements View.OnClickListener {
|
||||
|
||||
protected TextView actionbar_tv_title;
|
||||
protected RecyclerView detail_rv_show;
|
||||
protected LinearLayout detail_ll_bottom;
|
||||
protected TextView detail_tv_download;
|
||||
protected ProgressBar detail_pb_progressbar;
|
||||
protected TextView detail_tv_per;
|
||||
protected LinearLayout reuse_ll_loading;
|
||||
protected LinearLayout reuse_no_connection;
|
||||
protected ImageView iv_share;
|
||||
|
||||
protected GameEntity gameEntity;
|
||||
protected DownloadEntity mDownloadEntity;
|
||||
|
||||
protected String entrance;
|
||||
protected String name;
|
||||
protected String title;
|
||||
protected String downloadAddWord;
|
||||
|
||||
protected Handler handler = new Handler();
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
if (gameEntity != null && gameEntity.getApk().size() == 1) {
|
||||
String url = gameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(downloadEntity.getUrl())) {
|
||||
if (!"pause".equals(DownloadManager.getInstance(DetailActivity.this).
|
||||
getStatus(downloadEntity.getUrl()))) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
entrance = getIntent().getStringExtra("entrance");
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_detail, null);
|
||||
|
||||
// 添加分享图标
|
||||
iv_share = new ImageView(this);
|
||||
iv_share.setImageResource(R.drawable.share_icon);
|
||||
iv_share.setOnClickListener(this);
|
||||
iv_share.setVisibility(View.GONE);
|
||||
iv_share.setPadding(DisplayUtils.dip2px(this, 13),DisplayUtils.dip2px(this, 11)
|
||||
,DisplayUtils.dip2px(this, 11),DisplayUtils.dip2px(this, 13));
|
||||
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) contentView.findViewById(
|
||||
R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(iv_share, params);
|
||||
|
||||
init(contentView);
|
||||
|
||||
actionbar_tv_title = (TextView) findViewById(R.id.actionbar_tv_title);
|
||||
detail_rv_show = (RecyclerView) findViewById(R.id.detail_rv_show);
|
||||
detail_ll_bottom = (LinearLayout) findViewById(R.id.detail_ll_bottom);
|
||||
detail_tv_download = (TextView) findViewById(R.id.detail_tv_download);
|
||||
detail_pb_progressbar = (ProgressBar) findViewById(R.id.detail_pb_progressbar);
|
||||
detail_tv_per = (TextView) findViewById(R.id.detail_tv_per);
|
||||
reuse_ll_loading = (LinearLayout) findViewById(R.id.reuse_ll_loading);
|
||||
reuse_no_connection = (LinearLayout) findViewById(R.id.reuse_no_connection);
|
||||
|
||||
detail_ll_bottom.setOnClickListener(this);
|
||||
detail_tv_download.setOnClickListener(this);
|
||||
detail_pb_progressbar.setOnClickListener(this);
|
||||
detail_tv_per.setOnClickListener(this);
|
||||
reuse_no_connection.setOnClickListener(this);
|
||||
|
||||
}
|
||||
|
||||
//接收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 onResume() {
|
||||
super.onResume();
|
||||
if (gameEntity != null
|
||||
&& gameEntity.getApk() != null
|
||||
&& gameEntity.getApk().size() == 1) {
|
||||
initDownload(true);
|
||||
}
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
protected void initDownload(boolean isCheck) {
|
||||
if (Config.isShow(this)) {
|
||||
detail_ll_bottom.setVisibility(View.VISIBLE);
|
||||
detail_rv_show.setPadding(0, 0, 0,
|
||||
DisplayUtils.dip2px(getApplicationContext(), 44));
|
||||
} else {
|
||||
detail_ll_bottom.setVisibility(View.GONE);
|
||||
detail_rv_show.setPadding(0, 0, 0, 0);
|
||||
}
|
||||
if (gameEntity != null && "光环助手".equals(gameEntity.getName())) {
|
||||
detail_ll_bottom.setVisibility(View.GONE);
|
||||
detail_rv_show.setPadding(0, 0, 0, 0);
|
||||
} else if (gameEntity == null || gameEntity.getApk().isEmpty()) {
|
||||
detail_tv_download.setVisibility(View.VISIBLE);
|
||||
detail_pb_progressbar.setVisibility(View.GONE);
|
||||
detail_tv_per.setVisibility(View.GONE);
|
||||
detail_tv_download.setText("暂无下载");
|
||||
detail_tv_download.setBackgroundResource(R.drawable.game_item_btn_pause_style);
|
||||
detail_tv_download.setTextColor(0xFF999999);
|
||||
detail_tv_download.setClickable(false);
|
||||
} else {
|
||||
detail_tv_download.setVisibility(View.VISIBLE);
|
||||
detail_pb_progressbar.setVisibility(View.GONE);
|
||||
detail_tv_per.setVisibility(View.GONE);
|
||||
boolean isInstalled = false;
|
||||
if (gameEntity.getApk() != null && gameEntity.getApk().size() == 1
|
||||
&& PackageManager.isInstalled(gameEntity.getApk().get(0).getPackageName())) {
|
||||
isInstalled = true;
|
||||
}
|
||||
if (isInstalled) {
|
||||
if (PackageManager.isCanUpdate(gameEntity.getApk().get(0).getPackageName())) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
detail_tv_download.setText(String.format("更新《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
detail_tv_download.setText(String.format("更新《%s》%s",
|
||||
gameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
} else {
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !PackageUtils.isSignature(this, gameEntity.getApk().get(0).getPackageName())
|
||||
) {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
detail_tv_download.setText(String.format("插件化《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_plugin_style);
|
||||
detail_tv_download.setText(String.format("插件化《%s》%s",
|
||||
gameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
} else {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
detail_tv_download.setText(String.format("启动《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_launch_style);
|
||||
detail_tv_download.setText(String.format("启动《%s》%s",
|
||||
gameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (TextUtils.isEmpty(downloadAddWord)) {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
detail_tv_download.setText(String.format("下载《%s》",
|
||||
gameEntity.getName()));
|
||||
} else {
|
||||
detail_tv_download.setBackgroundResource(
|
||||
R.drawable.game_item_btn_download_style);
|
||||
detail_tv_download.setText(String.format("下载《%s》%s",
|
||||
gameEntity.getName(), downloadAddWord));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isCheck && gameEntity != null
|
||||
&& gameEntity.getApk() != null
|
||||
&& gameEntity.getApk().size() == 1) {
|
||||
String url = gameEntity.getApk().get(0).getUrl();
|
||||
List<DownloadEntity> list = DownloadManager.getInstance(getApplicationContext()).getAll();
|
||||
for (DownloadEntity entry : list) {
|
||||
if (url.equals(entry.getUrl())) {
|
||||
mDownloadEntity = entry;
|
||||
detail_tv_download.setVisibility(View.GONE);
|
||||
detail_pb_progressbar.setVisibility(View.VISIBLE);
|
||||
detail_tv_per.setVisibility(View.VISIBLE);
|
||||
invalidate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
detail_pb_progressbar.setProgress((int) (mDownloadEntity.getPercent() * 10));
|
||||
detail_tv_per.setTextColor(0xFFFFFFFF);
|
||||
switch (mDownloadEntity.getStatus()) {
|
||||
case downloading:
|
||||
case pause:
|
||||
case timeout:
|
||||
case neterror:
|
||||
case waiting:
|
||||
detail_tv_per.setText("下载中");
|
||||
break;
|
||||
case done:
|
||||
detail_tv_per.setText("安装");
|
||||
if (mDownloadEntity.isPluggable()
|
||||
&& PackageManager.isInstalled(mDownloadEntity.getPackageName())) {
|
||||
detail_pb_progressbar.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_plugin_radius_style));
|
||||
} else {
|
||||
detail_pb_progressbar.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_normal_radius_style));
|
||||
}
|
||||
break;
|
||||
case cancel:
|
||||
case hijack:
|
||||
initDownload(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 接收下载被删除消息
|
||||
public void onEvent(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())
|
||||
&& gameEntity != null
|
||||
&& gameEntity.getApk() != null
|
||||
&& gameEntity.getApk().size() == 1) {
|
||||
String url = gameEntity.getApk().get(0).getUrl();
|
||||
if (url.equals(status.getUrl())) {
|
||||
initDownload(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 接受安装、卸载消息
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
if (gameEntity != null
|
||||
&& gameEntity.getApk() != null
|
||||
&& gameEntity.getApk().size() == 1) {
|
||||
String packageName = gameEntity.getApk().get(0).getPackageName();
|
||||
if (packageName.equals(busFour.getPackageName())) {
|
||||
initDownload(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == detail_tv_download) {
|
||||
if (gameEntity != null && !gameEntity.getApk().isEmpty()) {
|
||||
if (gameEntity.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, gameEntity, entrance, name + ":" + title);
|
||||
}
|
||||
} else {
|
||||
toast("稍等片刻~!游戏正在上传中...");
|
||||
}
|
||||
} else if (v == detail_pb_progressbar || v == detail_tv_per) {
|
||||
String str = detail_tv_per.getText().toString();
|
||||
if ("下载中".equals(str)) {
|
||||
startActivity(new Intent(this, DownloadManagerActivity.class));
|
||||
} else if ("安装".equals(str)) {
|
||||
PackageUtils.launchSetup(this, mDownloadEntity.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void download() {
|
||||
String str = detail_tv_download.getText().toString();
|
||||
if (str.contains("启动")) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", gameEntity.getApk().get(0).getPlatform());
|
||||
kv.put("页面", name);
|
||||
DataUtils.onEvent(DetailActivity.this, "游戏启动", gameEntity.getName(), kv);
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(this, gameEntity.getApk().get(0).getPackageName());
|
||||
} else {
|
||||
String method;
|
||||
if (str.contains("更新")) {
|
||||
method = "更新";
|
||||
} else if (str.contains("插件化")) {
|
||||
method = "插件化";
|
||||
} else {
|
||||
method = "下载";
|
||||
}
|
||||
ApkEntity apkEntity = gameEntity.getApk().get(0);
|
||||
String msg = FileUtils.isCanDownload(apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(DetailActivity.this, "游戏下载", gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("页面", name);
|
||||
kv2.put("位置", entrance);
|
||||
DataUtils.onEvent(DetailActivity.this, "游戏下载位置", gameEntity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(DetailActivity.this, "应用数据", gameEntity.getName(), kv3);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
map.put("method", method.equals("下载") ? "正常" : method);
|
||||
map.put("platform", PlatformUtils.getInstance(getApplicationContext())
|
||||
.getPlatformName(gameEntity.getApk().get(0).getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("location", name + ":" + title);
|
||||
map.put("entrance", entrance);
|
||||
map.put("btn_status", method);
|
||||
map.put("network", NetworkUtils.getConnectedType(this));
|
||||
DataCollectionManager.onEvent(this, "download", map);
|
||||
|
||||
DownloadManager.createDownload(this, apkEntity, gameEntity, method, entrance, name + ":" + title);
|
||||
|
||||
detail_tv_download.setVisibility(View.GONE);
|
||||
detail_pb_progressbar.setVisibility(View.VISIBLE);
|
||||
detail_tv_per.setVisibility(View.VISIBLE);
|
||||
detail_pb_progressbar.setProgress(0);
|
||||
detail_tv_per.setText("0.0%");
|
||||
|
||||
DownloadManager.getInstance(DetailActivity.this).putStatus(apkEntity.getUrl(), "downloading");
|
||||
} else {
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
package com.gh.base;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
@ -10,11 +9,8 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
@ -22,8 +18,6 @@ import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.xiaomi.mipush.sdk.ErrorCode;
|
||||
import com.xiaomi.mipush.sdk.MiPushClient;
|
||||
import com.xiaomi.mipush.sdk.MiPushCommandMessage;
|
||||
import com.xiaomi.mipush.sdk.MiPushMessage;
|
||||
import com.xiaomi.mipush.sdk.PushMessageReceiver;
|
||||
@ -63,17 +57,6 @@ import java.util.Locale;
|
||||
*/
|
||||
public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
|
||||
private String mRegId;
|
||||
private long mResultCode = -1;
|
||||
private String mReason;
|
||||
private String mCommand;
|
||||
private String mMessage;
|
||||
private String mTopic;
|
||||
private String mAlias;
|
||||
private String mAccount;
|
||||
private String mStartTime;
|
||||
private String mEndTime;
|
||||
|
||||
@Override
|
||||
public void onReceivePassThroughMessage(Context context,
|
||||
MiPushMessage message) {
|
||||
@ -86,15 +69,12 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
Utils.log("channel = " + channel);
|
||||
// 1判断渠道号是否一致或是否为ALL
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(context, context.getPackageName(), "TD_CHANNEL_ID");
|
||||
if ("ALL".equals(channel)
|
||||
|| TD_CHANNEL_ID
|
||||
.equalsIgnoreCase(channel)) {
|
||||
if ("ALL".equals(channel) || channel.equalsIgnoreCase(TD_CHANNEL_ID)) {
|
||||
String type = jsonObject.getString("type");
|
||||
Utils.log("type = " + type);
|
||||
if ("NEWS".equals(type)) {
|
||||
// 新闻推送
|
||||
JSONArray jsonArray = jsonObject
|
||||
.getJSONArray("package");
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("package");
|
||||
ArrayMap<String, Boolean> map = getInstalledMapFromLocal(context);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
Boolean b = map.get(jsonArray.getString(i));
|
||||
@ -119,14 +99,11 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
if (gh_version != null) {
|
||||
gh_version = gh_version.substring(2);
|
||||
// 判断gh_version是否相同
|
||||
if (gh_version.equals(apk
|
||||
.getString("gh_version"))) {
|
||||
if (gh_version.equals(apk.getString("gh_version"))) {
|
||||
// 判断version是否相同
|
||||
String version = PackageUtils
|
||||
.getVersionByPackage(context,
|
||||
packageName);
|
||||
if (version.equals(apk
|
||||
.getString("version"))) {
|
||||
String version = PackageUtils.getVersionByPackage(
|
||||
context, packageName);
|
||||
if (apk.getString("version").equals(version)) {
|
||||
// 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包
|
||||
continue;
|
||||
}
|
||||
@ -147,24 +124,10 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Log.v(AppController.TAG, "onReceivePassThroughMessage is called. "
|
||||
+ message.toString());
|
||||
String log = context.getString(R.string.recv_passthrough_message,
|
||||
message.getContent());
|
||||
|
||||
if (!TextUtils.isEmpty(message.getTopic())) {
|
||||
mTopic = message.getTopic();
|
||||
} else if (!TextUtils.isEmpty(message.getAlias())) {
|
||||
mAlias = message.getAlias();
|
||||
}
|
||||
|
||||
Message msg = Message.obtain();
|
||||
msg.obj = log;
|
||||
AppController.getHandler().sendMessage(msg);
|
||||
Log.v(AppController.TAG, "onReceivePassThroughMessage is called. " + message.toString());
|
||||
}
|
||||
|
||||
private void showNotification(Context context, JSONObject jsonObject, int id)
|
||||
throws JSONException {
|
||||
private void showNotification(Context context, JSONObject jsonObject, int id) throws JSONException {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("com.gh.gamecenter.NOTIFICATION");
|
||||
intent.putExtra("notifyId", id);
|
||||
@ -185,7 +148,8 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
RemoteViews remoteViews = null;
|
||||
|
||||
if (Build.MANUFACTURER.equals("Meizu")
|
||||
&& (Build.MODEL.startsWith("m") || Build.MODEL.startsWith("MX"))) {
|
||||
&& (Build.MODEL.startsWith("m")
|
||||
|| Build.MODEL.startsWith("MX"))) {
|
||||
remoteViews = new RemoteViews(context.getPackageName(),
|
||||
R.layout.notification_meizu);
|
||||
SimpleDateFormat format = new SimpleDateFormat("HH:mm",
|
||||
@ -193,8 +157,8 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
remoteViews.setTextViewText(R.id.time, format.format(new Date()));
|
||||
} else if (Build.MANUFACTURER.equals("Xiaomi")
|
||||
&& (Build.MODEL.startsWith("MI")
|
||||
|| Build.MODEL.startsWith("HM") || Build.MODEL
|
||||
.startsWith("Redmi"))) {
|
||||
|| Build.MODEL.startsWith("HM")
|
||||
|| Build.MODEL.startsWith("Redmi"))) {
|
||||
// 小米系统
|
||||
remoteViews = new RemoteViews(context.getPackageName(),
|
||||
R.layout.notification_xiaomi);
|
||||
@ -211,27 +175,39 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
String path = context.getCacheDir() + File.separator
|
||||
+ url.substring(url.lastIndexOf("/") + 1);
|
||||
try {
|
||||
FileUtils.downloadFile(url, path);
|
||||
int result = FileUtils.downloadFile(url, path);
|
||||
if (result == -1) {
|
||||
// 下载出错,使用光环logo
|
||||
path = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// 下载出错,使用光环logo
|
||||
path = null;
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (remoteViews != null) {
|
||||
remoteViews.setImageViewBitmap(R.id.icon,
|
||||
BitmapFactory.decodeFile(path));
|
||||
// remoteViews.setImageViewResource(R.id.icon, R.drawable.me_icon);
|
||||
remoteViews.setTextViewText(R.id.title,
|
||||
jsonObject.getString("pushTitle"));
|
||||
remoteViews.setTextViewText(R.id.intro,
|
||||
jsonObject.getString("pushDesc"));
|
||||
if (path == null) {
|
||||
remoteViews.setImageViewBitmap(R.id.icon, BitmapFactory.decodeResource(context.getResources(), R.drawable.logo));
|
||||
} else {
|
||||
remoteViews.setImageViewBitmap(R.id.icon, BitmapFactory.decodeFile(path));
|
||||
}
|
||||
remoteViews.setTextViewText(R.id.title, jsonObject.getString("pushTitle"));
|
||||
remoteViews.setTextViewText(R.id.intro, jsonObject.getString("pushDesc"));
|
||||
notification.contentView = remoteViews;
|
||||
} else {
|
||||
notification = new NotificationCompat.Builder(context)
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.logo_black)
|
||||
.setTicker(jsonObject.getString("pushTitle"))
|
||||
.setContentTitle(jsonObject.getString("pushTitle"))
|
||||
.setContentText(jsonObject.getString("pushDesc"))
|
||||
.setContentIntent(pendingIntent)
|
||||
.setLargeIcon(BitmapFactory.decodeFile(path)).build();
|
||||
.setContentIntent(pendingIntent);
|
||||
if (path == null) {
|
||||
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.logo));
|
||||
} else {
|
||||
builder.setLargeIcon(BitmapFactory.decodeFile(path));
|
||||
}
|
||||
notification = builder.build();
|
||||
}
|
||||
|
||||
notification.defaults = Notification.DEFAULT_SOUND;// 添加系统默认声音
|
||||
@ -240,7 +216,7 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
}
|
||||
|
||||
private ArrayMap<String, Boolean> getInstalledMapFromLocal(Context context) {
|
||||
ArrayMap<String, Boolean> map = new ArrayMap<String, Boolean>();
|
||||
ArrayMap<String, Boolean> map = new ArrayMap<>();
|
||||
ArrayList<String> list = getAllPackageName(context);
|
||||
for (String str : list) {
|
||||
map.put(str, true);
|
||||
@ -249,7 +225,7 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
}
|
||||
|
||||
private ArrayList<String> getAllPackageName(Context context) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
List<PackageInfo> packageInfos = context.getPackageManager()
|
||||
.getInstalledPackages(0);
|
||||
for (int i = 0, size = packageInfos.size(); i < size; i++) {
|
||||
@ -266,21 +242,6 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
MiPushMessage message) {
|
||||
Log.v(AppController.TAG, "onNotificationMessageClicked is called. "
|
||||
+ message.toString());
|
||||
String log = context.getString(R.string.click_notification_message,
|
||||
message.getContent());
|
||||
|
||||
if (!TextUtils.isEmpty(message.getTopic())) {
|
||||
mTopic = message.getTopic();
|
||||
} else if (!TextUtils.isEmpty(message.getAlias())) {
|
||||
mAlias = message.getAlias();
|
||||
}
|
||||
|
||||
Message msg = Message.obtain();
|
||||
if (message.isNotified()) {
|
||||
msg.obj = log;
|
||||
}
|
||||
AppController.getHandler().sendMessage(msg);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -288,105 +249,12 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
MiPushMessage message) {
|
||||
Log.v(AppController.TAG, "onNotificationMessageArrived is called. "
|
||||
+ message.toString());
|
||||
String log = context.getString(R.string.arrive_notification_message,
|
||||
message.getContent());
|
||||
|
||||
if (!TextUtils.isEmpty(message.getTopic())) {
|
||||
mTopic = message.getTopic();
|
||||
} else if (!TextUtils.isEmpty(message.getAlias())) {
|
||||
mAlias = message.getAlias();
|
||||
}
|
||||
|
||||
Message msg = Message.obtain();
|
||||
msg.obj = log;
|
||||
AppController.getHandler().sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommandResult(Context context, MiPushCommandMessage message) {
|
||||
Log.v(AppController.TAG,
|
||||
"onCommandResult is called. " + message.toString());
|
||||
String command = message.getCommand();
|
||||
List<String> arguments = message.getCommandArguments();
|
||||
String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments
|
||||
.get(0) : null);
|
||||
String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments
|
||||
.get(1) : null);
|
||||
String log = "";
|
||||
if (MiPushClient.COMMAND_REGISTER.equals(command)) {
|
||||
if (message.getResultCode() == ErrorCode.SUCCESS) {
|
||||
mRegId = cmdArg1;
|
||||
log = context.getString(R.string.register_success);
|
||||
} else {
|
||||
log = context.getString(R.string.register_fail);
|
||||
}
|
||||
} else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) {
|
||||
if (message.getResultCode() == ErrorCode.SUCCESS) {
|
||||
mAlias = cmdArg1;
|
||||
log = context.getString(R.string.set_alias_success, mAlias);
|
||||
} else {
|
||||
log = context.getString(R.string.set_alias_fail,
|
||||
message.getReason());
|
||||
}
|
||||
} else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) {
|
||||
if (message.getResultCode() == ErrorCode.SUCCESS) {
|
||||
mAlias = cmdArg1;
|
||||
log = context.getString(R.string.unset_alias_success, mAlias);
|
||||
} else {
|
||||
log = context.getString(R.string.unset_alias_fail,
|
||||
message.getReason());
|
||||
}
|
||||
} else if (MiPushClient.COMMAND_SET_ACCOUNT.equals(command)) {
|
||||
if (message.getResultCode() == ErrorCode.SUCCESS) {
|
||||
mAccount = cmdArg1;
|
||||
log = context.getString(R.string.set_account_success, mAccount);
|
||||
} else {
|
||||
log = context.getString(R.string.set_account_fail,
|
||||
message.getReason());
|
||||
}
|
||||
} else if (MiPushClient.COMMAND_UNSET_ACCOUNT.equals(command)) {
|
||||
if (message.getResultCode() == ErrorCode.SUCCESS) {
|
||||
mAccount = cmdArg1;
|
||||
log = context.getString(R.string.unset_account_success,
|
||||
mAccount);
|
||||
} else {
|
||||
log = context.getString(R.string.unset_account_fail,
|
||||
message.getReason());
|
||||
}
|
||||
} else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) {
|
||||
if (message.getResultCode() == ErrorCode.SUCCESS) {
|
||||
mTopic = cmdArg1;
|
||||
log = context.getString(R.string.subscribe_topic_success,
|
||||
mTopic);
|
||||
} else {
|
||||
log = context.getString(R.string.subscribe_topic_fail,
|
||||
message.getReason());
|
||||
}
|
||||
} else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) {
|
||||
if (message.getResultCode() == ErrorCode.SUCCESS) {
|
||||
log = context.getString(R.string.unsubscribe_topic_success,
|
||||
mTopic);
|
||||
} else {
|
||||
log = context.getString(R.string.unsubscribe_topic_fail,
|
||||
message.getReason());
|
||||
}
|
||||
} else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) {
|
||||
if (message.getResultCode() == ErrorCode.SUCCESS) {
|
||||
mStartTime = cmdArg1;
|
||||
mEndTime = cmdArg2;
|
||||
log = context.getString(R.string.set_accept_time_success,
|
||||
mStartTime, mEndTime);
|
||||
} else {
|
||||
log = context.getString(R.string.set_accept_time_fail,
|
||||
message.getReason());
|
||||
}
|
||||
} else {
|
||||
log = message.getReason();
|
||||
}
|
||||
|
||||
Message msg = Message.obtain();
|
||||
msg.obj = log;
|
||||
AppController.getHandler().sendMessage(msg);
|
||||
Log.v(AppController.TAG, "onCommandResult is called. "
|
||||
+ message.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -394,47 +262,6 @@ public class GHPushMessageReceiver extends PushMessageReceiver {
|
||||
MiPushCommandMessage message) {
|
||||
Log.v(AppController.TAG, "onReceiveRegisterResult is called. "
|
||||
+ message.toString());
|
||||
String command = message.getCommand();
|
||||
List<String> arguments = message.getCommandArguments();
|
||||
String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments
|
||||
.get(0) : null);
|
||||
String log;
|
||||
if (MiPushClient.COMMAND_REGISTER.equals(command)) {
|
||||
if (message.getResultCode() == ErrorCode.SUCCESS) {
|
||||
mRegId = cmdArg1;
|
||||
log = context.getString(R.string.register_success);
|
||||
} else {
|
||||
log = context.getString(R.string.register_fail);
|
||||
}
|
||||
} else {
|
||||
log = message.getReason();
|
||||
}
|
||||
|
||||
Message msg = Message.obtain();
|
||||
msg.obj = log;
|
||||
AppController.getHandler().sendMessage(msg);
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public static String getSimpleDate() {
|
||||
return new SimpleDateFormat("MM-dd hh:mm:ss").format(new Date());
|
||||
}
|
||||
|
||||
public static class PushHandler extends Handler {
|
||||
|
||||
private Context context;
|
||||
|
||||
public PushHandler(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
String s = (String) msg.obj;
|
||||
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
// Toast.makeText(context, s, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
237
app/src/main/java/com/gh/base/HomeFragment.java
Normal file
237
app/src/main/java/com/gh/base/HomeFragment.java
Normal file
@ -0,0 +1,237 @@
|
||||
package com.gh.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.ConcernActivity;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SearchActivity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBTopStatus;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/9.
|
||||
*/
|
||||
public class HomeFragment extends Fragment implements View.OnClickListener {
|
||||
|
||||
protected View view;
|
||||
protected LinearLayout home_ll_top;
|
||||
protected View home_slide_line;
|
||||
protected ViewPager home_vp_content;
|
||||
|
||||
protected LinearLayout.LayoutParams lparams;
|
||||
|
||||
protected Handler handler = new Handler();
|
||||
|
||||
private TextView downloadHint;
|
||||
private TextView searchHint;
|
||||
|
||||
private String hint;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
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)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
int top = DisplayUtils.getInternalDimensionSize(getResources(),
|
||||
"status_bar_height");
|
||||
home_actionbar.setPadding(0, top, 0, 0);
|
||||
lparams.height += top;
|
||||
}
|
||||
home_actionbar.setLayoutParams(lparams);
|
||||
|
||||
initActionBar();
|
||||
|
||||
home_ll_top = (LinearLayout) view.findViewById(R.id.home_ll_top);
|
||||
home_slide_line = view.findViewById(R.id.home_slide_line);
|
||||
home_vp_content = (ViewPager) view.findViewById(R.id.home_vp_content);
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (container != null) {
|
||||
container.removeView(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private void initActionBar() {
|
||||
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);
|
||||
|
||||
if (Config.isShow(getActivity())) {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
downloadHint = (TextView) view.findViewById(R.id.action_tip);
|
||||
int updateSize = PackageManager.getUpdateListSize();
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size();
|
||||
if (downloadSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText(String.valueOf(downloadSize));
|
||||
} else if (updateSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText(String.valueOf(updateSize));
|
||||
} else {
|
||||
downloadHint.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
searchHint = (TextView) view.findViewById(R.id.actionbar_search_input);
|
||||
searchHint.setOnClickListener(this);
|
||||
if (!TextUtils.isEmpty(MainActivity.searchHint)) {
|
||||
hint = MainActivity.searchHint;
|
||||
searchHint.setHint(hint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final int id = v.getId();
|
||||
if (id == R.id.actionbar_notification) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "关注图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "关注图标");
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
startActivity(new Intent(getActivity(), ConcernActivity.class));
|
||||
} else if (id == R.id.actionbar_rl_download) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "下载图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "下载图标");
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
startActivity(new Intent(getActivity(), DownloadManagerActivity.class));
|
||||
} else if (id == R.id.actionbar_search_input) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "搜索框");
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "搜索框");
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
Intent goSearch = new Intent(getActivity(), SearchActivity.class);
|
||||
goSearch.putExtra("clicked", false);
|
||||
goSearch.putExtra("hint", hint);
|
||||
startActivity(goSearch);
|
||||
} else if (id == R.id.actionbar_iv_search) {
|
||||
DataUtils.onEvent(getActivity(), "主页", "搜索图标");
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "搜索图标");
|
||||
map.put("page", "主页");
|
||||
DataCollectionManager.onEvent(getActivity(), "click-item", map);
|
||||
|
||||
Intent searchIntent = new Intent(getActivity(), SearchActivity.class);
|
||||
searchIntent.putExtra("clicked", true);
|
||||
searchIntent.putExtra("hint", hint);
|
||||
startActivity(searchIntent);
|
||||
}
|
||||
}
|
||||
|
||||
// 打开下载按钮事件
|
||||
public void onEventMainThread(EBReuse reuse) {
|
||||
if ("Refresh".equals(reuse.getType())) {
|
||||
if (Config.isShow(getActivity())) {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
view.findViewById(R.id.actionbar_rl_download).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBTopStatus status) {
|
||||
if (!TextUtils.isEmpty(status.getSearchHint())) {
|
||||
hint = status.getSearchHint();
|
||||
searchHint.setHint(hint);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
downloadHint = (TextView) view.findViewById(R.id.action_tip);
|
||||
int updateSize = PackageManager.getUpdateListSize();
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size();
|
||||
if (downloadSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText(String.valueOf(downloadSize));
|
||||
} else if (updateSize != 0) {
|
||||
downloadHint.setVisibility(View.VISIBLE);
|
||||
downloadHint.setText(String.valueOf(updateSize));
|
||||
} else {
|
||||
downloadHint.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
|
||||
List<Fragment> list = getChildFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
if (hidden) {
|
||||
for (Fragment fragment : getChildFragmentManager().getFragments()) {
|
||||
transaction.hide(fragment);
|
||||
}
|
||||
} else {
|
||||
for (Fragment fragment : getChildFragmentManager().getFragments()) {
|
||||
transaction.show(fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
}
|
||||
@ -1,16 +1,17 @@
|
||||
package com.gh.common.constant;
|
||||
|
||||
import com.gh.gamecenter.SplashScreenActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public final class Config {
|
||||
public class Config {
|
||||
|
||||
// test host dev.ghzhushou.com/api
|
||||
public static final String HOST = "http://api.ghzhushou.com/";
|
||||
// public static final String HOST = "http://115.28.145.16:9001/";
|
||||
|
||||
public static final String PREFERENCE = "ghzhushou";
|
||||
|
||||
// public static final boolean isShow = true;
|
||||
public static final boolean isShow = SplashScreenActivity.isShow;
|
||||
|
||||
public static boolean isShow(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
return sp.getBoolean("isShow", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -38,4 +38,5 @@ public class Constants {
|
||||
public static final int SEARCH_CD = 5 * 60 * 1000;
|
||||
//评论 cd间隔
|
||||
public static final int COMMENT_CD = 60 * 1000;
|
||||
|
||||
}
|
||||
|
||||
154
app/src/main/java/com/gh/common/util/ConcernUtils.java
Normal file
154
app/src/main/java/com/gh/common/util/ConcernUtils.java
Normal file
@ -0,0 +1,154 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/8/24.
|
||||
*/
|
||||
public class ConcernUtils {
|
||||
|
||||
public static void loadConcernData(final String url, final DownJsonListener listener) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(url,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
if (listener != null){
|
||||
listener.downSucced(response.toString());
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (listener != null){
|
||||
listener.downFailed();
|
||||
}
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
public static void postConcernGameId(final String gameId, final String postUrl, final DownJsonListener listener){
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
JSONArray data = new JSONArray();
|
||||
data.put(gameId);
|
||||
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.POST, postUrl, data.toString(),
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
if (listener != null) {
|
||||
listener.downSucced("关注成功");
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (listener != null) {
|
||||
listener.downFailed();
|
||||
}
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static void deleteConcernData(final String url, final DownJsonListener listener){
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.DELETE, url,
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
if (listener != null) {
|
||||
listener.downSucced("删除成功");
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (listener != null) {
|
||||
listener.downFailed();
|
||||
}
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static void updateConcernData(final String url, final JSONArray data, final DownJsonListener listener){
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.PUT, url, data.toString(),
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
if (listener != null) {
|
||||
listener.downSucced("更新设备关注成功");
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (listener != null) {
|
||||
listener.downFailed();
|
||||
}
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
}).start();
|
||||
}
|
||||
|
||||
public interface DownJsonListener {
|
||||
void downSucced(String str);
|
||||
void downFailed();
|
||||
}
|
||||
|
||||
// 获取设备号ID
|
||||
public static String uuid(Context context){
|
||||
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
|
||||
final String tmDevice, tmSerial, androidId;
|
||||
tmDevice = "" + tm.getDeviceId();
|
||||
tmSerial = "" + tm.getSimSerialNumber();
|
||||
androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
|
||||
|
||||
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
|
||||
return deviceUuid.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ public class DataUtils {
|
||||
for (String key : var3.keySet()) {
|
||||
prop.setProperty(key, var3.get(key) + "");
|
||||
}
|
||||
StatService.trackCustomBeginKVEvent(var0, var1, prop);
|
||||
StatService.trackCustomKVEvent(var0, var1, prop);
|
||||
}
|
||||
|
||||
public static void onPause(Activity var0) {
|
||||
|
||||
@ -15,14 +15,16 @@ public class DeviceUtils {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
|
||||
if (!TextUtils.isEmpty(imei)) {
|
||||
buffer.append("imei=" + imei);
|
||||
buffer.append("imei=");
|
||||
buffer.append(imei);
|
||||
}
|
||||
String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
|
||||
if (!TextUtils.isEmpty(android_id)) {
|
||||
if (buffer.length() != 0) {
|
||||
buffer.append(",");
|
||||
}
|
||||
buffer.append("android_id=" + android_id);
|
||||
buffer.append("android_id=");
|
||||
buffer.append(android_id);
|
||||
}
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
String mac = wm.getConnectionInfo().getMacAddress();
|
||||
@ -30,7 +32,8 @@ public class DeviceUtils {
|
||||
if (buffer.length() != 0) {
|
||||
buffer.append(",");
|
||||
}
|
||||
buffer.append("mac=" + mac);
|
||||
buffer.append("mac=");
|
||||
buffer.append(mac);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ import java.io.OutputStream;
|
||||
* Created by sunpengfei on 15/11/4.
|
||||
*/
|
||||
public class DexUtils {
|
||||
|
||||
private static final int BUF_SIZE = 2048;
|
||||
|
||||
public static boolean prepareAssetsDex(Context context, File dexInternalStoragePath, String dex_file) {
|
||||
@ -53,7 +54,7 @@ public class DexUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean prepareDex(Context context, File dexInternalStoragePath, File dex_file) {
|
||||
public static boolean prepareDex(File dexInternalStoragePath, File dex_file) {
|
||||
BufferedInputStream bis = null;
|
||||
OutputStream dexWriter = null;
|
||||
|
||||
@ -86,4 +87,5 @@ public class DexUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,12 +4,12 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
public class DialogUtils {
|
||||
@ -26,142 +26,130 @@ public class DialogUtils {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public static void showDialog(final Context context, final String path) {
|
||||
private static boolean isShow = false;
|
||||
|
||||
public static void showWarningDialog(Context context, String title, CharSequence msg, String cancel, String confirm,
|
||||
final ConfiremListener cmListener, final CancelListener clListener) {
|
||||
|
||||
if (isShow) {
|
||||
return;
|
||||
}
|
||||
isShow = true;
|
||||
|
||||
final Dialog dialog = new Dialog(context);
|
||||
View view = View.inflate(context,
|
||||
R.layout.search_history_delete_dialog, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("卸载");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
|
||||
content.setText("您已安装了官方原版,该版本与插件版本冲突,是否卸载官方原版?");
|
||||
View view = View.inflate(context, R.layout.common_alertdialog, null);
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("忽略");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
// 标题
|
||||
TextView alertdialog_title = (TextView) view.findViewById(R.id.alertdialog_title);
|
||||
alertdialog_title.setText(title);
|
||||
|
||||
// 内容
|
||||
TextView alertdialog_content = (TextView) view.findViewById(R.id.alertdialog_content);
|
||||
alertdialog_content.setText(msg);
|
||||
|
||||
// 取消按钮
|
||||
TextView alertdialog_cannel = (TextView) view.findViewById(R.id.alertdialog_cannel);
|
||||
alertdialog_cannel.setText(cancel);
|
||||
alertdialog_cannel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (clListener != null) {
|
||||
clListener.onCancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
TextView confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("卸载");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
|
||||
// 确定按钮
|
||||
TextView alertdialog_confirm = (TextView) view.findViewById(R.id.alertdialog_confirm);
|
||||
alertdialog_confirm.setText(confirm);
|
||||
alertdialog_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Utils.log("packageName = "
|
||||
+ PackageUtils.getPackageNameByPath(context, path));
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(context, path), path);
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context,
|
||||
path));
|
||||
dialog.dismiss();
|
||||
if (cmListener != null) {
|
||||
cmListener.onConfirem();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setOnDismissListener(new Dialog.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
isShow = false;
|
||||
}
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private static boolean isShowHijackDialog = false;
|
||||
|
||||
public static void showHijackDialog(final Context context) {
|
||||
if (!isShowHijackDialog) {
|
||||
final Dialog dialog = new Dialog(context);
|
||||
View view = View.inflate(context,
|
||||
R.layout.search_history_delete_dialog, null);
|
||||
TextView title = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("警告");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
|
||||
content.setText("您当前网络环境异常,下载地址已被替换(网络劫持),请更换网络环境进行下载。");
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("确定");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 跳转wifi管理界面
|
||||
Intent intent = new Intent("android.settings.WIFI_SETTINGS");
|
||||
context.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.setOnDismissListener(new Dialog.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
isShowHijackDialog = false;
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
isShowHijackDialog = true;
|
||||
}
|
||||
showWarningDialog(context, "警告", "您当前网络环境异常,下载地址已被替换(网络劫持),请更换网络环境进行下载。",
|
||||
new ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
// 跳转wifi管理界面
|
||||
Intent intent = new Intent("android.settings.WIFI_SETTINGS");
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isShowDeleteDialog = false;
|
||||
|
||||
public static void showDeleteDialog(final Context context, final String path) {
|
||||
if (!isShowDeleteDialog) {
|
||||
final Dialog dialog = new Dialog(context);
|
||||
View view = View.inflate(context,
|
||||
R.layout.search_history_delete_dialog, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("卸载");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
|
||||
content.setText("您已安装了官方原版,该版本与插件版本冲突,是否卸载官方原版?");
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("忽略");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
TextView confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("卸载");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(context, path), path);
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context,
|
||||
path));
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.setOnDismissListener(new Dialog.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
isShowDeleteDialog = false;
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
isShowDeleteDialog = true;
|
||||
}
|
||||
public static void showWarningDialog(Context context, String title, CharSequence msg, final ConfiremListener listener) {
|
||||
showWarningDialog(context, title, msg, "取消", "确定", listener, null);
|
||||
}
|
||||
|
||||
public static void showDownloadDialog(Context context, ConfiremListener listener) {
|
||||
showWarningDialog(context, "下载提示", "您当前使用的网络为2G/3G/4G,开始下载将会消耗移动流量,确定下载?", listener);
|
||||
}
|
||||
|
||||
public static void showCancelDialog(Context context, final ConfiremListener listener) {
|
||||
Spanned content = Html.fromHtml("取消关注游戏后,您将无法及时收到游戏" +
|
||||
"<font color='#ff0000'>攻略</font>、" +
|
||||
"<font color='#ff0000'>资讯</font>等最新动态提醒。");
|
||||
showWarningDialog(context, "取消关注", content, "暂不取消", "确定取消", listener, null);
|
||||
}
|
||||
|
||||
public static void showPluginDialog(Context context, final ConfiremListener listener) {
|
||||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||||
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
|
||||
+ "<font color=\"#ff0000\">安装插件版本</font>" + "。");
|
||||
showWarningDialog(context, "插件化安装", spanned, listener);
|
||||
}
|
||||
|
||||
public static void showDisclaimerDialog(Context context, String content) {
|
||||
final Dialog disclaimerDialog = new Dialog(context);
|
||||
View view = View.inflate(context, R.layout.dialog_disclaimer, null);
|
||||
|
||||
// TextView title = (TextView) view.findViewById(R.id.disclaimer_title);
|
||||
// title.setText("免责声明");
|
||||
|
||||
TextView message = (TextView) view.findViewById(R.id.disclaimer_message);
|
||||
Spanned spanned = Html.fromHtml(content);
|
||||
message.setText(spanned);
|
||||
|
||||
view.findViewById(R.id.disclaimer_confirm).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
disclaimerDialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
disclaimerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
disclaimerDialog.setContentView(view);
|
||||
disclaimerDialog.show();
|
||||
}
|
||||
|
||||
public interface ConfiremListener{
|
||||
void onConfirem();
|
||||
}
|
||||
|
||||
public interface CancelListener{
|
||||
void onCancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ public class DisplayUtils {
|
||||
* 将px值转换为sp值,保证文字大小不变
|
||||
*
|
||||
* @param pxValue
|
||||
* @param fontScale
|
||||
* @param pxValue
|
||||
* (DisplayMetrics类中属性scaledDensity)
|
||||
* @return
|
||||
*/
|
||||
@ -38,7 +38,7 @@ public class DisplayUtils {
|
||||
* 将sp值转换为px值,保证文字大小不变
|
||||
*
|
||||
* @param spValue
|
||||
* @param fontScale
|
||||
* @param spValue
|
||||
* (DisplayMetrics类中属性scaledDensity)
|
||||
* @return
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -134,9 +134,7 @@ public class FileUtils {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static float getFreeSpaceByPath(String path) {
|
||||
StatFs statfs = new StatFs(path);
|
||||
|
||||
long blockSize = statfs.getBlockSize();
|
||||
|
||||
long availableBlocks = statfs.getAvailableBlocks();
|
||||
|
||||
return availableBlocks * blockSize / 1024f / 1024f;
|
||||
@ -168,8 +166,7 @@ public class FileUtils {
|
||||
DataInputStream dis = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url)
|
||||
.openConnection();
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(5 * 1000);
|
||||
@ -193,7 +190,7 @@ public class FileUtils {
|
||||
dis.close();
|
||||
}
|
||||
return code;
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
} finally {
|
||||
@ -207,7 +204,7 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
public static String uploadFile(String url, String filePath, String token) {
|
||||
public static JSONObject uploadFile(String url, String filePath, String token) {
|
||||
String end = "\r\n";
|
||||
String twoHyphens = "--";
|
||||
String boundary = UUID.randomUUID().toString().replaceAll("-", "")
|
||||
@ -220,21 +217,23 @@ public class FileUtils {
|
||||
* post method must write something to the connection
|
||||
*/
|
||||
connection.setDoOutput(true);
|
||||
/* Read from the connection. Default is true. */
|
||||
// Read from the connection. Default is true.
|
||||
connection.setDoInput(true);
|
||||
/* Post cannot use caches */
|
||||
// Post cannot use caches
|
||||
connection.setUseCaches(false);
|
||||
/* Set the post method. Default is GET */
|
||||
// Set the post method. Default is GET
|
||||
connection.setRequestMethod("POST");
|
||||
/* 设置请求属性 */
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(5 * 1000);
|
||||
// 设置请求属性
|
||||
connection.setRequestProperty("Connection", "Keep-Alive");
|
||||
connection.setRequestProperty("Charset", "UTF-8");
|
||||
connection.setRequestProperty("Content-Type",
|
||||
"multipart/form-data;boundary=" + boundary);
|
||||
if (token != null) {
|
||||
connection.setRequestProperty("Auth", token);
|
||||
connection.setRequestProperty("TOKEN", token);
|
||||
}
|
||||
/* 设置StrictMode 否则HTTPURLConnection连接失败,因为这是在主进程中进行网络连接 */
|
||||
// 设置StrictMode 否则HTTPURLConnection连接失败,因为这是在主进程中进行网络连接
|
||||
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
|
||||
.detectDiskReads().detectDiskWrites().detectNetwork()
|
||||
.penaltyLog().build());
|
||||
@ -243,57 +242,63 @@ public class FileUtils {
|
||||
Utils.log("name = " + file.getName());
|
||||
Utils.log("length = " + file.length());
|
||||
}
|
||||
/* 设置DataOutputStream,getOutputStream中默认调用connect() */
|
||||
// 设置DataOutputStream,getOutputStream中默认调用connect()
|
||||
DataOutputStream dos = new DataOutputStream(
|
||||
connection.getOutputStream()); // output
|
||||
// to
|
||||
// the
|
||||
// connection
|
||||
// to the connection
|
||||
dos.writeBytes(twoHyphens + boundary + end);
|
||||
dos.writeBytes("Content-Disposition: form-data; "
|
||||
+ "name=\"Filedata\";filename=\"" + file.getName() + "\""
|
||||
+ end);
|
||||
dos.writeBytes(end);
|
||||
/* 取得文件的FileInputStream */
|
||||
// 取得文件的FileInputStream
|
||||
FileInputStream fStream = new FileInputStream(file);
|
||||
/* 设置每次写入8192bytes */
|
||||
// 设置每次写入8192bytes
|
||||
int bufferSize = 8192;
|
||||
byte[] buffer = new byte[bufferSize]; // 8k
|
||||
int length = -1;
|
||||
/* 从文件读取数据至缓冲区 */
|
||||
// 从文件读取数据至缓冲区
|
||||
while ((length = fStream.read(buffer)) != -1) {
|
||||
/* 将资料写入DataOutputStream中 */
|
||||
// 将资料写入DataOutputStream中
|
||||
dos.write(buffer, 0, length);
|
||||
}
|
||||
dos.writeBytes(end);
|
||||
dos.writeBytes(twoHyphens + boundary + twoHyphens + end);
|
||||
/* 关闭流,写入的东西自动生成Http正文 */
|
||||
// 关闭流,写入的东西自动生成Http正文
|
||||
fStream.close();
|
||||
/* 关闭DataOutputStream */
|
||||
// 关闭DataOutputStream
|
||||
dos.flush();
|
||||
dos.close();
|
||||
|
||||
/* 从返回的输入流读取响应信息 */
|
||||
InputStream is = connection.getInputStream(); // input from the
|
||||
// connection
|
||||
// 正式建立HTTP连接
|
||||
Utils.log("con.getResponseCode() = " + connection.getResponseCode());
|
||||
InputStream inputStream;
|
||||
try {
|
||||
inputStream = connection.getInputStream();
|
||||
} catch (IOException ioe) {
|
||||
inputStream = connection.getErrorStream();
|
||||
}
|
||||
int ch;
|
||||
StringBuffer b = new StringBuffer();
|
||||
while ((ch = is.read()) != -1) {
|
||||
while ((ch = inputStream.read()) != -1) {
|
||||
b.append((char) ch);
|
||||
}
|
||||
/* 显示网页响应内容 */
|
||||
// 显示网页响应内容
|
||||
Utils.log("content = " + b.toString().trim());
|
||||
|
||||
// {"status":"success","url":"http:\/\/api.ghzhushou.com\/temp\/5688e548d7859e6f278b4567.jpg"}
|
||||
if (connection.getResponseCode() == HttpStatus.SC_OK) {
|
||||
int statusCode = connection.getResponseCode();
|
||||
Utils.log("statusCode = " + statusCode);
|
||||
if (statusCode == HttpStatus.SC_OK) {
|
||||
// {"icon":"http:\/\/gh-test-1.oss-cn-qingdao.aliyuncs.com\/pic\/57e4f4d58a3200042d29492f.jpg"}
|
||||
JSONObject response = new JSONObject(b.toString().trim());
|
||||
if ("success".equals(response.getString("status"))) {
|
||||
return response.getString("url");
|
||||
}
|
||||
response.put("statusCode", HttpStatus.SC_OK);
|
||||
return response;
|
||||
} else if (statusCode == HttpStatus.SC_FORBIDDEN) {
|
||||
JSONObject response = new JSONObject(b.toString().trim());
|
||||
response.put("statusCode", HttpStatus.SC_FORBIDDEN);
|
||||
return response;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
/* 显示异常信息 */
|
||||
// 显示异常信息
|
||||
e.printStackTrace();
|
||||
Utils.log("Fail:" + e);
|
||||
}
|
||||
return null;
|
||||
|
||||
37
app/src/main/java/com/gh/common/util/GameUtils.java
Normal file
37
app/src/main/java/com/gh/common/util/GameUtils.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.gamecenter.GameDetailActivity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/29.
|
||||
*/
|
||||
public class GameUtils {
|
||||
|
||||
/**
|
||||
* 启动游戏详情页面
|
||||
*/
|
||||
public static void startGameDetailActivity(Context context, GameEntity gameEntity, String entrance) {
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
Intent intent = new Intent(context, GameDetailActivity.class);
|
||||
intent.putExtra("entrance", entrance);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动游戏详情页面
|
||||
*/
|
||||
public static void startGameDetailActivity(Context context, String gameId, String entrance) {
|
||||
Intent intent = new Intent(context, GameDetailActivity.class);
|
||||
intent.putExtra("gameId", gameId);
|
||||
intent.putExtra("entrance", entrance);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,66 +26,66 @@ import java.util.TimeZone;
|
||||
*/
|
||||
public class GameViewUtils {
|
||||
|
||||
public static void setLabelList(Context context, LinearLayout labelLayout,
|
||||
List<String> tag) {
|
||||
public static void setLabelList(Context context, LinearLayout labelLayout, List<String> tag) {
|
||||
labelLayout.removeAllViews();
|
||||
if (tag == null || tag.isEmpty()) {
|
||||
labelLayout.addView(getGameTagView(context, "官方版"));
|
||||
labelLayout.addView(getGameTagView(context, "官方版", 0));
|
||||
} else {
|
||||
for (int i = 0, size = tag.size() > 3 ? 3 : tag.size(); i < size; i++) {
|
||||
labelLayout.addView(getGameTagView(context, tag.get(i)));
|
||||
if (i == size - 1) {
|
||||
labelLayout.addView(getGameTagView(context, tag.get(i), 0));
|
||||
} else {
|
||||
labelLayout.addView(getGameTagView(context, tag.get(i), DisplayUtils.dip2px(context, 5)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取游戏标签列表视图
|
||||
public static void setLabelList(Context context, LinearLayout labelLayout,
|
||||
String tag) {
|
||||
public static void setLabelList(Context context, LinearLayout labelLayout, String tag) {
|
||||
labelLayout.removeAllViews();
|
||||
// 添加tag标签
|
||||
if (tag != null && !tag.isEmpty()) {
|
||||
String[] tags = tag.split(",");
|
||||
for (int i = 0; i < tags.length; i++) {
|
||||
labelLayout.addView(getGameTagView(context, tags[i]));
|
||||
if (i == tags.length - 1) {
|
||||
labelLayout.addView(getGameTagView(context, tags[i], 0));
|
||||
} else {
|
||||
labelLayout.addView(getGameTagView(context, tags[i], DisplayUtils.dip2px(context, 5)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TextView getGameTagView(Context context, String tagStr) {
|
||||
LayoutParams lp = new LayoutParams(
|
||||
public static TextView getGameTagView(Context context, String tagStr, int rightMargin) {
|
||||
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
lp.setMargins(0, 0, DisplayUtils.dip2px(context, 5), 0);
|
||||
lparams.rightMargin = rightMargin;
|
||||
TextView tag = new TextView(context);
|
||||
tag.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
|
||||
tag.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
|
||||
tag.setSingleLine(true);
|
||||
tag.setText(tagStr);
|
||||
if ("官方版".equals(tagStr) || "已关注".equals(tagStr)) {
|
||||
tag.setBackgroundResource(R.drawable.border_red_bg);
|
||||
tag.setTextColor(0xffbc2132);
|
||||
} else if ("已安装".equals(tagStr)) {
|
||||
tag.setBackgroundResource(R.drawable.border_blue_bg);
|
||||
tag.setTextColor(0xff1BA4FC);
|
||||
} else {
|
||||
tag.setBackgroundResource(R.drawable.border_green_bg);
|
||||
tag.setTextColor(0xff2ec991);
|
||||
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));
|
||||
}
|
||||
tag.setLayoutParams(lp);
|
||||
tag.setPadding(DisplayUtils.dip2px(context, 4),
|
||||
DisplayUtils.dip2px(context, 2),
|
||||
DisplayUtils.dip2px(context, 4),
|
||||
DisplayUtils.dip2px(context, 2));
|
||||
tag.setLayoutParams(lparams);
|
||||
tag.setPadding(DisplayUtils.dip2px(context, 3),
|
||||
0,
|
||||
DisplayUtils.dip2px(context, 3),
|
||||
DisplayUtils.dip2px(context, 1));
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static String getGameTestDate(long testTime) {
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
|
||||
Locale.CHINA);
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
|
||||
format.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||
|
||||
String testDate;
|
||||
|
||||
try {
|
||||
long today = format.parse(format.format(new Date())).getTime();
|
||||
long day = Long.parseLong(testTime + "000");
|
||||
|
||||
@ -15,8 +15,7 @@ public class GzipUtils {
|
||||
/*
|
||||
* 数据压缩
|
||||
*/
|
||||
public static void compress(InputStream is, OutputStream os)
|
||||
throws IOException {
|
||||
public static void compress(InputStream is, OutputStream os) throws IOException {
|
||||
GZIPOutputStream gos = null;
|
||||
try {
|
||||
gos = new GZIPOutputStream(os);
|
||||
@ -38,8 +37,7 @@ public class GzipUtils {
|
||||
/*
|
||||
* 数据解压缩
|
||||
*/
|
||||
public static void decompress(InputStream is, OutputStream os)
|
||||
throws IOException {
|
||||
public static void decompress(InputStream is, OutputStream os) throws IOException {
|
||||
GZIPInputStream gis = null;
|
||||
try {
|
||||
gis = new GZIPInputStream(is);
|
||||
@ -112,4 +110,5 @@ public class GzipUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ import dalvik.system.PathClassLoader;
|
||||
|
||||
/* compiled from: ProGuard */
|
||||
public final class HotFix {
|
||||
|
||||
public static void patch(Context context, String patchDexFile, String patchClassName) {
|
||||
if (patchDexFile != null && new File(patchDexFile).exists()) {
|
||||
try {
|
||||
@ -153,4 +154,5 @@ public final class HotFix {
|
||||
}
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
}
|
||||
65
app/src/main/java/com/gh/common/util/HttpsUtils.java
Normal file
65
app/src/main/java/com/gh/common/util/HttpsUtils.java
Normal file
@ -0,0 +1,65 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import java.net.URL;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/10/8.
|
||||
*/
|
||||
public class HttpsUtils {
|
||||
|
||||
private static class MyTrustManager implements X509TrustManager {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
||||
throws CertificateException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType)
|
||||
|
||||
throws CertificateException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class MyHostnameVerifier implements HostnameVerifier {
|
||||
@Override
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static SSLSocketFactory mSSLSocketFactory;
|
||||
private static HostnameVerifier mHostnameVerifier;
|
||||
|
||||
public static HttpsURLConnection getHttpsURLConnection(URL url) throws Exception {
|
||||
if (mSSLSocketFactory == null || mHostnameVerifier == null) {
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, new TrustManager[]{new MyTrustManager()}, new SecureRandom());
|
||||
mSSLSocketFactory = sc.getSocketFactory();
|
||||
|
||||
mHostnameVerifier = new MyHostnameVerifier();
|
||||
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(mSSLSocketFactory);
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(mHostnameVerifier);
|
||||
}
|
||||
return (HttpsURLConnection) url.openConnection();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,7 +2,10 @@ package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Matrix;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
@ -13,15 +16,18 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class ImageUtils {
|
||||
private static ImageUtils singleton;
|
||||
private static ImageLoader imageLoader;
|
||||
private static DisplayImageOptions options;
|
||||
private static ImageUtils singleton;
|
||||
private static ImageLoader imageLoader;
|
||||
private static DisplayImageOptions options;
|
||||
private ArrayMap<String, WeakReference<Bitmap>> imageCache = new ArrayMap<String, WeakReference<Bitmap>>();
|
||||
|
||||
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
|
||||
|
||||
@ -39,18 +45,21 @@ public class ImageUtils {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
private ImageUtils(Context context, int size) {
|
||||
private ImageUtils(Context context, int size) {
|
||||
|
||||
options = new DisplayImageOptions.Builder().cacheInMemory(true)
|
||||
.cacheOnDisk(true).considerExifParams(true)
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)
|
||||
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
|
||||
// .showImageOnLoading(R.drawable.ocupy)
|
||||
// .showImageForEmptyUri(R.drawable.ocupy)
|
||||
// .showImageOnFail(R.drawable.ocupy)
|
||||
.build();
|
||||
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
|
||||
context).writeDebugLogs().build();
|
||||
context).writeDebugLogs()
|
||||
.memoryCacheExtraOptions(480, 800)
|
||||
.build();
|
||||
|
||||
ImageLoader.getInstance().init(config);
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
@ -86,6 +95,10 @@ public class ImageUtils {
|
||||
|
||||
});
|
||||
}
|
||||
//增加一个上下文环境,图片宽度设最大(paddSize为左右边距大小),高度自适应
|
||||
public void display(String url, ImageView imageView, int drawable, Context context, int paddingSize) {
|
||||
display(url, imageView, drawable, ScaleType.FIT_XY, null, context, paddingSize);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, int drawable) {
|
||||
display(url, imageView, drawable, ScaleType.FIT_XY, null);
|
||||
@ -111,8 +124,14 @@ public class ImageUtils {
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
imageView.setImageResource(drawable);
|
||||
if (imageView instanceof CircleImageView) {
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
}
|
||||
if (drawable != -1) {
|
||||
imageView.setImageResource(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,17 +147,138 @@ public class ImageUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, null);
|
||||
public void display(final String url, final ImageView imageView,
|
||||
final int drawable, final ScaleType scaleType,
|
||||
final OnLoadingCompleteListener listener, final Context context, final int paddSize) {
|
||||
imageLoader.displayImage(url, imageView, options,
|
||||
new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view,
|
||||
Bitmap loadedImage) {
|
||||
int width = loadedImage.getWidth();
|
||||
int height = loadedImage.getHeight();
|
||||
int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
|
||||
widthPixels = widthPixels - DisplayUtils.dip2px(context,paddSize);
|
||||
float index = (float) height / (float) width;
|
||||
int newHeight = (int)(index * widthPixels);
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
|
||||
if (layoutParams != null){
|
||||
layoutParams.height = newHeight;
|
||||
layoutParams.width = widthPixels;
|
||||
imageView.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
if (imageView instanceof CircleImageView) {
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
imageView.setScaleType(scaleType);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onLoadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
if (drawable != -1) {
|
||||
imageView.setImageResource(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view,
|
||||
FailReason reason) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null);
|
||||
public void display(final String url, final ImageView imageView,
|
||||
final int drawable, final ScaleType scaleType,
|
||||
final OnLoadingCompleteListener listener, final int i) {
|
||||
imageLoader.displayImage(url, imageView, options,
|
||||
new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view,
|
||||
Bitmap loadedImage) {
|
||||
WeakReference<Bitmap> bitmapWeakReference = imageCache.get(imageUri);
|
||||
try {
|
||||
if (bitmapWeakReference!=null){
|
||||
Bitmap bitmap = bitmapWeakReference.get();
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}else {
|
||||
Matrix m = new Matrix();
|
||||
m.setRotate(i, (float) loadedImage.getWidth() / 2, (float) loadedImage.getHeight() / 2);
|
||||
Bitmap bm1 = Bitmap.createBitmap(loadedImage, 0, 0, loadedImage.getWidth(), loadedImage.getHeight(), m, true);
|
||||
imageView.setImageBitmap(bm1);
|
||||
WeakReference<Bitmap> weakBM = new WeakReference<Bitmap>(bm1);
|
||||
imageCache.put(imageUri, weakBM);
|
||||
}
|
||||
|
||||
} catch (OutOfMemoryError ex) {
|
||||
Utils.log("Bitmap:::内存溢出");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (imageView instanceof CircleImageView) {
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
imageView.setScaleType(scaleType);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onLoadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
if (drawable != -1) {
|
||||
imageView.setImageResource(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view,
|
||||
FailReason reason) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//获取图片BitMap
|
||||
public void loadBitmap(String url, ImageLoadingListener listener){
|
||||
imageLoader.loadImage(url, listener);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, listener);
|
||||
}
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, null);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null);
|
||||
}
|
||||
|
||||
//旋转图片 i表示角度
|
||||
public void display(String url, ImageView imageView, int i, boolean isHorizontal) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null, i);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, listener);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, listener);
|
||||
|
||||
@ -9,9 +9,11 @@ import java.io.RandomAccessFile;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Installation {
|
||||
private static String sID = null;
|
||||
|
||||
private static final String INSTALLATION = "INSTALLATION";
|
||||
|
||||
private static String sID = null;
|
||||
|
||||
public synchronized static String getUUID(Context context) {
|
||||
if (sID == null) {
|
||||
File installation = new File(context.getFilesDir(), INSTALLATION);
|
||||
@ -42,4 +44,5 @@ public class Installation {
|
||||
out.write(id.getBytes());
|
||||
out.close();
|
||||
}
|
||||
|
||||
}
|
||||
@ -74,4 +74,5 @@ public class MD5Utils {
|
||||
BigInteger bigInt = new BigInteger(1, digest.digest());
|
||||
return bigInt.toString(16);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
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 2016/8/22.
|
||||
* RecyclerView 自适应高度
|
||||
*/
|
||||
public class MeasureHeightLayoutManager extends LinearLayoutManager {
|
||||
|
||||
public MeasureHeightLayoutManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private int[] mMeasuredDimension = new int[1];
|
||||
|
||||
@Override
|
||||
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state,
|
||||
int widthSpec, int heightSpec) {
|
||||
|
||||
final int heightSize = View.MeasureSpec.getSize(heightSpec);
|
||||
|
||||
int height = 0;
|
||||
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];
|
||||
|
||||
}
|
||||
if (height > heightSize){
|
||||
super.onMeasure(recycler, state, widthSpec, heightSpec);
|
||||
}else {
|
||||
setMeasuredDimension(View.MeasureSpec.getSize(widthSpec), height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
|
||||
int heightSpec, int[] measuredDimension) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -9,8 +9,7 @@ public class NetworkUtils {
|
||||
/**
|
||||
* 判断是否有网络连接
|
||||
*
|
||||
* @param context
|
||||
* 上下文
|
||||
* @param context 上下文
|
||||
* @return true 有网络连接 false 无网络连接
|
||||
*/
|
||||
public static boolean isNetworkConnected(Context context) {
|
||||
@ -29,8 +28,7 @@ public class NetworkUtils {
|
||||
/**
|
||||
* 判断WIFI网络是否可用
|
||||
*
|
||||
* @param context
|
||||
* 上下文
|
||||
* @param context 上下文
|
||||
* @return true wifi可用 false wifi不可用
|
||||
*/
|
||||
public static boolean isWifiConnected(Context context) {
|
||||
@ -49,8 +47,7 @@ public class NetworkUtils {
|
||||
/**
|
||||
* 判断MOBILE网络是否可用
|
||||
*
|
||||
* @param context
|
||||
* 上下文
|
||||
* @param context 上下文
|
||||
* @return true mobile可用 false mobile不可用
|
||||
*/
|
||||
public static boolean isMobileConnected(Context context) {
|
||||
@ -106,4 +103,5 @@ public class NetworkUtils {
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,10 +3,12 @@ package com.gh.common.util;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.gh.gamecenter.NewsActivity;
|
||||
import com.android.volley.Request;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.NewsDetailsEntity;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
|
||||
public class NewsUtils {
|
||||
|
||||
@ -36,18 +38,26 @@ public class NewsUtils {
|
||||
* @param entrance
|
||||
* @return
|
||||
*/
|
||||
public static void startNewsActivity(Context context,
|
||||
NewsEntity newsEntity, String entrance) {
|
||||
Intent intent = new Intent(context, NewsActivity.class);
|
||||
NewsDetailsEntity entity = new NewsDetailsEntity();
|
||||
entity.setId(newsEntity.getId());
|
||||
entity.setTitle(newsEntity.getTitle());
|
||||
entity.setType(newsEntity.getType());
|
||||
entity.setTime(newsEntity.getPublishOn());
|
||||
intent.putExtra("entity", entity);
|
||||
public static void startNewsActivity(Context context, NewsEntity newsEntity, String entrance) {
|
||||
Intent intent = new Intent(context, NewsDetailActivity.class);
|
||||
intent.putExtra("id", newsEntity.getId());
|
||||
intent.putExtra("title", newsEntity.getTitle());
|
||||
intent.putExtra("type", newsEntity.getType());
|
||||
intent.putExtra("entrance", entrance);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计阅读量
|
||||
* @param news_id
|
||||
*/
|
||||
public static void statNewsViews(String news_id) {
|
||||
String url = "http://data.ghzhushou.com/news/stat?news_id=" + news_id;
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Request.Method.POST, url, null, null);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -133,6 +133,70 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断是否是插件包
|
||||
*/
|
||||
public static boolean isSignature(Context context, String packageName) {
|
||||
String signature = getApkSignatureByPackageName(context, packageName);
|
||||
if (publicKey.equals(signature)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据apk路径,获取apk包名、签名 根据包名 判断 是否已安装游戏 根据签名 判断 是否一致
|
||||
*
|
||||
* @param path apk路径
|
||||
* @return true 可执行安装 false 要卸载已安装的,再执行安装
|
||||
*/
|
||||
public static boolean isCanLaunchSetup(Context context, String path) {
|
||||
String packageName = getPackageNameByPath(context, path);
|
||||
|
||||
boolean isContain = isContain(context, packageName);
|
||||
if (!isContain) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean isInstalled = isInstalled(context, packageName);
|
||||
if (!isInstalled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String signature = getApkSignatureByPackageName(context, packageName);
|
||||
return publicKey.equals(signature);
|
||||
}
|
||||
|
||||
/*
|
||||
* 启动安装应用程序
|
||||
*/
|
||||
public static void launchSetup(final Context context, final String path) {
|
||||
if (isCanLaunchSetup(context, path)) {
|
||||
context.startActivity(PackageUtils.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showPluginDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context, path));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取应用第一次安装的时间
|
||||
*/
|
||||
public static long getInstalledTime(Context context, String packageName) {
|
||||
try {
|
||||
PackageInfo packageInfo = context.getPackageManager()
|
||||
.getPackageInfo(packageName, 0);
|
||||
return packageInfo.firstInstallTime;
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 解析签名
|
||||
*/
|
||||
@ -175,11 +239,17 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已安装的软件的包名、版本(非系统应用)
|
||||
*
|
||||
* @param context
|
||||
* 上下文
|
||||
* @return 已安装软件的包名的集合
|
||||
*/
|
||||
public static ArrayList<String> getAllPackageName(Context context) {
|
||||
FilterManager filterManager = new FilterManager(context);
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
List<PackageInfo> packageInfos = context.getPackageManager()
|
||||
.getInstalledPackages(0);
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
List<PackageInfo> packageInfos = context.getPackageManager().getInstalledPackages(0);
|
||||
for (int i = 0, size = packageInfos.size(); i < size; i++) {
|
||||
PackageInfo packageInfo = packageInfos.get(i);
|
||||
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
|
||||
@ -239,7 +309,7 @@ public class PackageUtils {
|
||||
return false;
|
||||
}
|
||||
if (map == null) {
|
||||
map = new ArrayMap<String, Boolean>();
|
||||
map = new ArrayMap<>();
|
||||
List<PackageInfo> infos = context.getPackageManager()
|
||||
.getInstalledPackages(0);
|
||||
for (PackageInfo info : infos) {
|
||||
|
||||
@ -11,10 +11,8 @@ import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.SplashScreenActivity;
|
||||
import com.gh.gamecenter.eventbus.EBPlatformChanged;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
@ -33,15 +31,15 @@ import de.greenrobot.event.EventBus;
|
||||
|
||||
public class PlatformUtils {
|
||||
|
||||
private static PlatformUtils mInstance;
|
||||
|
||||
private Context context;
|
||||
|
||||
private ArrayMap<String, String> platformMap;
|
||||
private ArrayMap<String, Integer> platformPicMap;
|
||||
private ArrayMap<String, String> platformPicUrlMap;
|
||||
private ArrayMap<String, String> platformColorMap;
|
||||
|
||||
private static PlatformUtils mInstance;
|
||||
|
||||
private Context context;
|
||||
|
||||
private PlatformUtils(Context con) {
|
||||
this.context = con.getApplicationContext();
|
||||
initMap();
|
||||
@ -189,7 +187,7 @@ public class PlatformUtils {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EventBus.getDefault().post(new EBPlatformChanged());
|
||||
EventBus.getDefault().post(new EBReuse("PlatformChanged"));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -214,7 +212,7 @@ public class PlatformUtils {
|
||||
if (color != null) {
|
||||
return color;
|
||||
}
|
||||
return "#1BA4FC";
|
||||
return "#00B7FA";
|
||||
}
|
||||
|
||||
public int getPlatformPic(String platform) {
|
||||
@ -224,7 +222,7 @@ public class PlatformUtils {
|
||||
}
|
||||
Integer id = platformPicMap.get(platform);
|
||||
if (id != null) {
|
||||
return id.intValue();
|
||||
return id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -270,32 +268,25 @@ public class PlatformUtils {
|
||||
}
|
||||
isUpdate = true;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/support/setting/platform",
|
||||
Constants.PLATFORM_CD),
|
||||
Config.HOST + "v1d45/support/setting/platform",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
try {
|
||||
Set<String> pset = new HashSet<String>();
|
||||
Set<String> platformSet = new HashSet<>();
|
||||
for (int i = 0; i < response.length(); i++) {
|
||||
JSONObject jsonObject = response
|
||||
.getJSONObject(i);
|
||||
JSONObject jsonObject = response.getJSONObject(i);
|
||||
String code = jsonObject.getString("code");
|
||||
String name = jsonObject.getString("name");
|
||||
String pic = jsonObject.getString("pic");
|
||||
String color = jsonObject.getString("color");
|
||||
pset.add(code + "=" + name + "=" + pic + "="
|
||||
+ color);
|
||||
platformSet.add(code + "=" + name + "=" + pic + "=" + color);
|
||||
}
|
||||
SharedPreferences sharedPreferences = context
|
||||
.getSharedPreferences("gh_platform",
|
||||
Context.MODE_PRIVATE);
|
||||
Editor editor = sharedPreferences.edit();
|
||||
editor.putStringSet("platform", pset);
|
||||
editor.apply();
|
||||
SharedPreferences sp = context.getSharedPreferences(
|
||||
"gh_platform", Context.MODE_PRIVATE);
|
||||
sp.edit().putStringSet("platform", platformSet).apply();
|
||||
initMap();
|
||||
EventBus.getDefault().post(new EBPlatformChanged());
|
||||
EventBus.getDefault().post(new EBReuse("PlatformChanged"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -307,6 +298,7 @@ public class PlatformUtils {
|
||||
isUpdate = false;
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -43,7 +43,6 @@ public class RSEUtils {
|
||||
* 使用公钥加密
|
||||
*
|
||||
* @param content
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String encryptByPublic(String content) {
|
||||
@ -68,10 +67,7 @@ public class RSEUtils {
|
||||
/**
|
||||
* 使用公钥解密
|
||||
*
|
||||
* @param content
|
||||
* 密文
|
||||
* @param key
|
||||
* 商户私钥
|
||||
* @param content 密文
|
||||
* @return 解密后的字符串
|
||||
*/
|
||||
public static String decryptByPublic(String content) {
|
||||
|
||||
@ -17,7 +17,7 @@ public class RandomUtils {
|
||||
if (i == 0) {
|
||||
index[i] = random.nextInt(size);
|
||||
} else {
|
||||
random(random, index, i, size);
|
||||
index[i] = random(random, index, i, size);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
|
||||
@ -13,7 +13,7 @@ public class RunningUtils {
|
||||
/**
|
||||
* 判断当前应用程序处于前台还是后台
|
||||
*/
|
||||
public static boolean isApplicationBroughtToBackground(final Context context) {
|
||||
public static boolean isApplicationBroughtToBackground(Context context) {
|
||||
ActivityManager am = (ActivityManager) context
|
||||
.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
|
||||
|
||||
519
app/src/main/java/com/gh/common/util/ShareUtils.java
Normal file
519
app/src/main/java/com/gh/common/util/ShareUtils.java
Normal file
@ -0,0 +1,519 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
import com.tencent.connect.share.QQShare;
|
||||
import com.tencent.connect.share.QzoneShare;
|
||||
import com.tencent.mm.sdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.sdk.openapi.SendMessageToWX;
|
||||
import com.tencent.mm.sdk.openapi.WXAPIFactory;
|
||||
import com.tencent.mm.sdk.openapi.WXMediaMessage;
|
||||
import com.tencent.mm.sdk.openapi.WXWebpageObject;
|
||||
import com.tencent.mm.sdk.platformtools.Util;
|
||||
import com.tencent.tauth.IUiListener;
|
||||
import com.tencent.tauth.Tencent;
|
||||
import com.tencent.tauth.UiError;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import cn.sharesdk.framework.Platform;
|
||||
import cn.sharesdk.framework.PlatformActionListener;
|
||||
import cn.sharesdk.framework.ShareSDK;
|
||||
import cn.sharesdk.sina.weibo.SinaWeibo;
|
||||
import cn.sharesdk.system.text.ShortMessage;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/9/4.
|
||||
*/
|
||||
public class ShareUtils {
|
||||
private static ShareUtils instance;
|
||||
|
||||
private String shareUrl;
|
||||
private String shareGameName;
|
||||
private String shareIcon;
|
||||
private String shareNewsTitle; // shareNewsTitle不为空就是新闻分享,否则是游戏分享
|
||||
|
||||
private boolean isPlugin = false;
|
||||
|
||||
private static IWXAPI api;
|
||||
private static Tencent mTencent;
|
||||
|
||||
private Handler handler;
|
||||
|
||||
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
|
||||
, R.drawable.share_copyfont_logo, R.drawable.share_cancel_logo};
|
||||
private String[] arrLabel = {"微信好友", "朋友圈", "QQ好友", "QQ空间", "新浪微博", "短信", "复制链接", "取消"};
|
||||
|
||||
private PopupWindow popupWindow;
|
||||
|
||||
private Context context;
|
||||
|
||||
public static ShareUtils getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = new ShareUtils();
|
||||
mTencent = Tencent.createInstance("1104659243", context); //初始化QQ分享
|
||||
api = WXAPIFactory.createWXAPI(context, "wx3ffd0785fad18396"); //初始化微信分享
|
||||
}
|
||||
instance.context = context;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void showShareWindows(View view, String url, String gameName, String icon ,String newsTitle, boolean isPlugin){
|
||||
this.shareIcon = icon;
|
||||
this.shareGameName = gameName;
|
||||
this.shareUrl = url;
|
||||
this.shareNewsTitle = newsTitle;
|
||||
this.isPlugin = isPlugin;
|
||||
|
||||
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){
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
shareRecyclerView.setLayoutManager(gridLayoutManager);
|
||||
shareRecyclerView.setAdapter(new ShareRecyclerViewAdapter());
|
||||
|
||||
RelativeLayout.LayoutParams rlParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
|
||||
, DisplayUtils.dip2px(context, 200));
|
||||
rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
contentView.addView(shareRecyclerView,rlParams);
|
||||
|
||||
popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
||||
, LinearLayout.LayoutParams.MATCH_PARENT, true);
|
||||
popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
|
||||
popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
|
||||
|
||||
contentView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
contentView.setOnKeyListener(new View.OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK
|
||||
&& event.getRepeatCount() == 0 && popupWindow != null
|
||||
&& popupWindow.isShowing()) {
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class ShareRecyclerViewAdapter extends RecyclerView.Adapter<ShareRecyclerViewAdapter.ViewHolder>{
|
||||
|
||||
@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.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, 45), DisplayUtils.dip2px(context, 45));
|
||||
logoParams.setMargins(0, DisplayUtils.dip2px(context, 10), 0, 0);
|
||||
shareLogo.setLayoutParams(logoParams);
|
||||
|
||||
TextView shareLabel = new TextView(context);
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.setMargins(0, DisplayUtils.dip2px(context,10), 0, 0);
|
||||
shareLabel.setLayoutParams(layoutParams);
|
||||
shareLabel.setGravity(Gravity.CENTER);
|
||||
shareLabel.setTextColor(Color.parseColor("#3a3a3a"));
|
||||
shareLabel.setTextSize(13);
|
||||
|
||||
linearLayout.addView(shareLogo);
|
||||
linearLayout.addView(shareLabel);
|
||||
|
||||
return new ViewHolder(linearLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||
holder.shareLogo.setImageResource(arrLogo[position]);
|
||||
holder.shareLabel.setText(arrLabel[position]);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (holder.getPosition()){
|
||||
case 0:
|
||||
wechatSahre();
|
||||
break;
|
||||
case 1:
|
||||
wechatMomentsSahre();
|
||||
break;
|
||||
case 2:
|
||||
qqSahre();
|
||||
break;
|
||||
case 3:
|
||||
qZoneSahre();
|
||||
break;
|
||||
case 4:
|
||||
sinaWeiboSahre();
|
||||
break;
|
||||
case 5:
|
||||
shortMessageSahre();
|
||||
break;
|
||||
case 6:
|
||||
copyLink(shareUrl);
|
||||
break;
|
||||
case 7:
|
||||
popupWindow.dismiss();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder{
|
||||
LinearLayout linearLayout;
|
||||
TextView shareLabel;
|
||||
ImageView shareLogo;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
linearLayout = (LinearLayout) itemView;
|
||||
shareLogo = (ImageView) linearLayout.getChildAt(0);
|
||||
shareLabel = (TextView) linearLayout.getChildAt(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//QQ分享
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "光环助手");
|
||||
|
||||
mTencent.shareToQQ(
|
||||
(Activity) context, params,QqShareListener);
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
//微信好友分享
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
||||
req.transaction = buildTransaction("webpage");
|
||||
req.message = msg;
|
||||
req.scene = SendMessageToWX.Req.WXSceneSession;
|
||||
|
||||
loadBitMap(shareIcon, msg, req);
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
//QQ空间分享
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<String> imageUrls = new ArrayList<String>();
|
||||
imageUrls.add(shareIcon);
|
||||
|
||||
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);
|
||||
params.putString(QzoneShare.SHARE_TO_QQ_APP_NAME, "光环助手");
|
||||
|
||||
mTencent.shareToQzone(
|
||||
(Activity) context, params,QqShareListener);
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
//微信朋友圈分享
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
||||
|
||||
req.transaction = buildTransaction("webpage");
|
||||
req.message = msg;
|
||||
req.scene = SendMessageToWX.Req.WXSceneTimeline;
|
||||
|
||||
loadBitMap(shareIcon, msg, req);
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
|
||||
//新浪微博分享
|
||||
private void sinaWeiboSahre(){
|
||||
SinaWeibo.ShareParams sinaWeiboParams = new SinaWeibo.ShareParams();
|
||||
handler = new Handler();
|
||||
|
||||
if (shareNewsTitle != null){
|
||||
sinaWeiboParams.setText(shareNewsTitle + " " + shareUrl);
|
||||
}else {
|
||||
if (isPlugin){
|
||||
sinaWeiboParams.setText("向你推荐:" + shareGameName + "(光环加速版) " + shareUrl);
|
||||
}else {
|
||||
sinaWeiboParams.setText("向你推荐:" + shareGameName + " " + shareUrl);
|
||||
}
|
||||
}
|
||||
sinaWeiboParams.setImageUrl(shareIcon);
|
||||
sharePlatform(sinaWeiboParams, SinaWeibo.NAME);
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Utils.toast(context, "分享成功");
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
//短信分享
|
||||
private void shortMessageSahre(){
|
||||
ShortMessage.ShareParams shortMessageParams = new ShortMessage.ShareParams();
|
||||
|
||||
if (shareNewsTitle != null){
|
||||
shortMessageParams.setText(shareNewsTitle + shareUrl);
|
||||
}else {
|
||||
if (isPlugin){
|
||||
shortMessageParams.setText("向你推荐:" + shareGameName + "(光环加速版)" + shareUrl);
|
||||
}else {
|
||||
shortMessageParams.setText("向你推荐:" + shareGameName + shareUrl);
|
||||
}
|
||||
}
|
||||
shortMessageParams.setUrl(shareUrl);
|
||||
shortMessageParams.setTitleUrl(shareUrl);
|
||||
|
||||
sharePlatform(shortMessageParams, ShortMessage.NAME);
|
||||
}
|
||||
|
||||
//分享平台回调
|
||||
private void sharePlatform(Platform.ShareParams params, String name) {
|
||||
Utils.toast(context,"分享跳转中...");
|
||||
Platform platform = ShareSDK.getPlatform(name);
|
||||
if (platform.getName().equals(SinaWeibo.NAME)){
|
||||
platform.SSOSetting(true);
|
||||
}
|
||||
platform.setPlatformActionListener(new PlatformActionListener() {
|
||||
@Override
|
||||
public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
|
||||
Utils.log("分享成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Platform platform, int i, Throwable throwable) {
|
||||
Utils.log("分享失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Platform platform, int i) {
|
||||
Utils.log("取消分享");
|
||||
}
|
||||
});
|
||||
platform.share(params);
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
|
||||
private String buildTransaction(final String type) {
|
||||
return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
//复制文字链接
|
||||
private void copyLink(String copyContent) {
|
||||
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setText(copyContent);
|
||||
popupWindow.dismiss();
|
||||
|
||||
Utils.toast(context,"复制成功");
|
||||
}
|
||||
|
||||
private void loadBitMap(final String iconUrl, final WXMediaMessage msg, final SendMessageToWX.Req req){
|
||||
ImageUtils.getInstance(context).loadBitmap(iconUrl, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String s, View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String s, View view, FailReason failReason) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String s, View view, Bitmap bitmap) {
|
||||
|
||||
Bitmap compressBp = compressBitmap(bitmap);
|
||||
Bitmap resultBp = addBackGround(compressBp);
|
||||
msg.thumbData = Util.bmpToByteArray(resultBp, true);
|
||||
api.sendReq(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String s, View view) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//添加背景,防止图片格式为PNG的图片分享出现黑框问题
|
||||
private Bitmap addBackGround(Bitmap result) {
|
||||
Bitmap bgBitmap;
|
||||
int[] colors = new int[result.getWidth()*result.getHeight()];
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
colors[i] = Color.WHITE;
|
||||
}
|
||||
bgBitmap = Bitmap.createBitmap(colors, result.getWidth(), result.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
|
||||
Bitmap newmap = Bitmap
|
||||
.createBitmap(result.getWidth(), result.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(newmap);
|
||||
canvas.drawBitmap(bgBitmap, 0, 0, null);
|
||||
canvas.drawBitmap(result, (result.getHeight() - result.getWidth()) / 2,
|
||||
(result.getHeight() - result.getWidth()) / 2, null);
|
||||
canvas.save(Canvas.ALL_SAVE_FLAG);
|
||||
canvas.restore();
|
||||
|
||||
return newmap;
|
||||
}
|
||||
|
||||
//压缩图片
|
||||
private Bitmap compressBitmap(Bitmap bitmap) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, bos);
|
||||
float zoom = (float) Math.sqrt(10 * 1024 / (float) bos.toByteArray().length);
|
||||
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.setScale(zoom, zoom);
|
||||
|
||||
Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||
bos.reset();
|
||||
|
||||
result.compress(Bitmap.CompressFormat.JPEG, 85, bos);
|
||||
|
||||
while(bos.toByteArray().length > 10 * 1024){
|
||||
System.out.println(bos.toByteArray().length);
|
||||
matrix.setScale(0.9f, 0.9f);
|
||||
result = Bitmap.createBitmap(result, 0, 0, result.getWidth(), result.getHeight(), matrix, true);
|
||||
bos.reset();
|
||||
result.compress(Bitmap.CompressFormat.JPEG, 85, bos);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//QQ或者QQ空间分享回调处理
|
||||
public IUiListener QqShareListener = new IUiListener() {
|
||||
@Override
|
||||
public void onComplete(Object o) {
|
||||
Utils.toast(context, "分享成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(UiError uiError) {
|
||||
Utils.toast(context, "分享失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
Utils.toast(context, "分享已取消");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@ -5,7 +5,7 @@ public class SpeedUtils {
|
||||
public static String getSpeed(long kSpeed) {
|
||||
if (kSpeed >= 1000) {
|
||||
float mSpeed = kSpeed / 1024f;
|
||||
String str = mSpeed + "";
|
||||
String str = String.valueOf(mSpeed);
|
||||
if (str.length() > 4) {
|
||||
str = str.substring(0, 4);
|
||||
}
|
||||
@ -14,10 +14,9 @@ public class SpeedUtils {
|
||||
return kSpeed + "K/s";
|
||||
}
|
||||
|
||||
public static String getRemainTime(long totalSize, long currentSize,
|
||||
long speed) {
|
||||
public static String getRemainTime(long totalSize, long currentSize, long speed) {
|
||||
long remainSize = totalSize - currentSize;
|
||||
long remainTime = 0;
|
||||
long remainTime;
|
||||
if (speed != 0) {
|
||||
remainTime = remainSize / speed;
|
||||
} else {
|
||||
@ -35,4 +34,5 @@ public class SpeedUtils {
|
||||
return second + "秒";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -11,43 +13,21 @@ public class TimestampUtils {
|
||||
// 基准时间
|
||||
private static final long BASE = 1426608000000L;
|
||||
|
||||
private static ArrayMap<String, Integer> map;
|
||||
private static ArrayMap<String, Integer> intervalMap; // 间隔
|
||||
private static ArrayMap<String, Integer> cdMap; // cd
|
||||
|
||||
/*
|
||||
* 根据CD获取时间戳
|
||||
*/
|
||||
public static long getTimestamp(String url, int cd) {
|
||||
if (map == null){
|
||||
map = new ArrayMap<String, Integer>();
|
||||
map.put("^" + Config.HOST + "v1d45/index/kapaitoutiao" + "$", 5);
|
||||
map.put("^" + Config.HOST + "v1d45/index/remenkapai" + "$", 10);
|
||||
map.put("^" + Config.HOST + "v1d45/index/xincekapai" + "$", 15);
|
||||
map.put("^" + Config.HOST + "v1d45/index/yuedujingxuan" + "$", 20);
|
||||
map.put("^" + Config.HOST + "v1d45/index/zuixinchajian" + "$", 25);
|
||||
map.put("^" + Config.HOST + "v1d45/search/game\\?keyword=.+" + "$", 30);
|
||||
map.put("^" + Config.HOST + "v1d45/plugin/slide" + "$", 40);
|
||||
map.put("^" + Config.HOST + "v1d45/plugin/jingpin\\?limit=20\\&offset=.+" + "$", 35);
|
||||
map.put("^" + Config.HOST + "v1d45/plugin/zuixin\\?limit=20\\&offset=.+" + "$", 45);
|
||||
map.put("^" + Config.HOST + "v1d45/plugin/danji\\?limit=20\\&offset=.+" + "$", 50);
|
||||
map.put("^" + Config.HOST + "v1d45/game/remenkapai" + "$", 60);
|
||||
map.put("^" + Config.HOST + "v1d45/game/youxituijian" + "$", 85);
|
||||
map.put("^" + Config.HOST + "v1d45/game/xincekapai\\?limit=10\\&offset=.+" + "$", 90);
|
||||
map.put("^" + Config.HOST + "v1d45/game/.+/digest" + "$", 55);
|
||||
map.put("^" + Config.HOST + "v1d45/game/.+/digest" + "$", 65);
|
||||
map.put("^" + Config.HOST + "v1d45/game/.+/news_digest" + "$", 70);
|
||||
map.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=3\\&offset=0\\&type_group=.+" + "$", 75);
|
||||
map.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=5\\&offset=0\\&type_group=.+" + "$", 80);
|
||||
map.put("^" + Config.HOST + "v1d45/news/.+/suggestion" + "$", 95);
|
||||
map.put("^" + Config.HOST + "v1d45/news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 100);
|
||||
map.put("^" + Config.HOST + "v1d45/support/setting/platform" + "$", 105);
|
||||
map.put("^" + Config.HOST + "v1d45/support/package/.+/game/digest" + "$", 110);
|
||||
map.put("^" + Config.HOST + "v1d45/support/package/update\\?package=.+" + "$", 115);
|
||||
if (intervalMap == null) {
|
||||
initIntervalMap();
|
||||
}
|
||||
long base = BASE;
|
||||
for (String key : map.keySet()){
|
||||
for (String key : intervalMap.keySet()){
|
||||
if (Pattern.matches(key, url)) {
|
||||
Utils.log("url add base = " + url);
|
||||
base += map.get(key);
|
||||
base += intervalMap.get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -56,10 +36,96 @@ public class TimestampUtils {
|
||||
return (long) (Math.ceil((now - base) / cd) * cd + base);
|
||||
}
|
||||
|
||||
private static void initCDMap() {
|
||||
cdMap = new ArrayMap<>();
|
||||
cdMap.put("^" + Config.HOST + "v1d50/index/slides" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/game/chajian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/game/tuijian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/game/.+/detail" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/game/.+/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/game/remenkapai" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/game/.+/news_digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/game/column/.+\\?page=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/package/.+/game/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/game/danjiyouxi\\?limit=20\\&offset=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/news/.+/digest" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/news/.+/detail" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/news/.+/suggestion" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=3" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/news/zixun\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d50/news/yuanchuang\\?limit=10\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/search/game\\?keyword=.+" + "$", Constants.SEARCH_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/setting/platform" + "$", Constants.PLATFORM_CD);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/package/update\\?package=.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/device/.+/concern" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/device/.+/concern/.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2/stat/download" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2/disclaimer" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/search/game/default" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/support/upgrade\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/support/time/current" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/setting/ui" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2d0/support/download_status\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v1d46/support/suggestion" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v2/game/.+/serverInfo" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "v1d45/support/package/unused\\?skip=.+" + "$", 0);
|
||||
}
|
||||
|
||||
private static void initIntervalMap() {
|
||||
intervalMap = new ArrayMap<>();
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/index/slides" + "$", 5);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/game/chajian" + "$", 10);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/game/tuijian" + "$", 15);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/game/.+/detail" + "$", 20);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/game/.+/digest" + "$", 25);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/game/remenkapai" + "$", 30);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/game/.+/news_digest" + "$", 35);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/game/column/.+\\?page=.+" + "$", 40);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/support/package/.+/game/digest" + "$", 45);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/game/danjiyouxi\\?limit=20\\&offset=.+" + "$", 50);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/news/.+/digest" + "$", 55);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/news/.+/detail" + "$", 60);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/news/.+/suggestion" + "$", 65);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=3" + "$", 70);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/news/zixun\\?limit=20\\&offset=.+" + "$", 75);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+" + "$", 80);
|
||||
intervalMap.put("^" + Config.HOST + "v1d50/news/yuanchuang\\?limit=10\\&offset=.+" + "$", 85);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 90);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", 95);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", 100);
|
||||
intervalMap.put("^" + Config.HOST + "v2d0/zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", 105);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", 110);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/search/game\\?keyword=.+" + "$", 115);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/support/setting/platform" + "$", 120);
|
||||
intervalMap.put("^" + Config.HOST + "v1d45/support/package/update\\?package=.+" + "$", 125);
|
||||
}
|
||||
|
||||
/*
|
||||
* 为url添加timestamp
|
||||
*/
|
||||
public static String addTimestamp(String url, int cd) {
|
||||
public static String addTimestamp(String url) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return url;
|
||||
}
|
||||
if (cdMap == null) {
|
||||
initCDMap();
|
||||
}
|
||||
int cd = 0;
|
||||
for (String key : cdMap.keySet()){
|
||||
if (Pattern.matches(key, url)) {
|
||||
cd = cdMap.get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cd == 0) {
|
||||
return url;
|
||||
}
|
||||
if (url.contains("?")) {
|
||||
String u = url + "×tamp=" + getTimestamp(url, cd);
|
||||
Utils.log("url = " + u);
|
||||
@ -70,7 +136,7 @@ public class TimestampUtils {
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 去除url中的timestamp
|
||||
*/
|
||||
|
||||
@ -3,13 +3,23 @@ package com.gh.common.util;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.tencent.stat.StatConfig;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
@ -20,6 +30,80 @@ import java.util.Map;
|
||||
|
||||
public class TokenUtils {
|
||||
|
||||
// 注册设备
|
||||
public static synchronized String register(final Context context) {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
if (!TextUtils.isEmpty(android_id)) {
|
||||
params.put("ANDROID_ID", android_id);
|
||||
}
|
||||
String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
|
||||
if (!TextUtils.isEmpty(imei)) {
|
||||
params.put("IMEI", imei);
|
||||
}
|
||||
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
String mac = wm.getConnectionInfo().getMacAddress();
|
||||
if (!TextUtils.isEmpty(mac)) {
|
||||
params.put("MAC", mac);
|
||||
} else {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
sp.edit().putBoolean("isUploadMac", false).apply();
|
||||
}
|
||||
String mid = StatConfig.getMid(context);
|
||||
if (!TextUtils.isEmpty(mid) || !"0".equals(mid)) {
|
||||
params.put("MTA_ID", mid);
|
||||
} else {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
sp.edit().putBoolean("isUploadMid", false).apply();
|
||||
}
|
||||
String url = "http://user.ghzhushou.com/v1d0/device/register";
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
JSONObject body = new JSONObject(params);
|
||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setRequestMethod("POST");
|
||||
|
||||
connection.addRequestProperty("Content-Type", "application/json; charset=utf-8");
|
||||
connection.addRequestProperty("Device", DeviceUtils.getDeviceHeader(context));
|
||||
|
||||
connection.connect();
|
||||
|
||||
OutputStreamWriter outputStream = new OutputStreamWriter(
|
||||
connection.getOutputStream(), "utf-8");
|
||||
outputStream.write(body.toString());
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
if (connection.getResponseCode() == 200) {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(connection.getInputStream()));
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
reader.close();
|
||||
|
||||
try {
|
||||
JSONObject response = new JSONObject(builder.toString());
|
||||
String device_id = response.getString("device_id");
|
||||
// 保存device_id
|
||||
saveDeviceId(context, device_id);
|
||||
Utils.log("device_id = " + device_id);
|
||||
return device_id;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取用户token
|
||||
public static synchronized String getToken(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE,
|
||||
@ -30,40 +114,18 @@ public class TokenUtils {
|
||||
long time = System.currentTimeMillis();
|
||||
// 判断token是否过期
|
||||
if (time < expire) {
|
||||
// token未过期
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
// Map<String, String> params = DeviceUtils.getDeviceParams(context);
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
String url = Config.HOST + "v1d45/token/visit";
|
||||
|
||||
//判断是否已登录
|
||||
if (sp.getBoolean("isLogin", false)) {
|
||||
// 已登录,获取用户名和密码自动登录
|
||||
String username = sp.getString("username", null);
|
||||
String password = sp.getString("password", null);
|
||||
if (username == null || password == null) {
|
||||
url = Config.HOST + "v2/token/user?time=" + System.currentTimeMillis();
|
||||
params.put("username", username);
|
||||
try {
|
||||
String s = RSEUtils.encryptByPublic(password + username + System.currentTimeMillis() / 1000);
|
||||
Utils.log("加密 = " + s);
|
||||
params.put("password", s);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
url = Config.HOST + "v2/token/mobile?time=" + System.currentTimeMillis();
|
||||
String mobile = sp.getString("mobile", null);
|
||||
params.put("mobile_number", mobile);
|
||||
}
|
||||
}
|
||||
|
||||
// 重新获取token
|
||||
String url = "http://user.ghzhushou.com/v1d0/login";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("device_id", getDeviceId(context));
|
||||
try {
|
||||
JSONObject body = new JSONObject(params);
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url)
|
||||
.openConnection();
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
connection.setConnectTimeout(5000);
|
||||
@ -90,12 +152,15 @@ public class TokenUtils {
|
||||
}
|
||||
reader.close();
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(builder.toString());
|
||||
Editor editor = sp.edit();
|
||||
editor.putString("token", jsonObject.getString("token"));
|
||||
JSONObject jsonObject = new JSONObject(builder.toString());
|
||||
editor.putString("user_name", jsonObject.getString("name"));
|
||||
editor.putString("user_icon", jsonObject.getString("icon"));
|
||||
jsonObject = jsonObject.getJSONObject("token");
|
||||
editor.putString("token", jsonObject.getString("value"));
|
||||
editor.putLong("token_expire", jsonObject.getLong("expire"));
|
||||
editor.apply();
|
||||
return jsonObject.getString("token");
|
||||
return jsonObject.getString("value");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -103,7 +168,165 @@ public class TokenUtils {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static synchronized void saveDeviceId(Context context, String device_id){
|
||||
saveSharedPreferences(context, device_id);
|
||||
saveDataFile(context, device_id);
|
||||
svaeSDCard(device_id, "/gh-uuid");//SDCard根目录
|
||||
svaeSDCard(device_id, "/system");//SDCard system目录
|
||||
svaeSDCard(device_id, "/data");//SDCard data目录
|
||||
}
|
||||
|
||||
//将uuid存到sp
|
||||
private static void saveSharedPreferences(Context context, String device_id) {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor edit = sp.edit();
|
||||
edit.putString("uuid", device_id);
|
||||
edit.apply();
|
||||
Utils.log("saveDeviceId", "保存成功SP");
|
||||
}
|
||||
|
||||
//将uuid存到data/data/PackageName/files文件夹下
|
||||
private static void saveDataFile(Context context, String device_id) {
|
||||
FileOutputStream fops;
|
||||
try {
|
||||
fops = context.openFileOutput("uuid", Context.MODE_PRIVATE);
|
||||
fops.write(device_id.getBytes());
|
||||
fops.close();
|
||||
Utils.log("saveDeviceId", "保存成功DataFile");
|
||||
} catch (Exception e) {
|
||||
Utils.log("保存uuid到data/data/PackageName/files文件异常" + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//将uuid存到SD卡
|
||||
private static void svaeSDCard(String device_id, String saveDir) {
|
||||
File sdCardDir = Environment.getExternalStorageDirectory();
|
||||
String path = sdCardDir.getPath() + saveDir;
|
||||
|
||||
File file = new File(path);
|
||||
if (!file.exists()){
|
||||
file.mkdirs();
|
||||
}
|
||||
|
||||
// 判断文件是否存在,存在则删除
|
||||
File uuidFile = new File(path +"/uuid");
|
||||
if (uuidFile.isFile() && uuidFile.exists()){
|
||||
Utils.log(saveDir + "文件夹里的文件存在,执行删除操作");
|
||||
uuidFile.delete();
|
||||
}
|
||||
|
||||
File writeFile = new File(file, "uuid");
|
||||
FileOutputStream fos;
|
||||
try {
|
||||
fos = new FileOutputStream(writeFile);
|
||||
fos.write(device_id.getBytes());
|
||||
fos.close();
|
||||
Utils.log("saveDeviceId", "保存成功SDCard"+"目录为:"+saveDir);
|
||||
} catch (Exception e) {
|
||||
Utils.log("保存uuid到SDCard异常" + saveDir + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 启动助手时,检查uuid
|
||||
public static void checkDeviceID(Context context) {
|
||||
String uuid = loadSharedPreferences(context, false);
|
||||
if (uuid == null) {
|
||||
// 重新获取uuid,保存
|
||||
return;
|
||||
}
|
||||
// 检查
|
||||
if (loadSharedPreferences(context, true) == null){
|
||||
saveSharedPreferences(context, uuid);
|
||||
}
|
||||
if (loadDataFile(context ,true) == null){
|
||||
saveDataFile(context, uuid);
|
||||
}
|
||||
String[] dirName = {"/gh-uuid", "/system", "/data"};
|
||||
for (int i = 0; i< 3; i++) {
|
||||
String s = loadSDCard(dirName[i]);
|
||||
if (s == null) {
|
||||
svaeSDCard(uuid, dirName[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized String getDeviceId(Context context) {
|
||||
return loadSharedPreferences(context, false);
|
||||
}
|
||||
|
||||
//读取SharedPreferences的uuid
|
||||
private static String loadSharedPreferences(Context context, boolean isCheck) {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
String uuid = sp.getString("uuid", null);
|
||||
if (isCheck){
|
||||
return uuid;
|
||||
}
|
||||
if (uuid == null){
|
||||
return loadDataFile(context, false);
|
||||
}
|
||||
Utils.log("getDeviceId", "获取成功SP" + uuid);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
//读取data/data/PackageName/files的uuid
|
||||
private static String loadDataFile(Context context, boolean isCheck) {
|
||||
File file = new File(context.getFilesDir(), "uuid");
|
||||
if (file.exists()){
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] b = new byte[1024];
|
||||
int count = -1;
|
||||
String uuid = null;
|
||||
while ((count = fis.read(b)) != -1) {
|
||||
uuid = new String(b, 0, count, "UTF-8");
|
||||
}
|
||||
Utils.log("getDeviceId", "获取成功DataFile"+ uuid);
|
||||
return uuid;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else if (!isCheck){
|
||||
String[] dirName = {"/gh-uuid", "/system", "/data"};
|
||||
for (int i = 0; i< 3; i++) {
|
||||
String s = loadSDCard(dirName[i]);
|
||||
if (s != null) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//读取SD卡的uuid
|
||||
private static String loadSDCard(String saveDir){
|
||||
File sdCardDir = Environment.getExternalStorageDirectory();
|
||||
String path = sdCardDir.getPath() + saveDir;
|
||||
File file = new File(path, "uuid");
|
||||
if (file.exists()){
|
||||
FileInputStream fis = null;
|
||||
ByteArrayOutputStream bos = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
bos = new ByteArrayOutputStream();
|
||||
byte[] array = new byte[1024];
|
||||
int len = -1;
|
||||
while( (len = fis.read(array)) != -1){
|
||||
bos.write(array,0,len);
|
||||
}
|
||||
bos.close();
|
||||
fis.close();
|
||||
Utils.log("getDeviceId", "获取成功SDCard"+"目录为:"+saveDir+"::"+bos.toString());
|
||||
return bos.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-19
|
||||
* @update 2015-8-19
|
||||
* @des 控制debug调试信息
|
||||
*/
|
||||
public class Trace {
|
||||
private final String TAG = "gh_debug";
|
||||
private Map<String, Boolean> maps;//(tag, boolean), boolean = true,表示debug信息可以显示,否则不能显示
|
||||
|
||||
private static Trace mInstance;
|
||||
|
||||
private Trace(){
|
||||
maps = new HashMap<String ,Boolean>();
|
||||
}
|
||||
|
||||
public static Trace getInstance(){
|
||||
synchronized (Trace.class) {
|
||||
if(mInstance == null)
|
||||
mInstance = new Trace();
|
||||
return mInstance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void debug(String tag, String msg){
|
||||
if(maps.get(tag) == null){
|
||||
maps.put(tag, false);
|
||||
}
|
||||
|
||||
if(maps.get(tag) == true){
|
||||
Log.d(TAG, tag + "==>" + msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tag debug的tag
|
||||
* @param flag true,则输出该tag的debug信息,否则不输出该tag的debug信息
|
||||
*/
|
||||
public void setClassDebug(String tag, boolean flag){
|
||||
maps.put(tag, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param flag true--所有tag的debug消息都可以输出,否则全部都不输出
|
||||
*/
|
||||
public void setDebug(boolean flag){
|
||||
for ( String tag : maps.keySet()) {
|
||||
maps.put(tag, flag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,12 +1,14 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -14,16 +16,33 @@ import java.lang.reflect.Field;
|
||||
public class Utils {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
private final static String TAG = "result";
|
||||
|
||||
public static void log(String msg) {
|
||||
log(TAG, msg);
|
||||
}
|
||||
|
||||
public static void log(Object obj) {
|
||||
log(TAG, obj.getClass().getSimpleName() + ":" + obj.toString());
|
||||
}
|
||||
|
||||
public static void log(String tag, String msg) {
|
||||
log(Log.ERROR, tag, msg);
|
||||
}
|
||||
|
||||
public static void log(String tag, Object obj) {
|
||||
log(Log.ERROR, tag, obj.getClass().getSimpleName() + ":" + obj.toString());
|
||||
}
|
||||
|
||||
private static void log(int priority, String tag, String msg) {
|
||||
if (DEBUG) {
|
||||
Log.e("result", msg);
|
||||
Log.println(priority, tag, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(Object obj) {
|
||||
|
||||
private static void log(int priority, String tag, Object obj) {
|
||||
if (DEBUG) {
|
||||
Log.e("result", obj.getClass().getSimpleName() + " = " + obj.toString());
|
||||
Log.println(priority, tag, obj.getClass().getSimpleName() + ":" + obj.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +50,20 @@ public class Utils {
|
||||
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取服务器时间
|
||||
*/
|
||||
public static long getTime(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
long serverTime = sp.getLong("server_time", 0);
|
||||
long clientTime = sp.getLong("client_time", 0);
|
||||
if (serverTime == 0 || clientTime == 0) {
|
||||
return System.currentTimeMillis() / 1000;
|
||||
} else {
|
||||
return serverTime + (System.currentTimeMillis() / 1000 - clientTime);
|
||||
}
|
||||
}
|
||||
|
||||
public static void hideSoftInput(Context context, EditText editText) {
|
||||
InputMethodManager imm = (InputMethodManager) context
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
249
app/src/main/java/com/gh/common/view/CardLinearLayout.java
Normal file
249
app/src/main/java/com/gh/common/view/CardLinearLayout.java
Normal file
@ -0,0 +1,249 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/31.
|
||||
*/
|
||||
public class CardLinearLayout extends LinearLayout {
|
||||
|
||||
private Drawable mLeftDrawable, mTopDrawable, mRightDrawable, mBottomDrawable, mCenterDrawable;
|
||||
private Drawable mLeftTopDrawable, mRightTopDrawable, mLeftBottomDrawable, mRightBottomDrawable;
|
||||
|
||||
private int mLeft, mTop, mRight, mBottom;
|
||||
|
||||
private boolean isBottom;
|
||||
|
||||
public CardLinearLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public CardLinearLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public CardLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
setWillNotDraw(false);
|
||||
isBottom = true;
|
||||
|
||||
mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_left);
|
||||
mTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_top);
|
||||
mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_right);
|
||||
mBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_bottom);
|
||||
mCenterDrawable = getContext().getResources().getDrawable(R.drawable.frame_center);
|
||||
|
||||
mLeftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_top_square);
|
||||
mRightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_top_square);
|
||||
mLeftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_bottom_square);
|
||||
mRightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_bottom_square);
|
||||
|
||||
if (attrs != null) {
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CardLayout);
|
||||
mLeft = ta.getDimensionPixelSize(R.styleable.CardLayout_left, 0);
|
||||
mTop = ta.getDimensionPixelSize(R.styleable.CardLayout_top, 0);
|
||||
mRight = ta.getDimensionPixelSize(R.styleable.CardLayout_right, 0);
|
||||
mBottom = ta.getDimensionPixelSize(R.styleable.CardLayout_bottom, 0);
|
||||
ta.recycle();
|
||||
}
|
||||
setPadding(getPaddingLeft() + mLeft, getPaddingTop() + mTop, getPaddingRight() + mRight, getPaddingBottom() + mBottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
if (mLeft != 0 && mTop != 0 && mRight != 0 && mBottom != 0) {
|
||||
// 左、上、右、下
|
||||
if (mLeftTopDrawable != null) {
|
||||
mLeftTopDrawable.setBounds(0, 0, mLeft, mTop);
|
||||
mLeftTopDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mTopDrawable != null) {
|
||||
mTopDrawable.setBounds(mLeft, 0, getWidth() - mRight, mTop);
|
||||
mTopDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mRightTopDrawable != null) {
|
||||
mRightTopDrawable.setBounds(getWidth() - mRight, 0, getWidth(), mTop);
|
||||
mRightTopDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mLeftDrawable != null) {
|
||||
mLeftDrawable.setBounds(0, mTop, mLeft, getHeight() - mBottom);
|
||||
mLeftDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mRightDrawable != null) {
|
||||
mRightDrawable.setBounds(getWidth() - mRight, mTop, getWidth(), getHeight() - mBottom);
|
||||
mRightDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mLeftBottomDrawable != null) {
|
||||
mLeftBottomDrawable.setBounds(0, getHeight() - mBottom, mLeft, getHeight());
|
||||
mLeftBottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (isBottom) {
|
||||
if (mBottomDrawable != null) {
|
||||
mBottomDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight());
|
||||
mBottomDrawable.draw(canvas);
|
||||
}
|
||||
} else {
|
||||
if (mCenterDrawable != null) {
|
||||
mCenterDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight());
|
||||
mCenterDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
if (mRightBottomDrawable != null) {
|
||||
mRightBottomDrawable.setBounds(getWidth() - mRight, getHeight() - mBottom, getWidth(), getHeight());
|
||||
mRightBottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
} else if (mLeft != 0 && mTop != 0 && mRight != 0) {
|
||||
// 左、上、右
|
||||
if (mLeftTopDrawable != null) {
|
||||
mLeftTopDrawable.setBounds(0, 0, mLeft, mTop);
|
||||
mLeftTopDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mTopDrawable != null) {
|
||||
mTopDrawable.setBounds(mLeft, 0, getWidth() - mRight, mTop);
|
||||
mTopDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mRightTopDrawable != null) {
|
||||
mRightTopDrawable.setBounds(getWidth() - mRight, 0, getWidth(), mTop);
|
||||
mRightTopDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mLeftDrawable != null) {
|
||||
mLeftDrawable.setBounds(0, mTop, mLeft, getHeight());
|
||||
mLeftDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mRightDrawable != null) {
|
||||
mRightDrawable.setBounds(getWidth() - mRight, mTop, getWidth(), getHeight());
|
||||
mRightDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
} else if (mLeft != 0 && mBottom != 0 && mRight != 0) {
|
||||
// 左、下、右
|
||||
if (mLeftDrawable != null) {
|
||||
mLeftDrawable.setBounds(0, 0, mLeft, getHeight() - mBottom);
|
||||
mLeftDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mRightDrawable != null) {
|
||||
mRightDrawable.setBounds(getWidth() - mRight, 0, getWidth(), getHeight() - mBottom);
|
||||
mRightDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mLeftBottomDrawable != null) {
|
||||
mLeftBottomDrawable.setBounds(0, getHeight() - mBottom, mLeft, getHeight());
|
||||
mLeftBottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (isBottom) {
|
||||
if (mBottomDrawable != null) {
|
||||
mBottomDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight());
|
||||
mBottomDrawable.draw(canvas);
|
||||
}
|
||||
} else {
|
||||
if (mCenterDrawable != null) {
|
||||
mCenterDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight());
|
||||
mCenterDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
if (mRightBottomDrawable != null) {
|
||||
mRightBottomDrawable.setBounds(getWidth() - mRight, getHeight() - mBottom, getWidth(), getHeight());
|
||||
mRightBottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
} else if (mLeft != 0 && mRight != 0) {
|
||||
// 左、右
|
||||
if (mLeftDrawable != null) {
|
||||
mLeftDrawable.setBounds(0, 0, mLeft, getHeight());
|
||||
mLeftDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (mRightDrawable != null) {
|
||||
mRightDrawable.setBounds(getWidth() - mRight, 0, getWidth(), getHeight());
|
||||
mRightDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int newHeight = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec) + mTop + mBottom,
|
||||
MeasureSpec.getMode(heightMeasureSpec));
|
||||
super.onMeasure(widthMeasureSpec, newHeight);
|
||||
}
|
||||
|
||||
public void setBottom(boolean bottom) {
|
||||
isBottom = bottom;
|
||||
}
|
||||
|
||||
public void setShadow(int left, int top, int right, int bottom) {
|
||||
setPadding(getPaddingLeft() - mLeft + left,
|
||||
getPaddingTop() - mTop + top,
|
||||
getPaddingRight() - mRight + right,
|
||||
getPaddingBottom() - mBottom + bottom);
|
||||
this.mLeft = left;
|
||||
this.mTop = top;
|
||||
this.mRight = right;
|
||||
this.mBottom = bottom;
|
||||
}
|
||||
|
||||
public void setmLeft(int left) {
|
||||
setPadding(getPaddingLeft() - mLeft + left, getPaddingTop(), getPaddingRight(), getPaddingBottom());
|
||||
this.mLeft = left;
|
||||
}
|
||||
|
||||
public void setmTop(int top) {
|
||||
setPadding(getPaddingLeft(), getPaddingTop() - mTop + top, getPaddingRight(), getPaddingBottom());
|
||||
this.mTop = top;
|
||||
}
|
||||
|
||||
public void setmRight(int right) {
|
||||
setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight() - mRight + right, getPaddingBottom());
|
||||
this.mRight = right;
|
||||
}
|
||||
|
||||
public void setmBottom(int bottom) {
|
||||
setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom() - mBottom + bottom);
|
||||
this.mBottom = bottom;
|
||||
}
|
||||
|
||||
public int getmLeft() {
|
||||
return mLeft;
|
||||
}
|
||||
|
||||
public int getmTop() {
|
||||
return mTop;
|
||||
}
|
||||
|
||||
public int getmRight() {
|
||||
return mRight;
|
||||
}
|
||||
|
||||
public int getmBottom() {
|
||||
return mBottom;
|
||||
}
|
||||
}
|
||||
99
app/src/main/java/com/gh/common/view/CardRelativeLayout.java
Normal file
99
app/src/main/java/com/gh/common/view/CardRelativeLayout.java
Normal file
@ -0,0 +1,99 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/9.
|
||||
*/
|
||||
public class CardRelativeLayout extends RelativeLayout {
|
||||
|
||||
private Drawable topDrawable, bottomDrawable;
|
||||
private Drawable leftTopDrawable, rightTopDrawable, leftBottomDrawable, rightBottomDrawable;
|
||||
|
||||
private int mLeft, mTop, mRight, mBottom;
|
||||
|
||||
public CardRelativeLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public CardRelativeLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public CardRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
setWillNotDraw(false);
|
||||
topDrawable = getContext().getResources().getDrawable(R.drawable.frame_top);
|
||||
bottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_bottom);
|
||||
|
||||
leftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_top_square);
|
||||
rightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_top_square);
|
||||
leftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_bottom_square);
|
||||
rightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_bottom_square);
|
||||
|
||||
if (attrs != null) {
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CardLayout);
|
||||
mLeft = ta.getDimensionPixelSize(R.styleable.CardLayout_left, 0);
|
||||
mTop = ta.getDimensionPixelSize(R.styleable.CardLayout_top, 0);
|
||||
mRight = ta.getDimensionPixelSize(R.styleable.CardLayout_right, 0);
|
||||
mBottom = ta.getDimensionPixelSize(R.styleable.CardLayout_bottom, 0);
|
||||
ta.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (mTop != 0) {
|
||||
if (leftBottomDrawable != null) {
|
||||
leftBottomDrawable.setBounds(0, 0, mLeft, mTop);
|
||||
leftBottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (bottomDrawable != null) {
|
||||
bottomDrawable.setBounds(mLeft, 0, getWidth() - mRight, mTop);
|
||||
bottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (rightBottomDrawable != null) {
|
||||
rightBottomDrawable.setBounds(getWidth() - mRight, 0, getWidth(), mTop);
|
||||
rightBottomDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
if (mBottom != 0) {
|
||||
if (leftTopDrawable != null) {
|
||||
leftTopDrawable.setBounds(0, getHeight() - mBottom, mLeft, getHeight());
|
||||
leftTopDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (topDrawable != null) {
|
||||
topDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight());
|
||||
topDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (rightTopDrawable != null) {
|
||||
rightTopDrawable.setBounds(getWidth() - mRight, getHeight() - mBottom, getWidth(), getHeight());
|
||||
rightTopDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setmBottom(int mBottom) {
|
||||
this.mBottom = mBottom;
|
||||
}
|
||||
|
||||
public void setmTop(int mTop) {
|
||||
this.mTop = mTop;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
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 2016/8/9.
|
||||
*/
|
||||
public class ChildLinearLayoutManager extends LinearLayoutManager {
|
||||
|
||||
public ChildLinearLayoutManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ChildLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
|
||||
super(context, orientation, reverseLayout);
|
||||
}
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
}
|
||||
private int[] mMeasuredDimension = new int[1];
|
||||
|
||||
@Override
|
||||
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state,
|
||||
int widthSpec, int heightSpec) {
|
||||
|
||||
final int heightMode = View.MeasureSpec.getMode(heightSpec);
|
||||
final int heightSize = View.MeasureSpec.getSize(heightSpec);
|
||||
|
||||
int height = 0;
|
||||
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];
|
||||
|
||||
}
|
||||
if (heightMode == View.MeasureSpec.EXACTLY){
|
||||
height = heightSize;
|
||||
}
|
||||
|
||||
setMeasuredDimension(View.MeasureSpec.getSize(widthSpec), height);
|
||||
}
|
||||
|
||||
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
|
||||
int heightSpec, int[] measuredDimension) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -32,7 +32,7 @@ public class Concern_LinearLayout extends LinearLayout {
|
||||
if (concern_rv_recommend.getHeight() < height) {
|
||||
postDelayed(show, 10);
|
||||
} else {
|
||||
concern_iv_delete.setImageResource(R.drawable.concern_delete);
|
||||
concern_iv_delete.setImageResource(R.drawable.concern_down);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -52,7 +52,7 @@ public class Concern_LinearLayout extends LinearLayout {
|
||||
postDelayed(hide, 10);
|
||||
} else {
|
||||
concern_rv_recommend.setVisibility(View.GONE);
|
||||
concern_iv_delete.setImageResource(R.drawable.concern_arrow);
|
||||
concern_iv_delete.setImageResource(R.drawable.concern_up);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -58,19 +58,25 @@ public class CropImageCustom extends RelativeLayout {
|
||||
return mZoomImageView.clip();
|
||||
}
|
||||
|
||||
public void savePicture(String path) {
|
||||
public boolean savePicture(String path) {
|
||||
Bitmap bitmap = mZoomImageView.clip();
|
||||
File file = new File(path);
|
||||
try {
|
||||
BufferedOutputStream bos = new BufferedOutputStream(
|
||||
new FileOutputStream(file));
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
|
||||
bos.flush();
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
file.delete();
|
||||
e.printStackTrace();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
public ImageView getCropImageZoomView() {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,105 +0,0 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBShowDone;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class Gh_LinearLayout extends LinearLayout {
|
||||
|
||||
private LinearLayout dm_item, dm_item_ll_delete;
|
||||
|
||||
private int height;
|
||||
private int total;
|
||||
private int distance;
|
||||
|
||||
private boolean isSliding;
|
||||
|
||||
public boolean isSliding() {
|
||||
return isSliding;
|
||||
}
|
||||
|
||||
private int position;
|
||||
|
||||
Runnable show = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
LayoutParams lparams = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, height);
|
||||
lparams.height = dm_item.getHeight() + distance;
|
||||
if (lparams.height > total) {
|
||||
lparams.height = total;
|
||||
}
|
||||
dm_item.setLayoutParams(lparams);
|
||||
invalidate();
|
||||
if (dm_item.getHeight() < total) {
|
||||
postDelayed(show, 10);
|
||||
} else {
|
||||
isSliding = false;
|
||||
EventBus.getDefault().post(new EBShowDone("下载管理", position));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Runnable hide = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
LayoutParams lparams = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, height);
|
||||
lparams.height = dm_item.getHeight() - distance;
|
||||
if (lparams.height < height) {
|
||||
lparams.height = height;
|
||||
}
|
||||
dm_item.setLayoutParams(lparams);
|
||||
invalidate();
|
||||
if (dm_item.getHeight() > height) {
|
||||
postDelayed(hide, 10);
|
||||
} else {
|
||||
dm_item_ll_delete.setVisibility(View.GONE);
|
||||
isSliding = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public Gh_LinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
|
||||
height = DisplayUtils.dip2px(getContext(), 66);
|
||||
total = DisplayUtils.dip2px(getContext(), 96);
|
||||
distance = DisplayUtils.dip2px(getContext(), 3);
|
||||
|
||||
isSliding = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
|
||||
super.onAttachedToWindow();
|
||||
dm_item = (LinearLayout) findViewById(R.id.dm_item);
|
||||
dm_item_ll_delete = (LinearLayout) findViewById(R.id.dm_item_ll_delete);
|
||||
}
|
||||
|
||||
public void showDeleteView(int position) {
|
||||
this.position = position;
|
||||
isSliding = true;
|
||||
dm_item_ll_delete.setVisibility(View.VISIBLE);
|
||||
removeCallbacks(hide);
|
||||
post(show);
|
||||
getHandler();
|
||||
}
|
||||
|
||||
public void hideDeleteView() {
|
||||
isSliding = true;
|
||||
removeCallbacks(show);
|
||||
post(hide);
|
||||
}
|
||||
}
|
||||
@ -6,17 +6,17 @@ import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
public class Gh_ImageLayout extends RelativeLayout {
|
||||
|
||||
public class Gh_RelativeLayout extends RelativeLayout {
|
||||
|
||||
private GestureDetector mGestureDetector;
|
||||
private OnSingleTapListener listener;
|
||||
|
||||
public Gh_ImageLayout(Context context) {
|
||||
|
||||
public Gh_RelativeLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public Gh_ImageLayout(Context context, AttributeSet attrs) {
|
||||
public Gh_RelativeLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
mGestureDetector = new GestureDetector(context,
|
||||
@ -24,7 +24,6 @@ public class Gh_ImageLayout extends RelativeLayout {
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
|
||||
if (listener != null) {
|
||||
listener.onSingleTap();
|
||||
}
|
||||
@ -8,18 +8,15 @@ import android.view.MotionEvent;
|
||||
public class Gh_ViewPager extends ViewPager {
|
||||
|
||||
public Gh_ViewPager(Context context) {
|
||||
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public Gh_ViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
getChildAt(i).dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@ -16,7 +17,7 @@ public class HorizontalItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
public HorizontalItemDecoration(Context context, int interval, int size) {
|
||||
paint = new Paint();
|
||||
paint.setColor(0xffffffff);
|
||||
paint.setColor(Color.WHITE);
|
||||
mInterval = DisplayUtils.dip2px(context, interval);
|
||||
mSize = size;
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ public class VerticalItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
public VerticalItemDecoration(Context context, int interval) {
|
||||
paint = new Paint();
|
||||
paint.setColor(context.getResources().getColor(R.color.bg_color));
|
||||
paint.setColor(context.getResources().getColor(R.color.background));
|
||||
mInterval = DisplayUtils.dip2px(context, interval);
|
||||
}
|
||||
|
||||
|
||||
@ -2,51 +2,48 @@ package com.gh.download;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.util.Log;
|
||||
|
||||
import com.gh.common.util.Utils;
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
|
||||
public class DBHelper extends OrmLiteSqliteOpenHelper
|
||||
{
|
||||
public class DBHelper extends OrmLiteSqliteOpenHelper {
|
||||
|
||||
private static final String DB_NAME = "gh_download.db";
|
||||
private static final int VERSION = 3;
|
||||
|
||||
|
||||
/**
|
||||
* downloadDao ,每张表对应一个
|
||||
*/
|
||||
private Dao<DownloadEntry, String> downloadDao;
|
||||
private Dao<DownloadEntity, String> downloadDao;
|
||||
|
||||
private DBHelper(Context context)
|
||||
{
|
||||
private DBHelper(Context context) {
|
||||
super(context, DB_NAME, null, VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource)
|
||||
{
|
||||
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
|
||||
try {
|
||||
Log.v("ormlite_test", "onCreate ====================");
|
||||
TableUtils.createTable(connectionSource, DownloadEntry.class);
|
||||
Utils.log("ormlite_test", "onCreate ====================");
|
||||
TableUtils.createTable(connectionSource, DownloadEntity.class);
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase database,
|
||||
ConnectionSource connectionSource, int oldVersion, int newVersion)
|
||||
{
|
||||
public void onUpgrade(SQLiteDatabase database,
|
||||
ConnectionSource connectionSource,
|
||||
int oldVersion,
|
||||
int newVersion) {
|
||||
try {
|
||||
TableUtils.dropTable(connectionSource, DownloadEntry.class, true);
|
||||
onCreate(database, connectionSource);
|
||||
TableUtils.dropTable(connectionSource, DownloadEntity.class, true);
|
||||
onCreate(database, connectionSource);
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static DBHelper mInstance;
|
||||
@ -57,25 +54,22 @@ public class DBHelper extends OrmLiteSqliteOpenHelper
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static synchronized DBHelper getInstance(Context context)
|
||||
{
|
||||
public static synchronized DBHelper getInstance(Context context) {
|
||||
context = context.getApplicationContext();
|
||||
if (mInstance == null)
|
||||
{
|
||||
synchronized (DBHelper.class)
|
||||
{
|
||||
if (mInstance == null)
|
||||
mInstance = new DBHelper(context);
|
||||
}
|
||||
}
|
||||
|
||||
if (mInstance == null) {
|
||||
synchronized (DBHelper.class) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new DBHelper(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public Dao<DownloadEntry, String> getDownloadDao(){
|
||||
public Dao<DownloadEntity, String> getDownloadDao() {
|
||||
try {
|
||||
if(downloadDao == null){
|
||||
downloadDao = getDao(DownloadEntry.class);
|
||||
if (downloadDao == null) {
|
||||
downloadDao = getDao(DownloadEntity.class);
|
||||
}
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
@ -87,10 +81,9 @@ public class DBHelper extends OrmLiteSqliteOpenHelper
|
||||
* 释放资源
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
public void close() {
|
||||
super.close();
|
||||
downloadDao= null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,81 +1,57 @@
|
||||
package com.gh.download;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Observable;
|
||||
|
||||
|
||||
public class DataChanger extends Observable{
|
||||
private HashMap<String, DownloadTask> mDownloadingTasks;//当前正在下载的任务队列
|
||||
private HashMap<String, DownloadEntry> mDownloadEntries;//包含所有下载任务的任务队列
|
||||
|
||||
public class DataChanger extends Observable {
|
||||
|
||||
private static DataChanger mInstance;
|
||||
|
||||
private DataChanger() {
|
||||
mDownloadingTasks = new HashMap<String, DownloadTask>();
|
||||
mDownloadEntries = new HashMap<String, DownloadEntry>();
|
||||
}
|
||||
|
||||
public static DataChanger getInstance(){
|
||||
|
||||
public static DataChanger getInstance() {
|
||||
if(mInstance == null){
|
||||
mInstance = new DataChanger();
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public HashMap<String, DownloadTask> getDownloadingTasks() {
|
||||
return mDownloadingTasks;
|
||||
private final Map<String, DownloadTask> mDownloadingTasks;//当前正在下载的任务队列
|
||||
private final Map<String, DownloadEntity> mDownloadEntries;//包含所有下载任务的任务队列
|
||||
|
||||
private DataChanger() {
|
||||
mDownloadingTasks = Collections.synchronizedMap(new HashMap<String, DownloadTask>());
|
||||
mDownloadEntries = Collections.synchronizedMap(new HashMap<String, DownloadEntity>());
|
||||
}
|
||||
|
||||
public HashMap<String, DownloadEntry> getDownloadEntries() {
|
||||
return mDownloadEntries;
|
||||
public Map<String, DownloadTask> getDownloadingTasks() {
|
||||
synchronized (mDownloadingTasks) {
|
||||
return mDownloadingTasks;
|
||||
}
|
||||
}
|
||||
|
||||
public void addToDownloadEntries(DownloadEntry entry) {
|
||||
mDownloadEntries.put(entry.getUrl(), entry);
|
||||
public Map<String, DownloadEntity> getDownloadEntries() {
|
||||
synchronized (mDownloadEntries) {
|
||||
return mDownloadEntries;
|
||||
}
|
||||
}
|
||||
|
||||
public int getDownloadingSize() {
|
||||
return mDownloadingTasks.size();
|
||||
}
|
||||
|
||||
public synchronized void notifyDataChanged(DownloadEntry entry) {
|
||||
if(entry != null){
|
||||
if(mDownloadEntries.get(entry.getUrl()) != null){
|
||||
mDownloadEntries.put(entry.getUrl(), entry);
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
public synchronized void notifyDataChanged(DownloadEntity entry) {
|
||||
if (entry != null) {
|
||||
if (getDownloadEntries().get(entry.getUrl()) != null) {
|
||||
getDownloadEntries().put(entry.getUrl(), entry);
|
||||
}
|
||||
setChanged();
|
||||
notifyObservers(entry);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addToDownloadingTask(String url, DownloadTask task) {
|
||||
mDownloadingTasks.put(url, task);
|
||||
}
|
||||
|
||||
public void removeDownloadingTask(String url) {
|
||||
getDownloadingTasks().remove(url);
|
||||
}
|
||||
|
||||
public void removeDownloadEntry(String url) {
|
||||
getDownloadEntries().remove(url);
|
||||
}
|
||||
|
||||
public void pauseDownloadingTasks(String url) {
|
||||
DownloadTask downloadTask = getDownloadingTasks().get(url);
|
||||
if(downloadTask != null){
|
||||
public synchronized void pauseDownloadingTasks(String url) {
|
||||
DownloadTask downloadTask = getDownloadingTasks().remove(url);
|
||||
if (downloadTask != null) {
|
||||
downloadTask.pause();
|
||||
removeDownloadingTask(url);
|
||||
}
|
||||
pauseDownloadEntries(url);
|
||||
}
|
||||
|
||||
public void pauseDownloadEntries(String url) {
|
||||
DownloadEntry entry = getDownloadEntries().get(url);
|
||||
if(entry != null){
|
||||
entry.setStatus(DownloadStatus.pause);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.gh.download;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
@ -9,10 +8,11 @@ public abstract class DataWatcher implements Observer{
|
||||
|
||||
@Override
|
||||
public void update(Observable observable, Object data) {
|
||||
onDataChanged(DataChanger.getInstance().getDownloadEntries());
|
||||
if (data != null && data instanceof DownloadEntity) {
|
||||
onDataChanged((DownloadEntity) data);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void onDataChanged(HashMap<String, DownloadEntry> downloadingEntries);
|
||||
|
||||
public abstract void onDataChanged(DownloadEntity downloadEntity);
|
||||
|
||||
}
|
||||
|
||||
@ -8,7 +8,8 @@ import com.j256.ormlite.dao.Dao;
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadDao {
|
||||
private static Dao<DownloadEntry, String> downloadDaoOpe;
|
||||
|
||||
private static Dao<DownloadEntity, String> downloadDaoOpe;
|
||||
private static DBHelper helper;
|
||||
private static DownloadDao mInstance;
|
||||
|
||||
@ -37,7 +38,7 @@ public class DownloadDao {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public void newOrUpdate(DownloadEntry entry) {
|
||||
public void newOrUpdate(DownloadEntity entry) {
|
||||
try {
|
||||
if (DownloadStatus.cancel.equals(entry.getStatus())) {
|
||||
downloadDaoOpe.delete(entry);
|
||||
@ -49,18 +50,17 @@ public class DownloadDao {
|
||||
}
|
||||
}
|
||||
|
||||
public DownloadEntry get(String url) {
|
||||
public DownloadEntity get(String url) {
|
||||
try {
|
||||
return downloadDaoOpe.queryForId(url);
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<DownloadEntry> getAll() {
|
||||
List<DownloadEntry> list = null;
|
||||
public List<DownloadEntity> getAll() {
|
||||
List<DownloadEntity> list = null;
|
||||
try {
|
||||
list = downloadDaoOpe.queryForAll();
|
||||
} catch (java.sql.SQLException e) {
|
||||
@ -75,6 +75,6 @@ public class DownloadDao {
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
281
app/src/main/java/com/gh/download/DownloadEntity.java
Normal file
281
app/src/main/java/com/gh/download/DownloadEntity.java
Normal file
@ -0,0 +1,281 @@
|
||||
package com.gh.download;
|
||||
|
||||
import com.j256.ormlite.field.DataType;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
@DatabaseTable(tableName = "download")
|
||||
public class DownloadEntity implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@DatabaseField(id = true, columnName="url")
|
||||
private String url;
|
||||
|
||||
@DatabaseField(columnName="name")
|
||||
private String name;
|
||||
|
||||
@DatabaseField(columnName="status")
|
||||
private DownloadStatus status;
|
||||
|
||||
@DatabaseField(columnName="path")
|
||||
private String path;
|
||||
|
||||
@DatabaseField(columnName="progress")
|
||||
private long progress;
|
||||
|
||||
@DatabaseField(columnName="size")
|
||||
private long size;
|
||||
|
||||
@DatabaseField(columnName="percent")
|
||||
private double percent;
|
||||
|
||||
@DatabaseField(columnName="speed")
|
||||
private long speed;
|
||||
|
||||
@DatabaseField(columnName="meta", dataType=DataType.SERIALIZABLE)
|
||||
private HashMap<String, String> meta;//其他
|
||||
|
||||
public String getGameId() {
|
||||
if (meta != null) {
|
||||
return meta.get("gameId");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setGameId(String gameId) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("gameId", gameId);
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
if (meta != null) {
|
||||
return meta.get("packageName");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("packageName", packageName);
|
||||
}
|
||||
|
||||
public String getETag() {
|
||||
if (meta != null) {
|
||||
return meta.get("ETag");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setETag(String ETag) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("ETag", ETag);
|
||||
}
|
||||
|
||||
public boolean isUpdate() {
|
||||
if (meta != null) {
|
||||
if ("true".equals(meta.get("isUpdate"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setUpdate(boolean update) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("isUpdate", String.valueOf(update));
|
||||
}
|
||||
|
||||
public boolean isPlugin() {
|
||||
if (meta != null) {
|
||||
if ("true".equals(meta.get("isPlugin"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setPlugin(boolean plugin) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("isPlugin", String.valueOf(plugin));
|
||||
}
|
||||
|
||||
public boolean isPluggable() {
|
||||
if (meta != null) {
|
||||
if ("true".equals(meta.get("isPluggable"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setPluggable(boolean pluggable) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("isPluggable", String.valueOf(pluggable));
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
if (meta != null) {
|
||||
return meta.get("platform");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPlatform(String platform) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("platform", platform);
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
if (meta != null) {
|
||||
return meta.get("icon");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setIcon(String icon) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("icon", icon);
|
||||
}
|
||||
|
||||
public String getEntrance() {
|
||||
if (meta != null) {
|
||||
return meta.get("entrance");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setEntrance(String entrance) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("entrance", entrance);
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
if (meta != null) {
|
||||
return meta.get("location");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("location", location);
|
||||
}
|
||||
|
||||
public long getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(long speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
if (meta != null) {
|
||||
return meta.get("error");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setError(String error) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("error", error);
|
||||
}
|
||||
|
||||
public HashMap<String, String> getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public void setMeta(HashMap<String, String> meta) {
|
||||
if (this.meta != null) {
|
||||
this.meta.putAll(meta);
|
||||
} else {
|
||||
this.meta = meta;
|
||||
}
|
||||
}
|
||||
|
||||
public double getPercent() {
|
||||
return percent;
|
||||
}
|
||||
|
||||
public void setPercent(double percent) {
|
||||
this.percent = percent;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DownloadStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(DownloadStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public long getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(long progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,144 +0,0 @@
|
||||
package com.gh.download;
|
||||
|
||||
import com.j256.ormlite.field.DataType;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@DatabaseTable(tableName = "download")
|
||||
public class DownloadEntry implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@DatabaseField(id = true,columnName="url")
|
||||
private String url;
|
||||
|
||||
// @DatabaseField(columnName="id")
|
||||
// private String id;
|
||||
|
||||
@DatabaseField(columnName="name")
|
||||
private String name;
|
||||
|
||||
@DatabaseField(columnName="status")
|
||||
private DownloadStatus status;
|
||||
|
||||
@DatabaseField(columnName="path")
|
||||
private String path;
|
||||
|
||||
@DatabaseField(columnName="progress")
|
||||
private long progress;
|
||||
|
||||
@DatabaseField(columnName="size")
|
||||
private long size;
|
||||
|
||||
@DatabaseField(columnName="percent")
|
||||
private double percent;
|
||||
|
||||
@DatabaseField(columnName="speed")
|
||||
private long speed;
|
||||
|
||||
@DatabaseField(columnName="meta", dataType=DataType.SERIALIZABLE)
|
||||
private HashMap<String, String> meta;//其他
|
||||
|
||||
public long getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
public void setSpeed(long speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getMeta() {
|
||||
return meta;
|
||||
}
|
||||
public void setMeta(HashMap<String, String> meta) {
|
||||
this.meta = meta;
|
||||
}
|
||||
public double getPercent() {
|
||||
return percent;
|
||||
}
|
||||
public void setPercent(double percent) {
|
||||
this.percent = percent;
|
||||
}
|
||||
// public String getId() {
|
||||
// return id;
|
||||
// }
|
||||
// public void setId(String id) {
|
||||
// this.id = id;
|
||||
// }
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public DownloadStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(DownloadStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
public long getProgress() {
|
||||
return progress;
|
||||
}
|
||||
public void setProgress(long progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder metas = new StringBuilder();
|
||||
metas.append("(");
|
||||
|
||||
|
||||
int i = 1;
|
||||
|
||||
if(meta != null){
|
||||
for (Entry<String, String> entry : meta.entrySet()) {
|
||||
metas.append(entry.getKey());
|
||||
metas.append(":");
|
||||
metas.append(entry.getValue());
|
||||
if(i != meta.size()){
|
||||
metas.append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
metas.append(")");
|
||||
return "["
|
||||
+ name + "==="
|
||||
+ url + "==="
|
||||
+ path + "==="
|
||||
+ status + "==="
|
||||
+ progress + "==="
|
||||
+ size + "==="
|
||||
+ percent + "%==="
|
||||
+ speed + "k/s==="
|
||||
+ metas +
|
||||
"]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -6,11 +6,12 @@ package com.gh.download;
|
||||
* @version create time:Sep 23, 2014 5:52:11 PM
|
||||
*/
|
||||
public interface DownloadListener {
|
||||
|
||||
/**
|
||||
* 更新每一次下载的大小
|
||||
* @param downloadedSize
|
||||
*/
|
||||
void onProgressChanged(int downloadedSize);
|
||||
void onProgressChanged(long length, int downloadedSize);
|
||||
|
||||
/**
|
||||
* 更新任务下载状态
|
||||
@ -18,5 +19,10 @@ public interface DownloadListener {
|
||||
*/
|
||||
void onStatusChanged(DownloadStatus status);
|
||||
|
||||
/**
|
||||
* 更新任务下载状态
|
||||
* @param status
|
||||
*/
|
||||
void onStatusChanged(DownloadStatus status, String error);
|
||||
|
||||
}
|
||||
|
||||
@ -9,22 +9,37 @@ import android.widget.Toast;
|
||||
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.Trace;
|
||||
import com.gh.common.util.MD5Utils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class DownloadManager {
|
||||
private static DownloadManager mInstance;
|
||||
private Context context;
|
||||
|
||||
private static DownloadManager mInstance;
|
||||
|
||||
private Context context;
|
||||
private Handler handler;
|
||||
|
||||
private ArrayMap<String, Long> lastTimeMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntity>> gameMap;
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DownloadManager(Context context) {
|
||||
this.context = context;
|
||||
lastTimeMap = new ArrayMap<String, Long>();
|
||||
|
||||
lastTimeMap = new ArrayMap<>();
|
||||
platformMap = new ArrayMap<>();
|
||||
gameMap = new ArrayMap<>();
|
||||
statusMap = new ArrayMap<>();
|
||||
|
||||
handler = new Handler(context.getMainLooper()){
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
@ -38,6 +53,16 @@ public class DownloadManager {
|
||||
if (System.currentTimeMillis() - lastTimeMap.get(url) >= 1000) {
|
||||
pause(url);
|
||||
}
|
||||
} else if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message message = Message.obtain();
|
||||
message.obj = name;
|
||||
message.what = Constants.DOWNLOAD_ROLL;
|
||||
sendMessageDelayed(message, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -48,6 +73,51 @@ public class DownloadManager {
|
||||
lastTimeMap.put(url, time);
|
||||
}
|
||||
|
||||
public void putQueue(String name, LinkedBlockingQueue<String> queue) {
|
||||
platformMap.put(name, queue);
|
||||
}
|
||||
|
||||
public LinkedBlockingQueue<String> getQueue(String name) {
|
||||
return platformMap.get(name);
|
||||
}
|
||||
|
||||
public void removePlatform(String name, String platform) {
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(name);
|
||||
if (queue != null) {
|
||||
queue.remove(platform);
|
||||
platformMap.put(name, queue);
|
||||
}
|
||||
}
|
||||
|
||||
public void initGameMap() {
|
||||
gameMap.clear();
|
||||
List<DownloadEntity> list = DownloadManager.getInstance(context).getAll();
|
||||
if (list != null && list.size() != 0) {
|
||||
String name;
|
||||
for (DownloadEntity downloadEntity : list) {
|
||||
name = downloadEntity.getName();
|
||||
ArrayMap<String, DownloadEntity> map = gameMap.get(name);
|
||||
if (map == null) {
|
||||
map = new ArrayMap<>();
|
||||
gameMap.put(name, map);
|
||||
}
|
||||
map.put(downloadEntity.getPlatform(), downloadEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayMap<String, DownloadEntity> getEntryMap(String name) {
|
||||
return gameMap.get(name);
|
||||
}
|
||||
|
||||
public void putStatus(String url, String status) {
|
||||
statusMap.put(url, status);
|
||||
}
|
||||
|
||||
public String getStatus(String url) {
|
||||
return statusMap.get(url);
|
||||
}
|
||||
|
||||
public void sendMessageDelayed(Message msg, long delayMillis) {
|
||||
handler.sendMessageDelayed(msg, delayMillis);
|
||||
}
|
||||
@ -59,7 +129,7 @@ public class DownloadManager {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
private Intent getIntent(DownloadEntry entry, DownloadStatus status) {
|
||||
private Intent getIntent(DownloadEntity entry, DownloadStatus status) {
|
||||
Intent service = new Intent(context, DownloadService.class);
|
||||
service.putExtra(Constants.KEY_DOWNLOAD_ENTRY, entry);
|
||||
service.putExtra(Constants.KEY_DOWNLOAD_ACTION, status.name());
|
||||
@ -69,18 +139,15 @@ public class DownloadManager {
|
||||
/**
|
||||
* 根据url到本地sqlite数据库中查找并获取该文件的保存路径, 并检查改路径下文件是否存在,不存在则删除该条无效记录
|
||||
*
|
||||
* @param url
|
||||
* 下载任务的标识url
|
||||
* @param url 下载任务的标识url
|
||||
*/
|
||||
private boolean checkDownloadEntryRecordValidate(String url) {
|
||||
DownloadEntry entry = get(url);
|
||||
DownloadEntity entry = get(url);
|
||||
if (entry != null && ((int)entry.getPercent()) != 0) {
|
||||
File file = new File(entry.getPath());
|
||||
if (!file.exists()) {
|
||||
DownloadDao.getInstance(context).delete(url);
|
||||
Trace.getInstance().debug(
|
||||
DownloadManager.class.getSimpleName(),
|
||||
"文件不存在,删除该条无效数据库记录!");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "文件不存在,删除该条无效数据库记录!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -94,12 +161,11 @@ public class DownloadManager {
|
||||
* @return
|
||||
*/
|
||||
public boolean isFileCompleted(String url) {
|
||||
DownloadEntry entry = get(url);
|
||||
DownloadEntity entry = get(url);
|
||||
|
||||
if (entry != null) {
|
||||
if (entry.getPercent() == 100) {
|
||||
Trace.getInstance().debug(
|
||||
DownloadManager.class.getSimpleName(), "文件已经下载完成!");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "文件已经下载完成!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -109,8 +175,7 @@ public class DownloadManager {
|
||||
|
||||
public boolean isTaskDownloading(String url) {
|
||||
if (DataChanger.getInstance().getDownloadingTasks().get(url) != null) {
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
url + "正在下载!");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), url + "正在下载!");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -119,17 +184,56 @@ public class DownloadManager {
|
||||
/**
|
||||
* 添加一个下载任务
|
||||
*
|
||||
* @param entry
|
||||
* @param downloadEntity
|
||||
*/
|
||||
public void add(DownloadEntry entry) {
|
||||
if (entry != null) {
|
||||
String url = entry.getUrl();
|
||||
public void add(DownloadEntity downloadEntity) {
|
||||
if (downloadEntity != null) {
|
||||
String url = downloadEntity.getUrl();
|
||||
checkDownloadEntryRecordValidate(url);
|
||||
if (!isFileCompleted(url) && !isTaskDownloading(url)) {
|
||||
context.startService(getIntent(entry, DownloadStatus.add));
|
||||
if (isFileCompleted(url)) {
|
||||
downloadEntity.setStatus(DownloadStatus.done);
|
||||
DataChanger.getInstance().notifyDataChanged(downloadEntity);
|
||||
} else if (!isTaskDownloading(url)) {
|
||||
context.startService(getIntent(downloadEntity, DownloadStatus.add));
|
||||
}
|
||||
}
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(), "add");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "add");
|
||||
}
|
||||
|
||||
public static void createDownload(Context context,
|
||||
GameEntity gameEntity,
|
||||
String method,
|
||||
String entrance,
|
||||
String location) {
|
||||
createDownload(context, gameEntity.getApk().get(0), gameEntity, method, entrance, location);
|
||||
}
|
||||
|
||||
public static void createDownload(Context context,
|
||||
ApkEntity apkEntity,
|
||||
GameEntity gameEntity,
|
||||
String method,
|
||||
String entrance,
|
||||
String location) {
|
||||
|
||||
DownloadEntity downloadEntity = new DownloadEntity();
|
||||
downloadEntity.setUrl(apkEntity.getUrl());
|
||||
downloadEntity.setName(gameEntity.getName());
|
||||
downloadEntity.setPath(FileUtils.getDownloadPath(context,
|
||||
MD5Utils.getContentMD5(gameEntity.getName() + "_" + System.currentTimeMillis()) + ".apk"));
|
||||
downloadEntity.setETag(apkEntity.getEtag());
|
||||
downloadEntity.setIcon(gameEntity.getIcon());
|
||||
downloadEntity.setPlatform(apkEntity.getPlatform());
|
||||
downloadEntity.setPackageName(apkEntity.getPackageName());
|
||||
downloadEntity.setGameId(gameEntity.getId());
|
||||
downloadEntity.setEntrance(entrance);
|
||||
downloadEntity.setLocation(location);
|
||||
if (method.equals("更新")) {
|
||||
downloadEntity.setUpdate(true);
|
||||
} else if (method.equals("插件化")) {
|
||||
downloadEntity.setPluggable(true);
|
||||
}
|
||||
downloadEntity.setPlugin(gameEntity.getTag() != null && gameEntity.getTag().size() != 0);
|
||||
DownloadManager.getInstance(context.getApplicationContext()).add(downloadEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,13 +243,12 @@ public class DownloadManager {
|
||||
*/
|
||||
public void pause(String url) {
|
||||
checkDownloadEntryRecordValidate(url);
|
||||
DownloadEntry entry = DataChanger.getInstance().getDownloadEntries()
|
||||
DownloadEntity entry = DataChanger.getInstance().getDownloadEntries()
|
||||
.get(url);
|
||||
if (entry != null) {
|
||||
context.startService(getIntent(entry, DownloadStatus.pause));
|
||||
}
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"pause");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "pause");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,7 +257,7 @@ public class DownloadManager {
|
||||
* @param url
|
||||
*/
|
||||
public void resume(String url) {
|
||||
DownloadEntry entry = get(url);
|
||||
DownloadEntity entry = get(url);
|
||||
|
||||
// 暂停任务后,把文件删除,然后点继续,文件不存在,需要重新加入下载队列进行下载
|
||||
if (checkDownloadEntryRecordValidate(url)) {
|
||||
@ -163,82 +266,74 @@ public class DownloadManager {
|
||||
add(entry);
|
||||
} else {
|
||||
if (entry != null) {
|
||||
if (!isFileCompleted(url) && !isTaskDownloading(url)) {
|
||||
if (isFileCompleted(url)) {
|
||||
entry.setStatus(DownloadStatus.done);
|
||||
DataChanger.getInstance().notifyDataChanged(entry);
|
||||
} else if (!isTaskDownloading(url)) {
|
||||
context.startService(getIntent(entry, DownloadStatus.resume));
|
||||
}
|
||||
}
|
||||
}
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"resume");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "resume");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据url取消下载,并删除已下载的文件
|
||||
*
|
||||
* @param id
|
||||
* @param url
|
||||
*/
|
||||
public void cancel(String url) {
|
||||
cancel(url, true);
|
||||
}
|
||||
|
||||
public void cancel(String url, boolean isDeleteFile) {
|
||||
|
||||
DownloadEntry temp = DownloadDao.getInstance(context).get(url);
|
||||
if (temp != null) {
|
||||
DownloadEntity entry = DownloadDao.getInstance(context).get(url);
|
||||
if (entry != null) {
|
||||
if (isDeleteFile) {
|
||||
FileUtils.deleteFile(temp.getPath());
|
||||
FileUtils.deleteFile(entry.getPath());
|
||||
}
|
||||
DownloadDao.getInstance(context).delete(url);
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"cancle==>file and record were deleted!");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "cancle==>file and record were deleted!");
|
||||
}
|
||||
|
||||
DownloadEntry entry = DataChanger.getInstance().getDownloadEntries()
|
||||
.get(url);
|
||||
if (entry != null) {
|
||||
entry.setStatus(DownloadStatus.cancel);
|
||||
context.startService(getIntent(entry, DownloadStatus.cancel));
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"cancel");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "cancel");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消并删除所有下载任务(包括下载中、等待、暂停状态的任务)
|
||||
*/
|
||||
public void cancleAll() {
|
||||
for (Entry<String, DownloadEntry> entry : DataChanger.getInstance()
|
||||
for (Entry<String, DownloadEntity> entry : DataChanger.getInstance()
|
||||
.getDownloadEntries().entrySet()) {
|
||||
cancel(entry.getValue().getUrl(), true);
|
||||
}
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"cancel all");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "cancel all");
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始所有下载任务
|
||||
*/
|
||||
public void startAll() {
|
||||
for (Entry<String, DownloadEntry> entry : DataChanger.getInstance()
|
||||
for (Entry<String, DownloadEntity> entry : DataChanger.getInstance()
|
||||
.getDownloadEntries().entrySet()) {
|
||||
add(entry.getValue());
|
||||
}
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"start all");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "start all");
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停所有正在下载的任务
|
||||
*/
|
||||
public void pauseAll() {
|
||||
for (Entry<String, DownloadEntry> entry : DataChanger.getInstance()
|
||||
.getDownloadEntries().entrySet()) {
|
||||
for (Entry<String, DownloadEntity> entry : DataChanger.getInstance().getDownloadEntries().entrySet()) {
|
||||
if (entry.getValue().getStatus() == DownloadStatus.downloading) {
|
||||
pause(entry.getValue().getUrl());
|
||||
}
|
||||
}
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"pause all");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "pause all");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,7 +342,7 @@ public class DownloadManager {
|
||||
* @param url
|
||||
* @return null表示下载列表中不存在该任务,否则返回下载任务
|
||||
*/
|
||||
public DownloadEntry get(String url) {
|
||||
public DownloadEntity get(String url) {
|
||||
return DownloadDao.getInstance(context).get(url);
|
||||
}
|
||||
|
||||
@ -256,28 +351,43 @@ public class DownloadManager {
|
||||
*
|
||||
* @return null表示没有下载任务
|
||||
*/
|
||||
public List<DownloadEntry> getAll() {
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"getAll");
|
||||
public List<DownloadEntity> getAll() {
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "getAll");
|
||||
return DownloadDao.getInstance(context).getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数据库中当前是下载状态,但并未在下载进程中的下载数据
|
||||
*/
|
||||
public void checkAll() {
|
||||
List<String> urlList = new ArrayList<>();
|
||||
for (Entry<String, DownloadTask> entry : DataChanger.getInstance()
|
||||
.getDownloadingTasks().entrySet()) {
|
||||
urlList.add(entry.getValue().getEntry().getUrl());
|
||||
}
|
||||
for (DownloadEntity downloadEntity : getAll()) {
|
||||
if (!urlList.contains(downloadEntity.getUrl())
|
||||
&& downloadEntity.getStatus().equals(DownloadStatus.downloading)) {
|
||||
downloadEntity.setStatus(DownloadStatus.pause);
|
||||
DownloadDao.getInstance(context).newOrUpdate(downloadEntity);
|
||||
DataChanger.getInstance().notifyDataChanged(downloadEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addObserver(DataWatcher dataWatcher) {
|
||||
DataChanger.getInstance().addObserver(dataWatcher);
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"addObserver");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "addObserver");
|
||||
}
|
||||
|
||||
public void removeObserver(DataWatcher dataWatcher) {
|
||||
DataChanger.getInstance().deleteObserver(dataWatcher);
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"removeObserver");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "removeObserver");
|
||||
}
|
||||
|
||||
public void removeObservers() {
|
||||
DataChanger.getInstance().deleteObservers();
|
||||
Trace.getInstance().debug(DownloadManager.class.getSimpleName(),
|
||||
"removeObservers");
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "removeObserver");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,16 +3,17 @@ package com.gh.download;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.Trace;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class DownloadService extends Service {
|
||||
|
||||
@Override
|
||||
@ -23,18 +24,15 @@ public class DownloadService extends Service {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Trace.getInstance().debug(DownloadService.class.getSimpleName(),
|
||||
"onStartCommand");
|
||||
Utils.log(DownloadService.class.getSimpleName(), "onStartCommand");
|
||||
if (intent != null && intent.getExtras() != null) {
|
||||
DownloadStatus status = DownloadStatus.valueOf(intent
|
||||
.getStringExtra(Constants.KEY_DOWNLOAD_ACTION));
|
||||
DownloadEntry entry = (DownloadEntry) intent
|
||||
DownloadEntity entry = (DownloadEntity) intent
|
||||
.getSerializableExtra(Constants.KEY_DOWNLOAD_ENTRY);
|
||||
switch (status) {
|
||||
case add:
|
||||
@ -58,18 +56,18 @@ public class DownloadService extends Service {
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
private synchronized void addDownload(DownloadEntry entry) {
|
||||
DownloadEntry downloadEntry = DownloadDao.getInstance(this).get(
|
||||
private synchronized void addDownload(DownloadEntity entry) {
|
||||
DownloadEntity downloadEntity = DownloadDao.getInstance(this).get(
|
||||
entry.getUrl());
|
||||
// 数据库下载历史中有这个任务的下载记录
|
||||
if (downloadEntry != null) {
|
||||
entry = downloadEntry;
|
||||
if (downloadEntity != null) {
|
||||
entry = downloadEntity;
|
||||
}
|
||||
|
||||
if (DataChanger.getInstance().getDownloadingSize() >= Constants.MAX_DOWNLOADING_SIZE) {
|
||||
if (DataChanger.getInstance().getDownloadingTasks().size() >= Constants.MAX_DOWNLOADING_SIZE) {
|
||||
// 1.改任务队列的状态
|
||||
entry.setStatus(DownloadStatus.waiting);
|
||||
DataChanger.getInstance().addToDownloadEntries(entry);
|
||||
DataChanger.getInstance().getDownloadEntries().put(entry.getUrl(), entry);
|
||||
// 2.改数据库状态
|
||||
DownloadDao.getInstance(this).newOrUpdate(entry);
|
||||
// 3.通知更新
|
||||
@ -77,34 +75,31 @@ public class DownloadService extends Service {
|
||||
} else {
|
||||
startDownload(entry);
|
||||
}
|
||||
Trace.getInstance().debug(DownloadService.class.getSimpleName(),
|
||||
"addDownload==>" + entry);
|
||||
Utils.log(DownloadService.class.getSimpleName(), "addDownload==>" + entry);
|
||||
EventBus.getDefault().post(new EBDownloadStatus("download"));
|
||||
}
|
||||
|
||||
private synchronized void startDownload(DownloadEntry entry) {
|
||||
private synchronized void startDownload(DownloadEntity entry) {
|
||||
// 1.改任务队列的状态
|
||||
entry.setStatus(DownloadStatus.downloading);
|
||||
DataChanger.getInstance().addToDownloadEntries(entry);
|
||||
DataChanger.getInstance().getDownloadEntries().put(entry.getUrl(), entry);
|
||||
DownloadTask task = new DownloadTask(handler, entry, this);
|
||||
task.start();
|
||||
DataChanger.getInstance().addToDownloadingTask(entry.getUrl(), task);
|
||||
DataChanger.getInstance().getDownloadingTasks().put(entry.getUrl(), task);
|
||||
// 2.改数据库状态
|
||||
DownloadDao.getInstance(this).newOrUpdate(entry);
|
||||
// 3.通知更新
|
||||
DataChanger.getInstance().notifyDataChanged(entry);
|
||||
|
||||
Trace.getInstance().debug(DownloadService.class.getSimpleName(),
|
||||
"startDownload==>" + entry);
|
||||
Utils.log(DownloadService.class.getSimpleName(), "startDownload==>" + entry);
|
||||
}
|
||||
|
||||
private synchronized void resumeDownload(DownloadEntry entry) {
|
||||
private synchronized void resumeDownload(DownloadEntity entry) {
|
||||
addDownload(entry);
|
||||
Trace.getInstance().debug(DownloadService.class.getSimpleName(),
|
||||
"resumeDownload==>" + entry);
|
||||
Utils.log(DownloadService.class.getSimpleName(), "resumeDownload==>" + entry);
|
||||
}
|
||||
|
||||
private synchronized void pauseDownload(DownloadEntry entry) {
|
||||
|
||||
private synchronized void pauseDownload(DownloadEntity entry) {
|
||||
if (entry != null) {
|
||||
DownloadTask task = DataChanger.getInstance().getDownloadingTasks()
|
||||
.get(entry.getUrl());
|
||||
@ -119,31 +114,33 @@ public class DownloadService extends Service {
|
||||
// 3.通知更新
|
||||
DataChanger.getInstance().notifyDataChanged(entry);
|
||||
}
|
||||
Trace.getInstance().debug(DownloadService.class.getSimpleName(),
|
||||
"pauseDownload==>" + entry);
|
||||
Utils.log(DownloadService.class.getSimpleName(), "pauseDownload==>" + entry);
|
||||
}
|
||||
|
||||
private synchronized void cancelDownload(DownloadEntry entry) {
|
||||
private synchronized void cancelDownload(DownloadEntity downloadEntity) {
|
||||
DownloadTask task = DataChanger.getInstance().getDownloadingTasks()
|
||||
.get(entry.getUrl());
|
||||
.get(downloadEntity.getUrl());
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
// 改任务队列的状态
|
||||
DataChanger.getInstance().removeDownloadingTask(entry.getUrl());
|
||||
DataChanger.getInstance().notifyDataChanged(entry);
|
||||
DataChanger.getInstance().getDownloadingTasks().remove(downloadEntity.getUrl());
|
||||
DataChanger.getInstance().notifyDataChanged(downloadEntity);
|
||||
}
|
||||
if (entry != null) {
|
||||
DataChanger.getInstance().removeDownloadEntry(entry.getUrl());
|
||||
DataChanger.getInstance().notifyDataChanged(entry);
|
||||
if (downloadEntity != null) {
|
||||
DataChanger.getInstance().getDownloadEntries().remove(downloadEntity.getUrl());
|
||||
DataChanger.getInstance().notifyDataChanged(downloadEntity);
|
||||
}
|
||||
Trace.getInstance().debug(DownloadService.class.getSimpleName(),
|
||||
"cancelDownload==>" + entry);
|
||||
Utils.log(DownloadService.class.getSimpleName(), "cancelDownload==>" + downloadEntity);
|
||||
EBDownloadStatus status = new EBDownloadStatus("delete", downloadEntity.getName(),
|
||||
downloadEntity.getPlatform(), downloadEntity.getUrl());
|
||||
status.setPluggable(downloadEntity.isPluggable());
|
||||
EventBus.getDefault().post(status);
|
||||
}
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
private Handler handler = new Handler() {
|
||||
public void handleMessage(android.os.Message msg) {
|
||||
DownloadEntry entry = (DownloadEntry) msg.obj;
|
||||
DownloadEntity entry = (DownloadEntity) msg.obj;
|
||||
DataChanger.getInstance().notifyDataChanged(entry);
|
||||
|
||||
if (msg.what == 1 && msg.obj != null) {
|
||||
@ -151,13 +148,10 @@ public class DownloadService extends Service {
|
||||
case downloading:
|
||||
break;
|
||||
case done:
|
||||
removeAndCheckNext(entry);
|
||||
break;
|
||||
case pause:
|
||||
// pauseDownload(entry);
|
||||
removeAndCheckNext(entry);
|
||||
break;
|
||||
case cancel:
|
||||
case timeout:
|
||||
case neterror:
|
||||
removeAndCheckNext(entry);
|
||||
break;
|
||||
default:
|
||||
@ -167,18 +161,17 @@ public class DownloadService extends Service {
|
||||
}
|
||||
};
|
||||
|
||||
private synchronized void removeAndCheckNext(DownloadEntry obj) {
|
||||
DataChanger.getInstance().removeDownloadingTask(obj.getUrl());
|
||||
DataChanger.getInstance().removeDownloadEntry(obj.getUrl());
|
||||
for (Entry<String, DownloadEntry> entry : DataChanger.getInstance()
|
||||
private synchronized void removeAndCheckNext(DownloadEntity downloadEntity) {
|
||||
DataChanger.getInstance().getDownloadingTasks().remove(downloadEntity.getUrl());
|
||||
DataChanger.getInstance().getDownloadEntries().remove(downloadEntity.getUrl());
|
||||
for (Entry<String, DownloadEntity> entry : DataChanger.getInstance()
|
||||
.getDownloadEntries().entrySet()) {
|
||||
if (entry.getValue().getStatus() == DownloadStatus.waiting) {
|
||||
startDownload(entry.getValue());
|
||||
return;
|
||||
}
|
||||
}
|
||||
Trace.getInstance().debug(DownloadService.class.getSimpleName(),
|
||||
"removeAndCheckNext==>" + obj);
|
||||
};
|
||||
Utils.log(DownloadService.class.getSimpleName(), "removeAndCheckNext==>" + downloadEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,16 +6,13 @@ import android.os.Message;
|
||||
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.Trace;
|
||||
import com.gh.common.util.Utils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class DownloadTask implements DownloadListener {
|
||||
|
||||
private DownloadEntry entry;
|
||||
private DownloadEntity entry;
|
||||
private Handler handler;
|
||||
private Context context;
|
||||
private DownloadThread downloadThread;
|
||||
@ -28,20 +25,20 @@ public class DownloadTask implements DownloadListener {
|
||||
private long lastTime;
|
||||
private long intervalDownloadedSize;
|
||||
|
||||
public DownloadTask(Handler handler, final DownloadEntry entry,
|
||||
public DownloadTask(Handler handler, final DownloadEntity entry,
|
||||
Context context) {
|
||||
|
||||
this.entry = entry;
|
||||
this.handler = handler;
|
||||
|
||||
this.context = context;
|
||||
DownloadEntry historyEntry = DownloadDao.getInstance(context).get(
|
||||
DownloadEntity historyEntry = DownloadDao.getInstance(context).get(
|
||||
entry.getUrl());
|
||||
if (historyEntry != null && historyEntry.getSize() != 0) {
|
||||
// 历史下载任务,初始化数据
|
||||
this.totalSize = entry.getSize();
|
||||
this.currPercent = (int) (entry.getProgress() * 100l / totalSize);
|
||||
Trace.getInstance().debug(DownloadTask.class.getSimpleName(),
|
||||
this.currPercent = (int) (entry.getProgress() * 100L / totalSize);
|
||||
Utils.log(DownloadTask.class.getSimpleName(),
|
||||
"DownloadTask==>" + "历史下载任务,初始化数据");
|
||||
} else {
|
||||
// 第一次下载
|
||||
@ -53,20 +50,18 @@ public class DownloadTask implements DownloadListener {
|
||||
|
||||
public void start() {
|
||||
// 从下载历史里获取过去下载的进度信息
|
||||
DownloadEntry downloadEntry = DownloadDao.getInstance(context).get(entry.getUrl());
|
||||
DownloadEntity downloadEntity = DownloadDao.getInstance(context).get(entry.getUrl());
|
||||
|
||||
if (downloadEntry != null) {
|
||||
entry = downloadEntry;
|
||||
if (downloadEntity != null) {
|
||||
entry = downloadEntity;
|
||||
entry.setStatus(DownloadStatus.downloading);
|
||||
Trace.getInstance().debug(
|
||||
DownloadTask.class.getSimpleName(),
|
||||
"start==>" + "load from history:" + entry.getUrl() + "--"
|
||||
+ entry.getProgress() + "," + entry.getSize());
|
||||
Utils.log(DownloadTask.class.getSimpleName(),
|
||||
"start==>" + "load from history:" + entry.getUrl()
|
||||
+ "--" + entry.getProgress() + "," + entry.getSize());
|
||||
currSize = entry.getProgress();
|
||||
currPercent = entry.getPercent();
|
||||
} else {
|
||||
Trace.getInstance().debug(DownloadTask.class.getSimpleName(),
|
||||
"start==>" + "First log into history!");
|
||||
Utils.log(DownloadTask.class.getSimpleName(), "start==>" + "First log into history!");
|
||||
}
|
||||
|
||||
downloadThread = new DownloadThread(context, this.entry, this);
|
||||
@ -75,8 +70,8 @@ public class DownloadTask implements DownloadListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onProgressChanged(int len) {
|
||||
currSize += len;
|
||||
public synchronized void onProgressChanged(long length, int len) {
|
||||
currSize = length;
|
||||
double percent = 0;
|
||||
if (entry.getSize() != 0) {
|
||||
percent = currSize * 100.0 / entry.getSize();
|
||||
@ -84,7 +79,11 @@ public class DownloadTask implements DownloadListener {
|
||||
percent = Double.parseDouble(df.format(percent));
|
||||
}
|
||||
entry.setProgress(currSize);
|
||||
entry.setPercent(percent);
|
||||
if (percent == 100.0d) {
|
||||
entry.setPercent(100);
|
||||
} else {
|
||||
entry.setPercent(percent);
|
||||
}
|
||||
|
||||
if (percent > currPercent) {
|
||||
currPercent = percent;
|
||||
@ -107,23 +106,25 @@ public class DownloadTask implements DownloadListener {
|
||||
intervalDownloadedSize += len;
|
||||
}
|
||||
|
||||
Trace.getInstance()
|
||||
.debug(DownloadTask.class.getSimpleName(),
|
||||
"onProgressChanged==>" + entry.getName() + "**"
|
||||
+ entry.getPercent() + "%**" + entry.getSpeed()
|
||||
+ "k/s");
|
||||
Utils.log(DownloadTask.class.getSimpleName(),
|
||||
"onProgressChanged==>" + entry.getName() + "**"
|
||||
+ entry.getPercent() + "%**" + entry.getSpeed() + "k/s");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(DownloadStatus status) {
|
||||
onStatusChanged(status, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(DownloadStatus status, String error) {
|
||||
if (status == DownloadStatus.cancel
|
||||
|| status == DownloadStatus.hijack) {
|
||||
entry.setProgress(0);
|
||||
entry.setPercent(0);
|
||||
FileUtils.deleteFile(entry.getPath());
|
||||
DownloadDao.getInstance(context).delete(entry.getUrl());
|
||||
Trace.getInstance().debug(DownloadTask.class.getSimpleName(),
|
||||
Utils.log(DownloadTask.class.getSimpleName(),
|
||||
"onStatusChanged==>" + entry.getUrl() + " is calcled!");
|
||||
}
|
||||
|
||||
@ -138,36 +139,21 @@ public class DownloadTask implements DownloadListener {
|
||||
}
|
||||
|
||||
/*********************** 处理网络异常 ***********************/
|
||||
if (status == DownloadStatus.timeout
|
||||
|| status == DownloadStatus.neterror) {
|
||||
HashMap<String, DownloadTask> map = DataChanger.getInstance().getDownloadingTasks();
|
||||
Iterator<String> iterator = map.keySet().iterator();
|
||||
String key;
|
||||
while (iterator.hasNext()) {
|
||||
key = iterator.next();
|
||||
DownloadTask task = map.get(key);
|
||||
if (task != null) {
|
||||
task.pause();
|
||||
}
|
||||
iterator.remove();
|
||||
if (status == DownloadStatus.timeout || status == DownloadStatus.neterror) {
|
||||
entry.setError(error);
|
||||
DownloadTask task = DataChanger.getInstance().getDownloadingTasks().remove(entry.getUrl());
|
||||
if (task != null) {
|
||||
task.pause();
|
||||
}
|
||||
for (Entry<String, DownloadEntry> entry : DataChanger.getInstance()
|
||||
.getDownloadEntries().entrySet()) {
|
||||
DataChanger.getInstance().pauseDownloadEntries(entry.getKey());
|
||||
DownloadDao.getInstance(context).newOrUpdate(entry.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
entry.setStatus(status);
|
||||
DownloadDao.getInstance(context).newOrUpdate(entry);
|
||||
Message msg = handler.obtainMessage();
|
||||
// handler.removeMessages(1);
|
||||
msg.what = 1;
|
||||
msg.obj = entry;
|
||||
handler.sendMessage(msg);
|
||||
Trace.getInstance().debug(DownloadTask.class.getSimpleName(),
|
||||
"onStatusChanged:" + status);
|
||||
Utils.log(DownloadTask.class.getSimpleName(), "onStatusChanged:" + status);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
@ -178,6 +164,7 @@ public class DownloadTask implements DownloadListener {
|
||||
downloadThread.setStatus(DownloadStatus.pause);
|
||||
}
|
||||
|
||||
// check download progress
|
||||
// DataChanger notify progress
|
||||
public DownloadEntity getEntry() {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.gh.common.util.Trace;
|
||||
import com.gh.common.util.HttpsUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
@ -17,16 +17,18 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class DownloadThread extends Thread {
|
||||
|
||||
private static final int CONNECT_TIME = 5000;
|
||||
private static final int READ_TIME = 5000;
|
||||
|
||||
private DownloadEntry entry;
|
||||
private DownloadEntity entry;
|
||||
private DownloadListener listener;
|
||||
private DownloadStatus status;
|
||||
private Context context;
|
||||
|
||||
public DownloadThread(Context context, DownloadEntry entry,
|
||||
DownloadListener listener) {
|
||||
public DownloadThread(Context context,
|
||||
DownloadEntity entry,
|
||||
DownloadListener listener) {
|
||||
this.entry = entry;
|
||||
this.listener = listener;
|
||||
this.context = context;
|
||||
@ -53,32 +55,41 @@ public class DownloadThread extends Thread {
|
||||
}
|
||||
|
||||
URL url = new URL(entry.getUrl());
|
||||
HttpURLConnection connection = (HttpURLConnection) url
|
||||
.openConnection();
|
||||
Utils.log("url = " + entry.getUrl());
|
||||
|
||||
HttpURLConnection connection;
|
||||
if ("https".equals(url.getProtocol())) {
|
||||
connection = HttpsUtils.getHttpsURLConnection(url);
|
||||
} else {
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
}
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setRequestProperty("RANGE",
|
||||
"bytes=" + targetFile.length() + "-");
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"startPosition-->" + targetFile.length());
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
Trace.getInstance().debug(DownloadThread.class.getSimpleName(),
|
||||
"startPosition-->" + targetFile.length());
|
||||
|
||||
|
||||
int code = connection.getResponseCode();
|
||||
if (code == HttpStatus.SC_MOVED_PERMANENTLY || code == HttpStatus.SC_MOVED_TEMPORARILY) {
|
||||
Utils.log("code = " +code);
|
||||
if (code == HttpStatus.SC_MOVED_PERMANENTLY
|
||||
|| code == HttpStatus.SC_MOVED_TEMPORARILY) {
|
||||
//未自动重定向
|
||||
String location = connection.getHeaderField("Location");
|
||||
Utils.log("location = " + location);
|
||||
// entry.setUrl(location);
|
||||
url = new URL(location);
|
||||
connection = (HttpURLConnection) url
|
||||
.openConnection();
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setRequestProperty("RANGE",
|
||||
"bytes=" + targetFile.length() + "-");
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"startPosition-->" + targetFile.length());
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
}
|
||||
@ -90,13 +101,13 @@ public class DownloadThread extends Thread {
|
||||
if (!TextUtils.isEmpty(eTag) && eTag.startsWith("\"") && eTag.endsWith("\"")) {
|
||||
eTag = eTag.substring(1, eTag.length() - 1);
|
||||
}
|
||||
String eTag2 = entry.getMeta().get("ETag");
|
||||
String eTag2 = entry.getETag();
|
||||
if (!TextUtils.isEmpty(eTag2) && !eTag2.equals(eTag)) {
|
||||
//链接被劫持,抛出异常
|
||||
Utils.log("eTag = " + eTag);
|
||||
Utils.log("eTag2 = " + eTag2);
|
||||
listener.onStatusChanged(DownloadStatus.hijack);
|
||||
Trace.getInstance().debug(DownloadThread.class.getSimpleName(),
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"error-->链接被劫持");
|
||||
interrupt();
|
||||
} else {
|
||||
@ -104,11 +115,10 @@ public class DownloadThread extends Thread {
|
||||
if (entry.getSize() == 0) {
|
||||
entry.setSize(conentLength);
|
||||
DownloadDao.getInstance(context).newOrUpdate(entry);
|
||||
Trace.getInstance().debug(DownloadThread.class.getSimpleName(),
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"记录第一次长度");
|
||||
}
|
||||
Trace.getInstance().debug(
|
||||
DownloadThread.class.getSimpleName(),
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"progress:" + entry.getProgress() + "/curfilesize:"
|
||||
+ targetFile.length() + "=====contentLength:"
|
||||
+ conentLength + "/ totalSize:" + entry.getSize());
|
||||
@ -117,7 +127,7 @@ public class DownloadThread extends Thread {
|
||||
int len;
|
||||
while ((len = bis.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
listener.onProgressChanged(len);
|
||||
listener.onProgressChanged(targetFile.length(), len);
|
||||
if (status == DownloadStatus.pause
|
||||
|| status == DownloadStatus.cancel) {
|
||||
listener.onStatusChanged(status);
|
||||
@ -129,10 +139,7 @@ public class DownloadThread extends Thread {
|
||||
listener.onStatusChanged(DownloadStatus.done);
|
||||
}
|
||||
bos.flush();
|
||||
Log.v("bug_test", "flush==>" + targetFile.length() + ",progress==>"
|
||||
+ entry.getProgress());
|
||||
Trace.getInstance().debug(
|
||||
DownloadThread.class.getSimpleName(),
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"flush==>" + targetFile.length() + ",progress==>"
|
||||
+ entry.getProgress());
|
||||
|
||||
@ -140,13 +147,15 @@ public class DownloadThread extends Thread {
|
||||
bos.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String errorMsg = Log.getStackTraceString(e);
|
||||
|
||||
//e.getMessage() will null error
|
||||
if (!TextUtils.isEmpty(e.getMessage()) && e.getMessage().contains("connection timeout")) {
|
||||
listener.onStatusChanged(DownloadStatus.timeout);
|
||||
listener.onStatusChanged(DownloadStatus.timeout, errorMsg);
|
||||
} else {
|
||||
listener.onStatusChanged(DownloadStatus.neterror);
|
||||
listener.onStatusChanged(DownloadStatus.neterror, errorMsg);
|
||||
}
|
||||
Trace.getInstance().debug(DownloadThread.class.getSimpleName(),
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"exception-->" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,105 +1,103 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.common.view.Concern_LinearLayout;
|
||||
import com.gh.gamecenter.adapter.ConcernAdapter;
|
||||
import com.gh.gamecenter.adapter.ConcernRecommendAdapter;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
public static final String TAG = ConcernActivity.class.getSimpleName();
|
||||
|
||||
private Concern_LinearLayout view;
|
||||
private RecyclerView concern_rv_show, concern_rv_recommend;
|
||||
private ConcernManager manager;
|
||||
private ImageView concern_iv_delete;
|
||||
private ConcernAdapter concernAdapter;
|
||||
private ConcernRecommendAdapter concernRecommendAdapter;
|
||||
private RelativeLayout concern_rl_title;
|
||||
private TextView concern_tv_none;
|
||||
private LinearLayout reuse_none_data;
|
||||
|
||||
private List<ConcernInfo> list;
|
||||
private List<GameEntity> recommendList;
|
||||
private List<GameEntity> concernList;
|
||||
private ConcernManager concernManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
view = (Concern_LinearLayout) View.inflate(this,
|
||||
R.layout.activity_concern, null);
|
||||
|
||||
view = (Concern_LinearLayout) View.inflate(this, R.layout.activity_concern, null);
|
||||
init(view, "我的关注");
|
||||
|
||||
manager = new ConcernManager(getApplicationContext());
|
||||
concernManager = new ConcernManager(getApplicationContext());
|
||||
|
||||
list = manager.getConcernGame();
|
||||
|
||||
if (list == null) {
|
||||
list = new ArrayList<ConcernInfo>();
|
||||
}
|
||||
|
||||
recommendList = new ArrayList<GameEntity>();
|
||||
|
||||
concernList = new ArrayList<GameEntity>();
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
initConcernGame();
|
||||
} else {
|
||||
concern_tv_none.setVisibility(View.VISIBLE);
|
||||
List<ConcernInfo> concernList = concernManager.getConcernGame();
|
||||
if (concernList == null || concernList.isEmpty()) {
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
concern_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
concern_iv_delete.setOnClickListener(this);
|
||||
concern_rl_title.setOnClickListener(this);
|
||||
|
||||
concern_rv_show.setHasFixedSize(true);
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
|
||||
concern_rv_show.setLayoutManager(gridLayoutManager);
|
||||
concern_rv_show.setAdapter(new ConcernViewAdapter());
|
||||
concern_rv_show.setLayoutManager(new GridLayoutManager(this, 3));
|
||||
concernAdapter = new ConcernAdapter(this);
|
||||
concern_rv_show.setAdapter(concernAdapter);
|
||||
|
||||
concern_rv_recommend.setHasFixedSize(true);
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(this, 4));
|
||||
concern_rv_recommend.setAdapter(new RecommendViewAdapter());
|
||||
concernRecommendAdapter = new ConcernRecommendAdapter(this);
|
||||
concern_rv_recommend.setAdapter(concernRecommendAdapter);
|
||||
}
|
||||
|
||||
initRecommendGame();
|
||||
@Override
|
||||
public void loadEmpty() {
|
||||
if (concernAdapter.getConcernList() == null
|
||||
|| concernAdapter.getConcernList().isEmpty()) {
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
concern_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
if (concernRecommendAdapter.getRecommendGameList() == null
|
||||
|| concernRecommendAdapter.getRecommendGameList().isEmpty()) {
|
||||
concern_rl_title.setVisibility(View.GONE);
|
||||
concern_rv_recommend.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (concernRecommendAdapter.getRecommendGameList().size() < 4) {
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(
|
||||
ConcernActivity.this, concernRecommendAdapter.getRecommendGameList().size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
concern_rl_title.setVisibility(View.VISIBLE);
|
||||
concern_rv_recommend.setVisibility(View.VISIBLE);
|
||||
int size = concernRecommendAdapter.getRecommendGameList().size();
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(this, size > 4 ? 4 : size));
|
||||
concern_rv_recommend.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == concern_iv_delete) {
|
||||
if (v == concern_rl_title) {
|
||||
if (concern_rv_recommend.getVisibility() == View.VISIBLE) {
|
||||
view.hideRecyclerView();
|
||||
} else {
|
||||
@ -108,305 +106,70 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void initRecommendGame() {
|
||||
JsonArrayExtendedRequest recommendRequest = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/game/remenkapai", Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
processingData(response);
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
Utils.log("changed = " + changed.getGameId());
|
||||
Utils.log("changed = " + changed.isConcern());
|
||||
if (changed.isConcern()) {
|
||||
for (GameEntity gameEntity : concernRecommendAdapter.getGameList()) {
|
||||
if (changed.getGameId().equals(gameEntity.getId())) {
|
||||
ConcernInfo concernInfo = new ConcernInfo();
|
||||
concernInfo.setGameName(gameEntity.getName());
|
||||
concernInfo.setConcern(true);
|
||||
concernInfo.setIcon(gameEntity.getIcon());
|
||||
concernInfo.setId(gameEntity.getId());
|
||||
concernAdapter.getConcernList().add(concernInfo);
|
||||
concernAdapter.getConcernGameList().add(gameEntity);
|
||||
if (reuse_none_data.getVisibility() == View.VISIBLE) {
|
||||
reuse_none_data.setVisibility(View.GONE);
|
||||
concern_rv_show.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接
|
||||
if (error.getClass().equals(NoConnectionError.class)) {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(recommendRequest, ConcernActivity.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<GameEntity> list = gson.fromJson(response.toString(), listType);
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
if (!manager.isConcern(list.get(i).getId())) {
|
||||
recommendList.add(list.get(i));
|
||||
concernAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!recommendList.isEmpty()) {
|
||||
concern_rl_title.setVisibility(View.VISIBLE);
|
||||
concern_rv_recommend.setVisibility(View.VISIBLE);
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(this,
|
||||
recommendList.size() > 4 ? 4 : recommendList.size()));
|
||||
concern_rv_recommend.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void initConcernGame() {
|
||||
final List<JSONObject> result = new ArrayList<JSONObject>();
|
||||
final int count = list.size();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
JsonObjectExtendedRequest concernObjectRequest = new JsonObjectExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/"
|
||||
+ list.get(i).getId() + "/digest", Constants.GAME_CD),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
result.add(response);
|
||||
if (result.size() == count) {
|
||||
processingConcernGame(result);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接
|
||||
if (error.getClass().equals(NoConnectionError.class)) {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(concernObjectRequest, ConcernActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingConcernGame(List<JSONObject> data) {
|
||||
List<GameEntity> gameList = new ArrayList<GameEntity>();
|
||||
Gson gson = new Gson();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
gameList.add(gson.fromJson(data.get(i).toString(), GameEntity.class));
|
||||
}
|
||||
for (int i = 0, sizei = list.size(); i < sizei; i++) {
|
||||
for (int j = 0, sizej = gameList.size(); j < sizej; j++) {
|
||||
if (list.get(i).getId().equals(gameList.get(j).getId())) {
|
||||
concernList.add(gameList.get(j));
|
||||
for (int i = 0, size = concernRecommendAdapter.getRecommendGameList().size(); i < size; i++) {
|
||||
if (changed.getGameId().equals(concernRecommendAdapter.getRecommendGameList().get(i).getId())) {
|
||||
concernRecommendAdapter.getRecommendGameList().remove(i);
|
||||
concernRecommendAdapter.notifyDataSetChanged();
|
||||
if (concernRecommendAdapter.getRecommendGameList().isEmpty()) {
|
||||
concern_rl_title.setVisibility(View.GONE);
|
||||
concern_rv_recommend.setVisibility(View.GONE);
|
||||
}
|
||||
if (concernRecommendAdapter.getRecommendGameList().size() < 4) {
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(
|
||||
ConcernActivity.this, concernRecommendAdapter.getRecommendGameList().size()));
|
||||
} else {
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(
|
||||
ConcernActivity.this, 4));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
concern_rv_show.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private class ConcernViewHolder extends RecyclerView.ViewHolder implements
|
||||
OnClickListener {
|
||||
|
||||
private ImageView concern_item_icon;
|
||||
private TextView concern_item_name, concern_item_btn;
|
||||
private View view;
|
||||
|
||||
public ConcernViewHolder(View convertView) {
|
||||
super(convertView);
|
||||
concern_item_icon = (ImageView) convertView.findViewById(R.id.concern_item_icon);
|
||||
concern_item_name = (TextView) convertView.findViewById(R.id.concern_item_name);
|
||||
concern_item_btn = (TextView) convertView.findViewById(R.id.concern_item_btn);
|
||||
concern_item_btn.setOnClickListener(this);
|
||||
convertView.setOnClickListener(this);
|
||||
view = convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getPosition();
|
||||
if (v == concern_item_btn) {
|
||||
// 删除关注表中的数据,并更新界面
|
||||
if (manager.findConcernById(list.get(position).getId()) != null) {
|
||||
ConcernInfo concernInfo = list.remove(position);
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("状态", "取消关注");
|
||||
DataUtils.onEvent(ConcernActivity.this, "游戏关注", concernInfo.getGameName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", concernInfo.getGameName());
|
||||
map.put("type", "取消关注");
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(ConcernActivity.this, "concern", map);
|
||||
|
||||
manager.deleteConcern(concernInfo.getId());
|
||||
concernList.remove(position);
|
||||
concern_rv_show.getAdapter().notifyItemRemoved(position);
|
||||
if (list.isEmpty()) {
|
||||
concern_tv_none.setVisibility(View.VISIBLE);
|
||||
concern_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
concern_item_btn.setClickable(false);
|
||||
view.setClickable(false);
|
||||
|
||||
recommendList = new ArrayList<GameEntity>();
|
||||
initRecommendGame();
|
||||
} else {
|
||||
toast("取消失败,请稍后再试");
|
||||
}
|
||||
} else {
|
||||
if (concernList != null && !concernList.isEmpty()) {
|
||||
GameEntity gameEntity = concernList.get(position);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "关注列表");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("page", "我的关注");
|
||||
DataCollectionManager.onEvent(ConcernActivity.this, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
Intent intent = new Intent(ConcernActivity.this, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "我的关注-列表");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
concernRecommendAdapter.getRecommendGameList().clear();
|
||||
for (int i = 0, size = concernRecommendAdapter.getGameList().size(); i < size; i++) {
|
||||
if (!concernManager.isConcern(concernRecommendAdapter.getGameList().get(i).getId())) {
|
||||
concernRecommendAdapter.getRecommendGameList().add(concernRecommendAdapter.getGameList().get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ConcernViewAdapter extends
|
||||
RecyclerView.Adapter<ConcernViewHolder> {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ConcernViewHolder holder, int position) {
|
||||
ConcernInfo concernEntity = list.get(position);
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
concernEntity.getIcon(), holder.concern_item_icon);
|
||||
holder.concern_item_name.setText(concernEntity.getGameName());
|
||||
holder.concern_item_btn.setText("取消关注");
|
||||
holder.concern_item_btn.setBackgroundResource(R.drawable.textview_cancel_style);
|
||||
holder.concern_item_btn.setClickable(true);
|
||||
holder.view.setClickable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConcernViewHolder onCreateViewHolder(ViewGroup viewGroup,
|
||||
int type) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.concern_item, viewGroup, false);
|
||||
return new ConcernViewHolder(view);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class RecommendViewHolder extends RecyclerView.ViewHolder implements
|
||||
OnClickListener {
|
||||
|
||||
private ImageView concern_item_icon;
|
||||
private TextView concern_item_name, concern_item_btn;
|
||||
private View view;
|
||||
|
||||
public RecommendViewHolder(View convertView) {
|
||||
super(convertView);
|
||||
|
||||
concern_item_icon = (ImageView) convertView.findViewById(R.id.concern_item_icon);
|
||||
concern_item_name = (TextView) convertView.findViewById(R.id.concern_item_name);
|
||||
concern_item_btn = (TextView) convertView.findViewById(R.id.concern_item_btn);
|
||||
concern_item_btn.setOnClickListener(this);
|
||||
convertView.setOnClickListener(this);
|
||||
view = convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getPosition();
|
||||
if (v == concern_item_btn) {
|
||||
// 添加关注到表,并更新当前界面,插入一个关注
|
||||
GameEntity gameEntity = recommendList.get(position);
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("状态", "关注");
|
||||
DataUtils.onEvent(ConcernActivity.this, "游戏关注", gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("type", "关注");
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(ConcernActivity.this, "concern", map);
|
||||
|
||||
manager.addByEntity(gameEntity);
|
||||
ConcernInfo concernEntity = new ConcernInfo();
|
||||
concernEntity.setGameName(gameEntity.getName());
|
||||
concernEntity.setConcern(true);
|
||||
concernEntity.setIcon(gameEntity.getIcon());
|
||||
concernEntity.setId(gameEntity.getId());
|
||||
list.add(concernEntity);
|
||||
if (list.size() == 1) {
|
||||
concern_tv_none.setVisibility(View.GONE);
|
||||
concern_rv_show.setVisibility(View.VISIBLE);
|
||||
}
|
||||
concern_rv_show.getAdapter().notifyItemInserted(list.size() - 1);
|
||||
|
||||
concernList.add(recommendList.remove(position));
|
||||
if (recommendList.isEmpty()) {
|
||||
concern_rl_title.setVisibility(View.GONE);
|
||||
concern_rv_recommend.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (recommendList.size() < 4) {
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(
|
||||
ConcernActivity.this, recommendList.size()));
|
||||
}
|
||||
concern_rv_recommend.getAdapter().notifyItemRemoved(position);
|
||||
}
|
||||
concern_item_btn.setClickable(false);
|
||||
view.setClickable(false);
|
||||
concernRecommendAdapter.notifyDataSetChanged();
|
||||
if (concernRecommendAdapter.getRecommendGameList().isEmpty()) {
|
||||
concern_rl_title.setVisibility(View.GONE);
|
||||
concern_rv_recommend.setVisibility(View.GONE);
|
||||
} else {
|
||||
GameEntity gameEntity = recommendList.get(position);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("location", "热门游戏推荐");
|
||||
map.put("createOn", System.currentTimeMillis() / 1000);
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("page", "我的关注");
|
||||
DataCollectionManager.onEvent(ConcernActivity.this, "click-item", map);
|
||||
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
|
||||
Intent intent = new Intent(ConcernActivity.this, GameDetailsActivity.class);
|
||||
intent.putExtra("entrance", "我的关注-推荐");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
concern_rl_title.setVisibility(View.VISIBLE);
|
||||
concern_rv_recommend.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (concernRecommendAdapter.getRecommendGameList().size() < 4) {
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(
|
||||
ConcernActivity.this, concernRecommendAdapter.getRecommendGameList().size()));
|
||||
} else {
|
||||
concern_rv_recommend.setLayoutManager(new GridLayoutManager(
|
||||
ConcernActivity.this, 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class RecommendViewAdapter extends RecyclerView.Adapter<RecommendViewHolder> {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return recommendList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecommendViewHolder holder, int position) {
|
||||
GameEntity gameEntity = recommendList.get(position);
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
gameEntity.getIcon(), holder.concern_item_icon);
|
||||
holder.concern_item_name.setText(gameEntity.getName());
|
||||
holder.concern_item_btn.setText("关注");
|
||||
holder.concern_item_btn.setBackgroundResource(R.drawable.textview_red_style);
|
||||
holder.concern_item_btn.setClickable(true);
|
||||
holder.view.setClickable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecommendViewHolder onCreateViewHolder(ViewGroup viewGroup,
|
||||
int type) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.concern_item, viewGroup, false);
|
||||
return new RecommendViewHolder(view);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isPause = false;
|
||||
|
||||
@Override
|
||||
@ -420,56 +183,49 @@ public class ConcernActivity extends BaseActivity implements OnClickListener {
|
||||
super.onResume();
|
||||
Utils.log("isPause = " + isPause);
|
||||
if (isPause) {
|
||||
List<ConcernInfo> concernList = manager.getConcernGame();
|
||||
List<ConcernInfo> concernList = concernManager.getConcernGame();
|
||||
boolean isChanged = false;
|
||||
if (concernList == null) {
|
||||
if (list.size() != 0){
|
||||
if (concernAdapter.getConcernList().size() != 0){
|
||||
isChanged = true;
|
||||
}
|
||||
} else {
|
||||
if (list.isEmpty()
|
||||
|| concernList.size() > list.size()
|
||||
|| concernList.size() < list.size()) {
|
||||
if (concernAdapter.getConcernList() == null
|
||||
|| concernAdapter.getConcernList().isEmpty()
|
||||
|| concernList.size() > concernAdapter.getConcernList().size()
|
||||
|| concernList.size() < concernAdapter.getConcernList().size()) {
|
||||
isChanged = true;
|
||||
}
|
||||
}
|
||||
Utils.log("isChanged = " + isChanged);
|
||||
if (isChanged) {
|
||||
list = concernList;
|
||||
if (list == null) {
|
||||
list = new ArrayList<ConcernInfo>();
|
||||
}
|
||||
concernList = new ArrayList<ConcernInfo>();
|
||||
if (!list.isEmpty()) {
|
||||
concern_tv_none.setVisibility(View.GONE);
|
||||
concern_rv_show.setVisibility(View.VISIBLE);
|
||||
initConcernGame();
|
||||
} else {
|
||||
concern_tv_none.setVisibility(View.VISIBLE);
|
||||
concern_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
recommendList = new ArrayList<GameEntity>();
|
||||
initRecommendGame();
|
||||
concernAdapter = new ConcernAdapter(this);
|
||||
concern_rv_show.setAdapter(concernAdapter);
|
||||
}
|
||||
isPause = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
view = null;
|
||||
concern_rv_show = null;
|
||||
concern_rv_recommend = null;
|
||||
manager = null;
|
||||
concern_iv_delete = null;
|
||||
concern_rl_title = null;
|
||||
concern_tv_none = null;
|
||||
list = null;
|
||||
recommendList = null;
|
||||
concernList = null;
|
||||
AppController.canclePendingRequests(TAG);
|
||||
String uuid = TokenUtils.getDeviceId(this);
|
||||
JSONArray data = new JSONArray();
|
||||
for (ConcernInfo concernInfo : concernManager.getConcernGame()) {
|
||||
data.put(concernInfo.getId());
|
||||
}
|
||||
ConcernUtils.updateConcernData(Config.HOST + "v2d0/device/" + uuid + "/concern", data,
|
||||
new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
public void downSucced(String str) {
|
||||
Utils.log("更新设备关注游戏成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downFailed() {
|
||||
Utils.log("更新设备关注游戏失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
117
app/src/main/java/com/gh/gamecenter/CropImageActivity.java
Normal file
117
app/src/main/java/com/gh/gamecenter/CropImageActivity.java
Normal file
@ -0,0 +1,117 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.view.CropImageCustom;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CropImageActivity extends BaseActivity {
|
||||
|
||||
private CropImageCustom cropimage_custom;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what == 0) {
|
||||
toast("上传成功");
|
||||
} else if (msg.what == 1) {
|
||||
toast("上传失败");
|
||||
} else if (msg.what == 2) {
|
||||
toast("修改太频繁,请稍后再试");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_cropimage, null);
|
||||
|
||||
init(contentView, "图片裁剪");
|
||||
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) findViewById(R.id.reuse_actionbar);
|
||||
|
||||
TextView confirm = new TextView(this);
|
||||
confirm.setText("确定");
|
||||
confirm.setTextColor(0xffffffff);
|
||||
confirm.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
||||
int padding = DisplayUtils.dip2px(getApplicationContext(), 10);
|
||||
confirm.setPadding(padding, padding, padding, padding);
|
||||
confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final Dialog dialog = DialogUtils.showWaitDialog(
|
||||
CropImageActivity.this, "上传中...");
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String path = getCacheDir() + File.separator
|
||||
+ System.currentTimeMillis() + ".jpg";
|
||||
if (cropimage_custom.savePicture(path)) {
|
||||
// 上传图片
|
||||
JSONObject result = FileUtils.uploadFile("http://user.ghzhushou.com/v1d0/icon",
|
||||
path, TokenUtils.getToken(CropImageActivity.this));
|
||||
dialog.dismiss();
|
||||
if (result != null) {
|
||||
try {
|
||||
int statusCode = result.getInt("statusCode");
|
||||
if (statusCode == HttpStatus.SC_OK) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra("url", result.getString("icon"));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
handler.sendEmptyMessage(0);
|
||||
} else if (statusCode == HttpStatus.SC_FORBIDDEN
|
||||
&& "too frequent".equals(result.getString("detail"))) {
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
handler.sendEmptyMessage(1);
|
||||
}
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
handler.sendEmptyMessage(1);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
rparams.addRule(RelativeLayout.CENTER_VERTICAL);
|
||||
confirm.setLayoutParams(rparams);
|
||||
reuse_actionbar.addView(confirm);
|
||||
|
||||
String path = getIntent().getStringExtra("path");
|
||||
|
||||
ImageUtils.getInstance(getApplicationContext()).displayFile(
|
||||
"file://" + path, cropimage_custom.getCropImageZoomView());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -15,7 +15,7 @@ import android.widget.TextView;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.download.DownLoadManagerFragment;
|
||||
import com.gh.gamecenter.download.GameDownLoadFragment;
|
||||
import com.gh.gamecenter.download.GameUpdateFragment;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
import com.gh.gamecenter.eventbus.EBMiPush;
|
||||
@ -35,10 +35,12 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
OnClickListener, OnPageChangeListener {
|
||||
|
||||
private ViewPager downloadmanager_viewPager;
|
||||
private TextView downloadmanager_tv_download, downloadmanager_tv_update,
|
||||
downloadmanager_download_number, downloadmanager_update_number;
|
||||
private LinearLayout downloadmanager_ll_download,
|
||||
downloadmanager_ll_update;
|
||||
private TextView downloadmanager_tv_download;
|
||||
private TextView downloadmanager_tv_update;
|
||||
private TextView downloadmanager_download_number;
|
||||
private TextView downloadmanager_update_number;
|
||||
private LinearLayout downloadmanager_ll_download;
|
||||
private LinearLayout downloadmanager_ll_update;
|
||||
private View downloadmanager_slide_line;
|
||||
private LinearLayout.LayoutParams lparams;
|
||||
|
||||
@ -46,45 +48,37 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("CurrentItem", downloadmanager_viewPager.getCurrentItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this,
|
||||
R.layout.activity_downloadmanager, null);
|
||||
|
||||
init(contentView, "下载更新管理");
|
||||
View contentView = View.inflate(this, R.layout.activity_downloadmanager, null);
|
||||
init(contentView, "下载管理");
|
||||
|
||||
downloadmanager_ll_download.setOnClickListener(this);
|
||||
downloadmanager_ll_update.setOnClickListener(this);
|
||||
|
||||
int currentItem = getIntent().getIntExtra("currentItem", -1);
|
||||
|
||||
int updateSize = PackageManager.getUpdateList().size();
|
||||
|
||||
int downloadSize = DownloadManager.getInstance(getApplicationContext())
|
||||
.getAll().size();
|
||||
|
||||
if (updateSize != 0) {
|
||||
downloadmanager_update_number.setVisibility(View.VISIBLE);
|
||||
downloadmanager_update_number.setText("" + updateSize);
|
||||
downloadmanager_update_number.setText(String.valueOf(updateSize));
|
||||
} else {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
int downloadSize = DownloadManager.getInstance(getApplicationContext()).getAll().size();
|
||||
if (downloadSize != 0) {
|
||||
downloadmanager_download_number.setVisibility(View.VISIBLE);
|
||||
downloadmanager_download_number.setText("" + downloadSize);
|
||||
downloadmanager_download_number.setText(String.valueOf(downloadSize));
|
||||
} else {
|
||||
downloadmanager_download_number.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
int currentItem = getIntent().getIntExtra("currentItem", -1);
|
||||
if (currentItem == -1) {
|
||||
if (updateSize != 0 && downloadSize == 0) {
|
||||
currentItem = 1;
|
||||
@ -96,8 +90,7 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / 2;
|
||||
lparams = new LinearLayout.LayoutParams(width / 2, DisplayUtils.dip2px(
|
||||
getApplicationContext(), 2));
|
||||
lparams = new LinearLayout.LayoutParams(width / 2, DisplayUtils.dip2px(getApplicationContext(), 2));
|
||||
lparams.leftMargin = outMetrics.widthPixels / 8;
|
||||
if (currentItem != 0) {
|
||||
downloadmanager_ll_download.setClickable(true);
|
||||
@ -130,9 +123,8 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
|
||||
if (position == 0) {
|
||||
DownLoadManagerFragment fragment = new DownLoadManagerFragment();
|
||||
GameDownLoadFragment fragment = new GameDownLoadFragment();
|
||||
fragment.setPath(getIntent().getStringExtra("path"));
|
||||
return fragment;
|
||||
} else {
|
||||
@ -160,17 +152,15 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
new EBUISwitch("DownloadManagerActivity", 0));
|
||||
downloadmanager_ll_download.setClickable(false);
|
||||
downloadmanager_ll_update.setClickable(true);
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
downloadmanager_tv_update.setTextColor(0xFF333333);
|
||||
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_ll_download.setClickable(true);
|
||||
downloadmanager_ll_update.setClickable(false);
|
||||
downloadmanager_tv_download.setTextColor(0xFF333333);
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
downloadmanager_tv_download.setTextColor(getResources().getColor(R.color.title));
|
||||
downloadmanager_tv_update.setTextColor(getResources().getColor(R.color.theme));
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,7 +204,7 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBDownloadChanged changed) {
|
||||
if (changed.getType() == "download") {
|
||||
if ("download".equals(changed.getType())) {
|
||||
if (changed.getVisibility() == View.VISIBLE){
|
||||
downloadmanager_download_number.setVisibility(View.VISIBLE);
|
||||
} else if (changed.getVisibility() == View.GONE) {
|
||||
@ -222,15 +212,15 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
} else if (changed.getVisibility() == View.INVISIBLE) {
|
||||
downloadmanager_download_number.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
downloadmanager_download_number.setText(changed.getSize() + "");
|
||||
} else if (changed.getType() == "update") {
|
||||
downloadmanager_download_number.setText(String.valueOf(changed.getSize()));
|
||||
} else if ("update".equals(changed.getType())) {
|
||||
if (changed.getSize() == -1) {
|
||||
int number = Integer.valueOf(downloadmanager_update_number
|
||||
.getText().toString());
|
||||
if (number == 1) {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
} else {
|
||||
downloadmanager_update_number.setText((number - 1) + "");
|
||||
downloadmanager_update_number.setText(String.valueOf(number - 1));
|
||||
}
|
||||
} else {
|
||||
if (changed.getSize() != 0) {
|
||||
@ -241,7 +231,7 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
} else if (changed.getVisibility() == View.INVISIBLE) {
|
||||
downloadmanager_update_number.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
downloadmanager_update_number.setText(changed.getSize() + "");
|
||||
downloadmanager_update_number.setText(String.valueOf(changed.getSize()));
|
||||
} else {
|
||||
downloadmanager_update_number.setVisibility(View.GONE);
|
||||
}
|
||||
@ -255,17 +245,4 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
downloadmanager_viewPager = null;
|
||||
downloadmanager_tv_download = null;
|
||||
downloadmanager_tv_update = null;
|
||||
downloadmanager_download_number = null;
|
||||
downloadmanager_update_number = null;
|
||||
downloadmanager_ll_download = null;
|
||||
downloadmanager_ll_update = null;
|
||||
downloadmanager_slide_line = null;
|
||||
lparams = null;
|
||||
}
|
||||
}
|
||||
@ -1,183 +0,0 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.game.Game1Fragment;
|
||||
import com.gh.gamecenter.game.Game2Fragment;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class GameActivity extends BaseFragmentActivity implements
|
||||
OnClickListener, OnPageChangeListener {
|
||||
|
||||
private ViewPager game_viewpager;
|
||||
private TextView new_game_text, test_game_text;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
private View slide_line;
|
||||
|
||||
private int width;
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
|
||||
super.onSaveInstanceState(outState);
|
||||
Utils.log(this.getClass().getSimpleName() + " onSaveInstanceState");
|
||||
outState.putInt("CurrentItem", game_viewpager.getCurrentItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_game, null);
|
||||
|
||||
init(contentView, "游戏");
|
||||
|
||||
initView();
|
||||
if (savedInstanceState != null) {
|
||||
rparams.leftMargin = width
|
||||
* savedInstanceState.getInt("CurrentItem") + width / 4;
|
||||
slide_line.setLayoutParams(rparams);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void initView() {
|
||||
new_game_text.setOnClickListener(this);
|
||||
test_game_text.setOnClickListener(this);
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / 2;
|
||||
rparams = new RelativeLayout.LayoutParams(width / 2,
|
||||
DisplayUtils.dip2px(getApplicationContext(), 2));
|
||||
rparams.addRule(RelativeLayout.BELOW, R.id.game_ll_top);
|
||||
rparams.leftMargin = outMetrics.widthPixels / 8;
|
||||
slide_line.setLayoutParams(rparams);
|
||||
|
||||
game_viewpager.setAdapter(new ViewPagerAdapter(
|
||||
getSupportFragmentManager()));
|
||||
game_viewpager.addOnPageChangeListener(this);
|
||||
int currTab = getIntent().getIntExtra("tab", 0);
|
||||
setcurrTab(currTab);
|
||||
}
|
||||
|
||||
private void setcurrTab(int position) {
|
||||
game_viewpager.setCurrentItem(position);
|
||||
if (position == 0) {
|
||||
new_game_text.setClickable(false);
|
||||
test_game_text.setClickable(true);
|
||||
new_game_text.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
test_game_text.setTextColor(0xFF333333);
|
||||
} else {
|
||||
new_game_text.setClickable(true);
|
||||
test_game_text.setClickable(false);
|
||||
new_game_text.setTextColor(0xFF333333);
|
||||
test_game_text.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
}
|
||||
if (position != 0) {
|
||||
rparams.leftMargin = (int) (width * position) + width / 4;
|
||||
slide_line.setLayoutParams(rparams);
|
||||
} else {
|
||||
rparams.leftMargin = (int) (width * position) + width / 4;
|
||||
slide_line.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
|
||||
public class ViewPagerAdapter extends FragmentPagerAdapter {
|
||||
public ViewPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (position == 0) {
|
||||
return new Game1Fragment();
|
||||
} else {
|
||||
return new Game2Fragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.actionbar_rl_back:
|
||||
finish();
|
||||
break;
|
||||
case R.id.new_game_text:
|
||||
game_viewpager.setCurrentItem(0);
|
||||
break;
|
||||
case R.id.test_game_text:
|
||||
game_viewpager.setCurrentItem(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
if (position == 0) {
|
||||
EventBus.getDefault().post(new EBUISwitch("GameActivity", 0));
|
||||
new_game_text.setClickable(false);
|
||||
test_game_text.setClickable(true);
|
||||
new_game_text.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
test_game_text.setTextColor(0xFF333333);
|
||||
} else {
|
||||
EventBus.getDefault().post(new EBUISwitch("GameActivity", 1));
|
||||
new_game_text.setClickable(true);
|
||||
test_game_text.setClickable(false);
|
||||
new_game_text.setTextColor(0xFF333333);
|
||||
test_game_text.setTextColor(getResources().getColor(
|
||||
R.color.theme_colors));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
rparams.leftMargin = (int) (width * positionOffset) + width / 4;
|
||||
slide_line.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
|
||||
super.onDestroy();
|
||||
game_viewpager = null;
|
||||
new_game_text = null;
|
||||
test_game_text = null;
|
||||
rparams = null;
|
||||
slide_line = null;
|
||||
}
|
||||
}
|
||||
212
app/src/main/java/com/gh/gamecenter/GameDetailActivity.java
Normal file
212
app/src/main/java/com/gh/gamecenter/GameDetailActivity.java
Normal file
@ -0,0 +1,212 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.DetailActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.gamedetail.GameDetailAdapter;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/8/12.
|
||||
*/
|
||||
public class GameDetailActivity extends DetailActivity implements View.OnClickListener{
|
||||
|
||||
public static final String TAG = GameDetailActivity.class.getSimpleName();
|
||||
|
||||
private GameDetailAdapter adapter;
|
||||
|
||||
private String gameId;
|
||||
|
||||
private long start;
|
||||
|
||||
private boolean isSentReport;
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
AppController.put("GameEntity", gameEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
name = "游戏详情";
|
||||
isSentReport = false;
|
||||
|
||||
gameId = getIntent().getStringExtra("gameId");
|
||||
if (gameId == null) {
|
||||
gameEntity = (GameEntity) AppController.get("GameEntity", true);
|
||||
if (gameEntity != null) {
|
||||
title = gameEntity.getName();
|
||||
actionbar_tv_title.setText(gameEntity.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);
|
||||
|
||||
if (gameEntity != null) {
|
||||
adapter.setGameEntity(gameEntity);
|
||||
adapter.getGameDetail();
|
||||
} else if (gameId != null) {
|
||||
getGameDigest();
|
||||
} else {
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
if (reuse_ll_loading.getVisibility() == View.VISIBLE) {
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
if (!TextUtils.isEmpty(adapter.getGameDetailEntity().getShareCode())) {
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
}
|
||||
downloadAddWord = adapter.getGameDetailEntity().getDownloadAddWord();
|
||||
initDownload(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
} else if (v == iv_share) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("点击", "分享");
|
||||
DataUtils.onEvent(this, "插件数据", gameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "分享");
|
||||
map.put("news", gameEntity.getName());
|
||||
map.put("page", "游戏详情");
|
||||
DataCollectionManager.onEvent(this, "click-item", map);
|
||||
|
||||
String url = "http://www.ghzhushou.com/game/" + adapter.getGameDetailEntity().getShareCode();
|
||||
showShare(url, gameEntity.getName(), gameEntity.getIcon(), null, gameEntity.getTag(), entrance, "游戏");
|
||||
}
|
||||
}
|
||||
|
||||
// 获取游戏摘要
|
||||
private void getGameDigest() {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + gameId + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
title = gameEntity.getName();
|
||||
actionbar_tv_title.setText(gameEntity.getName());
|
||||
adapter.setGameEntity(gameEntity);
|
||||
adapter.getGameDetail();
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
if (!TextUtils.isEmpty(gameId) && changed.getGameId().equals(gameId)) {
|
||||
adapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (!isSentReport) {
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
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秒";
|
||||
} else {
|
||||
cost = "大于60秒";
|
||||
}
|
||||
|
||||
if (gameEntity != null && !TextUtils.isEmpty(gameEntity.getName())) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("停留时长", cost);
|
||||
DataUtils.onEvent(this, "插件数据", gameEntity.getName(), kv);
|
||||
|
||||
if (seconds > 0) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
map.put("time", seconds);
|
||||
map.put("from", entrance);
|
||||
DataCollectionManager.onEvent(this, "game", map);
|
||||
}
|
||||
}
|
||||
|
||||
isSentReport = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
166
app/src/main/java/com/gh/gamecenter/GameNewsActivity.java
Normal file
166
app/src/main/java/com/gh/gamecenter/GameNewsActivity.java
Normal file
@ -0,0 +1,166 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
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.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
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 java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/29.
|
||||
*/
|
||||
public class GameNewsActivity extends BaseActivity implements View.OnClickListener{
|
||||
|
||||
public static final String TAG = GameNewsActivity.class.getSimpleName();
|
||||
|
||||
private GameNewsAdapter adapter;
|
||||
private GameNewsTypeListAdapter typeListAdapter;
|
||||
|
||||
private RecyclerView game_news_list;
|
||||
private RecyclerView game_news_top_type_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private ImageView ivSearch;
|
||||
|
||||
private ArrayMap<String, GameNewsAdapter> adapterMap;
|
||||
|
||||
private ArrayList<String> typeList;
|
||||
|
||||
private String gameName;
|
||||
private String gameId;
|
||||
private String entrance;
|
||||
|
||||
private float startY = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
entrance = getIntent().getStringExtra("entrance");
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_game_news, null);
|
||||
|
||||
ivSearch = new ImageView(this);
|
||||
ivSearch.setImageResource(R.drawable.search_icon);
|
||||
|
||||
RelativeLayout.LayoutParams ivSearchParams = new RelativeLayout.LayoutParams(
|
||||
DisplayUtils.dip2px(this, 20), DisplayUtils.dip2px(this, 20));
|
||||
ivSearchParams.addRule( RelativeLayout.CENTER_VERTICAL);
|
||||
ivSearchParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
ivSearchParams.setMargins(0, 0, DisplayUtils.dip2px(this, 10), 0);
|
||||
|
||||
RelativeLayout reuse_actionbar = (RelativeLayout) contentView.findViewById(R.id.reuse_actionbar);
|
||||
reuse_actionbar.addView(ivSearch, ivSearchParams);
|
||||
ivSearch.setOnClickListener(this);
|
||||
ivSearch.setVisibility(View.GONE);
|
||||
|
||||
gameName = getIntent().getStringExtra("gameName");
|
||||
init(contentView, gameName);
|
||||
|
||||
adapterMap = new ArrayMap<>();
|
||||
|
||||
typeList = getIntent().getStringArrayListExtra("articleTypes");
|
||||
typeList.add(0, "全部");
|
||||
|
||||
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) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
if (layoutManager.findFirstVisibleItemPosition() >= 1) {
|
||||
game_news_top_type_list.setVisibility(View.VISIBLE);
|
||||
ivSearch.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
game_news_top_type_list.setVisibility(View.GONE);
|
||||
ivSearch.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() == adapter.getItemCount() - 1) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading() && !adapter.isNetworkError()) {
|
||||
adapter.addList(adapter.getNewsList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
startY = event.getY();
|
||||
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
if (Math.abs(startY - event.getY()) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
adapterMap.put(change.getType(), adapter);
|
||||
}
|
||||
game_news_list.setAdapter(adapter);
|
||||
|
||||
game_news_top_type_list.setVisibility(View.GONE);
|
||||
ivSearch.setVisibility(View.GONE);
|
||||
typeListAdapter.setNewsType(change.getType(), change.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == ivSearch){
|
||||
game_news_list.scrollToPosition(0);
|
||||
game_news_top_type_list.setVisibility(View.GONE);
|
||||
ivSearch.setVisibility(View.GONE);
|
||||
adapter.openKeyBoard();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,273 +0,0 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.HotCardAdapter;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBPWDismiss;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.plugin.Plugin2Fragment;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class HotCardActivity extends BaseActivity {
|
||||
|
||||
private RecyclerView hotcard_list;
|
||||
private HotCardAdapter adapter;
|
||||
private LinearLayout hotcard_ll_loading;
|
||||
|
||||
// 黄壮华 添加 记录信息的map 修改2015/8/15
|
||||
private ArrayMap<String, Integer> locationMap;
|
||||
private ArrayMap<String, ArrayMap<String, DownloadEntry>> gameMap;
|
||||
private ArrayMap<String, LinkedBlockingQueue<String>> platformMap;
|
||||
private ArrayMap<String, String> nameMap;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
private boolean isDestroy = false;
|
||||
|
||||
private ArrayMap<String, String> statusMap;
|
||||
|
||||
private DismissEntity dismissEntity;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (!isDestroy) {
|
||||
if (msg.what == Constants.DOWNLOAD_ROLL) {
|
||||
String name = (String) msg.obj;
|
||||
if (platformMap != null) {
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(name);
|
||||
if (queue.size() > 1) {
|
||||
queue.offer(queue.poll());
|
||||
Message msg2 = Message.obtain();
|
||||
msg2.obj = name;
|
||||
msg2.what = Constants.DOWNLOAD_ROLL;
|
||||
sendMessageDelayed(msg2, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
|
||||
@Override
|
||||
public void onDataChanged(
|
||||
HashMap<String, DownloadEntry> downloadingEntries) {
|
||||
for (java.util.Map.Entry<String, DownloadEntry> entry : downloadingEntries
|
||||
.entrySet()) {
|
||||
DownloadEntry downloadEntry = entry.getValue();
|
||||
|
||||
Integer location = locationMap.get(downloadEntry.getName());
|
||||
if (location != null) {
|
||||
int index = location.intValue();
|
||||
|
||||
GameEntity detailedEntity = adapter.getList().get(index);
|
||||
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(detailedEntity,
|
||||
downloadEntry, platformMap, handler, adapter,
|
||||
index, statusMap);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_hotcard, null);
|
||||
|
||||
init(contentView, "热门卡牌");
|
||||
|
||||
dismissEntity = new DismissEntity(false);
|
||||
|
||||
statusMap = new ArrayMap<String, String>();
|
||||
locationMap = new ArrayMap<String, Integer>();
|
||||
gameMap = new ArrayMap<String, ArrayMap<String, DownloadEntry>>();
|
||||
platformMap = new ArrayMap<String, LinkedBlockingQueue<String>>();
|
||||
nameMap = new ArrayMap<String, String>();
|
||||
|
||||
hotcard_list.setHasFixedSize(true);
|
||||
hotcard_list.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(this, gameMap);
|
||||
|
||||
// 黄壮华 传递引用 修改2015/8/15
|
||||
adapter = new HotCardAdapter(this, platformMap, statusMap, dismissEntity);
|
||||
hotcard_list.setAdapter(adapter);
|
||||
hotcard_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
|
||||
addList();
|
||||
|
||||
}
|
||||
|
||||
private void addList() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/game/remenkapai", Constants.GAME_CD),
|
||||
new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
processingData(response);
|
||||
}
|
||||
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接
|
||||
if (error.getClass().equals(NoConnectionError.class)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
AppController.addToRequestQueue(request, Plugin2Fragment.class);
|
||||
}
|
||||
|
||||
private void processingData(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<GameEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
GameManager manager = new GameManager(getApplicationContext());
|
||||
List<GameEntity> gameList = gson
|
||||
.fromJson(response.toString(), listType);
|
||||
if (gameList != null && !gameList.isEmpty()) {
|
||||
for (GameEntity entity : gameList) {
|
||||
// 黄壮华 初始化游戏状态 修改2015/8/15
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
manager.addOrUpdate(new GameInfo(apkEntity.getPackageName(),
|
||||
entity.getId(), entity.getName()));
|
||||
}
|
||||
}
|
||||
adapter.getList().addAll(gameList);
|
||||
adapter.notifyItemRangeInserted(adapter.getList().size() - gameList.size(), gameList.size());
|
||||
}
|
||||
|
||||
// 黄壮华 获取游戏位置信息 修改2015/8/15
|
||||
for (int i = 0, size = adapter.getList().size(); i < size; i++) {
|
||||
GameEntity entity = adapter.getList().get(i);
|
||||
locationMap.put(entity.getName(), i);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
nameMap.put(apkEntity.getPackageName(), entity.getName());
|
||||
}
|
||||
}
|
||||
|
||||
hotcard_list.setVisibility(View.VISIBLE);
|
||||
hotcard_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPWDismiss dismiss) {
|
||||
if (dismissEntity != null) {
|
||||
dismissEntity.setShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = nameMap.get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
int location = locationMap.get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity entity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
entity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
// 黄壮华 添加 初始化游戏状态 修改2015/8/21
|
||||
DownloadItemUtils.initializeGameMap(this, gameMap);
|
||||
List<GameEntity> entities = new ArrayList<GameEntity>();
|
||||
for (GameEntity entity : adapter.getList()) {
|
||||
entity.setEntryMap(gameMap.get(entity.getName()));
|
||||
entities.add(entity);
|
||||
}
|
||||
adapter.setList(entities);
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(getApplicationContext()).addObserver(
|
||||
dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
statusMap.clear();
|
||||
DownloadManager.getInstance(getApplicationContext()).removeObserver(
|
||||
dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(Plugin2Fragment.class);
|
||||
hotcard_list = null;
|
||||
adapter = null;
|
||||
hotcard_ll_loading = null;
|
||||
locationMap = null;
|
||||
gameMap = null;
|
||||
platformMap = null;
|
||||
nameMap = null;
|
||||
statusMap = null;
|
||||
dismissEntity = null;
|
||||
handler = null;
|
||||
dataWatcher = null;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
415
app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java
Normal file
415
app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java
Normal file
@ -0,0 +1,415 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.NoConnectionError;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.DetailActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.newsdetail.NewsDetailAdapter;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文章详情页面 要启动该页面 需要传入一下参数 放入 EssayEntity中传过来 文章 id 文章标题 title 文章发表时间 time
|
||||
*
|
||||
* @author 黄壮华
|
||||
*/
|
||||
public class NewsDetailActivity extends DetailActivity implements OnClickListener {
|
||||
|
||||
public static final String TAG = NewsDetailActivity.class.getSimpleName();
|
||||
|
||||
private NewsDetailAdapter adapter;
|
||||
|
||||
private String newsId;
|
||||
|
||||
private long start = 0L;
|
||||
|
||||
private boolean isSentReport = false;
|
||||
|
||||
private float Y11, Y12, Y21, Y22;
|
||||
private float X11, X12, X21, X22;
|
||||
private boolean isSecondDown = false;
|
||||
private double R11;
|
||||
private int scrollSize = 300;//滑动距离超过300触发事件(放大缩小字体)
|
||||
private SharedPreferences sp;
|
||||
private int fontsize;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
name = "新闻详情";
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
|
||||
detail_rv_show.setHasFixedSize(true);
|
||||
detail_rv_show.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new NewsDetailAdapter(this, entrance);
|
||||
detail_rv_show.setAdapter(adapter);
|
||||
|
||||
newsId = getIntent().getStringExtra("newsId");
|
||||
if (newsId == null) {
|
||||
String id = getIntent().getStringExtra("id");
|
||||
String type = getIntent().getStringExtra("type");
|
||||
String title = getIntent().getStringExtra("title");
|
||||
if (type != null) {
|
||||
actionbar_tv_title.setText(type);
|
||||
}
|
||||
this.title = title;
|
||||
adapter.setId(id);
|
||||
adapter.setType(type);
|
||||
adapter.setTitle(title);
|
||||
adapter.getNewsDetail();
|
||||
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
getNewsDigest(newsId);
|
||||
}
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
View view = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
|
||||
if (view != null) {
|
||||
view.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
|
||||
mHits[mHits.length - 1] = SystemClock.uptimeMillis();
|
||||
if (mHits[0] >= (SystemClock.uptimeMillis() - 1000)) {
|
||||
detail_rv_show.scrollToPosition(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Activity.MODE_PRIVATE);
|
||||
fontsize = sp.getInt("fontsize", 1);
|
||||
if (fontsize == 0) {
|
||||
fontsize = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadDone(Object obj) {
|
||||
if (reuse_ll_loading != null) {
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
detail_rv_show.setVisibility(View.VISIBLE);
|
||||
}
|
||||
getGameDetail((String) obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
detail_rv_show.setVisibility(View.GONE);
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
detail_ll_bottom.setVisibility(View.GONE);
|
||||
detail_rv_show.setPadding(0, 0, 0, 0);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private String getFontSize(int i) {
|
||||
switch (i){
|
||||
case 1:
|
||||
return "小字号";
|
||||
case 2:
|
||||
return "中字号";
|
||||
case 3:
|
||||
return "大字号";
|
||||
case 4:
|
||||
return "特大字号";
|
||||
default:
|
||||
return "未知字号";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加手势监听,控制字体大小
|
||||
*
|
||||
* @author 柯皓源
|
||||
*/
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
switch (ev.getAction() & MotionEventCompat.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
isSecondDown = false;
|
||||
int pointerIndex = MotionEventCompat.findPointerIndex(ev, MotionEventCompat.getPointerId(ev, 0));
|
||||
Y11 = MotionEventCompat.getY(ev, pointerIndex);
|
||||
X11 = MotionEventCompat.getX(ev, pointerIndex);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
final int actionUpIndex = MotionEventCompat.getActionIndex(ev);
|
||||
int pointerIndex2 = MotionEventCompat.findPointerIndex(ev, MotionEventCompat.getPointerId(ev, actionUpIndex));
|
||||
Y12 = MotionEventCompat.getY(ev, pointerIndex2);
|
||||
X12 = MotionEventCompat.getX(ev, pointerIndex2);
|
||||
float X2 = Math.abs(X12 - X22);
|
||||
float Y2 = Math.abs(Y12 - Y22);
|
||||
float R2 = (X2 * X2) + (Y2 * Y2);
|
||||
double R12 = Math.sqrt(R2);
|
||||
if (isSecondDown) {
|
||||
if ((R11 - R12) > scrollSize && fontsize > 1) {
|
||||
fontsize--;
|
||||
adapter.setFontSize(fontsize);
|
||||
sp.edit().putInt("fontsize", fontsize).apply();
|
||||
String fontSizeText = getFontSize(fontsize);
|
||||
Toast.makeText(this, fontSizeText, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
if ((R11 - R12) < -scrollSize && fontsize < 4) {
|
||||
fontsize ++;
|
||||
adapter.setFontSize(fontsize);
|
||||
sp.edit().putInt("fontsize", fontsize).apply();
|
||||
String fontSizeText = getFontSize(fontsize);
|
||||
Toast.makeText(this, fontSizeText, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (isSecondDown) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case MotionEventCompat.ACTION_POINTER_DOWN:
|
||||
isSecondDown = true;
|
||||
final int pointerIndexDown = MotionEventCompat.getActionIndex(ev);
|
||||
int pointerIndex1 = MotionEventCompat.findPointerIndex(ev, MotionEventCompat.getPointerId(ev, pointerIndexDown));
|
||||
Y21 = MotionEventCompat.getY(ev, pointerIndex1);
|
||||
X21 = MotionEventCompat.getX(ev, pointerIndex1);
|
||||
float X1 = Math.abs(X11 - X21);
|
||||
float Y1 = Math.abs(Y11 - Y21);
|
||||
float R1 = (X1 * X1) + (Y1 * Y1);
|
||||
R11 = Math.sqrt(R1);
|
||||
break;
|
||||
case MotionEventCompat.ACTION_POINTER_UP:
|
||||
final int pointerIndexUp = MotionEventCompat.getActionIndex(ev);
|
||||
int pointerIndex21 = MotionEventCompat.findPointerIndex(ev, MotionEventCompat.getPointerId(ev, pointerIndexUp));
|
||||
Y22 = MotionEventCompat.getY(ev, pointerIndex21);
|
||||
X22 = MotionEventCompat.getX(ev, pointerIndex21);
|
||||
break;
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
private void getNewsDigest(final String news_id) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/news/" + news_id + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
NewsEntity newsEntity = gson.fromJson(response.toString(), NewsEntity.class);
|
||||
if (newsEntity.getType() != null) {
|
||||
actionbar_tv_title.setText(newsEntity.getType());
|
||||
}
|
||||
|
||||
adapter.setId(news_id);
|
||||
adapter.setType(newsEntity.getType());
|
||||
adapter.setTitle(newsEntity.getTitle());
|
||||
adapter.getNewsDetail();
|
||||
|
||||
title = newsEntity.getTitle();
|
||||
|
||||
iv_share.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
// 无网络连接和访问超时
|
||||
if (error.getClass().equals(NoConnectionError.class)
|
||||
|| error.getClass().equals(TimeoutError.class)) {
|
||||
detail_rv_show.setVisibility(View.GONE);
|
||||
reuse_ll_loading.setVisibility(View.GONE);
|
||||
detail_ll_bottom.setVisibility(View.GONE);
|
||||
detail_rv_show.setPadding(0, 0, 0, 0);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
private long[] mHits = new long[2];
|
||||
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
super.onClick(v);
|
||||
if (v == iv_share) {
|
||||
if (adapter != null) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("名字", adapter.getNewsDetailEntity().getTitle());
|
||||
kv.put("位置", "分享");
|
||||
DataUtils.onEvent(this, "点击", "新闻详情", kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "分享");
|
||||
map.put("news", adapter.getNewsDetailEntity().getTitle());
|
||||
map.put("page", "新闻详情");
|
||||
DataCollectionManager.onEvent(this, "click-item", map);
|
||||
|
||||
String url = "http://www.ghzhushou.com/article/" +
|
||||
adapter.getNewsDetailEntity().getId() + ".html";
|
||||
if (gameEntity == null){
|
||||
showShare(url, adapter.getNewsDetailEntity().getTitle(),
|
||||
"http://image.ghzhushou.com/pic/57d604808ab49e467d8b4568.png",
|
||||
adapter.getNewsDetailEntity().getTitle(), null, entrance, "新闻");
|
||||
}else {
|
||||
showShare(url, gameEntity.getName(), gameEntity.getIcon(),
|
||||
adapter.getNewsDetailEntity().getTitle(), gameEntity.getTag(),
|
||||
entrance, "新闻");
|
||||
}
|
||||
}
|
||||
} else if (v == reuse_no_connection) {
|
||||
detail_rv_show.setVisibility(View.VISIBLE);
|
||||
reuse_ll_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (newsId != null) {
|
||||
getNewsDigest(newsId);
|
||||
} else {
|
||||
String id = getIntent().getStringExtra("id");
|
||||
String type = getIntent().getStringExtra("type");
|
||||
String title = getIntent().getStringExtra("title");
|
||||
if (type != null) {
|
||||
actionbar_tv_title.setText(type);
|
||||
}
|
||||
adapter.setId(id);
|
||||
adapter.setType(type);
|
||||
adapter.setTitle(title);
|
||||
adapter.getNewsDetail();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void getGameDetail(String gameId) {
|
||||
if (TextUtils.isEmpty(gameId)) {
|
||||
detail_ll_bottom.setVisibility(View.GONE);
|
||||
detail_rv_show.setPadding(0, 0, 0, 0);
|
||||
return;
|
||||
}
|
||||
JsonObjectExtendedRequest gameRequest = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + gameId + "/news_digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
adapter.setGameEntity(gameEntity); //出现空指针 找不到原因
|
||||
adapter.notifyItemInserted(1);
|
||||
downloadAddWord = gameEntity.getDownloadAddWord();
|
||||
initDownload(true);
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(gameRequest, TAG);
|
||||
}
|
||||
|
||||
// 关注事件
|
||||
public void onEventMainThread(EBConcernChanged changed) {
|
||||
if (gameEntity != null && changed.getGameId().equals(gameEntity.getId())) {
|
||||
adapter.notifyItemChanged(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
detail_rv_show.setVisibility(View.VISIBLE);
|
||||
reuse_ll_loading.setVisibility(View.VISIBLE);
|
||||
detail_ll_bottom.setVisibility(View.VISIBLE);
|
||||
detail_rv_show.setPadding(0, 0, 0, DisplayUtils.dip2px(getApplicationContext(), 44));
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (!isSentReport) {
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
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秒";
|
||||
} else {
|
||||
cost = "大于60秒";
|
||||
}
|
||||
|
||||
if (adapter.getNewsDetailEntity() != null) {
|
||||
// 阅读报告
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("用时", cost);
|
||||
DataUtils.onEvent(NewsDetailActivity.this, "阅读文章", adapter.getNewsDetailEntity().getTitle(), kv);
|
||||
|
||||
// 阅读报告
|
||||
Map<String, Object> kv1 = new HashMap<>();
|
||||
kv1.put(entrance, "阅读数");
|
||||
kv1.put(entrance, "用时:" + cost);
|
||||
DataUtils.onEvent(NewsDetailActivity.this, "文章数据", adapter.getNewsDetailEntity().getTitle(), kv1);
|
||||
|
||||
if (seconds > 0) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("title", adapter.getNewsDetailEntity().getTitle());
|
||||
map.put("type", adapter.getNewsDetailEntity().getType());
|
||||
map.put("author", adapter.getNewsDetailEntity().getAuthor());
|
||||
if (gameEntity != null) {
|
||||
map.put("game", gameEntity.getName());
|
||||
map.put("game_id", gameEntity.getId());
|
||||
}
|
||||
map.put("time", seconds);
|
||||
map.put("from", entrance);
|
||||
DataCollectionManager.onEvent(this, "news", map);
|
||||
}
|
||||
}
|
||||
|
||||
isSentReport = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,186 +0,0 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.view.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.NewsOrRaidersListAdapter;
|
||||
import com.gh.gamecenter.eventbus.EBConcernChanged;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
|
||||
/**
|
||||
* @author 温冠超
|
||||
* @email 294299195@qq.com
|
||||
* @date 2015-8-10 首页资讯或攻略板块
|
||||
*/
|
||||
public class NewsOrRaidersActivity extends BaseActivity {
|
||||
|
||||
private RecyclerView news_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private NewsOrRaidersListAdapter adapter;
|
||||
private LinearLayout news_ll_loading, reuse_no_connection;
|
||||
private TextView news_tv_label;
|
||||
private RelativeLayout news_rl_label;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
private String type;
|
||||
|
||||
private boolean isDestroy;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
type = getIntent().getStringExtra("type");
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
View contentView = View.inflate(this,
|
||||
R.layout.activity_news_or_raiders, null);
|
||||
|
||||
init(contentView, type);
|
||||
|
||||
reuse_no_connection.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_ll_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new NewsOrRaidersListAdapter(
|
||||
NewsOrRaidersActivity.this, news_list, news_ll_loading,
|
||||
reuse_no_connection, type, news_rl_label, news_tv_label);
|
||||
news_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
rparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.WRAP_CONTENT);
|
||||
|
||||
news_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
news_list.setLayoutManager(layoutManager);
|
||||
|
||||
adapter = new NewsOrRaidersListAdapter(this, news_list,
|
||||
news_ll_loading, reuse_no_connection, type, news_rl_label,
|
||||
news_tv_label);
|
||||
|
||||
news_list.setAdapter(adapter);
|
||||
news_list.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
v.performClick();
|
||||
}
|
||||
if (news_ll_loading.getVisibility() == View.VISIBLE) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
news_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
int position = layoutManager.findFirstVisibleItemPosition();
|
||||
|
||||
if (adapter.getPosition_today() != -1
|
||||
&& position >= adapter.getPosition_today()
|
||||
&& position <= adapter.getTodaySize()
|
||||
+ adapter.getPosition_today()) {
|
||||
news_tv_label.setText("今天");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_red);
|
||||
} else if (adapter.getPosition_before() != -1
|
||||
&& position >= adapter.getPosition_before()) {
|
||||
news_tv_label.setText("昨天/以前");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_gray);
|
||||
} else if (adapter.getPosition_mygame() != -1) {
|
||||
news_tv_label.setText("我的游戏");
|
||||
news_tv_label.setBackgroundResource(R.drawable.title_blue);
|
||||
}
|
||||
|
||||
if (position == adapter.getPosition_today() - 1
|
||||
|| position == adapter.getPosition_before() - 1) {
|
||||
int buttom = layoutManager.findViewByPosition(position)
|
||||
.getBottom();
|
||||
if (buttom <= news_rl_label.getHeight()) {
|
||||
rparams.topMargin = buttom - news_rl_label.getHeight();
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
}
|
||||
} else {
|
||||
rparams.topMargin = 0;
|
||||
news_rl_label.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView,
|
||||
int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (!isDestroy && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() + 1 == adapter.getItemCount()) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading() && !adapter.isNetworkError()) {
|
||||
adapter.addList();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
news_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBConcernChanged busSeven) {
|
||||
adapter.updateMyGameNews();
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
news_list.setVisibility(View.GONE);
|
||||
news_ll_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new NewsOrRaidersListAdapter(this, news_list,
|
||||
news_ll_loading, reuse_no_connection, type,
|
||||
news_rl_label, news_tv_label);
|
||||
news_list.setAdapter(adapter);
|
||||
} else if (adapter.isNetworkError()) {
|
||||
adapter.setNetworkError(false);
|
||||
adapter.notifyItemChanged(adapter.getItemCount());
|
||||
adapter.addList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
AppController.canclePendingRequests(NewsOrRaidersActivity.class);
|
||||
news_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
news_ll_loading = null;
|
||||
reuse_no_connection = null;
|
||||
news_tv_label = null;
|
||||
news_rl_label = null;
|
||||
rparams = null;
|
||||
type = null;
|
||||
}
|
||||
|
||||
}
|
||||
359
app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java
Normal file
359
app/src/main/java/com/gh/gamecenter/NewsSearchActivity.java
Normal file
@ -0,0 +1,359 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
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.VerticalItemDecoration;
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.entity.NewsEntity;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/8/22.
|
||||
*/
|
||||
public class NewsSearchActivity extends BaseActivity {
|
||||
|
||||
public static final String TAG = NewsSearchActivity.class.getSimpleName();
|
||||
|
||||
private RecyclerView gamedetail_news_rv;
|
||||
private List<NewsEntity> newsEntities;
|
||||
private NewsSearchAdapter searchAdapter;
|
||||
private TextView tv_search;
|
||||
private LinearLayout reuse_none_data;
|
||||
private EditText et_search;
|
||||
private LinearLayout gamedetail_news_ll_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private CardView gamedetail_news_cardView;
|
||||
|
||||
private MeasureHeightLayoutManager layoutManager;
|
||||
|
||||
private boolean isLoadOver = true;
|
||||
private boolean isRemove = false;
|
||||
private boolean isNetworkError = false;
|
||||
|
||||
private String gameName;
|
||||
private String searchKey;
|
||||
private String gameId;
|
||||
private String entrance;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
private int page = 1;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getIntent();
|
||||
gameName = intent.getExtras().getString("gameName");
|
||||
searchKey = intent.getExtras().getString("searchKey");
|
||||
gameId = intent.getExtras().getString("gameId");
|
||||
entrance = intent.getExtras().getString("entrance");
|
||||
|
||||
View view = View.inflate(this, R.layout.activity_gamedetail_news, null);
|
||||
init(view, gameName);
|
||||
|
||||
newsEntities = new ArrayList<>();
|
||||
searchAdapter = new NewsSearchAdapter();
|
||||
|
||||
findViewById(R.id.gamedetail_news_type_ll).setVisibility(View.GONE);
|
||||
findViewById(R.id.ll_search).setVisibility(View.VISIBLE);
|
||||
|
||||
layoutManager = new MeasureHeightLayoutManager(this);
|
||||
|
||||
gamedetail_news_rv.setLayoutManager(layoutManager);
|
||||
gamedetail_news_rv.setAdapter(searchAdapter);
|
||||
gamedetail_news_rv.addItemDecoration(new VerticalItemDecoration(NewsSearchActivity.this, 1));
|
||||
|
||||
et_search.setText(searchKey);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadNewsData(page);
|
||||
}
|
||||
}).start();
|
||||
|
||||
tv_search.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
searchKey = et_search.getText().toString().trim();
|
||||
if (searchKey.length() >= 1) {
|
||||
newsEntities.clear();
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
page = 1;
|
||||
loadNewsData(page);
|
||||
}
|
||||
},1000);
|
||||
|
||||
}else {
|
||||
Toast.makeText(NewsSearchActivity.this,"请输入关键字",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
gamedetail_news_rv.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE &&layoutManager.findLastVisibleItemPosition() + 1 == searchAdapter.getItemCount()
|
||||
&&isLoadOver&&!isRemove&& !isNetworkError){
|
||||
isLoadOver = false;
|
||||
page++;
|
||||
loadNewsData(page);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
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() {
|
||||
loadNewsData(1);
|
||||
}
|
||||
},1000);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void loadNewsData(final int page) {
|
||||
DataUtils.onEvent(this, "游戏新闻搜索", searchKey);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("key", searchKey);
|
||||
map.put("from", "游戏新闻搜索");
|
||||
DataCollectionManager.onEvent(this, "search", map);
|
||||
|
||||
String url = Config.HOST + "v1d45/search/news?game_id=" + gameId
|
||||
+ "&keyword=" + Uri.encode(searchKey) + "&page="+ page + "&limit=20";
|
||||
final JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(url,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
Type listType = new TypeToken<ArrayList<NewsEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
ArrayList<NewsEntity> newsList = gson.fromJson(response.toString(), listType);
|
||||
|
||||
int listSize = newsList.size();
|
||||
|
||||
// 去除重复数据
|
||||
removeDuplicateData(newsList);
|
||||
|
||||
if (!newsList.isEmpty()) {
|
||||
newsEntities.addAll(newsList);
|
||||
searchAdapter.notifyDataSetChanged();
|
||||
}
|
||||
isLoadOver = true;
|
||||
gamedetail_news_ll_loading.setVisibility(View.GONE);
|
||||
gamedetail_news_cardView.setVisibility(View.VISIBLE);
|
||||
if (newsEntities.isEmpty()) {
|
||||
gamedetail_news_cardView.setVisibility(View.GONE);
|
||||
reuse_none_data.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
gamedetail_news_cardView.setVisibility(View.VISIBLE);
|
||||
reuse_none_data.setVisibility(View.GONE);
|
||||
}
|
||||
if (listSize == 0 || (page == 1 && listSize < 20)) {
|
||||
isRemove = true;
|
||||
searchAdapter.notifyItemChanged(searchAdapter.getItemCount() - 1);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
if (page ==1){
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
gamedetail_news_ll_loading.setVisibility(View.GONE);
|
||||
}
|
||||
isLoadOver = true;
|
||||
toast("加载失败,请检查网络状态");
|
||||
isNetworkError = true;
|
||||
searchAdapter.notifyItemChanged(searchAdapter.getItemCount() - 1);
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
private void removeDuplicateData(ArrayList<NewsEntity> newsList) {
|
||||
if (newsEntities == null || newsEntities.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String id;
|
||||
for (int i = 0; i < newsList.size(); i++) {
|
||||
id = newsList.get(i).getId();
|
||||
for (NewsEntity newsEntity : newsEntities) {
|
||||
if (id.equals(newsEntity.getId())) {
|
||||
newsList.remove(i);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
|
||||
public class NewsSearchAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == newsEntities.size()) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == 0){
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@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() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
NewsEntity newsEntity = newsEntities.get(holder.getPosition());
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("名字", newsEntity.getTitle());
|
||||
kv.put("位置", String.valueOf(holder.getPosition() + 1));
|
||||
DataUtils.onEvent(NewsSearchActivity.this, "点击", "游戏新闻搜索", kv);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("location", "列表");
|
||||
map.put("page", "游戏新闻搜索");
|
||||
map.put("news", newsEntity.getTitle());
|
||||
map.put("news_id", newsEntity.getId());
|
||||
DataCollectionManager.onEvent(NewsSearchActivity.this, "click-item", map);
|
||||
|
||||
// 统计阅读量
|
||||
NewsUtils.statNewsViews(newsEntity.getId());
|
||||
NewsUtils.startNewsActivity(NewsSearchActivity.this, newsEntity, entrance + "+(游戏新闻搜索)");
|
||||
}
|
||||
});
|
||||
}else if (holder instanceof FooterViewHolder){
|
||||
FooterViewHolder viewHolder = (FooterViewHolder) holder;
|
||||
viewHolder.itemView.setPadding(0, 0, 0, 0);
|
||||
if (isNetworkError) {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载失败,点击重试");
|
||||
viewHolder.itemView.setClickable(true);
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
isNetworkError = false;
|
||||
notifyItemChanged(getItemCount() - 1);
|
||||
loadNewsData(page);
|
||||
}
|
||||
});
|
||||
} else if (isRemove) {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.GONE);
|
||||
viewHolder.footerview_tv_loading.setText("加载完毕");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
} else {
|
||||
viewHolder.footerview_progressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.footerview_tv_loading.setText("加载中...");
|
||||
viewHolder.itemView.setClickable(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (newsEntities.isEmpty()){
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,103 +0,0 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
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.OriginalAdapter;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/6/12.
|
||||
*/
|
||||
public class OriginalActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private SwipeRefreshLayout original_swipe_refresh;
|
||||
private RecyclerView original_list;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private OriginalAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate original_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private boolean isDestroy;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_original, null);
|
||||
|
||||
init(contentView, "原创");
|
||||
|
||||
isDestroy = false;
|
||||
|
||||
original_swipe_refresh.setColorSchemeResources(R.color.theme_colors);
|
||||
original_swipe_refresh.setOnRefreshListener(this);
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
original_swipe_refresh.setRefreshing(true);
|
||||
original_list.setVisibility(View.VISIBLE);
|
||||
original_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
original_list.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
original_list.setLayoutManager(layoutManager);
|
||||
adapter = new OriginalAdapter(this, original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
original_list.setAdapter(adapter);
|
||||
original_list.addItemDecoration(new VerticalItemDecoration(this, 1));
|
||||
original_list.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
|
||||
if (!isDestroy && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
&& layoutManager.findLastVisibleItemPosition() + 1 == adapter.getItemCount()) {
|
||||
if (!adapter.isRemove() && !adapter.isLoading() && !adapter.isNetworkError()) {
|
||||
adapter.addList(adapter.getNewsList().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapter = new OriginalAdapter(OriginalActivity.this, original_list, original_swipe_refresh,
|
||||
original_pb_loading, reuse_no_connection, true);
|
||||
original_list.setAdapter(adapter);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
isDestroy = true;
|
||||
original_swipe_refresh = null;
|
||||
original_list = null;
|
||||
layoutManager = null;
|
||||
adapter = null;
|
||||
original_pb_loading = null;
|
||||
reuse_no_connection = null;
|
||||
handler = null;
|
||||
}
|
||||
}
|
||||
173
app/src/main/java/com/gh/gamecenter/PluginActivity.java
Normal file
173
app/src/main/java/com/gh/gamecenter/PluginActivity.java
Normal file
@ -0,0 +1,173 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
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 com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.adapter.PluginAdapter;
|
||||
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 java.util.List;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/7/6.
|
||||
*/
|
||||
public class PluginActivity extends BaseActivity {
|
||||
|
||||
public static final String TAG = PluginActivity.class.getSimpleName();
|
||||
|
||||
private RecyclerView plugin_list;
|
||||
private PluginAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate plugin_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
|
||||
private String entrance;
|
||||
|
||||
private boolean isEverpause = false;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
//特殊 插件化update
|
||||
if (downloadEntity.isPluggable()) {
|
||||
Integer location = adapter.getLocationMap().get(
|
||||
downloadEntity.getName() + " - " + downloadEntity.getPlatform());
|
||||
if (location != null) {
|
||||
GameEntity detailedEntity = adapter.getPluginList().get(location);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(PluginActivity.this, detailedEntity,
|
||||
downloadEntity, adapter, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
entrance = getIntent().getStringExtra("entrance");
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_plugin, null);
|
||||
|
||||
init(contentView, "可以插件化的游戏");
|
||||
|
||||
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
plugin_pb_loading.setVisibility(View.VISIBLE);
|
||||
plugin_list.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new PluginAdapter(PluginActivity.this, entrance);
|
||||
plugin_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
plugin_list.setHasFixedSize(true);
|
||||
plugin_list.setLayoutManager(new LinearLayoutManager(this));
|
||||
adapter = new PluginAdapter(this, entrance);
|
||||
plugin_list.setAdapter(adapter);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
if (plugin_pb_loading != null && plugin_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
plugin_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
// 下载被删除事件
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(this).removePlatform(status.getName(), status.getPlatform());
|
||||
Integer location = adapter.getLocationMap().get(status.getName() + " - " + status.getPlatform());
|
||||
if (location != null) {
|
||||
GameEntity gameEntity = adapter.getPluginList().get(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
if (TextUtils.isEmpty(status.getPlatform())) {
|
||||
gameEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
plugin_list.setVisibility(View.VISIBLE);
|
||||
plugin_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new PluginAdapter(this, entrance);
|
||||
plugin_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//安装、卸载事件
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
//特殊 插件化
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
Integer location = adapter.getLocationMap().get(name);
|
||||
if (location != null) {
|
||||
if ("安装".equals(busFour.getType()) || "卸载".equals(busFour.getType())) {
|
||||
List<GameEntity> list = adapter.getPluginList();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
if (list.get(i).getApk().get(0).getPackageName()
|
||||
.equals(busFour.getPackageName())) {
|
||||
list.remove(i);
|
||||
adapter.notifyItemRemoved(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
isEverpause = true;
|
||||
DownloadManager.getInstance(this).removeObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
for (GameEntity entity : adapter.getPluginList()) {
|
||||
entity.setEntryMap(DownloadManager.getInstance(this).getEntryMap(entity.getName()));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
isEverpause = false;
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,8 @@ import android.app.ActionBar.LayoutParams;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.text.Editable;
|
||||
@ -30,9 +32,9 @@ import com.gh.gamecenter.eventbus.EBSearch;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager;
|
||||
import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig;
|
||||
import com.gh.gamecenter.search.Search1DetailFragment;
|
||||
import com.gh.gamecenter.search.Search2GameListFragment;
|
||||
import com.gh.gamecenter.search.Search3HistoryFragment;
|
||||
import com.gh.gamecenter.search.SearchGameDetailFragment;
|
||||
import com.gh.gamecenter.search.SearchGameListFragment;
|
||||
import com.gh.gamecenter.search.SearchHistoryFragment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -41,9 +43,9 @@ import java.util.Map;
|
||||
|
||||
public class SearchActivity extends BaseFragmentActivity {
|
||||
|
||||
private Search1DetailFragment game_detail_fragment;
|
||||
private Search2GameListFragment game_list_fragment;
|
||||
private Search3HistoryFragment search_history_fragment;
|
||||
private SearchGameDetailFragment game_detail_fragment;
|
||||
private SearchGameListFragment game_list_fragment;
|
||||
private SearchHistoryFragment search_history_fragment;
|
||||
|
||||
private RelativeLayout searchBack;
|
||||
private EditText searchInput;
|
||||
@ -51,11 +53,23 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
private TextView searchButton;
|
||||
|
||||
private SearchHistoryDao dao;
|
||||
private TextWatcher mTextWatcher;
|
||||
|
||||
private String searchKey;
|
||||
|
||||
private int currentTab;
|
||||
|
||||
private boolean isSearchDetail;
|
||||
|
||||
private Handler handler = new Handler(){
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.what == 1){
|
||||
setResultPresentModel(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@ -73,7 +87,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
setTranslucentStatus(true);
|
||||
SystemBarTintManager tintManager = new SystemBarTintManager(this);
|
||||
tintManager.setStatusBarTintEnabled(true);
|
||||
tintManager.setStatusBarTintResource(R.color.search_theme_colors);
|
||||
tintManager.setStatusBarTintResource(R.color.theme);
|
||||
SystemBarConfig config = tintManager.getConfig();
|
||||
contentView.setPadding(0, config.getPixelInsetTop(false), 0,
|
||||
config.getPixelInsetBottom());
|
||||
@ -93,6 +107,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
if (TextUtils.isEmpty(searchKey)) {
|
||||
currentTab = 0;
|
||||
} else {
|
||||
isSearchDetail = true;
|
||||
searchInput.setText(searchKey);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
}
|
||||
@ -105,8 +120,6 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
}
|
||||
|
||||
setResultPresentModel(currentTab);
|
||||
|
||||
searchInput.addTextChangedListener(mTextWatcher);
|
||||
}
|
||||
|
||||
public void setActionBarLayout(final String hint, final boolean isFromHome) {
|
||||
@ -122,8 +135,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
searchInput = (EditText) findViewById(R.id.etSearch);
|
||||
searchInput.setOnEditorActionListener(new OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId,
|
||||
KeyEvent event) {
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
@ -131,6 +143,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
if (newSearchKey.length() < 1) {
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
newSearchKey = searchInput.getHint().toString();
|
||||
isSearchDetail = true;
|
||||
searchInput.setText(hint);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
}
|
||||
@ -153,6 +166,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
searchBack = (RelativeLayout) findViewById(R.id.btnGoBack);
|
||||
|
||||
if (isFromHome && !TextUtils.isEmpty(hint)) {
|
||||
isSearchDetail = true;
|
||||
searchInput.setText(hint);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
} else if (!TextUtils.isEmpty(hint)) {
|
||||
@ -170,6 +184,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
if (newSearchKey.length() < 1) {
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
newSearchKey = searchInput.getHint().toString();
|
||||
isSearchDetail = true;
|
||||
searchInput.setText(hint);
|
||||
searchInput.setSelection(searchInput.getText().length());
|
||||
}
|
||||
@ -179,6 +194,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
if (!TextUtils.isEmpty(searchKey)) {
|
||||
setResultPresentModel(2);
|
||||
dao.add(searchKey);
|
||||
isSearchDetail = false;
|
||||
} else {
|
||||
toast("请输入搜索内容");
|
||||
}
|
||||
@ -195,7 +211,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
|
||||
});
|
||||
|
||||
mTextWatcher = new TextWatcher() {
|
||||
searchInput.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
@ -214,15 +230,16 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
public void afterTextChanged(Editable s) {
|
||||
String newSearchKey = s.toString().trim();
|
||||
if (!newSearchKey.equals(searchKey)) {
|
||||
handler.removeMessages(1);
|
||||
searchKey = newSearchKey;
|
||||
if (searchKey.length() < 1) {
|
||||
setResultPresentModel(0);
|
||||
} else {
|
||||
setResultPresentModel(1);
|
||||
} else if (!isSearchDetail){
|
||||
handler.sendEmptyMessageDelayed(1, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
searchBack.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
@ -242,7 +259,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
if (fragment.getClass().equals(Search3HistoryFragment.class)) {
|
||||
if (fragment.getClass().equals(SearchHistoryFragment.class)) {
|
||||
transaction.remove(fragment);
|
||||
break;
|
||||
}
|
||||
@ -251,7 +268,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
} else {
|
||||
transaction.remove(search_history_fragment);
|
||||
}
|
||||
search_history_fragment = new Search3HistoryFragment();
|
||||
search_history_fragment = new SearchHistoryFragment();
|
||||
transaction.add(R.id.search_result, search_history_fragment);
|
||||
currentTab = 0;
|
||||
break;
|
||||
@ -260,7 +277,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
if (fragment.getClass().equals(Search2GameListFragment.class)) {
|
||||
if (fragment.getClass().equals(SearchGameListFragment.class)) {
|
||||
transaction.remove(fragment);
|
||||
break;
|
||||
}
|
||||
@ -269,7 +286,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
} else {
|
||||
transaction.remove(game_list_fragment);
|
||||
}
|
||||
game_list_fragment = new Search2GameListFragment();
|
||||
game_list_fragment = new SearchGameListFragment();
|
||||
game_list_fragment.setKey(searchKey);
|
||||
transaction.add(R.id.search_result, game_list_fragment);
|
||||
currentTab = 1;
|
||||
@ -277,17 +294,16 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
case 2:
|
||||
DataUtils.onEvent(SearchActivity.this, "搜索页面", searchKey);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("key", searchKey);
|
||||
map.put("from", "搜索页面");
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(this, "search", map);
|
||||
|
||||
if (game_detail_fragment == null) {
|
||||
List<Fragment> list = getSupportFragmentManager().getFragments();
|
||||
if (list != null) {
|
||||
for (Fragment fragment : list) {
|
||||
if (fragment.getClass().equals(Search1DetailFragment.class)) {
|
||||
if (fragment.getClass().equals(SearchGameDetailFragment.class)) {
|
||||
transaction.remove(fragment);
|
||||
break;
|
||||
}
|
||||
@ -296,7 +312,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
} else {
|
||||
transaction.remove(game_detail_fragment);
|
||||
}
|
||||
game_detail_fragment = new Search1DetailFragment();
|
||||
game_detail_fragment = new SearchGameDetailFragment();
|
||||
game_detail_fragment.setKey(searchKey);
|
||||
transaction.add(R.id.search_result, game_detail_fragment);
|
||||
currentTab = 2;
|
||||
@ -326,6 +342,7 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
}
|
||||
|
||||
public void onEvent(EBSearch search) {
|
||||
isSearchDetail = true;
|
||||
String str = search.getKey();
|
||||
searchInput.setText(str);
|
||||
searchInput.setFocusable(true);
|
||||
@ -337,16 +354,14 @@ public class SearchActivity extends BaseFragmentActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
game_detail_fragment = null;
|
||||
game_list_fragment = null;
|
||||
search_history_fragment = null;
|
||||
searchBack = null;
|
||||
searchInput = null;
|
||||
searchCancel = null;
|
||||
searchButton = null;
|
||||
dao = null;
|
||||
searchKey = null;
|
||||
public void finish() {
|
||||
super.finish();
|
||||
DataUtils.onEvent(this, "搜索页面", searchKey);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("key", searchKey);
|
||||
map.put("from", "搜索页面");
|
||||
DataCollectionManager.onEvent(this, "search", map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -7,42 +7,32 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TrafficUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.db.info.FilterInfo;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
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.manager.ConcernManager;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.manager.SuspectedGameManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -52,18 +42,16 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* 引导页面
|
||||
*
|
||||
@ -72,27 +60,31 @@ import java.util.Set;
|
||||
*/
|
||||
public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private ConcernManager concernManager;
|
||||
private PackageManager manager;
|
||||
private SharedPreferences sp;
|
||||
private boolean isFirst;
|
||||
public static final String TAG = SplashScreenActivity.class.getSimpleName();
|
||||
|
||||
public static boolean isShow = true;
|
||||
private SharedPreferences sp;
|
||||
|
||||
private String from;
|
||||
|
||||
private long start;
|
||||
|
||||
private boolean isFirst;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
isFirst = true;
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
|
||||
from = getIntent().getStringExtra("from");
|
||||
|
||||
if (sp.getBoolean("isFirstLaunch", true)
|
||||
if (sp.getBoolean("isNewFirstLaunch", true)
|
||||
|| sp.getInt("actionbar_height", 0) != 0) {
|
||||
setTheme(R.style.AppTheme_Guide);
|
||||
} else {
|
||||
@ -102,21 +94,19 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
if (mActionBar != null) {
|
||||
mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||
RelativeLayout relativeLayout = new RelativeLayout(this);
|
||||
relativeLayout.setBackgroundResource(R.color.theme_colors);
|
||||
relativeLayout.setBackgroundResource(R.color.theme);
|
||||
LayoutParams params = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
mActionBar.setCustomView(relativeLayout, params);// 自定义ActionBar布局
|
||||
}
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_splash);
|
||||
|
||||
if (sp.getBoolean("isFirstLaunch", true)) {
|
||||
findViewById(R.id.splash_ll_normal).setVisibility(View.GONE);
|
||||
|
||||
if (sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
setContentView(R.layout.activity_splash_intro);
|
||||
ViewPager splash_viewPager = (ViewPager) findViewById(R.id.splash_viewPager);
|
||||
splash_viewPager.setVisibility(View.VISIBLE);
|
||||
splash_viewPager.setAdapter(new ViewPagerAdapter());
|
||||
} else {
|
||||
setContentView(R.layout.activity_splash_normal);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,54 +117,55 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
|
||||
return pics.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
|
||||
ImageView iv = new ImageView(SplashScreenActivity.this);
|
||||
iv.setBackgroundResource(pics[position]);
|
||||
if (position == pics.length - 1) {
|
||||
iv.setOnClickListener(new View.OnClickListener() {
|
||||
View view = View.inflate(SplashScreenActivity.this, R.layout.splash_viewpage_item, null);
|
||||
TextView textView = (TextView) view.findViewById(R.id.splash_viewPager_item_btn);
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
RelativeLayout.LayoutParams rparams = (RelativeLayout.LayoutParams) textView.getLayoutParams();
|
||||
rparams.height = outMetrics.heightPixels / 4;
|
||||
textView.setLayoutParams(rparams);
|
||||
textView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(SplashScreenActivity.this,
|
||||
MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
launch();
|
||||
}
|
||||
});
|
||||
container.addView(view);
|
||||
return view;
|
||||
} else {
|
||||
ImageView imageView = new ImageView(SplashScreenActivity.this);
|
||||
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||
imageView.setImageResource(pics[position]);
|
||||
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
container.addView(imageView, params);
|
||||
return imageView;
|
||||
}
|
||||
container.addView(iv);
|
||||
return iv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
|
||||
container.removeView((View) object);
|
||||
object = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
|
||||
if (sp.getBoolean("isFirstLaunch", true)) {
|
||||
Intent intent = new Intent(SplashScreenActivity.this,
|
||||
MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
if (sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
launch();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
@ -184,70 +175,106 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
if (hasFocus && isFirst) {
|
||||
isFirst = false;
|
||||
|
||||
// 第一次启动,把package.txt文件内容加载进数据库
|
||||
if (!sp.getBoolean("isLoadFilter", false)) {
|
||||
try {
|
||||
List<FilterInfo> list = new ArrayList<FilterInfo>();
|
||||
List<FilterInfo> list = new ArrayList<>();
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(getAssets().open(
|
||||
"package.txt")));
|
||||
new InputStreamReader(getAssets().open("package.txt")));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
list.add(new FilterInfo(line));
|
||||
}
|
||||
reader.close();
|
||||
FilterManager filterManager = new FilterManager(
|
||||
getApplicationContext());
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
filterManager.addAllFilter(list);
|
||||
sp.edit().putBoolean("isLoadFilter", true).apply();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
isFirst = false;
|
||||
|
||||
checkUpdateFile();
|
||||
|
||||
concernManager = new ConcernManager(getApplicationContext());
|
||||
checkGhFile();
|
||||
|
||||
/*
|
||||
* 更新过滤表,获取自动刷新的cd,获取版本对应表
|
||||
*/
|
||||
String time = sp.getString("filter_time", null);
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
|
||||
Locale.getDefault());
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||
String today = format.format(new Date());
|
||||
if (!today.equals(time)) {
|
||||
FilterManager manager = new FilterManager(
|
||||
getApplicationContext());
|
||||
FilterManager manager = new FilterManager(getApplicationContext());
|
||||
manager.getFilterFromServer(today);
|
||||
|
||||
// 获取版本代码、名称
|
||||
getPlatform();
|
||||
}
|
||||
|
||||
// 获取下载按钮状态、开启or关闭
|
||||
getDownloadStatus();
|
||||
|
||||
getUISetting();
|
||||
|
||||
getTime();
|
||||
|
||||
/*
|
||||
* 上传数据
|
||||
*/
|
||||
DataCollectionManager.getInstance(getApplicationContext()).upload();
|
||||
|
||||
/*
|
||||
* 初始化已安装软件map,获取游戏更新列表和已安装列表
|
||||
*/
|
||||
manager = new PackageManager(getApplicationContext());
|
||||
manager.getInstalledMapFromLocal();
|
||||
|
||||
getInstalledListFromServer();
|
||||
// 不是第一次启动
|
||||
if (!sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
int height = sp.getInt("actionbar_height", 0);
|
||||
if (height == 0) {
|
||||
final ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
sp.edit().putInt("actionbar_height", actionBar.getHeight()).apply();
|
||||
}
|
||||
}
|
||||
long end = System.currentTimeMillis() - start;
|
||||
if (end < 3000) {
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launch();
|
||||
}
|
||||
}, 3000 - end);
|
||||
} else {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取服务器时间
|
||||
*/
|
||||
private void getTime() {
|
||||
StringExtendedRequest request = new StringExtendedRequest(
|
||||
Request.Method.GET, Config.HOST + "v2d0/support/time/current",
|
||||
new Response.Listener<String>() {
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
if (response.matches("^[0-9]{10}$")) {
|
||||
try {
|
||||
Editor editor = sp.edit();
|
||||
editor.putLong("server_time", Long.parseLong(response));
|
||||
editor.putLong("client_time", System.currentTimeMillis() / 1000);
|
||||
editor.apply();
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取界面设置
|
||||
*/
|
||||
@ -255,39 +282,24 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/setting/ui",
|
||||
new Response.Listener<JSONObject>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
|
||||
Utils.log(response.toString());
|
||||
// "platform_order":{"normal":["9u","baidu","360"]}}
|
||||
try {
|
||||
Editor editor = sp.edit();
|
||||
editor.putInt("download_box_row", response
|
||||
.getJSONObject("download_box")
|
||||
.getInt("row"));
|
||||
editor.putInt("download_box_row",
|
||||
response.getJSONObject("download_box").getInt("row"));
|
||||
editor.putInt("download_box_column",
|
||||
response.getJSONObject("download_box")
|
||||
.getInt("column"));
|
||||
editor.putInt(
|
||||
"game_detail_news_type_tab_column",
|
||||
response.getJSONObject(
|
||||
"game_detail_news_type_tab")
|
||||
.getInt("column"));
|
||||
response.getJSONObject("download_box").getInt("column"));
|
||||
editor.putInt("game_detail_news_type_tab_column",
|
||||
response.getJSONObject("game_detail_news_type_tab").getInt("column"));
|
||||
editor.apply();
|
||||
} catch (JSONException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -297,45 +309,43 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this,
|
||||
getPackageName(), "TD_CHANNEL_ID");
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/setting/download/" + TD_CHANNEL_ID
|
||||
+ "/switch2?version="
|
||||
+ PackageUtils.getVersion(getApplicationContext()), new Response.Listener<JSONObject>() {
|
||||
|
||||
Config.HOST + "v2d0/support/download_status?version=" + PackageUtils.getVersion(getApplicationContext())
|
||||
+ "&channel=" + TD_CHANNEL_ID,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
try {
|
||||
isShow = response.getBoolean("status");
|
||||
String status = response.getString("status");
|
||||
if ("on".equals(status)) {
|
||||
sp.edit().putBoolean("isShow", true).apply();
|
||||
} else {
|
||||
sp.edit().putBoolean("isShow", false).apply();
|
||||
}
|
||||
EventBus.getDefault().post(new EBReuse("Refresh"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
isShow = true;
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
/*
|
||||
* 检查下载文件夹下是否有旧版本的光环助手的包,有这删除
|
||||
* 检查下载文件夹下是否有旧版本的光环助手的包,有则删除
|
||||
*/
|
||||
private void checkUpdateFile() {
|
||||
File file = new File(FileUtils.getDownloadDir(this) + File.separator);
|
||||
if (file.isDirectory()) {
|
||||
for (File f : file.listFiles()) {
|
||||
if (!f.isDirectory() && f.getName().startsWith("光环助手V")) {
|
||||
String name = f.getName();
|
||||
private void checkGhFile() {
|
||||
File folder = new File(FileUtils.getDownloadDir(this) + File.separator);
|
||||
if (folder.isDirectory()) {
|
||||
for (File file : folder.listFiles()) {
|
||||
if (!file.isDirectory() && file.getName().startsWith("光环助手V")) {
|
||||
String name = file.getName();
|
||||
int index = name.indexOf("_");
|
||||
if (index != -1) {
|
||||
float version = Float.valueOf(name.substring(
|
||||
name.indexOf("V") + 1, index));
|
||||
float currentVersion = Float.valueOf(PackageUtils
|
||||
.getVersion(getApplicationContext()));
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersion(getApplicationContext()));
|
||||
if (version <= currentVersion) {
|
||||
f.delete();
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -345,13 +355,12 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private void getPlatform() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/support/setting/platform",
|
||||
Constants.PLATFORM_CD),
|
||||
Config.HOST + "v1d45/support/setting/platform",
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
try {
|
||||
Set<String> pset = new HashSet<String>();
|
||||
Set<String> pset = new HashSet<>();
|
||||
for (int i = 0; i < response.length(); i++) {
|
||||
JSONObject jsonObject = response
|
||||
.getJSONObject(i);
|
||||
@ -368,328 +377,62 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
editor.putStringSet("platform", pset);
|
||||
editor.apply();
|
||||
} catch (JSONException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
private int iCount;
|
||||
// 跳转到主界面
|
||||
private void launch() {
|
||||
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
|
||||
|
||||
private void getInstalledListFromServer() {
|
||||
List<String> list = manager.getLocalPackageName();
|
||||
final int count = list.size();
|
||||
final List<JSONObject> data = new ArrayList<JSONObject>();
|
||||
final List<String> useParams = new ArrayList<String>();
|
||||
iCount = 0;
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
final String packageName = list.get(i);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/" + list.get(i)
|
||||
+ "/game/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
iCount++;
|
||||
if (response.length() != 0) {
|
||||
data.add(response);
|
||||
useParams.add(packageName);
|
||||
}
|
||||
if (iCount == count) {
|
||||
processingInstalledData(data, useParams);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
iCount++;
|
||||
if (iCount == count) {
|
||||
processingInstalledData(data, useParams);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingInstalledData(List<JSONObject> data,
|
||||
List<String> useParams) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
Gson gson = new Gson();
|
||||
ConcernManager manager = new ConcernManager(getApplicationContext());
|
||||
for (int i = 0, size = data.size(); i < size; i++) {
|
||||
GameDigestEntity gameDigestEntity = gson.fromJson(data.get(i)
|
||||
.toString(), GameDigestEntity.class);
|
||||
GameInfo gameEntity = new GameInfo();
|
||||
gameEntity.setId(gameDigestEntity.getId());
|
||||
gameEntity.setPackageName(useParams.get(i));
|
||||
manager.updateByEntity(gameEntity, false);
|
||||
list.add(useParams.get(i));
|
||||
}
|
||||
|
||||
// 移除疑似游戏数据库中所有数据
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(
|
||||
getApplicationContext());
|
||||
suspectedGameManager.deleteAll();
|
||||
|
||||
getUpdateListFromServer(list);
|
||||
|
||||
updateConcern();
|
||||
}
|
||||
|
||||
private void getUpdateListFromServer(List<String> list) {
|
||||
|
||||
Comparator<String> comparator = new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String lhs, String rhs) {
|
||||
|
||||
char[] clhs = lhs.toCharArray();
|
||||
char[] crhs = rhs.toCharArray();
|
||||
int length = 0;
|
||||
if (clhs.length < crhs.length) {
|
||||
length = clhs.length;
|
||||
} else if (clhs.length > crhs.length) {
|
||||
length = crhs.length;
|
||||
} else {
|
||||
length = clhs.length;
|
||||
}
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (clhs[i] > crhs[i]) {
|
||||
return 1;
|
||||
} else if (clhs[i] < crhs[i]) {
|
||||
return -1;
|
||||
} else if (i == length - 1) {
|
||||
if (clhs.length < crhs.length) {
|
||||
return -1;
|
||||
} else if (clhs.length > crhs.length) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
Collections.sort(list, comparator);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String packages;
|
||||
PackageManager.clearUpdateList();
|
||||
for (int i = 0, sizei = (list.size() / 10) + 1; i < sizei; i++) {
|
||||
builder.delete(0, builder.length());
|
||||
for (int j = i * 10, sizej = (i + 1) * 10 > list.size() ? list
|
||||
.size() : (i + 1) * 10; j < sizej; j++) {
|
||||
builder.append(list.get(j) + "-");
|
||||
}
|
||||
if (builder.length() != 0) {
|
||||
packages = builder.substring(0, builder.length() - 1);
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/update?package="
|
||||
+ packages, new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
|
||||
Utils.log("getUpdateList=" + response.toString());
|
||||
if (response.length() != 0) {
|
||||
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<ArrayList<GameUpdateEntity>>() {}.getType();
|
||||
ArrayList<GameUpdateEntity> games = gson.fromJson(response.toString(), listType);
|
||||
GameUpdateEntity gameUpdateEntity;
|
||||
for (int i = 0; i < games.size(); i++) {
|
||||
gameUpdateEntity = games.get(i);
|
||||
// 判断是否gh_version是否相同
|
||||
String gh_version = (String) PackageUtils
|
||||
.getMetaData(SplashScreenActivity.this, gameUpdateEntity.getPackageName(), "gh_version");
|
||||
if (gh_version != null) {
|
||||
gh_version = gh_version.substring(2);
|
||||
// 判断gh_version是否相同
|
||||
if (gh_version.equals(gameUpdateEntity.getGhVersion())) {
|
||||
// 判断version是否相同
|
||||
String version = PackageUtils
|
||||
.getVersionByPackage(SplashScreenActivity.this, gameUpdateEntity.getPackageName());
|
||||
if (version.equals(gameUpdateEntity.getVersion())) {
|
||||
// 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包
|
||||
games.remove(i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PackageManager.addUpdateList(games);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request,
|
||||
SplashScreenActivity.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int cCount;
|
||||
|
||||
private void updateConcern() {
|
||||
|
||||
ArrayList<String> concernId = new ArrayList<String>();
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
concernId.add(entity.getId());
|
||||
}
|
||||
|
||||
if (concernId.size() != 0) {
|
||||
cCount = 0;
|
||||
final int count = concernId.size();
|
||||
for (int i = 0, size = concernId.size(); i < size; i++) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/game/" + concernId.get(i)
|
||||
+ "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
|
||||
cCount++;
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(
|
||||
response.toString(), GameEntity.class);
|
||||
|
||||
ArrayMap<String, ConcernInfo> map = concernManager
|
||||
.getConcernMap();
|
||||
ConcernInfo entity = map.get(gameEntity.getId());
|
||||
if (entity != null) {
|
||||
List<ApkEntity> list = gameEntity.getApk();
|
||||
HashMap<String, Boolean> packageNames = new HashMap<String, Boolean>();
|
||||
for (int j = 0, sizej = list.size(); j < sizej; j++) {
|
||||
packageNames.put(
|
||||
list.get(j).getPackageName(), false);
|
||||
}
|
||||
entity.setTime(System.currentTimeMillis());
|
||||
entity.setPackageNames(packageNames);
|
||||
concernManager.updateByConcern(entity);
|
||||
}
|
||||
if (cCount == count) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
cCount++;
|
||||
if (cCount == count) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request,
|
||||
SplashScreenActivity.class);
|
||||
}
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
if (bundle != null && bundle.getString("to") != null) {
|
||||
intentControl(bundle, intent);
|
||||
} else {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
update();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void update() {
|
||||
/*
|
||||
* 更新关注列表数据
|
||||
*/
|
||||
TrafficUtils spy = TrafficUtils.getInstance(getApplicationContext(),
|
||||
true);
|
||||
List<ConcernInfo> concernEntities = concernManager.getAllConcern();
|
||||
for (ConcernInfo concernEntity : concernEntities) {
|
||||
concernEntity.setTime(System.currentTimeMillis());
|
||||
int quantity = 0;
|
||||
HashMap<String, Boolean> packageNames = new HashMap<String, Boolean>();
|
||||
for (String packageName : concernEntity.getPackageNames().keySet()) {
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
quantity++;
|
||||
packageNames.put(packageName, true);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
}
|
||||
concernEntity.setPackageNames(packageNames);
|
||||
concernEntity.setInstalled(quantity > 0 ? true : false);
|
||||
concernEntity.setInstalledQuantity(quantity);
|
||||
String tag = null;
|
||||
int weight = 0;
|
||||
if (concernEntity.isConcern() && concernEntity.isInstalled()) {
|
||||
tag = "已关注,已安装";
|
||||
weight = 2;
|
||||
} else if (concernEntity.isConcern()
|
||||
&& !concernEntity.isInstalled()) {
|
||||
tag = "已关注";
|
||||
weight = 1;
|
||||
} else if (!concernEntity.isConcern()
|
||||
&& concernEntity.isInstalled()) {
|
||||
tag = "已安装";
|
||||
weight = 1;
|
||||
}
|
||||
concernEntity.setTag(tag);
|
||||
long traffic = spy.getTraffic(new ArrayList<String>(concernEntity
|
||||
.getPackageNames().keySet()));
|
||||
concernEntity.setTraffic(traffic);
|
||||
if (traffic > 0) {
|
||||
weight++;
|
||||
}
|
||||
concernEntity.setWeight(weight);
|
||||
if (weight == 0) {
|
||||
concernManager.deleteConcern(concernEntity.getId());
|
||||
} else {
|
||||
concernManager.updateByConcern(concernEntity);
|
||||
}
|
||||
}
|
||||
if (!sp.getBoolean("isFirstLaunch", true)) {
|
||||
|
||||
int height = sp.getInt("actionbar_height", 0);
|
||||
if (height == 0) {
|
||||
final ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
sp.edit().putInt("actionbar_height", actionBar.getHeight())
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
|
||||
Intent intent = new Intent(SplashScreenActivity.this,
|
||||
MainActivity.class);
|
||||
intent.putExtra("from", from);
|
||||
if ("plugin".equals(from)) {
|
||||
intent.putExtra("packageName",
|
||||
getIntent().getStringExtra("packageName"));
|
||||
intent.putExtra("packageName", getIntent().getStringExtra("packageName"));
|
||||
} else if ("mipush_news".equals(from)) {
|
||||
intent.putExtra("entity",
|
||||
getIntent().getSerializableExtra("entity"));
|
||||
intent.putExtra("newsId", getIntent().getStringExtra("newsId"));
|
||||
} else if ("mipush_plugin".equals(from)) {
|
||||
intent.putExtra("data", getIntent().getStringExtra("data"));
|
||||
} else if ("plugin_install".equals(from)) {
|
||||
intent.putExtra("path", getIntent().getStringExtra("path"));
|
||||
}
|
||||
}
|
||||
|
||||
startActivity(intent);
|
||||
finish();
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void intentControl(Bundle bundle, Intent intent) {
|
||||
String to = bundle.getString("to");
|
||||
if ("NewsActivity".equals(to) || "NewsDetailActivity".equals(to)) {
|
||||
intent.putExtra("newsId", bundle.getString("newsId"));
|
||||
intent.putExtra("entrance", bundle.getString("entrance"));
|
||||
} else if("DownloadManagerActivity".equals(to)) {
|
||||
intent.putExtra("packageName", bundle.getString("packageName"));
|
||||
} else if ("GameDetailsActivity".equals(to) || "GameDetailActivity".equals(to)) {
|
||||
intent.putExtra("gameId", bundle.getString("gameId"));
|
||||
intent.putExtra("entrance", bundle.getString("entrance"));
|
||||
} else if ("SubjectActivity".equals(to)) {
|
||||
intent.putExtra("id", bundle.getString("id"));
|
||||
intent.putExtra("name", bundle.getString("name"));
|
||||
intent.putExtra("order", bundle.getBoolean("order"));
|
||||
} else if ("ViewImageActivity".equals(to)) {
|
||||
intent.putExtra("urls", bundle.getStringArrayList("urls"));
|
||||
intent.putExtra("current", bundle.getInt("current",0));
|
||||
intent.putExtra("ScaleType", bundle.getString("ScaleType"));
|
||||
}
|
||||
if ("NewsActivity".equals(to)) {
|
||||
intent.putExtra("to", "NewsDetailActivity");
|
||||
} else if ("GameDetailsActivity".equals(to)) {
|
||||
intent.putExtra("to", "GameDetailActivity");
|
||||
} else {
|
||||
intent.putExtra("to", to);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
196
app/src/main/java/com/gh/gamecenter/SubjectActivity.java
Normal file
196
app/src/main/java/com/gh/gamecenter/SubjectActivity.java
Normal file
@ -0,0 +1,196 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
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 com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DownloadItemUtils;
|
||||
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.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;
|
||||
|
||||
public class SubjectActivity extends BaseActivity {
|
||||
|
||||
public static final String TAG = SubjectActivity.class.getSimpleName();
|
||||
|
||||
private RecyclerView subject_list;
|
||||
private SubjectAdapter adapter;
|
||||
private ProgressBarCircularIndeterminate subject_pb_loading;
|
||||
private LinearLayout reuse_no_connection;
|
||||
private LinearLayoutManager layoutManager;
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String entrance;
|
||||
|
||||
private int page = 1;
|
||||
|
||||
private boolean order;
|
||||
private boolean isEverpause = false;
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
Integer location = adapter.getLocationMap().get(downloadEntity.getName());
|
||||
if (location != null) {
|
||||
GameEntity detailedEntity = adapter.getList().get(location);
|
||||
if (detailedEntity != null) {
|
||||
DownloadItemUtils.processDate(SubjectActivity.this, detailedEntity, downloadEntity,
|
||||
adapter, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
entrance = getIntent().getStringExtra("entrance");
|
||||
|
||||
id = getIntent().getStringExtra("id");
|
||||
name = getIntent().getStringExtra("name");
|
||||
order = getIntent().getBooleanExtra("order",false);
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_subject, null);
|
||||
init(contentView, name);
|
||||
|
||||
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, id, name, order, entrance);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
|
||||
subject_list.setHasFixedSize(true);
|
||||
subject_list.setLayoutManager(layoutManager);
|
||||
adapter = new SubjectAdapter(this, id, name, order, entrance);
|
||||
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
|
||||
&& adapter.getItemCount() == layoutManager.findLastVisibleItemPosition() + 1){
|
||||
page++;
|
||||
adapter.initList(page);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadError() {
|
||||
if (subject_pb_loading != null && subject_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
subject_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
toast("加载失败,请检查网络状态");
|
||||
subject_list.setVisibility(View.GONE);
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDone() {
|
||||
if (subject_pb_loading != null && subject_pb_loading.getVisibility() == View.VISIBLE) {
|
||||
subject_pb_loading.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
// 下载被删除事件
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
if ("delete".equals(status.getStatus())) {
|
||||
DownloadManager.getInstance(this).removePlatform(status.getName(), status.getPlatform());
|
||||
Integer location = adapter.getLocationMap().get(status.getName());
|
||||
if (location != null) {
|
||||
GameEntity gameEntity = adapter.getList().get(location);
|
||||
if (gameEntity != null && gameEntity.getEntryMap() != null) {
|
||||
if (TextUtils.isEmpty(status.getPlatform())) {
|
||||
gameEntity.getEntryMap().remove("官方版");
|
||||
} else {
|
||||
gameEntity.getEntryMap().remove(status.getPlatform());
|
||||
}
|
||||
}
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
String name = adapter.getNameMap().get(busFour.getPackageName());
|
||||
if (name != null) {
|
||||
int location = adapter.getLocationMap().get(name);
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
GameEntity entity = adapter.getList().get(location);
|
||||
for (ApkEntity apkEntity : entity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(
|
||||
busFour.getPackageName())) {
|
||||
entity.getEntryMap().remove(apkEntity.getPlatform());
|
||||
adapter.notifyItemChanged(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
adapter.notifyItemChanged(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//连接上网络事件
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
|
||||
subject_list.setVisibility(View.VISIBLE);
|
||||
subject_pb_loading.setVisibility(View.VISIBLE);
|
||||
reuse_no_connection.setVisibility(View.GONE);
|
||||
adapter = new SubjectAdapter(SubjectActivity.this, id, name, order, entrance);
|
||||
subject_list.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isEverpause) {
|
||||
for (GameEntity entity : adapter.getList()) {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
AppController.canclePendingRequests(TAG);
|
||||
}
|
||||
}
|
||||
@ -4,10 +4,9 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.Editable;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
@ -24,6 +23,7 @@ import com.android.volley.toolbox.JsonObjectRequest;
|
||||
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.PackageUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
@ -42,9 +42,11 @@ import java.util.regex.Pattern;
|
||||
* */
|
||||
public class SuggestionActivity extends BaseActivity implements OnClickListener {
|
||||
|
||||
private TextView tv_suggest_title, tv_suggest_connectway;
|
||||
public static final String TAG = SuggestionActivity.class.getSimpleName();
|
||||
|
||||
private TextView tv_suggest_connectway;
|
||||
private EditText et_suggest_content, et_suggest_connectway;
|
||||
private TextView btn_suggest_post;
|
||||
private CardView btn_suggest_post;
|
||||
|
||||
private boolean isShowing = false;
|
||||
|
||||
@ -59,17 +61,10 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
btn_suggest_post.setOnClickListener(this);
|
||||
btn_suggest_post.setClickable(false);
|
||||
|
||||
Spanned title = Html.fromHtml("<font color='red'>*</font>意见描述");
|
||||
tv_suggest_title.setText(title);
|
||||
|
||||
et_suggest_content
|
||||
.setHint("使用过程中发现的任何问题或者其他建议都欢迎提交给我们~光环助手会努力变得更好更强大!");
|
||||
|
||||
et_suggest_content.requestFocus();
|
||||
|
||||
tv_suggest_connectway.setText("邮箱");
|
||||
|
||||
et_suggest_connectway.setHint("留下您的邮箱,以便我们更好地回复您!");
|
||||
et_suggest_content.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||
@ -81,12 +76,9 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
public void onTextChanged(CharSequence s, int start, int before,
|
||||
int count) {
|
||||
if (s.length() > 0) {
|
||||
btn_suggest_post.setBackgroundColor(getResources()
|
||||
.getColor(R.color.theme_colors));
|
||||
btn_suggest_post.setClickable(true);
|
||||
} else {
|
||||
btn_suggest_post.setClickable(false);
|
||||
btn_suggest_post.setBackgroundColor(0x881BA4FC);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +105,7 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
View view = View.inflate(this, R.layout.set_wait_dialog, null);
|
||||
TextView message = (TextView) view
|
||||
.findViewById(R.id.set_wait_message);
|
||||
message.setText("正在上传中...");
|
||||
message.setText("正在反馈...");
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
@ -121,7 +113,7 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (isShowing) {
|
||||
AppController.canclePendingRequests(SuggestionActivity.class);
|
||||
AppController.canclePendingRequests(TAG);
|
||||
toast("取消发送");
|
||||
}
|
||||
}
|
||||
@ -139,87 +131,62 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
|
||||
// 弹出确认对话框
|
||||
private void showConfirmDialog(final String email) {
|
||||
final Dialog confirmDialog = new Dialog(this);
|
||||
View view = View.inflate(this, R.layout.search_history_delete_dialog,
|
||||
null);
|
||||
TextView title = (TextView) view.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("温馨提示");
|
||||
TextView content = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_message);
|
||||
|
||||
content.setText("填写联系方式有助于我们更好的一对一地解决您的问题,确定不填写吗?");
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("填写");
|
||||
cancel.setTextColor(0xffFFFFFF);
|
||||
cancel.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
confirmDialog.dismiss();
|
||||
et_suggest_connectway.requestFocus();
|
||||
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(et_suggest_connectway, 0);
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
});
|
||||
TextView confirm = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirm.setText("提交");
|
||||
confirm.setTextColor(0xff999999);
|
||||
confirm.setBackgroundResource(R.drawable.textview_cancel_style);
|
||||
confirm.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
confirmDialog.dismiss();
|
||||
isShowing = true;
|
||||
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.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
DialogUtils.showWarningDialog(this, "温馨提示", "填写联系方式有助于我们更好地一对一解决您的问题,确定不填写吗?",
|
||||
"直接提交", "我要填写",
|
||||
new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (isShowing) {
|
||||
AppController.canclePendingRequests(SuggestionActivity.class);
|
||||
toast("取消发送");
|
||||
}
|
||||
public void onConfirem() {
|
||||
et_suggest_connectway.requestFocus();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
sleep(300);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(et_suggest_connectway, 0);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
},
|
||||
new DialogUtils.CancelListener() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
isShowing = true;
|
||||
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.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (isShowing) {
|
||||
AppController.canclePendingRequests(TAG);
|
||||
toast("取消发送");
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
sendSuggestion(dialog, email);
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
sendSuggestion(dialog, email);
|
||||
}
|
||||
});
|
||||
confirmDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
confirmDialog.setContentView(view);
|
||||
confirmDialog.show();
|
||||
}
|
||||
|
||||
private void sendSuggestion(final Dialog dialog, String email) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("message", et_suggest_content.getText().toString().trim());
|
||||
map.put("from", email);
|
||||
map.put("ghversion", PackageUtils.getVersion(this));
|
||||
map.put("channel", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
map.put("type", android.os.Build.MODEL);
|
||||
map.put("sdk", android.os.Build.VERSION.SDK_INT + "");
|
||||
map.put("sdk", String.valueOf(android.os.Build.VERSION.SDK_INT));
|
||||
map.put("version", android.os.Build.VERSION.RELEASE);
|
||||
map.put("imei", ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId());
|
||||
JsonObjectRequest request = new JsonObjectRequest(Method.POST,
|
||||
@ -247,11 +214,11 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
isShowing = false;
|
||||
dialog.dismiss();
|
||||
toast("发送失败,请检查网络情况!");
|
||||
toast("提交失败,请检查网络状态");
|
||||
}
|
||||
});
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request, SuggestionActivity.class);
|
||||
AppController.addToRequestQueue(request, TAG);
|
||||
}
|
||||
|
||||
private boolean isEmailAddress(String email) {
|
||||
@ -261,14 +228,4 @@ public class SuggestionActivity extends BaseActivity implements OnClickListener
|
||||
return m.matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
|
||||
super.onDestroy();
|
||||
tv_suggest_title = null;
|
||||
tv_suggest_connectway = null;
|
||||
et_suggest_content = null;
|
||||
et_suggest_connectway = null;
|
||||
btn_suggest_post = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -18,215 +19,289 @@ 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.view.Gh_ImageLayout;
|
||||
import com.gh.common.view.Gh_ImageLayout.OnSingleTapListener;
|
||||
import com.gh.common.view.Gh_RelativeLayout;
|
||||
import com.gh.common.view.Gh_RelativeLayout.OnSingleTapListener;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pl.droidsonroids.gif.GifDrawable;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
|
||||
|
||||
/**
|
||||
* 查看游戏截图页面
|
||||
*
|
||||
*
|
||||
* @author 黄壮华
|
||||
*
|
||||
*/
|
||||
public class ViewImageActivity extends BaseActivity implements
|
||||
OnPageChangeListener {
|
||||
OnPageChangeListener {
|
||||
|
||||
private ViewPager viewimage_vp_show;
|
||||
private ViewImageAdapter adapter;
|
||||
private View viewimage_slide_line;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
private ViewPager viewimage_vp_show;
|
||||
private ViewImageAdapter adapter;
|
||||
private View viewimage_slide_line;
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
|
||||
private ArrayList<String> urls;
|
||||
private ArrayList<String> urls;
|
||||
|
||||
private int current;
|
||||
private int width;
|
||||
private String scaleType;
|
||||
private String scaleType;
|
||||
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
notifyItemChanged(msg.arg1);
|
||||
}
|
||||
};
|
||||
private int width;
|
||||
|
||||
private void notifyItemChanged(int position) {
|
||||
Object object = viewimage_vp_show.findViewWithTag(position);
|
||||
if (object != null) {
|
||||
RelativeLayout view = (RelativeLayout) object;
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
final ProgressBarCircularIndeterminate progressBar = (ProgressBarCircularIndeterminate) view.findViewById(R.id.viewimage_pb_loading);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
private boolean isOrientation;
|
||||
private boolean isLoading = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
notifyItemChanged(msg.arg1);
|
||||
}
|
||||
};
|
||||
|
||||
Intent intent = getIntent();
|
||||
urls = intent.getStringArrayListExtra("urls");
|
||||
current = intent.getIntExtra("current", 0);
|
||||
scaleType = intent.getStringExtra("ScaleType");
|
||||
private void notifyItemChanged(int position) {
|
||||
Object object = viewimage_vp_show.findViewWithTag(position);
|
||||
if (object != null) {
|
||||
RelativeLayout view = (RelativeLayout) object;
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
final ProgressBarCircularIndeterminate progressBar = (ProgressBarCircularIndeterminate) view.findViewById(R.id.viewimage_pb_loading);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER,
|
||||
new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, new ImageUtils.OnLoadingCompleteListener() {
|
||||
@Override
|
||||
public void onLoadingComplete() {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
current = savedInstanceState.getInt("currentItem", 0);
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_viewimage);
|
||||
Intent intent = getIntent();
|
||||
urls = intent.getStringArrayListExtra("urls");
|
||||
int current = intent.getIntExtra("current", 0);
|
||||
scaleType = intent.getStringExtra("ScaleType");
|
||||
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / urls.size();
|
||||
if (savedInstanceState != null) {
|
||||
current = savedInstanceState.getInt("currentItem", 0);
|
||||
isOrientation = savedInstanceState.getBoolean("isOrientation");
|
||||
}
|
||||
|
||||
rparams = new RelativeLayout.LayoutParams(width, DisplayUtils.dip2px(
|
||||
getApplicationContext(), 1));
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
rparams.bottomMargin = DisplayUtils.dip2px(getApplicationContext(), 10);
|
||||
rparams.leftMargin = width * current;
|
||||
viewimage_slide_line = findViewById(R.id.viewimage_slide_line);
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
|
||||
viewimage_vp_show = (ViewPager) findViewById(R.id.viewimage_vp_show);
|
||||
adapter = new ViewImageAdapter();
|
||||
viewimage_vp_show.setAdapter(adapter);
|
||||
viewimage_vp_show.setCurrentItem(current);
|
||||
viewimage_vp_show.addOnPageChangeListener(this);
|
||||
}
|
||||
setContentView(R.layout.activity_viewimage);
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", viewimage_vp_show.getCurrentItem());
|
||||
}
|
||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
|
||||
width = outMetrics.widthPixels / urls.size();
|
||||
|
||||
private class ViewImageAdapter extends PagerAdapter implements
|
||||
OnSingleTapListener {
|
||||
rparams = new RelativeLayout.LayoutParams(width, DisplayUtils.dip2px(getApplicationContext(), 1));
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
rparams.bottomMargin = DisplayUtils.dip2px(getApplicationContext(), 10);
|
||||
rparams.leftMargin = width * current;
|
||||
viewimage_slide_line = findViewById(R.id.viewimage_slide_line);
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return urls.size();
|
||||
}
|
||||
viewimage_vp_show = (ViewPager) findViewById(R.id.viewimage_vp_show);
|
||||
adapter = new ViewImageAdapter();
|
||||
viewimage_vp_show.setAdapter(adapter);
|
||||
viewimage_vp_show.setCurrentItem(current);
|
||||
viewimage_vp_show.addOnPageChangeListener(this);
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
Gh_ImageLayout view = (Gh_ImageLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_item, null);
|
||||
view.setOnSingleTapListener(this);
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER);
|
||||
} else {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView);
|
||||
}
|
||||
if (!urls.get(position).startsWith("http://image.ghzhushou.com/pic/hq/")) {
|
||||
checkUrl(urls.get(position));
|
||||
}
|
||||
view.setTag(position);
|
||||
container.addView(view);
|
||||
return view;
|
||||
}
|
||||
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
isOrientation = true; // 横屏
|
||||
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
isOrientation = false;// 竖屏
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
}
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("currentItem", viewimage_vp_show.getCurrentItem());
|
||||
outState.putBoolean("isOrientation", isOrientation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
container.removeView((View) object);
|
||||
object = null;
|
||||
}
|
||||
private class ViewImageAdapter extends PagerAdapter implements
|
||||
OnSingleTapListener {
|
||||
|
||||
@Override
|
||||
public void onSingleTap() {
|
||||
finish();
|
||||
}
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (urls == null) {
|
||||
return 0;
|
||||
}
|
||||
return urls.size();
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
String url = urls.get(position);
|
||||
Gh_RelativeLayout view;
|
||||
if (url.contains(".gif")) {
|
||||
view = (Gh_RelativeLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_gif_item, null);
|
||||
GifImageView gifImageView = (GifImageView) view.findViewById(R.id.viewimage_iv_gif);
|
||||
if (!isLoading) {
|
||||
loadGifData(gifImageView, urls.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int newState) {
|
||||
} else {
|
||||
view = (Gh_RelativeLayout) View.inflate(container.getContext(),
|
||||
R.layout.viewimage_normal_item, null);
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.viewimage_iv_show);
|
||||
if (scaleType != null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, ScaleType.FIT_CENTER);
|
||||
} else if (isOrientation && imageView.getDrawable() == null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView, 270, isOrientation);
|
||||
} else if (imageView.getDrawable() == null) {
|
||||
ImageUtils.getInstance(getApplicationContext()).display(
|
||||
urls.get(position), imageView);
|
||||
}
|
||||
if (!urls.get(position).startsWith("http://image.ghzhushou.com/pic/hq/")) {
|
||||
checkUrl(urls.get(position));
|
||||
}
|
||||
}
|
||||
view.setOnSingleTapListener(this);
|
||||
view.setTag(position);
|
||||
container.addView(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
private void loadGifData(final GifImageView gifImageView, final String gifUrl) {
|
||||
isLoading = true;
|
||||
gifImageView.setImageResource(R.drawable.ocupy);
|
||||
gifImageView.setScaleType(ScaleType.CENTER);
|
||||
final GifDrawable[] gifDrawable = {null};
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
URL url = new URL(gifUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5 * 1000);
|
||||
conn.setReadTimeout(5 * 1000);
|
||||
conn.connect();
|
||||
if (conn.getResponseCode() == 200) {
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
byte[] data = new byte[1024 * 5];
|
||||
int count = -1;
|
||||
while ((count = inputStream.read(data, 0, 1024 * 5)) != -1) {
|
||||
output.write(data, 0, count);
|
||||
}
|
||||
byte[] bytes = output.toByteArray();
|
||||
gifDrawable[0] = new GifDrawable(bytes);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
gifImageView.setImageDrawable(gifDrawable[0]);
|
||||
gifImageView.setScaleType(ScaleType.FIT_CENTER);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
rparams.leftMargin = (int) (width * (positionOffset + position));
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
// container.removeView((View) object);
|
||||
// object = null;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onSingleTap() {
|
||||
finish();
|
||||
}
|
||||
|
||||
private void checkUrl(final String url) {
|
||||
if (!url.startsWith("http://image.ghzhushou.com/pic/")){
|
||||
return;
|
||||
}
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String newUrl = "http://image.ghzhushou.com/pic/hq" + url.substring(url.lastIndexOf("/"));
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(5 * 1000);
|
||||
connection.connect();
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200) {
|
||||
//图片存在
|
||||
for (int i = 0, size = urls.size(); i < size; i++) {
|
||||
if (urls.get(i).equals(url)){
|
||||
urls.set(i, newUrl);
|
||||
Message msg = new Message();
|
||||
msg.arg1 = i;
|
||||
handler.sendMessage(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
viewimage_vp_show = null;
|
||||
adapter = null;
|
||||
viewimage_slide_line = null;
|
||||
rparams = null;
|
||||
urls = null;
|
||||
}
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int newState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
rparams.leftMargin = (int) (width * (positionOffset + position));
|
||||
viewimage_slide_line.setLayoutParams(rparams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
|
||||
}
|
||||
|
||||
private void checkUrl(final String url) {
|
||||
if (!url.startsWith("http://image.ghzhushou.com/pic/")) {
|
||||
return;
|
||||
}
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String newUrl = "http://image.ghzhushou.com/pic/hq" + url.substring(url.lastIndexOf("/"));
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(5 * 1000);
|
||||
connection.connect();
|
||||
int code = connection.getResponseCode();
|
||||
if (code == 200) {
|
||||
//图片存在
|
||||
if (urls == null) {
|
||||
return;
|
||||
}
|
||||
//urls出现空指针
|
||||
for (int i = 0, size = urls.size(); i < size; i++) {
|
||||
if (urls.get(i).equals(url)) {
|
||||
urls.set(i, newUrl);
|
||||
Message msg = new Message();
|
||||
msg.arg1 = i;
|
||||
handler.sendMessage(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
/**
|
||||
* Created by idea on 2016/4/6.
|
||||
*/
|
||||
/*
|
||||
* 官网地站:http://www.mob.com
|
||||
* 技术支持QQ: 4006852216
|
||||
* 官方微信:ShareSDK (如果发布新版本的话,我们将会第一时间通过微信将版本更新内容推送给您。如果使用过程中有任何问题,也可以通过微信与我们取得联系,我们将会在24小时内给予回复)
|
||||
*
|
||||
* Copyright (c) 2013年 mob.com. All rights reserved.
|
||||
*/
|
||||
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import cn.sharesdk.wechat.utils.WXAppExtendObject;
|
||||
import cn.sharesdk.wechat.utils.WXMediaMessage;
|
||||
import cn.sharesdk.wechat.utils.WechatHandlerActivity;
|
||||
|
||||
/**
|
||||
* 微信客户端回调activity示例
|
||||
*/
|
||||
public class WXEntryActivity extends WechatHandlerActivity {
|
||||
/**
|
||||
* 处理微信发出的向第三方应用请求app message
|
||||
* <p/>
|
||||
* 在微信客户端中的聊天页面有“添加工具”,可以将本应用的图标添加到其中
|
||||
* 此后点击图标,下面的代码会被执行。Demo仅仅只是打开自己而已,但你可
|
||||
* 做点其他的事情,包括根本不打开任何页面
|
||||
*/
|
||||
public void onGetMessageFromWXReq(WXMediaMessage msg) {
|
||||
Intent iLaunchMyself = getPackageManager().getLaunchIntentForPackage(getPackageName());
|
||||
startActivity(iLaunchMyself);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理微信向第三方应用发起的消息
|
||||
* <p/>
|
||||
* 此处用来接收从微信发送过来的消息,比方说本demo在wechatpage里面分享
|
||||
* 应用时可以不分享应用文件,而分享一段应用的自定义信息。接受方的微信
|
||||
* 客户端会通过这个方法,将这个信息发送回接收方手机上的本demo中,当作
|
||||
* 回调。
|
||||
* <p/>
|
||||
* 本Demo只是将信息展示出来,但你可做点其他的事情,而不仅仅只是Toast
|
||||
*/
|
||||
public void onShowMessageFromWXReq(WXMediaMessage msg) {
|
||||
if (msg != null && msg.mediaObject != null && (msg.mediaObject instanceof WXAppExtendObject)) {
|
||||
WXAppExtendObject obj = (WXAppExtendObject) msg.mediaObject;
|
||||
Toast.makeText(this, obj.extInfo, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user