From 8c348fea68a1803dee25cbc2f79d1f23a6ec9f4b Mon Sep 17 00:00:00 2001 From: daneren2005 Date: Thu, 8 Aug 2013 12:17:20 -0700 Subject: Replace my implementation of getNewId with official View.generateViewId() View.generateViewId() is only available in API >= 17, so want to be able to use it everywhere. My implementation can possibly cause conflicts with statically defined IDs in R. --- .../daneren2005/dsub/fragments/SubsonicFragment.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 9e8ec29c..577d40d3 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -72,10 +72,11 @@ import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; public class SubsonicFragment extends SherlockFragment { private static final String TAG = SubsonicFragment.class.getSimpleName(); - private static int internalID = Integer.MAX_VALUE; + private static final AtomicInteger nextGeneratedId = new AtomicInteger(1); private static int TAG_INC = 10; private int tag; @@ -282,8 +283,15 @@ public class SubsonicFragment extends SherlockFragment { } protected int getNewId() { - internalID--; - return internalID; + for (;;) { + final int result = nextGeneratedId.get(); + // aapt-generated IDs have the high byte nonzero; clamp to the range under that. + int newValue = result + 1; + if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. + if (nextGeneratedId.compareAndSet(result, newValue)) { + return result; + } + } } public int getRootId() { return rootView.getId(); -- cgit v1.2.3