Пример #1
0
 /**
  * When the Take Picture button is clicked ...
  *
  * @param b
  */
 public void onTakePhoto(View b) {
   Log.d(TAG, "Take Picture selected");
   Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   // Do I need to specify where the gallery is to store things? YES
   startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
   BackgroundToast.showToast(
       ContextManager.getActivityContext(), "Newly created photo now myPhoto", Toast.LENGTH_LONG);
 }
Пример #2
0
 /**
  * When the Unfriend button is clicked ...
  *
  * @param b
  */
 public void onUnfriend(View b) {
   Log.d(TAG, "Unfriend selected");
   try {
     snet.setFriend(new DDNSFullName(currentSelection), false);
     BackgroundToast.showToast(
         ContextManager.getActivityContext(),
         "We are no longer friends with " + currentSelection,
         Toast.LENGTH_LONG);
   } catch (DB461Exception e) {
     Log.e(TAG, "Failed to set the selected name as no longer a friend");
   }
 }
Пример #3
0
  /**
   * When the Choose Picture button is clicked ...
   *
   * @param b
   */
  public void onChoosePicture(View b) {
    Log.d(TAG, "Choose Picture selected");

    // Attempts to access the gallery
    Intent intent =
        new Intent(
            Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    startActivityForResult(intent, CHOOSE_PICTURE_ACTIVITY_REQUEST_CODE);
    BackgroundToast.showToast(
        ContextManager.getActivityContext(), "New photo set as chosen", Toast.LENGTH_LONG);
  }
Пример #4
0
 /**
  * Called after we've been unloaded from memory and are restarting. E.g., 1st launch after
  * power-up; relaunch after going Home.
  */
 protected void onStart() {
   super.onStart();
   Log.d(TAG, "onStart");
   SharedPreferences settings = getSharedPreferences(PREFS_NAME, 3);
   if (settings.getInt("currentLayout", currentLayout) == R.layout.snet_main) {
     setLayoutMain();
     currentLayout = R.layout.snet_main;
   } else {
     Log.d(TAG, "Layout is contact");
     setLayoutContact();
     currentLayout = R.layout.snet_contact;
   }
   // save my context so that this app can retrieve it later
   ContextManager.setActivityContext(this);
 }
Пример #5
0
 public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
   // An item was selected. Store that item
   currentSelection = (String) parent.getItemAtPosition(pos);
   Log.d(TAG, "User selected: " + currentSelection);
   ContextManager.setActivityContext(this);
 }
Пример #6
0
 /**
  * When the Update Pictures button is clicked ...
  *
  * @param b
  */
 public void onExchange(View b) {
   Log.d(TAG, "Update Pictures selected");
   setLayoutContact();
   // save my context so that this app can retrieve it later
   ContextManager.setActivityContext(this);
 }
Пример #7
0
  /** Overrides onActivityResult so that I can capture and utilize the picture taken by the user */
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
      if (resultCode == RESULT_OK) {
        // Image captured and saved to fileUri specified in the Intent
        Log.d(TAG, "Picture taken");
        Bitmap photoBmp = (Bitmap) data.getExtras().get("data");
        // Sets the image viewed to the bitmap created by the camera
        ((ImageView) findViewById(R.id.mypicture)).setImageBitmap(photoBmp);

        // Need to store the file using its hash
        int file = photoBmp.hashCode();
        try {
          String filename = mGallery.getCanonicalPath() + "/" + file + ".jpg";
          File f = new File(filename);
          Log.d(
              TAG,
              "Trying to write the photo to file and update the database.  Photo display should already be set");
          FileOutputStream fOut = new FileOutputStream(f);
          photoBmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
          fOut.flush();
          fOut.close();
          // Writes the bitmap to the file
          snet.newMyPhoto(mMyName, filename, mGallery);
          // Then attempts to update the MyPhoto field for the user.

          // Then tries to update the gallery viewer
          sendBroadcast(
              new Intent(
                  Intent.ACTION_MEDIA_MOUNTED,
                  Uri.parse("file://" + Environment.getExternalStorageDirectory())));
        } catch (DB461Exception e) {
          Log.e(TAG, "Failed to set the picture as the new myPhoto");
        } catch (IOException e) {
          Log.e(TAG, "Failed to write the picture to file");
          Log.e(TAG, "Error message was: " + e.getMessage());
        }
      } else if (resultCode == RESULT_CANCELED) {
        // User canceled the request
        Log.d(TAG, "User canceled taking a new picture");
      } else {
        String msg = "Picture capturing failed";
        Log.e(TAG, msg);
        BackgroundToast.showToast(ContextManager.getActivityContext(), msg, Toast.LENGTH_LONG);
        // Image capture failed, advise user
      }
    } else if (requestCode == CHOOSE_PICTURE_ACTIVITY_REQUEST_CODE) {
      if (resultCode == RESULT_OK) {
        // We are trying to recover the selected image from the gallery
        // Code provided
        Uri selectedImage = data.getData();
        String[] filePathColumn = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String filePath = cursor.getString(columnIndex);
        cursor.close();
        try {
          filePath = filePath.substring(mGallery.getCanonicalPath().length());
          snet.setChosenPhoto(mMyName, mGallery.getCanonicalPath() + "/" + filePath, mGallery);
          // Tries to set the selected photo as the user's chosen photo
        } catch (DB461Exception e) {
          Log.e(TAG, "We failed to set the selected photo as the new chosen photo");
        } catch (IOException e) {
          Log.e(TAG, "We failed to get the path name");
        }
        // Then tries to update the gallery viewer
        sendBroadcast(
            new Intent(
                Intent.ACTION_MEDIA_MOUNTED,
                Uri.parse("file://" + Environment.getExternalStorageDirectory())));
      } else if (resultCode == RESULT_CANCELED) {
        Log.d(TAG, "User cancelled selected a new chosen photo");
      } else {
        Log.e(TAG, "No chosen photo was selected");
      }
    } else {
      // Should not have intercepted this as we utilized no other request codes
      String msg = "We intercepted an unexpected activity";
      Log.e(TAG, msg);
      BackgroundToast.showToast(ContextManager.getActivityContext(), msg, Toast.LENGTH_LONG);
    }
    // We want to return to the main menu screen no matter what
    setContentView(R.layout.snet_main);
  }