Apply a bunch of Android Studio fixes

This commit is contained in:
Daniel Martí 2015-04-07 11:43:07 +02:00
parent a67fdfeb89
commit e3175530ed
37 changed files with 95 additions and 95 deletions

View File

@ -1,7 +1,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<fragment
android:id="@+id/fragment_app_list"

View File

@ -1,12 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:paddingTop="38.8dp"> <!-- 69px * 96dpi / 160dpi -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="38.8dp"> <!-- 69px * 96dpi / 160dpi -->
<ImageView
android:layout_width="wrap_content"

View File

@ -1,4 +1,4 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<resources>
<style name="AppBaseThemeDark" parent="Theme.AppCompat">
<!-- API 11 theme customizations go here -->

View File

@ -150,7 +150,7 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A
class ApkListAdapter extends ArrayAdapter<Apk> {
private LayoutInflater mInflater = (LayoutInflater) mctx.getSystemService(
private final LayoutInflater mInflater = (LayoutInflater) mctx.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
public ApkListAdapter(Context context, App app) {
@ -331,8 +331,8 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A
*/
private static class ConfigurationChangeHelper {
public ApkDownloader downloader;
public App app;
public final ApkDownloader downloader;
public final App app;
public ConfigurationChangeHelper(ApkDownloader downloader, App app) {
this.downloader = downloader;
@ -941,7 +941,7 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A
}
}
Installer.InstallerCallback myInstallerCallback = new Installer.InstallerCallback() {
final Installer.InstallerCallback myInstallerCallback = new Installer.InstallerCallback() {
@Override
public void onSuccess(final int operation) {

View File

@ -18,11 +18,11 @@ public class CompatibilityChecker extends Compatibility {
private static final String TAG = "fdroid.Compatibility";
private Context context;
private Set<String> features;
private String[] cpuAbis;
private String cpuAbisDesc;
private boolean ignoreTouchscreen;
private final Context context;
private final Set<String> features;
private final String[] cpuAbis;
private final String cpuAbisDesc;
private final boolean ignoreTouchscreen;
public CompatibilityChecker(Context ctx) {

View File

@ -191,7 +191,7 @@ public class FDroid extends ActionBarActivity {
return true;
case R.id.action_about:
View view = null;
View view;
if (Build.VERSION.SDK_INT >= 11) {
LayoutInflater li = LayoutInflater.from(this);
view = li.inflate(R.layout.about, null);
@ -211,7 +211,7 @@ public class FDroid extends ActionBarActivity {
} catch (Exception e) {
}
Builder p = null;
Builder p;
if (Build.VERSION.SDK_INT >= 11) {
p = new AlertDialog.Builder(this).setView(view);
} else {

View File

@ -65,11 +65,11 @@ public class FDroidApp extends Application {
public static String ipAddressString = null;
public static String ssid = "";
public static String bssid = "";
public static Repo repo = new Repo();
public static final Repo repo = new Repo();
public static Set<String> selectedApps = null; // init in SelectLocalAppsFragment
// Leaving the fully qualified class name here to help clarify the difference between spongy/bouncy castle.
private static org.spongycastle.jce.provider.BouncyCastleProvider spongyCastleProvider;
private static final org.spongycastle.jce.provider.BouncyCastleProvider spongyCastleProvider;
private static Messenger localRepoServiceMessenger = null;
private static boolean localRepoServiceIsBound = false;
@ -276,7 +276,7 @@ public class FDroidApp extends Application {
}
}
private static ServiceConnection serviceConnection = new ServiceConnection() {
private static final ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
localRepoServiceMessenger = new Messenger(service);

View File

@ -98,7 +98,7 @@ public class Hasher {
}
public static String hex(Certificate cert) {
byte[] encoded = null;
byte[] encoded;
try {
encoded = cert.getEncoded();
} catch(CertificateEncodingException e) {

View File

@ -78,14 +78,14 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
private boolean compactLayout = DEFAULT_COMPACT_LAYOUT;
private boolean filterAppsRequiringRoot = DEFAULT_ROOTED;
private Map<String,Boolean> initialized = new HashMap<>();
private final Map<String,Boolean> initialized = new HashMap<>();
private List<ChangeListener> compactLayoutListeners = new ArrayList<>();
private List<ChangeListener> filterAppsRequiringRootListeners = new ArrayList<>();
private List<ChangeListener> updateHistoryListeners = new ArrayList<>();
private List<ChangeListener> localRepoBonjourListeners = new ArrayList<>();
private List<ChangeListener> localRepoNameListeners = new ArrayList<>();
private List<ChangeListener> localRepoHttpsListeners = new ArrayList<>();
private final List<ChangeListener> compactLayoutListeners = new ArrayList<>();
private final List<ChangeListener> filterAppsRequiringRootListeners = new ArrayList<>();
private final List<ChangeListener> updateHistoryListeners = new ArrayList<>();
private final List<ChangeListener> localRepoBonjourListeners = new ArrayList<>();
private final List<ChangeListener> localRepoNameListeners = new ArrayList<>();
private final List<ChangeListener> localRepoHttpsListeners = new ArrayList<>();
private boolean isInitialized(String key) {
return initialized.containsKey(key) && initialized.get(key);

View File

@ -23,7 +23,7 @@ public interface ProgressListener {
// that function can initialize "total" and progressively
// update "progress"
public int progress;
public int total;
public final int total;
public Event(String type) {
this(type, NO_VALUE, NO_VALUE, null);

View File

@ -20,8 +20,8 @@ import com.google.zxing.encode.QRCodeEncoder;
public class QrGenAsyncTask extends AsyncTask<String, Void, Void> {
private static final String TAG = "fdroid.QrGenAsyncTask";
private Activity activity;
private int viewId;
private final Activity activity;
private final int viewId;
private Bitmap qrBitmap;
public QrGenAsyncTask(Activity activity, int viewId) {
@ -63,7 +63,7 @@ public class QrGenAsyncTask extends AsyncTask<String, Void, Void> {
} catch (WriterException e) {
Log.e(TAG, e.getMessage());
}
return (Void) null;
return null;
}
@Override

View File

@ -36,14 +36,14 @@ import java.util.List;
public class RepoXMLHandler extends DefaultHandler {
// The repo we're processing.
private Repo repo;
private final Repo repo;
private List<App> apps = new ArrayList<>();
private List<Apk> apksList = new ArrayList<>();
private final List<App> apps = new ArrayList<>();
private final List<Apk> apksList = new ArrayList<>();
private App curapp = null;
private Apk curapk = null;
private StringBuilder curchars = new StringBuilder();
private final StringBuilder curchars = new StringBuilder();
// After processing the XML, these will be -1 if the index didn't specify
// them - otherwise it will be the value specified.
@ -61,7 +61,7 @@ public class RepoXMLHandler extends DefaultHandler {
private String hashType;
private int progressCounter = 0;
private ProgressListener progressListener;
private final ProgressListener progressListener;
private int totalAppCount;

View File

@ -56,7 +56,6 @@ import org.fdroid.fdroid.net.Downloader;
import org.fdroid.fdroid.updater.RepoUpdater;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

View File

@ -143,8 +143,8 @@ public final class Utils {
}
public static boolean copy(File inFile, File outFile) {
InputStream input = null;
OutputStream output = null;
InputStream input;
OutputStream output;
try {
input = new FileInputStream(inFile);
output = new FileOutputStream(outFile);
@ -358,7 +358,7 @@ public final class Utils {
}
public static class CommaSeparatedList implements Iterable<String> {
private String value;
private final String value;
private CommaSeparatedList(String list) {
value = list;

View File

@ -18,8 +18,8 @@ public class TabManager {
public static final int INDEX_INSTALLED = 1;
public static final int INDEX_CAN_UPDATE = 2;
private ViewPager pager;
private FDroid parent;
private final ViewPager pager;
private final FDroid parent;
private final ActionBar actionBar;
private Spinner actionBarSpinner = null;

View File

@ -278,8 +278,9 @@ public class App extends ValueObject implements Comparable<App> {
if (features != null && features.length > 0) {
List<String> featureNames = new ArrayList<>(features.length);
for (int i = 0; i < features.length; i++)
featureNames.add(features[i].name);
for (FeatureInfo feature : features) {
featureNames.add(feature.name);
}
apk.features = Utils.CommaSeparatedList.make(featureNames);
}

View File

@ -581,7 +581,7 @@ public class AppProvider extends FDroidProvider {
} else {
selection.append(" AND ");
}
selection.append(column + " like ?");
selection.append(column).append(" like ?");
selectionKeywords[iKeyword] = keyword;
iKeyword++;
}

View File

@ -101,7 +101,7 @@ public class DBHelper extends SQLiteOpenHelper {
private static final int DB_VERSION = 47;
private Context context;
private final Context context;
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DB_VERSION);

View File

@ -24,10 +24,10 @@ public class InstalledAppCacheUpdater {
private static final String TAG = "fdroid.InstalledAppCacheUpdater";
private Context context;
private final Context context;
private List<PackageInfo> toInsert = new ArrayList<>();
private List<String> toDelete = new ArrayList<>();
private final List<PackageInfo> toInsert = new ArrayList<>();
private final List<String> toDelete = new ArrayList<>();
protected InstalledAppCacheUpdater(Context context) {
this.context = context;

View File

@ -5,8 +5,8 @@ import java.util.List;
abstract class QueryBuilder {
private List<String> fields = new ArrayList<>();
private StringBuilder tables = new StringBuilder(getRequiredTables());
private final List<String> fields = new ArrayList<>();
private final StringBuilder tables = new StringBuilder(getRequiredTables());
private String selection = null;
private String orderBy = null;

View File

@ -28,8 +28,8 @@ import android.os.AsyncTask;
public class CheckRootAsyncTask extends AsyncTask<Void, Void, Boolean> {
ProgressDialog mDialog;
Context mContext;
CheckRootCallback mCallback;
final Context mContext;
final CheckRootCallback mCallback;
public interface CheckRootCallback {
public void onRootCheck(boolean rootGranted);

View File

@ -36,9 +36,9 @@ import android.util.Log;
* instantiate a working Installer based on F-Droids granted permissions.
*/
abstract public class Installer {
protected Context mContext;
protected PackageManager mPm;
protected InstallerCallback mCallback;
protected final Context mContext;
protected final PackageManager mPm;
protected final InstallerCallback mCallback;
public static final String TAG = "fdroid.Installer";

View File

@ -72,7 +72,7 @@ public class LocalRepoManager {
"swap-tick-not-done.png"
};
private Map<String, App> apps = new HashMap<>();
private final Map<String, App> apps = new HashMap<>();
public final SanitizedFile xmlIndex;
private SanitizedFile xmlIndexJar = null;

View File

@ -45,7 +45,7 @@ public class LocalRepoService extends Service {
private Notification notification;
// Unique Identification Number for the Notification.
// We use it on Notification start, and to cancel it.
private int NOTIFICATION = R.string.local_repo_running;
private final int NOTIFICATION = R.string.local_repo_running;
private Handler webServerThreadHandler = null;
private LocalHTTPD localHttpd;
@ -90,7 +90,7 @@ public class LocalRepoService extends Service {
}
}
private BroadcastReceiver onWifiChange = new BroadcastReceiver() {
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent i) {
stopNetworkServices();
@ -109,7 +109,7 @@ public class LocalRepoService extends Service {
}
};
private ChangeListener localRepoHttpsChangeListener = new ChangeListener() {
private final ChangeListener localRepoHttpsChangeListener = new ChangeListener() {
@Override
public void onPreferenceChange() {
Log.i(TAG, "onPreferenceChange");

View File

@ -59,9 +59,9 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener {
*/
public static final String EVENT_DATA_ERROR_TYPE = "apkDownloadErrorType";
private Apk curApk;
private String repoAddress;
private SanitizedFile localFile;
private final Apk curApk;
private final String repoAddress;
private final SanitizedFile localFile;
private ProgressListener listener;
private AsyncDownloadWrapper dlWrapper = null;
@ -69,7 +69,7 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener {
private int totalSize = 0;
private boolean isComplete = false;
private long id = ++downloadIdCounter;
private final long id = ++downloadIdCounter;
public void setProgressListener(ProgressListener listener) {
this.listener = listener;

View File

@ -26,8 +26,8 @@ public class AsyncDownloadWrapper extends Handler {
private static final int MSG_ERROR = 4;
private static final String MSG_DATA = "data";
private Downloader downloader;
private Listener listener;
private final Downloader downloader;
private final Listener listener;
private DownloadThread downloadThread = null;
/**

View File

@ -24,7 +24,7 @@ public abstract class Downloader {
private ProgressListener progressListener = null;
private Bundle eventData = null;
private File outputFile;
private final File outputFile;
protected URL sourceUrl;
protected String cacheTag = null;

View File

@ -40,15 +40,19 @@ public class LocalHTTPD extends NanoHTTPD {
StringTokenizer st = new StringTokenizer(uri, "/ ", true);
while (st.hasMoreTokens()) {
String tok = st.nextToken();
if (tok.equals("/"))
switch (tok) {
case "/":
newUri += "/";
else if (tok.equals(" "))
break;
case " ":
newUri += "%20";
else {
break;
default:
try {
newUri += URLEncoder.encode(tok, "UTF-8");
} catch (UnsupportedEncodingException ignored) {
}
break;
}
}
return newUri;
@ -147,8 +151,7 @@ public class LocalHTTPD extends NanoHTTPD {
}
}
Response response = null;
response = serveFile(uri, headers, f, getMimeTypeForFile(uri));
Response response = serveFile(uri, headers, f, getMimeTypeForFile(uri));
return response != null ? response :
createResponse(Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
"Error 404, file not found.");

View File

@ -127,9 +127,9 @@ public class MDnsHelper implements ServiceListener {
}
public static class RepoScanListAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mLayoutInflater;
private List<DiscoveredRepo> mEntries = new ArrayList<>();
private final Context mContext;
private final LayoutInflater mLayoutInflater;
private final List<DiscoveredRepo> mEntries = new ArrayList<>();
public RepoScanListAdapter(Context context) {
mContext = context;

View File

@ -54,8 +54,8 @@ public class LocalRepoActivity extends ActionBarActivity {
private Timer stopTimer;
private int SET_IP_ADDRESS = 7345;
private int UPDATE_REPO = 7346;
private final int SET_IP_ADDRESS = 7345;
private final int UPDATE_REPO = 7346;
/** Called when the activity is first created. */
@Override
@ -108,14 +108,14 @@ public class LocalRepoActivity extends ActionBarActivity {
LocalBroadcastManager.getInstance(this).unregisterReceiver(onLocalRepoChange);
}
private BroadcastReceiver onWifiChange = new BroadcastReceiver() {
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent i) {
resetNetworkInfo();
}
};
private BroadcastReceiver onLocalRepoChange = new BroadcastReceiver() {
private final BroadcastReceiver onLocalRepoChange = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent i) {
String state = i.getStringExtra(LocalRepoService.STATE);
@ -185,7 +185,7 @@ public class LocalRepoActivity extends ActionBarActivity {
setUIFromWifi();
} else if (requestCode == UPDATE_REPO) {
setUIFromWifi();
new UpdateAsyncTask(this, FDroidApp.selectedApps.toArray(new String[0]))
new UpdateAsyncTask(this, FDroidApp.selectedApps.toArray(new String[FDroidApp.selectedApps.size()]))
.execute();
}
}
@ -277,9 +277,9 @@ public class LocalRepoActivity extends ActionBarActivity {
class UpdateAsyncTask extends AsyncTask<Void, String, Void> {
private static final String TAG = "fdroid.LocalRepoActivity.UpdateAsyncTask";
private ProgressDialog progressDialog;
private String[] selectedApps;
private Uri sharingUri;
private final ProgressDialog progressDialog;
private final String[] selectedApps;
private final Uri sharingUri;
public UpdateAsyncTask(Context c, String[] apps) {
selectedApps = apps;

View File

@ -52,7 +52,7 @@ public class QrWizardDownloadActivity extends ActionBarActivity {
LocalBroadcastManager.getInstance(this).unregisterReceiver(onWifiChange);
}
private BroadcastReceiver onWifiChange = new BroadcastReceiver() {
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent i) {
Log.i(TAG, "onWifiChange.onReceive()");

View File

@ -63,7 +63,7 @@ public class QrWizardWifiNetworkActivity extends ActionBarActivity {
LocalBroadcastManager.getInstance(this).unregisterReceiver(onWifiChange);
}
private BroadcastReceiver onWifiChange = new BroadcastReceiver() {
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent i) {
Log.i(TAG, "onWifiChange.onReceive()");

View File

@ -58,7 +58,7 @@ public class SelectLocalAppsActivity extends ActionBarActivity {
return super.onOptionsItemSelected(item);
}
public ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
public final ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {

View File

@ -71,7 +71,7 @@ public class AvailableAppsFragment extends AppListFragment implements
private class CategoryObserver extends ContentObserver {
private ArrayAdapter<String> adapter;
private final ArrayAdapter<String> adapter;
public CategoryObserver(ArrayAdapter<String> adapter) {
super(null);

View File

@ -293,7 +293,7 @@ public class RepoDetailsFragment extends Fragment {
@TargetApi(16)
private void prepareNfcMenuItems(Menu menu) {
boolean needsEnableNfcMenuItem = false;
boolean needsEnableNfcMenuItem;
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
if (nfcAdapter == null) {
return;

View File

@ -24,7 +24,7 @@ import org.fdroid.fdroid.net.WifiStateChangeService;
public class JoinWifiFragment extends Fragment {
private BroadcastReceiver onWifiChange = new BroadcastReceiver() {
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
refreshWifiState();

View File

@ -43,7 +43,7 @@ public class WifiQrFragment extends Fragment {
private static final String TAG = "fdroid.WifiQrFragment";
private BroadcastReceiver onWifiChange = new BroadcastReceiver() {
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent i) {
setUIFromWifi();