All Projects → LukasLechnerDev → Clickableareasimages

LukasLechnerDev / Clickableareasimages

Licence: other
An android library which lets you define clickable areas in your images.

Programming Languages

java
68154 projects - #9 most used programming language

ClickableAreasImages

An android library that lets you define rectangular clickable areas in your images.

Description

ClickableAreasImages is an android library that lets you define rectangular clickable areas in your images and associate different objects to it. The images are zoomable and orientation changes are also handled.

demo image

Sample Application

I created a sample application.

get it on Google Play

Sample Usage

    public class MainActivity extends AppCompatActivity implements OnClickableAreaClickedListener {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            // Add image
            ImageView image = (ImageView) findViewById(R.id.imageView);
            image.setImageResource(R.drawable.simpsons);

            // Create your image
            ClickableAreasImage clickableAreasImage = new ClickableAreasImage(new PhotoViewAttacher(image), this);

            // Initialize your clickable area list
            List<ClickableArea> clickableAreas = new ArrayList<>();

            // Define your clickable areas
            // parameter values (pixels): (x coordinate, y coordinate, width, height) and assign an object to it
            clickableAreas.add(new ClickableArea(500, 200, 125, 200, new Character("Homer", "Simpson")));
        	clickableAreas.add(new ClickableArea(600, 440, 130, 160, new Character("Bart", "Simpson")));

            // Set your clickable areas to the image
            clickableAreasImage.setClickableAreas(clickableAreas);
        }

        // Listen for touches on your images:
        @Override
        public void onClickableAreaTouched(Object item) {
            if (item instanceof Character) {
                String text = ((Character) item).getFirstName() + " " + ((Character) item).getLastName();
                Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
            }
        }
    ...
    }

Download

Add it in your root build.gradle:

    allprojects {
		repositories {
			...
			maven { url "https://jitpack.io" }
		}
	}

    dependencies {
	        compile 'com.github.Lukle:ClickableAreasImages:v0.1'
	}

Thanks to

PhotoView, which serves as foundation for this library.

License

Copyright 2016, Lukas Lechner

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].