Added initial dialog on first run

git-svn-id: https://forja.rediris.es/svn/cusl6-swadroid/trunk@118 5bc14d19-1e4b-4ba2-aa50-860af135f48c
This commit is contained in:
Juan Miguel Boyero Corral 2011-11-22 22:10:07 +00:00
parent 0f103c6f4b
commit 967a6a3e11
6 changed files with 74 additions and 22 deletions

View File

@ -47,7 +47,9 @@ public final class R {
public static final int errorMsgNoConnection=0x7f06001c;
public static final int errorMsgWorkaroundEmulator=0x7f06001a;
public static final int examAnnouncement=0x7f060021;
public static final int firstRunMsg=0x7f06002a;
public static final int forumReply=0x7f060025;
public static final int initialDialogTitle=0x7f06002b;
public static final int loginModuleLabel=0x7f060001;
public static final int loginProgressDescription=0x7f060014;
public static final int loginProgressTitle=0x7f060013;
@ -55,6 +57,7 @@ public final class R {
public static final int loginTitle_menu=0x7f060012;
public static final int marksFile=0x7f060022;
public static final int message=0x7f060024;
public static final int noMsg=0x7f060029;
public static final int notice=0x7f060023;
public static final int notificationsFromMsg=0x7f060026;
public static final int notificationsModuleLabel=0x7f060002;
@ -76,6 +79,7 @@ public final class R {
public static final int userPasswordSummary_preferences=0x7f06000c;
public static final int userPasswordTitle_preferences=0x7f06000d;
public static final int user_preferences=0x7f060007;
public static final int yesMsg=0x7f060028;
}
public static final class xml {
public static final int preferences=0x7f040000;

View File

@ -29,4 +29,8 @@
<string name="notice">Aviso</string>
<string name="message">Mensaje</string>
<string name="forumReply">Respuesta en foro</string><string name="notificationsFromMsg">De</string><string name=" notificationsDateMsg">Fecha</string>
<string name="yesMsg"></string>
<string name="noMsg">No</string>
<string name="firstRunMsg">Antes de usar la aplicación por primera vez debe introducir el nombre de usuario y la contraseña de acceso a SWAD en la pantalla de configuración.\n\nPuede acceder a la pantalla de configuración desde el menú de la aplicación en cualquier momento.\n\n¿Desea abrir ahora la pantalla de configuración?</string>
<string name="initialDialogTitle">IMPORTANTE</string>
</resources>

View File

@ -33,6 +33,9 @@
<string name="forumReply">Forum reply</string>
<string name="notificationsFromMsg">From</string>
<string name=" notificationsDateMsg">Date</string>
<string name="yesMsg">Yes</string>
<string name="noMsg">No</string><string name="firstRunMsg">Before using the application for the first time you must enter the user name and password for SWAD at the setup screen.\n\nYou can access to the setup screen from the application menu anytime.\n\nDo you want to open the configuration screen now?</string>
<string name="initialDialogTitle">IMPORTANT</string>

View File

@ -48,14 +48,6 @@ public class Global {
* Request code for Notifications module.
*/
public static final int NOTIFICATIONS_REQUEST_CODE = 3;
/**
* Student type constant
*/
public static String STUDENT_TYPE = "student";
/**
* Teacher type constant
*/
public static String TEACHER_TYPE = "teacher";
/**
* Class Module's tag name for Logcat
*/

View File

@ -55,6 +55,14 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
* User password preference name.
*/
private static final String USERPASSWORDPREF = "userPasswordPref";
/**
* Last application version
*/
private int lastVersion;
/**
* Last application version preference name.
*/
private static final String LASTVERSIONPREF = "lastVersionPref";
/**
* User ID preference
*/
@ -85,20 +93,22 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
}
/**
* Get if this is the first run
* Gets last application version
*
* @return returns true, if this is the first run
*/
public boolean getFirstRun() {
return prefs.getBoolean("firstRun", true);
public int getLastVersion() {
return lastVersion;
}
/**
* Store the first run
* Sets last application version
*/
public void setRunned() {
editor.putBoolean("firstRun", false);
editor.commit();
public void setLastVersion(int lv) {
lastVersion = lv;
editor = prefs.edit();
editor.putInt(LASTVERSIONPREF, lv);
editor.commit();
}
private String getStarsSequence(int size)
@ -118,10 +128,11 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
* @param ctx Context of activity.
*/
public void getPreferences(Context ctx) {
// Get the xml/preferences.xml preferences
// Get the preferences
prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
userID = prefs.getString(USERIDPREF, "");
userPassword = prefs.getString(USERPASSWORDPREF, "");
lastVersion = prefs.getInt(LASTVERSIONPREF, 0);
}
/* (non-Javadoc)
@ -134,6 +145,10 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
//Restore preferences
addPreferencesFromResource(R.xml.preferences);
prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
userID = prefs.getString(USERIDPREF, "");
userPassword = prefs.getString(USERPASSWORDPREF, "");
lastVersion = prefs.getInt(LASTVERSIONPREF, 0);
editor = prefs.edit();
userIDPref = findPreference(USERIDPREF);
@ -204,5 +219,7 @@ public class Preferences extends PreferenceActivity implements OnPreferenceChang
@Override
protected void onPause() {
super.onPause();
editor.putInt(LASTVERSIONPREF, lastVersion);
editor.commit();
}
}

View File

@ -23,6 +23,7 @@ import com.android.dataframework.DataFramework;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@ -86,6 +87,26 @@ public class SWADMain extends ListActivity {
})*/
}
/**
* Shows initial dialog on first run.
*/
public void showInitialDialog() {
new AlertDialog.Builder(this)
.setTitle(R.string.initialDialogTitle)
.setMessage(R.string.firstRunMsg)
.setCancelable(false)
.setPositiveButton(R.string.yesMsg, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
viewPreferences();
}
})
.setNegativeButton(R.string.noMsg, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
}
/* (non-Javadoc)
* @see android.app.Activity#onCreateOptionsMenu()
*/
@ -168,7 +189,10 @@ public class SWADMain extends ListActivity {
*/
@Override
public void onCreate(Bundle icicle) {
int lastVersion, currentVersion;
try {
//Initialize screen
super.onCreate(icicle);
Window w = getWindow();
w.requestFeature(Window.FEATURE_LEFT_ICON);
@ -178,20 +202,28 @@ public class SWADMain extends ListActivity {
functions = getResources().getStringArray(R.array.functions);
setListAdapter(new ArrayAdapter<String>(this, R.layout.functions_list_item, functions));
//Initialize database
db = DataFramework.getInstance();
db.open(this, this.getPackageName());
dbHelper = new DataBaseHelper(db);
prefs.getPreferences(getBaseContext());
//Initialize preferences
prefs.getPreferences(getBaseContext());
//Initialize HTTPS connections
SecureConnection.initSecureConnection();
if(prefs.getFirstRun()) {
viewPreferences();
prefs.setRunned();
//Check if this is the first run after an install or upgrade
//If this is the first run, show initial dialog
lastVersion = prefs.getLastVersion();
currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
if(lastVersion == 0) {
showInitialDialog();
prefs.setLastVersion(currentVersion);
}
} catch (Exception ex) {
Log.e(ex.getClass().getSimpleName(), ex.toString());
error(ex.toString());
Log.e(ex.getClass().getSimpleName(), ex.getMessage());
error(ex.getMessage());
ex.printStackTrace();
}
}