Skip to content

Commit

Permalink
Merge pull request #11 from vontell/dev
Browse files Browse the repository at this point in the history
Dev into Master
  • Loading branch information
vontell authored Jul 28, 2016
2 parents 3e21eb0 + 0e4413d commit abfdbcd
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 159 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 @@ -20,6 +20,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

// EXAMPLE WITH BASIC DRAWABLE RESOURCES ---------------------------------------------------
// INCLUDES PROGRESS STYLE -----------------------------------------------------------------

// Grab the views
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager_one);
Expand All @@ -37,12 +38,29 @@ 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 WITHOUT PROGRESS STYLE ----------------------------------------------------------

LinearLayout indicatorContainerDefault = (LinearLayout) findViewById(R.id.indicator_default);

// Bind the view pager to the indicatorContainer
IndicatorBinder defaultInd = new IndicatorBinder().bind(this,
viewPager,
indicatorContainerDefault,
selectedImage,
unselectedImage);

// Set whether you want a progress style
defaultInd.setProgressStyle(false);

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

// Create each tab TextView
Expand All @@ -56,7 +74,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 +85,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
20 changes: 16 additions & 4 deletions 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 All @@ -27,13 +27,25 @@
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="@+id/view_pager_one"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:gravity="center_horizontal"
android:id="@+id/indicator_cont">
android:id="@+id/indicator_cont"
android:layout_below="@+id/indicator_default"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">

</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="@+id/indicator_default"
android:layout_marginTop="8dp"
android:layout_below="@+id/view_pager_one"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="center_horizontal"></LinearLayout>


</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
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 +28,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,15 +60,15 @@ 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,
@DrawableRes final int indicatorOffResource) {

// Load the indicator drawables
final Drawable selected = context.getResources().getDrawable(indicatorOnResource);
final Drawable unselected = context.getResources().getDrawable(indicatorOffResource);
final Drawable selected = ContextCompat.getDrawable(context, indicatorOnResource);
final Drawable unselected = ContextCompat.getDrawable(context, indicatorOffResource);

// Load the container with indicators
final int numItems = viewPager.getAdapter().getCount();
Expand All @@ -72,11 +95,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 +110,7 @@ public void onPageScrollStateChanged(int state) {

}
});

return this;
}

/**
Expand All @@ -103,7 +127,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 @@ -131,11 +155,11 @@ public static void bindTextTabs(

// Set colors of the TextView
if(i == viewPager.getCurrentItem()) {
tab.setBackgroundColor(context.getResources().getColor(backgroundSelectedColor));
tab.setTextColor(context.getResources().getColor(textSelectedColor));
tab.setBackgroundColor(ContextCompat.getColor(context, backgroundSelectedColor));
tab.setTextColor(ContextCompat.getColor(context, textSelectedColor));
} else {
tab.setBackgroundColor(context.getResources().getColor(backgroundUnselectedColor));
tab.setTextColor(context.getResources().getColor(textUnselectedColor));
tab.setBackgroundColor(ContextCompat.getColor(context, backgroundUnselectedColor));
tab.setTextColor(ContextCompat.getColor(context, textUnselectedColor));
}

// Set Click Listeners of the tabs
Expand All @@ -148,7 +172,6 @@ public void onClick(View view) {
});

tabContainer.addView(tab);

}

// Set listener for ViewPager changes
Expand All @@ -164,11 +187,11 @@ public void onPageSelected(int position) {
for(int i = 0; i < tabViews.size(); i++){
TextView tab = (TextView) tabContainer.getChildAt(i);
if(i == position) {
tab.setBackgroundColor(context.getResources().getColor(backgroundSelectedColor));
tab.setTextColor(context.getResources().getColor(textSelectedColor));
tab.setBackgroundColor(ContextCompat.getColor(context, backgroundSelectedColor));
tab.setTextColor(ContextCompat.getColor(context, textSelectedColor));
} else {
tab.setBackgroundColor(context.getResources().getColor(backgroundUnselectedColor));
tab.setTextColor(context.getResources().getColor(textUnselectedColor));
tab.setBackgroundColor(ContextCompat.getColor(context, backgroundUnselectedColor));
tab.setTextColor(ContextCompat.getColor(context, textUnselectedColor));
}
}
}
Expand All @@ -178,7 +201,7 @@ public void onPageScrollStateChanged(int state) {

}
});

return this;
}

/**
Expand Down

0 comments on commit abfdbcd

Please sign in to comment.