List of usage examples for android.content Context AUDIO_SERVICE
String AUDIO_SERVICE
To view the source code for android.content Context AUDIO_SERVICE.
Click Source Link
From source file:se.erichansander.retrotimer.TimerKlaxon.java
private void play(boolean ring, boolean vibrate) { TinyTracelog.trace("5"); // stop() checks to see if we are already playing. stop();//w w w . j a v a2 s. co m if (ring) { TinyTracelog.trace("5.1"); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setOnErrorListener(new OnErrorListener() { public boolean onError(MediaPlayer mp, int what, int extra) { TinyTracelog.trace("5.1.e1"); stop(); return true; } }); try { /* * Check if we are in a call. If we are, use the in-call alarm * resource at a low volume to not disrupt the call. */ if (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) { TinyTracelog.trace("5.1.1"); mMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME); setDataSourceFromResource(getResources(), mMediaPlayer, R.raw.in_call_alarm); } else { TinyTracelog.trace("5.1.2"); setDataSourceFromResource(getResources(), mMediaPlayer, R.raw.classic_alarm); } } catch (Exception ex) { // Failed to set data source. Not much we can do to save // the situation though... TinyTracelog.trace("5.1.e2"); } try { final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // do not play alarms if stream volume is 0 int volume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM); TinyTracelog.trace("5.1.3 " + volume); if (volume != 0) { mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mMediaPlayer.setLooping(true); mMediaPlayer.prepare(); if (mAudioFocusHelper != null) { mAudioFocusHelper.requestFocus(); } mMediaPlayer.start(); } } catch (Exception ex) { // Failed to play ring tone. Not much we can do to save // the situation though... TinyTracelog.trace("5.1.e3"); } } /* Start the vibrator after everything is ok with the media player */ if (vibrate) { TinyTracelog.trace("5.2"); mVibrator.vibrate(sVibratePattern, 0); } else { mVibrator.cancel(); } mPlaying = true; }
From source file:com.example.mydemos.view.RingtonePickerActivity.java
/** Called when the activity is first created. */ @Override/* w w w. j a v a2 s. c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.ringtone_picker); CharSequence sysTitle = (CharSequence) getResources().getText(R.string.sys_tone); CharSequence MusicTitle = (CharSequence) getResources().getText(R.string.sd_music); CharSequence RecordTitle = (CharSequence) getResources().getText(R.string.record_tone); Intent intent = getIntent(); toneType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1); Log.e("duwenhua", "ringPick get toneType:" + toneType); //! by duwenhua //if(toneType == RingtoneManager.TYPE_RINGTONE_SECOND) // toneType = RINGTONE_TYPE; //! by duwenhua mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); //Log.i("lys", "mUriForDefaultItem == " + mUriForDefaultItem); if (savedInstanceState != null) { mSelectedId = savedInstanceState.getLong(SAVE_CLICKED_POS, -1); } //Log.i("lys", "mUriForDefaultItem 1== " + mUriForDefaultItem+", mSelectedId =="+mSelectedId); mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); //if(mUriForDefaultItem != null) //{ // mSelectedId = ContentUris.parseId(mUriForDefaultItem); //} //Log.i("lys", "RingtonePickerActivity.java onCreate mExistingUri == " + mExistingUri); //String action = getIntent().getAction(); //Log.i("lys", "PT Intent action == " + action); if (toneType == NOTIFICATION_TYPE) { mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI; } else if (toneType == RINGTONE_TYPE) { mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI; } else if (toneType == ALARM_TYPE) { mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI; } if (isAvailableToCheckRingtone() == true) { Ringtone ringtone_DefaultItem = checkRingtone_reflect(this, mUriForDefaultItem, toneType); if (ringtone_DefaultItem != null && ringtone_DefaultItem.getUri() != null) { mUriForDefaultItem = ringtone_DefaultItem.getUri(); Log.i("lys", "RingtoneManager.getRingtone mUriForDefaultItem== " + mUriForDefaultItem); } else { //mUriForDefaultItem = 'content/medial/'; /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard start */ String originalRingtone = Settings.System.getString(getApplicationContext().getContentResolver(), "ringtone_original"); if (originalRingtone != null && !TextUtils.isEmpty(originalRingtone)) { mUriForDefaultItem = Uri.parse(originalRingtone); Log.e("liyang", "select riongtone error ,change to originalRingtone == " + mExistingUri); } /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard end */ Log.i("lys", "mUriForDefaultItem set as default mUriForDefaultItem== 222"); } if (mExistingUri != null) { Ringtone ringtone = checkRingtone_reflect(this, mExistingUri, toneType); if (ringtone != null && ringtone.getUri() != null) { //mUriForDefaultItem = ringtone.getUri(); mExistingUri = ringtone.getUri(); Log.i("lys", "RingtoneManager.getRingtone mExistingUri== " + mExistingUri); } else { mExistingUri = mUriForDefaultItem; Log.i("lys", "mExistingUri set as default mExistingUri== " + mExistingUri); } } } boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false); Log.e("lys", "includeDrm ==" + includeDrm); mRingtoneManager = new RingtoneManager(this); mRingtoneManager.setIncludeDrm(includeDrm); if (toneType != -1) { mRingtoneManager.setType(toneType); } setVolumeControlStream(mRingtoneManager.inferStreamType()); // toneActivityType = mRingtoneManager.getActivityType(); if (toneType == ALARM_TYPE) { sysTitle = (CharSequence) getResources().getText(R.string.alarm_tone); } else if (toneType == NOTIFICATION_TYPE) { sysTitle = (CharSequence) getResources().getText(R.string.notification_tone); } listView = new ListView(this); listView.setOnItemClickListener(this); //listView.setBackgroundColor(#ff5a5a5a); listView.setFastScrollEnabled(true); //listView.setFastScrollAlwaysVisible(true); listView.setEmptyView(findViewById(android.R.id.empty)); //mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); //mHasDefaultItem = true; //temp if (mHasDefaultItem) { //chengcheng addDefaultStaticItem(listView, com.android.internal.R.string.ringtone_default); } setDefaultRingtone(); if (mHasSilentItem) { // chengcheng addSilendStaticItem(listView, com.android.internal.R.string.ringtone_silent); } audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mAudioFocusListener = new OnAudioFocusChangeListener() { public void onAudioFocusChange(int focusChange) { } }; okBtn = (Button) findViewById(R.id.ok); okBtn.setOnClickListener(this); cancelBtn = (Button) findViewById(R.id.cancel); cancelBtn.setOnClickListener(this); TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); mTabHost.addTab(mTabHost.newTabSpec("tab_system").setIndicator(sysTitle, null).setContent(this)); mTabHost.addTab(mTabHost.newTabSpec("tab_music").setIndicator(MusicTitle, null).setContent(this)); mTabHost.addTab(mTabHost.newTabSpec("tab_record").setIndicator(RecordTitle, null).setContent(this)); mTabHost.setCurrentTab(0); mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { // stopMediaPlayer(); createTabContent(tabId); } }); }
From source file:com.bliex.android.lockpatternlib.PatternView.java
public PatternView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternView, defStyleAttr, 0); final String aspect = a.getString(R.styleable.PatternView_pl_aspect); if ("square".equals(aspect)) { mAspect = ASPECT_SQUARE;/*from www . j av a2 s .c om*/ } else if ("lock_width".equals(aspect)) { mAspect = ASPECT_LOCK_WIDTH; } else if ("lock_height".equals(aspect)) { mAspect = ASPECT_LOCK_HEIGHT; } else { mAspect = ASPECT_SQUARE; } setClickable(true); mPathPaint.setAntiAlias(true); mPathPaint.setDither(true); // Removed since every developer should set their own patternViewStyle. //mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color); //mErrorColor = context.getColor(R.color.lock_pattern_view_error_color); //mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color); mRegularColor = a.getColor(R.styleable.PatternView_pl_regularColor, mRegularColor); mErrorColor = a.getColor(R.styleable.PatternView_pl_errorColor, mErrorColor); mSuccessColor = a.getColor(R.styleable.PatternView_pl_successColor, mSuccessColor); a.recycle(); mPathPaint.setStyle(Paint.Style.STROKE); mPathPaint.setStrokeJoin(Paint.Join.ROUND); mPathPaint.setStrokeCap(Paint.Cap.ROUND); mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width); mPathPaint.setStrokeWidth(mPathWidth); mDotSize = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size); mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated); mPaint.setAntiAlias(true); mPaint.setDither(true); mCellStates = new CellState[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { mCellStates[i][j] = new CellState(); mCellStates[i][j].radius = mDotSize / 2; mCellStates[i][j].row = i; mCellStates[i][j].col = j; } } mFastOutSlowInInterpolator = new FastOutSlowInInterpolator(); mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator(); mExploreByTouchHelper = new PatternExploreByTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper); mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); }
From source file:com.mobileman.moments.android.frontend.activity.IncomingCallActivity.java
private void playRingtone() { AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); if ((audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) || (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0)) { vibrate();/*w ww .j a v a2 s . co m*/ delayHandler = new Handler(); delayHandler.postDelayed(new Runnable() { public void run() { sendNotificationAndFinish(); } }, MAXIMUM_CALL_NOTIFICATION_DURATION); } else if (audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) { if (mPlayer == null) { mPlayer = MediaPlayer.create(getApplicationContext(), R.raw.moments_30s); // mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer) { sendNotificationAndFinish(); } }); mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mediaPlayer, int i, int i2) { sendNotificationAndFinish(); return false; } }); mPlayer.start(); } } }
From source file:com.zwj.customview.gesturelock.PatternView.java
public PatternView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternView, defStyleAttr, 0); mRowCount = a.getInteger(R.styleable.PatternView_pl_rowCount, PATTERN_SIZE_DEFAULT); mColumnCount = a.getInteger(R.styleable.PatternView_pl_columnCount, PATTERN_SIZE_DEFAULT); final String aspect = a.getString(R.styleable.PatternView_pl_aspect); if ("square".equals(aspect)) { mAspect = ASPECT_SQUARE;// w w w.j a v a2 s.c om } else if ("lock_width".equals(aspect)) { mAspect = ASPECT_LOCK_WIDTH; } else if ("lock_height".equals(aspect)) { mAspect = ASPECT_LOCK_HEIGHT; } else { mAspect = ASPECT_SQUARE; } setClickable(true); mPathPaint.setAntiAlias(true); mPathPaint.setDither(true); // Removed since every developer should set their own patternViewStyle. //mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color); //mErrorColor = context.getColor(R.color.lock_pattern_view_error_color); //mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color); mRegularColor = a.getColor(R.styleable.PatternView_pl_regularColor, mRegularColor); mErrorColor = a.getColor(R.styleable.PatternView_pl_errorColor, mErrorColor); mSuccessColor = a.getColor(R.styleable.PatternView_pl_successColor, mSuccessColor); // int excircleColor = a.getColor(R.styleable.PatternView_excircle_color, Color.WHITE); // ? mExcircleRadius = a.getDimensionPixelSize(R.styleable.PatternView_excircle_radius, getResources().getDimensionPixelSize(R.dimen.pl_pattern_excircle_radius)); // TODO ?????View???? mDotRadius = a.getDimensionPixelSize(R.styleable.PatternView_dot_radius, getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size)); mDotRadiusActivated = a.getDimensionPixelSize(R.styleable.PatternView_dot_activated_radius, getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_size_activated)); a.recycle(); mPathPaint.setStyle(Paint.Style.STROKE); mPathPaint.setStrokeJoin(Paint.Join.ROUND); mPathPaint.setStrokeCap(Paint.Cap.ROUND); mPathWidth = getResources().getDimensionPixelSize(R.dimen.pl_pattern_dot_line_width); mPathPaint.setStrokeWidth(mPathWidth); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaintExcircle.setAntiAlias(true); mPaintExcircle.setDither(true); mPaintExcircle.setColor(excircleColor); updatePatternSize(); mFastOutSlowInInterpolator = new FastOutSlowInInterpolator(); mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator(); mExploreByTouchHelper = new PatternExploreByTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper); mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); }
From source file:com.koma.music.service.MusicService.java
/** * {@inheritDoc}/* w w w. j a va 2 s . c o m*/ */ @Override public void onCreate() { LogUtils.d(TAG, "Creating service"); super.onCreate(); if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { stopSelf(); return; } else { mReadGranted = true; } mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Initialize the favorites and recents databases mRecentlyPlayCache = RecentlyPlay.getInstance(this); // gets the song play count cache mSongPlayCountCache = SongPlayCount.getInstance(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); // Initialize the image fetcher // mImageFetcher = ImageFetcher.getInstance(this); // Initialize the image cache // mImageFetcher.setImageCache(ImageCache.getInstance(this)); // Start up the thread running the service. Note that we create a // separate thread because the service normally runs in the process's // main thread, which we don't want to block. We also make it // background priority so CPU-intensive work will not disrupt the UI. mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); // Initialize the handler mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); // Initialize the audio manager and register any headset controls for // playback mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // Use the remote control APIs to set the playback state setUpMediaSession(); // Initialize the preferences mPreferences = getSharedPreferences("MusicService", 0); mCardId = getCardId(); mShowAlbumArtOnLockscreen = mPreferences.getBoolean(PreferenceUtils.SHOW_ALBUM_ART_ON_LOCKSCREEN, false); setShakeToPlayEnabled(mPreferences.getBoolean(PreferenceUtils.SHAKE_TO_PLAY, false)); registerExternalStorageListener(); // Initialize the media player mPlayer = new MultiPlayer(this); mPlayer.setHandler(mPlayerHandler); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(MusicServiceConstants.SERVICECMD); filter.addAction(MusicServiceConstants.TOGGLEPAUSE_ACTION); filter.addAction(MusicServiceConstants.PAUSE_ACTION); filter.addAction(MusicServiceConstants.STOP_ACTION); filter.addAction(MusicServiceConstants.NEXT_ACTION); filter.addAction(MusicServiceConstants.PREVIOUS_ACTION); filter.addAction(MusicServiceConstants.PREVIOUS_FORCE_ACTION); filter.addAction(MusicServiceConstants.REPEAT_ACTION); filter.addAction(MusicServiceConstants.SHUFFLE_ACTION); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); // Get events when MediaStore content changes mMediaObserver = new MediaObserver(mPlayerHandler); getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaObserver); getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaObserver); // Initialize the delayed shutdown intent final Intent shutdownIntent = new Intent(this, MusicService.class); shutdownIntent.setAction(MusicServiceConstants.SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); // Listen for the idle state scheduleDelayedShutdown(); // Bring the queue back reloadQueue(); notifyChange(MusicServiceConstants.QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:air.com.snagfilms.cast.chromecast.VideoChromeCastManager.java
private VideoChromeCastManager(Context context, String applicationId, Class<?> targetActivity, String dataNamespace) {//from www.ja va 2s .c om super(context, applicationId); mContext = context; Log.d(TAG, "VideoChromeCastManager is instantiated"); mVideoConsumers = Collections.synchronizedSet(new HashSet<IVideoCastConsumer>()); mDataNamespace = dataNamespace; if (null == targetActivity) { targetActivity = VideoPlayerActivity.class; } mTargetActivity = targetActivity; Utils.saveStringToPreference(context, Constants.PREFS_KEY_CAST_ACTIVITY_NAME, mTargetActivity.getName()); mMiniControllers = Collections.synchronizedSet(new HashSet<IMiniController>()); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(context, VideoIntentReceiver.class); mHandler = new Handler(new UpdateNotificationHandlerCallback()); }
From source file:com.firefly.sample.castcompanionlibrary.cast.VideoCastManager.java
private VideoCastManager(Context context, String applicationId, Class<?> targetActivity, String dataNamespace) { super(context, applicationId); LOGD(TAG, "VideoCastManager is instantiated"); mVideoConsumers = Collections.synchronizedSet(new HashSet<IVideoCastConsumer>()); mDataNamespace = dataNamespace;/*from ww w . j av a 2 s .c o m*/ if (null == targetActivity) { targetActivity = VideoCastControllerActivity.class; } mTargetActivity = targetActivity; Utils.saveStringToPreference(mContext, PREFS_KEY_CAST_ACTIVITY_NAME, mTargetActivity.getName()); if (null != mDataNamespace) { Utils.saveStringToPreference(mContext, PREFS_KEY_CAST_CUSTOM_DATA_NAMESPACE, dataNamespace); } mMiniControllers = Collections.synchronizedSet(new HashSet<IMiniController>()); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(context, VideoIntentReceiver.class); mHandler = new Handler(new UpdateNotificationHandlerCallback()); }
From source file:com.naman14.timber.musicplayer.MusicService.java
@Override public void onCreate() { if (D)/* w w w. j a v a 2 s . c o m*/ Log.d(TAG, "Creating service"); super.onCreate(); mNotificationManager = NotificationManagerCompat.from(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); mSongPlayCount = SongPlayCount.getInstance(this); mRecentStore = RecentStore.getInstance(this); mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setUpMediaSession(); } mPreferences = getSharedPreferences("Service", 0); // mCardId = getCardId(); // registerExternalStorageListener(); mPlayer = new MultiPlayer2(this); mPlayer.setHandler(mPlayerHandler); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(SERVICECMD); filter.addAction(TOGGLEPAUSE_ACTION); filter.addAction(PAUSE_ACTION); filter.addAction(STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(PREVIOUS_FORCE_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); // mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler); // getContentResolver().registerContentObserver( // MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver); // getContentResolver().registerContentObserver( // MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver); // Initialize the wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); final Intent shutdownIntent = new Intent(this, MusicService.class); shutdownIntent.setAction(SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); scheduleDelayedShutdown(); // reloadQueueAfterPermissionCheck(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:fm.feed.android.playersdk.view.PlayerView.java
private void initializeView() { RelativeLayout rootView = (RelativeLayout) inflate(getContext(), R.layout.view_player, this); mTitle = (TextView) rootView.findViewById(R.id.pu_title); mArtist = (TextView) rootView.findViewById(R.id.pu_artist); mAlbum = (TextView) rootView.findViewById(R.id.pu_album); mPrefix = (TextView) rootView.findViewById(R.id.pu_prefix); mSuffix = (TextView) rootView.findViewById(R.id.pu_suffix); mProgressBar = (ProgressBar) rootView.findViewById(R.id.pu_progress); LinearLayout topContainer = (LinearLayout) rootView.findViewById(R.id.pu_top_icons); LinearLayout bottomContainer = (LinearLayout) rootView.findViewById(R.id.pu_bottom_icons); // We need to create the SVGImageView instances and add them programmatically. mDislike = newSvgImage(1, ImageView.ScaleType.FIT_START); mLike = newSvgImage(2, ImageView.ScaleType.FIT_CENTER); mPlayPause = newSvgImage(2, ImageView.ScaleType.FIT_CENTER); mSkip = newSvgImage(1, ImageView.ScaleType.FIT_END); mVolume = newSvgImage(1, ImageView.ScaleType.FIT_START); mShare = newSvgImage(1, ImageView.ScaleType.FIT_END); // Set the SVG resource to the SVGImageView setSvgResource(mDislike, R.drawable.ic_thumbdown_faded, R.string.accessibility_dislike); setSvgResource(mLike, R.drawable.ic_thumbup_faded, R.string.accessibility_like); setSvgResource(mPlayPause, R.drawable.ic_play_faded, R.string.accessibility_play); setSvgResource(mSkip, R.drawable.ic_skip_disabled, R.string.accessibility_skip_disabled); setSvgResource(mVolume, R.drawable.ic_speakerhigh_faded, R.string.accessibility_volume_muted); setSvgResource(mShare, R.drawable.ic_share_faded, R.string.accessibility_share); // Add SVGImageViews to the layout. topContainer.addView(mDislike);//from w w w . j a va2s .com topContainer.addView(mLike); topContainer.addView(mPlayPause); topContainer.addView(mSkip); bottomContainer.addView(mVolume); bottomContainer.addView(mShare); mDislike.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!mPlayer.hasPlay()) { return; } Play.LikeState likeState = mPlayer.getPlay().getLikeState(); switch (likeState) { case NONE: setSvgResource(mDislike, R.drawable.ic_thumbdown_normal, R.string.accessibility_disliked); mPlayer.dislike(); break; case LIKED: setSvgResource(mLike, R.drawable.ic_thumbup_faded, R.string.accessibility_like); mPlayer.unlike(); break; case DISLIKED: // Do nothing break; } } }); mLike.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!mPlayer.hasPlay()) { return; } Play.LikeState likeState = mPlayer.getPlay().getLikeState(); switch (likeState) { case NONE: setSvgResource(mLike, R.drawable.ic_thumbup_normal, R.string.accessibility_liked); mPlayer.like(); break; case LIKED: // Do nothing break; case DISLIKED: setSvgResource(mDislike, R.drawable.ic_thumbdown_faded, R.string.accessibility_unlike); setSvgResource(mLike, R.drawable.ic_thumbup_normal, R.string.accessibility_liked); mPlayer.like(); break; } } }); mPlayPause.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mPlayer.getState() == PlayInfo.State.PLAYING) { mPlayer.pause(); } else { mPlayer.play(); } } }); mSkip.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mPlayer.isSkippable()) { setSvgResource(mSkip, R.drawable.ic_skip_normal, R.string.accessibility_skipping); mPlayer.skip(); } } }); mShare.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mPlayer == null || !mPlayer.hasPlay()) { Log.i(TAG, "Cannot share if not playing"); return; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); String subject = mShareSubject; String body = mShareBody; if (subject == null) { subject = getContext().getString(R.string.share_subject_template); } if (body == null) { Play play = mPlayer.getPlay(); String title = play.getAudioFile().getTrack().getTitle(); String artist = play.getAudioFile().getArtist().getName(); String album = play.getAudioFile().getRelease().getTitle(); body = getContext().getString(R.string.share_body_template, title, artist, album); } // Add data to the intent, the receiving app will decide what to do with it. intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, body); getContext() .startActivity(Intent.createChooser(intent, getContext().getString(R.string.share_via))); } }); mVolume.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AudioManager am = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); int volume = mAudioSettingsContentObserver.getCurrentVolume(); am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_SHOW_UI); } }); updateSpeakerUI(); }