Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.dialogs;
11

    
12
import android.util.DisplayMetrics;
13
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
import org.distorted.objects.RubikObjectList;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

    
25
class RubikDialogTutorialPagerAdapter extends PagerAdapter
26
  {
27
  private final FragmentActivity mAct;
28
  private final RubikDialogTutorialView[] mViews;
29
  private final int mNumTabs;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
  RubikDialogTutorialPagerAdapter(FragmentActivity act, ViewPager viewPager)
34
    {
35
    mAct     = act;
36
    mNumTabs = RubikObjectList.getNumTutorialObjects();
37
    mViews   = new RubikDialogTutorialView[mNumTabs];
38

    
39
    viewPager.setAdapter(this);
40
    viewPager.setOffscreenPageLimit(1);
41
    }
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  @Override
59
  @NonNull
60
  public Object instantiateItem(@NonNull ViewGroup collection, final int position)
61
    {
62
    DisplayMetrics metrics = mAct.getResources().getDisplayMetrics();
63

    
64
    mViews[position] = new RubikDialogTutorialView(mAct, metrics.heightPixels, position);
65
    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
    mViews[position] = null;
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  @Override
90
  public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
91
    {
92
    return view == object;
93
    }
94
  }
(29-29/32)