HomeXLarge.java revision fd122354f4d26a15834a677b86680f655a4516ff
1/*
2 * Copyright (C) 2010 Google Inc.
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.loaderapp;
18
19import com.android.loaderapp.fragments.ContactFragment;
20import com.android.loaderapp.fragments.ContactsListFragment;
21
22import android.app.ActionBar;
23import android.app.Activity;
24import android.app.FragmentTransaction;
25import android.content.Intent;
26import android.content.res.Resources;
27import android.net.Uri;
28import android.os.Bundle;
29import android.provider.ContactsContract;
30import android.view.Menu;
31import android.view.MenuItem;
32
33public class HomeXLarge extends Activity implements ContactsListFragment.Controller,
34        ActionBar.Callback {
35    private static final int ACTION_ID_SEARCH = 0;
36    private static final int ACTION_ID_ADD = 1;
37
38    ContactsListFragment mList;
39    ContactFragment mDetails;
40
41    @Override
42    public void onCreate(Bundle savedState) {
43        super.onCreate(savedState);
44
45        setContentView(R.layout.home_xlarge);
46
47        mList = new ContactsListFragment();
48        mList.setController(this);
49        mDetails = new ContactFragment(null, new ContactFragment.DefaultController(this));
50        FragmentTransaction transaction = openFragmentTransaction();
51        transaction.add(R.id.contacts_list, mList);
52        transaction.add(R.id.contact_details, mDetails);
53        transaction.commit();
54
55        getActionBar().setCallback(this);
56
57        Intent intent = getIntent();
58        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
59            mDetails.loadContact(intent.getData());
60        }
61    }
62
63    public void onAction(int id) {
64        switch (id) {
65            case ACTION_ID_SEARCH:
66                startSearch(null, false, null, true);
67                break;
68
69            case ACTION_ID_ADD:
70                startActivity(new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI));
71                break;
72        }
73    }
74
75    public void onContactSelected(Uri contactUri) {
76        // The user clicked on an item in the left side pane, start loading the data for it
77        mDetails.loadContact(contactUri);
78    }
79
80    public boolean onCreateActionMenu(Menu menu) {
81        Resources resources = getResources();
82        menu.add(0, ACTION_ID_SEARCH, 0, R.string.menu_search)
83                .setIcon(resources.getDrawable(android.R.drawable.ic_menu_search));
84        menu.add(0, ACTION_ID_ADD, 1, R.string.menu_newContact)
85                .setIcon(resources.getDrawable(android.R.drawable.ic_menu_add));
86
87        return true;
88    }
89
90    public boolean onUpdateActionMenu(Menu menu) {
91        return false;
92    }
93
94    public boolean onActionItemSelected(MenuItem item) {
95        switch (item.getItemId()) {
96            case ACTION_ID_SEARCH: {
97                startSearch(null, false, null, true);
98                return true;
99            }
100
101            case ACTION_ID_ADD: {
102                startActivity(new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI));
103                return true;
104            }
105        }
106        return false;
107    }
108
109    public boolean onCreateContextMode(int modeId, Menu menu) {
110        return false;
111    }
112
113    public boolean onPrepareContextMode(int modeId, Menu menu) {
114        return false;
115    }
116
117    public boolean onContextItemSelected(int modeId, MenuItem item) {
118        return false;
119    }
120}
121