Config.LOGD is deprecated - android

In android.util.Config, the Config.LOGD, Config.LOGV are now deprecated. Can you please tell me how to refactor my code to in order to get rid of the warnings compiler generated?
Thank you.

Config.DEBUG is deprecated use BuildConfig.DEBUG instead.
See the Google I/O App for Android (iosched) source code for reference on how to make logging more consistent throughout your Android application.
http://code.google.com/p/iosched/source/browse/android/src/com/google/android/apps/iosched/util/LogUtils.java

You should use Config.DEBUG(true in Debug mode) instead of Config.LOGD.

Yes, Robby means it. See the explanation of open source code.
public final class Config
{
/**
* If this is a debug build, this field will be true.
*/
public static final boolean DEBUG = ConfigBuildFlags.DEBUG;
PS: I just want to set the above words as comment, but I don't know how to set as comments, so I can only set as another answer.

Related

Class name is marked as 'not covered' while running code coverage in Android Studio

I have tried AndroidStudio's code coverage feature and I have met a strange issue:
It is marks the tested class's name as 'not covered' code.
How is that possible? Is that a bug?
Picture here:
As you can see it has one method with 4 lines and each one of them is covered. So why is the red line at the class's name?
You are using a static method, so the class itself is never created as an object, therefore never testing that ability.
I tried the lombok #UtilityClass, it helped to ignore the class name and code coverage was improved to be 100%.
Since also a class with a static function has a default no-argument constructor, your code coverage tool will complain. A good way to solve this, is by adding a private constructor.
private EmailValidator() {
}

How to find out a default behavior/value for an Android API?

I am learning Android programming, this seems to be a silly question.
pd = new ProgressDialog(this);
pd.setCancelable(false);
Cancelable can be
true
false
default behavior / not set
Is there an easy way to know the default behavior is either true or false?
In android Studio editor, use ctrl + Q, got this:
Online reference does not help either. setCancelable
I can run the code, then know the result, but it gotta be a easy way, right?
Take a look into its parent class: Dialog.
You can find out this line
/**
* This field should be made private, so it is hidden from the SDK.
* {#hide}
*/
protected boolean mCancelable = true;
By the way ProgressDialog it's not recommend by Google. You should use ProgressBar instead. You have to handle block button or something like this while ProgressBar is showing, but it bring user a better UX
You can control + click (on Android Studio or Eclipse) on the class that interests you and see on the library's source whether the boolean flag is set upon initialization on the class.
Usually, the information would be on the online reference. However, as you point out, it isn't!
Whenever I find I need to know something like that, and it isn't documented, then I check the source code. It is usually quite trivial to search for the specific class source in Google.
This of course, is only showing the value it takes by default for Android 4.4. In this case though, the value is unlikely to have a changed default. You should always bear that possibility in mind.

Best way to Enable Android Support Library Debugging Flag

I'm running into many problems with the Android Support Library's ViewPager widget. Due to lack of documentation and just incorrect behavior, I've been learning how things work based on the source.
Looking at the source, I see that the ViewPager, I see a constant defined as
private static final boolean DEBUG = false;
If I can set this to true, then I can enable all the debugging for the ViewPager class
However, I can't determine how to modify this value at runtime. Reflection didn't seem to have access to it.
Is the only way to change this flag is by recompiling the source?
1.remove the "final" property;
2.add a method allowed to modify the DEBUG value;
3.recompile the source.
For enabling debug, maybe you should extends this class firstly. Then use your customized class instead of ViewPager.
A final variable cannot be changed after it is assigned therefore you would need to recompile from source with DEBUG = true if you want to enable the built in debugging statements.

Android Lint Plugin - set custom warning / error that should be checked

My question is if there is a way to add to lint plugin a custom check which it should warn me about before building a version. For example I want it to check all Cursor, InputStream objects in my code if they are closed, or to check my code for //TODO:, //FIXME:.
Any ideas if there is any kind of way to do that, or even not with Lint Plugin?
Thanks in advance!
Yes, you can add custom checks; see http://tools.android.com/tips/lint/writing-a-lint-check and http://tools.android.com/tips/lint-custom-rules .
For your specific question, note that there's a new lint check in 21.1 which looks at comments. It doesn't look for TODO or FIXME; instead, it complains if it finds the comment marker "STOPSHIP". If you want to add a rule for todo or fixme, you might want to base it on that check.

Proguard shrinks too much

Since ADT 17 you can find in the gen folder a BuildConfig class with a DEBUG constant. I often use this constant in my code, since ADT changes the value automatically when you export the application.
However with Proguard this doesn't work anymore. E.g. I have following snippet:
if (!BuildConfig.DEBUG) {
ACRA.init(this);
}
Proguard notices, that DEBUG is true, so it removes this snippet completely and shrinks the app. After that ADT changes DEBUG constant, but this is too late.
The only solution I know is to create my own DEBUG constant and to change it manually again. But I really like the functionality of ADT. Do you know a better solution?
Thanks in advance.
Edit:
There is a workaround. Create your own DEBUG constant, which is initialized at runtime:
debug = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
I create this variable at the very first in the onCreate method of my Application class. That is a workaround, which works, but it isn't the solution of the problem.

Categories

Resources