I had created a demo app to known about SKMaps, it worked good with adding annotations. However, now I have moved the code to actual project with the same requirements. Added annotations is not being displayed. I tried with both SKAnnotationView (custom view) and default Annotation type like SKAnnotation.SK_ANNOTATION_TYPE_RED and SKAnnotation.SK_ANNOTATION_TYPE_PURPLE. Nothing is being added to the map.
I have a custom view pager in the same screen, I removed the same and checked still didn't work. SKMapViewHolder is added dynamically.
Code snippet for adding SKMapViewHolder dynamically:
SKMapViewHolder mMapHolder = new SKMapViewHolder(OfflineMapScreen.this);
mMapHolder.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
RelativeLayout outerLayout = (RelativeLayout) findViewById(R.id.outer_layout);
outerLayout.addView(mMapHolder);
RelativeLayout.LayoutParams rlp = (android.widget.RelativeLayout.LayoutParams) mMapHolder.getLayoutParams();
rlp.addRule(RelativeLayout.BELOW, R.id.header);
mMapHolder.setLayoutParams(rlp);
mOSMMapView = mMapHolder.getMapSurfaceView();
mOSMMapView.setMapSurfaceListener(this);
mOSMMapView.getMapSettings().setFollowerMode(SKMapFollowerMode.NONE);
mOSMMapView.getMapSettings().setMapPanningEnabled(true);
mOSMMapView.getMapSettings().setInertiaPanningEnabled(true);
mOSMMapView.getMapSettings().setCompassShown(false);
mOSMMapView.getMapSettings().setCurrentPositionShown(false);
mOSMMapView.setZoomSmooth(14f, 500);
Anybody has the solution for this? Code snippet of adding annotations can be seen here: http://postimg.org/image/sdbwzej9z/
In the image you provided we have noticed that when setting the location you are reusing the same value for both latitude and longitude. Use something like:
annotationDrawable.setLocation(new SKCoordinate(Double.valueOf(aPlace.getLongitude()),Double.valueOf(aPlace.getLatitude())) ;
I have to modify the image of a SKAnnotation.
Annotation builder code:
private SKAnnotation getAnnotationFromView (int id,int minZoomLvl, View view) {
SKAnnotation annotation = new SKAnnotation();
SKAnnotationView annotationView = new SKAnnotationView();
annotationView.setView(view);
annotation.setUniqueID(id);
annotation.setOffset(new SKScreenPoint(annotationView.getWidth()/2, annotationView.getHeight()/2));
annotation.setAnnotationView(annotationView);
annotation.setMininumZoomLevel(minZoomLvl);
return annotation;
}
Now my problem is to update the annotation/image to the current state (position, orientation). Is there a way doing that without re adding the annotation? Looking into the documentation I found mapView.updateAnnotation() but it seems to work just for images added with annotation.setImagePath(imagePath)
Can someone help me with that?
Unfortunately no.
There is an inconsistency in the implementation (we'll address that in a future update) that allows one to reposition only annotations with the icon taken from an file.
If you'd like to reposition an (any) annotation you could/should remove it and add it again.
If you'd like to change the icon/view - then the updateAnnotation API should do the job
A detailed explanation of issue can be understood from this question as the user had added image to explain it better.
I am loading Html content in my WebView. My layout is having many view and WebView is place inside ScrollView(as per layout requirement). Please don't answer as - "Don't put WebView inside ScrollView". I know that its not a good thing to put WebView inside a ScrollView, but as per requirement I need to do so.
So, I have Left Fragment(showing List Items) and Right Fragment(Showing data reflected on selection of List Item from Left Fragment). Now, first of all when I load Html content inside WebV it shows correct. After that when I refresh WebView with new Html content the problem occurs.
Suppose, my first Html content is of 100 lines it shows correctly and then I reload WebView with my new Html content which is of 40 lines then the WebView is not shrinking and fitting to the content with 40 lines, it still remains as long as 100 lines showing white/blank space at the bottom.
So, it seems that WebView is able to re-size itself from less content which is previously loaded to more content but unable to re-size itself when the content is less than previously loaded content.
I had tried many ways,
Adding android:hardwareAccelerated="true" in Manifest
This Blog
Also many other ways and blog
Also I had tried to use mWebView.clearView(); which causes to re-size the size of WebView but at times the WebView start blinking which is just annoying. Similar to this video
But, couldn't find any proper solution. If anyone of you have the same issue before just let me know the best solution I could apply.
UPDATE -
After further googling it seems that this is a well-known issue in Honeycomb. This question also indicates the similar issue.
Seems there's no way to resize the WebView(decrease) its size dynamically once its loaded. So, the only thing that could solve my problem was reloading the complete WebView.
So, instead of defining the Fragment in XML, I changed my stuff by adding Fragment dynamically every time. By which I was able to solve my issue.
This is a known problem with WebView and some available solution doesn't work in all the devices.
I tried many solution given in SO answers and also searched over the internet but none of them worked for me too.
I ended up , removing the WebView and adding the WebView again at the same position in in Layout
Here is that demo code,
final RelativeLayout rl = new RelativeLayout(this);
myWebView = new WebView(this);
myWebView.setBackgroundColor(Color.GRAY);
myWebView.loadUrl("file:///android_asset/1.htm");
rl.addView(myWebView); // ******* Added At Index 0
Button btn = new Button(this);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (!flg) {
rl.removeViewAt(0);
myWebView = new WebView(MainActivity.this);
myWebView.setBackgroundColor(Color.GRAY);
myWebView.loadUrl("file:///android_asset/3.htm");
rl.addView(myWebView, 0, new RelativeLayout.LayoutParams(
new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT)));
flg = true;
} else {
rl.removeViewAt(0);
myWebView = new WebView(MainActivity.this);
myWebView.setBackgroundColor(Color.GRAY);
myWebView.loadUrl("file:///android_asset/1.htm");
rl.addView(myWebView, 0, new RelativeLayout.LayoutParams(
new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT)));
flg = false;
}
}
});
rl.addView(btn); // ******* Added At Index 1
setContentView(rl);
guys, it seems I found a solution for local content. You should just call webView.reload() before loading new content - somehow it does the resizing without any blinking.
Here I have changed the height of webview depending of softkeyboard display
activityRootView = (RelativeLayout) findViewById(R.id.webview1);
mWebView = (WebViewEx) WebViewActivity.this.findViewById(R.id.webview);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if(heightDiff != lastValue) {
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
Log.i("Screen Size Changed","KeyBoard Displaying"+ r.bottom);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.height=r.bottom;
mWebView.setLayoutParams(params);
//appView.sendJavascript("onKeyBoardShow(" + r.bottom + ");");
} else {
/// appView.sendJavascript("onKeyBoardHide();");
Log.i("Screen Size Changed","KeyBoard not displaying" +r.bottom);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.height=r.bottom;
mWebView.setLayoutParams(params);
}
lastValue = heightDiff;
}
}
});
i have not tried but why dont you give a try by setting weblayout params again, before u load the new contents. ie set height and width to wrapcontent. if success found please reply. if wont find success better go for javascipt
I set the visibility of my WebView to Gone, and load the content into the WebView while it's gone. Then I set the visibility to visible after letting the DOM and JS load and it seems to draw the length correctly. Since there isn't a callback like onPageFinished for determining when the JS has finished executing, I give the WebView a one second delay before I set the visibility to true. This workaround suffices for my purposes, so hopefully it addresses the needs of some of you guys!
Everytime creating an object of webview and give its param is a pain instead you can do following steps and it will work
put a blank html file in assets folder and give it a name
empty.html
call webview.loadUrl("file:///android_asset/empty.html");
now load your content.
Webview will shrink its height.
Make sure you are not putting any content in empty.html
This do the magic! It says
Android property: android:layout_weight = "1 in the layout should work...
In my case, WebView is in the RelativeLayout. So doing thi android:layout_height="wrap_content" worked like a charm :)
As #Ankit pointed out, go to an empty page could help. "about:blank" is better, though.
Today I noticed a very strange bug - the system used the wrong ResId in the method SetBackgroundResource(). Sure I thought it was my mistake. I fixed the ResId by copying and pasting it from the R file. After I've re-installed the app many times for testing I noticed that a wrong image was set again so it messed up my app. I went to the corresponding method and found out that Eclipse inserted a very similar (but wrong! ..015 instead of ..016) ResId as a method parameter without any actions from me.
I don't think that's important but this strange thing always happens here:
LinearLayout nlap = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(10, 5, 10, 0);
nlap.setLayoutParams(params);
nlap.setOrientation(LinearLayout.HORIZONTAL);
nlap.setBackgroundResource(0x7f020016);
nlap.getBackground().setAlpha(111);
return nlap;
Just clean all your related projects and build again.
Never hard-code a R.id.
I've seen this before: With old versions of ADT and library projects this would sometimes happen. Haven't seen it with ADT 21.
Recently, for me, Eclipse has started underlining R.id's red as if they are wrong or unknown, but they do not show up in the Problems view, and they are not actually wrong. I'm still looking for a bug report for this.
I am trying to use native components in a LWUIT app on Android platform.
private Component createNativeTextEdit() {
final Object[] result = new Object[1];
AndroidImplementation.runOnAndroidUIThreadAndWait(LWUITActivity.currentActivity, new Runnable() {
#Override
public void run() {
EditText nativeView = new EditText(LWUITActivity.currentActivity);
nativeView.setText("Type here..");
result[0] = PeerComponent.create(nativeView);
}
});
return (Component)result[0];
}
I then place a component inside a form:
mMainForm = new Form();
mMainForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
mMainForm.addComponent(createNativeTextEdit());
mMainForm.show();
Then I get an "IllegalArgumentException: width and height must be > 0" when the system tries to draw the new form.
I traced the problem down to the call to AndroidImplementation.PeerWrapper.getBuffer() and the values returned by getWidth() and getHeight() are width=474 and height=0.
How is height supposed to be set? What am I missing?
Do you know of a working sample program that uses PeerComponent on Android? I searched the web but could only find some snippets where it is not clear where the code is called from, which thread it is executed on etc.
Thanks.
I figured out the issue.
I am using LWUIT 1.5 thorsten_s port for Android.
The issue is that LWUIT computes components preferred size before the native view is added so both width and height are set to 0.
The way to fix it is to call View.measure() on the PeerWrapper at creation time to initialize it to preferred size.
Inside AndroidImplementation.java at the end of the constructor for PeerWrapper class add the line:
measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
This completely fixes the problem. I can now use components like AnalogClock, DatePicker, and native EditText in LWUIT forms.
This sort of thing works for us in the Codename One implementation. I'm not exactly sure what is happening in Thorsten's port since we are pretty much forked by now. We intend to release Codename One with a native access demo that will demonstrate access to native widgets.