Project

General

Profile

« Previous | Next » 

Revision 2c9ab085

Added by Leszek Koltunski almost 3 years ago

Downloading updates: dialog progress.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java
25 25
import android.widget.Button;
26 26
import android.widget.ImageView;
27 27
import android.widget.LinearLayout;
28
import android.widget.ProgressBar;
28 29
import android.widget.TextView;
29 30

  
30 31
import org.distorted.main.R;
31 32
import org.distorted.network.RubikUpdates;
32
import org.distorted.objectlib.json.JsonWriter;
33 33

  
34 34
///////////////////////////////////////////////////////////////////////////////////////////////////
35 35

  
36 36
public class RubikDialogUpdateView
37 37
  {
38
  private View mView;
39

  
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

  
42 38
  public RubikDialogUpdateView()
43 39
    {
44 40

  
......
46 42

  
47 43
///////////////////////////////////////////////////////////////////////////////////////////////////
48 44

  
49
  public View createView(Activity act, RubikUpdates.UpdateInfo info, int fontSize, int padding, boolean isNew,
45
  public View createView(Activity act, RubikUpdates.UpdateInfo info, int fontSize, int padding,
50 46
                         LinearLayout.LayoutParams pImage, LinearLayout.LayoutParams pView,
51 47
                         LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt )
52 48
    {
53
    int layoutID = R.layout.dialog_updates_pane;
54
    mView = act.getLayoutInflater().inflate(layoutID, null);
49
    boolean isCompleted = info.mPercent>=100;
50
    int layoutID = isCompleted
51
                   ? R.layout.dialog_updates_completed
52
                   : R.layout.dialog_updates_started;
55 53

  
56
    Button button = mView.findViewById(R.id.updates_pane_button);
57

  
58
    button.setOnClickListener( new View.OnClickListener()
59
      {
60
      @Override
61
      public void onClick(View v)
62
        {
63
        android.util.Log.e("D", "INSTALL pressed");
64
        }
65
      });
54
    View view = act.getLayoutInflater().inflate(layoutID, null);
66 55

  
67
    TextView title = mView.findViewById(R.id.updates_pane_title);
56
    TextView title = view.findViewById(R.id.updates_pane_title);
68 57
    title.setText(info.mObjectLongName);
69
    TextView description = mView.findViewById(R.id.updates_pane_description);
58
    TextView description = view.findViewById(R.id.updates_pane_description);
70 59
    description.setText(info.mDescription);
71 60

  
72
    ImageView image = mView.findViewById(R.id.updates_pane_image);
61
    ImageView image = view.findViewById(R.id.updates_pane_image);
73 62
    image.setBackgroundResource(R.drawable.unknown_icon);
74 63

  
75 64
    image.setLayoutParams(pImage);
76
    mView.setLayoutParams(pView);
65
    view.setLayoutParams(pView);
77 66

  
78 67
    title.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
79 68
    description.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
80
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
81 69

  
82 70
    title.setLayoutParams(pText);
83 71
    description.setLayoutParams(pText);
84
    button.setLayoutParams(pButt);
85 72

  
86
    mView.setPadding(padding,padding,padding,padding);
73
    view.setPadding(padding,padding,padding,padding);
74

  
75
    if( isCompleted )
76
      {
77
      Button button = view.findViewById(R.id.updates_pane_button);
78

  
79
      button.setOnClickListener( new View.OnClickListener()
80
        {
81
        @Override
82
        public void onClick(View v)
83
          {
84
          android.util.Log.e("D", "INSTALL pressed");
85
          }
86
        });
87

  
88
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
89
      button.setLayoutParams(pButt);
90
      }
91
    else
92
      {
93
      ProgressBar bar = view.findViewById(R.id.updates_pane_bar);
94
      bar.setLayoutParams(pButt);
95
      bar.setProgress(info.mPercent);
96
      }
87 97

  
88
    return mView;
98
    return view;
89 99
    }
90 100
  }
src/main/java/org/distorted/dialogs/RubikDialogUpdates.java
136 136

  
137 137
  private void receiveUpdate(RubikUpdates updates, FragmentActivity act)
138 138
    {
139
    int numN = updates.getNewNumber();
140
    int numU = updates.getUpdNumber();
141
    int num = numN+numU;
139
    int numC = updates.getCompletedNumber();
142 140

  
143
    if( num<=0 )
141
    if( numC<=0 )
144 142
      {
145

  
146 143
      mText.setText(act.getString(R.string.no_updates));
147 144
      }
148 145
    else
......
150 147
      //mText.setText("Downloading...");
151 148

  
152 149
      int imagH = (int)(mSize*1.00f);
153
      int textH = (int)(mSize*0.23f);
154
      int buttH = (int)(mSize*0.49f);
150
      int textH = (int)(mSize*0.27f);
151
      int buttH = (int)(mSize*0.35f);
155 152

  
156 153
      LinearLayout.LayoutParams pI = new LinearLayout.LayoutParams( imagH,imagH );
157 154
      LinearLayout.LayoutParams pV = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, mSize );
......
163 160

  
164 161
      if( mLayout!=null )
165 162
        {
166
        for(int i=0; i<numN; i++)
163
        for(int i=0; i<numC; i++)
167 164
          {
168
          RubikUpdates.UpdateInfo info = updates.getNewUpdate(i);
165
          RubikUpdates.UpdateInfo info = updates.getCompletedUpdate(i);
169 166
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
170
          View pane = rubikView.createView(act,info,mFontSize,mPadding,true,pI,pV,pT,pB);
167
          View pane = rubikView.createView(act,info,mFontSize,mPadding,pI,pV,pT,pB);
171 168
          mLayout.addView(pane);
172 169
          }
173
        for(int i=0; i<numU; i++)
170

  
171
        int numS = updates.getStartedNumber();
172

  
173
        for(int i=0; i<numS; i++)
174 174
          {
175
          RubikUpdates.UpdateInfo info = updates.getUpdUpdate(i);
175
          RubikUpdates.UpdateInfo info = updates.getStartedUpdate(i);
176 176
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
177
          View pane = rubikView.createView(act,info,mFontSize,mPadding,false,pI,pV,pT,pB);
177
          View pane = rubikView.createView(act,info,mFontSize,mPadding,pI,pV,pT,pB);
178 178
          mLayout.addView(pane);
179 179
          }
180 180
        }
src/main/java/org/distorted/network/RubikUpdates.java
34 34
    public final String mDescription;
35 35
    public final int mObjectMinorVersion;
36 36
    public final int mExtrasMinorVersion;
37
    public final int mPercent;
37 38
    public final boolean mUpdateObject;
38 39
    public final boolean mUpdateExtras;
39 40

  
40
    public UpdateInfo(String shortName, String longName, String description, int objectMinor, int extrasMinor, boolean updateO, boolean updateE)
41
    public UpdateInfo(String shortName, String longName, String description, int objectMinor,
42
                      int extrasMinor, int percent, boolean updateO, boolean updateE)
41 43
      {
42 44
      mObjectShortName    = shortName;
43 45
      mObjectLongName     = longName;
44 46
      mDescription        = description;
45 47
      mObjectMinorVersion = objectMinor;
46 48
      mExtrasMinorVersion = extrasMinor;
49
      mPercent            = percent;
47 50
      mUpdateObject       = updateO;
48 51
      mUpdateExtras       = updateE;
49 52
      }
50 53
    }
51 54

  
52 55
  private String mUrl;
53
  private final ArrayList<UpdateInfo> mNew, mUpd;
56
  private final ArrayList<UpdateInfo> mCompleted, mStarted;
54 57

  
55 58
///////////////////////////////////////////////////////////////////////////////////////////////////
56 59

  
57 60
  public RubikUpdates()
58 61
    {
59
    mNew = new ArrayList<>();
60
    mUpd = new ArrayList<>();
62
    mCompleted = new ArrayList<>();
63
    mStarted   = new ArrayList<>();
61 64
    }
62 65

  
63 66
///////////////////////////////////////////////////////////////////////////////////////////////////
......
79 82

  
80 83
  private void parseLine(String[] elements)
81 84
    {
82
    String shortName   = elements[0];
83
    String objMinor    = elements[1];
84
    String extMinor    = elements[2];
85
    String longName    = elements[3];
86
    String description = elements[4];
87
    int oMinor, eMinor;
85
    String shortName   = elements[0].trim();
86
    String objMinor    = elements[1].trim();
87
    String extMinor    = elements[2].trim();
88
    String percent     = elements[3].trim();
89
    String longName    = elements[4];
90
    String description = elements[5];
91
    int oMinor, eMinor, oPercent;
88 92

  
89 93
    try { oMinor = Integer.parseInt(objMinor); }
90 94
    catch (NumberFormatException ex) { oMinor = -1; }
91 95
    try { eMinor = Integer.parseInt(extMinor); }
92 96
    catch (NumberFormatException ex) { eMinor = -1; }
97
    try { oPercent = Integer.parseInt(percent); }
98
    catch (NumberFormatException ex) { oPercent = -1; }
93 99

  
94
    if( oMinor>=0 && eMinor>=0 )
100
    if( oMinor>=0 && eMinor>=0 && oPercent>=0 )
95 101
      {
96 102
      int objOrdinal = RubikObjectList.getOrdinal(shortName.toUpperCase());
103
      boolean updateO=true, updateE=true;
97 104

  
98 105
      if( objOrdinal>=0 )
99 106
        {
100 107
        int localObjectMinor = RubikObjectList.getLocalObjectMinor(objOrdinal);
101 108
        int localExtrasMinor = RubikObjectList.getLocalExtrasMinor(objOrdinal);
102
        boolean updateO = localObjectMinor<oMinor;
103
        boolean updateE = localExtrasMinor<eMinor;
104

  
105
        if( updateO || updateE )
106
          {
107
          UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,updateO,updateE);
108
          mUpd.add(info);
109
          }
109
        updateO = localObjectMinor<oMinor;
110
        updateE = localExtrasMinor<eMinor;
110 111
        }
111
      else
112
      if( updateO || updateE )
112 113
        {
113
        UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,true,true);
114
        mNew.add(info);
114
        UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,oPercent,updateO,updateE);
115
        if(oPercent>=100) mCompleted.add(info);
116
        else              mStarted.add(info);
115 117
        }
