I am just wondering what is the format in Zxing.
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Do you think I can delete this line of code?
According to the latest version in the trunk:
/**
* Call intent.getStringExtra(RESULT_FORMAT) to determine which barcode format was found.
* See Contents.Format for possible values.
*/
public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT";
Contents.Format actually doesn't exist (anymore), but browsing through the code it seems fair to assume the "formats" have been replaced by "types". Contents.Type defines the following possibilities:
public static final String TEXT = "TEXT_TYPE";
public static final String EMAIL = "EMAIL_TYPE";
public static final String PHONE = "PHONE_TYPE";
public static final String SMS = "SMS_TYPE";
public static final String CONTACT = "CONTACT_TYPE";
public static final String LOCATION = "LOCATION_TYPE";
In other words: it gives you information about the type of data that is encoded by the scanned barcode. If you don't care about the type, you can simply ignore it.
This is a string naming the format of the barcode scanned, like "QR_CODE" or "UPC_A". Values come from the class BarcodeFormat. Can you remove it? sure, don't write this line of code if you don't need it!
Are you talking about using the intent integrator? If so, this is the kind of barcode that you just scanned. I don't know what your purposes are, but if you want to support more barcodes, you might want to consider this line more important.
Related
I'm entering a new codebase and have to understand how it works. There's a BR file that's autogenerated. I think it comes from the Data Binding Library. That BR files contains a lot of values, but I see no way to automatically search for the area in the code from where the content of that file gets specified.
When I have for example:
public static final int currentDate = 35;
public static final int currentEmail = 36;
How do I lookup where the code that results in those variables existing originates?
I see no way to automatically search for the area in the code from
where the content of that file gets specified.
First of all, BR file is auto generated which will not let you know where from the fields generated. Same like you can not search R fields, where they belong to.
But there are normally two types of fields generated in BR file.
1st is <variable defined in your layout.
<variable
name="model"
type="sample.data.Model"/>
2nd is #Bindable fields.
#Bindable
public String getPassword() {
return password;
}
So BR file look like
public class BR {
public static final int _all = 0;
public static final int model = 0;
public static final int password = 1;
}
_all is some default integer which always gets generated.
Usually generated code relies under this path:
path to project/app/build/generated/rs
To check that in Android studio, you can change project structure view
from 'Android' to 'Project' and follow above path to see generated
code.
That's a bit tricky to find. You can right click on a field and choose "Find Usages" but that will only show you where it's used, not where it originates from. The fields in BR.java are generated from methods marked with #Bindable Like
#Bindable
public String getSomeStringValue() {
return "Some arbitrary string.";
}
Which will result in a field in the BR.java file looking like:
public static final int someStringValue = 126;
So to be able to find where something in the BR-file originates from you take what's in the BR.java file and slap on a "get" and then search for it. Myself, I would probably search for #Bindable instead.
why on all demos and tutorials in SQLiteOpenHelper class variables are always: public static final
Have a look:
public static final String ORDER_ID = "order_id";
public static final String ORDER_LOGIN_NAME = "login_name";
public static final String ORDER_RESTO_U_NAME = "resto_uniqe_name";
My question is: I am making an application and its database is too big. So, I will have to make atleast 60-70 variables of these kind. Won't it affect application performance? As these are static variables.
Any help will be highly appreciated....
Well, whether they public or private or package-protected depends on your needs, but final static is a good way of declaring constants per Android guidelines, take a look here for explanation: http://developer.android.com/training/articles/perf-tips.html#UseFinal
Consider the following declaration at the top of a class:
static int intVal = 42;
static String strVal = "Hello, world!";
The compiler generates a class initializer method, called , that is executed when the class is first used. The method stores the value 42 into intVal, and extracts a reference from the classfile string constant table for strVal. When these values are referenced later on, they are accessed with field lookups.
We can improve matters with the "final" keyword:
static final int intVal = 42;
static final String strVal = "Hello, world!";
The class no longer requires a method, because the constants go into static field initializers in the dex file. Code that refers to intVal will use the integer value 42 directly, and accesses to strVal will use a relatively inexpensive "string constant" instruction instead of a field lookup.
I am trying to define a search string and new to android, not sure how to do the same. Any clue?
Here's my code for the same:
public final static String PROD_ENVIRONMENT = "https://mobile13.com/fwd/answers/answers/service/v1/?q=**KEYWORD**%20revenue&ui.theme=novadark&uuid=PADACT-002&userAgent=iphone";
I want to replace the KEYWORD with a dynamic string like %s, which can be recognized with a static string say "public static string KEYWORD" , which i can check ,in turn matches the typed keyword and display the results accordingly
Try this
public final static String PROD_ENVIRONMENT = "https://mobile13.com/fwd/answers/answers/service/v1/?q="+KEYWORD+"%20revenue&ui.theme=novadark&uuid=PADACT-002&userAgent=iphone";
That is if you have the static variable in the same class. If you have it in a different class, say StaticUtils class then you can put it as StaticUtils.KEYWORD.
why will String.format not work?
android documentation
I would like to read your thoughts on how to solve the following problem. Here are the basic requirements of the application I am working on.
Display multiple locations one city on a map.
Support for multiple cities.
Display the properties of a location on a separate details view.
Location properties of each city differ.
I would like to implement a flexible decision logic that switches between cities based on the location that the map is at. That means, the initial information I rely on, is the map center. Here is the theoretical workflow.
Get the current center location from the map.
Translate the location into a city url and uri.
Download locations via HTTP using the url.
Store the locations in local database. One table for each city since location properties differ.
Load cached or downloaded data from a content resolver using the uri.
Create overlay items and include the uri reference and a unique id.
Open a details view when tapping on a location.
The details view should render the city specific location properties.
The location properties again are loaded via a content resolver based on the passed uri and unique id.
Questions:
I am particular interested on how you would switch cities, query parameters such as column names using the UriMatcher class.
Would you prepare one details view for each city? Or do you see any practical solution to swap text fields, label, .. based on the available property information?
To illustrate the different properties, here are two example cities and a content provider.
Example:
public class DatabaseParis {
public static final class Contract {
public static final String COLUMN_LATITUDE = "latitude";
public static final String COLUMN_LONGITUDE = "longitude";
public static final String COLUMN_NAME = "name";
}
And another city ...
public class DatabaseDenver {
public static final class Contract {
public static final String COLUMN_LATITUDE = "lat";
public static final String COLUMN_LONGITUDE = "lon";
public static final String COLUMN_HEIGHT = "height";
public static final String COLUMN_DIAMETER = "diameter";
}
And a content provider ...
public class CustomContentProvider extends ContentProvider {
public static final class Contract {
public static final Uri URI_PARIS = Uri.parse("content://" + AUTHORITY + "/cities/paris");
}
private static final String AUTHORITY = "com.example.cities.locations";
private static final int URI_CODE_PARIS = 0;
private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
static {
URI_MATCHER.addURI(AUTHORITY, "cities/paris", URI_CODE_PARIS);
}
I am unsure about using one or multiple content provider since I read putting all database references into one can be a problem when the data should be synced in the future.
I guess one who deals with such a scenario should consume the following information sources.
Developing Android REST client applications, Virgil Dobjanschi, Google I/O San Francisco, 2010
ContentProvider and REST API, Benjamin Brombach, Android UserGroup Berlin, 2012
I have a response in html form from the server, now I want to read the characters or say data of between particular tag, for example: font tag starting---(The data that I want to read)----font tag ending.
I have stored the string in a String Variable named "response".
How can I do this in android?
Thanks,
david
You can probably use regex Pattern.
Here's a little example, though it can be probably made more efficient and abstract:
public static void main(final String[] args) {
final String html = "Some text <font> here </font>, and some <font>there</font>";
final Pattern ptrn = Pattern.compile("<font>(.+?)</font>");
final Matcher mtchr = ptrn.matcher(html);
while (mtchr.find()) {
final String result = html.substring(mtchr.start(), mtchr.end()).replace("<font>", "").replace("</font>", "");
System.out.println(result);
}
}
Result:
here there
P.S. You probably shouldn't use this for large responses (and I think it's not adviced to use regex for html). Maybe you should use some parser (SAX for one).
are you in a browser ? if so you can use jQuery or simply :
document.getElementById('divID').innerHTML;