Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogTutorialPagerAdapter.java @ eaf87d1d

1 234a7582 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 5b4eaf7e Leszek Koltunski
import android.util.DisplayMetrics;
23 234a7582 Leszek Koltunski
import android.view.View;
24
import android.view.ViewGroup;
25
26
import androidx.annotation.NonNull;
27
import androidx.fragment.app.FragmentActivity;
28
import androidx.viewpager.widget.PagerAdapter;
29
import androidx.viewpager.widget.ViewPager;
30
31 eaf87d1d Leszek Koltunski
import org.distorted.tutorials.TutorialList;
32 234a7582 Leszek Koltunski
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35
class RubikDialogTutorialPagerAdapter extends PagerAdapter
36
  {
37 3329a277 Leszek Koltunski
  private final FragmentActivity mAct;
38
  private final RubikDialogTutorialView[] mViews;
39
  private final int mNumTabs;
40 234a7582 Leszek Koltunski
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 5b4eaf7e Leszek Koltunski
  RubikDialogTutorialPagerAdapter(FragmentActivity act, ViewPager viewPager)
44 234a7582 Leszek Koltunski
    {
45 3329a277 Leszek Koltunski
    mAct     = act;
46 234a7582 Leszek Koltunski
    mNumTabs = TutorialList.NUM_OBJECTS;
47 3329a277 Leszek Koltunski
    mViews   = new RubikDialogTutorialView[mNumTabs];
48 234a7582 Leszek Koltunski
49
    viewPager.setAdapter(this);
50 3329a277 Leszek Koltunski
    viewPager.setOffscreenPageLimit(1);
51 234a7582 Leszek Koltunski
    }
52
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
55
  @Override
56
  @NonNull
57
  public Object instantiateItem(@NonNull ViewGroup collection, final int position)
58
    {
59 5b4eaf7e Leszek Koltunski
    DisplayMetrics metrics = mAct.getResources().getDisplayMetrics();
60
61 ef1f3e34 Leszek Koltunski
    mViews[position] = new RubikDialogTutorialView(mAct, metrics.widthPixels, position);
62 234a7582 Leszek Koltunski
    collection.addView(mViews[position]);
63
64
    return mViews[position];
65
    }
66
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69
  @Override
70
  public void destroyItem(ViewGroup collection, int position, @NonNull Object view)
71
    {
72
    collection.removeView((View) view);
73
    }
74
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
77
  @Override
78
  public int getCount()
79
    {
80
    return mNumTabs;
81
    }
82
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
85
  @Override
86
  public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
87
    {
88
    return view == object;
89
    }
90
  }