EMMA Coverage Report (generated Wed Jun 27 17:43:42 CEST 2012)
[all classes][aarddict.android]

COVERAGE SUMMARY FOR SOURCE FILE [BaseDictionaryActivity.java]

nameclass, %method, %block, %line, %
BaseDictionaryActivity.java83%  (5/6)84%  (16/19)81%  (305/376)84%  (70/83)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseDictionaryActivity$3$10%   (0/1)0%   (0/2)0%   (0/36)0%   (0/8)
BaseDictionaryActivity$3$1 (BaseDictionaryActivity$3): void 0%   (0/1)0%   (0/6)0%   (0/1)
run (): void 0%   (0/1)0%   (0/30)0%   (0/7)
     
class BaseDictionaryActivity$1100% (1/1)67%  (2/3)52%  (29/56)50%  (5/10)
onServiceDisconnected (ComponentName): void 0%   (0/1)0%   (0/27)0%   (0/5)
BaseDictionaryActivity$1 (BaseDictionaryActivity): void 100% (1/1)100% (6/6)100% (1/1)
onServiceConnected (ComponentName, IBinder): void 100% (1/1)100% (23/23)100% (4/4)
     
class BaseDictionaryActivity$3100% (1/1)100% (2/2)83%  (40/48)86%  (6/7)
run (): void 100% (1/1)81%  (34/42)83%  (5/6)
BaseDictionaryActivity$3 (BaseDictionaryActivity): void 100% (1/1)100% (6/6)100% (1/1)
     
class BaseDictionaryActivity100% (1/1)100% (8/8)100% (114/114)100% (31/31)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
BaseDictionaryActivity (): void 100% (1/1)100% (9/9)100% (2/2)
access$000 (): String 100% (1/1)100% (2/2)100% (1/1)
onCreate (Bundle): void 100% (1/1)100% (35/35)100% (9/9)
onDestroy (): void 100% (1/1)100% (11/11)100% (4/4)
onDictionaryOpenFinished (): void 100% (1/1)100% (1/1)100% (1/1)
onDictionaryServiceConnected (): void 100% (1/1)100% (17/17)100% (4/4)
registerProgressReceiver (): void 100% (1/1)100% (35/35)100% (10/10)
     
class BaseDictionaryActivity$2100% (1/1)100% (2/2)100% (111/111)100% (29/29)
BaseDictionaryActivity$2 (BaseDictionaryActivity): void 100% (1/1)100% (6/6)100% (1/1)
onReceive (Context, Intent): void 100% (1/1)100% (105/105)100% (28/28)
     
class BaseDictionaryActivity$3$2100% (1/1)100% (2/2)100% (11/11)100% (3/3)
BaseDictionaryActivity$3$2 (BaseDictionaryActivity$3): void 100% (1/1)100% (6/6)100% (1/1)
run (): void 100% (1/1)100% (5/5)100% (2/2)

