forked from victorwon/mopub-android-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joe Blubaugh
committed
Apr 3, 2015
1 parent
10eef43
commit ec95adb
Showing
92 changed files
with
3,861 additions
and
719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
mopub-sample/src/main/java/com/mopub/simpleadsdemo/LoggingUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.mopub.simpleadsdemo; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.mopub.common.logging.MoPubLog; | ||
import com.mopub.mobileads.MoPubErrorCode; | ||
|
||
import java.util.logging.Handler; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogManager; | ||
import java.util.logging.LogRecord; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Used to intercept logs so that we can view logs at a lower level | ||
* than Verbose (ie. Level.FINEST). This will show a toast when we | ||
* receive a matching error from the mopub sdk. | ||
*/ | ||
public class LoggingUtils { | ||
private LoggingUtils() { | ||
} | ||
|
||
/** | ||
* The name of the custom logger we're looking for | ||
*/ | ||
private static final String LOGGER_NAME = "com.mopub"; | ||
|
||
private static boolean sEnabled; | ||
|
||
/** | ||
* Makes it so that this app can intercept Level.FINEST log messages. | ||
* This is not thread safe. | ||
* | ||
* @param context Needs a context to send toasts. | ||
*/ | ||
static void enableCanaryLogging(@NonNull final Context context) { | ||
if (sEnabled) { | ||
return; | ||
} | ||
|
||
final Handler handler = new SampleAppLogHandler(context.getApplicationContext()); | ||
final Logger logger = getLogger(); | ||
|
||
logger.setLevel(Level.ALL); | ||
logger.addHandler(handler); | ||
|
||
sEnabled = true; | ||
} | ||
|
||
private static Logger getLogger() { | ||
// This makes sure the static block in MoPubLog is executed before | ||
// LogManager#getLogManager is called. | ||
MoPubLog.c("Canary level logging enabled"); | ||
|
||
return LogManager.getLogManager().getLogger(LOGGER_NAME); | ||
} | ||
|
||
private static class SampleAppLogHandler extends Handler { | ||
|
||
@NonNull | ||
private final Context mContext; | ||
|
||
protected SampleAppLogHandler(@NonNull final Context context) { | ||
super(); | ||
mContext = context; | ||
} | ||
|
||
@Override | ||
public void publish(final LogRecord logRecord) { | ||
// Toasts the warmup message if X-Warmup flag is set to 1 | ||
if (logRecord != null && MoPubErrorCode.WARMUP.toString().equals(logRecord.getMessage())) { | ||
Utils.logToast(mContext, MoPubErrorCode.WARMUP.toString()); | ||
} | ||
} | ||
|
||
@Override | ||
public void flush() { | ||
} | ||
|
||
@Override | ||
public void close() throws SecurityException { | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.