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:com.neogb.asynctaskfragment.sample.MainActivity.java

private void enableStrictMode() {
    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().build());
    }// ww w . j  ava  2s.  c  o  m
}

From source file:com.example.harish.b2bapplication.activity.ProfileFragment.java

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

From source file:com.greendev.image.ImageGridActivity.java

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

    /*//from   www .  j  a  v  a 2  s.co m
     * get the intent called from an Activity (eg. Portfolio.class or
     * PhotoActivity)
     */
    Intent intent = getIntent();
    /** get the bundle from the intent **/
    Bundle b = intent.getExtras();

    // set title in action bar
    TITLE = b.getString("TITLE");
    setActionBarTitle(TITLE);

    // PhotoActivityGridFragment
    key = b.getString("key");
    if (key == null)
        key = "hi";

    if (BuildConfig.DEBUG) {
        Utils.enableStrictMode();
    }

    try {
        if (getSupportFragmentManager().findFragmentByTag(TAG) == null) {
            final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

            // If calling this activity for the Gallery images then use
            // PhotoActivityGridFragment
            if (key.equals("PhotoActivityGridFragment")) {
                TYPE_URL_THUMB = b.getStringArray("TYPE_URL_THUMB");
                SETS_NAMES = b.getStringArray("SETS_NAMES");

                /* Parcelable Objects from PhotoActivity */
                setImgsParcel = b.getParcelable("SET_IMGS");
                if (setImgsParcel != null) {
                    setImgs = setImgsParcel.getArray();
                    if (setImgs == null)
                        setImgs = Images.boothDesignsThumbUrls;
                } else
                    setImgs = Images.campaignsThumbUrls;

                setThumbsParcel = b.getParcelable("SET_THUMBS");
                if (setThumbsParcel != null) {
                    setThumbs = setThumbsParcel.getArray();
                    if (setThumbs == null)
                        setThumbs = Images.boothDesignsThumbUrls;
                } else
                    setThumbs = Images.campaignsThumbUrls;

                setDescsParcel = b.getParcelable("SET_DESCS");
                if (setDescsParcel != null) {
                    setDescs = setDescsParcel.getArray();
                    if (setDescs == null)
                        setDescs = Images.boothDesignsThumbUrls;
                } else
                    setDescs = Images.campaignsThumbUrls;

                ft.add(android.R.id.content, new PhotoActivityGridFragment(this, ImageGridActivity.class,
                        TYPE_URL_THUMB, setImgs, setThumbs, setDescs, SETS_NAMES), TAG);
            } else {
                /** retrieve the string array extra passed */
                TYPE_URL = b.getStringArray("TYPE_URL");
                TYPE_URL_THUMB = b.getStringArray("TYPE_URL_THUMB");

                CAPTIONS = b.getStringArray("CAPTIONS");

                ft.add(android.R.id.content, new ImageGridFragment(this, ImageDetailActivity.class, TYPE_URL,
                        TYPE_URL_THUMB, CAPTIONS), TAG);
            }
            ft.commit();
        }

    } catch (Exception e) {
        Log.e(TAG, e.toString());

    }

}

From source file:ca.xecure.easychip.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);

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

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);/*from   ww  w  . java 2  s  . c  o  m*/

    //Set the pager with an adapter
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new FlipAdapter(getSupportFragmentManager()));
    pager.setCurrentItem(1);

    //Bind the title indicator to the adapter
    TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.titles);
    indicator.setViewPager(pager);

    final float density = getResources().getDisplayMetrics().density;
    indicator.setBackgroundColor(0xFF7AA7D6);
    //        indicator.setBackgroundColor(0xFFDD7200);
    indicator.setFooterColor(0xFFECF1F2);
    indicator.setFooterLineHeight(0);
    indicator.setFooterIndicatorHeight(7 * density);
    indicator.setFooterIndicatorStyle(IndicatorStyle.Triangle);
    indicator.setTextColor(0xAAFFFFFF);
    indicator.setSelectedColor(0xFFFFFFFF);
    indicator.setSelectedBold(true);

    registerReceiver(confirm_payment_handler, new IntentFilter(CONFIRM_PAYMENT_ACTION));

    settings = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
    String email_address = settings.getString(EMAIL_ADDRESS_PREF, null);
    if (email_address != null) {
        register_cloud_message();
    } else {
        choose_email_address();
    }
}

From source file:com.example.app_2.utils.Utils.java

