private void scanLeDevice(final boolean enable) {
   if (enable) {
     mHandler.postDelayed(
         new Runnable() {
           @Override
           public void run() {
             if (Build.VERSION.SDK_INT < 21) {
               mBluetoothAdapter.stopLeScan(mLeScanCallback);
             } else {
               mLEScanner.stopScan(mScanCallback);
             }
           }
         },
         SCAN_PERIOD);
     if (Build.VERSION.SDK_INT < 21) {
       mBluetoothAdapter.startLeScan(mLeScanCallback);
     } else {
       mLEScanner.startScan(filters, settings, mScanCallback);
     }
   } else {
     if (Build.VERSION.SDK_INT < 21) {
       mBluetoothAdapter.stopLeScan(mLeScanCallback);
     } else {
       mLEScanner.stopScan(mScanCallback);
     }
   }
 }
示例#2
0
 /** Cancel loading of a drawable for a certain ImageView. */
 public void cancelLoad(ImageView view) {
   String fso = mRequests.get(view);
   if (fso != null && mWorkerHandler != null) {
     mWorkerHandler.removeMessages(MSG_LOAD, fso);
   }
   mRequests.remove(view);
 }
 private void sendExceptionMsg(int what, Exception e) {
   e.printStackTrace();
   Message msg = Message.obtain();
   msg.obj = e;
   msg.what = what;
   queryHandler.sendMessage(msg);
 }
 @Override
 public void handleMessage(Message msg) {
   switch (msg.what) {
     case WebSocketService.MSG_INCOMING:
       String text = msg.getData().getString("text");
       incoming.setText("Incoming Message: " + text);
       break;
     default:
       super.handleMessage(msg);
   }
 }
示例#5
0
 public void handleMessage(Message msg) {
   mValue++;
   mText.setText(Integer.toString(mValue));
   try {
     Thread.sleep(50);
   } catch (InterruptedException e) {;
   }
   if (mValue < 100 && mQuit == false) {
     mProgress.setProgress(mValue);
     mHandler.sendEmptyMessage(0);
   } else {
     dismissDialog(0);
   }
 }
示例#6
0
        public void handleMessage(Message msg) {
          Ball B;
          for (int idx = 0; idx < arBall.size(); idx++) {
            B = arBall.get(idx);
            B.Move(getWidth(), getHeight());
            if (B.count > 4) {
              arBall.remove(idx);
              idx--;
            }
          }

          invalidate();
          mHandler.sendEmptyMessageDelayed(0, DELAY);
        }
