Giter Site home page Giter Site logo

alg520 / android-tilelayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rajasharan/android-tilelayout

0.0 1.0 0.0 720 KB

An android layout to load Tiles asynchronously using AsyncAdapter<T>. Reference implementation of SimpleTileAdapter provided.

License: MIT License

Java 100.00%

android-tilelayout's Introduction

Android Tile Layout

An android layout to load Tiles asynchronously using AsyncAdapter along with sample implementation of a simple 2D layer extending AsyncAdapter<Point>

Demo

Usage

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    root = (TileLayout) findViewById(R.id.tiles);
    adapter = new SimpleTileAdapter(this);
    root.setAsyncAdapter(adapter);
}

activity_main.xml

<com.rajasharan.tilelayout.TileLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tiles"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
</com.rajasharan.tilelayout.TileLayout>

AsyncAdapter<T> API

AsyncAdapter provides API to retrieve Views in background represented by tags. For eg: to retrieve views in a 2D surface you can tag the properties of the View from your data-model. For reference implementation see SimpleTileAdapter.java

/**
 * @return width of the view
 */
public abstract int getWidth()

/**
 * @return height of the view
 */
public abstract int getHeight()

/**
 * Returns the View represented by tag in your data-model.
 *
 * @param tag view's identifier tag from your data-model.
 * @return the default view is immediately returned and a message sent to Adapter-Thread to work on real view
 */
public final View getView(T tag)

/**
 * Return the default view while real view is being created in background.
 *
 * @param tag view's identifier in your data-model.
 * @return must immediately return default view
 */
protected abstract View getDefaultView(T tag)

/**
 * This method is called on non-UI background thread.
 * The real view can be created here from your data-model represented by tag.
 *
 * @param tag the view's identifier in your data-model.
 * @return the real view represented by tag in your data-model.
 */
public abstract View getViewInBackground(T tag)

/**
 * Intended to be called by the Root Layout that acts as an AdapterView and
 * needs its views to be available on an async basis.
 * <br>
 * Unless you are implementing your own ViewGroup don't call this method directly.
 */
public void setOnViewAvailableListener(OnViewAvailableListener<T> listener) {
    mListener = listener;
}

/**
 * Listener callback interface when View is available.
 */
public interface OnViewAvailableListener<T> {
    /**
     * This method is invoked when the newly created view is available.
     * <br>
     * <b>Note: </b> This method is inoked on non-UI background thread.
     * Use post(Runnable) to interact with UI thread.
     *
     * @param tag view's identifier in your data-model
     * @param view the newly created/available view.
     */
    void OnViewAvailable(final T tag, final View view);
}

TODO

  • yet to implement touch panning
The MIT License (MIT)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.