com.google.android.glass.timeline.LiveCard Java Examples

The following examples show how to use com.google.android.glass.timeline.LiveCard. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimerLiveCardManager.java    From gdk-timer-sample with Apache License 2.0 6 votes vote down vote up
/** Starts a new {@link Timer}/{@link LiveCard} combination with the provided duration. */
public Timer startNewTimer(long durationMillis) {
    Timer timer = new Timer(durationMillis);
    TimerDrawer drawer = new TimerDrawer(mContext, timer);
    LiveCard liveCard = new LiveCard(mContext, timer.toString());

    liveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(drawer);
    liveCard.setVoiceActionEnabled(true);

    Intent menuIntent = new Intent(mContext, MenuActivity.class);
    menuIntent.setData(Uri.parse("glass.timer:" + timer.hashCode()));
    menuIntent.putExtra(TimerService.EXTRA_TIMER_HASH_CODE, timer.hashCode());
    liveCard.setAction(PendingIntent.getActivity(mContext, 0, menuIntent, 0));
    if (mContext instanceof Service) {
        liveCard.attach((Service) mContext);
    }
    liveCard.publish(PublishMode.REVEAL);
    timer.start();

    mTimers.put(timer, liveCard);
    return timer;
}
 
Example #2
Source File: MenuActivity.java    From gdk-timer-sample with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mFromLiveCardVoice = getIntent().getBooleanExtra(LiveCard.EXTRA_FROM_LIVECARD_VOICE, false);
    if (mFromLiveCardVoice) {
        // When activated by voice from a live card, enable voice commands. The menu
        // will automatically "jump" ahead to the items (skipping the guard phrase
        // that was already said at the live card).
        getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS);
    }

    // Bind to the Timer service to retrive the current timer's data.
    Intent serviceIntent = new Intent(this, TimerService.class);
    serviceIntent.putExtra(
        TimerService.EXTRA_TIMER_HASH_CODE,
        getIntent().getIntExtra(TimerService.EXTRA_TIMER_HASH_CODE, 0));
    serviceIntent.setData(getIntent().getData());
    bindService(serviceIntent, mConnection, 0);
}
 
Example #3
Source File: HudService.java    From Voidstar-AutoHud with Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (mLiveCard == null) {
        mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID);
        mRenderer = new HudRenderer(this, mObdManager);

        mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mRenderer);

        // Display the options menu when the live card is tapped.
        Intent menuIntent = new Intent(this, MenuActivity.class);
        menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));

        mLiveCard.publish(LiveCard.PublishMode.REVEAL);
    }

    return START_STICKY;
}
 
Example #4
Source File: TimerLiveCardManager.java    From gdk-timer-sample with Apache License 2.0 5 votes vote down vote up
/**
 * Stops the {@link Timer}/{@link LiveCard} and returns whether or not the manager is empty of
 * {@link Timer}.
 */
public boolean stopTimer(int timerHashCode) {
    Timer timer = findTimer(timerHashCode);

    if (timer != null) {
        LiveCard liveCard = mTimers.get(timer);

        liveCard.unpublish();
        timer.reset();
        mTimers.remove(timer);
    }
    return mTimers.isEmpty();
}
 
Example #5
Source File: TimerLiveCardManagerTest.java    From gdk-timer-sample with Apache License 2.0 5 votes vote down vote up
public void testStartNewTimer() {
    Timer timer = mManager.startNewTimer(INITIAL_DURATION_MILLIS);
    LiveCard liveCard = mManager.getLiveCard(timer);

    assertNotNull(timer);
    assertNotNull(liveCard);
    assertTrue(timer.isStarted());
    assertEquals(INITIAL_DURATION_MILLIS, timer.getDurationMillis());
    assertTrue(liveCard.isPublished());
}
 
Example #6
Source File: TimerLiveCardManager.java    From gdk-timer-sample with Apache License 2.0 4 votes vote down vote up
/** Returns the {@link LiveCard} associated with this {@link Timer}. */
public LiveCard getLiveCard(Timer timer) {
    return mTimers.get(timer);
}