1 |
d18993ac
|
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.dialog;
|
21 |
|
|
|
22 |
|
|
import android.support.annotation.NonNull;
|
23 |
|
|
import android.support.v4.app.FragmentActivity;
|
24 |
|
|
import android.support.v4.view.PagerAdapter;
|
25 |
|
|
import android.support.v4.view.ViewPager;
|
26 |
|
|
import android.view.View;
|
27 |
|
|
import android.view.ViewGroup;
|
28 |
|
|
import android.widget.LinearLayout;
|
29 |
|
|
|
30 |
|
|
import org.distorted.patterns.RubikPattern;
|
31 |
|
|
|
32 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
|
|
class RubikDialogPatternPagerAdapter extends PagerAdapter
|
35 |
|
|
{
|
36 |
|
|
private FragmentActivity mAct;
|
37 |
|
|
private RubikDialogPatternView[] mViews;
|
38 |
|
|
private int mNumTabs;
|
39 |
|
|
|
40 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
// TODO: temporary mockup
|
42 |
|
|
|
43 |
|
|
private String[] createCategories(int pos)
|
44 |
|
|
{
|
45 |
|
|
String[] ret = new String[8];
|
46 |
|
|
|
47 |
|
|
for(int i=0; i<8; i++)
|
48 |
|
|
{
|
49 |
|
|
ret[i] = "CATEGORY "+pos+" "+i;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
return ret;
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56 |
|
|
|
57 |
|
|
RubikDialogPatternPagerAdapter(FragmentActivity act, ViewPager viewPager)
|
58 |
|
|
{
|
59 |
|
|
mAct = act;
|
60 |
|
|
mNumTabs = RubikPattern.NUM_CUBES;
|
61 |
|
|
mViews = new RubikDialogPatternView[mNumTabs];
|
62 |
|
|
|
63 |
|
|
viewPager.setAdapter(this);
|
64 |
|
|
viewPager.setOffscreenPageLimit(mNumTabs-1);
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68 |
|
|
|
69 |
|
|
@Override
|
70 |
|
|
@NonNull
|
71 |
|
|
public Object instantiateItem(@NonNull ViewGroup collection, final int position)
|
72 |
|
|
{
|
73 |
|
|
String[] categories = createCategories(position);
|
74 |
176308f8
|
Leszek Koltunski
|
mViews[position] = new RubikDialogPatternView(mAct, categories);
|
75 |
|
|
collection.addView(mViews[position]);
|
76 |
d18993ac
|
Leszek Koltunski
|
|
77 |
|
|
return mViews[position];
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81 |
|
|
|
82 |
|
|
@Override
|
83 |
|
|
public void destroyItem(ViewGroup collection, int position, @NonNull Object view)
|
84 |
|
|
{
|
85 |
|
|
collection.removeView((View) view);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89 |
|
|
|
90 |
|
|
@Override
|
91 |
|
|
public int getCount()
|
92 |
|
|
{
|
93 |
|
|
return mNumTabs;
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97 |
|
|
|
98 |
|
|
@Override
|
99 |
|
|
public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
|
100 |
|
|
{
|
101 |
|
|
return view == object;
|
102 |
|
|
}
|
103 |
|
|
}
|