Project

General

Profile

« Previous | Next » 

Revision 6647b730

Added by Leszek Koltunski over 2 years ago

Bandaged 3x3: new dialog.

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorObjectView.java
19 19

  
20 20
package org.distorted.bandaged;
21 21

  
22
import android.os.Bundle;
22 23
import android.view.LayoutInflater;
23 24
import android.view.View;
24 25
import android.widget.LinearLayout;
25 26

  
27
import org.distorted.dialogs.RubikDialogBandagedDelete;
26 28
import org.distorted.helpers.TransparentButton;
27 29
import org.distorted.helpers.TransparentImageButton;
28 30
import org.distorted.main.R;
......
88 90
      @Override
89 91
      public void onClick(View v)
90 92
        {
91
        act.deleteObject(mName);
93
        Bundle bundle = new Bundle();
94
        bundle.putString("name", mName );
95
        RubikDialogBandagedDelete dialog = new RubikDialogBandagedDelete();
96
        dialog.setArguments(bundle);
97
        dialog.show( act.getSupportFragmentManager(), RubikDialogBandagedDelete.getDialogTag() );
92 98
        }
93 99
      });
94 100
    }
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
27 27
import android.opengl.GLSurfaceView;
28 28
import android.widget.Toast;
29 29

  
30
import org.distorted.dialogs.RubikDialogSaveBandaged;
30
import org.distorted.dialogs.RubikDialogBandagedSave;
31 31
import org.distorted.library.effect.PostprocessEffectBorder;
32 32
import org.distorted.library.main.DistortedEffects;
33 33
import org.distorted.library.main.DistortedFramebuffer;
......
504 504
   public void displaySavingDialog()
505 505
     {
506 506
     BandagedCreatorActivity act = (BandagedCreatorActivity)mView.getContext();
507
     RubikDialogSaveBandaged saveDiag = new RubikDialogSaveBandaged();
507
     RubikDialogBandagedSave saveDiag = new RubikDialogBandagedSave();
508 508
     saveDiag.show(act.getSupportFragmentManager(), null);
509 509
     }
510 510

  
src/main/java/org/distorted/dialogs/RubikDialogBandagedDelete.java
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.View;
29
import android.view.Window;
30
import android.widget.Button;
31
import android.widget.TextView;
32

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

  
38
import org.distorted.bandaged.BandagedCreatorActivity;
39
import org.distorted.main.R;
40
import org.distorted.main.RubikActivity;
41

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

  
44
public class RubikDialogBandagedDelete extends AppCompatDialogFragment
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.delete_object );
62
    builder.setCustomTitle(tv);
63

  
64
    final View view = inflater.inflate(R.layout.dialog_delete_object, null);
65

  
66
    TextView save = view.findViewById(R.id.delete_object_text);
67
    save.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
68

  
69
    builder.setCancelable(true);
70

  
71
    Bundle args = getArguments();
72
    String name;
73

  
74
    try
75
      {
76
      name = args.getString("name");
77
      }
78
    catch(Exception e)
79
      {
80
      name = "";
81
      }
82
    final String objectName = name;
83

  
84
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
85
      {
86
      @Override
87
      public void onClick(DialogInterface dialog, int which)
88
        {
89
        BandagedCreatorActivity bact = (BandagedCreatorActivity)getContext();
90

  
91
        if( bact!=null )
92
          {
93
          bact.deleteObject(objectName);
94
          }
95
        }
96
      });
97

  
98
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
99
      {
100
      @Override
101
      public void onClick(DialogInterface dialog, int which)
102
        {
103
        // empty
104
        }
105
      });
106

  
107
    builder.setView(view);
108
    final Dialog dialog = builder.create();
109

  
110
    dialog.setCanceledOnTouchOutside(false);
111
    Window window = dialog.getWindow();
112

  
113
    if( window!=null )
114
      {
115
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
116
      }
117

  
118
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
119
      {
120
      @Override
121
      public void onShow(DialogInterface dialog)
122
        {
123
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
124
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
125
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
126
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
127
        }
128
      });
129

  
130
    return dialog;
131
    }
132

  
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

  
135
  public static String getDialogTag()
136
    {
137
    return "DialogBandagedDelete";
138
    }
139
  }
src/main/java/org/distorted/dialogs/RubikDialogBandagedSave.java
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.View;
29
import android.view.Window;
30
import android.view.WindowManager;
31
import android.widget.Button;
32
import android.widget.TextView;
33

  
34
import androidx.annotation.NonNull;
35
import androidx.appcompat.app.AlertDialog;
36
import androidx.appcompat.app.AppCompatDialogFragment;
37
import androidx.fragment.app.FragmentActivity;
38

  
39
import org.distorted.bandaged.BandagedCreatorActivity;
40
import org.distorted.bandaged.BandagedCreatorRenderer;
41
import org.distorted.main.R;
42
import org.distorted.main.RubikActivity;
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
public class RubikDialogBandagedSave extends AppCompatDialogFragment
47
  {
48
  @NonNull
49
  @Override
50
  public Dialog onCreateDialog(Bundle savedInstanceState)
51
    {
52
    FragmentActivity act = getActivity();
53
    LayoutInflater inflater = act.getLayoutInflater();
54
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
55

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

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

  
66
    final View view = inflater.inflate(R.layout.dialog_save_object, null);
67

  
68
    TextView save = view.findViewById(R.id.save_object_text);
69
    save.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
70

  
71
    builder.setCancelable(true);
72

  
73
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
74
      {
75
      @Override
76
      public void onClick(DialogInterface dialog, int which)
77
        {
78
        BandagedCreatorActivity bact = (BandagedCreatorActivity)getContext();
79

  
80
        if( bact!=null )
81
          {
82
          BandagedCreatorRenderer rend = bact.getRenderer();
83
          rend.saveObject();
84
          }
85
        }
86
      });
87

  
88
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
89
      {
90
      @Override
91
      public void onClick(DialogInterface dialog, int which)
92
        {
93
        // empty
94
        }
95
      });
