Example usage for android.app ProgressDialog setProgress

List of usage examples for android.app ProgressDialog setProgress

Introduction

In this page you can find the example usage for android.app ProgressDialog setProgress.

Prototype

public void setProgress(int value) 

Source Link

Document

Sets the current progress.

Usage

From source file:nf.frex.android.FrexActivity.java

private void setWallpaper() {
    final WallpaperManager wallpaperManager = WallpaperManager.getInstance(FrexActivity.this);
    final int desiredWidth = wallpaperManager.getDesiredMinimumWidth();
    final int desiredHeight = wallpaperManager.getDesiredMinimumHeight();

    final Image image = view.getImage();
    final int imageWidth = image.getWidth();
    final int imageHeight = image.getHeight();

    final boolean useDesiredSize = desiredWidth > imageWidth || desiredHeight > imageHeight;

    DialogInterface.OnClickListener noListener = new DialogInterface.OnClickListener() {
        @Override//from  w w  w  . ja  v a2 s.co  m
        public void onClick(DialogInterface dialog, int which) {
            // ok
        }
    };

    if (useDesiredSize) {
        showYesNoDialog(this, R.string.set_wallpaper,
                getString(R.string.wallpaper_compute_msg, desiredWidth, desiredHeight),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        final Image wallpaperImage;
                        try {
                            wallpaperImage = new Image(desiredWidth, desiredHeight);
                        } catch (OutOfMemoryError e) {
                            alert(getString(R.string.out_of_memory));
                            return;
                        }

                        final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this);

                        Generator.ProgressListener progressListener = new Generator.ProgressListener() {
                            int numLines;

                            @Override
                            public void onStarted(int numTasks) {
                            }

                            @Override
                            public void onSomeLinesComputed(int taskId, int line1, int line2) {
                                numLines += 1 + line2 - line1;
                                progressDialog.setProgress(numLines);
                            }

                            @Override
                            public void onStopped(boolean cancelled) {
                                progressDialog.dismiss();
                                if (!cancelled) {
                                    setWallpaper(wallpaperManager, wallpaperImage);
                                }
                            }
                        };
                        final Generator wallpaperGenerator = new Generator(view.getGeneratorConfig(),
                                SettingsActivity.NUM_CORES, progressListener);

                        DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                if (progressDialog.isShowing()) {
                                    progressDialog.dismiss();
                                }
                                wallpaperGenerator.cancel();
                            }
                        };
                        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        progressDialog.setCancelable(true);
                        progressDialog.setMax(desiredHeight);
                        progressDialog.setOnCancelListener(cancelListener);
                        progressDialog.show();

                        Arrays.fill(wallpaperImage.getValues(), FractalView.MISSING_VALUE);
                        wallpaperGenerator.start(wallpaperImage, false);
                    }
                }, noListener, null);
    } else {
        showYesNoDialog(this, R.string.set_wallpaper, getString(R.string.wallpaper_replace_msg),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        setWallpaper(wallpaperManager, image);
                    }
                }, noListener, null);
    }
}

From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == FilePicker.PICK_FILE_REQUEST) {
        if (resultCode == RESULT_OK) {
            String filePath = data.getStringExtra(FilePicker.EXTRA_FILE_PATH);

            if (TextUtils.isEmpty(filePath)) {
                showToast("No file was choosen.");
                return;
            }//ww  w . j  ava  2s .c o  m

            File file = new File(filePath);

            final ProgressDialog uploadProgressDialog = new ProgressDialog(SkyDriveActivity.this);
            uploadProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            uploadProgressDialog.setMessage("Uploading...");
            uploadProgressDialog.setCancelable(true);
            uploadProgressDialog.show();

            final LiveOperation operation = mClient.uploadAsync(mCurrentFolderId, file.getName(), file,
                    new LiveUploadOperationListener() {
                        @Override
                        public void onUploadProgress(int totalBytes, int bytesRemaining,
                                LiveOperation operation) {
                            int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining);

                            uploadProgressDialog.setProgress(percentCompleted);
                        }

                        @Override
                        public void onUploadFailed(LiveOperationException exception, LiveOperation operation) {
                            uploadProgressDialog.dismiss();
                            showToast(exception.getMessage());
                        }

                        @Override
                        public void onUploadCompleted(LiveOperation operation) {
                            uploadProgressDialog.dismiss();

                            JSONObject result = operation.getResult();
                            if (result.has(JsonKeys.ERROR)) {
                                JSONObject error = result.optJSONObject(JsonKeys.ERROR);
                                String message = error.optString(JsonKeys.MESSAGE);
                                String code = error.optString(JsonKeys.CODE);
                                showToast(code + ": " + message);
                                return;
                            }

                            loadFolder(mCurrentFolderId);
                        }
                    });

            uploadProgressDialog.setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    operation.cancel();
                }
            });
        }
    }
}

