Revision c02fa107
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/dialogs/RubikDialogUpdates.java | ||
---|---|---|
14 | 14 |
import android.app.Dialog; |
15 | 15 |
import android.content.DialogInterface; |
16 | 16 |
import android.graphics.Bitmap; |
17 |
import android.os.Bundle; |
|
18 |
import android.util.DisplayMetrics; |
|
19 | 17 |
import android.util.TypedValue; |
20 |
import android.view.LayoutInflater; |
|
21 | 18 |
import android.view.View; |
22 |
import android.view.Window; |
|
23 | 19 |
import android.widget.Button; |
24 | 20 |
import android.widget.LinearLayout; |
25 | 21 |
import android.widget.TextView; |
26 | 22 |
|
27 |
import androidx.annotation.NonNull; |
|
28 | 23 |
import androidx.appcompat.app.AlertDialog; |
29 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
30 | 24 |
import androidx.fragment.app.FragmentActivity; |
31 | 25 |
|
32 | 26 |
import org.distorted.main.R; |
33 |
import org.distorted.main.RubikActivity; |
|
34 | 27 |
import org.distorted.external.RubikNetwork; |
35 | 28 |
import org.distorted.external.RubikUpdates; |
36 | 29 |
|
37 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 31 |
|
39 |
public class RubikDialogUpdates extends AppCompatDialogFragment implements RubikNetwork.IconReceiver, RubikNetwork.Updatee
|
|
32 |
public class RubikDialogUpdates extends RubikDialogAbstract implements RubikNetwork.IconReceiver, RubikNetwork.Updatee
|
|
40 | 33 |
{ |
41 | 34 |
private TextView mText; |
42 | 35 |
private LinearLayout mLayout; |
43 | 36 |
private int mMargin, mSize, mFontSize, mPadding; |
44 |
|
|
45 | 37 |
private ArrayList<RubikDialogUpdateView> mPanes; |
46 | 38 |
|
47 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
48 | 40 |
|
49 |
private View createView(FragmentActivity act, LayoutInflater inflater, float size, int minH)
|
|
41 |
public int getResource()
|
|
50 | 42 |
{ |
51 |
final View view = inflater.inflate(R.layout.dialog_updates, null); |
|
52 |
|
|
53 |
mLayout= view.findViewById(R.id.updates_main_layout); |
|
54 |
mText = view.findViewById(R.id.updates_message); |
|
55 |
mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
56 |
mText.setText( act.getString(R.string.downloading) ); |
|
43 |
return R.layout.dialog_updates; |
|
44 |
} |
|
57 | 45 |
|
58 |
mLayout.setMinimumHeight(minH); |
|
59 |
mText.setMinimumHeight(minH); |
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 | 47 |
|
61 |
return view; |
|
48 |
public int getTitleResource() |
|
49 |
{ |
|
50 |
return R.string.updates; |
|
62 | 51 |
} |
63 | 52 |
|
64 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
65 | 54 |
|
66 |
@NonNull |
|
67 |
@Override |
|
68 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
55 |
public boolean hasArgument() |
|
69 | 56 |
{ |
70 |
if( mPanes==null ) mPanes = new ArrayList<>(); |
|
57 |
return false; |
|
58 |
} |
|
71 | 59 |
|
72 |
FragmentActivity act = getActivity(); |
|
73 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
74 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
75 |
|
|
76 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
77 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
78 |
int h= displaymetrics.heightPixels; |
|
79 |
final float titleSize= h*0.032f; |
|
80 |
final float okSize = h*0.04f; |
|
81 |
mMargin = (int)(h*0.01f); |
|
82 |
mSize = (int)(h*0.14f); |
|
83 |
mFontSize = (int)(h*0.02f); |
|
84 |
mPadding = (int)(h*0.01f); |
|
85 |
|
|
86 |
TextView title = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
87 |
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
88 |
title.setText(R.string.updates); |
|
89 |
builder.setCustomTitle(title); |
|
90 |
|
|
91 |
builder.setCancelable(true); |
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
|
62 |
public void setPositive(AlertDialog.Builder builder) |
|
63 |
{ |
|
92 | 64 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
93 | 65 |
{ |
94 | 66 |
@Override |
... | ... | |
97 | 69 |
|
98 | 70 |
} |
99 | 71 |
}); |
72 |
} |
|
100 | 73 |
|
101 |
int minH = (int)(0.25f*h); |
|
102 |
View view = createView(act,inflater,okSize,minH); |
|
103 |
view.setMinimumHeight(minH); |
|
104 |
builder.setView(view); |
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 | 75 |
|
106 |
Dialog dialog = builder.create(); |
|
107 |
dialog.setCanceledOnTouchOutside(false); |
|
108 |
Window window = dialog.getWindow(); |
|
76 |
public void setNegative(AlertDialog.Builder builder) |
|
77 |
{ |
|
109 | 78 |
|
110 |
if( window!=null ) |
|
111 |
{ |
|
112 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
113 |
} |
|
79 |
} |
|
114 | 80 |
|
115 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
116 |
{ |
|
117 |
@Override |
|
118 |
public void onShow(DialogInterface dialog) |
|
119 |
{ |
|
120 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
121 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize); |
|
122 |
} |
|
123 |
}); |
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
public void onShowDialog(DialogInterface dialog, float size) |
|
84 |
{ |
|
85 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
86 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
87 |
} |
|
88 |
|
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
92 |
{ |
|
93 |
if( mPanes==null ) mPanes = new ArrayList<>(); |
|
94 |
|
|
95 |
int minH = (int)(mHeight*0.25f); |
|
96 |
mMargin = (int)(mHeight*0.01f); |
|
97 |
mSize = (int)(mHeight*0.14f); |
|
98 |
mFontSize = (int)(mHeight*0.02f); |
|
99 |
mPadding = (int)(mHeight*0.01f); |
|
100 |
|
|
101 |
mLayout= view.findViewById(R.id.updates_main_layout); |
|
102 |
mText = view.findViewById(R.id.updates_message); |
|
103 |
mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
104 |
mText.setText( act.getString(R.string.downloading) ); |
|
105 |
|
|
106 |
mLayout.setMinimumHeight(minH); |
|
107 |
mText.setMinimumHeight(minH); |
|
108 |
view.setMinimumHeight(minH); |
|
124 | 109 |
|
125 | 110 |
RubikNetwork network = RubikNetwork.getInstance(); |
126 | 111 |
network.signUpForUpdates(this); |
127 |
|
|
128 |
return dialog; |
|
129 | 112 |
} |
130 | 113 |
|
131 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
187 | 170 |
{ |
188 | 171 |
FragmentActivity act = getActivity(); |
189 | 172 |
|
173 |
android.util.Log.e("D", "receiveUpdate1"); |
|
174 |
|
|
190 | 175 |
if( act!=null ) |
191 | 176 |
{ |
192 | 177 |
act.runOnUiThread(new Runnable() |
Also available in: Unified diff
Continue unifying all the dialogs under one RubikDialogAbstract.