├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── array.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_add.png │ │ │ │ ├── ic_back.png │ │ │ │ ├── ic_sure.png │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_type_tag.png │ │ │ │ ├── ic_note_type.png │ │ │ │ ├── ic_drawer_home.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_launcher_round.png │ │ │ │ └── ic_launcher_foreground.png │ │ │ ├── drawable │ │ │ │ ├── ripple_type.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ └── layout │ │ │ │ ├── item_note_type.xml │ │ │ │ ├── item_note.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── activity_note.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── leiyun │ │ │ │ └── easynote │ │ │ │ ├── model │ │ │ │ └── Note.kt │ │ │ │ ├── App.kt │ │ │ │ ├── utils │ │ │ │ ├── SoftInputUtil.kt │ │ │ │ └── DateUtil.kt │ │ │ │ ├── base │ │ │ │ └── BaseActivity.kt │ │ │ │ ├── adapter │ │ │ │ └── NotesAdapter.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ └── ui │ │ │ │ └── NoteActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── leiyun │ │ │ └── easynote │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── leiyun │ │ └── easynote │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro ├── objectbox-models │ ├── default.json.bak │ └── default.json └── build.gradle ├── settings.gradle ├── images ├── 01.jpg ├── 02.jpg ├── 03.jpg ├── 04.jpg └── 05.jpg ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/images/01.jpg -------------------------------------------------------------------------------- /images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/images/02.jpg -------------------------------------------------------------------------------- /images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/images/03.jpg -------------------------------------------------------------------------------- /images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/images/04.jpg -------------------------------------------------------------------------------- /images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/images/05.jpg -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | EasyNote 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xhdpi/ic_add.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xhdpi/ic_back.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_sure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xhdpi/ic_sure.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_type_tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xhdpi/ic_type_tag.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_note_type.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xhdpi/ic_note_type.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20dp 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_drawer_home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xhdpi/ic_drawer_home.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyun-studio/EasyNote/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ripple_type.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/array.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 旅游 5 | 个人 6 | 生活 7 | 工作 8 | 未标签 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/test/java/com/leiyun/easynote/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/leiyun/easynote/model/Note.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote.model 2 | 3 | import io.objectbox.annotation.Entity 4 | import io.objectbox.annotation.Id 5 | import java.util.* 6 | 7 | /** 8 | * 类名:Note 9 | * 作者:Yun.Lei 10 | * 功能: 11 | * 创建日期:2017-08-03 10:58 12 | * 修改人: 13 | * 修改时间: 14 | * 修改备注: 15 | */ 16 | @Entity 17 | data class Note( 18 | @Id var id: Long = 0, 19 | var type: String? = null, 20 | var content: String? = null, 21 | var date: Date? = null 22 | ) -------------------------------------------------------------------------------- /app/src/androidTest/java/com/leiyun/easynote/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.leiyun.easynote", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #1296db 6 | #FF0000 7 | #FFFFFF 8 | #FFD700 9 | #00BFFF 10 | #00FF7F 11 | #ff4400 12 | #ff6c38 13 | #e5e5e5 14 | #333333 15 | #4d4d4d 16 | #666666 17 | #999999 18 | #00000000 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/leiyun/easynote/App.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote 2 | 3 | import android.app.Application 4 | import com.leiyun.easynote.model.MyObjectBox 5 | import io.objectbox.BoxStore 6 | 7 | /** 8 | * 类名:App 9 | * 作者:Yun.Lei 10 | * 功能: 11 | * 创建日期:2017-08-03 10:35 12 | * 修改人: 13 | * 修改时间: 14 | * 修改备注: 15 | */ 16 | class App : Application() { 17 | 18 | lateinit var boxStore: BoxStore 19 | private set 20 | 21 | val colorArr = intArrayOf(R.color.colorGold, 22 | R.color.colorSkyBlue, 23 | R.color.colorSpringGreen, 24 | R.color.colorCrimson, 25 | R.color.colorOrange) 26 | 27 | override fun onCreate() { 28 | super.onCreate() 29 | instance = this 30 | boxStore = MyObjectBox.builder().androidContext(this).build() 31 | } 32 | 33 | companion object { 34 | lateinit var instance: App 35 | private set 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/leiyun/easynote/utils/SoftInputUtil.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote.utils 2 | 3 | import android.app.Activity 4 | import android.content.Context 5 | import android.view.View 6 | import android.view.inputmethod.InputMethodManager 7 | 8 | /** 9 | * 类名:SoftInputUtil 10 | * 作者:Yun.Lei 11 | * 功能: 12 | * 创建日期:2017-08-03 17:38 13 | * 修改人: 14 | * 修改时间: 15 | * 修改备注: 16 | */ 17 | class SoftInputUtil { 18 | companion object { 19 | fun showSoftInput(activity: Activity) { 20 | val softInputManager: InputMethodManager = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager 21 | softInputManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS) 22 | } 23 | 24 | fun hideSoftInput(activity: Activity, view: View) { 25 | val softInputManager: InputMethodManager = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager 26 | if (softInputManager.isActive) { 27 | softInputManager.hideSoftInputFromWindow(view.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /app/objectbox-models/default.json.bak: -------------------------------------------------------------------------------- 1 | { 2 | "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", 3 | "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", 4 | "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", 5 | "entities": [ 6 | { 7 | "id": "1:2080087761558428936", 8 | "lastPropertyId": "4:6319221952719110310", 9 | "name": "Note", 10 | "properties": [ 11 | { 12 | "id": "1:4957720321640557431", 13 | "name": "id" 14 | }, 15 | { 16 | "id": "2:150636222616832672", 17 | "name": "text" 18 | }, 19 | { 20 | "id": "3:3837759228157602935", 21 | "name": "comment" 22 | }, 23 | { 24 | "id": "4:6319221952719110310", 25 | "name": "date" 26 | } 27 | ] 28 | } 29 | ], 30 | "lastEntityId": "1:2080087761558428936", 31 | "lastIndexId": "0:0", 32 | "lastSequenceId": "0:0", 33 | "modelVersion": 2, 34 | "retiredEntityUids": [], 35 | "retiredIndexUids": [], 36 | "retiredPropertyUids": [], 37 | "version": 1 38 | } -------------------------------------------------------------------------------- /app/objectbox-models/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", 3 | "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", 4 | "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", 5 | "entities": [ 6 | { 7 | "id": "1:2080087761558428936", 8 | "lastPropertyId": "6:6484737807232750001", 9 | "name": "Note", 10 | "properties": [ 11 | { 12 | "id": "1:4957720321640557431", 13 | "name": "id" 14 | }, 15 | { 16 | "id": "4:6319221952719110310", 17 | "name": "date" 18 | }, 19 | { 20 | "id": "5:8935639062428984753", 21 | "name": "type" 22 | }, 23 | { 24 | "id": "6:6484737807232750001", 25 | "name": "content" 26 | } 27 | ] 28 | } 29 | ], 30 | "lastEntityId": "1:2080087761558428936", 31 | "lastIndexId": "0:0", 32 | "lastSequenceId": "0:0", 33 | "modelVersion": 2, 34 | "retiredEntityUids": [], 35 | "retiredIndexUids": [], 36 | "retiredPropertyUids": [ 37 | 150636222616832672, 38 | 3837759228157602935 39 | ], 40 | "version": 1 41 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/item_note_type.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 29 | 30 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/leiyun/easynote/utils/DateUtil.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote.utils 2 | 3 | import java.text.DateFormat 4 | import java.text.SimpleDateFormat 5 | import java.util.* 6 | 7 | /** 8 | * 类名:DateUtil 9 | * 作者:Yun.Lei 10 | * 功能: 11 | * 创建日期:2017-08-02 17:45 12 | * 修改人: 13 | * 修改时间: 14 | * 修改备注: 15 | */ 16 | class DateUtil { 17 | companion object { 18 | 19 | fun getDate(): Date = Calendar.getInstance().time 20 | 21 | fun getNowTimeFriendly(): String { 22 | val calendar: Calendar = Calendar.getInstance() 23 | val hourOfDay = calendar.get(Calendar.HOUR_OF_DAY) 24 | val friendlyHint = getFriendlyHint(hourOfDay) 25 | val format1 = SimpleDateFormat("yyyy年MM月dd日 ", Locale.CHINA) 26 | val format2 = SimpleDateFormat("H:mm", Locale.CHINA) 27 | return format1.format(calendar.time) + friendlyHint + format2.format(calendar.time) 28 | } 29 | 30 | fun getFriendlyTimeOfDate(date: Date): String { 31 | val calendar: Calendar = Calendar.getInstance() 32 | calendar.time = date 33 | val hourOfDay = calendar.get(Calendar.HOUR_OF_DAY) 34 | val friendlyHint = getFriendlyHint(hourOfDay) 35 | val format1 = SimpleDateFormat("yyyy年MM月dd日 ", Locale.CHINA) 36 | val format2 = SimpleDateFormat("H:mm", Locale.CHINA) 37 | return format1.format(calendar.time) + friendlyHint + format2.format(calendar.time) 38 | } 39 | 40 | fun getFriendlyHint(hourOfDay: Int): String = when (hourOfDay) { 41 | in 7..8 -> "清晨" 42 | in 9..11 -> "上午" 43 | in 12..13 -> "中午" 44 | in 14..16 -> "下午" 45 | in 17..19 -> "傍晚" 46 | in 19..21 -> "晚上" 47 | else -> { 48 | "深夜" 49 | } 50 | } 51 | 52 | fun getDateFormat(format: String): DateFormat = SimpleDateFormat(format, Locale.CHINA) 53 | } 54 | } -------------------------------------------------------------------------------- /app/src/main/java/com/leiyun/easynote/base/BaseActivity.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote.base 2 | 3 | import android.app.Activity 4 | import android.graphics.Color 5 | import android.os.Build.VERSION 6 | import android.os.Build.VERSION_CODES 7 | import android.os.Bundle 8 | import android.support.design.widget.Snackbar 9 | import android.support.v7.app.AppCompatActivity 10 | import android.view.View 11 | import android.view.Window 12 | import android.view.WindowManager 13 | import com.jaeger.library.StatusBarUtil 14 | import org.jetbrains.anko.toast 15 | 16 | 17 | /** 18 | * 类名:BaseActivity 19 | * 作者:Yun.Lei 20 | * 功能: 21 | * 创建日期:2017-08-02 9:57 22 | * 修改人: 23 | * 修改时间: 24 | * 修改备注: 25 | */ 26 | 27 | fun Activity.showTips(view: View?, msg: String) { 28 | if (view != null) { 29 | Snackbar.make(view, msg, Snackbar.LENGTH_SHORT).show() 30 | } else { 31 | toast(msg) 32 | } 33 | } 34 | 35 | abstract class BaseActivity : AppCompatActivity() { 36 | override fun onCreate(savedInstanceState: Bundle?) { 37 | super.onCreate(savedInstanceState) 38 | window.requestFeature(Window.FEATURE_NO_TITLE) 39 | if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { 40 | val window = window 41 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) 42 | window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE 43 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) 44 | window.statusBarColor = Color.TRANSPARENT 45 | window.navigationBarColor = Color.TRANSPARENT 46 | } 47 | setContentView(getContentLayout()) 48 | setStatusBar() 49 | initData() 50 | } 51 | 52 | abstract fun getContentLayout(): Int 53 | 54 | abstract fun initData() 55 | 56 | open fun setStatusBar() { 57 | StatusBarUtil.setColor(this, Color.WHITE, 50) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_note.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 22 | 23 | 34 | 35 | 36 | 45 | 46 | 53 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | apply plugin: 'kotlin-kapt' 8 | 9 | apply plugin: 'io.objectbox' 10 | 11 | /*uploadArchives.enabled = false 12 | 13 | // Until the ObjectBox Gradle plugin has better support for Kotlin, we must help it a bit: 14 | //task('compileKotlin').dependsOn objectbox 15 | android.sourceSets.main.java.srcDirs += 'build/generated/source/objectbox'*/ 16 | 17 | android { 18 | compileSdkVersion 26 19 | buildToolsVersion "26.0.2" 20 | defaultConfig { 21 | applicationId "com.leiyun.easynote" 22 | minSdkVersion 21 23 | targetSdkVersion 26 24 | versionCode 1 25 | versionName "1.0.1" 26 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 27 | } 28 | buildTypes { 29 | release { 30 | minifyEnabled false 31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 32 | } 33 | } 34 | 35 | sourceSets { 36 | main.java.srcDirs += 'src/main/kotlin' 37 | } 38 | } 39 | 40 | dependencies { 41 | implementation fileTree(dir: 'libs', include: ['*.jar']) 42 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 43 | compile('org.jetbrains.anko:anko:0.10.0') { 44 | exclude group: 'com.google.android', module: 'android' 45 | } 46 | compile "io.objectbox:objectbox-android:$objectBoxVersion" 47 | compile "io.objectbox:objectbox-kotlin:$objectBoxVersion" 48 | kapt "io.objectbox:objectbox-processor:$objectBoxVersion" 49 | implementation 'com.android.support:appcompat-v7:26.0.0' 50 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 51 | implementation 'com.android.support:design:26.0.0' 52 | implementation 'com.android.support:support-v4:26.0.0' 53 | implementation 'com.jaeger.statusbarutil:library:1.4.0' 54 | testImplementation 'junit:junit:4.12' 55 | androidTestImplementation 'com.android.support.test:runner:0.5' 56 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.0' 57 | } 58 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 17 | 18 | 21 | 22 | 28 | 29 | 34 | 35 | 36 | 41 | 42 | 52 | 53 | 54 | 55 | 62 | 63 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/leiyun/easynote/adapter/NotesAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote.adapter 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.ImageView 8 | import android.widget.TextView 9 | import com.leiyun.easynote.App 10 | import com.leiyun.easynote.R 11 | import com.leiyun.easynote.model.Note 12 | import com.leiyun.easynote.utils.DateUtil 13 | 14 | /** 15 | * 类名:NotesAdapter 16 | * 作者:Yun.Lei 17 | * 功能: 18 | * 创建日期:2017-08-03 14:59 19 | * 修改人: 20 | * 修改时间: 21 | * 修改备注: 22 | */ 23 | class NotesAdapter : RecyclerView.Adapter() { 24 | 25 | private var dataset: List = ArrayList() 26 | private var onItemClickListener: OnItemClickListener? = null 27 | 28 | fun setData(datas: List) { 29 | dataset = datas 30 | notifyDataSetChanged() 31 | } 32 | 33 | fun setOnItemClickListener(onItemClickListener: OnItemClickListener) { 34 | this.onItemClickListener = onItemClickListener 35 | } 36 | 37 | override fun onBindViewHolder(holder: ViewHolder?, position: Int) { 38 | holder!!.itemView.tag = position 39 | holder.bindData(dataset[position]) 40 | } 41 | 42 | override fun getItemCount(): Int = dataset.size 43 | 44 | override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { 45 | val itemView = LayoutInflater.from(parent!!.context).inflate(R.layout.item_note, parent, false) 46 | itemView.setOnClickListener { v -> 47 | val note: Note = dataset[v.tag as Int] 48 | if (onItemClickListener != null) { 49 | onItemClickListener!!.onItemClick(note) 50 | } 51 | } 52 | itemView.setOnLongClickListener { v -> 53 | val note: Note = dataset[v!!.tag as Int] 54 | if (onItemClickListener != null) { 55 | onItemClickListener!!.onItemLongClick(note) 56 | } 57 | true 58 | } 59 | return ViewHolder(itemView) 60 | } 61 | 62 | 63 | inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 64 | var contentTv: TextView = itemView.findViewById(R.id.contentTv) 65 | var dateTv: TextView = itemView.findViewById(R.id.dateTv) 66 | var typeIcon: ImageView = itemView.findViewById(R.id.typeIcon) 67 | fun bindData(note: Note) { 68 | contentTv.text = note.content 69 | dateTv.text = DateUtil.getDateFormat("M月d日").format(note.date) 70 | val typeArr = itemView.context.resources.getStringArray(R.array.arr_note_type) 71 | if ("未标签" == note.type) { 72 | typeIcon.visibility = View.INVISIBLE 73 | } else { 74 | typeIcon.visibility = View.VISIBLE 75 | typeArr.indices 76 | .filter { note.type == typeArr[it] } 77 | .forEach { typeIcon.setColorFilter(itemView.context.resources.getColor(App.instance.colorArr[it])) } 78 | } 79 | } 80 | } 81 | 82 | interface OnItemClickListener { 83 | fun onItemClick(note: Note) 84 | fun onItemLongClick(note: Note) 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_note.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 19 | 20 | 30 | 31 | 41 | 42 | 43 | 47 | 48 | 52 | 53 | 62 | 63 | 73 | 74 | 75 | 84 | 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyNote 2 | ## 使用Kotlin开发的仿华为手机EMUI备忘录,数据本地存储使用ObjectBox 3 | 4 | ### Kotlin-ObjectBox的使用 5 | 6 | 1、工程配置 7 | ``` 8 | buildscript { 9 | ext.kotlin_version = '1.1.3-2' 10 | ext.objectBoxVersion = "0.9.13" 11 | repositories { 12 | google() 13 | jcenter() 14 | maven { url "http://objectbox.net/beta-repo/" } 15 | } 16 | dependencies { 17 | classpath 'com.android.tools.build:gradle:3.0.0-alpha9' 18 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 19 | classpath "io.objectbox:objectbox-gradle-plugin:$objectBoxVersion" 20 | // NOTE: Do not place your application dependencies here; they belong 21 | // in the individual module build.gradle files 22 | } 23 | } 24 | 25 | allprojects { 26 | repositories { 27 | google() 28 | jcenter() 29 | maven { url "http://objectbox.net/beta-repo/" } 30 | } 31 | } 32 | ``` 33 | ``` 34 | apply plugin: 'kotlin-kapt' 35 | apply plugin: 'io.objectbox' 36 | ``` 37 | ``` 38 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 39 | compile('org.jetbrains.anko:anko:0.10.0') { 40 | exclude group: 'com.google.android', module: 'android' 41 | } 42 | compile "io.objectbox:objectbox-android:$objectBoxVersion" 43 | compile "io.objectbox:objectbox-kotlin:$objectBoxVersion" 44 | kapt "io.objectbox:objectbox-processor:$objectBoxVersion" 45 | ``` 46 | 2、配置KotlinBean--->make project 47 | ```kotlin 48 | @Entity 49 | data class Note( 50 | @Id var id: Long = 0, 51 | var type: String? = null, 52 | var content: String? = null, 53 | var date: Date? = null 54 | ) 55 | ``` 56 | 3、使用ObjectBox(基本使用) 57 | ```kotlin 58 | class App : Application() { 59 | 60 | lateinit var boxStore: BoxStore 61 | private set 62 | 63 | override fun onCreate() { 64 | super.onCreate() 65 | instance = this 66 | boxStore = MyObjectBox.builder().androidContext(this).build() 67 | } 68 | } 69 | 70 | private lateinit var noteBox: Box 71 | private lateinit var noteQuery: Query 72 | 73 | noteBox = (application as App).boxStore.boxFor(Note::class.java) 74 | notesQuery = noteBox.query().order(Note_.content).build() 75 | ``` 76 | 增、改 77 | ```kotlin 78 | private fun addNote() { 79 | val content = contentTv.text.toString() 80 | val note = Note(type = type, content = content, date = date) 81 | if (noteID != -1L) { //不传ID则ID自增,传入ID则为改 82 | note.id = noteID 83 | } 84 | noteBox.put(note) 85 | } 86 | ``` 87 | 删 88 | 89 | ```kotlin 90 | noteBox.remove(note) 91 | ``` 92 | 查 93 | 94 | ```kotlin 95 | fun queryNotes() { //查询全部 96 | val notes = noteQuery.find() 97 | mAdapter.setData(notes) 98 | } 99 | 100 | fun queryNotes(type: String) { //查询指定type 101 | val builder: QueryBuilder = noteBox.query() 102 | val notes = builder.equal(Note_.type, type).build().find() 103 | mAdapter.setData(notes) 104 | } 105 | ``` 106 | 107 | ### EasyNote预览 108 | 109 | ![image](https://github.com/leiyun1993/EasyNote/raw/master/images/01.jpg) 110 | ![image](https://github.com/leiyun1993/EasyNote/raw/master/images/02.jpg) 111 | ![image](https://github.com/leiyun1993/EasyNote/raw/master/images/03.jpg) 112 | ![image](https://github.com/leiyun1993/EasyNote/raw/master/images/04.jpg) 113 | ![image](https://github.com/leiyun1993/EasyNote/raw/master/images/05.jpg) 114 | 115 | ### 相关链接 116 | 117 | 1、GreenDao老东家的[ObjectBox](https://github.com/greenrobot/ObjectBox) 118 | 119 | 2、Google 2017IO大会指定Android开发语言[Kotlin](https://github.com/JetBrains/kotlin) 120 | 121 | 3、Anko是一个使开发Android应用更简单更快捷的库[Anko](https://github.com/Kotlin/anko) 122 | 123 | ### 更新日志 124 | 125 | 1、升级objectBoxVersion 126 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 17 | 22 | 27 | 32 | 37 | 42 | 47 | 52 | 57 | 62 | 67 | 72 | 77 | 82 | 87 | 92 | 97 | 102 | 107 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/leiyun/easynote/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import android.graphics.Color 6 | import android.support.v7.app.AlertDialog 7 | import android.support.v7.widget.LinearLayoutManager 8 | import android.view.Gravity 9 | import android.view.View 10 | import android.widget.ImageView 11 | import android.widget.TextView 12 | import com.jaeger.library.StatusBarUtil 13 | import com.leiyun.easynote.adapter.NotesAdapter 14 | import com.leiyun.easynote.base.BaseActivity 15 | import com.leiyun.easynote.base.showTips 16 | import com.leiyun.easynote.model.Note 17 | import com.leiyun.easynote.model.Note_ 18 | import com.leiyun.easynote.ui.NoteActivity 19 | import io.objectbox.Box 20 | import io.objectbox.query.Query 21 | import io.objectbox.query.QueryBuilder 22 | import kotlinx.android.synthetic.main.activity_main.* 23 | import org.jetbrains.anko.startActivityForResult 24 | 25 | 26 | class MainActivity : BaseActivity() { 27 | private val reqCode: Int = 0x01 28 | private lateinit var noteBox: Box 29 | private lateinit var noteQuery: Query 30 | private lateinit var mAdapter: NotesAdapter 31 | 32 | 33 | override fun getContentLayout(): Int = R.layout.activity_main 34 | 35 | override fun setStatusBar() { 36 | StatusBarUtil.setColorForDrawerLayout(this, drawerLayout, Color.WHITE, 50) 37 | } 38 | 39 | override fun initData() { 40 | noteBox = (application as App).boxStore.boxFor(Note::class.java) 41 | noteQuery = noteBox.query().build() 42 | 43 | val typeArr = resources.getStringArray(R.array.arr_note_type) 44 | for (i in typeArr.indices) { 45 | val itemView = View.inflate(this, R.layout.item_note_type, null) 46 | itemView.tag = i 47 | val typeIcon: ImageView = itemView.findViewById(R.id.typeIcon) 48 | val typeName: TextView = itemView.findViewById(R.id.typeName) 49 | typeIcon.setColorFilter(resources.getColor((application as App).colorArr[i])) 50 | typeName.text = typeArr[i] 51 | leftDrawer.addView(itemView) 52 | itemView.setOnClickListener { v -> 53 | queryNotes(typeArr[v.tag as Int]) 54 | drawerLayout.closeDrawer(Gravity.START, false) 55 | } 56 | } 57 | val itemView = View.inflate(this, R.layout.item_note_type, null) 58 | val typeIcon: ImageView = itemView.findViewById(R.id.typeIcon) 59 | val typeName: TextView = itemView.findViewById(R.id.typeName) 60 | typeIcon.setColorFilter(resources.getColor(R.color.white)) 61 | typeName.text = "全部" 62 | itemView.setOnClickListener { 63 | queryNotes() 64 | drawerLayout.closeDrawer(Gravity.START, false) 65 | } 66 | leftDrawer.addView(itemView) 67 | 68 | toolbar.setNavigationIcon(R.mipmap.ic_drawer_home) 69 | toolbar.title = "备忘录" 70 | toolbar.setTitleTextAppearance(this, R.style.Toolbar_TitleText) 71 | toolbar.setNavigationOnClickListener { 72 | drawerLayout.openDrawer(Gravity.START, true) 73 | } 74 | floatBtn.setOnClickListener { 75 | startActivityForResult(reqCode) 76 | } 77 | 78 | recycleView.layoutManager = LinearLayoutManager(this) 79 | mAdapter = NotesAdapter() 80 | recycleView.adapter = mAdapter 81 | mAdapter.setOnItemClickListener(object : NotesAdapter.OnItemClickListener { 82 | override fun onItemClick(note: Note) { 83 | startActivityForResult(reqCode, "noteID" to note.id) 84 | } 85 | 86 | override fun onItemLongClick(note: Note) { 87 | deleteNote(note) 88 | } 89 | 90 | }) 91 | queryNotes() 92 | } 93 | 94 | fun queryNotes() { 95 | val notes = noteQuery.find() 96 | mAdapter.setData(notes) 97 | } 98 | 99 | fun queryNotes(type: String) { 100 | val builder: QueryBuilder = noteBox.query() 101 | val notes = builder.equal(Note_.type, type).build().find() 102 | mAdapter.setData(notes) 103 | } 104 | 105 | fun deleteNote(note: Note) { 106 | AlertDialog.Builder(this) 107 | .setMessage("确认删除?") 108 | .setTitle("温馨提示") 109 | .setNegativeButton("取消") { dialog, _ -> 110 | dialog.dismiss() 111 | } 112 | .setPositiveButton("确定") { dialog, _ -> 113 | dialog.dismiss() 114 | noteBox.remove(note) 115 | showTips(coordinatorLayout, "删除成功") 116 | queryNotes() 117 | }.show() 118 | 119 | } 120 | 121 | 122 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 123 | super.onActivityResult(requestCode, resultCode, data) 124 | if (resultCode == Activity.RESULT_OK && requestCode == reqCode) { 125 | queryNotes() 126 | } 127 | } 128 | 129 | 130 | } 131 | -------------------------------------------------------------------------------- /app/src/main/java/com/leiyun/easynote/ui/NoteActivity.kt: -------------------------------------------------------------------------------- 1 | package com.leiyun.easynote.ui 2 | 3 | import android.app.Activity 4 | import android.support.v7.app.AlertDialog 5 | import android.view.View 6 | import android.widget.ImageView 7 | import android.widget.LinearLayout 8 | import android.widget.TextView 9 | import com.leiyun.easynote.App 10 | import com.leiyun.easynote.R 11 | import com.leiyun.easynote.base.BaseActivity 12 | import com.leiyun.easynote.base.showTips 13 | import com.leiyun.easynote.model.Note 14 | import com.leiyun.easynote.model.Note_ 15 | import com.leiyun.easynote.utils.DateUtil 16 | import com.leiyun.easynote.utils.SoftInputUtil 17 | import io.objectbox.Box 18 | import io.objectbox.query.Query 19 | import kotlinx.android.synthetic.main.activity_note.* 20 | import org.jetbrains.anko.imageResource 21 | import java.util.* 22 | 23 | class NoteActivity : BaseActivity() { 24 | private var date: Date? = null 25 | private lateinit var noteBox: Box 26 | private lateinit var notesQuery: Query 27 | private var note: Note? = null 28 | private var noteID: Long = -1 29 | private var type: String = "未标签" 30 | 31 | override fun getContentLayout(): Int = R.layout.activity_note 32 | 33 | override fun initData() { 34 | noteID = intent.getLongExtra("noteID", -1) 35 | noteBox = (application as App).boxStore.boxFor(Note::class.java) 36 | notesQuery = noteBox.query().order(Note_.content).build() 37 | if (noteID != -1L) { 38 | note = noteBox.get(noteID) 39 | } 40 | 41 | toolbar.setNavigationIcon(R.mipmap.ic_back) 42 | toolbar.setTitleTextAppearance(this, R.style.Toolbar_TitleText) 43 | toolbar.setNavigationOnClickListener { 44 | onBackPressed() 45 | } 46 | sureBtn.setOnClickListener { 47 | val content = contentTv.text.toString() 48 | if (content.isEmpty()) { 49 | showTips(null, "不能保存空的备忘录") 50 | } else { 51 | addNote() 52 | setResult(Activity.RESULT_OK) 53 | finish() 54 | } 55 | } 56 | tagBtn.setOnClickListener { 57 | sureBtn.visibility = View.VISIBLE 58 | edtNoteTitle.visibility = View.VISIBLE 59 | toolbar.title = "" 60 | showTypeDialog() 61 | } 62 | 63 | if (note == null) { 64 | noteTime.text = DateUtil.getNowTimeFriendly() 65 | date = DateUtil.getDate() 66 | } else { 67 | sureBtn.visibility = View.GONE 68 | edtNoteTitle.visibility = View.GONE 69 | toolbar.title = "备忘录" 70 | date = (note as Note).date 71 | noteTime.text = DateUtil.getFriendlyTimeOfDate((note as Note).date!!) 72 | contentTv.setText((note as Note).content) 73 | contentTv.isFocusable = false 74 | contentTv.isFocusableInTouchMode = false 75 | contentTv.setOnClickListener { 76 | contentTv.isFocusable = true 77 | contentTv.isFocusableInTouchMode = true 78 | contentTv.requestFocus() 79 | contentTv.setSelection((note as Note).content!!.length) 80 | SoftInputUtil.showSoftInput(this@NoteActivity) 81 | sureBtn.visibility = View.VISIBLE 82 | edtNoteTitle.visibility = View.VISIBLE 83 | toolbar.title = "" 84 | contentTv.setOnClickListener(null) 85 | } 86 | if ("未标签" == (note as Note).type) { 87 | tagBtn.imageResource = R.mipmap.ic_type_tag 88 | } else { 89 | val typeArr = resources.getStringArray(R.array.arr_note_type) 90 | tagBtn.imageResource = R.mipmap.ic_note_type 91 | typeArr.indices 92 | .filter { (note as Note).type == typeArr[it] } 93 | .forEach { tagBtn.setColorFilter(resources.getColor(App.instance.colorArr[it])) } 94 | } 95 | } 96 | 97 | } 98 | 99 | fun showTypeDialog() { 100 | val view: LinearLayout = LinearLayout(this) 101 | val dialog = AlertDialog.Builder(this) 102 | .setView(view).show() 103 | view.orientation = LinearLayout.VERTICAL 104 | val typeArr = resources.getStringArray(R.array.arr_note_type) 105 | for (i in typeArr.indices) { 106 | val itemView = View.inflate(this, R.layout.item_note_type, null) 107 | itemView.tag = i 108 | val typeIcon: ImageView = itemView.findViewById(R.id.typeIcon) 109 | val typeName: TextView = itemView.findViewById(R.id.typeName) 110 | typeIcon.setColorFilter(resources.getColor((application as App).colorArr[i])) 111 | typeName.text = typeArr[i] 112 | view.addView(itemView) 113 | itemView.setOnClickListener { v -> 114 | val position = v.tag as Int 115 | type = typeArr[position] 116 | tagBtn.imageResource = R.mipmap.ic_note_type 117 | tagBtn.setColorFilter(resources.getColor((application as App).colorArr[position])) 118 | dialog.dismiss() 119 | } 120 | } 121 | } 122 | 123 | private fun addNote() { 124 | val content = contentTv.text.toString() 125 | val note = Note(type = type, content = content, date = date) 126 | if (noteID != -1L) { 127 | note.id = noteID 128 | } 129 | noteBox.put(note) 130 | } 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | --------------------------------------------------------------------------------