Search Results are in english though Search Language set to german - android

I am doing offline geocoding with skobbler sdk. I use the offline map for Germany and I am searching for States within Germany. I have set the search language to German. As an example I am looking for "Niedersachsen". Passing the first few letters, e.g. "Nie" makes the SearchManager find "Niedersachsen" but in the skSearchResult variable the name is "Lower Saxony". So the correct State is found but in the wrong language(english instead of german). How can I solve this? Here is my piece of codes which does the search:
public class AddressSearchListener implements SKSearchListener {
// current list level at which to search
private String mapPackageName;
private AddressSearchFragment addressSearchFragment;
public AddressSearchListener() {
Log.d("AddressSearchListener", "begin");
this.mapPackageName = "DE";
}
public void setFragment(AddressSearchFragment addressSearchFragment) {
this.addressSearchFragment = addressSearchFragment;
}
public void startSearch(long parentId, SKSearchManager.SKListLevel searchLevel, String s) {
Log.d("AddressSearchListener", "startSearch begin");
// get a search manager object
SKSearchManager mgr = new SKSearchManager(this);
// get a multi-step search object
SKMultiStepSearchSettings searchSettings = new SKMultiStepSearchSettings();
searchSettings.setSearchLanguage(SKMaps.SKLanguage.LANGUAGE_DE);
// set the offline package in which to search
// the France package in this case needs to be installed
searchSettings.setOfflinePackageCode(mapPackageName);
// set list level of the search
searchSettings.setListLevel(searchLevel);
// set maximum number of results to be received
searchSettings.setMaxSearchResultsNumber(20);
// set the id of the parent in which to search
searchSettings.setParentIndex(parentId);
// set a filter for the results
searchSettings.setSearchTerm(s);
// initiate the search
Log.d("AddressSearchListener", "startSearch time " + System.currentTimeMillis());
mgr.multistepSearch(searchSettings);
}
#Override
public void onReceivedSearchResults(List<SKSearchResult> skSearchResults) {
Log.d(getClass().getName(), "onReceivedSearchResults begin");
Log.d("AddressSearchListener", "onReceivedSearchResults time " + System.currentTimeMillis());
List<AddressSearchResultMeta> addressSearchResults = new ArrayList<AddressSearchResultMeta>();
for (SKSearchResult skSearchResult : skSearchResults) {
Log.d("onReceivedSearchResults", "result: " + skSearchResult);
AddressSearchResultMeta addressSearchResultMeta = new AddressSearchResultMeta(skSearchResult);
addressSearchResults.add(addressSearchResultMeta);
}
addressSearchFragment.passResults(addressSearchResults);
}
}

The issue was just a bug within Skobbler SDK. It is fixed in version 2.5.1.

Related

My current location is not clear in Google map Android

I use Google map in my app. I try to get my current location I can show my location but the point is not clear. I don't Know what is problem .
As you can see picture below.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatches {
public static void main(String args[]) {
// String to be scanned to find the pattern.
String line = "This order was placed for QT3000! OK?";
String pattern = "(.*)(\\d+)(.*)";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(line);
if (m.find()) {
System.out.println("Found value: " + m.group(0));
System.out.println("Found value: " + m.group(1));
System.out.println("Found value: " + m.group(2));
} else {
System.out.println("NO MATCH");
}
}
}
Anyone know solution that ?
Your current location will not work correctly in emulator. Current location is not showing in my android app You should try it in actual device to get correct result. For focus in or out you may use this code:
mMap.addMarker(MarkerOptions().position(mylocation).title("My Location"))
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mylocation, 14f))
You can change 14f to what you want.

Android. Espresso. How to check that text is shown in a specific language without hard code strings?

