Example usage for android.view ViewStub inflate

List of usage examples for android.view ViewStub inflate

Introduction

In this page you can find the example usage for android.view ViewStub inflate.

Prototype

public View inflate() 

Source Link

Document

Inflates the layout resource identified by #getLayoutResource() and replaces this StubbedView in its parent by the inflated layout resource.

Usage

From source file:com.android.mms.ui.ComposeMessageActivity.java

private void initRecipientsEditor() {
    if (isRecipientsEditorVisible()) {
        return;// w w w.j  a v a 2 s.c o m
    }
    // Must grab the recipients before the view is made visible because getRecipients()
    // returns empty recipients when the editor is visible.
    ContactList recipients = getRecipients();

    ViewStub stub = (ViewStub) findViewById(R.id.recipients_editor_stub);
    if (stub != null) {
        View stubView = stub.inflate();
        mRecipientsEditor = (RecipientsEditor) stubView.findViewById(R.id.recipients_editor);
        mRecipientsPicker = (ImageButton) stubView.findViewById(R.id.recipients_picker);
        mRecipientsSelector = (ImageButton) stubView.findViewById(R.id.recipients_selector);
        mRecipientsSelector.setVisibility(View.VISIBLE);
    } else {
        mRecipientsEditor = (RecipientsEditor) findViewById(R.id.recipients_editor);
        mRecipientsEditor.setVisibility(View.VISIBLE);
        mRecipientsPicker = (ImageButton) findViewById(R.id.recipients_picker);
        mRecipientsSelector = (ImageButton) findViewById(R.id.recipients_selector);
        mRecipientsSelector.setVisibility(View.VISIBLE);
    }
    mRecipientsPicker.setOnClickListener(this);
    mRecipientsSelector.setOnClickListener(this);

    mRecipientsEditor.setAdapter(new ChipsRecipientAdapter(this));
    mRecipientsEditor.populate(recipients);
    mRecipientsEditor.setOnCreateContextMenuListener(mRecipientsMenuCreateListener);
    mRecipientsEditor.addTextChangedListener(mRecipientsWatcher);
    // TODO : Remove the max length limitation due to the multiple phone picker is added and the
    // user is able to select a large number of recipients from the Contacts. The coming
    // potential issue is that it is hard for user to edit a recipient from hundred of
    // recipients in the editor box. We may redesign the editor box UI for this use case.
    // mRecipientsEditor.setFilters(new InputFilter[] {
    //         new InputFilter.LengthFilter(RECIPIENTS_MAX_LENGTH) });

    mRecipientsEditor.setOnSelectChipRunnable(new Runnable() {
        @Override
        public void run() {
            // After the user selects an item in the pop-up contacts list, move the
            // focus to the text editor if there is only one recipient.  This helps
            // the common case of selecting one recipient and then typing a message,
            // but avoids annoying a user who is trying to add five recipients and
            // keeps having focus stolen away.
            if (mRecipientsEditor.getRecipientCount() == 1) {
                // if we're in extract mode then don't request focus
                final InputMethodManager inputManager = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                if (inputManager == null || !inputManager.isFullscreenMode()) {
                    mTextEditor.requestFocus();
                }
            }
        }
    });

    mRecipientsEditor.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                RecipientsEditor editor = (RecipientsEditor) v;
                ContactList contacts = editor.constructContactsFromInput(false);
                updateTitle(contacts);
            }
        }
    });

    PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher(this, mRecipientsEditor);

    mTopPanel.setVisibility(View.VISIBLE);
}

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

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

    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:com.cognizant.trumobi.PersonaLauncher.java

/**
 * Finds all the views we need and configure them properly.
 *//*from   ww  w . j  av  a  2  s  .com*/
