EMMA Coverage Report (generated Fri Jan 29 20:09:05 CET 2016)
[all classes][kdk.android.simplydo]

COVERAGE SUMMARY FOR SOURCE FILE [SimplyDoActivity.java]

nameclass, %method, %block, %line, %
SimplyDoActivity.java100% (15/15)100% (69/69)95%  (1416/1495)93%  (326/351)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimplyDoActivity$10100% (1/1)100% (2/2)90%  (19/21)83%  (5/6)
onEditorAction (TextView, int, KeyEvent): boolean 100% (1/1)87%  (13/15)80%  (4/5)
SimplyDoActivity$10 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
     
class SimplyDoActivity$12100% (1/1)100% (2/2)90%  (19/21)83%  (5/6)
onEditorAction (TextView, int, KeyEvent): boolean 100% (1/1)87%  (13/15)80%  (4/5)
SimplyDoActivity$12 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
     
class SimplyDoActivity100% (1/1)100% (37/37)94%  (1089/1164)92%  (262/285)
onBackPressed (): void 100% (1/1)60%  (18/30)60%  (6/10)
listSelected (ListDesc, boolean): void 100% (1/1)78%  (28/36)73%  (8/11)
onMenuItemSelected (int, MenuItem): boolean 100% (1/1)84%  (128/153)82%  (36/44)
addItem (): void 100% (1/1)90%  (36/40)92%  (11/12)
onPrepareDialog (int, Dialog): void 100% (1/1)92%  (55/60)88%  (15/17)
onCreateDialog (int): Dialog 100% (1/1)94%  (63/67)95%  (21/22)
onCreate (Bundle): void 100% (1/1)95%  (338/355)95%  (71/75)
<static initializer> 100% (1/1)100% (3/3)100% (1/1)
SimplyDoActivity (): void 100% (1/1)100% (27/27)100% (6/6)
access$1000 (SimplyDoActivity): ItemDesc 100% (1/1)100% (3/3)100% (1/1)
access$1002 (SimplyDoActivity, ItemDesc): ItemDesc 100% (1/1)100% (5/5)100% (1/1)
access$1100 (SimplyDoActivity): DataViewer 100% (1/1)100% (3/3)100% (1/1)
access$1200 (SimplyDoActivity, ItemDesc): void 100% (1/1)100% (4/4)100% (1/1)
access$1300 (SimplyDoActivity, ListDesc, boolean): void 100% (1/1)100% (5/5)100% (1/1)
access$1402 (SimplyDoActivity, ListDesc): ListDesc 100% (1/1)100% (5/5)100% (1/1)
access$200 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$300 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$400 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$500 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$600 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$700 (SimplyDoActivity): AlertDialog 100% (1/1)100% (3/3)100% (1/1)
access$800 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$900 (SimplyDoActivity): AlertDialog 100% (1/1)100% (3/3)100% (1/1)
addList (): void 100% (1/1)100% (32/32)100% (9/9)
cacheInvalidated (): void 100% (1/1)100% (27/27)100% (9/9)
contextDeleteItem (): void 100% (1/1)100% (28/28)100% (6/6)
contextDeleteList (): void 100% (1/1)100% (26/26)100% (5/5)
getDataVeiwer (): DataViewer 100% (1/1)100% (3/3)100% (1/1)
getInstance (): SimplyDoActivity 100% (1/1)100% (2/2)100% (1/1)
itemEditOk (): void 100% (1/1)100% (24/24)100% (6/6)
itemSelected (ItemDesc): void 100% (1/1)100% (33/33)100% (6/6)
listEditOk (): void 100% (1/1)100% (20/20)100% (5/5)
onCreateOptionsMenu (Menu): boolean 100% (1/1)100% (8/8)100% (2/2)
onDestroy (): void 100% (1/1)100% (12/12)100% (5/5)
onPrepareOptionsMenu (Menu): boolean 100% (1/1)100% (57/57)100% (13/13)
onSaveInstanceState (Bundle): void 100% (1/1)100% (25/25)100% (7/7)
onStart (): void 100% (1/1)100% (47/47)100% (12/12)
     
class SimplyDoActivity$1100% (1/1)100% (2/2)100% (10/10)100% (3/3)
SimplyDoActivity$1 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (View): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimplyDoActivity$11100% (1/1)100% (2/2)100% (10/10)100% (3/3)
SimplyDoActivity$11 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimplyDoActivity$2100% (1/1)100% (2/2)100% (10/10)100% (3/3)
SimplyDoActivity$2 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (View): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimplyDoActivity$3100% (1/1)100% (2/2)100% (9/9)100% (3/3)
SimplyDoActivity$3 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (3/3)100% (2/2)
     
