Project

General

Profile

« Previous | Next » 

Revision 9c39179e

Added by Leszek Koltunski over 2 years ago

Downloading updates: dialog progress.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.Activity;
23
import android.view.View;
24
import android.widget.Button;
25
import android.widget.TextView;
26

  
27
import org.distorted.main.R;
28
import org.distorted.network.RubikUpdates;
29
import org.distorted.objectlib.json.JsonWriter;
30

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

  
33
public class RubikDialogUpdateView
34
  {
35
  private View mView;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39
  public RubikDialogUpdateView()
40
    {
41

  
42
    }
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
  public View createView(Activity act, RubikUpdates.UpdateInfo info, boolean isNew)
47
    {
48
    int layoutID = R.layout.dialog_updates_pane;
49
    mView = act.getLayoutInflater().inflate(layoutID, null);
50
    Button install = mView.findViewById(R.id.updates_pane_button);
51

  
52
    install.setOnClickListener( new View.OnClickListener()
53
      {
54
      @Override
55
      public void onClick(View v)
56
        {
57
        android.util.Log.e("D", "INSTALL pressed");
58
        }
59
      });
60

  
61
    TextView title = mView.findViewById(R.id.updates_pane_title);
62
    title.setText(info.mObjectLongName);
63
    TextView version = mView.findViewById(R.id.updates_pane_version);
64
    String strVersion = info.mUpdateObject
65
                        ? JsonWriter.VERSION_OBJECT_MAJOR+"."+info.mObjectMinorVersion
66
                        : JsonWriter.VERSION_EXTRAS_MAJOR+"."+info.mExtrasMinorVersion;
67
    version.setText(strVersion);
68
    TextView description = mView.findViewById(R.id.updates_pane_description);
69
    description.setText(info.mDescription);
70

  
71
    return mView;
72
    }
73
  }
src/main/java/org/distorted/dialogs/RubikDialogUpdates.java
20 20
package org.distorted.dialogs;
21 21

  
22 22
import android.app.Dialog;
23
import android.content.Context;
23 24
import android.content.DialogInterface;
24 25
import android.os.Bundle;
25 26
import android.util.DisplayMetrics;
......
27 28
import android.view.LayoutInflater;
28 29
import android.view.View;
29 30
import android.view.Window;
31
import android.view.WindowManager;
30 32
import android.widget.Button;
33
import android.widget.LinearLayout;
34
import android.widget.ScrollView;
31 35
import android.widget.TextView;
32 36

  
33 37
import androidx.annotation.NonNull;
......
44 48

  
45 49
public class RubikDialogUpdates extends AppCompatDialogFragment implements RubikNetwork.Updatee
46 50
  {
47
  private View createView(LayoutInflater inflater)
51
  private TextView mText;
52
  private ScrollView mScroll;
53
  private LinearLayout mLayout;
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  private View createView(FragmentActivity act, LayoutInflater inflater, float size)
48 58
    {
49 59
    final View view = inflater.inflate(R.layout.dialog_updates, null);
50 60

  
51
    TextView text = view.findViewById(R.id.about_version);
52
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, 50);
53
    text.setText("ggggg ruyujk j k");
61
    mLayout= view.findViewById(R.id.updates_main_layout);
62
    mScroll= view.findViewById(R.id.updates_scroll);
63
    mText  = view.findViewById(R.id.updates_message);
64
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
65
    mText.setText( act.getString(R.string.downloading) );
54 66

  
55 67
    return view;
56 68
    }
......
70 82
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
71 83
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
72 84

  
73
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
74
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
75
    tv.setText(R.string.updates);
76
    builder.setCustomTitle(tv);
85
    TextView title = (TextView) inflater.inflate(R.layout.dialog_title, null);
86
    title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
87
    title.setText(R.string.updates);
88
    builder.setCustomTitle(title);
77 89

  
78 90
    builder.setCancelable(true);
79 91
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
......
85 97
        }
86 98
      });
87 99

  
88
    View view = createView(inflater);
100
    View view = createView(act,inflater,okSize);
89 101
    builder.setView(view);
90 102

  
91 103
    Dialog dialog = builder.create();
......
107 119
        }
108 120
      });
109 121

  
122
    return dialog;
123
    }
124

  
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

  
127
  @Override
