Example usage for android.text Selection setSelection

List of usage examples for android.text Selection setSelection

Introduction

In this page you can find the example usage for android.text Selection setSelection.

Prototype

public static final void setSelection(Spannable text, int index) 

Source Link

Document

Move the cursor to offset index.

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

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

    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.klinker.android.launcher.launcher3.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(/* ww w .ja  va  2  s  .c om*/
                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(// w  ww . jav a2  s .  c om
                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:com.android.soma.Launcher.java

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

    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.undatech.opaque.RemoteCanvas.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    android.util.Log.d(TAG, "onCreateInputConnection called");
    int version = android.os.Build.VERSION.SDK_INT;
    BaseInputConnection bic = null;//from w ww  .j  av  a 2  s . c  o m
    if (!bb && version >= Build.VERSION_CODES.JELLY_BEAN) {
        bic = new BaseInputConnection(this, false) {
            final static String junk_unit = "%%%%%%%%%%";
            final static int multiple = 1000;
            Editable e;

            @Override
            public Editable getEditable() {
                if (e == null) {
                    int numTotalChars = junk_unit.length() * multiple;
                    String junk = new String();
                    for (int i = 0; i < multiple; i++) {
                        junk += junk_unit;
                    }
                    e = Editable.Factory.getInstance().newEditable(junk);
                    Selection.setSelection(e, numTotalChars);
                    if (RemoteCanvas.this.keyboard != null) {
                        RemoteCanvas.this.keyboard.skippedJunkChars = false;
                    }
                }
                return e;
            }
        };
    } else {
        bic = new BaseInputConnection(this, false);
    }

    outAttrs.actionLabel = null;
    outAttrs.inputType = InputType.TYPE_NULL;
    /* TODO: If people complain about kbd not working, this is a possible workaround to
     * test and add an option for.
    // Workaround for IME's that don't support InputType.TYPE_NULL.
    if (version >= 11) {
    outAttrs.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
    outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN;
    }*/
    return bic;
}

From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java

@Override
public void clearSearchResult() {
    if (mApps.setOrderedFilter(null)) {
        mAppsRecyclerView.onSearchResultsChanged();
    }/*from   ww w.  jav a 2 s. co m*/

    // Clear the search query
    mSearchQueryBuilder.clear();
    mSearchQueryBuilder.clearSpans();
    Selection.setSelection(mSearchQueryBuilder, 0);
}

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

private void clearTypedText() {
    mDefaultKeySsb.clear();
    mDefaultKeySsb.clearSpans();
    Selection.setSelection(mDefaultKeySsb, 0);
}