Project

General

Profile

Download (3.93 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / dialogs / RubikDialogTutorialPagerAdapter.java @ 234a7582

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube 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
// Magic Cube 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 Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.dialogs;
21

    
22
import android.view.View;
23
import android.view.ViewGroup;
24

    
25
import androidx.annotation.NonNull;
26
import androidx.fragment.app.FragmentActivity;
27
import androidx.viewpager.widget.PagerAdapter;
28
import androidx.viewpager.widget.ViewPager;
29

    
30
import org.distorted.tutorial.TutorialList;
31

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

    
34
class RubikDialogTutorialPagerAdapter extends PagerAdapter
35
  {
36
  private FragmentActivity mAct;
37
  private RubikDialogTutorialView[] mViews;
38
  private RubikDialogTutorial mDialog;
39
  private int mNumTabs;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  RubikDialogTutorialPagerAdapter(FragmentActivity act, ViewPager viewPager, RubikDialogTutorial dialog)
44
    {
45
    mAct = act;
46
    mDialog = dialog;
47
    mNumTabs = TutorialList.NUM_OBJECTS;
48
    mViews = new RubikDialogTutorialView[mNumTabs];
49

    
50
    viewPager.setAdapter(this);
51
    viewPager.setOffscreenPageLimit(mNumTabs-1);
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  void rememberState()
57
    {
58
    // TODO
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  @Override
64
  @NonNull
65
  public Object instantiateItem(@NonNull ViewGroup collection, final int position)
66
    {
67
    mViews[position] = new RubikDialogTutorialView(mAct, mDialog, position);
68
    collection.addView(mViews[position]);
69

    
70
    return mViews[position];
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  @Override
76
  public void destroyItem(ViewGroup collection, int position, @NonNull Object view)
77
    {
78
    collection.removeView((View) view);
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  @Override
84
  public int getCount()
85
    {
86
    return mNumTabs;
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  @Override
92
  public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
93
    {
94
    return view == object;
95
    }
96
  }
(17-17/18)