Use final where possible

This commit is contained in:
wb9688 2020-08-16 10:24:58 +02:00
parent d306513319
commit 87228673b4
132 changed files with 1024 additions and 1005 deletions

View file

@ -59,7 +59,7 @@ public final class AnimatedProgressBar extends ProgressBar {
@Override
protected void applyTransformation(final float interpolatedTime, final Transformation t) {
super.applyTransformation(interpolatedTime, t);
float value = from + (to - from) * interpolatedTime;
final float value = from + (to - from) * interpolatedTime;
progressBar.setProgress((int) value);
}
}

View file

@ -178,7 +178,7 @@ public class CollapsibleView extends LinearLayout {
}
public void broadcastState() {
for (StateListener listener : listeners) {
for (final StateListener listener : listeners) {
listener.onStateChanged(currentState);
}
}

View file

@ -55,9 +55,10 @@ public final class FocusAwareDrawerLayout extends DrawerLayout {
boolean hasOpenPanels = false;
for (int i = 0; i < getChildCount(); ++i) {
View child = getChildAt(i);
final View child = getChildAt(i);
DrawerLayout.LayoutParams lp = (DrawerLayout.LayoutParams) child.getLayoutParams();
final DrawerLayout.LayoutParams lp
= (DrawerLayout.LayoutParams) child.getLayoutParams();
if (lp.gravity != 0 && isDrawerVisible(child)) {
hasOpenPanels = true;
@ -82,9 +83,10 @@ public final class FocusAwareDrawerLayout extends DrawerLayout {
View content = null;
for (int i = 0; i < getChildCount(); ++i) {
View child = getChildAt(i);
final View child = getChildAt(i);
DrawerLayout.LayoutParams lp = (DrawerLayout.LayoutParams) child.getLayoutParams();
final DrawerLayout.LayoutParams lp
= (DrawerLayout.LayoutParams) child.getLayoutParams();
if (lp.gravity == 0) {
content = child;

View file

@ -87,12 +87,12 @@ public final class FocusOverlayView extends Drawable implements
}
private void updateRect() {
View focusedView = focused == null ? null : this.focused.get();
final View focusedView = focused == null ? null : this.focused.get();
int l = focusRect.left;
int r = focusRect.right;
int t = focusRect.top;
int b = focusRect.bottom;
final int l = focusRect.left;
final int r = focusRect.right;
final int t = focusRect.top;
final int b = focusRect.bottom;
if (focusedView != null && isShown(focusedView)) {
focusedView.getGlobalVisibleRect(focusRect);
@ -184,40 +184,40 @@ public final class FocusOverlayView extends Drawable implements
}
public static void setupFocusObserver(final Dialog dialog) {
Rect displayRect = new Rect();
final Rect displayRect = new Rect();
Window window = dialog.getWindow();
final Window window = dialog.getWindow();
assert window != null;
View decor = window.getDecorView();
final View decor = window.getDecorView();
decor.getWindowVisibleDisplayFrame(displayRect);
FocusOverlayView overlay = new FocusOverlayView(dialog.getContext());
final FocusOverlayView overlay = new FocusOverlayView(dialog.getContext());
overlay.setBounds(0, 0, displayRect.width(), displayRect.height());
setupOverlay(window, overlay);
}
public static void setupFocusObserver(final Activity activity) {
Rect displayRect = new Rect();
final Rect displayRect = new Rect();
Window window = activity.getWindow();
View decor = window.getDecorView();
final Window window = activity.getWindow();
final View decor = window.getDecorView();
decor.getWindowVisibleDisplayFrame(displayRect);
FocusOverlayView overlay = new FocusOverlayView(activity);
final FocusOverlayView overlay = new FocusOverlayView(activity);
overlay.setBounds(0, 0, displayRect.width(), displayRect.height());
setupOverlay(window, overlay);
}
private static void setupOverlay(final Window window, final FocusOverlayView overlay) {
ViewGroup decor = (ViewGroup) window.getDecorView();
final ViewGroup decor = (ViewGroup) window.getDecorView();
decor.getOverlay().add(overlay);
fixFocusHierarchy(decor);
ViewTreeObserver observer = decor.getViewTreeObserver();
final ViewTreeObserver observer = decor.getViewTreeObserver();
observer.addOnScrollChangedListener(overlay);
observer.addOnGlobalFocusChangeListener(overlay);
observer.addOnGlobalLayoutListener(overlay);
@ -235,7 +235,7 @@ public final class FocusOverlayView extends Drawable implements
window.setCallback(new WindowCallbackWrapper(window.getCallback()) {
@Override
public boolean dispatchKeyEvent(final KeyEvent event) {
boolean res = super.dispatchKeyEvent(event);
final boolean res = super.dispatchKeyEvent(event);
overlay.onKey(event);
return res;
}
@ -280,10 +280,10 @@ public final class FocusOverlayView extends Drawable implements
return; // clusters aren't supposed to nest
}
int childCount = viewGroup.getChildCount();
final int childCount = viewGroup.getChildCount();
for (int i = 0; i < childCount; ++i) {
View view = viewGroup.getChildAt(i);
final View view = viewGroup.getChildAt(i);
if (view instanceof ViewGroup) {
clearFocusObstacles((ViewGroup) view);

View file

@ -64,7 +64,7 @@ public class LargeTextMovementMethod extends LinkMovementMethod {
final int keyCode,
final int movementMetaState,
final KeyEvent event) {
int newDir = keyToDir(keyCode);
final int newDir = keyToDir(keyCode);
if (direction != 0 && newDir != direction) {
return false;
@ -72,7 +72,7 @@ public class LargeTextMovementMethod extends LinkMovementMethod {
this.direction = 0;
ViewGroup root = findScrollableParent(widget);
final ViewGroup root = findScrollableParent(widget);
widget.getHitRect(visibleRect);
@ -118,46 +118,46 @@ public class LargeTextMovementMethod extends LinkMovementMethod {
}
private boolean gotoPrev(final TextView view, final Spannable buffer) {
Layout layout = view.getLayout();
final Layout layout = view.getLayout();
if (layout == null) {
return false;
}
View root = findScrollableParent(view);
final View root = findScrollableParent(view);
int rootHeight = root.getHeight();
final int rootHeight = root.getHeight();
if (visibleRect.top >= 0) {
// we fit entirely into the viewport, no need for fancy footwork
return false;
}
int topExtra = -visibleRect.top;
final int topExtra = -visibleRect.top;
int firstVisibleLineNumber = layout.getLineForVertical(topExtra);
final int firstVisibleLineNumber = layout.getLineForVertical(topExtra);
// when deciding whether to pass "focus" to span, account for one more line
// this ensures, that focus is never passed to spans partially outside scroll window
int visibleStart = firstVisibleLineNumber == 0
final int visibleStart = firstVisibleLineNumber == 0
? 0
: layout.getLineStart(firstVisibleLineNumber - 1);
ClickableSpan[] candidates = buffer.getSpans(
final ClickableSpan[] candidates = buffer.getSpans(
visibleStart, buffer.length(), ClickableSpan.class);
if (candidates.length != 0) {
int a = Selection.getSelectionStart(buffer);
int b = Selection.getSelectionEnd(buffer);
final int a = Selection.getSelectionStart(buffer);
final int b = Selection.getSelectionEnd(buffer);
int selStart = Math.min(a, b);
int selEnd = Math.max(a, b);
final int selStart = Math.min(a, b);
final int selEnd = Math.max(a, b);
int bestStart = -1;
int bestEnd = -1;
for (int i = 0; i < candidates.length; i++) {
int start = buffer.getSpanStart(candidates[i]);
int end = buffer.getSpanEnd(candidates[i]);
final int start = buffer.getSpanStart(candidates[i]);
final int end = buffer.getSpanEnd(candidates[i]);
if ((end < selEnd || selStart == selEnd) && start >= visibleStart) {
if (end > bestEnd) {
@ -173,7 +173,7 @@ public class LargeTextMovementMethod extends LinkMovementMethod {
}
}
float fourLines = view.getTextSize() * 4;
final float fourLines = view.getTextSize() * 4;
visibleRect.left = 0;
visibleRect.right = view.getWidth();
@ -184,49 +184,49 @@ public class LargeTextMovementMethod extends LinkMovementMethod {
}
private boolean gotoNext(final TextView view, final Spannable buffer) {
Layout layout = view.getLayout();
final Layout layout = view.getLayout();
if (layout == null) {
return false;
}
View root = findScrollableParent(view);
final View root = findScrollableParent(view);
int rootHeight = root.getHeight();
final int rootHeight = root.getHeight();
if (visibleRect.bottom <= rootHeight) {
// we fit entirely into the viewport, no need for fancy footwork
return false;
}
int bottomExtra = visibleRect.bottom - rootHeight;
final int bottomExtra = visibleRect.bottom - rootHeight;
int visibleBottomBorder = view.getHeight() - bottomExtra;
final int visibleBottomBorder = view.getHeight() - bottomExtra;
int lineCount = layout.getLineCount();
final int lineCount = layout.getLineCount();
int lastVisibleLineNumber = layout.getLineForVertical(visibleBottomBorder);
final int lastVisibleLineNumber = layout.getLineForVertical(visibleBottomBorder);
// when deciding whether to pass "focus" to span, account for one more line
// this ensures, that focus is never passed to spans partially outside scroll window
int visibleEnd = lastVisibleLineNumber == lineCount - 1
final int visibleEnd = lastVisibleLineNumber == lineCount - 1
? buffer.length()
: layout.getLineEnd(lastVisibleLineNumber - 1);
ClickableSpan[] candidates = buffer.getSpans(0, visibleEnd, ClickableSpan.class);
final ClickableSpan[] candidates = buffer.getSpans(0, visibleEnd, ClickableSpan.class);
if (candidates.length != 0) {
int a = Selection.getSelectionStart(buffer);
int b = Selection.getSelectionEnd(buffer);
final int a = Selection.getSelectionStart(buffer);
final int b = Selection.getSelectionEnd(buffer);
int selStart = Math.min(a, b);
int selEnd = Math.max(a, b);
final int selStart = Math.min(a, b);
final int selEnd = Math.max(a, b);
int bestStart = Integer.MAX_VALUE;
int bestEnd = Integer.MAX_VALUE;
for (int i = 0; i < candidates.length; i++) {
int start = buffer.getSpanStart(candidates[i]);
int end = buffer.getSpanEnd(candidates[i]);
final int start = buffer.getSpanStart(candidates[i]);
final int end = buffer.getSpanEnd(candidates[i]);
if ((start > selStart || selStart == selEnd) && end <= visibleEnd) {
if (start < bestStart) {
@ -245,7 +245,7 @@ public class LargeTextMovementMethod extends LinkMovementMethod {
// there are no links within visible area, but still some text past visible area
// scroll visible area further in required direction
float fourLines = view.getTextSize() * 4;
final float fourLines = view.getTextSize() * 4;
visibleRect.left = 0;
visibleRect.right = view.getWidth();

View file

@ -104,14 +104,14 @@ public class NewPipeRecyclerView extends RecyclerView {
// can mess with focused View by moving it off-screen and detaching)
if (focused != null) {
View focusedItem = findContainingItemView(focused);
final View focusedItem = findContainingItemView(focused);
if (focusedItem != null) {
focusedItem.getHitRect(focusRect);
}
}
// call focusSearch() to initiate layout, but disregard returned View for now
View adapterResult = super.focusSearch(focused, direction);
final View adapterResult = super.focusSearch(focused, direction);
if (adapterResult != null && !isOutside(adapterResult)) {
adapterResult.requestFocus(direction);
return true;
@ -148,16 +148,16 @@ public class NewPipeRecyclerView extends RecyclerView {
return false;
}
FocusFinder finder = FocusFinder.getInstance();
final FocusFinder finder = FocusFinder.getInstance();
// try to use FocusFinder instead of adapter
ViewGroup root = (ViewGroup) getRootView();
final ViewGroup root = (ViewGroup) getRootView();
tempFocus.set(focusRect);
root.offsetDescendantRectToMyCoords(this, tempFocus);
View focusFinderResult = finder.findNextFocusFromRect(root, tempFocus, direction);
final View focusFinderResult = finder.findNextFocusFromRect(root, tempFocus, direction);
if (focusFinderResult != null && !isOutside(focusFinderResult)) {
focusFinderResult.requestFocus(direction);
return true;
@ -172,7 +172,7 @@ public class NewPipeRecyclerView extends RecyclerView {
parent.offsetDescendantRectToMyCoords(this, tempFocus);
View candidate = finder.findNextFocusFromRect(parent, tempFocus, direction);
final View candidate = finder.findNextFocusFromRect(parent, tempFocus, direction);
if (candidate != null && candidate.requestFocus(direction)) {
return true;
}

View file

@ -118,7 +118,7 @@ public class ScrollableTabLayout extends TabLayout {
final int count = getTabCount();
int contentWidth = 0;
for (int i = 0; i < count; i++) {
View child = getTabAt(i).view;
final View child = getTabAt(i).view;
if (child.getVisibility() == View.VISIBLE) {
// Use tab's minimum requested width should actual content be too small
contentWidth += Math.max(child.getMinimumWidth(), child.getMeasuredWidth());

View file

@ -64,12 +64,12 @@ public final class SuperScrollLayoutManager extends LinearLayoutManager {
@Nullable
@Override
public View onInterceptFocusSearch(@NonNull final View focused, final int direction) {
View focusedItem = findContainingItemView(focused);
final View focusedItem = findContainingItemView(focused);
if (focusedItem == null) {
return super.onInterceptFocusSearch(focused, direction);
}
int listDirection = getAbsoluteDirection(direction);
final int listDirection = getAbsoluteDirection(direction);
if (listDirection == 0) {
return super.onInterceptFocusSearch(focused, direction);
}
@ -82,9 +82,9 @@ public final class SuperScrollLayoutManager extends LinearLayoutManager {
// Fortunately we can intercept focus search and implement our own logic, based purely
// on position along the LinearLayoutManager axis
ViewGroup recycler = (ViewGroup) focusedItem.getParent();
final ViewGroup recycler = (ViewGroup) focusedItem.getParent();
int sourcePosition = getPosition(focusedItem);
final int sourcePosition = getPosition(focusedItem);
if (sourcePosition == 0 && listDirection < 0) {
return super.onInterceptFocusSearch(focused, direction);
}
@ -100,7 +100,7 @@ public final class SuperScrollLayoutManager extends LinearLayoutManager {
: View.FOCUSABLES_ALL);
try {
for (View view : focusables) {
for (final View view : focusables) {
if (view == focused || view == recycler) {
continue;
}
@ -111,7 +111,7 @@ public final class SuperScrollLayoutManager extends LinearLayoutManager {
continue;
}
int candidate = getDistance(sourcePosition, view, listDirection);
final int candidate = getDistance(sourcePosition, view, listDirection);
if (candidate < 0) {
continue;
}
@ -162,12 +162,12 @@ public final class SuperScrollLayoutManager extends LinearLayoutManager {
}
private int getDistance(final int sourcePosition, final View candidate, final int direction) {
View itemView = findContainingItemView(candidate);
final View itemView = findContainingItemView(candidate);
if (itemView == null) {
return -1;
}
int position = getPosition(itemView);
final int position = getPosition(itemView);
return direction * (position - sourcePosition);
}