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

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.

Related

Error while trying to use .startsWith() and .contains() methods in kotlin

When I try to use the methods .startsWith and .contains with the variable value, I get the words in red, because apparently, they do not exist.
Can someone help with this error? I tried looking on the internet to see if this is an old deprecated function but I did not find anything apparently it is not deprecated...
Click to see the error here
I think you are leaving an space after calling the contains function. So is like you are not sending any arguments to the function.
It should be like this:
value.contains("/")
And same for startsWith
value.startsWith("-")
I just updated my old Android studio from 4.1.2 to the new ARTIC FOX 2020.3.1... and the error magically disappeared...Thanks.

Various questions #NonNull, #NotNull and #ParametersAreNonnullByDefault

I'm an Android dev who is using AndroidStudio or IntelliJ IDEA.
I tend to trust my IDE and I'm annoyed with next facts:
In android project when IDE autogenerates a method in java that extends Kotlin class then both IDE uses #NotNull instead of #NonNull, is there setting for this? This
We have #ParametersAreNonnullByDefault but when I override the method from the point 1 and I don't put any annotation IDE warns me, but why?
Am I wrong in my assumptions?
Are there solutions?
Which annotations to use for null/not-null is set under Configure annotations... in the Compiler page of the Settings/Preferences dialog. Select the one you want and press the checkmark button. See https://www.jetbrains.com/help/idea/nullable-notnull-configuration-dialog.html for documentation.
I can't test right now whether IDEA/AS use the default annotations from there when overriding a method which already uses another, but if they don't you'll need to file a ticket.

Is there an eclipse plugin to generate findViewById calls?

I use eclipse for android development, and I find it very annoying that every time I create an activity or add new views to my activity, I need to create the references to views in my layout. I am looking for some kind of eclipse plugin that can generate the calls to findViewById() from the layout. I couldn't really find anything because I didn't know what it would be named. It would be very useful and time saving if that kind of plugin existed.
EDIT: The answers you gave are great. Can these tools also add more references to an existing activity so I don't have to manually do that when I add a view to the layout?
You can use https://github.com/JakeWharton/butterknife library for View Injections.
You can also get eclipse plugin https://marketplace.eclipse.org/content/lazy-android for the same.
But the ButterKnife library is frequently being contributed by android devs than the mentioned eclipse plugin. With this library, you can also avoid instantiating listeners yourself by just using like,
#OnClick(R.id.submit) void submit() {
// TODO call server...
}
For View injections, simply,
#InjectView(R.id.user) EditText username;
#InjectView(R.id.pass) EditText password;
So, it will compile as,
username = (EditText) findViewById(R.id.user);
password = (EditText) findViewById(R.id.pass);
Try the morcinek code generator. Its really simple to use.
This are the steps to install the plugin:
http://tmorcinek.wordpress.com/2011/11/30/eclipse-plugin-for-automatic-generation-of-activity-code-from-xml-layout-file/
After install process you may want to configurate a package to get the classes built by the generator, on the IDE -> Window -> Preferences on Bookmark Android Code Generator you can change that parameter.
The plugin does need a better interface for custom activities, still you could get the code, its really simple to make the changes you need, at least the inline listeners.
This solution doesnt work to modify classes you already have, that would be a really good improvement... i'll give it a try in a couple days with more time.

Eclipse Indigo does not allow #Override for non Activity overwritten methods

I am using Eclipse Indigo for Android development. The problem i face is that it does not allow #Override for non Activity overwritten methods. For example if i implement onErrorListner of MediaPlayer and i set attribute #Override with it then it gives the following compile time error:
The method onError(MediaPlayer, int, int) of type MyActivity must override a superclass method
And to fix this problem, i am suggested the following
Remove "#Override" annotation
Tough removing the #Override fixes the issue but why does it complain about it and also removing it may cause stopping some functionality of its parent etc??
I have downloaded many examples which use this "#Override" attribute with non-activity methods which proves that this is used and i might be missing some obvious thing. But i cannot run these examples in Eclipse Indigo without removing these "#Override" attributes from all the classes.
Why?
Any help is greatly appreciated.
Your project Java compiler level is set to 1.5 instead of 1.6. See here.
It is not good to remove that line. you need to change to JDK version in your eclipse then you will not get such errors. Follow, following steps for it,
Right Click on your Project & select Properties.
Then from the left section Select Java Compiler & select the Version of the JDK you installed. If it is already selected then de-select it & try it.

ECLIPSE comments in Android code - what is this?

I was just writing my code and put a // TODO: comment line, so I don't forget then on the left side a unknown little icon appears.
Does anyone know what this means and how to use this? I could not find anything about this extra feature thingy. Are there more of these? Can one search for "TODOs" somehow?
Thanks
This link should help explain it.
To view the added tasks, you have to open the Tasks window, which is different from the Task List Window. To open the Tasks window:
window -> show view -> other… > general > tasks
If you don’t see general, try typing “task” in the filter text box.
Whenever you create a class with an implemented method usually eclipse will fill it in for you (the unimplemented methods) and it creates the methods and puts that comment in there (it's auto-generated and a method stub)
You can make those To-do blocks yourself as a reminder for unimplemented / not completed methods. If you want to work on an old project you can just check the scrollbar and see for any blue bars so you know you haven't implemented some methods yet and implement them.
Press Window->Show view->Tasks.
This bookmark show all your TODO and another comments marks for your project/workspace
I'm not sure if this is the reason, but I noticed the feature stopped
working sometime after this was announced:
check this
also this post
and this post
this may help you

Categories

Resources