Android Wear 2.0 - retrieve calendar color from iOS Apple Calendar - wear-os

I have an Android Wear app that fetches calendar events via WearableCalendarContract. It works great when paired with Android phones, but I recently discovered a bug when pairing with an iOS device using the Apple Calendar, in that it would not fetch event colors.
After some investigation, it looks to me like the Apple Calendar doesn't let users give individual calendar events different colors - however, it does let them create different calendars, each with their own individual color. Problem is, my WearableCalendarContract query doesn't seem to fetch the calendar colors either.
Is there a solution to this issue, or am I just going to have to set a default color if no color is found?
Code is below. Thanks!
final long currentTime = System.currentTimeMillis();
Uri.Builder builder = WearableCalendarContract.Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, currentTime - DateUtils.DAY_IN_MILLIS);
ContentUris.appendId(builder, currentTime + DateUtils.DAY_IN_MILLIS);
final String[] PROJECTION = {
CalendarContract.Calendars._ID, // 0
CalendarContract.Instances.BEGIN, // 1
CalendarContract.Instances.END, // 2
CalendarContract.Events.EVENT_COLOR, // 3
CalendarContract.Events.TITLE, // 4
CalendarContract.Events.ALL_DAY, // 5
CalendarContract.Events.CALENDAR_COLOR, // 6
CalendarContract.Events.DISPLAY_COLOR // 7
};
final Cursor cursor = getContentResolver()
.query(builder.build(),
PROJECTION,
null, // selection (all)
null, // selection args
null); // order

Related

CocosSharp game on Android startup takes a long time to draw graphics

We have a somewhat simple game written using CocosSharp. The game is within another Xamarin.Forms app. When the player clicks to play the game, we bring them to a splash screen. On iOS this screen displays immediately but on Android, the screen is just black for about 15 seconds. The music plays pretty much immediately on both platforms.
The following is called from the ViewCreated event of the CocosSharpView.
InitializeAudio();
var scene = new Scenes.SplashScene(GameView);
GameView.RunWithScene(scene);
The hang up seems to be when creating labels. The following take ~10 seconds to complete with 99% of it being in the constructor of the first label. We call our CreateText in the constructor.
private void CreateText()
{
var label = new CCLabel("Text 1", "BD_CARTOON_SHOUT.TTF", 80)
{
PositionX = layer.ContentSize.Width / 2.0f,
PositionY = layer.ContentSize.Height / 1.5f,
Color = CCColor3B.DarkGray
};
layer.AddChild(label);
label = new CCLabel("Text 2", "BD_CARTOON_SHOUT.TTF", 60)
{
PositionX = layer.ContentSize.Width / 2.0f,
PositionY = 50f,
Color = CCColor3B.DarkGray
};
layer.AddChild(label);
}
Keep in mind this only happens on Android.
Thanks in advance!
I had the same issue several weeks ago. The problem was CCLabel constructor
where it didn't know which type of font are you using and therefore trying all other types before finally trying the last one which is correct. You need to specify font type in CCLabel constructor like this:
var label = new CCLabel("Text 1", "BD_CARTOON_SHOUT.TTF", 80, CCLabelFormat.SystemFont);
Hope it helps.

How to get the battery level from Kontakt.io beacons using AltBeacon API

I need to get the battery level from the kontakt.io beacons. I have set the layout as below and the DataFields are empty when I read the beacons in RangingBeaconsInRegion.
I was expecting I could read the battery level from the last bit as described in the Kontakt.io documentation.
This is my current code:
private BeaconManager InitializeBeaconManager()
{
BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);
var iBeaconParser = new BeaconParser();
iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
bm.BeaconParsers.Add(iBeaconParser);
_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;
bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);
return bm;
}
void RangingBeaconsInRegion(object sender, RangeEventArgs e)
{
if (e.Beacons.Count > 0)
{
var beacon = e.Beacons.FirstOrDefault();
var data = beacon.DataFields.FirstOrDefault();
// here DataFields is empty!
}
}
I am using Xamarin Forms and this is the code for the Android Version.
Is this possible? or do I need to use the Kontakt.io API?
UPDATE
I have removed all parsers before apply the new layout and I am able to read the dataFields. However, I am getting a value 8 which I have no idea what this value means.
I am not positive the syntax on Xamarin, but try removing all existing beacon parsers before adding your custom one. I suspect the built in iBeacon parser is still active And it is matching first.
The battery level in Kontakt.io beacons are part of their "scan response packet", not part of the iBeacon structure, you'll have to use CoreBluetooth to read Characteristic 1, Service 5.
A quick breakdown of how this works is also described here, and the recently launched Xamarin component uses the same CoreBluetooth approach.

UI Testing in Xcode 7: Selecting a row number in a UIPickerView / PickerWheel

Is there a way in Xcode 7 UI Testing to select the 3rd row in a UIPickerView?
I have tried various things like this to identify the rows in each picker but all the requests below return 0 found:
XCUIApplication().pickers.element.cells.count
XCUIApplication().pickers.element.staticTexts.count
Any ideas?
Updated: I am aware of adjustToPickerWheelValue method where you can select a particular value you already know, but I am trying to select the 3rd value (index = 4) when I don't know the values that exist in the picker.
You can use -adjustToPickerWheelValue: to select items on a UIPickerView.
When there is one UIPickerView on the screen you can select the element directly, like so.
let app = XCUIApplication()
app.launch()
app.pickerWheels.element.adjustToPickerWheelValue("Books")
If the picker has multiple wheels you will need to first select the wheel via it's accessibility identifier, then adjust it.
app.pickerWheels["Feet"].adjustToPickerWheelValue("5")
Here's a GitHub repo with a working example. And some more information in a blog post I wrote.
Workaround:
let pickerWheel = XCUIApplication().pickers.pickerWheels.element
let appWindowHeight = XCUIApplication().windows.elementBoundByIndex(0).frame.height
let pickerWheelCellHeight = GFloat(44)
func advancePickerWheelOneValue() -> Self {
let topScrollPoint = Double(pickerWheel.frame.midY/appWindowHeight)
let bottomScrollPoint = Double((pickerWheel.frame.midY + pickerWheelCellHeight)/appWindowHeight)
let topScreenPoint = XCUIApplication().windows.elementBoundByIndex(0).coordinateWithNormalizedOffset(CGVector(dx: 0.5, dy: topScrollPoint))
let bottomScreenPoint = XCUIApplication().windows.elementBoundByIndex(0).coordinateWithNormalizedOffset(CGVector(dx: 0.5, dy: bottomScrollPoint))
bottomScreenPoint.pressForDuration(0, thenDragToCoordinate: topScreenPoint)
return self
}
You may need to adjust the dx value depending on where the picker is.
.coordinateWithNormalizedOffset(CGVector(dx: 0.5,
But 0.5 works if the picker occupies the width of the screen.
With this method you an move the picker on value at a time. Call it multiple times and you get to the value you want.
Its not ideal but it can help if you want to check certain indexes. Hopefully you would have to use it on a picker with hundreds of values ;)
Example with Date picker (UIDatePicker)
XCUIApplication().datePickers.pickerWheels.elementBoundByIndex(0).adjustToPickerWheelValue("March")
XCUIApplication().datePickers.pickerWheels.elementBoundByIndex(1).adjustToPickerWheelValue("24")
XCUIApplication().datePickers.pickerWheels.elementBoundByIndex(2).adjustToPickerWheelValue("2000")
And here is example with Picker view (UIPickerView)
XCUIApplication().pickerWheels.element.adjustToPickerWheelValue("Male")

smartgwt calendar getdaybodyhtml issue

I have a issue with the smartgwt calendar tool, I've customized it to assign special icon flags certain days in the month through the protected method getdaybodyhtml() of the class calendar, everything works fine except for one thing when I display the calendar on chrome(all versions) IE(7,8,9) and FF(till 14.0.1), but when I display the calendar on FF(between 15 to 19) this flags icons aren't displayed. I've made a follow to the code and I found that the html code that I defined there in the getdaybodyhtml() method is not printed.
I was looking on the smartgwt for any issue like that but i don't found anything related.
Any help would be received.
(sorry if my english is not so good, is my second language)
Here is the piece of code:
private Calendar calendar = new Calendar(){
#Override
#SuppressWarnings("deprecation")
protected String getDayBodyHTML(Date date, CalendarEvent[] events, Calendar calendar, int rowNum, int colNum) {
String value = defaultMessage != null ? defaultMessage : date.getDate()+"";
// The "events" are the events of the day
List<CalendarEvent> calendarEvents = new ArrayList<CalendarEvent>(Arrays.asList(events));
if(calendarEvents != null && calendarEvents.size() > 0) {
// Removing the tooltip and the excluded colours
removeTooltipsFromCalendar(calendar,date);
removeExcludedColoursFromCalendar(calendarEvents);
if(calendarEvents.size() == 1){
// Description contains the colour
String colour = calendarEvents.get(0).getDescription();
value = imgHTML(COASTAL_IMAGES_DIR+colour+COASTAL_IMAGE_SUFFIX, colourWidth, colourHeight, "images", "class='handCursor'", null);
}else if(calendarEvents.size() > 1){
// Might have two vessels going to the same port in the same day
Set<String> colours = new HashSet<String>();
for(CalendarEvent event : calendarEvents){
// Description contains the colour
colours.add(event.getDescription());
}
int numberOfPorts = colours.size();
for(String colour : colours){
value += "<div>";
value += imgHTML(COASTAL_IMAGES_DIR+colour+COASTAL_IMAGE_SUFFIX, colourWidth, colourHeight/numberOfPorts, "images", "class='handCursor'", null);
value += "</div>";
}
}else{
value = defaultMessage != null ? defaultMessage : date.getDate()+"";
}
}
return value;
}
};
PD: In all the versions of chrome and IE the piece of code:
value += "<div>";
value += imgHTML(COASTAL_IMAGES_DIR+colour+COASTAL_IMAGE_SUFFIX, colourWidth, colourHeight/numberOfPorts, "images", "class='handCursor'", null);
value += "</div>";
is printed ok, in fire fox till the 14 version it's printed ok, but in ff from 15 to 19 not prints the "div" and the "image". I already see the code throw firebug and the div just not apear in that firefox version(15-19).
PD: it doesn't work on last update of IE 10 too.
Are you able to see icons in following sample in SmartGWT showcase.
I'm able to see icons in above sample for April 2, April 3, April 4 and April 5 as of March 31.
CalendarEvent instances used in this sample are created for 2, 3, 4 and 5 days ahead of current date.
I'm using FireFox 19.0.2
Finally I found the issue. I don't know why but in the resent versions of Firefox, after 14 version, the gwt calendar(v 2.1) is repeating the printing of the calendar twice automatically, so when it prints the second time, it did it without the images inside the day bodies.
Solution: manually creation of code to stop the twice printing.

How to create an iOS Time Zone Picker?

My app is a logbook for pilots and I'd like to give the user the option of putting the app in the time zone of their choice. Airline pilots may fly across the world but have to reference their home base time zone when entering flight information. I want to offer a UI that allows them to select a time zone option such as "Local" (which is device local, depending on their location), "UTC", and then the hard one "custom".
I'm using MonoTouch.Dialog which allows you to wire up a collection but the problem is in iOS the list of time zones is rather long. I use the System.TimeZoneInfo namespace to retrieve the list of time zones just like in Windows. However, iOS uses a presentation such as "United States/New York, United States/XYZ, etc.". So to keep this list manageable I'm going to need to break this up by splitting on the / so I can first present a list of countries, the user will tap that and a secondary list will then present in a UITableView which is the regions such as "New York." I'll then capture the time zone and use the System.TimeZoneInfo methods to convert from UTC to the custom time zone.
My question is how, particularly in MonoTouch.Dialog, can I have a collection and then a sub-collection. i.e. a UITableView of Countries with a disclosure indicator that takes you to the regions for the country?
On this same note, has anyone else implemented a "time zone" selector/picker in iOS (Xcode or MonoTouch)?
Thank you for your ideas and help with this problem.
The following will get you the UI you are looking for:
var groups = from tz in TimeZoneInfo.GetSystemTimeZones ()
let name = tz.ToString ()
let idx = name.IndexOf ('/')
where idx != -1
let first = name.Substring (0, idx)
group tz by first into g
select new { Region = g.Key, Zones=g };
var root = new RootElement ("TimeZones"){
new Section ("Regions"){
from r in groups
select (Element) new RootElement (r.Region.ToString ()){
new Section () {
from z in r.Zones
select (Element) new StringElement (z.ToString ())
}
}
}
};
dvc = new DialogViewController (root);
It produces this UI:
(source: tirania.org)
And the nested elements look like this:
(source: tirania.org)
On this same note, has anyone else implemented a "time zone" selector/picker in iOS (Xcode or MonoTouch)?
I have not seen one doing exactly this. However this article shows you how to use UIPickerView to implement your own pickers (close to what you want). It should not be too hard to convert this into C#.
Once you have your own UITimeZonePicker then it should be easy to create a TimeZoneElement for MonoTouch.Dialog (mostly copy/pasting DateElement).

Resources