Project

General

Profile

« Previous | Next » 

Revision b1e9596b

Added by Leszek Koltunski almost 4 years ago

Display the 'Privacy Policy' dialog (only if locale is set to ZH - chinese requirement)

View differences:

src/main/java/org/distorted/dialogs/RubikDialogAbout.java
79 79
    final View view = inflater.inflate(R.layout.dialog_about, null);
80 80
    TextView text = view.findViewById(R.id.about_version);
81 81
    String appName = getString(R.string.app_name);
82
    String appVers;
83 82

  
84
    try
85
      {
86
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
87
      appVers = pInfo.versionName;
88
      }
89
    catch (PackageManager.NameNotFoundException e)
90
      {
91
      appVers = "1.2.2";
92
      }
93 83

  
94 84
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
95
    text.setText(getString(R.string.ap_placeholder,appName, appVers));
85
    text.setText(getString(R.string.ap_placeholder,appName, getAppVers(act)));
96 86

  
97 87
    MovementMethod mm = LinkMovementMethod.getInstance();
98 88
    TextView text1 = view.findViewById(R.id.about_section1);
......
105 95
    text3.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
106 96
    text3.setMovementMethod(mm);
107 97

  
98
    TextView text4 = view.findViewById(R.id.about_section4);
99

  
100
    if( RubikActivity.localeIsChinese() )
101
      {
102
      text4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
103
      text4.setMovementMethod(mm);
104
      }
105
    else
106
      {
107
      text4.setVisibility(View.GONE);
108
      }
109

  
108 110
    builder.setView(view);
109 111

  
110 112
    Dialog dialog = builder.create();
......
128 130

  
129 131
    return dialog;
130 132
    }
133

  
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

  
136
  private String getAppVers(FragmentActivity act)
137
    {
138
    try
139
      {
140
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
141
      return pInfo.versionName;
142
      }
143
    catch (PackageManager.NameNotFoundException e)
144
      {
145
      return "unknown";
146
      }
147
    }
131 148
  }
src/main/java/org/distorted/dialogs/RubikDialogPrivacy.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.dialogs;
21

  
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
import android.text.method.LinkMovementMethod;
26
import android.text.method.MovementMethod;
27
import android.util.DisplayMetrics;
28
import android.util.TypedValue;
29
import android.view.LayoutInflater;
30
import android.view.View;
31
import android.widget.Button;
32
import android.widget.TextView;
33

  
34
import androidx.annotation.NonNull;
35
import androidx.appcompat.app.AlertDialog;
36
import androidx.appcompat.app.AppCompatDialogFragment;
37
import androidx.fragment.app.FragmentActivity;
38

  
39
import org.distorted.main.R;
40
import org.distorted.main.RubikActivity;
41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

  
44
public class RubikDialogPrivacy extends AppCompatDialogFragment
45
  {
46
  @NonNull
47
  @Override
48
  public Dialog onCreateDialog(Bundle savedInstanceState)
49
    {
50
    final RubikActivity ract = (RubikActivity)getContext();
51

  
52
    FragmentActivity act = getActivity();
53
    LayoutInflater inflater = act.getLayoutInflater();
54
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
55

  
56
    DisplayMetrics displaymetrics = new DisplayMetrics();
57
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
58
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
59
    final float butSize  = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
60

  
61
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
62
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
63
    tv.setText(R.string.privacy_policy);
64
    builder.setCustomTitle(tv);
65

  
66
    MovementMethod mm = LinkMovementMethod.getInstance();
67
    final View view = inflater.inflate(R.layout.dialog_privacy, null);
68
    TextView text = view.findViewById(R.id.privacy_string);
69
    text.setMovementMethod(mm);
70

  
71
    builder.setCancelable(true);
72

  
73
    builder.setPositiveButton( R.string.accept, new DialogInterface.OnClickListener()
74
      {
75
      @Override
76
      public void onClick(DialogInterface dialog, int which)
77
        {
78
        if( ract!=null ) ract.acceptPrivacy();
79
        }
80
      });
81

  
82
    builder.setNegativeButton( R.string.decline, new DialogInterface.OnClickListener()
83
      {
84
      @Override
85
      public void onClick(DialogInterface dialog, int which)
86
        {
87
        if( ract!=null ) ract.declinePrivacy();
88
        }
89
      });
90

  
91
    builder.setView(view);
92

  
93
    final Dialog dialog = builder.create();
94
    dialog.setCanceledOnTouchOutside(false);
95

  
96
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
97
      {
98
      @Override
99
      public void onShow(DialogInterface dialog)
100
        {
101
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
102
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
103
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
104
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
105
        }
106
      });
107

  
108
    return dialog;
109
    }
