class AMQStylesheetElement
Attributes
params[RW]
radius[RW]
view[RW]
Public Class Methods
new(view, layout_params)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 81 def initialize(view, layout_params) self.view = view self.params = layout_params.new(LAYOUT_SIZE_OPTIONS[:mp], LAYOUT_SIZE_OPTIONS[:mp]) self end
Public Instance Methods
alpha=(value)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 291 def alpha=(value) self.view.get.alpha = value end
background_color=(color)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 247 def background_color=(color) self.view.get.backgroundColor = AMQColor.parse_color(color.to_s) end
background_image=(image_name)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 251 def background_image=(image_name) context = self.view.get.getContext resource_id = context.getResources.getIdentifier(image_name, "drawable", context.getPackageName) self.view.get.backgroundResource = resource_id end
border_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_motion_query/stylesheet.rb, line 238 def border_color=(color) shape = Android::Graphics::Drawable::ShapeDrawable.new shape.shape = Android::Graphics::Drawable::Shapes::RectShape.new shape.paint.color = AMQColor.parse_color(color.to_s) shape.paint.strokeWidth = 1 shape.paint.style = Android::Graphics::Paint::Style::STROKE self.view.get.background = shape end
click=(method_name)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 203 def click=(method_name) self.view.get.onClickListener = AMQClickListener.new(self.view.activity, method_name) end
extra=(something)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 199 def extra=(something) self.view.extra = something end
get_margins()
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 183 def get_margins lp = self.params [lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin] end
get_padding()
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 158 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_motion_query/stylesheet.rb, line 304 def gravity=(alignment) if GRAVITY_OPTIONS.keys.include? alignment self.view.get.gravity = GRAVITY_OPTIONS[alignment] else puts "The value #{alignment} is not a supported gravity value. Defaulting to center." self.gravity = :center end end
height=(h)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 105 def height=(h) if h == :mp || h == :wc self.params.height = LAYOUT_SIZE_OPTIONS[h] else self.params.height = h end end
hint=(t)
click to toggle source
def font=(font)
if TYPE_FACE_OPTIONS.keys.include? font self.view.get.typeFace = TYPE_FACE_OPTIONS[font] else raise "The value #{font} is not a supported font value. Use one of #{TYPE_FACE_OPTIONS.keys}" end
end
# File lib/android_motion_query/stylesheet.rb, line 287 def hint=(t) self.view.get.hint = t end
id=(number)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 87 def id=(number) self.view.get.id = number end
image=(image_name)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 257 def 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
input_type=(text_type)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 295 def input_type=(text_type) if INPUT_TYPES.keys.include? text_type self.view.get.inputType = INPUT_TYPES[text_type] else puts "The value #{text_type} is not a supported input_type value. Defaulting to normal text." self.input_type = :normal end end
layout_gravity=(alignment)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 313 def layout_gravity=(alignment) if GRAVITY_OPTIONS.keys.include? alignment self.params.gravity = GRAVITY_OPTIONS[alignment] else puts "The value #{alignment} is not a supported gravity value. Defaulting to center." self.params.gravity = :center end end
margin=(number)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 188 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_motion_query/stylesheet.rb, line 178 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_motion_query/stylesheet.rb, line 163 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_motion_query/stylesheet.rb, line 168 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_motion_query/stylesheet.rb, line 173 def margin_top=(number) left, top, right, bottom = get_margins self.margin = [left, number, right, bottom] end
number_of_columns=(columns)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 322 def number_of_columns=(columns) self.view.get.numColumns = columns end
orientation=(o)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 113 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_motion_query/stylesheet.rb, line 147 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_motion_query/stylesheet.rb, line 142 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_motion_query/stylesheet.rb, line 127 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_motion_query/stylesheet.rb, line 132 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_motion_query/stylesheet.rb, line 137 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_motion_query/stylesheet.rb, line 263 def scale_type=(option) self.view.get.scaleType = SCALE_TYPES[option] end
stretch_mode=(mode)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 326 def stretch_mode=(mode) self.view.get.stretchMode = mode end
text=(t)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 92 def text=(t) self.view.get.text = t self end
text_alignment=(alignment)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 267 def text_alignment=(alignment) self.gravity = alignment end
text_color=(color)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 271 def text_color=(color) self.view.get.textColor = AMQColor.parse_color(color.to_s) end
text_size=(size)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 275 def text_size=(size) self.view.get.textSize = size end
vertical_spacing=(space)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 330 def vertical_spacing=(space) self.view.get.verticalSpacing = space end
weight=(number)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 123 def weight=(number) self.params.weight = number end
weight_sum=(number)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 119 def weight_sum=(number) self.view.get.weightSum = number end
width=(w)
click to toggle source
# File lib/android_motion_query/stylesheet.rb, line 97 def width=(w) if w == :mp || w == :wc self.params.width = LAYOUT_SIZE_OPTIONS[w] else self.params.width = w end end