EMMA Coverage Report (generated Tue Jun 26 14:54:12 CEST 2012)
[all classes][org.tomdroid.ui]

COVERAGE SUMMARY FOR SOURCE FILE [Tomdroid.java]

nameclass, %method, %block, %line, %
Tomdroid.java80%  (4/5)80%  (16/20)73%  (312/425)74%  (65,5/89)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Tomdroid$20%   (0/1)0%   (0/2)0%   (0/13)0%   (0/3)
Tomdroid$2 (Tomdroid, ProgressDialog): void 0%   (0/1)0%   (0/9)0%   (0/1)
handleMessage (Message): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class Tomdroid100% (1/1)83%  (10/12)73%  (273/373)72%  (54,5/76)
ViewList (Context): void 0%   (0/1)0%   (0/13)0%   (0/3)
onContextItemSelected (MenuItem): boolean 0%   (0/1)0%   (0/41)0%   (0/10)
onResume (): void 100% (1/1)39%  (24/61)65%  (8,5/13)
onOptionsItemSelected (MenuItem): boolean 100% (1/1)86%  (24/28)88%  (7/8)
showAboutDialog (): void 100% (1/1)93%  (65/70)67%  (6/9)
<static initializer> 100% (1/1)100% (13/13)100% (2/2)
Tomdroid (): void 100% (1/1)100% (9/9)100% (2/2)
ViewNote (long): void 100% (1/1)100% (24/24)100% (4/4)
onCreate (Bundle): void 100% (1/1)100% (69/69)100% (13/13)
onCreateContextMenu (ContextMenu, View, ContextMenu$ContextMenuInfo): void 100% (1/1)100% (19/19)100% (5/5)
onCreateOptionsMenu (Menu): boolean 100% (1/1)100% (9/9)100% (3/3)
onListItemClick (ListView, View, int, long): void 100% (1/1)100% (17/17)100% (4/4)
     
class Tomdroid$1100% (1/1)100% (2/2)100% (12/12)100% (4/4)
Tomdroid$1 (Tomdroid): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (6/6)100% (3/3)
     
class Tomdroid$3100% (1/1)100% (2/2)100% (9/9)100% (3/3)
Tomdroid$3 (Tomdroid): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (3/3)100% (2/2)
     
class Tomdroid$4100% (1/1)100% (2/2)100% (18/18)100% (4/4)
Tomdroid$4 (Tomdroid): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (12/12)100% (3/3)

