assets/src/ruboto/activity/reload.rb in ruboto-0.15.0 vs assets/src/ruboto/activity/reload.rb in ruboto-0.16.0

- old
+ new

@@ -1,26 +1,28 @@ +require 'ruboto/activity' + module Ruboto::Activity::Reload import org.ruboto.Log def onResume - Log.d "Ruboto::Activity::Reload onResume" + Log.d 'Ruboto::Activity::Reload onResume' super @ruboto_activity_reload_receiver = ReloadReceiver.new(self) filter = android.content.IntentFilter.new(android.content.Intent::ACTION_VIEW) registerReceiver(@ruboto_activity_reload_receiver, filter) - Log.d "Ruboto::Activity::Reload registered reload receiver" + Log.d 'Ruboto::Activity::Reload registered reload receiver' rescue Exception Log.e "Exception registering reload listener: #{$!.message}" Log.e $!.backtrace.join("\n") end def onPause super unregisterReceiver(@ruboto_activity_reload_receiver) @ruboto_activity_reload_receiver = nil - Log.d "Ruboto::Activity::Reload unregistered reload receiver" + Log.d 'Ruboto::Activity::Reload unregistered reload receiver' rescue Exception Log.e "Exception unregistering reload listener: #{$!.message}" Log.e $!.backtrace.join("\n") end @@ -36,20 +38,23 @@ # FIXME(uwe): I would like to receive a string array, # but have not found a way to do that. def onReceive(context, reload_intent) Log.d "Got reload intent: #{reload_intent.inspect}" - file = reload_intent.get_string_extra('file') - if file - Log.d "load file: #{file.inspect}" - load file - end - if (reload_intent.get_string_extra('restart')) + file_string = reload_intent.get_string_extra('reload') + if file_string + files = file_string.split(/(?<!&);/).map { |f| f.gsub(/&(.)/) { |m| m[1] } } + files.each do |file| + Log.d "load file: #{file.inspect}" + load file + end Log.d 'restart activity' - if @activity.intent.action == android.content.Intent::ACTION_MAIN - restart_intent = android.content.Intent.new(@activity.intent).setAction(android.content.Intent::ACTION_VIEW) + if @activity.intent.action == android.content.Intent::ACTION_MAIN || + @activity.intent.action == android.hardware.usb.UsbManager::ACTION_USB_DEVICE_ATTACHED + restart_intent = android.content.Intent.new(@activity.intent). + setAction(android.content.Intent::ACTION_VIEW) else - restart_intent = @activity.intent + restart_intent = @activity.intent end @activity.startActivity(restart_intent) @activity.finish Log.d 'activity restarted' end