• 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.example.android.networkconnect;
18 
19 import android.net.NetworkInfo;
20 import android.support.annotation.IntDef;
21 
22 /**
23  * Sample interface containing bare minimum methods needed for an asynchronous task
24  * to update the UI Context.
25  */
26 
27 public interface DownloadCallback {
28     interface Progress {
29         int ERROR = -1;
30         int CONNECT_SUCCESS = 0;
31         int GET_INPUT_STREAM_SUCCESS = 1;
32         int PROCESS_INPUT_STREAM_IN_PROGRESS = 2;
33         int PROCESS_INPUT_STREAM_SUCCESS = 3;
34     }
35 
36     /**
37      * Indicates that the callback handler needs to update its appearance or information based on
38      * the result of the task. Expected to be called from the main thread.
39      */
updateFromDownload(String result)40     void updateFromDownload(String result);
41 
42     /**
43      * Get the device's active network status in the form of a NetworkInfo object.
44      */
getActiveNetworkInfo()45     NetworkInfo getActiveNetworkInfo();
46 
47     /**
48      * Indicate to callback handler any progress update.
49      * @param progressCode must be one of the constants defined in DownloadCallback.Progress.
50      * @param percentComplete must be 0-100.
51      */
onProgressUpdate(int progressCode, int percentComplete)52     void onProgressUpdate(int progressCode, int percentComplete);
53 
54     /**
55      * Indicates that the download operation has finished. This method is called even if the
56      * download hasn't completed successfully.
57      */
finishDownloading()58     void finishDownloading();
59 
60 }
61