Android Open Source - Curio_android_SDK Parameter Loader






From Project

Back to project page Curio_android_SDK.

License

The source code is released under:

Apache License

If you think the Android project Curio_android_SDK 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

/*
 * Copyright (C) 2014 Turkcell//w  ww . java 2s.c om
 * 
 * Created by Can Ciloglu on 10 Haz 2014
 *
 */
package com.turkcell.curio.utils;

import android.content.Context;

/**
 * Provides a practical way for loading parameters from curio.xml configuration file.
 * 
 * @author Can Ciloglu
 *
 */
public class ParameterLoader {

  private static final String TAG = "ParameterLoader";
  private final Context context;

  public ParameterLoader(Context ctx) {
    if (ctx == null) {
      throw new NullPointerException("Context cannot be null");
    }
    this.context = ctx;
  }

  private int getResourceIdForType(String key, String type) {
    if (context == null) {
      return 0;
    }
    return context.getResources().getIdentifier(key, type, context.getPackageName());
  }

  public String getString(String key, String defaultValue) {
    int id = getResourceIdForType(key, "string");
    if (id == 0) {
      return defaultValue;
    } else {
      return context.getString(id);
    }
  }

  public boolean getBoolean(String key, boolean defaultValue) {
    int id = getResourceIdForType(key, "bool");
    if (id == 0) {
      return defaultValue;
    } else {
      return "true".equalsIgnoreCase(context.getString(id));
    }
  }

  public int getInteger(String key, int defaultValue) {
    int id = getResourceIdForType(key, "integer");
    if (id == 0) {
      return defaultValue;
    } else {
      try {
        return Integer.parseInt(context.getString(id));
      } catch (NumberFormatException e) {
        CurioLogger.w(TAG, "NumberFormatException parsing " + context.getString(id));
        return defaultValue;
      }
    }
  }

}




Java Source Code List

com.turkcell.curio.CurioClient.java
com.turkcell.curio.CurioRequestProcessor.java
com.turkcell.curio.DBRequestProcessor.java
com.turkcell.curio.ICurioResultListener.java
com.turkcell.curio.INetworkConnectivityChangeListener.java
com.turkcell.curio.model.OfflineRequest.java
com.turkcell.curio.model.OnlineRequest.java
com.turkcell.curio.model.Screen.java
com.turkcell.curio.utils.Constants.java
com.turkcell.curio.utils.CurioClientSettings.java
com.turkcell.curio.utils.CurioDBContract.java
com.turkcell.curio.utils.CurioDBHelper.java
com.turkcell.curio.utils.CurioLogger.java
com.turkcell.curio.utils.CurioUtil.java
com.turkcell.curio.utils.NetworkUtil.java
com.turkcell.curio.utils.ParameterLoader.java
com.turkcell.curio.utils.PushUtil.java
com.turkcell.curio.utils.UUIDGenerator.java
com.turkcell.curio.utils.VisitorCodeManager.java
com.turkcell.curiosample.BlankActivity.java
com.turkcell.curiosample.MainActivity.java
com.turkcell.curiosample.PushNotificationBroadcastReceiver.java
com.turkcell.curiosample.PushNotificationIntentService.java