Interactive Carousel in Android - android

I want to make a carousel in Android but must be an interactive one.
I tryed to use this library https://github.com/jacevedo/Android-Apps but i didn't work how i wan't.
What i need is Something like:
The idea is: when a color is clicked the picture change its color with setTint(). If the picture changes the color keep the selected color.
I need that be compatible with android 4.2
Any library or any guide that works similar?
Thanks!

You can try CarouselView library.
Include the following code view in your layout:
<com.synnapps.carouselview.CarouselView
android:id="#+id/carouselView"
android:layout_width="match_parent"
android:layout_height="200dp"
app:fillColor="#FFFFFFFF"
app:pageColor="#00000000"
app:radius="6dp"
app:slideInterval="3000"
app:strokeColor="#FF777777"
app:strokeWidth="1dp"/>
carouselView = (CarouselView) findViewById(R.id.carouselView);
carouselView.setPageCount(sampleImages.length);
carouselView.setImageListener(imageListener);
carouselView.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
// Do your desired action
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
ImageListener imageListener = new ImageListener() {
#Override
public void setImageForPosition(int position, ImageView imageView) {
// Set the desired picture
}
};

Related

Intent activity in Carousel [duplicate]

I found a library on github that has CarouselPicker com.github.Vatican-Cameos:CarouselPicker:v1.0 i added this in the dependencies and compile also in repositories maven { url 'https://jitpack.io'}
I have successfully make a CarouselPicker this is the JAVA CODE
carouselPicker = (CarouselPicker)findViewById(R.id.carouselPicker);
List<CarouselPicker.PickerItem> itemsImage = new ArrayList<>();
itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.abc));
itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.123));
itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.colors));
itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.shapes));
CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this, itemsImage,0);
carouselPicker.setAdapter(imageAdapter);
And by having a LinearLayout this is the XML code
<in.goodiebag.carouselpicker.CarouselPicker
android:id="#+id/carouselPicker"
android:layout_marginTop="50dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:items_visible="three"
/>
I cant find on google on what if the 1st item in the carousel picker selected like a OnClickListenerto change the intent
I found a library you used on this link
You must use addOnPageChangeListener like this:
carouselPicker.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
//position of the selected item
if(position == 0){
startActivity(new Intent(thisActivity.this, anotherActivity1.class));
}
else if(position == 1){
startActivity(new Intent(thisActivity.this, anotherActivity2.class));
}
// Same conditions for another cases.
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
So, your onClickListener that you want to handle the click event, is onPageSelected method.

How to get view and scroll like make my trip application "Hot Deals" section.?

i followed this tutorial "https://github.com/DevExchanges/ViewPagerCards"
i got the view like hotdeals section of MMT.But now i also want to change the image while swiping of cardview same as MMT.
you should be add two viewpager.
One for imagePager and second for cardviewPager
cardviewPager .addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
imagePager.setCurrentItem(position);
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
If you are using Viewpagers you can change the image by using the listener of onPageChanged.

MainActivity Get Position Of Item From PagerAdapter [duplicate]

