BearND has uploaded a new change for review. https://gerrit.wikimedia.org/r/146629
Change subject: Checkstyle: Category Coding (some) ...................................................................... Checkstyle: Category Coding (some) Change-Id: I4824d10a1a22def72e9135a441cc90299f6ca4dd --- M scripts/templates/basichash.java.jinja M wikipedia/src/main/java/org/wikipedia/Utils.java M wikipedia/src/main/java/org/wikipedia/WikipediaApp.java M wikipedia/src/main/java/org/wikipedia/editing/summaries/EditSummaryTag.java M wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java M wikipedia/src/main/java/org/wikipedia/migration/BookmarksMigrator.java M wikipedia/src/main/java/org/wikipedia/pagehistory/usercontributions/UserContribsActivity.java M wikipedia/src/main/java/org/wikipedia/pageimages/PageImagePersistanceHelper.java M wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java M wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagePersistanceHelper.java M wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagesActivity.java M wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java M wikipedia/src/main/java/org/wikipedia/staticdata/FileAliasData.java M wikipedia/src/main/java/org/wikipedia/staticdata/MainPageNameData.java M wikipedia/src/main/java/org/wikipedia/staticdata/SpecialAliasData.java 15 files changed, 90 insertions(+), 56 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/29/146629/1 diff --git a/scripts/templates/basichash.java.jinja b/scripts/templates/basichash.java.jinja index 725e202..fc20e36 100644 --- a/scripts/templates/basichash.java.jinja +++ b/scripts/templates/basichash.java.jinja @@ -8,8 +8,10 @@ public class {{ class_name }} { private static HashMap<String, String> DATA_MAP; + private static void setupData() { - DATA_MAP = new HashMap<String, String>({{wikis|length}}); + final int SIZE = {{wikis|length}}; + DATA_MAP = new HashMap<String, String>(SIZE); {%- for wiki in wikis %} DATA_MAP.put("{{wiki.lang}}", "{{wiki.props[key]}}"); diff --git a/wikipedia/src/main/java/org/wikipedia/Utils.java b/wikipedia/src/main/java/org/wikipedia/Utils.java index 991a355..bed471b 100644 --- a/wikipedia/src/main/java/org/wikipedia/Utils.java +++ b/wikipedia/src/main/java/org/wikipedia/Utils.java @@ -84,8 +84,7 @@ public static String md5base64(final String s) { try { // Create MD5 Hash - MessageDigest digest = java.security.MessageDigest - .getInstance("MD5"); + MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(s.getBytes("utf-8")); byte[] messageDigest = digest.digest(); @@ -108,8 +107,7 @@ StringBuilder hexStr = new StringBuilder(); try { // Create MD5 Hash - MessageDigest digest = java.security.MessageDigest - .getInstance("MD5"); + MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(s.getBytes("utf-8")); byte[] messageDigest = digest.digest(); diff --git a/wikipedia/src/main/java/org/wikipedia/WikipediaApp.java b/wikipedia/src/main/java/org/wikipedia/WikipediaApp.java index 0a05d92..c523eca 100644 --- a/wikipedia/src/main/java/org/wikipedia/WikipediaApp.java +++ b/wikipedia/src/main/java/org/wikipedia/WikipediaApp.java @@ -51,8 +51,6 @@ resDialogCommentPrompt = R.string.acra_report_dialog_comment, mailTo = "mobile-android-wikipedia-cras...@wikimedia.org") public class WikipediaApp extends Application { - private Bus bus; - public static long SHORT_ANIMATION_DURATION; public static long MEDIUM_ANIMATION_DURATION; @@ -79,15 +77,18 @@ public static int THEME_LIGHT; public static int THEME_DARK; - private int currentTheme = 0; public static final int FONT_SIZE_MULTIPLIER_MIN = -5; public static final int FONT_SIZE_MULTIPLIER_MAX = 8; + private static final float FONT_SIZE_FACTOR = 0.1f; /** * Singleton instance of WikipediaApp */ private static WikipediaApp INSTANCE; + + private Bus bus; + private int currentTheme = 0; private ConnectionChangeReceiver connChangeReceiver; public static boolean FALLBACK = false; @@ -473,6 +474,6 @@ */ public float getFontSize(Window window) { int multiplier = PreferenceManager.getDefaultSharedPreferences(this).getInt(WikipediaApp.PREFERENCE_TEXT_SIZE_MULTIPLIER, 0); - return Utils.getFontSizeFromSp(window, getResources().getDimension(R.dimen.textSize)) * (1.0f + multiplier * 0.1f); + return Utils.getFontSizeFromSp(window, getResources().getDimension(R.dimen.textSize)) * (1.0f + multiplier * FONT_SIZE_FACTOR); } } diff --git a/wikipedia/src/main/java/org/wikipedia/editing/summaries/EditSummaryTag.java b/wikipedia/src/main/java/org/wikipedia/editing/summaries/EditSummaryTag.java index ac2cd51..5261930 100644 --- a/wikipedia/src/main/java/org/wikipedia/editing/summaries/EditSummaryTag.java +++ b/wikipedia/src/main/java/org/wikipedia/editing/summaries/EditSummaryTag.java @@ -10,8 +10,10 @@ import org.wikipedia.R; public class EditSummaryTag extends TextView { + public static final int MARGIN = 4; + public static final int PADDING = 8; - Resources resources; + private Resources resources; private boolean selected = false; public EditSummaryTag(Context context) { @@ -37,8 +39,8 @@ LayoutParams.WRAP_CONTENT ); - int margin = getDp(4); - int padding = getDp(8); + int margin = getDp(MARGIN); + int padding = getDp(PADDING); params.setMargins(margin, margin, margin, margin); setLayoutParams(params); @@ -75,10 +77,6 @@ } private int getDp(int dp) { - return (int) TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, - dp, - resources.getDisplayMetrics() - ); + return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); } } \ No newline at end of file diff --git a/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java b/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java index 256d8c9..4cd0fc4 100644 --- a/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java +++ b/wikipedia/src/main/java/org/wikipedia/history/HistoryEntryPersistanceHelper.java @@ -9,24 +9,30 @@ import java.util.Date; public class HistoryEntryPersistanceHelper extends PersistanceHelper<HistoryEntry> { + + private static final int COL_INDEX_SITE = 1; + private static final int COL_INDEX_TITLE = 2; + private static final int COL_INDEX_TIMESTAMP = 3; + private static final int COL_INDEX_SOURCE = 4; + @Override public HistoryEntry fromCursor(Cursor c) { // Carefully, get them back by using position only - Site site = new Site(c.getString(1)); + Site site = new Site(c.getString(COL_INDEX_SITE)); // FIXME: Does not handle non mainspace pages - PageTitle title = new PageTitle(null, c.getString(2), site); - Date timestamp = new Date(c.getLong(3)); - int source = c.getInt(4); + PageTitle title = new PageTitle(null, c.getString(COL_INDEX_TITLE), site); + Date timestamp = new Date(c.getLong(COL_INDEX_TIMESTAMP)); + int source = c.getInt(COL_INDEX_SOURCE); return new HistoryEntry(title, timestamp, source); } @Override protected ContentValues toContentValues(HistoryEntry obj) { ContentValues contentValues = new ContentValues(); + contentValues.put("site", obj.getTitle().getSite().getDomain()); contentValues.put("title", obj.getTitle().getPrefixedText()); contentValues.put("timestamp", obj.getTimestamp().getTime()); contentValues.put("source", obj.getSource()); - contentValues.put("site", obj.getTitle().getSite().getDomain()); return contentValues; } @@ -60,6 +66,4 @@ protected String[] getPrimaryKeySelectionArgs(HistoryEntry obj) { throw new UnsupportedOperationException("No Primary Keys make sense for History"); } - - } diff --git a/wikipedia/src/main/java/org/wikipedia/migration/BookmarksMigrator.java b/wikipedia/src/main/java/org/wikipedia/migration/BookmarksMigrator.java index de3a0e8..6f50512 100644 --- a/wikipedia/src/main/java/org/wikipedia/migration/BookmarksMigrator.java +++ b/wikipedia/src/main/java/org/wikipedia/migration/BookmarksMigrator.java @@ -24,6 +24,9 @@ * since this will not be needed after that. One time migration, isn't it? */ public class BookmarksMigrator { + private static final int COL_INDEX_SITE = 1; + private static final int COL_INDEX_TITLE = 2; + private static final int COL_INDEX_TIME = 3; private final WikipediaApp app; public BookmarksMigrator(WikipediaApp app) { @@ -48,9 +51,9 @@ int rowsFound = 0; cur.moveToFirst(); while (!cur.isAfterLast()) { - Site site = new Site(cur.getString(1)); - PageTitle title = new PageTitle(cur.getString(2), site); - Date timestamp = new Date(cur.getLong(3)); + Site site = new Site(cur.getString(COL_INDEX_SITE)); + PageTitle title = new PageTitle(cur.getString(COL_INDEX_TITLE), site); + Date timestamp = new Date(cur.getLong(COL_INDEX_TIME)); SavedPage page = new SavedPage(title, timestamp); app.getPersister(SavedPage.class).upsert(page); Log.d("Wikipedia", "Migrated " + title.getDisplayText()); diff --git a/wikipedia/src/main/java/org/wikipedia/pagehistory/usercontributions/UserContribsActivity.java b/wikipedia/src/main/java/org/wikipedia/pagehistory/usercontributions/UserContribsActivity.java index 6faaabf..b537214 100644 --- a/wikipedia/src/main/java/org/wikipedia/pagehistory/usercontributions/UserContribsActivity.java +++ b/wikipedia/src/main/java/org/wikipedia/pagehistory/usercontributions/UserContribsActivity.java @@ -17,6 +17,8 @@ import java.util.ArrayList; public class UserContribsActivity extends ThemedActionBarActivity { + private static final int NUMBER_TO_FETCH = 24; + private ListView userContribsList; private View moreContainer; private TextView moreText; @@ -66,7 +68,7 @@ if (isFetching) { return; } - new FetchUserContribsTask(this, app.getPrimarySite(), app.getUserInfoStorage().getUser().getUsername(), 24, lastContinue) { + new FetchUserContribsTask(this, app.getPrimarySite(), app.getUserInfoStorage().getUser().getUsername(), NUMBER_TO_FETCH, lastContinue) { @Override public void onBeforeExecute() { isFetching = true; diff --git a/wikipedia/src/main/java/org/wikipedia/pageimages/PageImagePersistanceHelper.java b/wikipedia/src/main/java/org/wikipedia/pageimages/PageImagePersistanceHelper.java index 5522134..0897afd 100644 --- a/wikipedia/src/main/java/org/wikipedia/pageimages/PageImagePersistanceHelper.java +++ b/wikipedia/src/main/java/org/wikipedia/pageimages/PageImagePersistanceHelper.java @@ -7,13 +7,18 @@ import org.wikipedia.data.PersistanceHelper; public class PageImagePersistanceHelper extends PersistanceHelper<PageImage> { + + private static final int COL_INDEX_SITE = 1; + private static final int COL_INDEX_TITLE = 2; + private static final int COL_INDEX_IMAGE_NAME = 3; + @Override public PageImage fromCursor(Cursor c) { // Carefully, get them back by using position only - Site site = new Site(c.getString(1)); + Site site = new Site(c.getString(COL_INDEX_SITE)); // FIXME: Does not handle non mainspace pages - PageTitle title = new PageTitle(null, c.getString(2), site); - String imageName = c.getString(3); + PageTitle title = new PageTitle(null, c.getString(COL_INDEX_TITLE), site); + String imageName = c.getString(COL_INDEX_IMAGE_NAME); return new PageImage(title, imageName); } diff --git a/wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java b/wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java index 755d21c..3f4b1bd 100644 --- a/wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java +++ b/wikipedia/src/main/java/org/wikipedia/pageimages/PageImageSaveTask.java @@ -8,9 +8,12 @@ import java.util.Map; public class PageImageSaveTask extends PageImagesTask { + private static final int SIZE = 96; + private final WikipediaApp app; + public PageImageSaveTask(WikipediaApp app, Api api, PageTitle title) { - super(api, title.getSite(), Arrays.asList(new PageTitle[] {title}), 96); + super(api, title.getSite(), Arrays.asList(new PageTitle[] {title}), SIZE); this.app = app; } diff --git a/wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagePersistanceHelper.java b/wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagePersistanceHelper.java index 1faaac0..0e71b0c 100644 --- a/wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagePersistanceHelper.java +++ b/wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagePersistanceHelper.java @@ -9,13 +9,18 @@ import java.util.Date; public class SavedPagePersistanceHelper extends PersistanceHelper<SavedPage> { + + private static final int COL_INDEX_SITE = 1; + private static final int COL_INDEX_TITLE = 2; + private static final int COL_INDEX_TIME = 3; + @Override public SavedPage fromCursor(Cursor c) { // Carefully, get them back by using position only - Site site = new Site(c.getString(1)); + Site site = new Site(c.getString(COL_INDEX_SITE)); // FIXME: Does not handle non mainspace pages - PageTitle title = new PageTitle(null, c.getString(2), site); - Date timestamp = new Date(c.getLong(3)); + PageTitle title = new PageTitle(null, c.getString(COL_INDEX_TITLE), site); + Date timestamp = new Date(c.getLong(COL_INDEX_TIME)); return new SavedPage(title, timestamp); } @@ -65,6 +70,4 @@ obj.getTitle().getPrefixedText() }; } - - } diff --git a/wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagesActivity.java b/wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagesActivity.java index dc123e4..0ece511 100644 --- a/wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagesActivity.java +++ b/wikipedia/src/main/java/org/wikipedia/savedpages/SavedPagesActivity.java @@ -211,6 +211,10 @@ } private class SavedPagesAdapter extends CursorAdapter { + + /** see SavedPageContentProvider.query() MATCH_WITH_PAGEIMAGES */ + private static final int COL_INDEX_IMAGE_NAME = 4; + public SavedPagesAdapter(Context context, Cursor c, boolean autoRequery) { super(context, c, autoRequery); } @@ -233,7 +237,7 @@ view.setTag(entry); Picasso.with(SavedPagesActivity.this) - .load(cursor.getString(4)) + .load(cursor.getString(COL_INDEX_IMAGE_NAME)) .placeholder(R.drawable.ic_pageimage_placeholder) .error(R.drawable.ic_pageimage_placeholder) .into(thumbnail); @@ -254,7 +258,6 @@ } else { sectionHeader.setVisibility(View.GONE); } - } } diff --git a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java index b421f71..66ae51d 100644 --- a/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java +++ b/wikipedia/src/main/java/org/wikipedia/search/SearchArticlesFragment.java @@ -47,7 +47,12 @@ public class SearchArticlesFragment extends Fragment { private static final int DELAY_MILLIS = 300; - + private static final int MAX_CACHE_SIZE_SEARCH_RESULTS = 4; + private static final int MAX_CACHE_SIZE_IMAGES = 48; + private static final float THUMB_SIZE_DP = 48f; + private static final int LEFT_MARGIN_BASE_DP = 10; + private static float OFFSET_WINDOW_MAX = 0.5f; + private static float OFFSET_WINDOW_MIN = 0f; private static final int MESSAGE_SEARCH = 1; private WikipediaApp app; @@ -73,8 +78,10 @@ private boolean isSearchActive = false; - private ParcelableLruCache<List<PageTitle>> searchResultsCache = new ParcelableLruCache<List<PageTitle>>(4, List.class); - private ParcelableLruCache<String> pageImagesCache = new ParcelableLruCache<String>(48, String.class); + private ParcelableLruCache<List<PageTitle>> searchResultsCache + = new ParcelableLruCache<List<PageTitle>>(MAX_CACHE_SIZE_SEARCH_RESULTS, List.class); + private ParcelableLruCache<String> pageImagesCache + = new ParcelableLruCache<String>(MAX_CACHE_SIZE_IMAGES, String.class); private String lastSearchedText; private Handler searchHandler; @@ -116,7 +123,7 @@ app.getAPIForSite(app.getPrimarySite()), app.getPrimarySite(), results, - (int)(48f * WikipediaApp.SCREEN_DENSITY)) { + (int)(THUMB_SIZE_DP * WikipediaApp.SCREEN_DENSITY)) { @Override public void onFinish(Map<PageTitle, String> result) { for (Map.Entry<PageTitle, String> entry : result.entrySet()) { @@ -335,8 +342,8 @@ drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { private boolean hideKeyboardCalled = false; - private float offsetWindow = 0.5f; - private float offsetWindowMax = offsetWindow, offsetWindowMin = 0f; + private float offsetWindow = OFFSET_WINDOW_MAX; + @Override public void onDrawerSlide(View drawerView, float slideOffset) { // Hide the keyboard when the drawer is opened @@ -349,15 +356,15 @@ // Animation for sliding drawer open and close // Modeled after the general behavior of Google apps // Shift left and right margins appropriately to make sure that the rest of the layout does not shift - if (slideOffset >= offsetWindowMax) { - offsetWindowMax = slideOffset; - offsetWindowMin = offsetWindowMax - offsetWindow; - } else if (slideOffset < offsetWindowMin) { - offsetWindowMin = slideOffset; - offsetWindowMax = offsetWindowMin + offsetWindow; + if (slideOffset >= OFFSET_WINDOW_MAX) { + OFFSET_WINDOW_MAX = slideOffset; + OFFSET_WINDOW_MIN = OFFSET_WINDOW_MAX - offsetWindow; + } else if (slideOffset < OFFSET_WINDOW_MIN) { + OFFSET_WINDOW_MIN = slideOffset; + OFFSET_WINDOW_MAX = OFFSET_WINDOW_MIN + offsetWindow; } LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(drawerIndicator.getLayoutParams()); - params.leftMargin = -(int)(10 * WikipediaApp.SCREEN_DENSITY * offsetWindowMin); + params.leftMargin = -(int)(LEFT_MARGIN_BASE_DP * WikipediaApp.SCREEN_DENSITY * OFFSET_WINDOW_MIN); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && drawerView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { params.leftMargin = -params.leftMargin; @@ -373,7 +380,6 @@ } } }); - } @Override diff --git a/wikipedia/src/main/java/org/wikipedia/staticdata/FileAliasData.java b/wikipedia/src/main/java/org/wikipedia/staticdata/FileAliasData.java index f285b51..c510763 100644 --- a/wikipedia/src/main/java/org/wikipedia/staticdata/FileAliasData.java +++ b/wikipedia/src/main/java/org/wikipedia/staticdata/FileAliasData.java @@ -8,8 +8,10 @@ public class FileAliasData { private static HashMap<String, String> DATA_MAP; + private static void setupData() { - DATA_MAP = new HashMap<String, String>(287); + final int SIZE = 287; + DATA_MAP = new HashMap<String, String>(SIZE); DATA_MAP.put("en", "File"); DATA_MAP.put("nl", "Bestand"); DATA_MAP.put("de", "Datei"); diff --git a/wikipedia/src/main/java/org/wikipedia/staticdata/MainPageNameData.java b/wikipedia/src/main/java/org/wikipedia/staticdata/MainPageNameData.java index 43a8428..97c999c 100644 --- a/wikipedia/src/main/java/org/wikipedia/staticdata/MainPageNameData.java +++ b/wikipedia/src/main/java/org/wikipedia/staticdata/MainPageNameData.java @@ -8,8 +8,10 @@ public class MainPageNameData { private static HashMap<String, String> DATA_MAP; + private static void setupData() { - DATA_MAP = new HashMap<String, String>(287); + final int SIZE = 287; + DATA_MAP = new HashMap<String, String>(SIZE); DATA_MAP.put("en", "Main Page"); DATA_MAP.put("nl", "Hoofdpagina"); DATA_MAP.put("de", "Wikipedia:Hauptseite"); diff --git a/wikipedia/src/main/java/org/wikipedia/staticdata/SpecialAliasData.java b/wikipedia/src/main/java/org/wikipedia/staticdata/SpecialAliasData.java index 3c219d3..ad27139 100644 --- a/wikipedia/src/main/java/org/wikipedia/staticdata/SpecialAliasData.java +++ b/wikipedia/src/main/java/org/wikipedia/staticdata/SpecialAliasData.java @@ -8,8 +8,10 @@ public class SpecialAliasData { private static HashMap<String, String> DATA_MAP; + private static void setupData() { - DATA_MAP = new HashMap<String, String>(287); + final int SIZE = 287; + DATA_MAP = new HashMap<String, String>(SIZE); DATA_MAP.put("en", "Special"); DATA_MAP.put("nl", "Speciaal"); DATA_MAP.put("de", "Spezial"); -- To view, visit https://gerrit.wikimedia.org/r/146629 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4824d10a1a22def72e9135a441cc90299f6ca4dd Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: BearND <bsitzm...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits