Example usage for android.app ActionBar NAVIGATION_MODE_LIST

List of usage examples for android.app ActionBar NAVIGATION_MODE_LIST

Introduction

In this page you can find the example usage for android.app ActionBar NAVIGATION_MODE_LIST.

Prototype

int NAVIGATION_MODE_LIST

To view the source code for android.app ActionBar NAVIGATION_MODE_LIST.

Click Source Link

Document

List navigation mode.

Usage

From source file:no.barentswatch.fiskinfo.BaseActivity.java

/**
 * Initializes and configures the ActionBar depending on the users API-Level
 * The backward compatible version uses a hacked together spinner for the
 * drop down menu in the action bar, as it did not exist prior to API-level
 * 11.// w w w  . ja v  a 2s . c o m
 */
private void initalizeAndConfigureActionBar() {
    actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#085382")));

    initalizeAndConfigureActionBarSpinners();

    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setListNavigationCallbacks(adapter, navigationListener);
    actionBar.setSelectedNavigationItem(adapter.getCount());
}

From source file:com.concentricsky.android.khanacademy.app.VideoListActivity.java

@Override
protected void onStart() {
    Log.d(LOG_TAG, "onStart");
    super.onStart();
    stopped = false;/*from w  w w  .j  a  va 2 s.c  om*/

    mainMenuDelegate = new MainMenuDelegate(this);

    listView = (AbsListView) findViewById(android.R.id.list);
    listView.setOnItemClickListener(clickListener);

    if (listView instanceof ListView) {
        // It is important that this is inflated with listView passed as the parent, despite the attach false parameter.
        // Otherwise, the view ends up with incorrect LayoutParams and we see crazy, crazy behavior.
        headerView = getLayoutInflater().inflate(R.layout.header_video_list, listView, false);
        ListView lv = (ListView) listView;
        if (lv.getHeaderViewsCount() == 0) {
            lv.addHeaderView(headerView);
        }
    } else { // GridView, fixed header
        headerView = findViewById(R.id.header_video_list);
    }

    /**  Responsive layout stuff 
     * 
     *  Based on screen width, we will find either
     *   narrow
     *     a listview with a header view
     *     items are a thumbnail to the left and a title on white space to the right.
     *     header is a thumbnail with overlaid title across the bottom
     * 
     *   middle
     *     a fixed header on top and a grid view below
     *     header is thumb to left, title above scrolling description to right
     *     items are thumbs with title overlaid across the bottom (3 across)
     *   
     *   wide
     *     a fixed header to the left and a grid view on the right
     *     header is thumb on top, title next, description at bottom
     *     items are thumbs with title overlaid across the bottom (3 across)
     *  
     *  
     *  So in this class, we 
     *    find view by id 'list'
     *    if it's a ListView, inflate and attach header view
     *    if not, then the header is fixed and already in the layout
     *    either way, now we can find header views by id
     *    adapter is the same either way
     *  
     *  
     *  
     *  **/

    ActionBar ab = getActionBar();
    displayOptionsAdapter = new ArrayAdapter<String>(getActionBar().getThemedContext(),
            android.R.layout.simple_list_item_1, displayOptions);
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setTitle("");
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    ab.setListNavigationCallbacks(displayOptionsAdapter, navListener);
    ab.setSelectedNavigationItem(isShowingDownloadedVideosOnly ? 1 : 0);

    requestDataService(new ObjectCallback<KADataService>() {
        @Override
        public void call(KADataService dataService) {
            VideoListActivity.this.dataService = dataService;

            if (topicId != null) {
                Dao<Topic, String> topicDao;
                try {
                    topicDao = dataService.getHelper().getTopicDao();
                    topic = topicDao.queryForId(topicId);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            } else {
                Log.e(LOG_TAG, "Topic id not set for video list");
                topic = dataService.getRootTopic();
                topicId = topic.getId();
            }

            thumbnailManager = dataService.getThumbnailManager();
            api = dataService.getAPIAdapter();
            api.registerUserUpdateListener(userUpdateListener);

            // This instead happens in ActionBar.OnNavigationListener#onNavigationItemSelected, which
            // fires after onResume.
            //            setParentTopic(topic);
        }
    });

    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_LIBRARY_UPDATE);
    filter.addAction(ACTION_BADGE_EARNED);
    filter.addAction(ACTION_OFFLINE_VIDEO_SET_CHANGED);
    filter.addAction(ACTION_DOWNLOAD_PROGRESS_UPDATE);
    filter.addAction(ACTION_TOAST);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter);
    thumbExecutor = Executors.newSingleThreadExecutor();
}

