📄 simplelist.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3)
// Source File Name: SimpleList.java
package com.sonyericsson.fb.ui.fbComponents;
import java.util.Vector;
import se.southend.drops.gui.BitmapSprite;
import se.southend.drops.integeraffector.*;
import se.southend.drops.scene.Group;
import se.southend.drops.scene.Node;
import se.southend.drops.screen.KeyHandler;
// Referenced classes of package com.sonyericsson.fb.ui.fbComponents:
// ListItem
public class SimpleList extends Group
{
public SimpleList()
{
mSelectorFollow = null;
mFirstFocusable = -1;
mFireIsDown = false;
mItems = new Group();
mSelectorGroup = new Group();
mSelectorGroup.setVisible(false);
mBackground = new Group();
add(mBackground);
add(mSelectorGroup);
add(mItems);
mWrapEnabled = true;
}
public void setSelector(BitmapSprite selector)
{
if(selector != null)
{
mSelector = selector;
mSelectorGroup.add(selector);
mSelectorFollow = new FollowAffector(1) {
public void run()
{
mSelector.setWorldPosition(0, getValue());
}
};
mSelectorFollow.setSourceSpeed(20);
AffectorHandler.getInstance().addAffector(mSelectorFollow);
}
}
public int indexOf(ListItem item)
{
return mItems.getChildren().indexOf(item);
}
public ListItem get(int index)
{
return (ListItem)mItems.getChild(index);
}
public boolean isEmpty()
{
return mItems.getChildCount() == 0;
}
public void next()
{
if(isEmpty())
return;
int newIndex = mCurrent != mItems.getChildCount() - 1 ? mCurrent + 1 : 0;
if(!mWrapEnabled && newIndex == 0)
return;
if(((ListItem)mItems.getChild(newIndex)).isFocusable())
{
if(newIndex < mCurrent)
select(newIndex, true);
else
select(newIndex, false);
} else
if(mFirstFocusable != -1)
{
mCurrent = newIndex;
next();
}
}
public void previous()
{
if(isEmpty())
return;
int newIndex = mCurrent != 0 ? mCurrent - 1 : mItems.getChildCount() - 1;
if(!mWrapEnabled && newIndex == mItems.getChildCount() - 1)
return;
if(((ListItem)mItems.getChild(newIndex)).isFocusable())
{
if(newIndex > mCurrent)
select(newIndex, true);
else
select(newIndex, false);
} else
if(mFirstFocusable != -1)
{
mCurrent = newIndex;
previous();
}
}
public void select(ListItem item, boolean instant)
{
if(mItems.getChildren().contains(item))
select(mItems.getChildren().indexOf(item), instant);
}
public void selectFirst()
{
select(mFirstFocusable, true);
}
public void select(int index, boolean instant)
{
if(mCurrentItem != null)
mCurrentItem.setFocused(false);
if(mSelector != null)
if(instant)
mSelectorFollow.setSourceSpeed(64);
else
mSelectorFollow.setSourceSpeed(20);
ListItem item = (ListItem)mItems.getChild(index);
mCurrent = index;
mCurrentItem = item;
mCurrentItem.setFocused(true);
if(mSelector != null)
mSelectorFollow.setTargetPosition(new int[] {
mCurrentItem.getLocalY()
});
}
public void add(ListItem item)
{
int yPos;
if(isEmpty())
{
yPos = item.getHeight() / 2;
mSelectorGroup.setVisible(true);
} else
{
ListItem lastItem = (ListItem)mItems.getChild(mItems.getChildCount() - 1);
yPos = lastItem.getLocalY() + (lastItem.getHeight() / 2 + item.getHeight() / 2 << 8);
}
item.setListPosition(yPos);
mItems.add(item);
if(mFirstFocusable == -1 && item.isFocusable())
mFirstFocusable = mItems.getChildCount() - 1;
}
public void remove(ListItem item)
{
int listIndex = -1;
int i = 0;
do
{
if(i >= mItems.getChildCount())
break;
if(mItems.getChild(i) == item)
{
listIndex = i;
break;
}
i++;
} while(true);
if(listIndex < 0)
return;
mItems.remove(item);
if(mFirstFocusable == listIndex)
mFirstFocusable = -1;
if(mCurrentItem == item)
{
item.setFocused(false);
mCurrentItem = null;
mCurrent = 0;
} else
if(mCurrent > listIndex)
mCurrent--;
for(i = listIndex; i < mItems.getChildCount(); i++)
{
ListItem oldItem = (ListItem)mItems.getChild(i);
int yPos;
if(isEmpty())
{
yPos = oldItem.getHeight() / 2;
} else
{
ListItem lastItem = (ListItem)mItems.getChild(mItems.getChildCount() - 1);
yPos = lastItem.getLocalY() + (lastItem.getHeight() / 2 + oldItem.getHeight() / 2 << 8);
}
oldItem.setListPosition(yPos);
if(mFirstFocusable == -1 && oldItem.isFocusable())
mFirstFocusable = i;
}
}
public boolean input(KeyHandler keyHandler)
{
boolean handled = false;
if(keyHandler.wasPressed(16))
{
if(mFireIsDown)
return true;
mFireIsDown = true;
} else
if(!keyHandler.isHeld(16))
mFireIsDown = false;
if(mItems.getChildCount() > 0)
handled = ((ListItem)mItems.getChild(mCurrent)).input(keyHandler);
if(!handled)
{
if(keyHandler.wasPressed(8))
{
next();
return true;
}
if(keyHandler.wasPressed(4))
{
previous();
return true;
}
}
return false;
}
public int getSize()
{
return mItems.getChildCount();
}
public void setWrappingEnabled(boolean enabled)
{
mWrapEnabled = enabled;
}
public BitmapSprite getSelector()
{
return mSelector;
}
protected Group getItems()
{
return mItems;
}
protected Group getBackground()
{
return mBackground;
}
public ListItem getCurrentItem()
{
return mCurrentItem;
}
public int getCurrentIndex()
{
return mCurrent;
}
private Group mItems;
private Group mSelectorGroup;
private BitmapSprite mSelector;
private Group mBackground;
private int mCurrent;
private ListItem mCurrentItem;
private boolean mWrapEnabled;
private FollowAffector mSelectorFollow;
private int mFirstFocusable;
private boolean mFireIsDown;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -