Example usage for android.widget ProgressBar ProgressBar

List of usage examples for android.widget ProgressBar ProgressBar

Introduction

In this page you can find the example usage for android.widget ProgressBar ProgressBar.

Prototype

public ProgressBar(Context context, AttributeSet attrs, int defStyleAttr) 

Source Link

Usage

From source file:org.inversebit.proto01.main.DiagnoserFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final Button but = new Button(getActivity().getBaseContext());
    but.setText("Start");
    but.setOnClickListener(new OnClickListener() {
        @Override/*from  ww  w  .j av  a  2s .  co m*/
        public void onClick(View v) {
            but.setVisibility(View.GONE);
            pb = new ProgressBar(getActivity().getBaseContext(), null,
                    android.R.attr.progressBarStyleHorizontal);
            ((LinearLayout) getActivity().findViewById(R.id.progressLayout)).addView(pb, 300, 10);
            getDataAndDiagnose();
        }
    });
    ((LinearLayout) getActivity().findViewById(R.id.progressLayout)).addView(but);
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.ProgressFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);/*  w  w  w. ja  v  a2s.co m*/

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    FrameLayout cframe = new FrameLayout(context);
    cframe.setId(INTERNAL_CONTENT_CONTAINER_ID);

    TextView tv = new TextView(context);
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    cframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    View contentView = onCreateContentView(inflater, cframe, savedInstanceState);
    cframe.addView(contentView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(cframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

From source file:org.ligi.android.dubwise_uavtalk.dashboard.DownloadDashboardImagesStatusAlertDialog.java

/**
 * //  w  w w  . ja  v a2s  .c om
 * @param activity
 * @param autoclose - if the alert should close when connection is established
 * 
 */
public static void show(Context activity, boolean autoclose, Intent after_connection_intent) {

    LinearLayout lin = new LinearLayout(activity);
    lin.setOrientation(LinearLayout.VERTICAL);

    ScrollView sv = new ScrollView(activity);
    TextView details_text_view = new TextView(activity);

    LinearLayout lin_in_scrollview = new LinearLayout(activity);
    lin_in_scrollview.setOrientation(LinearLayout.VERTICAL);
    sv.addView(lin_in_scrollview);
    lin_in_scrollview.addView(details_text_view);

    details_text_view.setText("no text");

    ProgressBar progress = new ProgressBar(activity, null, android.R.attr.progressBarStyleHorizontal);
    progress.setMax(img_lst.length);

    lin.addView(progress);
    lin.addView(sv);

    new AlertDialog.Builder(activity).setTitle("Download Status").setView(lin)
            .setPositiveButton("OK", new DialogDiscardingOnClickListener()).show();

    class AlertDialogUpdater implements Runnable {

        private Handler h = new Handler();
        private TextView myTextView;
        private ProgressBar myProgress;

        public AlertDialogUpdater(TextView ab, ProgressBar progress) {
            myTextView = ab;
            myProgress = progress;

        }

        public void run() {

            for (int i = 0; i < img_lst.length; i++) {
                class MsgUpdater implements Runnable {

                    private int i;

                    public MsgUpdater(int i) {
                        this.i = i;
                    }

                    public void run() {
                        myProgress.setProgress(i + 1);
                        if (i != img_lst.length - 1)
                            myTextView.setText("Downloading " + img_lst[i] + ".png");
                        else
                            myTextView.setText("Ready - please restart DUBwise to apply changes!");
                    }
                }
                h.post(new MsgUpdater(i));

                try {
                    URLConnection ucon = new URL(url_lst[i]).openConnection();
                    BufferedInputStream bis = new BufferedInputStream(ucon.getInputStream());

                    ByteArrayBuffer baf = new ByteArrayBuffer(50);
                    int current = 0;
                    while ((current = bis.read()) != -1)
                        baf.append((byte) current);

                    File path = new File(
                            Environment.getExternalStorageDirectory() + "/dubwise/images/dashboard");
                    path.mkdirs();

                    FileOutputStream fos = new FileOutputStream(
                            new File(path.getAbsolutePath() + "/" + img_lst[i] + ".png"));
                    fos.write(baf.toByteArray());
                    fos.close();
                } catch (Exception e) {
                }

                try {
                    Thread.sleep(199);
                } catch (InterruptedException e) {
                }

            }
        }
    }

    new Thread(new AlertDialogUpdater(details_text_view, progress)).start();
}

From source file:com.android.calculator2.Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();
    FrameLayout root = new FrameLayout(context);

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);/*from ww  w  .j a va2 s. c o m*/

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_VIEW_CONTAINER_ID);

    View cv = inflateView(savedInstanceState);
    cv.setId(android.R.id.content);
    lframe.addView(cv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

From source file:touchgallery.UrlTouchImageView.java

@SuppressWarnings("deprecation")
protected void init() {
    mImageView = new TouchImageView(mContext);
    LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    mImageView.setLayoutParams(params);//from w  w  w. j a  va  2s. co m
    this.addView(mImageView);
    mImageView.setVisibility(GONE);

    mProgressBar = new ProgressBar(mContext, null, android.R.attr.progressBarStyleHorizontal);
    params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_VERTICAL);
    params.setMargins(30, 0, 30, 0);
    mProgressBar.setLayoutParams(params);
    mProgressBar.setIndeterminate(false);
    mProgressBar.setMax(100);
    this.addView(mProgressBar);
}

