Compare commits
1 Commits
master
...
hxs_xiaomi
Author | SHA1 | Date |
---|---|---|
|
8c397f596a | 3 years ago |
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="#50000000" />
|
||||
</selector>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
#Sat Sep 11 10:03:18 CST 2021
|
||||
gradle.version=7.2
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,123 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="16" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="C:\Users\Lenovo\.android\avd\Pixel_5_API_23.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2021-09-12T08:09:43.695989200Z" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,21 @@
|
||||
<?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="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="openjdk-16" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="BintrayJCenter" />
|
||||
<option name="name" value="BintrayJCenter" />
|
||||
<option name="url" value="https://jcenter.bintray.com/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="Google" />
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="..\:/Android app/Notes-master/app/src/main/res/drawable/new_note.xml" value="0.24270833333333333" />
|
||||
<entry key="..\:/Android app/Notes-master/app/src/main/res/layout/add_account_text.xml" value="0.10260416666666666" />
|
||||
<entry key="..\:/Android app/Notes-master/app/src/main/res/layout/datetime_picker.xml" value="0.10260416666666666" />
|
||||
<entry key="..\:/Android app/Notes-master/app/src/main/res/layout/note_edit.xml" value="0.26145833333333335" />
|
||||
<entry key="..\:/Android app/Notes-master/app/src/main/res/layout/note_item.xml" value="0.146875" />
|
||||
<entry key="..\:/Android app/Notes-master/app/src/main/res/menu/call_note_edit.xml" value="0.19444444444444445" />
|
||||
<entry key="..\:/Android app/Notes-master/app/src/main/res/menu/note_edit.xml" value="0.22291666666666668" />
|
||||
<entry key="..\:/Android app/Notes-master/app/src/main/res/xml/preferences.xml" value="0.12158054711246201" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" project-jdk-name="16" 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,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" type="JAVA_MODULE" version="4" />
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SonarLintProjectState">
|
||||
<lastEventPolling>1631850246765</lastEventPolling>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SonarLintProjectSettings">
|
||||
<option name="bindingEnabled" value="true" />
|
||||
<option name="projectKey" value="Kilito" />
|
||||
<option name="serverId" value="Kilito" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Automatically generated file. DO NOT MODIFY
|
||||
*/
|
||||
package net.micode.notes;
|
||||
|
||||
public final class BuildConfig {
|
||||
public static final boolean DEBUG = Boolean.parseBoolean("true");
|
||||
public static final String APPLICATION_ID = "net.micode.notes";
|
||||
public static final String BUILD_TYPE = "debug";
|
||||
public static final int VERSION_CODE = 1;
|
||||
public static final String VERSION_NAME = "0.1";
|
||||
}
|
@ -0,0 +1,281 @@
|
||||
/*
|
||||
* 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 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";
|
||||
|
||||
public static final String TOP = "top";
|
||||
}
|
||||
|
||||
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 {@link #MIMETYPE} specific, used for
|
||||
* integer data type
|
||||
* <P> Type: INTEGER </P>
|
||||
*/
|
||||
public static final String DATA1 = "data1";
|
||||
|
||||
/**
|
||||
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
|
||||
* integer data type
|
||||
* <P> Type: INTEGER </P>
|
||||
*/
|
||||
public static final String DATA2 = "data2";
|
||||
|
||||
/**
|
||||
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
|
||||
* TEXT data type
|
||||
* <P> Type: TEXT </P>
|
||||
*/
|
||||
public static final String DATA3 = "data3";
|
||||
|
||||
/**
|
||||
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
|
||||
* TEXT data type
|
||||
* <P> Type: TEXT </P>
|
||||
*/
|
||||
public static final String DATA4 = "data4";
|
||||
|
||||
/**
|
||||
* Generic data column, the meaning is {@link #MIMETYPE} 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,373 @@
|
||||
/*
|
||||
* 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 = 4;
|
||||
|
||||
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.TOP+" 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";
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
boolean reCreateTriggers = false;
|
||||
boolean skipV2 = false;
|
||||
|
||||
if (oldVersion == 1) {
|
||||
upgradeToV2(db);
|
||||
skipV2 = true; // this upgrade including the upgrade from v2 to v3
|
||||
oldVersion++;
|
||||
}
|
||||
|
||||
if (oldVersion == 2 && !skipV2) {
|
||||
upgradeToV3(db);
|
||||
reCreateTriggers = true;
|
||||
oldVersion++;
|
||||
}
|
||||
|
||||
if (oldVersion == 3) {
|
||||
upgradeToV4(db);
|
||||
oldVersion++;
|
||||
}
|
||||
|
||||
if (oldVersion == 4) {
|
||||
upgradeToV5(db);
|
||||
oldVersion++;
|
||||
}
|
||||
|
||||
if (reCreateTriggers) {
|
||||
reCreateNoteTableTriggers(db);
|
||||
reCreateDataTableTriggers(db);
|
||||
}
|
||||
|
||||
if (oldVersion != newVersion) {
|
||||
throw new IllegalStateException("Upgrade notes database to version " + newVersion
|
||||
+ "fails");
|
||||
}
|
||||
}
|
||||
|
||||
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 CLOUMN" + NoteColumns.TOP
|
||||
+ " INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,517 @@
|
||||
/*
|
||||
* 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.data;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import net.micode.notes.data.Notes;
|
||||
import net.micode.notes.data.Notes.DataColumns;
|
||||
import net.micode.notes.data.Notes.NoteColumns;
|
||||
import net.micode.notes.gtask.exception.ActionFailureException;
|
||||
import net.micode.notes.tool.GTaskStringUtils;
|
||||
import net.micode.notes.tool.ResourceParser;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class SqlNote {
|
||||
private static final String TAG = SqlNote.class.getSimpleName();
|
||||
|
||||
private static final int INVALID_ID = -99999;
|
||||
|
||||
public static final String[] PROJECTION_NOTE = 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.SYNC_ID,
|
||||
NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID,
|
||||
NoteColumns.VERSION,NoteColumns.TOP
|
||||
};
|
||||
|
||||
public static final int ID_COLUMN = 0;
|
||||
|
||||
public static final int ALERTED_DATE_COLUMN = 1;
|
||||
|
||||
public static final int BG_COLOR_ID_COLUMN = 2;
|
||||
|
||||
public static final int CREATED_DATE_COLUMN = 3;
|
||||
|
||||
public static final int HAS_ATTACHMENT_COLUMN = 4;
|
||||
|
||||
public static final int MODIFIED_DATE_COLUMN = 5;
|
||||
|
||||
public static final int NOTES_COUNT_COLUMN = 6;
|
||||
|
||||
public static final int PARENT_ID_COLUMN = 7;
|
||||
|
||||
public static final int SNIPPET_COLUMN = 8;
|
||||
|
||||
public static final int TYPE_COLUMN = 9;
|
||||
|
||||
public static final int WIDGET_ID_COLUMN = 10;
|
||||
|
||||
public static final int WIDGET_TYPE_COLUMN = 11;
|
||||
|
||||
public static final int SYNC_ID_COLUMN = 12;
|
||||
|
||||
public static final int LOCAL_MODIFIED_COLUMN = 13;
|
||||
|
||||
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
|
||||
|
||||
public static final int GTASK_ID_COLUMN = 15;
|
||||
|
||||
public static final int VERSION_COLUMN = 16;
|
||||
|
||||
public static final int Top_COLUMN = 17;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
private boolean mIsCreate;
|
||||
|
||||
private long mId;
|
||||
|
||||
private long mAlertDate;
|
||||
|
||||
private int mBgColorId;
|
||||
|
||||
private long mCreatedDate;
|
||||
|
||||
private int mHasAttachment;
|
||||
|
||||
private long mModifiedDate;
|
||||
|
||||
private long mParentId;
|
||||
|
||||
private String mSnippet;
|
||||
|
||||
private int mType;
|
||||
|
||||
private int mWidgetId;
|
||||
|
||||
private int mWidgetType;
|
||||
|
||||
private long mOriginParent;
|
||||
|
||||
private long mVersion;
|
||||
|
||||
private ContentValues mDiffNoteValues;
|
||||
|
||||
private ArrayList<SqlData> mDataList;
|
||||
|
||||
private String mTop ;
|
||||
|
||||
public SqlNote(Context context) {
|
||||
mContext = context;
|
||||
mContentResolver = context.getContentResolver();
|
||||
mIsCreate = true;
|
||||
mId = INVALID_ID;
|
||||
mAlertDate = 0;
|
||||
mBgColorId = ResourceParser.getDefaultBgId(context);
|
||||
mCreatedDate = System.currentTimeMillis();
|
||||
mHasAttachment = 0;
|
||||
mModifiedDate = System.currentTimeMillis();
|
||||
mParentId = 0;
|
||||
mSnippet = "";
|
||||
mType = Notes.TYPE_NOTE;
|
||||
mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
|
||||
mOriginParent = 0;
|
||||
mVersion = 0;
|
||||
mDiffNoteValues = new ContentValues();
|
||||
mDataList = new ArrayList<SqlData>();
|
||||
mTop = getmTop();
|
||||
}
|
||||
|
||||
public SqlNote(Context context, Cursor c) {
|
||||
mContext = context;
|
||||
mContentResolver = context.getContentResolver();
|
||||
mIsCreate = false;
|
||||
loadFromCursor(c);
|
||||
mDataList = new ArrayList<SqlData>();
|
||||
if (mType == Notes.TYPE_NOTE)
|
||||
loadDataContent();
|
||||
mDiffNoteValues = new ContentValues();
|
||||
mTop = getmTop();
|
||||
}
|
||||
|
||||
public SqlNote(Context context, long id) {
|
||||
mContext = context;
|
||||
mContentResolver = context.getContentResolver();
|
||||
mIsCreate = false;
|
||||
loadFromCursor(id);
|
||||
mDataList = new ArrayList<SqlData>();
|
||||
if (mType == Notes.TYPE_NOTE)
|
||||
loadDataContent();
|
||||
mDiffNoteValues = new ContentValues();
|
||||
mTop = getmTop();
|
||||
|
||||
}
|
||||
|
||||
private void loadFromCursor(long id) {
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
|
||||
new String[] {
|
||||
String.valueOf(id)
|
||||
}, null);
|
||||
if (c != null) {
|
||||
c.moveToNext();
|
||||
loadFromCursor(c);
|
||||
} else {
|
||||
Log.w(TAG, "loadFromCursor: cursor = null");
|
||||
}
|
||||
} finally {
|
||||
if (c != null)
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFromCursor(Cursor c) {
|
||||
mId = c.getLong(ID_COLUMN);
|
||||
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
|
||||
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
|
||||
mCreatedDate = c.getLong(CREATED_DATE_COLUMN);
|
||||
mHasAttachment = c.getInt(HAS_ATTACHMENT_COLUMN);
|
||||
mModifiedDate = c.getLong(MODIFIED_DATE_COLUMN);
|
||||
mParentId = c.getLong(PARENT_ID_COLUMN);
|
||||
mSnippet = c.getString(SNIPPET_COLUMN);
|
||||
mType = c.getInt(TYPE_COLUMN);
|
||||
mWidgetId = c.getInt(WIDGET_ID_COLUMN);
|
||||
mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
|
||||
mVersion = c.getLong(VERSION_COLUMN);
|
||||
mTop = c.getString(Top_COLUMN);
|
||||
}
|
||||
|
||||
private void loadDataContent() {
|
||||
Cursor c = null;
|
||||
mDataList.clear();
|
||||
try {
|
||||
c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
|
||||
"(note_id=?)", new String[] {
|
||||
String.valueOf(mId)
|
||||
}, null);
|
||||
if (c != null) {
|
||||
if (c.getCount() == 0) {
|
||||
Log.w(TAG, "it seems that the note has not data");
|
||||
return;
|
||||
}
|
||||
while (c.moveToNext()) {
|
||||
SqlData data = new SqlData(mContext, c);
|
||||
mDataList.add(data);
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "loadDataContent: cursor = null");
|
||||
}
|
||||
} finally {
|
||||
if (c != null)
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setContent(JSONObject js) {
|
||||
try {
|
||||
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
||||
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
|
||||
Log.w(TAG, "cannot set system folder");
|
||||
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
|
||||
// for folder we can only update the snnipet and type
|
||||
String snippet = note.has(NoteColumns.SNIPPET) ? note
|
||||
.getString(NoteColumns.SNIPPET) : "";
|
||||
if (mIsCreate || !mSnippet.equals(snippet)) {
|
||||
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
|
||||
}
|
||||
mSnippet = snippet;
|
||||
|
||||
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
|
||||
: Notes.TYPE_NOTE;
|
||||
if (mIsCreate || mType != type) {
|
||||
mDiffNoteValues.put(NoteColumns.TYPE, type);
|
||||
}
|
||||
mType = type;
|
||||
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
|
||||
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
||||
long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
|
||||
if (mIsCreate || mId != id) {
|
||||
mDiffNoteValues.put(NoteColumns.ID, id);
|
||||
}
|
||||
mId = id;
|
||||
|
||||
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
|
||||
.getLong(NoteColumns.ALERTED_DATE) : 0;
|
||||
if (mIsCreate || mAlertDate != alertDate) {
|
||||
mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate);
|
||||
}
|
||||
mAlertDate = alertDate;
|
||||
|
||||
int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note
|
||||
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
|
||||
if (mIsCreate || mBgColorId != bgColorId) {
|
||||
mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId);
|
||||
}
|
||||
mBgColorId = bgColorId;
|
||||
|
||||
long createDate = note.has(NoteColumns.CREATED_DATE) ? note
|
||||
.getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis();
|
||||
if (mIsCreate || mCreatedDate != createDate) {
|
||||
mDiffNoteValues.put(NoteColumns.CREATED_DATE, createDate);
|
||||
}
|
||||
mCreatedDate = createDate;
|
||||
|
||||
int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT) ? note
|
||||
.getInt(NoteColumns.HAS_ATTACHMENT) : 0;
|
||||
if (mIsCreate || mHasAttachment != hasAttachment) {
|
||||
mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment);
|
||||
}
|
||||
mHasAttachment = hasAttachment;
|
||||
|
||||
long modifiedDate = note.has(NoteColumns.MODIFIED_DATE) ? note
|
||||
.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis();
|
||||
if (mIsCreate || mModifiedDate != modifiedDate) {
|
||||
mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate);
|
||||
}
|
||||
mModifiedDate = modifiedDate;
|
||||
|
||||
long parentId = note.has(NoteColumns.PARENT_ID) ? note
|
||||
.getLong(NoteColumns.PARENT_ID) : 0;
|
||||
if (mIsCreate || mParentId != parentId) {
|
||||
mDiffNoteValues.put(NoteColumns.PARENT_ID, parentId);
|
||||
}
|
||||
mParentId = parentId;
|
||||
|
||||
String snippet = note.has(NoteColumns.SNIPPET) ? note
|
||||
.getString(NoteColumns.SNIPPET) : "";
|
||||
if (mIsCreate || !mSnippet.equals(snippet)) {
|
||||
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
|
||||
}
|
||||
mSnippet = snippet;
|
||||
|
||||
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
|
||||
: Notes.TYPE_NOTE;
|
||||
if (mIsCreate || mType != type) {
|
||||
mDiffNoteValues.put(NoteColumns.TYPE, type);
|
||||
}
|
||||
mType = type;
|
||||
|
||||
int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID)
|
||||
: AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
if (mIsCreate || mWidgetId != widgetId) {
|
||||
mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId);
|
||||
}
|
||||
mWidgetId = widgetId;
|
||||
|
||||
int widgetType = note.has(NoteColumns.WIDGET_TYPE) ? note
|
||||
.getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE;
|
||||
if (mIsCreate || mWidgetType != widgetType) {
|
||||
mDiffNoteValues.put(NoteColumns.WIDGET_TYPE, widgetType);
|
||||
}
|
||||
mWidgetType = widgetType;
|
||||
|
||||
long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID) ? note
|
||||
.getLong(NoteColumns.ORIGIN_PARENT_ID) : 0;
|
||||
if (mIsCreate || mOriginParent != originParent) {
|
||||
mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent);
|
||||
}
|
||||
mOriginParent = originParent;
|
||||
|
||||
for (int i = 0; i < dataArray.length(); i++) {
|
||||
JSONObject data = dataArray.getJSONObject(i);
|
||||
SqlData sqlData = null;
|
||||
if (data.has(DataColumns.ID)) {
|
||||
long dataId = data.getLong(DataColumns.ID);
|
||||
for (SqlData temp : mDataList) {
|
||||
if (dataId == temp.getId()) {
|
||||
sqlData = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sqlData == null) {
|
||||
sqlData = new SqlData(mContext);
|
||||
mDataList.add(sqlData);
|
||||
}
|
||||
|
||||
sqlData.setContent(data);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public JSONObject getContent() {
|
||||
try {
|
||||
JSONObject js = new JSONObject();
|
||||
|
||||
if (mIsCreate) {
|
||||
Log.e(TAG, "it seems that we haven't created this in database yet");
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject note = new JSONObject();
|
||||
if (mType == Notes.TYPE_NOTE) {
|
||||
note.put(NoteColumns.ID, mId);
|
||||
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
|
||||
note.put(NoteColumns.BG_COLOR_ID, mBgColorId);
|
||||
note.put(NoteColumns.CREATED_DATE, mCreatedDate);
|
||||
note.put(NoteColumns.HAS_ATTACHMENT, mHasAttachment);
|
||||
note.put(NoteColumns.MODIFIED_DATE, mModifiedDate);
|
||||
note.put(NoteColumns.PARENT_ID, mParentId);
|
||||
note.put(NoteColumns.SNIPPET, mSnippet);
|
||||
note.put(NoteColumns.TYPE, mType);
|
||||
note.put(NoteColumns.WIDGET_ID, mWidgetId);
|
||||
note.put(NoteColumns.WIDGET_TYPE, mWidgetType);
|
||||
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
|
||||
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
||||
|
||||
JSONArray dataArray = new JSONArray();
|
||||
for (SqlData sqlData : mDataList) {
|
||||
JSONObject data = sqlData.getContent();
|
||||
if (data != null) {
|
||||
dataArray.put(data);
|
||||
}
|
||||
}
|
||||
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
||||
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {
|
||||
note.put(NoteColumns.ID, mId);
|
||||
note.put(NoteColumns.TYPE, mType);
|
||||
note.put(NoteColumns.SNIPPET, mSnippet);
|
||||
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
||||
}
|
||||
|
||||
return js;
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setParentId(long id) {
|
||||
mParentId = id;
|
||||
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
|
||||
}
|
||||
|
||||
public void setGtaskId(String gid) {
|
||||
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
||||
}
|
||||
|
||||
public void setSyncId(long syncId) {
|
||||
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
|
||||
}
|
||||
|
||||
public void resetLocalModified() {
|
||||
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public long getParentId() {
|
||||
return mParentId;
|
||||
}
|
||||
|
||||
public String getSnippet() {
|
||||
return mSnippet;
|
||||
}
|
||||
|
||||
public String getmTop(){
|
||||
return mTop;
|
||||
}
|
||||
|
||||
public boolean isNoteType() {
|
||||
return mType == Notes.TYPE_NOTE;
|
||||
}
|
||||
|
||||
public void commit(boolean validateVersion) {
|
||||
if (mIsCreate) {
|
||||
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
|
||||
mDiffNoteValues.remove(NoteColumns.ID);
|
||||
}
|
||||
|
||||
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
|
||||
try {
|
||||
mId = Long.valueOf(uri.getPathSegments().get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "Get note id error :" + e.toString());
|
||||
throw new ActionFailureException("create note failed");
|
||||
}
|
||||
if (mId == 0) {
|
||||
throw new IllegalStateException("Create thread id failed");
|
||||
}
|
||||
|
||||
if (mType == Notes.TYPE_NOTE) {
|
||||
for (SqlData sqlData : mDataList) {
|
||||
sqlData.commit(mId, false, -1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) {
|
||||
Log.e(TAG, "No such note");
|
||||
throw new IllegalStateException("Try to update note with invalid id");
|
||||
}
|
||||
if (mDiffNoteValues.size() > 0) {
|
||||
mVersion ++;
|
||||
int result = 0;
|
||||
if (!validateVersion) {
|
||||
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
|
||||
+ NoteColumns.ID + "=?)", new String[] {
|
||||
String.valueOf(mId)
|
||||
});
|
||||
} else {
|
||||
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
|
||||
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
|
||||
new String[] {
|
||||
String.valueOf(mId), String.valueOf(mVersion)
|
||||
});
|
||||
}
|
||||
if (result == 0) {
|
||||
Log.w(TAG, "there is no update. maybe user updates note when syncing");
|
||||
}
|
||||
}
|
||||
|
||||
if (mType == Notes.TYPE_NOTE) {
|
||||
for (SqlData sqlData : mDataList) {
|
||||
sqlData.commit(mId, validateVersion, mVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// refresh local info
|
||||
loadFromCursor(mId);
|
||||
if (mType == Notes.TYPE_NOTE)
|
||||
loadDataContent();
|
||||
|
||||
mDiffNoteValues.clear();
|
||||
mIsCreate = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
|
||||
/*
|
||||
* 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.Builder builder = new Notification.Builder(mContext);
|
||||
builder.setContentTitle(mContext.getString(R.string.app_name));
|
||||
builder.setContentText(content);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
notification = builder.getNotification();
|
||||
/*notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
|
||||
pendingIntent);*/
|
||||
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,392 @@
|
||||
/*
|
||||
* 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
|
||||
private 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 String mTop;
|
||||
|
||||
private NoteSettingChangedListener mNoteSettingStatusListener;
|
||||
|
||||
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;
|
||||
|
||||
private static final int NOTE_TOP_COLUMN = 6 ;
|
||||
|
||||
// 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;
|
||||
mTop = "0" ;
|
||||
}
|
||||
|
||||
// Existing note construct
|
||||
private WorkingNote(Context context, long noteId, long folderId) {
|
||||
mContext = context;
|
||||
mNoteId = noteId;
|
||||
mFolderId = folderId;
|
||||
mIsDeleted = false;
|
||||
mNote = new Note();
|
||||
mTop = "0" ;
|
||||
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 setTop(String Top){
|
||||
if (Top != mTop){
|
||||
mTop = Top;
|
||||
mNote.setTopValue(NoteColumns.TOP,mTop);
|
||||
}
|
||||
}
|
||||
|
||||
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 getTopId() {
|
||||
if (mTop.equals("1")) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getWidgetType() {
|
||||
return mWidgetType;
|
||||
}
|
||||
|
||||
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,888 @@
|
||||
/*
|
||||
* 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.AlarmManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.SearchManager;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.style.BackgroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
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.TextNote;
|
||||
import net.micode.notes.model.WorkingNote;
|
||||
import net.micode.notes.model.WorkingNote.NoteSettingChangedListener;
|
||||
import net.micode.notes.tool.DataUtils;
|
||||
import net.micode.notes.tool.ResourceParser;
|
||||
import net.micode.notes.tool.ResourceParser.TextAppearanceResources;
|
||||
import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener;
|
||||
import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
|
||||
import net.micode.notes.widget.NoteWidgetProvider_2x;
|
||||
import net.micode.notes.widget.NoteWidgetProvider_4x;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.content.Intent;
|
||||
|
||||
|
||||
|
||||
public class NoteEditActivity extends Activity implements OnClickListener,
|
||||
NoteSettingChangedListener, OnTextViewChangeListener {
|
||||
private class HeadViewHolder {
|
||||
public TextView tvModified;
|
||||
|
||||
public ImageView ivAlertIcon;
|
||||
|
||||
public TextView tvAlertDate;
|
||||
|
||||
public ImageView ibSetBgColor;
|
||||
}
|
||||
|
||||
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
||||
static {
|
||||
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
||||
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
|
||||
sBgSelectorBtnsMap.put(R.id.iv_bg_blue, ResourceParser.BLUE);
|
||||
sBgSelectorBtnsMap.put(R.id.iv_bg_green, ResourceParser.GREEN);
|
||||
sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE);
|
||||
}
|
||||
|
||||
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
||||
static {
|
||||
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
||||
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
|
||||
sBgSelectorSelectionMap.put(ResourceParser.BLUE, R.id.iv_bg_blue_select);
|
||||
sBgSelectorSelectionMap.put(ResourceParser.GREEN, R.id.iv_bg_green_select);
|
||||
sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
|
||||
}
|
||||
|
||||
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
||||
static {
|
||||
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
|
||||
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
|
||||
sFontSizeBtnsMap.put(R.id.ll_font_normal, ResourceParser.TEXT_MEDIUM);
|
||||
sFontSizeBtnsMap.put(R.id.ll_font_super, ResourceParser.TEXT_SUPER);
|
||||
}
|
||||
|
||||
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
||||
static {
|
||||
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
||||
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
|
||||
sFontSelectorSelectionMap.put(ResourceParser.TEXT_MEDIUM, R.id.iv_medium_select);
|
||||
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
|
||||
}
|
||||
|
||||
private static final String TAG = "NoteEditActivity";
|
||||
|
||||
private HeadViewHolder mNoteHeaderHolder;
|
||||
|
||||
private View mHeadViewPanel;
|
||||
|
||||
private View mNoteBgColorSelector;
|
||||
|
||||
private View mFontSizeSelector;
|
||||
|
||||
private EditText mNoteEditor;
|
||||
|
||||
private View mNoteEditorPanel;
|
||||
|
||||
private WorkingNote mWorkingNote;
|
||||
|
||||
private SharedPreferences mSharedPrefs;
|
||||
private int mFontSizeId;
|
||||
|
||||
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
|
||||
|
||||
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10;
|
||||
|
||||
public static final String TAG_CHECKED = String.valueOf('\u221A');
|
||||
public static final String TAG_UNCHECKED = String.valueOf('\u25A1');
|
||||
|
||||
private LinearLayout mEditTextList;
|
||||
|
||||
private String mUserQuery;
|
||||
private Pattern mPattern;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setContentView(R.layout.note_edit);
|
||||
|
||||
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
initResources();
|
||||
}
|
||||
|
||||
/**
|
||||
* Current activity may be killed when the memory is low. Once it is killed, for another time
|
||||
* user load this activity, we should restore the former state
|
||||
*/
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));
|
||||
if (!initActivityState(intent)) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Restoring from killed activity");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean initActivityState(Intent intent) {
|
||||
/**
|
||||
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
|
||||
* then jump to the NotesListActivity
|
||||
*/
|
||||
mWorkingNote = null;
|
||||
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
|
||||
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
|
||||
mUserQuery = "";
|
||||
|
||||
/**
|
||||
* Starting from the searched result
|
||||
*/
|
||||
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
|
||||
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
|
||||
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
||||
}
|
||||
|
||||
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
|
||||
Intent jump = new Intent(this, NotesListActivity.class);
|
||||
startActivity(jump);
|
||||
showToast(R.string.error_note_not_exist);
|
||||
finish();
|
||||
return false;
|
||||
} else {
|
||||
mWorkingNote = WorkingNote.load(this, noteId);
|
||||
if (mWorkingNote == null) {
|
||||
Log.e(TAG, "load note failed with note id" + noteId);
|
||||
finish();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
getWindow().setSoftInputMode(
|
||||
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
||||
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
||||
// New note
|
||||
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
||||
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
||||
AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE,
|
||||
Notes.TYPE_WIDGET_INVALIDE);
|
||||
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
|
||||
ResourceParser.getDefaultBgId(this));
|
||||
|
||||
// Parse call-record note
|
||||
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
||||
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
|
||||
if (callDate != 0 && phoneNumber != null) {
|
||||
if (TextUtils.isEmpty(phoneNumber)) {
|
||||
Log.w(TAG, "The call record number is null");
|
||||
}
|
||||
long noteId = 0;
|
||||
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
|
||||
phoneNumber, callDate)) > 0) {
|
||||
mWorkingNote = WorkingNote.load(this, noteId);
|
||||
if (mWorkingNote == null) {
|
||||
Log.e(TAG, "load call note failed with note id" + noteId);
|
||||
finish();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
|
||||
widgetType, bgResId);
|
||||
mWorkingNote.convertToCallNote(phoneNumber, callDate);
|
||||
}
|
||||
} else {
|
||||
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
|
||||
bgResId);
|
||||
}
|
||||
|
||||
getWindow().setSoftInputMode(
|
||||
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
||||
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
} else {
|
||||
Log.e(TAG, "Intent not specified action, should not support");
|
||||
finish();
|
||||
return false;
|
||||
}
|
||||
mWorkingNote.setOnSettingStatusChangedListener(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
initNoteScreen();
|
||||
}
|
||||
|
||||
private void initNoteScreen() {
|
||||
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
||||
.getTexAppearanceResource(mFontSizeId));
|
||||
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
||||
switchToListMode(mWorkingNote.getContent());
|
||||
} else {
|
||||
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
||||
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
||||
}
|
||||
for (Integer id : sBgSelectorSelectionMap.keySet()) {
|
||||
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
|
||||
}
|
||||
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
||||
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
||||
|
||||
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this,
|
||||
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
|
||||
| DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME
|
||||
| DateUtils.FORMAT_SHOW_YEAR));
|
||||
|
||||
/**
|
||||
* TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker
|
||||
* is not ready
|
||||
*/
|
||||
showAlertHeader();
|
||||
}
|
||||
|
||||
private void showAlertHeader() {
|
||||
if (mWorkingNote.hasClockAlert()) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (time > mWorkingNote.getAlertDate()) {
|
||||
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
|
||||
} else {
|
||||
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
|
||||
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
|
||||
}
|
||||
mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
|
||||
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
||||
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
initActivityState(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
/**
|
||||
* For new note without note id, we should firstly save it to
|
||||
* generate a id. If the editing note is not worth saving, there
|
||||
* is no id which is equivalent to create new note
|
||||
*/
|
||||
if (!mWorkingNote.existInDatabase()) {
|
||||
saveNote();
|
||||
}
|
||||
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
||||
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
|
||||
&& !inRangeOfView(mNoteBgColorSelector, ev)) {
|
||||
mNoteBgColorSelector.setVisibility(View.GONE);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mFontSizeSelector.getVisibility() == View.VISIBLE
|
||||
&& !inRangeOfView(mFontSizeSelector, ev)) {
|
||||
mFontSizeSelector.setVisibility(View.GONE);
|
||||
return true;
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
private boolean inRangeOfView(View view, MotionEvent ev) {
|
||||
int []location = new int[2];
|
||||
view.getLocationOnScreen(location);
|
||||
int x = location[0];
|
||||
int y = location[1];
|
||||
if (ev.getX() < x
|
||||
|| ev.getX() > (x + view.getWidth())
|
||||
|| ev.getY() < y
|
||||
|| ev.getY() > (y + view.getHeight())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void initResources() {
|
||||
mHeadViewPanel = findViewById(R.id.note_title);
|
||||
mNoteHeaderHolder = new HeadViewHolder();
|
||||
mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date);
|
||||
mNoteHeaderHolder.ivAlertIcon = (ImageView) findViewById(R.id.iv_alert_icon);
|
||||
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
|
||||
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
|
||||
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
|
||||
mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
|
||||
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
|
||||
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
|
||||
for (int id : sBgSelectorBtnsMap.keySet()) {
|
||||
ImageView iv = (ImageView) findViewById(id);
|
||||
iv.setOnClickListener(this);
|
||||
}
|
||||
|
||||
mFontSizeSelector = findViewById(R.id.font_size_selector);
|
||||
for (int id : sFontSizeBtnsMap.keySet()) {
|
||||
View view = findViewById(id);
|
||||
view.setOnClickListener(this);
|
||||
};
|
||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
|
||||
/**
|
||||
* HACKME: Fix bug of store the resource id in shared preference.
|
||||
* The id may larger than the length of resources, in this case,
|
||||
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
|
||||
*/
|
||||
if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
|
||||
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
|
||||
}
|
||||
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if(saveNote()) {
|
||||
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
|
||||
}
|
||||
clearSettingState();
|
||||
}
|
||||
|
||||
private void updateWidget() {
|
||||
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
||||
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
||||
intent.setClass(this, NoteWidgetProvider_2x.class);
|
||||
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {
|
||||
intent.setClass(this, NoteWidgetProvider_4x.class);
|
||||
} else {
|
||||
Log.e(TAG, "Unspported widget type");
|
||||
return;
|
||||
}
|
||||
|
||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
||||
mWorkingNote.getWidgetId()
|
||||
});
|
||||
|
||||
sendBroadcast(intent);
|
||||
setResult(RESULT_OK, intent);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
if (id == R.id.btn_set_bg_color) {
|
||||
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
||||
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
||||
- View.VISIBLE);
|
||||
} else if (sBgSelectorBtnsMap.containsKey(id)) {
|
||||
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
||||
View.GONE);
|
||||
mWorkingNote.setBgColorId(sBgSelectorBtnsMap.get(id));
|
||||
mNoteBgColorSelector.setVisibility(View.GONE);
|
||||
} else if (sFontSizeBtnsMap.containsKey(id)) {
|
||||
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.GONE);
|
||||
mFontSizeId = sFontSizeBtnsMap.get(id);
|
||||
mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit();
|
||||
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
|
||||
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
||||
getWorkingText();
|
||||
switchToListMode(mWorkingNote.getContent());
|
||||
} else {
|
||||
mNoteEditor.setTextAppearance(this,
|
||||
TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
||||
}
|
||||
mFontSizeSelector.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if(clearSettingState()) {
|
||||
return;
|
||||
}
|
||||
|
||||
saveNote();
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
private boolean clearSettingState() {
|
||||
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
|
||||
mNoteBgColorSelector.setVisibility(View.GONE);
|
||||
return true;
|
||||
} else if (mFontSizeSelector.getVisibility() == View.VISIBLE) {
|
||||
mFontSizeSelector.setVisibility(View.GONE);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onBackgroundColorChanged() {
|
||||
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
||||
View.VISIBLE);
|
||||
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
|
||||
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
if (isFinishing()) {
|
||||
return true;
|
||||
}
|
||||
clearSettingState();
|
||||
menu.clear();
|
||||
if (mWorkingNote.getFolderId() == Notes.ID_CALL_RECORD_FOLDER) {
|
||||
getMenuInflater().inflate(R.menu.call_note_edit, menu);
|
||||
} else {
|
||||
getMenuInflater().inflate(R.menu.note_edit, menu);
|
||||
}
|
||||
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
||||
menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_normal_mode);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_list_mode);
|
||||
}
|
||||
if (mWorkingNote.hasClockAlert()) {
|
||||
menu.findItem(R.id.menu_alert).setVisible(false);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_delete_remind).setVisible(false);
|
||||
}
|
||||
if (mWorkingNote.getTopId() == 1) {
|
||||
menu.findItem(R.id.top).setTitle("取消置顶");
|
||||
} else if(mWorkingNote.getTopId() == 0){
|
||||
menu.findItem(R.id.top).setTitle("置顶");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
//////////////////
|
||||
final Button topBtn = (Button) findViewById(R.id.top);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_new_note:
|
||||
createNewNote();
|
||||
break;
|
||||
case R.id.menu_delete:
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(getString(R.string.alert_title_delete));
|
||||
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
||||
builder.setMessage(getString(R.string.alert_message_delete_note));
|
||||
builder.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
deleteCurrentNote();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
builder.show();
|
||||
break;
|
||||
case R.id.menu_font_size:
|
||||
mFontSizeSelector.setVisibility(View.VISIBLE);
|
||||
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case R.id.menu_list_mode:
|
||||
mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ?
|
||||
TextNote.MODE_CHECK_LIST : 0);
|
||||
break;
|
||||
case R.id.menu_share:
|
||||
getWorkingText();
|
||||
sendTo(this, mWorkingNote.getContent());
|
||||
break;
|
||||
case R.id.menu_send_to_desktop:
|
||||
sendToDesktop();
|
||||
break;
|
||||
case R.id.menu_alert:
|
||||
setReminder();
|
||||
break;
|
||||
case R.id.menu_delete_remind:
|
||||
mWorkingNote.setAlertDate(0, false);
|
||||
break;
|
||||
case R.id.top:
|
||||
mWorkingNote.setTop((mWorkingNote.getTopId()) == 1 ? "0" : "1");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setReminder() {
|
||||
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
||||
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
||||
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
||||
mWorkingNote.setAlertDate(date , true);
|
||||
}
|
||||
});
|
||||
d.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
||||
* and {@text/plain} type
|
||||
*/
|
||||
private void sendTo(Context context, String info) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, info);
|
||||
intent.setType("text/plain");
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
private void createNewNote() {
|
||||
// Firstly, save current editing notes
|
||||
saveNote();
|
||||
|
||||
// For safety, start a new NoteEditActivity
|
||||
finish();
|
||||
Intent intent = new Intent(this, NoteEditActivity.class);
|
||||
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
|
||||
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void deleteCurrentNote() {
|
||||
if (mWorkingNote.existInDatabase()) {
|
||||
HashSet<Long> ids = new HashSet<Long>();
|
||||
long id = mWorkingNote.getNoteId();
|
||||
if (id != Notes.ID_ROOT_FOLDER) {
|
||||
ids.add(id);
|
||||
} else {
|
||||
Log.d(TAG, "Wrong note id, should not happen");
|
||||
}
|
||||
if (!isSyncMode()) {
|
||||
if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) {
|
||||
Log.e(TAG, "Delete Note error");
|
||||
}
|
||||
} else {
|
||||
if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) {
|
||||
Log.e(TAG, "Move notes to trash folder error, should not happens");
|
||||
}
|
||||
}
|
||||
}
|
||||
mWorkingNote.markDeleted(true);
|
||||
}
|
||||
|
||||
private boolean isSyncMode() {
|
||||
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
|
||||
}
|
||||
|
||||
public void onClockAlertChanged(long date, boolean set) {
|
||||
/**
|
||||
* User could set clock to an unsaved note, so before setting the
|
||||
* alert clock, we should save the note first
|
||||
*/
|
||||
if (!mWorkingNote.existInDatabase()) {
|
||||
saveNote();
|
||||
}
|
||||
if (mWorkingNote.getNoteId() > 0) {
|
||||
Intent intent = new Intent(this, AlarmReceiver.class);
|
||||
intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId()));
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
|
||||
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
|
||||
showAlertHeader();
|
||||
if(!set) {
|
||||
alarmManager.cancel(pendingIntent);
|
||||
} else {
|
||||
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* There is the condition that user has input nothing (the note is
|
||||
* not worthy saving), we have no note id, remind the user that he
|
||||
* should input something
|
||||
*/
|
||||
Log.e(TAG, "Clock alert setting error");
|
||||
showToast(R.string.error_note_empty_for_clock);
|
||||
}
|
||||
}
|
||||
|
||||
public void onWidgetChanged() {
|
||||
updateWidget();
|
||||
}
|
||||
|
||||
public void onEditTextDelete(int index, String text) {
|
||||
int childCount = mEditTextList.getChildCount();
|
||||
if (childCount == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = index + 1; i < childCount; i++) {
|
||||
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
||||
.setIndex(i - 1);
|
||||
}
|
||||
|
||||
mEditTextList.removeViewAt(index);
|
||||
NoteEditText edit = null;
|
||||
if(index == 0) {
|
||||
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
||||
R.id.et_edit_text);
|
||||
} else {
|
||||
edit = (NoteEditText) mEditTextList.getChildAt(index - 1).findViewById(
|
||||
R.id.et_edit_text);
|
||||
}
|
||||
int length = edit.length();
|
||||
edit.append(text);
|
||||
edit.requestFocus();
|
||||
edit.setSelection(length);
|
||||
}
|
||||
|
||||
public void onEditTextEnter(int index, String text) {
|
||||
/**
|
||||
* Should not happen, check for debug
|
||||
*/
|
||||
if(index > mEditTextList.getChildCount()) {
|
||||
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
|
||||
}
|
||||
|
||||
View view = getListItem(text, index);
|
||||
mEditTextList.addView(view, index);
|
||||
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
||||
edit.requestFocus();
|
||||
edit.setSelection(0);
|
||||
for (int i = index + 1; i < mEditTextList.getChildCount(); i++) {
|
||||
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
|
||||
.setIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void switchToListMode(String text) {
|
||||
mEditTextList.removeAllViews();
|
||||
String[] items = text.split("\n");
|
||||
int index = 0;
|
||||
for (String item : items) {
|
||||
if(!TextUtils.isEmpty(item)) {
|
||||
mEditTextList.addView(getListItem(item, index));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
mEditTextList.addView(getListItem("", index));
|
||||
mEditTextList.getChildAt(index).findViewById(R.id.et_edit_text).requestFocus();
|
||||
|
||||
mNoteEditor.setVisibility(View.GONE);
|
||||
mEditTextList.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
|
||||
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
|
||||
if (!TextUtils.isEmpty(userQuery)) {
|
||||
mPattern = Pattern.compile(userQuery);
|
||||
Matcher m = mPattern.matcher(fullText);
|
||||
int start = 0;
|
||||
while (m.find(start)) {
|
||||
spannable.setSpan(
|
||||
new BackgroundColorSpan(this.getResources().getColor(
|
||||
R.color.user_query_highlight)), m.start(), m.end(),
|
||||
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
start = m.end();
|
||||
}
|
||||
}
|
||||
return spannable;
|
||||
}
|
||||
|
||||
private View getListItem(String item, int index) {
|
||||
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
|
||||
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
||||
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
|
||||
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
|
||||
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
} else {
|
||||
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (item.startsWith(TAG_CHECKED)) {
|
||||
cb.setChecked(true);
|
||||
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
item = item.substring(TAG_CHECKED.length(), item.length()).trim();
|
||||
} else if (item.startsWith(TAG_UNCHECKED)) {
|
||||
cb.setChecked(false);
|
||||
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
|
||||
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim();
|
||||
}
|
||||
|
||||
edit.setOnTextViewChangeListener(this);
|
||||
edit.setIndex(index);
|
||||
edit.setText(getHighlightQueryResult(item, mUserQuery));
|
||||
return view;
|
||||
}
|
||||
|
||||
public void onTextChange(int index, boolean hasText) {
|
||||
if (index >= mEditTextList.getChildCount()) {
|
||||
Log.e(TAG, "Wrong index, should not happen");
|
||||
return;
|
||||
}
|
||||
if(hasText) {
|
||||
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void onCheckListModeChanged(int oldMode, int newMode) {
|
||||
if (newMode == TextNote.MODE_CHECK_LIST) {
|
||||
switchToListMode(mNoteEditor.getText().toString());
|
||||
} else {
|
||||
if (!getWorkingText()) {
|
||||
mWorkingNote.setWorkingText(mWorkingNote.getContent().replace(TAG_UNCHECKED + " ",
|
||||
""));
|
||||
}
|
||||
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
||||
mEditTextList.setVisibility(View.GONE);
|
||||
mNoteEditor.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getWorkingText() {
|
||||
boolean hasChecked = false;
|
||||
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
|
||||
View view = mEditTextList.getChildAt(i);
|
||||
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
|
||||
if (!TextUtils.isEmpty(edit.getText())) {
|
||||
if (((CheckBox) view.findViewById(R.id.cb_edit_item)).isChecked()) {
|
||||
sb.append(TAG_CHECKED).append(" ").append(edit.getText()).append("\n");
|
||||
hasChecked = true;
|
||||
} else {
|
||||
sb.append(TAG_UNCHECKED).append(" ").append(edit.getText()).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
mWorkingNote.setWorkingText(sb.toString());
|
||||
} else {
|
||||
mWorkingNote.setWorkingText(mNoteEditor.getText().toString());
|
||||
}
|
||||
return hasChecked;
|
||||
}
|
||||
|
||||
private boolean saveNote() {
|
||||
getWorkingText();
|
||||
boolean saved = mWorkingNote.saveNote();
|
||||
if (saved) {
|
||||
/**
|
||||
* There are two modes from List view to edit view, open one note,
|
||||
* create/edit a node. Opening node requires to the original
|
||||
* position in the list when back from edit view, while creating a
|
||||
* new node requires to the top of the list. This code
|
||||
* {@link #RESULT_OK} is used to identify the create/edit state
|
||||
*/
|
||||
setResult(RESULT_OK);
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
private void sendToDesktop() {
|
||||
/**
|
||||
* Before send message to home, we should make sure that current
|
||||
* editing note is exists in databases. So, for new note, firstly
|
||||
* save it
|
||||
*/
|
||||
if (!mWorkingNote.existInDatabase()) {
|
||||
saveNote();
|
||||
}
|
||||
|
||||
if (mWorkingNote.getNoteId() > 0) {
|
||||
Intent sender = new Intent();
|
||||
Intent shortcutIntent = new Intent(this, NoteEditActivity.class);
|
||||
shortcutIntent.setAction(Intent.ACTION_VIEW);
|
||||
shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
|
||||
sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||
sender.putExtra(Intent.EXTRA_SHORTCUT_NAME,
|
||||
makeShortcutIconTitle(mWorkingNote.getContent()));
|
||||
sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
|
||||
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app));
|
||||
sender.putExtra("duplicate", true);
|
||||
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
||||
showToast(R.string.info_note_enter_desktop);
|
||||
sendBroadcast(sender);
|
||||
} else {
|
||||
/**
|
||||
* There is the condition that user has input nothing (the note is
|
||||
* not worthy saving), we have no note id, remind the user that he
|
||||
* should input something
|
||||
*/
|
||||
Log.e(TAG, "Send to desktop error");
|
||||
showToast(R.string.error_note_empty_for_send_to_desktop);
|
||||
}
|
||||
}
|
||||
|
||||
private String makeShortcutIconTitle(String content) {
|
||||
content = content.replace(TAG_CHECKED, "");
|
||||
content = content.replace(TAG_UNCHECKED, "");
|
||||
return content.length() > SHORTCUT_ICON_TITLE_MAX_LEN ? content.substring(0,
|
||||
SHORTCUT_ICON_TITLE_MAX_LEN) : content;
|
||||
}
|
||||
|
||||
private void showToast(int resId) {
|
||||
showToast(resId, Toast.LENGTH_SHORT);
|
||||
}
|
||||
|
||||
private void showToast(int resId, int duration) {
|
||||
Toast.makeText(this, resId, duration).show();
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{}
|
@ -0,0 +1 @@
|
||||
{}
|
@ -0,0 +1 @@
|
||||
{}
|
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
appMetadataVersion=1.0
|
||||
androidGradlePluginVersion=7.0.2
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "COMPATIBLE_SCREEN_MANIFEST",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "net.micode.notes",
|
||||
"variantName": "debug",
|
||||
"elements": []
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue