diff --git a/SonarTestCode.txt b/SonarTestCode.txt new file mode 100644 index 0000000..40a530a --- /dev/null +++ b/SonarTestCode.txt @@ -0,0 +1 @@ +gradlew sonarqube -Dsonar.projectKey=MiCodes -Dsonar.host.url=http://localhost:9000 -Dsonar.login=29c76d5ce5f4da5c0398ac577754cc938c679792 \ No newline at end of file diff --git a/src/MiCodeNotes/.idea/caches/build_file_checksums.ser b/src/MiCodeNotes/.idea/caches/build_file_checksums.ser index d980052..2bdd8be 100644 Binary files a/src/MiCodeNotes/.idea/caches/build_file_checksums.ser and b/src/MiCodeNotes/.idea/caches/build_file_checksums.ser differ diff --git a/src/MiCodeNotes/app/src/main/java/net/micode/notes/gtask/data/SqlData.java b/src/MiCodeNotes/app/src/main/java/net/micode/notes/gtask/data/SqlData.java index 81beeed..bec3ea2 100644 --- a/src/MiCodeNotes/app/src/main/java/net/micode/notes/gtask/data/SqlData.java +++ b/src/MiCodeNotes/app/src/main/java/net/micode/notes/gtask/data/SqlData.java @@ -40,7 +40,7 @@ public class SqlData { private static final int INVALID_ID = -99999; - public static final String[] PROJECTION_DATA = new String[] { + protected static final String[] PROJECTION_DATA = new String[] { DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1, DataColumns.DATA3 }; diff --git a/src/MiCodeNotes/app/src/main/java/net/micode/notes/gtask/data/TaskList.java b/src/MiCodeNotes/app/src/main/java/net/micode/notes/gtask/data/TaskList.java index 1ec86a2..50efb63 100644 --- a/src/MiCodeNotes/app/src/main/java/net/micode/notes/gtask/data/TaskList.java +++ b/src/MiCodeNotes/app/src/main/java/net/micode/notes/gtask/data/TaskList.java @@ -134,28 +134,30 @@ public class TaskList extends Node { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); } - try { - JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); - - if (folder != null){ - if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { - String name = folder.getString(NoteColumns.SNIPPET); - setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name); - } else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { - if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER) - setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT); - else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER) - setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX - + GTaskStringUtils.FOLDER_CALL_NOTE); - else - Log.e(TAG, "invalid system folder"); - } else { - Log.e(TAG, "error type"); + if (js != null) { + try { + JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); + + if (folder != null){ + if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { + String name = folder.getString(NoteColumns.SNIPPET); + setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name); + } else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { + if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER) + setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT); + else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER) + setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + + GTaskStringUtils.FOLDER_CALL_NOTE); + else + Log.e(TAG, "invalid system folder"); + } else { + Log.e(TAG, "error type"); + } } + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); } - } catch (JSONException e) { - Log.e(TAG, e.toString()); - e.printStackTrace(); } } diff --git a/src/MiCodeNotes/app/src/main/java/net/micode/notes/model/WorkingNote.java b/src/MiCodeNotes/app/src/main/java/net/micode/notes/model/WorkingNote.java index da39d44..5120768 100644 --- a/src/MiCodeNotes/app/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/src/MiCodeNotes/app/src/main/java/net/micode/notes/model/WorkingNote.java @@ -62,7 +62,7 @@ public class WorkingNote { private NoteSettingChangedListener mNoteSettingStatusListener; - public static final String[] DATA_PROJECTION = new String[] { + protected static final String[] DATA_PROJECTION = new String[] { DataColumns.ID, DataColumns.CONTENT, DataColumns.MIME_TYPE, @@ -72,7 +72,7 @@ public class WorkingNote { DataColumns.DATA4, }; - public static final String[] NOTE_PROJECTION = new String[] { + protected static final String[] NOTE_PROJECTION = new String[] { NoteColumns.PARENT_ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, diff --git a/src/MiCodeNotes/app/src/main/java/net/micode/notes/tool/BackupUtils.java b/src/MiCodeNotes/app/src/main/java/net/micode/notes/tool/BackupUtils.java index 90feacc..0c2f6c4 100644 --- a/src/MiCodeNotes/app/src/main/java/net/micode/notes/tool/BackupUtils.java +++ b/src/MiCodeNotes/app/src/main/java/net/micode/notes/tool/BackupUtils.java @@ -73,7 +73,7 @@ public class BackupUtils { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); } - public int exportToText() { + public int exportToText() throws IOException { return mTextExport.exportToText(); } @@ -218,7 +218,7 @@ public class BackupUtils { /** * Note will be exported as text which is user readable */ - public int exportToText() { + public int exportToText() throws IOException { if (!externalStorageAvailable()) { Log.d(TAG, "Media was not mounted"); return STATE_SD_CARD_UNMOUONTED; @@ -285,26 +285,25 @@ public class BackupUtils { /** * Get a print stream pointed to the file {@generateExportedTextFile} */ - private PrintStream getExportToTextPrintStream() { + private PrintStream getExportToTextPrintStream() throws IOException { File file = generateFileMountedOnSDcard(mContext, R.string.file_path, R.string.file_name_txt_format); if (file == null) { Log.e(TAG, "create file to exported failed"); return null; } + mFileName = file.getName(); mFileDirectory = mContext.getString(R.string.file_path); PrintStream ps = null; - try { - FileOutputStream fos = new FileOutputStream(file); + + try (FileOutputStream fos = new FileOutputStream(file)) { ps = new PrintStream(fos); } catch (FileNotFoundException e) { e.printStackTrace(); - ps.close(); return null; } catch (NullPointerException e) { e.printStackTrace(); - ps.close(); return null; } return ps; @@ -330,7 +329,12 @@ public class BackupUtils { filedir.mkdir(); } if (!file.exists()) { - file.createNewFile(); + boolean res = file.createNewFile(); + if (res == true) { + Log.i("BackupUtils", "Create new file sucessfully"); + } else { + Log.i("BackupUtils", "Fail to create new file"); + } } return file; } catch (SecurityException e) { diff --git a/src/MiCodeNotes/app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java b/src/MiCodeNotes/app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java index 51c487c..62229e7 100644 --- a/src/MiCodeNotes/app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java +++ b/src/MiCodeNotes/app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java @@ -30,7 +30,7 @@ import net.micode.notes.data.Notes.NoteColumns; public class FoldersListAdapter extends CursorAdapter { - public static final String [] PROJECTION = { + protected static final String [] PROJECTION = { NoteColumns.ID, NoteColumns.SNIPPET }; diff --git a/src/MiCodeNotes/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/src/MiCodeNotes/app/src/main/java/net/micode/notes/ui/NotesListActivity.java index 8098489..ff19f0f 100644 --- a/src/MiCodeNotes/app/src/main/java/net/micode/notes/ui/NotesListActivity.java +++ b/src/MiCodeNotes/app/src/main/java/net/micode/notes/ui/NotesListActivity.java @@ -150,7 +150,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt /** * Insert an introduction when user firstly use this application */ - setAppInfoFromRawRes(); + try { + setAppInfoFromRawRes(); + } catch (IOException e) { + e.printStackTrace(); + } } @Override @@ -169,36 +173,24 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt * 并创建一条新便签,将其写入 * 函数参数:@return: 无 */ - private void setAppInfoFromRawRes() { + private void setAppInfoFromRawRes() throws IOException { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) { StringBuilder sb = new StringBuilder(); InputStream in = null; - - try { - in = getResources().openRawResource(R.raw.introduction); - if (in != null) { - InputStreamReader isr = new InputStreamReader(in); - BufferedReader br = new BufferedReader(isr); + in = getResources().openRawResource(R.raw.introduction); + if (in != null) { + try (InputStreamReader isr = new InputStreamReader(in); + BufferedReader br = new BufferedReader(isr);) { char [] buf = new char[1024]; int len = 0; while ((len = br.read(buf)) > 0) { sb.append(buf, 0, len); } - - isr.close(); - br.close(); - } else { - Log.e(TAG, "Read introduction file error"); - return; - } - - } catch (IOException e) { - e.printStackTrace(); - return; - } finally { - if(in != null) { + } catch (IOException e) { + e.printStackTrace(); + } finally { try { in.close(); } catch (IOException e) { @@ -208,8 +200,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt } } - - WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER, AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE, ResourceParser.RED); @@ -982,7 +972,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt @Override protected Integer doInBackground(Void... unused) { - return backup.exportToText(); + try { + return backup.exportToText(); + } catch (IOException e) { + e.printStackTrace(); + } + return -1; } @Override diff --git a/src/MiCodeNotes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java b/src/MiCodeNotes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java index d5a473a..0b27777 100644 --- a/src/MiCodeNotes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java +++ b/src/MiCodeNotes/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java @@ -33,7 +33,7 @@ import net.micode.notes.ui.NoteEditActivity; import net.micode.notes.ui.NotesListActivity; public abstract class NoteWidgetProvider extends AppWidgetProvider { - public static final String [] PROJECTION = new String [] { + protected static final String [] PROJECTION = new String [] { NoteColumns.ID, NoteColumns.BG_COLOR_ID, NoteColumns.SNIPPET