1/* This file is part of Aard Dictionary for Android <http://aarddict.org>.
2 * 
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 3
5 * as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * GNU General Public License <http://www.gnu.org/licenses/gpl-3.0.txt>
11 * for more details.
12 * 
13 * Copyright (C) 2010 Igor Tkach
14*/
15 
16package aarddict.android;
17 
18import android.app.Activity;
19import android.app.ProgressDialog;
20import android.content.BroadcastReceiver;
21import android.content.ComponentName;
22import android.content.Context;
23import android.content.Intent;
24import android.content.IntentFilter;
25import android.content.ServiceConnection;
26import android.os.IBinder;
27import android.util.Log;
28import android.view.Window;
29import android.widget.Toast;
30 
31abstract class BaseDictionaryActivity extends Activity {
32    
33    private final static String         TAG        = BaseDictionaryActivity.class
34                                                   .getName();
35    
36    protected final static String ACTION_NO_DICTIONARIES = "aarddict.android.ACTION_NO_DICTIONARIES";
37    
38    protected BroadcastReceiver   broadcastReceiver;    
39    protected DictionaryService dictionaryService;
40    
41    
42    private ServiceConnection connection = new ServiceConnection() {
43        public void onServiceConnected(ComponentName className, IBinder service) {
44            dictionaryService = ((DictionaryService.LocalBinder)service).getService();
45            Log.d(TAG, "Service connected: " + dictionaryService);            
46            onDictionaryServiceConnected();
47        }
48 
49        public void onServiceDisconnected(ComponentName className) {
50            Log.d(TAG, "Service disconnected: " + dictionaryService);
51            dictionaryService = null;
52            Toast.makeText(BaseDictionaryActivity.this, "Dictionary service disconnected, quitting...",
53                    Toast.LENGTH_LONG).show();
54            finish();
55        }
56    };
57 
58    private void registerProgressReceiver() {
59        IntentFilter intentFilter = new IntentFilter();
60        intentFilter.addAction(DictionaryService.DICT_OPEN_FAILED);
61        intentFilter.addAction(DictionaryService.DISCOVERY_STARTED);
62        intentFilter.addAction(DictionaryService.DISCOVERY_FINISHED);
63        intentFilter.addAction(DictionaryService.OPEN_FINISHED);
64        intentFilter.addAction(DictionaryService.OPEN_STARTED);
65        intentFilter.addAction(DictionaryService.OPENED_DICT);
66                       
67        broadcastReceiver = new BroadcastReceiver() {
68        
69            ProgressDialog discoveryProgress;
70            ProgressDialog openProgress;
71            
72            @Override
73            public void onReceive(Context context, Intent intent) {
74                String a = intent.getAction();
75                if (a.equals(DictionaryService.DISCOVERY_STARTED)) {
76                    Log.d(TAG, "dictionary disconvery started");
77                    if (discoveryProgress == null) {
78                        discoveryProgress = new DiscoveryProgressDialog(context);
79                    }
80                    discoveryProgress.show();
81                } else
82                if (a.equals(DictionaryService.DISCOVERY_FINISHED)) {
83                    Log.d(TAG, "dictionary discovery finished");
84                    if (discoveryProgress != null) {
85                        discoveryProgress.dismiss();
86                        discoveryProgress = null;
87                    }                   
88                } else
89                if (a.equals(DictionaryService.OPEN_STARTED)) { 
90                    Log.d(TAG, "dictionary open started");
91                    int count = intent.getIntExtra("count", 0);
92                    if (openProgress == null) {
93                        openProgress = new OpeningProgressDialog(context);
94                    }
95                    openProgress.setMax(count);
96                    openProgress.show();
97                } else
98                if (a.equals(DictionaryService.DICT_OPEN_FAILED) || 
99                        a.equals(DictionaryService.OPENED_DICT)) {
100                    if (openProgress != null) {
101                        openProgress.incrementProgressBy(1); 
102                    }
103                } else
104                if (a.equals(DictionaryService.OPEN_FINISHED)) {
105                    if (openProgress != null) {                     
106                        openProgress.dismiss();
107                        openProgress = null;
108                    }
109                    onDictionaryOpenFinished();
110                }                               
111            }
112        };
113        registerReceiver(broadcastReceiver, intentFilter);        
114    }
115          
116    protected void onCreate(android.os.Bundle savedInstanceState) {
117        super.onCreate(savedInstanceState);
118        getWindow().requestFeature(Window.FEATURE_LEFT_ICON);        
119        registerProgressReceiver();
120        initUI();
121        getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.aarddict);
122        Intent dictServiceIntent = new Intent(this, DictionaryService.class);
123        startService(dictServiceIntent);
124        bindService(dictServiceIntent, connection, 0);        
125    };
126            
127    abstract void initUI();
128    
129    void onDictionaryServiceConnected() {                        
130                if (dictionaryService.getDictionaries().isEmpty()) {
131                new Thread(new Runnable() {                                
132                                public void run() {
133                                        dictionaryService.openDictionaries();
134                                        Log.d(TAG, 
135                                                        String.format("After openDictionaries() we have %d dictionaries", 
136                                                                        dictionaryService.getDictionaries().size()));
137                                        if (dictionaryService.getDictionaries().isEmpty()) {
138                                                runOnUiThread(new Runnable() {                                                        
139                                                        public void run() {
140                                                                Intent next = new Intent();
141                                                                next.setAction(ACTION_NO_DICTIONARIES);
142                                                                next.setClass(getApplicationContext(), DictionariesActivity.class);
143                                                                Log.d(TAG, "No dictionaries, starting Dictionaries activity");
144                                                                startActivity(next);
145                                                                finish();
146                                                        }
147                                                });
148                                        } else {
149                                                runOnUiThread(new Runnable() {                                                                
150                                                        public void run() {
151                                                                onDictionaryServiceReady();
152                                                        }
153                                                });                                                    
154                                        }
155                                }
156                        }).start();
157                }
158                else {
159                        onDictionaryServiceReady();
160                }
161    };
162    
163    abstract void onDictionaryServiceReady();
164    void onDictionaryOpenFinished(){};
165            
166    protected void onDestroy() {
167        super.onDestroy();
168        unregisterReceiver(broadcastReceiver);
169        unbindService(connection);
170    }    
171}

[all classes][aarddict.android]
EMMA 0.0.0 (unsupported private build) (C) Vladimir Roubtsov