List of usage examples for java.util ArrayList clear
public void clear()
From source file:com.xrmaddness.offthegrid.ListActivity.java
public void view_contacts() { ListView listview = (ListView) findViewById(R.id.contact_list); ArrayAdapter<Spanned> contacts_adapter; ArrayList<Spanned> contacts_list; contacts_list = new ArrayList<Spanned>(); final List<contact> contacts = db.contact_get_all(); contacts_list.clear(); for (int i = 0; i < contacts.size(); i++) { long time_lastact; Date lastact;/*from w w w . j a v a 2 s .co m*/ Spanned view_span; contact contact = contacts.get(i); String view_html; long unread = 0; time_lastact = contact.time_lastact_get() * 1000; lastact = new java.util.Date(time_lastact); SimpleDateFormat dateformat = new SimpleDateFormat(); String name_start = ""; String name_end = ""; if (contact.time_lastact_get() > contact.unread_get()) { name_start = "<b>"; name_end = "</b>"; unread = db.message_get_count_by_id(contact.id_get(), contact.unread_get()); } view_html = "<font "; if (contact.type_get() == contact.TYPE_PERSON) { Log.d("list", "person"); switch (contact.keystat_get()) { case com.xrmaddness.offthegrid.contact.KEYSTAT_NONE: Log.d("list", "keystat none"); view_html += "color='#990000'"; break; case com.xrmaddness.offthegrid.contact.KEYSTAT_RECEIVED: Log.d("list", "keystat received"); view_html += "color='#cc6600'"; break; case com.xrmaddness.offthegrid.contact.KEYSTAT_VERIFIED: Log.d("list", "keystat verified"); view_html += "color='#004400'"; break; } } view_html += ">"; view_html += name_start + contact.name_get() + name_end + "<br><small>"; if (contact.type_get() == contact.TYPE_GROUP) { String owner = contact.address_get(); List<String> members = contact.members_get(); for (int j = 0; j < members.size(); j++) { String member = members.get(j); if (member.equals(owner)) { view_html += "<i>" + member + "</i> "; } else { view_html += member + " "; } } } else { view_html += "<i>" + contact.address_get() + "</i> "; } view_html += "<br>"; view_html += dateformat.format(lastact); view_html += "</small></font>"; /* add number of unread messages */ if (unread > 0) { view_html += "<small><font color='#00cc00'> (" + unread + ")</font></small>"; } view_span = Html.fromHtml(view_html); contacts_list.add(view_span); } contacts_adapter = new ArrayAdapter<Spanned>(this, android.R.layout.simple_list_item_1, contacts_list); listview.setAdapter(contacts_adapter); contacts_adapter.notifyDataSetChanged(); listview.setAdapter(contacts_adapter); listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long id) { final contact c = contacts.get(position); if (c.type_get() == contact.TYPE_GROUP) { contact_view(c); } if (c.type_get() == contact.TYPE_PERSON) { switch (c.keystat_get()) { case contact.KEYSTAT_NONE: { Log.d("contact", "ask action"); AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); CharSequence[] items = { getString(R.string.action_send_key), getString(R.string.action_remove) }; builder.setTitle(R.string.dialog_contact).setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Log.d("contact", "which: " + which); if (which == 0) { Log.d("contact", "send_key_dialg(c)"); send_key_dialog(c); } if (which == 1) { Log.d("contact", "remove(c)"); remove(c); } } }); builder.show(); break; } case contact.KEYSTAT_RECEIVED: { Log.d("contact", "ask action"); AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); CharSequence[] items = { getString(R.string.action_verify), getString(R.string.action_send_key), getString(R.string.action_remove) }; builder.setTitle(R.string.dialog_contact).setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Log.d("contact", "which: " + which); if (which == 0) { Log.d("contact", "verify_dialog(c)"); verify_dialog(c); } if (which == 1) { Log.d("contact", "send_key_dialg(c)"); send_key_dialog(c); } if (which == 2) { Log.d("contact", "remove(c)"); remove(c); } } }); builder.show(); break; } case contact.KEYSTAT_VERIFIED: { contact_view(c); } } } } }); listview.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View view, int position, long id) { final contact c = contacts.get(position); if (c.type_get() == contact.TYPE_GROUP) { Log.d("contact", "ask action"); AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); CharSequence[] items = { getString(R.string.action_set_member), getString(R.string.action_set_name), getString(R.string.action_remove) }; builder.setTitle(R.string.dialog_contact).setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Log.d("contact", "which: " + which); if (which == 0) { Log.d("group", "set member"); set_member_dialog(c); } if (which == 1) { Log.d("group", "set name"); group_name_dialog(c); } if (which == 2) { Log.d("group", "remove(c)"); remove(c); } } }); builder.show(); return true; } if (c.type_get() == contact.TYPE_PERSON) { switch (c.keystat_get()) { case contact.KEYSTAT_VERIFIED: { Log.d("contact", "ask action"); AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); CharSequence[] items = { getString(R.string.action_send_key), getString(R.string.action_fingerprint), getString(R.string.action_remove) }; builder.setTitle(R.string.dialog_contact).setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Log.d("contact", "which: " + which); if (which == 0) { Log.d("contact", "send_key_dialg(c)"); send_key_dialog(c); } if (which == 1) { view_fingerprint_dialog(c); } if (which == 2) { Log.d("contact", "remove(c)"); remove(c); } } }); builder.show(); return true; } } } return false; } }); }
From source file:io.xujiaji.dmlib.recyclerview_item_anim.DmItemAnimator.java
/** * ?//from w ww.j a v a 2s . c o m */ @Override public void runPendingAnimations() { boolean removalsPending = !mPendingRemovals.isEmpty(); boolean movesPending = !mPendingMoves.isEmpty(); boolean changesPending = !mPendingChanges.isEmpty(); boolean additionsPending = !mPendingAdditions.isEmpty(); if (!removalsPending && !movesPending && !additionsPending && !changesPending) { // return; } // for (ViewHolder holder : mPendingRemovals) { animateRemoveImpl(holder); } mPendingRemovals.clear(); // item if (movesPending) { final ArrayList<MoveInfo> moves = new ArrayList<>(); moves.addAll(mPendingMoves); mMovesList.add(moves); mPendingMoves.clear(); Runnable mover = new Runnable() { @Override public void run() { for (MoveInfo moveInfo : moves) { animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY); } moves.clear(); mMovesList.remove(moves); } }; if (removalsPending) { View view = moves.get(0).holder.itemView; ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration()); } else { mover.run(); } } // item? if (changesPending) { final ArrayList<ChangeInfo> changes = new ArrayList<>(); changes.addAll(mPendingChanges); mChangesList.add(changes); mPendingChanges.clear(); Runnable changer = new Runnable() { @Override public void run() { for (ChangeInfo change : changes) { animateChangeImpl(change); } changes.clear(); mChangesList.remove(changes); } }; if (removalsPending) { ViewHolder holder = changes.get(0).oldHolder; ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration()); } else { changer.run(); } } // item if (additionsPending) { final ArrayList<ViewHolder> additions = new ArrayList<>(); additions.addAll(mPendingAdditions); mAdditionsList.add(additions); mPendingAdditions.clear(); Runnable adder = new Runnable() { public void run() { for (ViewHolder holder : additions) { animateAddImpl(holder); } additions.clear(); mAdditionsList.remove(additions); } }; if (removalsPending || movesPending || changesPending) { long removeDuration = removalsPending ? getRemoveDuration() : 0; long moveDuration = movesPending ? getMoveDuration() : 0; long changeDuration = changesPending ? getChangeDuration() : 0; long totalDelay = removeDuration + Math.max(moveDuration, changeDuration); View view = additions.get(0).itemView; ViewCompat.postOnAnimationDelayed(view, adder, totalDelay); } else { adder.run(); } } }
From source file:com.mikepenz.itemanimators.BaseItemAnimator.java
@Override public void runPendingAnimations() { boolean removalsPending = !mPendingRemovals.isEmpty(); boolean movesPending = !mPendingMoves.isEmpty(); boolean changesPending = !mPendingChanges.isEmpty(); boolean additionsPending = !mPendingAdditions.isEmpty(); if (!removalsPending && !movesPending && !additionsPending && !changesPending) { // nothing to animate return;/*from ww w .j av a2s. c om*/ } // First, remove stuff for (ViewHolder holder : mPendingRemovals) { animateRemoveImpl(holder); } mPendingRemovals.clear(); // Next, move stuff if (movesPending) { final ArrayList<MoveInfo> moves = new ArrayList<>(); moves.addAll(mPendingMoves); mMovesList.add(moves); mPendingMoves.clear(); Runnable mover = new Runnable() { @Override public void run() { for (MoveInfo moveInfo : moves) { animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY); } moves.clear(); mMovesList.remove(moves); } }; if (removalsPending) { View view = moves.get(0).holder.itemView; ViewCompat.postOnAnimationDelayed(view, mover, 0); } else { mover.run(); } } // Next, change stuff, to run in parallel with move animations if (changesPending) { final ArrayList<ChangeInfo> changes = new ArrayList<>(); changes.addAll(mPendingChanges); mChangesList.add(changes); mPendingChanges.clear(); Runnable changer = new Runnable() { @Override public void run() { for (ChangeInfo change : changes) { animateChangeImpl(change); } changes.clear(); mChangesList.remove(changes); } }; if (removalsPending) { ViewHolder holder = changes.get(0).oldHolder; long moveDuration = movesPending ? getMoveDuration() : 0; ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDelay(getRemoveDuration(), moveDuration, getChangeDuration())); } else { changer.run(); } } // Next, add stuff if (additionsPending) { final ArrayList<ViewHolder> additions = new ArrayList<>(); additions.addAll(mPendingAdditions); mAdditionsList.add(additions); mPendingAdditions.clear(); Runnable adder = new Runnable() { public void run() { for (ViewHolder holder : additions) { animateAddImpl(holder); } additions.clear(); mAdditionsList.remove(additions); } }; if (removalsPending || movesPending || changesPending) { long removeDuration = removalsPending ? getRemoveDuration() : 0; long moveDuration = movesPending ? getMoveDuration() : 0; long changeDuration = changesPending ? getChangeDuration() : 0; View view = additions.get(0).itemView; ViewCompat.postOnAnimationDelayed(view, adder, getAddDelay(removeDuration, moveDuration, changeDuration)); } else { adder.run(); } } }
From source file:FastArrayList.java
/** * Remove all of the elements from this list. The list will be empty * after this call returns./*from w w w .j a v a 2 s.com*/ * * @exception UnsupportedOperationException if <code>clear()</code> * is not supported by this list */ public void clear() { if (fast) { synchronized (this) { ArrayList temp = (ArrayList) list.clone(); temp.clear(); list = temp; } } else { synchronized (list) { list.clear(); } } }
From source file:com.freeme.filemanager.view.FileViewFragment.java
@Override public boolean onRefreshFileList(String path, FileSortHelper sort) { if (optionMenu != null) { mFileViewInteractionHub.onPrepareOptionsMenu(optionMenu); }/*from w w w . j a va 2 s . c o m*/ //*/ Added by tyd wulinaghuan 2013-12-09 for: fix NullPointerException bug if (TextUtils.isEmpty(path)) { return false; } //*/ final File file = new File(path); if (!file.exists() || !file.isDirectory()) { return false; } final int pos = computeScrollPosition(path); final ArrayList<FileInfo> fileList = mFileNameList; fileList.clear(); //modify by tyd mingjun 20150526 for refresh slowly if (isFirst) { isFirst = false; handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 0 && fileList.isEmpty()) { if (isLayout == 0 && loadDialog != null) { if (mTagPath != null) { if (!mTagPath.equals(file.getAbsolutePath())) { loadDialog.show(); } } else { Intent intent = new Intent(); intent.setClassName(BuildConfig.APPLICATION_ID, "FileExplorerTabActivity"); if (mActivity.getPackageManager().resolveActivity(intent, 0) != null) { loadDialog.show(); } } } } }; }; new Thread(new ThreadShow()).start(); LoadlistDataTask listData = new LoadlistDataTask(file, fileList, sort, pos); listData.execute(); } else { File[] listFiles = file.listFiles(mFileCagetoryHelper.getFilter()); if (listFiles == null) return true; //modify by tyd liuyong 20140504 for refresh slowly for (File child : listFiles) { // do not show selected file if in move state if (mFileViewInteractionHub.inMoveState() && mFileViewInteractionHub.isFileSelected(child.getPath())) continue; String absolutePath = child.getAbsolutePath(); if (Util.isNormalFile(absolutePath) && Util.shouldShowFile(absolutePath)) { FileInfo lFileInfo = Util.GetFileInfo(child, mFileCagetoryHelper.getFilter(), Settings.instance().getShowDotAndHiddenFiles()); if (lFileInfo != null && !lFileInfo.fileName.equals("droi")) { fileList.add(lFileInfo); } } } mTagPath = file.getAbsolutePath(); sortCurrentList(sort); showEmptyView(fileList.size() == 0); mFileListView.post(new Runnable() { @Override public void run() { mFileListView.setSelection(pos); } }); } // add by xueweili for listview to check on 20160407 //mFileListView.requestFocusFromTouch(); //end return true; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.harvester.FileHarvestController.java
/** * This is for posts automatically sent by the client during the harvest, to check on the status of the harvest and * return updated log data and whether the harvest is complete or still running. An HTTP post is redirected here * when an isHarvestClick parameter is contained in the post data and set to "false". * @param request the HTTP request//from w w w .j av a 2 s .co m * @param response the HTTP response */ private void doCheckHarvestStatusPost(HttpServletRequest request, HttpServletResponse response) { JSONObject json; try { String newline = "\n"; String sessionId = getSessionId(request); SessionInfo sessionInfo = sessionIdToSessionInfo.get(sessionId); //if we have started a thread, check the status and return it to the user if (sessionInfo != null) { String[] unsentLogLines; ArrayList<String> unsentLogLinesList = sessionInfo.unsentLogLines; //don't let the harvester thread add data to the unsent log lines list until we have both copied it and cleared it synchronized (unsentLogLinesList) { unsentLogLines = unsentLogLinesList.toArray(new String[unsentLogLinesList.size()]); unsentLogLinesList.clear(); } String progressSinceLastCheck = ""; for (int i = 0; i < unsentLogLines.length; i++) { progressSinceLastCheck += unsentLogLines[i] + newline; } boolean finished = sessionInfo.isFinished(); boolean abnormalTermination = false; VitroRequest vreq = new VitroRequest(request); ArrayList<String> newlyAddedUrls = new ArrayList<String>(); ArrayList<String> newlyAddedUris = new ArrayList<String>(); if (finished) { newlyAddedUris = sessionInfo.newlyAddedUris; if (newlyAddedUris != null) { for (String uri : newlyAddedUris) { newlyAddedUrls.add(UrlBuilder.getIndividualProfileUrl(uri, vreq)); } } //remove all entries in "sessionIdTo..." mappings for this session ID clearSessionInfo(sessionId); if (sessionInfo.getAbnormalTermination()) abnormalTermination = true; } if (!abnormalTermination) { json = generateJson(false); json.put("progressSinceLastCheck", progressSinceLastCheck); json.put("finished", finished); json.put("newlyAddedUris", newlyAddedUris); json.put("newlyAddedUrls", newlyAddedUrls); } else { json = generateJson(true); log.error("File harvest terminated abnormally."); } } else { //if we have not started a harvest thread, the browser should not have made this request to begin with. Bad browser, very bad browser. json = generateJson(true); log.error("Attempt to check status of a harvest that was never started! (Session ID " + sessionId + ")"); } } catch (Exception e) { json = generateJson(true); log.error(e, e); } try { response.getWriter().write(json.toString()); } catch (IOException e) { log.error(e, e); } }
From source file:com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override//from w w w . j av a 2s . co m public void runPendingAnimations() { boolean removalsPending = !mPendingRemovals.isEmpty(); boolean movesPending = !mPendingMoves.isEmpty(); boolean changesPending = !mPendingChanges.isEmpty(); boolean additionsPending = !mPendingAdditions.isEmpty(); if (!removalsPending && !movesPending && !additionsPending && !changesPending) { // nothing to animate return; } // First, remove stuff for (RecyclerView.ViewHolder holder : mPendingRemovals) { animateRemoveImpl(holder); } mPendingRemovals.clear(); // Next, move stuff if (movesPending) { final ArrayList<MoveInfo> moves = new ArrayList<>(); moves.addAll(mPendingMoves); mMovesList.add(moves); mPendingMoves.clear(); Runnable mover = new Runnable() { @Override public void run() { for (CircularRevealItemAnimator.MoveInfo moveInfo : moves) { animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY); } moves.clear(); mMovesList.remove(moves); } }; if (removalsPending) { View view = moves.get(0).holder.itemView; ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration()); } else { mover.run(); } } // Next, change stuff, to run in parallel with move animations if (changesPending) { final ArrayList<ChangeInfo> changes = new ArrayList<>(); changes.addAll(mPendingChanges); mChangesList.add(changes); mPendingChanges.clear(); Runnable changer = new Runnable() { @Override public void run() { for (CircularRevealItemAnimator.ChangeInfo change : changes) { animateChangeImpl(change); } changes.clear(); mChangesList.remove(changes); } }; if (removalsPending) { RecyclerView.ViewHolder holder = changes.get(0).oldHolder; ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration()); } else { changer.run(); } } // Next, add stuff if (additionsPending) { final ArrayList<RecyclerView.ViewHolder> additions = new ArrayList<>(); additions.addAll(mPendingAdditions); mAdditionsList.add(additions); mPendingAdditions.clear(); Runnable adder = new Runnable() { @Override public void run() { for (RecyclerView.ViewHolder holder : additions) { animateAddImpl(holder); } additions.clear(); mAdditionsList.remove(additions); } }; if (removalsPending || movesPending || changesPending) { long removeDuration = removalsPending ? getRemoveDuration() : 0; long moveDuration = movesPending ? getMoveDuration() : 0; long changeDuration = changesPending ? getChangeDuration() : 0; long totalDelay = removeDuration + Math.max(moveDuration, changeDuration); View view = additions.get(0).itemView; ViewCompat.postOnAnimationDelayed(view, adder, totalDelay); } else { adder.run(); } } }
From source file:FormatStorage.BlockIndex.java
public IndexInfo[] getIndexInfoByKey(int value) throws Exception { int size = keyIndexInfos.size(); int lineSize = lineIndexInfos.size(); if (size != lineSize) { throw new SEException.InnerException("key indexInfo size != line indexInfo size"); }//from w w w.j a v a 2 s .co m ArrayList<IndexInfo> info = new ArrayList<IndexInfo>(10); for (int i = 0; i < size; i++) { IndexInfo indexInfo = keyIndexInfos.get(i); if (value >= indexInfo.beginKey && value <= indexInfo.endKey) { IndexInfo lineInfo = lineIndexInfos.get(i); IndexInfo tmpInfo = new IndexInfo(); tmpInfo.beginKey = indexInfo.beginKey; tmpInfo.endKey = indexInfo.endKey; tmpInfo.beginLine = lineInfo.beginLine; tmpInfo.endLine = lineInfo.endLine; tmpInfo.offset = lineInfo.offset; tmpInfo.len = lineInfo.len; tmpInfo.idx = lineInfo.idx; info.add(tmpInfo); } } size = info.size(); if (size == 0) { return null; } IndexInfo[] result = new IndexInfo[size]; for (int i = 0; i < size; i++) { result[i] = info.get(i); } info.clear(); info = null; return result; }
From source file:com.flexible.flexibleadapter.common.FlexibleItemAnimator.java
private void runMoveAnimation(boolean removalsPending, boolean movesPending) { if (movesPending) { final ArrayList<MoveInfo> moves = new ArrayList<>(); moves.addAll(mPendingMoves);// w ww.ja v a 2 s . c o m mMovesList.add(moves); mPendingMoves.clear(); Runnable mover = new Runnable() { @Override public void run() { for (MoveInfo moveInfo : moves) { animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY); } moves.clear(); mMovesList.remove(moves); } }; if (removalsPending) { View view = moves.get(0).holder.itemView; ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration()); } else { mover.run(); } } }
From source file:mp.teardrop.SongTimeline.java
int addCloudSongs(ArrayList<CloudSongMetadata> cloudSongs, int mode) { ArrayList<Song> timeline = mSongs; synchronized (this) { saveActiveSongs();//from w w w . ja v a 2 s. c o m switch (mode) { case MODE_ENQUEUE: case MODE_ENQUEUE_POS_FIRST: case MODE_ENQUEUE_ID_FIRST: break; case MODE_PLAY_NEXT: timeline.subList(mCurrentPos + 1, timeline.size()).clear(); break; case MODE_PLAY: case MODE_PLAY_POS_FIRST: case MODE_PLAY_ID_FIRST: timeline.clear(); mCurrentPos = 0; break; default: throw new IllegalArgumentException("Invalid mode: " + mode); } /* int start = timeline.size(); Song jumpSong = null; */ for (CloudSongMetadata cloudSong : cloudSongs) { Song song = new Song(true, cloudSong.path, cloudSong.title, cloudSong.album, cloudSong.artist, 1); song.dropboxLinkCreated = new Date(); //it was created only seconds ago when the // user picked the songs in the library if (cloudSong.rgTrack != 0f) song.rgTrack = cloudSong.rgTrack; if (cloudSong.rgAlbum != 0f) song.rgAlbum = cloudSong.rgAlbum; song.dbPath = cloudSong.dbPath; timeline.add(song); } /* if (mShuffleMode != SHUFFLE_NONE) MediaUtils.shuffle(timeline.subList(start, timeline.size()), mShuffleMode == SHUFFLE_ALBUMS); */ broadcastChangedSongs(); } changed(); return cloudSongs.size(); }