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

Commit 2a16a58

Browse files
committed
Merged develop into master
2 parents 6f9aea5 + 1c9491b commit 2a16a58

File tree

11 files changed

+109
-57
lines changed

11 files changed

+109
-57
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.2'
8+
classpath 'com.android.tools.build:gradle:2.2.0'
99
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
10-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
10+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files
1313
}

demo/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 23
4+
compileSdkVersion 24
55
buildToolsVersion "23.0.3"
66

77
defaultConfig {
88
applicationId "org.neotech.app.retainabletasksdemo"
9-
minSdkVersion 8
10-
targetSdkVersion 23
9+
minSdkVersion 9
10+
targetSdkVersion 24
1111
versionCode 1
1212
versionName "1.0"
1313
}
@@ -23,13 +23,13 @@ dependencies {
2323
compile project(':library')
2424
//compile 'org.neotech.library:android-retainable-tasks:0.1.0'
2525

26-
compile 'com.android.support:appcompat-v7:23.4.0'
27-
compile 'com.android.support:design:23.4.0'
26+
compile 'com.android.support:appcompat-v7:24.2.1'
27+
compile 'com.android.support:design:24.2.1'
2828

2929
//LeakCanary is used to detect memory leaks in debug builds.
30-
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
31-
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
32-
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
30+
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
31+
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
32+
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
3333

3434
//Unit-testing
3535
testCompile 'junit:junit:4.12'

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

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

3+
import android.graphics.Typeface;
4+
import android.os.Build;
5+
import android.os.Parcel;
6+
import android.os.Parcelable;
37
import android.support.annotation.NonNull;
8+
import android.support.design.internal.ParcelableSparseArray;
49
import android.text.Editable;
510
import android.text.Html;
611
import android.text.Spannable;
@@ -16,10 +21,24 @@
1621
*/
1722
public final class ExtendedHtml {
1823

24+
public static final int FROM_HTML_MODE_LEGACY = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N?Html.FROM_HTML_MODE_LEGACY:0;
25+
public static final int FROM_HTML_MODE_COMPACT = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N?Html.FROM_HTML_MODE_COMPACT:0;
26+
public static final int FROM_HTML_OPTION_USE_CSS_COLORS = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N?Html.FROM_HTML_OPTION_USE_CSS_COLORS:0;
27+
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N?Html.FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE:0;
28+
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_DIV = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N?Html.FROM_HTML_SEPARATOR_LINE_BREAK_DIV:0;
29+
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_HEADING = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N?Html.FROM_HTML_SEPARATOR_LINE_BREAK_HEADING:0;
30+
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N?Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST:0;
31+
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N?Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM:0;
32+
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N?Html.FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH:0;
33+
1934
private static final ExtendedTagHandler TAG_HANDLER = new ExtendedTagHandler();
2035

21-
public static Spanned fromHtml(String source){
22-
return Html.fromHtml(source, null, TAG_HANDLER);
36+
public static Spanned fromHtml(String source, int flags){
37+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
38+
return Html.fromHtml(source, flags, null, TAG_HANDLER);
39+
} else {
40+
return Html.fromHtml(source, null, TAG_HANDLER);
41+
}
2342
}
2443

2544
private static class CodeSpan extends TypefaceSpan {
@@ -31,6 +50,11 @@ public CodeSpan(int backgroundColor){
3150
this.backgroundColor = backgroundColor;
3251
}
3352

53+
protected CodeSpan(Parcel in) {
54+
super(in);
55+
this.backgroundColor = in.readInt();
56+
}
57+
3458
@Override
3559
public void updateDrawState(TextPaint tp) {
3660
super.updateDrawState(tp);
@@ -42,14 +66,37 @@ public void updateMeasureState(TextPaint paint) {
4266
super.updateMeasureState(paint);
4367
paint.bgColor = backgroundColor;
4468
}
69+
70+
public static final Creator<CodeSpan> CREATOR = new Creator<CodeSpan>() {
71+
72+
@Override
73+
public CodeSpan createFromParcel(Parcel in) {
74+
return new CodeSpan(in);
75+
}
76+
77+
@Override
78+
public CodeSpan[] newArray(int size) {
79+
return new CodeSpan[size];
80+
}
81+
};
82+
83+
@Override
84+
public void writeToParcel(Parcel dest, int flags) {
85+
super.writeToParcel(dest, flags);
86+
dest.writeInt(backgroundColor);
87+
}
88+
89+
public int describeContents() {
90+
return 0;
91+
}
4592
}
4693

4794
/**
4895
* Based on: http://stackoverflow.com/questions/4044509/android-how-to-use-the-html-taghandler
4996
*/
5097
private static class ExtendedTagHandler implements Html.TagHandler {
5198

52-
private static final int COLOR = 0xFFCCCCCC;
99+
private static final int COLOR = 0xFFDDDDDD;
53100

54101
@Override
55102
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.support.annotation.NonNull;
99
import android.support.v7.app.AppCompatActivity;
1010
import android.support.v7.widget.Toolbar;
11+
import android.text.Html;
1112
import android.text.Spanned;
1213
import android.view.LayoutInflater;
1314
import android.view.Menu;
@@ -40,7 +41,6 @@ public class Main extends TaskActivityCompat implements Task.Callback {
4041
protected void onCreate(Bundle savedInstanceState) {
4142
super.onCreate(savedInstanceState);
4243
setContentView(R.layout.activity_main);
43-
// setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
4444

4545
vSwitcher = (ViewSwitcher) findViewById(R.id.switcher);
4646
list = (ListView) findViewById(android.R.id.list);
@@ -182,7 +182,6 @@ public View getView(int position, View convertView, ViewGroup parent) {
182182
return convertView;
183183
}
184184

185-
186185
@Override
187186
public void onClick(View v) {
188187
v.getContext().startActivity((Intent) v.getTag());
@@ -198,8 +197,8 @@ private static class Demo {
198197
public Demo(Context context, int titleResId, int descriptionResId, String uri, Intent intent){
199198
this.intentStart = intent;
200199
this.intentView = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/NeoTech-Software/Android-Retainable-Tasks/tree/master/demo/src/main/java/" + uri));
201-
this.title = ExtendedHtml.fromHtml(context.getString(titleResId));
202-
this.description = ExtendedHtml.fromHtml(context.getString(descriptionResId));
200+
this.title = ExtendedHtml.fromHtml(context.getString(titleResId), ExtendedHtml.FROM_HTML_MODE_LEGACY);
201+
this.description = ExtendedHtml.fromHtml(context.getString(descriptionResId), ExtendedHtml.FROM_HTML_MODE_LEGACY);
203202
}
204203
}
205204
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Apr 28 17:08:46 CEST 2016
1+
#Mon Oct 03 15:46:44 CEST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

library/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ext {
1616
artifact = 'android-retainable-tasks'
1717

1818
libraryDescription = 'Android-Retainable-Tasks is an easy to use mini-library for easy asynchronous background tasking with callback support to the UI. This library is based on the Android AsyncTask implementation but with support for retaining tasks and therefore surviving configuration changes (orientation).'
19-
libraryVersion = '0.2.3'
19+
libraryVersion = '0.2.4'
2020

2121
siteUrl = 'https://github.com/NeoTech-Software/Android-Retainable-Tasks'
2222
gitUrl = 'https://github.com/NeoTech-Software/Android-Retainable-Tasks.git'
@@ -36,12 +36,12 @@ group = publishedGroupId
3636
version = libraryVersion
3737

3838
android {
39-
compileSdkVersion 23
39+
compileSdkVersion 24
4040
buildToolsVersion "23.0.3"
4141

4242
defaultConfig {
4343
minSdkVersion 8
44-
targetSdkVersion 23
44+
targetSdkVersion 24
4545
versionCode 1
4646
versionName = libraryVersion
4747
}
@@ -60,8 +60,8 @@ configurations {
6060
dependencies {
6161
compile fileTree(dir: 'libs', include: ['*.jar'])
6262
testCompile 'junit:junit:4.12'
63-
compile 'com.android.support:appcompat-v7:23.4.0'
64-
javadocCompile 'com.android.support:appcompat-v7:23.4.0'
63+
compile 'com.android.support:appcompat-v7:24.2.1'
64+
javadocCompile 'com.android.support:appcompat-v7:24.2.1'
6565
}
6666

6767
apply from: 'publish-library.gradle'

library/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
<manifest package="org.neotech.library.retainabletasks">
1+
<manifest package="org.neotech.library.retainabletasks"
2+
xmlns:tools="http://schemas.android.com/tools">
3+
4+
<uses-sdk tools:overrideLibrary="android.support.v7.appcompat" />
25
</manifest>

library/src/main/java/org/neotech/library/retainabletasks/TaskManager.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.neotech.library.retainabletasks;
22

33
import android.annotation.TargetApi;
4+
import android.app.Activity;
45
import android.os.Build;
56
import android.support.annotation.MainThread;
67
import android.support.annotation.NonNull;
78
import android.support.annotation.Nullable;
89
import android.support.v4.app.Fragment;
10+
import android.support.v4.app.FragmentActivity;
911
import android.support.v4.app.FragmentManager;
1012

1113
import org.neotech.library.retainabletasks.internal.BaseTaskManager;
@@ -97,7 +99,8 @@ public interface TaskAttachListener {
9799
/**
98100
* Checks if the {@link Task} with the given tag has delivered it's result.
99101
* @param tag The tag which identifies the Task to check.
100-
* @return true if the Task did deliver it's result, false if not.
102+
* @return true if the Task did deliver it's result, false if the Task did not deliver it's
103+
* result or the task is not found using {@link #getTask(String)}.
101104
* @see Task#isResultDelivered()
102105
*/
103106
@MainThread
@@ -107,7 +110,7 @@ public interface TaskAttachListener {
107110
* Checks if the {@link Task} with the given tag is running.
108111
* @param tag The tag which identifies the Task to check.
109112
* @return true if the Task is running ({@link Task#doInBackground()} is executing), false if
110-
* not.
113+
* the Task is not running or the task is not found using {@link #getTask(String)}.
111114
* @see Task#isRunning()
112115
*/
113116
@MainThread
@@ -151,11 +154,14 @@ public static boolean isStrictDebugModeEnabled(){
151154
@MainThread
152155
public static TaskManager getFragmentTaskManager(@NonNull Fragment fragment){
153156
final String tag = getTaskManagerTag(fragment.getTag());
154-
if(fragment.getParentFragment() != null){
155-
return getTaskManager(TaskRetainingFragment.getInstance(fragment.getParentFragment().getFragmentManager()), tag);
156-
} else {
157-
return getTaskManager(TaskRetainingFragment.getInstance(fragment.getFragmentManager()), tag);
157+
158+
//Get the root activity
159+
while(fragment.getParentFragment() != null){
160+
fragment = fragment.getParentFragment();
158161
}
162+
final FragmentActivity root = fragment.getActivity();
163+
164+
return getTaskManager(TaskRetainingFragment.getInstance(root.getSupportFragmentManager()), tag);
159165
}
160166

161167
/**
@@ -170,18 +176,21 @@ public static TaskManager getFragmentTaskManager(@NonNull android.app.Fragment f
170176
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
171177
return getFragmentTaskManagerAPI17(fragment, tag);
172178
} else {
173-
return getTaskManager(TaskRetainingFragment.getInstance(fragment.getFragmentManager()), tag);
179+
return getTaskManager(TaskRetainingFragment.getInstance(fragment.getActivity().getFragmentManager()), tag);
174180
}
175181
}
176182

177183
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
178184
@MainThread
179185
private static TaskManager getFragmentTaskManagerAPI17(@NonNull android.app.Fragment fragment, String tag){
180-
if(fragment.getParentFragment() != null){
181-
return getTaskManager(TaskRetainingFragment.getInstance(fragment.getParentFragment().getFragmentManager()), tag);
182-
} else {
183-
return getTaskManager(TaskRetainingFragment.getInstance(fragment.getFragmentManager()), tag);
186+
187+
//Get the root activity
188+
while(fragment.getParentFragment() != null){
189+
fragment = fragment.getParentFragment();
184190
}
191+
final Activity root = fragment.getActivity();
192+
193+
return getTaskManager(TaskRetainingFragment.getInstance(root.getFragmentManager()), tag);
185194
}
186195

187196

library/src/main/java/org/neotech/library/retainabletasks/TaskManagerLifeCycleProxy.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.annotation.TargetApi;
44
import android.app.Activity;
55
import android.os.Build;
6+
import android.support.annotation.MainThread;
67
import android.support.annotation.NonNull;
78
import android.support.v4.app.Fragment;
89
import android.support.v4.app.FragmentActivity;
@@ -12,7 +13,7 @@
1213
/**
1314
* Created by Rolf on 3-3-2016.
1415
*/
15-
public final class TaskManagerLifeCycleProxy implements BaseTaskManager.UIStateProvider {
16+
public final class TaskManagerLifeCycleProxy {
1617

1718
private BaseTaskManager fragmentTaskManager;
1819
private final TaskManagerProvider provider;
@@ -32,23 +33,28 @@ public TaskManagerLifeCycleProxy(@NonNull TaskManagerProvider provider){
3233
this.provider = provider;
3334
}
3435

36+
@MainThread
3537
public void onStart(){
3638
uiReady = true;
39+
((BaseTaskManager) getTaskManager()).setUIReady(uiReady);
3740
((BaseTaskManager) getTaskManager()).attach(provider);
3841
}
3942

43+
@MainThread
4044
public void onStop(){
4145
uiReady = false;
46+
((BaseTaskManager) getTaskManager()).setUIReady(uiReady);
4247
((BaseTaskManager) getTaskManager()).detach();
4348
}
4449

50+
@MainThread
4551
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
4652
public TaskManager getTaskManager(){
4753
if(fragmentTaskManager != null) {
4854
return fragmentTaskManager;
4955
}
5056
if(provider instanceof FragmentActivity){
51-
fragmentTaskManager = (BaseTaskManager) TaskManager.getActivityTaskManager(((FragmentActivity) provider).getSupportFragmentManager());
57+
fragmentTaskManager = (BaseTaskManager) TaskManager.getActivityTaskManager(((FragmentActivity) provider).getFragmentManager());
5258
} else if(provider instanceof Fragment){
5359
fragmentTaskManager = (BaseTaskManager) TaskManager.getFragmentTaskManager((Fragment) provider);
5460
} else if(provider instanceof Activity){
@@ -59,12 +65,7 @@ public TaskManager getTaskManager(){
5965
//This should never happen as the constructor checks everything.
6066
}
6167
*/
62-
fragmentTaskManager.setUIStateProvider(this);
68+
fragmentTaskManager.setUIReady(uiReady);
6369
return fragmentTaskManager;
6470
}
65-
66-
@Override
67-
public boolean isUserInterfaceReady() {
68-
return uiReady;
69-
}
7071
}

0 commit comments

Comments
 (0)