Skip to content

Most visited

Recently visited

navigation
DirectShare / src / com.example.android.directshare /

Contact.java

1
/*
2
 * Copyright (C) 2015 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.example.android.directshare;
18
 
19
/**
20
 * Provides the list of dummy contacts. This sample implements this as constants, but real-life apps
21
 * should use a database and such.
22
 */
23
public class Contact {
24
 
25
    /**
26
     * The list of dummy contacts.
27
     */
28
    public static final Contact[] CONTACTS = {
29
            new Contact("Tereasa"),
30
            new Contact("Chang"),
31
            new Contact("Kory"),
32
            new Contact("Clare"),
33
            new Contact("Landon"),
34
            new Contact("Kyle"),
35
            new Contact("Deana"),
36
            new Contact("Daria"),
37
            new Contact("Melisa"),
38
            new Contact("Sammie"),
39
    };
40
 
41
    /**
42
     * The contact ID.
43
     */
44
    public static final String ID = "contact_id";
45
 
46
    /**
47
     * Representative invalid contact ID.
48
     */
49
    public static final int INVALID_ID = -1;
50
 
51
    /**
52
     * The name of this contact.
53
     */
54
    private final String mName;
55
 
56
    /**
57
     * Instantiates a new {@link Contact}.
58
     *
59
     * @param name The name of the contact.
60
     */
61
    public Contact(String name) {
62
        mName = name;
63
    }
64
 
65
    /**
66
     * Finds a {@link Contact} specified by a contact ID.
67
     *
68
     * @param id The contact ID. This needs to be a valid ID.
69
     * @return A {@link Contact}
70
     */
71
    public static Contact byId(int id) {
72
        return CONTACTS[id];
73
    }
74
 
75
    /**
76
     * Gets the name of this contact.
77
     *
78
     * @return The name of this contact.
79
     */
80
    public String getName() {
81
        return mName;
82
    }
83
 
84
    /**
85
     * Gets the icon of this contact.
86
     *
87
     * @return The icon.
88
     */
89
    public int getIcon() {
90
        return R.mipmap.logo_avatar;
91
    }
92
 
93
}
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)