This repository has been archived by the owner on May 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
144 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/claha/showtimeremote/base/BaseFragmentPagerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.claha.showtimeremote.base; | ||
|
||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentStatePagerAdapter; | ||
import android.support.v4.view.PagerAdapter; | ||
|
||
import java.util.List; | ||
|
||
public class BaseFragmentPagerAdapter extends FragmentStatePagerAdapter { | ||
|
||
private List<Class<? extends BaseFragment>> fragments; | ||
|
||
public BaseFragmentPagerAdapter(FragmentManager fragmentManager, List<Class<? extends BaseFragment>> fragments) { | ||
super(fragmentManager); | ||
this.fragments = fragments; | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
try { | ||
return fragments.get(position).newInstance(); | ||
} catch (InstantiationException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return fragments.size(); | ||
} | ||
|
||
@Override | ||
public int getItemPosition(Object object) { | ||
return PagerAdapter.POSITION_NONE; | ||
} | ||
|
||
public void setFragments(List<Class<? extends BaseFragment>> fragments) { | ||
this.fragments = fragments; | ||
notifyDataSetChanged(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/claha/showtimeremote/base/BaseViewPagerIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.claha.showtimeremote.base; | ||
|
||
import android.content.Context; | ||
import android.database.DataSetObserver; | ||
import android.support.v4.view.ViewPager; | ||
import android.util.AttributeSet; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.LinearLayout; | ||
import android.widget.RadioGroup; | ||
|
||
import com.claha.showtimeremote.R; | ||
|
||
public class BaseViewPagerIndicator extends RadioGroup implements RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener { | ||
|
||
private ViewPager viewPager; | ||
|
||
public BaseViewPagerIndicator(Context context) { | ||
super(context, null); | ||
} | ||
|
||
public BaseViewPagerIndicator(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
setOrientation(LinearLayout.HORIZONTAL); | ||
setOnCheckedChangeListener(this); | ||
} | ||
|
||
private void createIndicators() { | ||
Log.d("DEBUG", "createIndicators: " + viewPager.getAdapter().getCount()); | ||
removeAllViews(); | ||
for (int i = 0; i < viewPager.getAdapter().getCount(); i++) { | ||
View indicator = inflate(getContext(), R.layout.indicator, null); | ||
addView(indicator); | ||
} | ||
setChecked(viewPager.getCurrentItem()); | ||
} | ||
|
||
public void setViewPager(ViewPager viewPager) { | ||
this.viewPager = viewPager; | ||
this.viewPager.setOnPageChangeListener(this); | ||
createIndicators(); | ||
|
||
this.viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() { | ||
@Override | ||
public void onChanged() { | ||
createIndicators(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onCheckedChanged(RadioGroup group, int checkedId) { | ||
if (viewPager != null) { | ||
int index = group.indexOfChild(group.findViewById(checkedId)); | ||
viewPager.setCurrentItem(index); | ||
} | ||
} | ||
|
||
@Override | ||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | ||
} | ||
|
||
@Override | ||
public void onPageSelected(int position) { | ||
setChecked(position); | ||
} | ||
|
||
@Override | ||
public void onPageScrollStateChanged(int state) { | ||
} | ||
|
||
private void setChecked(int position) { | ||
check(getChildAt(position).getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> |