Project

General

Profile

« Previous | Next » 

Revision 4d6327a1

Added by Leszek Koltunski almost 2 years ago

Dialog 'buy stars'

View differences:

src/main/java/org/distorted/dialogs/RubikDialogStarsError.java
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

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

  
27
import org.distorted.main.R;
28
import org.distorted.main.RubikActivity;
29
import org.distorted.purchase.PurchaseScreenPane;
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
public class RubikDialogStarsError extends AppCompatDialogFragment
34
  {
35
  @NonNull
36
  @Override
37
  public Dialog onCreateDialog(Bundle savedInstanceState)
38
    {
39
    FragmentActivity act = getActivity();
40
    LayoutInflater inflater = act.getLayoutInflater();
41
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
42
    DisplayMetrics displaymetrics = new DisplayMetrics();
43
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
44
    final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
45
    final View view = inflater.inflate(R.layout.dialog_stars_error, null);
46

  
47
    Bundle args = getArguments();
48
    long price;
49

  
50
    try
51
      {
52
      price = args.getInt("price");
53
      }
54
    catch(Exception e)
55
      {
56
      price = PurchaseScreenPane.UNLOCK_ALL_PRICE;
57
      }
58

  
59
    builder.setCancelable(true);
60

  
61
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
62
      {
63
      @Override
64
      public void onClick(DialogInterface dialog, int which) { }
65
      });
66

  
67
    builder.setView(view);
68

  
69
    final Dialog dialog = builder.create();
70
    dialog.setCanceledOnTouchOutside(false);
71
    Window window = dialog.getWindow();
72

  
73
    if( window!=null )
74
      {
75
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
76
      }
77

  
78
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
79
      {
80
      @Override
81
      public void onShow(DialogInterface dialog)
82
        {
83
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
84
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
85
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
86
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
87
        }
88
      });
89

  
90
    return dialog;
91
    }
92
  }
src/main/java/org/distorted/dialogs/RubikDialogStarsExplain.java
69 69
        {
70 70
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
71 71
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
72
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
73
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
74 72
        }
75 73
      });
76 74

  
src/main/java/org/distorted/dialogs/RubikDialogStarsStatus.java
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.external.RubikScores;
29
import org.distorted.main.R;
30
import org.distorted.main.RubikActivity;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
public class RubikDialogStarsStatus extends AppCompatDialogFragment
35
  {
36
  @NonNull
37
  @Override
38
  public Dialog onCreateDialog(Bundle savedInstanceState)
39
    {
40
    FragmentActivity act = getActivity();
41
    LayoutInflater inflater = act.getLayoutInflater();
42
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
43
    DisplayMetrics displaymetrics = new DisplayMetrics();
44
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
45
    final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
46
    final View view = inflater.inflate(R.layout.dialog_stars_status, null);
47

  
48
    fillUpNumberOfStars(view);
49

  
50
    builder.setCancelable(true);
51

  
52
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
53
      {
54
      @Override
55
      public void onClick(DialogInterface dialog, int which) { }
56
      });
57

  
58
    builder.setView(view);
59

  
60
    final Dialog dialog = builder.create();
61
    dialog.setCanceledOnTouchOutside(false);
62
    Window window = dialog.getWindow();
63

  
64
    if( window!=null )
65
      {
66
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
67
      }
68

  
69
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
70
      {
71
      @Override
72
      public void onShow(DialogInterface dialog)
73
        {
74
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
75
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
76
        }
77
      });
78

  
79
    return dialog;
80
    }
81

  
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

  
84
  void fillUpNumberOfStars(View view)
85
    {
86
    int number = RubikScores.getInstance().getNumStars();
87
    TextView v = view.findViewById(R.id.stars_string1);
88
    v.setText(getString(R.string.buy_string1,number));
89
    }
90
  }
src/main/java/org/distorted/purchase/PurchaseScreenPane.java
10 10
package org.distorted.purchase;
11 11

  
12 12
import android.graphics.drawable.Drawable;
13
import android.os.Bundle;
14 13
import android.util.TypedValue;
15 14
import android.view.View;
16 15
import android.widget.ImageButton;
......
20 19

  
21 20
import androidx.core.content.res.ResourcesCompat;
22 21

  
23
import org.distorted.dialogs.RubikDialogStarsError;
22
import org.distorted.dialogs.RubikDialogStarsStatus;
24 23
import org.distorted.external.RubikScores;
25 24
import org.distorted.library.main.DistortedScreen;
26 25
import org.distorted.main.R;
......
75 74

  
76 75
///////////////////////////////////////////////////////////////////////////////////////////////////
77 76

  
78
  private void showError(PurchaseActivity act, int price)
77
  private void showError(PurchaseActivity act)
