Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogBandagedSave.java @ 9dfb553f

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.widget.Button;
21
import android.widget.TextView;
22

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

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

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

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

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

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

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

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

    
60
    builder.setCancelable(true);
61

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

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

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

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

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

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

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

    
109
    return dialog;
110
    }
111
  }
(4-4/25)