Project

General

Profile

« Previous | Next » 

Revision 179f7189

Added by Leszek Koltunski over 2 years ago

Downloading updates: dialog progress.

View differences:

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;
24 23
import android.content.DialogInterface;
25 24
import android.os.Bundle;
26 25
import android.util.DisplayMetrics;
......
28 27
import android.view.LayoutInflater;
29 28
import android.view.View;
30 29
import android.view.Window;
31
import android.view.WindowManager;
32 30
import android.widget.Button;
33 31
import android.widget.LinearLayout;
34
import android.widget.ScrollView;
35 32
import android.widget.TextView;
36 33

  
37 34
import androidx.annotation.NonNull;
......
49 46
public class RubikDialogUpdates extends AppCompatDialogFragment implements RubikNetwork.Updatee
50 47
  {
51 48
  private TextView mText;
52
  private ScrollView mScroll;
53 49
  private LinearLayout mLayout;
54 50
  private int mMargin, mSize, mFontSize;
55 51

  
56 52
///////////////////////////////////////////////////////////////////////////////////////////////////
57 53

  
58
  private View createView(FragmentActivity act, LayoutInflater inflater, float size)
54
  private View createView(FragmentActivity act, LayoutInflater inflater, float size, int minH)
59 55
    {
60 56
    final View view = inflater.inflate(R.layout.dialog_updates, null);
61 57

  
62 58
    mLayout= view.findViewById(R.id.updates_main_layout);
63
    mScroll= view.findViewById(R.id.updates_scroll);
64 59
    mText  = view.findViewById(R.id.updates_message);
65 60
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
66 61
    mText.setText( act.getString(R.string.downloading) );
67 62

  
63
    mLayout.setMinimumHeight(minH);
64
    mText.setMinimumHeight(minH);
65

  
68 66
    return view;
69 67
    }
70 68

  
......
103 101
        }
104 102
      });
105 103

  
106
    View view = createView(act,inflater,okSize);
104
    int minH = (int)(0.35f*h);
105
    View view = createView(act,inflater,okSize,minH);
106
    view.setMinimumHeight(minH);
107 107
    builder.setView(view);
108 108

  
109 109
    Dialog dialog = builder.create();
......
133 133

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

  
136
  @Override
137
  public void onResume()
136
  private void receiveUpdate(RubikUpdates updates, FragmentActivity act)
138 137
    {
139
    super.onResume();
140

  
141
    Window window = getDialog().getWindow();
142
    Context context = getContext();
143

  
144
    if( window!=null && context!=null )
145
      {
146
      DisplayMetrics metrics = context.getResources().getDisplayMetrics();
147
      final float height= metrics.heightPixels;
148

  
149
      WindowManager.LayoutParams params = window.getAttributes();
150
      params.width = WindowManager.LayoutParams.WRAP_CONTENT;
151
      params.height = (int)(0.75f*height);
152
      window.setAttributes(params);
153

  
154
      int textHeight = (int)(0.75f*params.height);
155
      mText.setHeight(textHeight);
156
      mLayout.setMinimumHeight(textHeight);
157
      }
158
    }
159

  
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

  
162
  public void receiveUpdate(RubikUpdates updates)
163
    {
164
    FragmentActivity act = getActivity();
165 138
    int numN = updates.getNewNumber();
166 139
    int numU = updates.getUpdNumber();
167 140
    int num = numN+numU;
168 141

  
169 142
    if( num<=0 )
170 143
      {
171
      mScroll.setVerticalScrollBarEnabled(false);
144

  
172 145
      mText.setText(act.getString(R.string.no_updates));
173 146
      }
174 147
    else
175 148
      {
149
      //mText.setText("Downloading...");
150

  
176 151
      int imagH = (int)(mSize*1.00f);
177 152
      int textH = (int)(mSize*0.23f);
178 153
      int buttH = (int)(mSize*0.49f);
......
209 184
      }
210 185
    }
211 186

  
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

  
189
  public void receiveUpdate(RubikUpdates updates)
190
    {
191
    FragmentActivity act = getActivity();
192

  
193
    if( act!=null )
194
      {
195
      act.runOnUiThread(new Runnable()
196
        {
197
        @Override
198
        public void run()
199
          {
200
          receiveUpdate(updates,act);
201
          }
202
        });
203
      }
204
    }
