Feature click listener issue android GeoJsonLayer - android

Hello I'm working with google map android api and I'm using google maps android geojson utility. I'm adding 3 layers of geojson into the map only the road_layer(LineString) have feature click event. The click event is working fine until I'm adding the samsad_boundary_layer(Polygon). The issue is if the samsad_boundary_layer feature is clicked it's triggering the road_layer feature click event although the layer(samsad_boundary_layer) have no feature click event.
private void showBoundery(){
try {
samsad_boundary_layer=new GeoJsonLayer(mMap,R.raw.samsad_boundary,MapActivity.this); //1st Layer
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
samsad_boundary_layer.getDefaultPolygonStyle().setZIndex(-12f);
GeoJsonPolygonStyle polygonStyle=samsad_boundary_layer.getDefaultPolygonStyle();
polygonStyle.setStrokeWidth(5f);
polygonStyle.setStrokeColor(getResources().getColor(R.color.purple));
samsad_boundary_layer.addLayerToMap();
}
private void retrieveFileFromResource() {
try {
temp_layer=new GeoJsonLayer(mMap,R.raw.area_survey,this); //2nd Layer
temp_layer.addLayerToMap();
road_layer=new GeoJsonLayer(mMap,R.raw.road_survey,this); //3rd Layer
road_layer.setOnFeatureClickListener(new Layer.OnFeatureClickListener() {
#Override
public void onFeatureClick(Feature feature) {
if (feature!=null){
Iterator<HashMap> flavoursIter = feature.getProperties().iterator();
while (flavoursIter.hasNext()){
Map.Entry entry = (Map.Entry)flavoursIter.next();
//Log.v("SURVEYOR_FEATURE",entry.getKey().toString()+":"+entry.getValue());
}
}
}
});
GeoJsonLineStringStyle lineStyle=road_layer.getDefaultLineStringStyle();
lineStyle.setZIndex(10f);
lineStyle.setWidth(2f);
lineStyle.setColor(getResources().getColor(R.color.light_green));
road_layer.addLayerToMap();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}

Instead of adding 3 layers on map separately, traverse through all and create single layer.
Then add layer to map and set feature click listener. Handle onFeatureClick accordingly.

Related

How to customize the pop up message content (I want to customize according to the app's language(my app contains multiple language))

I have implemented In-app updates to notify user when new version is available using this library, https://developer.android.com/guide/playcore/in-app-updates
mAppUpdateManager = AppUpdateManagerFactory.create(this);
mAppUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
#Override
public void onSuccess(AppUpdateInfo appUpdateInfo) {
if(appUpdateInfo.updateAvailability()==UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE))
{
try {
mAppUpdateManager.startUpdateFlowForResult(appUpdateInfo,AppUpdateType.FLEXIBLE,MainActivity.this,RC_APP_UPDATE);
} catch (IntentSender.SendIntentException e) {
throw new RuntimeException(e);
}
}
}
});
By default, when an update is available, it shows pop up message and gets updated as expected but, I want to change the language and message content(not update XXX?? XXX recommends that you *****) so that I can change the message contents according to the language of user(my app supports multiple language selections)
Thank you.
mAppUpdateManager = AppUpdateManagerFactory.create(this); mAppUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() { #Override public void onSuccess(AppUpdateInfo appUpdateInfo) { if(appUpdateInfo.updateAvailability()==UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) { try { mAppUpdateManager.startUpdateFlowForResult(appUpdateInfo,AppUpdateType.FLEXIBLE,MainActivity.this,RC_APP_UPDATE); } catch (IntentSender.SendIntentException e) { throw new RuntimeException(e); } } } });
I tried this according to the official website and other articles too but, couldn't find the way to customize it.

Dropbox Synchronous interrupts

In my Android app, when the following code is successful:
mDbxAcctMgr.startLink(SyncActivity.this,REQUEST_LINK_TO_DBX);
This code runs:
if (ds.getSyncStatus().hasIncoming) {
try {
Map<String, Set<DbxRecord>> mMap = mDatastore
.sync();
dataHasIncoming(mMap); // Inserted into the database
} catch (DbxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
If you close the app while this is occurring, dataHasIncoming(mMap) just inserts part of the data, but loses the rest. Is there any way around this, such as setting a node, or re-opening the synchronization without checking all the data?

how to create the camera object that other apps also use the camera when my app also running?

I am doing a project related to live wallpaper, in that camera was set as wallpaper, so in my app camera was running continuously, if user set camera as wallpaper, after he opening the camera it will shows the camera failed to load error,
so, i am using the following code to avoid this error:
public void onVisibilityChanged(boolean visible) {
if (visible){
try {
mCamera.reconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else{
try {
mCamera.unlock();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
But my problem is could not unlock the camera object to other apps use the camera.
can any one give me an idea how can i do this?
You cannot access the object used by the native camera app or other apps to access camera. When you create mCamera, you are creating your own object which is used by your app. At a time, only one object can access a particular camera resource, and you have no control over other objects of other apps accessing that camera resource.
If you want avoid the failed to load error, you need to release your camera object before you open another app which uses camera resource. But then I do not think your main objective will be accomplished.
I am using same method with small modifications to solve the issue, i was doing following changes in the code
public void onVisibilityChanged(boolean visible) {
// TODO Auto-generated method stub
super.onVisibilityChanged(visible);
if (visible) {
try {
"open camera object"
}catch (Exception e) {
e.printStackTrace();
}
}else {
try {
"release the camera object"
}catch (RuntimeException e) {
e.printStackTrace();
}
}
}

how can i share my comments in googleplus by using addthis

i tried out its not working anyone can help me out
public void googlefunc(View v)
{
try {
AddThis.shareItem(this, "googleplus", mUrl, mShareTitle,
mShareDescription);
}
catch (ATDatabaseException e) {
e.printStackTrace();
}
catch (ATSharerException e) {
e.printStackTrace();
}
}
You have to use google_plusone (or google_plusone_share) instead of googleplus.
See the list of the available service (and search for google_plusone to find the right row).

How can I enable NFC reader via API?

There is any way I can enable Android NFC reader using API?
So apparently there is no way to enable the NFC from the API, even though Google does so within their source code (see below).
If you look at a line from the API for NfcAdapter.isEnabled():
Return true if this NFC Adapter has
any features enabled.
Application may use this as a helper
to suggest that the user should turn
on NFC in Settings.
If this method returns false, the NFC
hardware is guaranteed not to generate
or respond to any NFC transactions.
It looks like there is no way to do it within the API. Bummer. Your best bet is a dialog to inform the user they need to enable it in the settings, and perhaps launch a settings intent.
EDIT: The following is from the source, but it looks like they didn't allow the user to implement the methods in the API (I'm confused about this).
I found this from the android source code to help enable and disable the adapter.
Relevant source:
public boolean onPreferenceChange(Preference preference,
Object value) {
// Turn NFC on/off
final boolean desiredState = (Boolean) value;
mCheckbox.setEnabled(false);
// Start async update of the NFC adapter state, as the API is
// unfortunately blocking...
new Thread("toggleNFC") {
public void run() {
Log.d(TAG, "Setting NFC enabled state to: "
+ desiredState);
boolean success = false;
if (desiredState) {
success = mNfcAdapter.enable();
} else {
success = mNfcAdapter.disable();
}
if (success) {
Log.d(TAG,
"Successfully changed NFC enabled state to "
+ desiredState);
mHandler.post(new Runnable() {
public void run() {
handleNfcStateChanged(desiredState);
}
});
} else {
Log.w(TAG, "Error setting NFC enabled state to "
+ desiredState);
mHandler.post(new Runnable() {
public void run() {
mCheckbox.setEnabled(true);
mCheckbox
.setSummary(R.string.nfc_toggle_error);
}
});
}
}
}.start();
return false;
}
I got it working through reflection
This code works on API 15, haven't checked it against other verions yet
public boolean changeNfcEnabled(Context context, boolean enabled) {
// Turn NFC on/off
final boolean desiredState = enabled;
mNfcAdapter = NfcAdapter.getDefaultAdapter(context);
if (mNfcAdapter == null) {
// NFC is not supported
return false;
}
new Thread("toggleNFC") {
public void run() {
Log.d(TAG, "Setting NFC enabled state to: " + desiredState);
boolean success = false;
Class<?> NfcManagerClass;
Method setNfcEnabled, setNfcDisabled;
boolean Nfc;
if (desiredState) {
try {
NfcManagerClass = Class.forName(mNfcAdapter.getClass().getName());
setNfcEnabled = NfcManagerClass.getDeclaredMethod("enable");
setNfcEnabled.setAccessible(true);
Nfc = (Boolean) setNfcEnabled.invoke(mNfcAdapter);
success = Nfc;
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
} else {
try {
NfcManagerClass = Class.forName(mNfcAdapter.getClass().getName());
setNfcDisabled = NfcManagerClass.getDeclaredMethod("disable");
setNfcDisabled.setAccessible(true);
Nfc = (Boolean) setNfcDisabled.invoke(mNfcAdapter);
success = Nfc;
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
if (success) {
Log.d(TAG, "Successfully changed NFC enabled state to "+ desiredState);
} else {
Log.w(TAG, "Error setting NFC enabled state to "+ desiredState);
}
}
}.start();
return false;
}//end method
This requires 2 permissions though, put them in the manifest:
<!-- change NFC status toggle -->
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
The NFC button's state switches accordingly when the code is used, so there are no issues when doing it manually in the seetings menu.
If you can see the NfcService Application Source Code, there is a Interface file INfcAdapter.aidl. In the file two API's are there namely "boolean enable()" and "boolean disable()". You can directly use this API's to enable and disable NfcService through an android application. But the trick over here is that you can not compile the code using SDK provided by the Android. You have to compile the application using the a makefile. I have successfully build a application.
I hope this forum would be help you to resolve this issue as well to get the clear understanding on the NFC power on/off API barries.
http://ranjithdroid.blogspot.com/2015/11/turn-onoff-android-nfc-by.html

Categories

Resources