A lightweight library which used to add a polygon with 4 vetrexes over an image and allow the user to move either the whole polygon at once or the vertexes one by one.
Add this in your root build.gradle
file (not your module build.gradle
file):
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}
Add this to your module's build.gradle
file (make sure the version matches the JitPack badge above):
dependencies {
...
implementation 'com.github.hamzasharuf:floorplanner:1.2'
}
In your_layout.xml
add the FloorPlannerView
.
<com.hamzasharuf.floor_planner.FloorPlannerView
android:id="@+id/floor_planner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/conan"
app:boxPadding="20"
app:fillColor="#995FAC4A"
app:extendedTouchRadius="30"
app:markerColor="#ff0000"
app:polygonHeightRatio="0.75"
app:polygonStrokeWidth="10"
app:polygonWidthRatio="0.75"
app:markerRadius="15"
app:strokeColor="@color/teal_700" />
You can customize the FloorPlannerView
by changing its attributes either in the xml
layout or in the code.
-
app:boxPadding="20"
Add padding to the surrounding box to prevent the polygon from exceeding this padding and to have a sufficient space between the box borders and the polygon. -
app:markerRadius="15"
The radius of the marker which is used to describe a polygon vertex on theFloorPlannerView
. -
app:markerColor="#ff0000"
The color of the vertexes' markers. -
app:fillColor="#995FAC4A"
The fill color of the polygon. -
app:strokeColor="#ff018786"
The stroke color of the polygon which is used to describe the sides of the polygon. -
app:polygonStrokeWidth="10"
The stroke width of the polygon which is used to describe the sides of the polygon. -
app:polygonWidthRatio="0.75"
Describes the width ratio the polygon will take out of the full FloorPlanner width once it's drawn for the first time. should be between 0.5 and 1. -
app:polygonHeightRatio="0.75"
Describes the height ratio the polygon will take out of the full FloorPlanner height once it's drawn for the first time. should be between 0.5 and 1. -
app:extendedTouchRadius="30"
Additional imaginary radius to the vertex to make the touch event on the vertex more easy for the user (To avoid forcing the user to touch the vertex itself).
val fp = findViewById<FloorPlannerView>(R.id.floor_planner)
fp.apply {
setExtendedTouchRadius(50)
setBoxPadding(30f)
setMarkerRadius(14)
setFillColor(Color.CYAN)
setStrokeColor(Color.GREEN)
setMarkerColor(Color.RED)
setPolygonHeightRatio(0.75f)
setPolygonWidthRatio(0.75f)
setExtendedTouchRadius(30)
}
You can extend the imaginary
You can access the Polygon or the vertexes directly
val fp = findViewById<FloorPlannerView>(R.id.floor_planner)
fp.polygon
fp.vertexes
You can add a listener to the polygon changes and have a callback whenever the user moves the polygon or any of its vertexes.
fp.onCoordinatesUpdatedListener = object : FloorPlannerView.OnCoordinatesUpdatedListener {
override fun onCoordinatesUpdated(polygon: Polygon) {
Log.d(TAG, "New Vertexes Coordinates => ${polygon.vertexes}")
}
}
- Fork floorplanner.
- Create a new branch (using GitHub) or the command
git checkout -b branch-name develop
). - Start a pull request. Reference existing issues when possible.
MIT License
Copyright (c) 2021 Hamza Sharaf
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.