Example usage for android.os StrictMode setVmPolicy

List of usage examples for android.os StrictMode setVmPolicy

Introduction

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

Prototype

public static void setVmPolicy(final VmPolicy policy) 

Source Link

Document

Sets the policy for what actions in the VM process (on any thread) should be detected, as well as the penalty if such actions occur.

Usage

From source file:xyz.klinker.blur.launcher3.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(//from  w w w  .  j  a v a  2 s .  co m
                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());
    }

    predictiveAppsProvider = new PredictiveAppsProvider(this);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.preOnCreate();
    }

    try {
        super.onCreate(savedInstanceState);
    } catch (Exception e) {
        super.onCreate(new Bundle());
    }

    UpdateUtils.checkUpdate(this);
    LauncherAppState app = LauncherAppState.getInstance();

    // Load configuration-specific DeviceProfile
    mDeviceProfile = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            ? app.getInvariantDeviceProfile().landscapeProfile
            : app.getInvariantDeviceProfile().portraitProfile;

    mSharedPrefs = Utilities.getPrefs(this);
    mIsSafeModeEnabled = getPackageManager().isSafeMode();
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();

    mDragController = new DragController(this);
    mInflater = getLayoutInflater();
    mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);

    mStats = new Stats(this);

    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");
    }

    setContentView(R.layout.launcher);

    app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
    app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
    setupViews();
    setUpBlur();

    mDeviceProfile.layout(this);

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

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

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

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

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

    mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
    // In case we are on a device with locked rotation, we should look at preferences to check
    // if the user has specifically allowed rotation.
    if (!mRotationEnabled) {
        mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
    }

    // On large interfaces, or on devices that a user has specifically enabled screen rotation,
    // we want the screen to auto-rotate based on the current orientation
    setOrientation();

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
    }

    if (shouldShowIntroScreen()) {
        showIntroScreen();
    } else {
        showFirstRunActivity();
        showFirstRunClings();
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(/*from   w ww.  j a  v  a2 s .c o  m*/
                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());
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (LauncherAppState.PROFILE_STARTUP) {
            Trace.beginSection("Launcher-onCreate");
        }
    }

    predictiveAppsProvider = new PredictiveAppsProvider(this);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.preOnCreate();
    }

    super.onCreate(savedInstanceState);

    app = LauncherAppState.getInstance();

    // Load configuration-specific DeviceProfile
    mDeviceProfile = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            ? app.getInvariantDeviceProfile().landscapeProfile
            : app.getInvariantDeviceProfile().portraitProfile;

    mSharedPrefs = Utilities.getPrefs(this);
    mIsSafeModeEnabled = getPackageManager().isSafeMode();
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);

    mDragController = new DragController(this);
    mAllAppsController = new AllAppsTransitionController(this);
    mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, mAllAppsController);

    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;

    setContentView(R.layout.launcher);

    //Shortcuts variable init
    masterLayout = (InsettableFrameLayout) findViewById(R.id.launcher);
    gridSize = new GridSize((int) app.getInvariantDeviceProfile().numColumns,
            (int) app.getInvariantDeviceProfile().numRows);

    IS_ALLOW_MIC = Utilities.isAllowVoiceInSearchBarPrefEnabled(getApplicationContext());

    setupViews();
    mDeviceProfile.layout(this, false /* notifyListeners */);
    mExtractedColors = new ExtractedColors();
    loadExtractedColorsAndColorItems();

    ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)).addAccessibilityStateChangeListener(this);

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    if (LauncherAppState.PROFILE_STARTUP) {
        Trace.endSection();
    }

    // We only load the page synchronously if the user rotates (or triggers a
    // configuration change) while launcher is in the foreground
    if (!mModel.startLoader(mWorkspace.getRestorePage())) {
        // If we are not binding synchronously, show a fade in animation when
        // the first page bind completes.
        mDragLayer.setAlpha(0);
    } else {
        setWorkspaceLoading(true);
    }

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

    IntentFilter filter = new IntentFilter(ACTION_APPWIDGET_HOST_RESET);
    registerReceiver(mUiBroadcastReceiver, filter);

    mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
    // In case we are on a device with locked rotation, we should look at preferences to check
    // if the user has specifically allowed rotation.
    if (!mRotationEnabled) {
        mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
        mRotationPrefChangeHandler = new RotationPrefChangeHandler();
        mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
    }

    // On large interfaces, or on devices that a user has specifically enabled screen rotation,
    // we want the screen to auto-rotate based on the current orientation
    setOrientation();

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
    }

    activity = this;
    /*if (!isTaskRoot()) {
    finish();
    return;
    }*/

    adminComponent = new ComponentName(Launcher.this, DarClass.class);
    devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

    appHasFingerprint = Utilities.getAppHasFingerprint(getApplicationContext());
    appHasPassword = Utilities.getAppHasPassword(getApplicationContext());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
    }

    icons = Utilities.getIconPack(Utilities.getAppIconPackageNamePrefEnabled(getApplicationContext()));
    if (icons == null || icons.isEmpty() || icons.size() == 0) {
        if (Utilities.getAppIconPackageNamePrefEnabled(getApplicationContext()) != null && !Utilities
                .getAppIconPackageNamePrefEnabled(getApplicationContext()).equalsIgnoreCase("NULL")) {
            Utilities.answerToRestoreIconPack(this,
                    Utilities.getAppIconPackageNamePrefEnabled(getApplicationContext()));
        }
    }

    if (FirstRun.isFirstLaunch(getApplicationContext())) {
        WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
        try {
            myWallpaperManager.setResource(R.drawable.wallpaper);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (Utilities.doCheckPROVersion(getApplicationContext())) {

    }

    mDefaultScreenId = Utilities.getLongCustomDefault(this, Utilities.SETTINGS_UI_HOMESCREEN_DEFAULT_SCREEN_ID,
            1);
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(//ww w .  j  a v a2s .c  o  m
                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);

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

    // Determine the dynamic grid properties
    Point smallestSize = new Point();
    Point largestSize = new Point();
    Point realSize = new Point();
    Display display = getWindowManager().getDefaultDisplay();
    display.getCurrentSizeRange(smallestSize, largestSize);
    display.getRealSize(realSize);
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);
    // Lazy-initialize the dynamic grid
    DeviceProfile grid = app.initDynamicGrid(this, Math.min(smallestSize.x, smallestSize.y),
            Math.min(largestSize.x, largestSize.y), realSize.x, realSize.y, dm.widthPixels, dm.heightPixels);

    // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
    mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mIconCache.flushInvalidIcons(grid);
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mStats = new Stats(this);

    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();
    grid.layout(this);

    registerContentObservers();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    // Update customization drawer _after_ restoring the states
    if (mAppsCustomizeContent != null) {
        mAppsCustomizeContent.onPackagesUpdated(LauncherModel.getSortedWidgetsAndShortcuts(this));
    }
    {
        {
            final RajawaliSurfaceView surface = new RajawaliSurfaceView(this);
            surface.setFrameRate(60.0);
            surface.setRenderMode(IRajawaliSurface.RENDERMODE_WHEN_DIRTY);

            // Add mSurface to your root view
            addContentView(surface, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT));

            mRenderer = new WallpaperRenderer(this);
            surface.setSurfaceRenderer(mRenderer);
        }
    }

    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());
        }
    }

    // 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);

    showFirstRunCling();

    //        following code is for Native method support test
    {

    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(/*from  w w  w  .j  a  v a2  s .c  o  m*/
                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());
    }

    predictiveAppsProvider = new PredictiveAppsProvider(this);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.preOnCreate();
    }

    try {
        super.onCreate(savedInstanceState);
    } catch (Exception e) {
        super.onCreate(new Bundle());
    }

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

    // Load configuration-specific DeviceProfile
    mDeviceProfile = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            ? app.getInvariantDeviceProfile().landscapeProfile
            : app.getInvariantDeviceProfile().portraitProfile;

    mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mIsSafeModeEnabled = getPackageManager().isSafeMode();
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();

    mDragController = new DragController(this);
    mInflater = getLayoutInflater();
    mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, this);

    mStats = new Stats(this);

    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");
    }

    setContentView(R.layout.launcher);

    setupViews();
    setUpBlur();

    mDeviceProfile.layout(this);

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

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

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

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

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

    mRotationEnabled = Utilities.isRotationAllowedForDevice(getApplicationContext());
    // In case we are on a device with locked rotation, we should look at preferences to check
    // if the user has specifically allowed rotation.
    if (!mRotationEnabled) {
        mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext(), false);
    }

    // On large interfaces, or on devices that a user has specifically enabled screen rotation,
    // we want the screen to auto-rotate based on the current orientation
    setOrientation();

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
        if (mLauncherCallbacks.hasLauncherOverlay()) {
            ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
            mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
            mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(mLauncherOverlayContainer,
                    mLauncherOverlayCallbacks);
            mWorkspace.setLauncherOverlay(mLauncherOverlay);
        }
    }

    if (shouldShowIntroScreen()) {
        showIntroScreen();
    } else {
        showFirstRunActivity();
        showFirstRunClings();
    }
}

