EMMA Coverage Report (generated Thu Oct 17 06:14:17 PDT 2013)
[all classes][com.example.android.notepad]

COVERAGE SUMMARY FOR SOURCE FILE [NotesList.java]

nameclass, %method, %block, %line, %
NotesList.java100% (1/1)50%  (4/8)39%  (106/271)33%  (18/55)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NotesList100% (1/1)50%  (4/8)39%  (106/271)33%  (18/55)
onContextItemSelected (MenuItem): boolean 0%   (0/1)0%   (0/45)0%   (0/12)
onCreateContextMenu (ContextMenu, View, ContextMenu$ContextMenuInfo): void 0%   (0/1)0%   (0/67)0%   (0/15)
onListItemClick (ListView, View, int, long): void 0%   (0/1)0%   (0/35)0%   (0/6)
onOptionsItemSelected (MenuItem): boolean 0%   (0/1)0%   (0/18)0%   (0/4)
<static initializer> 100% (1/1)100% (12/12)100% (1/1)
NotesList (): void 100% (1/1)100% (3/3)100% (1/1)
onCreate (Bundle): void 100% (1/1)100% (53/53)100% (10/10)
onCreateOptionsMenu (Menu): boolean 100% (1/1)100% (38/38)100% (6/6)

1/*
2 * Copyright (C) 2007 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.example.android.notepad;
18 
19import com.example.android.notepad.NotePad.NoteColumns;
20 
21import android.app.ListActivity;
22import android.content.ComponentName;
23import android.content.ContentUris;
24import android.content.Intent;
25import android.database.Cursor;
26import android.net.Uri;
27import android.os.Bundle;
28import android.util.Log;
29import android.view.ContextMenu;
30import android.view.Menu;
31import android.view.MenuInflater;
32import android.view.MenuItem;
33import android.view.View;
34import android.view.ContextMenu.ContextMenuInfo;
35import android.widget.AdapterView;
36import android.widget.ListView;
37import android.widget.SimpleCursorAdapter;
38 
39/**
40 * Displays a list of notes. Will display notes from the {@link Uri}
41 * provided in the intent if there is one, otherwise defaults to displaying the
42 * contents of the {@link NoteProvider}
43 */
44public class NotesList extends ListActivity {
45    private static final String TAG = "NotesList";
46 
47    /**
48     * The columns we are interested in from the database
49     */
50    private static final String[] PROJECTION = new String[] {
51        NoteColumns._ID, // 0
52        NoteColumns.TITLE, // 1
53    };
54 
55    /** The index of the title column */
56    private static final int COLUMN_INDEX_TITLE = 1;
57    
58    @Override
59    protected void onCreate(Bundle savedInstanceState) {
60        super.onCreate(savedInstanceState);
61 
62        setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
63 
64        // If no data was given in the intent (because we were started
65        // as a MAIN activity), then use our default content provider.
66        Intent intent = getIntent();
67        if (intent.getData() == null) {
68            intent.setData(NoteColumns.CONTENT_URI);
69        }
70 
71        // Inform the list we provide context menus for items
72        getListView().setOnCreateContextMenuListener(this);
73        
74        // Perform a managed query. The Activity will handle closing and requerying the cursor
75        // when needed.
76        Cursor cursor = managedQuery(getIntent().getData(), PROJECTION, null, null,
77                                        NoteColumns.DEFAULT_SORT_ORDER);
78 
79        // Used to map notes entries from the database to views
80        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.noteslist_item, cursor,
81                new String[] { NoteColumns.TITLE }, new int[] { android.R.id.text1 });
82        setListAdapter(adapter);
83    }
84 
85    @Override
86    public boolean onCreateOptionsMenu(Menu menu) {
87        // Inflate menu from XML resource
88        MenuInflater inflater = getMenuInflater();
89        inflater.inflate(R.menu.list_options_menu, menu);
90        
91        // Generate any additional actions that can be performed on the
92        // overall list.  In a normal install, there are no additional
93        // actions found here, but this allows other applications to extend
94        // our menu with their own actions.
95        Intent intent = new Intent(null, getIntent().getData());
96        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
97        menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
98                new ComponentName(this, NotesList.class), null, intent, 0, null);
99 
100        return super.onCreateOptionsMenu(menu);
101    }
102 
103    @Override
104    public boolean onOptionsItemSelected(MenuItem item) {
105        switch (item.getItemId()) {
106        case R.id.menu_add:
107            // Launch activity to insert a new item
108            startActivity(new Intent(Intent.ACTION_INSERT, getIntent().getData()));
109            return true;
110        default:
111            return super.onOptionsItemSelected(item);
112        }
113    }
114 
115    @Override
116    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
117        AdapterView.AdapterContextMenuInfo info;
118        try {
119             info = (AdapterView.AdapterContextMenuInfo) menuInfo;
120        } catch (ClassCastException e) {
121            Log.e(TAG, "bad menuInfo", e);
122            return;
123        }
124 
125        Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
126        if (cursor == null) {
127            // For some reason the requested item isn't available, do nothing
128            return;
129        }
130 
131        // Inflate menu from XML resource
132        MenuInflater inflater = getMenuInflater();
133        inflater.inflate(R.menu.list_context_menu, menu);
134        
135        // Set the context menu header
136        menu.setHeaderTitle(cursor.getString(COLUMN_INDEX_TITLE));
137        
138        // Append to the
139        // menu items for any other activities that can do stuff with it
140        // as well.  This does a query on the system for any activities that
141        // implement the ALTERNATIVE_ACTION for our data, adding a menu item
142        // for each one that is found.
143        Intent intent = new Intent(null, Uri.withAppendedPath(getIntent().getData(), 
144                                        Integer.toString((int) info.id) ));
145        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
146        menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
147                new ComponentName(this, NotesList.class), null, intent, 0, null);
148    }
149        
150    @Override
151    public boolean onContextItemSelected(MenuItem item) {
152        AdapterView.AdapterContextMenuInfo info;
153        try {
154             info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
155        } catch (ClassCastException e) {
156            Log.e(TAG, "bad menuInfo", e);
157            return false;
158        }
159        
160        Uri noteUri = ContentUris.withAppendedId(getIntent().getData(), info.id);
161 
162        switch (item.getItemId()) {
163        case R.id.context_open:
164            // Launch activity to view/edit the currently selected item
165            startActivity(new Intent(Intent.ACTION_EDIT, noteUri));
166            return true;
167        case R.id.context_delete:
168            // Delete the note that the context menu is for
169            getContentResolver().delete(noteUri, null, null);
170            return true;
171        default:
172            return super.onContextItemSelected(item);
173        }
174    }
175 
176    @Override
177    protected void onListItemClick(ListView l, View v, int position, long id) {
178        Uri noteUri = ContentUris.withAppendedId(getIntent().getData(), id);
179        
180        String action = getIntent().getAction();
181        if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
182            // The caller is waiting for us to return a note selected by
183            // the user.  The have clicked on one, so return it now.
184            setResult(RESULT_OK, new Intent().setData(noteUri));
185        } else {
186            // Launch activity to view/edit the currently selected item
187            startActivity(new Intent(Intent.ACTION_EDIT, noteUri));
188        }
189    }
190}

[all classes][com.example.android.notepad]
EMMA 2.0.5312 (C) Vladimir Roubtsov