pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Guides

  • Table of Contents
  • App Resources
  • Appstore Publishing
  • Best Practices
  • Communication
    • Advanced Communication
    • Datalogging
    • PebbleKit Android
    • PebbleKit JS
    • PebbleKit iOS (Discontinued)
    • Sending and Receiving Data
    • Sports API
  • Debugging
  • Design and Interaction
  • Events and Services
  • Graphics and Animations
  • Migrating Older Apps
  • Pebble Packages
  • Pebble Timeline
  • Rocky.js
  • Smartstraps
  • Tools and Resources
  • User Interfaces

Sports API

すべての Pebble ウォッチには、Sports アプリと Golf アプリという 2 つの組み込みシステムウォッチアプリがあります。これらのアプリは、PebbleKit Android または PebbleKit iOS 経由で起動されるまで、ランチャーから非表示になっています。

どちらも、スポーツ関連のデータを一般的な形式で表示する汎用アプリとして設計されています。目標は、フィットネスやゴルフのモバイルアプリが Pebble と統合して、Pebble 用の追加アプリを作成および維持する必要なく、着用者にアクティビティに関するデータを表示できるようにすることです。このアプローチを使用する人気アプリの例は、Runkeeper アプリです。

Sports アプリと Golf アプリは、Android または iOS アプリの PebbleKit によって起動、終了、および制御されます。以下の各セクションに例を示します。どちらの場合も、入力可能なデータフィールドは異なりますが、データは同じ方法でプッシュされます。

利用可能なデータフィールド

Sports

aplite

basalt

chalk

Sports アプリは、サイクリングやランニングなど、幅広いスポーツに適用できるアクティビティの継続時間と距離を表示します。アプリの設定に応じてペースまたは速度を表示する、設定可能な 3 番目のフィールドも使用できます。Sports API では、各フィールドのラベルをメートル法(デフォルト)またはヤードポンド法単位で表示するようにアプリを設定することもできます。

アクションバーは、Select ボタンを使用してアクティビティセッションを一時停止および再開するようにユーザーに促すために使用されます。コンパニオンアプリは、これらのイベントをリッスンし、必要に応じて一時停止/再開操作を実装する責任があります。

Golf

aplite

basalt

chalk

Golf アプリは、パーとホール番号、およびフロント、ミッド、リアヤーデージなど、ゴルフゲームに関連するデータの表示に特化しています。

Sports アプリと同様に、アクションバーはコンパニオンアプリへの適切なフィードバックを可能にするために使用されます。この場合、アクションは「up」、「ball」、「down」イベントであり、コンパニオンは必要に応じてこれらを処理する必要があります。

PebbleKit Android での使用

Android アプリが PebbleKit Android をセットアップしたら、Sports アプリと Golf アプリを起動して、必要に応じてカスタマイズできます。

Sports と Golf の起動

Sports API アプリの 1 つを起動するには、startAppOnPebble() を呼び出して、Constants クラスから UUID を提供するだけです:

// Launch the Sports app
PebbleKit.startAppOnPebble(getApplicationContext(), Constants.SPORTS_UUID);

Sports のカスタマイズ

使用する単位タイプを選択するには、Constants クラスから希望する値を含む PebbleDictionary を構築して送信します。SPORTS_UNITS_IMPERIAL または SPORTS_UNITS_METRIC のいずれかを使用できます:

PebbleDictionary dict = new PebbleDictionary();

// Display imperial units
dict.addUint8(Constants.SPORTS_UNITS_KEY, Constants.SPORTS_UNITS_IMPERIAL);

PebbleKit.sendDataToPebble(getApplicationContext(), Constants.SPORTS_UUID, dict);

3 番目のフィールドのラベルとして「pace」または「speed」を選択するには、上記の例と同様の PebbleDictionary を構築して送信します。これは、単位選択と同じメッセージで実行できます:

PebbleDictionary dict = new PebbleDictionary();

// Display speed instead of pace
dict.addUint8(Constants.SPORTS_LABEL_KEY, Constants.SPORTS_DATA_SPEED);

PebbleKit.sendDataToPebble(getApplicationContext(), Constants.SPORTS_UUID, dict);

注意: Golf アプリにはカスタマイズ可能なフィールドはありません。

データの表示

現在のアクティビティに関するデータは、PebbleDictionary を使用して Sports API アプリのいずれかに送信できます。たとえば、Sports アプリで継続時間と距離の値を表示するには:

PebbleDictionary dict = new PebbleDictionary();

// Show a value for duration and distance
dict.addString(Constants.SPORTS_TIME_KEY, "12:52");
dict.addString(Constants.SPORTS_DISTANCE_KEY, "23.8");

PebbleKit.sendDataToPebble(getApplicationContext(), Constants.SPORTS_UUID, dict);

Constants ドキュメントを読んで、カスタマイズに使用できるすべての利用可能なパラメータについて学習してください。

ボタンイベントの処理

Sports API アプリの 1 つからボタンイベントが生成されると、メッセージが Android コンパニオンアプリに送信され、PebbleDataReceiver を使用して処理できます。たとえば、Sports アプリの状態の変化をリッスンするには、受信した PebbleDictionary で Constants.SPORTS_STATE_KEY を検索します。以下の例では、Android Toast を使用してユーザーに通知されます:

