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

COVERAGE SUMMARY FOR SOURCE FILE [SyncMessageHandler.java]

nameclass, %method, %block, %line, %
SyncMessageHandler.java33%  (1/3)18%  (2/11)3%   (9/271)7%   (4/60)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SyncMessageHandler$10%   (0/1)0%   (0/2)0%   (0/7)0%   (0/2)
SyncMessageHandler$1 (SyncMessageHandler): void 0%   (0/1)0%   (0/6)0%   (0/1)
onClick (DialogInterface, int): void 0%   (0/1)0%   (0/1)0%   (0/1)
     
class SyncMessageHandler$20%   (0/1)0%   (0/2)0%   (0/21)0%   (0/4)
SyncMessageHandler$2 (SyncMessageHandler, ErrorList): void 0%   (0/1)0%   (0/9)0%   (0/1)
onClick (DialogInterface, int): void 0%   (0/1)0%   (0/12)0%   (0/3)
     
class SyncMessageHandler100% (1/1)29%  (2/7)4%   (9/243)7%   (4/54)
access$000 (SyncMessageHandler): Activity 0%   (0/1)0%   (0/3)0%   (0/1)
handleMessage (Message): void 0%   (0/1)0%   (0/113)0%   (0/22)
handleSyncProgress (Message): void 0%   (0/1)0%   (0/50)0%   (0/10)
onSynchronizationDone (): void 0%   (0/1)0%   (0/32)0%   (0/8)
onSynchronizationStarted (): void 0%   (0/1)0%   (0/36)0%   (0/9)
<static initializer> 100% (1/1)100% (3/3)100% (1/1)
SyncMessageHandler (Activity): void 100% (1/1)100% (6/6)100% (3/3)

1/*
2 * Tomdroid
3 * Tomboy on Android
4 * http://www.launchpad.net/tomdroid
5 * 
6 * Copyright 2010, Rodja Trappe <mail@rodja.net>
7 * Copyright 2010, Benoit Garret <benoit.garret_launchpad@gadz.org>
8 * Copyright 2010, Olivier Bilodeau <olivier@bottomlesspit.org>
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.R;
28import org.tomdroid.sync.SyncManager;
29import org.tomdroid.sync.SyncService;
30import org.tomdroid.util.ErrorList;
31 
32import android.app.Activity;
33import android.app.AlertDialog;
34import android.content.DialogInterface;
35import android.content.DialogInterface.OnClickListener;
36import android.os.Handler;
37import android.os.Message;
38import android.util.Log;
39import android.view.View;
40import android.view.animation.Animation;
41import android.view.animation.AnimationUtils;
42import android.view.animation.RotateAnimation;
43import android.widget.ImageView;
44import android.widget.Toast;
45 
46public class SyncMessageHandler extends Handler {
47 
48        private static String TAG = "SycnMessageHandler";
49        private Activity activity;
50        
51        public SyncMessageHandler(Activity activity) {
52                this.activity = activity;
53        }
54 
55        @Override
56        public void handleMessage(Message msg) {
57 
58                String serviceDescription = SyncManager.getInstance().getCurrentService().getDescription();
59                String message = "";
60                        
61                switch (msg.what) {
62 
63                        case SyncService.PARSING_COMPLETE:
64                                final ErrorList errors = (ErrorList)msg.obj;
65                                if(errors.isEmpty()) {
66                                        message = this.activity.getString(R.string.messageSyncComplete);
67                                        message = String.format(message,serviceDescription);
68                                        Toast.makeText(activity, message, Toast.LENGTH_SHORT).show();
69                                } else {
70 
71                                        message = this.activity.getString(R.string.messageSyncError);
72                                        new AlertDialog.Builder(activity).setMessage(message)
73                                                .setTitle(this.activity.getString(R.string.error))
74                                                .setPositiveButton("Save to sd card", new OnClickListener() {
75                                                        public void onClick(DialogInterface dialog, int which) {
76                                                                if(!errors.save()) {
77                                                                        // TODO put string in a translatable bundle
78                                                                        Toast.makeText(activity, "Could not save the errors, please check your SD card.",
79                                                                                        Toast.LENGTH_SHORT).show();
80                                                                }
81                                                        }
82                                                })
83                                                .setNegativeButton("Close", new OnClickListener() {
84                                                        public void onClick(DialogInterface dialog, int which) {}
85                                                }).show();
86                                }
87                                break;
88 
89                        case SyncService.PARSING_NO_NOTES:
90                                message = this.activity.getString(R.string.messageSyncNoNote);
91                                message = String.format(message,serviceDescription);
92                                Toast.makeText(activity, message, Toast.LENGTH_SHORT).show();
93                                break;
94                                
95                        case SyncService.NO_INTERNET:
96                                // TODO put string in a translatable bundle
97                                Toast.makeText(activity, this.activity.getString(R.string.messageSyncNoConnection),
98                                                Toast.LENGTH_SHORT).show();
99                                break;
100                                
101                        case SyncService.NO_SD_CARD:
102                                // TODO put string in a translatable bundle
103                                Toast.makeText(activity, "SD card not found.",
104                                                Toast.LENGTH_SHORT).show();
105                                break;
106 
107                        case SyncService.SYNC_PROGRESS:
108                                handleSyncProgress(msg);
109                                break;
110 
111                        default:
112                                if (Tomdroid.LOGGING_ENABLED)
113                                        Log.i(TAG, "handler called with an unknown message");
114                                break;
115 
116                }
117        }
118 
119        private void handleSyncProgress(Message msg) {
120                ImageView syncIcon = (ImageView) activity.findViewById(R.id.syncIcon);
121 
122                RotateAnimation rotation = new RotateAnimation(180 * msg.arg2 / 100f,
123                                180 * msg.arg1 / 100f, Animation.RELATIVE_TO_SELF, 0.5f,
124                                Animation.RELATIVE_TO_SELF, 0.5f);
125                rotation.setDuration(700);
126                rotation.setFillAfter(true);
127                syncIcon.startAnimation(rotation);
128 
129                if (msg.arg1 == 0) {
130                        onSynchronizationStarted();
131                } else if (msg.arg1 == 100) {
132                        onSynchronizationDone();
133                }
134        }
135 
136        private void onSynchronizationDone() {
137                ImageView syncButton = (ImageView) activity.findViewById(R.id.sync);
138                ImageView syncIcon = (ImageView) activity.findViewById(R.id.syncIcon);
139 
140                syncButton.setClickable(true);
141                syncIcon.getDrawable().setAlpha(Actionbar.DEFAULT_ICON_ALPHA);
142 
143                View dot = activity.findViewById(R.id.sync_dot);
144                dot.setVisibility(View.INVISIBLE);
145                dot.getAnimation().setRepeatCount(0);
146        }
147 
148        private void onSynchronizationStarted() {
149                ImageView syncButton = (ImageView) activity.findViewById(R.id.sync);
150                ImageView syncIcon = (ImageView) activity.findViewById(R.id.syncIcon);
151 
152                syncButton.setClickable(false);
153                syncIcon.getDrawable().setAlpha(40);
154                
155                Animation pulse = AnimationUtils.loadAnimation(activity, R.anim.pulse);
156                View dot = activity.findViewById(R.id.sync_dot);
157                dot.setVisibility(View.VISIBLE);
158                dot.startAnimation(pulse);
159        }
160 
161}

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