110
  }
src/main/java/org/distorted/main/RubikActivity.java
20 20
package org.distorted.main;
21 21

  
22 22
import android.content.SharedPreferences;
23
import android.os.Build;
23 24
import android.os.Bundle;
25
import android.os.LocaleList;
24 26
import android.preference.PreferenceManager;
25 27
import androidx.appcompat.app.AppCompatActivity;
26 28

  
......
29 31
import com.google.firebase.analytics.FirebaseAnalytics;
30 32

  
31 33
import org.distorted.dialogs.RubikDialogError;
34
import org.distorted.dialogs.RubikDialogPrivacy;
32 35
import org.distorted.effects.BaseEffect;
33 36
import org.distorted.library.main.DistortedLibrary;
34 37

  
......
39 42
import org.distorted.states.RubikState;
40 43
import org.distorted.states.RubikStatePlay;
41 44

  
45
import java.util.Locale;
46

  
42 47
///////////////////////////////////////////////////////////////////////////////////////////////////
43 48

  
44 49
public class RubikActivity extends AppCompatActivity
......
62 67
    private boolean mJustStarted;
63 68
    private FirebaseAnalytics mFirebaseAnalytics;
64 69
    private static int mScreenWidth, mScreenHeight;
70
    private boolean mPolicyAccepted, mIsChinese;
65 71

  
66 72
///////////////////////////////////////////////////////////////////////////////////////////////////
67 73

  
......
79 85
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
80 86
      mScreenWidth =displaymetrics.widthPixels;
81 87
      mScreenHeight=displaymetrics.heightPixels;
88

  
89
      mIsChinese = localeIsChinese();
82 90
      }
83 91

  
84 92
///////////////////////////////////////////////////////////////////////////////////////////////////
......
141 149
        play.setObjectAndSize(this,obj,s);
142 150
        view.getPreRender().changeObject(obj,s);
143 151
        }
152

  
153
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
144 154
      }
145 155
    
146 156
///////////////////////////////////////////////////////////////////////////////////////////////////
......
159 169
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
160 170
      SharedPreferences.Editor editor = preferences.edit();
161 171

  
172
      editor.putBoolean("policyAccepted", mPolicyAccepted);
173

  
162 174
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
163 175
        {
164 176
        BaseEffect.Type.getType(i).savePreferences(editor);
......
182 194
      {
183 195
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
184 196

  
197
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
198

  
185 199
      for (int i=0; i< BaseEffect.Type.LENGTH; i++)
186 200
        {
187 201
        BaseEffect.Type.getType(i).restorePreferences(preferences);
......
198 212
      view.getPreRender().restorePreferences(preferences);
199 213
      }
200 214

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

  
217
    private void PrivacyPolicy()
218
      {
219
      RubikDialogPrivacy priDiag = new RubikDialogPrivacy();
220
      priDiag.show(getSupportFragmentManager(), null);
221
      }
222

  
201 223
///////////////////////////////////////////////////////////////////////////////////////////////////
202 224

  
203 225
    void OpenGLError(String message)
......
309 331
      {
310 332
      if( mScreenHeight<1000 )
311 333
        {
312
        //android.util.Log.e("view", "returning small, mScrH="+mScreenHeight);
313 334
        return 0;
314 335
        }
315 336
      if( mScreenHeight<1600 )
316 337
        {
317
        //android.util.Log.e("view", "returning medium, mScrH="+mScreenHeight);
318 338
        return 1;
319 339
        }
320 340
      if( mScreenHeight<1900 )
321 341
        {
322
        //android.util.Log.e("view", "returning bug, mScrH="+mScreenHeight);
323 342
        return 2;
324 343
        }
325 344

  
326
      //android.util.Log.e("view", "returning huge, mScrH="+mScreenHeight);
327 345
      return 3;
328 346
      }
329 347

  
......
342 360
        }
343 361
      }
344 362

  
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

  
365
    public void acceptPrivacy()
366
      {
367
      mPolicyAccepted = true;
368
      }
369

  
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

  
372
    public void declinePrivacy()
373
      {
374
      finish();
375
      }
376

  
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

  
379
    public static boolean localeIsChinese()
380
      {
381
      String language;
382

  
383
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
384
        {
385
        language= LocaleList.getDefault().get(0).getLanguage();
386
        }
387
      else
388
        {
389
        language= Locale.getDefault().getLanguage();
390
        }
391

  
392
      return language.equals("zh");
393
      }
394

  
345 395
///////////////////////////////////////////////////////////////////////////////////////////////////
346 396

  
347 397
    public boolean isVertical()
src/main/res/layout/dialog_about.xml
56 56
            android:layout_marginRight="10dp"
