Skip to content

Instantly share code, notes, and snippets.

@bender-rulez
Created May 12, 2011 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bender-rulez/969319 to your computer and use it in GitHub Desktop.
Save bender-rulez/969319 to your computer and use it in GitHub Desktop.
dashboardLabels = ['profil','wermachtwas','favoriten','gruppeneinladungen','besucher','mail','personensuchen'];
dashboardLabelsNames = ['Profil','Timeline','Favoriten','Following','Follower','Nachrichten','Suchen'];
for (var c=0;c<dashboardLabels.length;c++)
{
var item = Titanium.UI.createDashboardItem({
canDelete:false,
label:dashboardLabels[c]
});
var innerView = createDashboardItem(dashboardLabelsNames[c],Ti.Filesystem.resourcesDirectory+'/images/dashboard/'+dashboardLabels[c]+'_off.png','false');
item.add(innerView);
item.add(createDashboardItem(dashboardLabelsNames[c],Ti.Filesystem.resourcesDirectory+'/images/dashboard/'+dashboardLabels[c]+'_off.png','true'));
dashboarddata.push(item);
}
var dashboard = Titanium.UI.createDashboardView({
backgroundColor:'transparent',
data:dashboarddata,
top:10,
wobble:true
});
win.add(dashboard);
dashboard.addEventListener('touchstart',function(e)
{
e.item.children[0].hide();
e.item.children[1].show();
});
dashboard.addEventListener('touchend',function(e)
{
setTimeout(function()
{
e.item.children[1].hide();
e.item.children[0].show();
},150);
});
dashboard.addEventListener('click',function(e)
{
setTimeout(function()
{
switch(e.item.label)
{
case 'mail':
// do something
break;
}
},250);
});
function createDashboardItem(label, image, mode){
var container = Ti.UI.createView({
height : 'auto',
width : 'auto',
backgroundColor:'transparent'
});
if (mode == 'true') {
container.opacity = 0.5;
container.visbile = false;
}
container.add(Ti.UI.createImageView({
image : image,
width : 70,
height : 70,
top : 0,
backgroundColor:'transparent'
}));
container.add(Ti.UI.createLabel({
text : label,
textAlign : 'center',
color : 'white',
font : {fontSize:13,fontWeight:'bold',fontFamily:'Arial'},
height : 33,
width: 100,
top : 70,
shadowColor:'#1b1b1b',
shadowOffset:{x: 1, y: 1},
backgroundColor:'transparent'
}));
return container;
}
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#ifdef USE_TI_UIDASHBOARDVIEW
#import "TiUIDashboardView.h"
#import "TiUtils.h"
#import "TiRect.h"
#import "TiUIDashboardViewProxy.h"
#import "TiUIDashboardItemProxy.h"
#import "LauncherView.h"
#import "LauncherItem.h"
#import "LauncherButton.h"
@implementation TiUIDashboardView
-(void)dealloc
{
if (launcher.editing)
{
[launcher endEditing];
}
launcher.delegate = nil;
RELEASE_TO_NIL(launcher);
[super dealloc];
}
-(LauncherView*)launcher
{
if (launcher==nil)
{
launcher = [[LauncherView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
launcher.delegate = self;
[launcher setEditable:[[[self proxy] valueForUndefinedKey:@"editable"] boolValue]];
[self addSubview:launcher];
}
return launcher;
}
-(void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds
{
if (!CGRectIsEmpty(bounds))
{
[TiUtils setView:launcher positionRect:bounds];
}
}
-(void)setEditable_:(id)args
{
ENSURE_TYPE(args, NSNumber);
if (launcher != nil) {
[launcher setEditable:[args boolValue]];
}
[[self proxy] replaceValue:args forKey:@"editable" notification:NO];
}
-(void)setRows_:(NSNumber *)rows
{
if (rows) {
[self launcher];
launcher.rowCount = [rows intValue];
}
}
-(void)setColumns_:(NSNumber *)cols
{
if (cols) {
[self launcher];
launcher.columnCount = [cols intValue];
}
}
-(void)setData_:(id)args
{
[self launcher];
for (TiUIDashboardItemProxy *proxy in args)
{
ENSURE_TYPE(proxy,TiUIDashboardItemProxy);
[launcher addItem:proxy.item animated:NO];
}
}
-(void)startEditing
{
[launcher beginEditing];
}
-(void)stopEditing
{
[launcher endEditing];
}
#pragma mark Delegates
- (void)launcherView:(LauncherView*)launcher didAddItem:(LauncherItem*)item
{
}
- (void)launcherView:(LauncherView*)launcher_ didRemoveItem:(LauncherItem*)item
{
// update our data array
[self.proxy replaceValue:[launcher items] forKey:@"data" notification:NO];
NSMutableDictionary *event = [NSMutableDictionary dictionary];
[event setObject:item.userData forKey:@"item"];
if ([self.proxy _hasListeners:@"delete"])
{
[self.proxy fireEvent:@"delete" withObject:event];
}
if ([item.userData _hasListeners:@"delete"])
{
[item.userData fireEvent:@"delete" withObject:event];
}
}
- (void)launcherView:(LauncherView*)launcher_ willDragItem:(LauncherItem*)item
{
NSMutableDictionary *event = [NSMutableDictionary dictionary];
// the actual item being moved
[event setObject:item.userData forKey:@"item"];
if ([self.proxy _hasListeners:@"dragStart"])
{
[self.proxy fireEvent:@"dragStart" withObject:event];
}
if ([item.userData _hasListeners:@"dragStart"])
{
[item.userData fireEvent:@"dragStart" withObject:event];
}
}
- (void)launcherView:(LauncherView*)launcher_ didDragItem:(LauncherItem*)item
{
NSMutableDictionary *event = [NSMutableDictionary dictionary];
// the actual item being moved
[event setObject:item.userData forKey:@"item"];
if ([self.proxy _hasListeners:@"dragEnd"])
{
[self.proxy fireEvent:@"dragEnd" withObject:event];
}
if ([item.userData _hasListeners:@"dragEnd"])
{
[item.userData fireEvent:@"dragEnd" withObject:event];
}
}
- (void)launcherView:(LauncherView*)launcher_ didMoveItem:(LauncherItem*)item
{
NSMutableDictionary *event = [NSMutableDictionary dictionary];
// the actual item being moved
[event setObject:item.userData forKey:@"item"];
// the new (uncommitted) items in order
[event setObject:[launcher items] forKey:@"items"];
if ([self.proxy _hasListeners:@"move"])
{
[self.proxy fireEvent:@"move" withObject:event];
}
if ([item.userData _hasListeners:@"move"])
{
[item.userData fireEvent:@"move" withObject:event];
}
}
- (void)launcherView:(LauncherView*)launcher didSelectItem:(LauncherItem*)item
{
NSMutableDictionary *event = [NSMutableDictionary dictionary];
[event setObject:item.userData forKey:@"item"];
// convert our location to the location within our superview
CGRect curFrame = [self convertRect:item.button.frame toView:[self superview]];
TiRect *rect = [[TiRect alloc] _initWithPageContext:[self.proxy pageContext]];
[rect setRect:curFrame];
[event setObject:rect forKey:@"location"];
[rect release];
if ([self.proxy _hasListeners:@"click"])
{
[self.proxy fireEvent:@"click" withObject:event];
}
if ([item.userData _hasListeners:@"click"])
{
[item.userData fireEvent:@"click" withObject:event];
}
if ([self.proxy _hasListeners:@"touchstart"])
{
[self.proxy fireEvent:@"touchstart" withObject:event];
}
if ([item.userData _hasListeners:@"touchstart"])
{
[item.userData fireEvent:@"touchstart" withObject:event];
}
if ([self.proxy _hasListeners:@"touchend"])
{
[self.proxy fireEvent:@"touchend" withObject:event];
}
if ([item.userData _hasListeners:@"touchend"])
{
[item.userData fireEvent:@"touchend" withObject:event];
}
}
- (void)launcherViewDidBeginEditing:(LauncherView*)launcher
{
if ([self.proxy _hasListeners:@"edit"])
{
NSMutableDictionary *event = [NSMutableDictionary dictionary];
[self.proxy fireEvent:@"edit" withObject:event];
}
}
- (void)launcherViewDidEndEditing:(LauncherView*)launcher_
{
// update our data array since it's possible been reordered
[self.proxy replaceValue:[launcher_ items] forKey:@"data" notification:NO];
if ([self.proxy _hasListeners:@"commit"])
{
NSMutableDictionary *event = [NSMutableDictionary dictionary];
[self.proxy fireEvent:@"commit" withObject:event];
}
}
- (BOOL)launcherViewShouldWobble:(LauncherView *)launcher_
{
// all the wobble effect to be turned off if required by Apple
return [TiUtils boolValue:[self.proxy valueForUndefinedKey:@"wobble"] def:YES];
}
@end
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment