diff options
author | Michael Keppler <michael.keppler@etas.com> | 2015-01-03 09:17:09 +0100 |
---|---|---|
committer | Michael Keppler <michael.keppler@etas.com> | 2015-01-03 09:17:09 +0100 |
commit | 213ce4c0f819eb54d97e9ecc43a471b792b9372c (patch) | |
tree | acc6bb3324a128481a8fd5993f39ae626bd7d286 /cgeo-calendar | |
parent | 419816fd76b8dbd3e8117fcdd99c3ea30c46e17c (diff) | |
download | cgeo-213ce4c0f819eb54d97e9ecc43a471b792b9372c.zip cgeo-213ce4c0f819eb54d97e9ecc43a471b792b9372c.tar.gz cgeo-213ce4c0f819eb54d97e9ecc43a471b792b9372c.tar.bz2 |
some code cleanups with Android Studio
Diffstat (limited to 'cgeo-calendar')
6 files changed, 34 insertions, 32 deletions
diff --git a/cgeo-calendar/src/cgeo/calendar/AbstractAddEntry.java b/cgeo-calendar/src/cgeo/calendar/AbstractAddEntry.java index 31e2bd9..893161c 100644 --- a/cgeo-calendar/src/cgeo/calendar/AbstractAddEntry.java +++ b/cgeo-calendar/src/cgeo/calendar/AbstractAddEntry.java @@ -4,10 +4,10 @@ import android.util.Log; abstract class AbstractAddEntry { - protected CalendarEntry entry; - protected CalendarActivity activity; + protected final CalendarEntry entry; + protected final CalendarActivity activity; - public AbstractAddEntry(final CalendarEntry entry, CalendarActivity activity) { + public AbstractAddEntry(final CalendarEntry entry, final CalendarActivity activity) { this.entry = entry; this.activity = activity; } @@ -16,7 +16,7 @@ abstract class AbstractAddEntry { try { addEntryToCalendarInternal(); activity.showToast(R.string.event_success); - } catch (Exception e) { + } catch (final Exception e) { activity.showToast(R.string.event_fail); Log.e(CalendarActivity.LOG_TAG, "addToCalendar", e); diff --git a/cgeo-calendar/src/cgeo/calendar/AddEntry.java b/cgeo-calendar/src/cgeo/calendar/AddEntry.java index cdb59d9..30af346 100644 --- a/cgeo-calendar/src/cgeo/calendar/AddEntry.java +++ b/cgeo-calendar/src/cgeo/calendar/AddEntry.java @@ -8,14 +8,15 @@ import java.util.Date; class AddEntry extends AbstractAddEntry { - private int calendarId; + private final int calendarId; /** * @param entry + * new entry to be stored * @param calendarId - * The selected calendar + * The selected calendar */ - public AddEntry(CalendarEntry entry, CalendarActivity activity, int calendarId) { + public AddEntry(final CalendarEntry entry, final CalendarActivity activity, final int calendarId) { super(entry, activity); this.calendarId = calendarId; } diff --git a/cgeo-calendar/src/cgeo/calendar/AddEntryLevel14.java b/cgeo-calendar/src/cgeo/calendar/AddEntryLevel14.java index 0ceed67..11820b4 100644 --- a/cgeo-calendar/src/cgeo/calendar/AddEntryLevel14.java +++ b/cgeo-calendar/src/cgeo/calendar/AddEntryLevel14.java @@ -12,7 +12,7 @@ import java.util.Date; */ class AddEntryLevel14 extends AbstractAddEntry { - public AddEntryLevel14(CalendarEntry entry, CalendarActivity activity) { + public AddEntryLevel14(final CalendarEntry entry, final CalendarActivity activity) { super(entry, activity); } diff --git a/cgeo-calendar/src/cgeo/calendar/CalendarActivity.java b/cgeo-calendar/src/cgeo/calendar/CalendarActivity.java index 14d71b4..2f0c08d 100644 --- a/cgeo-calendar/src/cgeo/calendar/CalendarActivity.java +++ b/cgeo-calendar/src/cgeo/calendar/CalendarActivity.java @@ -16,7 +16,7 @@ public final class CalendarActivity extends Activity { /** Called when the activity is first created. */ @Override - public void onCreate(Bundle savedInstanceState) { + public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { @@ -35,7 +35,7 @@ public final class CalendarActivity extends Activity { } else { selectCalendarForAdding(entry); } - } catch (Exception e) { + } catch (final Exception e) { Log.e(LOG_TAG, e.getMessage(), e); finish(); } @@ -45,6 +45,7 @@ public final class CalendarActivity extends Activity { * Adds the cache to the Android-calendar if it is an event. * * @param entry + * new entry to be stored */ private void selectCalendarForAdding(final CalendarEntry entry) { final SparseArray<String> calendars = queryCalendars(); @@ -64,7 +65,7 @@ public final class CalendarActivity extends Activity { builder.setTitle(R.string.calendars); builder.setItems(items, new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int item) { + public void onClick(final DialogInterface dialog, final int item) { final int calendarId = calendars.keyAt(item); new AddEntry(entry, CalendarActivity.this, calendarId).addEntryToCalendar(); finish(); @@ -72,7 +73,7 @@ public final class CalendarActivity extends Activity { }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override - public void onCancel(DialogInterface dialog) { + public void onCancel(final DialogInterface dialog) { finish(); } }); @@ -82,11 +83,11 @@ public final class CalendarActivity extends Activity { private SparseArray<String> queryCalendars() { final SparseArray<String> calendars = new SparseArray<>(); - final String[] projection = new String[] { "_id", "displayName" }; final Uri calendarProvider = Compatibility.getCalendarProviderURI(); Cursor cursor = null; try { + final String[] projection = new String[]{"_id", "displayName"}; cursor = getContentResolver().query(calendarProvider, projection, "selected=1", null, null); if (cursor == null) { @@ -102,13 +103,13 @@ public final class CalendarActivity extends Activity { final String idString = cursor.getString(indexId); if (idString != null) { try { - int id = Integer.parseInt(idString); + final int id = Integer.parseInt(idString); final String calName = cursor.getString(indexName); if (id > 0 && calName != null) { calendars.put(id, calName); } - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { Log.e(LOG_TAG, "CalendarActivity.selectCalendarForAdding", e); } } diff --git a/cgeo-calendar/src/cgeo/calendar/CalendarEntry.java b/cgeo-calendar/src/cgeo/calendar/CalendarEntry.java index a1761c7..1e37d6b 100644 --- a/cgeo-calendar/src/cgeo/calendar/CalendarEntry.java +++ b/cgeo-calendar/src/cgeo/calendar/CalendarEntry.java @@ -16,14 +16,14 @@ import java.util.Date; class CalendarEntry { - private String shortDesc; - private String hiddenDate; - private String url; - private String personalNote; - private String name; - private String coords; + private final String shortDesc; + private final String hiddenDate; + private final String url; + private final String personalNote; + private final String name; + private final String coords; private int startTimeMinutes = -1; - private Uri uri; + private final Uri uri; public CalendarEntry(final Uri uri) { this.uri = uri; @@ -37,7 +37,7 @@ class CalendarEntry { if (startTime.length() > 0) { try { this.startTimeMinutes = Integer.parseInt(startTime); - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { Log.e("CalendarEntry creation", e); } } @@ -50,7 +50,7 @@ class CalendarEntry { return ""; } return URLDecoder.decode(param, CharEncoding.UTF_8).trim(); - } catch (UnsupportedEncodingException e) { + } catch (final UnsupportedEncodingException e) { Log.e("CalendarEntry.getParameter", e); } return ""; @@ -81,14 +81,14 @@ class CalendarEntry { */ protected Date parseDate() { try { - Calendar cal = Calendar.getInstance(); + final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(Long.parseLong(getHiddenDate())); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); return cal.getTime(); - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { // cannot happen normally, but static code analysis does not know } return null; diff --git a/cgeo-calendar/src/cgeo/calendar/Compatibility.java b/cgeo-calendar/src/cgeo/calendar/Compatibility.java index 8813f41..ff14a0f 100644 --- a/cgeo-calendar/src/cgeo/calendar/Compatibility.java +++ b/cgeo-calendar/src/cgeo/calendar/Compatibility.java @@ -5,19 +5,19 @@ import android.os.Build; public final class Compatibility { - private final static int sdkVersion = Build.VERSION.SDK_INT; - private final static boolean isLevel8 = sdkVersion >= 8; - private final static boolean isLevel14 = sdkVersion >= 14; + private final static int SDK_VERSION = Build.VERSION.SDK_INT; + private final static boolean IS_LEVEL_8 = SDK_VERSION >= 8; + private final static boolean IS_LEVEL_14 = SDK_VERSION >= 14; public static Uri getCalendarProviderURI() { - return Uri.parse(isLevel8 ? "content://com.android.calendar/calendars" : "content://calendar/calendars"); + return Uri.parse(IS_LEVEL_8 ? "content://com.android.calendar/calendars" : "content://calendar/calendars"); } public static Uri getCalendarEventsProviderURI() { - return Uri.parse(isLevel8 ? "content://com.android.calendar/events" : "content://calendar/events"); + return Uri.parse(IS_LEVEL_8 ? "content://com.android.calendar/events" : "content://calendar/events"); } public static boolean isLevel14() { - return isLevel14; + return IS_LEVEL_14; } } |