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
17package com.android.gallery3d.data;
18
19import android.graphics.Rect;
20
21import com.android.gallery3d.common.Utils;
22
23import java.util.StringTokenizer;
24
25public 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 String getName() {
49        return mName;
50    }
51
52    @Override
53    public boolean equals(Object obj) {
54        if (obj instanceof Face) {
55            Face face = (Face) obj;
56            return mPersonId.equals(face.mPersonId);
57        }
58        return false;
59    }
60
61    public int compareTo(Face another) {
62        return mName.compareTo(another.mName);
63    }
64}
65