Skip to content
This repository was archived by the owner on Dec 17, 2020. It is now read-only.

Commit 0c2af94

Browse files
committed
Lint fixes, comments, some small new API renames.
1 parent 9e67e11 commit 0c2af94

File tree

20 files changed

+194
-178
lines changed

20 files changed

+194
-178
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,8 @@ private class VerySimpleTask extends Task<Integer, Integer> {
274274
}
275275

276276
public List<Integer> getProgressCache(){
277-
/**
278-
* This method is safe to call on the ui-thread because the
279-
* onProgressUpdate method is executed on the same thread.
280-
*/
277+
// This method is safe to call on the ui-thread because the
278+
// onProgressUpdate method is executed on the same thread.
281279
return progressValues;
282280
}
283281
}

annotations-processor/src/main/java/org/neotech/library/retainabletasks/AnnotationsProcessor.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@
2222
import javax.annotation.processing.RoundEnvironment;
2323
import javax.lang.model.SourceVersion;
2424
import javax.lang.model.element.Element;
25-
import javax.lang.model.element.ElementKind;
2625
import javax.lang.model.element.ExecutableElement;
2726
import javax.lang.model.element.Modifier;
2827
import javax.lang.model.element.TypeElement;
2928
import javax.lang.model.element.VariableElement;
30-
import javax.lang.model.type.DeclaredType;
31-
import javax.lang.model.type.TypeKind;
3229
import javax.lang.model.type.TypeMirror;
33-
import javax.lang.model.util.Types;
3430
import javax.tools.Diagnostic;
3531

