Class: AndroidMotionQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/android_motion_query/amq.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(activity) ⇒ AndroidMotionQuery

Returns a new instance of AndroidMotionQuery.



5
6
7
8
# File 'lib/android_motion_query/amq.rb', line 5

def initialize(activity)
  self.activity = activity
  self
end

Instance Attribute Details

#activityObject

Returns the value of attribute activity.



2
3
4
# File 'lib/android_motion_query/amq.rb', line 2

def activity
  @activity
end

#rootObject

Returns the value of attribute root.



2
3
4
# File 'lib/android_motion_query/amq.rb', line 2

def root
  @root
end

#stylesheetObject

Returns the value of attribute stylesheet.



3
4
5
# File 'lib/android_motion_query/amq.rb', line 3

def stylesheet
  @stylesheet
end

#view_idsObject

Returns the value of attribute view_ids.



2
3
4
# File 'lib/android_motion_query/amq.rb', line 2

def view_ids
  @view_ids
end

Instance Method Details

#add(view_sym, style, &block) ⇒ Object



33
34
35
# File 'lib/android_motion_query/amq.rb', line 33

def add(view_sym, style, &block)
  self.send(view_sym, style, &block)
end

#create_android_query_view(view, style_method, layout_params, options = {}, &block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/android_motion_query/amq.rb', line 14

def create_android_query_view(view, style_method, layout_params, options = {}, &block)
  self.root = AMQView.new(view, self.activity, self.stylesheet, style_method, layout_params, options)
  self.stylesheet.apply_style_for(self.root, style_method, layout_params)
  block.call(self.root) if block_given?
  self.activity.setContentView(self.root.get)
  self
end

#create_standalone_amq_view(view, style_method, layout_params, options = {}, &block) ⇒ Object



22
23
24
25
26
27
# File 'lib/android_motion_query/amq.rb', line 22

def create_standalone_amq_view(view, style_method, layout_params, options = {}, &block)
  amq_view = AMQView.new(view, self.activity, self.stylesheet, style_method, layout_params, options)
  self.stylesheet.apply_style_for(amq_view, style_method, layout_params)
  block.call(amq_view) if block_given?
  amq_view
end

#find(id) ⇒ Object



29
30
31
# File 'lib/android_motion_query/amq.rb', line 29

def find(id)
  self.root.get.findViewById(id).tag
end

#frame_layout(style_method, &block) ⇒ Object



49
50
51
52
53
# File 'lib/android_motion_query/amq.rb', line 49

def frame_layout(style_method, &block)
  view = Android::Widget::FrameLayout.new(self.activity)
  layout_params = Android::Widget::FrameLayout::LayoutParams
  create_android_query_view(view, style_method, layout_params, {}, &block)
end

#linear_layout(style_method, &block) ⇒ Object



37
38
39
40
41
# File 'lib/android_motion_query/amq.rb', line 37

def linear_layout(style_method, &block)
  view = Android::Widget::LinearLayout.new(self.activity)
  layout_params = Android::Widget::LinearLayout::LayoutParams
  create_android_query_view(view, style_method, layout_params, {}, &block)
end

#relative_layout(style_method, &block) ⇒ Object



43
44
45
46
47
# File 'lib/android_motion_query/amq.rb', line 43

def relative_layout(style_method, &block)
  view = Android::Widget::RelativeLayout.new(self.activity)
  layout_params = Android::Widget::RelativeLayout::LayoutParams
  create_android_query_view(view, style_method, layout_params, {}, &block)
end

#text_view(style_method, &block) ⇒ Object



55
56
57
58
59
# File 'lib/android_motion_query/amq.rb', line 55

def text_view(style_method, &block)
  view = Android::Widget::TextView.new(self.activity)
  layout_params = Android::Widget::LinearLayout::LayoutParams
  create_standalone_amq_view(view, style_method, layout_params, {}, &block)
end

#toast(text, options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/android_motion_query/amq.rb', line 61

def toast(text, options = {})
  options = {
    gravity: :bottom,
    length: :short
  }.merge(options)

  gravity_options = {
    top: Android::View::Gravity::TOP,
    left: Android::View::Gravity::LEFT,
    right: Android::View::Gravity::RIGHT,
    bottom: Android::View::Gravity::BOTTOM,
    center: Android::View::Gravity::CENTER,
    bottom_right: Android::View::Gravity::BOTTOM | Android::View::Gravity::RIGHT,
    bottom_left: Android::View::Gravity::BOTTOM | Android::View::Gravity::LEFT,
    center_right: Android::View::Gravity::CENTER | Android::View::Gravity::RIGHT,
    center_left: Android::View::Gravity::CENTER | Android::View::Gravity::LEFT,
    top_right: Android::View::Gravity::TOP | Android::View::Gravity::RIGHT,
    top_left: Android::View::Gravity::TOP | Android::View::Gravity::LEFT,
  }

  length_options = {
    short: Android::Widget::Toast::LENGTH_SHORT,
    long: Android::Widget::Toast::LENGTH_LONG,
  }

  the_toast = Android::Widget::Toast.makeText(self.activity, text, length_options[options[:length]])
  the_toast.setGravity(gravity_options[options[:gravity]], 0, 0)
  the_toast.show    
end