Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / DialogAbout.java @ c2025412

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 1c04d054 leszek
import android.app.Activity;
13 1c89e2a7 Leszek Koltunski
import android.app.Dialog;
14 d2f9fa0d Leszek Koltunski
import android.content.Intent;
15 34d6b123 Leszek Koltunski
import android.content.pm.PackageInfo;
16
import android.content.pm.PackageManager;
17 e71baee1 Leszek Koltunski
import android.content.res.Resources;
18 d2f9fa0d Leszek Koltunski
import android.net.Uri;
19 b4ee249e Leszek Koltunski
import android.util.TypedValue;
20 1c89e2a7 Leszek Koltunski
import android.view.View;
21
import android.view.Window;
22
import android.view.WindowManager;
23 d2f9fa0d Leszek Koltunski
import android.widget.LinearLayout;
24 24da418d Leszek Koltunski
import android.widget.TextView;
25 1c89e2a7 Leszek Koltunski
26
import androidx.fragment.app.FragmentActivity;
27
28 d2f9fa0d Leszek Koltunski
import org.distorted.main.BuildConfig;
29 1c89e2a7 Leszek Koltunski
import org.distorted.main.R;
30
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 8477cf44 leszek
public class DialogAbout extends DialogAbstract
34 1c89e2a7 Leszek Koltunski
  {
35 e71baee1 Leszek Koltunski
  private static final String WHATS_NEW =
36 8c4d432a leszek
      "1. The first two algorithmic solvers:\n     - the Beginner Method (3x3)\n     - Kilominx solver\n" +
37
      "2. Lots of internal improvements and small fixes, for example for the movement of the Coin puzzles";
38 8d1b2017 leszek
39
  private static final String WHATS_COMING =
40 8c4d432a leszek
      "1. More algorithmic solvers - Megaminx, 4x4 and more.\n" +
41 edc6fab2 leszek
      "2. Support for sticker modes (Tartan Cube, Shepherd's Cube, etc).\n" +
42 7214ddf1 leszek
      "3. iOS version (no time for this, anyone can help? Code is open-source)\n" +
43 edc6fab2 leszek
      "4. More objects:\n    - Ghost Cubes\n    - more Mixups\n    - more Barrels\n";
44 1c89e2a7 Leszek Koltunski
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46
47
  @Override
48
  public void onResume()
49
    {
50
    super.onResume();
51
52
    Window window = getDialog().getWindow();
53
54
    if( window!=null )
55
      {
56
      WindowManager.LayoutParams params = window.getAttributes();
57 e71baee1 Leszek Koltunski
      params.width  = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
58 1c89e2a7 Leszek Koltunski
      window.setAttributes(params);
59
      }
60
    }
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64 e71baee1 Leszek Koltunski
  public int getResource()      { return R.layout.dialog_about; }
65
  public int getTitleResource() { return PARAMETRIC_TITLE; }
66 1c89e2a7 Leszek Koltunski
  public boolean hasArgument()  { return true; }
67
  public int getPositive()      { return R.string.ok; }
68
  public int getNegative()      { return -1; }
69 e71baee1 Leszek Koltunski
  public void positiveAction()  { }
70
  public void negativeAction()  { }
71 1c89e2a7 Leszek Koltunski
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
74 1c04d054 leszek
  private String findCurrentVersion(Activity act)
75 1c89e2a7 Leszek Koltunski
    {
76 34d6b123 Leszek Koltunski
    String version;
77
    try
78 1c89e2a7 Leszek Koltunski
      {
79 34d6b123 Leszek Koltunski
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
80
      version= pInfo.versionName;
81 1c89e2a7 Leszek Koltunski
      }
82 34d6b123 Leszek Koltunski
    catch (PackageManager.NameNotFoundException e)
83
      {
84
      version= "unknown";
85
      }
86
87
    return version;
88 1c89e2a7 Leszek Koltunski
    }
89
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92 e71baee1 Leszek Koltunski
  @Override
93 1c04d054 leszek
  String getTitleString(FragmentActivity fact)
94 1c89e2a7 Leszek Koltunski
    {
95 e71baee1 Leszek Koltunski
    Resources res= getResources();
96 1c04d054 leszek
    Activity act= (Activity) getContext();
97
    String version= act!=null ? findCurrentVersion(act) : "unknown";
98 e71baee1 Leszek Koltunski
    return res.getString(R.string.ab_placeholder,version);
99
    }
100 1c89e2a7 Leszek Koltunski
101 e71baee1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
102 1c89e2a7 Leszek Koltunski
103 e71baee1 Leszek Koltunski
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
104
    {
105 b4ee249e Leszek Koltunski
    int width = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
106
    int sS= (int)(width*0.043f);
107
    int bS= (int)(width*0.060f);
108 24da418d Leszek Koltunski
109 b4ee249e Leszek Koltunski
    TextView shaV = view.findViewById(R.id.about_share_string);
110
    TextView emaV = view.findViewById(R.id.about_mail_string);
111
    TextView addV = view.findViewById(R.id.about_mail_address);
112
113
    TextView newV = view.findViewById(R.id.about_new_message);
114 24da418d Leszek Koltunski
    newV.setText(WHATS_NEW);
115 b4ee249e Leszek Koltunski
    TextView comV = view.findViewById(R.id.about_coming_message);
116 24da418d Leszek Koltunski
    comV.setText(WHATS_COMING);
117 d2f9fa0d Leszek Koltunski
118
    LinearLayout layoutShare = view.findViewById(R.id.about_share_layout);
119
120
    layoutShare.setOnClickListener(new View.OnClickListener()
121
       {
122
       @Override
123
       public void onClick(View v)
124
         {
125
         share(act);
126
         }
127
       });
128
129
    LinearLayout layoutEmail = view.findViewById(R.id.about_email_layout);
130
131
    layoutEmail.setOnClickListener(new View.OnClickListener()
132
       {
133
       @Override
134
       public void onClick(View v)
135
         {
136
         email(act);
137
         }
138
       });
139 b4ee249e Leszek Koltunski
140
    shaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
141
    emaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
142
    addV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
143
    newV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
144
    comV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
145 d2f9fa0d Leszek Koltunski
    }
146
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148
149
  private void share(FragmentActivity act)
150
    {
151
    Resources res = act.getResources();
152
    String name = res.getString(R.string.app_name);
153
154
    Intent intent = new Intent();
155
    intent.setAction(Intent.ACTION_SEND);
156
    intent.putExtra(Intent.EXTRA_TEXT,
157
    name+": https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
158
    intent.setType("text/plain");
159
160
    if (intent.resolveActivity(act.getPackageManager()) != null)
161
      {
162
      startActivity(intent);
163
      }
164
    }
165
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
168
  private void email(FragmentActivity act)
169
    {
170
    Resources res = act.getResources();
171
    String[] email = { res.getString(R.string.email_address) };
172 1c04d054 leszek
    String version = findCurrentVersion((Activity)act);
173 d2f9fa0d Leszek Koltunski
    String name = res.getString(R.string.app_name);
174
175
    Intent intent = new Intent(Intent.ACTION_SENDTO);
176
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
177
    intent.putExtra(Intent.EXTRA_EMAIL, email);
178
    intent.putExtra(Intent.EXTRA_SUBJECT, name+" "+version);
179
180
    if (intent.resolveActivity(act.getPackageManager()) != null)
181
      {
182
      startActivity(intent);
183
      }
184 1c89e2a7 Leszek Koltunski
    }
185
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187
188
  public static String getDialogTag()
189
    {
190 e71baee1 Leszek Koltunski
    return "DialogAbout";
191 1c89e2a7 Leszek Koltunski
    }
192
  }