Sha256: 15ec3a7ca4a9c8c2e0ff18aaefdcb02ed644a1f8eb2ba01c27f24341572ba4c5

Contents?: true

Size: 1.91 KB

Versions: 25

Compression:

Stored size: 1.91 KB

Contents

#######################################################
#
# ruboto/preference.rb
#
# Basic set up for preferences (activity and widgets).
#
#######################################################

require 'ruboto/activity'

java_import 'android.preference.PreferenceScreen'
java_import 'android.preference.Preference'
java_import 'org.ruboto.RubotoPreferenceActivity'
ruboto_configure_activity(RubotoPreferenceActivity)

RubotoPreferenceActivity.class_eval do
    def preference_screen(params={})
      rv = self.getPreferenceManager.createPreferenceScreen(self)
      parent = params.delete(:parent) || @parent
      rv.configure self, params
      parent.addPreference(rv) if parent

      if block_given?
        old_parent, @parent = @parent, rv
        yield
        @parent = old_parent
      end
      rv
    end
end

Preference.class_eval do
    def configure(context, params = {})
      params.each do |k, v|
        if v.is_a?(Array)
          self.send("set#{k.to_s.gsub(/(^|_)([a-z])/) { $2.upcase }}", *v)
        else
          self.send("set#{k.to_s.gsub(/(^|_)([a-z])/) { $2.upcase }}", v)
        end
      end
    end
end

#
# RubotoPreferenceActivity Preference Generation
#

def ruboto_import_preferences(*preferences)
  preferences.each { |i| ruboto_import_preference i }
end

def ruboto_import_preference(class_name, package_name='android.preference')
  klass = java_import("#{package_name}.#{class_name}") || eval("Java::#{package_name}.#{class_name}")
  return unless klass

  RubotoPreferenceActivity.class_eval "
     def #{(class_name.to_s.gsub(/([A-Z])/) { '_' + $1.downcase })[1..-1]}(params={})
        rv = #{class_name}.new self
        parent = params.delete(:parent) || @parent
        rv.configure self, params
        parent.addPreference(rv) if parent
      
        if block_given?
          old_parent, @parent = @parent, rv
          yield
          @parent = old_parent
        end
        rv
     end
   "
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ruboto-1.6.1 assets/src/ruboto/preference.rb
ruboto-1.6.0 assets/src/ruboto/preference.rb
ruboto-1.5.0 assets/src/ruboto/preference.rb
ruboto-1.4.1 assets/src/ruboto/preference.rb
ruboto-1.4.0 assets/src/ruboto/preference.rb
ruboto-1.3.1 assets/src/ruboto/preference.rb
ruboto-1.3.0 assets/src/ruboto/preference.rb
ruboto-1.2.0 assets/src/ruboto/preference.rb
ruboto-1.1.2 assets/src/ruboto/preference.rb
ruboto-1.1.1 assets/src/ruboto/preference.rb
ruboto-1.1.0 assets/src/ruboto/preference.rb
ruboto-1.0.3 assets/src/ruboto/preference.rb
ruboto-1.0.2 assets/src/ruboto/preference.rb
ruboto-1.0.1 assets/src/ruboto/preference.rb
ruboto-1.0.0 assets/src/ruboto/preference.rb
ruboto-0.16.0 assets/src/ruboto/preference.rb
ruboto-0.15.0 assets/src/ruboto/preference.rb
ruboto-0.14.0 assets/src/ruboto/preference.rb
ruboto-0.13.0 assets/src/ruboto/preference.rb
ruboto-0.12.0 assets/src/ruboto/preference.rb