Android Open Source - android-gskbyte-utils Download Dialog Fragment






From Project

Back to project page android-gskbyte-utils.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project android-gskbyte-utils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.gskbyte.dialog;
//from   w  ww. j a v a2 s  .c o m
import org.gskbyte.R;
import org.gskbyte.download.DiskDownload;
import org.gskbyte.download.Download;
import org.gskbyte.download.DownloadManager;
import org.gskbyte.download.MemoryDownload;
import org.gskbyte.util.Logger;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.Toast;

public class DownloadDialogFragment
extends LoadDialogFragment
implements Download.Listener
{

private static final String KEY_DOWNLOAD_REQUEST = "downloadRequest";

private Download download;
private Listener listener = null;

public static interface Listener
{
    public void downloadDialogDidDismiss(DownloadDialogFragment dialog, boolean downloadSucceeded);
}

public static DownloadDialogFragment NewInstanceForDownload(Download.Request d)
{
    DownloadDialogFragment fragment = new DownloadDialogFragment();
    
    Bundle args = new Bundle();
    args.putSerializable(KEY_DOWNLOAD_REQUEST, d);
    fragment.setArguments(args);
    
    return fragment;
}
    
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);    
    Download.Request request = (Download.Request) getArguments().getSerializable(KEY_DOWNLOAD_REQUEST);
    
    if(request != null) {
        if(request instanceof MemoryDownload.Request) {
            download = new MemoryDownload((MemoryDownload.Request)request);
        } else if(request instanceof DiskDownload.Request) {
            download = new DiskDownload((DiskDownload.Request)request);
        } else {
            Logger.error(getClass(), "Download Request class not recognized: " + request.getClass());
        }
    }
    if(download != null) {
        download.addListener(this);
        download.resume();
    } else {
        Logger.error(getClass(), "No download to start with, dismissing");
        onDownloadFailed(null);
    }
}

@Override
public void onDestroy()
{
    super.onDestroy();
    download = null;
    listener = null;
}

public Download getDownload()
{ return download; }

public void setDownload(Download d)
{ download = d; }

public void setListener(Listener listener)
{ this.listener = listener; }

public void show(FragmentManager manager, String tag)
{
    throw new IllegalStateException("Call showAndBeginDownload() to show this");
}

public int show(FragmentTransaction ft, String tag)
{
    throw new IllegalStateException("Call showAndBeginDownload() to show this");
}

public void showAndBeginDownload(FragmentManager fm, String tag)
{
    super.show(fm, getClass().toString());
}

public void showAndBeginDownloadCheckingWiFi(Context context, final FragmentManager fm, final String tag)
{
    if( DownloadManager.IsConnectionActive(context) ) {
        if( DownloadManager.IsConnectionWifi(context) ) {
            showAndBeginDownload(fm, tag);
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setCancelable(false);
            builder.setTitle(R.string.no_wifi_detected);
            builder.setMessage(R.string.no_wifi_detected_description);
            builder.setNegativeButton(R.string.no, null);
            builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {
                    showAndBeginDownload(fm, tag);
                }
            });
            builder.create().show();
        }
    } else {
        Toast.makeText(context, R.string.error_connection_not_available, Toast.LENGTH_SHORT).show();
    }
}

@Override
public void onDownloadStarted(Download download)
{
    
}

@Override
public void onDownloadFailed(Download download)
{
    dismiss();
    if(listener != null)
        listener.downloadDialogDidDismiss(this, false);
}

@Override
public void onDownloadRate(Download download, float rate)
{
    setProgressRate(rate);
}

@Override
public void onDownloadFinished(Download download)
{
    dismiss();
    if(listener != null)
        listener.downloadDialogDidDismiss(this, true);
}

}




Java Source Code List

com.woozzu.android.widget.IndexScroller.java
com.woozzu.android.widget.IndexableListView.java
org.gskbyte.FragmentWrapperActivity.java
org.gskbyte.animation.ExpandAnimation.java
org.gskbyte.bitmap.AbstractBitmapManager.java
org.gskbyte.bitmap.BitmapColorizer.java
org.gskbyte.bitmap.BitmapManager.java
org.gskbyte.bitmap.CachedBitmapColorizer.java
org.gskbyte.bitmap.IndexedBitmaps.java
org.gskbyte.bitmap.LRUBitmapCache.java
org.gskbyte.bitmap.LRUBitmapManager.java
org.gskbyte.bitmap.PrivateBitmapManager.java
org.gskbyte.bitmap.ReferencedBitmaps.java
org.gskbyte.collection.ArrayHashMap.java
org.gskbyte.collection.DoubleSparseArray.java
org.gskbyte.collection.ListHashMap.java
org.gskbyte.dialog.DownloadDialogFragment.java
org.gskbyte.dialog.LoadDialogFragment.java
org.gskbyte.dialog.OpenLinkDialogBuilder.java
org.gskbyte.dialog.PickerDialogFragment.java
org.gskbyte.download.DiskDownload.java
org.gskbyte.download.DownloadManager.java
org.gskbyte.download.Download.java
org.gskbyte.download.MemoryDownload.java
org.gskbyte.drawable.AutoBackgroundButtonDrawable.java
org.gskbyte.listener.IListenable.java
org.gskbyte.listener.ListenableNG.java
org.gskbyte.listener.Listenable.java
org.gskbyte.preferences.DialogSeekBarPreference.java
org.gskbyte.preferences.InlineSeekBarPreference.java
org.gskbyte.remote.AsyncURLRequest.java
org.gskbyte.remote.URLRequest.java
org.gskbyte.tasks.QueuedTaskExecutor.java
org.gskbyte.tasks.TaskStep.java
org.gskbyte.tasks.Task.java
org.gskbyte.ui.ArrayAdapterWithDefaultValue.java
org.gskbyte.ui.ListAdapter.java
org.gskbyte.ui.ColorDialog.ColorDialog.java
org.gskbyte.ui.ColorDialog.ColorPreference.java
org.gskbyte.ui.iconifiedMainMenuList.EntryView.java
org.gskbyte.ui.iconifiedMainMenuList.MainMenuAdapter.java
org.gskbyte.ui.iconifiedMainMenuList.MenuEntry.java
org.gskbyte.util.FrequentIntents.java
org.gskbyte.util.IOUtils.java
org.gskbyte.util.Logger.java
org.gskbyte.util.OpenFileHandlerFactory.java
org.gskbyte.util.OpenFileHandler.java
org.gskbyte.util.XmlUtils.java
org.gskbyte.view.AsyncImageView.java
org.gskbyte.view.AutoBackgroundButton.java
org.gskbyte.view.AutoBackgroundImageButton.java
org.gskbyte.view.AutoHeightImageView.java
org.gskbyte.view.ExpandedGridView.java
org.gskbyte.view.ExpandedListView.java
org.gskbyte.view.FontUtil.java
org.gskbyte.view.FontableButton.java
org.gskbyte.view.FontableCheckBox.java
org.gskbyte.view.FontableEditText.java
org.gskbyte.view.FontableTextView.java
org.gskbyte.view.FullWidthImageView.java
org.gskbyte.view.ProportionalHeightLayout.java
org.gskbyte.view.PullToRefreshListView.java
org.gskbyte.view.SquaredLayout.java
org.gskbyte.view.StepSeekBar.java
org.gskbyte.view.TextViewUtil.java
org.gskbyte.view.ViewUtils.java