Example usage for android.os Bundle isEmpty

List of usage examples for android.os Bundle isEmpty

Introduction

In this page you can find the example usage for android.os Bundle isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if the mapping of this Bundle is empty, false otherwise.

Usage

From source file:Main.java

public static boolean isEmpty(Bundle bundle) {
    if (bundle == null || bundle.isEmpty()) {
        return true;
    }// w w w  . j av  a  2 s .  c o  m

    return false;
}

From source file:Main.java

/**
 * Converts a {@link android.os.Bundle} object to a {@code String}.
 *
 * @param bundle The converted bundle./*from   w ww  .ja va2s.com*/
 * @return The string representation of the bundle.
 */
@NonNull
public static String toString(@Nullable final Bundle bundle) {
    if (bundle == null) {
        return "null";
    }

    if (bundle.isEmpty()) {
        return "";
    }

    final StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append('[');
    for (String key : bundle.keySet()) {
        stringBuilder.append('"').append(key).append("\":\"").append(bundle.get(key)).append('"')
                .append(ITEM_DIVIDER);
    }
    stringBuilder.setLength(stringBuilder.length() - ITEM_DIVIDER.length());
    stringBuilder.append(']');
    return stringBuilder.toString();
}

From source file:com.fanfou.app.opensource.util.IntentHelper.java

public static void logIntent(final String tag, final Intent intent) {
    if (intent == null) {
        return;// w w  w . j  a v a2  s.c  o  m
    }
    final StringBuffer sb = new StringBuffer();
    sb.append("\nAction:" + intent.getAction());
    sb.append("\nData:" + intent.getData());
    sb.append("\nDataStr:" + intent.getDataString());
    sb.append("\nScheme:" + intent.getScheme());
    sb.append("\nType:" + intent.getType());
    final Bundle extras = intent.getExtras();
    if ((extras != null) && !extras.isEmpty()) {
        for (final String key : extras.keySet()) {
            final Object value = extras.get(key);
            sb.append("\nEXTRA: {" + key + "::" + value + "}");
        }
    } else {
        sb.append("\nNO EXTRAS");
    }
    Log.i(tag, sb.toString());
}

From source file:org.peercast.core.Channel.java

/**
 * nativeGetChannels??wrap???/*  w w  w . ja  va  2 s  .  co m*/
 *
 * @see PeerCastService#nativeGetChannels()
 */
public static List<Channel> fromNativeResult(Bundle bChannels) {
    List<Channel> channels = new ArrayList<>();

    while (bChannels != null && !bChannels.isEmpty()) {
        //Log.d("Channel.java", ""+bChannel);
        channels.add(new Channel(bChannels));
        bChannels = bChannels.getBundle("next");
    }
    return channels;
}

From source file:com.groupme.sdk.util.HttpUtils.java

public static String encodeParams(Bundle params) {
    if (params == null || params.isEmpty()) {
        return "";
    }//from   w w w . j a  v  a 2 s.co  m

    StringBuilder sb = new StringBuilder();
    boolean first = true;

    for (String key : params.keySet()) {
        if (first) {
            first = false;
        } else {
            sb.append("&");
        }

        try {
            sb.append(URLEncoder.encode(key, Constants.UTF_8)).append("=")
                    .append(URLEncoder.encode(params.getString(key), Constants.UTF_8));
        } catch (UnsupportedEncodingException e) {
            Log.e(Constants.LOG_TAG, "Unsupported encoding: " + e.toString());
        }
    }

    return sb.toString();
}

From source file:com.scoreflex.ScoreflexGcmClient.java

protected static boolean onBroadcastReceived(Context context, Intent intent, int iconResource,
        Class<? extends Activity> activity) {
    Bundle extras = intent.getExtras();

    if (extras.isEmpty()) { // has effect of unparcelling Bundle
        return false;
    }//from  ww w  .  j a  v a2  s  . c  o m
    String customDataJson = extras.getString(SCOREFLEX_CUSTOM_DATA_EXTRA_KEY);
    if (null == customDataJson) {
        return false;
    }

    try {

        JSONObject customData = new JSONObject(customDataJson);
        JSONObject data = customData.getJSONObject(SCOREFLEX_NOTIFICATION_EXTRA_KEY);
        JSONObject sfxData = data.optJSONObject("data");

        if (data.getInt("code") < Scoreflex.NOTIFICATION_TYPE_CHALLENGE_INVITATION) {
            return false;
        }
        String targetPlayerId = sfxData.optString("targetPlayerId");
        String loggedPlayerId = ScoreflexRestClient.getPlayerId(context);

        if (!targetPlayerId.equals(loggedPlayerId)) {
            return false;
        }
        PendingIntent pendingIntent = buildPendingIntent(data, context, activity);
        Notification notification = buildNotification(extras.getString("alert"), context, iconResource,
                pendingIntent);

        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(data.getInt("code"), notification);
        intent.removeExtra(SCOREFLEX_CUSTOM_DATA_EXTRA_KEY);
    } catch (JSONException e1) {

    }

    return false;
}

