List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.example.chu.myvideodemo.MusicService.java
public void play(boolean createNewNextTrack) { int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (D)//w ww. ja v a 2 s . com Log.d(TAG, "Starting playback: audio focus request status = " + status); if (status != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { return; } final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(intent); mAudioManager.registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mSession.setActive(true); if (createNewNextTrack) { setNextTrack(); } else { setNextTrack(mNextPlayPos); } if (mPlayer.isInitialized()) { final long duration = mPlayer.duration(); if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) { gotoNext(true); } mPlayer.start(); mPlayerHandler.removeMessages(FADEDOWN); mPlayerHandler.sendEmptyMessage(FADEUP); setIsSupposedToBePlaying(true, true); cancelShutdown(); //updateNotification(); notifyChange(META_CHANGED); } else if (mPlaylist.size() <= 0) { setShuffleMode(SHUFFLE_AUTO); } }
From source file:com.android.launcher2.AsyncTaskCallback.java
public void syncWidgetPageItems(final int page, final boolean immediate) { int numItemsPerPage = mWidgetCountX * mWidgetCountY; // Calculate the dimensions of each cell we are giving to each widget final ArrayList<Object> items = new ArrayList<Object>(); int contentWidth = mWidgetSpacingLayout.getContentWidth(); final int cellWidth = ((contentWidth - mPageLayoutPaddingLeft - mPageLayoutPaddingRight - ((mWidgetCountX - 1) * mWidgetWidthGap)) / mWidgetCountX); int contentHeight = mWidgetSpacingLayout.getContentHeight(); final int cellHeight = ((contentHeight - mPageLayoutPaddingTop - mPageLayoutPaddingBottom - ((mWidgetCountY - 1) * mWidgetHeightGap)) / mWidgetCountY); // Prepare the set of widgets to load previews for in the background int offset = (page - mNumAppsPages) * numItemsPerPage; for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) { items.add(mWidgets.get(i));// ww w. j a v a 2 s . co m } // Prepopulate the pages with the other widget info, and fill in the previews later final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page); layout.setColumnCount(layout.getCellCountX()); for (int i = 0; i < items.size(); ++i) { Object rawInfo = items.get(i); PendingAddItemInfo createItemInfo = null; PagedViewWidget widget = (PagedViewWidget) mLayoutInflater.inflate(R.layout.apps_customize_widget, layout, false); if (rawInfo instanceof AppWidgetProviderInfo) { // Fill in the widget information AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo; createItemInfo = new PendingAddWidgetInfo(info, null, null); // Determine the widget spans and min resize spans. int[] spanXY = Launcher.getSpanForWidget(mLauncher, info); createItemInfo.spanX = spanXY[0]; createItemInfo.spanY = spanXY[1]; int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, info); createItemInfo.minSpanX = minSpanXY[0]; createItemInfo.minSpanY = minSpanXY[1]; widget.applyFromAppWidgetProviderInfo(info, -1, spanXY); widget.setTag(createItemInfo); widget.setShortPressListener(this); } else if (rawInfo instanceof ResolveInfo) { // Fill in the shortcuts information ResolveInfo info = (ResolveInfo) rawInfo; createItemInfo = new PendingAddShortcutInfo(info.activityInfo); createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; createItemInfo.componentName = new ComponentName(info.activityInfo.packageName, info.activityInfo.name); widget.applyFromResolveInfo(mPackageManager, info); widget.setTag(createItemInfo); } widget.setOnClickListener(this); widget.setOnLongClickListener(this); widget.setOnTouchListener(this); widget.setOnKeyListener(this); // Layout each widget int ix = i % mWidgetCountX; int iy = i / mWidgetCountX; GridLayout.LayoutParams lp = new GridLayout.LayoutParams(GridLayout.spec(iy, GridLayout.LEFT), GridLayout.spec(ix, GridLayout.TOP)); lp.width = cellWidth; lp.height = cellHeight; lp.setGravity(Gravity.TOP | Gravity.LEFT); if (ix > 0) lp.leftMargin = mWidgetWidthGap; if (iy > 0) lp.topMargin = mWidgetHeightGap; layout.addView(widget, lp); } // wait until a call on onLayout to start loading, because // PagedViewWidget.getPreviewSize() will return 0 if it hasn't been laid out // TODO: can we do a measure/layout immediately? layout.setOnLayoutListener(new Runnable() { public void run() { // Load the widget previews int maxPreviewWidth = cellWidth; int maxPreviewHeight = cellHeight; if (layout.getChildCount() > 0) { PagedViewWidget w = (PagedViewWidget) layout.getChildAt(0); int[] maxSize = w.getPreviewSize(); maxPreviewWidth = maxSize[0]; maxPreviewHeight = maxSize[1]; } if (immediate) { AsyncTaskPageData data = new AsyncTaskPageData(page, items, maxPreviewWidth, maxPreviewHeight, null, null); loadWidgetPreviewsInBackground(null, data); onSyncWidgetPageItems(data); } else { if (mInTransition) { mDeferredPrepareLoadWidgetPreviewsTasks.add(this); } else { prepareLoadWidgetPreviewsTask(page, items, maxPreviewWidth, maxPreviewHeight, mWidgetCountX); } } } }); }
From source file:com.newsrob.EntryManager.java
public void maintainBootReceiverState() { final ComponentName cName = new ComponentName(ctx, BootReceiver.class); final PackageManager pm = ctx.getPackageManager(); final int newComponentState = isAutoSyncEnabled() ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if (pm.getComponentEnabledSetting(cName) != newComponentState) { Log.d(TAG, "Setting new component enabled state on BootReceiver: " + isAutoSyncEnabled()); pm.setComponentEnabledSetting(cName, newComponentState, PackageManager.DONT_KILL_APP); }/* w ww. j ava2 s. c o m*/ PL.log("EntryManager.maintainBootReceiverState(): Component enabled=" + pm.getComponentEnabledSetting(cName), ctx); }
From source file:com.grazerss.EntryManager.java
@SuppressWarnings("unchecked") public void maintainPremiumDependencies() { this.proVersion = null; if (false) {//from w w w . j a v a 2 s. c o m final int desiredComponentState = isProVersion() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; final Class[] componentsToDeactivate = { FireReceiver.class, MockEditSettingsActivity.class }; final PackageManager pm = ctx.getPackageManager(); for (final Class cls : componentsToDeactivate) { final ComponentName cName = new ComponentName(ctx, cls); pm.setComponentEnabledSetting(cName, desiredComponentState, PackageManager.DONT_KILL_APP); } } }
From source file:com.firefly.sample.castcompanionlibrary.cast.VideoCastManager.java
@SuppressLint("InlinedApi") private void setUpRemoteControl(final MediaInfo info) { if (!isFeatureEnabled(BaseCastManager.FEATURE_LOCKSCREEN)) { return;/*from w ww.j a va 2s . c o m*/ } LOGD(TAG, "setupRemoteControl() was called"); mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); ComponentName eventReceiver = new ComponentName(mContext, VideoIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(eventReceiver); if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat( PendingIntent.getBroadcast(mContext, 0, intent, 0)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.addToMediaRouter(mMediaRouter); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE); if (null == info) { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); return; } else { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } // Update the remote control's image updateLockScreenImage(info); // update the remote control's metadata updateLockScreenMetadata(); }
From source file:air.com.snagfilms.cast.chromecast.VideoChromeCastManager.java
@SuppressLint("InlinedApi") private void setUpRemoteControl(final MediaInfo info) { if (!isFeatureEnabled(BaseChromeCastManager.FEATURE_LOCKSCREEN)) { return;/*from w ww . j av a 2 s . co m*/ } Log.d(TAG, "setupRemoteControl() was called"); mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); ComponentName eventReceiver = new ComponentName(mContext, VideoIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(eventReceiver); if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat( PendingIntent.getBroadcast(mContext, 0, intent, 0)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.addToMediaRouter(mMediaRouter); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE); if (null == info) { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); return; } else { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } // Update the remote control's image updateLockScreenImage(info); // update the remote control's metadata updateLockScreenMetadata(); }
From source file:com.bluros.music.MusicService.java
public void play(boolean createNewNextTrack) { int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (D)//from w w w.ja v a 2 s . co m Log.d(TAG, "Starting playback: audio focus request status = " + status); if (status != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { return; } final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(intent); mAudioManager.registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mSession.setActive(true); if (createNewNextTrack) { setNextTrack(); } else { setNextTrack(mNextPlayPos); } if (mPlayer.isInitialized()) { final long duration = mPlayer.duration(); if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) { gotoNext(true); } mPlayer.start(); mPlayerHandler.removeMessages(FADEDOWN); mPlayerHandler.sendEmptyMessage(FADEUP); setIsSupposedToBePlaying(true, true); cancelShutdown(); updateNotification(); notifyChange(META_CHANGED); } else if (mPlaylist.size() <= 0) { setShuffleMode(SHUFFLE_AUTO); } }
From source file:mp.teardrop.PlaybackService.java
/** * Create a song notification. Call through the NotificationManager to * display it.// w w w . j a v a 2s . co m * * @param song The Song to display information about. * @param state The state. Determines whether to show paused or playing icon. */ public Notification createNotification(Song song, int state) { boolean playing = (state & FLAG_PLAYING) != 0; RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification); RemoteViews expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded); Bitmap cover = song.getCover(this); if (cover == null) { views.setImageViewResource(R.id.cover, R.drawable.fallback_cover); expanded.setImageViewResource(R.id.cover, R.drawable.fallback_cover); } else { views.setImageViewBitmap(R.id.cover, cover); expanded.setImageViewBitmap(R.id.cover, cover); } int playButton = getPlayButtonResource(playing); views.setImageViewResource(R.id.play_pause, playButton); expanded.setImageViewResource(R.id.play_pause, playButton); ComponentName service = new ComponentName(this, PlaybackService.class); Intent previous = new Intent(PlaybackService.ACTION_PREVIOUS_SONG); previous.setComponent(service); expanded.setOnClickPendingIntent(R.id.previous, PendingIntent.getService(this, 0, previous, 0)); Intent playPause = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK_NOTIFICATION); playPause.setComponent(service); views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0)); expanded.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0)); Intent next = new Intent(PlaybackService.ACTION_NEXT_SONG); next.setComponent(service); views.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0)); expanded.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0)); Intent close = new Intent(PlaybackService.ACTION_CLOSE_NOTIFICATION); close.setComponent(service); views.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0)); expanded.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0)); views.setTextViewText(R.id.title, song.title); views.setTextViewText(R.id.artist, song.artist); expanded.setTextViewText(R.id.title, song.title); expanded.setTextViewText(R.id.album, song.album); expanded.setTextViewText(R.id.artist, song.artist); Notification notification = new Notification(); notification.contentView = views; notification.icon = R.drawable.status_icon; notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.contentIntent = mNotificationAction; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // expanded view is available since 4.1 notification.bigContentView = expanded; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification.visibility = Notification.VISIBILITY_PUBLIC; } // if(mNotificationNag) { // if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // notification.priority = Notification.PRIORITY_MAX; // notification.vibrate = new long[0]; // needed to get headsup // } else { // notification.tickerText = song.title + " - " + song.artist; // } // } return notification; }
From source file:com.andrew.apollo.MusicPlaybackService.java
/** * Resumes or starts playback.// ww w . j av a 2 s. c o m */ public void play() { if (mAudioManager == null) { return; } stopSimplePlayer(); int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (D) LOG.info("Starting playback: audio focus request status = " + status); if (status != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { return; } try { mAudioManager.registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); } catch (SecurityException e) { e.printStackTrace(); // see explanation in initService } if (mPlayer != null && mPlayer.isInitialized()) { setNextTrack(); if (mShuffleEnabled && (mHistory.empty() || mHistory.peek() != mPlayPos)) { mHistory.push(mPlayPos); } final long duration = mPlayer.duration(); if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) { gotoNext(true); } mPlayer.start(); if (mPlayerHandler != null) { mPlayerHandler.removeMessages(FADE_DOWN); mPlayerHandler.sendEmptyMessage(FADE_UP); } if (!mIsSupposedToBePlaying) { mIsSupposedToBePlaying = true; notifyChange(PLAYSTATE_CHANGED); } cancelShutdown(); updateNotification(); } }
From source file:com.aniruddhc.acemusic.player.Services.AudioPlaybackService.java
/** * Updates all open homescreen/lockscreen widgets. *//*from w w w . jav a2 s .c o m*/ public void updateWidgets() { try { //Fire a broadcast message to the widget(s) to update them. Intent smallWidgetIntent = new Intent(mContext, SmallWidgetProvider.class); smallWidgetIntent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); int smallWidgetIds[] = AppWidgetManager.getInstance(mContext) .getAppWidgetIds(new ComponentName(mContext, SmallWidgetProvider.class)); smallWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, smallWidgetIds); mContext.sendBroadcast(smallWidgetIntent); Intent largeWidgetIntent = new Intent(mContext, LargeWidgetProvider.class); largeWidgetIntent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); int largeWidgetIds[] = AppWidgetManager.getInstance(mContext) .getAppWidgetIds(new ComponentName(mContext, LargeWidgetProvider.class)); largeWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, largeWidgetIds); mContext.sendBroadcast(largeWidgetIntent); Intent blurredWidgetIntent = new Intent(mContext, BlurredWidgetProvider.class); blurredWidgetIntent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); int blurredWidgetIds[] = AppWidgetManager.getInstance(mContext) .getAppWidgetIds(new ComponentName(mContext, BlurredWidgetProvider.class)); blurredWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, blurredWidgetIds); mContext.sendBroadcast(blurredWidgetIntent); Intent albumArtWidgetIntent = new Intent(mContext, AlbumArtWidgetProvider.class); albumArtWidgetIntent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); int albumArtWidgetIds[] = AppWidgetManager.getInstance(mContext) .getAppWidgetIds(new ComponentName(mContext, AlbumArtWidgetProvider.class)); albumArtWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, albumArtWidgetIds); mContext.sendBroadcast(albumArtWidgetIntent); } catch (Exception e) { e.printStackTrace(); } }