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
/*
* G2Android
* Copyright (c) 2009 Anthony Dahanne
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package net.dahanne.android.g2android.activity;

import net.dahanne.android.g2android.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;

/**
* THIS CLASS WAS COPIED FROM THE GPL project Astrid
* https://github.com/todoroo/astrid
*
* Displays an EULA ("End User License Agreement") that the user has to accept
* before using the application. Your application should call
* {@link Eula#showEula(android.app.Activity)} in the onCreate() method of the
* first activity. If the user accepts the EULA, it will never be shown again.
* If the user refuses, {@link android.app.Activity#finish()} is invoked on your
* activity.
*/
class FirstTime {
private static final String PREFERENCE_EULA_ACCEPTED = "eula.accepted"; //$NON-NLS-1$
private static final String PREFERENCES_EULA = "eula"; //$NON-NLS-1$

/**
* Displays the EULA if necessary. This method should be called from the
* onCreate() method of your main Activity.
*
* @param activity
* The Activity to finish if the user rejects the EULA
*/
static void showEula(final Activity activity, boolean isExplicitlyCalled) {
final SharedPreferences preferences = activity.getSharedPreferences(
PREFERENCES_EULA, Activity.MODE_PRIVATE);
if (preferences.getBoolean(PREFERENCE_EULA_ACCEPTED, false)
&& !isExplicitlyCalled) {
return;
}

final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.switch_title);
builder.setCancelable(true);
builder.setPositiveButton(R.string.download_from_market,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
downloadFromMarket(activity, preferences);
}
});
builder.setNegativeButton(R.string.download_from_project_home,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
downloadFromProjectHome(activity, preferences);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
refuse(activity);
}
});
builder.setMessage(R.string.switching_to_regalandroid);
builder.show();
}

private static void downloadFromMarket(Activity activity,
SharedPreferences preferences) {
preferences.edit().putBoolean(PREFERENCE_EULA_ACCEPTED, true).commit();
Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://market.android.com/details?id=net.dahanne.android.regalandroid"));
activity.startActivity(intent);

}

private static void downloadFromProjectHome(Activity activity,
SharedPreferences preferences) {
preferences.edit().putBoolean(PREFERENCE_EULA_ACCEPTED, true).commit();
Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://code.google.com/p/regalandroid/downloads/list"));
activity.startActivity(intent);
}

private static void refuse(Activity activity) {
activity.finish();
}

private FirstTime() {
// don't construct me
}
}

Change log

r109 by anthony.dahanne on Jan 16, 2011   Diff
last version, 1.6.3 : urging users to
switch to ReGalAndroid
Go to: 
Project members, sign in to write a code review

Older revisions

r59 by anthony.dahanne on Nov 24, 2009   Diff
quality check with findbugs, 2 bugs
fixed
r27 by anthony.dahanne on Aug 27, 2009   Diff
adding some new Progress dialogs
r11 by anthony.dahanne on Aug 16, 2009   Diff
*New feature : login into the gallery
using your username/password, solving
 issue #1 
*New screen activity added :
FirstTime, to explain the user what
...
All revisions of this file

File info

Size: 3915 bytes, 108 lines
Powered by Google Project Hosting