MCPcopy Index your code
hub / github.com/Marksss/AndroidAutoSwitcher

github.com/Marksss/AndroidAutoSwitcher @v1.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2 ↗ · + Follow
153 symbols 372 edges 23 files 50 documented · 33%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

English | 中文文档

AndroidAutoSwitcher

License Platform API Download

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.

demo-gif

Usage

Add the dependency to your project build.gradle file

compile 'com.github.markshawn:auto-switcher:1.0.1'

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.

Extension points exported contracts — how you extend this code

SingleOperator (Interface)
Created by shenxl on 2018/7/23. [5 implementers]
auto-switcher/src/main/java/com/switcher/base/SingleOperator.java
ChainOperator (Interface)
Created by shenxl on 2018/7/23. [2 implementers]
auto-switcher/src/main/java/com/switcher/base/ChainOperator.java
OnItemClickListener (Interface)
Interface definition for a callback to be invoked when an item in this View has been clicked. [1 implementers]
auto-switcher/src/main/java/com/switcher/base/BaseSwitchView.java
SwitchListener (Interface)
The animation listener to be notified when the animation of switcher starts, ends or repeats.
auto-switcher/src/main/java/com/switcher/AutoSwitchView.java

Core symbols most depended-on inside this repo

getCurrentView
called by 15
auto-switcher/src/main/java/com/switcher/base/BaseSwitchView.java
setInterpolator
called by 12
auto-switcher/src/main/java/com/switcher/builder/CarouselStrategyBuilder.java
getPreviousView
called by 11
auto-switcher/src/main/java/com/switcher/base/BaseSwitchView.java
setDuration
called by 10
auto-switcher/src/main/java/com/switcher/builder/ContinuousStrategyBuilder.java
getItemCount
called by 9
auto-switcher/src/main/java/com/switcher/base/BaseSwitchView.java
showNextWithInterval
called by 8
auto-switcher/src/main/java/com/switcher/base/ChainOperator.java
build
called by 7
auto-switcher/src/main/java/com/switcher/SwitchStrategy.java
getIndexInLoop
called by 7
auto-switcher/src/main/java/com/switcher/base/Utils.java

Shape

Method 126
Class 22
Interface 4
Enum 1

Languages

Java100%

Modules by API surface

auto-switcher/src/main/java/com/switcher/AutoSwitchView.java28 symbols
auto-switcher/src/main/java/com/switcher/base/BaseSwitchView.java26 symbols
auto-switcher/src/main/java/com/switcher/SwitchStrategy.java16 symbols
auto-switcher/src/main/java/com/switcher/builder/CarouselStrategyBuilder.java8 symbols
app/src/main/java/com/example/app/adapter/BannerAdapter2.java8 symbols
auto-switcher/src/main/java/com/switcher/builder/ContinuousStrategyBuilder.java6 symbols
auto-switcher/src/main/java/com/switcher/builder/AnimatorStrategyBuilder.java6 symbols
auto-switcher/src/main/java/com/switcher/base/ChainOperator.java6 symbols
auto-switcher/src/main/java/com/switcher/builder/AnimationStrategyBuilder.java5 symbols
app/src/main/java/com/example/app/adapter/SingleTextAdapter.java5 symbols
app/src/main/java/com/example/app/adapter/MyAdapterInList.java5 symbols
app/src/main/java/com/example/app/adapter/HornAdapter.java5 symbols

For agents

$ claude mcp add AndroidAutoSwitcher \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact