/** The state is saved so that it is save to rotate the screen */
 @Override
 public void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putBoolean("evil", evilType);
   if (evilType) {
     outState.putSerializable("words", EvilGameplay.words);
   } else {
     outState.putString("word", game.word);
   }
   outState.putCharArray("guessed", game.lettersGuessed);
   outState.putCharArray("letters", game.wordLetters);
   outState.putInt("left", game.leftGuesses);
   outState.putInt("score", game.score);
   outState.putInt("setGuesses", game.setGuesses);
 }
 /**
  * Add extended data to the extra.
  *
  * @param name The name of the extra data, with package prefix.
  * @param value The char array data value.
  * @return Returns the same extra object, for chaining multiple calls into a single statement.
  * @see #putExtras
  * @see #removeExtra
  * @see #getCharArrayExtra(String)
  */
 public Request putExtra(String name, char[] value) {
   if (mExtras == null) {
     mExtras = new Bundle();
   }
   mExtras.putCharArray(name, value);
   return this;
 }
  public static HomeKontaktFragment newInstance(String data) {
    HomeKontaktFragment myFragment = new HomeKontaktFragment();

    Bundle args = new Bundle();
    args.putCharArray("data", data.toCharArray());
    myFragment.setArguments(args);

    return myFragment;
  }
  /**
   * Finishes activity with {@link Activity#RESULT_OK}.
   *
   * @param pattern the pattern, if this is in mode creating pattern. In any cases, it can be set to
   *     {@code null}.
   */
  private void finishWithResultOk(char[] pattern) {
    if (ACTION_CREATE_PATTERN.equals(getIntent().getAction()))
      mIntentResult.putExtra(EXTRA_PATTERN, pattern);
    else {
      /*
       * If the user was "logging in", minimum try count can not be zero.
       */
      mIntentResult.putExtra(EXTRA_RETRY_COUNT, mRetryCount + 1);
    }

    setResult(RESULT_OK, mIntentResult);

    /*
     * ResultReceiver
     */
    ResultReceiver receiver = getIntent().getParcelableExtra(EXTRA_RESULT_RECEIVER);
    if (receiver != null) {
      Bundle bundle = new Bundle();
      if (ACTION_CREATE_PATTERN.equals(getIntent().getAction()))
        bundle.putCharArray(EXTRA_PATTERN, pattern);
      else {
        /*
         * If the user was "logging in", minimum try count can not be
         * zero.
         */
        bundle.putInt(EXTRA_RETRY_COUNT, mRetryCount + 1);
      }
      receiver.send(RESULT_OK, bundle);
    }

    /*
     * PendingIntent
     */
    PendingIntent pi = getIntent().getParcelableExtra(EXTRA_PENDING_INTENT_OK);
    if (pi != null) {
      try {
        pi.send(this, RESULT_OK, mIntentResult);
      } catch (Throwable t) {
        Log.e(CLASSNAME, "Error sending PendingIntent: " + pi, t);
      }
    }

    finish();
  } // finishWithResultOk()
