class AndroidMotionQuery::StylesheetElement
Constants
- LAYOUT_SIZE_OPTIONS
- ORIENTATION_OPTIONS
Attributes
params[RW]
radius[RW]
view[RW]
Public Class Methods
new(view, layout_params)
click to toggle source
# File lib/android_query/views.rb, line 95 def initialize(view, layout_params) self.view = view self.params = layout_params.new(LAYOUT_SIZE_OPTIONS[:mp], LAYOUT_SIZE_OPTIONS[:wc]) self end
Public Instance Methods
background_color=(color)
click to toggle source
TODO find a solution for rounded corners (with or without images) def corner_radius=(radius)
self.radius ||= radius drawable = self.view.get.getDrawable if drawable self.draw_image_with_radius(drawable, self.radius) else shape = Android::Graphics::GradientDrawable.new shape.cornerRadius = self.radius self.view.get.background = shape end
end TODO find a solution for rounded corners (with or without images) def draw_image_with_radius(image, radius)
self.radius ||= radius width = image.getWidth height = image.getHeight result = Android::Graphics::Bitmap.createBitmap(width, height, Android::Graphics::Bitmap::Config::ARGB_8888) canvas = Android::Graphics::Canvas.new(result) canvas.drawARGB(0, 0, 0, 0) paint = Android::Graphics::Paint.new paint.antiAlias = true paint.color = AQColor.parse_color('#000000') rect = Android::Graphics::Rect.new(0, 0, width, height) rect_f = Android::Graphics::RectF.new(rect) canvas.drawRoundRect(rect_f, self.radius, self.radius, paint) paint.xfermode = Android::Graphics::PorterDuffXfermode.new(Android::Graphics::PorterDuff::Mode::SRC_IN) canvas.drawBitmap(raw, rect, rect, paint) result
end
# File lib/android_query/views.rb, line 251 def background_color=(color) self.view.get.backgroundColor = AQColor.parse_color(color.to_s) end
background_image=(image_name)
click to toggle source
# File lib/android_query/views.rb, line 255 def background_image=(image_name) context = self.view.get.getContext resource_id = context.getResources.getIdentifier(image_name, "drawable", context.getPackageName) self.view.get.setImageResource(resource_id) end
click=(method_name)
click to toggle source
# File lib/android_query/views.rb, line 216 def click=(method_name) self.view.get.onClickListener = AQClickListener.new(self.view.activity, method_name) end
extra=(something)
click to toggle source
# File lib/android_query/views.rb, line 212 def extra=(something) self.view.extra = something end
get_margins()
click to toggle source
# File lib/android_query/views.rb, line 196 def get_margins lp = self.params [lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin] end
get_padding()
click to toggle source
# File lib/android_query/views.rb, line 171 def get_padding v = self.view.get [v.getPaddingLeft, v.getPaddingTop, v.getPaddingRight, v.getPaddingBottom] end
gravity=(alignment)
click to toggle source
# File lib/android_query/views.rb, line 283 def gravity=(alignment) 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, } self.view.get.gravity = gravity_options[alignment] end
height=(h)
click to toggle source
# File lib/android_query/views.rb, line 118 def height=(h) if h == :mp || h == :wc self.params.height = LAYOUT_SIZE_OPTIONS[h] else self.params.height = h end end
id=(number)
click to toggle source
# File lib/android_query/views.rb, line 101 def id=(number) self.view.get.id = number end
margin=(number)
click to toggle source
# File lib/android_query/views.rb, line 201 def margin=(number) if number.class == Array && number.count == 4 left, top, right, bottom = number self.params.setMargins(left, top, right, bottom) elsif number.class == Fixnum self.params.setMargins(number, number, number, number) else raise "Invalid value (#{number}) set as margin for #{self.view.get}" end end
margin_bottom=(number)
click to toggle source
# File lib/android_query/views.rb, line 191 def margin_bottom=(number) left, top, right, bottom = get_margins self.margin = [left, top, right, number] end
margin_left=(number)
click to toggle source
# File lib/android_query/views.rb, line 176 def margin_left=(number) left, top, right, bottom = get_margins self.margin = [number, top, right, bottom] end
margin_right=(number)
click to toggle source
# File lib/android_query/views.rb, line 181 def margin_right=(number) left, top, right, bottom = get_margins self.margin = [left, top, number, bottom] end
margin_top=(number)
click to toggle source
# File lib/android_query/views.rb, line 186 def margin_top=(number) left, top, right, bottom = get_margins self.margin = [left, number, right, bottom] end
orientation=(o)
click to toggle source
# File lib/android_query/views.rb, line 126 def orientation=(o) if o == :vertical || o == :horizontal self.view.get.orientation = ORIENTATION_OPTIONS[o] end end
padding=(number)
click to toggle source
# File lib/android_query/views.rb, line 160 def padding=(number) if number.class == Array && number.count == 4 left, top, right, bottom = number self.view.get.setPadding(left, top, right, bottom) elsif number.class == Fixnum self.view.get.setPadding(number, number, number, number) else raise "Invalid value (#{number}) set as padding for #{self.view.get}" end end
padding_bottom=(number)
click to toggle source
# File lib/android_query/views.rb, line 155 def padding_bottom=(number) left, top, right, bottom = get_padding self.padding = [left, top, right, number] end
padding_left=(number)
click to toggle source
# File lib/android_query/views.rb, line 140 def padding_left=(number) left, top, right, bottom = get_padding self.padding = [number, top, right, bottom] end
padding_right=(number)
click to toggle source
# File lib/android_query/views.rb, line 145 def padding_right=(number) left, top, right, bottom = get_padding self.padding = [left, top, number, bottom] end
padding_top=(number)
click to toggle source
# File lib/android_query/views.rb, line 150 def padding_top=(number) left, top, right, bottom = get_padding self.padding = [left, number, right, bottom] end
scale_type=(option)
click to toggle source
# File lib/android_query/views.rb, line 261 def scale_type=(option) scale_types = { center: Android::Widget::ImageView::ScaleType::CENTER, center_crop: Android::Widget::ImageView::ScaleType::CENTER_CROP, center_inside: Android::Widget::ImageView::ScaleType::CENTER_INSIDE, fit_center: Android::Widget::ImageView::ScaleType::FIT_CENTER, fit_end: Android::Widget::ImageView::ScaleType::FIT_END, fit_start: Android::Widget::ImageView::ScaleType::FIT_START, fit_xy: Android::Widget::ImageView::ScaleType::FIT_XY, matrix: Android::Widget::ImageView::ScaleType::MATRIX, } self.view.get.scaleType = scale_types[option] end
text=(t)
click to toggle source
# File lib/android_query/views.rb, line 106 def text=(t) self.view.get.text = t end
text_alignment=(alignment)
click to toggle source
# File lib/android_query/views.rb, line 275 def text_alignment=(alignment) self.gravity = alignment end
text_color=(color)
click to toggle source
# File lib/android_query/views.rb, line 279 def text_color=(color) self.view.get.textColor = AQColor.parse_color(color.to_s) end
weight=(number)
click to toggle source
# File lib/android_query/views.rb, line 136 def weight=(number) self.params.weight = number end
weight_sum=(number)
click to toggle source
# File lib/android_query/views.rb, line 132 def weight_sum=(number) self.view.get.weightSum = number end
width=(w)
click to toggle source
# File lib/android_query/views.rb, line 110 def width=(w) if w == :mp || w == :wc self.params.width = LAYOUT_SIZE_OPTIONS[w] else self.params.width = w end end