From source file:joshuatee.wx.USWXOGLRadarActivity.java

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

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    //editor = preferences.edit();
    theme_blue_current = preferences.getString("THEME_BLUE", "");
    setTheme(Utility.Theme(theme_blue_current));

    //setContentView(R.layout.activity_uswxoglradar);

    if (!DataStore.loaded)
        DataStore.Init(this);

    space = Pattern.compile(" ");
    comma = Pattern.compile(",");
    colon = Pattern.compile(":");

    //mImageMap = (ImageMap) findViewById(R.id.map);
    //mImageMap.setVisibility(View.GONE);

    cod_warnings_default = preferences.getString("COD_WARNINGS_DEFAULT", "");
    cod_cities_default = preferences.getString("COD_CITIES_DEFAULT", "");
    cod_hw_default = preferences.getString("COD_HW_DEFAULT", "true");
    cod_locdot_default = preferences.getString("COD_LOCDOT_DEFAULT", "true");
    cod_lakes_default = preferences.getString("COD_LAKES_DEFAULT", "true");

    //delay = UtilityImg.GetAnimInterval(preferences);

    img = new TouchImageView2(getApplicationContext());
    img.setMaxZoom(max_zoom);/*from   w  ww . ja  v  a 2  s  .  c  o m*/
    img.setZoom(init_zoom);

    dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);

    boolean isActionBarSplitted = ((dm.widthPixels / dm.density) < 400.00f);
    if (isActionBarSplitted) {
        ab_split = true;
    }

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    statusBarHeight = getResources().getDimensionPixelSize(resourceId);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
    actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId);
    actionBarHeight *= dm.density;

    screen_width = dm.widthPixels;
    screen_height = dm.heightPixels - statusBarHeight - actionBarHeight;

    turl = getIntent().getStringArrayExtra(RID);

    prod = "N0Q";

    view = new GLSurfaceView(this);
    view.setEGLContextClientVersion(2);
    mScaleDetector = new ScaleGestureDetector(this, new ScaleListener());
    mGestureDetector = new GestureDetectorCompat(this, this);

    OGLR = new OpenGLRenderRadar2Dv4(this);
    view.setRenderer(OGLR);
    view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    density = (float) (OGLR.ort_int * 2) / dm.widthPixels;

    setContentView(view);
    ogl_in_view = true;

    rid1 = turl[0];
    state = turl[1];
    if (turl.length > 2) {
        prod = turl[2];
        if (prod.equals("N0R")) {
            prod = "N0Q";
        }
    }

    //rid_fav = preferences.getString(pref_token," : : :");
    //sector = preferences.getString("COD_SECTOR_"+state,"");
    //state = preferences.getString("STATE_CODE_"+state,"");
    //onek = preferences.getString("COD_1KM_"+rid1,"");

    setTitle(prod);

    rid_fav = preferences.getString(pref_token, " : : :");
    rid_arr_loc = UtilityFavorites.SetupFavMenu(preferences, rid_fav, turl[0], pref_token_location, colon);
    adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item,
            rid_arr_loc);
    getActionBar().setListNavigationCallbacks(adapter, navigationListener);
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    navigationListener = new OnNavigationListener() {

        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {

            if (itemPosition == 0 || itemPosition > 2) {
                rid1 = space.split(rid_arr_loc[itemPosition])[0];

                //rid_loc = preferences.getString("RID_LOC_"+rid1,"");
                //editor.putString("NEXRAD_LAST", rid1); 
                //editor.commit();

                old_state = state;
                old_sector = sector;
                old_onek = onek;
                state = comma.split(preferences.getString("RID_LOC_" + rid1, ""))[0];
                sector = preferences.getString("COD_SECTOR_" + state, "");
                state = preferences.getString("STATE_CODE_" + state, "");
                onek = preferences.getString("COD_1KM_" + rid1, "");

                if (prod.equals("2k")) {
                    img_url = img_url.replace(old_sector, sector);
                    img_url = img_url.replace(old_state, state);
                    img_url = img_url.replace(old_onek, onek);
                }
                if (!restarted) {
                    img.resetZoom();
                    img.setZoom(init_zoom);
                    OGLR.setZoom(1.0f);
                    mScaleFactor = 1.0f;
                    OGLR.mPositionX = 0.0f;
                    OGLR.mPositionY = 0.0f;
                }
                restarted = false;
                new GetContent().execute();
            } else if (itemPosition == 1) {
                Intent dtx_srm = new Intent(getApplicationContext(), RIDAddFavActivity.class);
                startActivity(dtx_srm);
            } else if (itemPosition == 2) {
                Intent dtx_srm2 = new Intent(getApplicationContext(), RIDRemoveFavActivity.class);
                startActivity(dtx_srm2);
            }

            return false;
        }
    };
    getActionBar().setListNavigationCallbacks(adapter, navigationListener);

}

