当前位置: 首页>>代码示例>>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;未经允许,请勿转载。