116 118
      }
117 119
    }
......
122 124
    {
123 125
    android.util.Log.e("D", updates);
124 126

  
125
    mNew.clear();
126
    mUpd.clear();
127
    mCompleted.clear();
128
    mStarted.clear();
127 129

  
128 130
    String[] lines = updates.split("\n");
129 131
    int numLines = lines.length;
......
134 136
      for(int line=1; line<numLines; line++)
135 137
        {
136 138
        String[] elements = lines[line].split(",");
137
        if( elements.length>=3 ) parseLine(elements);
139
        if( elements.length>=6 ) parseLine(elements);
138 140
        }
139 141
      }
140 142
    }
......
143 145

  
144 146
  public void updateDone(String shortName)
145 147
    {
146
    for( UpdateInfo info : mNew)
148
    for( UpdateInfo info : mCompleted)
147 149
      {
148 150
      if( info.mObjectShortName.equals(shortName) )
149 151
        {
150
        mNew.remove(info);
151
        return;
152
        }
153
      }
154

  
155
    for( UpdateInfo info : mUpd)
156
      {
157
      if( info.mObjectShortName.equals(shortName) )
158
        {
159
        mUpd.remove(info);
152
        mCompleted.remove(info);
160 153
        return;
161 154
        }
162 155
      }
......
164 157

  
165 158
///////////////////////////////////////////////////////////////////////////////////////////////////
166 159

  
167
  public UpdateInfo getNewUpdate(int ordinal)
160
  public UpdateInfo getCompletedUpdate(int ordinal)
168 161
    {
169
    return mNew.get(ordinal);
162
    return mCompleted.get(ordinal);
170 163
    }
171 164

  
172 165
///////////////////////////////////////////////////////////////////////////////////////////////////
173 166

  
174
  public UpdateInfo getUpdUpdate(int ordinal)
167
  public UpdateInfo getStartedUpdate(int ordinal)
175 168
    {
176
    return mUpd.get(ordinal);
169
    return mStarted.get(ordinal);
177 170
    }
178 171

  
179 172
///////////////////////////////////////////////////////////////////////////////////////////////////
180 173

  
181
  public int getNewNumber()
174
  public int getCompletedNumber()
182 175
    {
183
    return mNew.size();
176
    return mCompleted.size();
184 177
    }
185 178

  
186 179
///////////////////////////////////////////////////////////////////////////////////////////////////
187 180

  
188
  public int getUpdNumber()
181
  public int getStartedNumber()
189 182
    {
190
    return mUpd.size();
183
    return mStarted.size();
191 184
    }
192 185

  
193 186
///////////////////////////////////////////////////////////////////////////////////////////////////
......
195 188
  public void showDebug()
196 189
    {
197 190
    android.util.Log.e("D", "url: "+mUrl);
198
    android.util.Log.e("D", "new objects: "+debug(mNew));
199
    android.util.Log.e("D", "upd objects: "+debug(mUpd));
191
    android.util.Log.e("D", "ready objects: "+debug(mCompleted));
192
    android.util.Log.e("D", "next  objects: "+debug(mStarted));
200 193
    }
201 194
}
src/main/java/org/distorted/screens/RubikScreenPlay.java
721 721
        @Override
