<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
- <classpathentry kind="lib" path="libs/android-support-v4.jar"/>
+ <classpathentry kind="lib" path="libs/android-support-v4.jar">
+ <attributes>
+ <attribute name="javadoc_location" value="file:/E:/tools/adt-bundle-windows-x86_64-20130917/sdk/extras/android/support/v4/docs/"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="lib" path="libs/org.opensrf2_serialized_reg.jar"/>
<classpathentry kind="lib" path="libs/zxing_barcode.jar"/>
<classpathentry kind="lib" path="libs/androwrapee-1.1.0.jar"/>
\r
<activity\r
android:name="org.evergreen.android.views.splashscreen.SplashActivity"\r
- android:label="@string/ou_app_label"\r
- android:theme="@android:style/Theme.Light.NoTitleBar" >\r
-\r
- <!--\r
+ android:label="@string/ou_app_label">\r
+ <!-- android:theme="@android:style/Theme.Light.NoTitleBar" -->\r
<intent-filter>\r
<action android:name="android.intent.action.MAIN" />\r
\r
<category android:name="android.intent.category.LAUNCHER" />\r
- </intent-filter>\r\r
- -->\r
- </activity>\r
+ </intent-filter>\r </activity>\r
<activity\r
android:name="org.evergreen.android.views.MainScreenDashboard"\r
android:label="@string/ou_app_label"\r
android:name="org.evergreen.android.views.StartupActivity"\r
android:label="@string/ou_app_name"\r
android:windowSoftInputMode="adjustResize|stateVisible" >\r
- <intent-filter>\r
- <action android:name="android.intent.action.MAIN" />\r
-\r
- <category android:name="android.intent.category.LAUNCHER" />\r
- </intent-filter>\r
</activity>\r
<activity\r
android:name="org.evergreen_ils.auth.AuthenticatorActivity"\r
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
+ android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context=".JunkActivity" >
<TextView
- android:id="@+id/textView1"
+ android:id="@+id/junkTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginLeft="20dp"
- android:layout_marginTop="51dp"
- android:text="Large Text"
+ android:text="token"
android:textAppearance="?android:attr/textAppearanceLarge" />
-</RelativeLayout>
\ No newline at end of file
+ <EditText
+ android:id="@+id/junkTokenText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ems="10" >
+
+ <requestFocus />
+ </EditText>
+
+ <TextView
+ android:id="@+id/junkUsernameLabel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="username"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <EditText
+ android:id="@+id/junkUsernameText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ems="10" />
+
+ <Button
+ android:id="@+id/junkButton"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="try again" />
+
+</LinearLayout>
\ No newline at end of file
>
<TextView
- android:id="@+id/textView1"
+ android:id="@+id/junkTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ou_account_sign_in_message"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:background="@drawable/background_splash"
+ android:background="#ffffff"
android:gravity="center_horizontal"
android:orientation="vertical" >
-
- <ImageView
- android:id="@+id/logo"
- android:layout_width="280dip"
- android:layout_height="wrap_content"
- android:src="@drawable/evergreen_logo"
- android:layout_centerInParent="true"
-
- />
+ <ImageView
+ android:id="@+id/logo"
+ android:layout_width="280dip"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="106dp"
+ android:src="@drawable/evergreen_logo_sm072"
+ android:contentDescription="@string/library_text_logo" />
+ <TextView
+ android:id="@+id/action_in_progress"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/logo"
+ android:gravity="center"
+ android:paddingTop="10dip" />
-
- <ProgressBar
- android:id="@+id/activity_splash_progress_bar"
- style="@android:style/Widget.ProgressBar.Horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/logo"
- android:paddingTop="40dip"
- />
+ <ProgressBar
+ android:id="@+id/activity_splash_progress_bar"
+ style="@android:style/Widget.ProgressBar.Large"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_below="@+id/logo"
+ android:paddingTop="40dip" />
- <TextView
- android:id="@+id/action_in_progress"
- android:layout_width="fill_parent"
- android:gravity="center"
- android:layout_height="wrap_content"
- android:layout_below="@id/logo"
- android:paddingTop="10dip"
- />
</RelativeLayout>
\ No newline at end of file
>
<ProgressBar
+ android:id="@+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginBottom="8dp" />
+ android:layout_marginBottom="8dp"
+ android:visibility="gone" />
<TextView
- android:id="@+id/login_status_message"
+ android:id="@+id/login_progress_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:fontFamily="sans-serif-light"
- android:text="@string/login_progress_signing_in"
+ android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/textView1"
+ android:id="@+id/junkTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
<?xml version="1.0" encoding="utf-8"?>
<!-- ou_cwmars.xml - C/W MARS organizational unit -->
<resources>
- <!-- TODO: make this HTTPS -->
+ <!-- TODO: make URLs HTTPS -->
+ <string name="ou_library_url">http://bark.cwmars.org</string>
<string name="ou_gateway_url">http://bark.cwmars.org/osrf-gateway-v1</string>
<string name="ou_app_name">C/W Mars Library</string>
<string name="ou_app_label">C/W Mars</string>
<string name="menu_barcode_scan">barcode scan</string>
<!-- Header portion -->
- <string name="library_text_logo"> Evergreen </string>
+ <string name="library_text_logo">Evergreen</string>
<string name="my_account_button_text">My Account</string>
<string name="options_button_text">Options</string>
<string name="search_details_title">Search Details</string>
import android.app.Activity;
import android.os.Bundle;
+import android.view.View.OnClickListener;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
import android.widget.TextView;
public class JunkActivity extends Activity {
+
+ private Button b;
+ //private TextView tv;
+ private EditText t,t2;
+ private String auth_token = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- TextView tv = new TextView(this);
+ setContentView(R.layout.activity_junk);
+ b = (Button) findViewById(R.id.junkButton);
+ b.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ if (auth_token == null) {
+ LoginController.getInstance(JunkActivity.this).login();
+ }
+ }
+ });
+ t = (EditText) findViewById(R.id.junkTokenText);
+ t2 = (EditText) findViewById(R.id.junkUsernameText);
String account_name = LoginController.getInstance(this).getAccountName();
- String auth_token = LoginController.getInstance(this).getAuthToken();
- tv.setText("account.name="+((account_name==null)?"null":account_name)
- + "\nauth_token="+((auth_token==null)?"null":auth_token));
- setContentView(tv);
+ auth_token = LoginController.getInstance(this).getAuthToken();
+ t.setText((auth_token==null)?"null":auth_token);
+ t2.setText((account_name==null)?"null":account_name);
+
+ if (auth_token == null) {
+ LoginController.getInstance(this).login();
+ }
}
}
public static String METHOD_CONTAINER_FULL_DELETE = "open-ils.actor.container.full_delete";
/** The book bags. */
- public ArrayList<BookBag> bookBags = null;
+ private ArrayList<BookBag> bookBags = new ArrayList<BookBag>();
/** The conn. */
public HttpConnection conn;
/**
* The auth token. Sent with every request that needs authentication
* */
- //kcxxx: refactor into Account obj
public String authToken = null;
/** The cm. */
- private ConnectivityManager cm;
+ private ConnectivityManager cm = null;
/** The auth time. */
private Integer authTime = null;
/** The user id. */
- //kcxxx: refactor into Account obj
private Integer userID = null;
- //kcxxx: refactor into Account obj
+ /** home library ID. */
private Integer homeLibraryID = null;
- /** The user name. */
- public static String userName = "daniel";
+ private boolean haveSession;
- /** The password. */
- public static String password = "demo123";
+ /** The user name. */
+ public static String userName = null;
+
+ /** Whether we have ever established a session **/
/** The account access. */
private static AccountAccess accountAccess = null;
* @param httpAddress the http address
* @param cm the cm
*/
- private AccountAccess(String httpAddress, ConnectivityManager cm) {
+ private AccountAccess(String httpAddress) {
System.out.println("AccountAccess ctor: "+httpAddress);
this.httpAddress = httpAddress;
- this.cm = cm;
try {
// configure the connection
* @param cm the cm
* @return the account access
*/
- public static AccountAccess getAccountAccess(String httpAddress,
- ConnectivityManager cm) {
+ public static AccountAccess getAccountAccess(String httpAddress) {
if (accountAccess == null) {
- accountAccess = new AccountAccess(httpAddress, cm);
+ accountAccess = new AccountAccess(httpAddress);
}
System.out.println(" Addresses " + httpAddress + " "
+ accountAccess.httpAddress);
* @return the account access
*/
public static AccountAccess getAccountAccess() {
+ return accountAccess;
+ }
- if (accountAccess != null) {
- return accountAccess;
- }
-
- return null;
+ public static void setAccountName(String username) {
+ userName = username;
}
public Integer getHomeLibraryID() {
}
/**
- * Sets the account info.
- *
- * @param username the username
- * @param password the password
- */
- public static void setAccountInfo(String username, String password) {
-
- AccountAccess.userName = username;
- AccountAccess.password = password;
-
- }
-
- /**
* Authenticate.
*
* @return true, if successful
public boolean authenticate() throws NoNetworkAccessException,
NoAccessToServer {
- String seed = authenticateInit();
-
- return authenticateComplete(seed);
+ //TODO this is a giant hack
+ return true;
}
/**
- * Gets the account summary.
- *
- * @return the account summary
+ * Retrieve session.
*/
- public OSRFObject getAccountSummary() {
+ public boolean initSession() {
+
+ if (this.haveSession)
+ return true;
Method method = new Method(METHOD_AUTH_SESSION_RETRV);
System.out.println("User Id " + userID);
- return au;
- }
- return null;
- }
-
- /**
- * Authenticate init.
- *
- * @return seed for phase 2 of login
- * @throws NoAccessToServer the no access to server
- * @throws NoNetworkAccessException the no network access exception
- */
- private String authenticateInit() throws NoAccessToServer,
- NoNetworkAccessException {
-
- String seed = null;
-
- System.out.println("AccountAccess.authenticateInit " + httpAddress);
- Object resp = (Object) Utils.doRequest(conn, SERVICE_AUTH,
- METHOD_AUTH_INIT, cm, new Object[] { userName });
- if (resp != null)
- seed = resp.toString();
-
- System.out.println("Seed " + seed);
-
- return seed;
- }
-
- /**
- * Authenticate complete. Phase 2 of login process Application sends
- * username and hash to confirm login
- *
- * @param seed the seed
- * @return true, if successful
- * @throws NoAccessToServer the no access to server
- * @throws NoNetworkAccessException the no network access exception
- * @returns bollean if auth was ok
- */
- private boolean authenticateComplete(String seed) throws NoAccessToServer,
- NoNetworkAccessException {
- System.out.println("AccountAccess.authenticateComplete seed=" + seed);
-
- // calculate hash to pass to server for authentication process phase 2
- // seed = "b18a9063e0c6f49dfe7a854cc6ab5775";
- String hash = md5(seed + md5(password));
-
- HashMap<String, String> complexParam = new HashMap<String, String>();
- // TODO parameter for user login
- complexParam.put("type", "opac");
- complexParam.put("username", userName);
- complexParam.put("password", hash);
-
- Object resp = Utils.doRequest(conn, SERVICE_AUTH, METHOD_AUTH_COMPLETE,
- cm, new Object[] { complexParam });
- if (resp == null) {
- System.out.println("Result: null");
- return false;
- }
-
- String queryResult = ((Map<String, String>) resp).get("textcode");
- System.out.println("Result: " + queryResult);
-
- if (queryResult.equals("SUCCESS")) {
- Object payload = ((Map<String, String>) resp).get("payload");
- accountAccess.authToken = ((Map<String, String>) payload)
- .get("authtoken");
- try {
- System.out.println(authToken);
- accountAccess.authTime = ((Map<String, Integer>) payload)
- .get("authtime");
-
- } catch (Exception e) {
- System.err.println("Error in parsing authtime "
- + e.getMessage());
- }
-
- // get user ID
- try {
- accountAccess.getAccountSummary();
- } catch (Exception e) {
- Log.d(TAG,
- "Error in retrieving account info, this is normal if it is before IDL load");
- System.err.println("Error in retrieving account info "+e.getMessage()+" cause: "+e.getCause());
- }
-
- return true;
+ this.haveSession = true;
}
-
- return false;
-
+ return this.haveSession;
}
// ------------------------Checked Out Items Section
// bags-----------------------------------//
/**
- * Gets the bookbags.
+ * Retrieve bookbags from the server.
*
* @return the bookbags
* @throws SessionNotFoundException the session not found exception
* @throws NoNetworkAccessException the no network access exception
* @throws NoAccessToServer the no access to server
*/
- public ArrayList<BookBag> getBookbags() throws SessionNotFoundException,
+ public boolean retrieveBookbags() throws SessionNotFoundException,
NoNetworkAccessException, NoAccessToServer {
Object response = Utils.doRequest(conn, SERVICE_ACTOR,
this.bookBags = bookBagObj;
if (bookbags == null)
- return bookBagObj;
+ return true;
for (int i = 0; i < bookbags.size(); i++) {
bookBagObj.add(bag);
}
- return bookBagObj;
+ return true;
+ }
+
+ public ArrayList<BookBag> getBookbags() {
+ return this.bookBags;
}
/**
METHOD_CONTAINER_CREATE, authToken, cm, new Object[] {
authToken, container, parameter });
}
-
}
private void getTokenForLastActiveAccount() {
final String username = mAppPrefs.getLastAccountName();
- Log.d(TAG, "getToken> username="+username);
+ Log.d(TAG, "getTokenForLastActiveAccount> username="+username);
// first try to get an auth token for the last account used
- if (!TextUtils.isEmpty(username)) {
- if (reuseExistingAccountAuthToken(username)) {
- Log.d(TAG, "getToken> reuseExisting returned true");
- }
+ if (!TextUtils.isEmpty(username) && reuseExistingAccountAuthToken(username)) {
+ Log.d(TAG, "getTokenForLastActiveAccount> reuseExisting returned true");
} else {
getTokenForAccountCreateIfNeeded();
}
mAuthToken = null;
showMessage(msg);
}
+
+ protected void onInvalidateAuthToken() {
+ mAuthToken = null;
+ }
private boolean reuseExistingAccountAuthToken(final String account_name) {
+ Log.d(TAG, "reuseExistingAccountAuthToken> looking for "+account_name);
final Account availableAccounts[] = mAccountManager.getAccountsByType(Const.ACCOUNT_TYPE);
for (int i = 0; i < availableAccounts.length; i++) {
Log.d(TAG, "reuseExistingAccountAuthToken> looking for "+account_name+", found "+availableAccounts[i].name);
}
/**
- * Invalidates the auth token for the account
- * @param account
- * @param authTokenType
+ * Invalidates the current auth token for the account
*/
- private void invalidateAuthToken(final Account account) {
- final AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(account, Const.AUTHTOKEN_TYPE, null, mActivity, null, null);
-
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- Bundle bnd = future.getResult();
-
- final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
- mAccountManager.invalidateAuthToken(account.type, authtoken);
- showMessage(account.name + " invalidated");
- mAppPrefs.putLastAccountName(null);
- } catch (Exception e) {
- mAppPrefs.putLastAccountName(null);
- e.printStackTrace();
- showMessage(e.getMessage());
- }
- }
- }).start();
+ public void invalidateAuthToken() {
+ if (mAuthToken != null) {
+ mAccountManager.invalidateAuthToken(Const.ACCOUNT_TYPE, mAuthToken);
+ onInvalidateAuthToken();
+ }
}
/**
});
try {
+ accountAccess.retrieveBookbags();
bookBags = accountAccess.getBookbags();
} catch (NoNetworkAccessException e) {
public class GlobalConfigs {
public static String IDL_FILE_FROM_ROOT = "/reports/fm_IDL.xml";
- public static String IDL_FILE_FROM_ASSETS = "fm_IDL.xml";///reports/fm_IDL.xml?class=x&class=y&...
+ public static String IDL_FILE_FROM_ASSETS = "fm_IDL.xml";
public static String httpAddress = "";
private boolean init = false;
*/
private boolean initialize(Context context) {
if (init == false) {
- // TODO do this in AsyncTask
loadIDLFile(context);
getOrganisations();
getCopyStatusesAvailable((ConnectivityManager) context
return in;
}
- /**
- * Checks to see if network access is enabled
- *
- * @throws NoNetworkAccessException
- * if neither data connection or wifi are enabled
- * NoAccessToServer if the library remote server can't be
- * reached
- *
- */
- public static boolean checkNetworkStatus(ConnectivityManager cm)
- throws NoNetworkAccessException, NoAccessToServer {
-
- boolean networkAccessEnabled = false;
- boolean httpAddressAccessReachable = false;
-
- NetworkInfo ni = cm.getActiveNetworkInfo();
- if (ni != null) {
- if (ni.getType() == ConnectivityManager.TYPE_WIFI)
- if (ni.isConnected()) {
- networkAccessEnabled = true;
- }
- if (ni.getType() == ConnectivityManager.TYPE_MOBILE)
- if (ni.isConnected()) {
- networkAccessEnabled = true;
- }
- }
-
- System.out.println("Network access " + networkAccessEnabled);
-
- if (!networkAccessEnabled)
- throw new NoNetworkAccessException();
-
- if (networkAccessEnabled) {
- httpAddressAccessReachable = checkIfNetAddressIsReachable(GlobalConfigs.httpAddress);
- if (httpAddressAccessReachable == false)
- throw new NoAccessToServer();
- }
- return networkAccessEnabled;
-
- }
-
public static boolean checkIfNetAddressIsReachable(String url)
throws NoAccessToServer {
Object[] params) throws SessionNotFoundException,
NoNetworkAccessException, NoAccessToServer {
- // check for network connectivity
- checkNetworkStatus(cm);
-
// check to see if EG http server is reachable
checkIfNetAddressIsReachable(GlobalConfigs.httpAddress);
String methodName, ConnectivityManager cm, Object[] params)
throws NoNetworkAccessException, NoAccessToServer {
- // check for network connectivity
- checkNetworkStatus(cm);
-
// check to see if EG http server is reachable
checkIfNetAddressIsReachable(GlobalConfigs.httpAddress);
}
});
// get bookbags
- AccountAccess ac = AccountAccess.getAccountAccess();
- bookBags = ac.bookBags;
+ bookBags = AccountAccess.getAccountAccess().getBookbags();
libraryHoursButton = (Button) findViewById(R.id.library_hours_button);
libraryHoursButton.setOnClickListener(new OnClickListener() {
;
// login with the user credentials
- AccountAccess accountAccess = AccountAccess.getAccountAccess(
- GlobalConfigs.httpAddress,
- (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE));
+ AccountAccess accountAccess = AccountAccess.getAccountAccess(GlobalConfigs.httpAddress);
boolean auth = true;
try {
accountAccess.authenticate();
public static BasicDetailsFragment newInstance(RecordInfo record,
Integer position, Integer total) {
- BasicDetailsFragment fragment = new BasicDetailsFragment(record,
- position, total);
+ BasicDetailsFragment fragment = new BasicDetailsFragment();
+ fragment.setDetails(record, position, total);
return fragment;
}
- public BasicDetailsFragment(RecordInfo record, Integer position,
+ private void setDetails(RecordInfo record, Integer position,
Integer total) {
this.record = record;
this.position = position;
this.total = total;
-
- search = SearchCatalog.getInstance();
}
public BasicDetailsFragment() {
AccountAccess ac = AccountAccess.getAccountAccess();
- bookBags = ac.bookBags;
+ bookBags = ac.getBookbags();
String array_spinner[] = new String[bookBags.size()];
for (int i = 0; i < array_spinner.length; i++)
AccountAccess ac = AccountAccess.getAccountAccess();
try {
ac.addRecordToBookBag(record.doc_id,
- ac.bookBags.get(bookbag_selected).id);
+ ac.getBookbags().get(bookbag_selected).id);
} catch (SessionNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public void run() {
boolean routeToAddress = true;
- AccountAccess account = AccountAccess
- .getAccountAccess(
- GlobalConfigs.httpAddress,
- (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE));
- try {
- Utils.checkNetworkStatus((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE));
- } catch (NoNetworkAccessException e) {
- routeToAddress = false;
-
- Log.d(TAG, " No network access");
-
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- if (reference != null) {
- progressDialog.dismiss();
- AlertDialog.Builder builder = new AlertDialog.Builder(
- context);
- builder.setMessage(
- "There seams to be no network connectivity! Do you want to start network settings?")
- .setPositiveButton("Yes",
- dialogClickListener)
- .setNegativeButton("No",
- dialogClickListener).show();
- }
- }
- });
-
- } catch (NoAccessToServer e) {
-
- Log.d(TAG, " no route to hoast");
- routeToAddress = false;
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- if (reference != null)
- Toast.makeText(
- getApplicationContext(),
- "There is no route to host :"
- + GlobalConfigs.httpAddress,
- Toast.LENGTH_LONG).show();
- }
-
- });
- }
+ AccountAccess account = AccountAccess.getAccountAccess(GlobalConfigs.httpAddress);
if (routeToAddress) {
AccountAccess.userName = sharedPreferences
.getString("username", "");
checkConnection = true;
- } else if (key.equals("password")) {
- AccountAccess.password = sharedPreferences
- .getString("password", "");
- checkConnection = true;
} else if (key.equals("library_url")) {
checkConnection = true;
GlobalConfigs.httpAddress = sharedPreferences.getString(
editor.commit();
GlobalConfigs.httpAddress = server_http.getText()
.toString();
- AccountAccess accountAccess = AccountAccess
- .getAccountAccess(
- GlobalConfigs.httpAddress,
- (ConnectivityManager) getSystemService(Service.CONNECTIVITY_SERVICE));
-
- AccountAccess.setAccountInfo(username.getText()
- .toString(), password.getText().toString());
-
+ AccountAccess accountAccess = AccountAccess.getAccountAccess(GlobalConfigs.httpAddress);
try {
auth = accountAccess.authenticate();
Log.d(TAG, "Auth " + auth);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_startup);
- mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message);
+ mLoginStatusMessageView = (TextView) findViewById(R.id.login_progress_message);
LoginController.getInstance(this).loginForActivity(JunkActivity.class);
}
import org.evergreen.android.globals.GlobalConfigs;
import org.evergreen.android.globals.NoAccessToServer;
import org.evergreen.android.globals.NoNetworkAccessException;
+import org.evergreen_ils.auth.Const;
+import android.accounts.AccountManager;
+import android.accounts.AccountManagerCallback;
+import android.accounts.AccountManagerFuture;
import android.app.Activity;
-import android.content.Context;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
+import android.os.Bundle;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;
-public class LoadingTask extends AsyncTask<String, Integer, Integer> {
+public class LoadingTask extends AsyncTask<String, String, String> {
+ private String TAG = "LoadingTask";
+
+ public static final String TASK_OK = "OK";
- public interface LoadingTaskFinishedListener {
- void onTaskFinished(); // If you want to pass something back to the
- // listener add a param to this method
+ public interface LoadingTaskListener {
+ void onPreExecute();
+ void onProgressUpdate(String value);
+ void onPostExecute(String result);
}
- // This is the progress bar you want to update while the task is in progress
- private final ProgressBar progressBar;
// This is the listener that will be told when this task is finished
- private final LoadingTaskFinishedListener finishedListener;
-
- private Context context;
-
- 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, Activity callingActivity) {
- this.progressBar = progressBar;
- this.finishedListener = finishedListener;
- this.context = context;
- this.progressText = progressText;
- this.callingActivity = callingActivity;
+ private final LoadingTaskListener mListener;
+ private Activity mCallingActivity;
+ private AccountManager mAccountManager;
+
+ public LoadingTask(LoadingTaskListener listener, Activity callingActivity) {
+ this.mListener = listener;
+ this.mCallingActivity = callingActivity;
+ mAccountManager = AccountManager.get(callingActivity);
}
-
+
@Override
- protected Integer doInBackground(String... params) {
- Log.i("Start download", "Starting task with url: " + params[0]);
- if (resourcesDontAlreadyExist()) {
- downloadResources();
- }
- // Perhaps you want to return something to your post execute
- return 1234;
- }
-
- private boolean resourcesDontAlreadyExist() {
- // Here you would query your app's internal state to see if this
- // download had been performed before
- // Perhaps once checked save this in a shared preference for speed of
- // access next time
- return true; // returning true so we show the splash every time
+ protected void onPreExecute() {
+ super.onPreExecute();
+ mListener.onPreExecute();
}
- private void downloadResources() {
- // We are just imitating some process thats takes a bit of time (loading
- // of resources / downloading)
- int count = 10;
- text = "download files";
- publishProgress(50);
-
- GlobalConfigs gl = GlobalConfigs.getGlobalConfigs(context);
- text = "authenticate user";
- publishProgress(70);
-
- AccountAccess ac = AccountAccess.getAccountAccess(
- GlobalConfigs.httpAddress, (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE));
+ @Override
+ protected String doInBackground(String... params) {
try {
- ac.authenticate();
+ Log.d(TAG, "Loading resources");
+ publishProgress("Loading resources");
+ GlobalConfigs gl = GlobalConfigs.getGlobalConfigs(mCallingActivity);
+
+ Log.d(TAG, "Signing in");
+ publishProgress("Signing in");
+ final AccountManagerFuture<Bundle> future = mAccountManager.getAuthTokenByFeatures(Const.ACCOUNT_TYPE, Const.AUTHTOKEN_TYPE, null, mCallingActivity, null, null, null, null);
+ Bundle bnd = future.getResult();
+ Log.d(TAG, "bnd="+bnd);
+ final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
+ final String account_name = bnd.getString(AccountManager.KEY_ACCOUNT_NAME);
+ Log.d(TAG, "account_name="+account_name+" token="+authtoken);
+ //onSuccessfulLogin(account_name, authtoken);
+ if (account_name == null)
+ return "no account";
+
+ Log.d(TAG, "Starting session");
+ publishProgress("Starting session");
+ AccountAccess ac = AccountAccess.getAccountAccess(GlobalConfigs.httpAddress);
+ if (!ac.initSession())
+ return "no session";
+
+ Log.d(TAG, "Retrieving bookbags");
+ publishProgress("Retrieving bookbags");
+ ac.retrieveBookbags();
+
+ return TASK_OK;
} catch (Exception e) {
+ Log.d(TAG, "Caught exception", e);
+ return e.getMessage();
}
- 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);
-
}
@Override
- protected void onProgressUpdate(Integer... values) {
+ protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
- progressBar.setProgress(values[0]); // This is ran on the UI thread so
- // it is ok to update our progress
- // bar ( a UI view ) here
- progressText.setText(text);
+ mListener.onProgressUpdate(values[0]);
}
@Override
- protected void onPostExecute(Integer result) {
+ protected void onPostExecute(String result) {
super.onPostExecute(result);
- finishedListener.onTaskFinished(); // Tell whoever was listening we have
- // finished
+ mListener.onPostExecute(result);
}
}
\ No newline at end of file
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.searchCatalog.SearchCatalogListView;
-import org.evergreen.android.views.ConfigureApplicationActivity;
-import org.evergreen.android.views.splashscreen.LoadingTask.LoadingTaskFinishedListener;
+import org.evergreen.android.views.splashscreen.LoadingTask.LoadingTaskListener;
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.Service;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.net.ConnectivityManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
-public class SplashActivity extends Activity implements
- LoadingTaskFinishedListener {
+public class SplashActivity extends Activity implements LoadingTaskListener {
private TextView progressText;
-
private Context context;
-
private ProgressBar progressBar;
-
private String TAG = "SplashActivity";
-
private AlertDialog alertDialog;
-
-
- private static final int ABORT = 1;
- private static final int ABORT_SERVER_PROBLEM = 2;
- private static final int ABORT_NETWORK_CONN_PROLEM = 3;
- private static final int OK = 0;
- private int abort;
private SharedPreferences prefs;
- private SplashActivity activity;
+ private LoadingTask task;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- this.context = this;
- activity = this;
- // Show the splash screen
setContentView(R.layout.activity_splash);
- progressText = (TextView) findViewById(R.id.action_in_progress);
+ this.context = this;
- // Find the progress bar
+ progressText = (TextView) findViewById(R.id.action_in_progress);
progressBar = (ProgressBar) findViewById(R.id.activity_splash_progress_bar);
- abort = OK;
- 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);
-
-
-
- Thread checkConnThread = new Thread(new Runnable() {
-
- @Override
- public void run() {
- // TODO Auto-generated method stub
- try {
- Utils.checkNetworkStatus((ConnectivityManager) getSystemService(Service.CONNECTIVITY_SERVICE));
- } catch (NoNetworkAccessException e) {
- abort = ABORT_NETWORK_CONN_PROLEM;
- e.printStackTrace();
- } catch (NoAccessToServer e) {
- // you have no access to server or server down
- abort = ABORT_SERVER_PROBLEM;
- e.printStackTrace();
- }
-
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- if(!prefs.contains("library_url")) {
- Intent configureIntent = new Intent(context,
- ConfigureApplicationActivity.class);
- startActivityForResult(configureIntent, 0);
- }
-
- if (abort == OK) {
- // Start your loading
- new LoadingTask(progressBar, activity, activity, progressText, activity)
- .execute("download"); // Pass in whatever you need a url is
- // just an example we don't use it
- // in this tutorial
- }
- else
- {
-
- switch(abort) {
-
- case ABORT_NETWORK_CONN_PROLEM : {
- AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
- context);
-
- // set title
- alertDialogBuilder.setTitle("Network problem");
-
- // set dialog message
- alertDialogBuilder
- .setMessage("You do not have your network activated. Please activate it!")
- .setCancelable(false)
- .setNegativeButton("exit",new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,int id) {
- // if this button is clicked, just close
- // the dialog box and do nothing
- dialog.cancel();
- finish();
- }
- });
-
- // create alert dialog
- alertDialog = alertDialogBuilder.create();
-
- // show it
- alertDialog.show();
-
- } break;
-
- case ABORT_SERVER_PROBLEM : {
- AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
- context);
-
- // set title
- alertDialogBuilder.setTitle("Evergreen server problem");
-
- // set dialog message
- alertDialogBuilder
- .setMessage("Seams the server can't be found. Please configure the server address")
- .setCancelable(false)
- .setPositiveButton("Configure",new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,int id) {
- // if this button is clicked, close
- // current activity
-
- Intent configureIntent = new Intent(context,
- ConfigureApplicationActivity.class);
- startActivityForResult(configureIntent, 0);
-
- }
- })
- .setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog,int id) {
- // if this button is clicked, just close
- // the dialog box and do nothing
- dialog.cancel();
- finish();
- }
- });
-
- // create alert dialog
- alertDialog = alertDialogBuilder.create();
-
- // show it
- alertDialog.show();
- } break;
-
- }
-
- }
- }
- });
- }
- });
-
- checkConnThread.start();
-
-
+ prefs= PreferenceManager.getDefaultSharedPreferences(context);
+ GlobalConfigs.httpAddress = context.getString(R.string.ou_library_url);
+ String username = prefs.getString("username", "");
+ AccountAccess.setAccountName(username);
+ task = new LoadingTask(this, this);
+ task.execute(new String());
}
-
@Override
protected void onStop() {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- switch (resultCode) {
- case ConfigureApplicationActivity.RESULT_CONFIGURE_SUCCESS: {
- new LoadingTask(progressBar, this, this, progressText, this)
- .execute("download");
-
- }
- break;
+ Log.d(TAG, "onActivityResult> "+requestCode+" "+resultCode);
+ }
- }
+ private void startApp() {
+ Intent intent = new Intent(SplashActivity.this, SearchCatalogListView.class);
+ startActivity(intent);
+ finish();
}
- // This is the callback for when your async task has finished
@Override
- public void onTaskFinished() {
- completeSplash();
+ public void onPreExecute() {
+ progressBar.setVisibility(View.VISIBLE);
}
- private void completeSplash() {
- startApp();
- finish(); // Don't forget to finish this Splash Activity so the user
- // can't return to it!
+ @Override
+ public void onProgressUpdate(String value) {
+ progressText.setText(value);
}
- private void startApp() {
- Intent intent = new Intent(SplashActivity.this,
- SearchCatalogListView.class);
- startActivity(intent);
+ @Override
+ public void onPostExecute(String result) {
+ Log.d(TAG, "onPostExecute> "+result);
+ progressBar.setVisibility(View.GONE);
+ if (result.equals(LoadingTask.TASK_OK)) {
+ startApp();
+ } else {
+ String extra_text = "...Failed";
+ if (!TextUtils.isEmpty(result)) extra_text = extra_text + ": " + result;
+ progressText.setText(progressText.getText() + extra_text);
+ //retryButton.setVisibility(View.VISIBLE);
+ }
}
}
\ No newline at end of file