Created
January 8, 2010 18:32
-
-
Save pocmo/272261 to your computer and use it in GitHub Desktop.
Demo of "DeckView" for Android, see Video at: http://www.youtube.com/watch?v=sv74m0Mcmms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.yaaic.deckster; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.Display; | |
import android.view.KeyEvent; | |
import android.view.View; | |
import android.widget.AdapterView; | |
import android.widget.Gallery; | |
import android.widget.Toast; | |
import android.widget.ViewSwitcher; | |
import android.widget.AdapterView.OnItemClickListener; | |
import android.widget.TableLayout.LayoutParams; | |
import android.widget.TextView; | |
public class Deckster extends Activity implements OnItemClickListener { | |
private Gallery gallery; | |
private ViewSwitcher switcher; | |
private DecksterAdapter adapter; | |
private View childView = null; | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
Display d = getWindowManager().getDefaultDisplay(); | |
int width = d.getWidth(); | |
int height = d.getHeight(); | |
adapter = new DecksterAdapter(width, height); | |
gallery = (Gallery) findViewById(R.id.gallery); | |
gallery.setAdapter(adapter); | |
//gallery.setOnClickListener(this); | |
gallery.setOnItemClickListener(this); | |
switcher = (ViewSwitcher) findViewById(R.id.switcher); | |
} | |
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { | |
Log.d("Deckster", "Selected item: " + arg2); | |
//Toast.makeText(this, "Selected: " + arg2, Toast.LENGTH_SHORT).show(); | |
childView = adapter.getView(arg2, null, gallery); | |
childView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); | |
switcher.addView(childView); | |
switcher.showNext(); | |
} | |
@Override | |
public boolean onKeyDown(int keyCode, KeyEvent event) | |
{ | |
if (keyCode == KeyEvent.KEYCODE_BACK) { | |
onBackPressed(); | |
return true; | |
} | |
return false; | |
} | |
public void onBackPressed() | |
{ | |
if (childView != null) { | |
switcher.showNext(); | |
switcher.removeView(childView); | |
switcher.showNext(); | |
childView = null; | |
Log.d("Deckster", "Back pressed"); | |
} else { | |
Log.d("Deckster", "Back pressed -> FINISH"); | |
finish(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.yaaic.deckster; | |
import android.content.Context; | |
import android.content.res.TypedArray; | |
import android.util.Log; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseAdapter; | |
import android.widget.Gallery; | |
import android.widget.TextView; | |
public class DecksterAdapter extends BaseAdapter | |
{ | |
private int width; | |
private int height; | |
public DecksterAdapter(int width, int height) | |
{ | |
this.width = width; | |
this.height = height; | |
Log.d("foo", width + "x" + height); | |
} | |
public int getCount() | |
{ | |
return 7; | |
} | |
public Object getItem(int position) | |
{ | |
return position; | |
} | |
public long getItemId(int position) | |
{ | |
return position; | |
} | |
private int[] colors = { | |
0xfffce94f, | |
0xfffcaf3e, | |
0xffe9b96e, | |
0xff8ae234, | |
0xff729fcf, | |
0xffad7fa8, | |
0xffef2929, | |
}; | |
public View getView(int position, View convertView, ViewGroup parent) | |
{ | |
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
View v = inflater.inflate(R.layout.view, null); | |
float fw = (float) width; | |
float fh = (float) height; | |
float vwf = fw / 100 * 80; | |
float vhf = fh / 100 * 80; | |
int w = (int) vwf; | |
int h = (int) vhf; | |
TextView tv = (TextView) v.findViewById(R.id.foo); | |
tv.setTextColor(0xff000000); | |
tv.setText("T" + position); | |
tv.setBackgroundColor(colors[position]); | |
v.setLayoutParams(new Gallery.LayoutParams(w, h)); | |
return v; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An enhanced version of this DeckView is part of Yaaic: http://github.com/pocmo/Yaaic