Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogAbout.java @ 527557b7

1 1c89e2a7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 d2f9fa0d Leszek Koltunski
import android.content.Intent;
14 34d6b123 Leszek Koltunski
import android.content.pm.PackageInfo;
15
import android.content.pm.PackageManager;
16 e71baee1 Leszek Koltunski
import android.content.res.Resources;
17 d2f9fa0d Leszek Koltunski
import android.net.Uri;
18 b4ee249e Leszek Koltunski
import android.util.TypedValue;
19 1c89e2a7 Leszek Koltunski
import android.view.View;
20
import android.view.Window;
21
import android.view.WindowManager;
22 d2f9fa0d Leszek Koltunski
import android.widget.LinearLayout;
23 24da418d Leszek Koltunski
import android.widget.TextView;
24 1c89e2a7 Leszek Koltunski
25
import androidx.fragment.app.FragmentActivity;
26
27 d2f9fa0d Leszek Koltunski
import org.distorted.main.BuildConfig;
28 1c89e2a7 Leszek Koltunski
import org.distorted.main.R;
29
import org.distorted.main.RubikActivity;
30
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 e71baee1 Leszek Koltunski
public class RubikDialogAbout extends RubikDialogAbstract
34 1c89e2a7 Leszek Koltunski
  {
35 e71baee1 Leszek Koltunski
  private static final String WHATS_NEW =
36 24da418d Leszek Koltunski
      "1. Solvers: 2x2x3, Pyraminx & Skewb Diamond.\n" +
37
      "2. Implement Icosamate & Master Icosamate\n" +
38
      "3. Connect the solvers to the scrambling engine. Which means: from now on, " +
39 c69ea8e1 Leszek Koltunski
       "all puzzles which have a solver implemented will be perfectly scrambled " +
40
       " - i.e. any scramble at Level 7 will always require exactly 7 moves to solve. " +
41 24da418d Leszek Koltunski
       "Which also means that in some point in the future, we'll have to clear the High Scores.";
42 1c89e2a7 Leszek Koltunski
43 e71baee1 Leszek Koltunski
  private static final String WHATS_COMING =
44 24da418d Leszek Koltunski
      "1. More solvers (2x2, Skewb, Dino).\n" +
45 34d6b123 Leszek Koltunski
      "2. Support for adjustable stickers.\n" +
46
      "3. In-game currency (stars)\n" +
47 bf1edbac Leszek Koltunski
      "4. More objects (Penrose Cubes, higher-order Jings, Ghost Cubes, more Mirrors, more Mixups)\n" +
48
      "5. Creator of bandaged Pyraminxes.";
49 1c89e2a7 Leszek Koltunski
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
52
  @Override
53
  public void onResume()
54
    {
55
    super.onResume();
56
57
    Window window = getDialog().getWindow();
58
59
    if( window!=null )
60
      {
61
      WindowManager.LayoutParams params = window.getAttributes();
62 e71baee1 Leszek Koltunski
      params.width  = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
63 bf1edbac Leszek Koltunski
 //     params.height = (int)(mHeight*0.85f);
64 1c89e2a7 Leszek Koltunski
      window.setAttributes(params);
65
      }
66
    }
67
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
70 e71baee1 Leszek Koltunski
  public int getResource()      { return R.layout.dialog_about; }
71
  public int getTitleResource() { return PARAMETRIC_TITLE; }
72 1c89e2a7 Leszek Koltunski
  public boolean hasArgument()  { return true; }
73
  public int getPositive()      { return R.string.ok; }
74
  public int getNegative()      { return -1; }
75 e71baee1 Leszek Koltunski
  public void positiveAction()  { }
76
  public void negativeAction()  { }
77 1c89e2a7 Leszek Koltunski
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
80 34d6b123 Leszek Koltunski
  private String findCurrentVersion(RubikActivity act)
81 1c89e2a7 Leszek Koltunski
    {
82 34d6b123 Leszek Koltunski
    String version;
83
    try
84 1c89e2a7 Leszek Koltunski
      {
85 34d6b123 Leszek Koltunski
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
86
      version= pInfo.versionName;
87 1c89e2a7 Leszek Koltunski
      }
88 34d6b123 Leszek Koltunski
    catch (PackageManager.NameNotFoundException e)
89
      {
90
      version= "unknown";
91
      }
92
93
    return version;
94 1c89e2a7 Leszek Koltunski
    }
95
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97
98 e71baee1 Leszek Koltunski
  @Override
99
  String getTitleString(FragmentActivity act)
100 1c89e2a7 Leszek Koltunski
    {
101 e71baee1 Leszek Koltunski
    Resources res= getResources();
102
    RubikActivity ract= (RubikActivity) getContext();
103
    String version= ract!=null ? findCurrentVersion(ract) : "unknown";
104
    return res.getString(R.string.ab_placeholder,version);
105
    }
106 1c89e2a7 Leszek Koltunski
107 e71baee1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
108 1c89e2a7 Leszek Koltunski
109 e71baee1 Leszek Koltunski
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
110
    {
111 b4ee249e Leszek Koltunski
    int width = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
112
    int sS= (int)(width*0.043f);
113
    int bS= (int)(width*0.060f);
114 24da418d Leszek Koltunski
115 b4ee249e Leszek Koltunski
    TextView shaV = view.findViewById(R.id.about_share_string);
116
    TextView emaV = view.findViewById(R.id.about_mail_string);
117
    TextView addV = view.findViewById(R.id.about_mail_address);
118
119
    TextView newV = view.findViewById(R.id.about_new_message);
120 24da418d Leszek Koltunski
    newV.setText(WHATS_NEW);
121 b4ee249e Leszek Koltunski
    TextView comV = view.findViewById(R.id.about_coming_message);
122 24da418d Leszek Koltunski
    comV.setText(WHATS_COMING);
123 d2f9fa0d Leszek Koltunski
124
    LinearLayout layoutShare = view.findViewById(R.id.about_share_layout);
125
126
    layoutShare.setOnClickListener(new View.OnClickListener()
127
       {
128
       @Override
129
       public void onClick(View v)
130
         {
131
         share(act);
132
         }
133
       });
134
135
    LinearLayout layoutEmail = view.findViewById(R.id.about_email_layout);
136
137
    layoutEmail.setOnClickListener(new View.OnClickListener()
138
       {
139
       @Override
140
       public void onClick(View v)
141
         {
142
         email(act);
143
         }
144
       });
145 b4ee249e Leszek Koltunski
146
    shaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
147
    emaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
148
    addV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
149
    newV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
150
    comV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
151 d2f9fa0d Leszek Koltunski
    }
152
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154
155
  private void share(FragmentActivity act)
156
    {
157
    Resources res = act.getResources();
158
    String name = res.getString(R.string.app_name);
159
160
    Intent intent = new Intent();
161
    intent.setAction(Intent.ACTION_SEND);
162
    intent.putExtra(Intent.EXTRA_TEXT,
163
    name+": https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
164
    intent.setType("text/plain");
165
166
    if (intent.resolveActivity(act.getPackageManager()) != null)
167
      {
168
      startActivity(intent);
169
      }
170
    }
171
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
174
  private void email(FragmentActivity act)
175
    {
176
    Resources res = act.getResources();
177
    String[] email = { res.getString(R.string.email_address) };
178
    String version = findCurrentVersion((RubikActivity)act);
179
    String name = res.getString(R.string.app_name);
180
181
    Intent intent = new Intent(Intent.ACTION_SENDTO);
182
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
183
    intent.putExtra(Intent.EXTRA_EMAIL, email);
184
    intent.putExtra(Intent.EXTRA_SUBJECT, name+" "+version);
185
186
    if (intent.resolveActivity(act.getPackageManager()) != null)
187
      {
188
      startActivity(intent);
189
      }
190 1c89e2a7 Leszek Koltunski
    }
191
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193
194
  public static String getDialogTag()
195
    {
196 e71baee1 Leszek Koltunski
    return "DialogAbout";
197 1c89e2a7 Leszek Koltunski
    }
198
  }