Java Code Examples for com.google.android.vending.expansion.downloader.Helpers#getDownloaderStringResourceIDFromState()

The following examples show how to use com.google.android.vending.expansion.downloader.Helpers#getDownloaderStringResourceIDFromState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadNotification.java    From QtAndroidTools with MIT License 4 votes vote down vote up
void onDownloadStateChanged(int newState) {
    mClientProxy.onDownloadStateChanged(newState);
    if (newState != mState) {
        mState = newState;
        if (newState == IDownloaderClient.STATE_IDLE || null == mContentIntent) {
            return;
        }
        @StringRes int stringDownloadID;
        int iconResource;
        boolean ongoingEvent;

        mBuilder.setPriority(NotificationCompat.PRIORITY_LOW);

        // get the new title string and paused text
        switch (newState) {
            case 0:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = AndroidApkExpansionFiles.STRING_UNKNOWN;
                ongoingEvent = false;
                break;

            case IDownloaderClient.STATE_DOWNLOADING:
                iconResource = android.R.drawable.stat_sys_download;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = true;
                break;

            case IDownloaderClient.STATE_FETCHING_URL:
            case IDownloaderClient.STATE_CONNECTING:
                iconResource = android.R.drawable.stat_sys_download_done;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = true;
                break;

            case IDownloaderClient.STATE_COMPLETED:
                // show notification without progress
                mCurrentBuilder = mBuilder;
                mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
            case IDownloaderClient.STATE_PAUSED_BY_REQUEST:
                iconResource = android.R.drawable.stat_sys_download_done;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = false;
                break;

            case IDownloaderClient.STATE_FAILED:
            case IDownloaderClient.STATE_FAILED_CANCELED:
            case IDownloaderClient.STATE_FAILED_FETCHING_URL:
            case IDownloaderClient.STATE_FAILED_SDCARD_FULL:
            case IDownloaderClient.STATE_FAILED_UNLICENSED:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = false;
                break;

            default:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = true;
                break;
        }

        mCurrentText = AndroidApkExpansionFiles.getString(stringDownloadID);
        mCurrentTitle = mLabel;
        mCurrentBuilder.setTicker(mLabel + ": " + mCurrentText);
        mCurrentBuilder.setSmallIcon(iconResource);
        mCurrentBuilder.setContentTitle(mCurrentTitle);
        mCurrentBuilder.setContentText(mCurrentText);
        if (ongoingEvent) {
            mCurrentBuilder.setOngoing(true);
            mCurrentBuilder.setOnlyAlertOnce(true);
        } else {
            mCurrentBuilder.setOnlyAlertOnce(false);
            mCurrentBuilder.setOngoing(false);
            mCurrentBuilder.setAutoCancel(true);
        }
        mNotificationManager.notify(NOTIFICATION_ID, mCurrentBuilder.build());
    }
}
 
Example 2
Source File: DownloadNotification.java    From play-apk-expansion with Apache License 2.0 4 votes vote down vote up
@Override
public void onDownloadStateChanged(int newState) {
    if (null != mClientProxy) {
        mClientProxy.onDownloadStateChanged(newState);
    }
    if (newState != mState) {
        mState = newState;
        if (newState == IDownloaderClient.STATE_IDLE || null == mContentIntent) {
            return;
        }
        int stringDownloadID;
        int iconResource;
        boolean ongoingEvent;

        // get the new title string and paused text
        switch (newState) {
            case 0:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = R.string.state_unknown;
                ongoingEvent = false;
                break;

            case IDownloaderClient.STATE_DOWNLOADING:
                iconResource = android.R.drawable.stat_sys_download;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = true;
                break;

            case IDownloaderClient.STATE_FETCHING_URL:
            case IDownloaderClient.STATE_CONNECTING:
                iconResource = android.R.drawable.stat_sys_download_done;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = true;
                break;

            case IDownloaderClient.STATE_COMPLETED:
            case IDownloaderClient.STATE_PAUSED_BY_REQUEST:
                iconResource = android.R.drawable.stat_sys_download_done;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = false;
                break;

            case IDownloaderClient.STATE_FAILED:
            case IDownloaderClient.STATE_FAILED_CANCELED:
            case IDownloaderClient.STATE_FAILED_FETCHING_URL:
            case IDownloaderClient.STATE_FAILED_SDCARD_FULL:
            case IDownloaderClient.STATE_FAILED_UNLICENSED:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = false;
                break;

            default:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = true;
                break;
        }

        mCurrentText = mContext.getString(stringDownloadID);
        mCurrentTitle = mLabel;
        mCurrentBuilder.setTicker(mLabel + ": " + mCurrentText);
        mCurrentBuilder.setSmallIcon(iconResource);
        mCurrentBuilder.setContentTitle(mCurrentTitle);
        mCurrentBuilder.setContentText(mCurrentText);
        if (ongoingEvent) {
            mCurrentBuilder.setOngoing(true);
        } else {
            mCurrentBuilder.setOngoing(false);
            mCurrentBuilder.setAutoCancel(true);
        }
        mNotificationManager.notify(NOTIFICATION_ID, mCurrentBuilder.build());
    }
}
 
