List of usage examples for android.os StrictMode setThreadPolicy
public static void setThreadPolicy(final ThreadPolicy policy)
From source file:com.example.michael.bumpy.EditDetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_details); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); if (Driver.getInstance().getId() != "") { try {// www . j a v a 2s . co m ((ImageButton) findViewById(R.id.addCarLicensePhoto)).setImageBitmap(Globals .GetImageFromURL("user/" + Driver.getInstance().getId() + "/pic/filescarLicense.jpeg")); ((ImageButton) findViewById(R.id.addDrivingLicensePhoto)).setImageBitmap(Globals .GetImageFromURL("user/" + Driver.getInstance().getId() + "/pic/filesdrivingLicense.jpeg")); ((ImageButton) findViewById(R.id.addCarInsurancePhoto)).setImageBitmap(Globals .GetImageFromURL("user/" + Driver.getInstance().getId() + "/pic/filescarInsurance.jpeg")); String jsonData = Globals.GetDataFromServer("users/" + Driver.getInstance().getId()); JSONObject obj = null; try { obj = new JSONObject(jsonData).getJSONObject("message"); Driver.getInstance().setPhone(obj.getString("phone")); Driver.getInstance().setEmail(obj.getString("email")); Driver.getInstance().setName(obj.getString("name")); } catch (JSONException e) { e.printStackTrace(); } ((EditText) findViewById(R.id.emailVal)).setText(Driver.getInstance().getEmail()); ((EditText) findViewById(R.id.nameVal)).setText(Driver.getInstance().getName()); ((EditText) findViewById(R.id.phoneVal)).setText(Driver.getInstance().getPhone()); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.android.mail.ui.AbstractMailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (STRICT_MODE) { StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems .penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().build()); }/*w w w .j av a 2 s .c om*/ super.onCreate(savedInstanceState); mUiHandler.setEnabled(true); }
From source file:air.com.snagfilms.utils.Utils.java
@TargetApi(VERSION_CODES.HONEYCOMB) public static void enableStrictMode() { if (Utils.hasGingerbread()) { StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll() .penaltyLog();/* w ww .j a va 2 s . c o m*/ StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll() .penaltyLog(); if (Utils.hasHoneycomb()) { threadPolicyBuilder.penaltyFlashScreen(); /* * vmPolicyBuilder * .setClassInstanceLimit(ImageGridActivity.class, 1) * .setClassInstanceLimit(ImageDetailActivity.class, 1); */ } StrictMode.setThreadPolicy(threadPolicyBuilder.build()); StrictMode.setVmPolicy(vmPolicyBuilder.build()); } }
From source file:com.worklight.poc.Pull.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pull); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); _Pull = this; new NetnServerCheck(_Pull).execute(); img = (ImageView) findViewById(R.id.imageView1); buttonConnect = (Button) findViewById(R.id.buttonConnect); buttonInvoke = (Button) findViewById(R.id.buttonInvoke); textView = (TextView) findViewById(R.id.textView); textViewbottom = (TextView) findViewById(R.id.textViewbottom); final WLClient client = WLClient.createInstance(this); buttonConnect.setOnClickListener(new OnClickListener() { @Override// w ww .j a v a2s .c o m public void onClick(View v) { updateTextView("Connecting..."); Utility.setPrefData("login", "false", _Pull); client.connect(new PullConnectListener()); } }); buttonInvoke.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getCatalog(_Pull); } }); }
From source file:com.swetha.easypark.GoogleDirectionsActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mapdirections); 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()); Log.i("GoogleDirectionsActivity", "Inside Oncreate"); Intent theIntent = getIntent();//from w w w . j ava 2s . com tolat = theIntent.getDoubleExtra(GetParkingLots.LATITUDE, Constants.doubleDefaultValue); tolng = theIntent.getDoubleExtra(GetParkingLots.LONGITUDE, Constants.doubleDefaultValue); toPosition = new LatLng(tolat, tolng); Log.i("GoogleDirectionsActivity", "After Setting tolat, tolng, toPosition" + tolat + "\n" + tolng + "\n" + toPosition); md = new GetDirections(); Log.i("GoogleDirectionsActivity", "After calling GetDirctions constructor"); FragmentManager fm = getSupportFragmentManager(); Log.i("GoogleDirectionsActivity", "After creating fragmentManager" + fm); SupportMapFragment supportMapfragment = ((SupportMapFragment) fm.findFragmentById(R.id.drivingdirections)); Log.i("GoogleDirectionsActivity", "After creating SupportMapFragment" + supportMapfragment); mMap = supportMapfragment.getMap(); Log.i("GoogleDirectionsActivity", "After getting map"); mMap.setMyLocationEnabled(true); Log.i("GoogleDirectionsActivity", "After setMyLocationEnabled"); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Log.i("GoogleDirectionsActivity", "After locationManager"); Criteria criteria = new Criteria(); // Getting the name of the provider that meets the criteria provider = locationManager.getBestProvider(criteria, true); if (provider != null && !provider.equals("")) { // Get the location from the given provider location = locationManager.getLastKnownLocation(provider); locationManager.requestLocationUpdates(provider, 500, 1, GoogleDirectionsActivity.this); if (location != null) { fromlat = location.getLatitude(); fromlng = location.getLongitude(); } else { fromlat = GetParkingLots.latitude; fromlng = GetParkingLots.longitude; } } else { Toast.makeText(getBaseContext(), "No Provider Found", Toast.LENGTH_SHORT).show(); finish(); } Log.e("GoogleDirectionsActivity", "After setting location"); fromPosition = new LatLng(fromlat, fromlng); LatLng coordinates = new LatLng(fromlat, fromlng); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 16)); mMap.addMarker(new MarkerOptions().position(fromPosition).title("Start")); mMap.addMarker(new MarkerOptions().position(toPosition).title("End")); Document doc = md.getDocument(fromPosition, toPosition, Constants.MODE_DRIVING); String duration = md.getDurationText(doc); tv_duration = (TextView) findViewById(R.id.tv_time); tv_duration.setText("Estimated driving time:" + duration); ArrayList<LatLng> directionPoint = md.getDirection(doc); PolylineOptions rectLine = new PolylineOptions().width(6).color(Color.RED); for (int i = 0; i < directionPoint.size(); i++) { rectLine.add(directionPoint.get(i)); } mMap.addPolyline(rectLine); }
From source file:com.example.hbranciforte.trafficclient.DataTraffic.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_data_traffic); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }// w ww .ja va 2 s . c o m try { zone_info = new JSONObject((String) getIntent().getSerializableExtra("zone_info")); } catch (JSONException e) { e.printStackTrace(); } EditText ed_fichas = (EditText) findViewById(R.id.fichas); ed_fichas.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { //float price = (float) 0.0; Integer time = 0; TextView txtvalor = (TextView) findViewById(R.id.valor); TextView txttiempo = (TextView) findViewById(R.id.txtTime); if (s.toString() != "") { try { price = (float) zone_info.getDouble("unit_price") * Float.valueOf(s.toString()); time = zone_info.getInt("unit_time") * Integer.parseInt(s.toString()); txtvalor.setText("$ ".concat(Float.toString(price))); txttiempo.setText(time.toString().concat(" min")); } catch (Exception e) { Log.e("getting data0:", e.getMessage()); txttiempo.setText("0 min"); txtvalor.setText("$ 0.0"); } } } }); }
From source file:com.commonsware.cwac.loaderex.demo.ConstantsBrowserACL.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); setContentView(R.layout.main);// ww w . j av a 2 s. co m db = new DatabaseHelper(this); adapter = new SimpleCursorAdapter(this, R.layout.row, null, new String[] { DatabaseHelper.TITLE, DatabaseHelper.VALUE }, new int[] { R.id.title, R.id.value }); ListView lv = (ListView) findViewById(R.id.constants); lv.setAdapter(adapter); registerForContextMenu(lv); getSupportLoaderManager().initLoader(0, null, this); }
From source file:com.example.qrpoll.Poll.java
/** * Konstruktor,Przetwarzanie danych zawartych w formacie JSON, laczenie pytan z odpowiedziami * @param address adres strony z ktorej chcemy pobrac dane * @param context/* w ww.j a v a2 s .co m*/ * @throws JSONException */ public Poll(String address, Context context) throws JSONException { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); this.address = address; this.context = context; String full_address = address + "api/info"; String s = ""; try { s = MyHttpURLConnection.get(full_address); } catch (Exception404 e) { System.out.println("404!"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONArray array; JSONObject jo; JSONObject jo_inside; try { array = new JSONArray(s); jo = array.getJSONObject(0); jo_inside = jo.getJSONObject("info"); this.hash_id = jo_inside.get("hash_id").toString(); this.subject = jo_inside.get("subject").toString(); this.room = jo_inside.get("room").toString(); this.start_date = jo_inside.get("time").toString(); } catch (JSONException e) { e.printStackTrace(); } full_address = address + "api/version"; try { s = MyHttpURLConnection.get(full_address); } catch (Exception404 e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } Log.d("moje", s); array = new JSONArray(s); jo = array.getJSONObject(0); version = Integer.parseInt(jo.get("version").toString()); full_address = address + "api/questions"; try { s = MyHttpURLConnection.get(full_address); } catch (Exception404 e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } array = new JSONArray(s); String pk, question_text; question_map = new HashMap<String, Question>(); for (int i = 0; i < array.length(); i++) { jo = array.getJSONObject(i); pk = jo.get("pk").toString(); jo_inside = jo.getJSONObject("fields"); question_text = jo_inside.get("question_text").toString(); String rating = jo_inside.get("isRating").toString(); String max = jo_inside.get("question_choices_max").toString(); if (rating.equals("false")) { question_map.put(pk, new Question(pk, question_text, rating, max)); } else { ratingID = Integer.parseInt(pk); } } full_address = address + "api/choices"; try { s = MyHttpURLConnection.get(full_address); } catch (Exception404 e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } array = new JSONArray(s); String question_pk, choice_text; int votes; for (int i = 0; i < array.length(); i++) { jo = array.getJSONObject(i); pk = jo.get("pk").toString(); jo_inside = jo.getJSONObject("fields"); question_pk = jo_inside.get("question").toString(); choice_text = jo_inside.get("choice_text").toString(); if (!question_pk.equals(ratingID + "")) { question_map.get(question_pk).addChoice(pk, choice_text); } else { ratingquestions.add(pk); } } }
From source file:com.commonsware.android.strict.WeatherDemo.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main);/* w w w . j av a2 s .c o m*/ StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); mgr = (LocationManager) getSystemService(LOCATION_SERVICE); format = getString(R.string.url); browser = (WebView) findViewById(R.id.webkit); client = new DefaultHttpClient(); }
From source file:be.ehb.fallwear.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (DEVELOPER_MODE) { StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems .penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); }// ww w. j a v a2 s. c o m super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); mBtnReg = (Button) findViewById(R.id.btnReg); mBtnUnReg = (Button) findViewById(R.id.bntUnReg); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mRegistrationProgressBar.setVisibility(ProgressBar.GONE); mBtnReg.setVisibility(View.GONE); mBtnUnReg.setVisibility(View.VISIBLE); mBtnReg.setEnabled(true); mInformationTextView.setVisibility(View.VISIBLE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); String token = sharedPreferences.getString(QuickstartPreferences.TOKEN, "00"); if (sentToken) { String message = getResources().getString(R.string.gcm_send_message); mInformationTextView.setText(String.format(message, token)); } else { mInformationTextView.setText(getString(R.string.token_error_message)); } } }; mUnRegisterBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mRegistrationProgressBar.setVisibility(ProgressBar.GONE); mInformationTextView.setVisibility(View.VISIBLE); mBtnReg.setVisibility(View.VISIBLE); mBtnUnReg.setVisibility(View.GONE); mBtnUnReg.setEnabled(true); mInformationTextView.setText(R.string.unregistered); } }; mInformationTextView = (TextView) findViewById(R.id.informationTextView); }