From source file:org.wingy.jp8chan.ui.activity.ImageViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP);

    super.onCreate(savedInstanceState);

    if (postAdapter == null) {
        Logger.e(TAG, "Posts in ImageViewActivity was null");
        finish();/*from  ww  w  .  j  av  a 2  s . c  om*/
        return;
    }

    threadManager = threadManagerStatic;

    ThemeHelper.setTheme(this);

    progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
    progressBar.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT));
    progressBar.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_no_bg));
    progressBar.setIndeterminate(false);
    progressBar.setMax(1000000);

    final FrameLayout decorView = (FrameLayout) getWindow().getDecorView();
    decorView.addView(progressBar);

    progressBar.post(new Runnable() {
        @Override
        public void run() {
            View contentView = decorView.findViewById(android.R.id.content);
            progressBar.setY(contentView.getY() - progressBar.getHeight() / 2);
        }
    });

    // Get the posts with images
    ArrayList<Post> imagePosts = new ArrayList<>();
    for (Post post : postAdapter.getList()) {
        if (post.hasImage) {
            imagePosts.add(post);
        }
    }

    // Setup our pages and adapter
    setContentView(R.layout.image_pager);
    viewPager = (ViewPager) findViewById(R.id.image_pager);
    adapter = new ImageViewAdapter(getFragmentManager(), this);
    adapter.setList(imagePosts);
    viewPager.setAdapter(adapter);
    viewPager.setOnPageChangeListener(this);

    // Select the right image
    for (int i = 0; i < imagePosts.size(); i++) {
        if (imagePosts.get(i).no == selectedId) {
            viewPager.setCurrentItem(i);
            onPageSelected(i);
            break;
        }
    }
}

From source file:com.wms.opensource.images3android.activity.ImageListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (layout != null) {
        ViewGroup parent = (ViewGroup) layout.getParent();
        parent.removeView(layout);//from   w w  w. j a  va  2  s  .  c  o m
        return layout;
    }

    if (listView == null) {
        layout = new RelativeLayout(getActivity());
        listView = new ListView(getActivity());
        layout.addView(listView);

        progressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);

        // Center a view in relative layout
        RelativeLayout.LayoutParams progressBarParams = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        progressBarParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        progressBar.setLayoutParams(progressBarParams);
        progressBar.setVisibility(View.INVISIBLE);
        layout.addView(progressBar);

        // Before reloading videos, display videos if they have been saved before
        String imagesFilePath = "";
        imagesFilePath = StorageUtil.getTempDirectory(this.getActivity()) + "/"
                + PersistFileNameUtil.getImagesPersistFileName(getString(R.string.imagePlantId), page);

        boolean imagesFileExists = FileUtil.fileExist(imagesFilePath);
        if (imagesFileExists) {
            loadCachedImagesTask = new LoadCachedImagesTask(getActivity(), loadImagesHandler, progressBar,
                    getActivity().getString(R.string.ImageS3ServiceURL),
                    getActivity().getString(R.string.imagePlantId), page);
            loadCachedImagesTask.execute();
        } else {
            NetworkStatus networkStatus = NetworkUtil.getNetworkStatus(getActivity());
            if (networkStatus.equals(NetworkStatus.WIFI_CONNECTED)
                    || networkStatus.equals(NetworkStatus.MOBILE_CONNECTED)) {
                String pageToken = page == 1 ? "" : ImageListFragmentActivity.pageTokens.get(page - 1);
                loadImagesTask = new LoadImagesTask(getActivity(), loadImagesHandler,
                        getActivity().getString(R.string.ImageS3ServiceURL),
                        getActivity().getString(R.string.imagePlantId), pageToken, page);
                loadImagesTask.execute();
            } else {
                Toast.makeText(getActivity(), getString(R.string.noNetworkAvailable), Toast.LENGTH_LONG).show();
            }
        }
    }
    return layout;
}

