Android Open Source - APO-Theta-Upsilon-App Phone Open Helper






From Project

Back to project page APO-Theta-Upsilon-App.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project APO-Theta-Upsilon-App listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.cwru.apo;
/*from w  ww  .  j a v a  2s .c o m*/
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import edu.cwru.apo.API.Methods;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

public class PhoneOpenHelper extends SQLiteOpenHelper implements AsyncRestRequestListener<Methods, JSONObject>{

    private static final int DATABASE_VERSION = 1;
    private static final String PHONE_TABLE_NAME = "phoneDB";
    private static final String PHONE_TABLE_CREATE =
                "CREATE TABLE " + PHONE_TABLE_NAME + " (_id TEXT PRIMARY KEY, first TEXT, last TEXT, phone TEXT, family TEXT);";
    private static SQLiteDatabase database = null;
    private static Context context;
    
    PhoneOpenHelper(Context context) {
        super(context, PHONE_TABLE_NAME, null, DATABASE_VERSION);
        PhoneOpenHelper.context = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
      database = db;
      database.execSQL(PHONE_TABLE_CREATE);
    }

  @Override
  public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub
    
  }
  
  public void loadData() 
  {
    if (database == null)
      database = this.getWritableDatabase();
    API api = new API(context);
    if(!api.callMethod(Methods.phone, this, (String[])null))
    {
      Toast msg = Toast.makeText(context, "Error: Calling phone", Toast.LENGTH_LONG);
      msg.show();
    }

  }
  
  public void onRestRequestComplete(Methods method, JSONObject result) {
    if(method == Methods.phone)
    {
      if(result != null)
      {
        try {
          String requestStatus = result.getString("requestStatus");
          if(requestStatus.compareTo("success") == 0)
          {
            SharedPreferences.Editor editor = context.getSharedPreferences(APO.PREF_FILE_NAME, 0).edit();
            editor.putLong("updateTime", result.getLong("updateTime"));
            editor.commit();
            int numbros = result.getInt("numBros");
            JSONArray caseID = result.getJSONArray("caseID");
            JSONArray first = result.getJSONArray("first");
            JSONArray last = result.getJSONArray("last");
            JSONArray phone = result.getJSONArray("phone");
            JSONArray family = result.getJSONArray("family");
            ContentValues values; 
            for(int i = 0; i < numbros; i++)
            {
              values = new ContentValues();
              values.put("_id", caseID.getString(i));
              values.put("first", first.getString(i));
              values.put("last", last.getString(i));
              values.put("phone", phone.getString(i));
              values.put("family", family.getString(i));
              database.replace("phoneDB", null, values);
            }
          }
          else if(requestStatus.compareTo("timestamp invalid") == 0)
          {
            Toast msg = Toast.makeText(context, "Invalid timestamp.  Please try again.", Toast.LENGTH_LONG);
            msg.show();
          }
          else if(requestStatus.compareTo("HMAC invalid") == 0)
          {
            Auth.loggedIn = false;
            Toast msg = Toast.makeText(context, "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
            msg.show();
          }
          else
          {
            Toast msg = Toast.makeText(context, "Invalid requestStatus", Toast.LENGTH_LONG);
            msg.show();
          }
        } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      
    }
  }
}




Java Source Code List

edu.cwru.apo.API.java
edu.cwru.apo.APO.java
edu.cwru.apo.AsyncRestRequestListener.java
edu.cwru.apo.Auth.java
edu.cwru.apo.Contract.java
edu.cwru.apo.Directory.java
edu.cwru.apo.DynamicHmac.java
edu.cwru.apo.ForgotPassword.java
edu.cwru.apo.Hex.java
edu.cwru.apo.Hmac.java
edu.cwru.apo.Home.java
edu.cwru.apo.ImageAdapter.java
edu.cwru.apo.Installation.java
edu.cwru.apo.Login.java
edu.cwru.apo.News.java
edu.cwru.apo.PhoneOpenHelper.java
edu.cwru.apo.Profile.java
edu.cwru.apo.Report.java
edu.cwru.apo.RestClient.java
edu.cwru.apo.TrustAPOHttpClient.java