project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/Downloader/DownloadService.java
author Xeli
Thu, 01 Sep 2011 14:55:31 +0200
branchhedgeroid
changeset 5671 ba4c3a4c8b09
parent 5637 fcc0e5b3d66b
permissions -rw-r--r--
Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5621
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
     1
/*
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
     3
 * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com>
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
     4
 *
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
     8
 *
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    12
 * GNU General Public License for more details.
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    13
 *
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    15
 * along with this program; if not, write to the Free Software
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    17
 */
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    18
ea796c83ea47 added licenses
Xeli
parents: 5514
diff changeset
    19
5412
ab055114c788 Moved download classes to their own dir and fixed the way the dest dir is being 'build'
Xeli
parents: 5406
diff changeset
    20
package org.hedgewars.mobile.Downloader;
ab055114c788 Moved download classes to their own dir and fixed the way the dest dir is being 'build'
Xeli
parents: 5406
diff changeset
    21
ab055114c788 Moved download classes to their own dir and fixed the way the dest dir is being 'build'
Xeli
parents: 5406
diff changeset
    22
import java.util.ArrayList;
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    23
5412
ab055114c788 Moved download classes to their own dir and fixed the way the dest dir is being 'build'
Xeli
parents: 5406
diff changeset
    24
import org.hedgewars.mobile.MainActivity;
ab055114c788 Moved download classes to their own dir and fixed the way the dest dir is being 'build'
Xeli
parents: 5406
diff changeset
    25
import org.hedgewars.mobile.R;
ab055114c788 Moved download classes to their own dir and fixed the way the dest dir is being 'build'
Xeli
parents: 5406
diff changeset
    26
import org.hedgewars.mobile.Utils;
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    27
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    28
import android.app.Notification;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    29
import android.app.NotificationManager;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    30
import android.app.PendingIntent;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    31
import android.app.Service;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    32
import android.content.Intent;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    33
import android.os.Handler;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    34
import android.os.IBinder;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    35
import android.os.Message;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    36
import android.os.Messenger;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    37
import android.os.RemoteException;
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
    38
import android.preference.PreferenceManager;
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    39
import android.util.Log;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    40
import android.widget.RemoteViews;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    41
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    42
public class DownloadService extends Service {
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    43
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
    44
	public static final String PREF_DOWNLOADED = "downloaded";
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    45
	public static final int MSG_CANCEL = 0;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    46
	public static final int MSG_REGISTER_CLIENT = 1;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    47
	public static final int MSG_UNREGISTER_CLIENT = 2;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    48
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    49
	public static final int NOTIFICATION_PROCESSING = 0;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    50
	public static final int NOTIFICATION_DONE = 1;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    51
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    52
	private DownloadAsyncTask downloadTask;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    53
	private final Messenger messenger = new Messenger(new DownloadHandler());
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    54
	private NotificationManager nM;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    55
	private RemoteViews contentView;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    56
	private Notification notification;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    57
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    58
	private ArrayList<Messenger> clientList = new ArrayList<Messenger>();
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    59
	private Message onRegisterMessage = null;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    60
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    61
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    62
	class DownloadHandler extends Handler{
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    63
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    64
		public void handleMessage(Message msg){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    65
			switch(msg.what){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    66
			case MSG_CANCEL:
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    67
				downloadTask.cancel(false);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    68
				break;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    69
			case MSG_REGISTER_CLIENT:
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    70
				clientList.add(msg.replyTo);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    71
				if(onRegisterMessage != null){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    72
					try {
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    73
						msg.replyTo.send(Message.obtain(onRegisterMessage));
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    74
					} catch (RemoteException e) {
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    75
						e.printStackTrace();
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    76
					}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    77
				}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    78
				break;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    79
			case MSG_UNREGISTER_CLIENT:
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    80
				clientList.remove(msg.replyTo);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    81
				break;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    82
			}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    83
		}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    84
	}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    85
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    86
	public final static int TASKID_START = 0;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    87
	public final static int TASKID_CANCEL = 1;
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
    88
	public final static int TASKID_RETRY = 2;
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    89
	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    90
	public int onStartCommand(Intent intent, int flags, int startId){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    91
		switch(intent.getIntExtra("taskID", TASKID_START)){
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
    92
		case TASKID_RETRY:
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
    93
			if(downloadTask != null){
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
    94
				downloadTask.cancel(false);
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
    95
				downloadTask = null;
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
    96
			}
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    97
		case TASKID_START:
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    98
			nM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
    99
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   100
			notification = new Notification(R.drawable.statusbar, getString(R.string.notification_title), System.currentTimeMillis());
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   101
			//notification.flags |= Notification.FLAG_ONGOING_EVENT;// | Notification.FLAG_NO_CLEAR | Notification.FLAG_FOREGROUND_SERVICE;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   102
			notification.flags |= Notification.FLAG_ONGOING_EVENT;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   103
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   104
			contentView = new RemoteViews(getPackageName(), R.layout.notification);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   105
			contentView.setProgressBar(R.id.notification_progress, 100, 34, false);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   106
			notification.contentView = contentView;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   107
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   108
			PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, DownloadActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   109
			notification.contentIntent = contentIntent;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   110
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   111
			//nM.notify(NOTIFICATION_PROCESSING, notification);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   112
			startForeground(NOTIFICATION_PROCESSING, notification);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   113
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   114
			if(downloadTask == null){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   115
				downloadTask = new DownloadAsyncTask(this);
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   116
				downloadTask.execute(Utils.getDownloadPath(this));
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   117
			}	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   118
			break;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   119
		case TASKID_CANCEL:
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   120
			downloadTask.cancel(false);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   121
			stopService();
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   122
			break;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   123
		}		
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   124
		return 0;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   125
	}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   126
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   127
	public void onDestroy(){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   128
		Log.e("bla", "onDestroy");
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   129
		downloadTask.cancel(false);	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   130
	}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   131
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   132
	public IBinder onBind(Intent intent) {
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   133
		return messenger.getBinder();
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   134
	}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   135
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   136
	/*
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   137
	 * Thread safe method to let clients know the processing is starting and will process int max kbytes
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   138
	 */
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   139
	public void start(int max){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   140
		onRegisterMessage = Message.obtain(null, DownloadActivity.MSG_START, max, -1);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   141
		sendMessageToClients(onRegisterMessage);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   142
	}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   143
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   144
	/*
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   145
	 * periodically gets called by the ASyncTask, we can't tell for sure when it's called
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   146
	 */
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   147
	public void update(int progress, int max, String fileName){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   148
		progress = (progress/1024);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   149
		updateNotification(progress, max, fileName);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   150
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   151
		sendMessageToClients(Message.obtain(null, DownloadActivity.MSG_UPDATE, progress, max, fileName));
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   152
	}
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   153
	
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   154
	/*
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   155
	 * Call back from the ASync task when the task has either run into an error or finished otherwise
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   156
	 */
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   157
	public void done(boolean succesful){
5671
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   158
		if(succesful){
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   159
			PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(DownloadService.PREF_DOWNLOADED, true).commit();
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   160
			sendMessageToClients(Message.obtain(null, DownloadActivity.MSG_DONE));
ba4c3a4c8b09 Check if we need to download and prevent user from reaching the startgame menu because it needs images from the download
Xeli
parents: 5637
diff changeset
   161
		}else sendMessageToClients(Message.obtain(null, DownloadActivity.MSG_FAILED));
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   162
		stopService();//stopService clears all notifications and thus must be called before we show the ready notification
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   163
		showDoneNotification();
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   164
	}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   165
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   166
	private void stopService(){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   167
		nM.cancelAll();
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   168
		stopForeground(true);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   169
		stopSelf();
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   170
	}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   171
	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   172
	private void updateNotification(int progress, int max, String fileName){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   173
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   174
		contentView.setProgressBar(R.id.notification_progress, max, progress, false);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   175
		contentView.setTextViewText(R.id.progressbar_sub, String.format("%dkb/%dkb (Compressed sizes)", progress, max));
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   176
		nM.notify(NOTIFICATION_PROCESSING, notification);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   177
	}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   178
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   179
	private void showDoneNotification(){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   180
		nM.cancelAll();
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   181
		stopForeground(true);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   182
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   183
		String title = getString(R.string.notification_title);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   184
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   185
		notification = new Notification(R.drawable.icon, title, System.currentTimeMillis());
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   186
		notification.flags |= Notification.FLAG_AUTO_CANCEL;
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   187
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   188
		notification.setLatestEventInfo(this, title, getString(R.string.notification_done), contentIntent);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   189
		nM.notify(NOTIFICATION_DONE, notification);
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   190
	}	
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   191
	private void sendMessageToClients(Message msg){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   192
		for(Messenger m : clientList){
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   193
			try {
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   194
				m.send(Message.obtain(msg));
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   195
			} catch (RemoteException e) {}//TODO should we catch this properly?
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   196
		}
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   197
	}
5412
ab055114c788 Moved download classes to their own dir and fixed the way the dest dir is being 'build'
Xeli
parents: 5406
diff changeset
   198
5397
4ae1b082e4ba Added download functionality and changed some icons
Xeli
parents:
diff changeset
   199
}