public class

TileServiceCompat

extends java.lang.Object

 java.lang.Object

↳androidx.core.service.quicksettings.TileServiceCompat

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.15.0-alpha02'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.15.0-alpha02

Artifact androidx.core:core:1.15.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.core:core com.android.support:support-compat

Overview

A helper for accessing API methods.

Summary

Methods
public static voidclearTileServiceWrapper()

public static voidsetTileServiceWrapper(androidx.core.service.quicksettings.TileServiceCompat.TileServiceWrapper serviceWrapper)

public static voidstartActivityAndCollapse(TileService tileService, PendingIntentActivityWrapper wrapper)

Calls the correct #startActivityAndCollapse() method depending on the app's targeted .

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static void startActivityAndCollapse(TileService tileService, PendingIntentActivityWrapper wrapper)

Calls the correct #startActivityAndCollapse() method depending on the app's targeted .

public static void setTileServiceWrapper(androidx.core.service.quicksettings.TileServiceCompat.TileServiceWrapper serviceWrapper)

public static void clearTileServiceWrapper()

Source

/*
 * Copyright 2023 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.core.service.quicksettings;

import static android.os.Build.VERSION.SDK_INT;

import android.app.PendingIntent;
import android.content.Intent;
import android.service.quicksettings.TileService;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;

/**
 * A helper for accessing {@link TileService} API methods.
 */
public class TileServiceCompat {

    private static TileServiceWrapper sTileServiceWrapper;

    /**
     * Calls the correct {@link TileService}#startActivityAndCollapse() method
     * depending on the app's targeted {@link android.os.Build.VERSION_CODES}.
     */
    public static void startActivityAndCollapse(@NonNull TileService tileService,
            @NonNull PendingIntentActivityWrapper wrapper) {
        if (SDK_INT >= 34) {
            if (sTileServiceWrapper != null) {
                sTileServiceWrapper.startActivityAndCollapse(wrapper.getPendingIntent());
            } else {
                Api34Impl.startActivityAndCollapse(tileService, wrapper.getPendingIntent());
            }
        } else if (SDK_INT >= 24) {
            if (sTileServiceWrapper != null) {
                sTileServiceWrapper.startActivityAndCollapse(wrapper.getIntent());
            } else {
                Api24Impl.startActivityAndCollapse(tileService, wrapper.getIntent());
            }
        }
    }

    @RestrictTo(RestrictTo.Scope.LIBRARY)
    public static void setTileServiceWrapper(@NonNull TileServiceWrapper serviceWrapper) {
        sTileServiceWrapper = serviceWrapper;
    }

    @RestrictTo(RestrictTo.Scope.LIBRARY)
    public static void clearTileServiceWrapper() {
        sTileServiceWrapper = null;
    }

    @RequiresApi(34)
    private static class Api34Impl {
        static void startActivityAndCollapse(TileService service,
                PendingIntent pendingIntent) {
            service.startActivityAndCollapse(pendingIntent);
        }
    }

    @RequiresApi(24)
    private static class Api24Impl {
        static void startActivityAndCollapse(TileService service, Intent intent) {
            service.startActivityAndCollapse(intent);
        }
    }

    private TileServiceCompat() {
    }

    interface TileServiceWrapper {
        void startActivityAndCollapse(PendingIntent pendingIntent);

        void startActivityAndCollapse(Intent intent);
    }
}