From 5ff9a3c71001ae5b44901b82ee2c326af26aba0e Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sat, 9 Feb 2019 16:59:28 +0100 Subject: [PATCH] remove Lint errors --- .../ui/fragment/FileDetailFragment.java | 23 +++--- .../android/ui/preview/ImageViewCustom.java | 80 ------------------- .../cube/GridViewWithHeaderAndFooter.java | 74 +++++------------ .../src/main/res/menu/file_actions_menu.xml | 4 +- 4 files changed, 33 insertions(+), 148 deletions(-) delete mode 100644 owncloudApp/src/main/java/com/owncloud/android/ui/preview/ImageViewCustom.java diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java index adc720b7954..43eaee47fd3 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -1,4 +1,4 @@ -/** +/* * ownCloud Android client application * * @author Bartek Przybylski @@ -57,6 +57,9 @@ import com.owncloud.android.utils.MimetypeIconUtil; import com.owncloud.android.utils.PreferenceUtils; +import org.jetbrains.annotations.NotNull; + + /** * This Fragment is used to display the details about a file. */ @@ -76,7 +79,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener /** * Public factory method to create new FileDetailFragment instances. - * + *

* When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before). * * @param fileToDetail An {@link OCFile} to show in the fragment @@ -94,7 +97,7 @@ public static FileDetailFragment newInstance(OCFile fileToDetail, Account accoun /** * Creates an empty details fragment. - * + *

* It's necessary to keep a public constructor without parameters; the system uses it when tries * to reinstantiate a fragment automatically. */ @@ -106,7 +109,7 @@ public FileDetailFragment() { @Override public void onActivityCreated(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true); mProgressController = new TransferProgressController((ComponentsGetter) getActivity()); ProgressBar progressBar = mView.findViewById(R.id.fdProgressBar); @@ -128,8 +131,7 @@ public void onActivityCreated(Bundle savedInstanceState) { } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setFile(getArguments().getParcelable(ARG_FILE)); mAccount = getArguments().getParcelable(ARG_ACCOUNT); @@ -154,7 +156,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, } @Override - public void onSaveInstanceState(Bundle outState) { + public void onSaveInstanceState(@NotNull Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable(FileActivity.EXTRA_FILE, getFile()); outState.putParcelable(FileActivity.EXTRA_ACCOUNT, mAccount); @@ -367,9 +369,9 @@ public boolean isEmpty() { * Updates the view with all relevant details about that file. * * @param forcedTransferring Flag signaling if the file should be considered as downloading or uploading, - * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and - * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false. - * @param refresh If 'true', try to refresh the whole file from the database + * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and + * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false. + * @param refresh If 'true', try to refresh the whole file from the database */ private void updateFileDetails(boolean forcedTransferring, boolean refresh) { if (readyToShow()) { @@ -431,6 +433,7 @@ private void setFilename(String filename) { /** * Updates the MIME type in view + * * @param file : An {@link OCFile} */ private void setFiletype(OCFile file) { diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/ImageViewCustom.java b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/ImageViewCustom.java deleted file mode 100644 index f8b5fb37359..00000000000 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/ImageViewCustom.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.owncloud.android.ui.preview; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.os.Build; -import android.util.AttributeSet; -import android.view.View; -import android.widget.ImageView; - -import com.owncloud.android.lib.common.utils.Log_OC; - -public class ImageViewCustom extends ImageView { - - private static final String TAG = ImageViewCustom.class.getSimpleName(); - - private static final boolean IS_ICS_OR_HIGHER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; - private static final boolean IS_VERSION_BUGGY_ON_RECYCLES = - Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1 || - Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2; - - private int mBitmapHeight; - private int mBitmapWidth; - - public ImageViewCustom(Context context) { - super(context); - } - - public ImageViewCustom(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public ImageViewCustom(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - @SuppressLint("NewApi") - @Override - protected void onDraw(Canvas canvas) { - - if (IS_ICS_OR_HIGHER && checkIfMaximumBitmapExceed(canvas) || IS_VERSION_BUGGY_ON_RECYCLES) { - // Software type is set with two targets: - // 1. prevent that bitmaps larger than maximum textures allowed are shown as black views in devices - // with LAYER_TYPE_HARDWARE enabled by default; - // 2. grant that bitmaps are correctly dellocated from memory in versions suffering the bug fixed in - // https://android.googlesource.com/platform/frameworks/base/+/034de6b1ec561797a2422314e6ef03e3cd3e08e0; - // - setLayerType(View.LAYER_TYPE_SOFTWARE, null); - } - - super.onDraw(canvas); - } - - /** - * Checks if current bitmaps exceed the maximum OpenGL texture size limit - * - * @param canvas Canvas where the view will be drawn into. - * @return boolean True means that the bitmap is too big for the canvas. - */ - @SuppressLint("NewApi") - private boolean checkIfMaximumBitmapExceed(Canvas canvas) { - Log_OC.v(TAG, "Canvas maximum: " + canvas.getMaximumBitmapWidth() + " - " + canvas.getMaximumBitmapHeight()); - return mBitmapWidth > canvas.getMaximumBitmapWidth() - || mBitmapHeight > canvas.getMaximumBitmapHeight(); - - } - - @Override - /** - * Keeps the size of the bitmap cached in member variables for faster access in {@link #onDraw(Canvas)} , - * but without keeping another reference to the {@link Bitmap} - */ - public void setImageBitmap(Bitmap bm) { - mBitmapWidth = bm.getWidth(); - mBitmapHeight = bm.getHeight(); - super.setImageBitmap(bm); - } - -} diff --git a/owncloudApp/src/main/java/third_parties/in/srain/cube/GridViewWithHeaderAndFooter.java b/owncloudApp/src/main/java/third_parties/in/srain/cube/GridViewWithHeaderAndFooter.java index a756ee3316e..54e6f343813 100644 --- a/owncloudApp/src/main/java/third_parties/in/srain/cube/GridViewWithHeaderAndFooter.java +++ b/owncloudApp/src/main/java/third_parties/in/srain/cube/GridViewWithHeaderAndFooter.java @@ -55,7 +55,7 @@ private static class FixedViewInfo { * The view to add to the grid */ public View view; - public ViewGroup viewContainer; + ViewGroup viewContainer; /** * The data backing the view. This is returned from {@link android.widget.ListAdapter#getItem(int)}. */ @@ -63,16 +63,15 @@ private static class FixedViewInfo { /** * true if the fixed view should be selectable in the grid */ - public boolean isSelectable; + boolean isSelectable; } - private int mNumColumns = AUTO_FIT; private View mViewForMeasureRowHeight = null; private int mRowHeight = -1; - private static final String LOG_TAG = "grid-view-with-header-and-footer"; + private static final String LOG_TAG = "grid-view-header-footer"; - private ArrayList mHeaderViewInfos = new ArrayList(); - private ArrayList mFooterViewInfos = new ArrayList(); + private ArrayList mHeaderViewInfos = new ArrayList<>(); + private ArrayList mFooterViewInfos = new ArrayList<>(); private void initHeaderGridView() { } @@ -96,7 +95,7 @@ public GridViewWithHeaderAndFooter(Context context, AttributeSet attrs, int defS protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); ListAdapter adapter = getAdapter(); - if (adapter != null && adapter instanceof HeaderViewGridAdapter) { + if (adapter instanceof HeaderViewGridAdapter) { ((HeaderViewGridAdapter) adapter).setNumColumns(getNumColumnsCompatible()); invalidateRowHeight(); ((HeaderViewGridAdapter) adapter).setRowHeight(getRowHeight()); @@ -108,15 +107,6 @@ public void setClipChildren(boolean clipChildren) { // Ignore, since the header rows depend on not being clipped } - /** - * Do not call this method unless you know how it works. - * - * @param clipChildren - */ - public void setClipChildrenSupper(boolean clipChildren) { - super.setClipChildren(false); - } - /** * Add a fixed view to appear at the top of the grid. If addHeaderView is * called more than once, the views will appear in the order they were @@ -263,23 +253,8 @@ private void removeFixedViewInfo(View v, ArrayList where) { } } - @TargetApi(11) private int getNumColumnsCompatible() { - if (Build.VERSION.SDK_INT >= 11) { - return super.getNumColumns(); - } else { - try { - Field numColumns = getClass().getSuperclass().getDeclaredField("mNumColumns"); - numColumns.setAccessible(true); - return numColumns.getInt(this); - } catch (Exception e) { - if (mNumColumns != -1) { - return mNumColumns; - } - throw new RuntimeException("Can not determine the mNumColumns for this API platform, please call " + - "setNumColumns to set it."); - } - } + return super.getNumColumns(); } @TargetApi(16) @@ -337,24 +312,14 @@ public int getRowHeight() { return mRowHeight; } - @TargetApi(11) public void tryToScrollToBottomSmoothly() { int lastPos = getAdapter().getCount() - 1; - if (Build.VERSION.SDK_INT >= 11) { - smoothScrollToPositionFromTop(lastPos, 0); - } else { - setSelection(lastPos); - } + smoothScrollToPositionFromTop(lastPos, 0); } - @TargetApi(11) public void tryToScrollToBottomSmoothly(int duration) { int lastPos = getAdapter().getCount() - 1; - if (Build.VERSION.SDK_INT >= 11) { - smoothScrollToPositionFromTop(lastPos, 0, duration); - } else { - setSelection(lastPos); - } + smoothScrollToPositionFromTop(lastPos, 0, duration); } @Override @@ -406,9 +371,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override public void setNumColumns(int numColumns) { super.setNumColumns(numColumns); - mNumColumns = numColumns; ListAdapter adapter = getAdapter(); - if (adapter != null && adapter instanceof HeaderViewGridAdapter) { + if (adapter instanceof HeaderViewGridAdapter) { ((HeaderViewGridAdapter) adapter).setNumColumns(numColumns); } } @@ -426,7 +390,7 @@ private static class HeaderViewGridAdapter implements WrapperListAdapter, Filter private final DataSetObservable mDataSetObservable = new DataSetObservable(); private final ListAdapter mAdapter; static final ArrayList EMPTY_INFO_LIST = - new ArrayList(); + new ArrayList<>(); // This ArrayList is assumed to NOT be null. ArrayList mHeaderViewInfos; @@ -458,7 +422,7 @@ public HeaderViewGridAdapter(ArrayList headerViewInfos, ArrayList && areAllListInfosSelectable(mFooterViewInfos); } - public void setNumColumns(int numColumns) { + void setNumColumns(int numColumns) { if (numColumns < 1) { return; } @@ -468,7 +432,7 @@ public void setNumColumns(int numColumns) { } } - public void setRowHeight(int height) { + void setRowHeight(int height) { mRowHeight = height; } @@ -476,7 +440,7 @@ public int getHeadersCount() { return mHeaderViewInfos.size(); } - public int getFootersCount() { + int getFootersCount() { return mFooterViewInfos.size(); } @@ -496,7 +460,7 @@ private boolean areAllListInfosSelectable(ArrayList infos) { return true; } - public boolean removeHeader(View v) { + boolean removeHeader(View v) { for (int i = 0; i < mHeaderViewInfos.size(); i++) { FixedViewInfo info = mHeaderViewInfos.get(i); if (info.view == v) { @@ -510,7 +474,7 @@ public boolean removeHeader(View v) { return false; } - public boolean removeFooter(View v) { + boolean removeFooter(View v) { for (int i = 0; i < mFooterViewInfos.size(); i++) { FixedViewInfo info = mFooterViewInfos.get(i); if (info.view == v) { @@ -543,8 +507,7 @@ public boolean areAllItemsEnabled() { } private int getAdapterAndPlaceHolderCount() { - final int adapterCount = (int) (Math.ceil(1f * mAdapter.getCount() / mNumColumns) * mNumColumns); - return adapterCount; + return (int) (Math.ceil(1f * mAdapter.getCount() / mNumColumns) * mNumColumns); } @Override @@ -657,8 +620,7 @@ public View getView(int position, View convertView, ViewGroup parent) { adapterCount = getAdapterAndPlaceHolderCount(); if (adjPosition < adapterCount) { if (adjPosition < mAdapter.getCount()) { - View view = mAdapter.getView(adjPosition, convertView, parent); - return view; + return mAdapter.getView(adjPosition, convertView, parent); } else { if (convertView == null) { convertView = new View(parent.getContext()); diff --git a/owncloudApp/src/main/res/menu/file_actions_menu.xml b/owncloudApp/src/main/res/menu/file_actions_menu.xml index 6950aeb0460..5909f985fe3 100644 --- a/owncloudApp/src/main/res/menu/file_actions_menu.xml +++ b/owncloudApp/src/main/res/menu/file_actions_menu.xml @@ -23,13 +23,13 @@ + app:showAsAction="never" /> + app:showAsAction="never" />