128
  public void onResume()
129
    {
130
    super.onResume();
131

  
110 132
    RubikNetwork network = RubikNetwork.getInstance();
111 133
    network.signUpForUpdates(this);
112 134

  
113
    return dialog;
135
    Window window = getDialog().getWindow();
136
    Context context = getContext();
137

  
138
    if( window!=null && context!=null )
139
      {
140
      DisplayMetrics metrics = context.getResources().getDisplayMetrics();
141
      final float height= metrics.heightPixels;
142

  
143
      WindowManager.LayoutParams params = window.getAttributes();
144
      params.width = WindowManager.LayoutParams.WRAP_CONTENT;
145
      params.height = (int)(0.75f*height);
146
      window.setAttributes(params);
147

  
148
      int textHeight = (int)(0.8f*params.height);
149
      mText.setHeight(textHeight);
150
      }
114 151
    }
115 152

  
116 153
///////////////////////////////////////////////////////////////////////////////////////////////////
117 154

  
118 155
  public void receiveUpdate(RubikUpdates updates)
119 156
    {
157
    FragmentActivity act = getActivity();
158
    int numN = updates.getNewNumber();
159
    int numU = updates.getUpdNumber();
160
    int num = numN+numU;
120 161

  
162
    if( num<=0 )
163
      {
164
      mScroll.setVerticalScrollBarEnabled(false);
165
      mText.setText(act.getString(R.string.no_updates));
166
      }
167
    else
168
      {
169
      mText.setVisibility(View.GONE);
170

  
171
      if( mLayout!=null )
172
        {
173
        for(int i=0; i<numN; i++)
174
          {
175
          RubikUpdates.UpdateInfo info = updates.getNewUpdate(i);
176
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
177
          View pane = rubikView.createView(act,info,true);
178
          mLayout.addView(pane);
179
          }
180
        for(int i=0; i<numU; i++)
181
          {
182
          RubikUpdates.UpdateInfo info = updates.getUpdUpdate(i);
183
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
184
          View pane = rubikView.createView(act,info,false);
185
          mLayout.addView(pane);
186
          }
187
        }
188
      else
189
        {
190
        android.util.Log.e("D", "mainLayout NULL");
191
        }
192
      }
121 193
    }
122 194

  
123 195
///////////////////////////////////////////////////////////////////////////////////////////////////
124 196

  
125 197
  public void errorUpdate()
126 198
    {
127
    android.util.Log.e("D", "Dialog: Error receiving update");
199
    mScroll.setVerticalScrollBarEnabled(false);
200
    mText.setText("Network error");
128 201
    }
129 202

  
130 203
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/main/RubikActivity.java
86 86
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
87 87
    public static final float TAB_WIDTH           = 0.100f;
88 88
    public static final float TAB_HEIGHT          = 0.100f;
89
    public static final float BUBBLE_SIZE         = 0.15f;
89 90

  
90 91
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
91 92
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
src/main/java/org/distorted/network/RubikUpdates.java
164 164

  
165 165
///////////////////////////////////////////////////////////////////////////////////////////////////
166 166

  
167
  public int getNumberOfUpdates()
167
  public UpdateInfo getNewUpdate(int ordinal)
168 168
    {
169
    return mNew.size()+mUpd.size();
169
    return mNew.get(ordinal);
170
    }
171

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

  
174
  public UpdateInfo getUpdUpdate(int ordinal)
175
    {
176
    return mUpd.get(ordinal);
177
    }
178

  
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

  
181
  public int getNewNumber()
182
    {
183
    return mNew.size();
184
    }
185

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

  
188
  public int getUpdNumber()
189
    {
190
    return mUpd.size();
170 191
    }
171 192

  
172 193
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/screens/RubikScreenPlay.java
78 78
  private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
79 79
  private LinearLayout mPlayLayout;
80 80
  private TextView mBubbleUpdates;
81
  private RubikUpdates mUpdates;
82 81
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
83 82
  private int mLevelValue;
84 83
  private float mButtonSize, mMenuItemSize, mMenuTextSize;
......
86 85
  private int mUpperBarHeight;
87 86
  private boolean mShouldReactToEndOfScrambling;
88 87
  private int mBottomHeight;
88
  private float mScreenWidth;
