From 7b664ba28c7b3d58005933148adb5119dae3d98a Mon Sep 17 00:00:00 2001 From: MichaelFlisar Date: Mon, 13 Feb 2017 12:27:24 +0100 Subject: [PATCH] code documentation added for the builders --- README.md | 13 +-- .../com/michaelflisar/lumberjack/demo/L.java | 13 +-- .../lumberjack/demo/MainActivity.java | 33 ++++++-- .../app/src/main/res/layout/activity_main.xml | 7 ++ .../lumberjack/FileLoggingSetup.java | 46 ++++++++++ .../lumberjack/NotificationLoggingSetup.java | 58 ++++++++++++- .../lumberjack/OverlayLoggingSetup.java | 84 ++++++++++++++++--- .../src/main/res/layout/overlay.xml | 4 +- 8 files changed, 225 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 9596aa5..4f50ea3 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ dependencies { // modules (OPTIONAL) compile 'com.github.MFlisar.Lumberjack:lumberjack-filelogger:1.3' compile 'com.github.MFlisar.Lumberjack:lumberjack-notification:1.3' + debugCompile project(':lumberjack-overlay') + releaseCompile project(':lumberjack-overlay-noop') // ALTERNATIVELY you can add ALL modules at once like following // compile 'com.github.MFlisar:Lumberjack:1.3' @@ -43,7 +45,7 @@ dependencies { ###Example -This is what the demo setup will print out (to your file, to the notification, to console). It has pretty printing enabled and prints first 5 values of an array automatically. It as well prints caller class and group combined as tag. The demo shows that +This is what the demo setup will print out (to your file, to the notification, to console, to the overlay). It has pretty printing enabled and prints first 5 values of an array automatically. It as well prints caller class and group combined as tag. The demo shows that * arrays are printed automatically * custom classes are automatically formatter to the custom formatter you have registered, no matter if the classes are printed inside an array or as a simple value @@ -95,8 +97,7 @@ The overlay logger is based on Hannes Dorfmann's DebugOverlay: https://github.co ###Missing * Notification Logger - * An activity that can be launched via the notification (that shows the logs and offers advanced filter options) - * filter: errors only - * overlay logger - * demo gif - * noop für overlay logger to avoid the overlay manifest permission \ No newline at end of file + * An activity that can be launched via the notification (that shows the logs and offers advanced filter options) + * filter: errors only + * Overlay Logger + * filter: errors only \ No newline at end of file diff --git a/demo/app/src/main/java/com/michaelflisar/lumberjack/demo/L.java b/demo/app/src/main/java/com/michaelflisar/lumberjack/demo/L.java index 16c84cf..20f8e54 100644 --- a/demo/app/src/main/java/com/michaelflisar/lumberjack/demo/L.java +++ b/demo/app/src/main/java/com/michaelflisar/lumberjack/demo/L.java @@ -61,8 +61,8 @@ public String log(MainActivity.TestClass item, boolean logInList) { }); // some test logs... - L.d(G_TEST, "initLumberjack fertig"); - L.d(G_TEST, "LogFiles: %s", FileLoggingUtil.getAllExistingLogFiles(FILE_LOG_SETUP)); + L.d(G_TEST1, "initLumberjack fertig"); + L.d(G_TEST2, "LogFiles: %s", FileLoggingUtil.getAllExistingLogFiles(FILE_LOG_SETUP)); } public static void initOverlayLogger(Activity activity) @@ -78,7 +78,7 @@ public static void handleOverlayPermissionDialogResult(int requestCode, int resu // we know that the 4th tree is the overlay logger, so we just hand on the data boolean success = ((OverlayLoggingTree)Timber.forest().get(3)).checkRequestPermissionResult(requestCode, resultCode, data); - L.d(G_TEST, "Overlay permission granted: %b", success); + L.d(G_TEST1, "Overlay permission granted: %b", success); } // ----------------------------- @@ -86,11 +86,13 @@ public static void handleOverlayPermissionDialogResult(int requestCode, int resu // ----------------------------- // Groups - public static final ILogGroup G_TEST = L.createGroup("TEST-GROUP"); + public static final ILogGroup G_TEST1 = L.createGroup("TEST-GROUP 1"); + public static final ILogGroup G_TEST2 = L.createGroup("TEST-GROUP 2"); public static final ArrayList LOG_GROUPS = new ArrayList() { { - add(G_TEST); + add(G_TEST1); + add(G_TEST2); } }; @@ -108,6 +110,7 @@ public static void handleOverlayPermissionDialogResult(int requestCode, int resu .withTitle("Demo Logger") //.withBigIcon(R.mipmap.ic_launcher_default) .withNotificationId(150) + .withButtonIntentRequestCodeBase(250) .withFilters(LOG_GROUPS); // ----------------------------- diff --git a/demo/app/src/main/java/com/michaelflisar/lumberjack/demo/MainActivity.java b/demo/app/src/main/java/com/michaelflisar/lumberjack/demo/MainActivity.java index e49b5a8..27170b5 100644 --- a/demo/app/src/main/java/com/michaelflisar/lumberjack/demo/MainActivity.java +++ b/demo/app/src/main/java/com/michaelflisar/lumberjack/demo/MainActivity.java @@ -3,17 +3,24 @@ import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.view.View; import java.util.ArrayList; import java.util.Arrays; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity implements View.OnClickListener { + private int mCount = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + if (savedInstanceState != null) + mCount = savedInstanceState.getInt("mCount"); + + findViewById(R.id.btLog).setOnClickListener(this); + // here we can ask for the permission, so we init the overlay logger in here // make sure to pass on the result of the permission dialog to the overlay logger! L.initOverlayLogger(this); @@ -30,13 +37,13 @@ protected void onCreate(Bundle savedInstanceState) { L.d("Test array log: %s", new ArrayList<>(Arrays.asList("array value 1", "array value 2"))); // Test 3: a few logs with usage of groups - L.d(L.G_TEST, "Test message in test group"); - L.d(L.G_TEST, "Test message in test group, value=%d", 999); + L.d(L.G_TEST1, "Test message in test group"); + L.d(L.G_TEST1, "Test message in test group, value=%d", 999); // Test 4: Disable a group, log to this group and see, that nothing is logged and enable group again - L.disableLogGroup(L.G_TEST); - L.e(L.G_TEST, "This message should NOT appear anywhere because the group is disabled!"); - L.enableLogGroup(L.G_TEST); + L.disableLogGroup(L.G_TEST1); + L.e(L.G_TEST1, "This message should NOT appear anywhere because the group is disabled!"); + L.enableLogGroup(L.G_TEST1); // Test 5 - custom object formatting // we have registered a custom formatter for our TestClass, so we can DIRECTLY pass TestClasses for any string paramter and lumberjack will take care of it! @@ -50,6 +57,20 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } + @Override + public void onSaveInstanceState(Bundle outState) + { + super.onSaveInstanceState(outState); + outState.putInt("mCount", mCount); + } + + @Override + public void onClick(View view) + { + mCount++; + L.d("Button clicked: %d", mCount); + } + public static class TestClass { public int x; diff --git a/demo/app/src/main/res/layout/activity_main.xml b/demo/app/src/main/res/layout/activity_main.xml index c165f71..a942d69 100644 --- a/demo/app/src/main/res/layout/activity_main.xml +++ b/demo/app/src/main/res/layout/activity_main.xml @@ -14,4 +14,11 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> + +