Revision 46be3ddf
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.app.Activity; |
23 | 23 |
import android.graphics.Bitmap; |
24 |
import android.graphics.Color; |
|
24 | 25 |
import android.util.TypedValue; |
25 | 26 |
import android.view.View; |
26 | 27 |
import android.widget.Button; |
... | ... | |
30 | 31 |
import android.widget.TextView; |
31 | 32 |
|
32 | 33 |
import org.distorted.main.R; |
34 |
import org.distorted.network.RubikNetwork; |
|
33 | 35 |
import org.distorted.network.RubikUpdates; |
34 | 36 |
|
37 |
import java.io.InputStream; |
|
38 |
|
|
35 | 39 |
import static android.view.View.GONE; |
40 |
import static android.view.View.VISIBLE; |
|
36 | 41 |
|
37 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 43 |
|
39 |
public class RubikDialogUpdateView |
|
44 |
public class RubikDialogUpdateView implements RubikNetwork.Downloadee
|
|
40 | 45 |
{ |
41 | 46 |
private ImageView mIcon; |
47 |
private RubikUpdates.UpdateInfo mInfo; |
|
48 |
private ProgressBar mBar; |
|
49 |
private Button mButton; |
|
50 |
private TextView mDescription; |
|
42 | 51 |
|
43 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 53 |
|
45 | 54 |
public View createView(Activity act, RubikUpdates.UpdateInfo info, int fontSize, int padding, |
46 | 55 |
LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt ) |
47 | 56 |
{ |
57 |
mInfo = info; |
|
58 |
final RubikNetwork.Downloadee downloadee = this; |
|
48 | 59 |
View view = act.getLayoutInflater().inflate(R.layout.dialog_updates_pane, null); |
49 | 60 |
TextView title = view.findViewById(R.id.updates_pane_title); |
50 | 61 |
title.setText(info.mObjectLongName); |
51 |
TextView description = view.findViewById(R.id.updates_pane_description);
|
|
52 |
description.setText(info.mDescription);
|
|
62 |
mDescription = view.findViewById(R.id.updates_pane_description);
|
|
63 |
mDescription.setText(info.mDescription);
|
|
53 | 64 |
|
54 | 65 |
mIcon = view.findViewById(R.id.updates_pane_image); |
55 | 66 |
mIcon.setImageResource(R.drawable.unknown_icon); |
... | ... | |
57 | 68 |
view.setLayoutParams(pView); |
58 | 69 |
|
59 | 70 |
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); |
60 |
description.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
|
|
71 |
mDescription.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
|
|
61 | 72 |
|
62 | 73 |
title.setLayoutParams(pText); |
63 |
description.setLayoutParams(pText);
|
|
74 |
mDescription.setLayoutParams(pText);
|
|
64 | 75 |
|
65 | 76 |
view.setPadding(padding,padding,padding,padding); |
66 | 77 |
|
67 |
ProgressBar bar = view.findViewById(R.id.updates_pane_bar);
|
|
68 |
Button button = view.findViewById(R.id.updates_pane_button);
|
|
78 |
mBar = view.findViewById(R.id.updates_pane_bar);
|
|
79 |
mButton = view.findViewById(R.id.updates_pane_button);
|
|
69 | 80 |
|
70 | 81 |
if( info.mPercent>=100 ) |
71 | 82 |
{ |
72 |
bar.setVisibility(GONE);
|
|
73 |
button.setOnClickListener( new View.OnClickListener()
|
|
83 |
mBar.setVisibility(GONE);
|
|
84 |
mButton.setOnClickListener( new View.OnClickListener()
|
|
74 | 85 |
{ |
75 | 86 |
@Override |
76 | 87 |
public void onClick(View v) |
77 | 88 |
{ |
78 |
android.util.Log.e("D", "INSTALL pressed"); |
|
89 |
startDownload(); |
|
90 |
RubikNetwork network = RubikNetwork.getInstance(); |
|
91 |
network.downloadJSON(info,downloadee); |
|
79 | 92 |
} |
80 | 93 |
}); |
81 | 94 |
|
82 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); |
|
83 |
button.setLayoutParams(pButt); |
|
95 |
mButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); |
|
96 |
mButton.setLayoutParams(pButt); |
|
97 |
mBar.setLayoutParams(pButt); |
|
84 | 98 |
} |
85 | 99 |
else |
86 | 100 |
{ |
87 |
button.setVisibility(GONE);
|
|
88 |
bar.setLayoutParams(pButt);
|
|
89 |
bar.setProgress(info.mPercent);
|
|
101 |
mButton.setVisibility(GONE);
|
|
102 |
mBar.setLayoutParams(pButt);
|
|
103 |
mBar.setProgress(info.mPercent);
|
|
90 | 104 |
} |
91 | 105 |
|
92 | 106 |
return view; |
... | ... | |
98 | 112 |
{ |
99 | 113 |
mIcon.setImageBitmap(icon); |
100 | 114 |
} |
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
private void startDownload() |
|
119 |
{ |
|
120 |
mDescription.setText(R.string.downloading); |
|
121 |
mBar.setProgress(20); |
|
122 |
mButton.setVisibility(GONE); |
|
123 |
mBar.setVisibility(VISIBLE); |
|
124 |
} |
|
125 |
|
|
126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
127 |
|
|
128 |
public void jsonDownloaded() |
|
129 |
{ |
|
130 |
if( mInfo.mUpdateObject && mInfo.mObjectStream==null ) |
|
131 |
{ |
|
132 |
mDescription.setTextColor(Color.parseColor("#ff0000")); |
|
133 |
mDescription.setText(R.string.networkError); |
|
134 |
} |
|
135 |
else |
|
136 |
{ |
|
137 |
mBar.setProgress(50); |
|
138 |
mDescription.setText(R.string.installing); |
|
139 |
} |
|
140 |
} |
|
101 | 141 |
} |
Also available in: Unified diff
progress with the Updates: download the jsons.