List of usage examples for java.lang Thread getDefaultUncaughtExceptionHandler
public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()
From source file:com.dragoniade.deviantart.deviation.SearchRss.java
private int retrieveTotal(ProgressDialog progress, Collection collection) { int offset = collection == null ? 6000 : 480; int greaterThan = 0; int lessThan = Integer.MAX_VALUE; int iteration = 0; String searchQuery = search.getSearch().replace("%username%", user); while (total < 0) { if (progress.isCancelled()) { return -1; }//from ww w . j ava2 s . co m progress.setText("Fetching total (" + ++iteration + ")"); String queryString = "http://backend.deviantart.com/rss.xml?q=" + searchQuery + (collection == null ? "" : "/" + collection.getId()) + "&type=deviation&offset=" + offset; GetMethod method = new GetMethod(queryString); try { int sc = -1; do { sc = client.executeMethod(method); if (sc != 200) { LoggableException ex = new LoggableException(method.getResponseBodyAsString()); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex); int res = DialogHelper.showConfirmDialog(owner, "An error has occured when contacting deviantART : error " + sc + ". Try again?", "Continue?", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return -1; } } } while (sc != 200); XmlToolkit toolkit = XmlToolkit.getInstance(); Element responses = toolkit.parseDocument(method.getResponseBodyAsStream()); method.releaseConnection(); List<?> deviations = toolkit.getMultipleNodes(responses, "channel/item"); HashMap<String, String> prefixes = new HashMap<String, String>(); prefixes.put("atom", responses.getOwnerDocument().lookupNamespaceURI("atom")); Node next = toolkit.getSingleNode(responses, "channel/atom:link[@rel='next']", toolkit.getNamespaceContext(prefixes)); int size = deviations.size(); if (debug) { System.out.println(); System.out.println(); System.out.println("Lesser Than: " + lessThan); System.out.println("Greater Than: " + greaterThan); System.out.println("Offset: " + offset); System.out.println("Size: " + size); } if (size != OFFSET && size > 0) { if (next != null) { greaterThan = offset + OFFSET; } else { if (debug) System.out.println("Total (offset + size) : " + (offset + size)); return offset + size; } } // Page is full, there is more deviations if (size == OFFSET) { greaterThan = offset + OFFSET; } if (size == 0) { lessThan = offset; } if (greaterThan == lessThan) { if (debug) System.out.println("Total (greaterThan) : " + greaterThan); return greaterThan; } if (lessThan == Integer.MAX_VALUE) { offset = offset * 2; } else { offset = (greaterThan + lessThan) / 2; if (offset % 60 != 0) { offset = (offset / 60) * 60; } } try { Thread.sleep(500); } catch (InterruptedException e) { } } catch (IOException e) { int res = DialogHelper.showConfirmDialog(owner, "An error has occured when contacting deviantART : error " + e + ". Try again?", "Continue?", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return -1; } } } return total; }
From source file:org.de.jmg.learn.MainActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); blnTextToSpeech = false;//from w w w . j a va 2 s . co m lib.main = this; //getting the kind of userinterface: television or watch or else int UIMode = lib.getUIMode(this); switch (UIMode) { case Configuration.UI_MODE_TYPE_TELEVISION: isTV = true; break; case Configuration.UI_MODE_TYPE_WATCH: isWatch = true; break; } if (savedInstanceState != null) { JMGDataDirectory = savedInstanceState.getString("JMGDataDirectory"); } setContentView(R.layout.activity_main_viewpager); /** Getting a reference to ViewPager from the layout */ View pager = this.findViewById(R.id.pager); Layout = (ViewGroup) pager; mPager = (ViewPager) pager; /** Getting a reference to FragmentManager */ FragmentManager fm = getSupportFragmentManager(); setPageChangedListener(); /** Creating an instance of FragmentPagerAdapter */ if (fPA == null) { fPA = new MyFragmentPagerAdapter(fm, this, savedInstanceState != null); } /** Setting the FragmentPagerAdapter object to the viewPager object */ mPager.setAdapter(fPA); //mPager.setCurrentItem(0); libLearn.gStatus = "onCreate getEink"; try { _blnEink = getWindowManager().getDefaultDisplay().getRefreshRate() < 5.0; if (_blnEink) lib.ShowToast(this, "This is an Eink diplay!"); } catch (Exception ex) { lib.ShowException(this, ex); } try { libLearn.gStatus = "onCreate setContentView"; mainView = findViewById(Window.ID_ANDROID_CONTENT); defaultErrorHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(ErrorHandler); // View LayoutMain = findViewById(R.id.layoutMain); processPreferences(savedInstanceState != null); libLearn.gStatus = "onCreate Copy Assets"; CopyAssets(); try { processBundle(savedInstanceState); } catch (Exception e) { e.printStackTrace(); lib.ShowException(this, e); } //InitSettings(); Intent intent = getIntent(); if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri uri = intent.getData(); if (uri.toString().startsWith("loginquizlet:/")) { loginQuizlet = new LoginQuizletActivity(); this.onNewIntent(intent); } //finish(); } } catch (Exception ex) { lib.ShowException(this, ex); } }
From source file:com.google.android.marvin.screenspeak.ScreenSpeakService.java
@Override public void onCreate() { super.onCreate(); sInstance = this; setServiceState(SERVICE_STATE_INACTIVE); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mSystemUeh = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); mAccessibilityEventProcessor = new AccessibilityEventProcessor(this); initializeInfrastructure();//w w w .j a v a 2 s .co m }
From source file:com.google.android.marvin.mytalkback.TalkBackService.java
@Override public void onCreate() { super.onCreate(); sInstance = this; setServiceState(ServiceState.INACTIVE); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mSystemUeh = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); initializeInfrastructure();/*w w w.ja v a 2s . com*/ }
From source file:org.elasticsearch.test.ESIntegTestCase.java
protected final void beforeInternal() throws Exception { assert Thread.getDefaultUncaughtExceptionHandler() instanceof ElasticsearchUncaughtExceptionHandler; try {//from w w w.j ava2s . co m final Scope currentClusterScope = getCurrentClusterScope(); switch (currentClusterScope) { case SUITE: assert SUITE_SEED != null : "Suite seed was not initialized"; currentCluster = buildAndPutCluster(currentClusterScope, SUITE_SEED); break; case TEST: currentCluster = buildAndPutCluster(currentClusterScope, randomLong()); break; default: fail("Unknown Scope: [" + currentClusterScope + "]"); } cluster().beforeTest(getRandom(), getPerTestTransportClientRatio()); cluster().wipe(); randomIndexTemplate(); printTestMessage("before"); } catch (OutOfMemoryError e) { if (e.getMessage().contains("unable to create new native thread")) { ESTestCase.printStackDump(logger); } throw e; } }
From source file:com.dragoniade.deviantart.deviation.SearchRss.java
public List<Collection> getCollections() { List<Collection> collections = new ArrayList<Collection>(); if (search.getCollection() == null) { collections.add(null);/*from w w w . jav a 2 s . co m*/ return collections; } String queryString = "http://" + user + ".deviantart.com/" + search.getCollection() + "/"; GetMethod method = new GetMethod(queryString); try { int sc = -1; do { sc = client.executeMethod(method); if (sc != 200) { LoggableException ex = new LoggableException(method.getResponseBodyAsString()); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex); int res = DialogHelper.showConfirmDialog(owner, "An error has occured when contacting deviantART : error " + sc + ". Try again?", "Continue?", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return null; } } } while (sc != 200); InputStream is = method.getResponseBodyAsStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int read = -1; while ((read = is.read(buffer)) > -1) { baos.write(buffer, 0, read); if (baos.size() > 2097152) { int res = DialogHelper.showConfirmDialog(owner, "An error has occured: The document is too big (over 2 megabytes) and look suspicious. Abort?", "Continue?", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_NO_OPTION) { return null; } } } String charsetName = method.getResponseCharSet(); String body = baos.toString(charsetName); String regex = user + ".deviantart.com/" + search.getCollection() + "/([0-9]+)\"[^>]*>([^<]+)<"; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(body); while (matcher.find()) { String id = matcher.group(1); String name = matcher.group(2); Collection c = new Collection(Long.parseLong(id), name); collections.add(c); } } catch (IOException e) { } finally { method.releaseConnection(); } collections.add(null); return collections; }
From source file:org.elasticsearch.test.ElasticsearchIntegrationTest.java
protected final void beforeInternal() throws Exception { assert Thread.getDefaultUncaughtExceptionHandler() instanceof ElasticsearchUncaughtExceptionHandler; try {/*ww w.java 2s.co m*/ final Scope currentClusterScope = getCurrentClusterScope(); switch (currentClusterScope) { case SUITE: assert SUITE_SEED != null : "Suite seed was not initialized"; currentCluster = buildAndPutCluster(currentClusterScope, SUITE_SEED); break; case TEST: currentCluster = buildAndPutCluster(currentClusterScope, randomLong()); break; default: fail("Unknown Scope: [" + currentClusterScope + "]"); } cluster().beforeTest(getRandom(), getPerTestTransportClientRatio()); cluster().wipe(); randomIndexTemplate(); printTestMessage("before"); } catch (OutOfMemoryError e) { if (e.getMessage().contains("unable to create new native thread")) { ElasticsearchTestCase.printStackDump(logger); } throw e; } }
From source file:com.vonglasow.michael.satstat.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Context c = getApplicationContext(); File dumpDir = c.getExternalFilesDir(null); DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.ROOT); fmt.setTimeZone(TimeZone.getTimeZone("UTC")); String fileName = String.format("satstat-%s.log", fmt.format(new Date(System.currentTimeMillis()))); File dumpFile = new File(dumpDir, fileName); PrintStream s;// www . j a va 2 s . c o m try { InputStream buildInStream = getResources().openRawResource(R.raw.build); s = new PrintStream(dumpFile); s.append("SatStat build: "); int i; try { i = buildInStream.read(); while (i != -1) { s.write(i); i = buildInStream.read(); } buildInStream.close(); } catch (IOException e1) { e1.printStackTrace(); } s.append("\n\n"); e.printStackTrace(s); s.flush(); s.close(); Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(dumpFile); mediaScanIntent.setData(contentUri); c.sendBroadcast(mediaScanIntent); } catch (FileNotFoundException e2) { e2.printStackTrace(); } defaultUEH.uncaughtException(t, e); } }); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); prefUnitType = mSharedPreferences.getBoolean(Const.KEY_PREF_UNIT_TYPE, prefUnitType); prefKnots = mSharedPreferences.getBoolean(Const.KEY_PREF_KNOTS, prefKnots); prefCoord = Integer .valueOf(mSharedPreferences.getString(Const.KEY_PREF_COORD, Integer.toString(prefCoord))); prefUtc = mSharedPreferences.getBoolean(Const.KEY_PREF_UTC, prefUtc); prefCid = mSharedPreferences.getBoolean(Const.KEY_PREF_CID, prefCid); prefCid2 = mSharedPreferences.getBoolean(Const.KEY_PREF_CID2, prefCid2); prefWifiSort = Integer .valueOf(mSharedPreferences.getString(Const.KEY_PREF_WIFI_SORT, Integer.toString(prefWifiSort))); prefMapOffline = mSharedPreferences.getBoolean(Const.KEY_PREF_MAP_OFFLINE, prefMapOffline); prefMapPath = mSharedPreferences.getString(Const.KEY_PREF_MAP_PATH, prefMapPath); ActionBar actionBar = getSupportActionBar(); setContentView(R.layout.activity_main); // Find out default screen orientation Configuration config = getResources().getConfiguration(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); int rot = wm.getDefaultDisplay().getRotation(); isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180) || config.orientation == Configuration.ORIENTATION_PORTRAIT && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270)); Log.d(TAG, "isWideScreen=" + Boolean.toString(isWideScreen)); // Create the adapter that will return a fragment for each of the // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); Context ctx = new ContextThemeWrapper(getApplication(), R.style.AppTheme); mTabLayout = new TabLayout(ctx); LinearLayout.LayoutParams mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); mTabLayout.setLayoutParams(mTabLayoutParams); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { TabLayout.Tab newTab = mTabLayout.newTab(); newTab.setIcon(mSectionsPagerAdapter.getPageIcon(i)); mTabLayout.addTab(newTab); } actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(mTabLayout); mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager)); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout)); // This is needed by the mapsforge library. AndroidGraphicFactory.createInstance(this.getApplication()); // Get system services for event delivery locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mOrSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mAccSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mGyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mMagSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mLightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mProximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mPressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mHumiditySensor = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mTempSensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); }
From source file:com.dragoniade.deviantart.favorites.FavoritesDownloader.java
private STATUS downloadFile(Deviation da, String downloadUrl, String filename, boolean reportError, YesNoAllDialog matureMoveDialog, YesNoAllDialog overwriteDialog, YesNoAllDialog overwriteNewerDialog, YesNoAllDialog deleteEmptyDialog) { AtomicBoolean download = new AtomicBoolean(true); File art = getFile(da, downloadUrl, filename, download, matureMoveDialog, overwriteDialog, overwriteNewerDialog, deleteEmptyDialog); if (art == null) { return null; }/*from ww w . j ava 2 s. c o m*/ if (download.get()) { File parent = art.getParentFile(); if (!parent.exists()) { if (!parent.mkdirs()) { showMessageDialog(owner, "Unable to create '" + parent.getPath() + "'.", "Error", JOptionPane.ERROR_MESSAGE); return null; } } GetMethod method = new GetMethod(downloadUrl); try { int sc = -1; do { sc = client.executeMethod(method); requestCount++; if (sc != 200) { if (sc == 404 || sc == 403) { method.releaseConnection(); return STATUS.NOTFOUND; } else { LoggableException ex = new LoggableException(method.getResponseBodyAsString()); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex); int res = showConfirmDialog(owner, "An error has occured when contacting deviantART : error " + sc + ". Try again?", "Continue?", JOptionPane.YES_NO_CANCEL_OPTION); if (res == JOptionPane.NO_OPTION) { String text = "<br/><a style=\"color:red;\" href=\"" + da.getUrl() + "\">" + downloadUrl + " has an error" + "</a>"; setPaneText(text); method.releaseConnection(); progress.incremTotal(); return STATUS.SKIP; } if (res == JOptionPane.CANCEL_OPTION) { return null; } try { Thread.sleep(500); } catch (InterruptedException e) { } } } } while (sc != 200); int length = (int) method.getResponseContentLength(); int copied = 0; progress.setUnitMax(length); InputStream is = method.getResponseBodyAsStream(); File tmpFile = new File(art.getParentFile(), art.getName() + ".tmp"); FileOutputStream fos = new FileOutputStream(tmpFile, false); byte[] buffer = new byte[16184]; int read = -1; while ((read = is.read(buffer)) > 0) { fos.write(buffer, 0, read); copied += read; progress.setUnitValue(copied); if (progress.isCancelled()) { is.close(); method.releaseConnection(); tmpFile.delete(); return null; } } fos.close(); method.releaseConnection(); if (art.exists()) { if (!art.delete()) { showMessageDialog(owner, "Unable to delete '" + art.getPath() + "'.", "Error", JOptionPane.ERROR_MESSAGE); return null; } } if (!tmpFile.renameTo(art)) { showMessageDialog(owner, "Unable to rename '" + tmpFile.getPath() + "' to '" + art.getPath() + "'.", "Error", JOptionPane.ERROR_MESSAGE); return null; } art.setLastModified(da.getTimestamp().getTime()); return STATUS.DOWNLOADED; } catch (HttpException e) { showMessageDialog(owner, "Error contacting deviantART: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); return null; } catch (IOException e) { showMessageDialog(owner, "Error contacting deviantART: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); return null; } } else { progress.setText("Skipping file '" + filename + "' from " + da.getArtist()); return STATUS.SKIP; } }
From source file:com.cognizant.trumobi.em.Email.java
@Override public void onCreate() { super.onCreate(); /*BugSenseHandler.initAndStartSession(this.getApplicationContext(), "377266e1");*//*from ww w .jav a2 s . c o m*/ Thread.setDefaultUncaughtExceptionHandler( new PersonaExceptionHandler(this, Thread.getDefaultUncaughtExceptionHandler())); EmPreferences prefs = EmPreferences.getPreferences(this); DEBUG = prefs.getEnableDebugLogging(); DEBUG_SENSITIVE = prefs.getEnableSensitiveLogging(); setTempDirectory(this); appContext = getApplicationContext(); checkBugSenseEnableStatus(); // Reset all accounts to default visible window EmEmController.getInstance(this).resetVisibleLimits(); // Enable logging in the EAS service, so it starts up as early as // possible. EmDebug.updateLoggingFlags(this); // Listen Phone Call Changes DialerParentActivity listenState = new DialerParentActivity(); callListner = listenState.new PhoneCallListener(getAppContext()); telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); telMgr.listen(callListner, PhoneCallListener.LISTEN_CALL_STATE); //Broadcast registerBroadcastReceiver(); }