├── .gitignore ├── .idea ├── gradle.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── aaaa.gif ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ ├── app-release.apk │ └── output.json ├── src │ ├── androidTest │ │ └── java │ │ │ └── top │ │ │ └── jplayer │ │ │ └── audio │ │ │ └── ExampleInstrumentedTest.java │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ ├── com │ │ │ │ └── ping │ │ │ │ │ └── greendao │ │ │ │ │ └── gen │ │ │ │ │ ├── DaoMaster.java │ │ │ │ │ ├── DaoSession.java │ │ │ │ │ ├── LoginBeanDao.java │ │ │ │ │ └── RecordSleepBeanDao.java │ │ │ └── top │ │ │ │ └── jplayer │ │ │ │ └── audio │ │ │ │ ├── ActivityLoginAct.java │ │ │ │ ├── ActivitySVG.java │ │ │ │ ├── AudioApplication.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── RecordSleepActivity.java │ │ │ │ ├── WavePlayActivity.java │ │ │ │ ├── WebActivity.java │ │ │ │ ├── bean │ │ │ │ ├── LoginBean.java │ │ │ │ ├── ModelSVG.java │ │ │ │ └── RecordSleepBean.java │ │ │ │ ├── dialog │ │ │ │ ├── BaseCustomDialogFragment.java │ │ │ │ ├── CurrentRecordDialog.java │ │ │ │ ├── ForgetDialogFragment.java │ │ │ │ ├── ForgetSureDialog.java │ │ │ │ ├── RegisterDialogFragment.java │ │ │ │ └── ValueSureDialog.java │ │ │ │ ├── utils │ │ │ │ ├── AndroidScheduler.java │ │ │ │ ├── ColorUtil.java │ │ │ │ ├── CustomMp3Recorder.java │ │ │ │ ├── DaoManager.java │ │ │ │ ├── DateUtils.java │ │ │ │ ├── FontMatrixUtils.java │ │ │ │ ├── LoginDaoUtil.java │ │ │ │ ├── RecordDaoUtil.java │ │ │ │ ├── ScreenUtils.java │ │ │ │ └── SizeUtils.java │ │ │ │ └── view │ │ │ │ └── CompassServant.java │ │ └── res │ │ │ ├── anim │ │ │ ├── fade_in.xml │ │ │ ├── fade_out.xml │ │ │ ├── slide_in_bottom.xml │ │ │ ├── slide_in_center.xml │ │ │ ├── slide_in_right.xml │ │ │ ├── slide_in_top.xml │ │ │ ├── slide_out_bottom.xml │ │ │ ├── slide_out_center.xml │ │ │ ├── slide_out_right.xml │ │ │ └── slide_out_top.xml │ │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ ├── bg_btn_login_selected.xml │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ ├── activity_login_act.xml │ │ │ ├── activity_main.xml │ │ │ ├── activity_sleep_record.xml │ │ │ ├── activity_svg.xml │ │ │ ├── activity_wave_play.xml │ │ │ ├── activity_webview.xml │ │ │ ├── dialog_current_record.xml │ │ │ ├── dialog_forget_sure.xml │ │ │ ├── dialog_register.xml │ │ │ └── dialog_value_sure.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_clear.png │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_round.png │ │ │ ├── ic_mobile_flag.png │ │ │ └── ic_password_flag.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── black.png │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_round.png │ │ │ └── logo.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ ├── arrays.xml │ │ │ ├── attrs.xml │ │ │ ├── colors.xml │ │ │ ├── integers.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ │ └── xml │ │ │ ├── backup_descriptor.xml │ │ │ └── provider.xml │ └── test │ │ └── java │ │ └── top │ │ └── jplayer │ │ └── audio │ │ └── ExampleUnitTest.java └── tinker-support.gradle ├── audio.jks ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 35 | 36 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | C:\Users\suhao\AppData\Roaming\Subversion 35 | 36 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | "# Audio" 2 | ![Gif](./aaaa.gif) 3 | 4 | ### **BestSleep** 5 | 6 | #### 启动页 7 | - 采用 SVG获取图片Path 生成动态效果 8 | #### 登录,注册,忘记密码 9 | - 适配小屏幕手机,键盘弹起界面跟随做出变化 10 | ``` 11 | mScrollView.addOnLayoutChangeListener(new ViewGroup.OnLayoutChangeListener() { 12 | @Override 13 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { 14 | /* old是改变前的左上右下坐标点值,没有old的是改变后的左上右下坐标点值 15 | 现在认为只要控件将Activity向上推的高度超过了1/3屏幕高,就认为软键盘弹起*/ 16 | if (oldBottom != 0 && bottom != 0 && (oldBottom - bottom > keyHeight)) { 17 | Log.e("wenzhihao", "up------>" + (oldBottom - bottom)); 18 | int dist = mContent.getBottom() - bottom; 19 | if (dist > 0) { 20 | ObjectAnimator mAnimatorTranslateY = ObjectAnimator.ofFloat(mContent, "translationY", 0.0f, -dist); 21 | mAnimatorTranslateY.setDuration(300); 22 | mAnimatorTranslateY.setInterpolator(new LinearInterpolator()); 23 | mAnimatorTranslateY.start(); 24 | RxAnimationTool.zoomIn(mLogo, 0.6f, dist); 25 | } 26 | mService.setVisibility(View.INVISIBLE); 27 | 28 | } else if (oldBottom != 0 && bottom != 0 && (bottom - oldBottom > keyHeight)) { 29 | Log.e("wenzhihao", "down------>" + (bottom - oldBottom)); 30 | if ((mContent.getBottom() - oldBottom) > 0) { 31 | ObjectAnimator mAnimatorTranslateY = ObjectAnimator.ofFloat(mContent, "translationY", mContent.getTranslationY(), 0); 32 | mAnimatorTranslateY.setDuration(300); 33 | mAnimatorTranslateY.setInterpolator(new LinearInterpolator()); 34 | mAnimatorTranslateY.start(); 35 | //键盘收回后,logo恢复原来大小,位置同样回到初始位置 36 | RxAnimationTool.zoomOut(mLogo, 0.6f); 37 | } 38 | mService.setVisibility(View.VISIBLE); 39 | } 40 | } 41 | }); 42 | ``` 43 | - 注册及忘记密码界面采用dialog 形式弹出,以封装Dialog类,方便使用 ``` BaseCustonDialogFragment.java ``` 44 | - 账号采用GreenDao数据库,进行账号的增,删,改,查。 45 | - 数据库升级需要修改 46 | ``` 47 | greendao { 48 | schemaVersion 2 //每次升级需要自增 49 | daoPackage 'com.ping.greendao.gen' 50 | targetGenDir 'src/main/java' 51 | } 52 | ``` 53 | #### 音波分贝 54 | - 声音转分贝公式 55 | - 56 | ![image](http://upload.wikimedia.org/math/9/0/2/9023cb5d56a945e9332196fabacb463a.png) 57 | 58 | - 具体代码实现 59 | 60 | ``` 61 | 平方和除以数据总长度,得到音量大小。 62 | double mean = v / (double) readSize; 63 | double volume = 10 * Math.log10(mean); 64 | ``` 65 | - 分贝显示 ``` compass_servant.setPointerDecibel(value); ```采用开源控件 * CompassServant 66 | 67 | - 音波显示 采用开源控件 * AudioWaveView 68 | 69 | - 代码算法打鼾检测 70 | - 1. 71 | 72 | 73 | ``` 74 | 75 | /** 76 | * 打鼾状态检测,一秒轮循检测,监测机制 77 | * 大于60分贝的话记录,一秒内超过某分贝即为打鼾(一秒内记录值大约为20次,超过一定次,低于限制次即为打鼾,否则为其他状态) 78 | * 79 | */ 80 | subscribe = Observable.interval(1, TimeUnit.SECONDS).subscribe(new Consumer() { 81 | @Override 82 | public void accept(Long aLong) throws Exception { 83 | if (integerList.size() > 0) { 84 | count = 0; 85 | countQuick = 0; 86 | Observable.fromIterable(integerList).subscribe(new Consumer() { 87 | @Override 88 | public void accept(Integer integer) throws Exception { 89 | if (integer > 60) { 90 | count += integer; 91 | } 92 | countQuick += integer; 93 | } 94 | }, new Consumer() { 95 | @Override 96 | public void accept(Throwable throwable) throws Exception { 97 | 98 | } 99 | }); 100 | Log.e("一秒数据", Arrays.toString(integerList.toArray())); 101 | int i = count / 3; 102 | int iQuick = countQuick / integerList.size(); 103 | if (i > 60) { 104 | countList.add(i); 105 | } 106 | if (isStartVibrate && iQuick > 60 && iQuick < 70) { 107 | countSnoring.add(iQuick); 108 | RxVibrateTool.vibrateOnce(MainActivity.this, 300); 109 | } 110 | integerList.clear(); 111 | } 112 | } 113 | }); 114 | ``` 115 | - 2. 116 | 117 | ``` 118 | /** 119 | * 检测是否处于打鼾状态 120 | */ 121 | subscribe1 = Observable.interval(10, TimeUnit.SECONDS).subscribe(new Consumer() { 122 | @Override 123 | public void accept(Long aLong) throws Exception { 124 | /** 125 | * 126 | */ 127 | if (5 <= countList.size()) { 128 | isStartVibrate = true; 129 | countSnoring.add(countList.size()); 130 | RxVibrateTool.vibrateOnce(MainActivity.this, 1000); 131 | countList.clear(); 132 | } else { 133 | isStartVibrate = false; 134 | } 135 | } 136 | }); 137 | ``` 138 | 139 | - 3. 140 | ``` 141 | 142 | /** 143 | * 开启超时检测打鼾,一分钟后 一定时间内开启,否则关闭打鼾状态 144 | */ 145 | subscribe2 = Observable.timer(1, TimeUnit.MINUTES) 146 | .subscribeOn(Schedulers.io()) 147 | .observeOn(AndroidScheduler.mainThread()) 148 | .subscribe(new Consumer() { 149 | @Override 150 | public void accept(Long aLong) throws Exception { 151 | isStartVibrate = false; 152 | } 153 | }, new Consumer() { 154 | @Override 155 | public void accept(Throwable throwable) throws Exception { 156 | 157 | } 158 | }); 159 | 160 | ``` 161 | 162 | #### 睡眠记录 163 | 164 | - 数据库记录每日睡眠状况 165 | - 当日数据通过Dialog 弹窗显示 166 | 167 | ``` 168 | CurrentRecordDialog dialog = new CurrentRecordDialog(); 169 | Bundle arguments = new Bundle(); 170 | arguments.putParcelable("record", recordBean); 171 | dialog.setArguments(arguments); 172 | dialog.show(getSupportFragmentManager(), "current"); 173 | ``` 174 | - 记录分析健康报告(包含睡眠时间,打鼾次数等...) 175 | - 日历形式选择查看某日记录,(绿点显示何日记录睡眠状态)采用开源框架* ncalendar 176 | 177 | #### 精准投放 178 | - 封装WebView 实现可加载网页 179 | - 180 | ``` 181 | //只需要在入口更改连接就可以 182 | Intent intent = new Intent(this, ActivityWebView.class); 183 | Bundle value = new Bundle(); 184 | value.putString("url", "http://www.baidu.com"); 185 | intent.putExtra("bundle", value); 186 | startActivity(intent); 187 | ``` 188 | 189 | #### 其他 190 | 191 | - 关于Android 6.0 权限动态申请问题 192 | 193 | ``` 194 | //解决申请权限 195 | AndPermission.with(this) 196 | .permission(Permission.WRITE_EXTERNAL_STORAGE, Permission.RECORD_AUDIO) 197 | .onGranted(new Action() { 198 | @Override 199 | public void onAction(List permissions) { 200 | } 201 | }) 202 | .onDenied(new Action() { 203 | @Override 204 | public void onAction(@NonNull List permissions) { 205 | AndPermission.hasAlwaysDeniedPermission(MainActivity.this, permissions); 206 | } 207 | }) 208 | .start(); 209 | ``` 210 | - 关于Android 7.0 FileProvider 文件权限问题 211 | 212 | ``` 213 | 214 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 215 | StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); 216 | StrictMode.setVmPolicy(builder.build()); 217 | } 218 | 219 | ``` 220 | -------------------------------------------------------------------------------- /aaaa.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jplayer-top/SnoringRecord/c4783f9e355044fc4590f6ae1e5430ab8f40e328/aaaa.gif -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.jakewharton.butterknife' 3 | apply plugin: 'org.greenrobot.greendao' 4 | apply from: 'tinker-support.gradle' 5 | android { 6 | compileSdkVersion 27 7 | defaultConfig { 8 | applicationId "top.jplayer.audio" 9 | minSdkVersion 19 10 | targetSdkVersion 27 11 | versionCode 2 12 | versionName "1.1" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | multiDexEnabled true//65535上限设置 15 | ndk { 16 | //设置支持的SO库架构 17 | abiFilters 'armeabi' ,'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a' 18 | } 19 | } 20 | lintOptions { 21 | checkReleaseBuilds false 22 | // Or, if you prefer, you can continue to check for errors in release builds, 23 | // but continue the build even when errors are found: 24 | abortOnError false 25 | } 26 | signingConfigs { 27 | config { 28 | keyAlias "audio_key" 29 | keyPassword "123456" 30 | storeFile file("../audio.jks") 31 | storePassword "123456" 32 | } 33 | 34 | debug { 35 | keyAlias "audio_key" 36 | keyPassword "123456" 37 | storeFile file("../audio.jks") 38 | storePassword "123456" 39 | } 40 | release { 41 | keyAlias "audio_key" 42 | keyPassword "123456" 43 | storeFile file("../audio.jks") 44 | storePassword "123456" 45 | } 46 | } 47 | buildTypes { 48 | release { 49 | signingConfig signingConfigs.config 50 | minifyEnabled false 51 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 52 | } 53 | debug { 54 | signingConfig signingConfigs.config 55 | minifyEnabled false 56 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 57 | } 58 | } 59 | } 60 | 61 | greendao { 62 | schemaVersion 2 63 | daoPackage 'com.ping.greendao.gen' 64 | targetGenDir 'src/main/java' 65 | } 66 | dependencies { 67 | implementation fileTree(include: ['*.jar'], dir: 'libs') 68 | implementation 'com.android.support:appcompat-v7:27.1.1' 69 | implementation 'com.android.support.constraint:constraint-layout:1.1.0' 70 | testImplementation 'junit:junit:4.12' 71 | 72 | implementation 'com.github.CarGuo:RecordWave:v1.1.8' 73 | 74 | implementation 'com.github.vondear:RxTools:v1.7.8.3' 75 | 76 | implementation 'com.jakewharton:butterknife:8.5.1' 77 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' 78 | 79 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 80 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 81 | implementation 'org.greenrobot:greendao:3.2.2' 82 | implementation 'com.android.support:cardview-v7:27.1.1' 83 | implementation 'io.reactivex.rxjava2:rxjava:2.1.0' 84 | implementation 'com.jaredrummler:animated-svg-view:1.0.5' 85 | implementation 'com.yanzhenjie:permission:2.0.0-rc4' 86 | implementation 'com.necer.ncalendar:ncalendar:2.4.6' 87 | 88 | implementation "com.android.support:multidex:1.0.1" 89 | implementation 'com.tencent.bugly:crashreport_upgrade:1.3.4' 90 | } 91 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/release/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jplayer-top/SnoringRecord/c4783f9e355044fc4590f6ae1e5430ab8f40e328/app/release/app-release.apk -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2},"path":"app-release.apk","properties":{"packageId":"top.jplayer.audio","split":"","minSdkVersion":"19"}}] -------------------------------------------------------------------------------- /app/src/androidTest/java/top/jplayer/audio/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("top.jplayer.audio", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 33 | 37 | 38 | 39 | 40 | 44 | 48 | 49 | 50 | 54 | 58 | 59 | 60 | 61 | 62 | 63 | 67 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/ping/greendao/gen/DaoMaster.java: -------------------------------------------------------------------------------- 1 | package com.ping.greendao.gen; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | import android.database.sqlite.SQLiteDatabase.CursorFactory; 6 | import android.util.Log; 7 | 8 | import org.greenrobot.greendao.AbstractDaoMaster; 9 | import org.greenrobot.greendao.database.StandardDatabase; 10 | import org.greenrobot.greendao.database.Database; 11 | import org.greenrobot.greendao.database.DatabaseOpenHelper; 12 | import org.greenrobot.greendao.identityscope.IdentityScopeType; 13 | 14 | 15 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. 16 | /** 17 | * Master of DAO (schema version 2): knows all DAOs. 18 | */ 19 | public class DaoMaster extends AbstractDaoMaster { 20 | public static final int SCHEMA_VERSION = 2; 21 | 22 | /** Creates underlying database table using DAOs. */ 23 | public static void createAllTables(Database db, boolean ifNotExists) { 24 | LoginBeanDao.createTable(db, ifNotExists); 25 | RecordSleepBeanDao.createTable(db, ifNotExists); 26 | } 27 | 28 | /** Drops underlying database table using DAOs. */ 29 | public static void dropAllTables(Database db, boolean ifExists) { 30 | LoginBeanDao.dropTable(db, ifExists); 31 | RecordSleepBeanDao.dropTable(db, ifExists); 32 | } 33 | 34 | /** 35 | * WARNING: Drops all table on Upgrade! Use only during development. 36 | * Convenience method using a {@link DevOpenHelper}. 37 | */ 38 | public static DaoSession newDevSession(Context context, String name) { 39 | Database db = new DevOpenHelper(context, name).getWritableDb(); 40 | DaoMaster daoMaster = new DaoMaster(db); 41 | return daoMaster.newSession(); 42 | } 43 | 44 | public DaoMaster(SQLiteDatabase db) { 45 | this(new StandardDatabase(db)); 46 | } 47 | 48 | public DaoMaster(Database db) { 49 | super(db, SCHEMA_VERSION); 50 | registerDaoClass(LoginBeanDao.class); 51 | registerDaoClass(RecordSleepBeanDao.class); 52 | } 53 | 54 | public DaoSession newSession() { 55 | return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); 56 | } 57 | 58 | public DaoSession newSession(IdentityScopeType type) { 59 | return new DaoSession(db, type, daoConfigMap); 60 | } 61 | 62 | /** 63 | * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - 64 | */ 65 | public static abstract class OpenHelper extends DatabaseOpenHelper { 66 | public OpenHelper(Context context, String name) { 67 | super(context, name, SCHEMA_VERSION); 68 | } 69 | 70 | public OpenHelper(Context context, String name, CursorFactory factory) { 71 | super(context, name, factory, SCHEMA_VERSION); 72 | } 73 | 74 | @Override 75 | public void onCreate(Database db) { 76 | Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); 77 | createAllTables(db, false); 78 | } 79 | } 80 | 81 | /** WARNING: Drops all table on Upgrade! Use only during development. */ 82 | public static class DevOpenHelper extends OpenHelper { 83 | public DevOpenHelper(Context context, String name) { 84 | super(context, name); 85 | } 86 | 87 | public DevOpenHelper(Context context, String name, CursorFactory factory) { 88 | super(context, name, factory); 89 | } 90 | 91 | @Override 92 | public void onUpgrade(Database db, int oldVersion, int newVersion) { 93 | Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); 94 | dropAllTables(db, true); 95 | onCreate(db); 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/ping/greendao/gen/DaoSession.java: -------------------------------------------------------------------------------- 1 | package com.ping.greendao.gen; 2 | 3 | import java.util.Map; 4 | 5 | import org.greenrobot.greendao.AbstractDao; 6 | import org.greenrobot.greendao.AbstractDaoSession; 7 | import org.greenrobot.greendao.database.Database; 8 | import org.greenrobot.greendao.identityscope.IdentityScopeType; 9 | import org.greenrobot.greendao.internal.DaoConfig; 10 | 11 | import top.jplayer.audio.bean.LoginBean; 12 | import top.jplayer.audio.bean.RecordSleepBean; 13 | 14 | import com.ping.greendao.gen.LoginBeanDao; 15 | import com.ping.greendao.gen.RecordSleepBeanDao; 16 | 17 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. 18 | 19 | /** 20 | * {@inheritDoc} 21 | * 22 | * @see org.greenrobot.greendao.AbstractDaoSession 23 | */ 24 | public class DaoSession extends AbstractDaoSession { 25 | 26 | private final DaoConfig loginBeanDaoConfig; 27 | private final DaoConfig recordSleepBeanDaoConfig; 28 | 29 | private final LoginBeanDao loginBeanDao; 30 | private final RecordSleepBeanDao recordSleepBeanDao; 31 | 32 | public DaoSession(Database db, IdentityScopeType type, Map>, DaoConfig> 33 | daoConfigMap) { 34 | super(db); 35 | 36 | loginBeanDaoConfig = daoConfigMap.get(LoginBeanDao.class).clone(); 37 | loginBeanDaoConfig.initIdentityScope(type); 38 | 39 | recordSleepBeanDaoConfig = daoConfigMap.get(RecordSleepBeanDao.class).clone(); 40 | recordSleepBeanDaoConfig.initIdentityScope(type); 41 | 42 | loginBeanDao = new LoginBeanDao(loginBeanDaoConfig, this); 43 | recordSleepBeanDao = new RecordSleepBeanDao(recordSleepBeanDaoConfig, this); 44 | 45 | registerDao(LoginBean.class, loginBeanDao); 46 | registerDao(RecordSleepBean.class, recordSleepBeanDao); 47 | } 48 | 49 | public void clear() { 50 | loginBeanDaoConfig.clearIdentityScope(); 51 | recordSleepBeanDaoConfig.clearIdentityScope(); 52 | } 53 | 54 | public LoginBeanDao getLoginBeanDao() { 55 | return loginBeanDao; 56 | } 57 | 58 | public RecordSleepBeanDao getRecordSleepBeanDao() { 59 | return recordSleepBeanDao; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/ping/greendao/gen/LoginBeanDao.java: -------------------------------------------------------------------------------- 1 | package com.ping.greendao.gen; 2 | 3 | import android.database.Cursor; 4 | import android.database.sqlite.SQLiteStatement; 5 | 6 | import org.greenrobot.greendao.AbstractDao; 7 | import org.greenrobot.greendao.Property; 8 | import org.greenrobot.greendao.internal.DaoConfig; 9 | import org.greenrobot.greendao.database.Database; 10 | import org.greenrobot.greendao.database.DatabaseStatement; 11 | 12 | import top.jplayer.audio.bean.LoginBean; 13 | 14 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. 15 | /** 16 | * DAO for table "LOGIN_BEAN". 17 | */ 18 | public class LoginBeanDao extends AbstractDao { 19 | 20 | public static final String TABLENAME = "LOGIN_BEAN"; 21 | 22 | /** 23 | * Properties of entity LoginBean.
24 | * Can be used for QueryBuilder and for referencing column names. 25 | */ 26 | public static class Properties { 27 | public final static Property _id = new Property(0, Long.class, "_id", true, "_id"); 28 | public final static Property Name = new Property(1, String.class, "name", false, "NAME"); 29 | public final static Property Password = new Property(2, String.class, "password", false, "PASSWORD"); 30 | } 31 | 32 | 33 | public LoginBeanDao(DaoConfig config) { 34 | super(config); 35 | } 36 | 37 | public LoginBeanDao(DaoConfig config, DaoSession daoSession) { 38 | super(config, daoSession); 39 | } 40 | 41 | /** Creates the underlying database table. */ 42 | public static void createTable(Database db, boolean ifNotExists) { 43 | String constraint = ifNotExists? "IF NOT EXISTS ": ""; 44 | db.execSQL("CREATE TABLE " + constraint + "\"LOGIN_BEAN\" (" + // 45 | "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: _id 46 | "\"NAME\" TEXT NOT NULL ," + // 1: name 47 | "\"PASSWORD\" TEXT NOT NULL );"); // 2: password 48 | } 49 | 50 | /** Drops the underlying database table. */ 51 | public static void dropTable(Database db, boolean ifExists) { 52 | String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"LOGIN_BEAN\""; 53 | db.execSQL(sql); 54 | } 55 | 56 | @Override 57 | protected final void bindValues(DatabaseStatement stmt, LoginBean entity) { 58 | stmt.clearBindings(); 59 | 60 | Long _id = entity.get_id(); 61 | if (_id != null) { 62 | stmt.bindLong(1, _id); 63 | } 64 | stmt.bindString(2, entity.getName()); 65 | stmt.bindString(3, entity.getPassword()); 66 | } 67 | 68 | @Override 69 | protected final void bindValues(SQLiteStatement stmt, LoginBean entity) { 70 | stmt.clearBindings(); 71 | 72 | Long _id = entity.get_id(); 73 | if (_id != null) { 74 | stmt.bindLong(1, _id); 75 | } 76 | stmt.bindString(2, entity.getName()); 77 | stmt.bindString(3, entity.getPassword()); 78 | } 79 | 80 | @Override 81 | public Long readKey(Cursor cursor, int offset) { 82 | return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); 83 | } 84 | 85 | @Override 86 | public LoginBean readEntity(Cursor cursor, int offset) { 87 | LoginBean entity = new LoginBean( // 88 | cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // _id 89 | cursor.getString(offset + 1), // name 90 | cursor.getString(offset + 2) // password 91 | ); 92 | return entity; 93 | } 94 | 95 | @Override 96 | public void readEntity(Cursor cursor, LoginBean entity, int offset) { 97 | entity.set_id(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); 98 | entity.setName(cursor.getString(offset + 1)); 99 | entity.setPassword(cursor.getString(offset + 2)); 100 | } 101 | 102 | @Override 103 | protected final Long updateKeyAfterInsert(LoginBean entity, long rowId) { 104 | entity.set_id(rowId); 105 | return rowId; 106 | } 107 | 108 | @Override 109 | public Long getKey(LoginBean entity) { 110 | if(entity != null) { 111 | return entity.get_id(); 112 | } else { 113 | return null; 114 | } 115 | } 116 | 117 | @Override 118 | public boolean hasKey(LoginBean entity) { 119 | return entity.get_id() != null; 120 | } 121 | 122 | @Override 123 | protected final boolean isEntityUpdateable() { 124 | return true; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /app/src/main/java/com/ping/greendao/gen/RecordSleepBeanDao.java: -------------------------------------------------------------------------------- 1 | package com.ping.greendao.gen; 2 | 3 | import android.database.Cursor; 4 | import android.database.sqlite.SQLiteStatement; 5 | 6 | import org.greenrobot.greendao.AbstractDao; 7 | import org.greenrobot.greendao.Property; 8 | import org.greenrobot.greendao.internal.DaoConfig; 9 | import org.greenrobot.greendao.database.Database; 10 | import org.greenrobot.greendao.database.DatabaseStatement; 11 | 12 | import top.jplayer.audio.bean.RecordSleepBean; 13 | 14 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. 15 | /** 16 | * DAO for table "RECORD_SLEEP_BEAN". 17 | */ 18 | public class RecordSleepBeanDao extends AbstractDao { 19 | 20 | public static final String TABLENAME = "RECORD_SLEEP_BEAN"; 21 | 22 | /** 23 | * Properties of entity RecordSleepBean.
24 | * Can be used for QueryBuilder and for referencing column names. 25 | */ 26 | public static class Properties { 27 | public final static Property _id = new Property(0, Long.class, "_id", true, "_id"); 28 | public final static Property Day = new Property(1, String.class, "day", false, "DAY"); 29 | public final static Property StartTime = new Property(2, String.class, "startTime", false, "START_TIME"); 30 | public final static Property EndTime = new Property(3, String.class, "endTime", false, "END_TIME"); 31 | public final static Property SleepTime = new Property(4, String.class, "sleepTime", false, "SLEEP_TIME"); 32 | public final static Property SleepSnoring = new Property(5, String.class, "sleepSnoring", false, "SLEEP_SNORING"); 33 | public final static Property Account = new Property(6, String.class, "account", false, "ACCOUNT"); 34 | } 35 | 36 | 37 | public RecordSleepBeanDao(DaoConfig config) { 38 | super(config); 39 | } 40 | 41 | public RecordSleepBeanDao(DaoConfig config, DaoSession daoSession) { 42 | super(config, daoSession); 43 | } 44 | 45 | /** Creates the underlying database table. */ 46 | public static void createTable(Database db, boolean ifNotExists) { 47 | String constraint = ifNotExists? "IF NOT EXISTS ": ""; 48 | db.execSQL("CREATE TABLE " + constraint + "\"RECORD_SLEEP_BEAN\" (" + // 49 | "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: _id 50 | "\"DAY\" TEXT NOT NULL ," + // 1: day 51 | "\"START_TIME\" TEXT NOT NULL ," + // 2: startTime 52 | "\"END_TIME\" TEXT NOT NULL ," + // 3: endTime 53 | "\"SLEEP_TIME\" TEXT NOT NULL ," + // 4: sleepTime 54 | "\"SLEEP_SNORING\" TEXT NOT NULL ," + // 5: sleepSnoring 55 | "\"ACCOUNT\" TEXT NOT NULL );"); // 6: account 56 | } 57 | 58 | /** Drops the underlying database table. */ 59 | public static void dropTable(Database db, boolean ifExists) { 60 | String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"RECORD_SLEEP_BEAN\""; 61 | db.execSQL(sql); 62 | } 63 | 64 | @Override 65 | protected final void bindValues(DatabaseStatement stmt, RecordSleepBean entity) { 66 | stmt.clearBindings(); 67 | 68 | Long _id = entity.get_id(); 69 | if (_id != null) { 70 | stmt.bindLong(1, _id); 71 | } 72 | stmt.bindString(2, entity.getDay()); 73 | stmt.bindString(3, entity.getStartTime()); 74 | stmt.bindString(4, entity.getEndTime()); 75 | stmt.bindString(5, entity.getSleepTime()); 76 | stmt.bindString(6, entity.getSleepSnoring()); 77 | stmt.bindString(7, entity.getAccount()); 78 | } 79 | 80 | @Override 81 | protected final void bindValues(SQLiteStatement stmt, RecordSleepBean entity) { 82 | stmt.clearBindings(); 83 | 84 | Long _id = entity.get_id(); 85 | if (_id != null) { 86 | stmt.bindLong(1, _id); 87 | } 88 | stmt.bindString(2, entity.getDay()); 89 | stmt.bindString(3, entity.getStartTime()); 90 | stmt.bindString(4, entity.getEndTime()); 91 | stmt.bindString(5, entity.getSleepTime()); 92 | stmt.bindString(6, entity.getSleepSnoring()); 93 | stmt.bindString(7, entity.getAccount()); 94 | } 95 | 96 | @Override 97 | public Long readKey(Cursor cursor, int offset) { 98 | return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); 99 | } 100 | 101 | @Override 102 | public RecordSleepBean readEntity(Cursor cursor, int offset) { 103 | RecordSleepBean entity = new RecordSleepBean( // 104 | cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // _id 105 | cursor.getString(offset + 1), // day 106 | cursor.getString(offset + 2), // startTime 107 | cursor.getString(offset + 3), // endTime 108 | cursor.getString(offset + 4), // sleepTime 109 | cursor.getString(offset + 5), // sleepSnoring 110 | cursor.getString(offset + 6) // account 111 | ); 112 | return entity; 113 | } 114 | 115 | @Override 116 | public void readEntity(Cursor cursor, RecordSleepBean entity, int offset) { 117 | entity.set_id(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); 118 | entity.setDay(cursor.getString(offset + 1)); 119 | entity.setStartTime(cursor.getString(offset + 2)); 120 | entity.setEndTime(cursor.getString(offset + 3)); 121 | entity.setSleepTime(cursor.getString(offset + 4)); 122 | entity.setSleepSnoring(cursor.getString(offset + 5)); 123 | entity.setAccount(cursor.getString(offset + 6)); 124 | } 125 | 126 | @Override 127 | protected final Long updateKeyAfterInsert(RecordSleepBean entity, long rowId) { 128 | entity.set_id(rowId); 129 | return rowId; 130 | } 131 | 132 | @Override 133 | public Long getKey(RecordSleepBean entity) { 134 | if(entity != null) { 135 | return entity.get_id(); 136 | } else { 137 | return null; 138 | } 139 | } 140 | 141 | @Override 142 | public boolean hasKey(RecordSleepBean entity) { 143 | return entity.get_id() != null; 144 | } 145 | 146 | @Override 147 | protected final boolean isEntityUpdateable() { 148 | return true; 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/ActivitySVG.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.os.Message; 7 | import android.widget.ImageView; 8 | import android.widget.RelativeLayout; 9 | 10 | import com.jaredrummler.android.widget.AnimatedSvgView; 11 | import com.vondear.rxtools.RxActivityTool; 12 | import com.vondear.rxtools.RxBarTool; 13 | import com.vondear.rxtools.activity.ActivityBase; 14 | 15 | import butterknife.BindView; 16 | import butterknife.ButterKnife; 17 | import top.jplayer.audio.bean.ModelSVG; 18 | 19 | /** 20 | * @author vondear 21 | */ 22 | public class ActivitySVG extends ActivityBase { 23 | 24 | @BindView(R.id.animated_svg_view) 25 | AnimatedSvgView mSvgView; 26 | @BindView(R.id.activity_svg) 27 | RelativeLayout mActivitySvg; 28 | @BindView(R.id.app_name) 29 | ImageView mAppName; 30 | @SuppressLint("HandlerLeak") 31 | private Handler checkhandler = new Handler() { 32 | @Override 33 | public void handleMessage(Message msg) { 34 | // mAppName.setVisibility(View.VISIBLE); 35 | } 36 | }; 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | RxBarTool.hideStatusBar(this); 42 | setContentView(R.layout.activity_svg); 43 | ButterKnife.bind(this); 44 | setSvg(ModelSVG.values()[0]); 45 | CheckUpdate(); 46 | } 47 | 48 | private void setSvg(ModelSVG modelSvg) { 49 | mSvgView.setGlyphStrings(modelSvg.glyphs); 50 | mSvgView.setFillColors(modelSvg.colors); 51 | mSvgView.setViewportSize(modelSvg.width, modelSvg.height); 52 | mSvgView.setTraceResidueColor(0x32000000); 53 | mSvgView.setTraceColors(modelSvg.colors); 54 | mSvgView.rebuildGlyphData(); 55 | mSvgView.start(); 56 | } 57 | 58 | 59 | private void CheckUpdate() { 60 | new Thread() { 61 | public void run() { 62 | try { 63 | Thread.sleep(500); 64 | Message msg = checkhandler.obtainMessage(); 65 | checkhandler.sendMessage(msg); 66 | Thread.sleep(2000); 67 | toMain(); 68 | } catch (Exception e) { 69 | // TODO Auto-generated catch block 70 | e.printStackTrace(); 71 | } 72 | } 73 | }.start(); 74 | } 75 | 76 | public void toMain() { 77 | RxActivityTool.skipActivityAndFinish(this, ActivityLoginAct.class); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/AudioApplication.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio; 2 | 3 | import android.content.Context; 4 | import android.os.Build; 5 | import android.os.StrictMode; 6 | import android.support.multidex.MultiDex; 7 | import android.support.multidex.MultiDexApplication; 8 | 9 | import com.tencent.bugly.Bugly; 10 | import com.tencent.bugly.beta.Beta; 11 | import com.vondear.rxtools.RxTool; 12 | 13 | /** 14 | * Created by Administrator on 2018/5/5. 15 | * rul 16 | */ 17 | 18 | public class AudioApplication extends MultiDexApplication { 19 | 20 | public static AudioApplication application; 21 | 22 | @Override 23 | public void onCreate() { 24 | super.onCreate(); 25 | application = this; 26 | RxTool.init(this); 27 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 28 | StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); 29 | StrictMode.setVmPolicy(builder.build()); 30 | } 31 | Bugly.init(this, "4b3faed579", false); 32 | } 33 | @Override 34 | protected void attachBaseContext(Context base) { 35 | super.attachBaseContext(base); 36 | // you must install multiDex whatever tinker is installed! 37 | MultiDex.install(base); 38 | 39 | 40 | // 安装tinker 41 | Beta.installTinker(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/RecordSleepActivity.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.ActionBar; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.text.TextUtils; 8 | import android.util.Log; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.Toast; 12 | 13 | import com.necer.ncalendar.calendar.NCalendar; 14 | import com.necer.ncalendar.listener.OnCalendarChangedListener; 15 | 16 | import org.joda.time.LocalDate; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import butterknife.BindView; 22 | import butterknife.ButterKnife; 23 | import butterknife.Unbinder; 24 | import top.jplayer.audio.bean.RecordSleepBean; 25 | import top.jplayer.audio.dialog.CurrentRecordDialog; 26 | import top.jplayer.audio.utils.RecordDaoUtil; 27 | 28 | import static top.jplayer.audio.utils.DateUtils.getCurrentBigMonth; 29 | 30 | /** 31 | * Created by Obl on 2018/5/7. 32 | * top.jplayer.audio 33 | * call me : jplayer_top@163.com 34 | * github : https://github.com/oblivion0001 35 | */ 36 | 37 | public class RecordSleepActivity extends AppCompatActivity { 38 | @BindView(R.id.ncalendarrrr) 39 | NCalendar mNcalendar; 40 | @BindView(R.id.showRecord) 41 | Button showRecord; 42 | private Unbinder mUnbinder; 43 | private ActionBar mActionBar; 44 | private List mRecordSleepBeans; 45 | RecordSleepBean recordBean; 46 | 47 | @Override 48 | protected void onCreate(@Nullable Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | setContentView(R.layout.activity_sleep_record); 51 | mActionBar = getSupportActionBar(); 52 | mUnbinder = ButterKnife.bind(this); 53 | 54 | RecordDaoUtil recordDaoUtil = new RecordDaoUtil(this); 55 | mRecordSleepBeans = recordDaoUtil.queryAllbean(); 56 | 57 | List list = new ArrayList<>(); 58 | for (RecordSleepBean recordSleepBean : mRecordSleepBeans) { 59 | list.add(recordSleepBean.day); 60 | } 61 | mNcalendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { 62 | @Override 63 | public void onCalendarChanged(LocalDate date) { 64 | Log.e("asda", date.toString()); 65 | if (mActionBar != null) { 66 | mActionBar.setTitle(getCurrentBigMonth(date.toString())); 67 | } 68 | for (RecordSleepBean recordSleepBean : mRecordSleepBeans) { 69 | if (TextUtils.equals(recordSleepBean.day, date.toString())) { 70 | recordBean = recordSleepBean; 71 | showRecord.setEnabled(true); 72 | break; 73 | } else { 74 | showRecord.setEnabled(false); 75 | recordBean = null; 76 | } 77 | } 78 | } 79 | }); 80 | 81 | showRecord.setOnClickListener(new View.OnClickListener() { 82 | @Override 83 | public void onClick(View v) { 84 | if (recordBean != null) { 85 | CurrentRecordDialog dialog = new CurrentRecordDialog(); 86 | Bundle arguments = new Bundle(); 87 | arguments.putParcelable("record", recordBean); 88 | dialog.setArguments(arguments); 89 | dialog.show(getSupportFragmentManager(), "current"); 90 | } else { 91 | Toast.makeText(RecordSleepActivity.this, "当日无测量数据", Toast.LENGTH_SHORT).show(); 92 | } 93 | } 94 | }); 95 | mNcalendar.setPoint(list); 96 | } 97 | 98 | @Override 99 | protected void onDestroy() { 100 | super.onDestroy(); 101 | mUnbinder.unbind(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/WavePlayActivity.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | import android.widget.Button; 8 | import android.widget.RelativeLayout; 9 | import android.widget.SeekBar; 10 | 11 | import com.piterwilson.audio.MP3RadioStreamDelegate; 12 | import com.piterwilson.audio.MP3RadioStreamPlayer; 13 | import com.shuyu.waveview.AudioWaveView; 14 | 15 | import java.io.IOException; 16 | import java.util.Timer; 17 | import java.util.TimerTask; 18 | 19 | import butterknife.BindView; 20 | import butterknife.ButterKnife; 21 | import butterknife.OnClick; 22 | import top.jplayer.audio.utils.ScreenUtils; 23 | import top.jplayer.audio.utils.SizeUtils; 24 | 25 | 26 | /** 27 | * Created by Administrator on 2018/5/4. 28 | * 播放界面 29 | */ 30 | 31 | public class WavePlayActivity extends AppCompatActivity implements MP3RadioStreamDelegate { 32 | 33 | private final static String TAG = "WavePlayActivity"; 34 | 35 | @BindView(R.id.audioWave) 36 | AudioWaveView audioWave; 37 | @BindView(R.id.activity_wave_play) 38 | RelativeLayout activityWavePlay; 39 | @BindView(R.id.playBtn) 40 | Button playBtn; 41 | @BindView(R.id.seekBar) 42 | SeekBar seekBar; 43 | 44 | 45 | MP3RadioStreamPlayer player; 46 | 47 | Timer timer; 48 | 49 | boolean playeEnd; 50 | 51 | boolean seekBarTouch; 52 | 53 | @Override 54 | protected void onCreate(Bundle savedInstanceState) { 55 | super.onCreate(savedInstanceState); 56 | setContentView(R.layout.activity_wave_play); 57 | ButterKnife.bind(this); 58 | new Handler().postDelayed(new Runnable() { 59 | @Override 60 | public void run() { 61 | play(); 62 | } 63 | }, 1000); 64 | playBtn.setEnabled(false); 65 | seekBar.setEnabled(false); 66 | 67 | 68 | seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 69 | @Override 70 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 71 | 72 | } 73 | 74 | @Override 75 | public void onStartTrackingTouch(SeekBar seekBar) { 76 | seekBarTouch = true; 77 | } 78 | 79 | @Override 80 | public void onStopTrackingTouch(SeekBar seekBar) { 81 | seekBarTouch = false; 82 | if (!playeEnd) { 83 | player.seekTo(seekBar.getProgress()); 84 | } 85 | } 86 | }); 87 | 88 | timer = new Timer(); 89 | timer.schedule(new TimerTask() { 90 | @Override 91 | public void run() { 92 | if (playeEnd || player == null || !seekBar.isEnabled()) { 93 | return; 94 | } 95 | long position = player.getCurPosition(); 96 | if (position > 0 && !seekBarTouch) { 97 | seekBar.setProgress((int) position); 98 | } 99 | } 100 | }, 1000, 1000); 101 | } 102 | 103 | 104 | @Override 105 | protected void onDestroy() { 106 | super.onDestroy(); 107 | audioWave.stopView(); 108 | if (timer != null) { 109 | timer.cancel(); 110 | timer = null; 111 | } 112 | stop(); 113 | } 114 | 115 | @OnClick(R.id.playBtn) 116 | public void onClick() { 117 | 118 | if (playeEnd) { 119 | stop(); 120 | playBtn.setText("暂停"); 121 | seekBar.setEnabled(true); 122 | play(); 123 | return; 124 | } 125 | 126 | if (player.isPause()) { 127 | playBtn.setText("暂停"); 128 | player.setPause(false); 129 | seekBar.setEnabled(false); 130 | } else { 131 | playBtn.setText("播放"); 132 | player.setPause(true); 133 | seekBar.setEnabled(true); 134 | } 135 | 136 | } 137 | 138 | private void play() { 139 | if (player != null) { 140 | player.stop(); 141 | player.release(); 142 | player = null; 143 | } 144 | player = new MP3RadioStreamPlayer(); 145 | //player.setUrlString(this, true, "http://www.stephaniequinn.com/Music/Commercial%20DEMO%20-%2005.mp3"); 146 | player.setUrlString(getIntent().getStringExtra("uri")); 147 | player.setDelegate(this); 148 | 149 | int size = ScreenUtils.getScreenWidth() / SizeUtils.dp2px(1);//控件默认的间隔是1 150 | player.setDataList(audioWave.getRecList(), size); 151 | //player.setWaveSpeed(1100); 152 | //mRecorder.setDataList(audioWave.getRecList(), size); 153 | //player.setStartWaveTime(5000); 154 | //audioWave.setDrawBase(false); 155 | audioWave.setBaseRecorder(player); 156 | audioWave.startView(); 157 | try { 158 | player.play(); 159 | } catch (IOException e) { 160 | e.printStackTrace(); 161 | } 162 | } 163 | 164 | 165 | private void stop() { 166 | player.stop(); 167 | } 168 | 169 | 170 | /**************************************** 171 | * Delegate methods. These are all fired from a background thread so we have to call any GUI code on the main thread. 172 | ****************************************/ 173 | 174 | @Override 175 | public void onRadioPlayerPlaybackStarted(final MP3RadioStreamPlayer player) { 176 | Log.i(TAG, "onRadioPlayerPlaybackStarted"); 177 | this.runOnUiThread(new Runnable() { 178 | 179 | @Override 180 | public void run() { 181 | playeEnd = false; 182 | playBtn.setEnabled(true); 183 | seekBar.setMax((int) player.getDuration()); 184 | seekBar.setEnabled(true); 185 | } 186 | }); 187 | } 188 | 189 | @Override 190 | public void onRadioPlayerStopped(MP3RadioStreamPlayer player) { 191 | Log.i(TAG, "onRadioPlayerStopped"); 192 | this.runOnUiThread(new Runnable() { 193 | 194 | @Override 195 | public void run() { 196 | playeEnd = true; 197 | playBtn.setText("播放"); 198 | playBtn.setEnabled(true); 199 | seekBar.setEnabled(false); 200 | } 201 | }); 202 | 203 | } 204 | 205 | @Override 206 | public void onRadioPlayerError(MP3RadioStreamPlayer player) { 207 | Log.i(TAG, "onRadioPlayerError"); 208 | this.runOnUiThread(new Runnable() { 209 | 210 | @Override 211 | public void run() { 212 | playeEnd = false; 213 | playBtn.setEnabled(true); 214 | seekBar.setEnabled(false); 215 | } 216 | }); 217 | 218 | } 219 | 220 | @Override 221 | public void onRadioPlayerBuffering(MP3RadioStreamPlayer player) { 222 | Log.i(TAG, "onRadioPlayerBuffering"); 223 | this.runOnUiThread(new Runnable() { 224 | 225 | @Override 226 | public void run() { 227 | playBtn.setEnabled(false); 228 | seekBar.setEnabled(false); 229 | } 230 | }); 231 | 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/WebActivity.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio; 2 | 3 | import android.content.Intent; 4 | import android.content.res.Configuration; 5 | import android.graphics.Bitmap; 6 | import android.graphics.Paint; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import android.os.Bundle; 10 | import android.text.method.MovementMethod; 11 | import android.util.Log; 12 | import android.view.View; 13 | import android.webkit.DownloadListener; 14 | import android.webkit.WebChromeClient; 15 | import android.webkit.WebSettings; 16 | import android.webkit.WebView; 17 | import android.webkit.WebViewClient; 18 | import android.widget.ImageView; 19 | import android.widget.LinearLayout; 20 | import android.widget.ProgressBar; 21 | import android.widget.TextView; 22 | import android.widget.Toast; 23 | 24 | import com.vondear.rxtools.RxBarTool; 25 | import com.vondear.rxtools.RxImageTool; 26 | import com.vondear.rxtools.RxKeyboardTool; 27 | import com.vondear.rxtools.activity.ActivityBase; 28 | import com.vondear.rxtools.activity.ActivityWebView; 29 | import com.vondear.rxtools.view.RxTextAutoZoom; 30 | 31 | /** 32 | * Created by Administrator on 2018/5/5. 33 | * webView 34 | */ 35 | 36 | public class WebActivity extends ActivityBase { 37 | private static final int TIME_INTERVAL = 2000; 38 | ProgressBar pbWebBase; 39 | TextView tvTitle; 40 | WebView webBase; 41 | ImageView ivFinish; 42 | RxTextAutoZoom mRxTextAutoZoom; 43 | LinearLayout llIncludeTitle; 44 | private String webPath = ""; 45 | private long mBackPressed; 46 | 47 | 48 | protected void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | RxBarTool.setTransparentStatusBar(this); 51 | this.setContentView(com.vondear.rxtools.R.layout.activity_webview); 52 | this.getWindow().setSoftInputMode(32); 53 | this.initView(); 54 | this.initData(); 55 | } 56 | 57 | private void initView() { 58 | this.mRxTextAutoZoom = (RxTextAutoZoom) this.findViewById(com.vondear.rxtools.R.id.afet_tv_title); 59 | this.llIncludeTitle = (LinearLayout) this.findViewById(com.vondear.rxtools.R.id.ll_include_title); 60 | this.tvTitle = (TextView) this.findViewById(com.vondear.rxtools.R.id.tv_title); 61 | this.pbWebBase = (ProgressBar) this.findViewById(com.vondear.rxtools.R.id.pb_web_base); 62 | this.webBase = (WebView) this.findViewById(com.vondear.rxtools.R.id.web_base); 63 | this.ivFinish = (ImageView) this.findViewById(com.vondear.rxtools.R.id.iv_finish); 64 | this.ivFinish.setOnClickListener(new View.OnClickListener() { 65 | public void onClick(View view) { 66 | if (WebActivity.this.webBase.canGoBack()) { 67 | WebActivity.this.webBase.goBack(); 68 | } else { 69 | WebActivity.this.finish(); 70 | } 71 | 72 | } 73 | }); 74 | this.initAutoFitEditText(); 75 | } 76 | 77 | public void initAutoFitEditText() { 78 | this.mRxTextAutoZoom.clearFocus(); 79 | this.mRxTextAutoZoom.setEnabled(false); 80 | this.mRxTextAutoZoom.setFocusableInTouchMode(false); 81 | this.mRxTextAutoZoom.setFocusable(false); 82 | this.mRxTextAutoZoom.setEnableSizeCache(false); 83 | this.mRxTextAutoZoom.setMovementMethod((MovementMethod) null); 84 | this.mRxTextAutoZoom.setMaxHeight(RxImageTool.dip2px(55.0F)); 85 | this.mRxTextAutoZoom.setMinTextSize(Float.valueOf(37.0F)); 86 | RxTextAutoZoom.setNormalization(this, this.llIncludeTitle, this.mRxTextAutoZoom); 87 | RxKeyboardTool.hideSoftInput(this); 88 | } 89 | 90 | private void initData() { 91 | this.pbWebBase.setMax(100); 92 | Bundle bundle = getIntent().getBundleExtra("bundle"); 93 | this.webPath = bundle.getString("url"); 94 | if ("".equals(this.webPath)) { 95 | this.webPath = "http://www.baidu.com"; 96 | } 97 | 98 | WebSettings webSettings = this.webBase.getSettings(); 99 | if (Build.VERSION.SDK_INT >= 19) { 100 | webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); 101 | } 102 | 103 | if (Build.VERSION.SDK_INT >= 19) { 104 | webSettings.setLoadsImagesAutomatically(true); 105 | } else { 106 | webSettings.setLoadsImagesAutomatically(false); 107 | } 108 | 109 | if (Build.VERSION.SDK_INT >= 11) { 110 | this.webBase.setLayerType(1, (Paint) null); 111 | } 112 | 113 | this.webBase.setLayerType(2, (Paint) null); 114 | webSettings.setJavaScriptEnabled(true); 115 | webSettings.setSupportZoom(true); 116 | webSettings.setBuiltInZoomControls(true); 117 | webSettings.setDisplayZoomControls(false); 118 | webSettings.setUseWideViewPort(true); 119 | webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); 120 | webSettings.setLoadWithOverviewMode(true); 121 | webSettings.setDatabaseEnabled(true); 122 | webSettings.setSavePassword(true); 123 | webSettings.setDomStorageEnabled(true); 124 | this.webBase.setSaveEnabled(true); 125 | this.webBase.setKeepScreenOn(true); 126 | this.webBase.setWebChromeClient(new WebChromeClient() { 127 | public void onReceivedTitle(WebView view, String title) { 128 | super.onReceivedTitle(view, title); 129 | WebActivity.this.mRxTextAutoZoom.setText(title); 130 | } 131 | 132 | public void onProgressChanged(WebView view, int newProgress) { 133 | WebActivity.this.pbWebBase.setProgress(newProgress); 134 | super.onProgressChanged(view, newProgress); 135 | } 136 | }); 137 | this.webBase.setWebViewClient(new WebViewClient() { 138 | public void onPageFinished(WebView view, String url) { 139 | super.onPageFinished(view, url); 140 | if (!WebActivity.this.webBase.getSettings().getLoadsImagesAutomatically()) { 141 | WebActivity.this.webBase.getSettings().setLoadsImagesAutomatically(true); 142 | } 143 | 144 | WebActivity.this.pbWebBase.setVisibility(View.GONE); 145 | } 146 | 147 | public void onPageStarted(WebView view, String url, Bitmap favicon) { 148 | WebActivity.this.pbWebBase.setVisibility(View.VISIBLE); 149 | super.onPageStarted(view, url, favicon); 150 | } 151 | 152 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 153 | if (!url.startsWith("http:") && !url.startsWith("https:")) { 154 | try { 155 | Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url)); 156 | WebActivity.this.startActivity(intent); 157 | } catch (Exception var4) { 158 | var4.printStackTrace(); 159 | } 160 | 161 | return true; 162 | } else { 163 | view.loadUrl(url); 164 | return false; 165 | } 166 | } 167 | }); 168 | this.webBase.setDownloadListener(new DownloadListener() { 169 | public void onDownloadStart(String paramAnonymousString1, String paramAnonymousString2, String paramAnonymousString3, String paramAnonymousString4, long paramAnonymousLong) { 170 | Intent intent = new Intent(); 171 | intent.setAction("android.intent.action.VIEW"); 172 | intent.setData(Uri.parse(paramAnonymousString1)); 173 | WebActivity.this.startActivity(intent); 174 | } 175 | }); 176 | this.webBase.loadUrl(this.webPath); 177 | Log.v("帮助类完整连接", this.webPath); 178 | } 179 | 180 | protected void onSaveInstanceState(Bundle paramBundle) { 181 | super.onSaveInstanceState(paramBundle); 182 | paramBundle.putString("url", this.webBase.getUrl()); 183 | } 184 | 185 | public void onConfigurationChanged(Configuration newConfig) { 186 | try { 187 | super.onConfigurationChanged(newConfig); 188 | if (this.getResources().getConfiguration().orientation == 2) { 189 | Log.v("Himi", "onConfigurationChanged_ORIENTATION_LANDSCAPE"); 190 | } else if (this.getResources().getConfiguration().orientation == 1) { 191 | Log.v("Himi", "onConfigurationChanged_ORIENTATION_PORTRAIT"); 192 | } 193 | } catch (Exception var3) { 194 | ; 195 | } 196 | 197 | } 198 | 199 | public void onBackPressed() { 200 | if (this.webBase.canGoBack()) { 201 | this.webBase.goBack(); 202 | } else { 203 | if (this.mBackPressed + 2000L > System.currentTimeMillis()) { 204 | super.onBackPressed(); 205 | return; 206 | } 207 | 208 | Toast.makeText(this.getBaseContext(), "再次点击返回键退出", Toast.LENGTH_SHORT).show(); 209 | this.mBackPressed = System.currentTimeMillis(); 210 | } 211 | 212 | } 213 | } -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/bean/LoginBean.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.bean; 2 | 3 | import org.greenrobot.greendao.annotation.Entity; 4 | import org.greenrobot.greendao.annotation.Id; 5 | import org.greenrobot.greendao.annotation.NotNull; 6 | import org.greenrobot.greendao.annotation.Generated; 7 | 8 | /** 9 | * Created by Administrator on 2018/5/5. 10 | * 登录Bean 11 | */ 12 | @Entity 13 | public class LoginBean { 14 | @Id(autoincrement = true) 15 | private Long _id; 16 | @NotNull 17 | public String name; 18 | @NotNull 19 | public String password; 20 | @Generated(hash = 1213769788) 21 | public LoginBean(Long _id, @NotNull String name, @NotNull String password) { 22 | this._id = _id; 23 | this.name = name; 24 | this.password = password; 25 | } 26 | @Generated(hash = 1112702939) 27 | public LoginBean() { 28 | } 29 | public Long get_id() { 30 | return this._id; 31 | } 32 | public void set_id(Long _id) { 33 | this._id = _id; 34 | } 35 | public String getName() { 36 | return this.name; 37 | } 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | public String getPassword() { 42 | return this.password; 43 | } 44 | public void setPassword(String password) { 45 | this.password = password; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/bean/RecordSleepBean.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.bean; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import org.greenrobot.greendao.annotation.Entity; 7 | import org.greenrobot.greendao.annotation.Id; 8 | import org.greenrobot.greendao.annotation.NotNull; 9 | import org.greenrobot.greendao.annotation.Generated; 10 | 11 | /** 12 | * Created by Obl on 2018/5/7. 13 | * top.jplayer.audio.bean 14 | * call me : jplayer_top@163.com 15 | * github : https://github.com/oblivion0001 16 | */ 17 | @Entity 18 | public class RecordSleepBean implements Parcelable{ 19 | @Id(autoincrement = true) 20 | private Long _id; 21 | @NotNull 22 | public String day; 23 | @NotNull 24 | public String startTime; 25 | @NotNull 26 | public String endTime; 27 | @NotNull 28 | public String sleepTime; 29 | @NotNull 30 | public String sleepSnoring; 31 | @NotNull 32 | public String account; 33 | @Generated(hash = 902071034) 34 | public RecordSleepBean(Long _id, @NotNull String day, @NotNull String startTime, 35 | @NotNull String endTime, @NotNull String sleepTime, 36 | @NotNull String sleepSnoring, @NotNull String account) { 37 | this._id = _id; 38 | this.day = day; 39 | this.startTime = startTime; 40 | this.endTime = endTime; 41 | this.sleepTime = sleepTime; 42 | this.sleepSnoring = sleepSnoring; 43 | this.account = account; 44 | } 45 | @Generated(hash = 423924899) 46 | public RecordSleepBean() { 47 | } 48 | 49 | protected RecordSleepBean(Parcel in) { 50 | if (in.readByte() == 0) { 51 | _id = null; 52 | } else { 53 | _id = in.readLong(); 54 | } 55 | day = in.readString(); 56 | startTime = in.readString(); 57 | endTime = in.readString(); 58 | sleepTime = in.readString(); 59 | sleepSnoring = in.readString(); 60 | account = in.readString(); 61 | } 62 | 63 | public static final Creator CREATOR = new Creator() { 64 | @Override 65 | public RecordSleepBean createFromParcel(Parcel in) { 66 | return new RecordSleepBean(in); 67 | } 68 | 69 | @Override 70 | public RecordSleepBean[] newArray(int size) { 71 | return new RecordSleepBean[size]; 72 | } 73 | }; 74 | 75 | public Long get_id() { 76 | return this._id; 77 | } 78 | public void set_id(Long _id) { 79 | this._id = _id; 80 | } 81 | public String getDay() { 82 | return this.day; 83 | } 84 | public void setDay(String day) { 85 | this.day = day; 86 | } 87 | public String getStartTime() { 88 | return this.startTime; 89 | } 90 | public void setStartTime(String startTime) { 91 | this.startTime = startTime; 92 | } 93 | public String getEndTime() { 94 | return this.endTime; 95 | } 96 | public void setEndTime(String endTime) { 97 | this.endTime = endTime; 98 | } 99 | public String getSleepTime() { 100 | return this.sleepTime; 101 | } 102 | public void setSleepTime(String sleepTime) { 103 | this.sleepTime = sleepTime; 104 | } 105 | public String getSleepSnoring() { 106 | return this.sleepSnoring; 107 | } 108 | public void setSleepSnoring(String sleepSnoring) { 109 | this.sleepSnoring = sleepSnoring; 110 | } 111 | public String getAccount() { 112 | return this.account; 113 | } 114 | public void setAccount(String account) { 115 | this.account = account; 116 | } 117 | 118 | @Override 119 | public String toString() { 120 | return "RecordSleepBean{" + 121 | "_id=" + _id + 122 | ", day='" + day + '\'' + 123 | ", startTime='" + startTime + '\'' + 124 | ", endTime='" + endTime + '\'' + 125 | ", sleepTime='" + sleepTime + '\'' + 126 | ", sleepSnoring='" + sleepSnoring + '\'' + 127 | ", account='" + account + '\'' + 128 | '}'; 129 | } 130 | 131 | @Override 132 | public int describeContents() { 133 | return 0; 134 | } 135 | 136 | @Override 137 | public void writeToParcel(Parcel dest, int flags) { 138 | if (_id == null) { 139 | dest.writeByte((byte) 0); 140 | } else { 141 | dest.writeByte((byte) 1); 142 | dest.writeLong(_id); 143 | } 144 | dest.writeString(day); 145 | dest.writeString(startTime); 146 | dest.writeString(endTime); 147 | dest.writeString(sleepTime); 148 | dest.writeString(sleepSnoring); 149 | dest.writeString(account); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/dialog/BaseCustomDialogFragment.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.dialog; 2 | 3 | import android.app.Dialog; 4 | import android.content.DialogInterface; 5 | import android.os.Bundle; 6 | import android.support.annotation.LayoutRes; 7 | import android.support.annotation.NonNull; 8 | import android.support.v4.app.DialogFragment; 9 | import android.support.v4.app.FragmentActivity; 10 | import android.view.Gravity; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.view.Window; 15 | import android.view.WindowManager; 16 | import android.widget.EditText; 17 | 18 | import com.vondear.rxtools.RxKeyboardTool; 19 | 20 | import top.jplayer.audio.R; 21 | 22 | 23 | /** 24 | * Created by Obl on 2018/3/20. 25 | * top.jplayer.baseprolibrary.widgets.dialog 26 | */ 27 | 28 | public abstract class BaseCustomDialogFragment extends DialogFragment { 29 | 30 | public View mContentView; 31 | 32 | 33 | @NonNull 34 | @Override 35 | public Dialog onCreateDialog(Bundle savedInstanceState) { 36 | Dialog dialog = new Dialog(getActivity(), R.style.dialog_custom); 37 | dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 38 | dialog.setCancelable(true); 39 | dialog.setCanceledOnTouchOutside(true); 40 | dialog.setContentView(contentView()); 41 | return dialog; 42 | } 43 | 44 | private View contentView() { 45 | mContentView = LayoutInflater.from(getContext()).inflate(initLayout(), null); 46 | return mContentView; 47 | } 48 | 49 | @Override 50 | public void onResume() { 51 | super.onResume(); 52 | Window window = getDialog().getWindow(); 53 | if (window != null) { 54 | window.setGravity(setGravity()); //此处可以设置dialog显示的位置 55 | window.setWindowAnimations(setAnim()); //添加动画 56 | WindowManager.LayoutParams layoutParams = window.getAttributes(); 57 | layoutParams.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND; 58 | layoutParams.dimAmount = setAlpha(); 59 | window.getDecorView().setPadding(0, 0, 0, 0); 60 | window.setLayout(setWidth(), setHeight()); 61 | window.setAttributes(layoutParams); 62 | window.setSoftInputMode(setSoftInputState()); 63 | } 64 | initView(mContentView); 65 | initData(mContentView); 66 | } 67 | 68 | public void initData(View view) { 69 | 70 | } 71 | 72 | public float setAlpha() { 73 | return 0.5f; 74 | } 75 | 76 | private int setWidth() { 77 | return ViewGroup.LayoutParams.MATCH_PARENT; 78 | } 79 | 80 | public int setHeight() { 81 | return ViewGroup.LayoutParams.WRAP_CONTENT; 82 | } 83 | 84 | public int setAnim() { 85 | return R.style.AnimBottom; 86 | } 87 | 88 | public int setGravity() { 89 | return Gravity.BOTTOM; 90 | } 91 | 92 | @Override 93 | public void onDismiss(DialogInterface dialog) { 94 | super.onDismiss(dialog); 95 | FragmentActivity activity = getActivity(); 96 | if (activity != null) { 97 | RxKeyboardTool.hideSoftInput(activity); 98 | } 99 | } 100 | 101 | protected abstract void initView(View view); 102 | 103 | public abstract @LayoutRes 104 | int initLayout(); 105 | 106 | public int setSoftInputState() { 107 | return WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN; 108 | } 109 | 110 | /** 111 | * 手动打开软键盘 112 | */ 113 | public void setSoftInputMethod(EditText editText) { 114 | FragmentActivity activity = getActivity(); 115 | if (activity != null) { 116 | RxKeyboardTool.showSoftInput(activity, editText); 117 | } 118 | } 119 | } 120 | 121 | 122 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/dialog/CurrentRecordDialog.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.dialog; 2 | 3 | import android.os.Bundle; 4 | import android.view.Gravity; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import butterknife.BindView; 9 | import butterknife.ButterKnife; 10 | import top.jplayer.audio.R; 11 | import top.jplayer.audio.bean.RecordSleepBean; 12 | import top.jplayer.audio.utils.ScreenUtils; 13 | import top.jplayer.audio.utils.SizeUtils; 14 | 15 | /** 16 | * Created by Obl on 2018/5/7. 17 | * top.jplayer.audio.dialog 18 | * call me : jplayer_top@163.com 19 | * github : https://github.com/oblivion0001 20 | */ 21 | 22 | public class CurrentRecordDialog extends BaseCustomDialogFragment { 23 | @BindView(R.id.tvCurDay) 24 | TextView mTvCurDay; 25 | @BindView(R.id.tvStartTime) 26 | TextView mTvStartTime; 27 | @BindView(R.id.tvEndTime) 28 | TextView mTvEndTime; 29 | @BindView(R.id.tvSleepTime) 30 | TextView mTvSleepTime; 31 | @BindView(R.id.tvSnoringCount) 32 | TextView mTvSnoringCount; 33 | @BindView(R.id.tvRecord) 34 | TextView mTvRecord; 35 | 36 | @Override 37 | protected void initView(View view) { 38 | ButterKnife.bind(this, view); 39 | Bundle bundle = getArguments(); 40 | if (bundle != null) { 41 | RecordSleepBean recordBean = bundle.getParcelable("record"); 42 | if (recordBean != null) { 43 | mTvCurDay.setText(recordBean.day); 44 | mTvSnoringCount.setText(recordBean.sleepSnoring); 45 | mTvEndTime.setText(recordBean.endTime); 46 | mTvStartTime.setText(recordBean.startTime); 47 | mTvSleepTime.setText(recordBean.sleepTime); 48 | mTvRecord.setText(recordBean.account); 49 | } 50 | } 51 | } 52 | 53 | @Override 54 | public int setGravity() { 55 | return Gravity.CENTER; 56 | } 57 | 58 | @Override 59 | public int setAnim() { 60 | return R.style.AnimCenter; 61 | } 62 | 63 | @Override 64 | public int setHeight() { 65 | return ScreenUtils.getScreenHeight() - SizeUtils.dp2px(80); 66 | } 67 | 68 | @Override 69 | public int initLayout() { 70 | return R.layout.dialog_current_record; 71 | } 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/dialog/ForgetDialogFragment.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.dialog; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.text.Editable; 7 | import android.text.InputType; 8 | import android.text.TextUtils; 9 | import android.text.TextWatcher; 10 | import android.view.Gravity; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.EditText; 14 | import android.widget.ImageView; 15 | import android.widget.LinearLayout; 16 | import android.widget.RelativeLayout; 17 | import android.widget.ScrollView; 18 | import android.widget.Toast; 19 | 20 | import com.vondear.rxtools.RxBarTool; 21 | import com.vondear.rxtools.RxKeyboardTool; 22 | import com.vondear.rxtools.view.dialog.RxDialogShapeLoading; 23 | 24 | import java.util.List; 25 | import java.util.Random; 26 | 27 | import butterknife.BindView; 28 | import butterknife.ButterKnife; 29 | import butterknife.OnClick; 30 | import butterknife.Unbinder; 31 | import top.jplayer.audio.MainActivity; 32 | import top.jplayer.audio.R; 33 | import top.jplayer.audio.bean.LoginBean; 34 | import top.jplayer.audio.utils.LoginDaoUtil; 35 | import top.jplayer.audio.utils.ScreenUtils; 36 | 37 | /** 38 | * Created by Administrator on 2018/5/5. 39 | * 注册 40 | */ 41 | 42 | public class ForgetDialogFragment extends BaseCustomDialogFragment { 43 | @BindView(R.id.et_mobile) 44 | EditText etMobile; 45 | @BindView(R.id.iv_clean_phone) 46 | ImageView ivCleanPhone; 47 | @BindView(R.id.et_password) 48 | EditText etPassword; 49 | @BindView(R.id.clean_password) 50 | ImageView cleanPassword; 51 | @BindView(R.id.iv_show_pwd) 52 | ImageView ivShowPwd; 53 | @BindView(R.id.btn_login) 54 | Button btnLogin; 55 | Unbinder unbinder; 56 | @BindView(R.id.content) 57 | LinearLayout content; 58 | @BindView(R.id.scrollView) 59 | ScrollView scrollView; 60 | @BindView(R.id.root) 61 | RelativeLayout root; 62 | Unbinder unbinder1; 63 | private RxDialogShapeLoading rxDialogShapeLoading; 64 | 65 | @Override 66 | protected void initView(View view) { 67 | unbinder = ButterKnife.bind(this, view); 68 | RxBarTool.setTransparentStatusBar(getActivity());//状态栏透明化 69 | RxBarTool.StatusBarLightMode(getActivity()); 70 | btnLogin.setText("找回密码"); 71 | initEvent(); 72 | } 73 | 74 | private void initEvent() { 75 | etMobile.addTextChangedListener(new TextWatcher() { 76 | @Override 77 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 78 | 79 | } 80 | 81 | @Override 82 | public void onTextChanged(CharSequence s, int start, int before, int count) { 83 | 84 | } 85 | 86 | @Override 87 | public void afterTextChanged(Editable s) { 88 | if (!TextUtils.isEmpty(s) && ivCleanPhone.getVisibility() == View.GONE) { 89 | ivCleanPhone.setVisibility(View.VISIBLE); 90 | } else if (TextUtils.isEmpty(s)) { 91 | ivCleanPhone.setVisibility(View.GONE); 92 | } 93 | } 94 | }); 95 | etPassword.addTextChangedListener(new TextWatcher() { 96 | @Override 97 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 98 | 99 | } 100 | 101 | @Override 102 | public void onTextChanged(CharSequence s, int start, int before, int count) { 103 | 104 | } 105 | 106 | @Override 107 | public void afterTextChanged(Editable s) { 108 | if (!TextUtils.isEmpty(s) && cleanPassword.getVisibility() == View.GONE) { 109 | cleanPassword.setVisibility(View.VISIBLE); 110 | } else if (TextUtils.isEmpty(s)) { 111 | cleanPassword.setVisibility(View.GONE); 112 | } 113 | if (s.toString().isEmpty()) 114 | return; 115 | if (!s.toString().matches("[A-Za-z0-9]+")) { 116 | String temp = s.toString(); 117 | Toast.makeText(getContext(), "请输入数字或字母", Toast.LENGTH_SHORT).show(); 118 | s.delete(temp.length() - 1, temp.length()); 119 | etPassword.setSelection(s.length()); 120 | } 121 | } 122 | }); 123 | btnLogin.setOnClickListener(new View.OnClickListener() { 124 | @Override 125 | public void onClick(View v) { 126 | RxKeyboardTool.hideSoftInput(getActivity()); 127 | LoginDaoUtil loginDaoUtil = new LoginDaoUtil(getContext()); 128 | final String phone = etMobile.getText().toString(); 129 | String password = etPassword.getText().toString(); 130 | if (TextUtils.equals(phone, "")) { 131 | Toast.makeText(getContext(), "请输入用户名", Toast.LENGTH_SHORT).show(); 132 | return; 133 | } 134 | if (TextUtils.equals(password, "")) { 135 | Toast.makeText(getContext(), "请输入密码", Toast.LENGTH_SHORT).show(); 136 | return; 137 | } 138 | List beans = loginDaoUtil.queryAllloginBean(); 139 | LoginBean realBean = null; 140 | for (LoginBean bean : beans) { 141 | if (bean.name.equals(phone) && bean.password.equals(password)) { 142 | realBean = bean; 143 | } 144 | } 145 | rxDialogShapeLoading = new RxDialogShapeLoading(getContext()); 146 | rxDialogShapeLoading.show(); 147 | int delayMillis = (new Random().nextInt(3) + 1) * 1000; 148 | Handler handler = new Handler(); 149 | if (realBean != null) { 150 | handler.postDelayed(new Runnable() { 151 | @Override 152 | public void run() { 153 | rxDialogShapeLoading.dismiss(); 154 | ForgetSureDialog dialog = new ForgetSureDialog(); 155 | Bundle bundle = new Bundle(); 156 | bundle.putString("phone", phone); 157 | dialog.setArguments(bundle); 158 | dialog.setOnDismisslistener(new ForgetSureDialog.DismissListener() { 159 | @Override 160 | public void onDismiss() { 161 | dismiss(); 162 | } 163 | }); 164 | dialog.show(getActivity().getSupportFragmentManager(), "forget_sure"); 165 | } 166 | }, delayMillis); 167 | } else { 168 | handler.postDelayed(new Runnable() { 169 | @Override 170 | public void run() { 171 | rxDialogShapeLoading.dismiss(); 172 | Toast.makeText(getContext(), "账号密码不正确,请重新输入", Toast.LENGTH_SHORT).show(); 173 | } 174 | }, delayMillis); 175 | } 176 | } 177 | }); 178 | } 179 | 180 | @Override 181 | public int setHeight() { 182 | return ScreenUtils.getScreenHeight(); 183 | } 184 | 185 | @Override 186 | public int setAnim() { 187 | return R.style.AnimBottom; 188 | } 189 | 190 | @Override 191 | public int setGravity() { 192 | return Gravity.BOTTOM; 193 | } 194 | 195 | @Override 196 | public int initLayout() { 197 | return R.layout.dialog_register; 198 | } 199 | 200 | @Override 201 | public void onDestroyView() { 202 | super.onDestroyView(); 203 | unbinder.unbind(); 204 | } 205 | 206 | @OnClick({R.id.iv_clean_phone, R.id.clean_password, R.id.iv_show_pwd}) 207 | public void onViewClicked(View view) { 208 | switch (view.getId()) { 209 | case R.id.iv_clean_phone: 210 | etMobile.setText(""); 211 | break; 212 | case R.id.clean_password: 213 | etPassword.setText(""); 214 | break; 215 | case R.id.iv_show_pwd: 216 | if (etPassword.getInputType() != InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) { 217 | etPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); 218 | ivShowPwd.setImageResource(R.drawable.pass_visuable); 219 | } else { 220 | etPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); 221 | ivShowPwd.setImageResource(R.drawable.pass_gone); 222 | } 223 | String pwd = etPassword.getText().toString(); 224 | if (!TextUtils.isEmpty(pwd)) 225 | etPassword.setSelection(pwd.length()); 226 | break; 227 | } 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/dialog/ForgetSureDialog.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.dialog; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.text.Editable; 6 | import android.text.InputType; 7 | import android.text.TextUtils; 8 | import android.text.TextWatcher; 9 | import android.view.Gravity; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.EditText; 14 | import android.widget.ImageView; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | 18 | import com.vondear.rxtools.RxKeyboardTool; 19 | import com.vondear.rxtools.view.dialog.RxDialogShapeLoading; 20 | 21 | import java.util.List; 22 | import java.util.Random; 23 | 24 | import butterknife.BindView; 25 | import butterknife.ButterKnife; 26 | import butterknife.OnClick; 27 | import butterknife.Unbinder; 28 | import top.jplayer.audio.R; 29 | import top.jplayer.audio.bean.LoginBean; 30 | import top.jplayer.audio.utils.LoginDaoUtil; 31 | 32 | /** 33 | * Created by Administrator on 2018/5/5. 34 | */ 35 | 36 | public class ForgetSureDialog extends BaseCustomDialogFragment { 37 | @BindView(R.id.et_password) 38 | EditText etPassword; 39 | @BindView(R.id.clean_password) 40 | ImageView cleanPassword; 41 | @BindView(R.id.iv_show_pwd) 42 | ImageView ivShowPwd; 43 | @BindView(R.id.textView12) 44 | TextView textView12; 45 | @BindView(R.id.tv_sure) 46 | TextView tvSure; 47 | @BindView(R.id.textView10) 48 | TextView textView10; 49 | @BindView(R.id.tv_cancle) 50 | TextView tvCancle; 51 | Unbinder unbinder; 52 | 53 | @Override 54 | protected void initView(View view) { 55 | unbinder = ButterKnife.bind(this, view); 56 | etPassword.addTextChangedListener(new TextWatcher() { 57 | @Override 58 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 59 | 60 | } 61 | 62 | @Override 63 | public void onTextChanged(CharSequence s, int start, int before, int count) { 64 | 65 | } 66 | 67 | @Override 68 | public void afterTextChanged(Editable s) { 69 | if (!TextUtils.isEmpty(s) && cleanPassword.getVisibility() == View.GONE) { 70 | cleanPassword.setVisibility(View.VISIBLE); 71 | } else if (TextUtils.isEmpty(s)) { 72 | cleanPassword.setVisibility(View.GONE); 73 | } 74 | if (s.toString().isEmpty()) 75 | return; 76 | if (!s.toString().matches("[A-Za-z0-9]+")) { 77 | String temp = s.toString(); 78 | Toast.makeText(getContext(), "请输入数字或字母", Toast.LENGTH_SHORT).show(); 79 | s.delete(temp.length() - 1, temp.length()); 80 | etPassword.setSelection(s.length()); 81 | } 82 | } 83 | }); 84 | } 85 | 86 | @Override 87 | public int initLayout() { 88 | return R.layout.dialog_forget_sure; 89 | } 90 | 91 | @Override 92 | public int setGravity() { 93 | return Gravity.CENTER; 94 | } 95 | 96 | @Override 97 | public int setAnim() { 98 | return R.style.AnimCenter; 99 | } 100 | 101 | @Override 102 | public void onDestroyView() { 103 | super.onDestroyView(); 104 | unbinder.unbind(); 105 | } 106 | 107 | DismissListener listener; 108 | private RxDialogShapeLoading rxDialogShapeLoading; 109 | 110 | public void setOnDismisslistener(DismissListener listener) { 111 | this.listener = listener; 112 | } 113 | 114 | public interface DismissListener { 115 | void onDismiss(); 116 | } 117 | 118 | @OnClick({R.id.clean_password, R.id.iv_show_pwd, R.id.tv_sure, R.id.tv_cancle}) 119 | public void onViewClicked(View view) { 120 | switch (view.getId()) { 121 | case R.id.clean_password: 122 | etPassword.setText(""); 123 | break; 124 | case R.id.iv_show_pwd: 125 | if (etPassword.getInputType() != InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) { 126 | etPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); 127 | ivShowPwd.setImageResource(R.drawable.pass_visuable); 128 | } else { 129 | etPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); 130 | ivShowPwd.setImageResource(R.drawable.pass_gone); 131 | } 132 | String pwd = etPassword.getText().toString(); 133 | if (!TextUtils.isEmpty(pwd)) 134 | etPassword.setSelection(pwd.length()); 135 | break; 136 | case R.id.tv_sure: 137 | Bundle bundle = getArguments(); 138 | assert bundle != null; 139 | String phone = bundle.getString("phone"); 140 | String password = etPassword.getText().toString(); 141 | RxKeyboardTool.hideSoftInput(getActivity()); 142 | LoginDaoUtil loginDaoUtil = new LoginDaoUtil(getContext()); 143 | if (TextUtils.equals(password, "")) { 144 | Toast.makeText(getContext(), "请输入要修改的密码", Toast.LENGTH_SHORT).show(); 145 | return; 146 | } 147 | List beans = loginDaoUtil.queryAllloginBean(); 148 | LoginBean realBean = null; 149 | for (LoginBean bean : beans) { 150 | if (bean.name.equals(phone)) { 151 | realBean = bean; 152 | } 153 | } 154 | if (realBean != null) { 155 | realBean.password = password; 156 | loginDaoUtil.updateloginBean(realBean); 157 | rxDialogShapeLoading = new RxDialogShapeLoading(getContext()); 158 | rxDialogShapeLoading.show(); 159 | dismiss(); 160 | int delayMillis = (new Random().nextInt(3) + 1) * 1000; 161 | new Handler().postDelayed(new Runnable() { 162 | @Override 163 | public void run() { 164 | rxDialogShapeLoading.dismiss(); 165 | if (listener != null) { 166 | listener.onDismiss(); 167 | } 168 | } 169 | }, delayMillis); 170 | } 171 | break; 172 | case R.id.tv_cancle: 173 | dismiss(); 174 | break; 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/dialog/RegisterDialogFragment.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.dialog; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.text.Editable; 7 | import android.text.InputType; 8 | import android.text.TextUtils; 9 | import android.text.TextWatcher; 10 | import android.view.Gravity; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.Button; 15 | import android.widget.EditText; 16 | import android.widget.ImageView; 17 | import android.widget.LinearLayout; 18 | import android.widget.RelativeLayout; 19 | import android.widget.ScrollView; 20 | import android.widget.Toast; 21 | 22 | import com.vondear.rxtools.RxBarTool; 23 | import com.vondear.rxtools.RxKeyboardTool; 24 | import com.vondear.rxtools.view.dialog.RxDialogShapeLoading; 25 | 26 | import java.util.List; 27 | import java.util.Random; 28 | 29 | import butterknife.BindView; 30 | import butterknife.ButterKnife; 31 | import butterknife.OnClick; 32 | import butterknife.Unbinder; 33 | import top.jplayer.audio.MainActivity; 34 | import top.jplayer.audio.R; 35 | import top.jplayer.audio.bean.LoginBean; 36 | import top.jplayer.audio.utils.LoginDaoUtil; 37 | import top.jplayer.audio.utils.ScreenUtils; 38 | 39 | /** 40 | * Created by Administrator on 2018/5/5. 41 | * 注册 42 | */ 43 | 44 | public class RegisterDialogFragment extends BaseCustomDialogFragment { 45 | @BindView(R.id.et_mobile) 46 | EditText etMobile; 47 | @BindView(R.id.iv_clean_phone) 48 | ImageView ivCleanPhone; 49 | @BindView(R.id.et_password) 50 | EditText etPassword; 51 | @BindView(R.id.clean_password) 52 | ImageView cleanPassword; 53 | @BindView(R.id.iv_show_pwd) 54 | ImageView ivShowPwd; 55 | @BindView(R.id.btn_login) 56 | Button btnLogin; 57 | Unbinder unbinder; 58 | @BindView(R.id.content) 59 | LinearLayout content; 60 | @BindView(R.id.scrollView) 61 | ScrollView scrollView; 62 | @BindView(R.id.root) 63 | RelativeLayout root; 64 | Unbinder unbinder1; 65 | private RxDialogShapeLoading rxDialogShapeLoading; 66 | 67 | @Override 68 | protected void initView(View view) { 69 | unbinder = ButterKnife.bind(this, view); 70 | RxBarTool.setTransparentStatusBar(getActivity());//状态栏透明化 71 | RxBarTool.StatusBarLightMode(getActivity()); 72 | initEvent(); 73 | } 74 | 75 | private void initEvent() { 76 | etMobile.addTextChangedListener(new TextWatcher() { 77 | @Override 78 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 79 | 80 | } 81 | 82 | @Override 83 | public void onTextChanged(CharSequence s, int start, int before, int count) { 84 | 85 | } 86 | 87 | @Override 88 | public void afterTextChanged(Editable s) { 89 | if (!TextUtils.isEmpty(s) && ivCleanPhone.getVisibility() == View.GONE) { 90 | ivCleanPhone.setVisibility(View.VISIBLE); 91 | } else if (TextUtils.isEmpty(s)) { 92 | ivCleanPhone.setVisibility(View.GONE); 93 | } 94 | } 95 | }); 96 | etPassword.addTextChangedListener(new TextWatcher() { 97 | @Override 98 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 99 | 100 | } 101 | 102 | @Override 103 | public void onTextChanged(CharSequence s, int start, int before, int count) { 104 | 105 | } 106 | 107 | @Override 108 | public void afterTextChanged(Editable s) { 109 | if (!TextUtils.isEmpty(s) && cleanPassword.getVisibility() == View.GONE) { 110 | cleanPassword.setVisibility(View.VISIBLE); 111 | } else if (TextUtils.isEmpty(s)) { 112 | cleanPassword.setVisibility(View.GONE); 113 | } 114 | if (s.toString().isEmpty()) 115 | return; 116 | if (!s.toString().matches("[A-Za-z0-9]+")) { 117 | String temp = s.toString(); 118 | Toast.makeText(getContext(), "请输入数字或字母", Toast.LENGTH_SHORT).show(); 119 | s.delete(temp.length() - 1, temp.length()); 120 | etPassword.setSelection(s.length()); 121 | } 122 | } 123 | }); 124 | btnLogin.setOnClickListener(new View.OnClickListener() { 125 | @Override 126 | public void onClick(View v) { 127 | RxKeyboardTool.hideSoftInput(getActivity()); 128 | LoginDaoUtil loginDaoUtil = new LoginDaoUtil(getContext()); 129 | String phone = etMobile.getText().toString(); 130 | String password = etPassword.getText().toString(); 131 | if (TextUtils.equals(phone, "")) { 132 | Toast.makeText(getContext(), "请输入用户名", Toast.LENGTH_SHORT).show(); 133 | return; 134 | } 135 | if (TextUtils.equals(password, "")) { 136 | Toast.makeText(getContext(), "请输入密码", Toast.LENGTH_SHORT).show(); 137 | return; 138 | } 139 | List beans = loginDaoUtil.queryAllloginBean(); 140 | LoginBean realBean = null; 141 | for (LoginBean bean : beans) { 142 | if (bean.name.equals(phone)) { 143 | realBean = bean; 144 | } 145 | } 146 | rxDialogShapeLoading = new RxDialogShapeLoading(getContext()); 147 | rxDialogShapeLoading.show(); 148 | int delayMillis = (new Random().nextInt(3) + 1) * 1000; 149 | Handler handler = new Handler(); 150 | if (realBean == null) { 151 | loginDaoUtil.insertloginBean(new LoginBean(null, phone, password)); 152 | handler.postDelayed(new Runnable() { 153 | @Override 154 | public void run() { 155 | rxDialogShapeLoading.dismiss(); 156 | RegisterDialogFragment.this.dismiss(); 157 | startActivity(new Intent(getContext(), MainActivity.class)); 158 | } 159 | }, delayMillis); 160 | } else { 161 | handler.postDelayed(new Runnable() { 162 | @Override 163 | public void run() { 164 | rxDialogShapeLoading.dismiss(); 165 | Toast.makeText(getContext(), "账号已存在,请返回登录", Toast.LENGTH_SHORT).show(); 166 | } 167 | }, delayMillis); 168 | } 169 | } 170 | }); 171 | } 172 | 173 | @Override 174 | public int setHeight() { 175 | return ScreenUtils.getScreenHeight(); 176 | } 177 | 178 | @Override 179 | public int setAnim() { 180 | return R.style.AnimBottom; 181 | } 182 | 183 | @Override 184 | public int setGravity() { 185 | return Gravity.BOTTOM; 186 | } 187 | 188 | @Override 189 | public int initLayout() { 190 | return R.layout.dialog_register; 191 | } 192 | 193 | @Override 194 | public void onDestroyView() { 195 | super.onDestroyView(); 196 | unbinder.unbind(); 197 | } 198 | 199 | @OnClick({R.id.iv_clean_phone, R.id.clean_password, R.id.iv_show_pwd}) 200 | public void onViewClicked(View view) { 201 | switch (view.getId()) { 202 | case R.id.iv_clean_phone: 203 | etMobile.setText(""); 204 | break; 205 | case R.id.clean_password: 206 | etPassword.setText(""); 207 | break; 208 | case R.id.iv_show_pwd: 209 | if (etPassword.getInputType() != InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) { 210 | etPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); 211 | ivShowPwd.setImageResource(R.drawable.pass_visuable); 212 | } else { 213 | etPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); 214 | ivShowPwd.setImageResource(R.drawable.pass_gone); 215 | } 216 | String pwd = etPassword.getText().toString(); 217 | if (!TextUtils.isEmpty(pwd)) 218 | etPassword.setSelection(pwd.length()); 219 | break; 220 | } 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/dialog/ValueSureDialog.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.dialog; 2 | 3 | import android.view.View; 4 | import android.widget.EditText; 5 | import android.widget.TextView; 6 | 7 | import butterknife.BindView; 8 | import butterknife.ButterKnife; 9 | import butterknife.OnClick; 10 | import top.jplayer.audio.R; 11 | 12 | /** 13 | * Created by Administrator on 2018/5/5. 14 | * 输入法阀值 15 | */ 16 | 17 | public class ValueSureDialog extends BaseCustomDialogFragment { 18 | 19 | @BindView(R.id.tv_content) 20 | public EditText mTvContent; 21 | @BindView(R.id.tv_sure) 22 | TextView mTvSure; 23 | @BindView(R.id.tv_cancel) 24 | TextView mTvCancel; 25 | public int value = 60; 26 | SureListener listener; 27 | 28 | public interface SureListener { 29 | void onSureListener(int value); 30 | } 31 | 32 | public void setSureListener(SureListener listener) { 33 | this.listener = listener; 34 | } 35 | 36 | @Override 37 | protected void initView(View view) { 38 | ButterKnife.bind(this, view); 39 | 40 | } 41 | 42 | @Override 43 | public int initLayout() { 44 | return R.layout.dialog_value_sure; 45 | } 46 | 47 | 48 | @OnClick({R.id.tv_sure, R.id.tv_cancel}) 49 | public void onClick(View view) { 50 | switch (view.getId()) { 51 | case R.id.tv_sure: 52 | value = Integer.parseInt(mTvContent.getText().toString()); 53 | listener.onSureListener(value); 54 | dismiss(); 55 | break; 56 | case R.id.tv_cancel: 57 | dismiss(); 58 | break; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/utils/AndroidScheduler.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.utils; 2 | 3 | import android.os.Handler; 4 | import android.os.Looper; 5 | import android.support.annotation.NonNull; 6 | 7 | import java.util.concurrent.Executor; 8 | 9 | import io.reactivex.Scheduler; 10 | import io.reactivex.schedulers.Schedulers; 11 | 12 | /** 13 | * Created by Administrator on 2018/5/6. 14 | * diaoduqi 15 | */ 16 | 17 | public class AndroidScheduler implements Executor { 18 | private static AndroidScheduler instance; 19 | 20 | private final Scheduler mMainScheduler; 21 | private final Handler mHandler; 22 | 23 | private AndroidScheduler() { 24 | mHandler = new Handler(Looper.myLooper()); 25 | mMainScheduler = Schedulers.from(this); 26 | } 27 | 28 | public static synchronized Scheduler mainThread() { 29 | if (instance == null) { 30 | instance = new AndroidScheduler(); 31 | } 32 | return instance.mMainScheduler; 33 | } 34 | 35 | @Override 36 | public void execute(@NonNull Runnable command) { 37 | mHandler.post(command); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/utils/ColorUtil.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.utils; 2 | 3 | import android.graphics.Color; 4 | 5 | import java.util.Random; 6 | 7 | public class ColorUtil { 8 | /** 9 | * 随机生成漂亮的颜色 10 | * @return 11 | */ 12 | public static int randomColor() { 13 | Random random = new Random(); 14 | 15 | int red = random.nextInt(150) + 50; 16 | 17 | int green = random.nextInt(150) + 50; 18 | 19 | int blue = random.nextInt(150) + 50; 20 | 21 | return Color.rgb(red, green, blue); // 根据rgb混合生成一种新的颜色 22 | } 23 | 24 | /** 25 | * 随机生成漂亮的颜色,带透明度的 26 | * @return 27 | */ 28 | public static int randomColorArgb() { 29 | Random random = new Random(); 30 | 31 | int alpha = random.nextInt(70) + 30; 32 | 33 | int red = random.nextInt(150) + 50; 34 | 35 | int green = random.nextInt(150) + 50; 36 | 37 | int blue = random.nextInt(150) + 50; 38 | 39 | return Color.argb(alpha, red, green, blue); // 根据argb混合生成一种新的颜色 40 | } 41 | 42 | 43 | /** 44 | * 颜色与上一个十六进制数ARGB,得到一个颜色加深的效果,效果从 0-F 深 45 | * @param color 46 | * @return 47 | */ 48 | public static int getColorDeeply(int color) { 49 | // | 0xF0000000 & 0xFFF5F5F5 50 | return color & 0xFFDDDDDD; 51 | } 52 | 53 | 54 | /** 55 | * 颜色值取反 56 | * @param color 57 | * @return 58 | */ 59 | public static int getColorReverse(int color) { 60 | // String string = String.format("#%x", color); // string reverse 61 | int red = 255 - Color.red(color); 62 | int green = 255 - Color.green(color); 63 | int blue = 255 - Color.blue(color); 64 | return Color.argb(255, red, green, blue); 65 | } 66 | 67 | /** 68 | * 获取两个颜色值之间渐变的某个点的颜色值 69 | * @param resSColor 70 | * @param resEColor 71 | * @param rangeColorRate 72 | * @return 73 | */ 74 | public static int getCompositeColor(int resSColor, int resEColor, float rangeColorRate) { 75 | int sc = resSColor; 76 | int ec = resEColor; 77 | int rS = Color.red(sc); 78 | int gS = Color.green(sc); 79 | int bS = Color.blue(sc); 80 | int rE = Color.red(ec); 81 | int gE = Color.green(ec); 82 | int bE = Color.blue(ec); 83 | int r = (int) (rS + (rE - rS) * 1f * rangeColorRate); 84 | int g = (int) (gS + (gE - gS) * 1f * rangeColorRate); 85 | int b = (int) (bS + (bE - bS) * 1f * rangeColorRate); 86 | return Color.argb(255, r, g, b); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/utils/DaoManager.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.utils; 2 | 3 | import android.content.Context; 4 | 5 | import com.ping.greendao.gen.DaoMaster; 6 | import com.ping.greendao.gen.DaoSession; 7 | 8 | import org.greenrobot.greendao.query.QueryBuilder; 9 | 10 | /** 11 | * Created by Administrator on 2018/5/5. 12 | * 数据库管理器 13 | */ 14 | 15 | public class DaoManager { 16 | private static final String TAG = DaoManager.class.getSimpleName(); 17 | private static final String DB_NAME = "greendaotest"; 18 | 19 | private Context context; 20 | 21 | //多线程中要被共享的使用volatile关键字修饰 22 | private volatile static DaoManager manager = new DaoManager(); 23 | private static DaoMaster sDaoMaster; 24 | private static DaoMaster.DevOpenHelper sHelper; 25 | private static DaoSession sDaoSession; 26 | 27 | /** 28 | * 单例模式获得操作数据库对象 29 | * 30 | * @return 31 | */ 32 | public static DaoManager getInstance() { 33 | return manager; 34 | } 35 | 36 | public void init(Context context) { 37 | this.context = context; 38 | } 39 | 40 | /** 41 | * 判断是否有存在数据库,如果没有则创建 42 | * 43 | * @return 44 | */ 45 | public DaoMaster getDaoMaster() { 46 | if (sDaoMaster == null) { 47 | DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, DB_NAME, null); 48 | sDaoMaster = new DaoMaster(helper.getWritableDatabase()); 49 | } 50 | return sDaoMaster; 51 | } 52 | 53 | /** 54 | * 完成对数据库的添加、删除、修改、查询操作,仅仅是一个接口 55 | * 56 | * @return 57 | */ 58 | public DaoSession getDaoSession() { 59 | if (sDaoSession == null) { 60 | if (sDaoMaster == null) { 61 | sDaoMaster = getDaoMaster(); 62 | } 63 | sDaoSession = sDaoMaster.newSession(); 64 | } 65 | return sDaoSession; 66 | } 67 | 68 | /** 69 | * 打开输出日志,默认关闭 70 | */ 71 | public void setDebug() { 72 | QueryBuilder.LOG_SQL = true; 73 | QueryBuilder.LOG_VALUES = true; 74 | } 75 | 76 | /** 77 | * 关闭所有的操作,数据库开启后,使用完毕要关闭 78 | */ 79 | public void closeConnection() { 80 | closeHelper(); 81 | closeDaoSession(); 82 | } 83 | 84 | public void closeHelper() { 85 | if (sHelper != null) { 86 | sHelper.close(); 87 | sHelper = null; 88 | } 89 | } 90 | 91 | public void closeDaoSession() { 92 | if (sDaoSession != null) { 93 | sDaoSession.clear(); 94 | sDaoSession = null; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/utils/FontMatrixUtils.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.utils; 2 | 3 | import android.graphics.Paint; 4 | 5 | /** 6 | * @author dyzs 7 | * Created on 2016/3/24. 8 | */ 9 | public class FontMatrixUtils { 10 | private FontMatrixUtils() { 11 | throw new UnsupportedOperationException("font matrix can't be initialized"); 12 | } 13 | /** 14 | * @details 准确的计算画笔绘制文字的Y轴的正确坐标,这个坐标计算的基础为 paint X = 0,y = 0 15 | * @param paint 16 | * @return 17 | */ 18 | public static float calcTextCenterVerticalBaselineY(Paint paint) { 19 | Paint.FontMetrics fm = paint.getFontMetrics(); 20 | float ret = paint.getTextSize() / 2 - fm.descent 21 | + (fm.bottom - fm.top) / 2; 22 | return ret; 23 | } 24 | 25 | public static float calcTextHalfHeightPoint (Paint paint) { 26 | Paint.FontMetrics fm = paint.getFontMetrics(); 27 | float ret = (fm.bottom - fm.top) / 2; 28 | return ret; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/utils/LoginDaoUtil.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.utils; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import com.ping.greendao.gen.LoginBeanDao; 7 | 8 | import org.greenrobot.greendao.query.QueryBuilder; 9 | 10 | import java.util.List; 11 | 12 | import top.jplayer.audio.bean.LoginBean; 13 | 14 | /** 15 | * Created by Administrator on 2018/5/5. 16 | * 注册工具类 17 | */ 18 | 19 | public class LoginDaoUtil { 20 | private static final String TAG = LoginDaoUtil.class.getSimpleName(); 21 | private DaoManager mManager; 22 | 23 | public LoginDaoUtil(Context context){ 24 | mManager = DaoManager.getInstance(); 25 | mManager.init(context); 26 | } 27 | 28 | /** 29 | * 完成loginBean记录的插入,如果表未创建,先创建loginBean表 30 | * @param loginBean 31 | * @return 32 | */ 33 | public boolean insertloginBean(LoginBean loginBean){ 34 | boolean flag = false; 35 | flag = mManager.getDaoSession().getLoginBeanDao().insert(loginBean) != -1; 36 | Log.i(TAG, "insert LoginBean :" + flag + "-->" + loginBean.toString()); 37 | return flag; 38 | } 39 | 40 | /** 41 | * 插入多条数据,在子线程操作 42 | * @param loginBeanList 43 | * @return 44 | */ 45 | public boolean insertMultloginBean(final List loginBeanList) { 46 | boolean flag = false; 47 | try { 48 | mManager.getDaoSession().runInTx(new Runnable() { 49 | @Override 50 | public void run() { 51 | for (LoginBean loginBean : loginBeanList) { 52 | mManager.getDaoSession().insertOrReplace(loginBean); 53 | } 54 | } 55 | }); 56 | flag = true; 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | return flag; 61 | } 62 | 63 | /** 64 | * 修改一条数据 65 | * @param loginBean 66 | * @return 67 | */ 68 | public boolean updateloginBean(LoginBean loginBean){ 69 | boolean flag = false; 70 | try { 71 | mManager.getDaoSession().update(loginBean); 72 | flag = true; 73 | }catch (Exception e){ 74 | e.printStackTrace(); 75 | } 76 | return flag; 77 | } 78 | 79 | /** 80 | * 删除单条记录 81 | * @param loginBean 82 | * @return 83 | */ 84 | public boolean deleteloginBean(LoginBean loginBean){ 85 | boolean flag = false; 86 | try { 87 | //按照id删除 88 | mManager.getDaoSession().delete(loginBean); 89 | flag = true; 90 | }catch (Exception e){ 91 | e.printStackTrace(); 92 | } 93 | return flag; 94 | } 95 | 96 | /** 97 | * 删除所有记录 98 | * @return 99 | */ 100 | public boolean deleteAll(){ 101 | boolean flag = false; 102 | try { 103 | //按照id删除 104 | mManager.getDaoSession().deleteAll(LoginBean.class); 105 | flag = true; 106 | }catch (Exception e){ 107 | e.printStackTrace(); 108 | } 109 | return flag; 110 | } 111 | 112 | /** 113 | * 查询所有记录 114 | * @return 115 | */ 116 | public List queryAllloginBean(){ 117 | return mManager.getDaoSession().loadAll(LoginBean.class); 118 | } 119 | 120 | /** 121 | * 根据主键id查询记录 122 | * @param key 123 | * @return 124 | */ 125 | public LoginBean queryloginBeanById(long key){ 126 | return mManager.getDaoSession().load(LoginBean.class, key); 127 | } 128 | 129 | /** 130 | * 使用native sql进行查询操作 131 | */ 132 | public List queryloginBeanByNativeSql(String sql, String[] conditions){ 133 | return mManager.getDaoSession().queryRaw(LoginBean.class, sql, conditions); 134 | } 135 | 136 | /** 137 | * 使用queryBuilder进行查询 138 | * @return 139 | */ 140 | public List queryloginBeanByQueryBuilder(long id){ 141 | QueryBuilder queryBuilder = mManager.getDaoSession().queryBuilder(LoginBean.class); 142 | return queryBuilder.where(LoginBeanDao.Properties._id.eq(id)).list(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/utils/RecordDaoUtil.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.utils; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import com.ping.greendao.gen.RecordSleepBeanDao; 7 | 8 | import org.greenrobot.greendao.query.QueryBuilder; 9 | 10 | import java.util.List; 11 | 12 | import top.jplayer.audio.bean.RecordSleepBean; 13 | 14 | /** 15 | * Created by Administrator on 2018/5/5. 16 | * 注册工具类 17 | */ 18 | 19 | public class RecordDaoUtil { 20 | private static final String TAG = RecordDaoUtil.class.getSimpleName(); 21 | private DaoManager mManager; 22 | 23 | public RecordDaoUtil(Context context){ 24 | mManager = DaoManager.getInstance(); 25 | mManager.init(context); 26 | } 27 | 28 | /** 29 | * 完成bean记录的插入,如果表未创建,先创建bean表 30 | * @param bean 31 | * @return 32 | */ 33 | public boolean insertbean(RecordSleepBean bean){ 34 | boolean flag = false; 35 | flag = mManager.getDaoSession().getRecordSleepBeanDao().insert(bean) != -1; 36 | Log.i(TAG, "insert LoginBean :" + flag + "-->" + bean.toString()); 37 | return flag; 38 | } 39 | 40 | /** 41 | * 插入多条数据,在子线程操作 42 | * @param beanList 43 | * @return 44 | */ 45 | public boolean insertMultbean(final List beanList) { 46 | boolean flag = false; 47 | try { 48 | mManager.getDaoSession().runInTx(new Runnable() { 49 | @Override 50 | public void run() { 51 | for (RecordSleepBean bean : beanList) { 52 | mManager.getDaoSession().insertOrReplace(bean); 53 | } 54 | } 55 | }); 56 | flag = true; 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | return flag; 61 | } 62 | 63 | /** 64 | * 修改一条数据 65 | * @param bean 66 | * @return 67 | */ 68 | public boolean updatebean(RecordSleepBean bean){ 69 | boolean flag = false; 70 | try { 71 | mManager.getDaoSession().update(bean); 72 | flag = true; 73 | }catch (Exception e){ 74 | e.printStackTrace(); 75 | } 76 | return flag; 77 | } 78 | 79 | /** 80 | * 删除单条记录 81 | * @param bean 82 | * @return 83 | */ 84 | public boolean deletebean(RecordSleepBean bean){ 85 | boolean flag = false; 86 | try { 87 | //按照id删除 88 | mManager.getDaoSession().delete(bean); 89 | flag = true; 90 | }catch (Exception e){ 91 | e.printStackTrace(); 92 | } 93 | return flag; 94 | } 95 | 96 | /** 97 | * 删除所有记录 98 | * @return 99 | */ 100 | public boolean deleteAll(){ 101 | boolean flag = false; 102 | try { 103 | //按照id删除 104 | mManager.getDaoSession().deleteAll(RecordSleepBean.class); 105 | flag = true; 106 | }catch (Exception e){ 107 | e.printStackTrace(); 108 | } 109 | return flag; 110 | } 111 | 112 | /** 113 | * 查询所有记录 114 | * @return 115 | */ 116 | public List queryAllbean(){ 117 | return mManager.getDaoSession().loadAll(RecordSleepBean.class); 118 | } 119 | 120 | /** 121 | * 根据主键id查询记录 122 | * @param key 123 | * @return 124 | */ 125 | public RecordSleepBean querybeanById(long key){ 126 | return mManager.getDaoSession().load(RecordSleepBean.class, key); 127 | } 128 | 129 | /** 130 | * 使用native sql进行查询操作 131 | */ 132 | public List querybeanByNativeSql(String sql, String[] conditions){ 133 | return mManager.getDaoSession().queryRaw(RecordSleepBean.class, sql, conditions); 134 | } 135 | 136 | /** 137 | * 使用queryBuilder进行查询 138 | * @return 139 | */ 140 | public List querybeanByQueryBuilder(long id){ 141 | QueryBuilder queryBuilder = mManager.getDaoSession().queryBuilder(RecordSleepBean.class); 142 | return queryBuilder.where(RecordSleepBeanDao.Properties._id.eq(id)).list(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /app/src/main/java/top/jplayer/audio/utils/SizeUtils.java: -------------------------------------------------------------------------------- 1 | package top.jplayer.audio.utils; 2 | 3 | import android.util.DisplayMetrics; 4 | import android.util.TypedValue; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import top.jplayer.audio.AudioApplication; 9 | 10 | /** 11 | *
 12 |  *     author: Blankj
 13 |  *     blog  : http://blankj.com
 14 |  *     time  : 2016/08/02
 15 |  *     desc  : 尺寸相关工具类
 16 |  * 
17 | */ 18 | public final class SizeUtils { 19 | 20 | private SizeUtils() { 21 | throw new UnsupportedOperationException("u can't instantiate me..."); 22 | } 23 | 24 | /** 25 | * dp 转 px 26 | * 27 | * @param dpValue dp 值 28 | * @return px 值 29 | */ 30 | public static int dp2px(final float dpValue) { 31 | final float scale = AudioApplication.application.getResources().getDisplayMetrics().density; 32 | return (int) (dpValue * scale + 0.5f); 33 | } 34 | 35 | /** 36 | * px 转 dp 37 | * 38 | * @param pxValue px 值 39 | * @return dp 值 40 | */ 41 | public static int px2dp(final float pxValue) { 42 | final float scale = AudioApplication.application.getResources().getDisplayMetrics().density; 43 | return (int) (pxValue / scale + 0.5f); 44 | } 45 | 46 | /** 47 | * sp 转 px 48 | * 49 | * @param spValue sp 值 50 | * @return px 值 51 | */ 52 | public static int sp2px(final float spValue) { 53 | final float fontScale = AudioApplication.application.getResources().getDisplayMetrics().scaledDensity; 54 | return (int) (spValue * fontScale + 0.5f); 55 | } 56 | 57 | /** 58 | * px 转 sp 59 | * 60 | * @param pxValue px 值 61 | * @return sp 值 62 | */ 63 | public static int px2sp(final float pxValue) { 64 | final float fontScale = AudioApplication.application.getResources().getDisplayMetrics().scaledDensity; 65 | return (int) (pxValue / fontScale + 0.5f); 66 | } 67 | 68 | /** 69 | * 各种单位转换 70 | *

该方法存在于 TypedValue

71 | * 72 | * @param unit 单位 73 | * @param value 值 74 | * @param metrics DisplayMetrics 75 | * @return 转换结果 76 | */ 77 | public static float applyDimension(final int unit, 78 | final float value, 79 | final DisplayMetrics metrics) { 80 | switch (unit) { 81 | case TypedValue.COMPLEX_UNIT_PX: 82 | return value; 83 | case TypedValue.COMPLEX_UNIT_DIP: 84 | return value * metrics.density; 85 | case TypedValue.COMPLEX_UNIT_SP: 86 | return value * metrics.scaledDensity; 87 | case TypedValue.COMPLEX_UNIT_PT: 88 | return value * metrics.xdpi * (1.0f / 72); 89 | case TypedValue.COMPLEX_UNIT_IN: 90 | return value * metrics.xdpi; 91 | case TypedValue.COMPLEX_UNIT_MM: 92 | return value * metrics.xdpi * (1.0f / 25.4f); 93 | } 94 | return 0; 95 | } 96 | 97 | /** 98 | * 在 onCreate 中获取视图的尺寸 99 | *

需回调 onGetSizeListener 接口,在 onGetSize 中获取 view 宽高

100 | *

用法示例如下所示

101 | *
102 |      * SizeUtils.forceGetViewSize(view, new SizeUtils.onGetSizeListener() {
103 |      *     Override
104 |      *     public void onGetSize(final View view) {
105 |      *         view.getWidth();
106 |      *     }
107 |      * });
108 |      * 
109 | * 110 | * @param view 视图 111 | * @param listener 监听器 112 | */ 113 | public static void forceGetViewSize(final View view, final onGetSizeListener listener) { 114 | view.post(new Runnable() { 115 | @Override 116 | public void run() { 117 | if (listener != null) { 118 | listener.onGetSize(view); 119 | } 120 | } 121 | }); 122 | } 123 | 124 | /** 125 | * 获取到 View 尺寸的监听 126 | */ 127 | public interface onGetSizeListener { 128 | void onGetSize(View view); 129 | } 130 | 131 | /** 132 | * 测量视图尺寸 133 | * 134 | * @param view 视图 135 | * @return arr[0]: 视图宽度, arr[1]: 视图高度 136 | */ 137 | public static int[] measureView(final View view) { 138 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 139 | if (lp == null) { 140 | lp = new ViewGroup.LayoutParams( 141 | ViewGroup.LayoutParams.MATCH_PARENT, 142 | ViewGroup.LayoutParams.WRAP_CONTENT 143 | ); 144 | } 145 | int widthSpec = ViewGroup.getChildMeasureSpec(0, 0, lp.width); 146 | int lpHeight = lp.height; 147 | int heightSpec; 148 | if (lpHeight > 0) { 149 | heightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY); 150 | } else { 151 | heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 152 | } 153 | view.measure(widthSpec, heightSpec); 154 | return new int[]{view.getMeasuredWidth(), view.getMeasuredHeight()}; 155 | } 156 | 157 | /** 158 | * 获取测量视图宽度 159 | * 160 | * @param view 视图 161 | * @return 视图宽度 162 | */ 163 | public static int getMeasuredWidth(final View view) { 164 | return measureView(view)[0]; 165 | } 166 | 167 | /** 168 | * 获取测量视图高度 169 | * 170 | * @param view 视图 171 | * @return 视图高度 172 | */ 173 | public static int getMeasuredHeight(final View view) { 174 | return measureView(view)[1]; 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /app/src/main/res/anim/fade_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/anim/fade_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 26 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_center.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 26 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | 23 | 27 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 26 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_center.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 26 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 26 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_btn_login_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 11 | 16 | 21 | 26 | 31 | 36 | 41 | 46 | 51 | 56 | 61 | 66 | 71 | 76 | 81 | 86 | 91 | 96 | 101 | 106 | 111 | 116 | 121 | 126 | 131 | 136 | 141 | 146 | 151 | 156 | 161 | 166 | 171 | 172 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login_act.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 21 | 22 | 34 | 35 | 40 | 41 | 48 | 49 | 54 | 55 | 69 | 70 | 77 | 78 | 79 | 83 | 84 | 90 | 91 | 96 | 97 | 111 | 112 | 119 | 120 | 126 | 127 | 128 | 132 | 133 |