| 33 |
33 |
|
| 34 |
34 |
class GenericViewPager
|
| 35 |
35 |
{
|
| 36 |
|
static final int[] TABS =
|
|
36 |
static final int[][] TABS =
|
| 37 |
37 |
{
|
| 38 |
38 |
// Add here a new row to create another tab serving effects of a given type (you would also need to
|
| 39 |
39 |
// create a new layout to fill the first 3 values of the row ). Comment out a row to remove the tab.
|
| 40 |
40 |
//
|
| 41 |
|
// LAYOUT //////////// INNER LAYOUT //////// SPINNER ////////////// EFFECT_TYPE //////////////////// SHOW CENTER // SHOW REGION
|
| 42 |
|
R.layout.effects3dtab0, R.id.effects3dlayout0, R.id.effects3dspinner0, EffectType.MATRIX .ordinal() , 1, 0 ,
|
| 43 |
|
R.layout.effects3dtab1, R.id.effects3dlayout1, R.id.effects3dspinner1, EffectType.VERTEX .ordinal() , 1, 1 ,
|
| 44 |
|
R.layout.effects3dtab2, R.id.effects3dlayout2, R.id.effects3dspinner2, EffectType.FRAGMENT .ordinal() , 1, 0 ,
|
| 45 |
|
R.layout.effects3dtab3, R.id.effects3dlayout3, R.id.effects3dspinner3, EffectType.POSTPROCESS.ordinal() , 0, 0
|
|
41 |
////// LAYOUT //////////// INNER LAYOUT //////// SPINNER ////////////// EFFECT_TYPE //////////////////// SHOW CENTER // SHOW REGION
|
|
42 |
{ R.layout.effects3dtab0, R.id.effects3dlayout0, R.id.effects3dspinner0, EffectType.MATRIX .ordinal() , 1, 0 } ,
|
|
43 |
{ R.layout.effects3dtab1, R.id.effects3dlayout1, R.id.effects3dspinner1, EffectType.VERTEX .ordinal() , 1, 1 } ,
|
|
44 |
{ R.layout.effects3dtab2, R.id.effects3dlayout2, R.id.effects3dspinner2, EffectType.FRAGMENT .ordinal() , 1, 0 } ,
|
|
45 |
{ R.layout.effects3dtab3, R.id.effects3dlayout3, R.id.effects3dspinner3, EffectType.POSTPROCESS.ordinal() , 0, 0 }
|
| 46 |
46 |
};
|
| 47 |
47 |
|
| 48 |
|
static final int NUM = 6; // 6 ints required to describe 1 tab
|
| 49 |
|
private static final int NUM_TABS = TABS.length/NUM;
|
|
48 |
private static final int NUM_TABS = TABS.length;
|
| 50 |
49 |
|
| 51 |
50 |
private ViewPager mViewPager;
|
| 52 |
51 |
private int mCurrentTab;
|
| ... | ... | |
| 63 |
62 |
{
|
| 64 |
63 |
if( position>=0 && position<NUM_TABS )
|
| 65 |
64 |
{
|
| 66 |
|
GenericTab tab = new GenericTab(); // no we cannot make tab equal to mTab[position]
|
| 67 |
|
// tabs have to be set through the setTab() method
|
| 68 |
|
Bundle bundle = new Bundle(); // otherwise it doesn't work on recreation (rotate!)
|
|
65 |
GenericTab tab = new GenericTab();
|
|
66 |
|
|
67 |
Bundle bundle = new Bundle();
|
| 69 |
68 |
bundle.putInt("position", position);
|
| 70 |
69 |
tab.setArguments(bundle);
|
| 71 |
70 |
|
| ... | ... | |
| 84 |
83 |
@Override
|
| 85 |
84 |
public CharSequence getPageTitle(int position)
|
| 86 |
85 |
{
|
| 87 |
|
int ordinal = TABS[position*NUM + 3];
|
|
86 |
int ordinal = TABS[position][3];
|
| 88 |
87 |
return EffectType.getType(ordinal).name();
|
| 89 |
88 |
}
|
| 90 |
89 |
}
|
| ... | ... | |
| 105 |
104 |
|
| 106 |
105 |
void showRegionAndCenter(boolean showR, boolean showC, GenericSurfaceView sv)
|
| 107 |
106 |
{
|
| 108 |
|
boolean localShowC = (TABS[NUM*mCurrentTab + 4] == 1);
|
| 109 |
|
boolean localShowR = (TABS[NUM*mCurrentTab + 5] == 1);
|
|
107 |
boolean localShowC = (TABS[mCurrentTab][4] == 1);
|
|
108 |
boolean localShowR = (TABS[mCurrentTab][5] == 1);
|
| 110 |
109 |
|
| 111 |
110 |
sv.getRenderer().showRegionAndCenter( (showR&&localShowR) , (showC&&localShowC) );
|
| 112 |
111 |
}
|
| ... | ... | |
| 122 |
121 |
|
| 123 |
122 |
void setCurrentTab(EffectType type)
|
| 124 |
123 |
{
|
| 125 |
|
for(int i=0; i<NUM_TABS; i++)
|
|
124 |
for(int tab=0; tab<NUM_TABS; tab++)
|
| 126 |
125 |
{
|
| 127 |
|
if( TABS[i*NUM + 3] == type.ordinal() )
|
|
126 |
if( TABS[tab][3] == type.ordinal() )
|
| 128 |
127 |
{
|
| 129 |
|
mCurrentTab = i;
|
|
128 |
mCurrentTab = tab;
|
| 130 |
129 |
break;
|
| 131 |
130 |
}
|
| 132 |
131 |
}
|
Further improvement for the Generic app.