Code Monkey home page Code Monkey logo

ulizama.com.baboonmedia.remoteimage's Introduction

Remote Image Widget Titanium Alloy

This widget for the Appcelerator Titanium Alloy MVC framework provides a view that supports remote image loading with full image caching. Image caching is made using a fork of TiCachedImages.

Installing

Get it gitTio

Download this repository and consult the Alloy Documentation on how to install it, or simply use the gitTio CLI:

$ gittio install com.baboonmedia.remoteimage

Usage

Just require the widget on a view:

<Widget src="com.baboonmedia.remoteimage" id="RemoteImage">
	<ActivityIndicator id="activityIndicator" role="activityindicator" />
    <View role="loadingerror">
       <Label>Unable to load image. Tap to retry</Label>
    </View>
</Widget>

Child Views

Inside the widget you can assign a couple of child views with role assigned to display the activity indicator and an error message.

  • loadingerror - The view with this role will be shown when there was an error loading the remote image with a singletap listener attached to it to retry laoding of the image.
  • activityindicator - The activity indicator to be shown while loading the image. It can be any kind of view as long as it has a show()and hide()method.

Widget Specific Properties

Besides the common Titanium properties of a view, the widget accepts the following properties to determine it's behavior.

Property Type Description
image String Full url of the image to load.
autoload Boolean If set to false the image won't be loaded until the load method is called.
gethires Boolean If this property is set to true then the url will be parsed to include the @2x suffix. For example, if url is set to http://mysite.com/image.jpg and gethires is set to true, then the url will be converted to http://mysite.com/[email protected].
onDone Function Function to be called when the image has been loaded. The callback will be sent a msg string with the full details of the cached file.
onError Function Function to be called if the image has failed loading. The callback will be sent an error string with the error message.

Run-time styling

You can use $.myId.applyProperties() to apply any new properties to the widget after it has been automatically initialized:

$.myId.applyProperties({
	autoload: true,
    image: 'http://mysite.com/otherimage.jpg',
    backgroundColor: 'black'
});

Public Methods

Method Description
applyProperties() Method to assign new properties to the widget
load() If the image hasn't been loaded start loading the image. This method has to be called manually if autoload is set to false
setImage() Sets a new image and loads it if autoload is set to true
getImage() Returns the url of the current image
getImageCachePath() Returns the local path of the cached image
clean() It's highly recommended that you call this method before disposing from the object to prevent memory leaks.
gc() Calls the garbage collector to clean any expired images. Upon initialization the garbage collector is called.
wipeCache() Clear everything on the cache, regardless if it has expired or not.

Configuration

To set configuration set them in your app/config.json.

You can adjust the following variables:

Variable Default Description
remoteimage_timeout 120000 Sets the http timeout.
remoteimage_property_key RemoteImage The Ti.App.Property key to use for storing the cache metadata.
remoteimage_directory RemoteImageCache The directory to save the cache files. The applicationDataDirectory is prefixed.
remoteimage_expiration 8640000 How long in miliseconds a cached file is considered expired since the last time it was requested.
remoteimage_requests 20 The number of simultaneous network requests allowed.
remoteimage_debug 0 Set to 1 to display debug messages.

Changelog

  • 1.1 Fixed a bug on the debug display
  • 1.0 Initial version

Licenses

This work is released under the MIT license.

TiCachedImages released under the MIT license.

This work includes an embedded and modified version of then/promise which is Copyright (c) 2013 Forbes Lindesay and release under the MIT license.

Appcelerator, Appcelerator Titanium and associated marks and logos are trademarks of Appcelerator, Inc.

Titanium is Copyright (c) 2008-2012 by Appcelerator, Inc. All Rights Reserved.

ulizama.com.baboonmedia.remoteimage's People

Contributors

ulizama avatar manumaticx avatar

Watchers

James Cloos avatar Brenton House avatar

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.