Skip to content

Commit

Permalink
Added feature to allow progress style
Browse files Browse the repository at this point in the history
Library object now needs to be instantiated

setIsProgressStyle to control progress
  • Loading branch information
ehila committed Jul 27, 2016
1 parent 3e21eb0 commit 7aabe4f
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 146 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.iml
.gradle
.idea/
/local.properties
/.idea/workspace.xml
/.idea/libraries
Expand Down
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

22 changes: 0 additions & 22 deletions .idea/compiler.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/copyright/profiles_settings.xml

This file was deleted.

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

This file was deleted.

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

This file was deleted.

46 changes: 0 additions & 46 deletions .idea/misc.xml

This file was deleted.

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

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ protected void onCreate(Bundle savedInstanceState) {
int unselectedImage = R.drawable.indicator_unselected;

// Bind the view pager to the indicatorContainer
IndicatorBinder.bind(this,
IndicatorBinder sample = new IndicatorBinder().bind(this,
viewPager,
indicatorContainer,
selectedImage,
unselectedImage);
// Set whether you want a progress style
sample.setProgressStyle(true);

// EXAMPLE WITH TABS -----------------------------------------------------------------------

Expand All @@ -56,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
tabViews.get(1).setText("Tab 2");
tabViews.get(2).setText("Tab 3");
tabViews.get(3).setText("Tab 4");
tabViews.get(4).setText("Tab 6");
tabViews.get(4).setText("Tab 5");

// Set the requested colors
int selectedBackgroundColor = R.color.tabBackgroundSelected;
Expand All @@ -67,7 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Grab the LinearLayout
LinearLayout tabContainer = (LinearLayout) findViewById(R.id.tab_container);

IndicatorBinder.bindTextTabs(this,
new IndicatorBinder().bindTextTabs(this,
viewPager,
tabContainer,
tabViews,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="@+id/tab_container"></LinearLayout>
android:id="@+id/tab_container"/>

<android.support.v4.view.ViewPager
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
Expand All @@ -25,6 +27,26 @@
*/
public class IndicatorBinder {

private boolean isProgressStyle = false;

/**
* Returns if the current indicator is set to progress style or not
* @return returns true or false
*/
public boolean isProgressStyle() {
return isProgressStyle;
}

/**
* Set whether the indicators are set to selected as your swipe through the view pager or not
* Currently only setup to work with bind method
* Default is false
* @param progressStyle boolean for progress style
*/
public void setProgressStyle(boolean progressStyle) {
isProgressStyle = progressStyle;
}

/**
* Binds the viewPager to indicatorContainer, such that indicatorContainer has a list of
* indicators, all displaying the drawable at indicatorOffResource except for the ith child,
Expand All @@ -37,7 +59,7 @@ public class IndicatorBinder {
* @param indicatorOnResource The drawable to display for indicators that are not selected
* @param indicatorOffResource The drawable to display for the selected indicator
*/
public static void bind(@NonNull final Context context,
public IndicatorBinder bind(@NonNull final Context context,
@NonNull final ViewPager viewPager,
@NonNull final ViewGroup indicatorContainer,
@DrawableRes final int indicatorOnResource,
Expand Down Expand Up @@ -72,11 +94,12 @@ public void onPageSelected(int position) {

for(int i = 0; i < numItems; i++){
ImageView indicator = (ImageView) indicatorContainer.getChildAt(i);
if(i == position){
indicator.setImageDrawable(selected);

if(isProgressStyle){
indicator.setImageDrawable((i <= position) ? selected : unselected);
}
else {
indicator.setImageDrawable(unselected);
indicator.setImageDrawable((i == position) ? selected : unselected);
}
}
}
Expand All @@ -86,7 +109,7 @@ public void onPageScrollStateChanged(int state) {

}
});

return this;
}

/**
Expand All @@ -103,7 +126,7 @@ public void onPageScrollStateChanged(int state) {
* @param textSelectedColor The text color resource for a selected tab
* @param textUnselectedColor The text color resource for an unselected tab
*/
public static void bindTextTabs(
public IndicatorBinder bindTextTabs(
@NonNull final Context context,
@NonNull final ViewPager viewPager,
@NonNull final LinearLayout tabContainer,
Expand Down Expand Up @@ -148,7 +171,6 @@ public void onClick(View view) {
});

tabContainer.addView(tab);

}

// Set listener for ViewPager changes
Expand Down Expand Up @@ -178,7 +200,7 @@ public void onPageScrollStateChanged(int state) {

}
});

return this;
}

/**
Expand Down

0 comments on commit 7aabe4f

Please sign in to comment.