From cb0c5ea8058e941d934516848ba04cee6181e046 Mon Sep 17 00:00:00 2001 From: Ludovic Roland Date: Thu, 26 Oct 2017 11:55:04 +0200 Subject: [PATCH] RED-149 #time 30m Remove the deprecated SendLoadingIntent annotation + Remove the unused SendLogsTask class + Remove the sendRecipient getLogReportRecipient method from the SmartApplication class + Mark some classes (ForBusinessObject components) as deprecated + clean-up the code --- .../smartnsoft/droid4me/app/AppInternals.java | 6 +- .../smartnsoft/droid4me/app/AppPublics.java | 13 -- .../droid4me/app/ExceptionHandlers.java | 60 +----- .../app/ForBusinessObjectActivity.java | 1 + .../droid4me/app/SmartApplication.java | 14 +- .../framework/BusinessObjectLifeCycle.java | 1 + .../ForBusinessObjectImplementation.java | 1 + .../droid4me/util/SendLogsTask.java | 190 ------------------ .../droid4me/widget/SmartViewPager.java | 2 +- .../droid4sample/Droid4SampleApplication.java | 8 - 10 files changed, 8 insertions(+), 288 deletions(-) delete mode 100644 library/src/main/java/com/smartnsoft/droid4me/util/SendLogsTask.java diff --git a/library/src/main/java/com/smartnsoft/droid4me/app/AppInternals.java b/library/src/main/java/com/smartnsoft/droid4me/app/AppInternals.java index 7c6d7730..4c74a276 100644 --- a/library/src/main/java/com/smartnsoft/droid4me/app/AppInternals.java +++ b/library/src/main/java/com/smartnsoft/droid4me/app/AppInternals.java @@ -501,10 +501,9 @@ void unregisterBroadcastListeners() * Should be invoked during the {@link Droid4mizer#onBeforeRefreshBusinessObjectsAndDisplay()} method: is responsible for triggering a loading * broadcast intent if required, in order to indicate that the activity is loading. */ - @SuppressWarnings("deprecation") void onStartLoading() { - if (component.getClass().getAnnotation(AppPublics.SendLoadingIntentAnnotation.class) != null || component instanceof AppPublics.SendLoadingIntent) + if (component.getClass().getAnnotation(AppPublics.SendLoadingIntentAnnotation.class) != null) { // We indicate the activity which is loading, in order to filter the loading events AppPublics.LoadingBroadcastListener.broadcastLoading(activity, System.identityHashCode(activity), System.identityHashCode(component), true); @@ -515,10 +514,9 @@ void onStartLoading() * Should be invoked just after the {@link SmartActivity#onSynchronizeDisplayObjects()} method: is responsible for triggering a loading broadcast * intent if required, in order to indicate that the activity has stopped loading. */ - @SuppressWarnings("deprecation") void onStopLoading() { - if (component.getClass().getAnnotation(AppPublics.SendLoadingIntentAnnotation.class) != null || component instanceof AppPublics.SendLoadingIntent) + if (component.getClass().getAnnotation(AppPublics.SendLoadingIntentAnnotation.class) != null) { // We indicate the activity which is loading, in order to filter the loading events AppPublics.LoadingBroadcastListener.broadcastLoading(activity, System.identityHashCode(activity), System.identityHashCode(component), false); diff --git a/library/src/main/java/com/smartnsoft/droid4me/app/AppPublics.java b/library/src/main/java/com/smartnsoft/droid4me/app/AppPublics.java index f7a4d43b..5207d64c 100644 --- a/library/src/main/java/com/smartnsoft/droid4me/app/AppPublics.java +++ b/library/src/main/java/com/smartnsoft/droid4me/app/AppPublics.java @@ -266,21 +266,8 @@ public interface BroadcastListenersProvider /** * When an {@link Activity} implements that interface, it will send broadcast intents while loading and once the loading is over. * - * @see AppPublics.SendLoadingIntentAnnotation * @see AppPublics.BroadcastListener * @see AppPublics.BroadcastListenerProvider - * @since 2010.02.04 - * @deprecated use {@link AppPublics.SendLoadingIntentAnnotation} instead - */ - public interface SendLoadingIntent - { - - } - - /** - * Same concept as {@link AppPublics.SendLoadingIntent}, but through an annotation. - * - * @see AppPublics.SendLoadingIntent * @since 2013.04.12 */ @Retention(RetentionPolicy.RUNTIME) diff --git a/library/src/main/java/com/smartnsoft/droid4me/app/ExceptionHandlers.java b/library/src/main/java/com/smartnsoft/droid4me/app/ExceptionHandlers.java index 7ddeb40c..5f151b91 100644 --- a/library/src/main/java/com/smartnsoft/droid4me/app/ExceptionHandlers.java +++ b/library/src/main/java/com/smartnsoft/droid4me/app/ExceptionHandlers.java @@ -38,7 +38,6 @@ import com.smartnsoft.droid4me.app.SmartApplication.I18N; import com.smartnsoft.droid4me.log.Logger; import com.smartnsoft.droid4me.log.LoggerFactory; -import com.smartnsoft.droid4me.util.SendLogsTask; /** * A wrapper class which holds {@link ActivityController.ExceptionHandler} implementations. @@ -534,66 +533,9 @@ public static class DefaultExceptionHandler extends ExceptionHandlers.AbstractExceptionHandler { - private final String logReportRecipients; - - public DefaultExceptionHandler(I18N i18n, IssueAnalyzer issueAnalyzer, String logReportRecipients) + public DefaultExceptionHandler(I18N i18n, IssueAnalyzer issueAnalyzer) { super(i18n, issueAnalyzer); - this.logReportRecipients = logReportRecipients; - } - - @Override - protected boolean onBusinessObjectAvailableExceptionFallback(Activity activity, Object component, - BusinessObjectUnavailableException exception) - { - if (logReportRecipients == null) - { - return super.onBusinessObjectAvailableExceptionFallback(activity, component, exception); - } - else - { - return sendLogs(activity); - } - } - - @Override - protected boolean onActivityExceptionFallback(Activity activity, Object component, Throwable throwable) - { - if (logReportRecipients == null) - { - return super.onActivityExceptionFallback(activity, component, throwable); - } - else - { - return sendLogs(activity); - } - } - - protected final boolean sendLogs(final Activity activity) - { - // If the logger recipient is not set, no e-mail submission is proposed - showDialog(activity, i18n.dialogBoxErrorTitle, i18n.otherProblemHint, i18n.reportButtonLabel, new OnClickListener() - { - public void onClick(DialogInterface dialogInterface, int which) - { - new SendLogsTask(activity, i18n.retrievingLogProgressMessage, "[" + i18n.applicationName + "] Error log - v%1s", logReportRecipients).execute(null, null); - } - }, activity.getString(android.R.string.cancel), new OnClickListener() - { - public void onClick(DialogInterface dialogInterface, int which) - { - // We leave the activity, because we cannot go any further - activity.finish(); - } - }, new DialogInterface.OnCancelListener() - { - public void onCancel(DialogInterface dialog) - { - // We leave the activity, because we cannot go any further - activity.finish(); - } - }); - return true; } } diff --git a/library/src/main/java/com/smartnsoft/droid4me/app/ForBusinessObjectActivity.java b/library/src/main/java/com/smartnsoft/droid4me/app/ForBusinessObjectActivity.java index 04305147..919efc15 100644 --- a/library/src/main/java/com/smartnsoft/droid4me/app/ForBusinessObjectActivity.java +++ b/library/src/main/java/com/smartnsoft/droid4me/app/ForBusinessObjectActivity.java @@ -32,6 +32,7 @@ * @author Édouard Mercier * @since 2008.04.13 */ +@Deprecated public abstract class ForBusinessObjectActivity extends SmartActivity implements BusinessObjectLifeCycle diff --git a/library/src/main/java/com/smartnsoft/droid4me/app/SmartApplication.java b/library/src/main/java/com/smartnsoft/droid4me/app/SmartApplication.java index ca3991bd..640ec693 100644 --- a/library/src/main/java/com/smartnsoft/droid4me/app/SmartApplication.java +++ b/library/src/main/java/com/smartnsoft/droid4me/app/SmartApplication.java @@ -43,7 +43,6 @@ import com.smartnsoft.droid4me.BuildConfig; import com.smartnsoft.droid4me.app.ActivityController.ExceptionHandler; import com.smartnsoft.droid4me.app.ExceptionHandlers.AbstractExceptionHandler; -import com.smartnsoft.droid4me.app.ExceptionHandlers.DefaultExceptionHandler; import com.smartnsoft.droid4me.log.Logger; import com.smartnsoft.droid4me.log.LoggerFactory; @@ -311,17 +310,6 @@ public void onLowMemory() } } - /** - * If the application uses an {@link DefaultExceptionHandler} as an {@link ActivityController.ExceptionHandler}, when a managed - * exception is detected, and is not handled, a dialog box is submitted to the end-user, in order to propose to send the bug cause by inspecting the - * Android {@code logcat}. In that case, do not forget to declare the {@code android.permission.READ_LOGS} permission in the - * {@code AndroidManifest.xml}. - * - * @return the e-mail address that will be used when submitting an error log message ; if it returns {@code null}, the application will not propose - * to send the bug cause - */ - protected abstract String getLogReportRecipient(); - /** *

