Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogAbout.java @ 2a37cfa4

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