SDK Download
Add library to project
With your project open click on File -> New -> New module
and select Import .JAR/.AAR Package
. In the next screen select the supplied aar file in File name and click Finish.
Right click on the application module and select Open Module Settings
. On the tab Dependencies
add the imported floorplannerviewer
as a Module dependency
.
Add viewer to activity
Add the viewer fragment to your layout file.
<fragment
android:name="com.floorplanner.floorplannerviewer.FPViewerFragment"
android:id="@+id/viewerfragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Get a reference to the viewer and store it in field of your activity.
import com.floorplanner.floorplannerviewer.FPViewerFragment;
// ...
private FPViewerFragment viewerFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
viewerFragment = (FPViewerFragment)getSupportFragmentManager()
.findFragmentById(R.id.viewerfragment);
// ...
Use viewer fragment
Load project
Using loadProject
you can load a new project using either a project id or an url to a fml project.
viewerFragment.loadProject(33549795);
viewerFragment.loadProject("https://floorplanner.com/api/v2/projects/33549795.fml")
Change view mode
Using getViewMode
and setViewMode
you can change the active viewmode for the viewer.
if (viewerFragment.getViewMode == FPViewerFragment.ViewMode.Mode3D) {
viewerFragment.setViewMode(FPViewerFragment.ViewMode.Mode2D);
} else {
viewerFragment.setViewMode(FPViewerFragment.ViewMode.Mode3D);
}
Get designs in project
The following example lists the available designs in a Menu
using getFloors
, shows them and selects the new design using loadDesign
.
viewerFragment.getFloors(new FPViewerFragment.GetFloorsHandler() {
@Override
public void onReceiveFloors(List<Floor> floors) {
PopupMenu popup = new PopupMenu(MainActivity.this, control);
Menu menu = popup.getMenu();
for (Floor floor : floors) {
SubMenu subMenu = menu.addSubMenu(floor.getName());
for (final Design design : floor.getDesigns()) {
MenuItem menuItem = subMenu.add(design.getName());
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
viewerFragment.loadDesign(design);
return true;
}
});
}
}
popup.show();
}
});