79 78
    {
80
    Bundle bundle = new Bundle();
81
    bundle.putInt("price", price );
82
    RubikDialogStarsError d = new RubikDialogStarsError();
83
    d.setArguments(bundle);
79
    RubikDialogStarsStatus d = new RubikDialogStarsStatus();
84 80
    d.show(act.getSupportFragmentManager(), null);
85 81
    }
86 82

  
......
114 110
        }
115 111
      else
116 112
        {
117
        showError(act,price);
113
        showError(act);
118 114
        }
119 115
      }
120 116
    }
......
123 119

  
124 120
  private void allButtonClicked(PurchaseActivity act)
125 121
    {
126
    int price = UNLOCK_ALL_PRICE;
127

  
128
    if( chargeUser(price) )
122
    if( chargeUser(UNLOCK_ALL_PRICE) )
129 123
      {
130 124
      RubikObjectList.buyAll();
131 125
      showSuccess(act,null);
132 126
      }
133 127
    else
134 128
      {
135
      showError(act,price);
129
      showError(act);
136 130
      }
137 131
    }
138 132

  
src/main/res/layout/dialog_stars_error.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:gravity="center|fill_horizontal"
6
    android:padding="10dp"
7
    android:background="@color/grey"
8
    android:orientation="vertical">
9

  
10
    <TextView
11
        android:id="@+id/privacy_string"
12
        android:background="@color/dark_grey"
13
        android:layout_width="match_parent"
14
        android:layout_height="match_parent"
15
        android:gravity="start"
16
        android:textSize="21sp"
17
        android:padding="10dp"
18
        android:text="@string/explain_stars_text"
19
        />
20
</LinearLayout>
src/main/res/layout/dialog_stars_status.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:gravity="center|fill_horizontal"
6
    android:padding="10dp"
7
    android:background="@color/grey"
8
    android:orientation="vertical">
9

  
10
    <TextView
11
        android:id="@+id/stars_string1"
12
        android:background="@color/dark_grey"
13
        android:layout_width="match_parent"
14
        android:layout_height="match_parent"
15
        android:gravity="start"
16
        android:textSize="21sp"
17
        android:padding="10dp"
18
        android:text="@string/buy_string1"
19
        />
20
    <TextView
21
        android:id="@+id/stars_string2"
22
        android:background="@color/dark_grey"
23
        android:layout_width="match_parent"
24
        android:layout_height="match_parent"
25
        android:gravity="start"
26
        android:textSize="21sp"
27
        android:padding="10dp"
28
        android:text="@string/buy_string2"
29
        />
30
    <ImageButton
31
        android:id="@+id/stars_buy_button"
32
        android:layout_width="match_parent"
33
        android:layout_height="wrap_content"
34
        android:gravity="center"
35
        android:backgroundTint="@color/red"
36
        android:scaleType="fitCenter"
37
        android:src="@drawable/price_50"
38
        />
39
</LinearLayout>
src/main/res/values-de/strings.xml
58 58

  
59 59
    <string name="buy_one">Diesen Cube freischalten</string>
60 60
    <string name="buy_all">Alles freischalten</string>
61
    <string name="buy">Kauf</string>
62
    <string name="buy_string1">Sie haben %1$d Sterne.</string>
63
    <string name="buy_string2">Verdiene Sterne durch das Lösen von Rätseln. Sie können auch Sterne kaufen.</string>
61 64

  
62 65
    <string name="config_details">Einzelheiten</string>
63 66
    <string name="config_name">Name</string>
src/main/res/values-es/strings.xml
58 58

  
59 59
    <string name="buy_one">Desbloquea este cubo</string>
60 60
    <string name="buy_all">Desbloquear todo</string>
61
    <string name="buy">Comprar</string>
62
    <string name="buy_string1">Tienes %1$d estrellas.</string>
63
    <string name="buy_string2">Gana estrellas resolviendo puzles. También puedes comprar estrellas.</string>
61 64

  
62 65
    <string name="config_details">Detalles</string>
63 66
    <string name="config_name">Nombre</string>
src/main/res/values-fr/strings.xml
58 58

  
59 59
    <string name="buy_one">Déverrouiller ce cube</string>
60 60
    <string name="buy_all">Tout débloquer</string>
61
    <string name="buy">acheter</string>
62
    <string name="buy_string1">Vous avez %1$d étoiles.</string>
63
    <string name="buy_string2">Gagnez des étoiles en résolvant des puzzles. Vous pouvez également acheter des étoiles.</string>
61 64

  
62 65
    <string name="config_details">Détails</string>
63 66
    <string name="config_name">Nom</string>
src/main/res/values-ja/strings.xml
58 58

  
59 59
    <string name="buy_one">キューブをアンロックして</string>
60 60
    <string name="buy_all">全部のロックを解除して</string>
