Project

General

Profile

Download (5.29 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / generic / GenericViewPager.java @ f3ca895f

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2018 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// 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
// Distorted is distributed in the hope that it will be useful,                                  //
12
// 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
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.examples.generic;
21

    
22
import android.os.Bundle;
23
import android.support.v4.app.Fragment;
24
import android.support.v4.app.FragmentManager;
25
import android.support.v4.app.FragmentPagerAdapter;
26
import android.support.v4.view.ViewPager;
27
import android.support.v7.app.AppCompatActivity;
28

    
29
import org.distorted.examples.R;
30
import org.distorted.library.effect.EffectType;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
class GenericViewPager
35
  {
36
  static final int[][] TABS =
37
    {
38
    // Add here a new row to create another tab serving effects of a given type (you would also need to
39
    // create a new layout to fill the first 3 values of the row ). Comment out a row to remove the tab.
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 }
46
    };
47

    
48
  private static final int NUM_TABS = TABS.length;
49

    
50
  private ViewPager mViewPager;
51
  private int mCurrentTab;
52

    
53
  private class GenericTabViewPager extends FragmentPagerAdapter
54
    {
55
    GenericTabViewPager(FragmentManager fm)
56
      {
57
      super(fm);
58
      }
59

    
60
    @Override
61
    public Fragment getItem(int position)
62
      {
63
      if( position>=0 && position<NUM_TABS )
64
        {
65
        GenericTab tab = new GenericTab();
66

    
67
        Bundle bundle = new Bundle();
68
        bundle.putInt("position", position);
69
        tab.setArguments(bundle);
70

    
71
        return tab;
72
        }
73

    
74
      return null;
75
      }
76

    
77
    @Override
78
    public int getCount()
79
      {
80
      return NUM_TABS;
81
      }
82

    
83
    @Override
84
    public CharSequence getPageTitle(int position)
85
      {
86
      int ordinal = TABS[position][3];
87
      return EffectType.getType(ordinal).name();
88
      }
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  GenericViewPager(AppCompatActivity act, int resourceID)
94
    {
95
    mViewPager = act.findViewById(resourceID);
96
    mViewPager.setOffscreenPageLimit( NUM_TABS-1 );
97
    GenericTabViewPager pager = new GenericTabViewPager( act.getSupportFragmentManager() );
98
    mViewPager.setAdapter(pager);
99

    
100
    mCurrentTab = 0;
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  void showRegionAndCenter(boolean showR, boolean showC, GenericSurfaceView sv)
106
    {
107
    boolean localShowC = (TABS[mCurrentTab][4] == 1);
108
    boolean localShowR = (TABS[mCurrentTab][5] == 1);
109

    
110
    sv.getRenderer().showRegionAndCenter( (showR&&localShowR) , (showC&&localShowC) );
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  ViewPager getPager()
116
    {
117
    return mViewPager;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  void setCurrentTab(EffectType type)
123
    {
124
    for(int tab=0; tab<NUM_TABS; tab++)
125
      {
126
      if( TABS[tab][3] == type.ordinal() )
127
        {
128
        mCurrentTab = tab;
129
        break;
130
        }
131
      }
132
    }
133
  }
(7-7/7)