Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7139286
commit 1f15653
Showing
7 changed files
with
218 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:a="http://schemas.android.com/apk/res/android" | ||
a:layout_width="fill_parent" | ||
a:layout_height="fill_parent" | ||
a:orientation="horizontal" | ||
> | ||
|
||
<Button | ||
a:id="@id/nmbtnzoomout" | ||
a:layout_width="wrap_content" | ||
a:layout_height="wrap_content" | ||
a:background="@android:drawable/btn_minus" | ||
/> | ||
<Button | ||
a:id="@id/nmbtnzoomin" | ||
a:layout_width="wrap_content" | ||
a:layout_height="wrap_content" | ||
a:background="@android:drawable/btn_plus" | ||
/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<!-- Pre-allocate ids that are used by user defined layouts --> | ||
<item type="id" name="nmbtnzoomout" /> | ||
<item type="id" name="nmbtnzoomin" /> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
nanomaps-sample/src/net/rcode/nanomaps/sample/widgets/MapControls.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package net.rcode.nanomaps.sample.widgets; | ||
|
||
import net.rcode.nanomaps.MapSurface; | ||
import net.rcode.nanomaps.sample.R; | ||
import android.content.Context; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.FrameLayout; | ||
|
||
/** | ||
* Helper for instantiating map controls | ||
* @author stella | ||
* | ||
*/ | ||
public class MapControls { | ||
MapSurface map; | ||
Context context; | ||
|
||
public MapControls(MapSurface map) { | ||
this.map=map; | ||
this.context=map.getContext(); | ||
} | ||
|
||
public View createZoomControl(int layoutResource) { | ||
FrameLayout root=new FrameLayout(context); | ||
View control=LayoutInflater.from(context).inflate(layoutResource, root); | ||
configureZoomControl(control); | ||
return root; | ||
} | ||
|
||
/** | ||
* Given a view, hook it up with events so that it controls the | ||
* zoom settings of the map. | ||
* @param control | ||
*/ | ||
public void configureZoomControl(View control) { | ||
View btn; | ||
|
||
// Zoom in button | ||
btn=control.findViewById(R.id.nmbtnzoomin); | ||
if (btn!=null) { | ||
btn.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Log.d("nanomaps", "Zoom In"); | ||
double current=map.getMapState().getLevel(); | ||
int max=map.getMapMaxLevel(); | ||
double next=Math.floor(current)+1; | ||
if (next>max) next=max; | ||
map.getMapState().setLevel(next, map.getWidth()/2, map.getHeight()/2); | ||
} | ||
}); | ||
} | ||
|
||
// Zoom out button | ||
btn=control.findViewById(R.id.nmbtnzoomout); | ||
if (btn!=null) { | ||
btn.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Log.d("nanomaps", "Zoom Out"); | ||
double current=map.getMapState().getLevel(); | ||
int min=map.getMapMinLevel(); | ||
double next=Math.ceil(current)-1; | ||
if (next<min) next=min; | ||
map.getMapState().setLevel(next, map.getWidth()/2, map.getHeight()/2); | ||
} | ||
}); | ||
} | ||
} | ||
} |