branch_chen
chenwenjie 8 months ago
parent 3366060794
commit 2a8e049f64

@ -8,4 +8,7 @@
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="2a5a6da1-3c6a-4858-a781-ab7547af5410" />
</component>
</module> </module>

@ -26,6 +26,9 @@ import android.util.Log;
import java.util.HashMap; import java.util.HashMap;
public class Contact { public class Contact {
private Contact() {
throw new IllegalStateException("Utility class");
}
// 缓存联系人信息,键为电话号码,值为联系人姓名 // 缓存联系人信息,键为电话号码,值为联系人姓名
private static HashMap<String, String> sContactCache; private static HashMap<String, String> sContactCache;
@ -45,7 +48,7 @@ public class Contact {
// 如果联系人缓存为空,进行初始化 // 如果联系人缓存为空,进行初始化
if(sContactCache == null) { if(sContactCache == null) {
sContactCache = new HashMap<String, String>(); sContactCache = new HashMap<>();
} }
// 如果缓存中已包含该电话号码对应的联系人姓名,则直接返回姓名 // 如果缓存中已包含该电话号码对应的联系人姓名,则直接返回姓名

@ -18,6 +18,8 @@ package net.micode.notes.data;
import android.net.Uri; import android.net.Uri;
import java.util.PrimitiveIterator;
// Notes 类中定义了很多常量这些常量大多是int型和string型 // Notes 类中定义了很多常量这些常量大多是int型和string型
public class Notes { public class Notes {
// 权限 // 权限
@ -55,6 +57,9 @@ public class Notes {
// 数据类型常量 // 数据类型常量
public static class DataConstants { public static class DataConstants {
private DataConstants() {
throw new IllegalStateException("Utility class");
}
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
} }
@ -63,14 +68,14 @@ public class Notes {
/** /**
* Uri to query all notes and folders * Uri to query all notes and folders
*/ */
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); public static final Uri CONTENT_NOTE_URI = Uri.parse(content + AUTHORITY + "/note");
//定义查询便签和文件夹的指针 //定义查询便签和文件夹的指针
/** /**
* Uri to query data * Uri to query data
*/ */
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); public static final Uri CONTENT_DATA_URI = Uri.parse(content + AUTHORITY + "/data");
//定义查找数据的指针 //定义查找数据的指针
@ -294,6 +299,9 @@ public class Notes {
* Mode to indicate the text in check list mode or not * Mode to indicate the text in check list mode or not
* <P> Type: Integer 1:check list mode 0: normal mode </P> * <P> Type: Integer 1:check list mode 0: normal mode </P>
*/ */
private TextNote() {
throw new IllegalStateException("Utility class");
}
// 表示文本为检查列表模式或非检查列表模式的模式 // 表示文本为检查列表模式或非检查列表模式的模式
public static final String MODE = DATA1; public static final String MODE = DATA1;
@ -312,6 +320,9 @@ public class Notes {
* Call date for this record * Call date for this record
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
private CallNote() {
throw new IllegalStateException("Utility class");
}
// 记录的通话日期 // 记录的通话日期
public static final String CALL_DATE = DATA1; public static final String CALL_DATE = DATA1;

@ -42,6 +42,8 @@ public class NotesProvider extends ContentProvider {
private static final String TAG = "NotesProvider"; private static final String TAG = "NotesProvider";
private static final String URL = "Unknown URI ";
private static final int URI_NOTE = 1; private static final int URI_NOTE = 1;
private static final int URI_NOTE_ITEM = 2; private static final int URI_NOTE_ITEM = 2;
private static final int URI_DATA = 3; private static final int URI_DATA = 3;
@ -139,7 +141,7 @@ public class NotesProvider extends ContentProvider {
} }
break; break;
default: default:
throw new IllegalArgumentException("Unknown URI " + uri); throw new IllegalArgumentException(URL+ uri);
} }
if (c != null) { if (c != null) {
c.setNotificationUri(getContext().getContentResolver(), uri); c.setNotificationUri(getContext().getContentResolver(), uri);
@ -164,7 +166,7 @@ public class NotesProvider extends ContentProvider {
insertedId = dataId = db.insert(TABLE.DATA, null, values); insertedId = dataId = db.insert(TABLE.DATA, null, values);
break; break;
default: default:
throw new IllegalArgumentException("Unknown URI " + uri); throw new IllegalArgumentException(URL + uri);
} }
// Notify the note uri // Notify the note uri
if (noteId > 0) { if (noteId > 0) {
@ -283,7 +285,7 @@ public class NotesProvider extends ContentProvider {
sql.append(" WHERE "); sql.append(" WHERE ");
} }
if (id > 0) { if (id > 0) {
sql.append(NoteColumns.ID + "=" + String.valueOf(id)); sql.append(NoteColumns.ID + "=" + id);
} }
if (!TextUtils.isEmpty(selection)) { if (!TextUtils.isEmpty(selection)) {
String selectString = id > 0 ? parseSelection(selection) : selection; String selectString = id > 0 ? parseSelection(selection) : selection;

@ -26,7 +26,7 @@ import org.json.JSONObject;
public class MetaData extends Task { public class MetaData extends Task {
private final static String TAG = MetaData.class.getSimpleName(); private static final String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null; private String mRelatedGid = null;

@ -47,7 +47,7 @@ public abstract class Node {
private boolean mDeleted; private boolean mDeleted;
public Node() { protected Node() {
mGid = null; mGid = null;
mName = ""; mName = "";
mLastModified = 0; mLastModified = 0;

@ -43,7 +43,7 @@ public class SqlNote {
private static final int INVALID_ID = -99999; private static final int INVALID_ID = -99999;
public static final String[] PROJECTION_NOTE = new String[] { protected static final String[] PROJECTION_NOTE = new String[] {
NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE, NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE,
NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE, NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE,
@ -140,7 +140,7 @@ public class SqlNote {
mOriginParent = 0; mOriginParent = 0;
mVersion = 0; mVersion = 0;
mDiffNoteValues = new ContentValues(); mDiffNoteValues = new ContentValues();
mDataList = new ArrayList<SqlData>(); mDataList = new ArrayList<>();
} }
public SqlNote(Context context, Cursor c) { public SqlNote(Context context, Cursor c) {
@ -148,7 +148,7 @@ public class SqlNote {
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
mIsCreate = false; mIsCreate = false;
loadFromCursor(c); loadFromCursor(c);
mDataList = new ArrayList<SqlData>(); mDataList = new ArrayList<>();
if (mType == Notes.TYPE_NOTE) if (mType == Notes.TYPE_NOTE)
loadDataContent(); loadDataContent();
mDiffNoteValues = new ContentValues(); mDiffNoteValues = new ContentValues();
@ -159,7 +159,7 @@ public class SqlNote {
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
mIsCreate = false; mIsCreate = false;
loadFromCursor(id); loadFromCursor(id);
mDataList = new ArrayList<SqlData>(); mDataList = new ArrayList<>();
if (mType == Notes.TYPE_NOTE) if (mType == Notes.TYPE_NOTE)
loadDataContent(); loadDataContent();
mDiffNoteValues = new ContentValues(); mDiffNoteValues = new ContentValues();

@ -39,7 +39,7 @@ public class TaskList extends Node {
public TaskList() { public TaskList() {
super(); super();
mChildren = new ArrayList<Task>(); mChildren = new ArrayList<>();
mIndex = 1; mIndex = 1;
} }

@ -298,7 +298,9 @@ public class GTaskClient {
Log.d(TAG, "encoding: " + contentEncoding); Log.d(TAG, "encoding: " + contentEncoding);
} }
InputStream input = entity.getContent(); InputStream input = entity.getContent();
if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) { if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
input = new GZIPInputStream(entity.getContent()); input = new GZIPInputStream(entity.getContent());
} else if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) { } else if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) {
@ -306,11 +308,12 @@ public class GTaskClient {
input = new InflaterInputStream(entity.getContent(), inflater); input = new InflaterInputStream(entity.getContent(), inflater);
} }
try {
InputStreamReader isr = new InputStreamReader(input); InputStreamReader isr = new InputStreamReader(input);
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
try {
while (true) { while (true) {
String buff = br.readLine(); String buff = br.readLine();
if (buff == null) { if (buff == null) {
@ -331,7 +334,7 @@ public class GTaskClient {
HttpPost httpPost = createHttpPost(); HttpPost httpPost = createHttpPost();
try { try {
LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>(); LinkedList<BasicNameValuePair> list = new LinkedList<>();
list.add(new BasicNameValuePair("r", js.toString())); list.add(new BasicNameValuePair("r", js.toString()));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8"); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8");
httpPost.setEntity(entity); httpPost.setEntity(entity);

@ -90,13 +90,13 @@ public class GTaskManager {
private GTaskManager() { private GTaskManager() {
mSyncing = false; mSyncing = false;
mCancelled = false; mCancelled = false;
mGTaskListHashMap = new HashMap<String, TaskList>(); mGTaskListHashMap = new HashMap<>();
mGTaskHashMap = new HashMap<String, Node>(); mGTaskHashMap = new HashMap<>();
mMetaHashMap = new HashMap<String, MetaData>(); mMetaHashMap = new HashMap<>();
mMetaList = null; mMetaList = null;
mLocalDeleteIdMap = new HashSet<Long>(); mLocalDeleteIdMap = new HashSet<>();
mGidToNid = new HashMap<String, Long>(); mGidToNid = new HashMap<>();
mNidToGid = new HashMap<Long, String>(); mNidToGid = new HashMap<>();
} }
public static synchronized GTaskManager getInstance() { public static synchronized GTaskManager getInstance() {
@ -132,11 +132,10 @@ public class GTaskManager {
client.resetUpdateArray(); client.resetUpdateArray();
// login google task // login google task
if (!mCancelled) {
if (!client.login(mActivity)) { if (!mCancelled&&!client.login(mActivity)) {
throw new NetworkFailureException("login google task failed"); throw new NetworkFailureException("login google task failed");
} }
}
// get the task list from google // get the task list from google
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list)); asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list));
@ -249,6 +248,7 @@ public class GTaskManager {
private void syncContent() throws NetworkFailureException { private void syncContent() throws NetworkFailureException {
int syncType; int syncType;
String DESC = " DESC";
Cursor c = null; Cursor c = null;
String gid; String gid;
Node node; Node node;
@ -294,7 +294,7 @@ public class GTaskManager {
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE, c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
"(type=? AND parent_id<>?)", new String[] { "(type=? AND parent_id<>?)", new String[] {
String.valueOf(Notes.TYPE_NOTE), String.valueOf(Notes.ID_TRASH_FOLER) String.valueOf(Notes.TYPE_NOTE), String.valueOf(Notes.ID_TRASH_FOLER)
}, NoteColumns.TYPE + " DESC"); }, NoteColumns.TYPE + DESC);
if (c != null) { if (c != null) {
while (c.moveToNext()) { while (c.moveToNext()) {
gid = c.getString(SqlNote.GTASK_ID_COLUMN); gid = c.getString(SqlNote.GTASK_ID_COLUMN);
@ -337,11 +337,10 @@ public class GTaskManager {
// mCancelled can be set by another thread, so we neet to check one by // mCancelled can be set by another thread, so we neet to check one by
// one // one
// clear local delete table // clear local delete table
if (!mCancelled) {
if (!DataUtils.batchDeleteNotes(mContentResolver, mLocalDeleteIdMap)) { if (!mCancelled&&!DataUtils.batchDeleteNotes(mContentResolver, mLocalDeleteIdMap)) {
throw new ActionFailureException("failed to batch-delete local deleted notes"); throw new ActionFailureException("failed to batch-delete local deleted notes");
} }
}
// refresh local sync id // refresh local sync id
if (!mCancelled) { if (!mCancelled) {
@ -619,7 +618,7 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote); updateRemoteMeta(node.getGid(), sqlNote);
} }
private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException { private void addRemoteNode(Cursor c) throws NetworkFailureException {
if (mCancelled) { if (mCancelled) {
return; return;
} }

@ -24,23 +24,23 @@ import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
public class GTaskSyncService extends Service { public class GTaskSyncService extends Service {
public final static String ACTION_STRING_NAME = "sync_action_type"; public static final String ACTION_STRING_NAME = "sync_action_type";
public final static int ACTION_START_SYNC = 0; public static final int ACTION_START_SYNC = 0;
public final static int ACTION_CANCEL_SYNC = 1; public static final int ACTION_CANCEL_SYNC = 1;
public final static int ACTION_INVALID = 2; public static final int ACTION_INVALID = 2;
public final static String GTASK_SERVICE_BROADCAST_NAME = "net.micode.notes.gtask.remote.gtask_sync_service"; public static final String GTASK_SERVICE_BROADCAST_NAME = "net.micode.notes.gtask.remote.gtask_sync_service";
public final static String GTASK_SERVICE_BROADCAST_IS_SYNCING = "isSyncing"; public static final String GTASK_SERVICE_BROADCAST_IS_SYNCING = "isSyncing";
public final static String GTASK_SERVICE_BROADCAST_PROGRESS_MSG = "progressMsg"; public static final String GTASK_SERVICE_BROADCAST_PROGRESS_MSG = "progressMsg";
private static GTaskASyncTask mSyncTask = null; private GTaskASyncTask mSyncTask = null;
private static String mSyncProgress = ""; private String mSyncProgress = "";
private void startSync() { private void startSync() {
if (mSyncTask == null) { if (mSyncTask == null) {

@ -186,7 +186,7 @@ public class Note {
throw new IllegalArgumentException("Wrong note id:" + noteId); throw new IllegalArgumentException("Wrong note id:" + noteId);
} }
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ArrayList<ContentProviderOperation> operationList = new ArrayList<>();
ContentProviderOperation.Builder builder = null; ContentProviderOperation.Builder builder = null;
if(mTextDataValues.size() > 0) { if(mTextDataValues.size() > 0) {

@ -62,7 +62,7 @@ public class WorkingNote {
private NoteSettingChangedListener mNoteSettingStatusListener; private NoteSettingChangedListener mNoteSettingStatusListener;
public static final String[] DATA_PROJECTION = new String[] { protected static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID, DataColumns.ID,
DataColumns.CONTENT, DataColumns.CONTENT,
DataColumns.MIME_TYPE, DataColumns.MIME_TYPE,
@ -72,7 +72,7 @@ public class WorkingNote {
DataColumns.DATA4, DataColumns.DATA4,
}; };
public static final String[] NOTE_PROJECTION = new String[] { protected static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID, NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE, NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID, NoteColumns.BG_COLOR_ID,

@ -30,7 +30,7 @@ import net.micode.notes.data.Notes.NoteColumns;
public class FoldersListAdapter extends CursorAdapter { public class FoldersListAdapter extends CursorAdapter {
public static final String [] PROJECTION = { protected static final String [] PROJECTION = {
NoteColumns.ID, NoteColumns.ID,
NoteColumns.SNIPPET NoteColumns.SNIPPET
}; };

@ -82,6 +82,84 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public TextView tvAlertDate; public TextView tvAlertDate;
public ImageView ibSetBgColor; public ImageView ibSetBgColor;
public HeadViewHolder() {
}
public HeadViewHolder(TextView tvModified, ImageView ivAlertIcon, TextView tvAlertDate, ImageView ibSetBgColor) {
this.tvModified = tvModified;
this.ivAlertIcon = ivAlertIcon;
this.tvAlertDate = tvAlertDate;
this.ibSetBgColor = ibSetBgColor;
}
/**
*
* @return tvModified
*/
public TextView getTvModified() {
return tvModified;
}
/**
*
* @param tvModified
*/
public void setTvModified(TextView tvModified) {
this.tvModified = tvModified;
}
/**
*
* @return ivAlertIcon
*/
public ImageView getIvAlertIcon() {
return ivAlertIcon;
}
/**
*
* @param ivAlertIcon
*/
public void setIvAlertIcon(ImageView ivAlertIcon) {
this.ivAlertIcon = ivAlertIcon;
}
/**
*
* @return tvAlertDate
*/
public TextView getTvAlertDate() {
return tvAlertDate;
}
/**
*
* @param tvAlertDate
*/
public void setTvAlertDate(TextView tvAlertDate) {
this.tvAlertDate = tvAlertDate;
}
/**
*
* @return ibSetBgColor
*/
public ImageView getIbSetBgColor() {
return ibSetBgColor;
}
/**
*
* @param ibSetBgColor
*/
public void setIbSetBgColor(ImageView ibSetBgColor) {
this.ibSetBgColor = ibSetBgColor;
}
public String toString() {
return "HeadViewHolder{tvModified = " + tvModified + ", ivAlertIcon = " + ivAlertIcon + ", tvAlertDate = " + tvAlertDate + ", ibSetBgColor = " + ibSetBgColor + "}";
}
} }
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();

@ -35,7 +35,7 @@ import net.micode.notes.ui.NotesListActivity;
// 抽象类,用于管理便签小部件 // 抽象类,用于管理便签小部件
public abstract class NoteWidgetProvider extends AppWidgetProvider { public abstract class NoteWidgetProvider extends AppWidgetProvider {
// 定义用于查询数据库时需要的字段 // 定义用于查询数据库时需要的字段
public static final String [] PROJECTION = new String [] { protected static final String [] PROJECTION = new String [] {
NoteColumns.ID, NoteColumns.ID,
NoteColumns.BG_COLOR_ID, NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET NoteColumns.SNIPPET

@ -8,4 +8,7 @@
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="2bc3aa93-142a-4dd1-a0f8-6ef739285ff6" />
</component>
</module> </module>
Loading…
Cancel
Save