@Override
  public void onReceive(Context context, Intent intent) {
    LogHandler.configureLogger();

    try {
      String log = "onReceive: Action: ";
      log += intent.getAction();
      log += "( ";
      if (intent.getData() != null) {
        log += intent.getData().getScheme();
        log += "://";
        log += intent.getData().getHost();
      }
      log += " ) ";
      Bundle extras = intent.getExtras();
      log += "{ ";
      if (extras != null) {
        for (String extra : extras.keySet()) {
          log += extra + "[" + extras.get(extra) + "], ";
        }
      }
      log += " }";
      Log.d(this, log);
    } catch (Exception e) {
      Log.e(e);
    }

    try {
      if (ExternalAppConstants.SLEEP_AS_ANDROID_ALARM_EVENT
          .ALARM_TRIGGERED
          .getIntentAction()
          .equals(intent.getAction())) {
        Log.d("IntentReceiver", "Alarm triggered!");
        ActionHandler.execute(
            context, ExternalAppConstants.SLEEP_AS_ANDROID_ALARM_EVENT.ALARM_TRIGGERED);

      } else if (ExternalAppConstants.SLEEP_AS_ANDROID_ALARM_EVENT
          .ALARM_SNOOZED
          .getIntentAction()
          .equals(intent.getAction())) {
        Log.d("IntentReceiver", "Alarm snoozed...");
        ActionHandler.execute(
            context, ExternalAppConstants.SLEEP_AS_ANDROID_ALARM_EVENT.ALARM_SNOOZED);

      } else if (ExternalAppConstants.SLEEP_AS_ANDROID_ALARM_EVENT
          .ALARM_DISMISSED
          .getIntentAction()
          .equals(intent.getAction())) {
        Log.d("IntentReceiver", "Alarm dismissed...");
        ActionHandler.execute(
            context, ExternalAppConstants.SLEEP_AS_ANDROID_ALARM_EVENT.ALARM_DISMISSED);

      } else {
        Log.d("IntentReceiver", "Received unknown intent: " + intent.getAction());
      }

    } catch (Exception e) {
      Log.e(e);
    }
  }
Esempio n. 2
1
  public void logIntent(String tag, String msg, Intent intent, int logLevel, boolean logExtras) {
    StringBuilder sb = new StringBuilder();

    if (msg != null) {
      sb.append(msg);
      sb.append(intent.toString());
    } else {
      sb.append("LOG Intent: ");
      sb.append(intent.toString());
    }

    if (intent.getAction() != null) {
      sb.append(intent.getAction());
      sb.append(" ");
    }

    if (intent.getDataString() != null) {
      sb.append(intent.getDataString());
      sb.append(" ");
    }

    if (logExtras) {
      Bundle extras = intent.getExtras();
      if (extras != null) {
        for (String key : extras.keySet()) {
          String extra = String.valueOf(extras.get(key));
          sb.append(String.format("EXTRA [\"%s\"]: %s ", key, extra));
        }
      }
    }

    log(tag, sb.toString(), logLevel);
  }
Esempio n. 3
0
  /**
   * This is a convenience method to test whether or not two bundles' contents are equal. This
   * method only works if the contents of each bundle are primitive data types or strings. Otherwise
   * this method may wrongly report they they are not equal.
   *
   * @param bundle1
   * @param bundle2
   * @return
   */
  public static boolean areEqual(Bundle bundle1, Bundle bundle2) {
    // Null for none or both, or the same
    if (bundle1 == null) {
      return bundle2 == null;
    } else if (bundle2 == null) {
      return false;
    } else if (bundle1 == bundle2) {
      return true;
    }

    // Same key set
    Set<String> keySet = bundle1.keySet();
    if (!keySet.equals(bundle2.keySet())) {
      return false;
    }

    // Same values in key set
    for (String key : keySet) {
      Object value1 = bundle1.get(key);
      Object value2 = bundle2.get(key);
      if (!(value1 == null ? value2 == null : value1.equals(value2))) {
        return false;
      }
    }
    return true;
  }
 private void updateValuesFromBundle(Bundle savedInstanceState) {
   if (savedInstanceState != null) {
     if (savedInstanceState.keySet().contains(REQUESTING_LOCATION_UPDATES_KEY)) {
       requestingLocationUpdates = savedInstanceState.getBoolean(REQUESTING_LOCATION_UPDATES_KEY);
     }
     if (savedInstanceState.keySet().contains(LOCATION_KEY)) {
       lastLocation = savedInstanceState.getParcelable(LOCATION_KEY);
     }
   }
 }
