Example usage for android.util SparseArray get

List of usage examples for android.util SparseArray get

Introduction

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

Prototype

public E get(int key) 

Source Link

Document

Gets the Object mapped from the specified key, or null if no such mapping has been made.

Usage

From source file:com.facebook.litho.ComponentsPools.java

static boolean canAddMountContentToPool(Context context, ComponentLifecycle lifecycle) {
    if (lifecycle.poolSize() == 0) {
        return false;
    }//from  w  w w  .  jav a  2 s . c  o  m

    final SparseArray<RecyclePool> poolsArray = sMountContentPoolsByContext.get(context);

    if (poolsArray == null) {
        return true;
    }

    final RecyclePool pool = poolsArray.get(lifecycle.getId());
    return pool == null || !pool.isFull();
}

From source file:dentex.youtube.downloader.YTD.java

public static CharSequence getListFilterConstraint(int c) {
    //0/*from  w w  w  . j a va  2  s .co  m*/
    List<Integer> iMp4List = Arrays.asList(iMp4);
    //1
    List<Integer> iWebmList = Arrays.asList(iWebm);
    //2
    List<Integer> iFlvList = Arrays.asList(iFlv);
    //3
    List<Integer> i3gpList = Arrays.asList(i3gp);

    //4
    List<Integer> iHdList = Arrays.asList(iHd);
    //5
    List<Integer> iLdList = Arrays.asList(iLd);
    //6
    List<Integer> iMdList = Arrays.asList(iMd);
    //7
    List<Integer> iSdList = Arrays.asList(iSd);

    //8
    List<Integer> i3dList = Arrays.asList(i3d);

    //9
    List<Integer> iVoList = Arrays.asList(iVo);
    //10
    List<Integer> iAoList = Arrays.asList(iAo);

    SparseArray<List<Integer>> filtersMap = new SparseArray<List<Integer>>();

    filtersMap.put(MP4_FILTER, iMp4List);
    filtersMap.put(WEBM_FILTER, iWebmList);
    filtersMap.put(FLV_FILTER, iFlvList);
    filtersMap.put(_3GP_FILTER, i3gpList);
    filtersMap.put(HD_FILTER, iHdList);
    filtersMap.put(LD_FILTER, iLdList);
    filtersMap.put(MD_FILTER, iMdList);
    filtersMap.put(SD_FILTER, iSdList);
    filtersMap.put(_3D_FILTER, i3dList);
    filtersMap.put(VO_FILTER, iVoList);
    filtersMap.put(AO_FILTER, iAoList);

    if (c == -1)
        return VIEW_ALL_STRING;

    CharSequence constraint = null;
    List<Integer> selectedMap = filtersMap.get(c);

    for (int i = 0; i < selectedMap.size(); i++) {
        if (constraint == null) {
            constraint = String.valueOf(selectedMap.get(i));
        } else {
            constraint = constraint + "/" + selectedMap.get(i);
        }
    }
    //Utils.logger("i", "ListFilterConstraint: " + constraint, DEBUG_TAG);
    return constraint;
}

From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java

private void addUpdateIfNeeded(SparseArray<List<String>> versionUpdates, ModelUpdate update) {
    if (versionUpdates.get(update.version()) != null) {
        versionUpdates.get(update.version()).add(update.sql());
    }//from www  . java  2  s.com
}

From source file:ru.annin.store.presentation.ui.viewholder.MainViewHolder.java

public MainViewHolder refreshChart() {
    SparseArray<Fragment> fragments = chartPagerAdapter.getRegisteredFragments();
    for (int i = 0; i < fragments.size(); ++i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null && fragment instanceof BaseChartFragment) {
            ((BaseChartFragment) fragment).updateChart();
        }/* w  w w  . jav a2 s.c  o m*/
    }
    return this;
}

From source file:com.harrcharr.reverb.StreamNodeFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.stream_node_fragment, container, false);
    mNodeHolder = (ViewGroup) v.findViewById(R.id.nodeHolder);

    PulseManager p = (getActivity() == null ? null : ((HasPulseManager) getActivity()).getPulseManager());

    if (p != null) {
        synchronized (p) {
            SparseArray<T> nodes = getNodesFromManager(p);
            for (int i = 0; i < nodes.size(); i++) {
                T node = nodes.get(nodes.keyAt(i));
                if (node != null) {
                    updateNode(node);/*from   w w w. j ava 2  s .c  o m*/
                }
            }
        }
    }

    ReverbSharedPreferences.registerOnSharedPreferenceChangeListener(getActivity(), this);

    return v;
}

From source file:com.harrcharr.reverb.StreamNodeFragment.java

public void onPulseConnectionReady(final PulseManager p) {
    if (getActivity() != null) {
        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                try {
                    getViewGroup().removeAllViews();
                    Log.d("Reverb", "Removed stale nodes");
                } catch (Exception e) {
                    Log.e("Reverb", e.getMessage());
                }/*  ww w . j  a va2 s. co m*/

                synchronized (p) {
                    SparseArray<T> nodes = getNodesFromManager(p);
                    for (int i = 0; i < nodes.size(); i++) {
                        T node = nodes.get(nodes.keyAt(i));
                        if (node != null) {
                            updateNode(node);
                        }
                    }
                }
            }
        });

    }

}

From source file:android.databinding.ViewDataBinding.java

/** @hide */
protected static <T> T getFromList(SparseArray<T> list, int index) {
    if (list == null || index < 0) {
        return null;
    }/*  w  w w  . j  ava  2s . c o  m*/
    return list.get(index);
}

From source file:com.aware.plugin.polarhrm.Plugin.java

private void showUI() {
    if (algorithm == null)
        return;//from   w  w w  .java2s . co m

    notificationBuilder.setContentText(
            "Heart rate: " + ((last_heart_rate > 0) ? last_heart_rate : "waiting for connection"));
    notificationBuilder.setContentTitle("Heart rate monitor");

    SparseArray<double[]> zones = algorithm.getZones();
    int zone = algorithm.getZone(last_heart_rate);
    double[] range = zones.get(zone);
    String announce = "";
    switch (zone) {
    case Algorithm.HR_ZONE_RECOVERY:
        notificationBuilder.setSubText("HR zone: recovery [" + range[0] + ";" + range[1] + "]");
        announce = "Recovery";
        break;
    case Algorithm.HR_ZONE_AEROBIC:
        notificationBuilder.setSubText("HR zone: aerobic [" + range[0] + ";" + range[1] + "]");
        announce = "Medium";
        break;
    case Algorithm.HR_ZONE_ANAEROBIC:
        notificationBuilder.setSubText("HR zone: anaerobic [" + range[0] + ";" + range[1] + "]");
        announce = "High";
        break;
    case Algorithm.HR_ZONE_RED_LINE:
        notificationBuilder.setSubText("HR zone: red line [" + range[0] + ";" + range[1] + "]");
        announce = "Extreme";
        break;
    case Algorithm.HR_ZONE_REGULAR:
        notificationBuilder
                .setSubText("HR zone: regular, less than " + zones.get(Algorithm.HR_ZONE_RECOVERY)[0]);
        announce = "Relaxed";
        break;
    }

    if (zone != last_zone && prefs.getBoolean("notify", false) && last_zone != -1) {
        Intent tts = new Intent(getApplicationContext(), Text_2_speech.class);
        tts.putExtra(Text_2_speech.EXTRA_TTS_TEXT, announce);
        startService(tts);
    }
    last_zone = zone;

    notificationBuilder.setSmallIcon(R.drawable.ic_stat_polar_hrm);
    notificationBuilder.setContentIntent(null);
    notificationBuilder.setOngoing(true);
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setWhen(System.currentTimeMillis());
    notManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}

From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayMainPresenter.java

@Override
public void createEncounter() {
    List<InputField> inputFields = new ArrayList<>();
    List<SelectOneField> radioGroupFields = new ArrayList<>();

    mFormDisplayView.enableSubmitButton(false);

    Encountercreate encountercreate = new Encountercreate();
    encountercreate.setPatient(mPatient.getUuid());
    encountercreate.setEncounterType(mEncountertype);

    List<Obscreate> observations = new ArrayList<>();

    SparseArray<Fragment> activefrag = mPageAdapter.getRegisteredFragments();
    boolean valid = true;
    for (int i = 0; i < activefrag.size(); i++) {
        FormDisplayPageFragment formPageFragment = (FormDisplayPageFragment) activefrag.get(i);
        if (!formPageFragment.checkInputFields()) {
            valid = false;/*from www. j ava 2s .c  o  m*/
            break;
        }

        inputFields.addAll(formPageFragment.getInputFields());
        radioGroupFields.addAll(formPageFragment.getSelectOneFields());
    }

    if (valid) {
        for (InputField input : inputFields) {
            if (input.getValue() != -1.0) {
                Obscreate obscreate = new Obscreate();
                obscreate.setConcept(input.getConcept());
                obscreate.setValue(String.valueOf(input.getValue()));
                LocalDateTime localDateTime = new LocalDateTime();
                obscreate.setObsDatetime(localDateTime.toString());
                obscreate.setPerson(mPatient.getUuid());
                observations.add(obscreate);
            }
        }

        for (SelectOneField radioGroupField : radioGroupFields) {
            if (radioGroupField.getChosenAnswer() != null) {
                Obscreate obscreate = new Obscreate();
                obscreate.setConcept(radioGroupField.getConcept());
                obscreate.setValue(radioGroupField.getChosenAnswer().getConcept());
                LocalDateTime localDateTime = new LocalDateTime();
                obscreate.setObsDatetime(localDateTime.toString());
                obscreate.setPerson(mPatient.getUuid());
                observations.add(obscreate);
            }
        }

        encountercreate.setObservations(observations);
        encountercreate.setFormname(mFormname);
        encountercreate.setPatientId(mPatientID);
        encountercreate.setFormUuid(getFormResourceByName(mFormname).getUuid());
        encountercreate.setObslist();
        encountercreate.save();

        if (!mPatient.isSynced()) {
            mPatient.addEncounters(encountercreate.getId());
            new PatientDAO().updatePatient(mPatient.getId(), mPatient);
            ToastUtil.error("Patient not yet registered. Form data is saved locally "
                    + "and will sync when internet connection is restored. ");
            mFormDisplayView.enableSubmitButton(true);
        } else {
            new EncounterService().addEncounter(encountercreate, new DefaultResponseCallbackListener() {
                @Override
                public void onResponse() {
                    mFormDisplayView.enableSubmitButton(true);
                }

                @Override
                public void onErrorResponse(String errorMessage) {
                    mFormDisplayView.showToast(errorMessage);
                    mFormDisplayView.enableSubmitButton(true);
                }
            });
            mFormDisplayView.quitFormEntry();
        }
    } else {
        mFormDisplayView.enableSubmitButton(true);
    }
}

From source file:com.facebook.litho.ComponentsPools.java

static Object acquireMountContent(Context context, int componentId, boolean allocatePool) {
    if (context instanceof ComponentContext) {
        context = ((ComponentContext) context).getBaseContext();

        if (context instanceof ComponentContext) {
            throw new IllegalStateException("Double wrapped ComponentContext.");
        }/*from ww w.  ja  va  2s  .c  o  m*/
    }

    final RecyclePool<Object> pool;

    synchronized (mountContentLock) {

        if (allocatePool) {
            if (sActivityCallbacks == null && !sIsManualCallbacks) {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    throw new RuntimeException(
                            "Activity callbacks must be invoked manually below ICS (API level 14)");
                }
                sActivityCallbacks = new PoolsActivityCallback();
                ((Application) context.getApplicationContext())
                        .registerActivityLifecycleCallbacks(sActivityCallbacks);
            }
        }

        SparseArray<RecyclePool> poolsArray = sMountContentPoolsByContext.get(context);

        if (poolsArray == null) {
            if (allocatePool) {
                // The context is created here because we are sure the Activity is alive at this point in
                // contrast of the release call where the Activity might by gone.
                sMountContentPoolsByContext.put(context, new SparseArray<RecyclePool>());
            }
            return null;
        }

        pool = poolsArray.get(componentId);
        if (pool == null) {
            return null;
        }
    }

    return pool.acquire();
}