Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Iterator;
- import android.R;
- import android.widget.Adapter;
- import android.widget.AdapterView;
- import android.widget.CheckBox;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- import android.widget.LinearLayout.LayoutParams;
- import android.graphics.Color;
- import android.graphics.Typeface;
- import android.graphics.drawable.ColorDrawable;
- import android.graphics.drawable.GradientDrawable;
- import android.graphics.drawable.GradientDrawable.Orientation;
- import android.text.method.KeyListener;
- import android.view.KeyEvent;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.View.OnKeyListener;
- public class List extends Screen implements Choice {
- public Command SELECT_COMMAND = null;
- String title;
- int listType;
- int fitPolicy;
- boolean bUpdate = true;
- boolean bUpdateSelection = true;
- int iSelectedIndex = -1;
- ArrayList arrayListItems = new ArrayList();
- TextView textView;
- ListView listView;
- public List(String title, int listType) {
- this.title = title;
- this.listType = listType;
- UpdateView();
- }
- public List(String title, int listType, String[] stringElements,
- Image[] imageElements) {
- this(title, listType);
- for (int i = 0; i < stringElements.length; i++) {
- ListItem templistitem = new ListItem(stringElements[i],
- imageElements[i], false);
- if (arrayListItems.size() == 0) {
- templistitem.bSelected = true;
- }
- arrayListItems.add(templistitem);
- }
- UpdateView();
- }
- public void UpdateView() {
- bUpdate = true;
- }
- public void UpdateSelection() {
- bUpdateSelection = true;
- }
- public void UpdateDisplay() {
- if (bUpdate == true) {
- this.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
- LayoutParams.FILL_PARENT));
- this.setOrientation(LinearLayout.VERTICAL);
- this.removeAllViews();
- this.setBackgroundColor(Color.WHITE);
- textView = new TextView(UIGlobal.APP_CONTEXT);
- textView.setTypeface(UIGlobal.APP_TYPEFACE, Typeface.BOLD);
- textView.setTextSize(Font.getDefaultFont().getSize());
- textView.setTextColor(UIGlobal.TEXT_NORMAL);
- textView.setText(this.title);
- this.addView(textView, 0);
- MIDPListAdapter midplistadapter = new MIDPListAdapter(
- arrayListItems);
- listView = new ListView(UIGlobal.APP_CONTEXT);
- listView.setAdapter(midplistadapter);
- listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
- listView.setStackFromBottom(false);
- listView.setClickable(true);
- listView.setDivider(new ColorDrawable(Color.LTGRAY));
- listView.setDividerHeight(3);
- listView.setFooterDividersEnabled(true);
- listView.setHeaderDividersEnabled(true);
- listView.setCacheColorHint(00000000);
- listView.requestFocusFromTouch();
- if (arrayListItems.size() > 0) {
- listView.setSelection(0);
- setSelectedIndex(0, true);
- iSelectedIndex = 0;
- }
- AdapterView.OnItemClickListener mItemClickedHandler = new AdapterView.OnItemClickListener() {
- public void onItemClick(AdapterView parent, View v,
- int position, long id) {
- iSelectedIndex = position;
- selectItem(iSelectedIndex, true);
- }
- };
- listView.setOnItemClickListener(mItemClickedHandler);
- this.addView(listView, 1);
- bUpdate = false;
- }
- }
- public View getView() {
- if (bUpdate == true) {
- UpdateDisplay();
- }
- if (bUpdateSelection == true) {
- }
- return this;
- }
- public void RefreshList() {
- System.out.println(" RefreshList iSelectedIndex " + iSelectedIndex);
- for (int i = 0; i < arrayListItems.size(); i++) {
- ListItem templistitem = (ListItem) arrayListItems.get(i);
- if (i != iSelectedIndex) {
- if (templistitem.bSelected == true) {
- templistitem.bSelected = false;
- arrayListItems.set(i, templistitem);
- }
- } else {
- if (templistitem.bSelected == false) {
- templistitem.bSelected = true;
- arrayListItems.set(i, templistitem);
- }
- }
- }
- }
- public int append(String stringPart, Image imagePart) {
- ListItem templistitem = new ListItem(stringPart, imagePart, false);
- if (arrayListItems.size() == 0) {
- templistitem.bSelected = true;
- }
- arrayListItems.add(templistitem);
- UpdateView();
- return (arrayListItems.size() - 1);
- }
- public void delete(int elementNum) {
- arrayListItems.remove(elementNum);
- UpdateView();
- }
- public void deleteAll() {
- arrayListItems.clear();
- UpdateView();
- }
- public void addCommand(Command cmd) {
- super.addCommand(cmd);
- if (cmd.getLabel().toUpperCase().equals("NEXT")
- || cmd.getLabel().toUpperCase().equals("SELECT")) // First
- // command
- // is linked
- // to Select
- // Command
- {
- SELECT_COMMAND = cmd;
- }
- }
- public Image getImage(int elementNum) {
- ListItem templistitem = (ListItem) arrayListItems.get(elementNum);
- return templistitem.imagePart;
- }
- public int getSelectedFlags(boolean[] selectedArray_return) {
- RefreshList();
- int intSelectedCount = 0;
- int i = 0;
- Iterator itr = arrayListItems.iterator();
- while (itr.hasNext()) {
- ListItem templistitem = (ListItem) itr.next();
- selectedArray_return[i] = templistitem.bSelected;
- if (templistitem.bSelected) {
- intSelectedCount++;
- }
- }
- return intSelectedCount;
- }
- public int getSelectedIndex() {
- RefreshList();
- return iSelectedIndex;
- }
- public String getString(int elementNum) {
- ListItem templistitem = (ListItem) arrayListItems.get(elementNum);
- return templistitem.stringPart;
- }
- public void insert(int elementNum, String stringPart, Image imagePart) {
- ListItem templistitem = new ListItem(stringPart, imagePart, false);
- arrayListItems.add(elementNum, templistitem);
- UpdateView();
- }
- public boolean isSelected(int elementNum) {
- RefreshList();
- ListItem templistitem = (ListItem) arrayListItems.get(elementNum);
- return templistitem.bSelected;
- }
- public void set(int elementNum, String stringPart, Image imagePart) {
- ListItem templistitem = new ListItem(stringPart, imagePart, false);
- arrayListItems.set(elementNum, templistitem);
- UpdateView();
- }
- public void setSelectCommand(Command command) {
- SELECT_COMMAND = command;
- }
- public void setSelectedFlags(boolean[] selectedArray) {
- for (int i = 0; i < arrayListItems.size(); i++) {
- ListItem templistitem = (ListItem) arrayListItems.get(i);
- if (templistitem.bSelected != selectedArray[i]) {
- templistitem.bSelected = selectedArray[i];
- arrayListItems.set(i, templistitem);
- }
- }
- }
- public void setTitle(String s) {
- this.title = s;
- }
- public int size() {
- return arrayListItems.size();
- }
- public void selectItem(int elementNum, boolean selected) {
- setSelectedIndex(elementNum, selected);
- if ((this.commandListener != null) && (SELECT_COMMAND != null)) {
- this.commandListener.commandAction(SELECT_COMMAND, this);
- } else if ((this.commandListener != null) && (aListCommands.size() > 1)) {
- this.commandListener.commandAction((Command) aListCommands.get(0),
- this);
- }
- }
- @Override
- public void setSelectedIndex(int elementNum, boolean selected) {
- for (int i = 0; i < arrayListItems.size(); i++) {
- ListItem templistitem = (ListItem) arrayListItems.get(i);
- if (elementNum == i) {
- templistitem.bSelected = selected;
- arrayListItems.set(i, templistitem);
- } else {
- if (selected == true) {
- if (templistitem.bSelected == true) // Make all other
- // selection false
- {
- templistitem.bSelected = false;
- arrayListItems.set(i, templistitem);
- }
- }
- }
- }
- iSelectedIndex = elementNum;
- }
- @Override
- public int getFitPolicy() {
- return fitPolicy;
- }
- @Override
- public void setFitPolicy(int fitPolicy) {
- this.fitPolicy = fitPolicy;
- }
- public void SelectNextItem() {
- int iCurrentlySelectedIndex = iSelectedIndex;
- if (iCurrentlySelectedIndex == (arrayListItems.size() - 1)) {
- setSelectedIndex(0, true);
- } else {
- setSelectedIndex(iCurrentlySelectedIndex + 1, true);
- }
- }
- public void SelectPreviousItem() {
- int iCurrentlySelectedIndex = iSelectedIndex;
- if (iCurrentlySelectedIndex == 0) {
- setSelectedIndex(arrayListItems.size() - 1, true);
- } else {
- setSelectedIndex(iCurrentlySelectedIndex - 1, true);
- }
- }
- @Override
- public Font getFont(int elementNum) {
- return null;
- }
- @Override
- public void setFont(int elementNum, Font font) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement