Merge pull request 'wan' (#5) from a_branch into master

master
pkl7bfvwa 4 months ago
commit 2697485a71

@ -4,10 +4,10 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-05-29T14:05:32.256772800Z">
<DropdownSelection timestamp="2025-06-05T01:06:08.196508400Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\Administrator\.android\avd\Pixel_9_Pro_XL.avd" />
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\Administrator\.android\avd\Medium_Phone_2.avd" />
</handle>
</Target>
</DropdownSelection>

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
@ -6,4 +7,11 @@
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="VisualizationToolProject">
<option name="state">
<ProjectState>
<option name="scale" value="0.1132844335778321" />
</ProjectState>
</option>
</component>
</project>

@ -10,7 +10,7 @@ android {
defaultConfig {
applicationId = "net.micode.notes"
minSdk = 24
minSdk = 30
targetSdk = 35
versionCode = 1
versionName = "1.0"

@ -23,7 +23,7 @@ Component组件、Extra扩展信息、Flag标志位 -->
android:versionCode="1"
android:versionName="0.1" >
<uses-sdk android:minSdkVersion="24" />
<uses-sdk android:minSdkVersion="30" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

@ -29,11 +29,15 @@ import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import net.micode.notes.R;
import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
import java.util.Objects;
public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher;
@ -73,12 +77,6 @@ public class NotesProvider extends ContentProvider {
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
+ " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
@Override
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
@ -86,7 +84,7 @@ public class NotesProvider extends ContentProvider {
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
Cursor c = null;
SQLiteDatabase db = mHelper.getReadableDatabase();
@ -132,6 +130,11 @@ public class NotesProvider extends ContentProvider {
try {
searchString = String.format("%%%s%%", searchString);
String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
+ " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
new String[] { searchString });
} catch (IllegalStateException ex) {
@ -142,13 +145,13 @@ public class NotesProvider extends ContentProvider {
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (c != null) {
c.setNotificationUri(getContext().getContentResolver(), uri);
c.setNotificationUri(Objects.requireNonNull(getContext()).getContentResolver(), uri);
}
return c;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
public Uri insert(@NonNull Uri uri, ContentValues values) {
SQLiteDatabase db = mHelper.getWritableDatabase();
long dataId = 0, noteId = 0, insertedId = 0;
switch (mMatcher.match(uri)) {
@ -168,13 +171,13 @@ public class NotesProvider extends ContentProvider {
}
// Notify the note uri
if (noteId > 0) {
getContext().getContentResolver().notifyChange(
Objects.requireNonNull(getContext()).getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
}
// Notify the data uri
if (dataId > 0) {
getContext().getContentResolver().notifyChange(
Objects.requireNonNull(getContext()).getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
}
@ -182,7 +185,7 @@ public class NotesProvider extends ContentProvider {
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
int count = 0;
String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase();
@ -198,7 +201,7 @@ public class NotesProvider extends ContentProvider {
* ID that smaller than 0 is system folder which is not allowed to
* trash
*/
long noteId = Long.valueOf(id);
long noteId = Long.parseLong(id);
if (noteId <= 0) {
break;
}
@ -220,15 +223,15 @@ public class NotesProvider extends ContentProvider {
}
if (count > 0) {
if (deleteData) {
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
Objects.requireNonNull(getContext()).getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
}
getContext().getContentResolver().notifyChange(uri, null);
Objects.requireNonNull(getContext()).getContentResolver().notifyChange(uri, null);
}
return count;
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int count = 0;
String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase();
@ -240,7 +243,7 @@ public class NotesProvider extends ContentProvider {
break;
case URI_NOTE_ITEM:
id = uri.getPathSegments().get(1);
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
increaseNoteVersion(Long.parseLong(id), selection, selectionArgs);
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs);
break;
@ -260,9 +263,9 @@ public class NotesProvider extends ContentProvider {
if (count > 0) {
if (updateData) {
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
Objects.requireNonNull(getContext()).getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
}
getContext().getContentResolver().notifyChange(uri, null);
Objects.requireNonNull(getContext()).getContentResolver().notifyChange(uri, null);
}
return count;
}
@ -283,7 +286,7 @@ public class NotesProvider extends ContentProvider {
sql.append(" WHERE ");
}
if (id > 0) {
sql.append(NoteColumns.ID + "=" + String.valueOf(id));
sql.append(NoteColumns.ID + "=").append(String.valueOf(id));
}
if (!TextUtils.isEmpty(selection)) {
String selectString = id > 0 ? parseSelection(selection) : selection;
@ -297,7 +300,7 @@ public class NotesProvider extends ContentProvider {
}
@Override
public String getType(Uri uri) {
public String getType(@NonNull Uri uri) {
// TODO Auto-generated method stub
return null;
}

@ -35,8 +35,8 @@ import java.util.ArrayList;
public class Note {
private ContentValues mNoteDiffValues;
private NoteData mNoteData;
private final ContentValues mNoteDiffValues;
private final NoteData mNoteData;
private static final String TAG = "Note";
/**
* Create a new note id for adding a new note to databases
@ -54,10 +54,10 @@ public class Note {
long noteId = 0;
try {
noteId = Long.valueOf(uri.getPathSegments().get(1));
assert uri != null;
noteId = Long.parseLong(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
noteId = 0;
}
if (noteId == -1) {
throw new IllegalStateException("Wrong note id:" + noteId);
@ -97,7 +97,7 @@ public class Note {
}
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
return !mNoteDiffValues.isEmpty() || mNoteData.isLocalModified();
}
public boolean syncNote(Context context, long noteId) {
@ -122,22 +122,18 @@ public class Note {
}
mNoteDiffValues.clear();
if (mNoteData.isLocalModified()
&& (mNoteData.pushIntoContentResolver(context, noteId) == null)) {
return false;
}
return true;
return !mNoteData.isLocalModified()
|| (mNoteData.pushIntoContentResolver(context, noteId) != null);
}
private class NoteData {
private long mTextDataId;
private ContentValues mTextDataValues;
private final ContentValues mTextDataValues;
private long mCallDataId;
private ContentValues mCallDataValues;
private final ContentValues mCallDataValues;
private static final String TAG = "NoteData";
@ -189,14 +185,15 @@ public class Note {
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = null;
if(mTextDataValues.size() > 0) {
if(!mTextDataValues.isEmpty()) {
mTextDataValues.put(DataColumns.NOTE_ID, noteId);
if (mTextDataId == 0) {
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues);
try {
setTextDataId(Long.valueOf(uri.getPathSegments().get(1)));
assert uri != null;
setTextDataId(Long.parseLong(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
Log.e(TAG, "Insert new text data fail with noteId" + noteId);
mTextDataValues.clear();
@ -211,14 +208,15 @@ public class Note {
mTextDataValues.clear();
}
if(mCallDataValues.size() > 0) {
if(!mCallDataValues.isEmpty()) {
mCallDataValues.put(DataColumns.NOTE_ID, noteId);
if (mCallDataId == 0) {
mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mCallDataValues);
try {
setCallDataId(Long.valueOf(uri.getPathSegments().get(1)));
assert uri != null;
setCallDataId(Long.parseLong(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
Log.e(TAG, "Insert new call data fail with noteId" + noteId);
mCallDataValues.clear();
@ -233,16 +231,13 @@ public class Note {
mCallDataValues.clear();
}
if (operationList.size() > 0) {
if (!operationList.isEmpty()) {
try {
ContentProviderResult[] results = context.getContentResolver().applyBatch(
Notes.AUTHORITY, operationList);
return (results == null || results.length == 0 || results[0] == null) ? null
return results.length == 0 || results[0] == null ? null
: ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId);
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
} catch (OperationApplicationException e) {
} catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
}

@ -34,7 +34,7 @@ import net.micode.notes.tool.ResourceParser.NoteBgResources;
public class WorkingNote {
// Note for the working note
private Note mNote;
private final Note mNote;
// Note Id
private long mNoteId;
// Note content
@ -54,7 +54,7 @@ public class WorkingNote {
private long mFolderId;
private Context mContext;
private final Context mContext;
private static final String TAG = "WorkingNote";
@ -217,12 +217,8 @@ public class WorkingNote {
}
private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
return false;
} else {
return true;
}
return !mIsDeleted && (existInDatabase() || !TextUtils.isEmpty(mContent))
&& (!existInDatabase() || mNote.isLocalModified());
}
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
@ -295,7 +291,7 @@ public class WorkingNote {
}
public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false);
return (mAlertDate > 0);
}
public String getContent() {

@ -63,7 +63,7 @@ public class BackupUtils {
// Backup or restore success
public static final int STATE_SUCCESS = 4;
private TextExport mTextExport;
private final TextExport mTextExport;
private BackupUtils(Context context) {
mTextExport = new TextExport(context);
@ -121,7 +121,7 @@ public class BackupUtils {
private static final int FORMAT_NOTE_DATE = 1;
private static final int FORMAT_NOTE_CONTENT = 2;
private Context mContext;
private final Context mContext;
private String mFileName;
private String mFileDirectory;
@ -267,9 +267,9 @@ public class BackupUtils {
if (noteCursor != null) {
if (noteCursor.moveToFirst()) {
do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
ps.printf((getFormat(FORMAT_NOTE_DATE)) + "%n", DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)));
// Query data belong to this note
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
@ -298,10 +298,7 @@ public class BackupUtils {
try {
FileOutputStream fos = new FileOutputStream(file);
ps = new PrintStream(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
} catch (NullPointerException e) {
} catch (FileNotFoundException | NullPointerException e) {
e.printStackTrace();
return null;
}
@ -331,9 +328,7 @@ public class BackupUtils {
file.createNewFile();
}
return file;
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (SecurityException | IOException e) {
e.printStackTrace();
}

@ -42,7 +42,7 @@ public class DataUtils {
Log.d(TAG, "the ids is null");
return true;
}
if (ids.size() == 0) {
if (ids.isEmpty()) {
Log.d(TAG, "no id is in the hashset");
return true;
}
@ -59,14 +59,12 @@ public class DataUtils {
}
try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) {
if (results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
return true;
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
} catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
}
return false;
@ -98,14 +96,12 @@ public class DataUtils {
try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) {
if (results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
return true;
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
} catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
}
return false;
@ -232,12 +228,10 @@ public class DataUtils {
null);
if (cursor != null && cursor.moveToFirst()) {
try {
try (cursor) {
return cursor.getString(0);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call number fails " + e.toString());
} finally {
cursor.close();
}
}
return "";

@ -38,6 +38,7 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils;
import java.io.IOException;
import java.util.Objects;
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
@ -64,7 +65,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
Intent intent = getIntent();
try {
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
mNoteId = Long.parseLong(Objects.requireNonNull(intent.getData()).getPathSegments().get(1));
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
@ -104,16 +105,8 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
mPlayer.prepare();
mPlayer.setLooping(true);
mPlayer.start();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
} catch (IllegalArgumentException | SecurityException | IOException |
IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -131,15 +124,11 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
}
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_NEGATIVE:
if (which == DialogInterface.BUTTON_NEGATIVE) {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, mNoteId);
startActivity(intent);
break;
default:
break;
}
}

@ -16,6 +16,7 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
@ -38,6 +39,7 @@ public class AlarmInitReceiver extends BroadcastReceiver {
private static final int COLUMN_ID = 0;
private static final int COLUMN_ALERTED_DATE = 1;
@SuppressLint("UnsafeProtectedBroadcastReceiver")
@Override
public void onReceive(Context context, Intent intent) {
long currentDate = System.currentTimeMillis();

@ -50,9 +50,9 @@ public class DateTimePicker extends FrameLayout {
private final NumberPicker mHourSpinner;
private final NumberPicker mMinuteSpinner;
private final NumberPicker mAmPmSpinner;
private Calendar mDate;
private final Calendar mDate;
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
private final String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
private boolean mIsAm;
@ -64,7 +64,30 @@ public class DateTimePicker extends FrameLayout {
private OnDateTimeChangedListener mOnDateTimeChangedListener;
private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
public interface OnDateTimeChangedListener {
void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute);
}
public DateTimePicker(Context context) {
this(context, System.currentTimeMillis());
}
public DateTimePicker(Context context, long date) {
this(context, date, DateFormat.is24HourFormat(context));
}
public DateTimePicker(Context context, long date, boolean is24HourView) {
super(context);
mDate = Calendar.getInstance();
mInitialising = true;
mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY;
inflate(context, R.layout.datetime_picker, this);
mDateSpinner = (NumberPicker) findViewById(R.id.date);
mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL);
mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL);
NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal);
@ -72,8 +95,10 @@ public class DateTimePicker extends FrameLayout {
onDateTimeChanged();
}
};
mDateSpinner.setOnValueChangedListener(mOnDateChangedListener);
private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
mHourSpinner = (NumberPicker) findViewById(R.id.hour);
NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
boolean isDateChanged = false;
@ -114,8 +139,12 @@ public class DateTimePicker extends FrameLayout {
}
}
};
private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
mHourSpinner.setOnValueChangedListener(mOnHourChangedListener);
mMinuteSpinner = (NumberPicker) findViewById(R.id.minute);
mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL);
mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL);
mMinuteSpinner.setOnLongPressUpdateInterval(100);
NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
int minValue = mMinuteSpinner.getMinValue();
@ -143,8 +172,14 @@ public class DateTimePicker extends FrameLayout {
onDateTimeChanged();
}
};
mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() {
String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings();
mAmPmSpinner = (NumberPicker) findViewById(R.id.amPm);
mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL);
mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL);
mAmPmSpinner.setDisplayedValues(stringsForAmPm);
NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mIsAm = !mIsAm;
@ -157,45 +192,6 @@ public class DateTimePicker extends FrameLayout {
onDateTimeChanged();
}
};
public interface OnDateTimeChangedListener {
void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute);
}
public DateTimePicker(Context context) {
this(context, System.currentTimeMillis());
}
public DateTimePicker(Context context, long date) {
this(context, date, DateFormat.is24HourFormat(context));
}
public DateTimePicker(Context context, long date, boolean is24HourView) {
super(context);
mDate = Calendar.getInstance();
mInitialising = true;
mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY;
inflate(context, R.layout.datetime_picker, this);
mDateSpinner = (NumberPicker) findViewById(R.id.date);
mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL);
mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL);
mDateSpinner.setOnValueChangedListener(mOnDateChangedListener);
mHourSpinner = (NumberPicker) findViewById(R.id.hour);
mHourSpinner.setOnValueChangedListener(mOnHourChangedListener);
mMinuteSpinner = (NumberPicker) findViewById(R.id.minute);
mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL);
mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL);
mMinuteSpinner.setOnLongPressUpdateInterval(100);
mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings();
mAmPmSpinner = (NumberPicker) findViewById(R.id.amPm);
mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL);
mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL);
mAmPmSpinner.setDisplayedValues(stringsForAmPm);
mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener);
// update controls to initial state

@ -31,10 +31,9 @@ import android.text.format.DateUtils;
public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
private Calendar mDate = Calendar.getInstance();
private final Calendar mDate = Calendar.getInstance();
private boolean mIs24HourView;
private OnDateTimeSetListener mOnDateTimeSetListener;
private DateTimePicker mDateTimePicker;
public interface OnDateTimeSetListener {
void OnDateTimeSet(AlertDialog dialog, long date);
@ -42,7 +41,7 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
public DateTimePickerDialog(Context context, long date) {
super(context);
mDateTimePicker = new DateTimePicker(context);
DateTimePicker mDateTimePicker = new DateTimePicker(context);
setView(mDateTimePicker);
mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() {
public void onDateTimeChanged(DateTimePicker view, int year, int month,
@ -77,7 +76,7 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
DateUtils.FORMAT_SHOW_YEAR |
DateUtils.FORMAT_SHOW_DATE |
DateUtils.FORMAT_SHOW_TIME;
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR;
flag |= DateUtils.FORMAT_24HOUR;
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
}

@ -28,9 +28,9 @@ import android.widget.PopupMenu.OnMenuItemClickListener;
import net.micode.notes.R;
public class DropdownMenu {
private Button mButton;
private PopupMenu mPopupMenu;
private Menu mMenu;
private final Button mButton;
private final PopupMenu mPopupMenu;
private final Menu mMenu;
public DropdownMenu(Context context, Button button, int menuId) {
mButton = button;

@ -63,8 +63,8 @@ public class FoldersListAdapter extends CursorAdapter {
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
}
private class FolderListItem extends LinearLayout {
private TextView mName;
private static class FolderListItem extends LinearLayout {
private final TextView mName;
public FolderListItem(Context context) {
super(context);

@ -16,6 +16,7 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
@ -52,6 +53,8 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.TextNote;
@ -68,13 +71,14 @@ import net.micode.notes.widget.NoteWidgetProvider_4x;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener {
private class HeadViewHolder {
private static class HeadViewHolder {
public TextView tvModified;
public ImageView ivAlertIcon;
@ -147,7 +151,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private LinearLayout mEditTextList;
private String mUserQuery;
private Pattern mPattern;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -166,9 +169,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* user load this activity, we should restore the former state
*/
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) {
if (savedInstanceState.containsKey(Intent.EXTRA_UID)) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));
if (!initActivityState(intent)) {
@ -193,7 +196,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* Starting from the searched result
*/
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
noteId = Long.parseLong(Objects.requireNonNull(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY)));
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
}
@ -205,11 +208,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return false;
} else {
mWorkingNote = WorkingNote.load(this, noteId);
if (mWorkingNote == null) {
Log.e(TAG, "load note failed with note id" + noteId);
finish();
return false;
}
}
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
@ -235,11 +233,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
phoneNumber, callDate)) > 0) {
mWorkingNote = WorkingNote.load(this, noteId);
if (mWorkingNote == null) {
Log.e(TAG, "load call note failed with note id" + noteId);
finish();
return false;
}
} else {
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
widgetType, bgResId);
@ -309,7 +302,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} else {
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
};
}
}
@Override
@ -319,7 +312,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
@Override
protected void onSaveInstanceState(Bundle outState) {
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
/**
* For new note without note id, we should firstly save it to
@ -354,13 +347,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
if (ev.getX() < x
|| ev.getX() > (x + view.getWidth())
|| ev.getY() < y
|| ev.getY() > (y + view.getHeight())) {
return false;
}
return true;
return !(ev.getX() < x)
&& !(ev.getX() > (x + view.getWidth()))
&& !(ev.getY() < y)
&& !(ev.getY() > (y + view.getHeight()));
}
private void initResources() {
@ -383,7 +373,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
for (int id : sFontSizeBtnsMap.keySet()) {
View view = findViewById(id);
view.setOnClickListener(this);
};
}
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
/**
@ -439,7 +429,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} else if (sFontSizeBtnsMap.containsKey(id)) {
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.GONE);
mFontSizeId = sFontSizeBtnsMap.get(id);
mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit();
mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).apply();
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
getWorkingText();
@ -505,6 +495,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true;
}
@SuppressLint("NonConstantResourceId")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -609,7 +600,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
return !NotesPreferenceActivity.getSyncAccountName(this).trim().isEmpty();
}
public void onClockAlertChanged(long date, boolean set) {
@ -711,7 +702,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
if (!TextUtils.isEmpty(userQuery)) {
mPattern = Pattern.compile(userQuery);
Pattern mPattern = Pattern.compile(userQuery);
assert fullText != null;
Matcher m = mPattern.matcher(fullText);
int start = 0;
while (m.find(start)) {
@ -726,7 +718,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
private View getListItem(String item, int index) {
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
@SuppressLint("InflateParams") View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
@ -743,11 +735,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if (item.startsWith(TAG_CHECKED)) {
cb.setChecked(true);
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
item = item.substring(TAG_CHECKED.length(), item.length()).trim();
item = item.substring(TAG_CHECKED.length()).trim();
} else if (item.startsWith(TAG_UNCHECKED)) {
cb.setChecked(false);
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim();
item = item.substring(TAG_UNCHECKED.length()).trim();
}
edit.setOnTextViewChangeListener(this);

@ -16,6 +16,7 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Rect;
import android.text.Layout;
@ -32,6 +33,8 @@ import android.view.MenuItem.OnMenuItemClickListener;
import android.view.MotionEvent;
import android.widget.EditText;
import androidx.annotation.NonNull;
import net.micode.notes.R;
import java.util.HashMap;
@ -99,11 +102,10 @@ public class NoteEditText extends EditText {
// TODO Auto-generated constructor stub
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (event.getAction() == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= getTotalPaddingLeft();
@ -115,7 +117,6 @@ public class NoteEditText extends EditText {
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
Selection.setSelection(getText(), off);
break;
}
return super.onTouchEvent(event);
@ -170,18 +171,14 @@ public class NoteEditText extends EditText {
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (mOnTextViewChangeListener != null) {
if (!focused && TextUtils.isEmpty(getText())) {
mOnTextViewChangeListener.onTextChange(mIndex, false);
} else {
mOnTextViewChangeListener.onTextChange(mIndex, true);
}
mOnTextViewChangeListener.onTextChange(mIndex, focused || !TextUtils.isEmpty(getText()));
}
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
protected void onCreateContextMenu(ContextMenu menu) {
if (getText() instanceof Spanned) {
if (getText() != null) {
int selStart = getSelectionStart();
int selEnd = getSelectionEnd();
@ -192,7 +189,7 @@ public class NoteEditText extends EditText {
if (urls.length == 1) {
int defaultResId = 0;
for(String schema: sSchemaActionResMap.keySet()) {
if(urls[0].getURL().indexOf(schema) >= 0) {
if(urls[0].getURL().contains(schema)) {
defaultResId = sSchemaActionResMap.get(schema);
break;
}
@ -204,7 +201,7 @@ public class NoteEditText extends EditText {
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
public boolean onMenuItemClick(@NonNull MenuItem item) {
// goto a new intent
urls[0].onClick(NoteEditText.this);
return true;

@ -55,13 +55,13 @@ public class NoteItemData {
private static final int WIDGET_ID_COLUMN = 10;
private static final int WIDGET_TYPE_COLUMN = 11;
private long mId;
private long mAlertDate;
private int mBgColorId;
private long mCreatedDate;
private boolean mHasAttachment;
private long mModifiedDate;
private int mNotesCount;
private final long mId;
private final long mAlertDate;
private final int mBgColorId;
private final long mCreatedDate;
private final boolean mHasAttachment;
private final long mModifiedDate;
private final int mNotesCount;
private long mParentId;
private String mSnippet;
private int mType;

@ -16,6 +16,7 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@ -60,6 +61,8 @@ import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
@ -93,7 +96,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
};
}
private ListEditState mState;
@ -164,7 +167,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
InputStream in = null;
try {
in = getResources().openRawResource(R.raw.introduction);
if (in != null) {
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
char [] buf = new char[1024];
@ -172,10 +174,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
while ((len = br.read(buf)) > 0) {
sb.append(buf, 0, len);
}
} else {
Log.e(TAG, "Read introduction file error");
return;
}
} catch (IOException e) {
e.printStackTrace();
return;
@ -195,7 +193,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
ResourceParser.RED);
note.setWorkingText(sb.toString());
if (note.saveNote()) {
sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).apply();
} else {
Log.e(TAG, "Save introduction note error");
return;
@ -209,6 +207,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
startAsyncNotesListQuery();
}
@SuppressLint({"ClickableViewAccessibility", "InflateParams"})
private void initResources() {
mContentResolver = this.getContentResolver();
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
@ -234,12 +233,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu;
private ActionMode mActionMode;
private MenuItem mMoveMenu;
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
getMenuInflater().inflate(R.menu.note_list_options, menu);
menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
mMoveMenu = menu.findItem(R.id.move);
MenuItem mMoveMenu = menu.findItem(R.id.move);
if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER
|| DataUtils.getUserFolderCount(mContentResolver) == 0) {
mMoveMenu.setVisible(false);
@ -252,7 +250,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mNotesListView.setLongClickable(false);
mAddNewNote.setVisibility(View.GONE);
View customView = LayoutInflater.from(NotesListActivity.this).inflate(
@SuppressLint("InflateParams") View customView = LayoutInflater.from(NotesListActivity.this).inflate(
R.layout.note_list_dropdown_menu, null);
mode.setCustomView(customView);
mDropDownMenu = new DropdownMenu(NotesListActivity.this,
@ -312,7 +310,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
updateMenu();
}
public boolean onMenuItemClick(MenuItem item) {
@SuppressLint("NonConstantResourceId")
public boolean onMenuItemClick(@NonNull MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
Toast.LENGTH_SHORT).show();
@ -348,6 +347,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private class NewNoteOnTouchListener implements OnTouchListener {
@SuppressLint("ClickableViewAccessibility")
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
@ -406,7 +406,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return false;
}
};
}
private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
@ -417,6 +417,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
@SuppressLint("HandlerLeak")
private final class BackgroundQueryHandler extends AsyncQueryHandler {
public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver);
@ -469,6 +470,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
@SuppressLint("StaticFieldLeak")
private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
@ -557,13 +559,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mTitleBar.setVisibility(View.VISIBLE);
}
@SuppressLint("NonConstantResourceId")
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_new_note:
if (v.getId() == R.id.btn_new_note) {
createNewNote();
break;
default:
break;
}
}
@ -719,7 +718,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
};
@Override
public void onContextMenuClosed(Menu menu) {
public void onContextMenuClosed(@NonNull Menu menu) {
if (mNotesListView != null) {
mNotesListView.setOnCreateContextMenuListener(null);
}
@ -727,7 +726,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
@Override
public boolean onContextItemSelected(MenuItem item) {
public boolean onContextItemSelected(@NonNull MenuItem item) {
if (mFocusNoteDataItem == null) {
Log.e(TAG, "The long click data item is null");
return false;
@ -778,6 +777,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
@SuppressLint("NonConstantResourceId")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -824,6 +824,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
@SuppressLint("StaticFieldLeak")
private void exportNoteToText() {
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
new AsyncTask<Void, Void, Integer>() {
@ -867,7 +868,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
return !NotesPreferenceActivity.getSyncAccountName(this).trim().isEmpty();
}
private void startPreferenceActivity() {

@ -33,15 +33,15 @@ import java.util.Iterator;
public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter";
private Context mContext;
private HashMap<Integer, Boolean> mSelectedIndex;
private final Context mContext;
private final 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);
@ -92,8 +92,8 @@ public class NotesListAdapter extends CursorAdapter {
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 (Boolean.TRUE.equals(mSelectedIndex.get(position))) {
long id = getItemId(position);
if (id == Notes.ID_ROOT_FOLDER) {
Log.d(TAG, "Wrong item id, should not happen");
} else {
@ -108,7 +108,7 @@ public class NotesListAdapter extends CursorAdapter {
public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) {
if (Boolean.TRUE.equals(mSelectedIndex.get(position))) {
Cursor c = (Cursor) getItem(position);
if (c != null) {
AppWidgetAttribute widget = new AppWidgetAttribute();
@ -130,13 +130,10 @@ public class NotesListAdapter extends CursorAdapter {
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()) {
if (iter.next()) {
count++;
}
}
@ -152,7 +149,7 @@ public class NotesListAdapter extends CursorAdapter {
if (null == mSelectedIndex.get(position)) {
return false;
}
return mSelectedIndex.get(position);
return Boolean.TRUE.equals(mSelectedIndex.get(position));
}
@Override

@ -16,6 +16,7 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.content.Context;
import android.text.format.DateUtils;
import android.view.View;
@ -31,12 +32,12 @@ 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 final ImageView mAlert;
private final TextView mTitle;
private final TextView mTime;
private final TextView mCallName;
private NoteItemData mItemData;
private CheckBox mCheckBox;
private final CheckBox mCheckBox;
public NotesListItem(Context context) {
super(context);
@ -48,6 +49,7 @@ public class NotesListItem extends LinearLayout {
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
}
@SuppressLint("SetTextI18n")
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
mCheckBox.setVisibility(View.VISIBLE);

@ -18,6 +18,7 @@ package net.micode.notes.ui;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
@ -47,6 +48,8 @@ import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService;
import java.util.Objects;
public class NotesPreferenceActivity extends PreferenceActivity {
public static final String PREFERENCE_NAME = "notes_preferences";
@ -69,12 +72,13 @@ public class NotesPreferenceActivity extends PreferenceActivity {
private boolean mHasAddedAccount;
@SuppressLint("UnspecifiedRegisterReceiverFlag")
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
/* using the app icon for navigation */
getActionBar().setDisplayHomeAsUpEnabled(true);
Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preferences);
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
@ -292,12 +296,8 @@ public class NotesPreferenceActivity extends PreferenceActivity {
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();
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, Objects.requireNonNullElse(account, ""));
editor.apply();
// clean up last sync time
setLastSyncTime(this, 0);
@ -327,7 +327,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
editor.remove(PREFERENCE_LAST_SYNC_TIME);
}
editor.commit();
editor.apply();
// clean up local gtask related info
new Thread(new Runnable() {
@ -351,7 +351,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
editor.commit();
editor.apply();
}
public static long getLastSyncTime(Context context) {
@ -375,14 +375,12 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (item.getItemId() == 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;
}
return false;
}
}

@ -31,7 +31,7 @@
android:id="@+id/hour"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginStart="5dip"
android:focusable="true"
android:focusableInTouchMode="true"
/>
@ -40,7 +40,7 @@
android:id="@+id/minute"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginStart="5dip"
android:focusable="true"
android:focusableInTouchMode="true"
/>
@ -49,7 +49,7 @@
android:id="@+id/amPm"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginStart="5dip"
android:focusable="true"
android:focusableInTouchMode="true"
/>

@ -15,7 +15,7 @@
limitations under the License.
-->
<FrameLayout
<FrameLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/list_background"
@ -37,8 +37,9 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left|center_vertical"
android:layout_marginRight="8dip"
android:textAppearance="@style/TextAppearanceSecondaryItem" />
android:layout_marginEnd="8dip"
android:textAppearance="@style/TextAppearanceSecondaryItem"
tools:ignore="RtlHardcoded" />
<ImageView
android:id="@+id/iv_alert_icon"
@ -52,8 +53,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="2dip"
android:layout_marginRight="8dip"
android:layout_marginStart="2dip"
android:layout_marginEnd="8dip"
android:textAppearance="@style/TextAppearanceSecondaryItem" />
<ImageButton
@ -81,11 +82,13 @@
android:scrollbars="none"
android:overScrollMode="never"
android:layout_gravity="left|top"
android:fadingEdgeLength="0dip">
android:fadingEdgeLength="0dip"
tools:ignore="RtlHardcoded">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_height="wrap_content"
android:orientation="horizontal">
<net.micode.notes.ui.NoteEditText
android:id="@+id/note_edit_view"
@ -97,14 +100,15 @@
android:linksClickable="false"
android:minLines="12"
android:textAppearance="@style/TextAppearancePrimaryItem"
android:lineSpacingMultiplier="1.2" />
android:lineSpacingMultiplier="1.2"
tools:ignore="RtlHardcoded" />
<LinearLayout
android:id="@+id/note_edit_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="-10dip"
android:layout_marginStart="-10dip"
android:visibility="gone" />
</LinearLayout>
</ScrollView>
@ -121,7 +125,8 @@
android:layout_height="43dip"
android:layout_width="wrap_content"
android:background="@drawable/bg_color_btn_mask"
android:layout_gravity="top|right" />
android:layout_gravity="top|right"
tools:ignore="RtlHardcoded" />
<LinearLayout
android:id="@+id/note_bg_color_selector"
@ -129,9 +134,11 @@
android:layout_height="wrap_content"
android:background="@drawable/note_edit_color_selector_panel"
android:layout_marginTop="30dip"
android:layout_marginRight="8dip"
android:layout_marginEnd="8dip"
android:layout_gravity="top|right"
android:visibility="gone">
android:baselineAligned="false"
android:visibility="gone"
tools:ignore="RtlHardcoded">
<FrameLayout
android:layout_width="0dip"
@ -151,7 +158,8 @@
android:layout_marginRight="5dip"
android:focusable="false"
android:visibility="gone"
android:src="@drawable/selected" />
android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<FrameLayout
@ -172,7 +180,8 @@
android:focusable="false"
android:visibility="gone"
android:layout_marginRight="3dip"
android:src="@drawable/selected" />
android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<FrameLayout
@ -193,7 +202,8 @@
android:focusable="false"
android:visibility="gone"
android:layout_marginRight="2dip"
android:src="@drawable/selected" />
android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<FrameLayout
@ -213,7 +223,8 @@
android:layout_gravity="bottom|right"
android:focusable="false"
android:visibility="gone"
android:src="@drawable/selected" />
android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<FrameLayout
@ -233,7 +244,8 @@
android:layout_gravity="bottom|right"
android:focusable="false"
android:visibility="gone"
android:src="@drawable/selected" />
android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout>
</LinearLayout>
@ -243,6 +255,7 @@
android:layout_height="wrap_content"
android:background="@drawable/font_size_selector_bg"
android:layout_gravity="bottom"
android:baselineAligned="false"
android:visibility="gone">
<FrameLayout
@ -256,7 +269,8 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center">
android:gravity="center"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
@ -276,11 +290,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginRight="6dip"
android:layout_marginEnd="6dip"
android:layout_marginBottom="-7dip"
android:focusable="false"
android:visibility="gone"
android:src="@drawable/selected" />
android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<FrameLayout
@ -294,7 +309,8 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center">
android:gravity="center"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
@ -316,9 +332,10 @@
android:layout_gravity="bottom|right"
android:focusable="false"
android:visibility="gone"
android:layout_marginRight="6dip"
android:layout_marginEnd="6dip"
android:layout_marginBottom="-7dip"
android:src="@drawable/selected" />
android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<FrameLayout
@ -332,7 +349,8 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center">
android:gravity="center"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
@ -354,9 +372,10 @@
android:layout_gravity="bottom|right"
android:focusable="false"
android:visibility="gone"
android:layout_marginRight="6dip"
android:layout_marginEnd="6dip"
android:layout_marginBottom="-7dip"
android:src="@drawable/selected" />
android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<FrameLayout
@ -370,7 +389,8 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center">
android:gravity="center"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
@ -392,9 +412,10 @@
android:layout_gravity="bottom|right"
android:focusable="false"
android:visibility="gone"
android:layout_marginRight="6dip"
android:layout_marginEnd="6dip"
android:layout_marginBottom="-7dip"
android:src="@drawable/selected" />
android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout>
</LinearLayout>
</FrameLayout>

@ -17,6 +17,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
@ -26,7 +27,8 @@
android:layout_height="28dip"
android:checked="false"
android:focusable="false"
android:layout_gravity="top|left" />
android:layout_gravity="top|left"
tools:ignore="RtlHardcoded" />
<net.micode.notes.ui.NoteEditText
android:id="@+id/et_edit_text"

@ -17,6 +17,7 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/note_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
@ -39,7 +40,8 @@
android:layout_height="0dip"
android:layout_weight="1"
android:textAppearance="@style/TextAppearancePrimaryItem"
android:visibility="gone" />
android:visibility="gone"
tools:ignore="NestedWeights" />
<LinearLayout
android:layout_width="fill_parent"
@ -74,5 +76,6 @@
android:id="@+id/iv_alert_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"/>
android:layout_gravity="top|right"
tools:ignore="RtlHardcoded" />
</FrameLayout>

@ -45,7 +45,7 @@
android:cacheColorHint="@null"
android:listSelector="@android:color/transparent"
android:divider="@null"
android:fadingEdge="@null" />
android:fadingEdge="none" />
</LinearLayout>
<Button

@ -17,6 +17,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigation_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -28,5 +29,6 @@
android:gravity="left|center_vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="?android:attr/borderlessButtonStyle" />
style="?android:attr/borderlessButtonStyle"
tools:ignore="RtlHardcoded" />
</LinearLayout>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save