Skip to content

Commit

Permalink
fix some problems found by code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
CampelloManuel committed Apr 28, 2024
1 parent 97fde6b commit 651ecfd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
// Pass the event to ActionBarDrawerToggle. If it returns true, then it has handled the
// drawer icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import android.os.Environment;
import android.util.Log;

import androidx.annotation.NonNull;

import com.nononsenseapps.notepad.BuildConfig;
import com.nononsenseapps.notepad.providercontract.ProviderContract;

Expand Down Expand Up @@ -73,20 +75,20 @@ public TextFileProvider() {
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
// Implement this to handle requests to delete one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public String getType(Uri uri) {
public String getType(@NonNull Uri uri) {
// TODO: Implement this to handle requests for the MIME type of the data
// at the given URI.
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public Uri insert(Uri uri, ContentValues values) {
public Uri insert(@NonNull Uri uri, ContentValues values) {
// TODO: Implement this to handle requests to insert a new row.
throw new UnsupportedOperationException("Not yet implemented");
}
Expand Down Expand Up @@ -154,7 +156,7 @@ public Cursor query(Uri uri, String[] projection, String selection,
}

@Override
public int update(Uri uri, ContentValues values, String selection,
public int update(@NonNull Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
// TODO: Implement this to handle requests to update one or more rows.
throw new UnsupportedOperationException("Not yet implemented");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import android.database.sqlite.SQLiteStatement;
import android.net.Uri;

import androidx.annotation.NonNull;

import com.nononsenseapps.helpers.NnnLogger;
import com.nononsenseapps.helpers.UpdateNotifier;
import com.nononsenseapps.notepad.BuildConfig;
Expand Down Expand Up @@ -59,7 +61,7 @@ public MyContentProvider() {
}

@Override
public String getType(Uri uri) {
public String getType(@NonNull Uri uri) {
switch (sURIMatcher.match(uri)) {
case Notification.BASEITEMCODE:
case Notification.BASEURICODE:
Expand Down Expand Up @@ -108,7 +110,7 @@ public boolean onCreate() {
}

@Override
synchronized public Uri insert(Uri uri, ContentValues values) {
synchronized public Uri insert(@NonNull Uri uri, ContentValues values) {
final SQLiteDatabase db = DatabaseHandler.getInstance(getContext())
.getWritableDatabase();

Expand Down Expand Up @@ -159,7 +161,7 @@ synchronized public Uri insert(Uri uri, ContentValues values) {
}

@Override
synchronized public int update(Uri uri, ContentValues values,
synchronized public int update(@NonNull Uri uri, ContentValues values,
String selection, String[] selectionArgs) {
final SQLiteDatabase db = DatabaseHandler.getInstance(getContext())
.getWritableDatabase();
Expand Down Expand Up @@ -299,7 +301,7 @@ synchronized private int safeDeleteItem(final SQLiteDatabase db,
}

@Override
synchronized public int delete(Uri uri, String selection,
synchronized public int delete(@NonNull Uri uri, String selection,
String[] selectionArgs) {
final SQLiteDatabase db = DatabaseHandler.getInstance(getContext())
.getWritableDatabase();
Expand Down Expand Up @@ -368,7 +370,7 @@ synchronized public int delete(Uri uri, String selection,
}

@Override
synchronized public Cursor query(Uri uri, String[] projection, String selection,
synchronized public Cursor query(@NonNull Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
Cursor result;
final long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void applyPassword() {
.getDefaultSharedPreferences(this.getContext());
String currentPassword = settings.getString(KEY_PASSWORD, "");

if ("".equals(currentPassword)) {
if (currentPassword.isEmpty()) {
// it's new => Save the password directly
settings.edit()
.putString(KEY_PASSWORD, passw1)
Expand Down Expand Up @@ -100,7 +100,7 @@ private void clearPassword() {
.getDefaultSharedPreferences(this.getContext());
String currentPassword = settings.getString(KEY_PASSWORD, "");

if ("".equals(currentPassword)) {
if (currentPassword.isEmpty()) {
// Save the (empty) password directly
settings.edit()
.putString(KEY_PASSWORD, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public boolean onCreate() {
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
public Cursor query(@NonNull Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
if (!PreferencesHelper.isSdSyncEnabled(getContext())) {
return null;
Expand All @@ -168,12 +168,12 @@ public Cursor query(Uri uri, String[] projection, String selection,
}

@Override
public String getType(Uri uri) {
public String getType(@NonNull Uri uri) {
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public Uri insert(Uri uri, ContentValues values) {
public Uri insert(@NonNull Uri uri, ContentValues values) {
if (!PreferencesHelper.isSdSyncEnabled(getContext())) {
return null;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
}

@Override
public int update(Uri uri, ContentValues values, String selection,
public int update(@NonNull Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
if (!PreferencesHelper.isSdSyncEnabled(getContext())) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.os.Message;
import android.os.Process;

import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;

import com.nononsenseapps.helpers.NnnLogger;
Expand Down Expand Up @@ -192,7 +193,7 @@ public void onMonitorChange() {
}

@Override
public void handleMessage(Message msg) {
public void handleMessage(@NonNull Message msg) {

if (synchronizers.isEmpty()) {
synchronizers.addAll(getSynchronizers());
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/nononsenseapps/ui/DateView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
Expand All @@ -48,7 +49,6 @@ public DateView(Context context) {
// TODO if you want to also show a "due time" on the note, use this instead:
// mDateFormatter = TimeFormatter.getLocalFormatterShort(context);
// as of now we only show the date, which for me is good enough.
// (note that this line is called many times in this file)
mDateFormatter = TimeFormatter.getLocalFormatterShortDateOnly(context);
}

Expand All @@ -58,8 +58,8 @@ public DateView(Context context, AttributeSet attrs) {
try {
mDateFormatter = TimeFormatter.getLocalFormatterShortDateOnly(context);
} catch (Exception e) {
// Just to function in view
mDateFormatter = new SimpleDateFormat();
// return a simple fallback formatter, just to show something in the view
mDateFormatter = new SimpleDateFormat("E d MMM yyyy, HH:ss", Locale.US);
}
}

Expand Down

0 comments on commit 651ecfd

Please sign in to comment.