Class: Potion::ViewIdGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/project/potion.rb

Overview

Android’s generateViewId method was implemented in API leve 17 - for older devices we need to roll our own solution.

This is apparently Android’s implementation from View.java, according to: stackoverflow.com/questions/1714297/android-view-setidint-id-programmatically-how-to-avoid-id-conflicts

Class Method Summary collapse

Class Method Details

.generateObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/project/potion.rb', line 65

def self.generate
  while true do
    result = @current_id.get
    # aapt-generated IDs have the high byte nonzero; clamp to the range under that.
    new_value = result + 1
    if new_value > 0x00FFFFFF
      new_value = 1
    end
    if @current_id.compareAndSet(result, new_value)
      return result
    end
  end
end