project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadFragment.java
author Wuzzy <Wuzzy2@mail.ru>
Sat, 21 Oct 2017 18:38:28 +0200
changeset 12734 4e0e59255856
parent 10017 de822cd3df3a
permissions -rw-r--r--
Sniper rifle mission: Faster dynamite blow-up, also skip with precise
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
     1
/*
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6566
diff changeset
     3
 * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com>
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
     4
 *
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
     5
 * This program is free software; you can redistribute it and/or
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
     6
 * modify it under the terms of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
     8
 * of the License, or (at your option) any later version.
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
     9
 *
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    13
 * GNU General Public License for more details.
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    14
 *
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6700
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    18
 */
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    19
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    20
package org.hedgewars.hedgeroid.Downloader;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    21
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    22
import org.hedgewars.hedgeroid.R;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    23
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    24
import android.content.ComponentName;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    25
import android.content.Context;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    26
import android.content.Intent;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    27
import android.content.ServiceConnection;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    28
import android.os.Bundle;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    29
import android.os.Handler;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    30
import android.os.IBinder;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    31
import android.os.Message;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    32
import android.os.Messenger;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    33
import android.os.RemoteException;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    34
import android.support.v4.app.Fragment;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    35
import android.view.LayoutInflater;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    36
import android.view.View;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    37
import android.view.View.OnClickListener;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    38
import android.view.ViewGroup;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    39
import android.widget.Button;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    40
import android.widget.ProgressBar;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    41
import android.widget.TextView;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    42
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    43
public class DownloadFragment extends Fragment{
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    44
    public static final String EXTRA_TASK = "task";
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    45
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    46
    public static final int MSG_START = 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    47
    public static final int MSG_UPDATE = 1;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    48
    public static final int MSG_DONE = 2;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    49
    public static final int MSG_FAILED = 3;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    50
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    51
    private boolean boundToService = false;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    52
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    53
    private TextView progress_sub;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    54
    private ProgressBar progress;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    55
    private Button /*positive,*/ negative;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    56
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    57
    private DownloadPackage pack;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    58
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    59
    private Handler messageHandler;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    60
    private Messenger messenger, messengerService;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    61
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    62
    public static DownloadFragment getInstance(DownloadPackage task){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    63
        DownloadFragment df = new DownloadFragment();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    64
        Bundle args = new Bundle();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    65
        args.putParcelable(DownloadFragment.EXTRA_TASK, task);
6437
4ed58839b13b Android: fixed serviceconnectionleak, made the result code of asynctask a bit better, fix cancel button
Xeli
parents: 6434
diff changeset
    66
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    67
        df.setArguments(args);
6437
4ed58839b13b Android: fixed serviceconnectionleak, made the result code of asynctask a bit better, fix cancel button
Xeli
parents: 6434
diff changeset
    68
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    69
        return df;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    70
    }
6437
4ed58839b13b Android: fixed serviceconnectionleak, made the result code of asynctask a bit better, fix cancel button
Xeli
parents: 6434
diff changeset
    71
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    72
    public void onActivityCreated(Bundle savedInstanceState){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    73
        super.onActivityCreated(savedInstanceState);
6437
4ed58839b13b Android: fixed serviceconnectionleak, made the result code of asynctask a bit better, fix cancel button
Xeli
parents: 6434
diff changeset
    74
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    75
        messageHandler = new Handler(messageCallback);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    76
        messenger = new Messenger(messageHandler);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    77
        Intent i = new Intent(getActivity().getApplicationContext(), DownloadService.class);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    78
        getActivity().startService(i);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    79
        getActivity().bindService(new Intent(getActivity().getApplicationContext(), DownloadService.class), connection, Context.BIND_AUTO_CREATE);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    80
    }
6437
4ed58839b13b Android: fixed serviceconnectionleak, made the result code of asynctask a bit better, fix cancel button
Xeli
parents: 6434
diff changeset
    81
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    82
    public View onCreateView(LayoutInflater inflater, ViewGroup viewgroup, Bundle savedInstanceState){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    83
        View v = inflater.inflate(R.layout.download_progress, viewgroup, false);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    84
        progress_sub = (TextView)v.findViewById(R.id.progressbar_sub);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    85
        progress = (ProgressBar)v.findViewById(R.id.progressbar);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    86
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    87
        //positive = (Button) v.findViewById(R.id.background);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    88
        negative = (Button) v.findViewById(R.id.cancelDownload);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    89
        //positive.setOnClickListener(backgroundClicker);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    90
        negative.setOnClickListener(cancelClicker);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    91
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    92
        pack = getArguments().getParcelable(DownloadFragment.EXTRA_TASK);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    93
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    94
        return v;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    95
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    96
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    97
    private OnClickListener backgroundClicker = new OnClickListener(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    98
        public void onClick(View v){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    99
            getActivity().finish();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   100
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   101
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   102
    private OnClickListener cancelClicker = new OnClickListener(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   103
        public void onClick(View v){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   104
            if(messengerService != null){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   105
                Message message = Message.obtain(messageHandler, DownloadService.MSG_CANCEL, pack);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   106
                try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   107
                    messengerService.send(message);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   108
                } catch (RemoteException e) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   109
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   110
            //getActivity().finish();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   111
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   112
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   113
    private OnClickListener doneClicker = new OnClickListener(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   114
        public void onClick(View v){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   115
            getActivity().finish();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   116
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   117
    };
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   118
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   119
    private OnClickListener tryAgainClicker = new OnClickListener(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   120
        public void onClick(View v){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   121
            if(messengerService != null){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   122
                Message message = Message.obtain(messageHandler, DownloadService.MSG_ADDTASK, pack);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   123
                message.replyTo = messenger;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   124
                try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   125
                    messengerService.send(message);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   126
                } catch (RemoteException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   127
                    e.printStackTrace();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   128
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   129
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   130
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   131
    };
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   132
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   133
    public void onDestroy(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   134
        unBindFromService();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   135
        super.onDestroy();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   136
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   137
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   138
    private ServiceConnection connection = new ServiceConnection(){
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   139
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   140
        public void onServiceConnected(ComponentName name, IBinder service) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   141
            messengerService = new Messenger(service);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   142
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   143
            try{
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   144
                //give the service a task
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   145
                if(messengerService != null){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   146
                    Message message = Message.obtain(messageHandler, DownloadService.MSG_ADDTASK, pack);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   147
                    message.replyTo = messenger;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   148
                    messengerService.send(message);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   149
                }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   150
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   151
            }catch (RemoteException e){}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   152
        }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   153
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   154
        public void onServiceDisconnected(ComponentName name) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   155
            messengerService = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   156
        }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   157
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   158
    };
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   159
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   160
    public void unBindFromService(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   161
        if(messengerService != null){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   162
            try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   163
                Message message = Message.obtain(messageHandler, DownloadService.MSG_UNREGISTER_CLIENT, pack);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   164
                message.replyTo = messenger;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   165
                messengerService.send(message);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   166
            } catch (RemoteException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   167
                e.printStackTrace();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   168
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   169
        }
6437
4ed58839b13b Android: fixed serviceconnectionleak, made the result code of asynctask a bit better, fix cancel button
Xeli
parents: 6434
diff changeset
   170
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   171
        getActivity().unbindService(connection);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   172
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   173
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   174
    private Handler.Callback messageCallback = new Handler.Callback() {
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   175
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   176
        public boolean handleMessage(Message msg) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   177
            switch(msg.what){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   178
            case MSG_START:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   179
                progress.setMax(msg.arg1);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   180
                progress_sub.setText(String.format("%dkb/%dkb\n%s", 0, msg.arg1, ""));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   181
                //positive.setText(R.string.download_background);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   182
                //positive.setOnClickListener(backgroundClicker);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   183
                negative.setText(R.string.download_cancel);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   184
                negative.setOnClickListener(cancelClicker);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   185
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   186
            case MSG_UPDATE:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   187
                progress_sub.setText(String.format("%d%% - %dkb/%dkb\n%s",(msg.arg1*100)/msg.arg2, msg.arg1, msg.arg2, msg.obj));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   188
                progress.setProgress(msg.arg1);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   189
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   190
            case MSG_DONE:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   191
                progress.setProgress(progress.getMax());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   192
                progress_sub.setText(R.string.download_done);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   193
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   194
                //  positive.setText(R.string.download_back);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   195
                //  positive.setOnClickListener(doneClicker);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   196
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   197
                negative.setVisibility(View.INVISIBLE);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   198
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   199
            case MSG_FAILED:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   200
                progress.setProgress(progress.getMax());
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   201
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   202
                String errorMsg = getString(R.string.download_failed);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   203
                switch(msg.arg1){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   204
                case DownloadAsyncTask.EXIT_CONNERROR: progress_sub.setText(errorMsg + " " + "Connection error"); break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   205
                case DownloadAsyncTask.EXIT_FNF: progress_sub.setText(errorMsg + " " + "File not found"); break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   206
                case DownloadAsyncTask.EXIT_MD5: progress_sub.setText(errorMsg + " " + "MD5 check failed"); break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   207
                case DownloadAsyncTask.EXIT_URLFAIL: progress_sub.setText(errorMsg + " " + "Invalid url"); break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   208
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   209
                negative.setText(R.string.download_tryagain);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   210
                negative.setOnClickListener(tryAgainClicker);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   211
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   212
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   213
            return false;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   214
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   215
    };
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   216
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   217
}