Example usage for android.widget AbsListView CHOICE_MODE_SINGLE

List of usage examples for android.widget AbsListView CHOICE_MODE_SINGLE

Introduction

In this page you can find the example usage for android.widget AbsListView CHOICE_MODE_SINGLE.

Prototype

int CHOICE_MODE_SINGLE

To view the source code for android.widget AbsListView CHOICE_MODE_SINGLE.

Click Source Link

Document

The list allows up to one choice

Usage

From source file:com.simas.vc.nav_drawer.NavDrawerFragment.java

public void selectItem(int position) {
    getListView().setSelectedPosition(position);
    // Scroll to the selected item if in single mode
    if (getListView().getChoiceMode() == AbsListView.CHOICE_MODE_SINGLE) {
        getListView().setSelection(position);
    }/*from   www .j av a2 s  .  c  o  m*/
    // Notify the activity
    mCallbacks.onNavigationDrawerItemSelected(position);
}

From source file:org.cafemember.ui.LaunchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Date now = new Date();
    /*int year = now.getYear();
    int month = now.getMonth();//from  www. java2 s . c o m
    int day = now.getDay();
    now.getDate();
    long curr = 147083220000l;
    if(System.currentTimeMillis() > curr ){
    Toast.makeText(this,"    . ?      ",Toast.LENGTH_LONG).show();
    finish();
    }*/

    ApplicationLoader.postInitApplication();
    NativeCrashManager.handleDumpFiles(this);

    if (!UserConfig.isClientActivated()) {
        Intent intent = getIntent();
        if (intent != null && intent.getAction() != null && (Intent.ACTION_SEND.equals(intent.getAction())
                || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE))) {
            super.onCreate(savedInstanceState);
            finish();
            return;
        }
        if (intent != null && !intent.getBooleanExtra("fromIntro", false)) {
            SharedPreferences preferences = ApplicationLoader.applicationContext
                    .getSharedPreferences("logininfo2", MODE_PRIVATE);
            Map<String, ?> state = preferences.getAll();
            if (state.isEmpty()) {
                Intent intent2 = new Intent(this, IntroActivity.class);
                startActivity(intent2);
                super.onCreate(savedInstanceState);
                finish();
                return;
            }
        }
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setTheme(R.style.Theme_TMessages);
    getWindow().setBackgroundDrawableResource(R.drawable.transparent);

    super.onCreate(savedInstanceState);
    Theme.loadRecources(this);

    if (UserConfig.passcodeHash.length() != 0 && UserConfig.appLocked) {
        UserConfig.lastPauseTime = ConnectionsManager.getInstance().getCurrentTime();
    }

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        AndroidUtilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    }

    actionBarLayout = new ActionBarLayout(this);

    drawerLayoutContainer = new DrawerLayoutContainer(this);
    setContentView(drawerLayoutContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    if (AndroidUtilities.isTablet()) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        RelativeLayout launchLayout = new RelativeLayout(this);
        drawerLayoutContainer.addView(launchLayout);
        FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) launchLayout.getLayoutParams();
        layoutParams1.width = LayoutHelper.MATCH_PARENT;
        layoutParams1.height = LayoutHelper.MATCH_PARENT;
        launchLayout.setLayoutParams(layoutParams1);

        backgroundTablet = new ImageView(this);
        backgroundTablet.setScaleType(ImageView.ScaleType.CENTER_CROP);
        backgroundTablet.setImageResource(R.drawable.cats);
        launchLayout.addView(backgroundTablet);
        RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) backgroundTablet
                .getLayoutParams();
        relativeLayoutParams.width = LayoutHelper.MATCH_PARENT;
        relativeLayoutParams.height = LayoutHelper.MATCH_PARENT;
        backgroundTablet.setLayoutParams(relativeLayoutParams);

        launchLayout.addView(actionBarLayout);
        relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams();
        relativeLayoutParams.width = LayoutHelper.MATCH_PARENT;
        relativeLayoutParams.height = LayoutHelper.MATCH_PARENT;
        actionBarLayout.setLayoutParams(relativeLayoutParams);

        rightActionBarLayout = new ActionBarLayout(this);
        launchLayout.addView(rightActionBarLayout);
        relativeLayoutParams = (RelativeLayout.LayoutParams) rightActionBarLayout.getLayoutParams();
        relativeLayoutParams.width = AndroidUtilities.dp(320);
        relativeLayoutParams.height = LayoutHelper.MATCH_PARENT;
        rightActionBarLayout.setLayoutParams(relativeLayoutParams);
        rightActionBarLayout.init(rightFragmentsStack);
        rightActionBarLayout.setDelegate(this);

        shadowTabletSide = new FrameLayout(this);
        shadowTabletSide.setBackgroundColor(0x40295274);
        launchLayout.addView(shadowTabletSide);
        relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTabletSide.getLayoutParams();
        relativeLayoutParams.width = AndroidUtilities.dp(1);
        relativeLayoutParams.height = LayoutHelper.MATCH_PARENT;
        shadowTabletSide.setLayoutParams(relativeLayoutParams);

        shadowTablet = new FrameLayout(this);
        shadowTablet.setVisibility(View.GONE);
        shadowTablet.setBackgroundColor(0x7F000000);
        launchLayout.addView(shadowTablet);
        relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTablet.getLayoutParams();
        relativeLayoutParams.width = LayoutHelper.MATCH_PARENT;
        relativeLayoutParams.height = LayoutHelper.MATCH_PARENT;
        shadowTablet.setLayoutParams(relativeLayoutParams);
        shadowTablet.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (!actionBarLayout.fragmentsStack.isEmpty() && event.getAction() == MotionEvent.ACTION_UP) {
                    float x = event.getX();
                    float y = event.getY();
                    int location[] = new int[2];
                    layersActionBarLayout.getLocationOnScreen(location);
                    int viewX = location[0];
                    int viewY = location[1];

                    if (layersActionBarLayout.checkTransitionAnimation()
                            || x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY
                                    && y < viewY + layersActionBarLayout.getHeight()) {
                        return false;
                    } else {
                        if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
                            for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
                                layersActionBarLayout
                                        .removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
                                a--;
                            }
                            layersActionBarLayout.closeLastFragment(true);
                        }
                        return true;
                    }
                }
                return false;
            }
        });

        shadowTablet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        layersActionBarLayout = new ActionBarLayout(this);
        layersActionBarLayout.setRemoveActionBarExtraHeight(true);
        layersActionBarLayout.setBackgroundView(shadowTablet);
        layersActionBarLayout.setUseAlphaAnimations(true);
        layersActionBarLayout.setBackgroundResource(R.drawable.boxshadow);
        launchLayout.addView(layersActionBarLayout);
        relativeLayoutParams = (RelativeLayout.LayoutParams) layersActionBarLayout.getLayoutParams();
        relativeLayoutParams.width = AndroidUtilities.dp(530);
        relativeLayoutParams.height = AndroidUtilities.dp(528);
        layersActionBarLayout.setLayoutParams(relativeLayoutParams);
        layersActionBarLayout.init(layerFragmentsStack);
        layersActionBarLayout.setDelegate(this);
        layersActionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
        layersActionBarLayout.setVisibility(View.GONE);
    } else {
        drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }

    ListView listView = new ListView(this) {
        @Override
        public boolean hasOverlappingRendering() {
            return false;
        }
    };
    listView.setBackgroundColor(0xffffffff);
    listView.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this));
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    drawerLayoutContainer.setDrawerLayout(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    Point screenSize = AndroidUtilities.getRealScreenSize();
    layoutParams.width = AndroidUtilities.isTablet() ? AndroidUtilities.dp(320)
            : Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56);
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    listView.setLayoutParams(layoutParams);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //
            if (position == 12) {
                presentFragment(new SettingsActivity());
                drawerLayoutContainer.closeDrawer(false);
            } else if (position == 11) {

                try {
                    RulesActivity his = new RulesActivity();
                    presentFragment(his);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                drawerLayoutContainer.closeDrawer(false);
            } else if (position == 2) {

                Defaults def = Defaults.getInstance();
                boolean open = def.openOnJoin();
                def.setOpenOnJoin(!open);
                if (view instanceof TextCheckCell) {
                    ((TextCheckCell) view).setChecked(!open);
                }
            } else if (position == 4) {
                try {
                    HistoryActivity his = new HistoryActivity();
                    presentFragment(his);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                drawerLayoutContainer.closeDrawer(false);
            }

            else if (position == 3) {
                Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://telegram.me/cafemember"));
                startActivity(telegram);

                drawerLayoutContainer.closeDrawer(false);
            } else if (position == 5) {
                try {
                    FAQActivity his = new FAQActivity();
                    presentFragment(his);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                drawerLayoutContainer.closeDrawer(false);
            } else if (position == 6) {
                Intent telegram = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("https://telegram.me/" + Defaults.getInstance().getSupport()));
                startActivity(telegram);

                drawerLayoutContainer.closeDrawer(false);
            } else if (position == 7) {
                try {
                    HelpActivity his = new HelpActivity();
                    presentFragment(his);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                drawerLayoutContainer.closeDrawer(false);
            } else if (position == 8) {
                try {
                    AddRefActivity his = new AddRefActivity();
                    presentFragment(his);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                drawerLayoutContainer.closeDrawer(false);
            } else if (position == 9) {

                try {
                    Log.d("TAB", "Triggering");
                    ShareActivity his = new ShareActivity();
                    Log.d("TAB", "Triggered");
                    presentFragment(his);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                drawerLayoutContainer.closeDrawer(false);
            } else if (position == 10) {
                try {
                    //                        TransfareActivity his = new TransfareActivity();
                    //                        presentFragment(his);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                drawerLayoutContainer.closeDrawer(false);
            }
        }
    });

    drawerLayoutContainer.setParentActionBarLayout(actionBarLayout);
    actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
    actionBarLayout.init(mainFragmentsStack);
    actionBarLayout.setDelegate(this);

    ApplicationLoader.loadWallpaper();

    passcodeView = new PasscodeView(this);
    drawerLayoutContainer.addView(passcodeView);
    FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) passcodeView.getLayoutParams();
    layoutParams1.width = LayoutHelper.MATCH_PARENT;
    layoutParams1.height = LayoutHelper.MATCH_PARENT;
    passcodeView.setLayoutParams(layoutParams1);

    NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this);
    currentConnectionState = ConnectionsManager.getInstance().getConnectionState();

    NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedConnectionState);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.needShowAlert);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
    if (Build.VERSION.SDK_INT < 14) {
        NotificationCenter.getInstance().addObserver(this, NotificationCenter.screenStateChanged);
    }

    if (actionBarLayout.fragmentsStack.isEmpty()) {
        if (!UserConfig.isClientActivated()) {
            actionBarLayout.addFragmentToStack(new LoginActivity());
            drawerLayoutContainer.setAllowOpenDrawer(false, false);
        } else {
            dialogsFragment = new DialogsActivity(null);
            actionBarLayout.addFragmentToStack(dialogsFragment);
            drawerLayoutContainer.setAllowOpenDrawer(true, false);
        }

        try {
            if (savedInstanceState != null) {
                String fragmentName = savedInstanceState.getString("fragment");
                if (fragmentName != null) {
                    Bundle args = savedInstanceState.getBundle("args");
                    switch (fragmentName) {
                    case "chat":
                        if (args != null) {
                            ChatActivity chat = new ChatActivity(args);
                            if (actionBarLayout.addFragmentToStack(chat)) {
                                chat.restoreSelfArgs(savedInstanceState);
                            }
                        }
                        break;
                    case "settings": {
                        SettingsActivity settings = new SettingsActivity();
                        actionBarLayout.addFragmentToStack(settings);
                        settings.restoreSelfArgs(savedInstanceState);
                        break;
                    }
                    case "group":
                        if (args != null) {
                            GroupCreateFinalActivity group = new GroupCreateFinalActivity(args);
                            if (actionBarLayout.addFragmentToStack(group)) {
                                group.restoreSelfArgs(savedInstanceState);
                            }
                        }
                        break;
                    case "channel":
                        if (args != null) {
                            ChannelCreateActivity channel = new ChannelCreateActivity(args);
                            if (actionBarLayout.addFragmentToStack(channel)) {
                                channel.restoreSelfArgs(savedInstanceState);
                            }
                        }
                        break;
                    case "edit":
                        if (args != null) {
                            ChannelEditActivity channel = new ChannelEditActivity(args);
                            if (actionBarLayout.addFragmentToStack(channel)) {
                                channel.restoreSelfArgs(savedInstanceState);
                            }
                        }
                        break;
                    case "chat_profile":
                        if (args != null) {
                            ProfileActivity profile = new ProfileActivity(args);
                            if (actionBarLayout.addFragmentToStack(profile)) {
                                profile.restoreSelfArgs(savedInstanceState);
                            }
                        }
                        break;
                    case "wallpapers": {
                        WallpapersActivity settings = new WallpapersActivity();
                        actionBarLayout.addFragmentToStack(settings);
                        settings.restoreSelfArgs(savedInstanceState);
                        break;
                    }
                    }
                }
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    } else {
        boolean allowOpen = true;
        if (AndroidUtilities.isTablet()) {
            allowOpen = actionBarLayout.fragmentsStack.size() <= 1
                    && layersActionBarLayout.fragmentsStack.isEmpty();
            if (layersActionBarLayout.fragmentsStack.size() == 1
                    && layersActionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) {
                allowOpen = false;
            }
        }
        if (actionBarLayout.fragmentsStack.size() == 1
                && actionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) {
            allowOpen = false;
        }
        drawerLayoutContainer.setAllowOpenDrawer(allowOpen, false);
    }

    handleIntent(getIntent(), false, savedInstanceState != null, false);
    needLayout();

    final View view = getWindow().getDecorView().getRootView();
    view.getViewTreeObserver()
            .addOnGlobalLayoutListener(onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    int height = view.getMeasuredHeight();
                    if (height > AndroidUtilities.dp(100) && height < AndroidUtilities.displaySize.y
                            && height + AndroidUtilities.dp(100) > AndroidUtilities.displaySize.y) {
                        AndroidUtilities.displaySize.y = height;
                        FileLog.e("tmessages", "fix display size y to " + AndroidUtilities.displaySize.y);
                    }
                }
            });
}

