Revision f8a21f6b
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/dialogs/RubikDialogTutorial.java | ||
---|---|---|
10 | 10 |
package org.distorted.dialogs; |
11 | 11 |
|
12 | 12 |
import android.app.Dialog; |
13 |
import android.content.Context; |
|
14 |
import android.content.DialogInterface; |
|
15 |
import android.os.Bundle; |
|
16 |
import android.util.DisplayMetrics; |
|
17 |
import android.util.TypedValue; |
|
18 |
import android.view.LayoutInflater; |
|
19 | 13 |
import android.view.View; |
20 | 14 |
import android.view.ViewGroup; |
21 | 15 |
import android.view.Window; |
22 | 16 |
import android.view.WindowManager; |
23 |
import android.widget.Button; |
|
24 | 17 |
import android.widget.ImageView; |
25 |
import android.widget.TextView; |
|
26 | 18 |
|
27 |
import androidx.annotation.NonNull; |
|
28 |
import androidx.appcompat.app.AlertDialog; |
|
29 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
30 | 19 |
import androidx.fragment.app.FragmentActivity; |
31 | 20 |
import androidx.viewpager.widget.ViewPager; |
32 | 21 |
|
... | ... | |
39 | 28 |
|
40 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | 30 |
|
42 |
public class RubikDialogTutorial extends AppCompatDialogFragment
|
|
31 |
public class RubikDialogTutorial extends RubikDialogAbstract
|
|
43 | 32 |
{ |
44 | 33 |
private RubikDialogTutorialPagerAdapter mPagerAdapter; |
45 | 34 |
|
46 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
47 | 36 |
|
48 |
@NonNull |
|
49 | 37 |
@Override |
50 |
public Dialog onCreateDialog(Bundle savedInstanceState)
|
|
38 |
public void onResume()
|
|
51 | 39 |
{ |
52 |
final FragmentActivity act = getActivity(); |
|
53 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
54 |
|
|
55 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
56 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
40 |
super.onResume(); |
|
57 | 41 |
|
58 |
int h = displaymetrics.heightPixels; |
|
59 |
final float titleSize= h*RubikActivity.TAB_TEXT_SIZE; |
|
60 |
final float okSize = h*RubikActivity.TAB_BUTTON_SIZE; |
|
61 |
final int tabHeight= (int)(h*RubikActivity.TAB_HEIGHT); |
|
62 |
final int tabWidth = (int)(h*RubikActivity.TAB_WIDTH); |
|
42 |
if( mPagerAdapter!=null ) mPagerAdapter.clickPossible(); |
|
63 | 43 |
|
64 |
LayoutInflater layoutInflater = act.getLayoutInflater(); |
|
65 |
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null); |
|
66 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
67 |
tv.setText(R.string.tutorials); |
|
68 |
builder.setCustomTitle(tv); |
|
44 |
Window window = getDialog().getWindow(); |
|
69 | 45 |
|
70 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
|
46 |
if( window!=null )
|
|
71 | 47 |
{ |
72 |
@Override |
|
73 |
public void onClick(DialogInterface dialog, int which) |
|
74 |
{ |
|
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.85f,mWidth*1.30f ); |
|
51 |
window.setAttributes(params); |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 | 56 |
|
76 |
} |
|
77 |
}); |
|
57 |
public int getResource() { return R.layout.dialog_tabbed; } |
|
58 |
public int getTitleResource() { return R.string.tutorials; } |
|
59 |
public boolean hasArgument() { return false; } |
|
60 |
public int getPositive() { return R.string.ok; } |
|
61 |
public int getNegative() { return -1; } |
|
78 | 62 |
|
79 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
80 |
final View view = inflater.inflate(R.layout.dialog_tabbed, null); |
|
81 |
builder.setView(view); |
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
public void positiveAction() |
|
66 |
{ |
|
67 |
|
|
68 |
} |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
public void negativeAction() |
|
73 |
{ |
|
74 |
|
|
75 |
} |
|
76 |
|
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
80 |
{ |
|
81 |
final int tabHeight= (int)(mHeight*RubikActivity.TAB_HEIGHT); |
|
82 |
final int tabWidth = (int)(mHeight*RubikActivity.TAB_WIDTH); |
|
82 | 83 |
|
83 | 84 |
ViewPager viewPager = view.findViewById(R.id.viewpager); |
84 | 85 |
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs); |
85 | 86 |
mPagerAdapter = new RubikDialogTutorialPagerAdapter(act,viewPager); |
86 | 87 |
tabLayout.setupWithViewPager(viewPager); |
87 |
viewPager.setCurrentItem(getTutorialOrdinal()); |
|
88 |
int obj = RubikObjectList.getCurrObject(); |
|
89 |
int ord = RubikObjectList.getTutorialOrdinal(obj); |
|
90 |
viewPager.setCurrentItem(ord); |
|
88 | 91 |
|
89 | 92 |
ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight ); |
90 | 93 |
int numObjects = RubikObjectList.getNumTutorialObjects(); |
... | ... | |
99 | 102 |
TabLayout.Tab tab = tabLayout.getTabAt(i); |
100 | 103 |
if(tab!=null) tab.setCustomView(imageView); |
101 | 104 |
} |
102 |
|
|
103 |
Dialog dialog = builder.create(); |
|
104 |
dialog.setCanceledOnTouchOutside(false); |
|
105 |
Window window = dialog.getWindow(); |
|
106 |
|
|
107 |
if( window!=null ) |
|
108 |
{ |
|
109 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
110 |
} |
|
111 |
|
|
112 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
113 |
{ |
|
114 |
@Override |
|
115 |
public void onShow(DialogInterface dialog) |
|
116 |
{ |
|
117 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
118 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize); |
|
119 |
} |
|
120 |
}); |
|
121 |
|
|
122 |
return dialog; |
|
123 |
} |
|
124 |
|
|
125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
126 |
|
|
127 |
private int getTutorialOrdinal() |
|
128 |
{ |
|
129 |
int obj = RubikObjectList.getCurrObject(); |
|
130 |
return RubikObjectList.getTutorialOrdinal(obj); |
|
131 |
} |
|
132 |
|
|
133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
134 |
|
|
135 |
@Override |
|
136 |
public void onResume() |
|
137 |
{ |
|
138 |
super.onResume(); |
|
139 |
|
|
140 |
if( mPagerAdapter!=null ) mPagerAdapter.clickPossible(); |
|
141 |
|
|
142 |
Window window = getDialog().getWindow(); |
|
143 |
Context context = getContext(); |
|
144 |
|
|
145 |
if( window!=null && context!=null ) |
|
146 |
{ |
|
147 |
DisplayMetrics metrics = context.getResources().getDisplayMetrics(); |
|
148 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
149 |
params.width = (int)Math.min( 0.65f*metrics.heightPixels,0.98f*metrics.widthPixels ); |
|
150 |
params.height = (int)Math.min( 0.85f*metrics.heightPixels,1.30f*metrics.widthPixels ); |
|
151 |
window.setAttributes(params); |
|
152 |
} |
|
153 | 105 |
} |
154 | 106 |
|
155 | 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Unify all dialogs.