I need to create a floorplan which can be scrolled and zoomed.Some sections of this plan shall be linked to other activities (ie. kitchen). My idea was to lay a simple button on the kitchen-region. With a click on it you can get to the kitchen activity.
Because of scrolling- and zooming-requirement I created a WebView containing my floorplan:
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".FloorplanActivity"
xmlns:android="http://schemas.android.com/apk/res/android">
<WebView
android:id="#+id/webViewFloorplan"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<Button
android:id="#+id/buttonKuehltheke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</WebView>
</LinearLayout>
But now I'm not able to lay a button on a specific region on the floorplan. The Button always appears in upper left corner of my floorplan.
MainActivity-Code:
WebView wvFloorplan = (WebView) findViewById(R.id.webViewFloorplan);
wvFloorplan.getSettings().setBuiltInZoomControls(true);
wvFloorplan.loadUrl("file:///android_asset/services_plan.png");
What needs to be done to set the button to every postition on my WebView (Floorplan)?
Thx Arne
If you are going to be scrolling and zooming this WebView, the coordinates for the kitchen section are going to be dynamic, so positioning a button over it will be difficult.
I would suggest overriding WebView.shouldOverrideUrlLoading. This way you can use html to create a link to the kitchen activity.
wvFloorplan.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("act:")) {
Intent intent = new Intent( <kitchen activity> );
startActivity(intent);
return true;
}
return false;
}
});
You will have to write an html wrapper around the image to map parts of your images to different links but now the coordinates will be static. Instead of http urls use Href="act:kitchen"
Related
I have one WebView which has a RelativeLayout parent.
in WebView when i click on some specific button, it loads another url. i want to disable keyboard on that url. and that url i got in shouldoverrideurlloading(WebView view , Url Url) method.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context="com.xenopsi.benchmark.BrowserActivity">
<WebView
android:id="#+id/browserView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:scrollbars="none"/>
</RelativeLayout>
On that method i did:
relativeLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
webView.setFocusable(false);
webView.setFocusableInTouchMode(true);
but still when i tap on text field of that page , keyboard still shown.
if i did same code on onCreate() method of activity, its work fine,
but my problem is want to disable it on shouldOverrideUrlLoading method when my page load.
Okey as you mention you want to hide keyboard for particular link, do something like this,
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.e("Loading URL", url);
view.loadUrl(url);
if(url.equals(yourUrl)){
// hide keyboard
} else {
// unhide keyboard
}
return true;
}
I hope this will Help..
Happy Coding..
I am developing an Android offline mapping application using osmdroid and osm bonus pack and loading the tiles and data from external storage. Right now, as the data grows, markers are starting to get cramped together, I even have the situation of two places on the same building. I know this kind of issue has been asked a lot before, mine is about a simple temporal workaround I'm thinking of implementing. How about if two places are near enough(right in top of each other!) the standard info window pops up as a ListView with each row designed like the standard bubble(image, title, moreInfoButton).
My question is: some thoughts or advices on how to create the new bonuspack_bubble.xml layout file.
I don't know if this will help you.
I needed to create a CustomInfoBubble for my project. What I did was, to extend the InfoWindow default class, and pass to it my custom bubble layout. Something like this:
http://mobiledevstories.wordpress.com/2014/03/01/osmdroid-bonus-pack-markers-with-clickable-infowindows/
My Java class MapCustomInfoBubble looks like this:
public class MapCustomInfoBubble extends InfoWindow {
public MapCustomInfoBubble(MapView mapView) {
super(R.layout.map_infobubble_black, mapView);//my custom layout and my mapView
}
#Override
public void onClose() {
//by default, do nothing
}
#Override
public void onOpen(Object item) {
Marker marker = (Marker)item; //the marker on which you click to open the bubble
String title = marker.getTitle();
if (title == null)
title = "";
Button moreInfo = (Button)mView.findViewById(R.id.bubble_moreinfo);//the button that I have in my XML;
moreInfo.setText(title);
moreInfo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
gotoMoreInfoWindow();//custom method; starts another activity
}
});
}
}
In my XML file, I have:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/map_infobubble_black" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView android:id="#+id/bubble_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:maxEms="17"
android:layout_gravity="left"
android:layout_weight="1"
android:text="Title" />
<Button android:id="#+id/bubble_moreinfo"
android:background="#drawable/map_btn_moreinfo"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="0" />
</LinearLayout>
</LinearLayout>
Somewhere else in my code, I then use:
Marker wp = new Marker(mapView);
wp.setPosition(new GeoPoint(mylocation.getMyLocation()));
wp.setTitle(editTextName.getText().toString());
wp.setInfoWindow(new MapCustomInfoBubble(mapView));
mapView.getOverlays().add(wp);
mapView.invalidate();
In my code, I set the text on the button with the Marker's title.
The Marker is the item on which I click. If you want to put info about more markers in the same InfoWindow (inside a ListView), I think you would need to know in advance what the info will be.
I believe that, You can put whatever code you want inside onOpen(), however, I am not so sure if it's a good practice. You could try creating a custom Constructor and put your logic there. It should work.
You need to pass the Resource Id (layout) and mapView to the super constructor, so it returns a valid mView object.
It's a simple app I've got and I'd like the button I've made to launch a specific URL via the browser. Could you guys give me a little info to get this going, like I've said I've got the button already to go in my app. Here's the code -- lemme' know if you need anything else
.java File
package reseeveBeta.mpi.dcasey;
import android.app.Activity;
import android.os.Bundle;
public class ReseeveBetaActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Welcome to Reseeve, tap register to begin account creation" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:text="If you already have and account, please login below" >
<requestFocus />
</EditText>
</LinearLayout>
This line should open your built-in browser, with the specified url:
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.google.com")));
Your Activity should have parts like this:
//define class variables here
Button btn;
protected void onCreate(Bundle savedInstanceState)
{
//some code of yours
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(this);
//more code of yours
}
//whatever else you have in your source code
public void onClick(View v)
{
//handle the click events here, in this case open www.google.com with the default browser
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.google.com")));
}
It might not be 100% accurate syntax, since I did just write this on my own, but you get the idea.
You can do that with Rebol 3, this easily:
REBOL []
load-gui
view [button "Go" on-action [browse http://msn.com]]
That's a fully functioning GUI program, which runs on Android AND on desktop, using the exact same code across all platforms. Take a look at:
http://rebolforum.com/index.cgi?f=printtopic&permalink=Nick25-Aug-2013/10:08:38-7:00&archiveflag=new
Simple create one WebView in xml
<WebView
android:id="#+id/web_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
Here is the Simple java code for that
String URL="www.gtumca.co.cc";
WebView wv=(WebView)findViewById(R.layout.web_view);
onClick()
{
wv.loadUrl(URL);
}
I have a activity in Android TextView followed ListView again TextView. The content of first TextView fills the whole screen and in order to see the ListView and second TextView the user has to scrolldown. Now I wish to show the second TextView when activity start instead of first TextView.
Instead I want TextView2 to be visible when activity starts.
EDITED
Sample code as per advice of #Urban
public class FocusTestActivity extends Activity {
private static final String TAG = "FocusTestActivity";
ScrollView scroll;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView text1 = (TextView) findViewById(R.id.text1);
TextView text2 = (TextView) findViewById(R.id.text2);
TextView text3 = (TextView) findViewById(R.id.text3);
String hello = "We provide services to K-12 education sector."
+ "Our services include Feasibility report, Marketing, Curriculum design"
+ "Teachers planning, Design and Technology, Parents expectation"
+ "management, Transport planning, Day-to-day operations and Statutory"
+ "compliances. Please find a brief introduction attached with mail. Also visit"
+ "www.wissenways.com We can help you with overall process of setting-up school. We have"
+ "experience include establishing International, pre-school and CBSE"
+ "schools from scratch. Please feel free to contact if you need some help in your school venture."
+ "Best of Luck!<br/><br/>";
text1.setText(Html.fromHtml(hello));
text2.setText(Html.fromHtml(hello));
text3.setText(Html.fromHtml(hello));
ScrollView scroll = (ScrollView) findViewById(R.id.scrollcontainer);
}
public void onStart() {
super.onStart();
Log.d(TAG,"Inside onStart");
scroll.post(new Runnable() {
#Override
public void run() {
scroll.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
}
XML Code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollcontainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
android:textSize="17sp"/>
<TextView
android:id="#+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
android:textSize="17sp"/>
<TextView
android:id="#+id/text3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
android:textSize="17sp"/>
</LinearLayout>
</ScrollView>
LOGCAT output:
getScrollView().post(new Runnable() {
#Override
public void run() {
getScrollView().fullScroll(ScrollView.FOCUS_DOWN);
}
});
Using this code in the onCreate should start the scrollview (in which your list and two text views are) at the bottom position. I dont know why you would want to do that, and im guessing there could be a better way to do what you want rather than forcing the scroll position to the bottom, but anyways...
This is the question from where the above code is taken from, you couldve searched for it.
Hope this helped.
Here are 3 simple options i can give you:
Change there places
Make another activity with the second textview and launch that activity first then show you current one
Show a Toast with the text in the second textview at the start of your activity (problem with this one is the user closes it and you want to show it again or user wants to see it again you need to launch a new toast)
I don't fully understand your difficulty with this problem
EDIT:
when must the first textview display at the top? if never just do the first option :\ if under some event, have a empty textview at the top and at the bottom and by code change it's text to what you want at the moment you want
You could also use in your xml file a RealtiveLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:id="#+id/txtview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ListView
android:id="#id/android:list"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#id/textview2/>
<TextView
android:id="#+id/txtview1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#id/android:list"/>
</RelativeLayout>
I've created a countdown timer that counts Days:Hrs:Mins:Sec. using regular text view and updating it using my handler works fine for me.
however I want to create a cool animation for the changing digits:
1st Q:
I have 2 options as I see it to draw the numbers:
1. using a home made font applied with a style
2. using a textview/btn with no text on them and applying a backrgound image using setBackgroundResource()
--what should I choose?
2nd Q:
I've created a wrapper for ViewFlipper(not extending it)
public class transitionair extends Activity {
SpecialFlipperWrapper m_thousand;
SpecialFlipperWrapper m_hundred;
SpecialFlipperWrapper m_tens;
SpecialFlipperWrapper m_ones;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
ViewFlipper flipper_Tsnds=(ViewFlipper)findViewById(R.id.yearThousand);
m_thousand = new SpecialFlipperWrapper(flipper_Tsnds, this, 9);
ViewFlipper flipper_Hndrds=(ViewFlipper)findViewById(R.id.yearHundread);
m_hundred = new SpecialFlipperWrapper(flipper_Hndrds, this, 9);
ViewFlipper flipper_Tns=(ViewFlipper)findViewById(R.id.yearTens);
m_tens = new SpecialFlipperWrapper(flipper_Tns, this, 9);
ViewFlipper flipper_Ons=(ViewFlipper)findViewById(R.id.yearOnes);
m_ones = new SpecialFlipperWrapper(flipper_Ons, this, 9);
m_thousand.startFlipping();
m_hundred.startFlipping();
m_tens.startFlipping();
m_ones.startFlipping();
}
}
however trying to fetch one of the latter views that come after the yearThousand id are retrieving null
XML I'm Using is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ViewFlipper
android:id="#+id/yearThousand"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ViewFlipper
android:id="#+id/yearHundread"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ViewFlipper
android:id="#+id/yearTens"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ViewFlipper
android:id="#+id/yearOnes"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
ps xml's for the animation itself are working so I left them out
Main questions is: can I make it better?
second question is: how?
third question is why is my layout returning null on the second call to it and how can I avoid it?
10XX