Example usage for android.os Bundle putInt

List of usage examples for android.os Bundle putInt

Introduction

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

Prototype

public void putInt(@Nullable String key, int value) 

Source Link

Document

Inserts an int value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:org.planetmono.dcuploader.SignOnGallog.java

public Runnable getMethodSignOn(final Application app, final Bundle b, final Handler resultHandler) {
    return new Runnable() {
        public void run() {
            String id, password;/*from ww w  . ja  v  a 2s .c  om*/

            id = b.getString("id");
            password = b.getString("password");

            Message m = resultHandler.obtainMessage();
            Bundle bm = m.getData();

            Log.d(Application.TAG, "logging in...");

            HttpPost post = new HttpPost(SIGNON_URL);
            List<NameValuePair> vlist = new ArrayList<NameValuePair>();
            vlist.add(new BasicNameValuePair("user_id", id));
            vlist.add(new BasicNameValuePair("password", password));
            vlist.add(new BasicNameValuePair("x", "0"));
            vlist.add(new BasicNameValuePair("y", "0"));
            vlist.add(new BasicNameValuePair("s_url", "about:blank"));
            try {
                post.setEntity(new UrlEncodedFormEntity(vlist));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            post.setHeader("Origin", SIGNON_BASE_URL);
            post.setHeader("Referer", SIGNON_PAGE_URL);

            HttpResponse response = null;
            try {
                response = app.sendPostRequest(post);
            } catch (Exception e) {
                e.printStackTrace();

                bm.putBoolean("result", false);
                bm.putString("resultString", " ");
                resultHandler.sendMessage(m);
                return;
            }

            HttpEntity entity = response.getEntity();
            BufferedReader r;
            try {
                r = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));

                while (true) {
                    String line = r.readLine();
                    if (line == null)
                        break;

                    if (line.contains(" ")
                            || line.contains("?? ? ")) {
                        bm.putBoolean("result", false);
                        bm.putString("resultString", "? ");
                        resultHandler.sendMessage(m);
                        entity.consumeContent();
                        return;
                    } else if (line.contains("about:blank")) {
                        /* successful */
                        bm.putBoolean("result", true);
                        bm.putInt("method", getMethodId());
                        resultHandler.sendMessage(m);
                        entity.consumeContent();
                        return;
                    }
                }
            } catch (Exception e) {
                bm.putBoolean("result", false);
                bm.putString("resultString", " ");
                resultHandler.sendMessage(m);

                try {
                    entity.consumeContent();
                } catch (IOException e1) {
                }

                return;
            }

            try {
                entity.consumeContent();
            } catch (IOException e) {
            }

            /* abnormal status. */
            bm.putBoolean("result", false);
            bm.putString("resultString", "   .");
            resultHandler.sendMessage(m);
        }
    };
}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

public void JSgoBack() {
    // TODO Auto-generated method stub
    DebugLog.d(TAG, "JSgoBack() mWebView.getUrl() = " + mWebView.getUrl());
    if (mWebView.getUrl() != null) {
        if (GameInfo.isErrorUrl(mWebView.getUrl())) {
            Bundle bundle = new Bundle();
            bundle.putInt("msgtype", Constants.HANDLER_UI_NOTIFY_EXIT_APP_SERVEER);
            bundle.putString("msgcontent", "Notify Exit Application");

            Intent intent = new Intent(Constants.RECEIVER_BROADCAST);
            intent.putExtras(bundle);//from w w w .  j a v  a  2  s.c o  m

            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else {
            DebugLog.d(TAG, "JSgoBack() javascript:history.back()");
            mWebView.loadUrl("javascript:history.back();");
        }
    }
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void openTweetSearch(final Activity activity, final long account_id, final String query,
        final int search_id) {
    if (activity == null)
        return;// w  w  w.  j a v  a2 s  .  c om
    if (activity instanceof DualPaneActivity && ((DualPaneActivity) activity).isDualPaneMode()) {
        final DualPaneActivity dual_pane_activity = (DualPaneActivity) activity;
        final Fragment fragment = new SearchTweetsFragment();
        final Bundle args = new Bundle();
        args.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
        if (query != null) {
            args.putString(INTENT_KEY_QUERY, query);
        }
        if (search_id > 0) {
            args.putInt(INTENT_KEY_ID, search_id);
        }
        fragment.setArguments(args);
        dual_pane_activity.showAtPane(DualPaneActivity.PANE_LEFT, fragment, true);
    } else {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWEETINGS);
        builder.authority(AUTHORITY_SEARCH);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
        builder.appendQueryParameter(QUERY_PARAM_TYPE, QUERY_PARAM_VALUE_TWEETS);
        if (query != null) {
            builder.appendQueryParameter(QUERY_PARAM_QUERY, query);
        }
        if (search_id > 0) {
            builder.appendQueryParameter(QUERY_PARAM_ID, String.valueOf(search_id));
        }
        activity.startActivity(new Intent(Intent.ACTION_VIEW, builder.build()));
    }
}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

private void exitApp(String jsonData) {
    String result = null;/*from  ww w  . j a v a2 s. co  m*/
    try {
        JSONObject json = new JSONObject(jsonData);
        String id = json.optString("id");
        String type = json.optString("type");

        Bundle bundle = new Bundle();
        bundle.putInt("msgtype", Constants.HANDLER_UI_NOTIFY_EXIT_APP_SERVEER);
        bundle.putString("msgcontent", "Notify Exit Application");

        Intent intent = new Intent(Constants.RECEIVER_BROADCAST);
        intent.putExtras(bundle);

        if (mContext != null)
            mContext.sendBroadcast(intent);
        else
            DebugLog.d(TAG, "mContext == null");

        result = "{" + "\"id\": \"" + id + "\"," + "\"type\": \"result\"," + "\"code\": \"200\","
                + "\"message\": \"success(200)\"" + "}";
    } catch (Exception e) {
        // TODO Auto-generated catch block
        DebugLog.d(TAG, "exception = " + e.getMessage());
        result = "{" + "\"code\": \"" + Constants.RESPONSE_500
                + "\",\"message\": \" player internal error(500) \"}";
    }

    this.ubiGCPlayerCallback("exitApp", result);
}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

private void handleProhibitCheckAvailableNetwork(String jsonData) {
    JSONObject json;/*from   www .j  av a2s.com*/
    try {
        json = new JSONObject(jsonData);
        mPlayId = json.optString("id");
        DebugLog.d(TAG, "handleProhibitCheckAvailableNetwork() enter");

        String result = "{\"code\": \"" + Constants.RESPONSE_500
                + "\",\"message\": \"Only allow to play game under LTE or WIFI.\"}";
        ubiGCPlayerCallback("checkAvailableNetwork", result);

        notifyClosePlayerWebJS();
        callJsUpdateStatus(Constants.RESPONSE_302);

        WebBrowser.sGameExitStatus = Constants.GAMEACTIVITY_ALERT_DIALOG_TYPE_NOT_LTEWIFI;
        DebugLog.d(TAG, "====prohibit play in 3G network=====");
        Utils.ShowOKPrompt(mContext, GameActivityRes.STRING_WARNING, GameActivityRes.STRING_NETWORKTYPE_WRN_3G,
                GameActivityRes.STRING_NETWORKTYPE_CLOSEAPK, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        LoadWebJsActivity.sGameingExitAndExitApp = true;
                        Bundle bundle = new Bundle();
                        bundle.putInt("msgtype", NotifyManagement.LOCAL_GAMEACTIVITY_RESULT);
                        Intent intent = new Intent(Constants.RECEIVER_BROADCAST);
                        intent.putExtras(bundle);
                        WebBrowser.this.mContext.sendBroadcast(intent);
                        dialog.dismiss();
                    }
                });
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        DebugLog.d(TAG, "excepion = " + e.getMessage());
    }

}

From source file:com.gimranov.zandy.app.data.Item.java

/**
 * Makes ArrayList<Bundle> from the present item's creators. Primarily for
 * use with CreatorActivity, but who knows?
 *///from   w  ww . j  a va  2  s  . c o m
public ArrayList<Bundle> creatorsToBundleArray() {
    JSONObject itemContent = this.content;
    /*
     * Here we walk through the data and make Bundles to send to the
     * ArrayAdapter. There should be no real risk of JSON exceptions, since
     * the JSON was checked when initialized in the Item object.
     * 
     * Each Bundle has six keys: "itemKey", "name", "firstName", "lastName",
     * "creatorType", "position"
     * 
     * Field mode is encoded implicitly -- if either of "firstName" and
     * "lastName" is non-empty ("") or non-null, we treat this as a
     * two-field name. key The field "name" is the one-field name if the
     * others are empty, otherwise it's a display version of the two-field
     * name.
     */

    ArrayList<Bundle> rows = new ArrayList<Bundle>();

    Bundle b = new Bundle();

    if (!itemContent.has("creators")) {
        return rows;
    }

    try {
        JSONArray creators = itemContent.getJSONArray("creators");
        Log.d(TAG, creators.toString());
        for (int i = 0; i < creators.length(); i++) {
            b = new Bundle();
            Log.d(TAG, creators.getJSONObject(i).toString());
            b.putString("creatorType", creators.getJSONObject(i).getString("creatorType"));
            b.putString("firstName", creators.getJSONObject(i).optString("firstName"));
            b.putString("lastName", creators.getJSONObject(i).optString("lastName"));
            b.putString("name", creators.getJSONObject(i).optString("name"));
            // If name is empty, fill with the others
            if (b.getString("name").equals(""))
                b.putString("name", b.getString("firstName") + " " + b.getString("lastName"));
            b.putString("itemKey", this.key);
            b.putInt("position", i);
            rows.add(b);
        }
    } catch (JSONException e) {
        Log.e(TAG, "JSON exception caught in creator bundler: ", e);
    }

    return rows;
}

From source file:cgeo.geocaching.CacheDetailActivity.java

@Override
public void onSaveInstanceState(final Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(STATE_PAGE_INDEX, getCurrentItem());
}

From source file:com.shurik.droidzebra.ZebraEngine.java

private JSONObject Callback(int msgcode, JSONObject data) {
    JSONObject retval = null;//w ww  . ja  v a2s  . c o m
    Message msg = mHandler.obtainMessage(msgcode);
    Bundle b = new Bundle();
    msg.setData(b);
    // Log.d("ZebraEngine", String.format("Callback(%d,%s)", msgcode, data.toString()));
    if (bInCallback)
        fatalError("Recursive vallback call");
    try {
        bInCallback = true;
        switch (msgcode) {
        case MSG_ERROR: {
            b.putString("error", data.getString("error"));
            if (getEngineState() == ES_INITIAL) {
                // delete .bin files if initialization failed
                // will be recreated from resources
                new File(mFilesDir, PATTERNS_FILE).delete();
                new File(mFilesDir, BOOK_FILE).delete();
                new File(mFilesDir, BOOK_FILE_COMPRESSED).delete();
            }
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_DEBUG: {
            b.putString("message", data.getString("message"));
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_BOARD: {
            int len;
            JSONObject info;
            JSONArray zeArray;
            byte[] moves;

            JSONArray zeboard = data.getJSONArray("board");
            byte newBoard[] = new byte[BOARD_SIZE * BOARD_SIZE];
            for (int i = 0; i < zeboard.length(); i++) {
                JSONArray row = zeboard.getJSONArray(i);
                for (int j = 0; j < row.length(); j++) {
                    newBoard[i * BOARD_SIZE + j] = (byte) row.getInt(j);
                }
            }
            b.putByteArray("board", newBoard);
            b.putInt("side_to_move", data.getInt("side_to_move"));
            mCurrentGameState.mDisksPlayed = data.getInt("disks_played");

            // black info
            {
                Bundle black = new Bundle();
                info = data.getJSONObject("black");
                black.putString("time", info.getString("time"));
                black.putFloat("eval", (float) info.getDouble("eval"));
                black.putInt("disc_count", info.getInt("disc_count"));
                black.putString("time", info.getString("time"));

                zeArray = info.getJSONArray("moves");
                len = zeArray.length();
                moves = new byte[len];
                assert (2 * len <= mCurrentGameState.mMoveSequence.length);
                for (int i = 0; i < len; i++) {
                    moves[i] = (byte) zeArray.getInt(i);
                    mCurrentGameState.mMoveSequence[2 * i] = moves[i];
                }
                black.putByteArray("moves", moves);
                b.putBundle("black", black);
            }

            // white info
            {
                Bundle white = new Bundle();
                info = data.getJSONObject("white");
                white.putString("time", info.getString("time"));
                white.putFloat("eval", (float) info.getDouble("eval"));
                white.putInt("disc_count", info.getInt("disc_count"));
                white.putString("time", info.getString("time"));

                zeArray = info.getJSONArray("moves");
                len = zeArray.length();
                moves = new byte[len];
                assert ((2 * len + 1) <= mCurrentGameState.mMoveSequence.length);
                for (int i = 0; i < len; i++) {
                    moves[i] = (byte) zeArray.getInt(i);
                    mCurrentGameState.mMoveSequence[2 * i + 1] = moves[i];
                }
                white.putByteArray("moves", moves);
                b.putBundle("white", white);
            }

            mHandler.sendMessage(msg);
        }
            break;

        case MSG_CANDIDATE_MOVES: {
            JSONArray jscmoves = data.getJSONArray("moves");
            CandidateMove cmoves[] = new CandidateMove[jscmoves.length()];
            mValidMoves = new int[jscmoves.length()];
            for (int i = 0; i < jscmoves.length(); i++) {
                JSONObject jscmove = jscmoves.getJSONObject(i);
                mValidMoves[i] = jscmoves.getJSONObject(i).getInt("move");
                cmoves[i] = new CandidateMove(new Move(jscmove.getInt("move")));
            }
            msg.obj = cmoves;
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_GET_USER_INPUT: {
            mMovesWithoutInput = 0;

            setEngineState(ES_USER_INPUT_WAIT);

            waitForEngineState(ES_PLAY);

            while (mPendingEvent == null) {
                setEngineState(ES_USER_INPUT_WAIT);
                waitForEngineState(ES_PLAY);
            }

            retval = mPendingEvent;

            setEngineState(ES_PLAYINPROGRESS);

            mValidMoves = null;
            mPendingEvent = null;
        }
            break;

        case MSG_PASS: {
            setEngineState(ES_USER_INPUT_WAIT);
            mHandler.sendMessage(msg);
            waitForEngineState(ES_PLAY);
            setEngineState(ES_PLAYINPROGRESS);
        }
            break;

        case MSG_OPENING_NAME: {
            b.putString("opening", data.getString("opening"));
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_LAST_MOVE: {
            b.putInt("move", data.getInt("move"));
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_GAME_START: {
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_GAME_OVER: {
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_MOVE_START: {
            mMoveStartTime = android.os.SystemClock.uptimeMillis();

            mSideToMove = data.getInt("side_to_move");

            // can change player info here
            if (mPlayerInfoChanged) {
                zeSetPlayerInfo(PLAYER_BLACK, mPlayerInfo[PLAYER_BLACK].skill,
                        mPlayerInfo[PLAYER_BLACK].exactSolvingSkill, mPlayerInfo[PLAYER_BLACK].wldSolvingSkill,
                        mPlayerInfo[PLAYER_BLACK].playerTime, mPlayerInfo[PLAYER_BLACK].playerTimeIncrement);
                zeSetPlayerInfo(PLAYER_WHITE, mPlayerInfo[PLAYER_WHITE].skill,
                        mPlayerInfo[PLAYER_WHITE].exactSolvingSkill, mPlayerInfo[PLAYER_WHITE].wldSolvingSkill,
                        mPlayerInfo[PLAYER_WHITE].playerTime, mPlayerInfo[PLAYER_WHITE].playerTimeIncrement);
                zeSetPlayerInfo(PLAYER_ZEBRA, mPlayerInfo[PLAYER_ZEBRA].skill,
                        mPlayerInfo[PLAYER_ZEBRA].exactSolvingSkill, mPlayerInfo[PLAYER_ZEBRA].wldSolvingSkill,
                        mPlayerInfo[PLAYER_ZEBRA].playerTime, mPlayerInfo[PLAYER_ZEBRA].playerTimeIncrement);
            }
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_MOVE_END: {
            // introduce delay between moves made by the computer without user input
            // so we can actually to see that the game is being played :)
            if (mMoveDelay > 0 || (mMovesWithoutInput > 1 && mPlayerInfo[mSideToMove].skill > 0)) {
                long moveEnd = android.os.SystemClock.uptimeMillis();
                int delay = mMoveDelay > 0 ? mMoveDelay : SELFPLAY_MOVE_DELAY;
                if ((moveEnd - mMoveStartTime) < delay) {
                    android.os.SystemClock.sleep(delay - (moveEnd - mMoveStartTime));
                }
            }

            // this counter is reset by user input
            mMovesWithoutInput += 1;

            mHandler.sendMessage(msg);
        }
            break;

        case MSG_EVAL_TEXT: {
            b.putString("eval", data.getString("eval"));
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_PV: {
            JSONArray zeArray = data.getJSONArray("pv");
            int len = zeArray.length();
            byte[] moves = new byte[len];
            for (int i = 0; i < len; i++)
                moves[i] = (byte) zeArray.getInt(i);
            b.putByteArray("pv", moves);
            mHandler.sendMessage(msg);
        }
            break;

        case MSG_CANDIDATE_EVALS: {
            JSONArray jscevals = data.getJSONArray("evals");
            CandidateMove cmoves[] = new CandidateMove[jscevals.length()];
            for (int i = 0; i < jscevals.length(); i++) {
                JSONObject jsceval = jscevals.getJSONObject(i);
                cmoves[i] = new CandidateMove(new Move(jsceval.getInt("move")), jsceval.getString("eval_s"),
                        jsceval.getString("eval_l"), (jsceval.getInt("best") != 0));
            }
            msg.obj = cmoves;
            mHandler.sendMessage(msg);

        }
            break;

        default: {
            b.putString("error", String.format("Unkown message ID %d", msgcode));
            msg.setData(b);
            mHandler.sendMessage(msg);
        }
            break;
        }
    } catch (JSONException e) {
        msg.what = MSG_ERROR;
        b.putString("error", "JSONException:" + e.getMessage());
        msg.setData(b);
        mHandler.sendMessage(msg);
    } finally {
        bInCallback = false;
    }
    return retval;
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

public static void showAlertLicense(String title, String message, Handler handler) {
    Message msg1 = handler.obtainMessage();
    Bundle b = new Bundle();
    b.putInt("message_type", Const.UIUTILS_SHOWALERT_LICENSE);
    b.putString("title", title);
    b.putString("body", message);
    msg1.setData(b);/*from w  w  w  .ja  va 2 s . c o  m*/
    handler.sendMessage(msg1);
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

public static void showAlertHtml(String title, String message, Handler handler) {
    Message msg1 = handler.obtainMessage();
    Bundle b = new Bundle();
    b.putInt("message_type", Const.UIUTILS_SHOWALERT_HTML);
    b.putString("title", title);
    b.putString("body", message);
    msg1.setData(b);/*  ww w .  j  av  a  2s. c  om*/
    handler.sendMessage(msg1);
}