Project

General

Profile

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

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

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. Solvers: 2x2x3, Pyraminx & Skewb Diamond.\n" +
37
      "2. Implement Icosamate & Master Icosamate\n" +
38
      "3. Connect the solvers to the scrambling engine. Which means: from now on, " +
39
       "all puzzles which have a solver implemented will be perfectly scrambled " +
40
       " - i.e. any scramble at Level 7 will always require exactly 7 moves to solve. " +
41
       "Which also means that in some point in the future, we'll have to clear the High Scores.";
42

    
43
  private static final String WHATS_COMING =
44
      "1. More solvers (2x2, Skewb, Dino).\n" +
45
      "2. Support for adjustable stickers.\n" +
46
      "3. In-game currency (stars)\n" +
47
      "4. More objects (Penrose Cubes, higher-order Jings, Ghost Cubes, more Mirrors, more Mixups)\n" +
48
      "5. Creator of bandaged Pyraminxes.";
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
  @Override
53
  public void onResume()
54
    {
55
    super.onResume();
56

    
57
    Window window = getDialog().getWindow();
58

    
59
    if( window!=null )
60
      {
61
      WindowManager.LayoutParams params = window.getAttributes();
62
      params.width  = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
63
 //     params.height = (int)(mHeight*0.85f);
64
      window.setAttributes(params);
65
      }
66
    }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

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

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

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

    
93
    return version;
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  @Override
99
  String getTitleString(FragmentActivity act)
100
    {
101
    Resources res= getResources();
102
    RubikActivity ract= (RubikActivity) getContext();
103
    String version= ract!=null ? findCurrentVersion(ract) : "unknown";
104
    return res.getString(R.string.ab_placeholder,version);
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
110
    {
111
    int width = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
112
    int sS= (int)(width*0.043f);
113
    int bS= (int)(width*0.060f);
114

    
115
    TextView shaV = view.findViewById(R.id.about_share_string);
116
    TextView emaV = view.findViewById(R.id.about_mail_string);
117
    TextView addV = view.findViewById(R.id.about_mail_address);
118

    
119
    TextView newV = view.findViewById(R.id.about_new_message);
120
    newV.setText(WHATS_NEW);
121
    TextView comV = view.findViewById(R.id.about_coming_message);
122
    comV.setText(WHATS_COMING);
123

    
124
    LinearLayout layoutShare = view.findViewById(R.id.about_share_layout);
125

    
126
    layoutShare.setOnClickListener(new View.OnClickListener()
127
       {
128
       @Override
129
       public void onClick(View v)
130
         {
131
         share(act);
132
         }
133
       });
134

    
135
    LinearLayout layoutEmail = view.findViewById(R.id.about_email_layout);
136

    
137
    layoutEmail.setOnClickListener(new View.OnClickListener()
138
       {
139
       @Override
140
       public void onClick(View v)
141
         {
142
         email(act);
143
         }
144
       });
145

    
146
    shaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
147
    emaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS);
148
    addV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
149
    newV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
150
    comV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS);
151
    }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  private void share(FragmentActivity act)
156
    {
157
    Resources res = act.getResources();
158
    String name = res.getString(R.string.app_name);
159

    
160
    Intent intent = new Intent();
161
    intent.setAction(Intent.ACTION_SEND);
162
    intent.putExtra(Intent.EXTRA_TEXT,
163
    name+": https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
164
    intent.setType("text/plain");
165

    
166
    if (intent.resolveActivity(act.getPackageManager()) != null)
167
      {
168
      startActivity(intent);
169
      }
170
    }
171

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

    
174
  private void email(FragmentActivity act)
175
    {
176
    Resources res = act.getResources();
177
    String[] email = { res.getString(R.string.email_address) };
178
    String version = findCurrentVersion((RubikActivity)act);
179
    String name = res.getString(R.string.app_name);
180

    
181
    Intent intent = new Intent(Intent.ACTION_SENDTO);
182
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
183
    intent.putExtra(Intent.EXTRA_EMAIL, email);
184
    intent.putExtra(Intent.EXTRA_SUBJECT, name+" "+version);
185

    
186
    if (intent.resolveActivity(act.getPackageManager()) != null)
187
      {
188
      startActivity(intent);
189
      }
190
    }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

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