Merge remote-tracking branch 'refs/remotes/commons-app/master'

This commit is contained in:
Josephine Lim 2017-03-03 01:02:51 +10:00
commit 031b1faa38
31 changed files with 339 additions and 99 deletions

View file

@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply from: 'quality.gradle'
dependencies {
compile ('com.github.nicolas-raoul:Quadtree:211b6fe59ac48f') {

23
app/quality.gradle Normal file
View file

@ -0,0 +1,23 @@
apply plugin: 'checkstyle'
check.dependsOn 'checkstyle'
checkstyle {
toolVersion = '7.5.1'
}
task checkstyle(type: Checkstyle) {
configFile file("${project.rootDir}/script/style/checkstyle.xml")
source 'src'
include '**/*.java'
exclude '**/gen/**'
classpath = files()
reports {
html {
enabled true
destination "$project.buildDir/reports/checkstyle/checkstyle.html"
}
}
}

View file

@ -24,8 +24,8 @@ public class AboutActivity extends Activity {
privacyPolicyText = (TextView) findViewById(R.id.about_privacy_policy);
uploadsToText = (TextView) findViewById(R.id.about_uploads_to);
uploadsToText.setText(fr.free.nrw.commons.CommonsApplication.EVENTLOG_WIKI);
versionText.setText(fr.free.nrw.commons.CommonsApplication.APPLICATION_VERSION);
uploadsToText.setText(CommonsApplication.EVENTLOG_WIKI);
versionText.setText(CommonsApplication.APPLICATION_VERSION);
// We can't use formatted strings directly because it breaks with
// our localization tools. Grab an HTML string and turn it into

View file

@ -122,7 +122,7 @@ public class CommonsApplication extends Application {
if (maxMem < 48L * 1024L * 1024L) {
// Cache only one bitmap if VM memory is too small (such as Nexus One);
Log.d("Commons", "Skipping bitmap cache; max mem is: " + maxMem);
imageCache = new LruCache<String, Bitmap>(1);
imageCache = new LruCache<>(1);
} else {
int cacheSize = (int) (maxMem / (1024 * 8));
Log.d("Commons", "Bitmap cache size " + cacheSize + " from max mem " + maxMem);

View file

@ -11,7 +11,7 @@ import java.util.Map;
import java.util.Set;
public class LicenseList {
Map<String, fr.free.nrw.commons.License> licenses = new HashMap<String, fr.free.nrw.commons.License>();
Map<String, License> licenses = new HashMap<>();
Resources res;
private static String XMLNS_LICENSE = "https://www.mediawiki.org/wiki/Extension:UploadWizard/xmlns/licenses";
@ -19,12 +19,12 @@ public class LicenseList {
public LicenseList(Activity activity) {
res = activity.getResources();
XmlPullParser parser = res.getXml(R.xml.wikimedia_licenses);
while (fr.free.nrw.commons.Utils.xmlFastForward(parser, XMLNS_LICENSE, "license")) {
while (Utils.xmlFastForward(parser, XMLNS_LICENSE, "license")) {
String id = parser.getAttributeValue(null, "id");
String template = parser.getAttributeValue(null, "template");
String url = parser.getAttributeValue(null, "url");
String name = nameForTemplate(template);
fr.free.nrw.commons.License license = new fr.free.nrw.commons.License(id, template, url, name);
License license = new License(id, template, url, name);
licenses.put(id, license);
}
}
@ -33,18 +33,18 @@ public class LicenseList {
return licenses.keySet();
}
public Collection<fr.free.nrw.commons.License> values() {
public Collection<License> values() {
return licenses.values();
}
public fr.free.nrw.commons.License get(String key) {
public License get(String key) {
return licenses.get(key);
}
public fr.free.nrw.commons.License licenseForTemplate(String template) {
String ucTemplate = fr.free.nrw.commons.Utils.capitalize(template);
for (fr.free.nrw.commons.License license : values()) {
if (ucTemplate.equals(fr.free.nrw.commons.Utils.capitalize(license.getTemplate()))) {
public License licenseForTemplate(String template) {
String ucTemplate = Utils.capitalize(template);
for (License license : values()) {
if (ucTemplate.equals(Utils.capitalize(license.getTemplate()))) {
return license;
}
}

View file

@ -27,11 +27,11 @@ public class Media implements Parcelable {
};
protected Media() {
this.categories = new ArrayList<String>();
this.descriptions = new HashMap<String, String>();
this.categories = new ArrayList<>();
this.descriptions = new HashMap<>();
}
private HashMap<String, Object> tags = new HashMap<String, Object>();
private HashMap<String, Object> tags = new HashMap<>();
public Object getTag(String key) {
return tags.get(key);

View file

@ -46,8 +46,8 @@ public class MediaDataExtractor {
*/
public MediaDataExtractor(String filename, LicenseList licenseList) {
this.filename = filename;
categories = new ArrayList<String>();
descriptions = new HashMap<String, String>();
categories = new ArrayList<>();
descriptions = new HashMap<>();
fetched = false;
processed = false;
this.licenseList = licenseList;
@ -251,7 +251,7 @@ public class MediaDataExtractor {
// Texts are wrapped in things like {{en|foo} or {{en|1=foo bar}}.
// Text outside those wrappers is stuffed into a 'default' faux language key if present.
private Map<String, String> getMultilingualText(Node parentNode) throws IOException {
Map<String, String> texts = new HashMap<String, String>();
Map<String, String> texts = new HashMap<>();
StringBuilder localText = new StringBuilder();
NodeList nodes = parentNode.getChildNodes();

View file

@ -13,7 +13,7 @@ import android.view.View;
import android.view.ViewGroup;
public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
fr.free.nrw.commons.CommonsApplication app;
CommonsApplication app;
private AppCompatDelegate mDelegate;
@ -23,7 +23,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
ListPreference licensePreference = (ListPreference) findPreference(fr.free.nrw.commons.Prefs.DEFAULT_LICENSE);
ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
// WARNING: ORDERING NEEDS TO MATCH FOR THE LICENSE NAMES AND DISPLAY VALUES
licensePreference.setEntries(new String[]{
getString(R.string.license_name_cc0),
@ -31,21 +31,21 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
getString(R.string.license_name_cc_by_sa)
});
licensePreference.setEntryValues(new String[]{
fr.free.nrw.commons.Prefs.Licenses.CC0,
fr.free.nrw.commons.Prefs.Licenses.CC_BY,
fr.free.nrw.commons.Prefs.Licenses.CC_BY_SA
Prefs.Licenses.CC0,
Prefs.Licenses.CC_BY,
Prefs.Licenses.CC_BY_SA
});
licensePreference.setSummary(getString(fr.free.nrw.commons.Utils.licenseNameFor(licensePreference.getValue())));
licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));
licensePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(getString(fr.free.nrw.commons.Utils.licenseNameFor((String)newValue)));
preference.setSummary(getString(Utils.licenseNameFor((String)newValue)));
return true;
}
});
app = (fr.free.nrw.commons.CommonsApplication)getApplicationContext();
app = (CommonsApplication)getApplicationContext();
}
@Override

View file

@ -17,9 +17,6 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
@ -34,12 +31,13 @@ import java.util.TimeZone;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import fr.free.nrw.commons.upload.ShareActivity;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
public class Utils {
@ -104,7 +102,7 @@ public class Utils {
}
public static String getStringFromDOM(Node dom) {
javax.xml.transform.Transformer transformer = null;
Transformer transformer = null;
try {
transformer = TransformerFactory.newInstance().newTransformer();
} catch (TransformerConfigurationException e) {
@ -116,8 +114,8 @@ public class Utils {
}
StringWriter outputStream = new StringWriter();
javax.xml.transform.dom.DOMSource domSource = new javax.xml.transform.dom.DOMSource(dom);
javax.xml.transform.stream.StreamResult strResult = new javax.xml.transform.stream.StreamResult(outputStream);
DOMSource domSource = new DOMSource(dom);
StreamResult strResult = new StreamResult(outputStream);
try {
transformer.transform(domSource, strResult);

View file

@ -1,5 +1,6 @@
package fr.free.nrw.commons.auth;
import android.accounts.AccountManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
@ -10,7 +11,7 @@ public class WikiAccountAuthenticatorService extends Service{
@Override
public IBinder onBind(Intent intent) {
if (!intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT)) {
if (!intent.getAction().equals(AccountManager.ACTION_AUTHENTICATOR_INTENT)) {
return null;
}

View file

@ -33,7 +33,7 @@ public class CacheController {
}
public void cacheCategory() {
List<String> pointCatList = new ArrayList<String>();
List<String> pointCatList = new ArrayList<>();
if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true) {
pointCatList.addAll(MwVolleyApi.getGpsCat());
Log.d(TAG, "Categories being cached: " + pointCatList);
@ -47,7 +47,7 @@ public class CacheController {
//Convert decLatitude and decLongitude to a coordinate offset range
convertCoordRange();
pointsFound = quadTree.searchWithin(xMinus, yMinus, xPlus, yPlus);
List<String> displayCatList = new ArrayList<String>();
List<String> displayCatList = new ArrayList<>();
Log.d(TAG, "Points found in quadtree: " + Arrays.asList(pointsFound));
if (pointsFound.length != 0) {

View file

@ -7,10 +7,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.TreeSet;
import fr.free.nrw.commons.R;

View file

@ -2,7 +2,6 @@ package fr.free.nrw.commons.category;
import android.app.Activity;
import android.content.ContentProviderClient;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.database.Cursor;
@ -21,11 +20,11 @@ import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;
import android.widget.EditText;
import android.widget.ListView;
@ -39,7 +38,6 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -52,8 +50,8 @@ import fr.free.nrw.commons.upload.MwVolleyApi;
* Displays the category suggestion and selection screen. Category search is initiated here.
*/
public class CategorizationFragment extends Fragment {
public static interface OnCategoriesSaveHandler {
public void onCategoriesSave(ArrayList<String> categories);
public interface OnCategoriesSaveHandler {
void onCategoriesSave(ArrayList<String> categories);
}
ListView categoriesList;
@ -69,14 +67,14 @@ public class CategorizationFragment extends Fragment {
protected HashMap<String, ArrayList<String>> categoriesCache;
private ArrayList<String> selectedCategories = new ArrayList<String>();
private ArrayList<String> selectedCategories = new ArrayList<>();
// LHS guarantees ordered insertions, allowing for prioritized method A results
private final Set<String> results = new LinkedHashSet<String>();
private final Set<String> results = new LinkedHashSet<>();
PrefixUpdater prefixUpdaterSub;
MethodAUpdater methodAUpdaterSub;
private final ArrayList<String> titleCatItems = new ArrayList<String>();
private final ArrayList<String> titleCatItems = new ArrayList<>();
final CountDownLatch mergeLatch = new CountDownLatch(1);
private ContentProviderClient client;
@ -164,7 +162,7 @@ public class CategorizationFragment extends Fragment {
* @return a list containing recent categories
*/
protected ArrayList<String> recentCatQuery() {
ArrayList<String> items = new ArrayList<String>();
ArrayList<String> items = new ArrayList<>();
try {
Cursor cursor = client.query(
@ -192,16 +190,16 @@ public class CategorizationFragment extends Fragment {
*/
protected ArrayList<String> mergeItems() {
Set<String> mergedItems = new LinkedHashSet<String>();
Set<String> mergedItems = new LinkedHashSet<>();
Log.d(TAG, "Calling APIs for GPS cats, title cats and recent cats...");
List<String> gpsItems = new ArrayList<String>();
List<String> gpsItems = new ArrayList<>();
if (MwVolleyApi.GpsCatExists.getGpsCatExists()) {
gpsItems.addAll(MwVolleyApi.getGpsCat());
}
List<String> titleItems = new ArrayList<String>(titleCatQuery());
List<String> recentItems = new ArrayList<String>(recentCatQuery());
List<String> titleItems = new ArrayList<>(titleCatQuery());
List<String> recentItems = new ArrayList<>(recentCatQuery());
//Await results of titleItems, which is likely to come in last
try {
@ -219,7 +217,7 @@ public class CategorizationFragment extends Fragment {
Log.d(TAG, "Adding recent items: " + recentItems);
//Needs to be an ArrayList and not a List unless we want to modify a big portion of preexisting code
ArrayList<String> mergedItemsList = new ArrayList<String>(mergedItems);
ArrayList<String> mergedItemsList = new ArrayList<>(mergedItems);
Log.d(TAG, "Merged item list: " + mergedItemsList);
return mergedItemsList;
@ -233,8 +231,8 @@ public class CategorizationFragment extends Fragment {
protected void setCatsAfterAsync(ArrayList<String> categories, String filter) {
if (getActivity() != null) {
ArrayList<CategoryItem> items = new ArrayList<CategoryItem>();
HashSet<String> existingKeys = new HashSet<String>();
ArrayList<CategoryItem> items = new ArrayList<>();
HashSet<String> existingKeys = new HashSet<>();
for (CategoryItem item : categoriesAdapter.getItems()) {
if (item.selected) {
items.add(item);
@ -282,7 +280,7 @@ public class CategorizationFragment extends Fragment {
prefixUpdaterSub = new PrefixUpdater(this) {
@Override
protected ArrayList<String> doInBackground(Void... voids) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> result = new ArrayList<>();
try {
result = super.doInBackground();
latch.await();
@ -302,7 +300,7 @@ public class CategorizationFragment extends Fragment {
Log.d(TAG, "Prefix result: " + result);
String filter = categoriesFilter.getText().toString();
ArrayList<String> resultsList = new ArrayList<String>(results);
ArrayList<String> resultsList = new ArrayList<>(results);
categoriesCache.put(filter, resultsList);
Log.d(TAG, "Final results List: " + resultsList);
@ -424,8 +422,8 @@ public class CategorizationFragment extends Fragment {
ArrayList<CategoryItem> items;
if(savedInstanceState == null) {
items = new ArrayList<CategoryItem>();
categoriesCache = new HashMap<String, ArrayList<String>>();
items = new ArrayList<>();
categoriesCache = new HashMap<>();
} else {
items = savedInstanceState.getParcelableArrayList("currentCategories");
categoriesCache = (HashMap<String, ArrayList<String>>) savedInstanceState.getSerializable("categoriesCache");
@ -469,7 +467,7 @@ public class CategorizationFragment extends Fragment {
}
@Override
public void onCreateOptionsMenu(Menu menu, android.view.MenuInflater inflater) {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.fragment_categorization, menu);
}

View file

@ -1,7 +1,6 @@
package fr.free.nrw.commons.category;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@ -83,7 +82,7 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
//otherwise if user has typed something in that isn't in cache, search API for matching categories
MWApi api = CommonsApplication.createMWApi();
ApiResult result;
ArrayList<String> categories = new ArrayList<String>();
ArrayList<String> categories = new ArrayList<>();
//URL https://commons.wikimedia.org/w/api.php?action=query&format=xml&list=search&srwhat=text&srenablerewrites=1&srnamespace=14&srlimit=10&srsearch=
try {
@ -110,7 +109,7 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
}
Log.d(TAG, "Found categories from Method A search, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<String>(filterYears(categories));
ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
return filteredItems;
}
}

View file

@ -82,17 +82,17 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
protected ArrayList<String> doInBackground(Void... voids) {
//If user hasn't typed anything in yet, get GPS and recent items
if(TextUtils.isEmpty(filter)) {
ArrayList<String> mergedItems = new ArrayList<String>(catFragment.mergeItems());
ArrayList<String> mergedItems = new ArrayList<>(catFragment.mergeItems());
Log.d(TAG, "Merged items, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<String>(filterYears(mergedItems));
ArrayList<String> filteredItems = new ArrayList<>(filterYears(mergedItems));
return filteredItems;
}
//if user types in something that is in cache, return cached category
if(catFragment.categoriesCache.containsKey(filter)) {
ArrayList<String> cachedItems = new ArrayList<String>(catFragment.categoriesCache.get(filter));
ArrayList<String> cachedItems = new ArrayList<>(catFragment.categoriesCache.get(filter));
Log.d(TAG, "Found cache items, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<String>(filterYears(cachedItems));
ArrayList<String> filteredItems = new ArrayList<>(filterYears(cachedItems));
return filteredItems;
}
@ -100,7 +100,7 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
//URL: https://commons.wikimedia.org/w/api.php?action=query&list=allcategories&acprefix=filter&aclimit=25
MWApi api = CommonsApplication.createMWApi();
ApiResult result;
ArrayList<String> categories = new ArrayList<String>();
ArrayList<String> categories = new ArrayList<>();
try {
result = api.action("query")
.param("list", "allcategories")
@ -120,7 +120,7 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
}
Log.d(TAG, "Found categories from Prefix search, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<String>(filterYears(categories));
ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
return filteredItems;
}
}

View file

@ -165,7 +165,7 @@ public class Contribution extends Media {
public void save() {
try {
if(contentUri == null) {
contentUri = client.insert(fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI, this.toContentValues());
contentUri = client.insert(ContributionsContentProvider.BASE_URI, this.toContentValues());
} else {
client.update(contentUri, toContentValues(), null, null);
}
@ -234,7 +234,7 @@ public class Contribution extends Media {
//Check that cursor has a value to avoid CursorIndexOutOfBoundsException
if (cursor.getCount() > 0) {
c.contentUri = fr.free.nrw.commons.contributions.ContributionsContentProvider.uriForId(cursor.getInt(0));
c.contentUri = ContributionsContentProvider.uriForId(cursor.getInt(0));
c.filename = cursor.getString(1);
c.localUri = TextUtils.isEmpty(cursor.getString(2)) ? null : Uri.parse(cursor.getString(2));
c.imageUrl = cursor.getString(3);

View file

@ -76,12 +76,12 @@ public class ContributionController {
Uri imageData = data.getData();
shareIntent.setType(activity.getContentResolver().getType(imageData));
shareIntent.putExtra(Intent.EXTRA_STREAM, imageData);
shareIntent.putExtra(UploadService.EXTRA_SOURCE, fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY);
shareIntent.putExtra(UploadService.EXTRA_SOURCE, Contribution.SOURCE_GALLERY);
break;
case SELECT_FROM_CAMERA:
shareIntent.setType("image/jpeg"); //FIXME: Find out appropriate mime type
shareIntent.putExtra(Intent.EXTRA_STREAM, lastGeneratedCaptureURI);
shareIntent.putExtra(UploadService.EXTRA_SOURCE, fr.free.nrw.commons.contributions.Contribution.SOURCE_CAMERA);
shareIntent.putExtra(UploadService.EXTRA_SOURCE, Contribution.SOURCE_CAMERA);
break;
}
Log.i("Image", "Image selected");

View file

@ -45,7 +45,7 @@ public class ContributionsActivity
private MediaDetailPagerFragment mediaDetails;
private UploadService uploadService;
private boolean isUploadServiceConnected;
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<DataSetObserver>();
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
private String CONTRIBUTION_SELECTION = "";
/*
This sorts in the following order:

View file

@ -11,6 +11,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
@ -51,7 +52,7 @@ class ContributionsListAdapter extends CursorAdapter {
mwImageView.setMedia(contribution, ((CommonsApplication) activity.getApplicationContext()).getImageLoader());
// FIXME: For transparent images
} else {
com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(actualUrl, views.imageView, contributionDisplayOptions, new SimpleImageLoadingListener() {
ImageLoader.getInstance().displayImage(actualUrl, views.imageView, contributionDisplayOptions, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

View file

@ -92,7 +92,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
ArrayList<ApiResult> uploads = result.getNodes("/api/query/logevents/item");
Log.d("Commons", uploads.size() + " results!");
ArrayList<ContentValues> imageValues = new ArrayList<ContentValues>();
ArrayList<ContentValues> imageValues = new ArrayList<>();
for(ApiResult image: uploads) {
String filename = image.getString("@title");
if(fileExists(contentProviderClient, filename)) {

View file

@ -32,7 +32,7 @@ public class CategoryImagesLoader extends AsyncTaskLoader<List<Media>>{
@Override
public List<Media> loadInBackground() {
ArrayList<Media> mediaList = new ArrayList<Media>();
ArrayList<Media> mediaList = new ArrayList<>();
ApiResult result;
try {
result = app.getApi().action("query")

View file

@ -39,7 +39,7 @@ public class MediaDetailFragment extends Fragment {
private boolean editable;
private DisplayImageOptions displayOptions;
private fr.free.nrw.commons.media.MediaDetailPagerFragment.MediaDetailProvider detailProvider;
private MediaDetailPagerFragment.MediaDetailProvider detailProvider;
private int index;
public static MediaDetailFragment forMedia(int index) {
@ -64,7 +64,7 @@ public class MediaDetailFragment extends Fragment {
//private EditText title;
private ProgressBar loadingProgress;
private ImageView loadingFailed;
private fr.free.nrw.commons.media.MediaDetailSpacer spacer;
private MediaDetailSpacer spacer;
private int initialListTop = 0;
private TextView title;
@ -97,7 +97,7 @@ public class MediaDetailFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
detailProvider = (fr.free.nrw.commons.media.MediaDetailPagerFragment.MediaDetailProvider)getActivity();
detailProvider = (MediaDetailPagerFragment.MediaDetailProvider)getActivity();
if(savedInstanceState != null) {
editable = savedInstanceState.getBoolean("editable");
@ -108,7 +108,7 @@ public class MediaDetailFragment extends Fragment {
index = getArguments().getInt("index");
initialListTop = 0;
}
categoryNames = new ArrayList<String>();
categoryNames = new ArrayList<>();
categoryNames.add(getString(R.string.detail_panel_cats_loading));
final View view = inflater.inflate(R.layout.fragment_media_detail, container, false);
@ -119,7 +119,7 @@ public class MediaDetailFragment extends Fragment {
scrollView = (ScrollView) view.findViewById(R.id.mediaDetailScrollView);
// Detail consists of a list view with main pane in header view, plus category list.
spacer = (fr.free.nrw.commons.media.MediaDetailSpacer) view.findViewById(R.id.mediaDetailSpacer);
spacer = (MediaDetailSpacer) view.findViewById(R.id.mediaDetailSpacer);
title = (TextView) view.findViewById(R.id.mediaDetailTitle);
desc = (TextView) view.findViewById(R.id.mediaDetailDesc);
license = (TextView) view.findViewById(R.id.mediaDetailLicense);

View file

@ -46,11 +46,11 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
}
public interface MediaDetailProvider {
public Media getMediaAtPosition(int i);
public int getTotalMediaCount();
public void notifyDatasetChanged();
public void registerDataSetObserver(DataSetObserver observer);
public void unregisterDataSetObserver(DataSetObserver observer);
Media getMediaAtPosition(int i);
int getTotalMediaCount();
void notifyDatasetChanged();
void registerDataSetObserver(DataSetObserver observer);
void unregisterDataSetObserver(DataSetObserver observer);
}
//FragmentStatePagerAdapter allows user to swipe across collection of images (no. of images undetermined)
@ -71,7 +71,7 @@ public class MediaDetailPagerFragment extends Fragment implements ViewPager.OnPa
}
}, 5);
}
return fr.free.nrw.commons.media.MediaDetailFragment.forMedia(i, editable);
return MediaDetailFragment.forMedia(i, editable);
}
@Override

View file

@ -21,7 +21,7 @@ public class ModifierSequence {
public ModifierSequence(Uri mediaUri) {
this.mediaUri = mediaUri;
modifiers = new ArrayList<PageModifier>();
modifiers = new ArrayList<>();
}
public ModifierSequence(Uri mediaUri, JSONObject data) {

View file

@ -21,7 +21,7 @@ public class NearbyPlaces {
}
else {
try {
places = new ArrayList<Place>();
places = new ArrayList<>();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

View file

@ -24,7 +24,7 @@ import fr.free.nrw.commons.contributions.ContributionsActivity;
*/
public class ExistingFileAsync extends AsyncTask<Void, Void, Boolean> {
private static final String TAG = fr.free.nrw.commons.upload.ExistingFileAsync.class.getName();
private static final String TAG = ExistingFileAsync.class.getName();
private String fileSHA1;
private Context context;

View file

@ -249,7 +249,7 @@ public class MultipleShareActivity
if(intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
if(photosList == null) {
photosList = new ArrayList<Contribution>();
photosList = new ArrayList<>();
ArrayList<Uri> urisList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
for(int i=0; i < urisList.size(); i++) {
Contribution up = new Contribution();

View file

@ -11,6 +11,7 @@ import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
@ -36,7 +37,7 @@ import fr.free.nrw.commons.media.MediaDetailPagerFragment;
public class MultipleUploadListFragment extends Fragment {
public interface OnMultipleUploadInitiatedHandler {
public void OnMultipleUploadInitiated();
void OnMultipleUploadInitiated();
}
private GridView photosGrid;
@ -200,7 +201,7 @@ public class MultipleUploadListFragment extends Fragment {
}
@Override
public void onCreateOptionsMenu(Menu menu, android.view.MenuInflater inflater) {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
inflater.inflate(R.menu.fragment_multiple_upload_list, menu);

View file

@ -42,7 +42,7 @@ public class MwVolleyApi {
public MwVolleyApi(Context context) {
this.context = context;
categorySet = new HashSet<String>();
categorySet = new HashSet<>();
}
public static List<String> getGpsCat() {
@ -50,7 +50,7 @@ public class MwVolleyApi {
}
public static void setGpsCat(List cachedList) {
categoryList = new ArrayList<String>();
categoryList = new ArrayList<>();
categoryList.addAll(cachedList);
Log.d(TAG, "Setting GPS cats from cache: " + categoryList.toString());
}
@ -236,7 +236,7 @@ public class MwVolleyApi {
}
}
categoryList = new ArrayList<String>(categorySet);
categoryList = new ArrayList<>(categorySet);
builder.replace(builder.length() - 1, builder.length(), "");
return builder.toString();
}

View file

@ -21,10 +21,8 @@ import android.widget.Toast;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

222
script/style/checkstyle.xml Normal file
View file

@ -0,0 +1,222 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<!--
Modified from https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml.
Modifications are:
- doubled each value in Indentation
Checkstyle configuration that checks the Google coding conventions from Google Java Style
that can be found at https://google.github.io/styleguide/javaguide.html.
Checkstyle is very configurable. Be sure to read the documentation at
http://checkstyle.sf.net (or in your downloaded distribution).
To completely disable a check, just comment it out or delete it from the file.
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
-->
<module name = "Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format" value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message" value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true"/>
<property name="allowByTailComment" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="LineLength">
<property name="max" value="100"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="AvoidStarImport"/>
<module name="OneTopLevelClass"/>
<module name="NoLineWrap"/>
<module name="EmptyBlock">
<property name="option" value="TEXT"/>
<property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
</module>
<module name="NeedBraces"/>
<module name="LeftCurly">
<property name="maxLineLength" value="100"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlySame"/>
<property name="tokens" value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_DO"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlyAlone"/>
<property name="option" value="alone"/>
<property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT, INSTANCE_INIT"/>
</module>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
<message key="ws.notFollowed"
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
<message key="ws.notPreceded"
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
</module>
<module name="OneStatementPerLine"/>
<module name="MultipleVariableDeclarations"/>
<module name="ArrayTypeStyle"/>
<module name="MissingSwitchDefault"/>
<module name="FallThrough"/>
<module name="UpperEll"/>
<module name="ModifierOrder"/>
<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapDot"/>
<property name="tokens" value="DOT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapComma"/>
<property name="tokens" value="COMMA"/>
<property name="option" value="EOL"/>
</module>
<module name="PackageName">
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
<message key="name.invalidPattern"
value="Package name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="TypeName">
<message key="name.invalidPattern"
value="Type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MemberName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="CatchParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LocalVariableName">
<property name="tokens" value="VARIABLE_DEF"/>
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ClassTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Class type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MethodTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Method type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="InterfaceTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="NoFinalizer"/>
<module name="GenericWhitespace">
<message key="ws.followed"
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
<message key="ws.preceded"
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
<message key="ws.illegalFollow"
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
<message key="ws.notPreceded"
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
</module>
<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="8"/>
<property name="lineWrappingIndentation" value="8"/>
<property name="arrayInitIndent" value="4"/>
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="1"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/>
<module name="CustomImportOrder">
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="true"/>
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
</module>
<module name="MethodParamPad"/>
<module name="ParenPad"/>
<module name="OperatorWrap">
<property name="option" value="NL"/>
<property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
</module>
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationMostCases"/>
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
</module>
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationVariables"/>
<property name="tokens" value="VARIABLE_DEF"/>
<property name="allowSamelineMultipleAnnotations" value="true"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="JavadocTagContinuationIndentation"/>
<module name="SummaryJavadoc">
<property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
</module>
<module name="JavadocParagraph"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingThrowsTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
</module>
<module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
<message key="name.invalidPattern"
value="Method name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="SingleLineJavadoc">
<property name="ignoreInlineTags" value="false"/>
</module>
<module name="EmptyCatchBlock">
<property name="exceptionVariableName" value="expected"/>
</module>
<module name="CommentsIndentation"/>
</module>
</module>