1 |
1e7603bb
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2018 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
71c8884f
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
1e7603bb
|
Leszek Koltunski
|
// //
|
6 |
71c8884f
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
1e7603bb
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
71c8884f
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
1e7603bb
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
71c8884f
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
1e7603bb
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.examples.generic;
|
21 |
|
|
|
22 |
|
|
import android.os.Bundle;
|
23 |
2fad84a7
|
Leszek Koltunski
|
|
24 |
|
|
import androidx.annotation.NonNull;
|
25 |
|
|
import androidx.fragment.app.Fragment;
|
26 |
|
|
import androidx.fragment.app.FragmentManager;
|
27 |
|
|
import androidx.fragment.app.FragmentPagerAdapter;
|
28 |
|
|
|
29 |
|
|
import androidx.viewpager.widget.ViewPager;
|
30 |
|
|
import androidx.appcompat.app.AppCompatActivity;
|
31 |
1e7603bb
|
Leszek Koltunski
|
|
32 |
|
|
import org.distorted.examples.R;
|
33 |
|
|
import org.distorted.library.effect.EffectType;
|
34 |
|
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
class GenericViewPager
|
38 |
|
|
{
|
39 |
d271024d
|
Leszek Koltunski
|
static final int[][] TABS =
|
40 |
7126b262
|
Leszek Koltunski
|
{
|
41 |
|
|
// Add here a new row to create another tab serving effects of a given type (you would also need to
|
42 |
|
|
// create a new layout to fill the first 3 values of the row ). Comment out a row to remove the tab.
|
43 |
|
|
//
|
44 |
d271024d
|
Leszek Koltunski
|
////// LAYOUT //////////// INNER LAYOUT //////// SPINNER ////////////// EFFECT_TYPE //////////////////// SHOW CENTER // SHOW REGION
|
45 |
|
|
{ R.layout.effects3dtab0, R.id.effects3dlayout0, R.id.effects3dspinner0, EffectType.MATRIX .ordinal() , 1, 0 } ,
|
46 |
|
|
{ R.layout.effects3dtab1, R.id.effects3dlayout1, R.id.effects3dspinner1, EffectType.VERTEX .ordinal() , 1, 1 } ,
|
47 |
|
|
{ R.layout.effects3dtab2, R.id.effects3dlayout2, R.id.effects3dspinner2, EffectType.FRAGMENT .ordinal() , 1, 0 } ,
|
48 |
|
|
{ R.layout.effects3dtab3, R.id.effects3dlayout3, R.id.effects3dspinner3, EffectType.POSTPROCESS.ordinal() , 0, 0 }
|
49 |
7126b262
|
Leszek Koltunski
|
};
|
50 |
1e7603bb
|
Leszek Koltunski
|
|
51 |
d271024d
|
Leszek Koltunski
|
private static final int NUM_TABS = TABS.length;
|
52 |
1e7603bb
|
Leszek Koltunski
|
|
53 |
|
|
private ViewPager mViewPager;
|
54 |
|
|
private int mCurrentTab;
|
55 |
|
|
|
56 |
2fad84a7
|
Leszek Koltunski
|
private static class GenericTabViewPager extends FragmentPagerAdapter
|
57 |
1e7603bb
|
Leszek Koltunski
|
{
|
58 |
|
|
GenericTabViewPager(FragmentManager fm)
|
59 |
|
|
{
|
60 |
|
|
super(fm);
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
@Override
|
64 |
2fad84a7
|
Leszek Koltunski
|
@NonNull
|
65 |
1e7603bb
|
Leszek Koltunski
|
public Fragment getItem(int position)
|
66 |
|
|
{
|
67 |
2fad84a7
|
Leszek Koltunski
|
GenericTab tab = new GenericTab();
|
68 |
1e7603bb
|
Leszek Koltunski
|
|
69 |
2fad84a7
|
Leszek Koltunski
|
Bundle bundle = new Bundle();
|
70 |
|
|
bundle.putInt("position", position);
|
71 |
|
|
tab.setArguments(bundle);
|
72 |
1e7603bb
|
Leszek Koltunski
|
|
73 |
2fad84a7
|
Leszek Koltunski
|
return tab;
|
74 |
1e7603bb
|
Leszek Koltunski
|
}
|
75 |
|
|
|
76 |
|
|
@Override
|
77 |
|
|
public int getCount()
|
78 |
|
|
{
|
79 |
|
|
return NUM_TABS;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
@Override
|
83 |
|
|
public CharSequence getPageTitle(int position)
|
84 |
|
|
{
|
85 |
d271024d
|
Leszek Koltunski
|
int ordinal = TABS[position][3];
|
86 |
1e7603bb
|
Leszek Koltunski
|
return EffectType.getType(ordinal).name();
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
|
|
GenericViewPager(AppCompatActivity act, int resourceID)
|
93 |
|
|
{
|
94 |
|
|
mViewPager = act.findViewById(resourceID);
|
95 |
|
|
mViewPager.setOffscreenPageLimit( NUM_TABS-1 );
|
96 |
|
|
GenericTabViewPager pager = new GenericTabViewPager( act.getSupportFragmentManager() );
|
97 |
|
|
mViewPager.setAdapter(pager);
|
98 |
|
|
|
99 |
|
|
mCurrentTab = 0;
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103 |
|
|
|
104 |
|
|
void showRegionAndCenter(boolean showR, boolean showC, GenericSurfaceView sv)
|
105 |
|
|
{
|
106 |
d271024d
|
Leszek Koltunski
|
boolean localShowC = (TABS[mCurrentTab][4] == 1);
|
107 |
|
|
boolean localShowR = (TABS[mCurrentTab][5] == 1);
|
108 |
1e7603bb
|
Leszek Koltunski
|
|
109 |
|
|
sv.getRenderer().showRegionAndCenter( (showR&&localShowR) , (showC&&localShowC) );
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
|
|
|
114 |
|
|
ViewPager getPager()
|
115 |
|
|
{
|
116 |
|
|
return mViewPager;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
|
121 |
|
|
void setCurrentTab(EffectType type)
|
122 |
|
|
{
|
123 |
d271024d
|
Leszek Koltunski
|
for(int tab=0; tab<NUM_TABS; tab++)
|
124 |
1e7603bb
|
Leszek Koltunski
|
{
|
125 |
d271024d
|
Leszek Koltunski
|
if( TABS[tab][3] == type.ordinal() )
|
126 |
1e7603bb
|
Leszek Koltunski
|
{
|
127 |
d271024d
|
Leszek Koltunski
|
mCurrentTab = tab;
|
128 |
1e7603bb
|
Leszek Koltunski
|
break;
|
129 |
|
|
}
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
|
|
}
|