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:co.beem.project.beem.service.XmppConnectionAdapter.java

/**
 * {@inheritDoc}/* w w w.  ja  v  a  2  s. c  o m*/
 */
@Override
public boolean disconnect() {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    if (mAdaptee != null && mAdaptee.isConnected())
        mAdaptee.disconnect();
    return true;
}

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

protected void checkForWidgetsUpdate(Context context, Troll troll) {

    try {//from   w w  w. jav  a  2  s .c  o  m
        AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);

        ComponentName componentName = new ComponentName(context, HomeScreenWidget.class);
        int[] appWidgetIds = widgetManager.getAppWidgetIds(componentName);

        if (appWidgetIds != null && appWidgetIds.length > 0) {

            // FIXME AThimel 14/02/14 Remove ASAP
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);

            String dlaText = Trolls.getWidgetDlaTextFunction(context).apply(troll);
            Bitmap blason = MhDlaNotifierUtils.loadBlasonForWidget(troll.getBlason(), context.getCacheDir());

            for (int appWidgetId : appWidgetIds) {

                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.home_screen_widget);
                views.setTextViewText(R.id.widgetDla, dlaText);

                if (blason == null) {
                    views.setImageViewResource(R.id.widgetImage, R.drawable.trarnoll_square_transparent_128);
                } else {
                    views.setImageViewBitmap(R.id.widgetImage, blason);
                }

                // Tell the AppWidgetManager to perform an update on the current app widget
                widgetManager.updateAppWidget(appWidgetId, views);
            }
        }

    } catch (Exception eee) {
        Log.e(TAG, "Unable to update widget(s)", eee);
    }

}