3632
public final class AnnotationsProcessor extends AbstractProcessor {

demo/src/main/java/org/neotech/app/retainabletasksdemo/ExtendedHtml.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package org.neotech.app.retainabletasksdemo;
22

3-
import android.graphics.Typeface;
43
import android.os.Build;
54
import android.os.Parcel;
6-
import android.os.Parcelable;
75
import android.support.annotation.NonNull;
8-
import android.support.design.internal.ParcelableSparseArray;
96
import android.text.Editable;
107
import android.text.Html;
118
import android.text.Spannable;

demo/src/main/java/org/neotech/app/retainabletasksdemo/activity/DemoActivityAnnotations.java

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@
22

33
import android.os.Bundle;
44
import android.support.annotation.Nullable;
5-
import android.support.design.widget.Snackbar;
65
import android.support.v4.app.DialogFragment;
76
import android.view.View;
87

98
import org.neotech.app.retainabletasksdemo.OnAlertDialogClickListener;
10-
import org.neotech.app.retainabletasksdemo.ProgressDialog;
119
import org.neotech.app.retainabletasksdemo.R;
12-
import org.neotech.app.retainabletasksdemo.tasks.SimpleTask;
13-
import org.neotech.library.retainabletasks.Task;
14-
import org.neotech.library.retainabletasks.TaskAttach;
15-
import org.neotech.library.retainabletasks.TaskCancel;
16-
import org.neotech.library.retainabletasks.TaskPostExecute;
17-
import org.neotech.library.retainabletasks.TaskProgress;
10+
import org.neotech.library.retainabletasks.*;
1811
import org.neotech.library.retainabletasks.providers.TaskActivityCompat;
1912

2013
/**
14+
* This demo activity shows how annotations can be used to get task results (instead of using the
15+
* {@link Task.Callback} interface). By default every object
16+
* that is an instance of {@link TaskManagerOwner} works with annotations out-of-the-box. However
17+
* if you wan't a custom object to receive task results you should manually bind that object.
18+
*
19+
* Note: only library based classed that implement {@link TaskManagerOwner} are guaranteed to work
20+
* with annotations out-of-the -box.
21+
*
2122
* Created by Rolf Smit on 29-May-17.
2223
*/
2324
public final class DemoActivityAnnotations extends TaskActivityCompat implements View.OnClickListener, OnAlertDialogClickListener {
2425

2526
private static final String TASK_PROGRESS = "progress-dialog";
26-
private static final String DIALOG_PROGRESS = "progress-dialog";
2727

28-
private ProgressDialog progressDialog;
28+
private final ProgressTaskHandler progressTaskHandler = new ProgressTaskHandler(this);
29+
30+
public DemoActivityAnnotations(){
31+
bindTaskTarget(progressTaskHandler);
32+
}
2933

3034
@Override
3135
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -35,40 +39,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3539

3640
if(savedInstanceState == null) {
3741
// After starting this activity directly start the task.
38-
getTaskManager().execute(new SimpleTask(TASK_PROGRESS));
42+
progressTaskHandler.execute();
3943
}
4044
}
4145

4246
@Override
4347
public void onClick(View v) {
4448
// On click execute the task
45-
getTaskManager().execute(new SimpleTask(TASK_PROGRESS));
46-
}
47-
48-
@TaskAttach(TASK_PROGRESS)
49-
public void onAttach(Task<?, ?> rawTask){
50-
// Task attaches, make sure to show the progress dialog and update the progress if needed.
51-
final SimpleTask task = (SimpleTask) rawTask;
52-
progressDialog = ProgressDialog.showIfNotShowing(getSupportFragmentManager(), DIALOG_PROGRESS);
53-
if(task.getLastKnownProgress() != null) {
54-
progressDialog.setProgress(task.getLastKnownProgress());
55-
}
56-
}
57-
58-
@TaskProgress(TASK_PROGRESS)
59-
public void onProgress(Task<?, ?> task, Object progress){
60-
progressDialog.setProgress((int) progress);
61-
}
62-
63-
// Now this is cool, we can have a single method handle both the normal onPostExecute and the
64-
// onCancelled call.
65-
@TaskPostExecute(TASK_PROGRESS)
66-
@TaskCancel(TASK_PROGRESS)
67-
public void onFinish(Task<?, ?> task){
68-
progressDialog.dismiss();
69-
if(task.isCancelled()) {
70-
Snackbar.make(findViewById(android.R.id.content), getString(R.string.toast_task_canceled, getString(R.string.task_progress_dialog)), Snackbar.LENGTH_LONG).show();
71-
}
49+
progressTaskHandler.execute();
7250
}
7351

7452
@Override

demo/src/main/java/org/neotech/app/retainabletasksdemo/activity/DemoActivityBasic.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ protected void onCreate(Bundle savedInstanceState) {
4343
@Override
4444
public Task.Callback onPreAttach(@NonNull Task<?, ?> task) {
4545
if(task.getTag().equals(TASK_RETAIN_UI_STATE)){
46-
/**
47-
* the onPreAttach method will only be called if the task did not deliver its result
48-
* and thus is still available/referenced by the TaskManger.
49-
*
50-
* At this point the UI can be restored to the "task is running" state.
51-
*/
46+
47+
// The onPreAttach method will only be called if the task did not deliver its result and
48+
// thus is still available/referenced by the TaskManger.
49+
50+
// At this point the UI can be restored to the "task is running" state.
5251
if (!task.isResultDelivered()) { //This call isn't necessary.
5352
retainUserInterfaceButton.setEnabled(false);
5453
retainUserInterfaceButton.setText("" + task.getLastKnownProgress());
@@ -63,7 +62,7 @@ public Task.Callback onPreAttach(@NonNull Task<?, ?> task) {
6362
public void onClick(View v) {
6463
final int id = v.getId();
6564
if(id == R.id.button_progress_task) {
66-
if (getTaskManager().isRunning(TASK_PROGRESS)) {
65+
if (getTaskManager().isActive(TASK_PROGRESS)) {
6766
Toast.makeText(this, R.string.toast_task_already_running, Toast.LENGTH_SHORT).show();
6867
}
6968
SimpleTask task = new SimpleTask(TASK_PROGRESS);

demo/src/main/java/org/neotech/app/retainabletasksdemo/activity/Main.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import android.net.Uri;
66
import android.os.Bundle;
77
import android.os.SystemClock;
8-
import android.support.annotation.NonNull;
98
import android.text.Spanned;
109
import android.view.LayoutInflater;
1110
import android.view.Menu;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.neotech.app.retainabletasksdemo.activity;
2+
3+
import android.support.design.widget.Snackbar;
4+
5+
import org.neotech.app.retainabletasksdemo.ProgressDialog;
6+
import org.neotech.app.retainabletasksdemo.R;
7+
import org.neotech.app.retainabletasksdemo.tasks.SimpleTask;
8+
import org.neotech.library.retainabletasks.Task;
9+
import org.neotech.library.retainabletasks.TaskAttach;
10+
import org.neotech.library.retainabletasks.TaskCancel;
11+
import org.neotech.library.retainabletasks.TaskPostExecute;
12+
import org.neotech.library.retainabletasks.TaskProgress;
13+
14+
/**
15+
* Created by Rolf Smit on 30-May-17.
16+
*/
17+
public final class ProgressTaskHandler {
18+
19+
private static final String TASK_PROGRESS = "progress-dialog";
20+
private static final String DIALOG_PROGRESS = "progress-dialog";
21+
22+
private ProgressDialog progressDialog;
23+
24+
private final DemoActivityAnnotations demoActivityAnnotations;
25+
26+
public ProgressTaskHandler(DemoActivityAnnotations demoActivityAnnotations){
27+
this.demoActivityAnnotations = demoActivityAnnotations;
28+
}
29+
30+
public void execute(){
31+
if(!demoActivityAnnotations.getTaskManager().isActive(TASK_PROGRESS)) {
32+
demoActivityAnnotations.getTaskManager().execute(new SimpleTask(TASK_PROGRESS));
33+
}
34+
}
35+
36+
@TaskAttach(TASK_PROGRESS)
37+
public void onAttach(SimpleTask task){
38+
// Task attaches, make sure to show the progress dialog and update the progress if needed.
39+
progressDialog = ProgressDialog.showIfNotShowing(demoActivityAnnotations.getSupportFragmentManager(), DIALOG_PROGRESS);
40+
if(task.getLastKnownProgress() != null) {
41+
progressDialog.setProgress(task.getLastKnownProgress());
42+
}
43+
}
44+
45+
@TaskProgress(TASK_PROGRESS)
46+
public void onProgress(Task<?, ?> task, Object progress){
47+
progressDialog.setProgress((int) progress);
48+
}
49+
50+
// Now this is cool, we can have a single method handle both the normal onPostExecute and the
51+
// onCancelled call.
52+
@TaskPostExecute(TASK_PROGRESS)
53+
@TaskCancel(TASK_PROGRESS)
54+
public void onFinish(SimpleTask task){
55+
progressDialog.dismiss();
56+
if(task.isCancelled()) {
57+
Snackbar.make(demoActivityAnnotations.findViewById(android.R.id.content), demoActivityAnnotations.getString(R.string.toast_task_canceled, demoActivityAnnotations.getString(R.string.task_progress_dialog)), Snackbar.LENGTH_LONG).show();
58+
}
59+
}
60+
61+
62+
}

demo/src/main/res/values/dimens.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
<!-- Default screen margins, per the Android Design guidelines. -->
33
<dimen name="activity_horizontal_margin">16dp</dimen>
44
<dimen name="activity_vertical_margin">16dp</dimen>
5-
<dimen name="fab_margin">16dp</dimen>
65
</resources>

demo/src/main/res/values/strings.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
<string name="navigation_drawer_open">Open navigation drawer</string>
2121
<string name="navigation_drawer_close">Close navigation drawer</string>
2222

23-
<string name="text_open_fragment_activity">Start fragment test activity</string>
24-
<string name="text_open_v11_activity">Start non-support library Activity</string>
25-
26-
2723
<string name="text_fragment_task_manager_explanation">"This Activity has three Fragments, each Fragment extends the TaskFragment and has its own TaskManager instance.
2824

2925
When you select another Fragment using the left drawer the current fragment will be detached, this means that any Task started using the Fragments TaskManger will only deliver its result when the Fragment is attached to the Activity again.

library/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<manifest package="org.neotech.library.retainabletasks"
2-
xmlns:tools="http://schemas.android.com/tools">
1+
<manifest package="org.neotech.library.retainabletasks">
32

43
</manifest>

0 commit comments

Comments
 (0)