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