Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogBandagedSave.java @ 05c044a5

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.dialogs;
11

    
12
import android.app.Dialog;
13
import android.content.DialogInterface;
14
import android.os.Bundle;
15
import android.util.DisplayMetrics;
16
import android.util.TypedValue;
17
import android.view.LayoutInflater;
18
import android.view.View;
19
import android.view.Window;
20
import android.view.WindowManager;
21
import android.widget.Button;
22
import android.widget.TextView;
23

    
24
import androidx.annotation.NonNull;
25
import androidx.appcompat.app.AlertDialog;
26
import androidx.appcompat.app.AppCompatDialogFragment;
27
import androidx.fragment.app.FragmentActivity;
28

    
29
import org.distorted.bandaged.BandagedCreatorActivity;
30
import org.distorted.bandaged.BandagedCreatorRenderer;
31
import org.distorted.main.R;
32
import org.distorted.main.RubikActivity;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class RubikDialogBandagedSave extends AppCompatDialogFragment
37
  {
38
  @NonNull
39
  @Override
40
  public Dialog onCreateDialog(Bundle savedInstanceState)
41
    {
42
    FragmentActivity act = getActivity();
43
    LayoutInflater inflater = act.getLayoutInflater();
44
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
45

    
46
    DisplayMetrics displaymetrics = new DisplayMetrics();
47
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
48
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
49
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
50

    
51
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
52
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
53
    tv.setText( R.string.save_object );
54
    builder.setCustomTitle(tv);
55

    
56
    final View view = inflater.inflate(R.layout.dialog_save_object, null);
57

    
58
    TextView save = view.findViewById(R.id.save_object_text);
59
    save.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
60

    
61
    builder.setCancelable(true);
62

    
63
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
64
      {
65
      @Override
66
      public void onClick(DialogInterface dialog, int which)
67
        {
68
        BandagedCreatorActivity bact = (BandagedCreatorActivity)getContext();
69

    
70
        if( bact!=null )
71
          {
72
          BandagedCreatorRenderer rend = bact.getRenderer();
73
          rend.saveObject();
74
          }
75
        }
76
      });
77

    
78
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
79
      {
80
      @Override
81
      public void onClick(DialogInterface dialog, int which)
82
        {
83
        // empty
84
        }
85
      });
86

    
87
    builder.setView(view);
88
    final Dialog dialog = builder.create();
89

    
90
    dialog.setCanceledOnTouchOutside(false);
91
    Window window = dialog.getWindow();
92

    
93
    if( window!=null )
94
      {
95
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
96
      }
97

    
98
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
99
      {
100
      @Override
101
      public void onShow(DialogInterface dialog)
102
        {
103
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
104
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
105
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
106
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
107
        }
108
      });
109

    
110
    return dialog;
111
    }
112
  }
(4-4/23)