I need to check my fragment when I change the app language.
Here is my Android Espresso test:
#Test
public void changeLanguages() {
Resources resources = context.getResources();
String[] appLanguages = resources.getStringArray(R.array.app_lang_codes);
for (int index = 0; index < appLanguages.length; index++) {
String currentLang = appLanguages[index];
Locale currentLocale = new Locale(currentLang);
if (currentLocale.equals(AppLanguageService.getLocaleRO(context))) {
// click Romanian
onView(withId(R.id.containerLanguageRO)).perform(click());
onView(withId(R.id.textViewSelectLanguage)).check(matches(withText("Selecți limba")));
} else if (currentLocale.equals(AppLanguageService.getLocaleEN(context))) {
// click English
onView(withId(R.id.containerLanguageEN)).perform(click());
onView(withId(R.id.textViewSelectLanguage)).check(matches(withText("Select language")));
}
}
}
Ant it's working fine. OK!
But as you can see I need to hard code the string for a specific language for the test.
"Selecți limba" and "Select language". And I think it's not good.
Is it possible to not use hard code strings to check that text is shown in a specific language?
You can use
mActivityRule.getActivity()
to get the activity you are testing. With this you could fetch a string from your resources like this:
mActivityRule.getActivity().getResources().getString(R.string.your_string)
You could rewrite your check like this:
onView(withId(R.id.textViewSelectLanguage)).check(matches(withText(mActivityRule.getActivity().getResources().getString(R.string.your_string))));
where your_string is the name of your string resource in your strings.xml files.

Check all TextViews in an Activity

I was wondering if it is possible to run a check against all the TextViews in an Activity/View and make ones which don't have any content in them invisible? I don't really want to wrap a if statement around each of the TextViews when setting text.
I currently have an activity that will populate a range of TextViews with content from a Database. However there is a chance that some fields in the database will not have any content and to keep a clean UI I want to simply make these fields invisible instead of them just sitting blank.
Here is where I am setting the content:
public void settingContent() {
eventTitle.setText(event.EventTitle);
eventLocation.setText(event.SiteName);
organiser.setText(event.Organiser);
eventType.setText(event.setEventTitle());
DateFormatter dateFormatter = new DateFormatter();
String startDate = dateFormatter.getFormattedDate(event.StartDateTime);
String endDate = dateFormatter.getFormattedDate(event.CloseDateTime);
String eventDates = startDate + " - " + endDate;
dates.setText(eventDates);
cost.setText(event.FeeDetails);
bookingContact.setText(event.BookingContactName);
stewardContact.setText(event.StewardContactName);
unitTypes.setText(event.MaxUnits);
mapReference.setText(event.MapReference);
eventNumber.setText(event.EventNumber);
otherInformation.setText(event.OtherInformation);
directions.setText(event.SiteRouting);
if(event.isTempHoliday()) {
eventIcon.setImageResource(R.drawable.icon_holidaysites_card);
} else {
eventIcon.setImageResource(R.drawable.icon_clubmeets_card);
}
}
So is this possible or is it a case of just having to check each individual TextView before setting?
List<TextView> lstTexts = new ArrayList<TextView>();
lstTexts.add(cost);
lstTexts.add(bookingContact);
lstTexts.add(stewardContact);
lstTexts.add(unitTypes);
lstTexts.add(mapReference);
lstTexts.add(eventNumber);
lstTexts.add(otherInformation);
lstTexts.add(directions);
//then you can run this method
boolean empty = checkAllTV(lstTexts);
This is the method for it.
public boolean checkAllTV(List<TextView> allTV){
for(TextView tv : allTV){
if(tv.getText().toString().equals("")||tv.getText().toString()==null)
return false;
}
return true;
}
I am on Mobile so I am not able to check the code! but you can get the idea.
Hope it Helps.

how to get current player rank in openfeint in android app

In my android app i m using open feint and i m facing problem in getting my rank(current player).
how do i get that.here is my code.
//hard coded for example
long scoreValue = 60;
Score s = new Score(scoreValue, null);
Leaderboard l = new Leaderboard(String.valueOf(HomeScreen.LeaderBoardId));
s.submitTo(l, new Score.SubmitToCB() {
#Override
public void onSuccess(boolean newHighScore) {
System.out.println("Score submitted successfully");
}
#Override
public void onFailure(String exceptionMessage) {
Toast.makeText(GameScreen.this,
"Error (" + exceptionMessage + ") posting score.",
Toast.LENGTH_SHORT).show();
}
});
User u= OpenFeint.getCurrentUser();
int rank=s.rank;
System.out.println("RANK"+rank);
i can get the user details but i dont know how do i get my rank. i m stuck.please help.
thanks in advance.
Rank is not set when you submit a score. See this discussion for details.
You have to use the leaderboard to get the rank.
Also openfient is being replaced with GREE, so if you are just starting you may want to switch to the new platform.

