List of usage examples for android.app Activity findViewById
@Nullable public <T extends View> T findViewById(@IdRes int id)
From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java
/** * Add the currency buttons dynamically from the money_defs.xml file */// w w w .jav a 2 s . co m private void addButtons() { ArrayList<CurrencyValueDef> currencies; LinearLayout buttons; Activity parent; parent = getActivity(); buttons = (LinearLayout) parent.findViewById(R.id.moneyButtonsLayout); currencies = CurrencyManager.getCurrencyDefList(); View.OnClickListener listener; listener = new View.OnClickListener() { public void onClick(View v) { onMoneyClicked(v); } }; for (CurrencyValueDef c : currencies) { ImageView v; v = new ImageView(parent); v.setOnClickListener(listener); v.setImageDrawable(c.getDrawable()); v.setLongClickable(true); v.setTag(c); buttons.addView(v); } }
From source file:ru.valle.btc.MainActivityTest.java
private String getText(final Activity activity, final int id) { FutureTask<String> task = new FutureTask<>(new Callable<String>() { @Override/*ww w .ja v a 2 s . c om*/ public String call() throws Exception { TextView textView = ((TextView) activity.findViewById(id)); return textView.getVisibility() == View.VISIBLE ? getString(textView) : null; } }); activity.runOnUiThread(task); try { return task.get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } return null; }
From source file:com.emobc.android.activities.generators.FormActivityGenerator.java
@Override protected void loadAppLevelData(final Activity activity, final AppLevelData data) { this.item = (FormLevelDataItem) data.findByNextLevel(nextLevel); //rotateScreen(activity); initializeHeader(activity, item);/*from www.j av a2 s .co m*/ controlsMap = new HashMap<String, View>(); //Create Banner CreateMenus c = (CreateMenus) activity; c.createBanner(); LinearLayout formLayout = (LinearLayout) activity.findViewById(R.id.formLayout); for (FormDataItem dataItem : item.getList()) { TextView label = new TextView(activity); label.setText(dataItem.getFieldLabel()); formLayout.addView(label); insertField(activity, dataItem, formLayout); } Button submit = new Button(activity); submit.setText(R.string.form_submit_buttom); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { processSubmit(activity); } }); formLayout.addView(submit); ((FormActivity) activity).setControlsMap(controlsMap); }
From source file:dynamite.zafroshops.app.fragment.ZopItemFragment.java
private void setZop(Activity activity) { if (zop != null && zop.Location != null && MainActivity.LastLocation != null) { float[] results = new float[1]; Location.distanceBetween(MainActivity.LastLocation.Latitude, MainActivity.LastLocation.Longitude, zop.Location.Latitude, zop.Location.Longitude, results); zop.Distance = results[0] / 1000; }/*from ww w. j a v a 2 s . co m*/ LinearLayout itemZop = (LinearLayout) activity.findViewById(R.id.itemZop); RelativeLayout loader = (RelativeLayout) activity.findViewById(R.id.relativeLayoutLoader); ArrayList<MobileOpeningHourData> ohs = zop.getGroupedOpeningHours(); if (ohs != null) { setLayout(activity.getLayoutInflater(), itemZop, zop, loader); } }
From source file:com.apptentive.android.sdk.module.engagement.interaction.view.survey.SurveyInteractionView.java
@Override public void doOnCreate(final Activity activity, Bundle savedInstanceState) { if (savedInstanceState != null) { surveySubmitted = savedInstanceState.getBoolean(KEY_SURVEY_SUBMITTED, false); }// www .j a v a2 s . co m if (interaction == null || surveySubmitted) { activity.finish(); return; } activity.setContentView(R.layout.apptentive_survey); // Hide branding if needed. final View branding = activity.findViewById(R.id.apptentive_branding_view); if (branding != null) { if (Configuration.load(activity).isHideBranding(activity)) { branding.setVisibility(View.GONE); } } TextView title = (TextView) activity.findViewById(R.id.title); title.setFocusable(true); title.setFocusableInTouchMode(true); title.setText(interaction.getName()); String descriptionText = interaction.getDescription(); if (descriptionText != null) { TextView description = (TextView) activity.findViewById(R.id.description); description.setText(descriptionText); description.setVisibility(View.VISIBLE); } final Button send = (Button) activity.findViewById(R.id.send); send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Util.hideSoftKeyboard(activity, view); surveySubmitted = true; if (interaction.isShowSuccessMessage() && interaction.getSuccessMessage() != null) { SurveyThankYouDialog dialog = new SurveyThankYouDialog(activity); dialog.setMessage(interaction.getSuccessMessage()); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { activity.finish(); } }); dialog.show(); } else { activity.finish(); } EngagementModule.engageInternal(activity, interaction, EVENT_SUBMIT, data.toString()); ApptentiveDatabase.getInstance(activity).addPayload(new SurveyResponse(interaction, surveyState)); Log.d("Survey Submitted."); callListener(true); cleanup(); } }); LinearLayout questions = (LinearLayout) activity.findViewById(R.id.questions); questions.removeAllViews(); // Then render all the questions for (final Question question : interaction.getQuestions()) { if (question.getType() == Question.QUESTION_TYPE_SINGLELINE) { TextSurveyQuestionView textQuestionView = new TextSurveyQuestionView(activity, surveyState, (SinglelineQuestion) question); textQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() { public void onAnswered() { sendMetricForQuestion(activity, question); send.setEnabled(isSurveyValid()); } }); questions.addView(textQuestionView); } else if (question.getType() == Question.QUESTION_TYPE_MULTICHOICE) { MultichoiceSurveyQuestionView multichoiceQuestionView = new MultichoiceSurveyQuestionView(activity, surveyState, (MultichoiceQuestion) question); multichoiceQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() { public void onAnswered() { sendMetricForQuestion(activity, question); send.setEnabled(isSurveyValid()); } }); questions.addView(multichoiceQuestionView); } else if (question.getType() == Question.QUESTION_TYPE_MULTISELECT) { MultiselectSurveyQuestionView multiselectQuestionView = new MultiselectSurveyQuestionView(activity, surveyState, (MultiselectQuestion) question); multiselectQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() { public void onAnswered() { sendMetricForQuestion(activity, question); send.setEnabled(isSurveyValid()); } }); questions.addView(multiselectQuestionView); } } send.setEnabled(isSurveyValid()); // Force the top of the survey to be shown first. title.requestFocus(); }
From source file:com.ninetwozero.battlelog.fragments.PlatoonOverviewFragment.java
public final void showProfile(PlatoonInformation data) { // Do we have valid data? if (data == null) { return;// w ww. j a va 2 s . co m } // Get the activity Activity activity = getActivity(); if (activity == null) { return; } // Let's start by getting an ImageView if (imageViewBadge == null) { imageViewBadge = (ImageView) activity.findViewById(R.id.image_badge); } // Set some TextViews ((TextView) activity.findViewById(R.id.text_name_platoon)) .setText(data.getName() + " [" + data.getTag() + "]"); ((TextView) activity.findViewById(R.id.text_date)).setText( getString(R.string.info_platoon_created).replace( "{DATE}", PublicUtils.getDate(data.getDate()) ).replace( "{RELATIVE DATE}", PublicUtils.getRelativeDate(context, data.getDate()) )); // Platform!! switch (data.getPlatformId()) { case 1: ((ImageView) activity.findViewById(R.id.image_platform)).setImageResource(R.drawable.logo_pc); break; case 2: ((ImageView) activity.findViewById(R.id.image_platform)).setImageResource(R.drawable.logo_xbox); break; case 4: ((ImageView) activity.findViewById(R.id.image_platform)).setImageResource(R.drawable.logo_ps3); break; default: ((ImageView) activity.findViewById(R.id.image_platform)).setImageResource(R.drawable.logo_pc); break; } // Set the properties imageViewBadge.setImageBitmap( BitmapFactory.decodeFile( PublicUtils.getCachePath(context) + data.getId() + ".jpeg" ) ); // Do we have a link?! if (data.getWebsite() != null && !data.getWebsite().equals("")) { ((TextView) activity.findViewById(R.id.text_web)).setText(data.getWebsite()); ((View) activity.findViewById(R.id.wrap_web)).setTag(data.getWebsite()); } else { ((View) activity.findViewById(R.id.wrap_web)).setVisibility(View.GONE); } // Do we have a presentation? if (data.getPresentation() != null && !data.getPresentation().equals("")) { ((TextView) activity.findViewById(R.id.text_presentation)).setText(data.getPresentation()); } else { ((TextView) activity.findViewById(R.id.text_presentation)).setText(R.string.info_profile_empty_pres); } }
From source file:com.ninetwozero.battlelog.fragments.ProfileOverviewFragment.java
public final void showProfile(ProfileInformation data) { // Do we have valid data? if (data == null) { return;// w w w .ja v a2s .c o m } // Get activity Activity activity = getActivity(); if (activity == null) { return; } // Let's start drawing the... layout ((TextView) activity.findViewById(R.id.text_username)).setText(data.getUsername()); // When did was the users last login? if (data.isPlaying() && data.isOnline()) { ((TextView) activity.findViewById(R.id.text_online)).setText( getString(R.string.info_profile_playing).replace( "{server name}", data.getCurrentServer() ) ); } else if (data.isOnline()) { ((TextView) activity.findViewById(R.id.text_online)).setText(R.string.info_profile_online); } else { ((TextView) activity.findViewById(R.id.text_online)).setText(data.getLastLogin(context)); } // Is the status ""? if (!data.getStatusMessage().equals("")) { // Set the status ((TextView) activity.findViewById(R.id.text_status)).setText(data.getStatusMessage()); ((TextView) activity.findViewById(R.id.text_status_date)).setText( PublicUtils.getRelativeDate(context, data.getStatusMessageChanged(), R.string.info_lastupdate)); } else { // Hide the view ((RelativeLayout) activity.findViewById(R.id.wrap_status)).setVisibility(View.GONE); } // Do we have a presentation? if (data.getPresentation() != null && !data.getPresentation().equals("")) { ((TextView) activity.findViewById(R.id.text_presentation)).setText(data.getPresentation()); } else { ((TextView) activity.findViewById(R.id.text_presentation)).setText(R.string.info_profile_empty_pres); } // Any platoons? if (data.getNumPlatoons() > 0) { // Init View convertView; LinearLayout platoonWrapper = (LinearLayout) activity.findViewById(R.id.list_platoons); // Clear the platoonWrapper ((TextView) activity.findViewById(R.id.text_platoon)).setVisibility(View.GONE); platoonWrapper.removeAllViews(); // Iterate over the platoons for (PlatoonData currentPlatoon : data.getPlatoons()) { // Does it already exist? if (platoonWrapper.findViewWithTag(currentPlatoon) != null) { continue; } // Recycle convertView = layoutInflater.inflate(R.layout.list_item_platoon, platoonWrapper, false); // Set the TextViews ((TextView) convertView.findViewById(R.id.text_name)).setText(currentPlatoon.getName()); ((TextView) convertView.findViewById(R.id.text_tag)).setText("[" + currentPlatoon.getTag() + "]"); ((TextView) convertView.findViewById(R.id.text_members)) .setText(currentPlatoon.getCountMembers() + ""); ((TextView) convertView.findViewById(R.id.text_fans)).setText(currentPlatoon.getCountFans() + ""); // Almost forgot - we got a Bitmap too! ((ImageView) convertView.findViewById(R.id.image_badge)).setImageBitmap( BitmapFactory.decodeFile(PublicUtils.getCachePath(context) + currentPlatoon.getImage()) ); // Store it in the tag convertView.setTag(currentPlatoon); convertView.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // On-click startActivity( new Intent(context, PlatoonActivity.class).putExtra( "platoon", (PlatoonData) v.getTag() ) ); } } ); // Add it! platoonWrapper.addView(convertView); } } else { ((LinearLayout) activity.findViewById(R.id.list_platoons)).removeAllViews(); ((TextView) activity.findViewById(R.id.text_platoon)).setVisibility(View.VISIBLE); } // Set the username ((TextView) activity.findViewById(R.id.text_username)).setText(data.getUsername()); }
From source file:com.emobc.android.activities.generators.PdfActivityGenerator.java
@Override protected void loadAppLevelData(final Activity activity, final AppLevelData data) { final PdfLevelDataItem item = (PdfLevelDataItem) data.findByNextLevel(nextLevel); if (item == null) return;//from w w w. j av a 2 s. c o m //rotateScreen(activity); initializeHeader(activity, item); //Create Banner CreateMenus c = (CreateMenus) activity; c.createBanner(); if (Utils.hasLength(item.getPdfUrl())) { WebView webview = (WebView) activity.findViewById(R.id.pdfviewer); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true); webview.setWebViewClient(new InsideWebViewClient(activity)); webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + item.getPdfUrl()); //activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(item.getPdfUrl()))); /* File outputDir = activity.getCacheDir(); try { File outputFile = File.createTempFile("eMobc", ".tmp", outputDir); if(downloadPdfToFile(outputFile, item.getPdfUrl())){ File file = new File(outputFile.getAbsolutePath()); if (file.exists()) { Uri path = Uri.fromFile(outputFile); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { activity.startActivity(intent); }catch (ActivityNotFoundException e) { Toast.makeText(activity, "No Application Available to View PDF", Toast.LENGTH_SHORT).show(); } } } } catch (IOException e1) { Log.e("PdfActivityGenerator", "Error: " + e1.getMessage()); }*/ /* String pdfFileUrl = String.format(PDF_WEBVIEW_TPL, item.getPdfUrl()); try { URL url = new URL(pdfFileUrl); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); url = uri.toURL(); WebView webView = (WebView)activity.findViewById(R.id.pdfviewer); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(url.toString()); Uri uriPath = Uri.parse(item.getPdfUrl()); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uriPath, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { activity.startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(activity, "No Application Available to View PDF", Toast.LENGTH_SHORT).show(); } } catch (MalformedURLException e) { Log.e("PdfActivityGenerator", "MalformedURLException: " + e.getMessage()); } catch (URISyntaxException e) { Log.e("PdfActivityGenerator", "URISyntaxException: " + e.getMessage()); } */ } }
From source file:com.andrew.apollo.ui.fragments.profile.ApolloFragment.java
@SuppressWarnings("deprecation") @Override//from w ww . j av a2s.co m public void onAttach(final Activity activity) { super.onAttach(activity); mProfileTabCarousel = (ProfileTabCarousel) activity.findViewById(R.id.activity_profile_base_tab_carousel); if (activity instanceof BaseActivity) { // Register the music status listener ((BaseActivity) activity).setMusicStateListenerListener(this); } }
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); }/* w w w .j a v a 2 s.c o m*/ 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; }