Project

General

Profile

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

examples / src / main / java / org / distorted / examples / generic / GenericViewPager.java @ 2fad84a7

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

    
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

    
32
import org.distorted.examples.R;
33
import org.distorted.library.effect.EffectType;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
class GenericViewPager
38
  {
39
  static final int[][] TABS =
40
    {
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
    ////// 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
    };
50

    
51
  private static final int NUM_TABS = TABS.length;
52

    
53
  private ViewPager mViewPager;
54
  private int mCurrentTab;
55

    
56
  private static class GenericTabViewPager extends FragmentPagerAdapter
57
    {
58
    GenericTabViewPager(FragmentManager fm)
59
      {
60
      super(fm);
61
      }
62

    
63
    @Override
64
    @NonNull
65
    public Fragment getItem(int position)
66
      {
67
      GenericTab tab = new GenericTab();
68

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

    
73
      return tab;
74
      }
75

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

    
82
    @Override
83
    public CharSequence getPageTitle(int position)
84
      {
85
      int ordinal = TABS[position][3];
86
      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
    boolean localShowC = (TABS[mCurrentTab][4] == 1);
107
    boolean localShowR = (TABS[mCurrentTab][5] == 1);
108

    
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
    for(int tab=0; tab<NUM_TABS; tab++)
124
      {
125
      if( TABS[tab][3] == type.ordinal() )
126
        {
127
        mCurrentTab = tab;
128
        break;
129
        }
130
      }
131
    }
132
  }
(8-8/8)