• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
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 
17 package com.android.documentsui.services;
18 
19 import static junit.framework.Assert.assertFalse;
20 import static junit.framework.Assert.assertTrue;
21 
22 import android.app.Notification;
23 import android.app.Notification.Builder;
24 import android.content.Context;
25 
26 import com.android.documentsui.base.Features;
27 import com.android.documentsui.clipping.UrisSupplier;
28 import com.android.documentsui.R;
29 import com.android.documentsui.base.DocumentInfo;
30 import com.android.documentsui.base.DocumentStack;
31 import com.android.documentsui.services.FileOperationService.OpType;
32 
33 import java.text.NumberFormat;
34 
35 public class TestJob extends Job {
36 
37     private boolean mStarted;
38     private Runnable mStartRunnable;
39 
40     private int mNumOfNotifications = 0;
41 
TestJob(Context service, Listener listener, String id, @OpType int opType, DocumentStack stack, UrisSupplier srcs, Runnable startRunnable, Features features)42     TestJob(Context service, Listener listener, String id, @OpType int opType, DocumentStack stack,
43             UrisSupplier srcs, Runnable startRunnable, Features features) {
44         super(service, listener, id, opType, stack, srcs, features);
45 
46         mStartRunnable = startRunnable;
47     }
48 
49     @Override
start()50     void start() {
51         mStarted = true;
52 
53         mStartRunnable.run();
54     }
55 
assertStarted()56     void assertStarted() {
57         assertTrue(mStarted);
58     }
59 
assertNotStarted()60     void assertNotStarted() {
61         assertFalse(mStarted);
62     }
63 
fail(DocumentInfo doc)64     void fail(DocumentInfo doc) {
65         onFileFailed(doc);
66     }
67 
getNumOfNotifications()68     int getNumOfNotifications() {
69         return mNumOfNotifications;
70     }
71 
72     @Override
getSetupNotification()73     Notification getSetupNotification() {
74         ++mNumOfNotifications;
75         return getSetupNotification(service.getString(R.string.copy_preparing));
76     }
77 
78     @Override
getProgressNotification()79     Notification getProgressNotification() {
80         ++mNumOfNotifications;
81         double completed = mStarted ? 1F : 0F;
82         return mProgressBuilder
83                 .setProgress(1, (int) completed, true)
84                 .setSubText(NumberFormat.getPercentInstance().format(completed))
85                 .build();
86     }
87 
88     @Override
getFailureNotification()89     Notification getFailureNotification() {
90         // the "copy" stuff was just convenient and available :)
91         return getFailureNotification(
92                 R.plurals.copy_error_notification_title, R.drawable.ic_menu_copy);
93     }
94 
95     @Override
getWarningNotification()96     Notification getWarningNotification() {
97         throw new UnsupportedOperationException();
98     }
99 
100     @Override
createProgressBuilder()101     Builder createProgressBuilder() {
102         ++mNumOfNotifications;
103         // the "copy" stuff was just convenient and available :)
104         return super.createProgressBuilder(
105                 service.getString(R.string.copy_notification_title),
106                 R.drawable.ic_menu_copy,
107                 service.getString(android.R.string.cancel),
108                 R.drawable.ic_cab_cancel);
109     }
110 
111     @Override
finish()112     void finish() {
113     }
114 }
115