Example usage for java.util ArrayList indexOf

List of usage examples for java.util ArrayList indexOf

Introduction

In this page you can find the example usage for java.util ArrayList indexOf.

Prototype

public int indexOf(Object o) 

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:carskit.data.processor.DataDAO.java

/**
 * Convert loaded SparseMatrix to SparseTensor
 *//*w  w  w  . j a  v a2 s  . c  o  m*/

public SparseTensor toSparseTensor(SparseMatrix sm) {
    int numDims = 2 + this.numContextDims();
    int[] dims = new int[numDims];
    List<Integer>[] ndLists = (List<Integer>[]) new List<?>[numDims];
    Set<Integer>[] ndSets = (Set<Integer>[]) new Set<?>[numDims];
    List<Double> vals = new ArrayList<Double>();
    for (int d = 0; d < numDims; d++) {
        ndLists[d] = new ArrayList<Integer>();
        ndSets[d] = new HashSet<Integer>();
    }

    dimensionConditionsList = new HashMap<>();

    for (librec.data.MatrixEntry me : sm) {
        int rowid = me.row();
        int ctxid = me.column();
        double rate = me.get();
        int uid = getUserIdFromUI(rowid);
        int iid = getItemIdFromUI(rowid);

        vals.add(rate);
        ndLists[0].add(uid); // user dimension
        ndSets[0].add(uid);
        ndLists[1].add(iid); // item dimension
        ndSets[1].add(iid);

        // start recording context dimensions
        Collection<Integer> listOfConditions = contextConditionsList.get(ctxid);
        for (int condId : listOfConditions) {
            int dimId = condDimensionMap.get(condId);
            int index_condId = -1;
            if (dimensionConditionsList.containsKey(dimId)) {
                ArrayList<Integer> list = dimensionConditionsList.get(dimId);
                index_condId = list.indexOf(condId);
                if (index_condId == -1)
                    list.add(condId);
                index_condId = list.size() - 1;
                dimensionConditionsList.put(dimId, list);
            } else {
                ArrayList<Integer> list = new ArrayList<>();
                list.add(condId);
                dimensionConditionsList.put(dimId, list);
                index_condId = 0;
            }
            ndLists[2 + dimId].add(index_condId); // since user and item dimensions are the first two dimensions
            ndSets[2 + dimId].add(index_condId);
        }
    }
    for (int d = 0; d < numDims; d++) {
        dims[d] = ndSets[d].size();
    }
    SparseTensor st = new SparseTensor(dims, ndLists, vals);
    st.setUserDimension(0);
    st.setItemDimension(1);
    return st;
}

From source file:com.vgi.mafscaling.OpenLoop.java

private boolean getColumnsFilters(String[] elements, boolean isPolSet) {
    boolean ret = true;
    ArrayList<String> columns = new ArrayList<String>(Arrays.asList(elements));
    String logThtlAngleColName = Config.getThrottleAngleColumnName();
    String logAfLearningColName = Config.getAfLearningColumnName();
    String logAfCorrectionColName = Config.getAfCorrectionColumnName();
    String logMafvColName = Config.getMafVoltageColumnName();
    String logAfrColName = Config.getWidebandAfrColumnName();
    String logRpmColName = Config.getRpmColumnName();
    String logLoadColName = Config.getLoadColumnName();
    String logCommandedAfrColName = Config.getCommandedAfrColumnName();
    logThtlAngleColIdx = columns.indexOf(logThtlAngleColName);
    logAfLearningColIdx = columns.indexOf(logAfLearningColName);
    logAfCorrectionColIdx = columns.indexOf(logAfCorrectionColName);
    logMafvColIdx = columns.indexOf(logMafvColName);
    logAfrColIdx = columns.indexOf(logAfrColName);
    logRpmColIdx = columns.indexOf(logRpmColName);
    logLoadColIdx = columns.indexOf(logLoadColName);
    logCommandedAfrCol = columns.indexOf(logCommandedAfrColName);
    if (logThtlAngleColIdx == -1) {
        Config.setThrottleAngleColumnName(Config.NO_NAME);
        ret = false;//from   w w  w .  ja  v  a 2 s .c om
    }
    if (logAfLearningColIdx == -1) {
        Config.setAfLearningColumnName(Config.NO_NAME);
        ret = false;
    }
    if (logAfCorrectionColIdx == -1) {
        Config.setAfCorrectionColumnName(Config.NO_NAME);
        ret = false;
    }
    if (logMafvColIdx == -1) {
        Config.setMafVoltageColumnName(Config.NO_NAME);
        ret = false;
    }
    if (logAfrColIdx == -1) {
        Config.setWidebandAfrColumnName(Config.NO_NAME);
        ret = false;
    }
    if (logRpmColIdx == -1) {
        Config.setRpmColumnName(Config.NO_NAME);
        ret = false;
    }
    if (logLoadColIdx == -1) {
        Config.setLoadColumnName(Config.NO_NAME);
        ret = false;
    }
    if (logCommandedAfrCol == -1) {
        Config.setCommandedAfrColumnName(Config.NO_NAME);
        if (!isPolSet)
            ret = false;
    }
    wotPoint = Config.getWOTStationaryPointValue();
    minMafV = Config.getMafVMinimumValue();
    afrErrPrct = Config.getWidebandAfrErrorPercentValue();
    minWotEnrichment = Config.getWOTEnrichmentValue();
    afrRowOffset = Config.getWBO2RowOffset();
    skipRowsOnTransition = Config.getOLCLTransitionSkipRows();
    return ret;
}

From source file:de.spiritcroc.modular_remote.MainActivity.java

public void orderPages(List<Integer> order) {
    ArrayList<PageContainerFragment> pages = new ArrayList<>();
    for (int i = 0; i < this.pages.size(); i++) {
        int index = order.indexOf(i);
        if (index < 0 || index >= this.pages.size()) {
            Log.e(LOG_TAG, "orderPages: illegal index " + index + " for page " + i);
            return;
        }/*from   w  w  w  .  j  a  v a 2 s  . c o  m*/
        pages.add(this.pages.get(index));
    }
    if (pages.equals(this.pages)) {
        return;
    }
    PageContainerFragment currentPage = this.pages.get(viewPager.getCurrentItem());
    this.pages = pages;
    notifyDataSetChanged();
    restart(pages.indexOf(currentPage));
}

From source file:nubisave.component.graph.splitteradaption.NubisaveEditor.java

protected void interconnectNubisaveComponents(Graph<AbstractNubisaveComponent, Object> nubisaveComponentGraph,
        Factory<? extends NubiSaveEdge> edgeFactory) {
    boolean connected = false;
    WeightedNubisaveVertexEdge edge;/*from   w  w  w  . ja  v  a 2s  .c  o m*/
    File file = new File(storage_directory + "/" + "connections.txt");
    HashMap hh = new HashMap();
    ArrayList<AbstractNubisaveComponent> myNodeList = new ArrayList<AbstractNubisaveComponent>(
            nubisaveComponentGraph.getVertices());
    ArrayList str = new ArrayList();
    for (int i = 0; i < nubisaveComponentGraph.getVertices().size(); i++) {
        str.add(myNodeList.get(i).getUniqueName());
    }
    if (file.exists()) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(file));
            String strLine;
            try {
                //Read the text file Line By Line
                while ((strLine = reader.readLine()) != null) {
                    String startVertex = strLine.split(" ")[0];
                    String endVertex = strLine.split(" ")[1];
                    hh.put(startVertex, endVertex);

                    for (AbstractNubisaveComponent component : nubisaveComponentGraph.getVertices()) {
                        if (component.getUniqueName().equals(startVertex)) {
                            String endpoint = (String) hh.get(startVertex);
                            int pos = str.indexOf(endpoint);
                            AbstractNubisaveComponent endcomponent = myNodeList.get(pos);
                            edge = (WeightedNubisaveVertexEdge) edgeFactory.create();
                            edge.setWeight(component.getNrOfFilePartsToStore());
                            graph.addEdge(edge, component.getRequiredPorts().iterator().next(),
                                    endcomponent.getProvidedPorts().iterator().next(), EdgeType.DIRECTED);
                        }
                    }
                }
                reader.close();
            } catch (IOException ex) {
                Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:org.saiku.reporting.core.builder.SimpleCrosstabBuilder.java

public void build() throws ReportProcessingException {

    /*/*  ww w.ja va  2  s .  c  o m*/
     * Generate the Details-Row
     */
    final CrosstabCellBody cellBody = new CrosstabCellBody();

    //---------------------------------
    DetailsHeader detailsHeader = new DetailsHeader();
    detailsHeader.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f);
    detailsHeader.getStyle().setStyleProperty(BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_ROW);
    ArrayList<FieldDefinition> detailFieldDefinitions = this.reportSpecification.getFieldDefinitions();
    final float[] computedWidth = ReportBuilderUtil.correctFieldWidths(detailFieldDefinitions, definition);
    DetailsHeaderBuilder detailsHeaderBuilder = new DetailsHeaderBuilder(attributeContext, definition,
            flowController, reportSpecification);
    int j = 0;
    for (FieldDefinition field : detailFieldDefinitions) {
        detailsHeaderBuilder.build(detailsHeader, field, computedWidth[j], j);
        j++;
    }
    cellBody.setHeader(detailsHeader);
    //---------------------------------

    cellBody.addElement(createCell(null, INNERMOST, INNERMOST));

    GroupBody body = cellBody;

    /*
     * Generate the Column-Groups
     */
    ArrayList<GroupDefinition> groupDefinitions = this.reportSpecification.getGroupDefinitions();

    ListIterator<GroupDefinition> colGrpItr = groupDefinitions.listIterator(groupDefinitions.size());

    while (colGrpItr.hasPrevious()) {
        final GroupDefinition colGrp = colGrpItr.previous();
        if (colGrp.getType().equals(GroupType.CT_COLUMN)) {
            final CrosstabColumnGroup columnGroup = new CrosstabColumnGroup(body);

            columnGroup.setName("Group " + colGrp.getGroupName());
            columnGroup.setField(colGrp.getFieldId());

            /*
             1) Chrosstab Header
             2) Title Header
             3) Summary Header
             */
            final List<RootBandFormat> headerFormats = colGrp.getHeaderFormats();

            int index = groupDefinitions.indexOf(colGrp);
            String uid = RPT_GROUP_HEADER + index;
            String htmlClass = "saiku " + uid;

            RootBandFormat headerFormat = null;

            if (headerFormats.size() < 1 || headerFormats.get(0) == null) {
                headerFormat = new RootBandFormat();
                headerFormats.add(0, headerFormat);
            } else {
                headerFormat = headerFormats.get(0);
            }

            Element headerItem = createFieldItem(colGrp.getFieldId());

            //MergeFormatUtil.mergeElementFormats(headerItem, headerFormat);
            MergeFormatUtil.mergeElementFormats(columnGroup.getHeader(), headerFormat);

            headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS,
                    htmlClass + "-0");
            headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-0");

            //Is this used for style definitions?            
            headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Xml.ID, uid + "-0");

            columnGroup.getHeader().addElement(headerItem);
            columnGroup.getHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f);
            columnGroup.getHeader().getStyle().setStyleProperty(TextStyleKeys.BOLD, Boolean.TRUE);

            RootBandFormat titleFormat = null;

            if (headerFormats.size() < 2 || headerFormats.get(1) == null) {
                titleFormat = new RootBandFormat();
                headerFormats.add(1, titleFormat);
            } else {
                titleFormat = headerFormats.get(1);
            }

            String titleLabel = titleFormat.getLabel() != null ? titleFormat.getLabel()
                    : colGrp.getDisplayName();
            Element titleItem = createLabel(titleLabel);

            MergeFormatUtil.mergeElementFormats(titleItem, titleFormat);

            titleItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS,
                    htmlClass + "-1");
            titleItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-1");
            columnGroup.getTitleHeader().addElement(titleItem);
            columnGroup.getTitleHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f);

            RootBandFormat summaryFormat = null;

            if (headerFormats.size() < 3 || headerFormats.get(2) == null) {
                summaryFormat = new RootBandFormat();
                headerFormats.add(1, summaryFormat);
            } else {
                summaryFormat = headerFormats.get(2);
            }

            String summaryLabel = summaryFormat.getLabel() != null ? summaryFormat.getLabel() : "Total";
            Element summaryItem = createLabel(summaryLabel);

            MergeFormatUtil.mergeElementFormats(summaryItem, summaryFormat);

            summaryItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS,
                    htmlClass + "-2");
            summaryItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-2");
            columnGroup.getSummaryHeader().addElement(summaryItem);
            columnGroup.getSummaryHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f);
            columnGroup.setPrintSummary(colGrp.isPrintSummary());

            if (colGrp.isPrintSummary()) {
                //create cell needs to be enhanced later to always pick the correct group combination for the
                //element formats

                final CrosstabCell cell = createCell("Group " + colGrp.getFieldId(), colGrp.getFieldId(),
                        INNERMOST);
                cell.setColumnField(colGrp.getFieldId());
                cell.setName(colGrp.getFieldId());
                cellBody.addElement(cell);
            }
            body = new CrosstabColumnGroupBody(columnGroup);
        }
    }

    /*
     * Generate the Row-Groups
     */
    ListIterator<GroupDefinition> rowGrpItr = groupDefinitions.listIterator(groupDefinitions.size());

    while (rowGrpItr.hasPrevious()) {
        final GroupDefinition rowGrp = rowGrpItr.previous();
        if (rowGrp.getType().equals(GroupType.CT_ROW)) {
            final CrosstabRowGroup rowGroup = new CrosstabRowGroup(body);
            int index = groupDefinitions.indexOf(rowGrp);
            String uid = RPT_GROUP_HEADER + index;
            String htmlClass = "saiku " + uid;

            rowGroup.setName("Group " + rowGrp.getGroupName());
            rowGroup.setField(rowGrp.getFieldId());

            final List<RootBandFormat> headerFormats = rowGrp.getHeaderFormats();

            RootBandFormat headerFormat = null;

            if (headerFormats.size() < 1 || headerFormats.get(0) == null) {
                headerFormat = new RootBandFormat();
                headerFormats.add(0, headerFormat);
            } else {
                headerFormat = headerFormats.get(0);
            }

            Element headerItem = createFieldItem(rowGrp.getFieldId());

            //MergeFormatUtil.mergeElementFormats(headerItem, headerFormat);
            MergeFormatUtil.mergeElementFormats(rowGroup.getHeader(), headerFormat);

            headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS,
                    htmlClass + "-0");
            headerItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-0");

            rowGroup.getHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f);
            rowGroup.getHeader().getStyle().setStyleProperty(TextStyleKeys.BOLD, Boolean.TRUE);
            rowGroup.getHeader().addElement(headerItem);

            RootBandFormat titleFormat = null;

            if (headerFormats.size() < 2 || headerFormats.get(1) == null) {
                titleFormat = new RootBandFormat();
                headerFormats.add(1, titleFormat);
            } else {
                titleFormat = headerFormats.get(1);
            }

            String titleLabel = titleFormat.getLabel() != null ? titleFormat.getLabel()
                    : rowGrp.getDisplayName();
            Element titleItem = createLabel(titleLabel);

            MergeFormatUtil.mergeElementFormats(titleItem, titleFormat);

            titleItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS,
                    htmlClass + "-1");
            titleItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-1");

            rowGroup.getTitleHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f);
            rowGroup.getTitleHeader().addElement(titleItem);

            RootBandFormat summaryFormat = null;

            if (headerFormats.size() < 3 || headerFormats.get(2) == null) {
                summaryFormat = new RootBandFormat();
                headerFormats.add(1, summaryFormat);
            } else {
                summaryFormat = headerFormats.get(2);
            }

            String summaryLabel = summaryFormat.getLabel() != null ? summaryFormat.getLabel() : "Total";
            Element summaryItem = createLabel(summaryLabel);

            MergeFormatUtil.mergeElementFormats(summaryItem, summaryFormat);

            summaryItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.STYLE_CLASS,
                    htmlClass + "-2");
            summaryItem.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.XML_ID, uid + "-2");
            rowGroup.getSummaryHeader().getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, -100f);
            rowGroup.getSummaryHeader().addElement(summaryItem);
            rowGroup.setPrintSummary(rowGrp.isPrintSummary());

            if (rowGrp.isPrintSummary()) {
                final CrosstabCell cell = createCell("Group " + rowGroup.getField(), INNERMOST,
                        rowGrp.getFieldId());
                cell.setRowField(rowGrp.getFieldId());
                cell.setName(rowGrp.getFieldId());
                cellBody.addElement(cell);

                ListIterator<GroupDefinition> colGrpItrInner = groupDefinitions
                        .listIterator(groupDefinitions.size());

                while (colGrpItrInner.hasPrevious()) {
                    final GroupDefinition colGrp = colGrpItrInner.previous();
                    if (colGrp.getType().equals(GroupType.CT_COLUMN)) {
                        if (colGrp.isPrintSummary()) {
                            final CrosstabCell crosstabCell = createCell("Group " + rowGroup.getField(),
                                    colGrp.getFieldId(), rowGrp.getFieldId());
                            crosstabCell.setColumnField(colGrp.getFieldId());
                            crosstabCell.setRowField(rowGrp.getFieldId());
                            crosstabCell.setName(colGrp.getFieldId() + "," + rowGroup.getField());
                            cellBody.addElement(crosstabCell);
                        }
                    }
                }
            }
            body = new CrosstabRowGroupBody(rowGroup);
        }
    }
    /*
     * Let's ommit Other-Groups for now
     */

    // At The end we need to wrap the generated stuff in a crosstabgroup and put it in the
    // report
    CrosstabGroup crosstabRootGroup = new CrosstabGroup(body);
    crosstabRootGroup.setPrintColumnTitleHeader(true);
    crosstabRootGroup.setPrintDetailsHeader(true);
    insertCrosstab(crosstabRootGroup);

    //remove all relational groups
    GroupUtils.removedUnusedTemplateGroups(0, definition);

}

