GalleryActivity.java :  » Game » bimbodroid » com » bimbodroid » Android Open Source

Android Open Source » Game » bimbodroid 
bimbodroid » com » bimbodroid » GalleryActivity.java
package com.bimbodroid;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class GalleryActivity extends Activity {;
  
  private int [] content;
  private int[] price; 
  private int selected = 0;
  private int funds;
  private String action;
  
  public void UpdateData(int position){
    selected = position;
    ((TextView)findViewById(R.id.price)).setText("Price :" + String.valueOf(price[position]) + "$");
    ((ImageView)findViewById(R.id.pic)).setImageResource(content[position]);
  }
  
  public void SendReturnData(){
    Intent result = new Intent();
    result.putExtra("selected", selected);
    result.putExtra("action", action);
    setResult(RESULT_OK,result);
    finish();
  }
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallery);
    // Get args
    Bundle args = getIntent().getExtras();
    this.content = args.getIntArray("content");
    this.price = args.getIntArray("price");
    this.funds = args.getInt("funds");
    this.action = args.getString("action");
    // Set the gallery item
    Gallery g = (Gallery)findViewById(R.id.gallery);
    g.setAdapter(new ImageAdapter(this,content));
    g.setOnItemSelectedListener(new OnItemSelectedListener(){
      @Override
      public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {
        GalleryActivity.this.UpdateData(position);
      }
      @Override
      public void onNothingSelected(AdapterView<?> arg0) {}
    });
    // Set the action button
    Button b = (Button)findViewById(R.id.select);
    b.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View clicked) {
        @SuppressWarnings("unused")
        int p = GalleryActivity.this.price[GalleryActivity.this.selected];
        @SuppressWarnings("unused")
        boolean b = GalleryActivity.this.funds < GalleryActivity.this.price[GalleryActivity.this.selected];
        if (GalleryActivity.this.funds < GalleryActivity.this.price[GalleryActivity.this.selected]) 
          Toast.makeText(clicked.getContext(), "Insufficient Funds", Toast.LENGTH_LONG).show();
        else GalleryActivity.this.SendReturnData();
      }
    });
    // Init element
    UpdateData(0);  
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.