Compare commits
308 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7862426144 | |||
| 6e196262a5 | |||
| 11abd6d60f | |||
| 54df9912eb | |||
| b46e1f3291 | |||
| 98eb063ea1 | |||
| ac29a19ee8 | |||
| 553d005ed0 | |||
| 96e59d764a | |||
| cb3c3eb046 | |||
| 8d50f12886 | |||
| c8821f2f54 | |||
| b3e2f3545d | |||
| 383b7bce21 | |||
| ab9a8fd106 | |||
| 2954260722 | |||
| 6f78ba604f | |||
| 4471d95482 | |||
| 929038fc30 | |||
| c2cf64dfa0 | |||
| 719177b816 | |||
| 190296e533 | |||
| f1f33112fc | |||
| b1fdeeef65 | |||
| 63b8e9551c | |||
| f6758d4d3a | |||
| e873b539eb | |||
| 95a3d7b494 | |||
| 1578925613 | |||
| f3ee2d2cf0 | |||
| 39d71f3627 | |||
| e52caa013d | |||
| 18d88ab298 | |||
| b768f5f661 | |||
| b756410982 | |||
| bcc58481ed | |||
| 2c6fd5d0d8 | |||
| 24238acf0e | |||
| 089399307f | |||
| 385d9155f7 | |||
| 6eaef8388b | |||
| 3100d6aede | |||
| 35b62c2bc6 | |||
| ded2fcdc7d | |||
| 0479cfca18 | |||
| 4f0a2dd3c8 | |||
| e082ad97ac | |||
| 40d8f17ce7 | |||
| 140f876164 | |||
| 5fa0fa8d17 | |||
| da8ac35932 | |||
| 9e6491b86b | |||
| fcdb0e3d80 | |||
| e42e4ee96d | |||
| a9d42403d9 | |||
| 561dd33044 | |||
| c5618bb3db | |||
| d9f5ba517d | |||
| 054ceda63a | |||
| ad0efd98ff | |||
| f0b473db2c | |||
| 58324c5d24 | |||
| 82d960c586 | |||
| ec9219ac7f | |||
| 28e7bd5304 | |||
| 4e4c2cd788 | |||
| 896c4e980c | |||
| 4262ec7386 | |||
| 08744c55ce | |||
| 6031161452 | |||
| 55c657aba6 | |||
| c4e01140a2 | |||
| c9cdf51b51 | |||
| 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 16
|
||||
versionName "2.1"
|
||||
|
||||
// 默认的渠道
|
||||
// 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,53 @@ 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 'com.android.support:cardview-v7:21.0.0'
|
||||
|
||||
compile ('com.facebook.fresco:fresco:0.12.0') {
|
||||
exclude module: 'support-v4'
|
||||
}
|
||||
compile ('com.facebook.fresco:animated-gif:0.12.0') {
|
||||
exclude module: 'support-v4'
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
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.
Binary file not shown.
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.
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"
|
||||
@ -61,7 +52,6 @@
|
||||
|
||||
<application
|
||||
android:name="com.gh.base.AppController"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/logo"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppThemeNormal" >
|
||||
@ -71,7 +61,9 @@
|
||||
android:value="81DB144D555386A38A70B833537EC256" />
|
||||
<meta-data
|
||||
android:name="TD_CHANNEL_ID"
|
||||
android:value="GH_200" />
|
||||
android:value="GH_TEST"
|
||||
/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<!-- MTA -->
|
||||
<meta-data
|
||||
@ -79,7 +71,8 @@
|
||||
android:value="APV567FTBS7J"/>
|
||||
<meta-data
|
||||
android:name="InstallChannel"
|
||||
android:value="GH_127"/>
|
||||
android:value="GH_TEST"/>
|
||||
<!--android:value="${CHANNEL_VALUE}"-->
|
||||
|
||||
<activity
|
||||
android:name="com.gh.gamecenter.SplashScreenActivity"
|
||||
@ -93,6 +86,54 @@
|
||||
<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.gh.gamecenter.WebActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
<activity
|
||||
android:name="com.mob.tools.MobUIShell"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
@ -109,53 +150,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>
|
||||
@ -174,10 +197,17 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name="com.gh.gamecenter.receiver.UninstallReceiver"
|
||||
android:name="com.gh.gamecenter.receiver.DownloadReceiver"
|
||||
android:exported="false" >
|
||||
<intent-filter>
|
||||
<action android:name="com.gh.gamecenter.UNINSTALL" />
|
||||
<action android:name="com.gh.gamecenter.DOWNLOAD" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name="com.gh.gamecenter.receiver.InstallReceiver"
|
||||
android:exported="false" >
|
||||
<intent-filter>
|
||||
<action android:name="com.gh.gamecenter.INSTALL" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name="com.gh.gamecenter.receiver.NetworkStateReceiver" >
|
||||
@ -216,20 +246,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 + "support/upgrade")) {
|
||||
if (request.getCacheEntry() != null) {
|
||||
return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED,
|
||||
request.getCacheEntry().data, responseHeaders, true);
|
||||
|
||||
@ -176,9 +176,8 @@ public class DiskBasedCache implements Cache {
|
||||
|
||||
public synchronized void modify(String key, byte[] data) {
|
||||
File file = getFileForKey(key);
|
||||
CountingInputStream cis = null;
|
||||
try {
|
||||
cis = new CountingInputStream(new FileInputStream(file));
|
||||
CountingInputStream cis = new CountingInputStream(new FileInputStream(file));
|
||||
CacheHeader e = CacheHeader.readHeader(cis); // eat header
|
||||
Entry entry = e.toCacheEntry(data);
|
||||
cis.close();
|
||||
|
||||
@ -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,103 @@ 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.facebook.drawee.backends.pipeline.Fresco;
|
||||
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();
|
||||
//初始化Fresco
|
||||
Fresco.initialize(this);
|
||||
|
||||
// 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 +118,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 +158,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 +177,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 +209,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 +224,4 @@ public class AppController extends Application {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static PushHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,11 +4,14 @@ import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.gamecenter.SplashScreenActivity;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.tencent.stat.StatService;
|
||||
@ -55,18 +58,25 @@ public class AppUncaHandler implements UncaughtExceptionHandler {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Intent intent = new Intent(appController.getApplicationContext(),
|
||||
SplashScreenActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
PendingIntent restartIntent = PendingIntent.getActivity(
|
||||
appController.getApplicationContext(), 0, intent,
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// 退出程序并重启
|
||||
AlarmManager mgr = (AlarmManager) appController
|
||||
.getSystemService(Context.ALARM_SERVICE);
|
||||
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
|
||||
restartIntent); // 1秒钟后重启应用
|
||||
// 防止重复奔溃,导致助手一直重启,20秒内不做处理
|
||||
SharedPreferences sp = appController.getApplicationContext().getSharedPreferences(
|
||||
Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
long time = sp.getLong("last_restart_time", 0);
|
||||
if (System.currentTimeMillis() - time > 20 * 1000) {
|
||||
sp.edit().putLong("last_restart_time", System.currentTimeMillis()).apply();
|
||||
Intent intent = new Intent(appController.getApplicationContext(),
|
||||
SplashScreenActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
PendingIntent restartIntent = PendingIntent.getActivity(
|
||||
appController.getApplicationContext(), 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
// 退出程序并重启
|
||||
AlarmManager mgr = (AlarmManager) appController
|
||||
.getSystemService(Context.ALARM_SERVICE);
|
||||
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
|
||||
restartIntent); // 1秒钟后重启应用
|
||||
}
|
||||
appController.finishActivity();
|
||||
}
|
||||
}
|
||||
@ -78,19 +88,17 @@ public class AppUncaHandler implements UncaughtExceptionHandler {
|
||||
// MTA主动上传错误
|
||||
StatService.reportError(appController.getApplicationContext(), errorMsg);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
// WIFI实时上传错误数据
|
||||
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);
|
||||
DataCollectionManager.onEvent(appController.getApplicationContext(),
|
||||
"error", map, false);
|
||||
map.put("system", android.os.Build.VERSION.SDK_INT + "=" + android.os.Build.VERSION.RELEASE);
|
||||
DataCollectionManager.onEvent(appController.getApplicationContext(), "error", map,
|
||||
NetworkUtils.isWifiConnected(appController.getApplicationContext()));
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss",
|
||||
Locale.getDefault());
|
||||
File file = new File(FileUtils.getLogPath(
|
||||
appController.getApplicationContext(),
|
||||
// 保存到本地
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault());
|
||||
File file = new File(FileUtils.getLogPath(appController.getApplicationContext(),
|
||||
format.format(new Date()) + "_gh_assist" + ".log"));
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
@ -109,6 +117,7 @@ public class AppUncaHandler implements UncaughtExceptionHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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());
|
||||
DialogUtils.showQqSessionDialog(this, null);// 建议用户联系客服
|
||||
} 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());
|
||||
DialogUtils.showQqSessionDialog(this, null);// 建议用户联系客服
|
||||
} 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");
|
||||
}
|
||||
}
|
||||
|
||||
413
app/src/main/java/com/gh/base/DetailActivity.java
Normal file
413
app/src/main/java/com/gh/base/DetailActivity.java
Normal file
@ -0,0 +1,413 @@
|
||||
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.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 String downloadOffText;
|
||||
|
||||
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);
|
||||
if (TextUtils.isEmpty(downloadOffText)) {
|
||||
detail_tv_download.setText("暂无下载");
|
||||
} else {
|
||||
detail_tv_download.setText(downloadOffText);
|
||||
}
|
||||
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.getId(), 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
|
||||
&& !TextUtils.isEmpty(gameEntity.getApk().get(0).getGhVersion())
|
||||
&& !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();
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(getApplicationContext()).get(url);
|
||||
if (downloadEntity != null) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
detail_tv_download.setVisibility(View.GONE);
|
||||
detail_pb_progressbar.setVisibility(View.VISIBLE);
|
||||
detail_tv_per.setVisibility(View.VISIBLE);
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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:
|
||||
case notfound:
|
||||
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)) {
|
||||
Intent intent = new Intent(this, DownloadManagerActivity.class);
|
||||
intent.putExtra("url", gameEntity.getApk().get(0).getUrl());
|
||||
startActivity(intent);
|
||||
} 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(this, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
236
app/src/main/java/com/gh/base/HomeFragment.java
Normal file
236
app/src/main/java/com/gh/base/HomeFragment.java
Normal file
@ -0,0 +1,236 @@
|
||||
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) {
|
||||
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,19 @@
|
||||
package com.gh.common.constant;
|
||||
|
||||
import com.gh.gamecenter.SplashScreenActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public final 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 class Config {
|
||||
|
||||
public static final String HOST = "http://api.ghzhushou.com/v2d1/";
|
||||
public static final String USER_HOST = "http://user.ghzhushou.com/v1d0/";
|
||||
public static final String COMMENT_HOST = "http://comment.ghzhushou.com/v1d0/";
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
24
app/src/main/java/com/gh/common/constant/ItemViewType.java
Normal file
24
app/src/main/java/com/gh/common/constant/ItemViewType.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.gh.common.constant;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/10/16.
|
||||
*/
|
||||
public class ItemViewType {
|
||||
|
||||
public static final int COLUMN_HEADER = 0; // 专题头部布局
|
||||
public static final int GAME_SLIDE = 1; // 滚动图布局
|
||||
public static final int GAME_NORMAL = 2; // 正常游戏布局
|
||||
public static final int GAME_TEST = 3; // 测试游戏布局
|
||||
public static final int GAME_IMAGE = 4; // 游戏大图布局
|
||||
public static final int NEWS_HEADER = 5; // 新闻头部布局
|
||||
public static final int NEWS_TEXT = 6; // 新闻文本布局
|
||||
public static final int NEWS_IMAGE = 7; // 新闻带图布局
|
||||
public static final int NEWS_IMAGE1 = 8; // 新闻带一张小图布局
|
||||
public static final int NEWS_IMAGE2 = 9; // 新闻带三张小图布局
|
||||
public static final int NEWS_IMAGE3 = 10; // 新闻带一张大图布局
|
||||
public static final int NEWS_DIGEST = 11; // 新闻摘要布局
|
||||
public static final int SEARCH_NORMAL = 12; // 搜索正常布局
|
||||
public static final int SEARCH_DELETE = 13; // 清空历史记录布局
|
||||
public static final int LOADING = 14; // 加载布局
|
||||
|
||||
}
|
||||
87
app/src/main/java/com/gh/common/util/BitmapUtils.java
Normal file
87
app/src/main/java/com/gh/common/util/BitmapUtils.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.media.ExifInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/10/21.
|
||||
*/
|
||||
public class BitmapUtils {
|
||||
|
||||
/**
|
||||
* 根据文件路径返回bitmap
|
||||
* @param filepath 文件路径
|
||||
* @param w 宽
|
||||
* @param h 高
|
||||
* @return bitmap
|
||||
*/
|
||||
public static Bitmap getBitmapByFile(String filepath, int w, int h) {
|
||||
try {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
// 设置为ture只获取图片大小
|
||||
options.inJustDecodeBounds = true;
|
||||
options.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
// 返回为空
|
||||
BitmapFactory.decodeFile(filepath, options);
|
||||
int width = options.outWidth;
|
||||
int height = options.outHeight;
|
||||
float scaleWidth = 0.f, scaleHeight = 0.f;
|
||||
if (width > w || height > h) {
|
||||
// 缩放
|
||||
scaleWidth = ((float) width) / w;
|
||||
scaleHeight = ((float) height) / h;
|
||||
}
|
||||
options.inJustDecodeBounds = false;
|
||||
int scale = (int) Math.ceil(Math.max(scaleWidth, scaleHeight));
|
||||
if (scale % 2 == 1) {
|
||||
scale += 1;
|
||||
}
|
||||
options.inSampleSize = scale;
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(filepath, options);
|
||||
bitmap = rotatePicture(filepath, bitmap);
|
||||
if (bitmap != null) {
|
||||
return bitmap;
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap rotatePicture(String path, Bitmap bitmap) {
|
||||
int rotate = 0;
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(path);
|
||||
int orientation = exifInterface.getAttributeInt(
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.ORIENTATION_NORMAL);
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
rotate = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
rotate = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
rotate = 270;
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (rotate != 0) {
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.setRotate(rotate);
|
||||
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
|
||||
bitmap.getHeight(), matrix, true);
|
||||
} else {
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,14 +21,14 @@ public class DataUtils {
|
||||
public static void init(Application application) {
|
||||
//TalkingData
|
||||
//dubug true release false
|
||||
TCAgent.LOG_ON = false;
|
||||
TCAgent.LOG_ON = true;
|
||||
TCAgent.init(application);
|
||||
TCAgent.setReportUncaughtExceptions(true);
|
||||
|
||||
//MTA
|
||||
// 打开debug开关,可查看mta上报日志或错误
|
||||
// dubug true release false
|
||||
StatConfig.setDebugEnable(false);
|
||||
StatConfig.setDebugEnable(true);
|
||||
// 收集未处理的异常
|
||||
StatConfig.setAutoExceptionCaught(true);
|
||||
// 设置数据上报策略
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,15 +1,17 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
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 +28,158 @@ 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;
|
||||
// 网络劫持时 打开QQ客户端,创建临时会话
|
||||
public static void showQqSessionDialog(final Context context, String qq) {
|
||||
if (qq == null) {
|
||||
qq = "2586716223";// 默认客服QQ
|
||||
}
|
||||
final String finalQq = qq;
|
||||
showWarningDialog(context, "警告", "您当前网络环境异常,下载地址可能被运营商恶意替换(网络劫持)" +
|
||||
",如多次下载失败,请联系客服获取正确的下载地址(客服QQ:" + qq + ")"
|
||||
, "取消", "前往QQ", new ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
if (ShareUtils.isQQClientAvailable(context)) {
|
||||
//安装了QQ会直接调用QQ,打开手机QQ进行会话 QQ号:2586716223
|
||||
String str = "mqqwpa://im/chat?chat_type=wpa&uin=" + finalQq + "&version=1&src_type=web&web_src=oicqzone.com";
|
||||
Uri uri = Uri.parse(str);
|
||||
Intent it = new Intent(Intent.ACTION_VIEW, uri);
|
||||
context.startActivity(it);
|
||||
} else {
|
||||
//没有安装QQ 复制账号
|
||||
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setText(finalQq);
|
||||
Utils.toast(context,"已复制" + finalQq);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
|
||||
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
@ -5,7 +5,6 @@ import android.os.Environment;
|
||||
import android.os.StatFs;
|
||||
import android.os.StrictMode;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@ -38,7 +37,11 @@ public class FileUtils {
|
||||
File file = new File(dir + File.separator + TEST_FILE_NAME);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
if (!file.createNewFile()) {
|
||||
// cannot create file
|
||||
Utils.log("cannot create file");
|
||||
dir = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//cannot create file
|
||||
@ -96,21 +99,6 @@ public class FileUtils {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void checkDirExists(String dirName) {
|
||||
File file = Environment.getExternalStorageDirectory();
|
||||
if (file.isDirectory()) {
|
||||
File[] fs = file.listFiles();
|
||||
for (int i = 0; i < fs.length; i++) {
|
||||
if (fs[i].isDirectory()
|
||||
&& fs[i].getName().equalsIgnoreCase(dirName)
|
||||
&& !fs[i].getName().equals(dirName)) {
|
||||
fs[i].delete();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMounted() {
|
||||
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
|
||||
@ -134,15 +122,13 @@ 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;
|
||||
}
|
||||
|
||||
public static String isCanDownload(String size) {
|
||||
public static String isCanDownload(Context context, String size) {
|
||||
String msg = null;
|
||||
String packageSizeStr = "";
|
||||
for (int i = 0; i < size.length(); i++) {
|
||||
@ -154,8 +140,7 @@ public class FileUtils {
|
||||
if (packageSizeStr.length() != 0) {
|
||||
packageSize = Float.valueOf(packageSizeStr);
|
||||
}
|
||||
float freeSpace = getFreeSpaceByPath(Environment
|
||||
.getExternalStorageDirectory().getAbsolutePath());
|
||||
float freeSpace = getFreeSpaceByPath(getDownloadDir(context));
|
||||
if (freeSpace < packageSize) {
|
||||
msg = "手机存储空间不足,无法进行下载!";
|
||||
}
|
||||
@ -168,8 +153,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 +177,7 @@ public class FileUtils {
|
||||
dis.close();
|
||||
}
|
||||
return code;
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
} finally {
|
||||
@ -207,7 +191,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 +204,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 +229,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;
|
||||
/* 从文件读取数据至缓冲区 */
|
||||
int length;
|
||||
// 从文件读取数据至缓冲区
|
||||
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 == HttpURLConnection.HTTP_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", HttpURLConnection.HTTP_OK);
|
||||
return response;
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN) {
|
||||
JSONObject response = new JSONObject(b.toString().trim());
|
||||
response.put("statusCode", HttpURLConnection.HTTP_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,50 @@ 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) {
|
||||
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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,151 +1,161 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.view.View;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.net.Uri;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gh.common.view.CircleImageView;
|
||||
import com.facebook.common.executors.CallerThreadExecutor;
|
||||
import com.facebook.common.references.CloseableReference;
|
||||
import com.facebook.datasource.DataSource;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.drawee.controller.BaseControllerListener;
|
||||
import com.facebook.drawee.controller.ControllerListener;
|
||||
import com.facebook.drawee.drawable.ScalingUtils;
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchy;
|
||||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.facebook.imagepipeline.core.ImagePipeline;
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.facebook.imagepipeline.image.ImageInfo;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.gh.gamecenter.R;
|
||||
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.listener.ImageLoadingListener;
|
||||
|
||||
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;
|
||||
|
||||
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
|
||||
private static ImageUtils singleton;
|
||||
|
||||
public static ImageUtils getInstance(Context context) {
|
||||
if (singleton == null) {
|
||||
synchronized (ImageUtils.class) {
|
||||
if (singleton == null) {
|
||||
singleton = new ImageUtils(context.getApplicationContext(),
|
||||
(int) Runtime.getRuntime().maxMemory() / 10);
|
||||
singleton = new ImageUtils();
|
||||
return singleton;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
private ImageUtils(Context context, int size) {
|
||||
|
||||
options = new DisplayImageOptions.Builder().cacheInMemory(true)
|
||||
.cacheOnDisk(true).considerExifParams(true)
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)
|
||||
// .showImageOnLoading(R.drawable.ocupy)
|
||||
// .showImageForEmptyUri(R.drawable.ocupy)
|
||||
// .showImageOnFail(R.drawable.ocupy)
|
||||
// 自适应图片宽高
|
||||
public void display (String url , final SimpleDraweeView simpleDraweeView, final Context context, final int paddingSize){
|
||||
ControllerListener listener = new BaseControllerListener(){
|
||||
@Override
|
||||
public void onFinalImageSet(String id, Object imageInfo, Animatable animatable) {
|
||||
super.onFinalImageSet(id, imageInfo, animatable);
|
||||
if (imageInfo == null){
|
||||
return;
|
||||
}
|
||||
ImageInfo imageInfo1 = (ImageInfo) imageInfo;
|
||||
int height = imageInfo1.getHeight();
|
||||
int width = imageInfo1.getWidth();
|
||||
int widthPixels = context.getResources().getDisplayMetrics().widthPixels - DisplayUtils.dip2px(context,paddingSize);
|
||||
float index = (float) height / (float) width;
|
||||
int newHeight = (int)(index * widthPixels);
|
||||
ViewGroup.LayoutParams layoutParams = simpleDraweeView.getLayoutParams();
|
||||
layoutParams.height = newHeight;
|
||||
simpleDraweeView.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntermediateImageSet(String id, Object imageInfo) {
|
||||
super.onIntermediateImageSet(id, imageInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntermediateImageFailed(String id, Throwable throwable) {
|
||||
super.onIntermediateImageFailed(id, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String id, Throwable throwable) {
|
||||
super.onFailure(id, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRelease(String id) {
|
||||
super.onRelease(id);
|
||||
}
|
||||
};
|
||||
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setUri(url)
|
||||
.setControllerListener(listener)
|
||||
.build();
|
||||
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
|
||||
context).writeDebugLogs().build();
|
||||
simpleDraweeView.setController(controller);
|
||||
|
||||
ImageLoader.getInstance().init(config);
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
}
|
||||
|
||||
public void displayFile(String url, ImageView imageView) {
|
||||
imageLoader.displayImage(url, imageView, options,
|
||||
new ImageLoadingListener() {
|
||||
//设置缩放类型,设置按压状态下的叠加图
|
||||
public void display (String url , SimpleDraweeView simpleDraweeView, ScalingUtils.ScaleType scaleType, Context context){
|
||||
GenericDraweeHierarchyBuilder builder =
|
||||
new GenericDraweeHierarchyBuilder(context.getResources());
|
||||
GenericDraweeHierarchy hierarchy = builder
|
||||
.setFadeDuration(500)
|
||||
.setPressedStateOverlay(new ColorDrawable(context.getResources().getColor(R.color.pressed_bg)))
|
||||
.setPlaceholderImage(R.drawable.ocupy2, ScalingUtils.ScaleType.CENTER)
|
||||
.setBackground(new ColorDrawable(Color.parseColor("#ececec")))
|
||||
.setActualImageScaleType(scaleType)
|
||||
.build();
|
||||
simpleDraweeView.setHierarchy(hierarchy);
|
||||
simpleDraweeView.setImageURI(url);
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String arg0, View arg1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String arg0, View view,
|
||||
Bitmap arg2) {
|
||||
AlphaAnimation animation = new AlphaAnimation(0f, 1f);
|
||||
animation.setDuration(500);
|
||||
view.startAnimation(animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String arg0, View arg1,
|
||||
FailReason arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted(String arg0, View arg1) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, int drawable) {
|
||||
display(url, imageView, drawable, ScaleType.FIT_XY, null);
|
||||
//设置占位符
|
||||
public void display (String url , SimpleDraweeView simpleDraweeView, int placeholderImage, Context context){
|
||||
|
||||
GenericDraweeHierarchyBuilder builder =
|
||||
new GenericDraweeHierarchyBuilder(context.getResources());
|
||||
GenericDraweeHierarchy hierarchy = builder
|
||||
.setFadeDuration(500)
|
||||
.setPressedStateOverlay(new ColorDrawable(context.getResources().getColor(R.color.pressed_bg)))
|
||||
.setBackground(new ColorDrawable(Color.parseColor("#ececec")))
|
||||
.setPlaceholderImage(placeholderImage)
|
||||
.build();
|
||||
simpleDraweeView.setHierarchy(hierarchy);
|
||||
simpleDraweeView.setImageURI(url);
|
||||
|
||||
}
|
||||
|
||||
public void display(final String url, final ImageView imageView,
|
||||
final int drawable, final ScaleType scaleType,
|
||||
final OnLoadingCompleteListener listener) {
|
||||
imageLoader.displayImage(url, imageView, options,
|
||||
new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view,
|
||||
Bitmap loadedImage) {
|
||||
if (imageView instanceof CircleImageView) {
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
imageView.setScaleType(scaleType);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onLoadingComplete();
|
||||
}
|
||||
}
|
||||
//图片下载监听和设置低高分辨率图片
|
||||
public void display (String url, String lowUrl, SimpleDraweeView simpleDraweeView, ControllerListener listener){
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted(String imageUri, View view) {
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
imageView.setImageResource(drawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String imageUri, View view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view,
|
||||
FailReason reason) {
|
||||
|
||||
}
|
||||
});
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setImageRequest(ImageRequest.fromUri(url))
|
||||
.setControllerListener(listener)
|
||||
.setLowResImageRequest(ImageRequest.fromUri(lowUrl)) //低分辨率图片
|
||||
.build();
|
||||
simpleDraweeView.setController(controller);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, null);
|
||||
public void display (String url, SimpleDraweeView simpleDraweeView, ControllerListener listener){
|
||||
|
||||
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
||||
.setImageRequest(ImageRequest.fromUri(url))
|
||||
.setControllerListener(listener)
|
||||
.build();
|
||||
simpleDraweeView.setController(controller);
|
||||
}
|
||||
|
||||
public void display(String url, ImageView imageView) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, null);
|
||||
}
|
||||
//获取bitmap
|
||||
public void display (String url, BaseBitmapDataSubscriber dataSubscriber, Context context){
|
||||
ImageRequest imageRequest = ImageRequestBuilder
|
||||
.newBuilderWithSource(Uri.parse(url))
|
||||
.setProgressiveRenderingEnabled(true)
|
||||
.build();
|
||||
|
||||
public void display(String url, ImageView imageView, ScaleType scaleType, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, scaleType, listener);
|
||||
}
|
||||
ImagePipeline imagePipeline = Fresco.getImagePipeline();
|
||||
DataSource<CloseableReference<CloseableImage>>
|
||||
dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
|
||||
dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
|
||||
|
||||
public void display(String url, ImageView imageView, OnLoadingCompleteListener listener) {
|
||||
display(url, imageView, R.drawable.ocupy, ScaleType.FIT_XY, listener);
|
||||
}
|
||||
|
||||
public interface OnLoadingCompleteListener {
|
||||
void onLoadingComplete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
85
app/src/main/java/com/gh/common/util/NotificationUtils.java
Normal file
85
app/src/main/java/com/gh/common/util/NotificationUtils.java
Normal file
@ -0,0 +1,85 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/10/10.
|
||||
*/
|
||||
public class NotificationUtils {
|
||||
|
||||
public static void showDownloadDoneNotification(Context context, DownloadEntity downloadEntity, int flag) {
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("path", downloadEntity.getPath());
|
||||
intent.setAction("com.gh.gamecenter.INSTALL");
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, flag,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
String text;
|
||||
String title;
|
||||
if (downloadEntity.isPluggable()) {
|
||||
text = "下载完成,点击继续插件化";
|
||||
title = downloadEntity.getName() + "-"
|
||||
+ PlatformUtils.getInstance(context).getPlatformName(downloadEntity.getPlatform());
|
||||
} else {
|
||||
if (downloadEntity.isPlugin()) {
|
||||
text = downloadEntity.getName() + "-"
|
||||
+ PlatformUtils.getInstance(context).getPlatformName(downloadEntity.getPlatform()) + " 下载完成";
|
||||
} else {
|
||||
text = downloadEntity.getName() + " 下载完成";
|
||||
}
|
||||
title = "点击立即安装";
|
||||
}
|
||||
Notification notification = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.logo)
|
||||
.setTicker(text)
|
||||
.setContentTitle(title)
|
||||
.setContentText(text)
|
||||
.setContentIntent(pendingIntent).build();
|
||||
// notification.defaults = Notification.DEFAULT_SOUND;// 添加系统默认声音
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL; // // FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。
|
||||
nManager.notify(flag, notification);
|
||||
}
|
||||
|
||||
public static void showDownloadingNotification(Context context) {
|
||||
int downloadingSize = 0;
|
||||
for (DownloadEntity entity : DownloadManager.getInstance(context).getAll()) {
|
||||
if (entity.getStatus().equals(DownloadStatus.downloading)
|
||||
|| entity.getStatus().equals(DownloadStatus.waiting)
|
||||
|| entity.getStatus().equals(DownloadStatus.pause)
|
||||
|| entity.getStatus().equals(DownloadStatus.timeout)
|
||||
|| entity.getStatus().equals(DownloadStatus.neterror)) {
|
||||
downloadingSize++;
|
||||
}
|
||||
}
|
||||
if (downloadingSize == 0) {
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nManager.cancel(0x123);
|
||||
} else {
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("com.gh.gamecenter.DOWNLOAD");
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0x123,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Notification notification = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.logo)
|
||||
.setTicker("你有" + downloadingSize + "个游戏正在下载中")
|
||||
.setContentTitle("点击查看详情")
|
||||
.setContentText("你有" + downloadingSize + "个游戏正在下载中")
|
||||
.setContentIntent(pendingIntent).build();
|
||||
// notification.defaults = Notification.DEFAULT_SOUND;// 添加系统默认声音
|
||||
notification.flags |= Notification.FLAG_NO_CLEAR; // 通知无法手动清除
|
||||
nManager.notify(0x123, notification);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -9,18 +9,14 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.Signature;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
@ -31,65 +27,6 @@ public class PackageUtils {
|
||||
|
||||
public static final String publicKey = "OpenSSLRSAPublicKey{modulus=a8c4bb5748fec8d5c35db1a7a182d41ba4721a91131a417330af79ef4ddb43f9fa0ff4907b0a613bfe152de0ed8fc1b2e6f94a908aa98a5f7adc1ce814ba7ec919d75d9910bdfd8649b4789da6a90ffb61f0d23ac4f828a78fcd0d6f6120c1c43c1f87f7498a89eb40ca8e32dfc2f9d5c10d612b95192870223674e241e53305abf320d7eed76ded398778576e4db7b17b3bc6a792f13de5e43a6a5fae4276c73e6990ce97f68dff0ec16fc9594f175c8d49cd0d7877340d9de60942ca0efc737e50b6c295dfe0713e4532b4e810e1ea11b702b4a27753e41559cbceb247e7f044ec4e3ab2e8bccd8b9fd71286e63307550bcde86deee95adb8133076269135b,publicExponent=10001}";
|
||||
|
||||
/*
|
||||
* 根据apk路径,获取apk的签名信息,耗时
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static String getApkSignatureByPath(Context context, String path) {
|
||||
String PATH_PackageParser = "android.content.pm.PackageParser";
|
||||
try {
|
||||
// apk包的文件路径
|
||||
// 这是一个Package 解释器, 是隐藏的
|
||||
// 构造函数的参数只有一个, apk文件的路径
|
||||
// PackageParser packageParser = new PackageParser(apkPath);
|
||||
Class pkgParserCls = Class.forName(PATH_PackageParser);
|
||||
Class[] typeArgs = new Class[1];
|
||||
typeArgs[0] = String.class;
|
||||
Constructor pkgParserCt = pkgParserCls.getConstructor(typeArgs);
|
||||
Object[] valueArgs = new Object[1];
|
||||
valueArgs[0] = path;
|
||||
Object pkgParser = pkgParserCt.newInstance(valueArgs);
|
||||
// 这个是与显示有关的, 里面涉及到一些像素显示等等, 我们使用默认的情况
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
metrics.setToDefaults();
|
||||
// PackageParser.Package mPkgInfo = packageParser.parsePackage(new
|
||||
// File(apkPath), apkPath,
|
||||
// metrics, 0);
|
||||
typeArgs = new Class[4];
|
||||
typeArgs[0] = File.class;
|
||||
typeArgs[1] = String.class;
|
||||
typeArgs[2] = DisplayMetrics.class;
|
||||
typeArgs[3] = Integer.TYPE;
|
||||
Method pkgParser_parsePackageMtd = pkgParserCls.getDeclaredMethod(
|
||||
"parsePackage", typeArgs);
|
||||
valueArgs = new Object[4];
|
||||
valueArgs[0] = new File(path);
|
||||
valueArgs[1] = path;
|
||||
valueArgs[2] = metrics;
|
||||
valueArgs[3] = PackageManager.GET_SIGNATURES;
|
||||
Object pkgParserPkg = pkgParser_parsePackageMtd.invoke(pkgParser,
|
||||
valueArgs);
|
||||
|
||||
typeArgs = new Class[2];
|
||||
typeArgs[0] = pkgParserPkg.getClass();
|
||||
typeArgs[1] = Integer.TYPE;
|
||||
Method pkgParser_collectCertificatesMtd = pkgParserCls
|
||||
.getDeclaredMethod("collectCertificates", typeArgs);
|
||||
valueArgs = new Object[2];
|
||||
valueArgs[0] = pkgParserPkg;
|
||||
valueArgs[1] = PackageManager.GET_SIGNATURES;
|
||||
pkgParser_collectCertificatesMtd.invoke(pkgParser, valueArgs);
|
||||
// 应用程序信息包, 这个公开的, 不过有些函数, 变量没公开
|
||||
Field packageInfoFld = pkgParserPkg.getClass().getDeclaredField(
|
||||
"mSignatures");
|
||||
Signature[] info = (Signature[]) packageInfoFld.get(pkgParserPkg);
|
||||
return parseSignature(info[0].toByteArray())[0];
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据路径,获取apk的包名
|
||||
*/
|
||||
@ -104,6 +41,9 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取meta-data
|
||||
*/
|
||||
public static Object getMetaData(Context context, String packageName, String name) {
|
||||
try {
|
||||
Bundle metaDate = context.getPackageManager().getApplicationInfo(
|
||||
@ -120,8 +60,7 @@ public class PackageUtils {
|
||||
/*
|
||||
* 根据包名,获取apk的签名信息
|
||||
*/
|
||||
public static String getApkSignatureByPackageName(Context context,
|
||||
String packageName) {
|
||||
public static String getApkSignatureByPackageName(Context context, String packageName) {
|
||||
try {
|
||||
PackageInfo packageInfo = context.getPackageManager()
|
||||
.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
|
||||
@ -133,6 +72,95 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断是否可以更新
|
||||
*/
|
||||
public static boolean isCanUpdate(Context context, GameUpdateEntity gameUpdateEntity) {
|
||||
// 判断是否gh_version是否相同
|
||||
String gh_version = (String) PackageUtils.getMetaData(
|
||||
context, 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(
|
||||
context, gameUpdateEntity.getPackageName());
|
||||
if (version != null && version.equals(gameUpdateEntity.getVersion())) {
|
||||
// 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断是否是插件包
|
||||
*/
|
||||
public static boolean isSignature(Context context, String packageName) {
|
||||
String signature = getApkSignatureByPackageName(context, packageName);
|
||||
if (publicKey.equals(signature)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据apk路径,获取apk包名、签名 根据包名 判断 是否已安装游戏 根据签名 判断 是否一致
|
||||
*/
|
||||
public static boolean isCanLaunchSetup(Context context, String path) {
|
||||
String packageName = getPackageNameByPath(context, path);
|
||||
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return true;
|
||||
}
|
||||
boolean isContain = com.gh.gamecenter.manager.PackageManager.isInstalled(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;
|
||||
}
|
||||
|
||||
/*
|
||||
* 解析签名
|
||||
*/
|
||||
@ -165,6 +193,9 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取apk的版本
|
||||
*/
|
||||
public static String getVersionByPackage(Context context, String packageName) {
|
||||
try {
|
||||
return context.getPackageManager().getPackageInfo(packageName,
|
||||
@ -175,11 +206,13 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取所有已安装的软件的包名、版本(非系统应用)
|
||||
*/
|
||||
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) {
|
||||
@ -193,6 +226,9 @@ public class PackageUtils {
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* 启动应用
|
||||
*/
|
||||
public static void launchApplicationByPackageName(Context context,
|
||||
String packageName) {
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(
|
||||
@ -224,33 +260,8 @@ public class PackageUtils {
|
||||
* 根据包名,判断是否已安装该游戏
|
||||
*/
|
||||
public static boolean isInstalled(Context context, String packageName) {
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(
|
||||
packageName);
|
||||
if (intent == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ArrayMap<String, Boolean> map;
|
||||
|
||||
public static boolean isContain(Context context, String packageName) {
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return false;
|
||||
}
|
||||
if (map == null) {
|
||||
map = new ArrayMap<String, Boolean>();
|
||||
List<PackageInfo> infos = context.getPackageManager()
|
||||
.getInstalledPackages(0);
|
||||
for (PackageInfo info : infos) {
|
||||
map.put(info.packageName, true);
|
||||
}
|
||||
}
|
||||
Boolean b = map.get(packageName);
|
||||
if (b != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
|
||||
return intent != null;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -277,13 +288,4 @@ public class PackageUtils {
|
||||
return installIntent;
|
||||
}
|
||||
|
||||
public static String getInstalledApkPath(Context context, String packageName) {
|
||||
try {
|
||||
return context.getPackageManager().getApplicationInfo(packageName,
|
||||
0).sourceDir;
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,19 +11,17 @@ 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;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
@ -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();
|
||||
@ -55,7 +53,7 @@ public class PlatformUtils {
|
||||
}
|
||||
|
||||
private void initMap() {
|
||||
ArrayMap<String, Integer> platformPicMap = new ArrayMap<String, Integer>();
|
||||
ArrayMap<String, Integer> platformPicMap = new ArrayMap<>();
|
||||
platformPicMap.put("360", R.drawable.platform_360);
|
||||
platformPicMap.put("37wan", R.drawable.platform_37);
|
||||
platformPicMap.put("91", R.drawable.platform_91);
|
||||
@ -74,7 +72,7 @@ public class PlatformUtils {
|
||||
platformPicMap.put("vivo", R.drawable.platform_vivo);
|
||||
platformPicMap.put("wdj", R.drawable.platform_wdj);
|
||||
|
||||
ArrayMap<String, String> platformColorMap = new ArrayMap<String, String>();
|
||||
ArrayMap<String, String> platformColorMap = new ArrayMap<>();
|
||||
platformColorMap.put("360", "#218FA4");
|
||||
platformColorMap.put("37wan", "#F5BD20");
|
||||
platformColorMap.put("91", "#6A63CB");
|
||||
@ -93,8 +91,8 @@ public class PlatformUtils {
|
||||
platformColorMap.put("vivo", "#3FA5E3");
|
||||
platformColorMap.put("wdj", "#5ABA3F");
|
||||
|
||||
ArrayMap<String, String> platformMap = new ArrayMap<String, String>();
|
||||
ArrayMap<String, String> platformPicUrlMap = new ArrayMap<String, String>();
|
||||
ArrayMap<String, String> platformMap = new ArrayMap<>();
|
||||
ArrayMap<String, String> platformPicUrlMap = new ArrayMap<>();
|
||||
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||
"gh_platform", Context.MODE_PRIVATE);
|
||||
@ -104,7 +102,7 @@ public class PlatformUtils {
|
||||
try {
|
||||
properties
|
||||
.load(context.getAssets().open("platform.properties"));
|
||||
Set<String> pset = new HashSet<String>();
|
||||
Set<String> pset = new HashSet<>();
|
||||
for (Object object : properties.keySet()) {
|
||||
platformMap.put(object.toString(),
|
||||
(String) properties.get(object));
|
||||
@ -118,7 +116,7 @@ public class PlatformUtils {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
ArrayList<String> urls = new ArrayList<String>();
|
||||
ArrayList<String> urls = new ArrayList<>();
|
||||
for (String str : set) {
|
||||
String[] platform = str.split("=");
|
||||
platformMap.put(platform[0], platform[1]);
|
||||
@ -177,7 +175,7 @@ public class PlatformUtils {
|
||||
+ url.substring(url.lastIndexOf("/") + 1);
|
||||
try {
|
||||
int code = FileUtils.downloadFile(url, savePath);
|
||||
if (code == HttpStatus.SC_OK) {
|
||||
if (code == HttpURLConnection.HTTP_OK) {
|
||||
success++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -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"));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -201,30 +199,24 @@ public class PlatformUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayMap<String, String> getPlatformMap() {
|
||||
return platformMap;
|
||||
}
|
||||
|
||||
public String getPlatformColor(String platform) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)
|
||||
|| "local_plugin".equals(platform)) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)) {
|
||||
return "#BB3D42";
|
||||
}
|
||||
String color = platformColorMap.get(platform);
|
||||
if (color != null) {
|
||||
return color;
|
||||
}
|
||||
return "#1BA4FC";
|
||||
return "#00B7FA";
|
||||
}
|
||||
|
||||
public int getPlatformPic(String platform) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)
|
||||
|| "local_plugin".equals(platform)) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)) {
|
||||
return R.drawable.platform_gf;
|
||||
}
|
||||
Integer id = platformPicMap.get(platform);
|
||||
if (id != null) {
|
||||
return id.intValue();
|
||||
return id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -244,7 +236,7 @@ public class PlatformUtils {
|
||||
}
|
||||
}
|
||||
if (path == null && !isCheck) {
|
||||
ArrayList<String> urls = new ArrayList<String>();
|
||||
ArrayList<String> urls = new ArrayList<>();
|
||||
for (String value : platformPicUrlMap.values()) {
|
||||
urls.add(value);
|
||||
}
|
||||
@ -255,8 +247,7 @@ public class PlatformUtils {
|
||||
}
|
||||
|
||||
public String getPlatformName(String platform) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)
|
||||
|| "local_plugin".equals(platform)) {
|
||||
if ("".equals(platform) || "官方版".equals(platform)) {
|
||||
return "官方版";
|
||||
}
|
||||
return platformMap.get(platform);
|
||||
@ -270,32 +261,25 @@ public class PlatformUtils {
|
||||
}
|
||||
isUpdate = true;
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST
|
||||
+ "v1d45/support/setting/platform",
|
||||
Constants.PLATFORM_CD),
|
||||
Config.HOST + "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 +291,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);
|
||||
|
||||
526
app/src/main/java/com/gh/common/util/ShareUtils.java
Normal file
526
app/src/main/java/com/gh/common/util/ShareUtils.java
Normal file
@ -0,0 +1,526 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
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.facebook.common.references.CloseableReference;
|
||||
import com.facebook.datasource.DataSource;
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.gh.gamecenter.R;
|
||||
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 java.util.List;
|
||||
|
||||
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).display(iconUrl, new BaseBitmapDataSubscriber() {
|
||||
@Override
|
||||
protected void onNewResultImpl(Bitmap bitmap) {
|
||||
Bitmap compressBp = compressBitmap(bitmap);
|
||||
Bitmap resultBp = addBackGround(compressBp);
|
||||
msg.thumbData = Util.bmpToByteArray(resultBp, true);
|
||||
api.sendReq(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
|
||||
Utils.log("分享获取bitmap失败");
|
||||
}
|
||||
}, context);
|
||||
}
|
||||
|
||||
//添加背景,防止图片格式为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, "分享已取消");
|
||||
}
|
||||
};
|
||||
|
||||
//检查是否安装手机QQ
|
||||
public static boolean isQQClientAvailable(Context context){
|
||||
final PackageManager packageManager = context.getPackageManager();
|
||||
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
|
||||
if (pinfo != null) {
|
||||
for (int i = 0; i < pinfo.size(); i++) {
|
||||
String pn = pinfo.get(i).packageName; if (pn.equals("com.tencent.mobileqq")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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,109 @@ 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
|
||||
|
||||
public static void initMap() {
|
||||
initIntervalMap();
|
||||
initCDMap();
|
||||
}
|
||||
|
||||
private static void initIntervalMap() {
|
||||
intervalMap = new ArrayMap<>();
|
||||
intervalMap.put("^" + Config.HOST + "index/slides" + "$", 5);
|
||||
intervalMap.put("^" + Config.HOST + "game/chajian" + "$", 10);
|
||||
intervalMap.put("^" + Config.HOST + "game/tuijian" + "$", 15);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/detail" + "$", 20);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/digest" + "$", 25);
|
||||
intervalMap.put("^" + Config.HOST + "game/remenkapai" + "$", 30);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", 35);
|
||||
intervalMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", 40);
|
||||
intervalMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", 45);
|
||||
intervalMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", 50);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/digest" + "$", 55);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/detail" + "$", 60);
|
||||
intervalMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", 65);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", 70);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", 75);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", 80);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", 85);
|
||||
intervalMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", 90);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", 95);
|
||||
intervalMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", 100);
|
||||
intervalMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", 105);
|
||||
intervalMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", 110);
|
||||
intervalMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", 115);
|
||||
intervalMap.put("^" + Config.HOST + "support/setting/platform" + "$", 120);
|
||||
intervalMap.put("^" + Config.HOST + "update/package/.+" + "$", 125);
|
||||
intervalMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", 130);
|
||||
}
|
||||
|
||||
private static void initCDMap() {
|
||||
cdMap = new ArrayMap<>();
|
||||
cdMap.put("^" + Config.HOST + "index/slides" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/chajian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/tuijian" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/detail" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/remenkapai" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news_digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/column/.+\\?page=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/package/.+/game/digest" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/danjiyouxi\\?limit=20\\&offset=.+" + "$", Constants.GAME_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/digest" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/detail" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news/.+/suggestion" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=3" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/zixun\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/yuanchuang\\?limit=10\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "news\\?type_group=.+\\&offset=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?key=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/news\\?limit=20\\&offset=.+\\&type=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "zixun/guanzhu\\?game_id=.+\\&limit=20\\&offset=.+" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/news\\?game_id=.+\\&keyword=.+\\&page=.+\\&limit=20" + "$", Constants.NEWS_CD);
|
||||
cdMap.put("^" + Config.HOST + "search/game\\?keyword=.+" + "$", Constants.SEARCH_CD);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/platform" + "$", Constants.PLATFORM_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "update/game/.+/package/.+" + "$", Constants.UPDATE_CD);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "device/.+/concern/.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "stat/download" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "disclaimer" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "search/game/default" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/upgrade\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/time/current" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/setting/ui" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/download_status\\?version=.+\\&channel=.+" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/suggestion" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "game/.+/serverInfo" + "$", 0);
|
||||
cdMap.put("^" + Config.HOST + "support/package/unused\\?skip=.+" + "$", 0);
|
||||
}
|
||||
|
||||
private static ArrayMap<String, Integer> getIntervalMap() {
|
||||
if (intervalMap == null) {
|
||||
intervalMap = new ArrayMap<>();
|
||||
}
|
||||
return intervalMap;
|
||||
}
|
||||
|
||||
private static ArrayMap<String, Integer> getCdMap() {
|
||||
if (cdMap == null) {
|
||||
cdMap = new ArrayMap<>();
|
||||
}
|
||||
return cdMap;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据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);
|
||||
}
|
||||
long base = BASE;
|
||||
for (String key : map.keySet()){
|
||||
for (String key : getIntervalMap().keySet()){
|
||||
if (Pattern.matches(key, url)) {
|
||||
Utils.log("url add base = " + url);
|
||||
base += map.get(key);
|
||||
base += getIntervalMap().get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -59,7 +127,20 @@ public class TimestampUtils {
|
||||
/*
|
||||
* 为url添加timestamp
|
||||
*/
|
||||
public static String addTimestamp(String url, int cd) {
|
||||
public static String addTimestamp(String url) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return url;
|
||||
}
|
||||
int cd = 0;
|
||||
for (String key : getCdMap().keySet()){
|
||||
if (Pattern.matches(key, url)) {
|
||||
cd = getCdMap().get(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cd == 0) {
|
||||
return url;
|
||||
}
|
||||
if (url.contains("?")) {
|
||||
String u = url + "×tamp=" + getTimestamp(url, cd);
|
||||
Utils.log("url = " + u);
|
||||
@ -70,7 +151,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,79 @@ 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 = Config.USER_HOST + "device/register";
|
||||
try {
|
||||
JSONObject body = new JSONObject(params);
|
||||
HttpURLConnection 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 +113,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 = Config.USER_HOST + "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 +151,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 +167,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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,14 +26,12 @@ public class TrafficUtils {
|
||||
synchronized (TrafficUtils.class) {
|
||||
if (instance == null) {
|
||||
instance = new TrafficUtils(context);
|
||||
if (update)
|
||||
instance.update();
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (update)
|
||||
if (update) {
|
||||
instance.update();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -47,9 +45,7 @@ public class TrafficUtils {
|
||||
// 获取所有的安装在手机上的应用软件的信息,并且获取这些软件里面的权限信息
|
||||
PackageManager pm = context.getPackageManager();// 获取系统应用包管理
|
||||
// 获取每个包内的androidmanifest.xml信息,它的权限等等
|
||||
List<PackageInfo> pinfos = pm
|
||||
.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES
|
||||
| PackageManager.GET_PERMISSIONS);
|
||||
List<PackageInfo> pinfos = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
|
||||
// 遍历每个应用包信息
|
||||
for (PackageInfo info : pinfos) {
|
||||
// 请求每个程序包对应的androidManifest.xml里面的权限
|
||||
@ -64,9 +60,7 @@ public class TrafficUtils {
|
||||
long rx = TrafficStats.getUidRxBytes(uId);
|
||||
// 如果返回-1,代表不支持使用该方法,注意必须是2.2以上的
|
||||
long tx = TrafficStats.getUidTxBytes(uId);
|
||||
if (rx < 0 || tx < 0) {
|
||||
continue;
|
||||
} else {
|
||||
if (rx >= 0 && tx >= 0) {
|
||||
db.update(info.packageName, rx + tx);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,29 +1,48 @@
|
||||
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;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean DEBUG = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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,32 +6,31 @@ 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,
|
||||
new GestureDetector.SimpleOnGestureListener() {
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
|
||||
if (listener != null) {
|
||||
listener.onSingleTap();
|
||||
}
|
||||
return super.onSingleTapUp(e);
|
||||
}
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
if (listener != null) {
|
||||
listener.onSingleTap();
|
||||
}
|
||||
return super.onSingleTapUp(e);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void setOnSingleTapListener(OnSingleTapListener listener) {
|
||||
@ -5,25 +5,56 @@ import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class Gh_ViewPager extends ViewPager {
|
||||
|
||||
private boolean mChildIsBeingDragged=false;//当前子控件是否处理拖动状态
|
||||
|
||||
public Gh_ViewPager(Context context) {
|
||||
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public Gh_ViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
getChildAt(i).dispatchTouchEvent(event);
|
||||
}
|
||||
// for (int i = 0; i < getChildCount(); i++) {
|
||||
// getChildAt(i).dispatchTouchEvent(event);
|
||||
// }
|
||||
return super.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if(mChildIsBeingDragged){
|
||||
return false;
|
||||
}
|
||||
|
||||
//指针索引超出范围异常
|
||||
try {
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void onEvent(EBReuse reuse) {
|
||||
if ("isStopMove".equals(reuse.getType())) {
|
||||
mChildIsBeingDragged = false;
|
||||
}
|
||||
if ("isStartove".equals(reuse.getType())){
|
||||
mChildIsBeingDragged = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestory (){
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -1,91 +0,0 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
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 MyGame_LinearLayout extends LinearLayout {
|
||||
|
||||
private LinearLayout mygame_ll;
|
||||
private RecyclerView mygame_rv_show;
|
||||
|
||||
private int height;
|
||||
private int distance;
|
||||
private int total;
|
||||
|
||||
private int position;
|
||||
|
||||
Runnable show = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LayoutParams lparams = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, height);
|
||||
lparams.height = mygame_ll.getHeight() + distance;
|
||||
if (lparams.height > total) {
|
||||
lparams.height = total;
|
||||
}
|
||||
mygame_ll.setLayoutParams(lparams);
|
||||
invalidate();
|
||||
if (lparams.height < total) {
|
||||
postDelayed(show, 10);
|
||||
} else {
|
||||
EventBus.getDefault().post(new EBShowDone("我的游戏", position));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Runnable hide = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LayoutParams lparams = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT, height);
|
||||
lparams.height = mygame_ll.getHeight() - distance;
|
||||
if (lparams.height < height) {
|
||||
lparams.height = height;
|
||||
}
|
||||
mygame_ll.setLayoutParams(lparams);
|
||||
invalidate();
|
||||
if (lparams.height > height) {
|
||||
postDelayed(hide, 10);
|
||||
} else {
|
||||
mygame_rv_show.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public MyGame_LinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
height = DisplayUtils.dip2px(getContext(), 66);
|
||||
distance = DisplayUtils.dip2px(getContext(), 5);
|
||||
total = DisplayUtils.dip2px(getContext(), 136);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
|
||||
super.onAttachedToWindow();
|
||||
mygame_rv_show = (RecyclerView) findViewById(R.id.mygame_rv_show);
|
||||
mygame_ll = (LinearLayout) findViewById(R.id.mygame_ll);
|
||||
}
|
||||
|
||||
public void showRecyclerView(int position) {
|
||||
this.position = position;
|
||||
mygame_rv_show.setVisibility(View.VISIBLE);
|
||||
removeCallbacks(hide);
|
||||
post(show);
|
||||
}
|
||||
|
||||
public void hideRecyclerView() {
|
||||
removeCallbacks(show);
|
||||
post(hide);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/10/11.
|
||||
*/
|
||||
public class RecyclerViewExtended extends RecyclerView {
|
||||
|
||||
public RecyclerViewExtended(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public RecyclerViewExtended(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public RecyclerViewExtended(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
private OnDispatchTouchListener mListener;
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (mListener != null) {
|
||||
mListener.onDispatch(this, ev);
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
public void setOnDispatchTouchListener(OnDispatchTouchListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public interface OnDispatchTouchListener {
|
||||
void onDispatch(View v, MotionEvent event);
|
||||
}
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
279
app/src/main/java/com/gh/common/view/ZoomSimpleDraweeView.java
Normal file
279
app/src/main/java/com/gh/common/view/ZoomSimpleDraweeView.java
Normal file
@ -0,0 +1,279 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/10/26.
|
||||
*/
|
||||
public class ZoomSimpleDraweeView extends SimpleDraweeView {
|
||||
private ScaleGestureDetector mScaleDetector;
|
||||
private GestureDetector mGestureDetector;
|
||||
|
||||
private float mCurrentScale = 1f;
|
||||
private Matrix mCurrentMatrix;
|
||||
private setOnSingleClickListener mClickListener;
|
||||
|
||||
private float imgagePro = -1; // 图片宽高比
|
||||
|
||||
public ZoomSimpleDraweeView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public ZoomSimpleDraweeView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public ZoomSimpleDraweeView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mCurrentMatrix = new Matrix();
|
||||
|
||||
ScaleGestureDetector.OnScaleGestureListener scaleListener = new ScaleGestureDetector
|
||||
.SimpleOnScaleGestureListener() {
|
||||
|
||||
@Override
|
||||
public boolean onScale(ScaleGestureDetector detector) {
|
||||
float scaleFactor = detector.getScaleFactor();
|
||||
if (mCurrentScale < 4f || detector.getScaleFactor() < 1f){
|
||||
mCurrentScale *= scaleFactor;
|
||||
mCurrentMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
|
||||
invalidate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScaleEnd(ScaleGestureDetector detector) {
|
||||
super.onScaleEnd(detector);
|
||||
|
||||
if (mCurrentScale < 1f) {
|
||||
reset();
|
||||
}
|
||||
checkBorder();
|
||||
}
|
||||
|
||||
};
|
||||
mScaleDetector = new ScaleGestureDetector(getContext(), scaleListener);
|
||||
|
||||
GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
if (mClickListener != null) {
|
||||
mClickListener.onClick();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||
if (mCurrentScale > 1f) {
|
||||
mCurrentMatrix.postTranslate(-distanceX, -distanceY);
|
||||
invalidate();
|
||||
checkBorder();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
final float x = e.getX();
|
||||
final float y = e.getY();
|
||||
float scaleSize ; //扩大或缩小的倍数
|
||||
|
||||
if (mCurrentScale > 1.5f){ //缩小时直接回到原画大小
|
||||
scaleSize = 0.5f;
|
||||
ZoomSimpleDraweeView.this.post(new AutoScaleRunnable(mCurrentScale * scaleSize, getWidth() / 2f, getHeight() / 2f, false));
|
||||
} else {
|
||||
scaleSize = 2.0f;
|
||||
ZoomSimpleDraweeView.this.post(new AutoScaleRunnable(mCurrentScale * scaleSize, x, y, true));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
|
||||
return super.onSingleTapUp(e);
|
||||
}
|
||||
};
|
||||
mGestureDetector = new GestureDetector(getContext(), gestureListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查图片边界是否移到view以内
|
||||
* 目的是让图片边缘不要移动到view里面
|
||||
*/
|
||||
private void checkBorder() {
|
||||
RectF rectF = getDisplayRect(mCurrentMatrix);
|
||||
boolean reset = false;
|
||||
float dx = 0;
|
||||
float dy = 0;
|
||||
|
||||
|
||||
if (rectF.left > 0) {
|
||||
dx = getLeft() - rectF.left;
|
||||
reset = true;
|
||||
}
|
||||
if (rectF.top > 0) {
|
||||
dy = getTop() - rectF.top;
|
||||
reset = true;
|
||||
}
|
||||
if (rectF.right < getRight()) {
|
||||
dx = getRight() - rectF.right;
|
||||
reset = true;
|
||||
}
|
||||
if (rectF.bottom < getHeight()) {
|
||||
dy = getHeight() - rectF.bottom;
|
||||
reset = true;
|
||||
}
|
||||
if (reset) {
|
||||
mCurrentMatrix.postTranslate(dx, dy);
|
||||
invalidate();
|
||||
}
|
||||
if (dy == 0 && reset || mCurrentScale == 1f){
|
||||
EventBus.getDefault().post(new EBReuse("isStopMove"));
|
||||
} else{
|
||||
EventBus.getDefault().post(new EBReuse("isStartove"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that maps the supplied Matrix to the current Drawable
|
||||
*
|
||||
* @param matrix - Matrix to map Drawable against
|
||||
* @return RectF - Displayed Rectangle
|
||||
*/
|
||||
private RectF getDisplayRect(Matrix matrix) {
|
||||
// int bottom;
|
||||
// if (imgagePro != -1){
|
||||
// bottom = (int) (getRight()*imgagePro);
|
||||
// } else {
|
||||
// bottom = getBottom();
|
||||
// }
|
||||
RectF rectF = new RectF(getLeft(), getTop(), getRight(), getBottom());
|
||||
matrix.mapRect(rectF);
|
||||
return rectF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImageURI(Uri uri) {
|
||||
reset();
|
||||
super.setImageURI(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
int saveCount = canvas.save();
|
||||
canvas.concat(mCurrentMatrix);
|
||||
super.onDraw(canvas);
|
||||
canvas.restoreToCount(saveCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
mScaleDetector.onTouchEvent(event);
|
||||
if (!mScaleDetector.isInProgress()) {
|
||||
mGestureDetector.onTouchEvent(event);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置图片
|
||||
*/
|
||||
public void reset() {
|
||||
mCurrentMatrix.reset();
|
||||
mCurrentScale = 1f;
|
||||
invalidate();
|
||||
EventBus.getDefault().post(new EBReuse("isStopMove"));
|
||||
}
|
||||
private final float[] matrixValues = new float[9];
|
||||
public final float getScale() {
|
||||
mCurrentMatrix.getValues(matrixValues);
|
||||
return matrixValues[Matrix.MSCALE_X];
|
||||
}
|
||||
/**
|
||||
* 自动缩放的任务
|
||||
*/
|
||||
private class AutoScaleRunnable implements Runnable {
|
||||
static final float BIGGER = 1.07f;
|
||||
static final float SMALLER = 0.96f;
|
||||
private float mTargetScale;
|
||||
private boolean isExp;
|
||||
|
||||
/**
|
||||
* 缩放的中心
|
||||
*/
|
||||
private float x;
|
||||
private float y;
|
||||
|
||||
/**
|
||||
* @param isExp :判断是否是放大
|
||||
*/
|
||||
public AutoScaleRunnable(float targetScale, float x, float y, boolean isExp) {
|
||||
this.mTargetScale = targetScale;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.isExp = isExp;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (isExp){ //放大
|
||||
mCurrentMatrix.postScale(BIGGER, BIGGER, x, y);
|
||||
invalidate();
|
||||
if (mCurrentScale < mTargetScale && mCurrentScale <= 4) {
|
||||
ZoomSimpleDraweeView.this.postDelayed(this, 10);
|
||||
mCurrentScale = mCurrentScale * BIGGER;
|
||||
} else {
|
||||
checkBorder();
|
||||
mCurrentScale = getScale();
|
||||
}
|
||||
}else {//缩小
|
||||
mCurrentMatrix.postScale(SMALLER, SMALLER, x, y);
|
||||
invalidate();
|
||||
checkBorder();
|
||||
if (getScale() > 1.01) {
|
||||
ZoomSimpleDraweeView.this.postDelayed(this, 1);
|
||||
mCurrentScale = mCurrentScale * SMALLER;
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//图片宽高比例
|
||||
public void setImagePro (float imgPro){
|
||||
this.imgagePro = imgPro;
|
||||
}
|
||||
|
||||
|
||||
public void setOnSingleClickListener(setOnSingleClickListener listener) {
|
||||
mClickListener = listener;
|
||||
}
|
||||
|
||||
public interface setOnSingleClickListener {
|
||||
void onClick();
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
351
app/src/main/java/com/gh/download/DownloadEntity.java
Normal file
351
app/src/main/java/com/gh/download/DownloadEntity.java
Normal file
@ -0,0 +1,351 @@
|
||||
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 boolean isReset() {
|
||||
if (meta != null) {
|
||||
if ("true".equals(meta.get("isReset"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setReset(boolean reset) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("isReset", String.valueOf(reset));
|
||||
}
|
||||
|
||||
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 long getStart() {
|
||||
if (meta != null) {
|
||||
String start = meta.get("start");
|
||||
if (start == null) {
|
||||
return 0;
|
||||
}
|
||||
return Long.valueOf(start);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setStart(long start) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("start", String.valueOf(start));
|
||||
}
|
||||
|
||||
public long getEnd() {
|
||||
if (meta != null) {
|
||||
String end = meta.get("end");
|
||||
if (end == null) {
|
||||
return 0;
|
||||
}
|
||||
return Long.valueOf(end);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setEnd(long end) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("end", String.valueOf(end));
|
||||
}
|
||||
|
||||
public long getInstalled() {
|
||||
if (meta != null) {
|
||||
String installed = meta.get("installed");
|
||||
if (installed == null) {
|
||||
return 0;
|
||||
}
|
||||
return Integer.valueOf(installed);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setInstalled(int installed) {
|
||||
if (meta == null) {
|
||||
meta = new HashMap<>();
|
||||
}
|
||||
meta.put("installed", String.valueOf(installed));
|
||||
}
|
||||
|
||||
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,39 @@ 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.PackageUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
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,16 +55,70 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
context.startService(new Intent(context, DownloadService.class));
|
||||
}
|
||||
|
||||
public void put(String url, long time) {
|
||||
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 = 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 +130,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 +140,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 +162,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 +176,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 +185,63 @@ 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);
|
||||
int installed = 0;
|
||||
for (ApkEntity apk : gameEntity.getApk()) {
|
||||
if (PackageManager.isInstalled(apk.getPackageName())) {
|
||||
installed++;
|
||||
}
|
||||
}
|
||||
downloadEntity.setInstalled(installed);
|
||||
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 +251,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 +265,7 @@ public class DownloadManager {
|
||||
* @param url
|
||||
*/
|
||||
public void resume(String url) {
|
||||
DownloadEntry entry = get(url);
|
||||
DownloadEntity entry = get(url);
|
||||
|
||||
// 暂停任务后,把文件删除,然后点继续,文件不存在,需要重新加入下载队列进行下载
|
||||
if (checkDownloadEntryRecordValidate(url)) {
|
||||
@ -163,121 +274,143 @@ 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据url获取某一个下载任务
|
||||
*
|
||||
* @param url
|
||||
* @param url 下载链接
|
||||
* @return null表示下载列表中不存在该任务,否则返回下载任务
|
||||
*/
|
||||
public DownloadEntry get(String url) {
|
||||
public DownloadEntity get(String url) {
|
||||
return DownloadDao.getInstance(context).get(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据包名获取某一个下载任务
|
||||
*
|
||||
* @param packageName 包名
|
||||
* @return null表示下载列表中不存在该任务,否则返回下载任务
|
||||
*/
|
||||
public DownloadEntity getByPackage(String packageName) {
|
||||
for (DownloadEntity downloadEntity : DownloadDao.getInstance(context).getAll()) {
|
||||
if (packageName.equals(downloadEntity.getPackageName())) {
|
||||
return downloadEntity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有下载列表中的任务
|
||||
*
|
||||
* @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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,20 +1,30 @@
|
||||
package com.gh.download;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.Trace;
|
||||
import com.gh.common.util.NotificationUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
public class DownloadService extends Service {
|
||||
|
||||
private int mFlag = (int) System.currentTimeMillis() / 1000;
|
||||
|
||||
private ArrayMap<String, Integer> flagMap = new ArrayMap<>();
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
@ -23,22 +33,32 @@ public class DownloadService extends Service {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
Utils.log(DownloadService.class.getSimpleName(), "onCreate");
|
||||
// ArrayList<DownloadEntity> doneList = new ArrayList<>();
|
||||
// for (DownloadEntity downloadEntity : DownloadManager.getInstance(this).getAll()) {
|
||||
// if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
// doneList.add(downloadEntity);
|
||||
// }
|
||||
// }
|
||||
NotificationUtils.showDownloadingNotification(this);
|
||||
// if (doneList.size() != 0) {
|
||||
// for (DownloadEntity downloadEntity : doneList) {
|
||||
// mFlag++;
|
||||
// flagMap.put(downloadEntity.getUrl(), mFlag);
|
||||
// NotificationUtils.showDownloadDoneNotification(this, downloadEntity, mFlag);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@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
|
||||
.getSerializableExtra(Constants.KEY_DOWNLOAD_ENTRY);
|
||||
DownloadStatus status = DownloadStatus.valueOf(intent.getStringExtra(Constants.KEY_DOWNLOAD_ACTION));
|
||||
DownloadEntity entry = (DownloadEntity) intent.getSerializableExtra(Constants.KEY_DOWNLOAD_ENTRY);
|
||||
switch (status) {
|
||||
case add:
|
||||
addDownload(entry);
|
||||
addDownload(entry, true);
|
||||
break;
|
||||
case pause:
|
||||
case timeout:
|
||||
@ -51,25 +71,24 @@ public class DownloadService extends Service {
|
||||
case cancel:
|
||||
cancelDownload(entry);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
private synchronized void addDownload(DownloadEntry entry) {
|
||||
DownloadEntry downloadEntry = DownloadDao.getInstance(this).get(
|
||||
entry.getUrl());
|
||||
private synchronized void addDownload(DownloadEntity entry, boolean isShow) {
|
||||
DownloadEntity downloadEntity = DownloadDao.getInstance(this).get(entry.getUrl());
|
||||
// 数据库下载历史中有这个任务的下载记录
|
||||
if (downloadEntry != null) {
|
||||
entry = downloadEntry;
|
||||
if (downloadEntity != null) {
|
||||
entry = downloadEntity;
|
||||
} else {
|
||||
entry.setStart(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
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,37 +96,37 @@ 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"));
|
||||
|
||||
if (isShow) {
|
||||
NotificationUtils.showDownloadingNotification(this);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
addDownload(entry);
|
||||
Trace.getInstance().debug(DownloadService.class.getSimpleName(),
|
||||
"resumeDownload==>" + entry);
|
||||
private synchronized void resumeDownload(DownloadEntity entry) {
|
||||
addDownload(entry, false);
|
||||
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());
|
||||
DownloadTask task = DataChanger.getInstance().getDownloadingTasks().get(entry.getUrl());
|
||||
if (task != null) {
|
||||
// 1.改任务队列的状态
|
||||
entry.setStatus(DownloadStatus.pause);
|
||||
@ -119,31 +138,40 @@ 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(), downloadEntity.getPackageName());
|
||||
status.setPluggable(downloadEntity.isPluggable());
|
||||
EventBus.getDefault().post(status);
|
||||
|
||||
Integer flag = flagMap.get(downloadEntity.getUrl());
|
||||
if (flag != null) {
|
||||
NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nManager.cancel(flag);
|
||||
}
|
||||
NotificationUtils.showDownloadingNotification(DownloadService.this);
|
||||
}
|
||||
|
||||
@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 +179,19 @@ public class DownloadService extends Service {
|
||||
case downloading:
|
||||
break;
|
||||
case done:
|
||||
mFlag++;
|
||||
flagMap.put(entry.getUrl(), mFlag);
|
||||
NotificationUtils.showDownloadingNotification(DownloadService.this);
|
||||
NotificationUtils.showDownloadDoneNotification(DownloadService.this, entry, mFlag);
|
||||
removeAndCheckNext(entry);
|
||||
break;
|
||||
case pause:
|
||||
// pauseDownload(entry);
|
||||
case cancel:
|
||||
removeAndCheckNext(entry);
|
||||
break;
|
||||
case cancel:
|
||||
case timeout:
|
||||
case neterror:
|
||||
NotificationUtils.showDownloadingNotification(DownloadService.this);
|
||||
removeAndCheckNext(entry);
|
||||
break;
|
||||
default:
|
||||
@ -167,18 +201,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
package com.gh.download;
|
||||
|
||||
public enum DownloadStatus {
|
||||
add, pause, cancel, downloading, done, waiting, resume, timeout, neterror, hijack
|
||||
add, pause, cancel, downloading, done, waiting, resume, timeout, neterror, hijack, notfound
|
||||
}
|
||||
|
||||
@ -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,26 @@ 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) {
|
||||
|| status == DownloadStatus.hijack
|
||||
|| status == DownloadStatus.notfound) {
|
||||
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!");
|
||||
}
|
||||
|
||||
@ -131,6 +133,7 @@ public class DownloadTask implements DownloadListener {
|
||||
entry.setSpeed(0);
|
||||
entry.setProgress(entry.getSize());
|
||||
entry.setPercent(100);
|
||||
entry.setEnd(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (status == DownloadStatus.pause) {
|
||||
@ -138,36 +141,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 +166,7 @@ public class DownloadTask implements DownloadListener {
|
||||
downloadThread.setStatus(DownloadStatus.pause);
|
||||
}
|
||||
|
||||
// check download progress
|
||||
// DataChanger notify progress
|
||||
public DownloadEntity getEntry() {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,29 +4,28 @@ 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;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
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;
|
||||
@ -35,7 +34,19 @@ public class DownloadThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
download();
|
||||
}
|
||||
|
||||
private void download() {
|
||||
Utils.log("url = " + entry.getUrl());
|
||||
if (TextUtils.isEmpty(entry.getUrl())) {
|
||||
listener.onStatusChanged(DownloadStatus.notfound);
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "error-->url is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferedInputStream bis = null;
|
||||
BufferedOutputStream bos = null;
|
||||
try {
|
||||
File targetFile = new File(entry.getPath());
|
||||
if (!targetFile.exists()) {
|
||||
@ -45,112 +56,127 @@ public class DownloadThread extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
FileOutputStream fileOutputStream;
|
||||
if (targetFile.length() > 0) {
|
||||
fileOutputStream = new FileOutputStream(entry.getPath(), true);
|
||||
} else {
|
||||
fileOutputStream = new FileOutputStream(entry.getPath());
|
||||
}
|
||||
HttpURLConnection connection = openConnection(new URL(entry.getUrl()), targetFile.length());
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "startPosition-->" + targetFile.length());
|
||||
|
||||
URL url = new URL(entry.getUrl());
|
||||
HttpURLConnection connection = (HttpURLConnection) url
|
||||
.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setRequestProperty("RANGE",
|
||||
"bytes=" + 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) {
|
||||
if (code == HttpURLConnection.HTTP_MOVED_PERM
|
||||
|| code == HttpURLConnection.HTTP_MOVED_TEMP) {
|
||||
//未自动重定向
|
||||
String location = connection.getHeaderField("Location");
|
||||
Utils.log("location = " + location);
|
||||
// entry.setUrl(location);
|
||||
url = new URL(location);
|
||||
connection = (HttpURLConnection) url
|
||||
.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setConnectTimeout(CONNECT_TIME);
|
||||
connection.setReadTimeout(READ_TIME);
|
||||
connection.setRequestProperty("RANGE",
|
||||
"bytes=" + targetFile.length() + "-");
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
connection = openConnection(new URL(location), targetFile.length());
|
||||
|
||||
code = connection.getResponseCode();
|
||||
}
|
||||
Utils.log("code = " +code);
|
||||
if (code == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
// 404 Not Found
|
||||
listener.onStatusChanged(DownloadStatus.notfound);
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "error-->404 Not Found");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
|
||||
long conentLength = connection.getContentLength();
|
||||
String eTag = connection.getHeaderField("ETag");
|
||||
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(),
|
||||
"error-->链接被劫持");
|
||||
interrupt();
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "error-->链接被劫持");
|
||||
return;
|
||||
}
|
||||
|
||||
long conentLength = connection.getContentLength();
|
||||
// 第一次下载记录文件长度
|
||||
if (entry.getSize() == 0) {
|
||||
entry.setSize(conentLength);
|
||||
DownloadDao.getInstance(context).newOrUpdate(entry);
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "记录第一次长度");
|
||||
}
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"progress:" + entry.getProgress() + "/curfilesize:"
|
||||
+ targetFile.length() + "=====contentLength:"
|
||||
+ conentLength + "/ totalSize:" + entry.getSize());
|
||||
|
||||
bis = new BufferedInputStream(connection.getInputStream());
|
||||
if (targetFile.length() > 0) {
|
||||
bos = new BufferedOutputStream(new FileOutputStream(entry.getPath(), true));
|
||||
} else {
|
||||
// 第一次下载记录文件长度
|
||||
if (entry.getSize() == 0) {
|
||||
entry.setSize(conentLength);
|
||||
DownloadDao.getInstance(context).newOrUpdate(entry);
|
||||
Trace.getInstance().debug(DownloadThread.class.getSimpleName(),
|
||||
"记录第一次长度");
|
||||
bos = new BufferedOutputStream(new FileOutputStream(entry.getPath()));
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = bis.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
listener.onProgressChanged(targetFile.length(), len);
|
||||
if (status == DownloadStatus.pause
|
||||
|| status == DownloadStatus.cancel) {
|
||||
listener.onStatusChanged(status);
|
||||
break;
|
||||
}
|
||||
Trace.getInstance().debug(
|
||||
DownloadThread.class.getSimpleName(),
|
||||
"progress:" + entry.getProgress() + "/curfilesize:"
|
||||
+ targetFile.length() + "=====contentLength:"
|
||||
+ conentLength + "/ totalSize:" + entry.getSize());
|
||||
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = bis.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
listener.onProgressChanged(len);
|
||||
if (status == DownloadStatus.pause
|
||||
|| status == DownloadStatus.cancel) {
|
||||
listener.onStatusChanged(status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (status != DownloadStatus.pause
|
||||
&& status != DownloadStatus.cancel) {
|
||||
listener.onStatusChanged(DownloadStatus.done);
|
||||
}
|
||||
bos.flush();
|
||||
Log.v("bug_test", "flush==>" + targetFile.length() + ",progress==>"
|
||||
+ entry.getProgress());
|
||||
Trace.getInstance().debug(
|
||||
DownloadThread.class.getSimpleName(),
|
||||
"flush==>" + targetFile.length() + ",progress==>"
|
||||
+ entry.getProgress());
|
||||
|
||||
bis.close();
|
||||
bos.close();
|
||||
}
|
||||
bos.flush();
|
||||
Utils.log(DownloadThread.class.getSimpleName(),
|
||||
"flush==>" + targetFile.length() + ",progress==>"
|
||||
+ entry.getProgress() + ",size==>" + entry.getSize());
|
||||
|
||||
if (targetFile.length() == entry.getSize()) {
|
||||
listener.onStatusChanged(DownloadStatus.done);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//e.getMessage() will null error
|
||||
if (!TextUtils.isEmpty(e.getMessage()) && e.getMessage().contains("connection timeout")) {
|
||||
listener.onStatusChanged(DownloadStatus.timeout);
|
||||
if (!entry.isReset()) {
|
||||
entry.setReset(true);
|
||||
download();
|
||||
} else {
|
||||
listener.onStatusChanged(DownloadStatus.neterror);
|
||||
String errorMsg = Log.getStackTraceString(e);
|
||||
if (!TextUtils.isEmpty(e.getMessage()) && e.getMessage().contains("connection timeout")) {
|
||||
listener.onStatusChanged(DownloadStatus.timeout, errorMsg);
|
||||
} else {
|
||||
listener.onStatusChanged(DownloadStatus.neterror, errorMsg);
|
||||
}
|
||||
Utils.log(DownloadThread.class.getSimpleName(), "exception-->" + e.toString());
|
||||
}
|
||||
} finally {
|
||||
if (bis != null) {
|
||||
try {
|
||||
bis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (bos != null) {
|
||||
try {
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Trace.getInstance().debug(DownloadThread.class.getSimpleName(),
|
||||
"exception-->" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private HttpURLConnection openConnection(URL url, long range) throws Exception {
|
||||
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.setDoInput(true);
|
||||
connection.setRequestProperty("RANGE", "bytes=" + range + "-");
|
||||
//设置自动重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void setStatus(DownloadStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@ -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,71 @@ 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) {
|
||||
if (!changed.isSingle()) {
|
||||
return;
|
||||
}
|
||||
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 +184,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 + "device/" + uuid + "/concern", data,
|
||||
new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
public void downSucced(String str) {
|
||||
Utils.log("更新设备关注游戏成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downFailed() {
|
||||
Utils.log("更新设备关注游戏失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
138
app/src/main/java/com/gh/gamecenter/CropImageActivity.java
Normal file
138
app/src/main/java/com/gh/gamecenter/CropImageActivity.java
Normal file
@ -0,0 +1,138 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
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.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.BitmapUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.view.CropImageCustom;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.net.HttpURLConnection;
|
||||
|
||||
public class CropImageActivity extends BaseActivity {
|
||||
|
||||
private CropImageCustom cropimage_custom;
|
||||
|
||||
private SoftReference<Bitmap> reference;
|
||||
|
||||
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(Config.USER_HOST + "icon",
|
||||
path, TokenUtils.getToken(CropImageActivity.this));
|
||||
dialog.dismiss();
|
||||
if (result != null) {
|
||||
try {
|
||||
int statusCode = result.getInt("statusCode");
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra("url", result.getString("icon"));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
handler.sendEmptyMessage(0);
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN
|
||||
&& "too frequent".equals(result.getString("detail"))) {
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
if (hasFocus && (reference == null || reference.get() == null)) {
|
||||
ImageView imageView = cropimage_custom.getCropImageZoomView();
|
||||
Bitmap bitmap = BitmapUtils.getBitmapByFile(getIntent().getStringExtra("path"),
|
||||
imageView.getWidth(), imageView.getHeight());
|
||||
if (bitmap != null) {
|
||||
reference = new SoftReference<>(bitmap);
|
||||
imageView.setImageBitmap(reference.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (reference != null) {
|
||||
reference.get().recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
@ -15,11 +16,11 @@ 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;
|
||||
import com.gh.gamecenter.eventbus.EBPerformClick;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
@ -35,56 +36,52 @@ 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;
|
||||
|
||||
private int width;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@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 +93,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);
|
||||
@ -125,28 +121,19 @@ public class DownloadManagerActivity extends BaseFragmentActivity implements
|
||||
|
||||
public FragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
|
||||
if (position == 0) {
|
||||
DownLoadManagerFragment fragment = new DownLoadManagerFragment();
|
||||
fragment.setPath(getIntent().getStringExtra("path"));
|
||||
return fragment;
|
||||
return new GameDownLoadFragment();
|
||||
} else {
|
||||
GameUpdateFragment fragment = new GameUpdateFragment();
|
||||
fragment.setParams(getIntent().getStringExtra(
|
||||
"packageName"), getIntent().getBooleanExtra(
|
||||
"isPushIntent", false));
|
||||
return fragment;
|
||||
return new GameUpdateFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
@ -160,17 +147,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 +199,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 +207,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,31 +226,27 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onEventMainThread(EBPerformClick click) {
|
||||
if (click.getFrom().equals("update")) {
|
||||
downloadmanager_ll_download.performClick();
|
||||
|
||||
public void onEventMainThread(EBSkip skip) {
|
||||
if ("DownloadManagerActivity".equals(skip.getType())) {
|
||||
if (skip.getCurrentItem() == 0) {
|
||||
handler.postDelayed(runnable, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadmanager_ll_download.performClick();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
217
app/src/main/java/com/gh/gamecenter/GameDetailActivity.java
Normal file
217
app/src/main/java/com/gh/gamecenter/GameDetailActivity.java
Normal file
@ -0,0 +1,217 @@
|
||||
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();
|
||||
downloadOffText = gameEntity.getDownloadOffText();
|
||||
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 + "game/" + gameId + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
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();
|
||||
} else {
|
||||
reuse_no_connection.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}, 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.isSingle() && 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
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user