| 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 |
|
|
import android.os.Bundle;
|
| 25 |
66e777b0
|
Leszek Koltunski
|
import androidx.annotation.NonNull;
|
| 26 |
|
|
import androidx.fragment.app.FragmentActivity;
|
| 27 |
|
|
import androidx.viewpager.widget.ViewPager;
|
| 28 |
|
|
import androidx.appcompat.app.AlertDialog;
|
| 29 |
|
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
| 30 |
|
|
import com.google.android.material.tabs.TabLayout;
|
| 31 |
e108b57e
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
| 32 |
|
|
import android.view.LayoutInflater;
|
| 33 |
|
|
import android.view.View;
|
| 34 |
|
|
import android.view.Window;
|
| 35 |
|
|
import android.view.WindowManager;
|
| 36 |
|
|
import android.widget.ImageView;
|
| 37 |
|
|
import android.widget.TextView;
|
| 38 |
|
|
|
| 39 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
| 40 |
|
|
import org.distorted.objects.RubikObjectList;
|
| 41 |
b498f3f6
|
Leszek Koltunski
|
import org.distorted.patterns.RubikPatternList;
|
| 42 |
e108b57e
|
Leszek Koltunski
|
|
| 43 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 44 |
|
|
|
| 45 |
|
|
public class RubikDialogPattern extends AppCompatDialogFragment
|
| 46 |
|
|
{
|
| 47 |
|
|
RubikDialogPatternPagerAdapter mPagerAdapter;
|
| 48 |
|
|
|
| 49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 50 |
|
|
|
| 51 |
|
|
@Override
|
| 52 |
|
|
public void onStart()
|
| 53 |
|
|
{
|
| 54 |
|
|
super.onStart();
|
| 55 |
|
|
|
| 56 |
584585d0
|
Leszek Koltunski
|
Dialog dialog = getDialog();
|
| 57 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
| 58 |
|
|
|
| 59 |
|
|
Window window = dialog.getWindow();
|
| 60 |
|
|
|
| 61 |
|
|
if( window!=null )
|
| 62 |
|
|
{
|
| 63 |
|
|
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
|
| 64 |
|
|
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
|
| 65 |
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
| 66 |
|
|
}
|
| 67 |
e108b57e
|
Leszek Koltunski
|
}
|
| 68 |
|
|
|
| 69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 70 |
|
|
|
| 71 |
|
|
@NonNull
|
| 72 |
|
|
@Override
|
| 73 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
| 74 |
|
|
{
|
| 75 |
|
|
FragmentActivity act = getActivity();
|
| 76 |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
| 77 |
|
|
|
| 78 |
|
|
LayoutInflater layoutInflater = act.getLayoutInflater();
|
| 79 |
|
|
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
|
| 80 |
6f2a942e
|
Leszek Koltunski
|
tv.setText(R.string.choose_pattern);
|
| 81 |
e108b57e
|
Leszek Koltunski
|
builder.setCustomTitle(tv);
|
| 82 |
|
|
|
| 83 |
|
|
Bundle args = getArguments();
|
| 84 |
|
|
int curTab;
|
| 85 |
|
|
|
| 86 |
|
|
try
|
| 87 |
|
|
{
|
| 88 |
|
|
curTab = args.getInt("tab");
|
| 89 |
|
|
}
|
| 90 |
|
|
catch(Exception e)
|
| 91 |
|
|
{
|
| 92 |
|
|
curTab = 0;
|
| 93 |
|
|
}
|
| 94 |
|
|
|
| 95 |
|
|
LayoutInflater inflater = act.getLayoutInflater();
|
| 96 |
|
|
final View view = inflater.inflate(R.layout.dialog_tabbed, null);
|
| 97 |
|
|
builder.setView(view);
|
| 98 |
|
|
|
| 99 |
|
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
| 100 |
|
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
| 101 |
|
|
mPagerAdapter = new RubikDialogPatternPagerAdapter(act, viewPager, this);
|
| 102 |
|
|
tabLayout.setupWithViewPager(viewPager);
|
| 103 |
|
|
viewPager.setCurrentItem(curTab);
|
| 104 |
|
|
|
| 105 |
b498f3f6
|
Leszek Koltunski
|
for(int i=0; i< RubikPatternList.NUM_OBJECTS; i++)
|
| 106 |
e108b57e
|
Leszek Koltunski
|
{
|
| 107 |
b498f3f6
|
Leszek Koltunski
|
RubikObjectList list = RubikPatternList.getObject(i);
|
| 108 |
|
|
int size = RubikPatternList.getSize(i);
|
| 109 |
|
|
int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),size);
|
| 110 |
|
|
int iconID = list.getIconIDs()[sizeIndex];
|
| 111 |
|
|
|
| 112 |
e108b57e
|
Leszek Koltunski
|
ImageView imageView = new ImageView(act);
|
| 113 |
b498f3f6
|
Leszek Koltunski
|
imageView.setImageResource(iconID);
|
| 114 |
e108b57e
|
Leszek Koltunski
|
TabLayout.Tab tab = tabLayout.getTabAt(i);
|
| 115 |
|
|
if(tab!=null) tab.setCustomView(imageView);
|
| 116 |
|
|
}
|
| 117 |
|
|
|
| 118 |
|
|
return builder.create();
|
| 119 |
|
|
}
|
| 120 |
|
|
|
| 121 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 122 |
|
|
|
| 123 |
|
|
@Override
|
| 124 |
|
|
public void onResume()
|
| 125 |
|
|
{
|
| 126 |
|
|
super.onResume();
|
| 127 |
|
|
|
| 128 |
|
|
Window window = getDialog().getWindow();
|
| 129 |
|
|
Context context = getContext();
|
| 130 |
|
|
|
| 131 |
|
|
if( window!=null && context!=null )
|
| 132 |
|
|
{
|
| 133 |
|
|
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
| 134 |
|
|
final float height= metrics.heightPixels;
|
| 135 |
|
|
|
| 136 |
|
|
WindowManager.LayoutParams params = window.getAttributes();
|
| 137 |
|
|
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
| 138 |
|
|
params.height = (int)(0.75f*height);
|
| 139 |
|
|
window.setAttributes(params);
|
| 140 |
|
|
}
|
| 141 |
|
|
}
|
| 142 |
|
|
|
| 143 |
044529c1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 144 |
|
|
|
| 145 |
c715128d
|
Leszek Koltunski
|
public void rememberState()
|
| 146 |
044529c1
|
Leszek Koltunski
|
{
|
| 147 |
c715128d
|
Leszek Koltunski
|
mPagerAdapter.rememberState();
|
| 148 |
044529c1
|
Leszek Koltunski
|
}
|
| 149 |
|
|
|
| 150 |
e108b57e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 151 |
|
|
|
| 152 |
|
|
public static String getDialogTag()
|
| 153 |
|
|
{
|
| 154 |
|
|
return "DialogPattern";
|
| 155 |
|
|
}
|
| 156 |
|
|
}
|