// Get IOB and COB only, dont update chart public static JSONObject getIOBCOB(Activity a) { List<Stats> statList = Stats.updateActiveBarChart(a.getBaseContext()); JSONObject reply = new JSONObject(); if (statList.size() > 0) { try { reply.put("iob", String.format(Locale.ENGLISH, "%.2f", statList.get(0).iob)); reply.put("cob", String.format(Locale.ENGLISH, "%.2f", statList.get(0).cob)); } catch (JSONException e) { Crashlytics.logException(e); e.printStackTrace(); } return reply; } else { try { reply.put("iob", String.format(Locale.ENGLISH, "%.2f", 0.00)); reply.put("cob", String.format(Locale.ENGLISH, "%.2f", 0.00)); } catch (JSONException e) { Crashlytics.logException(e); e.printStackTrace(); } return reply; } }
/** * Called when the BroadcastReceiver receives an Intent broadcast. Checks to see whether the * intent's action is _listClickAction. If it is, the app widget displays a Toast message for the * current item. */ @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(_listClickAction)) { // ---Launch video search in the browser--- String searchText = intent.getStringExtra("search_text"); String linkScheme1 = intent.getStringExtra("scheme1"); String linkScheme2 = intent.getStringExtra("scheme2"); Intent browserIntent = null; // new Intent(_listClickAction); try { browserIntent = new Intent( Intent.ACTION_VIEW, Uri.parse(linkScheme1 + URLEncoder.encode(searchText, "UTF-8") + linkScheme2)); } catch (UnsupportedEncodingException e) { BugSenseHandler.sendExceptionMessage("Widget4x4Provider", "onReceive", e); Crashlytics.setString("Widget4x4Provider", "onReceive"); Crashlytics.logException(e); if (ApplicationContext.DEBUG_MODE) e.printStackTrace(); } browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); browserIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); context.startActivity(browserIntent); } else if (intent.getAction().equals("android.appwidget.action.APPWIDGET_UPDATE")) { // ---Update the widget with latest search--- final AppWidgetManager mgr = AppWidgetManager.getInstance(context); onUpdate(context, mgr, appWidgetIds); } super.onReceive(context, intent); }
private void initUserSelectionMap() { try { String jsonString = readFromFile(NEWS_CAT_FILE); Crashlytics.log(Log.INFO, LOG_TAG, "jsonString - " + jsonString); fullJsonMap = JsonHelper.toMap(new JSONObject(jsonString)); Crashlytics.log(Log.INFO, LOG_TAG, "fullJsonMap - " + fullJsonMap.toString()); userSelectionMap = getUserFeedMapFromJsonMap(fullJsonMap); Crashlytics.log(Log.INFO, LOG_TAG, "UserSelectionMap - " + userSelectionMap.toString()); } catch (JSONException e) { Crashlytics.logException(e); } }
public void updateNewsCatFileWithNewAssets() { try { String jsonString = readFromFile(NEWS_CAT_FILE, true); Crashlytics.log(Log.INFO, LOG_TAG, "newJsonString - " + jsonString); Map<String, Object> newFullJsonMap = JsonHelper.toMap(new JSONObject(jsonString)); Crashlytics.log(Log.INFO, LOG_TAG, "newFullJsonMap - " + newFullJsonMap.toString()); convertUserFeedMapToJsonMap(newFullJsonMap); Map<String, List<String>> newUserSelectionMap = getUserFeedMapFromJsonMap(newFullJsonMap); Crashlytics.log(Log.INFO, LOG_TAG, "newUserSelectionMap - " + newUserSelectionMap); setUserSelectionMap(newUserSelectionMap); } catch (JSONException e) { e.printStackTrace(); } }
private void logUser() { // TODO: Use the current user's information // You can call any combination of these three methods Crashlytics.setUserIdentifier("12345"); Crashlytics.setUserEmail("*****@*****.**"); Crashlytics.setUserName("Test User"); }
// Updates Stats public static JSONObject updateChart(Activity a) { JSONObject reply = new JSONObject(); List<Stats> statList = Stats.updateActiveBarChart(a.getBaseContext()); if (iobcobChart != null || statList != null || statList.size() > 0) { // reloads charts with Treatment data iobcobChart.setColumnChartData(extendedGraphBuilder.iobcobFutureChart(statList)); try { reply.put("iob", String.format(Locale.ENGLISH, "%.2f", statList.get(0).iob)); reply.put("cob", String.format(Locale.ENGLISH, "%.2f", statList.get(0).cob)); } catch (JSONException e) { Crashlytics.logException(e); e.printStackTrace(); } return reply; } else { try { reply.put("iob", String.format(Locale.ENGLISH, "%.2f", 0.00)); reply.put("cob", String.format(Locale.ENGLISH, "%.2f", 0.00)); } catch (JSONException e) { Crashlytics.logException(e); e.printStackTrace(); } return reply; } }
public void handleLetterPress( KeyEvent event, int keyCode, Device.DeviceType mDeviceType, IBinder windowToken) { if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { // ---Done/Enter button was pressed--- InputMethodManager keyboard = (InputMethodManager) ApplicationContext.getInstance().getSystemService(Context.INPUT_METHOD_SERVICE); if (keyboard != null) { try { keyboard.hideSoftInputFromWindow(windowToken, 0); } catch (Exception e) { BugSenseHandler.sendExceptionMessage( "KeyBindings", "KeyEventHandlers.handleLetterPress", e); Crashlytics.setString("KeyBindings", "KeyEventHandlers.handleLetterPress"); Crashlytics.logException(e); if (ApplicationContext.DEBUG_MODE) e.printStackTrace(); } } } else if (event.getKeyCode() != KeyEvent.KEYCODE_MENU) { if (!SearchFragmentTab.ENGLISH_KBD_BACKSPACE) { if (mDeviceType == Device.DeviceType.Google_TV) { // *---Goog TV custom keys mappings!--- handleGoogTvKeyPress(event, keyCode); } else { handleNonGoogTvKeyPress(event, keyCode); } } else { SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false; } } }
private Boolean login(final LoLin1Account acc) { ChatServer chatServer; chatServer = ChatServer.valueOf(acc.getRealmEnum().name().toUpperCase(Locale.ENGLISH)); try { api = new LoLChat( LoLin1Application.getInstance().getContext(), ConnectivityManager.CONNECTIVITY_ACTION, chatServer, Boolean.FALSE); } catch (IOException e) { Crashlytics.logException(e); e.printStackTrace(System.err); if (!(e instanceof SSLException)) { launchBroadcastLoginFailed(); } return Boolean.FALSE; } Boolean loginSuccess = Boolean.FALSE; try { loginSuccess = api.login(acc.getUsername(), acc.getPassword()); } catch (IOException e) { Crashlytics.logException(e); } if (loginSuccess) { api.reloadRoster(); isConnected = Boolean.TRUE; return Boolean.TRUE; } else { isConnected = Boolean.FALSE; return Boolean.FALSE; } }
@Override public void call(JSONArray args) throws JSONException { if (argsLengthValid(3, args)) { Crashlytics.log(args.getInt(0), args.getString(1), args.getString(2)); } else { Crashlytics.log(args.getString(0)); } }
@Override protected Integer doInBackground(Void... params) { int result = R.string.toast_back_up; // Count all non-story files for (File f : app_internal) { mTotalFiles += countFiles(f); } // Count all story files for (File f : appFiles) { mTotalFiles += countFiles(f); } // Set the maximum possible progress in the progress bar publishProgress(mZippedFiles); final FileOutputStream fos; ZipOutputStream zos = null; byte[] buffer = new byte[1024]; try { fos = new FileOutputStream(output); zos = new ZipOutputStream(fos); // Zip all files for (File f : app_internal) { zipDir(zos, f, buffer, f.getName()); } for (File f : appFiles) { zipDir(zos, f, buffer, f.getName()); } } catch (IOException e) { Crashlytics.logException(e); result = R.string.error_unknown; } finally { // Note that ZipOutputStream closes the underlying FileOutputStream try { if (zos != null) zos.close(); } catch (IOException e) { Crashlytics.logException(e); result = R.string.error_unknown; } } return result; }
// TODO: make it private public void saveUserSelectionToJsonFile(Map<String, Object> newFullJsonMap) { try { fullJsonMap = newFullJsonMap; Object jsonString = JsonHelper.toJSON(newFullJsonMap); Crashlytics.log(Log.INFO, LOG_TAG, "Updating fullJson - " + jsonString.toString()); userSelectionMap = getUserFeedMapFromJsonMap(fullJsonMap); Crashlytics.log( Log.INFO, LOG_TAG, "Updated UserSelectionMap - " + userSelectionMap.toString()); writeToInternalStorage(jsonString.toString(), NEWS_CAT_FILE); } catch (JSONException e) { e.printStackTrace(); } }
@UiThread void updateUiAdapter(Address address) { if (map == null) { return; } try { ignoreUpdate = true; CameraPosition position = new CameraPosition.Builder() .target(new LatLng(address.getLatitude(), address.getLongitude())) .zoom(currentZoom) .build(); CameraUpdate update = CameraUpdateFactory.newCameraPosition(position); map.animateCamera(update); autocompleteEndereco.setAdapter(null); autocompleteEndereco.setText(street); autocompleteEndereco.setAdapter( new PlacesAutoCompleteAdapter( getActivity(), R.layout.autocomplete_list_item, ExploreFragment.class)); tvNumero.setText(number); } catch (Exception e) { Log.e("ZUP", e.getMessage(), e); Crashlytics.logException(e); } }
private void setValueOfKey(Map<String, Boolean> map, String key, Boolean value) { if (isKeyPresent(map, key)) { map.put(key, value); } else { Crashlytics.log(Log.ERROR, LOG_TAG, "Key: " + key + " not found..returning false"); } }
@Override public void onLoginFinished(Intent errorIntent) { AuthenticatorHelper helper = App.get(this).getAuthenticatorHelper(); boolean result = helper.hasAccount(); boolean premiumMember = helper.getRestrictions().isPremiumMember(); if (result) { //noinspection ConstantConditions Crashlytics.setUserName(helper.getAccount().name); } AnalyticsUtil.actionLogin(result, premiumMember); setResult(result ? RESULT_OK : RESULT_CANCELED); if (errorIntent != null) { startActivity(errorIntent); finish(); return; } if (premiumMember) { finish(); return; } BasicMembershipWarningDialogFragment.newInstance() .show(getFragmentManager(), BasicMembershipWarningDialogFragment.FRAGMENT_TAG); }
/** Show dialog with new features for this version */ public static AlertDialog showWhatsNewDialog(Context context) { Resources resources = context.getResources(); StringBuilder releaseTitle = new StringBuilder(resources.getString(R.string.title_whats_new)); PackageInfo packageInfo; try { packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); releaseTitle.append(" - v").append(packageInfo.versionName); } catch (NameNotFoundException e) { Crashlytics.logException(e); Log.e(LOG_TAG, "Error displaying 'Whats new' dialog"); } return new AlertDialog.Builder(context) .setTitle(releaseTitle.toString()) .setMessage(R.string.whats_new) .setPositiveButton( R.string.label_dismiss, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .show(); }
@Background void cameraChangeTask() { showHideLoading(true); try { valid = ZupApi.validateCityBoundary(getActivity(), latitude, longitude); if (GPSUtils.getFromLocation(getActivity(), latitude, longitude) == null) { return; } Address addr = GPSUtils.getFromLocation(getActivity(), latitude, longitude).get(0); showHideLoading(false); verifyValid(); if (addr == null) { return; } street = addr.getThoroughfare(); if (!TextUtils.isEmpty(addr.getFeatureName()) && StringUtils.isNumeric(addr.getFeatureName().substring(0, 1))) { number = addr.getFeatureName(); } else { number = ""; } updateUiAdapter(addr); } catch (Exception e) { Log.e("ZUP", e.getMessage(), e); Crashlytics.logException(e); } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Crashlytics.start(this); Resize.setup(this, false); context = this; RelativeLayout bgLayout = new RelativeLayout(this); bgLayout.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); bgLayout.setBackgroundResource(R.drawable.splash_bg); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_IN_PARENT); splashImageView = new ImageView(this); splashImageView.setLayoutParams(params); splashImageView.setBackgroundResource(R.drawable.splash_logo); bgLayout.addView(splashImageView); setContentView(bgLayout); Handler h = new Handler(); h.postDelayed(this, 2000); }
public static void setSuggested_Temp_Basal(JSONObject openAPSSuggest, Context c) { try { Suggested_Temp_Basal = new TempBasal(); Notifications.clear(MainActivity.activity); // Clears any open notifications if (openAPSSuggest.has("rate")) { // Temp Basal suggested Suggested_Temp_Basal.rate = openAPSSuggest.getDouble("rate"); Suggested_Temp_Basal.ratePercent = openAPSSuggest.getInt("ratePercent"); Suggested_Temp_Basal.duration = openAPSSuggest.getInt("duration"); Suggested_Temp_Basal.basal_type = openAPSSuggest.getString("temp"); Suggested_Temp_Basal.basal_adjustemnt = openAPSSuggest.getString("basal_adjustemnt"); if (openAPSSuggest .getString("openaps_mode") .equals("closed")) { // OpenAPS mode is closed, send command direct to pump pumpAction.setTempBasal( openAPSFragment.getSuggested_Temp_Basal(), MainActivity.activity); } else { // Make notification (Wear & Phone) Notifications.newTemp(openAPSSuggest, c); } } } catch (Exception e) { Crashlytics.logException(e); Toast.makeText( MainActivity.activity, "Crash in setSuggested_Temp_Basal", Toast.LENGTH_SHORT) .show(); } currentOpenAPSSuggest = openAPSSuggest; update(); }
/** * Toggles the Hybrid keyboard with the appropriate language * * @param sFragmentManager FragmentManager that is responsible for the transaction */ public void handleHybridShiftButton(FragmentManager sFragmentManager) { BugSenseHandler.sendEvent("Hybrid shift button was pressed"); Crashlytics.log("Hybrid shift button was pressed"); SearchFragmentTab.myVib.vibrate(20); // ---Figure out what type of hybrid keyboard should be shown, and save it in shared prefs--- if (ApplicationContext.getInstance().getHybridKeyboardMode().equals("") || ApplicationContext.getInstance() .getHybridKeyboardMode() .equals("Hybrid_English_To_Russ")) { ApplicationContext.getInstance().setHybridKeyboardMode("Hybrid_Russian_To_Eng"); } else { ApplicationContext.getInstance().setHybridKeyboardMode("Hybrid_English_To_Russ"); } ApplicationContext.getInstance() .sharedPreferencesEditor .putString("HYBRID_TYPE", ApplicationContext.getInstance().getHybridKeyboardMode()); ApplicationContext.getInstance().sharedPreferencesEditor.commit(); if (Build.VERSION.SDK_INT > 7) ApplicationContext.getInstance().backupManager.dataChanged(); // ---refresh the search tab_layout--- SearchFragmentTab searchFragment = new SearchFragmentTab(); sFragmentManager .beginTransaction() .replace(sFragmentManager.findFragmentByTag("search").getId(), searchFragment, "search") .commit(); mapKeyBindings(ApplicationContext.getInstance()); }
@Override public void genericAsyncTaskOnSuccess(Object obj) { if (PurpleSQ.isLoadingDialogVisible()) { PurpleSQ.dismissLoadingDialog(); } mPaymentTask = null; if (obj != null && obj instanceof PaymentPayUVo) { PaymentPayUVo paymentPayUVo = (PaymentPayUVo) obj; PaymentPayUVo.PaymentRequstVo mPaymentRequstVo = paymentPayUVo.getRequest(); new PayUTask(mActivity, mPaymentRequstVo).execute((Void) null); } else if (obj != null && obj instanceof CouponsVo) { CouponsVo couponsVo = (CouponsVo) obj; updateUiForCoupon(couponsVo); } else if (obj != null && obj instanceof TransactionVo) { TransactionVo transactionVo = (TransactionVo) obj; try { mTransactionVo = transactionVo; PurpleSQ.showLoadingDialog(PaymentActivity.this); mPaymentTask = new PaymentTask(authVo.getToken(), couponCode, mTransactionVo, PaymentActivity.this); mPaymentTask.execute((Void) null); } catch (Exception e) { e.printStackTrace(); Crashlytics.logException(e); } } }
private void init() { try { jsonObject = new JSONObject(this.serverResponse.responseData); checkErrors(); if (!serverResponse.isResponseOk()) { jsonObject = null; } } catch (Exception e) { if (SettingsManager.DEBUG()) Log.e(LOG_TAG, "JSONUtility " + e.getMessage()); if (SettingsManager.DEBUG()) Log.e(LOG_TAG, "JSONUtility :: Failed to parse json"); Crashlytics.setString("response message", serverResponse.responseMessage); Crashlytics.setString("response data", serverResponse.responseData); Crashlytics.setInt("response code", serverResponse.code); Crashlytics.setString("request url", serverResponse.request); Crashlytics.logException(e); } }
/** * Returns the currency for an account which has been parsed (but not yet saved to the db) * * <p>This is used when parsing splits to assign the right currencies to the splits * * @param accountUID GUID of the account * @return Currency of the account */ private Currency getCurrencyForAccount(String accountUID) { try { return mAccountMap.get(accountUID).getCurrency(); } catch (Exception e) { Crashlytics.logException(e); return Currency.getInstance(Money.DEFAULT_CURRENCY_CODE); } }
/** * Handles the case when we reach the end of the template numeric slot * * @param characterString Parsed characters containing split amount */ private void handleEndOfTemplateNumericSlot(String characterString, TransactionType splitType) { try { BigDecimal amountBigD = GncXmlHelper.parseSplitAmount(characterString); Money amount = new Money(amountBigD, getCurrencyForAccount(mSplit.getAccountUID())); mSplit.setValue(amount.absolute()); mSplit.setType(splitType); mIgnoreTemplateTransaction = false; // we have successfully parsed an amount } catch (NumberFormatException | ParseException e) { String msg = "Error parsing template credit split amount " + characterString; Log.e(LOG_TAG, msg + "\n" + e.getMessage()); Crashlytics.log(msg); Crashlytics.logException(e); } finally { if (splitType == TransactionType.CREDIT) mInCreditNumericSlot = false; else mInDebitNumericSlot = false; } }
private boolean getValueOfKey(Map<String, Boolean> map, String key) { if (isKeyPresent(map, key)) { return map.get(key); } else { Crashlytics.log(Log.ERROR, LOG_TAG, "Key: " + key + " not found..returning false"); } return false; }
public String readFromFile(String fileName, boolean readFromAsset) { StringBuilder returnString = new StringBuilder(); InputStreamReader isr = null; BufferedReader input = null; FileInputStream fis = null; InputStream is = null; try { File file = new File(context.getCacheDir(), fileName); if (readFromAsset) { // Reading from Assets Crashlytics.log(Log.INFO, LOG_TAG, "Reading from Assets"); is = context.getAssets().open(fileName); isr = new InputStreamReader(is); } else { // Reading from Internal Crashlytics.log(Log.INFO, LOG_TAG, "Reading from Internal"); fis = new FileInputStream(file); isr = new InputStreamReader(fis); } input = new BufferedReader(isr); String line; while ((line = input.readLine()) != null) { returnString.append(line); returnString.append("\n"); } if (readFromAsset) { writeToInternalStorage(returnString.toString(), fileName); } } catch (FileNotFoundException e) { Crashlytics.logException(e); } catch (Exception e) { Crashlytics.logException(e); } finally { try { if (isr != null) isr.close(); if (fis != null) fis.close(); if (is != null) is.close(); if (input != null) input.close(); } catch (Exception e2) { Crashlytics.logException(e2); } } return returnString.toString(); }
public static void uploadTempBasals(Context c, SharedPreferences prefs) { // Will grab the last 20 suggested TempBasals and check they have all been uploaded to NS List<TempBasal> tempBasals = TempBasal.latestTempBasals(20); JSONArray tempBasalsJSONArray = new JSONArray(); String url = prefs.getString("nightscout_url", "") + "/treatments/"; DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ"); String dateAsISO8601; for (TempBasal tempBasal : tempBasals) { try { JSONObject tempBasalJSON = new JSONObject(); JSONObject tempBasalIntegration = tools.getJSONO(tempBasal.integration); if (!tempBasalIntegration.has("ns_upload_id")) { tempBasalJSON.put("happ_id", tempBasal.getId()); tempBasalJSON.put("enterdBy", "HAPP_APP"); dateAsISO8601 = df.format(tempBasal.start_time); tempBasalJSON.put("created_at", dateAsISO8601); tempBasalJSON.put("eventType", "Temp Basal"); tempBasalJSON.put("duration", tempBasal.duration); // if (tempBasal.basal_type.equals("percent")) { //Percent is // not supported in NS as expected // tempBasalJSON.put("percent", tempBasal.ratePercent); //Basal 1U / // Hour // } else { //NS = 50% // means * 1.5 ~~ HAPP 50% means * 0.5 tempBasalJSON.put("absolute", tempBasal.rate); // } tempBasalsJSONArray.put(tempBasalJSON); } else if (tempBasalIntegration.has("ns_temp_basal_stop")) { // This Temp Basal has been stopped, insert a record to NS so it knows if (tempBasalIntegration.getString("ns_temp_basal_stop").equals("dirty")) { tempBasalJSON.put("happ_id", tempBasal.getId()); tempBasalJSON.put("enterdBy", "HAPP_APP"); dateAsISO8601 = df.format(tempBasal.endDate()); tempBasalJSON.put("created_at", dateAsISO8601); tempBasalJSON.put("eventType", "Temp Basal"); // tempBasalJSON.put("happ_note", "temp_basal_stop"); tempBasalsJSONArray.put(tempBasalJSON); } } } catch (JSONException | NullPointerException e) { Crashlytics.logException(e); } } if (tempBasalsJSONArray.length() > 0) { jsonPost(tempBasalsJSONArray, url, c); } }
public void deselectNewsCat(String newspaper, String category, Map<String, Object> map) { if (map.containsKey(newspaper)) { Map<String, Boolean> categories = getAllCategoriesFromJsonMap(newspaper, map); setValueOfKey(categories, category, false); } else { Crashlytics.log(Log.ERROR, LOG_TAG, "Key: " + newspaper + " not found..returning false"); throw new RuntimeException("Key: " + newspaper + " not found"); } }
public boolean isNewsCatSelected(String newspaper, String category, Map<String, Object> map) { boolean selected; if (map.containsKey(newspaper)) { Map<String, Boolean> categories = getAllCategoriesFromJsonMap(newspaper, map); selected = getValueOfKey(categories, category); } else { Crashlytics.log(Log.ERROR, LOG_TAG, "Key: " + newspaper + " not found..returning false"); selected = false; } return selected; }
@Override public void onCompleted(Exception e, T result) { if (e != null) { Crashlytics.log(Log.ERROR, TAG, "URL requested:" + mUrl); onException(e); return; } if (result == null) { Crashlytics.log(Log.ERROR, TAG, "Ion returned result was null."); onError(); return; } try { onSuccess(result); } catch (Exception e1) { Crashlytics.log( Log.ERROR, TAG, "Exception occurred in onSuccess of Ion. URL requested:" + mUrl); onException(e1); } }
private void disconnect() { // All the null checks are necessary because this method is run when an account is added // from out of the app as well try { if (mLoginTask != null) mLoginTask.get(); // Disconnecting in the middle of a login may be troublesome } catch (InterruptedException | ExecutionException e) { Crashlytics.logException(e); } try { if (api != null) { api.disconnect(); api = null; } } catch (SmackException.NotConnectedException e) { Crashlytics.logException(e); } if (mSmackAndroid != null) mSmackAndroid.onDestroy(); isConnected = Boolean.FALSE; }