Project

General

Profile

« Previous | Next » 

Revision 3e26ff35

Added by Leszek Koltunski over 2 years ago

  • ID 3e26ff354215fad5ee77203fde09d7c31c0dc23f
  • Parent 3441bb94

About Dialog

View differences:

distorted-sokoban/src/main/java/helpers/TransparentButton.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 helpers;
11

  
12
import android.annotation.SuppressLint;
13
import android.content.Context;
14
import android.util.TypedValue;
15
import android.widget.LinearLayout;
16

  
17
import com.google.android.material.button.MaterialButton;
18

  
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

  
21
@SuppressLint("ViewConstructor")
22
public class TransparentButton extends MaterialButton
23
{
24
   public TransparentButton(Context context, int resId, float textSize)
25
      {
26
      this(context, resId, textSize, 1.0f);
27
      }
28

  
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

  
31
   public TransparentButton(Context context, int resId, float textSize, float weight)
32
      {
33
      super(context);
34

  
35
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, weight);
36

  
37
      setLayoutParams(params);
38
      setPadding(0,0,0,0);
39
      setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
40
      setText(resId);
41

  
42
      TypedValue outValue = new TypedValue();
43
      context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
44
      setBackgroundResource(outValue.resourceId);
45
      }
46
}
distorted-sokoban/src/main/java/helpers/TransparentImageButton.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 helpers;
11

  
12
import android.annotation.SuppressLint;
13
import android.content.Context;
14
import android.util.TypedValue;
15
import android.widget.LinearLayout;
16

  
17
import com.google.android.material.button.MaterialButton;
18

  
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

  
21
@SuppressLint("ViewConstructor")
22
public class TransparentImageButton extends MaterialButton
23
{
24
  public static final int GRAVITY_START  = 0;
25
  public static final int GRAVITY_MIDDLE = 1;
26
  public static final int GRAVITY_END    = 2;
27

  
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

  
30
  public TransparentImageButton(Context context, int icon, int gravity, LinearLayout.LayoutParams params)
31
    {
32
    super(context);
33

  
34
    setLayoutParams(params);
35
    setPadding(0,0,0,0);
36
    setIconResource(icon);
37
    setIconTint(null);
38

  
39
    switch(gravity)
40
      {
41
      case GRAVITY_START : setIconGravity(MaterialButton.ICON_GRAVITY_START     ); break;
42
      case GRAVITY_MIDDLE: setIconGravity(MaterialButton.ICON_GRAVITY_TEXT_START); break;
43
      case GRAVITY_END   : setIconGravity(MaterialButton.ICON_GRAVITY_END       ); break;
44
      }
45

  
46
    TypedValue outValue = new TypedValue();
47
    context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
48
    setBackgroundResource(outValue.resourceId);
49
    }
50
}
distorted-sokoban/src/main/java/org/distorted/dialogs/SokobanDialogAbout.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Sokoban.                                                           //
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.DialogInterface;
14
import android.content.pm.PackageInfo;
15
import android.content.pm.PackageManager;
16
import android.os.Bundle;
17
import androidx.annotation.NonNull;
18
import androidx.fragment.app.FragmentActivity;
19
import androidx.appcompat.app.AlertDialog;
20
import androidx.appcompat.app.AppCompatDialogFragment;
21

  
22
import android.util.DisplayMetrics;
23
import android.util.TypedValue;
24
import android.view.LayoutInflater;
25
import android.view.View;
26
import android.view.Window;
27
import android.widget.Button;
28
import android.widget.TextView;
29

  
30
import org.distorted.sokoban.R;
31
import org.distorted.sokoban.SokobanActivity;
32

  
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

  
35
public class SokobanDialogAbout extends AppCompatDialogFragment
36
  {
37
  @NonNull
38
  @Override
39
  public Dialog onCreateDialog(Bundle savedInstanceState)
40
    {
41
    FragmentActivity act = getActivity();
42
    LayoutInflater inflater = act.getLayoutInflater();
43
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
44

  
45
    DisplayMetrics displaymetrics = new DisplayMetrics();
46
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
47
    final float titleSize= displaymetrics.widthPixels * SokobanActivity.MENU_BIG_TEXT_SIZE;
48
    final float okSize   = displaymetrics.widthPixels * SokobanActivity.DIALOG_BUTTON_SIZE;
49
    final float textSize = displaymetrics.widthPixels * SokobanActivity.MENU_SMALL_TEXT_SIZE;
50

  
51
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
52
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
53
    tv.setText(R.string.about);
54
    builder.setCustomTitle(tv);
55

  
56
    builder.setCancelable(true);
57
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
58
      {
59
      @Override
60
      public void onClick(DialogInterface dialog, int which)
61
        {
62

  
63
        }
64
      });
65

  
66
    final View view = inflater.inflate(R.layout.dialog_about, null);
67
    TextView text = view.findViewById(R.id.about_version);
68
    String appName = getString(R.string.app_name);
69

  
70
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
71
    text.setText(getString(R.string.ap_placeholder,appName, getAppVers(act)));
72

  
73
    TextView help = view.findViewById(R.id.about_help);
74
    help.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
75

  
76
    builder.setView(view);
77

  
78
    Dialog dialog = builder.create();
79
    dialog.setCanceledOnTouchOutside(false);
80
    Window window = dialog.getWindow();
81

  
82
    if( window!=null )
83
      {
84
      window.getDecorView().setSystemUiVisibility(SokobanActivity.FLAGS);
85
      }
86

  
87
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
88
      {
89
      @Override
90
      public void onShow(DialogInterface dialog)
91
        {
92
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
93
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
94
        }
95
      });
