Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogAbout.java @ 7464b393

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

    
26
import androidx.fragment.app.FragmentActivity;
27

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

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

    
33
public class RubikDialogAbout extends RubikDialogAbstract
34
  {
35
  private static final String WHATS_NEW =
36
      "1. Fix for 4x4 Penrose - now it correctly detects all solved states.\n" +
37
      "2. Sorry for lack of activity lately - I've been busy with private stuff. Now I'm resuming development! \n\nNext: algorithmic solvers";
38

    
39
  private static final String WHATS_COMING =
40
      "1. Algorithmic solvers. (sub-optimal solvers for larger puzzles such as the 4x4)\n" +
41
      "2. Support for sticker modes (Tartan Cube, Shepherd's Cube, etc).\n" +
42
      "3. iOS version (no time for this, anyone can help? Code is open-source)\n" +
43
      "4. More objects:\n    - Ghost Cubes\n    - more Mixups\n    - more Barrels\n";
44

    
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
      params.width  = (int)Math.min( mHeight*0.60f,mWidth*0.90f );
58
      window.setAttributes(params);
59
      }
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

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

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

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

    
87
    return version;
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  @Override
93
  String getTitleString(FragmentActivity fact)
94
    {
95
    Resources res= getResources();
96
    Activity act= (Activity) getContext();
97
    String version= act!=null ? findCurrentVersion(act) : "unknown";
98
    return res.getString(R.string.ab_placeholder,version);
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
104
    {
105
    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

    
109
    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
    newV.setText(WHATS_NEW);
115
    TextView comV = view.findViewById(R.id.about_coming_message);
116
    comV.setText(WHATS_COMING);
117

    
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

    
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
    }
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
    String version = findCurrentVersion((Activity)act);
173
    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
    }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
  public static String getDialogTag()
189
    {
190
    return "DialogAbout";
191
    }
192
  }
(2-2/24)