Android support of dictionary based BreakIterator - android

I have the following same code run in API level 16 vs API level 21, and I found that in API level 16, the dictionary based iterator (tokenizer) seems not working, while in API level 21, the dictionary based iterator is working properly.
BreakIterator it = BreakIterator.getWordInstance();
String txt = "我们一起";
it.setText(txt);
int start = it.first();
int end = it.next();
buf = new StringBuffer();
while (end != BreakIterator.DONE) {
String word = txt.substring(start,end).trim();
if (!word.isEmpty()) {
buf.append(word);
buf.append("+");
}
start = end;
end = it.next();
}
vw.setText(buf);
In API Level 21, the text view shows ("我们" is a word, "一起" is a word)
我们+一起+
However in API Level 16, it shows as below (each Chinese character is a word):
我+们+一+起+
So I suspect that the API level 21 has enabled the dictionary based iterator, while previous API versions not.
However, after I have a search in the C++ source code of Android, I found that the key function RuleBasedBreakIterator::checkDictionary is both there in rbbi.cpp, for both API levels. It gives me the hints that both API shall support dictionary based iterator. I also suspect that the difference is because of the different category value set for different char-set. However I am not able trace back how these values are set and whether there is difference.
My question is, how to further confirm that the API implementation is enhanced in API level 21?

Related

KeyCharacterMap to use from code only

I need to insert a special character into my Android app that is not included in any the existing KeyCharacterMap files. Generating key events is the only way I see to get any active control without knowing which one.
To load this map in order to generate the KeyEvent from I have to specify the map's id but this ID comes from an InputDevice and there is no such device for my newly generated kcm file.
What is the best way to either use this keymap without an existing inputdevice or fake the inputdevice?
I believe that you can generate special key with this solution :
char[] szRes = szStringText.toCharArray(); // Convert String to Char arra
KeyCharacterMap CharMap;
if(Build.VERSION.SDK_INT >= 11) // My soft runs until API 5
CharMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
else
CharMap = KeyCharacterMap.load(KeyCharacterMap.ALPHA);
KeyEvent[] events = CharMap.getEvents(szRes);
for(int i=0; i<events.length; i++)
MainWebView.dispatchKeyEvent(events[i]); // MainWebView is webview
You can build the string[] szStringText with "!/§)". Normally, the code convert charactere. Source : https://www.codota.com/code/java/classes/android.view.KeyCharacterMap

Select android os name based on version number

First of all, nice day to everyone!
My code needs to detect which android version is being used on by means of getprop ro.build.version.release. I do so using systems with root and python for android.
For the time being the devices I tested the code things were working nice but partially of course because I haven't taking into consideration the updates in between new os versions. I just added the new version I was testing on to a dictionary.
So let's say I have this dictionary:
VersionName = {'4.0':"Ice Cream Sandwich", '4.0.4':"Ice Cream Sandwich", '4.1':"Jelly Bean", '4.2':"Jelly Bean", '4.3':"Jelly Bean", '4.4':"KitKat", '5.0':"Lollipop", '5.1':'Lollipop', '6.0':"Marshmallow", '7.1.1':"Nougat"}
I would add:
'4.4.2':'KitKat'
To save and detect the new version I was working on but that's not going to work. To overcome this I just simply made a search to select the first and the last release of an android version.
VersionName = {'Ice Cream Sandwich':['4.0', '4.0.4'], 'Jelly Bean':['4.1', '4.3.1'], 'KitKat':['4.4', '4.4.4'], 'Lollipop':['5.0', '5.1.1'], 'Marshmallow':['6.0', '6.0.1'], 'Nougat':['7.0', '7.1.1']}
The problems comes if the update version is in between the two values.
Given {'KitKat':['4.4', '4.4.4']} and device version 4.4.2 how can I detect if it's part of KitKat
maybe store the min and max as two variables, then do if os(version)> (min value):
then check if os(version) < (max value)
This is how I would approach the problem with the help provided! There are better ways I know that much so if anyone has another method please share.
def DroidName(ReleaseVersion):
# ReleaseVersion = '4.4.2'
VersionValue = {'Ice Cream Sandwich':['4.0', '4.0.4'], 'Jelly Bean':['4.1', '4.3.1'], 'KitKat':['4.4', '4.4.4'], 'Lollipop':['5.0', '5.1.1'], 'Marshmallow':['6.0', '6.0.1'], 'Nougat':['7.0', '7.1.1']}
for i in VersionValue.items():
AndroidName = i[0]
MinimalValue = i[1][0]
MaximunValue = i[1][1]
if ReleaseVersion >= MinimalValue and ReleaseVersion <= MaximunValue:
print AndroidName, ReleaseVersion
break

How to ignore diacritics with a regex in Android 2.2?

I need to use Android 2.2 (API 8) and I have seen that Normalizer.normalize(text, Normalizer.Form.NFD) is only available from Android API 9.
What can I add to my regex to ignore accents ?
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
for (String keyword : keywords.keySet()) {
String caseInsensitiveRegex = "(?i)\\b" + keyword + "\\b";
Pattern pattern = Pattern.compile(caseInsensitiveRegex);
Matcher m = pattern.matcher(stringBuilder);
while (m.find()){
// Do some stuff
}
}
Thanks per advance for your help ;)
is only available from Android API 9
Android is open sourced project. There's nothing preventing you from grabbing that part of API 9 and putting directly in your app so you will no longer be API dependent and I at the moment I am not seeing any obstacles for doing this in your case.

error in reading g-data

From different post i have concluded that insertion, deletion and updation in Calendar is only possible by using g-data.
Therefore i am using g-data 1.41.3 with android 1.5 api level 3.
Problem is that , i am using the following code.
1 // Send the request and receive the response:
2 // the code is use for reading Calendar Content
3 // feedUrl = http://209.85.132.104/calendar/feeds/androidshma#gmail.com/allcalendars/full
4
5 CalendarFeed resultFeed = service.getFeed(feedUrl, CalendarFeed.class);
6
7 // Print the title of each calendar
8 for (int i = 0; i < resultFeed.getEntries().size(); i++) {
9 CalendarEntry entry = resultFeed.getEntries().get(i);
10 System.out.println("\t" + entry.getTitle().getPlainText());
11 }
problem is that application throwing exception on line no. 5.
Exception is as follow:
java.lang.VerifyError: com.google.gdata.util.common.xml.parsing.SecureGenericXMLFactory$SecureSAXParserFactory
and in different forum it is mention that No XSchema support in Android 1.0. Maybe later version.
how i can read calendar contents?
it is noted that without android its working fine.
till now gdata not supported on android.
http://code.google.com/p/android-gdata/
no g data libraries available.

CloudMade + Android

Good afternoon,
i write in order to ask a question about the use of the API KEY. I'm developing an application for Android, so i use the service provided for www.nutiteq.com for using the api maps.
But the problem is the following:
when i use the code proposed by nutiteq:
mapComponent = new BasicMapComponent("115f89503138416a242f40fb7d7f338e4b73e583e8e343.19717285",
"TouristEye", "TouristEye", 1, 1,
new WgsPoint(mCenter.getLong(), mCenter.getLat()), 10);
mapComponent.setMap(new CloudMade(" 24c1c76c612248f7acd23978088bfb3a", 64, 1));
the API Key i ask for Cloud Made doesn't work correctly and i can't use the maps. I selected mobile use when i get the Api key and have passed more than hour since i asked for it.
Hope you can help me.
public CloudMade(java.lang.String licenseKey,
java.lang.String userid,
int tileSize,
int mapLayout)
You must add your userid after your licenseKey.
bye

Categories

Resources