Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternView.java @ 4debbf44

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.main.R;
30
import org.distorted.main.RubikActivity;
31
import org.distorted.objects.RubikObjectList;
32
import org.distorted.patterns.RubikPattern;
33
import org.distorted.patterns.RubikPatternList;
34
import org.distorted.states.RubikState;
35
import org.distorted.states.RubikStatePattern;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

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

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

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

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

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

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

    
69
    mTab = position;
70
    mDialog = dialog;
71
    mExpandedGroup = -1;
72

    
73
    View tab = inflate( act, R.layout.dialog_pattern_tab, null);
74

    
75
    mListView = tab.findViewById(R.id.patternListView);
76
    mListAdapter = new RubikDialogPatternListAdapter(act,mTab);
77
    mListView.setAdapter(mListAdapter);
78

    
79
    mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
80
      {
81
      @Override
82
      public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
83
        {
84
        RubikPattern pattern = RubikPattern.getInstance();
85
        int[][] moves = pattern.reInitialize(mTab, groupPosition, childPosition);
86

    
87
        RubikObjectList list = RubikPatternList.getObject(mTab);
88
        int size             = RubikPatternList.getSize(mTab);
89

    
90
        ract.setupObject(list, size, moves);
91

    
92
        RubikStatePattern state = (RubikStatePattern) RubikState.PATT.getStateClass();
93

    
94
        state.setPattern(ract, mTab, groupPosition, childPosition);
95

    
96
        mDialog.rememberState();
97
        mDialog.dismiss();
98

    
99
        return false;
100
        }
101
      });
102

    
103
    mListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener()
104
      {
105
      @Override
106
      public void onGroupExpand(int groupPosition)
107
        {
108
        if(mExpandedGroup!=-1 && groupPosition!=mExpandedGroup)
109
          {
110
          mListView.collapseGroup(mExpandedGroup);
111
          }
112

    
113
        mExpandedGroup = groupPosition;
114
        }
115
      });
116

    
117
    addView(tab);
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  int getCurrentCategory()
123
    {
124
    return mPos;
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  int getCurrentScrollPos()
130
    {
131
    return 0;//mScroll.getScrollY();
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
  @Override
137
  protected void onLayout(boolean changed, int left, int top, int right, int bottom)
138
    {
139
    super.onLayout(changed,left,top,right,bottom);
140
/*
141
    if( !changed )
142
      {
143
      final RubikPattern pattern = RubikPattern.getInstance();
144
      mScroll.setScrollY( pattern.recallScrollPos(mTab) );
145
      }
146
 */
147
    }
148
  }
(8-8/14)