| 1 |
e108b57e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
3a9d19ed
|
Leszek Koltunski
|
// Copyright 2020 Leszek Koltunski //
|
| 3 |
e108b57e
|
Leszek Koltunski
|
// //
|
| 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.app.Dialog;
|
| 23 |
|
|
import android.content.Context;
|
| 24 |
52d0a923
|
Leszek Koltunski
|
import android.content.DialogInterface;
|
| 25 |
e108b57e
|
Leszek Koltunski
|
import android.os.Bundle;
|
| 26 |
66e777b0
|
Leszek Koltunski
|
import androidx.annotation.NonNull;
|
| 27 |
|
|
import androidx.fragment.app.FragmentActivity;
|
| 28 |
|
|
import androidx.viewpager.widget.ViewPager;
|
| 29 |
|
|
import androidx.appcompat.app.AlertDialog;
|
| 30 |
|
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
| 31 |
|
|
import com.google.android.material.tabs.TabLayout;
|
| 32 |
e108b57e
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
| 33 |
52d0a923
|
Leszek Koltunski
|
import android.util.TypedValue;
|
| 34 |
e108b57e
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
| 35 |
|
|
import android.view.View;
|
| 36 |
6e3fcb91
|
Leszek Koltunski
|
import android.view.ViewGroup;
|
| 37 |
e108b57e
|
Leszek Koltunski
|
import android.view.Window;
|
| 38 |
|
|
import android.view.WindowManager;
|
| 39 |
52d0a923
|
Leszek Koltunski
|
import android.widget.Button;
|
| 40 |
e108b57e
|
Leszek Koltunski
|
import android.widget.ImageView;
|
| 41 |
|
|
import android.widget.TextView;
|
| 42 |
|
|
|
| 43 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
| 44 |
52d0a923
|
Leszek Koltunski
|
import org.distorted.main.RubikActivity;
|
| 45 |
d433b50e
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
| 46 |
|
|
import org.distorted.objects.RubikObjectList;
|
| 47 |
b498f3f6
|
Leszek Koltunski
|
import org.distorted.patterns.RubikPatternList;
|
| 48 |
52547ba7
|
Leszek Koltunski
|
import org.distorted.screens.RubikScreenPlay;
|
| 49 |
|
|
import org.distorted.screens.ScreenList;
|
| 50 |
e108b57e
|
Leszek Koltunski
|
|
| 51 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 52 |
|
|
|
| 53 |
|
|
public class RubikDialogPattern extends AppCompatDialogFragment
|
| 54 |
|
|
{
|
| 55 |
b88be423
|
Leszek Koltunski
|
private RubikDialogPatternPagerAdapter mPagerAdapter;
|
| 56 |
e108b57e
|
Leszek Koltunski
|
|
| 57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 58 |
|
|
|
| 59 |
|
|
@NonNull
|
| 60 |
|
|
@Override
|
| 61 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
| 62 |
|
|
{
|
| 63 |
a8576d91
|
Leszek Koltunski
|
final FragmentActivity act = getActivity();
|
| 64 |
e108b57e
|
Leszek Koltunski
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
| 65 |
|
|
|
| 66 |
52d0a923
|
Leszek Koltunski
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
| 67 |
|
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
| 68 |
6e3fcb91
|
Leszek Koltunski
|
|
| 69 |
|
|
int scrWidth = displaymetrics.widthPixels;
|
| 70 |
|
|
final float titleSize= scrWidth*RubikActivity.MENU_BIG_TEXT_SIZE;
|
| 71 |
|
|
final float okSize = scrWidth*RubikActivity.DIALOG_BUTTON_SIZE;
|
| 72 |
|
|
final int tabHeight= (int)(scrWidth*RubikActivity.TAB_HEIGHT);
|
| 73 |
|
|
final int tabWidth = (int)(scrWidth*RubikActivity.TAB_WIDTH);
|
| 74 |
52d0a923
|
Leszek Koltunski
|
|
| 75 |
e108b57e
|
Leszek Koltunski
|
LayoutInflater layoutInflater = act.getLayoutInflater();
|
| 76 |
|
|
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
|
| 77 |
52d0a923
|
Leszek Koltunski
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
| 78 |
6f2a942e
|
Leszek Koltunski
|
tv.setText(R.string.choose_pattern);
|
| 79 |
e108b57e
|
Leszek Koltunski
|
builder.setCustomTitle(tv);
|
| 80 |
|
|
|
| 81 |
a8576d91
|
Leszek Koltunski
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
| 82 |
|
|
{
|
| 83 |
|
|
@Override
|
| 84 |
|
|
public void onClick(DialogInterface dialog, int which)
|
| 85 |
|
|
{
|
| 86 |
|
|
|
| 87 |
|
|
}
|
| 88 |
|
|
});
|
| 89 |
|
|
|
| 90 |
e108b57e
|
Leszek Koltunski
|
LayoutInflater inflater = act.getLayoutInflater();
|
| 91 |
|
|
final View view = inflater.inflate(R.layout.dialog_tabbed, null);
|
| 92 |
|
|
builder.setView(view);
|
| 93 |
|
|
|
| 94 |
|
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
| 95 |
|
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
| 96 |
|
|
mPagerAdapter = new RubikDialogPatternPagerAdapter(act, viewPager, this);
|
| 97 |
|
|
tabLayout.setupWithViewPager(viewPager);
|
| 98 |
52547ba7
|
Leszek Koltunski
|
viewPager.setCurrentItem(getPatternOrdinal());
|
| 99 |
e108b57e
|
Leszek Koltunski
|
|
| 100 |
6e3fcb91
|
Leszek Koltunski
|
ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
|
| 101 |
|
|
|
| 102 |
b498f3f6
|
Leszek Koltunski
|
for(int i=0; i< RubikPatternList.NUM_OBJECTS; i++)
|
| 103 |
e108b57e
|
Leszek Koltunski
|
{
|
| 104 |
6e3fcb91
|
Leszek Koltunski
|
int ordinal = RubikPatternList.getObject(i);
|
| 105 |
d433b50e
|
Leszek Koltunski
|
RubikObject object = RubikObjectList.getObject(ordinal);
|
| 106 |
e108b57e
|
Leszek Koltunski
|
ImageView imageView = new ImageView(act);
|
| 107 |
eb985085
|
Leszek Koltunski
|
if( object!=null ) object.setIconTo(act,imageView);
|
| 108 |
6e3fcb91
|
Leszek Koltunski
|
imageView.setLayoutParams(paramsView);
|
| 109 |
e108b57e
|
Leszek Koltunski
|
TabLayout.Tab tab = tabLayout.getTabAt(i);
|
| 110 |
|
|
if(tab!=null) tab.setCustomView(imageView);
|
| 111 |
|
|
}
|
| 112 |
|
|
|
| 113 |
85248b04
|
Leszek Koltunski
|
Dialog dialog = builder.create();
|
| 114 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
| 115 |
|
|
Window window = dialog.getWindow();
|
| 116 |
|
|
|
| 117 |
|
|
if( window!=null )
|
| 118 |
|
|
{
|
| 119 |
ffd68f35
|
Leszek Koltunski
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
| 120 |
85248b04
|
Leszek Koltunski
|
}
|
| 121 |
|
|
|
| 122 |
52d0a923
|
Leszek Koltunski
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
| 123 |
|
|
{
|
| 124 |
|
|
@Override
|
| 125 |
|
|
public void onShow(DialogInterface dialog)
|
| 126 |
|
|
{
|
| 127 |
|
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
| 128 |
|
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
| 129 |
|
|
}
|
| 130 |
|
|
});
|
| 131 |
|
|
|
| 132 |
85248b04
|
Leszek Koltunski
|
return dialog;
|
| 133 |
e108b57e
|
Leszek Koltunski
|
}
|
| 134 |
|
|
|
| 135 |
52547ba7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 136 |
|
|
|
| 137 |
|
|
private int getPatternOrdinal()
|
| 138 |
|
|
{
|
| 139 |
400ff34d
|
Leszek Koltunski
|
int obj = RubikObjectList.getCurrObject();
|
| 140 |
52547ba7
|
Leszek Koltunski
|
int ret = RubikPatternList.getOrdinal(obj);
|
| 141 |
|
|
|
| 142 |
|
|
if( ret<0 )
|
| 143 |
|
|
{
|
| 144 |
400ff34d
|
Leszek Koltunski
|
ret = RubikPatternList.getOrdinal(RubikObjectList.DEF_OBJECT);
|
| 145 |
52547ba7
|
Leszek Koltunski
|
}
|
| 146 |
|
|
|
| 147 |
|
|
return ret;
|
| 148 |
|
|
}
|
| 149 |
|
|
|
| 150 |
e108b57e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 151 |
|
|
|
| 152 |
|
|
@Override
|
| 153 |
|
|
public void onResume()
|
| 154 |
|
|
{
|
| 155 |
|
|
super.onResume();
|
| 156 |
|
|
|
| 157 |
|
|
Window window = getDialog().getWindow();
|
| 158 |
|
|
Context context = getContext();
|
| 159 |
|
|
|
| 160 |
|
|
if( window!=null && context!=null )
|
| 161 |
|
|
{
|
| 162 |
|
|
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
| 163 |
|
|
final float height= metrics.heightPixels;
|
| 164 |
|
|
|
| 165 |
|
|
WindowManager.LayoutParams params = window.getAttributes();
|
| 166 |
|
|
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
| 167 |
|
|
params.height = (int)(0.75f*height);
|
| 168 |
|
|
window.setAttributes(params);
|
| 169 |
|
|
}
|
| 170 |
|
|
}
|
| 171 |
|
|
|
| 172 |
044529c1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 173 |
|
|
|
| 174 |
c715128d
|
Leszek Koltunski
|
public void rememberState()
|
| 175 |
044529c1
|
Leszek Koltunski
|
{
|
| 176 |
c715128d
|
Leszek Koltunski
|
mPagerAdapter.rememberState();
|
| 177 |
044529c1
|
Leszek Koltunski
|
}
|
| 178 |
|
|
|
| 179 |
e108b57e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 180 |
|
|
|
| 181 |
|
|
public static String getDialogTag()
|
| 182 |
|
|
{
|
| 183 |
|
|
return "DialogPattern";
|
| 184 |
|
|
}
|
| 185 |
|
|
}
|