ViewPager pager = /* get my ViewPager */; // assume this actually has stuff in it final ArrayList<String> titles = new ArrayList<String>(); FragmentManager fm = getSupportFragmentManager(); pager.setAdapter(new FragmentStatePagerAdapter(fm) { public int getCount() { return titles.size(); } public Fragment getItem(int position) { MyFragment fragment = new MyFragment(); fragment.setTitle(titles.get(position)); return fragment; } public int getItemPosition(Object item) { MyFragment fragment = (MyFragment)item; String title = fragment.getTitle(); int position = titles.indexOf(title); if (position >= 0) { return position; } else { return POSITION_NONE; } } });
private void addToMap(Map<String, Method> map, String name, Method newMethod) { Method mapMethod = map.get(name); // Adds new method to map if method does not exist in map // or if class of new method is subclass of class of method in map. if ((mapMethod != null) && (newMethod != null)) { // get the class hierarchy. ArrayList<Class<?>> classHierarchy = new ArrayList<Class<?>>(); for (Class<?> cls=this.getClass(); cls != null; cls=cls.getSuperclass()) { classHierarchy.add(cls); } int classLevelMap = classHierarchy.indexOf(mapMethod.getDeclaringClass()); int classLevelNew = classHierarchy.indexOf(newMethod.getDeclaringClass()); if (classLevelMap <= classLevelNew) { return; } } map.put(name, newMethod); } }
/** * Shuffles the current play queue. * * This method first backs up the existing play queue and item being played. * Then a newly shuffled play queue will be generated along with currently * playing item placed at the beginning of the queue. * * Will emit a {@link ReorderEvent} in any context. * */ public synchronized void shuffle() { if (backup == null) { backup = new ArrayList<>(streams); } final int originIndex = getIndex(); final PlayQueueItem current = getItem(); Collections.shuffle(streams); final int newIndex = streams.indexOf(current); if (newIndex != -1) { streams.add(0, streams.remove(newIndex)); } queueIndex.set(0); broadcast(new ReorderEvent(originIndex, queueIndex.get())); }
/** * Add a SQL statement to the history. * * @param sql the SQL statement */ void addCommand(String sql) { if (sql == null) { return; } sql = sql.trim(); if (sql.length() == 0) { return; } if (commandHistory.size() > MAX_HISTORY) { commandHistory.remove(0); } int idx = commandHistory.indexOf(sql); if (idx >= 0) { commandHistory.remove(idx); } commandHistory.add(sql); if (server.isCommandHistoryAllowed()) { server.saveCommandHistoryList(commandHistory); } }
/** * 为被裁切的图片设置已被裁切的标识 * * @param uri 被裁切的图片 * @return 该图片是否是最后一张 */ public Map setCropWithUri(Uri uri, boolean cropped) { if (!cropped) { hasFailed = true; } int index = outUris.indexOf(uri); tImages.get(index).setCropped(cropped); Map result = new HashMap(); result.put("index", index); result.put("isLast", index == outUris.size() - 1 ? true : false); return result; } }
private void initHourData() { hours.clear(); int currentHour = 0; if (!resetWhileWheel) { if (timeMode == HOUR_24) { currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); } else { currentHour = Calendar.getInstance().get(Calendar.HOUR); } } for (int i = startHour; i <= endHour; i++) { String hour = DateUtils.fillZero(i); if (!resetWhileWheel) { if (i == currentHour) { selectedHour = hour; } } hours.add(hour); } if (hours.indexOf(selectedHour) == -1) { //当前设置的小时不在指定范围,则默认选中范围开始的小时 selectedHour = hours.get(0); } if (!resetWhileWheel) { selectedMinute = DateUtils.fillZero(Calendar.getInstance().get(Calendar.MINUTE)); } }
/** * Adds a texture to this material. Throws and error if the maximum number of textures was reached. * * @param texture * * @throws TextureException */ public void addTexture(ATexture texture) throws TextureException { if (mTextureList.indexOf(texture) > -1) return; if (mTextureList.size() + 1 > mMaxTextures) { throw new TextureException("Maximum number of textures for this material has been reached. Maximum number of textures is " + mMaxTextures + "."); } mTextureList.add(texture); TextureManager.getInstance().addTexture(texture); texture.registerMaterial(this); mIsDirty = true; }
assert graph != null : "Graph not defined"; assert ((!isFinalNode(node)) && (!isInitialNode(node))); int nodePosition = nodes.indexOf(node); nodes.remove(nodePosition); int index; for (graph.startNodeIterator(), index = nodePosition; graph.hasMoreNodes(); index++) { nodes.add(index, graph.nextNode());
/** * Copies a path */ private static void duplicatePath(int lastPathIndex, State fromState, State toState, ArrayList<ArrayList<State>> paths) { ArrayList<State> lastPath = paths.get(lastPathIndex); // copy the last path to a new one, from start to current state int fromIndex = lastPath.indexOf(fromState); int toIndex = lastPath.indexOf(toState); if (toIndex == -1) { toIndex = lastPath.size() - 1; } ArrayList<State> newPath = new ArrayList<State>(lastPath.subList( fromIndex, toIndex)); paths.add(newPath); }
assert stsc != null; if (stsc.getEntries().isEmpty()) { List<SampleToChunkBox.Entry> entries = new ArrayList<SampleToChunkBox.Entry>(); stsc.setEntries(entries); entries.add(new SampleToChunkBox.Entry(chunkNumber, samples.size(), 1)); if (ctts == null) { ctts = new CompositionTimeToSample(); ctts.setEntries(new ArrayList<CompositionTimeToSample.Entry>()); ArrayList<Box> bs = new ArrayList<Box>(stbl.getBoxes()); bs.add(bs.indexOf(stts), ctts); if (stts.getEntries().isEmpty()) { ArrayList<TimeToSampleBox.Entry> entries = new ArrayList<TimeToSampleBox.Entry>(stts.getEntries()); entries.add(new TimeToSampleBox.Entry(1, sample.getDuration())); stts.setEntries(entries); } else {