just looking through the source for renderscript.
I think I spotted a mistake, on line 36
private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
Think that needs to be a double == but don't have enough coding experience to be sure.
No, I don't think it is a bug. It's setting LOG_ENABLED to either LOGD or LOGV depending on the value of DEBUG.
The relevant bit is:
public class RenderScript {
static final String LOG_TAG = "libRS_jni";
private static final boolean DEBUG = false;
#SuppressWarnings({"UnusedDeclaration", "deprecation"})
private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
and that last line is conceptually equivalent to:
private static final boolean LOG_ENABLED;
if (DEBUG)
LOG_ENABLED = Config.LOGD;
else
LOG_ENABLED = Config.LOGV;
In fact,
private static final boolean LOG_ENABLED == DEBUG ? Config.LOGD : Config.LOGV;
doesn't actually make sense since it means:
private static final boolean ((LOG_ENABLED == DEBUG)
? Config.LOGD
: Config.LOGV);
which doesn't have a variable name being declared at all, just a value that should be assigned to something.
It's just a simple bit of confusion about how ternary operators work in Java. You're doing something like:
int i;
boolean b;
int n1=2;
int n2=3;
i = b ? n1 : n2;
where b can be an expression evaluating to true or false. I used to use parenthesis around the first element to make this clear, although I just looked through some of my code and I seem to have stopped doing that now!
Related
I'm trying to build a profile for the Tasker app that responds to the BATTERY_CHANGED broadcast intent and I saw one of the Extras called Online that appears to correspond with the specific charger type or condition, but I can't seem to find a proper list of potential values for this Extra. At best, I've found a few of the values, such as 1 being None, 4 is USB, 10 is Wireless, 100 is Fast Wireless. Others I have just guessed at, such as 6 being a QuickCharge 2.0 or 3.0 type charger and 19 being a Power Delivery charger, but otherwise I can't be sure.
Is there any official documentation for this Extra in Android P?
There's surprisingly little documentation about the online extra!
I found this list which seems to be from a decompiled Samsung Pay app, weirdly enough:
public static final int BATTERY_ONLINE_FAST_WIRELESS_CHARGER = 100;
public static final int BATTERY_ONLINE_INCOMPATIBLE_CHARGER = 0;
public static final int BATTERY_ONLINE_NONE = 1;
public static final int BATTERY_ONLINE_POGO = 23;
public static final int BATTERY_ONLINE_TA = 3;
public static final int BATTERY_ONLINE_USB = 4;
public static final int BATTERY_ONLINE_WATER_IN_CONNECTOR = 101;
public static final int BATTERY_ONLINE_WIRELESS_CHARGER = 10;
The values seem to match with almost all of yours, I do find it very odd that seems to be no other record of them (from a quick Google).
Despite the android.os package of the linked file, perhaps it's not part of the OS / has been changed / has a different name. Maybe a Samsung-specific feature?
I use SignalStength to get the quality of the signal, before sending sms:
signalStrength.getLevel()
I then wanted to compare the integer with a static constant in SignalStength:
if (signalStrengthLevel == SignalStrength.SIGNAL_STRENGTH_POOR) {
//...
}
But it doesn't compile in Android Studio. I realized that for some reason, these constants are marked as hidden in the source code:
/** #hide */
public static final int SIGNAL_STRENGTH_POOR
= TelephonyProtoEnums.SIGNAL_STRENGTH_POOR; // = 1
Which forces me to copy/paste these constants in one of my own classes...
I then wonder if anyone knows the reason why the developers decided to mark these constants as hidden?
In the documentation of the TelephonyManager, we can find getSignalStrength() method, which returns SignalStrength type, which has getLevel() method. In the documentation of getLevel() method, we can read the following information about returned integer value:
a single integer from 0 to 4 representing the general signal quality.
This may take into account many different radio technology inputs. 0
represents very poor signal strength while 4 represents a very strong
signal strength.
Taking that into consideration, I'd solve that in the following way:
create static values like:
private final static int VERY_POOR_SIGNAL = 0;
private final static int POOR_SIGNAL = 1;
private final static int MEDIUM_SIGNAL = 2;
private final static int STRONG_SIGNAL = 3;
private final static int VERY_STRONG_SIGNAL = 4;
and use this values to compare them with the integer value returned by:
telephonyManager.getSignalStrength().getLevel()
The word /** #hide */ just informs that the API is not accessible from SDK. I think it might be for security reasons.
Check this post
How do you add 3 or more complications in your watch face? Does the name of the complication ids matter? I know how to have 2 complications,https://codelabs.developers.google.com/codelabs/adding-complications-to-your-android-wear-watch-face/index.html#0, but not 3 or 4.
Is this correct?:
private static final int LEFT_DIAL_COMPLICATION = 0;
private static final int RIGHT_DIAL_COMPLICATION = 1;
private static final int BOTTOM_DIAL_COMPLICATION = 2;
public static final int[] COMPLICATION_IDS = {LEFT_DIAL_COMPLICATION, RIGHT_DIAL_COMPLICATION, BOTTOM_DIAL_COMPLICATION};
Or do I have to change that code? I haven't found any documentations on 3 complications or more.
Thanks for any answer!
(Posted solution on behalf of the OP).
The name wasn't the problem, it was a name-array.
I'm attempting to get the int resource id for a layout resource by name, using Resources.GetIdentifier() of the Android API, but it returns 0. I'm using c#/monodroid/Xamarin, but regular java Android knowledge would apply too I suspect. Here's my code:
int resId = Resources.GetIdentifier(typeName, "layout", _activity.PackageName);
Where typeName = "FrmMain", and in my project I have the file "Resources/Layout/FrmMain.axml". Any ideas?
This is old, but for everyone getting this problem, I think it is because the resource name should be in lower case, so:
int resId = Resources.GetIdentifier("FrmMain", "layout", _activity.PackageName);
does not work, but:
int resId = Resources.GetIdentifier("frmmain", nameof(Resource.Layout).ToLower(), _activity.PackageName);
should work
I don't know why that's failing, but wouldn't something like Resource.Layout.FrmMain achieve what you're after?
edit:
According to this answer, you can (and should) use reflection to achieve what you're after, so I think you would try something like this:
var resourceId = (int)typeof(Resource.Layout).GetField(typeName).GetValue(null);
which does seem to work on my app and should get what you're after.
In my case, this issue came up when I had to upgrade the target SDK due to google's new policy since November, 2018.
I had to display some strings according to the server response code (ex : api_res_001_suc), but it did not work on the upgraded version.
The overall version, about 22 as I recall, had to be changed to 27.
The cause of the issue seems to be the default translation stuff. When I put all the default translation for every string, it worked.
My code is,
getResources().getIdentifier(resName, "string", "packageName");
I've created a ResourceHelper class to handle this situation. Here is the code:
public static class ResourceHelper
{
public static int FindId(string resourceId)
{
var type = typeof(Resource.Id);
var field = type.GetField(resourceId);
return (int)field.GetRawConstantValue();
}
public static int FindLayout(string layoutName)
{
var type = typeof(Resource.Layout);
var field = type.GetField(layoutName);
return (int)field.GetRawConstantValue();
}
public static int FindMenu(string menuName)
{
var type = typeof(Resource.Menu);
var field = type.GetField(menuName);
return (int)field.GetRawConstantValue();
}
}
Actually I'm improving it because I need to use it from another Assembly and it's restricted to work in the same Assembly of the Droid App. I'm thinking about put a generic method (or an Extension one) to do this. Here is a draft of my idea:
public static int FindResource<T>(string resourceName)
{
var type = typeof(T);
var field = type.GetField(resourceName);
return (int)field.GetRawConstantValue();
}
Hope it can help you.
I found a program in Android that claims to return marker positions in AR ("AR_speaker") and uses native code (jni). My problem is in the markerInfo class. I can't understand the meaning of this regular expression:
^id=(\\d+):name=(.+):pos\\[0\\]=([\\d.]+):pos\\[1\\]=([\\d.]+)$
public class MarkerInfo implements Serializable {
private static final long serialVersionUID = 1L;
private static final Pattern REGEX = Pattern.compile("^id=(\\d+):name=(.+):pos\\[0\\]=([\\d.]+):pos\\[1\\]=([\\d.]+)$");
private Integer id;
private String fileName;
private Float[] pos = new Float[3];
public MarkerInfo(String markerStr) {
Matcher m = REGEX.matcher(markerStr);
if (!m.find()) throw new RuntimeException("not markerInfo string : " + markerStr);
id = Integer.parseInt(m.group(1));
fileName = m.group(2);
pos[0] = Float.parseFloat(m.group(3));
pos[1] = Float.parseFloat(m.group(4));
//pos[2]=Float.parseFloat(m.group(5));
}
public Integer getId() {
return id;
}
public String getFileName() {
return fileName;
}
public Float[] getPos() {
return pos;
}
}
My other question is where are these data stored? Do any patterns used in AR have these data? In which file? (For example, in marker.patt?)
In Regular Expressions ^ means "start of expression or deny character but in this case is start of expression", then this is what the expression is looking for in the markerStr, is looking for the characters "id=" followed by one or more decimal characters followed by ":name=" followed by a group one or more characters of any kind (thats what .+ mean) followed by ":pos[0]=" followed by one or more decimal characters or dot (thats what [\d.]+ mean) followed by "pos[1]=" followed by one or more decimal characters or dot (thats what [\d.]+ mean) and $ means the end of the regular expression...
Hope this help, and anyway i recommed you to read about Regex, they are extremely good tool to find patterns in a string, that's what they are using it for in this case...
Regards!