Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support RTL layout #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class MainActivity extends FancyWalkthroughActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

FancyWalkthroughCard fancywalkthroughCard1 = new FancyWalkthroughCard("Find Restaurant", "Find the best restaurant in your neighborhood.",R.drawable.find_restaurant1);
FancyWalkthroughCard fancywalkthroughCard2 = new FancyWalkthroughCard("Pick the best", "Pick the right place using trusted ratings and reviews.",R.drawable.pickthebest);
FancyWalkthroughCard fancywalkthroughCard3 = new FancyWalkthroughCard("Choose your meal", "Easily find the type of food you're craving.",R.drawable.chooseurmeal);
Expand Down Expand Up @@ -44,8 +45,10 @@ protected void onCreate(Bundle savedInstanceState) {
//setImageBackground(R.drawable.restaurant);
setInactiveIndicatorColor(R.color.grey_600);
setActiveIndicatorColor(R.color.colorGreen);
setOnboardPages(pages);

//to allow for RTL layout
setRTL(true);
setOnboardPages(pages);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import android.support.annotation.ColorRes;
import android.support.annotation.RequiresApi;
import android.support.annotation.StringRes;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
Expand All @@ -25,6 +27,8 @@
import com.shashank.sony.fancywalkthroughlib.utils.ShadowTransformer;
import com.shashank.sony.fancywalkthroughlib.views.CircleIndicatorView;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

public abstract class FancyWalkthroughActivity extends AppCompatActivity implements View.OnClickListener, ViewPager.OnPageChangeListener {
Expand All @@ -44,6 +48,7 @@ public abstract class FancyWalkthroughActivity extends AppCompatActivity impleme
private List<Integer> colorList;
private boolean solidBackground = false;
private List<FancyWalkthroughCard> pages;
private boolean isRTL = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -52,34 +57,53 @@ protected void onCreate(Bundle savedInstanceState) {
setStatusBackgroundColor();
hideActionBar();

parentLayout = (RelativeLayout) findViewById(R.id.parent_layout);
circleIndicatorView = (CircleIndicatorView) findViewById(R.id.circle_indicator_view);
btnSkip = (TextView) findViewById(R.id.btn_skip);
buttonsLayout = (FrameLayout) findViewById(R.id.buttons_layout);
navigationControls = (FrameLayout) findViewById(R.id.navigation_layout);
ivNext = (ImageView) findViewById(R.id.ivNext);
ivPrev = (ImageView) findViewById(R.id.ivPrev);
backgroundImage = (ImageView) findViewById(R.id.background_image);
vpOnboarderPager = (ViewPager) findViewById(R.id.vp_pager);
parentLayout = findViewById(R.id.parent_layout);
circleIndicatorView = findViewById(R.id.circle_indicator_view);
btnSkip = findViewById(R.id.btn_skip);
buttonsLayout = findViewById(R.id.buttons_layout);
navigationControls = findViewById(R.id.navigation_layout);
ivNext = findViewById(R.id.ivNext);
ivPrev = findViewById(R.id.ivPrev);
backgroundImage = findViewById(R.id.background_image);
vpOnboarderPager = findViewById(R.id.vp_pager);
vpOnboarderPager.addOnPageChangeListener(this);
btnSkip.setOnClickListener(this);
ivPrev.setOnClickListener(this);
ivNext.setOnClickListener(this);

hideFinish(false);
fadeOut(ivPrev, false);
}

public void setOnboardPages(List<FancyWalkthroughCard> pages) {
public void setOnboardPages(final List<FancyWalkthroughCard> pages) {

this.pages = pages;
ahoyOnboarderAdapter = new FancyWalkthroughAdapter(pages, getSupportFragmentManager(), dpToPixels(0, this), typeface);
if(isRTL) { //reverse the order of pages so first page is the last

Collections.reverse(this.pages);
fadeOut(ivNext, false);
} else {

fadeOut(ivPrev, false);
} //end if

ahoyOnboarderAdapter = new FancyWalkthroughAdapter(pages, getSupportFragmentManager(), dpToPixels(0, this), typeface, isRTL);
mCardShadowTransformer = new ShadowTransformer(vpOnboarderPager, ahoyOnboarderAdapter);
mCardShadowTransformer.enableScaling(true);
vpOnboarderPager.setAdapter(ahoyOnboarderAdapter);
vpOnboarderPager.setPageTransformer(false, mCardShadowTransformer);
circleIndicatorView.setPageIndicators(pages.size());

if(isRTL) { // start from the last page

//without postdelayed, a rectangle is drawn around the first page
vpOnboarderPager.postDelayed(new Runnable() {
@Override
public void run() {
vpOnboarderPager.setCurrentItem(pages.size() - 1, true);
}
},1);
circleIndicatorView.setCurrentPage(ahoyOnboarderAdapter.getCount() - 1);
} //end if
}

public float dpToPixels(int dp, Context context) {
Expand All @@ -101,12 +125,34 @@ public void onClick(View v) {
boolean isInFirstPage = vpOnboarderPager.getCurrentItem() == 0;
boolean isInLastPage = vpOnboarderPager.getCurrentItem() == ahoyOnboarderAdapter.getCount() - 1;

if (isRTL) { //if RTL, reverse the order
isInFirstPage = vpOnboarderPager.getCurrentItem() == ahoyOnboarderAdapter.getCount() - 1;
isInLastPage = vpOnboarderPager.getCurrentItem() == 0;
}
if (i == R.id.btn_skip && isInLastPage) {
onFinishButtonPressed();
} else if (i == R.id.ivPrev && !isInFirstPage) {
vpOnboarderPager.setCurrentItem(vpOnboarderPager.getCurrentItem() - 1);
} else if (i == R.id.ivNext && !isInLastPage) {
vpOnboarderPager.setCurrentItem(vpOnboarderPager.getCurrentItem() + 1);
} else if (i == R.id.ivPrev) {
if (isRTL) {
if(!isInLastPage) {

vpOnboarderPager.setCurrentItem(vpOnboarderPager.getCurrentItem() - 1);
}//end if
} else {
if(!isInFirstPage) {
vpOnboarderPager.setCurrentItem(vpOnboarderPager.getCurrentItem() - 1);
} //end if
}
} else if (i == R.id.ivNext) {
if (isRTL) {
if(!isInFirstPage) {

vpOnboarderPager.setCurrentItem(vpOnboarderPager.getCurrentItem() + 1);
}//end if
} else {
if(!isInLastPage) {
vpOnboarderPager.setCurrentItem(vpOnboarderPager.getCurrentItem() + 1);
} //end if
}
}
}

Expand All @@ -120,24 +166,51 @@ public void onPageSelected(int position) {

int firstPagePosition = 0;
int lastPagePosition = ahoyOnboarderAdapter.getCount() - 1;
circleIndicatorView.setCurrentPage(position);

//in case of RTL first is the last
if (isRTL) {
firstPagePosition = ahoyOnboarderAdapter.getCount() - 1;
lastPagePosition = 0;
} //end if

circleIndicatorView.setCurrentPage(position);

if (position == lastPagePosition) {
fadeOut(circleIndicatorView);
showFinish();
fadeOut(ivNext);
fadeIn(ivPrev);
if(isRTL) {
fadeOut(ivPrev);
fadeIn(ivNext);
} else {
fadeOut(ivNext);
fadeIn(ivPrev);
} //end if
} else if (position == firstPagePosition) {
fadeOut(ivPrev);
fadeIn(ivNext);

if(isRTL) {

fadeOut(ivNext);
fadeIn(ivPrev);
} else {

fadeOut(ivPrev);
fadeIn(ivNext);
} //end if
hideFinish();
fadeIn(circleIndicatorView);
} else {
fadeIn(circleIndicatorView);
hideFinish();
fadeIn(ivPrev);
fadeIn(ivNext);

if(isRTL) {

fadeIn(ivNext);
fadeIn(ivPrev);
} else {

fadeIn(ivPrev);
fadeIn(ivNext);
}
}

if (solidBackground && (pages.size() == colorList.size())) {
Expand Down Expand Up @@ -292,6 +365,13 @@ public void setActiveIndicatorColor(int color) {
this.circleIndicatorView.setActiveIndicatorColor(color);
}


public void setRTL(boolean value) {

this.isRTL = value;
}


/**
* <br/><br/>
* <b>N.B. Builds before JELLY_BEAN will use the default style</b>
Expand Down
Loading