From source file:g7.bluesky.launcher3.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    activity = this;
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(/*from   w w  w .  ja  v  a2s.  com*/
                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());
    }

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.preOnCreate();
    }

    super.onCreate(savedInstanceState);

    LauncherAppState.setApplicationContext(getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);

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

    // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
    mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);

    // Set defaultSharedPref
    defaultSharedPref = PreferenceManager.getDefaultSharedPreferences(this);

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

    mStats = new Stats(this);

    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();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

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

    if (!mRestoring) {
        if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
        } 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.getRestorePage());
        }
    }

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

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

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

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
        if (mLauncherCallbacks.hasLauncherOverlay()) {
            ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
            mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
            mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(mLauncherOverlayContainer,
                    mLauncherOverlayCallbacks);
            mWorkspace.setLauncherOverlay(mLauncherOverlay);
        }
    }

    if (shouldShowIntroScreen()) {
        showIntroScreen();
    } else {
        showFirstRunActivity();
        showFirstRunClings();
    }

    //create extramenu
    //llExtraMenu = (LinearLayout) findViewById(R.id.ll_extra_menu);
    //llExtraMenu.addView(new ExtraMenu(this, null));
    flLauncher = (LauncherRootView) findViewById(R.id.launcher);
    mExtraMenu = new ExtraMenu(this, null);
    flLauncher.addView(mExtraMenu);
    if (!defaultSharedPref.getBoolean(SettingConstants.EXTRA_MENU_PREF_KEY, false)) {
        mExtraMenu.setVisibility(View.GONE);
    }

    editTextFilterApps.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            String searchString = editTextFilterApps.getText().toString();
            if (listApps != null && listApps.size() > 0) {
                if (searchString.trim().length() > 0) {
                    ArrayList<AppInfo> searchList = new ArrayList<>();
                    for (AppInfo appInfo : listApps) {
                        String appTitle = StringUtil
                                .convertVNString(appInfo.getTitle().toString().toLowerCase().trim());
                        searchString = StringUtil.convertVNString(searchString.toLowerCase().trim());
                        if (appTitle.contains(searchString)) {
                            searchList.add(appInfo);
                        }
                    }
                    mAppsCustomizeContent.setApps(searchList);
                } else {
                    mAppsCustomizeContent.setApps((ArrayList<AppInfo>) listApps);
                }
            }
        }
    });

    // Spinner element
    Spinner spinner = (Spinner) findViewById(R.id.spinner);

    // Spinner click listener
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Clear spinner text
            ((TextView) view).setText(null);

            SharedPreferences.Editor editor = defaultSharedPref.edit();
            editor.putInt(SettingConstants.SORT_PREF_KEY, position);
            editor.apply();

            // Value from preference
            int prefVal = defaultSharedPref.getInt(SettingConstants.SORT_PREF_KEY, SettingConstants.SORT_A_Z);
            LauncherUtil.sortListApps(defaultSharedPref, listApps, prefVal);
            mAppsCustomizeContent.invalidatePageData();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    // Creating adapter for spinner
    ArrayAdapter<CharSequence> dataAdapter = ArrayAdapter.createFromResource(this, R.array.sort_options,
            android.R.layout.simple_spinner_item);

    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);

    // attaching data adapter to spinner
    spinner.setAdapter(dataAdapter);

    // Set default value
    final int prefSortOptionVal = defaultSharedPref.getInt(SettingConstants.SORT_PREF_KEY,
            SettingConstants.SORT_A_Z);
    spinner.setSelection(prefSortOptionVal);

    // Listen on pref change
    prefChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
            if (key.equalsIgnoreCase(SettingConstants.EXTRA_MENU_PREF_KEY)) {
                if (!defaultSharedPref.getBoolean(SettingConstants.EXTRA_MENU_PREF_KEY, false)) {
                    mExtraMenu.setVisibility(View.GONE);
                } else {
                    mExtraMenu.setVisibility(View.VISIBLE);
                }
            } else if (key.equalsIgnoreCase(SettingConstants.ICON_THEME_PREF_KEY)) {
                mModel.forceReload();
                loadIconPack();
            }
        }
    };
    defaultSharedPref.registerOnSharedPreferenceChangeListener(prefChangeListener);
}

