Compare commits
67 Commits
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.micode.notes.data;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
|
||||||
import android.provider.ContactsContract.Data;
|
|
||||||
import android.telephony.PhoneNumberUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class Contact {
|
|
||||||
private static HashMap<String, String> sContactCache;
|
|
||||||
private static final String TAG = "Contact";
|
|
||||||
|
|
||||||
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
|
|
||||||
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
|
|
||||||
+ " AND " + Data.RAW_CONTACT_ID + " IN "
|
|
||||||
+ "(SELECT raw_contact_id "
|
|
||||||
+ " FROM phone_lookup"
|
|
||||||
+ " WHERE min_match = '+')";
|
|
||||||
|
|
||||||
public static String getContact(Context context, String phoneNumber) {
|
|
||||||
if(sContactCache == null) {
|
|
||||||
sContactCache = new HashMap<String, String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(sContactCache.containsKey(phoneNumber)) {
|
|
||||||
return sContactCache.get(phoneNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
String selection = CALLER_ID_SELECTION.replace("+",
|
|
||||||
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
|
|
||||||
Cursor cursor = context.getContentResolver().query(
|
|
||||||
Data.CONTENT_URI,
|
|
||||||
new String [] { Phone.DISPLAY_NAME },
|
|
||||||
selection,
|
|
||||||
new String[] { phoneNumber },
|
|
||||||
null);
|
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
|
||||||
try {
|
|
||||||
String name = cursor.getString(0);
|
|
||||||
sContactCache.put(phoneNumber, name);
|
|
||||||
return name;
|
|
||||||
} catch (IndexOutOfBoundsException e) {
|
|
||||||
Log.e(TAG, " Cursor get string error " + e.toString());
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.d(TAG, "No contact matched with number:" + phoneNumber);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,362 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* 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" +
|
|
||||||
")";
|
|
||||||
|
|
||||||
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 (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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* 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.database.Cursor;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import net.micode.notes.tool.GTaskStringUtils;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
|
|
||||||
public class MetaData extends Task {
|
|
||||||
private final static String TAG = MetaData.class.getSimpleName();
|
|
||||||
|
|
||||||
private String mRelatedGid = null;
|
|
||||||
|
|
||||||
public void setMeta(String gid, JSONObject metaInfo) {
|
|
||||||
try {
|
|
||||||
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Log.e(TAG, "failed to put related gid");
|
|
||||||
}
|
|
||||||
setNotes(metaInfo.toString());
|
|
||||||
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRelatedGid() {
|
|
||||||
return mRelatedGid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isWorthSaving() {
|
|
||||||
return getNotes() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContentByRemoteJSON(JSONObject js) {
|
|
||||||
super.setContentByRemoteJSON(js);
|
|
||||||
if (getNotes() != null) {
|
|
||||||
try {
|
|
||||||
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
||||||
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Log.w(TAG, "failed to get related gid");
|
|
||||||
mRelatedGid = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContentByLocalJSON(JSONObject js) {
|
|
||||||
// this function should not be called
|
|
||||||
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JSONObject getLocalJSONFromContent() {
|
|
||||||
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSyncAction(Cursor c) {
|
|
||||||
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* 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.database.Cursor;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
public abstract class Node {
|
|
||||||
public static final int SYNC_ACTION_NONE = 0;
|
|
||||||
|
|
||||||
public static final int SYNC_ACTION_ADD_REMOTE = 1;
|
|
||||||
|
|
||||||
public static final int SYNC_ACTION_ADD_LOCAL = 2;
|
|
||||||
|
|
||||||
public static final int SYNC_ACTION_DEL_REMOTE = 3;
|
|
||||||
|
|
||||||
public static final int SYNC_ACTION_DEL_LOCAL = 4;
|
|
||||||
|
|
||||||
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;
|
|
||||||
|
|
||||||
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;
|
|
||||||
|
|
||||||
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
|
|
||||||
|
|
||||||
public static final int SYNC_ACTION_ERROR = 8;
|
|
||||||
|
|
||||||
private String mGid;
|
|
||||||
|
|
||||||
private String mName;
|
|
||||||
|
|
||||||
private long mLastModified;
|
|
||||||
|
|
||||||
private boolean mDeleted;
|
|
||||||
|
|
||||||
public Node() {
|
|
||||||
mGid = null;
|
|
||||||
mName = "";
|
|
||||||
mLastModified = 0;
|
|
||||||
mDeleted = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract JSONObject getCreateAction(int actionId);
|
|
||||||
|
|
||||||
public abstract JSONObject getUpdateAction(int actionId);
|
|
||||||
|
|
||||||
public abstract void setContentByRemoteJSON(JSONObject js);
|
|
||||||
|
|
||||||
public abstract void setContentByLocalJSON(JSONObject js);
|
|
||||||
|
|
||||||
public abstract JSONObject getLocalJSONFromContent();
|
|
||||||
|
|
||||||
public abstract int getSyncAction(Cursor c);
|
|
||||||
|
|
||||||
public void setGid(String gid) {
|
|
||||||
this.mGid = gid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.mName = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastModified(long lastModified) {
|
|
||||||
this.mLastModified = lastModified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeleted(boolean deleted) {
|
|
||||||
this.mDeleted = deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGid() {
|
|
||||||
return this.mGid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.mName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastModified() {
|
|
||||||
return this.mLastModified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getDeleted() {
|
|
||||||
return this.mDeleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,505 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* 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
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
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>();
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,113 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.micode.notes.tool;
|
|
||||||
|
|
||||||
public class GTaskStringUtils {
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ACTION_ID = "action_id";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ACTION_LIST = "action_list";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ACTION_TYPE = "action_type";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_COMPLETED = "completed";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_DELETED = "deleted";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_DEST_LIST = "dest_list";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_ID = "id";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_INDEX = "index";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_LIST_ID = "list_id";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_LISTS = "lists";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_NAME = "name";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_NEW_ID = "new_id";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_NOTES = "notes";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_PARENT_ID = "parent_id";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_RESULTS = "results";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_TASKS = "tasks";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_TYPE = "type";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_TYPE_TASK = "TASK";
|
|
||||||
|
|
||||||
public final static String GTASK_JSON_USER = "user";
|
|
||||||
|
|
||||||
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";
|
|
||||||
|
|
||||||
public final static String FOLDER_DEFAULT = "Default";
|
|
||||||
|
|
||||||
public final static String FOLDER_CALL_NOTE = "Call_Note";
|
|
||||||
|
|
||||||
public final static String FOLDER_META = "METADATA";
|
|
||||||
|
|
||||||
public final static String META_HEAD_GTASK_ID = "meta_gid";
|
|
||||||
|
|
||||||
public final static String META_HEAD_NOTE = "meta_note";
|
|
||||||
|
|
||||||
public final static String META_HEAD_DATA = "meta_data";
|
|
||||||
|
|
||||||
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.micode.notes.ui;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
public class AlarmReceiver extends BroadcastReceiver {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
intent.setClass(context, AlarmAlertActivity.class);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* 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 java.util.Calendar;
|
|
||||||
|
|
||||||
import net.micode.notes.R;
|
|
||||||
import net.micode.notes.ui.DateTimePicker;
|
|
||||||
import net.micode.notes.ui.DateTimePicker.OnDateTimeChangedListener;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.DialogInterface.OnClickListener;
|
|
||||||
import android.text.format.DateFormat;
|
|
||||||
import android.text.format.DateUtils;
|
|
||||||
|
|
||||||
public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
|
|
||||||
|
|
||||||
private Calendar mDate = Calendar.getInstance();
|
|
||||||
private boolean mIs24HourView;
|
|
||||||
private OnDateTimeSetListener mOnDateTimeSetListener;
|
|
||||||
private DateTimePicker mDateTimePicker;
|
|
||||||
|
|
||||||
public interface OnDateTimeSetListener {
|
|
||||||
void OnDateTimeSet(AlertDialog dialog, long date);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DateTimePickerDialog(Context context, long date) {
|
|
||||||
super(context);
|
|
||||||
mDateTimePicker = new DateTimePicker(context);
|
|
||||||
setView(mDateTimePicker);
|
|
||||||
mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() {
|
|
||||||
public void onDateTimeChanged(DateTimePicker view, int year, int month,
|
|
||||||
int dayOfMonth, int hourOfDay, int minute) {
|
|
||||||
mDate.set(Calendar.YEAR, year);
|
|
||||||
mDate.set(Calendar.MONTH, month);
|
|
||||||
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
|
||||||
mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
|
||||||
mDate.set(Calendar.MINUTE, minute);
|
|
||||||
updateTitle(mDate.getTimeInMillis());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mDate.setTimeInMillis(date);
|
|
||||||
mDate.set(Calendar.SECOND, 0);
|
|
||||||
mDateTimePicker.setCurrentDate(mDate.getTimeInMillis());
|
|
||||||
setButton(context.getString(R.string.datetime_dialog_ok), this);
|
|
||||||
setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener)null);
|
|
||||||
set24HourView(DateFormat.is24HourFormat(this.getContext()));
|
|
||||||
updateTitle(mDate.getTimeInMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set24HourView(boolean is24HourView) {
|
|
||||||
mIs24HourView = is24HourView;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
|
|
||||||
mOnDateTimeSetListener = callBack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTitle(long date) {
|
|
||||||
int flag =
|
|
||||||
DateUtils.FORMAT_SHOW_YEAR |
|
|
||||||
DateUtils.FORMAT_SHOW_DATE |
|
|
||||||
DateUtils.FORMAT_SHOW_TIME;
|
|
||||||
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR;
|
|
||||||
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(DialogInterface arg0, int arg1) {
|
|
||||||
if (mOnDateTimeSetListener != null) {
|
|
||||||
mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.micode.notes.ui;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.CursorAdapter;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import net.micode.notes.R;
|
|
||||||
import net.micode.notes.data.Notes;
|
|
||||||
import net.micode.notes.data.Notes.NoteColumns;
|
|
||||||
|
|
||||||
|
|
||||||
public class FoldersListAdapter extends CursorAdapter {
|
|
||||||
public static final String [] PROJECTION = {
|
|
||||||
NoteColumns.ID,
|
|
||||||
NoteColumns.SNIPPET
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final int ID_COLUMN = 0;
|
|
||||||
public static final int NAME_COLUMN = 1;
|
|
||||||
|
|
||||||
public FoldersListAdapter(Context context, Cursor c) {
|
|
||||||
super(context, c);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
||||||
return new FolderListItem(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
|
||||||
if (view instanceof FolderListItem) {
|
|
||||||
String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
|
|
||||||
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
|
|
||||||
((FolderListItem) view).bind(folderName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFolderName(Context context, int position) {
|
|
||||||
Cursor cursor = (Cursor) getItem(position);
|
|
||||||
return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
|
|
||||||
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class FolderListItem extends LinearLayout {
|
|
||||||
private TextView mName;
|
|
||||||
|
|
||||||
public FolderListItem(Context context) {
|
|
||||||
super(context);
|
|
||||||
inflate(context, R.layout.folder_list_item, this);
|
|
||||||
mName = (TextView) findViewById(R.id.tv_folder_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void bind(String name) {
|
|
||||||
mName.setText(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,184 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.micode.notes.ui;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.CursorAdapter;
|
|
||||||
|
|
||||||
import net.micode.notes.data.Notes;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
|
|
||||||
public class NotesListAdapter extends CursorAdapter {
|
|
||||||
private static final String TAG = "NotesListAdapter";
|
|
||||||
private Context mContext;
|
|
||||||
private HashMap<Integer, Boolean> mSelectedIndex;
|
|
||||||
private int mNotesCount;
|
|
||||||
private boolean mChoiceMode;
|
|
||||||
|
|
||||||
public static class AppWidgetAttribute {
|
|
||||||
public int widgetId;
|
|
||||||
public int widgetType;
|
|
||||||
};
|
|
||||||
|
|
||||||
public NotesListAdapter(Context context) {
|
|
||||||
super(context, null);
|
|
||||||
mSelectedIndex = new HashMap<Integer, Boolean>();
|
|
||||||
mContext = context;
|
|
||||||
mNotesCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
||||||
return new NotesListItem(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
|
||||||
if (view instanceof NotesListItem) {
|
|
||||||
NoteItemData itemData = new NoteItemData(context, cursor);
|
|
||||||
((NotesListItem) view).bind(context, itemData, mChoiceMode,
|
|
||||||
isSelectedItem(cursor.getPosition()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCheckedItem(final int position, final boolean checked) {
|
|
||||||
mSelectedIndex.put(position, checked);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInChoiceMode() {
|
|
||||||
return mChoiceMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChoiceMode(boolean mode) {
|
|
||||||
mSelectedIndex.clear();
|
|
||||||
mChoiceMode = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void selectAll(boolean checked) {
|
|
||||||
Cursor cursor = getCursor();
|
|
||||||
for (int i = 0; i < getCount(); i++) {
|
|
||||||
if (cursor.moveToPosition(i)) {
|
|
||||||
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
|
|
||||||
setCheckedItem(i, checked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashSet<Long> getSelectedItemIds() {
|
|
||||||
HashSet<Long> itemSet = new HashSet<Long>();
|
|
||||||
for (Integer position : mSelectedIndex.keySet()) {
|
|
||||||
if (mSelectedIndex.get(position) == true) {
|
|
||||||
Long id = getItemId(position);
|
|
||||||
if (id == Notes.ID_ROOT_FOLDER) {
|
|
||||||
Log.d(TAG, "Wrong item id, should not happen");
|
|
||||||
} else {
|
|
||||||
itemSet.add(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashSet<AppWidgetAttribute> getSelectedWidget() {
|
|
||||||
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
|
|
||||||
for (Integer position : mSelectedIndex.keySet()) {
|
|
||||||
if (mSelectedIndex.get(position) == true) {
|
|
||||||
Cursor c = (Cursor) getItem(position);
|
|
||||||
if (c != null) {
|
|
||||||
AppWidgetAttribute widget = new AppWidgetAttribute();
|
|
||||||
NoteItemData item = new NoteItemData(mContext, c);
|
|
||||||
widget.widgetId = item.getWidgetId();
|
|
||||||
widget.widgetType = item.getWidgetType();
|
|
||||||
itemSet.add(widget);
|
|
||||||
/**
|
|
||||||
* Don't close cursor here, only the adapter could close it
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Invalid cursor");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return itemSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSelectedCount() {
|
|
||||||
Collection<Boolean> values = mSelectedIndex.values();
|
|
||||||
if (null == values) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Iterator<Boolean> iter = values.iterator();
|
|
||||||
int count = 0;
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
if (true == iter.next()) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAllSelected() {
|
|
||||||
int checkedCount = getSelectedCount();
|
|
||||||
return (checkedCount != 0 && checkedCount == mNotesCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSelectedItem(final int position) {
|
|
||||||
if (null == mSelectedIndex.get(position)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mSelectedIndex.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onContentChanged() {
|
|
||||||
super.onContentChanged();
|
|
||||||
calcNotesCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void changeCursor(Cursor cursor) {
|
|
||||||
super.changeCursor(cursor);
|
|
||||||
calcNotesCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calcNotesCount() {
|
|
||||||
mNotesCount = 0;
|
|
||||||
for (int i = 0; i < getCount(); i++) {
|
|
||||||
Cursor c = (Cursor) getItem(i);
|
|
||||||
if (c != null) {
|
|
||||||
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
|
|
||||||
mNotesCount++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Invalid cursor");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,122 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.micode.notes.ui;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.text.format.DateUtils;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import net.micode.notes.R;
|
|
||||||
import net.micode.notes.data.Notes;
|
|
||||||
import net.micode.notes.tool.DataUtils;
|
|
||||||
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
|
|
||||||
|
|
||||||
|
|
||||||
public class NotesListItem extends LinearLayout {
|
|
||||||
private ImageView mAlert;
|
|
||||||
private TextView mTitle;
|
|
||||||
private TextView mTime;
|
|
||||||
private TextView mCallName;
|
|
||||||
private NoteItemData mItemData;
|
|
||||||
private CheckBox mCheckBox;
|
|
||||||
|
|
||||||
public NotesListItem(Context context) {
|
|
||||||
super(context);
|
|
||||||
inflate(context, R.layout.note_item, this);
|
|
||||||
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
||||||
mTitle = (TextView) findViewById(R.id.tv_title);
|
|
||||||
mTime = (TextView) findViewById(R.id.tv_time);
|
|
||||||
mCallName = (TextView) findViewById(R.id.tv_name);
|
|
||||||
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
|
|
||||||
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
|
|
||||||
mCheckBox.setVisibility(View.VISIBLE);
|
|
||||||
mCheckBox.setChecked(checked);
|
|
||||||
} else {
|
|
||||||
mCheckBox.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
mItemData = data;
|
|
||||||
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
||||||
mCallName.setVisibility(View.GONE);
|
|
||||||
mAlert.setVisibility(View.VISIBLE);
|
|
||||||
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
|
|
||||||
mTitle.setText(context.getString(R.string.call_record_folder_name)
|
|
||||||
+ context.getString(R.string.format_folder_files_count, data.getNotesCount()));
|
|
||||||
mAlert.setImageResource(R.drawable.call_record);
|
|
||||||
} else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
||||||
mCallName.setVisibility(View.VISIBLE);
|
|
||||||
mCallName.setText(data.getCallName());
|
|
||||||
mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem);
|
|
||||||
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
|
|
||||||
if (data.hasAlert()) {
|
|
||||||
mAlert.setImageResource(R.drawable.clock);
|
|
||||||
mAlert.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
mAlert.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mCallName.setVisibility(View.GONE);
|
|
||||||
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
|
|
||||||
|
|
||||||
if (data.getType() == Notes.TYPE_FOLDER) {
|
|
||||||
mTitle.setText(data.getSnippet()
|
|
||||||
+ context.getString(R.string.format_folder_files_count,
|
|
||||||
data.getNotesCount()));
|
|
||||||
mAlert.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
|
|
||||||
if (data.hasAlert()) {
|
|
||||||
mAlert.setImageResource(R.drawable.clock);
|
|
||||||
mAlert.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
mAlert.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
|
|
||||||
|
|
||||||
setBackground(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setBackground(NoteItemData data) {
|
|
||||||
int id = data.getBgColorId();
|
|
||||||
if (data.getType() == Notes.TYPE_NOTE) {
|
|
||||||
if (data.isSingle() || data.isOneFollowingFolder()) {
|
|
||||||
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
|
|
||||||
} else if (data.isLast()) {
|
|
||||||
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
|
|
||||||
} else if (data.isFirst() || data.isMultiFollowingFolder()) {
|
|
||||||
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
|
|
||||||
} else {
|
|
||||||
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoteItemData getItemData() {
|
|
||||||
return mItemData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,388 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.micode.notes.ui;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.accounts.AccountManager;
|
|
||||||
import android.app.ActionBar;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.preference.Preference;
|
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
import android.preference.PreferenceCategory;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.text.format.DateFormat;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import net.micode.notes.R;
|
|
||||||
import net.micode.notes.data.Notes;
|
|
||||||
import net.micode.notes.data.Notes.NoteColumns;
|
|
||||||
import net.micode.notes.gtask.remote.GTaskSyncService;
|
|
||||||
|
|
||||||
|
|
||||||
public class NotesPreferenceActivity extends PreferenceActivity {
|
|
||||||
public static final String PREFERENCE_NAME = "notes_preferences";
|
|
||||||
|
|
||||||
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
|
|
||||||
|
|
||||||
public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
|
|
||||||
|
|
||||||
public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
|
|
||||||
|
|
||||||
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
|
|
||||||
|
|
||||||
private static final String AUTHORITIES_FILTER_KEY = "authorities";
|
|
||||||
|
|
||||||
private PreferenceCategory mAccountCategory;
|
|
||||||
|
|
||||||
private GTaskReceiver mReceiver;
|
|
||||||
|
|
||||||
private Account[] mOriAccounts;
|
|
||||||
|
|
||||||
private boolean mHasAddedAccount;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
|
|
||||||
/* using the app icon for navigation */
|
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
|
||||||
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
|
|
||||||
mReceiver = new GTaskReceiver();
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
|
|
||||||
registerReceiver(mReceiver, filter);
|
|
||||||
|
|
||||||
mOriAccounts = null;
|
|
||||||
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
|
|
||||||
getListView().addHeaderView(header, null, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
|
|
||||||
// need to set sync account automatically if user has added a new
|
|
||||||
// account
|
|
||||||
if (mHasAddedAccount) {
|
|
||||||
Account[] accounts = getGoogleAccounts();
|
|
||||||
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
|
|
||||||
for (Account accountNew : accounts) {
|
|
||||||
boolean found = false;
|
|
||||||
for (Account accountOld : mOriAccounts) {
|
|
||||||
if (TextUtils.equals(accountOld.name, accountNew.name)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
setSyncAccount(accountNew.name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
if (mReceiver != null) {
|
|
||||||
unregisterReceiver(mReceiver);
|
|
||||||
}
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadAccountPreference() {
|
|
||||||
mAccountCategory.removeAll();
|
|
||||||
|
|
||||||
Preference accountPref = new Preference(this);
|
|
||||||
final String defaultAccount = getSyncAccountName(this);
|
|
||||||
accountPref.setTitle(getString(R.string.preferences_account_title));
|
|
||||||
accountPref.setSummary(getString(R.string.preferences_account_summary));
|
|
||||||
accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
|
||||||
if (!GTaskSyncService.isSyncing()) {
|
|
||||||
if (TextUtils.isEmpty(defaultAccount)) {
|
|
||||||
// the first time to set account
|
|
||||||
showSelectAccountAlertDialog();
|
|
||||||
} else {
|
|
||||||
// if the account has already been set, we need to promp
|
|
||||||
// user about the risk
|
|
||||||
showChangeAccountConfirmAlertDialog();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Toast.makeText(NotesPreferenceActivity.this,
|
|
||||||
R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mAccountCategory.addPreference(accountPref);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadSyncButton() {
|
|
||||||
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
|
|
||||||
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
|
|
||||||
|
|
||||||
// set button state
|
|
||||||
if (GTaskSyncService.isSyncing()) {
|
|
||||||
syncButton.setText(getString(R.string.preferences_button_sync_cancel));
|
|
||||||
syncButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
GTaskSyncService.cancelSync(NotesPreferenceActivity.this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
syncButton.setText(getString(R.string.preferences_button_sync_immediately));
|
|
||||||
syncButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
GTaskSyncService.startSync(NotesPreferenceActivity.this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
|
|
||||||
|
|
||||||
// set last sync time
|
|
||||||
if (GTaskSyncService.isSyncing()) {
|
|
||||||
lastSyncTimeView.setText(GTaskSyncService.getProgressString());
|
|
||||||
lastSyncTimeView.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
long lastSyncTime = getLastSyncTime(this);
|
|
||||||
if (lastSyncTime != 0) {
|
|
||||||
lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time,
|
|
||||||
DateFormat.format(getString(R.string.preferences_last_sync_time_format),
|
|
||||||
lastSyncTime)));
|
|
||||||
lastSyncTimeView.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
lastSyncTimeView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshUI() {
|
|
||||||
loadAccountPreference();
|
|
||||||
loadSyncButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showSelectAccountAlertDialog() {
|
|
||||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
||||||
|
|
||||||
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
|
||||||
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
|
||||||
titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
|
|
||||||
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
|
|
||||||
subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));
|
|
||||||
|
|
||||||
dialogBuilder.setCustomTitle(titleView);
|
|
||||||
dialogBuilder.setPositiveButton(null, null);
|
|
||||||
|
|
||||||
Account[] accounts = getGoogleAccounts();
|
|
||||||
String defAccount = getSyncAccountName(this);
|
|
||||||
|
|
||||||
mOriAccounts = accounts;
|
|
||||||
mHasAddedAccount = false;
|
|
||||||
|
|
||||||
if (accounts.length > 0) {
|
|
||||||
CharSequence[] items = new CharSequence[accounts.length];
|
|
||||||
final CharSequence[] itemMapping = items;
|
|
||||||
int checkedItem = -1;
|
|
||||||
int index = 0;
|
|
||||||
for (Account account : accounts) {
|
|
||||||
if (TextUtils.equals(account.name, defAccount)) {
|
|
||||||
checkedItem = index;
|
|
||||||
}
|
|
||||||
items[index++] = account.name;
|
|
||||||
}
|
|
||||||
dialogBuilder.setSingleChoiceItems(items, checkedItem,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
setSyncAccount(itemMapping[which].toString());
|
|
||||||
dialog.dismiss();
|
|
||||||
refreshUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
|
|
||||||
dialogBuilder.setView(addAccountView);
|
|
||||||
|
|
||||||
final AlertDialog dialog = dialogBuilder.show();
|
|
||||||
addAccountView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
mHasAddedAccount = true;
|
|
||||||
Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
|
|
||||||
intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
|
|
||||||
"gmail-ls"
|
|
||||||
});
|
|
||||||
startActivityForResult(intent, -1);
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showChangeAccountConfirmAlertDialog() {
|
|
||||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
||||||
|
|
||||||
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
|
||||||
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
|
||||||
titleTextView.setText(getString(R.string.preferences_dialog_change_account_title,
|
|
||||||
getSyncAccountName(this)));
|
|
||||||
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
|
|
||||||
subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
|
|
||||||
dialogBuilder.setCustomTitle(titleView);
|
|
||||||
|
|
||||||
CharSequence[] menuItemArray = new CharSequence[] {
|
|
||||||
getString(R.string.preferences_menu_change_account),
|
|
||||||
getString(R.string.preferences_menu_remove_account),
|
|
||||||
getString(R.string.preferences_menu_cancel)
|
|
||||||
};
|
|
||||||
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
if (which == 0) {
|
|
||||||
showSelectAccountAlertDialog();
|
|
||||||
} else if (which == 1) {
|
|
||||||
removeSyncAccount();
|
|
||||||
refreshUI();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dialogBuilder.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Account[] getGoogleAccounts() {
|
|
||||||
AccountManager accountManager = AccountManager.get(this);
|
|
||||||
return accountManager.getAccountsByType("com.google");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSyncAccount(String account) {
|
|
||||||
if (!getSyncAccountName(this).equals(account)) {
|
|
||||||
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
|
||||||
if (account != null) {
|
|
||||||
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account);
|
|
||||||
} else {
|
|
||||||
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
|
|
||||||
}
|
|
||||||
editor.commit();
|
|
||||||
|
|
||||||
// clean up last sync time
|
|
||||||
setLastSyncTime(this, 0);
|
|
||||||
|
|
||||||
// clean up local gtask related info
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(NoteColumns.GTASK_ID, "");
|
|
||||||
values.put(NoteColumns.SYNC_ID, 0);
|
|
||||||
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
Toast.makeText(NotesPreferenceActivity.this,
|
|
||||||
getString(R.string.preferences_toast_success_set_accout, account),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeSyncAccount() {
|
|
||||||
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
|
||||||
if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) {
|
|
||||||
editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);
|
|
||||||
}
|
|
||||||
if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
|
|
||||||
editor.remove(PREFERENCE_LAST_SYNC_TIME);
|
|
||||||
}
|
|
||||||
editor.commit();
|
|
||||||
|
|
||||||
// clean up local gtask related info
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(NoteColumns.GTASK_ID, "");
|
|
||||||
values.put(NoteColumns.SYNC_ID, 0);
|
|
||||||
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getSyncAccountName(Context context) {
|
|
||||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
||||||
Context.MODE_PRIVATE);
|
|
||||||
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setLastSyncTime(Context context, long time) {
|
|
||||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
||||||
Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
|
||||||
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
|
|
||||||
editor.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getLastSyncTime(Context context) {
|
|
||||||
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
||||||
Context.MODE_PRIVATE);
|
|
||||||
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class GTaskReceiver extends BroadcastReceiver {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
refreshUI();
|
|
||||||
if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) {
|
|
||||||
TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
|
|
||||||
syncStatus.setText(intent
|
|
||||||
.getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case android.R.id.home:
|
|
||||||
Intent intent = new Intent(this, NotesListActivity.class);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
startActivity(intent);
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* 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.widget;
|
|
||||||
|
|
||||||
import android.appwidget.AppWidgetManager;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import net.micode.notes.R;
|
|
||||||
import net.micode.notes.data.Notes;
|
|
||||||
import net.micode.notes.tool.ResourceParser;
|
|
||||||
|
|
||||||
|
|
||||||
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
|
|
||||||
@Override
|
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
||||||
super.update(context, appWidgetManager, appWidgetIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutId() {
|
|
||||||
return R.layout.widget_2x;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getBgResourceId(int bgId) {
|
|
||||||
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getWidgetType() {
|
|
||||||
return Notes.TYPE_WIDGET_2X;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* 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.widget;
|
|
||||||
|
|
||||||
import android.appwidget.AppWidgetManager;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import net.micode.notes.R;
|
|
||||||
import net.micode.notes.data.Notes;
|
|
||||||
import net.micode.notes.tool.ResourceParser;
|
|
||||||
|
|
||||||
|
|
||||||
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
|
|
||||||
@Override
|
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
||||||
super.update(context, appWidgetManager, appWidgetIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getLayoutId() {
|
|
||||||
return R.layout.widget_4x;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getBgResourceId(int bgId) {
|
|
||||||
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getWidgetType() {
|
|
||||||
return Notes.TYPE_WIDGET_4X;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in new issue