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

Commit 8c28085

Browse files
author
Rolf Smit
committed
Initial commit.
1 parent d95fb88 commit 8c28085

File tree

48 files changed

+2038
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2038
-1
lines changed

.gitignore

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
# File based on:
2+
# - GitHub default Android
3+
# - https://intellij-support.jetbrains.com/entries/23393067
4+
# - http://stackoverflow.com/questions/16736856/what-should-be-in-my-gitignore-for-an-android-studio-project
5+
16
# Built application files
27
*.apk
38
*.ap_
49

510
# Files for the Dalvik VM
611
*.dex
712

8-
# Java class files
13+
# Java (generated) class files
914
*.class
1015

1116
# Generated files
@@ -30,3 +35,26 @@ proguard/
3035

3136
# Android Studio captures folder
3237
captures/
38+
39+
# Mac OS X clutter
40+
*.DS_Store
41+
42+
# Windows clutter
43+
Thumbs.db
44+
45+
# Intellij IDEA
46+
*.iml
47+
.idea
48+
.idea/workspace.xml
49+
.idea/tasks.xml
50+
.idea/datasources.xml
51+
.idea/dataSources.ids
52+
53+
#NDK
54+
obj/
55+
56+
# More Idea files
57+
/local.properties
58+
/.idea/libraries
59+
60+
*.hprof

Android-Retainable-Tasks.iml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id="Android-Retainable-Tasks" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="java-gradle" name="Java-Gradle">
5+
<configuration>
6+
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
<option name="BUILDABLE" value="false" />
8+
</configuration>
9+
</facet>
10+
</component>
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
12+
<exclude-output />
13+
<content url="file://$MODULE_DIR$">
14+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
15+
</content>
16+
<orderEntry type="inheritedJdk" />
17+
<orderEntry type="sourceFolder" forTests="false" />
18+
</component>
19+
</module>

build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:1.5.0'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
jcenter()
18+
}
19+
}
20+
21+
task clean(type: Delete) {
22+
delete rootProject.buildDir
23+
}

demo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

demo/build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.2"
6+
7+
defaultConfig {
8+
applicationId "org.neotech.app.retainabletasksdemo"
9+
minSdkVersion 9
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(include: ['*.jar'], dir: 'libs')
24+
testCompile 'junit:junit:4.12'
25+
compile 'com.android.support:appcompat-v7:23.2.0'
26+
compile 'com.android.support:design:23.2.0'
27+
compile project(':library')
28+
29+
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' // or 1.4-beta1
30+
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' // or 1.4-beta1
31+
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' // or 1.4-beta1
32+
}

demo/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in D:\Programs\adt-bundle-windows-x86_64-20131030\sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.neotech.app.retainabletasksdemo;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

demo/src/main/AndroidManifest.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="org.neotech.app.retainabletasksdemo">
4+
5+
<application
6+
android:name=".App"
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity
13+
android:name=".Main"
14+
android:label="@string/app_name"
15+
android:theme="@style/AppTheme.NoActionBar">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.neotech.app.retainabletasksdemo;
2+
3+
import android.app.Application;
4+
5+
import com.squareup.leakcanary.LeakCanary;
6+
7+
/**
8+
* Created by Rolf on 29-2-2016.
9+
*/
10+
public class App extends Application {
11+
12+
@Override
13+
public void onCreate() {
14+
super.onCreate();
15+
LeakCanary.install(this);
16+
}
17+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.neotech.app.retainabletasksdemo;
2+
3+
import android.os.Bundle;
4+
import android.support.design.widget.FloatingActionButton;
5+
import android.support.design.widget.Snackbar;
6+
import android.support.v4.app.DialogFragment;
7+
import android.support.v7.app.AppCompatActivity;
8+
import android.support.v7.widget.Toolbar;
9+
import android.view.View;
10+
import android.widget.Toast;
11+
12+
import org.neotech.app.retainabletasksdemo.tasks.SimpleTask;
13+
import org.neotech.app.retainabletasksdemo.tasks.TaskWithoutCallback;
14+
import org.neotech.library.retainabletasks.Task;
15+
import org.neotech.library.retainabletasks.TaskExecutor;
16+
import org.neotech.library.retainabletasks.TaskHandler;
17+
18+
public class Main extends AppCompatActivity implements View.OnClickListener, Task.AdvancedCallback, OnAlertDialogClickListener {
19+
20+
private static final String TASK_SIMPLE = "Demo-task";
21+
22+
private ProgressDialog progressDialog;
23+
24+
@Override
25+
protected void onCreate(Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
setContentView(R.layout.activity_main);
28+
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
29+
setSupportActionBar(toolbar);
30+
31+
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
32+
fab.setOnClickListener(this);
33+
}
34+
35+
@Override
36+
protected void onStart() {
37+
super.onStart();
38+
progressDialog = ProgressDialog.getExistingInstance(getSupportFragmentManager(), "progress-dialog");
39+
getTaskHandler().attachListener(TASK_SIMPLE, this);
40+
}
41+
42+
@Override
43+
public void onClick(View v) {
44+
if(getTaskHandler().isRunning(TASK_SIMPLE)){
45+
Toast.makeText(this, "Task already running", Toast.LENGTH_SHORT).show();
46+
}
47+
48+
SimpleTask task = new SimpleTask(TASK_SIMPLE);
49+
getTaskHandler().execute(task, this);
50+
51+
TaskWithoutCallback callback = new TaskWithoutCallback(this);
52+
TaskExecutor.execute(callback);
53+
}
54+
55+
public TaskHandler getTaskHandler(){
56+
return TaskHandler.getActivityTaskHandler(getSupportFragmentManager());
57+
}
58+
59+
@Override
60+
public void onPreExecute(Task<?, ?> task) {
61+
progressDialog = ProgressDialog.showIfNotShowing(getSupportFragmentManager(), "progress-dialog");
62+
}
63+
64+
@Override
65+
public void onPostExecute(Task<?, ?> task) {
66+
progressDialog.dismiss();
67+
Snackbar.make(findViewById(android.R.id.content), "Task finished.", Snackbar.LENGTH_LONG).show();
68+
}
69+
70+
@Override
71+
public void onCanceled(Task<?, ?> task) {
72+
progressDialog.dismiss();
73+
Snackbar.make(findViewById(android.R.id.content), "Task canceled.", Snackbar.LENGTH_LONG).show();
74+
}
75+
76+
@Override
77+
public void onProgressUpdate(Task<?, ?> task, Object progress) {
78+
progressDialog.setProgress((int) progress);
79+
}
80+
81+
@Override
82+
public void onDialogFragmentClick(DialogFragment fragment, int which) {
83+
getTaskHandler().cancel(TASK_SIMPLE);
84+
}
85+
}

0 commit comments

Comments
 (0)