205

  
212 206
///////////////////////////////////////////////////////////////////////////////////////////////////
213 207

  
214 208
  public void errorUpdate()
215 209
    {
216
    mScroll.setVerticalScrollBarEnabled(false);
217 210
    mText.setText("Network error");
218 211
    }
219 212

  
src/main/java/org/distorted/screens/RubikScreenPlay.java
19 19

  
20 20
package org.distorted.screens;
21 21

  
22
import java.lang.ref.WeakReference;
23

  
24
import android.app.Activity;
22 25
import android.content.Context;
23 26
import android.content.SharedPreferences;
24 27
import android.content.res.Resources;
......
86 89
  private boolean mShouldReactToEndOfScrambling;
87 90
  private int mBottomHeight;
88 91
  private float mScreenWidth;
92
  private WeakReference<RubikActivity> mWeakAct;
89 93

  
90 94
///////////////////////////////////////////////////////////////////////////////////////////////////
91 95

  
......
98 102

  
99 103
  void enterScreen(final RubikActivity act)
100 104
    {
105
    mWeakAct = new WeakReference<>(act);
101 106
    int numObjects = RubikObjectList.getNumObjects();
102 107
    mScreenWidth = act.getScreenWidthInPixels();
103 108
    mUpperBarHeight = act.getHeightUpperBar();
......
707 712
    {
708 713
    updates.showDebug();
709 714

  
710
    int numN = updates.getNewNumber();
711
    int numU = updates.getUpdNumber();
712
    int num = numN+numU;
715
    Activity act = mWeakAct.get();
713 716

  
714
    if( num>0 )
715
      {
716
      String shownNum = String.valueOf(num);
717
      mBubbleUpdates.setText(shownNum);
718
      mBubbleUpdates.setVisibility(View.VISIBLE);
719
      int height = (int)(0.05f*mScreenWidth);
720
      mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height);
721
      }
722
    else
717
    if( act!=null )
723 718
      {
724
      mBubbleUpdates.setVisibility(View.INVISIBLE);
719
      act.runOnUiThread(new Runnable()
720
        {
721
        @Override
722
        public void run()
723
          {
724
          int numN = updates.getNewNumber();
725
          int numU = updates.getUpdNumber();
726
          int num = numN+numU;
727

  
728
          if( num>0 )
729
            {
730
            String shownNum = String.valueOf(num);
731
            mBubbleUpdates.setText(shownNum);
732
            mBubbleUpdates.setVisibility(View.VISIBLE);
733
            int height = (int)(0.05f*mScreenWidth);
734
            mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height);
735
            }
736
         else
737
            {
738
            mBubbleUpdates.setVisibility(View.INVISIBLE);
739
            }
740
          }
741
        });
725 742
      }
726 743
    }
727 744

  
src/main/res/layout/dialog_updates.xml
2 2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3 3
    android:id="@+id/updates_scroll"
4 4
    android:layout_width="match_parent"
5
    android:layout_height="wrap_content"
6
    android:paddingLeft="10dp"
7
    android:paddingRight="10dp">
5
    android:layout_height="match_parent"
6
    android:background="@color/black"
7
    android:layout_marginLeft="10dp"
8
    android:layout_marginRight="10dp">
8 9

  
9 10
    <LinearLayout
10 11
        android:id="@+id/updates_main_layout"
11 12
        android:layout_width="match_parent"
12 13
        android:layout_height="wrap_content"
13
        android:background="@color/black"
14 14
        android:paddingBottom="10dp"
15 15
        android:orientation="vertical">
16 16

  
src/main/res/layout/dialog_updates_pane.xml
26 26
    		android:gravity="center_vertical"
27 27
    		android:layout_width="match_parent"
28 28
    		android:layout_height="wrap_content"
29
    		android:singleLine="true"
29 30
    		android:textStyle="bold"/>
30 31

  
31 32
        <TextView
32 33
    		android:id="@+id/updates_pane_description"
33 34
    		android:gravity="center_vertical"
34 35
    		android:layout_width="wrap_content"
35
    		android:layout_height="wrap_content"/>
36
    		android:layout_height="wrap_content"
37
    		android:singleLine="true"/>
36 38

  
37 39
    	<Button
38 40
             android:id="@+id/updates_pane_button"

Also available in: Unified diff