<commit_before>require 'ruboto/base'
require 'ruboto/package'

#######################################################
#
# ruboto/activity.rb
#
# Basic activity set up.
#
#######################################################

#
# Context
#
module Ruboto
  module Context
    def start_ruboto_dialog(remote_variable, theme=Java::android.R.style::Theme_Dialog, &block)
      java_import 'org.ruboto.RubotoDialog'
      start_ruboto_activity(remote_variable, RubotoDialog, theme, &block)
    end

    def start_ruboto_activity(class_name = nil, options = nil, &block)
      if options.nil?
        if class_name.is_a?(Hash)
          options = class_name
          class_name = nil
        else
          options = {}
        end
      end

      # FIXME(uwe):  Deprecated.  Remove june 2014.
      if options[:class_name]
        puts "\nDEPRECATON: The ':class_name' option is deprecated.  Put the class name in the first argument instead."
      end

      java_class = options.delete(:java_class) || RubotoActivity
      theme = options.delete(:theme)

      # FIXME(uwe):  Remove the use of the :class_name option in june 2014
      class_name_option = options.delete(:class_name)
      class_name ||= class_name_option
      # EMXIF

      script_name = options.delete(:script)
      raise "Unknown options: #{options}" unless options.empty?

      if class_name.nil? && block_given?
        class_name =
            "#{java_class.name.split('::').last}_#{source_descriptor(block)[0].split('/').last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}"
      end

      if Object.const_defined?(class_name)
        Object.const_get(class_name).class_eval(&block) if block_given?
      else
        Object.const_set(class_name, Class.new(&block))
      end
      i = android.content.Intent.new
      i.setClass self, java_class.java_class
      i.putExtra(Ruboto::THEME_KEY, theme) if theme
      i.putExtra(Ruboto::CLASS_NAME_KEY, class_name) if class_name
      i.putExtra(Ruboto::SCRIPT_NAME_KEY, script_name) if script_name
      startActivity i
      self
    end

    private

    def source_descriptor(proc)
      if md = /^#<Proc:0x[0-9A-Fa-f]+@(.+):(\d+)(?: \(lambda\))?>$/.match(proc.inspect)
        filename, line = md.captures
        return filename, line.to_i
      end
    end

  end

end
<commit_msg>* Allow Symbols and Classes to be passed as class names to start_ruboto_activity.<commit_after>require 'ruboto/base'
require 'ruboto/package'

#######################################################
#
# ruboto/activity.rb
#
# Basic activity set up.
#
#######################################################

#
# Context
#
module Ruboto
  module Context
    def start_ruboto_dialog(remote_variable, theme=Java::android.R.style::Theme_Dialog, &block)
      java_import 'org.ruboto.RubotoDialog'
      start_ruboto_activity(remote_variable, RubotoDialog, theme, &block)
    end

    def start_ruboto_activity(class_name = nil, options = nil, &block)
      if options.nil?
        if class_name.is_a?(Hash)
          options = class_name
          class_name = nil
        else
          options = {}
        end
      end

      # FIXME(uwe):  Deprecated.  Remove june 2014.
      if options[:class_name]
        puts "\nDEPRECATON: The ':class_name' option is deprecated.  Put the class name in the first argument instead."
      end

      java_class = options.delete(:java_class) || RubotoActivity
      theme = options.delete(:theme)

      # FIXME(uwe):  Remove the use of the :class_name option in june 2014
      class_name_option = options.delete(:class_name)
      class_name ||= class_name_option
      # EMXIF

      script_name = options.delete(:script)
      raise "Unknown options: #{options}" unless options.empty?

      if class_name.nil? && block_given?
        class_name =
            "#{java_class.name.split('::').last}_#{source_descriptor(block)[0].split('/').last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}"
      end

      class_name = class_name.to_s

      if Object.const_defined?(class_name)
        Object.const_get(class_name).class_eval(&block) if block_given?
      else
        Object.const_set(class_name, Class.new(&block))
      end
      i = android.content.Intent.new
      i.setClass self, java_class.java_class
      i.putExtra(Ruboto::THEME_KEY, theme) if theme
      i.putExtra(Ruboto::CLASS_NAME_KEY, class_name) if class_name
      i.putExtra(Ruboto::SCRIPT_NAME_KEY, script_name) if script_name
      startActivity i
      self
    end

    private

    def source_descriptor(proc)
      if md = /^#<Proc:0x[0-9A-Fa-f]+@(.+):(\d+)(?: \(lambda\))?>$/.match(proc.inspect)
        filename, line = md.captures
        return filename, line.to_i
      end
    end

  end

end

{'fraction_non_alphanumeric': 0.1572512647554806, 'fraction_numerical': 0.0054806070826306915, 'mean_word_length': 3.0314358538657604, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5498764', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1473, 'n_words': 314}