Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternView.java @ 3f7a4363

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.content.Context;
23
import androidx.fragment.app.FragmentActivity;
24
import android.util.AttributeSet;
25
import android.view.View;
26
import android.widget.ExpandableListView;
27
import android.widget.FrameLayout;
28

    
29
import org.distorted.objectlib.main.ObjectList;
30

    
31
import org.distorted.main.R;
32
import org.distorted.main.RubikActivity;
33
import org.distorted.patterns.RubikPattern;
34
import org.distorted.patterns.RubikPatternList;
35
import org.distorted.screens.ScreenList;
36
import org.distorted.screens.RubikScreenPattern;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class RubikDialogPatternView extends FrameLayout
41
  {
42
  private ExpandableListView mListView;
43
  private RubikDialogPatternListAdapter mListAdapter;
44
  private RubikDialogPattern mDialog;
45
  private int mTab, mPos;
46
  private int mExpandedGroup;
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  public RubikDialogPatternView(Context context, AttributeSet attrs, int defStyle)
51
    {
52
    super(context, attrs, defStyle);
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  public RubikDialogPatternView(Context context, AttributeSet attrs)
58
    {
59
    super(context, attrs);
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  public RubikDialogPatternView(FragmentActivity act, RubikDialogPattern dialog, int position)
65
    {
66
    super(act);
67

    
68
    final RubikActivity ract = (RubikActivity)getContext();
69

    
70
    mTab = position;
71
    mDialog = dialog;
72

    
73
    RubikPattern pattern = RubikPattern.getInstance();
74
    mExpandedGroup = pattern.recallExpanded(position);
75

    
76
    View tab = inflate( act, R.layout.dialog_pattern_tab, null);
77

    
78
    mListView = tab.findViewById(R.id.patternListView);
79
    mListAdapter = new RubikDialogPatternListAdapter(act,mTab, ract.getScreenHeightInPixels());
80
    mListView.setAdapter(mListAdapter);
81

    
82
    if( mExpandedGroup>=0 )
83
      {
84
      mListView.expandGroup(mExpandedGroup);
85
      }
86

    
87
    int visible = pattern.recallVisiblePos(mTab);
88
    mListView.setSelectionFromTop(visible,0);
89

    
90
    mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
91
      {
92
      @Override
93
      public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
94
        {
95
        RubikPattern pattern = RubikPattern.getInstance();
96
        int[][] moves   = pattern.reInitialize(mTab, groupPosition, childPosition);
97
        ObjectList list = RubikPatternList.getObject(mTab);
98
        int size        = RubikPatternList.getSize(mTab);
99

    
100
        ract.setupObject(list, size, moves);
101

    
102
        ScreenList.switchScreen(ract, ScreenList.PATT);
103
        RubikScreenPattern state = (RubikScreenPattern) ScreenList.PATT.getScreenClass();
104
        state.setPattern(ract, mTab, groupPosition, childPosition);
105

    
106
        mDialog.rememberState();
107
        mDialog.dismiss();
108

    
109
        return false;
110
        }
111
      });
112

    
113
    mListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener()
114
      {
115
      @Override
116
      public void onGroupExpand(int groupPosition)
117
        {
118
        if(mExpandedGroup!=-1 && groupPosition!=mExpandedGroup)
119
          {
120
          mListView.collapseGroup(mExpandedGroup);
121
          }
122

    
123
        mExpandedGroup = groupPosition;
124
        }
125
      });
126

    
127
    addView(tab);
128
    }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
  int getCurrentCategory()
133
    {
134
    return mPos;
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  int getCurrentVisiblePos()
140
    {
141
    return mListView.getFirstVisiblePosition();
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  int getExpanded()
147
    {
148
    return mExpandedGroup;
149
    }
150
  }
(9-9/19)