61
    <string name="buy">買う</string>
62
    <string name="buy_string1">星は%1$dつです。</string>
63
    <string name="buy_string2">パズルを解くとスターがもらえます。また、スターを購入することもできます。</string>
61 64

  
62 65
    <string name="config_details">詳細</string>
63 66
    <string name="config_name">名前</string>
src/main/res/values-ko/strings.xml
58 58

  
59 59
    <string name="buy_one">이 큐브의 잠금을 해제</string>
60 60
    <string name="buy_all">모든 것을 잠금 해제</string>
61
    <string name="buy">구입</string>
62
    <string name="buy_string1">별이 %1$d개입니다.</string>
63
    <string name="buy_string2">퍼즐을 풀어 별을 획득하세요. 별을 살 수도 있습니다.</string>
61 64

  
62 65
    <string name="config_details">세부</string>
63 66
    <string name="config_name">이름</string>
src/main/res/values-pl/strings.xml
58 58

  
59 59
    <string name="buy_one">Odblokuj tą kostkę</string>
60 60
    <string name="buy_all">Odblokuj wszystko</string>
61
    <string name="buy">Kup</string>
62
    <string name="buy_string1">Masz %1$d gwiazdek.</string>
63
    <string name="buy_string2">Zdobywaj nowe gwiazdki, rozwiązując kostki. Możesz także kupić gwiazdki.</string>
61 64

  
62 65
    <string name="config_details">O kostce</string>
63 66
    <string name="config_name">Nazwa</string>
......
71 74
    <string name="credits2">Piękne Wzory Waltera Randelshofera. Zobacz <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
72 75
    <string name="credits3">Rubik i RubikCube to zarejestrowane znaki towarowe. Nie jesteśmy z nimi powiązani.</string>
73 76

  
74
    <string name="explain_stars_text">Ta wersja wprowadza koncepcję gwiazdek.\n\nZdobywaj gwiazdki, rozwiązując poziomy. Możesz także kupić gwiazdki.\n\nWydawaj gwiazdki, aby odblokować obiekty i inne funkcje w aplikacji.</string>
77
    <string name="explain_stars_text">Ta wersja wprowadza koncepcję gwiazdek.\n\nZdobywaj gwiazdki, rozwiązując kostki. Możesz także kupić gwiazdki.\n\nWydawaj gwiazdki, aby odblokować obiekty i inne funkcje w aplikacji.</string>
75 78
    <string name="solver_generic_error1">Rozwiązywacz takiego obiektu jest jeszcze nie zaimplementowany!</string>
76 79

  
77 80
    <string name="solver_cube3_error1">Jest tylko %1$d %2$s ścian.</string>
src/main/res/values-ru/strings.xml
58 58

  
59 59
    <string name="buy_one">Разблокируйте этот куб</string>
60 60
    <string name="buy_all">Разблокировать все</string>
61
    <string name="buy">Купите</string>
62
    <string name="buy_string1">У вас %1$d звезд.</string>
63
    <string name="buy_string2">Зарабатывайте звезды, решая головоломки. Вы также можете покупать звезды.</string>
61 64

  
62 65
    <string name="config_details">Детали</string>
63 66
    <string name="config_name">Имя</string>
src/main/res/values-zh-rCN/strings.xml
58 58

  
59 59
    <string name="buy_one">解锁这个立方体</string>
60 60
    <string name="buy_all">解锁一切</string>
61
    <string name="buy">购买</string>
62
    <string name="buy_string1">你有 %1$d 颗星。</string>
63
    <string name="buy_string2">通过解开谜题获得星星。你也可以购买星星。</string>
61 64

  
62 65
    <string name="config_details">细节</string>
63 66
    <string name="config_name">姓名</string>
src/main/res/values-zh-rTW/strings.xml
58 58

  
59 59
    <string name="buy_one">解鎖這個立方體</string>
60 60
    <string name="buy_all">解鎖一切</string>
61
    <string name="buy">買</string>
62
    <string name="buy_string1">你有 %1$d 顆星。</string>
63
    <string name="buy_string2">通過解開謎題贏得星星。你也可以購買星星。</string>
61 64

  
62 65
    <string name="config_details">細節</string>
63 66
    <string name="config_name">姓名</string>
src/main/res/values/strings.xml
59 59

  
60 60
    <string name="buy_one">Unlock this cube</string>
61 61
    <string name="buy_all">Unlock everything</string>
62
    <string name="buy">Buy</string>
63
    <string name="buy_string1">You have %1$d stars.</string>
64
    <string name="buy_string2">Earn stars by solving puzzles. You can also buy stars.</string>
62 65

  
63 66
    <string name="level1" translatable="false">1</string>
64 67
    <string name="level2" translatable="false">2</string>

Also available in: Unified diff