Module: DroidAdbs::WM

Defined in:
lib/droid_adbs/commons/wm.rb

Class Method Summary collapse

Class Method Details

.get_densityInteger

Returns density. If this method fail to get density, then return 0.

Returns:

  • (Integer)

    density. If this method fail to get density, then return 0.



5
6
7
8
9
# File 'lib/droid_adbs/commons/wm.rb', line 5

def get_density
  result = `#{::DroidAdbs.shell} wm density`.strip
  return 0 unless result.match(/\APhysical density:.*/)
  result.split(/\s/).last.to_i
end

.reset_densityString

Returns message from adb commands.

Returns:

  • (String)

    message from adb commands



12
13
14
# File 'lib/droid_adbs/commons/wm.rb', line 12

def reset_density
  `#{::DroidAdbs.shell} wm density reset`.strip
end

.set_density(base_density:, scale: :normal) ⇒ String

Don’t forget to call ‘reset_density` after change density via adb

Parameters:

  • base_density (Integer)

    density with get_density

  • scale (hash) (defaults to: :normal)

    :small, :normal, :large, :huge. default is :normal

Returns:

  • (String)

    message from adb commands



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/droid_adbs/commons/wm.rb', line 20

def set_density(base_density:, scale: :normal)
  density = case scale
              when :small
                (base_density * 0.85).to_i
              when :large
                (base_density * 1.15).to_i
              when :huge
                (base_density * 1.3).to_i
              else # include :normal
                base_density
            end
  `#{::DroidAdbs.shell} wm density #{density}`.strip
end