From source file:nf.frex.android.FrexActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;/*from www  . j a va  2 s. c om*/
    }
    if (requestCode == R.id.manage_fractals && data.getAction().equals(Intent.ACTION_VIEW)) {
        final Uri imageUri = data.getData();
        if (imageUri != null) {
            File imageFile = new File(imageUri.getPath());
            String configName = FrexIO.getFilenameWithoutExt(imageFile);
            File paramFile = new File(imageFile.getParent(), configName + FrexIO.PARAM_FILE_EXT);
            try {
                FileInputStream fis = new FileInputStream(paramFile);
                try {
                    readFrexDoc(fis, configName);
                } finally {
                    fis.close();
                }
            } catch (IOException e) {
                Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()),
                        Toast.LENGTH_SHORT).show();
            }
        }
    } else if (requestCode == R.id.settings) {
        view.getGenerator().setNumTasks(SettingsActivity.getNumTasks(this));
    } else if (requestCode == SELECT_PICTURE_REQUEST_CODE) {
        final Uri imageUri = data.getData();
        final ColorQuantizer colorQuantizer = new ColorQuantizer();
        final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this);
        final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                colorQuantizer.cancel();
            }
        };
        final ColorQuantizer.ProgressListener progressListener = new ColorQuantizer.ProgressListener() {
            @Override
            public void progress(final String msg, final int iter, final int maxIter) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        progressDialog.setMessage(msg);
                        progressDialog.setProgress(iter);
                    }
                });
            }
        };

        progressDialog.setTitle(getString(R.string.get_pal_from_img_title));
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setCancelable(true);
        progressDialog.setOnCancelListener(cancelListener);
        progressDialog.setMax(colorQuantizer.getMaxIterCount());
        progressDialog.show();

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                Bitmap bitmap;
                try {
                    bitmap = FrexIO.readBitmap(getContentResolver(), imageUri, 256);
                } catch (IOException e) {
                    alert("I/O error: " + e.getLocalizedMessage());
                    return;
                }
                ColorScheme colorScheme = colorQuantizer.quantize(bitmap, progressListener);
                progressDialog.dismiss();
                if (colorScheme != null) {
                    Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: Got colorScheme");
                    String colorSchemeId = "$" + imageUri.toString();
                    colorSchemes.add(colorSchemeId, colorScheme);
                    view.setColorSchemeId(colorSchemeId);
                    view.setColorScheme(colorScheme);
                    view.recomputeColors();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: showDialog(R.id.colors)");
                            showDialog(R.id.colors);
                        }
                    });

                }
            }
        });
        thread.start();
    }
}

From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java