From source file:org.quantumbadger.redreader.activities.AlbumListingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    PrefsUtility.applyTheme(this);

    OptionsMenuUtility.fixActionBar(AlbumListingActivity.this, getString(R.string.imgur_album));

    if (getActionBar() != null) {
        getActionBar().setHomeButtonEnabled(true);
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }//w  ww. ja  v  a 2  s . c  o  m

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences) == PrefsUtility.AppearanceTheme.NIGHT;

    if (solidblack)
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    final Intent intent = getIntent();

    mUrl = intent.getDataString();

    if (mUrl == null) {
        finish();
        return;
    }

    final Matcher matchImgur = LinkHandler.imgurAlbumPattern.matcher(mUrl);
    final String albumId;

    if (matchImgur.find()) {
        albumId = matchImgur.group(2);
    } else {
        Log.e("AlbumListingActivity", "URL match failed");
        revertToWeb();
        return;
    }

    Log.i("AlbumListingActivity", "Loading URL " + mUrl + ", album id " + albumId);

    final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
    progressBar.setIndeterminate(true);

    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(progressBar);

    ImgurAPI.getAlbumInfo(this, albumId, Constants.Priority.IMAGE_VIEW, 0, new GetAlbumInfoListener() {

        @Override
        public void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status,
                final String readableMessage) {
            Log.e("AlbumListingActivity", "getAlbumInfo call failed: " + type);

            if (status != null)
                Log.e("AlbumListingActivity", "status was: " + status.toString());
            if (t != null)
                Log.e("AlbumListingActivity", "exception was: ", t);

            // It might be a single image, not an album

            if (status == null) {
                revertToWeb();
                return;
            }

            ImgurAPI.getImageInfo(AlbumListingActivity.this, albumId, Constants.Priority.IMAGE_VIEW, 0,
                    new GetImageInfoListener() {
                        @Override
                        public void onFailure(final RequestFailureType type, final Throwable t,
                                final StatusLine status, final String readableMessage) {
                            Log.e("AlbumListingActivity", "Image info request also failed: " + type);
                            revertToWeb();
                        }

                        @Override
                        public void onSuccess(final ImageInfo info) {
                            Log.i("AlbumListingActivity", "Link was actually an image.");
                            LinkHandler.onLinkClicked(AlbumListingActivity.this, info.urlOriginal);
                            finish();
                        }

                        @Override
                        public void onNotAnImage() {
                            Log.i("AlbumListingActivity", "Not an image either");
                            revertToWeb();
                        }
                    });
        }

        @Override
        public void onSuccess(final ImgurAPI.AlbumInfo info) {
            Log.i("AlbumListingActivity", "Got album, " + info.images.size() + " image(s)");

            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                @Override
                public void run() {

                    if (info.title != null && !info.title.trim().isEmpty()) {
                        OptionsMenuUtility.fixActionBar(AlbumListingActivity.this,
                                getString(R.string.imgur_album) + ": " + info.title);
                    }

                    layout.removeAllViews();

                    final ListView listView = new ListView(AlbumListingActivity.this);
                    listView.setAdapter(new AlbumAdapter(info));
                    layout.addView(listView);

                    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(final AdapterView<?> parent, final View view,
                                final int position, final long id) {

                            LinkHandler.onLinkClicked(AlbumListingActivity.this,
                                    info.images.get(position).urlOriginal, false, null, info, position);
                        }
                    });
                }
            });
        }
    });

    setContentView(layout);
}

From source file:org.bohrmeista.chan.ui.activity.ImageViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP);

    super.onCreate(savedInstanceState);

    if (postAdapter == null) {
        Logger.e(TAG, "Posts in ImageViewActivity was null");
        finish();//from  w ww.j ava2  s . co  m
        return;
    }

    threadManager = threadManagerStatic;

    ThemeHelper.setTheme(this);

    progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
    progressBar.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT));
    progressBar.setProgressDrawable(getResources().getDrawable(R.drawable.progressbar_no_bg));
    progressBar.setIndeterminate(false);
    progressBar.setMax(1000000);

    final FrameLayout decorView = (FrameLayout) getWindow().getDecorView();
    decorView.addView(progressBar);

    progressBar.post(new Runnable() {
        @Override
        public void run() {
            View contentView = decorView.findViewById(android.R.id.content);
            progressBar.setY(contentView.getY() - progressBar.getHeight() / 2);
        }
    });

    // Get the posts with images
    ArrayList<Post> imagePosts = new ArrayList<>();
    for (Post post : postAdapter.getList()) {
        if (post.images.size() > 0) {
            imagePosts.add(post);
        }
    }

    // Setup our pages and adapter
    setContentView(R.layout.image_pager);
    viewPager = (ViewPager) findViewById(R.id.image_pager);
    imageAdapter = new ImageViewAdapter(getFragmentManager(), this);
    imageAdapter.setList(imagePosts);
    viewPager.setAdapter(imageAdapter);
    viewPager.setOnPageChangeListener(this);

    // Select the right image
    int imageIndex = 0;
    for (Post post : imagePosts) {
        if (post.no == selectedId) {
            viewPager.setCurrentItem(imageIndex);
            onPageSelected(imageIndex);

            thumbList = (TwoWayView) findViewById(R.id.thumbList);
            thumbListAdapter = new ThumbListAdapter(this, post.images, imageIndex);
            thumbList.setAdapter(thumbListAdapter);
            thumbList.setVisibility(post.images.size() <= 1 ? View.GONE : View.VISIBLE);
            return;
        }
        imageIndex += post.images.size();
    }
}

