EMMA Coverage Report (generated Thu Apr 28 17:26:26 CEST 2016)
[all classes][kdk.android.simplydo]

COVERAGE SUMMARY FOR SOURCE FILE [MoveToAction.java]

nameclass, %method, %block, %line, %
MoveToAction.java100% (4/4)100% (15/15)97%  (306/316)94%  (66/70)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MoveToAction100% (1/1)100% (9/9)96%  (270/280)94%  (59/63)
listSelected (): void 100% (1/1)92%  (58/63)85%  (11/13)
prepareDialog (Dialog, ItemDesc): void 100% (1/1)94%  (76/81)89%  (17/19)
MoveToAction (Context, DataViewer, ListPropertiesAdapter, ItemPropertiesAdapt... 100% (1/1)100% (41/41)100% (11/11)
access$000 (MoveToAction, DialogInterface, int): void 100% (1/1)100% (5/5)100% (1/1)
access$100 (MoveToAction): void 100% (1/1)100% (3/3)100% (1/1)
access$200 (MoveToAction): void 100% (1/1)100% (3/3)100% (1/1)
createDialog (): Dialog 100% (1/1)100% (47/47)100% (9/9)
endDialog (): void 100% (1/1)100% (13/13)100% (5/5)
itemClicked (DialogInterface, int): void 100% (1/1)100% (24/24)100% (5/5)
     
class MoveToAction$1100% (1/1)100% (2/2)100% (12/12)100% (3/3)
MoveToAction$1 (MoveToAction): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (6/6)100% (2/2)
     
class MoveToAction$2100% (1/1)100% (2/2)100% (10/10)100% (3/3)
MoveToAction$2 (MoveToAction): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (4/4)100% (2/2)
     
class MoveToAction$3100% (1/1)100% (2/2)100% (14/14)100% (4/4)
MoveToAction$3 (MoveToAction): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (8/8)100% (3/3)

1/*
2 * Copyright (C) 2013 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 java.util.ArrayList;
23import java.util.List;
24 
25import android.app.AlertDialog;
26import android.app.Dialog;
27import android.content.Context;
28import android.content.DialogInterface;
29import android.util.Log;
30import android.widget.ArrayAdapter;
31import android.widget.Button;
32import android.widget.Toast;
33 
34public class MoveToAction
35{
36    private Context context;
37    private DataViewer dataViewer;
38    private ListPropertiesAdapter listPropertiesAdapter;
39    private ItemPropertiesAdapter itemPropertiesAdapter;
40    
41    private ArrayAdapter<String> aa;
42    private Button okButton;
43    private DialogInterface.OnClickListener itemClickedListener;
44    private DialogInterface.OnClickListener listSelectedListener;
45    private DialogInterface.OnClickListener cancelClickedListener;
46    private Integer selectedItem = null;
47    private List<ListDesc> dataViewList = new ArrayList<ListDesc>();
48    private ItemDesc ctxItem;
49    
50    public MoveToAction(
51            Context context, 
52            DataViewer dataViewer, 
53            ListPropertiesAdapter listPropertiesAdapter, 
54            ItemPropertiesAdapter itemPropertiesAdapter)
55    {
56        this.context = context;
57        this.dataViewer = dataViewer;
58        this.listPropertiesAdapter = listPropertiesAdapter;
59        this.itemPropertiesAdapter = itemPropertiesAdapter;
60        
61        itemClickedListener = new DialogInterface.OnClickListener() {
62            @Override
63            public void onClick(DialogInterface dialog, int which)
64            {
65                itemClicked(dialog, which);
66            }
67        };
68        listSelectedListener = new DialogInterface.OnClickListener() {
69            public void onClick(DialogInterface dialog, int id) {
70                listSelected();
71            }
72        };
73        cancelClickedListener = new DialogInterface.OnClickListener() {
74            public void onClick(DialogInterface dialog, int id) {
75                Log.v(L.TAG, "MoveToAction.cancelClickedListener: Cancel");
76                endDialog();
77            }
78        };
79    }
80    
81    
82    public Dialog createDialog()
83    {
84        aa = new ArrayAdapter<String>(context, android.R.layout.select_dialog_singlechoice);
85        
86        AlertDialog.Builder builder = new AlertDialog.Builder(context);
87        builder.setTitle(R.string.moveToTitle);
88        builder.setSingleChoiceItems(aa, -1, itemClickedListener);
89        builder.setPositiveButton(R.string.moveToPositive, listSelectedListener);
90        builder.setNegativeButton(R.string.moveToNegative, cancelClickedListener);
91        builder.setCancelable(true);
92        
93        AlertDialog alertDialog = builder.create();
94        return alertDialog;
95    }
96    
97    
98    public void prepareDialog(Dialog dialog, ItemDesc ctxItem)
99    {
100        if(aa == null)
101        {
102            Log.e(L.TAG, "MoveToAction.prepareDialog() called before createDialog()");
103            return;
104        }
105        
106 
107        ListDesc selectedListDesc = dataViewer.getSelectedList();
108        dataViewList.clear();
109        dataViewList.addAll(dataViewer.getListData());
110        dataViewList.remove(selectedListDesc);
111        
112        aa.clear();
113        int selectedId = selectedListDesc.getId();
114        for(int i = 0; i < dataViewList.size(); i++)
115        {
116            ListDesc listDesc = dataViewList.get(i);
117            if(listDesc.getId() != selectedId)
118            {
119                aa.add(listDesc.getLabel());
120            }
121        }
122        
123        aa.notifyDataSetChanged();
124        
125        AlertDialog alertDialog = (AlertDialog)dialog;
126        okButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
127        okButton.setEnabled(selectedItem != null);
128        
129        this.ctxItem = ctxItem;
130    }
131    
132    
133    private void itemClicked(DialogInterface dialog, int which)
134    {
135        Log.d(L.TAG, "MoveToAction.itemClicked(): Selected " + which);
136 
137        if(!okButton.isEnabled())
138        {
139            okButton.setEnabled(true);
140        }
141        
142        selectedItem = which;
143    }
144    
145    
146    private void listSelected()
147    {
148        if(selectedItem == null)
149        {
150            Log.e(L.TAG, "MoveToAction.listSelected(): called without a selected item");
151            return;
152        }
153        Log.d(L.TAG, "MoveToAction.listSelected(): called");
154        
155        ListDesc listDesc = dataViewList.get(selectedItem);
156        dataViewer.moveItem(ctxItem, listDesc.getId());
157        itemPropertiesAdapter.notifyDataSetChanged();
158        listPropertiesAdapter.notifyDataSetChanged();
159        
160        String itemMoved = String.format(context.getString(R.string.moveToMoved), ctxItem.getLabel(), listDesc.getLabel());
161        Toast t = Toast.makeText(context, itemMoved, Toast.LENGTH_SHORT);
162        t.show();
163        
164        endDialog();
165    }
166    
167    
168    private void endDialog()
169    {
170        // make sure left overs from prepareDialog don't hold unneeded objects
171        ctxItem = null;
172        okButton = null;
173        dataViewList.clear();
174        aa.clear();
175    }
176}

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