From source file:de.grobox.liberario.activities.MainActivity.java

private void enableStrictMode() {
    if (!BuildConfig.DEBUG)
        return;//from www .  j a v  a 2 s.c o m

    StrictMode.ThreadPolicy.Builder threadPolicy = new StrictMode.ThreadPolicy.Builder();
    threadPolicy.detectAll();
    threadPolicy.penaltyLog();
    StrictMode.setThreadPolicy(threadPolicy.build());
    StrictMode.VmPolicy.Builder vmPolicy = new StrictMode.VmPolicy.Builder();
    vmPolicy.detectAll();
    vmPolicy.penaltyLog();
    StrictMode.setVmPolicy(vmPolicy.build());
}

From source file:me.trashout.fragment.TrashReportOrEditFragment.java

private void createCameraIntentChooser() {
    List<Intent> allIntents = new ArrayList<>();
    PackageManager packageManager = getActivity().getPackageManager();
    allIntents.addAll(getCameraIntents(getActivity(), packageManager));
    Intent target;/*from w w  w .j av a  2s. co m*/
    if (allIntents.isEmpty()) {
        target = new Intent();
    } else {
        target = allIntents.get(allIntents.size() - 1);
        allIntents.remove(allIntents.size() - 1);
    }

    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    StrictMode.setVmPolicy(builder.build());

    Intent chooserIntent = Intent.createChooser(target,
            getString(com.theartofdev.edmodo.cropper.R.string.pick_image_intent_chooser_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()]));
    getActivity().startActivityForResult(chooserIntent, CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE);
}