96

  
97
    builder.setView(view);
98
    final Dialog dialog = builder.create();
99

  
100
    dialog.setCanceledOnTouchOutside(false);
101
    Window window = dialog.getWindow();
102

  
103
    if( window!=null )
104
      {
105
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
106
      }
107

  
108
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
109
      {
110
      @Override
111
      public void onShow(DialogInterface dialog)
112
        {
113
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
114
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
115
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
116
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
117
        }
118
      });
119

  
120
    return dialog;
121
    }
122
  }
src/main/java/org/distorted/dialogs/RubikDialogSaveBandaged.java
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.View;
29
import android.view.Window;
30
import android.view.WindowManager;
31
import android.widget.Button;
32
import android.widget.TextView;
33

  
34
import androidx.annotation.NonNull;
35
import androidx.appcompat.app.AlertDialog;
36
import androidx.appcompat.app.AppCompatDialogFragment;
37
import androidx.fragment.app.FragmentActivity;
38

  
39
import org.distorted.bandaged.BandagedCreatorActivity;
40
import org.distorted.bandaged.BandagedCreatorRenderer;
41
import org.distorted.main.R;
42
import org.distorted.main.RubikActivity;
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
public class RubikDialogSaveBandaged extends AppCompatDialogFragment
47
  {
48
  @NonNull
49
  @Override
50
  public Dialog onCreateDialog(Bundle savedInstanceState)
51
    {
52
    FragmentActivity act = getActivity();
53
    LayoutInflater inflater = act.getLayoutInflater();
54
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
55

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

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

  
66
    final View view = inflater.inflate(R.layout.dialog_save_object, null);
67

  
68
    TextView save = view.findViewById(R.id.save_object_text);
69
    save.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
70

  
71
    builder.setCancelable(true);
72

  
73
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
74
      {
75
      @Override
76
      public void onClick(DialogInterface dialog, int which)
77
        {
78
        BandagedCreatorActivity bact = (BandagedCreatorActivity)getContext();
79

  
80
        if( bact!=null )
81
          {
82
          BandagedCreatorRenderer rend = bact.getRenderer();
83
          rend.saveObject();
84
          }
85
        }
86
      });
87

  
88
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
89
      {
90
      @Override
91
      public void onClick(DialogInterface dialog, int which)
92
        {
93
        // empty
94
        }
95
      });
96

  
97
    builder.setView(view);
98
    final Dialog dialog = builder.create();
99

  
100
    dialog.setCanceledOnTouchOutside(false);
101
    Window window = dialog.getWindow();
102

  
103
    if( window!=null )
104
      {
105
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
106
      }
107

  
108
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
109
      {
110
      @Override
111
      public void onShow(DialogInterface dialog)
112
        {
113
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
114
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
115
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
116
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
117
        }
118
      });
119

  
120
    return dialog;
121
    }
122
  }
src/main/res/layout/dialog_delete_object.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent"
5
    android:gravity="center_horizontal"
6
    android:orientation="vertical">
7

  
8
    <LinearLayout
9
        android:layout_width="fill_parent"
10
        android:layout_height="fill_parent"
11
        android:gravity="center|fill_horizontal"
12
        android:layout_marginLeft="10dp"
13
        android:layout_marginRight="10dp"
14
        android:layout_marginTop="0dp"
15
        android:background="@color/grey"
16
        android:orientation="vertical">
17

  
18
         <TextView
19
            android:id="@+id/delete_object_text"
20
            android:layout_width="match_parent"
21
            android:layout_height="match_parent"
22
            android:gravity="center"
23
            android:textSize="24sp"
24
            android:layout_marginTop="10dp"
25
            android:layout_marginLeft="10dp"
26
            android:layout_marginRight="10dp"
27
            android:layout_marginBottom="10dp"
28
            android:text="@string/delete_object_really"/>
29

  
30
    </LinearLayout>
31
</LinearLayout>
src/main/res/values/strings.xml
40 40
    <string name="level_full">Full Scramble</string>
41 41
    <string name="save_object">Save</string>
42 42
    <string name="save_object_really">Do you want to save this Cube?</string>
43
    <string name="delete_object">Delete</string>
44
    <string name="delete_object_really">Do you want to delete this Cube?</string>
43 45

  
44 46
    <string name="scores">High Scores</string>
45 47
    <string name="patterns">Pretty Patterns</string>

Also available in: Unified diff