Example usage for android.os StrictMode setThreadPolicy

List of usage examples for android.os StrictMode setThreadPolicy

Introduction

In this page you can find the example usage for android.os StrictMode setThreadPolicy.

Prototype

public static void setThreadPolicy(final ThreadPolicy policy) 

Source Link

Document

Sets the policy for what actions on the current thread should be detected, as well as the penalty if such actions occur.

Usage

From source file:org.madebcn.android.compass.CompassActivity.java

/** Called when the activity is first created. */
@Override/* w  w  w  .j a v a  2  s . c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    // Get an instance of the SensorManager
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    // Get an instance of the PowerManager
    mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);

    // Get an instance of the WindowManager

    // Create a bright wake lock
    mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass().getName());

    // instantiate our simulation view and set it as the activity's content
    mSimulationView = new SimulationView(this);
    setContentView(R.layout.main);

    angleField = (TextView) findViewById(R.id.textView2);
    serverField = (EditText) findViewById(R.id.editText1); //editText1
    switchButton = (Switch) findViewById(R.id.switch1); //Switch1
    setangleButton = (Button) findViewById(R.id.button2);//button2
    statusField = (TextView) findViewById(R.id.textView3); //textview3

}

From source file:au.com.wallaceit.reddinator.Rservice.java

public ListRemoteViewsFactory(Context context, Intent intent) {
    this.mContext = context;
    appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
            AppWidgetManager.INVALID_APPWIDGET_ID);
    global = ((GlobalObjects) context.getApplicationContext());
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    //System.out.println("New view factory created for widget ID:"+appWidgetId);
    // Set thread network policy to prevent network on main thread exceptions.
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    // if this is a user request (apart from 'loadmore') or an auto update, do not attempt to load cache.
    // when a user clicks load more and a new view factory needs to be created we don't want to bypass cache, we want to load the cached items
    int loadType = global.getLoadType();
    if (!global.getBypassCache() || loadType == GlobalObjects.LOADTYPE_LOADMORE) {
        // load cached data
        data = global.getFeed(mSharedPreferences, appWidgetId);
        if (data.length() != 0) {
            titleFontSize = mSharedPreferences.getString(context.getString(R.string.widget_theme_pref), "16");
            try {
                lastItemId = data.getJSONObject(data.length() - 1).getJSONObject("data").getString("name");
            } catch (JSONException e) {
                lastItemId = "0"; // Could not get last item ID; perform a reload next time and show error view :(
                e.printStackTrace();/*from   w w w  .j  a  va 2 s.  c o m*/
            }
            if (loadType == GlobalObjects.LOADTYPE_LOAD) {
                loadCached = true; // this isn't a loadmore request, the cache is loaded and we're done
                //System.out.println("Cache loaded, no user request received.");
            }
        } else {
            loadReddits(false); // No feed items; do a reload.
        }
    } else {
        data = new JSONArray(); // set empty data to prevent any NPE
    }
}

From source file:ca.ualberta.cmput301f12t05.ufill.Webservicer.java

/**
 * Consumes the LIST operation of the service
 * //w  w  w. j  a v  a 2 s .c  om
 * @return JSON representation of the Bin list
 * @throws Exception
 */
public String listBins() throws Exception {

    String jsonStringVersion = new String();
    List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
    nvps.add(new BasicNameValuePair("action", "list"));
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    httpPost.setEntity(new UrlEncodedFormEntity(nvps));
    HttpResponse response = httpclient.execute(httpPost);

    String status = response.getStatusLine().toString();
    HttpEntity entity = response.getEntity();

    System.out.println(status);

    if (entity != null) {
        InputStream is = entity.getContent();
        jsonStringVersion = convertStreamToString(is);
    }

    // and ensure it is fully consumed
    entity.consumeContent();
    return jsonStringVersion;
}

From source file:com.almunt.jgcaap.systemupdater.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//  ww  w. j  av  a  2  s .c  o m
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    rv = (RecyclerView) findViewById(R.id.rv);
    llm = new LinearLayoutManager(this);
    rv.setLayoutManager(llm);
    rv.setAdapter(new RVAdapter(currentfiles));
    currentRomcardView = (CardView) findViewById(R.id.cardview1);
    currentRomTextView = (TextView) findViewById(R.id.text);
    currentRomTextView.setText(getOS());
    refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            RefreshLinks();
        }
    });
    SetupRecyclerViewClicks();
    RefreshLinks();
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.getMenu().getItem(0).setChecked(true);
}