// Create a receiver for when the Sports app state changes
PebbleDataReceiver reciever = new PebbleKit.PebbleDataReceiver(
                                                        Constants.SPORTS_UUID) {

  @Override
  public void receiveData(Context context, int id, PebbleDictionary data) {
    // Always ACKnowledge the last message to prevent timeouts
    PebbleKit.sendAckToPebble(getApplicationContext(), id);

    // Get action and display as Toast
    Long value = data.getUnsignedIntegerAsLong(Constants.SPORTS_STATE_KEY);
    if(value != null) {
      int state = value.intValue();
      String text = (state == Constants.SPORTS_STATE_PAUSED)
                                                      ? "Resumed!" : "Paused!";
      Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
    }
  }

};

// Register the receiver
PebbleKit.registerReceivedDataHandler(getApplicationContext(), receiver);

PebbleKit iOS での使用

iOS アプリが PebbleKit iOS (Discontinued) をセットアップしたら、Sports アプリと Golf アプリを起動して、必要に応じてカスタマイズできます。コンパニオンアプリは、PBPebbleCentralDelegate のデリゲートとして自身を設定し、watchDidConnect: が発火したら PBWatch プロパティを割り当てる必要があります。この PBWatch オブジェクトは、Sports API アプリを操作するために使用されます。

これがどのように行われるかについては、PebbleKit iOS (Discontinued) ガイドの Becoming a Delegate を参照してください。

Sports と Golf の起動

Sports API アプリの 1 つを起動するには、必要に応じて sportsAppLaunch: または golfAppLaunch: を呼び出すだけです:

[self.watch sportsAppLaunch:^(PBWatch * _Nonnull watch,
                                                  NSError * _Nullable error) {
  NSLog(@"Sports app was launched");
}];

Sports のカスタマイズ

使用する単位タイプを選択するには、希望する isMetric BOOL で sportsAppSetMetric: を呼び出します:

BOOL isMetric = YES;

[self.watch sportsAppSetMetric:isMetric onSent:^(PBWatch * _Nonnull watch,
                                                 NSError * _Nonnull error) {
  if (!error) {
    NSLog(@"Successfully sent message.");
  } else {
    NSLog(@"Error sending message: %@", error);
  }
}];

3 番目のフィールドのラベルとして「pace」または「speed」を選択するには、希望する isPace BOOL で sportsAppSetLabel: を呼び出します:

BOOL isPace = YES;

[self.watch sportsAppSetLabel:isPace onSent:^(PBWatch * _Nonnull watch,
                                              NSError * _Nullable error) {
  if (!error) {
    NSLog(@"Successfully sent message.");
  } else {
    NSLog(@"Error sending message: %@", error);
  }
}];

注意: Golf アプリにはカスタマイズ可能なフィールドはありません。

データの表示

現在のアクティビティに関するデータは、sportsAppUpdate: または golfAppUpdate: を使用して Sports または Golf アプリのいずれかに送信できます。たとえば、Sports アプリで継続時間と距離の値を表示するには:

// Construct a dictionary of data
NSDictionary *update = @{ PBSportsTimeKey: @"12:34",
                          PBSportsDistanceKey: @"6.23" };

// Send the data to the Sports app
[self.watch sportsAppUpdate:update onSent:^(PBWatch * _Nonnull watch,
                                                  NSError * _Nullable error) {
  if (!error) {
    NSLog(@"Successfully sent message.");
  } else {
    NSLog(@"Error sending message: %@", error);
  }
}];

PBWatch ドキュメントを読んで、カスタマイズに使用できるすべての利用可能なメソッドと値について学習してください。

ボタンイベントの処理

Sports API アプリの 1 つからボタンイベントが生成されると、メッセージが Android コンパニオンアプリに送信され、sportsAppAddReceiveUpdateHandler を使用し、メッセージが受信されたときに実行されるブロックを提供することで処理できます。たとえば、Sports アプリの状態の変化をリッスンするには、提供された SportsAppActivityState の値を確認します:

// Register to get state updates from the Sports app
[self.watch sportsAppAddReceiveUpdateHandler:^BOOL(PBWatch *watch,
                                                SportsAppActivityState state) {
  // Display the new state of the watchapp
  switch (state) {
    case SportsAppActivityStateRunning:
      NSLog(@"Watchapp now running.");
      break;
    case SportsAppActivityStatePaused:
      NSLog(@"Watchapp now paused.");
      break;
    default: break;
  }

  // Finally
  return YES;
}];
You need JavaScript enabled to read and post comments.

Overview

  • 利用可能なデータフィールド
  • Sports
  • Golf
  • PebbleKit Android での使用
  • Sports と Golf の起動
  • Sports のカスタマイズ
  • データの表示
  • ボタンイベントの処理
  • PebbleKit iOS での使用
  • Sports と Golf の起動
  • Sports のカスタマイズ
  • データの表示
  • ボタンイベントの処理

Examples

  • PebbleKit Sports API Demos