@Override
protected Dialog onCreateDialog(final int id, final Bundle bundle) {
    Dialog dialog = null;/*from  ww  w  .  java 2 s .c  om*/
    switch (id) {
    case DIALOG_DOWNLOAD_ID: {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Download").setMessage("This file will be downloaded to the sdcard.")
                .setPositiveButton("OK", new Dialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final ProgressDialog progressDialog = new ProgressDialog(SkyDriveActivity.this);
                        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        progressDialog.setMessage("Downloading...");
                        progressDialog.setCancelable(true);
                        progressDialog.show();

                        String fileId = bundle.getString(JsonKeys.ID);
                        String name = bundle.getString(JsonKeys.NAME);

                        File file = new File(Environment.getExternalStorageDirectory(), name);

                        final LiveDownloadOperation operation = mClient.downloadAsync(fileId + "/content", file,
                                new LiveDownloadOperationListener() {
                                    @Override
                                    public void onDownloadProgress(int totalBytes, int bytesRemaining,
                                            LiveDownloadOperation operation) {
                                        int percentCompleted = computePrecentCompleted(totalBytes,
                                                bytesRemaining);

                                        progressDialog.setProgress(percentCompleted);
                                    }

                                    @Override
                                    public void onDownloadFailed(LiveOperationException exception,
                                            LiveDownloadOperation operation) {
                                        progressDialog.dismiss();
                                        showToast(exception.getMessage());
                                    }

                                    @Override
                                    public void onDownloadCompleted(LiveDownloadOperation operation) {
                                        progressDialog.dismiss();
                                        showToast("File downloaded.");
                                    }
                                });

                        progressDialog.setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                operation.cancel();
                            }
                        });
                    }
                }).setNegativeButton("Cancel", new Dialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

        dialog = builder.create();
        break;
    }
    }

    if (dialog != null) {
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                removeDialog(id);
            }
        });
    }

    return dialog;
}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void saveWavPart2(final String finalval, final String needToRename) {
    Intent new_intent = new Intent();
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 15);
    new_intent.putExtra(getResources().getString(R.string.msrv_outfile), finalval);
    sendBroadcast(new_intent);
    final ProgressDialog prog;
    prog = new ProgressDialog(TimidityActivity.this);
    prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override//w  w w  .ja va 2  s  .c  om
        public void onClick(DialogInterface dialog, int which) {

            dialog.dismiss();
        }
    });
    prog.setTitle("Converting to WAV");
    prog.setMessage("Converting...");
    prog.setIndeterminate(false);
    prog.setCancelable(false);
    prog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    prog.show();
    new Thread(new Runnable() {
        @Override
        public void run() {
            while (!localfinished && prog.isShowing()) {
                prog.setMax(JNIHandler.maxTime);
                prog.setProgress(JNIHandler.currTime);
                try {

                    Thread.sleep(25);
                } catch (InterruptedException e) {
                }
            }
            if (!localfinished) {
                JNIHandler.stop();
                TimidityActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(TimidityActivity.this, "Conversion canceled", Toast.LENGTH_SHORT).show();
                        if (!Globals.keepWav) {
                            if (new File(finalval).exists())
                                new File(finalval).delete();
                        } else {
                            fileFrag.getDir(fileFrag.currPath);
                        }
                    }
                });

            } else {
                TimidityActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        String trueName = finalval;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null
                                && needToRename != null) {
                            if (Globals.renameDocumentFile(TimidityActivity.this, finalval, needToRename)) {
                                trueName = needToRename;
                            } else {
                                trueName = "Error";
                            }
                        }
                        Toast.makeText(TimidityActivity.this, "Wrote " + trueName, Toast.LENGTH_SHORT).show();
                        prog.dismiss();
                        fileFrag.getDir(fileFrag.currPath);
                    }
                });
            }
        }
    }).start();
}

From source file:com.dwdesign.tweetings.activity.ComposeActivity.java

private void UploadProgressMethod(final ProgressDialog dialog) {
    //This method is called directly by the timer
    //and runs in the same thread as the timer.

    //We call the method that will work with the UI
    //through the runOnUiThread method.
    this.runOnUiThread(new Runnable() {
        public void run() {
            // use data here
            if (upload != null && upload.getRequestLength() > 0) {
                float progress = (float) upload.getRequestStatus() / (float) upload.getRequestLength();
                float longPc = progress * 100;
                int percentage = Math.round(longPc);
                if (percentage >= 100) {
                    dialog.setProgress(100);
                    dialog.setIndeterminate(true);
                    dialog.setMessage(getString(R.string.uploading_media_wait));
                } else {
                    dialog.setProgress(percentage);
                }//  w  ww  .  j a va 2 s . c om
            }
        }
    });
}

From source file:de.da_sense.moses.client.AvailableFragment.java

/**
 * FIXME: The ProgressDialog doesn't show up. Handles installing APK from
 * the Server.//from  ww  w  .j  ava2s .  c o m
 * 
 * @param app
 *            the App to download and install
 */
