Example usage for android.widget FrameLayout setKeepScreenOn

List of usage examples for android.widget FrameLayout setKeepScreenOn

Introduction

In this page you can find the example usage for android.widget FrameLayout setKeepScreenOn.

Prototype

public void setKeepScreenOn(boolean keepScreenOn) 

Source Link

Document

Controls whether the screen should remain on, modifying the value of #KEEP_SCREEN_ON .

Usage

From source file:com.razerzone.store.sdk.engine.gamemaker.Plugin.java

public static String init(final String secretApiKey) {

    if (sEnableLogging) {
        Log.d(TAG, "init: secretApiKey=" + secretApiKey);
    }/*from w ww .  j  a  va 2  s .  com*/

    final Activity activity = Plugin.getRelay().getCurrentActivity();
    if (null == activity) {
        Log.d(TAG, "Current activity is null");
        return sFalse;
    } else {
        Log.d(TAG, "Current activity is valid");
    }

    final FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
    if (null == content) {
        Log.d(TAG, "Content is null");
        return sFalse;
    } else {
        Runnable runnable = new Runnable() {
            public void run() {
                Log.d(TAG, "Disable screensaver");
                content.setKeepScreenOn(true);

                Log.d(TAG, "Add inputView");
                sInputView = new InputView(activity);

                Bundle developerInfo = null;
                try {
                    developerInfo = StoreFacade.createInitBundle(secretApiKey);
                } catch (InvalidParameterException e) {
                    Log.e(TAG, e.getMessage());
                    activity.finish();
                    return;
                }

                if (sEnableLogging) {
                    Log.d(TAG, "developer_id=" + developerInfo.getString(StoreFacade.DEVELOPER_ID));
                }

                if (sEnableLogging) {
                    Log.d(TAG, "developer_public_key length="
                            + developerInfo.getByteArray(StoreFacade.DEVELOPER_PUBLIC_KEY).length);
                }

                sInitCompleteListener = new CancelIgnoringResponseListener<Bundle>() {
                    @Override
                    public void onSuccess(Bundle bundle) {
                        if (sEnableLogging) {
                            Log.d(TAG, "InitCompleteListener: onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessInit");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                        sInitialized = true;
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.d(TAG, "InitCompleteListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureInit");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sStoreFacade = StoreFacade.getInstance();
                try {
                    sStoreFacade.init(activity, developerInfo, sInitCompleteListener);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                sRequestLoginListener = new ResponseListener<Void>() {
                    @Override
                    public void onSuccess(Void result) {
                        if (sEnableLogging) {
                            Log.d(TAG, "sRequestLoginListener: onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestLogin");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "sRequestLoginListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestLogin");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.d(TAG, "sRequestLoginListener: onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestLogin");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sRequestGamerInfoListener = new ResponseListener<GamerInfo>() {
                    @Override
                    public void onSuccess(GamerInfo info) {
                        if (null == info) {
                            Log.e(TAG, "GamerInfo is null!");
                            return;
                        }
                        if (sEnableLogging) {
                            Log.d(TAG, "sRequestGamerInfoListener: onSuccess uuid=" + info.getUuid()
                                    + " username=" + info.getUsername());
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestGamerInfo");
                            JSONObject data = new JSONObject();
                            data.put("uuid", info.getUuid());
                            data.put("username", info.getUsername());
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "sRequestGamerInfoListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestGamerInfo");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.d(TAG, "sRequestGamerInfoListener: onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestGamerInfo");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sRequestProductsListener = new ResponseListener<List<Product>>() {
                    @Override
                    public void onSuccess(final List<Product> products) {
                        if (null == products) {
                            Log.e(TAG, "Products are null!");
                            return;
                        }
                        if (sEnableLogging) {
                            Log.i(TAG, "sRequestProductsListener: onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestProducts");
                            JSONArray data = new JSONArray();
                            int index = 0;
                            for (Product product : products) {
                                JSONObject item = new JSONObject();
                                try {
                                    item.put("currencyCode", product.getCurrencyCode());
                                    item.put("description", product.getDescription());
                                    item.put("identifier", product.getIdentifier());
                                    item.put("localPrice", product.getLocalPrice());
                                    item.put("name", product.getName());
                                    item.put("originalPrice", product.getOriginalPrice());
                                    item.put("percentOff", product.getPercentOff());
                                    item.put("developerName", product.getDeveloperName());
                                    data.put(index, item);
                                    ++index;
                                } catch (JSONException e2) {
                                }
                            }
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "sRequestProductsListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestProducts");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.i(TAG, "sRequestProductsListener: onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestProducts");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sRequestPurchaseListener = new ResponseListener<PurchaseResult>() {

                    @Override
                    public void onSuccess(PurchaseResult result) {
                        if (null == result) {
                            Log.e(TAG, "PurchaseResult is null!");
                            return;
                        }
                        if (sEnableLogging) {
                            Log.i(TAG, "sRequestPurchaseListener: onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestPurchase");
                            JSONObject data = new JSONObject();
                            data.put("identifier", result.getProductIdentifier());
                            data.put("ownerId", result.getOrderId());
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "sRequestPurchaseListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestPurchase");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.i(TAG, "sRequestPurchaseListener: onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestPurchase");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sRequestReceiptsListener = new ResponseListener<Collection<Receipt>>() {

                    @Override
                    public void onSuccess(Collection<Receipt> receipts) {
                        if (null == receipts) {
                            Log.e(TAG, "Receipts are null!");
                            return;
                        }
                        if (sEnableLogging) {
                            Log.i(TAG, "requestReceipts onSuccess: received " + receipts.size() + " receipts");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestReceipts");
                            JSONArray data = new JSONArray();
                            int index = 0;
                            for (Receipt receipt : receipts) {
                                JSONObject item = new JSONObject();
                                try {
                                    item.put("identifier", receipt.getIdentifier());
                                    item.put("purchaseDate", receipt.getPurchaseDate());
                                    item.put("gamer", receipt.getGamer());
                                    item.put("uuid", receipt.getUuid());
                                    item.put("localPrice", receipt.getLocalPrice());
                                    item.put("currency", receipt.getCurrency());
                                    item.put("generatedDate", receipt.getGeneratedDate());
                                    data.put(index, item);
                                    ++index;
                                } catch (JSONException e2) {
                                }
                            }
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "requestReceipts onFailure: errorCode=" + errorCode + " errorMessage="
                                    + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestReceipts");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.i(TAG, "requestReceipts onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestReceipts");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sShutdownListener = new CancelIgnoringResponseListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        if (sEnableLogging) {
                            Log.i(TAG, "shutdown onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessShutdown");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int i, String s, Bundle bundle) {
                        if (sEnableLogging) {
                            Log.i(TAG, "shutdown onFailure");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureShutdown");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                Controller.init(activity);
            }
        };
        activity.runOnUiThread(runnable);
    }

    return sTrue;
}