-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
将 zhanghai/AndroidFastScroll 添加为子模块以确保 Java 版本的升级(修复资源引用错误,未做其它改动)
- Loading branch information
1 parent
eb2adf5
commit d3249dd
Showing
34 changed files
with
2,641 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
plugins { | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
namespace = "me.zhanghai.android.fastscroll" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 21 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_18 | ||
targetCompatibility = JavaVersion.VERSION_18 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "18" | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(libs.androidx.appcompat) | ||
implementation(libs.androidx.recyclerview) | ||
testImplementation(libs.junit) | ||
androidTestImplementation(libs.androidx.junit) | ||
androidTestImplementation(libs.androidx.espresso.core) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<!-- | ||
~ Copyright 2019 Google LLC | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<manifest /> |
74 changes: 74 additions & 0 deletions
74
fastscroll/src/main/java/me/zhanghai/android/fastscroll/AutoMirrorDrawable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package me.zhanghai.android.fastscroll; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.graphics.Canvas; | ||
import android.graphics.Rect; | ||
import android.graphics.drawable.Drawable; | ||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.graphics.drawable.DrawableWrapperCompat; | ||
import androidx.core.graphics.drawable.DrawableCompat; | ||
|
||
@SuppressLint("RestrictedApi") | ||
class AutoMirrorDrawable extends DrawableWrapperCompat { | ||
|
||
public AutoMirrorDrawable(@NonNull Drawable drawable) { | ||
super(drawable); | ||
} | ||
|
||
@Override | ||
public void draw(@NonNull Canvas canvas) { | ||
if (needMirroring()) { | ||
float centerX = getBounds().exactCenterX(); | ||
canvas.scale(-1, 1, centerX, 0); | ||
super.draw(canvas); | ||
canvas.scale(-1, 1, centerX, 0); | ||
} else { | ||
super.draw(canvas); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onLayoutDirectionChanged(int layoutDirection) { | ||
super.onLayoutDirectionChanged(layoutDirection); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isAutoMirrored() { | ||
return true; | ||
} | ||
|
||
private boolean needMirroring() { | ||
return DrawableCompat.getLayoutDirection(this) == View.LAYOUT_DIRECTION_RTL; | ||
} | ||
|
||
@Override | ||
public boolean getPadding(@NonNull Rect padding) { | ||
boolean hasPadding = super.getPadding(padding); | ||
if (needMirroring()) { | ||
int paddingStart = padding.left; | ||
int paddingEnd = padding.right; | ||
padding.left = paddingEnd; | ||
padding.right = paddingStart; | ||
} | ||
return hasPadding; | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
fastscroll/src/main/java/me/zhanghai/android/fastscroll/DefaultAnimationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package me.zhanghai.android.fastscroll; | ||
|
||
import android.view.View; | ||
import android.view.animation.Interpolator; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.interpolator.view.animation.FastOutLinearInInterpolator; | ||
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator; | ||
|
||
public class DefaultAnimationHelper implements FastScroller.AnimationHelper { | ||
|
||
private static final int SHOW_DURATION_MILLIS = 150; | ||
private static final int HIDE_DURATION_MILLIS = 200; | ||
private static final Interpolator SHOW_SCROLLBAR_INTERPOLATOR = | ||
new LinearOutSlowInInterpolator(); | ||
private static final Interpolator HIDE_SCROLLBAR_INTERPOLATOR = | ||
new FastOutLinearInInterpolator(); | ||
private static final int AUTO_HIDE_SCROLLBAR_DELAY_MILLIS = 1500; | ||
|
||
@NonNull | ||
private final View mView; | ||
|
||
private boolean mScrollbarAutoHideEnabled = true; | ||
|
||
private boolean mShowingScrollbar = true; | ||
private boolean mShowingPopup; | ||
|
||
public DefaultAnimationHelper(@NonNull View view) { | ||
mView = view; | ||
} | ||
|
||
@Override | ||
public void showScrollbar(@NonNull View trackView, @NonNull View thumbView) { | ||
|
||
if (mShowingScrollbar) { | ||
return; | ||
} | ||
mShowingScrollbar = true; | ||
|
||
trackView.animate() | ||
.alpha(1) | ||
.translationX(0) | ||
.setDuration(SHOW_DURATION_MILLIS) | ||
.setInterpolator(SHOW_SCROLLBAR_INTERPOLATOR) | ||
.start(); | ||
thumbView.animate() | ||
.alpha(1) | ||
.translationX(0) | ||
.setDuration(SHOW_DURATION_MILLIS) | ||
.setInterpolator(SHOW_SCROLLBAR_INTERPOLATOR) | ||
.start(); | ||
} | ||
|
||
@Override | ||
public void hideScrollbar(@NonNull View trackView, @NonNull View thumbView) { | ||
|
||
if (!mShowingScrollbar) { | ||
return; | ||
} | ||
mShowingScrollbar = false; | ||
|
||
boolean isLayoutRtl = mView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; | ||
int width = Math.max(trackView.getWidth(), thumbView.getWidth()); | ||
float translationX; | ||
if (isLayoutRtl) { | ||
translationX = trackView.getLeft() == 0 ? -width : 0; | ||
} else { | ||
translationX = trackView.getRight() == mView.getWidth() ? width : 0; | ||
} | ||
trackView.animate() | ||
.alpha(0) | ||
.translationX(translationX) | ||
.setDuration(HIDE_DURATION_MILLIS) | ||
.setInterpolator(HIDE_SCROLLBAR_INTERPOLATOR) | ||
.start(); | ||
thumbView.animate() | ||
.alpha(0) | ||
.translationX(translationX) | ||
.setDuration(HIDE_DURATION_MILLIS) | ||
.setInterpolator(HIDE_SCROLLBAR_INTERPOLATOR) | ||
.start(); | ||
} | ||
|
||
@Override | ||
public boolean isScrollbarAutoHideEnabled() { | ||
return mScrollbarAutoHideEnabled; | ||
} | ||
|
||
public void setScrollbarAutoHideEnabled(boolean enabled) { | ||
mScrollbarAutoHideEnabled = enabled; | ||
} | ||
|
||
@Override | ||
public int getScrollbarAutoHideDelayMillis() { | ||
return AUTO_HIDE_SCROLLBAR_DELAY_MILLIS; | ||
} | ||
|
||
@Override | ||
public void showPopup(@NonNull View popupView) { | ||
|
||
if (mShowingPopup) { | ||
return; | ||
} | ||
mShowingPopup = true; | ||
|
||
popupView.animate() | ||
.alpha(1) | ||
.setDuration(SHOW_DURATION_MILLIS) | ||
.start(); | ||
} | ||
|
||
@Override | ||
public void hidePopup(@NonNull View popupView) { | ||
|
||
if (!mShowingPopup) { | ||
return; | ||
} | ||
mShowingPopup = false; | ||
|
||
popupView.animate() | ||
.alpha(0) | ||
.setDuration(HIDE_DURATION_MILLIS) | ||
.start(); | ||
} | ||
} |
Oops, something went wrong.