├── .gitignore
├── .idea
├── gradle.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── libs
│ ├── eventbus-2.0.2.jar
│ ├── xutils-3.3.32-sources.jar
│ └── xutils-3.3.32.jar
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── kevin
│ │ └── vension
│ │ └── uploadservice
│ │ ├── ExampleInstrumentedTest.java
│ │ ├── MainActivityTest.java
│ │ └── ScreenShots.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── kevin
│ │ │ └── vension
│ │ │ └── uploadservice
│ │ │ ├── MainActivity.java
│ │ │ ├── MyApp.java
│ │ │ ├── events
│ │ │ ├── PhotoSelectionAddedEvent.java
│ │ │ ├── PhotoSelectionRemovedEvent.java
│ │ │ ├── UploadStateChangedEvent.java
│ │ │ ├── UploadingPausedStateChangedEvent.java
│ │ │ ├── UploadsModifiedEvent.java
│ │ │ └── UploadsStartEvent.java
│ │ │ ├── model
│ │ │ ├── PhotoUpload.java
│ │ │ └── PhotoUploadController.java
│ │ │ └── service
│ │ │ ├── PhotupThreadRunnable.java
│ │ │ └── UploadService.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── menu
│ │ └── main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── kevin
│ └── vension
│ └── uploadservice
│ └── ExampleUnitTest.java
├── build.gradle
├── gif
└── GIF.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | 1.8
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UpLoadService
2 | Android实现后台Service上传文件,通知栏提示上传进度
3 |
4 | # gif展示
5 |
6 | 
7 |
8 | ##
9 |
10 | Created with the help of uploadService by [Vension](https://github.com/Vension)
11 | ```
12 | Copyright 2017 com.github.vension
13 |
14 | Licensed under the Apache License, Version 2.0 (the "License");
15 | you may not use this file except in compliance with the License.
16 | You may obtain a copy of the License at
17 |
18 | http://www.apache.org/licenses/LICENSE-2.0
19 |
20 | Unless required by applicable law or agreed to in writing, software
21 | distributed under the License is distributed on an "AS IS" BASIS,
22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 | See the License for the specific language governing permissions and
24 | limitations under the License.
25 | ```
26 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.kevin.vension.uploadservice"
7 | minSdkVersion 15
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28 | implementation files('libs/eventbus-2.0.2.jar')
29 | }
30 |
--------------------------------------------------------------------------------
/app/libs/eventbus-2.0.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/libs/eventbus-2.0.2.jar
--------------------------------------------------------------------------------
/app/libs/xutils-3.3.32-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/libs/xutils-3.3.32-sources.jar
--------------------------------------------------------------------------------
/app/libs/xutils-3.3.32.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/libs/xutils-3.3.32.jar
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/kevin/vension/uploadservice/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.kevin.vension.uploadservice", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/kevin/vension/uploadservice/MainActivityTest.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice;
2 |
3 |
4 | import android.support.test.espresso.ViewInteraction;
5 | import android.support.test.rule.ActivityTestRule;
6 | import android.support.test.runner.AndroidJUnit4;
7 | import android.test.suitebuilder.annotation.LargeTest;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.view.ViewParent;
11 |
12 | import org.hamcrest.Description;
13 | import org.hamcrest.Matcher;
14 | import org.hamcrest.TypeSafeMatcher;
15 | import org.hamcrest.core.IsInstanceOf;
16 | import org.junit.Rule;
17 | import org.junit.Test;
18 | import org.junit.runner.RunWith;
19 |
20 | import static android.support.test.espresso.Espresso.onView;
21 | import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
22 | import static android.support.test.espresso.assertion.ViewAssertions.matches;
23 | import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
24 | import static android.support.test.espresso.matcher.ViewMatchers.withId;
25 | import static org.hamcrest.Matchers.allOf;
26 |
27 | @LargeTest
28 | @RunWith(AndroidJUnit4.class)
29 | public class MainActivityTest {
30 |
31 | @Rule
32 | public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
33 |
34 | @Test
35 | public void mainActivityTest() {
36 | // Added a sleep statement to match the app's execution delay.
37 | // The recommended way to handle such scenarios is to use Espresso idling resources:
38 | // https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
39 | try {
40 | Thread.sleep(2000);
41 | } catch (InterruptedException e) {
42 | e.printStackTrace();
43 | }
44 |
45 | ViewInteraction linearLayout = onView(
46 | allOf(childAtPosition(
47 | IsInstanceOf.instanceOf(android.widget.FrameLayout.class),
48 | 0),
49 | isDisplayed()));
50 | linearLayout.check(doesNotExist());
51 |
52 | ViewInteraction linearLayout2 = onView(
53 | allOf(childAtPosition(
54 | IsInstanceOf.instanceOf(android.widget.FrameLayout.class),
55 | 0),
56 | isDisplayed()));
57 | linearLayout2.check(doesNotExist());
58 |
59 | ViewInteraction view = onView(
60 | allOf(childAtPosition(
61 | allOf(withId(android.R.id.content),
62 | childAtPosition(
63 | withId(R.id.decor_content_parent),
64 | 1)),
65 | 0),
66 | isDisplayed()));
67 | view.check(matches(isDisplayed()));
68 |
69 | }
70 |
71 | private static Matcher childAtPosition(
72 | final Matcher parentMatcher, final int position) {
73 |
74 | return new TypeSafeMatcher() {
75 | @Override
76 | public void describeTo(Description description) {
77 | description.appendText("Child at position " + position + " in parent ");
78 | parentMatcher.describeTo(description);
79 | }
80 |
81 | @Override
82 | public boolean matchesSafely(View view) {
83 | ViewParent parent = view.getParent();
84 | return parent instanceof ViewGroup && parentMatcher.matches(parent)
85 | && view.equals(((ViewGroup) parent).getChildAt(position));
86 | }
87 | };
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/kevin/vension/uploadservice/ScreenShots.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice;
2 |
3 |
4 | import android.support.test.rule.ActivityTestRule;
5 | import android.support.test.runner.AndroidJUnit4;
6 | import android.test.suitebuilder.annotation.LargeTest;
7 |
8 | import org.junit.Rule;
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 |
12 | @LargeTest
13 | @RunWith(AndroidJUnit4.class)
14 | public class ScreenShots {
15 |
16 | @Rule
17 | public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
18 |
19 | @Test
20 | public void screenShots() {
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.os.Bundle;
6 | import android.preference.PreferenceManager;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 |
11 | import com.kevin.vension.uploadservice.model.PhotoUpload;
12 | import com.kevin.vension.uploadservice.model.PhotoUploadController;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 |
21 |
22 | addImage();
23 |
24 | }
25 |
26 | private void addImage() {
27 | MyApp app = (MyApp) getApplication();
28 | PhotoUploadController con = app.getPhotoUploadController();
29 | for (int i = 0; i < 20; i++) {
30 | PhotoUpload selection = new PhotoUpload();
31 | selection.setName("图片" + i);
32 | con.addUpload(selection);
33 | }
34 | startService(MyApp.createExplicitFromImplicitIntent(this, new Intent("INTENT_SERVICE_UPLOAD_ALL")));
35 | }
36 |
37 |
38 | @Override
39 | public boolean onCreateOptionsMenu(Menu menu) {
40 | // Inflate the menu; this adds items to the action bar if it is present.
41 | getMenuInflater().inflate(R.menu.main, menu);
42 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
43 | boolean isPaused = prefs.getBoolean("isPaused", false);
44 | menu.findItem(R.id.action_settings).setTitle(isPaused ? "Resume" : "Pause");
45 | return true;
46 | }
47 |
48 | @Override
49 | public boolean onOptionsItemSelected(MenuItem item) {
50 | // Handle action bar item clicks here. The action bar will
51 | // automatically handle clicks on the Home/Up button, so long
52 | // as you specify a parent activity in AndroidManifest.xml.
53 | int id = item.getItemId();
54 | if (id == R.id.action_settings) {
55 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
56 | boolean isPaused = prefs.getBoolean("isPaused", false);
57 | prefs.edit().putBoolean("isPaused", !isPaused).commit();
58 | if (isPaused) {
59 | startService(MyApp.createExplicitFromImplicitIntent(this, new Intent("INTENT_SERVICE_UPLOAD_ALL")));
60 | }
61 | return true;
62 | }
63 | return super.onOptionsItemSelected(item);
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/MyApp.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice;
2 |
3 | import android.app.Application;
4 | import android.content.ComponentName;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.pm.PackageManager;
8 | import android.content.pm.ResolveInfo;
9 |
10 | import com.kevin.vension.uploadservice.model.PhotoUploadController;
11 |
12 | import java.util.List;
13 |
14 | public class MyApp extends Application {
15 |
16 | private PhotoUploadController mPhotoController;
17 |
18 | @Override
19 | public void onCreate() {
20 | super.onCreate();
21 | mPhotoController = new PhotoUploadController(this);
22 | startService(createExplicitFromImplicitIntent(this, new Intent("INTENT_SERVICE_UPLOAD_ALL")));
23 | }
24 |
25 | public static MyApp getApplication(Context context) {
26 | return (MyApp) context.getApplicationContext();
27 | }
28 |
29 | public PhotoUploadController getPhotoUploadController() {
30 | return mPhotoController;
31 | }
32 |
33 | public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
34 | // Retrieve all services that can match the given intent
35 | PackageManager pm = context.getPackageManager();
36 | List resolveInfo = pm.queryIntentServices(implicitIntent, 0);
37 |
38 | // Make sure only one match was found
39 | if (resolveInfo == null || resolveInfo.size() != 1) {
40 | return null;
41 | }
42 |
43 | // Get component info and create ComponentName
44 | ResolveInfo serviceInfo = resolveInfo.get(0);
45 | String packageName = serviceInfo.serviceInfo.packageName;
46 | String className = serviceInfo.serviceInfo.name;
47 | ComponentName component = new ComponentName(packageName, className);
48 |
49 | // Create a new intent. Use the old one for extras and such reuse
50 | Intent explicitIntent = new Intent(implicitIntent);
51 |
52 | // Set the component to be explicit
53 | explicitIntent.setComponent(component);
54 |
55 | return explicitIntent;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/events/PhotoSelectionAddedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.kevin.vension.uploadservice.events;
17 |
18 | import com.kevin.vension.uploadservice.model.PhotoUpload;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | public class PhotoSelectionAddedEvent {
24 |
25 | private final List mUploads;
26 |
27 | public PhotoSelectionAddedEvent(List uploads) {
28 | mUploads = uploads;
29 | }
30 |
31 | public PhotoSelectionAddedEvent(PhotoUpload upload) {
32 | mUploads = new ArrayList();
33 | mUploads.add(upload);
34 | }
35 |
36 | public List getTargets() {
37 | return mUploads;
38 | }
39 |
40 | public PhotoUpload getTarget() {
41 | if (isSingleChange()) {
42 | return mUploads.get(0);
43 | } else {
44 | throw new IllegalStateException("Can only call this when isSingleChange returns true");
45 | }
46 | }
47 |
48 | public boolean isSingleChange() {
49 | return mUploads.size() == 1;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/events/PhotoSelectionRemovedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.kevin.vension.uploadservice.events;
17 |
18 | import com.kevin.vension.uploadservice.model.PhotoUpload;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 |
24 | public class PhotoSelectionRemovedEvent {
25 |
26 | private final List mUploads;
27 |
28 | public PhotoSelectionRemovedEvent(List uploads) {
29 | mUploads = uploads;
30 | }
31 |
32 | public PhotoSelectionRemovedEvent(PhotoUpload upload) {
33 | mUploads = new ArrayList();
34 | mUploads.add(upload);
35 | }
36 |
37 | public List getTargets() {
38 | return mUploads;
39 | }
40 |
41 | public PhotoUpload getTarget() {
42 | if (isSingleChange()) {
43 | return mUploads.get(0);
44 | } else {
45 | throw new IllegalStateException("Can only call this when isSingleChange returns true");
46 | }
47 | }
48 |
49 | public boolean isSingleChange() {
50 | return mUploads.size() == 1;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/events/UploadStateChangedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.kevin.vension.uploadservice.events;
17 |
18 |
19 | import com.kevin.vension.uploadservice.model.PhotoUpload;
20 |
21 | public class UploadStateChangedEvent {
22 |
23 | private final PhotoUpload mUpload;
24 |
25 | public UploadStateChangedEvent(PhotoUpload upload) {
26 | mUpload = upload;
27 | }
28 |
29 | public PhotoUpload getUpload() {
30 | return mUpload;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/events/UploadingPausedStateChangedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.kevin.vension.uploadservice.events;
17 |
18 | /** 上传任务状态改变 */
19 | public class UploadingPausedStateChangedEvent {
20 | // 空实现 直接开始下一个任务即可
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/events/UploadsModifiedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.kevin.vension.uploadservice.events;
17 |
18 | public class UploadsModifiedEvent {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/events/UploadsStartEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.kevin.vension.uploadservice.events;
17 |
18 | public class UploadsStartEvent {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/model/PhotoUpload.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice.model;
2 |
3 |
4 | import com.kevin.vension.uploadservice.events.UploadStateChangedEvent;
5 | import com.kevin.vension.uploadservice.events.UploadsModifiedEvent;
6 |
7 | import de.greenrobot.event.EventBus;
8 |
9 | /** 上传任务 */
10 | public class PhotoUpload {
11 |
12 | // 任务状态
13 | public static final int STATE_UPLOAD_COMPLETED = 5;
14 | public static final int STATE_UPLOAD_ERROR = 4;
15 | public static final int STATE_UPLOAD_IN_PROGRESS = 3;
16 | public static final int STATE_UPLOAD_WAITING = 2;
17 | public static final int STATE_SELECTED = 1;
18 | public static final int STATE_NONE = 0;
19 | private int mState;
20 | private String name;
21 |
22 | public int getUploadState() {
23 | return mState;
24 | }
25 |
26 | public void reset() {
27 | mState = STATE_NONE;
28 | }
29 |
30 | public void setUploadState(final int state) {
31 | if (mState != state) {
32 | mState = state;
33 |
34 | switch (state) {
35 | case STATE_UPLOAD_ERROR:
36 | case STATE_UPLOAD_COMPLETED:
37 | EventBus.getDefault().post(new UploadsModifiedEvent());
38 | break;
39 | case STATE_SELECTED:
40 | case STATE_UPLOAD_WAITING:
41 | break;
42 | }
43 | notifyUploadStateListener();
44 | }
45 | }
46 |
47 | private void notifyUploadStateListener() {
48 | EventBus.getDefault().post(new UploadStateChangedEvent(this));
49 | }
50 |
51 | public String getName() {
52 | return name;
53 | }
54 |
55 | public void setName(String name) {
56 | this.name = name;
57 | }
58 |
59 | @Override
60 | public String toString() {
61 | return name;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/model/PhotoUploadController.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice.model;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import com.kevin.vension.uploadservice.MyApp;
7 | import com.kevin.vension.uploadservice.events.UploadsModifiedEvent;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | import de.greenrobot.event.EventBus;
13 |
14 | /**
15 | * 上传事件队列
16 | */
17 | public class PhotoUploadController {
18 | public static PhotoUploadController getFromContext(Context context) {
19 | return MyApp.getApplication(context).getPhotoUploadController();
20 | }
21 |
22 | private final Context mContext;
23 | private final ArrayList mSelectedPhotoList;
24 |
25 | private final ArrayList mUploadingList;
26 |
27 | public PhotoUploadController(Context context) {
28 | mContext = context;
29 | mSelectedPhotoList = new ArrayList();
30 | mUploadingList = new ArrayList();
31 | }
32 |
33 | // 添加任务方法
34 | public boolean addUpload(PhotoUpload selection) {
35 | if (null != selection) {
36 | synchronized (this) {
37 | if (!mUploadingList.contains(selection)) {
38 | selection.setUploadState(PhotoUpload.STATE_UPLOAD_WAITING);
39 | mUploadingList.add(selection);
40 | mSelectedPhotoList.remove(selection);
41 | postEvent(new UploadsModifiedEvent());
42 | return true;
43 | }
44 | }
45 | }
46 |
47 | return false;
48 | }
49 |
50 | public synchronized int getActiveUploadsCount() {
51 | int count = 0;
52 | for (PhotoUpload upload : mUploadingList) {
53 | if (upload.getUploadState() != PhotoUpload.STATE_UPLOAD_COMPLETED) {
54 | count++;
55 | }
56 | }
57 | return count;
58 | }
59 |
60 | /* 获取下一个任务 */
61 | public synchronized PhotoUpload getNextUpload() {
62 | for (PhotoUpload selection : mUploadingList) {
63 | if (selection.getUploadState() == PhotoUpload.STATE_UPLOAD_WAITING) {
64 | return selection;
65 | }
66 | }
67 | return null;
68 | }
69 |
70 | public synchronized List getUploadingUploads() {
71 | return new ArrayList(mUploadingList);
72 | }
73 |
74 | public synchronized int getUploadsCount() {
75 | return mUploadingList.size();
76 | }
77 |
78 | public synchronized boolean hasSelections() {
79 | return !mSelectedPhotoList.isEmpty();
80 | }
81 |
82 | public synchronized boolean hasUploads() {
83 | return !mUploadingList.isEmpty();
84 | }
85 |
86 | public synchronized boolean hasWaitingUploads() {
87 | for (PhotoUpload upload : mUploadingList) {
88 | if (upload.getUploadState() == PhotoUpload.STATE_UPLOAD_WAITING) {
89 | return true;
90 | }
91 | }
92 | return false;
93 | }
94 |
95 | public synchronized boolean isOnUploadList(PhotoUpload selection) {
96 | return mUploadingList.contains(selection);
97 | }
98 |
99 | public synchronized boolean isSelected(PhotoUpload selection) {
100 | return mSelectedPhotoList.contains(selection);
101 | }
102 |
103 | public void removeUpload(final PhotoUpload selection) {
104 | boolean removed = false;
105 | synchronized (this) {
106 | removed = mUploadingList.remove(selection);
107 | }
108 | Log.e("图片上传","removeUpload==》" + removed);
109 | if (removed) {
110 | selection.setUploadState(PhotoUpload.STATE_NONE);
111 | postEvent(new UploadsModifiedEvent());
112 | }
113 | }
114 |
115 | public void reset() {
116 | synchronized (this) {
117 | mSelectedPhotoList.clear();
118 | mUploadingList.clear();
119 | }
120 |
121 | }
122 |
123 | private void postEvent(Object event) {
124 | EventBus.getDefault().post(event);
125 | }
126 |
127 | void populateFromDatabase() {
128 |
129 | final List uploadsFromDb = new ArrayList<>();// =
130 | // PhotoUploadDatabaseHelper.getUploads(mContext);
131 | if (null != uploadsFromDb) {
132 | mUploadingList.addAll(uploadsFromDb);
133 | // PhotoUpload.populateCache(uploadsFromDb);
134 | }
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/service/PhotupThreadRunnable.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice.service;
2 |
3 | import android.os.Process;
4 |
5 | public abstract class PhotupThreadRunnable implements Runnable {
6 |
7 | public final void run() {
8 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
9 |
10 | runImpl();
11 | }
12 |
13 | public abstract void runImpl();
14 |
15 | protected boolean isInterrupted() {
16 | return Thread.currentThread().isInterrupted();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/kevin/vension/uploadservice/service/UploadService.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice.service;
2 |
3 | import android.app.NotificationManager;
4 | import android.app.PendingIntent;
5 | import android.app.Service;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.SharedPreferences;
9 | import android.net.ConnectivityManager;
10 | import android.net.NetworkInfo;
11 | import android.os.IBinder;
12 | import android.preference.PreferenceManager;
13 | import android.support.v4.app.NotificationCompat;
14 | import android.util.Log;
15 |
16 | import com.kevin.vension.uploadservice.MainActivity;
17 | import com.kevin.vension.uploadservice.MyApp;
18 | import com.kevin.vension.uploadservice.R;
19 | import com.kevin.vension.uploadservice.events.UploadStateChangedEvent;
20 | import com.kevin.vension.uploadservice.events.UploadingPausedStateChangedEvent;
21 | import com.kevin.vension.uploadservice.model.PhotoUpload;
22 | import com.kevin.vension.uploadservice.model.PhotoUploadController;
23 |
24 | import org.xutils.common.Callback.CommonCallback;
25 | import org.xutils.http.RequestParams;
26 | import org.xutils.x;
27 |
28 | import java.io.File;
29 | import java.util.concurrent.ExecutorService;
30 | import java.util.concurrent.Executors;
31 | import java.util.concurrent.Future;
32 |
33 | import de.greenrobot.event.EventBus;
34 |
35 | public class UploadService extends Service {
36 | //
37 | private boolean mCurrentlyUploading;
38 | private ExecutorService mExecutor = Executors.newSingleThreadExecutor();
39 | private PhotoUploadController mController;
40 | private int mNumberUploaded = 0;
41 | private Future> mCurrentUploadRunnable;
42 | private EventBus bus = EventBus.getDefault();
43 | private NotificationCompat.Builder mNotificationBuilder;
44 | private NotificationManager mNotificationMgr;
45 |
46 | private class UpdateRunnable extends PhotupThreadRunnable {
47 |
48 | private final PhotoUpload mSelection;
49 |
50 | public UpdateRunnable(PhotoUpload selection) {
51 | mSelection = selection;
52 | }
53 |
54 | public void runImpl() {
55 | try {
56 | Log.e("图片上传","runImpl==》" + mController.getUploadsCount());
57 | if (mSelection.getUploadState() == PhotoUpload.STATE_UPLOAD_WAITING) {
58 | mSelection.setUploadState(PhotoUpload.STATE_UPLOAD_IN_PROGRESS);
59 | // 暂停1秒 模拟上传
60 | Thread.sleep(1000);
61 | // TODO 在这里配置文件服务器地址和参数,需要上传的文件 使用公司文件服务器测试通过
62 | RequestParams params = new RequestParams("https://www.baidu.com/");
63 | params.addBodyParameter("f", new File("文件路径"));
64 | x.http().post(params, new CommonCallback() {
65 |
66 | @Override
67 | public void onSuccess(String result) {
68 | mSelection.setUploadState(PhotoUpload.STATE_UPLOAD_COMPLETED);
69 | }
70 |
71 | @Override
72 | public void onError(Throwable ex, boolean isOnCallback) {
73 | mSelection.setUploadState(PhotoUpload.STATE_UPLOAD_ERROR);
74 | }
75 |
76 | @Override
77 | public void onCancelled(CancelledException cex) {
78 | mSelection.setUploadState(PhotoUpload.STATE_UPLOAD_WAITING);
79 | }
80 |
81 | @Override
82 | public void onFinished() {
83 | // 通知service
84 | Log.e("图片上传","onFinished==》" + mController.getUploadsCount());
85 | bus.post(new UploadingPausedStateChangedEvent());
86 | }
87 |
88 | });
89 | }
90 | } catch (InterruptedException e) {
91 | e.printStackTrace();
92 | }
93 | }
94 |
95 | }
96 |
97 | @Override
98 | public void onCreate() {
99 | super.onCreate();
100 | bus.register(this);
101 | mController = ((MyApp) getApplication()).getPhotoUploadController();
102 | mNotificationMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
103 | }
104 |
105 | @Override
106 | public void onDestroy() {
107 | super.onDestroy();
108 | bus.unregister(this);
109 | }
110 |
111 | @Override
112 | public IBinder onBind(Intent intent) {
113 | return null;
114 | }
115 |
116 | @Override
117 | public int onStartCommand(Intent intent, int flags, int startId) {
118 | if (null == intent || "INTENT_SERVICE_UPLOAD_ALL".equals(intent.getAction())) {
119 | if (uploadAll()) {
120 | return START_STICKY;
121 | }
122 | }
123 | return START_NOT_STICKY;
124 | }
125 |
126 | // 监听添加任务
127 | public void onEventMainThread(UploadStateChangedEvent event) {
128 | PhotoUpload upload = event.getUpload();
129 | switch (upload.getUploadState()) {
130 | case PhotoUpload.STATE_UPLOAD_IN_PROGRESS:
131 | updateNotification(upload);
132 | break;
133 | case PhotoUpload.STATE_UPLOAD_COMPLETED:
134 | mNumberUploaded++;
135 | mController.removeUpload(upload);
136 | case PhotoUpload.STATE_UPLOAD_ERROR:
137 | startNextUploadOrFinish();
138 |
139 | case PhotoUpload.STATE_UPLOAD_WAITING:
140 | break;
141 | }
142 | }
143 |
144 | // 监听任务改变
145 | void startNextUploadOrFinish() {
146 | PhotoUpload nextUpload = mController.getNextUpload();
147 | if (null != nextUpload && canUpload()) {
148 | startUpload(nextUpload);
149 | } else {
150 | mCurrentlyUploading = false;
151 | stopSelf();
152 | }
153 | }
154 |
155 | private boolean canUpload() {
156 | return !isUploadingPaused(this) && isConnected(this);
157 | }
158 |
159 | private void startUpload(PhotoUpload upload) {
160 | mCurrentUploadRunnable = mExecutor.submit(new UpdateRunnable(upload));
161 | mCurrentlyUploading = true;
162 | }
163 |
164 | private boolean uploadAll() {
165 | if (mCurrentlyUploading) {
166 | return true;
167 | }
168 |
169 | if (canUpload()) {
170 | PhotoUpload nextUpload = mController.getNextUpload();
171 | if (null != nextUpload) {
172 | startForeground();
173 | startUpload(nextUpload);
174 | return true;
175 | }
176 | }
177 |
178 | mCurrentlyUploading = false;
179 | stopSelf();
180 |
181 | return false;
182 | }
183 |
184 | void stopUploading() {
185 | if (null != mCurrentUploadRunnable) {
186 | mCurrentUploadRunnable.cancel(true);
187 | }
188 | mCurrentlyUploading = false;
189 | stopSelf();
190 | }
191 |
192 | public void onEvent(UploadingPausedStateChangedEvent event) {
193 | if (isUploadingPaused(this)) {
194 | stopUploading();
195 | } else {
196 | startNextUploadOrFinish();
197 | }
198 | }
199 |
200 | private boolean isUploadingPaused(UploadService uploadService) {
201 | SharedPreferences prefs = PreferenceManager
202 | .getDefaultSharedPreferences(this);
203 | return prefs.getBoolean("isPaused", false);
204 | }
205 |
206 | private void startForeground() {
207 | if (null == mNotificationBuilder) {
208 | mNotificationBuilder = new android.support.v4.app.NotificationCompat.Builder(
209 | this);
210 | mNotificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
211 | mNotificationBuilder.setContentTitle(getString(R.string.app_name));
212 | mNotificationBuilder.setOngoing(true);
213 | mNotificationBuilder.setWhen(System.currentTimeMillis());
214 |
215 | PendingIntent intent = PendingIntent.getActivity(this, 0,
216 | new Intent(this, MainActivity.class), 0);
217 | mNotificationBuilder.setContentIntent(intent);
218 | }
219 | startForeground(12, mNotificationBuilder.build());
220 | }
221 |
222 | void updateNotification(final PhotoUpload upload) {
223 | String text;
224 |
225 | switch (upload.getUploadState()) {
226 | case PhotoUpload.STATE_UPLOAD_WAITING:
227 | text = "上传: " + upload.getName();
228 | mNotificationBuilder.setContentTitle(text);
229 | mNotificationBuilder.setTicker(text);
230 | mNotificationBuilder.setProgress(0, 0, true);
231 | mNotificationBuilder.setWhen(System.currentTimeMillis());
232 | break;
233 |
234 | case PhotoUpload.STATE_UPLOAD_IN_PROGRESS:
235 | text = "上传: " + upload.getName();
236 | mNotificationBuilder.setContentTitle(text);
237 | mNotificationBuilder.setTicker(text);
238 | mNotificationBuilder.setProgress(0, 0, true);
239 | mNotificationBuilder.setWhen(System.currentTimeMillis());
240 |
241 | break;
242 | }
243 |
244 | mNotificationMgr.notify(12, mNotificationBuilder.build());
245 | }
246 |
247 | public static boolean isConnected(Context context) {
248 | ConnectivityManager mgr = (ConnectivityManager) context
249 | .getSystemService(Context.CONNECTIVITY_SERVICE);
250 | final NetworkInfo info = mgr.getActiveNetworkInfo();
251 | return null != info && info.isConnectedOrConnecting();
252 | }
253 |
254 | }
255 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | UpLoadService
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/kevin/vension/uploadservice/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.kevin.vension.uploadservice;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gif/GIF.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/gif/GIF.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vension/UpLoadService/7b2ac36252f1c3287b01f1bd92017ac168d8cdbc/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Dec 13 13:31:55 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------