class SimplyDoActivity$4100% (1/1)100% (2/2)100% (12/12)100% (4/4)
SimplyDoActivity$4 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (6/6)100% (3/3)
     
class SimplyDoActivity$5100% (1/1)100% (2/2)100% (9/9)100% (3/3)
SimplyDoActivity$5 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (3/3)100% (2/2)
     
class SimplyDoActivity$6100% (1/1)100% (2/2)100% (12/12)100% (4/4)
SimplyDoActivity$6 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (6/6)100% (3/3)
     
class SimplyDoActivity$7100% (1/1)100% (2/2)100% (22/22)100% (4/4)
SimplyDoActivity$7 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onEditorAction (TextView, int, KeyEvent): boolean 100% (1/1)100% (16/16)100% (3/3)
     
class SimplyDoActivity$8100% (1/1)100% (2/2)100% (11/11)100% (3/3)
SimplyDoActivity$8 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onEditorAction (TextView, int, KeyEvent): boolean 100% (1/1)100% (5/5)100% (2/2)
     
class SimplyDoActivity$9100% (1/1)100% (2/2)100% (10/10)100% (3/3)
SimplyDoActivity$9 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimplyDoActivity$ItemsListReactor100% (1/1)100% (4/4)100% (102/102)100% (20/20)
SimplyDoActivity$ItemsListReactor (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
SimplyDoActivity$ItemsListReactor (SimplyDoActivity, SimplyDoActivity$1): void 100% (1/1)100% (4/4)100% (1/1)
onCreateContextMenu (ContextMenu, View, ContextMenu$ContextMenuInfo): void 100% (1/1)100% (72/72)100% (14/14)
onItemClick (AdapterView, View, int, long): void 100% (1/1)100% (20/20)100% (5/5)
     
class SimplyDoActivity$ListsListReactor100% (1/1)100% (4/4)100% (72/72)100% (14/14)
SimplyDoActivity$ListsListReactor (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
SimplyDoActivity$ListsListReactor (SimplyDoActivity, SimplyDoActivity$1): void 100% (1/1)100% (4/4)100% (1/1)
onCreateContextMenu (ContextMenu, View, ContextMenu$ContextMenuInfo): void 100% (1/1)100% (41/41)100% (8/8)
onItemClick (AdapterView, View, int, long): void 100% (1/1)100% (21/21)100% (5/5)

1/*
2 * Copyright (C) 2013, 2011 Keith Kildare
3 * 
4 * This file is part of SimplyDo.
5 * 
6 * SimplyDo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * 
11 * SimplyDo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 * 
16 * You should have received a copy of the GNU General Public License
17 * along with SimplyDo.  If not, see <http://www.gnu.org/licenses/>.
18 * 
19 */
20package kdk.android.simplydo;
21 
22import android.app.Activity;
23import android.app.AlertDialog;
24import android.app.Dialog;
25import android.content.DialogInterface;
26import android.content.Intent;
27import android.content.SharedPreferences;
28import android.os.Bundle;
29import android.preference.PreferenceManager;
30import android.util.Log;
31import android.view.ContextMenu;
32import android.view.KeyEvent;
33import android.view.LayoutInflater;
34import android.view.Menu;
35import android.view.MenuItem;
36import android.view.View;
37import android.view.ViewGroup;
38import android.view.WindowManager;
39import android.view.ContextMenu.ContextMenuInfo;
40import android.view.animation.AnimationUtils;
41import android.widget.AdapterView;
42import android.widget.Button;
43import android.widget.EditText;
44import android.widget.ListView;
45import android.widget.TextView;
46import android.widget.ViewSwitcher;
47import android.widget.AdapterView.AdapterContextMenuInfo;
48import android.widget.AdapterView.OnItemClickListener;
49import android.widget.TextView.OnEditorActionListener;
50 
51public class SimplyDoActivity extends Activity 
52{
53    private static final int DELETE_INACTIVE = 100;
54    private static final int DELETE_LIST     = 101;
55    private static final int EDIT_LIST       = 102;
56    private static final int DELETE_ITEM     = 103;
57    private static final int EDIT_ITEM       = 104;
58    private static final int TOGGLE_STAR     = 105;
59    private static final int SETTINGS        = 106;
60    private static final int SORT_NOW        = 107;
61    private static final int MOVE_ITEM       = 108;
62    
63    private static final int DIALOG_LIST_DELETE = 200;
64    private static final int DIALOG_ITEM_DELETE = 201;
65    private static final int DIALOG_LIST_EDIT = 202;
66    private static final int DIALOG_ITEM_EDIT = 203;
67    private static final int DIALOG_ITEM_MOVE = 204;
68    private static final int DIALOG_DELETE_INACTIVE = 205;
69    
70    private static SimplyDoActivity instance = null;
71    
72    private DataViewer dataViewer;
73    private ListPropertiesAdapter listPropertiesAdapter;
74    private ItemPropertiesAdapter itemPropertiesAdapter;
75    
76    private ListsListReactor listsListReactor = new ListsListReactor();
77    private ItemsListReactor itemsListReactor = new ItemsListReactor();
78    
79    private ItemDesc ctxItem;
80    private ListDesc ctxList;
81    
82    private AlertDialog.Builder itemDeleteBuilder;
83    private AlertDialog.Builder listDeleteBuilder;
84    
85    private AlertDialog.Builder listEditBuilder;
86    private AlertDialog listEditDialog;
87    
88    private AlertDialog.Builder itemEditBuilder;
89    private AlertDialog itemEditDialog;
90    
91    private EditText itemEditView;
92    private EditText listEditView;
93    
94    private ListListSorter listListSorter = new ListListSorter();
95    private ItemListSorter itemListSorter = new ItemListSorter();
96    
97    private MoveToAction moveItemToAction;
98    private DeleteInactiveAction deleteInactiveAction;
99 
100    
101    /** Called when the activity is first created. */
102    @Override
103    public void onCreate(Bundle savedInstanceState) 
104    {
105        Log.v(L.TAG, "SimplyDoActivity.onCreate() called");
106        
107        super.onCreate(savedInstanceState);
108        
109        setContentView(R.layout.main);
110        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
111                
112        DataManager dataManager = new DataManager(this);
113        
114        //dataViewer = new SimpleDataViewer(dataManager);
115        
116        CachingDataViewer cdv = new CachingDataViewer(dataManager);
117        cdv.start();
118        dataViewer = cdv;
119        
120        listPropertiesAdapter = new ListPropertiesAdapter(this, dataViewer);
121        
122        ListView listView = (ListView)findViewById(R.id.ListsListView);
123        listView.setAdapter(listPropertiesAdapter);
124        listView.setOnCreateContextMenuListener(listsListReactor);
125        listView.setOnItemClickListener(listsListReactor);
126        
127        itemPropertiesAdapter = new ItemPropertiesAdapter(this, dataViewer);
128        ListView itemView = (ListView)findViewById(R.id.ItemsListView);
129        itemView.setAdapter(itemPropertiesAdapter);
130        itemView.setOnCreateContextMenuListener(itemsListReactor);
131        itemView.setOnItemClickListener(itemsListReactor);
132        
133        Button addList = (Button)findViewById(R.id.AddListButton);
134        addList.setOnClickListener(new View.OnClickListener() {
135            @Override
136            public void onClick(View v)
137            {
138                addList();
139            }
140        });
141        
142        Button addItem = (Button)findViewById(R.id.AddItemButton);
143        addItem.setOnClickListener(new View.OnClickListener() {
144            @Override
145            public void onClick(View v)
146            {
147                addItem();
148            }
149        });
150        
151        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
152        viewSwitch.setInAnimation(AnimationUtils.loadAnimation(this,
153                android.R.anim.slide_in_left));
154        viewSwitch.setOutAnimation(AnimationUtils.loadAnimation(this,
155                android.R.anim.slide_out_right));
156        
157        listDeleteBuilder = new AlertDialog.Builder(this);
158        listDeleteBuilder.setMessage(R.string.listDeleteMessage)
159               .setCancelable(true)
160               .setTitle(R.string.listDeleteTitle)
161               .setPositiveButton(R.string.listDeletePositive, new DialogInterface.OnClickListener() {
162                   @Override
163                                public void onClick(DialogInterface dialog, int id) {
164                       contextDeleteList();
165                       dialog.cancel();
166                   }
167               })
168               .setNegativeButton(R.string.listDeleteNegative, new DialogInterface.OnClickListener() {
169                   @Override
170                                public void onClick(DialogInterface dialog, int id) {
171                        dialog.cancel();
172                   }
173               });
174        
175        itemDeleteBuilder = new AlertDialog.Builder(this);
176        itemDeleteBuilder.setMessage(
177                R.string.itemDeleteMessage)
178               .setCancelable(true)
179               .setTitle(R.string.itemDeleteTitle)
180               .setPositiveButton(R.string.itemDeletePositive, new DialogInterface.OnClickListener() {
181                   @Override
182                                public void onClick(DialogInterface dialog, int id) {
183                       contextDeleteItem();
184                       dialog.cancel();
185                   }
186               })
187               .setNegativeButton(R.string.itemDeleteNegative, new DialogInterface.OnClickListener() {
188                   @Override
189                                public void onClick(DialogInterface dialog, int id) {
190                        dialog.cancel();
191                   }
192               });
193        
194        EditText addListEditText = (EditText)findViewById(R.id.AddListEditText);
195        addListEditText.setOnEditorActionListener(new OnEditorActionListener() {
196            @Override
197            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
198            {
199                Log.d(L.TAG, "Editor Action " + actionId);
200                addList();
201                return true;
202            }
203        });
204        
205        EditText addItemEditText = (EditText)findViewById(R.id.AddItemEditText);
206        addItemEditText.setOnEditorActionListener(new OnEditorActionListener() {
207            @Override
208            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
209            {
210                addItem();
211                return true;
212            }
213        });
214        
215        LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
216        
217        View itemEditLayout = inflater.inflate(R.layout.item_edit, (ViewGroup)findViewById(R.id.item_edit_root));
218        
219        itemEditBuilder = new AlertDialog.Builder(this);
220        itemEditBuilder.setView(itemEditLayout)
221            .setCancelable(true)
222            .setTitle(R.string.itemEditTitle)
223            .setPositiveButton(R.string.itemEditPositive, new DialogInterface.OnClickListener() {
224                @Override
225                                public void onClick(DialogInterface dialog, int id) {
226                    itemEditOk();
227                }
228            })
229            .setNegativeButton(R.string.itemEditNegative, null);
230 
231        itemEditView = (EditText)itemEditLayout.findViewById(R.id.EditItemLabelEditText);
232        itemEditView.setOnEditorActionListener(new OnEditorActionListener() {
233            @Override
234            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
235            {
236                if(itemEditDialog != null)
237                {
238                    itemEditOk();
239                    itemEditDialog.cancel();
240                    return true;
241                }
242                else
243                {
244                    return false;
245                }
246            }
247        });
248        
249        View listEditLayout = inflater.inflate(R.layout.list_edit, (ViewGroup)findViewById(R.id.list_edit_root));
250 
251        listEditBuilder = new AlertDialog.Builder(this);
252        listEditBuilder.setView(listEditLayout)
253            .setCancelable(true)
254            .setTitle(R.string.listEditTitle)
255            .setPositiveButton(R.string.listEditPositive, new DialogInterface.OnClickListener() {
256                @Override
257                                public void onClick(DialogInterface dialog, int id) {
258                    listEditOk();
259                }
260            })
261            .setNegativeButton(R.string.listEditNegative, null);
262                
263        listEditView = (EditText)listEditLayout.findViewById(R.id.EditListLabelEditText);
264        listEditView.setOnEditorActionListener(new OnEditorActionListener() {
265            @Override
266            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
267            {
268                if(listEditDialog != null)
269                {
270                    listEditOk();
271                    listEditDialog.cancel();
272                    return true;
273                }
274                else
275                {
276                    return false;
277                }
278            }
279        });
280        
281        dataViewer.fetchLists();
282        listPropertiesAdapter.notifyDataSetChanged();
283        
284        moveItemToAction = new MoveToAction(
285                this, 
286                dataViewer, 
287                listPropertiesAdapter, 
288                itemPropertiesAdapter);
289        
290        deleteInactiveAction = new DeleteInactiveAction(
291                this, 
292                dataViewer, 
293                listPropertiesAdapter, 
294                itemPropertiesAdapter);
295        
296        if (savedInstanceState==null) 
297        {
298            Log.d(L.TAG, "SimplyDoActivity.onCreate()");
299        }
300        else 
301        {
302            Log.d(L.TAG, "SimplyDoActivity.onCreate() with a supplied state");
303            
304            Integer listId = (Integer)savedInstanceState.getSerializable("currentListId");
305            if(listId != null)
306            {
307                ListDesc listDesc = dataViewer.fetchList(listId);
308                if(listDesc != null)
309                {
310                    listSelected(listDesc, false);
311                }
312                else
313                {
314                    Log.w(L.TAG, "SimplyDoActivity.onCreate(): savedInstanceState had bad list ID");
315                }
316            }
317        }
318        
319        instance = this;
320    }
321    
322    public static SimplyDoActivity getInstance()
323    {
324        return instance;
325    }
326    
327    public DataViewer getDataVeiwer()
328    {
329        return dataViewer;
330    }
331    
332    public void cacheInvalidated()
333    {
334        Log.v(L.TAG, "SimplyDoActivity.cacheInvalidated(): Entered");
335        
336        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
337        int displayed = viewSwitch.getDisplayedChild();
338        if(displayed == 1)
339        {
340            setTitle(R.string.app_name);
341            viewSwitch.showPrevious();
342        }
343 
344        itemPropertiesAdapter.notifyDataSetChanged();
345        listPropertiesAdapter.notifyDataSetChanged();
346    }
347    
348    @Override
349    protected void onStart()
350    {
351        Log.v(L.TAG, "SimplyDoActivity.onStart(): called");
352        
353        super.onStart();
354        
355        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
356        
357        String itemSort = prefs.getString("itemSorting", ItemListSorter.PREF_ACTIVE_STARRED);
358        //Log.v(L.TAG, "itemSort = " + itemSort);
359        
360        itemListSorter.setSortingMode(itemSort);
361        itemListSorter.sort(dataViewer.getItemData());
362        itemPropertiesAdapter.notifyDataSetChanged();
363        
364        String listSort = prefs.getString("listSorting", ListListSorter.PREF_ALPHA);
365        listListSorter.setSortingMode(listSort);
366        //Log.v(L.TAG, "listSort = " + listSort);
367        
368        listListSorter.sort(dataViewer.getListData());
369        listPropertiesAdapter.notifyDataSetChanged();
370    }
371 
372 
373    @Override
374    protected void onSaveInstanceState(Bundle outState)
375    {
376        Log.v(L.TAG, "SimplyDoActivity.onSaveInstanceState() called");
377        
378        super.onSaveInstanceState(outState);
379        
380        ListDesc selectedList = dataViewer.getSelectedList();
381        if(selectedList != null)
382        {
383            outState.putSerializable("currentListId", selectedList.getId());
384        }
385        else
386        {
387            outState.putSerializable("currentListId", null);
388        }
389    }
390 
391 
392    @Override
393    protected void onDestroy()
394    {
395        Log.v(L.TAG, "SimplyDoActivity.onDestroy() called");
396        
397        super.onDestroy();
398        
399        dataViewer.close();
400        
401        instance = null;
402    }
403 
404 
405    @Override
406    public void onBackPressed()
407    {
408        Log.v(L.TAG, "SimplyDoActivity.onBackPressed() called");
409        
410        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
411        int displayed = viewSwitch.getDisplayedChild();
412        
413        if(displayed == 0)
414        {
415            super.onBackPressed();
416        }
417        else
418        {
419            setTitle(R.string.app_name);
420            viewSwitch.showPrevious();
421            dataViewer.setSelectedList(null);
422            itemPropertiesAdapter.notifyDataSetChanged();
423        }
424    }
425 
426 
427    @Override
428    public boolean onCreateOptionsMenu(Menu menu)
429    {
430        Log.v(L.TAG, "SimplyDoActivity.onCreateOptionsMenu() called");
431        return super.onCreateOptionsMenu(menu);
432    }
433 
434 
435    @Override
436    public boolean onPrepareOptionsMenu(Menu menu)
437    {
438        Log.v(L.TAG, "SimplyDoActivity.onPrepareOptionsMenu() called");
439        
440        menu.clear();
441        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
442        boolean isItemDisplay = viewSwitch.getDisplayedChild() != 0;
443        
444        if(isItemDisplay)
445        {
446            MenuItem deleteInactiveMI = menu.add(Menu.NONE, DELETE_INACTIVE, Menu.NONE, R.string.optionsMenuDeleteInactive);
447            deleteInactiveMI.setIcon(android.R.drawable.ic_menu_delete);
448        }
449        
450        MenuItem settingsMI = menu.add(Menu.NONE, SETTINGS, Menu.NONE, R.string.optionsMenuSettings);
451        settingsMI.setIcon(android.R.drawable.ic_menu_preferences);
452        
453        if(isItemDisplay)
454        {
455            MenuItem sortNowMI = menu.add(Menu.NONE, SORT_NOW, Menu.NONE, R.string.optionsMenuSort);
456            sortNowMI.setIcon(android.R.drawable.ic_menu_sort_by_size);
457        }
458        
459        return true;
460    }
461    
462    
463 
464    @Override
465    public boolean onMenuItemSelected(int featureId, MenuItem item)
466    {
467        Log.v(L.TAG, "SimplyDoActivity.onMenuItemSelected() called");
468        
469        switch(item.getItemId())
470        {
471        case DELETE_INACTIVE:
472        {
473            ListDesc currentList = dataViewer.getSelectedList();
474            if(currentList == null)
475            {
476                Log.e(L.TAG, "Delete inactive called but selected list was null");
477                return true;
478            }
479            Log.d(L.TAG, "Deleting Inactive");
480            
481            deleteInactiveAction.deleteInactive(DIALOG_DELETE_INACTIVE);
482            
483            return true;
484        }
485        case SETTINGS:
486        {
487            Intent settingsActivity = new Intent(getBaseContext(), SettingsActivity.class);
488            startActivity(settingsActivity);
489            return true;
490        }
491        case SORT_NOW:
492        {
493            itemListSorter.sort(dataViewer.getItemData());
494            itemPropertiesAdapter.notifyDataSetChanged();
495            return true;
496        }
497        case DELETE_LIST:
498            Log.d(L.TAG, "Got Delete List");
499            // Call are you sure?
500            showDialog(DIALOG_LIST_DELETE);
501            return true;
502        case DELETE_ITEM:
503            Log.d(L.TAG, "Got Delete Item");
504            if(ctxItem.isActive())
505            {
506                // Call are you sure?
507                showDialog(DIALOG_ITEM_DELETE);
508            }
509            else
510            {
511                contextDeleteItem();
512            }
513            return true;
514        case EDIT_ITEM:
515            Log.d(L.TAG, "Got Edit Item");
516            showDialog(DIALOG_ITEM_EDIT);
517            return true;
518        case EDIT_LIST:
519            Log.d(L.TAG, "Got Edit List");
520            showDialog(DIALOG_LIST_EDIT);
521            return true;
522        case TOGGLE_STAR:
523            if(ctxItem == null)
524            {
525                Log.e(L.TAG, "Toggle star but no context item!");
526                return true;
527            }
528            Log.d(L.TAG, "Toggling star");
529            
530            dataViewer.updateItemStarness(ctxItem, !ctxItem.isStar());
531            itemListSorter.markStarredUpdate(ctxItem);
532            itemPropertiesAdapter.notifyDataSetChanged();
533            return true;
534        case MOVE_ITEM:
535            if(ctxItem == null)
536            {
537                Log.e(L.TAG, "Move item selected but no context item!");
538                return true;
539            }
540            Log.d(L.TAG, "Displaying move item dialog");
541            
542            showDialog(DIALOG_ITEM_MOVE);
543            
544            return true;
545        }
546        
547        return super.onMenuItemSelected(featureId, item);
548    }
549 
550 
551    @Override
552    protected Dialog onCreateDialog(int id)
553    {
554        Log.v(L.TAG, "SimplyDoActivity.onCreateDialog(): Entered");
555        
556        Dialog dialog = null;
557                
558        switch(id)
559        {
560            case DIALOG_LIST_DELETE:
561            {
562                dialog = listDeleteBuilder.create();
563                break;
564            }
565            case DIALOG_ITEM_DELETE:
566            {
567                dialog = itemDeleteBuilder.create();
568                break;
569            }
570            case DIALOG_ITEM_EDIT:
571            {
572                itemEditDialog = itemEditBuilder.create();
573                itemEditDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
574                dialog = itemEditDialog;
575                break;
576            }
577            case DIALOG_LIST_EDIT:
578            {
579                listEditDialog = listEditBuilder.create();
580                listEditDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
581                dialog = listEditDialog;
582                break;
583            }
584            case DIALOG_ITEM_MOVE:
585            {
586                dialog = moveItemToAction.createDialog();
587                break;
588            }
589            case DIALOG_DELETE_INACTIVE:
590            {
591                dialog = deleteInactiveAction.createDialog();
592                break;
593            }
594        }
595        
596        if(dialog == null)
597        {
598            dialog = super.onCreateDialog(id);
599        }
600        
601        Log.v(L.TAG, "SimplyDoActivity.onCreateDialog(): Exit");
602        return dialog;
603    }
604    
605    
606    @Override
607    protected void onPrepareDialog(int id, Dialog dialog)
608    {
609        Log.v(L.TAG, "SimplyDoActivity.onPrepareDialog(): Entered");
610        
611        switch(id)
612        {
613        case DIALOG_ITEM_EDIT:
614            if(ctxItem != null)
615            {
616                itemEditView.setText(ctxItem.getLabel());
617            }
618            else
619            {
620                Log.e(L.TAG, "onPrepareDialog()/DIALOG_ITEM_EDIT called for nonexistant item");
621            }
622            break;
623        case DIALOG_LIST_EDIT:
624            if(ctxList != null)
625            {
626                listEditView.setText(ctxList.getLabel());            
627            }
628            else
629            {
630                Log.e(L.TAG, "onPrepareDialog()/DIALOG_LIST_EDIT called for nonexistant list");
631            }
632            break;
633        case DIALOG_ITEM_MOVE:
634            if(ctxItem != null)
635            {
636                moveItemToAction.prepareDialog(dialog, ctxItem);
637            }
638            else
639            {
640                Log.e(L.TAG, "onPrepareDialog()/DIALOG_ITEM_MOVE called for nonexistant item");
641            }
642            break;
643        default:
644            super.onPrepareDialog(id, dialog);
645            break;
646        }
647 
648        Log.v(L.TAG, "SimplyDoActivity.onPrepareDialog(): Exit");
649    }
650    
651    
652    private void listSelected(ListDesc list, boolean animate)
653    {
654        //Log.v(L.TAG, "SimplyDoActivity.listSelected() called on list " + list.getId());
655        
656        setTitle(list.getLabel());
657        
658        dataViewer.setSelectedList(list);
659        itemListSorter.sort(dataViewer.getItemData());
660        itemPropertiesAdapter.notifyDataSetChanged();
661        
662        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
663        
664        if(animate)
665        {
666            viewSwitch.showNext();
667        }
668        else
669        {
670            viewSwitch.reset();
671            viewSwitch.setAnimateFirstView(false);
672            viewSwitch.setDisplayedChild(1);
673        }
674    }
675    
676    
677    private void itemSelected(ItemDesc item)
678    {
679        Log.v(L.TAG, "Item selected " + item.getLabel());
680        
681        dataViewer.updateItemActiveness(item, !item.isActive());
682        itemListSorter.markActivityUpdate(item);
683        itemPropertiesAdapter.notifyDataSetChanged();
684        listPropertiesAdapter.notifyDataSetChanged();
685    }
686    
687    
688    private void addList()
689    {
690        EditText editText = (EditText)findViewById(R.id.AddListEditText);
691        
692        String txt = editText.getText().toString();
693        String txtTrim = txt.trim();
694        
695        if(txtTrim.length() > 0)
696        {
697            dataViewer.createList(txtTrim);
698            listListSorter.sort(dataViewer.getListData());
699            listPropertiesAdapter.notifyDataSetChanged();
700            editText.getText().clear();
701        }
702    }
703    
704    
705    private void addItem()
706    {
707        EditText editText = (EditText)findViewById(R.id.AddItemEditText);
708        
709        String txt = editText.getText().toString();
710        String txtTrim = txt.trim();
711        
712        if(txtTrim.length() > 0)
713        {
714            ListDesc currentList = dataViewer.getSelectedList();
715            if(currentList != null)
716            {
717                dataViewer.createItem(txtTrim);
718                itemPropertiesAdapter.notifyDataSetChanged();
719                listPropertiesAdapter.notifyDataSetChanged();
720                editText.getText().clear();
721            }
722            else
723            {
724                Log.e(L.TAG, "Add item called but selected list was null");
725            }
726        }
727    }
728    
729    
730    private void itemEditOk()
731    {
732        String txt = itemEditView.getText().toString();
733        
734        if(txt.trim().length() > 0)
735        {
736            dataViewer.updateItemLabel(ctxItem, txt);
737            itemListSorter.markEditUpdate(ctxItem);
738            itemPropertiesAdapter.notifyDataSetChanged();
739        }
740    }
741    
742    
743    private void listEditOk()
744    {
745        String txt = listEditView.getText().toString();
746        
747        if(txt.trim().length() > 0)
748        {
749            dataViewer.updateListLabel(ctxList.getId(), txt);
750            listPropertiesAdapter.notifyDataSetChanged();
751        }
752    }
753    
754    
755    private void contextDeleteList()
756    {
757        Log.d(L.TAG, "Deleting list " + ctxList.getLabel());
758        
759        dataViewer.deleteList(ctxList.getId());
760        listPropertiesAdapter.notifyDataSetChanged();
761        
762        ctxList = null;
763    }
764    
765    private void contextDeleteItem()
766    {
767        Log.d(L.TAG, "Deleting item " + ctxItem.getLabel());
768        
769        dataViewer.deleteItem(ctxItem);
770        itemPropertiesAdapter.notifyDataSetChanged();
771        listPropertiesAdapter.notifyDataSetChanged();
772        
773        ctxItem = null;
774    }
775    
776    
777    private class ItemsListReactor implements OnItemClickListener, View.OnCreateContextMenuListener
778    {
779        @Override
780        public void onCreateContextMenu(ContextMenu menu, View v,
781                ContextMenuInfo menuInfo)
782        {
783            Log.v(L.TAG, "ItemsListReactor.onCreateContextMenu()");
784            
785            AdapterContextMenuInfo ctxMenuInfo = (AdapterContextMenuInfo)menuInfo;
786            ListView listView = (ListView)findViewById(R.id.ItemsListView);
787            ctxItem = (ItemDesc)listView.getItemAtPosition(ctxMenuInfo.position);
788 
789            menu.setHeaderTitle(R.string.itemOptionsTitle);
790            menu.add(Menu.NONE, EDIT_ITEM, Menu.NONE, R.string.itemOptionsEdit);
791            menu.add(Menu.NONE, DELETE_ITEM, Menu.NONE, R.string.itemOptionsDelete);
792            int toggleText;
793            if(ctxItem.isStar())
794            {
795                toggleText = R.string.itemOptionsRemoveStar;
796            }
797            else
798            {
799                toggleText = R.string.itemOptionsAddStar;
800            }
801            menu.add(Menu.NONE, TOGGLE_STAR, Menu.NONE, toggleText);
802            if(dataViewer.getListData().size() > 1)
803            {
804                menu.add(Menu.NONE, MOVE_ITEM, Menu.NONE, R.string.itemOptionsMoveTo);
805            }
806        }
807 
808        
809        @Override
810        public void onItemClick(AdapterView<?> adapter, View view, int position,
811                long id)
812        {
813            Log.v(L.TAG, "ItemsListReactor.onItemClick()");
814            
815            ListView listView = (ListView)findViewById(R.id.ItemsListView);
816            ItemDesc itemDesc = (ItemDesc)listView.getItemAtPosition(position);
817            itemSelected(itemDesc);
818        }
819        
820    }
821    
822    private class ListsListReactor implements OnItemClickListener, View.OnCreateContextMenuListener
823    {
824        @Override
825        public void onItemClick(AdapterView<?> adapter, View view, int position,
826                long id)
827        {
828            Log.v(L.TAG, "ListsListReactor.onItemClick()");
829            
830            ListView listView = (ListView)findViewById(R.id.ListsListView);
831            ListDesc listDesc = (ListDesc)listView.getItemAtPosition(position);
832            listSelected(listDesc, true);
833        }
834 
835        @Override
836        public void onCreateContextMenu(ContextMenu menu, View v,
837                ContextMenuInfo menuInfo)
838        {
839            Log.v(L.TAG, "ListsListReactor.onCreateContextMenu()");
840            
841            AdapterContextMenuInfo ctxMenuInfo = (AdapterContextMenuInfo)menuInfo;
842            ListView listView = (ListView)findViewById(R.id.ListsListView);
843            ctxList = (ListDesc)listView.getItemAtPosition(ctxMenuInfo.position);
844 
845            menu.setHeaderTitle(R.string.listOptionsTitle);
846            menu.add(Menu.NONE, EDIT_LIST, Menu.NONE, R.string.listOptionsEdit);
847            menu.add(Menu.NONE, DELETE_LIST, Menu.NONE, R.string.listOptionsDelete);
848        }
849    
850    }
851}

[all classes][kdk.android.simplydo]
EMMA 2.0.5312 (C) Vladimir Roubtsov