private String[] getCommandLine() { InputStream is; try { is = getAssets().open("_cl_"); byte[] len = new byte[4]; int r = is.read(len); if (r < 4) { Log.d("XXX", "**ERROR** Wrong cmdline length.\n"); Log.d("GODOT", "**ERROR** Wrong cmdline length.\n"); return new String[0]; } int argc = ((int) (len[3] & 0xFF) << 24) | ((int) (len[2] & 0xFF) << 16) | ((int) (len[1] & 0xFF) << 8) | ((int) (len[0] & 0xFF)); String[] cmdline = new String[argc]; for (int i = 0; i < argc; i++) { r = is.read(len); if (r < 4) { Log.d("GODOT", "**ERROR** Wrong cmdline param lenght.\n"); return new String[0]; } int strlen = ((int) (len[3] & 0xFF) << 24) | ((int) (len[2] & 0xFF) << 16) | ((int) (len[1] & 0xFF) << 8) | ((int) (len[0] & 0xFF)); if (strlen > 65535) { Log.d("GODOT", "**ERROR** Wrong command len\n"); return new String[0]; } byte[] arg = new byte[strlen]; r = is.read(arg); if (r == strlen) { cmdline[i] = new String(arg, "UTF-8"); } } return cmdline; } catch (Exception e) { e.printStackTrace(); Log.d("GODOT", "**ERROR** Exception " + e.getClass().getName() + ":" + e.getMessage()); return new String[0]; } }
public boolean sendEmail(String subject, String body, String address) { try { GmailSender sender = new GmailSender("*****@*****.**", "hackapart4ever"); sender.sendMail(subject, body, "*****@*****.**", address); return true; } catch (Exception e) { Log.d("SendMail", e.getMessage(), e); return false; } }
@Override public void onReceive(Context context, Intent intent) { try { Log.d(G.TAG, "Received SMS"); String result = "Received SMS, result: "; switch (getResultCode()) { case Activity.RESULT_OK: result += "Message Received!"; break; default: result += "Error when receiving Message"; break; } Log.d(G.TAG, result); Utils.showResultInDialog(mActivity, result); } catch (Exception e) { e.printStackTrace(); Log.e(G.TAG, e.getMessage()); Utils.showResultInDialog(mActivity, "Error when receiving Message: " + e.getMessage()); } }
private void doRetryableAlert(Exception e, String msg) { AlertDialog.Builder dialog = new AlertDialog.Builder(SelectAccount.this); dialog.setTitle(msg); String dispMsg = msg + "\n\n" + e.getMessage(); dialog.setMessage(dispMsg); dialog.setPositiveButton( "Retry", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { requestAccountList(); } }); dialog.setNegativeButton("Cancel", emptyClickListener); AlertDialog dlg = dialog.create(); dlg.show(); }
@Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { Log.d(TAG, "onEditorAction: actionId: " + actionId + ", keyEvent: " + keyEvent); if ((actionId == EditorInfo.IME_ACTION_DONE) || ((keyEvent != null) && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))) { Log.d(TAG, "onEditorAction: IME_ACTION_DONE || KEYCODE_ENTER"); String input = textView.getText().toString().trim(); if (input.length() > 0) { String result = ""; try { result += calculator.calculate(input); } catch (Exception e) { result = "no result (" + e.getMessage() + ")"; } if (listAdapter.getCount() > 0) { listAdapter.add(""); } listAdapter.add(input + " ="); if (input.indexOf("@") > -1) { listAdapter.add(calculator.getEquation() + " ="); } listAdapter.add(result); listAdapter.notifyDataSetChanged(); inputView.endBatchEdit(); inputView.setText(""); hideKeyboard(); } } return false; }
private static String getCursorContent(Cursor c, int maxRows) { if (c == null) { return G.NOTHING_FOUND; } String allInfo = ""; while (c.moveToNext() && c.getPosition() < maxRows) { try { for (int i = 0; i < c.getColumnCount(); i++) { String s = c.getString(i); if (s != null) { allInfo += "[" + "Index:" + i + " | " + "Info: " + s + "]\n"; } } } catch (Exception e) { e.printStackTrace(); Log.e(G.TAG, e.getMessage()); } } c.close(); if (TextUtils.isEmpty(allInfo)) { return G.NOTHING_FOUND; } return allInfo; }
/** * Given a location fix, processes it and displays it in the table on the form. * * @param loc Location information */ private void DisplayLocationInfo(Location loc) { Utilities.LogDebug("GpsMainActivity.DisplayLocationInfo"); try { if (loc == null) { return; } TextView tvLatitude = (TextView) findViewById(R.id.txtLatitude); TextView tvLongitude = (TextView) findViewById(R.id.txtLongitude); TextView tvDateTime = (TextView) findViewById(R.id.txtDateTimeAndProvider); TextView tvAltitude = (TextView) findViewById(R.id.txtAltitude); TextView txtSpeed = (TextView) findViewById(R.id.txtSpeed); TextView txtSatellites = (TextView) findViewById(R.id.txtSatellites); TextView txtDirection = (TextView) findViewById(R.id.txtDirection); TextView txtAccuracy = (TextView) findViewById(R.id.txtAccuracy); String providerName = loc.getProvider(); if (providerName.equalsIgnoreCase("gps")) { providerName = getString(R.string.providername_gps); } else { providerName = getString(R.string.providername_celltower); } tvDateTime.setText( new Date(Session.getLatestTimeStamp()).toLocaleString() + getString(R.string.providername_using, providerName)); tvLatitude.setText(String.valueOf(loc.getLatitude())); tvLongitude.setText(String.valueOf(loc.getLongitude())); if (loc.hasAltitude()) { double altitude = loc.getAltitude(); if (AppSettings.shouldUseImperial()) { tvAltitude.setText( String.valueOf(Utilities.MetersToFeet(altitude)) + getString(R.string.feet)); } else { tvAltitude.setText(String.valueOf(altitude) + getString(R.string.meters)); } } else { tvAltitude.setText(R.string.not_applicable); } if (loc.hasSpeed()) { float speed = loc.getSpeed(); String unit; if (AppSettings.shouldUseImperial()) { if (speed > 1.47) { speed = speed * 0.6818f; unit = getString(R.string.miles_per_hour); } else { speed = Utilities.MetersToFeet(speed); unit = getString(R.string.feet_per_second); } } else { if (speed > 0.277) { speed = speed * 3.6f; unit = getString(R.string.kilometers_per_hour); } else { unit = getString(R.string.meters_per_second); } } txtSpeed.setText(String.valueOf(speed) + unit); } else { txtSpeed.setText(R.string.not_applicable); } if (loc.hasBearing()) { float bearingDegrees = loc.getBearing(); String direction; direction = Utilities.GetBearingDescription(bearingDegrees, getApplicationContext()); txtDirection.setText( direction + "(" + String.valueOf(Math.round(bearingDegrees)) + getString(R.string.degree_symbol) + ")"); } else { txtDirection.setText(R.string.not_applicable); } if (!Session.isUsingGps()) { txtSatellites.setText(R.string.not_applicable); Session.setSatelliteCount(0); } if (loc.hasAccuracy()) { float accuracy = loc.getAccuracy(); if (AppSettings.shouldUseImperial()) { txtAccuracy.setText( getString( R.string.accuracy_within, String.valueOf(Utilities.MetersToFeet(accuracy)), getString(R.string.feet))); } else { txtAccuracy.setText( getString( R.string.accuracy_within, String.valueOf(accuracy), getString(R.string.meters))); } } else { txtAccuracy.setText(R.string.not_applicable); } } catch (Exception ex) { SetStatus(getString(R.string.error_displaying, ex.getMessage())); } }
// Setup @Override protected void onCreate(Bundle savedInstanceState) { Log.v("SDL", "Device: " + android.os.Build.DEVICE); Log.v("SDL", "Model: " + android.os.Build.MODEL); Log.v("SDL", "onCreate():" + mSingleton); super.onCreate(savedInstanceState); SDLActivity.initialize(); // So we can call stuff from static callbacks mSingleton = this; // Load shared libraries String errorMsgBrokenLib = ""; try { loadLibraries(); } catch (UnsatisfiedLinkError e) { System.err.println(e.getMessage()); mBrokenLibraries = true; errorMsgBrokenLib = e.getMessage(); } catch (Exception e) { System.err.println(e.getMessage()); mBrokenLibraries = true; errorMsgBrokenLib = e.getMessage(); } if (mBrokenLibraries) { AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this); dlgAlert.setMessage( "An error occurred while trying to start the application. Please try again and/or reinstall." + System.getProperty("line.separator") + System.getProperty("line.separator") + "Error: " + errorMsgBrokenLib); dlgAlert.setTitle("SDL Error"); dlgAlert.setPositiveButton( "Exit", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close current activity SDLActivity.mSingleton.finish(); } }); dlgAlert.setCancelable(false); dlgAlert.create().show(); return; } // Set up the surface mSurface = new SDLSurface(getApplication()); if (Build.VERSION.SDK_INT >= 12) { mJoystickHandler = new SDLJoystickHandler_API12(); } else { mJoystickHandler = new SDLJoystickHandler(); } mLayout = new AbsoluteLayout(this); mLayout.addView(mSurface); setContentView(mLayout); }