Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rsqtechnologies.rehapointphysio.model.utils.views;
- import android.content.Context;
- import android.graphics.drawable.ShapeDrawable;
- import android.support.annotation.Nullable;
- import android.view.MotionEvent;
- import com.rey.material.widget.ImageView;
- import com.rsqtechnologies.rehapointphysio.R;
- import com.rsqtechnologies.rehapointphysio.model.businessobjects.BodyPartArea;
- import com.rsqtechnologies.rehapointphysio.model.businessobjects.BodyPartGroup;
- import com.rsqtechnologies.rehapointphysio.model.businessobjects.SkeletonClickableArea;
- import com.rsqtechnologies.rehapointphysio.model.utils.VectorShape;
- import com.rsqtechnologies.rehapointphysio.skeleton.SkeletonActivity;
- import java.util.ArrayList;
- import java.util.Deque;
- import java.util.LinkedList;
- public class SkeletonWithLayers extends ImageView {
- private Context context;
- private VectorShape shape;
- private Deque<VectorShape.Layer> layers = new LinkedList<>();
- private ArrayList<String> upperLimbPathNames;
- private ArrayList<String> lowerLimbPathNames;
- private ArrayList<String> spinePathNames;
- public SkeletonWithLayers(Context context) {
- super(context);
- this.context = context;
- shape = new VectorShape(context, R.drawable.skeleton_front);
- setBackground(new ShapeDrawable(shape));
- setupPathNames();
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- float posX = event.getX()/this.getWidth();
- float posY = event.getY()/this.getHeight();
- BodyPartGroup bodyPartGroup = null;
- if (checkIfClickedOnBodyPartGroup(BodyPartGroup.SPINE, posX, posY)){
- bodyPartGroup = BodyPartGroup.SPINE;
- } else if (checkIfClickedOnBodyPartGroup(BodyPartGroup.LOWER_LIMB, posX, posY)) {
- bodyPartGroup = BodyPartGroup.LOWER_LIMB;
- } else if (checkIfClickedOnBodyPartGroup(BodyPartGroup.UPPER_LIMB, posX, posY)) {
- bodyPartGroup = BodyPartGroup.UPPER_LIMB;
- }
- if (bodyPartGroup != null) {
- highlightBodyPartGroup(bodyPartGroup);
- ((SkeletonActivity) context).bodyPartOnClick(bodyPartGroup);
- }
- invalidate();
- return false;
- }
- private boolean checkIfClickedOnBodyPartGroup(BodyPartGroup bodyPartGroup, float posX, float posY){
- switch (bodyPartGroup){
- case SPINE:
- if (checkIfPositionInArea(posX, posY, getAreaCoordinates(SkeletonClickableArea.SPINE)))
- return true;
- break;
- case LOWER_LIMB:
- if (checkIfPositionInArea(posX, posY, getAreaCoordinates(SkeletonClickableArea.LEFT_LEG)) || checkIfPositionInArea(posX, posY, getAreaCoordinates(SkeletonClickableArea.RIGHT_LEG)))
- return true;
- break;
- case UPPER_LIMB:
- if (checkIfPositionInArea(posX, posY, getAreaCoordinates(SkeletonClickableArea.LEFT_TOP_ARM)) || checkIfPositionInArea(posX, posY, getAreaCoordinates(SkeletonClickableArea.LEFT_BOTTOM_ARM)) ||
- checkIfPositionInArea(posX, posY, getAreaCoordinates(SkeletonClickableArea.RIGHT_TOP_ARM))|| checkIfPositionInArea(posX, posY, getAreaCoordinates(SkeletonClickableArea.RIGHT_BOTTOM_ARM)))
- return true;
- break;
- }
- return false;
- }
- private boolean checkIfPositionInArea(double posX, double posY, ArrayList<Double> coordinates){
- if (posX > coordinates.get(0) && posX < coordinates.get(1) && posY > coordinates.get(2) && posY < coordinates.get(3)) {
- return true;
- } else {
- return false;
- }
- }
- public void highlightBodyAreas(BodyPartArea bodyPartArea){
- ArrayList<String> bodyParts = setupDetailesBodyPart(bodyPartArea);
- if (bodyParts != null && !bodyParts.isEmpty()) {
- for (String name : bodyParts) {
- shape.getLayersAt(name, layers);
- if (layers.size() != 0) {
- layers.getFirst().highlight();
- invalidate();
- }
- }
- }
- }
- public void highlightBodyPartGroup(BodyPartGroup bodyPartGroup){
- ArrayList<String> bodyPartsToHighlight = null;
- switch (bodyPartGroup){
- case UPPER_LIMB:
- bodyPartsToHighlight = upperLimbPathNames;
- break;
- case LOWER_LIMB:
- bodyPartsToHighlight = lowerLimbPathNames;
- break;
- case SPINE:
- bodyPartsToHighlight = spinePathNames;
- break;
- }
- unhighlightAll();
- for (String name : bodyPartsToHighlight) {
- shape.getLayersAt(name, layers);
- if (layers.size() != 0) {
- layers.getFirst().highlight();
- invalidate();
- }
- }
- }
- public void unhighlightAll() {
- unhighlightBodyParts(upperLimbPathNames);
- unhighlightBodyParts(lowerLimbPathNames);
- unhighlightBodyParts(spinePathNames);
- }
- private void unhighlightBodyParts(ArrayList<String> bodyParts) {
- for (String name : bodyParts) {
- shape.getLayersAt(name, layers);
- if (layers.size() != 0) {
- layers.getFirst().unhighlight();
- invalidate();
- }
- }
- }
- @Nullable
- private ArrayList<String> setupDetailesBodyPart(BodyPartArea bodyPartArea) {
- ArrayList<String> bodyParts = new ArrayList<>();
- switch (bodyPartArea) {
- case SHOULDER:
- bodyParts.add("shoulder_right_1");
- bodyParts.add("shoulder_right_2");
- break;
- case ELBOW:
- bodyParts.add("elbow_right_1");
- bodyParts.add("elbow_right_2");
- break;
- case WRIST:
- bodyParts.add("wrist_right");
- break;
- case HAND:
- bodyParts.add("hand_right");
- bodyParts.add("elbow_right_1");
- bodyParts.add("elbow_right_2");
- bodyParts.add("forearm_right");
- bodyParts.add("arm_right");
- bodyParts.add("wrist_right");
- break;
- case HIP_JOINT:
- bodyParts.add("hip_right");
- break;
- case KNEE_JOINT:
- bodyParts.add("knee_right_1");
- bodyParts.add("knee_right_2");
- break;
- case ANKLE:
- bodyParts.add("ankle_right_1");
- bodyParts.add("ankle_right_2");
- break;
- case FOOT:
- bodyParts.add("foot_right");
- bodyParts.add("heel_right");
- break;
- case CERVICAL_SPINE:
- bodyParts.add("neck");
- break;
- case THORARIC_SPINE:
- bodyParts.add("thoracic_spine");
- break;
- case LUMBAR_SPINE:
- bodyParts.add("lumbar_spine");
- break;
- case FAULTY_POSTURE:
- bodyParts.add("thoracic_spine");
- bodyParts.add("neck");
- bodyParts.add("lumbar_spine");
- break;
- case OTHER:
- break;
- }
- return bodyParts;
- }
- private void setupPathNames(){
- setupUpperLimbPathNames();
- setupLowerLimbPathNames();
- setupSpinePathNames();
- }
- private void setupUpperLimbPathNames() {
- upperLimbPathNames = new ArrayList<>();
- upperLimbPathNames.add("hand_right");
- upperLimbPathNames.add("hand_left");
- upperLimbPathNames.add("forearm_right");
- upperLimbPathNames.add("forearm_left");
- upperLimbPathNames.add("elbow_right_1");
- upperLimbPathNames.add("elbow_right_2");
- upperLimbPathNames.add("elbow_left_1");
- upperLimbPathNames.add("elbow_left_2");
- upperLimbPathNames.add("arm_right");
- upperLimbPathNames.add("arm_left");
- upperLimbPathNames.add("wrist_right");
- upperLimbPathNames.add("wrist_left");
- upperLimbPathNames.add("collarbone_right");
- upperLimbPathNames.add("collarbone_left");
- upperLimbPathNames.add("shoulder_right_1");
- upperLimbPathNames.add("shoulder_right_2");
- }
- private void setupLowerLimbPathNames() {
- lowerLimbPathNames = new ArrayList<>();
- lowerLimbPathNames.add("foot_right");
- lowerLimbPathNames.add("heel_left");
- lowerLimbPathNames.add("foot_left");
- lowerLimbPathNames.add("heel_right");
- lowerLimbPathNames.add("lowerleg_right");
- lowerLimbPathNames.add("lowerleg_left");
- lowerLimbPathNames.add("ankle_right_1");
- lowerLimbPathNames.add("ankle_right_2");
- lowerLimbPathNames.add("ankle_left_1");
- lowerLimbPathNames.add("ankle_left_2");
- lowerLimbPathNames.add("knee_right_1");
- lowerLimbPathNames.add("knee_right_2");
- lowerLimbPathNames.add("knee_left_1");
- lowerLimbPathNames.add("knee_left_2");
- lowerLimbPathNames.add("femur_right");
- lowerLimbPathNames.add("femur_left");
- lowerLimbPathNames.add("hip_right");
- lowerLimbPathNames.add("hip_left");
- }
- private void setupSpinePathNames(){
- spinePathNames = new ArrayList<>();
- spinePathNames.add("thoracic_spine");
- spinePathNames.add("neck");
- spinePathNames.add("lumbar_spine");
- }
- private ArrayList<Double> getAreaCoordinates(SkeletonClickableArea skeletonClickableArea){
- ArrayList<Double> coordinates = new ArrayList<>();
- switch (skeletonClickableArea){
- case SPINE:
- coordinates.add(0.3134);
- coordinates.add(0.6300);
- coordinates.add(0.1222);
- coordinates.add(0.4635);
- break;
- case LEFT_LEG:
- coordinates.add(0.2829);
- coordinates.add(0.4495);
- coordinates.add(0.4636);
- coordinates.add(0.9854);
- break;
- case RIGHT_LEG:
- coordinates.add(0.5095);
- coordinates.add(0.6795);
- coordinates.add(0.4636);
- coordinates.add(0.9854);
- break;
- case LEFT_TOP_ARM:
- coordinates.add(0.0);
- coordinates.add(0.3133);
- coordinates.add(0.1222);
- coordinates.add(0.3824);
- break;
- case LEFT_BOTTOM_ARM:
- coordinates.add(0.6300);
- coordinates.add(1.0);
- coordinates.add(0.1222);
- coordinates.add(0.3824);
- break;
- case RIGHT_TOP_ARM:
- coordinates.add(0.0);
- coordinates.add(0.2800);
- coordinates.add(0.3824);
- coordinates.add(0.6024);
- break;
- case RIGHT_BOTTOM_ARM:
- coordinates.add(0.6795);
- coordinates.add(1.0);
- coordinates.add(0.3824);
- coordinates.add(0.6024);
- break;
- }
- return coordinates;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement