当前位置: 首页>>代码示例>>Java>>正文


Java WearHelper类代码示例

本文整理汇总了Java中com.example.android.uamp.utils.WearHelper的典型用法代码示例。如果您正苦于以下问题:Java WearHelper类的具体用法?Java WearHelper怎么用?Java WearHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WearHelper类属于com.example.android.uamp.utils包,在下文中一共展示了WearHelper类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCustomAction

import com.example.android.uamp.utils.WearHelper; //导入依赖的package包/类
private void setCustomAction(PlaybackState.Builder stateBuilder) {
    MediaMetadata currentMusic = getCurrentPlayingMusic();
    if (currentMusic != null) {
        // Set appropriate "Favorite" icon on Custom action:
        String musicId = currentMusic.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
        int favoriteIcon = R.drawable.ic_star_off;
        if (mMusicProvider.isFavorite(musicId)) {
            favoriteIcon = R.drawable.ic_star_on;
        }
        LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ",
                musicId, " current favorite=", mMusicProvider.isFavorite(musicId));
        Bundle customActionExtras = new Bundle();
        WearHelper.setShowCustomActionOnWear(customActionExtras, true);
        stateBuilder.addCustomAction(new PlaybackState.CustomAction.Builder(
                CUSTOM_ACTION_THUMBS_UP, getString(R.string.favorite), favoriteIcon)
                .setExtras(customActionExtras)
                .build());
    }
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:20,代码来源:MusicService.java

示例2: setCustomAction

import com.example.android.uamp.utils.WearHelper; //导入依赖的package包/类
private void setCustomAction(PlaybackStateCompat.Builder stateBuilder) {
    MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic();
    if (currentMusic == null) {
        return;
    }
    // Set appropriate "Favorite" icon on Custom action:
    String mediaId = currentMusic.getDescription().getMediaId();
    if (mediaId == null) {
        return;
    }
    String musicId = MediaIDHelper.extractMusicIDFromMediaID(mediaId);
    int favoriteIcon = mMusicProvider.isFavorite(musicId) ?
            R.drawable.ic_star_on : R.drawable.ic_star_off;
    LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ",
            musicId, " current favorite=", mMusicProvider.isFavorite(musicId));
    Bundle customActionExtras = new Bundle();
    WearHelper.setShowCustomActionOnWear(customActionExtras, true);
    stateBuilder.addCustomAction(new PlaybackStateCompat.CustomAction.Builder(
            CUSTOM_ACTION_THUMBS_UP, mResources.getString(R.string.favorite), favoriteIcon)
            .setExtras(customActionExtras)
            .build());
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:23,代码来源:PlaybackManager.java

示例3: onGetRoot