I want to know the current page position of the ViewPager. I create an adapter and set this adapter to the ViewPager. Now I want to know the current page number or position of the current view, because I want to start some extra events on that particular page.
I used viewPager.setCurrentItem(1); for setting the first item.
Is there a similar method for getting the current page?
in the latest packages you can also use
vp.getCurrentItem()
or
vp is the viewPager ,
pageListener = new PageListener();
vp.setOnPageChangeListener(pageListener);
you have to put a page change listener for your viewPager. There is no method on viewPager to get the current page.
private int currentPage;
private static class PageListener extends SimpleOnPageChangeListener{
public void onPageSelected(int position) {
Log.i(TAG, "page selected " + position);
currentPage = position;
}
}
There is a method object_of_ViewPager.getCurrentItem() which returns the position of currently Viewed page of view pager
If you only want the position, vp.getCurrentItem() will give it to you, no need to apply the onPageChangeListener() for that purpose alone.
You will figure out that setOnPageChangeListener is deprecated, use addOnPageChangeListener, as below:
ViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
if(position == 1){ // if you want the second page, for example
//Your code here
}
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
For this problem Onpagechange listener is the best one But it will also have one small mistake that is it will not detect the starting time time of 0th position Once you will change the page it will starts to detect the Page selected position...For this problem I fount the easiest solution
1.You have to maintain the selected position value then use it....
2. Case 1: At the starting of the position is always Zero....
Case 2: Suppose if you set the current item means you will set that value into maintain position
3.Then do your action with the use of that maintain in your activity...
Public int maintain=0;
myViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int i, float v, int i2) {
//Toast.makeText(MyActivity.this, i+" Is Selected "+data.size(), Toast.LENGTH_SHORT).show();
}
#Override
public void onPageSelected( int i) {
// here you will get the position of selected page
maintain = i;
}
#Override
public void onPageScrollStateChanged(int i) {
}
});
updateButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MyActivity.this, i+" Is Selected "+data.size(), Toast.LENGTH_SHORT).show();
data.set(maintain, "Replaced "+maintain);
myViewPager.getAdapter().notifyDataSetChanged();
}
});
getCurrentItem(), doesn't actually give the right position for the first and the last page I fixed it adding this code:
public void CalcPostion() {
current = viewPager.getCurrentItem();
if ((last == current) && (current != 1) && (current != 0)) {
current = current + 1;
viewPager.setCurrentItem(current);
}
if ((last == 1) && (current == 1)) {
last = 0;
current = 0;
}
display();
last = current;
}
The setOnPageChangeListener() method is deprecated. Use
addOnPageChangeListener(OnPageChangeListener) instead.
You can use OnPageChangeListener and getting the position inside onPageSelected() method, this is an example:
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
Log.d(TAG, "my position is : " + position);
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
Or just use getCurrentItem() to get the real position:
viewPager.getCurrentItem();
There is no any method getCurrentItem() in viewpager.i already checked the API

How to achieve animation in ImageView like newsstand application header - Android

I want to set Animation to images of in image view like in newsstand application and change image after particular interval of time.
Please help its very important for me.
for animating a view (image view included) i recommend this library
set the animation time and when it ends change the image, full code for the code snippet
rope = YoYo.with(Techniques.FadeIn).duration(1000).playOn(mTarget);// after start,just click mTarget view, rope is not init
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Techniques technique = (Techniques)view.getTag();
rope = YoYo.with(technique)
.duration(1200)
.interpolate(new AccelerateDecelerateInterpolator())
.withListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
}
#Override
public void onAnimationEnd(Animator animation) {
//change image here
}
#Override
public void onAnimationCancel(Animator animation) {
Toast.makeText(MyActivity.this, "canceled", Toast.LENGTH_SHORT).show();
}
#Override
public void onAnimationRepeat(Animator animation) {
}
})
.playOn(mTarget);
}
});

Issue related to view pager and circle page indicator

I have four pages/screens in my view pager and I am using Circle page indicator for displaying the position of the screen. It works perfectly.
Now I need to add one more indicator circle even though the screen count is 4. Up on crossing the 4 the screen, I want to display another activity.
I have searched and found a solution for moving to another activity before the fake page (5th page is shown). Here is the code:
#Override
public Object instantiateItem(final ViewGroup container, int position) {
// TODO Auto-generated method stub
((ViewPager) container).setOnPageChangeListener(new OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// skip fake page (first), go to last page
if (position == 4) {
//instead of activity call, I am checking whether it's working or not
((ViewPager) container).setCurrentItem(0, false);
}
}
#Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
});
return super.instantiateItem(container, position);
}
But the problem is that, When I am doing this, the circle page indicator stops working.
Here is code for setting the adapter to circle page indicator:
mVpAdvertisement.setAdapter(mAdapter);
mCpIndicator.setViewPager(mVpAdvertisement);
mCpIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener()
{
#Override
public void onPageSelected(int position)
{
// on changing the pages during swipe
if(position==0)
{
}
}
#Override
public void onPageScrollStateChanged(int arg0)
{
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2)
{
}
});
I want to display 5 circles and upon swiping from 4th screen in view pager, I want application to display another activity, without showing the 5th screen (dummy screen) in view pager.
This is the library I am using: https://github.com/JakeWharton/Android-ViewPagerIndicator
I know this is too late, even the person posted the question got the answer also, but as it may help others to find the quick answer i am posting the answer.
Use two image(circle) for indicator one is for off and another for on. use frame layout to show the indicator. when user slide the viewPager just change the image. You can download the complete solutions which i have developed and working fine for me.
http://javaant.com/viewpager-with-circle-indicator-in-android

Categories

Resources