class Device::VirtualKeyboard

Attributes

attributes[RW]
text[RW]
type[RW]

Public Class Methods

change_keyboard() click to toggle source
# File lib/device/virtual_keyboard.rb, line 225
def self.change_keyboard
  if type.nil?
    self.type = :keyboard_capital
    Device::Display.print_bitmap('./shared/keyboard_capital.bmp')
  else
    Device::Display.print_bitmap("./shared/#{type}.bmp")
  end
end
parse(line_x, line_y, params) click to toggle source
# File lib/device/virtual_keyboard.rb, line 195
def self.parse(line_x, line_y, params)
  key = attributes[type].find do |value|
    value[:x].include?(line_x) && value[:y].include?(line_y)
  end
  return if key.nil?

  Device::Audio.beep(7, 60)
  show_text(key, params)

  key[:char]
end
show_text(key, params) click to toggle source
# File lib/device/virtual_keyboard.rb, line 207
def self.show_text(key, params)
  case key[:char]
  when :keyboard_uppercase, :keyboard_symbol_number, :keyboard_symbol_number_2, :keyboard_capital
    self.type = key[:char]
    change_keyboard
  when :erase
    self.text += '' if text.nil?
    self.text = text[0..-2]
  when :space
    self.text += ' '
  else
    if self.text && self.text.size < 20
      self.text << key[:char] unless key[:char] == :enter
    end
  end
  Device::Display.print_line("#{self.text}", params[:line], params[:column])
end
text_not_ready?(key) click to toggle source
# File lib/device/virtual_keyboard.rb, line 191
def self.text_not_ready?(key)
  key != :enter && key != Device::IO::ENTER && key != Device::IO::CANCEL
end
type_text(params = {}) click to toggle source
# File lib/device/virtual_keyboard.rb, line 158
def self.type_text(params = {})
  phisical_keys = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', "\017"]
  change_keyboard
  Device::Display.print_line("#{self.text}", params[:line], params[:column])
  if params[:timeout_enabled]
    time = Time.now + (params[:timeout] || Device::IO.timeout) / 1000
  end

  key = nil
  while text_not_ready?(key)
    line_x, line_y = getxy_stream(100)

    if line_x && line_y
      touch_clear
      key = parse(line_x, line_y, params)
    else
      if params[:timeout_enabled]
        break(Device::IO::KEY_TIMEOUT) if Time.now > time
      end
      key = getc(100)
      if phisical_keys.include?(key)
        if key == Device::IO::BACK
          show_text({char: :erase}, params)
        else
          show_text({char: key}, params)
        end
      end
    end
  end

  [key, self.text]
end
wifi_password() click to toggle source
# File lib/device/virtual_keyboard.rb, line 234
def self.wifi_password
  self.text = if Device::Setting.wifi_password == 'false'
                ''
              else
                Device::Setting.wifi_password
              end
end