@TargetApi(11)
public static void enableStrictMode() {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();/*ww w.  j  ava2 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.example.savedollars.ProductPriceDisplay.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    JSONData = (getIntent().getStringExtra("JsonData"));
    System.out.println("Json data in price page: " + JSONData);
    if (JSONData != null) {
        parseJsonData(JSONData);/*from w w w.  java2s . c  o  m*/
    }
    super.onCreate(savedInstanceState);
    System.out.println("after on create");

    setContentView(R.layout.pdtpriceview);

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

    Iterator objMapIterator = sortedMap.entrySet().iterator();
    int i = 0;
    System.out.println("3 Updating INFO totalCount:" + totalCount);

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

        PDT_INFO[i][0] = key;
        PDT_INFO[i][1] = "$" + sortedMap.get(key);
        System.out.println(
                "While Array Merchant Name:" + PDT_INFO[i][0] + "Array Merchant Price:" + PDT_INFO[i][1]);
        i++;
    }
    System.out.println("Total Updated Rows: " + i + " < totalCount:" + totalCount);

    ListViewAdapter listv = new ListViewAdapter(this, PDT_INFO);

    setListAdapter(listv);
    System.out.println("INFO Updated leter");

}

From source file:com.google.reviewit.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from w w  w .j  ava  2s  .  c o  m
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }

    drawer = (DrawerLayout) findViewById(R.id.drawer);
    list = (ListView) findViewById(R.id.mainList);

    items = new ArrayList<>();
    items.add(new Item(SortChangesFragment.class, R.string.app_menu_sort, R.drawable.ic_star_white_16dp, null));
    items.add(new Item(ReviewChangesFragment.class, R.string.app_menu_review, R.drawable.ic_feedback_white_18dp,
            null));
    items.add(new Item(SettingsFragment.class, R.string.app_menu_settings, R.drawable.ic_settings_white_18dp,
            null));

    list.setAdapter(new BaseAdapter() {
        @Override
        public int getCount() {
            return items.size();
        }

        @Override
        public Object getItem(int position) {
            return items.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = ((LayoutInflater) MainActivity.this
                        .getSystemService(Activity.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.main_list_item,
                                null);
            }

            Item item = items.get(position);

            ((ImageView) convertView.findViewById(R.id.mainListItemIcon)).setImageResource(item.iconId);
            WidgetUtil.setText(convertView, R.id.mainListItemTitle, getString(item.titleId));

            if (item.count != null) {
                WidgetUtil.setText(convertView, R.id.mainListItemCounter, item.count.toString());
            } else {
                convertView.findViewById(R.id.mainListItemCounter).setVisibility(View.GONE);
            }

            return convertView;
        }
    });

    toggle = new ActionBarDrawerToggle(this, drawer, R.string.app_name, R.string.app_name) {
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu();
        }
    };
    drawer.setDrawerListener(toggle);

    list.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            displayView(position);
        }
    });

    if (getApp().getPrefs().showIntro) {
        displayInitialView(new IntroFragment1());
    } else if (savedInstanceState == null) {
        switch (getApp().getPrefs().startScreen) {
        case REVIEW_SCREEN:
            displayInitialView(newFragmentInstance(items.get(1).fragmentClass));
            break;
        case SORT_SCREEN:
        default:
            displayInitialView(newFragmentInstance(items.get(0).fragmentClass));
            break;
        }
    }
}

From source file:com.example.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);/*  w w w.j  a  va 2s .  co m*/
    }

    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 i = 0;

    System.out.println("3 Updating INFO totalCount:" + totalCount);

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

        System.out.println("Value of i is " + i);
        String key = ProductTotalPriceDisplay.merchantNames[i];
        System.out.println("smita: merchant keys: " + key);
        String availability = (String) availabilityMap.get(key);

        System.out.println("i = " + i);
        System.out.println("Save DDollars key:" + key);
        System.out.println("Save DDollars availability :" + availability);
        PDT_INFO[i][0] = key;
        PDT_INFO[i][1] = availability;
        System.out.println(
                "While Array Merchant Name:" + PDT_INFO[i][0] + "Array Merchant Price:" + PDT_INFO[i][1]);
        i++;
        it.next();

    }
    System.out.println("Total Updated Rows: " + i + " < totalCount:" + totalCount);

    ListViewAdapter listv = new ListViewAdapter(this, PDT_INFO);

    setListAdapter(listv);
    System.out.println("INFO Updated leter");

}

From source file:org.kaaproject.kaa.demo.notification.NotificationDemoActivity.java

@Override
public void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    setContentView(R.layout.notification_demo);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    showTopics();//  w ww . j  ava2s  . c o m

    ((KaaNotificationApp) getApplicationContext()).setDemoActivity(this);
}

From source file:org.gplvote.signdoc.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*  w  ww . ja v  a  2  s .c o  m*/

    do_destroy = false;

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    btnInit = (Button) findViewById(R.id.btnInit);
    btnInit.setOnClickListener(this);
    btnRegister = (Button) findViewById(R.id.btnRegister);
    btnRegister.setOnClickListener(this);
    btnDocsList = (Button) findViewById(R.id.btnDocsList);
    btnDocsList.setOnClickListener(this);

    if (sPref == null) {
        sPref = getSharedPreferences(APP_PREFERENCES, MODE_PRIVATE);
    }
    ;
    settings = Settings.getInstance(this);

    checkPasswordDlgShow();
}