當前位置: 首頁>>代碼示例>>Java>>正文


Java GameRequest類代碼示例

本文整理匯總了Java中com.google.android.gms.games.request.GameRequest的典型用法代碼示例。如果您正苦於以下問題:Java GameRequest類的具體用法?Java GameRequest怎麽用?Java GameRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GameRequest類屬於com.google.android.gms.games.request包,在下文中一共展示了GameRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onRequestReceived

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
@Override
public void onRequestReceived(GameRequest request) {
    int requestStringResource;
    switch (request.getType()) {
        case GameRequest.TYPE_GIFT:
            requestStringResource = R.string.new_gift_received;
            break;
        case GameRequest.TYPE_WISH:
            requestStringResource = R.string.new_request_received;
            break;
        default:
            return;
    }
    Toast.makeText(BeGenerousActivity.this, requestStringResource,
            Toast.LENGTH_LONG).show();
    updateRequestCounts();
}
 
開發者ID:NahroTo,項目名稱:Fruit-Destroyer,代碼行數:18,代碼來源:BeGenerousActivity.java

示例2: onConnected

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
@Override
public void onConnected(Bundle connectionHint) {
    Log.d(TAG, "onConnected() called. Sign in successful!");
    showSignOutBar();
    checkPlayerStats();

    // This is *NOT* required; if you do not register a handler for
    // request events, you will get standard notifications instead.
    Games.Requests.registerRequestListener(mGoogleApiClient, mRequestListener);

    if (connectionHint != null) {
        ArrayList<GameRequest> requests;
        // Do we have any requests pending? (getGameRequestsFromBundle never returns null
        requests = Games.Requests.getGameRequestsFromBundle(connectionHint);
        if (!requests.isEmpty()) {
            // We have requests in onConnected's connectionHint.
            Log.d(TAG, "onConnected: connection hint has " + requests.size() + " request(s)");
        }
        Log.d(TAG, "===========\nRequests count " + requests.size());
        // Use regular handler
        handleRequests(requests);
    }

    // Our sample displays the request counts.
    updateRequestCounts();
}
 
開發者ID:NahroTo,項目名稱:Fruit-Destroyer,代碼行數:27,代碼來源:BeGenerousActivity.java

示例3: getRequestsString

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
private String getRequestsString(ArrayList<GameRequest> requests) {
    if (requests.size() == 0) {
        return "You have no requests to accept.";
    }

    if (requests.size() == 1) {
        return "Do you want to accept this request from "
                + requests.get(0).getSender().getDisplayName() + "?";
    }

    StringBuffer retVal = new StringBuffer(
            "Do you want to accept the following requests?\n\n");

    for (GameRequest request : requests) {
        retVal.append("  A "
                + (request.getType() == GameRequest.TYPE_GIFT ? "gift"
                        : "game request") + " from "
                + request.getSender().getDisplayName() + "\n");
    }

    return retVal.toString();
}
 
開發者ID:NahroTo,項目名稱:Fruit-Destroyer,代碼行數:23,代碼來源:BeGenerousActivity.java

示例4: sendGift

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
protected void sendGift() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.prompt_choose_gift)).setItems(R.array.gifts, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent;
            // The 'which' argument contains the index position
            // of the selected item
            switch (which) {
                // Powerup
                case 0:
                    intent = Games.Requests.getSendIntent(getApiClient(), GameRequest.TYPE_GIFT,
                            "p".getBytes(), Requests.REQUEST_DEFAULT_LIFETIME_DAYS, BitmapFactory.decodeResource(getResources(),
                                    R.drawable.powerup_button), getString(R.string.powerup));
                    startActivityForResult(intent, SEND_GIFT_CODE);
                    break;
                case 1:
                    intent = Games.Requests.getSendIntent(getApiClient(), GameRequest.TYPE_GIFT,
                            "u".getBytes(), Requests.REQUEST_DEFAULT_LIFETIME_DAYS, BitmapFactory.decodeResource(getResources(),
                                    R.drawable.undo_button), getString(R.string.undo));
                    startActivityForResult(intent, SEND_GIFT_CODE);
                    break;
            }
        }
    });
    builder.create().show();
}
 
開發者ID:TylerCarberry,項目名稱:2048-Battles,代碼行數:27,代碼來源:MainActivity.java

示例5: handleInboxResult

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
private void handleInboxResult(ArrayList<GameRequest> gameRequests) {
    for(GameRequest request : gameRequests) {

        if(getApiClient().isConnected())
            Games.Requests.acceptRequest(getApiClient(), request.getRequestId());
        else
            break;

        String senderName = request.getSender().getDisplayName();
        String message;

        if(new String(request.getData()).equals("p")) {
            message = String.format(getString(R.string.powerup_gift_received), senderName);
            incrementPowerupInventory(1);
        }
        else {

            message = String.format(getString(R.string.undo_gift_received), senderName);
            incrementUndoInventory(1);
        }
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
}
 
開發者ID:TylerCarberry,項目名稱:2048-Battles,代碼行數:24,代碼來源:MainActivity.java

示例6: getRequests

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
/**
 * Returns the requests received through the onConnected bundle. This should
 * be called from your GameHelperListener's
 *
 * @return The requests, or null if none were received.
 * @link{GameHelperListener#onSignInSucceeded method, to check if there are
 * incoming requests that must be
 * handled.
 */
public ArrayList<GameRequest> getRequests()
{
    if (!this.mGoogleApiClient.isConnected())
    {
        Log.w(TAG, "Warning: getRequests() should only be called "
            + "when signed in, "
            + "that is, after getting onSignInSuceeded()");
    }
    return this.mRequests;
}
 
開發者ID:overengineering,項目名稱:space-travels-3,代碼行數:20,代碼來源:GameHelper.java

示例7: countNotExpired

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
private int countNotExpired(GameRequestBuffer buf) {
    if (buf == null) {
        return 0;
    }

    int giftCount = 0;
    for (GameRequest gr : buf) {
        if (gr.getExpirationTimestamp() > System.currentTimeMillis()) {
            giftCount++;
        }
    }
    return giftCount;
}
 
開發者ID:NahroTo,項目名稱:Fruit-Destroyer,代碼行數:14,代碼來源:BeGenerousActivity.java

示例8: onResult

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
@Override
public void onResult(LoadRequestsResult result) {
    int giftCount = countNotExpired(result.getRequests(GameRequest.TYPE_GIFT));
    int wishCount = countNotExpired(result.getRequests(GameRequest.TYPE_WISH));

    ((TextView) findViewById(R.id.tv_gift_count)).setText(String
            .format(getString(R.string.gift_count), giftCount));
    ((TextView) findViewById(R.id.tv_request_count)).setText(String
            .format(getString(R.string.request_count), wishCount));
}
 
開發者ID:NahroTo,項目名稱:Fruit-Destroyer,代碼行數:11,代碼來源:BeGenerousActivity.java

示例9: updateRequestCounts

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
private void updateRequestCounts() {
    PendingResult<Requests.LoadRequestsResult> result = Games.Requests
            .loadRequests(mGoogleApiClient,
                    Requests.REQUEST_DIRECTION_INBOUND,
                    GameRequest.TYPE_ALL,
                    Requests.SORT_ORDER_EXPIRING_SOON_FIRST);
    result.setResultCallback(mLoadRequestsCallback);
}
 
開發者ID:NahroTo,項目名稱:Fruit-Destroyer,代碼行數:9,代碼來源:BeGenerousActivity.java

示例10: showSendIntent

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
/**
 * Show a send gift or send wish request using startActivityForResult.
 *
 * @param type
 *            the type of GameRequest (gift or wish) to show
 */
private void showSendIntent(int type) {
    // Make sure we have a valid API client.
    if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {

        String description;
        int intentCode;
        Bitmap icon;
        switch (type) {
        case GameRequest.TYPE_GIFT:
            description = getString(R.string.send_gift_description);
            intentCode = SEND_GIFT_CODE;
            icon = mGiftIcon;
            break;
        case GameRequest.TYPE_WISH:
            description = getString(R.string.send_request_description);
            intentCode = SEND_REQUEST_CODE;
            icon = mGiftIcon;
            break;
        default:
            return;
        }
        Intent intent = Games.Requests.getSendIntent(mGoogleApiClient, type,
                "".getBytes(), DEFAULT_LIFETIME, icon, description);
        startActivityForResult(intent, intentCode);
    }
}
 
開發者ID:NahroTo,項目名稱:Fruit-Destroyer,代碼行數:33,代碼來源:BeGenerousActivity.java

示例11: onSignInSucceeded

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
@Override
public void onSignInSucceeded() {
    setViewVisibility();

    ArrayList<GameRequest> requests = getGameHelper().getRequests();
    if (requests != null) {
        handleGiftRequest(requests);
    }

}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:11,代碼來源:SquashActivity.java

示例12: onClick

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.button_sign_in:
            // Check to see the developer who's running this sample code read the instructions :-)
            // NOTE: this check is here only because this is a sample! Don't include this
            // check in your actual production app.
            if (!BaseGameUtils.verifySampleSetup(this, R.string.app_id)) {
                Log.w(TAG, "*** Warning: setup problems detected. Sign in may not work!");
            }

            // start the sign-in flow
            Log.d(TAG, "Sign-in button clicked");
            mSignInClicked = true;
            mGoogleApiClient.connect();
            break;
        case R.id.button_sign_out:
            // sign out.
            Log.d(TAG, "Sign-out button clicked");
            mSignInClicked = false;
            Games.signOut(mGoogleApiClient);
            mGoogleApiClient.disconnect();
            showSignInBar();
            break;
        case R.id.button_send_gift:
            // send gift!
            showSendIntent(GameRequest.TYPE_GIFT);
            break;
        case R.id.button_send_request:
            // request gift!
            showSendIntent(GameRequest.TYPE_WISH);
            break;
        case R.id.button_open_inbox:
            // show inbox!
            if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
                startActivityForResult(
                        Games.Requests.getInboxIntent(mGoogleApiClient),
                        SHOW_INBOX);
            }
            break;
    }
}
 
開發者ID:NahroTo,項目名稱:Fruit-Destroyer,代碼行數:43,代碼來源:BeGenerousActivity.java

示例13: checkPendingPlayGifts

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
protected void checkPendingPlayGifts() {
    PendingResult<Requests.LoadRequestsResult> pendingGifts = Games.Requests.loadRequests(getApiClient(), Requests.REQUEST_DIRECTION_INBOUND,
            GameRequest.TYPE_GIFT, Requests.SORT_ORDER_EXPIRING_SOON_FIRST);
    pendingGifts.setResultCallback(new ResultCallback<Requests.LoadRequestsResult>() {
        @Override
        public void onResult(Requests.LoadRequestsResult loadRequestsResult) {
            final ImageButton inboxButton = (ImageButton) findViewById(R.id.inbox_button);

            if (loadRequestsResult.getRequests(GameRequest.TYPE_GIFT).getCount() > 0) {
                if(inboxButton.getVisibility() == View.VISIBLE)
                    return;

                inboxButton.setVisibility(View.VISIBLE);

                inboxButton.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View view, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_DOWN) {
                            inboxButton.setImageResource(R.drawable.inbox_button_pressed);
                        }
                        else if (event.getAction() == MotionEvent.ACTION_UP) {
                            inboxButton.setImageResource(R.drawable.inbox_button);

                            if(event.getX() > 0 && event.getX() < view.getWidth() &&
                                    event.getY() > 0 && event.getY() < view.getHeight())
                                onClick(view);
                        }
                        return true;
                    }
                });

                ObjectAnimator scaleX = ObjectAnimator.ofFloat(inboxButton, View.SCALE_X, 0.90f);
                ObjectAnimator scaleY = ObjectAnimator.ofFloat(inboxButton, View.SCALE_Y, 0.90f);

                scaleX.setDuration(1000);
                scaleY.setDuration(1000);
                scaleX.setRepeatCount(ObjectAnimator.INFINITE);
                scaleX.setRepeatMode(ObjectAnimator.REVERSE);
                scaleY.setRepeatCount(ObjectAnimator.INFINITE);
                scaleY.setRepeatMode(ObjectAnimator.REVERSE);

                AnimatorSet scaleDown = new AnimatorSet();
                scaleDown.play(scaleX).with(scaleY);
                scaleDown.start();
            }
            else
                inboxButton.setVisibility(View.GONE);
        }
    });
}
 
開發者ID:TylerCarberry,項目名稱:2048-Battles,代碼行數:51,代碼來源:MainActivity.java

示例14: onOptionsItemSelected

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_leaderboard:
        startActivityForResult(
                Games.Leaderboards.getLeaderboardIntent( getApiClient(),
                        getResources().getString(
                                R.string.leaderboard_bounces)),
                REQUEST_LEADERBOARD);
        return true;
    case R.id.menu_reset:
        return true;
    case R.id.menu_achievements:
        if (isSignedIn()) {
            startActivityForResult(
                    Games.Achievements.getAchievementsIntent( getApiClient() ),
                    REQUEST_ACHIEVEMENTS);
        }
        return true;

    case R.id.menu_send_gift:
        if (isSignedIn()) {
            Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
            Intent intent = Games.Requests.getSendIntent(getApiClient(), GameRequest.TYPE_GIFT,
                    "Gold".getBytes(), Requests.REQUEST_DEFAULT_LIFETIME_DAYS, bm, "A treasure chest!");

            startActivityForResult(intent, SEND_GIFT);


        }
        return true;

    case R.id.menu_gift_inbox:
        if (isSignedIn()) {
            startActivityForResult(Games.Requests.getInboxIntent(getApiClient()), SHOW_INBOX);
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:42,代碼來源:SquashActivity.java

示例15: getRequests

import com.google.android.gms.games.request.GameRequest; //導入依賴的package包/類
/**
 * Returns the requests received through the onConnected bundle. This should
 * be called from your GameHelperListener's
 *
 * @link{GameHelperListener#onSignInSucceeded method, to check if there are
 *                                            incoming requests that must be
 *                                            handled.
 * @return The requests, or null if none were received.
 */
public ArrayList<GameRequest> getRequests() {
    if (!mGoogleApiClient.isConnected()) {
        Log.w(TAG, "Warning: getRequests() should only be called "
                + "when signed in, "
                + "that is, after getting onSignInSucceeded()");
    }
    return mRequests;
}
 
開發者ID:AndreFCruz,項目名稱:feup-lpoo-armadillo,代碼行數:18,代碼來源:GameHelper.java


注:本文中的com.google.android.gms.games.request.GameRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。