My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.textuality.lifesaver2;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;

import com.textuality.aerc.Authenticator;

public class Saver extends Activity {

private WebView mReadout;

private static final String mHead = "<style>body {color: #fff; background: #000}\n" +
"a { text-decoration: none; font-weight: bold; color: #f88;}</style>";

@Override
protected void onCreate(Bundle mumble) {
super.onCreate(mumble);
setContentView(R.layout.save);

mReadout = (WebView) findViewById(R.id.saveData);
mReadout.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mReadout.setBackgroundColor(0xff000000);
mReadout.loadDataWithBaseURL(LifeSaver.PERSIST_APP_HREF,
"<html><head>" + mHead + "</head><body><p>" +
str(R.string.preparing_save) +
"</p></body></html>",
"text/html", "utf-8", null);

findViewById(R.id.saveBottom).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Saver.this, LifeSaver.class));
}
});
new PrepareUpload().execute();
}


class PrepareUpload extends AsyncTask<Void, String, String> {

private int mCallCount;
private int mMessageCount;
private Account mAccount;
private String mErrorMessage = null;

@Override
protected String doInBackground(Void... params) {
Cursor calls = getContentResolver().query(Columns.callsProvider(), null,
null, null, null);
mCallCount = calls.getCount();
Cursor messages = getContentResolver().query(Columns.messagesProvider(),
null, null, null, null);
mMessageCount = messages.getCount();
(new Notifier(Saver.this)).notifySave(str(R.string.saving) + mCallCount +
str(R.string.calls_and) + mMessageCount +
str(R.string.messages), false);

Account[] accounts = AccountManager.get(Saver.this).getAccountsByType("com.google");
if (accounts.length == 0) {
mErrorMessage = str(R.string.no_accounts);
return null;
}
mAccount = accounts[0];
Authenticator authent = Authenticator.appEngineAuthenticator(Saver.this, mAccount, LifeSaver.PERSIST_APP);

String authToken = authent.token();
if (authToken == null) {
mErrorMessage = authent.errorMessage();
return null;
}
return authToken;
}
@Override
protected void onPostExecute(String authToken) {
String body;
if (authToken == null) {
body = str(R.string.ouch) + " <br/><b>" +
mErrorMessage + "</b></p>";
} else {
body = "<p>" + str(R.string.your_life) +
mCallCount + str(R.string.calls_and) +
mMessageCount + str(R.string.messages) +
". " +
str(R.string.upload_started) +
"</p><p>" + str(R.string.visit) +
"&ldquo;" + mAccount.name + "&rdquo; " +
str(R.string.google_account) + ".</p>";
}

String page = "<html><head>" + mHead + "</head><body>" + body + "</body></html>";
mReadout.loadDataWithBaseURL(LifeSaver.PERSIST_APP_HREF, page, "text/html", "utf-8", null);

if (authToken != null) {
Intent intent = new Intent(Saver.this, UploadService.class);
intent.putExtra("authtoken", authToken);
startService(intent);
}
}
}

private String str(int id) {
return Saver.this.getString(id);
}
}

Change log

r23 by twb...@google.com on Feb 14, 2012   Diff
This is the published LifeSaver 2 v2.0
Go to: 
Project members, sign in to write a code review

Older revisions

r19 by twb...@google.com on Nov 25, 2011   Diff
Go to AppEngine-based back end.
This isn't released yet. If you build
and run it, it might well work, but
there's no guarantee that the back end
will be there or be functional.
...
r17 by twb...@google.com on Sep 15, 2010   Diff
Updating for LifeSaver 2

r14 by twb...@google.com on May 31, 2010   Diff
Move to 0.9.  Add the "type" field
back in for SMS, so users will
see whether the messages are sent and
received.  Fix bug reported by Alex
where Froyo phones will write SMS log
...
All revisions of this file

File info

Size: 4832 bytes, 127 lines
Powered by Google Project Hosting