722 722
        public void run()
723 723
          {
724
          int numN = updates.getNewNumber();
725
          int numU = updates.getUpdNumber();
726
          int num = numN+numU;
724
          int num = updates.getCompletedNumber();
727 725

  
728 726
          if( num>0 )
729 727
            {
src/main/res/drawable/black_progress.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3
    <item android:id="@android:id/background">
4
        <shape>
5
            <solid android:color="@android:color/white" />
6
        </shape>
7
    </item>
8

  
9
    <item android:id="@android:id/progress">
10
        <clip>
11
            <shape>
12
                <solid android:color="@android:color/black" />
13
            </shape>
14
        </clip>
15
    </item>
16

  
17
</layer-list>
18

  
src/main/res/layout/dialog_updates_completed.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:background="@color/medium_grey"
7
	android:padding="8dp"
8
	android:orientation="horizontal">
9

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

  
16
   	<LinearLayout
17
   		android:layout_width="match_parent"
18
 		android:layout_height="match_parent"
19
 		android:orientation="vertical"
20
 		android:layout_marginStart="8dp">
21

  
22
		<TextView
23
    		android:id="@+id/updates_pane_title"
24
    		android:gravity="top|start"
25
    		android:layout_width="match_parent"
26
    		android:layout_height="wrap_content"
27
    		android:singleLine="true"
28
            android:textStyle="bold"/>
29

  
30
        <TextView
31
    		android:id="@+id/updates_pane_description"
32
    		android:gravity="top|start"
33
    		android:layout_width="match_parent"
34
    		android:layout_height="wrap_content"
35
    		android:singleLine="true"/>
36

  
37
    	<Button
38
             android:id="@+id/updates_pane_button"
39
             android:layout_width="match_parent"
40
             android:layout_height="wrap_content"
41
             android:backgroundTint="@color/black"
42
             android:minHeight="0dp"
43
             android:minWidth="0dp"
44
             android:insetTop="0dp"
45
             android:insetBottom="0dp"
46
             android:text="@string/install"/>
47

  
48
 	</LinearLayout>
49
</LinearLayout>
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:background="@color/grey"
7
	android:padding="8dp"
8
	android:orientation="horizontal">
9

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

  
16
   	<LinearLayout
17
   		android:layout_width="match_parent"
18
 		android:layout_height="match_parent"
19
 		android:orientation="vertical"
20
 		android:layout_marginStart="8dp"
21

  
22
 		android:layout_gravity="center_vertical">
23

  
24
		<TextView
25
    		android:id="@+id/updates_pane_title"
26
    		android:gravity="center_vertical"
27
    		android:layout_width="match_parent"
28
    		android:layout_height="wrap_content"
29
    		android:singleLine="true"
30
    		android:textStyle="bold"/>
31

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

  
39
    	<Button
40
             android:id="@+id/updates_pane_button"
41
             android:layout_width="match_parent"
42
             android:layout_height="wrap_content"
43
             android:backgroundTint="@color/black"
44
             android:text="@string/install"
45
             android:gravity="center"/>
46

  
47
 	</LinearLayout>
48
</LinearLayout>
src/main/res/layout/dialog_updates_started.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:background="@color/medium_grey"
7
	android:padding="8dp"
8
	android:orientation="horizontal">
9

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

  
16
   	<LinearLayout
17
   		android:layout_width="match_parent"
18
 		android:layout_height="match_parent"
19
 		android:orientation="vertical"
20
 		android:layout_marginStart="8dp">
21

  
22
		<TextView
23
    		android:id="@+id/updates_pane_title"
24
    		android:gravity="top|start"
25
    		android:layout_width="match_parent"
26
    		android:layout_height="wrap_content"
27
    		android:singleLine="true"
28
    		android:textStyle="bold"/>
29

  
30
        <TextView
31
    		android:id="@+id/updates_pane_description"
32
    		android:gravity="top|start"
33
    		android:layout_width="wrap_content"
34
    		android:layout_height="wrap_content"
35
    		android:singleLine="true"/>
36

  
37
    	<ProgressBar
38
             android:id="@+id/updates_pane_bar"
39
             android:layout_width="match_parent"
40
             android:layout_height="wrap_content"
41
             style="@android:style/Widget.ProgressBar.Horizontal"
42
             android:progressDrawable="@drawable/black_progress"
43
             android:max="100"/>
44

  
45
 	</LinearLayout>
46
</LinearLayout>
src/main/res/values/colors.xml
7 7
    <color name="dark_grey">#ff222222</color>
8 8
    <color name="grey">#ff333333</color>
9 9
    <color name="light_grey">#ff555555</color>
10
    <color name="medium_grey">#ff444444</color>
10 11
    <color name="black">#ff010101</color>
11 12
    <color name="white">#ffffffff</color>
12 13
</resources>

Also available in: Unified diff