List of usage examples for android.os StrictMode setThreadPolicy
public static void setThreadPolicy(final ThreadPolicy policy)
From source file:com.android.project.imagefetcher.Utils.java
@TargetApi(11) public static void enableStrictMode(Class<?> strictClass) { if (Utils.hasGingerbread()) { StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll() .penaltyLog();/* ww w .j av a 2 s. c om*/ StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll() .penaltyLog(); if (Utils.hasHoneycomb()) { threadPolicyBuilder.penaltyFlashScreen(); vmPolicyBuilder.setClassInstanceLimit(strictClass, 1).setClassInstanceLimit(strictClass, 1); } StrictMode.setThreadPolicy(threadPolicyBuilder.build()); StrictMode.setVmPolicy(vmPolicyBuilder.build()); } }
From source file:fi.loezi.unifud.MainActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); setContentView(R.layout.activity_main); pager = (ViewPager) findViewById(R.id.pager); final PagerAdapter pagerAdapter = new RestaurantListPagerAdapter(getSupportFragmentManager(), new ArrayList<Restaurant>()); pager.setAdapter(pagerAdapter);//from w w w. j a v a2s . c o m pager.setCurrentItem(MessiApiHelper.getDateOffset()); }
From source file:com.project.utilities.Utilities.java
/** * Sends post request to sepcified URL/*w w w . ja v a 2 s. c om*/ * @param valuePairs * @param postUrl * @return */ public static String postRequest(final List<BasicNameValuePair> valuePairs, final String postUrl) { String responseStr = null; StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); HttpClient httpclient = new DefaultHttpClient(); Log.e("POST_REQUEST", "ACTION LOGIN"); HttpPost httppost = new HttpPost(postUrl); try { // Add your data List<NameValuePair> postFields = new ArrayList<NameValuePair>(2); for (BasicNameValuePair nameValuePair : valuePairs) { postFields.add(nameValuePair); } httppost.setEntity(new UrlEncodedFormEntity(postFields)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); responseStr = EntityUtils.toString(response.getEntity()); Log.e("POST_REQUEST", "RESPONSE_CODE: " + response.getStatusLine().getStatusCode() + ""); } catch (ClientProtocolException e) { Log.e("ClientProtocolException", e.getMessage().toString()); } catch (IOException e) { Log.e("IOException", e.getMessage().toString()); } return responseStr; }
From source file:requester.ExchangeRequest.java
public ExchangeRequest() { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }
From source file:com.example.loise.saladmotor.JSONUseActivity.java
/** Called when the activity is first created. */ @Override/*from ww w.j a v a 2 s . c om*/ public void onCreate(Bundle savedInstanceState) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads().detectDiskWrites().detectNetwork() // StrictMode is most commonly used to catch accidental disk or network access on the application's main thread .penaltyLog().build()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_database_conn); //Toast.makeText(getApplicationContext(), license.buildbrand.co.ke.DecoderActivity.myTextView.getText().toString(), Toast.LENGTH_LONG).show(); tv = (TextView) findViewById(R.id.showresult); tvtop = (TextView) findViewById(R.id.textView3); etphone = (EditText) findViewById(R.id.editText2); etname = (EditText) findViewById(R.id.editText); etlocation = (EditText) findViewById(R.id.editText3); etamount = (EditText) findViewById(R.id.editText4); submit = (Button) findViewById(R.id.button3); phone = etphone.getText().toString(); name = etname.getText().toString(); location = etlocation.getText().toString(); amount = etamount.getText().toString(); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (etname.getText().toString().equals("") && etphone.getText().toString().equals("") && etlocation.getText().toString().equals("") && etamount.getText().toString().equals("")) { Toast.makeText(getApplicationContext(), "input filed", Toast.LENGTH_SHORT).show(); } else { ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); // define the parameter postParameters.add(new BasicNameValuePair("name", etname.getText().toString())); postParameters.add(new BasicNameValuePair("phone", etphone.getText().toString())); postParameters.add(new BasicNameValuePair("location", etlocation.getText().toString())); postParameters.add(new BasicNameValuePair("amount", etamount.getText().toString())); String response = null; // call executeHttpPost method passing necessary parameters try { response = CustomHttpClient.executeHttpPost( "http://10.0.2.2/saladmotor/insert.php", // your ip address if using localhost server postParameters); // store the result returned by PHP script that runs MySQL query String result = response.toString(); //parse json data try { returnString = ""; JSONArray jArray = null; jArray = new JSONArray(result); //JSONObject json_data = jArray.getJSONObject(i); for (int i = 0; i < jArray.length(); i++) { JSONObject json_data = jArray.getJSONObject(i); Log.i("log_tag", ",name: " + json_data.getString("name") + ",phone: " + json_data.getString("phone") + ",location: " + json_data.getString("location") + ",amount: " + json_data.getString("amount") ); //Get an output to the screen //return new JSONObject(json_data.substring(json_data.indexOf("{"), json_data.lastIndexOf("}") + 1)); returnString += "\n name: " + json_data.getString("name") + "\n\n phone: " + json_data.getString("phone") + "\n\nlocation: " + json_data.getString("location") + "\n\namount: " + json_data.getString("location"); } } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } try { tv.setText(returnString); if (tv.getText().toString() == "") { tv.setText("NOT FOUND ON THE DATABASE"); } } catch (Exception e) { Log.e("log_tag", "Error in Display!" + e.toString()); ; } // while ((line = reader.readLine()) != null){ // sb.append(line); // json = sb.toString().substring(0, sb.toString().length()-1); // } } catch (Exception e) { Log.e("log_tag", "Error in http connection!!" + e.toString()); } Toast.makeText(getApplicationContext(), "ordered", Toast.LENGTH_SHORT).show(); } } }); // define the action when user clicks on submit button }
From source file:com.example.topsongsapp.MainFragmentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main_fragment); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }/* w w w . ja v a 2s . c o m*/ // Check to see if we have retained the worker fragment. TransactionFragment mTransactionFragment = (TransactionFragment) getSupportFragmentManager() .findFragmentByTag("trans"); // If not retained (or first time running), we need to create it. if (mTransactionFragment == null) { mTransactionFragment = new TransactionFragment(); // Tell it who it is working with. FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(mTransactionFragment, "trans").commit(); } mTabHost = (SongsFragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); mTabHost.addTab(mTabHost.newTabSpec(TAB_A).setIndicator(TAB_A, getResources().getDrawable(R.drawable.ic_action_locate)), TopSongsList.class); mTabHost.addTab(mTabHost.newTabSpec(TAB_B).setIndicator(TAB_B, getResources().getDrawable(R.drawable.ic_action_star)), FavouritesFragment.class); if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); } }
From source file:net.giovannicapuano.galax.util.Utils.java
/** * Perform a HTTP POST request.//ww w .j a v a 2 s .c o m */ public static HttpData postData(String path, List<NameValuePair> post, Context context) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); HttpConnectionParams.setSoTimeout(httpParameters, 10000); int status = HttpStatus.SC_INTERNAL_SERVER_ERROR; String body = ""; HttpClient httpClient = new DefaultHttpClient(httpParameters); HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, new PersistentCookieStore(context)); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); try { HttpPost httpPost = new HttpPost(context.getString(R.string.server) + path); httpPost.setEntity(new UrlEncodedFormEntity(post)); HttpResponse response = httpClient.execute(httpPost, localContext); status = response.getStatusLine().getStatusCode(); body = EntityUtils.toString(response.getEntity()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return new HttpData(status, body); }
From source file:com.espian.ticktock.TickTockActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*www . j a v a 2 s.c om*/ if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().detectAll().penaltyFlashScreen().penaltyLog().build()); } mPagerAdapter = new TitleCursorPagerAdapter(this); (mPager = (ViewPager) findViewById(R.id.pager)).setAdapter(mPagerAdapter); getLoaderManager().initLoader(0, null, this); }
From source file:com.example.karspoolingapp.UpdateCarinfo.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.update_car_info); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); //String username = session.getUsername(); //EditText carModel = (EditText) findViewById(R.id.editText1); // carModel.setText(username); carName = (EditText) findViewById(R.id.editText1); carModel = (EditText) findViewById(R.id.editText2); licensePlateNo = (EditText) findViewById(R.id.editText3); carColor = (EditText) findViewById(R.id.editText4); seatingCapacity = (EditText) findViewById(R.id.editText5); JSONObject json = jsonParser.getJSONFromUrl(READ_COMMENTS_URL); try {//ww w . j a v a2 s. c om jsonCarDetails = json.getJSONArray("cardetails"); JSONObject c = jsonCarDetails.getJSONObject(0); String yusername = c.getString("username"); String ycarname = c.getString("carno"); String ycarmodel = c.getString("carmodel"); String ylicenseplateno = c.getString("licenseplateno"); String ycarcolor = c.getString("carcolor"); String yseatingcapacity = c.getString("seatingcapacity"); carName.setText(ycarname); carModel.setText(ycarmodel); licensePlateNo.setText(ylicenseplateno); carColor.setText(ycarcolor); seatingCapacity.setText(yseatingcapacity); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:otmobile.FirstScreen.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(null); setContentView(otmobile.R.layout.activity_first_screen); //License the Application CoreHelper.license(this); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); //Add a listener for the take picture FloatingActionButton takepicture = (FloatingActionButton) findViewById(R.id.floatingCamera); takepicture.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onTakePictureClick(v);/* www .j a v a 2s. c om*/ } }); //Settings FloatingActionButton settings = (FloatingActionButton) findViewById(R.id.floatSettings); settings.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onSettingsClick(v); } }); //Gallery FloatingActionButton gallery = (FloatingActionButton) findViewById(R.id.floatingGallery); gallery.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onGalleryClick(v); } }); mLayout = findViewById(R.id.firstscreenRL); }