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

  

Also available in: Unified diff