Array in Between Condition - android

How do I implement this condition as shown in this image.

That's just in 2..4, i.e. in the integer range from 2 to 4, including the 4.
The ≤ is just some hint text provided by the IDE, similar to how you can see argument names in function calls - it's not part of the code, it's not really there. They added it to make it clearer what the .. operator does (vs until)
This might be because they're introducing a new operator, ..< which seems intended to replace until, or maybe they've been there a while! You can turn them on and off here in the settings:

Related

FirebaseAnalytics is missing several parameter constants

I would like to pass along an array of bundles to FirebaseAnalytics as described here but FirebaseAnalytics.Param does not contain an ITEMS value. In fact, it only seems to contain a subset of the values it should contain as shown here:
I have firebaseanalytics version 17.4.4 and I tried to fill in the Param.ITEMS constant value myself ("items" according to the docs) but DebugView shows a firebase error (20 - Event array parameter name is invalid). All other events and parameters seem to work just fine according to DebugView and I found nobody with similar problems. Does anyone have any ideas as to why I only see a subset of the parameters?
Make sure you perform a Gradle sync, as FirebaseAnalytics.Param.ITEMS is definitely available in v17.4.4.
Here it is in my project, note the version number in the bottom right:
If you're still having trouble, mouseover one of the options in your dropdown and it should show you the version being used.

Proguard deletes method parameters

Recently I found very strange thing with ProGuard. I have this code snippet
As you can see, method showTipHoodLock takes 2 parameters, fragmentManager and top (some offset)
but after I compile the app with minifyEnabled true
I got this on click callback
and this is Utils.showTipHoodLock method
As you can see, proguard deleted 2nd parameter (named top) from method signature and replaced its occurances with 0 literal.
Is it a bug, or a feature, or did I miss something?
P.S. If I change values in line
int coords[] = {0, 0}
to any other numbers, then everything works perfect, and nothing is deleted. Moreover The same snippet of code (which is copy-pasted) in different part of application (in other fragment), starts to work.
Is it a bug, or a feature, or did I miss something?
This is NOT a bug, this is a feature to optimise your code.
According to your piece of code, the second parameter is referenced by following logic as READ ONLY and its value is FIXED to be 0.
Proguard will remove (a kind of Proguard optimisation: Remove unused parameters or Propagate constant arguments) this parameter with this KNOWN FIXED value to simplify the invocation flow.

Reqular expressions in Android with input that contains []{}"

I am trying to extract the X and Y component using a regular expression from the following data:
{"SearchResults":[{"PageCount":"0"},
{"SEARCHVAL":"530106","CATEGORY":"Building",
"X":"103.8907","Y":"1.3537"}]}
This is the pattern I tried to no avail:
Pattern p1 = Pattern.compile("\\\"X:\\\"([0-9.]*)\\\",\\\"Y\\\":\"([0-9.]*)\\\"");
Matcher m1 = p1.match(result);
if( m1.matches() ){
print("match found");
}
I have also tried the following without any luck:
Pattern.compile("\"X:\"([0-9.]*)\",\"Y\":\"([0-9.]*)\"");
This should be easy, but yet I have been stuck here for the past 2 hours.
If you want regex to parse it, then you can use:
"X":"(\d+(?:\.\d+)?)","Y":"(\d+(?:\.\d+)?)"
Regex Demo
You are missing a quote(") after X in your regex. Though I recommend not to use your regex because it will also match 1.1.2.3
In JAVA:
\"X\":\"(\\d+(?:\\.\\d+)?)\",\"Y\":\"(\\d+(?:\\.\\d+)?)\"
This RegEx will work:
"X":"([0-9.]*)","Y":"([0-9.]*)"
The 1st Capture Group contains the X value, and the 2nd Capture Group contains the Y value
Live Demo on Regex101
Which means your Pattern.compile should be:
Pattern.compile("\"X\":\"([0-9.]*)\",\"Y\":\"([0-9.]*)\"");
Note that you may need to add .* at the start of the RegEx for it to work.
for others that are stuck with the same problem, the reason why .* is needed at the front/end is because i used the wrong method call.
according to http://developer.android.com/reference/java/util/regex/Matcher.html#matches()
public boolean matches ()
Added in API level 1 Tries to match the Pattern against the entire
region (or the entire input, if no region has been set).
It needs to match the entire region.
to do any match, i would need to use find() instead.
public boolean find ()
Added in API level 1 Moves to the next occurrence of the pattern in
the input. If a previous match was successful, the method continues
the search from the first character following that match in the input.
Otherwise it searches either from the region start (if one has been
set), or from position 0.
hope this is useful to others.
String.matches() provides more insights to matches() method http://developer.android.com/reference/java/lang/String.html
public boolean matches (String regularExpression)
This method returns true only if the regular
expression matches the entire input string. A common mistake is to
assume that this method behaves like contains(CharSequence); if you
want to match anywhere within the input string, you need to add .* to
the beginning and end of your regular expression. See matches(String,
CharSequence).

Location.convert with leading zero

I use the following code to convert position to readable format:
Location.convert(position, Location.FORMAT_MINUTES);
This works well, except for one little thing:
51.05074707907328 //input (double)
51°3.04482 //WHAT I GET
51°03.04482 //WHAT I NEED
So how do I force that zero? I don't want to manually fix that, but there is nothing about it in Location reference.
(If someone is wondering, I do use .replace(":", "°"); to change : to °)
Since you already do a manual replacement (":" to "°"), you could just as well do the same to add there a zero when there is a single digit between the ":" and ".", for example:
.replaceFirst(":(\\d)\\.", ":0$1.")
In any case the Location library doesn't give you a lot of power to control these things, so I don't think there is a really clean solution here.

Android class member "fields" understanding

I'm new to Android(and Java also) and I'm trying to understand what are Fields in predefined Android classes.
For example in the Android View class there are Fileds: EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET etc.
Please can you tell me how to understand this and how can I use it? For me it looks like some constants but it's not.
Typically they are constants for the class, to be used in situations like this:
myWidget.setColor(Widget.BLACK_AND_TAN);
They usually have integer values, but they make the code more readable this way, and also allow for later changes to the API without altering the behavior of previous code. (Widgets.BLACK_AND_TAN == 7, or Widgets.BLACK_AND_TAN ==15,could both be true, or any other number. It doesn't matter. Just that BLACK_AND_TAN always corresponds to Black and Tan coloring.)
edit: note that Widget is a made up class, as is the BLACK_AND_TAN constant. let me get a real example for you.
Real Example, used to re-position the cursor every time a text field is updated:
DefaultCaret caret = (DefaultCaret)outputArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
Note that these do not HAVE to be constants as we normally refer to them; for example
Toast.LENGTH_LONG;
can be user defined, but it does specify how long a toast should display

Categories

Resources