Esempio n. 5
0
  public static void printIntent(Intent intent) {
    EzLog.d("[Intent Info] actionName=" + intent.getAction());
    EzLog.d("  + Intent toString=" + intent.toString());

    Bundle extras = intent.getExtras();
    if (extras == null) return;

    Set keys = extras.keySet();
    int index = 0;
    for (String key : extras.keySet()) {
      EzLog.d("  + [" + index + "]" + " key=" + key + ", value=" + extras.get(key));
      index += 1;
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mRepository = (Repository) getArguments().getSerializable("repository");
    mSelectedRef = getArguments().getString("ref");

    if (savedInstanceState != null) {
      for (String entry : savedInstanceState.getStringArrayList(STATE_KEY_DIR_STACK)) {
        mDirStack.add(entry);
      }

      int prefixLen = STATE_KEY_CONTENT_CACHE_PREFIX.length();
      for (String key : savedInstanceState.keySet()) {
        if (key.startsWith(STATE_KEY_CONTENT_CACHE_PREFIX)) {
          String cacheKey = key.substring(prefixLen);
          if (cacheKey.equals("/")) {
            cacheKey = null;
          }
          mContentCache.put(
              cacheKey, (ArrayList<RepositoryContents>) savedInstanceState.getSerializable(key));
        }
      }
    } else {
      mDirStack.push("");
    }
  }
  /**
   * Transform Android event data into JSON Object used by JavaScript
   *
   * @param intent inBeacon SDK event data
   * @return a JSONObject with keys 'event', 'name' and 'data'
   */
  private JSONObject getEventObject(Intent intent) {
    String action = intent.getAction();
    String event = action.substring(action.lastIndexOf(".") + 1); // last part of action
    String message = intent.getStringExtra("message");
    Bundle extras = intent.getExtras();

    JSONObject eventObject = new JSONObject();
    JSONObject data = new JSONObject();

    try {
      if (extras != null) {
        Set<String> keys = extras.keySet();
        for (String key : keys) {
          data.put(key, extras.get(key)); // Android API < 19
          //                    data.put(key, JSONObject.wrap(extras.get(key)));    // Android API
          // >= 19
        }
      }
      data.put("message", message);

      eventObject.put("name", event);
      eventObject.put("data", data);

    } catch (JSONException e) {
      Log.e(TAG, e.getMessage(), e);
    }

    return eventObject;
  }
Esempio n. 8
0
  public static String doRequestPost(String url, Bundle params) {
    ArrayList<BasicNameValuePair> paramsList = new ArrayList<BasicNameValuePair>();
    BasicNameValuePair paramPair;
    if (params != null) {
      for (String key : params.keySet()) {
        paramPair = new BasicNameValuePair(key, params.getString(key));
        paramsList.add(paramPair);
      }
    }

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, CONNECTION_TIME_OUT);
    HttpConnectionParams.setSoTimeout(httpParameters, SOCKET_TIME_OUT);

    try {
      HttpPost httpRequest = new HttpPost(url);
      httpRequest.setEntity(new UrlEncodedFormEntity(paramsList, HTTP.UTF_8));
      HttpResponse httpResponse = new DefaultHttpClient(httpParameters).execute(httpRequest);

      if (httpResponse.getStatusLine().getStatusCode() == SUCCESS_STATUS) {
        String strResult = EntityUtils.toString(httpResponse.getEntity());
        return strResult;
      } else {
        LogUtils.logD("Http response error when do post operation!");
        return null;
      }
    } catch (Exception e) {
      LogUtils.logE(e.getMessage());
      return null;
    }
  }
    /**
     * Returns true if is a single email or single phone number provided in the {@link
     * android.content.Intent} extras bundle so that a pop-up confirmation dialog can be used to add
     * the data to a contact. Otherwise return false if there are other intent extras that require
     * launching the full contact editor. Ignore extras with the key {@link
     * com.silentcircle.silentcontacts.ScContactsContract.Intents.Insert NAME} because names are a
     * special case and we typically don't want to replace the name of an existing contact.
     */
    private boolean launchAddToContactDialog(Bundle extras) {
      if (extras == null) {
        return false;
      }

      // Copy extras because the set may be modified in the next step
      Set<String> intentExtraKeys = Sets.newHashSet();
      intentExtraKeys.addAll(extras.keySet());

      // Ignore name key because this is an existing contact.
      if (intentExtraKeys.contains(Insert.NAME)) {
        intentExtraKeys.remove(Insert.NAME);
      }

      int numIntentExtraKeys = intentExtraKeys.size();
      if (numIntentExtraKeys == 2) {
        boolean hasPhone =
            intentExtraKeys.contains(Insert.PHONE) && intentExtraKeys.contains(Insert.PHONE_TYPE);
        boolean hasEmail =
            intentExtraKeys.contains(Insert.EMAIL) && intentExtraKeys.contains(Insert.EMAIL_TYPE);
        return hasPhone || hasEmail;
      } else if (numIntentExtraKeys == 1) {
        return intentExtraKeys.contains(Insert.PHONE) || intentExtraKeys.contains(Insert.EMAIL);
      }
      // Having 0 or more than 2 intent extra keys means that we should launch
      // the full contact editor to properly handle the intent extras.
      return false;
    }
