示例#1
0
  @Override
  public void RemoveStoredKeyValuePairs(String[] keynames) {
    List<String> successfullKeyPairs = new ArrayList<String>();
    List<String> failedKeyPairs = new ArrayList<String>();
    SharedPreferences settings = GetOtherAppSharedPreferences();
    if (settings != null) {
      for (String keyname : keynames) {
        if (settings.contains(keyname)) {
          Editor ed = settings.edit();
          ed.remove(keyname);
          ed.commit();
          successfullKeyPairs.add(keyname);
        } else failedKeyPairs.add(keyname);
      }
    } else {
      LOGGER.logError("RemoveStoredKeyValuePairs", "Storage Unit is null.");
    }

    LOGGER.logInfo(
        "RemoveStoredKeyValuePairs",
        "Keys removed from storage unit: "
            + successfullKeyPairs.size()
            + "; Keys Not removed from storage unit: "
            + failedKeyPairs.size());
    IActivityManager am =
        (IActivityManager)
            AndroidServiceLocator.GetInstance()
                .GetService(AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    am.executeJS(
        "Unity.OnKeyValuePairsRemoveCompleted",
        new Object[] {successfullKeyPairs.toArray(), failedKeyPairs.toArray()});
  }
示例#2
0
 @Override
 public void StoreKeyValuePairs(KeyPair[] keypairs) {
   List<String> successfullKeyPairs = new ArrayList<String>();
   List<String> failedKeyPairs = new ArrayList<String>();
   SharedPreferences settings = GetOtherAppSharedPreferences();
   if (settings != null) {
     for (int i = 0; i < keypairs.length; i++) {
       try {
         String keyname = keypairs[i].getKey();
         String keyvalue = keypairs[i].getValue();
         Editor ed = settings.edit();
         ed.putString(keyname, keyvalue);
         ed.commit();
         successfullKeyPairs.add(keyname);
       } catch (Exception ex) {
         failedKeyPairs.add(keypairs[i].getKey());
       }
     }
   } else {
     LOGGER.logError("StoreKeyValuePairs", "Storage Unit is null.");
   }
   LOGGER.logInfo(
       "StoredKeyValuePairs",
       "Key stored in storage unit: "
           + successfullKeyPairs.size()
           + "; Keys Not stored in storage unit: "
           + failedKeyPairs.size());
   IActivityManager am =
       (IActivityManager)
           AndroidServiceLocator.GetInstance()
               .GetService(AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
   am.executeJS(
       "Unity.OnKeyValuePairsStoreCompleted",
       new Object[] {successfullKeyPairs.toArray(), failedKeyPairs.toArray()});
 }
示例#3
0
 private SQLiteDatabase openDatabase(Database db) throws SQLiteException {
   Context context = AndroidServiceLocator.getContext();
   return SQLiteDatabase.openDatabase(
       context.getDatabasePath(db.getName()).getAbsolutePath(),
       null,
       SQLiteDatabase.OPEN_READWRITE);
 }
示例#4
0
  @Override
  public Database[] GetDatabaseList() {
    Database[] result = null;

    LOGGER.logOperationBegin("GetDatabaseList", Logger.EMPTY_PARAMS, Logger.EMPTY_VALUES);

    try {
      String[] databaseNames = AndroidServiceLocator.getContext().databaseList();
      ArrayList<Database> databases = new ArrayList<Database>();
      for (String databaseName : databaseNames) {
        Database database =
            new Database(
                databaseName, DEFAULT_DATABASE_OPTION_NEW, DEFAULT_DATABASE_OPTION_COMPRESS);
        databases.add(database);
      }

      result = databases.toArray(new Database[databases.size()]);
    } catch (Exception ex) {
      LOGGER.logError("GetDatabaseList", "Error", ex);
    } finally {
      LOGGER.logOperationEnd("GetDatabaseList", result);
    }

    return result;
  }
示例#5
0
  private String checkProperty(String propertyName) {
    try {
      int resourceIdentifier =
          AndroidServiceLocator.getContext()
              .getResources()
              .getIdentifier(
                  propertyName, "string", AndroidServiceLocator.getContext().getPackageName());
      String propertyValue =
          AndroidServiceLocator.getContext().getResources().getString(resourceIdentifier);
      LOGGER.logInfo("Checking Shared Package Name", propertyName + "? " + propertyValue);
      return propertyValue;

    } catch (Exception ex) {
      LOGGER.logError(
          "Checking Shared Package Name",
          "Exception getting value for " + propertyName + ": " + ex.getMessage());
      return null;
    }
  }
示例#6
0
 private SharedPreferences GetOtherAppSharedPreferences() {
   SharedPreferences settings = null;
   try {
     Context otherAppCtx =
         AndroidServiceLocator.getContext()
             .createPackageContext(SHARED_PACKAGE_NAME, Context.CONTEXT_IGNORE_SECURITY);
     settings =
         otherAppCtx.getSharedPreferences(
             PREFERENCES_FILE_NAME, Context.MODE_MULTI_PROCESS + Context.MODE_PRIVATE);
   } catch (NameNotFoundException e) {
     LOGGER.logError("Opening Storage Unit", "The storage unit could not be accessed.");
   } catch (Exception e) {
     LOGGER.logError(
         "Opening Storage Unit", "The storage unit could not be accessed. Unhanlded error.");
   }
   return settings;
 }
示例#7
0
  @Override
  public boolean DeleteDatabase(Database db) {
    boolean result = false;

    LOGGER.logOperationBegin("DeleteDatabase", new String[] {"db"}, new Object[] {db});

    try {
      Context context = AndroidServiceLocator.getContext();
      result = context.deleteDatabase(db.getName());
    } catch (Exception ex) {
      LOGGER.logError("DeleteDatabase", "Error", ex);
    } finally {
      LOGGER.logOperationEnd("DeleteDatabase", result);
    }

    return result;
  }
示例#8
0
  @Override
  public void GetStoredKeyValuePair(String keyname) {
    List<KeyPair> foundKeyPairs = new ArrayList<KeyPair>();
    try {
      SharedPreferences settings = GetOtherAppSharedPreferences();
      if (settings != null) {
        if (settings.contains(keyname)) {
          foundKeyPairs.add(new KeyPair(keyname, settings.getString(keyname, null)));
        }
      } else LOGGER.logError("GetStoredKeyValuePair", "Storage Unit is null.");

    } catch (Exception e) {
      // TODO Auto-generated catch block
    }

    LOGGER.logInfo("GetStoredKeyValuePair", "Keys found in storage: " + foundKeyPairs.size());
    IActivityManager am =
        (IActivityManager)
            AndroidServiceLocator.GetInstance()
                .GetService(AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    am.executeJS("Unity.OnKeyValuePairsFound", new Object[] {foundKeyPairs.toArray()});
  }
示例#9
0
  @Override
  public Database CreateDatabase(String dbName) {
    Database db = null;

    LOGGER.logOperationBegin("CreateDatabase", new String[] {"dbName"}, new Object[] {dbName});

    SQLiteDatabase sqlDB = null;
    try {
      Context context = AndroidServiceLocator.getContext();
      sqlDB = context.openOrCreateDatabase(dbName, Context.MODE_PRIVATE, null);
      if (!sqlDB.isOpen()) {
        return null;
      }
      db = new Database(dbName, DEFAULT_DATABASE_OPTION_COMPRESS, DEFAULT_DATABASE_OPTION_NEW);
    } catch (Exception ex) {
      LOGGER.logError("CreateDatabase", "Error", ex);
    } finally {
      closeDatabase(sqlDB);
      LOGGER.logOperationEnd("CreateDatabase", db);
    }

    return db;
  }