private void setupViews() {
    //CERTIFICATE
    layout = (LinearLayout) findViewById(R.id.launcher_parent_layout);

    /*   if(!PersonaMainActivity.isRovaPoliciesOn)
          layout.setBackgroundResource(R.drawable.pr_bg);*/

    mDragLayer = (PersonaDragLayer) findViewById(R.id.drag_layer);
    final PersonaDragLayer personaDragLayer = mDragLayer;

    mWorkspace = (PersonaWorkspace) personaDragLayer.findViewById(R.id.workspace);
    final PersonaWorkspace personaWorkspace = mWorkspace;
    // ADW: The app drawer is now a ViewStub and we load the resource
    // depending on custom settings
    ViewStub tmp = (ViewStub) personaDragLayer.findViewById(R.id.stub_drawer);
    int drawerStyle = PersonaAlmostNexusSettingsHelper.getDrawerStyle(this);
    tmp.setLayoutResource(mDrawerStyles[drawerStyle]);
    mAllAppsGrid = (PersonaDrawer) tmp.inflate();
    mDeleteZone = (PersonaDeleteZone) personaDragLayer.findViewById(R.id.delete_zone);

    mHandleView = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_mab);
    mHandleView.setFocusable(true);
    mHandleView.setLauncher(this);
    mHandleView.setOnClickListener(this);
    personaDragLayer.addDragListener(mHandleView);
    /*
     * mHandleView.setOnTriggerListener(new OnTriggerListener() { public
     * void onTrigger(View v, int whichHandle) { mDockBar.open(); } public
     * void onGrabbedStateChange(View v, boolean grabbedState) { } public
     * void onClick(View v) { if (allAppsOpen) { closeAllApps(true); } else
     * { showAllApps(true, null); } } });
     */
    mAllAppsGrid.setTextFilterEnabled(false);
    mAllAppsGrid.setDragger(personaDragLayer);
    mAllAppsGrid.setLauncher(this);

    personaWorkspace.setOnLongClickListener(this);
    personaWorkspace.setDragger(personaDragLayer);
    personaWorkspace.setLauncher(this);

    mDeleteZone.setLauncher(this);
    mDeleteZone.setDragController(personaDragLayer);

    personaDragLayer.setIgnoredDropTarget((View) mAllAppsGrid);
    personaDragLayer.setDragScoller(personaWorkspace);
    personaDragLayer.addDragListener(mDeleteZone);
    // ADW: Dockbar inner icon viewgroup (PersonaMiniLauncher.java)
    mMiniLauncher = (PersonaMiniLauncher) personaDragLayer.findViewById(R.id.mini_content);
    mMiniLauncher.setLauncher(this);
    mMiniLauncher.setOnLongClickListener(this);
    mMiniLauncher.setDragger(personaDragLayer);
    personaDragLayer.addDragListener(mMiniLauncher);

    // ADW: Action Buttons (LAB/RAB)
    mLAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab);
    PersonaLog.d("personalauncher", "lab rab componenets initialized");
    mLAB.setLauncher(this);
    mLAB.setSpecialIcon(R.drawable.pr_arrow_left);
    mLAB.setSpecialAction(ACTION_CATALOG_PREV);
    personaDragLayer.addDragListener(mLAB);
    mRAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab);
    mRAB.setLauncher(this);
    mRAB.setSpecialIcon(R.drawable.pr_arrow_right);
    mRAB.setSpecialAction(ACTION_CATALOG_NEXT);
    personaDragLayer.addDragListener(mRAB);
    mLAB.setOnClickListener(this);
    mRAB.setOnClickListener(this);
    // ADW: secondary aActionButtons
    mLAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab2);
    mLAB2.setLauncher(this);
    personaDragLayer.addDragListener(mLAB2);
    mRAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab2);
    mRAB2.setLauncher(this);
    personaDragLayer.addDragListener(mRAB2);
    mLAB2.setOnClickListener(this);
    mRAB2.setOnClickListener(this);
    // ADW: Dots ImageViews
    mPreviousView = (ImageView) findViewById(R.id.btn_scroll_left);
    mNextView = (ImageView) findViewById(R.id.btn_scroll_right);
    mPreviousView.setOnLongClickListener(this);
    mNextView.setOnLongClickListener(this);

    // ADW: ActionButtons swipe gestures
    mHandleView.setSwipeListener(this);
    mLAB.setSwipeListener(this);
    mLAB2.setSwipeListener(this);
    mRAB.setSwipeListener(this);
    mRAB2.setSwipeListener(this);

    // mHandleView.setDragger(dragLayer);
    // mLAB.setDragger(dragLayer);
    // mRAB.setDragger(dragLayer);
    mRAB2.setDragger(personaDragLayer);
    mLAB2.setDragger(personaDragLayer);

    // ADW linearlayout with apptray, lab and rab
    mDrawerToolbar = findViewById(R.id.drawer_toolbar);
    mHandleView.setNextFocusUpId(R.id.drag_layer);
    mHandleView.setNextFocusLeftId(R.id.drag_layer);
    mLAB.setNextFocusUpId(R.id.drag_layer);
    mLAB.setNextFocusLeftId(R.id.drag_layer);
    mRAB.setNextFocusUpId(R.id.drag_layer);
    mRAB.setNextFocusLeftId(R.id.drag_layer);
    mLAB2.setNextFocusUpId(R.id.drag_layer);
    mLAB2.setNextFocusLeftId(R.id.drag_layer);
    mRAB2.setNextFocusUpId(R.id.drag_layer);
    mRAB2.setNextFocusLeftId(R.id.drag_layer);
    // ADW add a listener to the dockbar to show/hide the app-drawer-button
    // and the dots
    mDockBar = (PersonaDockBar) findViewById(R.id.dockbar);
    mDockBar.setDockBarListener(new DockBarListener() {
        public void onOpen() {
            mDrawerToolbar.setVisibility(View.GONE);
            if (mNextView.getVisibility() == View.VISIBLE) {
                mNextView.setVisibility(View.INVISIBLE);
                mPreviousView.setVisibility(View.INVISIBLE);
            }
        }

        public void onClose() {
            if (mDockStyle != DOCK_STYLE_NONE)
                mDrawerToolbar.setVisibility(View.VISIBLE);
            if (showDots && !isAllAppsVisible()) {
                mNextView.setVisibility(View.VISIBLE);
                mPreviousView.setVisibility(View.VISIBLE);
            }

        }
    });
    if (PersonaAlmostNexusSettingsHelper.getDesktopIndicator(this)) {
        mDesktopIndicator = (PersonaDesktopIndicator) (findViewById(R.id.desktop_indicator));
    }
    // ADW: Add focusability to screen items
    mLAB.setFocusable(true);
    mRAB.setFocusable(true);
    mLAB2.setFocusable(true);
    mRAB2.setFocusable(true);
    mPreviousView.setFocusable(true);
    mNextView.setFocusable(true);

    // ADW: Load the specified theme
    String themePackage = PersonaAlmostNexusSettingsHelper.getThemePackageName(this, THEME_DEFAULT);
    PackageManager pm = getPackageManager();
    Resources themeResources = null;
    if (!themePackage.equals(THEME_DEFAULT)) {
        try {
            themeResources = pm.getResourcesForApplication(themePackage);
        } catch (NameNotFoundException e) {
            // ADW The saved theme was uninstalled so we save the default
            // one
            PersonaAlmostNexusSettingsHelper.setThemePackageName(this, PersonaLauncher.THEME_DEFAULT);
        }
    }
    if (themeResources != null) {
        // Action Buttons
        loadThemeResource(themeResources, themePackage, "lab_bg", mLAB, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "rab_bg", mRAB, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "lab2_bg", mLAB2, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "rab2_bg", mRAB2, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "mab_bg", mHandleView, THEME_ITEM_BACKGROUND);
        // App drawer button
        // loadThemeResource(themeResources,themePackage,"handle_icon",mHandleView,THEME_ITEM_FOREGROUND);
        // View appsBg=findViewById(R.id.appsBg);
        // loadThemeResource(themeResources,themePackage,"handle",appsBg,THEME_ITEM_BACKGROUND);
        // Deletezone
        loadThemeResource(themeResources, themePackage, "ic_delete", mDeleteZone, THEME_ITEM_FOREGROUND);
        loadThemeResource(themeResources, themePackage, "delete_zone_selector", mDeleteZone,
                THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "home_arrows_left", mPreviousView,
                THEME_ITEM_FOREGROUND);
        loadThemeResource(themeResources, themePackage, "home_arrows_right", mNextView, THEME_ITEM_FOREGROUND);
        // Dockbar
        loadThemeResource(themeResources, themePackage, "dockbar_bg", mMiniLauncher, THEME_ITEM_BACKGROUND);
        try {
            themeFont = Typeface.createFromAsset(themeResources.getAssets(), "themefont.ttf");
        } catch (RuntimeException e) {
            // TODO: handle exception
        }
    }
    Drawable previous = mPreviousView.getDrawable();
    Drawable next = mNextView.getDrawable();
    mWorkspace.setIndicators(previous, next);

    // ADW: EOF Themes
    updateAlmostNexusUI();
}

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

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