Esempio n. 10
0
 public int hashCode() {
   Iterator localIterator = zzawD.keySet().iterator();
   String str;
   for (int i = 1; localIterator.hasNext(); i = zzawD.get(str).hashCode() + i * 31)
     str = (String) localIterator.next();
   return i;
 }
  /**
   * Persists all supported data types present in the passed in Bundle, to the cache
   *
   * @param bundle The Bundle containing information to be cached
   */
  public void save(Bundle bundle) {
    Validate.notNull(bundle, "bundle");

    SharedPreferences.Editor editor = cache.edit();

    for (String key : bundle.keySet()) {
      try {
        serializeKey(key, bundle, editor);
      } catch (JSONException e) {
        // Error in the bundle. Don't store a partial cache.
        Logger.log(
            LoggingBehavior.CACHE,
            Log.WARN,
            TAG,
            "Error processing value for key: '" + key + "' -- " + e);

        // Bypass the commit and just return. This cancels the entire edit transaction
        return;
      }
    }

    boolean successfulCommit = editor.commit();
    if (!successfulCommit) {
      Logger.log(
          LoggingBehavior.CACHE,
          Log.WARN,
          TAG,
          "SharedPreferences.Editor.commit() was not successful");
    }
  }
    @Override
    public void onComplete(Bundle values, FacebookException error) {
      if (error != null) {
        nativeCallback(mCallbackIndex, "null");
        error.printStackTrace();
      } else {
        if (values != null) {
          Set<String> keySet = values.keySet();
          JSONObject jsonObject = new JSONObject();

          for (String key : keySet) {
            Object valueObject = values.get(key);
            try {
              if (valueObject instanceof String) jsonObject.put(key, (String) valueObject);
              else if (valueObject instanceof Integer)
                jsonObject.put(key, ((Integer) valueObject).intValue());
              else if (valueObject instanceof Double)
                jsonObject.put(key, ((Double) valueObject).doubleValue());
              else if (valueObject instanceof Boolean)
                jsonObject.put(key, ((Boolean) valueObject).booleanValue());
              else if (valueObject instanceof JSONObject) jsonObject.put(key, valueObject);
            } catch (JSONException e) {
              e.printStackTrace();
            }
          }
          nativeCallback(mCallbackIndex, jsonObject.toString());
        }
      }
    }
  /**
   * Copy data from passed Bundle to current accumulated data. Does some careful processing of the
   * data.
   *
   * @param bookData Source
   */
  private void accumulateData(int searchId) {
    // See if we got data from this source
    if (!mSearchResults.containsKey(searchId)) return;
    Bundle bookData = mSearchResults.get(searchId);

    // See if we REALLY got data from this source
    if (bookData == null) return;

    for (String k : bookData.keySet()) {
      // If its not there, copy it.
      if (!mBookData.containsKey(k)
          || mBookData.getString(k) == null
          || mBookData.getString(k).trim().length() == 0)
        mBookData.putString(k, bookData.get(k).toString());
      else {
        // Copy, append or update data as appropriate.
        if (k.equals(CatalogueDBAdapter.KEY_AUTHOR_DETAILS)) {
          appendData(k, bookData, mBookData);
        } else if (k.equals(CatalogueDBAdapter.KEY_SERIES_DETAILS)) {
          appendData(k, bookData, mBookData);
        } else if (k.equals(CatalogueDBAdapter.KEY_DATE_PUBLISHED)) {
          // Grab a different date if we can parse it.
          Date newDate = Utils.parseDate(bookData.getString(k));
          if (newDate != null) {
            String curr = mBookData.getString(k);
            if (Utils.parseDate(curr) == null) {
              mBookData.putString(k, Utils.toSqlDateOnly(newDate));
            }
          }
        } else if (k.equals("__thumbnail")) {
          appendData(k, bookData, mBookData);
        }
      }
    }
  }
