List of usage examples for android.os StrictMode setThreadPolicy
public static void setThreadPolicy(final ThreadPolicy policy)
From source file:itcr.gitsnes.MainActivity.java
/** Like a game using backendHandler class * call like POST method *//* w w w. j av a 2 s . co m*/ public void like_Game(View view) { /* Async mode*/ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); /* Change button like image*/ TextView name = (TextView) this.findViewById(R.id.txtgameid); findViewById(R.id.btn_liker).setBackgroundResource(R.drawable.heart2); Log.i(TAG, name.getText().toString()); /* Commit like transaction*/ new BackendHandler().liked_Game(name.getText().toString()); Toast.makeText(this, "Thanks for your opinion about the games !!", Toast.LENGTH_LONG).show(); }
From source file:de.grobox.liberario.activities.MainActivity.java
private void enableStrictMode() { if (!BuildConfig.DEBUG) return;//from www. j a va 2 s . c o m StrictMode.ThreadPolicy.Builder threadPolicy = new StrictMode.ThreadPolicy.Builder(); threadPolicy.detectAll(); threadPolicy.penaltyLog(); StrictMode.setThreadPolicy(threadPolicy.build()); StrictMode.VmPolicy.Builder vmPolicy = new StrictMode.VmPolicy.Builder(); vmPolicy.detectAll(); vmPolicy.penaltyLog(); StrictMode.setVmPolicy(vmPolicy.build()); }
From source file:itcr.gitsnes.MainActivity.java
/** Create a frame with the favorites games of the user * call recomended GET method *//*from w ww . ja v a 2s . co m*/ public void getRecomended(MenuItem item) { /* Async mode*/ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); /* Build json*/ String input = new BackendHandler().get_Recommended(new KeyStore().getCurrent_user()); try { json_arr = new JSONArray(input); } catch (JSONException e) { Log.i(TAG, e.toString()); } /* Commit fragment transaction (master view)*/ RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback); rl.setBackgroundColor(Color.parseColor("#e7df00")); authButton.setVisibility(View.INVISIBLE); MasterGames new_fragment = new MasterGames(json_arr); new_fragment.setQtype("all"); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.placeholder, new_fragment); transaction.addToBackStack(null); transaction.commit(); }
From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java
private void restoreTab(TabRestoreDetails tabToRestore, boolean setAsActive) { // As we do this in startup, and restoring the active tab's state is critical, we permit // this read in the event that the prefetch task is not available. Either: // 1. The user just upgraded, has not yet set the new active tab id pref yet. Or // 2. restoreTab is used to preempt async queue and restore immediately on the UI thread. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try {// ww w . j av a2s .c o m long time = SystemClock.uptimeMillis(); TabState state; int restoredTabId = mPreferences.getInt(PREF_ACTIVE_TAB_ID, Tab.INVALID_TAB_ID); if (restoredTabId == tabToRestore.id && mPrefetchActiveTabTask != null) { long timeWaitingForPrefetch = SystemClock.uptimeMillis(); state = mPrefetchActiveTabTask.get(); logExecutionTime("RestoreTabPrefetchTime", timeWaitingForPrefetch); } else { // Necessary to do on the UI thread as a last resort. state = TabState.restoreTabState(getStateDirectory(), tabToRestore.id); } logExecutionTime("RestoreTabTime", time); restoreTab(tabToRestore, state, setAsActive); } catch (Exception e) { // Catch generic exception to prevent a corrupted state from crashing the app // at startup. Log.d(TAG, "loadTabs exception: " + e.toString(), e); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
From source file:eu.intermodalics.tango_ros_streamer.activities.RunningActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Log.e(TAG, "Uncaught exception of type " + e.getClass()); e.printStackTrace();//from ww w . j a v a2 s. c o m } }); // The following piece of code allows networking in main thread. // e.g. Restart Tango button calls a ROS service in UI thread. if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } mSharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); mRunLocalMaster = mSharedPref.getBoolean(getString(R.string.pref_master_is_local_key), false); mMasterUri = mSharedPref.getString(getString(R.string.pref_master_uri_key), getResources().getString(R.string.pref_master_uri_default)); mCreateNewMap = mSharedPref.getBoolean(getString(R.string.pref_create_new_map_key), false); String logFileName = mSharedPref.getString(getString(R.string.pref_log_file_key), getString(R.string.pref_log_file_default)); setupUI(); mLogger = new Logger(this, mLogTextView, TAGS_TO_LOG, logFileName, LOG_TEXT_MAX_LENGTH); }
From source file:itcr.gitsnes.MainActivity.java
/** Create a frame with the favorites games of the user * call moreliked GET method */// ww w . j a v a 2 s . co m public void getFavorites(MenuItem item) { /* Async mode*/ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); /* Build json*/ String input = new BackendHandler().getFavorites(); try { json_arr = new JSONArray(input); } catch (JSONException e) { Log.i(TAG, e.toString()); } /* Commit fragment transaction (master view)*/ RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback); rl.setBackgroundColor(Color.parseColor("#70d4b0")); authButton.setVisibility(View.INVISIBLE); MasterGames new_fragment = new MasterGames(json_arr); new_fragment.setQtype("all"); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.placeholder, new_fragment); transaction.addToBackStack(null); transaction.commit(); }
From source file:kr.wdream.ui.ChatActivity.java
public ChatActivity(Bundle args) { super(args);// w w w. j ava 2 s. com if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } }
From source file:ca.ramnansingh.randy.ibmwatsonspeechqa.AudioRecordTest.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Strictmode needed to run the http/wss request for devices > Gingerbread if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }// w w w. j a v a 2s.c o m //setContentView(R.layout.activity_main); setContentView(R.layout.activity_tab_text); ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); tabSTT = actionBar.newTab().setText("Speech to Text"); tabTTS = actionBar.newTab().setText("Text to Speech"); tabSTT.setTabListener(new MyTabListener(fragmentTabSTT)); tabTTS.setTabListener(new MyTabListener(fragmentTabTTS)); actionBar.addTab(tabSTT); actionBar.addTab(tabTTS); //actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0"))); }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
private void refreshSubreddits() { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); final ProgressDialog sdialog = ProgressDialog.show(SubredditSelectActivity.this, "Refreshing Subreddits", "One moment...", true); Thread t = new Thread() { public void run() { final int listLength; try { listLength = global.loadAccountSubreddits(); } catch (final RedditData.RedditApiException e) { e.printStackTrace();/*from w w w .j a v a 2 s . co m*/ runOnUiThread(new Runnable() { public void run() { sdialog.dismiss(); // check login required if (e.isAuthError()) global.mRedditData.initiateLogin(SubredditSelectActivity.this); // show error Toast.makeText(SubredditSelectActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } }); return; } runOnUiThread(new Runnable() { public void run() { sdialog.dismiss(); if (listLength == 0) { Toast.makeText(SubredditSelectActivity.this, "No subscriptions in your account, \nSuscribe to some subreddits", Toast.LENGTH_LONG).show(); } refreshSubredditsList(); } }); } }; t.start(); }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
private void refreshMultireddits() { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); final ProgressDialog sdialog = ProgressDialog.show(SubredditSelectActivity.this, "Refreshing Multis", "One moment...", true); Thread t = new Thread() { public void run() { final int listLength; try { listLength = global.loadAccountMultis(); } catch (final RedditData.RedditApiException e) { e.printStackTrace();/* www. j av a2 s .co m*/ runOnUiThread(new Runnable() { public void run() { sdialog.dismiss(); // check login required if (e.isAuthError()) global.mRedditData.initiateLogin(SubredditSelectActivity.this); // show error Toast.makeText(SubredditSelectActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } }); return; } runOnUiThread(new Runnable() { public void run() { sdialog.dismiss(); if (listLength == 0) { Toast.makeText(SubredditSelectActivity.this, "No multis in your account \nClick the add multi button to create some", Toast.LENGTH_LONG).show(); } mMultiAdapter.refreshMultis(); } }); } }; t.start(); }