master
张钧淇 1 year ago
parent 8bae2203e5
commit 596a6948d9

BIN
src/main/.DS_Store vendored

Binary file not shown.

@ -0,0 +1,313 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="com.gizwits.opensource.appkit"
android:versionCode="1" android:versionName="2.5.1.072715">
<!--push-all-start-->
<!--push_jiguang-false-start-->
<!-- 极光推送 -->
<permission android:name="com.gizwits.opensource.appkit.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" />
<!-- Required 一些系统要求的权限,如访问网络等 -->
<uses-permission android:name="com.gizwits.opensource.appkit.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<!-- Optional. Required for location feature -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<!-- 极光推送 -->
<!--push_jiguang-false-end-->
<!--push_baidu-false-start-->
<!-- 百度推送 -->
<!-- Push service 运行需要的权限 -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<!-- 富媒体需要声明的权限 -->
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<!-- 适配Android N系统必需的ContentProvider写权限声明写权限包含应用包名-->
<uses-permission
android:name="baidu.push.permission.WRITE_PUSHINFOPROVIDER.com.gizwits.opensource.appkit" />
<permission android:name="baidu.push.permission.WRITE_PUSHINFOPROVIDER.com.gizwits.opensource.appkit"
android:protectionLevel="signature"></permission>
<!--push_baidu-false-end-->
<!--push-all-end-->
<!-- SDK 使用权限 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_LOGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- 乐鑫配置库中使用的权限WIFI组播 -->
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.GET_TASKS" />
<application android:name="com.gizwits.opensource.appkit.GosApplication"
android:allowBackup="true" android:icon="@drawable/icon" android:label="@string/app_name"
android:theme="@style/AppTheme">
<!--<meta-data-->
<!--android:name="UMENG_APPKEY"-->
<!--android:value="55bf3f4b67e58eced6002ea3" />-->
<!--<meta-data-->
<!--android:name="UMENG_MESSAGE_SECRET"-->
<!--android:value="090399528857c395d540ce933c679d69" />-->
<meta-data android:name="UMENG_APPKEY" android:value="57c3eb24e0f55a32ba0019de"></meta-data>
<meta-data android:name="UMENG_MESSAGE_SECRET"
android:value="046bcebdeaa31b356a6866b1639eed1c"></meta-data>
<meta-data android:name="UMENG_CHANNEL" android:value="gizwits" />
<activity android:name="com.gizwits.opensource.appkit.CommonModule.SplashActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:exported="true"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--login_qq-false-start-->
<!-- 在此处填写腾讯官网申请的AppKey -->
<activity
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:exported="true"
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" />
<!--1105495693 tencent1105509702-->
<data android:scheme="tencent1105495693" />
</intent-filter>
</activity>
<activity android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!--login_qq-false-end-->
<!--login_weChat-false-start-->
<!--微信登录-->
<!--<activity android:name="com.gizwits.opensource.appkit.wxapi.WXEntryActivity"-->
<!--android:exported="true"></activity>-->
<activity android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize" android:exported="true"
android:launchMode="singleTop" android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar"></activity>
<!--login_weChat-false-end-->
<!-- 以下是框架中使用的Activity -->
<activity android:name="com.gizwits.opensource.appkit.UserModule.GosUserLoginActivity"
android:launchMode="singleTask" />
<!--register-all-start-->
<activity android:name="com.gizwits.opensource.appkit.UserModule.GosRegisterUserActivity" />
<!--register-all-end-->
<!--resetPassword-all-start-->
<activity
android:name="com.gizwits.opensource.appkit.UserModule.GosForgetPasswordActivity" />
<!--resetPassword-all-end-->
<activity
android:name="com.gizwits.opensource.appkit.UserModule.GosSendEmailPasswordActivity" />
<activity android:name="zxing.CaptureActivity" android:theme="@style/AppTheme" />
<activity android:name="com.gizwits.opensource.appkit.SettingsModule.GosAboutActivity" />
<activity
android:name="com.gizwits.opensource.appkit.ControlModule.GosDeviceControlActivity" />
<!--config-all-start-->
<!--config_softap-false-start-->
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosChooseDeviceWorkWiFiActivity" />
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosDeviceReadyActivity" />
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosChooseDeviceActivity" />
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosConfigCountdownActivity" />
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosDeviceResetActivity" />
<!--config_softap-false-end-->
<!--config_airlink-false-start-->
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosAirlinkChooseDeviceWorkWiFiActivity" />
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosAirlinkConfigCountdownActivity" />
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosAirlinkReadyActivity" />
<!--config_airlink-false-end-->
<!--wifiModuleType-true-start-->
<activity android:name="com.gizwits.opensource.appkit.ConfigModule.GosModeListActivity" />
<!--wifiModuleType-true-end-->
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosConfigFailedActivity" />
<activity android:name="com.gizwits.opensource.appkit.ConfigModule.GosModeListActivity2" />
<activity
android:name="com.gizwits.opensource.appkit.ConfigModule.GosChooseModuleHelpActivity" />
<!--config-all-end-->
<!-- <activity android:name="com.gizwits.setting.DeployThingActivity" > -->
<!-- </activity> -->
<activity android:name="com.gizwits.opensource.appkit.DeviceModule.GosMainActivity"
android:launchMode="singleTask" />
<activity android:name="com.gizwits.opensource.appkit.UserModule.GosUserManager" />
<!--personalCenter_changePassword-false-start-->
<activity
android:name="com.gizwits.opensource.appkit.UserModule.GosChangeUserPasswordActivity" />
<!--personalCenter_changePassword-false-end-->
<activity android:name="com.gizwits.opensource.appkit.sharingdevice.SharedDeviceListAcitivity" />
<activity android:name="com.gizwits.opensource.appkit.sharingdevice.SharedDeviceManagerActivity" />
<activity android:name="com.gizwits.opensource.appkit.sharingdevice.addSharedActivity" />
<activity android:name="com.gizwits.opensource.appkit.sharingdevice.twoSharedActivity" />
<activity android:name="com.gizwits.opensource.appkit.sharingdevice.userSharedActivity" />
<activity android:name="com.gizwits.opensource.appkit.sharingdevice.deviceSharedMessageActivity" />
<activity android:name="com.gizwits.opensource.appkit.sharingdevice.gosZxingDeviceSharingActivity" />
<!--User defined. 用户自定义的广播接收器-->
<receiver
android:name="com.gizwits.opensource.appkit.PushModule.JPushReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<!--Required 用户注册SDK的intent-->
<action android:name="cn.jpush.android.intent.REGISTRATION" />
<!--Required 用户接收SDK消息的intent-->
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
<!--Required 用户接收SDK通知栏信息的intent-->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
<!--Required 用户打开自定义通知栏的intent-->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
<!--Optional 用户接受Rich Push Javascript 回调函数的intent-->
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" />
<!--接收网络变化 连接/断开 since 1.6.3-->
<action android:name="cn.jpush.android.intent.CONNECTION" />
<category android:name="com.gizwits.opensource.appkit" />
</intent-filter>
</receiver>
<!--Required. For publish channel feature-->
<!--JPUSH_CHANNEL 是为了方便开发者统计APK分发渠道。-->
<!--例如:-->
<!--发到 Google Play 的APK可以设置为 google-play;-->
<!--发到其他市场的 APK 可以设置为 xxx-market。-->
<!--目前这个渠道统计功能的报表还未开放。-->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" />
<!--Required. AppKey copied from Portal-->
<meta-data android:name="JPUSH_APPKEY" android:value="JPUSH_APPKEY" />
<!--push_jiguang-false-end-->
<!--push_baidu-false-start-->
<!--百度推送-->
<!--push service start-->
<!--用于接收系统消息以保证PushService正常运行-->
<receiver
android:name="com.baidu.android.pushservice.PushServiceReceiver"
android:exported="true"
android:process=":bdservice_v1">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="com.baidu.android.pushservice.action.notification.SHOW" />
<action android:name="com.baidu.android.pushservice.action.media.CLICK" />
<!--以下四项为可选的action声明可大大提高service存活率和消息到达速度-->
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</receiver>
<!--Push服务接收客户端发送的各种请求-->
<receiver
android:name="com.baidu.android.pushservice.RegistrationReceiver"
android:exported="true"
android:process=":bdservice_v1">
<intent-filter>
<action android:name="com.baidu.android.pushservice.action.METHOD" />
<action android:name="com.baidu.android.pushservice.action.BIND_SYNC" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<service android:name="com.baidu.android.pushservice.PushService" android:exported="true"
android:process=":bdservice_v1">
<intent-filter>
<action android:name="com.baidu.android.pushservice.action.PUSH_SERVICE" />
</intent-filter>
</service>
<!--4.4版本新增的CommandService声明提升小米和魅族手机上的实际推送到达率-->
<service android:name="com.baidu.android.pushservice.CommandService"
android:exported="true" />
<!-- 适配Android N系统必需的ContentProvider声明写权限包含应用包名-->
<provider android:name="com.baidu.android.pushservice.PushInfoProvider"
android:authorities="com.gizwits.opensource.appkit.bdpush" android:exported="true"
android:protectionLevel="signature"
android:writePermission="baidu.push.permission.WRITE_PUSHINFOPROVIDER.com.gizwits.opensource.appkit" />
<!--push结束-->
<!--此处Receiver名字修改为当前包名路径-->
<receiver
android:name="com.gizwits.opensource.appkit.PushModule.BaiDuPushReceiver"
android:exported="true">
<intent-filter>
<!--接收push消息-->
<action android:name="com.baidu.android.pushservice.action.MESSAGE" />
<!--接收bind、setTags等method的返回结果-->
<action android:name="com.baidu.android.pushservice.action.RECEIVE" />
<!--接收通知点击事件,和通知自定义内容-->
<action android:name="com.baidu.android.pushservice.action.notification.CLICK" />
</intent-filter>
</receiver>
<!-- 在百度开发者中心查询应用的API Key -->
<meta-data android:name="api_key" android:value="BaiDu_APIKEY" />
<!--push_baidu-false-end-->
<!--push-all-end-->
</application>
</manifest>

Binary file not shown.

@ -0,0 +1,56 @@
{
"appInfo": {
"cloudService": {
"api": "api.gizwits.com:80",
"site": "site.gizwits.com:80"
},
"gizwitsInfo": {
"appId": "30fe77f49f4c4b50a3affd72aa221da1",
"appSecret": "162abf698315470da96673397cd567be"
},
"productInfo": [{
"productKey": "d58cf41924734241ac775eedef11dbce",
"productSecret": "4092fdf9dd6e4c4286010dffcfe4118e"
}],
"tencentInfo": {
"appId": "your_tencent_app_id"
},
"weChatInfo": {
"appId": "your_wechat_app_id",
"appSecret": "your_wechat_app_secret"
},
"pushInfo": {
"jpushAppKey": "your_jpush_app_key",
"bpushAppKey": "your_bpush_app_key"
}
},
"templateSelect": {
"deviceList": {
"unbindDevice": true,
"displayMac": true
}
},
"functionConfig": {
"bindDevice_qrcode": true,
"deviceOnboarding": {
"config_softap": true,
"config_airlink": true,
"wifiModuleType": []
},
"login_anonymous": true,
"login_qq": false,
"login_weChat": false,
"register_phoneUser": true,
"resetPassword_phoneUser": true,
"personalCenter_changePassword": true,
"push_baidu": false,
"push_jiguang": false
},
"viewConfig": {
"viewColor": {
"background": "FBDA51",
"contrast": "333333"
},
"statusBarStyle": "default"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

@ -0,0 +1,220 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>模组类型选择技巧</title>
</head>
<body>
<h3>模组类型选择技巧</h3>
<hr>
<h4>模组常见类型</h4>
<table border="1">
<!-- 表头-->
<tr>
<th>品牌</th>
<th>型号</th>
<th>图片</th>
</tr>
<!-- 乐鑫-->
<tr>
<td>乐鑫(ESP-8266)</td>
<td>
<table>
<tr>
<td>ESP-07S</td>
</tr>
<tr>
<td>ESP-12S</td>
</tr>
<tr>
<td>ESP-12F</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/ESP-07S.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/ESP-12S.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/ESP-12F.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- 庆科 -->
<tr>
<td>庆科</td>
<td>
<table>
<tr>
<td>EMW3162</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/EMW3162.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- 汉枫 -->
<tr>
<td>汉枫</td>
<td>
<table>
<tr>
<td>HF-LPB100</td>
</tr>
<tr>
<td>HF-LPB120</td>
</tr>
<tr>
<td>HF-LPT120</td>
</tr>
<tr>
<td>HF-LPT220</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/HF-LPB100.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/HF-LPB120.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/HF-LPT120.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/HF-LPT220.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- 瑞昱(Realtek) -->
<tr>
<td>瑞昱Realtek</td>
<td>
<table>
<tr>
<td>RTL8711AM</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/RTL8711AM.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- 联盛德 -->
<tr>
<td>联盛德</td>
<td>
<table>
<tr>
<td>TLN13SP01</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/TLN13P01.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- 高通 -->
<tr>
<td>高通</td>
<td>
<table>
<tr>
<td>QCA4004</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/QCA4004.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- TI -->
<tr>
<td>TI</td>
<td>
<table>
<tr>
<td>CC3200</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/CC3200.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='3'>
我们将会持续更新,为您带来更多的帮助参考信息。
</td>
</tr>
</table>
</body>
</html>

@ -0,0 +1,220 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Module Type Choose Tips</title>
</head>
<body>
<h3>Module Type Choose Tips</h3>
<hr>
<h4>Module Type</h4>
<table border="1">
<!-- table head-->
<tr>
<th>Brand</th>
<th>Type</th>
<th>Picture</th>
</tr>
<!-- ESP-->
<tr>
<td>ESP(ESP-8266)</td>
<td>
<table>
<tr>
<td>ESP-07S</td>
</tr>
<tr>
<td>ESP-12S</td>
</tr>
<tr>
<td>ESP-12F</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/ESP-07S.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/ESP-12S.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/ESP-12F.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- MXCHIP -->
<tr>
<td>MXCHIP</td>
<td>
<table>
<tr>
<td>EMW3162</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/EMW3162.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- HF -->
<tr>
<td>HF</td>
<td>
<table>
<tr>
<td>HF-LPB100</td>
</tr>
<tr>
<td>HF-LPB120</td>
</tr>
<tr>
<td>HF-LPT120</td>
</tr>
<tr>
<td>HF-LPT220</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/HF-LPB100.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/HF-LPB120.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/HF-LPT120.png" width="100" height="80">
</td>
</tr>
<tr>
<td>
<img src="image/HF-LPT220.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- RTK Realtek -->
<tr>
<td>RTK(Realtek)</td>
<td>
<table>
<tr>
<td>RTL8711AM</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/RTL8711AM.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- WM -->
<tr>
<td>WM</td>
<td>
<table>
<tr>
<td>TLN13SP01</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/TLN13P01.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- QCA -->
<tr>
<td>QCA</td>
<td>
<table>
<tr>
<td>QCA4004</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/QCA4004.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<!-- TI -->
<tr>
<td>TI</td>
<td>
<table>
<tr>
<td>CC3200</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<img src="image/CC3200.png" width="100" height="80">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='3'>
The content will be update continually, please follow it.
</td>
</tr>
</table>
</body>
</html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,34 @@
package com.gizwits.opensource.appkit.CommonModule;
import android.net.wifi.ScanResult;
import com.gizwits.gizwifisdk.api.GizDeviceSharingInfo;
import com.gizwits.gizwifisdk.api.GizUserInfo;
import java.util.ArrayList;
import java.util.List;
public class GosConstant {
// 设备热点默认前缀
public static final String SoftAP_Start = "XPG-GAgent";
public static final String SSIDPsw = "#10v3#";
public static boolean isOpenHot = false;
/**
* 0 使 setDeviceOnboarding
* 1 setDeviceOnboardingByBind
* 2 setDeviceOnboardingDeploy false
* 3 setDeviceOnboardingDeploy true
*/
public static int mNew = 0;
public static List<ScanResult> ssidList = new ArrayList<ScanResult>();
public static int nowPager = -1;
public static List<GizUserInfo> mybindUsers = new ArrayList<GizUserInfo>();
public static boolean isEdit = false;
public static List<GizDeviceSharingInfo> mydeviceSharingInfos = new ArrayList<GizDeviceSharingInfo>();
public static List<GizDeviceSharingInfo> newmydeviceSharingInfos = new ArrayList<GizDeviceSharingInfo>();
}

@ -0,0 +1,56 @@
package com.gizwits.opensource.appkit.CommonModule;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class NoScrollViewPager extends ViewPager {
private boolean noScroll = false;
public NoScrollViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public NoScrollViewPager(Context context) {
super(context);
}
public void setNoScroll(boolean noScroll) {
this.noScroll = noScroll;
}
@Override
public void scrollTo(int x, int y) {
super.scrollTo(x, y);
}
@Override
public boolean onTouchEvent(MotionEvent arg0) {
/* return false;//super.onTouchEvent(arg0); */
if (noScroll)
return false;
else
return super.onTouchEvent(arg0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
if (noScroll)
return false;
else
return super.onInterceptTouchEvent(arg0);
}
@Override
public void setCurrentItem(int item, boolean smoothScroll) {
super.setCurrentItem(item, smoothScroll);
}
@Override
public void setCurrentItem(int item) {
super.setCurrentItem(item);
}
}

@ -0,0 +1,115 @@
package com.gizwits.opensource.appkit.CommonModule;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.widget.TextView;
import com.gizwits.opensource.appkit.MessageCenter;
import com.gizwits.opensource.appkit.PushModule.GosPushManager;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.UserModule.GosUserLoginActivity;
import com.gizwits.opensource.appkit.utils.AssetsUtils;
/**
* Created by admin on 2017/6/8.
*/
public class SplashActivity extends Activity implements ActivityCompat.OnRequestPermissionsResultCallback {
private final int SPLASH_DISPLAY_LENGHT = 2000;
private Handler handler;
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE"};
//push-all-start
private GosPushManager gosPushManager;
//push-all-end
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!this.isTaskRoot()) {// 判断此activity是不是任务控件的源Activity“非”也就是说是被系统重新实例化出来的
Intent mainIntent = getIntent();
String action = mainIntent.getAction();
if (mainIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
&& action.equals(Intent.ACTION_MAIN)) {
finish();
return;
}
}
// getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_gos_splash);
handler = new Handler();
getWindow().getDecorView().post(new Runnable() {
@Override
public void run() {
//检测是否有写的权限
int permission = ActivityCompat.checkSelfPermission(SplashActivity.this,
"android.permission.WRITE_EXTERNAL_STORAGE");
if (permission != PackageManager.PERMISSION_GRANTED) {
try {
// 没有写的权限,去申请写的权限,会弹出对话框
ActivityCompat.requestPermissions(SplashActivity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
} catch (Exception e) {
e.printStackTrace();
}
} else {
initEvent();
}
}
});
}
private void initEvent() {
// 延迟SPLASH_DISPLAY_LENGHT时间然后跳转到MainActivity
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this,
GosUserLoginActivity.class);
startActivity(intent);
SplashActivity.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
MessageCenter.getInstance(SplashActivity.this);
// 在配置文件中选择推送类型2百度1极光推送
if (GosDeploy.appConfig_Push_BaiDu()) {
Log.e("TAG", "initEvent----: 百度推送");
gosPushManager = new GosPushManager(2, this);
}
if (GosDeploy.appConfig_Push_JiGuang()) {
gosPushManager = new GosPushManager(1, this);
}
TextView tvName = (TextView) findViewById(R.id.tvName);
if (AssetsUtils.isZh(SplashActivity.this)) {
if (GosDeploy.appConfig_LaunchInfoCH() != null) {
tvName.setText(GosDeploy.appConfig_LaunchInfoCH());
}
} else {
if (GosDeploy.appConfig_LaunchInfoEN() != null) {
tvName.setText(GosDeploy.appConfig_LaunchInfoEN());
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
initEvent();
}
}

@ -0,0 +1,59 @@
package com.gizwits.opensource.appkit.CommonModule;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import com.gizwits.opensource.appkit.R;
public class TipsDialog extends Dialog implements
View.OnClickListener {
private Button btnSure;
private TextView tvTips;
public TipsDialog(Context context) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawableResource(R.drawable.shape_button2);
setContentView(R.layout.dialog_tips);
initView();
setCancelable(false);
}
public TipsDialog(Context context, String txt) {
this(context);
tvTips.setText(txt);
}
public TipsDialog(Context context, int res) {
this(context);
tvTips.setText(res);
}
private void initView() {
btnSure = (Button) findViewById(R.id.btnSure);
tvTips = (TextView) findViewById(R.id.tvTips);
btnSure.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnSure:
cancel();
break;
}
}
}

@ -0,0 +1,505 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
import com.gizwits.opensource.appkit.utils.NetUtils;
import com.gizwits.opensource.appkit.utils.ToolUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
@SuppressLint("InflateParams")
public class GosAirlinkChooseDeviceWorkWiFiActivity extends GosConfigModuleBaseActivity implements OnClickListener {
private AlertDialog create;
private ArrayList<ScanResult> wifiList;
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.ACCESS_COARSE_LOCATION"};
/**
* wifi
*/
public WifiInfo wifiInfo;
/**
* The et SSID
*/
private EditText etSSID;
/**
* The et Psw
*/
private EditText etPsw;
/**
* The btn Next
*/
private Button btnNext;
/** The ll ChooseMode */
//private LinearLayout llChooseMode;
/**
* The cb Laws
*/
private CheckBox cbLaws;
/** The tv Mode */
//private TextView tvMode;
/**
* The rl WiFiList
*/
private RelativeLayout rlWiFiList;
/**
*
*/
private String workSSID, workSSIDPsw;
/**
* The data
*/
List<String> modeList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_airlink_choose_device_workwifi);
// 设置ActionBar
setToolBar(true, getString(R.string.choose_wifi));
initData();
initView();
ininEvent();
}
@Override
protected void onResume() {
super.onResume();
try {
// 预设workSSID && workSSIDPsw
workSSID = NetUtils.getCurentWifiSSID(this);
String mypass = spf.getString("mypass", "");
if (!TextUtils.isEmpty(workSSID)) {
etSSID.setText(workSSID);
etSSID.setSelection(workSSID.length());
if (!TextUtils.isEmpty(mypass)) {
JSONObject obj = new JSONObject(mypass);
if (obj.has(workSSID)) {
String pass = obj.getString(workSSID);
etPsw.setText(pass);
} else {
etPsw.setText("");
}
}
} else {
etSSID.setText(NetUtils.getCurentWifiSSID(this));
}
// 当没有任何文字的时候设置为明文显示
// if (TextUtils.isEmpty(etPsw.getText().toString())) {
// cbLaws.setChecked(true);
// etPsw.setInputType(0x90);
// } else {
// etPsw.setInputType(0x81);
// cbLaws.setChecked(false);
// }
} catch(JSONException e) {
e.printStackTrace();
}
}
private void initView() {
//tvMode = (TextView) findViewById(R.id.tvMode);
etSSID = (EditText) findViewById(R.id.etSSID);
etPsw = (EditText) findViewById(R.id.etPsw);
cbLaws = (CheckBox) findViewById(R.id.cbLaws);
btnNext = (Button) findViewById(R.id.btnNext);
//llChooseMode = (LinearLayout) findViewById(R.id.llChooseMode);
rlWiFiList = (RelativeLayout) findViewById(R.id.rlWiFiList);
// 配置文件部署
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
// llChooseMode.setVisibility(GosDeploy.setModuleSelectOn());
//llChooseMode.setVisibility(View.GONE);
}
private void ininEvent() {
btnNext.setOnClickListener(this);
rlWiFiList.setOnClickListener(this);
//llChooseMode.setOnClickListener(this);
cbLaws.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String psw = etPsw.getText().toString();
if (isChecked) {
etPsw.setInputType(0x90);
} else {
etPsw.setInputType(0x81);
}
etPsw.setSelection(psw.length());
}
});
//检测是否有位置定位的权限
int permission = ActivityCompat.checkSelfPermission(GosAirlinkChooseDeviceWorkWiFiActivity.this,
"android.permission.ACCESS_FINE_LOCATION");
if (permission != PackageManager.PERMISSION_GRANTED) {
try {
// 没有写的权限,去申请写的权限,会弹出对话框
ActivityCompat.requestPermissions(GosAirlinkChooseDeviceWorkWiFiActivity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
} catch(Exception e) {
e.printStackTrace();
}
}
}
private void initData() {
modeList = new ArrayList<String>();
String[] modes = this.getResources().getStringArray(R.array.mode);
for (String string : modes) {
modeList.add(string);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnNext:
if (ToolUtils.noDoubleClick()) {
workSSID = etSSID.getText().toString();
workSSIDPsw = etPsw.getText().toString();
if (TextUtils.isEmpty(workSSID)) {
Toast.makeText(GosAirlinkChooseDeviceWorkWiFiActivity.this, R.string.choose_wifi_list_title, toastTime)
.show();
return;
}
if (!workSSID.equals(NetUtils.getCurentWifiSSID(this))) {
final Dialog dialog1 = new AlertDialog.Builder(this, R.style.alert_dialog_style)
.setView(new EditText(this)).create();
dialog1.setCanceledOnTouchOutside(false);
dialog1.show();
Window window = dialog1.getWindow();
window.setContentView(R.layout.alert_gos_wifi);
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog1.cancel();
return;
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (dialog1.isShowing()) {
dialog1.cancel();
}
isEmptyAlert();
}
});
} else {
isEmptyAlert();
}
}
break;
case R.id.rlWiFiList:
AlertDialog.Builder dia = new AlertDialog.Builder(GosAirlinkChooseDeviceWorkWiFiActivity.this);
View view = View.inflate(GosAirlinkChooseDeviceWorkWiFiActivity.this, R.layout.alert_gos_wifi_list, null);
ListView listview = (ListView) view.findViewById(R.id.wifi_list);
List<ScanResult> rsList = NetUtils.getCurrentWifiScanResult(this);
List<String> localList = new ArrayList<String>();
localList.clear();
wifiList = new ArrayList<ScanResult>();
wifiList.clear();
for (ScanResult sss : rsList) {
if (sss.SSID.contains(SoftAP_Start)) {
} else {
if (localList.toString().contains(sss.SSID)) {
} else {
localList.add(sss.SSID);
wifiList.add(sss);
}
}
}
if (wifiList.size() == 0) {
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
// 未打开位置开关,可能导致定位失败或定位不准,提示用户或做相应处理
Toast.makeText(this, getString(R.string.open), Toast.LENGTH_LONG).show();
return;
}
}
WifiListAdapter adapter = new WifiListAdapter(wifiList);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
ScanResult sResult = wifiList.get(arg2);
String sSID = sResult.SSID;
etSSID.setText(sSID);
etSSID.setSelection(sSID.length());
etPsw.setText("");
create.dismiss();
}
});
dia.setView(view);
create = dia.create();
create.show();
break;
default:
break;
}
}
private static final String TAG = "GosAirlinkChooseDevice";
private void toAirlinkReady() {
// 需要记录所有配置过的wifi和密码
try {
String mypass = spf.getString("mypass", "");
if (TextUtils.isEmpty(mypass)) {
JSONObject mUserAndPass = new JSONObject();
mUserAndPass.put(workSSID, workSSIDPsw);
spf.edit().putString("mypass", mUserAndPass.toString()).commit();
} else {
JSONObject obj = new JSONObject(mypass);
obj.put(workSSID, workSSIDPsw);
spf.edit().putString("mypass", obj.toString()).commit();
}
} catch(JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
spf.edit().putString("workSSID", workSSID).commit();
spf.edit().putString("workSSIDPsw", workSSIDPsw).commit();
//wifiModuleType-false-start wifiModuleType-true-start
if (GosDeploy.appConfig_WifiModuleType().size() == 0) {
//wifiModuleType-false-end
Intent intent = new Intent(this, GosModeListActivity2.class);
startActivity(intent);
//wifiModuleType-false-start
} else {
//wifiModuleType-true-end
List<Integer> moduleTypes = GosDeploy.appConfig_WifiModuleType();
JSONArray array = new JSONArray();
for (int type : moduleTypes) {
if (type == 4) {
type = 0;
} else if (type < 4) {
type = type + 1;
} else if (type == 12) {
type = 6;
} else if (type >= 6 && type < 12) {
type = type + 1;
}
array.put(type);
}
spf.edit().putString("modulestyles", array.toString()).commit();
Intent intent = new Intent(this, GosAirlinkReadyActivity.class);
startActivity(intent);
//wifiModuleType-true-start
}
//wifiModuleType-false-end wifiModuleType-true-end
}
/*
* // 检查当前使用的WiFi是否曾经用过 protected boolean checkworkSSIDUsed(String workSSID)
* { if (spf.contains("workSSID")) { if (spf.getString("workSSID",
* "").equals(workSSID)) { return true; } } return false; }
*/
// 屏蔽掉返回键
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent intent = new Intent(this, GosMainActivity.class);
startActivity(intent);
//quitAlert(this, intent);
return true;
}
return false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent intent = new Intent(this, GosMainActivity.class);
startActivity(intent);
//quitAlert(this, intent);
break;
}
return true;
}
private void isEmptyAlert() {
if (TextUtils.isEmpty(workSSIDPsw)) {
final Dialog dialog = new AlertDialog.Builder(this, R.style.alert_dialog_style)
.setView(new EditText(this)).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_empty);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (dialog.isShowing()) {
dialog.cancel();
}
toAirlinkReady();
}
});
} else {
toAirlinkReady();
}
}
class WifiListAdapter extends BaseAdapter {
ArrayList<ScanResult> xpgList;
public WifiListAdapter(ArrayList<ScanResult> list) {
this.xpgList = list;
}
@Override
public int getCount() {
return xpgList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
Holder holder;
if (view == null) {
view = LayoutInflater.from(GosAirlinkChooseDeviceWorkWiFiActivity.this)
.inflate(R.layout.item_gos_wifi_list, null);
holder = new Holder(view);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
String ssid = xpgList.get(position).SSID;
holder.getTextView().setText(ssid);
return view;
}
}
class Holder {
View view;
public Holder(View view) {
this.view = view;
}
TextView textView;
public TextView getTextView() {
if (textView == null) {
textView = (TextView) view.findViewById(R.id.SSID_text);
}
return textView;
}
}
}

@ -0,0 +1,310 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizWifiConfigureMode;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.enumration.GizWifiGAgentType;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
import com.gizwits.opensource.appkit.view.RoundProgressBar;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import static com.gizwits.gizwifisdk.enumration.GizWifiErrorCode.GIZ_SDK_ONBOARDING_STOPPED;
@SuppressLint("HandlerLeak")
public class GosAirlinkConfigCountdownActivity extends
GosConfigModuleBaseActivity {
/** The tv Time */
//private TextView tvTimer;
/**
* The rpb Config
*/
private RoundProgressBar rpbConfig;
/**
*
*/
int secondleft = 60;
/**
* The timer
*/
Timer timer;
/**
*
*/
String workSSID, workSSIDPsw;
List<GizWifiGAgentType> modeList, modeDataList;
private TextView tvLeft;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_airlink_config_countdown);
// 设置ActionBar
setToolBar(false, R.string.search_join);
initView();
initData();
startAirlink();
tvLeft = (TextView) findViewById(R.id.tvLeft);
tvLeft.setVisibility(View.VISIBLE);
SpannableString ssTitle = new SpannableString(this.getString(R.string.cancel));
ssTitle.setSpan(new ForegroundColorSpan(GosDeploy.appConfig_Contrast()), 0, ssTitle.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
tvLeft.setText(ssTitle);
tvLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(GosAirlinkConfigCountdownActivity.this, GosMainActivity.class);
quitAlert(GosAirlinkConfigCountdownActivity.this, intent, getString(R.string.cancel_configuration));
}
});
}
private void initView() {
WindowManager wm = this.getWindowManager();
int width = wm.getDefaultDisplay().getWidth();
RelativeLayout cel_layout = (RelativeLayout) findViewById(R.id.params);
LayoutParams params = cel_layout.getLayoutParams();
params.height = width;
params.width = width;
cel_layout.setLayoutParams(params);
//tvTimer = (TextView) findViewById(R.id.tvTimer);
rpbConfig = (RoundProgressBar) findViewById(R.id.rpbConfig);
}
private static final String TAG = "GosAirlinkConfigCountdo";
private void initData() {
workSSID = spf.getString("workSSID", "");
workSSIDPsw = spf.getString("workSSIDPsw", "");
modeDataList = new ArrayList<GizWifiGAgentType>();
modeDataList.add(GizWifiGAgentType.GizGAgentESP);
modeDataList.add(GizWifiGAgentType.GizGAgentMXCHIP);
modeDataList.add(GizWifiGAgentType.GizGAgentHF);
modeDataList.add(GizWifiGAgentType.GizGAgentRTK);
modeDataList.add(GizWifiGAgentType.GizGAgentWM);
modeDataList.add(GizWifiGAgentType.GizGAgentQCA);
modeDataList.add(GizWifiGAgentType.GizGAgentFlyLink);
modeDataList.add(GizWifiGAgentType.GizGAgentTI);
modeDataList.add(GizWifiGAgentType.GizGAgentFSK);
modeDataList.add(GizWifiGAgentType.GizGAgentMXCHIP3);
modeDataList.add(GizWifiGAgentType.GizGAgentBL);
modeDataList.add(GizWifiGAgentType.GizGAgentAtmelEE);
modeDataList.add(GizWifiGAgentType.GizGAgentOther);
modeList = new ArrayList<GizWifiGAgentType>();
String types = spf.getString("modulestyles", null);
if (types != null) {
try {
JSONArray array = new JSONArray(types);
for (int i = 0; i < array.length(); i++) {
int type = (Integer) array.get(i);
modeList.add(modeDataList.get(type));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
private void startAirlink() {
String nullStr = null;
switch (GosConstant.mNew) {
case 0:
GizWifiSDK.sharedInstance().setDeviceOnboarding(workSSID, workSSIDPsw,
GizWifiConfigureMode.GizWifiAirLink, null, 60, modeList);
break;
case 1:
GizWifiSDK.sharedInstance().setDeviceOnboardingByBind(workSSID, workSSIDPsw,
GizWifiConfigureMode.GizWifiAirLink, null, 60, modeList);
break;
case 2:
GizWifiSDK.sharedInstance().setDeviceOnboardingDeploy(
workSSID,
workSSIDPsw,
GizWifiConfigureMode.GizWifiAirLink,
nullStr,
60,
modeList,
false
);
break;
case 3:
GizWifiSDK.sharedInstance().setDeviceOnboardingDeploy(
workSSID,
workSSIDPsw,
GizWifiConfigureMode.GizWifiAirLink,
nullStr,
60,
modeList,
true
);
break;
}
handler.sendEmptyMessage(handler_key.START_TIMER.ordinal());
}
private enum handler_key {
/**
*
*/
TIMER_TEXT,
/**
*
*/
START_TIMER,
/**
*
*/
SUCCESSFUL,
/**
*
*/
FAILED,
}
/**
* The handler.
*/
Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
handler_key key = handler_key.values()[msg.what];
switch (key) {
case START_TIMER:
isStartTimer();
break;
case SUCCESSFUL:
Toast.makeText(GosAirlinkConfigCountdownActivity.this,
R.string.configuration_successful, toastTime).show();
Intent intent1 = new Intent(GosAirlinkConfigCountdownActivity.this, GosMainActivity.class);
startActivity(intent1);
break;
case FAILED:
if (GosDeploy.appConfig_Config_Softap()) {
Toast.makeText(GosAirlinkConfigCountdownActivity.this,
getString(R.string.configuration_timeout), toastTime).show();
Intent intent = new Intent(
GosAirlinkConfigCountdownActivity.this,
GosDeviceReadyActivity.class);
/** 判断是否是从一键配置界面传过去的 */
intent.putExtra("isAirLink", true);
startActivity(intent);
} else {
Intent intent = new Intent(
GosAirlinkConfigCountdownActivity.this,
GosConfigFailedActivity.class);
/** 判断是否是从一键配置界面传过去的 */
intent.putExtra("isAirLink", true);
startActivity(intent);
}
break;
default:
break;
}
}
};
// 屏蔽掉返回键
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent intent = new Intent(GosAirlinkConfigCountdownActivity.this, GosMainActivity.class);
//quitAlert(this, intent);
quitAlert(this, intent, getString(R.string.cancel_configuration));
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
return true;
}
return false;
}
// 倒计时
public void isStartTimer() {
secondleft = 60;
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
secondleft--;
rpbConfig.setProgress((60 - secondleft) * (100 / 60.0));
}
}, 1000, 1000);
}
/**
*
*
* @param result
* @param mac MAC
* @param did DID
* @param productKey PK
*/
protected void didSetDeviceOnboarding(GizWifiErrorCode result, String mac,
String did, String productKey) {
if (GizWifiErrorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING == result) {
return;
}
if (timer != null) {
timer.cancel();
}
Message message = new Message();
if (result == GizWifiErrorCode.GIZ_SDK_SUCCESS) {
message.what = handler_key.SUCCESSFUL.ordinal();
} else if (result == GIZ_SDK_ONBOARDING_STOPPED) {
} else {
message.what = handler_key.FAILED.ordinal();
message.obj = toastError(result);
}
Log.i("Apptest", result.toString());
handler.sendMessage(message);
}
}

@ -0,0 +1,132 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.utils.AssetsUtils;
import com.gizwits.opensource.appkit.utils.ToolUtils;
import java.util.ArrayList;
import java.util.List;
public class GosAirlinkReadyActivity extends GosConfigModuleBaseActivity implements OnClickListener {
/**
* The tv Ready
*/
TextView tvReady;
/**
* The btn Next
*/
Button btnNext;
TextView tvDeviceTip;
private int sum = 0;
//private TextView moudlechoose;
private List<String> modeList;
private ImageView ivReady;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actvity_gos_airlink_ready);
// 设置ActionBar
setToolBar(true, R.string.airlink_ready_title);
initData();
initView();
initEvent();
}
private void initData() {
// workSSID = spf.getString("workSSID", "");
modeList = new ArrayList<String>();
String[] modes = this.getResources().getStringArray(R.array.mode);
for (String string : modes) {
modeList.add(string);
}
}
private void initView() {
tvReady = (TextView) findViewById(R.id.tvReady);
btnNext = (Button) findViewById(R.id.btnNext);
tvDeviceTip = (TextView) findViewById(R.id.tvDeviceTip);
ivReady = (ImageView) findViewById(R.id.ivReady);
SpannableString spannableString = new SpannableString(getString(R.string.common_ready_message));
if (AssetsUtils.isZh(this)) {
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#007AFF")), 9, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#007AFF")), 28, 45, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
tvReady.setText(spannableString);
// 配置文件部署
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
}
private void initEvent() {
btnNext.setOnClickListener(this);
tvDeviceTip.setOnClickListener(this);
ivReady.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnNext:
if (ToolUtils.noDoubleClick()) {
sum = 0;
Intent intent = new Intent(this, GosAirlinkConfigCountdownActivity.class);
startActivity(intent);
}
break;
default:
break;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
sum = 0;
this.finish();
//overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
break;
}
return true;
}
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event) {
// Intent intent = new Intent(this, GosAirlinkChooseDeviceWorkWiFiActivity.class);
// startActivity(intent);
// overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
// this.finish();
// return true;
// }
}

@ -0,0 +1,279 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.wifi.ScanResult;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.log.SDKLog;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.utils.AssetsUtils;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
@SuppressLint({"InflateParams", "HandlerLeak"})
public class GosChooseDeviceActivity extends GosConfigModuleBaseActivity implements OnClickListener {
/**
* The tv Nodevice
*/
TextView tvNodevice;
/**
* The list View
*/
ListView listView;
/**
* WiFi
*/
ArrayList<ScanResult> list;
/**
*
*/
ArrayList<ScanResult> softList;
/**
*
*/
Myadapter myadapter;
/**
*
*/
Timer timer;
int flag = 0;
private enum handler_key {
/**
*
*/
UPDATALIST,
}
Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
super.handleMessage(msg);
handler_key key = handler_key.values()[msg.what];
switch (key) {
// 更新列表
case UPDATALIST:
initData();
break;
}
}
;
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_choose_device);
// 设置ActionBar
setToolBar(true, R.string.choosedevice);
initView();
initEvent();
}
@Override
protected void onResume() {
super.onResume();
startTimer();
}
@Override
public void onPause() {
super.onPause();
timer.cancel();
}
private void initData() {
// list = new ArrayList<ScanResult>();
list = (ArrayList<ScanResult>) GosConstant.ssidList;
//list = (ArrayList<ScanResult>) NetUtils.getCurrentWifiScanResult(GosChooseDeviceActivity.this);
softList = new ArrayList<ScanResult>();
ScanResult scanResult;
for (int i = 0; i < list.size(); i++) {
scanResult = list.get(i);
if (scanResult.SSID.length() > SoftAP_Start.length()) {
if (scanResult.SSID.contains(SoftAP_Start)) {
softList.add(scanResult);
}
}
}
myadapter = new Myadapter(softList);
listView.setAdapter(myadapter);
}
private void initView() {
tvNodevice = (TextView) findViewById(R.id.nodevice);
listView = (ListView) findViewById(R.id.list_view);
}
private void initEvent() {
tvNodevice.setOnClickListener(this);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(GosChooseDeviceActivity.this, GosConfigCountdownActivity.class);
intent.putExtra("softSSID", softList.get(position).SSID);
startActivity(intent);
finish();
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.nodevice:
if (list == null) {
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
// 未打开位置开关,可能导致定位失败或定位不准,提示用户或做相应处理
Toast.makeText(this, getString(R.string.open), Toast.LENGTH_LONG).show();
return;
}
} else if (list.size() == 0) {
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
// 未打开位置开关,可能导致定位失败或定位不准,提示用户或做相应处理
Toast.makeText(this, getString(R.string.open), Toast.LENGTH_LONG).show();
return;
}
}
finish();
break;
default:
break;
}
}
private void startTimer() {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(handler_key.UPDATALIST.ordinal());
}
}, 0, 3000);
}
class Myadapter extends BaseAdapter {
ArrayList<ScanResult> softList;
public Myadapter(ArrayList<ScanResult> list) {
this.softList = list;
}
@Override
public int getCount() {
return softList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
Holder holder;
if (view == null) {
view = LayoutInflater.from(GosChooseDeviceActivity.this).inflate(R.layout.item_gos_wifi_device, null);
holder = new Holder(view);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
String ssid = softList.get(position).SSID;
// String itemStart = (String) getText(R.string.itemtext_start);
// String itemEnd = (String) getText(R.string.itemtext_end);
String s = "";
if (AssetsUtils.isZh(GosChooseDeviceActivity.this)) {
s = getString(R.string.device) + ssid.substring(ssid.length() - 4);
} else {
s = getString(R.string.device) + " " + ssid.substring(ssid.length() - 4);
}
holder.getTextView().setText(s);
return view;
}
}
class Holder {
View view;
public Holder(View view) {
this.view = view;
}
TextView textView;
public TextView getTextView() {
if (textView == null) {
textView = (TextView) view.findViewById(R.id.SSID_text);
}
return textView;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return true;
}
// 屏蔽掉返回键
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return false;
}
}

@ -0,0 +1,465 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.NetUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class GosChooseDeviceWorkWiFiActivity extends GosConfigModuleBaseActivity
implements OnClickListener, OnItemClickListener {
private AlertDialog create;
private ArrayList<ScanResult> wifiList;
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.ACCESS_COARSE_LOCATION"};
/**
* wifi
*/
public WifiInfo wifiInfo;
/**
* The et SSID
*/
private EditText etSSID;
/**
* The et Psw
*/
private EditText etPsw;
/**
* The btn Next
*/
private Button btnNext;
/**
* The cb Laws
*/
private CheckBox cbLaws;
/**
* The img WiFiList
*/
private RelativeLayout rlWiFiList;
/**
*
*/
private String softSSID, workSSID, workSSIDPsw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_choose_device_workwifi);
// 设置ActionBar
setToolBar(true, R.string.choose_wifi);
initData();
initView();
ininEvent();
}
private void initView() {
etSSID = (EditText) findViewById(R.id.etSSID);
etPsw = (EditText) findViewById(R.id.etPsw);
btnNext = (Button) findViewById(R.id.btnNext);
cbLaws = (CheckBox) findViewById(R.id.cbLaws);
rlWiFiList = (RelativeLayout) findViewById(R.id.rlWiFiList);
// 配置文件部署
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
if (!TextUtils.isEmpty(workSSID)) {
etSSID.setText(workSSID);
etSSID.setSelection(workSSID.length());
if (checkworkSSIDUsed(workSSID)) {
if (!TextUtils.isEmpty(spf.getString("workSSIDPsw", ""))) {
etPsw.setText(spf.getString("workSSIDPsw", ""));
}
}
}
}
private void ininEvent() {
btnNext.setOnClickListener(this);
rlWiFiList.setOnClickListener(this);
cbLaws.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String psw = etPsw.getText().toString();
if (isChecked) {
etPsw.setInputType(0x90);
} else {
etPsw.setInputType(0x81);
}
etPsw.setSelection(psw.length());
}
});
//检测是否有位置定位的权限
int permission = ActivityCompat.checkSelfPermission(GosChooseDeviceWorkWiFiActivity.this,
"android.permission.ACCESS_FINE_LOCATION");
if (permission != PackageManager.PERMISSION_GRANTED) {
try {
// 没有写的权限,去申请写的权限,会弹出对话框
ActivityCompat.requestPermissions(GosChooseDeviceWorkWiFiActivity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void initData() {
//softSSID = getIntent().getStringExtra("softssid");
workSSID = spf.getString("workSSID", "");
}
@Override
protected void onResume() {
super.onResume();
try {
// 预设workSSID && workSSIDPsw
workSSID = NetUtils.getCurentWifiSSID(this);
String mypass = spf.getString("mypass", "");
if (!TextUtils.isEmpty(workSSID)) {
etSSID.setText(workSSID);
etSSID.setSelection(workSSID.length());
if (!TextUtils.isEmpty(mypass)) {
JSONObject obj = new JSONObject(mypass);
if (obj.has(workSSID)) {
String pass = obj.getString(workSSID);
etPsw.setText(pass);
} else {
etPsw.setText("");
}
}
} else {
etSSID.setText(NetUtils.getCurentWifiSSID(this));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent intent = new Intent(this, GosMainActivity.class);
startActivity(intent);
//quitAlert(this, intent);
break;
}
return true;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnNext:
workSSID = etSSID.getText().toString();
workSSIDPsw = etPsw.getText().toString();
if (TextUtils.isEmpty(workSSID)) {
Toast.makeText(GosChooseDeviceWorkWiFiActivity.this, R.string.choose_wifi_list_title,
Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(workSSIDPsw)) {
final Dialog dialog = new AlertDialog.Builder(this, R.style.alert_dialog_style)
.setView(new EditText(this)).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_empty);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (dialog.isShowing()) {
dialog.cancel();
}
Intent intent = null;
//wifiModuleType-false-start wifiModuleType-true-start
if (GosDeploy.appConfig_WifiModuleType().size() == 0) {
//wifiModuleType-false-end
intent = new Intent(GosChooseDeviceWorkWiFiActivity.this,
GosModeListActivity2.class);
//wifiModuleType-false-start
} else {
//wifiModuleType-true-end
List<Integer> moduleTypes = GosDeploy.appConfig_WifiModuleType();
JSONArray array = new JSONArray();
for (int type : moduleTypes) {
if (type == 4) {
type = 0;
} else if (type < 4) {
type = type + 1;
} else if (type == 12) {
type = 6;
} else if (type >= 6 && type < 12) {
type = type + 1;
}
array.put(type);
}
spf.edit().putString("modulestyles", array.toString()).commit();
intent = new Intent(GosChooseDeviceWorkWiFiActivity.this,
GosDeviceReadyActivity.class);
//wifiModuleType-true-start
}
//wifiModuleType-false-end wifiModuleType-true-end
spf.edit().putString("workSSID", workSSID).commit();
spf.edit().putString("workSSIDPsw", workSSIDPsw).commit();
intent.putExtra("isAirlink", false);
startActivity(intent);
}
});
} else {
Intent intent = null;
//wifiModuleType-false-start wifiModuleType-true-start
if (GosDeploy.appConfig_WifiModuleType().size() == 0) {
//wifiModuleType-false-end
intent = new Intent(GosChooseDeviceWorkWiFiActivity.this,
GosModeListActivity2.class);
//wifiModuleType-false-start
} else {
//wifiModuleType-true-end
List<Integer> moduleTypes = GosDeploy.appConfig_WifiModuleType();
JSONArray array = new JSONArray();
for (int type : moduleTypes) {
if (type == 4) {
type = 0;
} else if (type < 4) {
type = type + 1;
} else if (type == 12) {
type = 6;
} else if (type >= 6 && type < 12) {
type = type + 1;
}
array.put(type);
}
spf.edit().putString("modulestyles", array.toString()).commit();
intent = new Intent(GosChooseDeviceWorkWiFiActivity.this,
GosDeviceReadyActivity.class);
//wifiModuleType-true-start
}
//wifiModuleType-false-end wifiModuleType-true-end
spf.edit().putString("workSSID", workSSID).commit();
spf.edit().putString("workSSIDPsw", workSSIDPsw).commit();
/** 判断是否是从一键配置界面传过去的 */
intent.putExtra("isAirlink", false);
startActivity(intent);
}
break;
case R.id.rlWiFiList:
AlertDialog.Builder dia = new AlertDialog.Builder(GosChooseDeviceWorkWiFiActivity.this);
View view = View.inflate(GosChooseDeviceWorkWiFiActivity.this, R.layout.alert_gos_wifi_list, null);
ListView listview = (ListView) view.findViewById(R.id.wifi_list);
List<ScanResult> rsList = NetUtils.getCurrentWifiScanResult(this);
List<String> localList = new ArrayList<String>();
localList.clear();
wifiList = new ArrayList<ScanResult>();
wifiList.clear();
for (ScanResult sss : rsList) {
if (sss.SSID.contains(GosConstant.SoftAP_Start)) {
} else {
if (localList.toString().contains(sss.SSID)) {
} else {
localList.add(sss.SSID);
wifiList.add(sss);
}
}
}
if (wifiList.size() == 0) {
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
// 未打开位置开关,可能导致定位失败或定位不准,提示用户或做相应处理
Toast.makeText(this, getString(R.string.open), Toast.LENGTH_LONG).show();
return;
}
}
WifiListAdapter adapter = new WifiListAdapter(wifiList);
listview.setAdapter(adapter);
listview.setOnItemClickListener(this);
dia.setView(view);
create = dia.create();
create.show();
break;
default:
break;
}
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
ScanResult sResult = wifiList.get(arg2);
String sSID = sResult.SSID;
etSSID.setText(sSID);
etSSID.setSelection(sSID.length());
etPsw.setText("");
create.dismiss();
}
// 检查当前使用的WiFi是否曾经用过
protected boolean checkworkSSIDUsed(String workSSID) {
if (spf.contains("workSSID")) {
if (spf.getString("workSSID", "").equals(workSSID)) {
return true;
}
}
return false;
}
// 屏蔽掉返回键
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent intent = new Intent(this, GosMainActivity.class);
startActivity(intent);
//quitAlert(this, intent);
return true;
}
return false;
}
class WifiListAdapter extends BaseAdapter {
ArrayList<ScanResult> xpgList;
public WifiListAdapter(ArrayList<ScanResult> list) {
this.xpgList = list;
}
@Override
public int getCount() {
return xpgList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
Holder holder;
if (view == null) {
view = LayoutInflater.from(GosChooseDeviceWorkWiFiActivity.this).inflate(R.layout.item_gos_wifi_list,
null);
holder = new Holder(view);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
String ssid = xpgList.get(position).SSID;
holder.getTextView().setText(ssid);
return view;
}
}
class Holder {
View view;
public Holder(View view) {
this.view = view;
}
TextView textView;
public TextView getTextView() {
if (textView == null) {
textView = (TextView) view.findViewById(R.id.SSID_text);
}
return textView;
}
}
}

@ -0,0 +1,41 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.AssetsUtils;
/**
* Created by admin on 2017/6/15.
*/
public class GosChooseModuleHelpActivity extends com.gizwits.opensource.appkit.ConfigModule.GosConfigModuleBaseActivity {
private WebView webHelp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_choose_module_help);
initView();
initEvent();
}
private void initEvent() {
setToolBar(true, getString(R.string.module_help));
WebSettings wSet = webHelp.getSettings();
wSet.setJavaScriptEnabled(true);
if (AssetsUtils.isZh(this)) {
webHelp.loadUrl("file:///android_asset/moduleTypeInfo.html");
} else {
webHelp.loadUrl("file:///android_asset/moduleTypeInfoEnglish.html");
}
}
private void initView() {
webHelp = (WebView) findViewById(R.id.webHelp);
}
}

@ -0,0 +1,424 @@
package com.gizwits.opensource.appkit.ConfigModule;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizWifiConfigureMode;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.enumration.GizWifiGAgentType;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
import com.gizwits.opensource.appkit.utils.NetUtils;
import com.gizwits.opensource.appkit.view.RoundProgressBar;
import com.gizwits.opensource.appkit.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import static com.gizwits.gizwifisdk.enumration.GizWifiErrorCode.GIZ_SDK_ONBOARDING_STOPPED;
@SuppressLint("HandlerLeak")
public class GosConfigCountdownActivity extends GosConfigModuleBaseActivity {
private GosWifiChangeReciver broadcase;
/**
* The rpb Config
*/
private RoundProgressBar rpbConfig;
/**
*
*/
int secondleft = 60;
/**
* The timer
*/
Timer timer;
/**
* The Frist
*/
boolean isFrist = true;
/**
* The isChecked
*/
boolean isChecked = false;
String softSSID, presentSSID, workSSID, workSSIDPsw;
private boolean isShowing = false;
private String SSID = null, SSIDPsw = null;
List<GizWifiGAgentType> modeList, modeDataList;
private TextView tvLeft;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_config_countdown);
// 设置ActionBar
setToolBar(false, R.string.search_join);
initView();
initData();
tvLeft = (TextView) findViewById(R.id.tvLeft);
tvLeft.setVisibility(View.VISIBLE);
SpannableString ssTitle = new SpannableString(this.getString(R.string.cancel));
ssTitle.setSpan(new ForegroundColorSpan(GosDeploy.appConfig_Contrast()), 0, ssTitle.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
tvLeft.setText(ssTitle);
tvLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(GosConfigCountdownActivity.this, GosMainActivity.class);
quitAlert(GosConfigCountdownActivity.this, intent, getString(R.string.cancel_configuration));
}
});
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus && isFrist) {
isShowing = true;
new Thread() {
public void run() {
try {
Thread.sleep(1 * 1000);
readyToSoftAP();
} catch(InterruptedException e) {
e.printStackTrace();
}
}
;
}.start();
isFrist = false;
}
}
private void initView() {
rpbConfig = (RoundProgressBar) findViewById(R.id.rpbConfig);
}
private void initData() {
softSSID = getIntent().getStringExtra("softSSID");
workSSIDPsw = spf.getString("workSSIDPsw", "");
modeDataList = new ArrayList<GizWifiGAgentType>();
modeDataList.add(GizWifiGAgentType.GizGAgentESP);
modeDataList.add(GizWifiGAgentType.GizGAgentMXCHIP);
modeDataList.add(GizWifiGAgentType.GizGAgentHF);
modeDataList.add(GizWifiGAgentType.GizGAgentRTK);
modeDataList.add(GizWifiGAgentType.GizGAgentWM);
modeDataList.add(GizWifiGAgentType.GizGAgentQCA);
modeDataList.add(GizWifiGAgentType.GizGAgentFlyLink);
modeDataList.add(GizWifiGAgentType.GizGAgentTI);
modeDataList.add(GizWifiGAgentType.GizGAgentFSK);
modeDataList.add(GizWifiGAgentType.GizGAgentMXCHIP3);
modeDataList.add(GizWifiGAgentType.GizGAgentBL);
modeDataList.add(GizWifiGAgentType.GizGAgentAtmelEE);
modeDataList.add(GizWifiGAgentType.GizGAgentOther);
modeList = new ArrayList<GizWifiGAgentType>();
String types = spf.getString("modulestyles", null);
if (types != null) {
try {
JSONArray array = new JSONArray(types);
for (int i = 0; i < array.length(); i++) {
int type = (Integer) array.get(i);
modeList.add(modeDataList.get(type));
}
} catch(JSONException e) {
e.printStackTrace();
}
}
}
private enum handler_key {
/**
*
*/
TICK_TIME,
/**
*
*/
OPEN_HOT,
/**
*
*/
START_TIMER,
/**
*
*/
SUCCESSFUL,
/**
*
*/
FAILED,
}
private static final String TAG = "GosConfigCountdownActiv";
/**
* The handler.
*/
Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
handler_key key = handler_key.values()[msg.what];
switch (key) {
case TICK_TIME:
break;
case OPEN_HOT:
if (GosConstant.isOpenHot) {
boolean b = setWifiApEnabled(true);
// boolean b = setWifiAp(true);
}
break;
case START_TIMER:
isStartTimer();
break;
// 配置成功
case SUCCESSFUL:
Toast.makeText(GosConfigCountdownActivity.this, R.string.configuration_successful, toastTime)
.show();
Intent intent1 = new Intent(GosConfigCountdownActivity.this, GosMainActivity.class);
startActivity(intent1);
break;
// 配置失败
case FAILED:
isChecked = false;
if (msg.obj != null) {
Toast.makeText(GosConfigCountdownActivity.this, msg.obj.toString(), toastTime)
.show();
}
Intent intent = new Intent(GosConfigCountdownActivity.this, GosConfigFailedActivity.class);
startActivity(intent);
finish();
break;
default:
break;
}
}
};
// 屏蔽掉返回键
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
quitAlert(this, timer);
return true;
}
return false;
}
// 倒计时
public void isStartTimer() {
secondleft = 60;
timer = new Timer();
// 切换至设备热点
wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
final WifiAutoConnectManager.WifiCipherType cipherType = WifiAutoConnectManager.getCipherType(GosConfigCountdownActivity.this, softSSID);
final WifiAutoConnectManager manager = new WifiAutoConnectManager(wifiManager);
timer.schedule(new TimerTask() {
@Override
public void run() {
if (isShowing) {
manager.connect(softSSID, SoftAP_PSW, cipherType);
}
secondleft--;
rpbConfig.setProgress((60 - secondleft) * (100 / 60.0));
if (secondleft == 1) {
handler.sendEmptyMessage(handler_key.FAILED.ordinal());
timer.cancel();
}
}
}, 1000, 1000);
}
private void readyToSoftAP() {
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
workSSID = spf.getString("workSSID", "");
workSSIDPsw = spf.getString("workSSIDPsw", "");
if (!workSSIDPsw.isEmpty() && workSSIDPsw.equals(GosConstant.SSIDPsw)) {
GosConstant.isOpenHot = true;
}
//新加
handler.sendEmptyMessage(handler_key.START_TIMER.ordinal());
isChecked = true;
while (isChecked) {
String presentSSID = NetUtils.getCurentWifiSSID(GosConfigCountdownActivity.this);
if (!TextUtils.isEmpty(presentSSID) && presentSSID.contains(SoftAP_Start)) {
if (checkNetwork(GosConfigCountdownActivity.this)) {
String connectWifiSsid = NetUtils.getConnectWifiSsid(GosConfigCountdownActivity.this);
isShowing = false;
isChecked = false;
//handler.sendEmptyMessage(handler_key.START_TIMER.ordinal());
switch (GosConstant.mNew) {
case 0:
GizWifiSDK.sharedInstance().setDeviceOnboarding(workSSID, workSSIDPsw,
GizWifiConfigureMode.GizWifiSoftAP, presentSSID, 60, modeList);
break;
case 1:
GizWifiSDK.sharedInstance().setDeviceOnboardingByBind(workSSID, workSSIDPsw,
GizWifiConfigureMode.GizWifiSoftAP, presentSSID, 60, modeList);
break;
case 2:
GizWifiSDK.sharedInstance().setDeviceOnboardingDeploy(workSSID, workSSIDPsw,
GizWifiConfigureMode.GizWifiSoftAP, presentSSID, 60, modeList, false);
break;
case 3:
GizWifiSDK.sharedInstance().setDeviceOnboardingDeploy(workSSID, workSSIDPsw,
GizWifiConfigureMode.GizWifiSoftAP, presentSSID, 60, modeList, true);
break;
}
if (GosConstant.isOpenHot) {
final Timer mtimer1 = new Timer();
mtimer1.schedule(new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(handler_key.OPEN_HOT.ordinal());
}
}, 5 * 1000);
}
// handler.sendEmptyMessageDelayed(handler_key.OFFTIME.ordinal(), 2000);
}
if (broadcase == null && !GosConstant.isOpenHot) {
broadcase = new GosWifiChangeReciver();
registerReceiver(broadcase, filter);
}
}
}
}
private WifiManager wifiManager = null;
// wifi热点开关
public boolean setWifiApEnabled(boolean enabled) {
//获取wifi管理服务
if (enabled) { // disable WiFi in any case
//wifi和热点不能同时打开所以打开热点的时候需要关闭wifi
wifiManager.setWifiEnabled(false);
}
try {
//热点的配置类
WifiConfiguration apConfig = new WifiConfiguration();
//配置热点的名称(可以在名字后面加点随机数什么的)
if (SSID == null && SSID.equals("")) {
SSID = android.os.Build.MODEL;
apConfig.SSID = SSID;
apConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
} else if (SSIDPsw == null && SSIDPsw.equals("")) {
apConfig.SSID = SSID;
apConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
} else {
apConfig.SSID = SSID;
//配置热点的密码
apConfig.preSharedKey = SSIDPsw;
//返回热点打开状态
// for (int i = 0; i < WifiConfiguration.KeyMgmt.strings.length; i++) {
// if ("WPA2_PSK".equals(WifiConfiguration.KeyMgmt.strings[i])) {
// apConfig.allowedKeyManagement.set(i);//直接给它赋索引的值
// Log.e("wpa2索引", String.valueOf(i));//结果是4
// }
// }
apConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);//直接给它赋索引的值
}
//通过反射调用设置热点
Method method = wifiManager.getClass().getMethod(
"setWifiApEnabled", WifiConfiguration.class, Boolean.TYPE);
//返回热点打开状态
return (Boolean) method.invoke(wifiManager, apConfig, enabled);
} catch(Exception e) {
return false;
}
}
/**
*
*
* @param result
* @param mac MAC
* @param did DID
* @param productKey PK
*/
protected void didSetDeviceOnboarding(GizWifiErrorCode result, String mac, String did, String productKey) {
if (GizWifiErrorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING == result) {
return;
}
if (timer != null) {
timer.cancel();
}
Message message = new Message();
if (result == GizWifiErrorCode.GIZ_SDK_SUCCESS) {
message.what = handler_key.SUCCESSFUL.ordinal();
} else if (result == GIZ_SDK_ONBOARDING_STOPPED) {
} else {
message.what = handler_key.FAILED.ordinal();
message.obj = toastError(result);
}
handler.sendMessage(message);
}
@Override
protected void onDestroy() {
super.onDestroy();
isChecked = false;
if (timer != null) {
timer.cancel();
}
if (broadcase != null) {
unregisterReceiver(broadcase);
broadcase = null;
}
}
}

@ -0,0 +1,118 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.content.Intent;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
import com.gizwits.opensource.appkit.utils.ToolUtils;
public class GosConfigFailedActivity extends GosConfigModuleBaseActivity implements OnClickListener {
/**
* The btn Again
*/
Button btnAgain;
/**
* The soft SSID
*/
String softSSID;
/**
* The data
*/
String promptText, cancelBesureText, beSureText, cancelText;
private boolean isAirLink;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_config_failed);
// 设置ActionBar
setToolBar(false, R.string.join_failed_title);
TextView tvLeft = (TextView) findViewById(R.id.tvLeft);
tvLeft.setVisibility(View.VISIBLE);
SpannableString ssTitle = new SpannableString(this.getString(R.string.cancel));
ssTitle.setSpan(new ForegroundColorSpan(GosDeploy.appConfig_Contrast()), 0, ssTitle.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
tvLeft.setText(ssTitle);
tvLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(GosConfigFailedActivity.this, GosMainActivity.class);
quitAlert(GosConfigFailedActivity.this, intent);
}
});
initView();
initEvent();
initData();
}
private void initView() {
btnAgain = (Button) findViewById(R.id.btnAgain);
// 配置文件部署
btnAgain.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnAgain.setTextColor(GosDeploy.appConfig_Contrast());
}
private void initEvent() {
btnAgain.setOnClickListener(this);
}
private void initData() {
/** 判断是否是从一键配置界面传过去的 */
isAirLink = getIntent().getBooleanExtra("isAirLink", false);
promptText = (String) getText(R.string.prompt);
cancelBesureText = (String) getText(R.string.cancel_besure);
beSureText = (String) getText(R.string.besure);
cancelText = (String) getText(R.string.cancel);
}
// 屏蔽掉返回键
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent intent = new Intent(GosConfigFailedActivity.this, GosMainActivity.class);
quitAlert(this, intent);
return true;
}
return false;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnAgain:
if (ToolUtils.noDoubleClick()) {
if (isAirLink) {
//config_airlink-false-start
Intent intent = new Intent(this, GosAirlinkChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
//config_airlink-false-end
} else {
// config_softap-false-start
Intent intent = new Intent(this, GosChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
// config_softap-false-end
}
}
break;
default:
break;
}
}
}

@ -0,0 +1,238 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizWifiSDKListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import java.util.List;
import java.util.Timer;
public class GosConfigModuleBaseActivity extends GosBaseActivity {
private GizWifiSDKListener gizWifiSDKListener = new GizWifiSDKListener() {
/** 用于设备配置 */
public void didSetDeviceOnboarding(GizWifiErrorCode result, String mac, String did, String productKey) {
GosConfigModuleBaseActivity.this.didSetDeviceOnboarding(result, mac, did, productKey);
}
};
/**
*
*
* @param result
* @param mac MAC
* @param did DID
* @param productKey PK
*/
protected void didSetDeviceOnboarding(GizWifiErrorCode result, String mac, String did, String productKey) {
}
@Override
protected void onResume() {
super.onResume();
// 每次返回activity都要注册一次sdk监听器保证sdk状态能正确回调
GizWifiSDK.sharedInstance().setListener(gizWifiSDKListener);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
break;
}
return super.onOptionsItemSelected(item);
}
/**
*
*
* @param context
*/
protected void quitAlert(Context context, final Intent intent) {
final Dialog dialog = new AlertDialog.Builder(this, R.style.alert_dialog_style)
.setView(new EditText(this)).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_quit);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (dialog.isShowing()) {
dialog.cancel();
}
startActivity(intent);
}
});
}
/**
*
*
* @param context
*/
protected void quitAlert(Context context) {
final Dialog dialog = new AlertDialog.Builder(context, R.style.alert_dialog_style).setView(new EditText(context)).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_quit);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (dialog.isShowing()) {
dialog.cancel();
}
finish();
}
});
}
/**
*
*
* @param context
*/
protected void quitAlert(Context context, final Intent intent, String content) {
final Dialog dialog = new AlertDialog.Builder(this, R.style.alert_dialog_style)
.setView(new EditText(this)).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_quit);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
TextView tvContent;
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
tvContent = (TextView) window.findViewById(R.id.tv_prompt);
tvContent.setText(content);
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
GizWifiSDK.sharedInstance().stopDeviceOnboarding();
startActivity(intent);
}
});
}
/**
* 退
*
* @param context
* @param timer
*/
protected void quitAlert(Context context, final Timer timer) {
final Dialog dialog = new AlertDialog.Builder(this, R.style.alert_dialog_style)
.setView(new EditText(this)).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_quit);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
GizWifiSDK.sharedInstance().stopDeviceOnboarding();
if (timer != null) {
timer.cancel();
}
if (dialog.isShowing()) {
dialog.cancel();
}
finish();
}
});
}
}

@ -0,0 +1,139 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.AssetsUtils;
import com.gizwits.opensource.appkit.utils.ToolUtils;
public class GosDeviceReadyActivity extends GosConfigModuleBaseActivity implements OnClickListener {
/**
* The tv Ready
*/
TextView tvReady;
/**
* The tv DeviceTip
*/
TextView tvDeviceTips;
/**
* The btn Next
*/
Button btnNext;
private int sum = 0;
/**
* The flag
*/
boolean flag = false;
boolean isAirLink = false;
private ImageView ivReady;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_device_ready);
// 设置ActionBar
setToolBar(true, R.string.model_confirmation);
/** 判断是否是从一键配置界面传过去的 */
isAirLink = getIntent().getBooleanExtra("isAirLink", false);
initView();
initEvent();
}
private void initView() {
tvReady = (TextView) findViewById(R.id.tvReady);
tvDeviceTips = (TextView) findViewById(R.id.tvDeviceTip);
btnNext = (Button) findViewById(R.id.btnNext);
ivReady = (ImageView) findViewById(R.id.ivReady);
SpannableString spannableString = new SpannableString(getString(R.string.common_ready_message));
if (AssetsUtils.isZh(this)) {
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF9500")), 9, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF9500")), 28, 45, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
tvReady.setText(spannableString);
// 配置文件部署
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
}
private void initEvent() {
btnNext.setOnClickListener(this);
tvDeviceTips.setOnClickListener(this);
ivReady.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnNext:
if (ToolUtils.noDoubleClick()) {
sum = 0;
Intent intent2 = new Intent(GosDeviceReadyActivity.this, GosChooseDeviceActivity.class);
startActivity(intent2);
}
break;
default:
break;
}
}
// 屏蔽掉返回键
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
sum = 0;
if (isAirLink) {
Intent intent = new Intent(GosDeviceReadyActivity.this, GosMainActivity.class);
startActivity(intent);
} else {
finish();
}
return true;
}
return false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
sum = 0;
if (isAirLink) {
Intent intent = new Intent(GosDeviceReadyActivity.this, GosMainActivity.class);
startActivity(intent);
} else {
finish();
}
break;
}
return true;
}
}

@ -0,0 +1,143 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
public class GosDeviceResetActivity extends GosConfigModuleBaseActivity implements OnClickListener {
/**
* The cb Select
*/
CheckBox cbSelect;
/**
* The tv Select
*/
TextView tvSelect;
/**
* The btn Next
*/
Button btnNext;
/**
* The flag
*/
String flag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actvity_gos_device_reset);
// 设置ActionBar
setToolBar(true, R.string.reset_device);
initView();
initEvent();
}
private void initView() {
cbSelect = (CheckBox) findViewById(R.id.cbSelect);
tvSelect = (TextView) findViewById(R.id.tvSelect);
btnNext = (Button) findViewById(R.id.btnNext);
/** 加载标志位 */
flag = getIntent().getStringExtra("flag").toString();
// 配置文件部署
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
}
private void initEvent() {
btnNext.setOnClickListener(this);
tvSelect.setOnClickListener(this);
btnNext.setClickable(false);
btnNext.setBackgroundResource(R.drawable.btn_next_shape_gray);
cbSelect.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnNext.setClickable(true);
} else {
btnNext.setBackgroundResource(R.drawable.btn_next_shape_gray);
btnNext.setClickable(false);
}
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnNext:
if (TextUtils.isEmpty(flag)) {
Intent intent = new Intent(GosDeviceResetActivity.this, GosChooseDeviceActivity.class);
startActivity(intent);
}
finish();
break;
case R.id.tvSelect:
if (cbSelect.isChecked()) {
cbSelect.setChecked(false);
} else {
cbSelect.setChecked(true);
}
break;
default:
break;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (TextUtils.isEmpty(flag)) {
Intent intent = new Intent(GosDeviceResetActivity.this, GosDeviceReadyActivity.class);
startActivity(intent);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
}
this.finish();
break;
}
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (TextUtils.isEmpty(flag)) {
Intent intent = new Intent(GosDeviceResetActivity.this, GosDeviceReadyActivity.class);
startActivity(intent);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
}
this.finish();
}
return true;
}
}

@ -0,0 +1,222 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.utils.ToolUtils;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.List;
public class GosModeListActivity extends GosConfigModuleBaseActivity {
/**
* The lv Mode
*/
ListView lvMode;
/**
* The data
*/
List<String> modeList;
/**
* The Adapter
*/
ModeListAdapter modeListAdapter;
List<Integer> list = new ArrayList<Integer>();
private Button btnOk;
private boolean isAirlink = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_modelist);
// 设置ActionBar
setToolBar(true, R.string.choose_mode_start);
final Drawable add = getResources().getDrawable(R.drawable.config_help_button);
int color = GosDeploy.appConfig_Contrast();
add.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
mToolbar.setOverflowIcon(add);
initData();
initView();
initEvent();
}
private void initView() {
lvMode = (ListView) findViewById(R.id.lvMode);
lvMode.setAdapter(modeListAdapter);// 初始化
btnOk = (Button) findViewById(R.id.btnOk);
btnOk.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnOk.setTextColor(GosDeploy.appConfig_Contrast());
}
private void initEvent() {
lvMode.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
modeListAdapter.selectIndex = arg2;
modeListAdapter.notifyDataSetChanged();
}
});
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ToolUtils.noDoubleClick()) {
if (modeListAdapter.selectIndex == 100) {
Toast.makeText(GosModeListActivity.this, getString(R.string.selece_module_type), toastTime).show();
} else {
JSONArray array = new JSONArray();
array.put(modeListAdapter.selectIndex);
spf.edit().putString("modulestyles", array.toString()).commit();
if (isAirlink) {
// config_airlink-false-start
Intent intent = new Intent(GosModeListActivity.this, GosAirlinkReadyActivity.class);
startActivity(intent);
// config_airlink-false-end
} else {
//config_softap-false-start
Intent intent = new Intent(GosModeListActivity.this, GosDeviceReadyActivity.class);
startActivity(intent);
//config_softap-false-end
}
}
}
}
});
}
private void initData() {
isAirlink = getIntent().getBooleanExtra("isAirlink", true);
modeList = new ArrayList<String>();
String[] modes = this.getResources().getStringArray(R.array.mode);
for (String string : modes) {
modeList.add(string);
}
modeListAdapter = new ModeListAdapter(this, modeList);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.module_style, menu);
return super.onCreateOptionsMenu(menu);
}
class ModeListAdapter extends BaseAdapter {
Context context;
List<String> modeList;
int selectIndex = 100;
public ModeListAdapter(Context context, List<String> modeList) {
super();
this.context = context;
this.modeList = modeList;
if (spf.getString("modulestyles", null) != null) {
try {
JSONArray array = new JSONArray(spf.getString("modulestyles", null));
for (int i = 0; i < array.length(); i++) {
selectIndex = Integer.parseInt(array.get(i).toString());
}
} catch(JSONException e) {
e.printStackTrace();
}
}
}
@Override
public int getCount() {
return modeList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
convertView = View.inflate(context, R.layout.item_gos_mode_list, null);
}
TextView tvModeText = (TextView) convertView.findViewById(R.id.tvModeText);
String modeText = modeList.get(position);
tvModeText.setText(modeText);
ImageView ivChoosed = (ImageView) convertView.findViewById(R.id.ivChoosed);
if (selectIndex == position) {
ivChoosed.setVisibility(View.VISIBLE);
} else {
ivChoosed.setVisibility(View.GONE);
}
return convertView;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
break;
case R.id.module_help:
if (ToolUtils.noDoubleClick()) {
startActivity(new Intent(GosModeListActivity.this, GosChooseModuleHelpActivity.class));
}
break;
}
return true;
}
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event) {
// Intent intent = new Intent(this, GosAirlinkChooseDeviceWorkWiFiActivity.class);
// startActivity(intent);
// overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
// this.finish();
// return true;
// }
}

@ -0,0 +1,219 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.utils.ToolUtils;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.List;
public class GosModeListActivity2 extends GosConfigModuleBaseActivity {
/**
* The lv Mode
*/
ListView lvMode;
/**
* The data
*/
List<String> modeList;
/**
* The Adapter
*/
ModeListAdapter modeListAdapter;
List<Integer> list = new ArrayList<Integer>();
private Button btnOk;
private boolean isAirlink = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_modelist);
// 设置ActionBar
setToolBar(true, R.string.choose_mode_start);
initData();
initView();
initEvent();
}
private void initView() {
lvMode = (ListView) findViewById(R.id.lvMode);
lvMode.setAdapter(modeListAdapter);// 初始化
btnOk = (Button) findViewById(R.id.btnOk);
btnOk.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnOk.setTextColor(GosDeploy.appConfig_Contrast());
}
private void initEvent() {
lvMode.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
boolean isRemove = false;
for (int i = 0; i < list.size(); i++) {
if (list.get(i) == arg2) {
list.remove(i);
isRemove = true;
}
}
if (!isRemove) {
list.add(arg2);
}
modeListAdapter.notifyDataSetChanged();
}
});
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ToolUtils.noDoubleClick()) {
if (list.size() == 0) {
Toast.makeText(GosModeListActivity2.this, getString(R.string.selece_module_type), toastTime).show();
} else {
JSONArray array = new JSONArray();
for (int i = 0; i < list.size(); i++) {
array.put(list.get(i));
}
Log.e("TAG", "onClick: " + array.toString());
spf.edit().putString("modulestyles", array.toString()).commit();
if (isAirlink) {
// config_airlink-false-start
Intent intent = new Intent(GosModeListActivity2.this, GosAirlinkReadyActivity.class);
startActivity(intent);
// config_airlink-false-end
} else {
//config_softap-false-start
Intent intent = new Intent(GosModeListActivity2.this, GosDeviceReadyActivity.class);
startActivity(intent);
//config_softap-false-end
}
}
}
}
});
}
private void initData() {
isAirlink = getIntent().getBooleanExtra("isAirlink", true);
String modules = spf.getString("modulestyles", null);
if (modules != null) {
try {
JSONArray array = new JSONArray(modules);
for (int i = 0; i < array.length(); i++) {
int type = (Integer) array.get(i);
list.add(type);
}
} catch(JSONException e) {
e.printStackTrace();
}
}
modeList = new ArrayList<String>();
String[] modes = this.getResources().getStringArray(R.array.mode);
for (String string : modes) {
modeList.add(string);
}
modeListAdapter = new ModeListAdapter(this, modeList);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.module_style, menu);
MenuItem menuItem = menu.findItem(R.id.module_help);
menuItem.setIcon(ToolUtils.editIcon(getResources(), R.drawable.config_help_button));
return super.onCreateOptionsMenu(menu);
}
class ModeListAdapter extends BaseAdapter {
Context context;
List<String> modeList;
public ModeListAdapter(Context context, List<String> modeList) {
super();
this.context = context;
this.modeList = modeList;
}
@Override
public int getCount() {
return modeList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
convertView = View.inflate(context, R.layout.item_gos_mode_list, null);
}
TextView tvModeText = (TextView) convertView.findViewById(R.id.tvModeText);
String modeText = modeList.get(position);
tvModeText.setText(modeText);
ImageView ivChoosed = (ImageView) convertView.findViewById(R.id.ivChoosed);
if (list.contains(position)) {
ivChoosed.setVisibility(View.VISIBLE);
} else {
ivChoosed.setVisibility(View.GONE);
}
return convertView;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
break;
case R.id.module_help:
if (ToolUtils.noDoubleClick()) {
startActivity(new Intent(GosModeListActivity2.this, GosChooseModuleHelpActivity.class));
}
break;
}
return true;
}
}

@ -0,0 +1,36 @@
package com.gizwits.opensource.appkit.ConfigModule;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.utils.NetUtils;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.wifi.WifiManager;
public class GosWifiChangeReciver extends BroadcastReceiver {
SharedPreferences spf;
@Override
public void onReceive(Context context, Intent intent) {
spf = context.getSharedPreferences(GosBaseActivity.SPF_Name, Context.MODE_PRIVATE);
String wifiname = spf.getString("workSSID", "");
String wifipass = spf.getString("workSSIDPsw", "");
String connectWifiSsid = NetUtils.getConnectWifiSsid(context);
if (connectWifiSsid != null && connectWifiSsid.contains(GosBaseActivity.SoftAP_Start)) {
} else {
if (connectWifiSsid.contains(wifiname)) {
return;
}
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiAutoConnectManager manager = new WifiAutoConnectManager(wifiManager);
manager.connect(wifiname, wifipass, WifiAutoConnectManager.getCipherType(context, wifiname));
}
}
}

@ -0,0 +1,231 @@
package com.gizwits.opensource.appkit.ConfigModule;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
import android.util.Log;
import java.util.List;
public class WifiAutoConnectManager {
private static final String TAG = WifiAutoConnectManager.class
.getSimpleName();
WifiManager wifiManager;
// 定义几种加密方式一种是WEP一种是WPA还有没有密码的情况
public enum WifiCipherType {
WIFICIPHER_WEP, WIFICIPHER_WPA, WIFICIPHER_NOPASS, WIFICIPHER_INVALID
}
// 构造函数
public WifiAutoConnectManager(WifiManager wifiManager) {
this.wifiManager = wifiManager;
}
// 提供一个外部接口,传入要连接的无线网
public void connect(String ssid, String password, WifiCipherType type) {
Thread thread = new Thread(new ConnectRunnable(ssid, password, type));
thread.start();
}
// 查看以前是否也配置过这个网络
private WifiConfiguration isExsits(String SSID) {
List<WifiConfiguration> existingConfigs = wifiManager
.getConfiguredNetworks();
if (existingConfigs != null) {
for (WifiConfiguration existingConfig : existingConfigs) {
if (existingConfig.SSID != null) {
if (existingConfig.SSID.equals("\"" + SSID + "\"")) {
return existingConfig;
}
}
}
}
return null;
}
private WifiConfiguration createWifiInfo(String SSID, String Password,
WifiCipherType Type) {
WifiConfiguration config = new WifiConfiguration();
config.allowedAuthAlgorithms.clear();
config.allowedGroupCiphers.clear();
config.allowedKeyManagement.clear();
config.allowedPairwiseCiphers.clear();
config.allowedProtocols.clear();
config.SSID = "\"" + SSID + "\"";
// config.SSID = SSID;
// nopass
if (Type == WifiCipherType.WIFICIPHER_NOPASS) {
// config.wepKeys[0] = "";
config.allowedKeyManagement.set(KeyMgmt.NONE);
// config.wepTxKeyIndex = 0;
}
// wep
if (Type == WifiCipherType.WIFICIPHER_WEP) {
if (!TextUtils.isEmpty(Password)) {
if (isHexWepKey(Password)) {
config.wepKeys[0] = Password;
} else {
config.wepKeys[0] = "\"" + Password + "\"";
}
}
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.wepTxKeyIndex = 0;
}
// wpa
if (Type == WifiCipherType.WIFICIPHER_WPA) {
config.preSharedKey = "\"" + Password + "\"";
config.hiddenSSID = true;
config.allowedAuthAlgorithms
.set(AuthAlgorithm.OPEN);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers
.set(WifiConfiguration.PairwiseCipher.TKIP);
// 此处需要修改否则不能自动重联
// config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedPairwiseCiphers
.set(WifiConfiguration.PairwiseCipher.CCMP);
config.status = WifiConfiguration.Status.ENABLED;
}
return config;
}
// 打开wifi功能
private boolean openWifi() {
boolean bRet = true;
if (!wifiManager.isWifiEnabled()) {
bRet = wifiManager.setWifiEnabled(true);
}
return bRet;
}
// 关闭WIFI
private void closeWifi() {
if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
}
}
class ConnectRunnable implements Runnable {
private String ssid;
private String password;
private WifiCipherType type;
public ConnectRunnable(String ssid, String password, WifiCipherType type) {
this.ssid = ssid;
this.password = password;
this.type = type;
}
@Override
public void run() {
// 打开wifi
openWifi();
// 开启wifi功能需要一段时间(我在手机上测试一般需要1-3秒左右)所以要等到wifi
// 状态变成WIFI_STATE_ENABLED的时候才能执行下面的语句
while (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) {
try {
// 为了避免程序一直while循环让它睡个100毫秒检测……
Thread.sleep(100);
} catch (InterruptedException ie) {
Log.i(TAG, ie.toString());
}
}
WifiConfiguration tempConfig = isExsits(ssid);
if (tempConfig != null) {
// wifiManager.removeNetwork(tempConfig.networkId);
boolean b = wifiManager.enableNetwork(tempConfig.networkId,
true);
} else {
WifiConfiguration wifiConfig = createWifiInfo(ssid, password,
type);
//
if (wifiConfig == null) {
Log.d(TAG, "wifiConfig is null!");
return;
}
int netID = wifiManager.addNetwork(wifiConfig);
boolean enabled = wifiManager.enableNetwork(netID, true);
Log.d(TAG, "enableNetwork status enable=" + enabled);
boolean connected = wifiManager.reconnect();
Log.d(TAG, "enableNetwork connected=" + connected);
}
}
}
private static boolean isHexWepKey(String wepKey) {
final int len = wepKey.length();
// WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
if (len != 10 && len != 26 && len != 58) {
return false;
}
return isHex(wepKey);
}
private static boolean isHex(String key) {
for (int i = key.length() - 1; i >= 0; i--) {
final char c = key.charAt(i);
if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a'
&& c <= 'f')) {
return false;
}
}
return true;
}
// 获取ssid的加密方式
public static WifiCipherType getCipherType(Context context, String ssid) {
WifiManager wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
List<ScanResult> list = wifiManager.getScanResults();
for (ScanResult scResult : list) {
if (!TextUtils.isEmpty(scResult.SSID) && scResult.SSID.equals(ssid)) {
String capabilities = scResult.capabilities;
// Log.i("hefeng","capabilities=" + capabilities);
if (!TextUtils.isEmpty(capabilities)) {
if (capabilities.contains("WPA")
|| capabilities.contains("wpa")) {
Log.i("hefeng", "wpa");
return WifiCipherType.WIFICIPHER_WPA;
} else if (capabilities.contains("WEP")
|| capabilities.contains("wep")) {
Log.i("hefeng", "wep");
return WifiCipherType.WIFICIPHER_WEP;
} else {
Log.i("hefeng", "no");
return WifiCipherType.WIFICIPHER_NOPASS;
}
}
}
}
return WifiCipherType.WIFICIPHER_INVALID;
}
}

@ -0,0 +1,429 @@
package com.gizwits.opensource.appkit.ControlModule;
import java.text.DecimalFormat;
import java.util.concurrent.ConcurrentHashMap;
import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceNetStatus;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizWifiDeviceListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.utils.HexStrUtils;
import android.util.Log;
import android.content.Context;
import android.view.MenuItem;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
public class GosControlModuleBaseActivity extends GosBaseActivity {
/*
* ===========================================================
* key
* ===========================================================
*/
// 数据点"心率检测"对应的标识名
protected static final String KEY_HREAT = "hreat";
// 数据点"心率上限"对应的标识名
protected static final String KEY_HEARTUP = "heartup";
// 数据点"心率下限"对应的标识名
protected static final String KEY_HEARTDW = "heartdw";
// 数据点"血氧检测"对应的标识名
protected static final String KEY_SPO2 = "spo2";
// 数据点"血氧上限"对应的标识名
protected static final String KEY_SPO2UP = "spo2up";
// 数据点"血氧下限"对应的标识名
protected static final String KEY_SPO2DW = "spo2dw";
// 数据点"体温上限"对应的标识名
protected static final String KEY_TEMPUP = "tempup";
// 数据点"体温下限"对应的标识名
protected static final String KEY_TEMPDW = "tempdw";
// 数据点"计步步数"对应的标识名
protected static final String KEY_BUS = "bus";
// 数据点"GPS纬度N"对应的标识名
protected static final String KEY_GPS_N = "GPS_N";
// 数据点"体温检测"对应的标识名
protected static final String KEY_TEMP = "temp";
// 数据点"GPS经度E"对应的标识名
protected static final String KEY_GPS_E = "GPS_E";
/*
* ===========================================================
* seekbar
* _ADDITION:
* _RATIO:
* _OFFSET:seekbar
* APPyAPP=x* RATIO+ADDITION
* seekbarOFFSET
* x=seekbar+
* ===========================================================
*/
// 数据点"心率检测"对应seekbar滚动条补偿值
protected static final int HREAT_OFFSET = 0;
// 数据点"心率检测"对应数据点增量值
protected static final int HREAT_ADDITION = 0;
// 数据点"心率检测"对应数据点定义的分辨率
protected static final int HREAT_RATIO = 1;
// 数据点"心率上限"对应seekbar滚动条补偿值
protected static final int HEARTUP_OFFSET = 0;
// 数据点"心率上限"对应数据点增量值
protected static final int HEARTUP_ADDITION = 0;
// 数据点"心率上限"对应数据点定义的分辨率
protected static final int HEARTUP_RATIO = 1;
// 数据点"心率下限"对应seekbar滚动条补偿值
protected static final int HEARTDW_OFFSET = 0;
// 数据点"心率下限"对应数据点增量值
protected static final int HEARTDW_ADDITION = 0;
// 数据点"心率下限"对应数据点定义的分辨率
protected static final int HEARTDW_RATIO = 1;
// 数据点"血氧检测"对应seekbar滚动条补偿值
protected static final int SPO2_OFFSET = 0;
// 数据点"血氧检测"对应数据点增量值
protected static final int SPO2_ADDITION = 0;
// 数据点"血氧检测"对应数据点定义的分辨率
protected static final int SPO2_RATIO = 1;
// 数据点"血氧上限"对应seekbar滚动条补偿值
protected static final int SPO2UP_OFFSET = 0;
// 数据点"血氧上限"对应数据点增量值
protected static final int SPO2UP_ADDITION = 0;
// 数据点"血氧上限"对应数据点定义的分辨率
protected static final int SPO2UP_RATIO = 1;
// 数据点"血氧下限"对应seekbar滚动条补偿值
protected static final int SPO2DW_OFFSET = 0;
// 数据点"血氧下限"对应数据点增量值
protected static final int SPO2DW_ADDITION = 0;
// 数据点"血氧下限"对应数据点定义的分辨率
protected static final int SPO2DW_RATIO = 1;
// 数据点"体温上限"对应seekbar滚动条补偿值
protected static final int TEMPUP_OFFSET = 0;
// 数据点"体温上限"对应数据点增量值
protected static final int TEMPUP_ADDITION = 0;
// 数据点"体温上限"对应数据点定义的分辨率
protected static final int TEMPUP_RATIO = 1;
// 数据点"体温下限"对应seekbar滚动条补偿值
protected static final int TEMPDW_OFFSET = 0;
// 数据点"体温下限"对应数据点增量值
protected static final int TEMPDW_ADDITION = 0;
// 数据点"体温下限"对应数据点定义的分辨率
protected static final int TEMPDW_RATIO = 1;
// 数据点"计步步数"对应seekbar滚动条补偿值
protected static final int BUS_OFFSET = 0;
// 数据点"计步步数"对应数据点增量值
protected static final int BUS_ADDITION = 0;
// 数据点"计步步数"对应数据点定义的分辨率
protected static final int BUS_RATIO = 1;
// 数据点"GPS纬度N"对应seekbar滚动条补偿值
protected static final int GPS_N_OFFSET = 0;
// 数据点"GPS纬度N"对应数据点增量值
protected static final int GPS_N_ADDITION = 0;
// 数据点"GPS纬度N"对应数据点定义的分辨率
protected static final double GPS_N_RATIO = 0.001;
// 数据点"体温检测"对应seekbar滚动条补偿值
protected static final int TEMP_OFFSET = 0;
// 数据点"体温检测"对应数据点增量值
protected static final int TEMP_ADDITION = 0;
// 数据点"体温检测"对应数据点定义的分辨率
protected static final double TEMP_RATIO = 0.1;
// 数据点"GPS经度E"对应seekbar滚动条补偿值
protected static final int GPS_E_OFFSET = 0;
// 数据点"GPS经度E"对应数据点增量值
protected static final int GPS_E_ADDITION = 50;
// 数据点"GPS经度E"对应数据点定义的分辨率
protected static final double GPS_E_RATIO = 0.001;
/*
* ===========================================================
*
* ===========================================================
*/
// 数据点"心率检测"对应的存储数据
protected static int data_hreat;
// 数据点"心率上限"对应的存储数据
protected static int data_heartup;
// 数据点"心率下限"对应的存储数据
protected static int data_heartdw;
// 数据点"血氧检测"对应的存储数据
protected static int data_spo2;
// 数据点"血氧上限"对应的存储数据
protected static int data_spo2up;
// 数据点"血氧下限"对应的存储数据
protected static int data_spo2dw;
// 数据点"体温上限"对应的存储数据
protected static int data_tempup;
// 数据点"体温下限"对应的存储数据
protected static int data_tempdw;
// 数据点"计步步数"对应的存储数据
protected static int data_bus;
// 数据点"GPS纬度N"对应的存储数据
protected static double data_GPS_N;
// 数据点"体温检测"对应的存储数据
protected static double data_temp;
// 数据点"GPS经度E"对应的存储数据
protected static double data_GPS_E;
/*
* ===========================================================
* key
* ===========================================================
*/
protected static final String WIFI_HARDVER_KEY = "wifiHardVersion";
protected static final String WIFI_SOFTVER_KEY = "wifiSoftVersion";
protected static final String MCU_HARDVER_KEY = "mcuHardVersion";
protected static final String MCU_SOFTVER_KEY = "mcuSoftVersion";
protected static final String WIFI_FIRMWAREID_KEY = "wifiFirmwareId";
protected static final String WIFI_FIRMWAREVER_KEY = "wifiFirmwareVer";
protected static final String PRODUCT_KEY = "productKey";
private Toast mToast;
@SuppressWarnings("unchecked")
protected void getDataFromReceiveDataMap(ConcurrentHashMap<String, Object> dataMap) {
// 已定义的设备数据点,有布尔、数值和枚举型数据
if (dataMap.get("data") != null) {
ConcurrentHashMap<String, Object> map = (ConcurrentHashMap<String, Object>) dataMap.get("data");
for (String dataKey : map.keySet()) {
if (dataKey.equals(KEY_HREAT)) {
data_hreat = (Integer) map.get(dataKey);
}
if (dataKey.equals(KEY_HEARTUP)) {
data_heartup = (Integer) map.get(dataKey);
}
if (dataKey.equals(KEY_HEARTDW)) {
data_heartdw = (Integer) map.get(dataKey);
}
if (dataKey.equals(KEY_SPO2)) {
data_spo2 = (Integer) map.get(dataKey);
}
if (dataKey.equals(KEY_SPO2UP)) {
data_spo2up = (Integer) map.get(dataKey);
}
if (dataKey.equals(KEY_SPO2DW)) {
data_spo2dw = (Integer) map.get(dataKey);
}
if (dataKey.equals(KEY_TEMPUP)) {
data_tempup = (Integer) map.get(dataKey);
}
if (dataKey.equals(KEY_TEMPDW)) {
data_tempdw = (Integer) map.get(dataKey);
}
if (dataKey.equals(KEY_BUS)) {
data_bus = (Integer) map.get(dataKey);
}
if (dataKey.equals(KEY_GPS_N)) {
if (map.get(dataKey) instanceof Integer) {
data_GPS_N = (Integer) map.get(dataKey);
} else {
data_GPS_N = (Double) map.get(dataKey);
}
}
if (dataKey.equals(KEY_TEMP)) {
if (map.get(dataKey) instanceof Integer) {
data_temp = (Integer) map.get(dataKey);
} else {
data_temp = (Double) map.get(dataKey);
}
}
if (dataKey.equals(KEY_GPS_E)) {
if (map.get(dataKey) instanceof Integer) {
data_GPS_E = (Integer) map.get(dataKey);
} else {
data_GPS_E = (Double) map.get(dataKey);
}
}
}
}
StringBuilder sBuilder = new StringBuilder();
// 已定义的设备报警数据点,设备发生报警后该字段有内容,没有发生报警则没内容
if (dataMap.get("alerts") != null) {
ConcurrentHashMap<String, Object> map = (ConcurrentHashMap<String, Object>) dataMap.get("alerts");
for (String alertsKey : map.keySet()) {
if ((Boolean) map.get(alertsKey)) {
sBuilder.append("报警:" + alertsKey + "=true" + "\n");
}
}
}
// 已定义的设备故障数据点,设备发生故障后该字段有内容,没有发生故障则没内容
if (dataMap.get("faults") != null) {
ConcurrentHashMap<String, Object> map = (ConcurrentHashMap<String, Object>) dataMap.get("faults");
for (String faultsKey : map.keySet()) {
if ((Boolean) map.get(faultsKey)) {
sBuilder.append("故障:" + faultsKey + "=true" + "\n");
}
}
}
if (sBuilder.length() > 0) {
sBuilder.insert(0, "[设备故障或报警]\n");
myToast(sBuilder.toString().trim());
}
// 透传数据,无数据点定义,适合开发者自行定义协议自行解析
if (dataMap.get("binary") != null) {
byte[] binary = (byte[]) dataMap.get("binary");
Log.i("", "Binary data:" + HexStrUtils.bytesToHexString(binary));
}
}
GizWifiDeviceListener gizWifiDeviceListener = new GizWifiDeviceListener() {
/** 用于设备订阅 */
public void didSetSubscribe(GizWifiErrorCode result, GizWifiDevice device, boolean isSubscribed) {
GosControlModuleBaseActivity.this.didSetSubscribe(result, device, isSubscribed);
};
/** 用于获取设备状态 */
public void didReceiveData(GizWifiErrorCode result, GizWifiDevice device,
java.util.concurrent.ConcurrentHashMap<String, Object> dataMap, int sn) {
GosControlModuleBaseActivity.this.didReceiveData(result, device, dataMap, sn);
};
/** 用于设备硬件信息 */
public void didGetHardwareInfo(GizWifiErrorCode result, GizWifiDevice device,
java.util.concurrent.ConcurrentHashMap<String, String> hardwareInfo) {
GosControlModuleBaseActivity.this.didGetHardwareInfo(result, device, hardwareInfo);
};
/** 用于修改设备信息 */
public void didSetCustomInfo(GizWifiErrorCode result, GizWifiDevice device) {
GosControlModuleBaseActivity.this.didSetCustomInfo(result, device);
};
/** 用于设备状态变化 */
public void didUpdateNetStatus(GizWifiDevice device, GizWifiDeviceNetStatus netStatus) {
GosControlModuleBaseActivity.this.didUpdateNetStatus(device, netStatus);
};
};
/**
*
*
* @param result
*
* @param device
*
* @param isSubscribed
*
*/
protected void didSetSubscribe(GizWifiErrorCode result, GizWifiDevice device, boolean isSubscribed) {
}
/**
*
*
* @param result
*
* @param device
*
* @param dataMap
*
* @param sn
*
*/
protected void didReceiveData(GizWifiErrorCode result, GizWifiDevice device,
java.util.concurrent.ConcurrentHashMap<String, Object> dataMap, int sn) {
}
/**
*
*
* @param result
*
* @param device
*
* @param hardwareInfo
*
*/
protected void didGetHardwareInfo(GizWifiErrorCode result, GizWifiDevice device,
java.util.concurrent.ConcurrentHashMap<String, String> hardwareInfo) {
}
/**
*
*
* @param result
*
* @param device
*
*/
protected void didSetCustomInfo(GizWifiErrorCode result, GizWifiDevice device) {
}
/**
*
*/
protected void didUpdateNetStatus(GizWifiDevice device, GizWifiDeviceNetStatus netStatus) {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
break;
}
return super.onOptionsItemSelected(item);
}
public void myToast(String string) {
if (mToast != null) {
mToast.setText(string);
} else {
mToast = Toast.makeText(getApplicationContext(), string, Toast.LENGTH_LONG);
}
mToast.show();
}
protected void hideKeyBoard() {
// 隐藏键盘
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
}
}
/**
*Description:20.36560.0120.37
*@param date
*@param scale
*@return
*/
protected String formatValue(double date, Object scale) {
if (scale instanceof Double) {
DecimalFormat df = new DecimalFormat(scale.toString());
return df.format(date);
}
return Math.round(date) + "";
}
}

@ -0,0 +1,603 @@
package com.gizwits.opensource.appkit.ControlModule;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import java.util.concurrent.ConcurrentHashMap;
import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceNetStatus;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.HexStrUtils;
import com.gizwits.opensource.appkit.view.HexWatcher;
public class GosDeviceControlActivity extends GosControlModuleBaseActivity
implements OnClickListener, OnEditorActionListener, OnSeekBarChangeListener {
/** 设备列表传入的设备变量 */
private GizWifiDevice mDevice;
private TextView tv_data_hreat;
private SeekBar sb_data_hreat;
private TextView tv_data_heartup;
private SeekBar sb_data_heartup;
private TextView tv_data_heartdw;
private SeekBar sb_data_heartdw;
private TextView tv_data_spo2;
private SeekBar sb_data_spo2;
private TextView tv_data_spo2up;
private SeekBar sb_data_spo2up;
private TextView tv_data_spo2dw;
private SeekBar sb_data_spo2dw;
private TextView tv_data_tempup;
private SeekBar sb_data_tempup;
private TextView tv_data_tempdw;
private SeekBar sb_data_tempdw;
private TextView tv_data_bus;
private SeekBar sb_data_bus;
private TextView tv_data_GPS_N;
private SeekBar sb_data_GPS_N;
private TextView tv_data_temp;
private SeekBar sb_data_temp;
private TextView tv_data_GPS_E;
private SeekBar sb_data_GPS_E;
private enum handler_key {
/** 更新界面 */
UPDATE_UI,
DISCONNECT,
}
private Runnable mRunnable = new Runnable() {
public void run() {
if (isDeviceCanBeControlled()) {
progressDialog.cancel();
} else {
toastDeviceNoReadyAndExit();
}
}
};
/** The handler. */
Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
handler_key key = handler_key.values()[msg.what];
switch (key) {
case UPDATE_UI:
updateUI();
break;
case DISCONNECT:
toastDeviceDisconnectAndExit();
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_device_control);
initDevice();
setToolBar(true, getDeviceName());
final Drawable add = getResources().getDrawable(R.drawable.common_setting_more);
int color = GosDeploy.appConfig_Contrast();
add.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
mToolbar.setOverflowIcon(add);
initView();
initEvent();
}
private void initView() {
tv_data_hreat = (TextView) findViewById(R.id.tv_data_hreat);
sb_data_hreat = (SeekBar) findViewById(R.id.sb_data_hreat);
tv_data_heartup = (TextView) findViewById(R.id.tv_data_heartup);
sb_data_heartup = (SeekBar) findViewById(R.id.sb_data_heartup);
tv_data_heartdw = (TextView) findViewById(R.id.tv_data_heartdw);
sb_data_heartdw = (SeekBar) findViewById(R.id.sb_data_heartdw);
tv_data_spo2 = (TextView) findViewById(R.id.tv_data_spo2);
sb_data_spo2 = (SeekBar) findViewById(R.id.sb_data_spo2);
tv_data_spo2up = (TextView) findViewById(R.id.tv_data_spo2up);
sb_data_spo2up = (SeekBar) findViewById(R.id.sb_data_spo2up);
tv_data_spo2dw = (TextView) findViewById(R.id.tv_data_spo2dw);
sb_data_spo2dw = (SeekBar) findViewById(R.id.sb_data_spo2dw);
tv_data_tempup = (TextView) findViewById(R.id.tv_data_tempup);
sb_data_tempup = (SeekBar) findViewById(R.id.sb_data_tempup);
tv_data_tempdw = (TextView) findViewById(R.id.tv_data_tempdw);
sb_data_tempdw = (SeekBar) findViewById(R.id.sb_data_tempdw);
tv_data_bus = (TextView) findViewById(R.id.tv_data_bus);
sb_data_bus = (SeekBar) findViewById(R.id.sb_data_bus);
tv_data_GPS_N = (TextView) findViewById(R.id.tv_data_GPS_N);
sb_data_GPS_N = (SeekBar) findViewById(R.id.sb_data_GPS_N);
tv_data_temp = (TextView) findViewById(R.id.tv_data_temp);
sb_data_temp = (SeekBar) findViewById(R.id.sb_data_temp);
tv_data_GPS_E = (TextView) findViewById(R.id.tv_data_GPS_E);
sb_data_GPS_E = (SeekBar) findViewById(R.id.sb_data_GPS_E);
}
private void initEvent() {
sb_data_hreat.setOnSeekBarChangeListener(this);
sb_data_heartup.setOnSeekBarChangeListener(this);
sb_data_heartdw.setOnSeekBarChangeListener(this);
sb_data_spo2.setOnSeekBarChangeListener(this);
sb_data_spo2up.setOnSeekBarChangeListener(this);
sb_data_spo2dw.setOnSeekBarChangeListener(this);
sb_data_tempup.setOnSeekBarChangeListener(this);
sb_data_tempdw.setOnSeekBarChangeListener(this);
sb_data_bus.setOnSeekBarChangeListener(this);
sb_data_GPS_N.setOnSeekBarChangeListener(this);
sb_data_temp.setOnSeekBarChangeListener(this);
sb_data_GPS_E.setOnSeekBarChangeListener(this);
}
private void initDevice() {
Intent intent = getIntent();
mDevice = (GizWifiDevice) intent.getParcelableExtra("GizWifiDevice");
mDevice.setListener(gizWifiDeviceListener);
Log.i("Apptest", mDevice.getDid());
}
private String getDeviceName() {
if (TextUtils.isEmpty(mDevice.getAlias())) {
return mDevice.getProductName();
}
return mDevice.getAlias();
}
@Override
protected void onResume() {
super.onResume();
getStatusOfDevice();
}
@Override
protected void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(mRunnable);
// 退出页面,取消设备订阅
mDevice.setSubscribe(false);
mDevice.setListener(null);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
default:
break;
}
}
/*
* ========================================================================
* EditText
* ========================================================================
*/
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
switch (v.getId()) {
default:
break;
}
hideKeyBoard();
return false;
}
/*
* ========================================================================
* seekbar
* ========================================================================
*/
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
switch (seekBar.getId()) {
case R.id.sb_data_hreat:
tv_data_hreat.setText(formatValue((progress + HREAT_OFFSET) * HREAT_RATIO + HREAT_ADDITION, 1));
break;
case R.id.sb_data_heartup:
tv_data_heartup.setText(formatValue((progress + HEARTUP_OFFSET) * HEARTUP_RATIO + HEARTUP_ADDITION, 1));
break;
case R.id.sb_data_heartdw:
tv_data_heartdw.setText(formatValue((progress + HEARTDW_OFFSET) * HEARTDW_RATIO + HEARTDW_ADDITION, 1));
break;
case R.id.sb_data_spo2:
tv_data_spo2.setText(formatValue((progress + SPO2_OFFSET) * SPO2_RATIO + SPO2_ADDITION, 1));
break;
case R.id.sb_data_spo2up:
tv_data_spo2up.setText(formatValue((progress + SPO2UP_OFFSET) * SPO2UP_RATIO + SPO2UP_ADDITION, 1));
break;
case R.id.sb_data_spo2dw:
tv_data_spo2dw.setText(formatValue((progress + SPO2DW_OFFSET) * SPO2DW_RATIO + SPO2DW_ADDITION, 1));
break;
case R.id.sb_data_tempup:
tv_data_tempup.setText(formatValue((progress + TEMPUP_OFFSET) * TEMPUP_RATIO + TEMPUP_ADDITION, 1));
break;
case R.id.sb_data_tempdw:
tv_data_tempdw.setText(formatValue((progress + TEMPDW_OFFSET) * TEMPDW_RATIO + TEMPDW_ADDITION, 1));
break;
case R.id.sb_data_bus:
tv_data_bus.setText(formatValue((progress + BUS_OFFSET) * BUS_RATIO + BUS_ADDITION, 1));
break;
case R.id.sb_data_GPS_N:
tv_data_GPS_N.setText(formatValue((progress + GPS_N_OFFSET) * GPS_N_RATIO + GPS_N_ADDITION, 0.001));
break;
case R.id.sb_data_temp:
tv_data_temp.setText(formatValue((progress + TEMP_OFFSET) * TEMP_RATIO + TEMP_ADDITION, 0.1));
break;
case R.id.sb_data_GPS_E:
tv_data_GPS_E.setText(formatValue((progress + GPS_E_OFFSET) * GPS_E_RATIO + GPS_E_ADDITION, 0.001));
break;
default:
break;
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
switch (seekBar.getId()) {
case R.id.sb_data_hreat:
sendCommand(KEY_HREAT, (seekBar.getProgress() + HREAT_OFFSET ) * HREAT_RATIO + HREAT_ADDITION);
break;
case R.id.sb_data_heartup:
sendCommand(KEY_HEARTUP, (seekBar.getProgress() + HEARTUP_OFFSET ) * HEARTUP_RATIO + HEARTUP_ADDITION);
break;
case R.id.sb_data_heartdw:
sendCommand(KEY_HEARTDW, (seekBar.getProgress() + HEARTDW_OFFSET ) * HEARTDW_RATIO + HEARTDW_ADDITION);
break;
case R.id.sb_data_spo2:
sendCommand(KEY_SPO2, (seekBar.getProgress() + SPO2_OFFSET ) * SPO2_RATIO + SPO2_ADDITION);
break;
case R.id.sb_data_spo2up:
sendCommand(KEY_SPO2UP, (seekBar.getProgress() + SPO2UP_OFFSET ) * SPO2UP_RATIO + SPO2UP_ADDITION);
break;
case R.id.sb_data_spo2dw:
sendCommand(KEY_SPO2DW, (seekBar.getProgress() + SPO2DW_OFFSET ) * SPO2DW_RATIO + SPO2DW_ADDITION);
break;
case R.id.sb_data_tempup:
sendCommand(KEY_TEMPUP, (seekBar.getProgress() + TEMPUP_OFFSET ) * TEMPUP_RATIO + TEMPUP_ADDITION);
break;
case R.id.sb_data_tempdw:
sendCommand(KEY_TEMPDW, (seekBar.getProgress() + TEMPDW_OFFSET ) * TEMPDW_RATIO + TEMPDW_ADDITION);
break;
case R.id.sb_data_bus:
sendCommand(KEY_BUS, (seekBar.getProgress() + BUS_OFFSET ) * BUS_RATIO + BUS_ADDITION);
break;
case R.id.sb_data_GPS_N:
sendCommand(KEY_GPS_N, (seekBar.getProgress() + GPS_N_OFFSET ) * GPS_N_RATIO + GPS_N_ADDITION);
break;
case R.id.sb_data_temp:
sendCommand(KEY_TEMP, (seekBar.getProgress() + TEMP_OFFSET ) * TEMP_RATIO + TEMP_ADDITION);
break;
case R.id.sb_data_GPS_E:
sendCommand(KEY_GPS_E, (seekBar.getProgress() + GPS_E_OFFSET ) * GPS_E_RATIO + GPS_E_ADDITION);
break;
default:
break;
}
}
/*
* ========================================================================
*
* ========================================================================
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.device_more, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_setDeviceInfo:
setDeviceInfo();
break;
case R.id.action_getHardwareInfo:
if (mDevice.isLAN()) {
mDevice.getHardwareInfo();
} else {
myToast("只允许在局域网下获取设备硬件信息!");
}
break;
case R.id.action_getStatu:
mDevice.getDeviceStatus();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
/**
* Description:UI
*/
protected void updateUI() {
tv_data_hreat.setText(data_hreat+"");
sb_data_hreat.setProgress((int)((data_hreat - HREAT_ADDITION) / HREAT_RATIO - HREAT_OFFSET));
tv_data_heartup.setText(data_heartup+"");
sb_data_heartup.setProgress((int)((data_heartup - HEARTUP_ADDITION) / HEARTUP_RATIO - HEARTUP_OFFSET));
tv_data_heartdw.setText(data_heartdw+"");
sb_data_heartdw.setProgress((int)((data_heartdw - HEARTDW_ADDITION) / HEARTDW_RATIO - HEARTDW_OFFSET));
tv_data_spo2.setText(data_spo2+"");
sb_data_spo2.setProgress((int)((data_spo2 - SPO2_ADDITION) / SPO2_RATIO - SPO2_OFFSET));
tv_data_spo2up.setText(data_spo2up+"");
sb_data_spo2up.setProgress((int)((data_spo2up - SPO2UP_ADDITION) / SPO2UP_RATIO - SPO2UP_OFFSET));
tv_data_spo2dw.setText(data_spo2dw+"");
sb_data_spo2dw.setProgress((int)((data_spo2dw - SPO2DW_ADDITION) / SPO2DW_RATIO - SPO2DW_OFFSET));
tv_data_tempup.setText(data_tempup+"");
sb_data_tempup.setProgress((int)((data_tempup - TEMPUP_ADDITION) / TEMPUP_RATIO - TEMPUP_OFFSET));
tv_data_tempdw.setText(data_tempdw+"");
sb_data_tempdw.setProgress((int)((data_tempdw - TEMPDW_ADDITION) / TEMPDW_RATIO - TEMPDW_OFFSET));
tv_data_bus.setText(data_bus+"");
sb_data_bus.setProgress((int)((data_bus - BUS_ADDITION) / BUS_RATIO - BUS_OFFSET));
tv_data_GPS_N.setText(data_GPS_N+"");
sb_data_GPS_N.setProgress((int)((data_GPS_N - GPS_N_ADDITION) / GPS_N_RATIO - GPS_N_OFFSET));
tv_data_temp.setText(data_temp+"");
sb_data_temp.setProgress((int)((data_temp - TEMP_ADDITION) / TEMP_RATIO - TEMP_OFFSET));
tv_data_GPS_E.setText(data_GPS_E+"");
sb_data_GPS_E.setProgress((int)((data_GPS_E - GPS_E_ADDITION) / GPS_E_RATIO - GPS_E_OFFSET));
}
private void setEditText(EditText et, Object value) {
et.setText(value.toString());
et.setSelection(value.toString().length());
et.clearFocus();
}
/**
* Description:退
*/
private void getStatusOfDevice() {
// 设备是否可控
if (isDeviceCanBeControlled()) {
// 可控则查询当前设备状态
mDevice.getDeviceStatus();
} else {
// 显示等待栏
progressDialog.show();
if (mDevice.isLAN()) {
// 小循环10s未连接上设备自动退出
mHandler.postDelayed(mRunnable, 10000);
} else {
// 大循环20s未连接上设备自动退出
mHandler.postDelayed(mRunnable, 20000);
}
}
}
/**
* ,
*
* <h3></h3>
* <p>
*
* </p>
*
* @param key
*
* @param value
*
*/
private void sendCommand(String key, Object value) {
if (value == null) {
return;
}
int sn = 5;
ConcurrentHashMap<String, Object> hashMap = new ConcurrentHashMap<String, Object>();
hashMap.put(key, value);
// 同时下发多个数据点需要一次性在map中放置全部需要控制的keyvalue值
// hashMap.put(key2, value2);
// hashMap.put(key3, value3);
mDevice.write(hashMap, sn);
Log.i("liang", "下发命令:" + hashMap.toString());
}
private boolean isDeviceCanBeControlled() {
return mDevice.getNetStatus() == GizWifiDeviceNetStatus.GizDeviceControlled;
}
private void toastDeviceNoReadyAndExit() {
Toast.makeText(this, "设备无响应,请检查设备是否正常工作", Toast.LENGTH_SHORT).show();
finish();
}
private void toastDeviceDisconnectAndExit() {
Toast.makeText(GosDeviceControlActivity.this, "连接已断开", Toast.LENGTH_SHORT).show();
finish();
}
/**
*
*
* @param hardwareInfo
*/
private void showHardwareInfo(String hardwareInfo) {
String hardwareInfoTitle = "设备硬件信息";
new AlertDialog.Builder(this).setTitle(hardwareInfoTitle).setMessage(hardwareInfo)
.setPositiveButton(R.string.besure, null).show();
}
/**
* Description:
*/
private void setDeviceInfo() {
final Dialog mDialog = new AlertDialog.Builder(this,R.style.edit_dialog_style).setView(new EditText(this)).create();
mDialog.show();
Window window = mDialog.getWindow();
window.setContentView(R.layout.alert_gos_set_device_info);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
final EditText etAlias;
final EditText etRemark;
etAlias = (EditText) window.findViewById(R.id.etAlias);
etRemark = (EditText) window.findViewById(R.id.etRemark);
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
if (!TextUtils.isEmpty(mDevice.getAlias())) {
setEditText(etAlias, mDevice.getAlias());
}
if (!TextUtils.isEmpty(mDevice.getRemark())) {
setEditText(etRemark, mDevice.getRemark());
}
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mDialog.dismiss();
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (TextUtils.isEmpty(etRemark.getText().toString())
&& TextUtils.isEmpty(etAlias.getText().toString())) {
myToast("请输入设备别名或备注!");
return;
}
mDevice.setCustomInfo(etRemark.getText().toString(), etAlias.getText().toString());
mDialog.dismiss();
String loadingText = (String) getText(R.string.loadingtext);
progressDialog.setMessage(loadingText);
progressDialog.show();
}
});
mDialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
hideKeyBoard();
}
});
}
/*
*
*/
@Override
protected void didGetHardwareInfo(GizWifiErrorCode result, GizWifiDevice device,
ConcurrentHashMap<String, String> hardwareInfo) {
super.didGetHardwareInfo(result, device, hardwareInfo);
StringBuffer sb = new StringBuffer();
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
myToast("获取设备硬件信息失败:" + result.name());
} else {
sb.append("Wifi Hardware Version:" + hardwareInfo.get(WIFI_HARDVER_KEY) + "\r\n");
sb.append("Wifi Software Version:" + hardwareInfo.get(WIFI_SOFTVER_KEY) + "\r\n");
sb.append("MCU Hardware Version:" + hardwareInfo.get(MCU_HARDVER_KEY) + "\r\n");
sb.append("MCU Software Version:" + hardwareInfo.get(MCU_SOFTVER_KEY) + "\r\n");
sb.append("Wifi Firmware Id:" + hardwareInfo.get(WIFI_FIRMWAREID_KEY) + "\r\n");
sb.append("Wifi Firmware Version:" + hardwareInfo.get(WIFI_FIRMWAREVER_KEY) + "\r\n");
sb.append("Product Key:" + "\r\n" + hardwareInfo.get(PRODUCT_KEY) + "\r\n");
// 设备属性
sb.append("Device ID:" + "\r\n" + mDevice.getDid() + "\r\n");
sb.append("Device IP:" + mDevice.getIPAddress() + "\r\n");
sb.append("Device MAC:" + mDevice.getMacAddress() + "\r\n");
}
showHardwareInfo(sb.toString());
}
/*
*
*/
@Override
protected void didSetCustomInfo(GizWifiErrorCode result, GizWifiDevice device) {
super.didSetCustomInfo(result, device);
if (GizWifiErrorCode.GIZ_SDK_SUCCESS == result) {
myToast("设置成功");
progressDialog.cancel();
finish();
} else {
myToast("设置失败:" + result.name());
}
}
/*
*
*/
@Override
protected void didUpdateNetStatus(GizWifiDevice device, GizWifiDeviceNetStatus netStatus) {
super.didUpdateNetStatus(device, netStatus);
if (netStatus == GizWifiDeviceNetStatus.GizDeviceControlled) {
mHandler.removeCallbacks(mRunnable);
progressDialog.cancel();
} else {
mHandler.sendEmptyMessage(handler_key.DISCONNECT.ordinal());
}
}
/*
* ACK
*/
@Override
protected void didReceiveData(GizWifiErrorCode result, GizWifiDevice device,
ConcurrentHashMap<String, Object> dataMap, int sn) {
super.didReceiveData(result, device, dataMap, sn);
Log.i("liang", "接收到数据");
if (result == GizWifiErrorCode.GIZ_SDK_SUCCESS && dataMap.get("data") != null) {
getDataFromReceiveDataMap(dataMap);
mHandler.sendEmptyMessage(handler_key.UPDATE_UI.ordinal());
}
}
}

@ -0,0 +1,735 @@
package com.gizwits.opensource.appkit.DeviceModule;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
/**
* author: smile .
* date: On 2018/6/7
*/
public class GosBaseFragment extends Fragment {
/**
*
*/
public SharedPreferences spf;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
spf = getActivity().getSharedPreferences("set", Context.MODE_PRIVATE);
}
public String toastError(GizWifiErrorCode errorCode) {
String errorString = (String) getText(R.string.UNKNOWN_ERROR);
switch (errorCode) {
case GIZ_SDK_SUCCESS:
errorString=(String)getText(R.string.GIZ_SDK_SUCCESS);
break;
case GIZ_SDK_PARAM_FORM_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_PARAM_FORM_INVALID);
break;
case GIZ_SDK_CLIENT_NOT_AUTHEN:
errorString = (String) getText(R.string.GIZ_SDK_CLIENT_NOT_AUTHEN);
break;
case GIZ_SDK_CLIENT_VERSION_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_CLIENT_VERSION_INVALID);
break;
case GIZ_SDK_UDP_PORT_BIND_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_UDP_PORT_BIND_FAILED);
break;
case GIZ_SDK_DAEMON_EXCEPTION:
errorString = (String) getText(R.string.GIZ_SDK_DAEMON_EXCEPTION);
break;
case GIZ_SDK_PARAM_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_PARAM_INVALID);
break;
case GIZ_SDK_APPID_LENGTH_ERROR:
errorString = (String) getText(R.string.GIZ_SDK_APPID_LENGTH_ERROR);
break;
case GIZ_SDK_LOG_PATH_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_LOG_PATH_INVALID);
break;
case GIZ_SDK_LOG_LEVEL_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_LOG_LEVEL_INVALID);
break;
case GIZ_SDK_UID_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_UID_INVALID);
break;
case GIZ_SDK_TOKEN_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_TOKEN_INVALID);
break;
case GIZ_SDK_USER_NOT_LOGIN:
errorString = (String) getText(R.string.GIZ_SDK_USER_NOT_LOGIN);
break;
case GIZ_SDK_APPID_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_APPID_INVALID);
break;
case GIZ_SDK_APP_SECRET_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_APP_SECRET_INVALID);
break;
case GIZ_SDK_PRODUCT_KEY_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_PRODUCT_KEY_INVALID);
break;
case GIZ_SDK_PRODUCT_SECRET_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_PRODUCT_SECRET_INVALID);
break;
case GIZ_SDK_DEVICE_NOT_IN_LAN:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_IN_LAN);
break;
case GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIAL_LIST:
errorString = (String) getText(R.string.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIAL_LIST);
break;
case GIZ_SDK_PRODUCTKEY_NOT_RELATED_WITH_APPID:
errorString = (String) getText(R.string.GIZ_SDK_PRODUCTKEY_NOT_RELATED_WITH_APPID);
break;
case GIZ_SDK_NO_AVAILABLE_DEVICE:
errorString = (String) getText(R.string.GIZ_SDK_NO_AVAILABLE_DEVICE);
break;
case GIZ_SDK_DEVICE_CONFIG_SEND_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONFIG_SEND_FAILED);
break;
case GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING);
break;
case GIZ_SDK_DEVICE_CONFIG_TIMEOUT:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONFIG_TIMEOUT);
break;
case GIZ_SDK_DEVICE_DID_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_DID_INVALID);
break;
case GIZ_SDK_DEVICE_MAC_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_MAC_INVALID);
break;
case GIZ_SDK_SUBDEVICE_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_SUBDEVICE_INVALID);
break;
case GIZ_SDK_DEVICE_PASSCODE_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_PASSCODE_INVALID);
break;
case GIZ_SDK_DEVICE_NOT_CENTERCONTROL:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_CENTERCONTROL);
break;
case GIZ_SDK_DEVICE_NOT_SUBSCRIBED:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_SUBSCRIBED);
break;
case GIZ_SDK_DEVICE_NO_RESPONSE:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NO_RESPONSE);
break;
case GIZ_SDK_DEVICE_NOT_READY:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_READY);
break;
case GIZ_SDK_DEVICE_NOT_BINDED:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_BINDED);
break;
case GIZ_SDK_DEVICE_CONTROL_WITH_INVALID_COMMAND:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_WITH_INVALID_COMMAND);
break;
// case GIZ_SDK_DEVICE_CONTROL_FAILED:
// errorString= (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_FAILED);
// break;
case GIZ_SDK_DEVICE_GET_STATUS_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_GET_STATUS_FAILED);
break;
case GIZ_SDK_DEVICE_CONTROL_VALUE_TYPE_ERROR:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_VALUE_TYPE_ERROR);
break;
case GIZ_SDK_DEVICE_CONTROL_VALUE_OUT_OF_RANGE:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_VALUE_OUT_OF_RANGE);
break;
case GIZ_SDK_DEVICE_CONTROL_NOT_WRITABLE_COMMAND:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_NOT_WRITABLE_COMMAND);
break;
case GIZ_SDK_BIND_DEVICE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_BIND_DEVICE_FAILED);
break;
case GIZ_SDK_UNBIND_DEVICE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_UNBIND_DEVICE_FAILED);
break;
case GIZ_SDK_DNS_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_DNS_FAILED);
break;
case GIZ_SDK_M2M_CONNECTION_SUCCESS:
errorString = (String) getText(R.string.GIZ_SDK_M2M_CONNECTION_SUCCESS);
break;
case GIZ_SDK_SET_SOCKET_NON_BLOCK_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SET_SOCKET_NON_BLOCK_FAILED);
break;
case GIZ_SDK_CONNECTION_TIMEOUT:
errorString = (String) getText(R.string.GIZ_SDK_CONNECTION_TIMEOUT);
break;
case GIZ_SDK_CONNECTION_REFUSED:
errorString = (String) getText(R.string.GIZ_SDK_CONNECTION_REFUSED);
break;
case GIZ_SDK_CONNECTION_ERROR:
errorString = (String) getText(R.string.GIZ_SDK_CONNECTION_ERROR);
break;
case GIZ_SDK_CONNECTION_CLOSED:
errorString = (String) getText(R.string.GIZ_SDK_CONNECTION_CLOSED);
break;
case GIZ_SDK_SSL_HANDSHAKE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SSL_HANDSHAKE_FAILED);
break;
case GIZ_SDK_DEVICE_LOGIN_VERIFY_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_LOGIN_VERIFY_FAILED);
break;
case GIZ_SDK_INTERNET_NOT_REACHABLE:
errorString = (String) getText(R.string.GIZ_SDK_INTERNET_NOT_REACHABLE);
break;
case GIZ_SDK_M2M_CONNECTION_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_M2M_CONNECTION_FAILED);
break;
case GIZ_SDK_HTTP_SERVER_NOT_SUPPORT_API:
errorString = (String) getText(R.string.GIZ_SDK_HTTP_SERVER_NOT_SUPPORT_API);
break;
case GIZ_SDK_HTTP_ANSWER_FORMAT_ERROR:
errorString = (String) getText(R.string.GIZ_SDK_HTTP_ANSWER_FORMAT_ERROR);
break;
case GIZ_SDK_HTTP_ANSWER_PARAM_ERROR:
errorString = (String) getText(R.string.GIZ_SDK_HTTP_ANSWER_PARAM_ERROR);
break;
case GIZ_SDK_HTTP_SERVER_NO_ANSWER:
errorString = (String) getText(R.string.GIZ_SDK_HTTP_SERVER_NO_ANSWER);
break;
case GIZ_SDK_HTTP_REQUEST_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_HTTP_REQUEST_FAILED);
break;
case GIZ_SDK_OTHERWISE:
errorString = (String) getText(R.string.GIZ_SDK_OTHERWISE);
break;
case GIZ_SDK_MEMORY_MALLOC_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_MEMORY_MALLOC_FAILED);
break;
case GIZ_SDK_THREAD_CREATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_THREAD_CREATE_FAILED);
break;
case GIZ_SDK_JSON_OBJECT_CREATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_JSON_OBJECT_CREATE_FAILED);
break;
case GIZ_SDK_JSON_PARSE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_JSON_PARSE_FAILED);
break;
case GIZ_SDK_SCHEDULER_CREATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_CREATE_FAILED);
break;
case GIZ_SDK_SCHEDULER_DELETE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_DELETE_FAILED);
break;
case GIZ_SDK_SCHEDULER_EDIT_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_EDIT_FAILED);
break;
case GIZ_SDK_SCHEDULER_LIST_UPDATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_LIST_UPDATE_FAILED);
break;
case GIZ_SDK_SCHEDULER_TASK_EDIT_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_TASK_EDIT_FAILED);
break;
case GIZ_SDK_SCHEDULER_TASK_LIST_UPDATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_TASK_LIST_UPDATE_FAILED);
break;
case GIZ_SDK_SCHEDULER_ID_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_ID_INVALID);
break;
case GIZ_SDK_SCHEDULER_ENABLE_DISABLE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_ENABLE_DISABLE_FAILED);
break;
case GIZ_SDK_SCHEDULER_STATUS_UPDATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_STATUS_UPDATE_FAILED);
break;
case GIZ_SDK_GROUP_ID_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_GROUP_ID_INVALID);
break;
case GIZ_SDK_GROUP_FAILED_DELETE_DEVICE:
errorString = (String) getText(R.string.GIZ_SDK_GROUP_FAILED_DELETE_DEVICE);
break;
case GIZ_SDK_GROUP_FAILED_ADD_DEVICE:
errorString = (String) getText(R.string.GIZ_SDK_GROUP_FAILED_ADD_DEVICE);
break;
case GIZ_SDK_GROUP_PRODUCTKEY_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_GROUP_PRODUCTKEY_INVALID);
break;
case GIZ_SDK_GROUP_CREATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_GROUP_CREATE_FAILED);
break;
case GIZ_SDK_GROUP_DELETE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_GROUP_FAILED_DELETE_DEVICE);
break;
case GIZ_SDK_GROUP_EDIT_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_GROUP_EDIT_FAILED);
break;
case GIZ_SDK_GROUP_LIST_UPDATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_GROUP_GET_DEVICE_FAILED);
break;
case GIZ_SDK_SCENE_CREATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCENE_CREATE_FAILED);
break;
case GIZ_SDK_SCENE_DELETE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCENE_DELETE_FAILED);
break;
case GIZ_SDK_SCENE_EDIT_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCENE_EDIT_FAILED);
break;
case GIZ_SDK_SCENE_LIST_UPDATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCENE_LIST_UPDATE_FAILED);
break;
case GIZ_SDK_SCENE_ITEM_LIST_EDIT_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCENE_ITEM_LIST_EDIT_FAILED);
break;
case GIZ_SDK_SCENE_ITEM_LIST_UPDATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCENE_ITEM_LIST_UPDATE_FAILED);
break;
case GIZ_SDK_SCENE_ID_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_SCENE_ID_INVALID);
break;
case GIZ_SDK_SCENE_RUN_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCENE_RUN_FAILED);
break;
case GIZ_SDK_SCENE_STATUS_UPDATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_SCENE_STATUS_UPDATE_FAILED);
break;
case GIZ_SDK_JOINT_ACTION_CREATE_FAILED:
errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_CREATE_FAILED);
break;
case GIZ_SDK_JOINT_ACTION_DELETE_FAILED:
errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_DELETE_FAILED);
break;
case GIZ_SDK_JOINT_ACTION_VER_UNSUPPORTED:
errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_VER_UNSUPPORTED);
break;
// case GIZ_SDK_JOINT_ACTION_INVALID_CONDITION_TYPE:
// errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_INVALID_CONDITION_TYPE);
// break;
// case GIZ_SDK_JOINT_ACTION_INVALID_RESULT_EVENT_TYPE:
// errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_INVALID_RESULT_EVENT_TYPE);
// break;
case GIZ_SDK_DATAPOINT_NOT_DOWNLOAD:
errorString = (String) getText(R.string.GIZ_SDK_DATAPOINT_NOT_DOWNLOAD);
break;
case GIZ_SDK_DATAPOINT_SERVICE_UNAVAILABLE:
errorString = (String) getText(R.string.GIZ_SDK_DATAPOINT_SERVICE_UNAVAILABLE);
break;
case GIZ_SDK_DATAPOINT_PARSE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_DATAPOINT_PARSE_FAILED);
break;
// case GIZ_SDK_NOT_INITIALIZED:
// errorString= (String) getText(R.string.GIZ_SDK_SDK_NOT_INITIALIZED);
// break;
case GIZ_SDK_APK_CONTEXT_IS_NULL:
errorString = (String) getText(R.string.GIZ_SDK_APK_CONTEXT_IS_NULL);
break;
case GIZ_SDK_APK_PERMISSION_NOT_SET:
errorString = (String) getText(R.string.GIZ_SDK_APK_PERMISSION_NOT_SET);
break;
case GIZ_SDK_CHMOD_DAEMON_REFUSED:
errorString = (String) getText(R.string.GIZ_SDK_CHMOD_DAEMON_REFUSED);
break;
case GIZ_SDK_EXEC_DAEMON_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_EXEC_DAEMON_FAILED);
break;
case GIZ_SDK_EXEC_CATCH_EXCEPTION:
errorString = (String) getText(R.string.GIZ_SDK_EXEC_CATCH_EXCEPTION);
break;
case GIZ_SDK_APPID_IS_EMPTY:
errorString = (String) getText(R.string.GIZ_SDK_APPID_IS_EMPTY);
break;
case GIZ_SDK_UNSUPPORTED_API:
errorString = (String) getText(R.string.GIZ_SDK_UNSUPPORTED_API);
break;
case GIZ_SDK_REQUEST_TIMEOUT:
errorString = (String) getText(R.string.GIZ_SDK_REQUEST_TIMEOUT);
break;
case GIZ_SDK_DAEMON_VERSION_INVALID:
errorString = (String) getText(R.string.GIZ_SDK_DAEMON_VERSION_INVALID);
break;
case GIZ_SDK_PHONE_NOT_CONNECT_TO_SOFTAP_SSID:
errorString = (String) getText(R.string.GIZ_SDK_PHONE_NOT_CONNECT_TO_SOFTAP_SSID);
break;
case GIZ_SDK_DEVICE_CONFIG_SSID_NOT_MATCHED:
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONFIG_SSID_NOT_MATCHED);
break;
case GIZ_SDK_NOT_IN_SOFTAPMODE:
errorString = (String) getText(R.string.GIZ_SDK_NOT_IN_SOFTAPMODE);
break;
// case GIZ_SDK_PHONE_WIFI_IS_UNAVAILABLE:
// errorString= (String)getText(R.string.GIZ_SDK_PHONE_WIFI_IS_UNAVAILABLE);
// break;
case GIZ_SDK_RAW_DATA_TRANSMIT:
errorString = (String) getText(R.string.GIZ_SDK_RAW_DATA_TRANSMIT);
break;
case GIZ_SDK_PRODUCT_IS_DOWNLOADING:
errorString = (String) getText(R.string.GIZ_SDK_PRODUCT_IS_DOWNLOADING);
break;
case GIZ_SDK_START_SUCCESS:
errorString = (String) getText(R.string.GIZ_SDK_START_SUCCESS);
break;
case GIZ_SDK_NEED_UPDATE_TO_LATEST:
errorString = (String) getText(R.string.GIZ_SDK_NEED_UPDATE_TO_LATEST);
break;
case GIZ_SDK_ONBOARDING_STOPPED:
errorString = (String) getText(R.string.GIZ_SDK_ONBOARDING_STOPPED);
break;
case GIZ_SDK_ONBOARDING_WIFI_IS_5G:
errorString = (String) getText(R.string.GIZ_SDK_ONBOARDING_WIFI_IS_5G);
break;
case GIZ_SDK_OTA_FIRMWARE_IS_LATEST:
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_IS_LATEST);
break;
case GIZ_SDK_OTA_FIRMWARE_CHECK_UPDATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_CHECK_UPDATE_FAILED);
break;
case GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_OK:
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_OK);
break;
case GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED);
break;
case GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE:
errorString = (String) getText(R.string.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE);
break;
case GIZ_SDK_OTA_PUSH_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_OTA_PUSH_FAILED);
break;
case GIZ_SDK_OTA_FIRMWARE_VERSION_TOO_LOW:
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_VERSION_TOO_LOW);
break;
case GIZ_SDK_OTA_FIRMWARE_CHECK_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_CHECK_FAILED);
break;
case GIZ_SDK_OTA_UPGRADE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_OTA_UPGRADE_FAILED);
break;
case GIZ_SDK_OTA_FIRMWARE_VERIFY_SUCCESS:
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_VERIFY_SUCCESS);
break;
case GIZ_SDK_OTA_DEVICE_NOT_SUPPORT:
errorString = (String) getText(R.string.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT);
break;
case GIZ_SDK_WS_HANDSHAKE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_WS_HANDSHAKE_FAILED);
break;
case GIZ_SDK_WS_LOGIN_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_WS_LOGIN_FAILED);
break;
// case GIZ_SDK_WS_DEVICE_SUBSCRIBE_FAILED:
// errorString = (String) getText(R.string.GIZ_SDK_WS_DEVICE_SUBSCRIBE_FAILED);
// break;
// case GIZ_SDK_WS_DEVICE_UNSUBSCRIBE_FAILED:
// errorString = (String) getText(R.string.GIZ_SDK_WS_DEVICE_UNSUBSCRIBE_FAILED);
// break;
case GIZ_SITE_PRODUCTKEY_INVALID:
errorString = (String) getText(R.string.GIZ_SITE_PRODUCTKEY_INVALID);
break;
case GIZ_SITE_DATAPOINTS_NOT_DEFINED:
errorString = (String) getText(R.string.GIZ_SITE_DATAPOINTS_NOT_DEFINED);
break;
case GIZ_SITE_DATAPOINTS_NOT_MALFORME:
errorString = (String) getText(R.string.GIZ_SITE_DATAPOINTS_NOT_MALFORME);
break;
case GIZ_OPENAPI_MAC_ALREADY_REGISTERED:
errorString = (String) getText(R.string.GIZ_OPENAPI_MAC_ALREADY_REGISTERED);
break;
case GIZ_OPENAPI_PRODUCT_KEY_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_PRODUCT_KEY_INVALID);
break;
case GIZ_OPENAPI_APPID_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_APPID_INVALID);
break;
case GIZ_OPENAPI_TOKEN_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_TOKEN_INVALID);
break;
case GIZ_OPENAPI_USER_NOT_EXIST:
errorString = (String) getText(R.string.GIZ_OPENAPI_USER_NOT_EXIST);
break;
case GIZ_OPENAPI_TOKEN_EXPIRED:
errorString = (String) getText(R.string.GIZ_OPENAPI_TOKEN_EXPIRED);
break;
case GIZ_OPENAPI_M2M_ID_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_M2M_ID_INVALID);
break;
case GIZ_OPENAPI_SERVER_ERROR:
errorString = (String) getText(R.string.GIZ_OPENAPI_SERVER_ERROR);
break;
case GIZ_OPENAPI_CODE_EXPIRED:
errorString = (String) getText(R.string.GIZ_OPENAPI_CODE_EXPIRED);
break;
case GIZ_OPENAPI_CODE_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_CODE_INVALID);
break;
case GIZ_OPENAPI_SANDBOX_SCALE_QUOTA_EXHAUSTED:
errorString = (String) getText(R.string.GIZ_OPENAPI_SANDBOX_SCALE_QUOTA_EXHAUSTED);
break;
case GIZ_OPENAPI_PRODUCTION_SCALE_QUOTA_EXHAUSTED:
errorString = (String) getText(R.string.GIZ_OPENAPI_PRODUCTION_SCALE_QUOTA_EXHAUSTED);
break;
case GIZ_OPENAPI_PRODUCT_HAS_NO_REQUEST_SCALE:
errorString = (String) getText(R.string.GIZ_OPENAPI_PRODUCT_HAS_NO_REQUEST_SCALE);
break;
case GIZ_OPENAPI_DEVICE_NOT_FOUND:
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_NOT_FOUND);
break;
case GIZ_OPENAPI_FORM_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_FORM_INVALID);
break;
case GIZ_OPENAPI_DID_PASSCODE_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_DID_PASSCODE_INVALID);
break;
case GIZ_OPENAPI_DEVICE_NOT_BOUND:
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_NOT_BOUND);
break;
case GIZ_OPENAPI_PHONE_UNAVALIABLE:
errorString = (String) getText(R.string.GIZ_OPENAPI_PHONE_UNAVALIABLE);
break;
case GIZ_OPENAPI_USERNAME_UNAVALIABLE:
errorString = (String) getText(R.string.GIZ_OPENAPI_USERNAME_UNAVALIABLE);
break;
case GIZ_OPENAPI_USERNAME_PASSWORD_ERROR:
errorString = (String) getText(R.string.GIZ_OPENAPI_USERNAME_PASSWORD_ERROR);
break;
case GIZ_OPENAPI_SEND_COMMAND_FAILED:
errorString = (String) getText(R.string.GIZ_OPENAPI_SEND_COMMAND_FAILED);
break;
case GIZ_OPENAPI_EMAIL_UNAVALIABLE:
errorString = (String) getText(R.string.GIZ_OPENAPI_EMAIL_UNAVALIABLE);
break;
case GIZ_OPENAPI_DEVICE_DISABLED:
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_DISABLED);
break;
case GIZ_OPENAPI_FAILED_NOTIFY_M2M:
errorString = (String) getText(R.string.GIZ_OPENAPI_FAILED_NOTIFY_M2M);
break;
case GIZ_OPENAPI_ATTR_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_ATTR_INVALID);
break;
case GIZ_OPENAPI_USER_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_USER_INVALID);
break;
case GIZ_OPENAPI_FIRMWARE_NOT_FOUND:
errorString = (String) getText(R.string.GIZ_OPENAPI_FIRMWARE_NOT_FOUND);
break;
case GIZ_OPENAPI_JD_PRODUCT_NOT_FOUND:
errorString = (String) getText(R.string.GIZ_OPENAPI_JD_PRODUCT_NOT_FOUND);
break;
case GIZ_OPENAPI_DATAPOINT_DATA_NOT_FOUND:
errorString = (String) getText(R.string.GIZ_OPENAPI_DATAPOINT_DATA_NOT_FOUND);
break;
case GIZ_OPENAPI_SCHEDULER_NOT_FOUND:
errorString = (String) getText(R.string.GIZ_OPENAPI_SCHEDULER_NOT_FOUND);
break;
case GIZ_OPENAPI_QQ_OAUTH_KEY_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_QQ_OAUTH_KEY_INVALID);
break;
case GIZ_OPENAPI_OTA_SERVICE_OK_BUT_IN_IDLE:
errorString = (String) getText(R.string.GIZ_OPENAPI_OTA_SERVICE_OK_BUT_IN_IDLE);
break;
case GIZ_OPENAPI_BT_FIRMWARE_UNVERIFIED:
errorString = (String) getText(R.string.GIZ_OPENAPI_BT_FIRMWARE_UNVERIFIED);
break;
case GIZ_OPENAPI_BT_FIRMWARE_NOTHING_TO_UPGRADE:
errorString = (String) getText(R.string.GIZ_OPENAPI_SAVE_KAIROSDB_ERROR);
break;
case GIZ_OPENAPI_SAVE_KAIROSDB_ERROR:
errorString = (String) getText(R.string.GIZ_OPENAPI_SAVE_KAIROSDB_ERROR);
break;
case GIZ_OPENAPI_EVENT_NOT_DEFINED:
errorString = (String) getText(R.string.GIZ_OPENAPI_EVENT_NOT_DEFINED);
break;
case GIZ_OPENAPI_SEND_SMS_FAILED:
errorString = (String) getText(R.string.GIZ_OPENAPI_SEND_SMS_FAILED);
break;
// case GIZ_OPENAPI_APPLICATION_AUTH_INVALID:
// errorString= (String)
// getText(R.string.GIZ_OPENAPI_APPLICATION_AUTH_INVALID);
// break;
case GIZ_OPENAPI_NOT_ALLOWED_CALL_API:
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_ALLOWED_CALL_API);
break;
case GIZ_OPENAPI_BAD_QRCODE_CONTENT:
errorString = (String) getText(R.string.GIZ_OPENAPI_BAD_QRCODE_CONTENT);
break;
case GIZ_OPENAPI_REQUEST_THROTTLED:
errorString = (String) getText(R.string.GIZ_OPENAPI_REQUEST_THROTTLED);
break;
case GIZ_OPENAPI_DEVICE_OFFLINE:
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_OFFLINE);
break;
case GIZ_OPENAPI_TIMESTAMP_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_TIMESTAMP_INVALID);
break;
case GIZ_OPENAPI_SIGNATURE_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_SIGNATURE_INVALID);
break;
case GIZ_OPENAPI_DEPRECATED_API:
errorString = (String) getText(R.string.GIZ_OPENAPI_DEPRECATED_API);
break;
case GIZ_OPENAPI_REGISTER_IS_BUSY:
errorString = (String) getText(R.string.GIZ_OPENAPI_REGISTER_IS_BUSY);
break;
case GIZ_OPENAPI_ALTER_PASSWORD_FAILED:
errorString = (String) getText(R.string.GIZ_OPENAPI_ALTER_PASSWORD_FAILED);
break;
case GIZ_OPENAPI_APPID_PK_NOT_RELATION:
errorString = (String) getText(R.string.GIZ_OPENAPI_APPID_PK_NOT_RELATION);
break;
case GIZ_OPENAPI_CALL_INNER_FAILED:
errorString = (String) getText(R.string.GIZ_OPENAPI_CALL_INNER_FAILED);
break;
case GIZ_OPENAPI_DEVICE_SHARING_NOT_ENABLED:
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_SHARING_NOT_ENABLED);
break;
case GIZ_OPENAPI_NOT_FIRST_USER_OF_DEVICE:
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_FIRST_USER_OF_DEVICE);
break;
case GIZ_OPENAPI_PRODUCT_KEY_AUTHEN_FAULT:
errorString = (String) getText(R.string.GIZ_OPENAPI_PRODUCT_KEY_AUTHEN_FAULT);
break;
case GIZ_OPENAPI_BUSY_NOW:
errorString = (String) getText(R.string.GIZ_OPENAPI_BUSY_NOW);
break;
case GIZ_OPENAPI_TWITTER_CONSUMER_KEY_INVALID:
errorString = (String) getText(R.string.GIZ_OPENAPI_TWITTER_CONSUMER_KEY_INVALID);
break;
case GIZ_OPENAPI_NOT_ALLOW_WEEK_PASSWORD:
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_ALLOW_WEEK_PASSWORD);
break;
// case GIZ_OPENAPI_CODE_NOT_EXIST:
// errorString = (String) getText(R.string.GIZ_OPENAPI_CODE_NOT_EXIST);
// break;
// case GIZ_OPENAPI_EMAIL_NOT_ACTIVE:
// errorString = (String) getText(R.string.GIZ_OPENAPI_EMAIL_NOT_ACTIVE);
// break;
// case GIZ_OPENAPI_EMAIL_NOT_ENABLE:
// errorString = (String) getText(R.string.GIZ_OPENAPI_EMAIL_NOT_ENABLE);
// break;
// case GIZ_OPENAPI_DEVICE_REGISTER_NOT_FOUND:
// errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_REGISTER_NOT_FOUND);
// break;
case GIZ_OPENAPI_CANNOT_SHARE_TO_SELF:
errorString = (String) getText(R.string.GIZ_OPENAPI_CANNOT_SHARE_TO_SELF);
break;
case GIZ_OPENAPI_ONLY_OWNER_CAN_SHARE:
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_OWNER_CAN_SHARE);
break;
case GIZ_OPENAPI_NOT_FOUND_GUEST:
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_FOUND_GUEST);
break;
case GIZ_OPENAPI_GUEST_ALREADY_BOUND:
errorString = (String) getText(R.string.GIZ_OPENAPI_GUEST_ALREADY_BOUND);
break;
case GIZ_OPENAPI_NOT_FOUND_SHARING_INFO:
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_FOUND_SHARING_INFO);
break;
case GIZ_OPENAPI_NOT_FOUND_THE_MESSAGE:
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_FOUND_THE_MESSAGE);
break;
case GIZ_OPENAPI_SHARING_IS_WAITING_FOR_ACCEPT:
errorString = (String) getText(R.string.GIZ_OPENAPI_SHARING_IS_WAITING_FOR_ACCEPT);
break;
case GIZ_OPENAPI_SHARING_IS_EXPIRED:
errorString = (String) getText(R.string.GIZ_OPENAPI_SHARING_IS_EXPIRED);
break;
case GIZ_OPENAPI_SHARING_IS_COMPLETED:
errorString = (String) getText(R.string.GIZ_OPENAPI_SHARING_IS_COMPLETED);
break;
case GIZ_OPENAPI_INVALID_SHARING_BECAUSE_UNBINDING:
errorString = (String) getText(R.string.GIZ_OPENAPI_INVALID_SHARING_BECAUSE_UNBINDING);
break;
case GIZ_OPENAPI_ONLY_OWNER_CAN_BIND:
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_OWNER_CAN_BIND);
break;
case GIZ_OPENAPI_ONLY_OWNER_CAN_OPERATE:
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_OWNER_CAN_OPERATE);
break;
case GIZ_OPENAPI_SHARING_ALREADY_CANCELLED:
errorString = (String) getText(R.string.GIZ_OPENAPI_SHARING_ALREADY_CANCELLED);
break;
case GIZ_OPENAPI_OWNER_CANNOT_UNBIND_SELF:
errorString = (String) getText(R.string.GIZ_OPENAPI_OWNER_CANNOT_UNBIND_SELF);
break;
case GIZ_OPENAPI_ONLY_GUEST_CAN_CHECK_QRCODE:
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_GUEST_CAN_CHECK_QRCODE);
break;
case GIZ_OPENAPI_MESSAGE_ALREADY_DELETED:
errorString = (String) getText(R.string.GIZ_OPENAPI_MESSAGE_ALREADY_DELETED);
break;
case GIZ_OPENAPI_BINDING_NOTIFY_FAILED:
errorString = (String) getText(R.string.GIZ_OPENAPI_BINDING_NOTIFY_FAILED);
break;
case GIZ_OPENAPI_ONLY_SELF_CAN_MODIFY_ALIAS:
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_SELF_CAN_MODIFY_ALIAS);
break;
case GIZ_OPENAPI_ONLY_RECEIVER_CAN_MARK_MESSAGE:
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_RECEIVER_CAN_MARK_MESSAGE);
break;
case GIZ_OPENAPI_GUEST_NOT_BIND:
errorString = (String) getText(R.string.GIZ_OPENAPI_GUEST_NOT_BIND);
break;
case GIZ_OPENAPI_CANNOT_TRANSFER_OWNER_TO_SELF:
errorString = (String) getText(R.string.GIZ_OPENAPI_CANNOT_TRANSFER_OWNER_TO_SELF);
break;
case GIZ_OPENAPI_TRANSFER_OWNER_TO_LIMIT_GUEST:
errorString = (String) getText(R.string.GIZ_OPENAPI_TRANSFER_OWNER_TO_LIMIT_GUEST);
break;
case GIZ_OPENAPI_RESERVED:
errorString = (String) getText(R.string.GIZ_OPENAPI_RESERVED);
break;
case GIZ_PUSHAPI_BODY_JSON_INVALID:
errorString = (String) getText(R.string.GIZ_PUSHAPI_BODY_JSON_INVALID);
break;
case GIZ_PUSHAPI_DATA_NOT_EXIST:
errorString = (String) getText(R.string.GIZ_PUSHAPI_DATA_NOT_EXIST);
break;
case GIZ_PUSHAPI_NO_CLIENT_CONFIG:
errorString = (String) getText(R.string.GIZ_PUSHAPI_NO_CLIENT_CONFIG);
break;
case GIZ_PUSHAPI_NO_SERVER_DATA:
errorString = (String) getText(R.string.GIZ_PUSHAPI_NO_SERVER_DATA);
break;
case GIZ_PUSHAPI_GIZWITS_APPID_EXIST:
errorString = (String) getText(R.string.GIZ_PUSHAPI_GIZWITS_APPID_EXIST);
break;
case GIZ_PUSHAPI_PARAM_ERROR:
errorString = (String) getText(R.string.GIZ_PUSHAPI_PARAM_ERROR);
break;
case GIZ_PUSHAPI_AUTH_KEY_INVALID:
errorString = (String) getText(R.string.GIZ_PUSHAPI_AUTH_KEY_INVALID);
break;
case GIZ_PUSHAPI_APPID_OR_TOKEN_ERROR:
errorString = (String) getText(R.string.GIZ_PUSHAPI_APPID_OR_TOKEN_ERROR);
break;
case GIZ_PUSHAPI_TYPE_PARAM_ERROR:
errorString = (String) getText(R.string.GIZ_PUSHAPI_TYPE_PARAM_ERROR);
break;
case GIZ_PUSHAPI_ID_PARAM_ERROR:
errorString = (String) getText(R.string.GIZ_PUSHAPI_ID_PARAM_ERROR);
break;
case GIZ_PUSHAPI_APPKEY_SECRETKEY_INVALID:
errorString = (String) getText(R.string.GIZ_PUSHAPI_APPKEY_SECRETKEY_INVALID);
break;
case GIZ_PUSHAPI_CHANNELID_ERROR_INVALID:
errorString = (String) getText(R.string.GIZ_PUSHAPI_CHANNELID_ERROR_INVALID);
break;
case GIZ_PUSHAPI_PUSH_ERROR:
errorString = (String) getText(R.string.GIZ_PUSHAPI_PUSH_ERROR);
break;
case GIZ_SDK_SUBDEVICE_ADD_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_ADD_SUBDEVICE_FAILED);
break;
case GIZ_SDK_SUBDEVICE_DELETE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_DELETE_SUBDEVICE_FAILED);
break;
case GIZ_SDK_SUBDEVICE_LIST_UPDATE_FAILED:
errorString = (String) getText(R.string.GIZ_SDK_GET_SUBDEVICES_FAILED);
break;
default:
errorString = (String) getText(R.string.UNKNOWN_ERROR);
break;
}
return errorString;
}
}

@ -0,0 +1,311 @@
package com.gizwits.opensource.appkit.DeviceModule;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.gizwifisdk.api.GizWifiCentralControlDevice;
import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingUserRole;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceNetStatus;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.sharingdevice.addSharedActivity;
import com.gizwits.opensource.appkit.utils.AssetsUtils;
import java.util.List;
import java.util.Map;
import static com.gizwits.gizwifisdk.enumration.GizWifiDeviceType.GizDeviceCenterControl;
@SuppressLint("InflateParams")
public class GosDeviceListAdapter extends BaseAdapter {
private static final String TAG = "GosDeviceListAdapter";
Handler handler = new Handler();
SharedPreferences spf;
protected static final int UNBOUND = 99;
protected static final int SHARE = 100;
public void setHandler(Handler handler) {
this.handler = handler;
}
Context context;
List<GizWifiDevice> deviceList;
public GosDeviceListAdapter(Context context, List<GizWifiDevice> deviceList) {
super();
this.context = context;
this.deviceList = deviceList;
}
public void setSpf(SharedPreferences spf) {
this.spf = spf;
}
@Override
public int getCount() {
return deviceList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
Holder holder;
if (view == null) {
view = LayoutInflater.from(context).inflate(
R.layout.item_gos_device_list, null);
holder = new Holder(view);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
final GizWifiDevice device = deviceList.get(position);
String deviceAlias = device.getAlias();
String devicePN = device.getProductName();
GizDeviceSharingUserRole role = device.getSharingRole();
if (role != null) {
if (role.name().equals("GizDeviceSharingSpecial") || role.name().equals("GizDeviceSharingOwner")) {
holder.getDelete2().setVisibility(View.VISIBLE);
holder.getDelete1().setVisibility(View.VISIBLE);
holder.getDevice().setPadding(0, 0, AssetsUtils.diptopx(context, -181), 0);
} else {
holder.getDelete1().setVisibility(View.GONE);
holder.getDelete2().setVisibility(View.VISIBLE);
holder.getDevice().setPadding(0, 0, AssetsUtils.diptopx(context, -91), 0);
}
}
GizWifiCentralControlDevice centralControlDevice = null;
holder.getTvDeviceMac().setVisibility(View.GONE);
holder.getTvDeviceMac().setVisibility(View.VISIBLE);
holder.getTvDeviceMac().setText(device.getMacAddress());
if (device.getNetStatus() == GizWifiDeviceNetStatus.GizDeviceOnline
|| device.getNetStatus() == GizWifiDeviceNetStatus.GizDeviceControlled) {
if (device.isLAN()) {
holder.getLlLeft().setImageResource(R.drawable.common_device_lan_online);
} else {
holder.getLlLeft().setImageResource(R.drawable.common_device_remote_online);
}
holder.getImgRight().setVisibility(View.VISIBLE);
if (device.isBind()) {// 已绑定设备
if (device.getProductType() == GizDeviceCenterControl) {
if (device instanceof GizWifiCentralControlDevice) {
centralControlDevice = (GizWifiCentralControlDevice) device;
}
}
if (centralControlDevice != null) {
if (centralControlDevice.getSubDeviceList().size() != 0) {
holder.getTvDeviceMac().setVisibility(View.VISIBLE);
if (AssetsUtils.isZh(context)) {
StringBuffer sb = new StringBuffer();
sb.append("已连接");
sb.append(centralControlDevice.getSubDeviceList().size());
sb.append("个设备");
holder.getTvDeviceMac().setText(sb.toString());
} else {
StringBuffer sb = new StringBuffer();
sb.append(centralControlDevice.getSubDeviceList().size());
sb.append(" devices connected");
holder.getTvDeviceMac().setText(sb.toString());
}
if (AssetsUtils.isZh(context)) {
StringBuffer sb = new StringBuffer();
sb.append(centralControlDevice.getMacAddress());
sb.append(" 已连接");
sb.append(centralControlDevice.getSubDeviceList().size());
sb.append("个设备");
holder.getTvDeviceMac().setText(sb.toString());
} else {
StringBuffer sb = new StringBuffer();
sb.append(centralControlDevice.getMacAddress());
sb.append(" ");
sb.append(centralControlDevice.getSubDeviceList().size());
sb.append(" devices connected");
holder.getTvDeviceMac().setText(sb.toString());
}
}
}
//这里会出现箭头不显示的状态
// holder.getImgRight().setVisibility(View.VISIBLE);
} else {// 未绑定设备
holder.getDelete2().setVisibility(View.GONE);
holder.getDevice().setPadding(0, 0, AssetsUtils.diptopx(context, 0), 0);
}
} else {// 设备不在线
holder.getSbDeviceStatus().setClickable(false);
holder.getImgRight().setVisibility(View.GONE);
if (device.isLAN()) {
holder.getLlLeft().setImageResource(R.drawable.common_device_lan_offline);
} else {
holder.getLlLeft().setImageResource(R.drawable.common_device_remote_offline);
}
}
if (TextUtils.isEmpty(deviceAlias)) {
List<Map<String, Object>> list = GosDeploy.appConfig_DeviceInfo();
boolean isName = true;
for (Map<String, Object> map : list) {
if (map.containsKey("productKey")) {
if (device.getProductKey().equals(map.get("productKey"))) {
if (AssetsUtils.isZh(context)) {
if (map.containsKey("productNameCH")) {
isName = false;
holder.getTvDeviceName().setText(map.get("productNameCH").toString());
}
} else {
if (map.containsKey("productNameEN")) {
isName = false;
holder.getTvDeviceName().setText(map.get("productNameEN").toString());
}
}
}
}
}
if (isName) {
holder.getTvDeviceName().setText(devicePN);
}
} else {
holder.getTvDeviceName().setText(deviceAlias);
}
holder.getDelete2().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Message message = new Message();
message.what = UNBOUND;
message.obj = device.getDid().toString();
handler.sendMessage(message);
}
});
holder.getDelete1().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Message message = new Message();
message.what = SHARE;
message.obj = device.getDid().toString();
handler.sendMessage(message);
if (!TextUtils.isEmpty(spf.getString("UserName", "")) && !TextUtils.isEmpty(spf.getString("PassWord", ""))) {
Intent intent = new Intent(context, addSharedActivity.class);
intent.putExtra("productname", device.getProductName());
intent.putExtra("did", device.getDid());
context.startActivity(intent);
} else {
Toast.makeText(context, context.getString(R.string.please_login), 2000).show();
}
}
});
return view;
}
}
class Holder {
View view;
public Holder(View view) {
this.view = view;
}
private TextView tvDeviceMac, tvDeviceStatus, tvDeviceName;
private RelativeLayout delete1, delete2, device;
private ImageView imgRight;
private ImageView lvLeft;
private Switch sbDeviceStatus;
public ImageView getLlLeft() {
if (null == lvLeft) {
lvLeft = (ImageView) view.findViewById(R.id.imgLeft);
}
return lvLeft;
}
public ImageView getImgRight() {
if (null == imgRight) {
imgRight = (ImageView) view.findViewById(R.id.imgRight);
}
return imgRight;
}
public RelativeLayout getDevice() {
if (null == device) {
device = (RelativeLayout) view.findViewById(R.id.rl_device);
}
return device;
}
public RelativeLayout getDelete2() {
if (null == delete2) {
delete2 = (RelativeLayout) view.findViewById(R.id.delete2);
}
return delete2;
}
public RelativeLayout getDelete1() {
if (null == delete1) {
delete1 = (RelativeLayout) view.findViewById(R.id.delete1);
}
return delete1;
}
public TextView getTvDeviceMac() {
if (null == tvDeviceMac) {
tvDeviceMac = (TextView) view.findViewById(R.id.tvDeviceMac);
}
return tvDeviceMac;
}
public TextView getTvDeviceName() {
if (null == tvDeviceName) {
tvDeviceName = (TextView) view.findViewById(R.id.tvDeviceName);
}
return tvDeviceName;
}
public Switch getSbDeviceStatus() {
if (null == sbDeviceStatus) {
sbDeviceStatus = (Switch) view.findViewById(R.id.sbDeviceStatus);
}
return sbDeviceStatus;
}
}

@ -0,0 +1,847 @@
package com.gizwits.opensource.appkit.DeviceModule;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceNetStatus;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.ConfigModule.GosAirlinkChooseDeviceWorkWiFiActivity;
import com.gizwits.opensource.appkit.ConfigModule.GosChooseDeviceWorkWiFiActivity;
import com.gizwits.opensource.appkit.ControlModule.GosDeviceControlActivity;
import com.gizwits.opensource.appkit.PushModule.GosPushManager;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.view.SlideListView2;
import com.gizwits.opensource.appkit.view.VerticalSwipeRefreshLayout;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
// config-all-start
// config_airlink-false-start
// config_airlink-false-end
//config_softap-false-start
//config_softap-false-end
// config-all-end
@SuppressLint("HandlerLeak")
public class GosDeviceListFragment extends GosDeviceModuleBaseFragment implements OnRefreshListener {
/**
* The ll NoDevice
*/
private ScrollView llNoDevice;
SwipeRefreshLayout mSwipeLayout;
/**
* The img NoDevice
*/
private ImageView imgNoDevice;
/**
* The btn NoDevice
*/
private Button btnNoDevice;
/**
* The ic BoundDevices
*/
private View icBoundDevices;
/**
* The ic FoundDevices
*/
private View icFoundDevices;
/**
* The tv BoundDevicesListTitle
*/
private TextView tvBoundDevicesListTitle;
/**
* The tv FoundDevicesListTitle
*/
private TextView tvFoundDevicesListTitle;
/**
* The ll NoBoundDevices
*/
private LinearLayout llNoBoundDevices;
/**
* The ll NoFoundDevices
*/
private LinearLayout llNoFoundDevices;
/**
* The slv BoundDevices
*/
private SlideListView2 slvBoundDevices;
/**
* The slv FoundDevices
*/
private SlideListView2 slvFoundDevices;
/**
* The sv ListGroup
*/
private ScrollView svListGroup;
/**
*
*/
private GosDeviceListAdapter myadapter;
private GosDeviceListAdapter myadapter1;
/**
*
*/
List<GizWifiDevice> boundDevicesList = new ArrayList<GizWifiDevice>();
List<GizWifiDevice> foundDevicesList = new ArrayList<GizWifiDevice>();
List<GizWifiDevice> offlineDevicesList = new ArrayList<GizWifiDevice>();
/**
*
*/
ArrayList<String> softNameList;
/**
* APPProductKey
*/
private List<String> ProductKeyList;
Intent intent;
String softssid, uid, token;
public static List<String> boundMessage;
/**
* 0 1 2 3 4
*/
public static int loginStatus;
int threeSeconds = 3;
/**
*
*/
protected static final int GETLIST = 0;
/**
*
*/
protected static final int UPDATALIST = 1;
/**
*
*/
protected static final int TOCONTROL = 2;
/**
*
*/
protected static final int TOAST = 3;
/**
*
*/
protected static final int BOUND = 9;
/**
*
*/
protected static final int UNBOUND = 99;
private static final int PULL_TO_REFRESH = 888;
private VerticalSwipeRefreshLayout mSwipeLayout1;
/**
*
*/
public ProgressDialog progressDialog;
Handler handler = new Handler() {
private AlertDialog myDialog;
private TextView dialog_name;
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case GETLIST:
Log.e(TAG, "handleMessage:GETLIST -----------------" + uid);
if (!uid.isEmpty() && !token.isEmpty()) {
// GizWifiSDK.sharedInstance().getBoundDevices(uid, token, ProductKeyList);
GizWifiSDK.sharedInstance().getBoundDevices(uid, token);
}
//login_anonymous-false-start
if (loginStatus == 0 && GosDeploy.appConfig_Login_Anonymous()) {
loginStatus = 3;
GizWifiSDK.sharedInstance().userLoginAnonymous();
}
//login_anonymous-false-end
break;
case UPDATALIST:
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.cancel();
}
UpdateUI();
break;
case BOUND:
break;
case UNBOUND:
if (progressDialog != null) {
progressDialog.show();
}
GizWifiSDK.sharedInstance().unbindDevice(uid, token, msg.obj.toString());
break;
case TOCONTROL:
intent = null;
Bundle bundle = new Bundle();
GizWifiDevice device = (GizWifiDevice) msg.obj;
if (intent == null) {
intent = new Intent(getContext(), GosDeviceControlActivity.class);
}
bundle.putParcelable("GizWifiDevice", device);
intent.putExtras(bundle);
startActivityForResult(intent, 1);
break;
case TOAST:
Toast.makeText(getContext(), msg.obj.toString(), 2000).show();
break;
case PULL_TO_REFRESH:
handler.sendEmptyMessage(GETLIST);
mSwipeLayout.setRefreshing(false);
mSwipeLayout1.setRefreshing(false);
break;
}
}
};
private View allView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
allView = inflater.inflate(R.layout.activity_gos_device_list, container, false);
//handler.sendEmptyMessage(GETLIST);
GosMessageHandler.getSingleInstance().StartLooperWifi(getContext());
setProgressDialog();
softNameList = new ArrayList<String>();
initData();
initView();
initEvent();
return allView;
}
/*
* @Override public void onWindowFocusChanged(boolean hasFocus) {
* super.onWindowFocusChanged(hasFocus); if (hasFocus && isFrist) {
* progressDialog.show();
*
* isFrist = false; } }
*/
@Override
public void onResume() {
super.onResume();
Log.e(TAG, "onResume: -------------");
handler.sendEmptyMessage(GETLIST);
GosDeviceModuleBaseFragment.deviceslist = GizWifiSDK.sharedInstance().getDeviceList();
UpdateUI();
// TODO GosMessageHandler.getSingleInstance().SetHandler(handler);
if (boundMessage.size() != 0) {
progressDialog.show();
if (boundMessage.size() == 2) {
GizWifiSDK.sharedInstance().bindDevice(uid, token, boundMessage.get(0), boundMessage.get(1), null);
} else if (boundMessage.size() == 1) {
GizWifiSDK.sharedInstance().bindDeviceByQRCode(uid, token, boundMessage.get(0), false);
} else if (boundMessage.size() == 3) {
GizDeviceSharing.checkDeviceSharingInfoByQRCode(spf.getString("Token", ""), boundMessage.get(2));
} else {
Log.i("Apptest", "ListSize:" + boundMessage.size());
}
}
}
@Override
public void onPause() {
super.onPause();
boundMessage.clear();
// TODO GosMessageHandler.getSingleInstance().SetHandler(null);
}
private void initView() {
svListGroup = (ScrollView) allView.findViewById(R.id.svListGroup);
llNoDevice = (ScrollView) allView.findViewById(R.id.llNoDevice);
imgNoDevice = (ImageView) allView.findViewById(R.id.imgNoDevice);
btnNoDevice = (Button) allView.findViewById(R.id.btnNoDevice);
icBoundDevices = allView.findViewById(R.id.icBoundDevices);
icFoundDevices = allView.findViewById(R.id.icFoundDevices);
slvBoundDevices = (SlideListView2) icBoundDevices.findViewById(R.id.slideListView1);
slvFoundDevices = (SlideListView2) icFoundDevices.findViewById(R.id.slideListView1);
llNoBoundDevices = (LinearLayout) icBoundDevices.findViewById(R.id.llHaveNotDevice);
llNoFoundDevices = (LinearLayout) icFoundDevices.findViewById(R.id.llHaveNotDevice);
tvBoundDevicesListTitle = (TextView) icBoundDevices.findViewById(R.id.tvListViewTitle);
tvFoundDevicesListTitle = (TextView) icFoundDevices.findViewById(R.id.tvListViewTitle);
String boundDevicesListTitle = null;
String foundDevicesListTitle = null;
boundDevicesListTitle = (String) getText(R.string.my_device);
foundDevicesListTitle = (String) getText(R.string.found_devices);
tvBoundDevicesListTitle.setText(boundDevicesListTitle);
tvFoundDevicesListTitle.setText(foundDevicesListTitle);
// 下拉刷新
mSwipeLayout = (VerticalSwipeRefreshLayout) allView.findViewById(R.id.id_swipe_ly);
mSwipeLayout.setOnRefreshListener(this);
mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
android.R.color.holo_orange_light, android.R.color.holo_red_light);
mSwipeLayout1 = (VerticalSwipeRefreshLayout) allView.findViewById(R.id.id_swipe_ly1);
mSwipeLayout1.setOnRefreshListener(this);
mSwipeLayout1.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
android.R.color.holo_orange_light, android.R.color.holo_red_light);
// setActionBar(true, true, "");
// actionBar.setIcon(getResources().getDrawable(R.drawable.qr_code));
}
private void initEvent() {
myadapter = new GosDeviceListAdapter(getContext(), foundDevicesList);
myadapter.setHandler(handler);
myadapter.setSpf(spf);
slvFoundDevices.setAdapter(myadapter);
myadapter1 = new GosDeviceListAdapter(getContext(), boundDevicesList);
myadapter1.setHandler(handler);
myadapter1.setSpf(spf);
slvBoundDevices.setAdapter(myadapter1);
// config-all-start
imgNoDevice.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
addDevice();
}
});
btnNoDevice.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
addDevice();
}
});
// config-all-end
slvFoundDevices.initSlideMode(SlideListView2.MOD_FORBID);
slvFoundDevices.setFocusable(false);
slvBoundDevices.initSlideMode(SlideListView2.MOD_RIGHT);
slvBoundDevices.setFocusable(false);
slvFoundDevices.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
slvFoundDevices.setEnabled(false);
slvFoundDevices.postDelayed(new Runnable() {
@Override
public void run() {
slvFoundDevices.setEnabled(true);
}
}, 1000);
final GizWifiDevice device = foundDevicesList.get(position);
device.setListener(getGizWifiDeviceListener(device));
if (device.getNetStatus() != GizWifiDeviceNetStatus.GizDeviceOffline) {
boolean isAuto = false;
List<Map<String, String>> list2 = GosDeploy.appConfig_ProductList();
for (Map<String, String> map2 : list2) {
String productkey = device.getProductKey();
Iterator it1 = map2.entrySet().iterator();
while (it1.hasNext()) {
Map.Entry entry1 = (Map.Entry) it1.next();
if (productkey.equals(entry1.getKey())) {
isAuto = true;
device.setSubscribe(entry1.getValue().toString(), true);
progressDialog.show();
break;
}
}
}
if (device.getNetStatus() == GizWifiDeviceNetStatus.GizDeviceOnline
&& !TextUtils.isEmpty(device.getDid()) && !device.isBind()
&& device.getProductType() == GizWifiDeviceType.GizDeviceSub) {
if (!isAuto) {
final Dialog dialog = new AlertDialog.Builder(getContext(), R.style.alert_dialog_style)
.setView(new EditText(getContext())).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_edit_name);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
TextView title = (TextView) window.findViewById(R.id.tvTitle);
final EditText remarkname = (EditText) window.findViewById(R.id.remarkname);
title.setText(getString(R.string.pleaseenterps));
LinearLayout llyes = (LinearLayout) window.findViewById(R.id.llSure);
LinearLayout llno = (LinearLayout) window.findViewById(R.id.llNo);
remarkname.setHint(getResources().getString(R.string.pleaseenter32ps));
llno.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
llyes.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String ps = remarkname.getText().toString();
if (TextUtils.isEmpty(ps) || ps.length() != 32) {
Toast.makeText(getContext(),
getResources().getString(R.string.psiserror), 0).show();
} else {
device.setSubscribe(remarkname.getText().toString(), true);
//device.setSubscribe(true);
progressDialog.show();
/**隐藏软键盘**/
View view = getActivity().getWindow().peekDecorView();
if (view != null) {
InputMethodManager inputmanger = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
dialog.dismiss();
}
}
});
}
} else {
// device.setSubscribe(null, true);
if (!isAuto) {
device.setSubscribe(null, true);
progressDialog.show();
}
}
}
}
});
slvBoundDevices.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
if (position < boundDevicesList.size()) {
slvBoundDevices.setEnabled(false);
slvBoundDevices.postDelayed(new Runnable() {
@Override
public void run() {
slvBoundDevices.setEnabled(true);
}
}, 1000);
final GizWifiDevice device = boundDevicesList.get(position);
device.setListener(getGizWifiDeviceListener(device));
if (device.getNetStatus() != GizWifiDeviceNetStatus.GizDeviceOffline) {
String productKey = device.getProductKey();
List<Map<String, String>> list2 = GosDeploy.appConfig_ProductList();
boolean isSubscribe = false;
for (Map<String, String> map2 : list2) {
Iterator it1 = map2.entrySet().iterator();
while (it1.hasNext()) {
Map.Entry entry1 = (Map.Entry) it1.next();
if (productKey.equals(entry1.getKey())) {
isSubscribe = true;
device.setSubscribe(entry1.getValue().toString(), true);
}
}
}
if (!isSubscribe) {
device.setSubscribe(null, true);
progressDialog.show();
}
}
}
}
});
}
private void initData() {
boundMessage = new ArrayList<String>();
// ProductKeyList = GosDeploy.setProductKeyList();
ProductKeyList = null;
uid = spf.getString("Uid", "");
token = spf.getString("Token", "");
if (uid.isEmpty() && token.isEmpty()) {
loginStatus = 0;
}
}
protected void didDiscovered(GizWifiErrorCode result, List<GizWifiDevice> deviceList) {
Log.e(TAG, "didDiscovered: 更新数据---------------");
GosDeviceModuleBaseFragment.deviceslist.clear();
for (GizWifiDevice gizWifiDevice : deviceList) {
GosDeviceModuleBaseFragment.deviceslist.add(gizWifiDevice);
}
handler.sendEmptyMessage(UPDATALIST);
}
protected void didUserLogin(GizWifiErrorCode result, String uid, String token) {
Log.e(TAG, "didUserLogin: -----------");
if (GizWifiErrorCode.GIZ_SDK_SUCCESS == result) {
loginStatus = 2;
this.uid = uid;
this.token = token;
spf.edit().putString("Uid", this.uid).commit();
spf.edit().putString("Token", this.token).commit();
handler.sendEmptyMessage(GETLIST);
// TODO 绑定推送
//GosPushManager.pushBindService(token);
if (GosDeploy.appConfig_Push_BaiDu()) {
GosPushManager.pushBindService(uid, token);
}
if (GosDeploy.appConfig_Push_JiGuang()) {
GosPushManager.pushBindService(uid, token);
}
} else {
loginStatus = 0;
if (GosDeploy.appConfig_Login_Anonymous()) {
tryUserLoginAnonymous();
}
}
}
protected void didUnbindDevice(GizWifiErrorCode result, String did) {
if (progressDialog != null) {
progressDialog.cancel();
}
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
// String unBoundFailed = (String) getText(R.string.unbound_failed);
Toast.makeText(getContext(), toastError(result), 2000).show();
}
}
@Override
protected void didSetSubscribe(GizWifiErrorCode result, GizWifiDevice device, boolean isSubscribed) {
// TODO 控制页面跳转
if (progressDialog != null) {
progressDialog.cancel();
}
Message msg = new Message();
if (GizWifiErrorCode.GIZ_SDK_SUCCESS == result) {
msg.what = TOCONTROL;
msg.obj = device;
} else {
if (device.isBind()) {
msg.what = TOAST;
// String setSubscribeFail = (String)
// getText(R.string.setsubscribe_failed);
msg.obj = toastError(result);// setSubscribeFail + "\n" + arg0;
}
}
handler.sendMessage(msg);
}
/**
*
*
* @param result
*/
@Override
protected void didChannelIDBind(GizWifiErrorCode result) {
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
Toast.makeText(getContext(), toastError(result), 2000).show();
}
}
/**
* ()
*
* @param error
* @param errorMessage
* @param did
*/
protected void didBindDevice(int error, String errorMessage, String did) {
if (progressDialog != null) {
progressDialog.cancel();
}
if (error != 0) {
String toast = getResources().getString(R.string.bound_failed) + "\n" + errorMessage;
Toast.makeText(getContext(), toast, 2000).show();
// Toast.makeText(this, R.string.bound_failed + "\n" + errorMessage,
// 2000).show();
} else {
Toast.makeText(getContext(), R.string.bound_successful, 2000).show();
}
}
private static final String TAG = "GosDeviceListFragment";
/**
*
*
* @param result
* @param did
*/
protected void didBindDevice(GizWifiErrorCode result, String did) {
if (progressDialog != null) {
progressDialog.cancel();
}
if (result != GizWifiErrorCode.GIZ_SDK_SUCCESS) {
Toast.makeText(getContext(), toastError(result), 2000).show();
} else {
Toast.makeText(getContext(), R.string.add_successful, 2000).show();
}
}
private void UpdateUI() {
if (GosDeviceModuleBaseFragment.deviceslist.isEmpty()) {
svListGroup.setVisibility(View.GONE);
llNoDevice.setVisibility(View.VISIBLE);
mSwipeLayout1.setVisibility(View.VISIBLE);
return;
} else {
llNoDevice.setVisibility(View.GONE);
mSwipeLayout1.setVisibility(View.GONE);
svListGroup.setVisibility(View.VISIBLE);
}
if (boundDevicesList == null) {
boundDevicesList = new ArrayList<GizWifiDevice>();
} else {
boundDevicesList.clear();
}
if (foundDevicesList == null) {
foundDevicesList = new ArrayList<GizWifiDevice>();
} else {
foundDevicesList.clear();
}
if (offlineDevicesList == null) {
offlineDevicesList = new ArrayList<GizWifiDevice>();
} else {
offlineDevicesList.clear();
}
for (GizWifiDevice gizWifiDevice : GosDeviceModuleBaseFragment.deviceslist) {
if (gizWifiDevice.isBind()) {
boundDevicesList.add(gizWifiDevice);
} else {
foundDevicesList.add(gizWifiDevice);
}
}
if (foundDevicesList.isEmpty()) {
slvFoundDevices.setVisibility(View.GONE);
llNoFoundDevices.setVisibility(View.VISIBLE);
} else {
if (myadapter == null) {
myadapter = new GosDeviceListAdapter(getContext(), foundDevicesList);
myadapter.setHandler(handler);
myadapter.setSpf(spf);
slvFoundDevices.setAdapter(myadapter);
} else {
myadapter.notifyDataSetChanged();
}
llNoFoundDevices.setVisibility(View.GONE);
slvFoundDevices.setVisibility(View.VISIBLE);
}
if (boundDevicesList.isEmpty()) {
slvBoundDevices.setVisibility(View.GONE);
llNoBoundDevices.setVisibility(View.VISIBLE);
} else {
if (myadapter1 == null) {
myadapter1 = new GosDeviceListAdapter(getContext(), boundDevicesList);
myadapter1.setHandler(handler);
myadapter1.setSpf(spf);
slvBoundDevices.setAdapter(myadapter1);
} else {
if (slvBoundDevices.isSlided()) {
slvBoundDevices.slideBack();
}
myadapter1.notifyDataSetChanged();
}
llNoBoundDevices.setVisibility(View.GONE);
slvBoundDevices.setVisibility(View.VISIBLE);
}
}
private void addDevice() {
if (GosDeploy.appConfig_Config_Softap()) {
if (!checkNetwork(getContext())) {
Toast.makeText(getContext(), R.string.network_error, 2000).show();
return;
}
if (GosDeploy.appConfig_Config_Airlink()) {
final Dialog dialog = new AlertDialog.Builder(getContext(), R.style.alert_dialog_style)
.setView(new EditText(getContext())).create();
dialog.setCanceledOnTouchOutside(true);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_overflow);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
LinearLayout llAirlink;
LinearLayout llSoftap;
llAirlink = (LinearLayout) window.findViewById(R.id.llAirlink);
llSoftap = (LinearLayout) window.findViewById(R.id.llSoftap);
llAirlink.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
intent = new Intent(getContext(), GosAirlinkChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
dialog.dismiss();
}
});
llSoftap.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
intent = new Intent(getContext(), GosChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
dialog.dismiss();
}
});
} else {
Intent intent = new Intent(getContext(), GosChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
}
} else {
if (GosDeploy.appConfig_Config_Airlink()) {
if (!checkNetwork(getContext())) {
Toast.makeText(getContext(), R.string.network_error, 2000).show();
return;
}
Intent intent = new Intent(getContext(), GosAirlinkChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
}
}
}
private void tryUserLoginAnonymous() {
threeSeconds = 3;
final Timer tsTimer = new Timer();
tsTimer.schedule(new TimerTask() {
@Override
public void run() {
threeSeconds--;
if (threeSeconds <= 0) {
tsTimer.cancel();
handler.sendEmptyMessage(GETLIST);
} else {
if (loginStatus == 4) {
tsTimer.cancel();
}
}
}
}, 1000, 1000);
}
@Override
public void onRefresh() {
handler.sendEmptyMessageDelayed(PULL_TO_REFRESH, 2000);
}
@Override
public void onDestroy() {
super.onDestroy();
progressDialog = null;
}
/**
* ProgressDialog
*/
public void setProgressDialog() {
progressDialog = new ProgressDialog(getContext());
String loadingText = getString(R.string.loadingtext);
progressDialog.setMessage(loadingText);
progressDialog.setCanceledOnTouchOutside(false);
}
/**
*
*
* @param context
* @return
*/
public boolean checkNetwork(Context context) {
ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo net = conn.getActiveNetworkInfo();
if (net != null && net.isConnected()) {
return true;
}
return false;
}
}

@ -0,0 +1,210 @@
package com.gizwits.opensource.appkit.DeviceModule;
import com.gizwits.gizwifisdk.api.GizWifiCentralControlDevice;
import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceNetStatus;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizWifiCentralControlDeviceListener;
import com.gizwits.gizwifisdk.listener.GizWifiDeviceListener;
import com.gizwits.gizwifisdk.listener.GizWifiSDKListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
public class GosDeviceModuleBaseActivity extends GosBaseActivity {
/**
*
*/
protected static List<GizWifiDevice> deviceslist = new ArrayList<GizWifiDevice>();
private GizWifiSDKListener gizWifiSDKListener = new GizWifiSDKListener() {
/** 用于设备列表 */
public void didDiscovered(GizWifiErrorCode result, List<GizWifiDevice> deviceList) {
GosDeviceModuleBaseActivity.this.didDiscovered(result, deviceList);
}
/** 用于用户匿名登录 */
public void didUserLogin(GizWifiErrorCode result, String uid, String token) {
GosDeviceModuleBaseActivity.this.didUserLogin(result, uid, token);
}
/** 用于设备解绑 */
public void didUnbindDevice(GizWifiErrorCode result, String did) {
GosDeviceModuleBaseActivity.this.didUnbindDevice(result, did);
}
/** 用于设备绑定 */
public void didBindDevice(GizWifiErrorCode result, String did) {
GosDeviceModuleBaseActivity.this.didBindDevice(result, did);
}
/** 用于设备绑定(旧) */
public void didBindDevice(int error, String errorMessage, String did) {
GosDeviceModuleBaseActivity.this.didBindDevice(error, errorMessage, did);
}
;
/** 用于绑定推送 */
public void didChannelIDBind(GizWifiErrorCode result) {
GosDeviceModuleBaseActivity.this.didChannelIDBind(result);
}
};
/**
*
*
* @param result
* @param deviceList
*/
protected void didDiscovered(GizWifiErrorCode result, List<GizWifiDevice> deviceList) {
}
/**
*
*
* @param result
* @param uid
* @param token
*/
protected void didUserLogin(GizWifiErrorCode result, String uid, String token) {
}
/**
*
*
* @param result
* @param did
*/
protected void didUnbindDevice(GizWifiErrorCode result, String did) {
}
/**
* ()
*
* @param error
* @param errorMessage
* @param did
*/
protected void didBindDevice(int error, String errorMessage, String did) {
}
;
/**
*
*
* @param result
* @param did
*/
protected void didBindDevice(GizWifiErrorCode result, String did) {
}
/**
*
*
* @param result
*/
protected void didChannelIDBind(GizWifiErrorCode result) {
}
/**
*
*/
protected GizWifiDeviceListener gizWifiDeviceListener = new GizWifiDeviceListener() {
// 用于设备订阅
public void didSetSubscribe(GizWifiErrorCode result, GizWifiDevice device, boolean isSubscribed) {
GosDeviceModuleBaseActivity.this.didSetSubscribe(result, device, isSubscribed);
}
;
};
protected GizWifiCentralControlDeviceListener gizWifisubDeviceListener = new GizWifiCentralControlDeviceListener() {
// 用于设备订阅
public void didSetSubscribe(GizWifiErrorCode result, GizWifiDevice device, boolean isSubscribed) {
GosDeviceModuleBaseActivity.this.didSetSubscribe(result, device, isSubscribed);
}
//同步更新子设备列表
@Override
public void didUpdateSubDevices(GizWifiCentralControlDevice device, GizWifiErrorCode result, List<GizWifiDevice> subDeviceList) {
GosDeviceModuleBaseActivity.this.didUpdateSubDevices(device, result, subDeviceList);
}
//设备网络状态变化通知
@Override
public void didUpdateNetStatus(GizWifiDevice device, GizWifiDeviceNetStatus netStatus) {
GosDeviceModuleBaseActivity.this.didUpdateNetStatus(device, netStatus);
}
;
};
public GizWifiDeviceListener getGizWifiDeviceListener(GizWifiDevice device) {
if (device.getProductType() == GizWifiDeviceType.GizDeviceNormal) {
return gizWifiDeviceListener;
} else {
return gizWifisubDeviceListener;
}
}
/**
*
*
* @param device
* @param netStatus
*/
protected void didUpdateNetStatus(GizWifiDevice device, GizWifiDeviceNetStatus netStatus) {
}
/**
*
*
* @param device
* @param result
* @param subDeviceList
*/
protected void didUpdateSubDevices(GizWifiCentralControlDevice device, GizWifiErrorCode result, List<GizWifiDevice> subDeviceList) {
}
/**
*
*
* @param result
* @param device
* @param isSubscribed
*/
protected void didSetSubscribe(GizWifiErrorCode result, GizWifiDevice device, boolean isSubscribed) {
}
@Override
protected void onResume() {
super.onResume();
// 每次返回activity都要注册一次sdk监听器保证sdk状态能正确回调
GizWifiSDK.sharedInstance().setListener(gizWifiSDKListener);
}
/**
* @param result
* @param cloudServiceInfo
*/
protected void didGetCurrentCloudService(GizWifiErrorCode result,
ConcurrentHashMap<String, String> cloudServiceInfo) {
}
}

@ -0,0 +1,214 @@
package com.gizwits.opensource.appkit.DeviceModule;
import android.util.Log;
import com.gizwits.gizwifisdk.api.GizWifiCentralControlDevice;
import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceNetStatus;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizWifiCentralControlDeviceListener;
import com.gizwits.gizwifisdk.listener.GizWifiDeviceListener;
import com.gizwits.gizwifisdk.listener.GizWifiSDKListener;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
public class GosDeviceModuleBaseFragment extends GosBaseFragment {
/**
*
*/
protected static List<GizWifiDevice> deviceslist = new ArrayList<GizWifiDevice>();
private GizWifiSDKListener gizWifiSDKListener = new GizWifiSDKListener() {
/** 用于设备列表 */
public void didDiscovered(GizWifiErrorCode result, List<GizWifiDevice> deviceList) {
GosDeviceModuleBaseFragment.this.didDiscovered(result, deviceList);
Log.e("GosDeviceModuleBaseFragment", "didDiscovered=====----: 更新数据");
}
/** 用于用户匿名登录 */
public void didUserLogin(GizWifiErrorCode result, String uid, String token) {
GosDeviceModuleBaseFragment.this.didUserLogin(result, uid, token);
}
/** 用于设备解绑 */
public void didUnbindDevice(GizWifiErrorCode result, String did) {
GosDeviceModuleBaseFragment.this.didUnbindDevice(result, did);
}
/** 用于设备绑定 */
public void didBindDevice(GizWifiErrorCode result, String did) {
GosDeviceModuleBaseFragment.this.didBindDevice(result, did);
}
/** 用于设备绑定(旧) */
public void didBindDevice(int error, String errorMessage, String did) {
GosDeviceModuleBaseFragment.this.didBindDevice(error, errorMessage, did);
}
;
/** 用于绑定推送 */
public void didChannelIDBind(GizWifiErrorCode result) {
GosDeviceModuleBaseFragment.this.didChannelIDBind(result);
}
};
/**
*
*
* @param result
* @param deviceList
*/
protected void didDiscovered(GizWifiErrorCode result, List<GizWifiDevice> deviceList) {
}
/**
*
*
* @param result
* @param uid
* @param token
*/
protected void didUserLogin(GizWifiErrorCode result, String uid, String token) {
}
/**
*
*
* @param result
* @param did
*/
protected void didUnbindDevice(GizWifiErrorCode result, String did) {
}
/**
* ()
*
* @param error
* @param errorMessage
* @param did
*/
protected void didBindDevice(int error, String errorMessage, String did) {
}
;
/**
*
*
* @param result
* @param did
*/
protected void didBindDevice(GizWifiErrorCode result, String did) {
}
/**
*
*
* @param result
*/
protected void didChannelIDBind(GizWifiErrorCode result) {
}
/**
*
*/
protected GizWifiDeviceListener gizWifiDeviceListener = new GizWifiDeviceListener() {
// 用于设备订阅
public void didSetSubscribe(GizWifiErrorCode result, GizWifiDevice device, boolean isSubscribed) {
GosDeviceModuleBaseFragment.this.didSetSubscribe(result, device, isSubscribed);
}
;
};
protected GizWifiCentralControlDeviceListener gizWifisubDeviceListener = new GizWifiCentralControlDeviceListener() {
// 用于设备订阅
public void didSetSubscribe(GizWifiErrorCode result, GizWifiDevice device, boolean isSubscribed) {
GosDeviceModuleBaseFragment.this.didSetSubscribe(result, device, isSubscribed);
}
//同步更新子设备列表
@Override
public void didUpdateSubDevices(GizWifiCentralControlDevice device, GizWifiErrorCode result, List<GizWifiDevice> subDeviceList) {
GosDeviceModuleBaseFragment.this.didUpdateSubDevices(device, result, subDeviceList);
}
//设备网络状态变化通知
@Override
public void didUpdateNetStatus(GizWifiDevice device, GizWifiDeviceNetStatus netStatus) {
GosDeviceModuleBaseFragment.this.didUpdateNetStatus(device, netStatus);
}
;
};
public GizWifiDeviceListener getGizWifiDeviceListener(GizWifiDevice device) {
if (device.getProductType() == GizWifiDeviceType.GizDeviceNormal) {
return gizWifiDeviceListener;
} else {
return gizWifisubDeviceListener;
}
}
/**
*
*
* @param device
* @param netStatus
*/
protected void didUpdateNetStatus(GizWifiDevice device, GizWifiDeviceNetStatus netStatus) {
}
/**
*
*
* @param device
* @param result
* @param subDeviceList
*/
protected void didUpdateSubDevices(GizWifiCentralControlDevice device, GizWifiErrorCode result, List<GizWifiDevice> subDeviceList) {
}
/**
*
*
* @param result
* @param device
* @param isSubscribed
*/
protected void didSetSubscribe(GizWifiErrorCode result, GizWifiDevice device, boolean isSubscribed) {
}
@Override
public void onResume() {
super.onResume();
// 每次返回activity都要注册一次sdk监听器保证sdk状态能正确回调
GizWifiSDK.sharedInstance().setListener(gizWifiSDKListener);
Log.e("TAG", "GosDeviceModuleBaseFragment ----onResume: ---");
}
/**
* @param result
* @param cloudServiceInfo
*/
protected void didGetCurrentCloudService(GizWifiErrorCode result,
ConcurrentHashMap<String, String> cloudServiceInfo) {
}
}

@ -0,0 +1,403 @@
package com.gizwits.opensource.appkit.DeviceModule;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.CommonModule.NoScrollViewPager;
import com.gizwits.opensource.appkit.CommonModule.TipsDialog;
//config-all-start
// config_airlink-false-start
import com.gizwits.opensource.appkit.ConfigModule.GosAirlinkChooseDeviceWorkWiFiActivity;
// config_airlink-false-end
//config_softap-false-start
import com.gizwits.opensource.appkit.ConfigModule.GosChooseDeviceWorkWiFiActivity;
//config_softap-false-end
//config-all-end
//push-all-start
import com.gizwits.opensource.appkit.PushModule.GosPushManager;
//push-all-end
import com.gizwits.opensource.appkit.utils.ToolUtils;
import java.util.Timer;
import java.util.TimerTask;
import zxing.CaptureActivity;
public class GosMainActivity extends GosDeviceModuleBaseActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
Context context = null;
@SuppressWarnings("deprecation")
private int viewPagerSelected = 0;
private Intent intent;
public static Activity instance = null;
private BottomNavigationView navigation;
private NoScrollViewPager viewPager;
private static final int REQUEST_EXTERNAL_STORAGE = 22;
private static String[] PERMISSIONS_STORAGE = {"android.permission.CAMERA"};
@Override
public boolean onNavigationItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_device:
if (GosDeploy.appConfig_BindDevice_Qrcode()) {
int color = GosDeploy.appConfig_Contrast();
final Drawable upArrow = getResources().getDrawable(R.drawable.common_qrcode_button);
upArrow.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
mToolbar.setNavigationIcon(upArrow);
SpannableString ssTitle = new SpannableString(this.getString(R.string.devicelist_title));
ssTitle.setSpan(new ForegroundColorSpan(GosDeploy.appConfig_Contrast()), 0, ssTitle.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
tvTitle.setText(ssTitle);
} else {
mToolbar.setNavigationIcon(null);
SpannableString ssTitle = new SpannableString(this.getString(R.string.devicelist_title));
ssTitle.setSpan(new ForegroundColorSpan(GosDeploy.appConfig_Contrast()), 0, ssTitle.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
tvTitle.setText(ssTitle);
}
break;
case R.id.navigation_message:
mToolbar.setNavigationIcon(null);
SpannableString ssTitle1 = new SpannableString(this.getString(R.string.messagecenter));
ssTitle1.setSpan(new ForegroundColorSpan(GosDeploy.appConfig_Contrast()), 0, ssTitle1.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
tvTitle.setText(ssTitle1);
break;
case R.id.navigation_user:
mToolbar.setNavigationIcon(null);
SpannableString ssTitle2 = new SpannableString(this.getString(R.string.personal_center));
ssTitle2.setSpan(new ForegroundColorSpan(GosDeploy.appConfig_Contrast()), 0, ssTitle2.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
tvTitle.setText(ssTitle2);
break;
}
viewPager.setCurrentItem(TabFragment.form(item.getItemId()).ordinal());
return true;
}
private enum TabFragment {
device(R.id.navigation_device, GosDeviceListFragment.class),
message(R.id.navigation_message, MessageCenterFragment.class),
user(R.id.navigation_user, GosSettiingsFragment.class);
private int menuId;
private Class<? extends Fragment> mClass;
private Fragment fragment;
TabFragment(int menuId, Class<? extends Fragment> mClass) {
this.menuId = menuId;
this.mClass = mClass;
}
private Fragment fragment() {
if (fragment == null) {
try {
fragment = mClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
fragment = new Fragment();
}
}
return fragment;
}
public static TabFragment form(int menuId) {
for (TabFragment fragment : values()) {
if (fragment.menuId == menuId) {
return fragment;
}
}
return user;
}
public static void onDestroy() {
for (TabFragment fragment : values()) {
fragment.fragment = null;
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_main);
context = GosMainActivity.this;
if (GosDeploy.appConfig_BindDevice_Qrcode()) {
setToolBar(true, R.string.devicelist_title);
} else {
setToolBar(false, R.string.devicelist_title);
}
initView();
}
private void initView() {
navigation = (BottomNavigationView) findViewById(R.id.navigation);
setThemeColor(GosDeploy.appConfig_Background());
navigation.setOnNavigationItemSelectedListener(this);
viewPager = (NoScrollViewPager) findViewById(R.id.content);
viewPager.setNoScroll(true);
viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return TabFragment.values()[position].fragment();
}
@Override
public int getCount() {
return TabFragment.values().length;
}
});
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
viewPagerSelected = position;
supportInvalidateOptionsMenu();
navigation.setSelectedItemId(TabFragment.values()[position].menuId);
}
});
}
//config-all-start
@Override
public boolean onCreateOptionsMenu(Menu menu) {
switch (viewPagerSelected) {
case 0:
if (GosDeploy.appConfig_Config_Airlink()) {
if (GosDeploy.appConfig_Config_Softap()) {
getMenuInflater().inflate(R.menu.gosdeviceconfig, menu);
} else {
getMenuInflater().inflate(R.menu.gosnull, menu);
MenuItem menuItem = menu.findItem(R.id.add);
menuItem.setIcon(ToolUtils.editIcon(getResources(), R.drawable.deviceonboarding_add));
}
} else {
if (GosDeploy.appConfig_Config_Softap()) {
getMenuInflater().inflate(R.menu.gosnull, menu);
MenuItem menuItem = menu.findItem(R.id.add);
menuItem.setIcon(ToolUtils.editIcon(getResources(), R.drawable.deviceonboarding_add));
}
}
break;
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
//bindDevice_qrcode-false-start
case android.R.id.home:
if (GosDeploy.appConfig_BindDevice_Qrcode()) {
int permission = ActivityCompat.checkSelfPermission(GosMainActivity.this,
"android.permission.CAMERA");
if (permission != PackageManager.PERMISSION_GRANTED) {
try {
// 没有写的权限,去申请写的权限,会弹出对话框
ActivityCompat.requestPermissions(GosMainActivity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
} catch (Exception e) {
e.printStackTrace();
}
} else {
intent = new Intent(GosMainActivity.this, CaptureActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
}
}
break;
//bindDevice_qrcode-false-end
//config_airlink-false-start config_softap-false-start
case R.id.airlink_config:
if (!checkNetwork(GosMainActivity.this)) {
Toast.makeText(GosMainActivity.this, R.string.network_error, 2000).show();
} else {
intent = new Intent(GosMainActivity.this, GosAirlinkChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
}
break;
case R.id.softap_config:
if (!checkNetwork(GosMainActivity.this)) {
Toast.makeText(GosMainActivity.this, R.string.network_error, 2000).show();
} else {
intent = new Intent(GosMainActivity.this, GosChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
}
break;
//config_softap-false-end config_airlink-false-end
case R.id.add:
if (GosDeploy.appConfig_Config_Airlink()) {
if (!checkNetwork(GosMainActivity.this)) {
Toast.makeText(GosMainActivity.this, R.string.network_error, 2000).show();
} else {
intent = new Intent(GosMainActivity.this, GosAirlinkChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
}
}
if (GosDeploy.appConfig_Config_Softap()) {
if (!checkNetwork(GosMainActivity.this)) {
Toast.makeText(GosMainActivity.this, R.string.network_error, 2000).show();
} else {
intent = new Intent(GosMainActivity.this, GosChooseDeviceWorkWiFiActivity.class);
startActivity(intent);
}
}
break;
}
return super.onOptionsItemSelected(item);
}
//config-all-end
//bindDevice_qrcode-false-start
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (GosDeploy.appConfig_BindDevice_Qrcode()) {
if (requestCode == 22) {
intent = new Intent(GosMainActivity.this, CaptureActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
}
}
}
//bindDevice_qrcode-false-end
/**
*
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
exitBy2Click(); // 调用双击退出函数
}
return false;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 666) {
finish();
} else if (resultCode == 98765) {
TipsDialog dialog = new TipsDialog(GosMainActivity.this,
getResources().getString(R.string.devicedisconnected));
dialog.show();
}
}
public void exitBy2Click() {
Timer tExit = null;
if (isExit == false) {
isExit = true; // 准备退出;
String doubleClick;
if (!TextUtils.isEmpty(spf.getString("UserName", ""))
&& !TextUtils.isEmpty(spf.getString("PassWord", ""))) {
doubleClick = (String) getText(R.string.doubleclick_logout);
} else {
if (getIntent().getBooleanExtra("ThredLogin", false)) {
doubleClick = (String) getText(R.string.doubleclick_logout);
} else {
doubleClick = (String) getText(R.string.doubleclick_back);
}
}
Toast.makeText(this, doubleClick, 2000).show();
tExit = new Timer();
tExit.schedule(new TimerTask() {
@Override
public void run() {
isExit = false; // 取消退出
}
}, 2000); // 如果2秒钟内没有按下返回键则启动定时器取消掉刚才执行的任务
} else {
logoutToClean();
}
}
/**
*
*/
void logoutToClean() {
spf.edit().putString("UserName", "").commit();
spf.edit().putString("PassWord", "").commit();
spf.edit().putString("Uid", "").commit();
//push-all-start
GosPushManager.pushUnBindService(spf.getString("Token", ""));
//push-all-end
spf.edit().putString("Token", "").commit();
finish();
if (GosDeviceListFragment.loginStatus == 1) {
GosDeviceListFragment.loginStatus = 0;
} else {
GosDeviceListFragment.loginStatus = 4;
}
}
/**
* 退
*/
private static Boolean isExit = false;
/**
*
*
* @param colorPrimary
*/
private void setThemeColor(int colorPrimary) {
final Drawable add = getResources().getDrawable(R.drawable.deviceonboarding_add);
int color = GosDeploy.appConfig_Contrast();
add.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
mToolbar.setOverflowIcon(add);
// bindDevice_qrcode-false-start
if (GosDeploy.appConfig_BindDevice_Qrcode()) {
final Drawable upArrow = getResources().getDrawable(R.drawable.common_qrcode_button);
upArrow.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
mToolbar.setNavigationIcon(upArrow);
}
// bindDevice_qrcode-false-end
//动态设置底部导航栏的颜色
int[][] states = new int[][]{
new int[]{-android.R.attr.state_checked},
new int[]{android.R.attr.state_checked}
};
int[] colors = new int[]{ToolUtils.editTextAlpha(), color};
ColorStateList csl = new ColorStateList(states, colors);
// 背景颜色
navigation.setBackgroundColor(colorPrimary);
// 文字颜色
navigation.setItemIconTintList(csl);
// 图片颜色
navigation.setItemTextColor(csl);
}
}

@ -0,0 +1,108 @@
package com.gizwits.opensource.appkit.DeviceModule;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.widget.RemoteViews;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.utils.NetUtils;
import java.util.ArrayList;
import java.util.List;
public class GosMessageHandler {
NotificationManager nm;
protected static final int SHOWDIALOG = 999;
private Context mcContext;
private ArrayList<String> newDeviceList = new ArrayList<String>();
private Handler mainHandler;
// 做一个单例
private static GosMessageHandler mInstance = new GosMessageHandler();
public static GosMessageHandler getSingleInstance() {
return mInstance;
}
public void SetHandler(Handler handler) {
this.mainHandler = handler;
}
public void StartLooperWifi(Context context) {
this.mcContext = context;
HandlerThread looperwifi = new HandlerThread("looperwifi");
looperwifi.start();
looper = new MyLooperHandler(looperwifi.getLooper());
looper.post(mRunnable);
}
class MyLooperHandler extends Handler {
public MyLooperHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
}
}
/**
* 线
*/
private Runnable mRunnable = new Runnable() {
public void run() {
if (mcContext == null) {
return;
}
newDeviceList.clear();
List<ScanResult> currentWifiScanResult = NetUtils
.getCurrentWifiScanResult(mcContext);
GosConstant.ssidList = currentWifiScanResult;
int flog = 0;
if (currentWifiScanResult != null) {
for (ScanResult scanResult : currentWifiScanResult) {
String ssid = scanResult.SSID;
// 获取系统的NotificationManager服务
nm = (NotificationManager) mcContext
.getSystemService(Context.NOTIFICATION_SERVICE);
if (ssid.contains(GosBaseActivity.SoftAP_Start)
&& ssid.length() > GosBaseActivity.SoftAP_Start.length()
&& !newDeviceList.toString().contains(ssid)) {
newDeviceList.add(ssid);
flog++;
}
}
}
if (mainHandler != null && newDeviceList.size() > 0) {
mainHandler.sendEmptyMessage(SHOWDIALOG);
}
looper.postDelayed(mRunnable, 2000);
}
};
private MyLooperHandler looper;
public ArrayList<String> getNewDeviceList() {
return newDeviceList;
}
}

@ -0,0 +1,136 @@
package com.gizwits.opensource.appkit.DeviceModule;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.SettingsModule.GosAboutActivity;
import com.gizwits.opensource.appkit.UserModule.GosUserManager;
import com.gizwits.opensource.appkit.sharingdevice.SharedDeviceListAcitivity;
public class GosSettiingsFragment extends GosBaseFragment implements OnClickListener {
private static final int SETTINGS = 123;
/**
* The ll About
*/
private LinearLayout llAbout;
/**
* The Intent
*/
Intent intent;
private LinearLayout usermanager;
private RelativeLayout lllogin;
private LinearLayout llDeviceShared;
private TextView phoneusername;
private View allView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
allView = inflater.inflate(R.layout.activity_gos_settings, container, false);
initView();
initEvent();
return allView;
}
private void initView() {
llAbout = (LinearLayout) allView.findViewById(R.id.llAbout);
usermanager = (LinearLayout) allView.findViewById(R.id.usermanager);
lllogin = (RelativeLayout) allView.findViewById(R.id.lllogin);
phoneusername = (TextView) allView.findViewById(R.id.phoneusername);
llDeviceShared = (LinearLayout) allView.findViewById(R.id.deviceshared);
}
private void initEvent() {
llAbout.setOnClickListener(this);
usermanager.setOnClickListener(this);
lllogin.setOnClickListener(this);
llDeviceShared.setOnClickListener(this);
if (!TextUtils.isEmpty(spf.getString("UserName", "")) && !TextUtils.isEmpty(spf.getString("PassWord", ""))) {
usermanager.setVisibility(View.VISIBLE);
lllogin.setVisibility(View.GONE);
phoneusername.setText(spf.getString("UserName", ""));
} else if (TextUtils.isEmpty(spf.getString("UserName", "")) && TextUtils.isEmpty(spf.getString("PassWord", ""))
&& !TextUtils.isEmpty(spf.getString("thirdUid", ""))) {
usermanager.setVisibility(View.VISIBLE);
String uid = spf.getString("thirdUid", "");
lllogin.setVisibility(View.GONE);
String myuid = uid.substring(0, 2) + "***" + uid.substring(uid.length() - 4, uid.length());
phoneusername.setText(myuid);
} else {
usermanager.setVisibility(View.GONE);
lllogin.setVisibility(View.VISIBLE);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.llAbout:
intent = new Intent(getContext(), GosAboutActivity.class);
startActivity(intent);
llAbout.setEnabled(false);
llAbout.postDelayed(new Runnable() {
@Override
public void run() {
llAbout.setEnabled(true);
}
}, 1000);
break;
case R.id.usermanager:
intent = null;
if (intent == null) {
intent = new Intent(getContext(), GosUserManager.class);
}
startActivityForResult(intent, SETTINGS);
usermanager.setEnabled(false);
usermanager.postDelayed(new Runnable() {
@Override
public void run() {
usermanager.setEnabled(true);
}
}, 1000);
break;
case R.id.lllogin:
lllogin.setEnabled(false);
lllogin.postDelayed(new Runnable() {
@Override
public void run() {
lllogin.setEnabled(true);
}
}, 1000);
getActivity().finish();
break;
case R.id.deviceshared:
Intent deviceshared1 = new Intent(getContext(), SharedDeviceListAcitivity.class);
startActivity(deviceshared1);
llDeviceShared.setEnabled(false);
llDeviceShared.postDelayed(new Runnable() {
@Override
public void run() {
llDeviceShared.setEnabled(true);
}
}, 1000);
break;
default:
break;
}
}
}

@ -0,0 +1,136 @@
package com.gizwits.opensource.appkit.DeviceModule;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.api.GizMessage;
import com.gizwits.gizwifisdk.enumration.GizMessageStatus;
import com.gizwits.gizwifisdk.enumration.GizMessageType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.sharingdevice.MsgNoticeActivity;
import com.gizwits.opensource.appkit.sharingdevice.deviceSharedMessageActivity;
import java.util.List;
//personalCenter_deviceSharing-false-start
//personalCenter_deviceSharing-false-end
public class MessageCenterFragment extends GosBaseFragment {
private LinearLayout llGizwitsmes;
//personalCenter_deviceSharing-false-start
private View redpoint;
private LinearLayout llDevicesShared;
//personalCenter_deviceSharing-false-end
private View allView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
allView = inflater.inflate(R.layout.activity_gos_message, container, false);
initView();
initEvent();
return allView;
}
//界面可见时再加载数据
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
//请求网络数据
//personalCenter_deviceSharing-false-start
String token = spf.getString("Token", "");
GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSharing);
//GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSystem);
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
@Override
public void didQueryMessageList(GizWifiErrorCode result, List<GizMessage> messageList) {
super.didQueryMessageList(result, messageList);
if (messageList.size() > 0) {
isShowRedPoint(messageList);
} else {
redpoint.setVisibility(View.GONE);
}
if (result.ordinal() != 0) {
Toast.makeText(getContext(), toastError(result), 2).show();
}
}
});
//personalCenter_deviceSharing-false-end
}
}
//personalCenter_deviceSharing-false-start
private void isShowRedPoint(List<GizMessage> messageList) {
boolean isshow = false;
redpoint.setVisibility(View.GONE);
for (int i = 0; i < messageList.size(); i++) {
GizMessage gizMessage = messageList.get(i);
GizMessageStatus status = gizMessage.getStatus();
if (status.ordinal() == 0) {
isshow = true;
redpoint.setVisibility(View.VISIBLE);
}
}
}
//personalCenter_deviceSharing-false-end
private void initView() {
llGizwitsmes = (LinearLayout) allView.findViewById(R.id.gizwitsmes);
//personalCenter_deviceSharing-false-start
// 判断当前的view 是否需要显示这个红点
redpoint = allView.findViewById(R.id.redpoint);
llDevicesShared = (LinearLayout) allView.findViewById(R.id.deviceshared);
//personalCenter_deviceSharing-false-end
}
private void initEvent() {
llGizwitsmes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 跳转到机智云公告页面
Intent intent = new Intent(getContext(), MsgNoticeActivity.class);
startActivity(intent);
llGizwitsmes.setEnabled(false);
llGizwitsmes.postDelayed(new Runnable() {
@Override
public void run() {
llGizwitsmes.setEnabled(true);
}
}, 1000);
}
});
//personalCenter_deviceSharing-false-start
llDevicesShared.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent tent = new Intent(getContext(), deviceSharedMessageActivity.class);
startActivity(tent);
llDevicesShared.setEnabled(false);
llDevicesShared.postDelayed(new Runnable() {
@Override
public void run() {
llDevicesShared.setEnabled(true);
}
}, 1000);
}
});
//personalCenter_deviceSharing-false-end
}
}

@ -0,0 +1,13 @@
package com.gizwits.opensource.appkit;
import android.app.Application;
public class GosApplication extends Application {
public static int flag = 0;
public void onCreate() {
super.onCreate();
}
}

@ -0,0 +1,112 @@
package com.gizwits.opensource.appkit;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.widget.Toast;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizLogPrintLevel;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
public class MessageCenter {
private static MessageCenter mCenter;
int flag = 0;
GosDeploy gosDeploy;
private int SETCLOUD = 1111;
private MessageCenter(Context c) {
if (mCenter == null) {
init(c);
}
}
private void init(Context c) {
gosDeploy = new GosDeploy(c);
//config-all-start
if (GosDeploy.appConfig_UseOnboardingDeploy()) {
if (GosDeploy.appConfig_OnboardingBind()) {
GosConstant.mNew = 3;
} else {
GosConstant.mNew = 2;
}
} else {
if (GosDeploy.appConfig_OnboardingBind()) {
GosConstant.mNew = 1;
} else {
GosConstant.mNew = 0;
}
}
//config-all-end
String AppID = GosDeploy.appConfig_GizwitsInfoAppID();
String AppSecret = GosDeploy.appConfig_GizwitsInfoAppSecret();
List<ConcurrentHashMap<String, String>> productInfoList = GosDeploy.appConfig_ProductInfoList();
if (productInfoList.size() == 0) {
productInfoList = null;
}
if (AppID == null || AppSecret == null || TextUtils.isEmpty(AppID) || AppID.contains("BeJson")
|| TextUtils.isEmpty(AppSecret) || AppSecret.contains("BeJson")
|| AppID.length() != 32 || AppSecret.length() != 32) {
String AppID_Toast = c.getString(R.string.AppID_Toast);
if (flag == 0) {
Toast.makeText(c, AppID_Toast, Toast.LENGTH_LONG).show();
}
flag++;
} else {
// 启动SDK
ConcurrentHashMap<String, String> serverMap = new ConcurrentHashMap<String, String>();
ConcurrentHashMap<String, String> appInfo = new ConcurrentHashMap<String, String>();
appInfo.put("appId", AppID);
appInfo.put("appSecret", AppSecret);
String api = GosDeploy.appConfig_CloudServiceApi();
String site = GosDeploy.appConfig_CloudServiceSite();
String push = GosDeploy.appConfig_CloudServicePush();
Pattern pattern = Pattern.compile("(^[a-zA-Z0-9\\-]{1,}\\.[a-zA-Z0-9]{1,}\\.[a-zA-Z0-9]{1,}\\:(\\d){1,}\\&(\\d){1,}$)|(^[a-zA-Z0-9\\-]{1,}\\.[a-zA-Z0-9]{1,}\\.[a-zA-Z0-9]{1,}$)");
Pattern pattern1 = Pattern.compile("(^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}\\:(\\d){1,}\\&(\\d){1,}$)|(^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$)");
if (api != null) {
if (pattern.matcher(api).matches() || pattern1.matcher(api).matches()) {
serverMap.put("openAPIInfo", api);
if (site != null) {
serverMap.put("siteInfo", site);
}
if (push != null && !push.isEmpty()) {
serverMap.put("pushInfo", GosDeploy.appConfig_CloudServicePush());
}
GizWifiSDK.sharedInstance().startWithAppInfo(c, appInfo, productInfoList, serverMap, false);
} else {
GizWifiSDK.sharedInstance().startWithAppInfo(c, appInfo,
productInfoList, null, false);
}
} else {
GizWifiSDK.sharedInstance().startWithAppInfo(c, appInfo,
productInfoList, null, false);
}
}
hand.sendEmptyMessageDelayed(SETCLOUD, 3000);
}
public static MessageCenter getInstance(Context c) {
if (mCenter == null) {
mCenter = new MessageCenter(c);
}
return mCenter;
}
Handler hand = new Handler() {
public void handleMessage(android.os.Message msg) {
GizWifiSDK.sharedInstance().setLogLevel(
GizLogPrintLevel.GizLogPrintAll);
}
};
}

@ -0,0 +1,67 @@
package com.gizwits.opensource.appkit.PushModule;
import android.content.Context;
import android.util.Log;
import com.baidu.android.pushservice.PushMessageReceiver;
import java.util.List;
public class BaiDuPushReceiver extends PushMessageReceiver {
// BaiDuPush_Channel_ID(此处需要在百度推送的Receiver里赋值)
public static String BaiDuPush_Channel_ID;
@Override
public void onBind(Context arg0, int arg1, String arg2, String arg3, String arg4, String arg5) {
// TODO Auto-generated method stub
BaiDuPush_Channel_ID = arg4;
Log.i("Apptest", BaiDuPush_Channel_ID + "---");
}
@Override
public void onDelTags(Context arg0, int arg1, List<String> arg2, List<String> arg3, String arg4) {
// TODO Auto-generated method stub
}
@Override
public void onListTags(Context arg0, int arg1, List<String> arg2, String arg3) {
// TODO Auto-generated method stub
}
@Override
public void onMessage(Context arg0, String arg1, String arg2) {
// TODO Auto-generated method stub
}
@Override
public void onNotificationArrived(Context arg0, String arg1, String arg2, String arg3) {
// TODO Auto-generated method stub
String notifyString = "通知到达 onNotificationArrived title=\"" + arg1
+ "\" description=\"" + arg2 + "\" customContent="
+ arg3;
Log.i(TAG, notifyString);
}
@Override
public void onNotificationClicked(Context arg0, String arg1, String arg2, String arg3) {
// TODO Auto-generated method stub
}
@Override
public void onSetTags(Context arg0, int arg1, List<String> arg2, List<String> arg3, String arg4) {
// TODO Auto-generated method stub
}
@Override
public void onUnbind(Context arg0, int arg1, String arg2) {
// TODO Auto-generated method stub
}
}

@ -0,0 +1,136 @@
package com.gizwits.opensource.appkit.PushModule;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
//push_baidu-false-start
import com.baidu.android.pushservice.PushConstants;
import com.baidu.android.pushservice.PushManager;
import com.baidu.android.pushservice.PushSettings;
//push_baidu-false-end
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizPushType;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import java.util.Set;
//push_jiguang-false-start
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;
//push_jiguang-false-end
public class GosPushManager {
static GizPushType gizPushType;
static Context context;
public GosPushManager(int PushType, Context context) {
super();
GosPushManager.context = context;
//push_jiguang-false-start
if (PushType == 1) {
GosPushManager.gizPushType = GizPushType.GizPushJiGuang;
jPush();
}
//push_jiguang-false-end
//push_baidu-false-start
if (PushType == 2) {
GosPushManager.gizPushType = GizPushType.GizPushBaiDu;
bDPush();
}
//push_baidu-false-end
}
/**
* Channel_ID
*/
public static String Channel_ID;
//push_jiguang-false-start
/**
* JPush SDK MainActivityonResumeonPause
* JPushInterface.onResume(context); JPushInterface.onPause(context);
*/
public void jPush() {
// 设置JPush调试模式
JPushInterface.setDebugMode(true);
// 初始化JPushSDK
JPushInterface.init(context);
}
//push_jiguang-false-end
//push_baidu-false-start
public void bDPush() {
final String BDPushAppKey = GosDeploy.appConfig_BpushAppKey();
if (BDPushAppKey != null) {
if (TextUtils.isEmpty(BDPushAppKey) || BDPushAppKey.contains("your_bpush_api_key")) {
GosBaseActivity.noIDAlert(context, R.string.BDPushAppID_Toast);
} else {
PushManager.startWork(context, PushConstants.LOGIN_TYPE_API_KEY, BDPushAppKey);
PushSettings.enableDebugMode(context, true);
}
}
}
//push_baidu-false-end
/**
*
*
* @param userId
* @param token
*/
public static void pushBindService(String userId, String token) {
//push_jiguang-false-start
if (GizPushType.GizPushJiGuang == gizPushType) {
// 获取JPush的RegistrationID,即Channel_ID
Channel_ID = JPushInterface.getRegistrationID(context);
// 设定JPush类型
JPushInterface.setAlias(context, Channel_ID, new TagAliasCallback() {
@Override
public void gotResult(int arg0, String arg1, Set<String> arg2) {
if (arg0 == 0) {
Log.i("Apptest", "Alias: " + arg1);
} else {
Log.i("Apptest", "Result: " + arg0);
}
}
});
}
//push_jiguang-false-end
//push_baidu-false-start
if (GizPushType.GizPushBaiDu == gizPushType) {
// 获取BDPush的Channel_ID
Channel_ID = BaiDuPushReceiver.BaiDuPush_Channel_ID;
Log.e("Manager", "pushBindService----: " + Channel_ID);
}
//push_baidu-false-end
// TODO 绑定推送
GizWifiSDK.sharedInstance().channelIDBind(token, Channel_ID, userId, gizPushType);
}
public static void pushUnBindService(String token) {
if (token.isEmpty()) {
return;
}
//push_jiguang-false-start
if (GizPushType.GizPushJiGuang == gizPushType) {
// 获取JPush的RegistrationID,即Channel_ID
Channel_ID = JPushInterface.getRegistrationID(context);
}
//push_jiguang-false-end
//push_baidu-false-start
if (GizPushType.GizPushBaiDu == gizPushType) {
// 获取BDPush的Channel_ID
Channel_ID = BaiDuPushReceiver.BaiDuPush_Channel_ID;
}
//push_baidu-false-end
// TODO 绑定推送
//Log.i("Apptest", Channel_ID + "\n" + gizPushType.toString() + "\n" + token);
GizWifiSDK.sharedInstance().channelIDUnBind(token, Channel_ID);
}
}

@ -0,0 +1,125 @@
package com.gizwits.opensource.appkit.PushModule;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Iterator;
import cn.jpush.android.api.JPushInterface;
public class JPushReceiver extends BroadcastReceiver {
private static final String TAG = "JPushReceiver";
@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle bundle = intent.getExtras();
Log.i(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
Log.i(TAG, "[MyReceiver] 接收Registration Id : " + regId);
//send the Registration Id to your server...
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
Log.i(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
//processCustomMessage(context, bundle);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Log.i(TAG, "[MyReceiver] 接收到推送下来的通知");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Log.i(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
String title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
String content = bundle.getString(JPushInterface.EXTRA_ALERT);
Log.i(TAG, "Title 标题:: " + title + " " + "Content : 内容:" + content);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
// Log.d(TAG, "[MyReceiver] 用户点击打开了通知");
//
// //打开自定义的Activity
// Intent i = new Intent(context, TestActivity.class);
// i.putExtras(bundle);
// //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
// context.startActivity(i);
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
Log.i(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码比如打开新的Activity 打开一个网页等..
} else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
Log.i(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
} else {
Log.i(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
}
} catch (Exception e) {
}
}
// 打印所有的 intent extra 数据
private static String printBundle(Bundle bundle) {
StringBuilder sb = new StringBuilder();
for (String key : bundle.keySet()) {
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));
} else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) {
sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));
} else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
Log.i(TAG, "This message has no Extra data");
continue;
}
try {
JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
Iterator<String> it = json.keys();
while (it.hasNext()) {
String myKey = it.next();
sb.append("\nkey:" + key + ", value: [" +
myKey + " - " + json.optString(myKey) + "]");
}
} catch (JSONException e) {
Log.i(TAG, "Get message extra JSON error!");
}
} else {
sb.append("\nkey:" + key + ", value:" + bundle.getString(key));
}
}
return sb.toString();
}
//send msg to MainActivity
// private void processCustomMessage(Context context, Bundle bundle) {
// if (MainActivity.isForeground) {
// String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
// String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
// Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
// msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
// if (!ExampleUtil.isEmpty(extras)) {
// try {
// JSONObject extraJson = new JSONObject(extras);
// if (extraJson.length() > 0) {
// msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
// }
// } catch (JSONException e) {
//
// }
//
// }
// LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
// }
// }
}

@ -0,0 +1,135 @@
package com.gizwits.opensource.appkit.SettingsModule;
import android.app.ActionBar;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.utils.AssetsUtils;
public class GosAboutActivity extends GosBaseActivity {
/**
* The tv SDKVersion.
*/
TextView tv_SDKVersion;
/**
* the tv appCode
*/
TextView tv_AppVersion;
/**
* The ActionBar
*/
ActionBar actionBar;
private LinearLayout llApp;
private LinearLayout llSDK;
private LinearLayout llAbout;
private TextView tvAbout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_about);
// 设置ActionBar
setToolBar(true, R.string.about);
initView();
initEvent();
}
private void initEvent() {
if (!GosDeploy.appConfig_ShowAPPVersion() && !GosDeploy.appConfig_ShowSDKVersion()) {
llApp.setVisibility(View.VISIBLE);
llSDK.setVisibility(View.VISIBLE);
llAbout.setVisibility(View.VISIBLE);
} else {
if (!GosDeploy.appConfig_ShowAPPVersion()) {
llApp.setVisibility(View.GONE);
}
if (!GosDeploy.appConfig_ShowSDKVersion()) {
llSDK.setVisibility(View.GONE);
}
if (GosDeploy.appConfig_AboutInfoCH() != null) {
if (GosDeploy.appConfig_AboutInfoEN() != null) {
if (AssetsUtils.isZh(this)) {
tvAbout.setText(GosDeploy.appConfig_AboutInfoCH());
} else {
tvAbout.setText(GosDeploy.appConfig_AboutInfoEN());
}
} else {
tvAbout.setText(GosDeploy.appConfig_AboutInfoCH());
}
llAbout.setVisibility(View.VISIBLE);
} else {
if (GosDeploy.appConfig_AboutInfoEN() != null) {
tvAbout.setText(GosDeploy.appConfig_AboutInfoEN());
llAbout.setVisibility(View.VISIBLE);
} else {
llAbout.setVisibility(View.GONE);
}
}
}
}
/**
* Inits the view.
*/
private void initView() {
llApp = (LinearLayout) findViewById(R.id.llAPP);
llSDK = (LinearLayout) findViewById(R.id.llSDK);
llAbout = (LinearLayout) findViewById(R.id.llAbout);
tvAbout = (TextView) findViewById(R.id.tvAbout);
tv_SDKVersion = (TextView) findViewById(R.id.versionCode);
tv_AppVersion = (TextView) findViewById(R.id.appCode);
}
@Override
public void onResume() {
super.onResume();
tv_SDKVersion.setText(GizWifiSDK.sharedInstance().getVersion().toString());
tv_AppVersion.setText(getAppVersionName(this));
}
/**
*
*/
public static String getAppVersionName(Context context) {
String versionName = "";
try {
// ---get the package info---
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
versionName = pi.versionName;
if (versionName == null || versionName.length() <= 0) {
return "";
}
} catch(Exception e) {
Log.i("Apptest", "Exception", e);
}
return versionName;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
break;
}
return super.onOptionsItemSelected(item);
}
}

@ -0,0 +1,28 @@
package com.gizwits.opensource.appkit.ThirdAccountModule;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.UiError;
import org.json.JSONObject;
public class BaseUiListener implements IUiListener {
@Override
public void onCancel() {
// TODO Auto-generated method stub
}
@Override
public void onComplete(Object arg0) {
doComplete((JSONObject)arg0);
}
protected void doComplete(JSONObject values) {
}
@Override
public void onError(UiError arg0) {
// TODO Auto-generated method stu
}
}

@ -0,0 +1,226 @@
package com.gizwits.opensource.appkit.UserModule;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.listener.GizWifiSDKListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
public class GosChangeUserPasswordActivity extends GosBaseActivity {
private EditText oldpass;
private EditText newpass;
private EditText confrimpass;
private Button btnConfirm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_change_password);
setToolBar(true, R.string.edit_password);
initView();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
GizWifiSDK.sharedInstance().setListener(listener);
}
GizWifiSDKListener listener = new GizWifiSDKListener() {
public void didChangeUserPassword(
com.gizwits.gizwifisdk.enumration.GizWifiErrorCode result) {
if (result.getResult() == 0) {
Toast.makeText(GosChangeUserPasswordActivity.this,
getResources().getString(R.string.passsuccess), 2000)
.show();
finish();
spf.edit().putString("PassWord", newpass.getText().toString())
.commit();
} else {
if (result.getResult() == 9020) {
Toast.makeText(GosChangeUserPasswordActivity.this,
getResources().getString(R.string.oldpasserror),
2000).show();
} else {
Toast.makeText(GosChangeUserPasswordActivity.this,
getResources().getString(R.string.passerror), 2000)
.show();
}
}
}
;
};
private CheckBox oldcheck;
private CheckBox newcheck;
private CheckBox concheck;
private void initView() {
btnConfirm = (Button) findViewById(R.id.btnLogin);
oldpass = (EditText) findViewById(R.id.oldpass);
newpass = (EditText) findViewById(R.id.newpass);
confrimpass = (EditText) findViewById(R.id.confrimpass);
confrimpass.setTransformationMethod(PasswordTransformationMethod
.getInstance());
oldpass.setTransformationMethod(PasswordTransformationMethod
.getInstance());
newpass.setTransformationMethod(PasswordTransformationMethod
.getInstance());
oldcheck = (CheckBox) findViewById(R.id.oldcheck);
newcheck = (CheckBox) findViewById(R.id.newcheck);
concheck = (CheckBox) findViewById(R.id.concheck);
// 配置文件部署
oldcheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
String psw = oldpass.getText().toString();
if (isChecked) {
// oldpass.setInputType(0x90);
oldpass.setTransformationMethod(HideReturnsTransformationMethod
.getInstance());
} else {
// oldpass.setInputType(0x81);
oldpass.setTransformationMethod(PasswordTransformationMethod
.getInstance());
}
oldpass.setSelection(psw.length());
}
});
newcheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
String psw = newpass.getText().toString();
if (isChecked) {
// newpass.setInputType(0x90);
newpass.setTransformationMethod(HideReturnsTransformationMethod
.getInstance());
} else {
// newpass.setInputType(0x81);
newpass.setTransformationMethod(PasswordTransformationMethod
.getInstance());
}
newpass.setSelection(psw.length());
}
});
concheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
String psw = confrimpass.getText().toString();
if (isChecked) {
// confrimpass.setInputType(0x90);
confrimpass
.setTransformationMethod(HideReturnsTransformationMethod
.getInstance());
} else {
// confrimpass.setInputType(0x81);
confrimpass
.setTransformationMethod(PasswordTransformationMethod
.getInstance());
}
confrimpass.setSelection(psw.length());
}
});
}
public void confirm(View v) {
if (TextUtils.isEmpty(oldpass.getText().toString())
|| TextUtils.isEmpty(newpass.getText().toString())
|| TextUtils.isEmpty(confrimpass.getText().toString())) {
if (TextUtils.isEmpty(oldpass.getText().toString())) {
Toast.makeText(
this,
getResources().getString(
R.string.enter_current_password), 2000).show();
return;
}
if (TextUtils.isEmpty(newpass.getText().toString())) {
Toast.makeText(this,
getResources().getString(R.string.enter_new_password),
2000).show();
return;
}
if (TextUtils.isEmpty(confrimpass.getText().toString())) {
Toast.makeText(
this,
getResources()
.getString(R.string.re_enter_new_password),
2000).show();
return;
}
} else {
//oldpass.getText().length() < 6 ||
if (newpass.getText().length() < 6 || confrimpass.getText().length() < 6) {
Toast.makeText(this,
getResources().getString(R.string.toast_psw_short),
2000).show();
}
String npass = newpass.getText().toString();
String cpass = confrimpass.getText().toString();
if (npass.equals(cpass)) {
GizWifiSDK.sharedInstance().changeUserPassword(
spf.getString("Token", ""),
oldpass.getText().toString(), npass);
} else {
Toast.makeText(this,
getResources().getString(R.string.nosamepass), 2000)
.show();
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return true;
}
}

@ -0,0 +1,385 @@
package com.gizwits.opensource.appkit.UserModule;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizUserAccountType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@SuppressLint("HandlerLeak")
public class GosForgetPasswordActivity extends GosUserModuleBaseActivity implements
OnClickListener {
/**
* The et Name
*/
private EditText etName;
/**
* The ll phone
*/
private LinearLayout llPhone;
/**
* The btn GetCode
*/
private TextView tvGetCode;
/**
* The et Code
*/
private EditText etCode;
/**
* The et Psw
*/
private EditText etPsw;
/**
* The et ConfirmPsw
*/
private EditText etConfirmPsw;
/**
*
*/
int secondleft = 60;
/**
* The timer.
*/
Timer timer;
//resetPassword_phoneUser-false-end
/**
* The btn Register
*/
private Button btnReset;
/**
*
*/
String name, code, psw, confirmpsw;
private enum handler_key {
//resetPassword_phoneUser-false-start
/**
* .
*/
GETCODE,
/**
* .
*/
SENDSUCCESSFUL,
/**
*
*/
TICK_TIME,
//resetPassword_phoneUser-false-end
/**
*
*/
TOAST,
/**
*
*/
RESET,
}
Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
handler_key key = handler_key.values()[msg.what];
switch (key) {
//resetPassword_phoneUser-false-start
case GETCODE:
progressDialog.show();
String AppSecret = GosDeploy.appConfig_GizwitsInfoAppSecret();
GizWifiSDK.sharedInstance().requestSendPhoneSMSCode(AppSecret,
msg.obj.toString());
break;
case SENDSUCCESSFUL:
etName.setEnabled(false);
etName.setTextColor(getResources().getColor(
R.color.text_gray_light));
isStartTimer();
break;
case TICK_TIME:
String getCodeAgain = getString(R.string.getcode_again);
String timerMessage = getString(R.string.timer_message);
secondleft--;
if (secondleft <= 0) {
timer.cancel();
tvGetCode.setTextColor(getResources().getColor(R.color.tomato));
tvGetCode.setEnabled(true);
tvGetCode.setText(getCodeAgain);
} else {
tvGetCode.setText(secondleft + timerMessage);
}
break;
//resetPassword_phoneUser-false-end
case TOAST:
String successfulText = (String) getText(R.string.reset_successful);
Toast.makeText(GosForgetPasswordActivity.this, msg.obj + "",
toastTime).show();
if (msg.obj.toString().equals(successfulText)) {
// spf.edit().putString("UserName", name).commit();
// spf.edit().putString("PassWord", psw).commit();
isclean = true;
//resetPassword_phoneUser-false-start
if (llPhone.getVisibility() == View.GONE) {
//resetPassword_phoneUser-false-end
Intent intent = new Intent(GosForgetPasswordActivity.this, GosSendEmailPasswordActivity.class);
startActivity(intent);
spf.edit().putString("Email", name).commit();
//resetPassword_phoneUser-false-start
} else {
finish();
}
//resetPassword_phoneUser-false-end
}
break;
case RESET:
progressDialog.show();
GizWifiSDK.sharedInstance().resetPassword(name, code, psw,
GizUserAccountType.GizUserPhone);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_forget_password);
// 设置ActionBar
setToolBar(true, R.string.forget_pass);
initView();
initEvent();
}
private void initView() {
etName = (EditText) findViewById(R.id.etName);
//resetPassword_phoneUser-false-start
llPhone = (LinearLayout) findViewById(R.id.llPhone);
tvGetCode = (TextView) findViewById(R.id.tvGetCode);
etCode = (EditText) findViewById(R.id.etCode);
etPsw = (EditText) findViewById(R.id.etPsw);
etConfirmPsw = (EditText) findViewById(R.id.etConfirmPsw);
//resetPassword_phoneUser-false-end
btnReset = (Button) findViewById(R.id.btnReset);
setPhoneOrEmailIsVisable();
}
private void setPhoneOrEmailIsVisable() {
//resetPassword_phoneUser-true-start resetPassword_phoneUser-false-start
if (GosDeploy.appConfig_ResetPassword_PhoneUser()) {
//resetPassword_phoneUser-true-end
etName.setHint(getResources().getString(R.string.name_phone));
llPhone.setVisibility(View.VISIBLE);
etName.setInputType(InputType.TYPE_CLASS_PHONE);
btnReset.setText(getResources().getString(R.string.reset));
//resetPassword_phoneUser-true-start
} else {
//resetPassword_phoneUser-false-end
//resetPassword_phoneUser-false-start
}
//resetPassword_phoneUser-true-end resetPassword_phoneUser-false-end
}
private void initEvent() {
final Timer etTimer = new Timer();
etTimer.schedule(new TimerTask() {
@Override
public void run() {
etName.requestFocus();
InputMethodManager imm = (InputMethodManager) etName
.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
etTimer.cancel();
}
}, 500);
//resetPassword_phoneUser-false-start
tvGetCode.setOnClickListener(this);
//resetPassword_phoneUser-false-end
btnReset.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
//resetPassword_phoneUser-false-start
case R.id.tvGetCode:
name = etName.getText().toString();
if (TextUtils.isEmpty(name)) {
Toast.makeText(GosForgetPasswordActivity.this,
R.string.toast_name_wrong, toastTime).show();
return;
}
Message msg = new Message();
msg.obj = name;
msg.what = handler_key.GETCODE.ordinal();
handler.sendMessage(msg);
break;
//resetPassword_phoneUser-false-end
case R.id.btnReset:
name = etName.getText().toString();
//resetPassword_phoneUser-false-start
code = etCode.getText().toString();
psw = etPsw.getText().toString();
confirmpsw = etConfirmPsw.getText().toString();
if (TextUtils.isEmpty(name)) {
Toast.makeText(GosForgetPasswordActivity.this,
R.string.toast_name_wrong, toastTime).show();
return;
}
if (llPhone.getVisibility() == View.VISIBLE) {
if (code.length() != 6) {
Toast.makeText(GosForgetPasswordActivity.this, R.string.no_getcode, toastTime).show();
return;
}
if (TextUtils.isEmpty(psw)) {
Toast.makeText(GosForgetPasswordActivity.this,
R.string.toast_psw_wrong, toastTime).show();
return;
}
if (psw.length() < 6) {
Toast.makeText(GosForgetPasswordActivity.this,
R.string.toast_psw_short, toastTime).show();
return;
}
if (!psw.equals(confirmpsw)) {
Toast.makeText(GosForgetPasswordActivity.this, R.string.toast_psw_confirm_failed, toastTime).show();
return;
}
} else {
//resetPassword_phoneUser-false-end
if (!name.contains("@")) {
Toast.makeText(GosForgetPasswordActivity.this, R.string.toase_name_email_fault, toastTime).show();
return;
}
//resetPassword_phoneUser-false-start
}
//resetPassword_phoneUser-false-end
/*
* if (psw.length() < 6) {
* Toast.makeText(GosForgetPasswordActivity.this,
* R.string.toast_psw_short, toastTime).show(); return; }
*/
handler.sendEmptyMessage(handler_key.RESET.ordinal());
break;
}
}
/**
*
*/
public void isStartTimer() {
tvGetCode.setEnabled(false);
tvGetCode.setTextColor(getResources().getColor(R.color.hint_color));
secondleft = 60;
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(handler_key.TICK_TIME.ordinal());
}
}, 1000, 1000);
}
/**
*
*/
@Override
protected void didRequestSendPhoneSMSCode(GizWifiErrorCode result,
String token) {
if (progressDialog != null) {
progressDialog.cancel();
}
Message msg = new Message();
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
// String sendFailed = (String) getText(R.string.send_failed);
msg.what = handler_key.TOAST.ordinal();
msg.obj = toastError(result);// sendFailed + "\n" +
// errorMessage;toastError(errorCode)
handler.sendMessage(msg);
} else {
handler.sendEmptyMessage(handler_key.SENDSUCCESSFUL.ordinal());
msg.what = handler_key.TOAST.ordinal();
String sendSuccessful = (String) getText(R.string.send_successful);
msg.obj = sendSuccessful;
handler.sendMessage(msg);
}
}
//resetPassword_phoneUser-false-end
/**
*
*/
@Override
public void didChangeUserPassword(GizWifiErrorCode result) {
if (progressDialog != null) {
progressDialog.cancel();
}
Message msg = new Message();
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
// String resetFailed = (String) getText(R.string.reset_failed);
msg.what = handler_key.TOAST.ordinal();
msg.obj = toastError(result);// resetFailed + "\n" + errorMessage;
handler.sendMessage(msg);
} else {
msg.what = handler_key.TOAST.ordinal();
String resetSuccessful = (String) getText(R.string.reset_successful);
msg.obj = resetSuccessful;
handler.sendMessage(msg);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
progressDialog = null;
}
}

@ -0,0 +1,359 @@
package com.gizwits.opensource.appkit.UserModule;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizUserAccountType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@SuppressLint("HandlerLeak")
public class GosRegisterUserActivity extends GosUserModuleBaseActivity implements OnClickListener, AdapterView.OnItemSelectedListener {
/**
* The et Name
*/
private EditText etName;
//register_phoneUser-false-start
/**
* The ll code
*/
private LinearLayout llCode;
/**
* The btn GetCode
*/
private TextView tvGetCode;
/**
* The et Code
*/
private EditText etCode;
/**
*
*/
int secondleft = 60;
/**
* The timer.
*/
Timer timer;
//register_phoneUser-false-end
/**
* The et Psw
*/
private EditText etPsw;
/**
* The et ConfirmPsw
*/
private EditText etConfirmPsw;
/**
* The btn Rrgister
*/
private Button btnRrgister;
/**
*
*/
String name, code, psw, confirmpsw;
private int usertype = 0;
private enum handler_key {
//register_phoneUser-false-start
/**
* .
*/
GETCODE,
/**
* .
*/
SENDSUCCESSFUL,
//register_phoneUser-false-end
/**
*
*/
TOAST,
/**
*
*/
TICK_TIME,
/**
*
*/
REGISTER,
}
Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
handler_key key = handler_key.values()[msg.what];
switch (key) {
//register_phoneUser-false-start
case GETCODE:
progressDialog.show();
String AppSecret = GosDeploy.appConfig_GizwitsInfoAppSecret();
GizWifiSDK.sharedInstance().requestSendPhoneSMSCode(AppSecret, msg.obj.toString());
break;
case SENDSUCCESSFUL:
etName.setEnabled(false);
etName.setTextColor(getResources().getColor(R.color.text_gray_light));
isStartTimer();
break;
case TICK_TIME:
String getCodeAgain = getString(R.string.getcode_again);
String timerMessage = getString(R.string.timer_message);
secondleft--;
if (secondleft <= 0) {
timer.cancel();
tvGetCode.setTextColor(getResources().getColor(R.color.tomato));
tvGetCode.setEnabled(true);
tvGetCode.setText(getCodeAgain);
} else {
tvGetCode.setText(secondleft + timerMessage);
}
break;
//register_phoneUser-false-end
case TOAST:
Toast.makeText(GosRegisterUserActivity.this, msg.obj.toString(), toastTime).show();
String successfulText = (String) getText(R.string.register_successful);
if (msg.obj.toString().equals(successfulText)) {
spf.edit().putString("UserName", name).commit();
spf.edit().putString("PassWord", psw).commit();
isclean = true;
finish();
}
break;
case REGISTER:
progressDialog.show();
GizWifiSDK.sharedInstance().registerUser(name, psw, code, GizUserAccountType.GizUserPhone);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_register_user);
// 设置ActionBar
setToolBar(true, R.string.register);
initView();
initEvent();
}
private void initView() {
etName = (EditText) findViewById(R.id.etName);
//register_phoneUser-false-start
tvGetCode = (TextView) findViewById(R.id.tvGetCode);
etCode = (EditText) findViewById(R.id.etCode);
llCode = (LinearLayout) findViewById(R.id.llCode);
//register_phoneUser-false-end
etPsw = (EditText) findViewById(R.id.etPsw);
etConfirmPsw = (EditText) findViewById(R.id.etConfirmPsw);
btnRrgister = (Button) findViewById(R.id.btnRrgister);
setPhoneOrEmailOrNormalIsVisable();
}
private void setPhoneOrEmailOrNormalIsVisable() {
etName.setHint(getResources().getString(R.string.name_phone));
usertype = 0;
}
private void initEvent() {
final Timer etTimer = new Timer();
etTimer.schedule(new TimerTask() {
@Override
public void run() {
etName.requestFocus();
InputMethodManager imm = (InputMethodManager) etName.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
etTimer.cancel();
}
}, 500);
//register_phoneUser-false-start
tvGetCode.setOnClickListener(this);
//register_phoneUser-false-end
btnRrgister.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
//register_phoneUser-false-start
case R.id.tvGetCode:
name = etName.getText().toString();
if (TextUtils.isEmpty(name)) {
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_name_wrong, toastTime).show();
return;
}
Message msg = new Message();
msg.obj = name;
msg.what = handler_key.GETCODE.ordinal();
handler.sendMessage(msg);
break;
//register_phoneUser-false-end
case R.id.btnRrgister:
name = etName.getText().toString();
//register_phoneUser-false-start
code = etCode.getText().toString();
//register_phoneUser-false-end
psw = etPsw.getText().toString();
confirmpsw = etConfirmPsw.getText().toString();
if (TextUtils.isEmpty(name)) {
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_name_wrong, toastTime).show();
return;
}
if (usertype == 0) {
if (code.length() != 6) {
Toast.makeText(GosRegisterUserActivity.this, R.string.no_getcode, toastTime).show();
return;
}
}
if (TextUtils.isEmpty(psw)) {
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_psw_wrong, toastTime).show();
return;
}
if (psw.length() < 6) {
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_psw_short, toastTime).show();
return;
}
if (TextUtils.isEmpty(confirmpsw)) {
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_psw_confirm, toastTime).show();
return;
}
if (!psw.equals(confirmpsw)) {
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_psw_confirm_failed, toastTime).show();
return;
}
/*
* if (psw.length() < 6) {
* Toast.makeText(GosRegisterUserActivity.this,
* R.string.toast_psw_short, toastTime).show(); return; }
*/
handler.sendEmptyMessage(handler_key.REGISTER.ordinal());
break;
}
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
etName.setText("");
etName.setEnabled(true);
etName.setTextColor(getResources().getColor(R.color.text_color));
//register_phoneUser-false-start
etCode.setText("");
//register_phoneUser-false-end
etPsw.setText("");
etConfirmPsw.setText("");
etName.setHint(getResources().getString(R.string.name_phone));
llCode.setVisibility(View.VISIBLE);
etName.setInputType(InputType.TYPE_CLASS_PHONE);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
//register_phoneUser-false-start
/**
*
*/
@Override
protected void didRequestSendPhoneSMSCode(GizWifiErrorCode result, String token) {
progressDialog.cancel();
Message msg = new Message();
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
msg.what = handler_key.TOAST.ordinal();
msg.obj = toastError(result);
handler.sendMessage(msg);
} else {
handler.sendEmptyMessage(handler_key.SENDSUCCESSFUL.ordinal());
msg.what = handler_key.TOAST.ordinal();
String sendSuccessful = (String) getText(R.string.send_successful);
msg.obj = sendSuccessful;
handler.sendMessage(msg);
}
}
/**
*
*/
public void isStartTimer() {
tvGetCode.setEnabled(false);
tvGetCode.setTextColor(getResources().getColor(R.color.hint_color));
secondleft = 60;
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(handler_key.TICK_TIME.ordinal());
}
}, 1000, 1000);
}
//register_phoneUser-false-end
/**
*
*/
@Override
protected void didRegisterUser(GizWifiErrorCode result, String uid, String token) {
progressDialog.cancel();
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
Message msg = new Message();
msg.what = handler_key.TOAST.ordinal();
msg.obj = toastError(result);
handler.sendMessage(msg);
} else {
Message msg = new Message();
msg.what = handler_key.TOAST.ordinal();
String registerSuccessful = (String) getText(R.string.register_successful);
msg.obj = registerSuccessful;
handler.sendMessage(msg);
}
}
}

@ -0,0 +1,69 @@
package com.gizwits.opensource.appkit.UserModule;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
public class GosSendEmailPasswordActivity extends GosBaseActivity {
private TextView tvEmail;
private Button btnReturn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_send_email_password);
// 设置ActionBar
setToolBar(true, R.string.forget_pass);
initView();
initEvent();
}
private static final String TAG = "GosSendEmailPasswordAct";
private void initView() {
tvEmail = (TextView) findViewById(R.id.tvEmail);
btnReturn = (Button) findViewById(R.id.btnReturn);
}
private void initEvent() {
String email = spf.getString("Email", "xxx@xxx.xx");
String s = getResources().getString(R.string.send_email_pass);
//字符串截取
String bb = s.substring(10, 20);
//字符串替换
String cc = s.replace(bb, email);
SpannableString spannableString = new SpannableString(cc);
spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.tomato)), 10, 10 + email.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tvEmail.setText(spannableString);
btnReturn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(GosSendEmailPasswordActivity.this, GosUserLoginActivity.class);
startActivity(intent);
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
break;
}
return true;
}
}

@ -0,0 +1,626 @@
package com.gizwits.opensource.appkit.UserModule;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.opensource.appkit.R;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizThirdAccountType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.DeviceModule.GosDeviceListFragment;
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
//push-all-start
import com.gizwits.opensource.appkit.PushModule.GosPushManager;
//push_jiguang-false-start
import cn.jpush.android.api.JPushInterface;
//push_jiguang-false-end
//push-all-end
import com.gizwits.opensource.appkit.utils.ToolUtils;
//login_weChat-false-start
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
//login_weChat-false-end
//login_qq-false-start
import com.gizwits.opensource.appkit.ThirdAccountModule.BaseUiListener;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
//login_qq-false-end
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Timer;
import java.util.TimerTask;
@SuppressLint("HandlerLeak")
public class GosUserLoginActivity extends com.gizwits.opensource.appkit.UserModule.GosUserModuleBaseActivity implements
OnClickListener {
//GosPushManager gosPushManager;
/**
* The et Name
*/
private static EditText etName;
/**
* The et Psw
*/
private static EditText etPsw;
/**
* The btn Login
*/
private Button btnLogin;
/**
* The tv Register
*/
private TextView tvRegister;
/**
* The tv Forget
*/
private TextView tvForget;
//login_anonymous-false-start
/**
* The tv Pass
*/
private TextView tvPass;
//login_anonymous-false-end
/**
* The cb Laws
*/
private CheckBox cbLaws;
/**
* The ll QQ
*/
private LinearLayout llQQ;
/**
* The ll Wechat
*/
private LinearLayout llWechat;
private LinearLayout llFacebook;
private LinearLayout llTwitter;
private LinearLayout llWechat1;
//login_qq-false-start
/**
* The Tencent
*/
private Tencent mTencent;
//login_qq-false-end
//login_weChat-false-start
/**
* The Wechat
*/
public static IWXAPI mIwxapi;
//login_weChat-false-end
/**
* The Scope
*/
private String Scope = "get_user_info,add_t";
//login_qq-false-start
/**
* The IUiListener
*/
IUiListener listener;
//login_qq-false-end
Intent intent;
/**
* The GizThirdAccountType
*/
public static GizThirdAccountType gizThirdAccountType;
/**
* The THRED_LOGIN UID&TOKEN
*/
public static String thirdUid, thirdToken;
private LinearLayout llInland;
private LinearLayout llForeign;
private View viewLine;
public static enum handler_key {
/**
*
*/
LOGIN,
/**
*
*/
AUTO_LOGIN,
/**
*
*/
THRED_LOGIN,
/**
*
*/
FOREIGN
}
/**
* WXEntryActivityHandler
*/
private Handler baseHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
handler_key key = handler_key.values()[msg.what];
switch (key) {
// 登录
case LOGIN:
progressDialog.show();
GosDeviceListFragment.loginStatus = 0;
GizWifiSDK.sharedInstance()
.userLogin(etName.getText().toString(),
etPsw.getText().toString());
break;
// 自动登录
case AUTO_LOGIN:
progressDialog.show();
GosDeviceListFragment.loginStatus = 0;
GizWifiSDK.sharedInstance().userLogin(
spf.getString("UserName", ""),
spf.getString("PassWord", ""));
break;
// 第三方登录
case THRED_LOGIN:
progressDialog.show();
GosDeviceListFragment.loginStatus = 0;
GizWifiSDK.sharedInstance().loginWithThirdAccount(
gizThirdAccountType, thirdUid, thirdToken);
spf.edit().putString("thirdUid", thirdUid).commit();
break;
case FOREIGN:
llForeign.setVisibility(View.VISIBLE);
llInland.setVisibility(View.GONE);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.AppTheme);
// requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
setContentView(R.layout.activity_gos_user_login);
// 设置actionBaru
//setActionBar(false, false, R.string.app_company);
initView();
initEvent();
}
@Override
protected void onResume() {
super.onResume();
//push-all-start
//push_jiguang-false-start
JPushInterface.onResume(this);
//push_jiguang-false-end
//push-all-end
autoLogin();
cleanuserthing();
}
private void cleanuserthing() {
if (isclean) {
etName.setText("");
etPsw.setText("");
}
}
private void autoLogin() {
if (TextUtils.isEmpty(spf.getString("UserName", ""))
|| TextUtils.isEmpty(spf.getString("PassWord", ""))) {
return;
}
baseHandler.sendEmptyMessageDelayed(handler_key.AUTO_LOGIN.ordinal(),
1000);
}
private void initView() {
etName = (EditText) findViewById(R.id.etName);
etPsw = (EditText) findViewById(R.id.etPsw);
btnLogin = (Button) findViewById(R.id.btnLogin);
//register-all-start
tvRegister = (TextView) findViewById(R.id.tvRegister);
//register-all-end
//resetPassword-all-start
tvForget = (TextView) findViewById(R.id.tvForget);
//resetPassword-all-end
//login_anonymous-false-start
tvPass = (TextView) findViewById(R.id.tvPass);
//login_anonymous-false-end
cbLaws = (CheckBox) findViewById(R.id.cbLaws);
llInland = (LinearLayout) findViewById(R.id.llInland);
llForeign = (LinearLayout) findViewById(R.id.llForeign);
//login_qq-false-start
llQQ = (LinearLayout) findViewById(R.id.llQQ);
//login_qq-false-end
//login_qq-false-start login_qq-true-start
viewLine = (View) findViewById(R.id.view_line);
//login_qq-false-end login_qq-true-end
//login_weChat-false-start
llWechat = (LinearLayout) findViewById(R.id.llWechat);
//login_weChat-false-end
//login_weChat-false-start
llWechat1 = (LinearLayout) findViewById(R.id.llWechat1);
//login_weChat-false-end
if (!GosDeploy.appConfig_Login_Anonymous()) {
tvPass.setVisibility(View.GONE);
}
if (!GosDeploy.appConfig_Register_PhoneUser()) {
tvRegister.setVisibility(View.GONE);
}
if (!GosDeploy.appConfig_ResetPassword_PhoneUser()) {
tvForget.setVisibility(View.GONE);
}
// 配置文件部署
btnLogin.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
btnLogin.setTextColor(GosDeploy.appConfig_Contrast());
//btnLogin.setTextColor( Color.argb(255, 0, 167, 186));
}
private void initEvent() {
btnLogin.setOnClickListener(this);
//register-all-start
tvRegister.setOnClickListener(this);
//register-all-end
//resetPassword-all-start
tvForget.setOnClickListener(this);
//resetPassword-all-end
//login_anonymous-false-start
tvPass.setOnClickListener(this);
//login_anonymous-false-end
//login_qq-false-start
llQQ.setOnClickListener(this);
//login_qq-false-end
//login_weChat-false-start
llWechat.setOnClickListener(this);
//login_weChat-false-end
//login_weChat-false-start
llWechat1.setOnClickListener(this);
//login_weChat-false-end
//login_qq-true-start login_qq-false-start
if (!GosDeploy.appConfig_Login_QQ()) {
llQQ.setVisibility(View.GONE);
viewLine.setVisibility(View.GONE);
}
//login_qq-true-end login_qq-true-end
//login_weChat-true-start login_weChat-false-start
if (!GosDeploy.appConfig_Login_Wechat()) {
llWechat.setVisibility(View.GONE);
llWechat1.setVisibility(View.GONE);
viewLine.setVisibility(View.GONE);
}
//login_weChat-false-end login_weChat-true-end
cbLaws.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
String psw = etPsw.getText().toString();
if (isChecked) {
etPsw.setInputType(0x90);
} else {
etPsw.setInputType(0x81);
}
etPsw.setSelection(psw.length());
}
});
GizWifiSDK.sharedInstance().getCurrentCloudService();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnLogin:
if (TextUtils.isEmpty(etName.getText().toString())) {
Toast.makeText(GosUserLoginActivity.this,
R.string.toast_name_wrong, toastTime).show();
return;
}
if (TextUtils.isEmpty(etPsw.getText().toString())) {
Toast.makeText(GosUserLoginActivity.this,
R.string.toast_psw_wrong, toastTime).show();
return;
}
baseHandler.sendEmptyMessage(handler_key.LOGIN.ordinal());
break;
// register-all-start
case R.id.tvRegister:
if (ToolUtils.noDoubleClick()) {
intent = new Intent(GosUserLoginActivity.this,
com.gizwits.opensource.appkit.UserModule.GosRegisterUserActivity.class);
startActivity(intent);
}
break;
//register-all-end
//resetPassword-all-start
case R.id.tvForget:
if (ToolUtils.noDoubleClick()) {
intent = new Intent(GosUserLoginActivity.this,
com.gizwits.opensource.appkit.UserModule.GosForgetPasswordActivity.class);
startActivity(intent);
}
break;
//resetPassword-all-end
//login_anonymous-false-start
case R.id.tvPass:
intent = null;
if (GosDeploy.appConfig_GizwitsInfoAppID() != null && GosDeploy.appConfig_GizwitsInfoAppSecret() != null) {
}
if (intent == null) {
intent = new Intent(GosUserLoginActivity.this, GosMainActivity.class);
}
startActivity(intent);
break;
//login_anonymous-false-end
//login_qq-false-start
case R.id.llQQ:
if (ToolUtils.noDoubleClick()) {
//login_qq-true-start
if (GosDeploy.appConfig_Login_QQ()) {
// login_qq-true-end
String tencentAPPID = GosDeploy.appConfig_TencentAppID();
if (TextUtils.isEmpty(tencentAPPID)) {
noIDAlert(this, R.string.TencentAPPID_Toast);
return;
} else {
// 启动QQ登录SDK
mTencent = Tencent.createInstance(GosDeploy.appConfig_TencentAppID(),
this.getApplicationContext());
}
listener = new BaseUiListener() {
protected void doComplete(JSONObject values) {
Message msg = new Message();
try {
if (values.getInt("ret") == 0) {
gizThirdAccountType = GizThirdAccountType.GizThirdQQ;
thirdUid = values.getString("openid").toString();
thirdToken = values.getString("access_token")
.toString();
msg.what = handler_key.THRED_LOGIN.ordinal();
baseHandler.sendMessage(msg);
} else {
Toast.makeText(GosUserLoginActivity.this,
msg.obj.toString(), toastTime).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
//使用qq登录将此处放开 并且到AndroidManifest 放开activity service
mTencent.login(this, Scope, listener);
//login_qq-true-start
}
// login_qq-true-end
}
break;
//login_qq-false-end
//login_weChat-false-start
case R.id.llWechat:
if (ToolUtils.noDoubleClick()) {
// login_weChat-true-start
if (GosDeploy.appConfig_Login_Wechat()) {
// login_weChat-true-end
String wechatAppID = GosDeploy.appConfig_WechatAppID();
String wechatAppSecret = GosDeploy.appConfig_WechatAppSecret();
if (TextUtils.isEmpty(wechatAppID)
|| TextUtils.isEmpty(wechatAppSecret)
|| wechatAppID.contains("your_wechat_app_id")
|| wechatAppSecret.contains("your_wechat_app_secret")) {
noIDAlert(this, R.string.WechatAppID_Toast);
return;
} else {
// 设置与WXEntryActivity共用Handler
setBaseHandler(baseHandler);
// 启动微信登录SDK
mIwxapi = WXAPIFactory.createWXAPI(this, wechatAppID, false);
// 将应用的AppID注册到微信
mIwxapi.registerApp(wechatAppID);
}
if (!(mIwxapi.isWXAppInstalled() && mIwxapi.isWXAppSupportAPI())) {
noIDAlert(this, R.string.No_WXApp);
return;
}
SendAuth.Req req = new SendAuth.Req();
req.scope = "snsapi_userinfo";
req.state = "wechat_sdk_demo";
mIwxapi.sendReq(req);
//login_weChat-true-start
}
// login_weChat-true-end
}
break;
//login_weChat-false-end
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//login_qq-false-start
if (requestCode == 11101) {
Tencent.onActivityResultData(requestCode, resultCode, data, listener);
}
//login_qq-false-end
}
/**
*
*/
protected void didGetCurrentCloudService(GizWifiErrorCode result,
java.util.concurrent.ConcurrentHashMap<String, String> cloudServiceInfo) {
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
Toast.makeText(this, toastError(result), toastTime).show();
} else {
if (cloudServiceInfo != null) {
String api = cloudServiceInfo.get("openAPIDomain");
if (api != null) {
if (api.equals("usapi.gizwits.com") || api.equals("euapi.gizwits.com")) {
baseHandler.sendEmptyMessage(handler_key.FOREIGN.ordinal());
}
}
}
}
}
/**
*
*/
@Override
protected void didUserLogin(GizWifiErrorCode result, String uid,
String token) {
progressDialog.cancel();
Log.i("Apptest", GosDeviceListFragment.loginStatus + "\t" + "User");
if (GosDeviceListFragment.loginStatus == 4
|| GosDeviceListFragment.loginStatus == 3) {
return;
}
Log.i("Apptest", GosDeviceListFragment.loginStatus + "\t" + "UserLogin");
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {// 登录失败
Toast.makeText(GosUserLoginActivity.this, toastError(result),
toastTime).show();
} else {// 登录成功
GosDeviceListFragment.loginStatus = 1;
Toast.makeText(GosUserLoginActivity.this,
R.string.toast_login_successful, toastTime).show();
// TODO 绑定推送\
//push-all-start
//push_baidu-false-start push_baidu-true-start
if (GosDeploy.appConfig_Push_BaiDu()) {
//push_baidu-true-end
GosPushManager.pushBindService(uid, token);
//push_baidu-true-start
}
//push_baidu-false-end push_baidu-true-end
//push_jiguang-false-start push_jiguang-true-start
if (GosDeploy.appConfig_Push_JiGuang()) {
//push_jiguang-true-end
GosPushManager.pushBindService(uid, token);
//push_jiguang-true-start
}
//push_jiguang-false-end push_jiguang-true-end
//push-all-end
// PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_API_KEY, "T45LbeyAo3muOzMHztipttr8");
if (!TextUtils.isEmpty(etName.getText().toString())
&& !TextUtils.isEmpty(etPsw.getText().toString())) {
spf.edit().putString("UserName", etName.getText().toString())
.commit();
spf.edit().putString("PassWord", etPsw.getText().toString())
.commit();
}
spf.edit().putString("Uid", uid).commit();
spf.edit().putString("Token", token).commit();
intent = null;
if (intent == null) {
intent = new Intent(GosUserLoginActivity.this,
GosMainActivity.class);
}
intent.putExtra("ThredLogin", true);
startActivity(intent);
}
}
/**
*
*
* @param result
*/
protected void didChannelIDUnBind(GizWifiErrorCode result) {
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
Toast.makeText(this, toastError(result), toastTime).show();
}
Log.i("Apptest", "UnBind:" + result.toString());
}
;
/**
*
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
exitBy2Click(); // 调用双击退出函数
}
return false;
}
/**
* 退
*/
private static Boolean isExit = false;
private void exitBy2Click() {
Timer tExit = null;
if (isExit == false) {
isExit = true; // 准备退出
String doubleClick = (String) getText(R.string.double_click);
Toast.makeText(this, doubleClick, toastTime).show();
tExit = new Timer();
tExit.schedule(new TimerTask() {
@Override
public void run() {
isExit = false; // 取消退出
}
}, 2000); // 如果2秒钟内没有按下返回键则启动定时器取消掉刚才执行的任务
} else {
this.finish();
System.exit(0);
}
}
@Override
public void onPause() {
super.onPause();
}
}

@ -0,0 +1,163 @@
package com.gizwits.opensource.appkit.UserModule;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.DeviceModule.GosDeviceListFragment;
import com.gizwits.opensource.appkit.PushModule.GosPushManager;
import com.gizwits.opensource.appkit.R;
//push-all-start
//push-all-end
public class GosUserManager extends GosBaseActivity {
private static final int GOSUSERMANAGER = 234;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_usermanager);
setToolBar(true, R.string.user_management);
initView();
}
private void initView() {
TextView phoneusernumber = (TextView) findViewById(R.id.phoneusernumber);
//personalCenter_changePassword-false-start
LinearLayout changeuserpassword = (LinearLayout) findViewById(R.id.changeuserpassword);
if (!GosDeploy.appConfig_PersonalCenter_ChangePassword()) {
changeuserpassword.setVisibility(View.GONE);
}
//personalCenter_changePassword-false-end
if (!TextUtils.isEmpty(spf.getString("UserName", ""))) {
phoneusernumber.setText(spf.getString("UserName", ""));
} else {
//personalCenter_changePassword-false-start
String uid = spf.getString("thirdUid", "");
if (!TextUtils.isEmpty(uid) && uid.length() != 0) {
String myuid = uid.substring(0, 2) + "***" + uid.substring(uid.length() - 4, uid.length());
phoneusernumber.setText(myuid);
changeuserpassword.setVisibility(View.GONE);
}
//personalCenter_changePassword-false-end
}
}
public void userlogout(View v) {
setResult(GOSUSERMANAGER);
logoutToClean();
Intent intent = new Intent(GosUserManager.this, GosUserLoginActivity.class);
quitAlert(intent, getString(R.string.exit_login));
}
//personalCenter_changePassword-false-start
public void changeuserpassword(View v) {
Intent tent = new Intent(this, GosChangeUserPasswordActivity.class);
startActivity(tent);
}
//personalCenter_changePassword-false-end
private void logoutToClean() {
//push-all-start
GosPushManager.pushUnBindService(spf.getString("Token", ""));
//push-all-end
spf.edit().putString("UserName", "").commit();
isclean = true;
spf.edit().putString("PassWord", "").commit();
spf.edit().putString("Uid", "").commit();
spf.edit().putString("Token", "").commit();
spf.edit().putString("thirdUid", "").commit();
if (GosDeviceListFragment.loginStatus == 1) {
GosDeviceListFragment.loginStatus = 0;
} else {
GosDeviceListFragment.loginStatus = 4;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
isclean = false;
finish();
break;
}
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
isclean = false;
finish();
return true;
}
return false;
}
/**
*
*
* @param
*/
protected void quitAlert(final Intent intent, String content) {
final Dialog dialog = new AlertDialog.Builder(this, R.style.alert_dialog_style)
.setView(new EditText(this)).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_quit);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
TextView tvContent;
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
tvContent = (TextView) window.findViewById(R.id.tv_prompt);
tvContent.setText(content);
llNo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
llSure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
startActivity(intent);
}
});
}
}

@ -0,0 +1,132 @@
package com.gizwits.opensource.appkit.UserModule;
import android.view.MenuItem;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizWifiSDKListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
public class GosUserModuleBaseActivity extends GosBaseActivity {
private GizWifiSDKListener gizWifiSDKListener = new GizWifiSDKListener() {
/** 用于用户登录 */
public void didUserLogin(GizWifiErrorCode result, String uid, String token) {
GosUserModuleBaseActivity.this.didUserLogin(result, uid, token);
};
/** 用于手机验证码 */
public void didRequestSendPhoneSMSCode(GizWifiErrorCode result, String token) {
GosUserModuleBaseActivity.this.didRequestSendPhoneSMSCode(result, token);
};
/** 用于用户注册 */
public void didRegisterUser(GizWifiErrorCode result, String uid, String token) {
GosUserModuleBaseActivity.this.didRegisterUser(result, uid, token);
};
/** 用于重置密码 */
public void didChangeUserPassword(GizWifiErrorCode result) {
GosUserModuleBaseActivity.this.didChangeUserPassword(result);
};
/** 用于解绑推送 */
public void didChannelIDUnBind(GizWifiErrorCode result) {
GosUserModuleBaseActivity.this.didChannelIDUnBind(result);
};
/** 用于设置云端服务环境 */
public void didGetCurrentCloudService(GizWifiErrorCode result,
java.util.concurrent.ConcurrentHashMap<String, String> cloudServiceInfo) {
GosUserModuleBaseActivity.this.didGetCurrentCloudService(result, cloudServiceInfo);
};
};
/**
*
*
* @param result
*
* @param uid
* ID
* @param token
*
*/
protected void didUserLogin(GizWifiErrorCode result, String uid, String token) {
};
/**
*
*
* @param result
*
* @param token
*
*/
protected void didRequestSendPhoneSMSCode(GizWifiErrorCode result, String token) {
};
/**
*
*
* @param result
*
* @param uid
* ID
* @param token
*
*/
protected void didRegisterUser(GizWifiErrorCode result, String uid, String token) {
};
/**
*
*
* @param result
*
*/
protected void didChangeUserPassword(GizWifiErrorCode result) {
};
/**
*
*
* @param result
*
*/
protected void didChannelIDUnBind(GizWifiErrorCode result) {
};
/**
*
*
* @param result
*
* @param cloudServiceInfo
*
*/
protected void didGetCurrentCloudService(GizWifiErrorCode result,
java.util.concurrent.ConcurrentHashMap<String, String> cloudServiceInfo) {
}
@Override
protected void onResume() {
super.onResume();
// 每次返回activity都要注册一次sdk监听器保证sdk状态能正确回调
GizWifiSDK.sharedInstance().setListener(gizWifiSDKListener);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
break;
}
return super.onOptionsItemSelected(item);
}
}

@ -0,0 +1,272 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.api.GizDeviceSharingInfo;
import com.gizwits.gizwifisdk.api.GizUserInfo;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingStatus;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.DateUtil;
public class InvitedFragment extends Fragment {
// 定义俩个整形值用来区分当前要显示的是哪个view对象
// 如果是1的话就共享列表 2的话就是受邀列表
private int mytpye = -1;
// private List<GizDeviceSharingInfo> mydeviceSharingInfos = new ArrayList<GizDeviceSharingInfo>();
private String token;
private myadapter myadapter;
private TextView myview;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
initdata();
// 动态找到布局文件再从这个布局中find出TextView对象
View contextView = inflater.inflate(R.layout.activity_gos_shared_list, container, false);
ListView mListView = (ListView) contextView.findViewById(R.id.mysharedlist);
myview = (TextView) contextView.findViewById(R.id.shareddeviceproductname);
myview.setText(getString(R.string.no_guest_users));
if (GosConstant.newmydeviceSharingInfos != null) {
myadapter = new myadapter();
mListView.setAdapter(myadapter);
}
return contextView;
}
public TextView getmyview() {
return myview;
}
// 初始化接口数据
private void initdata() {
SharedPreferences spf = getActivity().getSharedPreferences("set", Context.MODE_PRIVATE);
token = spf.getString("Token", "");
// GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingToMe, null);
//
// GizDeviceSharing.setListener(new GizDeviceSharingListener() {
//
// @Override
// public void didGetDeviceSharingInfos(GizWifiErrorCode result, String deviceID,
// List<GizDeviceSharingInfo> deviceSharingInfos) {
// super.didGetDeviceSharingInfos(result, deviceID, deviceSharingInfos);
// mydeviceSharingInfos = deviceSharingInfos;
//
// if (mydeviceSharingInfos.size() == 0) {
// myview.setVisibility(View.VISIBLE);
// myview.setText(getResources().getString(R.string.you_have_no_invited_message));
// } else {
// myview.setVisibility(View.GONE);
// }
// myadapter.notifyDataSetChanged();
// }
//
// @Override
// public void didAcceptDeviceSharing(GizWifiErrorCode result, String sharingID) {
// super.didAcceptDeviceSharing(result, sharingID);
//
// SharedDeviceListAcitivity activity = (SharedDeviceListAcitivity) getActivity();
// if (result.ordinal() != 0) {
// Toast.makeText(activity, activity.toastError(result), 2).show();
// }
//
// GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingToMe, null);
// }
//
// });
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
// listview的adapter通过刷新的bound对象的属性值来判断当前应该现实的是什么
class myadapter extends BaseAdapter {
@Override
public int getCount() {
return GosConstant.newmydeviceSharingInfos.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = View.inflate(getActivity(), R.layout.gos_shared_to_me_activity, null);
TextView mess = (TextView) view.findViewById(R.id.mess);
View redpoint = view.findViewById(R.id.redpoint);
TextView timemess = (TextView) view.findViewById(R.id.timemess);
TextView mystatues = (TextView) view.findViewById(R.id.mystatues);
LinearLayout buttionline = (LinearLayout) view.findViewById(R.id.buttionline);
TextView accept = (TextView) view.findViewById(R.id.accept);
TextView refuse = (TextView) view.findViewById(R.id.refuse);
final GizDeviceSharingInfo gizDeviceSharingInfo = GosConstant.newmydeviceSharingInfos.get(position);
GizUserInfo userInfo = gizDeviceSharingInfo.getUserInfo();
String username = userInfo.getUsername();
String email = userInfo.getEmail();
String phone = userInfo.getPhone();
String remark = userInfo.getRemark();
String uid = userInfo.getUid();
accept.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
GizDeviceSharing.acceptDeviceSharing(token, gizDeviceSharingInfo.getId(), true);
}
});
refuse.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
GizDeviceSharing.acceptDeviceSharing(token, gizDeviceSharingInfo.getId(), false);
}
});
String passs = getResources().getString(R.string.tomeshareddevice);
String[] split = passs.split("xxx");
if (!TextUtils.isEmpty(uid) && !uid.equals("null")) {
uid = uid.substring(0, 3) + "***" + uid.substring(uid.length() - 4, uid.length());
if (split.length > 2) {
mess.setText(split[0] + uid + split[split.length - 1]);
} else {
mess.setText(uid + split[split.length - 1]);
}
}
if (!TextUtils.isEmpty(email) && !email.equals("null")) {
if (split.length > 2) {
mess.setText(split[0] + email + split[split.length - 1]);
} else {
mess.setText(email + split[split.length - 1]);
}
}
if (!TextUtils.isEmpty(phone) && !phone.equals("null")) {
if (split.length > 2) {
mess.setText(split[0] + phone + split[split.length - 1]);
} else {
mess.setText(phone + split[split.length - 1]);
}
}
if (!TextUtils.isEmpty(username) && !username.equals("null")) {
if (split.length > 2) {
mess.setText(split[0] + username + split[split.length - 1]);
} else {
mess.setText(username + split[split.length - 1]);
}
}
if (!TextUtils.isEmpty(remark) && !remark.equals("null")) {
if (split.length > 2) {
mess.setText(split[0] + remark + split[split.length - 1]);
} else {
mess.setText(remark + split[split.length - 1]);
}
}
GizDeviceSharingStatus status = gizDeviceSharingInfo.getStatus();
String updatedAt = gizDeviceSharingInfo.getUpdatedAt();
updatedAt = DateUtil.utc2Local(updatedAt);
String expiredAt = gizDeviceSharingInfo.getExpiredAt();
expiredAt = DateUtil.utc2Local(expiredAt);
timemess.setText(updatedAt + " " + gizDeviceSharingInfo.getProductName());
int myintstatus = status.ordinal();
if (myintstatus == 0) {
String timeByFormat = DateUtil.getCurTimeByFormat("yyyy-MM-dd HH:mm:ss");
long diff = DateUtil.getDiff(timeByFormat, expiredAt);
if (diff > 0) {
redpoint.setVisibility(View.GONE);
mystatues.setVisibility(View.VISIBLE);
buttionline.setVisibility(View.GONE);
mystatues.setText(getResources().getString(R.string.requsettimeout));
} else {
redpoint.setVisibility(View.VISIBLE);
buttionline.setVisibility(View.VISIBLE);
mystatues.setVisibility(View.GONE);
}
} else {
redpoint.setVisibility(View.GONE);
mystatues.setVisibility(View.VISIBLE);
buttionline.setVisibility(View.GONE);
if (myintstatus == 1) {
mystatues.setText(getResources().getString(R.string.accept));
} else if (myintstatus == 2) {
mystatues.setText(getResources().getString(R.string.refuse));
} else if (myintstatus == 3) {
mystatues.setText(getResources().getString(R.string.cancelled));
}
}
return view;
}
}
public myadapter getmyadapter() {
return myadapter;
}
}

@ -0,0 +1,82 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.TextView;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.R;
/**
* Created by Sunny on 2015625
*
* @author Sunny
*/
public class MsgNoticeActivity extends GosBaseActivity {
private ListView lvNotice;
private TextView tvNoNotice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notice);
// setActionBar(true, true, R.string.msg_xnotice);
initView();
// initData();
}
private void initView(){
lvNotice=(ListView) findViewById(R.id.lvNotice);
tvNoNotice=(TextView) findViewById(R.id.tvNoNotice);
}
// private void initData(){
// NoticeDBService dbService= new NoticeDBService(this);
// ArrayList<NoticeBean> lsNotice=dbService.getNoticeList();
//
// if(lsNotice!=null&&lsNotice.size()>0){
// lvNotice.setVisibility(View.VISIBLE);
// tvNoNotice.setVisibility(View.GONE);
//
// NoticeAdapter na=new NoticeAdapter(this, lsNotice);
// lvNotice.setAdapter(na);
// }else{
// lvNotice.setVisibility(View.GONE);
// tvNoNotice.setVisibility(View.VISIBLE);
// }
// }
@Override
public void onResume() {
super.onResume();
// initData();
}
@Override
public void onPause() {
super.onPause();
}
public boolean onOptionsItemSelected(MenuItem menu) {
super.onOptionsItemSelected(menu);
switch (menu.getItemId()) {
case android.R.id.home:
finish();
break;
default:
break;
}
return true;
}
@Override
public void onBackPressed() {
finish();
}
}

@ -0,0 +1,233 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.api.GizDeviceSharingInfo;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.CommonModule.NoScrollViewPager;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.DateUtil;
import com.gizwits.opensource.appkit.view.ViewPagerIndicator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class SharedDeviceListAcitivity extends GosBaseActivity {
private List<String> tabList;
private List<Fragment> myfragmentlist;
private String token;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_shared_device_list);
setToolBar(true, R.string.sharedlist);
initData();
initView();
}
// 初始化tab标签中应该显示的文字
private void initData() {
token = spf.getString("Token", "");
myfragmentlist = new ArrayList<Fragment>();
SharedFragment ment1 = new SharedFragment();
InvitedFragment ment2 = new InvitedFragment();
myfragmentlist.add(ment1);
myfragmentlist.add(ment2);
tabList = new ArrayList<String>();
tabList.add(getResources().getString(R.string.shared));
tabList.add(getResources().getString(R.string.invited));
}
private void initView() {
ViewPagerIndicator indicator = (ViewPagerIndicator) findViewById(
R.id.vpi_indicator);
indicator.setVisibleTabCount(2);
indicator.setTabItemTitles(tabList);
NoScrollViewPager vp_shared = (NoScrollViewPager) findViewById(R.id.vp_shared_list);
vp_shared.setNoScroll(true);
vp_shared.setAdapter(new myFragmentAdapter(getSupportFragmentManager()));
indicator.setViewPager(vp_shared, 0);
indicator.setOnPageChangeListener(new ViewPagerIndicator.PageChangeListener() {
@Override
public void onPageSelected(int position) {
GosConstant.nowPager = position;
switch (GosConstant.nowPager) {
case 0:
break;
case 1:
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingToMe, null);
break;
default:
break;
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
class myFragmentAdapter extends FragmentStatePagerAdapter {
public myFragmentAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int arg0) {
if (arg0 == 0) {
SharedFragment shared = new SharedFragment();
return shared;
} else {
InvitedFragment shared = (InvitedFragment) myfragmentlist.get(arg0);
return shared;
}
}
@Override
public int getCount() {
return 2;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
initListener();
}
// 初始化接口数据
private void initListener() {
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
@Override
public void didGetDeviceSharingInfos(GizWifiErrorCode result, String deviceID,
List<GizDeviceSharingInfo> deviceSharingInfos) {
super.didGetDeviceSharingInfos(result, deviceID, deviceSharingInfos);
if (deviceSharingInfos != null) {
Collections.sort(deviceSharingInfos, new Comparator<GizDeviceSharingInfo>() {
@Override
public int compare(GizDeviceSharingInfo arg0, GizDeviceSharingInfo arg1) {
String updatedAt = DateUtil.utc2Local(arg0.getUpdatedAt());
String updatedAt2 = DateUtil.utc2Local(arg1.getUpdatedAt());
int diff = (int) DateUtil.getDiff(updatedAt2, updatedAt);
return diff;
}
});
}
GosConstant.newmydeviceSharingInfos = deviceSharingInfos;
InvitedFragment fragment = (InvitedFragment) myfragmentlist.get(1);
TextView myview = fragment.getmyview();
if (deviceSharingInfos.size() == 0) {
myview.setVisibility(View.VISIBLE);
myview.setText(getResources().getString(R.string.no_guest_users));
} else {
myview.setVisibility(View.GONE);
}
InvitedFragment.myadapter getmyadapter = fragment.getmyadapter();
getmyadapter.notifyDataSetChanged();
if (result.ordinal() != 0) {
Toast.makeText(SharedDeviceListAcitivity.this, toastError(result), 2).show();
}
}
@Override
public void didAcceptDeviceSharing(GizWifiErrorCode result, int sharingID) {
super.didAcceptDeviceSharing(result, sharingID);
if (result.ordinal() != 0) {
Toast.makeText(SharedDeviceListAcitivity.this, toastError(result), 2).show();
}
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingToMe, null);
}
});
}
}

@ -0,0 +1,282 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.MenuItem;
import android.widget.Toast;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.api.GizDeviceSharingInfo;
import com.gizwits.gizwifisdk.api.GizUserInfo;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.CommonModule.NoScrollViewPager;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.DateUtil;
import com.gizwits.opensource.appkit.view.ViewPagerIndicator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class SharedDeviceManagerActivity extends GosBaseActivity {
private List<String> tabList;
private String productname;
private String deviceid;
private List<Fragment> myfragmentlist;
private int viewPagerSelected = 0;
private boolean isgetsharing;
private String token;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_shared_device_list);
setToolBar(true, R.string.sharedmanager);
GosConstant.isEdit = false;
initData();
initView();
token = spf.getString("Token", "");
}
@Override
protected void onResume() {
super.onResume();
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
@Override
public void didSharingDevice(GizWifiErrorCode result, String deviceID, int sharingID, Bitmap QRCodeImage) {
super.didSharingDevice(result, deviceID, sharingID, QRCodeImage);
if (result.ordinal() != 0) {
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
}
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingByMe, deviceid);
}
@Override
public void didModifySharingInfo(GizWifiErrorCode result, int sharingID) {
super.didModifySharingInfo(result, sharingID);
if (result.ordinal() != 0) {
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
}
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingByMe, deviceid);
}
@Override
public void didGetDeviceSharingInfos(GizWifiErrorCode result, String deviceID,
List<GizDeviceSharingInfo> deviceSharingInfos) {
super.didGetDeviceSharingInfos(result, deviceID, deviceSharingInfos);
if (deviceSharingInfos != null) {
Collections.sort(deviceSharingInfos, new Comparator<GizDeviceSharingInfo>() {
@Override
public int compare(GizDeviceSharingInfo arg0, GizDeviceSharingInfo arg1) {
String updatedAt = DateUtil.utc2Local(arg0.getUpdatedAt());
String updatedAt2 = DateUtil.utc2Local(arg1.getUpdatedAt());
int diff = (int) DateUtil.getDiff(updatedAt2, updatedAt);
return diff;
}
});
}
GosConstant.mydeviceSharingInfos = deviceSharingInfos;
SharedStateFragment fragment = (SharedStateFragment) myfragmentlist.get(0);
Message msg = new Message();
msg.what = 1;
fragment.handler.sendMessage(msg);
SharedUserFragment fragment1 = (SharedUserFragment) myfragmentlist.get(1);
Message msg1 = new Message();
msg1.what = 1;
fragment1.handler.sendMessage(msg1);
if (result.ordinal() != 0) {
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
}
}
@Override
public void didGetBindingUsers(GizWifiErrorCode result, String deviceID, List<GizUserInfo> bindUsers) {
super.didGetBindingUsers(result, deviceID, bindUsers);
GosConstant.mybindUsers = bindUsers;
SharedUserFragment fragment = (SharedUserFragment) myfragmentlist.get(1);
SharedUserFragment.myadapter getmyadapter = fragment.getmyadapter();
if (getmyadapter != null) {
getmyadapter.notifyDataSetChanged();
}
if (result.ordinal() != 0) {
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
}
}
@Override
public void didUnbindUser(GizWifiErrorCode result, String deviceID, String guestUID) {
// TODO Auto-generated method stub
super.didUnbindUser(result, deviceID, guestUID);
GizDeviceSharing.getBindingUsers(token, deviceid);
if (result.ordinal() != 0) {
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
}
}
@Override
public void didRevokeDeviceSharing(GizWifiErrorCode result, int sharingID) {
// TODO Auto-generated method stub
super.didRevokeDeviceSharing(result, sharingID);
if (result.ordinal() == 0) {
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingByMe, deviceid);
} else {
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
}
}
});
}
// 初始化tab标签中应该显示的文字
private void initData() {
productname = getIntent().getStringExtra("productname");
deviceid = getIntent().getStringExtra("deviceid");
isgetsharing = getIntent().getBooleanExtra("isgetsharing", false);
tabList = new ArrayList<String>();
tabList.add(getResources().getString(R.string.sharedstated));
tabList.add(getResources().getString(R.string.boundusers));
SharedStateFragment shared = new SharedStateFragment();
SharedUserFragment shared1 = new SharedUserFragment();
myfragmentlist = new ArrayList<Fragment>();
myfragmentlist.add(shared);
myfragmentlist.add(shared1);
}
private void initView() {
ViewPagerIndicator indicator = (ViewPagerIndicator) findViewById(
R.id.vpi_indicator);
indicator.setVisibleTabCount(2);
indicator.setTabItemTitles(tabList);
NoScrollViewPager vp_shared = (NoScrollViewPager) findViewById(
R.id.vp_shared_list);
vp_shared.setNoScroll(true);
vp_shared.setAdapter(new myFragmentAdapter(getSupportFragmentManager()));
indicator.setViewPager(vp_shared, 0);
indicator.setOnPageChangeListener(new ViewPagerIndicator.PageChangeListener() {
@Override
public void onPageSelected(int position) {
viewPagerSelected = position;
if (position == 0 && isgetsharing) {
SharedPreferences spf = getSharedPreferences("set", Context.MODE_PRIVATE);
String token = spf.getString("Token", "");
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingByMe, deviceid);
} else if (position == 1 && isgetsharing) {
SharedStateFragment fragment3 = (SharedStateFragment) myfragmentlist.get(0);
Message msg = new Message();
msg.what = 2;
fragment3.handler.sendMessage(msg);
SharedPreferences spf = getSharedPreferences("set", Context.MODE_PRIVATE);
String token = spf.getString("Token", "");
GizDeviceSharing.getBindingUsers(token, deviceid);
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
class myFragmentAdapter extends FragmentStatePagerAdapter {
public myFragmentAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int arg0) {
Bundle b = new Bundle();
b.putString("productname", productname);
b.putString("deviceid", deviceid);
Fragment fragment = myfragmentlist.get(arg0);
fragment.setArguments(b);
return fragment;
}
@Override
public int getCount() {
return myfragmentlist.size();
}
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
// 刷新menu的方法
private void refreshMenu() {
// 核心是Activity这个方法
supportInvalidateOptionsMenu();
}
}

@ -0,0 +1,212 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingUserRole;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.R;
import java.util.ArrayList;
import java.util.List;
public class SharedFragment extends Fragment {
// 定义俩个整形值用来区分当前要显示的是哪个view对象
// 如果是1的话就共享列表 2的话就是受邀列表
private int mytpye = -1;
private List<GizWifiDevice> list;
private TextView myview;
private myadapter myadapter1;
private ListView mListView;
private View contextView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// 动态找到布局文件再从这个布局中find出TextView对象
contextView = inflater.inflate(R.layout.activity_gos_shared_list, container, false);
initView();
initData();
initEvent();
return contextView;
}
private void initView() {
mListView = (ListView) contextView.findViewById(R.id.mysharedlist);
myview = (TextView) contextView.findViewById(R.id.shareddeviceproductname);
}
private void initEvent() {
myadapter1 = new myadapter();
mListView.setAdapter(myadapter1);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
GizWifiDevice wifiDevice = list.get(arg2);
GizDeviceSharingUserRole sharingRole = wifiDevice.getSharingRole();
int role = sharingRole.ordinal();
boolean isgetsharing = false;
if (role == 2) {
isgetsharing = true;
}
mListView.setEnabled(false);
mListView.postDelayed(new Runnable() {
@Override
public void run() {
mListView.setEnabled(true);
}
}, 1000);
Intent tent = new Intent(getActivity(), SharedDeviceManagerActivity.class);
GosConstant.mybindUsers.clear();
GosConstant.mydeviceSharingInfos.clear();
tent.putExtra("productname", wifiDevice.getProductName());
tent.putExtra("deviceid", wifiDevice.getDid());
tent.putExtra("isgetsharing", isgetsharing);
startActivity(tent);
}
});
}
// 获取当前的设备列表
private void initData() {
list = new ArrayList<GizWifiDevice>();
List<GizWifiDevice> deviceList = GizWifiSDK.sharedInstance().getDeviceList();
for (GizWifiDevice gizWifiDevice : deviceList) {
GizDeviceSharingUserRole sharingRole = gizWifiDevice.getSharingRole();
if (sharingRole != null) {
if (sharingRole.ordinal() == 1 || sharingRole.ordinal() == 2) {
list.add(gizWifiDevice);
}
}
}
if (list.size() == 0) {
myview.setVisibility(View.VISIBLE);
myview.setText(getResources().getString(R.string.you_have_no_device));
} else {
myview.setVisibility(View.GONE);
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
// listview的adapter通过刷新的bound对象的属性值来判断当前应该现实的是什么
class myadapter extends BaseAdapter {
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
Holder holder;
if (view == null) {
view = View.inflate(getActivity(), R.layout.item_gos_device_shared_list, null);
holder = new Holder(view);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
holder.getTvDeviceName().setText(list.get(position).getProductName());
holder.getTvDeviceMac().setText(list.get(position).getMacAddress());
GizDeviceSharingUserRole sharingRole = list.get(position).getSharingRole();
if (sharingRole.ordinal() == 1) {
holder.getTvDeviceStatus().setVisibility(View.VISIBLE);
holder.getTvDeviceStatus().setText(getString(R.string.not_sharing));
} else if (sharingRole.ordinal() == 2) {
holder.getTvDeviceStatus().setVisibility(View.GONE);
}
return view;
}
}
public myadapter getmyadapter() {
return myadapter1;
}
// 设备列表对应的holder
class Holder {
View view;
public Holder(View view) {
this.view = view;
}
private TextView tvDeviceMac, tvDeviceStatus, tvDeviceName;
public TextView getTvDeviceMac() {
if (null == tvDeviceMac) {
tvDeviceMac = (TextView) view.findViewById(R.id.tvDeviceMac);
}
return tvDeviceMac;
}
public TextView getTvDeviceStatus() {
if (null == tvDeviceStatus) {
tvDeviceStatus = (TextView) view.findViewById(R.id.tvDeviceStatus);
}
return tvDeviceStatus;
}
public TextView getTvDeviceName() {
if (null == tvDeviceName) {
tvDeviceName = (TextView) view.findViewById(R.id.tvDeviceName);
}
return tvDeviceName;
}
}
}

@ -0,0 +1,600 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.api.GizDeviceSharingInfo;
import com.gizwits.gizwifisdk.api.GizUserInfo;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingStatus;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingType;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingWay;
import com.gizwits.gizwifisdk.enumration.GizUserAccountType;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.AssetsUtils;
import com.gizwits.opensource.appkit.utils.DateUtil;
import com.gizwits.opensource.appkit.view.SlideListView2;
public class SharedStateFragment extends Fragment {
// 定义俩个整形值用来区分当前要显示的是哪个view对象
// 如果是1的话就共享列表 2的话就是受邀列表
private int mytpye = -1;
View contextView;
private String deviceID;
private myadapter myadapter;
private String token;
private LinearLayout addshared;
private SlideListView2 mListView;
private String productname;
private TextView shareddeviceproductname;
private TextView tvSharedTo;
private LinearLayout llSharedTo;
private LinearLayout llAddShared;
private LinearLayout rename;
private SharedPreferences spf;
private LinearLayout cancel;
private RelativeLayout rlCancel;
private static final String TAG = "mySharedFragment3";
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
// 当GosConstant.mydeviceSharingInfos 在Activity中被赋值后执行
case 1:
if (GosConstant.mydeviceSharingInfos.size() == 0) {
String s = getResources().getString(R.string.have_not_been_shared);
String ss = s.substring(3, s.length());
StringBuilder sb = new StringBuilder(productname);
shareddeviceproductname.setText(sb.append(ss));
shareddeviceproductname.setVisibility(View.VISIBLE);
llSharedTo.setVisibility(View.GONE);
rename.setVisibility(View.GONE);
llAddShared.setVisibility(View.VISIBLE);
} else {
tvSharedTo.setText(productname + getResources().getString(R.string.sharedto));
llSharedTo.setVisibility(View.VISIBLE);
shareddeviceproductname.setVisibility(View.GONE);
if (rlCancel.getVisibility() == View.GONE) {
rename.setVisibility(View.VISIBLE);
llAddShared.setVisibility(View.VISIBLE);
}
}
if (myadapter == null) {
myadapter = new myadapter(true);
mListView.setAdapter(myadapter);
} else {
mListView.setAdapter(myadapter);
}
break;
case 2:
mListView.initSlideMode(SlideListView2.MOD_RIGHT);
mListView.setOnItemClickListener(null);
rlCancel.setVisibility(View.GONE);
llAddShared.setVisibility(View.VISIBLE);
break;
}
}
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// 动态找到布局文件再从这个布局中find出TextView对象
contextView = inflater.inflate(R.layout.activity_gos_shared_manage, container, false);
initView();
initData();
initEvent();
return contextView;
}
private void initView() {
mListView = (SlideListView2) contextView.findViewById(R.id.mysharedlist);
mListView.initSlideMode(SlideListView2.MOD_RIGHT);
llAddShared = (LinearLayout) contextView.findViewById(R.id.llAddShared);
rlCancel = (RelativeLayout) contextView.findViewById(R.id.rlCancel);
addshared = (LinearLayout) contextView.findViewById(R.id.addshared);
rename = (LinearLayout) contextView.findViewById(R.id.rename);
cancel = (LinearLayout) contextView.findViewById(R.id.cancel);
shareddeviceproductname = (TextView) contextView.findViewById(R.id.shareddeviceproductname);
tvSharedTo = (TextView) contextView.findViewById(R.id.tvSharedTo);
llSharedTo = (LinearLayout) contextView.findViewById(R.id.llSharedTo);
}
private void initData() {
Bundle arguments = getArguments();
productname = arguments.getString("productname");
spf = getActivity().getSharedPreferences("set", Context.MODE_PRIVATE);
token = spf.getString("Token", "");
deviceID = getArguments().getString("deviceid");
}
@Override
public void onResume() {
super.onResume();
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingByMe, deviceID);
}
private void initEvent() {
addshared.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (!TextUtils.isEmpty(spf.getString("UserName", "")) && !TextUtils.isEmpty(spf.getString("PassWord", ""))) {
Intent tent = new Intent(getActivity(), addSharedActivity.class);
tent.putExtra("productname", productname);
tent.putExtra("did", deviceID);
startActivity(tent);
} else {
Toast.makeText(getContext(), getString(R.string.please_login), 2000).show();
}
}
});
rename.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mListView.initSlideMode(SlideListView2.MOD_FORBID);
llAddShared.setVisibility(View.GONE);
rlCancel.setVisibility(View.VISIBLE);
myadapter = new myadapter(false);
mListView.setAdapter(myadapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
TextView name = (TextView) view.findViewById(R.id.tvDeviceName);
final Dialog dialog = new AlertDialog.Builder(getContext(), R.style.edit_dialog_style)
.setView(new EditText(getContext())).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_rename);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
final EditText remarkname = (EditText) window.findViewById(R.id.remarkname);
remarkname.setText(name.getText().toString());
remarkname.setSelection(name.getText().toString().length());
RelativeLayout rlClear = (RelativeLayout) window.findViewById(R.id.rlClear);
LinearLayout llyes = (LinearLayout) window.findViewById(R.id.llSure);
LinearLayout llno = (LinearLayout) window.findViewById(R.id.llNo);
llno.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
rlClear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
remarkname.setText("");
}
});
llyes.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String token = spf.getString("Token", "");
GizDeviceSharingInfo gizDeviceSharingInfo = GosConstant.mydeviceSharingInfos.get(position);
GizDeviceSharing.modifySharingInfo(token, gizDeviceSharingInfo.getId(),
remarkname.getText().toString());
dialog.dismiss();
}
});
}
});
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mListView.initSlideMode(SlideListView2.MOD_RIGHT);
mListView.setOnItemClickListener(null);
rlCancel.setVisibility(View.GONE);
llAddShared.setVisibility(View.VISIBLE);
myadapter = new myadapter(true);
mListView.setAdapter(myadapter);
}
});
}
public myadapter getmyadapter() {
return myadapter;
}
public RelativeLayout getRelativeLayout() {
return rlCancel;
}
public SlideListView2 getListview() {
return mListView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
// listview的adapter通过刷新的bound对象的属性值来判断当前应该现实的是什么
class myadapter extends BaseAdapter {
private String uid;
private boolean isShow;
@Override
public int getCount() {
return GosConstant.mydeviceSharingInfos.size();
}
public myadapter(boolean isShow) {
this.isShow = isShow;
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(
R.layout.gos_shared_by_me_activity, null);
holder = new ViewHolder();
holder.rlmyhome = (RelativeLayout) convertView.findViewById(R.id.rlmyhome);
holder.tvDeviceName = (TextView) convertView.findViewById(R.id.tvDeviceName);
holder.tvDeviceMac = (TextView) convertView.findViewById(R.id.tvDeviceMac);
holder.tvDeviceStatus = (TextView) convertView.findViewById(R.id.tvDeviceStatus);
holder.delete2name = (TextView) convertView.findViewById(R.id.delete2name);
holder.delete3name = (TextView) convertView.findViewById(R.id.delete3name);
holder.delete2 = (LinearLayout) convertView.findViewById(R.id.delete2);
holder.delete3 = (LinearLayout) convertView.findViewById(R.id.delete3);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.delete2.setVisibility(View.INVISIBLE);
holder.delete2name.setText(getResources().getString(R.string.cancel_sharing));
holder.delete3name.setText(getResources().getString(R.string.sharedagain));
GizDeviceSharingInfo gizDeviceSharingInfo = GosConstant.mydeviceSharingInfos.get(position);
final int id = gizDeviceSharingInfo.getId();
final String myid = gizDeviceSharingInfo.getDeviceID();
GizUserInfo userInfo = gizDeviceSharingInfo.getUserInfo();
// 更新时间
String updatedAt = gizDeviceSharingInfo.getUpdatedAt();
// 超时时间
String expiredAt = gizDeviceSharingInfo.getExpiredAt();
uid = userInfo.getUid();
String email = userInfo.getEmail();
String phone = userInfo.getPhone();
String username = userInfo.getUsername();
String remark = userInfo.getRemark();
if (!TextUtils.isEmpty(uid) && !uid.equals("null")) {
String myuid = uid.substring(0, 3) + "***" + uid.substring(uid.length() - 4, uid.length());
holder.tvDeviceName.setText(myuid);
}
if (!TextUtils.isEmpty(email) && !email.equals("null")) {
holder.tvDeviceName.setText(email);
}
if (!TextUtils.isEmpty(phone) && !phone.equals("null")) {
holder.tvDeviceName.setText(phone);
}
if (!TextUtils.isEmpty(username) && !username.equals("null")) {
holder.tvDeviceName.setText(username);
}
if (!TextUtils.isEmpty(remark) && !remark.equals("null")) {
holder.tvDeviceName.setText(remark);
}
updatedAt = DateUtil.utc2Local(updatedAt);
expiredAt = DateUtil.utc2Local(expiredAt);
holder.tvDeviceMac.setText(updatedAt);
GizDeviceSharingStatus status = gizDeviceSharingInfo.getStatus();
int ordinal = status.ordinal();
if (isShow) {
holder.tvDeviceStatus.setVisibility(View.VISIBLE);
} else {
holder.tvDeviceStatus.setVisibility(View.GONE);
}
switch (ordinal) {
case 0:
String timeByFormat = DateUtil.getCurTimeByFormat("yyyy-MM-dd HH:mm:ss");
long diff = DateUtil.getDiff(timeByFormat, expiredAt);
if (diff > 0) {
holder.delete3name.setText(getResources().getString(R.string.delete));
holder.delete2name.setText(getResources().getString(R.string.sharedagain));
holder.rlmyhome.setPadding(0, 0, AssetsUtils.diptopx(getContext(), -181), 0);
holder.delete2.setVisibility(View.VISIBLE);
holder.delete3.setVisibility(View.VISIBLE);
holder.delete2.setBackgroundColor(getResources().getColor(R.color.back_gray));
holder.delete3.setBackgroundColor(getResources().getColor(R.color.unbind));
holder.delete2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
GizDeviceSharing.sharingDevice(token, myid, GizDeviceSharingWay.GizDeviceSharingByNormal,
GosConstant.mydeviceSharingInfos.get(position).getUserInfo().getUid(),
GizUserAccountType.GizUserOther);
}
});
holder.delete3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
GizDeviceSharing.revokeDeviceSharing(token, id);
}
});
holder.tvDeviceStatus.setText(getResources().getString(R.string.timeout));
} else {
holder.delete3.setVisibility(View.GONE);
holder.rlmyhome.setPadding(0, 0, AssetsUtils.diptopx(getContext(), -91), 0);
holder.delete2.setVisibility(View.VISIBLE);
holder.delete2.setBackgroundColor(getResources().getColor(R.color.unbind));
holder.delete2name.setText(getResources().getString(R.string.cancel_sharing));
final String s = holder.tvDeviceName.getText().toString();
holder.delete2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
quitAlert(getActivity(), s, id);
}
});
holder.tvDeviceStatus.setText(getResources().getString(R.string.waitforaccept));
}
break;
case 1:
holder.tvDeviceStatus.setText(getResources().getString(R.string.accept));
holder.delete3.setVisibility(View.GONE);
holder.rlmyhome.setPadding(0, 0, AssetsUtils.diptopx(getContext(), -91), 0);
holder.delete2.setVisibility(View.VISIBLE);
holder.delete2.setBackgroundColor(getResources().getColor(R.color.unbind));
holder.delete2name.setText(getResources().getString(R.string.cancel_sharing));
final String s = holder.tvDeviceName.getText().toString();
holder.delete2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
quitAlert(getActivity(), s, id);
}
});
break;
case 2:
holder.rlmyhome.setPadding(0, 0, AssetsUtils.diptopx(getContext(), -181), 0);
holder.delete2.setVisibility(View.VISIBLE);
holder.delete3.setVisibility(View.VISIBLE);
holder.delete2.setBackgroundColor(getResources().getColor(R.color.back_gray));
holder.delete3.setBackgroundColor(getResources().getColor(R.color.unbind));
holder.tvDeviceStatus.setText(getResources().getString(R.string.refuse));
holder.delete3name.setText(getResources().getString(R.string.delete));
holder.delete2name.setText(getResources().getString(R.string.sharedagain));
holder.delete2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
GizDeviceSharing.sharingDevice(token, myid, GizDeviceSharingWay.GizDeviceSharingByNormal,
GosConstant.mydeviceSharingInfos.get(position).getUserInfo().getUid(),
GizUserAccountType.GizUserOther);
}
});
holder.delete3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
GizDeviceSharing.revokeDeviceSharing(token, id);
}
});
// tvDeviceStatus.setText(getResources().getString(R.string.timeout));
break;
case 3:
holder.rlmyhome.setPadding(0, 0, AssetsUtils.diptopx(getContext(), -181), 0);
holder.delete2.setVisibility(View.VISIBLE);
holder.delete3.setVisibility(View.VISIBLE);
holder.delete2.setBackgroundColor(getResources().getColor(R.color.back_gray));
holder.delete3.setBackgroundColor(getResources().getColor(R.color.unbind));
holder.tvDeviceStatus.setText(getResources().getString(R.string.cancelled));
holder.delete3name.setText(getResources().getString(R.string.delete));
holder.delete2name.setText(getResources().getString(R.string.sharedagain));
// delete2name.setGravity(Gravity.CENTER);
holder.delete2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
GizDeviceSharing.sharingDevice(token, myid, GizDeviceSharingWay.GizDeviceSharingByNormal,
GosConstant.mydeviceSharingInfos.get(position).getUserInfo().getUid(),
GizUserAccountType.GizUserOther);
}
});
holder.delete3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
GizDeviceSharing.revokeDeviceSharing(token, id);
}
});
break;
default:
break;
}
return convertView;
}
}
class ViewHolder {
TextView tvDeviceName;
TextView tvDeviceMac;
TextView tvDeviceStatus;
TextView delete2name;
TextView delete3name;
LinearLayout delete2;
LinearLayout delete3;
RelativeLayout rlmyhome;
}
protected void quitAlert(Context context, String username, final int uid2) {
final Dialog dialog = new AlertDialog.Builder(getActivity(), R.style.alert_dialog_style)
.setView(new EditText(getActivity())).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_quit);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
TextView view3 = (TextView) window.findViewById(R.id.textView3);
view3.setVisibility(View.VISIBLE);
TextView tv = (TextView) window.findViewById(R.id.tv_prompt);
String userstring = getResources().getString(R.string.deleteuserpremiss);
String[] split = userstring.split("xxx");
tv.setText(split[0] + username + split[1]);
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// GizDeviceSharing.unbindGuestUser(token, deviceID, uid2);
GizDeviceSharing.revokeDeviceSharing(token, uid2);
dialog.cancel();
}
});
}
}

@ -0,0 +1,275 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.api.GizUserInfo;
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.AssetsUtils;
import com.gizwits.opensource.appkit.utils.DateUtil;
import com.gizwits.opensource.appkit.view.SlideListView2;
public class SharedUserFragment extends Fragment {
// 定义俩个整形值用来区分当前要显示的是哪个view对象
// 如果是1的话就共享列表 2的话就是受邀列表
private int mytpye = -1;
private myadapter myadapter;
private String deviceID;
private String token;
private String uid;
private String productname;
private TextView shareddeviceproductname;
private SlideListView2 mListView;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:
if (GosConstant.mydeviceSharingInfos.size() == 0) {
String s = getResources().getString(R.string.have_not_been_shared);
String ss = s.substring(3, s.length());
StringBuilder sb = new StringBuilder(productname);
shareddeviceproductname.setText(sb.append(ss));
shareddeviceproductname.setVisibility(View.VISIBLE);
llSharedTo.setVisibility(View.GONE);
} else {
tvSharedTo.setText(productname + getResources().getString(R.string.sharedto));
llSharedTo.setVisibility(View.VISIBLE);
shareddeviceproductname.setVisibility(View.GONE);
}
myadapter = new myadapter();
mListView.setAdapter(myadapter);
break;
}
}
};
private TextView tvSharedTo;
private LinearLayout llSharedTo;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// 动态找到布局文件再从这个布局中find出TextView对象
View contextView = inflater.inflate(R.layout.activity_gos_shared_list, container, false);
mListView = (SlideListView2) contextView.findViewById(R.id.mysharedlist);
mListView.initSlideMode(SlideListView2.MOD_RIGHT);
shareddeviceproductname = (TextView) contextView.findViewById(R.id.shareddeviceproductname);
tvSharedTo = (TextView) contextView.findViewById(R.id.tvSharedTo);
llSharedTo = (LinearLayout) contextView.findViewById(R.id.llSharedTo);
Bundle arguments = getArguments();
productname = arguments.getString("productname");
initdata();
return contextView;
}
public myadapter getmyadapter() {
return myadapter;
}
private void initdata() {
SharedPreferences spf = getActivity().getSharedPreferences("set", Context.MODE_PRIVATE);
token = spf.getString("Token", "");
uid = spf.getString("Uid", "");
deviceID = getArguments().getString("deviceid");
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
// listview的adapter通过刷新的bound对象的属性值来判断当前应该现实的是什么
class myadapter extends BaseAdapter {
private String uid;
@Override
public int getCount() {
return GosConstant.mybindUsers.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(
R.layout.gos_shared_by_me_activity, null);
holder = new ViewHolder();
holder.rlmyhome = (RelativeLayout) convertView.findViewById(R.id.rlmyhome);
holder.tvDeviceName = (TextView) convertView.findViewById(R.id.tvDeviceName);
holder.tvDeviceMac = (TextView) convertView.findViewById(R.id.tvDeviceMac);
holder.tvDeviceStatus = (TextView) convertView.findViewById(R.id.tvDeviceStatus);
holder.delete2name = (TextView) convertView.findViewById(R.id.delete2name);
holder.delete3name = (TextView) convertView.findViewById(R.id.delete3name);
holder.delete2 = (LinearLayout) convertView.findViewById(R.id.delete2);
holder.delete3 = (LinearLayout) convertView.findViewById(R.id.delete3);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.rlmyhome.setPadding(0, 0, AssetsUtils.diptopx(getContext(), -90), 0);
holder.delete3.setVisibility(View.GONE);
holder.delete2name.setText(getResources().getString(R.string.cancel_sharing));
holder.delete2.setVisibility(View.VISIBLE);
holder.delete2name.setText(getResources().getString(R.string.cancel_sharing));
holder.tvDeviceStatus.setVisibility(View.GONE);
GizUserInfo userInfo = GosConstant.mybindUsers.get(position);
uid = userInfo.getUid();
String email = userInfo.getEmail();
String phone = userInfo.getPhone();
String username = userInfo.getUsername();
String remark = userInfo.getRemark();
String deviceBindTime = userInfo.getDeviceBindTime();
deviceBindTime = DateUtil.utc2Local(deviceBindTime);
holder.tvDeviceMac.setText(deviceBindTime);
if (!TextUtils.isEmpty(uid) && !uid.equals("null")) {
String myuid = uid.substring(0, 3) + "***" + uid.substring(uid.length() - 4, uid.length());
holder.tvDeviceName.setText(myuid);
}
if (!TextUtils.isEmpty(email) && !email.equals("null")) {
holder.tvDeviceName.setText(email);
}
if (!TextUtils.isEmpty(phone) && !phone.equals("null")) {
holder.tvDeviceName.setText(phone);
}
if (!TextUtils.isEmpty(username) && !username.equals("null")) {
holder.tvDeviceName.setText(username);
}
if (!TextUtils.isEmpty(remark) && !remark.equals("null")) {
holder.tvDeviceName.setText(remark);
}
final String s = holder.tvDeviceName.getText().toString();
holder.delete2name.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
quitAlert(getActivity(), s, GosConstant.mybindUsers.get(position).getUid());
}
});
return convertView;
}
}
class ViewHolder {
TextView tvDeviceName;
TextView tvDeviceMac;
TextView tvDeviceStatus;
TextView delete2name;
TextView delete3name;
LinearLayout delete2;
LinearLayout delete3;
RelativeLayout rlmyhome;
}
protected void quitAlert(Context context, String username, final String uid2) {
final Dialog dialog = new AlertDialog.Builder(getActivity(),R.style.alert_dialog_style)
.setView(new EditText(getActivity())).create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.alert_gos_quit);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
LinearLayout llNo, llSure;
llNo = (LinearLayout) window.findViewById(R.id.llNo);
llSure = (LinearLayout) window.findViewById(R.id.llSure);
TextView view3 = (TextView) window.findViewById(R.id.textView3);
view3.setVisibility(View.VISIBLE);
TextView tv = (TextView) window.findViewById(R.id.tv_prompt);
String userstring = getResources().getString(R.string.deleteuserpremiss);
String[] split = userstring.split("xxx");
tv.setText(split[0] + username + split[1]);
llNo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
llSure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
GizDeviceSharing.unbindUser(token, deviceID, uid2);
dialog.cancel();
}
});
}
}

@ -0,0 +1,88 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.R;
public class addSharedActivity extends GosBaseActivity {
private String productname;
private String did;
private LinearLayout devicetwoshared;
private LinearLayout usershared;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_addshared);
setToolBar(true, R.string.addshared);
initData();
initView();
}
private void initView() {
usershared = (LinearLayout) findViewById(R.id.usershared);
devicetwoshared = (LinearLayout) findViewById(R.id.devicetwoshared);
}
private void initData() {
Intent tent = getIntent();
productname = tent.getStringExtra("productname");
did = tent.getStringExtra("did");
}
// personalCenter_deviceSharing_qrcode-false-start
// 二维码分享
public void devicetwoshared(View v) {
Intent tent = new Intent(this, twoSharedActivity.class);
tent.putExtra("productname", productname);
tent.putExtra("did", did);
startActivity(tent);
devicetwoshared.setEnabled(false);
devicetwoshared.postDelayed(new Runnable() {
@Override
public void run() {
devicetwoshared.setEnabled(true);
}
}, 1000);
}
//personalCenter_deviceSharing_qrcode-false-end
// 用户账号分享
public void usershared(View v) {
Intent tent = new Intent(this, userSharedActivity.class);
tent.putExtra("productname", productname);
tent.putExtra("did", did);
startActivity(tent);
usershared.setEnabled(false);
usershared.postDelayed(new Runnable() {
@Override
public void run() {
usershared.setEnabled(true);
}
}, 1000);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
break;
}
return super.onOptionsItemSelected(item);
}
}

@ -0,0 +1,276 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.api.GizMessage;
import com.gizwits.gizwifisdk.enumration.GizMessageStatus;
import com.gizwits.gizwifisdk.enumration.GizMessageType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.DateUtil;
import com.gizwits.opensource.appkit.view.SlideListView2;
import com.gizwits.opensource.appkit.view.VerticalSwipeRefreshLayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class deviceSharedMessageActivity extends GosBaseActivity implements SwipeRefreshLayout.OnRefreshListener {
private List<GizMessage> mymessageList = new ArrayList<GizMessage>();
private myadapter myadapter;
private String token;
private String myid = "";
private int myposition = -1;
// 删除时需要用到的对话框
private ProgressDialog progressDialog;
private TextView tvNoMessage;
private VerticalSwipeRefreshLayout mSwipeLayout;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:
mSwipeLayout.setRefreshing(false);
GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSharing);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_device_shared_message_list);
setToolBar(true, R.string.devicesharedmess);
initView();
initData();
initProgressBar();
}
private void initProgressBar() {
progressDialog = new ProgressDialog(this);
String loadingText = getString(R.string.loadingtext);
progressDialog.setMessage(loadingText);
progressDialog.setCanceledOnTouchOutside(false);
}
// 初始化分享设备的数据
private void initData() {
//
// GizDeviceSharing.setListener(new GizDeviceSharingListener() {
//
// @Override
// public void didQueryMessageList(GizWifiErrorCode result,
// List<GizMessage> messageList) {
// super.didQueryMessageList(result, messageList);
//
// mymessageList = messageList;
// myadapter.notifyDataSetChanged();
// }
//
// });
token = spf.getString("Token", "");
GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSharing);
// GizDeviceSharing.queryMessageList(token,
// GizMessageType.GizMessageSystem);
}
private void initView() {
SlideListView2 devicelist = (SlideListView2) findViewById(R.id.devicelist);
tvNoMessage = (TextView) findViewById(R.id.tvNoMessage);
devicelist.initSlideMode(SlideListView2.MOD_RIGHT);
myadapter = new myadapter();
devicelist.setAdapter(myadapter);
// 下拉刷新
mSwipeLayout = (VerticalSwipeRefreshLayout) findViewById(R.id.id_swipe_ly);
mSwipeLayout.setOnRefreshListener(this);
mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
android.R.color.holo_orange_light, android.R.color.holo_red_light);
devicelist.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
View redpoint = arg1.findViewById(R.id.redpoint);
if (redpoint.getVisibility() == 0) {
redpoint.setVisibility(View.GONE);
GizMessage gizMessage = mymessageList.get(arg2);
GizDeviceSharing.markMessageStatus(token, gizMessage.getId(), GizMessageStatus.GizMessageRead);
}
}
});
}
@Override
public void onRefresh() {
Message msg = new Message();
msg.what = 1;
handler.sendMessageDelayed(msg, 2000);
}
class myadapter extends BaseAdapter {
@Override
public int getCount() {
return mymessageList.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(final int arg0, View arg1, ViewGroup arg2) {
View view = View.inflate(deviceSharedMessageActivity.this, R.layout.activity_device_item, null);
TextView mess = (TextView) view.findViewById(R.id.mess);
TextView timemess = (TextView) view.findViewById(R.id.timemess);
View redpoint = view.findViewById(R.id.redpoint);
RelativeLayout delete2 = (RelativeLayout) view.findViewById(R.id.delete2);
delete2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View c) {
GizMessage gizMessage = mymessageList.get(arg0);
String id = gizMessage.getId();
myid = id;
myposition = arg0;
GizDeviceSharing.markMessageStatus(token, gizMessage.getId(), GizMessageStatus.GizMessageDeleted);
progressDialog.show();
}
});
GizMessage gizMessage = mymessageList.get(arg0);
mess.setText(gizMessage.getContent());
timemess.setText(DateUtil.utc2Local(gizMessage.getUpdatedAt()));
int ordinal = gizMessage.getStatus().ordinal();
if (ordinal == 0) {
redpoint.setVisibility(View.VISIBLE);
} else {
redpoint.setVisibility(View.GONE);
}
return view;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
super.onResume();
//GizDeviceSharing.queryMessageList
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
@Override
public void didMarkMessageStatus(GizWifiErrorCode result, String messageID) {
super.didMarkMessageStatus(result, messageID);
if (result.ordinal() == 0 && myid.equals(messageID)) {
if (mymessageList.size() > myposition && myposition != -1) {
GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSharing);
}
} else {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.cancel();
}
}
}
@Override
public void didQueryMessageList(GizWifiErrorCode result, List<GizMessage> messageList) {
super.didQueryMessageList(result, messageList);
if (messageList != null) {
Collections.sort(messageList, new Comparator<GizMessage>() {
@Override
public int compare(GizMessage arg0, GizMessage arg1) {
String updatedAt = DateUtil.utc2Local(arg0.getUpdatedAt());
String updatedAt2 = DateUtil.utc2Local(arg1.getUpdatedAt());
int diff = (int) DateUtil.getDiff(updatedAt2, updatedAt);
return diff;
}
});
}
if (progressDialog.isShowing()) {
progressDialog.cancel();
}
mymessageList = messageList;
if (mymessageList.size() != 0) {
tvNoMessage.setVisibility(View.GONE);
}
myadapter.notifyDataSetChanged();
}
});
}
}

@ -0,0 +1,235 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.R;
import com.gizwits.opensource.appkit.utils.DateUtil;
public class gosZxingDeviceSharingActivity extends GosBaseActivity {
private String code;
private int time = 15;
private String[] split2s;
private String tip;
private TextView tiptext;
private String token;
private Button yes;
private Button no;
private TextView zxingtext;
private String whoshared;
private String[] splits;
private String userName;
private String productName;
private String deviceAlias;
private String expiredAt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gos_devicesharing_zxing_activity);
setToolBar(true, R.string.QR_code);
initData();
initView();
}
private void initView() {
zxingtext = (TextView) findViewById(R.id.zxingtext);
yes = (Button) findViewById(R.id.yes);
no = (Button) findViewById(R.id.no);
whoshared = getResources().getString(R.string.whoshared);
splits = whoshared.split("xxx");
// [, 向你共享, ,你接受并绑定设备吗?]
whoshared = userName + splits[1] + productName + splits[splits.length - 1];
zxingtext.setText(whoshared);
String timeByFormat = DateUtil.getCurTimeByFormat("yyyy-MM-dd HH:mm:ss");
expiredAt = DateUtil.utc2Local(expiredAt);
long diff = DateUtil.getDiff(expiredAt, timeByFormat);
if (diff >= 0) {
double c = diff / 60.0;
time = (int) Math.ceil(c);
} else {
tiptext.setText(getResources().getString(R.string.requestoutoftime));
yes.setClickable(false);
yes.setTextColor(getResources().getColor(R.color.gray));
return;
}
tiptext = (TextView) findViewById(R.id.tiptext);
tip = getResources().getString(R.string.tipthings);
split2s = tip.split("xx");
tip = split2s[0] + time + split2s[1];
tiptext.setText(tip);
hand.sendEmptyMessageDelayed(1, diff % 60 * 1000);
yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GizDeviceSharing.acceptDeviceSharingByQRCode(spf.getString("Token", ""), code);
}
});
no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
private void initData() {
Intent intent = getIntent();
code = intent.getStringExtra("code");
userName = intent.getStringExtra("userName");
productName = intent.getStringExtra("productName");
deviceAlias = intent.getStringExtra("deviceAlias");
expiredAt = intent.getStringExtra("expiredAt");
token = spf.getString("Token", "");
}
@Override
protected void onResume() {
super.onResume();
if (time > 0) {
tip = split2s[0] + time + split2s[1];
tiptext.setText(tip);
} else {
tiptext.setText(getResources().getString(R.string.requestoutoftime));
yes.setClickable(false);
yes.setTextColor(getResources().getColor(R.color.gray));
}
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
@Override
public void didAcceptDeviceSharing(GizWifiErrorCode result, int sharingID) {
super.didAcceptDeviceSharing(result, sharingID);
if (result.ordinal() == 0) {
finish();
} else {
Toast.makeText(gosZxingDeviceSharingActivity.this, toastError(result), 1).show();
finish();
}
}
@Override
public void didAcceptDeviceSharingByQRCode(GizWifiErrorCode result) {
super.didAcceptDeviceSharingByQRCode(result);
if (result.ordinal() == 0) {
Toast.makeText(gosZxingDeviceSharingActivity.this, "success", 1).show();
finish();
} else {
Toast.makeText(gosZxingDeviceSharingActivity.this, toastError(result), 1).show();
finish();
}
}
@Override
public void didCheckDeviceSharingInfoByQRCode(GizWifiErrorCode result, String userName, String productName,
String deviceAlias, String expiredAt) {
super.didCheckDeviceSharingInfoByQRCode(result, userName, productName, deviceAlias, expiredAt);
int errorcode = result.ordinal();
if (8041 <= errorcode && errorcode <= 8050 || errorcode == 8308) {
tiptext.setVisibility(View.GONE);
yes.setClickable(false);
no.setClickable(false);
yes.setTextColor(getResources().getColor(R.color.gray));
no.setTextColor(getResources().getColor(R.color.gray));
zxingtext.setText(getResources().getString(R.string.sorry));
} else if (errorcode != 0) {
tiptext.setVisibility(View.GONE);
yes.setClickable(false);
no.setClickable(false);
yes.setTextColor(getResources().getColor(R.color.gray));
no.setTextColor(getResources().getColor(R.color.gray));
zxingtext.setText(getResources().getString(R.string.verysorry));
} else {
tiptext.setVisibility(View.VISIBLE);
yes.setClickable(true);
no.setClickable(true);
yes.setTextColor(getResources().getColor(R.color.text_color));
no.setTextColor(getResources().getColor(R.color.text_color));
whoshared = userName + splits[1] + productName + splits[splits.length - 1];
zxingtext.setText(whoshared);
String timeByFormat = DateUtil.getCurTimeByFormat("yyyy-MM-dd HH:mm:ss");
expiredAt = DateUtil.utc2Local(expiredAt);
long diff = DateUtil.getDiff(expiredAt, timeByFormat);
if (diff >= 0) {
time = (int) Math.ceil(diff / 60);
} else {
}
Toast.makeText(gosZxingDeviceSharingActivity.this, diff % 60 + "", 1).show();
}
}
});
}
Handler hand = new Handler() {
public void handleMessage(android.os.Message msg) {
time = time - 1;
if (time > 0) {
tip = split2s[0] + time + split2s[1];
tiptext.setText(tip);
hand.sendEmptyMessageDelayed(1, 60000);
} else {
tiptext.setText(getResources().getString(R.string.requestoutoftime));
yes.setClickable(false);
yes.setTextColor(getResources().getColor(R.color.gray));
}
}
;
};
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
break;
}
return super.onOptionsItemSelected(item);
}
}

@ -0,0 +1,175 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingWay;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.R;
import java.util.Timer;
import java.util.TimerTask;
public class twoSharedActivity extends GosBaseActivity {
private String productname;
private String did;
private ImageView myimage;
private TextView timeout;
private TextView bottomtext;
private int time = 15;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_two_shared);
setToolBar(true, R.string.scan_code_sharing);
initData();
initView();
}
private void initView() {
TextView usersharedtext = (TextView) findViewById(R.id.usersharedtext);
myimage = (ImageView) findViewById(R.id.myimageview);
timeout = (TextView) findViewById(R.id.timeout);
timeout2 = splits[0] + time + splits[1];
timeout.setText(timeout2);
bottomtext = (TextView) findViewById(R.id.bottomtext);
usersharedtext.setText(getResources().getString(R.string.shared) + " " + productname
+ getResources().getString(R.string.friends));
}
private void initData() {
Intent tent = getIntent();
productname = tent.getStringExtra("productname");
did = tent.getStringExtra("did");
timeout2 = getResources().getString(R.string.zxingtimeout);
splits = timeout2.split("15");
GizDeviceSharing.sharingDevice(spf.getString("Token", ""), did, GizDeviceSharingWay.GizDeviceSharingByQRCode,
null, null);
}
private void startTimer() {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
time = time - 1;
hand.sendEmptyMessage(1);
}
}, 60000, 60000);
}
@Override
protected void onResume() {
super.onResume();
if (time > 0) {
timeout2 = splits[0] + time + splits[1];
timeout.setText(timeout2);
} else {
timeout.setText(getResources().getString(R.string.twofailed));
}
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
@Override
public void didSharingDevice(GizWifiErrorCode result, String deviceID, int sharingID,
Bitmap QRCodeImage) {
super.didSharingDevice(result, deviceID, sharingID, QRCodeImage);
if (QRCodeImage != null) {
myimage.setImageBitmap(QRCodeImage);
bottomtext.setVisibility(View.VISIBLE);
// hand.sendEmptyMessageDelayed(1, 60000);
startTimer();
} else {
int errorcode = result.ordinal();
if (8041 <= errorcode && errorcode <= 8050 || errorcode == 8308) {
timeout.setText(getResources().getString(R.string.twosharedtimeout));
bottomtext.setVisibility(View.GONE);
} else {
timeout.setText(getResources().getString(R.string.sharedfailed));
bottomtext.setVisibility(View.GONE);
}
}
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
Handler hand = new Handler() {
public void handleMessage(android.os.Message msg) {
// time = time - 1;
if (time > 0) {
timeout2 = splits[0] + time + splits[1];
timeout.setText(timeout2);
// hand.sendEmptyMessageDelayed(1, 60000);
} else {
timeout.setText(getResources().getString(R.string.twofailed));
}
};
};
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
time = 15;
hand.removeMessages(1);
if (timer != null) {
timer.cancel();
}
}
private String timeout2;
private String[] splits;
private Timer timer;
}

@ -0,0 +1,145 @@
package com.gizwits.opensource.appkit.sharingdevice;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingWay;
import com.gizwits.gizwifisdk.enumration.GizUserAccountType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.CommonModule.TipsDialog;
import com.gizwits.opensource.appkit.R;
public class userSharedActivity extends GosBaseActivity {
private String productname;
private EditText username;
private int chooseitem = 0;
private String did;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gos_user_shared);
setToolBar(true, R.string.account_shared);
initData();
initView();
}
private void initView() {
TextView usersharedtext = (TextView) findViewById(R.id.usersharedtext);
Button button = (Button) findViewById(R.id.button);
button.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
button.setTextColor(GosDeploy.appConfig_Contrast());
username = (EditText) findViewById(R.id.username);
usersharedtext.setText(
getResources().getString(R.string.shared) + productname + getResources().getString(R.string.friends));
}
private void initData() {
Intent tent = getIntent();
productname = tent.getStringExtra("productname");
did = tent.getStringExtra("did");
}
public void usershared(View v) {
final String usernametext = username.getText().toString();
if (TextUtils.isEmpty(usernametext)) {
// Toast.makeText(this,
// getResources().getString(R.string.toast_name_empet), 0).show();
TipsDialog dia = new TipsDialog(this, getResources().getString(R.string.toast_name_empet));
dia.show();
return;
}
SharedPreferences spf = getSharedPreferences("set", Context.MODE_PRIVATE);
String token = spf.getString("Token", "");
if (usernametext.length() < 32) {
if (usernametext.matches("[0-9]+")) {
GizDeviceSharing.sharingDevice(token, did, GizDeviceSharingWay.GizDeviceSharingByNormal, usernametext,
GizUserAccountType.GizUserPhone);
return;
}
}
if (usernametext.contains("@")) {
GizDeviceSharing.sharingDevice(token, did, GizDeviceSharingWay.GizDeviceSharingByNormal, usernametext,
GizUserAccountType.GizUserEmail);
return;
}
if (usernametext.length() == 32) {
if (usernametext.matches("[a-zA-Z0-9]+")) {
GizDeviceSharing.sharingDevice(token, did, GizDeviceSharingWay.GizDeviceSharingByNormal, usernametext,
GizUserAccountType.GizUserOther);
return;
}
}
Toast.makeText(this, getString(R.string.account_incorrect), Toast.LENGTH_LONG).show();
}
@Override
protected void onResume() {
super.onResume();
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
@Override
public void didSharingDevice(GizWifiErrorCode result, String deviceID, int sharingID,
Bitmap QRCodeImage) {
super.didSharingDevice(result, deviceID, sharingID, QRCodeImage);
if (result.ordinal() == 0) {
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.alawyssend), 1).show();
finish();
} else if (result == GizWifiErrorCode.GIZ_OPENAPI_GUEST_ALREADY_BOUND) {
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.account_shared2), toastTime).show();
} else if (result == GizWifiErrorCode.GIZ_OPENAPI_NOT_FOUND_GUEST) {
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.user_not_exist), toastTime).show();
} else if (result == GizWifiErrorCode.GIZ_OPENAPI_CANNOT_SHARE_TO_SELF) {
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.not_shared_self), toastTime).show();
} else {
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.send_failed1), 2).show();
}
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}

@ -0,0 +1,111 @@
package com.gizwits.opensource.appkit.utils;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Locale;
public class AssetsUtils {
public static void assetsDataToSD(String fileOutPutName,
String fileInPutName, Context context) throws IOException {
InputStream myInput;
File file = new File(fileOutPutName);
if (!file.exists()) {
file.createNewFile();
}else {
return;
}
OutputStream myOutput = new FileOutputStream(fileOutPutName);
myInput = context.getAssets().open(fileInPutName);
byte[] buffer = new byte[1024];
int length = myInput.read(buffer);
while (length > 0) {
myOutput.write(buffer, 0, length);
length = myInput.read(buffer);
}
myOutput.flush();
myInput.close();
myOutput.close();
}
public static void saveFile(String str) {
String filePath = null;
filePath = GosDeploy.fileOutName;
try {
if(filePath!=null){
File file = new File(filePath);
if (!file.exists()) {
File dir = new File(file.getParent());
dir.mkdirs();
file.createNewFile();
}
FileOutputStream outStream = new FileOutputStream(file);
outStream.write(str.getBytes());
outStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* dipdppx
*
* @param dipValue
* @param scale
* DisplayMetricsdensity
* @return
*/
public static int diptopx(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
/**
* sppx
*
* @param spValue
* @param fontScale
* DisplayMetricsscaledDensity
* @return
*/
public static int sptopx(Context context, float spValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * fontScale + 0.5f);
}
public static boolean isZh(Context context) {
Locale locale = context.getResources().getConfiguration().locale;
String language = locale.getLanguage();
if (language.endsWith("zh"))
return true;
else
return false;
}
public static int getScreenWidth(Context context)
{
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE );
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics( outMetrics);
return outMetrics .widthPixels ;
}
}

@ -0,0 +1,58 @@
package com.gizwits.opensource.appkit.utils;
import java.util.Locale;
public class HexStrUtils {
public static byte[] hexStringToBytes(String hexString) {
if (hexString == null || hexString.equals("")) {
return null;
}
hexString = hexString.toUpperCase(Locale.getDefault());
int length = hexString.length() / 2;
char[] hexChars = hexString.toCharArray();
byte[] d = new byte[length];
for (int i = 0; i < length; i++) {
int pos = i * 2;
d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
}
return d;
}
private static byte charToByte(char c) {
return (byte) "0123456789ABCDEF".indexOf(c);
}
/**
*
*
* @param byte[]
* @return HexString
*/
public static final String bytesToHexString(byte[] bArray) {
if (bArray == null) {
return "";
}
StringBuffer sb = new StringBuffer(bArray.length);
String sTemp;
for (int i = 0; i < bArray.length; i++) {
sTemp = Integer.toHexString(0xFF & bArray[i]);
if (sTemp.length() < 2)
sb.append(0);
sb.append(sTemp.toUpperCase(Locale.getDefault()));
}
return sb.toString();
}
public static final String splitBytesString(String byteString) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < byteString.length(); i++) {
sb.append(byteString.charAt(i));
if (sb.length() % 3 == 0 && sb.charAt(sb.length() - 1) != ' ') {
sb.insert(sb.length() - 1, ' ');
}
}
return sb.toString();
}
}

@ -0,0 +1,226 @@
/**
* Project Name:Gokit
* File Name:NetUtils.java
* Package Name:com.xpg.gokit.utils
* Date:2014-11-18 10:06:37
* Copyright (c) 2014~2015 Xtreme Programming Group, Inc.
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.gizwits.opensource.appkit.utils;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
import android.util.Log;
import java.util.List;
/**
* .
*
* @author Sunny Ding
*
* *
*/
public class NetUtils {
/**
* Wifi.
*
* @param context
*
* @return boolean
*
* *
*/
static public boolean isWifiConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWiFiNetworkInfo != null) {
if (mWiFiNetworkInfo.isAvailable()) {
return mWiFiNetworkInfo.isConnected();
} else {
return false;
}
}
}
return false;
}
/**
* .
*
* @param context
*
* @return boolean
*
* *
*/
static public boolean isMobileConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (mMobileNetworkInfo != null) {
if (mMobileNetworkInfo.isAvailable()) {
return mMobileNetworkInfo.isConnected();
} else {
return false;
}
}
}
return false;
}
/**
* WIFI.
*
* @param context
*
* @return ConnectedType
*
* *
*/
public static int getConnectedType(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
// 获取代表联网状态的NetWorkInfo对象
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
// 判断NetWorkInfo对象是否为空判断当前的网络连接是否可用
if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
return mNetworkInfo.getType();
}
}
return -1;
}
/**
* WIFISSID.
*
* @param context
*
* @return ssid
*
* *
*/
public static String getCurentWifiSSID(Context context) {
String ssid = "";
if (context != null) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
ssid = wifiInfo.getSSID();
if (!TextUtils.isEmpty(ssid) && ssid.substring(0, 1).equals("\"")
&& ssid.substring(ssid.length() - 1).equals("\"")) {
ssid = ssid.substring(1, ssid.length() - 1);
}
}
}
return ssid;
}
/**
* wifi.
*
* @param c
*
* @return the current wifi scan result
*/
public static List<ScanResult> getCurrentWifiScanResult(Context c) {
WifiManager wifiManager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
wifiManager.startScan();
return wifiManager.getScanResults();
}
public interface WifiSsidList {
public void ssidList(List<ScanResult> list);
}
static public String getConnectWifiSsid(Context c) {
String ssid = "";
WifiManager wifiManager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
ssid = wifiInfo.getSSID();
}
return ssid;
}
// 以下是获得版本信息的工具方法
// 版本名
public static String getVersionName(Context context) {
return getPackageInfo(context).versionName;
}
// 版本号
public static int getVersionCode(Context context) {
return getPackageInfo(context).versionCode;
}
private static PackageInfo getPackageInfo(Context context) {
PackageInfo pi = null;
try {
PackageManager pm = context.getPackageManager();
pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_CONFIGURATIONS);
return pi;
} catch (Exception e) {
e.printStackTrace();
}
return pi;
}
// 检测android 应用在前台还是后台
public static boolean isBackground(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
for (RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.processName.equals(context.getPackageName())) {
/*
* BACKGROUND=400 EMPTY=500 FOREGROUND=100 GONE=1000
* PERCEPTIBLE=130 SERVICE=300 ISIBLE=200
*/
Log.i(context.getPackageName(), "此appimportace =" + appProcess.importance
+ ",context.getClass().getName()=" + context.getClass().getName());
if (appProcess.importance != RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
Log.i(context.getPackageName(), "处于后台" + appProcess.processName);
return true;
} else {
Log.i(context.getPackageName(), "处于前台" + appProcess.processName);
return false;
}
}
}
return false;
}
}

@ -0,0 +1,138 @@
package com.gizwits.opensource.appkit.utils;
import android.text.TextUtils;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Created by zhaopan on 2016/11/7.
* e-mail: kangqiao610@gmail.com
*/
public class ReflectionUtils {
/**
* , DeclaredMethod
*
* @param object :
* @param methodName :
* @param parameterTypes :
* @return
*/
public static Method getDeclaredMethod(Object object, String methodName, Class<?>... parameterTypes) {
Method method = null;
for (Class<?> clazz = object.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
try {
method = clazz.getDeclaredMethod(methodName, parameterTypes);
return method;
} catch (Exception e) {
//这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
//如果这里的异常打印或者往外抛则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
}
}
return null;
}
/**
* , (private, protected, default)
*
* @param object :
* @param methodName :
* @param parameterTypes :
* @param parameters :
* @return
*/
public static Object invokeMethod(Object object, String methodName, Class<?>[] parameterTypes,
Object[] parameters) {
//根据 对象、方法名和对应的方法参数 通过反射 调用上面的方法获取 Method 对象
Method method = getDeclaredMethod(object, methodName, parameterTypes);
//抑制Java对方法进行检查,主要是针对私有方法而言
method.setAccessible(true);
try {
if (null != method) {
//调用object 的 method 所代表的方法,其方法的参数是 parameters
return method.invoke(object, parameters);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
/**
* , DeclaredField
*
* @param object :
* @param fieldName :
* @return
*/
public static Field getDeclaredField(Object object, String fieldName) {
Field field = null;
Class<?> clazz = object.getClass();
for (; clazz != Object.class; clazz = clazz.getSuperclass()) {
try {
field = clazz.getDeclaredField(fieldName);
return field;
} catch (Exception e) {
//这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
//如果这里的异常打印或者往外抛则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
}
}
return null;
}
public static Object getFieldValue(Object obj, String fieldName) {
if (obj == null || TextUtils.isEmpty(fieldName)) {
return null;
}
Class<?> clazz = obj.getClass();
while (clazz != Object.class) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
return field.get(obj);
} catch (Exception e) {
}
clazz = clazz.getSuperclass();
}
return null;
}
public static void setFieldValue(Object obj, String fieldName, Object value) {
if (obj == null || TextUtils.isEmpty(fieldName)) {
return;
}
Class<?> clazz = obj.getClass();
while (clazz != Object.class) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(obj, value);
return;
} catch (Exception e) {
}
clazz = clazz.getSuperclass();
}
}
}

@ -0,0 +1,66 @@
package com.gizwits.opensource.appkit.utils;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.drawable.DrawableCompat;
public class SkxDrawableHelper {
/**
* Drawable
*
* @param drawable Drawable
* @param color
* @return Drawable
*/
public static Drawable tintDrawable(Drawable drawable, int color) {
// 获取此drawable的共享状态实例
Drawable wrappedDrawable = getCanTintDrawable(drawable);
// 进行着色
DrawableCompat.setTint(wrappedDrawable, color);
return wrappedDrawable;
}
/**
* Drawable
* ColorStateList
*
* @param drawable Drawable
* @param color
* @return Drawable
*/
public static Drawable tintListDrawable(Drawable drawable, int color) {
return tintListDrawable(drawable, ColorStateList.valueOf(color));
}
/**
* Drawable
*
* @param drawable Drawable
* @param colors
* @return Drawable
*/
public static Drawable tintListDrawable( Drawable drawable, ColorStateList colors) {
Drawable wrappedDrawable = getCanTintDrawable(drawable);
// 进行着色
DrawableCompat.setTintList(wrappedDrawable, colors);
return wrappedDrawable;
}
/**
* tint Drawable
* <p>
* drawable newDrawable()
* warp()
* mutate()
*
* @param drawable drawable
* @return drawable
*/
private static Drawable getCanTintDrawable(Drawable drawable) {
// 获取此drawable的共享状态实例
Drawable.ConstantState state = drawable.getConstantState();
// 对drawable 进行重新实例化、包装、可变操作
return DrawableCompat.wrap(state == null ? drawable : state.newDrawable()).mutate();
}
}

@ -0,0 +1,146 @@
package com.gizwits.opensource.appkit.utils;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.widget.Toast;
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
import com.gizwits.opensource.appkit.R;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by admin on 2017/7/25.
*/
public class ToolUtils {
public static float getHue(int color) {
float[] HSV = new float[3];
Color.colorToHSV(color, HSV);
return (HSV[0] * 255 / 360);
}
public static int getInnerColor(float hue) {
float[] HSV = new float[3];
HSV[0] = hue * 360 / 255;
HSV[1] = 255;
HSV[2] = 255;
return Color.HSVToColor(HSV);
}
private static long lastClickTime = 0;
public static final int MIN_CLICK_DELAY_TIME = 800;
public static boolean noDoubleClick() {
long currentTime = Calendar.getInstance().getTimeInMillis();
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
lastClickTime = currentTime;
return true;
} else {
return false;
}
}
public static List<Map<String, Object>> parseJson(Context context, String str) throws JSONException {
if (str == null || str.equals("")) {
Toast.makeText(context, context.getString(R.string.download_fail), Toast.LENGTH_SHORT).show();
}
JSONObject uiJsonObject = new JSONObject(str);
JSONObject jsonObject = uiJsonObject.has("object") ? uiJsonObject.getJSONObject("object") : null;
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
if (uiJsonObject != null) {
JSONArray sessionJsonArrays = uiJsonObject.getJSONArray("sections");
if (sessionJsonArrays != null) {
for (int i = 0; i < sessionJsonArrays.length(); i++) {
JSONObject session = sessionJsonArrays.getJSONObject(i);
JSONArray elementjJsonArray = session.getJSONArray("elements");
if (elementjJsonArray != null) {
for (int j = 0; j < elementjJsonArray.length(); j++) {
Map<String, Object> map = new HashMap<String, Object>();
JSONObject elementObject = elementjJsonArray.getJSONObject(j);
String type = elementObject.getString("type");
String title = elementObject.has("title") ? elementObject.getString("title") : "";
map.put("title", title);
map.put("type", type);
String value = null;
if (type.equals("QBooleanElement")) {
value = elementObject.has("boolValue") ? elementObject.getString("boolValue") : "";
} else if (type.equals("QFloatElement")) {
value = elementObject.has("value") ? elementObject.getString("value") : "";
}
map.put("value", value);
list.add(map);
}
}
}
}
}
return list;
}
public static Drawable editIconAlpha(Resources res, int id) {
int color = GosDeploy.appConfig_Contrast();
Drawable drawable = SkxDrawableHelper.tintDrawable(res.getDrawable(id), color);
drawable.setAlpha(60);
return drawable;
}
public static Drawable editIcon(Resources res, int id) {
int color = GosDeploy.appConfig_Contrast();
return SkxDrawableHelper.tintDrawable(res.getDrawable(id), color);
}
public static int editTextAlpha() {
int color = GosDeploy.appConfig_Contrast();
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
int color1 = Color.argb(160, red, green, blue);
return color1;
}
public static int editStatusBarColor(int color) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
int color1 = Color.argb(255, red, green, blue);
return color1;
}
// // 需要点击几次 就设置几
// static long[] mHits = null;
// //public static boolean mShow = false;
//
// public static void onDisplaySettingButton() {
// if (mHits == null) {
// mHits = new long[5];
// }
// System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);//把从第二位至最后一位之间的数字复制到第一位至倒数第一位
// mHits[mHits.length - 1] = SystemClock.uptimeMillis();//记录一个时间
// if (SystemClock.uptimeMillis() - mHits[0] <= 1000) {//一秒内连续点击。
// mHits = null; //这里说明一下,我们在进来以后需要还原状态,否则如果点击过快,第六次,第七次 都会不断进来触发该效果。重新开始计数即可
//// if (mShow) {
//// mShow = false;
//// } else {
//// mShow = true;
//// }
// mShow = true;
// Log.e("Tool", "onDisplaySettingButton: 连点五次进入deploy模式");
// //这里一般会把mShow存储到sp中。
// }
// }
}

@ -0,0 +1,210 @@
package com.gizwits.opensource.appkit.view;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.text.Editable;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.widget.EditText;
/**
* Created by xud on 2017/3/2.
*/
public abstract class BaseKeyboard extends Keyboard implements KeyboardView.OnKeyboardActionListener {
private EditText mEditText;
private View mNextFocusView;
private KeyStyle mKeyStyle;
protected Context mContext;
public BaseKeyboard(Context context, int xmlLayoutResId) {
super(context, xmlLayoutResId);
mContext = context;
}
public BaseKeyboard(Context context, int xmlLayoutResId, int modeId, int width, int height) {
super(context, xmlLayoutResId, modeId, width, height);
mContext = context;
}
public BaseKeyboard(Context context, int xmlLayoutResId, int modeId) {
super(context, xmlLayoutResId, modeId);
mContext = context;
}
public BaseKeyboard(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding) {
super(context, layoutTemplateResId, characters, columns, horizontalPadding);
mContext = context;
}
public void setEditText(EditText editText) {
mEditText = editText;
}
public void setNextFocusView(View nextFocusView) {
mNextFocusView = nextFocusView;
}
public void setKeyStyle(KeyStyle keyStyle) {
mKeyStyle = keyStyle;
}
public EditText getEditText() {
return mEditText;
}
public View getNextFocusView() {
return mNextFocusView;
}
public KeyStyle getKeyStyle() {
return mKeyStyle;
}
public int getKeyCode( int redId) {
return mContext.getResources().getInteger(redId);
}
@Override
public void onPress(int primaryCode) {
}
@Override
public void onRelease(int primaryCode) {
}
@Override
public void onKey(int primaryCode, int[] keyCodes) {
if (null != mEditText && mEditText.hasFocus() && !handleSpecialKey(primaryCode)) {
Editable editable = mEditText.getText();
int start = mEditText.getSelectionStart();
int end = mEditText.getSelectionEnd();
if (end > start) {
editable.delete(start, end);
}
if (primaryCode == KEYCODE_DELETE) {
if (!TextUtils.isEmpty(editable)) {
if (start > 0) {
editable.delete(start - 1, start);
}
}
} else if (primaryCode == KEYCODE_CANCEL) {
hideKeyboard();
} else {
editable.insert(start, Character.toString((char) primaryCode));
}
}
}
@Override
public void onText(CharSequence text) {
}
@Override
public void swipeLeft() {
}
@Override
public void swipeRight() {
}
@Override
public void swipeDown() {
}
@Override
public void swipeUp() {
}
public void hideKeyboard() {
if (mNextFocusView != null) {
mNextFocusView.requestFocus();
}
}
/**
* @param primaryCode
* @return true if handle the key
* false no handle and dispatch
*/
public abstract boolean handleSpecialKey(int primaryCode);
public interface KeyStyle {
public Drawable getKeyBackound(Key key);
public Float getKeyTextSize(Key key);
public Integer getKeyTextColor(Key key);
public CharSequence getKeyLabel(Key key);
}
public Padding getPadding() {
return new Padding(0, 0, 0, 0);
}
public static class DefaultKeyStyle implements KeyStyle {
@Override
public Drawable getKeyBackound(Key key) {
return key.iconPreview;
}
@Override
public Float getKeyTextSize(Key key) {
return null;
}
@Override
public Integer getKeyTextColor(Key key) {
return null;
}
@Override
public CharSequence getKeyLabel(Key key) {
return key.label;
}
}
public static class Padding {
public int top;
public int left;
public int bottom;
public int right;
/**
* px
*
* @param top
* @param left
* @param bottom
* @param right
*/
public Padding(int top, int left, int bottom, int right) {
this.top = top;
this.left = left;
this.bottom = bottom;
this.right = right;
}
}
public float convertSpToPixels(Context context, float sp) {
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics());
return px;
}
}

@ -0,0 +1,202 @@
package com.gizwits.opensource.appkit.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.EditText;
import com.gizwits.opensource.appkit.utils.ReflectionUtils;
import java.util.List;
/**
* Created by xud on 2017/3/2.
*/
public class BaseKeyboardView extends KeyboardView {
private static final String TAG = "BaseKeyboardView";
private Drawable rKeyBackground;
private int rLabelTextSize;
private int rKeyTextSize;
private int rKeyTextColor;
private float rShadowRadius;
private int rShadowColor;
private Rect rClipRegion;
private Keyboard.Key rInvalidatedKey;
public BaseKeyboardView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0, 0);
}
public BaseKeyboardView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr, 0);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public BaseKeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs, defStyleAttr, defStyleRes);
}
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
rKeyBackground = (Drawable) ReflectionUtils.getFieldValue(this, "mKeyBackground");
rLabelTextSize = (Integer) ReflectionUtils.getFieldValue(this, "mLabelTextSize");
rKeyTextSize = (Integer) ReflectionUtils.getFieldValue(this, "mKeyTextSize");
rKeyTextColor = (Integer) ReflectionUtils.getFieldValue(this, "mKeyTextColor");
rShadowColor = (Integer) ReflectionUtils.getFieldValue(this, "mShadowColor");
rShadowRadius = (Float) ReflectionUtils.getFieldValue(this, "mShadowRadius");
}
@Override
public void onDraw(Canvas canvas) {
//说明CustomKeyboardView只针对CustomBaseKeyboard键盘进行重绘,
// 且CustomBaseKeyboard必需有设置CustomKeyStyle的回调接口实现, 才进行重绘, 这才有意义
if (null == getKeyboard() || !(getKeyboard() instanceof BaseKeyboard) || null == ((BaseKeyboard) getKeyboard()).getKeyStyle()) {
super.onDraw(canvas);
return;
}
rClipRegion = (Rect) ReflectionUtils.getFieldValue(this, "mClipRegion");
rInvalidatedKey = (Keyboard.Key) ReflectionUtils.getFieldValue(this, "mInvalidatedKey");
super.onDraw(canvas);
onRefreshKey(canvas);
}
/**
* onRefreshKeyprivate void onBufferDraw(). key.
*
* @param canvas
*/
private void onRefreshKey(Canvas canvas) {
final Paint paint = (Paint) ReflectionUtils.getFieldValue(this, "mPaint");
final Rect padding = (Rect) ReflectionUtils.getFieldValue(this, "mPadding");
paint.setColor(rKeyTextColor);
final int kbdPaddingLeft = getPaddingLeft();
final int kbdPaddingTop = getPaddingTop();
Drawable keyBackground = null;
final Rect clipRegion = rClipRegion;
final Keyboard.Key invalidKey = rInvalidatedKey;
boolean drawSingleKey = false;
if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
// Is clipRegion completely contained within the invalidated key?
if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left &&
invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top &&
invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right &&
invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) {
drawSingleKey = true;
}
}
//拿到当前键盘被弹起的输入源 和 键盘为每个key的定制实现customKeyStyle
EditText etCur = ((BaseKeyboard) getKeyboard()).getEditText();
BaseKeyboard.KeyStyle customKeyStyle = ((BaseKeyboard) getKeyboard()).getKeyStyle();
List<Keyboard.Key> keys = getKeyboard().getKeys();
final int keyCount = keys.size();
//canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
for (int i = 0; i < keyCount; i++) {
final Keyboard.Key key = keys.get(i);
if (drawSingleKey && invalidKey != key) {
continue;
}
//获取为Key自定义的背景, 若没有定制, 使用KeyboardView的默认属性keyBackground设置
keyBackground = customKeyStyle.getKeyBackound(key);
if (null == keyBackground) {
keyBackground = rKeyBackground;
}
int[] drawableState = key.getCurrentDrawableState();
keyBackground.setState(drawableState);
//获取为Key自定义的Label, 若没有定制, 使用xml布局中指定的
CharSequence keyLabel = customKeyStyle.getKeyLabel(key);
if (null == keyLabel) {
keyLabel = key.label;
}
// Switch the character to uppercase if shift is pressed
String label = keyLabel == null ? null : adjustCase(keyLabel).toString();
final Rect bounds = keyBackground.getBounds();
if (key.width != bounds.right ||
key.height != bounds.bottom) {
keyBackground.setBounds(0, 0, key.width, key.height);
}
canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop);
keyBackground.draw(canvas);
if (label != null) {
//获取为Key的Label的字体大小, 若没有定制, 使用KeyboardView的默认属性keyTextSize设置
Float customKeyTextSize = customKeyStyle.getKeyTextSize(key);
// For characters, use large font. For labels like "Done", use small font.
if (null != customKeyTextSize) {
paint.setTextSize(customKeyTextSize);
paint.setTypeface(Typeface.DEFAULT);
//paint.setTypeface(Typeface.DEFAULT_BOLD);
} else {
if (label.length() > 1 && key.codes.length < 2) {
paint.setTextSize(rLabelTextSize);
paint.setTypeface(Typeface.DEFAULT);
//paint.setTypeface(Typeface.DEFAULT_BOLD);
} else {
paint.setTextSize(rKeyTextSize);
paint.setTypeface(Typeface.DEFAULT);
//paint.setTypeface(Typeface.DEFAULT);
}
}
//获取为Key的Label的字体颜色, 若没有定制, 使用KeyboardView的默认属性keyTextColor设置
Integer customKeyTextColor = customKeyStyle.getKeyTextColor(key);
if (null != customKeyTextColor) {
paint.setColor(customKeyTextColor);
} else {
paint.setColor(rKeyTextColor);
}
// Draw a drop shadow for the text
paint.setShadowLayer(rShadowRadius, 0, 0, rShadowColor);
// Draw the text
canvas.drawText(label,
(key.width - padding.left - padding.right) / 2
+ padding.left,
(key.height - padding.top - padding.bottom) / 2
+ (paint.getTextSize() - paint.descent()) / 2 + padding.top,
paint);
// Turn off drop shadow
paint.setShadowLayer(0, 0, 0, 0);
} else if (key.icon != null) {
final int drawableX = (key.width - padding.left - padding.right
- key.icon.getIntrinsicWidth()) / 2 + padding.left;
final int drawableY = (key.height - padding.top - padding.bottom
- key.icon.getIntrinsicHeight()) / 2 + padding.top;
canvas.translate(drawableX, drawableY);
key.icon.setBounds(0, 0,
key.icon.getIntrinsicWidth(), key.icon.getIntrinsicHeight());
key.icon.draw(canvas);
canvas.translate(-drawableX, -drawableY);
}
canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop);
}
rInvalidatedKey = null;
}
private CharSequence adjustCase(CharSequence label) {
if (getKeyboard().isShifted() && label != null && label.length() < 3
&& Character.isLowerCase(label.charAt(0))) {
label = label.toString().toUpperCase();
}
return label;
}
}

@ -0,0 +1,130 @@
package com.gizwits.opensource.appkit.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import com.gizwits.opensource.appkit.R;
/**
* Created by qiaoning on 2017/8/9.
*/
public class CircleProgress extends View {
//小圆的个数
private int numOfCircles;
//最大圆半径
private int maxRadius;
//最小圆半径
private int minRadius;
//旋转速度
private int rotateSpeedInMillis;
//是否顺时针旋转
private boolean isClockwise;
//小圆的颜色
private int circleColor;
private Paint paint;
private float rotateDegrees;
private int numOfRotate;
public CircleProgress(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CircleProgress);
numOfCircles = array.getInt(R.styleable.CircleProgress_numOfCircles, 10);
maxRadius = array.getDimensionPixelSize(R.styleable.CircleProgress_maxRadius, dp2px(10));
minRadius = array.getDimensionPixelSize(R.styleable.CircleProgress_minRadius, dp2px(2));
rotateSpeedInMillis = array.getInt(R.styleable.CircleProgress_rotateSpeedInMillis, 200);
isClockwise = array.getBoolean(R.styleable.CircleProgress_isClockwise, true);
circleColor = array.getColor(R.styleable.CircleProgress_circleColor, Color.BLACK);
array.recycle();
paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
paint.setColor(circleColor);
//view每次旋转的角度
rotateDegrees = 360 / numOfCircles;
//旋转的周期为小圆的个数
numOfRotate = 0;
}
public CircleProgress(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CircleProgress(Context context) {
this(context, null);
}
@Override
protected void onDraw(Canvas canvas) {
//按一定角度旋转画布canvas当旋转周期==小圆个数时重置
if (numOfRotate == numOfCircles) {
numOfRotate = 0;
}
//根据旋转的方向旋转画布canvas然后再画小圆
if (isClockwise) {
canvas.rotate(rotateDegrees * numOfRotate, getWidth() / 2, getHeight() / 2);
} else {
canvas.rotate(-rotateDegrees * numOfRotate, getWidth() / 2, getHeight() / 2);
}
//记录旋转的次数下次invalidat()重绘时就可以使用新的角度旋转canvas使小圆产生旋转的感觉
numOfRotate++;
//取View最短边并减去最大圆的半径得到所有圆所在的圆路径的半径
int radius = (getWidth() > getHeight() ? getHeight() : getWidth()) / 2 - maxRadius;
//每个小圆的半径增量
float radiusIncrement = (float) (maxRadius - minRadius) / numOfCircles;
//每隔多少度绘制一个小圆,弧度制
double angle = 2 * Math.PI / numOfCircles;
//按位置画小圆
//每个小圆的位置可以由正弦余弦函数求出,并且每个小圆半径依次递增,若反方向则依次递减
if (isClockwise) {
for (int i = 0; i < numOfCircles; i++) {
float x = (float) (getWidth() / 2 + Math.cos(i * angle) * radius);
float y = (float) (getHeight() / 2 - Math.sin(i * angle) * radius);
canvas.drawCircle(x, y, maxRadius - radiusIncrement * i, paint);
}
} else {
for (int i = 0; i < numOfCircles; i++) {
float x = (float) (getWidth() / 2 + Math.cos(i * angle) * radius);
float y = (float) (getHeight() / 2 - Math.sin(i * angle) * radius);
canvas.drawCircle(x, y, minRadius + radiusIncrement * i, paint);
}
}
//旋转间隔即progressBar的旋转速度
postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
invalidate();
}
}, rotateSpeedInMillis);
}
//dp转px函数
private int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
}
}

@ -0,0 +1,59 @@
package com.gizwits.opensource.appkit.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.view.View;
import com.gizwits.opensource.appkit.R;
public class DotView extends View {
private Paint p;
private int width;
private int height;
private int dash;
public DotView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public DotView(Context context) {
super(context);
init(context);
}
private void init(Context context){
p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setStyle(Style.FILL);
p.setColor(context.getResources().getColor(R.color.line_gray));
final float scale = context.getResources().getDisplayMetrics().density;
dash=(int) (3 * scale + 0.5f);
}
@Override
protected void onDraw(Canvas canvas) {
if(width>10){
for(int i=0;i<width;i+=dash){
canvas.drawLine(i, 0, i+=dash, 0, p);
}
}
super.onDraw(canvas);
}
@Override
public void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
width=w;
height=h;
p.setStrokeWidth(height);
this.postInvalidate();
}
}

@ -0,0 +1,210 @@
package com.gizwits.opensource.appkit.view;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import com.gizwits.opensource.appkit.R;
@SuppressLint("Override")
public class GifView extends View {
/**
* 1
*/
private static final int DEFAULT_MOVIE_DURATION = 1000;
private int mMovieResourceId;
private Movie mMovie;
private long mMovieStart;
private int mCurrentAnimationTime = 0;
private float mLeft;
private float mTop;
private float mScale;
private int mMeasuredMovieWidth;
private int mMeasuredMovieHeight;
private boolean mVisible = true;
private volatile boolean mPaused = false;
public GifView(Context context) {
this(context, null);
}
public GifView(Context context, AttributeSet attrs) {
this(context, attrs, R.styleable.CustomTheme_gifViewStyle);
}
public GifView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setViewAttributes(context, attrs, defStyle);
}
private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
// 从描述文件中读出gif的值创建出Movie实例
final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifView, defStyle,
R.style.Widget_GifView);
mMovieResourceId = array.getResourceId(R.styleable.GifView_gif, -1);
mPaused = array.getBoolean(R.styleable.GifView_paused, false);
array.recycle();
if (mMovieResourceId != -1) {
mMovie = Movie.decodeStream(getResources().openRawResource(mMovieResourceId));
}
}
/**
* gif
*
* @param movieResId
*/
public void setMovieResource(int movieResId) {
this.mMovieResourceId = movieResId;
mMovie = Movie.decodeStream(getResources().openRawResource(mMovieResourceId));
requestLayout();
}
public void setMovie(Movie movie) {
this.mMovie = movie;
requestLayout();
}
public Movie getMovie() {
return mMovie;
}
public void setMovieTime(int time) {
mCurrentAnimationTime = time;
invalidate();
}
/**
*
*
* @param paused
*/
public void setPaused(boolean paused) {
this.mPaused = paused;
if (!paused) {
mMovieStart = android.os.SystemClock.uptimeMillis() - mCurrentAnimationTime;
}
invalidate();
}
/**
* gif
*
* @return
*/
public boolean isPaused() {
return this.mPaused;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mMovie != null) {
int movieWidth = mMovie.width();
int movieHeight = mMovie.height();
int maximumWidth = MeasureSpec.getSize(widthMeasureSpec);
float scaleW = (float) movieWidth / (float) maximumWidth;
mScale = 1f / scaleW;
mMeasuredMovieWidth = maximumWidth;
mMeasuredMovieHeight = (int) (movieHeight * mScale);
setMeasuredDimension(mMeasuredMovieWidth, mMeasuredMovieHeight);
} else {
setMeasuredDimension(getSuggestedMinimumWidth(), getSuggestedMinimumHeight());
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
mLeft = (getWidth() - mMeasuredMovieWidth) / 2f;
mTop = (getHeight() - mMeasuredMovieHeight) / 2f;
mVisible = getVisibility() == View.VISIBLE;
}
@Override
protected void onDraw(Canvas canvas) {
if (mMovie != null) {
if (!mPaused) {
updateAnimationTime();
drawMovieFrame(canvas);
invalidateView();
} else {
drawMovieFrame(canvas);
}
}
}
private void invalidateView() {
if (mVisible) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BASE) {
postInvalidate();
} else {
invalidate();
}
}
}
private void updateAnimationTime() {
long now = android.os.SystemClock.uptimeMillis();
// 如果第一帧,记录起始时间
if (mMovieStart == 0) {
mMovieStart = now;
}
// 取出动画的时长
int dur = mMovie.duration();
if (dur == 0) {
dur = DEFAULT_MOVIE_DURATION;
}
// 算出需要显示第几帧
mCurrentAnimationTime = (int) ((now - mMovieStart) % dur);
}
private void drawMovieFrame(Canvas canvas) {
// 设置要显示的帧,绘制即可
mMovie.setTime(mCurrentAnimationTime);
canvas.saveLayer(0, 0, getWidth(), getHeight(), null);
canvas.scale(mScale, mScale);
mMovie.draw(canvas, mLeft / mScale, mTop / mScale);
canvas.restore();
}
public void onScreenStateChanged(int screenState) {
mVisible = screenState == DEFAULT_MOVIE_DURATION;
invalidateView();
}
@Override
protected void onVisibilityChanged(View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
mVisible = visibility == View.VISIBLE;
invalidateView();
}
@Override
protected void onWindowVisibilityChanged(int visibility) {
super.onWindowVisibilityChanged(visibility);
mVisible = visibility == View.VISIBLE;
invalidateView();
}
}

@ -0,0 +1,63 @@
package com.gizwits.opensource.appkit.view;
import java.util.Locale;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
public class HexWatcher implements TextWatcher {
private EditText _text;
public HexWatcher(EditText _text) {
this._text = _text;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s == null || s.length() == 0)
return;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ' && i < s.length() - 1) {
continue;
} else {
sb.append(s.charAt(i));
if (sb.length() % 3 == 0 && sb.charAt(sb.length() - 1) != ' ') {
sb.insert(sb.length() - 1, ' ');
}
}
}
if (!sb.toString().equals(s.toString())) {
int index = start + 1;
if (sb.charAt(start) == ' ') {
if (before == 0) {
index++;
} else {
index--;
}
} else {
if (before == 1) {
index--;
}
}
_text.setText(sb.toString().toUpperCase(Locale.getDefault()));
_text.setSelection(index);
}
// _text.removeTextChangedListener(this);
// _text.setText(s.toString().toUpperCase(Locale.getDefault()));
// _text.addTextChangedListener(this);
}
@Override
public void afterTextChanged(Editable s) {
}
}

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

Loading…
Cancel
Save