Android Open Source - pi-android-player S P Utils






From Project

Back to project page pi-android-player.

License

The source code is released under:

Apache License

If you think the Android project pi-android-player 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 edu.ptit.xbmc.sp;
/*from ww  w . j  a  v  a2  s.  c  om*/
import edu.ptit.xbmc.model.Settings;
import edu.ptit.xbmc.tools.PiConnector;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import android.widget.Toast;

/**
 * Shared Preference Utilities
 * @author Khuong
 *
 */
public class SPUtils {
  /**
   * The unique instance of this class
   */
  private static SPUtils instance = null;
  public static SPUtils getInstance() {
    if (instance == null) {
      instance = new SPUtils();
    }
    return instance;
  }

  private SPUtils() {}
  
  public static boolean checkSettings(Context context){
    
    try {
      SharedPreferences sp = 
          context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
      String piUrl = sp.getString(Constants.STR_PI_URL, null);
      if(piUrl == null) {        
        return false;
      }
      int piPort = sp.getInt(Constants.STR_PI_PORT, 0);
      boolean check = PiConnector.getInstance().checkURLandPort(piUrl, piPort);      
      return check;
    } catch (Exception e) {          
      return false;
    }
  }
  public static void insertSettingsToSP(Context context,Settings settings){
    Log.i("URL in SPUtils", "http://" + settings.getPiUrl() + ":" + settings.getPiPort());
    try {
      SharedPreferences sp = 
          context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
      Editor editor = sp.edit();
      if(settings.getPiUrl() != null) editor.putString(Constants.STR_PI_URL, settings.getPiUrl());
      if(settings.getPiPort() > 0) editor.putInt(Constants.STR_PI_PORT, settings.getPiPort());
      editor.apply();      
      Toast.makeText(context, "Insert successful", Toast.LENGTH_LONG).show();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  //Khuongdv start oct4
  public static String getPiUrlFromSP(Context context){
    String piUrl = "";
    SharedPreferences sp = 
        context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
    piUrl = sp.getString(Constants.STR_PI_URL, "");
    return piUrl;
  }
  public static int getPiPortFromSP(Context context){
    SharedPreferences sp = 
        context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
    int piPort = sp.getInt(Constants.STR_PI_PORT, -1);
    return piPort;
  }
  //khuongdv end oct4
}




Java Source Code List

.FragmentAlbum.java
.FragmentArtist.java
.MyTabListener.java
.TabListenerForAlbum.java
edu.ptit.xbmc.activities.MainActivity.java
edu.ptit.xbmc.adapter.AllAlbumAdapter.java
edu.ptit.xbmc.adapter.AllArtistAdapter.java
edu.ptit.xbmc.adapter.AllSongAdapter2.java
edu.ptit.xbmc.adapter.ImageAdapter.java
edu.ptit.xbmc.fragments.FragmentAlbumDetail.java
edu.ptit.xbmc.fragments.FragmentAlbumList.java
edu.ptit.xbmc.fragments.FragmentAllSong.java
edu.ptit.xbmc.fragments.FragmentArtistDetail.java
edu.ptit.xbmc.fragments.FragmentArtistList.java
edu.ptit.xbmc.fragments.FragmentDirectRemote.java
edu.ptit.xbmc.fragments.FragmentNowPlaying.java
edu.ptit.xbmc.fragments.FragmentSettings.java
edu.ptit.xbmc.model.Album.java
edu.ptit.xbmc.model.Artist.java
edu.ptit.xbmc.model.Settings.java
edu.ptit.xbmc.model.Song.java
edu.ptit.xbmc.sp.Constants.java
edu.ptit.xbmc.sp.SPUtils.java
edu.ptit.xbmc.tablistener.TabListenerForArtist.java
edu.ptit.xbmc.tools.PiConnector.java
edu.ptit.xbmc.tools.Utils.java