Пример #1
0
  protected void onResume() {
    super.onResume();
    mGameSettings.getString(GAME_PREFERENCES_USERNAME, null);
    mGameSettings.getString(GAME_PREFERENCES_SCHOOL, null);
    if (mGameSettings.contains(GAME_PREFERENCES_AVATAR)) {
      String img = mGameSettings.getString(GAME_PREFERENCES_AVATAR, null);
      Uri path = Uri.parse(img);
      ImageButton ava = (ImageButton) findViewById(R.id.avatar);
      ava.setImageURI(null);
      ava.setImageURI(path);
    }
    if (mGameSettings.contains(GAME_PREFERENCES_DOB)) {
      long dtDob = mGameSettings.getLong(GAME_PREFERENCES_DOB, 0);
      TextView dob = (TextView) findViewById(R.id.ShowDate);
      dob.setText(DateFormat.format("MMMM dd, yyyy", dtDob));
    }

    final EditText usernameText = (EditText) findViewById(R.id.EnterUsername);
    usernameText.setText(mGameSettings.getString(GAME_PREFERENCES_USERNAME, null));
    final EditText emailText = (EditText) findViewById(R.id.enterschool);
    emailText.setText(mGameSettings.getString(GAME_PREFERENCES_SCHOOL, null));

    TextView passwordInfo = (TextView) findViewById(R.id.ShowPassword);
    passwordInfo.setText(mGameSettings.getString(GAME_PREFERENCES_PASSWORD, null));
  }
Пример #2
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    if (requestCode == REQUEST_CODE_PHOTO) {
      if (resultCode == RESULT_OK) {
        if (imageReturnedIntent == null) {
        } else {

          Bundle bndl = imageReturnedIntent.getExtras();
          if (bndl != null) {
            Object obj = imageReturnedIntent.getExtras().get("data");
            if (obj instanceof Bitmap) {
              Bitmap bitmap = (Bitmap) obj;
              imbutton.setImageBitmap(bitmap);
            }
          }
        }
      } else if (resultCode == RESULT_CANCELED) {

      }
    }
    Bitmap bitmap = null;
    switch (requestCode) {
      case GALLERY_REQUEST:
        if (resultCode == RESULT_OK) {
          Uri selectedImage = imageReturnedIntent.getData();
          imbutton.setImageURI(selectedImage);
          imbutton.setImageBitmap(bitmap);
        }
    }
  }
Пример #3
0
  private void saveAvatar(Bitmap avatar) {
    // TODO: Save the Bitmap as a local file called avatar.jpg
    String strAvatarFilename = "avatar.jpg";
    try {
      avatar.compress(CompressFormat.JPEG, 100, openFileOutput(strAvatarFilename, MODE_PRIVATE));
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // TODO: Determine the Uri to the local avatar.jpg file

    // TODO: Save the Uri path as a String preference
    Uri imageUri = Uri.fromFile(new File(getFilesDir(), strAvatarFilename));
    // TODO: Update the ImageButton with the new image
    ImageButton ava = (ImageButton) findViewById(R.id.avatar);

    ava.setImageURI(imageUri);
    String curimg = imageUri.getPath().toString();

    Editor edit = mGameSettings.edit();
    edit.putString(GAME_PREFERENCES_AVATAR, curimg);
    edit.commit();

    String userName = mGameSettings.getString(GAME_PREFERENCES_USERNAME, null);
    String avatarName = userName + "Avatar";
    String filePath = curimg;
    String description = "My player avatar ";
    App42API.initialize(
        this,
        "33febecb03a579e972755eccde307dd94a279b5cfe348f845b8762f8e3feb2d6",
        "b5be405b4e76d40a94cdc01250311205b5a7c7b2dc4d003714f24d0df3e219f8");
    AvatarService avatarService = App42API.buildAvatarService();
    App42API.setOfflineStorage(true);
    avatarService.createAvatar(
        avatarName,
        userName,
        filePath,
        description,
        new App42CallBack() {
          public void onSuccess(Object response) {
            Avatar avatar = (Avatar) response;
            System.out.println("avatarName is :" + avatar.getName());
            System.out.println("url is :" + avatar.getURL());
            System.out.println("tinyUrl is :" + avatar.getTinyURL());
            System.out.println("createdOn is :" + avatar.getCreatedOn());
            System.out.println("Description is :" + avatar.getDescription());
            System.out.println("Is Current :" + avatar.isCurrent());
            System.out.println("UserName is :" + avatar.getUserName());
          }

          public void onException(Exception ex) {
            System.out.println("Exception Message" + ex.getMessage());
          }
        });
  }