import com.example.android.uamp.utils.WearHelper; //导入依赖的package包/类
@Override
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid,
                             Bundle rootHints) {
    LogHelper.d(TAG, "OnGetRoot: clientPackageName=" + clientPackageName,
            "; clientUid=" + clientUid + " ; rootHints=", rootHints);
    // To ensure you are not allowing any arbitrary app to browse your app's contents, you
    // need to check the origin:
    if (!mPackageValidator.isCallerAllowed(this, clientPackageName, clientUid)) {
        // If the request comes from an untrusted package, return null. No further calls will
        // be made to other media browsing methods.
        LogHelper.w(TAG, "OnGetRoot: IGNORING request from untrusted package "
                + clientPackageName);
        return null;
    }
    //noinspection StatementWithEmptyBody
    if (CarHelper.isValidCarPackage(clientPackageName)) {
        // Optional: if your app needs to adapt the music library to show a different subset
        // when connected to the car, this is where you should handle it.
        // If you want to adapt other runtime behaviors, like tweak ads or change some behavior
        // that should be different on cars, you should instead use the boolean flag
        // set by the BroadcastReceiver mCarConnectionReceiver (mIsConnectedToCar).
    }
    //noinspection StatementWithEmptyBody
    if (WearHelper.isValidWearCompanionPackage(clientPackageName)) {
        // Optional: if your app needs to adapt the music library for when browsing from a
        // Wear device, you should return a different MEDIA ROOT here, and then,
        // on onLoadChildren, handle it accordingly.
    }
    return new BrowserRoot(MEDIA_ID_ROOT, null);
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:31,代码来源:MusicService.java

示例4: onGetRoot

import com.example.android.uamp.utils.WearHelper; //导入依赖的package包/类
@Override
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid,
                             Bundle rootHints) {
    LogHelper.d(TAG, "OnGetRoot: clientPackageName=" + clientPackageName,
            "; clientUid=" + clientUid + " ; rootHints=", rootHints);
    // To ensure you are not allowing any arbitrary app to browse your app's contents, you
    // need to check the origin:
    if (!mPackageValidator.isCallerAllowed(this, clientPackageName, clientUid)) {
        // If the request comes from an untrusted package, return an empty browser root.
        // If you return null, then the media browser will not be able to connect and
        // no further calls will be made to other media browsing methods.
        LogHelper.i(TAG, "OnGetRoot: Browsing NOT ALLOWED for unknown caller. "
                + "Returning empty browser root so all apps can use MediaController."
                + clientPackageName);
        return new MediaBrowserServiceCompat.BrowserRoot(MEDIA_ID_EMPTY_ROOT, null);
    }
    //noinspection StatementWithEmptyBody
    if (CarHelper.isValidCarPackage(clientPackageName)) {
        // Optional: if your app needs to adapt the music library to show a different subset
        // when connected to the car, this is where you should handle it.
        // If you want to adapt other runtime behaviors, like tweak ads or change some behavior
        // that should be different on cars, you should instead use the boolean flag
        // set by the BroadcastReceiver mCarConnectionReceiver (mIsConnectedToCar).
    }
    //noinspection StatementWithEmptyBody
    if (WearHelper.isValidWearCompanionPackage(clientPackageName)) {
        // Optional: if your app needs to adapt the music library for when browsing from a
        // Wear device, you should return a different MEDIA ROOT here, and then,
        // on onLoadChildren, handle it accordingly.
    }

    return new BrowserRoot(MEDIA_ID_ROOT, null);
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:34,代码来源:MusicService.java

示例5: onCreate

import com.example.android.uamp.utils.WearHelper; //导入依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    LogHelper.d(TAG, "onCreate");

    mPlayingQueue = new ArrayList<>();
    mMusicProvider = new MusicProvider();
    mPackageValidator = new PackageValidator(this);

    // Start a new MediaSession
    mSession = new MediaSession(this, "MusicService");
    setSessionToken(mSession.getSessionToken());
    mSession.setCallback(new MediaSessionCallback());
    mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
        MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

    mPlayback = new LocalPlayback(this, mMusicProvider);
    mPlayback.setState(PlaybackState.STATE_NONE);
    mPlayback.setCallback(this);
    mPlayback.start();

    Context context = getApplicationContext();
    Intent intent = new Intent(context, NowPlayingActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mSession.setSessionActivity(pi);

    mSessionExtras = new Bundle();
    CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
    WearHelper.setSlotReservationFlags(mSessionExtras, true, true);
    WearHelper.setUseBackgroundFromTheme(mSessionExtras, true);
    mSession.setExtras(mSessionExtras);

    updatePlaybackState(null);

    mMediaNotificationManager = new MediaNotificationManager(this);
    mCastManager = VideoCastManager.getInstance();
    mCastManager.addVideoCastConsumer(mCastConsumer);
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
}
 
开发者ID:GeorgeMe,项目名称:UniversalAndroidMusicPlayer,代码行数:41,代码来源:MusicService.java

示例6: onGetRoot

import com.example.android.uamp.utils.WearHelper; //导入依赖的package包/类
@Override
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid,
                             Bundle rootHints) {
    LogHelper.d(TAG, "OnGetRoot: clientPackageName=" + clientPackageName,
            "; clientUid=" + clientUid + " ; rootHints=", rootHints);
    // To ensure you are not allowing any arbitrary app to browse your app's contents, you
    // need to check the origin:
    if (!mPackageValidator.isCallerAllowed(this, clientPackageName, clientUid)) {
        // If the request comes from an untrusted package, return null. No further calls will
        // be made to other media browsing methods.
        LogHelper.w(TAG, "OnGetRoot: IGNORING request from untrusted package "
                + clientPackageName);
        return null;
    }
    //noinspection StatementWithEmptyBody
    if (CarHelper.isValidCarPackage(clientPackageName)) {
        // Optional: if your app needs to adapt ads, music library or anything else that
        // needs to run differently when connected to the car, this is where you should handle
        // it.
    }
    //noinspection StatementWithEmptyBody
    if (WearHelper.isValidWearCompanionPackage(clientPackageName)) {
        // Optional: if your app needs to adapt the music library for when browsing from a
        // Wear device, you should return a different MEDIA ROOT here, and then,
        // on onLoadChildren, handle it accordingly.
    }
    return new BrowserRoot(MEDIA_ID_ROOT, null);
}
 
开发者ID:GeorgeMe,项目名称:UniversalAndroidMusicPlayer,代码行数:29,代码来源:MusicService.java

示例7: onCreate

import com.example.android.uamp.utils.WearHelper; //导入依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    LogHelper.d(TAG, "onCreate");

    mPlayingQueue = new ArrayList<>();
    mMusicProvider = new MusicProvider();
    mPackageValidator = new PackageValidator(this);

    // Start a new MediaSession
    mSession = new MediaSession(this, "MusicService");
    setSessionToken(mSession.getSessionToken());
    mSession.setCallback(new MediaSessionCallback());
    mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
        MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

    mPlayback = new LocalPlayback(this, mMusicProvider);
    mPlayback.setState(PlaybackState.STATE_NONE);
    mPlayback.setCallback(this);
    mPlayback.start();

    Context context = getApplicationContext();
    Intent intent = new Intent(context, NowPlayingActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mSession.setSessionActivity(pi);

    mSessionExtras = new Bundle();
    CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
    WearHelper.setSlotReservationFlags(mSessionExtras, true, true);
    WearHelper.setUseBackgroundFromTheme(mSessionExtras, true);
    mSession.setExtras(mSessionExtras);

    updatePlaybackState(null);

    mMediaNotificationManager = new MediaNotificationManager(this);
    mCastManager = VideoCastManager.getInstance();
    mCastManager.addVideoCastConsumer(mCastConsumer);
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());

    IntentFilter filter = new IntentFilter(CarHelper.ACTION_MEDIA_STATUS);
    mCarConnectionReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String connectionEvent = intent.getStringExtra(CarHelper.MEDIA_CONNECTION_STATUS);
            mIsConnectedToCar = CarHelper.MEDIA_CONNECTED.equals(connectionEvent);
            LogHelper.i(TAG, "Connection event to Android Auto: ", connectionEvent,
                    " isConnectedToCar=", mIsConnectedToCar);
        }
    };
    registerReceiver(mCarConnectionReceiver, filter);
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:53,代码来源:MusicService.java


注:本文中的com.example.android.uamp.utils.WearHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。