* Caution: this method will return {@code null} as long as the parent {@link Application#onCreate()} has not been invoked. @@ -423,7 +411,7 @@ protected ActivityController.Interceptor getInterceptor() */ protected ActivityController.ExceptionHandler getExceptionHandler() { - return new ExceptionHandlers.DefaultExceptionHandler(getI18N(), null, getLogReportRecipient()); + return new ExceptionHandlers.DefaultExceptionHandler(getI18N(), null); } /** diff --git a/library/src/main/java/com/smartnsoft/droid4me/framework/BusinessObjectLifeCycle.java b/library/src/main/java/com/smartnsoft/droid4me/framework/BusinessObjectLifeCycle.java index 05f3365a..75018607 100644 --- a/library/src/main/java/com/smartnsoft/droid4me/framework/BusinessObjectLifeCycle.java +++ b/library/src/main/java/com/smartnsoft/droid4me/framework/BusinessObjectLifeCycle.java @@ -30,6 +30,7 @@ * @author Édouard Mercier * @since 2008.06.11 */ +@Deprecated public interface BusinessObjectLifeCycle { diff --git a/library/src/main/java/com/smartnsoft/droid4me/framework/ForBusinessObjectImplementation.java b/library/src/main/java/com/smartnsoft/droid4me/framework/ForBusinessObjectImplementation.java index b77c6048..d16c2bc1 100644 --- a/library/src/main/java/com/smartnsoft/droid4me/framework/ForBusinessObjectImplementation.java +++ b/library/src/main/java/com/smartnsoft/droid4me/framework/ForBusinessObjectImplementation.java @@ -30,6 +30,7 @@ * @author Édouard Mercier * @since 2008.08.11 */ +@Deprecated public abstract class ForBusinessObjectImplementation implements BusinessObjectLifeCycle { diff --git a/library/src/main/java/com/smartnsoft/droid4me/util/SendLogsTask.java b/library/src/main/java/com/smartnsoft/droid4me/util/SendLogsTask.java deleted file mode 100644 index 00718ce0..00000000 --- a/library/src/main/java/com/smartnsoft/droid4me/util/SendLogsTask.java +++ /dev/null @@ -1,190 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2017 Smart&Soft -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -package com.smartnsoft.droid4me.util; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - -import android.app.Activity; -import android.app.ProgressDialog; -import android.content.ActivityNotFoundException; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.os.AsyncTask; -import android.os.Build; - -import com.smartnsoft.droid4me.log.Logger; -import com.smartnsoft.droid4me.log.LoggerFactory; - -/** - * An asynchronous task which enables to send the logs of the application, along with the device details. - *

- *

- * Caution: the android.permission.READ_LOGS Android permission must be set in the AnroidManifest.xml file, when using that - * task. - *

- * - * @author Édouard Mercier - * @since 2010.10.21 - */ -public final class SendLogsTask - extends AsyncTask -{ - - private final static Logger log = LoggerFactory.getInstance(SendLogsTask.class); - - public static int MAX_LOG_LENGTH_IN_BYTES = 50 * 1024; - - private final Activity activity; - - private final String progressMessage; - - private final String emailSubjectFormat; - - private final String emailRecipient; - - private final String lineSeparator = System.getProperty("line.separator"); - - private ProgressDialog progressDialog; - - public SendLogsTask(Activity activity, String progressMessage, String emailSubjectFormat, String emailRecipient) - { - this.activity = activity; - this.progressMessage = progressMessage; - this.emailSubjectFormat = emailSubjectFormat; - this.emailRecipient = emailRecipient; - } - - @Override - protected void onPreExecute() - { - progressDialog = new ProgressDialog(activity); - progressDialog.setIndeterminate(true); - progressDialog.setMessage(progressMessage); - progressDialog.setCancelable(false); - progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() - { - public void onCancel(DialogInterface dialog) - { - activity.finish(); - } - }); - progressDialog.show(); - } - - @Override - protected StringBuilder doInBackground(Void... params) - { - final StringBuilder sb = new StringBuilder(); - try - { - final Process process = Runtime.getRuntime().exec(new String[] { "logcat", "-d", "-v", "time" }); - final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); - String line; - while ((line = bufferedReader.readLine()) != null) - { - sb.append(line); - sb.append(lineSeparator); - } - } - catch (IOException exception) - { - if (log.isErrorEnabled()) - { - log.error("Cannot extract the device logcat!", exception); - } - } - return sb; - } - - @Override - protected void onPostExecute(StringBuilder logcatSb) - { - if (logcatSb != null) - { - // We truncate the log if necessary - final int keepOffset = Math.max(logcatSb.length() - SendLogsTask.MAX_LOG_LENGTH_IN_BYTES, 0); - if (keepOffset > 0) - { - logcatSb.delete(0, keepOffset); - } - - String version; - try - { - final PackageInfo packagInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0); - version = packagInfo.versionName; - } - catch (PackageManager.NameNotFoundException exception) - { - if (log.isErrorEnabled()) - { - log.error("Cannot extract the current application packages information", exception); - } - version = "?"; - } - final Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("message/rfc822"); - intent.putExtra(Intent.EXTRA_EMAIL, new String[] { emailRecipient }); - intent.putExtra(Intent.EXTRA_SUBJECT, String.format(emailSubjectFormat, version)); - final StringBuffer sb = new StringBuffer(); - sb.append("Device model: ").append(Build.MODEL).append(lineSeparator); - sb.append("Firmware version: ").append(Build.VERSION.RELEASE).append(lineSeparator); - sb.append("Build number: ").append(Build.DISPLAY).append(lineSeparator); - sb.append("----------").append(lineSeparator).append(logcatSb); - intent.putExtra(Intent.EXTRA_TEXT, sb.toString()); - // We start the activity that will eventually send the log - try - { - activity.startActivity(intent); - } - catch (ActivityNotFoundException exception) - { - if (log.isWarnEnabled()) - { - // TODO: issue a toast! - log.warn("Cannot send the report, because no application is able to handle it!", exception); - } - } - dismissProgressDialog(); - activity.finish(); - } - else - { - dismissProgressDialog(); - } - } - - private void dismissProgressDialog() - { - if (progressDialog != null && progressDialog.isShowing()) - { - progressDialog.dismiss(); - progressDialog = null; - } - } - -} diff --git a/library/src/main/java/com/smartnsoft/droid4me/widget/SmartViewPager.java b/library/src/main/java/com/smartnsoft/droid4me/widget/SmartViewPager.java index c76708cd..7480bbf5 100644 --- a/library/src/main/java/com/smartnsoft/droid4me/widget/SmartViewPager.java +++ b/library/src/main/java/com/smartnsoft/droid4me/widget/SmartViewPager.java @@ -61,8 +61,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final View child = getChildAt(index); child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - int measuredHeight = child.getMeasuredHeight(); + final int measuredHeight = child.getMeasuredHeight(); if (measuredHeight > height) { height = measuredHeight; diff --git a/sample/src/main/java/com/smartnsoft/droid4sample/Droid4SampleApplication.java b/sample/src/main/java/com/smartnsoft/droid4sample/Droid4SampleApplication.java index 62613642..2c3a00f1 100644 --- a/sample/src/main/java/com/smartnsoft/droid4sample/Droid4SampleApplication.java +++ b/sample/src/main/java/com/smartnsoft/droid4sample/Droid4SampleApplication.java @@ -109,12 +109,6 @@ protected SmartApplication.I18N getI18N() return new SmartApplication.I18N(getText(R.string.problem), getText(R.string.unavailableItem), getText(R.string.unavailableService), getText(R.string.connectivityProblem), getText(R.string.connectivityProblemRetry), getText(R.string.unhandledProblem), getString(R.string.applicationName), getText(R.string.dialogButton_unhandledProblem), getString(R.string.progressDialogMessage_unhandledProblem)); } - @Override - protected String getLogReportRecipient() - { - return Constants.REPORT_LOG_RECIPIENT_EMAIL; - } - @Override protected ActivityController.Redirector getActivityRedirector() { @@ -145,8 +139,6 @@ protected ActivityController.ExceptionHandler getExceptionHandler() return super.getExceptionHandler(); } - - @Override protected ActivityController.Interceptor getInterceptor() {