Skip to content

Commit

Permalink
升级 Java 版本
Browse files Browse the repository at this point in the history
将 zhanghai/AndroidFastScroll 添加为子模块以确保 Java 版本的升级(修复资源引用错误,未做其它改动)
  • Loading branch information
Super12138 committed Jan 1, 2025
1 parent eb2adf5 commit d3249dd
Show file tree
Hide file tree
Showing 34 changed files with 2,641 additions and 9 deletions.
12 changes: 5 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_18
targetCompatibility = JavaVersion.VERSION_18
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "18"
}
buildFeatures {
viewBinding = true
Expand Down Expand Up @@ -89,10 +89,8 @@ dependencies {
implementation(libs.androidx.room.ktx)
annotationProcessor(libs.androidx.room.compiler)
ksp(libs.androidx.room.compiler)
// Room Backup
// implementation(libs.room.backup)
// Fast Scroll
implementation(libs.fast.scroll)
// FastScroll
implementation(project(":fastscroll"))
// Test
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.android.library) apply false
}
1 change: 1 addition & 0 deletions fastscroll/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
42 changes: 42 additions & 0 deletions fastscroll/build.gradle.kts
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 added fastscroll/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions fastscroll/proguard-rules.pro
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
19 changes: 19 additions & 0 deletions fastscroll/src/main/AndroidManifest.xml
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 />
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;
}
}
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();
}
}
Loading

0 comments on commit d3249dd

Please sign in to comment.