Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogAbout.java @ 58990dfd

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import android.content.Intent;
14
import android.content.pm.PackageInfo;
15
import android.content.pm.PackageManager;
16
import android.content.res.Resources;
17
import android.net.Uri;
18
import android.util.TypedValue;
19
import android.view.View;
20
import android.view.Window;
21
import android.view.WindowManager;
22
import android.widget.LinearLayout;
23
import android.widget.TextView;
24

    
25
import androidx.fragment.app.FragmentActivity;
26

    
27
import org.distorted.main.BuildConfig;
28
import org.distorted.main.R;
29
import org.distorted.main.RubikActivity;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class RubikDialogAbout extends RubikDialogAbstract
34
  {
35
  private static final String WHATS_NEW =
36
      "1. 3x3x2 Cuboid solver.\n" +
37
      "2. Support for 'coin' puzzles (Coin Tetrahedron, Ancient Coin Cube).\n" +
38
      "3. Improvements to the Highscores dialog.\n" +
39
      "4. Correct the Masterball (before it was nearly impossible to be solved)";
40

    
41
  private static final String WHATS_COMING =
42
      "1. iOS version.\n" +
43
      "2. Algorithmic solvers.\n" +
44
      "3. Support for adjustable stickers.\n" +
45
      "4. In-game currency (stars)\n" +
46
      "5. More objects:\n    - Penrose Cubes\n    - higher-order Jings\n    - Ghost Cubes\n    - more Mirrors\n    - more Mixups\n    - Ancient Coin Cube\n" +
47
      "6. Creator of bandaged Pyraminxes.";
48

    
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
      params.width  = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
62
 //     params.height = (int)(mHeight*0.85f);
63
      window.setAttributes(params);
64
      }
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  public int getResource()      { return R.layout.dialog_about; }
70
  public int getTitleResource() { return PARAMETRIC_TITLE; }
71
  public boolean hasArgument()  { return true; }
72
  public int getPositive()      { return R.string.ok; }
73
  public int getNegative()      { return -1; }
74
  public void positiveAction()  { }
75
  public void negativeAction()  { }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  private String findCurrentVersion(RubikActivity act)
80
    {
81
    String version;
82
    try
83
      {
84
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
85
      version= pInfo.versionName;
86
      }
87
    catch (PackageManager.NameNotFoundException e)
88
      {
89
      version= "unknown";
90
      }
91

    
92
    return version;
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  @Override
98
  String getTitleString(FragmentActivity act)
99
    {
100
    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

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
109
    {
110
    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

    
114
    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
    newV.setText(WHATS_NEW);
120
    TextView comV = view.findViewById(R.id.about_coming_message);
121
    comV.setText(WHATS_COMING);
122

    
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

    
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
    }
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
    }
190

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

    
193
  public static String getDialogTag()
194
    {
195
    return "DialogAbout";
196
    }
197
  }
(2-2/26)