From source file:com.example.android.navigationdrawerexample.Controller.PilihanController.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    /*Fragment fragment = new PlanetFragment();*/
    fragment = null;/*from  ww w  .ja v  a2s.co  m*/
    Bundle args = new Bundle();

    switch (position) {
    case 0:
        fragment = new Fragment() {
            @Override
            public void onResume() {
                super.onResume();
                new GetAllJadwalTask(PilihanController.this).execute(username);
            }

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);

                View view = inflater.inflate(R.layout.list_jadwal, container, false);
                GetAllJadwalListView = (ExpandableListView) view.findViewById(R.id.GetAllJadwalListView);
                ImageView buat = (ImageView) view.findViewById(R.id.button);
                //Button pilihan = (Button) view.findViewById(R.id.button9);
                if (role == 0)
                    buat.setVisibility(View.GONE);
                else
                    buat.setVisibility(View.VISIBLE);

                new GetAllJadwalTask(PilihanController.this).execute(username);

                GetAllJadwalListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

                    @Override
                    public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                        GetAllJadwalListView.expandGroup(groupPosition);
                        return true;
                    }
                });

                GetAllJadwalListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

                    @Override
                    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
                            int childPosition, long id) {
                        try {
                            //Toast.makeText(getApplicationContext(), listDataChild2.get(listDataHeader2.get(groupPosition)).get(childPosition).toString(), Toast.LENGTH_LONG).show();
                            int jadwalp = listDataChild2.get(listDataHeader2.get(groupPosition))
                                    .get(childPosition).getInt("Id");
                            int kelasp = listDataChild2.get(listDataHeader2.get(groupPosition))
                                    .get(childPosition).getInt("Id_kelas");
                            ////                                    JSONObject mahasiswaClicked = jsonArray.getJSONObject(groupPosition+childPosition);
                            ////                                    int jadwalp = mahasiswaClicked.getInt("Id");
                            ////                                    int kelasp = mahasiswaClicked.getInt("Id_kelas");
                            Intent showDetails = new Intent(getActivity(), JadwalController.class);
                            showDetails.putExtra("JadwalID", jadwalp);
                            showDetails.putExtra("KelasID", kelasp);
                            showDetails.putExtra("Username", username);
                            showDetails.putExtra("View", "detailJadwal");
                            startActivity(showDetails);

                        } catch (JSONException e) {
                            e.printStackTrace();
                            //Toast.makeText(getApplicationContext(), "lala masuk ex", Toast.LENGTH_LONG).show();
                        }
                        return false;
                    }
                });

                buat.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        Intent showDetails = new Intent(getActivity(), JadwalController.class);
                        //asumsi username gak null
                        showDetails.putExtra("Username", username);
                        showDetails.putExtra("View", "createJadwal");

                        startActivity(showDetails);
                    }
                });
                return view;
            }
        };
        args.putString(FragmentOne.ITEM_NAME, dataList.get(position).getItemName());
        args.putInt(FragmentOne.IMAGE_RESOURCE_ID, dataList.get(position).getImgResID());
        args.putInt("role", 2);
        break;
    case 1:
        fragment = new RoleFragment();
        args.putInt("role", 1);
        break;
    case 2:
        fragment = new Fragment() {
            @Override
            public void onResume() {
                super.onResume();
                new GetAllEnrollTask(PilihanController.this).execute(username);
            }

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);

                view = inflater.inflate(R.layout.list_enroll, container, false);

                //GetAllEnrollListView = (ListView) view.findViewById(R.id.GetAllJadwalListView);
                ImageView enroll = (ImageView) view.findViewById(R.id.button);
                expListView = (ExpandableListView) view.findViewById(R.id.lvExp);

                new GetAllEnrollTask(PilihanController.this).execute(username);

                expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

                    @Override
                    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
                            int childPosition, long id) {
                        //asumsikan kalo dipencet bisa ngeluarin infromasi asistennya
                        //viewnya di view_profile_personal
                        //kelasnya inten, nah loh pake controller mana nih??
                        //asumsikan gue punya kelas ProfileAsdos.java
                        String userAsdos = listDataChild.get(listDataHeader.get(groupPosition))
                                .get(childPosition);
                        Intent showDetails = new Intent(getActivity(), MenjabatController.class);
                        showDetails.putExtra("Username", userAsdos);
                        startActivity(showDetails);
                        return false;
                    }
                });

                enroll.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        Intent showDetails = new Intent(getActivity(), EnrollController.class);
                        showDetails.putExtra("Username", username);
                        startActivity(showDetails);
                    }
                });
                return view;
            }

        };
        args.putInt("role", 0);
        break;
    case 3:
        fragment = new Fragment() {
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);

                View view = inflater.inflate(R.layout.choose_forum, container, false);

                Button buttonForumReply = (Button) view.findViewById(R.id.choose_forum_1);
                Button buttonForumForum = (Button) view.findViewById(R.id.choose_forum_2);
                Button buttonForumPolling = (Button) view.findViewById(R.id.choose_forum_3);

                buttonForumReply.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), ForumQA.class);
                        intent.putExtra("Username", username);
                        startActivity(intent);
                    }
                });

                buttonForumForum.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), ForumRequest.class);
                        intent.putExtra("Username", username);
                        startActivity(intent);
                    }
                });

                buttonForumPolling.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), ForumPolling.class);
                        intent.putExtra("Username", username);
                        startActivity(intent);
                    }
                });

                return view;
            }

        };
        args.putInt("role", 3);
        break;
    case 4:
        //ProfileController profileController2 = new ProfileController(username);
        if (role == 2) {
            fragment = new Fragment() {

                @Override
                public View onCreateView(LayoutInflater inflater, ViewGroup container,
                        Bundle savedInstanceState) {
                    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                    StrictMode.setThreadPolicy(policy);

                    view = inflater.inflate(R.layout.admin, container, false);

                    //GetAllEnrollListView = (ListView) view.findViewById(R.id.GetAllJadwalListView);
                    Button kelas = (Button) view.findViewById(R.id.button9);
                    Button role = (Button) view.findViewById(R.id.button10);
                    Button database = (Button) view.findViewById(R.id.button11);
                    Button forum = (Button) view.findViewById(R.id.button12);

                    kelas.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            Intent showDetails = new Intent(getActivity(), KelasController.class);
                            //asumsi username gak null
                            showDetails.putExtra("Username", username);
                            showDetails.putExtra("View", "listKelas");
                            startActivity(showDetails);
                        }
                    });
                    role.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            Intent showDetails = new Intent(getActivity(), RoleController.class);
                            //asumsi username gak null
                            showDetails.putExtra("Username", username);
                            startActivity(showDetails);
                        }
                    });
                    database.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            Intent showDetails = new Intent(getActivity(), Database.class);
                            startActivity(showDetails);
                        }
                    });

                    forum.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            Intent showDetails = new Intent(getActivity(), AdminThread.class);
                            startActivity(showDetails);
                        }
                    });
                    return view;
                }
            };
        } else {
            fragment = new FragmentOne();
            Toast.makeText(getApplicationContext(), "Hei Anda Bukan Admin", Toast.LENGTH_LONG).show();
        }
        args.putInt("role", 4);
        break;
    case 5:
        session.logoutUser();
        finish();
        return;
    }
    /*args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);*/
    fragment.setArguments(args);

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java

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

    sensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    vector = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
    acc = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mag = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    mLockStateView = (TextView) findViewById(R.id.lock_state);
    mTextView = (TextView) findViewById(R.id.text);
    mRoll = (TextView) findViewById(R.id.roll);
    mPitch = (TextView) findViewById(R.id.pitch);
    mYaw = (TextView) findViewById(R.id.yaw);

    EditText videoip = (EditText) findViewById(R.id.videoip);
    videoip.setOnEditorActionListener(new OnEditorActionListener() {
        @Override/*from  w  w  w . j  a v a  2 s . co m*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                ip = v.getText().toString();
                startVideo();
                handled = true;
            }

            return handled;
        }
    });

    EditText connect = (EditText) findViewById(R.id.connect);
    connect.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEND) {

                try {
                    String address = v.getText().toString();
                    client = new Client(("tcp://" + address + ":6767"), "client");

                    try {
                        client.send("runtime", "getUptime");
                        //client.send("runtime", "start", "arduino", "Arduino");
                        //client.send("runtime", "start", "servo01", "Servo");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                } catch (URISyntaxException e) {
                    e.printStackTrace();
                }
                handled = true;
            }
            return handled;
        }
    });

    EditText comPort = (EditText) findViewById(R.id.comport);
    comPort.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                String address = v.getText().toString();
                if (client != null) {
                    try {
                        client.send("arduino", "connect", address);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                handled = true;
            }
            return handled;
        }
    });

    final Button calibrate = (Button) findViewById(R.id.calibrate);
    calibrate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //
            // Perform action on click
            if (client != null) {
                try {
                    client.send("oculus", "calibrate");
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }
    });

    ToggleButton toggleCardboard = (ToggleButton) findViewById(R.id.cardboard);
    toggleCardboard.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                cardboardMode = true;
            } else {
                cardboardMode = false;
            }
        }
    });

    ToggleButton toggleHeadTracking = (ToggleButton) findViewById(R.id.headTrackingButton);
    toggleHeadTracking.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                headTrackingMode = true;
            } else {
                headTrackingMode = false;
            }
        }
    });

    // First, we initialize the Hub singleton with an application identifier.
    Hub hub = Hub.getInstance();
    if (!hub.init(this, getPackageName())) {
        // We can't do anything with the Myo device if the Hub can't be initialized, so exit.
        Toast.makeText(this, "Couldn't initialize Hub", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    // Next, register for DeviceListener callbacks.
    hub.addListener(mListener);
    //hub.attachToAdjacentMyo();
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
}

From source file:com.android.launcher2.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_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().penaltyDeath().build());
    }//ww  w  .  j  a v  a  2 s  .  c  o m

    super.onCreate(savedInstanceState);
    LauncherApplication app = ((LauncherApplication) getApplication());
    mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    checkForLocaleChange();
    setContentView(R.layout.launcher);
    setupViews();
    showFirstRunWorkspaceCling();

    registerContentObservers();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    // Update customization drawer _after_ restoring the states
    if (mAppsCustomizeContent != null) {
        mAppsCustomizeContent.onPackagesUpdated();
    }

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        if (sPausedFromUserAction) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, -1);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(true, mWorkspace.getCurrentPage());
        }
    }

    if (!mModel.isAllAppsLoaded()) {
        ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
        mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);

    updateGlobalIcons();

    // On large interfaces, we want the screen to auto-rotate based on the current orientation
    unlockScreenOrientation(true);
}

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

@SuppressWarnings("unused")
@Override//  www .  j a v a 2  s  . com
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_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().penaltyDeath().build());
    }

    super.onCreate(savedInstanceState);
    LauncherApplication app = ((LauncherApplication) getApplication());
    mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    checkForLocaleChange();

    if (MainConfiguration.SCREEN_COUNT == 2) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_2);
        else
            setContentView(R.layout.launcher_2);
    } else if (MainConfiguration.SCREEN_COUNT == 3) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_3);
        else
            setContentView(R.layout.launcher_3);
    } else if (MainConfiguration.SCREEN_COUNT == 4) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_4);
        else
            setContentView(R.layout.launcher_4);
    } else if (MainConfiguration.SCREEN_COUNT == 5) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_5);
        else
            setContentView(R.layout.launcher_5);
    } else if (MainConfiguration.SCREEN_COUNT == 6) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_6);
        else
            setContentView(R.layout.launcher_6);
    } else if (MainConfiguration.SCREEN_COUNT == 7) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_7);
        else
            setContentView(R.layout.launcher_7);
    } else {
        setContentView(R.layout.launcher_5);
    }

    setupViews();
    showFirstRunWorkspaceCling();

    if (MainConfiguration.ALLOW_DRAWER) {
        this.drawerLayout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
        ((LauncherDrawerLayout) this.drawerLayout).postInit(this, this.mWorkspace, this.mSharedPrefs);
    }

    registerContentObservers();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    // Update customization drawer _after_ restoring the states
    if (mAppsCustomizeContent != null) {
        mAppsCustomizeContent.onPackagesUpdated();
    }

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        if (sPausedFromUserAction) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, -1);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(true, mWorkspace.getCurrentPage());
        }
    }

    if (!mModel.isAllAppsLoaded()) {
        ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
        mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);

    updateGlobalIcons();

    // On large interfaces, we want the screen to auto-rotate based on the current orientation
    unlockScreenOrientation(true);
}

From source file:com.eurotong.orderhelperandroid.Common.java

public static String downloadContentFromInternet(String urlString) throws IOException {
    /*//from   www .  ja  v  a  2  s  . co  m
    URLConnection feedUrl=null;
    try
    {
       feedUrl = new URL(url).openConnection();
    }
    catch (MalformedURLException e)
    {
       Log.v("ERROR","MALFORMED URL EXCEPTION");
    }
    catch (IOException e) {
       e.printStackTrace();
    }
    try
    {
       InputStream in = feedUrl.getInputStream();
       String json = convertStreamToString(in);
       return  json;
    }
    catch(Exception e){}
    return null;
    */
    //http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);

    DateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
    Date date = new Date();
    String datetime = dateFormat.format(date);
    // Create a URL for the desired page
    URL url = new URL(urlString + "?d=" + datetime);

    // Read all the text returned by the server

    InputStream in = url.openStream();
    String content = convertStreamToString(in);
    return content;
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_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().penaltyDeath().build());
    }/*from  ww  w .j ava2s .c o m*/

    super.onCreate(savedInstanceState);

    LauncherAppState.setApplicationContext(getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();

    // Lazy-initialize the dynamic grid
    DeviceProfile grid = app.initDynamicGrid(this);

    mIsSafeModeEnabled = getPackageManager().isSafeMode();
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mIconCache.flushInvalidIcons(grid);
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);

    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    checkForLocaleChange();
    setContentView(R.layout.launcher);

    setupViews();
    grid.layout(this);

    registerContentObservers();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        // We only load the page synchronously if the user rotates (or triggers a
        // configuration change) while launcher is in the foreground
        mModel.startLoader(true, 0);
    }

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);
}

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

