Project

General

Profile

Download (4.78 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / dialogs / RubikDialogUpdates.java @ 8678dd48

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
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
package org.distorted.dialogs;
21

    
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
import android.util.DisplayMetrics;
26
import android.util.TypedValue;
27
import android.view.LayoutInflater;
28
import android.view.Window;
29
import android.widget.Button;
30
import android.widget.TextView;
31

    
32
import androidx.annotation.NonNull;
33
import androidx.appcompat.app.AlertDialog;
34
import androidx.appcompat.app.AppCompatDialogFragment;
35
import androidx.fragment.app.FragmentActivity;
36

    
37
import org.distorted.main.R;
38
import org.distorted.main.RubikActivity;
39
import org.distorted.network.RubikNetwork;
40
import org.distorted.network.RubikUpdates;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
public class RubikDialogUpdates extends AppCompatDialogFragment implements RubikNetwork.Updatee
45
  {
46
  @NonNull
47
  @Override
48
  public Dialog onCreateDialog(Bundle savedInstanceState)
49
    {
50
    FragmentActivity act = getActivity();
51
    LayoutInflater inflater = act.getLayoutInflater();
52
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
53

    
54
    DisplayMetrics displaymetrics = new DisplayMetrics();
55
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
56
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
57
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
58

    
59
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
60
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
61
    tv.setText(R.string.updates);
62
    builder.setCustomTitle(tv);
63

    
64
    builder.setCancelable(true);
65
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
66
      {
67
      @Override
68
      public void onClick(DialogInterface dialog, int which)
69
        {
70

    
71
        }
72
      });
73

    
74
    Dialog dialog = builder.create();
75
    dialog.setCanceledOnTouchOutside(false);
76
    Window window = dialog.getWindow();
77

    
78
    if( window!=null )
79
      {
80
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
81
      }
82

    
83
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
84
      {
85
      @Override
86
      public void onShow(DialogInterface dialog)
87
        {
88
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
89
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
90
        }
91
      });
92

    
93
    RubikNetwork network = RubikNetwork.getInstance();
94
    network.signUpForUpdates(this);
95

    
96
    return dialog;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  public void receiveUpdate(RubikUpdates updates)
102
    {
103

    
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public void errorUpdate()
109
    {
110
    android.util.Log.e("D", "Dialog: Error receiving update");
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public static String getDialogTag()
116
    {
117
    return "DialogUpdates";
118
    }
119
  }
(20-20/20)