しっぽを追いかけて

ぐるぐるしながら考えています

Unity と猫の話題が中心   掲載内容は個人の私見であり、所属組織の見解ではありません

Xamarin.Forms で Microsoft Band に登録されたアプリタイルを取得する

Microsoft Band にアプリタイルを登録できたので、確認のために登録状態を再取得してみます

ソースコードの一式は下記にあります!

細かい実装などはこちらを参照ください

github.com

※ 順次改修していく予定なので、この記事の内容が現時点のソースより古い可能性があります


アプリタイルの管理クラスには必要な機能は 前回 実装済みなので、ViewModel を改修

/// <summary>
/// アプリタイル情報 ViewModel
/// </summary>
public class TilesViewModel : BindableBase
{
    ~ 中略 ~

    /// <summary>
    /// アプリタイル登録フラグ
    /// </summary>
    private bool existsTile = false;

    /// <summary>
    /// アプリタイル登録フラグ
    /// </summary>
    public bool ExistsTile
    {
        get { return this.existsTile; }
        set
        {
            this.SetProperty<bool>(ref this.existsTile, value);
            this.OnPropertyChanged("IsEnableTileManage");
        }
    }

    /// <summary>
    /// タイル変更可能フラグ
    /// </summary>
    public bool IsEnableTileManage
    {
        get { return !this.IsBusy && this.ExistsTile; }
    }

    /// <summary>
    /// タイルアイコン画像ソース
    /// </summary>
    private ImageSource icon = null;

    /// <summary>
    /// タイルアイコン画像ソース
    /// </summary>
    public ImageSource Icon
    {
        get { return this.icon; }
        set { this.SetProperty<ImageSource>(ref this.icon, value); }
    }

    /// <summary>
    /// タイル名称
    /// </summary>
    private string tileName = string.Empty;

    /// <summary>
    /// タイル名称
    /// </summary>
    public string TileName
    {
        get { return this.tileName; }
        set { this.SetProperty<string>(ref this.tileName, value); }
    }

    /// <summary>
    /// 基本色
    /// </summary>
    private ColorViewModel baseColor = new ColorViewModel();

    /// <summary>
    /// 基本色
    /// </summary>
    public ColorViewModel BaseColor
    {
        get { return this.baseColor; }
        set { this.SetProperty<ColorViewModel>(ref this.baseColor, value); }
    }

    ~ 中略 ~

    /// <summary>
    /// アプリタイル情報を取得する
    /// </summary>
    /// <returns>Task</returns>
    public async Task Pull()
    {
        this.IsBusy = true;
        var tiles = await this.manager.GetTilesAsync();
        if (tiles == null || !tiles.Any())
        {
            this.ExistsTile = false;
            this.IsBusy = false;
            return;
        }
        var tile = tiles.First();

        this.ExistsTile = true;
        this.Icon = tile.TileIconSource;
        this.TileName = tile.Name;

        this.BaseColor.Color = string.Format("#FF{0}{1}{2}",
            tile.Theme.Base.R.ToString("X2"),
            tile.Theme.Base.G.ToString("X2"),
            tile.Theme.Base.B.ToString("X2"));
        this.IsBusy = false;
    }

    ~ 中略 ~
}

アプリタイル管理クラスから情報を受け取ってそれをプロパティに反映します・・・XAML は前回と同じなので省略

さて追加した状態で情報を取得してみました!

f:id:matatabi_ux:20150503185515p:plain f:id:matatabi_ux:20150503185525p:plain

あれー?テーマカラーが取れていない・・・アプリタイル追加時にテーマカラーが設定できませんでしたが、Band 全体に適用されるオレンジ色ですらなく真っ黒!

それにブレークポイントをはってみたら、小さいアイコンも取れていないようでした

これは実装ミスかそれとも不具合か・・・?