Skip to content

Instantly share code, notes, and snippets.

@lajunta
Created September 21, 2015 18:23
Show Gist options
  • Save lajunta/470c304cb6b5b815e7ae to your computer and use it in GitHub Desktop.
Save lajunta/470c304cb6b5b815e7ae to your computer and use it in GitHub Desktop.
Drawable = Android::Graphics::Drawable::Drawable
BitmapFactory = Android::Graphics::BitmapFactory
Toast = Android::Widget::Toast
Url = Java::Net::URL
class MyAsyncTask < Android::Os::AsyncTask
attr :img
def doInBackground(params)
@img = params[1]
puts "doInBackground #{params}"
#self.publishProgress([1,2,3])
url = Url.new(params[0])
is = url.openStream()
BitmapFactory.decodeStream(is);
end
def onPostExecute(result)
puts "Result to Image"
@img.setImageBitmap(result)
end
end
class Imageviw < Android::App::Activity
def onCreate(savedInstanceState)
super
#Android::Os::AsyncTask.execute(MyRunnable.new)
setContentView(R::Layout::Image_viw)
img = findViewById(R::Id::Imgfromurl)
my_task = MyAsyncTask.new
#url = "http://dcs.conac.cn/image/blue.png"
url = "http://www.lwqzx.sdedu.net/ec/see/54518dcb444c2d4895010000"
my_task.execute([url,img])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment