扫描杆codeS(ZXing)在自己的线程和显示ProgessDialog [英] Scanning Barcodes (ZXing) in a own Thread and displaying a ProgessDialog

查看:182
本文介绍了扫描杆codeS(ZXing)在自己的线程和显示ProgessDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,因为我知道这一边我的大部分问题都得到了解答使用搜索。但是,这似乎是一个特殊的一个。

since I know this side most of my questions have been answered be using the search. But this seems to be a special one.

我是新来的谷歌Android的发展,所以我想通过边学边做。我想创建一个应用程序,它可以扫描棒codeS,并显示可能的产品清单。我使用ZXing(从这里得到这个!;))扫描barcdes。完美的作品。我quering与扫描栏code中的谷歌购物API,并得到解析RSS提要,因为有一个结果,(但在大多数情况下,^^)。

I am new to Google Android development, so I want to learn by doing. I want to create an app, that scans barcodes and displays a list of possible products. I am using ZXing (got this from here! ;)) to scan the barcdes. Works perfect. I'm quering the google shopping api with the scanned barcode and get parse the rss feed, since there is a result (but in most cases there is ^^).

这一切的伟大工程。但它需要多达四秒后我扫描应用程序返回到我的activitiy。这似乎很长,不是吗?所以我想在扫描部分转移到一个单独的线程,虽然quering从API的结果应该有一个ProgressDialog对于用户来说,他知道什么在那里发生。

This all works great. But it takes up to four seconds after I scan the app returns to my activitiy. This seems very long to, isn't it? So I thought to move the scanning part into a single thread and while quering the result from the api there should be a ProgressDialog for the user, that he knows whats going on there.

这就是我的code迄今:

Thats, my Code so far:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {  
      switch (requestCode) {
      case IntentIntegrator.REQUEST_CODE:
         if (resultCode == Activity.RESULT_OK) {

            IntentResult intentResult = 
               IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);

            if (intentResult != null) {
               String scannedCode = intentResult.getContents();
               String format = intentResult.getFormatName();

               //Gets information to the scanned product by the
               //Google-Shopping-API in form of a rss feed.
               AndroidFeedParser afp = new AndroidFeedParser("https://www.googleapis.com/shopping/search/v1/public/products?key=" +
                    AndroidFeedParser.API_KEY + "&country=DE&q=" + scannedCode + "&alt=" + AndroidFeedParser.FEED_CODE);

               //Parses the given rss feed and gives a FeedItem-List
               List<FeedItem> item = afp.parse();
               Toast toast = null;

               if(item.size() < 1) 
                   //products is NOT listed within the Google-Shopping-API
                   toast = Toast.makeText(this, "Dieses Produkt ist nicht in der Datenbank.", Toast.LENGTH_LONG);
                else 
                   //product is listed within the Google-Shopping-API
                   toast = Toast.makeText(this, item.get(1).getPrice().toString(), Toast.LENGTH_LONG);
               toast.show();
               Log.d("SEARCH_EAN", "OK, EAN: " + scannedCode + ", FORMAT: " + format);
            } else {
               Log.e("SEARCH_EAN", "IntentResult je NULL!");
            }
         } else if (resultCode == Activity.RESULT_CANCELED) {
            Log.e("SEARCH_EAN", "CANCEL");
         }
      } }

我告诉过你,这工作真棒。但是,这要花费很多时间,我想查询到多少时间API费用。我希望你明白我的问题,你能帮帮我!我知道,必须有一个Runnable接口实现的,该方法的run(),但我不知道我有什么code的一部分,分离成以上希望存档。请帮帮我!

I told ya, this works awesome. But this takes to much time, I guess the query to the api costs that much time. I hope you understand my question and you can help me! I do know, that there must be an Interface Runnable implemented and the method run(), but I do not know what part of code I do have to separate to archive that wish above. Please help me!

最好的问候,
巴斯蒂

Best regards, Basti

(对不起我的英文不好,我来自德国)

(Excuse me for my bad english, I'm from Germany)

推荐答案

您应该在创建AndroidFeedParser开始从线上一个新的异步任务......但也许你的应用程序已经完成? ;)

You should start a new asynchronous task from line when you create AndroidFeedParser... but maybe your app is already done? ;)

这篇关于扫描杆codeS(ZXing)在自己的线程和显示ProgessDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