public interface

CanvasComplicationFactory

 androidx.wear.watchface.CanvasComplicationFactory

Gradle dependencies

compile group: 'androidx.wear.watchface', name: 'watchface', version: '1.1.0-rc01'

  • groupId: androidx.wear.watchface
  • artifactId: watchface
  • version: 1.1.0-rc01

Artifact androidx.wear.watchface:watchface:1.1.0-rc01 it located at Google repository (https://maven.google.com/)

Overview

Factory for creating a CanvasComplication. This decouples construction of Complications and their CanvasComplication renderers.

Summary

Methods
public CanvasComplicationcreate(WatchState watchState, CanvasComplication.InvalidateCallback invalidateCallback)

Creates a CanvasComplication.

Methods

public CanvasComplication create(WatchState watchState, CanvasComplication.InvalidateCallback invalidateCallback)

Creates a CanvasComplication. This will be called on a background thread, however all CanvasComplication rendering will be done on the UI thread and there's a memory barrier between construction and usage so no special threading primitives are required. If the CanvasComplication needs to share state with the Renderer then it should override onRendererCreated.

Parameters:

watchState: The current WatchState
invalidateCallback: The CanvasComplication.InvalidateCallback the constructed CanvasComplication can use to request redrawing. This is typically used in conjunction with asynchronous loading of Drawables to update the watch face once the drawable has loaded.

Returns:

The constructed CanvasComplication.

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.wear.watchface;

import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;

/**
 * Factory for creating a CanvasComplication. This decouples construction of Complications and
 * their CanvasComplication renderers.
 */
// TODO(b/188035300): Put links into the comments.
public interface CanvasComplicationFactory {
    /**
     * Creates a CanvasComplication. This will be called on a background thread, however all
     * CanvasComplication rendering will be done on the UI thread and there's a memory barrier
     * between construction and usage so no special threading primitives are required. If the
     * CanvasComplication needs to share state with the Renderer then it should override
     * onRendererCreated.
     *
     * @param watchState The current WatchState
     * @param invalidateCallback The CanvasComplication.InvalidateCallback the constructed
     * CanvasComplication can use to request redrawing. This is typically used in
     * conjunction with asynchronous loading of Drawables to update the watch face once the
     * drawable has loaded.
     * @return The constructed CanvasComplication.
     */
    @NonNull
    @WorkerThread
    @SuppressWarnings("ExecutorRegistration") // This is UI thread only.
    CanvasComplication create(
            @NonNull WatchState watchState,
            @NonNull CanvasComplication.InvalidateCallback invalidateCallback);
}