List of usage examples for android.os StrictMode setThreadPolicy
public static void setThreadPolicy(final ThreadPolicy policy)
From source file:com.sythealth.fitness.util.Utils.java
@TargetApi(11) public static void enableStrictMode() { if (Utils.hasGingerbread()) { StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll() .penaltyLog();/*from w w w . j a v a 2 s .co m*/ StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll() .penaltyLog(); if (Utils.hasHoneycomb()) { threadPolicyBuilder.penaltyFlashScreen(); // vmPolicyBuilder // .setClassInstanceLimit(DailyArtWorkActivity.class, 1) // .setClassInstanceLimit(ImageDetailActivity.class, 1); } StrictMode.setThreadPolicy(threadPolicyBuilder.build()); StrictMode.setVmPolicy(vmPolicyBuilder.build()); } }
From source file:com.androzic.MainActivity.java
@SuppressLint({ "ShowToast", "NewApi" }) @Override//from w w w .j a v a2s . com protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.e(TAG, "onCreate()"); if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); application = Androzic.getApplication(); // check if called after crash if (!application.mapsInited) { restarting = true; startActivity(new Intent(this, Splash.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) .putExtras(getIntent())); finish(); return; } setContentView(R.layout.activity_main); mToolbar = (Toolbar) findViewById(R.id.action_toolbar); setSupportActionBar(mToolbar); mActionButton = (FloatingActionButton) findViewById(R.id.toolbar_action_button); backToast = Toast.makeText(this, R.string.backQuit, Toast.LENGTH_SHORT); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); onSharedPreferenceChanged(settings, getString(R.string.pref_exit)); onSharedPreferenceChanged(settings, getString(R.string.pref_hidestatusbar)); onSharedPreferenceChanged(settings, getString(R.string.pref_orientation)); settings.registerOnSharedPreferenceChangeListener(this); mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerItems = new ArrayList<>(); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerAdapter = new DrawerAdapter(this, mDrawerItems); mDrawerList.setAdapter(mDrawerAdapter); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); initializeDrawerItems(); mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mHomeDrawable = getDrawerToggleDelegate().getThemeUpIndicator(); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View drawerView) { if (drawerView == mDrawerList) { getSupportActionBar().setTitle(mTitle); supportInvalidateOptionsMenu(); } } public void onDrawerOpened(View drawerView) { if (drawerView == mDrawerList) { getSupportActionBar().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); } } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportFragmentManager().addOnBackStackChangedListener(mBackStackChangedListener); if (savedInstanceState == null) { mDrawerAdapter.setSelectedItem(-1); selectItem(0); } }
From source file:com.vsmartcard.acardemulator.SimulatorService.java
@Override public void onCreate() { super.onCreate(); Log.d("", "Begin transaction"); if (useVPCD) { if (socket == null) { try { if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }// www . j av a 2s . c o m vpcdConnect(); sendPowerOn(); } catch (IOException e) { e.printStackTrace(); vpcdDisconnect(); } } } else { if (simulator == null) createSimulator(); } }
From source file:com.z.stproperty.PropertyDetail.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a2 s. c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pdetail); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } try { pripertyDetail = (HashMap<String, String>) getIntent().getExtras().get("propertyDetail"); title = pripertyDetail.get("title"); propertyId = pripertyDetail.get("pID"); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mPrefs.edit().putString("propertyId", propertyId).commit(); dialog = ProgressDialog.show(PropertyDetail.this, "", "Loading. Please wait...", true); checkUpdate(); ((Button) findViewById(R.id.ShareIcon)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), ShareContent.class); startActivityForResult(intent, Constants.REQUEST_SHARE); } }); trimCache(); } catch (Exception e) { Log.e(this.getClass().getSimpleName(), e.getLocalizedMessage(), e); } }
From source file:org.adblockplus.android.ProxyService.java
@SuppressLint("NewApi") @Override// www .ja va2s .c om public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { // Proxy is running in separate thread, it's just some resolution request during initialization. // Not worth spawning a separate thread for this. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build(); StrictMode.setThreadPolicy(policy); } // Get port for local proxy SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Resources resources = getResources(); // Try to read user proxy settings String proxyHost = null; String proxyPort = null; String proxyExcl = null; String proxyUser = null; String proxyPass = null; if (NATIVE_PROXY_SUPPORTED) { // Read system settings proxyHost = System.getProperty("http.proxyHost"); proxyPort = System.getProperty("http.proxyPort"); proxyExcl = System.getProperty("http.nonProxyHosts"); Log.d(TAG, "PRX: " + proxyHost + ":" + proxyPort + "(" + proxyExcl + ")"); // not used but left for future reference String[] px = ProxySettings.getUserProxy(getApplicationContext()); if (px != null) Log.d(TAG, "PRX: " + px[0] + ":" + px[1] + "(" + px[2] + ")"); } else { // Read application settings proxyHost = prefs.getString(getString(R.string.pref_proxyhost), null); proxyPort = prefs.getString(getString(R.string.pref_proxyport), null); proxyUser = prefs.getString(getString(R.string.pref_proxyuser), null); proxyPass = prefs.getString(getString(R.string.pref_proxypass), null); } // Check for root privileges and try to install transparent proxy if (RootTools.isAccessGiven()) { try { initIptables(); StringBuffer cmd = new StringBuffer(); int uid = getPackageManager().getPackageInfo(getPackageName(), 0).applicationInfo.uid; cmd.append(iptables); cmd.append(IPTABLES_RETURN.replace("{{UID}}", String.valueOf(uid))); String rules = cmd.toString(); RootTools.sendShell(rules, DEFAULT_TIMEOUT); transparent = true; } catch (FileNotFoundException e) { // ignore - this is "normal" case } catch (NameNotFoundException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (IOException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (RootToolsException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (TimeoutException e) { Log.e(TAG, "Failed to initialize iptables", e); } } if (!transparent) { // Try to set native proxy nativeProxyAutoConfigured = ProxySettings.setConnectionProxy(getApplicationContext(), LOCALHOST, port, ""); if (NATIVE_PROXY_SUPPORTED) { registerReceiver(connectionReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); registerReceiver(connectionReceiver, new IntentFilter(Proxy.PROXY_CHANGE_ACTION)); } } // Save current native proxy situation. The service is always started on the first run so // we will always have a correct value from the box SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(getString(R.string.pref_proxyautoconfigured), transparent || nativeProxyAutoConfigured); editor.commit(); registerReceiver(proxyReceiver, new IntentFilter(ProxyService.BROADCAST_PROXY_FAILED)); registerReceiver(filterReceiver, new IntentFilter(AdblockPlus.BROADCAST_FILTERING_CHANGE)); registerReceiver(filterReceiver, new IntentFilter(AdblockPlus.BROADCAST_FILTER_MATCHES)); // Start proxy if (proxy == null) { // Select available port and bind to it, use previously selected port by default portVariants[0] = prefs.getInt(getString(R.string.pref_lastport), -1); ServerSocket listen = null; String msg = null; for (int p : portVariants) { if (p < 0) continue; try { listen = new ServerSocket(p, 1024); port = p; break; } catch (IOException e) { Log.e(TAG, null, e); msg = e.getMessage(); } } if (listen == null) { sendBroadcast(new Intent(BROADCAST_PROXY_FAILED).putExtra("msg", msg)); return; } // Save selected port editor.putInt(getString(R.string.pref_lastport), port); editor.commit(); // Initialize proxy proxyConfiguration.put("handler", "main"); proxyConfiguration.put("main.prefix", ""); proxyConfiguration.put("main.class", "sunlabs.brazil.server.ChainHandler"); if (transparent) { proxyConfiguration.put("main.handlers", "urlmodifier adblock"); proxyConfiguration.put("urlmodifier.class", "org.adblockplus.brazil.TransparentProxyHandler"); } else { proxyConfiguration.put("main.handlers", "https adblock"); proxyConfiguration.put("https.class", "org.adblockplus.brazil.SSLConnectionHandler"); } proxyConfiguration.put("adblock.class", "org.adblockplus.brazil.RequestHandler"); if (logRequests) proxyConfiguration.put("adblock.proxylog", "yes"); configureUserProxy(proxyConfiguration, proxyHost, proxyPort, proxyExcl, proxyUser, proxyPass); proxy = new ProxyServer(); proxy.logLevel = Server.LOG_DIAGNOSTIC; proxy.setup(listen, proxyConfiguration.getProperty("handler"), proxyConfiguration); proxy.start(); } if (transparent) { // Redirect traffic via iptables try { StringBuffer cmd = new StringBuffer(); cmd.append(iptables); cmd.append(IPTABLES_ADD_HTTP.replace("{{PORT}}", String.valueOf(port))); String rules = cmd.toString(); RootTools.sendShell(rules, DEFAULT_TIMEOUT); } catch (FileNotFoundException e) { // ignore - this is "normal" case } catch (IOException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (RootToolsException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (TimeoutException e) { Log.e(TAG, "Failed to initialize iptables", e); } } prefs.registerOnSharedPreferenceChangeListener(this); // Lock service hideIcon = prefs.getBoolean(getString(R.string.pref_hideicon), resources.getBoolean(R.bool.def_hideicon)); startForeground(ONGOING_NOTIFICATION_ID, getNotification()); // If automatic setting of proxy was blocked, check if user has set it manually boolean manual = isManual(); if (manual && NATIVE_PROXY_SUPPORTED) { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); updateNoTrafficCheck(connectivityManager); } sendStateChangedBroadcast(); Log.i(TAG, "Service started"); }
From source file:com.example.transfer.MainActivity.java
@SuppressLint("NewApi") @Override//from ww w . j a v a 2 s .c om protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } // Get handles to the UI view objects mLatLng = (TextView) findViewById(R.id.lat_lng); mAddress = (TextView) findViewById(R.id.address); mActivityIndicator = (ProgressBar) findViewById(R.id.address_progress); mConnectionState = (TextView) findViewById(R.id.text_connection_state); mConnectionStatus = (TextView) findViewById(R.id.text_connection_status); // Create a new global location parameters object mLocationRequest = LocationRequest.create(); progressBar = (ProgressBar) findViewById(R.id.progressBar1); new Thread(new Runnable() { public void run() { while (progressStatus < 100) { progressStatus += 1; // Update the progress bar and display the current value in // the text view handler.post(new Runnable() { public void run() { progressBar.setProgress(progressStatus); // textView.setText(progressStatus+"/"+progressBar.getMax()); } }); try { // Sleep for 200 milliseconds. Just to display the // progress slowly Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); /* * b = new Thread(new Runnable() { public void run() { while * (progressStatus < 100) { // progressStatus += 1; // Update the * progress bar and display the current value in // the text view * handler.post(new Runnable() { public void run() { * progressBar.setProgress(progressStatus); // * textView.setText(progressStatus+"/"+progressBar.getMax()); } }); // * try { // // Sleep for 200 milliseconds. Just to display the // * progress slowly // Thread.sleep(200); // } catch * (InterruptedException e) { // e.printStackTrace(); // } } } }); */ /* * Set the update interval */ mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS); // Use high accuracy mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Set the interval ceiling to one minute mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS); // Note that location updates are off until the user turns them on mUpdatesRequested = false; // Open Shared Preferences mPrefs = getSharedPreferences(LocationUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE); // Get an editor mEditor = mPrefs.edit(); /* * Create a new location client, using the enclosing class to handle * callbacks. */ mLocationClient = new LocationClient(this, this, this); ImageButton myB = (ImageButton) findViewById(R.id.bgImage); myB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gps = new GPSTracker(MainActivity.this); if (gps.canGetLocation()) { // \n is for new line // Toast.makeText(getApplicationContext(), // "Your Location is - \nLat: " + latitude + "\nLong: " + // longitude, Toast.LENGTH_LONG).show(); } else { // can't get location // GPS or Network is not enabled // Ask user to enable GPS/network in settings gps.showSettingsAlert(); } String district = null; String address = null; String lat = null; String log = null; // If Google Play Services is available if (servicesConnected()) { startPeriodicUpdates(); try { a.start(); Thread.sleep(5000); } catch (Exception e) { } // Get the current location Location currentLocation = mLocationClient.getLastLocation(); /* * Thread d = new Thread() { public void run() { * * } }; */ try { // Display the current location in the UI Log.i("i", LocationUtils.getLatLng(v.getContext(), currentLocation)); String[] curloc = LocationUtils.getLatLng(v.getContext(), currentLocation).split(","); String url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + curloc[0].trim() + "," + curloc[1].trim() + "&sensor=true&language=zh-TW"; lat = curloc[0].trim(); log = curloc[1].trim(); // progressBar.setProgress(50); JSONParser jsp = new JSONParser(); Log.i("hihihi", "Helloken http://maps.googleapis.com/maps/api/geocode/json?latlng=" + curloc[0].trim() + "," + curloc[1].trim() + "&sensor=true"); JSONObject obj = jsp.getJSONFromUrl(url); // TextView tw = (TextView) findViewById(R.id.address); mAddress.setText( obj.getJSONArray("results").getJSONObject(0).getString("formatted_address")); address = obj.getJSONArray("results").getJSONObject(0).getString("formatted_address"); JSONArray result = obj.getJSONArray("results"); for (int i = 0; result.getJSONObject(i) != null; i++) { JSONObject jo = result.getJSONObject(i); JSONArray a = jo.getJSONArray("address_components"); for (int x = 0; x < a.length(); x++) { JSONObject b = a.getJSONObject(x); if (b.getString("long_name").contains("?")) { mAddress.setText(mAddress.getText() + b.getString("long_name")); Log.i("i", "HelloKen " + b.getString("long_name")); district = b.getString("long_name"); } } if (district != null) break; } } catch (Exception e) { Log.i("i", "i error" + e.getMessage()); } finally { String districtTemp = null; String myDistrict = null; String districtAirPol = null; try { DBHelper dbh = new DBHelper(v.getContext()); Cursor c = dbh.getDistricts(); // get weather WeatherRSSpaser wrss = new WeatherRSSpaser( "http://rss.weather.gov.hk/rss/CurrentWeather_uc.xml"); wrss.readRSS(); String str = wrss.getResult().get(0); String disfromrss = "nothing"; String tempfromrss = ""; // System.out.println(str); String[] tdstr = str.split("<tr>"); for (int count = 0; count < tdstr.length; count++) { // progressStatus += 1; int s = tdstr[count].indexOf("<td>") + 4; int e = tdstr[count].indexOf("</td>"); if (s > 0 && e > 0) { Log.i("log", "->[" + tdstr[count].substring(s, e) + "]"); disfromrss = obserlocationToDistrict(tdstr[count].substring(s, e)); } s = tdstr[count].indexOf("<td width=\"100\" align=\"right\">") + 30; e = tdstr[count].indexOf("</SPAN>"); if (s > 0 && e > 0) tempfromrss = tdstr[count].substring(s, e); if (disfromrss.equals(district)) { mAddress.setText(mAddress.getText() + disfromrss + tempfromrss + "\n"); districtTemp = tempfromrss; } } // weather index ArrayList<String> al; RSSpaser rssp = new RSSpaser( "http://www.aqhi.gov.hk/epd/ddata/html/out/aqhi_ind_rss_ChT.xml"); rssp.readRSS(); al = rssp.getResult(); for (int cc = 0; cc < al.size(); cc++) { // if(al.get(cc).contains(district)) mAddress.setText(mAddress.getText() + al.get(cc) + "\n"); } while (c.moveToNext()) { Log.i("i", "HelloKen" + c.getString(c.getColumnIndex("DISTRICT"))); String temp = c.getString(c.getColumnIndex("DISTRICT")); // mAddress.setText(mAddress.getText() + // "your text here"+disfromrss + tempfromrss); if (temp.equals("TAI PO") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("SHA TIN") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("SOUTHERN") && district.equals("??")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("NORTH") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("YAU TSIM MONG") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("TUEN MUN") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("SAI KUNG") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("ISLANDS") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("KWAI TSING") && district.equals("??")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("YUEN LONG") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("TSUEN WAN") && district.equals("???")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("CENTRAL & WESTERN") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("WAN CHAI") && district.equals("??")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("KOWLOON CITY") && district.equals("???")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("WONG TAI SIN") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("KWUN TONG") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("SHAM SHUI PO") && district.equals("?")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } if (temp.equals("EASTERN") && district.equals("??")) { mAddress.setText( mAddress.getText() + c.getString(c.getColumnIndex("CHINAME")) + "\n"); } } dbh.close(); WeatherDescRSSpaser wdr = new WeatherDescRSSpaser(); wdr.readRSS(); stopPeriodicUpdates(); Intent i = new Intent(v.getContext(), GovActivity.class); i.putExtra("weather", wdr.getResult()); i.putExtra("lat", lat); i.putExtra("log", log); i.putExtra("temp", districtTemp); i.putExtra("district", district); i.putExtra("address", address); startActivity(i); } catch (Exception e) { // TODO Auto-generated catch block Log.i("i", "HelloKen " + e.getMessage());// .getMessage()); } } } } }); }
From source file:tv.piratemedia.lightcontroler.controller.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_controller); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); drawer = (DrawerFrameLayout) findViewById(R.id.drawer); setupApp();//from w ww .j a v a2 s . c om mHandler = new MyHandler(); Controller = new controlCommands(this, mHandler); ctx = this; Intent i = new Intent(this, notificationService.class); i.setAction(notificationService.START_SERVICE); this.startService(i); if (Build.VERSION.SDK_INT == 22) { //getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark)); drawer.setStatusBarBackgroundColor(getResources().getColor(R.color.colorPrimaryDark)); } drawer.setStatusBarBackgroundColor(getResources().getColor(R.color.colorPrimaryDark)); appState = new SaveState(this); Utils = new utils(this); new DataLayerListenerService(); //Call Pebble sender, get it to check if pebble is connceted and send up light states //Todo need to rethink this as pebble app only gets communication if its running. So maybe detect if app is running, then send? or when app becomes active, send if (prefs.getBoolean("pref_pebble", false)) { Log.d("Controller", "Pebble pref is active, lets start the app up"); new pebbleSender(ctx).initialConnect(Controller); new pebbleSender(ctx).sendZoneNames(); } else { //TODO add this functionality so the broadcast listener for pebble stops (pebbleReceiver) so we dont have it running in background listening for things Log.d("Controller", "Pebble prefs is inactive. Lets shut down the listener service so its not running anymore"); } }
From source file:ca.ualberta.cmput301f12t05.ufill.Webservicer.java
/** * Consumes the POST/Insert operation of the service * //from w w w . j a va 2s . com * @return Sourcer Id of placed bin * @throws Exception */ public String insertBin(CrowdSourcerBin SBin) throws Exception { List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>(); nvps.add(new BasicNameValuePair("action", "post")); nvps.add(new BasicNameValuePair("summary", (SBin.getcontent()).getTitle())); nvps.add(new BasicNameValuePair("content", gson.toJson(SBin.getcontent()))); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); //System.out.println(httpPost); HttpResponse response = httpclient.execute(httpPost); String status = response.getStatusLine().toString(); HttpEntity entity = response.getEntity(); System.out.println(status); CrowdSourcerBin newBin = null; if (entity != null) { InputStream is = entity.getContent(); String jsonStringVersion = convertStreamToString(is); Type BinType = CrowdSourcerBin.class; newBin = gson.fromJson(jsonStringVersion, BinType); System.out.println(newBin); } entity.consumeContent(); return newBin.getId(); }
From source file:org.spinsuite.sync.SyncDataTask.java
/** * /*from ww w .j a v a 2 s .c o m*/ * *** Constructor *** * @author Carlos Parada, cparada@erpcya.com, ERPCyA http://www.erpcya.com * @contributor Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com * <li>Get URL SOAP from Context * @param p_ctx * @param p_SPS_SyncMenu_ID * @param p_IsForced * @param p_IsDeleteBefore */ public SyncDataTask(Context p_ctx, int p_SPS_SyncMenu_ID, boolean p_IsForced, boolean p_IsDeleteBefore) { m_ctx = p_ctx; m_SPS_SyncMenu_ID = p_SPS_SyncMenu_ID; m_IsForced = p_IsForced; m_IsDeleteBefore = p_IsDeleteBefore; if (m_IsDeleteBefore) { m_IsForced = m_IsDeleteBefore; } StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); m_NFManager = (NotificationManager) m_ctx.getSystemService(Context.NOTIFICATION_SERVICE); m_Builder = new NotificationCompat.Builder(m_ctx); // Set URL m_URL = Env.getContext("#SUrlSoap"); // bgTask = new BackGroundTask(this, m_ctx); bgTask.runTask(); }
From source file:org.opensilk.music.MusicApp.java
protected void enableStrictMode() { if (DEBUG) {/*from w w w .ja va 2 s . com*/ final StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder() .detectAll().penaltyLog().penaltyFlashScreen(); StrictMode.setThreadPolicy(threadPolicyBuilder.build()); final StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll() .penaltyLog().setClassInstanceLimit(MediaCastManager.class, 1) .setClassInstanceLimit(BitmapDiskLruCache.class, 1) .setClassInstanceLimit(ArtworkLruCache.class, 1) .setClassInstanceLimit(LauncherActivity.class, 1) .setClassInstanceLimit(ArtworkRequestManagerImpl.class, 1); StrictMode.setVmPolicy(vmPolicyBuilder.build()); } }