Detecting "use only 2G networks" setting

Is there a way of returning the value of Android's mobile network setting for "use only 2G networks"?
The app being developed measures the internet speed at a certain location, but in order for this to be relevant, it must know if the user is deliberately restricting mobile internet to 2G.
I've taken a look at ConnectivityManager, but it only provides information about the background data setting or all networks. Iterating through them reveals that despite the setting being enabled, HSPA and UMTS return true for isAvailable():
for (NetworkInfo netInfo : cm.getAllNetworkInfo()) {
Log.i(TAG, netInfo.getSubtypeName() + ": " + netInfo.isAvailable());
}
The only hint I've found amidst all this is that netInfo.getReason() returns "connectionDisabled" on HSPA and UMTS when the setting is enabled. The trouble is, when the setting is disabled, those network types don't necessarily appear in the list at all. It doesn't seem right to me to use a string comparison specifically on HSPA and UMTS for "connectionDisabled".
What's the right way of tackling this?
For a small subset of devices (specifically for the LG Optimus 2X Speed, LG-P990), an answer seems to be:
int enabled = Settings.Secure.getInt(getContentResolver(),
"preferred_network_mode", -1);
Log.d("MYAPP", "2G only enabled: " + enabled);
Where the "use only 2G networks" setting is specified as:
0 indicates the setting is disabled
1 indicates the setting is enabled
-1 indicates the setting is not set (some devices?)
How I discovered this? I gathered all the key/value pairs from Settings.Secure using the following:
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(Settings.Secure.CONTENT_URI, null, null, null, null);
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
Log.d("MYAPP", "cursor: "
+ cursor.getString(0) + ", "
+ cursor.getString(1) + ", "
+ cursor.getString(2));
cursor.moveToNext();
}
}
I compared results between enabling and disabling the setting, and sure enough I got:
07-08 00:15:20.991: DEBUG/MYAPP(13813): cursor: 5154, preferred_network_mode, 1
Do NOT use the index column (5154 in the example above), as I've noticed it changes between toggling the setting.
Although this correlates with some documentation for Settings.Secure I found online, this value isn't respected by all phones.
If your device returns -1, perhaps listing the key value pairs will reveal which setting you need. Please comment if you encounter it!
As far as I can tell, there is no documented way of getting value for that setting. But there is a Use2GOnlyCheckBoxPreference class that can be used as an example. It uses internal Phone and PhoneFactory classes to obtain the current value of prefer_2g setting.
You can use Phone and PhoneFactory classes via reflection. But of cause this is undocumented and is on your own risk. Here is relevant code from Use2GOnlyCheckBoxPreference:
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
public class Use2GOnlyCheckBoxPreference extends CheckBoxPreference {
private Phone mPhone;
private MyHandler mHandler;
public Use2GOnlyCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mPhone = PhoneFactory.getDefaultPhone();
mHandler = new MyHandler();
mPhone.getPreferredNetworkType(
mHandler.obtainMessage(MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE));
}
private class MyHandler extends Handler {
private static final int MESSAGE_GET_PREFERRED_NETWORK_TYPE = 0;
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_GET_PREFERRED_NETWORK_TYPE:
handleGetPreferredNetworkTypeResponse(msg);
break;
}
}
private void handleGetPreferredNetworkTypeResponse(Message msg) {
AsyncResult ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
int type = ((int[])ar.result)[0];
Log.i(LOG_TAG, "get preferred network type="+type);
setChecked(type == Phone.NT_MODE_GSM_ONLY);
} else {
// Weird state, disable the setting
Log.i(LOG_TAG, "get preferred network type, exception="+ar.exception);
setEnabled(false);
}
}
}
}

Categories

Resources