List of usage examples for android.os Looper loop
public static void loop()
From source file:piuk.blockchain.android.WalletApplication.java
public void apiStoreKey(final String pin, final SuccessCallback callback) { final MyRemoteWallet blockchainWallet = this.blockchainWallet; if (blockchainWallet == null) { if (callback != null) callback.onFail();/*from w w w. j a v a2 s . c o m*/ return; } final WalletApplication application = this; new Thread(new Runnable() { @Override public void run() { Looper.prepare(); Editor edit = PreferenceManager.getDefaultSharedPreferences(application).edit(); // // Save PIN // try { byte[] bytes = new byte[16]; SecureRandom random = new SecureRandom(); random.nextBytes(bytes); final String key = new String(Hex.encode(bytes), "UTF-8"); random.nextBytes(bytes); final String value = new String(Hex.encode(bytes), "UTF-8"); final JSONObject response = piuk.blockchain.android.ui.PinEntryActivity.apiStoreKey(key, value, pin); if (response.get("success") != null) { callback.onSuccess(); edit.putString("pin_kookup_key", key); edit.putString("encrypted_password", MyWallet.encrypt(application.getRemoteWallet().getTemporyPassword(), value, piuk.blockchain.android.ui.PinEntryActivity.PBKDF2Iterations)); if (!edit.commit()) { throw new Exception("Error Saving Preferences"); } else { } } else { Toast.makeText(application, response.toString(), Toast.LENGTH_LONG).show(); } } catch (Exception e) { Toast.makeText(application, e.toString(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } // // // Looper.loop(); } }).start(); }
From source file:dentex.youtube.downloader.DashboardActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { BugSenseHandler.leaveBreadcrumb("DashboardActivity_filechooser_RESULT_OK"); @SuppressWarnings("unchecked") List<LocalFile> files = (List<LocalFile>) data.getSerializableExtra(FileChooserActivity._Results); String path = data.getStringExtra("path"); String name = data.getStringExtra("name"); File in = new File(path, name); final File chooserSelection = files.get(0); //Utils.logger("d", "file-chooser selection: " + chooserFolder.getPath(), DEBUG_TAG); //Utils.logger("d", "origin file's folder: " + currentItem.getPath(), DEBUG_TAG); switch (requestCode) { case 1: // ------------- > COPY File out1 = new File(chooserSelection, name); if (chooserSelection.getPath().equals(currentItem.getPath())) { out1 = new File(chooserSelection, "copy_" + currentItem.getFilename()); }/*w w w .j a v a 2 s.com*/ if (!out1.exists()) { switch (Utils.pathCheck(chooserSelection)) { case 0: // Path on standard sdcard new AsyncCopy().execute(in, out1); break; case 1: // Path not writable PopUps.showPopUp(getString(R.string.system_warning_title), getString(R.string.system_warning_msg), "alert", DashboardActivity.this); break; case 2: // Path not mounted Toast.makeText(DashboardActivity.this, getString(R.string.sdcard_unmounted_warning), Toast.LENGTH_SHORT).show(); } } else { PopUps.showPopUp(getString(R.string.long_press_warning_title), getString(R.string.long_press_warning_msg2), "info", DashboardActivity.this); } break; case 2: // ------------- > MOVE File out2 = new File(chooserSelection, name); if (!chooserSelection.getPath().equals(currentItem.getPath())) { if (!out2.exists()) { switch (Utils.pathCheck(chooserSelection)) { case 0: // Path on standard sdcard new AsyncMove().execute(in, out2); break; case 1: // Path not writable PopUps.showPopUp(getString(R.string.system_warning_title), getString(R.string.system_warning_msg), "alert", DashboardActivity.this); break; case 2: // Path not mounted Toast.makeText(DashboardActivity.this, getString(R.string.sdcard_unmounted_warning), Toast.LENGTH_SHORT).show(); } } else { PopUps.showPopUp(getString(R.string.long_press_warning_title), getString(R.string.long_press_warning_msg2), "info", DashboardActivity.this); } } else { PopUps.showPopUp(getString(R.string.long_press_warning_title), getString(R.string.long_press_warning_msg), "info", DashboardActivity.this); } break; case 3: // ------------- > MENU_BACKUP new Thread(new Runnable() { @Override public void run() { Looper.prepare(); String date = new SimpleDateFormat("yyyy-MM-dd'_'HH-mm-ss", Locale.US).format(new Date()); final File backup = new File(chooserSelection, date + "_" + YTD.JSON_FILENAME); try { Utils.copyFile(YTD.JSON_FILE, backup); Toast.makeText(sDashboard, getString(R.string.menu_backup_result_ok), Toast.LENGTH_SHORT).show(); } catch (IOException e) { Log.e(DEBUG_TAG, "IOException @ MENU_BACKUP: " + e.getMessage()); Toast.makeText(sDashboard, getString(R.string.menu_backup_result_failed), Toast.LENGTH_LONG).show(); } Looper.loop(); } }).start(); break; case 4: // ------------- > MENU_RESTORE AsyncRestore ar = new AsyncRestore(); ar.execute(chooserSelection); break; case 5: // ------------- > MENU_IMPORT AsyncImport ai = new AsyncImport(); ai.execute(chooserSelection); } } }
From source file:org.mozilla.gecko.GeckoApp.java
private void initialize() { mInitialized = true;/*from w w w. j a va 2s . c o m*/ Intent intent = getIntent(); String args = intent.getStringExtra("args"); if (args != null && args.contains("-profile")) { Pattern p = Pattern.compile("(?:-profile\\s*)(\\w*)(\\s*)"); Matcher m = p.matcher(args); if (m.find()) { mProfile = GeckoProfile.get(this, m.group(1)); mLastTitle = null; mLastViewport = null; mLastScreen = null; } } if (ACTION_UPDATE.equals(intent.getAction()) || args != null && args.contains("-alert update-app")) { Log.i(LOGTAG, "onCreate: Update request"); checkAndLaunchUpdate(); } mBrowserToolbar.init(); mBrowserToolbar.setTitle(mLastTitle); String passedUri = null; String uri = getURIFromIntent(intent); if (uri != null && uri.length() > 0) passedUri = mLastTitle = uri; if (passedUri == null || passedUri.equals("about:home")) { // show about:home if we aren't restoring previous session if (!getProfile().hasSession()) { mBrowserToolbar.updateTabCount(1); showAboutHome(); } } else { mBrowserToolbar.updateTabCount(1); } if (sGREDir == null) sGREDir = new File(this.getApplicationInfo().dataDir); Uri data = intent.getData(); if (data != null && "http".equals(data.getScheme()) && isHostOnPrefetchWhitelist(data.getHost())) { Intent copy = new Intent(intent); copy.setAction(ACTION_LOAD); GeckoAppShell.getHandler().post(new RedirectorRunnable(copy)); // We're going to handle this uri with the redirector, so setting // the action to MAIN and clearing the uri data prevents us from // loading it twice intent.setAction(Intent.ACTION_MAIN); intent.setData(null); passedUri = null; } sGeckoThread = new GeckoThread(intent, passedUri, mRestoreSession); if (!ACTION_DEBUG.equals(intent.getAction()) && checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched)) sGeckoThread.start(); mFavicons = new Favicons(this); Tabs.getInstance().setContentResolver(getContentResolver()); if (cameraView == null) { cameraView = new SurfaceView(this); cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } if (mLayerController == null) { /* * Create a layer client so that Gecko will have a buffer to draw into, but don't hook * it up to the layer controller yet. */ mSoftwareLayerClient = new GeckoSoftwareLayerClient(this); /* * Hook a placeholder layer client up to the layer controller so that the user can pan * and zoom a cached screenshot of the previous page. This call will return null if * there is no cached screenshot; in that case, we have no choice but to display a * checkerboard. * * TODO: Fall back to a built-in screenshot of the Fennec Start page for a nice first- * run experience, perhaps? */ mLayerController = new LayerController(this); mPlaceholderLayerClient = PlaceholderLayerClient.createInstance(this); mLayerController.setLayerClient(mPlaceholderLayerClient); mGeckoLayout.addView(mLayerController.getView(), 0); } mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container); mDoorHangerPopup = new DoorHangerPopup(this); mAutoCompletePopup = (AutoCompletePopup) findViewById(R.id.autocomplete_popup); Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up"); if (!sTryCatchAttached) { sTryCatchAttached = true; mMainHandler.post(new Runnable() { public void run() { try { Looper.loop(); } catch (Exception e) { GeckoAppShell.reportJavaCrash(e); } // resetting this is kinda pointless, but oh well sTryCatchAttached = false; } }); } //register for events GeckoAppShell.registerGeckoEventListener("DOMContentLoaded", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMWindowClose", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("log", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Content:StateChange", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Content:LoadError", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Doorhanger:Remove", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Menu:Add", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Menu:Remove", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Toast:Show", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Start", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Stop", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("FormAssist:AutoComplete", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Permissions:Data", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Downloads:Done", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("CharEncoding:Data", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("CharEncoding:State", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Update:Restart", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Tab:HasTouchListener", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext); 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(); final GeckoApp self = this; GeckoAppShell.getHandler().postDelayed(new Runnable() { public void run() { Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - pre checkLaunchState"); /* XXXX see bug 635342 We want to disable this code if possible. It is about 145ms in runtime SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE); String localeCode = settings.getString(getPackageName() + ".locale", ""); if (localeCode != null && localeCode.length() > 0) GeckoAppShell.setSelectedLocale(localeCode); */ if (!checkLaunchState(LaunchState.Launched)) { return; } checkMigrateProfile(); } }, 50); }
From source file:dentex.youtube.downloader.DashboardActivity.java
public void ffmpegJob(final File fileToConvert, final String bitrateType, final String bitrateValue) { BugSenseHandler.leaveBreadcrumb("ffmpegJob"); isFfmpegRunning = true;//w w w .ja va 2s . co m vfilename = currentItem.getFilename(); // audio job notification init aBuilder = new NotificationCompat.Builder(this); aNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); aBuilder.setSmallIcon(R.drawable.ic_stat_ytd); aBuilder.setContentTitle(vfilename); String aExt = currentItem.getAudioExt(); basename = currentItem.getBasename(); final String audioFileName; // "compose" the audio file if (bitrateValue != null) { extrTypeIsMp3Conv = true; audioFileName = basename + "_" + bitrateType + "-" + bitrateValue + ".mp3"; } else { extrTypeIsMp3Conv = false; audioFileName = basename + aExt; } audioFile = new File(fileToConvert.getParent(), audioFileName); if (!audioFile.exists()) { new Thread(new Runnable() { @Override public void run() { Looper.prepare(); FfmpegController ffmpeg = null; try { ffmpeg = new FfmpegController(DashboardActivity.this); // Toast + Notification + Log ::: Audio job in progress... String text = null; if (!extrTypeIsMp3Conv) { text = getString(R.string.audio_extr_progress); type = YTD.JSON_DATA_TYPE_A_E; } else { text = getString(R.string.audio_conv_progress); type = YTD.JSON_DATA_TYPE_A_M; } Toast.makeText(DashboardActivity.this, "YTD: " + text, Toast.LENGTH_LONG).show(); aBuilder.setContentTitle(audioFileName); aBuilder.setContentText(text); aBuilder.setOngoing(true); aNotificationManager.notify(2, aBuilder.build()); Utils.logger("i", vfilename + " " + text, DEBUG_TAG); } catch (IOException ioe) { Log.e(DEBUG_TAG, "Error loading ffmpeg. " + ioe.getMessage()); } ShellDummy shell = new ShellDummy(); try { ffmpeg.extractAudio(fileToConvert, audioFile, bitrateType, bitrateValue, shell); } catch (IOException e) { Log.e(DEBUG_TAG, "IOException running ffmpeg" + e.getMessage()); } catch (InterruptedException e) { Log.e(DEBUG_TAG, "InterruptedException running ffmpeg" + e.getMessage()); } Looper.loop(); } }).start(); } else { PopUps.showPopUp(getString(R.string.long_press_warning_title), getString(R.string.audio_extr_warning_msg), "info", DashboardActivity.this); isFfmpegRunning = false; } }
From source file:com.codename1.impl.android.AndroidImplementation.java
private String getUserAgent() { try {/*ww w. j a v a2 s . c om*/ String userAgent = System.getProperty("http.agent"); if (userAgent != null) { return userAgent; } } catch (Exception e) { } if (getActivity() == null) { return "Android-CN1"; } try { Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class, WebView.class); constructor.setAccessible(true); try { WebSettings settings = constructor.newInstance(getActivity(), null); return settings.getUserAgentString(); } finally { constructor.setAccessible(false); } } catch (Exception e) { final StringBuffer ua = new StringBuffer(); if (Thread.currentThread().getName().equalsIgnoreCase("main")) { WebView m_webview = new WebView(getActivity()); ua.append(m_webview.getSettings().getUserAgentString()); m_webview.destroy(); } else { final boolean[] flag = new boolean[1]; Thread thread = new Thread() { public void run() { Looper.prepare(); WebView m_webview = new WebView(getActivity()); ua.append(m_webview.getSettings().getUserAgentString()); m_webview.destroy(); Looper.loop(); flag[0] = true; synchronized (flag) { flag.notify(); } } }; thread.setUncaughtExceptionHandler(AndroidImplementation.exceptionHandler); thread.start(); while (!flag[0]) { synchronized (flag) { try { flag.wait(100); } catch (InterruptedException ex) { } } } } return ua.toString(); } }