From source file:com.veggies.android.todoList.MainActivity.java

private void setActionMenu() {
    isDisplayAllList = false;// www  .j a v  a  2 s.c o  m
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setListNavigationCallbacks(spinnerAdapter, new DropDownListenser());
}

From source file:com.concentricsky.android.khanacademy.app.ManageDownloadsActivity.java

@Override
protected void onStart() {
    super.onStart();

    gridView = (GridView) findViewById(R.id.grid);
    gridView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    gridView.setMultiChoiceModeListener(multiChoiceModeListener);
    gridView.setOnItemClickListener(itemClickListener);

    View emptyView = getLayoutInflater().inflate(R.layout.listview_empty, null, false);
    ((TextView) emptyView.findViewById(R.id.text_list_empty)).setText(R.string.msg_no_downloaded_videos);
    ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    addContentView(emptyView, p);//from   w  ww  . j  a  va  2  s .  c  o m

    gridView.setEmptyView(emptyView);

    requestDataService(new ObjectCallback<KADataService>() {
        @Override
        public void call(final KADataService dataService) {
            ManageDownloadsActivity.this.dataService = dataService;

            CursorAdapter adapter = new Adapter(ManageDownloadsActivity.this, null, 0,
                    dataService.getThumbnailManager());
            gridView.setAdapter(adapter);

            new AsyncTask<Void, Void, Cursor>() {
                @Override
                protected Cursor doInBackground(Void... arg) {
                    return getCursor();
                }

                @Override
                protected void onPostExecute(Cursor cursor) {
                    ((CursorAdapter) gridView.getAdapter()).changeCursor(cursor);
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

            final ActionBar ab = getActionBar();
            ab.setDisplayHomeAsUpEnabled(true);

            ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
            ab.setTitle("");

            setupListNavigation();

            // The receiver performs actions that require a dataService, so register it here.
            IntentFilter filter = new IntentFilter();
            filter.addAction(ACTION_LIBRARY_UPDATE);
            filter.addAction(ACTION_BADGE_EARNED);
            filter.addAction(ACTION_OFFLINE_VIDEO_SET_CHANGED);
            filter.addAction(ACTION_DOWNLOAD_PROGRESS_UPDATE);
            filter.addAction(ACTION_TOAST);
            broadcastManager.registerReceiver(receiver, filter);
        }
    });
}

From source file:com.nagravision.mediaplayer.FullscreenActivity.java

/**
 *
 *///from   w  w w. j  av  a 2 s . com
@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle inBundle) {
    Log.v(LOG_TAG, "FullscreenActivity::onCreate - Enter\n");
    super.onCreate(inBundle);

    getApplication().registerActivityLifecycleCallbacks(this);

    if (Build.VERSION.SDK_INT < 16) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_fullscreen);
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    mMoviesList = (ListView) findViewById(R.id.start_drawer);
    mUrlsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, MOVIES_ARR);
    mMoviesList.setAdapter(mUrlsAdapter);
    mVideoHolder = (VideoView) findViewById(R.id.fullscreen_content);

    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_FULLSCREEN;
    if (Build.VERSION.SDK_INT >= 19) {
        uiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
    }
    decorView.setSystemUiVisibility(uiOptions);
    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.hide();

    mNotifBuilder = new Notification.Builder(this);
    mNotifMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mExplicitIntent = new Intent(Intent.ACTION_VIEW);
    mExplicitIntent.setClass(this, this.getClass());
    mDefaultIntent = PendingIntent.getActivity(this, REQUEST_DISPLAY, mExplicitIntent,
            Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_DEBUG_LOG_RESOLUTION);
    mInfosActionIntent = new Intent();
    mInfosActionIntent.setAction("com.nagravision.mediaplayer.VIDEO_INFOS");
    mInfosActionIntent.addCategory(Intent.CATEGORY_DEFAULT);
    mInfosActionIntent.addCategory(Intent.CATEGORY_INFO);
    mInfosIntent = PendingIntent.getActivity(this, REQUEST_INFOS, mInfosActionIntent,
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_DEBUG_LOG_RESOLUTION);

    if (Build.VERSION.SDK_INT >= 19) {
        mVideoHolder.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE);
    } else {
        mVideoHolder.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_FULLSCREEN);
    }
    OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {
        public void onItemClick(@SuppressWarnings("rawtypes") AdapterView parent, View v, int position,
                long id) {
            Log.v(LOG_TAG, "FullscreenActivity.onCreate.OnItemClickListener::onItemClick - Enter\n");
            ClickItem(position, 0);
        }
    };

    mMoviesList.setOnItemClickListener(mMessageClickedHandler);

    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    mControlsView = new MediaController(this, true);
    mControlsView.setPrevNextListeners(new View.OnClickListener() {
        /*
         * Next listener
         */
        @Override
        public void onClick(View view) {
            Log.v(LOG_TAG, "FullscreenActivity.onCreate.OnClickListener::onClick(next) - Enter\n");
            mVideoHolder.stopPlayback();
            int position = 0;
            if (mLastPosition > 0)
                position = mLastPosition + 1;
            if (position >= MOVIES_URLS.length)
                position = 0;
            ClickItem(position, 0);

            String toaststr = getResources().getString(R.string.next_movie_toast_string) + MOVIES_ARR[position];
            Toast.makeText(FullscreenActivity.this, toaststr, Toast.LENGTH_LONG).show();
        }
    }, new View.OnClickListener() {
        /*
         * Prev listener
         */
        @Override
        public void onClick(View view) {
            Log.v(LOG_TAG, "FullscreenActivity.onCreate.OnClickListener::onClick(prev) - Enter\n");
            mVideoHolder.stopPlayback();
            int position = 0;
            if (mLastPosition > 0)
                position = mLastPosition - 1;
            if (position < 0)
                position = MOVIES_URLS.length - 1;
            ClickItem(position, 0);

            String toaststr = getResources().getString(R.string.prev_movie_toast_string) + MOVIES_ARR[position];
            Toast.makeText(FullscreenActivity.this, toaststr, Toast.LENGTH_LONG).show();
        }
    });
    mVideoHolder.setMediaController(mControlsView);

    // Set up an instance of SystemUiHider to control the system UI for
    // this activity.
    mSystemUiHider = SystemUiHider.getInstance(this, mVideoHolder, HIDER_FLAGS);
    mSystemUiHider.setup();
    mSystemUiHider.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
        // Cached values.
        int mControlsHeight;
        int mShortAnimTime;

        @Override
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
        public void onVisibilityChange(boolean visible) {
            Log.v(LOG_TAG, "FullscreenActivity.OnVisibilityChangeListener::onVisibilityChange - Enter\n");

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                if (mControlsHeight == 0)
                    mControlsHeight = mControlsView.getHeight();
                if (mShortAnimTime == 0)
                    mShortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
                mControlsView.animate().translationY(visible ? 0 : mControlsHeight).setDuration(mShortAnimTime);
            } else
                mControlsView.setVisibility(visible ? View.VISIBLE : View.GONE);

            if (visible && AUTO_HIDE)
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
        }
    });

    // Set up the user interaction to manually show or hide the system UI.
    mVideoHolder.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (TOGGLE_ON_CLICK) {
                mSystemUiHider.toggle();
            } else {
                mSystemUiHider.show();
            }
        }
    });

    mDrawer.openDrawer(mMoviesList);
}

