@ -1,9 +1,15 @@
|
||||
# generated files
|
||||
bin/
|
||||
gen/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
project.properties
|
||||
.settings/
|
||||
.classpath
|
||||
.project
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
local.properties
|
||||
|
||||
@ -1,190 +0,0 @@
|
||||
|
||||
Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
@ -0,0 +1 @@
|
||||
/build
|
||||
@ -0,0 +1,79 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "net.micode.notes"
|
||||
|
||||
// 修改这里:匹配你下载的 SDK 30
|
||||
compileSdk = 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "net.micode.notes"
|
||||
minSdk = 30
|
||||
// 修改这里:匹配你下载的 SDK 30
|
||||
targetSdk = 34
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
// === 这里是新增的代码,用来解决 Jar 包冲突报错 ===
|
||||
packaging {
|
||||
resources {
|
||||
excludes += "META-INF/DEPENDENCIES"
|
||||
excludes += "META-INF/NOTICE"
|
||||
excludes += "META-INF/LICENSE"
|
||||
excludes += "META-INF/LICENSE.txt"
|
||||
excludes += "META-INF/NOTICE.txt"
|
||||
}
|
||||
}
|
||||
// ==============================================
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// === 修改部分:使用兼容 SDK 30 的旧版本库 ===
|
||||
// 替换掉了原本的 libs.appcompat 等引用,改为写死的旧版本号
|
||||
// ViewPager2 用于左右滑动
|
||||
implementation("androidx.recyclerview:recyclerview:1.3.0")
|
||||
implementation("androidx.viewpager2:viewpager2:1.0.0")
|
||||
// Material Design 用于底部导航栏
|
||||
implementation("com.google.android.material:material:1.9.0")
|
||||
// Fragment 核心库 (确保使用 AndroidX 版本)
|
||||
implementation("androidx.fragment:fragment:1.5.7")
|
||||
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||
implementation("androidx.appcompat:appcompat:1.3.1")
|
||||
implementation("com.google.android.material:material:1.4.0")
|
||||
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||
implementation("androidx.drawerlayout:drawerlayout:1.2.0")
|
||||
implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0")
|
||||
|
||||
// 如果你需要 Activity 的新特性,也需要指定旧版本,否则默认会拉取最新的导致报错
|
||||
implementation("androidx.activity:activity:1.2.4")
|
||||
|
||||
// Google Play Services - 用于地理围栏
|
||||
implementation("com.google.android.gms:play-services-location:21.0.1")
|
||||
|
||||
// === 保持不变:你的 Jar 包路径 ===
|
||||
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
||||
|
||||
// === 测试库也建议指定旧版本,防止冲突 ===
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.3")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@ -0,0 +1,26 @@
|
||||
package net.micode.notes;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("net.micode.notes", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,153 @@
|
||||
package net.micode.notes.data;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.util.Log;
|
||||
|
||||
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
|
||||
import net.micode.notes.todo.TodoItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 待办事项数据访问层 (CRUD)
|
||||
*/
|
||||
public class TodoDao {
|
||||
private static final String TAG = "TodoDao";
|
||||
|
||||
private static final String COL_ID = "id";
|
||||
private static final String COL_CONTENT = "content";
|
||||
private static final String COL_IS_DONE = "is_done";
|
||||
private static final String COL_REMINDER_TYPE = "reminder_type";
|
||||
private static final String COL_REMINDER_TIMESTAMP = "reminder_timestamp";
|
||||
private static final String COL_LATITUDE = "latitude";
|
||||
private static final String COL_LONGITUDE = "longitude";
|
||||
private static final String COL_LOCATION_NAME = "location_name";
|
||||
private static final String COL_CREATED_TIME = "created_time";
|
||||
|
||||
private final NotesDatabaseHelper mHelper;
|
||||
|
||||
public TodoDao(Context context) {
|
||||
mHelper = NotesDatabaseHelper.getInstance(context);
|
||||
}
|
||||
|
||||
public long insert(TodoItem item) {
|
||||
SQLiteDatabase db = mHelper.getWritableDatabase();
|
||||
ContentValues cv = toContentValues(item);
|
||||
long id = db.insert(TABLE.TODO_ITEMS, null, cv);
|
||||
Log.d(TAG, "insert todo id=" + id);
|
||||
return id;
|
||||
}
|
||||
|
||||
public int update(TodoItem item) {
|
||||
if (item.getId() <= 0) return 0;
|
||||
SQLiteDatabase db = mHelper.getWritableDatabase();
|
||||
ContentValues cv = toContentValues(item);
|
||||
return db.update(TABLE.TODO_ITEMS, cv, COL_ID + "=?", new String[]{String.valueOf(item.getId())});
|
||||
}
|
||||
|
||||
public int delete(long id) {
|
||||
SQLiteDatabase db = mHelper.getWritableDatabase();
|
||||
return db.delete(TABLE.TODO_ITEMS, COL_ID + "=?", new String[]{String.valueOf(id)});
|
||||
}
|
||||
|
||||
public int deleteByIds(List<Long> ids) {
|
||||
if (ids == null || ids.isEmpty()) return 0;
|
||||
SQLiteDatabase db = mHelper.getWritableDatabase();
|
||||
StringBuilder sb = new StringBuilder(COL_ID).append(" IN (");
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
sb.append(i > 0 ? "," : "").append(ids.get(i));
|
||||
}
|
||||
sb.append(")");
|
||||
return db.delete(TABLE.TODO_ITEMS, sb.toString(), null);
|
||||
}
|
||||
|
||||
public TodoItem getById(long id) {
|
||||
SQLiteDatabase db = mHelper.getReadableDatabase();
|
||||
try (Cursor c = db.query(TABLE.TODO_ITEMS, null, COL_ID + "=?", new String[]{String.valueOf(id)}, null, null, null)) {
|
||||
if (c != null && c.moveToFirst()) {
|
||||
return fromCursor(c);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<TodoItem> getAll() {
|
||||
List<TodoItem> list = new ArrayList<>();
|
||||
SQLiteDatabase db = mHelper.getReadableDatabase();
|
||||
try (Cursor c = db.query(TABLE.TODO_ITEMS, null, null, null, null, null, COL_IS_DONE + " ASC, " + COL_CREATED_TIME + " DESC")) {
|
||||
if (c != null) {
|
||||
while (c.moveToNext()) {
|
||||
list.add(fromCursor(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<TodoItem> getUndone() {
|
||||
List<TodoItem> list = new ArrayList<>();
|
||||
SQLiteDatabase db = mHelper.getReadableDatabase();
|
||||
try (Cursor c = db.query(TABLE.TODO_ITEMS, null, COL_IS_DONE + "=0", null, null, null, COL_CREATED_TIME + " DESC")) {
|
||||
if (c != null) {
|
||||
while (c.moveToNext()) {
|
||||
list.add(fromCursor(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<TodoItem> getDone() {
|
||||
List<TodoItem> list = new ArrayList<>();
|
||||
SQLiteDatabase db = mHelper.getReadableDatabase();
|
||||
try (Cursor c = db.query(TABLE.TODO_ITEMS, null, COL_IS_DONE + "=1", null, null, null, COL_CREATED_TIME + " DESC")) {
|
||||
if (c != null) {
|
||||
while (c.moveToNext()) {
|
||||
list.add(fromCursor(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public int getUndoneCount() {
|
||||
SQLiteDatabase db = mHelper.getReadableDatabase();
|
||||
try (Cursor c = db.rawQuery("SELECT COUNT(*) FROM " + TABLE.TODO_ITEMS + " WHERE " + COL_IS_DONE + "=0", null)) {
|
||||
if (c != null && c.moveToFirst()) {
|
||||
return c.getInt(0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private ContentValues toContentValues(TodoItem item) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(COL_CONTENT, item.getContent());
|
||||
cv.put(COL_IS_DONE, item.isDone() ? 1 : 0);
|
||||
cv.put(COL_REMINDER_TYPE, item.getReminderType());
|
||||
cv.put(COL_REMINDER_TIMESTAMP, item.getReminderTimestamp());
|
||||
cv.put(COL_LATITUDE, item.getLatitude());
|
||||
cv.put(COL_LONGITUDE, item.getLongitude());
|
||||
cv.put(COL_LOCATION_NAME, item.getLocationName());
|
||||
cv.put(COL_CREATED_TIME, item.getCreatedTime());
|
||||
return cv;
|
||||
}
|
||||
|
||||
private TodoItem fromCursor(Cursor c) {
|
||||
TodoItem item = new TodoItem();
|
||||
item.setId(c.getLong(c.getColumnIndexOrThrow(COL_ID)));
|
||||
item.setContent(c.getString(c.getColumnIndexOrThrow(COL_CONTENT)));
|
||||
item.setDone(c.getInt(c.getColumnIndexOrThrow(COL_IS_DONE)) == 1);
|
||||
item.setReminderType(c.getInt(c.getColumnIndexOrThrow(COL_REMINDER_TYPE)));
|
||||
item.setReminderTimestamp(c.getLong(c.getColumnIndexOrThrow(COL_REMINDER_TIMESTAMP)));
|
||||
item.setLatitude(c.getDouble(c.getColumnIndexOrThrow(COL_LATITUDE)));
|
||||
item.setLongitude(c.getDouble(c.getColumnIndexOrThrow(COL_LONGITUDE)));
|
||||
item.setLocationName(c.getString(c.getColumnIndexOrThrow(COL_LOCATION_NAME)));
|
||||
item.setCreatedTime(c.getLong(c.getColumnIndexOrThrow(COL_CREATED_TIME)));
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package net.micode.notes.todo;
|
||||
|
||||
/**
|
||||
* 待办事项实体类
|
||||
*/
|
||||
public class TodoItem {
|
||||
/** 提醒类型:无 */
|
||||
public static final int REMINDER_NONE = 0;
|
||||
/** 提醒类型:时间 */
|
||||
public static final int REMINDER_TIME = 1;
|
||||
/** 提醒类型:地点 */
|
||||
public static final int REMINDER_LOCATION = 2;
|
||||
|
||||
private long id;
|
||||
private String content;
|
||||
private boolean isDone;
|
||||
private int reminderType;
|
||||
private long reminderTimestamp;
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
private String locationName;
|
||||
private long createdTime;
|
||||
|
||||
public TodoItem() {
|
||||
this.id = 0;
|
||||
this.content = "";
|
||||
this.isDone = false;
|
||||
this.reminderType = REMINDER_NONE;
|
||||
this.reminderTimestamp = 0;
|
||||
this.latitude = 0;
|
||||
this.longitude = 0;
|
||||
this.locationName = "";
|
||||
this.createdTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getId() { return id; }
|
||||
public void setId(long id) { this.id = id; }
|
||||
|
||||
public String getContent() { return content; }
|
||||
public void setContent(String content) { this.content = content != null ? content : ""; }
|
||||
|
||||
public boolean isDone() { return isDone; }
|
||||
public void setDone(boolean done) { isDone = done; }
|
||||
|
||||
public int getReminderType() { return reminderType; }
|
||||
public void setReminderType(int reminderType) { this.reminderType = reminderType; }
|
||||
|
||||
public long getReminderTimestamp() { return reminderTimestamp; }
|
||||
public void setReminderTimestamp(long reminderTimestamp) { this.reminderTimestamp = reminderTimestamp; }
|
||||
|
||||
public double getLatitude() { return latitude; }
|
||||
public void setLatitude(double latitude) { this.latitude = latitude; }
|
||||
|
||||
public double getLongitude() { return longitude; }
|
||||
public void setLongitude(double longitude) { this.longitude = longitude; }
|
||||
|
||||
public String getLocationName() { return locationName; }
|
||||
public void setLocationName(String locationName) { this.locationName = locationName != null ? locationName : ""; }
|
||||
|
||||
public long getCreatedTime() { return createdTime; }
|
||||
public void setCreatedTime(long createdTime) { this.createdTime = createdTime; }
|
||||
}
|
||||
@ -0,0 +1,142 @@
|
||||
package net.micode.notes.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.AsyncQueryHandler;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.media.projection.MediaProjectionManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Switch;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import net.micode.notes.R;
|
||||
import net.micode.notes.data.Notes;
|
||||
import net.micode.notes.data.Notes.NoteColumns;
|
||||
import net.micode.notes.tool.FloatingService;
|
||||
|
||||
public class InspirationFragment extends Fragment {
|
||||
|
||||
private ListView mListView;
|
||||
private NotesListAdapter mAdapter;
|
||||
private BackgroundQueryHandler mQueryHandler;
|
||||
private Switch mSwitchFloating;
|
||||
|
||||
private static final int QUERY_TOKEN = 202;
|
||||
private static final int REQUEST_CODE_OVERLAY_PERMISSION = 1001;
|
||||
private static final int REQUEST_CODE_SCREEN_CAPTURE = 1002;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_inspiration, container, false);
|
||||
initViews(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
private void initViews(View view) {
|
||||
mListView = view.findViewById(R.id.inspiration_list);
|
||||
mSwitchFloating = view.findViewById(R.id.switch_floating_ball);
|
||||
|
||||
mAdapter = new NotesListAdapter(getActivity());
|
||||
mListView.setAdapter(mAdapter);
|
||||
mQueryHandler = new BackgroundQueryHandler(getActivity().getContentResolver());
|
||||
mListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(android.widget.AdapterView<?> parent, View view, int position, long id) {
|
||||
// 跳转到编辑页 (复用 NoteEditActivity)
|
||||
Intent intent = new Intent(getActivity(), NoteEditActivity.class);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.putExtra(Intent.EXTRA_UID, id); // 传入便签 ID
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
mSwitchFloating.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
checkAndStartService();
|
||||
} else {
|
||||
stopFloatingService();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkAndStartService() {
|
||||
// 1. 检查悬浮窗权限
|
||||
if (!Settings.canDrawOverlays(getContext())) {
|
||||
Toast.makeText(getActivity(), "请授予悬浮窗权限", Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
Uri.parse("package:" + getActivity().getPackageName()));
|
||||
startActivityForResult(intent, REQUEST_CODE_OVERLAY_PERMISSION);
|
||||
mSwitchFloating.setChecked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 申请截屏权限
|
||||
MediaProjectionManager mm = (MediaProjectionManager) getActivity().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
|
||||
startActivityForResult(mm.createScreenCaptureIntent(), REQUEST_CODE_SCREEN_CAPTURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQUEST_CODE_OVERLAY_PERMISSION) {
|
||||
if (Settings.canDrawOverlays(getContext())) {
|
||||
checkAndStartService();
|
||||
}
|
||||
} else if (requestCode == REQUEST_CODE_SCREEN_CAPTURE) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
startFloatingService(resultCode, data);
|
||||
} else {
|
||||
mSwitchFloating.setChecked(false);
|
||||
Toast.makeText(getActivity(), "未授权截屏,无法开启", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startFloatingService(int resultCode, Intent data) {
|
||||
Intent intent = new Intent(getActivity(), FloatingService.class);
|
||||
intent.putExtra("resultCode", resultCode);
|
||||
intent.putExtra("data", data);
|
||||
getActivity().startForegroundService(intent);
|
||||
}
|
||||
|
||||
private void stopFloatingService() {
|
||||
Intent intent = new Intent(getActivity(), FloatingService.class);
|
||||
getActivity().stopService(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
refreshList();
|
||||
}
|
||||
|
||||
private void refreshList() {
|
||||
String selection = NoteColumns.PARENT_ID + "=?";
|
||||
String[] selectionArgs = { String.valueOf(Notes.ID_INSPIRATION_FOLDER) };
|
||||
mQueryHandler.startQuery(QUERY_TOKEN, null, Notes.CONTENT_NOTE_URI,
|
||||
NoteItemData.PROJECTION, selection, selectionArgs, NoteColumns.MODIFIED_DATE + " DESC");
|
||||
}
|
||||
|
||||
private final class BackgroundQueryHandler extends AsyncQueryHandler {
|
||||
public BackgroundQueryHandler(ContentResolver cr) { super(cr); }
|
||||
@Override
|
||||
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
|
||||
if (token == QUERY_TOKEN) mAdapter.changeCursor(cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="@color/bottom_nav_selected" android:state_checked="true" />
|
||||
<item android:color="@color/bottom_nav_unselected" />
|
||||
</selector>
|
||||
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 443 B After Width: | Height: | Size: 443 B |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |