Create a beautiful animated slide courtesy of Cuberto and modified by SWRevo by adding a sample implementation in a Java project.
- Android 7.0+
- Java 1.8
- This library made with kotlin language
Add the following to your build.gradle to use:
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.SWRevo:LiquidSwipe:1.0.0'
}
Add LiquidPager to your xml and use it like you would ViewPager, define in xml:
<id.indosw.liquidswipe_lib.LiquidPager
android:id="@+id/pager"android:layout_width="match_parent"android:layout_height="match_parent" />importandroid.os.Bundleimportandroidx.appcompat.app.AppCompatActivityimportid.indosw.liquidswipe_lib.LiquidPagerimportid.indosw.liquidswipesample.adapter.AdapterKtclassMainActivityKt : AppCompatActivity() {
overridefunonCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
valpager = findViewById<LiquidPager>(R.id.pager)
pager.adapter = AdapterKt(supportFragmentManager)
}
}importandroidx.appcompat.app.AppCompatActivity;
importandroid.os.Bundle;
importid.indosw.liquidswipe_lib.LiquidPager;
importid.indosw.liquidswipesample.adapter.AdapterJava;
publicclassMainActivityextendsAppCompatActivity {
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LiquidPagerpager = findViewById(R.id.pager);
pager.setAdapter(newAdapterJava(getSupportFragmentManager()));
}
}importandroid.os.Bundleimportandroidx.fragment.app.Fragmentimportandroidx.fragment.app.FragmentManagerimportandroidx.fragment.app.FragmentPagerAdapterimportid.indosw.liquidswipesample.fragment.PageFragmentKtclassAdapterKt(fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
privatevaltotal: Int = 6privatevaldata : ArrayList<PageFragmentKt> = ArrayList(total)
init {
for (iin0untiltotal) {
valfragment = PageFragmentKt()
valbundle = Bundle()
bundle.putInt("POSITION", i+1)
fragment.arguments = bundledata.add(fragment)
}
}
overridefungetItem(position: Int): Fragment {
returndata[position]
}
overridefungetCount(): Int {
returntotal
}
}importandroid.os.Bundle;
importandroidx.fragment.app.Fragment;
importandroidx.fragment.app.FragmentManager;
importandroidx.fragment.app.FragmentPagerAdapter;
importorg.jetbrains.annotations.NotNull;
importjava.util.ArrayList;
importid.indosw.liquidswipesample.fragment.PageFragmentJava;
importkotlin.jvm.internal.Intrinsics;
publicclassAdapterJavaextendsFragmentPagerAdapter {
privatefinalinttotal;
privatefinalArrayList<PageFragmentJava> data;
@NotNullpublicFragmentgetItem(intposition) {
Fragmentobj = data.get(position);
Intrinsics.checkNotNullExpressionValue(obj, "data[position]");
returnobj;
}
publicintgetCount() {
returntotal;
}
publicAdapterJava(@NotNullFragmentManagerfragmentManager) {
super(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
Intrinsics.checkNotNullParameter(fragmentManager, "fragmentManager");
total = 6;
data = newArrayList<>(total);
inti = 0;
for(; i < total; ++i) {
PageFragmentJavafragment = newPageFragmentJava();
Bundlebundle = newBundle();
bundle.putInt("POSITION", i + 1);
fragment.setArguments(bundle);
data.add(fragment);
}
}
}importandroid.graphics.Colorimportandroid.os.Bundleimportandroid.view.LayoutInflaterimportandroid.view.Viewimportandroid.view.ViewGroupimportandroidx.fragment.app.Fragmentimportid.indosw.liquidswipesample.RclassPageFragmentKt : Fragment() {
privatevarposition : Int = -1overridefunonCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
position = arguments?.getInt("POSITION")!!
}
overridefunonCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
vallayoutId = when (position) {
1 -> {
R.layout.first_page
}
2 -> {
R.layout.second_page
}
else -> R.layout.fragment_page_number
}
returnlayoutInflater.inflate(layoutId, container, false)
}
overridefunonViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
when (position) {
1 -> return2 -> return3 -> view.setBackgroundColor(
Color.rgb(
(0.3647058904 * 255).toInt(),
(0.06666667014 * 255).toInt(),
(0.9686274529 * 255).toInt()
)
)
4 -> view.setBackgroundColor(
Color.rgb(
255,
(0.3529352546 * 255).toInt(),
(0.2339158952 * 255).toInt()
)
)
5 -> view.setBackgroundColor(
Color.rgb(
(0.1215686277 * 255).toInt(),
(0.01176470611 * 255).toInt(),
(0.4235294163 * 255).toInt()
)
)
6 -> view.setBackgroundColor(
Color.rgb(
(0.3411764801 * 255).toInt(),
(0.6235294342 * 255).toInt(),
(0.1686274558 * 255).toInt()
)
)
else -> view.setBackgroundColor(
Color.rgb(
(Math.random() * 255).toInt(),
(Math.random() * 255).toInt(),
(Math.random() * 255).toInt()
)
)
}
}
}importandroid.graphics.Color;
importandroid.os.Bundle;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroidx.fragment.app.Fragment;
importorg.jetbrains.annotations.NotNull;
importorg.jetbrains.annotations.Nullable;
importid.indosw.liquidswipesample.R;
importkotlin.jvm.internal.Intrinsics;
publicfinalclassPageFragmentJavaextendsFragment {
privateintposition = -1;
@SuppressWarnings("ConstantConditions")
publicvoidonCreate(@NullableBundlesavedInstanceState) {
super.onCreate(savedInstanceState);
BundlevarBundle = this.getArguments();
IntegerintPos = varBundle != null ? varBundle.getInt("POSITION") : null;
Intrinsics.checkNotNull(intPos);
this.position = intPos;
}
@NullablepublicViewonCreateView(@NotNullLayoutInflaterinflater, @NullableViewGroupcontainer, @NullableBundlesavedInstanceState) {
Intrinsics.checkNotNullParameter(inflater, "inflater");
intviewPos;
if (this.position == 1) {
viewPos = R.layout.first_page;
} elseif (this.position == 2) {
viewPos = R.layout.second_page;
} else {
viewPos = R.layout.fragment_page_number;
}
intlayoutId = viewPos;
returnthis.getLayoutInflater().inflate(layoutId, container, false);
}
@SuppressWarnings("UnnecessaryReturnStatement")
publicvoidonViewCreated(@NotNullViewview, @NullableBundlesavedInstanceState) {
Intrinsics.checkNotNullParameter(view, "view");
super.onViewCreated(view, savedInstanceState);
if (this.position == 1) {
return;
} elseif (this.position == 2) {
return;
} elseif (this.position == 3) {
view.setBackgroundColor(
Color.rgb(
(int) 93.000002052D,
(int) 17.0000008857D,
(int) 247.0000004895D)
);
} elseif (this.position == 4) {
view.setBackgroundColor(
Color.rgb(255,
(int) 89.99848992300001D,
(int) 59.648553276D)
);
} elseif (this.position == 5) {
view.setBackgroundColor(
Color.rgb(
(int) 31.0000000635D,
(int) 3.00000005805D,
(int) 108.0000011565D)
);
} elseif (this.position == 6) {
view.setBackgroundColor(
Color.rgb(
(int) 87.0000024255D,
(int) 159.00000572099998D,
(int) 43.000001229D)
);
} else {
view.setBackgroundColor(
Color.rgb(
(int) (Math.random() * (double) 255),
(int) (Math.random() * (double) 255),
(int) (Math.random() * (double) 255))
);
}
}
}Similar library LiquidSwipe by Cuberto
Cuberto Design, info@cuberto.com - Modification by IndoSW
Liquid Swipe is available under the MIT license. See the LICENSE file for more info.