private void showLoginDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(ViewRedditActivity.this);
    // Get the layout inflater
    LayoutInflater inflater = getLayoutInflater();
    final View v = inflater.inflate(R.layout.logindialog, null);

    builder.setView(v)//  w w  w .j a  va  2s.c  om
            // Add action buttons
            .setPositiveButton("Login", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    final String username = ((EditText) v.findViewById(R.id.username)).getText().toString();
                    final String password = ((EditText) v.findViewById(R.id.password)).getText().toString();
                    final boolean rememberaccn = ((CheckBox) v.findViewById(R.id.rememberaccn)).isChecked();
                    dialog.cancel();
                    // run login procedure
                    final ProgressDialog logindialog = android.app.ProgressDialog.show(ViewRedditActivity.this,
                            "", ("Logging in..."), true);
                    Thread t = new Thread() {
                        public void run() {
                            // login
                            final String result = global.mRedditData.checkLogin(prefs, username, password,
                                    rememberaccn); // request "remember" cookie if account is being saved
                            // Set thread network policy to prevent network on main thread exceptions.
                            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll()
                                    .build();
                            StrictMode.setThreadPolicy(policy);
                            runOnUiThread(new Runnable() {
                                public void run() {
                                    logindialog.dismiss();
                                    if (result.equals("1")) {
                                        if (rememberaccn) { // store account if requested & login result is OK
                                            global.setAccount(prefs, username, password, true);
                                        }
                                    } else {
                                        // show error
                                        Toast.makeText(ViewRedditActivity.this, "Login error: " + result,
                                                Toast.LENGTH_LONG).show();
                                    }
                                }
                            });
                        }
                    };
                    t.start();
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).setTitle("Login to Reddit");
    builder.create().show();
}

From source file:itcr.gitsnes.MainActivity.java

/** Function to call DownloadFileAsync and
 * download the game file from AWS S3, on click call*/
public void download(View view) {
    TextView name = (TextView) this.findViewById(R.id.Uni_name);
    TextView _key = (TextView) this.findViewById(R.id.fileurl);

    final String file_key = _key.getText().toString();
    final String file_name = name.getText().toString();

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

    Toast.makeText(getApplicationContext(), "Starting download...", Toast.LENGTH_SHORT).show();
    String url = KS.MAIN_PATH + file_key;
    new DownloadFileAsync().execute(url, file_name);
    Toast.makeText(getApplicationContext(), "The file was downloaded", Toast.LENGTH_SHORT).show();
}