57 57
            android:text="@string/credits3"/>
58 58

  
59
        <TextView
60
            android:id="@+id/about_section4"
61
            android:layout_width="match_parent"
62
            android:layout_height="fill_parent"
63
            android:layout_weight="0.20"
64
            android:layout_marginBottom="10dp"
65
            android:layout_marginTop="10dp"
66
            android:layout_marginLeft="10dp"
67
            android:layout_marginRight="10dp"
68
            android:text="@string/credits4"/>
69

  
59 70
    </LinearLayout>
60 71

  
61 72
</ScrollView>
src/main/res/layout/dialog_privacy.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:gravity="center|fill_horizontal"
6
    android:layout_marginLeft="10dp"
7
    android:layout_marginRight="10dp"
8
    android:layout_marginTop="0dp"
9
    android:background="@color/grey"
10
    android:orientation="vertical">
11

  
12
    <TextView
13
        android:id="@+id/privacy_string"
14
        android:layout_width="match_parent"
15
        android:layout_height="match_parent"
16
        android:gravity="center"
17
        android:textSize="24sp"
18
        android:text="@string/privacy_policy_text"
19
        android:layout_marginTop="10dp"
20
        android:layout_marginLeft="10dp"
21
        android:layout_marginRight="10dp"
22
        android:layout_marginBottom="10dp"/>
23
</LinearLayout>
src/main/res/values-zh-rCN/strings.xml
34 34
    <string name="new_name_try_again">您选择的名称,%s,已被使用。请重试:</string>
35 35
    <string name="downloading">正在下载……</string>
36 36
    <string name="submitting">正在提交……</string>
37
    <string name="privacy_policy">隐私政策</string>
38
    <string name="privacy_policy_text">Please see and accept our <a href="https://distorted.org/redmine/projects/magic-cube/wiki/%E9%9A%90%E7%A7%81%E6%94%BF%E7%AD%96">隐私政策</a></string>
39
    <string name="accept">Accept</string>
40
    <string name="decline">Decline</string>
37 41
    <string name="credits1">此应用程式原始码开发使用Distorted图型库。根据<a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">通用公共许可版本2</a>或者任何更新版本(根据您的选择)进行许可。</string>
38 42
    <string name="credits2">Pretty Patterns by Werner Randelshofer. 請看 <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
39
    <string name="credits3">下载代码,浏览教程,学习如何添加自己的图形效果,学习如何编写自己的专案,创造美丽图案,实现自己的求解器,或者报告错误:\n\n<a href="https://distorted.org/redmine/projects/magic-cube/wiki">Distorted.org</a>
43
    <string name="credits3">下载代码,浏览教程,学习如何添加自己的图形效果,学习如何编写自己的专案,创造美丽图案,实现自己的求解器,或者报告错误:<a href="https://distorted.org/redmine/projects/magic-cube/wiki">Distorted.org</a>
40 44
  </string>
45
    <string name="credits4">Please see our <a href="https://distorted.org/redmine/projects/magic-cube/wiki/%E9%9A%90%E7%A7%81%E6%94%BF%E7%AD%96">隐私政策</a></string>
41 46

  
42 47
    <string name="solver_generic_error1">此对象和尺寸的求解器尚未实现!</string>
43 48

  
src/main/res/values/strings.xml
36 36
    <string name="new_name_try_again">The name you have chosen, %s, is already taken. Try again:</string>
37 37
    <string name="downloading">Downloading…</string>
38 38
    <string name="submitting">Submitting…</string>
39
    <string name="privacy_policy">Privacy Policy</string>
40
    <string name="privacy_policy_text">Please see and accept our <a href="https://distorted.org/redmine/projects/magic-cube/wiki/Privacy_policy">Privacy Policy</a></string>
41
    <string name="accept">Accept</string>
42
    <string name="decline">Decline</string>
39 43
    <string name="credits1">Open Source app developed using the Distorted graphics library. Licensed under <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPL version 2</a> or - at your option - any later version.</string>
40 44
    <string name="credits2">Pretty Patterns by Walter Randelshofer. See <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
41 45
    <string name="credits3">Download code, take a look at tutorials, learn how to add your own graphics effect, learn how to code your own object, contribute a Pretty Pattern, implement your own solver, or report a bug: \n\n<a href="https://distorted.org/redmine/projects/magic-cube/wiki">Distorted.org</a></string>
46
    <string name="credits4">Please see our <a href="https://distorted.org/redmine/projects/magic-cube/wiki/Privacy_policy">Privacy Policy</a></string>
42 47

  
43 48
    <string name="solver_generic_error1">Solver for this object and size not implemented yet!</string>
44 49

  

Also available in: Unified diff