Example 3
Source File: DownloadNotification.java    From travelguide with Apache License 2.0 4 votes vote down vote up
@Override
public void onDownloadStateChanged(int newState) {
    if (null != mClientProxy) {
        mClientProxy.onDownloadStateChanged(newState);
    }
    if (newState != mState) {
        mState = newState;
        if (newState == IDownloaderClient.STATE_IDLE || null == mContentIntent) {
            return;
        }
        int stringDownloadID;
        int iconResource;
        boolean ongoingEvent;

        // get the new title string and paused text
        switch (newState) {
            case 0:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = R.string.state_unknown;
                ongoingEvent = false;
                break;

            case IDownloaderClient.STATE_DOWNLOADING:
                iconResource = android.R.drawable.stat_sys_download;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = true;
                break;

            case IDownloaderClient.STATE_FETCHING_URL:
            case IDownloaderClient.STATE_CONNECTING:
                iconResource = android.R.drawable.stat_sys_download_done;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = true;
                break;

            case IDownloaderClient.STATE_COMPLETED:
            case IDownloaderClient.STATE_PAUSED_BY_REQUEST:
                iconResource = android.R.drawable.stat_sys_download_done;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = false;
                break;

            case IDownloaderClient.STATE_FAILED:
            case IDownloaderClient.STATE_FAILED_CANCELED:
            case IDownloaderClient.STATE_FAILED_FETCHING_URL:
            case IDownloaderClient.STATE_FAILED_SDCARD_FULL:
            case IDownloaderClient.STATE_FAILED_UNLICENSED:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = false;
                break;

            default:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                ongoingEvent = true;
                break;
        }
        mCurrentText = mContext.getString(stringDownloadID);
        mCurrentTitle = mLabel.toString();
        mCurrentNotification.tickerText = mLabel + ": " + mCurrentText;
        mCurrentNotification.icon = iconResource;
        mCurrentNotification.setLatestEventInfo(mContext, mCurrentTitle, mCurrentText,
                mContentIntent);
        if (ongoingEvent) {
            mCurrentNotification.flags |= Notification.FLAG_ONGOING_EVENT;
        } else {
            mCurrentNotification.flags &= ~Notification.FLAG_ONGOING_EVENT;
            mCurrentNotification.flags |= Notification.FLAG_AUTO_CANCEL;
        }
        mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification);
    }
}
 
