List of usage examples for android.widget ListView setChoiceMode
public void setChoiceMode(int choiceMode)
From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java
/** * Screen to select the tags that will be present in the test */// w w w.j av a 2 s. co m private void selectTags() { ListView checkBoxesList; TagsArrayAdapter tagsAdapter; List<TestTag> allTagsList = dbHelper.getOrderedCourseTags(Constants.getSelectedCourseCode()); screenStep = ScreenStep.TAGS; //Add "All tags" item in list's top allTagsList.add(0, new TestTag(0, getResources().getString(R.string.allMsg), 0)); setLayout(R.layout.tests_tags); checkBoxesList = (ListView) findViewById(R.id.testTagsList); tagsAdapter = new TagsArrayAdapter(this, R.layout.list_item_multiple_choice, allTagsList); checkBoxesList.setAdapter(tagsAdapter); checkBoxesList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); checkBoxesList.setOnItemClickListener(tagsAnswersTypeItemClickListener); checkBoxesList.setDividerHeight(0); }
From source file:com.simplealertdialog.SimpleAlertDialog.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(android.view.Window.FEATURE_NO_TITLE); setContentView(R.layout.sad__dialog_simple); getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); // Background setBackground(R.id.header, mBackgroundTop); setBackground(R.id.bar_wrapper, mBackgroundMiddle); setBackground(R.id.body, mBackgroundBottom); // Title/*from ww w . java2 s .c om*/ if (TextUtils.isEmpty(mTitle)) { findViewById(R.id.header).setVisibility(View.GONE); findViewById(R.id.bar_wrapper).setVisibility(View.GONE); findViewById(R.id.title).setVisibility(View.GONE); findViewById(R.id.icon).setVisibility(View.GONE); setBackground(R.id.body, mBackgroundFull); } else { ((TextView) findViewById(R.id.title)).setText(mTitle); if (mTitleTextStyle != 0) { ((TextView) findViewById(R.id.title)).setTextAppearance(getContext(), mTitleTextStyle); } if (mIcon > 0) { ((ImageView) findViewById(R.id.icon)).setImageResource(mIcon); findViewById(R.id.title).setPadding(findViewById(R.id.title).getPaddingLeft() / 2, findViewById(R.id.title).getPaddingTop(), findViewById(R.id.title).getPaddingRight(), findViewById(R.id.title).getPaddingBottom()); } else { findViewById(R.id.icon).setVisibility(View.GONE); } setBackground(R.id.bar, mTitleSeparatorBackground); if (mTitleSeparatorHeight == 0) { mTitleSeparatorHeight = getContext().getResources() .getDimensionPixelSize(R.dimen.sad__dialog_title_separator_height); } FrameLayout.LayoutParams lpBar = new FrameLayout.LayoutParams(getMatchParent(), mTitleSeparatorHeight); findViewById(R.id.bar).setLayoutParams(lpBar); findViewById(R.id.bar).requestLayout(); LinearLayout.LayoutParams lpBarWrapper = new LinearLayout.LayoutParams(getMatchParent(), mTitleSeparatorHeight); findViewById(R.id.bar_wrapper).setLayoutParams(lpBarWrapper); findViewById(R.id.bar_wrapper).requestLayout(); } // Message if (TextUtils.isEmpty(mMessage)) { findViewById(R.id.message).setVisibility(View.GONE); } else { ((TextView) findViewById(R.id.message)).setText(mMessage); if (mMessageTextStyle != 0) { ((TextView) findViewById(R.id.message)).setTextAppearance(getContext(), mMessageTextStyle); } } // Custom View if (mView != null) { LinearLayout group = (LinearLayout) findViewById(R.id.view); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(getMatchParent(), LinearLayout.LayoutParams.WRAP_CONTENT); group.addView(mView, lp); } else { findViewById(R.id.view).setVisibility(View.GONE); } // Custom Adapter if (mAdapter != null) { ListView list = (ListView) findViewById(R.id.list); list.setAdapter(mAdapter); if (mSingleChoice) { list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } if (mSingleChoice && 0 <= mCheckedItem && mCheckedItem < mAdapter.getCount()) { list.setItemChecked(mCheckedItem, true); list.setSelectionFromTop(mCheckedItem, 0); } list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mListItemListener != null) { mListItemListener.onItemClick(parent, view, position, id); } dismiss(); } }); } else { findViewById(R.id.list).setVisibility(View.GONE); } // Positive Button boolean hasPositiveButton = false; if (mPositiveButtonText != null) { hasPositiveButton = true; ((TextView) findViewById(R.id.button_positive_label)).setText(mPositiveButtonText); if (mButtonTextStyle != 0) { ((TextView) findViewById(R.id.button_positive_label)).setTextAppearance(getContext(), mButtonTextStyle); } } if (mPositiveButtonListener != null) { hasPositiveButton = true; findViewById(R.id.button_positive).setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (mPositiveButtonListener != null) { mPositiveButtonListener.onClick(SimpleAlertDialog.this, 0); } dismiss(); } }); } if (!hasPositiveButton) { findViewById(R.id.button_positive).setVisibility(View.GONE); } // Neutral Button boolean hasNeutralButton = false; if (mNeutralButtonText != null) { hasNeutralButton = true; ((TextView) findViewById(R.id.button_neutral_label)).setText(mNeutralButtonText); if (mButtonTextStyle != 0) { ((TextView) findViewById(R.id.button_neutral_label)).setTextAppearance(getContext(), mButtonTextStyle); } } if (mNeutralButtonListener != null) { hasNeutralButton = true; findViewById(R.id.button_neutral).setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (mNeutralButtonListener != null) { mNeutralButtonListener.onClick(SimpleAlertDialog.this, 0); } dismiss(); } }); } if (!hasNeutralButton) { findViewById(R.id.button_neutral).setVisibility(View.GONE); } // Negative Button boolean hasNegativeButton = false; if (mNegativeButtonText != null) { hasNegativeButton = true; ((TextView) findViewById(R.id.button_negative_label)).setText(mNegativeButtonText); if (mButtonTextStyle != 0) { ((TextView) findViewById(R.id.button_negative_label)).setTextAppearance(getContext(), mButtonTextStyle); } } if (mNegativeButtonListener != null) { hasNegativeButton = true; findViewById(R.id.button_negative).setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (mNegativeButtonListener != null) { mNegativeButtonListener.onClick(SimpleAlertDialog.this, 1); } dismiss(); } }); } if (!hasNegativeButton) { findViewById(R.id.button_negative).setVisibility(View.GONE); } if (!hasPositiveButton && !hasNegativeButton) { findViewById(R.id.button_divider_top).setVisibility(View.GONE); findViewById(R.id.button_divider).setVisibility(View.GONE); } else if (!hasPositiveButton || !hasNegativeButton) { findViewById(R.id.button_divider).setVisibility(View.GONE); setBackground(R.id.button_divider_top, mButtonTopDividerBackground); } else { setBackground(R.id.button_divider_top, mButtonTopDividerBackground); setBackground(R.id.button_divider, mButtonVerticalDividerBackground); } if (hasNeutralButton) { setBackground(R.id.button_divider_neutral, mButtonVerticalDividerBackground); } else { findViewById(R.id.button_divider_neutral).setVisibility(View.GONE); } }
From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java
private void selectColorModel() { String[] choices = new String[COLORMODEL.values().length]; int currentSelection = -1; for (int i = 0; i < choices.length; i++) { COLORMODEL cm = COLORMODEL.values()[i]; choices[i] = cm.toString();//www. j ava2 s .c o m if (canvas.isColorModel(cm)) currentSelection = i; } final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); ListView list = new ListView(this); list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, choices)); list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setItemChecked(currentSelection, true); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { dialog.dismiss(); COLORMODEL cm = COLORMODEL.values()[arg2]; canvas.setColorModel(cm); connection.setColorModel(cm.nameString()); connection.save(database.getWritableDatabase()); database.close(); Toast.makeText(RemoteCanvasActivity.this, getString(R.string.info_update_color_model_to) + cm.toString(), Toast.LENGTH_SHORT).show(); } }); dialog.setContentView(list); dialog.show(); }
From source file:com.csipsimple.ui.filters.AccountFiltersListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ListView lv = getListView(); //getListView().setSelector(R.drawable.transparent); lv.setCacheColorHint(Color.TRANSPARENT); // View management View detailsFrame = getActivity().findViewById(R.id.details); dualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE; if (savedInstanceState != null) { // Restore last state for checked position. curCheckFilterId = savedInstanceState.getLong(CURRENT_CHOICE, SipProfile.INVALID_ID); //curCheckWizard = savedInstanceState.getString(CURRENT_WIZARD); }// ww w .j a v a 2 s . c o m setListShown(false); if (mAdapter == null) { if (mHeaderView != null) { lv.addHeaderView(mHeaderView, null, true); } mAdapter = new AccountFiltersListAdapter(getActivity(), null); //getListView().setEmptyView(getActivity().findViewById(R.id.progress_container)); //getActivity().findViewById(android.R.id.empty).setVisibility(View.GONE); setListAdapter(mAdapter); registerForContextMenu(lv); lv.setVerticalFadingEdgeEnabled(true); } if (dualPane) { // In dual-pane mode, the list view highlights the selected item. Log.d("lp", "dual pane mode"); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); //lv.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT); lv.setVerticalScrollBarEnabled(false); lv.setFadingEdgeLength(50); updateCheckedItem(); // Make sure our UI is in the correct state. //showDetails(curCheckPosition, curCheckWizard); } else { //getListView().setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT); lv.setVerticalScrollBarEnabled(true); lv.setFadingEdgeLength(100); } }
From source file:com.example.maciej.mytask.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar);// w ww . j a v a 2s .c o m createNotification(); mDateTimeTextView = (TextView) findViewById(R.id.dateTimeTextView); // final Button addTaskBtn = (Button) findViewById(R.id.addTaskBtn); final ListView listview = (ListView) findViewById(R.id.taskListview); // final CheckedTextView listitem = (CheckedTextView) findViewById(R.id.checkedTextView1); mNameList = new ArrayList<String>(); mDescriptionList = new ArrayList<String>(); mDateList = new ArrayList<String>(); String savedNameList = getSharedPreferences(PREFS_TASKS, MODE_PRIVATE).getString(KEY_NAME_LIST, null); if (savedNameList != null) { String[] name_items = savedNameList.split(","); mNameList = new ArrayList<String>(Arrays.asList(name_items)); } String savedDescriptionList = getSharedPreferences(PREFS_TASKS, MODE_PRIVATE) .getString(KEY_DESCRIPTION_LIST, null); if (savedDescriptionList != null) { String[] description_items = savedDescriptionList.split(","); mDescriptionList = new ArrayList<String>(Arrays.asList(description_items)); } String savedDateList = getSharedPreferences(PREFS_TASKS, MODE_PRIVATE).getString(KEY_DATE_LIST, null); if (savedDateList != null) { String[] date_items = savedDateList.split(","); mDateList = new ArrayList<String>(Arrays.asList(date_items)); } mAdapter = new ArrayAdapter<String>(this, R.layout.list_item, mNameList); listview.setAdapter(mAdapter); listview.setItemsCanFocus(false); listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { CheckedTextView item = (CheckedTextView) view; if (item.isChecked()) { Toast.makeText(getApplicationContext(), getString(R.string.checked), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), getString(R.string.unchecked), Toast.LENGTH_SHORT) .show(); } } }); listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { descriptionClicked(view); return true; } }); mTickReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) { mDateTimeTextView.setText(getCurrentTimeStamp()); } } }; }
From source file:com.todotxt.todotxttouch.TodoTxtTouch.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); currentActivityPointer = this; setContentView(R.layout.main);//www . jav a 2 s .c o m m_app = (TodoApplication) getApplication(); m_app.m_prefs.registerOnSharedPreferenceChangeListener(this); this.taskBag = m_app.getTaskBag(); m_adapter = new TaskAdapter(this, R.layout.list_item, taskBag.getTasks(), getLayoutInflater()); // listen to the ACTION_LOGOUT intent, if heard display LoginScreen // and finish() current activity IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constants.INTENT_ACTION_ARCHIVE); intentFilter.addAction(Constants.INTENT_SYNC_CONFLICT); intentFilter.addAction(Constants.INTENT_ACTION_LOGOUT); intentFilter.addAction(Constants.INTENT_UPDATE_UI); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); m_broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equalsIgnoreCase(Constants.INTENT_ACTION_ARCHIVE)) { // archive // refresh screen to remove completed tasks // push to remote //archiveTasks(); } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_ACTION_LOGOUT)) { taskBag.clear(); m_app.broadcastWidgetUpdate(); // Intent i = new Intent(context, LoginScreen.class); // startActivity(i); // finish(); } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_UPDATE_UI)) { updateSyncUI(intent.getBooleanExtra("redrawList", false)); } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_SYNC_CONFLICT)) { handleSyncConflict(); } else if (intent.getAction().equalsIgnoreCase(ConnectivityManager.CONNECTIVITY_ACTION)) { handleConnectivityChange(context); } // Taskbag might have changed, update drawer adapter // to reflect new/removed contexts and projects updateNavigationDrawer(); } }; registerReceiver(m_broadcastReceiver, intentFilter); setListAdapter(this.m_adapter); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // Setup Navigation drawer m_drawerList = (ListView) findViewById(R.id.left_drawer); m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // Set the adapter for the list view updateNavigationDrawer(); SwipeDismissList.OnDismissCallback callback = new SwipeDismissList.OnDismissCallback() { // Gets called whenever the user deletes an item. public SwipeDismissList.Undoable onDismiss(AbsListView listView, final int position) { m_swipeList.setEnabled(false); final Task task = m_adapter.getItem(position); m_adapter.remove(task); ArrayList<Task> tasks = new ArrayList<Task>(); tasks.add(task); final boolean wasComplete = task.isCompleted(); final String popupTitle = listView.getResources() .getString(wasComplete ? R.string.swipe_action_unComplete : R.string.swipe_action_complete); if (wasComplete) { undoCompleteTasks(tasks, false); } else { completeTasks(tasks, false); } // Return an Undoable implementing every method return new SwipeDismissList.Undoable() { // Method is called when user undoes this deletion public void undo() { // Reinsert item to list ArrayList<Task> tasks = new ArrayList<Task>(); tasks.add(task); if (wasComplete) { completeTasks(tasks, false); } else { undoCompleteTasks(tasks, false); } } @Override public String getTitle() { return popupTitle; } }; } }; m_swipeList = new SwipeDismissList(lv, callback, SwipeDismissList.UndoMode.SINGLE_UNDO); m_swipeList.setPopupYOffset(56); m_swipeList.setAutoHideDelay(250); m_swipeList.setSwipeLayout(R.id.swipe_view); m_pullToRefreshAttacher = PullToRefreshAttacher.get(this); DefaultHeaderTransformer ht = (DefaultHeaderTransformer) m_pullToRefreshAttacher.getHeaderTransformer(); ht.setPullText(getString(R.string.pull_to_refresh)); ht.setRefreshingText(getString(R.string.syncing)); m_pullToRefreshAttacher.addRefreshableView(lv, this); // Delegate OnTouch calls to both libraries that want to receive them // Don't forward swipes when swiping on the left lv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { // Don't listen to gestures on the left area of the list // to prevent interference with the DrawerLayout ViewConfiguration vc = ViewConfiguration.get(view.getContext()); int deadZoneX = vc.getScaledTouchSlop(); if (motionEvent.getX() < deadZoneX) { return false; } m_pullToRefreshAttacher.onTouch(view, motionEvent); // Only listen to item swipes if we are not scrolling the // listview if (!mListScrolling && m_swipeList.onTouch(view, motionEvent)) { return false; } return false; } }); // We must set the scrollListener after the onTouchListener, // otherwise it will not fire lv.setOnScrollListener(this); initializeTasks(false); // Show search results Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { m_app.m_search = intent.getStringExtra(SearchManager.QUERY); Log.v(TAG, "Searched for " + m_app.m_search); m_app.storeFilters(); setFilteredTasks(false); } }
From source file:org.namelessrom.devicecontrol.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // setup action bar final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//w w w . j a v a 2s .c o m toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mSubFragmentTitle == -1) { sSlidingMenu.toggle(true); } else { onCustomBackPressed(true); } } }); // setup material menu icon sMaterialMenu = new MaterialMenuIconToolbar(this, Color.WHITE, MaterialMenuDrawable.Stroke.THIN) { @Override public int getToolbarViewId() { return R.id.toolbar; } }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { sMaterialMenu.setNeverDrawTouch(true); } Utils.setupDirectories(); final FrameLayout container = (FrameLayout) findViewById(R.id.container); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { container.setBackground(null); } else { //noinspection deprecation container.setBackgroundDrawable(null); } final View v = getLayoutInflater().inflate(R.layout.menu_list, container, false); final ListView menuList = (ListView) v.findViewById(R.id.navbarlist); final LinearLayout menuContainer = (LinearLayout) v.findViewById(R.id.menu_container); // setup our static items menuContainer.findViewById(R.id.menu_prefs).setOnClickListener(this); menuContainer.findViewById(R.id.menu_about).setOnClickListener(this); sSlidingMenu = new SlidingMenu(this); sSlidingMenu.setMode(SlidingMenu.LEFT); sSlidingMenu.setShadowWidthRes(R.dimen.shadow_width); sSlidingMenu.setShadowDrawable(R.drawable.shadow_left); sSlidingMenu.setBehindWidthRes(R.dimen.slidingmenu_offset); sSlidingMenu.setFadeEnabled(true); sSlidingMenu.setFadeDegree(0.45f); sSlidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); sSlidingMenu.setMenu(v); // setup touch mode MainActivity.setSwipeOnContent(DeviceConfiguration.get(this).swipeOnContent); // setup menu list setupMenuLists(); final MenuListArrayAdapter mAdapter = new MenuListArrayAdapter(this, R.layout.menu_main_list_item, mMenuEntries, mMenuIcons); menuList.setAdapter(mAdapter); menuList.setChoiceMode(ListView.CHOICE_MODE_SINGLE); menuList.setOnItemClickListener(this); loadFragmentPrivate(DeviceConstants.ID_ABOUT, false); getSupportFragmentManager().executePendingTransactions(); Utils.startTaskerService(); final String downgradePath = getFilesDir() + DeviceConstants.DC_DOWNGRADE; if (Utils.fileExists(downgradePath)) { if (!new File(downgradePath).delete()) { Logger.wtf(this, "Could not delete downgrade indicator file!"); } Toast.makeText(this, R.string.downgraded, Toast.LENGTH_LONG).show(); } if (DeviceConfiguration.get(this).dcFirstStart) { DeviceConfiguration.get(this).dcFirstStart = false; DeviceConfiguration.get(this).saveConfiguration(this); } }
From source file:nl.mpcjanssen.simpletask.Simpletask.java
private void handleIntent() { if (!m_app.isAuthenticated()) { Log.v(TAG, "handleIntent: not authenticated"); startLogin();/*from w w w . j a va2 s . co m*/ return; } if (!m_app.initialSyncDone()) { m_sync_dialog = new ProgressDialog(this, m_app.getActiveTheme()); m_sync_dialog.setIndeterminate(true); m_sync_dialog.setMessage("Initial Dropbox sync in progress, please wait...."); m_sync_dialog.setCancelable(false); m_sync_dialog.show(); } else if (m_sync_dialog != null) { m_sync_dialog.cancel(); } mFilter = new ActiveFilter(); m_leftDrawerList = (ListView) findViewById(R.id.left_drawer); m_rightDrawerList = (ListView) findViewById(R.id.right_drawer_list); m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // Set the list's click listener m_leftDrawerList.setOnItemClickListener(new DrawerItemClickListener()); if (m_drawerLayout != null) { m_drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ m_drawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */ R.string.changelist, /* "open drawer" description */ R.string.app_label /* "close drawer" description */ ) { /** * Called when a drawer has settled in a completely closed * state. */ public void onDrawerClosed(View view) { // setTitle(R.string.app_label); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { // setTitle(R.string.changelist); } }; // Set the drawer toggle as the DrawerListener m_drawerLayout.setDrawerListener(m_drawerToggle); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); } m_drawerToggle.syncState(); } // Show search or filter results Intent intent = getIntent(); if (Constants.INTENT_START_FILTER.equals(intent.getAction())) { mFilter.initFromIntent(intent); Log.v(TAG, "handleIntent: launched with filter" + mFilter); Log.v(TAG, "handleIntent: saving filter in prefs"); mFilter.saveInPrefs(TodoApplication.getPrefs()); } else { // Set previous filters and sort Log.v(TAG, "handleIntent: from m_prefs state"); mFilter.initFromPrefs(TodoApplication.getPrefs()); } // Initialize Adapter if (m_adapter == null) { m_adapter = new TaskAdapter(getLayoutInflater()); } m_adapter.setFilteredTasks(); getListView().setAdapter(this.m_adapter); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv.setMultiChoiceModeListener(new ActionBarListener()); lv.setClickable(true); lv.setOnItemClickListener(this); // If we were started with a selected task, // select it now and clear it from the intent String selectedTask = intent.getStringExtra(Constants.INTENT_SELECTED_TASK); if (!Strings.isEmptyOrNull(selectedTask)) { String[] parts = selectedTask.split(":", 2); setSelectedTask(Integer.valueOf(parts[0]), parts[1]); intent.removeExtra(Constants.INTENT_SELECTED_TASK); setIntent(intent); } else { // Set the adapter for the list view updateDrawers(); } if (m_savedInstanceState != null) { ArrayList<String> selection = m_savedInstanceState.getStringArrayList("selection"); int position = m_savedInstanceState.getInt("position"); if (selection != null) { for (String selected : selection) { String[] parts = selected.split(":", 2); setSelectedTask(Integer.valueOf(parts[0]), parts[1]); } } lv.setSelectionFromTop(position, 0); } }
From source file:androidVNC.VncCanvasActivity.java
private void selectColorModel() { // Stop repainting the desktop // because the display is composited! vncCanvas.disableRepaints();/*from w w w . j av a2 s. co m*/ String[] choices = new String[COLORMODEL.values().length]; int currentSelection = -1; for (int i = 0; i < choices.length; i++) { COLORMODEL cm = COLORMODEL.values()[i]; choices[i] = cm.toString(); if (vncCanvas.isColorModel(cm)) currentSelection = i; } final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); ListView list = new ListView(this); list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, choices)); list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setItemChecked(currentSelection, true); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { dialog.dismiss(); COLORMODEL cm = COLORMODEL.values()[arg2]; vncCanvas.setColorModel(cm); connection.setColorModel(cm.nameString()); connection.save(database.getWritableDatabase()); //Toast.makeText(VncCanvasActivity.this,"Updating Color Model to " + cm.toString(), Toast.LENGTH_SHORT).show(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { Log.i(TAG, "Color Model Selector dismissed"); // Restore desktop repaints vncCanvas.enableRepaints(); } }); dialog.setContentView(list); dialog.show(); }
From source file:nl.mpcjanssen.simpletask.Simpletask.java
private void updateLists(@NotNull final List<Task> checkedTasks) { final ArrayList<String> contexts = new ArrayList<String>(); Set<String> selectedContexts = new HashSet<String>(); final TaskCache taskbag = getTaskBag(); contexts.addAll(Util.sortWithPrefix(taskbag.getContexts(), m_app.sortCaseSensitive(), null)); for (Task t : checkedTasks) { selectedContexts.addAll(t.getLists()); }/*from ww w . j a v a2 s. co m*/ @SuppressLint("InflateParams") View view = getLayoutInflater().inflate(R.layout.tag_dialog, null, false); final ListView lv = (ListView) view.findViewById(R.id.listView); lv.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_multiple_choice, contexts.toArray(new String[contexts.size()]))); lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE); for (String context : selectedContexts) { int position = contexts.indexOf(context); if (position != -1) { lv.setItemChecked(position, true); } } final EditText ed = (EditText) view.findViewById(R.id.editText); m_app.setEditTextHint(ed, R.string.new_list_name); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(view); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ArrayList<String> originalLines = new ArrayList<String>(); originalLines.addAll(Util.tasksToString(getCheckedTasks())); ArrayList<String> items = new ArrayList<String>(); ArrayList<String> uncheckedItesm = new ArrayList<String>(); uncheckedItesm.addAll(Util.getCheckedItems(lv, false)); items.addAll(Util.getCheckedItems(lv, true)); String newText = ed.getText().toString(); if (!newText.equals("")) { items.add(ed.getText().toString()); } for (String item : items) { for (Task t : checkedTasks) { t.addList(item); } } for (String item : uncheckedItesm) { for (Task t : checkedTasks) { t.removeTag("@" + item); } } finishActionmode(); m_app.getTaskCache(null).modify(originalLines, checkedTasks, null, null); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog } }); // Create the AlertDialog AlertDialog dialog = builder.create(); dialog.setTitle(R.string.update_lists); dialog.show(); }