1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2023 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.app.Dialog;
|
13
|
import android.view.View;
|
14
|
import android.view.Window;
|
15
|
import android.view.WindowManager;
|
16
|
import android.widget.ExpandableListView;
|
17
|
|
18
|
import androidx.fragment.app.FragmentActivity;
|
19
|
|
20
|
import org.distorted.main.R;
|
21
|
import org.distorted.objectlib.main.ObjectControl;
|
22
|
import org.distorted.objectlib.patterns.RubikPattern;
|
23
|
import org.distorted.objectlib.patterns.RubikPatternList;
|
24
|
import org.distorted.objects.RubikObjectList;
|
25
|
import org.distorted.patternui.PatternActivity;
|
26
|
import org.distorted.patternui.ScreenList;
|
27
|
import org.distorted.patternui.ScreenPattern;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
public class RubikDialogPatternSingle extends RubikDialogAbstract
|
32
|
{
|
33
|
private ExpandableListView mListView;
|
34
|
private int mPatternOrdinal, mPos;
|
35
|
private int mExpandedGroup;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
@Override
|
40
|
public void onResume()
|
41
|
{
|
42
|
super.onResume();
|
43
|
|
44
|
Window window = getDialog().getWindow();
|
45
|
|
46
|
if( window!=null )
|
47
|
{
|
48
|
WindowManager.LayoutParams params = window.getAttributes();
|
49
|
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.98f );
|
50
|
//params.height = (int)Math.min( mHeight*0.80f,mWidth*1.30f );
|
51
|
window.setAttributes(params);
|
52
|
}
|
53
|
}
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
public int getResource() { return R.layout.dialog_pattern_single; }
|
58
|
public int getTitleResource() { return R.string.choose_pattern; }
|
59
|
public boolean hasArgument() { return true; }
|
60
|
public int getPositive() { return -1; }
|
61
|
public int getNegative() { return -1; }
|
62
|
public void positiveAction() { }
|
63
|
public void negativeAction() { }
|
64
|
|
65
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66
|
|
67
|
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
|
68
|
{
|
69
|
int objectOrdinal = RubikObjectList.getOrdinal(mArgument);
|
70
|
|
71
|
if( objectOrdinal<0 )
|
72
|
{
|
73
|
android.util.Log.e("D", "object "+mArgument+" not found");
|
74
|
return;
|
75
|
}
|
76
|
|
77
|
mPatternOrdinal = RubikPatternList.getOrdinal(objectOrdinal);
|
78
|
|
79
|
if( mPatternOrdinal<0 )
|
80
|
{
|
81
|
android.util.Log.e("D", "patterns for object "+mArgument+" not found");
|
82
|
return;
|
83
|
}
|
84
|
|
85
|
android.util.Log.e("D", "prepareBody: object "+mArgument);
|
86
|
|
87
|
final PatternActivity pact = (PatternActivity)getContext();
|
88
|
int width = pact!=null ? pact.getScreenWidthInPixels() : 100;
|
89
|
final ObjectControl control = pact!=null ? pact.getControl() : null;
|
90
|
|
91
|
RubikPattern pattern = RubikPattern.getInstance();
|
92
|
mExpandedGroup = pattern.recallExpanded(mPatternOrdinal);
|
93
|
|
94
|
mListView = view.findViewById(R.id.patternListView);
|
95
|
RubikDialogPatternListAdapter listAdapter = new RubikDialogPatternListAdapter(act,mPatternOrdinal,width);
|
96
|
mListView.setAdapter(listAdapter);
|
97
|
|
98
|
if( mExpandedGroup>=0 ) mListView.expandGroup(mExpandedGroup);
|
99
|
|
100
|
int visible = pattern.recallVisiblePos(mPatternOrdinal);
|
101
|
mListView.setSelectionFromTop(visible,0);
|
102
|
|
103
|
mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
|
104
|
{
|
105
|
@Override
|
106
|
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
|
107
|
{
|
108
|
RubikPattern pattern = RubikPattern.getInstance();
|
109
|
int[][] moves = pattern.reInitialize(mPatternOrdinal, groupPosition, childPosition);
|
110
|
if( control!=null ) control.initializeObject(moves);
|
111
|
|
112
|
ScreenPattern state = (ScreenPattern) ScreenList.PATT.getScreenClass();
|
113
|
state.setPattern(pact, mPatternOrdinal, groupPosition, childPosition);
|
114
|
|
115
|
rememberState();
|
116
|
dismiss();
|
117
|
|
118
|
return false;
|
119
|
}
|
120
|
});
|
121
|
|
122
|
mListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener()
|
123
|
{
|
124
|
@Override
|
125
|
public void onGroupExpand(int groupPosition)
|
126
|
{
|
127
|
if(mExpandedGroup!=-1 && groupPosition!=mExpandedGroup)
|
128
|
{
|
129
|
mListView.collapseGroup(mExpandedGroup);
|
130
|
}
|
131
|
|
132
|
mExpandedGroup = groupPosition;
|
133
|
}
|
134
|
});
|
135
|
}
|
136
|
|
137
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138
|
|
139
|
private void rememberState()
|
140
|
{
|
141
|
RubikPattern pattern = RubikPattern.getInstance();
|
142
|
pattern.rememberState(mPatternOrdinal,mPos,mListView.getFirstVisiblePosition(),mExpandedGroup);
|
143
|
}
|
144
|
|
145
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146
|
|
147
|
public static String getDialogTag()
|
148
|
{
|
149
|
return "DialogPatternSingle";
|
150
|
}
|
151
|
}
|