Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogAbout.java @ 7d1ba3d2

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 c91240c9 Leszek Koltunski
      "1. 3x3x2 Cuboid solver.\n" +
37 441f2db5 Leszek Koltunski
      "2. Support for 'coin' puzzles (Coin Tetrahedron, Ancient Coin Cube).\n" +
38 58990dfd Leszek Koltunski
      "3. Improvements to the Highscores dialog.\n" +
39
      "4. Correct the Masterball (before it was nearly impossible to be solved)";
40 1c89e2a7 Leszek Koltunski
41 e71baee1 Leszek Koltunski
  private static final String WHATS_COMING =
42 7d1ba3d2 Leszek Koltunski
      "1. Creator of bandaged Pyraminxes [in progress now].\n" +
43
      "2. iOS version.\n" +
44
      "3. Algorithmic solvers.\n" +
45
      "4. Support for adjustable stickers.\n" +
46
      "5. In-game currency (stars)\n" +
47
      "6. More objects:\n    - Tins Cube\n    - Ancient Coin Cube\n    - higher-order Jings\n    - Ghost Cubes\n    - more Mirrors\n    - more Mixups\n";
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 bf1edbac Leszek Koltunski
 //     params.height = (int)(mHeight*0.85f);
63 1c89e2a7 Leszek Koltunski
      window.setAttributes(params);
64
      }
65
    }
66
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69 e71baee1 Leszek Koltunski
  public int getResource()      { return R.layout.dialog_about; }
70
  public int getTitleResource() { return PARAMETRIC_TITLE; }
71 1c89e2a7 Leszek Koltunski
  public boolean hasArgument()  { return true; }
72
  public int getPositive()      { return R.string.ok; }
73
  public int getNegative()      { return -1; }
74 e71baee1 Leszek Koltunski
  public void positiveAction()  { }
75
  public void negativeAction()  { }
76 1c89e2a7 Leszek Koltunski
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
79 34d6b123 Leszek Koltunski
  private String findCurrentVersion(RubikActivity act)
80 1c89e2a7 Leszek Koltunski
    {
81 34d6b123 Leszek Koltunski
    String version;
82
    try
83 1c89e2a7 Leszek Koltunski
      {
84 34d6b123 Leszek Koltunski
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
85
      version= pInfo.versionName;
86 1c89e2a7 Leszek Koltunski
      }
87 34d6b123 Leszek Koltunski
    catch (PackageManager.NameNotFoundException e)
88
      {
89
      version= "unknown";
90
      }
91
92
    return version;
93 1c89e2a7 Leszek Koltunski
    }
94
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
97 e71baee1 Leszek Koltunski
  @Override
98
  String getTitleString(FragmentActivity act)
99 1c89e2a7 Leszek Koltunski
    {
100 e71baee1 Leszek Koltunski
    Resources res= getResources();
101
    RubikActivity ract= (RubikActivity) getContext();
102
    String version= ract!=null ? findCurrentVersion(ract) : "unknown";
103
    return res.getString(R.string.ab_placeholder,version);
104
    }
105 1c89e2a7 Leszek Koltunski
106 e71baee1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
107 1c89e2a7 Leszek Koltunski
108 e71baee1 Leszek Koltunski
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
109
    {
110 b4ee249e Leszek Koltunski
    int width = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
111
    int sS= (int)(width*0.043f);
112
    int bS= (int)(width*0.060f);
113 24da418d Leszek Koltunski
114 b4ee249e Leszek Koltunski
    TextView shaV = view.findViewById(R.id.about_share_string);
115
    TextView emaV = view.findViewById(R.id.about_mail_string);
116
    TextView addV = view.findViewById(R.id.about_mail_address);
117
118
    TextView newV = view.findViewById(R.id.about_new_message);
119 24da418d Leszek Koltunski
    newV.setText(WHATS_NEW);
120 b4ee249e Leszek Koltunski
    TextView comV = view.findViewById(R.id.about_coming_message);
121 24da418d Leszek Koltunski
    comV.setText(WHATS_COMING);
122 d2f9fa0d Leszek Koltunski
123
    LinearLayout layoutShare = view.findViewById(R.id.about_share_layout);
124
125
    layoutShare.setOnClickListener(new View.OnClickListener()
126
       {
127
       @Override
128
       public void onClick(View v)
129
         {
130
         share(act);
131
         }
132
       });
133
134
    LinearLayout layoutEmail = view.findViewById(R.id.about_email_layout);
135
136
    layoutEmail.setOnClickListener(new View.OnClickListener()
137
       {
138
       @Override
139
       public void onClick(View v)
140
         {
141
         email(act);
142
         }
143
       });
144 b4ee249e Leszek Koltunski
145
    shaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
146
    emaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
147
    addV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
148
    newV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
149
    comV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
150 d2f9fa0d Leszek Koltunski
    }
151
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
154
  private void share(FragmentActivity act)
155
    {
156
    Resources res = act.getResources();
157
    String name = res.getString(R.string.app_name);
158
159
    Intent intent = new Intent();
160
    intent.setAction(Intent.ACTION_SEND);
161
    intent.putExtra(Intent.EXTRA_TEXT,
162
    name+": https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
163
    intent.setType("text/plain");
164
165
    if (intent.resolveActivity(act.getPackageManager()) != null)
166
      {
167
      startActivity(intent);
168
      }
169
    }
170
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172
173
  private void email(FragmentActivity act)
174
    {
175
    Resources res = act.getResources();
176
    String[] email = { res.getString(R.string.email_address) };
177
    String version = findCurrentVersion((RubikActivity)act);
178
    String name = res.getString(R.string.app_name);
179
180
    Intent intent = new Intent(Intent.ACTION_SENDTO);
181
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
182
    intent.putExtra(Intent.EXTRA_EMAIL, email);
183
    intent.putExtra(Intent.EXTRA_SUBJECT, name+" "+version);
184
185
    if (intent.resolveActivity(act.getPackageManager()) != null)
186
      {
187
      startActivity(intent);
188
      }
189 1c89e2a7 Leszek Koltunski
    }
190
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192
193
  public static String getDialogTag()
194
    {
195 e71baee1 Leszek Koltunski
    return "DialogAbout";
196 1c89e2a7 Leszek Koltunski
    }
197
  }