Example 4
Source File: DownloadNotification.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
   public void onDownloadStateChanged(int newState) {
       if (null != mClientProxy) {
           mClientProxy.onDownloadStateChanged(newState);
       }
       if (newState != mState) {
           mState = newState;
           if (newState == IDownloaderClient.STATE_IDLE || null == mContentIntent) {
               return;
           }
           int stringDownloadID;
           int iconResource;
           boolean ongoingEvent;

           // get the new title string and paused text
           switch (newState) {
               case 0:
                   iconResource = android.R.drawable.stat_sys_warning;
                   stringDownloadID = R.string.state_unknown;
                   ongoingEvent = false;
                   break;

               case IDownloaderClient.STATE_DOWNLOADING:
                   iconResource = android.R.drawable.stat_sys_download;
                   stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                   ongoingEvent = true;
                   break;

               case IDownloaderClient.STATE_FETCHING_URL:
               case IDownloaderClient.STATE_CONNECTING:
                   iconResource = android.R.drawable.stat_sys_download_done;
                   stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                   ongoingEvent = true;
                   break;

               case IDownloaderClient.STATE_COMPLETED:
               case IDownloaderClient.STATE_PAUSED_BY_REQUEST:
                   iconResource = android.R.drawable.stat_sys_download_done;
                   stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                   ongoingEvent = false;
                   break;

               case IDownloaderClient.STATE_FAILED:
               case IDownloaderClient.STATE_FAILED_CANCELED:
               case IDownloaderClient.STATE_FAILED_FETCHING_URL:
               case IDownloaderClient.STATE_FAILED_SDCARD_FULL:
               case IDownloaderClient.STATE_FAILED_UNLICENSED:
                   iconResource = android.R.drawable.stat_sys_warning;
                   stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                   ongoingEvent = false;
                   break;

               default:
                   iconResource = android.R.drawable.stat_sys_warning;
                   stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(newState);
                   ongoingEvent = true;
                   break;
           }
           mCurrentText = mContext.getString(stringDownloadID);
           mCurrentTitle = mLabel.toString();
           mCurrentNotification.tickerText = mLabel + ": " + mCurrentText;
           mCurrentNotification.icon = iconResource;
           mCurrentNotification.setLatestEventInfo(mContext, mCurrentTitle, mCurrentText,
                   mContentIntent);
           if (ongoingEvent) {
               mCurrentNotification.flags |= Notification.FLAG_ONGOING_EVENT;
           } else {
               mCurrentNotification.flags &= ~Notification.FLAG_ONGOING_EVENT;
               mCurrentNotification.flags |= Notification.FLAG_AUTO_CANCEL;
           }
           mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification);
       }
   }
 
Example 5
Source File: DownloadNotification.java    From UnityOBBDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public void onDownloadStateChanged(int newState) {
    if (null != mClientProxy) {
        mClientProxy.onDownloadStateChanged(newState);
    }
    if (newState != mState) {
        mState = newState;
        if (newState == IDownloaderClient.STATE_IDLE || null == mContentIntent) {
            return;
        }
        int stringDownloadID;
        int iconResource;
        boolean ongoingEvent;

        // get the new title string and paused text
        switch (newState) {
            case 0:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = Helpers.getStringResource(mContext, "state_unknown");
                ongoingEvent = false;
                break;

            case IDownloaderClient.STATE_DOWNLOADING:
                iconResource = android.R.drawable.stat_sys_download;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(mContext, newState);
                ongoingEvent = true;
                break;

            case IDownloaderClient.STATE_FETCHING_URL:
            case IDownloaderClient.STATE_CONNECTING:
                iconResource = android.R.drawable.stat_sys_download_done;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(mContext, newState);
                ongoingEvent = true;
                break;

            case IDownloaderClient.STATE_COMPLETED:
            case IDownloaderClient.STATE_PAUSED_BY_REQUEST:
                iconResource = android.R.drawable.stat_sys_download_done;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(mContext, newState);
                ongoingEvent = false;
                break;

            case IDownloaderClient.STATE_FAILED:
            case IDownloaderClient.STATE_FAILED_CANCELED:
            case IDownloaderClient.STATE_FAILED_FETCHING_URL:
            case IDownloaderClient.STATE_FAILED_SDCARD_FULL:
            case IDownloaderClient.STATE_FAILED_UNLICENSED:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(mContext, newState);
                ongoingEvent = false;
                break;

            default:
                iconResource = android.R.drawable.stat_sys_warning;
                stringDownloadID = Helpers.getDownloaderStringResourceIDFromState(mContext, newState);
                ongoingEvent = true;
                break;
        }

        mCurrentText = mContext.getString(stringDownloadID);
        mCurrentTitle = mLabel;
        mCurrentBuilder.setTicker(mLabel + ": " + mCurrentText)
        .setSmallIcon(iconResource)
        .setContentTitle(mCurrentTitle)
        .setContentText(mCurrentText);
        if (ongoingEvent) {
            mCurrentBuilder.setOngoing(true);
        } else {
            mCurrentBuilder.setOngoing(false);
            mCurrentBuilder.setAutoCancel(true);
        }
        Notification notification;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            notification = mCurrentBuilder.build();
        } else {
            notification = mCurrentBuilder.getNotification();
        }
        mNotificationManager.notify(NOTIFICATION_ID, notification);
    }
}