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 [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html) [![API](https://img.shields.io/badge/API-12%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=12) [![Download](https://jitpack.io/v/Marksss/AndroidAutoSwitcher.svg)](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. ![demo-gif](https://github.com/Marksss/AndroidAutoSwitcher/blob/master/gif/demo.gif) ## 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 ``` ``` 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 [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html) [![API](https://img.shields.io/badge/API-12%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=12) [![Download](https://jitpack.io/v/Marksss/AndroidAutoSwitcher.svg)](https://jitpack.io/#Marksss/AndroidAutoSwitcher) AutoSwitchView是一个能自由切换两个子控件的控件容器,相比于ViewFlipper,它支持子控件的复用,数据量大的情况下能有更好的性能。同时,相比于AdapterViewFlipper,它有更好的扩展性,支持自定义各种切换动画。 ![demo-gif](https://github.com/Marksss/AndroidAutoSwitcher/blob/master/gif/demo.gif) ## 用法 ### 将JitPack添加到 `build.gradle` 文件中 ``` allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ``` ### 添加依赖 ```implementation 'com.github.Marksss:AndroidAutoSwitcher:v1.2'``` ### XML中的代码 ``` ``` 如果想让切换动画无限循环,只需将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 Testing documentation */ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @Test public void useAppContext() throws Exception { } } ================================================ FILE: app/src/main/AndroidManifest.xml ================================================ ================================================ 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 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 mEntityList; public HornAdapter(List 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 ================================================ ================================================ FILE: app/src/main/res/anim/anim_out.xml ================================================ ================================================ FILE: app/src/main/res/animator/anim_in.xml ================================================ ================================================ FILE: app/src/main/res/animator/anim_out.xml ================================================ ================================================ FILE: app/src/main/res/layout/activity_list.xml ================================================ ================================================ FILE: app/src/main/res/layout/activity_main.xml ================================================ ================================================ FILE: app/src/main/res/layout/activity_start.xml ================================================