• controller 이름 바꾸는 방법은 

안에서 controller 이름을 클릭후 변경가능

  • (간단하게 canvas의 요소를 controller코드상에서 outlet으로 연결하는 방법)

You’re going to make an outlet for this text field on the PlayerDetailsViewController using the Assistant Editor feature of Xcode. While still in the storyboard, open the Assistant Editor with the button from the toolbar (the one at the top right with two intertwining rings). It should automatically open on PlayerDetailsViewController.swift (if it doesn’t, use the jumpbar in the right hand split window to select PlayerDetailsViewController.swift).

Select the new text field and ctrl-drag(오르쪽클릭은 outlet,왼쪽클릭은 action) to the top of PlayersDetailViewController, just below the class definition. When the popup appears, name the new outlet nameTextField, and click Connect. Xcode will add the property to the PlayersDetailViewController class and connect it in the storyboard:


  • static cells: they only work in UITableViewController. Even though Interface Builder will let you add them to a table view inside a regular UIViewController, this won’t work during runtime.

  • (특정 요소를 first responder 로 만드는 방법 )

To avoid this, let a tap anywhere inside the row bring up the keyboard. OpenPlayerDetailsViewController.swift and add the following extension to the end of the file:

// MARK: - UITableViewDelegate
extension PlayerDetailsViewController {

  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.section == 0 {

If the user taps the first cell, the app should activate the text field. There’s only one cell in the section so you only need to test for the section index. Making the text field the first responder will automatically bring up the keyboard.


original source : http://www.androiddocs.com/training/wearables/ui/lists.html

Creating Lists

Lists let users select an item from a set of choices easily on wearable devices.

The Wearable UI Library includes the WearableListView class .

To create a list in your Android Wear apps:

  1. Add a WearableListView element to your activity’s layout definition.
  2. Create a custom layout implementation for your list items.
  3. Use this implementation to create a layout definition file for your list items.
  4. Create an adapter to populate the list.
  5. Assign the adapter to the WearableListView element

Add a List View




Create a Layout Implementation for List Items

This layout also implements the methods in the WearableListView.OnCenterProximityListener interface to change the color of the item’s icon and fade the text in response to events from WearableListView as the user scrolls through the list.

public class WearableListItemLayout extends LinearLayout
            implements WearableListView.OnCenterProximityListener {

   private ImageView mCircle;
   private TextView mName;

   private final float mFadedTextAlpha;
   private final int mFadedCircleColor;
   private final int mChosenCircleColor;

   public WearableListItemLayout(Context context) {
       this(context, null);

   public WearableListItemLayout(Context context, AttributeSet attrs) {
       this(context, attrs, 0);

   public WearableListItemLayout(Context context, AttributeSet attrs,
                                 int defStyle) {
       super(context, attrs, defStyle);

       mFadedTextAlpha = getResources()
                        .getInteger(R.integer.action_text_faded_alpha) / 100f;
       mFadedCircleColor = getResources().getColor(R.color.grey);
       mChosenCircleColor = getResources().getColor(R.color.blue);

   // Get references to the icon and text in the item layout definition
   protected void onFinishInflate() {
       // These are defined in the layout file for list items
       // (see next section)
       mCircle = (ImageView) findViewById(R.id.circle);
       mName = (TextView) findViewById(R.id.name);

   public void onCenterPosition(boolean animate) {
       ((GradientDrawable) mCircle.getDrawable()).setColor(mChosenCircleColor);

   public void onNonCenterPosition(boolean animate) {
       ((GradientDrawable) mCircle.getDrawable()).setColor(mFadedCircleColor);

Create a Layout Definition for Items



Create an Adapter to Populate the List

private static final class Adapter extends WearableListView.Adapter {
   private String[] mDataset;
   private final Context mContext;
   private final LayoutInflater mInflater;

   // Provide a suitable constructor (depends on the kind of dataset)
   public Adapter(Context context, String[] dataset) {
       mContext = context;
       mInflater = LayoutInflater.from(context);
       mDataset = dataset;

   // Provide a reference to the type of views you're using
   public static class ItemViewHolder extends WearableListView.ViewHolder {
       private TextView textView;
       public ItemViewHolder(View itemView) {
           // find the text view within the custom item's layout
           textView = (TextView) itemView.findViewById(R.id.name);

   // Create new views for list items
   // (invoked by the WearableListView's layout manager)
   public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                         int viewType) {
       // Inflate our custom layout for list items
       return new ItemViewHolder(mInflater.inflate(R.layout.list_item, null));

   // Replace the contents of a list item
   // Instead of creating new views, the list tries to recycle existing ones
   // (invoked by the WearableListView's layout manager)
   public void onBindViewHolder(WearableListView.ViewHolder holder,
                                int position) {
       // retrieve the text view
       ItemViewHolder itemHolder = (ItemViewHolder) holder;
       TextView view = itemHolder.textView;
       // replace text contents
       // replace list item's metadata

   // Return the size of your dataset
   // (invoked by the WearableListView's layout manager)
   public int getItemCount() {
       return mDataset.length;

Associate the Adapter and Set a Click Listener

public class WearActivity extends Activity
                         implements WearableListView.ClickListener {

   // Sample dataset for the list
   String[] elements = { "List Item 1", "List Item 2", ... };

   protected void onCreate(Bundle savedInstanceState) {

       // Get the list component from the layout of the activity
       WearableListView listView =
           (WearableListView) findViewById(R.id.wearable_list);

       // Assign an adapter to the list
       listView.setAdapter(new Adapter(this, elements));

       // Set a click listener

   // WearableListView click listener
   public void onClick(WearableListView.ViewHolder v) {
       Integer tag = (Integer) v.itemView.getTag();
       // use this data to complete some action ...

   public void onTopEmptyRegionClick() {

original source: http://www.androiddocs.com/training/wearables/notifications/pages.html

Adding Pages to a Notification

additional pages appear immediately to the right of the main notification card.

To create a notification with multiple pages:

  1. Create the main notification (the first page) with NotificationCompat.Builder, in the way you’d like the notification to appear on a handset.
  2. Create the additional pages for the wearable with NotificationCompat.Builder.
  3. Apply the pages to the main notification with the addPage() method or add multiple pages in a Collectionwith the addPages() method.

// Create builder for the main notification
NotificationCompat.Builder notificationBuilder =
       new NotificationCompat.Builder(this)
       .setContentTitle("Page 1")
       .setContentText("Short message")

// Create a big text style for the second page
BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
secondPageStyle.setBigContentTitle("Page 2")
              .bigText("A lot of text...");

// Create second page notification
Notification secondPageNotification =
       new NotificationCompat.Builder(this)

// Extend the notification builder with the second page
Notification notification = notificationBuilder
       .extend(new NotificationCompat.WearableExtender()

// Issue the notification
notificationManager =
notificationManager.notify(notificationId, notification);

original source :http://www.androiddocs.com/training/wearables/notifications/voice-input.html

Receiving Voice Input in a Notification

If you have handheld notifications that include an action to input text, such as reply to an email, it should normally launch an activity on the handheld device to input the text. However, when your notification appears on a wearable, there is no keyboard input, so you can let users dictate a reply or provide pre-defined text messages using RemoteInput.

When users reply with voice or select one of the available messages, the system attaches the text response to the Intentyou specified for the notification action and sends that intent to your handheld app.

Define the Voice Input

To create an action that supports voice input, create an instance of


that you can add to your notification action. This class’s constructor accepts a string that the system uses as the key for the voice input, which you’ll later use to retrieve the text of the input in your handheld app.For example, here’s how to create a


object that provides a custom label for the voice input prompt:

// Key for the string that's delivered in the action's intent
private static final String EXTRA_VOICE_REPLY = "extra_voice_reply";

String replyLabel = getResources().getString(R.string.reply_label);

RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)

Add Pre-defined Text Responses



<?xml version="1.0" encoding="utf-8"?>
   <string-array name="reply_choices">
public static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
String replyLabel = getResources().getString(R.string.reply_label);
String[] replyChoices = getResources().getStringArray(R.array.reply_choices);

RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)

Add the Voice Input as a Notification Action

// Create an intent for the reply action
Intent replyIntent = new Intent(this, ReplyActivity.class);
PendingIntent replyPendingIntent =
       PendingIntent.getActivity(this, 0, replyIntent,

// Create the reply action and add the remote input
NotificationCompat.Action action =
       new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,
               getString(R.string.label), replyPendingIntent)

// Build the notification and add the action via WearableExtender
Notification notification =
       new NotificationCompat.Builder(mContext)
               .extend(new WearableExtender().addAction(action))

// Issue the notification
NotificationManagerCompat notificationManager =
notificationManager.notify(notificationId, notification);

Receiving the Voice Input as a String

(notification은 sync와는 달리 일방통행이라고 하지만 reply action intent를 통해 reply message를 전달 받을수 있다. )

To receive the user’s transcribed message in the activity you declared in the reply action’s intent, call


, passing in the “Reply” action’s intent. This method returns a


that contains the text response. You can then query the


to obtain the response.


Do not use


to obtain the voice result, because the voice input is stored as


. The


method provides a convenient way to receive a character sequence without having to process the



* Obtain the intent that started this activity by calling
* Activity.getIntent() and pass it into this method to
* get the associated voice input string.

private CharSequence getMessageText(Intent intent) {
   Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
   if (remoteInput != null) {
       return remoteInput.getCharSequence(EXTRA_VOICE_REPLY);
   return null;

original source : http://www.androiddocs.com/training/wearables/notifications/creating.html

Creating a Notification for Wearables

NotificationCompat.Builder 을 사용하면 기본적으로 mobile, wearable 기기에 전달될 기본 notification을 만들수 있다.

Import the necessary classes


compile "com.android.support:support-v4:20.0.+"
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.NotificationCompat.WearableExtender;

Create Notifications with the Notification Builder

int notificationId = 001;
// Build intent for notification content
Intent viewIntent = new Intent(this, ViewEventActivity.class);
viewIntent.putExtra(EXTRA_EVENT_ID, eventId);
PendingIntent viewPendingIntent =
       PendingIntent.getActivity(this, 0, viewIntent, 0);

NotificationCompat.Builder notificationBuilder =
       new NotificationCompat.Builder(this)

// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =

// Build the notification and issues it with notification manager.
notificationManager.notify(notificationId, notificationBuilder.build());

When this notification appears on a handheld device, the user can invoke the PendingIntent specified by the setContentIntent() method by touching the notification. When this notification appears on an Android wearable, the user can swipe the notification to the left to reveal the Open action, which invokes the intent on the handheld device.

Add Action Buttons

// Build an intent for an action to view a map
Intent mapIntent = new Intent(Intent.ACTION_VIEW);
Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode(location));
PendingIntent mapPendingIntent =
       PendingIntent.getActivity(this, 0, mapIntent, 0);

NotificationCompat.Builder notificationBuilder =
       new NotificationCompat.Builder(this)
               getString(R.string.map), mapPendingIntent);

On a handheld, the action appears as an additional button attached to the notification. On a wearable, the action appears as a large button when the user swipes the notification to the left. When the user taps the action, the associated intent is invoked on the handheld.

Specify Wearable-only Actions

If you want the actions available on the wearable to be different from those on the handheld, then use WearableExtender.addAction(). Once you add an action with this method, the wearable does not display any other actions added with NotificationCompat.Builder.addAction(). That is, only the actions added with WearableExtender.addAction() appear on the wearable and they do not appear on the handheld.

// Create an intent for the reply action
Intent actionIntent = new Intent(this, ActionActivity.class);
PendingIntent actionPendingIntent =
       PendingIntent.getActivity(this, 0, actionIntent,

// Create the action
NotificationCompat.Action action =
       new NotificationCompat.Action.Builder(R.drawable.ic_action,
               getString(R.string.label), actionPendingIntent)

// Build the notification and add the action via WearableExtender
Notification notification =
       new NotificationCompat.Builder(mContext)
               .extend(new WearableExtender().addAction(action))

Add a Big View

To add the extended content to your notification, call setStyle() on the NotificationCompat.Builder object, passing it an instance of eitherBigTextStyle or InboxStyle.

// Specify the 'big view' content to display the long
// event description that may not fit the normal content text.
BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();

NotificationCompat.Builder notificationBuilder =
       new NotificationCompat.Builder(this)
               getResources(), R.drawable.notif_background))
               getString(R.string.map), mapPendingIntent)

Add Wearable Features For a Notification


setHintHideIcon(), setBackground()

  1. Create an instance of a WearableExtender, setting the wearable-specific options for the notication.
  2. Create an instance of NotificationCompat.Builder, setting the desired properties for your notification as described earlier in this lesson.
  3. Call extend() on the notification and pass in the WearableExtender. This applies the wearable options to the notification.
  4. Call build() to build the notification.
// Create a WearableExtender to add functionality for wearables
NotificationCompat.WearableExtender wearableExtender =
       new NotificationCompat.WearableExtender()

// Create a NotificationCompat.Builder to build a standard notification
// then extend it with the WearableExtender
Notification notif = new NotificationCompat.Builder(mContext)
       .setContentTitle("New mail from " + sender)

Note: The bitmap that you use with setBackground() should have a resolution of 400×400 for non-scrolling backgrounds and 640×400 for backgrounds that support parallax scrolling. Place these bitmap images in the res/drawable-nodpi directory. Place other non-bitmap resources for wearable notifications, such as those used with the setContentIcon() method, in the res/drawable-hdpi directory.

If you ever need to read wearable-specific options at a later time, use the corresponding get method for the option. This example calls the getHintHideIcon()

NotificationCompat.WearableExtender wearableExtender =
       new NotificationCompat.WearableExtender(notif);
boolean hintHideIcon = wearableExtender.getHintHideIcon();

Deliver the Notification

When you want to deliver your notifications, always use the NotificationManagerCompat API instead ofNotificationManager:

// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =

// Issue the notification with notification manager.
notificationManager.notify(notificationId, notif);