173 |
173 |
174 contentView = new RemoteViews(getPackageName(), R.layout.notification); |
174 contentView = new RemoteViews(getPackageName(), R.layout.notification); |
175 contentView.setProgressBar(R.id.notification_progress, 100, 34, false); |
175 contentView.setProgressBar(R.id.notification_progress, 100, 34, false); |
176 progressNotification.contentView = contentView; |
176 progressNotification.contentView = contentView; |
177 |
177 |
178 PendingIntent contentIntent = PendingIntent.getActivity(DownloadService.this, 0, new Intent(DownloadService.this, DownloadFragment.class), Intent.FLAG_ACTIVITY_NEW_TASK); |
178 PendingIntent contentIntent = PendingIntent.getActivity(DownloadService.this, 0, new Intent(DownloadService.this, DownloadListActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK); |
179 progressNotification.contentIntent = contentIntent; |
179 progressNotification.contentIntent = contentIntent; |
180 |
180 |
181 startForeground(NOTIFICATION_PROCESSING, progressNotification); |
181 startForeground(NOTIFICATION_PROCESSING, progressNotification); |
182 |
182 |
183 Message msg = Message.obtain(null, DownloadFragment.MSG_START, max, 0); |
183 Message msg = Message.obtain(null, DownloadFragment.MSG_START, max, 0); |
197 |
197 |
198 //Call back from the ASync task when the task has either run into an error or finished otherwise |
198 //Call back from the ASync task when the task has either run into an error or finished otherwise |
199 public void done(int result){ |
199 public void done(int result){ |
200 switch(result){ |
200 switch(result){ |
201 case DownloadAsyncTask.EXIT_SUCCESS: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break; |
201 case DownloadAsyncTask.EXIT_SUCCESS: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break; |
202 case DownloadAsyncTask.EXIT_CONNERROR: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED)); break; |
202 case DownloadAsyncTask.EXIT_CONNERROR: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_CONNERROR, 0)); break; |
203 case DownloadAsyncTask.EXIT_FNF: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED)); break; |
203 case DownloadAsyncTask.EXIT_FNF: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_FNF, 0)); break; |
204 case DownloadAsyncTask.EXIT_MD5: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED)); break; |
204 case DownloadAsyncTask.EXIT_MD5: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_MD5, 0)); break; |
205 case DownloadAsyncTask.EXIT_URLFAIL: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED)); break; |
205 case DownloadAsyncTask.EXIT_URLFAIL: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_FAILED, DownloadAsyncTask.EXIT_URLFAIL, 0)); break; |
206 case DownloadAsyncTask.EXIT_CANCELLED: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break; |
206 case DownloadAsyncTask.EXIT_CANCELLED: sendMessageToClients(Message.obtain(handler, DownloadFragment.MSG_DONE)); break; |
207 } |
207 } |
208 |
208 |
209 stopForeground(true); |
209 stopForeground(true); |
210 nM.cancel(NOTIFICATION_PROCESSING); |
210 nM.cancel(NOTIFICATION_PROCESSING); |