Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogTutorialPagerAdapter.java @ 83018ac4

1 234a7582 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 68191e7d Leszek Koltunski
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8 234a7582 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.dialogs;
11
12 5b4eaf7e Leszek Koltunski
import android.util.DisplayMetrics;
13 234a7582 Leszek Koltunski
import android.view.View;
14
import android.view.ViewGroup;
15
16
import androidx.annotation.NonNull;
17
import androidx.fragment.app.FragmentActivity;
18
import androidx.viewpager.widget.PagerAdapter;
19
import androidx.viewpager.widget.ViewPager;
20
21 804293f0 Leszek Koltunski
import org.distorted.objects.RubikObjectList;
22 234a7582 Leszek Koltunski
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24
25
class RubikDialogTutorialPagerAdapter extends PagerAdapter
26
  {
27 3329a277 Leszek Koltunski
  private final FragmentActivity mAct;
28
  private final RubikDialogTutorialView[] mViews;
29
  private final int mNumTabs;
30 234a7582 Leszek Koltunski
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 5b4eaf7e Leszek Koltunski
  RubikDialogTutorialPagerAdapter(FragmentActivity act, ViewPager viewPager)
34 234a7582 Leszek Koltunski
    {
35 3329a277 Leszek Koltunski
    mAct     = act;
36 804293f0 Leszek Koltunski
    mNumTabs = RubikObjectList.getNumTutorialObjects();
37 3329a277 Leszek Koltunski
    mViews   = new RubikDialogTutorialView[mNumTabs];
38 234a7582 Leszek Koltunski
39
    viewPager.setAdapter(this);
40 3329a277 Leszek Koltunski
    viewPager.setOffscreenPageLimit(1);
41 234a7582 Leszek Koltunski
    }
42
43 a84c3a25 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45
  void clickPossible()
46
    {
47
    for(int i=0; i<mNumTabs; i++)
48
      {
49
      if( mViews[i]!=null )
50
        {
51
        mViews[i].clickPossible(true);
52
        }
53
      }
54
    }
55
56 234a7582 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58
  @Override
59
  @NonNull
60
  public Object instantiateItem(@NonNull ViewGroup collection, final int position)
61
    {
62 5b4eaf7e Leszek Koltunski
    DisplayMetrics metrics = mAct.getResources().getDisplayMetrics();
63
64 ef1f3e34 Leszek Koltunski
    mViews[position] = new RubikDialogTutorialView(mAct, metrics.widthPixels, position);
65 234a7582 Leszek Koltunski
    collection.addView(mViews[position]);
66
67
    return mViews[position];
68
    }
69
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
72
  @Override
73
  public void destroyItem(ViewGroup collection, int position, @NonNull Object view)
74
    {
75
    collection.removeView((View) view);
76
    }
77
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
80
  @Override
81
  public int getCount()
82
    {
83
    return mNumTabs;
84
    }
85
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87
88
  @Override
89
  public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
90
    {
91
    return view == object;
92
    }
93
  }