Android Open Source - Xbox360CollectorsPlace Edit Achievements Activity






From Project

Back to project page Xbox360CollectorsPlace.

License

The source code is released under:

MIT License

If you think the Android project Xbox360CollectorsPlace listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.xboxcollectorsplace.ui;
/* ww w  .  jav a  2  s  . com*/
import com.xboxcollectorsplace.R;
import com.xboxcollectorsplace.bl.BLParameters;
import com.xboxcollectorsplace.utils.XLog;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * Windowed activity, used to edit the number of unlocked achievements of a game. It only contains 
 * a Button and an EditText, which contains a listener that prevents from entering a number bigger
 * than the total number of achievements of the game
 */
public class EditAchievementsActivity extends Activity implements OnClickListener 
{
  //------------------------------------------------------------------------- ATTRIBUTES*/
  
  private EditText _edtAchievements;
  private Button _btnOK;
  
  private int _totalAchievements;
  
  //------------------------------------------------------------------------- ON CREATE*/
  
    public void onCreate(Bundle savedInstanceState) 
    {
      try
      {
          super.onCreate(savedInstanceState);          
          setContentView(R.layout.activity_edit_achievements);
             
          this._edtAchievements = (EditText) this.findViewById(R.id.edtAchievements);
          this._btnOK = (Button) this.findViewById(R.id.btnOK);
                    
          if (this.getIntent().getExtras().containsKey(BLParameters.PARAMETERS.TOTAL_ACHIEVEMENTS))
      {
            this._totalAchievements = this.getIntent().getExtras().getInt(BLParameters.PARAMETERS.TOTAL_ACHIEVEMENTS, 0);
          }
          
          if (this.getIntent().getExtras().containsKey(BLParameters.PARAMETERS.CURRENT_ACHIEVEMENTS))
      {
            this._edtAchievements.setText(String.valueOf(this.getIntent().getExtras().getInt(BLParameters.PARAMETERS.CURRENT_ACHIEVEMENTS, 0)));
            
            if ("0".equals(this._edtAchievements.getText().toString()))
          {
              this._edtAchievements.setText("");
          }
            
            this._edtAchievements.setSelection(this._edtAchievements.length());
          }
          
          this._btnOK.setOnClickListener(this);
          this._edtAchievements.addTextChangedListener(new TextWatcher() 
          {
        public void onTextChanged(CharSequence s, int start, int before, int count) 
        {
        }
        
        public void beforeTextChanged(CharSequence s, int start, int count, int after) 
        {
        }
        
        public void afterTextChanged(Editable s) 
        {
          if (!TextUtils.isEmpty(_edtAchievements.getText().toString()))
          {
            int selectedAchievements = Integer.valueOf(_edtAchievements.getText().toString());
            
            if (selectedAchievements < 0)
            {
              _edtAchievements.setText("0");
              _edtAchievements.setSelection(_edtAchievements.length());
            }
            else if (selectedAchievements > _totalAchievements)
            {
              _edtAchievements.setText(String.valueOf(_totalAchievements));
              _edtAchievements.setSelection(_edtAchievements.length());
            }
          }
        }
      });
      }
      catch (Exception ex)
    {
      XLog.e("[EditAchievementsActivity.onCreate]", ex);
        }
    }
    
    //------------------------------------------------------------------------- EVENTS*/
  
    /**
     * Event related to the touch of the OK button. Returns the new value to the caller activity
     */
  public void onClick(View view)
  {
    try
    {
      if (view.getId() == this._btnOK.getId())
      {
        Intent output = new Intent();
        output.putExtra(BLParameters.PARAMETERS.CURRENT_ACHIEVEMENTS, !TextUtils.isEmpty(this._edtAchievements.getText().toString()) ? Integer.valueOf(this._edtAchievements.getText().toString()) : 0);
        this.setResult(RESULT_OK, output);
        this.finish();
      }
    }
    catch (Exception ex)
    {
      XLog.e("[EditAchievementsActivity.onClick]", ex);
    }
  }
}




Java Source Code List

com.xboxcollectorsplace.App.java
com.xboxcollectorsplace.bl.BLParameters.java
com.xboxcollectorsplace.bl.BLUtils.java
com.xboxcollectorsplace.bl.controllers.StorageController.java
com.xboxcollectorsplace.bl.entities.Catalog.java
com.xboxcollectorsplace.bl.entities.DLC.java
com.xboxcollectorsplace.bl.entities.Filters.java
com.xboxcollectorsplace.bl.entities.GamePhotoGallery.java
com.xboxcollectorsplace.bl.entities.GamePhoto.java
com.xboxcollectorsplace.bl.entities.Game.java
com.xboxcollectorsplace.bl.entities.Link.java
com.xboxcollectorsplace.bl.entities.OptionString.java
com.xboxcollectorsplace.bl.entities.Options.java
com.xboxcollectorsplace.bl.entities.SelectionFile.java
com.xboxcollectorsplace.bl.entities.Sort.java
com.xboxcollectorsplace.bl.extension.XboxAlarmReceiver.java
com.xboxcollectorsplace.bl.extension.XboxDownloaderService.java
com.xboxcollectorsplace.bl.extension.XboxInitialDownload.java
com.xboxcollectorsplace.ui.CatalogActivity.java
com.xboxcollectorsplace.ui.CollectionActivity.java
com.xboxcollectorsplace.ui.ConfigActivity.java
com.xboxcollectorsplace.ui.EditAchievementsActivity.java
com.xboxcollectorsplace.ui.EditPhotoTitleActivity.java
com.xboxcollectorsplace.ui.FileSelectorActivity.java
com.xboxcollectorsplace.ui.FilterSortActivity.java
com.xboxcollectorsplace.ui.GameDetailActivity.java
com.xboxcollectorsplace.ui.GoToActivity.java
com.xboxcollectorsplace.ui.PhotoGalleryActivity.java
com.xboxcollectorsplace.ui.SummaryActivity.java
com.xboxcollectorsplace.ui.SynopsisDetailActivity.java
com.xboxcollectorsplace.ui.TitleScreenActivity.java
com.xboxcollectorsplace.utils.JustifiedTextView.java
com.xboxcollectorsplace.utils.XComparator.java
com.xboxcollectorsplace.utils.XLog.java