Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogAbout.java @ b4ee249e

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 e71baee1 Leszek Koltunski
      "4. More objects (Penrose Cubes, higher-order Jings, Ghost Cubes, more Mirrors, more Mixups)";
48 1c89e2a7 Leszek Koltunski
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
51
  @Override
52
  public void onResume()
53
    {
54
    super.onResume();
55
56
    Window window = getDialog().getWindow();
57
58
    if( window!=null )
59
      {
60
      WindowManager.LayoutParams params = window.getAttributes();
61 e71baee1 Leszek Koltunski
      params.width  = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
62 1c89e2a7 Leszek Koltunski
      window.setAttributes(params);
63
      }
64
    }
65
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
68 e71baee1 Leszek Koltunski
  public int getResource()      { return R.layout.dialog_about; }
69
  public int getTitleResource() { return PARAMETRIC_TITLE; }
70 1c89e2a7 Leszek Koltunski
  public boolean hasArgument()  { return true; }
71
  public int getPositive()      { return R.string.ok; }
72
  public int getNegative()      { return -1; }
73 e71baee1 Leszek Koltunski
  public void positiveAction()  { }
74
  public void negativeAction()  { }
75 1c89e2a7 Leszek Koltunski
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
78 34d6b123 Leszek Koltunski
  private String findCurrentVersion(RubikActivity act)
79 1c89e2a7 Leszek Koltunski
    {
80 34d6b123 Leszek Koltunski
    String version;
81
    try
82 1c89e2a7 Leszek Koltunski
      {
83 34d6b123 Leszek Koltunski
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
84
      version= pInfo.versionName;
85 1c89e2a7 Leszek Koltunski
      }
86 34d6b123 Leszek Koltunski
    catch (PackageManager.NameNotFoundException e)
87
      {
88
      version= "unknown";
89
      }
90
91
    return version;
92 1c89e2a7 Leszek Koltunski
    }
93
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95
96 e71baee1 Leszek Koltunski
  @Override
97
  String getTitleString(FragmentActivity act)
98 1c89e2a7 Leszek Koltunski
    {
99 e71baee1 Leszek Koltunski
    Resources res= getResources();
100
    RubikActivity ract= (RubikActivity) getContext();
101
    String version= ract!=null ? findCurrentVersion(ract) : "unknown";
102
    return res.getString(R.string.ab_placeholder,version);
103
    }
104 1c89e2a7 Leszek Koltunski
105 e71baee1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
106 1c89e2a7 Leszek Koltunski
107 e71baee1 Leszek Koltunski
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
108
    {
109 b4ee249e Leszek Koltunski
    int width = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
110
    int sS= (int)(width*0.043f);
111
    int bS= (int)(width*0.060f);
112 24da418d Leszek Koltunski
113 b4ee249e Leszek Koltunski
    TextView shaV = view.findViewById(R.id.about_share_string);
114
    TextView emaV = view.findViewById(R.id.about_mail_string);
115
    TextView addV = view.findViewById(R.id.about_mail_address);
116
117
    TextView newV = view.findViewById(R.id.about_new_message);
118 24da418d Leszek Koltunski
    newV.setText(WHATS_NEW);
119 b4ee249e Leszek Koltunski
    TextView comV = view.findViewById(R.id.about_coming_message);
120 24da418d Leszek Koltunski
    comV.setText(WHATS_COMING);
121 d2f9fa0d Leszek Koltunski
122
    LinearLayout layoutShare = view.findViewById(R.id.about_share_layout);
123
124
    layoutShare.setOnClickListener(new View.OnClickListener()
125
       {
126
       @Override
127
       public void onClick(View v)
128
         {
129
         share(act);
130
         }
131
       });
132
133
    LinearLayout layoutEmail = view.findViewById(R.id.about_email_layout);
134
135
    layoutEmail.setOnClickListener(new View.OnClickListener()
136
       {
137
       @Override
138
       public void onClick(View v)
139
         {
140
         email(act);
141
         }
142
       });
143 b4ee249e Leszek Koltunski
144
    shaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
145
    emaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
146
    addV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
147
    newV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
148
    comV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
149 d2f9fa0d Leszek Koltunski
    }
150
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152
153
  private void share(FragmentActivity act)
154
    {
155
    Resources res = act.getResources();
156
    String name = res.getString(R.string.app_name);
157
158
    Intent intent = new Intent();
159
    intent.setAction(Intent.ACTION_SEND);
160
    intent.putExtra(Intent.EXTRA_TEXT,
161
    name+": https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
162
    intent.setType("text/plain");
163
164
    if (intent.resolveActivity(act.getPackageManager()) != null)
165
      {
166
      startActivity(intent);
167
      }
168
    }
169
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
172
  private void email(FragmentActivity act)
173
    {
174
    Resources res = act.getResources();
175
    String[] email = { res.getString(R.string.email_address) };
176
    String version = findCurrentVersion((RubikActivity)act);
177
    String name = res.getString(R.string.app_name);
178
179
    Intent intent = new Intent(Intent.ACTION_SENDTO);
180
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
181
    intent.putExtra(Intent.EXTRA_EMAIL, email);
182
    intent.putExtra(Intent.EXTRA_SUBJECT, name+" "+version);
183
184
    if (intent.resolveActivity(act.getPackageManager()) != null)
185
      {
186
      startActivity(intent);
187
      }
188 1c89e2a7 Leszek Koltunski
    }
189
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
192
  public static String getDialogTag()
193
    {
194 e71baee1 Leszek Koltunski
    return "DialogAbout";
195 1c89e2a7 Leszek Koltunski
    }
196
  }