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

COVERAGE SUMMARY FOR SOURCE FILE [MoveToAction.java]

nameclass, %method, %block, %line, %
MoveToAction.java100% (4/4)100% (15/15)96%  (304/316)94%  (65,9/70)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MoveToAction100% (1/1)100% (9/9)96%  (268/280)94%  (58,9/63)
prepareDialog (Dialog, ItemDesc): void 100% (1/1)91%  (74/81)89%  (16,9/19)
listSelected (): void 100% (1/1)92%  (58/63)85%  (11/13)
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            @Override
70                        public void onClick(DialogInterface dialog, int id) {
71                listSelected();
72            }
73        };
74        cancelClickedListener = new DialogInterface.OnClickListener() {
75            @Override
76                        public void onClick(DialogInterface dialog, int id) {
77                Log.v(L.TAG, "MoveToAction.cancelClickedListener: Cancel");
78                endDialog();
79            }
80        };
81    }
82    
83    
84    public Dialog createDialog()
85    {
86        aa = new ArrayAdapter<String>(context, android.R.layout.select_dialog_singlechoice);
87        
88        AlertDialog.Builder builder = new AlertDialog.Builder(context);
89        builder.setTitle(R.string.moveToTitle);
90        builder.setSingleChoiceItems(aa, -1, itemClickedListener);
91        builder.setPositiveButton(R.string.moveToPositive, listSelectedListener);
92        builder.setNegativeButton(R.string.moveToNegative, cancelClickedListener);
93        builder.setCancelable(true);
94        
95        AlertDialog alertDialog = builder.create();
96        return alertDialog;
97    }
98    
99    
100    public void prepareDialog(Dialog dialog, ItemDesc ctxItem)
101    {
102        if(aa == null)
103        {
104            Log.e(L.TAG, "MoveToAction.prepareDialog() called before createDialog()");
105            return;
106        }
107        
108 
109        ListDesc selectedListDesc = dataViewer.getSelectedList();
110        dataViewList.clear();
111        dataViewList.addAll(dataViewer.getListData());
112        dataViewList.remove(selectedListDesc);
113        
114        aa.clear();
115        int selectedId = selectedListDesc.getId();
116        for(int i = 0; i < dataViewList.size(); i++)
117        {
118            ListDesc listDesc = dataViewList.get(i);
119            if(listDesc.getId() != selectedId)
120            {
121                aa.add(listDesc.getLabel());
122            }
123        }
124        
125        aa.notifyDataSetChanged();
126        
127        AlertDialog alertDialog = (AlertDialog)dialog;
128        okButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
129        okButton.setEnabled(selectedItem != null);
130        
131        this.ctxItem = ctxItem;
132    }
133    
134    
135    private void itemClicked(DialogInterface dialog, int which)
136    {
137        Log.d(L.TAG, "MoveToAction.itemClicked(): Selected " + which);
138 
139        if(!okButton.isEnabled())
140        {
141            okButton.setEnabled(true);
142        }
143        
144        selectedItem = which;
145    }
146    
147    
148    private void listSelected()
149    {
150        if(selectedItem == null)
151        {
152            Log.e(L.TAG, "MoveToAction.listSelected(): called without a selected item");
153            return;
154        }
155        Log.d(L.TAG, "MoveToAction.listSelected(): called");
156        
157        ListDesc listDesc = dataViewList.get(selectedItem);
158        dataViewer.moveItem(ctxItem, listDesc.getId());
159        itemPropertiesAdapter.notifyDataSetChanged();
160        listPropertiesAdapter.notifyDataSetChanged();
161        
162        String itemMoved = String.format(context.getString(R.string.moveToMoved), ctxItem.getLabel(), listDesc.getLabel());
163        Toast t = Toast.makeText(context, itemMoved, Toast.LENGTH_SHORT);
164        t.show();
165        
166        endDialog();
167    }
168    
169    
170    private void endDialog()
171    {
172        // make sure left overs from prepareDialog don't hold unneeded objects
173        ctxItem = null;
174        okButton = null;
175        dataViewList.clear();
176        aa.clear();
177    }
178}

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