diff --git a/android-samples/Conference/app/about_fragment.rb b/android-samples/Conference/app/about_fragment.rb index c16e2275..d2f7c112 100644 --- a/android-samples/Conference/app/about_fragment.rb +++ b/android-samples/Conference/app/about_fragment.rb @@ -3,11 +3,14 @@ class AboutFragment < Android::App::Fragment @view ||= begin layout = Android::Widget::LinearLayout.new(activity) layout.orientation = Android::Widget::LinearLayout::VERTICAL - layout.setPadding(120, 120, 120, 120) + pad = 30 * activity.density + layout.setPadding(pad, pad, pad, pad) layout.backgroundColor = Android::Graphics::Color::WHITE logoView = Android::Widget::ImageView.new(activity) logoView.imageResource = activity.resources.getIdentifier('rmc_logo', 'drawable', activity.packageName) + logoView.adjustViewBounds = true + logoView.maxHeight = 400 * activity.density layout.addView(logoView) titleTextView = Android::Widget::TextView.new(activity) @@ -16,7 +19,7 @@ class AboutFragment < Android::App::Fragment titleTextView.setTypeface(nil, Android::Graphics::Typeface::BOLD) titleTextView.textColor = Android::Graphics::Color::BLACK titleTextView.gravity = Android::View::Gravity::CENTER_HORIZONTAL - titleTextView.setPadding(0, 40, 0, 10) + titleTextView.setPadding(0, 20 * activity.density, 0, 5 * activity.density) layout.addView(titleTextView) texts = [ @@ -31,7 +34,7 @@ class AboutFragment < Android::App::Fragment textView.textSize = 20.0 textView.textColor = Android::Graphics::Color::BLACK textView.gravity = Android::View::Gravity::CENTER_HORIZONTAL - textView.setPadding(0, 30, 0, 0) + textView.setPadding(0, 15 * activity.density, 0, 0) layout.addView(textView) end diff --git a/android-samples/Conference/app/main_activity.rb b/android-samples/Conference/app/main_activity.rb index 897f8350..d145a061 100644 --- a/android-samples/Conference/app/main_activity.rb +++ b/android-samples/Conference/app/main_activity.rb @@ -27,7 +27,7 @@ class MainActivity < Android::App::Activity # Create the drawer layout, which will be the activity's main view. The first subview must be the drawer content view and the second the drawer menu list view. @drawerLayout = Android::Support::V4::Widget::DrawerLayout.new(self) @drawerLayout.addView(@contentLayout, Android::Support::V4::Widget::DrawerLayout::LayoutParams.new(Android::View::ViewGroup::LayoutParams::MATCH_PARENT, Android::View::ViewGroup::LayoutParams::MATCH_PARENT)) - @drawerLayout.addView(@drawerList, Android::Support::V4::Widget::DrawerLayout::LayoutParams.new(dpToPx(240), Android::View::ViewGroup::LayoutParams::MATCH_PARENT, Android::View::Gravity::START)) + @drawerLayout.addView(@drawerList, Android::Support::V4::Widget::DrawerLayout::LayoutParams.new(240 * density, Android::View::ViewGroup::LayoutParams::MATCH_PARENT, Android::View::Gravity::START)) self.contentView = @drawerLayout # Enable the action bar app icon to behave as a drawer toggle action. @@ -71,11 +71,6 @@ class MainActivity < Android::App::Activity selectItem(position) end - # Helper to translate dp into pixels. - def dpToPx(dp) - dp * self.resources.displayMetrics.density - end - def selectItem(pos) # Create the view Fragment object if it does not exist already. @fragments[pos] ||= begin @@ -103,4 +98,8 @@ class MainActivity < Android::App::Activity self.title = MenuTitles[pos] @drawerLayout.closeDrawer(@drawerList) end + + def density + @density ||= resources.displayMetrics.density + end end diff --git a/android-samples/Conference/app/schedule_adapter.rb b/android-samples/Conference/app/schedule_adapter.rb index 59c8008d..1f42283c 100644 --- a/android-samples/Conference/app/schedule_adapter.rb +++ b/android-samples/Conference/app/schedule_adapter.rb @@ -27,22 +27,25 @@ class ScheduleAdapter < Android::Widget::ArrayAdapter titleTextView.gravity = Android::View::Gravity::CENTER_VERTICAL end + rightView = nil + rightViewHeight = -1 if whoTextView - layout1 = Android::Widget::LinearLayout.new(context) - layout1.orientation = Android::Widget::LinearLayout::VERTICAL - layout1.addView(titleTextView) - layout1.addView(whoTextView) + rightView = Android::Widget::LinearLayout.new(context) + rightView.orientation = Android::Widget::LinearLayout::VERTICAL + rightView.addView(titleTextView) + rightView.addView(whoTextView) else - layout1 = titleTextView + rightView = titleTextView + rightViewHeight = 65 * context.density end - whenTextView.setPadding(20, 10, 10, 10) - layout1.setPadding(10, 10, 10, 10) + whenTextView.setPadding(10 * context.density, 10, 10, 10) + rightView.setPadding(0, 10, 10, 10) layout2 = Android::Widget::LinearLayout.new(context) layout2.orientation = Android::Widget::LinearLayout::HORIZONTAL - layout2.addView(whenTextView, 170, -1) - layout2.addView(layout1, -1, 130) + layout2.addView(whenTextView, 85 * context.density, -1) + layout2.addView(rightView, -1, rightViewHeight) layout2 end end diff --git a/android-samples/Conference/app/sponsors_fragment.rb b/android-samples/Conference/app/sponsors_fragment.rb index 721cc779..b9e31e22 100644 --- a/android-samples/Conference/app/sponsors_fragment.rb +++ b/android-samples/Conference/app/sponsors_fragment.rb @@ -6,6 +6,7 @@ class SponsorsFragment < Android::App::Fragment logoView.imageResource = activity.resources.getIdentifier(basename, 'drawable', activity.packageName) logoView.onClickListener = self logoView.tag = url + logoView.adjustViewBounds = true logoView end @@ -14,14 +15,17 @@ class SponsorsFragment < Android::App::Fragment layout.addView(createLogoView.call('pixate', 'http://pixate.com')) - layout2 = Android::Widget::LinearLayout.new(activity) - layout2.orientation = Android::Widget::LinearLayout::HORIZONTAL - layout2.gravity = Android::View::Gravity::CENTER_HORIZONTAL - - layout2.addView(createLogoView.call('terriblelabs', 'http://terriblelabs.com')) - layout2.addView(createLogoView.call('rubymine', 'http://jetbrains.com/ruby')) - - layout.addView(layout2) + otherLayout = nil + if activity.density > 1.0 + otherLayout = Android::Widget::LinearLayout.new(activity) + otherLayout.orientation = Android::Widget::LinearLayout::HORIZONTAL + otherLayout.gravity = Android::View::Gravity::CENTER_HORIZONTAL + layout.addView(otherLayout) + else + otherLayout = layout + end + otherLayout.addView(createLogoView.call('terriblelabs', 'http://terriblelabs.com')) + otherLayout.addView(createLogoView.call('rubymine', 'http://jetbrains.com/ruby')) scrollView = Android::Widget::ScrollView.new(activity) scrollView.backgroundColor = Android::Graphics::Color::WHITE diff --git a/android-samples/Conference/resources/drawable/rmc_logo.png b/android-samples/Conference/resources/drawable/rmc_logo.png index ebb3fa25..a1ed74fa 100644 Binary files a/android-samples/Conference/resources/drawable/rmc_logo.png and b/android-samples/Conference/resources/drawable/rmc_logo.png differ