--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <TableLayout
+ android:id="@+id/credentials"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+
+ >
+
+ <TableRow
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <TextView
+ android:layout_width = "wrap_content"
+ android:layout_height = "wrap_content"
+ android:text = "@string/server_name_dialog"
+ />
+
+ <EditText
+ android:id="@+id/server_http_adress"
+ android:layout_width="200dip"
+ android:layout_height="wrap_content"
+ android:hint="@string/server_name_dialog"
+ />
+
+ </TableRow>
+ <TableRow
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <TextView
+ android:layout_width = "wrap_content"
+ android:layout_height = "wrap_content"
+ android:text = "@string/username"
+ />
+
+ <EditText
+ android:id="@+id/username"
+ android:layout_width="200dip"
+ android:layout_height="wrap_content"
+ android:hint="@string/username"
+ />
+
+ </TableRow>
+ <TableRow
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <TextView
+ android:layout_width = "wrap_content"
+ android:layout_height = "wrap_content"
+ android:text = "@string/password"
+ />
+
+ <EditText
+ android:id="@+id/password"
+ android:layout_width="200dip"
+ android:layout_height="wrap_content"
+ android:password="true"
+ />
+
+ </TableRow>
+ </TableLayout>
+
+ <Button
+ android:id="@+id/cancel_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/cancel"
+ android:layout_below="@id/credentials"
+ />
+ <Button
+ android:id="@+id/connect_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/connect_button"
+ android:layout_below="@id/credentials"
+ android:layout_toRightOf="@id/cancel_button"
+ />
+
+</RelativeLayout>
\ No newline at end of file
package org.evergreen.android.views.splashscreen;
import org.evergreen.android.accountAccess.AccountAccess;
+import org.evergreen.android.accountAccess.SessionNotFoundException;
import org.evergreen.android.globals.GlobalConfigs;
+import org.evergreen.android.globals.NoAccessToServer;
+import org.evergreen.android.globals.NoNetworkAccessException;
+import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
private TextView progressText;
+ private Activity callingActivity;
+
private String text;
/**
* A Loading task that will load some resources that are necessary for the app to start
* @param progressBar - the progress bar you want to update while the task is in progress
* @param finishedListener - the listener that will be told when this task is finished
*/
- public LoadingTask(ProgressBar progressBar, LoadingTaskFinishedListener finishedListener, Context context, TextView progressText) {
+ public LoadingTask(ProgressBar progressBar, LoadingTaskFinishedListener finishedListener, Context context, TextView progressText, Activity callingActivity) {
this.progressBar = progressBar;
this.finishedListener = finishedListener;
this.context = context;
this.progressText = progressText;
+ this.callingActivity = callingActivity;
}
@Override
protected Integer doInBackground(String... params) {
- Log.i("Tutorial", "Starting task with url: "+params[0]);
+ Log.i("Start download", "Starting task with url: "+params[0]);
if(resourcesDontAlreadyExist()){
downloadResources();
}
try{
ac.authenticate();
}catch(Exception e){}
+ text = "get user bookbags";
+ publishProgress(90);
+
+ try {
+ ac.bookBags = ac.getBookbags();
+ } catch (SessionNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NoNetworkAccessException e) {
+ e.printStackTrace();
+ } catch (NoAccessToServer e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
text = "loading application";
publishProgress(100);
package org.evergreen.android.views.splashscreen;
-
-
import org.evergreen.android.R;
+import org.evergreen.android.accountAccess.AccountAccess;
+import org.evergreen.android.globals.GlobalConfigs;
+import org.evergreen.android.globals.NoAccessToServer;
+import org.evergreen.android.globals.NoNetworkAccessException;
+import org.evergreen.android.globals.Utils;
import org.evergreen.android.views.MainScreenDashboard;
import org.evergreen.android.views.splashscreen.LoadingTask.LoadingTaskFinishedListener;
import android.app.Activity;
+import android.app.Dialog;
+import android.app.ProgressDialog;
+import android.app.Service;
+import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
+import android.widget.Toast;
-public class SplashActivity extends Activity implements LoadingTaskFinishedListener {
+public class SplashActivity extends Activity implements
+ LoadingTaskFinishedListener {
-
private TextView progressText;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Show the splash screen
- setContentView(R.layout.activity_splash);
-
- progressText = (TextView) findViewById(R.id.action_in_progress);
-
- // Find the progress bar
- ProgressBar progressBar = (ProgressBar) findViewById(R.id.activity_splash_progress_bar);
- // Start your loading
- new LoadingTask(progressBar, this, this, progressText).execute("download"); // Pass in whatever you need a url is just an example we don't use it in this tutorial
- }
-
- // This is the callback for when your async task has finished
- @Override
+
+ private Context context;
+
+ private Dialog dialog = null;
+
+ private ProgressDialog progressDialog = null;
+
+ private EditText server_http;
+
+ private EditText username;
+
+ private EditText password;
+
+ private ProgressBar progressBar;
+
+ private SplashActivity activity;
+
+ private String TAG = "SplashActivity";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ this.context = this;
+ // Show the splash screen
+ setContentView(R.layout.activity_splash);
+
+ activity = this;
+ dialog = new Dialog(context);
+ dialog.setContentView(R.layout.dialog_configure_application);
+ dialog.setTitle("Configure application");
+
+ server_http = (EditText) dialog.findViewById(R.id.server_http_adress);
+ username = (EditText) dialog.findViewById(R.id.username);
+ password = (EditText) dialog.findViewById(R.id.password);
+ Button cancel = (Button) dialog.findViewById(R.id.cancel_button);
+ Button connect = (Button) dialog.findViewById(R.id.connect_button);
+
+ cancel.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(context, "Exit application", Toast.LENGTH_SHORT)
+ .show();
+ finish();
+ }
+ });
+
+ connect.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+
+ Thread checkConn = new Thread(new Runnable() {
+ @Override
+ public void run() {
+
+ boolean server_address = false;
+ boolean auth = false;
+
+ try {
+ server_address = Utils
+ .checkIfNetAddressIsReachable(server_http
+ .getText().toString());
+ } catch (NoAccessToServer e) {
+ server_address = false;
+ }
+
+ if (server_address == true) {
+
+ SharedPreferences preferences = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = preferences
+ .edit();
+ //store into preference
+ editor.putString("library_url", server_http
+ .getText().toString());
+
+
+ editor.putString("username", username.getText().toString());
+ editor.putString("password", password.getText().toString());
+
+ editor.commit();
+ GlobalConfigs.httpAddress = server_http.getText().toString();
+ AccountAccess accountAccess = AccountAccess
+ .getAccountAccess(GlobalConfigs.httpAddress,(ConnectivityManager) activity.getSystemService(Service.CONNECTIVITY_SERVICE));
+
+ AccountAccess.setAccountInfo(username.getText().toString(),password.getText().toString());
+
+ try {
+ auth = accountAccess.authenticate();
+ Log.d(TAG, "Auth " + auth);
+ } catch (Exception e) {
+ System.out.println("Exception " + e.getMessage());
+ }
+
+ if (auth == true) {
+
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ progressDialog.dismiss();
+ dialog.dismiss();
+ // Start your loading
+ new LoadingTask(progressBar, activity,
+ activity, progressText, activity)
+ .execute("download");
+ }
+ });
+
+ } else {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ progressDialog.dismiss();
+ Toast.makeText(context,
+ "Bad user login information",
+ Toast.LENGTH_LONG).show();
+ }
+ });
+ }
+
+ } else {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ progressDialog.dismiss();
+ Toast.makeText(context,
+ "Bad library server url",
+ Toast.LENGTH_LONG).show();
+ }
+ });
+
+ }
+
+ }
+ });
+
+ progressDialog = ProgressDialog.show(context, "Please wait",
+ "Checking server and credentials");
+ checkConn.start();
+ }
+ });
+
+ dialog.setCancelable(true);
+
+ progressText = (TextView) findViewById(R.id.action_in_progress);
+
+ // Find the progress bar
+ progressBar = (ProgressBar) findViewById(R.id.activity_splash_progress_bar);
+
+ boolean abort = false;
+
+
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ GlobalConfigs.httpAddress = prefs.getString("library_url", "");
+ String username = prefs.getString("username", "username");
+ String password = prefs.getString("password", "pas");
+ AccountAccess.setAccountInfo(username, password);
+ try {
+
+ Utils.checkNetworkStatus((ConnectivityManager) getSystemService(Service.CONNECTIVITY_SERVICE));
+ } catch (NoNetworkAccessException e) {
+ abort = true;
+ e.printStackTrace();
+ } catch (NoAccessToServer e) {
+ abort = true;
+
+ dialog.show();
+
+ }
+
+ if (abort != true) {
+ // Start your loading
+ new LoadingTask(progressBar, this, this, progressText, this)
+ .execute("download"); // Pass in whatever you need a url is
+ // just an example we don't use it
+ // in this tutorial
+ }
+ }
+
+ // This is the callback for when your async task has finished
+ @Override
public void onTaskFinished() {
completeSplash();
}
- private void completeSplash(){
+ private void completeSplash() {
startApp();
- finish(); // Don't forget to finish this Splash Activity so the user can't return to it!
- }
+ finish(); // Don't forget to finish this Splash Activity so the user
+ // can't return to it!
+ }
- private void startApp() {
- Intent intent = new Intent(SplashActivity.this, MainScreenDashboard.class);
+ private void startApp() {
+ Intent intent = new Intent(SplashActivity.this,
+ MainScreenDashboard.class);
startActivity(intent);
}
}
\ No newline at end of file