Advertisement
Nolesh

LibGDX MyLazyImageList

Apr 10th, 2013
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.29 KB | None | 0 0
  1. package ru.nolesh.libgdx.extension;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import java.net.HttpURLConnection;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. import java.util.ArrayList;
  11. import java.util.HashMap;
  12. import java.util.List;
  13. import java.util.Map;
  14.  
  15. import com.badlogic.gdx.Gdx;
  16. import com.badlogic.gdx.files.FileHandle;
  17. import com.badlogic.gdx.graphics.Color;
  18. import com.badlogic.gdx.graphics.Pixmap;
  19. import com.badlogic.gdx.graphics.Texture;
  20. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  21. import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
  22. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  23. import com.badlogic.gdx.scenes.scene2d.InputEvent;
  24. import com.badlogic.gdx.scenes.scene2d.InputListener;
  25. import com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle;
  26. import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
  27. import com.badlogic.gdx.scenes.scene2d.ui.Widget;
  28. import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
  29. import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
  30. import com.badlogic.gdx.utils.GdxRuntimeException;
  31. import com.badlogic.gdx.utils.Pools;
  32.  
  33. /**
  34.  * Extended list with headers. It allows to load images from URL in lazy mode.
  35.  * @author Nolesh
  36.  */
  37. public class MyLazyImageList extends ScrollPane{
  38.        
  39.     public static final String SEPARATOR = "/*~*/";
  40.     private static final String SEPARATOR_TEMPLATE = "/\\*~\\*/";
  41.     private static final int MAX_THREAD_AMOUNT = 2;
  42.     private volatile static int threadAmount;
  43.    
  44.     private MyRawList rawList;
  45.     private boolean isEnabled;
  46.     private String emptyLabel;
  47.     private Texture placeholder;
  48.     private String headers[];
  49.     private Drawable headersBackground;
  50.     private Color headersColor;
  51.     private boolean useLocalStorage;   
  52.        
  53.     /**
  54.      * Constructor
  55.      * @param items To create items use MyLazyImageListItem.formItems(names, urls)
  56.      * @param style
  57.      * @param listStyle
  58.      * @param placeholder It must not be empty!
  59.      * @param useLocalStorage If true, downloaded images are stored relative to private storage of the app.
  60.      *          Otherwise, they are stored relative to SD card root (Neends WRITE_EXTERNAL_STORAGE permission).    
  61.      */
  62.     public MyLazyImageList(MyLazyImageListItem[] items, ScrollPaneStyle style,
  63.             ListStyle listStyle, Texture placeholder, boolean useLocalStorage){    
  64.         super(null, style);
  65.         isEnabled = true;
  66.         rawList = new MyRawList(items, listStyle, this);
  67.         setWidget(rawList);
  68.         setWidth(rawList.getPrefWidth());
  69.         setHeight(rawList.getPrefHeight());
  70.         setScrollingDisabled(true, false); 
  71.         emptyLabel = "There are no any items";
  72.         if(placeholder==null)
  73.             throw new IllegalArgumentException("Placeholder must not be empty!");
  74.         this.placeholder=placeholder;
  75.         this.useLocalStorage = useLocalStorage;
  76.         threadAmount=0;
  77.     }
  78.                
  79.     public boolean isEnabled() {
  80.         return isEnabled;
  81.     }
  82.  
  83.     public void setEnabled(boolean isEnabled) {
  84.         this.isEnabled = isEnabled;    
  85.     }
  86.        
  87.     public void setItems(MyLazyImageListItem[] items){
  88.         rawList.setItems(items);
  89.     }
  90.    
  91.     public void setSelectedIndex(int index){
  92.         rawList.setSelectedIndex(index);
  93.     }
  94.    
  95.     public int getSelectedIndex(){
  96.         if(isEnabled) return rawList.getSelectedIndex();
  97.         else return -1;
  98.     }
  99.    
  100.     public String getEmptyLabel() {
  101.         return emptyLabel;
  102.     }
  103.  
  104.     public void setEmptyLabel(String emptyLabel) {
  105.         this.emptyLabel = emptyLabel;
  106.     }
  107.    
  108.     public String[] getHeaders() {
  109.         return headers;
  110.     }
  111.  
  112.     /**
  113.      * Sets the headers
  114.      * @param headers String of headers (Use SEPARATOR to concatenate headers to each other)
  115.      * @param background - Must be not null!
  116.      */
  117.     public void setHeaders(String headers, Drawable background) {
  118.         if(background==null) throw new IllegalArgumentException("Background must be not null!");
  119.         this.headers = headers.split(SEPARATOR_TEMPLATE);      
  120.         headersBackground = background;
  121.     }
  122.  
  123.     public Color getHeadersColor() {
  124.         return headersColor;
  125.     }
  126.  
  127.     public void setHeadersColor(Color headersColor) {
  128.         this.headersColor = headersColor;
  129.     }
  130.                            
  131.     /******************** RAW LIST ************************/
  132.     public class MyRawList extends Widget{
  133.        
  134.         private MyLazyImageList myLazyImageList;
  135.         private ListStyle style;
  136.         private MyLazyImageListItem[] items;
  137.         private int selectedIndex; 
  138.         private float prefWidth, prefHeight;
  139.         private float itemHeight;
  140.         private float textOffsetX, textOffsetY;
  141.         private float coefH;
  142.         private float coefW;
  143.        
  144.         private Map<String, Texture> cache;  
  145.         private Map<String, Texture> tempCache;  
  146.            
  147.         private int imageWidth = 35, imageHeight = 26;  
  148.        
  149.        
  150.         public MyRawList (MyLazyImageListItem[] items, ListStyle style, MyLazyImageList myLazyImageList) {
  151.             coefH = (float)Gdx.graphics.getHeight()/320;
  152.             coefW = (float)Gdx.graphics.getWidth()/480;
  153.             setStyle(style);
  154.             setItems(items);
  155.             setWidth(getPrefWidth());
  156.             setHeight(getPrefHeight());    
  157.             this.myLazyImageList=myLazyImageList;
  158.  
  159.             cache = new HashMap<String, Texture>();            
  160.             tempCache = new HashMap<String, Texture>();
  161.            
  162.             addListener(new InputListener() {
  163.                 public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
  164.                     if(!isEnabled) return false;
  165.                     if (pointer == 0 && button != 0) return false;
  166.                     MyRawList.this.touchDown(y);
  167.                     return true;
  168.                 }
  169.             });        
  170.         }
  171.        
  172.  
  173.         protected void setItemIntoCache(String url, Texture texture){          
  174.             cache.put(url, texture);           
  175.         }
  176.            
  177.        
  178.         volatile List<String> beingDownloaded = new ArrayList<String>();
  179.         volatile List<String> downloaded = new ArrayList<String>();
  180.                                
  181.         private FileHandle getFileHandleFromURL(URL url){
  182.             String filename = url.getFile();
  183.             String[] splitter = filename.split("/");
  184.             filename = splitter[splitter.length-1];        
  185.             FileHandle fileHandle = useLocalStorage ? Gdx.files.local(filename) : Gdx.files.external(filename);        
  186.             return fileHandle;
  187.         }
  188.            
  189.         protected Texture getTexture(MyLazyImageListItem item){
  190.            
  191.             Texture texture = getTextureFromCache(item.url.toString());
  192.             if(texture!=null){             
  193.                 return texture;
  194.             }
  195.             FileHandle image = getFileHandleFromURL(item.url);         
  196.             if(image.exists()&&downloaded.contains(item.url.toString())
  197.                     &&!beingDownloaded.contains(item.url.toString())){             
  198.                 InputStream is = image.read();
  199.                 DataInputStream dis = new DataInputStream(is);
  200.                 byte[] data = new byte[(int)image.length()];
  201.                 try {
  202.                     dis.readFully(data);
  203.                     dis.close();
  204.                     image.delete();
  205.                     Gdx.app.log("MyLazyImageList", "Size of '"+item.url.toString()+"': "+data.length);
  206.                     setItemIntoCache(item.url.toString(), new Texture(new Pixmap(data, 0, data.length)));
  207.                     return getTextureFromCache(item.url.toString());
  208.                 } catch (IOException e) {}             
  209.             }
  210.                        
  211.             asyncDownloadTextureFromURL(item.url, image);          
  212.                        
  213.             return placeholder;
  214.         }
  215.        
  216.         protected void clearTextureCache(int from, int to) {  
  217.             List<String> temp = new ArrayList<String>();
  218.             for(int i = from; i<=to; i++){
  219.                 if(!temp.contains(items[i].url.toString())&&downloaded.contains(items[i].url.toString())){
  220.                     temp.add(items[i].url.toString());                 
  221.                 }
  222.             }
  223.            
  224.             downloaded.clear();
  225.             downloaded.addAll(temp);
  226.            
  227.             for(String key : downloaded){
  228.                 if(cache.containsKey(key)){
  229.                     tempCache.put(key, cache.get(key));                
  230.                 }
  231.             }
  232.             cache.clear();
  233.             cache.putAll(tempCache);           
  234.             tempCache.clear();
  235.         }  
  236.        
  237.         protected Texture getTextureFromCache(String url) {            
  238.             if (cache.containsKey(url)) {  
  239.                 return cache.get(url);
  240.             }
  241.             return null;  
  242.         }  
  243.            
  244.                
  245.         protected void asyncDownloadTextureFromURL(final URL url, final FileHandle image) {            
  246.            
  247.             if(beingDownloaded.contains(url.toString())) return;           
  248.             if(threadAmount>=MAX_THREAD_AMOUNT) return;
  249.             threadAmount++;
  250.             new Thread(new Runnable() {            
  251.                 @Override
  252.                 public void run() {                
  253.                     beingDownloaded.add(url.toString());
  254.                    
  255.                     Gdx.app.log("MyLazyImageList", "Downloading started: "+url.toString());
  256.                     Pixmap pixmap = syncDownloadPixmapFromURL(url);
  257.                     if(image.exists()) image.delete();
  258.                     if(pixmap==null){
  259.                         beingDownloaded.remove(url.toString());
  260.                         threadAmount--;
  261.                         return;
  262.                     }
  263.                     OutputStream stream = image.write(false);
  264.                     try {
  265.                 /**
  266.                 *TO GET PNG ENCODER CLASS FOLLOW TO: http://pastebin.com/psF60D8Q
  267.                 **/
  268.                         byte[] bytes = PNG.toPNG(pixmap);
  269.                        
  270.                         stream.write(bytes);
  271.                         stream.close();
  272.                         Gdx.app.log("MyLazyImageList", "Downloading stopped: "+url.toString());
  273.                        
  274.                         if(!downloaded.contains(url.toString()))
  275.                             downloaded.add(url.toString());
  276.                         beingDownloaded.remove(url.toString());
  277.                     } catch (IOException e) {}
  278.                     finally{
  279.                         threadAmount--;
  280.                     }
  281.                 }
  282.             }).start();
  283.            
  284.         }  
  285.        
  286.         private Pixmap syncDownloadPixmapFromURL(URL url) {  
  287.                 try {
  288.                     HttpURLConnection conn= (HttpURLConnection)url.openConnection();
  289.                     conn.setDoInput(true);
  290.                     conn.connect();
  291.                     int length = conn.getContentLength();  
  292.                     if(length<=0) return null;
  293.                     InputStream is = conn.getInputStream();
  294.                     DataInputStream dis = new DataInputStream(is);
  295.                     byte[] data = new byte[length];
  296.                     dis.readFully(data);
  297.                     Pixmap pixmap = new Pixmap(data, 0, data.length);
  298.                     pixmap = ImagePow2.isPow2(pixmap)?pixmap:ImagePow2.getPow2Pixmap(pixmap);
  299.                     return pixmap;                   
  300.                      
  301.                 } catch (MalformedURLException e) {  
  302.                     e.printStackTrace();  
  303.                 } catch (IOException e) {  
  304.                     e.printStackTrace();  
  305.                 }  
  306.                 return null;
  307.          }      
  308.        
  309.         void touchDown (float y) {
  310.             int oldIndex = selectedIndex;
  311.             selectedIndex = (int)((getHeight() - y) / itemHeight);
  312.             selectedIndex = Math.max(0, selectedIndex);
  313.             selectedIndex = Math.min(items.length - 1, selectedIndex);
  314.             ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
  315.             if (fire(changeEvent)) selectedIndex = oldIndex;
  316.             Pools.free(changeEvent);
  317.         }
  318.  
  319.         public void setStyle (ListStyle style) {
  320.             if (style == null) throw new IllegalArgumentException("style cannot be null.");
  321.             this.style = style;
  322.             if (items != null)
  323.                 setItems(items);
  324.             else
  325.                 invalidateHierarchy();
  326.         }
  327.  
  328.         /** Returns the list's style. Modifying the returned style may not have an effect until {@link #setStyle(ListStyle)} is called. */
  329.         public ListStyle getStyle () {
  330.             return style;
  331.         }
  332.  
  333.         int startIndex = 0;
  334.         int lastVisibleIndex = 0;
  335.                
  336.         @Override
  337.         public void draw (SpriteBatch batch, float parentAlpha) {
  338.            
  339.             BitmapFont font = style.font;
  340.             Drawable selectedDrawable = style.selection;
  341.             Color fontColorSelected = style.fontColorSelected;
  342.             Color fontColorUnselected = style.fontColorUnselected;
  343.  
  344.             float x = getX();
  345.             float y = getY();
  346.            
  347.             Color color = getColor();
  348.             parentAlpha*=getColor().a;     
  349.             batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
  350.            
  351.             font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha);
  352.             float itemY = getHeight();
  353.                        
  354.             //Makes offset for headers
  355.             if(headers!=null && !headers.equals("")){          
  356.                 itemY -= itemHeight/3 + (textOffsetY/3)*coefH - font.getBounds(headers[0]).height/2;               
  357.             }
  358.            
  359.             if(items==null){
  360.                 float centerX = myLazyImageList.getWidth()/2;
  361.                 float centerY = myLazyImageList.getHeight()/2;
  362.                 font.draw(batch, emptyLabel, centerX - font.getBounds(emptyLabel).width/2,
  363.                         centerY+font.getBounds(emptyLabel).height/2);
  364.                        
  365.                 return;
  366.             }
  367.            
  368.             boolean isSetLastVisibleIndex = true;
  369.             for (int i = 0; i < items.length; i++) {
  370.                 boolean isDrawn = true;
  371.                                
  372.                 if(getHeight()-itemY<myLazyImageList.getScrollY()-itemHeight){
  373.                     startIndex=i;
  374.                     isDrawn=false;
  375.                 }              
  376.                 if(getHeight()-itemY>myLazyImageList.getScrollY()+myLazyImageList.getHeight()){                
  377.                     if(isSetLastVisibleIndex) lastVisibleIndex=i;                  
  378.                     isSetLastVisibleIndex = false;
  379.                     isDrawn=false;
  380.                 }
  381.                
  382.                 if(isDrawn){                       
  383.                     if (selectedIndex == i && selectedIndex!=-1) {                     
  384.                             selectedDrawable.draw(batch, x, y + itemY - itemHeight, getWidth(), itemHeight);
  385.                             font.setColor(fontColorSelected.r, fontColorSelected.g,
  386.                                     fontColorSelected.b, fontColorSelected.a * parentAlpha);
  387.                        
  388.                     }
  389.                     else{                      
  390.                             font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b,
  391.                                     fontColorUnselected.a * parentAlpha);
  392.                        
  393.                     }
  394.                                                        
  395.                     String[] elements = items[i].name.split(SEPARATOR_TEMPLATE);
  396.                     float equalPartWidth = getWidth()/(elements.length+1);
  397.                    
  398.                     for(int j=0; j<elements.length; j++){
  399.                         String shortName = cutName(font, elements[j], (int)(equalPartWidth));
  400.                         if(shortName.equals(elements[j]))
  401.                             font.draw(batch, elements[j]
  402.                                     , x + textOffsetX +equalPartWidth*(j)+(equalPartWidth-font.getBounds(elements[j]).width)/2,
  403.                                     y + itemY - textOffsetY*coefH - font.getBounds(items[i].showName).height/2);
  404.                         else
  405.                             font.draw(batch, shortName
  406.                                 , x + textOffsetX + equalPartWidth*(j),
  407.                                 y + itemY - textOffsetY*coefH - font.getBounds(items[i].showName).height/2);
  408.                     }
  409.                    
  410.                     Texture tempTexture = getTexture(items[i]);
  411.                     if(tempTexture!=null)
  412.                     batch.draw(tempTexture, x + textOffsetX +equalPartWidth*(elements.length)+(equalPartWidth-imageWidth)/2,
  413.                             y + itemY-textOffsetY*coefH/2-imageHeight , imageWidth, imageHeight);      
  414.                 }
  415.                                    
  416.                 itemY -= itemHeight;
  417.             }
  418.            
  419.             //Drawing headers          
  420.             if(headers!=null && !headers.equals("")){  
  421.                 float height = font.getBounds(headers[0]).height + 6*coefH;                            
  422.                 headersBackground.draw(batch, 0, myLazyImageList.getHeight()-height, myLazyImageList.getWidth(), height);
  423.                
  424.                 float equalPartWidthForHeader = getWidth()/headers.length;
  425.                 font.setColor(headersColor==null?fontColorSelected:headersColor);
  426.                
  427.                 for(int k=0; k<headers.length; k++){
  428.                     font.draw(batch, headers[k], x+ textOffsetX + equalPartWidthForHeader*(k)
  429.                             + (equalPartWidthForHeader-font.getBounds(headers[k]).width)/2,
  430.                             myLazyImageList.getHeight()-3*coefH);
  431.                 }              
  432.             }
  433.            
  434.             clearTextureCache(startIndex, lastVisibleIndex);
  435.         }
  436.        
  437.         private String cutName(BitmapFont font, String name, int width){
  438.             if(font.getBounds(name).width<=width) return name;
  439.             String tempName = name;
  440.             while(true){
  441.                 if(font.getBounds(tempName+"...").width>width){
  442.                     if(tempName.length()<3) break;
  443.                     tempName=tempName.substring(0, tempName.length()-2);               
  444.                 }
  445.                 else break;
  446.             }
  447.             return tempName+"...";
  448.         }
  449.  
  450.         /** @return The index of the currently selected item. The top item has an index of 0. */
  451.         public int getSelectedIndex () {
  452.             return selectedIndex;
  453.         }
  454.  
  455.         public void setSelectedIndex (int index) {
  456.             if(index==-1) { selectedIndex = -1; return; }
  457.             if(items==null) throw new GdxRuntimeException("There are no any items!");
  458.             if (index < -1 || index >= items.length)               
  459.                 throw new GdxRuntimeException("index must be >= -1 and < " + items.length + ": " + index);
  460.             selectedIndex = index;
  461.         }
  462.  
  463.         /** @return The text of the currently selected item or null if the list is empty. */
  464.         public MyLazyImageListItem getSelection () {
  465.             if(items==null) return null;
  466.             if (items.length == 0) return null;
  467.             return items[selectedIndex];
  468.         }
  469.  
  470.         /** @return The index of the item that was selected, or -1. */
  471.         public int setSelection (String item) {
  472.             selectedIndex = -1;
  473.             if(items==null) return -1;
  474.             for (int i = 0, n = items.length; i < n; i++) {
  475.                 if (items[i].equals(item)) {
  476.                     selectedIndex = i;
  477.                     break;
  478.                 }
  479.             }
  480.             return selectedIndex;
  481.         }
  482.                
  483.         public void setItems (MyLazyImageListItem[] objects) {
  484.             if(objects == null){
  485.                 items = null;
  486.                 return;
  487.             }          
  488.             if (!(objects instanceof MyLazyImageListItem[])) {         
  489.                 throw new IllegalArgumentException("Items must be instance of MyLazyImageListItem");
  490.             }
  491.                
  492.             items = objects;
  493.             selectedIndex = 0;
  494.  
  495.             final BitmapFont font = style.font;
  496.             final Drawable selectedDrawable = style.selection;
  497.  
  498.             itemHeight = font.getCapHeight() - font.getDescent() * 2;
  499.             itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight();
  500.             itemHeight*=coefH;
  501.             prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();
  502.             textOffsetX = selectedDrawable.getLeftWidth();
  503.             textOffsetY = selectedDrawable.getTopHeight() - font.getDescent();
  504.  
  505.             prefWidth = 0;
  506.             for (int i = 0; i < items.length; i++) {           
  507.                 TextBounds bounds = font.getBounds(items[i].name);
  508.                 prefWidth = Math.max(bounds.width, prefWidth);                 
  509.             }
  510.             prefHeight = items.length * itemHeight;        
  511.             imageWidth*=coefW;
  512.             imageHeight*=coefH;        
  513.             invalidateHierarchy();         
  514.         }
  515.                                        
  516.         public MyLazyImageListItem[] getItems () {
  517.             return items;
  518.         }
  519.  
  520.         public float getPrefWidth () {
  521.             return prefWidth;
  522.         }
  523.  
  524.         public float getPrefHeight () {
  525.             return prefHeight;
  526.         }
  527.                
  528.     }  
  529.    
  530.     /************************ LIST ITEM ************************/
  531.     public static class MyLazyImageListItem{       
  532.         private String showName;   
  533.         public String name;    
  534.         public URL url;    
  535.        
  536.         public MyLazyImageListItem(String name, URL url){
  537.             showName = name;
  538.             this.name = name;          
  539.             this.url=url;          
  540.         }
  541.                        
  542.         /**
  543.          * Forms array of items (size of texts must be equal to size of urls)
  544.          * @param texts If you want to have several columns, you should split them by SEPARATOR
  545.          * @param urls URLs of the images which has to be downloaded
  546.          * @return
  547.          */
  548.         public static MyLazyImageListItem[] formItems(String[] texts, URL[] urls) {
  549.             if(texts.length!=urls.length) return null;             
  550.             MyLazyImageListItem[] listItems = new MyLazyImageListItem[texts.length];           
  551.             for (int i=0; i<texts.length; i++) {       
  552.                     listItems[i] = new MyLazyImageListItem(texts[i], urls[i]);             
  553.             }
  554.             return listItems;
  555.         }
  556.     }  
  557.    
  558.     public static class ImagePow2 {
  559.        
  560.         static int pow2[] = {2,4,8,16,32,64,128,256,512,1024,2048,4096,8192};      
  561.         public static boolean isPow2(Pixmap pixmap){
  562.             boolean isWidthPow2 = false, isHeightPow2 = false;
  563.             for(int i=0; i<pow2.length; i++){
  564.                 if(pow2[i]==pixmap.getWidth()) isWidthPow2=true;
  565.                 if(pow2[i]==pixmap.getHeight()) isHeightPow2=true;
  566.             }
  567.             return isWidthPow2&&isHeightPow2;
  568.         }
  569.         private static int getPow2(int value){
  570.             int diff = value;
  571.             int tmp = value;
  572.             int minVal = value;
  573.             for(int i=0; i<pow2.length; i++){
  574.                 diff = Math.abs(value - pow2[i]);
  575.                 if(tmp>diff){
  576.                     tmp=diff;
  577.                     minVal = pow2[i];
  578.                 }
  579.             }
  580.             return minVal;
  581.         }
  582.        
  583.         public static Pixmap getPow2Pixmap(Pixmap pixmap){
  584.             int width = getPow2(pixmap.getWidth());
  585.             int height = getPow2(pixmap.getHeight());
  586.             Pixmap updatedPixmap = new Pixmap(width, height, pixmap.getFormat());
  587.             updatedPixmap.drawPixmap(pixmap, 0, 0, pixmap.getWidth(), pixmap.getHeight(), 0, 0, width, height);
  588.             return updatedPixmap;
  589.         }              
  590.     }
  591. }
  592.  
  593. /**How to use**/
  594. /*
  595. MyLazyImageList myLazyListTop100 = new MyLazyImageList(null, scrollPaneStyle, listStyle,
  596.                 new Texture(Gdx.files.internal("skins/unknown_flag.png")), false);             
  597.         myLazyListTop100.setEnabled(false);
  598.         String splitter = MyLazyImageList.SEPARATOR;
  599.       //MyDrawable implements Drawable
  600.  myLazyListTop100.setHeaders("#"+splitter+"Nickname"+splitter+"Location"+splitter+"Score"+splitter+"Flag",
  601.                 new MyDrawable(new NinePatch(new Texture(Gdx.files.internal("images/background_list.png")))));
  602.         myLazyListTop100.setHeadersColor(new Color(0, 1, 1, 1));
  603.        
  604.  myLazyListTop100.setBounds(5, 5, width, height );
  605.         myLazyListTop100.setEnabled(false);
  606.         myLazyListTop100.setSelectedIndex(-1);
  607.         myLazyListTop100.setItems(null);
  608.         myLazyListTop100.setEmptyLabel("Loading...");
  609.         stage.addActor(myLazyListTop100);
  610. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement