Android Context Get getScenario(Context context, String filename, int widgetid, int defaultScenario)

Here you can find the source of getScenario(Context context, String filename, int widgetid, int defaultScenario)

Description

get Scenario

Declaration

public static int getScenario(Context context, String filename,
            int widgetid, int defaultScenario) 

Method Source Code

//package com.java2s;
import android.content.Context;
import android.util.Log;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    private final static boolean D = false;
    private final static String TAG = "ScenarioUtil";

    public static int getScenario(Context context, String filename,
            int widgetid, int defaultScenario) {
        FileInputStream fis = null;
        DataInputStream dis = null;
        try {//from w  w  w  . j  ava  2 s  .c  om
            fis = context.openFileInput(filename);
            dis = new DataInputStream(fis);
            String line = null;
            do {
                line = dis.readLine();
                if (line != null) {
                    String[] strs = line.split(",");
                    if (strs != null && strs.length >= 2) {
                        int wid = Integer.valueOf(strs[0]).intValue();
                        int sce = Integer.valueOf(strs[1]).intValue();
                        if (D) {
                            Log.d(TAG, "getScenario" + wid + "=>" + sce);
                        }
                        if (wid == widgetid) {
                            if (D) {
                                Log.d(TAG, "getScenario return " + wid
                                        + "=>" + sce);
                            }
                            return sce;
                        }
                    }
                }
            } while (line != null);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } finally {
            if (dis != null) {
                try {
                    dis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return defaultScenario;
    }
}

Related

  1. getResDimen(Context context, int resId)
  2. getResourcesPath(Context context, String url)
  3. getRevokedPerms(String packageName, Context ctx)
  4. getSavedPostsPath(Context context)
  5. getScaledDensity(Context context)
  6. getSeed(Context context)
  7. getSelectedLangCodes(Context context, int[] indexes, boolean[] selectedItems, int codeResourceId)
  8. getServiceMetaData(Context context, Class serviceClass, String key)
  9. getSignatures(final Context context)