From source file:com.frostwire.android.gui.activities.MainActivity2.java

private void setupMenuItems() {
    listMenu.setAdapter(new MainMenuAdapter2(this));
    listMenu.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    listMenu.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            syncSlideMenu();//from w w w .  j ava  2 s .  com
            controller2.closeSlideMenu();
            try {
                if (id == R.id.menu_main_settings) {
                    controller2.showPreferences();
                } else if (id == R.id.menu_main_shutdown) {
                    showShutdownDialog();
                } else if (id == R.id.menu_main_my_music) {
                    controller2.launchMyMusic();
                } else if (id == R.id.menu_main_support) {
                    UIUtils.openURL(MainActivity2.this, Constants.SUPPORT_URL);
                } else {
                    listMenu.setItemChecked(position, true);
                    controller2.switchFragment((int) id);
                }
            } catch (Throwable e) { // protecting from weird android UI engine issues
                LOG.error("Error clicking slide menu item", e);
            }
        }
    });
}

From source file:com.commonsware.cwac.masterdetail.MasterDetailHelper.java

int getDefaultChoiceMode() {
    return (strategy.isActivatedStyle() ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE);
}

From source file:org.dkf.jmule.activities.MainActivity.java

private void setupMenuItems() {
    listMenu.setAdapter(new MainMenuAdapter(this));
    listMenu.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    listMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from w w w.j  a  v a2s. c  om*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //onItemClick(AdapterView<?> parent, View view, int position, long id)
            syncSlideMenu();
            controller.closeSlideMenu();
            try {
                if (id == R.id.menu_main_settings) {
                    controller.showPreferences();
                } else if (id == R.id.menu_main_shutdown) {
                    showShutdownDialog();
                } else {
                    listMenu.setItemChecked(position, true);
                    controller.switchFragment((int) id);
                }
            } catch (Exception e) { // protecting from weird android UI engine issues
                log.error("Error clicking slide menu item", e);
            }
        }
    });
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

@NonNull
XpDropDownListView createDropDownListView(final Context context, final boolean hijackFocus) {
    final XpDropDownListView listView = new XpDropDownListView(context, hijackFocus);
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    return listView;
}