Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-9546: BlackBerry: Implement Platform elements needed for KitchenSink #87

Merged
merged 8 commits into from
Jul 9, 2012
22 changes: 19 additions & 3 deletions apidoc/Titanium/Platform/Platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ methods:

- name: createUUID
summary: Creates a globally-unique identifier.
platforms: [android, iphone, ipad, mobileweb]
returns:
type: String

Expand All @@ -52,6 +53,7 @@ methods:
- name: url
summary: The url to open.
type: String
platforms: [android, iphone, ipad, mobileweb]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openURL is part of this Jira task

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openURL already not part of app.js and doesn't prevent us from running KS. Also we don't have browser for now. That's why it leaved for near future.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a comment in the Jira

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


- name: is24HourTimeFormat
summary: Returns whether the system settings are configured to show times in 24-hour format.
Expand Down Expand Up @@ -87,16 +89,19 @@ properties:
summary: The system's WIFI IP address. No other network types are supported.
type: String
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: architecture
summary: The system's processor architecture.
type: String
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: availableMemory
summary: The system's unused memory, measured in megabytes on iOS and bytes on Android.
type: Number
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: batteryLevel
summary: |
Expand All @@ -109,6 +114,7 @@ properties:
summary: Determines whether battery monitoring is enabled.
default: false
type: Boolean
platforms: [android, iphone, ipad, mobileweb]

- name: batteryState
summary: Indicates the state of the battery. Accessible only when `batteryMonitoring` is enabled.
Expand All @@ -132,6 +138,7 @@ properties:
from the `DisplayCaps` object that it returns.
type: Titanium.Platform.DisplayCaps
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: id
summary: The applications's globally-unique ID (UUID).
Expand All @@ -145,6 +152,7 @@ properties:
documentation.
type: String
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: locale
summary: The system's default language.
Expand All @@ -156,6 +164,7 @@ properties:
sections of wikipedia for reference.
type: String
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: macaddress
summary: The system's network interface mac address, or app UUID.
Expand All @@ -165,6 +174,7 @@ properties:
unique device identification, which they have prohibited.
type: String
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: model
summary: The model of the device.
Expand Down Expand Up @@ -199,29 +209,33 @@ properties:
summary: The system's WIFI network mask. No other network types are supported.
type: String
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: osname

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a comment saying that for BlackBerry it will be 'blackberry'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

summary: |
The short name of the system's Operating System. For example, iPhone will return `iphone`,
iPad will return `ipad`, Android will return `android` and Mobile Web will return `mobileweb`.
iPad will return `ipad`, Android will return `android`, Mobile Web will return `mobileweb` and
BlackBerry will return `blackberry`.
type: String
permission: read-only

- name: ostype
summary: The Operating System architecture. On Android, this is `32bit`.
type: String
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: processorCount
summary: The number of processing cores.
type: Number
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: runtime
summary: The short name of the JavaScript runtime in use.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment saying that v8 is used in BlackBerry

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

description: |
On iOS this is "javascriptcore", on Android either "v8" or "rhino" and on Mobile Web it is
determined by the browser used.
On iOS this is "javascriptcore", on Android either "v8" or "rhino", on Mobile Web it is
determined by the browser used and on BlackBerry it is "v8".
type: String
permission: read-only

Expand All @@ -230,11 +244,13 @@ properties:
The system name, if set. On iOS, this can be found in Settings > General > About > Name.
type: String
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

- name: version
summary: The system's OS version.
type: String
permission: read-only
platforms: [android, iphone, ipad, mobileweb]

examples:
- title: Battery Event Example
Expand Down
220 changes: 220 additions & 0 deletions blackberry/tibb/NativePlatformInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2012 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.
*/

#include "NativePlatformInterface.h"
#include "TiConstants.h"
#include <vector>

#define PROP_GETTING_FUNCTION(NAME) prop_##NAME

#define PROP_GETTER(NAME) static Handle<Value> prop_##NAME(const NativePlatformInterface* instance) \
{\
return instance->NAME();\
}

typedef Handle<Value> (*NATIVE_PROPGET_CALLBACK)(const NativePlatformInterface* instance);

// Prototypes
static vector<NATIVE_PROPGET_CALLBACK> initFunctionMap();

// Statics
static const vector<NATIVE_PROPGET_CALLBACK> s_functionMap = initFunctionMap();

const NativePlatformInterface* NativePlatformInterface::instance()
{
static NativePlatformInterface s_theInstance;
return &s_theInstance;
}

NativePlatformInterface::NativePlatformInterface()
{
}

PROP_GETTER(getAddress)
Handle<Value> NativePlatformInterface::getAddress()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getArchitecture)
Handle<Value> NativePlatformInterface::getArchitecture()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getAvailableMemory)
Handle<Value> NativePlatformInterface::getAvailableMemory()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getBatteryLevel)
Handle<Value> NativePlatformInterface::getBatteryLevel()
{
return v8::Integer::New(instance()->batteryInfo_.level());
}

