Project

General

Profile

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

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

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