Example usage for android.util SparseBooleanArray get

List of usage examples for android.util SparseBooleanArray get

Introduction

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

Prototype

public boolean get(int key, boolean valueIfKeyNotFound) 

Source Link

Document

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

Usage

From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    screenStep = ScreenStep.MENU;//from w w  w.  jav  a2 s  .  com

    getSupportActionBar().setSubtitle(Constants.getSelectedCourseShortName());
    getSupportActionBar().setIcon(R.drawable.test);

    tagsAnswersTypeItemClickListener = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            ListView lv = (ListView) parent;
            int childCount = lv.getCount();
            SparseBooleanArray checkedItems = lv.getCheckedItemPositions();
            boolean allChecked = true;

            if (position == 0) {
                for (int i = 1; i < childCount; i++) {
                    lv.setItemChecked(i, checkedItems.get(0, false));
                }
            } else {
                for (int i = 1; i < childCount; i++) {
                    if (!checkedItems.get(i, false)) {
                        allChecked = false;
                    }
                }

                if (allChecked) {
                    lv.setItemChecked(0, true);
                } else {
                    lv.setItemChecked(0, false);
                }
            }
        }
    };

    tfAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    tfAdapter.add(getString(R.string.trueMsg));
    tfAdapter.add(getString(R.string.falseMsg));

    String selection = "id=" + Long.toString(Constants.getSelectedCourseCode());
    Cursor dbCursor = dbHelper.getDb().getCursor(Constants.DB_TABLE_TEST_CONFIG, selection, null);
    startManagingCursor(dbCursor);

    if (dbCursor.getCount() > 0) {
        if (isDebuggable) {
            Log.d(TAG, "selectedCourseCode = " + Long.toString(Constants.getSelectedCourseCode()));
        }

        test = (Test) dbHelper.getRow(Constants.DB_TABLE_TEST_CONFIG, "id",
                Long.toString(Constants.getSelectedCourseCode()));

        if (test != null) {
            selectNumQuestions();
        } else {
            Toast.makeText(this, R.string.testNoQuestionsCourseMsg, Toast.LENGTH_LONG).show();
            finish();
        }
    } else {
        Toast.makeText(this, R.string.testNoQuestionsMsg, Toast.LENGTH_LONG).show();
        finish();
    }

    setResult(RESULT_OK);
}

From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java

/**
 * Function to set the answer types that will be present in the test
 *///from   ww  w .  j  a  v a  2s. co m
private void setAnswerTypes() {
    ListView checkBoxesList = (ListView) findViewById(R.id.testAnswerTypesList);
    AnswerTypesArrayAdapter answerTypesAdapter = (AnswerTypesArrayAdapter) checkBoxesList.getAdapter();
    int childsCount = checkBoxesList.getCount();
    SparseBooleanArray checkedItems = checkBoxesList.getCheckedItemPositions();
    answerTypesList = new ArrayList<String>();

    /*
       * If "All tags" item checked, add the whole list to the list of selected answer types,
     * else, add the selected items to the list of selected answer types
     */
    if (checkedItems.get(0, false)) {
        answerTypesList.add("all");
    } else {
        for (int i = 1; i < childsCount; i++) {
            if (checkedItems.get(i, false)) {
                answerTypesList.add((String) answerTypesAdapter.getItem(i));
            }
        }
    }

    if (isDebuggable) {
        Log.d(TAG, "answerTypesList=" + answerTypesList.toString());
    }

    //If no answer types selected, show a message to notice user
    if (answerTypesList.isEmpty()) {
        Toast.makeText(getApplicationContext(), R.string.testNoAnswerTypesSelectedMsg, Toast.LENGTH_LONG)
                .show();

        //If any answer type is selected, generate the test and show the first question screen
    } else {
        makeTest();
    }
}

From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java

/**
 * Reads the user answer of a question// www. j  a va  2s.  c  om
 *
 * @param q Question to read the answer
 */
private void readUserAnswer(TestQuestion q) {
    LinearLayout testMakeList = (LinearLayout) findViewById(R.id.testMakeList);
    EditText textAnswer = (EditText) findViewById(R.id.testMakeEditText);
    List<TestAnswer> la = q.getAnswers();
    int checkedListCount, selectedPos;
    String answerType, userAnswer;
    SparseBooleanArray checkedItems;

    answerType = q.getAnswerType();
    if (answerType.equals(TestAnswer.TYPE_TEXT) || answerType.equals(TestAnswer.TYPE_INT)
            || answerType.equals(TestAnswer.TYPE_FLOAT)) {

        la.get(0).setUserAnswer(String.valueOf(textAnswer.getText()));
    } else if (answerType.equals(TestAnswer.TYPE_MULTIPLE_CHOICE)) {
        checkedItems = getCheckedItemPositions(testMakeList);
        checkedListCount = checkedItems.size();
        for (int i = 0; i < checkedListCount; i++) {
            la.get(i).setUserAnswer(Utils.parseBoolString(checkedItems.get(i, false)));
        }
    } else {
        selectedPos = getCheckedItemPosition(testMakeList);
        if (selectedPos == -1) {
            userAnswer = "";
        } else {
            userAnswer = la.get(selectedPos).getAnswer();
        }

        la.get(0).setUserAnswer(userAnswer);
    }
}