示例#7
0
文件: D4.java 项目: sarekautowerke/D4
  public void getFilesFromFolder(List filesAndFolders, String savePath) {
    // create a File object for the parent directory
    File downloadsDirectory = new File(savePath);
    // create the folder if needed.
    downloadsDirectory.mkdir();

    for (int i = 0; i < filesAndFolders.size(); i++) {
      Object links = filesAndFolders.get(i);
      List linksArray = (ArrayList) links;
      if (i == 0) {
        for (int j = 0; j < linksArray.size(); j += 2) {
          // We've got an array of file urls so download each one to a directory with the folder
          // name
          String fileURL = linksArray.get(j).toString();
          String fileName = linksArray.get(j + 1).toString();
          downloadFile(fileURL, savePath, fileName);
          progress++;
          Message msg = mHandler.obtainMessage();
          msg.arg1 = progress;
          mHandler.sendMessage(msg);
        }
      } else if (i == 1) {
        // we've got an array of folders so recurse down the levels, extracting subfolders and files
        // until we've downloaded everything.
        for (int j = 0; j < linksArray.size(); j += 2) {
          String folderURL = linksArray.get(j).toString();
          String folderName = linksArray.get(j + 1).toString();

          String page = getData(folderURL);
          List newFilesAndFolders = parsePage(page);
          String dlDirPath = savePath + folderName + "/";

          getFilesFromFolder(newFilesAndFolders, dlDirPath);
        }
      }
    }
  }
  public void run() {
    OfxRequest req = session.newRequest();
    AccountInfoMsgReq acctReq = new AccountInfoMsgReq();
    acctReq.acctListAge = session.profile.acctListAge;
    req.addRequest(acctReq);

    List<OfxMessageResp> response;
    try {
      response = req.submit(this);

      for (OfxMessageResp resp : response) {
        if (resp instanceof AccountInfoMsgResp) {
          AccountInfoMsgResp acctResp = (AccountInfoMsgResp) resp;
          session.profile.acctListAge = acctResp.acctListAge;
          accountList = acctResp.accounts;
        }
      }
    } catch (HttpResponseException e) {
      sendExceptionMsg(QH_ERR_STATUS, e);
    } catch (OfxError e) {
      sendExceptionMsg(QH_ERR_OFX, e);
    } catch (XmlPullParserException e) {
      sendExceptionMsg(QH_ERR_PARSE, e);
    } catch (SSLPeerUnverifiedException e) {
      sendExceptionMsg(QH_ERR_SSL_VERIFY, e);
    } catch (ClientProtocolException e) {
      sendExceptionMsg(QH_ERR_HTTP, e);
    } catch (ConnectException e) {
      sendExceptionMsg(QH_ERR_TIMEOUT, e);
    } catch (SocketException e) {
      sendExceptionMsg(QH_ERR_CONN, e);
    } catch (SSLException e) {
      sendExceptionMsg(QH_ERR_SSL, e);
    } catch (Exception e) {
      sendExceptionMsg(QH_ERR, e);
    }

    ProfileTable db = new ProfileTable(this);
    try {
      db.openWritable();
      db.syncAccounts(session, accountList);
    } catch (SQLiteException e) {
      sendExceptionMsg(QH_ERR, e);
    } finally {
      db.close();
    }

    queryHandler.sendEmptyMessage(QH_OK);
  }
示例#9
0
  @Override
  protected void onNewIntent(Intent intent) {
    if (checkLaunchState(LaunchState.GeckoExiting)) {
      // We're exiting and shouldn't try to do anything else just incase
      // we're hung for some reason we'll force the process to exit
      System.exit(0);
      return;
    }
    final String action = intent.getAction();
    if (ACTION_DEBUG.equals(action)
        && checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitForDebugger)) {

      mMainHandler.postDelayed(
          new Runnable() {
            public void run() {
              Log.i(LOG_FILE_NAME, "Launching from debug intent after 5s wait");
              setLaunchState(LaunchState.Launching);
              launch(null);
            }
          },
          1000 * 5 /* 5 seconds */);
      Log.i(LOG_FILE_NAME, "Intent : ACTION_DEBUG - waiting 5s before launching");
      return;
    }
    if (checkLaunchState(LaunchState.WaitForDebugger) || launch(intent)) return;

    if (Intent.ACTION_MAIN.equals(action)) {
      Log.i(LOG_FILE_NAME, "Intent : ACTION_MAIN");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(""));
    } else if (Intent.ACTION_VIEW.equals(action)) {
      String uri = intent.getDataString();
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "onNewIntent: " + uri);
    } else if (ACTION_WEBAPP.equals(action)) {
      String uri = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "Intent : WEBAPP - " + uri);
    } else if (ACTION_BOOKMARK.equals(action)) {
      String args = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(args));
      Log.i(LOG_FILE_NAME, "Intent : BOOKMARK - " + args);
    }
  }
  @Override
  public void handleDownloadThreadUpdate() {
    handler.post(
        new Runnable() {

          @Override
          public void run() {
            // total_files_to_download = downloadThread.getTotalQueued();
            total_files_to_download = links.size();
            if (downloadThread != null) {
              completed_downloads = downloadThread.getTotalCompleted() + initial_value;
            } else {
              completed_downloads = readProgress()[0];
            }

            progress_download.setMax(links.size());
            // progress_download.incrementProgressBy(1);
            progress_download.setProgress(0); // need to do it due to a ProgressBar bug
            progress_download.setProgress(completed_downloads);

            progress_text.setText(
                "Downloading "
                    + Integer.toString(completed_downloads + 1)
                    + " of "
                    + Integer.toString(links.size())
                    + ".");

            // writeProgress(completed_downloads,total_files_to_download);

            if (completed_downloads == total_files_to_download) {
              completed = true;
              writeProgress(completed_downloads, total_files_to_download);
              if (resume_pause.VISIBLE != View.GONE) resume_pause.setVisibility(View.GONE);
              downloadThread.requestStop();
              progress_text.setText("Completed.");
            }
          }
        });
  }
