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