@ -1,37 +0,0 @@
|
|||||||
*.iml
|
|
||||||
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Gradle files
|
|
||||||
.gradle/
|
|
||||||
build/
|
|
||||||
|
|
||||||
# Local configuration file (sdk path, etc)
|
|
||||||
local.properties
|
|
||||||
|
|
||||||
# Proguard folder generated by Eclipse
|
|
||||||
proguard/
|
|
||||||
|
|
||||||
# Log Files
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# Android Studio Navigation editor temp files
|
|
||||||
.navigation/
|
|
||||||
|
|
||||||
# Android Studio captures folder
|
|
||||||
captures/
|
|
||||||
|
|
||||||
# Intellij
|
|
||||||
*.iml
|
|
||||||
.idea/workspace.xml
|
|
||||||
.idea/tasks.xml
|
|
||||||
.idea/gradle.xml
|
|
||||||
.idea/dictionaries
|
|
||||||
.idea/libraries
|
|
||||||
.idea/
|
|
||||||
|
|
||||||
# Keystore files
|
|
||||||
*.jks
|
|
||||||
|
|
||||||
# External native build folder generated in Android Studio 2.2 and later
|
|
||||||
.externalNativeBuild
|
|
@ -1,20 +0,0 @@
|
|||||||
apply plugin: 'com.android.application'
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdkVersion 23
|
|
||||||
buildToolsVersion "25.0.1"
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
applicationId "net.micode.notes"
|
|
||||||
minSdkVersion 14
|
|
||||||
targetSdkVersion 14
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled false
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
android{ useLibrary 'org.apache.http.legacy' }
|
|
||||||
}
|
|
Before Width: | Height: | Size: 144 B |
Before Width: | Height: | Size: 148 B |
@ -1,15 +0,0 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'com.android.tools.build:gradle:2.3.2'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
allprojects {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
## Project-wide Gradle settings.
|
|
||||||
#
|
|
||||||
# For more details on how to configure your build environment visit
|
|
||||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
|
||||||
#
|
|
||||||
# Specifies the JVM arguments used for the daemon process.
|
|
||||||
# The setting is particularly useful for tweaking memory settings.
|
|
||||||
# Default value: -Xmx1024m -XX:MaxPermSize=256m
|
|
||||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
|
||||||
#
|
|
||||||
# When configured, Gradle will run in incubating parallel mode.
|
|
||||||
# This option should only be used with decoupled projects. More details, visit
|
|
||||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
|
||||||
# org.gradle.parallel=true
|
|
||||||
#Thu May 04 14:08:34 GMT+08:00 2017
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
|||||||
#Sat May 05 06:31:36 CST 2018
|
|
||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
|
@ -1,36 +0,0 @@
|
|||||||
ECLIPSE ANDROID PROJECT IMPORT SUMMARY
|
|
||||||
======================================
|
|
||||||
|
|
||||||
Ignored Files:
|
|
||||||
--------------
|
|
||||||
The following files were *not* copied into the new Gradle project; you
|
|
||||||
should evaluate whether these are still needed in your project and if
|
|
||||||
so manually move them:
|
|
||||||
|
|
||||||
* .gitignore
|
|
||||||
* NOTICE
|
|
||||||
* README.md
|
|
||||||
|
|
||||||
Moved Files:
|
|
||||||
------------
|
|
||||||
Android Gradle projects use a different directory structure than ADT
|
|
||||||
Eclipse projects. Here's how the projects were restructured:
|
|
||||||
|
|
||||||
* AndroidManifest.xml => app\src\main\AndroidManifest.xml
|
|
||||||
* res\ => app\src\main\res\
|
|
||||||
* src\ => app\src\main\java\
|
|
||||||
|
|
||||||
Next Steps:
|
|
||||||
-----------
|
|
||||||
You can now build the project. The Gradle project needs network
|
|
||||||
connectivity to download dependencies.
|
|
||||||
|
|
||||||
Bugs:
|
|
||||||
-----
|
|
||||||
If for some reason your project does not build, and you determine that
|
|
||||||
it is due to a bug or limitation of the Eclipse to Gradle importer,
|
|
||||||
please file a bug at http://b.android.com with category
|
|
||||||
Component-Tools.
|
|
||||||
|
|
||||||
(This import summary is for your information only, and can be deleted
|
|
||||||
after import once you are satisfied with the results.)
|
|
@ -1 +0,0 @@
|
|||||||
include ':app'
|
|
@ -0,0 +1,9 @@
|
|||||||
|
# generated files
|
||||||
|
bin/
|
||||||
|
gen/
|
||||||
|
|
||||||
|
# Local configuration file (sdk path, etc)
|
||||||
|
project.properties
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
@ -0,0 +1,2 @@
|
|||||||
|
#Fri Mar 14 15:44:14 CST 2025
|
||||||
|
gradle.version=8.11.1
|
@ -0,0 +1,2 @@
|
|||||||
|
#Fri Mar 14 15:44:00 CST 2025
|
||||||
|
java.home=E\:\\Android\\Android Studio\\jbr
|
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AndroidProjectSystem">
|
||||||
|
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AppInsightsSettings">
|
||||||
|
<option name="selectedTabId" value="Android Vitals" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel target="21" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="deploymentTargetSelector">
|
||||||
|
<selectionStates>
|
||||||
|
<SelectionState runConfigName="app">
|
||||||
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
|
<DropdownSelection timestamp="2025-06-07T15:56:39.281897900Z">
|
||||||
|
<Target type="DEFAULT_BOOT">
|
||||||
|
<handle>
|
||||||
|
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\Song91\.android\avd\Pixel_8_Pro.avd" />
|
||||||
|
</handle>
|
||||||
|
</Target>
|
||||||
|
</DropdownSelection>
|
||||||
|
<DialogSelection />
|
||||||
|
</SelectionState>
|
||||||
|
</selectionStates>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
|
<component name="GradleSettings">
|
||||||
|
<option name="linkedExternalProjectsSettings">
|
||||||
|
<GradleProjectSettings>
|
||||||
|
<option name="testRunner" value="CHOOSE_PER_TEST" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="gradleHome" value="$PROJECT_DIR$/../../Android/Gradle/gradle-8.13" />
|
||||||
|
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||||
|
<option name="modules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
<option value="$PROJECT_DIR$/app" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</GradleProjectSettings>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectMigrations">
|
||||||
|
<option name="MigrateToGradleLocalJavaHome">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="PWA">
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
<option name="wasEnabledAtLeastOnce" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectType">
|
||||||
|
<option name="id" value="Android" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RunConfigurationProducerService">
|
||||||
|
<option name="ignoredProducers">
|
||||||
|
<set>
|
||||||
|
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
|
||||||
|
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
|
||||||
|
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
|
||||||
|
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
|
||||||
|
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
|
||||||
|
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
|
||||||
|
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
|
||||||
|
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"java.configuration.updateBuildConfiguration": "interactive"
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
/build
|
@ -0,0 +1,60 @@
|
|||||||
|
plugins {
|
||||||
|
alias(libs.plugins.android.application)
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace = "net.micode.notes"
|
||||||
|
compileSdk = 35
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId = "net.micode.notes"
|
||||||
|
minSdk = 24
|
||||||
|
targetSdk = 35
|
||||||
|
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
|
||||||
|
}
|
||||||
|
packaging {
|
||||||
|
resources.excludes.add("META-INF/DEPENDENCIES");
|
||||||
|
resources.excludes.add("META-INF/NOTICE");
|
||||||
|
resources.excludes.add("META-INF/LICENSE");
|
||||||
|
resources.excludes.add("META-INF/LICENSE.txt");
|
||||||
|
resources.excludes.add("META-INF/NOTICE.txt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(libs.appcompat)
|
||||||
|
implementation(libs.material)
|
||||||
|
implementation(libs.activity)
|
||||||
|
implementation(libs.constraintlayout)
|
||||||
|
|
||||||
|
// 推荐的 fileTree 写法,兼容 Kotlin DSL
|
||||||
|
implementation(fileTree("httpcomponents-client-4.5.14-bin/lib") { include("*.jar") })
|
||||||
|
|
||||||
|
testImplementation(libs.junit)
|
||||||
|
androidTestImplementation(libs.ext.junit)// implementation(fileTree(mapOf(
|
||||||
|
// "dir" to "D:\\Code\\AndroidCode\\Notesmaster\\httpcomponents-client-4.5.14-bin\\lib",
|
||||||
|
// "include" to listOf("*.aar", "*.jar"),
|
||||||
|
// "exclude" to listOf("")
|
||||||
|
// )))
|
||||||
|
//修改为如下代码:
|
||||||
|
implementation(files("E:\\Code\\Notes-master\\httpcomponents-client-4.5.14-bin\\lib\\httpclient-osgi-4.5.14.jar"))
|
||||||
|
implementation(files("E:\\Code\\Notes-master\\httpcomponents-client-4.5.14-bin\\lib\\httpclient-win-4.5.14.jar"))
|
||||||
|
implementation(files("E:\\Code\\Notes-master\\httpcomponents-client-4.5.14-bin\\lib\\httpcore-4.4.16.jar"))
|
||||||
|
}
|
@ -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,159 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
package="net.micode.notes">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
|
||||||
|
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
|
||||||
|
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||||
|
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/Theme.Notesmaster"
|
||||||
|
tools:targetApi="31">
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".ui.NotesListActivity"
|
||||||
|
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||||
|
android:label="Notes"
|
||||||
|
android:launchMode="singleTop"
|
||||||
|
android:theme="@style/NoteTheme"
|
||||||
|
android:uiOptions="splitActionBarWhenNarrow"
|
||||||
|
android:windowSoftInputMode="adjustPan"
|
||||||
|
android:exported="true">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".ui.NoteEditActivity"
|
||||||
|
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||||
|
android:launchMode="singleTop"
|
||||||
|
android:theme="@style/NoteTheme"
|
||||||
|
android:exported="true">
|
||||||
|
|
||||||
|
<intent-filter >
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="vnd.android.cursor.item/text_note" />
|
||||||
|
<data android:mimeType="vnd.android.cursor.item/call_note" />
|
||||||
|
</intent-filter >>
|
||||||
|
|
||||||
|
<intent-filter >
|
||||||
|
<action android:name="android.intent.action.INSERT_OR_EDIT" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="vnd.android.cursor.item/text_note" />
|
||||||
|
<data android:mimeType="vnd.android.cursor.item/call_note" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEARCH" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.searchable"
|
||||||
|
android:resource="@xml/searchable" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="net.micode.notes.data.NotesProvider"
|
||||||
|
android:authorities="micode_notes"
|
||||||
|
android:multiprocess="true" />
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".widget.NoteWidgetProvider_2x"
|
||||||
|
android:label="@string/app_widget2x2"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_DELETED" />
|
||||||
|
<action android:name="android.intent.action.PRIVACY_MODE_CHANGED" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.appwidget.provider"
|
||||||
|
android:resource="@xml/widget_2x_info" />
|
||||||
|
</receiver>
|
||||||
|
<receiver
|
||||||
|
android:name=".widget.NoteWidgetProvider_4x"
|
||||||
|
android:label="@string/app_widget4x4"
|
||||||
|
android:exported="true">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
|
<action android:name="android.appwidget.action.APPWIDGET_DELETED" />
|
||||||
|
<action android:name="android.intent.action.PRIVACY_MODE_CHANGED" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.appwidget.provider"
|
||||||
|
android:resource="@xml/widget_4x_info" />
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<receiver android:name=".ui.AlarmInitReceiver"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name="net.micode.notes.ui.AlarmReceiver"
|
||||||
|
android:process=":remote" >
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".ui.AlarmAlertActivity"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:launchMode="singleInstance"
|
||||||
|
android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar" >
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name="net.micode.notes.ui.NotesPreferenceActivity"
|
||||||
|
android:label="@string/preferences_title"
|
||||||
|
android:launchMode="singleTop"
|
||||||
|
android:theme="@android:style/Theme.Holo.Light" >
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name="net.micode.notes.gtask.remote.GTaskSyncService"
|
||||||
|
android:exported="false" >
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.default_searchable"
|
||||||
|
android:value=".ui.NoteEditActivity" />
|
||||||
|
|
||||||
|
<!-- <activity-->
|
||||||
|
<!-- android:name=".MainActivity"-->
|
||||||
|
<!-- android:exported="true">-->
|
||||||
|
<!-- <intent-filter>-->
|
||||||
|
<!-- <action android:name="android.intent.action.MAIN" />-->
|
||||||
|
|
||||||
|
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
|
||||||
|
<!-- </intent-filter>-->
|
||||||
|
<!-- </activity>-->
|
||||||
|
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
@ -0,0 +1,24 @@
|
|||||||
|
package net.micode.notes;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.activity.EdgeToEdge;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.graphics.Insets;
|
||||||
|
import androidx.core.view.ViewCompat;
|
||||||
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
|
|
||||||
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
EdgeToEdge.enable(this);
|
||||||
|
setContentView(R.layout.activity_main);
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||||
|
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||||
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||||
|
return insets;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.data;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||||
|
import android.provider.ContactsContract.Data;
|
||||||
|
import android.telephony.PhoneNumberUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Contact {
|
||||||
|
private static HashMap<String, String> sContactCache;
|
||||||
|
private static final String TAG = "Contact";
|
||||||
|
|
||||||
|
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
|
||||||
|
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
|
||||||
|
+ " AND " + Data.RAW_CONTACT_ID + " IN "
|
||||||
|
+ "(SELECT raw_contact_id "
|
||||||
|
+ " FROM phone_lookup"
|
||||||
|
+ " WHERE min_match = '+')";
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.ECLAIR)
|
||||||
|
public static String getContact(Context context, String phoneNumber) {
|
||||||
|
if(sContactCache == null) {
|
||||||
|
sContactCache = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sContactCache.containsKey(phoneNumber)) {
|
||||||
|
return sContactCache.get(phoneNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
String selection = CALLER_ID_SELECTION.replace("+",
|
||||||
|
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
|
||||||
|
Cursor cursor = context.getContentResolver().query(
|
||||||
|
Data.CONTENT_URI,
|
||||||
|
new String [] { Phone.DISPLAY_NAME },
|
||||||
|
selection,
|
||||||
|
new String[] { phoneNumber },
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
try {
|
||||||
|
String name = cursor.getString(0);
|
||||||
|
sContactCache.put(phoneNumber, name);
|
||||||
|
return name;
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
Log.e(TAG, " Cursor get string error " + e.toString());
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "No contact matched with number:" + phoneNumber);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,285 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.data;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
public class Notes {
|
||||||
|
public static final String AUTHORITY = "micode_notes";
|
||||||
|
public static final String TAG = "Notes";
|
||||||
|
public static final int TYPE_NOTE = 0;
|
||||||
|
public static final int TYPE_FOLDER = 1;
|
||||||
|
public static final int TYPE_SYSTEM = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Following IDs are system folders' identifiers
|
||||||
|
* {@link Notes#ID_ROOT_FOLDER } is default folder
|
||||||
|
* {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder
|
||||||
|
* {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records
|
||||||
|
*/
|
||||||
|
public static final int ID_ROOT_FOLDER = 0;
|
||||||
|
public static final int ID_TEMPARAY_FOLDER = -1;
|
||||||
|
public static final int ID_CALL_RECORD_FOLDER = -2;
|
||||||
|
public static final int ID_TRASH_FOLER = -3;
|
||||||
|
|
||||||
|
public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date";
|
||||||
|
public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id";
|
||||||
|
public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_id";
|
||||||
|
public static final String INTENT_EXTRA_WIDGET_TYPE = "net.micode.notes.widget_type";
|
||||||
|
public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id";
|
||||||
|
public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date";
|
||||||
|
public static final String INTENT_EXTRA_IS_PRIVATE = "net.micode.notes.is_private";
|
||||||
|
|
||||||
|
public static final int TYPE_WIDGET_INVALIDE = -1;
|
||||||
|
public static final int TYPE_WIDGET_2X = 0;
|
||||||
|
public static final int TYPE_WIDGET_4X = 1;
|
||||||
|
|
||||||
|
public static class DataConstants {
|
||||||
|
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
|
||||||
|
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uri to query all notes and folders
|
||||||
|
*/
|
||||||
|
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uri to query data
|
||||||
|
*/
|
||||||
|
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
|
||||||
|
|
||||||
|
public interface NoteColumns {
|
||||||
|
/**
|
||||||
|
* The unique ID for a row
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String ID = "_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parent's id for note or folder
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String PARENT_ID = "parent_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created data for note or folder
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String CREATED_DATE = "created_date";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Latest modified date
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String MODIFIED_DATE = "modified_date";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alert date
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String ALERTED_DATE = "alert_date";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Folder's name or text content of note
|
||||||
|
* <P> Type: TEXT </P>
|
||||||
|
*/
|
||||||
|
public static final String SNIPPET = "snippet";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note's widget id
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String WIDGET_ID = "widget_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note's widget type
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String WIDGET_TYPE = "widget_type";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note's background color's id
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String BG_COLOR_ID = "bg_color_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For text note, it doesn't has attachment, for multi-media
|
||||||
|
* note, it has at least one attachment
|
||||||
|
* <P> Type: INTEGER </P>
|
||||||
|
*/
|
||||||
|
public static final String HAS_ATTACHMENT = "has_attachment";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Folder's count of notes
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String NOTES_COUNT = "notes_count";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The file type: folder or note
|
||||||
|
* <P> Type: INTEGER </P>
|
||||||
|
*/
|
||||||
|
public static final String TYPE = "type";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The last sync id
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String SYNC_ID = "sync_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sign to indicate local modified or not
|
||||||
|
* <P> Type: INTEGER </P>
|
||||||
|
*/
|
||||||
|
public static final String LOCAL_MODIFIED = "local_modified";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Original parent id before moving into temporary folder
|
||||||
|
* <P> Type : INTEGER </P>
|
||||||
|
*/
|
||||||
|
public static final String ORIGIN_PARENT_ID = "origin_parent_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The gtask id
|
||||||
|
* <P> Type : TEXT </P>
|
||||||
|
*/
|
||||||
|
public static final String GTASK_ID = "gtask_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version code
|
||||||
|
* <P> Type : INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String VERSION = "version";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为隐私便签
|
||||||
|
* <P> Type: INTEGER </P>
|
||||||
|
*/
|
||||||
|
public static final String IS_PRIVATE = "is_private";
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface DataColumns {
|
||||||
|
/**
|
||||||
|
* The unique ID for a row
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String ID = "_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MIME type of the item represented by this row.
|
||||||
|
* <P> Type: Text </P>
|
||||||
|
*/
|
||||||
|
public static final String MIME_TYPE = "mime_type";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The reference id to note that this data belongs to
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String NOTE_ID = "note_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created data for note or folder
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String CREATED_DATE = "created_date";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Latest modified date
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String MODIFIED_DATE = "modified_date";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data's content
|
||||||
|
* <P> Type: TEXT </P>
|
||||||
|
*/
|
||||||
|
public static final String CONTENT = "content";
|
||||||
|
|
||||||
|
|
||||||
|
/// Generic data column, the meaning is [#MIMETYPE] specific, used for
|
||||||
|
/// integer data type
|
||||||
|
///
|
||||||
|
/// Type: INTEGER
|
||||||
|
public static final String DATA1 = "data1";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic data column, the meaning is specific, used for
|
||||||
|
* integer data type
|
||||||
|
* <P> Type: INTEGER </P>
|
||||||
|
*/
|
||||||
|
public static final String DATA2 = "data2";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic data column, the meaning is specific, used for
|
||||||
|
* TEXT data type
|
||||||
|
* <P> Type: TEXT </P>
|
||||||
|
*/
|
||||||
|
public static final String DATA3 = "data3";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic data column, the meaning is specific, used for
|
||||||
|
* TEXT data type
|
||||||
|
* <P> Type: TEXT </P>
|
||||||
|
*/
|
||||||
|
public static final String DATA4 = "data4";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic data column, the meaning is specific, used for
|
||||||
|
* TEXT data type
|
||||||
|
* <P> Type: TEXT </P>
|
||||||
|
*/
|
||||||
|
public static final String DATA5 = "data5";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class TextNote implements DataColumns {
|
||||||
|
/**
|
||||||
|
* Mode to indicate the text in check list mode or not
|
||||||
|
* <P> Type: Integer 1:check list mode 0: normal mode </P>
|
||||||
|
*/
|
||||||
|
public static final String MODE = DATA1;
|
||||||
|
|
||||||
|
public static final int MODE_CHECK_LIST = 1;
|
||||||
|
|
||||||
|
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";
|
||||||
|
|
||||||
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
|
||||||
|
|
||||||
|
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class CallNote implements DataColumns {
|
||||||
|
/**
|
||||||
|
* Call date for this record
|
||||||
|
* <P> Type: INTEGER (long) </P>
|
||||||
|
*/
|
||||||
|
public static final String CALL_DATE = DATA1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phone number for this record
|
||||||
|
* <P> Type: TEXT </P>
|
||||||
|
*/
|
||||||
|
public static final String PHONE_NUMBER = DATA3;
|
||||||
|
|
||||||
|
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";
|
||||||
|
|
||||||
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";
|
||||||
|
|
||||||
|
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,365 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.data;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import net.micode.notes.data.Notes.DataColumns;
|
||||||
|
import net.micode.notes.data.Notes.DataConstants;
|
||||||
|
import net.micode.notes.data.Notes.NoteColumns;
|
||||||
|
|
||||||
|
|
||||||
|
public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
||||||
|
private static final String DB_NAME = "note.db";
|
||||||
|
|
||||||
|
private static final int DB_VERSION = 5;
|
||||||
|
|
||||||
|
public interface TABLE {
|
||||||
|
public static final String NOTE = "note";
|
||||||
|
|
||||||
|
public static final String DATA = "data";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String TAG = "NotesDatabaseHelper";
|
||||||
|
|
||||||
|
private static NotesDatabaseHelper mInstance;
|
||||||
|
|
||||||
|
private static final String CREATE_NOTE_TABLE_SQL =
|
||||||
|
"CREATE TABLE " + TABLE.NOTE + "(" +
|
||||||
|
NoteColumns.ID + " INTEGER PRIMARY KEY," +
|
||||||
|
NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
||||||
|
NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
||||||
|
NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," +
|
||||||
|
NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," +
|
||||||
|
NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
|
||||||
|
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.IS_PRIVATE + " INTEGER NOT NULL DEFAULT 0" +
|
||||||
|
")";
|
||||||
|
|
||||||
|
private static final String CREATE_DATA_TABLE_SQL =
|
||||||
|
"CREATE TABLE " + TABLE.DATA + "(" +
|
||||||
|
DataColumns.ID + " INTEGER PRIMARY KEY," +
|
||||||
|
DataColumns.MIME_TYPE + " TEXT NOT NULL," +
|
||||||
|
DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," +
|
||||||
|
NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
||||||
|
NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
||||||
|
DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," +
|
||||||
|
DataColumns.DATA1 + " INTEGER," +
|
||||||
|
DataColumns.DATA2 + " INTEGER," +
|
||||||
|
DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +
|
||||||
|
DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +
|
||||||
|
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
|
||||||
|
")";
|
||||||
|
|
||||||
|
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
|
||||||
|
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
|
||||||
|
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase folder's note count when move note to the folder
|
||||||
|
*/
|
||||||
|
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
|
||||||
|
"CREATE TRIGGER increase_folder_count_on_update "+
|
||||||
|
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
|
||||||
|
" BEGIN " +
|
||||||
|
" UPDATE " + TABLE.NOTE +
|
||||||
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
|
||||||
|
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrease folder's note count when move note from folder
|
||||||
|
*/
|
||||||
|
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
|
||||||
|
"CREATE TRIGGER decrease_folder_count_on_update " +
|
||||||
|
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
|
||||||
|
" BEGIN " +
|
||||||
|
" UPDATE " + TABLE.NOTE +
|
||||||
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
|
||||||
|
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
|
||||||
|
" AND " + NoteColumns.NOTES_COUNT + ">0" + ";" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase folder's note count when insert new note to the folder
|
||||||
|
*/
|
||||||
|
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
|
||||||
|
"CREATE TRIGGER increase_folder_count_on_insert " +
|
||||||
|
" AFTER INSERT ON " + TABLE.NOTE +
|
||||||
|
" BEGIN " +
|
||||||
|
" UPDATE " + TABLE.NOTE +
|
||||||
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
|
||||||
|
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrease folder's note count when delete note from the folder
|
||||||
|
*/
|
||||||
|
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
|
||||||
|
"CREATE TRIGGER decrease_folder_count_on_delete " +
|
||||||
|
" AFTER DELETE ON " + TABLE.NOTE +
|
||||||
|
" BEGIN " +
|
||||||
|
" UPDATE " + TABLE.NOTE +
|
||||||
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
|
||||||
|
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
|
||||||
|
" AND " + NoteColumns.NOTES_COUNT + ">0;" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update note's content when insert data with type {@link DataConstants#NOTE}
|
||||||
|
*/
|
||||||
|
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
|
||||||
|
"CREATE TRIGGER update_note_content_on_insert " +
|
||||||
|
" AFTER INSERT ON " + TABLE.DATA +
|
||||||
|
" WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
||||||
|
" BEGIN" +
|
||||||
|
" UPDATE " + TABLE.NOTE +
|
||||||
|
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
|
||||||
|
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update note's content when data with {@link DataConstants#NOTE} type has changed
|
||||||
|
*/
|
||||||
|
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
|
||||||
|
"CREATE TRIGGER update_note_content_on_update " +
|
||||||
|
" AFTER UPDATE ON " + TABLE.DATA +
|
||||||
|
" WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
||||||
|
" BEGIN" +
|
||||||
|
" UPDATE " + TABLE.NOTE +
|
||||||
|
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
|
||||||
|
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update note's content when data with {@link DataConstants#NOTE} type has deleted
|
||||||
|
*/
|
||||||
|
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
|
||||||
|
"CREATE TRIGGER update_note_content_on_delete " +
|
||||||
|
" AFTER delete ON " + TABLE.DATA +
|
||||||
|
" WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
||||||
|
" BEGIN" +
|
||||||
|
" UPDATE " + TABLE.NOTE +
|
||||||
|
" SET " + NoteColumns.SNIPPET + "=''" +
|
||||||
|
" WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete datas belong to note which has been deleted
|
||||||
|
*/
|
||||||
|
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
|
||||||
|
"CREATE TRIGGER delete_data_on_delete " +
|
||||||
|
" AFTER DELETE ON " + TABLE.NOTE +
|
||||||
|
" BEGIN" +
|
||||||
|
" DELETE FROM " + TABLE.DATA +
|
||||||
|
" WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete notes belong to folder which has been deleted
|
||||||
|
*/
|
||||||
|
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
|
||||||
|
"CREATE TRIGGER folder_delete_notes_on_delete " +
|
||||||
|
" AFTER DELETE ON " + TABLE.NOTE +
|
||||||
|
" BEGIN" +
|
||||||
|
" DELETE FROM " + TABLE.NOTE +
|
||||||
|
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move notes belong to folder which has been moved to trash folder
|
||||||
|
*/
|
||||||
|
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
|
||||||
|
"CREATE TRIGGER folder_move_notes_on_trash " +
|
||||||
|
" AFTER UPDATE ON " + TABLE.NOTE +
|
||||||
|
" WHEN new." + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
|
||||||
|
" BEGIN" +
|
||||||
|
" UPDATE " + TABLE.NOTE +
|
||||||
|
" SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
|
||||||
|
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
|
||||||
|
" END";
|
||||||
|
|
||||||
|
private static final String CREATE_PRIVACY_PASSWORD_TABLE_SQL =
|
||||||
|
"CREATE TABLE privacy_password(" +
|
||||||
|
"id INTEGER PRIMARY KEY," +
|
||||||
|
"password TEXT NOT NULL," +
|
||||||
|
"created_date INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)" +
|
||||||
|
")";
|
||||||
|
|
||||||
|
public NotesDatabaseHelper(Context context) {
|
||||||
|
super(context, DB_NAME, null, DB_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createNoteTable(SQLiteDatabase db) {
|
||||||
|
db.execSQL(CREATE_NOTE_TABLE_SQL);
|
||||||
|
reCreateNoteTableTriggers(db);
|
||||||
|
createSystemFolder(db);
|
||||||
|
Log.d(TAG, "note table has been created");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_delete");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS delete_data_on_delete");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_insert");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash");
|
||||||
|
|
||||||
|
db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);
|
||||||
|
db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);
|
||||||
|
db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER);
|
||||||
|
db.execSQL(NOTE_DELETE_DATA_ON_DELETE_TRIGGER);
|
||||||
|
db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER);
|
||||||
|
db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER);
|
||||||
|
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createSystemFolder(SQLiteDatabase db) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* call record foler for call notes
|
||||||
|
*/
|
||||||
|
values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER);
|
||||||
|
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
|
||||||
|
db.insert(TABLE.NOTE, null, values);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* root folder which is default folder
|
||||||
|
*/
|
||||||
|
values.clear();
|
||||||
|
values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER);
|
||||||
|
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
|
||||||
|
db.insert(TABLE.NOTE, null, values);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* temporary folder which is used for moving note
|
||||||
|
*/
|
||||||
|
values.clear();
|
||||||
|
values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER);
|
||||||
|
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
|
||||||
|
db.insert(TABLE.NOTE, null, values);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create trash folder
|
||||||
|
*/
|
||||||
|
values.clear();
|
||||||
|
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
|
||||||
|
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
|
||||||
|
db.insert(TABLE.NOTE, null, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createDataTable(SQLiteDatabase db) {
|
||||||
|
db.execSQL(CREATE_DATA_TABLE_SQL);
|
||||||
|
reCreateDataTableTriggers(db);
|
||||||
|
db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);
|
||||||
|
Log.d(TAG, "data table has been created");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reCreateDataTableTriggers(SQLiteDatabase db) {
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_delete");
|
||||||
|
|
||||||
|
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER);
|
||||||
|
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER);
|
||||||
|
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
|
||||||
|
}
|
||||||
|
|
||||||
|
static synchronized NotesDatabaseHelper getInstance(Context context) {
|
||||||
|
if (mInstance == null) {
|
||||||
|
mInstance = new NotesDatabaseHelper(context);
|
||||||
|
}
|
||||||
|
return mInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
createNoteTable(db);
|
||||||
|
createDataTable(db);
|
||||||
|
createPrivacyPasswordTable(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createPrivacyPasswordTable(SQLiteDatabase db) {
|
||||||
|
db.execSQL(CREATE_PRIVACY_PASSWORD_TABLE_SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
if (oldVersion < 2) {
|
||||||
|
upgradeToV2(db);
|
||||||
|
}
|
||||||
|
if (oldVersion < 3) {
|
||||||
|
upgradeToV3(db);
|
||||||
|
}
|
||||||
|
if (oldVersion < 4) {
|
||||||
|
upgradeToV4(db);
|
||||||
|
}
|
||||||
|
if (oldVersion < 5) {
|
||||||
|
upgradeToV5(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upgradeToV2(SQLiteDatabase db) {
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);
|
||||||
|
db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA);
|
||||||
|
createNoteTable(db);
|
||||||
|
createDataTable(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upgradeToV3(SQLiteDatabase db) {
|
||||||
|
// drop unused triggers
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_delete");
|
||||||
|
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update");
|
||||||
|
// add a column for gtask id
|
||||||
|
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID
|
||||||
|
+ " TEXT NOT NULL DEFAULT ''");
|
||||||
|
// add a trash system folder
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
|
||||||
|
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
|
||||||
|
db.insert(TABLE.NOTE, null, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upgradeToV4(SQLiteDatabase db) {
|
||||||
|
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
|
||||||
|
+ " INTEGER NOT NULL DEFAULT 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upgradeToV5(SQLiteDatabase db) {
|
||||||
|
// 添加隐私相关字段
|
||||||
|
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.IS_PRIVATE + " INTEGER NOT NULL DEFAULT 0");
|
||||||
|
// 创建隐私密码表
|
||||||
|
db.execSQL(CREATE_PRIVACY_PASSWORD_TABLE_SQL);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package net.micode.notes.data;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
public class PrivacyPasswordManager {
|
||||||
|
private static final String TABLE_NAME = "privacy_password";
|
||||||
|
private static final String COLUMN_ID = "id";
|
||||||
|
private static final String COLUMN_PASSWORD = "password";
|
||||||
|
private static final String COLUMN_CREATED_DATE = "created_date";
|
||||||
|
|
||||||
|
private NotesDatabaseHelper mDbHelper;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
public PrivacyPasswordManager(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
mDbHelper = NotesDatabaseHelper.getInstance(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置隐私密码
|
||||||
|
* @param password 密码
|
||||||
|
* @return 是否设置成功
|
||||||
|
*/
|
||||||
|
public boolean setPassword(String password) {
|
||||||
|
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(COLUMN_PASSWORD, password);
|
||||||
|
|
||||||
|
// 先删除旧的密码
|
||||||
|
db.delete(TABLE_NAME, null, null);
|
||||||
|
|
||||||
|
// 插入新密码
|
||||||
|
long result = db.insert(TABLE_NAME, null, values);
|
||||||
|
return result != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证密码是否正确
|
||||||
|
* @param password 要验证的密码
|
||||||
|
* @return 密码是否正确
|
||||||
|
*/
|
||||||
|
public boolean verifyPassword(String password) {
|
||||||
|
SQLiteDatabase db = mDbHelper.getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_PASSWORD}, null, null, null, null, null);
|
||||||
|
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
String storedPassword = cursor.getString(cursor.getColumnIndex(COLUMN_PASSWORD));
|
||||||
|
cursor.close();
|
||||||
|
return storedPassword.equals(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否已设置密码
|
||||||
|
* @return 是否已设置密码
|
||||||
|
*/
|
||||||
|
public boolean hasPassword() {
|
||||||
|
SQLiteDatabase db = mDbHelper.getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_ID}, null, null, null, null, null);
|
||||||
|
boolean hasPassword = cursor != null && cursor.getCount() > 0;
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return hasPassword;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,141 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.gtask.remote;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
import net.micode.notes.ui.NotesListActivity;
|
||||||
|
import net.micode.notes.ui.NotesPreferenceActivity;
|
||||||
|
|
||||||
|
|
||||||
|
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
|
||||||
|
|
||||||
|
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;
|
||||||
|
|
||||||
|
public interface OnCompleteListener {
|
||||||
|
void onComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
private NotificationManager mNotifiManager;
|
||||||
|
|
||||||
|
private GTaskManager mTaskManager;
|
||||||
|
|
||||||
|
private OnCompleteListener mOnCompleteListener;
|
||||||
|
|
||||||
|
public GTaskASyncTask(Context context, OnCompleteListener listener) {
|
||||||
|
mContext = context;
|
||||||
|
mOnCompleteListener = listener;
|
||||||
|
mNotifiManager = (NotificationManager) mContext
|
||||||
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
mTaskManager = GTaskManager.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelSync() {
|
||||||
|
mTaskManager.cancelSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void publishProgess(String message) {
|
||||||
|
publishProgress(new String[] {
|
||||||
|
message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//private void showNotification(int tickerId, String content) {
|
||||||
|
//Notification notification = new Notification(R.drawable.notification, mContext
|
||||||
|
//.getString(tickerId), System.currentTimeMillis());
|
||||||
|
// notification.defaults = Notification.DEFAULT_LIGHTS;
|
||||||
|
// notification.flags = Notification.FLAG_AUTO_CANCEL;
|
||||||
|
// PendingIntent pendingIntent;
|
||||||
|
// if (tickerId != R.string.ticker_success) {
|
||||||
|
// pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
|
||||||
|
// NotesPreferenceActivity.class), 0);
|
||||||
|
|
||||||
|
// } else {
|
||||||
|
// pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
|
||||||
|
// NotesListActivity.class), 0);
|
||||||
|
// }
|
||||||
|
// notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
|
||||||
|
// pendingIntent);
|
||||||
|
// mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
|
||||||
|
//}
|
||||||
|
private void showNotification(int tickerId, String content) {
|
||||||
|
PendingIntent pendingIntent;
|
||||||
|
if (tickerId != R.string.ticker_success) {
|
||||||
|
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
|
||||||
|
NotesPreferenceActivity.class), PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
} else {
|
||||||
|
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
|
||||||
|
NotesListActivity.class), PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
}
|
||||||
|
Notification.Builder builder = new Notification.Builder(mContext)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.setContentTitle(mContext.getString(R.string.app_name))
|
||||||
|
.setContentText(content)
|
||||||
|
.setContentIntent(pendingIntent)
|
||||||
|
.setWhen(System.currentTimeMillis())
|
||||||
|
.setOngoing(true);
|
||||||
|
Notification notification=builder.getNotification();
|
||||||
|
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Integer doInBackground(Void... unused) {
|
||||||
|
publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity
|
||||||
|
.getSyncAccountName(mContext)));
|
||||||
|
return mTaskManager.sync(mContext, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(String... progress) {
|
||||||
|
showNotification(R.string.ticker_syncing, progress[0]);
|
||||||
|
if (mContext instanceof GTaskSyncService) {
|
||||||
|
((GTaskSyncService) mContext).sendBroadcast(progress[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Integer result) {
|
||||||
|
if (result == GTaskManager.STATE_SUCCESS) {
|
||||||
|
showNotification(R.string.ticker_success, mContext.getString(
|
||||||
|
R.string.success_sync_account, mTaskManager.getSyncAccount()));
|
||||||
|
NotesPreferenceActivity.setLastSyncTime(mContext, System.currentTimeMillis());
|
||||||
|
} else if (result == GTaskManager.STATE_NETWORK_ERROR) {
|
||||||
|
showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_network));
|
||||||
|
} else if (result == GTaskManager.STATE_INTERNAL_ERROR) {
|
||||||
|
showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_internal));
|
||||||
|
} else if (result == GTaskManager.STATE_SYNC_CANCELLED) {
|
||||||
|
showNotification(R.string.ticker_cancel, mContext
|
||||||
|
.getString(R.string.error_sync_cancelled));
|
||||||
|
}
|
||||||
|
if (mOnCompleteListener != null) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
mOnCompleteListener.onComplete();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,375 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.model;
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetManager;
|
||||||
|
import android.content.ContentUris;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
import net.micode.notes.data.Notes.CallNote;
|
||||||
|
import net.micode.notes.data.Notes.DataColumns;
|
||||||
|
import net.micode.notes.data.Notes.DataConstants;
|
||||||
|
import net.micode.notes.data.Notes.NoteColumns;
|
||||||
|
import net.micode.notes.data.Notes.TextNote;
|
||||||
|
import net.micode.notes.tool.ResourceParser.NoteBgResources;
|
||||||
|
|
||||||
|
|
||||||
|
public class WorkingNote {
|
||||||
|
// Note for the working note
|
||||||
|
private Note mNote;
|
||||||
|
// Note Id
|
||||||
|
private long mNoteId;
|
||||||
|
// Note content
|
||||||
|
public String mContent;
|
||||||
|
// Note mode
|
||||||
|
private int mMode;
|
||||||
|
|
||||||
|
private long mAlertDate;
|
||||||
|
|
||||||
|
private long mModifiedDate;
|
||||||
|
|
||||||
|
private int mBgColorId;
|
||||||
|
|
||||||
|
private int mWidgetId;
|
||||||
|
|
||||||
|
private int mWidgetType;
|
||||||
|
|
||||||
|
private long mFolderId;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
private static final String TAG = "WorkingNote";
|
||||||
|
|
||||||
|
private boolean mIsDeleted;
|
||||||
|
|
||||||
|
private NoteSettingChangedListener mNoteSettingStatusListener;
|
||||||
|
|
||||||
|
private boolean mIsPrivate = false;
|
||||||
|
|
||||||
|
public static final String[] DATA_PROJECTION = new String[] {
|
||||||
|
DataColumns.ID,
|
||||||
|
DataColumns.CONTENT,
|
||||||
|
DataColumns.MIME_TYPE,
|
||||||
|
DataColumns.DATA1,
|
||||||
|
DataColumns.DATA2,
|
||||||
|
DataColumns.DATA3,
|
||||||
|
DataColumns.DATA4,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final String[] NOTE_PROJECTION = new String[] {
|
||||||
|
NoteColumns.PARENT_ID,
|
||||||
|
NoteColumns.ALERTED_DATE,
|
||||||
|
NoteColumns.BG_COLOR_ID,
|
||||||
|
NoteColumns.WIDGET_ID,
|
||||||
|
NoteColumns.WIDGET_TYPE,
|
||||||
|
NoteColumns.MODIFIED_DATE
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final int DATA_ID_COLUMN = 0;
|
||||||
|
|
||||||
|
private static final int DATA_CONTENT_COLUMN = 1;
|
||||||
|
|
||||||
|
private static final int DATA_MIME_TYPE_COLUMN = 2;
|
||||||
|
|
||||||
|
private static final int DATA_MODE_COLUMN = 3;
|
||||||
|
|
||||||
|
private static final int NOTE_PARENT_ID_COLUMN = 0;
|
||||||
|
|
||||||
|
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
|
||||||
|
|
||||||
|
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
|
||||||
|
|
||||||
|
private static final int NOTE_WIDGET_ID_COLUMN = 3;
|
||||||
|
|
||||||
|
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
|
||||||
|
|
||||||
|
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
|
||||||
|
|
||||||
|
// New note construct
|
||||||
|
private WorkingNote(Context context, long folderId) {
|
||||||
|
mContext = context;
|
||||||
|
mAlertDate = 0;
|
||||||
|
mModifiedDate = System.currentTimeMillis();
|
||||||
|
mFolderId = folderId;
|
||||||
|
mNote = new Note();
|
||||||
|
mNoteId = 0;
|
||||||
|
mIsDeleted = false;
|
||||||
|
mMode = 0;
|
||||||
|
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Existing note construct
|
||||||
|
private WorkingNote(Context context, long noteId, long folderId) {
|
||||||
|
mContext = context;
|
||||||
|
mNoteId = noteId;
|
||||||
|
mFolderId = folderId;
|
||||||
|
mIsDeleted = false;
|
||||||
|
mNote = new Note();
|
||||||
|
loadNote();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadNote() {
|
||||||
|
Cursor cursor = mContext.getContentResolver().query(
|
||||||
|
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
|
||||||
|
null, null);
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
|
||||||
|
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
|
||||||
|
mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
|
||||||
|
mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
|
||||||
|
mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
|
||||||
|
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "No note with id:" + mNoteId);
|
||||||
|
throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
|
||||||
|
}
|
||||||
|
loadNoteData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadNoteData() {
|
||||||
|
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
|
||||||
|
DataColumns.NOTE_ID + "=?", new String[] {
|
||||||
|
String.valueOf(mNoteId)
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
|
||||||
|
if (DataConstants.NOTE.equals(type)) {
|
||||||
|
mContent = cursor.getString(DATA_CONTENT_COLUMN);
|
||||||
|
mMode = cursor.getInt(DATA_MODE_COLUMN);
|
||||||
|
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
|
||||||
|
} else if (DataConstants.CALL_NOTE.equals(type)) {
|
||||||
|
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Wrong note type with type:" + type);
|
||||||
|
}
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "No data with id:" + mNoteId);
|
||||||
|
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
|
||||||
|
int widgetType, int defaultBgColorId) {
|
||||||
|
WorkingNote note = new WorkingNote(context, folderId);
|
||||||
|
note.setBgColorId(defaultBgColorId);
|
||||||
|
note.setWidgetId(widgetId);
|
||||||
|
note.setWidgetType(widgetType);
|
||||||
|
return note;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorkingNote load(Context context, long id) {
|
||||||
|
return new WorkingNote(context, id, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean saveNote() {
|
||||||
|
if (isWorthSaving()) {
|
||||||
|
if (!existInDatabase()) {
|
||||||
|
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
|
||||||
|
Log.e(TAG, "Create new note fail with id:" + mNoteId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mNote.syncNote(mContext, mNoteId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update widget content if there exist any widget of this note
|
||||||
|
*/
|
||||||
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
||||||
|
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
|
||||||
|
&& mNoteSettingStatusListener != null) {
|
||||||
|
mNoteSettingStatusListener.onWidgetChanged();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean existInDatabase() {
|
||||||
|
return mNoteId > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isWorthSaving() {
|
||||||
|
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|
||||||
|
|| (existInDatabase() && !mNote.isLocalModified())) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
|
||||||
|
mNoteSettingStatusListener = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlertDate(long date, boolean set) {
|
||||||
|
if (date != mAlertDate) {
|
||||||
|
mAlertDate = date;
|
||||||
|
mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate));
|
||||||
|
}
|
||||||
|
if (mNoteSettingStatusListener != null) {
|
||||||
|
mNoteSettingStatusListener.onClockAlertChanged(date, set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void markDeleted(boolean mark) {
|
||||||
|
mIsDeleted = mark;
|
||||||
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
||||||
|
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
|
||||||
|
mNoteSettingStatusListener.onWidgetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBgColorId(int id) {
|
||||||
|
if (id != mBgColorId) {
|
||||||
|
mBgColorId = id;
|
||||||
|
if (mNoteSettingStatusListener != null) {
|
||||||
|
mNoteSettingStatusListener.onBackgroundColorChanged();
|
||||||
|
}
|
||||||
|
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckListMode(int mode) {
|
||||||
|
if (mMode != mode) {
|
||||||
|
if (mNoteSettingStatusListener != null) {
|
||||||
|
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
|
||||||
|
}
|
||||||
|
mMode = mode;
|
||||||
|
mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidgetType(int type) {
|
||||||
|
if (type != mWidgetType) {
|
||||||
|
mWidgetType = type;
|
||||||
|
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidgetId(int id) {
|
||||||
|
if (id != mWidgetId) {
|
||||||
|
mWidgetId = id;
|
||||||
|
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorkingText(String text) {
|
||||||
|
if (!TextUtils.equals(mContent, text)) {
|
||||||
|
mContent = text;
|
||||||
|
mNote.setTextData(DataColumns.CONTENT, mContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void convertToCallNote(String phoneNumber, long callDate) {
|
||||||
|
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
|
||||||
|
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
|
||||||
|
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasClockAlert() {
|
||||||
|
return (mAlertDate > 0 ? true : false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return mContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAlertDate() {
|
||||||
|
return mAlertDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getModifiedDate() {
|
||||||
|
return mModifiedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBgColorResId() {
|
||||||
|
return NoteBgResources.getNoteBgResource(mBgColorId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBgColorId() {
|
||||||
|
return mBgColorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTitleBgResId() {
|
||||||
|
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCheckListMode() {
|
||||||
|
return mMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getNoteId() {
|
||||||
|
return mNoteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFolderId() {
|
||||||
|
return mFolderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidgetId() {
|
||||||
|
return mWidgetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidgetType() {
|
||||||
|
return mWidgetType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivate(boolean isPrivate) {
|
||||||
|
mIsPrivate = isPrivate;
|
||||||
|
mNote.setNoteValue(Notes.NoteColumns.IS_PRIVATE, isPrivate ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface NoteSettingChangedListener {
|
||||||
|
/**
|
||||||
|
* Called when the background color of current note has just changed
|
||||||
|
*/
|
||||||
|
void onBackgroundColorChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when user set clock
|
||||||
|
*/
|
||||||
|
void onClockAlertChanged(long date, boolean set);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call when user create note from widget
|
||||||
|
*/
|
||||||
|
void onWidgetChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call when switch between check list mode and normal mode
|
||||||
|
* @param oldMode is previous mode before change
|
||||||
|
* @param newMode is new mode
|
||||||
|
*/
|
||||||
|
void onCheckListModeChanged(int oldMode, int newMode);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,301 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.tool;
|
||||||
|
|
||||||
|
import android.content.ContentProviderOperation;
|
||||||
|
import android.content.ContentProviderResult;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentUris;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.OperationApplicationException;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
import net.micode.notes.data.Notes.CallNote;
|
||||||
|
import net.micode.notes.data.Notes.NoteColumns;
|
||||||
|
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
|
||||||
|
public class DataUtils {
|
||||||
|
public static final String TAG = "DataUtils";
|
||||||
|
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
|
||||||
|
if (ids == null) {
|
||||||
|
Log.d(TAG, "the ids is null");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (ids.size() == 0) {
|
||||||
|
Log.d(TAG, "no id is in the hashset");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
|
||||||
|
for (long id : ids) {
|
||||||
|
if(id == Notes.ID_ROOT_FOLDER) {
|
||||||
|
Log.e(TAG, "Don't delete system folder root");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ContentProviderOperation.Builder builder = ContentProviderOperation
|
||||||
|
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
|
||||||
|
operationList.add(builder.build());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
|
||||||
|
if (results == null || results.length == 0 || results[0] == null) {
|
||||||
|
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
||||||
|
} catch (OperationApplicationException e) {
|
||||||
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(NoteColumns.PARENT_ID, desFolderId);
|
||||||
|
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
|
||||||
|
values.put(NoteColumns.LOCAL_MODIFIED, 1);
|
||||||
|
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
|
||||||
|
long folderId) {
|
||||||
|
if (ids == null) {
|
||||||
|
Log.d(TAG, "the ids is null");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
|
||||||
|
for (long id : ids) {
|
||||||
|
ContentProviderOperation.Builder builder = ContentProviderOperation
|
||||||
|
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
|
||||||
|
builder.withValue(NoteColumns.PARENT_ID, folderId);
|
||||||
|
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
|
||||||
|
operationList.add(builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
|
||||||
|
if (results == null || results.length == 0 || results[0] == null) {
|
||||||
|
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
||||||
|
} catch (OperationApplicationException e) {
|
||||||
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
|
||||||
|
*/
|
||||||
|
public static int getUserFolderCount(ContentResolver resolver) {
|
||||||
|
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
|
||||||
|
new String[] { "COUNT(*)" },
|
||||||
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
|
||||||
|
new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)},
|
||||||
|
null);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
if(cursor != null) {
|
||||||
|
if(cursor.moveToFirst()) {
|
||||||
|
try {
|
||||||
|
count = cursor.getInt(0);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
Log.e(TAG, "get folder count failed:" + e.toString());
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
|
||||||
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
|
||||||
|
null,
|
||||||
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
|
||||||
|
new String [] {String.valueOf(type)},
|
||||||
|
null);
|
||||||
|
|
||||||
|
boolean exist = false;
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.getCount() > 0) {
|
||||||
|
exist = true;
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
|
||||||
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
|
||||||
|
null, null, null, null);
|
||||||
|
|
||||||
|
boolean exist = false;
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.getCount() > 0) {
|
||||||
|
exist = true;
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
|
||||||
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
|
||||||
|
null, null, null, null);
|
||||||
|
|
||||||
|
boolean exist = false;
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.getCount() > 0) {
|
||||||
|
exist = true;
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
|
||||||
|
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
|
||||||
|
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
|
||||||
|
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
|
||||||
|
" AND " + NoteColumns.SNIPPET + "=?",
|
||||||
|
new String[] { name }, null);
|
||||||
|
boolean exist = false;
|
||||||
|
if(cursor != null) {
|
||||||
|
if(cursor.getCount() > 0) {
|
||||||
|
exist = true;
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
|
||||||
|
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
|
||||||
|
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
|
||||||
|
NoteColumns.PARENT_ID + "=?",
|
||||||
|
new String[] { String.valueOf(folderId) },
|
||||||
|
null);
|
||||||
|
|
||||||
|
HashSet<AppWidgetAttribute> set = null;
|
||||||
|
if (c != null) {
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
set = new HashSet<AppWidgetAttribute>();
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
AppWidgetAttribute widget = new AppWidgetAttribute();
|
||||||
|
widget.widgetId = c.getInt(0);
|
||||||
|
widget.widgetType = c.getInt(1);
|
||||||
|
set.add(widget);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
Log.e(TAG, e.toString());
|
||||||
|
}
|
||||||
|
} while (c.moveToNext());
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
|
||||||
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
||||||
|
new String [] { CallNote.PHONE_NUMBER },
|
||||||
|
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
|
||||||
|
new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
try {
|
||||||
|
return cursor.getString(0);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
Log.e(TAG, "Get call number fails " + e.toString());
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
|
||||||
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
||||||
|
new String [] { CallNote.NOTE_ID },
|
||||||
|
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
|
||||||
|
+ CallNote.PHONE_NUMBER + ",?)",
|
||||||
|
new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
try {
|
||||||
|
return cursor.getLong(0);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
Log.e(TAG, "Get call note id fails " + e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSnippetById(ContentResolver resolver, long noteId) {
|
||||||
|
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
|
||||||
|
new String [] { NoteColumns.SNIPPET },
|
||||||
|
NoteColumns.ID + "=?",
|
||||||
|
new String [] { String.valueOf(noteId)},
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
String snippet = "";
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
snippet = cursor.getString(0);
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
return snippet;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Note is not found with id: " + noteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFormattedSnippet(String snippet) {
|
||||||
|
if (snippet != null) {
|
||||||
|
snippet = snippet.trim();
|
||||||
|
int index = snippet.indexOf('\n');
|
||||||
|
if (index != -1) {
|
||||||
|
snippet = snippet.substring(0, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return snippet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String formatDateTime(Context context, long time) {
|
||||||
|
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm", java.util.Locale.getDefault());
|
||||||
|
return sdf.format(new java.util.Date(time));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,151 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
|
import android.content.DialogInterface.OnDismissListener;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
import net.micode.notes.tool.DataUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
|
||||||
|
private long mNoteId;
|
||||||
|
private String mSnippet;
|
||||||
|
private static final int SNIPPET_PREW_MAX_LEN = 60;
|
||||||
|
MediaPlayer mPlayer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
|
||||||
|
final Window win = getWindow();
|
||||||
|
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||||
|
|
||||||
|
if (!isScreenOn()) {
|
||||||
|
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||||
|
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
||||||
|
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
||||||
|
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
|
||||||
|
try {
|
||||||
|
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
|
||||||
|
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
|
||||||
|
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
|
||||||
|
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
|
||||||
|
: mSnippet;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mPlayer = new MediaPlayer();
|
||||||
|
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
|
||||||
|
showActionDialog();
|
||||||
|
playAlarmSound();
|
||||||
|
} else {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isScreenOn() {
|
||||||
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
|
return pm.isScreenOn();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void playAlarmSound() {
|
||||||
|
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
||||||
|
|
||||||
|
int silentModeStreams = Settings.System.getInt(getContentResolver(),
|
||||||
|
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
|
||||||
|
|
||||||
|
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
|
||||||
|
mPlayer.setAudioStreamType(silentModeStreams);
|
||||||
|
} else {
|
||||||
|
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mPlayer.setDataSource(this, url);
|
||||||
|
mPlayer.prepare();
|
||||||
|
mPlayer.setLooping(true);
|
||||||
|
mPlayer.start();
|
||||||
|
} catch (IllegalArgumentException | SecurityException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showActionDialog() {
|
||||||
|
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
||||||
|
dialog.setTitle(R.string.app_name);
|
||||||
|
dialog.setMessage(mSnippet);
|
||||||
|
dialog.setPositiveButton(R.string.notealert_ok, this);
|
||||||
|
if (isScreenOn()) {
|
||||||
|
dialog.setNegativeButton(R.string.notealert_enter, this);
|
||||||
|
}
|
||||||
|
dialog.show().setOnDismissListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if (which == DialogInterface.BUTTON_NEGATIVE) {
|
||||||
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
||||||
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
|
intent.putExtra(Intent.EXTRA_UID, mNoteId);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
stopAlarmSound();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopAlarmSound() {
|
||||||
|
if (mPlayer != null) {
|
||||||
|
mPlayer.stop();
|
||||||
|
mPlayer.release();
|
||||||
|
mPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ContentUris;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.database.Cursor;
|
||||||
|
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
import net.micode.notes.data.Notes.NoteColumns;
|
||||||
|
|
||||||
|
|
||||||
|
public class AlarmInitReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
private static final String [] PROJECTION = new String [] {
|
||||||
|
NoteColumns.ID,
|
||||||
|
NoteColumns.ALERTED_DATE
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final int COLUMN_ID = 0;
|
||||||
|
private static final int COLUMN_ALERTED_DATE = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
long currentDate = System.currentTimeMillis();
|
||||||
|
Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
|
||||||
|
PROJECTION,
|
||||||
|
NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,
|
||||||
|
new String[] { String.valueOf(currentDate) },
|
||||||
|
null);
|
||||||
|
|
||||||
|
if (c != null) {
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
long alertDate = c.getLong(COLUMN_ALERTED_DATE);
|
||||||
|
Intent sender = new Intent(context, AlarmReceiver.class);
|
||||||
|
sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID)));
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
AlarmManager alermManager = (AlarmManager) context
|
||||||
|
.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);
|
||||||
|
} while (c.moveToNext());
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.content.AsyncQueryHandler;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.database.Cursor;
|
||||||
|
|
||||||
|
public class BackgroundQueryHandler extends AsyncQueryHandler {
|
||||||
|
public interface QueryCompleteListener {
|
||||||
|
void onQueryComplete(int token, Object cookie, Cursor cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private QueryCompleteListener listener;
|
||||||
|
|
||||||
|
public BackgroundQueryHandler(ContentResolver contentResolver) {
|
||||||
|
super(contentResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueryCompleteListener(QueryCompleteListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onQueryComplete(token, cookie, cursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
public class ListEditState {
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.text.Layout;
|
||||||
|
import android.text.Selection;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.style.URLSpan;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.ContextMenu;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.MenuItem.OnMenuItemClickListener;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class NoteEditText extends androidx.appcompat.widget.AppCompatEditText {
|
||||||
|
private static final String TAG = "NoteEditText";
|
||||||
|
private int mIndex;
|
||||||
|
private int mSelectionStartBeforeDelete;
|
||||||
|
|
||||||
|
private static final String SCHEME_TEL = "tel:" ;
|
||||||
|
private static final String SCHEME_HTTP = "http:" ;
|
||||||
|
private static final String SCHEME_EMAIL = "mailto:" ;
|
||||||
|
|
||||||
|
private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>();
|
||||||
|
static {
|
||||||
|
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel);
|
||||||
|
sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web);
|
||||||
|
sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call by the {@link NoteEditActivity} to delete or add edit text
|
||||||
|
*/
|
||||||
|
public interface OnTextViewChangeListener {
|
||||||
|
/**
|
||||||
|
* Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens
|
||||||
|
* and the text is null
|
||||||
|
*/
|
||||||
|
void onEditTextDelete(int index, String text);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER}
|
||||||
|
* happen
|
||||||
|
*/
|
||||||
|
void onEditTextEnter(int index, String text);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide or show item option when text change
|
||||||
|
*/
|
||||||
|
void onTextChange(int index, boolean hasText);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OnTextViewChangeListener mOnTextViewChangeListener;
|
||||||
|
|
||||||
|
public NoteEditText(Context context) {
|
||||||
|
super(context, null);
|
||||||
|
mIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndex(int index) {
|
||||||
|
mIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
|
||||||
|
mOnTextViewChangeListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoteEditText(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs, android.R.attr.editTextStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
super(context, attrs, defStyle);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
switch (event.getAction()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
|
||||||
|
int x = (int) event.getX();
|
||||||
|
int y = (int) event.getY();
|
||||||
|
x -= getTotalPaddingLeft();
|
||||||
|
y -= getTotalPaddingTop();
|
||||||
|
x += getScrollX();
|
||||||
|
y += getScrollY();
|
||||||
|
|
||||||
|
Layout layout = getLayout();
|
||||||
|
int line = layout.getLineForVertical(y);
|
||||||
|
int off = layout.getOffsetForHorizontal(line, x);
|
||||||
|
Selection.setSelection(getText(), off);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
switch (keyCode) {
|
||||||
|
case KeyEvent.KEYCODE_ENTER:
|
||||||
|
if (mOnTextViewChangeListener != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case KeyEvent.KEYCODE_DEL:
|
||||||
|
mSelectionStartBeforeDelete = getSelectionStart();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
|
switch(keyCode) {
|
||||||
|
case KeyEvent.KEYCODE_DEL:
|
||||||
|
if (mOnTextViewChangeListener != null) {
|
||||||
|
if (0 == mSelectionStartBeforeDelete && mIndex != 0) {
|
||||||
|
mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "OnTextViewChangeListener was not seted");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case KeyEvent.KEYCODE_ENTER:
|
||||||
|
if (mOnTextViewChangeListener != null) {
|
||||||
|
int selectionStart = getSelectionStart();
|
||||||
|
String text = getText().subSequence(selectionStart, length()).toString();
|
||||||
|
setText(getText().subSequence(0, selectionStart));
|
||||||
|
mOnTextViewChangeListener.onEditTextEnter(mIndex + 1, text);
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "OnTextViewChangeListener was not seted");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return super.onKeyUp(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
|
||||||
|
if (mOnTextViewChangeListener != null) {
|
||||||
|
if (!focused && TextUtils.isEmpty(getText())) {
|
||||||
|
mOnTextViewChangeListener.onTextChange(mIndex, false);
|
||||||
|
} else {
|
||||||
|
mOnTextViewChangeListener.onTextChange(mIndex, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onFocusChanged(focused, direction, previouslyFocusedRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreateContextMenu(ContextMenu menu) {
|
||||||
|
if (getText() instanceof Spanned) {
|
||||||
|
int selStart = getSelectionStart();
|
||||||
|
int selEnd = getSelectionEnd();
|
||||||
|
|
||||||
|
int min = Math.min(selStart, selEnd);
|
||||||
|
int max = Math.max(selStart, selEnd);
|
||||||
|
|
||||||
|
final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
|
||||||
|
if (urls.length == 1) {
|
||||||
|
int defaultResId = 0;
|
||||||
|
for(String schema: sSchemaActionResMap.keySet()) {
|
||||||
|
if(urls[0].getURL().indexOf(schema) >= 0) {
|
||||||
|
defaultResId = sSchemaActionResMap.get(schema);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defaultResId == 0) {
|
||||||
|
defaultResId = R.string.note_link_other;
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
|
||||||
|
new OnMenuItemClickListener() {
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
// goto a new intent
|
||||||
|
urls[0].onClick(NoteEditText.this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onCreateContextMenu(menu);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,232 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import net.micode.notes.data.Contact;
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
import net.micode.notes.data.Notes.NoteColumns;
|
||||||
|
import net.micode.notes.tool.DataUtils;
|
||||||
|
|
||||||
|
|
||||||
|
public class NoteItemData {
|
||||||
|
static final String [] PROJECTION = new String [] {
|
||||||
|
NoteColumns.ID,
|
||||||
|
NoteColumns.ALERTED_DATE,
|
||||||
|
NoteColumns.BG_COLOR_ID,
|
||||||
|
NoteColumns.CREATED_DATE,
|
||||||
|
NoteColumns.HAS_ATTACHMENT,
|
||||||
|
NoteColumns.MODIFIED_DATE,
|
||||||
|
NoteColumns.NOTES_COUNT,
|
||||||
|
NoteColumns.PARENT_ID,
|
||||||
|
NoteColumns.SNIPPET,
|
||||||
|
NoteColumns.TYPE,
|
||||||
|
NoteColumns.WIDGET_ID,
|
||||||
|
NoteColumns.WIDGET_TYPE,
|
||||||
|
NoteColumns.IS_PRIVATE
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final int ID_COLUMN = 0;
|
||||||
|
private static final int ALERTED_DATE_COLUMN = 1;
|
||||||
|
private static final int BG_COLOR_ID_COLUMN = 2;
|
||||||
|
private static final int CREATED_DATE_COLUMN = 3;
|
||||||
|
private static final int HAS_ATTACHMENT_COLUMN = 4;
|
||||||
|
private static final int MODIFIED_DATE_COLUMN = 5;
|
||||||
|
private static final int NOTES_COUNT_COLUMN = 6;
|
||||||
|
private static final int PARENT_ID_COLUMN = 7;
|
||||||
|
private static final int SNIPPET_COLUMN = 8;
|
||||||
|
private static final int TYPE_COLUMN = 9;
|
||||||
|
private static final int WIDGET_ID_COLUMN = 10;
|
||||||
|
private static final int WIDGET_TYPE_COLUMN = 11;
|
||||||
|
private static final int IS_PRIVATE_COLUMN = 12;
|
||||||
|
|
||||||
|
public long id;
|
||||||
|
public int type;
|
||||||
|
public int widgetId;
|
||||||
|
public int widgetType;
|
||||||
|
public boolean isPrivate;
|
||||||
|
public String snippet;
|
||||||
|
public long alertDate;
|
||||||
|
public int bgColorId;
|
||||||
|
private long mCreatedDate;
|
||||||
|
private boolean mHasAttachment;
|
||||||
|
private long mModifiedDate;
|
||||||
|
private int mNotesCount;
|
||||||
|
private long mParentId;
|
||||||
|
private String mName;
|
||||||
|
private String mPhoneNumber;
|
||||||
|
|
||||||
|
private boolean mIsLastItem;
|
||||||
|
private boolean mIsFirstItem;
|
||||||
|
private boolean mIsOnlyOneItem;
|
||||||
|
private boolean mIsOneNoteFollowingFolder;
|
||||||
|
private boolean mIsMultiNotesFollowingFolder;
|
||||||
|
|
||||||
|
public NoteItemData(Context context, Cursor cursor) {
|
||||||
|
id = cursor.getLong(ID_COLUMN);
|
||||||
|
alertDate = cursor.getLong(ALERTED_DATE_COLUMN);
|
||||||
|
bgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);
|
||||||
|
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);
|
||||||
|
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false;
|
||||||
|
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);
|
||||||
|
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);
|
||||||
|
mParentId = cursor.getLong(PARENT_ID_COLUMN);
|
||||||
|
snippet = cursor.getString(SNIPPET_COLUMN);
|
||||||
|
snippet = snippet.replace(NoteEditActivity.TAG_CHECKED, "").replace(
|
||||||
|
NoteEditActivity.TAG_UNCHECKED, "");
|
||||||
|
type = cursor.getInt(TYPE_COLUMN);
|
||||||
|
widgetId = cursor.getInt(WIDGET_ID_COLUMN);
|
||||||
|
widgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
|
||||||
|
isPrivate = (cursor.getInt(IS_PRIVATE_COLUMN) == 1);
|
||||||
|
|
||||||
|
mPhoneNumber = "";
|
||||||
|
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
|
||||||
|
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), id);
|
||||||
|
if (!TextUtils.isEmpty(mPhoneNumber)) {
|
||||||
|
mName = Contact.getContact(context, mPhoneNumber);
|
||||||
|
if (mName == null) {
|
||||||
|
mName = mPhoneNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mName == null) {
|
||||||
|
mName = "";
|
||||||
|
}
|
||||||
|
checkPostion(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkPostion(Cursor cursor) {
|
||||||
|
mIsLastItem = cursor.isLast() ? true : false;
|
||||||
|
mIsFirstItem = cursor.isFirst() ? true : false;
|
||||||
|
mIsOnlyOneItem = (cursor.getCount() == 1);
|
||||||
|
mIsMultiNotesFollowingFolder = false;
|
||||||
|
mIsOneNoteFollowingFolder = false;
|
||||||
|
|
||||||
|
if (type == Notes.TYPE_NOTE && !mIsFirstItem) {
|
||||||
|
int position = cursor.getPosition();
|
||||||
|
if (cursor.moveToPrevious()) {
|
||||||
|
if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER
|
||||||
|
|| cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) {
|
||||||
|
if (cursor.getCount() > (position + 1)) {
|
||||||
|
mIsMultiNotesFollowingFolder = true;
|
||||||
|
} else {
|
||||||
|
mIsOneNoteFollowingFolder = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!cursor.moveToNext()) {
|
||||||
|
throw new IllegalStateException("cursor move to previous but can't move back");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOneFollowingFolder() {
|
||||||
|
return mIsOneNoteFollowingFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMultiFollowingFolder() {
|
||||||
|
return mIsMultiNotesFollowingFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLast() {
|
||||||
|
return mIsLastItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCallName() {
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFirst() {
|
||||||
|
return mIsFirstItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSingle() {
|
||||||
|
return mIsOnlyOneItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAlertDate() {
|
||||||
|
return alertDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCreatedDate() {
|
||||||
|
return mCreatedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAttachment() {
|
||||||
|
return mHasAttachment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getModifiedDate() {
|
||||||
|
return mModifiedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBgColorId() {
|
||||||
|
return bgColorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getParentId() {
|
||||||
|
return mParentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNotesCount() {
|
||||||
|
return mNotesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFolderId () {
|
||||||
|
return mParentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidgetType() {
|
||||||
|
return widgetType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidgetId() {
|
||||||
|
return widgetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSnippet() {
|
||||||
|
return snippet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAlert() {
|
||||||
|
return (alertDate > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCallRecord() {
|
||||||
|
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getNoteType(Cursor cursor) {
|
||||||
|
return cursor.getInt(TYPE_COLUMN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrivate() {
|
||||||
|
return isPrivate;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,202 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CursorAdapter;
|
||||||
|
import net.micode.notes.data.Notes.NoteColumns;
|
||||||
|
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import net.micode.notes.ui.BackgroundQueryHandler;
|
||||||
|
import net.micode.notes.ui.NoteItemData;
|
||||||
|
|
||||||
|
public class NotesListAdapter extends CursorAdapter {
|
||||||
|
private static final String TAG = "NotesListAdapter";
|
||||||
|
private Context mContext;
|
||||||
|
private HashMap<Integer, Boolean> mSelectedIndex;
|
||||||
|
private int mNotesCount;
|
||||||
|
private boolean mChoiceMode;
|
||||||
|
|
||||||
|
private boolean mIsPrivacyMode;
|
||||||
|
private BackgroundQueryHandler mBackgroundQueryHandler;
|
||||||
|
|
||||||
|
public static class AppWidgetAttribute {
|
||||||
|
public int widgetId;
|
||||||
|
public int widgetType;
|
||||||
|
};
|
||||||
|
|
||||||
|
public NotesListAdapter(Context context) {
|
||||||
|
super(context, null);
|
||||||
|
mSelectedIndex = new HashMap<Integer, Boolean>();
|
||||||
|
mContext = context;
|
||||||
|
mNotesCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
View view = convertView;
|
||||||
|
if (view == null) {
|
||||||
|
view = new NotesListItem(mContext);
|
||||||
|
}
|
||||||
|
Cursor cursor = (Cursor) getItem(position);
|
||||||
|
NoteItemData noteData = new NoteItemData(mContext, cursor);
|
||||||
|
((NotesListItem) view).bind(noteData, mBackgroundQueryHandler, mChoiceMode, mIsPrivacyMode);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||||
|
return new NotesListItem(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckedItem(final int position, final boolean checked) {
|
||||||
|
mSelectedIndex.put(position, checked);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInChoiceMode() {
|
||||||
|
return mChoiceMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChoiceMode(boolean mode) {
|
||||||
|
mSelectedIndex.clear();
|
||||||
|
mChoiceMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectAll(boolean checked) {
|
||||||
|
Cursor cursor = getCursor();
|
||||||
|
for (int i = 0; i < getCount(); i++) {
|
||||||
|
if (cursor.moveToPosition(i)) {
|
||||||
|
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
|
||||||
|
setCheckedItem(i, checked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<Long> getSelectedItemIds() {
|
||||||
|
HashSet<Long> itemSet = new HashSet<Long>();
|
||||||
|
for (Integer position : mSelectedIndex.keySet()) {
|
||||||
|
if (mSelectedIndex.get(position) == true) {
|
||||||
|
Long id = getItemId(position);
|
||||||
|
if (id == Notes.ID_ROOT_FOLDER) {
|
||||||
|
Log.d(TAG, "Wrong item id, should not happen");
|
||||||
|
} else {
|
||||||
|
itemSet.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<AppWidgetAttribute> getSelectedWidget() {
|
||||||
|
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
|
||||||
|
for (Integer position : mSelectedIndex.keySet()) {
|
||||||
|
if (mSelectedIndex.get(position) == true) {
|
||||||
|
Cursor c = (Cursor) getItem(position);
|
||||||
|
if (c != null) {
|
||||||
|
AppWidgetAttribute widget = new AppWidgetAttribute();
|
||||||
|
NoteItemData item = new NoteItemData(mContext, c);
|
||||||
|
widget.widgetId = item.widgetId;
|
||||||
|
widget.widgetType = item.widgetType;
|
||||||
|
itemSet.add(widget);
|
||||||
|
/**
|
||||||
|
* Don't close cursor here, only the adapter could close it
|
||||||
|
*/
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Invalid cursor");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return itemSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSelectedCount() {
|
||||||
|
Collection<Boolean> values = mSelectedIndex.values();
|
||||||
|
if (null == values) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Iterator<Boolean> iter = values.iterator();
|
||||||
|
int count = 0;
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
if (true == iter.next()) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAllSelected() {
|
||||||
|
int checkedCount = getSelectedCount();
|
||||||
|
return (checkedCount != 0 && checkedCount == mNotesCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSelectedItem(final int position) {
|
||||||
|
if (null == mSelectedIndex.get(position)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return mSelectedIndex.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onContentChanged() {
|
||||||
|
super.onContentChanged();
|
||||||
|
calcNotesCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changeCursor(Cursor cursor) {
|
||||||
|
super.changeCursor(cursor);
|
||||||
|
calcNotesCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calcNotesCount() {
|
||||||
|
mNotesCount = 0;
|
||||||
|
for (int i = 0; i < getCount(); i++) {
|
||||||
|
Cursor c = (Cursor) getItem(i);
|
||||||
|
if (c != null) {
|
||||||
|
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
|
||||||
|
mNotesCount++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Invalid cursor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setPrivacyMode(boolean isPrivacyMode) {
|
||||||
|
mIsPrivacyMode = isPrivacyMode;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindView(android.view.View view, android.content.Context context, android.database.Cursor cursor) {
|
||||||
|
// 简单实现,实际项目中请根据需求完善
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.appwidget.AppWidgetManager;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
import net.micode.notes.tool.DataUtils;
|
||||||
|
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
|
||||||
|
import net.micode.notes.tool.ResourceParser;
|
||||||
|
import net.micode.notes.ui.BackgroundQueryHandler;
|
||||||
|
|
||||||
|
public class NotesListItem extends LinearLayout {
|
||||||
|
|
||||||
|
private static final String TAG = "NotesListItem";
|
||||||
|
private ImageView mAlert;
|
||||||
|
private TextView mTitle;
|
||||||
|
private TextView mTime;
|
||||||
|
private TextView mCallName;
|
||||||
|
private NoteItemData mItemData;
|
||||||
|
private CheckBox mCheckBox;
|
||||||
|
private boolean mIsPrivacyMode;
|
||||||
|
private Context mContext;
|
||||||
|
private boolean mRootFolder;
|
||||||
|
|
||||||
|
public NotesListItem(Context context) {
|
||||||
|
super(context);
|
||||||
|
mContext = context;
|
||||||
|
inflate(context, R.layout.note_item, this);
|
||||||
|
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
|
||||||
|
mTitle = (TextView) findViewById(R.id.tv_title);
|
||||||
|
mTime = (TextView) findViewById(R.id.tv_time);
|
||||||
|
mCallName = (TextView) findViewById(R.id.tv_name);
|
||||||
|
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bind(NoteItemData data, BackgroundQueryHandler handler, boolean choiceMode, boolean isPrivacyMode) {
|
||||||
|
mItemData = data;
|
||||||
|
if (data.id == Notes.ID_ROOT_FOLDER) {
|
||||||
|
mRootFolder = true;
|
||||||
|
mTitle.setText(mContext.getString(R.string.menu_move_parent_folder));
|
||||||
|
mTitle.setTextAppearance(mContext, R.style.TextAppearancePrimaryItem);
|
||||||
|
mAlert.setVisibility(View.GONE);
|
||||||
|
mCallName.setVisibility(View.GONE);
|
||||||
|
setBackgroundResource(R.drawable.list_selector_background);
|
||||||
|
} else if (data.id == Notes.ID_CALL_RECORD_FOLDER) {
|
||||||
|
mRootFolder = true;
|
||||||
|
mTitle.setText(mContext.getString(R.string.call_record_folder_name));
|
||||||
|
mTitle.setTextAppearance(mContext, R.style.TextAppearancePrimaryItem);
|
||||||
|
mAlert.setVisibility(View.GONE);
|
||||||
|
mCallName.setVisibility(View.GONE);
|
||||||
|
setBackgroundResource(R.drawable.list_selector_background);
|
||||||
|
} else {
|
||||||
|
mRootFolder = false;
|
||||||
|
if (data.type == Notes.TYPE_FOLDER) {
|
||||||
|
mTitle.setTextAppearance(mContext, R.style.TextAppearancePrimaryItem);
|
||||||
|
mAlert.setVisibility(View.GONE);
|
||||||
|
mCallName.setVisibility(View.GONE);
|
||||||
|
setBackgroundResource(R.drawable.list_selector_background);
|
||||||
|
} else {
|
||||||
|
mTitle.setTextAppearance(mContext, R.style.TextAppearanceSecondaryItem);
|
||||||
|
mAlert.setVisibility(View.VISIBLE);
|
||||||
|
if (data.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
||||||
|
&& data.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
|
||||||
|
mCallName.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
mCallName.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
setBackgroundResource(R.drawable.list_selector_background);
|
||||||
|
|
||||||
|
if (data.isPrivate) {
|
||||||
|
mTitle.setText("🔒 " + data.snippet);
|
||||||
|
} else {
|
||||||
|
mTitle.setText(data.snippet);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.alertDate > 0) {
|
||||||
|
mTime.setText(DataUtils.formatDateTime(mContext, data.alertDate));
|
||||||
|
mTime.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
mTime.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (choiceMode) {
|
||||||
|
mCheckBox.setVisibility(View.VISIBLE);
|
||||||
|
mCheckBox.setChecked(isChecked());
|
||||||
|
} else {
|
||||||
|
mCheckBox.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.bgColorId != ResourceParser.getDefaultBgId(mContext)) {
|
||||||
|
setBackgroundResource(ResourceParser.getNoteBgResId(data.bgColorId));
|
||||||
|
} else {
|
||||||
|
setBackgroundResource(R.drawable.list_selector_background);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBackground(NoteItemData data) {
|
||||||
|
int id = data.getBgColorId();
|
||||||
|
if (data.getType() == Notes.TYPE_NOTE) {
|
||||||
|
if (data.isSingle() || data.isOneFollowingFolder()) {
|
||||||
|
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
|
||||||
|
} else if (data.isLast()) {
|
||||||
|
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
|
||||||
|
} else if (data.isFirst() || data.isMultiFollowingFolder()) {
|
||||||
|
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
|
||||||
|
} else {
|
||||||
|
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoteItemData getItemData() {
|
||||||
|
return mItemData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivacyMode(boolean isPrivacyMode) {
|
||||||
|
mIsPrivacyMode = isPrivacyMode;
|
||||||
|
updatePrivacyMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePrivacyMode() {
|
||||||
|
if (mIsPrivacyMode) {
|
||||||
|
if (mTitle != null) {
|
||||||
|
mTitle.setText("******");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (mTitle != null && mItemData != null) {
|
||||||
|
mTitle.setText(mItemData.getSnippet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isChecked() {
|
||||||
|
return mCheckBox != null && mCheckBox.isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoteItemData getNoteItemData() {
|
||||||
|
return mItemData;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,388 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.accounts.AccountManager;
|
||||||
|
import android.app.ActionBar;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceCategory;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
import net.micode.notes.data.Notes.NoteColumns;
|
||||||
|
import net.micode.notes.gtask.remote.GTaskSyncService;
|
||||||
|
|
||||||
|
|
||||||
|
public class NotesPreferenceActivity extends PreferenceActivity {
|
||||||
|
public static final String PREFERENCE_NAME = "notes_preferences";
|
||||||
|
|
||||||
|
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
|
||||||
|
|
||||||
|
public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
|
||||||
|
|
||||||
|
public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
|
||||||
|
|
||||||
|
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
|
||||||
|
|
||||||
|
private static final String AUTHORITIES_FILTER_KEY = "authorities";
|
||||||
|
|
||||||
|
private PreferenceCategory mAccountCategory;
|
||||||
|
|
||||||
|
private GTaskReceiver mReceiver;
|
||||||
|
|
||||||
|
private Account[] mOriAccounts;
|
||||||
|
|
||||||
|
private boolean mHasAddedAccount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle icicle) {
|
||||||
|
super.onCreate(icicle);
|
||||||
|
|
||||||
|
/* using the app icon for navigation */
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
|
||||||
|
mReceiver = new GTaskReceiver();
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
|
||||||
|
registerReceiver(mReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
|
||||||
|
|
||||||
|
mOriAccounts = null;
|
||||||
|
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
|
||||||
|
getListView().addHeaderView(header, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
// need to set sync account automatically if user has added a new
|
||||||
|
// account
|
||||||
|
if (mHasAddedAccount) {
|
||||||
|
Account[] accounts = getGoogleAccounts();
|
||||||
|
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
|
||||||
|
for (Account accountNew : accounts) {
|
||||||
|
boolean found = false;
|
||||||
|
for (Account accountOld : mOriAccounts) {
|
||||||
|
if (TextUtils.equals(accountOld.name, accountNew.name)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
setSyncAccount(accountNew.name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
if (mReceiver != null) {
|
||||||
|
unregisterReceiver(mReceiver);
|
||||||
|
}
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAccountPreference() {
|
||||||
|
mAccountCategory.removeAll();
|
||||||
|
|
||||||
|
Preference accountPref = new Preference(this);
|
||||||
|
final String defaultAccount = getSyncAccountName(this);
|
||||||
|
accountPref.setTitle(getString(R.string.preferences_account_title));
|
||||||
|
accountPref.setSummary(getString(R.string.preferences_account_summary));
|
||||||
|
accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
if (!GTaskSyncService.isSyncing()) {
|
||||||
|
if (TextUtils.isEmpty(defaultAccount)) {
|
||||||
|
// the first time to set account
|
||||||
|
showSelectAccountAlertDialog();
|
||||||
|
} else {
|
||||||
|
// if the account has already been set, we need to promp
|
||||||
|
// user about the risk
|
||||||
|
showChangeAccountConfirmAlertDialog();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(NotesPreferenceActivity.this,
|
||||||
|
R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mAccountCategory.addPreference(accountPref);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadSyncButton() {
|
||||||
|
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
|
||||||
|
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
|
||||||
|
|
||||||
|
// set button state
|
||||||
|
if (GTaskSyncService.isSyncing()) {
|
||||||
|
syncButton.setText(getString(R.string.preferences_button_sync_cancel));
|
||||||
|
syncButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
GTaskSyncService.cancelSync(NotesPreferenceActivity.this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
syncButton.setText(getString(R.string.preferences_button_sync_immediately));
|
||||||
|
syncButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
GTaskSyncService.startSync(NotesPreferenceActivity.this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
|
||||||
|
|
||||||
|
// set last sync time
|
||||||
|
if (GTaskSyncService.isSyncing()) {
|
||||||
|
lastSyncTimeView.setText(GTaskSyncService.getProgressString());
|
||||||
|
lastSyncTimeView.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
long lastSyncTime = getLastSyncTime(this);
|
||||||
|
if (lastSyncTime != 0) {
|
||||||
|
lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time,
|
||||||
|
DateFormat.format(getString(R.string.preferences_last_sync_time_format),
|
||||||
|
lastSyncTime)));
|
||||||
|
lastSyncTimeView.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
lastSyncTimeView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshUI() {
|
||||||
|
loadAccountPreference();
|
||||||
|
loadSyncButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSelectAccountAlertDialog() {
|
||||||
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
||||||
|
|
||||||
|
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
||||||
|
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
||||||
|
titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
|
||||||
|
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
|
||||||
|
subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));
|
||||||
|
|
||||||
|
dialogBuilder.setCustomTitle(titleView);
|
||||||
|
dialogBuilder.setPositiveButton(null, null);
|
||||||
|
|
||||||
|
Account[] accounts = getGoogleAccounts();
|
||||||
|
String defAccount = getSyncAccountName(this);
|
||||||
|
|
||||||
|
mOriAccounts = accounts;
|
||||||
|
mHasAddedAccount = false;
|
||||||
|
|
||||||
|
if (accounts.length > 0) {
|
||||||
|
CharSequence[] items = new CharSequence[accounts.length];
|
||||||
|
final CharSequence[] itemMapping = items;
|
||||||
|
int checkedItem = -1;
|
||||||
|
int index = 0;
|
||||||
|
for (Account account : accounts) {
|
||||||
|
if (TextUtils.equals(account.name, defAccount)) {
|
||||||
|
checkedItem = index;
|
||||||
|
}
|
||||||
|
items[index++] = account.name;
|
||||||
|
}
|
||||||
|
dialogBuilder.setSingleChoiceItems(items, checkedItem,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
setSyncAccount(itemMapping[which].toString());
|
||||||
|
dialog.dismiss();
|
||||||
|
refreshUI();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
|
||||||
|
dialogBuilder.setView(addAccountView);
|
||||||
|
|
||||||
|
final AlertDialog dialog = dialogBuilder.show();
|
||||||
|
addAccountView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
mHasAddedAccount = true;
|
||||||
|
Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
|
||||||
|
intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
|
||||||
|
"gmail-ls"
|
||||||
|
});
|
||||||
|
startActivityForResult(intent, -1);
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showChangeAccountConfirmAlertDialog() {
|
||||||
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
||||||
|
|
||||||
|
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
||||||
|
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
||||||
|
titleTextView.setText(getString(R.string.preferences_dialog_change_account_title,
|
||||||
|
getSyncAccountName(this)));
|
||||||
|
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
|
||||||
|
subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
|
||||||
|
dialogBuilder.setCustomTitle(titleView);
|
||||||
|
|
||||||
|
CharSequence[] menuItemArray = new CharSequence[] {
|
||||||
|
getString(R.string.preferences_menu_change_account),
|
||||||
|
getString(R.string.preferences_menu_remove_account),
|
||||||
|
getString(R.string.preferences_menu_cancel)
|
||||||
|
};
|
||||||
|
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if (which == 0) {
|
||||||
|
showSelectAccountAlertDialog();
|
||||||
|
} else if (which == 1) {
|
||||||
|
removeSyncAccount();
|
||||||
|
refreshUI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogBuilder.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Account[] getGoogleAccounts() {
|
||||||
|
AccountManager accountManager = AccountManager.get(this);
|
||||||
|
return accountManager.getAccountsByType("com.google");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSyncAccount(String account) {
|
||||||
|
if (!getSyncAccountName(this).equals(account)) {
|
||||||
|
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
|
if (account != null) {
|
||||||
|
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account);
|
||||||
|
} else {
|
||||||
|
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
|
||||||
|
}
|
||||||
|
editor.commit();
|
||||||
|
|
||||||
|
// clean up last sync time
|
||||||
|
setLastSyncTime(this, 0);
|
||||||
|
|
||||||
|
// clean up local gtask related info
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(NoteColumns.GTASK_ID, "");
|
||||||
|
values.put(NoteColumns.SYNC_ID, 0);
|
||||||
|
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
Toast.makeText(NotesPreferenceActivity.this,
|
||||||
|
getString(R.string.preferences_toast_success_set_accout, account),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeSyncAccount() {
|
||||||
|
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
|
if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) {
|
||||||
|
editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);
|
||||||
|
}
|
||||||
|
if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
|
||||||
|
editor.remove(PREFERENCE_LAST_SYNC_TIME);
|
||||||
|
}
|
||||||
|
editor.commit();
|
||||||
|
|
||||||
|
// clean up local gtask related info
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(NoteColumns.GTASK_ID, "");
|
||||||
|
values.put(NoteColumns.SYNC_ID, 0);
|
||||||
|
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSyncAccountName(Context context) {
|
||||||
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
||||||
|
Context.MODE_PRIVATE);
|
||||||
|
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLastSyncTime(Context context, long time) {
|
||||||
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
||||||
|
Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
|
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getLastSyncTime(Context context) {
|
||||||
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
||||||
|
Context.MODE_PRIVATE);
|
||||||
|
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GTaskReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
refreshUI();
|
||||||
|
if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) {
|
||||||
|
TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
|
||||||
|
syncStatus.setText(intent
|
||||||
|
.getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
Intent intent = new Intent(this, NotesListActivity.class);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,109 @@
|
|||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
import net.micode.notes.data.PrivacyPasswordManager;
|
||||||
|
|
||||||
|
public class PrivacyPasswordDialog {
|
||||||
|
private Context mContext;
|
||||||
|
private PrivacyPasswordManager mPasswordManager;
|
||||||
|
private OnPasswordVerifiedListener mListener;
|
||||||
|
|
||||||
|
public interface OnPasswordVerifiedListener {
|
||||||
|
void onPasswordVerified();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivacyPasswordDialog(Context context, OnPasswordVerifiedListener listener) {
|
||||||
|
mContext = context;
|
||||||
|
mPasswordManager = new PrivacyPasswordManager(context);
|
||||||
|
mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示设置密码对话框
|
||||||
|
*/
|
||||||
|
public void showSetPasswordDialog() {
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_privacy_password, null);
|
||||||
|
final EditText passwordEdit = view.findViewById(R.id.password_edit);
|
||||||
|
final EditText confirmPasswordEdit = view.findViewById(R.id.confirm_password_edit);
|
||||||
|
|
||||||
|
new AlertDialog.Builder(mContext)
|
||||||
|
.setTitle(R.string.set_privacy_password)
|
||||||
|
.setView(view)
|
||||||
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
String password = passwordEdit.getText().toString();
|
||||||
|
String confirmPassword = confirmPasswordEdit.getText().toString();
|
||||||
|
|
||||||
|
if (password.isEmpty()) {
|
||||||
|
Toast.makeText(mContext, R.string.password_cannot_be_empty, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password.equals(confirmPassword)) {
|
||||||
|
Toast.makeText(mContext, R.string.passwords_do_not_match, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mPasswordManager.setPassword(password)) {
|
||||||
|
Toast.makeText(mContext, R.string.password_set_success, Toast.LENGTH_SHORT).show();
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.onPasswordVerified();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(mContext, R.string.password_set_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示验证密码对话框
|
||||||
|
*/
|
||||||
|
public void showVerifyPasswordDialog() {
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_verify_privacy_password, null);
|
||||||
|
final EditText passwordEdit = view.findViewById(R.id.password_edit);
|
||||||
|
|
||||||
|
new AlertDialog.Builder(mContext)
|
||||||
|
.setTitle(R.string.verify_privacy_password)
|
||||||
|
.setView(view)
|
||||||
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
String password = passwordEdit.getText().toString();
|
||||||
|
|
||||||
|
if (password.isEmpty()) {
|
||||||
|
Toast.makeText(mContext, R.string.password_cannot_be_empty, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mPasswordManager.verifyPassword(password)) {
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.onPasswordVerified();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(mContext, R.string.incorrect_password, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否需要设置密码
|
||||||
|
*/
|
||||||
|
public boolean needsPasswordSetup() {
|
||||||
|
return !mPasswordManager.hasPassword();
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||||
|
|
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 |