示例#11
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    mAppContext = this;
    mMainHandler = new Handler();

    if (!sTryCatchAttached) {
      sTryCatchAttached = true;
      mMainHandler.post(
          new Runnable() {
            public void run() {
              try {
                Looper.loop();
              } catch (Exception e) {
                Log.e(LOG_FILE_NAME, "top level exception", e);
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);
                pw.flush();
                GeckoAppShell.reportJavaCrash(sw.toString());
              }
              // resetting this is kinda pointless, but oh well
              sTryCatchAttached = false;
            }
          });
    }

    SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
    String localeCode = settings.getString(getPackageName() + ".locale", "");
    if (localeCode != null && localeCode.length() > 0) GeckoAppShell.setSelectedLocale(localeCode);

    Log.i(LOG_FILE_NAME, "create");
    super.onCreate(savedInstanceState);

    if (sGREDir == null) sGREDir = new File(this.getApplicationInfo().dataDir);

    getWindow()
        .setFlags(
            mFullscreen ? WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    if (cameraView == null) {
      cameraView = new SurfaceView(this);
      cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    if (surfaceView == null) surfaceView = new GeckoSurfaceView(this);
    else mainLayout.removeAllViews();

    mainLayout = new AbsoluteLayout(this);
    mainLayout.addView(
        surfaceView,
        new AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.MATCH_PARENT, // level 8
            AbsoluteLayout.LayoutParams.MATCH_PARENT,
            0,
            0));

    setContentView(
        mainLayout,
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    mConnectivityFilter = new IntentFilter();
    mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    mConnectivityReceiver = new GeckoConnectivityReceiver();

    IntentFilter batteryFilter = new IntentFilter();
    batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    mBatteryReceiver = new GeckoBatteryManager();
    registerReceiver(mBatteryReceiver, batteryFilter);

    if (SmsManager.getInstance() != null) {
      SmsManager.getInstance().start();
    }

    GeckoNetworkManager.getInstance().init();

    if (!checkAndSetLaunchState(LaunchState.PreLaunch, LaunchState.Launching)) return;

    checkAndLaunchUpdate();
    mLibLoadThread =
        new Thread(
            new Runnable() {
              public void run() {
                // At some point while loading the gecko libs our default locale gets set
                // so just save it to locale here and reset it as default after the join
                Locale locale = Locale.getDefault();
                GeckoAppShell.loadGeckoLibs(getApplication().getPackageResourcePath());
                Locale.setDefault(locale);
                Resources res = getBaseContext().getResources();
                Configuration config = res.getConfiguration();
                config.locale = locale;
                res.updateConfiguration(config, res.getDisplayMetrics());
              }
            });
    mLibLoadThread.start();
  }
示例#12
0
 // Send a message from the SDLMain thread
 boolean sendCommand(int command, Object data) {
   Message msg = commandHandler.obtainMessage();
   msg.arg1 = command;
   msg.obj = data;
   return commandHandler.sendMessage(msg);
 }
 @Override
 public void onDetachedFromWindow() {
   super.onDetachedFromWindow();
   ßløødy_ßadßøy_Handler.removeCallbacks(Arpan_Bløødy_ßãdboy);
 }
 @Override
 public void startCoverAnimation() {
   ßløødy_ßadßøy_Handler.post(Arpan_Bløødy_ßãdboy);
 }