Example usage for android.content.res Resources getAssets

List of usage examples for android.content.res Resources getAssets

Introduction

In this page you can find the example usage for android.content.res Resources getAssets.

Prototype

public final AssetManager getAssets() 

Source Link

Document

Retrieve underlying AssetManager storage for these resources.

Usage

From source file:com.bluekai.sampleapp.BlueKaiTab.java

@Override
public void onCreate(Bundle savedInstanceState) {
    try {//from  w ww. jav a  2s. c  o m
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_blue_kai);
        this.context = getApplicationContext();

        database = DataSource.getInstance(context);
        DevSettings devSettings = database.getDevSettings();
        if (devSettings == null) {
            try {
                Resources resources = this.getResources();
                AssetManager assetManager = resources.getAssets();
                InputStream inputStream = assetManager.open("settings.properties");
                Properties properties = new Properties();
                properties.load(inputStream);
                devMode = Boolean.parseBoolean(properties.getProperty("devmode"));
                useHttps = Boolean.parseBoolean(properties.getProperty("useHttps"));
                siteId = properties.getProperty("siteid");
            } catch (IOException e) {
                Log.e("BlueKaiSampleApp", "Error loading properties. Default values will be loaded from SDK",
                        e);
            }
        } else {
            siteId = devSettings.getBkurl();
            devMode = devSettings.isDevMode();
            useHttps = devSettings.isHttpsEnabled();
        }

        bk = BlueKai.getInstance(this, this, devMode, useHttps, siteId, appVersion, this, new Handler());
        bk.setFragmentManager(getSupportFragmentManager());

        keyText = (EditText) findViewById(R.id.keyText);
        valueText = (EditText) findViewById(R.id.valueText);
        //pairsCountText = (EditText) findViewById(R.id.pairs_count);

        clearButton = (Button) findViewById(R.id.clear);
        clearButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                keyText.setText("");
                valueText.setText("");
                keyText.requestFocus();
            }
        });

        sendButton = (Button) findViewById(R.id.send);
        sendButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String key = keyText.getText().toString();
                String value = valueText.getText().toString();
                if (key == null || key.trim().equals("")) {
                    keyText.requestFocus();
                    Toast.makeText(context, "Key is empty. Please enter a value", Toast.LENGTH_LONG).show();
                } else if (value == null || value.trim().equals("")) {
                    valueText.requestFocus();
                    Toast.makeText(context, "Value is empty. Please enter a value", Toast.LENGTH_LONG).show();
                } else {
                    bk.put(key, value);
                }
            }
        });
    } catch (Exception ex) {
        Log.e("BlueKaiTab", "Error while creating", ex);
    }
}

From source file:com.littlepancake.glpk.GLPKModLangFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_glpktest, container, false);
    problemEntryEditText = (EditText) v.findViewById(R.id.problemEntryEditText);
    buttonSolve = (Button) v.findViewById(R.id.buttonSolve);
    buttonClear = (Button) v.findViewById(R.id.buttonClear);
    buttonComments = (Button) v.findViewById(R.id.buttonComments);

    buttonSolve.setOnClickListener(this);
    buttonClear.setOnClickListener(this);
    buttonComments.setOnClickListener(this);

    Resources res = getResources();
    AssetManager am = res.getAssets();

    String fileList[] = null;// w  w w.  j  a v a2  s. c o  m
    try {
        fileList = am.list("");
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (fileList != null) {
        for (int i = 0; i < fileList.length; i++) {
            Log.d(tag, fileList[i]);
        }
    }
    return v;
}

From source file:net.bible.service.readingplan.ReadingPlanDao.java

/** look in assets/readingplan and sdcard/jsword/readingplan for reading plans and return a list of all codes
 *///from  w  ww  .j  a  va  2s .c o  m
private List<String> getAllReadingPlanCodes() throws IOException {

    Resources resources = BibleApplication.getApplication().getResources();
    AssetManager assetManager = resources.getAssets();

    List<String> allCodes = new ArrayList<String>();

    String[] internalPlans = assetManager.list(READING_PLAN_FOLDER);
    allCodes.addAll(getReadingPlanCodes(internalPlans));

    String[] userPlans = USER_READING_PLAN_FOLDER.list();
    allCodes.addAll(getReadingPlanCodes(userPlans));

    return allCodes;
}

From source file:com.photon.phresco.hybrid.eshop.activity.PhrescoActivity.java

/**
 * Read phresco-env-config.xml file to get to connect to web service
 *///  w  ww.j av  a2  s  .c om