From source file:com.bordengrammar.bordengrammarapp.MainActivity.java

@SuppressLint("AppCompatMethod")
@Override/*from w  w w.j  a v  a  2s . co  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setTranslucentStatus(true);
    }
    SystemBarTintManager tintManager = new SystemBarTintManager(this);
    tintManager.setStatusBarTintEnabled(true);
    tintManager.setStatusBarTintResource(R.color.bordenpurple);
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
    viewPager = (ViewPager) findViewById(R.id.pager);
    TabsPagerAdapter mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(mAdapter);
    tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    tabs.setViewPager(viewPager);
    tabs.setIndicatorColorResource(R.color.bordenyellow);
    tabs.setShouldExpand(true);
    tabs.setTextColorResource(R.color.white);

    actionBar = getActionBar();
    assert actionBar != null;
    actionBar.setHomeButtonEnabled(true);
    //actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);
    //for (String tab_name : tabs) {
    //   actionBar.addTab(actionBar.newTab().setText(tab_name)
    //         .setTabListener(this));
    //}
    //viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    //   @Override
    //   public void onPageSelected(int position) {
    //      actionBar.setSelectedNavigationItem(position);
    //
    //         }
    //         @Override
    //         public void onPageScrolled(int arg0, float arg1, int arg2) {
    //         }
    //         @Override
    //         public void onPageScrollStateChanged(int arg0) {
    //         }
    //      });

    FeedbackSettings feedbackSettings = new FeedbackSettings();
    feedbackSettings.setCancelButtonText("Cancel");
    feedbackSettings.setSendButtonText("Send");
    feedbackSettings.setText("Send feedback to improve the app");
    feedbackSettings.setTitle("Feedback");
    feedbackSettings.setToast("Thanks for your feedback");
    feedBack = new FeedbackDialog(this, "AF-186C1F794D93-1A", feedbackSettings);

    if (readPrefs("twitter").equals("error")) {
        //crouton
        Toast.makeText(this, "Error retreving tweets", Toast.LENGTH_LONG).show();
    }
    ParseAnalytics.trackAppOpened(getIntent());

}

From source file:com.savedollars.ProductShippingPriceDisplay.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    JSONData = (getIntent().getStringExtra("JsonData"));
    if (JSONData != null) {
        parseJsonData(JSONData);//w w  w  .ja v a  2  s .  c o  m
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pdtshippingpriceview);

    // Setting Product Name
    TextView productName = (TextView) findViewById(R.id.pdtNameTextView);
    productName.setText(pdtName);

    Iterator objMapIterator = sortedMap.entrySet().iterator();
    int rowIndex = 0;

    PDT_INFO = new String[totalCount][2];
    while (objMapIterator.hasNext()) {
        Map.Entry keyValuePairs = (Map.Entry) objMapIterator.next();
        String key = ProductTotalPriceDisplay.merchantNames[rowIndex];

        PDT_INFO[rowIndex][0] = key;
        PDT_INFO[rowIndex][1] = "$" + String.valueOf(sortedMap.get(key));
        rowIndex++;
    }

    ListViewAdapter listv = new ListViewAdapter(this, PDT_INFO);

    setListAdapter(listv);

    final ListView lv = getListView();

    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            lv.getItemAtPosition(position);
            String pdtKey = PDT_INFO[position][0];
            String merchantLink = (String) merchantLinkMap.get(pdtKey);

            Uri uri = Uri.parse(merchantLink);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);

        }
    });
}

From source file:com.hayageek.QRAuth.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    FacebookSdk.sdkInitialize(this.getApplicationContext());

    setContentView(R.layout.main);//from  ww w.java  2s  .co  m
    greeting = (TextView) findViewById(R.id.greeting);
    scanButton = (Button) findViewById(R.id.scanqr);

    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    if (accessToken != null) {
        Log.v("###", "Access Token: " + accessToken.getToken());
        scanButton.setVisibility(View.VISIBLE);
    } else {
        scanButton.setVisibility(View.INVISIBLE);
        Log.v("###", "## NOT LOgged IN");
    }

    callbackManager = CallbackManager.Factory.create();

    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.v("###", "Login Success");
            showText("Login Success");

            scanButton.setVisibility(View.VISIBLE);
            updateUI();
        }

        @Override
        public void onCancel() {
            Log.v("###", "Cancel");
            showText("User Cancel");

            scanButton.setVisibility(View.INVISIBLE);

            updateUI();
        }

        @Override
        public void onError(FacebookException exception) {
            Log.v("###", "Error Login");
            showText("Error login facebook");

            scanButton.setVisibility(View.INVISIBLE);

            updateUI();
        }

        private void showAlert() {
            new AlertDialog.Builder(MainActivity.this).setTitle(R.string.cancelled)
                    .setMessage(R.string.permission_not_granted).setPositiveButton(R.string.ok, null).show();
        }
    });

    profileTracker = new ProfileTracker() {
        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {

            if (oldProfile != null && currentProfile == null) {
                Log.v("##", "## Logged OUT");
                scanButton.setVisibility(View.INVISIBLE);

            }
            updateUI();
        }
    };

    final IntentIntegrator scanIntegrator = new IntentIntegrator(this);

    scanButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            scanIntegrator.initiateScan();
            //Intent intent = new Intent(getApplicationContext(),CaptureActivity.class);
            //intent.setAction("com.google.zxing.client.android.SCAN");
            //intent.putExtra("SAVE_HISTORY", false);
            //startActivityForResult(intent, 0);

        }
    });

}

From source file:com.test.weeklly.gplus.SignInActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Toast.makeText(this, "activity started", Toast.LENGTH_LONG).show();

    setContentView(R.layout.sign_in_activity);

    InternetAlertDialogManager alert = new InternetAlertDialogManager();
    ConnectionDetector cd = new ConnectionDetector(SignInActivity.this);
    boolean isInternetPresent = cd.isConnectingToInternet();
    while (!isInternetPresent) {
        // Internet Connection is not present
        alert.showNoConnectionDialog(SignInActivity.this);
        // stop executing code by return
        return;//from www.  j  a  v  a  2s  .  c  o m
    }

    Constants cons = new Constants();
    signup_url = cons.ip + "WeeklyService/Signup?";
    getinfo_url = cons.ip + "WeeklyService/getInfo?gid=";
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    final SharedPreferences app_preferences = getSharedPreferences("userdata", 0);
    g_id = app_preferences.getString("g_id", null);
    emailid = app_preferences.getString("emailid", null);
    name = app_preferences.getString("name", null);
    photourl = app_preferences.getString("photourl", null);

    if (g_id == null || emailid == null || name == null || photourl == null)
        ;//  setContentView(R.layout.sign_in_activity);
    else {

        /*Intent i=new Intent(this,com.test.weekly.backend.AndroidJSONParsingActivity.class);
        startActivity(i);
                
        SignInActivity.this.finish();*/
    }

    mSignInFragment = PlusClientFragment.getPlusClientFragment(this, MomentUtil.VISIBLE_ACTIVITIES);

    findViewById(R.id.sign_in_button).setOnClickListener(this);

}

