Skip to content

UsefulAnd/AndroidHeatMap

 
 

Repository files navigation

Release Method Count API Apache 2

AndroidHeatMap

AndroidHeatMap is an easy to use heat map control for Android apps.

Example View

Installation

There are three different ways to use this library:

1. Gradle dependency (recommended)

  • Add the following to your project level build.gradle:
allprojects {
	repositories {
		maven { url "https://jitpack.io" }
	}
}
  • Add this to your app build.gradle:
dependencies {
	compile 'ca.heartlandsoftware:androidheatmap:1.0'
}

2. Maven

  • Add the following to the <repositories> section of your pom.xml:
<repository>
	<id>jitpack.io</id>
	<url>https://jitpack.io</url>
</repository>
  • Add the following to the <dependencies> section of your pom.xml:
<dependency>
	<groupId>ca.heartlandsoftware</groupId>
	<artifactId>androidheatmap</artifactId>
	<version>1.0</version>
</dependency>

3. Clone the whole repository

  • Open your commandline-input and navigate to the desired destination folder on your machine (where you want to place the library)
  • Use the command git clone https://github.com/HeartlandSoftware/AndroidHeatMap.git to download the full AndroidHeatMap repository to your computer (this includes the folder of the library as well as the folder of the example project)
  • Import the library folder (AndroidHeatMap) into Android Studio (recommended) or your Eclipse workspace
  • Add it as a reference to your project:

Getting Started

Add a HeatMap control to your xml layout.

<ca.hss.heatmaplib.HeatMap
    android:id="@+id/heatmap"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:minOpacity="0"
    app:maxOpacity="255" />

Back in your activity or fragment you would get a reference to the BottomSheetLayout like any other view.

HeatMap heatMap = (HeatMap) findViewById(R.id.heatmap);

Set the range that you want the heat maps gradient to cover.

heatMap.setMinimum(0.0);
heatMap.setMaximum(100.0);

Now you can add data to the heat map.

//add random data to the map
Random rand = new Random();
for (int i = 0; i < 20; i++) {
    HeatMap.DataPoint point = new HeatMap.DataPoint(rand.nextFloat(), rand.nextFloat(), rand.nextDouble() * 100.0);
    heatMap.addData(point);
}

Options

Colour Gradient

Changing the colour gradient.

//make the colour gradient from pink to yellow
Map<Float, Integer> colorStops = new ArrayMap<>();
colors.put(0.0f, 0xffee42f4);
colors.put(1.0f, 0xffeef442);
heatMap.setColorStops(colors);

Opacity

Set the minimum and maximum opacity of the heat map. The value is an 2 byte alpha value with the range [0,255].

//make the minimum opacity completely transparent
heatMap.setMinimumOpactity(0);
//make the maximum opacity 50% transparent
heatMap.setMaximumOpacity(127);

Or set it in xml.

<ca.hss.heatmaplib.HeatMap
    app:minOpacity="0"
    app:maxOpacity="255" />

Radius

Set the radius of each points coloured gradient.

//set the radius to 300 pixels.
heatMap.setRadius(300);

Or in xml.

<ca.hss.heatmaplib.HeatMap
    app:radius="100dp" />

Refresh

After changing an option after the heat map has been rendered force a refresh.

heatMap.forceRefresh();

License

Copyright 2016 Heartland Software Solutions Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

A heat map view for Android.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%