89 89

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

  
......
99 99
  void enterScreen(final RubikActivity act)
100 100
    {
101 101
    int numObjects = RubikObjectList.getNumObjects();
102
    float width = act.getScreenWidthInPixels();
102
    mScreenWidth = act.getScreenWidthInPixels();
103 103
    mUpperBarHeight = act.getHeightUpperBar();
104 104

  
105
    mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE;
106
    mButtonSize   = width*RubikActivity.BUTTON_TEXT_SIZE;
107
    mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE;
105
    mMenuTextSize = mScreenWidth*RubikActivity.MENU_MED_TEXT_SIZE;
106
    mButtonSize   = mScreenWidth*RubikActivity.BUTTON_TEXT_SIZE;
107
    mMenuItemSize = mScreenWidth*RubikActivity.MENU_ITEM_SIZE;
108 108

  
109 109
    mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
110 110
    mColCount = NUM_COLUMNS;
......
113 113
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
114 114
    layoutTop.removeAllViews();
115 115

  
116
    setupObjectButton(act,width);
116
    setupObjectButton(act,mScreenWidth);
117 117
    layoutTop.addView(mObjButton);
118 118

  
119
    setupMenuButton(act,width);
119
    setupMenuButton(act,mScreenWidth);
120 120
    layoutTop.addView(mMenuButton);
121 121

  
122
    setupPlayButton(act,width);
122
    setupPlayButton(act,mScreenWidth);
123 123
    layoutTop.addView(mPlayButton);
124 124

  
125 125
    setupSolveButton(act);
......
707 707
    {
708 708
    updates.showDebug();
709 709

  
710
    mUpdates = updates;
711
    int num = mUpdates.getNumberOfUpdates();
710
    int numN = updates.getNewNumber();
711
    int numU = updates.getUpdNumber();
712
    int num = numN+numU;
712 713

  
713 714
    if( num>0 )
714 715
      {
715 716
      String shownNum = String.valueOf(num);
716 717
      mBubbleUpdates.setText(shownNum);
717 718
      mBubbleUpdates.setVisibility(View.VISIBLE);
719
      int height = (int)(0.05f*mScreenWidth);
720
      mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height);
718 721
      }
719 722
    else
720 723
      {
src/main/res/layout/dialog_updates.xml
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:id="@+id/updates_scroll"
3 4
    android:layout_width="match_parent"
4
    android:layout_height="match_parent">
5
    android:layout_height="wrap_content"
6
    android:paddingLeft="10dp"
7
    android:paddingRight="10dp">
5 8

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

  
17

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

  
28 24
    </LinearLayout>
29 25

  
src/main/res/layout/dialog_updates_pane.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout
3
	xmlns:android="http://schemas.android.com/apk/res/android"
4
	android:layout_width="match_parent"
5
	android:layout_height="wrap_content"
6
	android:orientation="horizontal"
7
	android:paddingTop="4dp"
8
	android:paddingBottom="4dp">
9

  
10
   	<ImageView
11
   		android:id="@+id/updates_pane_image"
12
   		android:layout_width="wrap_content"
13
   		android:layout_height="wrap_content"
14
   		android:layout_margin="8dp"/>
15

  
16
   	<LinearLayout
17
   		android:layout_width="0dp"
18
 		android:layout_height="wrap_content"
19
 		android:layout_weight="1"
20
 		android:orientation="vertical"
21
 		android:layout_gravity="center_vertical">
22

  
23
		<TextView
24
    		android:id="@+id/updates_pane_title"
25
    		android:layout_width="match_parent"
26
    		android:layout_height="wrap_content"
27
    		android:textStyle="bold"/>
28
   		<TextView
29
    		android:id="@+id/updates_pane_version"
30
    		android:layout_width="wrap_content"
31
    		android:layout_height="wrap_content"/>
32
    	<TextView
33
    		android:id="@+id/updates_pane_description"
34
    		android:layout_width="wrap_content"
35
    		android:layout_height="wrap_content"/>
36
    	<Button
37
             android:id="@+id/updates_pane_button"
38
             android:layout_width="wrap_content"
39
             android:layout_height="wrap_content"
40
             android:singleLine="true"
41
             android:gravity="end"/>
42
 	</LinearLayout>
43
</LinearLayout>
src/main/res/layout/popup_object.xml
21 21
   <RelativeLayout
22 22
       android:id="@+id/bottomLayout"
23 23
       android:layout_width="match_parent"
24
       android:background="@color/grey"
25 24
       android:layout_height="wrap_content"
25
       android:background="@color/grey"
26 26
       android:paddingEnd="10dp"
27 27
       android:paddingStart="10dp">
28 28

  
src/main/res/values-de/strings.xml
40 40
    <string name="tutorials">Lernprogrammen</string>
41 41
    <string name="about">Über die App</string>
42 42
    <string name="updates">Aktualisierungen</string>
43
    <string name="no_updates">Nicht gefunden</string>
43 44
    <string name="abandon_solve">Gib auf</string>
44 45

  
45 46
    <string name="config_details">Einzelheiten</string>
src/main/res/values-es/strings.xml
40 40
    <string name="tutorials">Tutoriales</string>
41 41
    <string name="about">Acerca de</string>
42 42
    <string name="updates">Actualizaciones</string>
43
    <string name="no_updates">Extraviado</string>
43 44
    <string name="abandon_solve">Abandonar</string>
44 45

  
45 46
    <string name="config_details">Detalles</string>
src/main/res/values-fr/strings.xml
40 40
    <string name="tutorials">Tutoriels</string>
41 41
    <string name="about">À propos de</string>
42 42
    <string name="updates">Mises à jour</string>
43
    <string name="no_updates">Pas trouvé</string>
43 44
    <string name="abandon_solve">Abandonner</string>
44 45

  
45 46
    <string name="config_details">Détails</string>
src/main/res/values-ja/strings.xml
40 40
    <string name="tutorials">チュートリアル</string>
41 41
    <string name="about">アプリについて</string>
42 42
    <string name="updates">更新</string>
43
    <string name="no_updates">見つかりません</string>
43 44
    <string name="abandon_solve">あきらめる</string>
44 45

  
45 46
    <string name="config_details">詳細</string>
src/main/res/values-ko/strings.xml
40 40
    <string name="tutorials">튜토리얼</string>
41 41
    <string name="about">정보</string>
42 42
    <string name="updates">업데이트</string>
43
    <string name="no_updates">업데이트가 없습니다</string>
43 44
    <string name="abandon_solve">포기</string>
44 45

  
45 46
    <string name="config_details">세부</string>
src/main/res/values-pl/strings.xml
40 40
    <string name="tutorials">Tutoriale</string>
41 41
    <string name="about">O aplikacji</string>
42 42
    <string name="updates">Aktualizacje</string>
43
    <string name="no_updates">Nie znaleziono</string>
43 44
    <string name="abandon_solve">Zrezygnuj</string>
44 45

  
45 46
    <string name="config_details">O kostce</string>
src/main/res/values-ru/strings.xml
40 40
    <string name="tutorials">Учебники</string>
41 41
    <string name="about">О нас</string>
42 42
    <string name="updates">Обновления</string>
43
    <string name="no_updates">Не найдено</string>
43 44
    <string name="abandon_solve">Сдаться</string>
44 45

  
45 46
    <string name="config_details">Детали</string>
src/main/res/values-zh-rCN/strings.xml
40 40
    <string name="tutorials">讲解</string>
41 41
    <string name="about">关于</string>
42 42
    <string name="updates">更新</string>
43
    <string name="no_updates">未找到更新</string>
43 44
    <string name="abandon_solve">放弃</string>
44 45

  
45 46
    <string name="config_details">细节</string>
src/main/res/values-zh-rTW/strings.xml
40 40
    <string name="tutorials">講解</string>
41 41
    <string name="about">關於</string>
42 42
    <string name="updates">更新</string>
43
    <string name="no_updates">未找到更新</string>
43 44
    <string name="abandon_solve">放棄</string>
44 45

  
45 46
    <string name="config_details">細節</string>
src/main/res/values/strings.xml
41 41
    <string name="tutorials">Tutorials</string>
42 42
    <string name="about">About</string>
43 43
    <string name="updates">Updates</string>
44
    <string name="no_updates">No update found</string>
44 45

  
45 46
    <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>
46 47
    <string name="credits2">Pretty Patterns by Walter Randelshofer. See <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>

Also available in: Unified diff