From source file:org.mozilla.gecko.GeckoApp.java

/**
 * Enable Android StrictMode checks (for supported OS versions).
 * http://developer.android.com/reference/android/os/StrictMode.html
 *//*from  w w  w  .  j  ava 2s .  com*/
private void enableStrictMode() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
        return;
    }

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());

    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
}

From source file:com.popdeem.sdk.uikit.activity.PDUIClaimActivity.java

private void startCamera() {
    try {// w  ww . j  ava2  s.com
        File f = setUpPhotoFile();
        mCurrentPhotoPath = f.getAbsolutePath();

        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        startActivityForResult(takePictureIntent,
                PDUIImageUtils.PD_TAKE_PHOTO_REQUEST_CODE); /*this line causes a crash if client app has camera permission - need to ask for camera permission of it exists*/

    } catch (IOException e) {
        e.printStackTrace();
        mCurrentPhotoPath = null;
    }
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

private boolean startActivity(View v, Intent intent, Object tag) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {/* w  w  w.  j  a  v  a2s . c  o  m*/
        // Only launch using the new animation if the shortcut has not opted out (this is a
        // private contract between launcher and may be ignored in the future).
        boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
        LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
        UserManagerCompat userManager = UserManagerCompat.getInstance(this);

        UserHandleCompat user = null;
        if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
            long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
            user = userManager.getUserForSerialNumber(serialNumber);
        }

        Bundle optsBundle = null;
        if (useLaunchAnimation) {
            ActivityOptions opts = null;
            if (Utilities.ATLEAST_MARSHMALLOW) {
                int left = 0, top = 0;
                int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
                if (v instanceof TextView) {
                    // Launch from center of icon, not entire view
                    Drawable icon = Workspace.getTextViewIcon((TextView) v);
                    if (icon != null) {
                        Rect bounds = icon.getBounds();
                        left = (width - bounds.width()) / 2;
                        top = v.getPaddingTop();
                        width = bounds.width();
                        height = bounds.height();
                    }
                }
                opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
            } else if (!Utilities.ATLEAST_LOLLIPOP) {
                // Below L, we use a scale up animation
                opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(),
                        v.getMeasuredHeight());
            } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
                // On L devices, we use the device default slide-up transition.
                // On L MR1 devices, we a custom version of the slide-up transition which
                // doesn't have the delay present in the device default.
                opts = ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim);
            }
            optsBundle = opts != null ? opts.toBundle() : null;
        }

        if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
            StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
            try {
                // Temporarily disable deathPenalty on all default checks. For eg, shortcuts
                // containing file Uris would cause a crash as penaltyDeathOnFileUriExposure
                // is enabled by default on NYC.
                StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
                // Could be launching some bookkeeping activity
                startActivity(intent, optsBundle);
            } finally {
                StrictMode.setVmPolicy(oldPolicy);
            }
        } else {
            // TODO Component can be null when shortcuts are supported for secondary user
            launcherApps.startActivityForProfile(intent.getComponent(), user, intent.getSourceBounds(),
                    optsBundle);
        }
        return true;
    } catch (SecurityException e) {
        if (Utilities.ATLEAST_MARSHMALLOW && tag instanceof ItemInfo) {
            // Due to legacy reasons, direct call shortcuts require Launchers to have the
            // corresponding permission. Show the appropriate permission prompt if that
            // is the case.
            if (intent.getComponent() == null && Intent.ACTION_CALL.equals(intent.getAction())
                    && checkSelfPermission(
                            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Rename sPendingAddItem to a generic name.
                sPendingAddItem = preparePendingAddArgs(REQUEST_PERMISSION_CALL_PHONE, intent, 0,
                        (ItemInfo) tag);
                requestPermissions(new String[] { Manifest.permission.CALL_PHONE },
                        REQUEST_PERMISSION_CALL_PHONE);
                return false;
            }
        }
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Launcher does not have the permission to launch " + intent
                + ". Make sure to create a MAIN intent-filter for the corresponding activity "
                + "or use the exported attribute for this activity. " + "tag=" + tag + " intent=" + intent, e);
    }
    return false;
}