From f26e36e752baade03e4fb61bdf60b95c9b293ead Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Wed, 15 Jun 2016 11:35:38 -0400 Subject: [PATCH 1/2] add adapter class for DebugModule to make implementations without runtime features cleaner --- .../debugdrawer/base/DebugModuleAdapter.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 debugdrawer-base/src/main/java/io/palaima/debugdrawer/base/DebugModuleAdapter.java diff --git a/debugdrawer-base/src/main/java/io/palaima/debugdrawer/base/DebugModuleAdapter.java b/debugdrawer-base/src/main/java/io/palaima/debugdrawer/base/DebugModuleAdapter.java new file mode 100644 index 0000000..866206e --- /dev/null +++ b/debugdrawer-base/src/main/java/io/palaima/debugdrawer/base/DebugModuleAdapter.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2015 Mantas Palaima + * Copyright (C) 2016 Oleg Godovykh + * + * 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 io.palaima.debugdrawer.base; + +public abstract class DebugModuleAdapter implements DebugModule { + + @Override + public void onOpened() { + // do nothing + } + + @Override + public void onClosed() { + // do nothing + } + + @Override + public void onResume() { + // do nothing + } + + @Override + public void onPause() { + // do nothing + } + + @Override + public void onStart() { + // do nothing + } + + @Override + public void onStop() { + // do nothing + } +} From bf0f74bf28e75bb56b2fac6b8b9220b26541e608 Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Wed, 15 Jun 2016 11:50:09 -0400 Subject: [PATCH 2/2] convert modules with lot of empty overrides to adapter usage --- .../debugdrawer/commons/BuildModule.java | 31 ++-------------- .../debugdrawer/commons/DeviceModule.java | 35 ++----------------- .../debugdrawer/commons/NetworkModule.java | 25 ++----------- .../debugdrawer/commons/SettingsModule.java | 35 ++----------------- .../io/palaima/debugdrawer/fps/FpsModule.java | 24 ++----------- .../debugdrawer/glide/GlideModule.java | 20 ++--------- .../debugdrawer/okhttp/OkHttpModule.java | 29 ++------------- .../debugdrawer/okhttp3/OkHttp3Module.java | 29 ++------------- .../debugdrawer/picasso/PicassoModule.java | 28 ++------------- .../debugdrawer/scalpel/ScalpelModule.java | 34 ++---------------- .../debugdrawer/timber/TimberModule.java | 34 ++---------------- 11 files changed, 26 insertions(+), 298 deletions(-) diff --git a/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/BuildModule.java b/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/BuildModule.java index 769f07d..477e4c7 100644 --- a/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/BuildModule.java +++ b/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/BuildModule.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2015 Mantas Palaima + * Copyright (C) 2016 Oleg Godovykh * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,10 +26,9 @@ import android.view.ViewGroup; import android.widget.TextView; -import io.palaima.debugdrawer.base.DebugModule; - -public class BuildModule implements DebugModule { +import io.palaima.debugdrawer.base.DebugModuleAdapter; +public class BuildModule extends DebugModuleAdapter { private final Context context; @@ -60,21 +60,6 @@ public void onOpened() { refresh(); } - @Override - public void onClosed() { - - } - - @Override - public void onResume() { - - } - - @Override - public void onPause() { - - } - private void refresh() { try { final PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); @@ -83,14 +68,4 @@ private void refresh() { packageLabel.setText(info.packageName); } catch (PackageManager.NameNotFoundException e) {} } - - @Override - public void onStart() { - - } - - @Override - public void onStop() { - - } } diff --git a/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/DeviceModule.java b/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/DeviceModule.java index 5ac5681..346b053 100644 --- a/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/DeviceModule.java +++ b/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/DeviceModule.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2015 Mantas Palaima + * Copyright (C) 2016 Oleg Godovykh * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +26,9 @@ import android.view.ViewGroup; import android.widget.TextView; -import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; -public class DeviceModule implements DebugModule { +public class DeviceModule extends DebugModuleAdapter { private String deviceMake; private String deviceModel; @@ -101,34 +102,4 @@ public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup pa return view; } - - @Override - public void onOpened() { - - } - - @Override - public void onClosed() { - - } - - @Override - public void onResume() { - - } - - @Override - public void onPause() { - - } - - @Override - public void onStart() { - - } - - @Override - public void onStop() { - - } } diff --git a/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/NetworkModule.java b/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/NetworkModule.java index 0f8ac02..3c5ecc0 100644 --- a/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/NetworkModule.java +++ b/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/NetworkModule.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2015 Mantas Palaima + * Copyright (C) 2016 Oleg Godovykh * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +27,9 @@ import android.widget.CompoundButton; import android.widget.Switch; -import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; -public class NetworkModule implements DebugModule { +public class NetworkModule extends DebugModuleAdapter { private final Context context; @@ -85,26 +86,6 @@ public void onCheckedChanged(CompoundButton button, boolean isChecked) { return view; } - @Override - public void onOpened() { - - } - - @Override - public void onClosed() { - - } - - @Override - public void onResume() { - - } - - @Override - public void onPause() { - - } - @Override public void onStop() { networkController.setOnNetworkChangedListener(null); diff --git a/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/SettingsModule.java b/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/SettingsModule.java index 74e0b82..940a1de 100644 --- a/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/SettingsModule.java +++ b/debugdrawer-commons/src/main/java/io/palaima/debugdrawer/commons/SettingsModule.java @@ -1,6 +1,7 @@ /* * Copyright (C) 2014 LemonLabs * Copyright (C) 2015 Mantas Palaima + * Copyright (C) 2016 Oleg Godovykh * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +30,9 @@ import android.widget.ImageView; import android.widget.Toast; -import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; -public class SettingsModule implements DebugModule, View.OnClickListener { +public class SettingsModule extends DebugModuleAdapter implements View.OnClickListener { private final Context context; @@ -86,36 +87,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup pa return view; } - @Override - public void onOpened() { - - } - - @Override - public void onClosed() { - - } - - @Override - public void onResume() { - - } - - @Override - public void onPause() { - - } - - @Override - public void onStart() { - - } - - @Override - public void onStop() { - - } - @Override public void onClick(View v) { if (v == developer || v == developerTitle) { diff --git a/debugdrawer-fps/src/main/java/io/palaima/debugdrawer/fps/FpsModule.java b/debugdrawer-fps/src/main/java/io/palaima/debugdrawer/fps/FpsModule.java index 14ea4b6..3d57ad3 100644 --- a/debugdrawer-fps/src/main/java/io/palaima/debugdrawer/fps/FpsModule.java +++ b/debugdrawer-fps/src/main/java/io/palaima/debugdrawer/fps/FpsModule.java @@ -7,10 +7,10 @@ import android.widget.CompoundButton; import android.widget.Switch; -import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; import jp.wasabeef.takt.Takt; -public class FpsModule implements DebugModule { +public class FpsModule extends DebugModuleAdapter { private static final boolean HAS_TAKT; @@ -59,16 +59,6 @@ public void onCheckedChanged(CompoundButton button, boolean isChecked) { return view; } - @Override - public void onOpened() { - - } - - @Override - public void onClosed() { - - } - @Override public void onResume() { if (isChecked) { @@ -82,14 +72,4 @@ public void onPause() { program.stop(); } } - - @Override - public void onStart() { - - } - - @Override - public void onStop() { - - } } diff --git a/debugdrawer-glide/src/main/java/io/palaima/debugdrawer/glide/GlideModule.java b/debugdrawer-glide/src/main/java/io/palaima/debugdrawer/glide/GlideModule.java index dd05e34..8d11b96 100644 --- a/debugdrawer-glide/src/main/java/io/palaima/debugdrawer/glide/GlideModule.java +++ b/debugdrawer-glide/src/main/java/io/palaima/debugdrawer/glide/GlideModule.java @@ -13,9 +13,9 @@ import java.lang.reflect.Field; -import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; -public class GlideModule implements DebugModule { +public class GlideModule extends DebugModuleAdapter { private static final boolean HAS_GLIDE; @@ -92,26 +92,10 @@ public GlideModule(@NonNull Glide glide) { refresh(); } - @Override public void onClosed() { - - } - @Override public void onResume() { refresh(); } - @Override public void onPause() { - - } - - @Override public void onStart() { - - } - - @Override public void onStop() { - - } - private void refresh() { BitmapPool pool = glide.getBitmapPool(); diff --git a/debugdrawer-okhttp/src/main/java/io/palaima/debugdrawer/okhttp/OkHttpModule.java b/debugdrawer-okhttp/src/main/java/io/palaima/debugdrawer/okhttp/OkHttpModule.java index b63fb28..8cad48f 100644 --- a/debugdrawer-okhttp/src/main/java/io/palaima/debugdrawer/okhttp/OkHttpModule.java +++ b/debugdrawer-okhttp/src/main/java/io/palaima/debugdrawer/okhttp/OkHttpModule.java @@ -8,9 +8,9 @@ import com.squareup.okhttp.OkHttpClient; -import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; -public class OkHttpModule implements DebugModule { +public class OkHttpModule extends DebugModuleAdapter { private static final boolean HAS_OKHTTP; @@ -86,31 +86,6 @@ public void onOpened() { refresh(); } - @Override - public void onClosed() { - - } - - @Override - public void onResume() { - - } - - @Override - public void onPause() { - - } - - @Override - public void onStart() { - - } - - @Override - public void onStop() { - - } - private static String sizeString(long bytes) { String[] units = new String[] { "B", "KB", "MB", "GB" }; int unit = 0; diff --git a/debugdrawer-okhttp3/src/main/java/io/palaima/debugdrawer/okhttp3/OkHttp3Module.java b/debugdrawer-okhttp3/src/main/java/io/palaima/debugdrawer/okhttp3/OkHttp3Module.java index 159220f..e66ae87 100644 --- a/debugdrawer-okhttp3/src/main/java/io/palaima/debugdrawer/okhttp3/OkHttp3Module.java +++ b/debugdrawer-okhttp3/src/main/java/io/palaima/debugdrawer/okhttp3/OkHttp3Module.java @@ -6,10 +6,10 @@ import android.view.ViewGroup; import android.widget.TextView; -import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; import okhttp3.OkHttpClient; -public class OkHttp3Module implements DebugModule { +public class OkHttp3Module extends DebugModuleAdapter { private static final boolean HAS_OKHTTP3; @@ -85,31 +85,6 @@ public void onOpened() { refresh(); } - @Override - public void onClosed() { - - } - - @Override - public void onResume() { - - } - - @Override - public void onPause() { - - } - - @Override - public void onStart() { - - } - - @Override - public void onStop() { - - } - private static String sizeString(long bytes) { String[] units = new String[] { "B", "KB", "MB", "GB" }; int unit = 0; diff --git a/debugdrawer-picasso/src/main/java/io/palaima/debugdrawer/picasso/PicassoModule.java b/debugdrawer-picasso/src/main/java/io/palaima/debugdrawer/picasso/PicassoModule.java index c43119e..06b9b6a 100644 --- a/debugdrawer-picasso/src/main/java/io/palaima/debugdrawer/picasso/PicassoModule.java +++ b/debugdrawer-picasso/src/main/java/io/palaima/debugdrawer/picasso/PicassoModule.java @@ -12,8 +12,9 @@ import com.squareup.picasso.StatsSnapshot; import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; -public class PicassoModule implements DebugModule { +public class PicassoModule extends DebugModuleAdapter { private static final boolean HAS_PICASSO; @@ -88,21 +89,6 @@ public void onOpened() { refresh(); } - @Override - public void onClosed() { - - } - - @Override - public void onResume() { - - } - - @Override - public void onPause() { - - } - private void refresh() { StatsSnapshot snapshot = picasso.getSnapshot(); String size = getSizeString(snapshot.size); @@ -119,16 +105,6 @@ private void refresh() { transformedAverageLabel.setText(getSizeString(snapshot.averageTransformedBitmapSize)); } - @Override - public void onStart() { - - } - - @Override - public void onStop() { - - } - private static String getSizeString(long bytes) { String[] units = new String[] { "B", "KB", "MB", "GB" }; int unit = 0; diff --git a/debugdrawer-scalpel/src/main/java/io/palaima/debugdrawer/scalpel/ScalpelModule.java b/debugdrawer-scalpel/src/main/java/io/palaima/debugdrawer/scalpel/ScalpelModule.java index 310dbe8..08fed40 100644 --- a/debugdrawer-scalpel/src/main/java/io/palaima/debugdrawer/scalpel/ScalpelModule.java +++ b/debugdrawer-scalpel/src/main/java/io/palaima/debugdrawer/scalpel/ScalpelModule.java @@ -13,9 +13,9 @@ import com.jakewharton.scalpel.ScalpelFrameLayout; -import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; -public class ScalpelModule implements DebugModule { +public class ScalpelModule extends DebugModuleAdapter { private static final boolean HAS_SCALPEL; @@ -84,34 +84,4 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { return view; } - - @Override - public void onOpened() { - - } - - @Override - public void onClosed() { - - } - - @Override - public void onResume() { - - } - - @Override - public void onPause() { - - } - - @Override - public void onStart() { - - } - - @Override - public void onStop() { - - } } diff --git a/debugdrawer-timber/src/main/java/io/palaima/debugdrawer/timber/TimberModule.java b/debugdrawer-timber/src/main/java/io/palaima/debugdrawer/timber/TimberModule.java index ad2ae0c..1c59d23 100644 --- a/debugdrawer-timber/src/main/java/io/palaima/debugdrawer/timber/TimberModule.java +++ b/debugdrawer-timber/src/main/java/io/palaima/debugdrawer/timber/TimberModule.java @@ -5,10 +5,10 @@ import android.view.View; import android.view.ViewGroup; -import io.palaima.debugdrawer.base.DebugModule; +import io.palaima.debugdrawer.base.DebugModuleAdapter; import io.palaima.debugdrawer.timber.ui.LogDialog; -public class TimberModule implements DebugModule { +public class TimberModule extends DebugModuleAdapter { @NonNull @Override @@ -24,34 +24,4 @@ public void onClick(View v) { return view; } - - @Override - public void onOpened() { - - } - - @Override - public void onClosed() { - - } - - @Override - public void onResume() { - - } - - @Override - public void onPause() { - - } - - @Override - public void onStart() { - - } - - @Override - public void onStop() { - - } }