From source file:us.shandian.blacklight.ui.main.MainActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
    if ((parent != mOther || position == 0) && mLastChoice != null) {
        mLastChoice.getPaint().setFakeBoldText(false);
        mLastChoice.invalidate();//from w  ww  .j  a  v a  2  s  .c o m
    }

    if (mGroups != null && mGroups.getSize() > 0 && (parent != mOther || position != 1)) {
        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        getActionBar().setDisplayShowTitleEnabled(true);
    }

    if (parent == mMy) {
        TextView tv = (TextView) view;
        tv.getPaint().setFakeBoldText(true);
        tv.invalidate();
        mLastChoice = tv;
        mNext = position;
        if (mFragments[position] != null) {
            tv.postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        switchTo(position);
                    } catch (Exception e) {

                    }

                    if (position == 0 && mGroups != null && mGroups.getSize() > 0) {
                        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
                        getActionBar().setDisplayShowTitleEnabled(false);
                        updateActionSpinner();
                    }
                }
            }, 400);
        }
    } else if (parent == mAtMe) {
        TextView tv = (TextView) view;
        tv.getPaint().setFakeBoldText(true);
        tv.invalidate();
        mLastChoice = tv;
        mNext = position + 4;
        if (mFragments[4 + position] != null) {
            tv.postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        switchTo(4 + position);
                    } catch (Exception e) {

                    }
                }
            }, 400);
        }
    } else if (parent == mOther) {
        switch (position) {
        case 0: {
            mNext = 6;
            view.postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        switchTo(6);
                    } catch (Exception e) {

                    }
                }
            }, 400);
            break;
        }
        case 1: {
            Intent i = new Intent();
            i.setAction(Intent.ACTION_MAIN);
            i.setClass(this, SettingsActivity.class);
            startActivity(i);
            break;
        }
        case 2: {
            mLoginCache.logout();
            Intent i = new Intent();
            i.setAction(Intent.ACTION_MAIN);
            i.setClass(this, EntryActivity.class);
            startActivity(i);
            finish();
            break;
        }
        }
    }

    mDrawer.closeDrawer(mDrawerGravity);
}

