Example #1
0
 private static void saveLangue(String filepath, String data) {
   BufferedWriter writer = null;
   try {
     writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(filepath))));
     writer.write(data);
   } catch (Exception e) {
     Log.d("savelangue1", e.getMessage());
   } finally {
     if (writer != null) {
       try {
         writer.close();
       } catch (Exception e) {
         Log.d("savelangue", e.getMessage());
       }
     }
   }
 }
 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;
   }
 }
Example #3
0
 private static String getLangueSave(String path) {
   String monText = "";
   BufferedReader input = null;
   try {
     input = new BufferedReader(new InputStreamReader(new FileInputStream(new File(path))));
     String line;
     StringBuffer buffer = new StringBuffer();
     while ((line = input.readLine()) != null) {
       buffer.append(line);
     }
     monText = buffer.toString();
   } catch (Exception e) {
     Log.d("getlangue1", e.getMessage());
   } finally {
     if (input != null) {
       try {
         input.close();
       } catch (Exception e2) {
         Log.d("getlangue2", e2.getMessage());
       }
     }
   }
   return monText;
 }
Example #4
0
  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];
    }
  }
        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();
        }
Example #6
0
 public void mOnClick(View v) {
   switch (v.getId()) {
     case R.id.test:
       String rootdir = Environment.getRootDirectory().getAbsolutePath();
       String datadir = Environment.getDataDirectory().getAbsolutePath();
       String cachedir = Environment.getDownloadCacheDirectory().getAbsolutePath();
       mEdit.setText(
           String.format(
               "ext = %s\nroot=%s\ndata=%s\ncache=%s", mSdPath, rootdir, datadir, cachedir));
       break;
     case R.id.save:
       File dir = new File(mSdPath + "/dir");
       dir.mkdir();
       File file = new File(mSdPath + "/dir/file.txt");
       try {
         FileOutputStream fos = new FileOutputStream(file);
         String str = "This file exists in SDcard";
         fos.write(str.getBytes());
         fos.close();
         mEdit.setText("write success");
       } catch (FileNotFoundException e) {
         mEdit.setText("File Not Found." + e.getMessage());
       } catch (SecurityException e) {
         mEdit.setText("Security Exception");
       } catch (Exception e) {
         mEdit.setText(e.getMessage());
       }
       break;
     case R.id.load:
       try {
         FileInputStream fis = new FileInputStream(mSdPath + "/dir/file.txt");
         byte[] data = new byte[fis.available()];
         while (fis.read(data) != -1) {;
         }
         fis.close();
         mEdit.setText(new String(data));
       } catch (FileNotFoundException e) {
         mEdit.setText("File Not Found");
       } catch (Exception e) {;
       }
       break;
   }
 }
Example #7
0
  @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;
  }
Example #8
0
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   if (mediaRecorder == null) {
     try {
       Log.d(TAG, "Opening camera");
       camera = Camera.open();
       Log.d(TAG, "Camera opened");
       Camera.Parameters parameters = camera.getParameters();
       setRequestedOrientation(90);
       camera.setDisplayOrientation(90);
       camera.setParameters(parameters);
       Log.d(TAG, "Set parameters");
       camera.setPreviewDisplay(holder); // set SurfaceHolder as destination for frames
       Log.d(TAG, "Set preview display");
       camera.startPreview();
       Button takePhotoButton = (Button) findViewById(R.id.takePhotoButton);
       takePhotoButton.setVisibility(View.VISIBLE);
       Log.d(TAG, "Button visible");
       Log.d(TAG, "Preview started");
     } catch (Exception e) {
       Log.d(TAG, e.getMessage());
     }
   }
 }
Example #9
0
  @Override
  public void onClick(View v) {
    if (v.getId() == R.id.takePhotoButton) {
      camera.takePicture(shutterCallback, rawCallback, jpegCallback);
      Button takePhotoButton = (Button) findViewById(R.id.takePhotoButton);
      takePhotoButton.setVisibility(View.INVISIBLE);
    }
    if (v.getId() == R.id.cameraTryAgainButton) {
      Button saveButton = (Button) findViewById(R.id.savePhotoButton);
      saveButton.setVisibility(View.INVISIBLE);
      Button cameraTryAgainButton = (Button) findViewById(R.id.cameraTryAgainButton);
      cameraTryAgainButton.setVisibility(View.INVISIBLE);
      Button takePhotoButton = (Button) findViewById(R.id.takePhotoButton);
      takePhotoButton.setVisibility(View.VISIBLE);
      camera.startPreview();
      /*canvas = holder.lockCanvas();
      Picture picture = new Picture();
      picture.draw(canvas);
      canvas.drawPicture(picture);
      holder.unlockCanvasAndPost(canvas);*/
    }
    if (v.getId() == R.id.savePhotoButton) {
      filename = "picture" + ic.numberOfPictures + ".jpg"; // STEP ONE : Set filename
      ic.numberOfPictures++;
      file = path + filename;

      Calendar calendar = new GregorianCalendar(); // STEP TWO : Get Calendar object
      int month = calendar.get(calendar.MONTH); // 			  and time/date
      int day = calendar.get(calendar.DAY_OF_MONTH);
      String time = calendar.getTime().toString().substring(11, 19);
      int hour = Integer.valueOf(time.substring(0, 2));
      if (hour > 12) {
        int oldHour = hour; // STEP THREE: Format time
        hour = hour - 12;
        String oldS = Integer.toString(oldHour);
        String hourS = Integer.toString(hour);
        if (hourS.length() == 1) hourS = "0" + hourS;
        time = time.substring(2);
        time = hourS + time;
        time.replaceFirst(oldS, hourS);
        isAM = false;
      }
      if (isAM) time = time + " AM " + " ---		Picture";
      else time = time + " PM " + " ---		Picture";
      String year = new Integer(calendar.get(calendar.YEAR)).toString();
      database
          .get(year)
          .get(months[month])
          .get(days[day - 1])
          .put(time, file); // STEP FOUR: Pull day out of
      Toast.makeText(this, "Picture saved to: " + file, Toast.LENGTH_LONG)
          .show(); //			  the database
      Button saveButton = (Button) findViewById(R.id.savePhotoButton);
      saveButton.setVisibility(View.INVISIBLE);
      Button takePhotoButton = (Button) findViewById(R.id.takePhotoButton);
      takePhotoButton.setVisibility(View.INVISIBLE);
      try {
        FileOutputStream camFOS =
            new FileOutputStream(file); // STEP FIVE: Save picture to MindBook directory
        camFOS.write(picture);
        camFOS.close();
      } catch (FileNotFoundException fnfe) {
        Log.d("CAMERA", fnfe.getMessage());
      } catch (IOException ioe) {
        Log.d("CAMERA", ioe.getMessage());
      }
      try {
        ObjectOutputStream dataOOS =
            new ObjectOutputStream(new FileOutputStream(path + "database.ser"));
        dataOOS.writeObject(database);
        dataOOS.close();
        ObjectOutputStream counterOOS =
            new ObjectOutputStream(new FileOutputStream(path + "counter.ser"));
        counterOOS.writeObject(ic);
        counterOOS.close();
      } catch (Exception e) {
        Log.d("CAMERA", e.getMessage());
      }
    }
  }
Example #10
0
  // 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);
  }