From source file:com.example.testapplication.DialogLocation.java

@SuppressLint("InlinedApi")
@Override//from  w  w w.j  a  v  a 2s  . co m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mProgressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);
    mProgressBarInv = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);
    mProgressBarInv.setVisibility(ProgressBar.GONE);

    mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    mCriteria = new Criteria();
    int criteria = (mGpsPref) ? Criteria.POWER_HIGH : Criteria.POWER_MEDIUM;
    mCriteria.setPowerRequirement(criteria);

    mProvider = mLocationManager.getBestProvider(mCriteria, true);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    int telephonyInfo = tm.getNetworkType();

    boolean networkAvailable = true;

    if ((telephonyInfo == TelephonyManager.NETWORK_TYPE_UNKNOWN && !networkInfo.isConnected())
            || !mLocationManager.isProviderEnabled("network")) {
        networkAvailable = false;
    }

    int locationMode = -1;
    int locationType = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {
            locationMode = Settings.Secure.getInt(getActivity().getContentResolver(),
                    Settings.Secure.LOCATION_MODE);
        } catch (SettingNotFoundException e) {
            e.printStackTrace();
        }

        if (locationMode == Settings.Secure.LOCATION_MODE_OFF
                || (!networkAvailable && (mProvider.matches("network"))))
            locationType = NO_LOCATION_SERVICES;
        else if (mGpsPref && (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY
                || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY))
            locationType = (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY || !networkAvailable)
                    ? USING_ONLY_GPS_LOCATION
                    : USING_GPS_LOCATION_NETWORK_AVAILABLE;
        else if (mProvider.matches("network") && (locationMode == Settings.Secure.LOCATION_MODE_BATTERY_SAVING
                || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY))
            locationType = USING_NETWORK_LOCATION;

    } else {
        if (mProvider.matches("passive") || !networkAvailable
                && (mProvider.matches("network") || (!mGpsPref && mProvider.matches("gps"))))
            locationType = NO_LOCATION_SERVICES;
        else if (mProvider.matches("gps") && mGpsPref)
            locationType = ((mProvider.matches("gps")) || !networkAvailable) ? USING_ONLY_GPS_LOCATION
                    : USING_GPS_LOCATION_NETWORK_AVAILABLE;
        else if (mProvider.matches("network"))
            locationType = USING_NETWORK_LOCATION;
    }

    switch (locationType) {
    case NO_LOCATION_SERVICES:
        builder.setTitle(DIALOG_LOCATION_NO_LOCATION_SERVICES_TITLE);
        builder.setMessage(DIALOG_LOCATION_NO_LOCATION_SERVICES_MESSAGE);
        builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton);
        mAbortRequest = true;
        break;
    case USING_ONLY_GPS_LOCATION:
        builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE);
        builder.setMessage(DIALOG_LOCATION_ONLY_GPS_MESSAGE);
        builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton);
        builder.setView(mProgressBar);
        break;
    case USING_GPS_LOCATION_NETWORK_AVAILABLE:
        builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE);
        builder.setPositiveButton(DIALOG_LOCATION_USE_NETWORK, null);
        builder.setView(mProgressBar);
        break;
    case USING_NETWORK_LOCATION:
        builder.setView(mProgressBar);
        builder.setTitle(DIALOG_LOCATION_UPDATING_NETWORK_TITLE);
        break;
    }

    builder.setNegativeButton(DIALOG_LOCATION_CANCEL, cancelListener);
    builder.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                mCallback.onLocationFound(null, mFragmentId);
                mLocationManager.removeUpdates(DialogLocation.this);
                Toast.makeText(getActivity(), "Location request cancelled", Toast.LENGTH_SHORT).show();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });

    mRealDialog = builder.create();
    mRealDialog.setOnShowListener(usingNetwork);
    mRealDialog.setCanceledOnTouchOutside(false);
    return mRealDialog;
}