1/*
2 * Tomdroid
3 * Tomboy on Android
4 * http://www.launchpad.net/tomdroid
5 * 
6 * Copyright 2009, 2010, 2011 Olivier Bilodeau <olivier@bottomlesspit.org>
7 * Copyright 2009, Benoit Garret <benoit.garret_launchpad@gadz.org>
8 * Copyright 2010, Rodja Trappe <mail@rodja.net>
9 * 
10 * This file is part of Tomdroid.
11 * 
12 * Tomdroid is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 * 
17 * Tomdroid is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 * GNU General Public License for more details.
21 * 
22 * You should have received a copy of the GNU General Public License
23 * along with Tomdroid.  If not, see <http://www.gnu.org/licenses/>.
24 */
25package org.tomdroid.ui;
26 
27import org.tomdroid.Note;
28import org.tomdroid.NoteManager;
29import org.tomdroid.R;
30import org.tomdroid.sync.ServiceAuth;
31import org.tomdroid.sync.SyncManager;
32import org.tomdroid.sync.SyncService;
33import org.tomdroid.util.FirstNote;
34import org.tomdroid.util.Preferences;
35import org.tomdroid.util.Send;
36 
37import android.app.AlertDialog;
38import android.app.ListActivity;
39import android.app.ProgressDialog;
40import android.content.Context;
41import android.content.DialogInterface;
42import android.content.Intent;
43import android.content.DialogInterface.OnClickListener;
44import android.content.pm.PackageManager.NameNotFoundException;
45import android.database.Cursor;
46import android.net.Uri;
47import android.os.Bundle;
48import android.os.Environment;
49import android.os.Handler;
50import android.os.Message;
51import android.util.Log;
52import android.view.ContextMenu;
53import android.view.Menu;
54import android.view.MenuInflater;
55import android.view.MenuItem;
56import android.view.View;
57import android.view.ContextMenu.ContextMenuInfo;
58import android.widget.ListAdapter;
59import android.widget.ListView;
60import android.widget.TextView;
61import android.widget.AdapterView.AdapterContextMenuInfo;
62 
63public class Tomdroid extends ListActivity {
64 
65        // Global definition for Tomdroid
66        public static final String        AUTHORITY                        = "org.tomdroid.notes";
67        public static final Uri                CONTENT_URI                        = Uri
68                                                                                                                        .parse("content://" + AUTHORITY
69                                                                                                                                        + "/notes");
70        public static final String        CONTENT_TYPE                = "vnd.android.cursor.dir/vnd.tomdroid.note";
71        public static final String        CONTENT_ITEM_TYPE        = "vnd.android.cursor.item/vnd.tomdroid.note";
72        public static final String        PROJECT_HOMEPAGE        = "http://www.launchpad.net/tomdroid/";
73 
74        // config parameters
75        // TODO hardcoded for now
76        public static final String        NOTES_PATH                        = Environment.getExternalStorageDirectory()
77                                                                                                                        + "/tomdroid/";
78        // Logging should be disabled for release builds
79        public static final boolean        LOGGING_ENABLED                = false;
80        // Set this to false for release builds, the reason should be obvious
81        public static final boolean        CLEAR_PREFERENCES        = false;
82 
83        // Logging info
84        private static final String        TAG                                        = "Tomdroid";
85 
86        // UI to data model glue
87        private TextView                        listEmptyView;
88        private ListAdapter                        adapter;
89 
90        // UI feedback handler
91        private Handler        syncMessageHandler        = new SyncMessageHandler(this);
92        
93        /** Called when the activity is created. */
94        @Override
95        public void onCreate(Bundle savedInstanceState) {
96                super.onCreate(savedInstanceState);
97 
98                setContentView(R.layout.main);
99                Preferences.init(this, CLEAR_PREFERENCES);
100 
101                // did we already show the warning and got destroyed by android's activity killer?
102                if (Preferences.getBoolean(Preferences.Key.FIRST_RUN)) {
103                        Log.i(TAG, "Tomdroid is first run.");
104                        
105                        // add a first explanatory note
106                        NoteManager.putNote(this, FirstNote.createFirstNote());
107                        
108                        // Warn that this is a "will eat your babies" release
109                        new AlertDialog.Builder(this).setMessage(getString(R.string.strWelcome)).setTitle(
110                                        getString(R.string.titleWelcome)).setNeutralButton(getString(R.string.btnOk), new OnClickListener() {
111                                public void onClick(DialogInterface dialog, int which) {
112                                        Preferences.putBoolean(Preferences.Key.FIRST_RUN, false);
113                                        dialog.dismiss();
114                                }
115                        }).setIcon(R.drawable.icon).show();
116                }
117 
118                // adapter that binds the ListView UI to the notes in the note manager
119                adapter = NoteManager.getListAdapter(this);
120                setListAdapter(adapter);
121 
122                // set the view shown when the list is empty
123                // TODO default empty-list text is butt-ugly!
124                listEmptyView = (TextView) findViewById(R.id.list_empty);
125                getListView().setEmptyView(listEmptyView);
126                
127                registerForContextMenu((ListView)findViewById(android.R.id.list));
128        }
129 
130        @Override
131        public boolean onCreateOptionsMenu(Menu menu) {
132 
133                // Create the menu based on what is defined in res/menu/main.xml
134                MenuInflater inflater = getMenuInflater();
135                inflater.inflate(R.menu.main, menu);
136                return true;
137 
138        }
139 
140        @Override
141        public boolean onOptionsItemSelected(MenuItem item) {
142                switch (item.getItemId()) {
143                        case R.id.menuAbout:
144                                showAboutDialog();
145                                return true;
146 
147                        case R.id.menuPrefs:
148                                startActivity(new Intent(this, PreferencesActivity.class));
149                                return true;
150                                
151                        case R.id.menuSearch:
152                                startSearch(null, false, null, false);
153                                return true;
154                }
155 
156                return super.onOptionsItemSelected(item);
157        }
158        
159        @Override
160        public void onCreateContextMenu(ContextMenu menu, View v,
161                        ContextMenuInfo menuInfo) {
162                MenuInflater inflater = getMenuInflater();
163            inflater.inflate(R.menu.main_longclick, menu);
164            menu.setHeaderTitle(getString(R.string.noteOptions));
165                super.onCreateContextMenu(menu, v, menuInfo);
166        }
167 
168        @Override
169        public boolean onContextItemSelected(MenuItem item) {
170                AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
171                long noteId = info.id;
172                Uri intentUri = Uri.parse(Tomdroid.CONTENT_URI+"/"+noteId);
173                Note note = NoteManager.getNote(this, intentUri);
174                
175                switch (item.getItemId()) {
176                        case R.id.menu_send:
177                                (new Send(this, note)).send();
178                                break;
179                        case R.id.view:
180                                this.ViewNote(noteId);
181                                break;
182                                
183                        default:
184                                break;
185                }
186                
187                return super.onContextItemSelected(item);
188        }
189 
190        public void onResume() {
191                super.onResume();
192                Intent intent = this.getIntent();
193 
194                SyncService currentService = SyncManager.getInstance().getCurrentService();
195                
196                if (currentService.needsAuth() && intent != null) {
197                        Uri uri = intent.getData();
198 
199                        if (uri != null && uri.getScheme().equals("tomdroid")) {
200                                Log.i(TAG, "Got url : " + uri.toString());
201 
202                                final ProgressDialog dialog = ProgressDialog.show(this, "",        getString(R.string.prefSyncCompleteAuth), true, false);
203 
204                                Handler handler = new Handler() {
205 
206                                        @Override
207                                        public void handleMessage(Message msg) {
208                                                dialog.dismiss();
209                                        }
210 
211                                };
212 
213                                ((ServiceAuth) currentService).remoteAuthComplete(uri, handler);
214                        }
215                }
216                
217                SyncManager.setActivity(this);
218                SyncManager.setHandler(this.syncMessageHandler);
219        }
220 
221        private void showAboutDialog() {
222 
223                // grab version info
224                String ver;
225                try {
226                        ver = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
227                } catch (NameNotFoundException e) {
228                        e.printStackTrace();
229                        ver = "Not found!";
230                }
231 
232                // format the string
233                String aboutDialogFormat = getString(R.string.strAbout);
234                String aboutDialogStr = String.format(aboutDialogFormat, getString(R.string.app_desc), // App description
235                                getString(R.string.author), // Author name
236                                ver // Version
237                                );
238 
239                // build and show the dialog
240                new AlertDialog.Builder(this).setMessage(aboutDialogStr).setTitle(getString(R.string.titleAbout))
241                                .setIcon(R.drawable.icon).setNegativeButton(getString(R.string.btnProjectPage), new OnClickListener() {
242                                        public void onClick(DialogInterface dialog, int which) {
243                                                startActivity(new Intent(Intent.ACTION_VIEW, Uri
244                                                                .parse(Tomdroid.PROJECT_HOMEPAGE)));
245                                                dialog.dismiss();
246                                        }
247                                }).setPositiveButton(getString(R.string.btnOk), new OnClickListener() {
248                                        public void onClick(DialogInterface dialog, int which) {
249                                                dialog.dismiss();
250                                        }
251                                }).show();
252        }
253 
254        @Override
255        protected void onListItemClick(ListView l, View v, int position, long id) {
256 
257                Cursor item = (Cursor) adapter.getItem(position);
258                long noteId = item.getInt(item.getColumnIndexOrThrow(Note.ID));
259                        this.ViewNote(noteId);
260                
261        }
262        
263        public void ViewNote(long noteId) {
264                Uri intentUri = Uri.parse(Tomdroid.CONTENT_URI + "/" + noteId);
265                Intent i = new Intent(Intent.ACTION_VIEW, intentUri, this, ViewNote.class);
266                startActivity(i);
267        }
268        
269        public static void ViewList(Context View) {
270                if ( ! ( View instanceof Tomdroid ) )
271            {
272                        View.startActivity(new Intent(View, Tomdroid.class)
273                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
274            }
275        }
276 
277}

[all classes][org.tomdroid.ui]
EMMA 0.0.0 (unsupported private build) (C) Vladimir Roubtsov