Android Open Source - InfoWallpaper Current Song Data Collector






From Project

Back to project page InfoWallpaper.

License

The source code is released under:

MIT License

If you think the Android project InfoWallpaper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.andreashedin.infowallpaper;
//from   ww w.ja v a2 s  . co m
import java.util.List;

import android.app.ActivityManager;
import android.content.Intent;

public class CurrentSongDataCollector extends DataCollector {

  private static final String ARTIST = "#aa";
  private static final String ALBUM = "#ll";
  private static final String SONG = "#ss";

  private String mCurrentSong = "";
  private String mCurrentAlbum = "";
  private String mCurrentArtist = "";
  
  private boolean mPlaying = false;
  
  CurrentSongDataCollector(LiveInfoWallpaper parent) {
    super(parent);
    
    mPlaying = isMusicServiceRunning();
  }
  
  static String getSampleText(String str) {
    return str.replace(ALBUM, "Current Album").replace(ARTIST, "Current Artist").replace(SONG, "Current Song");
  }

  @Override
  void update(Object object) {
    Intent intent = (Intent)object;
    
    mPlaying = isMusicServiceRunning();
    mCurrentSong = intent.getStringExtra("track");
    mCurrentArtist = intent.getStringExtra("artist");
    mCurrentAlbum = intent.getStringExtra("album");
  }

  @Override
  String updateInfoString(String string, boolean numbersAsText) {
    String str = "";
    
    if(mPlaying) {
      str = string;
      str = str.replace(ARTIST, mCurrentArtist);
      str = str.replace(ALBUM, mCurrentAlbum);
      str = str.replace(SONG, mCurrentSong);
    }
    
    return str;
  }

  public boolean isMusicServiceRunning() {  
    ActivityManager am = (ActivityManager) mParent.getBaseContext().getSystemService("activity");
    if(am == null)
      return false;
    
    List<ActivityManager.RunningAppProcessInfo> runningApps;
    runningApps = am.getRunningAppProcesses();
    
    for(int i = 0; i < runningApps.size(); ++i) {
      if(runningApps.get(i).processName.compareTo("com.google.android.music") == 0) {
        return true;
      }
    }
  
    return false;
  }
}




Java Source Code List

com.andreashedin.general.ColorPickerDialog.java
com.andreashedin.general.CustomizeInfoDialog.java
com.andreashedin.general.EnterStringDialog.java
com.andreashedin.general.PickItemDialog.java
com.andreashedin.general.PositionInfosDialog.java
com.andreashedin.general.SelectConfigurationDialog.java
com.andreashedin.general.TextSizeDialog.java
com.andreashedin.general.WeatherSettingsDialog.java
com.andreashedin.infowallpaper.Background.java
com.andreashedin.infowallpaper.BatteryDataCollector.java
com.andreashedin.infowallpaper.ColorHandler.java
com.andreashedin.infowallpaper.ConfigHandler.java
com.andreashedin.infowallpaper.CurrentSongDataCollector.java
com.andreashedin.infowallpaper.DataCollector.java
com.andreashedin.infowallpaper.DateTimeDataCollector.java
com.andreashedin.infowallpaper.DisplayValuePair.java
com.andreashedin.infowallpaper.InfoData.java
com.andreashedin.infowallpaper.InfoItem.java
com.andreashedin.infowallpaper.LiveInfoSettings.java
com.andreashedin.infowallpaper.LiveInfoWallpaper.java
com.andreashedin.infowallpaper.PhoneStatusDataCollector.java
com.andreashedin.infowallpaper.Phone.java
com.andreashedin.infowallpaper.SaveLoadData.java
com.andreashedin.infowallpaper.Screen.java
com.andreashedin.infowallpaper.WeatherDataCollector.java
com.andreashedin.infowallpaper.WeatherHandler.java