@Override public void onStop(DownloadTask task) throws RemoteException { if (mNotificationManager != null && mNotification != null) { mNotification.tickerText = mStopTickerText; mNotification.flags = Notification.FLAG_AUTO_CANCEL; mNotification.contentIntent = mPendingIntent; // if (RecommAppsUtils.isZh()) { mNotification.setLatestEventInfo( mContext, mPauseText, mProgressText + " " + task.getAlreadyDownloadPercent() + "%", mPendingIntent); // } else { // mNotification.setLatestEventInfo(mContext, mPauseText, // task.getAlreadyDownloadPercent() + "%", // mPendingIntent); // } // mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); if (mNotification.contentView != null) { mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); } } if (task != null) { // add by xiedezhi sendBroadcastingToAppCenter(task); } }
@Override public void onFail(DownloadTask task) throws RemoteException { // TODO Auto-generated method stub if (mContext != null && task != null) { if (mNotificationManager != null) { // 移除之前的通知 mNotificationManager.cancel(NOTIFY_TAG, (int) task.getId()); // 更新下载信息 if (mShowNotification && mNotification != null) { mNotification.tickerText = mFailTickerText; mNotification.contentIntent = mPendingIntent; // mNotificationRemoteViews.setTextViewText(R.id.downloadTextView, mFailText); // mNotification.contentView = mNotificationRemoteViews; mNotification.setLatestEventInfo( mContext, mFailText, mProgressText + " " + task.getAlreadyDownloadPercent() + "%", mPendingIntent); mNotification.flags = Notification.FLAG_AUTO_CANCEL; // mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); if (mNotification.contentView != null) { mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); } } } } }
@Override public void onUpdate(DownloadTask task) throws RemoteException { if (task == null) { return; } if (task != null) { long currentTime = System.currentTimeMillis(); if (mStartDonwload == 0) { mStartDonwload = currentTime; mAlreadyDownloadSize = task.getAlreadyDownloadSize(); } if (currentTime - mPrevRefreshTime > REFRESH_INTERVAL) { mPrevRefreshTime = currentTime; if (mShowNotification && mNotificationManager != null && mNotification != null) { // 更新通知栏的step为1% if (task.getAlreadyDownloadPercent() < mPercentCount && mPercentCount > 100) { return; } sendBroadcastingToAppCenter(task); mPercentCount += mStep; mDisplayPercent = task.getAlreadyDownloadPercent(); mNotification.flags = Notification.FLAG_ONGOING_EVENT; mNotification.contentIntent = mPendingIntent; mNotification.setLatestEventInfo( mContext, mDownloadText, mProgressText + " " + task.getAlreadyDownloadPercent() + "%", mPendingIntent); // mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); if (mNotification.contentView != null) { mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); } } } } }
@Override public void onStart(DownloadTask task) throws RemoteException { // TODO Auto-generated method stub if (task == null) { // add by zhaojunjie return; } AppGameNetLogControll.getInstance() .startRecord( mContext, AppGameNetLogControll.DEFAULT_CURRENT_THREAD_CODE, AppGameNetInfoLog.NETLOG_TYPE_FOR_DOWNLOAD_APK); AppGameNetLogControll.getInstance() .setUrl(AppGameNetLogControll.DEFAULT_CURRENT_THREAD_CODE, task.getDownloadUrl()); mChildThreadCode = Thread.currentThread().hashCode(); mStartConntion = System.currentTimeMillis(); sendBroadcastingToAppCenter(task); if (mContext != null && mNotificationManager != null) { String downloadName = task.getDownloadName(); if (downloadName != null) { mStartTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_start_text)); mStopTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_stop_text)); mFailTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_fail_text)); mCompletedTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_complete_text)); mCancelTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_cancel_text)); mConnectText = String.format( DOWNLOAD_INFO_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_connect_text)); mDownloadText = String.format( DOWNLOAD_INFO_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_download_text)); mPauseText = String.format( DOWNLOAD_INFO_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_pause_text)); mFailText = String.format( DOWNLOAD_INFO_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_fail_text)); mCompleteText = mContext.getString(R.string.appgame_notification_complete_text); mProgressText = mContext.getString(R.string.appgame_notification_progress_text); Intent intent = new Intent(); intent.setClass(mContext, AppsDownloadActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mPendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mNotification = new Notification( R.drawable.notification_download_icon, mStartTickerText, System.currentTimeMillis()); mNotification.contentIntent = mPendingIntent; mNotification.flags = Notification.FLAG_AUTO_CANCEL; mNotification.setLatestEventInfo( mContext, mConnectText, mProgressText + " " + task.getAlreadyDownloadPercent() + "%", mPendingIntent); if (mNotification.contentView != null) { mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); } } else { mShowNotification = false; } } }