PROP_GETTER(getBatteryMonitoring)
Handle<Value> NativePlatformInterface::getBatteryMonitoring()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getBatteryState)
Handle<Value> NativePlatformInterface::getBatteryState()
{
bb::device::BatteryInfo::ChargingState bState = instance()->batteryInfo_.chargingState();
Ti::Platform::TI_BATTERY_STATE tiState = Ti::Platform::BATTERY_STATE_UNKNOWN;
switch (bState)
{
case bb::device::BatteryInfo::UnknownChargingState:
tiState = Ti::Platform::BATTERY_STATE_UNKNOWN;
break;
case bb::device::BatteryInfo::NotCharging:
tiState = Ti::Platform::BATTERY_STATE_UNKNOWN;
break;
case bb::device::BatteryInfo::Full:
tiState = Ti::Platform::BATTERY_STATE_FULL;
break;
case bb::device::BatteryInfo::Discharging:
tiState = Ti::Platform::BATTERY_STATE_UNPLUGGED;
break;
case bb::device::BatteryInfo::Charging:
tiState = Ti::Platform::BATTERY_STATE_CHARGING;
break;
}
return v8::Integer::New(tiState);
}

PROP_GETTER(getDisplayCaps)
Handle<Value> NativePlatformInterface::getDisplayCaps()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getId)
Handle<Value> NativePlatformInterface::getId()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getLocale)
Handle<Value> NativePlatformInterface::getLocale()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getMacaddress)
Handle<Value> NativePlatformInterface::getMacaddress()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getModel)
Handle<Value> NativePlatformInterface::getModel()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getName)
Handle<Value> NativePlatformInterface::getName()
{
return String::New("blackberry");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check what the other platforms do. I'm thinking this should be BlackBerry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All platforms return lowercase information

}

PROP_GETTER(getNetmask)
Handle<Value> NativePlatformInterface::getNetmask()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getOsname)
Handle<Value> NativePlatformInterface::getOsname()
{
return String::New("blackberry");
}

PROP_GETTER(getOstype)
Handle<Value> NativePlatformInterface::getOstype()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getProcessorCount)
Handle<Value> NativePlatformInterface::getProcessorCount()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getRuntime)
Handle<Value> NativePlatformInterface::getRuntime()
{
return String::New("v8");
}

PROP_GETTER(getUsername)
Handle<Value> NativePlatformInterface::getUsername()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

PROP_GETTER(getVersion)
Handle<Value> NativePlatformInterface::getVersion()
{
// TODO: Finish this when will be available in SDK
return Undefined();
}

Handle<Value> NativePlatformInterface::getPropertyValue(int propertyNumber)
{
if ((propertyNumber >= s_functionMap.size()) || (s_functionMap[propertyNumber] == NULL))
{
return Undefined();
}
Handle<Value> result = (s_functionMap[propertyNumber])(instance());
return result;
}

static vector<NATIVE_PROPGET_CALLBACK> initFunctionMap()
{
vector<NATIVE_PROPGET_CALLBACK> vect(N_PLATFORM_PROP_LAST);

vect[N_PLATFORM_PROP_UNDEFINED] = NULL;
vect[N_PLATFORM_PROP_ADDRESS] = NULL;
vect[N_PLATFORM_PROP_ARCHITECTURE] = NULL;
vect[N_PLATFORM_PROP_AVAILABLEMEMORY] = NULL;
vect[N_PLATFORM_PROP_BATTERYLEVEL] = PROP_GETTING_FUNCTION(getBatteryLevel);
vect[N_PLATFORM_PROP_BATTERYMONITORING] = NULL;
vect[N_PLATFORM_PROP_BATTERYSTATE] = PROP_GETTING_FUNCTION(getBatteryState);
vect[N_PLATFORM_PROP_DISPLAYCAPS] = NULL;
vect[N_PLATFORM_PROP_ID] = NULL;
vect[N_PLATFORM_PROP_LOCALE] = NULL;
vect[N_PLATFORM_PROP_MACADDRESS] = NULL;
vect[N_PLATFORM_PROP_MODEL] = NULL;
vect[N_PLATFORM_PROP_NAME] = PROP_GETTING_FUNCTION(getName);
vect[N_PLATFORM_PROP_NETMASK] = NULL;
vect[N_PLATFORM_PROP_OSNAME] = PROP_GETTING_FUNCTION(getOsname);
vect[N_PLATFORM_PROP_OSTYPE] = NULL;
vect[N_PLATFORM_PROP_PROCESSORCOUNT] = NULL;
vect[N_PLATFORM_PROP_RUNTIME] = PROP_GETTING_FUNCTION(getRuntime);
vect[N_PLATFORM_PROP_USERNAME] = NULL;
vect[N_PLATFORM_PROP_VERSION] = NULL;
return vect;
}