Example usage for android.util SparseArray SparseArray

List of usage examples for android.util SparseArray SparseArray

Introduction

In this page you can find the example usage for android.util SparseArray SparseArray.

Prototype

public SparseArray() 

Source Link

Document

Creates a new SparseArray containing no mappings.

Usage

From source file:com.mikecorrigan.trainscorekeeper.Players.java

@SuppressLint("NewApi")
public Players(final Activity context, ViewGroup viewGroup, final JSONArray jsonPlayers) {
    Log.vc(VERBOSE, TAG,/*  w  ww . j ava2  s. c o m*/
            "ctor: context=" + context + ", viewGroup=" + viewGroup + ", jsonPlayers=" + jsonPlayers);

    viewGroup.removeAllViews();

    Resources resources = context.getResources();

    String[] playerNames = resources.getStringArray(R.array.playerNames);

    TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables);

    TypedArray colorIdsArray = resources.obtainTypedArray(R.array.playerTextColors);
    int[] colorIds = new int[colorIdsArray.length()];
    for (int i = 0; i < colorIdsArray.length(); i++) {
        colorIds[i] = colorIdsArray.getResourceId(i, -1);
    }

    listeners = new HashSet<Listener>();
    players = new SparseArray<Player>();

    for (int i = 0; i < playerNames.length; i++) {
        PlayerButton toggleButton = new PlayerButton(context);
        toggleButton.setPlayerId(i);
        LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, 1f);
        toggleButton.setLayoutParams(layoutParams);
        Drawable drawable = drawablesArray.getDrawable(i);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            toggleButton.setBackgroundDrawable(drawable);
        } else {
            toggleButton.setBackground(drawable);
        }
        toggleButton.setPadding(10, 10, 10, 10);
        toggleButton.setTextColor(resources.getColor(colorIds[i]));
        toggleButton.setOnClickListener(onSelect);

        viewGroup.addView(toggleButton);

        final String name = playerNames[i];

        boolean enabled = true;

        // If the players configuration is available, determine which players are enabled.
        if (jsonPlayers != null) {
            enabled = false;
            for (int j = 0; j < jsonPlayers.length(); j++) {
                String jsonName = jsonPlayers.optString(j, "");
                if (jsonName.equalsIgnoreCase(name)) {
                    enabled = true;
                    break;
                }
            }
        }

        Player player = new Player(toggleButton, i, name, enabled);
        players.put(i, player);
    }

    setSelection(-1);

    drawablesArray.recycle();
    colorIdsArray.recycle();
}

From source file:com.mongolduu.android.ng.ChartActivity.java

/** Called when the activity is first created. */
@Override//w  w  w .j a  v a 2 s.  c  o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setActionBarContentView(R.layout.swipey);
    setTitle(R.string.chart_activity_title);

    refreshItem = (LoaderActionBarItem) addActionBarItem(Type.Refresh, R.id.action_bar_refresh);
    addActionBarItem(Type.Search, R.id.action_bar_search);

    fragments = new SparseArray<ChartFragment>();
    for (int i = 0; i < chartTypes.length; i++) {
        fragments.put(i, ChartFragment.newInstance(i, chartTypes[i]));
    }

    viewpager = (ViewPager) findViewById(R.id.viewpager);
    tabs = (SwipeyTabs) findViewById(R.id.swipeytabs);

    SwipeyTabsPagerAdapter adapter = new SwipeyTabsPagerAdapter(this, getSupportFragmentManager());
    viewpager.setAdapter(adapter);
    tabs.setAdapter(adapter);
    viewpager.setOnPageChangeListener(tabs);
    viewpager.setCurrentItem(1);
}

From source file:org.akvo.caddisfly.test.helper.ResultsTest.java

@Test
public void testEcSensorResult() {

    TestInfo testInfo = TestConfigHelper.loadTestByUuid("f88237b7-be3d-4fac-bbee-ab328eefcd14");
    assert testInfo != null;

    SparseArray<String> results = new SparseArray<>();
    results.put(1, "32432");
    results.put(2, "29.5");

    JSONObject resultJson = TestConfigHelper.getJsonResult(testInfo, results, -1, "", null);

    // Replace items that cannot be tested (e.g. currentTime)
    String json = resultJson.toString().replaceAll("(\"testDate\":\").*?\"", "$1today\"");
    json = json.replaceAll("(\"appVersion\":\").*?\"", "$1version\"");

    String expectedJson = "{\"type\":\"caddisfly\",\"name\":\"Water - Electrical Conductivity\",\"uuid\":\"f88237b7-be3d-4fac-bbee-ab328eefcd14\",\"result\":[{\"name\":\"Electrical Conductivity\",\"unit\":\"S\\/cm\",\"id\":1,\"value\":\"32432\"},{\"name\":\"Temperature\",\"unit\":\"Celsius\",\"id\":2,\"value\":\"29.5\"}],\"testDate\":\"today\",\"user\":{\"backDropDetection\":true,\"language\":\"\"},\"app\":{\"appVersion\":\"version\",\"language\":\"en\"},\"device\":{\"model\":\"unknown\",\"product\":\"unknown\",\"manufacturer\":\"unknown\",\"os\":\"Android - 6.0.1_r3 (23)\",\"country\":\"US\",\"language\":\"en\"}}";

    assertEquals(expectedJson, json);//  w  ww .  j a  v a  2s  . c o  m
}

From source file:com.dgsd.android.ShiftTracker.Adapter.DayAdapter.java

public DayAdapter(Context context, Cursor c, int julianDay) {
    super(context, c, false);
    inflater = LayoutInflater.from(context);
    mJulianDay = julianDay;// ww w.  j av  a  2 s  .c o m

    mIs24Hour = DateFormat.is24HourFormat(context);

    mStringBuilder = new StringBuilder();
    mFormatter = new Formatter((mStringBuilder));

    mCurrencyFormatter = NumberFormat.getCurrencyInstance();

    //Caching
    mIdToTimeArray = new SparseArray<String>();
    mIdToPayArray = new SparseArray<String>();

    mShowIncomePref = Prefs.getInstance(context).get(context.getString(R.string.settings_key_show_income),
            true);
}

From source file:com.intel.xdk.multitouch.MultiTouch.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();//  w  w w  .  j  a  v  a  2s  . c  o m

    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                try {
                    Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class);
                    m.invoke(WebView.class, true);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //WebView.setWebContentsDebuggingEnabled(true);
            }
        }
    });

    touchy = new View.OnTouchListener() {

        private SparseArray<Long> pointerId2Identifier = new SparseArray<Long>();

        @Override
        public boolean onTouch(View v, MotionEvent ev) {
            if (isMultitouchEnabled) {
                int pointerCount = ev.getPointerCount();

                //get the correct action
                int maskedAction = ev.getActionMasked();
                int idx = ev.getActionIndex();
                try {
                    String js = null;
                    if (maskedAction == MotionEvent.ACTION_POINTER_DOWN
                            || maskedAction == MotionEvent.ACTION_DOWN) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        //make a timestamp identifier and store it
                        long identifier = System.currentTimeMillis();
                        pointerId2Identifier.put(id, identifier);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchstart'},", identifier, x, y,
                                h, w);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_POINTER_UP
                            || maskedAction == MotionEvent.ACTION_UP) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchend'},",
                                pointerId2Identifier.get(id), x, y, h, w);
                        pointerId2Identifier.remove(id);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_MOVE) {
                        //send all events if it is a move
                        for (int i = 0; i < pointerCount; i++) {
                            int x = (int) ev.getX(i);
                            int y = (int) ev.getY(i);
                            int h = (int) v.getHeight();
                            int w = (int) v.getWidth();
                            int id = ev.getPointerId(i);
                            js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchmove'},",
                                    pointerId2Identifier.get(id), x, y, h, w);
                            queueMultitouchData(js, id, maskedAction);
                        }
                    } else {
                        Log.e("[intel.xdk]", "got a MotionEvent that is not up/down/move:" + ev);
                    }
                    //Log.i("[intel.xdk]", "onTouchEvent:"+js);
                } catch (Exception e) {
                    Log.e("[intel.xdk]", "Got an exception back from WebView: ", e);
                }

                return true;
            } else {
                return false;
            }
        }
    };
    webView.setOnTouchListener(touchy);

    lock = this;
    messages = new ArrayList<String>(0);
}

From source file:net.xisberto.phonetodesktop.ui.WaitListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }/* w ww .jav  a 2s .c  o  m*/
    setContentView(R.layout.activity_link_list);
    selectedItems = new SparseArray<Long>();
}

From source file:com.intel.xdk.player.Player.java

public Player() {
    soundPoolMapName2Id = new HashMap<String, Integer>();
    soundPoolMapId2Name = new SparseArray<String>();
    soundPoolShouldPlay = new HashMap<String, Boolean>();
}

From source file:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java

private BaseAdapterHelper(Context context, ViewGroup parent, int layoutId, int position) {
    this.context = context;
    this.position = position;
    this.views = new SparseArray<View>();
    convertView = LayoutInflater.from(context).inflate(layoutId, parent, false);
    convertView.setTag(this);
}

From source file:com.nightlynexus.viewstatepageradapter.ViewStatePagerAdapter.java

private void putInDetached(int position, View view) {
    SparseArray<Parcelable> viewState = new SparseArray<>();
    view.saveHierarchyState(viewState);/*from w  w w . j  a v a2  s . com*/
    detached.put(position, viewState);
}

From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java

public WeekAdapter(Context context, Cursor c, int julianDay) {
    super(context, c, false);
    inflater = LayoutInflater.from(context);
    mStartingJulianDay = julianDay;//from ww w .j  a v a  2 s  . com
    mRand = new Random();
    mTime = new Time();

    mIs24Hour = DateFormat.is24HourFormat(context);

    mStringBuilder = new StringBuilder();
    mFormatter = new Formatter((mStringBuilder));

    mCurrencyFormatter = NumberFormat.getCurrencyInstance();

    //Caching
    mJdToTitleArray = new SparseArray<String>();
    mIdToTimeArray = new SparseArray<String>();
    mIdToPayArray = new SparseArray<String>();

    mCurrentJulianDay = TimeUtils.getCurrentJulianDay();

    mShowIncomePref = Prefs.getInstance(context).get(context.getString(R.string.settings_key_show_income),
            true);
}