Android Open Source - android-sdk-samples Assets Property Reader






From Project

Back to project page android-sdk-samples.

License

The source code is released under:

Apache License

If you think the Android project android-sdk-samples 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 io.snapback.plugin.config;
/*from  w  ww  .j a  va  2s.c  o  m*/
import io.snapback.plugin.util.ParseConstants;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;

public class AssetsPropertyReader
{
  private static final String DEFAULT_FILE_NAME = "config.properties";
  private static AssetsPropertyReader instance;
  private Properties properties;

  /**
   * Convenient method useful where there is no context to provide.<br>
   * WARNING: call this method when the class object is already instantiated.
   */
  public static AssetsPropertyReader getLastInstance()
  {
    return instance;
  }
  
  public static AssetsPropertyReader getInstance(Context context)
  {
    return getInstance(context, DEFAULT_FILE_NAME);
  }
  
  public static AssetsPropertyReader getInstance(Context context, String fileName)
  {
    if(instance == null)
    {
      instance = new AssetsPropertyReader(context, fileName);
    }
    
    return instance;
  }
  
  private AssetsPropertyReader(Context context, String fileName)
  {
    properties = new Properties();
    
    try
    {
      /**
       * getAssets() Return an AssetManager instance for your
       * application's package. AssetManager Provides access to an
       * application's raw asset files;
       */
      AssetManager assetManager = context.getAssets();
      /**
       * Open an asset using ACCESS_STREAMING mode. This
       */
      InputStream inputStream = assetManager.open(fileName);
      /**
       * Loads properties from the specified InputStream,
       */
      properties.load(inputStream);

    }
    catch(IOException e)
    {
      Log.e("AssetsPropertyReader", e.toString());
    }
  }
  
  public String getValue(String key)
  {
    return properties.getProperty(key, null);
  }
  
  public String getParseAppID()
  {
    return getValue(ParseConstants.parse_app_id_key);
  }
  
  public String getParseClientID()
  {
    return getValue(ParseConstants.parse_client_id_key);
  }
}




Java Source Code List

com.atooma.plugin.snapback.CC_BlowDetection.java
com.atooma.plugin.snapback.CC_SnapDetection.java
com.atooma.plugin.snapback.PE_TorchOnOff.java
com.atooma.plugin.snapback.SnapbackModule.java
com.atooma.plugin.snapback.SnapbackReceiver.java
com.atooma.plugin.snapback.SnapbackRegister.java
com.atooma.plugin.snapback.TR_BlowDetectionGestureBased.java
io.snapback.camlauncher.MainActivity.java
io.snapback.orientedkeygamepad.MainActivity.java
io.snapback.plugin.config.AssetsPropertyReader.java
io.snapback.plugin.data.ParseHandler.java
io.snapback.plugin.data.SharedPrefsHandler.java
io.snapback.plugin.util.Constants.java
io.snapback.plugin.util.ParseConstants.java
io.snapback.plugin.util.Utils.java
io.snapback.snap4magic.MainActivity.java