From source file:org.alfresco.mobile.android.application.fragments.signin.AccountOAuthFragment.java

public static AccountOAuthFragment getOAuthFragment(Context context, AlfrescoAccount account) {
    String oauthUrl = null, apikey = null, apisecret = null;
    Bundle b = SessionManager.getInstance(context).getOAuthSettings();
    if (b != null && !b.isEmpty()) {
        oauthUrl = b.getString(OAUTH_URL);
        apikey = b.getString(OAUTH_API_KEY);
        apisecret = b.getString(OAUTH_API_SECRET);
    }//w w w  .  j ava 2s. co  m

    if (account != null) {
        String tmpOauthUrl = account.getUrl();
        if (!tmpOauthUrl.equals(oauthUrl)) {
            oauthUrl = tmpOauthUrl;
            apikey = null;
            apisecret = null;
        }
    }

    AccountOAuthFragment oauthFragment;
    if (oauthUrl == null || oauthUrl.isEmpty()) {
        oauthFragment = new AccountOAuthFragment();
    } else {
        oauthFragment = new AccountOAuthFragment(oauthUrl, apikey, apisecret);
    }
    return oauthFragment;
}

From source file:com.amazon.cordova.plugin.ADMMessageHandler.java

public static Bundle getOfflineMessage() {
    Bundle pushBundle = null;
    if (notificationIntent != null) {
        pushBundle = notificationIntent.getExtras().getBundle(PUSH_BUNDLE);
        if (pushBundle.isEmpty()) {
            pushBundle = null;/*from  w  w w.  ja v  a2s.  co  m*/
        }
    }
    return pushBundle;
}

From source file:com.zrlh.llkc.funciton.Http_Utility.java

/**
 * Construct a url encoded entity by parameters .
 * /*w w w .  jav  a 2s.  com*/
 * @param bundle
 *            :parameters key pairs
 * @return UrlEncodedFormEntity: encoed entity
 */
public static UrlEncodedFormEntity getPostParamters(Bundle bundle) throws Exception {
    if (bundle == null || bundle.isEmpty()) {
        return null;
    }
    try {
        List<NameValuePair> form = new ArrayList<NameValuePair>();
        for (String key : bundle.keySet()) {
            form.add(new BasicNameValuePair(key, bundle.getString(key)));
        }
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, "UTF-8");
        return entity;
    } catch (UnsupportedEncodingException e) {
        throw new UnsupportedEncodingException();
    }
}

From source file:com.groupme.sdk.util.HttpUtils.java

public static InputStream openStream(HttpClient client, String url, int method, String body, Bundle params,
        Bundle headers) throws HttpResponseException {
    HttpResponse response;/* www.  j  av  a2  s.  c  o  m*/
    InputStream in = null;

    Log.v("HttpUtils", "URL = " + url);

    try {
        switch (method) {
        case METHOD_GET:
            url = url + "?" + encodeParams(params);
            HttpGet get = new HttpGet(url);

            if (headers != null && !headers.isEmpty()) {
                for (String header : headers.keySet()) {
                    get.setHeader(header, headers.getString(header));
                }
            }

            response = client.execute(get);
            break;
        case METHOD_POST:
            if (body != null) {
                url = url + "?" + encodeParams(params);
            }

            HttpPost post = new HttpPost(url);
            Log.d(Constants.LOG_TAG, "URL: " + url);

            if (headers != null && !headers.isEmpty()) {
                for (String header : headers.keySet()) {
                    post.setHeader(header, headers.getString(header));
                }
            }

            if (body == null) {
                List<NameValuePair> pairs = bundleToList(params);
                post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));
            } else {
                post.setEntity(new StringEntity(body));
            }

            response = client.execute(post);
            break;
        case METHOD_PUT:
            if (body != null) {
                url = url + "?" + encodeParams(params);
            }

            HttpPut put = new HttpPut(url);

            if (headers != null && !headers.isEmpty()) {
                for (String header : headers.keySet()) {
                    put.setHeader(header, headers.getString(header));
                }
            }

            if (body == null) {
                List<NameValuePair> pairs = bundleToList(params);
                put.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));
            } else {
                put.setEntity(new StringEntity(body));
            }

            response = client.execute(put);
            break;
        default:
            throw new UnsupportedOperationException("Cannot execute HTTP method: " + method);
        }

        int statusCode = response.getStatusLine().getStatusCode();

        if (statusCode > 400) {
            throw new HttpResponseException(statusCode, read(response.getEntity().getContent()));
        }

        in = response.getEntity().getContent();
    } catch (ClientProtocolException e) {
        Log.e(Constants.LOG_TAG, "Client error: " + e.toString());
    } catch (IOException e) {
        Log.e(Constants.LOG_TAG, "IO error: " + e.toString());
    }

    return in;
}