1
- package org .neotech .app .retainabletasksdemo ;
1
+ package org .neotech .app .retainabletasksdemo . activity ;
2
2
3
- import android .content .Intent ;
4
- import android .net .Uri ;
5
3
import android .os .Bundle ;
6
4
import android .support .annotation .NonNull ;
7
5
import android .support .design .widget .Snackbar ;
8
6
import android .support .v4 .app .DialogFragment ;
9
- import android .support .v7 .widget .Toolbar ;
10
- import android .text .Html ;
11
7
import android .view .View ;
12
8
import android .widget .Button ;
13
- import android .widget .TextView ;
14
9
import android .widget .Toast ;
15
10
11
+ import org .neotech .app .retainabletasksdemo .OnAlertDialogClickListener ;
12
+ import org .neotech .app .retainabletasksdemo .ProgressDialog ;
13
+ import org .neotech .app .retainabletasksdemo .R ;
16
14
import org .neotech .app .retainabletasksdemo .tasks .CountDownTask ;
17
15
import org .neotech .app .retainabletasksdemo .tasks .SimpleTask ;
18
16
import org .neotech .app .retainabletasksdemo .tasks .TaskWithoutCallback ;
19
17
import org .neotech .library .retainabletasks .Task ;
20
- import org .neotech .library .retainabletasks .providers .TaskActivityCompat ;
21
18
import org .neotech .library .retainabletasks .TaskExecutor ;
19
+ import org .neotech .library .retainabletasks .providers .TaskActivityCompat ;
22
20
23
- public class Main extends TaskActivityCompat implements View .OnClickListener , Task .AdvancedCallback , OnAlertDialogClickListener {
21
+ public class DemoActivityBasic extends TaskActivityCompat implements View .OnClickListener , Task .AdvancedCallback , OnAlertDialogClickListener {
24
22
25
23
private static final String TASK_RETAIN_UI_STATE = "retain-ui-state" ;
26
24
private static final String TASK_PROGRESS = "progress-dialog" ;
27
- private static final String TASK_SERIAL = "serial-" ;
28
-
29
- private static final int [] serialTaskText = new int []{R .string .task_serial_1 , R .string .task_serial_2 , R .string .task_serial_2 };
30
- private static final Button [] serialTaskButton = new Button [3 ];
31
-
32
25
33
26
private static final String DIALOG_PROGRESS = "progress-dialog" ;
34
27
35
28
private ProgressDialog progressDialog ;
36
-
37
29
private Button retainUserInterfaceButton ;
38
30
39
31
@ Override
40
32
protected void onCreate (Bundle savedInstanceState ) {
41
33
super .onCreate (savedInstanceState );
42
- setContentView (R .layout .activity_main );
43
- setSupportActionBar ((Toolbar ) findViewById (R .id .toolbar ));
34
+ setContentView (R .layout .activity_demo_basic );
44
35
45
- findViewById (R .id .button_open_fragment_activity ).setOnClickListener (this );
46
- findViewById (R .id .button_open_v11_activity ).setOnClickListener (this );
47
-
48
- findViewById (R .id .fab ).setOnClickListener (this );
49
36
findViewById (R .id .button_no_ui_task ).setOnClickListener (this );
50
37
findViewById (R .id .button_progress_task ).setOnClickListener (this );
51
38
52
-
53
- ((TextView ) findViewById (R .id .text_serial_tasks )).setText (Html .fromHtml (getString (R .string .task_serial )));
54
- serialTaskButton [0 ] = (Button ) findViewById (R .id .button_serial_task_1 );
55
- serialTaskButton [0 ].setOnClickListener (this );
56
- serialTaskButton [1 ] = (Button ) findViewById (R .id .button_serial_task_2 );
57
- serialTaskButton [1 ].setOnClickListener (this );
58
- serialTaskButton [2 ] = (Button ) findViewById (R .id .button_serial_task_3 );
59
- serialTaskButton [2 ].setOnClickListener (this );
60
-
61
-
62
39
retainUserInterfaceButton = (Button ) findViewById (R .id .button_retain_ui_state_task );
63
40
retainUserInterfaceButton .setOnClickListener (this );
64
41
}
@@ -78,18 +55,14 @@ public Task.Callback onPreAttach(@NonNull Task<?, ?> task) {
78
55
}
79
56
} else if (task .getTag ().equals (TASK_PROGRESS )){
80
57
progressDialog = ProgressDialog .getExistingInstance (getSupportFragmentManager (), DIALOG_PROGRESS );
81
- } else if (task .getTag ().startsWith (TASK_SERIAL )){
82
- onPreAttachSerialTask (task );
83
58
}
84
59
return this ;
85
60
}
86
61
87
62
@ Override
88
63
public void onClick (View v ) {
89
64
final int id = v .getId ();
90
- if (id == R .id .fab ){
91
- startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse ("https://github.com/NeoTech-Software/Android-Retainable-Tasks" )));
92
- } else if (id == R .id .button_progress_task ) {
65
+ if (id == R .id .button_progress_task ) {
93
66
if (getTaskManager ().isRunning (TASK_PROGRESS )) {
94
67
Toast .makeText (this , R .string .toast_task_already_running , Toast .LENGTH_SHORT ).show ();
95
68
}
@@ -103,19 +76,6 @@ public void onClick(View v) {
103
76
CountDownTask task = new CountDownTask (TASK_RETAIN_UI_STATE , 10 );
104
77
getTaskManager ().execute (task , this );
105
78
retainUserInterfaceButton .setEnabled (false );
106
- } else if (id == R .id .button_open_fragment_activity ){
107
- startActivity (new Intent (this , ActivityWithFragments .class ));
108
- } else if (id == R .id .button_open_v11_activity ){
109
- startActivity (new Intent (this , ActivityV11 .class ));
110
- } else if (id == R .id .button_serial_task_1 ){
111
- getTaskManager ().execute (new CountDownTask (TASK_SERIAL + 1 , 10 ), this , TaskExecutor .SERIAL_EXECUTOR );
112
- v .setEnabled (false );
113
- } else if (id == R .id .button_serial_task_2 ){
114
- getTaskManager ().execute (new CountDownTask (TASK_SERIAL + 2 , 10 ), this , TaskExecutor .SERIAL_EXECUTOR );
115
- v .setEnabled (false );
116
- } else if (id == R .id .button_serial_task_3 ){
117
- getTaskManager ().execute (new CountDownTask (TASK_SERIAL + 3 , 10 ), this , TaskExecutor .SERIAL_EXECUTOR );
118
- v .setEnabled (false );
119
79
}
120
80
}
121
81
@@ -134,8 +94,6 @@ public void onPostExecute(Task<?, ?> task) {
134
94
} else if (task .getTag ().equals (TASK_RETAIN_UI_STATE )){
135
95
retainUserInterfaceButton .setEnabled (true );
136
96
retainUserInterfaceButton .setText (R .string .task_retain_ui_state );
137
- } else if (task .getTag ().startsWith (TASK_SERIAL )) {
138
- onPostExecuteSerialTask (task );
139
97
}
140
98
}
141
99
@@ -153,40 +111,11 @@ public void onProgressUpdate(Task<?, ?> task, Object progress) {
153
111
progressDialog .setProgress ((int ) progress );
154
112
} else if (task .getTag ().equals (TASK_RETAIN_UI_STATE )){
155
113
retainUserInterfaceButton .setText ("" + (int ) progress );
156
- } else if (task .getTag ().startsWith (TASK_SERIAL )){
157
- onProgressUpdateSerialTask (task , (Integer ) progress );
158
114
}
159
115
}
160
116
161
117
@ Override
162
118
public void onDialogFragmentClick (DialogFragment fragment , int which ) {
163
119
getTaskManager ().cancel (TASK_PROGRESS );
164
120
}
165
-
166
-
167
-
168
- private int getSerialTaskIndex (String tag ){
169
- return Integer .parseInt (tag .substring (TASK_SERIAL .length ())) - 1 ;
170
- }
171
-
172
- private void onPreAttachSerialTask (Task <?, ?> task ) {
173
- final int index = getSerialTaskIndex (task .getTag ());
174
- serialTaskButton [index ].setEnabled (false );
175
- final Integer progress = (Integer ) task .getLastKnownProgress ();
176
- if (progress != null ) {
177
- serialTaskButton [index ].setText ("" + progress );
178
- }
179
- }
180
-
181
- private void onPostExecuteSerialTask (Task <?, ?> task ) {
182
- final int index = getSerialTaskIndex (task .getTag ());
183
- serialTaskButton [index ].setEnabled (false );
184
- serialTaskButton [index ].setText (serialTaskText [index ]);
185
- serialTaskButton [index ].setEnabled (true );
186
- }
187
-
188
- private void onProgressUpdateSerialTask (Task <?, ?> task , int progress ){
189
- final int index = getSerialTaskIndex (task .getTag ());
190
- serialTaskButton [index ].setText ("" + progress );
191
- }
192
121
}
0 commit comments