Android Open Source - TileView Tile Render Task






From Project

Back to project page TileView.

License

The source code is released under:

MIT License

If you think the Android project TileView 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 com.qozix.tileview.tiles;
//from   w ww. j a  v  a  2  s.  co m
import java.lang.ref.WeakReference;
import java.util.LinkedList;

import com.qozix.os.AsyncTask;


class TileRenderTask extends AsyncTask<Void, Tile, Void> {

  private final WeakReference<TileManager> reference;
  
  // package level access
  TileRenderTask( TileManager tm ) {
    super();
    reference = new WeakReference<TileManager>( tm );
  }
  
  @Override
  protected void onPreExecute() {
    final TileManager tileManager = reference.get();
    if ( tileManager != null ) {
      tileManager.onRenderTaskPreExecute();
    }    
  }

  @Override
  protected Void doInBackground( Void... params ) {
    // have we been stopped or dereffed?
    TileManager tileManager = reference.get();
    // if not go ahead, but check again in each iteration
    if ( tileManager != null ) {
      // avoid concurrent modification exceptions by duplicating
      LinkedList<Tile> renderList = tileManager.getRenderList();
      // start rendering, checking each iteration if we need to break out
      for ( Tile m : renderList ) {
        // check again if we've been stopped or gc'ed
        tileManager = reference.get();
        if ( tileManager == null ) {
          return null;
        }
        // quit if we've been forcibly stopped
        if ( tileManager.getRenderIsCancelled() ) {
          return null;
        }
        // quit if task has been cancelled or replaced
        if ( isCancelled() ) {
          return null;
        }
        // once the bitmap is decoded, the heavy lift is done
        tileManager.decodeIndividualTile( m );
        // pass it to the UI thread for insertion into the view tree
        publishProgress( m );
      }
      
    }    
    return null;
  }

  @Override
  protected void onProgressUpdate( Tile... params ) {
    // have we been stopped or dereffed?
    TileManager tileManager = reference.get();
    // if not go ahead but check other cancel states
    if ( tileManager != null ) {
      // quit if it's been force-stopped
      if ( tileManager.getRenderIsCancelled() ) {
        return;
      }
      // quit if it's been stopped or replaced by a new task
      if ( isCancelled() ) {
        return;
      }
      // tile should already have bitmap decoded
      Tile m = params[0];
      // add the bitmap to it's view, add the view to the current detail level layout
      tileManager.renderIndividualTile( m );
    }
    
  }

  @Override
  protected void onPostExecute( Void param ) {
    // have we been stopped or dereffed?
    TileManager tileManager = reference.get();
    // if not go ahead but check other cancel states
    if ( tileManager != null ) {
      tileManager.onRenderTaskPostExecute();
    }
  }

  @Override
  protected void onCancelled() {
    // have we been stopped or dereffed?
    TileManager tileManager = reference.get();
    // if not go ahead but check other cancel states
    if ( tileManager != null ) {
      tileManager.onRenderTaskCancelled();
    }
  }

}




Java Source Code List

com.qozix.animation.AnimationListener.java
com.qozix.animation.Animator.java
com.qozix.animation.TweenHandler.java
com.qozix.animation.TweenListener.java
com.qozix.animation.Tween.java
com.qozix.animation.easing.EasingEquation.java
com.qozix.animation.easing.Linear.java
com.qozix.animation.easing.Strong.java
com.qozix.layouts.AnchorLayout.java
com.qozix.layouts.FixedLayout.java
com.qozix.layouts.ScalingLayout.java
com.qozix.layouts.StaticLayout.java
com.qozix.layouts.TranslationLayout.java
com.qozix.layouts.ZoomPanLayout.java
com.qozix.os.AsyncTask.java
com.qozix.tileview.TileView.java
com.qozix.tileview.detail.DetailLevelEventListener.java
com.qozix.tileview.detail.DetailLevelPatternParserDefault.java
com.qozix.tileview.detail.DetailLevelPatternParser.java
com.qozix.tileview.detail.DetailLevelSet.java
com.qozix.tileview.detail.DetailLevelSetupListener.java
com.qozix.tileview.detail.DetailLevel.java
com.qozix.tileview.detail.DetailManager.java
com.qozix.tileview.geom.PositionManager.java
com.qozix.tileview.graphics.BitmapDecoderAssets.java
com.qozix.tileview.graphics.BitmapDecoderHttp.java
com.qozix.tileview.graphics.BitmapDecoder.java
com.qozix.tileview.hotspots.HotSpotEventListener.java
com.qozix.tileview.hotspots.HotSpotManager.java
com.qozix.tileview.hotspots.HotSpot.java
com.qozix.tileview.markers.CalloutManager.java
com.qozix.tileview.markers.MarkerEventListener.java
com.qozix.tileview.markers.MarkerManager.java
com.qozix.tileview.paths.DrawablePath.java
com.qozix.tileview.paths.PathHelper.java
com.qozix.tileview.paths.PathManager.java
com.qozix.tileview.samples.SampleManager.java
com.qozix.tileview.tiles.TileCache.java
com.qozix.tileview.tiles.TileManager.java
com.qozix.tileview.tiles.TileRenderHandler.java
com.qozix.tileview.tiles.TileRenderListener.java
com.qozix.tileview.tiles.TileRenderTask.java
com.qozix.tileview.tiles.TileTransitionListener.java
com.qozix.tileview.tiles.Tile.java
com.qozix.tileview.tiles.selector.TileSetSelectorByRange.java
com.qozix.tileview.tiles.selector.TileSetSelectorClosest.java
com.qozix.tileview.tiles.selector.TileSetSelectorMinimalUpScale.java
com.qozix.tileview.tiles.selector.TileSetSelector.java
com.qozix.utils.ViewCurator.java
com.qozix.widgets.Scroller.java