From source file:com.google.example.eightbitartist.DrawingActivity.java

/**
 * Update the turn order so that each participant has a unique slot.
 *///ww  w  .  ja v a2  s .co m
private void updateTurnIndices() {
    // Turn order is determined by sorting participant IDs, which are consistent across
    // devices (but not across sessions)
    ArrayList<String> ids = new ArrayList<>();
    ids.addAll(mParticipants.keySet());
    Collections.sort(ids);

    // Get your turn order
    mMyTurnIndex = ids.indexOf(mMyPersistentId);
    Log.d(TAG, "My turn index: " + mMyTurnIndex);
}

From source file:SuitaDetails.java

public void setComboTBs() {
    if (parent == null)
        return;//w ww. j a  va2s. c om
    for (ListSelectionListener l : combo.getListSelectionListeners()) {
        combo.removeListSelectionListener(l);
    }
    StringBuilder b = new StringBuilder();
    DefaultMutableTreeNode root = RunnerRepository.window.mainpanel.p4.getSut().sut.root;
    int sutsnr = root.getChildCount();
    for (int i = 0; i < sutsnr; i++) {
        b.append(root.getChildAt(i).toString());
        b.append(";");
    }

    //         StringBuilder b = new StringBuilder();

    //         Node parentnode = RunnerRepository.window.mainpanel.p4.getTB().getParentNode();
    //         HashMap children =  parentnode.getChildren();
    //         if(children!=null&&children.size()!=0){
    //             Set keys = children.keySet();
    //             Iterator iter = keys.iterator();
    //             while(iter.hasNext()){
    //                 String n = iter.next().toString();
    //                 String name = parentnode.getChild(n).getName();
    //                 b.append(name);
    //                 b.append(";");
    //             }
    //         }
    String[] vecresult = b.toString().split(";");

    combo.setModel(new DefaultComboBoxModel(vecresult));

    String[] strings = parent.getEpId();
    ArrayList<String> array = new ArrayList<String>(Arrays.asList(vecresult));
    int[] sel = new int[strings.length];
    for (int i = 0; i < strings.length; i++) {
        sel[i] = array.indexOf(strings[i]);
    }
    combo.setSelectedIndices(sel);
    combo.addListSelectionListener(new MyListSelectionListener());

}

From source file:in.andres.kandroid.ui.TaskDetailActivity.java

private void showSubtaskDialog(@Nullable final KanboardSubtask subtask) {
    View dlgView = getLayoutInflater().inflate(R.layout.dialog_new_subtask, null);
    final EditText editTitle = (EditText) dlgView.findViewById(R.id.subtask_title);
    editTitle.setText(subtask == null ? "" : subtask.getTitle());
    final Spinner userSpinner = (Spinner) dlgView.findViewById(R.id.user_spinner);
    ArrayList<String> possibleOwners = Collections.list(users.elements());
    possibleOwners.add(0, "");
    ArrayAdapter<String> adapter = new ArrayAdapter<>(self, android.R.layout.simple_spinner_item,
            possibleOwners);//w w  w . ja  va2 s.co  m
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    userSpinner.setAdapter(adapter);
    if (subtask != null)
        userSpinner.setSelection(possibleOwners.indexOf(users.get(subtask.getUserId())));

    AlertDialog.Builder builder = new AlertDialog.Builder(self);
    builder.setTitle(getString(
            subtask == null ? R.string.taskview_fab_new_subtask : R.string.taskview_dlg_update_subtask));
    builder.setView(dlgView);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Integer userid = null;
            if (userSpinner.getSelectedItem() != null) {
                for (Enumeration<Integer> iter = users.keys(); iter.hasMoreElements();) {
                    Integer key = iter.nextElement();
                    if (users.get(key).contentEquals((String) userSpinner.getSelectedItem())) {
                        userid = key;
                        break;
                    }
                }
            }
            if (!editTitle.getText().toString().equalsIgnoreCase("")) {
                if (subtask == null) {
                    Log.i(Constants.TAG, "Creating new subtask.");
                    kanboardAPI.createSubtask(task.getId(), editTitle.getText().toString(), userid, null, null,
                            null);
                } else {
                    Log.i(Constants.TAG, "Updating subtask.");
                    kanboardAPI.updateSubtask(subtask.getId(), subtask.getTaskId(),
                            editTitle.getText().toString(), userid, null, null, null);
                }
                dialog.dismiss();
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    builder.show();
}

From source file:im.vector.fragments.MembersInvitationDialogFragment.java

/**
 * Init the dialog view.//from  w  w  w . j  ava 2s  .  c  o m
 * @param v the dialog view.
 */
void initView(View v) {
    mListView = ((ListView) v.findViewById(R.id.listView_members));

    IMXStore store = mSession.getDataHandler().getStore();

    // remove the current room members
    ArrayList<String> idsToIgnore = new ArrayList<String>();
    Room room = store.getRoom(mRoomId);
    Collection<RoomMember> currentMembers = room.getMembers();

    for (RoomMember member : currentMembers) {
        idsToIgnore.add(member.getUserId());
    }

    // get the members list
    ArrayList<RoomMember> members_OneToOne = new ArrayList<RoomMember>();
    ArrayList<String> ids_OneToOne = new ArrayList<String>();

    ArrayList<RoomMember> members_MaxTenMembers = new ArrayList<RoomMember>();
    ArrayList<String> ids_MaxTenMembers = new ArrayList<String>();

    ArrayList<RoomMember> members_BigRooms = new ArrayList<RoomMember>();
    ArrayList<String> ids_BigRooms = new ArrayList<String>();

    Collection<RoomSummary> summaries = store.getSummaries();

    for (RoomSummary summary : summaries) {
        // not the current summary
        if (!summary.getRoomId().equals(mRoomId)) {
            Collection<RoomMember> otherRoomMembers = room.getMembers();

            for (RoomMember member : otherRoomMembers) {
                String userID = member.getUserId();

                // accepted User ID or still active users
                if ((idsToIgnore.indexOf(userID) < 0)
                        && (RoomMember.MEMBERSHIP_JOIN.equals(member.membership))) {
                    int posOneToOne = ids_OneToOne.indexOf(userID);
                    int posTenMembers = ids_MaxTenMembers.indexOf(userID);
                    int posBigRooms = ids_BigRooms.indexOf(userID);

                    if (otherRoomMembers.size() <= 2) {
                        if (posBigRooms >= 0) {
                            members_BigRooms.remove(posBigRooms);
                            ids_BigRooms.remove(posBigRooms);
                        }

                        if (posTenMembers >= 0) {
                            members_MaxTenMembers.remove(posTenMembers);
                            ids_MaxTenMembers.remove(posTenMembers);
                        }

                        if (posOneToOne < 0) {
                            members_OneToOne.add(member);
                            ids_OneToOne.add(member.getUserId());
                        }
                    } else if (otherRoomMembers.size() <= 10) {
                        if (posBigRooms >= 0) {
                            members_BigRooms.remove(posBigRooms);
                            ids_BigRooms.remove(posBigRooms);
                        }

                        if ((posTenMembers < 0) && (posOneToOne < 0)) {
                            members_MaxTenMembers.add(member);
                            ids_MaxTenMembers.add(member.getUserId());
                        }
                    } else {
                        if ((posBigRooms < 0) && (posTenMembers < 0) && (posOneToOne < 0)) {
                            members_BigRooms.add(member);
                            ids_BigRooms.add(member.getUserId());
                        }
                    }
                }
            }
        }
    }

    mAdapter = new MembersInvitationAdapter(getActivity(), R.layout.adapter_item_members_invitation,
            getMXMediasCache());

    Collections.sort(members_OneToOne, alphaComparator);
    Collections.sort(members_MaxTenMembers, alphaComparator);
    Collections.sort(members_BigRooms, alphaComparator);

    mAdapter.addAll(members_OneToOne);
    mAdapter.addAll(members_MaxTenMembers);
    mAdapter.addAll(members_BigRooms);

    ArrayList<Integer> bounds = new ArrayList<Integer>();
    ArrayList<String> sectionTitles = new ArrayList<String>();

    int index = 0;

    if (members_OneToOne.size() > 0) {
        bounds.add(index);
        sectionTitles.add(getActivity().getResources().getString(R.string.members_one_to_one));
        index += members_OneToOne.size();
    }

    if (members_MaxTenMembers.size() > 0) {
        bounds.add(index);
        sectionTitles.add(getActivity().getResources().getString(R.string.members_small_room_members));
        index += members_MaxTenMembers.size();
    }

    if (members_BigRooms.size() > 0) {
        bounds.add(index);
        sectionTitles.add(getActivity().getResources().getString(R.string.members_large_room_members));
        index += members_BigRooms.size();
    }

    mAdapter.setSectionTiles(bounds, sectionTitles);

    mListView.setAdapter(mAdapter);
}

From source file:im.vector.activity.HomeActivity.java

private void refreshSlidingList() {
    // adjust the sliding menu entries
    ArrayList<Integer> slideMenuTitleIds = new ArrayList<Integer>(Arrays.asList(mSlideMenuTitleIds));
    ArrayList<Integer> slideMenuResourceIds = new ArrayList<Integer>(Arrays.asList(mSlideMenuResourceIds));

    Matrix matrix = Matrix.getInstance(this);

    // only one account, do not offer to remove it
    if (matrix.getSessions().size() == 1) {

        int pos = slideMenuTitleIds.indexOf(R.string.action_remove_account);

        if (pos >= 0) {
            slideMenuTitleIds.remove(pos);
            slideMenuResourceIds.remove(pos);
        }/*from  w  ww  .  j a  va  2  s.c  o m*/
    }

    GcmRegistrationManager gcmManager = Matrix.getInstance(this).getSharedGcmRegistrationManager();

    // hide the disconnect when GCM is enabled.
    if ((null != gcmManager) && gcmManager.useGCM()) {
        int pos = slideMenuTitleIds.indexOf(R.string.action_disconnect);

        if (pos >= 0) {
            slideMenuTitleIds.remove(pos);
            slideMenuResourceIds.remove(pos);
        }
    }

    // apply the updated sliding list
    Integer[] slideMenuTitleIds2 = new Integer[slideMenuTitleIds.size()];
    Integer[] slideMenuResourceIds2 = new Integer[slideMenuTitleIds.size()];
    addSlidingMenu(slideMenuResourceIds.toArray(slideMenuResourceIds2),
            slideMenuTitleIds.toArray(slideMenuTitleIds2), true);
}