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