diff --git a/README.md b/README.md index 35af04eac..4a1c6b846 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ [![License](https://img.shields.io/badge/License%20-Apache%202-337ab7.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![Arsenal](https://img.shields.io/badge/Arsenal%20-%20SmartRefresh-4cae4c.svg)](https://android-arsenal.com/details/1/6001) -[![Maven](https://img.shields.io/badge/%20Maven%20-2.0.5-5bc0de.svg)](https://s01.oss.sonatype.org/#nexus-search;quick~refresh-layout-kernel) +[![Maven](https://img.shields.io/badge/%20Maven%20-3.0.0-5bc0de.svg)](https://s01.oss.sonatype.org/#nexus-search;quick~refresh-layout-kernel) [![MinSdk](https://img.shields.io/badge/%20MinSdk%20-%2012%2B%20-f0ad4e.svg)](https://android-arsenal.com/api?level=12) -[![Methods](https://img.shields.io/badge/Methods%20%7C%20Size%20-%20784%20%7C%20121%20KB-d9534f.svg)](http://www.methodscount.com/?lib=com.scwang.smartrefresh%3ASmartRefreshLayout%3A1.0.4) +[![Methods](https://img.shields.io/badge/Methods%20%7C%20Size%20-%20784%20%7C%20121%20KB-d9534f.svg)](http://www.methodscount.com/?lib=io.github.scwang90:refresh%3ASmartRefreshLayout%3A1.0.4) ## [English](README_EN.md) | 中文 @@ -15,9 +15,13 @@ SmartRefreshLayout以打造一个强大,稳定,成熟的下拉刷新框架 其他第三方的 [Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)、[TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout) 。 还集成了各种炫酷的 Header 和 Footer。 +## IOS版本 + +IOS版本:[链接](https://github.com/scwang90/SmartRefreshControl) + ## 国内加速 -github 由于你懂的原因,下载速度缓慢,图片也无法查看,可以跳转 [国内镜像](https://gitee.com/scwang90/SmartRefreshLayout) +github 由于你懂的原因,下载速度缓慢,图片也无法查看,可以跳转 [Gitee镜像](https://gitee.com/scwang90/SmartRefreshLayout) ## 特点功能: @@ -35,6 +39,7 @@ github 由于你懂的原因,下载速度缓慢,图片也无法查看,可 - 支持 Header 和 Footer 交换混用 - 支持 AndroidX - 支持[横向刷新](https://github.com/scwang90/SmartRefreshHorizontal) + - 支持[IOS](https://github.com/scwang90/SmartRefreshControl) ## 传送门 @@ -112,33 +117,43 @@ V2.x 版本已经把依赖库拆分成8个包啦,用到的时候自行引用 - refresh-footer-ball 球脉冲加载 - refresh-footer-classics 经典加载 +> 注:在`Demo`中有些炫酷的 `Header`,他们并不具有实用性,所以没有打包上传仓库,所以无法直接添加依赖。 +如果你确实想要在`App`中集成它们,请自行找到对应个 `tag` 的分支,把对应版本的`Header`源码拷贝到自己的项目中,作为自定义Header来使用。 + +> 需要源码引用的`Header`如下: + +> [BezierCircleHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/BezierCircleHeader.java) +[DeliveryHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/DeliveryHeader.java) +[DropBoxHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/DropBoxHeader.java) +[FlyRefreshHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/FlyRefreshHeader.java) +[FunGameBattleCityHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameBattleCityHeader.java) +[FunGameHitBlockHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameHitBlockHeader.java) +[PhoenixHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/PhoenixHeader.java) +[StoreHouseHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/StoreHouseHeader.java) +[TaurusHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/TaurusHeader.java) +[WaterDropHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/WaterDropHeader.java) +[WaveSwipeHeader](refresh-header/src/main/java/com/scwang/smart/refresh/header/WaveSwipeHeader.java) + + ## 简单用例 #### 1.在 build.gradle 中添加依赖 +> 注:3.x 版本已经发布,主要升级为使用 `androidx` 替换 `support`, 并且目前尚未添加新功能, 如果你还需要使用 support 请使用 2.x 版本。 ```gradle implementation 'androidx.appcompat:appcompat:1.0.0' //必须 1.0.0 以上 -implementation 'io.github.scwang90:refresh-layout-kernel:2.0.5' //核心必须依赖 -implementation 'io.github.scwang90:refresh-header-classics:2.0.5' //经典刷新头 -implementation 'io.github.scwang90:refresh-header-radar:2.0.5' //雷达刷新头 -implementation 'io.github.scwang90:refresh-header-falsify:2.0.5' //虚拟刷新头 -implementation 'io.github.scwang90:refresh-header-material:2.0.5' //谷歌刷新头 -implementation 'io.github.scwang90:refresh-header-two-level:2.0.5' //二级刷新头 -implementation 'io.github.scwang90:refresh-footer-ball:2.0.5' //球脉冲加载 -implementation 'io.github.scwang90:refresh-footer-classics:2.0.5' //经典加载 +implementation 'io.github.scwang90:refresh-layout-kernel:3.0.0-alpha' //核心必须依赖 +implementation 'io.github.scwang90:refresh-header-classics:3.0.0-alpha' //经典刷新头 +implementation 'io.github.scwang90:refresh-header-radar:3.0.0-alpha' //雷达刷新头 +implementation 'io.github.scwang90:refresh-header-falsify:3.0.0-alpha' //虚拟刷新头 +implementation 'io.github.scwang90:refresh-header-material:3.0.0-alpha' //谷歌刷新头 +implementation 'io.github.scwang90:refresh-header-two-level:3.0.0-alpha' //二级刷新头 +implementation 'io.github.scwang90:refresh-footer-ball:3.0.0-alpha' //球脉冲加载 +implementation 'io.github.scwang90:refresh-footer-classics:3.0.0-alpha' //经典加载 ``` - -如果使用 AndroidX 先在 gradle.properties 中添加,两行都不能少噢~ - -``` -android.useAndroidX=true -android.enableJetifier=true - -``` - #### 2.在XML布局文件中添加 SmartRefreshLayout ```xml @@ -149,7 +164,7 @@ android.enableJetifier=true - Please note that in the `Demo`, there are some cool `Headers` that are not practical, so they have not been packaged and uploaded to the repository, and thus cannot be directly added as dependencies. +If you indeed want to integrate them into your `App`, please find the corresponding branch for each `tag`, copy the source code of the corresponding version of the `Header` into your own project, and use it as a custom `Header`. + +> The `Headers` that require source code reference are as follows: + ## Usage #### 1.Add a gradle dependency. -V 2.x changed the package name relative to 1.x, such as `com.scwang.smartrefresh` to `com.scwang.smart.refresh`. -It is suggested that in the new project, if the old project is upgraded, -the package name should be replaced, which is more troublesome. -But the main change is to subcontract SmartRefreshLayout to reduce unnecessary dependencies and avoid code redundancy. -However, there is no subcontracting to SmartRefreshHeader. -There are more than ten headers in it. -It is recommended that you copy the source code into the project whenever you need to use it. +> Please note: Version 3.x has been released, with the main upgrade being the replacement of `support` with `androidx`, and no new features have been added at this time. If you still need to use `support`, please use version 2.x. + ``` // Note: There will be no default Header and Footer after subcontracting. It needs to be added manually! -implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3' //core -implementation 'com.scwang.smart:refresh-header-classics:2.0.3' //ClassicsHeader -implementation 'com.scwang.smart:refresh-header-radar:2.0.3' //BezierRadarHeader -implementation 'com.scwang.smart:refresh-header-falsify:2.0.3' //FalsifyHeader -implementation 'com.scwang.smart:refresh-header-material:2.0.3' //MaterialHeader -implementation 'com.scwang.smart:refresh-header-two-level:2.0.3' //TwoLevelHeader -implementation 'com.scwang.smart:refresh-footer-ball:2.0.3' //BallPulseFooter -implementation 'com.scwang.smart:refresh-footer-classics:2.0.3' //ClassicsFooter + +// To search lastest version by https://search.maven.org/search?q=g:io.github.scwang90 +implementation 'io.github.scwang90:refresh-layout-kernel:3.0.0-alpha' //core +implementation 'io.github.scwang90:refresh-header-classics:3.0.0-alpha' //ClassicsHeader +implementation 'io.github.scwang90:refresh-header-radar:3.0.0-alpha' //BezierRadarHeader +implementation 'io.github.scwang90:refresh-header-falsify:3.0.0-alpha' //FalsifyHeader +implementation 'io.github.scwang90:refresh-header-material:3.0.0-alpha' //MaterialHeader +implementation 'io.github.scwang90:refresh-header-two-level:3.0.0-alpha' //TwoLevelHeader +implementation 'io.github.scwang90:refresh-footer-ball:3.0.0-alpha' //BallPulseFooter +implementation 'io.github.scwang90:refresh-footer-classics:3.0.0-alpha' //ClassicsFooter ``` - - - - If you use AndroidX, add it to gradle.properties @@ -146,7 +148,7 @@ android.enableJetifier=true - Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.scwang.refresh.layout", appContext.getPackageName()); + } +} diff --git a/app/src/androidTest/java/com/scwang/refreshlayout/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/scwang/refreshlayout/ExampleInstrumentedTest.java deleted file mode 100644 index 966b0d961..000000000 --- a/app/src/androidTest/java/com/scwang/refreshlayout/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.scwang.refreshlayout; - -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumentation test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.scwang.refreshlayout", appContext.getPackageName()); - } -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c9292d84b..cf5867a91 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + package="com.scwang.refresh.layout"> @@ -27,7 +27,8 @@ + android:label="@string/title_activity_index_main" + android:exported="true"> diff --git a/app/src/main/java/com/scwang/refreshlayout/App.java b/app/src/main/java/com/scwang/refresh/layout/App.java similarity index 67% rename from app/src/main/java/com/scwang/refreshlayout/App.java rename to app/src/main/java/com/scwang/refresh/layout/App.java index 6cd64651f..abfe3f9d8 100644 --- a/app/src/main/java/com/scwang/refreshlayout/App.java +++ b/app/src/main/java/com/scwang/refresh/layout/App.java @@ -1,21 +1,21 @@ -package com.scwang.refreshlayout; +package com.scwang.refresh.layout; import android.app.Application; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatDelegate; -import com.scwang.refreshlayout.util.DynamicTimeFormat; -import com.scwang.smartrefresh.layout.SmartRefreshLayout; -import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator; -import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator; -import com.scwang.smartrefresh.layout.api.DefaultRefreshInitializer; -import com.scwang.smartrefresh.layout.api.RefreshFooter; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.footer.ClassicsFooter; -import com.scwang.smartrefresh.layout.header.ClassicsHeader; -import com.squareup.leakcanary.LeakCanary; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatDelegate; + +import com.scwang.refresh.layout.util.DynamicTimeFormat; +import com.scwang.smart.refresh.layout.api.RefreshFooter; +import com.scwang.smart.refresh.layout.api.RefreshHeader; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator; +import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator; +import com.scwang.smart.refresh.layout.listener.DefaultRefreshInitializer; +import com.scwang.smart.refresh.layout.SmartRefreshLayout; +import com.scwang.smart.refresh.footer.ClassicsFooter; +import com.scwang.smart.refresh.header.ClassicsHeader; /** * @@ -62,11 +62,5 @@ public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull Refr @Override public void onCreate() { super.onCreate(); - if (LeakCanary.isInAnalyzerProcess(this)) { - // This process is dedicated to LeakCanary for heap analysis. - // You should not init your app in this process. - return; - } - LeakCanary.install(this); } } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/FragmentActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/FragmentActivity.java similarity index 84% rename from app/src/main/java/com/scwang/refreshlayout/activity/FragmentActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/FragmentActivity.java index 2a5346c9d..187a9561e 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/FragmentActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/FragmentActivity.java @@ -1,16 +1,17 @@ -package com.scwang.refreshlayout.activity; +package com.scwang.refresh.layout.activity; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; -import android.support.v7.app.AppCompatActivity; import android.widget.FrameLayout; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; + import java.util.HashMap; import java.util.Map; @@ -74,14 +75,13 @@ protected void replaceFragment() { transaction.commit(); } catch (Exception e) { e.printStackTrace(); -// AfExceptionHandler.handle(e, "AfFragmentActivity Fragment 类型错误:" + mFragmentClazz); } } // - private static Map typeCache = new HashMap<>(); + private static final Map> typeCache = new HashMap<>(); private Class getFragmentClass() throws ClassNotFoundException { - Class type = typeCache.get(mFragmentClazz); + Class type = typeCache.get(mFragmentClazz); if (type == null) { typeCache.put(mFragmentClazz, type = Class.forName(mFragmentClazz)); } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/IndexMainActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/IndexMainActivity.java similarity index 64% rename from app/src/main/java/com/scwang/refreshlayout/activity/IndexMainActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/IndexMainActivity.java index 70ce8d491..5f733aafc 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/IndexMainActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/IndexMainActivity.java @@ -1,26 +1,27 @@ -package com.scwang.refreshlayout.activity; +package com.scwang.refresh.layout.activity; import android.animation.ValueAnimator; import android.os.Bundle; -import android.support.annotation.IdRes; -import android.support.annotation.NonNull; -import android.support.design.widget.BottomNavigationView; -import android.support.design.widget.BottomNavigationView.OnNavigationItemSelectedListener; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.fragment.index.RefreshExampleFragment; -import com.scwang.refreshlayout.fragment.index.RefreshPracticeFragment; -import com.scwang.refreshlayout.fragment.index.RefreshStylesFragment; -import com.scwang.refreshlayout.util.StatusBarUtil; +import androidx.annotation.IdRes; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; +import androidx.viewpager2.adapter.FragmentStateAdapter; +import androidx.viewpager2.widget.ViewPager2; + +import com.google.android.material.bottomnavigation.BottomNavigationView; +import com.google.android.material.navigation.NavigationBarView; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.fragment.index.RefreshExampleFragment; +import com.scwang.refresh.layout.fragment.index.RefreshPracticeFragment; +import com.scwang.refresh.layout.fragment.index.RefreshStylesFragment; +import com.scwang.refresh.layout.util.StatusBarUtil; import java.lang.reflect.Field; -public class IndexMainActivity extends AppCompatActivity implements OnNavigationItemSelectedListener { +public class IndexMainActivity extends AppCompatActivity implements NavigationBarView.OnItemSelectedListener { private enum TabFragment { practice(R.id.navigation_practice, RefreshPracticeFragment.class), @@ -66,31 +67,39 @@ public static void onDestroy() { } } + private ViewPager2 mViewPager; + private FragmentStateAdapter mPageAdapter; + private ViewPager2.OnPageChangeCallback mPageChangedCallback; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_index_main); final BottomNavigationView navigation = findViewById(R.id.navigation); - navigation.setOnNavigationItemSelectedListener(this); + navigation.setOnItemSelectedListener(this); - ViewPager viewPager = findViewById(R.id.content); - viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) { + this.mPageChangedCallback = new ViewPager2.OnPageChangeCallback() { @Override - public int getCount() { - return TabFragment.values().length; + public void onPageSelected(int position) { + navigation.setSelectedItemId(TabFragment.values()[position].menuId); } + }; + this.mPageAdapter = new FragmentStateAdapter(this) { @Override - public Fragment getItem(int position) { - return TabFragment.values()[position].fragment(); + public int getItemCount() { + return TabFragment.values().length; } - }); - viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){ + @NonNull @Override - public void onPageSelected(int position) { - navigation.setSelectedItemId(TabFragment.values()[position].menuId); + public Fragment createFragment(int position) { + return TabFragment.values()[position].fragment(); } - }); + }; + + this.mViewPager = findViewById(R.id.content); + this.mViewPager.setAdapter(this.mPageAdapter); + this.mViewPager.registerOnPageChangeCallback(this.mPageChangedCallback); //状态栏透明和间距处理 StatusBarUtil.immersive(this, 0xff000000, 0.1f); @@ -100,9 +109,7 @@ public void onPageSelected(int position) { Field field = ValueAnimator.class.getDeclaredField("sDurationScale"); field.setAccessible(true); field.set(ValueAnimator.class, 1); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { + } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } } @@ -110,12 +117,13 @@ public void onPageSelected(int position) { @Override protected void onDestroy() { super.onDestroy(); + mViewPager.unregisterOnPageChangeCallback(mPageChangedCallback); TabFragment.onDestroy(); } @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { - ((ViewPager)findViewById(R.id.content)).setCurrentItem(TabFragment.from(item.getItemId()).ordinal()); + mViewPager.setCurrentItem(TabFragment.from(item.getItemId()).ordinal()); // getSupportFragmentManager() // .beginTransaction() // .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignCodeExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/AssignCodeExampleActivity.java similarity index 70% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/AssignCodeExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/AssignCodeExampleActivity.java index c277547e4..33f93849f 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignCodeExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/AssignCodeExampleActivity.java @@ -1,17 +1,18 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import com.scwang.refreshlayout.R; -import com.scwang.smartrefresh.header.MaterialHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.RefreshState; -import com.scwang.smartrefresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.footer.BallPulseFooter; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.smart.refresh.header.MaterialHeader; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.constant.RefreshState; +import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.footer.BallPulseFooter; +import com.scwang.smart.refresh.layout.simple.SimpleMultiListener; /** * 在Java代码中指定Header和Footer @@ -43,15 +44,13 @@ protected void onCreate(Bundle savedInstanceState) { if (isFirstEnter) { isFirstEnter = false; -// //触发上拉加载 -// mRefreshLayout.autoLoadMore(250, 250, 1.5f); //通过多功能监听接口实现 在第一次加载完成之后 自动刷新 - refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener(){ + refreshLayout.setOnMultiListener(new SimpleMultiListener(){ @Override public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) { if (oldState == RefreshState.LoadFinish && newState == RefreshState.None) { refreshLayout.autoRefresh(); - refreshLayout.setOnMultiPurposeListener(null); + refreshLayout.setOnMultiListener(null); } } @Override diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignDefaultExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/AssignDefaultExampleActivity.java similarity index 76% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/AssignDefaultExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/AssignDefaultExampleActivity.java index 2e2a184ab..1365f3471 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignDefaultExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/AssignDefaultExampleActivity.java @@ -1,24 +1,25 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.content.Context; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.util.DynamicTimeFormat; -import com.scwang.smartrefresh.layout.SmartRefreshLayout; -import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator; -import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator; -import com.scwang.smartrefresh.layout.api.RefreshFooter; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.RefreshState; -import com.scwang.smartrefresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.footer.ClassicsFooter; -import com.scwang.smartrefresh.layout.header.ClassicsHeader; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.util.DynamicTimeFormat; +import com.scwang.smart.refresh.layout.SmartRefreshLayout; +import com.scwang.smart.refresh.layout.api.RefreshFooter; +import com.scwang.smart.refresh.layout.api.RefreshHeader; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.constant.RefreshState; +import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.footer.ClassicsFooter; +import com.scwang.smart.refresh.header.ClassicsHeader; +import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator; +import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator; +import com.scwang.smart.refresh.layout.simple.SimpleMultiListener; /** * 全局指定默认的Header和Footer @@ -44,16 +45,14 @@ protected void onCreate(Bundle savedInstanceState) { final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout); if (isFirstEnter) { isFirstEnter = false; -// //触发上拉加载 -// mRefreshLayout.autoLoadMore(); //通过多功能监听接口实现 在第一次加载完成之后 自动刷新 - refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener(){ + refreshLayout.setOnMultiListener(new SimpleMultiListener(){ @Override public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) { if (oldState == RefreshState.LoadFinish && newState == RefreshState.None) { refreshLayout.autoRefresh(); - refreshLayout.setOnMultiPurposeListener(null); + refreshLayout.setOnMultiListener(null); } } @Override diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignXmlExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/AssignXmlExampleActivity.java similarity index 71% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/AssignXmlExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/AssignXmlExampleActivity.java index b31e904c8..c3a7dfa16 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/AssignXmlExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/AssignXmlExampleActivity.java @@ -1,14 +1,15 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import com.scwang.refreshlayout.R; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.RefreshState; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.constant.RefreshState; +import com.scwang.smart.refresh.layout.simple.SimpleMultiListener; /** * 在XML中指定Header和Footer @@ -32,15 +33,13 @@ protected void onCreate(Bundle savedInstanceState) { final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout); if (isFirstEnter) { isFirstEnter = false; -// //触发上拉加载 -// mRefreshLayout.autoLoadMore(250, 250, 1.5f); //通过多功能监听接口实现 在第一次加载完成之后 自动刷新 - refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener(){ + refreshLayout.setOnMultiListener(new SimpleMultiListener(){ @Override public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) { if (oldState == RefreshState.LoadFinish && newState == RefreshState.None) { refreshLayout.autoRefresh(); - refreshLayout.setOnMultiPurposeListener(null); + refreshLayout.setOnMultiListener(null); } } @Override diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/BasicExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/BasicExampleActivity.java similarity index 85% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/BasicExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/BasicExampleActivity.java index 25981c633..cbd10db81 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/BasicExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/BasicExampleActivity.java @@ -1,22 +1,23 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.os.Bundle; -import android.support.design.widget.BottomSheetDialog; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AbsListView; import android.widget.ListView; import android.widget.Toast; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshFooter; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.footer.ClassicsFooter; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.bottomsheet.BottomSheetDialog; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.footer.ClassicsFooter; +import com.scwang.smart.refresh.layout.api.RefreshFooter; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.Arrays; import java.util.Collection; @@ -35,7 +36,7 @@ public class BasicExampleActivity extends AppCompatActivity { private final Random random = new Random(); private BaseRecyclerAdapter mAdapter; private LoadingLayout mLoadingLayout; - private com.scwang.smartrefresh.layout.api.RefreshLayout mRefreshLayout; + private RefreshLayout mRefreshLayout; @Override protected void onCreate(Bundle savedInstanceState) { @@ -92,7 +93,7 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun mAdapter.setOnItemClickListener((parent, view, position, id) -> { BottomSheetDialog dialog=new BottomSheetDialog(BasicExampleActivity.this); View dialogView = View.inflate(getBaseContext(), R.layout.activity_example_basic, null); - com.scwang.smartrefresh.layout.api.RefreshLayout refreshLayout1 = dialogView.findViewById(R.id.refreshLayout); + RefreshLayout refreshLayout1 = dialogView.findViewById(R.id.refreshLayout); RecyclerView recyclerView = new RecyclerView(getBaseContext()); recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext())); recyclerView.setAdapter(mAdapter); @@ -105,12 +106,12 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun //点击测试 RefreshFooter footer = mRefreshLayout.getRefreshFooter(); - if (footer instanceof com.scwang.smartrefresh.layout.footer.ClassicsFooter) { + if (footer instanceof ClassicsFooter) { mRefreshLayout.getRefreshFooter().getView().findViewById(ClassicsFooter.ID_TEXT_TITLE).setOnClickListener(v -> Toast.makeText(getBaseContext(), "点击测试", Toast.LENGTH_SHORT).show()); } } - private void loadMore(com.scwang.smartrefresh.layout.api.RefreshLayout layout) { + private void loadMore(RefreshLayout layout) { layout.getLayout().postDelayed(() -> { if (random.nextBoolean()) { //如果刷新成功 @@ -126,6 +127,7 @@ private void loadMore(com.scwang.smartrefresh.layout.api.RefreshLayout layout) { } else { //刷新失败 layout.finishLoadMore(false); + Toast.makeText(getApplication(), "演示加载失败", Toast.LENGTH_SHORT).show(); } }, 2000); } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/CustomExampleActivity.java similarity index 91% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/CustomExampleActivity.java index 85f080b57..3946699a7 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/CustomExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/CustomExampleActivity.java @@ -1,10 +1,7 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.content.Context; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; @@ -14,9 +11,13 @@ import android.widget.Space; import android.widget.TextView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; import com.scwang.smart.drawable.ProgressDrawable; import com.scwang.smart.refresh.classics.ArrowDrawable; import com.scwang.smart.refresh.layout.api.RefreshHeader; @@ -170,15 +171,6 @@ public void onMoving(boolean isDragging, float percent, int offset, int height, } -// @Override -// public void onPulling(float percent, int offset, int height, int maxDragHeight) { -// -// } -// @Override -// public void onReleasing(float percent, int offset, int height, int maxDragHeight) { -// -// } - @Override public void onReleased(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) { @@ -193,5 +185,10 @@ public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) { public boolean isSupportHorizontalDrag() { return false; } + + @Override + public boolean autoOpen(int duration, float dragRate, boolean animationOnly) { + return false; + } } } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/I18nExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/I18nExampleActivity.java similarity index 71% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/I18nExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/I18nExampleActivity.java index b12967a1e..e75af8beb 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/I18nExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/I18nExampleActivity.java @@ -1,25 +1,25 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; import android.util.DisplayMetrics; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.header.ClassicsHeader; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.header.ClassicsHeader; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; import java.util.ArrayList; import java.util.Arrays; @@ -31,11 +31,11 @@ public class I18nExampleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - i1(R.string.item_example_i18n_system), - i2(R.string.item_example_i18n_chinese), - i3(R.string.item_example_i18n_english), + LanguageSystem(R.string.item_example_i18n_system), + LanguageChinese(R.string.item_example_i18n_chinese), + LanguageEnglish(R.string.item_example_i18n_english), ; - public int nameId; + public final int nameId; Item(@StringRes int nameId) { this.nameId = nameId; } @@ -76,14 +76,14 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - switch (Item.values()[position % Item.values().length].nameId) { - case R.string.item_example_i18n_system: + switch (Item.values()[position % Item.values().length]) { + case LanguageSystem: changeAppLanguage(Locale.getDefault()); break; - case R.string.item_example_i18n_chinese: + case LanguageChinese: changeAppLanguage(Locale.CHINESE); break; - case R.string.item_example_i18n_english: + case LanguageEnglish: changeAppLanguage(Locale.ENGLISH); break; } @@ -93,11 +93,7 @@ private void changeAppLanguage(Locale locale) { Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { - conf.locale = locale; - } else { - conf.setLocale(locale); - } + conf.setLocale(locale); res.updateConfiguration(conf, dm); startActivity(new Intent(this, getClass())); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/ListenerExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/ListenerExampleActivity.java similarity index 65% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/ListenerExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/ListenerExampleActivity.java index 097fb76c1..1461d5b95 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/ListenerExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/ListenerExampleActivity.java @@ -1,18 +1,19 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; import android.text.method.ScrollingMovementMethod; import android.widget.TextView; -import com.scwang.refreshlayout.R; -import com.scwang.smartrefresh.layout.api.RefreshFooter; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.RefreshState; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.smart.refresh.layout.api.RefreshFooter; +import com.scwang.smart.refresh.layout.api.RefreshHeader; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.constant.RefreshState; +import com.scwang.smart.refresh.layout.simple.SimpleMultiListener; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -28,11 +29,7 @@ public class ListenerExampleActivity extends AppCompatActivity { private TextView mTvContent; private String mHeaderMoving; -// private String mHeaderPulling; -// private String mHeaderReleasing; private String mFooterMoving; -// private String mFooterPulling; -// private String mFooterReleasing; private String mFooterStartAnimator; private String mHeaderStartAnimator; private String mFooterFinish; @@ -55,7 +52,7 @@ protected void onCreate(Bundle savedInstanceState) { mTvContent.setMovementMethod(ScrollingMovementMethod.getInstance()); final RefreshLayout refreshLayout = findViewById(R.id.refreshLayout); - refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() { + refreshLayout.setOnMultiListener(new SimpleMultiListener() { @Override public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) { @@ -65,22 +62,6 @@ public void onHeaderMoving(RefreshHeader header, boolean isDragging, float perce updateContent(); } -// @Override -// public void onHeaderPulling(@NonNull RefreshHeader header, float percent, int offset, int headerHeight, int maxDragHeight) { -// mHeaderPulling = String.format(Locale.CHINA, "%s\npercent=%.02f offset=%03d\nheight=%03d extend=%03d", -// FORMAT.format(new Date()), -// percent,offset,headerHeight,maxDragHeight); -// updateContent(); -// } -// -// @Override -// public void onHeaderReleasing(@NonNull RefreshHeader header, float percent, int offset, int headerHeight, int maxDragHeight) { -// mHeaderReleasing = String.format(Locale.CHINA, "%s\npercent=%.02f offset=%03d\nheight=%03d extend=%03d", -// FORMAT.format(new Date()), -// percent,offset,headerHeight,maxDragHeight); -// updateContent(); -// } - @Override public void onHeaderStartAnimator(@NonNull RefreshHeader header, int headerHeight, int maxDragHeight) { mHeaderStartAnimator = String.format(Locale.CHINA, "%s\nheight=%03d extend=%03d", @@ -103,22 +84,6 @@ public void onFooterMoving(RefreshFooter footer, boolean isDragging, float perce updateContent(); } -// @Override -// public void onFooterPulling(@NonNull RefreshFooter footer, float percent, int offset, int footerHeight, int maxDragHeight) { -// mFooterPulling = String.format(Locale.CHINA, "%s\npercent=%.02f\noffset=%03d height=%03d\nextend=%03d", -// FORMAT.format(new Date()), -// percent,offset,footerHeight,maxDragHeight); -// updateContent(); -// } -// -// @Override -// public void onFooterReleasing(@NonNull RefreshFooter footer, float percent, int offset, int footerHeight, int maxDragHeight) { -// mFooterReleasing = String.format(Locale.CHINA, "%s\npercent=%.02f\noffset=%03d height=%03d\nextend=%03d", -// FORMAT.format(new Date()), -// percent,offset,footerHeight,maxDragHeight); -// updateContent(); -// } - @Override public void onFooterStartAnimator(@NonNull RefreshFooter footer, int footerHeight, int maxDragHeight) { mFooterStartAnimator = String.format(Locale.CHINA, "%s\nheight=%03d extend=%03d", @@ -170,26 +135,18 @@ private void updateContent() { mTvContent.setText(String.format(Locale.CHINA, "onStateChanged:%s\n\n" + "onHeaderMoving:%s\n\n" + -// "onHeaderPulling:%s\n\n" + -// "onHeaderReleasing:%s\n\n" + "onHeaderStartAnimator:%s\n\n" + "onHeaderFinish:%s\n\n" + "onFooterMoving:%s\n\n" + -// "onFooterPulling:%s\n\n" + -// "onFooterReleasing:%s\n\n" + "onFooterStartAnimator:%s\n\n" + "onFooterFinish:%s\n\n" + "onRefresh:%s\n\n" + "onLoadMore:%s\n\n", mStateChanged, mHeaderMoving, -// mHeaderPulling, -// mHeaderReleasing, mHeaderStartAnimator, mHeaderFinish, mFooterMoving, -// mFooterPulling, -// mFooterReleasing, mFooterStartAnimator, mFooterFinish, mRefresh, diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/NestedLayoutExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/NestedLayoutExampleActivity.java similarity index 85% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/NestedLayoutExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/NestedLayoutExampleActivity.java index 9c6d1acdf..656d61b0d 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/NestedLayoutExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/NestedLayoutExampleActivity.java @@ -1,22 +1,23 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.TextView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.text.DateFormat; import java.text.SimpleDateFormat; diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/OverScrollExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/OverScrollExampleActivity.java similarity index 73% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/OverScrollExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/OverScrollExampleActivity.java index 96b4d39f5..ebffe89bd 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/OverScrollExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/OverScrollExampleActivity.java @@ -1,14 +1,15 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; import android.webkit.WebView; import android.webkit.WebViewClient; -import com.scwang.refreshlayout.R; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; /** * 越界回弹使用演示 @@ -41,8 +42,6 @@ public void onPageCommitVisible(WebView view, String url) { refreshLayout.finishRefresh(); } }); -// TextView textView = findViewById(R.id.textView); -// textView.setMovementMethod(new ScrollingMovementMethod()); } } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/example/SnapHelperExampleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/example/SnapHelperExampleActivity.java similarity index 78% rename from app/src/main/java/com/scwang/refreshlayout/activity/example/SnapHelperExampleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/example/SnapHelperExampleActivity.java index a35c16496..09e74bf51 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/example/SnapHelperExampleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/example/SnapHelperExampleActivity.java @@ -1,22 +1,23 @@ -package com.scwang.refreshlayout.activity.example; +package com.scwang.refresh.layout.activity.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.PagerSnapHelper; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.SnapHelper; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Switch; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.PagerSnapHelper; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.SnapHelper; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener; import java.util.Arrays; import java.util.Collection; diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/BannerPracticeActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/practice/BannerPracticeActivity.java similarity index 92% rename from app/src/main/java/com/scwang/refreshlayout/activity/practice/BannerPracticeActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/practice/BannerPracticeActivity.java index 752b3f5ac..d0c6e8682 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/BannerPracticeActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/practice/BannerPracticeActivity.java @@ -1,29 +1,30 @@ -package com.scwang.refreshlayout.activity.practice; +package com.scwang.refresh.layout.activity.practice; import android.content.Context; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.bumptech.glide.Glide; import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.util.StatusBarUtil; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.util.StatusBarUtil; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; import com.youth.banner.Banner; import com.youth.banner.BannerConfig; import com.youth.banner.listener.OnBannerListener; @@ -35,8 +36,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; - +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 广告轮播-Banner */ @@ -82,13 +82,6 @@ public void run() { },2000); } }); -// refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { -// @Override -// public void onLoadMore(@NonNull RefreshLayout refreshLayout) { -// mAdapter.addData(movies); -// refreshLayout.finishLoadMoreWithNoMoreData(); -// } -// }); refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { @Override public void onLoadMore(@NonNull RefreshLayout rl) { diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/FeedListPracticeActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/practice/FeedListPracticeActivity.java similarity index 73% rename from app/src/main/java/com/scwang/refreshlayout/activity/practice/FeedListPracticeActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/practice/FeedListPracticeActivity.java index 32ef413b4..9c7f8e2d0 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/FeedListPracticeActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/practice/FeedListPracticeActivity.java @@ -1,11 +1,12 @@ -package com.scwang.refreshlayout.activity.practice; +package com.scwang.refresh.layout.activity.practice; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import com.scwang.refreshlayout.R; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.smart.refresh.layout.api.RefreshLayout; /** * 微博列表 diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/ProfilePracticeActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/practice/ProfilePracticeActivity.java similarity index 73% rename from app/src/main/java/com/scwang/refreshlayout/activity/practice/ProfilePracticeActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/practice/ProfilePracticeActivity.java index 8ca0c915d..b153ac4a7 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/ProfilePracticeActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/practice/ProfilePracticeActivity.java @@ -1,12 +1,12 @@ -package com.scwang.refreshlayout.activity.practice; +package com.scwang.refresh.layout.activity.practice; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.View; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.util.StatusBarUtil; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.util.StatusBarUtil; /** * 个人中心 diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/QQBrowserPracticeActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/practice/QQBrowserPracticeActivity.java similarity index 82% rename from app/src/main/java/com/scwang/refreshlayout/activity/practice/QQBrowserPracticeActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/practice/QQBrowserPracticeActivity.java index 327a609f0..50cc782a4 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/QQBrowserPracticeActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/practice/QQBrowserPracticeActivity.java @@ -1,15 +1,15 @@ -package com.scwang.refreshlayout.activity.practice; +package com.scwang.refresh.layout.activity.practice; import android.annotation.SuppressLint; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.util.StatusBarUtil; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.util.StatusBarUtil; import ezy.ui.layout.LoadingLayout; @@ -34,7 +34,6 @@ protected void onCreate(Bundle savedInstanceState) { webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient(){ @Override - @SuppressWarnings("deprecation") public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/RepastPracticeActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/practice/RepastPracticeActivity.java similarity index 87% rename from app/src/main/java/com/scwang/refreshlayout/activity/practice/RepastPracticeActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/practice/RepastPracticeActivity.java index 006cf76e3..bd50c46eb 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/RepastPracticeActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/practice/RepastPracticeActivity.java @@ -1,22 +1,23 @@ -package com.scwang.refreshlayout.activity.practice; +package com.scwang.refresh.layout.activity.practice; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Toast; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.util.StatusBarUtil; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener; -import com.scwang.smartrefresh.layout.util.SmartUtil; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.refresh.layout.util.StatusBarUtil; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener; +import com.scwang.smart.refresh.layout.util.SmartUtil; import java.util.Arrays; import java.util.Collection; diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/WebViewPracticeActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/practice/WebViewPracticeActivity.java similarity index 82% rename from app/src/main/java/com/scwang/refreshlayout/activity/practice/WebViewPracticeActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/practice/WebViewPracticeActivity.java index 5fd3d6d23..a7111e346 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/WebViewPracticeActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/practice/WebViewPracticeActivity.java @@ -1,17 +1,18 @@ -package com.scwang.refreshlayout.activity.practice; +package com.scwang.refresh.layout.activity.practice; import android.annotation.SuppressLint; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; import android.webkit.WebView; import android.webkit.WebViewClient; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.util.StatusBarUtil; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import com.scwang.smartrefresh.layout.util.SmartUtil; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.util.StatusBarUtil; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; +import com.scwang.smart.refresh.layout.util.SmartUtil; import java.util.Locale; diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/practice/WeiboPracticeActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/practice/WeiboPracticeActivity.java similarity index 61% rename from app/src/main/java/com/scwang/refreshlayout/activity/practice/WeiboPracticeActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/practice/WeiboPracticeActivity.java index 29e09cc05..4ac381b29 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/practice/WeiboPracticeActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/practice/WeiboPracticeActivity.java @@ -1,20 +1,21 @@ -package com.scwang.refreshlayout.activity.practice; +package com.scwang.refresh.layout.activity.practice; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; -import android.support.v4.widget.NestedScrollView; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.Toast; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.util.StatusBarUtil; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; -import com.scwang.smartrefresh.layout.util.SmartUtil; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.core.widget.NestedScrollView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.util.StatusBarUtil; +import com.scwang.smart.refresh.layout.api.RefreshHeader; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.simple.SimpleMultiListener; +import com.scwang.smart.refresh.layout.util.SmartUtil; /** * 微博主页 @@ -45,7 +46,7 @@ protected void onCreate(Bundle savedInstanceState) { findViewById(R.id.attention).setOnClickListener(view -> Toast.makeText(view.getContext(),"点击了关注",Toast.LENGTH_SHORT).show()); findViewById(R.id.leaveword).setOnClickListener(view -> Toast.makeText(view.getContext(),"点击了留言",Toast.LENGTH_SHORT).show()); - refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() { + refreshLayout.setOnMultiListener(new SimpleMultiListener() { @Override public void onRefresh(@NonNull RefreshLayout refreshLayout) { refreshLayout.finishRefresh(3000); @@ -61,25 +62,13 @@ public void onHeaderMoving(RefreshHeader header, boolean isDragging, float perce parallax.setTranslationY(mOffset - mScrollY); toolbar.setAlpha(1 - Math.min(percent, 1)); } -// @Override -// public void onHeaderPulling(@NonNull RefreshHeader header, float percent, int offset, int bottomHeight, int maxDragHeight) { -// mOffset = offset / 2; -// parallax.setTranslationY(mOffset - mScrollY); -// toolbar.setAlpha(1 - Math.min(percent, 1)); -// } -// @Override -// public void onHeaderReleasing(@NonNull RefreshHeader header, float percent, int offset, int bottomHeight, int maxDragHeight) { -// mOffset = offset / 2; -// parallax.setTranslationY(mOffset - mScrollY); -// toolbar.setAlpha(1 - Math.min(percent, 1)); -// } }); scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { private int lastScrollY = 0; - private int h = SmartUtil.dp2px(170); - private int color = ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)&0x00ffffff; + private final int h = SmartUtil.dp2px(170); + private final int color = ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)&0x00ffffff; @Override - public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { + public void onScrollChange(@NonNull NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { if (lastScrollY < h) { scrollY = Math.min(h, scrollY); mScrollY = Math.min(scrollY, h); diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierCircleStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/BezierCircleStyleActivity.java similarity index 65% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/BezierCircleStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/BezierCircleStyleActivity.java index 1d89a7352..03f561bfa 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierCircleStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/BezierCircleStyleActivity.java @@ -1,42 +1,45 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; + public class BezierCircleStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 内容不偏移(R.string.item_style_content_translation_off), - 内容跟随偏移(R.string.item_style_content_translation_on), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + ContentNoOffset("内容不偏移", R.string.item_style_content_translation_off), + ContentOffset("内容跟随偏移", R.string.item_style_content_translation_on), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -82,22 +85,22 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 内容不偏移: + case ContentNoOffset: mRefreshLayout.setEnableHeaderTranslationContent(false); break; - case 内容跟随偏移: + case ContentOffset: mRefreshLayout.setEnableHeaderTranslationContent(true); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -107,9 +110,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setBackgroundResource(colorPrimary); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierRadarStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/BezierRadarStyleActivity.java similarity index 64% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/BezierRadarStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/BezierRadarStyleActivity.java index c8ec2d7f6..7efb555a2 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/BezierRadarStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/BezierRadarStyleActivity.java @@ -1,45 +1,47 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.header.BezierRadarHeader; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.header.BezierRadarHeader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class BezierRadarStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 打开左右拖动(R.string.item_style_horizontal_drag_on), - 关闭左右拖动(R.string.item_style_horizontal_drag_off), - 内容不偏移(R.string.item_style_content_translation_off), - 内容跟随偏移(R.string.item_style_content_translation_on), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + DragLeftRight("打开左右拖动", R.string.item_style_horizontal_drag_on), + DragUpDown("关闭左右拖动", R.string.item_style_horizontal_drag_off), + ContentNoOffset("内容不偏移", R.string.item_style_content_translation_off), + ContentOffset("内容跟随偏移", R.string.item_style_content_translation_on), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -87,28 +89,28 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 内容不偏移: + case ContentNoOffset: mRefreshLayout.setEnableHeaderTranslationContent(false); break; - case 内容跟随偏移: + case ContentOffset: mRefreshLayout.setEnableHeaderTranslationContent(true); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; - case 打开左右拖动: + case DragLeftRight: mRefreshHeader.setEnableHorizontalDrag(true); break; - case 关闭左右拖动: + case DragUpDown: mRefreshHeader.setEnableHorizontalDrag(false); break; } @@ -118,9 +120,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setBackgroundResource(colorPrimary); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/ClassicsStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/ClassicsStyleActivity.java similarity index 55% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/ClassicsStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/ClassicsStyleActivity.java index 8909cba25..82e4081d9 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/ClassicsStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/ClassicsStyleActivity.java @@ -1,29 +1,28 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.graphics.drawable.VectorDrawableCompat; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; import android.widget.ImageView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.util.DynamicTimeFormat; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.header.ClassicsHeader; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.refresh.layout.util.DynamicTimeFormat; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.header.ClassicsHeader; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -34,27 +33,27 @@ import java.util.Random; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class ClassicsStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { - private BaseRecyclerAdapter mAdpater; - private enum Item { - 尺寸拉伸(R.string.item_style_spinner_scale), - 位置平移(R.string.item_style_spinner_translation), - 背后固定(R.string.item_style_spinner_behind), - 显示时间(R.string.item_style_spinner_update_on), - 隐藏时间(R.string.item_style_spinner_update_off), -// 加载更多(R.string.item_style_load_more), - 默认主题(R.string.item_style_theme_default_abstract), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + SizeScale("尺寸拉伸", R.string.item_style_spinner_scale), + PlaceMove("位置平移", R.string.item_style_spinner_translation), + FixedBehind("背后固定", R.string.item_style_spinner_behind), + TimeShow("显示时间", R.string.item_style_spinner_update_on), + TimeHide("隐藏时间", R.string.item_style_spinner_update_off), +// LoadMore("加载更多", R.string.item_style_load_more), + ThemeDefault("默认主题", R.string.item_style_theme_default_abstract), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -78,6 +77,7 @@ protected void onCreate(Bundle savedInstanceState) { int delta = new Random().nextInt(7 * 24 * 60 * 60 * 1000); mClassicsHeader = (ClassicsHeader)mRefreshLayout.getRefreshHeader(); + assert mClassicsHeader != null; mClassicsHeader.setLastUpdateTime(new Date(System.currentTimeMillis()-delta)); mClassicsHeader.setTimeFormat(new SimpleDateFormat("更新于 MM-dd HH:mm", Locale.CHINA)); mClassicsHeader.setTimeFormat(new DynamicTimeFormat("更新于 %s")); @@ -97,7 +97,7 @@ protected void onCreate(Bundle savedInstanceState) { List items = new ArrayList<>(); items.addAll(Arrays.asList(Item.values())); items.addAll(Arrays.asList(Item.values())); - recyclerView.setAdapter(mAdpater = new BaseRecyclerAdapter(items, simple_list_item_2,this) { + recyclerView.setAdapter(new BaseRecyclerAdapter(items, simple_list_item_2,this) { @Override protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { holder.text(android.R.id.text1, model.name()); @@ -114,79 +114,52 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position mRefreshLayout.autoRefresh(); } -// mRefreshLayout.autoRefresh();//开始刷新数据时无数据 -// mClassicsHeader.setFinishDuration(0);//关闭Header的完成延时 -// mRefreshLayout.setOnRefreshListener(new OnRefreshListener() { -// @Override -// public void onRefresh(@NonNull RefreshLayout refreshLayout) { -// //刷新启动一秒后 关闭刷新 -// refreshLayout.getLayout().postDelayed(()->{ -// refreshLayout.finishRefresh(); -// }, 1000); -// //启动刷新两秒后 添加数据 -// refreshLayout.getLayout().postDelayed(()->{ -// List items = new ArrayList<>(); -// items.addAll(Arrays.asList(Item.values())); -// items.addAll(Arrays.asList(Item.values())); -// mAdpater.refresh(items); -// }, 2000); -// } -// }); - } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 背后固定: + case FixedBehind: mClassicsHeader.setSpinnerStyle(SpinnerStyle.FixedBehind); mRefreshLayout.setPrimaryColors(0xff444444, 0xffffffff); - if (Build.VERSION.SDK_INT >= 21) { - mDrawableProgress.setTint(0xffffffff); - } else if (mDrawableProgress instanceof VectorDrawableCompat) { - ((VectorDrawableCompat) mDrawableProgress).setTint(0xffffffff); - } + mDrawableProgress.setTint(0xffffffff); /* * 由于是后面才设置,需要手动更改视图的位置 * 如果在 onCreate 或者 xml 中设置好[SpinnerStyle] 就不用手动调整位置了 */ mRefreshLayout.getLayout().bringChildToFront(mRecyclerView); break; - case 尺寸拉伸: + case SizeScale: mClassicsHeader.setSpinnerStyle(SpinnerStyle.values[1]); break; - case 位置平移: + case PlaceMove: mClassicsHeader.setSpinnerStyle(SpinnerStyle.Translate); break; - case 显示时间: + case TimeShow: mClassicsHeader.setEnableLastTime(true); break; - case 隐藏时间: + case TimeHide: mClassicsHeader.setEnableLastTime(false); break; - case 默认主题: + case ThemeDefault: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); mRefreshLayout.getLayout().setBackgroundResource(android.R.color.transparent); mRefreshLayout.setPrimaryColors(0, 0xff666666); - if (Build.VERSION.SDK_INT >= 21) { - mDrawableProgress.setTint(0xff666666); - } else if (mDrawableProgress instanceof VectorDrawableCompat) { - ((VectorDrawableCompat) mDrawableProgress).setTint(0xff666666); - } + mDrawableProgress.setTint(0xff666666); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; -// case 加载更多: +// case LoadMore: // mRefreshLayout.autoLoadMore(); // return; } @@ -196,12 +169,8 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setBackgroundResource(colorPrimary); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - mDrawableProgress.setTint(0xffffffff); - } else if (mDrawableProgress instanceof VectorDrawableCompat) { - ((VectorDrawableCompat) mDrawableProgress).setTint(0xffffffff); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); + mDrawableProgress.setTint(0xffffffff); } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/DeliveryStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/DeliveryStyleActivity.java similarity index 72% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/DeliveryStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/DeliveryStyleActivity.java index 0bee9b447..219ebe1ad 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/DeliveryStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/DeliveryStyleActivity.java @@ -1,40 +1,43 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Window; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static com.scwang.refreshlayout.R.layout.item_style_delivery; +import static com.scwang.refresh.layout.R.layout.item_style_delivery; public class DeliveryStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 默认主题(R.string.item_style_theme_default_abstract), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + ThemeDefault("默认主题", R.string.item_style_theme_default_abstract), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -47,9 +50,7 @@ private enum Item { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_style_delivery); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(0xfff0f0f0); - } + getWindow().setStatusBarColor(0xfff0f0f0); if (Build.VERSION.SDK_INT >= 23) { Window window = getWindow(); int systemUiVisibility = window.getDecorView().getSystemUiVisibility(); @@ -85,14 +86,12 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 默认主题: + case ThemeDefault: mToolbar.setBackgroundResource(android.R.color.white); mToolbar.setTitleTextColor(0xffbbbbbb); mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_gray_24dp); mRefreshLayout.setPrimaryColors(0xfff0f0f0, 0xffffffff); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(0xfff0f0f0); - } + getWindow().setStatusBarColor(0xfff0f0f0); if (Build.VERSION.SDK_INT >= 23) { Window window = getWindow(); int systemUiVisibility = window.getDecorView().getSystemUiVisibility(); @@ -100,16 +99,16 @@ public void onItemClick(AdapterView parent, View view, int position, long id) window.getDecorView().setSystemUiVisibility(systemUiVisibility); } break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -121,9 +120,7 @@ private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setTitleTextColor(ContextCompat.getColor(this, android.R.color.white)); mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); if (Build.VERSION.SDK_INT >= 23) { Window window = getWindow(); int systemUiVisibility = window.getDecorView().getSystemUiVisibility(); diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/DropBoxStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/DropBoxStyleActivity.java similarity index 56% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/DropBoxStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/DropBoxStyleActivity.java index 5733c3839..3062784d1 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/DropBoxStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/DropBoxStyleActivity.java @@ -1,53 +1,54 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class DropBoxStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 默认主题(R.string.item_style_theme_default_abstract), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), - - - 默认1主题(R.string.item_style_theme_default_abstract), - 橙色1主题(R.string.item_style_theme_orange_abstract), - 红色1主题(R.string.item_style_theme_red_abstract), - 绿色1主题(R.string.item_style_theme_green_abstract), - 蓝色1主题(R.string.item_style_theme_blue_abstract), - - - 默认2主题(R.string.item_style_theme_default_abstract), - 橙色2主题(R.string.item_style_theme_orange_abstract), - 红色2主题(R.string.item_style_theme_red_abstract), - 绿色2主题(R.string.item_style_theme_green_abstract), - 蓝色2主题(R.string.item_style_theme_blue_abstract), + ThemeDefault("默认主题", R.string.item_style_theme_default_abstract), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), + + + ThemeDefault1("默认主题1", R.string.item_style_theme_default_abstract), + ThemeOrange1("橙色主题1", R.string.item_style_theme_orange_abstract), + ThemeRed1("红色主题1", R.string.item_style_theme_red_abstract), + ThemeGreen1("绿色主题1", R.string.item_style_theme_green_abstract), + ThemeBlue1("蓝色主题1", R.string.item_style_theme_blue_abstract), + + ThemeDefault2("默认主题2", R.string.item_style_theme_default_abstract), + ThemeOrange2("橙色主题2", R.string.item_style_theme_orange_abstract), + ThemeRed2("红色主题2", R.string.item_style_theme_red_abstract), + ThemeGreen2("绿色主题2", R.string.item_style_theme_green_abstract), + ThemeBlue2("蓝色主题2", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -90,20 +91,20 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 默认主题: + case ThemeDefault: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); mRefreshLayout.setPrimaryColors(0xff283645, 0xff6ea9ff); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -113,9 +114,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setBackgroundResource(colorPrimary); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/FlyRefreshStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/FlyRefreshStyleActivity.java similarity index 86% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/FlyRefreshStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/FlyRefreshStyleActivity.java index 233f4643c..e22655694 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/FlyRefreshStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/FlyRefreshStyleActivity.java @@ -1,9 +1,7 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; -import android.animation.AnimatorSet; -import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; import android.content.res.ColorStateList; @@ -11,35 +9,34 @@ import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.OvalShape; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.design.widget.AppBarLayout; -import android.support.design.widget.CollapsingToolbarLayout; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.AccelerateInterpolator; -import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; -import android.view.animation.OvershootInterpolator; import android.widget.ImageView; import android.widget.TextView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.util.StatusBarUtil; -import com.scwang.smartrefresh.header.FlyRefreshHeader; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.util.StatusBarUtil; import com.scwang.smart.refresh.header.flyrefresh.FlyView; import com.scwang.smart.refresh.header.flyrefresh.MountainSceneView; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; -import com.scwang.smartrefresh.layout.util.SmartUtil; +import com.scwang.smart.refresh.layout.api.RefreshHeader; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; +import com.scwang.smart.refresh.layout.simple.SimpleMultiListener; +import com.scwang.smart.refresh.header.FlyRefreshHeader; +import com.scwang.smart.refresh.layout.util.SmartUtil; import java.text.DateFormat; import java.text.ParseException; @@ -48,8 +45,6 @@ import java.util.Date; import java.util.Locale; -import jp.wasabeef.recyclerview.animators.BaseItemAnimator; - public class FlyRefreshStyleActivity extends AppCompatActivity { private RecyclerView mListView; @@ -108,22 +103,12 @@ public void onAnimationEnd(Animator animation) { }); //设置 让 AppBarLayout 和 RefreshLayout 的滚动同步 并不保持 toolbar 位置不变 final AppBarLayout appBar = findViewById(R.id.appbar); - mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() { + mRefreshLayout.setOnMultiListener(new SimpleMultiListener() { @Override public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) { appBar.setTranslationY(offset); toolbar.setTranslationY(-offset); } -// @Override -// public void onHeaderPulling(@NonNull RefreshHeader header, float percent, int offset, int footerHeight, int maxDragHeight) { -// appBar.setTranslationY(offset); -// toolbar.setTranslationY(-offset); -// } -// @Override -// public void onHeaderReleasing(@NonNull RefreshHeader header, float percent, int offset, int footerHeight, int maxDragHeight) { -// appBar.setTranslationY(offset); -// toolbar.setTranslationY(-offset); -// } }); /*----------------------------------------------------------- * 关键代码-结束 @@ -143,7 +128,6 @@ public void onHeaderMoving(RefreshHeader header, boolean isDragging, float perce mListView = findViewById(R.id.recyclerView); mListView.setLayoutManager(mLayoutManager); mListView.setAdapter(mAdapter); - mListView.setItemAnimator(new SampleItemAnimator()); mToolbarLayout = findViewById(R.id.toolbarLayout); mActionButton = findViewById(R.id.fab); /* @@ -307,7 +291,7 @@ public static class ItemData { } } - public static class SampleItemAnimator extends BaseItemAnimator { + /*public static class SampleItemAnimator extends BaseItemAnimator { @Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) { @@ -341,7 +325,7 @@ protected void animateAddImpl(final RecyclerView.ViewHolder holder) { animator.start(); } - } + }*/ public static class ElasticOutInterpolator implements Interpolator { diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameBattleCityStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/FunGameBattleCityStyleActivity.java similarity index 67% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameBattleCityStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/FunGameBattleCityStyleActivity.java index 19836885f..f128a9e82 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameBattleCityStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/FunGameBattleCityStyleActivity.java @@ -1,41 +1,43 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class FunGameBattleCityStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 默认主题(R.string.item_style_theme_default_abstract), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + ThemeDefault("默认主题", R.string.item_style_theme_default_abstract), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -82,19 +84,19 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 默认主题: + case ThemeDefault: mRefreshLayout.setPrimaryColorsId(android.R.color.white, android.R.color.black); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -104,9 +106,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setBackgroundResource(colorPrimary); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameHitBlockStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/FunGameHitBlockStyleActivity.java similarity index 67% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameHitBlockStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/FunGameHitBlockStyleActivity.java index b2c404fb5..57c5ed5bc 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/FunGameHitBlockStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/FunGameHitBlockStyleActivity.java @@ -1,41 +1,43 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class FunGameHitBlockStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 默认主题(R.string.item_style_theme_default_abstract), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + ThemeDefault("默认主题", R.string.item_style_theme_default_abstract), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -83,19 +85,19 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 默认主题: + case ThemeDefault: mRefreshLayout.setPrimaryColorsId(android.R.color.white, android.R.color.black); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -105,9 +107,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setBackgroundResource(colorPrimary); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/MaterialStyleActivity.java similarity index 65% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/MaterialStyleActivity.java index 895ae767a..4237cc478 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/MaterialStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/MaterialStyleActivity.java @@ -1,45 +1,47 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.header.MaterialHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.header.MaterialHeader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class MaterialStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 打开背景(R.string.item_style_bezier_on), - 关闭背景(R.string.item_style_bezier_off), - 内容不偏移(R.string.item_style_content_translation_off), - 内容跟随偏移(R.string.item_style_content_translation_on), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + BackgroundOpen("打开背景", R.string.item_style_bezier_on), + BackgroundClose("关闭背景", R.string.item_style_bezier_off), + ContentNoOffset("内容不偏移", R.string.item_style_content_translation_off), + ContentOffset("内容跟随偏移", R.string.item_style_content_translation_on), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -88,28 +90,28 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 内容不偏移: + case ContentNoOffset: mRefreshLayout.setEnableHeaderTranslationContent(false); break; - case 内容跟随偏移: + case ContentOffset: mRefreshLayout.setEnableHeaderTranslationContent(true); break; - case 打开背景: + case BackgroundOpen: mMaterialHeader.setShowBezierWave(true); break; - case 关闭背景: + case BackgroundClose: mMaterialHeader.setShowBezierWave(false); break; - case 蓝色主题: + case ThemeThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -121,9 +123,7 @@ private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); mMaterialHeader.setProgressBackgroundColorSchemeResource(colorPrimary); mMaterialHeader.setColorSchemeResources(android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/PhoenixStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/PhoenixStyleActivity.java similarity index 73% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/PhoenixStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/PhoenixStyleActivity.java index c06c33998..e6b743e37 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/PhoenixStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/PhoenixStyleActivity.java @@ -1,46 +1,48 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; import android.content.res.ColorStateList; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.design.widget.AppBarLayout; -import android.support.design.widget.CollapsingToolbarLayout; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class PhoenixStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 折叠(R.string.item_style_app_bar_collapse), - 展开(R.string.item_style_app_bar_expand), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + Collapse("折叠", R.string.item_style_app_bar_collapse), + Expend("展开", R.string.item_style_app_bar_expand), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -116,26 +118,26 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 折叠: + case Collapse: mAppBarLayout.setExpanded(false, true); mAppBarLayout.setEnabled(false); mRecyclerView.setNestedScrollingEnabled(false); break; - case 展开: + case Expend: mAppBarLayout.setEnabled(true); mAppBarLayout.setExpanded(true, true); mRecyclerView.setNestedScrollingEnabled(true); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -149,9 +151,7 @@ private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); mActionButton.setBackgroundColor(ContextCompat.getColor(this, colorPrimaryDark)); mActionButton.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(this, colorPrimaryDark))); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/StoreHouseStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/StoreHouseStyleActivity.java similarity index 78% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/StoreHouseStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/StoreHouseStyleActivity.java index a3f0fad61..b0493d9a5 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/StoreHouseStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/StoreHouseStyleActivity.java @@ -1,47 +1,49 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; import android.graphics.Point; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.header.StoreHouseHeader; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshHeader; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.header.StoreHouseHeader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class StoreHouseStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 显示商标(R.string.item_style_store_house_brand), - 显示图标(R.string.item_style_store_house_icon), - 显示中文(R.string.item_style_store_house_chinese), - 显示英文(R.string.item_style_store_house_english), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + ShowSymbol("显示商标", R.string.item_style_store_house_brand), + ShowIcon("显示图标", R.string.item_style_store_house_icon), + ShowChinese("显示中文", R.string.item_style_store_house_chinese), + ShowEnglish("显示英文", R.string.item_style_store_house_english), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -87,44 +89,44 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 显示中文: { + case ShowChinese: { RefreshHeader refreshHeader = mRefreshLayout.getRefreshHeader(); if (refreshHeader instanceof StoreHouseHeader) { ((StoreHouseHeader) refreshHeader).initWithPointList(getPointList()); } break; } - case 显示英文: { + case ShowEnglish: { RefreshHeader refreshHeader = mRefreshLayout.getRefreshHeader(); if (refreshHeader instanceof StoreHouseHeader) { ((StoreHouseHeader) refreshHeader).initWithString("SmartRefresh"); } break; } - case 显示图标: { + case ShowIcon: { RefreshHeader refreshHeader = mRefreshLayout.getRefreshHeader(); if (refreshHeader instanceof StoreHouseHeader) { ((StoreHouseHeader) refreshHeader).initWithStringArray(R.array.storehouse); } break; } - case 显示商标: { + case ShowSymbol: { RefreshHeader refreshHeader = mRefreshLayout.getRefreshHeader(); if (refreshHeader instanceof StoreHouseHeader) { ((StoreHouseHeader) refreshHeader).initWithStringArray(R.array.akta); } break; } - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -134,9 +136,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setBackgroundResource(colorPrimary); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } private List getPointList() { diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/TaurusStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/TaurusStyleActivity.java similarity index 73% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/TaurusStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/TaurusStyleActivity.java index 3e335ef86..173503671 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/TaurusStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/TaurusStyleActivity.java @@ -1,46 +1,48 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; import android.content.res.ColorStateList; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.design.widget.AppBarLayout; -import android.support.design.widget.CollapsingToolbarLayout; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class TaurusStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 折叠(R.string.item_style_app_bar_collapse), - 展开(R.string.item_style_app_bar_expand), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + Collapse("折叠", R.string.item_style_app_bar_collapse), + Expend("展开", R.string.item_style_app_bar_expand), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -96,7 +98,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position mActionButton = findViewById(R.id.fab); mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { boolean misAppbarExpand = true; - View fab = findViewById(R.id.fab); + final View fab = findViewById(R.id.fab); @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { int scrollRange = appBarLayout.getTotalScrollRange(); @@ -116,26 +118,26 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 折叠: + case Collapse: mAppBarLayout.setExpanded(false, true); mAppBarLayout.setEnabled(false); mRecyclerView.setNestedScrollingEnabled(false); break; - case 展开: + case Expend: mAppBarLayout.setEnabled(true); mAppBarLayout.setExpanded(true, true); mRecyclerView.setNestedScrollingEnabled(true); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -149,9 +151,7 @@ private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); mActionButton.setBackgroundColor(ContextCompat.getColor(this, colorPrimaryDark)); mActionButton.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(this, colorPrimaryDark))); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/WaterDropStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/WaterDropStyleActivity.java similarity index 65% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/WaterDropStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/WaterDropStyleActivity.java index e57efabe3..82efc0869 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/WaterDropStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/WaterDropStyleActivity.java @@ -1,43 +1,45 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class WaterDropStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 内容不偏移(R.string.item_style_content_translation_off), - 内容跟随偏移(R.string.item_style_content_translation_on), - 默认主题(R.string.item_style_theme_default_abstract), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + ContentNoOffset("内容不偏移", R.string.item_style_content_translation_off), + ContentOffset("内容跟随偏移", R.string.item_style_content_translation_on), + ThemeDefault("默认主题", R.string.item_style_theme_default_abstract), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -83,26 +85,26 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 内容不偏移: + case ContentNoOffset: mRefreshLayout.setEnableHeaderTranslationContent(false); break; - case 内容跟随偏移: + case ContentOffset: mRefreshLayout.setEnableHeaderTranslationContent(true); break; - case 默认主题: + case ThemeDefault: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); mRefreshLayout.setPrimaryColorsId(android.R.color.darker_gray); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -112,9 +114,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setBackgroundResource(colorPrimary); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } } diff --git a/app/src/main/java/com/scwang/refreshlayout/activity/style/WaveSwipeStyleActivity.java b/app/src/main/java/com/scwang/refresh/layout/activity/style/WaveSwipeStyleActivity.java similarity index 66% rename from app/src/main/java/com/scwang/refreshlayout/activity/style/WaveSwipeStyleActivity.java rename to app/src/main/java/com/scwang/refresh/layout/activity/style/WaveSwipeStyleActivity.java index d8f98b2b0..9da77d409 100644 --- a/app/src/main/java/com/scwang/refreshlayout/activity/style/WaveSwipeStyleActivity.java +++ b/app/src/main/java/com/scwang/refresh/layout/activity/style/WaveSwipeStyleActivity.java @@ -1,42 +1,44 @@ -package com.scwang.refreshlayout.activity.style; +package com.scwang.refresh.layout.activity.style; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; public class WaveSwipeStyleActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private enum Item { - 内容不偏移(R.string.item_style_content_translation_off), - 内容跟随偏移(R.string.item_style_content_translation_on), - 橙色主题(R.string.item_style_theme_orange_abstract), - 红色主题(R.string.item_style_theme_red_abstract), - 绿色主题(R.string.item_style_theme_green_abstract), - 蓝色主题(R.string.item_style_theme_blue_abstract), + ContentNoOffset("内容不偏移", R.string.item_style_content_translation_off), + ContentOffset("内容跟随偏移", R.string.item_style_content_translation_on), + ThemeOrange("橙色主题", R.string.item_style_theme_orange_abstract), + ThemeRed("红色主题", R.string.item_style_theme_red_abstract), + ThemeGreen("绿色主题", R.string.item_style_theme_green_abstract), + ThemeBlue("蓝色主题", R.string.item_style_theme_blue_abstract), ; - public int nameId; - Item(@StringRes int nameId) { + public final String remark; + public final int nameId; + Item(String remark, @StringRes int nameId) { + this.remark = remark; this.nameId = nameId; } } @@ -83,22 +85,22 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { - case 内容不偏移: + case ContentNoOffset: mRefreshLayout.setEnableHeaderTranslationContent(false); break; - case 内容跟随偏移: + case ContentOffset: mRefreshLayout.setEnableHeaderTranslationContent(true); break; - case 蓝色主题: + case ThemeBlue: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; - case 绿色主题: + case ThemeGreen: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; - case 红色主题: + case ThemeRed: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; - case 橙色主题: + case ThemeOrange: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } @@ -108,9 +110,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setThemeColor(int colorPrimary, int colorPrimaryDark) { mToolbar.setBackgroundResource(colorPrimary); mRefreshLayout.setPrimaryColorsId(colorPrimary, android.R.color.white); - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); - } + getWindow().setStatusBarColor(ContextCompat.getColor(this, colorPrimaryDark)); } } diff --git a/app/src/main/java/com/scwang/refreshlayout/adapter/BaseRecyclerAdapter.java b/app/src/main/java/com/scwang/refresh/layout/adapter/BaseRecyclerAdapter.java similarity index 95% rename from app/src/main/java/com/scwang/refreshlayout/adapter/BaseRecyclerAdapter.java rename to app/src/main/java/com/scwang/refresh/layout/adapter/BaseRecyclerAdapter.java index 690f25f87..f408c51f2 100644 --- a/app/src/main/java/com/scwang/refreshlayout/adapter/BaseRecyclerAdapter.java +++ b/app/src/main/java/com/scwang/refresh/layout/adapter/BaseRecyclerAdapter.java @@ -1,16 +1,17 @@ -package com.scwang.refreshlayout.adapter; +package com.scwang.refresh.layout.adapter; import android.database.DataSetObservable; import android.database.DataSetObserver; -import android.support.annotation.LayoutRes; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListAdapter; +import androidx.annotation.LayoutRes; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -91,10 +92,6 @@ public void setOpenAnimationEnable(boolean enabled) { // private final DataSetObservable mDataSetObservable = new DataSetObservable(); -// public boolean hasStableIds() { -// return false; -// } - public void registerDataSetObserver(DataSetObserver observer) { mDataSetObservable.registerObserver(observer); } diff --git a/app/src/main/java/com/scwang/refreshlayout/adapter/SmartViewHolder.java b/app/src/main/java/com/scwang/refresh/layout/adapter/SmartViewHolder.java similarity index 94% rename from app/src/main/java/com/scwang/refreshlayout/adapter/SmartViewHolder.java rename to app/src/main/java/com/scwang/refresh/layout/adapter/SmartViewHolder.java index 391b72e86..5dc43844c 100644 --- a/app/src/main/java/com/scwang/refreshlayout/adapter/SmartViewHolder.java +++ b/app/src/main/java/com/scwang/refresh/layout/adapter/SmartViewHolder.java @@ -1,15 +1,16 @@ -package com.scwang.refreshlayout.adapter; +package com.scwang.refresh.layout.adapter; import android.content.res.Resources; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; import android.util.TypedValue; import android.view.View; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.StringRes; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; + @SuppressWarnings("UnusedReturnValue") public class SmartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/BottomSheetExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/BottomSheetExampleFragment.java similarity index 69% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/BottomSheetExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/BottomSheetExampleFragment.java index 32097853b..4b30a7b3c 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/BottomSheetExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/BottomSheetExampleFragment.java @@ -1,33 +1,34 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.design.widget.BottomSheetDialog; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.header.ClassicsHeader; -import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.bottomsheet.BottomSheetDialog; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.header.ClassicsHeader; +import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; import java.util.Arrays; import java.util.Collection; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 使用示例-BottomSheet @@ -38,6 +39,7 @@ public class BottomSheetExampleFragment extends Fragment { private BaseRecyclerAdapter mAdapter; @Override + @NonNull public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_example_bottom_sheet, container, false); } @@ -49,7 +51,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat root = onCreateView(LayoutInflater.from(getContext()), null, null); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout); refreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white)); @@ -61,7 +63,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat RecyclerView recyclerView = root.findViewById(R.id.recyclerView); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(root.getContext(), VERTICAL)); recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(initData(),simple_list_item_2) { @Override @@ -73,7 +75,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Void model, int position }); BottomSheetDialog dialog = new BottomSheetDialog(getContext()); - dialog.setOnDismissListener(dialog1 -> getActivity().finish()); + dialog.setOnDismissListener(dialog1 -> requireActivity().finish()); dialog.setContentView(root); dialog.setCancelable(false); dialog.show(); diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/DisallowInterceptExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/DisallowInterceptExampleFragment.java similarity index 85% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/DisallowInterceptExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/DisallowInterceptExampleFragment.java index b9f906a64..207f2f06d 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/DisallowInterceptExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/DisallowInterceptExampleFragment.java @@ -1,16 +1,22 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.annotation.SuppressLint; import android.content.Context; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.AppCompatTextView; -import android.support.v7.widget.Toolbar; import android.util.AttributeSet; -import android.view.*; -import com.scwang.refreshlayout.R; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewConfiguration; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatTextView; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; + +import com.scwang.refresh.layout.R; /** * A simple {@link Fragment} subclass. @@ -30,7 +36,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); } public static class MoveView extends AppCompatTextView { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/EmptyLayoutExampleFragment.java similarity index 73% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/EmptyLayoutExampleFragment.java index e328335f0..57f424d39 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/EmptyLayoutExampleFragment.java @@ -1,41 +1,42 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.RefreshState; -import com.scwang.smartrefresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.header.ClassicsHeader; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.constant.RefreshState; +import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.header.ClassicsHeader; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; +import com.scwang.smart.refresh.layout.simple.SimpleMultiListener; import java.util.Arrays; import ezy.ui.layout.LoadingLayout; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; -import static com.scwang.refreshlayout.R.id.recyclerView; -import static com.scwang.refreshlayout.R.id.refreshLayout; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; +import static com.scwang.refresh.layout.R.id.recyclerView; +import static com.scwang.refresh.layout.R.id.refreshLayout; /** * 使用示例-空布页面 @@ -48,8 +49,8 @@ public enum Item { NestedInner("内部嵌套", EmptyLayoutExampleFragmentInner.class), NestedOuter("外部嵌套", EmptyLayoutExampleFragmentOuter.class), ; - public String name; - public Class clazz; + public final String name; + public final Class clazz; Item(String name, Class clazz) { this.name = name; this.clazz = clazz; @@ -71,7 +72,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); mRefreshLayout = root.findViewById(refreshLayout); mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white)); @@ -80,7 +81,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat mRecyclerView = root.findViewById(recyclerView); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + mRecyclerView.addItemDecoration(new DividerItemDecoration(root.getContext(), VERTICAL)); mLoadingLayout = root.findViewById(R.id.loading); mLoadingLayout.showEmpty(); @@ -92,7 +93,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat mRefreshLayout.autoRefresh(); } }, 3000); - mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() { + mRefreshLayout.setOnMultiListener(new SimpleMultiListener() { @Override public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) { mIsNeedDemo = false; diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentInner.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/EmptyLayoutExampleFragmentInner.java similarity index 74% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentInner.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/EmptyLayoutExampleFragmentInner.java index d434bf43b..a50116fab 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentInner.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/EmptyLayoutExampleFragmentInner.java @@ -1,17 +1,9 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,23 +11,32 @@ import android.widget.ImageView; import android.widget.TextView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.fragment.example.EmptyLayoutExampleFragment.Item; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.RefreshState; -import com.scwang.smartrefresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.header.ClassicsHeader; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.refresh.layout.fragment.example.EmptyLayoutExampleFragment.Item; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; +import com.scwang.smart.refresh.layout.constant.RefreshState; +import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.header.ClassicsHeader; +import com.scwang.smart.refresh.layout.simple.SimpleMultiListener; import java.util.ArrayList; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 使用示例-空布页面 @@ -58,7 +59,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); mRefreshLayout = root.findViewById(R.id.refreshLayout); mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white)); @@ -67,7 +68,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat RecyclerView recyclerView = root.findViewById(R.id.recyclerView); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(root.getContext(), VERTICAL)); recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(new ArrayList<>(), simple_list_item_2,EmptyLayoutExampleFragmentInner.this) { @Override protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { @@ -92,7 +93,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position mRefreshLayout.autoRefresh(); } }, 3000); - mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() { + mRefreshLayout.setOnMultiListener(new SimpleMultiListener() { @Override public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) { mIsNeedDemo = false; diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentOuter.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/EmptyLayoutExampleFragmentOuter.java similarity index 72% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentOuter.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/EmptyLayoutExampleFragmentOuter.java index 1b0a2a77d..67ffed27c 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/EmptyLayoutExampleFragmentOuter.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/EmptyLayoutExampleFragmentOuter.java @@ -1,17 +1,9 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,22 +11,31 @@ import android.widget.ImageView; import android.widget.TextView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.fragment.example.EmptyLayoutExampleFragment.Item; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.header.ClassicsHeader; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.refresh.layout.fragment.example.EmptyLayoutExampleFragment.Item; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.header.ClassicsHeader; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; -import static com.scwang.refreshlayout.R.id.recyclerView; -import static com.scwang.refreshlayout.R.id.refreshLayout; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; +import static com.scwang.refresh.layout.R.id.recyclerView; +import static com.scwang.refresh.layout.R.id.refreshLayout; /** * 使用示例-空布页面 @@ -56,7 +57,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); mRefreshLayout = root.findViewById(refreshLayout); mRefreshLayout.setRefreshHeader(new ClassicsHeader(getContext()).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white)); @@ -65,7 +66,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat mRecyclerView = root.findViewById(recyclerView); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + mRecyclerView.addItemDecoration(new DividerItemDecoration(root.getContext(), VERTICAL)); mEmptyLayout = root.findViewById(R.id.empty); diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/FlexBoxLayoutManagerFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/FlexBoxLayoutManagerFragment.java similarity index 85% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/FlexBoxLayoutManagerFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/FlexBoxLayoutManagerFragment.java index c3f9ed25f..422a5c9e2 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/FlexBoxLayoutManagerFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/FlexBoxLayoutManagerFragment.java @@ -1,25 +1,26 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; + import com.google.android.flexbox.AlignItems; import com.google.android.flexbox.FlexDirection; import com.google.android.flexbox.FlexWrap; import com.google.android.flexbox.FlexboxLayoutManager; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.util.SmartUtil; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.util.SmartUtil; import java.util.Arrays; import java.util.Random; @@ -40,7 +41,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); FlexboxLayoutManager manager = new FlexboxLayoutManager(root.getContext()); //设置主轴排列方式 diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/HorizontalExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/HorizontalExampleFragment.java similarity index 71% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/HorizontalExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/HorizontalExampleFragment.java index 2e46f041f..64e0a618d 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/HorizontalExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/HorizontalExampleFragment.java @@ -1,26 +1,25 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener; import java.util.Arrays; import java.util.Collection; -import java.util.Objects; import static android.R.layout.simple_list_item_2; @@ -42,12 +41,10 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); root.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - Objects.requireNonNull(getActivity()).getWindow().setStatusBarColor(0); - } + requireActivity().getWindow().setStatusBarColor(0); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); final RecyclerView recyclerView = root.findViewById(R.id.recyclerView); @@ -74,11 +71,6 @@ protected void onBindViewHolder(SmartViewHolder holder, Void model, int position mAdapter.refresh(initData()); RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout); -//// refreshLayout.setRefreshHeader(new MaterialHeader(root.getContext())); -// refreshLayout.setRefreshFooter(new RefreshFooterWrapper(new MaterialHeader(root.getContext())), -1, -2); -//// refreshLayout.setEnableHeaderTranslationContent(true); -// refreshLayout.setEnableFooterTranslationContent(true); -// refreshLayout.setEnableAutoLoadMore(false); refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() { @Override diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/NestedScrollExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/NestedScrollExampleFragment.java similarity index 81% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/NestedScrollExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/NestedScrollExampleFragment.java index c92fb47ad..d5e1dd677 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/NestedScrollExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/NestedScrollExampleFragment.java @@ -1,35 +1,36 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.design.widget.AppBarLayout; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.footer.ClassicsFooter; -import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.appbar.AppBarLayout; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; +import com.scwang.smart.refresh.footer.ClassicsFooter; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 使用示例-嵌套滚动 @@ -42,8 +43,8 @@ public enum Item { NestedIntegral("整体嵌套", NestedScrollExampleFragmentIntegral.class), NestedViewPager("ViewPager", NestedScrollExampleFragmentViewPager.class), ; - public String name; - public Class clazz; + public final String name; + public final Class clazz; Item(String name, Class clazz) { this.name = name; this.clazz = clazz; @@ -68,13 +69,13 @@ public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstan super.onViewCreated(root, savedInstanceState); Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); final BaseRecyclerAdapter adapter; RecyclerView recyclerView = root.findViewById(R.id.recyclerView); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(root.getContext(), VERTICAL)); recyclerView.setAdapter(adapter = new BaseRecyclerAdapter(Arrays.asList(Item.values()), simple_list_item_2, NestedScrollExampleFragment.this) { @Override protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/NestedScrollExampleFragmentIntegral.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/NestedScrollExampleFragmentIntegral.java similarity index 60% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/NestedScrollExampleFragmentIntegral.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/NestedScrollExampleFragmentIntegral.java index c832fe14b..692996c3d 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/NestedScrollExampleFragmentIntegral.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/NestedScrollExampleFragmentIntegral.java @@ -1,19 +1,8 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.content.Context; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -22,12 +11,22 @@ import android.widget.TextView; import android.widget.Toast; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.fragment.example.NestedScrollExampleFragment.Item; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager2.adapter.FragmentStateAdapter; +import androidx.viewpager2.widget.ViewPager2; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener; import com.youth.banner.Banner; import com.youth.banner.loader.ImageLoader; @@ -37,8 +36,8 @@ import java.util.List; import static android.R.layout.simple_list_item_2; -import static com.scwang.refreshlayout.R.mipmap.image_weibo_home_1; -import static com.scwang.refreshlayout.R.mipmap.image_weibo_home_2; +import static com.scwang.refresh.layout.R.mipmap.image_weibo_home_1; +import static com.scwang.refresh.layout.R.mipmap.image_weibo_home_2; /** * 使用示例-嵌套滚动-整体 @@ -46,11 +45,9 @@ */ public class NestedScrollExampleFragmentIntegral extends Fragment implements AdapterView.OnItemClickListener, OnRefreshLoadMoreListener { - private ViewPager mViewPager; + private ViewPager2 mViewPager; private SmartPagerAdapter mAdapter; -// private BaseRecyclerAdapter mAdapter; - @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_example_nestedscroll_integral, container, false); @@ -61,7 +58,7 @@ public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstan super.onViewCreated(root, savedInstanceState); Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); Banner banner = root.findViewById(R.id.banner); banner.setImageLoader(new BannerImageLoader()); @@ -69,34 +66,10 @@ public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstan banner.start(); mViewPager = root.findViewById(R.id.viewPager); - mViewPager.setAdapter(mAdapter = new SmartPagerAdapter(getChildFragmentManager())); -// RecyclerView recyclerView = root.findViewById(R.id.recyclerView); -// recyclerView.setItemAnimator(new DefaultItemAnimator()); -// recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); -// recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); -// recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(buildItems(), simple_list_item_2, NestedScrollExampleFragmentIntegral.this) { -// @Override -// protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { -// holder.text(android.R.id.text1, model.name()); -// holder.text(android.R.id.text2, model.name); -// holder.textColorId(android.R.id.text2, R.color.colorTextAssistant); -// } -// }); + mViewPager.setAdapter(mAdapter = new SmartPagerAdapter(this)); RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout); refreshLayout.setOnRefreshLoadMoreListener(this); -// refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { -// @Override -// public void onLoadMore(@NonNull final RefreshLayout refreshLayout) { -// refreshLayout.getLayout().postDelayed(new Runnable() { -// @Override -// public void run() { -// mAdapter.loadMore(buildItems()); -// refreshLayout.finishLoadMore(); -// } -// }, 2000); -// } -// }); TextView textView = root.findViewById(R.id.target); textView.setOnClickListener(v -> Toast.makeText(getContext(), "点击测试", Toast.LENGTH_SHORT).show()); @@ -125,32 +98,33 @@ public void displayImage(Context context, Object path, ImageView imageView) { } - public static class SmartPagerAdapter extends FragmentStatePagerAdapter { + public static class SmartPagerAdapter extends FragmentStateAdapter { private final SmartFragment[] fragments; - SmartPagerAdapter(FragmentManager fm) { + SmartPagerAdapter(Fragment fm) { super(fm); this.fragments = new SmartFragment[]{ new SmartFragment(),new SmartFragment() }; } + @NonNull @Override - public int getCount() { - return fragments.length; + public Fragment createFragment(int position) { + return fragments[position]; } @Override - public Fragment getItem(int position) { - return fragments[position]; + public int getItemCount() { + return fragments.length; } } public static class SmartFragment extends Fragment { private RecyclerView mRecyclerView; - private BaseRecyclerAdapter mAdapter; + private BaseRecyclerAdapter mAdapter; @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -162,10 +136,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL)); - mRecyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(buildItems(), simple_list_item_2) { + mRecyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(),DividerItemDecoration.VERTICAL)); + mRecyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(buildItems(), simple_list_item_2) { @Override - protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { + protected void onBindViewHolder(SmartViewHolder holder, NestedScrollExampleFragment.Item model, int position) { holder.text(android.R.id.text1, model.name()); holder.text(android.R.id.text2, model.name); holder.textColorId(android.R.id.text2, R.color.colorTextAssistant); @@ -173,10 +147,10 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position }); } - private Collection buildItems() { - List items = new ArrayList<>(); + private Collection buildItems() { + List items = new ArrayList<>(); for (int i = 0; i < 10; i++) { - items.addAll(Arrays.asList(Item.values())); + items.addAll(Arrays.asList(NestedScrollExampleFragment.Item.values())); } return items; } @@ -186,7 +160,7 @@ public void onRefresh(final RefreshLayout refreshLayout) { refreshLayout.getLayout().postDelayed(() -> { mAdapter.refresh(buildItems()); refreshLayout.finishRefresh(); - refreshLayout.resetNoMoreData();//setNoMoreData(false); + refreshLayout.resetNoMoreData(); }, 2000); } diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/NestedScrollExampleFragmentViewPager.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/NestedScrollExampleFragmentViewPager.java similarity index 77% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/NestedScrollExampleFragmentViewPager.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/NestedScrollExampleFragmentViewPager.java index a49041fe9..9b4d08980 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/NestedScrollExampleFragmentViewPager.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/NestedScrollExampleFragmentViewPager.java @@ -1,30 +1,30 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.design.widget.AppBarLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.header.PhoenixHeader; -import com.scwang.smartrefresh.layout.SmartRefreshLayout; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager2.adapter.FragmentStateAdapter; +import androidx.viewpager2.widget.ViewPager2; + +import com.google.android.material.appbar.AppBarLayout; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.header.PhoenixHeader; +import com.scwang.smart.refresh.layout.SmartRefreshLayout; import java.util.Arrays; import java.util.Collection; @@ -47,10 +47,10 @@ public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstan super.onViewCreated(root, savedInstanceState); Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); - ViewPager viewPager = root.findViewById(R.id.viewPager); - viewPager.setAdapter(new SmartPagerAdapter(getChildFragmentManager())); + ViewPager2 viewPager = root.findViewById(R.id.viewPager); + viewPager.setAdapter(new SmartPagerAdapter(this)); /* * 监听 AppBarLayout 的关闭和开启 ActionButton 设置关闭隐藏动画 @@ -76,25 +76,26 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { } - public static class SmartPagerAdapter extends FragmentStatePagerAdapter { + public static class SmartPagerAdapter extends FragmentStateAdapter { private final SmartFragment[] fragments; - SmartPagerAdapter(FragmentManager fm) { + SmartPagerAdapter(Fragment fm) { super(fm); this.fragments = new SmartFragment[]{ new SmartFragment(),new SmartFragment() }; } + @NonNull @Override - public int getCount() { - return fragments.length; + public Fragment createFragment(int position) { + return fragments[position]; } @Override - public Fragment getItem(int position) { - return fragments[position]; + public int getItemCount() { + return fragments.length; } } @@ -118,7 +119,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL)); + mRecyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(),DividerItemDecoration.VERTICAL)); mRecyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(initData(), simple_list_item_2) { @Override protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/NoMoreDataExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/NoMoreDataExampleFragment.java similarity index 81% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/NoMoreDataExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/NoMoreDataExampleFragment.java index 7ac5ed38a..3b7ac2e21 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/NoMoreDataExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/NoMoreDataExampleFragment.java @@ -1,23 +1,24 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; import java.util.ArrayList; import java.util.Collection; @@ -25,7 +26,7 @@ import java.util.Random; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * A simple {@link Fragment} subclass. @@ -50,12 +51,12 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); RecyclerView recyclerView = root.findViewById(R.id.recyclerView); if (recyclerView != null) { recyclerView.setNestedScrollingEnabled(false); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(root.getContext(), VERTICAL)); recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(simple_list_item_2) { @Override protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/PureScrollExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/PureScrollExampleFragment.java similarity index 74% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/PureScrollExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/PureScrollExampleFragment.java index ba8aec229..97e38dab9 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/PureScrollExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/PureScrollExampleFragment.java @@ -1,31 +1,32 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 使用示例-纯滚动模式 @@ -38,8 +39,8 @@ public enum Item { HeaderOnly("代码中单独指定Header", PureScrollExampleFragmentHeader.class), FooterOnly("XML中单独指定Footer", PureScrollExampleFragmentFooter.class), ; - public String name; - public Class clazz; + public final String name; + public final Class clazz; Item(String name, Class clazz) { this.name = name; this.clazz = clazz; @@ -56,14 +57,14 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); View view = root.findViewById(R.id.recyclerView); if (view instanceof RecyclerView) { RecyclerView recyclerView = (RecyclerView) view; recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(), VERTICAL)); recyclerView.setAdapter(new BaseRecyclerAdapter(Arrays.asList(Item.values()), simple_list_item_2,this) { @Override protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/PureScrollExampleFragmentFooter.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/PureScrollExampleFragmentFooter.java similarity index 65% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/PureScrollExampleFragmentFooter.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/PureScrollExampleFragmentFooter.java index de8e18e51..4a079b5fc 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/PureScrollExampleFragmentFooter.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/PureScrollExampleFragmentFooter.java @@ -1,33 +1,33 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.fragment.example.PureScrollExampleFragment.Item; -import com.scwang.smartrefresh.layout.api.RefreshLayout; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 使用示例-纯滚动模式 @@ -45,24 +45,23 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); toolbar.setTitle("Footer单独使用"); RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout); refreshLayout.setEnablePureScrollMode(true); refreshLayout.setEnableRefresh(false); refreshLayout.setEnableLoadMore(true); -// refreshLayout.setRefreshFooter(new FalsifyFooter(getContext())); View view = root.findViewById(R.id.recyclerView); if (view instanceof RecyclerView) { RecyclerView recyclerView = (RecyclerView) view; recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); - recyclerView.setAdapter(new BaseRecyclerAdapter(Arrays.asList(Item.values()), simple_list_item_2,this) { + recyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(), VERTICAL)); + recyclerView.setAdapter(new BaseRecyclerAdapter(Arrays.asList(PureScrollExampleFragment.Item.values()), simple_list_item_2,this) { @Override - protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { + protected void onBindViewHolder(SmartViewHolder holder, PureScrollExampleFragment.Item model, int position) { holder.text(android.R.id.text1, model.name()); holder.text(android.R.id.text2, model.name); holder.textColorId(android.R.id.text2, R.color.colorTextAssistant); @@ -73,7 +72,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - Item item = Item.values()[position]; + PureScrollExampleFragment.Item item = PureScrollExampleFragment.Item.values()[position]; if (Activity.class.isAssignableFrom(item.clazz)) { startActivity(new Intent(getContext(), item.clazz)); } else if (Fragment.class.isAssignableFrom(item.clazz)) { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/PureScrollExampleFragmentHeader.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/PureScrollExampleFragmentHeader.java similarity index 63% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/PureScrollExampleFragmentHeader.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/PureScrollExampleFragmentHeader.java index 40eb467c1..ddcbdea00 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/PureScrollExampleFragmentHeader.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/PureScrollExampleFragmentHeader.java @@ -1,34 +1,34 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.fragment.example.PureScrollExampleFragment.Item; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.header.FalsifyHeader; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.header.FalsifyHeader; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 使用示例-纯滚动模式 @@ -46,7 +46,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout); refreshLayout.setRefreshHeader(new FalsifyHeader(getContext()));//也可以在 XML 中添加 FalsifyHeader @@ -56,10 +56,10 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat RecyclerView recyclerView = (RecyclerView) view; recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); - recyclerView.setAdapter(new BaseRecyclerAdapter(Arrays.asList(Item.values()), simple_list_item_2,this) { + recyclerView.addItemDecoration(new DividerItemDecoration(root.getContext(), VERTICAL)); + recyclerView.setAdapter(new BaseRecyclerAdapter(Arrays.asList(PureScrollExampleFragment.Item.values()), simple_list_item_2,this) { @Override - protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { + protected void onBindViewHolder(SmartViewHolder holder, PureScrollExampleFragment.Item model, int position) { holder.text(android.R.id.text1, model.name()); holder.text(android.R.id.text2, model.name); holder.textColorId(android.R.id.text2, R.color.colorTextAssistant); @@ -70,7 +70,7 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - Item item = Item.values()[position]; + PureScrollExampleFragment.Item item = PureScrollExampleFragment.Item.values()[position]; if (Activity.class.isAssignableFrom(item.clazz)) { startActivity(new Intent(getContext(), item.clazz)); } else if (Fragment.class.isAssignableFrom(item.clazz)) { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/SpecifyStyleExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/SpecifyStyleExampleFragment.java similarity index 69% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/SpecifyStyleExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/SpecifyStyleExampleFragment.java index a640fb7c2..868de2f7e 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/SpecifyStyleExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/SpecifyStyleExampleFragment.java @@ -1,34 +1,35 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.activity.example.AssignCodeExampleActivity; -import com.scwang.refreshlayout.activity.example.AssignDefaultExampleActivity; -import com.scwang.refreshlayout.activity.example.AssignXmlExampleActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.activity.example.AssignCodeExampleActivity; +import com.scwang.refresh.layout.activity.example.AssignDefaultExampleActivity; +import com.scwang.refresh.layout.activity.example.AssignXmlExampleActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 使用示例-指定样式 @@ -41,8 +42,8 @@ public enum Item { Code("代码指定", AssignCodeExampleActivity.class), Xml("XML指定", AssignXmlExampleActivity.class), ; - public String name; - public Class clazz; + public final String name; + public final Class clazz; Item(String name, Class clazz) { this.name = name; this.clazz = clazz; @@ -59,7 +60,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); toolbar.setTitle("指定样式"); View view = root.findViewById(R.id.recyclerView); @@ -67,7 +68,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat RecyclerView recyclerView = (RecyclerView) view; recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(root.getContext(), VERTICAL)); recyclerView.setAdapter(new BaseRecyclerAdapter(Arrays.asList(Item.values()), simple_list_item_2,this) { @Override protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/StaggeredGridExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/StaggeredGridExampleFragment.java similarity index 84% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/StaggeredGridExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/StaggeredGridExampleFragment.java index be68421a3..28a07e3ee 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/StaggeredGridExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/StaggeredGridExampleFragment.java @@ -1,20 +1,21 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener; import java.util.Arrays; import java.util.Collection; diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/ViewPagerExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/example/ViewPagerExampleFragment.java similarity index 68% rename from app/src/main/java/com/scwang/refreshlayout/fragment/example/ViewPagerExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/example/ViewPagerExampleFragment.java index 6f6328cf0..dfb2cfe15 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/ViewPagerExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/example/ViewPagerExampleFragment.java @@ -1,32 +1,34 @@ -package com.scwang.refreshlayout.fragment.example; +package com.scwang.refresh.layout.fragment.example; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.footer.ClassicsFooter; -import com.scwang.smartrefresh.layout.header.ClassicsHeader; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager2.adapter.FragmentStateAdapter; +import androidx.viewpager2.widget.ViewPager2; + +import com.google.android.material.tabs.TabLayout; +import com.google.android.material.tabs.TabLayoutMediator; +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; +import com.scwang.smart.refresh.footer.ClassicsFooter; +import com.scwang.smart.refresh.header.ClassicsHeader; +import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener; import java.util.Arrays; import java.util.Collection; @@ -39,21 +41,21 @@ */ public class ViewPagerExampleFragment extends Fragment implements OnRefreshListener, OnRefreshLoadMoreListener { - - public enum Item { + private enum Item { NestedInner(R.string.item_example_pager_left, SmartFragment.class), NestedOuter(R.string.item_example_pager_right, SmartFragment.class), ; - public int nameId; - public Class clazz; + public final int nameId; + public final Class clazz; Item(@StringRes int nameId, Class clazz) { this.nameId = nameId; this.clazz = clazz; } } - private ViewPager mViewPager; + private ViewPager2 mViewPager; private SmartPagerAdapter mAdapter; + private TabLayoutMediator mTabLayoutMediator; @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -65,7 +67,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat super.onViewCreated(root, savedInstanceState); final Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); + toolbar.setNavigationOnClickListener(v -> requireActivity().finish()); RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout); refreshLayout.setOnRefreshLoadMoreListener(this); @@ -75,8 +77,15 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat mViewPager = root.findViewById(R.id.viewPager); TabLayout mTabLayout = root.findViewById(R.id.tableLayout); - mViewPager.setAdapter(mAdapter = new SmartPagerAdapter(Item.values())); - mTabLayout.setupWithViewPager(mViewPager, true); + mViewPager.setAdapter(mAdapter = new SmartPagerAdapter(this, Item.values())); + + this.mTabLayoutMediator = new TabLayoutMediator(mTabLayout, mViewPager, true, true, new TabLayoutMediator.TabConfigurationStrategy() { + @Override + public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) { + tab.setText(getString(Item.values()[position].nameId)); + } + }); + this.mTabLayoutMediator.attach(); } @Override @@ -90,34 +99,30 @@ public void onLoadMore(@NonNull RefreshLayout refreshLayout) { } - private class SmartPagerAdapter extends FragmentStatePagerAdapter { + private static class SmartPagerAdapter extends FragmentStateAdapter { private final Item[] items; private final SmartFragment[] fragments; - SmartPagerAdapter(Item... items) { - super(getChildFragmentManager()); + SmartPagerAdapter(Fragment fragment, Item... items) { + super(fragment); this.items = items; this.fragments = new SmartFragment[items.length]; } + @NonNull @Override - public int getCount() { - return items.length; - } - - @Override - public CharSequence getPageTitle(int position) { - return getString(items[position].nameId); - } - - @Override - public Fragment getItem(int position) { + public Fragment createFragment(int position) { if (fragments[position] == null) { fragments[position] = new SmartFragment(); } return fragments[position]; } + + @Override + public int getItemCount() { + return items.length; + } } public static class SmartFragment extends Fragment { @@ -134,9 +139,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); RecyclerView recyclerView = (RecyclerView) view; - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); recyclerView.setItemAnimator(new DefaultItemAnimator()); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(),DividerItemDecoration.VERTICAL)); recyclerView.setAdapter(mAdapter = new BaseRecyclerAdapter(initData(), simple_list_item_2) { @Override protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshExampleFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/index/RefreshExampleFragment.java similarity index 62% rename from app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshExampleFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/index/RefreshExampleFragment.java index 66b740caf..4cf0e9fef 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshExampleFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/index/RefreshExampleFragment.java @@ -1,39 +1,50 @@ -package com.scwang.refreshlayout.fragment.index; +package com.scwang.refresh.layout.fragment.index; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.activity.example.BasicExampleActivity; -import com.scwang.refreshlayout.activity.example.CustomExampleActivity; -import com.scwang.refreshlayout.activity.example.I18nExampleActivity; -import com.scwang.refreshlayout.activity.example.ListenerExampleActivity; -import com.scwang.refreshlayout.activity.example.NestedLayoutExampleActivity; -import com.scwang.refreshlayout.activity.example.SnapHelperExampleActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.fragment.example.*; -import com.scwang.refreshlayout.util.StatusBarUtil; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.activity.example.BasicExampleActivity; +import com.scwang.refresh.layout.activity.example.CustomExampleActivity; +import com.scwang.refresh.layout.activity.example.I18nExampleActivity; +import com.scwang.refresh.layout.activity.example.ListenerExampleActivity; +import com.scwang.refresh.layout.activity.example.NestedLayoutExampleActivity; +import com.scwang.refresh.layout.activity.example.SnapHelperExampleActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.refresh.layout.fragment.example.BottomSheetExampleFragment; +import com.scwang.refresh.layout.fragment.example.DisallowInterceptExampleFragment; +import com.scwang.refresh.layout.fragment.example.EmptyLayoutExampleFragment; +import com.scwang.refresh.layout.fragment.example.FlexBoxLayoutManagerFragment; +import com.scwang.refresh.layout.fragment.example.HorizontalExampleFragment; +import com.scwang.refresh.layout.fragment.example.NestedScrollExampleFragment; +import com.scwang.refresh.layout.fragment.example.NoMoreDataExampleFragment; +import com.scwang.refresh.layout.fragment.example.PureScrollExampleFragment; +import com.scwang.refresh.layout.fragment.example.SpecifyStyleExampleFragment; +import com.scwang.refresh.layout.fragment.example.StaggeredGridExampleFragment; +import com.scwang.refresh.layout.fragment.example.ViewPagerExampleFragment; +import com.scwang.refresh.layout.util.StatusBarUtil; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 使用示例 @@ -54,15 +65,14 @@ private enum Item { I18N(R.string.index_example_custom, I18nExampleActivity.class), SnapHelper(R.string.index_example_snap_helper, SnapHelperExampleActivity.class), ViewPager(R.string.index_example_pager, ViewPagerExampleFragment.class), - BottomSheet(R.string.index_example_bottom_sheet,BottomSheetExampleFragment.class), + BottomSheet(R.string.index_example_bottom_sheet, BottomSheetExampleFragment.class), FlexBoxLayout(R.string.index_example_flex_box, FlexBoxLayoutManagerFragment.class), Horizontal(R.string.index_example_horizontal, HorizontalExampleFragment.class), DisallowIntercept(R.string.index_example_disallow_intercept, DisallowInterceptExampleFragment.class), StaggeredGrid(R.string.index_example_disallow_intercept, StaggeredGridExampleFragment.class), -// ThreeLevel(R.string.index_example_level, ThreeLevelExampleFragment.class), ; - public int nameId; - public Class clazz; + public final int nameId; + public final Class clazz; Item(@StringRes int nameId, Class clazz) { this.nameId = nameId; @@ -85,7 +95,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat RecyclerView recyclerView = (RecyclerView) view; recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(), VERTICAL)); recyclerView.setAdapter(new BaseRecyclerAdapter(Arrays.asList(Item.values()), simple_list_item_2,this) { @Override protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshPracticeFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/index/RefreshPracticeFragment.java similarity index 64% rename from app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshPracticeFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/index/RefreshPracticeFragment.java index b76d3dd90..34fb5808c 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshPracticeFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/index/RefreshPracticeFragment.java @@ -1,41 +1,44 @@ -package com.scwang.refreshlayout.fragment.index; +package com.scwang.refresh.layout.fragment.index; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.FragmentActivity; -import com.scwang.refreshlayout.activity.practice.BannerPracticeActivity; -import com.scwang.refreshlayout.activity.practice.FeedListPracticeActivity; -import com.scwang.refreshlayout.activity.practice.ProfilePracticeActivity; -import com.scwang.refreshlayout.activity.practice.QQBrowserPracticeActivity; -import com.scwang.refreshlayout.activity.practice.RepastPracticeActivity; -import com.scwang.refreshlayout.activity.practice.WebViewPracticeActivity; -import com.scwang.refreshlayout.activity.practice.WeiboPracticeActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.fragment.practice.InstantPracticeFragment; -import com.scwang.refreshlayout.fragment.practice.SecondFloorPracticeFragment; -import com.scwang.refreshlayout.util.StatusBarUtil; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.FragmentActivity; +import com.scwang.refresh.layout.activity.practice.BannerPracticeActivity; +import com.scwang.refresh.layout.activity.practice.FeedListPracticeActivity; +import com.scwang.refresh.layout.activity.practice.ProfilePracticeActivity; +import com.scwang.refresh.layout.activity.practice.QQBrowserPracticeActivity; +import com.scwang.refresh.layout.activity.practice.RepastPracticeActivity; +import com.scwang.refresh.layout.activity.practice.WebViewPracticeActivity; +import com.scwang.refresh.layout.activity.practice.WeiboPracticeActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.refresh.layout.fragment.practice.InstantPracticeFragment; +import com.scwang.refresh.layout.fragment.practice.SecondFloorPracticeFragment; +import com.scwang.refresh.layout.util.StatusBarUtil; +import com.scwang.smart.refresh.layout.SmartRefreshLayout; +import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; /** * 实战演示 @@ -51,13 +54,12 @@ private enum Item { Weibo(R.string.index_practice_weibo, WeiboPracticeActivity.class), Banner(R.string.index_practice_banner, BannerPracticeActivity.class), QQBrowser(R.string.index_practice_qq_browser, QQBrowserPracticeActivity.class), -// TwoLevel("二级刷新", SecondFloorPracticeFragment.class), SecondFloor(R.string.index_practice_second_floor, SecondFloorPracticeFragment.class), Instant(R.string.index_practice_instant, InstantPracticeFragment.class) ; @StringRes - public int name; - public Class clazz; + public final int name; + public final Class clazz; Item(@StringRes int name, Class clazz) { this.name = name; this.clazz = clazz; @@ -80,7 +82,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat RecyclerView recyclerView = (RecyclerView) view; recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(), VERTICAL)); recyclerView.setAdapter(new BaseRecyclerAdapter(Arrays.asList(Item.values()), simple_list_item_2,this) { @Override protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) { @@ -90,6 +92,8 @@ protected void onBindViewHolder(SmartViewHolder holder, Item model, int position } }); } + SmartRefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout); + refreshLayout.setOnRefreshListener(RefreshLayout::finishRefresh); } @Override diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshStylesFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/index/RefreshStylesFragment.java similarity index 81% rename from app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshStylesFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/index/RefreshStylesFragment.java index ec6b39e3e..b1a224ff9 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/index/RefreshStylesFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/index/RefreshStylesFragment.java @@ -1,38 +1,39 @@ -package com.scwang.refreshlayout.fragment.index; +package com.scwang.refresh.layout.fragment.index; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.activity.style.BezierCircleStyleActivity; -import com.scwang.refreshlayout.activity.style.BezierRadarStyleActivity; -import com.scwang.refreshlayout.activity.style.ClassicsStyleActivity; -import com.scwang.refreshlayout.activity.style.DeliveryStyleActivity; -import com.scwang.refreshlayout.activity.style.DropBoxStyleActivity; -import com.scwang.refreshlayout.activity.style.FlyRefreshStyleActivity; -import com.scwang.refreshlayout.activity.style.FunGameBattleCityStyleActivity; -import com.scwang.refreshlayout.activity.style.FunGameHitBlockStyleActivity; -import com.scwang.refreshlayout.activity.style.MaterialStyleActivity; -import com.scwang.refreshlayout.activity.style.PhoenixStyleActivity; -import com.scwang.refreshlayout.activity.style.StoreHouseStyleActivity; -import com.scwang.refreshlayout.activity.style.TaurusStyleActivity; -import com.scwang.refreshlayout.activity.style.WaterDropStyleActivity; -import com.scwang.refreshlayout.activity.style.WaveSwipeStyleActivity; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.util.StatusBarUtil; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.activity.style.BezierCircleStyleActivity; +import com.scwang.refresh.layout.activity.style.BezierRadarStyleActivity; +import com.scwang.refresh.layout.activity.style.ClassicsStyleActivity; +import com.scwang.refresh.layout.activity.style.DeliveryStyleActivity; +import com.scwang.refresh.layout.activity.style.DropBoxStyleActivity; +import com.scwang.refresh.layout.activity.style.FlyRefreshStyleActivity; +import com.scwang.refresh.layout.activity.style.FunGameBattleCityStyleActivity; +import com.scwang.refresh.layout.activity.style.FunGameHitBlockStyleActivity; +import com.scwang.refresh.layout.activity.style.MaterialStyleActivity; +import com.scwang.refresh.layout.activity.style.PhoenixStyleActivity; +import com.scwang.refresh.layout.activity.style.StoreHouseStyleActivity; +import com.scwang.refresh.layout.activity.style.TaurusStyleActivity; +import com.scwang.refresh.layout.activity.style.WaterDropStyleActivity; +import com.scwang.refresh.layout.activity.style.WaveSwipeStyleActivity; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.refresh.layout.util.StatusBarUtil; import com.scwang.smart.refresh.footer.BallPulseFooter; import com.scwang.smart.refresh.header.BezierCircleHeader; import com.scwang.smart.refresh.header.ClassicsHeader; @@ -53,8 +54,8 @@ import java.util.Arrays; import static android.R.layout.simple_list_item_2; -import static android.support.v7.widget.DividerItemDecoration.VERTICAL; -import static com.scwang.refreshlayout.R.id.recyclerView; +import static androidx.recyclerview.widget.DividerItemDecoration.VERTICAL; +import static com.scwang.refresh.layout.R.id.recyclerView; /** * 风格展示 @@ -63,7 +64,7 @@ public class RefreshStylesFragment extends Fragment implements AdapterView.OnItemClickListener { private enum Item { - Hidden(R.string.title_activity_style_delivery,DeliveryStyleActivity.class), + Hidden(R.string.title_activity_style_delivery, DeliveryStyleActivity.class), Delivery(R.string.title_activity_style_delivery,DeliveryStyleActivity.class), DropBox(R.string.title_activity_style_drop_box, DropBoxStyleActivity.class), WaveSwipe(R.string.title_activity_style_wave_swipe, WaveSwipeStyleActivity.class), @@ -79,8 +80,8 @@ private enum Item { StoreHouse(R.string.title_activity_style_storehouse, StoreHouseStyleActivity.class), Classics(R.string.title_activity_style_classics, ClassicsStyleActivity.class), ; - public int nameId; - public Class clazz; + public final int nameId; + public final Class clazz; Item(@StringRes int nameId, Class clazz) { this.nameId = nameId; this.clazz = clazz; @@ -103,7 +104,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat RecyclerView recyclerView = (RecyclerView) view; recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), VERTICAL)); + recyclerView.addItemDecoration(new DividerItemDecoration(view.getContext(), VERTICAL)); recyclerView.setAdapter(new BaseRecyclerAdapter(Arrays.asList(Item.values()), simple_list_item_2,this) { @NonNull @Override diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/practice/InstantPracticeFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/practice/InstantPracticeFragment.java similarity index 90% rename from app/src/main/java/com/scwang/refreshlayout/fragment/practice/InstantPracticeFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/practice/InstantPracticeFragment.java index f0b56b5f9..ad2b9693a 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/practice/InstantPracticeFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/practice/InstantPracticeFragment.java @@ -1,24 +1,25 @@ -package com.scwang.refreshlayout.fragment.practice; +package com.scwang.refresh.layout.fragment.practice; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.util.DynamicTimeFormat; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.footer.ClassicsFooter; -import com.scwang.smartrefresh.layout.impl.ScrollBoundaryDeciderAdapter; -import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.refresh.layout.util.DynamicTimeFormat; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; +import com.scwang.smart.refresh.footer.ClassicsFooter; +import com.scwang.smart.refresh.layout.simple.SimpleBoundaryDecider; import java.util.Arrays; import java.util.Collection; @@ -43,7 +44,7 @@ public void onViewCreated(@NonNull View root, @Nullable Bundle savedInstanceStat toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - getActivity().finish(); + requireActivity().finish(); } }); @@ -64,7 +65,7 @@ public void onClick(View v) { refreshLayout.setEnableNestedScroll(false);//必须关闭 refreshLayout.setEnableScrollContentWhenLoaded(true);//必须关闭 refreshLayout.getLayout().setScaleY(-1);//必须设置 - refreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDeciderAdapter() { + refreshLayout.setScrollBoundaryDecider(new SimpleBoundaryDecider() { @Override public boolean canLoadMore(View content) { return super.canRefresh(content);//必须替换 diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/practice/SecondFloorPracticeFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/practice/SecondFloorPracticeFragment.java similarity index 77% rename from app/src/main/java/com/scwang/refreshlayout/fragment/practice/SecondFloorPracticeFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/practice/SecondFloorPracticeFragment.java index 84bcf7412..bb6cc6cf4 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/practice/SecondFloorPracticeFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/practice/SecondFloorPracticeFragment.java @@ -1,27 +1,28 @@ -package com.scwang.refreshlayout.fragment.practice; +package com.scwang.refresh.layout.fragment.practice; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.refreshlayout.util.StatusBarUtil; -import com.scwang.smartrefresh.layout.api.OnTwoLevelListener; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.RefreshState; -import com.scwang.smartrefresh.layout.header.TwoLevelHeader; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.adapter.BaseRecyclerAdapter; +import com.scwang.refresh.layout.adapter.SmartViewHolder; +import com.scwang.refresh.layout.util.StatusBarUtil; +import com.scwang.smart.refresh.header.listener.OnTwoLevelListener; +import com.scwang.smart.refresh.header.TwoLevelHeader; +import com.scwang.smart.refresh.layout.api.RefreshHeader; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.constant.RefreshState; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; +import com.scwang.smart.refresh.layout.simple.SimpleMultiListener; import java.util.Arrays; import java.util.List; @@ -49,12 +50,12 @@ public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstan toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - getActivity().finish(); + requireActivity().finish(); } }); final RefreshLayout refreshLayout = root.findViewById(R.id.refreshLayout); - refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() { + refreshLayout.setOnMultiListener(new SimpleMultiListener() { @Override public void onLoadMore(@NonNull RefreshLayout refreshLayout) { refreshLayout.finishLoadMore(2000); @@ -92,13 +93,6 @@ public void onClick(View v) { public boolean onTwoLevel(@NonNull RefreshLayout refreshLayout) { Toast.makeText(getContext(),"触发二楼事件",Toast.LENGTH_SHORT).show(); root.findViewById(R.id.second_floor_content).animate().alpha(1).setDuration(2000); -// refreshLayout.getLayout().postDelayed(new Runnable() { -// @Override -// public void run() { -// header.finishTwoLevel(); -// root.findViewById(R.id.second_floor_content).animate().alpha(0).setDuration(1000); -// } -// },5000); return true;//true 将会展开二楼状态 false 关闭刷新 } }); diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/practice/TwoLevelPracticeFragment.java b/app/src/main/java/com/scwang/refresh/layout/fragment/practice/TwoLevelPracticeFragment.java similarity index 78% rename from app/src/main/java/com/scwang/refreshlayout/fragment/practice/TwoLevelPracticeFragment.java rename to app/src/main/java/com/scwang/refresh/layout/fragment/practice/TwoLevelPracticeFragment.java index cfb90f0ec..564b8be2e 100644 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/practice/TwoLevelPracticeFragment.java +++ b/app/src/main/java/com/scwang/refresh/layout/fragment/practice/TwoLevelPracticeFragment.java @@ -1,21 +1,22 @@ -package com.scwang.refreshlayout.fragment.practice; +package com.scwang.refresh.layout.fragment.practice; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.util.StatusBarUtil; -import com.scwang.smartrefresh.layout.api.OnTwoLevelListener; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.header.TwoLevelHeader; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; + +import com.scwang.refresh.layout.R; +import com.scwang.refresh.layout.util.StatusBarUtil; +import com.scwang.smart.refresh.header.listener.OnTwoLevelListener; +import com.scwang.smart.refresh.header.TwoLevelHeader; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; /** * 二级刷新 @@ -37,7 +38,7 @@ public void onViewCreated(@NonNull final View root, @Nullable Bundle savedInstan toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - getActivity().finish(); + requireActivity().finish(); } }); diff --git a/app/src/main/java/com/scwang/refreshlayout/util/DynamicTimeFormat.java b/app/src/main/java/com/scwang/refresh/layout/util/DynamicTimeFormat.java similarity index 98% rename from app/src/main/java/com/scwang/refreshlayout/util/DynamicTimeFormat.java rename to app/src/main/java/com/scwang/refresh/layout/util/DynamicTimeFormat.java index e4c50423e..dd66665a2 100644 --- a/app/src/main/java/com/scwang/refreshlayout/util/DynamicTimeFormat.java +++ b/app/src/main/java/com/scwang/refresh/layout/util/DynamicTimeFormat.java @@ -1,6 +1,6 @@ -package com.scwang.refreshlayout.util; +package com.scwang.refresh.layout.util; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import java.text.FieldPosition; import java.text.SimpleDateFormat; diff --git a/app/src/main/java/com/scwang/refreshlayout/util/StatusBarUtil.java b/app/src/main/java/com/scwang/refresh/layout/util/StatusBarUtil.java similarity index 67% rename from app/src/main/java/com/scwang/refreshlayout/util/StatusBarUtil.java rename to app/src/main/java/com/scwang/refresh/layout/util/StatusBarUtil.java index b3ccf9302..0b410e6ae 100644 --- a/app/src/main/java/com/scwang/refreshlayout/util/StatusBarUtil.java +++ b/app/src/main/java/com/scwang/refresh/layout/util/StatusBarUtil.java @@ -1,11 +1,9 @@ -package com.scwang.refreshlayout.util; +package com.scwang.refresh.layout.util; import android.app.Activity; import android.content.Context; import android.content.res.Resources; import android.os.Build; -import android.support.annotation.FloatRange; -import android.support.annotation.RequiresApi; import android.util.Log; import android.util.TypedValue; import android.view.View; @@ -13,6 +11,9 @@ import android.view.Window; import android.view.WindowManager; +import androidx.annotation.FloatRange; +import androidx.annotation.RequiresApi; + import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.regex.Pattern; @@ -50,40 +51,28 @@ public static void immersive(Window window, int color) { } public static void immersive(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) { - if (Build.VERSION.SDK_INT >= 21) { - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.setStatusBarColor(mixtureColor(color, alpha)); - - int systemUiVisibility = window.getDecorView().getSystemUiVisibility(); - systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; - systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE; - window.getDecorView().setSystemUiVisibility(systemUiVisibility); - } else if (Build.VERSION.SDK_INT >= 19) { - window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - setTranslucentView((ViewGroup) window.getDecorView(), color, alpha); - } else if (Build.VERSION.SDK_INT >= MIN_API && Build.VERSION.SDK_INT > 16) { - int systemUiVisibility = window.getDecorView().getSystemUiVisibility(); - systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; - systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE; - window.getDecorView().setSystemUiVisibility(systemUiVisibility); - } + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(mixtureColor(color, alpha)); + + int systemUiVisibility = window.getDecorView().getSystemUiVisibility(); + systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE; + window.getDecorView().setSystemUiVisibility(systemUiVisibility); } public static void color(Activity activity, int color) { - if (Build.VERSION.SDK_INT >= 21) { - Window window = activity.getWindow(); - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.setStatusBarColor(color); - } + Window window = activity.getWindow(); + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(color); } // // public static void darkMode(Activity activity, boolean dark) { - if (isFlyme4Later()) { - darkModeForFlyme4(activity.getWindow(), dark); + if (isFlyMe4Later()) { + darkModeForFlyMe4(activity.getWindow(), dark); } else if (isMIUI6Later()) { darkModeForMIUI6(activity.getWindow(), dark); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -93,8 +82,8 @@ public static void darkMode(Activity activity, boolean dark) { public static void darkModeCancel(Activity activity) { Window window = activity.getWindow(); - if (isFlyme4Later()) { - darkModeForFlyme4(window, false); + if (isFlyMe4Later()) { + darkModeForFlyMe4(window, false); } else if (isMIUI6Later()) { darkModeForMIUI6(window, false); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -113,8 +102,8 @@ public static void darkMode(Activity activity, int color, @FloatRange(from = 0.0 public static void darkOnly(Activity activity) { Window window = activity.getWindow(); - if (isFlyme4Later()) { - darkModeForFlyme4(window, true); + if (isFlyMe4Later()) { + darkModeForFlyMe4(window, true); } else if (isMIUI6Later()) { darkModeForMIUI6(window, true); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -124,8 +113,8 @@ public static void darkOnly(Activity activity) { /** 设置状态栏darkMode,字体颜色及icon变黑(目前支持MIUI6以上,Flyme4以上,Android M以上) */ public static void darkMode(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) { - if (isFlyme4Later()) { - darkModeForFlyme4(window, true); + if (isFlyMe4Later()) { + darkModeForFlyMe4(window, true); immersive(window,color,alpha); } else if (isMIUI6Later()) { darkModeForMIUI6(window, true); @@ -133,11 +122,9 @@ public static void darkMode(Window window, int color, @FloatRange(from = 0.0, to } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { darkModeForM(window, true); immersive(window, color, alpha); - } else if (Build.VERSION.SDK_INT >= 19) { + } else { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); setTranslucentView((ViewGroup) window.getDecorView(), color, alpha); - } else { - immersive(window, color, alpha); } // if (Build.VERSION.SDK_INT >= 21) { // window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); @@ -170,26 +157,26 @@ private static void darkModeForM(Window window, boolean dark) { /** * 设置Flyme4+的darkMode,darkMode时候字体颜色及icon变黑 - * http://open-wiki.flyme.cn/index.php?title=Flyme%E7%B3%BB%E7%BB%9FAPI + * ... */ - public static boolean darkModeForFlyme4(Window window, boolean dark) { + public static boolean darkModeForFlyMe4(Window window, boolean dark) { boolean result = false; if (window != null) { try { WindowManager.LayoutParams e = window.getAttributes(); Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); - Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags"); + Field flyMeFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags"); darkFlag.setAccessible(true); - meizuFlags.setAccessible(true); + flyMeFlags.setAccessible(true); int bit = darkFlag.getInt(null); - int value = meizuFlags.getInt(e); + int value = flyMeFlags.getInt(e); if (dark) { value |= bit; } else { value &= ~bit; } - meizuFlags.setInt(e, value); + flyMeFlags.setInt(e, value); window.setAttributes(e); result = true; } catch (Exception var8) { @@ -202,7 +189,7 @@ public static boolean darkModeForFlyme4(Window window, boolean dark) { /** * 设置MIUI6+的状态栏是否为darkMode,darkMode时候字体颜色及icon变黑 - * http://dev.xiaomi.com/doc/p=4769/ + * ... */ public static boolean darkModeForMIUI6(Window window, boolean dark) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -224,7 +211,7 @@ public static boolean darkModeForMIUI6(Window window, boolean dark) { } /** 判断是否Flyme4以上 */ - public static boolean isFlyme4Later() { + public static boolean isFlyMe4Later() { return Build.FINGERPRINT.contains("Flyme_OS_4") || Build.VERSION.INCREMENTAL.contains("Flyme_OS_4") || Pattern.compile("Flyme OS [4|5]", Pattern.CASE_INSENSITIVE).matcher(Build.DISPLAY).find(); @@ -236,6 +223,7 @@ public static boolean isMIUI6Later() { Class clz = Class.forName("android.os.SystemProperties"); Method mtd = clz.getMethod("get", String.class); String val = (String) mtd.invoke(null, "ro.miui.ui.version.name"); + assert val != null; val = val.replaceAll("[vV]", ""); int version = Integer.parseInt(val); return version >= 6; @@ -248,59 +236,49 @@ public static boolean isMIUI6Later() { /** 增加View的paddingTop,增加的值为状态栏高度 */ public static void setPadding(Context context, View view) { - if (Build.VERSION.SDK_INT >= MIN_API) { - view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context), - view.getPaddingRight(), view.getPaddingBottom()); - } + view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context), + view.getPaddingRight(), view.getPaddingBottom()); } /** 增加View的paddingTop,增加的值为状态栏高度 (智能判断,并设置高度)*/ public static void setPaddingSmart(Context context, View view) { - if (Build.VERSION.SDK_INT >= MIN_API) { - ViewGroup.LayoutParams lp = view.getLayoutParams(); - if (lp != null && lp.height > 0) { - lp.height += getStatusBarHeight(context);//增高 - } - view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context), - view.getPaddingRight(), view.getPaddingBottom()); + ViewGroup.LayoutParams lp = view.getLayoutParams(); + if (lp != null && lp.height > 0) { + lp.height += getStatusBarHeight(context);//增高 } + view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context), + view.getPaddingRight(), view.getPaddingBottom()); } /** 增加View的高度以及paddingTop,增加的值为状态栏高度.一般是在沉浸式全屏给ToolBar用的 */ public static void setHeightAndPadding(Context context, View view) { - if (Build.VERSION.SDK_INT >= MIN_API) { - ViewGroup.LayoutParams lp = view.getLayoutParams(); - lp.height += getStatusBarHeight(context);//增高 - view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context), - view.getPaddingRight(), view.getPaddingBottom()); - } + ViewGroup.LayoutParams lp = view.getLayoutParams(); + lp.height += getStatusBarHeight(context);//增高 + view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context), + view.getPaddingRight(), view.getPaddingBottom()); } /** 增加View上边距(MarginTop)一般是给高度为 WARP_CONTENT 的小控件用的*/ public static void setMargin(Context context, View view) { - if (Build.VERSION.SDK_INT >= MIN_API) { - ViewGroup.LayoutParams lp = view.getLayoutParams(); - if (lp instanceof ViewGroup.MarginLayoutParams) { - ((ViewGroup.MarginLayoutParams) lp).topMargin += getStatusBarHeight(context);//增高 - } - view.setLayoutParams(lp); + ViewGroup.LayoutParams lp = view.getLayoutParams(); + if (lp instanceof ViewGroup.MarginLayoutParams) { + ((ViewGroup.MarginLayoutParams) lp).topMargin += getStatusBarHeight(context);//增高 } + view.setLayoutParams(lp); } /** * 创建假的透明栏 */ public static void setTranslucentView(ViewGroup container, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) { - if (Build.VERSION.SDK_INT >= 19) { - int mixtureColor = mixtureColor(color, alpha); - View translucentView = container.findViewById(android.R.id.custom); - if (translucentView == null && mixtureColor != 0) { - translucentView = new View(container.getContext()); - translucentView.setId(android.R.id.custom); - ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(container.getContext())); - container.addView(translucentView, lp); - } - if (translucentView != null) { - translucentView.setBackgroundColor(mixtureColor); - } + int mixtureColor = mixtureColor(color, alpha); + View translucentView = container.findViewById(android.R.id.custom); + if (translucentView == null && mixtureColor != 0) { + translucentView = new View(container.getContext()); + translucentView.setId(android.R.id.custom); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(container.getContext())); + container.addView(translucentView, lp); + } + if (translucentView != null) { + translucentView.setBackgroundColor(mixtureColor); } } diff --git a/app/src/main/java/com/scwang/refreshlayout/widget/RefreshContentHorizontal.java b/app/src/main/java/com/scwang/refresh/layout/widget/RefreshContentHorizontal.java similarity index 78% rename from app/src/main/java/com/scwang/refreshlayout/widget/RefreshContentHorizontal.java rename to app/src/main/java/com/scwang/refresh/layout/widget/RefreshContentHorizontal.java index 63e12333a..d65b97be9 100644 --- a/app/src/main/java/com/scwang/refreshlayout/widget/RefreshContentHorizontal.java +++ b/app/src/main/java/com/scwang/refresh/layout/widget/RefreshContentHorizontal.java @@ -1,13 +1,14 @@ -package com.scwang.refreshlayout.widget; +package com.scwang.refresh.layout.widget; import android.animation.ValueAnimator; -import android.support.annotation.NonNull; import android.view.View; import android.widget.AbsListView; +import androidx.annotation.NonNull; + +import com.scwang.smart.refresh.layout.util.SmartUtil; import com.scwang.smart.refresh.layout.wrapper.RefreshContentWrapper; -import static com.scwang.smartrefresh.layout.util.SmartUtil.scrollListBy; public class RefreshContentHorizontal extends RefreshContentWrapper { @@ -27,11 +28,11 @@ public ValueAnimator.AnimatorUpdateListener scrollContentWhenFinished(final int } @Override - public void onAnimationUpdate(ValueAnimator animation) { + public void onAnimationUpdate(@NonNull ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); try { if (mScrollableView instanceof AbsListView) { - scrollListBy((AbsListView) mScrollableView, value - mLastSpinner); + SmartUtil.scrollListBy((AbsListView) mScrollableView, value - mLastSpinner); } else { mScrollableView.scrollBy(value - mLastSpinner, 0); } diff --git a/app/src/main/java/com/scwang/refreshlayout/widget/ScrollBoundaryHorizontal.java b/app/src/main/java/com/scwang/refresh/layout/widget/ScrollBoundaryHorizontal.java similarity index 94% rename from app/src/main/java/com/scwang/refreshlayout/widget/ScrollBoundaryHorizontal.java rename to app/src/main/java/com/scwang/refresh/layout/widget/ScrollBoundaryHorizontal.java index f13889bde..ae480a8ad 100644 --- a/app/src/main/java/com/scwang/refreshlayout/widget/ScrollBoundaryHorizontal.java +++ b/app/src/main/java/com/scwang/refresh/layout/widget/ScrollBoundaryHorizontal.java @@ -1,12 +1,12 @@ -package com.scwang.refreshlayout.widget; +package com.scwang.refresh.layout.widget; import android.graphics.PointF; -import android.support.annotation.NonNull; import android.view.View; import android.view.ViewGroup; -import android.widget.AbsListView; -import com.scwang.smartrefresh.layout.util.SmartUtil; +import androidx.annotation.NonNull; + +import com.scwang.smart.refresh.layout.util.SmartUtil; /** * 滚动边界 diff --git a/app/src/main/java/com/scwang/refreshlayout/widget/SmartRefreshHorizontal.java b/app/src/main/java/com/scwang/refresh/layout/widget/SmartRefreshHorizontal.java similarity index 80% rename from app/src/main/java/com/scwang/refreshlayout/widget/SmartRefreshHorizontal.java rename to app/src/main/java/com/scwang/refresh/layout/widget/SmartRefreshHorizontal.java index b738fa0e4..ce8975ccd 100644 --- a/app/src/main/java/com/scwang/refreshlayout/widget/SmartRefreshHorizontal.java +++ b/app/src/main/java/com/scwang/refresh/layout/widget/SmartRefreshHorizontal.java @@ -1,28 +1,14 @@ -package com.scwang.refreshlayout.widget; +package com.scwang.refresh.layout.widget; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Interpolator; -import android.widget.FrameLayout; -import com.scwang.refreshlayout.R; +import com.scwang.refresh.layout.R; import com.scwang.smart.refresh.layout.api.RefreshComponent; -import com.scwang.smart.refresh.layout.api.RefreshFooter; -import com.scwang.smart.refresh.layout.api.RefreshHeader; -import com.scwang.smart.refresh.layout.api.RefreshLayout; -import com.scwang.smart.refresh.layout.constant.RefreshState; -import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; -import com.scwang.smart.refresh.layout.listener.OnMultiListener; -import com.scwang.smart.refresh.layout.listener.OnRefreshListener; -import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener; -import com.scwang.smart.refresh.layout.listener.ScrollBoundaryDecider; -import com.scwang.smart.refresh.layout.util.SmartUtil; -import com.scwang.smartrefresh.layout.SmartRefreshLayout; -import com.scwang.smartrefresh.layout.impl.ScrollBoundaryDeciderAdapter; +import com.scwang.smart.refresh.layout.simple.SimpleBoundaryDecider; +import com.scwang.smart.refresh.layout.SmartRefreshLayout; public class SmartRefreshHorizontal extends SmartRefreshLayout { @@ -35,7 +21,7 @@ public SmartRefreshHorizontal(Context context) { public SmartRefreshHorizontal(Context context, AttributeSet attrs) { super(context, attrs); setEnableAutoLoadMore(false); - setScrollBoundaryDecider(new ScrollBoundaryDeciderAdapter(){ + setScrollBoundaryDecider(new SimpleBoundaryDecider(){ @Override public boolean canRefresh(View content) { return ScrollBoundaryHorizontal.canRefresh(content, mActionEvent); diff --git a/app/src/main/java/com/scwang/refreshlayout/fragment/example/ThreeLevelExampleFragment.java b/app/src/main/java/com/scwang/refreshlayout/fragment/example/ThreeLevelExampleFragment.java deleted file mode 100644 index f7247429f..000000000 --- a/app/src/main/java/com/scwang/refreshlayout/fragment/example/ThreeLevelExampleFragment.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.scwang.refreshlayout.fragment.example; - - -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.scwang.refreshlayout.R; -import com.scwang.refreshlayout.adapter.BaseRecyclerAdapter; -import com.scwang.refreshlayout.adapter.SmartViewHolder; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; - -import java.util.Arrays; -import java.util.List; - -import static android.R.layout.simple_list_item_2; - -/** - * 三级刷新 - * A simple {@link Fragment} subclass. - */ -public class ThreeLevelExampleFragment extends Fragment { - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_example_three_level, container, false); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - final Toolbar toolbar = view.findViewById(R.id.toolbar); - toolbar.setNavigationOnClickListener(v -> getActivity().finish()); - - RecyclerView recyclerView = view.findViewById(R.id.recyclerView); - if (recyclerView != null) { - recyclerView.setAdapter(new BaseRecyclerAdapter(initData(), simple_list_item_2) { - @Override - protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) { - holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position)); - holder.text(android.R.id.text2, getString(R.string.item_example_number_abstract, position)); - holder.textColorId(android.R.id.text1, android.R.color.white); - holder.textColorId(android.R.id.text2, android.R.color.white); - } - }); - } - - RefreshLayout refreshLayout1 = view.findViewById(R.id.refreshLayout1); - if (refreshLayout1 != null) { - refreshLayout1.setOnRefreshListener((OnRefreshListener) refreshLayout -> refreshLayout.finishRefresh(1000)); - } - RefreshLayout refreshLayout2 = view.findViewById(R.id.refreshLayout2); - if (refreshLayout2 != null) { - refreshLayout2.getLayout().setEnabled(false); - refreshLayout2.setOnRefreshListener((OnRefreshListener) refreshLayout -> refreshLayout.finishRefresh(2000)); - } - } - - private List initData() { - return Arrays.asList(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null); - } -} diff --git a/app/src/main/res/drawable/ic_list_divider.xml b/app/src/main/res/drawable/ic_list_divider.xml index d7ab10ac7..1454d00ac 100644 --- a/app/src/main/res/drawable/ic_list_divider.xml +++ b/app/src/main/res/drawable/ic_list_divider.xml @@ -10,7 +10,7 @@ - + diff --git a/app/src/main/res/layout/activity_example_assign_code.xml b/app/src/main/res/layout/activity_example_assign_code.xml index 22a451ad7..876712817 100644 --- a/app/src/main/res/layout/activity_example_assign_code.xml +++ b/app/src/main/res/layout/activity_example_assign_code.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.example.AssignCodeExampleActivity"> + tools:context="com.scwang.refresh.layout.activity.example.AssignCodeExampleActivity"> - - - + diff --git a/app/src/main/res/layout/activity_example_assign_default.xml b/app/src/main/res/layout/activity_example_assign_default.xml index 93c335669..86f6a921f 100644 --- a/app/src/main/res/layout/activity_example_assign_default.xml +++ b/app/src/main/res/layout/activity_example_assign_default.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.example.AssignDefaultExampleActivity"> + tools:context="com.scwang.refresh.layout.activity.example.AssignDefaultExampleActivity"> - - @@ -22,6 +22,6 @@ android:padding="@dimen/dimenPaddingCommon" android:background="@android:color/white" android:text="@string/description_set_default_creator"/> - + diff --git a/app/src/main/res/layout/activity_example_assign_xml.xml b/app/src/main/res/layout/activity_example_assign_xml.xml index ef2625188..7b29ec3d3 100644 --- a/app/src/main/res/layout/activity_example_assign_xml.xml +++ b/app/src/main/res/layout/activity_example_assign_xml.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.example.AssignDefaultExampleActivity"> + tools:context="com.scwang.refresh.layout.activity.example.AssignDefaultExampleActivity"> - - - @@ -32,11 +32,11 @@ android:padding="@dimen/dimenPaddingCommon" android:background="@android:color/white" android:text="@string/description_define_in_xml"/> - - + diff --git a/app/src/main/res/layout/activity_example_basic.xml b/app/src/main/res/layout/activity_example_basic.xml index 16a4204b5..3bc0a8d7f 100644 --- a/app/src/main/res/layout/activity_example_basic.xml +++ b/app/src/main/res/layout/activity_example_basic.xml @@ -1,13 +1,13 @@ - + tools:context="com.scwang.refresh.layout.activity.example.BasicExampleActivity"> - - - - + - + diff --git a/app/src/main/res/layout/activity_example_custom.xml b/app/src/main/res/layout/activity_example_custom.xml index 9f9d3249e..e5154f6f7 100644 --- a/app/src/main/res/layout/activity_example_custom.xml +++ b/app/src/main/res/layout/activity_example_custom.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.example.CustomExampleActivity"> + tools:context="com.scwang.refresh.layout.activity.example.CustomExampleActivity"> - - @@ -23,6 +23,6 @@ android:background="@android:color/white" android:overScrollMode="never" tools:listitem="@android:layout/simple_list_item_2"/> - + diff --git a/app/src/main/res/layout/activity_example_i18n.xml b/app/src/main/res/layout/activity_example_i18n.xml index 85a9a03b0..d9b783127 100644 --- a/app/src/main/res/layout/activity_example_i18n.xml +++ b/app/src/main/res/layout/activity_example_i18n.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.example.I18nExampleActivity"> + tools:context="com.scwang.refresh.layout.activity.example.I18nExampleActivity"> - - @@ -23,6 +23,6 @@ android:background="@android:color/white" android:overScrollMode="never" tools:listitem="@android:layout/simple_list_item_2"/> - + diff --git a/app/src/main/res/layout/activity_example_listener.xml b/app/src/main/res/layout/activity_example_listener.xml index 2a594e784..dba074ba9 100644 --- a/app/src/main/res/layout/activity_example_listener.xml +++ b/app/src/main/res/layout/activity_example_listener.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.example.ListenerExampleActivity"> + tools:context="com.scwang.refresh.layout.activity.example.ListenerExampleActivity"> - - - + diff --git a/app/src/main/res/layout/activity_example_overscroll.xml b/app/src/main/res/layout/activity_example_overscroll.xml index 486eb4063..403e3c457 100644 --- a/app/src/main/res/layout/activity_example_overscroll.xml +++ b/app/src/main/res/layout/activity_example_overscroll.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.example.OverScrollExampleActivity"> + tools:context="com.scwang.refresh.layout.activity.example.OverScrollExampleActivity"> - - @@ -38,6 +38,6 @@ android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent"/> - + diff --git a/app/src/main/res/layout/activity_example_region.xml b/app/src/main/res/layout/activity_example_region.xml index 807201290..046867d08 100644 --- a/app/src/main/res/layout/activity_example_region.xml +++ b/app/src/main/res/layout/activity_example_region.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.example.NestedLayoutExampleActivity"> + tools:context="com.scwang.refresh.layout.activity.example.NestedLayoutExampleActivity"> - - - - + diff --git a/app/src/main/res/layout/activity_example_snaphelper.xml b/app/src/main/res/layout/activity_example_snaphelper.xml index b3d84b2c0..b9cb1ddc6 100644 --- a/app/src/main/res/layout/activity_example_snaphelper.xml +++ b/app/src/main/res/layout/activity_example_snaphelper.xml @@ -5,9 +5,9 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.example.SnapHelperExampleActivity"> + tools:context="com.scwang.refresh.layout.activity.example.SnapHelperExampleActivity"> - - - + - - - + diff --git a/app/src/main/res/layout/activity_experiment.xml b/app/src/main/res/layout/activity_experiment.xml index cb3da6d70..7b66a6879 100644 --- a/app/src/main/res/layout/activity_experiment.xml +++ b/app/src/main/res/layout/activity_experiment.xml @@ -1,12 +1,9 @@ - + android:layout_height="match_parent"> - @@ -14,40 +11,40 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" - android:text="Content"/> + android:text="@string/experiment_content"/> + android:text="@string/experiment_footer"/> - + android:text="@string/experiment_footer"/> + - + - + - + - + - + diff --git a/app/src/main/res/layout/activity_fly_refresh.xml b/app/src/main/res/layout/activity_fly_refresh.xml index ee122cd06..5809cead5 100644 --- a/app/src/main/res/layout/activity_fly_refresh.xml +++ b/app/src/main/res/layout/activity_fly_refresh.xml @@ -1,11 +1,11 @@ - + tools:context="com.scwang.refresh.layout.activity.style.FlyRefreshStyleActivity"> - - - - - + + - - - - + - - + diff --git a/app/src/main/res/layout/activity_index_main.xml b/app/src/main/res/layout/activity_index_main.xml index fd6e059a7..c38c0aed7 100644 --- a/app/src/main/res/layout/activity_index_main.xml +++ b/app/src/main/res/layout/activity_index_main.xml @@ -6,20 +6,21 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.IndexMainActivity"> + tools:context="com.scwang.refresh.layout.activity.IndexMainActivity"> - - - + tools:context="com.scwang.refresh.layout.activity.practice.BannerPracticeActivity"> - - - - + - + tools:context="com.scwang.refresh.layout.activity.practice.FeedListPracticeActivity"> - - - @@ -33,7 +33,7 @@ android:orientation="vertical" android:gravity="center_horizontal"> - - + - - + diff --git a/app/src/main/res/layout/activity_practice_profile.xml b/app/src/main/res/layout/activity_practice_profile.xml index 625072b43..154621a26 100644 --- a/app/src/main/res/layout/activity_practice_profile.xml +++ b/app/src/main/res/layout/activity_practice_profile.xml @@ -6,9 +6,9 @@ android:layout_height="match_parent" android:orientation="vertical" android:background="@color/colorPrimary" - tools:context="com.scwang.refreshlayout.activity.practice.ProfilePracticeActivity"> + tools:context="com.scwang.refresh.layout.activity.practice.ProfilePracticeActivity"> - - + - + tools:context="com.scwang.refresh.layout.activity.practice.QQBrowserPracticeActivity"> - @@ -17,7 +17,7 @@ android:id="@+id/loading" android:layout_width="match_parent" android:layout_height="match_parent"> - - + diff --git a/app/src/main/res/layout/activity_practice_repast.xml b/app/src/main/res/layout/activity_practice_repast.xml index 9acbb1b8c..9aee10eff 100644 --- a/app/src/main/res/layout/activity_practice_repast.xml +++ b/app/src/main/res/layout/activity_practice_repast.xml @@ -5,9 +5,9 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorBackgroundDark" - tools:context="com.scwang.refreshlayout.activity.practice.RepastPracticeActivity"> + tools:context="com.scwang.refresh.layout.activity.practice.RepastPracticeActivity"> - - - - + - + tools:context="com.scwang.refresh.layout.activity.practice.WebViewPracticeActivity"> - - - + - + tools:context="com.scwang.refresh.layout.activity.practice.WeiboPracticeActivity"> - - - - - + - + - + - - - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_bezier.xml b/app/src/main/res/layout/activity_style_bezier.xml index 0f355ce9d..26533467c 100644 --- a/app/src/main/res/layout/activity_style_bezier.xml +++ b/app/src/main/res/layout/activity_style_bezier.xml @@ -4,15 +4,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.scwang.refreshlayout.activity.style.BezierRadarStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.BezierRadarStyleActivity" android:orientation="vertical"> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_circle.xml b/app/src/main/res/layout/activity_style_circle.xml index ceaa0fb44..94aa1bc7d 100644 --- a/app/src/main/res/layout/activity_style_circle.xml +++ b/app/src/main/res/layout/activity_style_circle.xml @@ -4,15 +4,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.scwang.refreshlayout.activity.style.BezierCircleStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.BezierCircleStyleActivity" android:orientation="vertical"> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_classics.xml b/app/src/main/res/layout/activity_style_classics.xml index 55af59728..061baf683 100644 --- a/app/src/main/res/layout/activity_style_classics.xml +++ b/app/src/main/res/layout/activity_style_classics.xml @@ -5,15 +5,15 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorBackgroundDark" - tools:context="com.scwang.refreshlayout.activity.style.ClassicsStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.ClassicsStyleActivity" android:orientation="vertical"> - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_delivery.xml b/app/src/main/res/layout/activity_style_delivery.xml index 1c852aa1f..7844cefcf 100644 --- a/app/src/main/res/layout/activity_style_delivery.xml +++ b/app/src/main/res/layout/activity_style_delivery.xml @@ -5,17 +5,17 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f0f0f0" - tools:context="com.scwang.refreshlayout.activity.style.DeliveryStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.DeliveryStyleActivity" android:orientation="vertical"> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_dropbox.xml b/app/src/main/res/layout/activity_style_dropbox.xml index 4fd11b808..85a8519ed 100644 --- a/app/src/main/res/layout/activity_style_dropbox.xml +++ b/app/src/main/res/layout/activity_style_dropbox.xml @@ -4,15 +4,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.scwang.refreshlayout.activity.style.BezierRadarStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.BezierRadarStyleActivity" android:orientation="vertical"> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_fungame_battlecity.xml b/app/src/main/res/layout/activity_style_fungame_battlecity.xml index ae4cc858b..950da774d 100644 --- a/app/src/main/res/layout/activity_style_fungame_battlecity.xml +++ b/app/src/main/res/layout/activity_style_fungame_battlecity.xml @@ -4,15 +4,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.scwang.refreshlayout.activity.style.BezierRadarStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.BezierRadarStyleActivity" android:orientation="vertical"> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_fungame_hitblock.xml b/app/src/main/res/layout/activity_style_fungame_hitblock.xml index ede4d8870..ec59451e4 100644 --- a/app/src/main/res/layout/activity_style_fungame_hitblock.xml +++ b/app/src/main/res/layout/activity_style_fungame_hitblock.xml @@ -4,15 +4,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.scwang.refreshlayout.activity.style.BezierRadarStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.BezierRadarStyleActivity" android:orientation="vertical"> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_material.xml b/app/src/main/res/layout/activity_style_material.xml index 904c90727..dbb095391 100644 --- a/app/src/main/res/layout/activity_style_material.xml +++ b/app/src/main/res/layout/activity_style_material.xml @@ -4,15 +4,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.scwang.refreshlayout.activity.style.MaterialStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.MaterialStyleActivity" android:orientation="vertical"> - - - - - + diff --git a/app/src/main/res/layout/activity_style_phoenix.xml b/app/src/main/res/layout/activity_style_phoenix.xml index eca266843..ac9cb54af 100644 --- a/app/src/main/res/layout/activity_style_phoenix.xml +++ b/app/src/main/res/layout/activity_style_phoenix.xml @@ -1,19 +1,19 @@ - + tools:context="com.scwang.refresh.layout.activity.style.PhoenixStyleActivity"> - - - - - + + - - - - + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_storehouse.xml b/app/src/main/res/layout/activity_style_storehouse.xml index 0523a09ab..7ab57c508 100644 --- a/app/src/main/res/layout/activity_style_storehouse.xml +++ b/app/src/main/res/layout/activity_style_storehouse.xml @@ -4,15 +4,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.scwang.refreshlayout.activity.style.BezierRadarStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.BezierRadarStyleActivity" android:orientation="vertical"> - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_taurus.xml b/app/src/main/res/layout/activity_style_taurus.xml index fb4542dfb..a2f21557e 100644 --- a/app/src/main/res/layout/activity_style_taurus.xml +++ b/app/src/main/res/layout/activity_style_taurus.xml @@ -1,19 +1,19 @@ - + tools:context="com.scwang.refresh.layout.activity.style.TaurusStyleActivity"> - - - - - + + - - - - + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_style_water_drop.xml b/app/src/main/res/layout/activity_style_water_drop.xml index 6dc43ac70..7b1b4f759 100644 --- a/app/src/main/res/layout/activity_style_water_drop.xml +++ b/app/src/main/res/layout/activity_style_water_drop.xml @@ -4,15 +4,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.scwang.refreshlayout.activity.style.WaterDropStyleActivity" + tools:context="com.scwang.refresh.layout.activity.style.WaterDropStyleActivity" android:orientation="vertical"> - - - - - + diff --git a/app/src/main/res/layout/activity_style_wave_swipe.xml b/app/src/main/res/layout/activity_style_wave_swipe.xml index 59f750f1f..ca9154a8d 100644 --- a/app/src/main/res/layout/activity_style_wave_swipe.xml +++ b/app/src/main/res/layout/activity_style_wave_swipe.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.activity.style.WaveSwipeStyleActivity"> + tools:context="com.scwang.refresh.layout.activity.style.WaveSwipeStyleActivity"> - - - - - + diff --git a/app/src/main/res/layout/common_independence_recycler.xml b/app/src/main/res/layout/common_independence_recycler.xml index a0c6ca851..6b0cfb358 100644 --- a/app/src/main/res/layout/common_independence_recycler.xml +++ b/app/src/main/res/layout/common_independence_recycler.xml @@ -4,25 +4,25 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.PureScrollExampleFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.PureScrollExampleFragment"> - - - - + diff --git a/app/src/main/res/layout/common_loading.xml b/app/src/main/res/layout/common_loading.xml index d6bffc4a7..aef516181 100644 --- a/app/src/main/res/layout/common_loading.xml +++ b/app/src/main/res/layout/common_loading.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.PureScrollExampleFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.PureScrollExampleFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.BottomSheetExampleFragment"> - - - - + diff --git a/app/src/main/res/layout/fragment_example_disallow_intercept.xml b/app/src/main/res/layout/fragment_example_disallow_intercept.xml index 482d2f60a..8ee1e5e0e 100644 --- a/app/src/main/res/layout/fragment_example_disallow_intercept.xml +++ b/app/src/main/res/layout/fragment_example_disallow_intercept.xml @@ -1,12 +1,12 @@ - + tools:context="com.scwang.refresh.layout.fragment.example.DisallowInterceptExampleFragment"> - @@ -16,16 +16,16 @@ android:text="需求是内容控件长按后显示当前手指移动的坐标,比如股票分时k线图" android:layout_height="wrap_content" /> - - - + - + diff --git a/app/src/main/res/layout/fragment_example_emptylayout.xml b/app/src/main/res/layout/fragment_example_emptylayout.xml index 376cd93a3..550fe0199 100644 --- a/app/src/main/res/layout/fragment_example_emptylayout.xml +++ b/app/src/main/res/layout/fragment_example_emptylayout.xml @@ -4,14 +4,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.EmptyLayoutExampleFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.EmptyLayoutExampleFragment"> - - @@ -20,13 +20,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white"> - - + diff --git a/app/src/main/res/layout/fragment_example_emptylayout_inner.xml b/app/src/main/res/layout/fragment_example_emptylayout_inner.xml index 1319ceb41..e8c67d29a 100644 --- a/app/src/main/res/layout/fragment_example_emptylayout_inner.xml +++ b/app/src/main/res/layout/fragment_example_emptylayout_inner.xml @@ -4,21 +4,21 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.EmptyLayoutExampleFragmentInner"> + tools:context="com.scwang.refresh.layout.fragment.example.EmptyLayoutExampleFragmentInner"> - - - - + diff --git a/app/src/main/res/layout/fragment_example_emptylayout_outer.xml b/app/src/main/res/layout/fragment_example_emptylayout_outer.xml index 138853a90..f3f3cda48 100644 --- a/app/src/main/res/layout/fragment_example_emptylayout_outer.xml +++ b/app/src/main/res/layout/fragment_example_emptylayout_outer.xml @@ -4,9 +4,9 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.EmptyLayoutExampleFragmentOuter"> + tools:context="com.scwang.refresh.layout.fragment.example.EmptyLayoutExampleFragmentOuter"> - @@ -14,18 +14,18 @@ - - - + diff --git a/app/src/main/res/layout/fragment_example_horizontal.xml b/app/src/main/res/layout/fragment_example_horizontal.xml index b9da14076..9ebafe764 100644 --- a/app/src/main/res/layout/fragment_example_horizontal.xml +++ b/app/src/main/res/layout/fragment_example_horizontal.xml @@ -4,16 +4,16 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.HorizontalExampleFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.HorizontalExampleFragment"> - - - - - + diff --git a/app/src/main/res/layout/fragment_example_nestedscroll.xml b/app/src/main/res/layout/fragment_example_nestedscroll.xml index 9ac7f1711..4aaa89f39 100644 --- a/app/src/main/res/layout/fragment_example_nestedscroll.xml +++ b/app/src/main/res/layout/fragment_example_nestedscroll.xml @@ -1,19 +1,19 @@ - + tools:context="com.scwang.refresh.layout.fragment.example.NestedScrollExampleFragment"> - - - - - + + - - - - + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_example_nestedscroll_integral.xml b/app/src/main/res/layout/fragment_example_nestedscroll_integral.xml index 633f91316..1f795cb4a 100644 --- a/app/src/main/res/layout/fragment_example_nestedscroll_integral.xml +++ b/app/src/main/res/layout/fragment_example_nestedscroll_integral.xml @@ -5,32 +5,32 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.NestedScrollExampleFragmentIntegral"> + tools:context="com.scwang.refresh.layout.fragment.example.NestedScrollExampleFragmentIntegral"> - - - - - + @@ -39,20 +39,20 @@ - - - - + - - - - - - + - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_example_nestedscroll_view_pager.xml b/app/src/main/res/layout/fragment_example_nestedscroll_view_pager.xml index de8b4a985..3ae5e89fc 100644 --- a/app/src/main/res/layout/fragment_example_nestedscroll_view_pager.xml +++ b/app/src/main/res/layout/fragment_example_nestedscroll_view_pager.xml @@ -1,19 +1,19 @@ - + tools:context="com.scwang.refresh.layout.fragment.example.NestedScrollExampleFragmentViewPager"> - - - - - + + - - + @@ -46,18 +46,18 @@ - + - + - + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_example_purescroll.xml b/app/src/main/res/layout/fragment_example_purescroll.xml index 80893ffad..2db344c9d 100644 --- a/app/src/main/res/layout/fragment_example_purescroll.xml +++ b/app/src/main/res/layout/fragment_example_purescroll.xml @@ -4,26 +4,26 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.PureScrollExampleFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.PureScrollExampleFragment"> - - - - + diff --git a/app/src/main/res/layout/fragment_example_purescroll_header.xml b/app/src/main/res/layout/fragment_example_purescroll_header.xml index 80ea25535..4cf63aacd 100644 --- a/app/src/main/res/layout/fragment_example_purescroll_header.xml +++ b/app/src/main/res/layout/fragment_example_purescroll_header.xml @@ -4,29 +4,29 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.PureScrollExampleFragmentHeader"> + tools:context="com.scwang.refresh.layout.fragment.example.PureScrollExampleFragmentHeader"> - - - - - + diff --git a/app/src/main/res/layout/fragment_example_staggered_grid.xml b/app/src/main/res/layout/fragment_example_staggered_grid.xml index 4e761fdf9..a46771bce 100644 --- a/app/src/main/res/layout/fragment_example_staggered_grid.xml +++ b/app/src/main/res/layout/fragment_example_staggered_grid.xml @@ -4,27 +4,27 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.StaggeredGridExampleFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.StaggeredGridExampleFragment"> - - - - + diff --git a/app/src/main/res/layout/fragment_example_three_level.xml b/app/src/main/res/layout/fragment_example_three_level.xml deleted file mode 100644 index 55721cb3d..000000000 --- a/app/src/main/res/layout/fragment_example_three_level.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/fragment_example_viewpager.xml b/app/src/main/res/layout/fragment_example_viewpager.xml index 8a6268166..0a75cbb05 100644 --- a/app/src/main/res/layout/fragment_example_viewpager.xml +++ b/app/src/main/res/layout/fragment_example_viewpager.xml @@ -4,14 +4,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.ViewPagerExampleFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.ViewPagerExampleFragment"> - - - - - + diff --git a/app/src/main/res/layout/fragment_flexbox_layout_manager.xml b/app/src/main/res/layout/fragment_flexbox_layout_manager.xml index cc1912119..a59783a93 100644 --- a/app/src/main/res/layout/fragment_flexbox_layout_manager.xml +++ b/app/src/main/res/layout/fragment_flexbox_layout_manager.xml @@ -4,22 +4,22 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.FlexBoxLayoutManagerFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.FlexBoxLayoutManagerFragment"> - - - - + diff --git a/app/src/main/res/layout/fragment_no_more_data_example.xml b/app/src/main/res/layout/fragment_no_more_data_example.xml index 2becf8062..30609212a 100644 --- a/app/src/main/res/layout/fragment_no_more_data_example.xml +++ b/app/src/main/res/layout/fragment_no_more_data_example.xml @@ -4,15 +4,15 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.example.NoMoreDataExampleFragment"> + tools:context="com.scwang.refresh.layout.fragment.example.NoMoreDataExampleFragment"> - - - - - - + diff --git a/app/src/main/res/layout/fragment_practice_instant.xml b/app/src/main/res/layout/fragment_practice_instant.xml index 394c70bb2..554e07181 100644 --- a/app/src/main/res/layout/fragment_practice_instant.xml +++ b/app/src/main/res/layout/fragment_practice_instant.xml @@ -4,17 +4,17 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.practice.InstantPracticeFragment"> + tools:context="com.scwang.refresh.layout.fragment.practice.InstantPracticeFragment"> - - + - - - - - + + diff --git a/app/src/main/res/layout/fragment_practice_second_floor.xml b/app/src/main/res/layout/fragment_practice_second_floor.xml index 9931141ce..6b2b591ff 100644 --- a/app/src/main/res/layout/fragment_practice_second_floor.xml +++ b/app/src/main/res/layout/fragment_practice_second_floor.xml @@ -4,15 +4,15 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.practice.SecondFloorPracticeFragment"> + tools:context="com.scwang.refresh.layout.fragment.practice.SecondFloorPracticeFragment"> - - @@ -34,18 +34,18 @@ android:contentDescription="@string/app_name" android:scaleType="centerCrop" android:src="@mipmap/image_second_floor_content"/> - + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/> - - + - - + - - + diff --git a/app/src/main/res/layout/fragment_practice_twolevel.xml b/app/src/main/res/layout/fragment_practice_twolevel.xml index adaaaa7ac..fe72da9e6 100644 --- a/app/src/main/res/layout/fragment_practice_twolevel.xml +++ b/app/src/main/res/layout/fragment_practice_twolevel.xml @@ -4,35 +4,35 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.practice.TwoLevelPracticeFragment"> + tools:context="com.scwang.refresh.layout.fragment.practice.TwoLevelPracticeFragment"> - - + - - - - - + - + diff --git a/app/src/main/res/layout/fragment_refresh_example.xml b/app/src/main/res/layout/fragment_refresh_example.xml index 8eed796f7..04c5d7be5 100644 --- a/app/src/main/res/layout/fragment_refresh_example.xml +++ b/app/src/main/res/layout/fragment_refresh_example.xml @@ -1,12 +1,12 @@ - + tools:context="com.scwang.refresh.layout.fragment.index.RefreshExampleFragment"> - - - + diff --git a/app/src/main/res/layout/fragment_refresh_practive.xml b/app/src/main/res/layout/fragment_refresh_practive.xml index d3eef6506..f9d785e57 100644 --- a/app/src/main/res/layout/fragment_refresh_practive.xml +++ b/app/src/main/res/layout/fragment_refresh_practive.xml @@ -4,9 +4,9 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="com.scwang.refreshlayout.fragment.index.RefreshPracticeFragment"> + tools:context="com.scwang.refresh.layout.fragment.index.RefreshPracticeFragment"> - @@ -20,7 +20,7 @@ - + tools:context="com.scwang.refresh.layout.fragment.index.RefreshStylesFragment"> - @@ -22,7 +22,7 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/item_movie_item.xml b/app/src/main/res/layout/item_movie_item.xml index fd0a90ca0..c45a063d8 100644 --- a/app/src/main/res/layout/item_movie_item.xml +++ b/app/src/main/res/layout/item_movie_item.xml @@ -1,6 +1,5 @@ diff --git a/app/src/main/res/layout/item_practice_repast.xml b/app/src/main/res/layout/item_practice_repast.xml index 1c06c2f21..56fdf4398 100644 --- a/app/src/main/res/layout/item_practice_repast.xml +++ b/app/src/main/res/layout/item_practice_repast.xml @@ -26,8 +26,7 @@ + android:layout_height="55dp"/> - + tools:context="com.scwang.refresh.layout.activity.example.ListenerExampleActivity"> - + diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 20732f6ca..2b950ec82 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -155,19 +155,19 @@ 1.可以在Android Studio中的预览窗口预览效果\n 2.优先级高于 【全局默认】但是低于 【JavaCode】\n\n 代码示例:\n - \n - \t\n \t\n - \t\n - \n + \n ]]> 这是使用定制Header和Footer的第三种方法-代码设置\n\n 本方法是实际项目中比较少用的方法,其特点有:\n\n diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e22804bee..bc3ebdf97 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -151,19 +151,19 @@ 1.Can preview in Android Studio\n 2.Priority is higher than [global default] but below [JavaCode]\n\n Usage:\n - \n - \t\n \t\n - \t\n - \n + \n ]]> \n Usage: \n @@ -178,6 +178,8 @@ Hello blank fragment + Content + Footer diff --git a/app/src/test/java/com/scwang/refreshlayout/ExampleUnitTest.java b/app/src/test/java/com/scwang/refresh/ExampleUnitTest.java similarity index 69% rename from app/src/test/java/com/scwang/refreshlayout/ExampleUnitTest.java rename to app/src/test/java/com/scwang/refresh/ExampleUnitTest.java index 082813c6c..19e87702e 100644 --- a/app/src/test/java/com/scwang/refreshlayout/ExampleUnitTest.java +++ b/app/src/test/java/com/scwang/refresh/ExampleUnitTest.java @@ -1,8 +1,8 @@ -package com.scwang.refreshlayout; +package com.scwang.refresh; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). @@ -11,7 +11,7 @@ */ public class ExampleUnitTest { @Test - public void addition_isCorrect() throws Exception { + public void addition_isCorrect() { assertEquals(4, 2 + 2); } } \ No newline at end of file diff --git a/art/md_property.md b/art/md_property.md index 125334727..237d6bc87 100644 --- a/art/md_property.md +++ b/art/md_property.md @@ -17,10 +17,10 @@ public class RefreshActivity extends Activity { refreshLayout.setFooterHeight(100);//Footer标准高度(显示上拉高度>=标准高度 触发加载) refreshLayout.setFooterHeightPx(100);//同上-像素为单位 (V1.1.0删除) - refreshLayout.setFooterHeaderInsetStart(0);//设置 Header 起始位置偏移量 1.0.5 - refreshLayout.setFooterHeaderInsetStartPx(0);//同上-像素为单位 1.0.5 (V1.1.0删除) - refreshLayout.setFooterFooterInsetStart(0);//设置 Footer 起始位置偏移量 1.0.5 - refreshLayout.setFooterFooterInsetStartPx(0);//同上-像素为单位 1.0.5 (V1.1.0删除) + refreshLayout.setHeaderInsetStart(0);//设置 Header 起始位置偏移量 1.0.5 + refreshLayout.setHeaderInsetStartPx(0);//同上-像素为单位 1.0.5 (V1.1.0删除) + refreshLayout.setFooterInsetStart(0);//设置 Footer 起始位置偏移量 1.0.5 + refreshLayout.setFooterInsetStartPx(0);//同上-像素为单位 1.0.5 (V1.1.0删除) refreshLayout.setHeaderMaxDragRate(2);//最大显示下拉高度/Header标准高度 refreshLayout.setFooterMaxDragRate(2);//最大显示下拉高度/Footer标准高度 @@ -47,9 +47,9 @@ public class RefreshActivity extends Activity { refreshLayout.setDisableContentWhenRefresh(false);//是否在刷新的时候禁止列表的操作 refreshLayout.setDisableContentWhenLoading(false);//是否在加载的时候禁止列表的操作 - refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener());//设置多功能监听器 + refreshLayout.setOnMultiListener(new SimpleMultiListener());//设置多功能监听器 refreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDecider());//设置滚动边界判断 - refreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDeciderAdapter());//自定义滚动边界 + refreshLayout.setScrollBoundaryDecider(new SimpleBoundaryDecider());//自定义滚动边界 refreshLayout.setRefreshHeader(new ClassicsHeader(context));//设置Header refreshLayout.setRefreshFooter(new ClassicsFooter(context));//设置Footer @@ -410,7 +410,7 @@ xml代码设置 |setOnRefreshListener|OnRefreshListener|设置刷新监听器(不设置,默认3秒后关刷新)| |setOnLoadMoreListener|OnLoadMoreListener|设置加载监听器(不设置,默认3秒后关加载)| |setOnRefreshLoadMoreListener|OnRefreshLoadMoreListener|同时设置上面两个监听器| -|setOnMultiPurposeListener|OnMultiPurposeListener|设置多功能监听器| +|setOnMultiListener|OnMultiPurposeListener|设置多功能监听器| |setLoadMoreFinished|boolean|设置全部数据加载完成,之后不会触发加载事件| |setScrollBoundaryDecider|boundary|设置滚动边界判断| |finishRefresh|(int delayed)|完成刷新,结束刷新动画| @@ -465,4 +465,4 @@ xml代码设置 |setEnableLastTime|boolean|是否显示上次更新时间(默认true)| |setTextSizeTitle|dimension|标题文字大小(默认16sp)| |setTextSizeTime|dimension|时间文字大小(默认12sp)| -|setLastUpdateText|string|手动设置更新时间,将不会自动更新时间| \ No newline at end of file +|setLastUpdateText|string|手动设置更新时间,将不会自动更新时间| diff --git a/art/md_update.md b/art/md_update.md index 485b74a94..4d93c42cf 100644 --- a/art/md_update.md +++ b/art/md_update.md @@ -1,12 +1,19 @@ # 更新日志 -## V 2.0.0 (开发中) +## V 3.0.0-alpha +>抛弃 support 使用 androidx +>修复问题:复制kernel代码另外起包名后,加载更多时候recyclerview无法流畅滚动 +>修复问题:V2.1.0版本,demo案例,使用官方主题下拉刷新操作的时候,视图不可以滑动,但是响应点击,v2.0.6,v2.0.5没有这样的问题 +>修复问题:NullPointerException: Attempt to invoke interface method 'onAutoRefreshAnimationEnd()' on a null object reference +>修复问题:当场递归死循环, java.lang.StackOverflowError + +## V 2.0.0 >添加:srlStyle 主题支持 >分包:layout = kernel + two-level + header-classics + header-radar + header-falsify + footer-classics + footer-ball >修改:方法 OnMultiPurposeListener -> setOnMultiListener >修改:包名 com.scwang.smartrefresh -> com.scwang.smart.refresh >修改:类名 smartrefresh.layout.listener.OnMultiPurposeListener -> smart.refresh.layout.listener.OnMultiListener ->修改:类名 smartrefresh.layout.listener.SimpleMultiPurposeListener -> smart.refresh.layout.simple.SimpleMultiListener +>修改:类名 smartrefresh.layout.listener.SimpleMultiListener -> smart.refresh.layout.simple.SimpleMultiListener >添加:属性 srlBottomPullUpToCloseRate setBottomPullUpToCloseRate >回归:回归部分被去掉的API如:isRefreshing isLoading diff --git a/bintrayUpload.bat b/bintrayUpload.bat deleted file mode 100644 index 12c7480ae..000000000 --- a/bintrayUpload.bat +++ /dev/null @@ -1 +0,0 @@ -gradlew clean build bintrayUpload -PbintrayUser=scwang90 -PbintrayKey=%1 -PdryRun=false \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3941d9b26..4a467485f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,20 +3,21 @@ buildscript { repositories { google() - jcenter() + mavenCentral() + gradlePluginPortal() + maven { url 'https://maven.aliyun.com/repository/google' } // 兼容旧版 google + maven { url 'https://maven.aliyun.com/repository/jcenter' } // 兼容旧版 jcenter } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - classpath 'com.novoda:bintray-release:0.9.1' + classpath 'com.android.tools.build:gradle:7.2.2' } } allprojects { repositories { google() - jcenter() + mavenCentral() + gradlePluginPortal() } tasks.withType(Javadoc) { @@ -39,7 +40,7 @@ task clean(type: Delete) { delete rootProject.buildDir } -def file = 'local.properties' +def file = "${rootProject.projectDir}\\local.properties" if (new File(file).exists()) { Properties properties = new Properties() properties.load(new FileInputStream(file)) @@ -139,8 +140,14 @@ if (new File(file).exists()) { url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl credentials { // 这里就是之前在 issues.sonatype.org 注册的账号 - username "${properties["sonatype.username"]}" - password new String(Base64.mimeDecoder.decode("${properties["sonatype.password"]}"), "UTF-8") + // username "${properties["sonatype.username"]}" + // password new String(Base64.mimeDecoder.decode("${properties["sonatype.password"]}"), "UTF-8") + // 后期改用 Token 认证 + def tokenUsername = "${System.getenv('ossrhUsername')}" + def tokenPassword = "${System.getenv('ossrhPassword')}" + println "tokenUsername=\u001B[32m$tokenUsername\u001B[0m;tokenPassword=\u001B[32m$tokenPassword\u001B[0m" + username tokenUsername + password tokenPassword } } } diff --git a/gradle.properties b/gradle.properties index 69576ac3e..3ba267b31 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,14 +16,17 @@ org.gradle.jvmargs=-Xmx1536m # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true +android.useAndroidX=true +android.enableJetifier=true + SMART_USER=scwang90 SMART_GROUP=com.scwang.smart -SMART_VERSION=2.0.5 -# -SNAPSHOT +SMART_VERSION=3.0.0-alpha + SMART_PUBLISH=false SMART_GROUP_MVN=io.github.scwang90 SMART_EMAIL=scwang90@hotmail.com signing.keyId=888F6528 signing.password= -signing.secretKeyRingFile=/Users/scwang/.gnupg/secret-rsa.gpg +signing.secretKeyRingFile=../secret-rsa.gpg diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f27371572..7ae80cefc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip diff --git a/refresh-drawable-paint/build.gradle b/refresh-drawable-paint/build.gradle index 3411ebdcc..a1fda499f 100644 --- a/refresh-drawable-paint/build.gradle +++ b/refresh-drawable-paint/build.gradle @@ -4,16 +4,15 @@ description = 'common drawables for refresh animations' android { - compileSdkVersion 28 + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { release { @@ -28,10 +27,10 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - testImplementation 'junit:junit:4.12' - compileOnly 'com.android.support:support-annotations:28.0.0' + compileOnly 'androidx.annotation:annotation:1.9.1' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/refresh-drawable-paint/src/androidTest/java/com/scwang/smart/drawable/ExampleInstrumentedTest.java b/refresh-drawable-paint/src/androidTest/java/com/scwang/smart/drawable/ExampleInstrumentedTest.java index f26cf7c9d..8e21262d7 100644 --- a/refresh-drawable-paint/src/androidTest/java/com/scwang/smart/drawable/ExampleInstrumentedTest.java +++ b/refresh-drawable-paint/src/androidTest/java/com/scwang/smart/drawable/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.scwang.smart.drawable; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumentation test, which will execute on an Android device. @@ -17,10 +18,10 @@ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @Test - public void useAppContext() throws Exception { + public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.scwang.smartrefresh.layout.test", appContext.getPackageName()); + assertEquals("com.scwang.smart.drawable.test", appContext.getPackageName()); } } diff --git a/refresh-drawable-paint/src/main/java/com/scwang/smart/drawable/PaintDrawable.java b/refresh-drawable-paint/src/main/java/com/scwang/smart/drawable/PaintDrawable.java index a3c1ee925..84041b994 100644 --- a/refresh-drawable-paint/src/main/java/com/scwang/smart/drawable/PaintDrawable.java +++ b/refresh-drawable-paint/src/main/java/com/scwang/smart/drawable/PaintDrawable.java @@ -34,6 +34,7 @@ public void setColorFilter(ColorFilter cf) { } @Override + @Deprecated public int getOpacity() { return PixelFormat.TRANSLUCENT; } diff --git a/refresh-drawable-paint/src/main/java/com/scwang/smart/drawable/ProgressDrawable.java b/refresh-drawable-paint/src/main/java/com/scwang/smart/drawable/ProgressDrawable.java index 6dfd59de3..dda33a3bc 100644 --- a/refresh-drawable-paint/src/main/java/com/scwang/smart/drawable/ProgressDrawable.java +++ b/refresh-drawable-paint/src/main/java/com/scwang/smart/drawable/ProgressDrawable.java @@ -7,7 +7,8 @@ import android.graphics.Rect; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; /** * 旋转动画 @@ -31,7 +32,7 @@ public ProgressDrawable() { } @Override - public void onAnimationUpdate(ValueAnimator animation) { + public void onAnimationUpdate(@NonNull ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); mProgressDegree = 30 * (value / 30); final Drawable drawable = ProgressDrawable.this; diff --git a/refresh-drawable-paint/src/test/java/com/scwang/smart/drawable/ExampleUnitTest.java b/refresh-drawable-paint/src/test/java/com/scwang/smart/drawable/ExampleUnitTest.java index 03ae0c30f..d4c51452c 100644 --- a/refresh-drawable-paint/src/test/java/com/scwang/smart/drawable/ExampleUnitTest.java +++ b/refresh-drawable-paint/src/test/java/com/scwang/smart/drawable/ExampleUnitTest.java @@ -11,7 +11,7 @@ */ public class ExampleUnitTest { @Test - public void addition_isCorrect() throws Exception { + public void addition_isCorrect() { assertEquals(4, 2 + 2); } } \ No newline at end of file diff --git a/refresh-drawable-path/build.gradle b/refresh-drawable-path/build.gradle index 00d5aa720..4845124a6 100644 --- a/refresh-drawable-path/build.gradle +++ b/refresh-drawable-path/build.gradle @@ -4,16 +4,15 @@ description = 'path drawables for refresh animations' android { - compileSdkVersion 28 + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { release { @@ -28,11 +27,12 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - testImplementation 'junit:junit:4.12' api project(':refresh-drawable-paint') - compileOnly 'com.android.support:support-v4:28.0.0' + + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/refresh-drawable-path/src/androidTest/java/com/scwang/smart/drawable/ExampleInstrumentedTest.java b/refresh-drawable-path/src/androidTest/java/com/scwang/smart/drawable/ExampleInstrumentedTest.java index f26cf7c9d..8e21262d7 100644 --- a/refresh-drawable-path/src/androidTest/java/com/scwang/smart/drawable/ExampleInstrumentedTest.java +++ b/refresh-drawable-path/src/androidTest/java/com/scwang/smart/drawable/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.scwang.smart.drawable; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumentation test, which will execute on an Android device. @@ -17,10 +18,10 @@ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @Test - public void useAppContext() throws Exception { + public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.scwang.smartrefresh.layout.test", appContext.getPackageName()); + assertEquals("com.scwang.smart.drawable.test", appContext.getPackageName()); } } diff --git a/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/PathsDrawable.java b/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/PathsDrawable.java index d532aa3bf..ea57d9006 100644 --- a/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/PathsDrawable.java +++ b/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/PathsDrawable.java @@ -7,7 +7,8 @@ import android.graphics.Rect; import android.graphics.Region; import android.graphics.drawable.Drawable; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.scwang.smart.drawable.path.PathParser; diff --git a/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/path/PathParser.java b/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/path/PathParser.java index fd2daf25a..958047bb2 100644 --- a/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/path/PathParser.java +++ b/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/path/PathParser.java @@ -13,10 +13,12 @@ */ package com.scwang.smart.drawable.path; +import android.annotation.SuppressLint; import android.graphics.Matrix; import android.graphics.Path; import android.os.Build; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import java.util.ArrayList; import java.util.List; @@ -58,6 +60,7 @@ private static float[] copyOfRange(@NonNull float[] original, int start, int end return result; } + @SuppressLint("ObsoleteSdkInt") public static List transformScale(float ratioWidth, float ratioHeight, List originPaths, List orginSvgs) { Matrix matrix = new Matrix(); matrix.setScale(ratioWidth, ratioHeight); diff --git a/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/view/PathsView.java b/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/view/PathsView.java index 171f22c6f..7e285ab11 100644 --- a/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/view/PathsView.java +++ b/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/view/PathsView.java @@ -6,6 +6,8 @@ import android.util.AttributeSet; import android.view.View; +import androidx.annotation.NonNull; + import com.scwang.smart.drawable.PathsDrawable; /** @@ -54,7 +56,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto } @Override - protected void onDraw(Canvas canvas) { + protected void onDraw(@NonNull Canvas canvas) { mPathsDrawable.draw(canvas); } diff --git a/refresh-drawable-path/src/test/java/com/scwang/smart/drawable/ExampleUnitTest.java b/refresh-drawable-path/src/test/java/com/scwang/smart/drawable/ExampleUnitTest.java index 03ae0c30f..d4c51452c 100644 --- a/refresh-drawable-path/src/test/java/com/scwang/smart/drawable/ExampleUnitTest.java +++ b/refresh-drawable-path/src/test/java/com/scwang/smart/drawable/ExampleUnitTest.java @@ -11,7 +11,7 @@ */ public class ExampleUnitTest { @Test - public void addition_isCorrect() throws Exception { + public void addition_isCorrect() { assertEquals(4, 2 + 2); } } \ No newline at end of file diff --git a/refresh-footer-ball/build.gradle b/refresh-footer-ball/build.gradle index 835775c7c..d12770131 100644 --- a/refresh-footer-ball/build.gradle +++ b/refresh-footer-ball/build.gradle @@ -3,16 +3,16 @@ apply plugin: 'com.android.library' description = 'the footer BallPulseFooter of SmartRefreshLayout' android { - compileSdkVersion 28 + + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { @@ -22,16 +22,20 @@ android { } } + lintOptions { + abortOnError false + } + } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - compileOnly 'com.android.support:appcompat-v7:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - compileOnly project(':refresh-layout-kernel') + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/refresh-footer-ball/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java b/refresh-footer-ball/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java index eef94a702..d98e00583 100644 --- a/refresh-footer-ball/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java +++ b/refresh-footer-ball/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ -package com.scwang.smart.refresh.header; +package com.scwang.smart.refresh.footer; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. @@ -19,7 +20,7 @@ public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); assertEquals("com.scwang.smart.refresh.header.test", appContext.getPackageName()); } diff --git a/refresh-footer-ball/src/main/java/com/scwang/smart/refresh/footer/BallPulseFooter.java b/refresh-footer-ball/src/main/java/com/scwang/smart/refresh/footer/BallPulseFooter.java index 069173ed1..0811f6dff 100644 --- a/refresh-footer-ball/src/main/java/com/scwang/smart/refresh/footer/BallPulseFooter.java +++ b/refresh-footer-ball/src/main/java/com/scwang/smart/refresh/footer/BallPulseFooter.java @@ -6,14 +6,15 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.graphics.ColorUtils; import android.util.AttributeSet; import android.view.View; import android.view.animation.AccelerateDecelerateInterpolator; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.graphics.ColorUtils; + import com.scwang.smart.refresh.footer.ball.R; import com.scwang.smart.refresh.layout.api.RefreshFooter; import com.scwang.smart.refresh.layout.api.RefreshLayout; @@ -83,7 +84,7 @@ public BallPulseFooter(Context context, @Nullable AttributeSet attrs) { // @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { final View thisView = this; final int width = thisView.getWidth(); final int height = thisView.getHeight(); diff --git a/refresh-footer-ball/src/test/java/com/scwang/smart/refresh/footer/ExampleUnitTest.java b/refresh-footer-ball/src/test/java/com/scwang/smart/refresh/footer/ExampleUnitTest.java index 3f8e8d7aa..02e49e2c6 100644 --- a/refresh-footer-ball/src/test/java/com/scwang/smart/refresh/footer/ExampleUnitTest.java +++ b/refresh-footer-ball/src/test/java/com/scwang/smart/refresh/footer/ExampleUnitTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). diff --git a/refresh-footer-classics/build.gradle b/refresh-footer-classics/build.gradle index 686036390..261c3b8a8 100644 --- a/refresh-footer-classics/build.gradle +++ b/refresh-footer-classics/build.gradle @@ -3,16 +3,16 @@ apply plugin: 'com.android.library' description = 'the footer ClassicsFooter of SmartRefreshLayout' android { - compileSdkVersion 28 + + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { @@ -22,16 +22,21 @@ android { } } + lintOptions { + abortOnError false + } + } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - compileOnly 'com.android.support:appcompat-v7:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - api project(':refresh-drawable-paint') compileOnly project(':refresh-layout-kernel') + + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/refresh-footer-classics/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java b/refresh-footer-classics/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java index 03560746b..ec071b1a9 100644 --- a/refresh-footer-classics/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java +++ b/refresh-footer-classics/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.scwang.smart.refresh.footer; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. @@ -19,8 +20,8 @@ public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.scwang.smart.refresh.header.test", appContext.getPackageName()); + assertEquals("com.scwang.smart.refresh.footer.test", appContext.getPackageName()); } } diff --git a/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ArrowDrawable.java b/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ArrowDrawable.java index 952680231..31d7ae3d5 100644 --- a/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ArrowDrawable.java +++ b/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ArrowDrawable.java @@ -4,7 +4,8 @@ import android.graphics.Path; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.scwang.smart.drawable.PaintDrawable; diff --git a/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ClassicsAbstract.java b/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ClassicsAbstract.java index f98beb18f..9af3682d8 100644 --- a/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ClassicsAbstract.java +++ b/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/classics/ClassicsAbstract.java @@ -5,17 +5,18 @@ import android.graphics.drawable.Animatable; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.ColorRes; -import android.support.annotation.DrawableRes; -import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; + import com.scwang.smart.drawable.PaintDrawable; import com.scwang.smart.refresh.footer.classics.R; import com.scwang.smart.refresh.layout.api.RefreshComponent; diff --git a/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/footer/ClassicsFooter.java b/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/footer/ClassicsFooter.java index 3f8bd6aec..36e13a5a9 100644 --- a/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/footer/ClassicsFooter.java +++ b/refresh-footer-classics/src/main/java/com/scwang/smart/refresh/footer/ClassicsFooter.java @@ -2,12 +2,13 @@ import android.content.Context; import android.content.res.TypedArray; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; + import com.scwang.smart.drawable.ProgressDrawable; import com.scwang.smart.refresh.classics.ArrowDrawable; import com.scwang.smart.refresh.classics.ClassicsAbstract; diff --git a/refresh-footer-classics/src/test/java/com/scwang/smart/refresh/footer/ExampleUnitTest.java b/refresh-footer-classics/src/test/java/com/scwang/smart/refresh/footer/ExampleUnitTest.java index 3f8e8d7aa..02e49e2c6 100644 --- a/refresh-footer-classics/src/test/java/com/scwang/smart/refresh/footer/ExampleUnitTest.java +++ b/refresh-footer-classics/src/test/java/com/scwang/smart/refresh/footer/ExampleUnitTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). diff --git a/refresh-footer/build.gradle b/refresh-footer/build.gradle index 0914418ac..2c7f70ced 100644 --- a/refresh-footer/build.gradle +++ b/refresh-footer/build.gradle @@ -1,16 +1,15 @@ apply plugin: 'com.android.library' -//apply plugin: 'com.novoda.bintray-release' android { - compileSdkVersion 28 + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -27,21 +26,17 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - testImplementation 'junit:junit:4.12' + compileOnly project(':refresh-layout') compileOnly project(':refresh-footer-ball') compileOnly project(':refresh-footer-classics') - compileOnly project(':refresh-layout') -} -//publish { -// userOrg = SMART_USER -// groupId = 'com.scwang.smartrefresh' -// artifactId = 'SmartRefreshFooter' -// publishVersion = SMART_VERSION -// desc = 'Some delicate footers of SmartRefreshLayout' -// website = "https://github.com/scwang90/${rootProject.name}" -//} \ No newline at end of file +// compileOnly 'io.github.scwang90:refresh-footer-ball:3.0.0-alpha' //球脉冲加载 +// compileOnly 'io.github.scwang90:refresh-footer-classics:3.0.0-alpha' //经典加载 + + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' +} diff --git a/refresh-footer/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java b/refresh-footer/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java new file mode 100644 index 000000000..bbaf8c5e3 --- /dev/null +++ b/refresh-footer/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.scwang.smart.refresh.footer; + +import android.content.Context; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.scwang.smart.refresh.footer.test", appContext.getPackageName()); + } +} diff --git a/refresh-footer/src/androidTest/java/com/scwang/smartrefresh/footer/ExampleInstrumentedTest.java b/refresh-footer/src/androidTest/java/com/scwang/smartrefresh/footer/ExampleInstrumentedTest.java deleted file mode 100644 index ad487ee72..000000000 --- a/refresh-footer/src/androidTest/java/com/scwang/smartrefresh/footer/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.scwang.smartrefreshfooter; - -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumentation test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.scwang.smartrefreshfooter.test", appContext.getPackageName()); - } -} diff --git a/refresh-footer/src/main/AndroidManifest.xml b/refresh-footer/src/main/AndroidManifest.xml index a935bd955..96f0310d5 100644 --- a/refresh-footer/src/main/AndroidManifest.xml +++ b/refresh-footer/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/refresh-footer/src/test/java/com/scwang/smartrefresh/footer/ExampleUnitTest.java b/refresh-footer/src/test/java/com/scwang/smartrefresh/footer/ExampleUnitTest.java index 98bbe58c5..02e49e2c6 100644 --- a/refresh-footer/src/test/java/com/scwang/smartrefresh/footer/ExampleUnitTest.java +++ b/refresh-footer/src/test/java/com/scwang/smartrefresh/footer/ExampleUnitTest.java @@ -1,8 +1,8 @@ -package com.scwang.smartrefreshfooter; +package com.scwang.smart.refresh.footer; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). @@ -11,7 +11,7 @@ */ public class ExampleUnitTest { @Test - public void addition_isCorrect() throws Exception { + public void addition_isCorrect() { assertEquals(4, 2 + 2); } } \ No newline at end of file diff --git a/refresh-header-classics/build.gradle b/refresh-header-classics/build.gradle index 4deeb5111..7b3f4371b 100644 --- a/refresh-header-classics/build.gradle +++ b/refresh-header-classics/build.gradle @@ -3,16 +3,16 @@ apply plugin: 'com.android.library' description = 'the header ClassicsHeader of SmartRefreshLayout' android { - compileSdkVersion 28 + + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { @@ -22,17 +22,22 @@ android { } } + lintOptions { + abortOnError false + } + } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - compileOnly 'com.android.support:appcompat-v7:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - api project(':refresh-footer-classics') compileOnly project(':refresh-layout-kernel') + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' + } diff --git a/refresh-header-classics/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java b/refresh-header-classics/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java index eef94a702..e319e6a4a 100644 --- a/refresh-header-classics/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java +++ b/refresh-header-classics/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.scwang.smart.refresh.header; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. @@ -19,7 +20,7 @@ public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); assertEquals("com.scwang.smart.refresh.header.test", appContext.getPackageName()); } diff --git a/refresh-header-classics/src/main/java/com/scwang/smart/refresh/header/ClassicsHeader.java b/refresh-header-classics/src/main/java/com/scwang/smart/refresh/header/ClassicsHeader.java index 3c5f62048..45851d50f 100644 --- a/refresh-header-classics/src/main/java/com/scwang/smart/refresh/header/ClassicsHeader.java +++ b/refresh-header-classics/src/main/java/com/scwang/smart/refresh/header/ClassicsHeader.java @@ -4,11 +4,6 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.TypedArray; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentManager; import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; @@ -17,6 +12,12 @@ import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; + import com.scwang.smart.drawable.ProgressDrawable; import com.scwang.smart.refresh.classics.ArrowDrawable; import com.scwang.smart.refresh.classics.ClassicsAbstract; @@ -29,9 +30,11 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.TimeZone; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; @@ -219,13 +222,11 @@ public ClassicsHeader(Context context, AttributeSet attrs) { try {//try 不能删除-否则会出现兼容性问题 if (context instanceof FragmentActivity) { FragmentManager manager = ((FragmentActivity) context).getSupportFragmentManager(); - if (manager != null) { - @SuppressLint("RestrictedApi") - List fragments = manager.getFragments(); - if (fragments.size() > 0) { - setLastUpdateTime(new Date()); - return; - } + @SuppressLint("RestrictedApi") + List fragments = manager.getFragments(); + if (fragments.size() > 0) { + setLastUpdateTime(new Date()); + return; } } } catch (Throwable e) { @@ -291,6 +292,13 @@ public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull Refres public ClassicsHeader setLastUpdateTime(Date time) { final View thisView = this; mLastTime = time; + /* + * 时区修改后需要及时更新下拉刷新的时间否则出现下拉刷新的时间与系统时间不一致问题 + * 需要及时设置:mLastUpdateFormat.setCalendar + * 感谢:github 用户 findviewbyid 贡献的代码 + * 贡献日期:2023-01-12 + */ + mLastUpdateFormat.setCalendar(Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault())); mLastUpdateText.setText(mLastUpdateFormat.format(time)); if (mShared != null && !thisView.isInEditMode()) { mShared.edit().putLong(KEY_LAST_UPDATE_TIME, time.getTime()).apply(); diff --git a/refresh-header-classics/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java b/refresh-header-classics/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java index 80b4b4881..7ca278116 100644 --- a/refresh-header-classics/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java +++ b/refresh-header-classics/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). diff --git a/refresh-header-falsify/build.gradle b/refresh-header-falsify/build.gradle index 8289ea56d..7c8e09cf8 100644 --- a/refresh-header-falsify/build.gradle +++ b/refresh-header-falsify/build.gradle @@ -3,16 +3,16 @@ apply plugin: 'com.android.library' description = 'the header FalsifyHeader of SmartRefreshLayout' android { - compileSdkVersion 28 + + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { @@ -22,16 +22,19 @@ android { } } + lintOptions { + abortOnError false + } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - compileOnly 'com.android.support:appcompat-v7:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - compileOnly project(':refresh-layout-kernel') + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/refresh-header-radar/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java b/refresh-header-falsify/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java similarity index 68% rename from refresh-header-radar/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java rename to refresh-header-falsify/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java index eef94a702..e319e6a4a 100644 --- a/refresh-header-radar/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java +++ b/refresh-header-falsify/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.scwang.smart.refresh.header; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. @@ -19,7 +20,7 @@ public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); assertEquals("com.scwang.smart.refresh.header.test", appContext.getPackageName()); } diff --git a/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyFooter.java b/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyFooter.java index 533cd83e5..b5c9a627c 100644 --- a/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyFooter.java +++ b/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyFooter.java @@ -1,9 +1,10 @@ package com.scwang.smart.refresh.header; import android.content.Context; -import android.support.annotation.NonNull; import android.util.AttributeSet; +import androidx.annotation.NonNull; + import com.scwang.smart.refresh.header.falsify.FalsifyAbstract; import com.scwang.smart.refresh.layout.api.RefreshFooter; import com.scwang.smart.refresh.layout.api.RefreshKernel; diff --git a/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyHeader.java b/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyHeader.java index 2b0aed70b..5ec6eb19f 100644 --- a/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyHeader.java +++ b/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyHeader.java @@ -1,9 +1,10 @@ package com.scwang.smart.refresh.header; import android.content.Context; -import android.support.annotation.NonNull; import android.util.AttributeSet; +import androidx.annotation.NonNull; + import com.scwang.smart.refresh.header.falsify.FalsifyAbstract; import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshLayout; diff --git a/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/falsify/FalsifyAbstract.java b/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/falsify/FalsifyAbstract.java index d9d9298e8..9e4eb69b3 100644 --- a/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/falsify/FalsifyAbstract.java +++ b/refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/falsify/FalsifyAbstract.java @@ -4,12 +4,13 @@ import android.graphics.Canvas; import android.graphics.DashPathEffect; import android.graphics.Paint; -import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; import android.widget.TextView; +import androidx.annotation.NonNull; + import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.api.RefreshLayout; @@ -30,7 +31,7 @@ protected FalsifyAbstract(Context context, AttributeSet attrs, int defStyleAttr) } @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { super.dispatchDraw(canvas); final View thisView = this; if (thisView.isInEditMode()) {//这段代码在运行时不会执行,只会在Studio编辑预览时运行,不用在意性能问题 diff --git a/refresh-header-falsify/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java b/refresh-header-falsify/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java index 80b4b4881..7ca278116 100644 --- a/refresh-header-falsify/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java +++ b/refresh-header-falsify/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). diff --git a/refresh-header-material/build.gradle b/refresh-header-material/build.gradle index cf0155284..abc7bdcbe 100644 --- a/refresh-header-material/build.gradle +++ b/refresh-header-material/build.gradle @@ -3,16 +3,16 @@ apply plugin: 'com.android.library' description = 'the header MaterialHeader of SmartRefreshLayout' android { - compileSdkVersion 28 + + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { @@ -22,16 +22,20 @@ android { } } + lintOptions { + abortOnError false + } + } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - compileOnly 'com.android.support:appcompat-v7:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - compileOnly project(':refresh-layout-kernel') + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/refresh-header-falsify/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java b/refresh-header-material/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java similarity index 68% rename from refresh-header-falsify/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java rename to refresh-header-material/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java index eef94a702..e319e6a4a 100644 --- a/refresh-header-falsify/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java +++ b/refresh-header-material/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.scwang.smart.refresh.header; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. @@ -19,7 +20,7 @@ public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); assertEquals("com.scwang.smart.refresh.header.test", appContext.getPackageName()); } diff --git a/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/MaterialHeader.java b/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/MaterialHeader.java index 913826e45..d40a6f163 100644 --- a/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/MaterialHeader.java +++ b/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/MaterialHeader.java @@ -1,21 +1,24 @@ package com.scwang.smart.refresh.header; +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; -import android.support.annotation.ColorInt; -import android.support.annotation.ColorRes; -import android.support.annotation.NonNull; -import android.support.annotation.VisibleForTesting; -import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; +import androidx.core.content.ContextCompat; + import com.scwang.smart.refresh.header.material.CircleImageView; import com.scwang.smart.refresh.header.material.MaterialProgressDrawable; import com.scwang.smart.refresh.header.material.R; @@ -51,6 +54,7 @@ public class MaterialHeader extends SimpleComponent implements RefreshHeader { protected boolean mFinished; protected int mCircleDiameter; protected ImageView mCircleView; + protected RefreshKernel mKernel; protected MaterialProgressDrawable mProgress; /** @@ -58,6 +62,7 @@ public class MaterialHeader extends SimpleComponent implements RefreshHeader { */ protected int mWaveHeight; protected int mHeadHeight; + protected int mInitHeight; protected Path mBezierPath; protected Paint mBezierPaint; protected RefreshState mState; @@ -159,7 +164,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto } @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { if (mShowBezierWave) { //重置画笔 mBezierPath.reset(); @@ -184,6 +189,8 @@ public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDrag if (thisView.isInEditMode()) { mWaveHeight = mHeadHeight = height / 2; } + mKernel = kernel; + mInitHeight = height; } @Override @@ -230,7 +237,7 @@ public void onMoving(boolean isDragging, float percent, int offset, int height, @Override - public void onReleased(@NonNull RefreshLayout layout, int height, int maxDragHeight) { + public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) { mProgress.start(); } @@ -372,4 +379,29 @@ public MaterialHeader setScrollableWhenRefreshing(boolean scrollable) { return this; } // + @Override + public boolean autoOpen(int duration, float dragRate, final boolean animationOnly) { + if (mShowBezierWave) { + //如果显示背景,使用旧版的 autoRefresh 动画 + return false; + } + if (mKernel == null) { + //如果必要的组件没有初始化,也使用旧版动画 autoRefresh 动画 + return false; + } + final View circleView = mCircleView; + circleView.setAlpha(1); + circleView.setScaleX(0); + circleView.setScaleY(0); + circleView.setTranslationY(mInitHeight / 2f + mCircleDiameter / 2f); + circleView.animate().scaleX(1).scaleY(1).setDuration(duration).setListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + circleView.animate().setListener(null); + mProgress.start(); + mKernel.onAutoRefreshAnimationEnd(animation, animationOnly); + } + }); + return true; + } } diff --git a/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/material/CircleImageView.java b/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/material/CircleImageView.java index 52fa20bc6..557a6392f 100644 --- a/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/material/CircleImageView.java +++ b/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/material/CircleImageView.java @@ -17,18 +17,13 @@ import android.annotation.SuppressLint; import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.RadialGradient; -import android.graphics.Shader; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.OvalShape; -import android.os.Build; -import android.support.annotation.ColorInt; import android.view.View; import android.widget.ImageView; +import androidx.annotation.ColorInt; + /** * Private class created to work around issues with AnimationListeners being @@ -38,90 +33,30 @@ @SuppressLint({"ViewConstructor", "AppCompatCustomView"}) public class CircleImageView extends ImageView { - protected static final int KEY_SHADOW_COLOR = 0x1E000000; - protected static final int FILL_SHADOW_COLOR = 0x3D000000; - // PX - protected static final float X_OFFSET = 0f; - protected static final float Y_OFFSET = 1.75f; protected static final float SHADOW_RADIUS = 3.5f; protected static final int SHADOW_ELEVATION = 4; - // private Animation.AnimationListener mListener; int mShadowRadius; public CircleImageView(Context context, int color) { super(context); final View thisView = this; final float density = thisView.getResources().getDisplayMetrics().density; - final int shadowYOffset = (int) (density * Y_OFFSET); - final int shadowXOffset = (int) (density * X_OFFSET); mShadowRadius = (int) (density * SHADOW_RADIUS); ShapeDrawable circle; - if (android.os.Build.VERSION.SDK_INT >= 21) { - circle = new ShapeDrawable(new OvalShape()); - thisView.setElevation(SHADOW_ELEVATION * density); - } else { - OvalShape oval = new OvalShadow(mShadowRadius); - circle = new ShapeDrawable(oval); - thisView.setLayerType(LAYER_TYPE_SOFTWARE, circle.getPaint()); - circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, - KEY_SHADOW_COLOR); - final int padding = mShadowRadius; - // set padding so the inner image sits correctly within the shadow. - thisView.setPadding(padding, padding, padding, padding); - } + circle = new ShapeDrawable(new OvalShape()); + thisView.setElevation(SHADOW_ELEVATION * density); circle.getPaint().setColor(color); thisView.setBackground(circle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - final View thisView = this; super.onMeasure(widthMeasureSpec, heightMeasureSpec); - if (Build.VERSION.SDK_INT < 21) { - super.setMeasuredDimension( - thisView.getMeasuredWidth() + mShadowRadius * 2, - thisView.getMeasuredHeight() + mShadowRadius * 2); - } } -// public void setAnimationListener(Animation.AnimationListener listener) { -// mListener = listener; -// } -// -// @Override -// public void onAnimationStart() { -// super.onAnimationStart(); -// if (mListener != null) { -// mListener.onAnimationStart(getAnimation()); -// } -// } -// -// @Override -// public void onAnimationEnd() { -// super.onAnimationEnd(); -// if (mListener != null) { -// mListener.onAnimationEnd(getAnimation()); -// } -// } - -// /** -// * Update the background color of the circle image view. -// * -// * @param colorRes Id of a color resource. -// */ -// public void setBackgroundColorRes(int colorRes) { -// Context context = getContext(); -// if (Build.VERSION.SDK_INT >= 23) { -// setBackgroundColor(context.getResources().getColor(colorRes, context.getTheme())); -// } else { -// //noinspection deprecation -// setBackgroundColor(context.getResources().getColor(colorRes)); -// } -// } -// @Override public void setBackgroundColor(@ColorInt int color) { final View thisView = this; @@ -130,37 +65,4 @@ public void setBackgroundColor(@ColorInt int color) { } } - private class OvalShadow extends OvalShape { - private RadialGradient mRadialGradient; - private Paint mShadowPaint; - - OvalShadow(int shadowRadius) { - super(); - mShadowPaint = new Paint(); - mShadowRadius = shadowRadius; - updateRadialGradient((int) super.rect().width()); - } - - @Override - protected void onResize(float width, float height) { - super.onResize(width, height); - updateRadialGradient((int) width); - } - - @Override - public void draw(Canvas canvas, Paint paint) { - final View thisView = CircleImageView.this; - final int viewWidth = thisView.getWidth(); - final int viewHeight = thisView.getHeight(); - canvas.drawCircle(viewWidth / 2f, viewHeight / 2f, viewWidth / 2f, mShadowPaint); - canvas.drawCircle(viewWidth / 2f, viewHeight / 2f, viewWidth / 2f - mShadowRadius, paint); - } - - private void updateRadialGradient(int diameter) { - mRadialGradient = new RadialGradient(diameter / 2f, diameter / 2f, - mShadowRadius, new int[] { FILL_SHADOW_COLOR, Color.TRANSPARENT }, - null, Shader.TileMode.CLAMP); - mShadowPaint.setShader(mRadialGradient); - } - } } diff --git a/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/material/MaterialProgressDrawable.java b/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/material/MaterialProgressDrawable.java index 8a384f017..3ae4f3150 100644 --- a/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/material/MaterialProgressDrawable.java +++ b/refresh-header-material/src/main/java/com/scwang/smart/refresh/header/material/MaterialProgressDrawable.java @@ -27,10 +27,6 @@ import android.graphics.RectF; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.IntDef; -import android.support.annotation.NonNull; -import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.util.DisplayMetrics; import android.view.View; import android.view.animation.Animation; @@ -38,10 +34,13 @@ import android.view.animation.LinearInterpolator; import android.view.animation.Transformation; +import androidx.annotation.ColorInt; +import androidx.annotation.IntDef; +import androidx.annotation.NonNull; +import androidx.interpolator.view.animation.FastOutSlowInInterpolator; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import java.util.ArrayList; -import java.util.List; /** * Fancy progress indicator for Material theme. @@ -89,9 +88,6 @@ public class MaterialProgressDrawable extends Drawable implements Animatable { /** The number of points in the progress "star". */ private static final byte NUM_POINTS = 5; - /** The list of animators operating on this drawable. */ - private final List mAnimators = new ArrayList<>(); - /** The indicator ring, used to manage animation state. */ private final Ring mRing = new Ring(); @@ -108,12 +104,13 @@ public class MaterialProgressDrawable extends Drawable implements Animatable { private static final byte ARROW_HEIGHT_LARGE = 6; private static final float MAX_PROGRESS_ARC = .8f; - private View mParent; + private final View mParent; private Animation mAnimation; float mRotationCount; private float mWidth; private float mHeight; boolean mFinishing; + boolean mIsRunning; public MaterialProgressDrawable(View parent) { mParent = parent; @@ -262,47 +259,55 @@ void setRotation(float rotation) { } @Override + @Deprecated public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Override public boolean isRunning() { - final List animators = mAnimators; - final int N = animators.size(); - for (int i = 0; i < N; i++) { - final Animation animator = animators.get(i); - if (animator.hasStarted() && !animator.hasEnded()) { - return true; - } - } - return false; + return mIsRunning; +// final List animators = mAnimators; +// final int N = animators.size(); +// for (int i = 0; i < N; i++) { +// final Animation animator = animators.get(i); +// if (animator.hasStarted() && !animator.hasEnded()) { +// return true; +// } +// } +// return false; } @Override public void start() { - mAnimation.reset(); - mRing.storeOriginals(); - // Already showing some part of the ring - if (mRing.mEndTrim != mRing.mStartTrim) { - mFinishing = true; - mAnimation.setDuration(ANIMATION_DURATION / 2); - mParent.startAnimation(mAnimation); - } else { - mRing.setColorIndex(0); - mRing.resetOriginals(); - mAnimation.setDuration(ANIMATION_DURATION); - mParent.startAnimation(mAnimation); + if (!mIsRunning) { + mAnimation.reset(); + mRing.storeOriginals(); + // Already showing some part of the ring + if (mRing.mEndTrim != mRing.mStartTrim) { + mFinishing = true; + mAnimation.setDuration(ANIMATION_DURATION / 2); + mParent.startAnimation(mAnimation); + } else { + mRing.setColorIndex(0); + mRing.resetOriginals(); + mAnimation.setDuration(ANIMATION_DURATION); + mParent.startAnimation(mAnimation); + } + mIsRunning = true; } } @Override public void stop() { - mParent.clearAnimation(); - mRing.setColorIndex(0); - mRing.resetOriginals(); - showArrow(false); - setRotation(0); + if (mIsRunning) { + mParent.clearAnimation(); + mRing.setColorIndex(0); + mRing.resetOriginals(); + showArrow(false); + setRotation(0); + mIsRunning = false; + } } float getMinProgressArc(Ring ring) { @@ -311,7 +316,6 @@ float getMinProgressArc(Ring ring) { } // Adapted from ArgbEvaluator.java - @SuppressWarnings("RedundantCast") private int evaluateColorChange(float fraction, int startValue, int endValue) { int startA = (startValue >> 24) & 0xff; int startR = (startValue >> 16) & 0xff; @@ -447,7 +451,7 @@ public void onAnimationRepeat(Animation animation) { mAnimation = animation; } - private class Ring { + private static class Ring { final RectF mTempBounds = new RectF(); final Paint mPaint = new Paint(); final Paint mArrowPaint = new Paint(); @@ -472,9 +476,6 @@ private class Ring { double mRingCenterRadius; int mArrowWidth; int mArrowHeight; -// int mAlpha; -// final Paint mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG); -// int mBackgroundColor; int mCurrentColor; Ring() { diff --git a/refresh-header-material/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java b/refresh-header-material/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java index 80b4b4881..7ca278116 100644 --- a/refresh-header-material/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java +++ b/refresh-header-material/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). diff --git a/refresh-header-radar/build.gradle b/refresh-header-radar/build.gradle index 891dc9da7..da97673a3 100644 --- a/refresh-header-radar/build.gradle +++ b/refresh-header-radar/build.gradle @@ -3,16 +3,16 @@ apply plugin: 'com.android.library' description = 'the header BezierRadarHeader of SmartRefreshLayout' android { - compileSdkVersion 28 + + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { @@ -22,16 +22,20 @@ android { } } + lintOptions { + abortOnError false + } + } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - compileOnly 'com.android.support:appcompat-v7:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - compileOnly project(':refresh-layout-kernel') + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/refresh-header-two-level/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java b/refresh-header-radar/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java similarity index 68% rename from refresh-header-two-level/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java rename to refresh-header-radar/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java index eef94a702..e319e6a4a 100644 --- a/refresh-header-two-level/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java +++ b/refresh-header-radar/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.scwang.smart.refresh.header; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. @@ -19,7 +20,7 @@ public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); assertEquals("com.scwang.smart.refresh.header.test", appContext.getPackageName()); } diff --git a/refresh-header-radar/src/main/java/com/scwang/smart/refresh/header/BezierRadarHeader.java b/refresh-header-radar/src/main/java/com/scwang/smart/refresh/header/BezierRadarHeader.java index d11d9886e..92650ff3d 100644 --- a/refresh-header-radar/src/main/java/com/scwang/smart/refresh/header/BezierRadarHeader.java +++ b/refresh-header-radar/src/main/java/com/scwang/smart/refresh/header/BezierRadarHeader.java @@ -9,15 +9,16 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; -import android.support.annotation.ColorInt; -import android.support.annotation.ColorRes; -import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import android.view.View; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; + import com.scwang.smart.refresh.header.radar.R; import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshLayout; @@ -118,7 +119,7 @@ protected void onDetachedFromWindow() { // @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { final View thisView = this; final int width = thisView.getWidth(); final int height = thisView.isInEditMode() ? thisView.getHeight() : mWaveOffsetY; @@ -378,7 +379,7 @@ protected class AnimatorUpdater implements ValueAnimator.AnimatorUpdateListener this.propertyName = name; } @Override - public void onAnimationUpdate(ValueAnimator animation) { + public void onAnimationUpdate(@NonNull ValueAnimator animation) { if (PROPERTY_RADAR_SCALE == propertyName) { mRadarScale = (float) animation.getAnimatedValue(); } else if (PROPERTY_WAVE_HEIGHT == propertyName) { diff --git a/refresh-header-radar/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java b/refresh-header-radar/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java index 80b4b4881..7ca278116 100644 --- a/refresh-header-radar/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java +++ b/refresh-header-radar/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). diff --git a/refresh-header-two-level/build.gradle b/refresh-header-two-level/build.gradle index 6faa3a49c..146f133e8 100644 --- a/refresh-header-two-level/build.gradle +++ b/refresh-header-two-level/build.gradle @@ -3,16 +3,16 @@ apply plugin: 'com.android.library' description = 'the header TwoLevelHeader of SmartRefreshLayout' android { - compileSdkVersion 28 + + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { @@ -30,12 +30,12 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - compileOnly 'com.android.support:appcompat-v7:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - api project(':refresh-header-classics') compileOnly project(':refresh-layout-kernel') + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } diff --git a/refresh-header-material/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java b/refresh-header-two-level/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java similarity index 68% rename from refresh-header-material/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java rename to refresh-header-two-level/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java index eef94a702..e319e6a4a 100644 --- a/refresh-header-material/src/androidTest/java/com/scwang/smart/refresh/footer/ExampleInstrumentedTest.java +++ b/refresh-header-two-level/src/androidTest/java/com/scwang/smart/refresh/header/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.scwang.smart.refresh.header; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. @@ -19,7 +20,7 @@ public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); assertEquals("com.scwang.smart.refresh.header.test", appContext.getPackageName()); } diff --git a/refresh-header-two-level/src/main/java/com/scwang/smart/refresh/header/TwoLevelHeader.java b/refresh-header-two-level/src/main/java/com/scwang/smart/refresh/header/TwoLevelHeader.java index 3d2034685..42ac51bec 100644 --- a/refresh-header-two-level/src/main/java/com/scwang/smart/refresh/header/TwoLevelHeader.java +++ b/refresh-header-two-level/src/main/java/com/scwang/smart/refresh/header/TwoLevelHeader.java @@ -2,23 +2,24 @@ import android.content.Context; import android.content.res.TypedArray; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.view.NestedScrollingParent2; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.view.NestedScrollingParent2; + import com.scwang.smart.refresh.header.listener.OnTwoLevelListener; import com.scwang.smart.refresh.header.two.level.R; -import com.scwang.smart.refresh.layout.simple.SimpleComponent; -import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshComponent; +import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.api.RefreshLayout; import com.scwang.smart.refresh.layout.constant.RefreshState; import com.scwang.smart.refresh.layout.constant.SpinnerStyle; import com.scwang.smart.refresh.layout.listener.OnStateChangedListener; +import com.scwang.smart.refresh.layout.simple.SimpleComponent; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; @@ -26,8 +27,8 @@ /** * 二级刷新 * Created by scwang on 2017/5/26. + * @noinspection UnusedReturnValue, unused */ -@SuppressWarnings({"UnusedReturnValue", "unused"}) public class TwoLevelHeader extends SimpleComponent implements RefreshHeader, NestedScrollingParent2 { // diff --git a/refresh-header-two-level/src/main/java/com/scwang/smart/refresh/header/listener/OnTwoLevelListener.java b/refresh-header-two-level/src/main/java/com/scwang/smart/refresh/header/listener/OnTwoLevelListener.java index 550073327..708e67ca2 100644 --- a/refresh-header-two-level/src/main/java/com/scwang/smart/refresh/header/listener/OnTwoLevelListener.java +++ b/refresh-header-two-level/src/main/java/com/scwang/smart/refresh/header/listener/OnTwoLevelListener.java @@ -1,6 +1,6 @@ package com.scwang.smart.refresh.header.listener; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.scwang.smart.refresh.layout.api.RefreshLayout; diff --git a/refresh-header-two-level/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java b/refresh-header-two-level/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java index 80b4b4881..7ca278116 100644 --- a/refresh-header-two-level/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java +++ b/refresh-header-two-level/src/test/java/com/scwang/smart/refresh/header/ExampleUnitTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). diff --git a/refresh-header/build.gradle b/refresh-header/build.gradle index 2a5278a58..cef2f4bc9 100644 --- a/refresh-header/build.gradle +++ b/refresh-header/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' -//apply plugin: 'com.novoda.bintray-release' android { - compileSdkVersion 28 + compileSdkVersion 34 + defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 versionName SMART_VERSION @@ -25,26 +25,21 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - testImplementation 'junit:junit:4.12' - compileOnly 'com.android.support:support-annotations:28.0.0' - compileOnly 'com.android.support:support-v4:28.0.0' compileOnly project(':refresh-layout') compileOnly project(':refresh-drawable-path') compileOnly project(':refresh-header-material') - compileOnly project(':refresh-layout-kernel') compileOnly project(':refresh-header-falsify') -} -//publish { -// userOrg = SMART_USER -// groupId = 'com.scwang.smartrefresh' -// artifactId = 'SmartRefreshHeader' -// publishVersion = SMART_VERSION -// desc = 'Some delicate headers of SmartRefreshLayout' -// website = "https://github.com/scwang90/${rootProject.name}" -//} +// compileOnly 'io.github.scwang90:refresh-drawable-path:3.0.0-alpha' //矢量路径 +// compileOnly 'io.github.scwang90:refresh-layout-kernel:3.0.0-alpha' //核心必须依赖 +// compileOnly 'io.github.scwang90:refresh-header-falsify:3.0.0-alpha' //虚拟刷新头 +// compileOnly 'io.github.scwang90:refresh-header-material:3.0.0-alpha' //谷歌刷新头 + + compileOnly 'androidx.appcompat:appcompat:1.7.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' +} diff --git a/refresh-header/src/androidTest/java/com/scwang/smartrefresh/header/ExampleInstrumentedTest.java b/refresh-header/src/androidTest/java/com/scwang/smartrefresh/header/ExampleInstrumentedTest.java index 658713f92..7323435eb 100644 --- a/refresh-header/src/androidTest/java/com/scwang/smartrefresh/header/ExampleInstrumentedTest.java +++ b/refresh-header/src/androidTest/java/com/scwang/smartrefresh/header/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ -package com.scwang.smartrefresh.header; +package com.scwang.smart.refresh.header; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumentation test, which will execute on an Android device. @@ -17,10 +18,10 @@ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @Test - public void useAppContext() throws Exception { + public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.scwang.smartrefresh.header.test", appContext.getPackageName()); + assertEquals("com.scwang.smart.refresh.header.test", appContext.getPackageName()); } } diff --git a/refresh-header/src/main/AndroidManifest.xml b/refresh-header/src/main/AndroidManifest.xml index 5e8e6b960..ad144e777 100644 --- a/refresh-header/src/main/AndroidManifest.xml +++ b/refresh-header/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/BezierCircleHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/BezierCircleHeader.java index 3aee4c453..4e299dd3c 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/BezierCircleHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/BezierCircleHeader.java @@ -6,25 +6,26 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; -import android.support.v4.graphics.ColorUtils; import android.util.AttributeSet; import android.view.View; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.core.graphics.ColorUtils; + +import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.api.RefreshLayout; -import com.scwang.smart.refresh.layout.simple.SimpleComponent; -import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.util.SmartUtil; /** * CircleRefresh * Created by scwang on 2018/7/18. - * from https://github.com/tuesda/CircleRefreshLayout + * from ... */ public class BezierCircleHeader extends SimpleComponent implements RefreshHeader { @@ -82,7 +83,7 @@ public BezierCircleHeader(Context context, AttributeSet attrs) { // @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { final View thisView = this; final int viewWidth = thisView.getWidth(); final int viewHeight = mHeight;//thisView.getHeight(); @@ -268,7 +269,7 @@ public void onReleased(@NonNull RefreshLayout refreshLayout, int height, int max float springRatio = 0; int status = 0;//0 还没开始弹起 1 向上弹起 2 在弹起的最高点停住 @Override - public void onAnimationUpdate(ValueAnimator animation) { + public void onAnimationUpdate(@NonNull ValueAnimator animation) { float curValue = (float) animation.getAnimatedValue(); if (status == 0 && curValue <= 0) { status = 1; @@ -322,13 +323,10 @@ public int onFinish(@NonNull RefreshLayout layout, boolean success) { mShowOuter = false; final int DURATION_FINISH = 800; //动画时长 ValueAnimator animator = ValueAnimator.ofFloat(0, 1); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - final View thisView = BezierCircleHeader.this; - mFinishRatio = (float) animation.getAnimatedValue(); - thisView.invalidate(); - } + animator.addUpdateListener(animation -> { + final View thisView = BezierCircleHeader.this; + mFinishRatio = (float) animation.getAnimatedValue(); + thisView.invalidate(); }); animator.setInterpolator(new AccelerateInterpolator()); animator.setDuration(DURATION_FINISH); @@ -353,10 +351,5 @@ public void setPrimaryColors(@ColorInt int ... colors) { } } -// @NonNull -// @Override -// public SpinnerStyle getSpinnerStyle() { -// return SpinnerStyle.Scale; -// } // } \ No newline at end of file diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/DeliveryHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/DeliveryHeader.java index 8c699c631..792d23238 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/DeliveryHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/DeliveryHeader.java @@ -4,25 +4,26 @@ import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.scwang.smart.drawable.PathsDrawable; +import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.api.RefreshLayout; import com.scwang.smart.refresh.layout.constant.RefreshState; -import com.scwang.smart.refresh.layout.simple.SimpleComponent; -import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.util.SmartUtil; /** * Refresh your delivery! * Created by scwang on 2017/6/25. - * design https://dribbble.com/shots/2753803-Refresh-your-delivery + * design ... */ public class DeliveryHeader extends SimpleComponent implements RefreshHeader { @@ -140,7 +141,7 @@ public DeliveryHeader(Context context, @Nullable AttributeSet attrs) { // @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { final View thisView = this; final int width = thisView.getWidth(); final int height = mHeight;//thisView.getHeight(); diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/DropBoxHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/DropBoxHeader.java index 8f51c08ef..bef22982b 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/DropBoxHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/DropBoxHeader.java @@ -10,28 +10,29 @@ import android.graphics.Path; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.graphics.ColorUtils; import android.util.AttributeSet; import android.view.View; import android.view.animation.AccelerateInterpolator; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.graphics.ColorUtils; + import com.scwang.smart.drawable.PathsDrawable; +import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.api.RefreshLayout; import com.scwang.smart.refresh.layout.constant.RefreshState; -import com.scwang.smart.refresh.layout.simple.SimpleComponent; -import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.util.SmartUtil; -import com.scwang.smartrefresh.header.R; +import com.scwang.smart.refresh.header.R; /** * DropBoxRefresh * Created by scwang on 2017/6/24. - * design https://dribbble.com/shots/3470499-DropBox-Refresh + * design ... */ public class DropBoxHeader extends SimpleComponent implements RefreshHeader { @@ -154,13 +155,10 @@ protected void onAttachedToWindow() { mReboundAnimator = ValueAnimator.ofFloat(0, 1, 0); mReboundAnimator.setInterpolator(interpolator); mReboundAnimator.setDuration(300); - mReboundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - final View thisView = DropBoxHeader.this; - mReboundPercent = (float) animation.getAnimatedValue(); - thisView.invalidate(); - } + mReboundAnimator.addUpdateListener(animation -> { + final View thisView = DropBoxHeader.this; + mReboundPercent = (float) animation.getAnimatedValue(); + thisView.invalidate(); }); mReboundAnimator.addListener(new AnimatorListenerAdapter() { @Override @@ -178,22 +176,19 @@ public void onAnimationEnd(Animator animation) { mDropOutAnimator = ValueAnimator.ofFloat(0, 1); mDropOutAnimator.setInterpolator(interpolator); mDropOutAnimator.setDuration(300); - mDropOutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - if (mDropOutPercent < 1 || mDropOutPercent >= 3) { - mDropOutPercent = (float) animation.getAnimatedValue(); - } else if (mDropOutPercent < 2) { - mDropOutPercent = 1 + (float) animation.getAnimatedValue(); - } else if (mDropOutPercent < 3) { - mDropOutPercent = 2 + (float) animation.getAnimatedValue(); - if (mDropOutPercent == 3) { - mDropOutOverFlow = true; - } + mDropOutAnimator.addUpdateListener(animation -> { + if (mDropOutPercent < 1 || mDropOutPercent >= 3) { + mDropOutPercent = (float) animation.getAnimatedValue(); + } else if (mDropOutPercent < 2) { + mDropOutPercent = 1 + (float) animation.getAnimatedValue(); + } else if (mDropOutPercent < 3) { + mDropOutPercent = 2 + (float) animation.getAnimatedValue(); + if (mDropOutPercent == 3) { + mDropOutOverFlow = true; } - final View thisView = DropBoxHeader.this; - thisView.invalidate(); } + final View thisView = DropBoxHeader.this; + thisView.invalidate(); }); mDropOutAnimator.addListener(new AnimatorListenerAdapter() { @Override @@ -221,7 +216,7 @@ protected void onDetachedFromWindow() { } @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { final View thisView = this; final int width = thisView.getWidth(); diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/FlyRefreshHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/FlyRefreshHeader.java index c4a4f1c1f..18d8f794e 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/FlyRefreshHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/FlyRefreshHeader.java @@ -6,15 +6,16 @@ import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.view.animation.PathInterpolatorCompat; import android.util.AttributeSet; import android.view.View; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.view.animation.PathInterpolatorCompat; + import com.scwang.smart.refresh.header.flyrefresh.MountainSceneView; import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshKernel; @@ -24,7 +25,7 @@ /** * 纸飞机和山丘 * Created by scwang on 2017/6/6. - * from https://github.com/race604/FlyRefresh + * from ... */ public class FlyRefreshHeader extends FalsifyHeader implements RefreshHeader { @@ -110,12 +111,7 @@ public void onReleased(@NonNull RefreshLayout layout, int height, int maxDragHei if (mCurrentPercent > 0) { ValueAnimator valueAnimator = ValueAnimator.ofFloat(mCurrentPercent, 0); valueAnimator.setDuration(300); - valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - onMoving(true,(float) animation.getAnimatedValue(), 0, 0, 0); - } - }); + valueAnimator.addUpdateListener(animation -> onMoving(true,(float) animation.getAnimatedValue(), 0, 0, 0)); valueAnimator.start(); mCurrentPercent = 0; } diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameBattleCityHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameBattleCityHeader.java index 938c4abe5..e68011919 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameBattleCityHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameBattleCityHeader.java @@ -4,11 +4,12 @@ import android.graphics.Canvas; import android.graphics.Point; import android.graphics.RectF; -import android.support.annotation.NonNull; import android.util.AttributeSet; import android.util.SparseArray; import android.view.View; +import androidx.annotation.NonNull; + import com.scwang.smart.refresh.header.fungame.FunGameView; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.util.SmartUtil; @@ -19,7 +20,7 @@ /** * Created by scwang on 2018/3/09. - * from https://github.com/Hitomis/FunGameRefresh + * from ... */ public class FunGameBattleCityHeader extends FunGameView { @@ -185,7 +186,7 @@ protected RectF generateEnemyTank(int index) { protected int getTrackIndex(int y) { int index = y / (mHeaderHeight / TANK_ROW_NUM); index = index >= TANK_ROW_NUM ? TANK_ROW_NUM - 1 : index; - index = index < 0 ? 0 : index; + index = Math.max(index, 0); return index; } @@ -217,11 +218,13 @@ protected void upLevel() { bulletSpeed += SmartUtil.dp2px(1); wipeOutNum = 0; - if (enemyTankSpace > 12) - enemyTankSpace -= 12; + if (enemyTankSpace > 12) { + enemyTankSpace -= 12; + } - if (bulletSpace > 30) - bulletSpace -= 30; + if (bulletSpace > 30) { + bulletSpace -= 30; + } } /** diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameHitBlockHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameHitBlockHeader.java index 84cdd018c..5b4d0a4f2 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameHitBlockHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/FunGameHitBlockHeader.java @@ -5,22 +5,23 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; -import android.support.annotation.NonNull; -import android.support.v4.graphics.ColorUtils; import android.util.AttributeSet; import android.view.View; +import androidx.annotation.NonNull; +import androidx.core.graphics.ColorUtils; + import com.scwang.smart.refresh.header.fungame.FunGameView; import com.scwang.smart.refresh.layout.api.RefreshKernel; -import com.scwang.smartrefresh.header.R; -import com.scwang.smartrefresh.layout.util.SmartUtil; +import com.scwang.smart.refresh.layout.util.SmartUtil; +import com.scwang.smart.refresh.header.R; import java.util.ArrayList; import java.util.List; /** * Created by scwang on 2018/2/29. - * from https://github.com/Hitomis/FunGameRefresh + * from ... */ public class FunGameHitBlockHeader extends FunGameView { diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/PhoenixHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/PhoenixHeader.java index ab4b566e9..f94f27cdd 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/PhoenixHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/PhoenixHeader.java @@ -7,8 +7,6 @@ import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.View; import android.view.animation.Animation; @@ -16,19 +14,22 @@ import android.view.animation.LinearInterpolator; import android.view.animation.Transformation; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; + import com.scwang.smart.drawable.PathsDrawable; import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.api.RefreshLayout; -import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.util.SmartUtil; -import com.scwang.smartrefresh.header.R; +import com.scwang.smart.refresh.header.R; /** * Phoenix * Created by scwang on 2017/5/31. - * from https://github.com/Yalantis/Phoenix + * from ... */ public class PhoenixHeader extends SimpleComponent implements RefreshHeader { @@ -258,7 +259,7 @@ public void setPrimaryColors(@ColorInt int ... colors) { // @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { final View thisView = this; final int width = thisView.getWidth(); diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/StoreHouseHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/StoreHouseHeader.java index 78d22e84f..8c218f187 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/StoreHouseHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/StoreHouseHeader.java @@ -7,14 +7,15 @@ import android.graphics.Color; import android.graphics.Matrix; import android.graphics.PointF; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.View; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.view.animation.Transformation; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; + import com.scwang.smart.refresh.header.storehouse.StoreHouseBarItem; import com.scwang.smart.refresh.header.storehouse.StoreHousePath; import com.scwang.smart.refresh.layout.api.RefreshHeader; @@ -22,7 +23,7 @@ import com.scwang.smart.refresh.layout.api.RefreshLayout; import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.util.SmartUtil; -import com.scwang.smartrefresh.header.R; +import com.scwang.smart.refresh.header.R; import java.util.ArrayList; import java.util.List; @@ -30,7 +31,7 @@ /** * StoreHouseHeader * Created by scwang on 2017/5/31. - * from https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh + * from ... */ @SuppressWarnings({"unused", "UnusedReturnValue", "SameParameterValue"}) public class StoreHouseHeader extends SimpleComponent implements RefreshHeader { @@ -119,7 +120,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { } @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { final View thisView = this; final int c1 = canvas.save(); diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/TaurusHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/TaurusHeader.java index cc699675e..806e433bd 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/TaurusHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/TaurusHeader.java @@ -6,8 +6,6 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.View; import android.view.animation.AccelerateDecelerateInterpolator; @@ -16,14 +14,17 @@ import android.view.animation.Interpolator; import android.view.animation.Transformation; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; + import com.scwang.smart.drawable.PathsDrawable; import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.api.RefreshLayout; -import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.util.SmartUtil; -import com.scwang.smartrefresh.header.R; +import com.scwang.smart.refresh.header.R; import java.util.HashMap; import java.util.Map; @@ -32,7 +33,7 @@ /** * Taurus * Created by scwang on 2017/5/31. - * from https://github.com/Yalantis/Taurus + * from ... */ public class TaurusHeader extends SimpleComponent implements RefreshHeader { @@ -257,7 +258,7 @@ public void setPrimaryColors(@ColorInt int ... colors) { // @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { final View thisView = this; final int width = thisView.getWidth(); @@ -297,7 +298,7 @@ protected void drawWinds(Canvas canvas, int width) { for (Map.Entry wind : mWinds.entrySet()) { // We want that interval will be greater than fifth part of draggable distance - if (Math.abs(wind.getKey() - tmp) > mHeaderHeight / RANDOM_Y_COEFFICIENT) { + if (Math.abs(wind.getKey() - tmp) > 1f * mHeaderHeight / RANDOM_Y_COEFFICIENT) { y = tmp; } else { y = 0; diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/WaterDropHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/WaterDropHeader.java index 024ea56ed..5c13017ee 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/WaterDropHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/WaterDropHeader.java @@ -5,13 +5,14 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; + import com.scwang.smart.drawable.ProgressDrawable; import com.scwang.smart.refresh.header.material.MaterialProgressDrawable; import com.scwang.smart.refresh.header.waterdrop.WaterDropView; @@ -31,7 +32,7 @@ /** * WaterDropHeader * Created by scwang on 2017/5/31. - * from https://github.com/THEONE10211024/WaterDropListView + * from ... */ public class WaterDropHeader extends SimpleComponent implements RefreshHeader { @@ -124,7 +125,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { // @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { super.dispatchDraw(canvas); final View thisView = this; final View dropView = mWaterDropView; diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/WaveSwipeHeader.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/WaveSwipeHeader.java index 5b3694903..0d21049c3 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/WaveSwipeHeader.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/WaveSwipeHeader.java @@ -5,10 +5,6 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.IdRes; -import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.view.View; @@ -16,17 +12,22 @@ import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Animation; import android.view.animation.Transformation; -import android.widget.ImageView; + +import androidx.annotation.ColorInt; +import androidx.annotation.IdRes; +import androidx.annotation.NonNull; +import androidx.appcompat.widget.AppCompatImageView; +import androidx.core.content.ContextCompat; import com.scwang.smart.refresh.header.material.MaterialProgressDrawable; import com.scwang.smart.refresh.header.waveswipe.WaveView; import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshLayout; import com.scwang.smart.refresh.layout.constant.RefreshState; -import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.util.SmartUtil; -import com.scwang.smartrefresh.header.R; +import com.scwang.smart.refresh.header.R; import static android.view.View.MeasureSpec.EXACTLY; import static android.view.View.MeasureSpec.getSize; @@ -35,7 +36,7 @@ /** * 全屏水滴下拉头 * Created by scwang on 2017/6/4. - * from https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout + * from ... */ @SuppressWarnings("unused") public class WaveSwipeHeader extends SimpleComponent implements RefreshHeader { @@ -271,13 +272,10 @@ public void onReleased(@NonNull RefreshLayout layout, int height, int maxDragHei ValueAnimator animator = ValueAnimator.ofFloat(0, 0); animator.setDuration(500); animator.setInterpolator(new AccelerateDecelerateInterpolator()); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - final View circleView = mCircleView; - circleView.setTranslationY( - mWaveView.getCurrentCircleCenterY() + circleView.getHeight() / 2.f); - } + animator.addUpdateListener(valueAnimator -> { + final View circleView = mCircleView; + circleView.setTranslationY( + mWaveView.getCurrentCircleCenterY() + circleView.getHeight() / 2.f); }); animator.start(); } @@ -347,12 +345,6 @@ public void setPrimaryColors(@ColorInt int ... colors) { } } } -// -// @NonNull -// @Override -// public SpinnerStyle getSpinnerStyle() { -// return SpinnerStyle.MatchLayout; -// } // // @@ -372,7 +364,7 @@ public static boolean isOver600dp() { * * @author jmatsu */ - protected class ProgressAnimationImageView extends ImageView { + protected class ProgressAnimationImageView extends AppCompatImageView { /** * AnimationのStartとEnd時にListenerにアレする diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/flyrefresh/MountainSceneView.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/flyrefresh/MountainSceneView.java index 7c880f636..fa31fe4fa 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/flyrefresh/MountainSceneView.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/flyrefresh/MountainSceneView.java @@ -7,19 +7,21 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; -import android.support.annotation.ColorInt; -import android.support.v4.graphics.ColorUtils; -import android.support.v4.view.animation.PathInterpolatorCompat; import android.util.AttributeSet; import android.view.View; import android.view.animation.Interpolator; -import com.scwang.smartrefresh.header.R; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.core.graphics.ColorUtils; +import androidx.core.view.animation.PathInterpolatorCompat; + +import com.scwang.smart.refresh.header.R; /** * 山丘树木场景视图 * Created by scwang on 2018/5/28. - * from https://github.com/race604/FlyRefresh + * from ... */ @SuppressWarnings("UnnecessaryLocalVariable") public class MountainSceneView extends View { @@ -232,7 +234,7 @@ protected void drawTree(Canvas canvas, float scale, float baseX, float baseY, } @Override - protected void onDraw(Canvas canvas) { + protected void onDraw(@NonNull Canvas canvas) { super.onDraw(canvas); final View thisView = this; canvas.drawColor(COLOR_BACKGROUND); diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/fungame/FunGameBase.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/fungame/FunGameBase.java index 742e5003c..9c5515948 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/fungame/FunGameBase.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/fungame/FunGameBase.java @@ -2,19 +2,20 @@ import android.annotation.SuppressLint; import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.scwang.smart.refresh.layout.api.RefreshContent; import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.api.RefreshLayout; import com.scwang.smart.refresh.layout.constant.RefreshState; -import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.constant.SpinnerStyle; +import com.scwang.smart.refresh.layout.simple.SimpleComponent; import com.scwang.smart.refresh.layout.util.SmartUtil; import static android.view.MotionEvent.ACTION_MASK; @@ -206,11 +207,5 @@ public int onFinish(@NonNull RefreshLayout layout, boolean success) { } return 0; } -// -// @NonNull -// @Override -// public SpinnerStyle getSpinnerStyle() { -// return SpinnerStyle.MatchLayout; -// } // } diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/fungame/FunGameView.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/fungame/FunGameView.java index 15b4cb5cc..cf8d8d1b2 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/fungame/FunGameView.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/fungame/FunGameView.java @@ -9,9 +9,6 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; -import android.support.v4.graphics.ColorUtils; import android.text.TextPaint; import android.util.AttributeSet; import android.util.DisplayMetrics; @@ -22,18 +19,22 @@ import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.core.graphics.ColorUtils; + import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.api.RefreshLayout; import com.scwang.smart.refresh.layout.constant.RefreshState; import com.scwang.smart.refresh.layout.util.SmartUtil; -import com.scwang.smartrefresh.header.R; +import com.scwang.smart.refresh.header.R; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; /** * Created by scwang on 2018/2/29. - * https://github.com/Hitomis/FunGameRefresh + * from ... */ @SuppressWarnings("unused") public abstract class FunGameView extends FunGameBase { @@ -235,7 +236,7 @@ protected TextView createMaskView(Context context, String text, int textSize, in protected abstract void drawGame(Canvas canvas, int width, int height); @Override - protected void dispatchDraw(Canvas canvas) { + protected void dispatchDraw(@NonNull Canvas canvas) { final View thisView = this; final int width = thisView.getWidth(); final int height = mHeaderHeight; @@ -392,7 +393,7 @@ public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull Refres mMaskViewTop.setText(mMaskTextTopRelease); break; // case ReleaseToTwoLevel: -// mMaskViewTop.setText(com.scwang.smartrefresh.layout.R.string.srl_header_secondary); +// mMaskViewTop.setText(com.scwang.smart.refresh.layout.R.string.srl_header_secondary); // break; } } diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/waterdrop/WaterDropView.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/waterdrop/WaterDropView.java index b2a89e779..6bb415eb5 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/waterdrop/WaterDropView.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/waterdrop/WaterDropView.java @@ -6,17 +6,18 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; -import android.support.annotation.ColorInt; import android.view.View; import android.view.animation.DecelerateInterpolator; -import com.scwang.smartrefresh.layout.util.SmartUtil; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import com.scwang.smart.refresh.layout.util.SmartUtil; /** * 下拉头中间的 “水滴” * Created by scwang on 2018/6/23. - * from https://github.com/THEONE10211024/WaterDropListView + * from ... */ @SuppressWarnings("unused") public class WaterDropView extends View { @@ -85,7 +86,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto } @Override - protected void onDraw(Canvas canvas) { + protected void onDraw(@NonNull Canvas canvas) { super.onDraw(canvas); final View thisView = this; @@ -119,13 +120,13 @@ protected void makeBezierPath() { float top_y1 = (float) (topCircle.y + topCircle.radius * Math.sin(angle)); float top_x2 = (float) (topCircle.x + topCircle.radius * Math.cos(angle)); - float top_y2 = top_y1; + float top_y2 = top_y1 * 1; float bottom_x1 = (float) (bottomCircle.x - bottomCircle.radius * Math.cos(angle)); float bottom_y1 = (float) (bottomCircle.y + bottomCircle.radius * Math.sin(angle)); float bottom_x2 = (float) (bottomCircle.x + bottomCircle.radius * Math.cos(angle)); - float bottom_y2 = bottom_y1; + float bottom_y2 = bottom_y1 * 1; mPath.moveTo(topCircle.x, topCircle.y); @@ -165,13 +166,10 @@ protected double getAngle() { public ValueAnimator createAnimator() { ValueAnimator valueAnimator = ValueAnimator.ofFloat(1, 0.001f).setDuration(BACK_ANIM_DURATION); valueAnimator.setInterpolator(new DecelerateInterpolator()); - valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator1) { - WaterDropView.this.updateCompleteState((float) valueAnimator1.getAnimatedValue()); - final View thisView = WaterDropView.this; - thisView.postInvalidate(); - } + valueAnimator.addUpdateListener(animator -> { + WaterDropView.this.updateCompleteState((float) animator.getAnimatedValue()); + final View thisView = WaterDropView.this; + thisView.postInvalidate(); }); return valueAnimator; } diff --git a/refresh-header/src/main/java/com/scwang/smart/refresh/header/waveswipe/WaveView.java b/refresh-header/src/main/java/com/scwang/smart/refresh/header/waveswipe/WaveView.java index 00d7163d1..c161b4bae 100644 --- a/refresh-header/src/main/java/com/scwang/smart/refresh/header/waveswipe/WaveView.java +++ b/refresh-header/src/main/java/com/scwang/smart/refresh/header/waveswipe/WaveView.java @@ -23,13 +23,14 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; -import android.os.Build; -import android.support.annotation.ColorInt; import android.view.View; import android.view.ViewTreeObserver; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.BounceInterpolator; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; + /** * @author amyu *

@@ -213,14 +214,10 @@ public class WaveView extends View implements ViewTreeObserver.OnPreDrawListener /** * 各AnimatorのAnimatorUpdateListener */ - protected ValueAnimator.AnimatorUpdateListener mAnimatorUpdateListener = - new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - final View thisView = WaveView.this; - thisView.postInvalidate(); - } - }; + protected ValueAnimator.AnimatorUpdateListener mAnimatorUpdateListener = valueAnimator -> { + final View thisView = WaveView.this; + thisView.postInvalidate(); + }; /** * Constructor @@ -278,7 +275,7 @@ public boolean onPreDraw() { } @Override - protected void onDraw(Canvas canvas) { + protected void onDraw(@NonNull Canvas canvas) { super.onDraw(canvas); //引っ張ってる最中の波と終わったあとの波 // canvas.drawPath(mWavePath, mShadowPaint); @@ -439,11 +436,7 @@ public void beginPhase(float move1) { BEGIN_PHASE_POINTS[0][1], mWidth, 0); final View thisView = this; - if (Build.VERSION.SDK_INT >= 16) { - thisView.postInvalidateOnAnimation(); - } else { - thisView.invalidate(); - } + thisView.postInvalidateOnAnimation(); } @@ -480,11 +473,7 @@ public void appearPhase(float move1, float move2) { + mDropCircleRadius; final View thisView = this; - if (Build.VERSION.SDK_INT >= 16) { - thisView.postInvalidateOnAnimation(); - } else { - thisView.invalidate(); - } + thisView.postInvalidateOnAnimation(); } public void expandPhase(float move1, float move2, float move3) { @@ -538,11 +527,7 @@ public void expandPhase(float move1, float move2, float move3) { EXPAND_PHASE_POINTS[3][1]) + mDropCircleRadius; final View thisView = this; - if (Build.VERSION.SDK_INT >= 16) { - thisView.postInvalidateOnAnimation(); - } else { - thisView.invalidate(); - } + thisView.postInvalidateOnAnimation(); } /** @@ -569,17 +554,10 @@ public void startDropAnimation() { mDropCircleAnimator = ValueAnimator.ofFloat(500 * (mWidth / 1440.f), mMaxDropHeight); mDropCircleAnimator.setDuration(DROP_CIRCLE_ANIMATOR_DURATION); - mDropCircleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - mCurrentCircleCenterY = (float) animation.getAnimatedValue(); - final View thisView = WaveView.this; - if (Build.VERSION.SDK_INT >= 16) { - thisView.postInvalidateOnAnimation(); - } else { - thisView.invalidate(); - } - } + mDropCircleAnimator.addUpdateListener(animation -> { + mCurrentCircleCenterY = (float) animation.getAnimatedValue(); + final View thisView = WaveView.this; + thisView.postInvalidateOnAnimation(); }); mDropCircleAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); mDropCircleAnimator.start(); @@ -627,17 +605,14 @@ public void startWaveAnimation(float h) { h = Math.min(h, MAX_WAVE_HEIGHT) * mWidth; mWaveReverseAnimator = ValueAnimator.ofFloat(h, 0.f); mWaveReverseAnimator.setDuration(WAVE_ANIMATOR_DURATION); - mWaveReverseAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - float h = (Float) valueAnimator.getAnimatedValue(); - mWavePath.moveTo(0, 0); - mWavePath.quadTo(0.25f * mWidth, 0, 0.333f * mWidth, h * 0.5f); - mWavePath.quadTo(mWidth * 0.5f, h * 1.4f, 0.666f * mWidth, h * 0.5f); - mWavePath.quadTo(0.75f * mWidth, 0, mWidth, 0); - final View thisView = WaveView.this; - thisView.postInvalidate(); - } + mWaveReverseAnimator.addUpdateListener(valueAnimator -> { + float h1 = (Float) valueAnimator.getAnimatedValue(); + mWavePath.moveTo(0, 0); + mWavePath.quadTo(0.25f * mWidth, 0, 0.333f * mWidth, h1 * 0.5f); + mWavePath.quadTo(mWidth * 0.5f, h1 * 1.4f, 0.666f * mWidth, h1 * 0.5f); + mWavePath.quadTo(0.75f * mWidth, 0, mWidth, 0); + final View thisView = WaveView.this; + thisView.postInvalidate(); }); mWaveReverseAnimator.setInterpolator(new BounceInterpolator()); mWaveReverseAnimator.start(); diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/BezierCircleHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/BezierCircleHeader.java deleted file mode 100644 index dbcaefd67..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/BezierCircleHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * CircleRefresh - * Created by scwang on 2018/7/18. - * from https://github.com/tuesda/CircleRefreshLayout - */ -public class BezierCircleHeader extends com.scwang.smart.refresh.header.BezierCircleHeader implements RefreshHeader { - - // - public BezierCircleHeader(Context context) { - this(context, null); - } - - public BezierCircleHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // -} \ No newline at end of file diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/DeliveryHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/DeliveryHeader.java deleted file mode 100644 index a5b176421..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/DeliveryHeader.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.support.annotation.Nullable; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * Refresh your delivery! - * Created by scwang on 2017/6/25. - * design https://dribbble.com/shots/2753803-Refresh-your-delivery - */ -public class DeliveryHeader extends com.scwang.smart.refresh.header.DeliveryHeader implements RefreshHeader { - - // - public DeliveryHeader(Context context) { - this(context, null); - } - - public DeliveryHeader(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - } - // -} diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/DropBoxHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/DropBoxHeader.java deleted file mode 100644 index b705ce6c1..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/DropBoxHeader.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.support.annotation.Nullable; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * DropBoxRefresh - * Created by scwang on 2017/6/24. - * design https://dribbble.com/shots/3470499-DropBox-Refresh - */ -public class DropBoxHeader extends com.scwang.smart.refresh.header.DropBoxHeader implements RefreshHeader { - - // - public DropBoxHeader(Context context) { - this(context, null); - } - - public DropBoxHeader(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - } - // -} diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/FlyRefreshHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/FlyRefreshHeader.java deleted file mode 100644 index 713d46380..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/FlyRefreshHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * 纸飞机和山丘 - * Created by scwang on 2017/6/6. - * from https://github.com/race604/FlyRefresh - */ -public class FlyRefreshHeader extends com.scwang.smart.refresh.header.FlyRefreshHeader implements RefreshHeader { - - // - public FlyRefreshHeader(Context context) { - super(context); - } - - public FlyRefreshHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // -} diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/FunGameBattleCityHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/FunGameBattleCityHeader.java deleted file mode 100644 index 15c321e1a..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/FunGameBattleCityHeader.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -import java.util.Random; - -/** - * Created by scwang on 2018/3/09. - * from https://github.com/Hitomis/FunGameRefresh - */ -public class FunGameBattleCityHeader extends com.scwang.smart.refresh.header.FunGameBattleCityHeader implements RefreshHeader { - - // - public FunGameBattleCityHeader(Context context) { - this(context, null); - } - - public FunGameBattleCityHeader(Context context, AttributeSet attrs) { - super(context, attrs); - random = new Random(); - } - // - -} diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/FunGameHitBlockHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/FunGameHitBlockHeader.java deleted file mode 100644 index 60585dec7..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/FunGameHitBlockHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * Created by scwang on 2018/2/29. - * from https://github.com/Hitomis/FunGameRefresh - */ -public class FunGameHitBlockHeader extends com.scwang.smart.refresh.header.FunGameHitBlockHeader implements RefreshHeader { - - // - public FunGameHitBlockHeader(Context context) { - this(context, null); - } - - public FunGameHitBlockHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // - -} diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/MaterialHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/MaterialHeader.java deleted file mode 100644 index 63b93fa46..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/MaterialHeader.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * Material 主题下拉头 - * Created by scwang on 2017/6/2. - */ -public class MaterialHeader extends com.scwang.smart.refresh.header.MaterialHeader implements RefreshHeader { - - // - public MaterialHeader(Context context) { - this(context, null); - } - - public MaterialHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // -} diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/PhoenixHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/PhoenixHeader.java deleted file mode 100644 index 3e03e743f..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/PhoenixHeader.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * Phoenix - * Created by scwang on 2017/5/31. - * from https://github.com/Yalantis/Phoenix - */ -public class PhoenixHeader extends com.scwang.smart.refresh.header.PhoenixHeader implements RefreshHeader { - - // - public PhoenixHeader(Context context) { - this(context, null); - } - - public PhoenixHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // - -} - - diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/StoreHouseHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/StoreHouseHeader.java deleted file mode 100644 index 3824a9fc1..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/StoreHouseHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * StoreHouseHeader - * Created by scwang on 2017/5/31. - * from https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh - */ -public class StoreHouseHeader extends com.scwang.smart.refresh.header.StoreHouseHeader implements RefreshHeader { - - // - public StoreHouseHeader(Context context) { - this(context, null); - } - - public StoreHouseHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // -} \ No newline at end of file diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/TaurusHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/TaurusHeader.java deleted file mode 100644 index dd4c37d03..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/TaurusHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * Taurus - * Created by scwang on 2017/5/31. - * from https://github.com/Yalantis/Taurus - */ -public class TaurusHeader extends com.scwang.smart.refresh.header.TaurusHeader implements RefreshHeader { - - // - public TaurusHeader(Context context) { - this(context, null); - } - - public TaurusHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // -} diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/WaterDropHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/WaterDropHeader.java deleted file mode 100644 index a3f28a6d7..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/WaterDropHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * WaterDropHeader - * Created by scwang on 2017/5/31. - * from https://github.com/THEONE10211024/WaterDropListView - */ -public class WaterDropHeader extends com.scwang.smart.refresh.header.WaterDropHeader implements RefreshHeader { - - // - public WaterDropHeader(Context context) { - this(context, null); - } - - public WaterDropHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // -} \ No newline at end of file diff --git a/refresh-header/src/main/java/com/scwang/smartrefresh/header/WaveSwipeHeader.java b/refresh-header/src/main/java/com/scwang/smartrefresh/header/WaveSwipeHeader.java deleted file mode 100644 index 14db546ba..000000000 --- a/refresh-header/src/main/java/com/scwang/smartrefresh/header/WaveSwipeHeader.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.scwang.smartrefresh.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * 全屏水滴下拉头 - * Created by scwang on 2017/6/4. - * from https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout - */ -public class WaveSwipeHeader extends com.scwang.smart.refresh.header.WaveSwipeHeader implements RefreshHeader { - - // - public WaveSwipeHeader(Context context) { - this(context, null); - } - - public WaveSwipeHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // -} diff --git a/refresh-header/src/test/java/com/scwang/smartrefresh/header/ExampleUnitTest.java b/refresh-header/src/test/java/com/scwang/smartrefresh/header/ExampleUnitTest.java index ccffdf534..14e752a12 100644 --- a/refresh-header/src/test/java/com/scwang/smartrefresh/header/ExampleUnitTest.java +++ b/refresh-header/src/test/java/com/scwang/smartrefresh/header/ExampleUnitTest.java @@ -1,4 +1,4 @@ -package com.scwang.smartrefresh.header; +package com.scwang.smart.refresh.header; import org.junit.Test; @@ -6,7 +6,7 @@ import java.util.Date; import java.util.Locale; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). @@ -15,7 +15,7 @@ */ public class ExampleUnitTest { @Test - public void addition_isCorrect() throws Exception { + public void addition_isCorrect() { System.out.println(new SimpleDateFormat("'Last update' M-d HH:mm", Locale.CHINA).format(new Date())); assertEquals(4, 2 + 2); } diff --git a/refresh-layout-kernel/build.gradle b/refresh-layout-kernel/build.gradle index 8ac0c4115..73ed667a1 100644 --- a/refresh-layout-kernel/build.gradle +++ b/refresh-layout-kernel/build.gradle @@ -4,16 +4,15 @@ description = 'the kernel of SmartRefreshLayout' android { - compileSdkVersion 28 + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { release { @@ -28,82 +27,10 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - testImplementation 'junit:junit:4.12' - compileOnly 'com.android.support:design:28.0.0' -} + compileOnly 'com.google.android.material:material:1.12.0' -//apply plugin: 'maven-publish' -//apply plugin: 'signing' -// -//task androidSourcesJar(type: Jar) { -// archiveClassifier.set("sources") -// from android.sourceSets.main.java.source -// exclude "**/R.class" -// exclude "**/BuildConfig.class" -//} -// -//def projectName = name -//def projectDescription = description -//publishing { -// publications { -// mavenJava(MavenPublication) { -// // group id,发布后引用的依赖的 group id -// groupId SMART_GROUP_MVN -// // 发布后引用的依赖的 artifact id -// artifactId projectName -// // 发布的版本 -// version SMART_VERSION -// // 发布的 arr 的文件和源码文件 -// artifact("$buildDir/outputs/aar/${projectName}-release.aar") -// artifact androidSourcesJar -// pom { -// // 构件名称,可以自定义 -// name = projectName -// // 构件描述 -// description = projectDescription -// // 构件主页 -// url = "https://github.com/scwang90/${rootProject.name}" -// // 许可证名称和地址 -// licenses { -// license { -// name = 'The Apache License, Version 2.0' -// url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' -// } -// } -// // 开发者信息 -// developers { -// developer { -// name = SMART_USER -// email = SMART_EMAIL -// } -// } -// // 版本控制仓库地址 -// scm { -// url = "https://github.com/scwang90/${rootProject.name}" -// connection = "scm:git:github.com/scwang90/${rootProject.name}.git" -// developerConnection = "scm:git:ssh://git@github.com/scwang90/${rootProject.name}.git" -// } -// } -// } -// } -// repositories { -// maven { -// // 发布的位置,这里根据发布的版本区分了 SNAPSHOT 和最终版本两种情况 -// def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" -// def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" -// url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl -// credentials { -// // 这里就是之前在 issues.sonatype.org 注册的账号 -// username "${properties["sonatype.username"]}" -// password new String(Base64.mimeDecoder.decode("${properties["sonatype.password"]}"), "UTF-8") -// } -// } -// } -//} -//signing { -// sign publishing.publications -//} \ No newline at end of file + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' +} diff --git a/refresh-layout-kernel/src/androidTest/java/com/scwang/smart/refresh/layout/ExampleInstrumentedTest.java b/refresh-layout-kernel/src/androidTest/java/com/scwang/smart/refresh/layout/ExampleInstrumentedTest.java index 18d5469a4..d13614571 100644 --- a/refresh-layout-kernel/src/androidTest/java/com/scwang/smart/refresh/layout/ExampleInstrumentedTest.java +++ b/refresh-layout-kernel/src/androidTest/java/com/scwang/smart/refresh/layout/ExampleInstrumentedTest.java @@ -1,13 +1,14 @@ package com.scwang.smart.refresh.layout; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumentation test, which will execute on an Android device. @@ -17,10 +18,10 @@ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @Test - public void useAppContext() throws Exception { + public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.scwang.smartrefresh.layout.test", appContext.getPackageName()); + assertEquals("com.scwang.smart.refresh.layout.test", appContext.getPackageName()); } } diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/SmartRefreshLayout.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/SmartRefreshLayout.java index 12be6f520..35963cbac 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/SmartRefreshLayout.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/SmartRefreshLayout.java @@ -11,16 +11,8 @@ import android.graphics.Paint; import android.os.Handler; import android.os.Looper; -import android.support.annotation.ColorInt; -import android.support.annotation.ColorRes; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; -import android.support.v4.view.NestedScrollingChildHelper; -import android.support.v4.view.NestedScrollingParent; -import android.support.v4.view.NestedScrollingParentHelper; -import android.support.v4.view.ViewCompat; import android.util.AttributeSet; +import android.util.Log; import android.view.Gravity; import android.view.MotionEvent; import android.view.VelocityTracker; @@ -30,7 +22,6 @@ import android.view.ViewParent; import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; -import android.widget.AbsListView; import android.widget.Scroller; import android.widget.TextView; import android.widget.Toast; @@ -69,16 +60,25 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import static com.scwang.smart.refresh.layout.util.SmartUtil.dp2px; import static com.scwang.smart.refresh.layout.util.SmartUtil.fling; -import static com.scwang.smart.refresh.layout.util.SmartUtil.isContentView; import static java.lang.System.currentTimeMillis; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; +import androidx.core.view.NestedScrollingChildHelper; +import androidx.core.view.NestedScrollingParent; +import androidx.core.view.NestedScrollingParentHelper; +import androidx.core.view.ViewCompat; + /** * 智能刷新布局 * Intelligent RefreshLayout * Created by scwang on 2017/5/26. */ -@SuppressLint("RestrictedApi") @SuppressWarnings({"unused"}) +@SuppressLint("RestrictedApi") public class SmartRefreshLayout extends ViewGroup implements RefreshLayout, NestedScrollingParent/*, NestedScrollingChild*/ { // @@ -175,7 +175,12 @@ public class SmartRefreshLayout extends ViewGroup implements RefreshLayout, Nest protected RefreshComponent mRefreshHeader; //下拉头部视图 protected RefreshComponent mRefreshFooter; //上拉底部视图 - protected RefreshContent mRefreshContent; //显示内容视图 + /** + * 显示内容视图 + * 根据开发设计,本变量最终不可能为空,因为在 onAttachedToWindow 中判断如果未设置内容视图 + * 会自动创建一个 TextView 提示必须创建,并且 TextView 会变为 内容视图 + */ + protected RefreshContent mRefreshContent; // protected Paint mPaint; @@ -209,6 +214,14 @@ public class SmartRefreshLayout extends ViewGroup implements RefreshLayout, Nest protected boolean mFooterLocked = false;//Footer 正在loading 的时候是否锁住 列表不能向上滚动 + /* + * https://github.com/scwang90/SmartRefreshLayout/issues/1540 + * 问题修复辅助变量,记录关闭动画执行时手势事件 ACTION_DOWN 的触发时间 和 按下的坐标 + */ + protected long mLastTimeOnActionDown = 0; + protected float mLastTouchXOnActionDown = 0; + protected float mLastTouchYOnActionDown = 0; + //全局默认 Footer 构造器 protected static DefaultRefreshFooterCreator sFooterCreator = null; //全局默认 Header 构造器 @@ -243,6 +256,11 @@ public SmartRefreshLayout(Context context, AttributeSet attrs) { TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SmartRefreshLayout); + /* + * SmartRefreshLayout 继承 ViewGroup 后即使不设置 android:clipToPadding,也等效于 android:clipToPadding=true + * 特意添加 android:clipToPadding 来在 Java 代码中 判断是否设置过,没有设置强制 setClipToPadding(false) + * android:clipChildren 也是同样 + */ if (!ta.hasValue(R.styleable.SmartRefreshLayout_android_clipToPadding)) { super.setClipToPadding(false); } @@ -329,16 +347,18 @@ protected void onFinishInflate() { throw new RuntimeException("最多只支持3个子View,Most only support three sub view"); } - int contentLevel = 0; - int indexContent = -1; + int contentLevel = 0; // 当前找到内容布局的级别(0还没找到 1普通内容 2可滚动内容) + int indexContent = -1; // 内容布局所在的序号 for (int i = 0; i < count; i++) { View view = super.getChildAt(i); - if (isContentView(view) && (contentLevel < 2 || i == 1)) { + if (SmartUtil.isContentView(view) && (contentLevel < 2 || i == 1)) { + // 可滚动内容 indexContent = i; - contentLevel = 2; + contentLevel = 2; // 标记为可滚动内容,不会再被替换 } else if (!(view instanceof RefreshComponent) && contentLevel < 1) { + // 普通内容 indexContent = i; - contentLevel = i > 0 ? 1 : 0; + contentLevel = i > 0 ? 1 : 0; // 如果是第一个标记为:未找到(第一个有可能是自定义Header),否则标记为:普通内容 } } @@ -369,7 +389,7 @@ protected void onFinishInflate() { } /** - * 重写 onAttachedToWindow 来完成 smart 的特定功能 + * 重写 onAttachedToWindow 来完成 smart 的特定功能 (在 onFinishInflate 之后执行) * 1.添加默认或者全局设置的 Header 和 Footer (缺省情况下才会) * 2.做 Content 为空时的 TextView 提示 * 3.智能开启 嵌套滚动 NestedScrollingEnabled @@ -381,6 +401,7 @@ protected void onAttachedToWindow() { mAttachedToWindow = true; final View thisView = this; + // 在非编辑模式下,如果 onFinishInflate 初始化组件未成功,onAttachedToWindow 可以进行补充处理 if (!thisView.isInEditMode()) { if (mRefreshHeader == null) { @@ -765,7 +786,7 @@ protected void onDetachedFromWindow() { * @param drawingTime 绘制耗时 */ @Override - protected boolean drawChild(Canvas canvas, View child, long drawingTime) { + protected boolean drawChild(@NonNull Canvas canvas, View child, long drawingTime) { final View thisView = this; final View contentView = mRefreshContent != null ? mRefreshContent.getView() : null; if (mRefreshHeader != null && mRefreshHeader.getView() == child) { @@ -903,6 +924,17 @@ public boolean dispatchTouchEvent(MotionEvent e) { //--------------------------------------------------------------------------- // + if (action == MotionEvent.ACTION_DOWN) { + /* + * https://github.com/scwang90/SmartRefreshLayout/issues/1540 + * 辅助下面的问题修复,拦截手势事件的时候,对 MotionEvent.ACTION_DOWN 的触发时间进行备份 + * 计算是否点击需要判断 ACTION_DOWN 和 ACTION_UP 的时间间隔,还有按下坐标 + */ + mLastTouchXOnActionDown = touchX; + mLastTouchYOnActionDown = touchY; + mLastTimeOnActionDown = System.currentTimeMillis(); + } + //--------------------------------------------------------------------------- //嵌套滚动模式辅助 @@ -929,9 +961,38 @@ public boolean dispatchTouchEvent(MotionEvent e) { || (mHeaderNeedTouchEventWhenRefreshing && ((mState.isOpening || mState.isFinishing) && mState.isHeader)) || (mFooterNeedTouchEventWhenLoading && ((mState.isOpening || mState.isFinishing) && mState.isFooter))) { return super.dispatchTouchEvent(e); + } else if (mState.isFinishing) { + /* + * https://github.com/scwang90/SmartRefreshLayout/issues/1540 + * 在刷新动画关闭的时候,点击列表无法跳转, + * 是因为下面的 if (interceptAnimatorByAction || mState.isFinishing ) return false + * 屏蔽了所有手势事件,屏蔽的原因是如果关闭动画正在执行的时候,随意滑动列表会导致意外的错乱 + * 目前的修复方法并不是放开屏蔽,而是针对 先 ACTION_DOWN 再 ACTION_UP 的点击事件进行补偿处理 + * 从而实现,完成动画执行时,列表不可手动滑动,但是可以点击列表项 + */ + if (action == MotionEvent.ACTION_UP) { + //要求时间间隔小于半秒钟 + if (System.currentTimeMillis() - mLastTimeOnActionDown < 500) { + float dx = touchX - mLastTouchXOnActionDown; + float dy = touchY - mLastTouchYOnActionDown; + //要求坐标偏移小于系统阈值 + if (Math.abs(dx) < mTouchSlop && Math.abs(dy) < mTouchSlop) { + e.setAction(MotionEvent.ACTION_DOWN); + super.dispatchTouchEvent(e); + e.setAction(MotionEvent.ACTION_UP); + return super.dispatchTouchEvent(e); + } + } + } + /* + * 返回 true,但是不调用 super.dispatchTouchEvent(e),表示已经处理,但实际情况是没处理。 + * 这样在拦截到 down move 事件时,才会继续触发 up 事件 + * 否则 返回false 后面不会再接收到 move 和 up 的事件 + */ + return true; } - if (interceptAnimatorByAction(action) || mState.isFinishing + if (interceptAnimatorByAction(action) || (mState == RefreshState.Loading && mDisableContentWhenLoading) || (mState == RefreshState.Refreshing && mDisableContentWhenRefresh)) { return false; @@ -1081,8 +1142,7 @@ public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { // scrolling, ignore this request so that the vertical scroll event // isn't stolen View target = mRefreshContent.getScrollableView(); - if ((android.os.Build.VERSION.SDK_INT >= 21 || !(target instanceof AbsListView)) - && (/*target == null || */ViewCompat.isNestedScrollingEnabled(target))) { + if (ViewCompat.isNestedScrollingEnabled(target)) { mEnableDisallowIntercept = disallowIntercept; super.requestDisallowInterceptTouchEvent(disallowIntercept); } @@ -1561,12 +1621,7 @@ public void onAnimationEnd(Animator animation) { } } }); - reboundAnimator.addUpdateListener(new AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - mKernel.moveSpinner((int) animation.getAnimatedValue(), false); - } - }); + reboundAnimator.addUpdateListener(animation -> mKernel.moveSpinner((int) animation.getAnimatedValue(), false)); reboundAnimator.setStartDelay(startDelay); // reboundAnimator.setDuration(20000); reboundAnimator.start(); @@ -1645,6 +1700,7 @@ protected void overSpinner() { * 拖拽导致 状态重置 最终导致 显示 NoMoreData Footer 菊花却任然在转的情况 * overSpinner 时 LoadFinish 状态无任何操作即可 */ + Log.d("SmartRefreshLayout", "overSpinner 时 LoadFinish 状态无任何操作即可"); } else if (mSpinner != 0) { mKernel.animSpinner(0); } @@ -1652,6 +1708,7 @@ protected void overSpinner() { /** * 黏性移动 spinner + * 阻尼计算,根据原始华东距离,计算出阻尼后的距离 * @param spinner 偏移量 */ protected void moveSpinnerInfinitely(float spinner) { @@ -1685,7 +1742,7 @@ protected void moveSpinnerInfinitely(float spinner) { * 源码引用,然后删掉下面4行的代码 */ if (spinner > mScreenHeightPixels * 5 && (thisView.getTag() == null && thisView.getTag(R.id.srl_tag) == null) && mLastTouchY < mScreenHeightPixels / 6f && mLastTouchX < mScreenHeightPixels / 16f) { - String egg = "你这么死拉,臣妾做不到啊!"; + String egg = "不要再拉了,臣妾做不到啊!"; Toast.makeText(thisView.getContext(), egg, Toast.LENGTH_SHORT).show(); thisView.setTag(R.id.srl_tag, egg); } @@ -1740,25 +1797,24 @@ protected void moveSpinnerInfinitely(float spinner) { /* * 自动加载模式时,延迟触发 onLoadMore ,mReboundDuration 保证动画能顺利执行 */ - mHandler.postDelayed(new Runnable() { - @Override - public void run() { - if (mLoadMoreListener != null) { - mLoadMoreListener.onLoadMore(SmartRefreshLayout.this); - } else if (mOnMultiListener == null) { - finishLoadMore(2000);//如果没有任何加载监听器,两秒之后自动关闭 - } - final OnLoadMoreListener listener = mOnMultiListener; - if (listener != null) { - listener.onLoadMore(SmartRefreshLayout.this); - } + mHandler.postDelayed(() -> { + if (mLoadMoreListener != null) { + mLoadMoreListener.onLoadMore(SmartRefreshLayout.this); + } else if (mOnMultiListener == null) { + finishLoadMore(2000);//如果没有任何加载监听器,两秒之后自动关闭 + } + final OnLoadMoreListener listener = mOnMultiListener; + if (listener != null) { + listener.onLoadMore(SmartRefreshLayout.this); } }, mReboundDuration); } } + // // + // protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { // return p instanceof LayoutParams; // } @@ -1831,7 +1887,7 @@ public void onNestedScrollAccepted(@NonNull View child, @NonNull View target, in // Dispatch up to the nested parent mNestedChild.startNestedScroll(axes & ViewCompat.SCROLL_AXIS_VERTICAL); - mTotalUnconsumed = mSpinner;//0; + mTotalUnconsumed = mSpinner; mNestedInProgress = true; interceptAnimatorByAction(MotionEvent.ACTION_DOWN); @@ -2259,6 +2315,7 @@ public RefreshLayout setReboundDuration(int duration) { /** * Set whether to enable pull-up loading more (enabled by default). * 设置是否启用上拉加载更多(默认启用) + * 注意:本方法仅仅支持初始化的时候调用,如过没有数据的时候,需要关闭请使用: finishLoadMoreWithNoMoreData 或者 finishRefreshWithNoMoreData * @param enabled 是否启用 * @return RefreshLayout */ @@ -2981,7 +3038,7 @@ public void run() { notifyStateChanged(RefreshState.PullDownCanceled); } // mKernel.setState(RefreshState.None); - } else if (mState == RefreshState.Refreshing && mRefreshHeader != null && mRefreshContent != null) { + } else if (mState == RefreshState.Refreshing) { count++; mHandler.postDelayed(this, more); //提前设置 状态为 RefreshFinish 防止 postDelayed 导致 finishRefresh 过后,外部判断 state 还是 Refreshing @@ -2994,9 +3051,13 @@ public void run() { setNoMoreData(true); } } else { - int startDelay = mRefreshHeader.onFinish(SmartRefreshLayout.this, success); - if (mOnMultiListener != null && mRefreshHeader instanceof RefreshHeader) { - mOnMultiListener.onHeaderFinish((RefreshHeader) mRefreshHeader, success); + // 本else 分支的触发是的代码是上面的:count++;mHandler.postDelayed(this, more); + int startDelay = 0; + if (mRefreshHeader != null) { + startDelay = mRefreshHeader.onFinish(SmartRefreshLayout.this, success); + if (mOnMultiListener != null && mRefreshHeader instanceof RefreshHeader) { + mOnMultiListener.onHeaderFinish((RefreshHeader) mRefreshHeader, success); + } } //startDelay < Integer.MAX_VALUE 表示 延时 startDelay 毫秒之后,回弹关闭刷新 if (startDelay < Integer.MAX_VALUE) { @@ -3161,60 +3222,57 @@ public void run() { } } //准备:偏移并结束状态 - mHandler.postDelayed(new Runnable() { - @Override - public void run() { - AnimatorUpdateListener updateListener = null; - if (mEnableScrollContentWhenLoaded && offset < 0) { - updateListener = mRefreshContent.scrollContentWhenFinished(mSpinner); - if (updateListener != null) {//如果内容需要滚动显示新数据 - updateListener.onAnimationUpdate(ValueAnimator.ofInt(0, 0));//直接滚动, Footer 的距离 - } + mHandler.postDelayed(() -> { + AnimatorUpdateListener updateListener = null; + if (mEnableScrollContentWhenLoaded && offset < 0) { + updateListener = mRefreshContent.scrollContentWhenFinished(mSpinner); + if (updateListener != null) {//如果内容需要滚动显示新数据 + updateListener.onAnimationUpdate(ValueAnimator.ofInt(0, 0));//直接滚动, Footer 的距离 } - ValueAnimator animator = null;//动议动画和动画结束回调 - AnimatorListenerAdapter listenerAdapter = new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - if (animation != null && animation.getDuration() == 0) { - return;//0 表示被取消 - } - mFooterLocked = false; - if (noMoreData) { - setNoMoreData(true); - } - if (mState == RefreshState.LoadFinish) { - notifyStateChanged(RefreshState.None); - } + } + ValueAnimator animator = null;//动议动画和动画结束回调 + AnimatorListenerAdapter listenerAdapter = new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + if (animation != null && animation.getDuration() == 0) { + return;//0 表示被取消 } - }; - if (mSpinner > 0) { //大于0表示下拉, 这是 Header 可见, Footer 不可见 - animator = mKernel.animSpinner(0);//关闭 Header 回到原始状态 - } else if (updateListener != null || mSpinner == 0) {//如果 Header 和 Footer 都不可见 或者内容需要滚动显示新内容 - if (reboundAnimator != null) { - reboundAnimator.setDuration(0);//cancel会触发End调用,可以判断0来确定是否被cancel - reboundAnimator.cancel();//会触发 cancel 和 end 调用 - reboundAnimator = null;//取消之前的任何动画 + mFooterLocked = false; + if (noMoreData) { + setNoMoreData(true); } - //直接关闭 Header 或者 Header 到原始状态 - mKernel.moveSpinner(0, false); - mKernel.setState(RefreshState.None); - } else {//准备按正常逻辑关闭Footer - if (noMoreData && mEnableFooterFollowWhenNoMoreData) {//如果需要显示没有更多数据 - if (mSpinner >= -mFooterHeight) {//如果 Footer 的位置再可见范围内 - notifyStateChanged(RefreshState.None);//直接通知重置状态,不关闭 Footer - } else {//如果 Footer 的位置超出 Footer 显示高度 (这个情况的概率应该很低, 手指故意拖拽 Footer 向上超出原位置时会触发) - animator = mKernel.animSpinner(-mFooterHeight);//通过动画让 Footer 回到全显示状态位置 - } - } else { - animator = mKernel.animSpinner(0);//动画正常关闭 Footer + if (mState == RefreshState.LoadFinish) { + notifyStateChanged(RefreshState.None); } } - if (animator != null) { - animator.addListener(listenerAdapter);//如果通过动画关闭,绑定动画结束回调 + }; + if (mSpinner > 0) { //大于0表示下拉, 这是 Header 可见, Footer 不可见 + animator = mKernel.animSpinner(0);//关闭 Header 回到原始状态 + } else if (updateListener != null || mSpinner == 0) {//如果 Header 和 Footer 都不可见 或者内容需要滚动显示新内容 + if (reboundAnimator != null) { + reboundAnimator.setDuration(0);//cancel会触发End调用,可以判断0来确定是否被cancel + reboundAnimator.cancel();//会触发 cancel 和 end 调用 + reboundAnimator = null;//取消之前的任何动画 + } + //直接关闭 Header 或者 Header 到原始状态 + mKernel.moveSpinner(0, false); + mKernel.setState(RefreshState.None); + } else {//准备按正常逻辑关闭Footer + if (noMoreData && mEnableFooterFollowWhenNoMoreData) {//如果需要显示没有更多数据 + if (mSpinner >= -mFooterHeight) {//如果 Footer 的位置再可见范围内 + notifyStateChanged(RefreshState.None);//直接通知重置状态,不关闭 Footer + } else {//如果 Footer 的位置超出 Footer 显示高度 (这个情况的概率应该很低, 手指故意拖拽 Footer 向上超出原位置时会触发) + animator = mKernel.animSpinner(-mFooterHeight);//通过动画让 Footer 回到全显示状态位置 + } } else { - listenerAdapter.onAnimationEnd(null);//如果没有动画,立即执行结束回调(必须逻辑) + animator = mKernel.animSpinner(0);//动画正常关闭 Footer } } + if (animator != null) { + animator.addListener(listenerAdapter);//如果通过动画关闭,绑定动画结束回调 + } else { + listenerAdapter.onAnimationEnd(null);//如果没有动画,立即执行结束回调(必须逻辑) + } }, mSpinner < 0 ? startDelay : 0); } } @@ -3303,6 +3361,7 @@ public boolean autoRefresh(int delayed) { /** * Display refresh animation without triggering events. * 显示刷新动画,不触发事件 + * 注意:本方法只会开启动画,不会触发刷新事件。所以需要自己在外部适当的时机调用 finishRefresh 来关闭刷新动画 * @return true or false, Status non-compliance will fail. * 是否成功(状态不符合会失败) */ @@ -3324,55 +3383,42 @@ public boolean autoRefreshAnimationOnly() { @Override public boolean autoRefresh(int delayed, final int duration, final float dragRate,final boolean animationOnly) { if (mState == RefreshState.None && isEnableRefreshOrLoadMore(mEnableRefresh)) { - Runnable runnable = new Runnable() { - @Override - public void run() { - if (mViceState != RefreshState.Refreshing) return; - if (reboundAnimator != null) { - reboundAnimator.setDuration(0);//cancel会触发End调用,可以判断0来确定是否被cancel - reboundAnimator.cancel();//会触发 cancel 和 end 调用 - reboundAnimator = null; - } + Runnable runnable = () -> { + if (mViceState != RefreshState.Refreshing) return; + if (reboundAnimator != null) { + reboundAnimator.setDuration(0);//cancel会触发End调用,可以判断0来确定是否被cancel + reboundAnimator.cancel();//会触发 cancel 和 end 调用 + reboundAnimator = null; + } - final View thisView = SmartRefreshLayout.this; - mLastTouchX = thisView.getMeasuredWidth() / 2f; - mKernel.setState(RefreshState.PullDownToRefresh); + final View thisView = SmartRefreshLayout.this; + mLastTouchX = thisView.getMeasuredWidth() / 2f; + mKernel.setState(RefreshState.PullDownToRefresh); - final float height = mHeaderHeight == 0 ? mHeaderTriggerRate : mHeaderHeight; - final float dragHeight = dragRate < 10 ? height * dragRate : dragRate; - reboundAnimator = ValueAnimator.ofInt(mSpinner, (int) (dragHeight)); - reboundAnimator.setDuration(duration); - reboundAnimator.setInterpolator(new SmartUtil(SmartUtil.INTERPOLATOR_VISCOUS_FLUID)); - reboundAnimator.addUpdateListener(new AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - if (reboundAnimator != null && mRefreshHeader != null) { - mKernel.moveSpinner((int) animation.getAnimatedValue(), true); - } - } - }); - reboundAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - if (animation != null && animation.getDuration() == 0) { - return;//0 表示被取消 - } - reboundAnimator = null; - if (mRefreshHeader != null) { - if (mState != RefreshState.ReleaseToRefresh) { - mKernel.setState(RefreshState.ReleaseToRefresh); - } - setStateRefreshing(!animationOnly); - } else { - /* - * 2019-12-24 修复 mRefreshHeader=null 时状态错乱问题 - */ - mKernel.setState(RefreshState.None); - } - } - }); - reboundAnimator.start(); + if (mRefreshHeader != null && mRefreshHeader.autoOpen(duration, dragRate, animationOnly)) { + /* + * 2022-11-03 添加Header可以自己实现 autoOpen ,返回true表示支持,返回False表示不支持,使用老版本的 autoOpen + */ + return; } + + final float height = mHeaderHeight == 0 ? mHeaderTriggerRate : mHeaderHeight; + final float dragHeight = dragRate < 10 ? height * dragRate : dragRate; + reboundAnimator = ValueAnimator.ofInt(mSpinner, (int) (dragHeight)); + reboundAnimator.setDuration(duration); + reboundAnimator.setInterpolator(new SmartUtil(SmartUtil.INTERPOLATOR_VISCOUS_FLUID)); + reboundAnimator.addUpdateListener(animation -> { + if (reboundAnimator != null) { + mKernel.moveSpinner((int) animation.getAnimatedValue(), true); + } + }); + reboundAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mKernel.onAutoRefreshAnimationEnd(animation, animationOnly); + } + }); + reboundAnimator.start(); }; setViceState(RefreshState.Refreshing); if (delayed > 0) { @@ -3432,55 +3478,42 @@ public boolean autoLoadMoreAnimationOnly() { @Override public boolean autoLoadMore(int delayed, final int duration, final float dragRate, final boolean animationOnly) { if (mState == RefreshState.None && (isEnableRefreshOrLoadMore(mEnableLoadMore) && !mFooterNoMoreData)) { - Runnable runnable = new Runnable() { - @Override - public void run() { - if (mViceState != RefreshState.Loading)return; - if (reboundAnimator != null) { - reboundAnimator.setDuration(0);//cancel会触发End调用,可以判断0来确定是否被cancel - reboundAnimator.cancel();//会触发 cancel 和 end 调用 - reboundAnimator = null; - } + Runnable runnable = () -> { + if (mViceState != RefreshState.Loading)return; + if (reboundAnimator != null) { + reboundAnimator.setDuration(0);//cancel会触发End调用,可以判断0来确定是否被cancel + reboundAnimator.cancel();//会触发 cancel 和 end 调用 + reboundAnimator = null; + } - final View thisView = SmartRefreshLayout.this; - mLastTouchX = thisView.getMeasuredWidth() / 2f; - mKernel.setState(RefreshState.PullUpToLoad); + final View thisView = SmartRefreshLayout.this; + mLastTouchX = thisView.getMeasuredWidth() / 2f; + mKernel.setState(RefreshState.PullUpToLoad); - final float height = mFooterHeight == 0 ? mFooterTriggerRate : mFooterHeight; - final float dragHeight = dragRate < 10 ? dragRate * height : dragRate; - reboundAnimator = ValueAnimator.ofInt(mSpinner, - (int) (dragHeight)); - reboundAnimator.setDuration(duration); - reboundAnimator.setInterpolator(new SmartUtil(SmartUtil.INTERPOLATOR_VISCOUS_FLUID)); - reboundAnimator.addUpdateListener(new AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - if (reboundAnimator != null && mRefreshFooter != null) { - mKernel.moveSpinner((int) animation.getAnimatedValue(), true); - } - } - }); - reboundAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - if (animation != null && animation.getDuration() == 0) { - return;//0 表示被取消 - } - reboundAnimator = null; - if (mRefreshFooter != null) { - if (mState != RefreshState.ReleaseToLoad) { - mKernel.setState(RefreshState.ReleaseToLoad); - } - setStateLoading(!animationOnly); - } else { - /* - * 2019-12-24 修复 mRefreshFooter=null 时状态错乱问题 - */ - mKernel.setState(RefreshState.None); - } - } - }); - reboundAnimator.start(); + if (mRefreshFooter != null && mRefreshFooter.autoOpen(duration, dragRate, animationOnly)) { + /* + * 2022-11-03 添加Header可以自己实现 autoOpen ,返回true表示支持,返回False表示不支持,使用老版本的 autoOpen + */ + return; } + + final float height = mFooterHeight == 0 ? mFooterTriggerRate : mFooterHeight; + final float dragHeight = dragRate < 10 ? dragRate * height : dragRate; + reboundAnimator = ValueAnimator.ofInt(mSpinner, - (int) (dragHeight)); + reboundAnimator.setDuration(duration); + reboundAnimator.setInterpolator(new SmartUtil(SmartUtil.INTERPOLATOR_VISCOUS_FLUID)); + reboundAnimator.addUpdateListener(animation -> { + if (reboundAnimator != null && mRefreshFooter != null) { + mKernel.moveSpinner((int) animation.getAnimatedValue(), true); + } + }); + reboundAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mKernel.onAutoLoadMoreAnimationEnd(animation, animationOnly); + } + }); + reboundAnimator.start(); }; setViceState(RefreshState.Loading); if (delayed > 0) { @@ -3588,7 +3621,6 @@ public RefreshKernel setState(@NonNull RefreshState state) { case PullDownCanceled: if (!mState.isOpening && isEnableRefreshOrLoadMore(mEnableRefresh)) { notifyStateChanged(RefreshState.PullDownCanceled); -// resetStatus(); setState(RefreshState.None); } else { setViceState(RefreshState.PullDownCanceled); @@ -3597,7 +3629,6 @@ public RefreshKernel setState(@NonNull RefreshState state) { case PullUpCanceled: if (isEnableRefreshOrLoadMore(mEnableLoadMore) && !mState.isOpening && !(mFooterNoMoreData && mEnableFooterFollowWhenNoMoreData && mFooterNoMoreDataEffective)) { notifyStateChanged(RefreshState.PullUpCanceled); -// resetStatus(); setState(RefreshState.None); } else { setViceState(RefreshState.PullUpCanceled); @@ -3650,27 +3681,6 @@ public RefreshKernel setState(@NonNull RefreshState state) { default: notifyStateChanged(state); break; -// case RefreshFinish: { -// if (mState == RefreshState.Refreshing) { -// notifyStateChanged(RefreshState.RefreshFinish); -// } -// break; -// } -// case LoadFinish:{ -// if (mState == RefreshState.Loading) { -// notifyStateChanged(RefreshState.LoadFinish); -// } -// break; -// } -// case TwoLevelReleased: -// notifyStateChanged(RefreshState.TwoLevelReleased); -// break; -// case TwoLevelFinish: -// notifyStateChanged(RefreshState.TwoLevelFinish); -// break; -// case TwoLevel: -// notifyStateChanged(RefreshState.TwoLevel); -// break; } return null; } @@ -3766,7 +3776,6 @@ public RefreshKernel moveSpinner(final int spinner, final boolean isDragging) { tSpinner = spinner; } else if (oldSpinner < 0) { changed = true; - tSpinner = 0; } } /* @@ -3778,7 +3787,6 @@ public RefreshKernel moveSpinner(final int spinner, final boolean isDragging) { tSpinner = spinner; } else if (oldSpinner > 0) { changed = true; - tSpinner = 0; } } if (changed) { @@ -3960,6 +3968,40 @@ public RefreshKernel requestFloorBottomPullUpToCloseRate(float rate) { mTwoLevelBottomPullUpToCloseRate = rate; return this; } + + @Override + public RefreshKernel onAutoRefreshAnimationEnd(Animator animation, boolean animationOnly) { + if (animation != null && animation.getDuration() == 0) { + return this;//0 表示被取消 + } + reboundAnimator = null; + if (mState != RefreshState.ReleaseToRefresh) { + this.setState(RefreshState.ReleaseToRefresh); + } + SmartRefreshLayout.this.setStateRefreshing(!animationOnly); + return this; + } + + @Override + public RefreshKernel onAutoLoadMoreAnimationEnd(Animator animation, boolean animationOnly) { + if (animation != null && animation.getDuration() == 0) { + return this;//0 表示被取消 + } + reboundAnimator = null; + if (mRefreshFooter != null) { + if (mState != RefreshState.ReleaseToLoad) { + this.setState(RefreshState.ReleaseToLoad); + } + SmartRefreshLayout.this.setStateLoading(!animationOnly); + } else { + /* + * 2019-12-24 修复 mRefreshFooter=null 时状态错乱问题 + */ + this.setState(RefreshState.None); + } + return this; + } + // } // diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshComponent.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshComponent.java index a14919209..b27689d06 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshComponent.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshComponent.java @@ -1,20 +1,21 @@ package com.scwang.smart.refresh.layout.api; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; -import android.support.annotation.RestrictTo; import android.view.View; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.RestrictTo; + import com.scwang.smart.refresh.layout.constant.SpinnerStyle; import com.scwang.smart.refresh.layout.listener.OnStateChangedListener; -import static android.support.annotation.RestrictTo.Scope.LIBRARY; -import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP; -import static android.support.annotation.RestrictTo.Scope.SUBCLASSES; +import static androidx.annotation.RestrictTo.Scope.LIBRARY; +import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; +import static androidx.annotation.RestrictTo.Scope.SUBCLASSES; /** - * 刷新内部组件 + * 刷新组件 * Created by scwang on 2017/5/26. */ public interface RefreshComponent extends OnStateChangedListener { @@ -36,7 +37,7 @@ public interface RefreshComponent extends OnStateChangedListener { * 【仅限框架内调用】设置主题颜色 * @param colors 对应Xml中配置的 srlPrimaryColor srlAccentColor */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) +// @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) void setPrimaryColors(@ColorInt int... colors); /** @@ -45,7 +46,7 @@ public interface RefreshComponent extends OnStateChangedListener { * @param height HeaderHeight or FooterHeight * @param maxDragHeight 最大拖动高度 */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) +// @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight); /** * 【仅限框架内调用】手指拖动下拉(会连续多次调用,添加isDragging并取代之前的onPulling、onReleasing) @@ -55,7 +56,7 @@ public interface RefreshComponent extends OnStateChangedListener { * @param height 高度 HeaderHeight or FooterHeight (offset 可以超过 height 此时 percent 大于 1) * @param maxDragHeight 最大拖动高度 offset 可以超过 height 参数 但是不会超过 maxDragHeight */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) +// @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) void onMoving(boolean isDragging, float percent, int offset, int height, int maxDragHeight); /** @@ -64,7 +65,7 @@ public interface RefreshComponent extends OnStateChangedListener { * @param height 高度 HeaderHeight or FooterHeight * @param maxDragHeight 最大拖动高度 */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) +// @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) void onReleased(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight); /** @@ -73,7 +74,7 @@ public interface RefreshComponent extends OnStateChangedListener { * @param height HeaderHeight or FooterHeight * @param maxDragHeight 最大拖动高度 */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) +// @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight); /** @@ -82,7 +83,7 @@ public interface RefreshComponent extends OnStateChangedListener { * @param success 数据是否成功刷新或加载 * @return 完成动画所需时间 如果返回 Integer.MAX_VALUE 将取消本次完成事件,继续保持原有状态 */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) +// @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) int onFinish(@NonNull RefreshLayout refreshLayout, boolean success); /** @@ -91,7 +92,7 @@ public interface RefreshComponent extends OnStateChangedListener { * @param offsetX 下拉时,手指水平坐标对屏幕的偏移(0 - offsetX - LayoutWidth) * @param offsetMax 最大的偏移量 */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) +// @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) void onHorizontalDrag(float percentX, int offsetX, int offsetMax); /** @@ -99,4 +100,16 @@ public interface RefreshComponent extends OnStateChangedListener { * @return 水平拖动需要消耗更多的时间和资源,所以如果不支持请返回false */ boolean isSupportHorizontalDrag(); + + /** + * Display refresh animation, Multifunction. + * 显示刷新动画并且触发刷新事件 + * @param duration 拖拽动画持续时间 + * @param dragRate 拉拽的高度比率 + * @param animationOnly animation only 只有动画 + * @return If False is returned, this header does not support automatic refresh + * 返回 False 代表本Header不支持自动刷新 + */ + boolean autoOpen(int duration, float dragRate, boolean animationOnly); + } diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshContent.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshContent.java index 01c7e6b1b..47cb32000 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshContent.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshContent.java @@ -1,10 +1,11 @@ package com.scwang.smart.refresh.layout.api; import android.animation.ValueAnimator.AnimatorUpdateListener; -import android.support.annotation.NonNull; import android.view.MotionEvent; import android.view.View; +import androidx.annotation.NonNull; + import com.scwang.smart.refresh.layout.listener.ScrollBoundaryDecider; /** diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshFooter.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshFooter.java index 97d289d2a..12ce61208 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshFooter.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshFooter.java @@ -1,10 +1,11 @@ package com.scwang.smart.refresh.layout.api; -import android.support.annotation.RestrictTo; -import static android.support.annotation.RestrictTo.Scope.LIBRARY; -import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP; -import static android.support.annotation.RestrictTo.Scope.SUBCLASSES; +import androidx.annotation.RestrictTo; + +import static androidx.annotation.RestrictTo.Scope.LIBRARY; +import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; +import static androidx.annotation.RestrictTo.Scope.SUBCLASSES; /** * 刷新底部 @@ -17,6 +18,6 @@ public interface RefreshFooter extends RefreshComponent { * @param noMoreData 是否有更多数据 * @return true 支持全部加载完成的状态显示 false 不支持 */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) +// @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) boolean setNoMoreData(boolean noMoreData); } diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshKernel.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshKernel.java index 313014740..30967a6f9 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshKernel.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshKernel.java @@ -1,7 +1,9 @@ package com.scwang.smart.refresh.layout.api; +import android.animation.Animator; import android.animation.ValueAnimator; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.scwang.smart.refresh.layout.constant.RefreshState; @@ -93,5 +95,19 @@ public interface RefreshKernel { * @return RefreshKernel */ RefreshKernel requestFloorBottomPullUpToCloseRate(float rate); + /** + * 当 autoRefresh 动画结束时,处理刷新状态的事件 + * @param animation 动画对象 + * @param animationOnly 是否只播放动画,不通知事件 + * @return RefreshKernel + */ + RefreshKernel onAutoRefreshAnimationEnd(Animator animation, boolean animationOnly); + /** + * 当 autoLoadMore 动画结束时,处理刷新状态的事件 + * @param animation 动画对象 + * @param animationOnly 是否只播放动画,不通知事件 + * @return RefreshKernel + */ + RefreshKernel onAutoLoadMoreAnimationEnd(Animator animation, boolean animationOnly); // } diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshLayout.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshLayout.java index 262eb40a6..c06af7045 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshLayout.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/api/RefreshLayout.java @@ -1,15 +1,16 @@ package com.scwang.smart.refresh.layout.api; -import android.support.annotation.ColorInt; -import android.support.annotation.ColorRes; -import android.support.annotation.FloatRange; -import android.support.annotation.IdRes; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.view.View; import android.view.ViewGroup; import android.view.animation.Interpolator; +import androidx.annotation.ColorInt; +import androidx.annotation.ColorRes; +import androidx.annotation.FloatRange; +import androidx.annotation.IdRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.scwang.smart.refresh.layout.constant.RefreshState; import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; import com.scwang.smart.refresh.layout.listener.OnMultiListener; diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshFooterCreator.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshFooterCreator.java index 4d44dce38..71257dad6 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshFooterCreator.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshFooterCreator.java @@ -1,7 +1,8 @@ package com.scwang.smart.refresh.layout.listener; import android.content.Context; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.scwang.smart.refresh.layout.api.RefreshFooter; import com.scwang.smart.refresh.layout.api.RefreshLayout; diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshHeaderCreator.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshHeaderCreator.java index a13dbb430..cc68ad721 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshHeaderCreator.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshHeaderCreator.java @@ -1,7 +1,8 @@ package com.scwang.smart.refresh.layout.listener; import android.content.Context; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.scwang.smart.refresh.layout.api.RefreshHeader; import com.scwang.smart.refresh.layout.api.RefreshLayout; diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshInitializer.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshInitializer.java index 5c0ad0d3e..1da630da3 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshInitializer.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/DefaultRefreshInitializer.java @@ -1,7 +1,8 @@ package com.scwang.smart.refresh.layout.listener; import android.content.Context; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.scwang.smart.refresh.layout.api.RefreshLayout; diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnLoadMoreListener.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnLoadMoreListener.java index af77f052d..c0186ff73 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnLoadMoreListener.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnLoadMoreListener.java @@ -1,6 +1,6 @@ package com.scwang.smart.refresh.layout.listener; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.scwang.smart.refresh.layout.api.RefreshLayout; diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnRefreshListener.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnRefreshListener.java index 7bdaaf659..6f061027c 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnRefreshListener.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnRefreshListener.java @@ -1,6 +1,6 @@ package com.scwang.smart.refresh.layout.listener; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.scwang.smart.refresh.layout.api.RefreshLayout; diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnStateChangedListener.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnStateChangedListener.java index e70311bc8..a9898ded6 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnStateChangedListener.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/listener/OnStateChangedListener.java @@ -1,15 +1,16 @@ package com.scwang.smart.refresh.layout.listener; -import android.support.annotation.NonNull; -import android.support.annotation.RestrictTo; +import androidx.annotation.NonNull; +import androidx.annotation.RestrictTo; import com.scwang.smart.refresh.layout.api.RefreshLayout; import com.scwang.smart.refresh.layout.constant.RefreshState; -import static android.support.annotation.RestrictTo.Scope.LIBRARY; -import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP; -import static android.support.annotation.RestrictTo.Scope.SUBCLASSES; +import static androidx.annotation.RestrictTo.Scope.LIBRARY; +import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; +import static androidx.annotation.RestrictTo.Scope.SUBCLASSES; + /** * 刷新状态改变监听器 @@ -22,6 +23,6 @@ public interface OnStateChangedListener { * @param oldState 改变之前的状态 * @param newState 改变之后的状态 */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) +// @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState); } diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/simple/SimpleComponent.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/simple/SimpleComponent.java index b8fbb6688..c699a2e7e 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/simple/SimpleComponent.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/simple/SimpleComponent.java @@ -2,14 +2,15 @@ import android.annotation.SuppressLint; import android.content.Context; -import android.support.annotation.ColorInt; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.scwang.smart.refresh.layout.SmartRefreshLayout; import com.scwang.smart.refresh.layout.api.RefreshComponent; import com.scwang.smart.refresh.layout.api.RefreshFooter; @@ -24,7 +25,7 @@ /** * Component 初步实现 - * 实现 Header 和 Footer 时,继承 ComponentAbstract 的话可以少写很多接口方法 + * 实现 Header 和 Footer 时,继承 SimpleComponent 的话可以少写很多接口方法 * Created by scwang on 2018/2/6. */ public abstract class SimpleComponent extends RelativeLayout implements RefreshComponent { @@ -188,4 +189,9 @@ public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull Refres public boolean setNoMoreData(boolean noMoreData) { return mWrappedInternal instanceof RefreshFooter && ((RefreshFooter) mWrappedInternal).setNoMoreData(noMoreData); } + + @Override + public boolean autoOpen(int duration, float dragRate, boolean animationOnly) { + return false; + } } diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/simple/SimpleMultiListener.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/simple/SimpleMultiListener.java index 975734dea..34a0fa3de 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/simple/SimpleMultiListener.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/simple/SimpleMultiListener.java @@ -1,6 +1,6 @@ package com.scwang.smart.refresh.layout.simple; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.scwang.smart.refresh.layout.api.RefreshFooter; import com.scwang.smart.refresh.layout.api.RefreshHeader; diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/util/DesignUtil.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/util/DesignUtil.java index aaffa3b69..2af47afe3 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/util/DesignUtil.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/util/DesignUtil.java @@ -1,10 +1,11 @@ package com.scwang.smart.refresh.layout.util; -import android.support.design.widget.AppBarLayout; -import android.support.design.widget.CoordinatorLayout; import android.view.View; import android.view.ViewGroup; +import androidx.coordinatorlayout.widget.CoordinatorLayout; + +import com.google.android.material.appbar.AppBarLayout; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.listener.CoordinatorLayoutListener; @@ -22,14 +23,9 @@ public static void checkCoordinatorLayout(View content, RefreshKernel kernel, fi for (int i = layout.getChildCount() - 1; i >= 0; i--) { View view = layout.getChildAt(i); if (view instanceof AppBarLayout) { - ((AppBarLayout) view).addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { - @Override - public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - listener.onCoordinatorUpdate( - verticalOffset >= 0, - (appBarLayout.getTotalScrollRange() + verticalOffset) <= 0); - } - }); + ((AppBarLayout) view).addOnOffsetChangedListener((appBarLayout, verticalOffset) -> listener.onCoordinatorUpdate( + verticalOffset >= 0, + (appBarLayout.getTotalScrollRange() + verticalOffset) <= 0)); } } } diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/util/SmartUtil.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/util/SmartUtil.java index ec761689b..793e9abb0 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/util/SmartUtil.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/util/SmartUtil.java @@ -1,15 +1,9 @@ package com.scwang.smart.refresh.layout.util; +import android.annotation.SuppressLint; import android.content.res.Resources; import android.graphics.PointF; import android.os.Build; -import android.support.annotation.NonNull; -import android.support.v4.view.NestedScrollingChild; -import android.support.v4.view.NestedScrollingParent; -import android.support.v4.view.ScrollingView; -import android.support.v4.view.ViewPager; -import android.support.v4.widget.NestedScrollView; -import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; import android.view.animation.Interpolator; @@ -18,6 +12,15 @@ import android.widget.ListView; import android.widget.ScrollView; +import androidx.annotation.NonNull; +import androidx.core.view.NestedScrollingChild; +import androidx.core.view.NestedScrollingParent; +import androidx.core.view.ScrollingView; +import androidx.core.widget.NestedScrollView; +import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager.widget.ViewPager; +import androidx.viewpager2.widget.ViewPager2; + import com.scwang.smart.refresh.layout.api.RefreshComponent; import com.scwang.smart.refresh.layout.kernel.R; @@ -33,7 +36,7 @@ public class SmartUtil implements Interpolator { public static int INTERPOLATOR_VISCOUS_FLUID = 0; public static int INTERPOLATOR_DECELERATE = 1; - private int type; + private final int type; public SmartUtil(int type) { this.type = type; @@ -56,6 +59,7 @@ public static int measureViewHeight(View view) { return view.getMeasuredHeight(); } + @SuppressLint("ObsoleteSdkInt") public static void scrollListBy(@NonNull AbsListView listView, int y) { if (Build.VERSION.SDK_INT >= 19) { // Call the framework version directly @@ -98,6 +102,7 @@ public static boolean isContentView(View view) { } return isScrollableView(view) || view instanceof ViewPager + || view instanceof ViewPager2 || view instanceof NestedScrollingParent; } @@ -105,9 +110,7 @@ public static void fling(View scrollableView, int velocity) { if (scrollableView instanceof ScrollView) { ((ScrollView) scrollableView).fling(velocity); } else if (scrollableView instanceof AbsListView) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - ((AbsListView) scrollableView).fling(velocity); - } + ((AbsListView) scrollableView).fling(velocity); } else if (scrollableView instanceof WebView) { ((WebView) scrollableView).flingScroll(0, velocity); } else if (scrollableView instanceof NestedScrollView) { @@ -210,7 +213,7 @@ public static boolean isTransformedTouchPointInView(@NonNull View group,@NonNull // // - private static float density = Resources.getSystem().getDisplayMetrics().density; + private static final float density = Resources.getSystem().getDisplayMetrics().density; /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) diff --git a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/wrapper/RefreshContentWrapper.java b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/wrapper/RefreshContentWrapper.java index c21533467..5e154f116 100644 --- a/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/wrapper/RefreshContentWrapper.java +++ b/refresh-layout-kernel/src/main/java/com/scwang/smart/refresh/layout/wrapper/RefreshContentWrapper.java @@ -3,10 +3,6 @@ import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.graphics.PointF; -import android.support.annotation.NonNull; -import android.support.v4.view.NestedScrollingChild; -import android.support.v4.view.NestedScrollingParent; -import android.support.v4.view.ViewPager; import android.view.Gravity; import android.view.MotionEvent; import android.view.View; @@ -15,6 +11,12 @@ import android.widget.FrameLayout; import android.widget.Space; +import androidx.annotation.NonNull; +import androidx.core.view.NestedScrollingChild; +import androidx.core.view.NestedScrollingParent; +import androidx.viewpager.widget.ViewPager; +import androidx.viewpager2.widget.ViewPager2; + import com.scwang.smart.refresh.layout.api.RefreshContent; import com.scwang.smart.refresh.layout.api.RefreshKernel; import com.scwang.smart.refresh.layout.kernel.R; @@ -110,7 +112,7 @@ protected View findScrollableViewByPoint(View content, PointF event, View orgScr for (int i = childCount; i > 0; i--) { View child = viewGroup.getChildAt(i - 1); if (isTransformedTouchPointInView(viewGroup, child, event.x, event.y, point)) { - if (child instanceof ViewPager || !isContentView(child)) { + if (child instanceof ViewPager || child instanceof ViewPager2 || !isContentView(child)) { event.offset(point.x, point.y); child = findScrollableViewByPoint(child, event, orgScrollableView); event.offset(-point.x, -point.y); @@ -266,7 +268,7 @@ public AnimatorUpdateListener scrollContentWhenFinished(final int spinner) { } @Override - public void onAnimationUpdate(ValueAnimator animation) { + public void onAnimationUpdate(@NonNull ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); try { float dy = (value - mLastSpinner) * mScrollableView.getScaleY(); diff --git a/refresh-layout-kernel/src/main/res/values/attrs.xml b/refresh-layout-kernel/src/main/res/values/attrs.xml index e0cdbacb3..ddde53f87 100644 --- a/refresh-layout-kernel/src/main/res/values/attrs.xml +++ b/refresh-layout-kernel/src/main/res/values/attrs.xml @@ -41,6 +41,9 @@ + + + diff --git a/refresh-layout-kernel/src/test/java/com/scwang/smartrefresh/layout/ExampleUnitTest.java b/refresh-layout-kernel/src/test/java/com/scwang/smart/refresh/layout/ExampleUnitTest.java similarity index 68% rename from refresh-layout-kernel/src/test/java/com/scwang/smartrefresh/layout/ExampleUnitTest.java rename to refresh-layout-kernel/src/test/java/com/scwang/smart/refresh/layout/ExampleUnitTest.java index 1bc7ef8ad..2b5ddfecd 100644 --- a/refresh-layout-kernel/src/test/java/com/scwang/smartrefresh/layout/ExampleUnitTest.java +++ b/refresh-layout-kernel/src/test/java/com/scwang/smart/refresh/layout/ExampleUnitTest.java @@ -1,8 +1,8 @@ -package com.scwang.smartrefresh.layout; +package com.scwang.smart.refresh.layout; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). @@ -11,7 +11,7 @@ */ public class ExampleUnitTest { @Test - public void addition_isCorrect() throws Exception { + public void addition_isCorrect() { assertEquals(4, 2 + 2); } } \ No newline at end of file diff --git a/refresh-layout/build.gradle b/refresh-layout/build.gradle index 200c215de..c73603119 100644 --- a/refresh-layout/build.gradle +++ b/refresh-layout/build.gradle @@ -1,18 +1,16 @@ apply plugin: 'com.android.library' -//apply plugin: 'com.novoda.bintray-release' android { - compileSdkVersion 28 + compileSdkVersion 34 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 34 versionCode 1 - versionName "1.0" + versionName SMART_VERSION testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } buildTypes { release { @@ -27,25 +25,22 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - testImplementation 'junit:junit:4.12' - compileOnly 'com.android.support:design:28.0.0' compileOnly project(':refresh-layout-kernel') compileOnly project(':refresh-footer-ball') compileOnly project(':refresh-header-falsify') compileOnly project(':refresh-header-radar') compileOnly project(':refresh-header-two-level') +// compileOnly 'io.github.scwang90:refresh-layout-kernel:3.0.0-alpha' //核心必须依赖 +// compileOnly 'io.github.scwang90:refresh-header-radar:3.0.0-alpha' //雷达刷新头 +// compileOnly 'io.github.scwang90:refresh-header-falsify:3.0.0-alpha' //虚拟刷新头 +// compileOnly 'io.github.scwang90:refresh-header-two-level:3.0.0-alpha' //二级刷新头 +// compileOnly 'io.github.scwang90:refresh-footer-ball:3.0.0-alpha' //球脉冲加载 + + compileOnly 'com.google.android.material:material:1.12.0' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' } -// -//publish { -// userOrg = SMART_USER -// groupId = 'com.scwang.smartrefresh' -// artifactId = 'SmartRefreshLayout' -// publishVersion = SMART_VERSION -// desc = 'An intelligent refresh layout' -// website = "https://github.com/scwang90/${rootProject.name}" -//} diff --git a/refresh-layout/src/androidTest/java/com/scwang/smart/refresh/layout/ExampleInstrumentedTest.java b/refresh-layout/src/androidTest/java/com/scwang/smart/refresh/layout/ExampleInstrumentedTest.java new file mode 100644 index 000000000..d13614571 --- /dev/null +++ b/refresh-layout/src/androidTest/java/com/scwang/smart/refresh/layout/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.scwang.smart.refresh.layout; + +import android.content.Context; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.scwang.smart.refresh.layout.test", appContext.getPackageName()); + } +} diff --git a/refresh-layout/src/androidTest/java/com/scwang/smartrefresh/layout/ExampleInstrumentedTest.java b/refresh-layout/src/androidTest/java/com/scwang/smartrefresh/layout/ExampleInstrumentedTest.java deleted file mode 100644 index fc2af52b6..000000000 --- a/refresh-layout/src/androidTest/java/com/scwang/smartrefresh/layout/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.scwang.smartrefresh.layout; - -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumentation test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.scwang.smartrefresh.layout.test", appContext.getPackageName()); - } -} diff --git a/refresh-layout/src/main/AndroidManifest.xml b/refresh-layout/src/main/AndroidManifest.xml index 3d274dd71..aa611f1c0 100644 --- a/refresh-layout/src/main/AndroidManifest.xml +++ b/refresh-layout/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/SmartRefreshLayout.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/SmartRefreshLayout.java deleted file mode 100644 index 84952e712..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/SmartRefreshLayout.java +++ /dev/null @@ -1,284 +0,0 @@ -package com.scwang.smartrefresh.layout; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.util.AttributeSet; -import android.view.View; - -import com.scwang.smart.refresh.header.ClassicsHeader; -import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator; -import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator; -import com.scwang.smartrefresh.layout.api.DefaultRefreshInitializer; -import com.scwang.smartrefresh.layout.api.RefreshFooter; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.api.ScrollBoundaryDecider; -import com.scwang.smartrefresh.layout.footer.BallPulseFooter; -import com.scwang.smartrefresh.layout.header.BezierRadarHeader; -import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; -import com.scwang.smartrefresh.layout.listener.OnMultiPurposeListener; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener; -import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener; - -import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; -import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; - -/** - * 智能刷新布局 - * Intelligent RefreshLayout - * Created by scwang on 2017/5/26. - */ -@SuppressLint("RestrictedApi") -@SuppressWarnings({"unused"}) -public class SmartRefreshLayout extends com.scwang.smart.refresh.layout.SmartRefreshLayout implements RefreshLayout { - - // - public SmartRefreshLayout(Context context) { - this(context, null); - } - - public SmartRefreshLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - // - - // - - /** - * Set the header of RefreshLayout. - * 设置指定的 Header - * @param header RefreshHeader 刷新头 - * @return RefreshLayout - */ - @Override - public RefreshLayout setRefreshHeader(@NonNull RefreshHeader header) { - return setRefreshHeader(header, MATCH_PARENT, WRAP_CONTENT); - } - - /** - * Set the header of RefreshLayout. - * 设置指定的 Header - * @param header RefreshHeader 刷新头 - * @param width the width in px, can use MATCH_PARENT and WRAP_CONTENT. - * 宽度 可以使用 MATCH_PARENT, WRAP_CONTENT - * @param height the height in px, can use MATCH_PARENT and WRAP_CONTENT. - * 高度 可以使用 MATCH_PARENT, WRAP_CONTENT - * @return RefreshLayout - */ - @Override - public RefreshLayout setRefreshHeader(@NonNull RefreshHeader header, int width, int height) { - super.setRefreshHeader(header, width, height); - return this; - } - - /** - * Set the footer of RefreshLayout. - * 设置指定的 Footer - * @param footer RefreshFooter 刷新尾巴 - * @return RefreshLayout - */ - @Override - public RefreshLayout setRefreshFooter(@NonNull RefreshFooter footer) { - return setRefreshFooter(footer, MATCH_PARENT, WRAP_CONTENT); - } - - /** - * Set the footer of RefreshLayout. - * 设置指定的 Footer - * @param footer RefreshFooter 刷新尾巴 - * @param width the width in px, can use MATCH_PARENT and WRAP_CONTENT. - * 宽度 可以使用 MATCH_PARENT, WRAP_CONTENT - * @param height the height in px, can use MATCH_PARENT and WRAP_CONTENT. - * 高度 可以使用 MATCH_PARENT, WRAP_CONTENT - * @return RefreshLayout - */ - @Override - public RefreshLayout setRefreshFooter(@NonNull RefreshFooter footer, int width, int height) { - super.setRefreshFooter(footer, width, height); - return this; - } - - /** - * Get footer of RefreshLayout - * 获取当前 Footer - * @return RefreshLayout - */ - @Nullable - @Override - public RefreshFooter getRefreshFooter() { - return mRefreshFooter instanceof RefreshFooter ? (RefreshFooter) mRefreshFooter : null; - } - - /** - * Get header of RefreshLayout - * 获取当前 Header - * @return RefreshLayout - */ - @Nullable - @Override - public RefreshHeader getRefreshHeader() { - return mRefreshHeader instanceof RefreshHeader ? (RefreshHeader) mRefreshHeader : null; - } - -// /** -// * Get the current state of RefreshLayout -// * 获取当前状态 -// * @return RefreshLayout -// */ -// @NonNull -// @Override -// public RefreshState getState() { -// return mState; -// } - - - /** - * Set refresh listener separately. - * 单独设置刷新监听器 - * @param listener OnRefreshListener 刷新监听器 - * @return RefreshLayout - */ - @Override - public RefreshLayout setOnRefreshListener(final OnRefreshListener listener) { - super.setOnRefreshListener(new com.scwang.smart.refresh.layout.listener.OnRefreshListener() { - @Override - public void onRefresh(@NonNull com.scwang.smart.refresh.layout.api.RefreshLayout refreshLayout) { - listener.onRefresh(SmartRefreshLayout.this); - } - }); - return this; - } - - /** - * Set load more listener separately. - * 单独设置加载监听器 - * @param listener OnLoadMoreListener 加载监听器 - * @return RefreshLayout - */ - @Override - public RefreshLayout setOnLoadMoreListener(final OnLoadMoreListener listener) { - super.setOnLoadMoreListener(new com.scwang.smart.refresh.layout.listener.OnLoadMoreListener() { - @Override - public void onLoadMore(@NonNull com.scwang.smart.refresh.layout.api.RefreshLayout refreshLayout) { - listener.onLoadMore(SmartRefreshLayout.this); - } - }); - return this; - } - - /** - * Set refresh and load listeners at the same time. - * 同时设置刷新和加载监听器 - * @param listener OnRefreshLoadMoreListener 刷新加载监听器 - * @return RefreshLayout - */ - @Override - public RefreshLayout setOnRefreshLoadMoreListener(final OnRefreshLoadMoreListener listener) { - super.setOnRefreshLoadMoreListener(new com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener() { - @Override - public void onLoadMore(@NonNull com.scwang.smart.refresh.layout.api.RefreshLayout refreshLayout) { - listener.onLoadMore(SmartRefreshLayout.this); - } - - @Override - public void onRefresh(@NonNull com.scwang.smart.refresh.layout.api.RefreshLayout refreshLayout) { - listener.onRefresh(SmartRefreshLayout.this); - } - }); - return this; - } - - /** - * Set up a multi-function listener. - * Recommended {@link com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener} - * 设置多功能监听器 - * 建议使用 {@link com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener} - * @param listener OnMultiPurposeListener 多功能监听器 - * @return RefreshLayout - */ - @Override - public RefreshLayout setOnMultiPurposeListener(OnMultiPurposeListener listener) { - super.setOnMultiListener(new SimpleMultiPurposeListener(listener, this)); - return this; - } - - /** - * Set the scroll boundary Decider, Can customize when you can refresh. - * Recommended {@link com.scwang.smartrefresh.layout.impl.ScrollBoundaryDeciderAdapter} - * 设置滚动边界判断器 - * 建议使用 {@link com.scwang.smartrefresh.layout.impl.ScrollBoundaryDeciderAdapter} - * @param boundary ScrollBoundaryDecider 判断器 - * @return RefreshLayout - */ - @Override - public RefreshLayout setScrollBoundaryDecider(final ScrollBoundaryDecider boundary) { - super.setScrollBoundaryDecider(new ScrollBoundaryDecider() { - @Override - public boolean canRefresh(View content) { - return boundary.canRefresh(content); - } - - @Override - public boolean canLoadMore(View content) { - return boundary.canLoadMore(content); - } - }); - return this; - } - - /** - * 设置默认 Header 构建器 - * @param creator Header构建器 - */ - public static void setDefaultRefreshHeaderCreator(@NonNull final DefaultRefreshHeaderCreator creator) { - com.scwang.smart.refresh.layout.SmartRefreshLayout.setDefaultRefreshHeaderCreator(new com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator() { - @NonNull - @Override - public com.scwang.smart.refresh.layout.api.RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull com.scwang.smart.refresh.layout.api.RefreshLayout layout) { - if (layout instanceof RefreshLayout) { - return creator.createRefreshHeader(context, (RefreshLayout) layout); - } else { - return new BezierRadarHeader(context); - } - } - }); - } - - /** - * 设置默认 Footer 构建器 - * @param creator Footer构建器 - */ - public static void setDefaultRefreshFooterCreator(@NonNull final DefaultRefreshFooterCreator creator) { - com.scwang.smart.refresh.layout.SmartRefreshLayout.setDefaultRefreshFooterCreator(new com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator() { - @NonNull - @Override - public com.scwang.smart.refresh.layout.api.RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull com.scwang.smart.refresh.layout.api.RefreshLayout layout) { - if (layout instanceof RefreshLayout) { - return creator.createRefreshFooter(context, (RefreshLayout) layout); - } else { - return new BallPulseFooter(context); - } - } - }); - } - - /** - * 设置默认 Refresh 初始化器 - * @param initializer 全局初始化器 - */ - public static void setDefaultRefreshInitializer(@NonNull final DefaultRefreshInitializer initializer) { - com.scwang.smart.refresh.layout.SmartRefreshLayout.setDefaultRefreshInitializer(new com.scwang.smart.refresh.layout.listener.DefaultRefreshInitializer() { - @Override - public void initialize(@NonNull Context context, @NonNull com.scwang.smart.refresh.layout.api.RefreshLayout layout) { - if (layout instanceof RefreshLayout) { - initializer.initialize(context, (RefreshLayout)layout); - } - } - }); - } - // - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/DefaultRefreshFooterCreator.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/DefaultRefreshFooterCreator.java deleted file mode 100644 index 16dd939f3..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/DefaultRefreshFooterCreator.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -import android.content.Context; -import android.support.annotation.NonNull; - -/** - * 默认Footer创建器 - * Created by scwang on 2018/1/26. - */ -public interface DefaultRefreshFooterCreator { - @NonNull - RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout); -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/DefaultRefreshHeaderCreator.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/DefaultRefreshHeaderCreator.java deleted file mode 100644 index 628607ae8..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/DefaultRefreshHeaderCreator.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -import android.content.Context; -import android.support.annotation.NonNull; - -/** - * 默认Header创建器 - * Created by scwang on 2018/1/26. - */ -public interface DefaultRefreshHeaderCreator { - @NonNull - RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout); -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/DefaultRefreshInitializer.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/DefaultRefreshInitializer.java deleted file mode 100644 index 90fe2bf51..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/DefaultRefreshInitializer.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -import android.content.Context; -import android.support.annotation.NonNull; - -/** - * 默认全局初始化器 - * Created by scwang on 2018/5/29 0029. - */ -public interface DefaultRefreshInitializer { - void initialize(@NonNull Context context, @NonNull RefreshLayout layout); -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/OnTwoLevelListener.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/OnTwoLevelListener.java deleted file mode 100644 index 3784f4a18..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/OnTwoLevelListener.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -import android.support.annotation.NonNull; - -/** - * 二级刷新监听器 - */ -public interface OnTwoLevelListener { - /** - * 二级刷新触发 - * @param refreshLayout 刷新布局 - * @return true 将会展开二楼状态 false 关闭刷新 - */ - boolean onTwoLevel(@NonNull RefreshLayout refreshLayout); -} \ No newline at end of file diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshFooter.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshFooter.java deleted file mode 100644 index 8983c83ec..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshFooter.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -/** - * 刷新底部 - * Created by scwang on 2017/5/26. - */ -public interface RefreshFooter extends com.scwang.smart.refresh.layout.api.RefreshFooter { - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshHeader.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshHeader.java deleted file mode 100644 index 8fd9b26ba..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshHeader.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -/** - * 刷新头部 - * Created by scwang on 2017/5/26. - */ -public interface RefreshHeader extends com.scwang.smart.refresh.layout.api.RefreshHeader { - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshInternal.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshInternal.java deleted file mode 100644 index e85eb0e96..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshInternal.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -import android.support.annotation.NonNull; - -import com.scwang.smart.refresh.layout.api.RefreshComponent; -import com.scwang.smartrefresh.layout.constant.SpinnerStyle; - - -/** - * 刷新内部组件 - * Created by scwang on 2017/5/26. - */ -public interface RefreshInternal extends RefreshComponent { - - /** - * 获取变换方式 {@link SpinnerStyle} 必须返回 非空 - * @return 变换方式 - */ - @NonNull - SpinnerStyle getSpinnerStyle(); -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshKernel.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshKernel.java deleted file mode 100644 index c68dd02bb..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshKernel.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -/** - * 刷新布局核心功能接口 - * 为功能复杂的 Header 或者 Footer 开放的接口 - * Created by scwang on 2017/5/26. - */ -public interface RefreshKernel extends com.scwang.smart.refresh.layout.api.RefreshKernel { - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshLayout.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshLayout.java deleted file mode 100644 index 1cdb1cc13..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/RefreshLayout.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener; -import com.scwang.smartrefresh.layout.listener.OnMultiPurposeListener; -import com.scwang.smartrefresh.layout.listener.OnRefreshListener; -import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener; - -/** - * 刷新布局 - * interface of the refresh layout - * Created by scwang on 2017/5/26. - */ -@SuppressWarnings("UnusedReturnValue") -public interface RefreshLayout extends com.scwang.smart.refresh.layout.api.RefreshLayout { - - /** - * Set the footer of RefreshLayout. - * 设置指定的 Footer - * @param footer RefreshFooter 刷新尾巴 - * @return RefreshLayout - */ - RefreshLayout setRefreshFooter(@NonNull RefreshFooter footer); - - /** - * Set the footer of RefreshLayout. - * 设置指定的 Footer - * @param footer RefreshFooter 刷新尾巴 - * @param width the width in px, can use MATCH_PARENT and WRAP_CONTENT. - * 宽度 可以使用 MATCH_PARENT, WRAP_CONTENT - * @param height the height in px, can use MATCH_PARENT and WRAP_CONTENT. - * 高度 可以使用 MATCH_PARENT, WRAP_CONTENT - * @return RefreshLayout - */ - RefreshLayout setRefreshFooter(@NonNull RefreshFooter footer, int width, int height); - - /** - * Set the header of RefreshLayout. - * 设置指定的 Header - * @param header RefreshHeader 刷新头 - * @return RefreshLayout - */ - RefreshLayout setRefreshHeader(@NonNull RefreshHeader header); - - /** - * Set the header of RefreshLayout. - * 设置指定的 Header - * @param header RefreshHeader 刷新头 - * @param width the width in px, can use MATCH_PARENT and WRAP_CONTENT. - * 宽度 可以使用 MATCH_PARENT, WRAP_CONTENT - * @param height the height in px, can use MATCH_PARENT and WRAP_CONTENT. - * 高度 可以使用 MATCH_PARENT, WRAP_CONTENT - * @return RefreshLayout - */ - RefreshLayout setRefreshHeader(@NonNull RefreshHeader header, int width, int height); - - /** - * Set refresh listener separately. - * 单独设置刷新监听器 - * @param listener OnRefreshListener 刷新监听器 - * @return RefreshLayout - */ - RefreshLayout setOnRefreshListener(OnRefreshListener listener); - - /** - * Set load more listener separately. - * 单独设置加载监听器 - * @param listener OnLoadMoreListener 加载监听器 - * @return RefreshLayout - */ - RefreshLayout setOnLoadMoreListener(OnLoadMoreListener listener); - - /** - * Set refresh and load listeners at the same time. - * 同时设置刷新和加载监听器 - * @param listener OnRefreshLoadMoreListener 刷新加载监听器 - * @return RefreshLayout - */ - RefreshLayout setOnRefreshLoadMoreListener(OnRefreshLoadMoreListener listener); - - /** - * Set up a multi-function listener. - * Recommended {@link com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener} - * 设置多功能监听器 - * 建议使用 {@link com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener} - * @param listener OnMultiPurposeListener 多功能监听器 - * @return RefreshLayout - */ - RefreshLayout setOnMultiPurposeListener(OnMultiPurposeListener listener); - - /** - * Set the scroll boundary Decider, Can customize when you can refresh. - * Recommended {@link com.scwang.smartrefresh.layout.impl.ScrollBoundaryDeciderAdapter} - * 设置滚动边界判断器 - * 建议使用 {@link com.scwang.smartrefresh.layout.impl.ScrollBoundaryDeciderAdapter} - * @param boundary ScrollBoundaryDecider 判断器 - * @return RefreshLayout - */ - RefreshLayout setScrollBoundaryDecider(ScrollBoundaryDecider boundary); - - /** - * Get header of RefreshLayout - * 获取当前 Header - * @return RefreshLayout - */ - @Nullable - RefreshHeader getRefreshHeader(); - - /** - * Get footer of RefreshLayout - * 获取当前 Footer - * @return RefreshLayout - */ - @Nullable - RefreshFooter getRefreshFooter(); - -// /** -// * Get the current state of RefreshLayout -// * 获取当前状态 -// * @return RefreshLayout -// */ -// @NonNull -// RefreshState getState(); - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/ScrollBoundaryDecider.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/ScrollBoundaryDecider.java deleted file mode 100644 index e5c5dc281..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/api/ScrollBoundaryDecider.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.scwang.smartrefresh.layout.api; - -/** - * 滚动边界 - * Created by scwang on 2017/7/8. - */ -public interface ScrollBoundaryDecider extends com.scwang.smart.refresh.layout.listener.ScrollBoundaryDecider { -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/constant/RefreshState.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/constant/RefreshState.java deleted file mode 100644 index 840538aa3..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/constant/RefreshState.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.scwang.smartrefresh.layout.constant; - -/** - * 刷新状态 - */ -@SuppressWarnings("unused") -public enum RefreshState { - None(0,false,false,false,false,false), - PullDownToRefresh(1,true,false,false,false,false), PullUpToLoad(2,true,false,false,false,false), - PullDownCanceled(1,false,false,false,false,false), PullUpCanceled(2,false,false,false,false,false), - ReleaseToRefresh(1,true,false,false,false,true), ReleaseToLoad(2,true,false,false,false,true), - ReleaseToTwoLevel(1,true,false,false,true,true), TwoLevelReleased(1,false,false,false,true,false), - RefreshReleased(1,false,false,false,false,false), LoadReleased(2,false,false,false,false,false), - Refreshing(1,false,true,false,false,false), Loading(2,false,true,false,false,false), TwoLevel(1, false, true,false,true,false), - RefreshFinish(1,false,false,true,false,false), LoadFinish(2,false,false,true,false,false), TwoLevelFinish(1,false,false,true,true,false); - - public final boolean isHeader; - public final boolean isFooter; - public final boolean isTwoLevel;// 二级刷新 ReleaseToTwoLevel TwoLevelReleased TwoLevel - public final boolean isDragging;// 正在拖动状态:PullDownToRefresh PullUpToLoad ReleaseToRefresh ReleaseToLoad ReleaseToTwoLevel - public final boolean isOpening;// 正在刷新状态:Refreshing Loading TwoLevel - public final boolean isFinishing;//正在完成状态:RefreshFinish LoadFinish TwoLevelFinish - public final boolean isReleaseToOpening;// 释放立马打开 ReleaseToRefresh ReleaseToLoad ReleaseToTwoLevel - - RefreshState(int role, boolean dragging, boolean opening, boolean finishing, boolean twoLevel, boolean releaseToOpening) { - this.isHeader = role == 1; - this.isFooter = role == 2; - this.isDragging = dragging; - this.isOpening = opening; - this.isFinishing = finishing; - this.isTwoLevel = twoLevel; - this.isReleaseToOpening = releaseToOpening; - } - - public static RefreshState from(com.scwang.smart.refresh.layout.constant.RefreshState newState) { - for (RefreshState state : values()) { - if (state.ordinal() == newState.ordinal()) { - return state; - } - } - return None; - } - - public RefreshState toFooter() { - if (isHeader && !isTwoLevel) { - return values()[ordinal() + 1]; - } - return this; - } - - public RefreshState toHeader() { - if (isFooter && !isTwoLevel) { - return values()[ordinal()-1]; - } - return this; - } -} \ No newline at end of file diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/constant/SpinnerStyle.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/constant/SpinnerStyle.java deleted file mode 100644 index de41e328e..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/constant/SpinnerStyle.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.scwang.smartrefresh.layout.constant; - -/** - * 顶部和底部的组件在拖动时候的变换方式 - * Created by scwang on 2017/5/26. - */ -public class SpinnerStyle extends com.scwang.smart.refresh.layout.constant.SpinnerStyle { - - private SpinnerStyle() { - super(-1, false, false); - } - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/footer/BallPulseFooter.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/footer/BallPulseFooter.java deleted file mode 100644 index effb60696..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/footer/BallPulseFooter.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.scwang.smartrefresh.layout.footer; - -import android.content.Context; -import android.support.annotation.Nullable; -import android.util.AttributeSet; - -import com.scwang.smart.refresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.api.RefreshFooter; - - -/** - * 球脉冲底部加载组件 - * Created by scwang on 2017/5/30. - */ -@SuppressWarnings({"unused", "UnusedReturnValue"}) -public class BallPulseFooter extends com.scwang.smart.refresh.footer.BallPulseFooter implements RefreshFooter { - - // - public BallPulseFooter(Context context) { - this(context, null); - } - - public BallPulseFooter(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - } - // - - - @Override - public BallPulseFooter setSpinnerStyle(SpinnerStyle mSpinnerStyle) { - super.setSpinnerStyle(mSpinnerStyle); - return this; - } - - @Override - public BallPulseFooter setNormalColor(int color) { - super.setNormalColor(color); - return this; - } - - @Override - public BallPulseFooter setAnimatingColor(int color) { - super.setAnimatingColor(color); - return this; - } -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/footer/ClassicsFooter.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/footer/ClassicsFooter.java deleted file mode 100644 index 4f68fad95..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/footer/ClassicsFooter.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.scwang.smartrefresh.layout.footer; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smart.refresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.api.RefreshFooter; - -/** - * 经典上拉底部-兼容【1.x】版本-包名位置 - * Created by scwang on 2017/5/28. - */ -@SuppressWarnings({"unused", "UnusedReturnValue"}) -public class ClassicsFooter extends com.scwang.smart.refresh.footer.ClassicsFooter implements RefreshFooter { - - public ClassicsFooter(Context context) { - super(context); - } - - public ClassicsFooter(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - public ClassicsFooter setSpinnerStyle(SpinnerStyle style) { - super.setSpinnerStyle(style); - return this; - } - - @Override - public ClassicsFooter setPrimaryColor(int primaryColor) { - super.setPrimaryColor(primaryColor); - return this; - } - - @Override - public ClassicsFooter setAccentColor(int accentColor) { - super.setAccentColor(accentColor); - return this; - } - - @Override - public ClassicsFooter setPrimaryColorId(int colorId) { - super.setPrimaryColorId(colorId); - return this; - } - - @Override - public ClassicsFooter setAccentColorId(int colorId) { - super.setAccentColorId(colorId); - return this; - } - - @Override - public ClassicsFooter setFinishDuration(int delay) { - super.setFinishDuration(delay); - return this; - } - - @Override - public ClassicsFooter setTextSizeTitle(float size) { - super.setTextSizeTitle(size); - return this; - } - - @Override - public ClassicsFooter setTextSizeTitle(int unit, float size) { - super.setTextSizeTitle(unit, size); - return this; - } - - @Override - public ClassicsFooter setDrawableMarginRight(float dp) { - super.setDrawableMarginRight(dp); - return this; - } - - @Override - public ClassicsFooter setDrawableMarginRightPx(int px) { - super.setDrawableMarginRightPx(px); - return this; - } - - @Override - public ClassicsFooter setDrawableSize(float dp) { - super.setDrawableSize(dp); - return this; - } - - @Override - public ClassicsFooter setDrawableSizePx(int px) { - super.setDrawableSizePx(px); - return this; - } - - @Override - public ClassicsFooter setDrawableArrowSize(float dp) { - super.setDrawableArrowSize(dp); - return this; - } - - @Override - public ClassicsFooter setDrawableArrowSizePx(int px) { - super.setDrawableArrowSizePx(px); - return this; - } - - @Override - public ClassicsFooter setDrawableProgressSize(float dp) { - super.setDrawableProgressSize(dp); - return this; - } - - @Override - public ClassicsFooter setDrawableProgressSizePx(int px) { - super.setDrawableProgressSizePx(px); - return this; - } -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/footer/FalsifyFooter.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/footer/FalsifyFooter.java deleted file mode 100644 index 1ce4377c5..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/footer/FalsifyFooter.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.scwang.smartrefresh.layout.footer; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshFooter; - -/** - * 虚假的 Footer - * 用于 正真的 Footer 在 RefreshLayout 外部时, - * Created by scwang on 2017/6/14. - */ -@SuppressWarnings("unused") -public class FalsifyFooter extends com.scwang.smart.refresh.header.FalsifyFooter implements RefreshFooter { - - // - public FalsifyFooter(Context context) { - this(context, null); - } - - public FalsifyFooter(Context context, AttributeSet attrs) { - super(context, attrs); - } - // - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/BezierRadarHeader.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/BezierRadarHeader.java deleted file mode 100644 index 299c50b13..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/BezierRadarHeader.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.scwang.smartrefresh.layout.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * 贝塞尔曲线类雷达风格刷新组件 - * Created by scwang on 2017/5/28. - */ -@SuppressWarnings({"UnusedReturnValue", "unused"}) -public class BezierRadarHeader extends com.scwang.smart.refresh.header.BezierRadarHeader implements RefreshHeader { - - // - public BezierRadarHeader(Context context) { - this(context,null); - } - - public BezierRadarHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // - - @Override - public BezierRadarHeader setPrimaryColor(int color) { - super.setPrimaryColor(color); - return this; - } - - @Override - public BezierRadarHeader setAccentColor(int color) { - super.setAccentColor(color); - return this; - } - - @Override - public BezierRadarHeader setPrimaryColorId(int colorId) { - super.setPrimaryColorId(colorId); - return this; - } - - @Override - public BezierRadarHeader setAccentColorId(int colorId) { - super.setAccentColorId(colorId); - return this; - } - - @Override - public BezierRadarHeader setEnableHorizontalDrag(boolean enable) { - super.setEnableHorizontalDrag(enable); - return this; - } -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/ClassicsHeader.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/ClassicsHeader.java deleted file mode 100644 index 36aae02f0..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/ClassicsHeader.java +++ /dev/null @@ -1,220 +0,0 @@ -package com.scwang.smartrefresh.layout.header; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; - -import com.scwang.smart.refresh.layout.api.RefreshLayout; -import com.scwang.smart.refresh.layout.constant.SpinnerStyle; -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -import java.text.DateFormat; -import java.util.Date; - -/** - * 经典下拉头部-兼容【1.x】版本-包名位置 - * Created by scwang on 2017/5/28. - */ -@SuppressWarnings({"unused", "UnusedReturnValue"}) -public class ClassicsHeader extends com.scwang.smart.refresh.header.ClassicsHeader implements RefreshHeader { - - public ClassicsHeader(Context context) { - super(context); - } - - public ClassicsHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - public ClassicsHeader setLastUpdateTime(Date time) { - super.setLastUpdateTime(time); - return this; - } - - @Override - public ClassicsHeader setTimeFormat(DateFormat format) { - super.setTimeFormat(format); - return this; - } - - @Override - public ClassicsHeader setLastUpdateText(CharSequence text) { - super.setLastUpdateText(text); - return this; - } - - @Override - public ClassicsHeader setAccentColor(int accentColor) { - super.setAccentColor(accentColor); - return this; - } - - @Override - public ClassicsHeader setEnableLastTime(boolean enable) { - super.setEnableLastTime(enable); - return this; - } - - @Override - public ClassicsHeader setTextSizeTime(float size) { - super.setTextSizeTime(size); - return this; - } - - @Override - public ClassicsHeader setTextSizeTime(int unit, float size) { - super.setTextSizeTime(unit, size); - return this; - } - - @Override - public ClassicsHeader setTextTimeMarginTop(float dp) { - super.setTextTimeMarginTop(dp); - return this; - } - - @Override - public ClassicsHeader setTextTimeMarginTopPx(int px) { - super.setTextTimeMarginTopPx(px); - return this; - } - - /** - * @param colors 对应Xml中配置的 srlPrimaryColor srlAccentColor - * @deprecated 只由框架调用 - * 使用者使用 {@link RefreshLayout#setPrimaryColorsId(int...)} - */ - @Override - @Deprecated - public void setPrimaryColors(int... colors) { - super.setPrimaryColors(colors); - } - - @Override - public ClassicsHeader setProgressBitmap(Bitmap bitmap) { - super.setProgressBitmap(bitmap); - return this; - } - - @Override - public ClassicsHeader setProgressDrawable(Drawable drawable) { - super.setProgressDrawable(drawable); - return this; - } - - @Override - public ClassicsHeader setProgressResource(int resId) { - super.setProgressResource(resId); - return this; - } - - @Override - public ClassicsHeader setArrowBitmap(Bitmap bitmap) { - super.setArrowBitmap(bitmap); - return this; - } - - @Override - public ClassicsHeader setArrowDrawable(Drawable drawable) { - super.setArrowDrawable(drawable); - return this; - } - - @Override - public ClassicsHeader setArrowResource(int resId) { - super.setArrowResource(resId); - return this; - } - - @Override - public ClassicsHeader setSpinnerStyle(SpinnerStyle style) { - super.setSpinnerStyle(style); - return this; - } - - @Override - public ClassicsHeader setPrimaryColor(int primaryColor) { - super.setPrimaryColor(primaryColor); - return this; - } - - @Override - public ClassicsHeader setPrimaryColorId(int colorId) { - super.setPrimaryColorId(colorId); - return this; - } - - @Override - public ClassicsHeader setAccentColorId(int colorId) { - super.setAccentColorId(colorId); - return this; - } - - @Override - public ClassicsHeader setFinishDuration(int delay) { - super.setFinishDuration(delay); - return this; - } - - @Override - public ClassicsHeader setTextSizeTitle(float size) { - super.setTextSizeTitle(size); - return this; - } - - @Override - public ClassicsHeader setTextSizeTitle(int unit, float size) { - super.setTextSizeTitle(unit, size); - return this; - } - - @Override - public ClassicsHeader setDrawableMarginRight(float dp) { - super.setDrawableMarginRight(dp); - return this; - } - - @Override - public ClassicsHeader setDrawableMarginRightPx(int px) { - super.setDrawableMarginRightPx(px); - return this; - } - - @Override - public ClassicsHeader setDrawableSize(float dp) { - super.setDrawableSize(dp); - return this; - } - - @Override - public ClassicsHeader setDrawableSizePx(int px) { - super.setDrawableSizePx(px); - return this; - } - - @Override - public ClassicsHeader setDrawableArrowSize(float dp) { - super.setDrawableArrowSize(dp); - return this; - } - - @Override - public ClassicsHeader setDrawableArrowSizePx(int px) { - super.setDrawableArrowSizePx(px); - return this; - } - - @Override - public ClassicsHeader setDrawableProgressSize(float dp) { - super.setDrawableProgressSize(dp); - return this; - } - - @Override - public ClassicsHeader setDrawableProgressSizePx(int px) { - super.setDrawableProgressSizePx(px); - return this; - } -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/FalsifyHeader.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/FalsifyHeader.java deleted file mode 100644 index d105ce537..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/FalsifyHeader.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.scwang.smartrefresh.layout.header; - -import android.content.Context; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * 虚假的 Header - * 用于 正真的 Header 在 RefreshLayout 外部时, - * 使用本虚假的 FalsifyHeader 填充在 RefreshLayout 内部 - * 具体使用方法 参考 纸飞机(FlyRefreshHeader) - * Created by scwang on 2017/6/14. - */ -public class FalsifyHeader extends com.scwang.smart.refresh.header.FalsifyHeader implements RefreshHeader { - - // - public FalsifyHeader(Context context) { - this(context, null); - } - - public FalsifyHeader(Context context, AttributeSet attrs) { - super(context, attrs); - } - // -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/TwoLevelHeader.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/TwoLevelHeader.java deleted file mode 100644 index 3905ea599..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/header/TwoLevelHeader.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.scwang.smartrefresh.layout.header; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.util.AttributeSet; - -import com.scwang.smartrefresh.layout.api.OnTwoLevelListener; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; - -/** - * 二级刷新 - * Created by scwang on 2017/5/26. - */ -@SuppressWarnings("UnusedReturnValue") -public class TwoLevelHeader extends com.scwang.smart.refresh.header.TwoLevelHeader implements RefreshHeader { - - - // - public TwoLevelHeader(Context context) { - this(context, null); - } - - public TwoLevelHeader(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - } - // - - public TwoLevelHeader setOnTwoLevelListener(final OnTwoLevelListener listener) { - super.setOnTwoLevelListener(new com.scwang.smart.refresh.header.listener.OnTwoLevelListener() { - @Override - public boolean onTwoLevel(@NonNull com.scwang.smart.refresh.layout.api.RefreshLayout refreshLayout) { - return listener.onTwoLevel((RefreshLayout) refreshLayout); - } - }); - return this; - } - - @Override - public TwoLevelHeader setRefreshHeader(com.scwang.smart.refresh.layout.api.RefreshHeader header) { - super.setRefreshHeader(header); - return this; - } - - @Override - public TwoLevelHeader setRefreshHeader(com.scwang.smart.refresh.layout.api.RefreshHeader header, int width, int height) { - super.setRefreshHeader(header, width, height); - return this; - } - - @Override - public TwoLevelHeader setMaxRate(float rate) { - super.setMaxRate(rate); - return this; - } - - @Override - public TwoLevelHeader setEnablePullToCloseTwoLevel(boolean enabled) { - super.setEnablePullToCloseTwoLevel(enabled); - return this; - } - - @Override - public TwoLevelHeader setFloorRate(float rate) { - super.setFloorRate(rate); - return this; - } - - @Override - public TwoLevelHeader setRefreshRate(float rate) { - super.setRefreshRate(rate); - return this; - } - - @Override - public TwoLevelHeader setEnableTwoLevel(boolean enabled) { - super.setEnableTwoLevel(enabled); - return this; - } - - @Override - public TwoLevelHeader setFloorDuration(int duration) { - super.setFloorDuration(duration); - return this; - } -} \ No newline at end of file diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/RefreshFooterWrapper.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/RefreshFooterWrapper.java deleted file mode 100644 index 6bf8f5051..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/RefreshFooterWrapper.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.scwang.smartrefresh.layout.impl; - -import android.annotation.SuppressLint; -import android.view.View; - -import com.scwang.smartrefresh.layout.api.RefreshFooter; -import com.scwang.smartrefresh.layout.internal.InternalAbstract; - -/** - * 刷新底部包装 - * Created by scwang on 2017/5/26. - */ -@SuppressLint("ViewConstructor") -public class RefreshFooterWrapper extends InternalAbstract implements RefreshFooter { - - public RefreshFooterWrapper(View wrapper) { - super(wrapper); - } - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/RefreshHeaderWrapper.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/RefreshHeaderWrapper.java deleted file mode 100644 index 3f1c18931..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/RefreshHeaderWrapper.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.scwang.smartrefresh.layout.impl; - -import android.annotation.SuppressLint; -import android.view.View; - -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.internal.InternalAbstract; - -/** - * 刷新头部包装 - * Created by scwang on 2017/5/26. - */ -@SuppressLint("ViewConstructor") -public class RefreshHeaderWrapper extends InternalAbstract implements RefreshHeader { - - public RefreshHeaderWrapper(View wrapper) { - super(wrapper); - } - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/ScrollBoundaryDeciderAdapter.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/ScrollBoundaryDeciderAdapter.java deleted file mode 100644 index fabaecc56..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/impl/ScrollBoundaryDeciderAdapter.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.scwang.smartrefresh.layout.impl; - -import com.scwang.smart.refresh.layout.simple.SimpleBoundaryDecider; -import com.scwang.smartrefresh.layout.api.ScrollBoundaryDecider; - -/** - * 滚动边界 - * Created by scwang on 2017/7/8. - */ -public class ScrollBoundaryDeciderAdapter extends SimpleBoundaryDecider implements ScrollBoundaryDecider { - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/ArrowDrawable.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/ArrowDrawable.java deleted file mode 100644 index 4d8ba11ec..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/ArrowDrawable.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.scwang.smartrefresh.layout.internal; - -/** - * 箭头图像 - * Created by scwang on 2018/2/5. - */ -@SuppressWarnings("unused") -public class ArrowDrawable extends com.scwang.smart.refresh.classics.ArrowDrawable { - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/InternalAbstract.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/InternalAbstract.java deleted file mode 100644 index 35df9d41e..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/InternalAbstract.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.scwang.smartrefresh.layout.internal; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.util.AttributeSet; -import android.view.View; - -import com.scwang.smart.refresh.layout.simple.SimpleComponent; -import com.scwang.smartrefresh.layout.api.RefreshInternal; - -/** - * Internal 初步实现 - * 实现 Header 和 Footer 时,继承 InternalAbstract 的话可以少写很多接口方法 - * Created by scwang on 2018/2/6. - */ -public abstract class InternalAbstract extends SimpleComponent { - - - protected InternalAbstract(@NonNull View wrapped) { - super(wrapped); - } - - protected InternalAbstract(@NonNull View wrappedView, @Nullable RefreshInternal wrappedInternal) { - super(wrappedView, wrappedInternal); - } - - protected InternalAbstract(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/PaintDrawable.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/PaintDrawable.java deleted file mode 100644 index 53ad8bd3d..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/PaintDrawable.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.scwang.smartrefresh.layout.internal; - -/** - * 画笔 Drawable - * Created by scwang on 2017/6/16. - */ -public abstract class PaintDrawable extends com.scwang.smart.drawable.PaintDrawable { - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/ProgressDrawable.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/ProgressDrawable.java deleted file mode 100644 index 43c7e49b9..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/internal/ProgressDrawable.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.scwang.smartrefresh.layout.internal; - -/** - * 旋转动画 - * Created by scwang on 2017/6/16. - */ -public class ProgressDrawable extends com.scwang.smart.drawable.ProgressDrawable { - -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnLoadMoreListener.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnLoadMoreListener.java deleted file mode 100644 index 85b96bcc4..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnLoadMoreListener.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.scwang.smartrefresh.layout.listener; - -import android.support.annotation.NonNull; - -import com.scwang.smartrefresh.layout.api.RefreshLayout; - -/** - * 加载更多监听器 - * Created by scwang on 2017/5/26. - */ -public interface OnLoadMoreListener { - void onLoadMore(@NonNull RefreshLayout refreshLayout); -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnMultiPurposeListener.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnMultiPurposeListener.java deleted file mode 100644 index 6f16d289a..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnMultiPurposeListener.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.scwang.smartrefresh.layout.listener; - -import com.scwang.smartrefresh.layout.api.RefreshFooter; -import com.scwang.smartrefresh.layout.api.RefreshHeader; - -/** - * 多功能监听器 - * Created by scwang on 2017/5/26. - */ -public interface OnMultiPurposeListener extends OnRefreshLoadMoreListener, OnStateChangedListener { - /** - * 手指拖动下拉(会连续多次调用,添加isDragging并取代之前的onPulling、onReleasing) - * @param header 头部 - * @param isDragging true 手指正在拖动 false 回弹动画 - * @param percent 下拉的百分比 值 = offset/footerHeight (0 - percent - (footerHeight+maxDragHeight) / footerHeight ) - * @param offset 下拉的像素偏移量 0 - offset - (footerHeight+maxDragHeight) - * @param headerHeight 高度 HeaderHeight or FooterHeight - * @param maxDragHeight 最大拖动高度 - */ - void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight); - - void onHeaderReleased(RefreshHeader header, int headerHeight, int maxDragHeight); - void onHeaderStartAnimator(RefreshHeader header, int headerHeight, int maxDragHeight); - void onHeaderFinish(RefreshHeader header, boolean success); - - /** - * 手指拖动上拉(会连续多次调用,添加isDragging并取代之前的onPulling、onReleasing) - * @param footer 尾部 - * @param isDragging true 手指正在拖动 false 回弹动画 - * @param percent 下拉的百分比 值 = offset/footerHeight (0 - percent - (footerHeight+maxDragHeight) / footerHeight ) - * @param offset 下拉的像素偏移量 0 - offset - (footerHeight+maxDragHeight) - * @param footerHeight 高度 HeaderHeight or FooterHeight - * @param maxDragHeight 最大拖动高度 - */ - void onFooterMoving(RefreshFooter footer, boolean isDragging, float percent, int offset, int footerHeight, int maxDragHeight); - - void onFooterReleased(RefreshFooter footer, int footerHeight, int maxDragHeight); - void onFooterStartAnimator(RefreshFooter footer, int footerHeight, int maxDragHeight); - void onFooterFinish(RefreshFooter footer, boolean success); -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnRefreshListener.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnRefreshListener.java deleted file mode 100644 index 149d74abb..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnRefreshListener.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.scwang.smartrefresh.layout.listener; - -import android.support.annotation.NonNull; - -import com.scwang.smartrefresh.layout.api.RefreshLayout; - -/** - * 刷新监听器 - * Created by scwang on 2017/5/26. - */ -public interface OnRefreshListener { - void onRefresh(@NonNull RefreshLayout refreshLayout); -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnRefreshLoadMoreListener.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnRefreshLoadMoreListener.java deleted file mode 100644 index 60394b77e..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnRefreshLoadMoreListener.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.scwang.smartrefresh.layout.listener; - -/** - * 刷新加载组合监听器 - * Created by scwang on 2017/5/26. - */ -public interface OnRefreshLoadMoreListener extends OnRefreshListener, OnLoadMoreListener { -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnStateChangedListener.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnStateChangedListener.java deleted file mode 100644 index 4ba6ad678..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/OnStateChangedListener.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.scwang.smartrefresh.layout.listener; - - -import android.support.annotation.NonNull; -import android.support.annotation.RestrictTo; - -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.RefreshState; - -import static android.support.annotation.RestrictTo.Scope.LIBRARY; -import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP; -import static android.support.annotation.RestrictTo.Scope.SUBCLASSES; - -/** - * 刷新状态改变监听器 - * Created by scwang on 2017/5/26. - */ -public interface OnStateChangedListener { - /** - * 【仅限框架内调用】状态改变事件 {@link RefreshState} - * @param refreshLayout RefreshLayout - * @param oldState 改变之前的状态 - * @param newState 改变之后的状态 - */ - @RestrictTo({LIBRARY,LIBRARY_GROUP,SUBCLASSES}) - void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState); -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/SimpleMultiPurposeListener.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/SimpleMultiPurposeListener.java deleted file mode 100644 index 97a430655..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/listener/SimpleMultiPurposeListener.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.scwang.smartrefresh.layout.listener; - -import android.support.annotation.NonNull; - -import com.scwang.smart.refresh.layout.listener.OnMultiListener; -import com.scwang.smartrefresh.layout.api.RefreshFooter; -import com.scwang.smartrefresh.layout.api.RefreshHeader; -import com.scwang.smartrefresh.layout.api.RefreshLayout; -import com.scwang.smartrefresh.layout.constant.RefreshState; - -/** - * 多功能监听器 - * Created by scwang on 2017/5/26. - */ -public class SimpleMultiPurposeListener implements OnMultiPurposeListener, OnMultiListener { - - private RefreshLayout refreshLayout; - private OnMultiPurposeListener listener; - - public SimpleMultiPurposeListener() { - - } - - public SimpleMultiPurposeListener(OnMultiPurposeListener listener, RefreshLayout refreshLayout) { - this.listener = listener; - this.refreshLayout = refreshLayout; - } - - @Override - public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) { - if (listener != null) { - listener.onHeaderMoving(header, isDragging, percent, offset, headerHeight, maxDragHeight); - } - } - - @Override - public void onHeaderReleased(RefreshHeader header, int headerHeight, int maxDragHeight) { - if (listener != null) { - listener.onHeaderReleased(header, headerHeight, maxDragHeight); - } - } - - @Override - public void onHeaderStartAnimator(RefreshHeader header, int footerHeight, int maxDragHeight) { - if (listener != null) { - listener.onHeaderStartAnimator(header, footerHeight, maxDragHeight); - } - } - - @Override - public void onHeaderFinish(RefreshHeader header, boolean success) { - if (listener != null) { - listener.onHeaderFinish(header, success); - } - } - - @Override - public void onFooterMoving(RefreshFooter footer, boolean isDragging, float percent, int offset, int footerHeight, int maxDragHeight) { - if (listener != null) { - listener.onFooterMoving(footer, isDragging, percent, offset, footerHeight, maxDragHeight); - } - } - - @Override - public void onFooterReleased(RefreshFooter footer, int footerHeight, int maxDragHeight) { - if (listener != null) { - listener.onFooterReleased(footer, footerHeight, maxDragHeight); - } - } - - @Override - public void onFooterStartAnimator(RefreshFooter footer, int headerHeight, int maxDragHeight) { - if (listener != null) { - listener.onFooterStartAnimator(footer, headerHeight, maxDragHeight); - } - } - - @Override - public void onFooterFinish(RefreshFooter footer, boolean success) { - if (listener != null) { - listener.onFooterFinish(footer, success); - } - } - - @Override - public void onRefresh(@NonNull RefreshLayout refreshLayout) { - if (listener != null) { - listener.onRefresh(refreshLayout); - } - } - - @Override - public void onLoadMore(@NonNull RefreshLayout refreshLayout) { - if (listener != null) { - listener.onLoadMore(refreshLayout); - } - } - - @Override - public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) { - if (listener != null) { - listener.onStateChanged(refreshLayout, oldState, newState); - } - } - - @Override - public void onHeaderMoving(com.scwang.smart.refresh.layout.api.RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) { - if (refreshLayout != null) { - onHeaderMoving(refreshLayout.getRefreshHeader(), isDragging, percent, offset, headerHeight, maxDragHeight); - } - } - - @Override - public void onHeaderReleased(com.scwang.smart.refresh.layout.api.RefreshHeader header, int headerHeight, int maxDragHeight) { - if (refreshLayout != null) { - onHeaderReleased(refreshLayout.getRefreshHeader(), headerHeight, maxDragHeight); - } - } - - @Override - public void onHeaderStartAnimator(com.scwang.smart.refresh.layout.api.RefreshHeader header, int headerHeight, int maxDragHeight) { - if (refreshLayout != null) { - onHeaderStartAnimator(refreshLayout.getRefreshHeader(), headerHeight, maxDragHeight); - } - } - - @Override - public void onHeaderFinish(com.scwang.smart.refresh.layout.api.RefreshHeader header, boolean success) { - if (refreshLayout != null) { - onHeaderFinish(refreshLayout.getRefreshHeader(), success); - } - } - - @Override - public void onFooterMoving(com.scwang.smart.refresh.layout.api.RefreshFooter footer, boolean isDragging, float percent, int offset, int footerHeight, int maxDragHeight) { - if (refreshLayout != null) { - onFooterMoving(refreshLayout.getRefreshFooter(), isDragging, percent, offset, footerHeight, maxDragHeight); - } - } - - @Override - public void onFooterReleased(com.scwang.smart.refresh.layout.api.RefreshFooter footer, int footerHeight, int maxDragHeight) { - if (refreshLayout != null) { - onFooterReleased(refreshLayout.getRefreshFooter(), footerHeight, maxDragHeight); - } - } - - @Override - public void onFooterStartAnimator(com.scwang.smart.refresh.layout.api.RefreshFooter footer, int footerHeight, int maxDragHeight) { - if (refreshLayout != null) { - onFooterStartAnimator(refreshLayout.getRefreshFooter(), footerHeight, maxDragHeight); - } - } - - @Override - public void onFooterFinish(com.scwang.smart.refresh.layout.api.RefreshFooter footer, boolean success) { - if (refreshLayout != null) { - onFooterFinish(refreshLayout.getRefreshFooter(), success); - } - } - - @Override - public void onLoadMore(@NonNull com.scwang.smart.refresh.layout.api.RefreshLayout refreshLayout) { - if (this.refreshLayout != null) { - onLoadMore(this.refreshLayout); - } - } - - @Override - public void onRefresh(@NonNull com.scwang.smart.refresh.layout.api.RefreshLayout refreshLayout) { - if (this.refreshLayout != null) { - onRefresh(this.refreshLayout); - } - } - - @Override - public void onStateChanged(@NonNull com.scwang.smart.refresh.layout.api.RefreshLayout refreshLayout, @NonNull com.scwang.smart.refresh.layout.constant.RefreshState oldState, @NonNull com.scwang.smart.refresh.layout.constant.RefreshState newState) { - if (this.refreshLayout != null) { - onStateChanged(this.refreshLayout, RefreshState.from(oldState), RefreshState.from(newState)); - } - } -} diff --git a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/util/SmartUtil.java b/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/util/SmartUtil.java deleted file mode 100644 index 571ef74ee..000000000 --- a/refresh-layout/src/main/java/com/scwang/smartrefresh/layout/util/SmartUtil.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.scwang.smartrefresh.layout.util; - -/** - * SmartUtil - * Created by scwang on 2018/3/5. - */ -public class SmartUtil extends com.scwang.smart.refresh.layout.util.SmartUtil { - - private SmartUtil(int type) { - super(type); - } - -} diff --git a/refresh-layout/src/test/java/com/scwang/smartrefresh/layout/ExampleUnitTest.java b/refresh-layout/src/test/java/com/scwang/smart/refresh/layout/ExampleUnitTest.java similarity index 68% rename from refresh-layout/src/test/java/com/scwang/smartrefresh/layout/ExampleUnitTest.java rename to refresh-layout/src/test/java/com/scwang/smart/refresh/layout/ExampleUnitTest.java index 1bc7ef8ad..2b5ddfecd 100644 --- a/refresh-layout/src/test/java/com/scwang/smartrefresh/layout/ExampleUnitTest.java +++ b/refresh-layout/src/test/java/com/scwang/smart/refresh/layout/ExampleUnitTest.java @@ -1,8 +1,8 @@ -package com.scwang.smartrefresh.layout; +package com.scwang.smart.refresh.layout; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). @@ -11,7 +11,7 @@ */ public class ExampleUnitTest { @Test - public void addition_isCorrect() throws Exception { + public void addition_isCorrect() { assertEquals(4, 2 + 2); } } \ No newline at end of file