Android Open Source - abstract-art Uniform Grid View






From Project

Back to project page abstract-art.

License

The source code is released under:

GNU General Public License

If you think the Android project abstract-art listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.georgewhiteside.android.abstractart;
/*from w w  w  .ja  va 2s.  com*/
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.GridView;

public class UniformGridView extends GridView
{
  private int mColumnWidth = 0;
  
  public UniformGridView(Context context)
  {
    super(context);
  }
  
  public UniformGridView(Context context, AttributeSet attrs)
  {
    super(context, attrs);
  }
  
  public UniformGridView(Context context, AttributeSet attrs, int defStyle)
  {
    super(context, attrs, defStyle);
  }
  
  @Override
  public void setColumnWidth(int columnWidth)
  {
    super.setColumnWidth(columnWidth);
    
    if(columnWidth > 0)
    {
      mColumnWidth = columnWidth;
    }
  }
  
  @Override
    protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld)
    {
        super.onSizeChanged(xNew, yNew, xOld, yOld);

        if(xNew > 0 && mColumnWidth > 0)
        {
          int width = getWidth();
            int columns = xNew / mColumnWidth;
            
            if(columns > 1)
            {
              int paddingTop = ((View)this.getParent()).getPaddingTop();
              int paddingLeft = ((View)this.getParent()).getPaddingLeft();
              int paddingRight = ((View)this.getParent()).getPaddingRight();
              
              // can't seem to figure out how to calculate the extra view space... width % mColumnWidth
              // was what I figured, and when the number of columns is as expected it *looks* perfect,
              // but it causes the grid to drop a column way too soon when you start shrinking the spacing...
              // subtracting the verticalscrollbarwidth lets me get much tighter, within a couple pixels of spacing,
              // but it's still not quite right.
              int extraViewSpace = width % mColumnWidth - getVerticalScrollbarWidth();
              int extraColumnSpace = extraViewSpace / columns;
              
              setHorizontalSpacing(extraColumnSpace);
              setVerticalSpacing(extraColumnSpace);
            }
        }
    }
}




Java Source Code List

net.georgewhiteside.android.abstractart.AbstractArt.java
net.georgewhiteside.android.abstractart.BattleBackground.java
net.georgewhiteside.android.abstractart.BattleGroup.java
net.georgewhiteside.android.abstractart.Cache.java
net.georgewhiteside.android.abstractart.Distortion.java
net.georgewhiteside.android.abstractart.Enemy.java
net.georgewhiteside.android.abstractart.FPSCounter.java
net.georgewhiteside.android.abstractart.GLOffscreenSurface.java
net.georgewhiteside.android.abstractart.ImageLoader.java
net.georgewhiteside.android.abstractart.Layer.java
net.georgewhiteside.android.abstractart.Renderer.java
net.georgewhiteside.android.abstractart.RomUtil.java
net.georgewhiteside.android.abstractart.ServiceDialog.java
net.georgewhiteside.android.abstractart.Settings.java
net.georgewhiteside.android.abstractart.ShaderFactory.java
net.georgewhiteside.android.abstractart.Translation.java
net.georgewhiteside.android.abstractart.UniformGridView.java
net.georgewhiteside.android.abstractart.Wallpaper.java
net.georgewhiteside.android.abstractart.settings.BackgroundSelector.java
net.georgewhiteside.android.abstractart.settings.ClearCachePreference.java
net.georgewhiteside.android.abstractart.settings.CreateImageCachePreference.java
net.georgewhiteside.android.abstractart.settings.FrameRatePreference.java
net.georgewhiteside.android.abstractart.settings.ThumbnailAdapter.java
net.georgewhiteside.utility.Dimension.java
net.starmen.pkhack.HackModule.java
org.jf.GLWallpaper.GLWallpaperService.java
sheetrock.panda.changelog.ChangeLog.java