Repository: Marksss/AndroidAutoSwitcher
Branch: master
Commit: b62fab6207e0
Files: 61
Total size: 96.6 KB
Directory structure:
gitextract_hm9ildwt/
├── .gitignore
├── LICENSE
├── README.md
├── README_cn.md
├── app/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidTest/
│ │ └── java/
│ │ └── com/
│ │ └── example/
│ │ └── app/
│ │ └── ExampleInstrumentedTest.java
│ ├── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── example/
│ │ │ └── app/
│ │ │ ├── MainActivity.java
│ │ │ ├── MyApplication.java
│ │ │ ├── StartActivity.java
│ │ │ └── adapter/
│ │ │ ├── BannerAdapter.java
│ │ │ ├── BannerAdapter2.java
│ │ │ ├── HornAdapter.java
│ │ │ ├── MyAdapterInList.java
│ │ │ ├── PortraitAdapter.java
│ │ │ └── SingleTextAdapter.java
│ │ └── res/
│ │ ├── anim/
│ │ │ ├── anim_in.xml
│ │ │ └── anim_out.xml
│ │ ├── animator/
│ │ │ ├── anim_in.xml
│ │ │ └── anim_out.xml
│ │ ├── layout/
│ │ │ ├── activity_list.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── activity_start.xml
│ │ │ ├── item_in_list.xml
│ │ │ ├── item_list.xml
│ │ │ ├── item_portrait.xml
│ │ │ ├── item_single_text.xml
│ │ │ ├── start_banner.xml
│ │ │ ├── start_banner_2.xml
│ │ │ └── vertical_banner.xml
│ │ └── values/
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test/
│ └── java/
│ └── com/
│ └── example/
│ └── app/
│ └── ExampleUnitTest.java
├── auto-switcher/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── com/
│ │ └── switcher/
│ │ ├── AutoSwitchView.java
│ │ ├── SwitchStrategy.java
│ │ ├── base/
│ │ │ ├── BaseSwitchView.java
│ │ │ ├── ChainOperator.java
│ │ │ ├── SingleOperator.java
│ │ │ └── Utils.java
│ │ └── builder/
│ │ ├── AnimationStrategyBuilder.java
│ │ ├── AnimatorStrategyBuilder.java
│ │ ├── CarouselStrategyBuilder.java
│ │ ├── ContinuousStrategyBuilder.java
│ │ ├── DefaultStrategyBuilder.java
│ │ └── DirectionMode.java
│ └── res/
│ └── values/
│ ├── attrs.xml
│ └── strings.xml
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
*.apk
*.ap_
*.dex
*.class
*.log
.gradle
/bin
/gen
/local.properties
/.idea
/build
.DS_Store
/captures
/app/build
/bdwallet_pay_sdk/build
/common/build
/pingpp/build
/projectFilesBackup
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================
English | [中文文档](README_cn.md)
# AndroidAutoSwitcher
[](https://opensource.org/licenses/Apache-2.0)
[](http://developer.android.com/index.html)
[](https://android-arsenal.com/api?level=12)
[](https://jitpack.io/#Marksss/AndroidAutoSwitcher)
AutoSwitchView is a view that can automatically switch between two children (items). Compared to ViewFlipper, it has better stability for reusing its children when working on large data sets. Compared to AdapterViewFlipper, its expansibility is more excellent.

## Usage
### Add the JitPack repository to your build file
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
### Add the dependency
```implementation 'com.github.Marksss:AndroidAutoSwitcher:v1.2'```
### Code in XML
```
<com.switcher.AutoSwitchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:switcher_repeatCount="1"
app:switcher_autoStart="true"/>
```
If you want the switching animation to be infinite, you just need to set switcher_repeatCount -1.
### Code in Activity
```
AutoSwitchView as = (AutoSwitchView) findViewById(R.id.yourid);
as.setAdapter(new YourAdapter());
as.setSwitchStrategy(new YourStrategy()); // See Switching Strategy
as.startSwitcher(); // If you have set autoStart true, this is not needed.
```
### Switching Strategy
You can easily customize swtiching animations you like with SwitchStrategy. It supports both Animation and ObjectAnimator. Here are some builders of SwitchStrategy I have offered as follows.
- AnimationStrategyBuilder:
customize your own animation with Animation;
- AnimatorStrategyBuilder:
customize your own animation with ObjectAnimator;
- CarouselStrategyBuilder:
seamlessly switch between two items in different directions;
- ContinuousStrategyBuilder:
switch between items smoothly without any pauses;
An example:
```
as.setSwitchStrategy(
new AnimationStrategyBuilder(this, R.anim.anim_in, R.anim.anim_out).
build()
);
```
Another example:
```
as.setSwitchStrategy(
new CarouselStrategyBuilder().
setAnimDuration(900).
setInterpolator(new AccelerateDecelerateInterpolator()).
setMode(DirectionMode.right2Left).
build()
);
```
In most cases, strategies above are enough. If you want to customize animation that is not so complicated, you can use AnimationStrategyBuilde or AnimatorStrategyBuilder with your own Animation or ObjectAnimator.
### Additional
It usually is unnecessary. But if you want to customize more complicated animations, then you neeed to create your own SwitchStrategy through adding SingleOperator into BaseBuilder (init->next->withEnd) in turn to control all movements of the switcher.
```
new SwitchStrategy.BaseBuilder().
init(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
...//init your animation
}
}).next(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
...//run your own animation
}
}).withEnd(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
...//cancle or end your animation
}
}).build();
```
## License
AutoSwitchView is released under the [Apache License Version 2.0](LICENSE).
================================================
FILE: README_cn.md
================================================
[English](README.md) | 中文文档
# AndroidAutoSwitcher
[](https://opensource.org/licenses/Apache-2.0)
[](http://developer.android.com/index.html)
[](https://android-arsenal.com/api?level=12)
[](https://jitpack.io/#Marksss/AndroidAutoSwitcher)
AutoSwitchView是一个能自由切换两个子控件的控件容器,相比于ViewFlipper,它支持子控件的复用,数据量大的情况下能有更好的性能。同时,相比于AdapterViewFlipper,它有更好的扩展性,支持自定义各种切换动画。

## 用法
### 将JitPack添加到 `build.gradle` 文件中
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
### 添加依赖
```implementation 'com.github.Marksss:AndroidAutoSwitcher:v1.2'```
### XML中的代码
```
<com.switcher.AutoSwitchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:switcher_repeatCount="1"
app:switcher_autoStart="true"/>
```
如果想让切换动画无限循环,只需将switcher_repeatCount设置为-1.
### Activity中的代码
```
AutoSwitchView as = (AutoSwitchView) findViewById(R.id.yourid);
as.setAdapter(new YourAdapter());
as.setSwitchStrategy(new YourStrategy()); // See Switching Strategy
as.startSwitcher(); // If you have set autoStart true, this is not needed.
```
### Switching Strategy
你能利用SwitchStrategy轻松定制你喜欢的切换动画,它同时支持Animation和 ObjectAnimator。以下是一些已经提供的动画策略的建造者类:
- AnimationStrategyBuilde:
支持利用Animation定制自己的动画;
- AnimatorStrategyBuilder:
支持利用ObjectAnimator定制自己的动画;
- CarouselStrategyBuilder:
支持在不同方向上的两个item的无缝切换;
- ContinuousStrategyBuilder:
支持两个item之间的平滑无停顿的切换;
一个栗子:
```
as.setSwitchStrategy(
new AnimationStrategyBuilder(this, R.anim.anim_in, R.anim.anim_out).
build()
);
```
另一个栗子:
```
as.setSwitchStrategy(
new CarouselStrategyBuilder().
setAnimDuration(900).
setInterpolator(new AccelerateDecelerateInterpolator()).
setMode(DirectionMode.right2Left).
build()
);
```
在大多数情况下,以上的切换动画策略已经足够。如果想定制不那么复杂的动画, 也可以将自己的Animation或者ObjectAnimator添加到AnimationStrategyBuilde或者AnimatorStrategyBuilder中产生对应的切换策略。
### 复杂定制(非必需)
如果想定制更加复杂的切换动画, 你可以轮流添加SingleOperator到BaseBuilder中,创建你自己的SwitchStrategy,这样就可以完全控制切换流程了(如下所示)。
```
new SwitchStrategy.BaseBuilder().
init(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
...//init your animation
}
}).next(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
...//run your own animation
}
}).withEnd(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
...//cancle or end your animation
}
}).build();
```
## 许可证
AutoSwitchView基于 [Apache License Version 2.0](LICENSE) 发布。
================================================
FILE: app/.gitignore
================================================
/build
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.autoswitcher"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
compile 'com.github.markshawn:auto-switcher:1.2'
// compile project(':auto-switcher')
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: app/src/androidTest/java/com/example/app/ExampleInstrumentedTest.java
================================================
package com.example.app;
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.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
}
}
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name="com.example.app.StartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.example.app.MainActivity">
</activity>
</application>
</manifest>
================================================
FILE: app/src/main/java/com/example/app/MainActivity.java
================================================
package com.example.app;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.TextView;
import android.widget.Toast;
import com.example.app.adapter.BannerAdapter;
import com.example.app.adapter.HornAdapter;
import com.example.app.adapter.PortraitAdapter;
import com.example.app.adapter.SingleTextAdapter;
import com.switcher.AutoSwitchView;
import com.switcher.base.BaseSwitchView;
import com.switcher.builder.AnimationStrategyBuilder;
import com.switcher.builder.AnimatorStrategyBuilder;
import com.switcher.builder.CarouselStrategyBuilder;
import com.switcher.builder.ContinuousStrategyBuilder;
import com.switcher.builder.DirectionMode;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends Activity {
List<String> mEntityList = Arrays.asList(
"My Favourite Fruit is Apply",
"My Mother's Favourite Fruit is Blueberry",
"Anne's Favourite Fruit is Banana",
"Jake Hates Fruit");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AutoSwitchView aswBanner = (AutoSwitchView) findViewById(R.id.auto_roll_banner);
aswBanner.setAdapter(new BannerAdapter());
aswBanner.setSwitchStrategy(
new CarouselStrategyBuilder().
setAnimDuration(900).
setInterpolator(new AccelerateDecelerateInterpolator()).
setMode(DirectionMode.right2Left).
build()
);
aswBanner.setOnItemClickListener(new BaseSwitchView.OnItemClickListener() {
@Override
public void onItemClick(BaseSwitchView parent, View child, int position) {
Toast.makeText(MainActivity.this, "position=" + position, Toast.LENGTH_SHORT).show();
}
});
AutoSwitchView autoSwitchView = (AutoSwitchView) findViewById(R.id.auto_roll_0);
autoSwitchView.setAdapter(new HornAdapter(mEntityList));
AutoSwitchView autoSwitchView1 = (AutoSwitchView) findViewById(R.id.auto_roll_1);
autoSwitchView1.setAdapter(new HornAdapter(mEntityList));
autoSwitchView1.setSwitchStrategy(
new CarouselStrategyBuilder().
setAnimDuration(500).
setInterpolator(new DecelerateInterpolator()).
setMode(DirectionMode.bottom2Top).
build()
);
AutoSwitchView autoSwitchView2 = (AutoSwitchView) findViewById(R.id.auto_roll_2);
autoSwitchView2.setAdapter(new SingleTextAdapter("I am Animation"));
autoSwitchView2.setSwitchStrategy(
new AnimationStrategyBuilder(this, R.anim.anim_in, R.anim.anim_out).
build()
);
AutoSwitchView autoSwitchView3 = (AutoSwitchView) findViewById(R.id.auto_roll_3);
autoSwitchView3.setAdapter(new SingleTextAdapter("I am Animator"));
autoSwitchView3.setSwitchStrategy(
new AnimatorStrategyBuilder(this, R.animator.anim_in, R.animator.anim_out).
build()
);
AutoSwitchView autoSwitchView4 = (AutoSwitchView) findViewById(R.id.auto_roll_4);
autoSwitchView4.setAdapter(new PortraitAdapter());
autoSwitchView4.setSwitchStrategy(
new ContinuousStrategyBuilder().
setDuration(2000).
setMode(DirectionMode.left2Right).
build()
);
}
}
================================================
FILE: app/src/main/java/com/example/app/MyApplication.java
================================================
package com.example.app;
import android.app.Application;
import com.squareup.leakcanary.LeakCanary;
/**
* Created by shenxl on 2018/7/21.
*/
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
LeakCanary.install(this);
}
}
================================================
FILE: app/src/main/java/com/example/app/StartActivity.java
================================================
package com.example.app;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.EditText;
import com.example.app.adapter.BannerAdapter2;
import com.switcher.AutoSwitchView;
import com.switcher.builder.CarouselStrategyBuilder;
import com.switcher.builder.DirectionMode;
/**
* Created by shenxl on 2018/7/21.
*/
public class StartActivity extends Activity {
private AutoSwitchView mAswBanner;
private EditText mContentEdt, mCountEdt;
private BannerAdapter2 mBannerAdapter = new BannerAdapter2();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
mContentEdt = (EditText) findViewById(R.id.edt_content);
mCountEdt = (EditText) findViewById(R.id.edt_count);
mAswBanner = (AutoSwitchView) findViewById(R.id.start_banner);
mAswBanner.setAdapter(mBannerAdapter);
mAswBanner.setSwitchStrategy(
new CarouselStrategyBuilder().
setAnimDuration(900).
setInterpolator(new AccelerateDecelerateInterpolator()).
setMode(DirectionMode.right2Left).
build()
);
findViewById(R.id.btn_save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int count = 0;
try {
count = Integer.parseInt(mCountEdt.getText().toString());
} catch (Exception e) {
e.printStackTrace();
}
mBannerAdapter.setCount(count);
mBannerAdapter.setTitle(mContentEdt.getText().toString());
mAswBanner.startSwitcher();
}
});
mContentEdt.setText(mBannerAdapter.getTitle());
mCountEdt.setText(mBannerAdapter.getCount()+"");
findViewById(R.id.btn_example).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(StartActivity.this, MainActivity.class));
}
});
}
}
================================================
FILE: app/src/main/java/com/example/app/adapter/BannerAdapter.java
================================================
package com.example.app.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.example.app.R;
import com.switcher.base.BaseSwitchView;
/**
* Created by shenxl on 2018/7/21.
*/
public class BannerAdapter extends BaseSwitchView.AbsBaseAdapter {
@Override
public View makeView(Context context) {
return LayoutInflater.from(context).inflate(R.layout.start_banner, null, false);
}
@Override
public void updateItem(View view, int position) {
View container = view.findViewById(R.id.banner_container);
TextView title = (TextView) view.findViewById(R.id.banner_title);
switch (position) {
case 0:
container.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorPrimary));
title.setText("This is banner 0");
break;
case 1:
container.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorPrimaryDark));
title.setText("This is banner 1");
break;
default:
container.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorAccent));
title.setText("This is banner 2");
break;
}
}
@Override
public int getItemCount() {
return 3;
}
}
================================================
FILE: app/src/main/java/com/example/app/adapter/BannerAdapter2.java
================================================
package com.example.app.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.example.app.R;
import com.switcher.base.BaseSwitchView;
/**
* Created by shenxl on 2018/11/26.
*/
public class BannerAdapter2 extends BaseSwitchView.AbsBaseAdapter {
private int count = 3;
private String title = "This is banner";
@Override
public View makeView(Context context) {
return LayoutInflater.from(context).inflate(R.layout.start_banner_2, null, false);
}
@Override
public void updateItem(View view, int position) {
View container = view.findViewById(R.id.banner_container);
((TextView) view.findViewById(R.id.banner_title)).setText(title);
((TextView) view.findViewById(R.id.banner_pos)).setText("X"+position);
switch (position % 3) {
case 0:
container.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorPrimary));
break;
case 1:
container.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorPrimaryDark));
break;
default:
container.setBackgroundColor(view.getContext().getResources().getColor(R.color.colorAccent));
break;
}
}
public void setCount(int count) {
this.count = count;
}
public void setTitle(String title) {
this.title = title;
}
public int getCount() {
return count;
}
public String getTitle() {
return title;
}
@Override
public int getItemCount() {
return count;
}
}
================================================
FILE: app/src/main/java/com/example/app/adapter/HornAdapter.java
================================================
package com.example.app.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.example.app.R;
import com.switcher.AutoSwitchView;
import java.util.List;
/**
* Created by shenxl on 2018/7/21.
*/
public class HornAdapter extends AutoSwitchView.AbsBaseAdapter {
List<String> mEntityList;
public HornAdapter(List<String> entityList) {
mEntityList = entityList;
}
@Override
public View makeView(Context context) {
return LayoutInflater.from(context).inflate(R.layout.vertical_banner,null,false);
}
@Override
public void updateItem(View view, int position) {
String bean = mEntityList.get(position);
TextView title = (TextView) view.findViewById(R.id.item_banner_text);
TextView stones = (TextView) view.findViewById(R.id.item_banner_stones);
title.setText(bean);
stones.setText("X"+position);
}
@Override
public int getItemCount() {
return mEntityList == null ? 0 : mEntityList.size();
}
}
================================================
FILE: app/src/main/java/com/example/app/adapter/MyAdapterInList.java
================================================
package com.example.app.adapter;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import com.example.app.R;
import com.switcher.AutoSwitchView;
/**
* Created by shenxl on 2018/7/21.
*/
public class MyAdapterInList extends AutoSwitchView.AbsBaseAdapter{
private Activity mActivity;
private int count;
public MyAdapterInList(Activity activity, int count) {
mActivity = activity;
this.count = count;
}
@Override
public View makeView(Context context) {
return mActivity.getLayoutInflater().inflate(R.layout.item_in_list, null);
}
@Override
public void updateItem(View view, int position) {
TextView textView = (TextView) view.findViewById(R.id.text_item_in_list);
textView.setText("i am rolling in a listview : "+position);
}
@Override
public int getItemCount() {
return count;
}
}
================================================
FILE: app/src/main/java/com/example/app/adapter/PortraitAdapter.java
================================================
package com.example.app.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.example.app.R;
import com.switcher.base.BaseSwitchView;
/**
* Created by shenxl on 2018/7/21.
*/
public class PortraitAdapter extends BaseSwitchView.AbsBaseAdapter {
@Override
public View makeView(Context context) {
return LayoutInflater.from(context).inflate(R.layout.item_portrait, null, false);
}
@Override
public void updateItem(View view, int position) {
TextView name = (TextView) view.findViewById(R.id.item_name);
TextView desc = (TextView) view.findViewById(R.id.item_desc);
switch (position) {
case 0:
name.setText("Savannah");
desc.setText("Life means progress and progress means suffering");
break;
case 1:
name.setText("Alexandra");
desc.setText("Human life is like flowing water");
break;
default:
name.setText("Katherine");
desc.setText("1111112222244433");
break;
}
}
@Override
public int getItemCount() {
return 3;
}
}
================================================
FILE: app/src/main/java/com/example/app/adapter/SingleTextAdapter.java
================================================
package com.example.app.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.example.app.R;
import com.switcher.base.BaseSwitchView;
/**
* Created by shenxl on 2018/7/21.
*/
public class SingleTextAdapter extends BaseSwitchView.AbsBaseAdapter {
private String str;
public SingleTextAdapter(String str) {
this.str = str;
}
@Override
public View makeView(Context context) {
return LayoutInflater.from(context).inflate(R.layout.item_single_text, null, false);
}
@Override
public void updateItem(View view, int position) {
TextView te = (TextView) view.findViewById(R.id.single_text);
te.setText(str+" X"+position);
}
@Override
public int getItemCount() {
return 5;
}
}
================================================
FILE: app/src/main/res/anim/anim_in.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="100%p"
android:toXDelta="0"/>
</set>
================================================
FILE: app/src/main/res/anim/anim_out.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="0"
android:toXDelta="-100%p"/>
</set>
================================================
FILE: app/src/main/res/animator/anim_in.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="600"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="y"
android:valueFrom="-100"
android:valueTo="0"
android:valueType="floatType"/>
================================================
FILE: app/src/main/res/animator/anim_out.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="600"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="y"
android:valueFrom="0"
android:valueTo="100"
android:valueType="floatType"/>
================================================
FILE: app/src/main/res/layout/activity_list.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</FrameLayout>
================================================
FILE: app/src/main/res/layout/activity_main.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.switcher.AutoSwitchView
android:id="@+id/auto_roll_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:switcher_repeatCount="-1"
app:switcher_autoStart="true"/>
<com.switcher.AutoSwitchView
android:id="@+id/auto_roll_0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_gravity="center_horizontal"
app:switcher_repeatCount="-1"
app:switcher_autoStart="true"/>
<com.switcher.AutoSwitchView
android:id="@+id/auto_roll_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
app:switcher_repeatCount="-1"
app:switcher_autoStart="true"/>
<com.switcher.AutoSwitchView
android:id="@+id/auto_roll_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
app:switcher_repeatCount="-1"
app:switcher_autoStart="true"/>
<com.switcher.AutoSwitchView
android:id="@+id/auto_roll_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
app:switcher_repeatCount="-1"
app:switcher_autoStart="true"/>
<com.switcher.AutoSwitchView
android:id="@+id/auto_roll_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
app:switcher_autoStart="true"/>
</LinearLayout>
================================================
FILE: app/src/main/res/layout/activity_start.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<com.switcher.AutoSwitchView
android:id="@+id/start_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:switcher_repeatCount="-1"
app:switcher_autoStart="true"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="#000000"
android:text="content:"
android:layout_marginTop="30dp"
android:layout_marginLeft="15dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/start_banner"/>
<EditText
android:id="@+id/edt_content"
android:layout_width="0dp"
android:layout_height="49dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:background="@null"
android:hint="modify content"
android:singleLine="true"
android:textColorHint="#cccccc"
android:textColor="#535353"
android:textSize="15sp"
app:layout_constraintLeft_toRightOf="@id/tv_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBaseline_toBaselineOf="@id/tv_content" />
<EditText
android:id="@+id/edt_count"
android:layout_width="0dp"
android:layout_height="49dp"
android:layout_marginTop="10dp"
android:inputType="number"
android:background="@null"
android:hint="modify count"
android:singleLine="true"
android:textColorHint="#cccccc"
android:textSize="15sp"
app:layout_constraintLeft_toLeftOf="@id/edt_content"
app:layout_constraintRight_toRightOf="@id/edt_content"
app:layout_constraintTop_toBottomOf="@id/edt_content" />
<TextView
android:id="@+id/tv_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="#000000"
android:text="count:"
app:layout_constraintLeft_toLeftOf="@id/tv_content"
app:layout_constraintBaseline_toBaselineOf="@id/edt_count"/>
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Save changes"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/edt_count"/>
<Button
android:id="@+id/btn_example"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="40dp"
android:text="More examples"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
================================================
FILE: app/src/main/res/layout/item_in_list.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_item_in_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"/>
</FrameLayout>
================================================
FILE: app/src/main/res/layout/item_list.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"
android:paddingBottom="40dp">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:padding="8dp"
android:layout_gravity="center_horizontal"/>
<com.switcher.AutoSwitchView
android:id="@+id/auto_roll_in_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
================================================
FILE: app/src/main/res/layout/item_portrait.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:id="@+id/portrait"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:src="@drawable/portrait"/>
<TextView
android:id="@+id/item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/portrait"
android:text="my name"
android:textColor="#000000"
android:textSize="17sp"/>
<TextView
android:id="@+id/item_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/portrait"
android:layout_below="@id/item_name"
android:text="this is the desc"
android:textColor="#9c9c9c"
android:textSize="12sp"/>
</RelativeLayout>
</FrameLayout>
================================================
FILE: app/src/main/res/layout/item_single_text.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/single_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>
================================================
FILE: app/src/main/res/layout/start_banner.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/banner_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="22sp"
android:text="This is title"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp"
android:layout_marginTop="40dp"/>
<TextView
android:id="@+id/banner_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#919191"
android:textSize="10sp"
android:text="Click and See More"
android:drawablePadding="5dp"
android:drawableRight="@drawable/arrow_double"
android:layout_alignParentRight="true"
android:layout_below="@id/banner_title"
android:layout_margin="5dp"/>
</RelativeLayout>
================================================
FILE: app/src/main/res/layout/start_banner_2.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
>
<TextView
android:id="@+id/banner_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="40dp"
/>
<TextView
android:id="@+id/banner_pos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="22sp"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="35dp"
/>
</LinearLayout>
================================================
FILE: app/src/main/res/layout/vertical_banner.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/item_banner_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:drawablePadding="8dp"
android:drawableLeft="@drawable/horn"
android:textSize="11sp"
android:textColor="#666666"/>
<TextView
android:id="@+id/item_banner_stones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/stone"
android:drawablePadding="3dp"
android:layout_marginLeft="5dp"
android:textSize="11sp"
android:textColor="#666666"/>
</LinearLayout>
================================================
FILE: app/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
================================================
FILE: app/src/main/res/values/strings.xml
================================================
<resources>
<string name="app_name">AutoSwitcher</string>
</resources>
================================================
FILE: app/src/main/res/values/styles.xml
================================================
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
================================================
FILE: app/src/test/java/com/example/app/ExampleUnitTest.java
================================================
package com.example.app;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: auto-switcher/.gitignore
================================================
/build
================================================
FILE: auto-switcher/build.gradle
================================================
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 3
versionName "1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly 'com.android.support:appcompat-v7:26.0.0-beta1'
}
ext {
PUBLISH_GROUP_ID = 'com.github.markshawn'
PUBLISH_ARTIFACT_ID = 'auto-switcher'
PUBLISH_VERSION = '1.2'
}
apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
================================================
FILE: auto-switcher/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: auto-switcher/src/main/AndroidManifest.xml
================================================
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.switcher"/>
================================================
FILE: auto-switcher/src/main/java/com/switcher/AutoSwitchView.java
================================================
package com.switcher;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import com.switcher.base.BaseSwitchView;
import com.switcher.base.Utils;
import com.switcher.builder.DefaultStrategyBuilder;
/**
* AutoSwitchView will animate between two views and one is shown at a time.
* It can automatically switch between each child
*
* Created by shenxl on 2018/7/11.
*/
public class AutoSwitchView extends BaseSwitchView {
public static final int INFINITE = -1;
private SwitchStrategy mSwitchStrategy;
private SwitchListener mSwitchListener;
private boolean mWasRunningWhenDetached;
private boolean mIsRunning;
private boolean mAutoStart;
private int mHasRepeatedCount;
private int mRepeatCount;
public AutoSwitchView(Context context) {
super(context);
init(null);
}
public AutoSwitchView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
public AutoSwitchView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
public AutoSwitchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(attrs);
}
private void init(AttributeSet attrs) {
if (attrs != null) {
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.AutoSwitchView);
if (ta.getBoolean(R.styleable.AutoSwitchView_switcher_autoStart, false)) {
mAutoStart = true;
}
if (ta.hasValue(R.styleable.AutoSwitchView_switcher_repeatCount)) {
setRepeatCount(ta.getInt(R.styleable.AutoSwitchView_switcher_repeatCount, INFINITE));
}
ta.recycle();
}
mSwitchStrategy = new DefaultStrategyBuilder().build();
}
@Override
protected void onDetachedFromWindow() {
mWasRunningWhenDetached = mIsRunning;
mIsRunning = false;
if (mSwitchStrategy != null) {
mSwitchStrategy.onStop();
}
super.onDetachedFromWindow();
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mWasRunningWhenDetached || mAutoStart) {
startSwitcher();
}
}
@Override
public void setVisibility(int visibility) {
// Cancel animations or delays when it is hidden
if (visibility != VISIBLE){
stopSwitcher();
}
super.setVisibility(visibility);
}
@Override
public void setDisplayedItem(int itemIndex) {
// Cancel animations or delays when user choose one of items
if (mIsRunning) {
stopSwitcher();
}
super.setDisplayedItem(itemIndex);
}
/**
* @return
*
* @see #setSwitchStrategy(SwitchStrategy)
*/
public SwitchStrategy getSwitchStrategy() {
return mSwitchStrategy;
}
/**
* Customized animation strategy for switch between each child
*
* @param switchStrategy
*/
public void setSwitchStrategy(SwitchStrategy switchStrategy) {
if (mSwitchStrategy != null){
mSwitchStrategy.onStop();
mIsRunning = false;
}
mSwitchStrategy = switchStrategy;
}
/**
* @return
*
* @see #setSwitchListener(SwitchListener)
*/
public SwitchListener getSwitchListener() {
return mSwitchListener;
}
/**
* Sets a listener to notify the life of animation(that starts, ends or repeats)
*
* @param switchListener
*/
public void setSwitchListener(SwitchListener switchListener) {
mSwitchListener = switchListener;
}
/**
* @return
*
* @see #setRepeatCount(int)
*/
public int getRepeatCount() {
return mRepeatCount;
}
/**
* Sets how many times the animation should be repeated.
* If the repeat count is 0, the animation is never repeated.
* The repeat count is 0 by default.
*
* @param repeatCount the number of times the animation should be repeated
*/
public void setRepeatCount(int repeatCount) {
mRepeatCount = repeatCount;
}
/**
* @return
*
* @see #setAutoStart(boolean)
*/
public boolean isAutoStart() {
return mAutoStart;
}
/**
* Set if this view automatically calls {@link #startSwitcher()} when it
* becomes attached to a window.
*
* @param autoStart
*/
public void setAutoStart(boolean autoStart) {
mAutoStart = autoStart;
}
/**
* Start a timer to cycle through child views
*/
public void startSwitcher() {
mHasRepeatedCount = 0;
if (getChildCount() == 0 && mAdapter != null) {
addView(mAdapter.makeView(getContext()));
addView(mAdapter.makeView(getContext()));
} else {
for (int i = 0; i < getChildCount(); i++) {
getChildAt(i).setTag(null);
}
}
if (checkNoAnimCondtions()) {
stopSwitcher();
return;
}
if (!mIsRunning) {
if (mSwitchStrategy != null) {
post(new Runnable() {
@Override
public void run() {
if (mSwitchListener != null) {
mSwitchListener.switchStart(AutoSwitchView.this);
}
mSwitchStrategy.setSwitcher(AutoSwitchView.this);
mSwitchStrategy.init();
mIsRunning = true;
}
});
}
}
}
/**
* Cancel animations or delay
*/
public void stopSwitcher() {
mIsRunning = false;
if (mSwitchStrategy != null) {
mSwitchStrategy.onStop();
}
resetIndex();
if (mAdapter != null) {
if (mAdapter.getItemCount() == 0) {
removeAllViews();
} else if (mAdapter.getItemCount() == 1){
showIntervalState();
}
}
clearTags();
if (mSwitchListener != null) {
mSwitchListener.switchEnd(this);
}
}
boolean needStop() {
return checkNoAnimCondtions() || repeatOutOfLimit();
}
private boolean checkNoAnimCondtions() {
return getAdapter() == null || getAdapter().getItemCount() < 2 || getVisibility() != VISIBLE;
}
private boolean repeatOutOfLimit(){
return mRepeatCount != INFINITE && mHasRepeatedCount > mRepeatCount;
}
void showIntervalState() {
//show one view for a moment (mInterval) betwwn two switching actions
super.setDisplayedItem(mAdapter.getCurrentIndex());
}
void resetIndex() {
mWhichChild = 0;
if (mAdapter != null) {
mAdapter.setCurrentItem(0);
}
}
void stepOver() {
// index of view ++
stepForward();
if (mAdapter != null) {
// index of item ++
mAdapter.setCurrentItem(Utils.getIndexInLoop(mAdapter.getCurrentIndex() + 1, 0, mAdapter.getItemCount()));
if (mAdapter.getCurrentIndex() == 0) {
mHasRepeatedCount++;
if (mSwitchListener != null && !repeatOutOfLimit()) {
mSwitchListener.switchRepeat(this);
}
}
}
}
/**
* The animation listener to be notified when the animation of switcher starts,
* ends or repeats.
*/
public interface SwitchListener {
void switchStart(AutoSwitchView switcher);
void switchRepeat(AutoSwitchView switcher);
void switchEnd(AutoSwitchView switcher);
}
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/SwitchStrategy.java
================================================
package com.switcher;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import com.switcher.base.ChainOperator;
import com.switcher.base.SingleOperator;
/**
* A strategy that leads switcher {@link AutoSwitchView} to get all switching
* movement or animations done. It is a powerful tool that can be easliy
* customized through adding SingleOperator into {@link BaseBuilder}
* (init-next-withend) in turn to control all movements of {@link AutoSwitchView}.
*
* And some strategies are offered in the package builder, such as
* CarouselStrategyBuilder, AnimationStrategyBuilder, AnimatorStrategyBuilder
* and so on. The DefaultStrategyBuilder is used in {@link AutoSwitchView}
* by default.
*
* Created by shenxl on 2018/7/19.
*/
public class SwitchStrategy implements ChainOperator {
private boolean mIsStopped;
private long mInterval;
private AutoSwitchView mSwitcher;
private Handler mHandler = new Handler(Looper.getMainLooper());
private Object[] mCancelMembers;
private SingleOperator mInitStep, mNextStep, mStopStep;
private SwitchStrategy(BaseBuilder builder) {
mInitStep = builder.mInitStep;
mNextStep = builder.mNextStep;
mStopStep = builder.mStopStep;
}
void setSwitcher(AutoSwitchView switcher) {
mSwitcher = switcher;
}
void init(){
mIsStopped = false;
mSwitcher.resetIndex();
mSwitcher.showIntervalState();
if (mInitStep != null) {
mInitStep.operate(mSwitcher, this);
}
}
@Override
public void onStop(){
if (!mIsStopped) {
mHandler.removeCallbacksAndMessages(null);
if (mStopStep != null) {
mStopStep.operate(mSwitcher, this);
}
}
mIsStopped = true;
}
@Override
public void showNext(){
mSwitcher.stepOver();
if (mIsStopped){
return;
} else if (mSwitcher.needStop()){
mSwitcher.stopSwitcher();
return;
}
mSwitcher.getCurrentView().setVisibility(View.VISIBLE);
mSwitcher.getPreviousView().setVisibility(View.VISIBLE);
mSwitcher.updateCurrentView();
if (mNextStep != null) {
mNextStep.operate(mSwitcher, this);
}
}
@Override
public void showNextWithInterval(long delay){
this.mInterval = delay;
mSwitcher.showIntervalState();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
showNext();
}
}, delay);
}
@Override
public void stopWhenNeeded(Object... ts){
mCancelMembers = ts;
}
@Override
public Object[] getStoppingMembers() {
return mCancelMembers;
}
public static final class BaseBuilder {
private SingleOperator mInitStep;
private SingleOperator mNextStep;
private SingleOperator mStopStep;
public BaseBuilder() {
}
/**
* @param val The access to all the movements or animations in
* AutoSwitchView. if not called, nothing will happen.
* @return
*/
public BaseBuilder init(SingleOperator val) {
mInitStep = val;
return this;
}
/**
* @param val Automatically invoked after showNext or showNextWithInterval
* in {@link ChainOperator} is called
* @return
*/
public BaseBuilder next(SingleOperator val) {
mNextStep = val;
return this;
}
/**
* Strongly recommend calling it to cancel animations or delay in case menory
* leaks or anything unusual happens
*
* @param val Automatically invoked when the switching movements is stopped
* or {@link AutoSwitchView} is detached from window.
* @return
*/
public BaseBuilder withEnd(SingleOperator val) {
mStopStep = val;
return this;
}
public SwitchStrategy build() {
return new SwitchStrategy(this);
}
}
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/base/BaseSwitchView.java
================================================
package com.switcher.base;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
/**
* Base class for a {@link FrameLayout} container that can switch between views.
*
* Created by shenxl on 2018/7/19.
*/
public class BaseSwitchView extends FrameLayout {
public static final int INFINITE = -1;
protected int mWhichChild = 0;
protected AbsBaseAdapter mAdapter;
private OnItemClickListener mItemClickListener;
private int mActionDownItemIndex = -1;
public BaseSwitchView(Context context) {
super(context);
}
public BaseSwitchView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public BaseSwitchView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public BaseSwitchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void removeAllViews() {
super.removeAllViews();
mWhichChild = 0;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
if (mItemClickListener != null && mAdapter != null && mAdapter.getItemCount() > 0) {
mActionDownItemIndex = mAdapter.getCurrentIndex();
return true;
}
break;
case MotionEvent.ACTION_UP:
if (mItemClickListener != null && mAdapter != null && mAdapter.getItemCount() > 0 && mAdapter.getCurrentIndex() == mActionDownItemIndex ){
mItemClickListener.onItemClick(this, getCurrentView(), mAdapter.getCurrentIndex());
return true;
}
performClick();
mActionDownItemIndex = -1;
break;
}
return false;
}
public void setOnItemClickListener(OnItemClickListener itemClickListener) {
mItemClickListener = itemClickListener;
}
public void setAdapter(AbsBaseAdapter adapter) {
this.mAdapter = adapter;
}
public AbsBaseAdapter getAdapter() {
return mAdapter;
}
/**
* @return Returns the index of the currently displayed child view.
*/
public int getWhichChild() {
return mWhichChild;
}
/**
* Displays the data at the specified position on the current view and
* other views will be hidden
*
* @param itemIndex
*/
public void setDisplayedItem(int itemIndex) {
final int count = getChildCount();
final View currentView = getCurrentView();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child != currentView) {
child.setVisibility(View.GONE);
} else {
child.setVisibility(View.VISIBLE);
if (mAdapter != null) {
updateView(child, itemIndex);
mAdapter.mWhichItem = itemIndex;
}
}
}
}
/**
* call before we need to update view immediately
*/
public void clearTags(){
for (int i = 0;i < getChildCount();i++){
getChildAt(i).setTag(-1);
}
}
public View getCurrentView(){
return getChildAt(Utils.getIndexInLoop(mWhichChild, 0, getChildCount()));
}
public View getNextView(){
return getChildAt(Utils.getIndexInLoop(mWhichChild + 1, 0, getChildCount()));
}
public View getPreviousView(){
return getChildAt(Utils.getIndexInLoop(mWhichChild - 1, 0, getChildCount()));
}
public void stepForward() {
mWhichChild = Utils.getIndexInLoop(mWhichChild + 1, 0, getChildCount());
}
public void stepBackward() {
mWhichChild = Utils.getIndexInLoop(mWhichChild - 1, 0, getChildCount());
}
private void updateView(View view, int index){
if (mAdapter != null && index < mAdapter.getItemCount()) {
if (view.getTag() == null) {
view.setTag(index);
mAdapter.updateItem(view, index);
} else {
Integer i = (Integer) view.getTag();
if (i != index) {
view.setTag(index);
mAdapter.updateItem(view, index);
}
}
}
}
/**
* Displays the data at the current position on the current view
*/
public void updateCurrentView(){
if (mAdapter != null) {
updateView(getCurrentView(), mAdapter.getCurrentIndex());
}
}
/**
* An Adapter object acts as a bridge between child views in {@link BaseSwitchView}
* and the underlying data for that view.
*/
public static abstract class AbsBaseAdapter {
private int mWhichItem;
/**
* Create view that can be reused between items
*
* @param context
* @return
*/
public abstract View makeView(Context context);
/**
* Displays the data at the specified position on a specified view
*
* @param view
* @param position
*/
public abstract void updateItem(View view, int position);
/**
* @return How many items are in the data set represented by this Adapter.
*/
public abstract int getItemCount();
public final int getCurrentIndex() {
return mWhichItem;
}
public final void setCurrentItem(int whichItem) {
mWhichItem = whichItem;
}
public final int getNextIndex() {
return Utils.getIndexInLoop(mWhichItem + 1, 0, getItemCount());
}
}
/**
* Interface definition for a callback to be invoked when an item in this
* View has been clicked.
*/
public interface OnItemClickListener{
void onItemClick(BaseSwitchView parent, View child, int position);
}
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/base/ChainOperator.java
================================================
package com.switcher.base;
/**
* Created by shenxl on 2018/7/23.
*/
public interface ChainOperator {
/**
* Displays the data next item on the next view and {@link SingleOperator}
* that added in the next() in BaseBuilder will be invoked finally
*/
void showNext();
/**
* Call #showNext() after some delay
* @param delay
*/
void showNextWithInterval(long delay);
/**
* Stop switching movements and animations
*/
void onStop();
/**
* Cache objects that need to stopped
*
* @param ts
*/
void stopWhenNeeded(Object... ts);
/**
* Get objects that cached in #stopWhenNeeded(Object...)
*
* @return
*/
Object[] getStoppingMembers();
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/base/SingleOperator.java
================================================
package com.switcher.base;
import com.switcher.AutoSwitchView;
import com.switcher.SwitchStrategy;
/**
* Created by shenxl on 2018/7/23.
*/
public interface SingleOperator {
void operate(AutoSwitchView switcher, ChainOperator operator);
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/base/Utils.java
================================================
package com.switcher.base;
/**
* Created by shenxl on 2018/7/21.
*/
public class Utils {
public static int getIndexInLoop(int index, int start, int total){
if (index >= start + total) {
return start;
} else if (index < start) {
return total + start - 1;
}
return index;
}
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/builder/AnimationStrategyBuilder.java
================================================
package com.switcher.builder;
import android.content.Context;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import com.switcher.AutoSwitchView;
import com.switcher.SwitchStrategy;
import com.switcher.base.ChainOperator;
import com.switcher.base.SingleOperator;
/**
* Simple strategy to customize your own animation with {@link Animation}
*
* Created by shenxl on 2018/7/21.
*/
public class AnimationStrategyBuilder {
private Animation mAnimationIn;
private Animation mAnimationOut;
private long mInterval = 3000;
public AnimationStrategyBuilder(Animation animationIn, Animation animationOut) {
mAnimationIn = animationIn;
mAnimationOut = animationOut;
}
public AnimationStrategyBuilder(Context context, int resourceIDIn, int resourceIDOut){
mAnimationIn = AnimationUtils.loadAnimation(context, resourceIDIn);
mAnimationOut = AnimationUtils.loadAnimation(context, resourceIDOut);
}
public AnimationStrategyBuilder setInterval(long interval) {
mInterval = interval;
return this;
}
public SwitchStrategy build() {
return new SwitchStrategy.BaseBuilder().
init(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
operator.showNextWithInterval(mInterval);
}
}).
next(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
if (mAnimationIn != null) {
switcher.getCurrentView().startAnimation(mAnimationIn);
}
if (mAnimationOut != null) {
switcher.getPreviousView().startAnimation(mAnimationOut);
}
operator.showNextWithInterval(mInterval);
}
}).
withEnd(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
if (mAnimationIn != null) {
mAnimationIn.cancel();
}
if (mAnimationOut != null) {
mAnimationOut.cancel();
}
}
}).build();
}
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/builder/AnimatorStrategyBuilder.java
================================================
package com.switcher.builder;
import android.animation.AnimatorInflater;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.Handler;
import android.view.View;
import com.switcher.AutoSwitchView;
import com.switcher.SwitchStrategy;
import com.switcher.base.ChainOperator;
import com.switcher.base.SingleOperator;
/**
* Simple strategy to customize your own animation with {@link ObjectAnimator}
*
* Created by shenxl on 2018/7/21.
*/
public class AnimatorStrategyBuilder {
private ObjectAnimator mAnimatorIn;
private ObjectAnimator mAnimatorOut;
private long mInterval = 3000;
private Handler mHandler = new Handler();
public AnimatorStrategyBuilder(ObjectAnimator animatorIn, ObjectAnimator animatorOut) {
mAnimatorIn = animatorIn;
mAnimatorOut = animatorOut;
}
public AnimatorStrategyBuilder(Context context, int resourceIDIn, int resourceIDOut) {
mAnimatorIn = (ObjectAnimator) AnimatorInflater.loadAnimator(context, resourceIDIn);
mAnimatorOut = (ObjectAnimator) AnimatorInflater.loadAnimator(context, resourceIDOut);
}
public AnimatorStrategyBuilder setInterval(long interval) {
mInterval = interval;
return this;
}
public SwitchStrategy build() {
return new SwitchStrategy.BaseBuilder().
init(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
operator.showNextWithInterval(mInterval);
View childShow = switcher.getCurrentView();
childShow.setX(0);
childShow.setY(0);
childShow.setAlpha(1f);
}
}).
next(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, final ChainOperator operator) {
long delay = 0;
if (mAnimatorIn != null) {
mAnimatorIn.setTarget(switcher.getCurrentView());
mAnimatorIn.start();
delay = mAnimatorIn.getDuration();
}
if (mAnimatorOut != null) {
mAnimatorOut.setTarget(switcher.getPreviousView());
mAnimatorOut.start();
delay = delay > mAnimatorOut.getDuration() ? delay : mAnimatorOut.getDuration();
}
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
operator.showNextWithInterval(mInterval);
}
}, delay);
}
}).
withEnd(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
if (mAnimatorIn != null) {
mAnimatorIn.cancel();
}
if (mAnimatorOut != null) {
mAnimatorOut.cancel();
}
mHandler.removeCallbacksAndMessages(null);
}
}).build();
}
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/builder/CarouselStrategyBuilder.java
================================================
package com.switcher.builder;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.Interpolator;
import com.switcher.AutoSwitchView;
import com.switcher.SwitchStrategy;
import com.switcher.base.ChainOperator;
import com.switcher.base.SingleOperator;
/**
* A strategy that is able to switch between two items in different directions
*
* Created by shenxl on 2018/7/21.
*/
public class CarouselStrategyBuilder {
private long mInterval = 2000;
private long mAnimDuration = 500;
private DirectionMode mMode = DirectionMode.top2Bottom;
private Interpolator mInterpolator;
public CarouselStrategyBuilder setInterval(long interval) {
this.mInterval = interval;
return this;
}
public CarouselStrategyBuilder setAnimDuration(long animDuration) {
this.mAnimDuration = animDuration;
return this;
}
public CarouselStrategyBuilder setMode(DirectionMode mode) {
this.mMode = mode;
return this;
}
public CarouselStrategyBuilder setInterpolator(Interpolator interpolator) {
this.mInterpolator = interpolator;
return this;
}
public SwitchStrategy build() {
return new SwitchStrategy.BaseBuilder().
init(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
operator.showNextWithInterval(mInterval);
}
}).
next(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, final ChainOperator operator) {
View viewOut = switcher.getPreviousView();
switch (mMode) {
case top2Bottom:
viewOut.animate().setDuration(mAnimDuration).setInterpolator(mInterpolator).
translationYBy(switcher.getMeasuredHeight());
break;
case bottom2Top:
viewOut.animate().setDuration(mAnimDuration).setInterpolator(mInterpolator).
translationYBy(-switcher.getMeasuredHeight());
break;
case left2Right:
viewOut.animate().setDuration(mAnimDuration).setInterpolator(mInterpolator).
translationXBy(switcher.getMeasuredWidth());
break;
case right2Left:
viewOut.animate().setDuration(mAnimDuration).setInterpolator(mInterpolator).
translationXBy(-switcher.getMeasuredWidth());
break;
}
View viewIn = switcher.getCurrentView();
switch (mMode) {
case top2Bottom:
viewIn.setY(-switcher.getMeasuredHeight());
viewIn.animate().setDuration(mAnimDuration).setInterpolator(mInterpolator).
translationYBy(switcher.getMeasuredHeight());
break;
case bottom2Top:
viewIn.setY(switcher.getMeasuredHeight());
viewIn.animate().setDuration(mAnimDuration).setInterpolator(mInterpolator).
translationYBy(-switcher.getMeasuredHeight());
break;
case left2Right:
viewIn.setX(-switcher.getMeasuredWidth());
viewIn.animate().setDuration(mAnimDuration).setInterpolator(mInterpolator).
translationXBy(switcher.getMeasuredWidth());
break;
case right2Left:
viewIn.setX(switcher.getMeasuredWidth());
viewIn.animate().setDuration(mAnimDuration).setInterpolator(mInterpolator).
translationXBy(-switcher.getMeasuredWidth());
break;
}
viewIn.animate().withEndAction(new Runnable() {
@Override
public void run() {
operator.showNextWithInterval(mInterval);
}
});
operator.stopWhenNeeded(viewOut.animate(), viewIn.animate());
}
}).
withEnd(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
switcher.getCurrentView().setX(0);
switcher.getCurrentView().setY(0);
switcher.getCurrentView().setVisibility(View.VISIBLE);
switcher.getPreviousView().setX(0);
switcher.getPreviousView().setY(0);
switcher.getPreviousView().setVisibility(View.GONE);
if (operator.getStoppingMembers() != null) {
for (Object obj : operator.getStoppingMembers()) {
((ViewPropertyAnimator) obj).cancel();
}
}
}
}).build();
}
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/builder/ContinuousStrategyBuilder.java
================================================
package com.switcher.builder;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;
import com.switcher.AutoSwitchView;
import com.switcher.SwitchStrategy;
import com.switcher.base.ChainOperator;
import com.switcher.base.SingleOperator;
/**
* A strategy that is able to switch between items smoothly without any pauses
*
* Created by shenxl on 2018/7/21.
*/
public class ContinuousStrategyBuilder {
private long mDuration = 2000;
private DirectionMode mMode = DirectionMode.right2Left;
public ContinuousStrategyBuilder setDuration(long duration) {
this.mDuration = duration;
return this;
}
public ContinuousStrategyBuilder setMode(DirectionMode mode) {
this.mMode = mode;
return this;
}
public SwitchStrategy build() {
return new SwitchStrategy.BaseBuilder().
init(new SingleOperator() {
@Override
public void operate(final AutoSwitchView switcher, final ChainOperator operator) {
final float end = switcher.getAdapter().getItemCount() + 1;
ValueAnimator animator = ValueAnimator.ofFloat(0f, end);
animator.setDuration((long) (mDuration * end));
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setRepeatMode(ValueAnimator.RESTART);
animator.setInterpolator(new LinearInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = (float) animation.getAnimatedValue();
double floor = Math.floor(value);
if (switcher.getAdapter().getNextIndex() == floor) {
operator.showNext();
}
float offset;
switch (mMode) {
case top2Bottom:
offset = (float) ((value - floor) * switcher.getMeasuredHeight());
switcher.getCurrentView().setY(floor == end - 1 ? offset : offset - switcher.getMeasuredHeight());
switcher.getPreviousView().setY(floor == 0 || floor == end - 1 ? -switcher.getMeasuredHeight() : offset);
break;
case bottom2Top:
offset = (float) ((value - floor) * switcher.getMeasuredHeight());
switcher.getCurrentView().setY(floor == end - 1 ? -offset : switcher.getMeasuredHeight() - offset);
switcher.getPreviousView().setY(floor == 0 || floor == end - 1 ? switcher.getMeasuredHeight() : -offset);
break;
case left2Right:
offset = (float) ((value - floor) * switcher.getMeasuredWidth());
switcher.getCurrentView().setX(floor == end - 1 ? offset : offset - switcher.getMeasuredWidth());
switcher.getPreviousView().setX(floor == 0 || floor == end - 1 ? -switcher.getMeasuredWidth() : offset);
break;
case right2Left:
offset = (float) ((value - floor) * switcher.getMeasuredWidth());
switcher.getCurrentView().setX(floor == end - 1 ? -offset : switcher.getMeasuredWidth() - offset);
switcher.getPreviousView().setX(floor == 0 || floor == end - 1? switcher.getMeasuredWidth() : -offset);
break;
}
}
});
animator.start();
operator.stopWhenNeeded(animator);
}
}).
withEnd(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
if (operator.getStoppingMembers() != null) {
for (Object obj : operator.getStoppingMembers()) {
((ValueAnimator) obj).cancel();
}
}
}
}).build();
}}
================================================
FILE: auto-switcher/src/main/java/com/switcher/builder/DefaultStrategyBuilder.java
================================================
package com.switcher.builder;
import com.switcher.AutoSwitchView;
import com.switcher.SwitchStrategy;
import com.switcher.base.ChainOperator;
import com.switcher.base.SingleOperator;
/**
* The strategy, that is used in {@link AutoSwitchView} by default, only
* supports switching between items without any animations
*
* Created by shenxl on 2018/7/21.
*/
public class DefaultStrategyBuilder {
private long mInterval = 3000;
public DefaultStrategyBuilder setInterval(long interval) {
mInterval = interval;
return this;
}
public SwitchStrategy build() {
return new SwitchStrategy.BaseBuilder().
init(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
operator.showNextWithInterval(mInterval);
}
}).
next(new SingleOperator() {
@Override
public void operate(AutoSwitchView switcher, ChainOperator operator) {
operator.showNextWithInterval(mInterval);
}
}).build();
}
}
================================================
FILE: auto-switcher/src/main/java/com/switcher/builder/DirectionMode.java
================================================
package com.switcher.builder;
/**
* Created by shenxl on 2018/7/21.
*/
public enum DirectionMode {
top2Bottom, bottom2Top, left2Right, right2Left
}
================================================
FILE: auto-switcher/src/main/res/values/attrs.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="AutoSwitchView">
<attr name="switcher_autoStart" format="boolean" />
<attr name="switcher_repeatCount" format="integer" />
</declare-styleable>
</resources>
================================================
FILE: auto-switcher/src/main/res/values/strings.xml
================================================
<resources>
<string name="app_name">autoSwitcher</string>
</resources>
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Thu Oct 01 08:47:46 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: settings.gradle
================================================
include ':app', ':auto-switcher'
gitextract_hm9ildwt/ ├── .gitignore ├── LICENSE ├── README.md ├── README_cn.md ├── app/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── com/ │ │ └── example/ │ │ └── app/ │ │ └── ExampleInstrumentedTest.java │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── app/ │ │ │ ├── MainActivity.java │ │ │ ├── MyApplication.java │ │ │ ├── StartActivity.java │ │ │ └── adapter/ │ │ │ ├── BannerAdapter.java │ │ │ ├── BannerAdapter2.java │ │ │ ├── HornAdapter.java │ │ │ ├── MyAdapterInList.java │ │ │ ├── PortraitAdapter.java │ │ │ └── SingleTextAdapter.java │ │ └── res/ │ │ ├── anim/ │ │ │ ├── anim_in.xml │ │ │ └── anim_out.xml │ │ ├── animator/ │ │ │ ├── anim_in.xml │ │ │ └── anim_out.xml │ │ ├── layout/ │ │ │ ├── activity_list.xml │ │ │ ├── activity_main.xml │ │ │ ├── activity_start.xml │ │ │ ├── item_in_list.xml │ │ │ ├── item_list.xml │ │ │ ├── item_portrait.xml │ │ │ ├── item_single_text.xml │ │ │ ├── start_banner.xml │ │ │ ├── start_banner_2.xml │ │ │ └── vertical_banner.xml │ │ └── values/ │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test/ │ └── java/ │ └── com/ │ └── example/ │ └── app/ │ └── ExampleUnitTest.java ├── auto-switcher/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── switcher/ │ │ ├── AutoSwitchView.java │ │ ├── SwitchStrategy.java │ │ ├── base/ │ │ │ ├── BaseSwitchView.java │ │ │ ├── ChainOperator.java │ │ │ ├── SingleOperator.java │ │ │ └── Utils.java │ │ └── builder/ │ │ ├── AnimationStrategyBuilder.java │ │ ├── AnimatorStrategyBuilder.java │ │ ├── CarouselStrategyBuilder.java │ │ ├── ContinuousStrategyBuilder.java │ │ ├── DefaultStrategyBuilder.java │ │ └── DirectionMode.java │ └── res/ │ └── values/ │ ├── attrs.xml │ └── strings.xml ├── build.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle
SYMBOL INDEX (149 symbols across 23 files)
FILE: app/src/androidTest/java/com/example/app/ExampleInstrumentedTest.java
class ExampleInstrumentedTest (line 17) | @RunWith(AndroidJUnit4.class)
method useAppContext (line 19) | @Test
FILE: app/src/main/java/com/example/app/MainActivity.java
class MainActivity (line 29) | public class MainActivity extends Activity {
method onCreate (line 36) | @Override
FILE: app/src/main/java/com/example/app/MyApplication.java
class MyApplication (line 11) | public class MyApplication extends Application {
method onCreate (line 12) | @Override
FILE: app/src/main/java/com/example/app/StartActivity.java
class StartActivity (line 19) | public class StartActivity extends Activity {
method onCreate (line 24) | @Override
FILE: app/src/main/java/com/example/app/adapter/BannerAdapter.java
class BannerAdapter (line 15) | public class BannerAdapter extends BaseSwitchView.AbsBaseAdapter {
method makeView (line 17) | @Override
method updateItem (line 22) | @Override
method getItemCount (line 43) | @Override
FILE: app/src/main/java/com/example/app/adapter/BannerAdapter2.java
class BannerAdapter2 (line 14) | public class BannerAdapter2 extends BaseSwitchView.AbsBaseAdapter {
method makeView (line 18) | @Override
method updateItem (line 23) | @Override
method setCount (line 42) | public void setCount(int count) {
method setTitle (line 46) | public void setTitle(String title) {
method getCount (line 50) | public int getCount() {
method getTitle (line 54) | public String getTitle() {
method getItemCount (line 58) | @Override
FILE: app/src/main/java/com/example/app/adapter/HornAdapter.java
class HornAdapter (line 18) | public class HornAdapter extends AutoSwitchView.AbsBaseAdapter {
method HornAdapter (line 21) | public HornAdapter(List<String> entityList) {
method makeView (line 25) | @Override
method updateItem (line 30) | @Override
method getItemCount (line 39) | @Override
FILE: app/src/main/java/com/example/app/adapter/MyAdapterInList.java
class MyAdapterInList (line 15) | public class MyAdapterInList extends AutoSwitchView.AbsBaseAdapter{
method MyAdapterInList (line 19) | public MyAdapterInList(Activity activity, int count) {
method makeView (line 24) | @Override
method updateItem (line 29) | @Override
method getItemCount (line 35) | @Override
FILE: app/src/main/java/com/example/app/adapter/PortraitAdapter.java
class PortraitAdapter (line 15) | public class PortraitAdapter extends BaseSwitchView.AbsBaseAdapter {
method makeView (line 17) | @Override
method updateItem (line 22) | @Override
method getItemCount (line 43) | @Override
FILE: app/src/main/java/com/example/app/adapter/SingleTextAdapter.java
class SingleTextAdapter (line 15) | public class SingleTextAdapter extends BaseSwitchView.AbsBaseAdapter {
method SingleTextAdapter (line 18) | public SingleTextAdapter(String str) {
method makeView (line 22) | @Override
method updateItem (line 27) | @Override
method getItemCount (line 33) | @Override
FILE: app/src/test/java/com/example/app/ExampleUnitTest.java
class ExampleUnitTest (line 12) | public class ExampleUnitTest {
method addition_isCorrect (line 13) | @Test
FILE: auto-switcher/src/main/java/com/switcher/AutoSwitchView.java
class AutoSwitchView (line 18) | public class AutoSwitchView extends BaseSwitchView {
method AutoSwitchView (line 29) | public AutoSwitchView(Context context) {
method AutoSwitchView (line 34) | public AutoSwitchView(Context context, AttributeSet attrs) {
method AutoSwitchView (line 39) | public AutoSwitchView(Context context, AttributeSet attrs, int defStyl...
method AutoSwitchView (line 44) | public AutoSwitchView(Context context, AttributeSet attrs, int defStyl...
method init (line 49) | private void init(AttributeSet attrs) {
method onDetachedFromWindow (line 63) | @Override
method onAttachedToWindow (line 73) | @Override
method setVisibility (line 81) | @Override
method setDisplayedItem (line 90) | @Override
method getSwitchStrategy (line 104) | public SwitchStrategy getSwitchStrategy() {
method setSwitchStrategy (line 113) | public void setSwitchStrategy(SwitchStrategy switchStrategy) {
method getSwitchListener (line 126) | public SwitchListener getSwitchListener() {
method setSwitchListener (line 135) | public void setSwitchListener(SwitchListener switchListener) {
method getRepeatCount (line 144) | public int getRepeatCount() {
method setRepeatCount (line 155) | public void setRepeatCount(int repeatCount) {
method isAutoStart (line 164) | public boolean isAutoStart() {
method setAutoStart (line 174) | public void setAutoStart(boolean autoStart) {
method startSwitcher (line 181) | public void startSwitcher() {
method stopSwitcher (line 218) | public void stopSwitcher() {
method needStop (line 237) | boolean needStop() {
method checkNoAnimCondtions (line 241) | private boolean checkNoAnimCondtions() {
method repeatOutOfLimit (line 245) | private boolean repeatOutOfLimit(){
method showIntervalState (line 249) | void showIntervalState() {
method resetIndex (line 254) | void resetIndex() {
method stepOver (line 261) | void stepOver() {
type SwitchListener (line 280) | public interface SwitchListener {
method switchStart (line 281) | void switchStart(AutoSwitchView switcher);
method switchRepeat (line 283) | void switchRepeat(AutoSwitchView switcher);
method switchEnd (line 285) | void switchEnd(AutoSwitchView switcher);
FILE: auto-switcher/src/main/java/com/switcher/SwitchStrategy.java
class SwitchStrategy (line 24) | public class SwitchStrategy implements ChainOperator {
method SwitchStrategy (line 33) | private SwitchStrategy(BaseBuilder builder) {
method setSwitcher (line 39) | void setSwitcher(AutoSwitchView switcher) {
method init (line 43) | void init(){
method onStop (line 52) | @Override
method showNext (line 63) | @Override
method showNextWithInterval (line 82) | @Override
method stopWhenNeeded (line 94) | @Override
method getStoppingMembers (line 99) | @Override
class BaseBuilder (line 104) | public static final class BaseBuilder {
method BaseBuilder (line 109) | public BaseBuilder() {
method init (line 117) | public BaseBuilder init(SingleOperator val) {
method next (line 127) | public BaseBuilder next(SingleOperator val) {
method withEnd (line 140) | public BaseBuilder withEnd(SingleOperator val) {
method build (line 145) | public SwitchStrategy build() {
FILE: auto-switcher/src/main/java/com/switcher/base/BaseSwitchView.java
class BaseSwitchView (line 15) | public class BaseSwitchView extends FrameLayout {
method BaseSwitchView (line 23) | public BaseSwitchView(Context context) {
method BaseSwitchView (line 27) | public BaseSwitchView(Context context, AttributeSet attrs) {
method BaseSwitchView (line 31) | public BaseSwitchView(Context context, AttributeSet attrs, int defStyl...
method BaseSwitchView (line 35) | public BaseSwitchView(Context context, AttributeSet attrs, int defStyl...
method removeAllViews (line 39) | @Override
method onTouchEvent (line 45) | @Override
method setOnItemClickListener (line 66) | public void setOnItemClickListener(OnItemClickListener itemClickListen...
method setAdapter (line 70) | public void setAdapter(AbsBaseAdapter adapter) {
method getAdapter (line 74) | public AbsBaseAdapter getAdapter() {
method getWhichChild (line 81) | public int getWhichChild() {
method setDisplayedItem (line 91) | public void setDisplayedItem(int itemIndex) {
method clearTags (line 111) | public void clearTags(){
method getCurrentView (line 117) | public View getCurrentView(){
method getNextView (line 121) | public View getNextView(){
method getPreviousView (line 125) | public View getPreviousView(){
method stepForward (line 129) | public void stepForward() {
method stepBackward (line 133) | public void stepBackward() {
method updateView (line 137) | private void updateView(View view, int index){
method updateCurrentView (line 155) | public void updateCurrentView(){
class AbsBaseAdapter (line 165) | public static abstract class AbsBaseAdapter {
method makeView (line 174) | public abstract View makeView(Context context);
method updateItem (line 182) | public abstract void updateItem(View view, int position);
method getItemCount (line 187) | public abstract int getItemCount();
method getCurrentIndex (line 189) | public final int getCurrentIndex() {
method setCurrentItem (line 193) | public final void setCurrentItem(int whichItem) {
method getNextIndex (line 197) | public final int getNextIndex() {
type OnItemClickListener (line 206) | public interface OnItemClickListener{
method onItemClick (line 207) | void onItemClick(BaseSwitchView parent, View child, int position);
FILE: auto-switcher/src/main/java/com/switcher/base/ChainOperator.java
type ChainOperator (line 7) | public interface ChainOperator {
method showNext (line 12) | void showNext();
method showNextWithInterval (line 18) | void showNextWithInterval(long delay);
method onStop (line 23) | void onStop();
method stopWhenNeeded (line 30) | void stopWhenNeeded(Object... ts);
method getStoppingMembers (line 37) | Object[] getStoppingMembers();
FILE: auto-switcher/src/main/java/com/switcher/base/SingleOperator.java
type SingleOperator (line 10) | public interface SingleOperator {
method operate (line 11) | void operate(AutoSwitchView switcher, ChainOperator operator);
FILE: auto-switcher/src/main/java/com/switcher/base/Utils.java
class Utils (line 7) | public class Utils {
method getIndexInLoop (line 8) | public static int getIndexInLoop(int index, int start, int total){
FILE: auto-switcher/src/main/java/com/switcher/builder/AnimationStrategyBuilder.java
class AnimationStrategyBuilder (line 18) | public class AnimationStrategyBuilder {
method AnimationStrategyBuilder (line 23) | public AnimationStrategyBuilder(Animation animationIn, Animation anima...
method AnimationStrategyBuilder (line 28) | public AnimationStrategyBuilder(Context context, int resourceIDIn, int...
method setInterval (line 33) | public AnimationStrategyBuilder setInterval(long interval) {
method build (line 38) | public SwitchStrategy build() {
FILE: auto-switcher/src/main/java/com/switcher/builder/AnimatorStrategyBuilder.java
class AnimatorStrategyBuilder (line 20) | public class AnimatorStrategyBuilder {
method AnimatorStrategyBuilder (line 26) | public AnimatorStrategyBuilder(ObjectAnimator animatorIn, ObjectAnimat...
method AnimatorStrategyBuilder (line 31) | public AnimatorStrategyBuilder(Context context, int resourceIDIn, int ...
method setInterval (line 36) | public AnimatorStrategyBuilder setInterval(long interval) {
method build (line 41) | public SwitchStrategy build() {
FILE: auto-switcher/src/main/java/com/switcher/builder/CarouselStrategyBuilder.java
class CarouselStrategyBuilder (line 18) | public class CarouselStrategyBuilder {
method setInterval (line 24) | public CarouselStrategyBuilder setInterval(long interval) {
method setAnimDuration (line 29) | public CarouselStrategyBuilder setAnimDuration(long animDuration) {
method setMode (line 34) | public CarouselStrategyBuilder setMode(DirectionMode mode) {
method setInterpolator (line 39) | public CarouselStrategyBuilder setInterpolator(Interpolator interpolat...
method build (line 44) | public SwitchStrategy build() {
FILE: auto-switcher/src/main/java/com/switcher/builder/ContinuousStrategyBuilder.java
class ContinuousStrategyBuilder (line 18) | public class ContinuousStrategyBuilder {
method setDuration (line 22) | public ContinuousStrategyBuilder setDuration(long duration) {
method setMode (line 27) | public ContinuousStrategyBuilder setMode(DirectionMode mode) {
method build (line 32) | public SwitchStrategy build() {
FILE: auto-switcher/src/main/java/com/switcher/builder/DefaultStrategyBuilder.java
class DefaultStrategyBuilder (line 15) | public class DefaultStrategyBuilder {
method setInterval (line 18) | public DefaultStrategyBuilder setInterval(long interval) {
method build (line 23) | public SwitchStrategy build() {
FILE: auto-switcher/src/main/java/com/switcher/builder/DirectionMode.java
type DirectionMode (line 7) | public enum DirectionMode {
Condensed preview — 61 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (108K chars).
[
{
"path": ".gitignore",
"chars": 190,
"preview": "*.iml\n*.apk\n*.ap_\n*.dex\n*.class\n*.log\n.gradle\n/bin\n/gen\n/local.properties\n/.idea\n/build\n.DS_Store\n/captures\n/app/build\n/"
},
{
"path": "LICENSE",
"chars": 11357,
"preview": " Apache License\n Version 2.0, January 2004\n "
},
{
"path": "README.md",
"chars": 3815,
"preview": "English | [中文文档](README_cn.md)\n\n# AndroidAutoSwitcher\n[ | 中文文档\n\n# AndroidAutoSwitcher\n[ users:\n# Gradle settings configured through the IDE *will o"
},
{
"path": "gradlew",
"chars": 4971,
"preview": "#!/usr/bin/env bash\n\n##############################################################################\n##\n## Gradle start "
},
{
"path": "gradlew.bat",
"chars": 2314,
"preview": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem "
},
{
"path": "settings.gradle",
"chars": 33,
"preview": "include ':app', ':auto-switcher'\n"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the Marksss/AndroidAutoSwitcher GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 61 files (96.6 KB), approximately 23.6k tokens, and a symbol index with 149 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.