/** * Attaches the activity to the ASync task. * * @param activity The activity to which results will be sent on completion of this task. */ public void attachToActivity(PuzzleFragmentActivity activity) { if (activity.equals(this.mActivity) && mProgressDialog != null && mProgressDialog.isShowing()) { // The activity is already attached to this task. return; } if (DEBUG_GRID_GAME_FILE_CONVERTER) { Log.i(TAG, "Attach to activity"); } // Remember the activity that started this task. this.mActivity = activity; int maxProgressCounter = 0; // Determine how much (old) game files and preview files have to be // deleted. mGameFilesToBeDeleted = getGameFilesToBeDeleted(); maxProgressCounter += (mGameFilesToBeDeleted == null ? 0 : mGameFilesToBeDeleted.length); // Determine how much usage log files have to be deleted. mUsageLogFilesToBeDeleted = getUsageLogFilesToBeDeleted(); maxProgressCounter += (mUsageLogFilesToBeDeleted == null ? 0 : mUsageLogFilesToBeDeleted.length); // Determine how many solving attempts in the database have to be // converted. if ((solvingAttemptIds = new SolvingAttemptDatabaseAdapter().getAllToBeConverted()) != null) { maxProgressCounter += solvingAttemptIds.size(); } if (maxProgressCounter > 0) { // Build the dialog mProgressDialog = new ProgressDialog(mActivity); mProgressDialog.setTitle(R.string.dialog_converting_saved_games_title); mProgressDialog.setMessage( mActivity .getResources() .getString( (mCurrentVersion < 369 ? R.string.dialog_converting_cleanup_v1_message : R.string.dialog_converting_saved_games_message))); mProgressDialog.setIcon(android.R.drawable.ic_dialog_info); mProgressDialog.setIndeterminate(false); mProgressDialog.setCancelable(false); mProgressDialog.setMax(maxProgressCounter); // Set style of dialog. mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // Show the dialog mProgressDialog.show(); } // Initialize conversion results. mGridDefinitions = new ArrayList<String>(); }
@Override protected void onPostExecute(Void result) { // Phase 1 of upgrade has been completed. Start next phase. if (mActivity != null) { mActivity.upgradePhase2_UpdatePreferences(mCurrentVersion, mNewVersion); } detachFromActivity(); super.onPostExecute(result); }