Project

General

Profile

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

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

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
      "2. Support for 'coin' puzzles (Coin Tetrahedron, Ancient Coin Cube).";
38 1c89e2a7 Leszek Koltunski
39 e71baee1 Leszek Koltunski
  private static final String WHATS_COMING =
40 a0aff1b4 Leszek Koltunski
      "1. iOS version.\n" +
41 c91240c9 Leszek Koltunski
      "2. Algorithmic solvers.\n" +
42 a0aff1b4 Leszek Koltunski
      "3. Support for adjustable stickers.\n" +
43
      "4. In-game currency (stars)\n" +
44 c91240c9 Leszek Koltunski
      "5. More objects:\n    - Penrose Cubes\n    - higher-order Jings\n    - Ghost Cubes\n    - more Mirrors\n    - more Mixups\n    - Ancient Coin Cube\n" +
45 a0aff1b4 Leszek Koltunski
      "6. Creator of bandaged Pyraminxes.";
46 1c89e2a7 Leszek Koltunski
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
49
  @Override
50
  public void onResume()
51
    {
52
    super.onResume();
53
54
    Window window = getDialog().getWindow();
55
56
    if( window!=null )
57
      {
58
      WindowManager.LayoutParams params = window.getAttributes();
59 e71baee1 Leszek Koltunski
      params.width  = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
60 bf1edbac Leszek Koltunski
 //     params.height = (int)(mHeight*0.85f);
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 b4ee249e Leszek Koltunski
    int width = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
109
    int sS= (int)(width*0.043f);
110
    int bS= (int)(width*0.060f);
111 24da418d Leszek Koltunski
112 b4ee249e Leszek Koltunski
    TextView shaV = view.findViewById(R.id.about_share_string);
113
    TextView emaV = view.findViewById(R.id.about_mail_string);
114
    TextView addV = view.findViewById(R.id.about_mail_address);
115
116
    TextView newV = view.findViewById(R.id.about_new_message);
117 24da418d Leszek Koltunski
    newV.setText(WHATS_NEW);
118 b4ee249e Leszek Koltunski
    TextView comV = view.findViewById(R.id.about_coming_message);
119 24da418d Leszek Koltunski
    comV.setText(WHATS_COMING);
120 d2f9fa0d Leszek Koltunski
121
    LinearLayout layoutShare = view.findViewById(R.id.about_share_layout);
122
123
    layoutShare.setOnClickListener(new View.OnClickListener()
124
       {
125
       @Override
126
       public void onClick(View v)
127
         {
128
         share(act);
129
         }
130
       });
131
132
    LinearLayout layoutEmail = view.findViewById(R.id.about_email_layout);
133
134
    layoutEmail.setOnClickListener(new View.OnClickListener()
135
       {
136
       @Override
137
       public void onClick(View v)
138
         {
139
         email(act);
140
         }
141
       });
142 b4ee249e Leszek Koltunski
143
    shaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
144
    emaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
145
    addV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
146
    newV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
147
    comV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
148 d2f9fa0d Leszek Koltunski
    }
149
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
152
  private void share(FragmentActivity act)
153
    {
154
    Resources res = act.getResources();
155
    String name = res.getString(R.string.app_name);
156
157
    Intent intent = new Intent();
158
    intent.setAction(Intent.ACTION_SEND);
159
    intent.putExtra(Intent.EXTRA_TEXT,
160
    name+": https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
161
    intent.setType("text/plain");
162
163
    if (intent.resolveActivity(act.getPackageManager()) != null)
164
      {
165
      startActivity(intent);
166
      }
167
    }
168
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170
171
  private void email(FragmentActivity act)
172
    {
173
    Resources res = act.getResources();
174
    String[] email = { res.getString(R.string.email_address) };
175
    String version = findCurrentVersion((RubikActivity)act);
176
    String name = res.getString(R.string.app_name);
177
178
    Intent intent = new Intent(Intent.ACTION_SENDTO);
179
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
180
    intent.putExtra(Intent.EXTRA_EMAIL, email);
181
    intent.putExtra(Intent.EXTRA_SUBJECT, name+" "+version);
182
183
    if (intent.resolveActivity(act.getPackageManager()) != null)
184
      {
185
      startActivity(intent);
186
      }
187 1c89e2a7 Leszek Koltunski
    }
188
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190
191
  public static String getDialogTag()
192
    {
193 e71baee1 Leszek Koltunski
    return "DialogAbout";
194 1c89e2a7 Leszek Koltunski
    }
195
  }