aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2013-08-08 12:17:20 -0700
committerdaneren2005 <daneren2005@gmail.com>2013-08-08 12:17:20 -0700
commit8c348fea68a1803dee25cbc2f79d1f23a6ec9f4b (patch)
tree28b690668121538b653e7ecb1cb29610e75c3f09 /src/github
parent120f939fadc58792d8f37d1cce022fcf361d9db0 (diff)
downloaddsub-8c348fea68a1803dee25cbc2f79d1f23a6ec9f4b.tar.gz
dsub-8c348fea68a1803dee25cbc2f79d1f23a6ec9f4b.tar.bz2
dsub-8c348fea68a1803dee25cbc2f79d1f23a6ec9f4b.zip
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.
Diffstat (limited to 'src/github')
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java14
1 files changed, 11 insertions, 3 deletions
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();