Browse Source

Add null annotations for fragments

master
Anthony Restaino 9 years ago
parent
commit
970ffbaca8
  1. 5
      app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java
  2. 45
      app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java
  3. 16
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  4. 5
      app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java
  5. 7
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  6. 7
      app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java
  7. 45
      app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

5
app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java

@ -8,6 +8,7 @@ import android.content.DialogInterface; @@ -8,6 +8,7 @@ import android.content.DialogInterface;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import java.util.Arrays;
@ -88,7 +89,7 @@ public class AdvancedSettingsFragment extends LightningPreferenceFragment implem @@ -88,7 +89,7 @@ public class AdvancedSettingsFragment extends LightningPreferenceFragment implem
}
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
switch (preference.getKey()) {
case SETTINGS_RENDERINGMODE:
renderPicker();
@ -105,7 +106,7 @@ public class AdvancedSettingsFragment extends LightningPreferenceFragment implem @@ -105,7 +106,7 @@ public class AdvancedSettingsFragment extends LightningPreferenceFragment implem
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
// switch preferences
switch (preference.getKey()) {
case SETTINGS_NEWWINDOW:

45
app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java

@ -12,6 +12,8 @@ import android.os.Bundle; @@ -12,6 +12,8 @@ import android.os.Bundle;
import android.os.Environment;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import java.io.File;
@ -27,8 +29,11 @@ import acr.browser.lightning.app.BrowserApp; @@ -27,8 +29,11 @@ import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.database.BookmarkLocalSync;
import acr.browser.lightning.database.BookmarkManager;
import acr.browser.lightning.database.HistoryItem;
import com.anthonycr.grant.PermissionsManager;
import com.anthonycr.grant.PermissionsResultAction;
import acr.browser.lightning.utils.Preconditions;
import acr.browser.lightning.utils.Utils;
public class BookmarkSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener {
@ -37,12 +42,13 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -37,12 +42,13 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
private static final String SETTINGS_IMPORT = "import_bookmark";
private static final String SETTINGS_IMPORT_BROWSER = "import_browser";
private Activity mActivity;
@Inject
BookmarkManager mBookmarkManager;
@Nullable private Activity mActivity;
@Inject BookmarkManager mBookmarkManager;
private File[] mFileList;
private String[] mFileNameList;
private BookmarkLocalSync mSync;
@Nullable private BookmarkLocalSync mSync;
private static final String[] REQUIRED_PERMISSIONS = new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
@ -52,7 +58,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -52,7 +58,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
private class ImportBookmarksTask extends AsyncTask<Void, Void, Integer> {
private final WeakReference<Activity> mActivityReference;
@NonNull private final WeakReference<Activity> mActivityReference;
public ImportBookmarksTask(Activity activity) {
mActivityReference = new WeakReference<>(activity);
@ -61,10 +67,10 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -61,10 +67,10 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
@Override
protected Integer doInBackground(Void... params) {
List<HistoryItem> list = null;
if (mSync.isStockSupported()) {
list = mSync.getBookmarksFromStockBrowser();
} else if (mSync.isChromeSupported()) {
list = mSync.getBookmarksFromChrome();
if (getSync().isStockSupported()) {
list = getSync().getBookmarksFromStockBrowser();
} else if (getSync().isChromeSupported()) {
list = getSync().getBookmarksFromChrome();
}
int count = 0;
if (list != null && !list.isEmpty()) {
@ -86,6 +92,16 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -86,6 +92,16 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
}
}
@NonNull
private BookmarkLocalSync getSync() {
Preconditions.checkNonNull(mActivity);
if (mSync == null) {
mSync = new BookmarkLocalSync(mActivity);
}
return mSync;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -94,6 +110,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -94,6 +110,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
addPreferencesFromResource(R.xml.preference_bookmarks);
mActivity = getActivity();
mSync = new BookmarkLocalSync(mActivity);
initPrefs();
@ -117,8 +134,6 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -117,8 +134,6 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
Preference exportpref = findPreference(SETTINGS_EXPORT);
Preference importpref = findPreference(SETTINGS_IMPORT);
mSync = new BookmarkLocalSync(mActivity);
exportpref.setOnPreferenceClickListener(this);
importpref.setOnPreferenceClickListener(this);
@ -129,13 +144,13 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -129,13 +144,13 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
@Override
public void run() {
Preference importStock = findPreference(SETTINGS_IMPORT_BROWSER);
importStock.setEnabled(mSync.isStockSupported() || mSync.isChromeSupported());
importStock.setEnabled(getSync().isStockSupported() || getSync().isChromeSupported());
importStock.setOnPreferenceClickListener(BookmarkSettingsFragment.this);
}
};
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
switch (preference.getKey()) {
case SETTINGS_EXPORT:
PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(getActivity(), REQUIRED_PERMISSIONS,
@ -175,7 +190,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -175,7 +190,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
}
}
private void loadFileList(File path) {
private void loadFileList(@Nullable File path) {
File file;
if (path != null) {
file = path;
@ -208,7 +223,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref @@ -208,7 +223,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
private static class SortName implements Comparator<File> {
@Override
public int compare(File a, File b) {
public int compare(@NonNull File a, @NonNull File b) {
if (a.isDirectory() && b.isDirectory())
return a.getName().compareTo(b.getName());

16
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -146,7 +146,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -146,7 +146,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.bookmark_drawer, container, false);
mBookmarksListView = (ListView) view.findViewById(R.id.right_drawer_list);
mBookmarksListView.setOnItemClickListener(mItemClickListener);
@ -187,14 +187,14 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -187,14 +187,14 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
}
@Subscribe
public void addBookmark(final BrowserEvents.BookmarkAdded event) {
public void addBookmark(@NonNull final BrowserEvents.BookmarkAdded event) {
updateBookmarkIndicator(event.url);
String folder = mBookmarkManager.getCurrentFolder();
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(folder, true), false);
}
@Subscribe
public void currentPageInfo(final BrowserEvents.CurrentPageUrl event) {
public void currentPageInfo(@NonNull final BrowserEvents.CurrentPageUrl event) {
updateBookmarkIndicator(event.url);
String folder = mBookmarkManager.getCurrentFolder();
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(folder, true), false);
@ -227,7 +227,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -227,7 +227,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
}
@Subscribe
public void bookmarkDeleted(final BookmarkEvents.Deleted event) {
public void bookmarkDeleted(@NonNull final BookmarkEvents.Deleted event) {
mBookmarks.remove(event.item);
if (event.item.isFolder()) {
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
@ -236,7 +236,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -236,7 +236,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
}
}
private void setBookmarkDataSet(List<HistoryItem> items, boolean animate) {
private void setBookmarkDataSet(@NonNull List<HistoryItem> items, boolean animate) {
mBookmarks.clear();
mBookmarks.addAll(items);
mBookmarkAdapter.notifyDataSetChanged();
@ -294,7 +294,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -294,7 +294,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
}
private void handleLongPress(final HistoryItem item) {
private void handleLongPress(@NonNull final HistoryItem item) {
if (item.isFolder()) {
mBookmarksDialogBuilder.showBookmarkFolderLongPressedDialog(getContext(), item);
} else {
@ -303,7 +303,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -303,7 +303,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
}
@Override
public void onClick(View v) {
public void onClick(@NonNull View v) {
switch (v.getId()) {
case R.id.action_add_bookmark:
mEventBus.post(new BookmarkEvents.ToggleBookmarkForCurrentPage());
@ -338,7 +338,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -338,7 +338,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
final Context context;
public BookmarkViewAdapter(Context context, List<HistoryItem> data) {
public BookmarkViewAdapter(Context context, @NonNull List<HistoryItem> data) {
super(context, R.layout.bookmark_list_item, data);
this.context = context;
}

5
app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java

@ -8,6 +8,7 @@ import android.content.DialogInterface; @@ -8,6 +8,7 @@ import android.content.DialogInterface;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.LayoutInflater;
@ -83,7 +84,7 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme @@ -83,7 +84,7 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
}
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
switch (preference.getKey()) {
case SETTINGS_THEME:
themePicker();
@ -97,7 +98,7 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme @@ -97,7 +98,7 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
// switch preferences
switch (preference.getKey()) {
case SETTINGS_HIDESTATUSBAR:

7
app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

@ -10,6 +10,7 @@ import android.os.Bundle; @@ -10,6 +10,7 @@ import android.os.Bundle;
import android.os.Environment;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
@ -503,7 +504,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -503,7 +504,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
}
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
switch (preference.getKey()) {
case SETTINGS_PROXY:
proxyChoicePicker();
@ -526,7 +527,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -526,7 +527,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
boolean checked = false;
if (newValue instanceof Boolean) {
checked = (Boolean) newValue;
@ -586,7 +587,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -586,7 +587,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
public void afterTextChanged(@NonNull Editable s) {
if (!DownloadHandler.isWriteAccessAvailable(s.toString())) {
this.getDownload.setTextColor(this.errorColor);
} else {

7
app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java

@ -11,6 +11,7 @@ import android.os.Handler; @@ -11,6 +11,7 @@ import android.os.Handler;
import android.os.Message;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.webkit.WebView;
@ -114,7 +115,7 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme @@ -114,7 +115,7 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
}
@Override
public void handleMessage(Message msg) {
public void handleMessage(@NonNull Message msg) {
switch (msg.what) {
case 1:
Utils.showSnackbar(mHandlerContext, R.string.message_clear_history);
@ -128,7 +129,7 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme @@ -128,7 +129,7 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
}
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
switch (preference.getKey()) {
case SETTINGS_CLEARCACHE:
clearCache();
@ -209,7 +210,7 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme @@ -209,7 +210,7 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
switch (preference.getKey()) {
case SETTINGS_LOCATION:
mPreferenceManager.setLocationEnabled((Boolean) newValue);

45
app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

@ -69,8 +69,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -69,8 +69,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
private boolean mColorMode = true;
private boolean mShowInNavigationDrawer;
private RecyclerView mRecyclerView;
private LightningViewAdapter mTabsAdapter;
@Nullable private LightningViewAdapter mTabsAdapter;
private UIController mUiController;
@Inject TabsManager tabsManager;
@ -99,7 +98,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -99,7 +98,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view;
final LayoutManager layoutManager;
if (mShowInNavigationDrawer) {
@ -114,11 +113,11 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -114,11 +113,11 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
view = inflater.inflate(R.layout.tab_strip, container, false);
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
}
mRecyclerView = (RecyclerView) view.findViewById(R.id.tabs_list);
mRecyclerView.setLayoutManager(layoutManager);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.tabs_list);
recyclerView.setLayoutManager(layoutManager);
mTabsAdapter = new LightningViewAdapter(mShowInNavigationDrawer);
mRecyclerView.setAdapter(mTabsAdapter);
mRecyclerView.setHasFixedSize(true);
recyclerView.setAdapter(mTabsAdapter);
recyclerView.setHasFixedSize(true);
return view;
}
@ -134,7 +133,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -134,7 +133,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
@Override
public void onDestroyView() {
super.onDestroyView();
mRecyclerView = null;
mTabsAdapter = null;
}
@ -148,8 +146,10 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -148,8 +146,10 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
public void onResume() {
super.onResume();
// Force adapter refresh
if (mTabsAdapter != null) {
mTabsAdapter.notifyDataSetChanged();
}
}
@Override
public void onStop() {
@ -165,7 +165,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -165,7 +165,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
}
@Override
public void onClick(View v) {
public void onClick(@NonNull View v) {
switch (v.getId()) {
case R.id.new_tab_button:
mBus.post(new TabEvents.NewTab());
@ -184,7 +184,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -184,7 +184,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
}
@Override
public boolean onLongClick(View v) {
public boolean onLongClick(@NonNull View v) {
switch (v.getId()) {
case R.id.action_new_tab:
mBus.post(new TabEvents.NewTabLongPress());
@ -198,9 +198,9 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -198,9 +198,9 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
public class LightningViewAdapter extends RecyclerView.Adapter<LightningViewAdapter.LightningViewHolder> {
private final int mLayoutResourceId;
private final Drawable mBackgroundTabDrawable;
private final Drawable mForegroundTabDrawable;
private final Bitmap mForegroundTabBitmap;
@Nullable private final Drawable mBackgroundTabDrawable;
@Nullable private final Drawable mForegroundTabDrawable;
@Nullable private final Bitmap mForegroundTabBitmap;
private ColorMatrix mColorMatrix;
private Paint mPaint;
private ColorFilter mFilter;
@ -229,15 +229,16 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -229,15 +229,16 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
}
}
@NonNull
@Override
public LightningViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
public LightningViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
View view = inflater.inflate(mLayoutResourceId, viewGroup, false);
return new LightningViewHolder(view);
}
@Override
public void onBindViewHolder(final LightningViewHolder holder, int position) {
public void onBindViewHolder(@NonNull final LightningViewHolder holder, int position) {
holder.exitButton.setTag(position);
ViewCompat.jumpDrawablesToCurrentState(holder.exitButton);
@ -293,7 +294,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -293,7 +294,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
return tabsManager.size();
}
public Bitmap getDesaturatedBitmap(Bitmap favicon) {
public Bitmap getDesaturatedBitmap(@NonNull Bitmap favicon) {
Bitmap grayscaleBitmap = Bitmap.createBitmap(favicon.getWidth(),
favicon.getHeight(), Bitmap.Config.ARGB_8888);
@ -312,7 +313,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -312,7 +313,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
public class LightningViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
public LightningViewHolder(View view) {
public LightningViewHolder(@NonNull View view) {
super(view);
txtTitle = (TextView) view.findViewById(R.id.textTab);
favicon = (ImageView) view.findViewById(R.id.faviconTab);
@ -326,11 +327,11 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -326,11 +327,11 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
layout.setOnLongClickListener(this);
}
final TextView txtTitle;
final ImageView favicon;
final ImageView exit;
final FrameLayout exitButton;
final LinearLayout layout;
@NonNull final TextView txtTitle;
@NonNull final ImageView favicon;
@NonNull final ImageView exit;
@NonNull final FrameLayout exitButton;
@NonNull final LinearLayout layout;
@Override
public void onClick(View v) {

Loading…
Cancel
Save