1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.gallery3d.data; 18 19 import android.graphics.Rect; 20 21 import com.android.gallery3d.common.Utils; 22 23 import java.util.StringTokenizer; 24 25 public class Face implements Comparable<Face> { 26 private String mName; 27 private String mPersonId; 28 private Rect mPosition; 29 30 public Face(String name, String personId, String rect) { 31 mName = name; 32 mPersonId = personId; 33 Utils.assertTrue(mName != null && mPersonId != null && rect != null); 34 StringTokenizer tokenizer = new StringTokenizer(rect); 35 mPosition = new Rect(); 36 while (tokenizer.hasMoreElements()) { 37 mPosition.left = Integer.parseInt(tokenizer.nextToken()); 38 mPosition.top = Integer.parseInt(tokenizer.nextToken()); 39 mPosition.right = Integer.parseInt(tokenizer.nextToken()); 40 mPosition.bottom = Integer.parseInt(tokenizer.nextToken()); 41 } 42 } 43 44 public Rect getPosition() { 45 return mPosition; 46 } 47 48 public int getWidth() { 49 return mPosition.right - mPosition.left; 50 } 51 52 public int getHeight() { 53 return mPosition.bottom - mPosition.top; 54 } 55 56 public String getName() { 57 return mName; 58 } 59 60 public String getPersonId() { 61 return mPersonId; 62 } 63 64 @Override 65 public boolean equals(Object obj) { 66 if (obj instanceof Face) { 67 Face face = (Face) obj; 68 return mPersonId.equals(face.mPersonId); 69 } 70 return false; 71 } 72 73 public int compareTo(Face another) { 74 return mName.compareTo(another.mName); 75 } 76 } 77