96

  
97
    return dialog;
98
    }
99

  
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

  
102
  private String getAppVers(FragmentActivity act)
103
    {
104
    try
105
      {
106
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
107
      return pInfo.versionName;
108
      }
109
    catch (PackageManager.NameNotFoundException e)
110
      {
111
      return "unknown";
112
      }
113
    }
114
  }
distorted-sokoban/src/main/java/org/distorted/helpers/TransparentButton.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.helpers;
11

  
12
import android.annotation.SuppressLint;
13
import android.content.Context;
14
import android.util.TypedValue;
15
import android.widget.LinearLayout;
16

  
17
import com.google.android.material.button.MaterialButton;
18

  
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

  
21
@SuppressLint("ViewConstructor")
22
public class TransparentButton extends MaterialButton
23
{
24
   public TransparentButton(Context context, int resId, float textSize)
25
      {
26
      this(context, resId, textSize, 1.0f);
27
      }
28

  
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

  
31
   public TransparentButton(Context context, int resId, float textSize, float weight)
32
      {
33
      super(context);
34

  
35
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, weight);
36

  
37
      setLayoutParams(params);
38
      setPadding(0,0,0,0);
39
      setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
40
      setText(resId);
41

  
42
      TypedValue outValue = new TypedValue();
43
      context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
44
      setBackgroundResource(outValue.resourceId);
45
      }
46
}
distorted-sokoban/src/main/java/org/distorted/helpers/TransparentImageButton.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.helpers;
11

  
12
import android.annotation.SuppressLint;
13
import android.content.Context;
14
import android.util.TypedValue;
15
import android.widget.LinearLayout;
16

  
17
import com.google.android.material.button.MaterialButton;
18

  
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

  
21
@SuppressLint("ViewConstructor")
22
public class TransparentImageButton extends MaterialButton
23
{
24
  public static final int GRAVITY_START  = 0;
25
  public static final int GRAVITY_MIDDLE = 1;
26
  public static final int GRAVITY_END    = 2;
27

  
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

  
30
  public TransparentImageButton(Context context, int icon, int gravity, LinearLayout.LayoutParams params)
31
    {
32
    super(context);
33

  
34
    setLayoutParams(params);
35
    setPadding(0,0,0,0);
36
    setIconResource(icon);
37
    setIconTint(null);
38

  
39
    switch(gravity)
40
      {
41
      case GRAVITY_START : setIconGravity(MaterialButton.ICON_GRAVITY_START     ); break;
42
      case GRAVITY_MIDDLE: setIconGravity(MaterialButton.ICON_GRAVITY_TEXT_START); break;
43
      case GRAVITY_END   : setIconGravity(MaterialButton.ICON_GRAVITY_END       ); break;
44
      }
45

  
46
    TypedValue outValue = new TypedValue();
47
    context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
48
    setBackgroundResource(outValue.resourceId);
49
    }
50
}
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanActivity.java
19 19

  
20 20
package org.distorted.sokoban;
21 21

  
22
import android.app.Activity;
23 22
import android.os.Build;
24 23
import android.os.Bundle;
25 24
import android.util.DisplayMetrics;
......
33 32
import android.widget.LinearLayout;
34 33
import android.widget.TextView;
35 34

  
36
import helpers.TransparentImageButton;
35
import androidx.appcompat.app.AppCompatActivity;
36

  
37
import org.distorted.dialogs.SokobanDialogAbout;
38
import org.distorted.helpers.TransparentImageButton;
37 39

  
38 40
///////////////////////////////////////////////////////////////////////////////////////////////////
39 41

  
40
public class SokobanActivity extends Activity
42
public class SokobanActivity extends AppCompatActivity
41 43
  {
42 44
  private static final float RATIO_BAR    = 0.10f;
43 45
  private static final float RATIO_INSET  = 0.09f;
44 46
  private static final float MENU_SIZE    = 0.05f;
45 47

  
48
  public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
49
  public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
50
  public static final float DIALOG_BUTTON_SIZE  = 0.06f;
51

  
46 52
  public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
47 53
                                 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
48 54
                                 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
......
53 59

  
54 60
  private int mHeightUpperBar;
55 61
  private int mCurrentApiVersion;
56
  private TransparentImageButton mRecordsButton, mExitButton;
62
  private TransparentImageButton mRecordsButton, mAboutButton;
57 63
  private TextView mAppName;
58 64

  
59 65
///////////////////////////////////////////////////////////////////////////////////////////////////
......
158 164
    upper.addView(mRecordsButton);
159 165
    setupAppName();
160 166
    upper.addView(mAppName);
161
    setupExitButton();
162
    upper.addView(mExitButton);
167
    setupAboutButton();
168
    upper.addView(mAboutButton);
163 169
    }
164 170

  
165 171
///////////////////////////////////////////////////////////////////////////////////////////////////
......
182 188

  
183 189
///////////////////////////////////////////////////////////////////////////////////////////////////
184 190

  
185
  private void setupExitButton()
191
  private void setupAboutButton()