Example #5
0
  protected final void finishWithResultOk(char[] pattern) {
    if (LockPatternType.CREATE_PATTERN == lockPatternType) {
      if (autoSave) {
        AlpSettings.Security.setPattern(this, pattern);
      }
      intentResult.putExtra(EXTRA_PATTERN, pattern);
    } else {
      intentResult.putExtra(EXTRA_RETRY_COUNT, retryCount);
    }

    setResult(Activity.RESULT_OK, intentResult);

    /** ResultReceiver */
    ResultReceiver receiver = getIntent().getParcelableExtra(EXTRA_RESULT_RECEIVER);
    if (receiver != null) {
      Bundle bundle = new Bundle();
      if (LockPatternType.CREATE_PATTERN == lockPatternType)
        bundle.putCharArray(EXTRA_PATTERN, pattern);
      else {
        /** If the user was "logging in", minimum try count can not be zero. */
        bundle.putInt(EXTRA_RETRY_COUNT, retryCount);
      }
      bundle.putSerializable(EXTRA_LOCK_PATTERN_TYPE, lockPatternType);
      bundle.putBoolean(EXTRA_IS_MODIFY, isModify());
      receiver.send(Activity.RESULT_OK, bundle);
    }

    /** PendingIntent */
    PendingIntent pi = getIntent().getParcelableExtra(EXTRA_PENDING_INTENT_OK);
    if (pi != null) {
      try {
        pi.send(this, Activity.RESULT_OK, intentResult);
      } catch (Throwable t) {
        Log.e(CLASSNAME, "Error sending PendingIntent: " + pi, t);
      }
    }

    finish();
  }
 private static void putCharArray(String key, Bundle bundle) {
   bundle.putCharArray(key, getCharArray());
 }
  private void deserializeKey(String key, Bundle bundle) throws JSONException {
    String jsonString = cache.getString(key, "{}");
    JSONObject json = new JSONObject(jsonString);

    String valueType = json.getString(JSON_VALUE_TYPE);

    if (valueType.equals(TYPE_BOOLEAN)) {
      bundle.putBoolean(key, json.getBoolean(JSON_VALUE));
    } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      boolean[] array = new boolean[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = jsonArray.getBoolean(i);
      }
      bundle.putBooleanArray(key, array);
    } else if (valueType.equals(TYPE_BYTE)) {
      bundle.putByte(key, (byte) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_BYTE_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      byte[] array = new byte[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = (byte) jsonArray.getInt(i);
      }
      bundle.putByteArray(key, array);
    } else if (valueType.equals(TYPE_SHORT)) {
      bundle.putShort(key, (short) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_SHORT_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      short[] array = new short[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = (short) jsonArray.getInt(i);
      }
      bundle.putShortArray(key, array);
    } else if (valueType.equals(TYPE_INTEGER)) {
      bundle.putInt(key, json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_INTEGER_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      int[] array = new int[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = jsonArray.getInt(i);
      }
      bundle.putIntArray(key, array);
    } else if (valueType.equals(TYPE_LONG)) {
      bundle.putLong(key, json.getLong(JSON_VALUE));
    } else if (valueType.equals(TYPE_LONG_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      long[] array = new long[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = jsonArray.getLong(i);
      }
      bundle.putLongArray(key, array);
    } else if (valueType.equals(TYPE_FLOAT)) {
      bundle.putFloat(key, (float) json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_FLOAT_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      float[] array = new float[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = (float) jsonArray.getDouble(i);
      }
      bundle.putFloatArray(key, array);
    } else if (valueType.equals(TYPE_DOUBLE)) {
      bundle.putDouble(key, json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      double[] array = new double[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        array[i] = jsonArray.getDouble(i);
      }
      bundle.putDoubleArray(key, array);
    } else if (valueType.equals(TYPE_CHAR)) {
      String charString = json.getString(JSON_VALUE);
      if (charString != null && charString.length() == 1) {
        bundle.putChar(key, charString.charAt(0));
      }
    } else if (valueType.equals(TYPE_CHAR_ARRAY)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      char[] array = new char[jsonArray.length()];
      for (int i = 0; i < array.length; i++) {
        String charString = jsonArray.getString(i);
        if (charString != null && charString.length() == 1) {
          array[i] = charString.charAt(0);
        }
      }
      bundle.putCharArray(key, array);
    } else if (valueType.equals(TYPE_STRING)) {
      bundle.putString(key, json.getString(JSON_VALUE));
    } else if (valueType.equals(TYPE_STRING_LIST)) {
      JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
      int numStrings = jsonArray.length();
      ArrayList<String> stringList = new ArrayList<String>(numStrings);
      for (int i = 0; i < numStrings; i++) {
        Object jsonStringValue = jsonArray.get(i);
        stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue);
      }
      bundle.putStringArrayList(key, stringList);
    } else if (valueType.equals(TYPE_ENUM)) {
      try {
        String enumType = json.getString(JSON_VALUE_ENUM_TYPE);
        @SuppressWarnings({"unchecked", "rawtypes"})
        Class<? extends Enum> enumClass = (Class<? extends Enum>) Class.forName(enumType);
        @SuppressWarnings("unchecked")
        Enum<?> enumValue = Enum.valueOf(enumClass, json.getString(JSON_VALUE));
        bundle.putSerializable(key, enumValue);
      } catch (ClassNotFoundException e) {
      } catch (IllegalArgumentException e) {
      }
    }
  }
Example #8
0
 public Bundle to(Bundle bundle, char[] value) {
   if (bundle != null) {
     bundle.putCharArray(getName(), value);
   }
   return bundle;
 }