protected void handleInstallApp(ExternalApplication app) {

    final ProgressDialog progressDialog = new ProgressDialog(WelcomeActivity.getInstance());

    Log.d(TAG, "progressDialog = " + progressDialog);

    final ApkDownloadManager downloader = new ApkDownloadManager(app,
            WelcomeActivity.getInstance().getApplicationContext(), // getActivity().getApplicationContext(),
            new ExecutableForObject() {
                @Override
                public void execute(final Object o) {
                    if (o instanceof Integer) {
                        WelcomeActivity.getInstance().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (totalSize == -1) {
                                    totalSize = (Integer) o / 1024;
                                    progressDialog.setMax(totalSize);
                                } else {
                                    progressDialog.incrementProgressBy(
                                            ((Integer) o / 1024) - progressDialog.getProgress());
                                }
                            }
                        });
                        /*
                         * They were : Runnable runnable = new Runnable() {
                         * Integer temporary = (Integer) o / 1024;
                         * 
                         * @Override public void run() { if (totalSize ==
                         * -1) { totalSize = temporary;
                         * progressDialog.setMax(totalSize); } else {
                         * progressDialog .incrementProgressBy( temporary -
                         * progressDialog.getProgress()); } } };
                         * getActivity().runOnUiThread(runnable);
                         */
                    }
                }
            });

    progressDialog.setTitle(getString(R.string.downloadingApp));
    progressDialog.setMessage(getString(R.string.pleaseWait));
    progressDialog.setMax(0);
    progressDialog.setProgress(0);
    progressDialog.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            downloader.cancel();
        }
    });

    progressDialog.setCancelable(true);
    progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (progressDialog.isShowing())
                progressDialog.cancel();
        }
    });
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    Observer observer = new Observer() {
        @Override
        public void update(Observable observable, Object data) {
            if (downloader.getState() == ApkDownloadManager.State.ERROR) {
                // error downloading
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                showMessageBoxErrorDownloading(downloader);
            } else if (downloader.getState() == ApkDownloadManager.State.ERROR_NO_CONNECTION) {
                // error with connection
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                showMessageBoxErrorNoConnection(downloader);
            } else if (downloader.getState() == ApkDownloadManager.State.FINISHED) {
                // success
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                installDownloadedApk(downloader.getDownloadedApk(), downloader.getExternalApplicationResult());
            }
        }
    };
    downloader.addObserver(observer);
    totalSize = -1;
    // progressDialog.show(); FIXME: commented out in case it throws an
    // error
    downloader.start();
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    final BaseApplication application = (BaseApplication) getActivity().getApplication();
    final IOneDriveClient oneDriveClient = application.getOneDriveClient();

    if (requestCode == REQUEST_CODE_SIMPLE_UPLOAD && data != null && data.getData() != null
            && data.getData().getScheme().equalsIgnoreCase(SCHEME_CONTENT)) {

        final ProgressDialog dialog = new ProgressDialog(getActivity());
        dialog.setTitle(R.string.upload_in_progress_title);
        dialog.setMessage(getString(R.string.upload_in_progress_message));
        dialog.setIndeterminate(false);//  ww  w . ja  va2 s .  com
        dialog.setCancelable(false);
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgressNumberFormat(getString(R.string.upload_in_progress_number_format));
        dialog.show();
        final AsyncTask<Void, Void, Void> uploadFile = new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(final Void... params) {
                try {
                    final ContentResolver contentResolver = getActivity().getContentResolver();
                    final ContentProviderClient contentProvider = contentResolver
                            .acquireContentProviderClient(data.getData());
                    final byte[] fileInMemory = FileContent.getFileBytes(contentProvider, data.getData());
                    contentProvider.release();

                    // Fix up the file name (needed for camera roll photos, etc)
                    final String filename = FileContent.getValidFileName(contentResolver, data.getData());
                    final Option option = new QueryOption("@name.conflictBehavior", "fail");
                    oneDriveClient.getDrive().getItems(mItemId).getChildren().byId(filename).getContent()
                            .buildRequest(Collections.singletonList(option))
                            .put(fileInMemory, new IProgressCallback<Item>() {
                                @Override
                                public void success(final Item item) {
                                    dialog.dismiss();
                                    Toast.makeText(getActivity(),
                                            application.getString(R.string.upload_complete, item.name),
                                            Toast.LENGTH_LONG).show();
                                    refresh();
                                }

                                @Override
                                public void failure(final ClientException error) {
                                    dialog.dismiss();
                                    if (error.isError(OneDriveErrorCodes.NameAlreadyExists)) {
                                        Toast.makeText(getActivity(), R.string.upload_failed_name_conflict,
                                                Toast.LENGTH_LONG).show();
                                    } else {
                                        Toast.makeText(getActivity(),
                                                application.getString(R.string.upload_failed, filename),
                                                Toast.LENGTH_LONG).show();
                                    }
                                }

                                @Override
                                public void progress(final long current, final long max) {
                                    dialog.setProgress((int) current);
                                    dialog.setMax((int) max);
                                }
                            });
                } catch (final Exception e) {
                    Log.e(getClass().getSimpleName(), e.getMessage());
                    Log.e(getClass().getSimpleName(), e.toString());
                }
                return null;
            }
        };
        uploadFile.execute();
    }
}