186 192
    {
187
    final int icon = getDrawable(R.drawable.ui_exit_s,R.drawable.ui_exit_m, R.drawable.ui_exit_b, R.drawable.ui_exit_h);
193
    final int icon = getDrawable(R.drawable.ui_info_s,R.drawable.ui_info_m, R.drawable.ui_info_b, R.drawable.ui_info_h);
188 194
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
189
    mExitButton = new TransparentImageButton(this, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
195
    mAboutButton = new TransparentImageButton(this, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
190 196

  
191
    mExitButton.setOnClickListener( new View.OnClickListener()
197
    mAboutButton.setOnClickListener( new View.OnClickListener()
192 198
      {
193 199
      @Override
194 200
      public void onClick(View view)
195 201
        {
196
        finish();
202
        SokobanDialogAbout aDiag = new SokobanDialogAbout();
203
        aDiag.show( getSupportFragmentManager(), null);
197 204
        }
198 205
      });
199 206
    }
distorted-sokoban/src/main/res/layout/dialog_about.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent">
5

  
6
    <LinearLayout
7
        android:layout_width="fill_parent"
8
        android:layout_height="wrap_content"
9
        android:gravity="center|fill_horizontal"
10
        android:layout_marginLeft="10dp"
11
        android:layout_marginRight="10dp"
12
        android:layout_marginTop="0dp"
13
        android:background="@color/grey"
14
        android:orientation="vertical">
15

  
16
        <TextView
17
            android:id="@+id/about_version"
18
            android:layout_width="match_parent"
19
            android:layout_height="fill_parent"
20
            android:layout_weight="0.40"
21
            android:layout_marginTop="10dp"
22
            android:layout_marginLeft="10dp"
23
            android:layout_marginRight="10dp"
24
            android:layout_marginBottom="10dp"/>
25

  
26
        <TextView
27
            android:id="@+id/about_help"
28
            android:layout_width="match_parent"
29
            android:layout_height="fill_parent"
30
            android:layout_weight="0.80"
31
            android:layout_marginTop="10dp"
32
            android:layout_marginLeft="10dp"
33
            android:layout_marginRight="10dp"
34
            android:layout_marginBottom="10dp"
35
            android:text="@string/helptxt"/>
36

  
37
    </LinearLayout>
38

  
39
</ScrollView>
distorted-sokoban/src/main/res/layout/dialog_title.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3
  android:layout_width="match_parent"
4
  android:layout_height="match_parent"
5
  android:textSize="20sp"
6
  android:gravity="center"
7
  android:padding="10dp"/>
distorted-sokoban/src/main/res/layout/splash.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
  android:layout_width="fill_parent"
5
  android:layout_height="fill_parent"
6
  android:gravity="center"
7
  android:background="#FFFFFF">
8
  <ImageView 
9
      android:id="@+id/splashimage"
10
      android:src="@drawable/splash"
11
      android:layout_gravity="center"
12
      android:layout_width="wrap_content"
13
      android:layout_height="wrap_content"
14
      android:layout_centerHorizontal="true"/>
15
  <TextView 
16
  	  android:id="@+id/splashtext"
17
  	  android:layout_width="wrap_content"
18
      android:layout_height="wrap_content"
19
      android:text="@string/splash"
20
      android:textColor="#65bd45"
21
      android:textSize="24dp"
22
      android:layout_centerHorizontal="true"
23
      android:layout_below="@id/splashimage"/>
24
</RelativeLayout>
distorted-sokoban/src/main/res/values/strings.xml
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<resources>
3 3
    <string name="app_name">Magic Sokoban</string>
4
    <string name="splash">ThreeDCell presents</string>
5 4
    <string name="error">Startup error!!</string>
6 5
    <string name="email">sokoban@koltunski.pl</string>
7 6
    <string name="level">Level</string>
......
9 8
    <string name="questions">Questions?</string>
10 9
    <string name="yourbest">Your best:</string>
11 10
    <string name="worldsbest">World\'s best:</string>
12
    <string name="helptxt">Your goal is to move all the crates (yellow squares) to destination squares (marked with blue crosses). You can only push a crate, never pull it.\n\nYou can also create your own levels (go to Options -> Create New Level) and download levels created by others. Enjoy!</string>
11
    <string name="helptxt">Your goal is to move all the crates (yellow squares) to destination squares (marked with blue crosses). You can only push a crate, never pull it.</string>
13 12
    <string name="newr">New Record</string>
14 13
    <string name="subm">Submit it online?</string>
15 14
    <string name="moves">moves</string>
......
68 67
    <string name="ods">of destination squares</string>
69 68

  
70 69
    <string name="level_image">Level Image</string>
70
    <string name="about">About</string>
71

  
72
    <string name="ap_placeholder">%1$s %2$s</string>
71 73
</resources>

Also available in: Unified diff