From source file:polytech.carcassonnetour.MapsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maps_layout);

    overlay = (ImageView) findViewById(R.id.overlay);
    overlay.setVisibility(View.INVISIBLE);
    firstCenter = true;/*from   w w w. ja va  2 s  .  c  om*/
    autoCenter = false;

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    this.hotspots = getAllHotspots();
}

From source file:com.savedollars.ProductStockDisplay.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    JSONData = (getIntent().getStringExtra("JsonData"));

    if (JSONData != null) {
        parseJsonData(JSONData);/*from   w  w  w . ja va  2  s . c  om*/
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.pdtstockview);
    // Setting Product Name
    TextView productName = (TextView) findViewById(R.id.pdtNameTextView);
    productName.setText(pdtName);

    Iterator it = sortedMap.keySet().iterator();
    int rowIndex = 0;

    PDT_INFO = new String[totalCount][2];
    while (it.hasNext()) {

        String key = ProductTotalPriceDisplay.merchantNames[rowIndex];
        String availability = (String) availabilityMap.get(key);
        PDT_INFO[rowIndex][0] = key;
        PDT_INFO[rowIndex][1] = availability;
        rowIndex++;
        it.next();
    }

    ListViewAdapter listv = new ListViewAdapter(this, PDT_INFO);

    setListAdapter(listv);

    final ListView lv = getListView();

    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            lv.getItemAtPosition(position);
            String pdtKey = PDT_INFO[position][0];
            String merchantLink = (String) merchantLinkMap.get(pdtKey);

            Uri uri = Uri.parse(merchantLink);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);

        }
    });

}