From e892b12530335806f0b992011a61150a1975edad Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 27 Jun 2016 16:58:47 +0200 Subject: [PATCH] Display minimalist progress dialog when uploading logs --- src/org/linphone/AboutFragment.java | 76 +++++++++++++++++++++++++- src/org/linphone/LinphoneActivity.java | 16 ------ src/org/linphone/LinphoneManager.java | 4 -- 3 files changed, 74 insertions(+), 22 deletions(-) diff --git a/src/org/linphone/AboutFragment.java b/src/org/linphone/AboutFragment.java index 77a5f516f..86502d948 100644 --- a/src/org/linphone/AboutFragment.java +++ b/src/org/linphone/AboutFragment.java @@ -19,13 +19,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import org.linphone.core.LinphoneCore; +import org.linphone.core.LinphoneCore.LogCollectionUploadState; +import org.linphone.core.LinphoneCoreListenerBase; import org.linphone.mediastream.Log; +import android.app.Dialog; import android.app.Fragment; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.Intent; import android.content.pm.PackageManager.NameNotFoundException; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; +import android.view.WindowManager; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ImageView; @@ -38,6 +47,9 @@ public class AboutFragment extends Fragment implements OnClickListener { View sendLogButton = null; View resetLogButton = null; ImageView cancel; + LinphoneCoreListenerBase mListener; + private ProgressDialog progress; + private boolean uploadInProgress; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -62,22 +74,82 @@ public class AboutFragment extends Fragment implements OnClickListener { resetLogButton = view.findViewById(R.id.reset_log); resetLogButton.setOnClickListener(this); resetLogButton.setVisibility(org.linphone.LinphonePreferences.instance().isDebugEnabled() ? View.VISIBLE : View.GONE); + + mListener = new LinphoneCoreListenerBase() { + @Override + public void uploadProgressIndication(LinphoneCore lc, int offset, int total) { + } + + @Override + public void uploadStateChanged(LinphoneCore lc, LogCollectionUploadState state, String info) { + if (state == LogCollectionUploadState.LogCollectionUploadStateInProgress) { + displayUploadLogsInProgress(); + } else if (state == LogCollectionUploadState.LogCollectionUploadStateDelivered || state == LogCollectionUploadState.LogCollectionUploadStateNotDelivered) { + uploadInProgress = false; + if (progress != null) progress.dismiss(); + if (state == LogCollectionUploadState.LogCollectionUploadStateDelivered) { + sendLogs(LinphoneService.instance().getApplicationContext(), info); + } + } + } + }; return view; } + + private void displayUploadLogsInProgress() { + if (uploadInProgress) { + return; + } + uploadInProgress = true; + + progress = ProgressDialog.show(LinphoneActivity.instance(), null, null); + Drawable d = new ColorDrawable(getResources().getColor(R.color.colorE)); + d.setAlpha(200); + progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); + progress.getWindow().setBackgroundDrawable(d); + progress.setContentView(R.layout.progress_dialog); + progress.show(); + } + + private void sendLogs(Context context, String info){ + final String appName = context.getString(R.string.app_name); + + Intent i = new Intent(Intent.ACTION_SEND); + i.putExtra(Intent.EXTRA_EMAIL, new String[]{ context.getString(R.string.about_bugreport_email) }); + i.putExtra(Intent.EXTRA_SUBJECT, appName + " Logs"); + i.putExtra(Intent.EXTRA_TEXT, info); + i.setType("application/zip"); + + try { + startActivity(Intent.createChooser(i, "Send mail...")); + } catch (android.content.ActivityNotFoundException ex) { + Log.e(ex); + } + } @Override public void onPause() { + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.removeListener(mListener); + } + super.onPause(); } @Override public void onResume() { - super.onResume(); - + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.addListener(mListener); + } + if (org.linphone.LinphoneActivity.isInstanciated()) { LinphoneActivity.instance().selectMenu(FragmentsAvailable.ABOUT); } + + super.onResume(); } @Override diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 0fcfc05a8..d77460da7 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -970,22 +970,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta startActivityForResult(intent, CALL_ACTIVITY); } - public void sendLogs(Context context, String info){ - final String appName = context.getString(R.string.app_name); - - Intent i = new Intent(Intent.ACTION_SEND); - i.putExtra(Intent.EXTRA_EMAIL, new String[]{ context.getString(R.string.about_bugreport_email) }); - i.putExtra(Intent.EXTRA_SUBJECT, appName + " Logs"); - i.putExtra(Intent.EXTRA_TEXT, info); - i.setType("application/zip"); - - try { - startActivity(Intent.createChooser(i, "Send mail...")); - } catch (android.content.ActivityNotFoundException ex) { - Log.e(ex); - } - } - /** * Register a sensor to track phoneOrientation changes */ diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index f94fe313e..281426dc6 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -1467,10 +1467,6 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag @Override public void uploadStateChanged(LinphoneCore linphoneCore, LogCollectionUploadState state, String info) { Log.d("Log upload state: " + state.toString() + ", info = " + info); - - if (state == LogCollectionUploadState.LogCollectionUploadStateDelivered) { - LinphoneActivity.instance().sendLogs(LinphoneService.instance().getApplicationContext(),info); - } } @Override