Commit abe316ce625dc13943ef15efde7670bb6d72bbca
1 parent
d9135ec9
1 搭建设备说明界面
2 自定义pop框
Showing
100 changed files
with
3523 additions
and
450 deletions
app/build.gradle
| 1 | 1 | apply plugin: 'com.android.application' |
| 2 | - | |
| 2 | +static def stringValue(def value) { | |
| 3 | + return "\"${value}\"" | |
| 4 | +} | |
| 3 | 5 | android { |
| 4 | 6 | compileSdkVersion 28 |
| 5 | 7 | defaultConfig { |
| 6 | - applicationId "com.cnlive.strike.xiaojiaspeaker" | |
| 8 | + applicationId "com.cnlive.strike" | |
| 7 | 9 | minSdkVersion 18 |
| 8 | 10 | targetSdkVersion 28 |
| 9 | 11 | versionCode 1 |
| 10 | 12 | versionName "1.0" |
| 11 | 13 | testInstrumentationRunner "android.test.runner.AndroidJUnitRunner" |
| 14 | + multiDexEnabled true | |
| 12 | 15 | } |
| 13 | 16 | buildTypes { |
| 17 | + debug { | |
| 18 | + applicationIdSuffix ".debug" | |
| 19 | + resValue("string", "app_name", "网++ 内测") | |
| 20 | + buildConfigField("String", "APP_ID", stringValue("802_jhbqccxw08")) | |
| 21 | + buildConfigField("String", "APP_KEY", stringValue("9c5619e9be747bb3b925dd215ca5923d86f12c09b9394f")) | |
| 22 | + buildConfigField("String", "APP_SCERET", stringValue("1e6380cb347255e777f72b5aa60f41daa68443a132aaea")) | |
| 23 | + buildConfigField("String", "BAIDU_MAP_APP_KEY", stringValue("2IIsTtvX2FA88yvDrPZedc2ZvMhxyDbN")) | |
| 24 | +// BAIDU_MAP_APP_KEY: "OeotXc38bbnU7WmyKGA0VMahk4v35VG2" //测试 | |
| 25 | + | |
| 26 | + manifestPlaceholders = [ | |
| 27 | + | |
| 28 | + BAIDU_MAP_APP_KEY: "2IIsTtvX2FA88yvDrPZedc2ZvMhxyDbN" | |
| 29 | +// BAIDU_MAP_APP_KEY: "OeotXc38bbnU7WmyKGA0VMahk4v35VG2" | |
| 30 | + | |
| 31 | + ] | |
| 32 | + } | |
| 33 | +// BAIDU_MAP_APP_KEY: "Q7y9SGcZVs0tmhbNTiaz0jHm4S1xGzE2"//正式 | |
| 34 | +// BAIDU_MAP_APP_KEY: "0bWeo04KKKHqTwozcqgyLZVd0oVhv3rZ" | |
| 35 | + | |
| 14 | 36 | release { |
| 15 | - minifyEnabled false | |
| 16 | - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |
| 37 | + resValue("string", "app_name", "网++") | |
| 38 | + buildConfigField("String", "APP_ID", stringValue("769_jetj7bq525")) | |
| 39 | + buildConfigField("String", "APP_KEY", stringValue("0d57b045ec0c3988a682d94c644e66b9b8e0d2b8ef937d")) | |
| 40 | + buildConfigField("String", "APP_SCERET", stringValue("275e8dc29274a1186d82f65bc607c231d02bcb3bfd8976")) | |
| 41 | + buildConfigField("String", "BAIDU_MAP_APP_KEY", stringValue("Q7y9SGcZVs0tmhbNTiaz0jHm4S1xGzE2")) | |
| 42 | + | |
| 43 | + manifestPlaceholders = [ | |
| 44 | + BAIDU_MAP_APP_KEY: "Q7y9SGcZVs0tmhbNTiaz0jHm4S1xGzE2" | |
| 45 | +// BAIDU_MAP_APP_KEY: "0bWeo04KKKHqTwozcqgyLZVd0oVhv3rZ" | |
| 46 | + ] | |
| 17 | 47 | } |
| 18 | 48 | } |
| 19 | 49 | dataBinding { |
| 20 | 50 | enabled = true |
| 21 | 51 | } |
| 52 | + dexOptions { | |
| 53 | + javaMaxHeapSize '4g' | |
| 54 | + } | |
| 22 | 55 | compileOptions { |
| 23 | 56 | sourceCompatibility = 1.8 |
| 24 | 57 | targetCompatibility = 1.8 |
| ... | ... | @@ -29,7 +62,7 @@ android { |
| 29 | 62 | dependencies { |
| 30 | 63 | implementation fileTree(dir: 'libs', include: ['*.jar']) |
| 31 | 64 | testImplementation 'junit:junit:4.12' |
| 32 | - compile project(path: ':module_xiaojiaSoundBox') | |
| 65 | + implementation project(path: ':module_xiaojiaSoundBox') | |
| 33 | 66 | implementation "com.android.support:support-v4:$rootProject.supportV4" |
| 34 | 67 | implementation "com.android.support:appcompat-v7:$rootProject.appcompatV7" |
| 35 | 68 | implementation "com.android.support:design:$rootProject.design" |
| ... | ... | @@ -38,4 +71,5 @@ dependencies { |
| 38 | 71 | implementation "com.cnlive:app_arch:$rootProject.appArch" |
| 39 | 72 | implementation "com.qmuiteam:qmui:$rootProject.qmui" |
| 40 | 73 | implementation "com.cnlive.libs:base:$rootProject.libBase" |
| 74 | + androidTestImplementation 'junit:junit:4.12' | |
| 41 | 75 | } | ... | ... |
app/src/androidTest/java/com/cnlive/strike/xiaojiaspeaker/ExampleInstrumentedTest.java deleted
100644 → 0
| 1 | -package com.cnlive.strike.xiaojiaspeaker; | |
| 2 | - | |
| 3 | -import android.content.Context; | |
| 4 | - | |
| 5 | -import androidx.test.platform.app.InstrumentationRegistry; | |
| 6 | -import androidx.test.ext.junit.runners.AndroidJUnit4; | |
| 7 | - | |
| 8 | -import org.junit.Test; | |
| 9 | -import org.junit.runner.RunWith; | |
| 10 | - | |
| 11 | -import static org.junit.Assert.*; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * Instrumented test, which will execute on an Android device. | |
| 15 | - * | |
| 16 | - * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | |
| 17 | - */ | |
| 18 | -@RunWith(AndroidJUnit4.class) | |
| 19 | -public class ExampleInstrumentedTest { | |
| 20 | - @Test | |
| 21 | - public void useAppContext() { | |
| 22 | - // Context of the app under test. | |
| 23 | - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | |
| 24 | - | |
| 25 | - assertEquals("com.cnlive.strike.xiaojiaspeaker", appContext.getPackageName()); | |
| 26 | - } | |
| 27 | -} |
app/src/main/java/com/cnlive/strike/xiaojiaspeaker/MainActivity.java
| ... | ... | @@ -5,8 +5,11 @@ import android.content.Intent; |
| 5 | 5 | import android.os.Bundle; |
| 6 | 6 | import android.support.v7.app.AppCompatActivity; |
| 7 | 7 | |
| 8 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.AllDeviceActivity; | |
| 8 | 9 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothStep1Activity; |
| 9 | 10 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.BluetoothConnActivity; |
| 11 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.ConnBluetoothSuccessActivity; | |
| 12 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.DeviceInstructionActivity; | |
| 10 | 13 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.SearchDeviceActivity; |
| 11 | 14 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.SpeakerMainActivity; |
| 12 | 15 | |
| ... | ... | @@ -19,8 +22,11 @@ public class MainActivity extends AppCompatActivity { |
| 19 | 22 | setContentView(R.layout.activity_speaker_main); |
| 20 | 23 | // startActivity(new Intent(MainActivity.this, SpeakerMainActivity.class)); |
| 21 | 24 | // startActivity(new Intent(MainActivity.this, BluetoothConnActivity.class)); |
| 22 | - startActivity(new Intent(MainActivity.this, BlueToothStep1Activity.class)); | |
| 23 | - | |
| 25 | +// startActivity(new Intent(MainActivity.this, BlueToothStep1Activity.class)); | |
| 26 | +// startActivity(new Intent(MainActivity.this, ConnBluetoothSuccessActivity.class)); | |
| 27 | + startActivity(new Intent(MainActivity.this, AllDeviceActivity.class)); | |
| 28 | +// startActivity(new Intent(MainActivity.this, DeviceInstructionActivity.class)); | |
| 29 | +// | |
| 24 | 30 | |
| 25 | 31 | finish(); |
| 26 | 32 | } | ... | ... |
app/src/main/java/com/cnlive/strike/xiaojiaspeaker/MyApp.java
| ... | ... | @@ -2,11 +2,17 @@ package com.cnlive.strike.xiaojiaspeaker; |
| 2 | 2 | |
| 3 | 3 | import android.app.Application; |
| 4 | 4 | |
| 5 | +import com.cnlive.libs.base.application.AppConfig; | |
| 6 | +import com.cnlive.strike.speaker.BuildConfig; | |
| 5 | 7 | |
| 6 | 8 | |
| 7 | 9 | public class MyApp extends Application { |
| 8 | 10 | @Override |
| 9 | 11 | public void onCreate() { |
| 10 | 12 | super.onCreate(); |
| 13 | + String userId = ""; | |
| 14 | + AppConfig.init(getApplicationContext(), BuildConfig.APP_ID, BuildConfig.APP_KEY, BuildConfig.APP_SCERET, | |
| 15 | + 0, BuildConfig.DEBUG, "", "", | |
| 16 | + userId, "", "", "", ""); | |
| 11 | 17 | } |
| 12 | 18 | } | ... | ... |
app/src/main/res/values/strings.xml
module_xiaojiaSoundBox/build.gradle
| 1 | 1 | apply plugin: 'com.android.library' |
| 2 | +apply from: './maven_push.gradle' | |
| 3 | + | |
| 4 | +static def stringValue(def value) { | |
| 5 | + return "\"${value}\"" | |
| 6 | +} | |
| 2 | 7 | |
| 3 | 8 | android { |
| 4 | 9 | compileSdkVersion 28 |
| ... | ... | @@ -17,12 +22,25 @@ android { |
| 17 | 22 | enabled = true |
| 18 | 23 | } |
| 19 | 24 | buildTypes { |
| 25 | + debug { | |
| 26 | + } | |
| 20 | 27 | release { |
| 21 | 28 | minifyEnabled false |
| 22 | 29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 23 | 30 | } |
| 24 | 31 | } |
| 32 | + compileOptions { | |
| 33 | + sourceCompatibility JavaVersion.VERSION_1_8 | |
| 34 | + targetCompatibility JavaVersion.VERSION_1_8 | |
| 35 | + } | |
| 25 | 36 | |
| 37 | + dataBinding { | |
| 38 | + enabled true | |
| 39 | + } | |
| 40 | + | |
| 41 | + dexOptions { | |
| 42 | + javaMaxHeapSize '4g' | |
| 43 | + } | |
| 26 | 44 | } |
| 27 | 45 | |
| 28 | 46 | dependencies { |
| ... | ... | @@ -35,7 +53,9 @@ dependencies { |
| 35 | 53 | implementation "com.cnlive:app_arch:$rootProject.appArch" |
| 36 | 54 | implementation "com.qmuiteam:qmui:$rootProject.qmui" |
| 37 | 55 | implementation "com.cnlive.libs:base:$rootProject.libBase" |
| 38 | -// implementation 'com.blakequ.androidblemanager:bluetooth-manager-lib:2.1.5' | |
| 56 | + implementation "com.cnlive.libs:network:$rootProject.libNetwork" | |
| 57 | + | |
| 58 | + // 蓝牙相关 | |
| 39 | 59 | implementation 'com.clj.fastble:FastBleLib:2.3.4' |
| 40 | 60 | // https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/README-CN.md |
| 41 | 61 | // implementation 'com.blankj:utilcode:1.25.9' |
| ... | ... | @@ -45,5 +65,13 @@ dependencies { |
| 45 | 65 | // loading动画 |
| 46 | 66 | implementation "com.wang.avi:library:$rootProject.avi" |
| 47 | 67 | |
| 68 | +// implementation 'com.android.support.constraint:constraint-layout:1.1.3' | |
| 69 | + implementation "com.scwang.smartrefresh:SmartRefreshLayout:$rootProject.SmartRefreshLayout" | |
| 70 | + implementation "com.scwang.smartrefresh:SmartRefreshHeader:$rootProject.SmartRefreshHeader" | |
| 71 | + // implementation 'com.android.support.constraint:constraint-layout:1.1.3' | |
| 72 | + // 动画库 | |
| 73 | + // implementation 'com.android.support:support-compat:25.1.1' | |
| 74 | + implementation 'com.daimajia.easing:library:2.0@aar' | |
| 75 | + implementation 'com.daimajia.androidanimations:library:2.3@aar' | |
| 48 | 76 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' |
| 49 | 77 | } | ... | ... |
module_xiaojiaSoundBox/maven_push.gradle
0 → 100644
| 1 | +apply plugin: 'maven' | |
| 2 | + | |
| 3 | +uploadArchives() { | |
| 4 | + repositories { | |
| 5 | + mavenDeployer { | |
| 6 | + def lib = moudle_subscription | |
| 7 | + //发布环境(正式/测试) | |
| 8 | + android.defaultPublishConfig lib.debug ? "debug" : "release" | |
| 9 | + //发布渠道(地址/账号) | |
| 10 | + repository(url: maven.mavenMixedUrl) { | |
| 11 | + authentication(userName: maven.mavenUserName, password: maven.mavenPwd) | |
| 12 | + } | |
| 13 | + //发布信息(包名/别名/版本) | |
| 14 | + pom.project { | |
| 15 | + groupId lib.packeg | |
| 16 | + artifactId lib.name | |
| 17 | + version = lib.debug ? lib.version.concat("-SNAPSHOT") : lib.version | |
| 18 | + } | |
| 19 | + pom.whenConfigured { pom -> | |
| 20 | + pom.dependencies.clear() | |
| 21 | + } | |
| 22 | + | |
| 23 | + } | |
| 24 | + } | |
| 25 | +} | |
| 0 | 26 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/AndroidManifest.xml
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | + xmlns:tools="http://schemas.android.com/tools" | |
| 3 | 4 | package="com.cnlive.strike.xiaojiaspeaker"> |
| 4 | - | |
| 5 | + <!-- wifi --> | |
| 6 | + <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> | |
| 7 | + <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | |
| 5 | 8 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
| 6 | 9 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
| 7 | - <uses-permission android:name="android.permission.BLUETOOTH" /> | |
| 8 | - <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> | |
| 9 | - <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | |
| 10 | - <uses-permission android:name="android.permission.INTERNET" /> | |
| 11 | - <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> | |
| 12 | 10 | <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> |
| 11 | + <uses-permission | |
| 12 | + android:name="android.permission.WRITE_SECURE_SETTINGS" | |
| 13 | + tools:ignore="ProtectedPermissions" /> <!-- 蓝牙 --> | |
| 14 | + <uses-permission android:name="android.permission.BLUETOOTH" /> | |
| 15 | + <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <!-- wifi和蓝牙都要 --> | |
| 13 | 16 | <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> |
| 17 | + <uses-permission android:name="android.permission.INTERNET" /> | |
| 14 | 18 | |
| 15 | 19 | <application> |
| 16 | - <activity android:name=".ui.activity.SelectWifiActivity"></activity> | |
| 20 | + <activity android:name=".ui.activity.DeviceInstructionActivity"></activity> | |
| 21 | + <activity android:name=".ui.activity.AllDeviceActivity" /> | |
| 22 | + <activity android:name=".ui.activity.ConnBluetoothSuccessActivity" /> | |
| 23 | + <activity android:name=".ui.activity.SelectWifiActivity" /> | |
| 17 | 24 | <activity android:name=".ui.activity.BlueToothStep2Activity" /> |
| 18 | 25 | <activity android:name=".ui.activity.BlueToothStep1Activity" /> |
| 19 | 26 | <activity android:name=".ui.activity.BlueToothHelpActivity" /> | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/commonInfo/CommInfo.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.commonInfo; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | + | |
| 5 | +import com.cnlive.strike.xiaojiaspeaker.util.MySpHelper; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 公共参数 | |
| 9 | + * | |
| 10 | + * @author ys | |
| 11 | + */ | |
| 12 | +public class CommInfo { | |
| 13 | + //用户ID | |
| 14 | + private static final String KEY_USER_ID = "xiaojia_UserId"; | |
| 15 | + //是否显示礼物弹窗 | |
| 16 | + private static final String KEY_CONN_SUCCESS_GIF = "xiaojia_conn_success_gif"; | |
| 17 | + // 设备sn | |
| 18 | + private static final String KEY_SN = "xiaojia_sn"; | |
| 19 | + //当前token | |
| 20 | + private static final String KEY_TOKEN = "xiaojia_token"; | |
| 21 | + //家庭云id | |
| 22 | + private static final String KEY_FAMILY_ID = "xiaojia_family_id"; | |
| 23 | + | |
| 24 | + // | |
| 25 | + private static final int MyCurrentMode = Context.MODE_MULTI_PROCESS; | |
| 26 | + | |
| 27 | + public static void setFamilyId(Context context, String familyId) { | |
| 28 | + MySpHelper.getInstance(context, MyCurrentMode).putString(KEY_FAMILY_ID, familyId); | |
| 29 | + } | |
| 30 | + | |
| 31 | + public static String getFamilyId(Context context) { | |
| 32 | + return MySpHelper.getInstance(context, MyCurrentMode).getString(KEY_FAMILY_ID, ""); | |
| 33 | + } | |
| 34 | + | |
| 35 | + // | |
| 36 | + public static void setToken(Context context, String token) { | |
| 37 | + MySpHelper.getInstance(context, MyCurrentMode).putString(KEY_TOKEN, token); | |
| 38 | + } | |
| 39 | + | |
| 40 | + public static String getToken(Context context) { | |
| 41 | + return MySpHelper.getInstance(context, MyCurrentMode).getString(KEY_TOKEN, ""); | |
| 42 | + } | |
| 43 | + | |
| 44 | + public static String getSN(Context context) { | |
| 45 | + return MySpHelper.getInstance(context, MyCurrentMode).getString(KEY_SN, ""); | |
| 46 | + } | |
| 47 | + | |
| 48 | + public static void setSN(Context context, String sn) { | |
| 49 | + MySpHelper.getInstance(context, MyCurrentMode).putString(KEY_SN, sn); | |
| 50 | + } | |
| 51 | + | |
| 52 | + public static boolean getIsShowConnGift(Context context) { | |
| 53 | + return MySpHelper.getInstance(context, MyCurrentMode).getBoolean(KEY_CONN_SUCCESS_GIF, true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + public static void setIsShowConnGift(Context context, boolean isShow) { | |
| 57 | + MySpHelper.getInstance(context, MyCurrentMode).putBoolean(KEY_CONN_SUCCESS_GIF, isShow); | |
| 58 | + } | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * @param context | |
| 62 | + * @param uid | |
| 63 | + */ | |
| 64 | + public static void setUserId(Context context, String uid) { | |
| 65 | + MySpHelper.getInstance(context, MyCurrentMode).putString(KEY_USER_ID, uid); | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @param context | |
| 70 | + */ | |
| 71 | + public static String getUserId(Context context) { | |
| 72 | + return MySpHelper.getInstance(context, MyCurrentMode).getString(KEY_USER_ID, ""); | |
| 73 | + } | |
| 74 | + | |
| 75 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/constants/BlufiConstants.java
| ... | ... | @@ -20,4 +20,11 @@ public final class BlufiConstants { |
| 20 | 20 | public static final int POST_DATA_LENGTH_LESS = 16; |
| 21 | 21 | |
| 22 | 22 | public static final String PREF_MESH_IDS_NAME = "espblufi_mesh_ids"; |
| 23 | + // 音箱返回状态 | |
| 24 | + public static final String SSID_RECEIVED = "ssid received"; | |
| 25 | + public static final String WIFI_LINKING = "WiFi Linking"; | |
| 26 | + public static final String WIFI_LINK_OK = "WiFi Link OK"; | |
| 27 | + public static final String WIFI_LINK_FAIL = "WiFi Link Fail"; | |
| 28 | + | |
| 29 | + | |
| 23 | 30 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/presenter/AllDeviceFragmentPresenter.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.frame.presenter; | |
| 2 | + | |
| 3 | +import com.cnlive.strike.xiaojiaspeaker.frame.view.AllDeviceFragmentView; | |
| 4 | +import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; | |
| 5 | + | |
| 6 | +public class AllDeviceFragmentPresenter extends MvpBasePresenter<AllDeviceFragmentView> { | |
| 7 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/presenter/SelectWifiFragmentPresenter.java
| 1 | 1 | package com.cnlive.strike.xiaojiaspeaker.frame.presenter; |
| 2 | 2 | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.util.Log; | |
| 6 | + | |
| 7 | +import com.cnlive.libs.base.logic.Logic; | |
| 8 | +import com.cnlive.libs.base.logic.callback.DataCallback; | |
| 9 | +import com.cnlive.libs.base.logic.callback.FailureCallback; | |
| 10 | +import com.cnlive.libs.base.logic.callback.SuccessCallback; | |
| 11 | +import com.cnlive.libs.base.util.AlertUtil; | |
| 3 | 12 | import com.cnlive.strike.xiaojiaspeaker.frame.view.SelectWifiFragmentView; |
| 13 | +import com.cnlive.strike.xiaojiaspeaker.netWork.ApiServiceCMCC; | |
| 14 | +import com.cnlive.strike.xiaojiaspeaker.netWork.CmccRequest; | |
| 15 | +import com.cnlive.strike.xiaojiaspeaker.netWork.SubscriptionRequest; | |
| 16 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.BaseInfo; | |
| 17 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.ConfigDeviceNetParam; | |
| 18 | +import com.cnlive.strike.xiaojiaspeaker.netWork.result.ConfigDeviceNetResult; | |
| 19 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.ConnBluetoothSuccessActivity; | |
| 20 | +import com.cnlive.strike.xiaojiaspeaker.util.QMUITipDialogUtil; | |
| 4 | 21 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 5 | 22 | |
| 23 | +import org.greenrobot.eventbus.EventBus; | |
| 24 | + | |
| 25 | +import java.util.Map; | |
| 26 | + | |
| 27 | +import io.reactivex.disposables.Disposable; | |
| 28 | +import okhttp3.MediaType; | |
| 29 | +import okhttp3.RequestBody; | |
| 30 | +import retrofit2.Call; | |
| 31 | +import retrofit2.Callback; | |
| 32 | +import retrofit2.Response; | |
| 33 | + | |
| 6 | 34 | public class SelectWifiFragmentPresenter extends MvpBasePresenter<SelectWifiFragmentView> { |
| 35 | + private String TAG = "SelectWifiFragmentPresenter"; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * 查询配网情况 | |
| 39 | + * | |
| 40 | + * @param context | |
| 41 | + * @param param | |
| 42 | + */ | |
| 43 | + public void queryConfigDeviceNetResult(Activity context, ConfigDeviceNetParam param) { | |
| 44 | + CmccRequest.getInstance(ApiServiceCMCC.class) | |
| 45 | + .queryDeviceConfigNet(param) | |
| 46 | + .enqueue(new Callback<ConfigDeviceNetResult>() { | |
| 47 | + @Override | |
| 48 | + public void onResponse(Call<ConfigDeviceNetResult> call, Response<ConfigDeviceNetResult> response) { | |
| 49 | + if (null == getView()) { | |
| 50 | + return; | |
| 51 | + } | |
| 52 | + QMUITipDialogUtil.dismessDialog(); | |
| 53 | + ConfigDeviceNetResult result = response.body(); | |
| 54 | + //响应成功 | |
| 55 | + if (CmccRequest.SUCCRSS == result.getResult()) { | |
| 56 | + Log.e(TAG, "onResponse: "); | |
| 57 | + if ("success".equals(result.getData().getResult())) { | |
| 58 | + context.finish(); | |
| 59 | + ConnBluetoothSuccessActivity.startActivity(context); | |
| 60 | + } else { | |
| 61 | + AlertUtil.showDeftToast(context, "配网失败,请稍后重试"); | |
| 62 | + } | |
| 63 | + } else { | |
| 64 | + //响应失败 | |
| 65 | + AlertUtil.showDeftToast(context, "配网失败,请稍后重试"); | |
| 66 | + } | |
| 67 | + } | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public void onFailure(Call<ConfigDeviceNetResult> call, Throwable t) { | |
| 71 | + QMUITipDialogUtil.dismessDialog(); | |
| 72 | + } | |
| 73 | + }); | |
| 74 | + } | |
| 7 | 75 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/AllDeviceFragmentView.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.frame.view; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.support.v7.widget.LinearLayoutManager; | |
| 5 | + | |
| 6 | +import com.cnlive.strike.xiaojiaspeaker.model.AllDeviceInfo; | |
| 7 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothStep1Activity; | |
| 8 | +import com.cnlive.strike.xiaojiaspeaker.ui.adapter.AllDeviceAdapter; | |
| 9 | +import com.cnlive.strike.xiaojiaspeaker.ui.fragment.AllDeviceFragment; | |
| 10 | +import com.hannesdorfmann.mosby3.mvp.MvpView; | |
| 11 | + | |
| 12 | +import java.util.ArrayList; | |
| 13 | +import java.util.List; | |
| 14 | + | |
| 15 | +public class AllDeviceFragmentView implements MvpView { | |
| 16 | + private AllDeviceFragment fragment; | |
| 17 | + private AllDeviceAdapter adapter; | |
| 18 | + private List<AllDeviceInfo> allDeviceInfoList; | |
| 19 | + | |
| 20 | + public AllDeviceFragmentView(AllDeviceFragment fragment) { | |
| 21 | + this.fragment = fragment; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public Activity getContext() { | |
| 25 | + return fragment == null ? null : fragment.getActivity(); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public void initView() { | |
| 29 | + AllDeviceInfo allDeviceInfo = new AllDeviceInfo(); | |
| 30 | + allDeviceInfoList = new ArrayList<>(); | |
| 31 | + allDeviceInfoList.add(allDeviceInfo); | |
| 32 | + adapter = new AllDeviceAdapter(getContext(), allDeviceInfoList); | |
| 33 | + fragment.binding.rvAllDevice.setLayoutManager(new LinearLayoutManager(getContext())); | |
| 34 | + fragment.binding.rvAllDevice.setAdapter(adapter); | |
| 35 | + adapter.setOnAddClickListener(new AllDeviceAdapter.OnAddClickListener() { | |
| 36 | + @Override | |
| 37 | + public void onAddClick() { | |
| 38 | + BlueToothStep1Activity.startActivity(fragment.getActivity()); | |
| 39 | + } | |
| 40 | + }); | |
| 41 | + } | |
| 42 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/SearchDevicefragmentView.java
| ... | ... | @@ -136,83 +136,7 @@ public class SearchDevicefragmentView implements MvpView { |
| 136 | 136 | scanBlueToothDevice(); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - private void connectDevice(BleDevice bleDevice) { | |
| 140 | - BleManager.getInstance().disconnect(bleDevice); | |
| 141 | - BleManager.getInstance().connect(bleDevice, new BleGattCallback() { | |
| 142 | - // 开始连接 | |
| 143 | - @Override | |
| 144 | - public void onStartConnect() { | |
| 145 | - if (null == getContext()) { | |
| 146 | - return; | |
| 147 | - } | |
| 148 | - } | |
| 149 | - | |
| 150 | - // 连接失败 | |
| 151 | - @Override | |
| 152 | - public void onConnectFail(BleDevice bleDevice, BleException exception) { | |
| 153 | - | |
| 154 | - } | |
| 155 | - | |
| 156 | - // 连接成功,BleDevice即为所连接的BLE设备 | |
| 157 | - @Override | |
| 158 | - public void onConnectSuccess(final BleDevice bleDevice, BluetoothGatt gatt, int status) { | |
| 159 | - | |
| 160 | - BleManager.getInstance().notify( | |
| 161 | - bleDevice, | |
| 162 | - BlufiConstants.UUID_WIFI_SERVICE.toString(), | |
| 163 | - BlufiConstants.UUID_NOTIFY_CHARACTERISTIC.toString(), | |
| 164 | - new BleNotifyCallback() { | |
| 165 | - @Override | |
| 166 | - public void onNotifySuccess() { | |
| 167 | - Log.e(TAG, "onNotifySuccess: "); | |
| 168 | - // 打开通知操作成功 | |
| 169 | - BleManager.getInstance().write( | |
| 170 | - bleDevice, | |
| 171 | - BlufiConstants.UUID_WIFI_SERVICE.toString(), | |
| 172 | - BlufiConstants.UUID_WRITE_CHARACTERISTIC.toString(), | |
| 173 | - (BlueToothUtil.getSSIDAndPwd("CNLive-VIP", "cnlIVE_99", "he:28850150e8bd4c830314819939361b77")).getBytes(), | |
| 174 | - new BleWriteCallback() { | |
| 175 | - @Override | |
| 176 | - public void onWriteSuccess(int current, int total, byte[] justWrite) { | |
| 177 | - Log.e(TAG, "onWriteSuccess: " + justWrite.toString()); | |
| 178 | - // 发送数据到设备成功(分包发送的情况下,可以通过方法中返回的参数可以查看发送进度) | |
| 179 | - } | |
| 180 | - | |
| 181 | - @Override | |
| 182 | - public void onWriteFailure(BleException exception) { | |
| 183 | - Log.e(TAG, "onWriteFailure: "); | |
| 184 | 139 | |
| 185 | - } | |
| 186 | - }); | |
| 187 | - // | |
| 188 | - } | |
| 189 | - | |
| 190 | - @Override | |
| 191 | - public void onNotifyFailure(BleException exception) { | |
| 192 | - Log.e(TAG, "onNotifyFailure: " + exception); | |
| 193 | - } | |
| 194 | - | |
| 195 | - @Override | |
| 196 | - public void onCharacteristicChanged(byte[] data) { | |
| 197 | - try { | |
| 198 | - Log.e(TAG, "onCharacteristicChanged: " + new String(data, "UTF-8")); | |
| 199 | - } catch (UnsupportedEncodingException e) { | |
| 200 | - e.printStackTrace(); | |
| 201 | - } | |
| 202 | - } | |
| 203 | - } | |
| 204 | - ); | |
| 205 | - | |
| 206 | - | |
| 207 | - } | |
| 208 | - | |
| 209 | - // 连接中断,isActiveDisConnected表示是否是主动调用了断开连接方法 | |
| 210 | - @Override | |
| 211 | - public void onDisConnected(boolean isActiveDisConnected, BleDevice device, BluetoothGatt gatt, int status) { | |
| 212 | - | |
| 213 | - } | |
| 214 | - }); | |
| 215 | - } | |
| 216 | 140 | |
| 217 | 141 | /** |
| 218 | 142 | * 开始扫描蓝牙设备 |
| ... | ... | @@ -223,8 +147,8 @@ public class SearchDevicefragmentView implements MvpView { |
| 223 | 147 | } |
| 224 | 148 | //隐藏loading视图 |
| 225 | 149 | hideView(fragment.binding.llRetry); |
| 226 | - if (null != bleDevices) { | |
| 227 | - bleDevices.clear(); | |
| 150 | + if (null != adapter) { | |
| 151 | + adapter.clearData(); | |
| 228 | 152 | } |
| 229 | 153 | BleManager.getInstance().scan(new BleScanCallback() { |
| 230 | 154 | // 扫描结束,列出所有扫描到的符合扫描规则的BLE设备(主线程) | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/SelectWifiFragmentView.java
| 1 | 1 | package com.cnlive.strike.xiaojiaspeaker.frame.view; |
| 2 | 2 | |
| 3 | 3 | import android.app.Activity; |
| 4 | -import android.content.BroadcastReceiver; | |
| 5 | -import android.content.Context; | |
| 6 | -import android.content.Intent; | |
| 7 | -import android.content.IntentFilter; | |
| 8 | -import android.net.NetworkInfo; | |
| 4 | +import android.bluetooth.BluetoothGatt; | |
| 5 | +import android.graphics.Typeface; | |
| 9 | 6 | import android.net.wifi.ScanResult; |
| 10 | -import android.net.wifi.WifiManager; | |
| 7 | +import android.support.annotation.NonNull; | |
| 8 | +import android.support.v4.content.ContextCompat; | |
| 11 | 9 | import android.support.v7.widget.LinearLayoutManager; |
| 10 | +import android.text.TextUtils; | |
| 12 | 11 | import android.util.Log; |
| 12 | +import android.view.View; | |
| 13 | 13 | |
| 14 | -import com.cnlive.strike.xiaojiaspeaker.model.WifiConnModel; | |
| 15 | -import com.cnlive.strike.xiaojiaspeaker.ui.activity.SpeakerMainActivity; | |
| 14 | +import com.clj.fastble.BleManager; | |
| 15 | +import com.clj.fastble.callback.BleGattCallback; | |
| 16 | +import com.clj.fastble.callback.BleNotifyCallback; | |
| 17 | +import com.clj.fastble.callback.BleWriteCallback; | |
| 18 | +import com.clj.fastble.data.BleDevice; | |
| 19 | +import com.clj.fastble.exception.BleException; | |
| 20 | +import com.cnlive.libs.base.util.AlertUtil; | |
| 21 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 22 | +import com.cnlive.strike.xiaojiaspeaker.constants.BlufiConstants; | |
| 23 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.ConfigDeviceNetParam; | |
| 16 | 24 | import com.cnlive.strike.xiaojiaspeaker.ui.adapter.WifiRecycleAdapter; |
| 17 | 25 | import com.cnlive.strike.xiaojiaspeaker.ui.fragment.SelectWifiFragment; |
| 26 | +import com.cnlive.strike.xiaojiaspeaker.ui.widget.TipDialog; | |
| 27 | +import com.cnlive.strike.xiaojiaspeaker.ui.widget.WifiPwdDialog; | |
| 28 | +import com.cnlive.strike.xiaojiaspeaker.util.BlueToothUtil; | |
| 29 | +import com.cnlive.strike.xiaojiaspeaker.util.QMUITipDialogUtil; | |
| 18 | 30 | import com.cnlive.strike.xiaojiaspeaker.util.WifiUtils; |
| 19 | 31 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 20 | 32 | |
| 33 | +import java.io.UnsupportedEncodingException; | |
| 21 | 34 | import java.util.ArrayList; |
| 22 | 35 | import java.util.List; |
| 36 | +import java.util.logging.Handler; | |
| 23 | 37 | |
| 24 | 38 | public class SelectWifiFragmentView implements MvpView { |
| 25 | 39 | private SelectWifiFragment fragment; |
| ... | ... | @@ -27,6 +41,11 @@ public class SelectWifiFragmentView implements MvpView { |
| 27 | 41 | private List<ScanResult> results = new ArrayList<>(); |
| 28 | 42 | private WifiUtils wifiUtils; |
| 29 | 43 | private String TAG = "SelectWifiView"; |
| 44 | + private WifiPwdDialog wifiPwdDialog; | |
| 45 | + private TipDialog errorDialog; | |
| 46 | + private String SSID; | |
| 47 | + private BleDevice bleDevice; | |
| 48 | + private Handler failHandler; | |
| 30 | 49 | |
| 31 | 50 | public SelectWifiFragmentView(SelectWifiFragment fragment) { |
| 32 | 51 | this.fragment = fragment; |
| ... | ... | @@ -37,16 +56,86 @@ public class SelectWifiFragmentView implements MvpView { |
| 37 | 56 | return fragment == null ? null : fragment.getActivity(); |
| 38 | 57 | } |
| 39 | 58 | |
| 40 | - public void initWifiList() { | |
| 59 | + public void initWifiList(final BleDevice bleDevice) { | |
| 60 | + this.bleDevice = bleDevice; | |
| 61 | + showLoading(); | |
| 62 | + initWifiPwdDialog(); | |
| 63 | + initErrorDialog(); | |
| 41 | 64 | if (null == adapter) { |
| 42 | 65 | adapter = new WifiRecycleAdapter(getContext(), results); |
| 43 | 66 | fragment.binding.rvWifi.setLayoutManager(new LinearLayoutManager(getContext())); |
| 44 | 67 | fragment.binding.rvWifi.setAdapter(adapter); |
| 45 | 68 | } |
| 69 | + adapter.setOnItemClickListener(new WifiRecycleAdapter.onItemClickListener() { | |
| 70 | + @Override | |
| 71 | + public void onItemClick(int position, ScanResult scanResult) { | |
| 72 | + String encryptionType = scanResult.capabilities; | |
| 73 | + SSID = scanResult.SSID; | |
| 74 | + //判断是否需要输入密码 | |
| 75 | + if (!encryptionType.contains("WEP") && !encryptionType.contains("PSK") && !encryptionType.contains("EAP")) { | |
| 76 | + Log.e(TAG, "onItemClick: 不需要密码"); | |
| 77 | + connectDevice(bleDevice, SSID, ""); | |
| 78 | + } else { | |
| 79 | + //需要密码 | |
| 80 | + if (!wifiPwdDialog.isShowing()) { | |
| 81 | + wifiPwdDialog.setMsgTip(scanResult.SSID); | |
| 82 | + wifiPwdDialog.show(); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + } | |
| 86 | + }); | |
| 46 | 87 | wifiUtils.startScanWifi(); |
| 47 | 88 | } |
| 48 | 89 | |
| 90 | + private void initErrorDialog() { | |
| 91 | + errorDialog = new TipDialog(getContext(), "", "关闭", R.color.btn_green, new TipDialog.DialogInterface() { | |
| 92 | + @Override | |
| 93 | + public void onClick(TipDialog dialog) { | |
| 94 | + dialog.dismiss(); | |
| 95 | + } | |
| 96 | + }); | |
| 97 | + errorDialog.setTipTextStyle(Typeface.DEFAULT); | |
| 98 | + errorDialog.setTipTextSize(16); | |
| 99 | + errorDialog.setCancelable(false); | |
| 100 | + errorDialog.setCanceledOnTouchOutside(false); | |
| 101 | + } | |
| 102 | + | |
| 103 | + private void initRefreshLayout() { | |
| 104 | +// fragment.binding.refreshLayout.setEnableLoadMore(false); | |
| 105 | +// fragment.binding.refreshLayout.setOnRefreshListener(new OnRefreshListener() { | |
| 106 | +// @Override | |
| 107 | +// public void onRefresh(@NonNull RefreshLayout refreshLayout) { | |
| 108 | +// showLoading(); | |
| 109 | +// wifiUtils.startScanWifi(); | |
| 110 | +// } | |
| 111 | +// }); | |
| 112 | + } | |
| 113 | + | |
| 114 | + private void initWifiPwdDialog() { | |
| 115 | + wifiPwdDialog = new WifiPwdDialog(getContext(), "", "取消", new WifiPwdDialog.DialogInterface() { | |
| 116 | + @Override | |
| 117 | + public void onClick(WifiPwdDialog dialog) { | |
| 118 | + dialog.dismiss(); | |
| 119 | + } | |
| 120 | + }, "确定", new WifiPwdDialog.ConnDialogInterface() { | |
| 121 | + @Override | |
| 122 | + public void onClick(WifiPwdDialog dialog, String pwd) { | |
| 123 | + if (!TextUtils.isEmpty(pwd) && !TextUtils.isEmpty(SSID)) { | |
| 124 | + dialog.dismiss(); | |
| 125 | + connectDevice(bleDevice, SSID, pwd); | |
| 126 | + } else { | |
| 127 | + AlertUtil.showDeftToast(getContext(), "密码不能为空"); | |
| 128 | + } | |
| 129 | + } | |
| 130 | + }); | |
| 131 | + wifiPwdDialog.setLeftBtnColor(R.color.color_999999); | |
| 132 | + wifiPwdDialog.setRightBtnColor(R.color.btn_green); | |
| 133 | + wifiPwdDialog.setCancelable(false); | |
| 134 | + wifiPwdDialog.setCanceledOnTouchOutside(false); | |
| 135 | + } | |
| 136 | + | |
| 49 | 137 | public void updateWifiList() { |
| 138 | + hideLoading(); | |
| 50 | 139 | List<ScanResult> scanResults = wifiUtils.getScanResults(); |
| 51 | 140 | if (null != scanResults && null != results) { |
| 52 | 141 | results.clear(); |
| ... | ... | @@ -56,5 +145,149 @@ public class SelectWifiFragmentView implements MvpView { |
| 56 | 145 | } |
| 57 | 146 | } |
| 58 | 147 | } |
| 148 | + | |
| 149 | + public void showLoading() { | |
| 150 | + if (null == getContext()) { | |
| 151 | + return; | |
| 152 | + } | |
| 153 | + fragment.binding.avLoading.show(); | |
| 154 | + fragment.binding.llLoading.setVisibility(View.VISIBLE); | |
| 155 | + //设置按钮不可点击 | |
| 156 | + fragment.binding.btnNext.setClickable(false); | |
| 157 | + fragment.binding.btnNext.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_btn_press)); | |
| 158 | + | |
| 159 | + } | |
| 160 | + | |
| 161 | + public void hideLoading() { | |
| 162 | + if (null == getContext()) { | |
| 163 | + return; | |
| 164 | + } | |
| 165 | +// fragment.binding.refreshLayout.finishRefresh(); | |
| 166 | + fragment.binding.avLoading.hide(); | |
| 167 | + fragment.binding.llLoading.setVisibility(View.GONE); | |
| 168 | + //设置按钮可点击 | |
| 169 | + fragment.binding.btnNext.setClickable(true); | |
| 170 | + fragment.binding.btnNext.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.selector_btn_green)); | |
| 171 | + } | |
| 172 | + | |
| 173 | + private void connectDevice(BleDevice bleDevice, final String wifiSSID, final String wifiPwd) { | |
| 174 | + BleManager.getInstance().disconnect(bleDevice); | |
| 175 | + BleManager.getInstance().connect(bleDevice, new BleGattCallback() { | |
| 176 | + // 开始连接 | |
| 177 | + @Override | |
| 178 | + public void onStartConnect() { | |
| 179 | + if (null == getContext()) { | |
| 180 | + return; | |
| 181 | + } | |
| 182 | + QMUITipDialogUtil.loadingDialog(getContext(), "正在连接中,请稍后...", false); | |
| 183 | + | |
| 184 | + } | |
| 185 | + | |
| 186 | + // 连接失败 | |
| 187 | + @Override | |
| 188 | + public void onConnectFail(BleDevice bleDevice, BleException exception) { | |
| 189 | + QMUITipDialogUtil.failedDialog(getContext(), "连接失败,请重试...", 2); | |
| 190 | + Log.e(TAG, "onConnectFail: " + exception); | |
| 191 | + } | |
| 192 | + | |
| 193 | + // 连接成功,BleDevice即为所连接的BLE设备 | |
| 194 | + @Override | |
| 195 | + public void onConnectSuccess(final BleDevice bleDevice, BluetoothGatt gatt, int status) { | |
| 196 | + BleManager.getInstance().notify( | |
| 197 | + bleDevice, | |
| 198 | + BlufiConstants.UUID_WIFI_SERVICE.toString(), | |
| 199 | + BlufiConstants.UUID_NOTIFY_CHARACTERISTIC.toString(), | |
| 200 | + new BleNotifyCallback() { | |
| 201 | + @Override | |
| 202 | + public void onNotifySuccess() { | |
| 203 | + | |
| 204 | + // 打开通知操作成功 | |
| 205 | + BleManager.getInstance().write( | |
| 206 | + bleDevice, | |
| 207 | + BlufiConstants.UUID_WIFI_SERVICE.toString(), | |
| 208 | + BlufiConstants.UUID_WRITE_CHARACTERISTIC.toString(), | |
| 209 | + (BlueToothUtil.getSSIDAndPwd(wifiSSID, wifiPwd, "he:28850150e8bd4c830314819939361b77")).getBytes(), | |
| 210 | + new BleWriteCallback() { | |
| 211 | + @Override | |
| 212 | + public void onWriteSuccess(int current, int total, byte[] justWrite) { | |
| 213 | + Log.e(TAG, "onWriteSuccess: " + current + "," + total); | |
| 214 | + // 发送数据到设备成功(分包发送的情况下,可以通过方法中返回的参数可以查看发送进度) | |
| 215 | + } | |
| 216 | + | |
| 217 | + @Override | |
| 218 | + public void onWriteFailure(BleException exception) { | |
| 219 | + Log.e(TAG, "onWriteFailure: "); | |
| 220 | + QMUITipDialogUtil.failedDialog(getContext(), "连接失败,请重试...", 2); | |
| 221 | + | |
| 222 | + } | |
| 223 | + }); | |
| 224 | + // | |
| 225 | + } | |
| 226 | + | |
| 227 | + @Override | |
| 228 | + public void onNotifyFailure(BleException exception) { | |
| 229 | + Log.e(TAG, "onNotifyFailure: " + exception); | |
| 230 | + QMUITipDialogUtil.failedDialog(getContext(), "连接失败,请重试...", 2); | |
| 231 | + | |
| 232 | + } | |
| 233 | + | |
| 234 | + @Override | |
| 235 | + public void onCharacteristicChanged(byte[] data) { | |
| 236 | + if (null == getContext()) { | |
| 237 | + return; | |
| 238 | + } | |
| 239 | + try { | |
| 240 | + String result = new String(data, "UTF-8"); | |
| 241 | + Log.e(TAG, "onCharacteristicChanged: " + result); | |
| 242 | + if (result.indexOf(BlufiConstants.WIFI_LINK_OK) != -1) { | |
| 243 | + BleManager.getInstance().stopNotify(bleDevice, BlufiConstants.UUID_WIFI_SERVICE.toString(), BlufiConstants.UUID_NOTIFY_CHARACTERISTIC.toString()); | |
| 244 | + BleManager.getInstance().disconnect(bleDevice); | |
| 245 | + //查询配网是否成功 | |
| 246 | + if (null == getContext()) { | |
| 247 | + return; | |
| 248 | + } | |
| 249 | + queryDeviceConfigNet(getContext()); | |
| 250 | + } else if (result.indexOf(BlufiConstants.WIFI_LINK_FAIL) != -1) { | |
| 251 | + if (null != errorDialog) { | |
| 252 | + if (!TextUtils.isEmpty(SSID)) { | |
| 253 | + errorDialog.setTipMsg(SSID + "\n密码错误"); | |
| 254 | + if (!errorDialog.isShowing()) { | |
| 255 | + errorDialog.show(); | |
| 256 | + } | |
| 257 | + } | |
| 258 | + } | |
| 259 | + QMUITipDialogUtil.dismessDialog(); | |
| 260 | + BleManager.getInstance().stopNotify(bleDevice, BlufiConstants.UUID_WIFI_SERVICE.toString(), BlufiConstants.UUID_NOTIFY_CHARACTERISTIC.toString()); | |
| 261 | + BleManager.getInstance().disconnect(bleDevice); | |
| 262 | + } | |
| 263 | + } catch (UnsupportedEncodingException e) { | |
| 264 | + e.printStackTrace(); | |
| 265 | + } | |
| 266 | + } | |
| 267 | + } | |
| 268 | + ); | |
| 269 | + | |
| 270 | + | |
| 271 | + } | |
| 272 | + | |
| 273 | + // 连接中断,isActiveDisConnected表示是否是主动调用了断开连接方法 | |
| 274 | + @Override | |
| 275 | + public void onDisConnected(boolean isActiveDisConnected, BleDevice device, BluetoothGatt gatt, int status) { | |
| 276 | + | |
| 277 | + } | |
| 278 | + }); | |
| 279 | + } | |
| 280 | + | |
| 281 | + | |
| 282 | + private void queryDeviceConfigNet(Activity activity) { | |
| 283 | + ConfigDeviceNetParam param = new ConfigDeviceNetParam(); | |
| 284 | + param.setAction("mc/getWifiResult"); | |
| 285 | + ConfigDeviceNetParam.DataBean dataBean = new ConfigDeviceNetParam.DataBean(); | |
| 286 | + dataBean.setFrom("he:28850150e8bd4c830314819939361b77"); | |
| 287 | + dataBean.setMyid("he:28850150e8bd4c830314819939361b77"); | |
| 288 | + dataBean.setToken("6fdff0f39ec659c94dd12cdc32937e9d"); | |
| 289 | + param.setData(dataBean); | |
| 290 | + fragment.getPresenter().queryConfigDeviceNetResult(activity, param); | |
| 291 | + } | |
| 59 | 292 | } |
| 60 | 293 | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/model/AllDeviceInfo.java
0 → 100644
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/model/PopMenuInfo.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.model; | |
| 2 | + | |
| 3 | +public class PopMenuInfo { | |
| 4 | + private String title; | |
| 5 | + private int imgDraw; | |
| 6 | + | |
| 7 | + public String getTitle() { | |
| 8 | + return title; | |
| 9 | + } | |
| 10 | + | |
| 11 | + public void setTitle(String title) { | |
| 12 | + this.title = title; | |
| 13 | + } | |
| 14 | + | |
| 15 | + public int getImgDraw() { | |
| 16 | + return imgDraw; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public void setImgDraw(int imgDraw) { | |
| 20 | + this.imgDraw = imgDraw; | |
| 21 | + } | |
| 22 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/ApiServiceCMCC.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork; | |
| 2 | + | |
| 3 | + | |
| 4 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.BaseInfo; | |
| 5 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.ConfigDeviceNetParam; | |
| 6 | +import com.cnlive.strike.xiaojiaspeaker.netWork.result.ConfigDeviceNetResult; | |
| 7 | + | |
| 8 | +import java.util.Map; | |
| 9 | + | |
| 10 | +import io.reactivex.Observable; | |
| 11 | +import okhttp3.RequestBody; | |
| 12 | +import retrofit2.Call; | |
| 13 | +import retrofit2.adapter.rxjava2.Result; | |
| 14 | +import retrofit2.http.Body; | |
| 15 | +import retrofit2.http.POST; | |
| 16 | +import retrofit2.http.Query; | |
| 17 | +import retrofit2.http.QueryMap; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * 移动官方接口 | |
| 21 | + */ | |
| 22 | +public interface ApiServiceCMCC { | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 查询设备配网结果 | |
| 26 | + * | |
| 27 | + * @return | |
| 28 | + */ | |
| 29 | + @POST("users/custom") | |
| 30 | + Call<ConfigDeviceNetResult> queryDeviceConfigNet(@Body ConfigDeviceNetParam param); | |
| 31 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/ApiServiceXIaoJia.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork; | |
| 2 | + | |
| 3 | + | |
| 4 | +import java.util.Map; | |
| 5 | + | |
| 6 | +import io.reactivex.Observable; | |
| 7 | +import retrofit2.adapter.rxjava2.Result; | |
| 8 | +import retrofit2.http.GET; | |
| 9 | +import retrofit2.http.POST; | |
| 10 | +import retrofit2.http.QueryMap; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 达人有关的接口 | |
| 14 | + */ | |
| 15 | +public interface ApiServiceXIaoJia { | |
| 16 | + | |
| 17 | +} | |
| 18 | + | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/ApiSubscriber.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork; | |
| 2 | + | |
| 3 | + | |
| 4 | +import com.cnlive.libs.data.network.Subscriber; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Created by xiansong on 2017/9/8. | |
| 8 | + */ | |
| 9 | + | |
| 10 | +public class ApiSubscriber { | |
| 11 | + | |
| 12 | + private static final String success_code = "0"; | |
| 13 | + private static final String success_message = "数据加载成功"; | |
| 14 | + | |
| 15 | + public static final Subscriber.Config subscriberBuild = Subscriber.newConfig() | |
| 16 | + .putInfo(Subscriber.Config.response_success, success_code, success_message) ; | |
| 17 | + | |
| 18 | + public static String getSuccessCode(){ | |
| 19 | + return success_code; | |
| 20 | + } | |
| 21 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/CmccRequest.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork; | |
| 2 | + | |
| 3 | +import com.cnlive.strike.xiaojiaspeaker.netWork.result.ConfigDeviceNetResult; | |
| 4 | + | |
| 5 | +import java.io.IOException; | |
| 6 | + | |
| 7 | +import okhttp3.Interceptor; | |
| 8 | +import okhttp3.OkHttpClient; | |
| 9 | +import okhttp3.Request; | |
| 10 | +import okhttp3.Response; | |
| 11 | +import retrofit2.Call; | |
| 12 | +import retrofit2.Retrofit; | |
| 13 | +import retrofit2.converter.gson.GsonConverterFactory; | |
| 14 | + | |
| 15 | +public class CmccRequest { | |
| 16 | + private static Retrofit retrofit; | |
| 17 | + private static Class mclass; | |
| 18 | + //移动官方接口 | |
| 19 | + private static final String CMCC_API_DEBUG_URL = "http://storybox.roobo.net/"; | |
| 20 | + private static final String CMCC_API_REA_URL = "https://storybox-api.roobo.com/rtoy/"; | |
| 21 | + private static String TAG = "CmccRequest"; | |
| 22 | + | |
| 23 | + //错误状态码 | |
| 24 | + public static final int ERROR_5 = -5;//更新数据失败 | |
| 25 | + public static final int SUCCRSS = 0;//成功 | |
| 26 | + | |
| 27 | + public static ApiServiceCMCC getInstance(Class<ApiServiceCMCC> mclass) { | |
| 28 | + if (null == retrofit) { | |
| 29 | + // 创建Retrofit对象 | |
| 30 | + retrofit = new Retrofit.Builder() | |
| 31 | + .baseUrl(CMCC_API_REA_URL)//设置网络请求url,后面一段写在网络请求接口里面 | |
| 32 | + .addConverterFactory(GsonConverterFactory.create())//添加Gson支持,然后Retrofit就会使用Gson将响应体(api接口的Take)转换我们想要的类型。 | |
| 33 | + .client(new OkHttpClient.Builder().addInterceptor(new Interceptor() { | |
| 34 | + @Override | |
| 35 | + public Response intercept(Chain chain) throws IOException { | |
| 36 | + Request request = chain.request() | |
| 37 | + .newBuilder() | |
| 38 | + .addHeader("Content-Type", "application/json;charset=UTF-8") | |
| 39 | + .build(); | |
| 40 | + return chain.proceed(request); | |
| 41 | + } | |
| 42 | + }).build()) | |
| 43 | + .build(); | |
| 44 | + } | |
| 45 | + return retrofit.create(mclass); | |
| 46 | + } | |
| 47 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/SubscriptionRequest.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | + | |
| 5 | +import com.cnlive.libs.base.application.AppConfig; | |
| 6 | +import com.cnlive.libs.base.logic.callback.DataCallback; | |
| 7 | +import com.cnlive.libs.data.network.ApiBuild; | |
| 8 | +import com.cnlive.libs.data.network.Subscriber; | |
| 9 | +import com.cnlive.libs.data.network.interceptor.NetPPEncryptInterceptor; | |
| 10 | +import com.cnlive.libs.data.network.interceptor.NetPPPayEncryptInterceptor; | |
| 11 | +import com.cnlive.libs.data.network.interceptor.SignEncryptInterceptor; | |
| 12 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.BaseInfo; | |
| 13 | + | |
| 14 | +import io.reactivex.android.schedulers.AndroidSchedulers; | |
| 15 | +import io.reactivex.disposables.Disposable; | |
| 16 | +import io.reactivex.schedulers.Schedulers; | |
| 17 | +import okhttp3.Interceptor; | |
| 18 | +import retrofit2.adapter.rxjava2.Result; | |
| 19 | + | |
| 20 | +import static com.cnlive.libs.base.logic.Config.SUCCESS; | |
| 21 | + | |
| 22 | +/** | |
| 23 | + * Created by Lynn on 2019/3/27. | |
| 24 | + * modify by ShinnyYang | |
| 25 | + */ | |
| 26 | +public class SubscriptionRequest<Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> { | |
| 27 | + private static final String SP_CMS_URL_DEBUT = "http://cmstest.cnlive.com:8768/"; | |
| 28 | + private static final String SP_CMS_URL = "http://cms.cnlive.com:8768/"; | |
| 29 | + private static final int OKHTTP_KEEP_ALIVE_DURATION_SECONDS = 10; | |
| 30 | + //OPEN API 接口域名 | |
| 31 | + private static final String OPEN_URL = "https://api.cnlive.com/"; | |
| 32 | + //网++ 接口域名 | |
| 33 | + public static final String SP_BASE_URL = "https://apiwjj.cnlive.com/"; | |
| 34 | + //网++ 测试环境 接口域名 | |
| 35 | + public static final String SP_DEBUG_URL = "http://apiwjjtest.cnlive.com/"; | |
| 36 | + //OPEN API 接口域名 | |
| 37 | + private Observable observable; | |
| 38 | + //移动官方接口 | |
| 39 | + public static final String CMCC_API_DEBUG_URL = "http://storybox.roobo.net/"; | |
| 40 | + public static final String CMCC_API_REA_URL = "https://storybox-api.roobo.com/rtoy/"; | |
| 41 | + | |
| 42 | + private static <T> String baseCMSEndpoint() { | |
| 43 | + return AppConfig.isDebug() ? SP_CMS_URL_DEBUT : SP_CMS_URL; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public static <T> String baseEndpoint() { | |
| 47 | + return AppConfig.isDebug() ? SP_DEBUG_URL : SP_BASE_URL; | |
| 48 | + } | |
| 49 | + | |
| 50 | + private static <T> String serviceEndpoint(Class<T> clazz) { | |
| 51 | + //中国移动直接用正式环境 | |
| 52 | + if (clazz == ApiServiceCMCC.class) { | |
| 53 | + return CMCC_API_REA_URL; | |
| 54 | + } | |
| 55 | +// else if (clazz == ApiServiceCMCC.class) { | |
| 56 | +// return BAIDU_TRACE_URL; | |
| 57 | +// } else { | |
| 58 | + return baseEndpoint(); | |
| 59 | +// } | |
| 60 | + } | |
| 61 | + | |
| 62 | + public static <Service, Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> | |
| 63 | + SubscriptionRequest<Observable, BaseData> service(Class<Service> clazz, ApiBuild.Api<Service, Observable, BaseData> api) { | |
| 64 | + return service(clazz, api, new SignEncryptInterceptor()); | |
| 65 | + } | |
| 66 | + | |
| 67 | + public static <Service, Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> | |
| 68 | + SubscriptionRequest<Observable, BaseData> cmccService(Class<Service> clazz, ApiBuild.Api<Service, Observable, BaseData> api) { | |
| 69 | + return service(clazz, api, null); | |
| 70 | + } | |
| 71 | + | |
| 72 | + public static <Service> Service service(Class<Service> clazz) { | |
| 73 | + return service(clazz, new SignEncryptInterceptor()); | |
| 74 | + } | |
| 75 | + | |
| 76 | + | |
| 77 | + private static <Service> Service service(Class<Service> clazz, Interceptor... interceptor) { | |
| 78 | + return service(clazz, false, interceptor); | |
| 79 | + } | |
| 80 | + | |
| 81 | + private static <Service> Service service(Class<Service> clazz, boolean decode, Interceptor... interceptor) { | |
| 82 | + return ApiBuild.service(clazz, null) | |
| 83 | + .setEndpoint(serviceEndpoint(clazz)) | |
| 84 | + .addInterceptor(interceptor) | |
| 85 | + .service(decode, OKHTTP_KEEP_ALIVE_DURATION_SECONDS); | |
| 86 | + } | |
| 87 | + | |
| 88 | + public static <Service, Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> | |
| 89 | + SubscriptionRequest<Observable, BaseData> serviceEncrypt(Class<Service> clazz, ApiBuild.Api<Service, Observable, BaseData> api) { | |
| 90 | + return service(clazz, api, new NetPPEncryptInterceptor()); | |
| 91 | + } | |
| 92 | + | |
| 93 | + public static <Service, Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> | |
| 94 | + SubscriptionRequest<Observable, BaseData> servicePayEncrypt(Class<Service> clazz, ApiBuild.Api<Service, Observable, BaseData> api) { | |
| 95 | + return service(clazz, api, new NetPPPayEncryptInterceptor()); | |
| 96 | + } | |
| 97 | + | |
| 98 | + private static <Service, Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> | |
| 99 | + SubscriptionRequest<Observable, BaseData> service(Class<Service> clazz, ApiBuild.Api<Service, Observable, BaseData> api, Interceptor... interceptor) { | |
| 100 | + | |
| 101 | + SubscriptionRequest<Observable, BaseData> request = new SubscriptionRequest<Observable, BaseData>(); | |
| 102 | + | |
| 103 | + request.observable = ApiBuild.service(clazz, api) | |
| 104 | + .setEndpoint(serviceEndpoint(clazz)) | |
| 105 | + .addInterceptor(interceptor) | |
| 106 | + .build(false); | |
| 107 | + | |
| 108 | + return request; | |
| 109 | + } | |
| 110 | + | |
| 111 | + public Disposable subscribe(Context context, final DataCallback<BaseData> callback) { | |
| 112 | + Subscriber<BaseData> subscriber = new Subscriber<BaseData>(context) { | |
| 113 | + @Override | |
| 114 | + public void onCompleted(String s, String s1, BaseData data) { | |
| 115 | + if (callback == null) { | |
| 116 | + return; | |
| 117 | + } | |
| 118 | + callback.callback(SUCCESS, "", data); | |
| 119 | + } | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public void onError(String code, String message) { | |
| 123 | + if (callback == null) { | |
| 124 | + return; | |
| 125 | + } | |
| 126 | + int errorCode = -1; | |
| 127 | + try { | |
| 128 | + errorCode = Integer.valueOf(code); | |
| 129 | + } catch (Exception ignored) { | |
| 130 | + } | |
| 131 | + | |
| 132 | + callback.callback(errorCode, message, null); | |
| 133 | + } | |
| 134 | + }; | |
| 135 | + | |
| 136 | + return observable.take(1) | |
| 137 | + .subscribeOn(Schedulers.io()) | |
| 138 | + .observeOn(AndroidSchedulers.mainThread()) | |
| 139 | + .subscribe(subscriber.next, subscriber.error, subscriber.complete, subscriber.subscribe); | |
| 140 | + } | |
| 141 | + | |
| 142 | + public static <Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> | |
| 143 | + Disposable subscribe(Observable observable, Subscriber<BaseData> subscriber) { | |
| 144 | + return observable.take(1) | |
| 145 | + .subscribeOn(Schedulers.io()) | |
| 146 | + .observeOn(AndroidSchedulers.mainThread()) | |
| 147 | + .subscribe(subscriber.next, subscriber.error, subscriber.complete, subscriber.subscribe); | |
| 148 | + } | |
| 149 | +/***************************************************************************************/ | |
| 150 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/bean/BaseInfo.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork.bean; | |
| 2 | + | |
| 3 | +import com.cnlive.libs.data.network.model.IBaseInfo; | |
| 4 | +import com.cnlive.strike.xiaojiaspeaker.netWork.ApiSubscriber; | |
| 5 | + | |
| 6 | + | |
| 7 | +public class BaseInfo<T> implements IBaseInfo { | |
| 8 | + //TODO 接口错误信息 需要自定义 | |
| 9 | + private String errorCode = ApiSubscriber.getSuccessCode(); | |
| 10 | + private String errorMessage = ""; | |
| 11 | + | |
| 12 | + //TODO 接口内容数据 需要自定义 | |
| 13 | + private T data; | |
| 14 | + | |
| 15 | + public void setCode(String status_code) { | |
| 16 | + this.errorCode = status_code; | |
| 17 | + } | |
| 18 | + | |
| 19 | + @Override | |
| 20 | + public String getCode() { | |
| 21 | + return errorCode; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public void setMessage(String errorMessage) { | |
| 25 | + this.errorMessage = errorMessage; | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public String getMessage() { | |
| 30 | + return errorMessage; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public void setData(T data) { | |
| 34 | + this.data = data; | |
| 35 | + } | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public T getData() { | |
| 39 | + return data; | |
| 40 | + } | |
| 41 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/bean/ConfigDeviceNetParam.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork.bean; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 配网结果查询参数 | |
| 5 | + * | |
| 6 | + * @author ys | |
| 7 | + */ | |
| 8 | +public class ConfigDeviceNetParam { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * action : mc/getWifiResult | |
| 12 | + * data : {"myid":"1234567890ab","token":"xxxxx","from":"sessionId"} | |
| 13 | + */ | |
| 14 | + public ConfigDeviceNetParam() { | |
| 15 | + this.action = "mc/getWifiResult"; | |
| 16 | + } | |
| 17 | + | |
| 18 | + private String action; | |
| 19 | + private DataBean data; | |
| 20 | + | |
| 21 | + public String getAction() { | |
| 22 | + return action; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public void setAction(String action) { | |
| 26 | + this.action = action; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public DataBean getData() { | |
| 30 | + return data; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public void setData(DataBean data) { | |
| 34 | + this.data = data; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public static class DataBean { | |
| 38 | + /** | |
| 39 | + * myid : 1234567890ab | |
| 40 | + * token : xxxxx | |
| 41 | + * from : sessionId | |
| 42 | + */ | |
| 43 | + | |
| 44 | + private String myid; | |
| 45 | + private String token; | |
| 46 | + private String from; | |
| 47 | + | |
| 48 | + public String getMyid() { | |
| 49 | + return myid; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public void setMyid(String myid) { | |
| 53 | + this.myid = myid; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public String getToken() { | |
| 57 | + return token; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public void setToken(String token) { | |
| 61 | + this.token = token; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public String getFrom() { | |
| 65 | + return from; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public void setFrom(String from) { | |
| 69 | + this.from = from; | |
| 70 | + } | |
| 71 | + } | |
| 72 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/result/ConfigDeviceNetResult.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.netWork.result; | |
| 2 | + | |
| 3 | +public class ConfigDeviceNetResult { | |
| 4 | + | |
| 5 | + /** | |
| 6 | + * result : 0 | |
| 7 | + * msg : success | |
| 8 | + * data : {"mainctl":"4000119C000011AE","token":"6ff1ba3f2e62352b7a95ef943e33b368","pid":"he:28850150e8bd4c830314819939361b77","agentId":"UxN2JkZTg3OTYzMT","timestamp":1568615885732,"result":"success","isFirstBinded":false,"isBinded":true,"bindtel":"+86 132****5668"} | |
| 9 | + */ | |
| 10 | + | |
| 11 | + private int result; | |
| 12 | + private String msg; | |
| 13 | + private DataBean data; | |
| 14 | + | |
| 15 | + public int getResult() { | |
| 16 | + return result; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public void setResult(int result) { | |
| 20 | + this.result = result; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public String getMsg() { | |
| 24 | + return msg; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public void setMsg(String msg) { | |
| 28 | + this.msg = msg; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public DataBean getData() { | |
| 32 | + return data; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public void setData(DataBean data) { | |
| 36 | + this.data = data; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public static class DataBean { | |
| 40 | + /** | |
| 41 | + * mainctl : 4000119C000011AE | |
| 42 | + * token : 6ff1ba3f2e62352b7a95ef943e33b368 | |
| 43 | + * pid : he:28850150e8bd4c830314819939361b77 | |
| 44 | + * agentId : UxN2JkZTg3OTYzMT | |
| 45 | + * timestamp : 1568615885732 | |
| 46 | + * result : success | |
| 47 | + * isFirstBinded : false | |
| 48 | + * isBinded : true | |
| 49 | + * bindtel : +86 132****5668 | |
| 50 | + */ | |
| 51 | + | |
| 52 | + private String mainctl; | |
| 53 | + private String token; | |
| 54 | + private String pid; | |
| 55 | + private String agentId; | |
| 56 | + private long timestamp; | |
| 57 | + private String result; | |
| 58 | + private boolean isFirstBinded; | |
| 59 | + private boolean isBinded; | |
| 60 | + private String bindtel; | |
| 61 | + | |
| 62 | + public String getMainctl() { | |
| 63 | + return mainctl; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void setMainctl(String mainctl) { | |
| 67 | + this.mainctl = mainctl; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public String getToken() { | |
| 71 | + return token; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public void setToken(String token) { | |
| 75 | + this.token = token; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public String getPid() { | |
| 79 | + return pid; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public void setPid(String pid) { | |
| 83 | + this.pid = pid; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public String getAgentId() { | |
| 87 | + return agentId; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public void setAgentId(String agentId) { | |
| 91 | + this.agentId = agentId; | |
| 92 | + } | |
| 93 | + | |
| 94 | + public long getTimestamp() { | |
| 95 | + return timestamp; | |
| 96 | + } | |
| 97 | + | |
| 98 | + public void setTimestamp(long timestamp) { | |
| 99 | + this.timestamp = timestamp; | |
| 100 | + } | |
| 101 | + | |
| 102 | + public String getResult() { | |
| 103 | + return result; | |
| 104 | + } | |
| 105 | + | |
| 106 | + public void setResult(String result) { | |
| 107 | + this.result = result; | |
| 108 | + } | |
| 109 | + | |
| 110 | + public boolean isIsFirstBinded() { | |
| 111 | + return isFirstBinded; | |
| 112 | + } | |
| 113 | + | |
| 114 | + public void setIsFirstBinded(boolean isFirstBinded) { | |
| 115 | + this.isFirstBinded = isFirstBinded; | |
| 116 | + } | |
| 117 | + | |
| 118 | + public boolean isIsBinded() { | |
| 119 | + return isBinded; | |
| 120 | + } | |
| 121 | + | |
| 122 | + public void setIsBinded(boolean isBinded) { | |
| 123 | + this.isBinded = isBinded; | |
| 124 | + } | |
| 125 | + | |
| 126 | + public String getBindtel() { | |
| 127 | + return bindtel; | |
| 128 | + } | |
| 129 | + | |
| 130 | + public void setBindtel(String bindtel) { | |
| 131 | + this.bindtel = bindtel; | |
| 132 | + } | |
| 133 | + } | |
| 134 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/AllDeviceActivity.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.activity; | |
| 2 | + | |
| 3 | +import android.database.DatabaseUtils; | |
| 4 | +import android.databinding.DataBindingUtil; | |
| 5 | +import android.support.v4.content.ContextCompat; | |
| 6 | +import android.support.v7.app.AppCompatActivity; | |
| 7 | +import android.os.Bundle; | |
| 8 | +import android.view.View; | |
| 9 | + | |
| 10 | +import com.cnlive.libs.base.util.StatusBarUtil; | |
| 11 | +import com.cnlive.libs.base.util.StatusBarUtil2; | |
| 12 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 13 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ActivityAllDeviceBinding; | |
| 14 | +import com.cnlive.strike.xiaojiaspeaker.ui.fragment.AllDeviceFragment; | |
| 15 | +import com.cnlive.strike.xiaojiaspeaker.ui.fragment.SearchDevicefragment; | |
| 16 | +import com.cnlive.strike.xiaojiaspeaker.ui.fragment.SelectWifiFragment; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * 所有设备 | |
| 20 | + * | |
| 21 | + * @author ys | |
| 22 | + */ | |
| 23 | +public class AllDeviceActivity extends AppCompatActivity { | |
| 24 | + private ActivityAllDeviceBinding binding; | |
| 25 | + | |
| 26 | + @Override | |
| 27 | + protected void onCreate(Bundle savedInstanceState) { | |
| 28 | + super.onCreate(savedInstanceState); | |
| 29 | + binding = DataBindingUtil.setContentView(this, R.layout.activity_all_device); | |
| 30 | + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, AllDeviceFragment.newInstance()).commitAllowingStateLoss(); | |
| 31 | + | |
| 32 | + } | |
| 33 | + | |
| 34 | + | |
| 35 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/BlueToothStep1Activity.java
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/BlueToothStep2Activity.java
| ... | ... | @@ -29,6 +29,7 @@ import com.cnlive.strike.xiaojiaspeaker.databinding.ActivityBlueToothStep2Bindin |
| 29 | 29 | import com.cnlive.strike.xiaojiaspeaker.ui.widget.SelectDialog; |
| 30 | 30 | import com.cnlive.strike.xiaojiaspeaker.util.lib_permisshelper.PermissionsListener; |
| 31 | 31 | import com.cnlive.strike.xiaojiaspeaker.util.lib_permisshelper.PermissionsUtils; |
| 32 | +import com.cnlive.strike.xiaojiaspeaker.util.utilcode.CheckUtil; | |
| 32 | 33 | |
| 33 | 34 | public class BlueToothStep2Activity extends AppCompatActivity { |
| 34 | 35 | private ActivityBlueToothStep2Binding binding; |
| ... | ... | @@ -76,8 +77,14 @@ public class BlueToothStep2Activity extends AppCompatActivity { |
| 76 | 77 | binding.btnNext.setOnClickListener(new View.OnClickListener() { |
| 77 | 78 | @Override |
| 78 | 79 | public void onClick(View view) { |
| 79 | - //判断蓝牙是否打开 | |
| 80 | - getPermissionsWithTip(); | |
| 80 | + //判断GPS是否打开 | |
| 81 | + boolean isOpenGPS = CheckUtil.isOPenGps(BlueToothStep2Activity.this); | |
| 82 | + if (!isOpenGPS) { | |
| 83 | + CheckUtil.openGPS(BlueToothStep2Activity.this); | |
| 84 | + } else { | |
| 85 | + //判断蓝牙是否打开 | |
| 86 | + getPermissionsWithTip(); | |
| 87 | + } | |
| 81 | 88 | } |
| 82 | 89 | }); |
| 83 | 90 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/BluetoothConnActivity.java
| ... | ... | @@ -3,9 +3,13 @@ package com.cnlive.strike.xiaojiaspeaker.ui.activity; |
| 3 | 3 | import android.bluetooth.BluetoothAdapter; |
| 4 | 4 | import android.bluetooth.BluetoothDevice; |
| 5 | 5 | import android.bluetooth.BluetoothGatt; |
| 6 | +import android.content.BroadcastReceiver; | |
| 7 | +import android.content.Context; | |
| 6 | 8 | import android.content.Intent; |
| 9 | +import android.content.IntentFilter; | |
| 7 | 10 | import android.databinding.DataBindingUtil; |
| 8 | 11 | import android.os.Bundle; |
| 12 | +import android.os.Message; | |
| 9 | 13 | import android.support.v7.app.AppCompatActivity; |
| 10 | 14 | import android.support.v7.widget.DefaultItemAnimator; |
| 11 | 15 | import android.support.v7.widget.LinearLayoutManager; |
| ... | ... | @@ -29,6 +33,9 @@ import com.cnlive.strike.xiaojiaspeaker.databinding.ActivityBluetoothMainBinding |
| 29 | 33 | import com.cnlive.strike.xiaojiaspeaker.model.BlueToothMsgEvent; |
| 30 | 34 | import com.cnlive.strike.xiaojiaspeaker.model.BluetoothDeviceInfo; |
| 31 | 35 | import com.cnlive.strike.xiaojiaspeaker.ui.adapter.BluetoothDeviceAdapter; |
| 36 | +import com.cnlive.strike.xiaojiaspeaker.ui.adapter.BluetoothListViewAdapterTest; | |
| 37 | +import com.cnlive.strike.xiaojiaspeaker.ui.adapter.WifiRecycleAdapter; | |
| 38 | +import com.cnlive.strike.xiaojiaspeaker.util.QMUITipDialogUtil; | |
| 32 | 39 | |
| 33 | 40 | import org.greenrobot.eventbus.EventBus; |
| 34 | 41 | import org.greenrobot.eventbus.Subscribe; |
| ... | ... | @@ -46,203 +53,22 @@ public class BluetoothConnActivity extends AppCompatActivity { |
| 46 | 53 | private static final String TAG = "BluetoothConnActivity"; |
| 47 | 54 | private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); |
| 48 | 55 | private ActivityBluetoothMainBinding binding; |
| 49 | - private List<BleDevice> bleDevices = new ArrayList<>(); | |
| 50 | - private BluetoothDeviceAdapter adapter; | |
| 56 | + private BluetoothListViewAdapterTest adapter; | |
| 57 | + private List<BluetoothDevice> unbondDevices = new ArrayList<>(); // 用于存放未配对蓝牙设备 | |
| 58 | + private List<BluetoothDevice> bondDevices = new ArrayList<>();// 用于存放已配对蓝牙设备 | |
| 59 | + private BluetoothListViewAdapterTest bondAdapter = null; | |
| 60 | + private BluetoothListViewAdapterTest unBondAdapter = null; | |
| 51 | 61 | |
| 52 | 62 | @Override |
| 53 | 63 | protected void onCreate(Bundle savedInstanceState) { |
| 54 | 64 | super.onCreate(savedInstanceState); |
| 55 | 65 | binding = DataBindingUtil.setContentView(this, R.layout.activity_bluetooth_main); |
| 56 | 66 | initView(); |
| 57 | - initBlueToothScanConfig(); | |
| 58 | - initListAdapter(); | |
| 59 | - openBluetooth(); | |
| 60 | 67 | if (!EventBus.getDefault().isRegistered(this)) { |
| 61 | 68 | EventBus.getDefault().register(this); |
| 62 | 69 | } |
| 63 | 70 | } |
| 64 | 71 | |
| 65 | - private void initListAdapter() { | |
| 66 | - adapter = new BluetoothDeviceAdapter(this, bleDevices); | |
| 67 | - adapter.setHasStableIds(true); | |
| 68 | - binding.rvBlueTooth.setLayoutManager(new LinearLayoutManager(BluetoothConnActivity.this)); | |
| 69 | - binding.rvBlueTooth.setAdapter(adapter); | |
| 70 | - ((DefaultItemAnimator) binding.rvBlueTooth.getItemAnimator()).setSupportsChangeAnimations(false); | |
| 71 | - adapter.setOnItemClickListener(new BluetoothDeviceAdapter.OnItemClickListener() { | |
| 72 | - @Override | |
| 73 | - public void onItemClick(int position, BleDevice bleDevice) { | |
| 74 | - BleManager.getInstance().disconnect(bleDevice); | |
| 75 | - BleManager.getInstance().connect(bleDevice, new BleGattCallback() { | |
| 76 | - // 开始连接 | |
| 77 | - @Override | |
| 78 | - public void onStartConnect() { | |
| 79 | - | |
| 80 | - } | |
| 81 | - | |
| 82 | - // 连接失败 | |
| 83 | - @Override | |
| 84 | - public void onConnectFail(BleDevice bleDevice, BleException exception) { | |
| 85 | - | |
| 86 | - } | |
| 87 | - | |
| 88 | - // 连接成功,BleDevice即为所连接的BLE设备 | |
| 89 | - @Override | |
| 90 | - public void onConnectSuccess(final BleDevice bleDevice, BluetoothGatt gatt, int status) { | |
| 91 | - | |
| 92 | - BleManager.getInstance().notify( | |
| 93 | - bleDevice, | |
| 94 | - BlufiConstants.UUID_WIFI_SERVICE.toString(), | |
| 95 | - BlufiConstants.UUID_NOTIFY_CHARACTERISTIC.toString(), | |
| 96 | - new BleNotifyCallback() { | |
| 97 | - @Override | |
| 98 | - public void onNotifySuccess() { | |
| 99 | - Log.e(TAG, "onNotifySuccess: " ); | |
| 100 | - // 打开通知操作成功 | |
| 101 | - BleManager.getInstance().write( | |
| 102 | - bleDevice, | |
| 103 | - BlufiConstants.UUID_WIFI_SERVICE.toString(), | |
| 104 | - BlufiConstants.UUID_WRITE_CHARACTERISTIC.toString(), | |
| 105 | - (getSSIDAndPwd("CNLive-VIP", "cnlIVE_99", "he:28850150e8bd4c830314819939361b77")).getBytes(), | |
| 106 | - new BleWriteCallback() { | |
| 107 | - @Override | |
| 108 | - public void onWriteSuccess(int current, int total, byte[] justWrite) { | |
| 109 | - Log.e(TAG, "onWriteSuccess: " + justWrite.toString()); | |
| 110 | - // 发送数据到设备成功(分包发送的情况下,可以通过方法中返回的参数可以查看发送进度) | |
| 111 | - | |
| 112 | -// if (mIsExit) { | |
| 113 | -// return; | |
| 114 | -// } | |
| 115 | - | |
| 116 | - if (current == total) { | |
| 117 | -// BleManager.getInstance().stopNotify(bleDevice, | |
| 118 | -// BlufiConstants.UUID_WIFI_SERVICE.toString(), | |
| 119 | -// BlufiConstants.UUID_NOTIFY_CHARACTERISTIC.toString()); | |
| 120 | - } | |
| 121 | - } | |
| 122 | - | |
| 123 | - @Override | |
| 124 | - public void onWriteFailure(BleException exception) { | |
| 125 | - Log.e(TAG, "onWriteFailure: "); | |
| 126 | - | |
| 127 | -// if (mIsExit) { | |
| 128 | -// return; | |
| 129 | -// } | |
| 130 | - | |
| 131 | -// mainHandler.post(new Runnable() { | |
| 132 | -// @Override | |
| 133 | -// public void run() { | |
| 134 | -// // 发送数据到设备失败 | |
| 135 | -// getActivityView().onSendWifiFailure("数据发送失败,请确认设备蓝牙正常"); | |
| 136 | -// } | |
| 137 | -// }); | |
| 138 | - | |
| 139 | -// BleManager.getInstance().stopNotify(bleDevice, | |
| 140 | -// BlufiConstants.UUID_WIFI_SERVICE.toString(), | |
| 141 | -// BlufiConstants.UUID_NOTIFY_CHARACTERISTIC.toString()); | |
| 142 | - } | |
| 143 | - }); | |
| 144 | - // | |
| 145 | - } | |
| 146 | - | |
| 147 | - @Override | |
| 148 | - public void onNotifyFailure(BleException exception) { | |
| 149 | - Log.e(TAG, "onNotifyFailure: "+exception ); | |
| 150 | - } | |
| 151 | - | |
| 152 | - @Override | |
| 153 | - public void onCharacteristicChanged(byte[] data) { | |
| 154 | - try { | |
| 155 | - Log.e(TAG, "onCharacteristicChanged: "+ new String(data,"UTF-8")); | |
| 156 | - } catch (UnsupportedEncodingException e) { | |
| 157 | - e.printStackTrace(); | |
| 158 | - } | |
| 159 | - } | |
| 160 | - } | |
| 161 | - ); | |
| 162 | - | |
| 163 | - | |
| 164 | - } | |
| 165 | - | |
| 166 | - // 连接中断,isActiveDisConnected表示是否是主动调用了断开连接方法 | |
| 167 | - @Override | |
| 168 | - public void onDisConnected(boolean isActiveDisConnected, BleDevice device, BluetoothGatt gatt, int status) { | |
| 169 | - | |
| 170 | - } | |
| 171 | - }); | |
| 172 | - // | |
| 173 | - | |
| 174 | - // | |
| 175 | - | |
| 176 | - } | |
| 177 | - }); | |
| 178 | - } | |
| 179 | - | |
| 180 | - public String getSSIDAndPwd(String ssid, String pwd, String uid) { | |
| 181 | - StringBuilder builder = new StringBuilder(); | |
| 182 | - builder.append("1111("); | |
| 183 | - builder.append("v1"); | |
| 184 | - builder.append('#'); | |
| 185 | - builder.append(encode(ssid)); | |
| 186 | - builder.append('#'); | |
| 187 | - builder.append(encode(pwd)); | |
| 188 | - builder.append('#'); | |
| 189 | - builder.append(encode(uid)); | |
| 190 | - builder.append('#'); | |
| 191 | - builder.append(")2222"); | |
| 192 | - String info = builder.toString(); | |
| 193 | - String infoSend = info.replaceAll("(.{16})", "$1DATA"); | |
| 194 | - return "DATA" + infoSend; | |
| 195 | - } | |
| 196 | - | |
| 197 | - /** | |
| 198 | - * 初始化蓝牙扫描 | |
| 199 | - */ | |
| 200 | - private void initBlueToothScanConfig() { | |
| 201 | - BleManager.getInstance().init(getApplication()); | |
| 202 | - BleScanRuleConfig scanRuleConfig = new BleScanRuleConfig.Builder() | |
| 203 | -// .setServiceUuids(serviceUuids) // 只扫描指定的服务的设备,可选 | |
| 204 | -// .setDeviceName(true, names) // 只扫描指定广播名的设备,可选 | |
| 205 | -// .setDeviceMac(mac) // 只扫描指定mac的设备,可选 | |
| 206 | -// .setAutoConnect(isAutoConnect) // 连接时的autoConnect参数,可选,默认false | |
| 207 | - .setScanTimeOut(15000) // 扫描超时时间,可选,默认10秒;小于等于0表示不限制扫描时间 | |
| 208 | - .build(); | |
| 209 | - BleManager.getInstance().initScanRule(scanRuleConfig); | |
| 210 | - } | |
| 211 | - | |
| 212 | - /** | |
| 213 | - * 开始扫描蓝牙设备 | |
| 214 | - */ | |
| 215 | - public void scanBlueToothDevice() { | |
| 216 | - if (null != bleDevices) { | |
| 217 | - bleDevices.clear(); | |
| 218 | - } | |
| 219 | - BleManager.getInstance().scan(new BleScanCallback() { | |
| 220 | - // 扫描结束,列出所有扫描到的符合扫描规则的BLE设备(主线程) | |
| 221 | - @Override | |
| 222 | - public void onScanFinished(List<BleDevice> scanResultList) { | |
| 223 | - binding.rlProgress.setVisibility(View.GONE); | |
| 224 | - | |
| 225 | - } | |
| 226 | - | |
| 227 | - // 开始扫描(主线程) | |
| 228 | - @Override | |
| 229 | - public void onScanStarted(boolean success) { | |
| 230 | - binding.rlProgress.setVisibility(View.VISIBLE); | |
| 231 | - } | |
| 232 | - | |
| 233 | - // 扫描到一个符合扫描规则的BLE设备(主线程) | |
| 234 | - @Override | |
| 235 | - public void onScanning(BleDevice bleDevice) { | |
| 236 | -// Log.e(TAG, "onScanning: " + GsonUtils.toJson(bleDevice)); | |
| 237 | - if (TextUtils.isEmpty(bleDevice.getName())) { | |
| 238 | - return; | |
| 239 | - } | |
| 240 | - if (null != adapter) { | |
| 241 | - adapter.addListData(bleDevice); | |
| 242 | - } | |
| 243 | - } | |
| 244 | - }); | |
| 245 | - } | |
| 246 | 72 | |
| 247 | 73 | @Override |
| 248 | 74 | protected void onPause() { |
| ... | ... | @@ -266,13 +92,25 @@ public class BluetoothConnActivity extends AppCompatActivity { |
| 266 | 92 | } |
| 267 | 93 | |
| 268 | 94 | private void initView() { |
| 95 | + if (null == adapter) { | |
| 96 | + adapter = new BluetoothListViewAdapterTest(this, unbondDevices); | |
| 97 | + binding.rvBlueTooth.setLayoutManager(new LinearLayoutManager(this)); | |
| 98 | + binding.rvBlueTooth.setAdapter(adapter); | |
| 99 | + } | |
| 100 | + adapter.setOnItemClickListener(new BluetoothListViewAdapterTest.OnItemClickListener() { | |
| 101 | + @Override | |
| 102 | + public void onClick(int position, BluetoothDevice bluetoothDevice) { | |
| 103 | + BluetoothConnThread connThread = new BluetoothConnThread(BluetoothConnActivity.this, position,bluetoothDevice); | |
| 104 | + connThread.start(); | |
| 105 | + } | |
| 106 | + }); | |
| 269 | 107 | //搜索蓝牙设备按钮 |
| 270 | 108 | binding.btnScanBluetooth.setOnClickListener(new View.OnClickListener() { |
| 271 | 109 | @Override |
| 272 | 110 | public void onClick(View view) { |
| 273 | 111 | binding.rlProgress.setVisibility(View.VISIBLE); |
| 274 | 112 | if (isBluetoothOpen()) { |
| 275 | - scanBlueToothDevice(); | |
| 113 | + searchDevices(); | |
| 276 | 114 | } else { |
| 277 | 115 | openBluetooth(); |
| 278 | 116 | } |
| ... | ... | @@ -348,42 +186,46 @@ public class BluetoothConnActivity extends AppCompatActivity { |
| 348 | 186 | } |
| 349 | 187 | } |
| 350 | 188 | |
| 351 | -// /** | |
| 352 | -// * 搜索蓝牙的方法 | |
| 353 | -// */ | |
| 354 | -// private void startScanBluth() { | |
| 189 | + /** | |
| 190 | + * 搜索蓝牙的方法 | |
| 191 | + */ | |
| 192 | + private void startScanBluth() { | |
| 193 | + if (null!=unbondDevices){ | |
| 194 | + unbondDevices.clear(); | |
| 195 | + } | |
| 196 | + if(null!=adapter){ | |
| 197 | + adapter.notifyDataSetChanged(); | |
| 198 | + } | |
| 355 | 199 | // getBondBluetoothDeviceData(); |
| 356 | -// // 判断是否在搜索,如果在搜索,就取消搜索 | |
| 357 | -// if (mBluetoothAdapter.isDiscovering()) { | |
| 358 | -// mBluetoothAdapter.cancelDiscovery(); | |
| 359 | -// } else { | |
| 360 | -// // 开始搜索 | |
| 361 | -// mBluetoothAdapter.startDiscovery(); | |
| 200 | + // 判断是否在搜索,如果在搜索,就取消搜索 | |
| 201 | + if (mBluetoothAdapter.isDiscovering()) { | |
| 202 | + mBluetoothAdapter.cancelDiscovery(); | |
| 203 | + } else { | |
| 204 | + // 开始搜索 | |
| 205 | + mBluetoothAdapter.startDiscovery(); | |
| 362 | 206 | // QMUITipDialogUtil.loadingDialog(this, "正在搜索蓝牙设备,请稍后...", false); |
| 363 | -// | |
| 364 | -// } | |
| 365 | -// | |
| 366 | -// } | |
| 367 | 207 | |
| 208 | + } | |
| 368 | 209 | |
| 369 | -// /** | |
| 370 | -// * 注册异步搜索蓝牙设备的广播 | |
| 371 | -// */ | |
| 372 | -// private void searchDevices() { | |
| 373 | -// // 找到设备的广播 | |
| 374 | -// IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); | |
| 375 | -// filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); | |
| 376 | -// // 注册广播 | |
| 377 | -// registerReceiver(receiver, filter); | |
| 378 | -// isRegisterReceiver = true; | |
| 379 | -// // 搜索完成的广播 | |
| 380 | -// IntentFilter filter1 = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); | |
| 381 | -// // 注册广播 | |
| 382 | -// registerReceiver(receiver, filter1); | |
| 383 | -// isRegisterReceiver = true; | |
| 384 | -// Log.e(TAG, "startDiscovery: 注册广播"); | |
| 385 | -// startScanBluth(); | |
| 386 | -// } | |
| 210 | + } | |
| 211 | + | |
| 212 | + | |
| 213 | + /** | |
| 214 | + * 注册异步搜索蓝牙设备的广播 | |
| 215 | + */ | |
| 216 | + private void searchDevices() { | |
| 217 | + // 找到设备的广播 | |
| 218 | + IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); | |
| 219 | + filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); | |
| 220 | + // 注册广播 | |
| 221 | + registerReceiver(receiver, filter); | |
| 222 | + // 搜索完成的广播 | |
| 223 | + IntentFilter filter1 = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); | |
| 224 | + // 注册广播 | |
| 225 | + registerReceiver(receiver, filter1); | |
| 226 | + Log.e(TAG, "startDiscovery: 注册广播"); | |
| 227 | + startScanBluth(); | |
| 228 | + } | |
| 387 | 229 | |
| 388 | 230 | |
| 389 | 231 | /** |
| ... | ... | @@ -480,17 +322,119 @@ public class BluetoothConnActivity extends AppCompatActivity { |
| 480 | 322 | } |
| 481 | 323 | } |
| 482 | 324 | |
| 483 | - private String encode(String str) { | |
| 484 | - StringBuilder builder = new StringBuilder(); | |
| 485 | - for (int i = 0; i < str.length(); ++i) { | |
| 486 | - char ch = str.charAt(i); | |
| 487 | - if (ch == '#') { | |
| 488 | - builder.append('\\'); | |
| 489 | - } else if (ch == '\\') { | |
| 490 | - builder.append('\\'); | |
| 325 | + /** | |
| 326 | + * 广播接收器 | |
| 327 | + */ | |
| 328 | + private BroadcastReceiver receiver = new BroadcastReceiver() { | |
| 329 | + BluetoothDevice device = null; | |
| 330 | + | |
| 331 | + | |
| 332 | + @Override | |
| 333 | + public void onReceive(final Context context, Intent intent) { | |
| 334 | + // 收到的广播类型 | |
| 335 | + String action = intent.getAction(); | |
| 336 | + // 发现设备的广播 | |
| 337 | + if (BluetoothDevice.ACTION_FOUND.equals(action)) { | |
| 338 | + // 从intent中获取设备 | |
| 339 | + device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); | |
| 340 | + if (TextUtils.isEmpty(device.getName())){ | |
| 341 | + return; | |
| 342 | + } | |
| 343 | + // 只获取未配对设备 | |
| 344 | + Log.e(TAG, "蓝牙设备状态:" + device.getBondState()); | |
| 345 | + if (device.getBondState() == BluetoothDevice.BOND_NONE) { | |
| 346 | + adapter.updateList(device); | |
| 347 | + } | |
| 348 | + Log.e(TAG, "unbondDevices大小:" + unbondDevices.size()); | |
| 349 | + // 搜索完成 | |
| 350 | + } | |
| 351 | + if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { | |
| 352 | + QMUITipDialogUtil.dismessDialog(); | |
| 353 | +// //-1代表没有设备连接 | |
| 354 | +// BluetoothInfo bluetoothInfo = new BluetoothInfo(); | |
| 355 | +// if (unbondDevices.size() > 0) { | |
| 356 | +// bluetoothInfo.bluetoothDeviceList = unbondDevices; | |
| 357 | +// bluetoothInfo.position = -1; | |
| 358 | +// unBondAdapter = new BluetoothListViewAdapterTest(context, bluetoothInfo); | |
| 359 | +// lv_unBondBluetoothDevice.setAdapter(unBondAdapter); | |
| 360 | +//// setListViewHeightBasedOnChildren(lv_unBondBluetoothDevice); | |
| 361 | +// Log.e(TAG, "onReceive: 搜索完成"); | |
| 362 | +// } else { | |
| 363 | +// ToastUtil.msg(getApplicationContext(), "暂未发现可用的蓝牙设备!"); | |
| 364 | +// } | |
| 365 | + } | |
| 366 | + //状态改变时 | |
| 367 | + else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) { | |
| 368 | + device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); | |
| 369 | + switch (device.getBondState()) { | |
| 370 | + case BluetoothDevice.BOND_BONDING://正在配对 | |
| 371 | + Log.e("BlueToothTestActivity", "正在配对......"); | |
| 372 | + QMUITipDialogUtil.loadingDialog(getApplicationContext(),"正在配对......",false); | |
| 373 | +// if (progressDialog == null) { | |
| 374 | +// progressDialog = new ProgressDialog(BluetoothConnActivity.this); | |
| 375 | +// } | |
| 376 | +// progressDialog.setMessage("正在配对中,请稍后!"); | |
| 377 | +// progressDialog.show(); | |
| 378 | + break; | |
| 379 | + case BluetoothDevice.BOND_BONDED://配对结束 | |
| 380 | + Log.e("BlueToothTestActivity", "完成配对"); | |
| 381 | + QMUITipDialogUtil.dismessDialog(); | |
| 382 | +// QMUITipDialogUtil.successDialog(me, "配对已完成", 2); | |
| 383 | +// bondDevices.clear(); | |
| 384 | +// bondDevices = getBondedBluetoothDevice(); | |
| 385 | +// Log.e(TAG, "已配对蓝牙设备数量:" + bondDevices.size()); | |
| 386 | +// BluetoothInfo bluetoothInfo = new BluetoothInfo(); | |
| 387 | +// bluetoothInfo.position = -1; | |
| 388 | +// bluetoothInfo.bluetoothDeviceList = bondDevices; | |
| 389 | +// bondAdapter = new BluetoothListViewAdapterTest(BluetoothConnActivity.this, bluetoothInfo); | |
| 390 | +// lv_bondBluetoothDevice.setAdapter(bondAdapter); | |
| 391 | +// | |
| 392 | +// unBondAdapter.notifyDataSetChanged();//刷新未绑定列表 | |
| 393 | +// unbondDevices.remove(device); | |
| 394 | + | |
| 395 | + break; | |
| 396 | + case BluetoothDevice.BOND_NONE://取消配对/未配对 | |
| 397 | + Log.e("BlueToothTestActivity", "取消配对"); | |
| 398 | +// Message msg = new Message(); | |
| 399 | +// msg.what = Constant.BOND_BLUETOOTH_FAILED; | |
| 400 | +// handler.sendMessage(msg); | |
| 401 | + default: | |
| 402 | + break; | |
| 403 | + } | |
| 491 | 404 | } |
| 492 | - builder.append(ch); | |
| 493 | 405 | } |
| 494 | - return builder.toString(); | |
| 495 | - } | |
| 406 | + }; | |
| 407 | + | |
| 408 | + | |
| 409 | + private BroadcastReceiver mStatusReceive = new BroadcastReceiver() { | |
| 410 | + | |
| 411 | + @Override | |
| 412 | + public void onReceive(Context context, Intent intent) { | |
| 413 | + switch (intent.getAction()) { | |
| 414 | + case BluetoothAdapter.ACTION_STATE_CHANGED: | |
| 415 | + int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0); | |
| 416 | + switch (blueState) { | |
| 417 | + case BluetoothAdapter.STATE_TURNING_ON: | |
| 418 | + Log.e(TAG, "监听到蓝牙已开启"); | |
| 419 | +// mdialog = LoadingUtil.dialog(BluetoothConnActivity.this, "正在开启蓝牙,请稍后...", false); | |
| 420 | +// mdialog.show(); | |
| 421 | + break; | |
| 422 | + case BluetoothAdapter.STATE_ON: | |
| 423 | + Log.e(TAG, "监听到蓝牙已启动"); | |
| 424 | + QMUITipDialogUtil.dismessDialog(); | |
| 425 | + AlertUtil.showDeftToast(getApplicationContext(), "蓝牙已打开!"); | |
| 426 | +// getBondBluetoothDeviceData(); | |
| 427 | + //开始扫描 | |
| 428 | + break; | |
| 429 | + case BluetoothAdapter.STATE_TURNING_OFF: | |
| 430 | + break; | |
| 431 | + case BluetoothAdapter.STATE_OFF: | |
| 432 | + AlertUtil.showDeftToast(getApplicationContext(), "蓝牙未打开!"); | |
| 433 | + break; | |
| 434 | + } | |
| 435 | + break; | |
| 436 | + } | |
| 437 | + } | |
| 438 | + }; | |
| 439 | + | |
| 496 | 440 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/ConnBluetoothSuccessActivity.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.activity; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.databinding.DataBindingUtil; | |
| 6 | +import android.support.v4.content.ContextCompat; | |
| 7 | +import android.support.v7.app.AppCompatActivity; | |
| 8 | +import android.os.Bundle; | |
| 9 | +import android.view.View; | |
| 10 | + | |
| 11 | +import com.cnlive.libs.base.util.AlertUtil; | |
| 12 | +import com.cnlive.libs.base.util.StatusBarUtil; | |
| 13 | +import com.cnlive.libs.base.util.StatusBarUtil2; | |
| 14 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 15 | +import com.cnlive.strike.xiaojiaspeaker.commonInfo.CommInfo; | |
| 16 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ActivityConnBluetoothSuccessBinding; | |
| 17 | +import com.daimajia.androidanimations.library.Techniques; | |
| 18 | +import com.daimajia.androidanimations.library.YoYo; | |
| 19 | +import com.daimajia.androidanimations.library.zooming_exits.ZoomOutDownAnimator; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * 音箱连接成功页面 | |
| 23 | + * | |
| 24 | + * @author ys | |
| 25 | + */ | |
| 26 | +public class ConnBluetoothSuccessActivity extends AppCompatActivity { | |
| 27 | + private ActivityConnBluetoothSuccessBinding binding; | |
| 28 | + | |
| 29 | + @Override | |
| 30 | + protected void onCreate(Bundle savedInstanceState) { | |
| 31 | + super.onCreate(savedInstanceState); | |
| 32 | + binding = DataBindingUtil.setContentView(this, R.layout.activity_conn_bluetooth_success); | |
| 33 | + initTopBar(); | |
| 34 | + initView(); | |
| 35 | + } | |
| 36 | + | |
| 37 | + private void initView() { | |
| 38 | + //判断是否显示礼物弹窗 | |
| 39 | + boolean isShow = CommInfo.getIsShowConnGift(this); | |
| 40 | + if (isShow) { | |
| 41 | + showGift(); | |
| 42 | + } else { | |
| 43 | + hideGift(); | |
| 44 | + } | |
| 45 | + //前往听见中国 | |
| 46 | + binding.tvGoToListenChina.setOnClickListener(new View.OnClickListener() { | |
| 47 | + @Override | |
| 48 | + public void onClick(View view) { | |
| 49 | + } | |
| 50 | + }); | |
| 51 | + //礼物弹窗关闭 | |
| 52 | + binding.ivCloseGift.setOnClickListener(new View.OnClickListener() { | |
| 53 | + @Override | |
| 54 | + public void onClick(View view) { | |
| 55 | + YoYo.with(Techniques.ZoomOutDown) | |
| 56 | + .duration(700) | |
| 57 | + .repeat(0) | |
| 58 | + .playOn(binding.llGift); | |
| 59 | + binding.llGiftBlack.setVisibility(View.GONE); | |
| 60 | + //设置弹窗不在弹出 | |
| 61 | + CommInfo.setIsShowConnGift(ConnBluetoothSuccessActivity.this, false); | |
| 62 | + } | |
| 63 | + }); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void showGift() { | |
| 67 | + binding.llGiftBlack.setVisibility(View.VISIBLE); | |
| 68 | + binding.llGift.setVisibility(View.VISIBLE); | |
| 69 | + } | |
| 70 | + | |
| 71 | + public void hideGift() { | |
| 72 | + binding.llGiftBlack.setVisibility(View.GONE); | |
| 73 | + binding.llGift.setVisibility(View.GONE); | |
| 74 | + } | |
| 75 | + | |
| 76 | + private void initTopBar() { | |
| 77 | + StatusBarUtil.setStatusBarWrite(this); | |
| 78 | + StatusBarUtil2.setColor(this, ContextCompat.getColor(this, R.color.white), 0); | |
| 79 | + if (null != binding) { | |
| 80 | + binding.topbar.setTitle("连接成功"); | |
| 81 | + //设置返回按钮 | |
| 82 | + binding.topbar.addLeftImageButton(R.drawable.icon_back, R.id.left_back).setOnClickListener(new View.OnClickListener() { | |
| 83 | + @Override | |
| 84 | + public void onClick(View view) { | |
| 85 | + finish(); | |
| 86 | + } | |
| 87 | + }); | |
| 88 | + } | |
| 89 | + } | |
| 90 | + | |
| 91 | + public static void startActivity(Activity activity) { | |
| 92 | + activity.startActivity(new Intent(activity, ConnBluetoothSuccessActivity.class)); | |
| 93 | + } | |
| 94 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/DeviceInstructionActivity.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.activity; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.databinding.DataBindingUtil; | |
| 6 | +import android.support.v4.content.ContextCompat; | |
| 7 | +import android.support.v7.app.AppCompatActivity; | |
| 8 | +import android.os.Bundle; | |
| 9 | +import android.view.View; | |
| 10 | + | |
| 11 | +import com.cnlive.libs.base.util.StatusBarUtil; | |
| 12 | +import com.cnlive.libs.base.util.StatusBarUtil2; | |
| 13 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 14 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ActivityDeviceInstructionBinding; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * 设备说明 | |
| 18 | + * | |
| 19 | + * @author ys | |
| 20 | + */ | |
| 21 | +public class DeviceInstructionActivity extends AppCompatActivity { | |
| 22 | + private ActivityDeviceInstructionBinding binding; | |
| 23 | + | |
| 24 | + @Override | |
| 25 | + protected void onCreate(Bundle savedInstanceState) { | |
| 26 | + super.onCreate(savedInstanceState); | |
| 27 | + binding = DataBindingUtil.setContentView(this, R.layout.activity_device_instruction); | |
| 28 | + initTopBar(); | |
| 29 | + } | |
| 30 | + | |
| 31 | + private void initTopBar() { | |
| 32 | + StatusBarUtil.setStatusBarWrite(this); | |
| 33 | + StatusBarUtil2.setColor(this, ContextCompat.getColor(this, R.color.white), 0); | |
| 34 | + if (null != binding) { | |
| 35 | + binding.topbar.setTitle("设备说明"); | |
| 36 | + //设置返回按钮 | |
| 37 | + binding.topbar.addLeftImageButton(R.drawable.icon_back, R.id.left_back).setOnClickListener(new View.OnClickListener() { | |
| 38 | + @Override | |
| 39 | + public void onClick(View view) { | |
| 40 | + finish(); | |
| 41 | + } | |
| 42 | + }); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + public static void startActivity(Activity activity) { | |
| 47 | + activity.startActivity(new Intent(activity, DeviceInstructionActivity.class)); | |
| 48 | + } | |
| 49 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/SelectWifiActivity.java
| ... | ... | @@ -49,7 +49,7 @@ public class SelectWifiActivity extends AppCompatActivity { |
| 49 | 49 | wifiUtils = new WifiUtils(this); |
| 50 | 50 | // registerBroadcast(); |
| 51 | 51 | // getPermissionsWithTip(); |
| 52 | - getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SelectWifiFragment()).commitAllowingStateLoss(); | |
| 52 | + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, SelectWifiFragment.newInstance(bleDevice)).commitAllowingStateLoss(); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/SpeakerMainActivity.java
| ... | ... | @@ -155,30 +155,30 @@ public class SpeakerMainActivity extends AppCompatActivity implements WifiChange |
| 155 | 155 | // } |
| 156 | 156 | // } |
| 157 | 157 | |
| 158 | - adapter.setOnItemClickListener(new WifiRecycleAdapter.onItemClickListener() { | |
| 159 | - @Override | |
| 160 | - public void onItemClick(int position, final WifiConnModel wifiConnModel) { | |
| 161 | - new Thread(new Runnable() { | |
| 162 | - @Override | |
| 163 | - public void run() { | |
| 164 | - try { | |
| 165 | - Log.e(TAG, "run: " + i); | |
| 166 | - byte[] msgBuffer = null; | |
| 167 | - String text = "---------Hello World---------- "; | |
| 168 | - String ip = wifiUtils.getConnectedIPAddr(); | |
| 169 | - Socket socket = new Socket(ip, 9101); | |
| 170 | - socket.setSoTimeout(5000); | |
| 171 | - PrintStream out = new PrintStream(socket.getOutputStream()); | |
| 172 | - out.println(00); | |
| 173 | - out.flush(); | |
| 174 | - out.close(); | |
| 175 | - socket.close(); | |
| 176 | - } catch (Exception e) { | |
| 177 | - e.printStackTrace(); | |
| 178 | - } | |
| 179 | - SystemClock.sleep(5000); | |
| 180 | - } | |
| 181 | - }).start(); | |
| 158 | +// adapter.setOnItemClickListener(new WifiRecycleAdapter.onItemClickListener() { | |
| 159 | +// @Override | |
| 160 | +// public void onItemClick(int position, final WifiConnModel wifiConnModel) { | |
| 161 | +// new Thread(new Runnable() { | |
| 162 | +// @Override | |
| 163 | +// public void run() { | |
| 164 | +// try { | |
| 165 | +// Log.e(TAG, "run: " + i); | |
| 166 | +// byte[] msgBuffer = null; | |
| 167 | +// String text = "---------Hello World---------- "; | |
| 168 | +// String ip = wifiUtils.getConnectedIPAddr(); | |
| 169 | +// Socket socket = new Socket(ip, 9101); | |
| 170 | +// socket.setSoTimeout(5000); | |
| 171 | +// PrintStream out = new PrintStream(socket.getOutputStream()); | |
| 172 | +// out.println(00); | |
| 173 | +// out.flush(); | |
| 174 | +// out.close(); | |
| 175 | +// socket.close(); | |
| 176 | +// } catch (Exception e) { | |
| 177 | +// e.printStackTrace(); | |
| 178 | +// } | |
| 179 | +// SystemClock.sleep(5000); | |
| 180 | +// } | |
| 181 | +// }).start(); | |
| 182 | 182 | // selectSSID = wifiConnModel.getScanResult().SSID; |
| 183 | 183 | // Log.e(TAG, "onItemClick: "+wifiConnModel.getScanResult() ); |
| 184 | 184 | // connErrorCount = 0; |
| ... | ... | @@ -224,8 +224,8 @@ public class SpeakerMainActivity extends AppCompatActivity implements WifiChange |
| 224 | 224 | // wifiUtils.connectWifi(networkId); |
| 225 | 225 | // } |
| 226 | 226 | // } |
| 227 | - } | |
| 228 | - }); | |
| 227 | +// } | |
| 228 | +// }); | |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/AllDeviceAdapter.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.adapter; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.databinding.DataBindingUtil; | |
| 5 | +import android.graphics.Color; | |
| 6 | +import android.support.annotation.NonNull; | |
| 7 | +import android.support.v4.content.ContextCompat; | |
| 8 | +import android.support.v7.widget.RecyclerView; | |
| 9 | +import android.util.Log; | |
| 10 | +import android.view.LayoutInflater; | |
| 11 | +import android.view.View; | |
| 12 | +import android.view.ViewGroup; | |
| 13 | + | |
| 14 | +import com.clj.fastble.data.BleDevice; | |
| 15 | +import com.cnlive.strike.application.GlideApp; | |
| 16 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 17 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ListItemAllDeviceBinding; | |
| 18 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ListItemBluetoothDeviceBinding; | |
| 19 | +import com.cnlive.strike.xiaojiaspeaker.model.AllDeviceInfo; | |
| 20 | +import com.cnlive.strike.xiaojiaspeaker.model.PopMenuInfo; | |
| 21 | +import com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu.PopMenu; | |
| 22 | + | |
| 23 | +import java.util.ArrayList; | |
| 24 | +import java.util.List; | |
| 25 | + | |
| 26 | +public class AllDeviceAdapter extends RecyclerView.Adapter { | |
| 27 | + private Context context; | |
| 28 | + private List<AllDeviceInfo> allDeviceInfos; | |
| 29 | + private OnItemClickListener onItemClickListener; | |
| 30 | + private OnAddClickListener onAddClickListener; | |
| 31 | + private String TAG = "AllDeviceAdapter"; | |
| 32 | + | |
| 33 | + public AllDeviceAdapter(Context context, List<AllDeviceInfo> allDeviceInfos) { | |
| 34 | + this.context = context; | |
| 35 | + this.allDeviceInfos = allDeviceInfos; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { | |
| 39 | + this.onItemClickListener = onItemClickListener; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void setOnAddClickListener(OnAddClickListener onAddClickListener) { | |
| 43 | + this.onAddClickListener = onAddClickListener; | |
| 44 | + } | |
| 45 | + | |
| 46 | + @NonNull | |
| 47 | + @Override | |
| 48 | + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { | |
| 49 | + LayoutInflater inflater = LayoutInflater.from(context); | |
| 50 | + ListItemAllDeviceBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_all_device, viewGroup, false); | |
| 51 | + return new MyViewHolder(binding); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) { | |
| 56 | + final ListItemAllDeviceBinding binding = ((MyViewHolder) viewHolder).getBinding(); | |
| 57 | + if (i == allDeviceInfos.size()) { | |
| 58 | + //显示添加设备 | |
| 59 | + binding.llAdd.setVisibility(View.VISIBLE); | |
| 60 | + binding.rlRoot.setVisibility(View.GONE); | |
| 61 | + } else { | |
| 62 | + //隐藏添加设备 | |
| 63 | + binding.llAdd.setVisibility(View.GONE); | |
| 64 | + binding.rlRoot.setVisibility(View.VISIBLE); | |
| 65 | + GlideApp.with(context) | |
| 66 | + .load(ContextCompat.getDrawable(context, R.drawable.icon_xiaojia)) | |
| 67 | + .skipMemoryCache(false) | |
| 68 | + .placeholder(ContextCompat.getDrawable(context, R.drawable.icon_xiaojia)) | |
| 69 | + .dontAnimate() | |
| 70 | + .into(binding.ivBluetoothDeviceIcon); | |
| 71 | + } | |
| 72 | + | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Override | |
| 76 | + public int getItemCount() { | |
| 77 | + return allDeviceInfos.size() + 1; | |
| 78 | + } | |
| 79 | + | |
| 80 | + | |
| 81 | + private class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | |
| 82 | + public ListItemAllDeviceBinding getBinding() { | |
| 83 | + return binding; | |
| 84 | + } | |
| 85 | + | |
| 86 | + private ListItemAllDeviceBinding binding; | |
| 87 | + | |
| 88 | + public MyViewHolder(ListItemAllDeviceBinding binding) { | |
| 89 | + super(binding.getRoot()); | |
| 90 | + this.binding = binding; | |
| 91 | + binding.rlRoot.setOnClickListener(this); | |
| 92 | + binding.llAdd.setOnClickListener(this); | |
| 93 | + } | |
| 94 | + | |
| 95 | + @Override | |
| 96 | + public void onClick(View view) { | |
| 97 | + if (R.id.rl_root == view.getId()) { | |
| 98 | + if (null != onItemClickListener) { | |
| 99 | + onItemClickListener.onItemClick(getAdapterPosition(), allDeviceInfos.get(getAdapterPosition())); | |
| 100 | + | |
| 101 | + } | |
| 102 | + Log.e(TAG, "onClick: " + getAdapterPosition()); | |
| 103 | + } else if (R.id.ll_add == view.getId()) { | |
| 104 | + if (null != onAddClickListener) { | |
| 105 | + onAddClickListener.onAddClick(); | |
| 106 | + } | |
| 107 | + Log.e(TAG, "onAddClickListener: " + getAdapterPosition()); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + | |
| 111 | +// public View.OnClickListener mOnclick = new View.OnClickListener() { | |
| 112 | +// @Override | |
| 113 | +// public void onClick(View view) { | |
| 114 | +// if (R.id.rl_root == view.getId()) { | |
| 115 | +// if (null != onItemClickListener) { | |
| 116 | +// onItemClickListener.onItemClick(getAdapterPosition(), allDeviceInfos.get(getAdapterPosition())); | |
| 117 | +// } | |
| 118 | +// } else if (R.id.ll_add == view.getId()) { | |
| 119 | +// if (null != onAddClickListener) { | |
| 120 | +// onAddClickListener.onAddClick(); | |
| 121 | +// } | |
| 122 | +// } | |
| 123 | +// } | |
| 124 | +// }; | |
| 125 | + } | |
| 126 | + | |
| 127 | + public interface OnItemClickListener { | |
| 128 | + void onItemClick(int position, AllDeviceInfo AllDeviceInfo); | |
| 129 | + } | |
| 130 | + | |
| 131 | + public interface OnAddClickListener { | |
| 132 | + void onAddClick(); | |
| 133 | + } | |
| 134 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/BluetoothDeviceAdapter.java
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/BluetoothListViewAdapterTest.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.adapter; | |
| 2 | + | |
| 3 | +import android.bluetooth.BluetoothDevice; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.databinding.DataBindingUtil; | |
| 6 | +import android.support.annotation.NonNull; | |
| 7 | +import android.support.v7.widget.RecyclerView; | |
| 8 | +import android.view.LayoutInflater; | |
| 9 | +import android.view.View; | |
| 10 | +import android.view.ViewGroup; | |
| 11 | + | |
| 12 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 13 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ListItemBluetoothDeviceBinding; | |
| 14 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ListItemWifi1Binding; | |
| 15 | + | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | +public class BluetoothListViewAdapterTest extends RecyclerView.Adapter { | |
| 19 | + private Context context; | |
| 20 | + private List<BluetoothDevice> bluetoothDevices; | |
| 21 | + private OnItemClickListener onItemClickListener; | |
| 22 | + | |
| 23 | + public void updateList(BluetoothDevice bluetoothDevice) { | |
| 24 | + bluetoothDevices.add(bluetoothDevice); | |
| 25 | + notifyDataSetChanged(); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { | |
| 29 | + this.onItemClickListener = onItemClickListener; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public BluetoothListViewAdapterTest(Context context, List<BluetoothDevice> bluetoothDevices) { | |
| 33 | + this.context = context; | |
| 34 | + this.bluetoothDevices = bluetoothDevices; | |
| 35 | + } | |
| 36 | + | |
| 37 | + @NonNull | |
| 38 | + @Override | |
| 39 | + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { | |
| 40 | + LayoutInflater inflater = LayoutInflater.from(context); | |
| 41 | + ListItemBluetoothDeviceBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_bluetooth_device, viewGroup, false); | |
| 42 | + return new MyViewHolder(binding); | |
| 43 | + } | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) { | |
| 47 | + ListItemBluetoothDeviceBinding binding = ((MyViewHolder) viewHolder).getBinding(); | |
| 48 | + binding.tvDeviceName.setText(bluetoothDevices.get(i).getName()); | |
| 49 | + binding.llRoot.setOnClickListener(new View.OnClickListener() { | |
| 50 | + @Override | |
| 51 | + public void onClick(View view) { | |
| 52 | + if (null != onItemClickListener) { | |
| 53 | + onItemClickListener.onClick(i, bluetoothDevices.get(i)); | |
| 54 | + } | |
| 55 | + } | |
| 56 | + }); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Override | |
| 60 | + public int getItemCount() { | |
| 61 | + return bluetoothDevices.size(); | |
| 62 | + } | |
| 63 | + | |
| 64 | + private class MyViewHolder extends RecyclerView.ViewHolder { | |
| 65 | + | |
| 66 | + public ListItemBluetoothDeviceBinding getBinding() { | |
| 67 | + return binding; | |
| 68 | + } | |
| 69 | + | |
| 70 | + private ListItemBluetoothDeviceBinding binding; | |
| 71 | + | |
| 72 | + public MyViewHolder(ListItemBluetoothDeviceBinding binding) { | |
| 73 | + super(binding.getRoot()); | |
| 74 | + this.binding = binding; | |
| 75 | + } | |
| 76 | + } | |
| 77 | + | |
| 78 | + public interface OnItemClickListener { | |
| 79 | + void onClick(int position, BluetoothDevice bluetoothDevice); | |
| 80 | + } | |
| 81 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/PopMenuAdapter.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.adapter; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.databinding.DataBindingUtil; | |
| 5 | +import android.support.annotation.NonNull; | |
| 6 | +import android.support.v7.widget.RecyclerView; | |
| 7 | +import android.view.LayoutInflater; | |
| 8 | +import android.view.View; | |
| 9 | +import android.view.ViewGroup; | |
| 10 | + | |
| 11 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 12 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ListItemWifi1Binding; | |
| 13 | +import com.cnlive.strike.xiaojiaspeaker.databinding.PopItemMenuBinding; | |
| 14 | +import com.cnlive.strike.xiaojiaspeaker.model.PopMenuInfo; | |
| 15 | + | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | +public class PopMenuAdapter extends RecyclerView.Adapter { | |
| 19 | + private Context context; | |
| 20 | + private List<PopMenuInfo> popMenuInfoList; | |
| 21 | + | |
| 22 | + public PopMenuAdapter(Context context, List<PopMenuInfo> popMenuInfoList) { | |
| 23 | + this.context = context; | |
| 24 | + this.popMenuInfoList = popMenuInfoList; | |
| 25 | + } | |
| 26 | + | |
| 27 | + @NonNull | |
| 28 | + @Override | |
| 29 | + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { | |
| 30 | + LayoutInflater inflater = LayoutInflater.from(context); | |
| 31 | + PopItemMenuBinding binding = DataBindingUtil.inflate(inflater, R.layout.pop_item_menu, viewGroup, false); | |
| 32 | + return new MyViewHolder(binding); | |
| 33 | + } | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) { | |
| 37 | + PopItemMenuBinding binding = ((MyViewHolder) viewHolder).getBinding(); | |
| 38 | + binding.tvTip.setText(popMenuInfoList.get(i).getTitle()); | |
| 39 | + if (i == popMenuInfoList.size() - 1) { | |
| 40 | + binding.viewLine.setVisibility(View.GONE); | |
| 41 | + } else { | |
| 42 | + binding.viewLine.setVisibility(View.VISIBLE); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public int getItemCount() { | |
| 48 | + return popMenuInfoList.size(); | |
| 49 | + } | |
| 50 | + | |
| 51 | + private class MyViewHolder extends RecyclerView.ViewHolder { | |
| 52 | + | |
| 53 | + private PopItemMenuBinding binding; | |
| 54 | + | |
| 55 | + public PopItemMenuBinding getBinding() { | |
| 56 | + return binding; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public MyViewHolder(PopItemMenuBinding binding) { | |
| 60 | + super(binding.getRoot()); | |
| 61 | + this.binding = binding; | |
| 62 | + } | |
| 63 | + } | |
| 64 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/WifiRecycleAdapter.java
| ... | ... | @@ -102,14 +102,14 @@ public class WifiRecycleAdapter extends RecyclerView.Adapter { |
| 102 | 102 | // binding.tvWifiState.setText("正在连接..."); |
| 103 | 103 | // } |
| 104 | 104 | //// |
| 105 | -// binding.rlRoot.setOnClickListener(new View.OnClickListener() { | |
| 106 | -// @Override | |
| 107 | -// public void onClick(View view) { | |
| 108 | -// if (null != onItemClickListener) { | |
| 109 | -// onItemClickListener.onItemClick(position, scanResults.get(position)); | |
| 110 | -// } | |
| 111 | -// } | |
| 112 | -// }); | |
| 105 | + binding.rlRoot.setOnClickListener(new View.OnClickListener() { | |
| 106 | + @Override | |
| 107 | + public void onClick(View view) { | |
| 108 | + if (null != onItemClickListener) { | |
| 109 | + onItemClickListener.onItemClick(position, scanResults.get(position)); | |
| 110 | + } | |
| 111 | + } | |
| 112 | + }); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | @Override |
| ... | ... | @@ -154,7 +154,7 @@ public class WifiRecycleAdapter extends RecyclerView.Adapter { |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | public interface onItemClickListener { |
| 157 | - void onItemClick(int position, WifiConnModel wifiConnModel); | |
| 157 | + void onItemClick(int position, ScanResult scanResult); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/AllDeviceFragment.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.fragment; | |
| 2 | + | |
| 3 | +import android.Manifest; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.graphics.Color; | |
| 6 | +import android.os.Bundle; | |
| 7 | +import android.support.annotation.Nullable; | |
| 8 | +import android.support.v4.content.ContextCompat; | |
| 9 | +import android.support.v7.widget.LinearLayoutManager; | |
| 10 | +import android.support.v7.widget.RecyclerView; | |
| 11 | +import android.view.Display; | |
| 12 | +import android.view.LayoutInflater; | |
| 13 | +import android.view.View; | |
| 14 | +import android.view.ViewGroup; | |
| 15 | +import android.widget.Button; | |
| 16 | +import android.widget.LinearLayout; | |
| 17 | +import android.widget.PopupWindow; | |
| 18 | +import android.widget.RelativeLayout; | |
| 19 | + | |
| 20 | +import com.cnlive.libs.base.application.AppConfig; | |
| 21 | +import com.cnlive.libs.base.frame.fragment.MvpBindingFragment; | |
| 22 | +import com.cnlive.libs.base.util.AlertUtil; | |
| 23 | +import com.cnlive.libs.base.util.StatusBarUtil; | |
| 24 | +import com.cnlive.libs.base.util.StatusBarUtil2; | |
| 25 | +import com.cnlive.strike.ui.widget.UIPopup; | |
| 26 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 27 | +import com.cnlive.strike.xiaojiaspeaker.databinding.FragmentAllDeviceBinding; | |
| 28 | +import com.cnlive.strike.xiaojiaspeaker.frame.presenter.AllDeviceFragmentPresenter; | |
| 29 | +import com.cnlive.strike.xiaojiaspeaker.frame.view.AllDeviceFragmentView; | |
| 30 | +import com.cnlive.strike.xiaojiaspeaker.model.PopMenuInfo; | |
| 31 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothStep1Activity; | |
| 32 | +import com.cnlive.strike.xiaojiaspeaker.ui.adapter.PopMenuAdapter; | |
| 33 | +import com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu.PopMenu; | |
| 34 | +import com.qmuiteam.qmui.alpha.QMUIAlphaButton; | |
| 35 | +import com.qmuiteam.qmui.alpha.QMUIAlphaImageButton; | |
| 36 | +import com.qmuiteam.qmui.widget.popup.QMUIPopup; | |
| 37 | + | |
| 38 | +import java.util.ArrayList; | |
| 39 | +import java.util.List; | |
| 40 | + | |
| 41 | +public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, AllDeviceFragmentPresenter, Object, FragmentAllDeviceBinding> { | |
| 42 | + private UIPopup qmuiPopup; | |
| 43 | + | |
| 44 | + public static AllDeviceFragment newInstance() { | |
| 45 | + AllDeviceFragment fragment = new AllDeviceFragment(); | |
| 46 | + return fragment; | |
| 47 | + } | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + protected int getLayoutId() { | |
| 51 | + return R.layout.fragment_all_device; | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |
| 56 | + super.onActivityCreated(savedInstanceState); | |
| 57 | + } | |
| 58 | + | |
| 59 | + QMUIAlphaImageButton button; | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | |
| 63 | + super.onViewCreated(view, savedInstanceState); | |
| 64 | + initTopBar(); | |
| 65 | + if (null != getMvpView()) { | |
| 66 | + getMvpView().initView(); | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + private void initTopBar() { | |
| 71 | + StatusBarUtil.setStatusBarWrite(getActivity()); | |
| 72 | + StatusBarUtil2.setColor(getActivity(), ContextCompat.getColor(getActivity(), R.color.white), 0); | |
| 73 | + if (null != binding) { | |
| 74 | + binding.topbar.setTitle("所有设备"); | |
| 75 | + //设置返回按钮 | |
| 76 | + binding.topbar.addLeftImageButton(R.drawable.icon_back, R.id.left_back).setOnClickListener(new View.OnClickListener() { | |
| 77 | + @Override | |
| 78 | + public void onClick(View view) { | |
| 79 | + } | |
| 80 | + }); | |
| 81 | + //添加设备按钮 | |
| 82 | + button = binding.topbar.addRightImageButton(R.drawable.icon_item_add, R.id.right_add); | |
| 83 | + button.setOnClickListener(new View.OnClickListener() { | |
| 84 | + @Override | |
| 85 | + public void onClick(View view) { | |
| 86 | + BlueToothStep1Activity.startActivity(getActivity()); | |
| 87 | +// AddClick(); | |
| 88 | + } | |
| 89 | + }); | |
| 90 | + } | |
| 91 | + } | |
| 92 | + | |
| 93 | + private void AddClick() { | |
| 94 | + List<PopMenuInfo> popMenuInfoList = new ArrayList<>(); | |
| 95 | + PopMenuInfo popMenuInfo = new PopMenuInfo(); | |
| 96 | + popMenuInfo.setTitle("11"); | |
| 97 | + popMenuInfoList.add(popMenuInfo); | |
| 98 | + popMenuInfo = new PopMenuInfo(); | |
| 99 | + popMenuInfo.setTitle("22"); | |
| 100 | + popMenuInfoList.add(popMenuInfo); | |
| 101 | + popMenuInfo = new PopMenuInfo(); | |
| 102 | + popMenuInfo.setTitle("33"); | |
| 103 | + popMenuInfoList.add(popMenuInfo); | |
| 104 | + | |
| 105 | + PopMenu mPopMenu = new PopMenu.Builder(getActivity()) | |
| 106 | + .addData(popMenuInfoList) | |
| 107 | + .setBackgroundColor(Color.GRAY) | |
| 108 | + //.setCancelable(false) | |
| 109 | + .setCornerRadius(10f) | |
| 110 | + .build(); | |
| 111 | + mPopMenu.show(button); | |
| 112 | + } | |
| 113 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/SearchDevicefragment.java
| 1 | 1 | package com.cnlive.strike.xiaojiaspeaker.ui.fragment; |
| 2 | 2 | |
| 3 | 3 | import android.os.Bundle; |
| 4 | +import android.os.Handler; | |
| 4 | 5 | import android.support.annotation.Nullable; |
| 5 | 6 | import android.support.v4.content.ContextCompat; |
| 6 | 7 | import android.view.View; |
| ... | ... | @@ -22,6 +23,7 @@ import com.hannesdorfmann.mosby3.mvp.MvpFragment; |
| 22 | 23 | * @author ys |
| 23 | 24 | */ |
| 24 | 25 | public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmentView, SearchDevicefragmentPresenter, Object, FragmentSearchDeviceBinding> { |
| 26 | + | |
| 25 | 27 | @Override |
| 26 | 28 | protected int getLayoutId() { |
| 27 | 29 | return R.layout.fragment_search_device; |
| ... | ... | @@ -71,7 +73,7 @@ public class SearchDevicefragment extends MvpBindingFragment<SearchDevicefragmen |
| 71 | 73 | // .setDeviceName(true, names) // 只扫描指定广播名的设备,可选 |
| 72 | 74 | // .setDeviceMac(mac) // 只扫描指定mac的设备,可选 |
| 73 | 75 | // .setAutoConnect(isAutoConnect) // 连接时的autoConnect参数,可选,默认false |
| 74 | - .setScanTimeOut(1000*60) // 扫描超时时间,可选,默认10秒;小于等于0表示不限制扫描时间 | |
| 76 | + .setScanTimeOut(1000 * 60) // 扫描超时时间,可选,默认10秒;小于等于0表示不限制扫描时间 | |
| 75 | 77 | .build(); |
| 76 | 78 | BleManager.getInstance().initScanRule(scanRuleConfig); |
| 77 | 79 | //检查蓝牙是否打开 | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/SelectWifiFragment.java
| ... | ... | @@ -12,6 +12,7 @@ import android.support.v4.content.ContextCompat; |
| 12 | 12 | import android.util.Log; |
| 13 | 13 | import android.view.View; |
| 14 | 14 | |
| 15 | +import com.clj.fastble.data.BleDevice; | |
| 15 | 16 | import com.cnlive.libs.base.frame.fragment.MvpBindingFragment; |
| 16 | 17 | import com.cnlive.libs.base.util.StatusBarUtil; |
| 17 | 18 | import com.cnlive.libs.base.util.StatusBarUtil2; |
| ... | ... | @@ -19,8 +20,21 @@ import com.cnlive.strike.xiaojiaspeaker.R; |
| 19 | 20 | import com.cnlive.strike.xiaojiaspeaker.databinding.FragmentSelectWifiBinding; |
| 20 | 21 | import com.cnlive.strike.xiaojiaspeaker.frame.presenter.SelectWifiFragmentPresenter; |
| 21 | 22 | import com.cnlive.strike.xiaojiaspeaker.frame.view.SelectWifiFragmentView; |
| 23 | +import com.cnlive.strike.xiaojiaspeaker.netWork.bean.ConfigDeviceNetParam; | |
| 24 | + | |
| 25 | +import java.io.Serializable; | |
| 22 | 26 | |
| 23 | 27 | public class SelectWifiFragment extends MvpBindingFragment<SelectWifiFragmentView, SelectWifiFragmentPresenter, Object, FragmentSelectWifiBinding> { |
| 28 | + private String TAG = "SelectWifiFragment"; | |
| 29 | + | |
| 30 | + public static SelectWifiFragment newInstance(BleDevice bleDevice) { | |
| 31 | + Bundle bundle = new Bundle(); | |
| 32 | + bundle.putParcelable("bleDevice", bleDevice); | |
| 33 | + SelectWifiFragment fragment = new SelectWifiFragment(); | |
| 34 | + fragment.setArguments(bundle); | |
| 35 | + return fragment; | |
| 36 | + } | |
| 37 | + | |
| 24 | 38 | @Override |
| 25 | 39 | protected int getLayoutId() { |
| 26 | 40 | return R.layout.fragment_select_wifi; |
| ... | ... | @@ -37,13 +51,20 @@ public class SelectWifiFragment extends MvpBindingFragment<SelectWifiFragmentVie |
| 37 | 51 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 38 | 52 | super.onViewCreated(view, savedInstanceState); |
| 39 | 53 | initTopBar(); |
| 40 | - if (null != getMvpView()) { | |
| 41 | - getMvpView().initWifiList(); | |
| 42 | - registerBroadcast(); | |
| 54 | + if (null != getArguments()) { | |
| 55 | + BleDevice bleDevice = (BleDevice) getArguments().get("bleDevice"); | |
| 56 | + if (null != getMvpView() && null != bleDevice) { | |
| 57 | + getMvpView().initWifiList(bleDevice); | |
| 58 | + registerBroadcast(); | |
| 59 | + } | |
| 43 | 60 | } |
| 44 | 61 | |
| 62 | + | |
| 63 | + | |
| 45 | 64 | } |
| 46 | 65 | |
| 66 | + | |
| 67 | + | |
| 47 | 68 | private void initTopBar() { |
| 48 | 69 | StatusBarUtil.setStatusBarWrite(getActivity()); |
| 49 | 70 | StatusBarUtil2.setColor(getActivity(), ContextCompat.getColor(getActivity(), R.color.white), 0); |
| ... | ... | @@ -84,12 +105,14 @@ public class SelectWifiFragment extends MvpBindingFragment<SelectWifiFragmentVie |
| 84 | 105 | String resultAction = intent.getAction(); |
| 85 | 106 | //当扫描结果后,进行刷新列表 |
| 86 | 107 | if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { |
| 87 | - Log.e("aa", "onReceive: SCAN_RESULTS_AVAILABLE_ACTION" ); | |
| 108 | + Log.e(TAG, "onReceive: SCAN_RESULTS_AVAILABLE_ACTION"); | |
| 88 | 109 | //扫描wifi |
| 89 | 110 | if (null != getMvpView()) { |
| 90 | 111 | getMvpView().updateWifiList(); |
| 91 | 112 | } |
| 92 | - } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {//wifi连接网络状态变化 | |
| 113 | + } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { | |
| 114 | + Log.e(TAG, "onReceive: NETWORK_STATE_CHANGED_ACTION"); | |
| 115 | + //wifi连接网络状态变化 | |
| 93 | 116 | NetworkInfo.DetailedState state = ((NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO)).getDetailedState(); |
| 94 | 117 | } else if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {//wifi状态变化 |
| 95 | 118 | int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED); | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/TipDialog.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.widget; | |
| 2 | + | |
| 3 | +import android.app.Dialog; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.graphics.Typeface; | |
| 6 | +import android.os.Bundle; | |
| 7 | +import android.support.annotation.NonNull; | |
| 8 | +import android.view.LayoutInflater; | |
| 9 | +import android.view.View; | |
| 10 | +import android.view.ViewGroup; | |
| 11 | +import android.view.WindowManager; | |
| 12 | +import android.widget.Button; | |
| 13 | +import android.widget.LinearLayout; | |
| 14 | +import android.widget.TextView; | |
| 15 | + | |
| 16 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 17 | + | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * 提示对话框 | |
| 21 | + * | |
| 22 | + * @author ShinnyYang | |
| 23 | + * @date 2019/3/27 17:50 | |
| 24 | + */ | |
| 25 | +public class TipDialog extends Dialog { | |
| 26 | + private Context context; | |
| 27 | + private TextView tv_dialog_tip; | |
| 28 | + private Button btn_ok; | |
| 29 | + private LinearLayout ll_child; | |
| 30 | + private View view; | |
| 31 | + private DialogInterface okInterface; | |
| 32 | + private LinearLayout.LayoutParams layoutParams; | |
| 33 | + | |
| 34 | + public TipDialog(@NonNull Context context, String tipText, String btnOkText, int okTextColor, DialogInterface okInterface) { | |
| 35 | + super(context, R.style.MyDialog); | |
| 36 | + this.context = context; | |
| 37 | + view = LayoutInflater.from(context).inflate(R.layout.dialog_tip, null); | |
| 38 | + initView(view); | |
| 39 | + layoutParams = new LinearLayout.LayoutParams((int) (getScreenWidth(context) * 0.75), ViewGroup.LayoutParams.WRAP_CONTENT); | |
| 40 | + ll_child.setLayoutParams(layoutParams); | |
| 41 | + | |
| 42 | + tv_dialog_tip.setText(tipText); | |
| 43 | + btn_ok.setText(btnOkText); | |
| 44 | + btn_ok.setTextColor(context.getResources().getColor(okTextColor)); | |
| 45 | + this.okInterface = okInterface; | |
| 46 | + | |
| 47 | + } | |
| 48 | + | |
| 49 | + public TipDialog(@NonNull Context context, View customview, int themeResId) { | |
| 50 | + super(context, themeResId); | |
| 51 | + this.context = context; | |
| 52 | + } | |
| 53 | + | |
| 54 | + | |
| 55 | + @Override | |
| 56 | + protected void onCreate(Bundle savedInstanceState) { | |
| 57 | + super.onCreate(savedInstanceState); | |
| 58 | + //显示视图 | |
| 59 | + this.setContentView(view); | |
| 60 | + } | |
| 61 | + | |
| 62 | + public void setTipTextSize(float size) { | |
| 63 | + tv_dialog_tip.setTextSize(size); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void setTipTextStyle(Typeface typeface) { | |
| 67 | + tv_dialog_tip.setTypeface(typeface); | |
| 68 | + } | |
| 69 | + | |
| 70 | + public void setTipMsg(String tipMsg) { | |
| 71 | + tv_dialog_tip.setText(tipMsg); | |
| 72 | + } | |
| 73 | + | |
| 74 | + private void initView(View rootView) { | |
| 75 | + this.tv_dialog_tip = (TextView) rootView.findViewById(R.id.tv_dialog_tip); | |
| 76 | + this.btn_ok = (Button) rootView.findViewById(R.id.btn_ok); | |
| 77 | + this.ll_child = (LinearLayout) rootView.findViewById(R.id.ll_child); | |
| 78 | + btn_ok.setOnClickListener(new View.OnClickListener() { | |
| 79 | + @Override | |
| 80 | + public void onClick(View view) { | |
| 81 | + | |
| 82 | + okInterface.onClick(TipDialog.this); | |
| 83 | + } | |
| 84 | + }); | |
| 85 | + } | |
| 86 | + | |
| 87 | + public interface DialogInterface { | |
| 88 | + void onClick(TipDialog dialog); | |
| 89 | + } | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * 获取屏幕宽度 | |
| 93 | + * | |
| 94 | + * @param context | |
| 95 | + * @return | |
| 96 | + */ | |
| 97 | + public static int getScreenWidth(Context context) { | |
| 98 | + WindowManager wm = (WindowManager) context | |
| 99 | + .getSystemService(Context.WINDOW_SERVICE); | |
| 100 | + int width = wm.getDefaultDisplay().getWidth(); | |
| 101 | + return width; | |
| 102 | + } | |
| 103 | + | |
| 104 | + /** | |
| 105 | + * 获取屏幕高度 | |
| 106 | + * | |
| 107 | + * @param context | |
| 108 | + * @return | |
| 109 | + */ | |
| 110 | + public static int getScreenHeight(Context context) { | |
| 111 | + WindowManager wm = (WindowManager) context | |
| 112 | + .getSystemService(Context.WINDOW_SERVICE); | |
| 113 | + int height = wm.getDefaultDisplay().getHeight(); | |
| 114 | + return height; | |
| 115 | + } | |
| 116 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/WifiPwdDialog.java
| ... | ... | @@ -4,7 +4,10 @@ import android.app.Dialog; |
| 4 | 4 | import android.content.Context; |
| 5 | 5 | import android.os.Bundle; |
| 6 | 6 | import android.support.annotation.NonNull; |
| 7 | +import android.support.v4.content.ContextCompat; | |
| 7 | 8 | import android.text.Editable; |
| 9 | +import android.text.InputType; | |
| 10 | +import android.text.TextUtils; | |
| 8 | 11 | import android.text.TextWatcher; |
| 9 | 12 | import android.view.LayoutInflater; |
| 10 | 13 | import android.view.View; |
| ... | ... | @@ -12,6 +15,7 @@ import android.view.ViewGroup; |
| 12 | 15 | import android.view.WindowManager; |
| 13 | 16 | import android.widget.Button; |
| 14 | 17 | import android.widget.EditText; |
| 18 | +import android.widget.ImageView; | |
| 15 | 19 | import android.widget.LinearLayout; |
| 16 | 20 | import android.widget.TextView; |
| 17 | 21 | |
| ... | ... | @@ -35,6 +39,8 @@ public class WifiPwdDialog extends Dialog { |
| 35 | 39 | private DialogInterface cancelInterface; |
| 36 | 40 | private ConnDialogInterface okInterface; |
| 37 | 41 | private LinearLayout.LayoutParams layoutParams; |
| 42 | + private int rightColor = R.color.color_282828; | |
| 43 | + private ImageView iv_pwd; | |
| 38 | 44 | |
| 39 | 45 | public WifiPwdDialog(@NonNull Context context, String tipText, String btnCancelText, DialogInterface cancelInterface, String btnOkText, ConnDialogInterface okInterface) { |
| 40 | 46 | super(context, R.style.MyDialog); |
| ... | ... | @@ -51,29 +57,37 @@ public class WifiPwdDialog extends Dialog { |
| 51 | 57 | |
| 52 | 58 | } |
| 53 | 59 | |
| 60 | + public void setMsgTip(String msg) { | |
| 61 | + if (null != tv_dialog_tip) { | |
| 62 | + tv_dialog_tip.setText(msg); | |
| 63 | + } | |
| 64 | + } | |
| 65 | + | |
| 54 | 66 | public WifiPwdDialog(@NonNull Context context, View customview, int themeResId) { |
| 55 | 67 | super(context, themeResId); |
| 56 | 68 | this.context = context; |
| 57 | 69 | } |
| 58 | 70 | |
| 71 | + public void setLeftBtnColor(int textColor) { | |
| 72 | + if (null != btn_cancel && null != cancelInterface) { | |
| 73 | + btn_cancel.setTextColor(ContextCompat.getColor(context, textColor)); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + public void setRightBtnColor(int textColor) { | |
| 78 | + if (null != btn_ok && null != cancelInterface) { | |
| 79 | + this.rightColor = textColor; | |
| 80 | + btn_ok.setTextColor(ContextCompat.getColor(context, textColor)); | |
| 81 | + } | |
| 82 | + } | |
| 59 | 83 | |
| 60 | 84 | @Override |
| 61 | 85 | protected void onCreate(Bundle savedInstanceState) { |
| 62 | 86 | super.onCreate(savedInstanceState); |
| 63 | 87 | //显示视图 |
| 64 | 88 | this.setContentView(view); |
| 65 | - } | |
| 66 | - | |
| 67 | - private void initView(View rootView) { | |
| 68 | - this.tv_dialog_tip = (TextView) rootView.findViewById(R.id.tv_dialog_tip); | |
| 69 | - this.btn_cancel = (Button) rootView.findViewById(R.id.btn_cancel); | |
| 70 | - this.btn_ok = (Button) rootView.findViewById(R.id.btn_ok); | |
| 71 | - this.ll_child = (LinearLayout) rootView.findViewById(R.id.ll_child); | |
| 72 | - this.et_pwd = (EditText) rootView.findViewById(R.id.et_pwd); | |
| 73 | - btn_ok.setClickable(false); | |
| 74 | - btn_ok.setFocusable(false); | |
| 75 | - btn_ok.setBackground(null); | |
| 76 | - btn_ok.setTextColor(context.getResources().getColor(R.color.line)); | |
| 89 | + this.btn_ok.setClickable(false); | |
| 90 | + this.btn_ok.setTextColor(ContextCompat.getColor(context, R.color.line)); | |
| 77 | 91 | this.et_pwd.addTextChangedListener(new TextWatcher() { |
| 78 | 92 | @Override |
| 79 | 93 | public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { |
| ... | ... | @@ -84,13 +98,11 @@ public class WifiPwdDialog extends Dialog { |
| 84 | 98 | public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { |
| 85 | 99 | if (charSequence.length() < 8) { |
| 86 | 100 | btn_ok.setClickable(false); |
| 87 | - btn_ok.setFocusable(false); | |
| 88 | - btn_ok.setBackground(null); | |
| 89 | - btn_ok.setTextColor(context.getResources().getColor(R.color.line)); | |
| 101 | + btn_ok.setTextColor(ContextCompat.getColor(context, R.color.line)); | |
| 102 | + | |
| 90 | 103 | } else { |
| 91 | 104 | btn_ok.setClickable(true); |
| 92 | - btn_ok.setFocusable(true); | |
| 93 | - btn_ok.setTextColor(context.getResources().getColor(R.color.black)); | |
| 105 | + btn_ok.setTextColor(ContextCompat.getColor(context, rightColor)); | |
| 94 | 106 | btn_ok.setBackground(context.getResources().getDrawable(R.drawable.selector_dialog_btn_right)); |
| 95 | 107 | } |
| 96 | 108 | } |
| ... | ... | @@ -100,6 +112,36 @@ public class WifiPwdDialog extends Dialog { |
| 100 | 112 | |
| 101 | 113 | } |
| 102 | 114 | }); |
| 115 | + //是否显示密码点击 | |
| 116 | + iv_pwd.setOnClickListener(new View.OnClickListener() { | |
| 117 | + @Override | |
| 118 | + public void onClick(View view) { | |
| 119 | + //当前是加密 | |
| 120 | + if ("0".equals(iv_pwd.getTag().toString())) { | |
| 121 | + //显示明文 | |
| 122 | + iv_pwd.setTag("1"); | |
| 123 | + iv_pwd.setBackground(ContextCompat.getDrawable(context, R.drawable.icon_see_pwd)); | |
| 124 | + //选择状态 显示明文--设置为可见的密码 | |
| 125 | +// et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); | |
| 126 | + et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_CLASS_TEXT); | |
| 127 | + //移动光标位置 | |
| 128 | + if (!TextUtils.isEmpty(et_pwd.getText().toString())) { | |
| 129 | + et_pwd.setSelection(et_pwd.getText().toString().length()); | |
| 130 | + } | |
| 131 | + } | |
| 132 | + //显示加密 | |
| 133 | + else { | |
| 134 | + iv_pwd.setTag("0"); | |
| 135 | + iv_pwd.setBackground(ContextCompat.getDrawable(context, R.drawable.icon_no_see_pwd)); | |
| 136 | + //选择状态 设置为不可见的密码 | |
| 137 | + et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT); | |
| 138 | + //移动光标位置 | |
| 139 | + if (!TextUtils.isEmpty(et_pwd.getText().toString())) { | |
| 140 | + et_pwd.setSelection(et_pwd.getText().toString().length()); | |
| 141 | + } | |
| 142 | + } | |
| 143 | + } | |
| 144 | + }); | |
| 103 | 145 | btn_cancel.setOnClickListener(new View.OnClickListener() { |
| 104 | 146 | @Override |
| 105 | 147 | public void onClick(View view) { |
| ... | ... | @@ -118,6 +160,17 @@ public class WifiPwdDialog extends Dialog { |
| 118 | 160 | }); |
| 119 | 161 | } |
| 120 | 162 | |
| 163 | + private void initView(View rootView) { | |
| 164 | + this.tv_dialog_tip = (TextView) rootView.findViewById(R.id.tv_dialog_tip); | |
| 165 | + this.btn_cancel = (Button) rootView.findViewById(R.id.btn_cancel); | |
| 166 | + this.btn_ok = (Button) rootView.findViewById(R.id.btn_ok); | |
| 167 | + this.ll_child = (LinearLayout) rootView.findViewById(R.id.ll_child); | |
| 168 | + this.et_pwd = (EditText) rootView.findViewById(R.id.et_pwd); | |
| 169 | + this.iv_pwd = (ImageView) rootView.findViewById(R.id.iv_pwd); | |
| 170 | + iv_pwd.setTag("0"); | |
| 171 | + | |
| 172 | + } | |
| 173 | + | |
| 121 | 174 | public interface DialogInterface { |
| 122 | 175 | void onClick(WifiPwdDialog dialog); |
| 123 | 176 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/popmenu/ArrowDrawable.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu; | |
| 2 | + | |
| 3 | +import android.graphics.Canvas; | |
| 4 | +import android.graphics.Color; | |
| 5 | +import android.graphics.ColorFilter; | |
| 6 | +import android.graphics.Paint; | |
| 7 | +import android.graphics.Path; | |
| 8 | +import android.graphics.PixelFormat; | |
| 9 | +import android.graphics.Rect; | |
| 10 | +import android.graphics.drawable.ColorDrawable; | |
| 11 | +import android.support.annotation.ColorInt; | |
| 12 | +import android.view.Gravity; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 三角形箭头图片 | |
| 16 | + */ | |
| 17 | +final class ArrowDrawable extends ColorDrawable { | |
| 18 | + | |
| 19 | + private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
| 20 | + private final int mBackgroundColor; | |
| 21 | + private final int mGravity; | |
| 22 | + | |
| 23 | + private Path mPath; | |
| 24 | + | |
| 25 | + ArrowDrawable(@ColorInt int foregroundColor, int gravity) { | |
| 26 | + mGravity = Util.gravityToArrowDirection(gravity); | |
| 27 | + mBackgroundColor = Color.TRANSPARENT; | |
| 28 | + | |
| 29 | + mPaint.setColor(foregroundColor); | |
| 30 | + } | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + protected void onBoundsChange(Rect bounds) { | |
| 34 | + super.onBoundsChange(bounds); | |
| 35 | + updatePath(bounds); | |
| 36 | + } | |
| 37 | + | |
| 38 | + private synchronized void updatePath(Rect bounds) { | |
| 39 | + mPath = new Path(); | |
| 40 | + | |
| 41 | + switch (mGravity) { | |
| 42 | + case Gravity.START: | |
| 43 | + mPath.moveTo(bounds.width(), bounds.height()); | |
| 44 | + mPath.lineTo(0, bounds.height() / 2); | |
| 45 | + mPath.lineTo(bounds.width(), 0); | |
| 46 | + mPath.lineTo(bounds.width(), bounds.height()); | |
| 47 | + break; | |
| 48 | + case Gravity.TOP: | |
| 49 | + mPath.moveTo(0, bounds.height()); | |
| 50 | + mPath.lineTo(bounds.width() / 2, 0); | |
| 51 | + mPath.lineTo(bounds.width(), bounds.height()); | |
| 52 | + mPath.lineTo(0, bounds.height()); | |
| 53 | + break; | |
| 54 | + case Gravity.END: | |
| 55 | + mPath.moveTo(0, 0); | |
| 56 | + mPath.lineTo(bounds.width(), bounds.height() / 2); | |
| 57 | + mPath.lineTo(0, bounds.height()); | |
| 58 | + mPath.lineTo(0, 0); | |
| 59 | + break; | |
| 60 | + case Gravity.BOTTOM: | |
| 61 | + mPath.moveTo(0, 0); | |
| 62 | + mPath.lineTo(bounds.width() / 2, bounds.height()); | |
| 63 | + mPath.lineTo(bounds.width(), 0); | |
| 64 | + mPath.lineTo(0, 0); | |
| 65 | + break; | |
| 66 | + } | |
| 67 | + | |
| 68 | + mPath.close(); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public void draw(Canvas canvas) { | |
| 73 | + canvas.drawColor(mBackgroundColor); | |
| 74 | + if (mPath == null) { | |
| 75 | + updatePath(getBounds()); | |
| 76 | + } | |
| 77 | + canvas.drawPath(mPath, mPaint); | |
| 78 | + } | |
| 79 | + | |
| 80 | + @Override | |
| 81 | + public void setAlpha(int alpha) { | |
| 82 | + mPaint.setAlpha(alpha); | |
| 83 | + } | |
| 84 | + | |
| 85 | + public void setColor(@ColorInt int color) { | |
| 86 | + mPaint.setColor(color); | |
| 87 | + } | |
| 88 | + | |
| 89 | + @Override | |
| 90 | + public void setColorFilter(ColorFilter colorFilter) { | |
| 91 | + mPaint.setColorFilter(colorFilter); | |
| 92 | + } | |
| 93 | + | |
| 94 | + @Override | |
| 95 | + public int getOpacity() { | |
| 96 | + if (mPaint.getColorFilter() != null) { | |
| 97 | + return PixelFormat.TRANSLUCENT; | |
| 98 | + } | |
| 99 | + | |
| 100 | + switch (mPaint.getColor() >>> 24) { | |
| 101 | + case 255: | |
| 102 | + return PixelFormat.OPAQUE; | |
| 103 | + case 0: | |
| 104 | + return PixelFormat.TRANSPARENT; | |
| 105 | + } | |
| 106 | + return PixelFormat.TRANSLUCENT; | |
| 107 | + } | |
| 108 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/popmenu/PopMenu.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu; | |
| 2 | + | |
| 3 | +import android.animation.AnimatorSet; | |
| 4 | +import android.animation.ObjectAnimator; | |
| 5 | +import android.content.Context; | |
| 6 | +import android.graphics.Color; | |
| 7 | +import android.graphics.PointF; | |
| 8 | +import android.graphics.RectF; | |
| 9 | +import android.graphics.drawable.GradientDrawable; | |
| 10 | +import android.os.Build; | |
| 11 | +import android.support.annotation.ColorInt; | |
| 12 | +import android.support.annotation.DimenRes; | |
| 13 | +import android.support.annotation.NonNull; | |
| 14 | +import android.support.annotation.Size; | |
| 15 | +import android.support.v7.widget.LinearLayoutManager; | |
| 16 | +import android.support.v7.widget.RecyclerView; | |
| 17 | +import android.util.DisplayMetrics; | |
| 18 | +import android.view.Gravity; | |
| 19 | +import android.view.View; | |
| 20 | +import android.view.ViewGroup; | |
| 21 | +import android.view.ViewTreeObserver; | |
| 22 | +import android.view.animation.DecelerateInterpolator; | |
| 23 | +import android.widget.ImageView; | |
| 24 | +import android.widget.LinearLayout; | |
| 25 | +import android.widget.PopupWindow; | |
| 26 | + | |
| 27 | +import com.cnlive.strike.xiaojiaspeaker.model.PopMenuInfo; | |
| 28 | +import com.cnlive.strike.xiaojiaspeaker.ui.adapter.PopMenuAdapter; | |
| 29 | +import java.util.ArrayList; | |
| 30 | +import java.util.List; | |
| 31 | + | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * PopMenu | |
| 35 | + */ | |
| 36 | +public final class PopMenu { | |
| 37 | + | |
| 38 | + private final int mScreenWidthPixels; | |
| 39 | + private int mGravity; | |
| 40 | + | |
| 41 | + private final PopupWindow mPopupWindow; | |
| 42 | + private final int mScreenHeightPixels; | |
| 43 | + | |
| 44 | + private LinearLayout mContentView; | |
| 45 | + private ImageView mArrowView; | |
| 46 | + | |
| 47 | + private View mAnchorView; | |
| 48 | + | |
| 49 | + private int mBackgroundColor; | |
| 50 | + private RecyclerView mRecyclerView; | |
| 51 | + | |
| 52 | + private PopMenu.OnItemClickListener mItemClickListener; | |
| 53 | + private PopMenuAdapter mAdapter; | |
| 54 | + private List<PopMenuInfo> mData = new ArrayList<>(); | |
| 55 | + | |
| 56 | + public interface OnItemClickListener { | |
| 57 | +// void onItemClickListener(ActionItem item, int position); | |
| 58 | + } | |
| 59 | + | |
| 60 | + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { | |
| 61 | + mItemClickListener = onItemClickListener; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void addData(List<PopMenuInfo> data) { | |
| 65 | + mData.addAll(data); | |
| 66 | + } | |
| 67 | + | |
| 68 | + public void addData(PopMenuInfo item) { | |
| 69 | + mData.add(item); | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void clearData() { | |
| 73 | + mData.clear(); | |
| 74 | + } | |
| 75 | + | |
| 76 | + private PopMenu(Builder builder) { | |
| 77 | + DisplayMetrics dm = builder.mContext.getResources().getDisplayMetrics(); | |
| 78 | + mScreenHeightPixels = dm.heightPixels; | |
| 79 | + mScreenWidthPixels = dm.widthPixels; | |
| 80 | + mPopupWindow = new PopupWindow(builder.mContext); | |
| 81 | + mPopupWindow.setBackgroundDrawable(null); | |
| 82 | + mPopupWindow.setClippingEnabled(false); | |
| 83 | + mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); | |
| 84 | + mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | |
| 85 | + mPopupWindow.setContentView(getContentView(builder)); | |
| 86 | + mPopupWindow.setFocusable(true);//让popupwindow获取焦点 | |
| 87 | + mPopupWindow.setOutsideTouchable(builder.isCancelable); | |
| 88 | + } | |
| 89 | + | |
| 90 | + private View getContentView(final Builder builder) { | |
| 91 | + GradientDrawable drawable = new GradientDrawable(); | |
| 92 | + mBackgroundColor = builder.mBackgroundColor; | |
| 93 | + drawable.setColor(mBackgroundColor); | |
| 94 | + drawable.setCornerRadius(builder.mCornerRadius); | |
| 95 | + | |
| 96 | + mRecyclerView = new RecyclerView(builder.mContext); | |
| 97 | + mRecyclerView.setLayoutManager(new LinearLayoutManager(builder.mContext)); | |
| 98 | + mAdapter=new PopMenuAdapter(builder.mContext,mData); | |
| 99 | + mData.addAll(builder.mData); | |
| 100 | +// mAdapter = new CommonAdapter<ActionItem>(builder.mContext, | |
| 101 | +// R.layout.list_item_popmenu, mData) { | |
| 102 | +// | |
| 103 | +// @Override | |
| 104 | +// protected void convert(final ViewHolder holder, final ActionItem item, final int position) { | |
| 105 | +// holder.setText(R.id.tv_pop_menu, item.getText()); | |
| 106 | +// holder.setTextColor(R.id.tv_pop_menu, builder.mTextColor); | |
| 107 | +// ImageView iv = holder.getView(R.id.iv_pop_menu); | |
| 108 | +// if (builder.mIsShowImage) { | |
| 109 | +// if (item.getResId() != 0) { | |
| 110 | +// iv.setImageResource(item.getResId()); | |
| 111 | +// iv.setVisibility(View.VISIBLE); | |
| 112 | +// } else { | |
| 113 | +// iv.setVisibility(View.INVISIBLE); | |
| 114 | +// } | |
| 115 | +// } else { | |
| 116 | +// iv.setVisibility(View.GONE); | |
| 117 | +// } | |
| 118 | +// if (mItemClickListener == null) | |
| 119 | +// return; | |
| 120 | +// holder.getConvertView().setOnClickListener(new View.OnClickListener() { | |
| 121 | +// @Override | |
| 122 | +// public void onClick(View v) { | |
| 123 | +// mItemClickListener.onItemClickListener(item, position); | |
| 124 | +// dismiss(); | |
| 125 | +// } | |
| 126 | +// }); | |
| 127 | +// } | |
| 128 | +// }; | |
| 129 | + mRecyclerView.setAdapter(mAdapter); | |
| 130 | + | |
| 131 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
| 132 | + mRecyclerView.setBackground(drawable); | |
| 133 | + } else { | |
| 134 | + //noinspection deprecation | |
| 135 | + mRecyclerView.setBackgroundDrawable(drawable); | |
| 136 | + } | |
| 137 | + | |
| 138 | + LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); | |
| 139 | + textViewParams.gravity = Gravity.CENTER; | |
| 140 | + int cornerRadius = (int) builder.mCornerRadius; | |
| 141 | + mRecyclerView.setPadding(cornerRadius, cornerRadius, cornerRadius, cornerRadius); | |
| 142 | + mRecyclerView.setLayoutParams(textViewParams); | |
| 143 | + | |
| 144 | + mArrowView = new ImageView(builder.mContext); | |
| 145 | + | |
| 146 | + LinearLayout.LayoutParams arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight, 0); | |
| 147 | + | |
| 148 | + arrowLayoutParams.gravity = Gravity.CENTER; | |
| 149 | + mArrowView.setLayoutParams(arrowLayoutParams); | |
| 150 | + | |
| 151 | + mContentView = new LinearLayout(builder.mContext); | |
| 152 | + ViewGroup.LayoutParams contentLayoutParams=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
| 153 | + mContentView.setLayoutParams(contentLayoutParams); | |
| 154 | + mContentView.setOrientation(LinearLayout.VERTICAL); | |
| 155 | + mContentView.addView(mArrowView); | |
| 156 | + mContentView.addView(mRecyclerView);//为了计算高度 | |
| 157 | + return mContentView; | |
| 158 | + } | |
| 159 | + | |
| 160 | + public boolean isShowing() { | |
| 161 | + return mPopupWindow.isShowing(); | |
| 162 | + } | |
| 163 | + | |
| 164 | + public void show(final View anchorView) { | |
| 165 | + if (!isShowing()) { | |
| 166 | + mAnchorView = anchorView; | |
| 167 | + mContentView.getViewTreeObserver().addOnGlobalLayoutListener(mLocationLayoutListener); | |
| 168 | + | |
| 169 | + anchorView.addOnAttachStateChangeListener(mOnAttachStateChangeListener); | |
| 170 | + anchorView.post(new Runnable() { | |
| 171 | + @Override | |
| 172 | + public void run() { | |
| 173 | + mPopupWindow.showAsDropDown(anchorView); | |
| 174 | + } | |
| 175 | + }); | |
| 176 | + } | |
| 177 | + } | |
| 178 | + | |
| 179 | + public void dismiss() { | |
| 180 | + mPopupWindow.dismiss(); | |
| 181 | + } | |
| 182 | + | |
| 183 | + private PointF calculateLocation() { | |
| 184 | + PointF location = new PointF(); | |
| 185 | + | |
| 186 | + final RectF anchorRect = Util.calculateRectInWindow(mAnchorView); | |
| 187 | + final PointF anchorCenter = new PointF(anchorRect.centerX(), anchorRect.centerY()); | |
| 188 | + switch (mGravity) { | |
| 189 | + case Gravity.TOP: | |
| 190 | + location.x = anchorCenter.x - mContentView.getWidth() / 2f; | |
| 191 | + location.y = anchorRect.top - mContentView.getHeight(); | |
| 192 | + break; | |
| 193 | + case Gravity.BOTTOM: | |
| 194 | + location.x = anchorCenter.x - mContentView.getWidth() / 2f; | |
| 195 | + location.y = anchorRect.bottom; | |
| 196 | + break; | |
| 197 | + } | |
| 198 | + float marginX = Util.dpToPx(2); | |
| 199 | + if (mScreenWidthPixels - location.x - mContentView.getWidth() < marginX) { | |
| 200 | + location.x = mScreenWidthPixels - mContentView.getWidth() - marginX; | |
| 201 | + } else if (location.x < marginX) { | |
| 202 | + location.x = marginX; | |
| 203 | + } | |
| 204 | + return location; | |
| 205 | + } | |
| 206 | + | |
| 207 | + private final ViewTreeObserver.OnGlobalLayoutListener mLocationLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { | |
| 208 | + @Override | |
| 209 | + public void onGlobalLayout() { | |
| 210 | + Util.removeOnGlobalLayoutListener(mContentView, this); | |
| 211 | + | |
| 212 | + RectF anchorRect = Util.calculateRectOnScreen(mAnchorView); | |
| 213 | + if (anchorRect.centerY() <= mScreenHeightPixels >> 1) { | |
| 214 | + mGravity = Gravity.BOTTOM; | |
| 215 | + } else { | |
| 216 | + mGravity = Gravity.TOP; | |
| 217 | + } | |
| 218 | + mContentView.removeAllViews(); | |
| 219 | + if (mGravity == Gravity.TOP) { | |
| 220 | + mContentView.addView(mRecyclerView); | |
| 221 | + mContentView.addView(mArrowView); | |
| 222 | + } else { | |
| 223 | + mContentView.addView(mArrowView); | |
| 224 | + mContentView.addView(mRecyclerView); | |
| 225 | + } | |
| 226 | + PointF location = calculateLocation(); | |
| 227 | + mArrowView.setImageDrawable(new ArrowDrawable(mBackgroundColor, mGravity)); | |
| 228 | + mContentView.getViewTreeObserver().addOnGlobalLayoutListener(mArrowLayoutListener); | |
| 229 | + mPopupWindow.setClippingEnabled(true); | |
| 230 | + mPopupWindow.update((int) location.x, (int) location.y, mPopupWindow.getWidth(), mPopupWindow.getHeight()); | |
| 231 | + } | |
| 232 | + }; | |
| 233 | + | |
| 234 | + private final ViewTreeObserver.OnGlobalLayoutListener mArrowLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { | |
| 235 | + @Override | |
| 236 | + public void onGlobalLayout() { | |
| 237 | + Util.removeOnGlobalLayoutListener(mContentView, this); | |
| 238 | + | |
| 239 | + RectF anchorRect = Util.calculateRectOnScreen(mAnchorView); | |
| 240 | + RectF contentViewRect = Util.calculateRectOnScreen(mContentView); | |
| 241 | + float x, y; | |
| 242 | + if (mGravity == Gravity.BOTTOM || mGravity == Gravity.TOP) { | |
| 243 | + x = mContentView.getPaddingLeft() + Util.dpToPx(2); | |
| 244 | + float centerX = (contentViewRect.width() / 2f) - (mArrowView.getWidth() / 2f); | |
| 245 | + float newX = centerX - (contentViewRect.centerX() - anchorRect.centerX()); | |
| 246 | + if (newX > x) { | |
| 247 | + if (newX + mArrowView.getWidth() + x > contentViewRect.width()) { | |
| 248 | + x = contentViewRect.width() - mArrowView.getWidth() - x; | |
| 249 | + } else { | |
| 250 | + x = newX; | |
| 251 | + } | |
| 252 | + } | |
| 253 | + y = mArrowView.getTop(); | |
| 254 | + y = y + (mGravity == Gravity.TOP ? -1 : +1); | |
| 255 | + } else { | |
| 256 | + y = mContentView.getPaddingTop() + Util.dpToPx(2); | |
| 257 | + float centerY = (contentViewRect.height() / 2f) - (mArrowView.getHeight() / 2f); | |
| 258 | + float newY = centerY - (contentViewRect.centerY() - anchorRect.centerY()); | |
| 259 | + if (newY > y) { | |
| 260 | + if (newY + mArrowView.getHeight() + y > contentViewRect.height()) { | |
| 261 | + y = contentViewRect.height() - mArrowView.getHeight() - y; | |
| 262 | + } else { | |
| 263 | + y = newY; | |
| 264 | + } | |
| 265 | + } | |
| 266 | + x = mArrowView.getLeft(); | |
| 267 | + x = x + (mGravity == Gravity.START ? -1 : +1); | |
| 268 | + } | |
| 269 | + mArrowView.setX(x); | |
| 270 | + mArrowView.setY(y); | |
| 271 | + | |
| 272 | + startAnim(x, y); | |
| 273 | + } | |
| 274 | + }; | |
| 275 | + | |
| 276 | + private void startAnim(float x, float y) { | |
| 277 | + AnimatorSet animatorSet = new AnimatorSet();//组合动画 | |
| 278 | + ObjectAnimator scaleX = ObjectAnimator.ofFloat(mContentView, "scaleX", 0.2f, 1f); | |
| 279 | + ObjectAnimator scaleY = ObjectAnimator.ofFloat(mContentView, "scaleY", 0.2f, 1f); | |
| 280 | + ObjectAnimator alpha = ObjectAnimator.ofFloat(mContentView, "alpha", 0.5f, 1f); | |
| 281 | + mContentView.setPivotX(x + mArrowView.getWidth() / 2); | |
| 282 | + if (mGravity == Gravity.TOP) { | |
| 283 | + mContentView.setPivotY(y + mArrowView.getHeight()); | |
| 284 | + } else { | |
| 285 | + mContentView.setPivotY(y); | |
| 286 | + } | |
| 287 | + animatorSet.setDuration(300); | |
| 288 | + animatorSet.setInterpolator(new DecelerateInterpolator()); | |
| 289 | + animatorSet.play(scaleX).with(scaleY).with(alpha);//两个动画同时开始 | |
| 290 | + animatorSet.start(); | |
| 291 | + } | |
| 292 | + | |
| 293 | + private final View.OnAttachStateChangeListener mOnAttachStateChangeListener = new View.OnAttachStateChangeListener() { | |
| 294 | + @Override | |
| 295 | + public void onViewAttachedToWindow(View v) { | |
| 296 | + | |
| 297 | + } | |
| 298 | + | |
| 299 | + @Override | |
| 300 | + public void onViewDetachedFromWindow(View v) { | |
| 301 | + dismiss(); | |
| 302 | + } | |
| 303 | + }; | |
| 304 | + | |
| 305 | + public static final class Builder { | |
| 306 | + | |
| 307 | + private int mBackgroundColor = Color.BLACK; | |
| 308 | + public int mTextColor = Color.LTGRAY; | |
| 309 | + private boolean isCancelable = true; | |
| 310 | + | |
| 311 | + private float mCornerRadius; | |
| 312 | + private float mArrowHeight; | |
| 313 | + private float mArrowWidth; | |
| 314 | + | |
| 315 | + private Context mContext; | |
| 316 | + private List<PopMenuInfo> mData = new ArrayList<>(); | |
| 317 | + private int mLineColor = Color.GRAY; | |
| 318 | + private int mLineSize = 1; | |
| 319 | + private boolean mIsShowImage = true; | |
| 320 | + | |
| 321 | + public Builder(@NonNull Context context) { | |
| 322 | + mContext = context; | |
| 323 | + } | |
| 324 | + | |
| 325 | + public Builder setCancelable(boolean cancelable) { | |
| 326 | + isCancelable = cancelable; | |
| 327 | + return this; | |
| 328 | + } | |
| 329 | + | |
| 330 | + public Builder setBackgroundColor(@ColorInt int color) { | |
| 331 | + mBackgroundColor = color; | |
| 332 | + return this; | |
| 333 | + } | |
| 334 | + | |
| 335 | + public Builder setTextColor(@ColorInt int color) { | |
| 336 | + mTextColor = color; | |
| 337 | + return this; | |
| 338 | + } | |
| 339 | + | |
| 340 | + public Builder setLineColor(@ColorInt int color) { | |
| 341 | + mLineColor = color; | |
| 342 | + return this; | |
| 343 | + } | |
| 344 | + | |
| 345 | + public Builder setLineSize(@Size int size) { | |
| 346 | + mLineSize = size; | |
| 347 | + return this; | |
| 348 | + } | |
| 349 | + | |
| 350 | + public Builder setShowImage(boolean isShowImage) { | |
| 351 | + mIsShowImage = isShowImage; | |
| 352 | + return this; | |
| 353 | + } | |
| 354 | + | |
| 355 | + public Builder setCornerRadius(@DimenRes int resId) { | |
| 356 | + return setCornerRadius(mContext.getResources().getDimension(resId)); | |
| 357 | + } | |
| 358 | + | |
| 359 | + public Builder setCornerRadius(float radius) { | |
| 360 | + mCornerRadius = radius; | |
| 361 | + return this; | |
| 362 | + } | |
| 363 | + | |
| 364 | + public Builder setArrowHeight(@DimenRes int resId) { | |
| 365 | + return setArrowHeight(mContext.getResources().getDimension(resId)); | |
| 366 | + } | |
| 367 | + | |
| 368 | + public Builder setArrowHeight(float height) { | |
| 369 | + mArrowHeight = height; | |
| 370 | + return this; | |
| 371 | + } | |
| 372 | + | |
| 373 | + public Builder setArrowWidth(@DimenRes int resId) { | |
| 374 | + return setArrowWidth(mContext.getResources().getDimension(resId)); | |
| 375 | + } | |
| 376 | + | |
| 377 | + public Builder setArrowWidth(float width) { | |
| 378 | + mArrowWidth = width; | |
| 379 | + return this; | |
| 380 | + } | |
| 381 | + | |
| 382 | + public Builder addData(List<PopMenuInfo> items) { | |
| 383 | + mData.clear(); | |
| 384 | + mData.addAll(items); | |
| 385 | + return this; | |
| 386 | + } | |
| 387 | + | |
| 388 | + public Builder addData(PopMenuInfo item) { | |
| 389 | + mData.add(item); | |
| 390 | + return this; | |
| 391 | + } | |
| 392 | + | |
| 393 | + public PopMenu build() { | |
| 394 | + | |
| 395 | + if (mArrowHeight == 0) { | |
| 396 | + mArrowHeight = Util.dpToPx(5); | |
| 397 | + } | |
| 398 | + if (mArrowWidth == 0) { | |
| 399 | + mArrowWidth = Util.dpToPx(12); | |
| 400 | + } | |
| 401 | + return new PopMenu(this); | |
| 402 | + } | |
| 403 | + | |
| 404 | + } | |
| 405 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/popmenu/Util.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu; | |
| 2 | + | |
| 3 | +import android.content.res.Resources; | |
| 4 | +import android.graphics.RectF; | |
| 5 | +import android.os.Build; | |
| 6 | +import android.view.Gravity; | |
| 7 | +import android.view.View; | |
| 8 | +import android.view.ViewTreeObserver; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * utils | |
| 12 | + */ | |
| 13 | +final class Util { | |
| 14 | + | |
| 15 | + public static RectF calculateRectOnScreen(View view) { | |
| 16 | + int[] location = new int[2]; | |
| 17 | + view.getLocationOnScreen(location); | |
| 18 | + return new RectF(location[0], location[1], location[0] + view.getMeasuredWidth(), location[1] + view.getMeasuredHeight()); | |
| 19 | + } | |
| 20 | + | |
| 21 | + public static RectF calculateRectInWindow(View view) { | |
| 22 | + int[] location = new int[2]; | |
| 23 | + view.getLocationInWindow(location); | |
| 24 | + return new RectF(location[0], location[1], location[0] + view.getMeasuredWidth(), location[1] + view.getMeasuredHeight()); | |
| 25 | + } | |
| 26 | + | |
| 27 | + public static float pxToDp(float px) { | |
| 28 | + return px / Resources.getSystem().getDisplayMetrics().density; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public static float dpToPx(float dp) { | |
| 32 | + return dp * Resources.getSystem().getDisplayMetrics().density; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public static int gravityToArrowDirection(int gravity) { | |
| 36 | + switch (gravity) { | |
| 37 | + case Gravity.START: | |
| 38 | + return Gravity.END; | |
| 39 | + case Gravity.TOP: | |
| 40 | + return Gravity.BOTTOM; | |
| 41 | + case Gravity.END: | |
| 42 | + return Gravity.START; | |
| 43 | + case Gravity.BOTTOM: | |
| 44 | + return Gravity.TOP; | |
| 45 | + default: | |
| 46 | + return gravity; | |
| 47 | + } | |
| 48 | + } | |
| 49 | + | |
| 50 | + public static void removeOnGlobalLayoutListener(View view, ViewTreeObserver.OnGlobalLayoutListener listener) { | |
| 51 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
| 52 | + view.getViewTreeObserver().removeOnGlobalLayoutListener(listener); | |
| 53 | + } else { | |
| 54 | + view.getViewTreeObserver().removeGlobalOnLayoutListener(listener); | |
| 55 | + } | |
| 56 | + } | |
| 57 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/util/BlueToothUtil.java
| 1 | 1 | package com.cnlive.strike.xiaojiaspeaker.util; |
| 2 | 2 | |
| 3 | +import android.text.TextUtils; | |
| 4 | + | |
| 3 | 5 | public class BlueToothUtil { |
| 4 | 6 | public static String getSSIDAndPwd(String ssid, String pwd, String uid) { |
| 5 | 7 | StringBuilder builder = new StringBuilder(); |
| ... | ... | @@ -7,8 +9,10 @@ public class BlueToothUtil { |
| 7 | 9 | builder.append("v1"); |
| 8 | 10 | builder.append('#'); |
| 9 | 11 | builder.append(encode(ssid)); |
| 10 | - builder.append('#'); | |
| 11 | - builder.append(encode(pwd)); | |
| 12 | + if (!TextUtils.isEmpty(pwd)) { | |
| 13 | + builder.append('#'); | |
| 14 | + builder.append(encode(pwd)); | |
| 15 | + } | |
| 12 | 16 | builder.append('#'); |
| 13 | 17 | builder.append(encode(uid)); |
| 14 | 18 | builder.append('#'); | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/util/MySpHelper.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.util; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.content.SharedPreferences; | |
| 5 | +import android.util.Log; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * sharedPreferencesHelper 可以指定写入模式 | |
| 9 | + * //todo 其他人写的无法指定写入模式,这就造成,同一个APP的不同进程,访问的sp中的值不一致,造成保活服务没有可判断的标志位 | |
| 10 | + * | |
| 11 | + * @author ShinnyYang | |
| 12 | + */ | |
| 13 | +public class MySpHelper { | |
| 14 | + private static final String TAG = "MySpHelper"; | |
| 15 | + private static MySpHelper sharedPreferencesHelper = null; | |
| 16 | + private static int SP_MODE;//指定模式 | |
| 17 | + | |
| 18 | + //单例模式,把Context传进去 | |
| 19 | + public static MySpHelper getInstance(Context context, int MODE) { | |
| 20 | + SP_MODE = MODE; | |
| 21 | + if (sharedPreferencesHelper == null) { | |
| 22 | + synchronized (MySpHelper.class) { | |
| 23 | + if (sharedPreferencesHelper == null) { | |
| 24 | + sharedPreferencesHelper = new MySpHelper(); | |
| 25 | + sharedPreferencesHelper.setContext(context); | |
| 26 | + return sharedPreferencesHelper; | |
| 27 | + } | |
| 28 | + } | |
| 29 | + } | |
| 30 | + | |
| 31 | + return sharedPreferencesHelper; | |
| 32 | + } | |
| 33 | + | |
| 34 | + private Context context; | |
| 35 | + | |
| 36 | + public void setContext(Context context) { | |
| 37 | + this.context = context; | |
| 38 | + } | |
| 39 | + | |
| 40 | + //取Boolean 型数据 | |
| 41 | + public boolean getBoolean(String key, boolean defValue) { | |
| 42 | + try { | |
| 43 | + return getSP().getBoolean(key, defValue); | |
| 44 | + } catch (NullPointerException exception) { | |
| 45 | + Log.d("hcj", "" + exception); | |
| 46 | + return defValue; | |
| 47 | + } | |
| 48 | + } | |
| 49 | + | |
| 50 | + //存Boolean 型数据 | |
| 51 | + public void putBoolean(String key, boolean value) { | |
| 52 | + try { | |
| 53 | + SharedPreferences.Editor editor = getSP().edit(); | |
| 54 | + editor.putBoolean(key, value); | |
| 55 | + editor.commit(); | |
| 56 | + } catch (NullPointerException exception) { | |
| 57 | + Log.d("hcj", "" + exception); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + | |
| 61 | + //取Long 型数据 | |
| 62 | + public long getLong(String key, long defValue) { | |
| 63 | + try { | |
| 64 | + return getSP().getLong(key, defValue); | |
| 65 | + } catch (NullPointerException exception) { | |
| 66 | + Log.d("hcj", "" + exception); | |
| 67 | + return defValue; | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | + //存Long 型数据 | |
| 72 | + public void putLong(String key, long value) { | |
| 73 | + try { | |
| 74 | + SharedPreferences.Editor editor = getSP().edit(); | |
| 75 | + editor.putLong(key, value); | |
| 76 | + editor.commit(); | |
| 77 | + } catch (NullPointerException exception) { | |
| 78 | + Log.d("hcj", "" + exception); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + //取整型 | |
| 83 | + public int getInt(String key, int defaultValue) { | |
| 84 | + try { | |
| 85 | + return getSP().getInt(key, defaultValue); | |
| 86 | + } catch (Exception e) { | |
| 87 | + Log.d("hcj", "" + e); | |
| 88 | + return defaultValue; | |
| 89 | + | |
| 90 | + } | |
| 91 | + } | |
| 92 | + | |
| 93 | + //存整型 | |
| 94 | + public void putInt(String key, int value) { | |
| 95 | + try { | |
| 96 | + SharedPreferences.Editor editor = getSP().edit(); | |
| 97 | + editor.putInt(key, value); | |
| 98 | + editor.commit(); | |
| 99 | + } catch (Exception e) { | |
| 100 | + Log.d("hcj", "" + e); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + //取String | |
| 105 | + public String getString(String key, String defValue) { | |
| 106 | + try { | |
| 107 | + return getSP().getString(key, defValue); | |
| 108 | + } catch (NullPointerException e) { | |
| 109 | + Log.d("hcj", "" + e); | |
| 110 | + return defValue; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + | |
| 114 | + //存String | |
| 115 | + public void putString(String key, String value) { | |
| 116 | + try { | |
| 117 | + SharedPreferences.Editor editor = getSP().edit(); | |
| 118 | + editor.putString(key, value); | |
| 119 | + editor.commit(); | |
| 120 | + } catch (NullPointerException e) { | |
| 121 | + Log.d("hcj", "" + e); | |
| 122 | + } | |
| 123 | + } | |
| 124 | + | |
| 125 | + //清除数据 | |
| 126 | + public void clear() { | |
| 127 | + try { | |
| 128 | + SharedPreferences.Editor editor = getSP().edit(); | |
| 129 | + editor.clear(); | |
| 130 | + editor.commit(); | |
| 131 | + } catch (NullPointerException e) { | |
| 132 | + Log.d("hcj", "" + e); | |
| 133 | + } | |
| 134 | + } | |
| 135 | + | |
| 136 | + //获得SharedPreferences对象 | |
| 137 | + private SharedPreferences getSP() { | |
| 138 | + return context.getSharedPreferences("xiaojia-sp", SP_MODE); | |
| 139 | + } | |
| 140 | + | |
| 141 | + private SharedPreferences getSP(String name) { | |
| 142 | + return context.getSharedPreferences(name, SP_MODE); | |
| 143 | + } | |
| 144 | + | |
| 145 | + public void removeKey(String key) { | |
| 146 | + try { | |
| 147 | + SharedPreferences.Editor editor = getSP().edit(); | |
| 148 | + editor.remove(key); | |
| 149 | + editor.commit(); | |
| 150 | + } catch (NullPointerException e) { | |
| 151 | + Log.d(TAG, "removeKey:" + e); | |
| 152 | + } | |
| 153 | + } | |
| 154 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/util/utilcode/CheckUtil.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.util.utilcode; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.content.Intent; | |
| 6 | +import android.location.LocationManager; | |
| 7 | +import android.provider.Settings; | |
| 8 | +import android.widget.Toast; | |
| 9 | + | |
| 10 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 加检查工具 | |
| 14 | + * | |
| 15 | + * @author ys | |
| 16 | + */ | |
| 17 | +public class CheckUtil { | |
| 18 | + /** | |
| 19 | + * 判断GPS是否开启,GPS或者AGPS开启一个就认为是开启的 | |
| 20 | + * | |
| 21 | + * @param context | |
| 22 | + * @return true 表示开启 | |
| 23 | + */ | |
| 24 | + public static final boolean isOPenGps(final Context context) { | |
| 25 | + try { | |
| 26 | + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { | |
| 27 | + LocationManager locationManager | |
| 28 | + = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); | |
| 29 | + // 通过GPS卫星定位,定位级别可以精确到街(通过24颗卫星定位,在室外和空旷的地方定位准确、速度快) | |
| 30 | + boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); | |
| 31 | + // 通过WLAN或移动网络(3G/2G)确定的位置(也称作AGPS,辅助GPS定位。主要用于在室内或遮盖物(建筑群或茂密的深林等)密集的地方定位) | |
| 32 | + boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); | |
| 33 | + if (gps) { | |
| 34 | + return true; | |
| 35 | + } else { | |
| 36 | + return false; | |
| 37 | + } | |
| 38 | + } else { | |
| 39 | + return true; | |
| 40 | + } | |
| 41 | + } catch (Exception e) { | |
| 42 | + //异常就返回true | |
| 43 | + return true; | |
| 44 | + } | |
| 45 | + } | |
| 46 | + | |
| 47 | + public static void openGPS(Activity context) { | |
| 48 | + //开启GPS | |
| 49 | + try { | |
| 50 | + Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); | |
| 51 | + context.startActivityForResult(intent, 10); | |
| 52 | + Toast.makeText(context, context.getString(R.string.open_gps_tip), Toast.LENGTH_LONG).show(); | |
| 53 | + } catch (Exception e) { | |
| 54 | + Toast.makeText(context, "请手动打开GPS", Toast.LENGTH_LONG).show(); | |
| 55 | + } | |
| 56 | + } | |
| 57 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/conn_success_gift.png
0 → 100644
135 KB
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/conn_success_gift_close.png
0 → 100644
1.76 KB
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/icon_conn_success.png
0 → 100644
3.75 KB
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/icon_item_add.png
0 → 100644
426 Bytes
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/icon_item_right_arrow.png
0 → 100644
476 Bytes
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/icon_no_see_pwd.png
0 → 100644
688 Bytes
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/icon_see_pwd.png
0 → 100644
1.27 KB
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/key_instruction.png
0 → 100644
83.4 KB
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/light_instruction.png
0 → 100644
84.4 KB
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/pop_gray_left.png
0 → 100644
1.92 KB
module_xiaojiaSoundBox/src/main/res/drawable-hdpi/pop_gray_right.png
0 → 100644
2.3 KB
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/conn_success_gift.png
0 → 100644
263 KB
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/conn_success_gift_close.png
0 → 100644
1.22 KB
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/icon_conn_success.png
0 → 100644
3.39 KB
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/icon_item_add.png
0 → 100644
274 Bytes
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/icon_item_right_arrow.png
0 → 100644
461 Bytes
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/icon_no_see_pwd.png
0 → 100644
872 Bytes
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/icon_see_pwd.png
0 → 100644
1.42 KB
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/key_instruction.png
0 → 100644
128 KB
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/light_instruction.png
0 → 100644
151 KB
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/pop_gray_left.png
0 → 100644
2.28 KB
module_xiaojiaSoundBox/src/main/res/drawable-xhdpi/pop_gray_right.png
0 → 100644
2.44 KB
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/conn_success_gift.png
0 → 100644
469 KB
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/conn_success_gift_close.png
0 → 100644
4.04 KB
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/icon_conn_success.png
0 → 100644
8.42 KB
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/icon_item_add.png
0 → 100644
796 Bytes
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/icon_item_right_arrow.png
0 → 100644
816 Bytes
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/icon_no_see_pwd.png
0 → 100644
1.63 KB
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/icon_see_pwd.png
0 → 100644
2.87 KB
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/key_instruction.png
0 → 100644
246 KB
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/light_instruction.png
0 → 100644
266 KB
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/pop_gray_left.png
0 → 100644
4.54 KB
module_xiaojiaSoundBox/src/main/res/drawable-xxhdpi/pop_gray_right.png
0 → 100644
6.1 KB
module_xiaojiaSoundBox/src/main/res/drawable/layer_tran.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <item android:id="@+id/shape_id"> | |
| 4 | + <!-- 正三角 --> | |
| 5 | + <rotate | |
| 6 | + android:fromDegrees="45" | |
| 7 | + android:pivotX="-40%" | |
| 8 | + android:pivotY="80%" | |
| 9 | + android:toDegrees="45"> | |
| 10 | + <shape android:shape="rectangle"> | |
| 11 | + <solid android:color="#80000000" /> | |
| 12 | + </shape> | |
| 13 | + </rotate> | |
| 14 | + </item> | |
| 15 | +</layer-list> | |
| 0 | 16 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/drawable/selector_tip_dialog_btn_bottom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <item android:drawable="@color/transparent" android:state_pressed="false" /> | |
| 4 | + <item android:drawable="@drawable/shape_tip_dialog_btn_bottom_press" android:state_pressed="true" /> | |
| 5 | + | |
| 6 | +</selector> | |
| 0 | 7 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/drawable/shape_5_radius_white_bg.xml
0 → 100644
module_xiaojiaSoundBox/src/main/res/drawable/shape_menu_bg.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <solid android:color="#80000000" /> | |
| 4 | + <corners | |
| 5 | + android:bottomLeftRadius="4dp" | |
| 6 | + android:bottomRightRadius="4dp" | |
| 7 | + android:topLeftRadius="4dp" | |
| 8 | + android:topRightRadius="4dp" /> | |
| 9 | + <stroke | |
| 10 | + android:width="0.5dp" | |
| 11 | + android:color="#80000000" /> | |
| 12 | +</shape> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/drawable/shape_tip_dialog_btn_bottom_press.xml
0 → 100644
module_xiaojiaSoundBox/src/main/res/layout/activity_all_device.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout> | |
| 3 | + | |
| 4 | + <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 5 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 6 | + xmlns:tools="http://schemas.android.com/tools" | |
| 7 | + android:layout_width="match_parent" | |
| 8 | + android:layout_height="match_parent" | |
| 9 | + android:orientation="vertical" | |
| 10 | + tools:context=".ui.activity.AllDeviceActivity"> | |
| 11 | + | |
| 12 | + <RelativeLayout | |
| 13 | + android:id="@+id/fragment_container" | |
| 14 | + android:layout_width="match_parent" | |
| 15 | + android:layout_height="match_parent"></RelativeLayout> | |
| 16 | + | |
| 17 | + </RelativeLayout> | |
| 18 | +</layout> | |
| 0 | 19 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/activity_conn_bluetooth_success.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 4 | + xmlns:tools="http://schemas.android.com/tools"> | |
| 5 | + | |
| 6 | + <FrameLayout | |
| 7 | + android:layout_width="match_parent" | |
| 8 | + android:layout_height="match_parent"> | |
| 9 | + | |
| 10 | + <LinearLayout | |
| 11 | + android:layout_width="match_parent" | |
| 12 | + android:layout_height="match_parent" | |
| 13 | + android:orientation="vertical" | |
| 14 | + tools:context=".ui.activity.ConnBluetoothSuccessActivity"> | |
| 15 | + | |
| 16 | + <com.qmuiteam.qmui.widget.QMUITopBar | |
| 17 | + android:id="@+id/topbar" | |
| 18 | + android:layout_width="match_parent" | |
| 19 | + android:layout_height="?attr/qmui_topbar_height" /> | |
| 20 | + | |
| 21 | + <LinearLayout | |
| 22 | + android:layout_width="match_parent" | |
| 23 | + android:layout_height="0dp" | |
| 24 | + android:layout_weight="1.5" | |
| 25 | + android:focusable="true" | |
| 26 | + android:gravity="center" | |
| 27 | + android:orientation="vertical"> | |
| 28 | + | |
| 29 | + <ImageView | |
| 30 | + android:layout_width="65dp" | |
| 31 | + android:layout_height="65dp" | |
| 32 | + android:background="@drawable/icon_conn_success" /> | |
| 33 | + | |
| 34 | + <TextView | |
| 35 | + android:layout_width="wrap_content" | |
| 36 | + android:layout_height="wrap_content" | |
| 37 | + android:layout_marginTop="20dp" | |
| 38 | + android:text="@string/conn_success" | |
| 39 | + android:textColor="@color/btn_green" | |
| 40 | + android:textSize="20sp" | |
| 41 | + android:textStyle="bold" /> | |
| 42 | + </LinearLayout> | |
| 43 | + | |
| 44 | + <LinearLayout | |
| 45 | + android:layout_width="match_parent" | |
| 46 | + android:layout_height="0dp" | |
| 47 | + android:layout_weight="1" | |
| 48 | + android:orientation="vertical"> | |
| 49 | + | |
| 50 | + <TextView | |
| 51 | + android:layout_width="wrap_content" | |
| 52 | + android:layout_height="wrap_content" | |
| 53 | + android:layout_gravity="center_horizontal" | |
| 54 | + android:text="@string/to_sound_say_tip" | |
| 55 | + android:textColor="@color/color_999999" | |
| 56 | + android:textSize="16sp" | |
| 57 | + android:textStyle="bold" /> | |
| 58 | + | |
| 59 | + <TextView | |
| 60 | + android:layout_width="216dp" | |
| 61 | + android:layout_height="wrap_content" | |
| 62 | + android:layout_gravity="center_horizontal" | |
| 63 | + android:layout_marginLeft="20dp" | |
| 64 | + android:layout_marginTop="30sp" | |
| 65 | + android:background="@drawable/pop_gray_right" | |
| 66 | + android:gravity="center" | |
| 67 | + android:text="@string/xiaojia_say_story_tip" | |
| 68 | + android:textColor="@color/white" | |
| 69 | + android:textSize="12sp" /> | |
| 70 | + | |
| 71 | + <TextView | |
| 72 | + android:layout_width="216dp" | |
| 73 | + android:layout_height="wrap_content" | |
| 74 | + android:layout_gravity="center_horizontal" | |
| 75 | + android:layout_marginTop="20sp" | |
| 76 | + android:layout_marginRight="30dp" | |
| 77 | + android:background="@drawable/pop_gray_left" | |
| 78 | + android:gravity="center" | |
| 79 | + android:text="@string/xiaojia_listen_to_music_tip" | |
| 80 | + android:textColor="@color/white" | |
| 81 | + android:textSize="12sp" /> | |
| 82 | + </LinearLayout> | |
| 83 | + | |
| 84 | + <LinearLayout | |
| 85 | + android:layout_width="match_parent" | |
| 86 | + android:layout_height="0dp" | |
| 87 | + android:layout_weight="0.8" | |
| 88 | + android:gravity="center" | |
| 89 | + android:orientation="vertical"> | |
| 90 | + | |
| 91 | + <View | |
| 92 | + android:layout_width="match_parent" | |
| 93 | + android:layout_height="1dp" | |
| 94 | + android:layout_marginLeft="10dp" | |
| 95 | + android:layout_marginRight="10dp" | |
| 96 | + android:background="@color/line" /> | |
| 97 | + | |
| 98 | + <TextView | |
| 99 | + android:layout_width="wrap_content" | |
| 100 | + android:layout_height="wrap_content" | |
| 101 | + android:layout_gravity="center_horizontal" | |
| 102 | + android:layout_marginTop="15dp" | |
| 103 | + android:text="@string/also_to_listen_china" | |
| 104 | + android:textColor="@color/color_999999" | |
| 105 | + android:textSize="12sp" /> | |
| 106 | + | |
| 107 | + <TextView | |
| 108 | + android:id="@+id/tv_go_to_listen_china" | |
| 109 | + android:layout_width="wrap_content" | |
| 110 | + android:layout_height="wrap_content" | |
| 111 | + android:layout_gravity="center_horizontal" | |
| 112 | + android:layout_marginTop="15dp" | |
| 113 | + android:text="@string/go_to_liaten_china" | |
| 114 | + android:textColor="@color/btn_green" | |
| 115 | + android:textSize="13sp" /> | |
| 116 | + </LinearLayout> | |
| 117 | + </LinearLayout> | |
| 118 | + <!-- 礼物弹框--> | |
| 119 | + <LinearLayout | |
| 120 | + android:id="@+id/ll_gift_black" | |
| 121 | + android:layout_width="match_parent" | |
| 122 | + android:layout_height="match_parent" | |
| 123 | + android:background="#80000000"></LinearLayout> | |
| 124 | + | |
| 125 | + <LinearLayout | |
| 126 | + android:id="@+id/ll_gift" | |
| 127 | + android:layout_width="match_parent" | |
| 128 | + android:layout_height="match_parent" | |
| 129 | + android:clickable="true" | |
| 130 | + android:gravity="center" | |
| 131 | + android:orientation="vertical"> | |
| 132 | + | |
| 133 | + <ImageView | |
| 134 | + android:layout_width="370dp" | |
| 135 | + android:layout_height="339dp" | |
| 136 | + android:background="@drawable/conn_success_gift" /> | |
| 137 | + | |
| 138 | + <ImageView | |
| 139 | + android:id="@+id/iv_close_gift" | |
| 140 | + android:layout_width="35dp" | |
| 141 | + android:layout_height="35dp" | |
| 142 | + android:layout_marginTop="20dp" | |
| 143 | + android:background="@drawable/conn_success_gift_close" /> | |
| 144 | + </LinearLayout> | |
| 145 | + </FrameLayout> | |
| 146 | +</layout> | |
| 0 | 147 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/activity_device_instruction.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout> | |
| 3 | + | |
| 4 | + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 5 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 6 | + xmlns:tools="http://schemas.android.com/tools" | |
| 7 | + android:layout_width="match_parent" | |
| 8 | + android:layout_height="match_parent" | |
| 9 | + android:background="@color/color_F2F2F2" | |
| 10 | + android:orientation="vertical" | |
| 11 | + tools:context=".ui.activity.DeviceInstructionActivity"> | |
| 12 | + | |
| 13 | + <com.qmuiteam.qmui.widget.QMUITopBar | |
| 14 | + android:id="@+id/topbar" | |
| 15 | + android:layout_width="match_parent" | |
| 16 | + android:layout_height="?attr/qmui_topbar_height" /> | |
| 17 | + | |
| 18 | + <ScrollView | |
| 19 | + android:layout_width="match_parent" | |
| 20 | + android:layout_height="wrap_content"> | |
| 21 | + | |
| 22 | + <LinearLayout | |
| 23 | + android:layout_width="match_parent" | |
| 24 | + android:layout_height="wrap_content" | |
| 25 | + android:orientation="vertical"> | |
| 26 | + | |
| 27 | + <TextView | |
| 28 | + android:layout_width="wrap_content" | |
| 29 | + android:layout_height="wrap_content" | |
| 30 | + android:layout_margin="10dp" | |
| 31 | + android:text="按键图示说明" | |
| 32 | + android:textColor="@color/color_282828" | |
| 33 | + android:textSize="18sp" | |
| 34 | + android:textStyle="bold" /> | |
| 35 | + | |
| 36 | + <LinearLayout | |
| 37 | + android:layout_width="match_parent" | |
| 38 | + android:layout_height="wrap_content" | |
| 39 | + android:layout_marginLeft="10dp" | |
| 40 | + android:layout_marginRight="10dp" | |
| 41 | + android:layout_marginBottom="20dp" | |
| 42 | + android:background="@drawable/shape_5_radius_white_bg" | |
| 43 | + android:gravity="center"> | |
| 44 | + | |
| 45 | + <ImageView | |
| 46 | + android:layout_width="316dp" | |
| 47 | + android:layout_height="298dp" | |
| 48 | + android:background="@drawable/key_instruction" /> | |
| 49 | + </LinearLayout> | |
| 50 | + | |
| 51 | + <TextView | |
| 52 | + android:layout_width="wrap_content" | |
| 53 | + android:layout_height="wrap_content" | |
| 54 | + android:layout_margin="10dp" | |
| 55 | + android:text="环形灯效果说明" | |
| 56 | + android:textColor="@color/color_282828" | |
| 57 | + android:textSize="18sp" | |
| 58 | + android:textStyle="bold" /> | |
| 59 | + | |
| 60 | + <ImageView | |
| 61 | + android:layout_width="match_parent" | |
| 62 | + android:layout_height="348dp" | |
| 63 | + android:layout_gravity="center_horizontal" | |
| 64 | + android:layout_marginLeft="10dp" | |
| 65 | + android:layout_marginRight="10dp" | |
| 66 | + android:layout_marginBottom="20dp" | |
| 67 | + android:adjustViewBounds="true" | |
| 68 | + android:background="@drawable/light_instruction" | |
| 69 | + android:maxHeight="348dp" | |
| 70 | + android:scaleType="fitXY" /> | |
| 71 | + </LinearLayout> | |
| 72 | + </ScrollView> | |
| 73 | + </LinearLayout> | |
| 74 | +</layout> | |
| 0 | 75 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/dialog_tip.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + android:layout_width="match_parent" | |
| 4 | + android:layout_height="wrap_content" | |
| 5 | + android:gravity="center_horizontal"> | |
| 6 | + | |
| 7 | + | |
| 8 | + <LinearLayout | |
| 9 | + android:id="@+id/ll_child" | |
| 10 | + android:layout_width="match_parent" | |
| 11 | + android:layout_height="wrap_content" | |
| 12 | + android:background="@drawable/free_dialog_bg" | |
| 13 | + android:orientation="vertical" | |
| 14 | + android:paddingTop="10dp"> | |
| 15 | + | |
| 16 | + <TextView | |
| 17 | + android:id="@+id/tv_dialog_tip" | |
| 18 | + android:layout_width="wrap_content" | |
| 19 | + android:layout_height="wrap_content" | |
| 20 | + android:layout_gravity="center" | |
| 21 | + android:layout_marginLeft="10dp" | |
| 22 | + android:layout_marginRight="10dp" | |
| 23 | + android:gravity="center" | |
| 24 | + android:minHeight="75dp" | |
| 25 | + android:text="标题" | |
| 26 | + android:lineSpacingExtra="5dp" | |
| 27 | + android:textColor="@color/black" | |
| 28 | + android:textSize="17sp" /> | |
| 29 | + | |
| 30 | + | |
| 31 | + <View | |
| 32 | + android:layout_width="match_parent" | |
| 33 | + android:layout_height="1dp" | |
| 34 | + android:layout_marginTop="3dp" | |
| 35 | + android:background="@color/line" /> | |
| 36 | + | |
| 37 | + <LinearLayout | |
| 38 | + android:layout_width="match_parent" | |
| 39 | + android:layout_height="40dp" | |
| 40 | + android:orientation="horizontal"> | |
| 41 | + | |
| 42 | + | |
| 43 | + <LinearLayout | |
| 44 | + android:layout_width="0dp" | |
| 45 | + android:layout_height="match_parent" | |
| 46 | + android:layout_gravity="center" | |
| 47 | + android:layout_weight="1" | |
| 48 | + android:gravity="center"> | |
| 49 | + | |
| 50 | + <Button | |
| 51 | + android:id="@+id/btn_ok" | |
| 52 | + android:layout_width="match_parent" | |
| 53 | + android:layout_height="match_parent" | |
| 54 | + android:layout_gravity="center" | |
| 55 | + android:background="@drawable/selector_tip_dialog_btn_bottom" | |
| 56 | + android:text="好的" | |
| 57 | + android:textColor="@color/btn_green" | |
| 58 | + android:textSize="15sp" /> | |
| 59 | + </LinearLayout> | |
| 60 | + | |
| 61 | + | |
| 62 | + </LinearLayout> | |
| 63 | + </LinearLayout> | |
| 64 | +</LinearLayout> | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/dialog_wifi_pwd.xml
| ... | ... | @@ -25,22 +25,48 @@ |
| 25 | 25 | android:textSize="17sp" |
| 26 | 26 | android:textStyle="bold" /> |
| 27 | 27 | |
| 28 | - <EditText | |
| 29 | - android:id="@+id/et_pwd" | |
| 28 | + <FrameLayout | |
| 30 | 29 | android:layout_width="match_parent" |
| 31 | - android:layout_height="wrap_content" | |
| 32 | - android:layout_gravity="center" | |
| 33 | - android:layout_marginLeft="20dp" | |
| 34 | - android:layout_marginTop="20dp" | |
| 35 | - android:layout_marginRight="20dp" | |
| 36 | - android:layout_marginBottom="20dp" | |
| 37 | - android:background="@drawable/shape_et_wifi_bg" | |
| 38 | - android:gravity="center" | |
| 39 | - android:hint="请输入密码" | |
| 40 | - android:paddingTop="10dp" | |
| 41 | - android:paddingBottom="10dp" | |
| 42 | - android:textColor="@color/black" | |
| 43 | - android:textSize="12sp" /> | |
| 30 | + android:layout_height="wrap_content"> | |
| 31 | + | |
| 32 | + <LinearLayout | |
| 33 | + android:layout_width="match_parent" | |
| 34 | + android:layout_height="wrap_content" | |
| 35 | + android:gravity="center"> | |
| 36 | + | |
| 37 | + <EditText | |
| 38 | + android:id="@+id/et_pwd" | |
| 39 | + android:layout_width="0dp" | |
| 40 | + android:layout_height="wrap_content" | |
| 41 | + android:layout_gravity="center" | |
| 42 | + android:layout_marginLeft="20dp" | |
| 43 | + android:layout_marginTop="20dp" | |
| 44 | + android:layout_marginRight="20dp" | |
| 45 | + android:layout_marginBottom="20dp" | |
| 46 | + android:layout_weight="1" | |
| 47 | + android:digits="0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@." | |
| 48 | + android:gravity="left|center_vertical" | |
| 49 | + android:hint="请输入WIFI密码" | |
| 50 | + android:inputType="textWebPassword" | |
| 51 | + android:maxLines="1" | |
| 52 | + android:paddingTop="10dp" | |
| 53 | + android:paddingRight="30dp" | |
| 54 | + android:paddingBottom="20dp" | |
| 55 | + android:tag="0" | |
| 56 | + android:textColor="@color/black" | |
| 57 | + android:textSize="12sp" /> | |
| 58 | + | |
| 59 | + | |
| 60 | + </LinearLayout> | |
| 61 | + | |
| 62 | + <ImageView | |
| 63 | + android:id="@+id/iv_pwd" | |
| 64 | + android:layout_width="20dp" | |
| 65 | + android:layout_height="13dp" | |
| 66 | + android:layout_gravity="center_vertical|right" | |
| 67 | + android:layout_marginRight="30dp" | |
| 68 | + android:background="@drawable/icon_no_see_pwd" /> | |
| 69 | + </FrameLayout> | |
| 44 | 70 | |
| 45 | 71 | <View |
| 46 | 72 | android:layout_width="match_parent" |
| ... | ... | @@ -91,8 +117,9 @@ |
| 91 | 117 | android:layout_height="match_parent" |
| 92 | 118 | android:layout_gravity="center" |
| 93 | 119 | android:background="@drawable/selector_dialog_btn_right" |
| 120 | + android:clickable="false" | |
| 94 | 121 | android:text="否" |
| 95 | - android:textColor="@color/black" | |
| 122 | + android:textColor="@color/line" | |
| 96 | 123 | android:textSize="15sp" |
| 97 | 124 | android:textStyle="bold" /> |
| 98 | 125 | </LinearLayout> | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/fragment_all_device.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout> | |
| 3 | + | |
| 4 | + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 5 | + android:layout_width="match_parent" | |
| 6 | + android:layout_height="match_parent" | |
| 7 | + android:background="@color/color_F2F2F2" | |
| 8 | + android:orientation="vertical"> | |
| 9 | + | |
| 10 | + <com.qmuiteam.qmui.widget.QMUITopBar | |
| 11 | + android:id="@+id/topbar" | |
| 12 | + android:layout_width="match_parent" | |
| 13 | + android:layout_height="?attr/qmui_topbar_height" /> | |
| 14 | + | |
| 15 | + <android.support.v7.widget.RecyclerView | |
| 16 | + android:id="@+id/rv_all_device" | |
| 17 | + android:layout_width="match_parent" | |
| 18 | + android:layout_height="match_parent" | |
| 19 | + android:paddingTop="10dp" /> | |
| 20 | + </LinearLayout> | |
| 21 | +</layout> | |
| 0 | 22 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/fragment_search_device.xml
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 5 | 5 | android:layout_width="match_parent" |
| 6 | 6 | android:layout_height="match_parent" |
| 7 | - android:background="@color/white" | |
| 7 | + android:background="@color/color_F2F2F2" | |
| 8 | 8 | android:orientation="vertical"> |
| 9 | 9 | |
| 10 | 10 | <com.qmuiteam.qmui.widget.QMUITopBar |
| ... | ... | @@ -31,7 +31,7 @@ |
| 31 | 31 | android:id="@+id/ll_loading" |
| 32 | 32 | android:layout_width="match_parent" |
| 33 | 33 | android:layout_height="match_parent" |
| 34 | - android:background="@color/white" | |
| 34 | + android:background="@color/color_F2F2F2" | |
| 35 | 35 | android:gravity="center" |
| 36 | 36 | android:visibility="gone"> |
| 37 | 37 | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/fragment_select_wifi.xml
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | -<layout> | |
| 2 | +<layout xmlns:app="http://schemas.android.com/apk/res-auto"> | |
| 3 | 3 | |
| 4 | 4 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 5 | 5 | android:layout_width="match_parent" |
| ... | ... | @@ -17,21 +17,60 @@ |
| 17 | 17 | android:layout_height="0dp" |
| 18 | 18 | android:layout_weight="3"> |
| 19 | 19 | |
| 20 | - <android.support.v7.widget.RecyclerView | |
| 21 | - android:id="@+id/rv_wifi" | |
| 22 | - android:layout_width="match_parent" | |
| 23 | - android:layout_height="match_parent" | |
| 24 | - android:paddingTop="10dp" /> | |
| 20 | + | |
| 21 | +<!-- <com.scwang.smartrefresh.layout.SmartRefreshLayout--> | |
| 22 | +<!-- android:id="@+id/refresh_layout"--> | |
| 23 | +<!-- android:layout_width="match_parent"--> | |
| 24 | +<!-- android:layout_height="match_parent"--> | |
| 25 | +<!-- app:srlEnablePreviewInEditMode="false">--> | |
| 26 | + | |
| 27 | +<!-- <com.scwang.smartrefresh.layout.header.ClassicsHeader--> | |
| 28 | +<!-- android:layout_width="match_parent"--> | |
| 29 | +<!-- android:layout_height="wrap_content"--> | |
| 30 | +<!-- app:srlAccentColor="@color/color_282828" />--> | |
| 31 | + | |
| 32 | + <FrameLayout | |
| 33 | + android:layout_width="match_parent" | |
| 34 | + android:layout_height="match_parent"> | |
| 35 | + | |
| 36 | + <android.support.v7.widget.RecyclerView | |
| 37 | + android:id="@+id/rv_wifi" | |
| 38 | + android:layout_width="match_parent" | |
| 39 | + android:layout_height="match_parent" | |
| 40 | + android:paddingTop="10dp" /> | |
| 41 | + | |
| 42 | + <LinearLayout | |
| 43 | + android:id="@+id/ll_loading" | |
| 44 | + android:layout_width="match_parent" | |
| 45 | + android:layout_height="match_parent" | |
| 46 | + android:background="@color/color_F2F2F2" | |
| 47 | + android:gravity="center" | |
| 48 | + android:visibility="gone"> | |
| 49 | + | |
| 50 | + <com.wang.avi.AVLoadingIndicatorView | |
| 51 | + android:id="@+id/av_loading" | |
| 52 | + android:layout_width="50dp" | |
| 53 | + android:layout_height="50dp" | |
| 54 | + android:clickable="false" | |
| 55 | + android:focusableInTouchMode="false" | |
| 56 | + app:indicatorColor="@color/btn_green" | |
| 57 | + app:indicatorName="BallSpinFadeLoaderIndicator" /> | |
| 58 | + </LinearLayout> | |
| 59 | + </FrameLayout> | |
| 60 | +<!-- </com.scwang.smartrefresh.layout.SmartRefreshLayout>--> | |
| 61 | + | |
| 62 | + | |
| 25 | 63 | </LinearLayout> |
| 26 | 64 | |
| 27 | 65 | <LinearLayout |
| 28 | 66 | android:layout_width="match_parent" |
| 29 | 67 | android:layout_height="0dp" |
| 30 | 68 | android:layout_weight="0.5" |
| 31 | - android:gravity="center"> | |
| 69 | + android:gravity="center" | |
| 70 | + android:visibility="gone"> | |
| 32 | 71 | |
| 33 | 72 | <Button |
| 34 | - android:id="@+id/btn_bond_device" | |
| 73 | + android:id="@+id/btn_next" | |
| 35 | 74 | android:layout_width="match_parent" |
| 36 | 75 | android:layout_height="40dp" |
| 37 | 76 | android:layout_margin="20dp" | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/list_item_all_device.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + | |
| 4 | + | |
| 5 | + <FrameLayout | |
| 6 | + android:layout_width="match_parent" | |
| 7 | + android:layout_height="120dp" | |
| 8 | + android:background="@drawable/round_rectangle_bg"> | |
| 9 | + | |
| 10 | + <RelativeLayout | |
| 11 | + android:id="@+id/rl_root" | |
| 12 | + android:layout_width="match_parent" | |
| 13 | + android:layout_height="match_parent" | |
| 14 | + android:clickable="true" | |
| 15 | + android:focusable="true" | |
| 16 | + android:gravity="center_vertical" | |
| 17 | + android:paddingBottom="10dp"> | |
| 18 | + | |
| 19 | + <ImageView | |
| 20 | + android:id="@+id/iv_bluetoothDevice_icon" | |
| 21 | + android:layout_width="70dp" | |
| 22 | + android:layout_height="70dp" | |
| 23 | + android:layout_centerVertical="true" | |
| 24 | + android:layout_marginLeft="10dp" | |
| 25 | + android:layout_marginRight="10dp" | |
| 26 | + android:layout_marginBottom="20dp" /> | |
| 27 | + | |
| 28 | + | |
| 29 | + <LinearLayout | |
| 30 | + android:layout_width="wrap_content" | |
| 31 | + android:layout_height="match_parent" | |
| 32 | + android:layout_toLeftOf="@id/iv_arrow" | |
| 33 | + android:layout_toRightOf="@id/iv_bluetoothDevice_icon" | |
| 34 | + android:gravity="center_vertical" | |
| 35 | + android:orientation="vertical"> | |
| 36 | + | |
| 37 | + <TextView | |
| 38 | + android:id="@+id/tv_device_name" | |
| 39 | + android:layout_width="wrap_content" | |
| 40 | + android:layout_height="wrap_content" | |
| 41 | + android:layout_marginBottom="10dp" | |
| 42 | + android:ellipsize="end" | |
| 43 | + android:maxLines="1" | |
| 44 | + android:textColor="@color/color_282828" | |
| 45 | + android:textSize="17dp" | |
| 46 | + android:textStyle="bold" /> | |
| 47 | + | |
| 48 | + <TextView | |
| 49 | + android:id="@+id/tv_device_state" | |
| 50 | + android:layout_width="wrap_content" | |
| 51 | + android:layout_height="wrap_content" | |
| 52 | + android:layout_centerVertical="true" | |
| 53 | + android:layout_marginTop="10dp" | |
| 54 | + android:textColor="@color/color_999999" | |
| 55 | + android:textSize="14dp" /> | |
| 56 | + </LinearLayout> | |
| 57 | + | |
| 58 | + <ImageView | |
| 59 | + android:id="@+id/iv_arrow" | |
| 60 | + android:layout_width="10dp" | |
| 61 | + android:layout_height="16dp" | |
| 62 | + android:layout_alignParentRight="true" | |
| 63 | + android:layout_centerVertical="true" | |
| 64 | + android:layout_marginRight="20dp" | |
| 65 | + android:background="@drawable/icon_item_right_arrow" /> | |
| 66 | + | |
| 67 | + </RelativeLayout> | |
| 68 | + <!-- --> | |
| 69 | + <LinearLayout | |
| 70 | + android:id="@+id/ll_add" | |
| 71 | + android:layout_width="match_parent" | |
| 72 | + android:layout_height="match_parent" | |
| 73 | + android:gravity="center" | |
| 74 | + android:paddingBottom="10dp"> | |
| 75 | + | |
| 76 | + <ImageView | |
| 77 | + android:layout_width="16dp" | |
| 78 | + android:layout_height="16dp" | |
| 79 | + android:background="@drawable/icon_item_add" /> | |
| 80 | + | |
| 81 | + <TextView | |
| 82 | + android:layout_width="wrap_content" | |
| 83 | + android:layout_height="wrap_content" | |
| 84 | + android:layout_marginLeft="10dp" | |
| 85 | + android:text="添加设备" | |
| 86 | + android:textColor="@color/color_282828" | |
| 87 | + android:textSize="17sp" /> | |
| 88 | + </LinearLayout> | |
| 89 | + </FrameLayout> | |
| 90 | + | |
| 91 | +</layout> | |
| 0 | 92 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/pop_item_menu.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout> | |
| 3 | + | |
| 4 | + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 5 | + android:layout_width="wrap_content" | |
| 6 | + android:layout_height="wrap_content" | |
| 7 | + android:gravity="center_vertical" | |
| 8 | + android:minWidth="100dp" | |
| 9 | + android:orientation="vertical"> | |
| 10 | + | |
| 11 | + <LinearLayout | |
| 12 | + android:layout_width="wrap_content" | |
| 13 | + android:layout_height="wrap_content"> | |
| 14 | + | |
| 15 | + <ImageView | |
| 16 | + android:id="@+id/iv_icon" | |
| 17 | + android:layout_width="20dp" | |
| 18 | + android:layout_height="20dp" /> | |
| 19 | + | |
| 20 | + <TextView | |
| 21 | + android:id="@+id/tv_tip" | |
| 22 | + android:layout_width="wrap_content" | |
| 23 | + android:layout_height="wrap_content" | |
| 24 | + android:layout_marginLeft="10dp" | |
| 25 | + android:gravity="center_vertical" | |
| 26 | + android:minHeight="35dp" | |
| 27 | + android:textColor="@color/color_282828" /> | |
| 28 | + </LinearLayout> | |
| 29 | + | |
| 30 | + <View | |
| 31 | + android:id="@+id/view_line" | |
| 32 | + android:layout_width="match_parent" | |
| 33 | + android:layout_height="1dp" | |
| 34 | + android:background="@color/line" /> | |
| 35 | + | |
| 36 | + </LinearLayout> | |
| 37 | +</layout> | |
| 0 | 38 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/pop_menu.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + android:layout_width="wrap_content" | |
| 4 | + android:layout_height="match_parent" | |
| 5 | + android:orientation="vertical"> | |
| 6 | + | |
| 7 | + <View | |
| 8 | + android:id="@+id/view_jiao" | |
| 9 | + android:layout_width="20dp" | |
| 10 | + android:layout_height="20dp" | |
| 11 | + android:layout_marginLeft="2dp" | |
| 12 | + android:background="@drawable/layer_tran" /> | |
| 13 | + | |
| 14 | + <android.support.v7.widget.RecyclerView | |
| 15 | + android:id="@+id/rv_list" | |
| 16 | + android:layout_width="wrap_content" | |
| 17 | + android:layout_height="wrap_content" | |
| 18 | + android:layout_below="@id/view_jiao" | |
| 19 | + android:layout_marginTop="-1dp" /> | |
| 20 | +</RelativeLayout> | |
| 0 | 21 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/values/ids.xml
module_xiaojiaSoundBox/src/main/res/values/strings.xml
| ... | ... | @@ -16,5 +16,12 @@ |
| 16 | 16 | <string name="md_dialog_cancel">取消</string> |
| 17 | 17 | <string name="md_dialog_content_head">我们需要以下权限为你工作,请点击“确定”开启权限</string> |
| 18 | 18 | <string name="btn_next_step">下一步</string> |
| 19 | + <string name="conn_success">连接成功</string> | |
| 20 | + <string name="to_sound_say_tip">您可以对“小家音箱”说</string> | |
| 21 | + <string name="xiaojia_say_story_tip">“小家、小家,讲个故事”</string> | |
| 22 | + <string name="xiaojia_listen_to_music_tip">“小家、小家,放首歌听听”</string> | |
| 23 | + <string name="also_to_listen_china">也可以去“听见中国”听听有趣的故事</string> | |
| 24 | + <string name="go_to_liaten_china">前往听见中国 >></string> | |
| 25 | + <string name="open_gps_tip">为确保功能正常使用,请开启GPS!</string> | |
| 19 | 26 | |
| 20 | 27 | </resources> | ... | ... |