EMMA Coverage Report (generated Fri Jun 03 16:44:51 CEST 2016)
[all classes][kdk.android.simplydo]

COVERAGE SUMMARY FOR SOURCE FILE [SimplyDoActivity.java]

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

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