Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effects3d / Effects3DTabViewPager.java @ c2c45d0a

1 fe7fe83e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.effects3d;
21
22 c2c45d0a Leszek Koltunski
import android.support.v4.app.Fragment;
23
import android.support.v4.app.FragmentManager;
24
import android.support.v4.app.FragmentPagerAdapter;
25 fe7fe83e Leszek Koltunski
import android.view.View;
26 c2c45d0a Leszek Koltunski
import android.os.Bundle;
27 fe7fe83e Leszek Koltunski
28
import org.distorted.examples.R;
29
30
import java.lang.ref.WeakReference;
31
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34
public class Effects3DTabViewPager extends FragmentPagerAdapter
35
  {
36
  private static final int NUM_TABS = 3;
37
38 348dbeea Leszek Koltunski
  private WeakReference<Effects3DActivity2> mAct;
39 fe7fe83e Leszek Koltunski
  private Effects3DTab[] mTab;
40
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 348dbeea Leszek Koltunski
  public Effects3DTabViewPager(Effects3DActivity2 act, FragmentManager fm)
44 fe7fe83e Leszek Koltunski
    {
45
    super(fm);
46
    mAct = new WeakReference<>(act);
47
    mTab = new Effects3DTab[NUM_TABS];
48 cf6fb87f Leszek Koltunski
49
    android.util.Log.e("viewPager"," CONSTRUCTOR ");
50 fe7fe83e Leszek Koltunski
    }
51
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
54
  void newEffect(View v, int pos)
55
    {
56
    if( pos>=0 && pos<NUM_TABS ) mTab[pos].newEffect();
57
    }
58
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61
  void removeAll(View v, int pos)
62
    {
63
    if( pos>=0 && pos<NUM_TABS ) mTab[pos].removeAll();
64
    }
65
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
68
  void remove(View v, int pos)
69
    {
70
    if( pos>=0 && pos<NUM_TABS ) mTab[pos].remove(v);
71
    }
72
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
75
  @Override
76
  public Fragment getItem(int position)
77
    {
78
    android.util.Log.e("viewPager","creating tab "+position);
79
80 cf6fb87f Leszek Koltunski
    if( position>=0 && position<NUM_TABS )
81 fe7fe83e Leszek Koltunski
      {
82 cf6fb87f Leszek Koltunski
      Bundle bundle = new Bundle();
83
      bundle.putInt("position", position);
84
85
      mTab[position] = new Effects3DTab();
86
      mTab[position].setArguments(bundle);
87
      return mTab[position];
88 fe7fe83e Leszek Koltunski
      }
89 cf6fb87f Leszek Koltunski
90
    return null;
91 fe7fe83e Leszek Koltunski
    }
92
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
95
  @Override
96
  public int getCount()
97
    {
98
    return NUM_TABS;
99
    }
100
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
103
  @Override
104
  public CharSequence getPageTitle(int position)
105
    {
106
    switch (position)
107
      {
108
      case 0 : return mAct.get().getString(R.string.type_vertex);
109
      case 1 : return mAct.get().getString(R.string.type_fragment);
110
      case 2 : return mAct.get().getString(R.string.type_postprocess);
111
      default: return null;
112
      }
113
    }
114
  }