1/*
2 * Copyright (C) 2012 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.dialer.smartdial;
18
19import android.util.Log;
20import java.util.ArrayList;
21
22/**
23 * Stores information about a range of characters matched in a display name The integers start and
24 * end indicate that the range start to end (exclusive) correspond to some characters in the query.
25 * Used to highlight certain parts of the contact's display name to indicate that those ranges
26 * matched the user's query.
27 */
28public class SmartDialMatchPosition {
29
30  private static final String TAG = SmartDialMatchPosition.class.getSimpleName();
31
32  public int start;
33  public int end;
34
35  public SmartDialMatchPosition(int start, int end) {
36    this.start = start;
37    this.end = end;
38  }
39
40  /**
41   * Used by {@link SmartDialNameMatcher} to advance the positions of a match position found in a
42   * sub query.
43   *
44   * @param inList ArrayList of SmartDialMatchPositions to modify.
45   * @param toAdvance Offset to modify by.
46   */
47  public static void advanceMatchPositions(
48      ArrayList<SmartDialMatchPosition> inList, int toAdvance) {
49    for (int i = 0; i < inList.size(); i++) {
50      inList.get(i).advance(toAdvance);
51    }
52  }
53
54  /**
55   * Used mainly for debug purposes. Displays contents of an ArrayList of SmartDialMatchPositions.
56   *
57   * @param list ArrayList of SmartDialMatchPositions to print out in a human readable fashion.
58   */
59  public static void print(ArrayList<SmartDialMatchPosition> list) {
60    for (int i = 0; i < list.size(); i++) {
61      SmartDialMatchPosition m = list.get(i);
62      Log.d(TAG, "[" + m.start + "," + m.end + "]");
63    }
64  }
65
66  private void advance(int toAdvance) {
67    this.start += toAdvance;
68    this.end += toAdvance;
69  }
70}
71