Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternView.java @ 318c0a7d

1 e108b57e 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 1f9772f3 Leszek Koltunski
package org.distorted.dialogs;
21 e108b57e Leszek Koltunski
22
import android.content.Context;
23 66e777b0 Leszek Koltunski
import androidx.fragment.app.FragmentActivity;
24 e108b57e Leszek Koltunski
import android.util.AttributeSet;
25
import android.view.View;
26 4debbf44 Leszek Koltunski
import android.widget.ExpandableListView;
27 e108b57e Leszek Koltunski
import android.widget.FrameLayout;
28
29 318c0a7d Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
30 3f7a4363 Leszek Koltunski
31 1f9772f3 Leszek Koltunski
import org.distorted.main.R;
32
import org.distorted.main.RubikActivity;
33 3a9d19ed Leszek Koltunski
import org.distorted.patterns.RubikPattern;
34 b498f3f6 Leszek Koltunski
import org.distorted.patterns.RubikPatternList;
35 fcd5b990 Leszek Koltunski
import org.distorted.screens.ScreenList;
36
import org.distorted.screens.RubikScreenPattern;
37 e108b57e Leszek Koltunski
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39
40 4debbf44 Leszek Koltunski
public class RubikDialogPatternView extends FrameLayout
41 e108b57e Leszek Koltunski
  {
42 4debbf44 Leszek Koltunski
  private ExpandableListView mListView;
43
  private RubikDialogPatternListAdapter mListAdapter;
44 e108b57e Leszek Koltunski
  private RubikDialogPattern mDialog;
45 044529c1 Leszek Koltunski
  private int mTab, mPos;
46 4debbf44 Leszek Koltunski
  private int mExpandedGroup;
47 e108b57e Leszek Koltunski
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 3a9d19ed Leszek Koltunski
  public RubikDialogPatternView(FragmentActivity act, RubikDialogPattern dialog, int position)
65 e108b57e Leszek Koltunski
    {
66
    super(act);
67
68 4debbf44 Leszek Koltunski
    final RubikActivity ract = (RubikActivity)getContext();
69 e108b57e Leszek Koltunski
70 4debbf44 Leszek Koltunski
    mTab = position;
71
    mDialog = dialog;
72 054fbee1 Leszek Koltunski
73
    RubikPattern pattern = RubikPattern.getInstance();
74
    mExpandedGroup = pattern.recallExpanded(position);
75 e108b57e Leszek Koltunski
76 4debbf44 Leszek Koltunski
    View tab = inflate( act, R.layout.dialog_pattern_tab, null);
77 3a9d19ed Leszek Koltunski
78 4debbf44 Leszek Koltunski
    mListView = tab.findViewById(R.id.patternListView);
79 054fbee1 Leszek Koltunski
    mListAdapter = new RubikDialogPatternListAdapter(act,mTab, ract.getScreenHeightInPixels());
80 4debbf44 Leszek Koltunski
    mListView.setAdapter(mListAdapter);
81 3a9d19ed Leszek Koltunski
82 054fbee1 Leszek Koltunski
    if( mExpandedGroup>=0 )
83
      {
84
      mListView.expandGroup(mExpandedGroup);
85
      }
86
87
    int visible = pattern.recallVisiblePos(mTab);
88
    mListView.setSelectionFromTop(visible,0);
89
90 4debbf44 Leszek Koltunski
    mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
91 3a9d19ed Leszek Koltunski
      {
92 4debbf44 Leszek Koltunski
      @Override
93
      public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
94
        {
95
        RubikPattern pattern = RubikPattern.getInstance();
96 a8576d91 Leszek Koltunski
        int[][] moves   = pattern.reInitialize(mTab, groupPosition, childPosition);
97 318c0a7d Leszek Koltunski
        ObjectType list = RubikPatternList.getObject(mTab);
98 3a9d19ed Leszek Koltunski
99 7ac0ee88 Leszek Koltunski
        ract.setupObject(list, moves);
100 3a9d19ed Leszek Koltunski
101 f5da732a Leszek Koltunski
        ScreenList.switchScreen(ract, ScreenList.PATT);
102
        RubikScreenPattern state = (RubikScreenPattern) ScreenList.PATT.getScreenClass();
103 4debbf44 Leszek Koltunski
        state.setPattern(ract, mTab, groupPosition, childPosition);
104 3a9d19ed Leszek Koltunski
105 4debbf44 Leszek Koltunski
        mDialog.rememberState();
106
        mDialog.dismiss();
107 3a9d19ed Leszek Koltunski
108 4debbf44 Leszek Koltunski
        return false;
109
        }
110
      });
111 3a9d19ed Leszek Koltunski
112 4debbf44 Leszek Koltunski
    mListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener()
113 e108b57e Leszek Koltunski
      {
114 4debbf44 Leszek Koltunski
      @Override
115
      public void onGroupExpand(int groupPosition)
116 e108b57e Leszek Koltunski
        {
117 4debbf44 Leszek Koltunski
        if(mExpandedGroup!=-1 && groupPosition!=mExpandedGroup)
118 e108b57e Leszek Koltunski
          {
119 4debbf44 Leszek Koltunski
          mListView.collapseGroup(mExpandedGroup);
120 e108b57e Leszek Koltunski
          }
121
122 4debbf44 Leszek Koltunski
        mExpandedGroup = groupPosition;
123
        }
124
      });
125
126
    addView(tab);
127 e108b57e Leszek Koltunski
    }
128 3a9d19ed Leszek Koltunski
129 044529c1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
130
131
  int getCurrentCategory()
132
    {
133
    return mPos;
134
    }
135
136 c715128d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
137
138 054fbee1 Leszek Koltunski
  int getCurrentVisiblePos()
139 c715128d Leszek Koltunski
    {
140 054fbee1 Leszek Koltunski
    return mListView.getFirstVisiblePosition();
141 c715128d Leszek Koltunski
    }
142
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
145 054fbee1 Leszek Koltunski
  int getExpanded()
146 c715128d Leszek Koltunski
    {
147 054fbee1 Leszek Koltunski
    return mExpandedGroup;
148 3a9d19ed Leszek Koltunski
    }
149 e108b57e Leszek Koltunski
  }