From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java

/** Swaps fragments in the main content view */
private void selectItem(int position) {
    // set fragment title
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    setTitle(mTitles[position]);/*from www  . j av a 2 s. c om*/

    // Create a new fragment and specify the planet to show based on position
    switch (position) {
    case 0:
        fragment = new MainPrefsFragment();
        break;
    case 1:
        fragment = new PrefsGeneralFragment();
        break;
    case 2:
        fragment = new AppearancePreferencesFragment();
        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        break;
    case 3:
        fragment = new ServicePreferencesFragment();
        break;
    case 4:
        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(WIDGET_PRESENT, false)
                || isWidgetPlaced()) {
            fragment = new WidgetSettingsFragment();
        } else {
            fragment = new HowToAddWidgetFragment();
        }
        break;
    case 5:
        fragment = new PrefsAppSpecificFragment();
        break;
    case 6:
        fragment = new BackupRestorePreferenceFragment();
        break;
    case 7:
        fragment = new PrefsContactFragment();
        break;
    case 8:
        fragment = new AboutPreferencesFragment();
        break;
    case 9:
        requestUnlockApp();
        return;
    }

    // Insert the fragment by replacing any existing fragment
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    // Highlight the selected item, update the title, and close the drawer
    mDrawerList.setItemChecked(position, true);
    mDrawerLayout.closeDrawer(mDrawerList);
}