Project

General

Profile

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

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

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).";
38

    
39
  private static final String WHATS_COMING =
40
      "1. iOS version.\n" +
41
      "2. Algorithmic solvers.\n" +
42
      "3. Support for adjustable stickers.\n" +
43
      "4. In-game currency (stars)\n" +
44
      "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
      "6. Creator of bandaged Pyraminxes.";
46

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

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

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

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

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

    
90
    return version;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

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

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

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

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

    
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

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

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

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