diff options
author | Richard MacGregor <rmacgregor@cyngn.com> | 2015-08-11 11:52:49 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2016-11-02 21:30:39 -0700 |
commit | 8f1a21d4b8111c8f726a8c70ba496441a487507e (patch) | |
tree | 6eda76e11de2b8ef5f34a330bd2e42634a384934 /src/com | |
parent | ee7e64a2f7343536bc7b09ed0c869900db47758a (diff) | |
download | android_packages_apps_CMFileManager-8f1a21d4b8111c8f726a8c70ba496441a487507e.tar.gz android_packages_apps_CMFileManager-8f1a21d4b8111c8f726a8c70ba496441a487507e.tar.bz2 android_packages_apps_CMFileManager-8f1a21d4b8111c8f726a8c70ba496441a487507e.zip |
Update open file progress dialog
Now uses icon and color of file being opened
Background is correct color.
Change-Id: I0eda7bf82f81a057220822f92396c81d6cacafaf
Diffstat (limited to 'src/com')
8 files changed, 332 insertions, 26 deletions
diff --git a/src/com/cyanogenmod/filemanager/ui/dialogs/CustomProgressDialog.java b/src/com/cyanogenmod/filemanager/ui/dialogs/CustomProgressDialog.java new file mode 100644 index 00000000..0cd1bebf --- /dev/null +++ b/src/com/cyanogenmod/filemanager/ui/dialogs/CustomProgressDialog.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cyanogenmod.filemanager.ui.dialogs; + +import android.text.Spanned; +/** + * A class that wraps a dialog for showing a progress with text message (non graphical). + */ +public interface CustomProgressDialog { + + /** + * A class for listen program cancellation events. + */ + interface OnCancelListener { + /** + * Fires when a cancel were requested. + * + * @return boolean If the cancel can be done + */ + boolean onCancel(); + } + + /** + * Method that sets the cancel listener. + * + * @param onCancelListener The cancel listener + */ + public void setOnCancelListener(OnCancelListener onCancelListener); + + /** + * Method that sets the progress of the action. + * + * @param progress The progress of progress of the action + */ + public void setProgress(Spanned progress); + + /** + * Method that shows the dialog. + */ + public void show(); + + /** + * Method that dismiss the dialog. + */ + public void dismiss(); +} diff --git a/src/com/cyanogenmod/filemanager/ui/dialogs/MessageProgressDialog.java b/src/com/cyanogenmod/filemanager/ui/dialogs/MessageProgressDialog.java index 4fb0fba7..fdbd4b86 100644 --- a/src/com/cyanogenmod/filemanager/ui/dialogs/MessageProgressDialog.java +++ b/src/com/cyanogenmod/filemanager/ui/dialogs/MessageProgressDialog.java @@ -33,20 +33,8 @@ import com.cyanogenmod.filemanager.util.DialogHelper; /** * A class that wraps a dialog for showing a progress with text message (non graphical). */ -public class MessageProgressDialog implements DialogInterface.OnClickListener { - - /** - * A class for listen program cancellation events. - */ - public interface OnCancelListener { - /** - * Fires when a cancel were requested. - * - * @return boolean If the cancel can be done - */ - boolean onCancel(); - } - +public class MessageProgressDialog implements CustomProgressDialog, + DialogInterface.OnClickListener { /** * @hide */ @@ -151,6 +139,7 @@ public class MessageProgressDialog implements DialogInterface.OnClickListener { * * @param onCancelListener The cancel listener */ + @Override public void setOnCancelListener(OnCancelListener onCancelListener) { this.mOnCancelListener = onCancelListener; } @@ -160,6 +149,7 @@ public class MessageProgressDialog implements DialogInterface.OnClickListener { * * @param progress The progress of progress of the action */ + @Override public void setProgress(Spanned progress) { this.mProgress.setText(progress); } @@ -167,6 +157,7 @@ public class MessageProgressDialog implements DialogInterface.OnClickListener { /** * Method that shows the dialog. */ + @Override public void show() { DialogHelper.delegateDialogShow(this.mContext, this.mDialog); } @@ -174,6 +165,7 @@ public class MessageProgressDialog implements DialogInterface.OnClickListener { /** * Method that dismiss the dialog. */ + @Override public void dismiss() { this.mDialog.dismiss(); } diff --git a/src/com/cyanogenmod/filemanager/ui/dialogs/OpenFileProgressDialog.java b/src/com/cyanogenmod/filemanager/ui/dialogs/OpenFileProgressDialog.java new file mode 100644 index 00000000..09d94d38 --- /dev/null +++ b/src/com/cyanogenmod/filemanager/ui/dialogs/OpenFileProgressDialog.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.cyanogenmod.filemanager.ui.dialogs; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.PorterDuff.Mode; +import android.text.Spanned; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.TextView; +import com.cyanogenmod.filemanager.R; +import com.cyanogenmod.filemanager.util.DialogHelper; + +public class OpenFileProgressDialog implements CustomProgressDialog { + /** + * @hide + */ + final Context mContext; + /** + * @hide + */ + final AlertDialog mDialog; + /** + * @hide + */ + OnCancelListener mOnCancelListener; + + /** + * Constructor of <code>OpenFileProgressDialog</code>. + * + * + * @param context The current context + * @param iconId The icon dialog resource identifier + * @param message The dialog message to display + * @param color The primary color + * @param cancellable If the dialog is cancellable + */ + public OpenFileProgressDialog(Context context, int iconId, String message, int color, + boolean cancellable) { + //Save the context + this.mContext = context; + + LayoutInflater li = + (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + final View layout = li.inflate(R.layout.open_file_progress_dialog, null); + + // set colors and icons specific to this dialog + final ProgressBar progress = + (ProgressBar)layout.findViewById(R.id.message_progress_dialog_waiting); + progress.setIndeterminateTintList(ColorStateList.valueOf(color)); + + final ImageView icon = (ImageView)layout.findViewById(R.id.message_progress_dialog_icon); + icon.setImageResource(iconId); + icon.setColorFilter(color, Mode.SRC_IN); + + final TextView messageView = + (TextView)layout.findViewById(R.id.open_file_progress_dialog_filename); + if (!TextUtils.isEmpty(message)) { + messageView.setText(message); + } + + this.mDialog = DialogHelper.createDialog(context, layout); + this.mDialog.setCancelable(cancellable); + this.mDialog.setCanceledOnTouchOutside(cancellable); + } + + /** + * Method that sets the cancel listener. + * + * @param onCancelListener The cancel listener + */ + @Override + public void setOnCancelListener(OnCancelListener onCancelListener) { + this.mOnCancelListener = onCancelListener; + } + + /** + * Method that sets the progress of the action. + * + * @param progress The progress of progress of the action + */ + @Override + public void setProgress(Spanned progress) { + // Not implemented + } + + /** + * Method that shows the dialog. + */ + @Override + public void show() { + DialogHelper.delegateDialogShow(this.mContext, this.mDialog); + } + + /** + * Method that dismiss the dialog. + */ + @Override + public void dismiss() { + this.mDialog.dismiss(); + } +} diff --git a/src/com/cyanogenmod/filemanager/ui/policy/ActionsPolicy.java b/src/com/cyanogenmod/filemanager/ui/policy/ActionsPolicy.java index 01cb837a..703d2565 100644 --- a/src/com/cyanogenmod/filemanager/ui/policy/ActionsPolicy.java +++ b/src/com/cyanogenmod/filemanager/ui/policy/ActionsPolicy.java @@ -19,13 +19,13 @@ package com.cyanogenmod.filemanager.ui.policy; import android.content.Context; import android.os.AsyncTask; import android.text.Spanned; -import android.view.View; import android.widget.Toast; import com.cyanogenmod.filemanager.R; +import com.cyanogenmod.filemanager.ui.dialogs.CustomProgressDialog; import com.cyanogenmod.filemanager.ui.dialogs.MessageProgressDialog; +import com.cyanogenmod.filemanager.ui.dialogs.OpenFileProgressDialog; import com.cyanogenmod.filemanager.util.DialogHelper; -import com.cyanogenmod.filemanager.util.ExceptionUtil; /** @@ -38,6 +38,10 @@ public abstract class ActionsPolicy { * a */ protected interface BackgroundCallable { + enum DialogType { + MESSAGE_PROGRESS_DIALOG, + OPEN_FILE_PROGRESS_DIALOG, + } /** * Method that returns the resource identifier of the icon of the dialog * @@ -46,6 +50,13 @@ public abstract class ActionsPolicy { int getDialogIcon(); /** + * Method that returns the primary color to be used within the dialog + * + * @return int The color to be used for the dialog + */ + int getDialogColor(); + + /** * Method that returns the resource identifier of the title of the dialog * * @return int The resource identifier of the title of the dialog @@ -53,6 +64,20 @@ public abstract class ActionsPolicy { int getDialogTitle(); /** + * Method that returns the string message for use by the dialog + * + * @return string The string message for use by the dialog + */ + String getDialogMessage(); + + /** + * Method that returns the string message for use by the dialog + * + * @return DialogType The type of dialog to use. + */ + DialogType getDialogType(); + + /** * Method that returns if the dialog is cancellable * * @return boolean If the dialog is cancellable @@ -102,7 +127,7 @@ public abstract class ActionsPolicy { private final Context mCtx; private final BackgroundCallable mCallable; - private MessageProgressDialog mDialog; + private CustomProgressDialog mDialog; /** * Constructor of <code>BackgroundAsyncTask</code> @@ -120,12 +145,26 @@ public abstract class ActionsPolicy { protected void onPreExecute() { // Create the waiting dialog while doing some stuff on background final BackgroundAsyncTask task = this; - this.mDialog = new MessageProgressDialog( - this.mCtx, - this.mCallable.getDialogIcon(), - this.mCallable.getDialogTitle(), - R.string.waiting_dialog_msg, - this.mCallable.isDialogCancellable()); + switch (this.mCallable.getDialogType()) { + case MESSAGE_PROGRESS_DIALOG: + this.mDialog = new MessageProgressDialog( + this.mCtx, + this.mCallable.getDialogIcon(), + this.mCallable.getDialogTitle(), + R.string.waiting_dialog_msg, + this.mCallable.isDialogCancellable()); + Spanned progress = this.mCallable.requestProgress(); + this.mDialog.setProgress(progress); + break; + case OPEN_FILE_PROGRESS_DIALOG: + this.mDialog = new OpenFileProgressDialog( + this.mCtx, + this.mCallable.getDialogIcon(), + this.mCallable.getDialogMessage(), + this.mCallable.getDialogColor(), + this.mCallable.isDialogCancellable()); + break; + } this.mDialog.setOnCancelListener(new MessageProgressDialog.OnCancelListener() { @Override public boolean onCancel() { @@ -134,8 +173,6 @@ public abstract class ActionsPolicy { return true; } }); - Spanned progress = this.mCallable.requestProgress(); - this.mDialog.setProgress(progress); this.mDialog.show(); } diff --git a/src/com/cyanogenmod/filemanager/ui/policy/CompressActionPolicy.java b/src/com/cyanogenmod/filemanager/ui/policy/CompressActionPolicy.java index d7b47452..051d526d 100644 --- a/src/com/cyanogenmod/filemanager/ui/policy/CompressActionPolicy.java +++ b/src/com/cyanogenmod/filemanager/ui/policy/CompressActionPolicy.java @@ -212,10 +212,27 @@ public final class CompressActionPolicy extends ActionsPolicy { public int getDialogTitle() { return R.string.waiting_dialog_compressing_title; } + + @Override + public String getDialogMessage() { + return null; + } + + @Override + public DialogType getDialogType() { + return DialogType.MESSAGE_PROGRESS_DIALOG; + } + @Override public int getDialogIcon() { return 0; } + + @Override + public int getDialogColor() { + return 0; + } + @Override public boolean isDialogCancellable() { return true; @@ -524,10 +541,27 @@ public final class CompressActionPolicy extends ActionsPolicy { public int getDialogTitle() { return R.string.waiting_dialog_extracting_title; } + + @Override + public String getDialogMessage() { + return null; + } + + @Override + public DialogType getDialogType() { + return DialogType.MESSAGE_PROGRESS_DIALOG; + } + @Override public int getDialogIcon() { return 0; } + + @Override + public int getDialogColor() { + return 0; + } + @Override public boolean isDialogCancellable() { return true; diff --git a/src/com/cyanogenmod/filemanager/ui/policy/CopyMoveActionPolicy.java b/src/com/cyanogenmod/filemanager/ui/policy/CopyMoveActionPolicy.java index c6e8e0e0..ab73b03f 100755 --- a/src/com/cyanogenmod/filemanager/ui/policy/CopyMoveActionPolicy.java +++ b/src/com/cyanogenmod/filemanager/ui/policy/CopyMoveActionPolicy.java @@ -329,10 +329,27 @@ public final class CopyMoveActionPolicy extends ActionsPolicy { R.string.waiting_dialog_moving_title : R.string.waiting_dialog_copying_title; } + + @Override + public String getDialogMessage() { + return null; + } + + @Override + public DialogType getDialogType() { + return DialogType.MESSAGE_PROGRESS_DIALOG; + } + @Override public int getDialogIcon() { return 0; } + + @Override + public int getDialogColor() { + return 0; + } + @Override public boolean isDialogCancellable() { return !(mSrcConsole instanceof SecureConsole) @@ -552,6 +569,11 @@ public final class CopyMoveActionPolicy extends ActionsPolicy { } @Override + public int getDialogColor() { + return 0; + } + + @Override public int getDialogTitle() { return operation.equals(COPY_MOVE_OPERATION.MOVE) || operation.equals(COPY_MOVE_OPERATION.RENAME) ? @@ -560,6 +582,16 @@ public final class CopyMoveActionPolicy extends ActionsPolicy { } @Override + public String getDialogMessage() { + return null; + } + + @Override + public DialogType getDialogType() { + return DialogType.MESSAGE_PROGRESS_DIALOG; + } + + @Override public boolean isDialogCancellable() { return false; } diff --git a/src/com/cyanogenmod/filemanager/ui/policy/DeleteActionPolicy.java b/src/com/cyanogenmod/filemanager/ui/policy/DeleteActionPolicy.java index 9250eabf..b869d751 100644 --- a/src/com/cyanogenmod/filemanager/ui/policy/DeleteActionPolicy.java +++ b/src/com/cyanogenmod/filemanager/ui/policy/DeleteActionPolicy.java @@ -185,10 +185,27 @@ public final class DeleteActionPolicy extends ActionsPolicy { public int getDialogTitle() { return R.string.waiting_dialog_deleting_title; } + + @Override + public String getDialogMessage() { + return null; + } + + @Override + public DialogType getDialogType() { + return DialogType.MESSAGE_PROGRESS_DIALOG; + } + @Override public int getDialogIcon() { return 0; } + + @Override + public int getDialogColor() { + return 0; + } + @Override public boolean isDialogCancellable() { return false; diff --git a/src/com/cyanogenmod/filemanager/util/DialogHelper.java b/src/com/cyanogenmod/filemanager/util/DialogHelper.java index cd5fc650..469a07f3 100644 --- a/src/com/cyanogenmod/filemanager/util/DialogHelper.java +++ b/src/com/cyanogenmod/filemanager/util/DialogHelper.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.text.InputFilter; +import android.text.TextUtils; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; @@ -392,6 +393,17 @@ public final class DialogHelper { * Method that creates a new {@link AlertDialog}. * * @param context The current context + * @param content The content layout + * @return AlertDialog The alert dialog reference + */ + public static AlertDialog createDialog(Context context, View content) { + return createDialog(context, 0, null, content); + } + + /** + * Method that creates a new {@link AlertDialog}. + * + * @param context The current context * @param icon The icon resource * @param title The resource identifier of the title of the alert dialog * @param content The content layout @@ -413,7 +425,9 @@ public final class DialogHelper { public static AlertDialog createDialog(Context context, int icon, String title, View content) { //Create the alert dialog final AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setCustomTitle(createTitle(context, icon, title, false)); + if (!TextUtils.isEmpty(title)) { + builder.setCustomTitle(createTitle(context, icon, title, false)); + } builder.setView(content); return builder.create(); } |