From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java

public void performSearch(String query) {

    LOG.debug("Starting search for: " + query);

    final ProgressDialog searchProgress = new ProgressDialog(context);
    searchProgress.setOwnerActivity(getActivity());
    searchProgress.setCancelable(true);/*from   w w w  .  j  a va 2s  . c o m*/
    searchProgress.setMax(100);
    searchProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    final int[] counter = { 0 }; //Yes, this is essentially a pointer to an int :P

    final SearchTextTask task = new SearchTextTask(bookView.getBook());

    task.setOnPreExecute(() -> {

        searchProgress.setMessage(getString(R.string.search_wait));
        searchProgress.show();

        // Hide on-screen keyboard if it is showing
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

    });

    task.setOnProgressUpdate((values) -> {

        if (isAdded()) {

            LOG.debug("Found match at index=" + values[0].getIndex() + ", offset=" + values[0].getStart()
                    + " with context " + values[0].getDisplay());
            SearchResult res = values[0];

            if (res.getDisplay() != null) {
                counter[0] = counter[0] + 1;
                String update = String.format(getString(R.string.search_hits), counter[0]);
                searchProgress.setMessage(update);
            }

            searchProgress.setProgress(bookView.getPercentageFor(res.getIndex(), res.getStart()));
        }
    });

    task.setOnCancelled((result) -> {
        if (isAdded()) {
            Toast.makeText(context, R.string.search_cancelled, Toast.LENGTH_LONG).show();
        }
    });

    task.setOnPostExecute((result) -> {
        searchProgress.dismiss();

        if (!task.isCancelled() && isAdded()) {

            List<SearchResult> resultList = result.getOrElse(new ArrayList<>());

            if (resultList.size() > 0) {
                searchResults = resultList;
                showSearchResultDialog(resultList);
            } else {
                Toast.makeText(context, R.string.search_no_matches, Toast.LENGTH_LONG).show();
            }
        }
    });

    searchProgress.setOnCancelListener(dialog -> task.cancel(true));
    executeTask(task, query);
}

From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java

@Override
public void performSearch(String query) {

    LOG.debug("Starting search for: " + query);

    final ProgressDialog searchProgress = new ProgressDialog(context);
    searchProgress.setOwnerActivity(getActivity());
    searchProgress.setCancelable(true);/*from  ww w .  j  av a  2  s .  c  o m*/
    searchProgress.setMax(100);
    searchProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    final SearchTextTask task = new SearchTextTask(bookView.getBook()) {

        int i = 0;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            searchProgress.setMessage(getString(R.string.search_wait));
            searchProgress.show();

            // Hide on-screen keyboard if it is showing
            InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Activity.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

        }

        @Override
        protected void onProgressUpdate(SearchResult... values) {

            if (!isAdded()) {
                return;
            }

            super.onProgressUpdate(values);

            LOG.debug("Found match at index=" + values[0].getIndex() + ", offset=" + values[0].getStart()
                    + " with context " + values[0].getDisplay());
            SearchResult res = values[0];

            if (res.getDisplay() != null) {
                i++;
                String update = String.format(getString(R.string.search_hits), i);
                searchProgress.setMessage(update);
            }

            searchProgress.setProgress(bookView.getPercentageFor(res.getIndex(), res.getStart()));
        }

        @Override
        protected void onCancelled() {
            if (isAdded()) {
                Toast.makeText(context, R.string.search_cancelled, Toast.LENGTH_LONG).show();
            }
        }

        protected void onPostExecute(java.util.List<SearchResult> result) {

            searchProgress.dismiss();

            if (!isCancelled() && isAdded()) {
                if (result.size() > 0) {
                    searchResults = result;
                    showSearchResultDialog(result);
                } else {
                    Toast.makeText(context, R.string.search_no_matches, Toast.LENGTH_LONG).show();
                }
            }
        };
    };

    searchProgress.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            task.cancel(true);
        }
    });

    task.execute(query);
}