Esempio n. 14
0
 public static void extrasToStringBuilder(Bundle bundle, StringBuilder sb) {
   sb.append("[");
   for (String key : bundle.keySet()) {
     sb.append(key).append("=").append(bundle.get(key)).append(" ");
   }
   sb.append("]");
 }
Esempio n. 15
0
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == LOADAPP_RQ_CODE) {
     JSONObject json = new JSONObject();
     JSONObject jValue = new JSONObject();
     try {
       if (null != data) {
         Bundle bundle = data.getExtras();
         if (null != bundle) {
           Set<String> keys = bundle.keySet();
           if (null != keys) {
             for (String key : keys) {
               Object value = bundle.get(key);
               jValue.put(key, value);
             }
           }
         }
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
     try {
       json.put("value", jValue);
       if (resultCode == Activity.RESULT_OK) {
         json.put("resultCode", 1);
       } else {
         json.put("resultCode", 0);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
     jsCallback(function_loadApp, 0, EUExCallback.F_C_JSON, json.toString());
   }
 }
 protected final String invoke_put_string(String url, Bundle params) throws IOException {
   DefaultHttpClient dhc = new DefaultHttpClient();
   try {
     set_basic_auth(dhc);
     Log.i(_module_name, "PUT: " + url);
     HttpPut put = new HttpPut(url);
     sign_auth(put);
     if (params != null) {
       ArrayList<NameValuePair> nvps = new ArrayList<NameValuePair>();
       for (String key : params.keySet()) {
         nvps.add(new BasicNameValuePair(key, params.getString(key)));
       }
       UrlEncodedFormEntity reqEntity = new UrlEncodedFormEntity(nvps, "UTF-8");
       put.setEntity(reqEntity);
     }
     HttpResponse httpResponse = dhc.execute(put);
     int statusCode = httpResponse.getStatusLine().getStatusCode();
     String res = UHttpComponents.loadStringFromHttpResponse(httpResponse);
     if (!is_ok_status(statusCode)) {
       String phrase = httpResponse.getStatusLine().getReasonPhrase();
       String msg = String.format("PUT*STATUS: [%s:%s] %s <= %s", statusCode, phrase, res, url);
       throw new HttpIOException(msg, put, statusCode, phrase, res);
     }
     Log.i(_module_name, String.format("PUT-OK: %s <= %s", make_log_message(res.toString()), url));
     return res;
   } catch (IOException e) {
     Log.w(_module_name, String.format("PUT*IO: %s <= %s", e.getMessage(), url), e);
     throw e;
   } catch (Throwable e) {
     Log.w(_module_name, String.format("PUT*Throwable: %s <= %s", e.getMessage(), url), e);
     throw new InvocationTargetIOException(e);
   } finally {
     dhc.getConnectionManager().shutdown();
   }
 }
  public void testAssistContentAndAssistData() throws Exception {
    mTestActivity.startTest(TEST_CASE_TYPE);
    waitForAssistantToBeReady(mReadyLatch);
    mTestActivity.start3pApp(TEST_CASE_TYPE);
    waitForOnResume();
    startSession();
    waitForContext();
    verifyAssistDataNullness(false, false, false, false);

    Log.i(TAG, "assist bundle is: " + Utils.toBundleString(mAssistBundle));

    // tests that the assist content's structured data is the expected
    assertEquals(
        "AssistContent structured data did not match data in onProvideAssistContent",
        Utils.getStructuredJSON(),
        mAssistContent.getStructuredData());
    // tests the assist data. EXTRA_ASSIST_CONTEXT is what's expected.
    Bundle extraExpectedBundle = Utils.getExtraAssistBundle();
    Bundle extraAssistBundle = mAssistBundle.getBundle(Intent.EXTRA_ASSIST_CONTEXT);
    for (String key : extraExpectedBundle.keySet()) {
      assertTrue(
          "Assist bundle does not contain expected extra context key: " + key,
          extraAssistBundle.containsKey(key));
      assertEquals(
          "Extra assist context bundle values do not match for key: " + key,
          extraExpectedBundle.get(key),
          extraAssistBundle.get(key));
    }
  }
Esempio n. 18
0
 // 鎵撳嵃鎵�湁鐨�intent extra 鏁版嵁
 public static String printBundle(Bundle bundle) {
   StringBuilder sb = new StringBuilder();
   for (String key : bundle.keySet()) {
     sb.append("\nkey:" + key + ", value:" + bundle.getString(key));
   }
   return sb.toString();
 }
  protected void onStart() {
    super.onStart();
    this.a.updateHeader(
        "No current file!",
        R.string.pref_hardware_config_filename,
        R.id.active_filename,
        R.id.included_header);
    Bundle var1 = this.getIntent().getExtras();
    if (var1 != null) {
      Iterator var2 = var1.keySet().iterator();

      while (var2.hasNext()) {
        String var6 = (String) var2.next();
        DeviceConfiguration var7 = (DeviceConfiguration) var1.getSerializable(var6);
        this.j.add(Integer.parseInt(var6), var7);
      }

      for (int var3 = 0; var3 < this.j.size(); ++var3) {
        View var4 = this.a(var3);
        DeviceConfiguration var5 = (DeviceConfiguration) this.j.get(var3);
        this.a(var4);
        this.b(var4, var5);
        this.a(var4, var5);
      }
    }
  }
Esempio n. 20
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(
        TAG,
        getClass().getSimpleName()
            + ".onCreate ("
            + hashCode()
            + "): "
            + (savedInstanceState != null));

    ApiCompatUtil compatUtil = ApiCompatUtil.getInstance();
    compatUtil.requestWindowFeatures(this);
    setContentView(R.layout.prime);
    compatUtil.setWindowFeatures(this);

    compatUtil.setupActionBar(this);

    int curTab = DEFAULT_TAB;

    if (savedInstanceState != null) {
      Bundle fragData = savedInstanceState.getBundle("fragData");
      if (fragData != null) {
        Log.d(TAG, "MainActivity.onCreate: got fragData!");
        for (String key : fragData.keySet()) {
          Log.d(TAG, "  fragData key: " + key);
          if (!m_fragData.containsKey(key)) m_fragData.putBundle(key, fragData.getBundle(key));
        }
      }

      curTab = savedInstanceState.getInt(PrefKey.opentab.name(), DEFAULT_TAB);
    }

    boolean upgraded = false;
    if (savedInstanceState != null) {
      //      setCurrentTab(savedInstanceState.getInt(PrefKey.opentab.name(), -1));
    } else {
      Resources resources = getResources();
      SharedPreferences p = StaticUtils.getApplicationPreferences(this);
      upgraded = StaticUtils.checkUpgrade(this);
      if (!readInstanceState(this)) setInitialState();
      if (PrefKey.sync_on_open.getBoolean(p, resources)) {
        WeaveAccountInfo loginInfo = StaticUtils.getLoginInfo(this);
        if (upgraded || loginInfo == null) {
          StaticUtils.requestSync(this, m_handler);
        }
      }
    }

    FragmentManager fm = getSupportFragmentManager();
    // You can find Fragments just like you would with a View by using FragmentManager.
    Fragment fragment = fm.findFragmentById(R.id.fragment_content);

    // If we are using activity_fragment_xml.xml then this the fragment will not be null, otherwise
    // it will be.
    if (fragment == null) {
      setMyFragment(new MiscListFragment(), false);
    }
  }
Esempio n. 21
0
  /*
   * serializes a bundle to JSON.
   */
  private static JSONObject convertBundleToJson(Bundle extras) {
    try {
      JSONObject json;
      json = new JSONObject().put("event", "message");

      JSONObject jsondata = new JSONObject();
      Iterator<String> it = extras.keySet().iterator();
      while (it.hasNext()) {
        String key = it.next();
        Object value = extras.get(key);

        // System data from Android
        if (key.equals("from") || key.equals("collapse_key")) {
          json.put(key, value);
        } else if (key.equals("foreground")) {
          json.put(key, extras.getBoolean("foreground"));
        } else if (key.equals("coldstart")) {
          json.put(key, extras.getBoolean("coldstart"));
        } else {
          // Maintain backwards compatibility
          if (key.equals("message") || key.equals("msgcnt") || key.equals("soundname")) {
            json.put(key, value);
          }

          if (value instanceof String) {
            // Try to figure out if the value is another JSON object

            String strValue = (String) value;
            if (strValue.startsWith("{")) {
              try {
                JSONObject json2 = new JSONObject(strValue);
                jsondata.put(key, json2);
              } catch (Exception e) {
                jsondata.put(key, value);
              }
              // Try to figure out if the value is another JSON array
            } else if (strValue.startsWith("[")) {
              try {
                JSONArray json2 = new JSONArray(strValue);
                jsondata.put(key, json2);
              } catch (Exception e) {
                jsondata.put(key, value);
              }
            } else {
              jsondata.put(key, value);
            }
          }
        }
      } // while
      json.put("payload", jsondata);

      Log.v(TAG, "extrasToJSON: " + json.toString());

      return json;
    } catch (JSONException e) {
      Log.e(TAG, "extrasToJSON: JSON exception");
    }
    return null;
  }
Esempio n. 22
0
  @Override
  protected void onMessage(Context arg0, Intent message) {
    Bundle extras = message.getExtras();

    for (String key : extras.keySet()) {
      Log.d(Constants.TAG, String.format("onMessage: %s=%s", key, extras.getString(key)));
    }
  }
Esempio n. 23
0
 private LogcatReaderLoader(Parcel in) {
   this.recordingMode = in.readInt() == 1;
   this.multiple = in.readInt() == 1;
   Bundle bundle = in.readBundle();
   for (String key : bundle.keySet()) {
     lastLines.put(key, bundle.getString(key));
   }
 }
  private Map<String, Object> extrasToMap(Bundle extras) {
    Map<String, Object> dataMap = new TreeMap<String, Object>();
    for (String key : extras.keySet()) {
      dataMap.put(key, extras.get(key));
    }

    return dataMap;
  }
Esempio n. 25
0
 // Create a new LibInfo map from a Bundle.
 private static HashMap<String, LibInfo> createLibInfoMapFromBundle(Bundle bundle) {
   HashMap<String, LibInfo> map = new HashMap<String, LibInfo>();
   for (String library : bundle.keySet()) {
     LibInfo libInfo = bundle.getParcelable(library);
     map.put(library, libInfo);
   }
   return map;
 }
  /*
   * serializes a bundle to JSON.
   */
  private static JSONObject convertBundleToJson(Bundle extras) {
    try {
      JSONObject json = new JSONObject();
      JSONObject additionalData = new JSONObject();
      Iterator<String> it = extras.keySet().iterator();
      while (it.hasNext()) {
        String key = it.next();
        Object value = extras.get(key);

        Log.d(LOG_TAG, "key = " + key);

        // System data from Android
        if (key.equals("from") || key.equals("collapse_key")) {
          additionalData.put(key, value);
        } else if (key.equals("foreground")) {
          additionalData.put(key, extras.getBoolean("foreground"));
        } else if (key.equals("coldstart")) {
          additionalData.put(key, extras.getBoolean("coldstart"));
        } else if (key.equals("message") || key.equals("body")) {
          json.put("message", value);
        } else if (key.equals("title")) {
          json.put("title", value);
        } else if (key.equals("msgcnt") || key.equals("badge")) {
          json.put("count", value);
        } else if (key.equals("soundname") || key.equals("sound")) {
          json.put("sound", value);
        } else if (key.equals("image")) {
          json.put("image", value);
        } else if (key.equals("callback")) {
          json.put("callback", value);
        } else if (value instanceof String) {
          String strValue = (String) value;
          try {
            // Try to figure out if the value is another JSON object
            if (strValue.startsWith("{")) {
              additionalData.put(key, new JSONObject(strValue));
            }
            // Try to figure out if the value is another JSON array
            else if (strValue.startsWith("[")) {
              additionalData.put(key, new JSONArray(strValue));
            } else {
              additionalData.put(key, value);
            }
          } catch (Exception e) {
            additionalData.put(key, value);
          }
        }
      } // while

      json.put("additionalData", additionalData);
      Log.v(LOG_TAG, "extrasToJSON: " + json.toString());

      return json;
    } catch (JSONException e) {
      Log.e(LOG_TAG, "extrasToJSON: JSON exception");
    }
    return null;
  }
 public final void loadFromBundle(Bundle savedBundle) {
   if (mChildStates != null && savedBundle != null) {
     mChildStates.evictAll();
     for (Iterator<String> i = savedBundle.keySet().iterator(); i.hasNext(); ) {
       String key = i.next();
       mChildStates.put(key, savedBundle.getSparseParcelableArray(key));
     }
   }
 }
Esempio n. 28
0
 public synchronized void restoreInstanceState(Bundle inState) {
   for (String k : inState.keySet()) {
     if (k.startsWith(COOKIE_PREFIX) && k.endsWith(COOKIE_VALUE_TAG)) {
       String cookieName = k.substring(COOKIE_PREFIX_LEN, k.length() - COOKIE_VALUE_TAG_LEN);
       BasicClientCookie c = cookieFromBundle(inState, cookieName);
       super.addCookie(c);
     }
   }
 }
  @Override
  public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
      Bundle bundle = (Bundle) state;
      bundle.setClassLoader(loader);
      ArrayList<FragmentState> fs = bundle.getParcelableArrayList("states_fragment");
      ArrayList<Bundle> args = bundle.getParcelableArrayList("arg_fragment");
      ArrayList<String> tags = bundle.getStringArrayList("tag_fragment");
      ArrayList<String> classNames = bundle.getStringArrayList("classname_fragment");

      mFragments.clear();
      mFragmentStates.clear();
      mFragmentTags.clear();
      mFragmentClassNames.clear();
      mFragmentArgs.clear();
      if (fs != null) {
        for (int i = 0; i < fs.size(); i++) {
          FragmentState fragmentState = fs.get(i);
          mFragmentStates.add(fragmentState);
          if (fragmentState != null) {
            mFragmentArgs.add(fragmentState.mArguments);
            mFragmentTags.add(fragmentState.mTag);
            mFragmentClassNames.add(fragmentState.mClassName);
          } else {
            mFragmentArgs.add(args.get(i));
            mFragmentTags.add(tags.get(i));
            mFragmentClassNames.add(classNames.get(i));
          }
          mFragments.add(null);
        }
      }
      Iterable<String> keys = bundle.keySet();
      for (String key : keys) {
        if (key.startsWith("f")) {
          int index = Integer.parseInt(key.substring(1));
          Fragment f = null;
          try {
            f = mFragmentManager.getFragment(bundle, key);
          } catch (Throwable ex) {
            ex.printStackTrace();
          }
          if (f != null) {
            f.setMenuVisibility(false);
            mFragments.set(index, f);
            mFragmentArgs.set(index, f.mArguments);
            mFragmentTags.set(index, f.mTag);
            mFragmentClassNames.set(index, f.getClass().getName());
          } else {
            Log.w(TAG, "Bad fragment at key " + key);
          }
        }
      }
      // If restore will change
      notifyDataSetChanged();
    }
  }
 public ActiveRecordPartial where(Bundle data) {
   Set<String> keys = data.keySet();
   for (String key : keys) {
     if (data.get(key) == null) continue;
     String whereSQL = "";
     whereSQL = "'" + key + "' = " + data.get(key).toString();
     _whereList.add(whereSQL);
   }
   return this;
 }