public void readConfigXML() {
    try {

        Resources resources = getResources();
        AssetManager assetManager = resources.getAssets();

        // Read from the /assets directory
        InputStream inputStream = assetManager.open(Constants.PHRESCO_ENV_CONFIG);

        ConfigReader confReaderObj = new ConfigReader(inputStream);

        PhrescoLogger.info(TAG + "Default ENV = " + confReaderObj.getDefaultEnvName());

        List<Configuration> configByEnv = confReaderObj.getConfigByEnv(confReaderObj.getDefaultEnvName());

        for (Configuration configuration : configByEnv) {
            String envName = configuration.getEnvName();
            String envType = configuration.getType();
            PhrescoLogger.info(TAG + "envName = " + envName + " ----- envType = " + envType);
            //            properties = configuration.getProperties();

            if (envType.equalsIgnoreCase("webservice")) {
                /*String configJsonString = confReaderObj.getConfigAsJSON(envName, WEB_SERVICE, WEBSERVICE_CONFIG_NAME);
                getWebServiceURL(configJsonString);*/
            } else if (envType.equalsIgnoreCase("server")) {
                String configJsonString = confReaderObj.getConfigAsJSON(envName, SERVER, SERVER_CONFIG_NAME);
                getServerURL(configJsonString);
            }

        }

    } catch (ParserConfigurationException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : ParserConfigurationException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (SAXException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : SAXException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (IOException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : IOException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "readConfigXML : Exception: " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:com.photon.phresco.nativeapp.unit.test.testcases.A_MainActivityTest.java

/**
 * Read phresco-env-config.xml file to get to connect to web service
 *//*from w w  w  . ja va 2 s.  com*/
public void readConfigXML() {
    try {

        String protocol = "protocol";
        String host = "host";
        String port = "port";
        String context = "context";
        Resources resources = this.mContext.getResources();
        AssetManager assetManager = resources.getAssets();
        Properties properties = new Properties();

        // Read from the /assets directory
        InputStream inputStream = assetManager.open(Constants.PHRESCO_ENV_CONFIG);

        ConfigReader confReaderObj = new ConfigReader(inputStream);

        PhrescoLogger.info(TAG + "Default ENV = " + confReaderObj.getDefaultEnvName());

        List<Configuration> configByEnv = confReaderObj.getConfigByEnv(confReaderObj.getDefaultEnvName());

        for (Configuration configuration : configByEnv) {
            properties = configuration.getProperties();
            PhrescoLogger.info(TAG + "config value = " + configuration.getProperties());
            String webServiceProtocol = properties.getProperty(protocol).endsWith("://")
                    ? properties.getProperty(protocol)
                    : properties.getProperty(protocol) + "://"; // http://

            String webServiceHost = properties.getProperty(port).equalsIgnoreCase("")
                    ? (properties.getProperty(host).endsWith("/") ? properties.getProperty(host)
                            : properties.getProperty(host) + "/")
                    : properties.getProperty(host); // localhost/
            // localhost

            String webServicePort = properties.getProperty(port).equalsIgnoreCase("") ? ""
                    : (properties.getProperty(port).startsWith(":") ? properties.getProperty(port)
                            : ":" + properties.getProperty(port)); // "" (blank)
            // :1313

            String webServiceContext = properties.getProperty(context).startsWith("/")
                    ? properties.getProperty(context)
                    : "/" + properties.getProperty(context); // /phresco

            Constants.setWebContextURL(
                    webServiceProtocol + webServiceHost + webServicePort + webServiceContext + "/");
            Constants.setRestAPI(Constants.REST_API);
            PhrescoLogger.info(
                    TAG + "Constants.webContextURL : " + Constants.getWebContextURL() + Constants.getRestAPI());
        }

    } catch (ParserConfigurationException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : ParserConfigurationException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (SAXException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : SAXException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (IOException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : IOException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "readConfigXML : Exception: " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:com.bellman.bible.service.readingplan.ReadingPlanDao.java

/**
 * look in assets/readingplan and sdcard/jsword/readingplan for reading plans and return a list of all codes
 *//*from   w  w w . j a v a2  s .co m*/
private List<String> getAllReadingPlanCodes() throws IOException {

    Resources resources = CurrentActivityHolder.getInstance().getApplication().getResources();
    AssetManager assetManager = resources.getAssets();

    List<String> allCodes = new ArrayList<String>();

    String[] internalPlans = assetManager.list(READING_PLAN_FOLDER);
    allCodes.addAll(getReadingPlanCodes(internalPlans));

    String[] userPlans = USER_READING_PLAN_FOLDER.list();
    allCodes.addAll(getReadingPlanCodes(userPlans));

    return allCodes;
}

From source file:net.bible.service.readingplan.ReadingPlanDao.java

private synchronized Properties getPlanProperties(String planCode) {
    if (!planCode.equals(cachedPlanCode)) {
        Resources resources = BibleApplication.getApplication().getResources();
        AssetManager assetManager = resources.getAssets();
        String filename = planCode + DOT_PROPERTIES;

        // Read from the /assets directory
        Properties properties = new Properties();
        InputStream inputStream = null;
        try {//  w w w .j  a  va2s .  c  o m
            // check to see if a user has created his own reading plan with this name
            File userReadingPlanFile = new File(USER_READING_PLAN_FOLDER, filename);
            boolean isUserPlan = userReadingPlanFile.exists();

            if (!isUserPlan) {
                inputStream = assetManager.open(READING_PLAN_FOLDER + File.separator + filename);
            } else {
                inputStream = new FileInputStream(userReadingPlanFile);
            }
            properties.load(inputStream);
            Log.d(TAG, "The properties are now loaded");
            Log.d(TAG, "properties: " + properties);

            // cache it so we don't constantly reload the properties
            cachedPlanCode = planCode;
            cachedPlanProperties = properties;

        } catch (IOException e) {
            System.err.println("Failed to open reading plan property file");
            e.printStackTrace();
        } finally {
            IOUtil.close(inputStream);
        }
    }
    return cachedPlanProperties;
}

From source file:com.bellman.bible.service.readingplan.ReadingPlanDao.java

private synchronized Properties getPlanProperties(String planCode) {
    if (!planCode.equals(cachedPlanCode)) {
        Resources resources = CurrentActivityHolder.getInstance().getApplication().getResources();
        AssetManager assetManager = resources.getAssets();
        String filename = planCode + DOT_PROPERTIES;

        // Read from the /assets directory
        Properties properties = new Properties();
        InputStream inputStream = null;
        try {//from w ww.ja v a 2 s  . c  o  m
            // check to see if a user has created his own reading plan with this name
            File userReadingPlanFile = new File(USER_READING_PLAN_FOLDER, filename);
            boolean isUserPlan = userReadingPlanFile.exists();

            if (!isUserPlan) {
                inputStream = assetManager.open(READING_PLAN_FOLDER + File.separator + filename);
            } else {
                inputStream = new FileInputStream(userReadingPlanFile);
            }
            properties.load(inputStream);
            Log.d(TAG, "The properties are now loaded");
            Log.d(TAG, "properties: " + properties);

            // cache it so we don't constantly reload the properties
            cachedPlanCode = planCode;
            cachedPlanProperties = properties;

        } catch (IOException e) {
            System.err.println("Failed to open reading plan property file");
            e.printStackTrace();
        } finally {
            IOUtil.close(inputStream);
        }
    }
    return cachedPlanProperties;
}

From source file:com.silverpop.engage.deeplinking.EngageDeepLinkManager.java

private String readConfigFile(String configFileName) throws IOException {
    Resources resources = this.getApplicationContext().getResources();
    AssetManager assetManager = resources.getAssets();

    InputStream inputStream = assetManager.open(configFileName);
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
    StringBuilder sb = new StringBuilder();

    String line;//from w  w  w  .  j ava 2s .  co m
    while ((line = reader.readLine()) != null) {
        sb.append(line + "\n");
    }
    return sb.toString();
}

From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java

/**
 * Read phresco-env-config.xml file to get to connect to web service
 *///from  ww w .j  a  va  2 s .  c om
public void readConfigXML() {
    try {

        String protocol = "protocol";
        String host = "host";
        String port = "port";
        String context = "context";
        Resources resources = getResources();
        AssetManager assetManager = resources.getAssets();

        // Read from the /assets directory
        InputStream inputStream = assetManager.open(Constants.PHRESCO_ENV_CONFIG);

        ConfigReader confReaderObj = new ConfigReader(inputStream);

        PhrescoLogger.info(TAG + "Default ENV = " + confReaderObj.getDefaultEnvName());

        List<Configuration> configByEnv = confReaderObj.getConfigByEnv(confReaderObj.getDefaultEnvName());

        for (Configuration configuration : configByEnv) {
            properties = configuration.getProperties();
            PhrescoLogger.info(TAG + "config value = " + configuration.getProperties());
            String webServiceProtocol = properties.getProperty(protocol).endsWith("://")
                    ? properties.getProperty(protocol)
                    : properties.getProperty(protocol) + "://"; // http://

            String webServiceHost = properties.getProperty(port).equalsIgnoreCase("")
                    ? (properties.getProperty(host).endsWith("/") ? properties.getProperty(host)
                            : properties.getProperty(host) + "/")
                    : properties.getProperty(host); // localhost/
            // localhost

            String webServicePort = properties.getProperty(port).equalsIgnoreCase("") ? ""
                    : (properties.getProperty(port).startsWith(":") ? properties.getProperty(port)
                            : ":" + properties.getProperty(port)); // "" (blank)
            // :1313

            String webServiceContext = properties.getProperty(context).startsWith("/")
                    ? properties.getProperty(context)
                    : "/" + properties.getProperty(context); // /phresco

            Constants.setWebContextURL(
                    webServiceProtocol + webServiceHost + webServicePort + webServiceContext + "/");
            Constants.setRestAPI(Constants.REST_API);
            PhrescoLogger.info(
                    TAG + "Constants.webContextURL : " + Constants.getWebContextURL() + Constants.getRestAPI());
        }

    } catch (ParserConfigurationException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : ParserConfigurationException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (SAXException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : SAXException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (IOException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : IOException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "readConfigXML : Exception: " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}