Android Open Source - MixtioMD1Studio Utilities






From Project

Back to project page MixtioMD1Studio.

License

The source code is released under:

Apache License

If you think the Android project MixtioMD1Studio 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 2014 Mixtio Software LLC//from  w w  w.  j av a2s.c  o m
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 * */
package com.mixtio.md1studio;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by Roger on 2/9/14.
 */
public class Utilities {

    /**
     * Method used by Gson for reading json files.
     *
     * @param context The context from the requested class to open the raw directory where the json file is located
     * @return List<SquareModel> Data parsed from a json file in a List
     * */
    public static List<SquareModel> readJsonFile(Context context ) {
        Gson mGson = new Gson();
        List<SquareModel> data = null;

        InputStream inputStream = context.getResources().openRawResource(R.raw.square);
        Reader reader = new InputStreamReader(inputStream);
        Type listType = new TypeToken<List<SquareModel>>() {}.getType();

        data = mGson.fromJson(reader, listType);

        return data;
    }

    /**
     * Method for mapping the name of an image with its res folder filename.
     *
     * @param context The context from the requested class to map the requested resource.
     * @param image String name of the image file
     * @return int Id of the the requested image file from the res folder.
     * */
    public static int getImageId(Context context, String image) {
        int id = context.getApplicationContext().getResources().getIdentifier(image, "drawable", context.getPackageName());
        return id;
    }
}




Java Source Code List

com.mixtio.md1studio.ItemAdapter.java
com.mixtio.md1studio.ItemDetailActivity.java
com.mixtio.md1studio.ItemDetailFragment.java
com.mixtio.md1studio.ItemListFragment.java
com.mixtio.md1studio.MainActivity.java
com.mixtio.md1studio.SquareModel.java
com.mixtio.md1studio.Utilities.java