List of usage examples for android.widget AdapterView getAdapter
public abstract T getAdapter();
From source file:com.brandroidtools.filemanager.fragments.NavigationFragment.java
/** * {@inheritDoc}/*from ww w. j av a 2 s. c om*/ */ @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // Different actions depending on user preference // Get the adapter and the fso FileSystemObjectAdapter adapter = ((FileSystemObjectAdapter) parent.getAdapter()); FileSystemObject fso = adapter.getItem(position); // Parent directory hasn't actions if (fso instanceof ParentDirectory) { return false; } // Pick mode doesn't implements the onlongclick if (this.mNavigationMode.compareTo(NAVIGATION_MODE.PICKABLE) == 0) { return false; } updateSelectionMode(); return true; //Always consume the event }
From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java
/** * Method that shows a popup with a menu associated a {@link com.brandroidtools.filemanager.preferences.FileManagerSettings}. * * @param anchor The action button that was pressed * @param settings The array of settings associated with the action button *//* ww w. j av a2 s . co m*/ private void showSettingsPopUp(View anchor, List<FileManagerSettings> settings) { //Create the adapter final MenuSettingsAdapter adapter = new MenuSettingsAdapter(this, settings); //Create a show the popup menu final ListPopupWindow popup = DialogHelper.createListPopupWindow(this, adapter, anchor); popup.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { FileManagerSettings setting = ((MenuSettingsAdapter) parent.getAdapter()).getSetting(position); final int value = ((MenuSettingsAdapter) parent.getAdapter()).getId(position); popup.dismiss(); try { if (setting.compareTo(FileManagerSettings.SETTINGS_LAYOUT_MODE) == 0) { //Need to change the layout getCurrentNavigationFragment().changeViewMode(NavigationLayoutMode.fromId(value)); } else { //Save and refresh if (setting.getDefaultValue() instanceof Enum<?>) { //Enumeration Preferences.savePreference(setting, new ObjectIdentifier() { @Override public int getId() { return value; } }, false); } else { //Boolean boolean newval = Preferences.getSharedPreferences().getBoolean(setting.getId(), ((Boolean) setting.getDefaultValue()).booleanValue()); Preferences.savePreference(setting, Boolean.valueOf(!newval), false); } getCurrentNavigationFragment().refresh(); } } catch (Exception e) { Log.e(TAG, "Error applying navigation option", e); //$NON-NLS-1$ NavigationActivity.this.mHandler.post(new Runnable() { @Override public void run() { DialogHelper.showToast(NavigationActivity.this, R.string.msgs_settings_save_failure, Toast.LENGTH_SHORT); } }); } finally { adapter.dispose(); getCurrentNavigationFragment().getCustomTitle().restoreView(); } } }); popup.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { adapter.dispose(); } }); popup.show(); }
From source file:com.asksven.betterbatterystats.StatsActivity.java
/** * Take the change of selection from the spinners into account and refresh the ListView * with the right data/*from www .j av a 2 s. co m*/ */ public void onItemSelected(AdapterView<?> parent, View v, int position, long id) { // this method is fired even if nothing has changed so we nee to find that out SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); boolean bChanged = false; // id is in the order of the spinners, 0 is stat, 1 is stat_type if (parent == (Spinner) findViewById(R.id.spinnerStatType)) { // detect if something changed String newStat = (String) ((ReferencesAdapter) parent.getAdapter()).getItemName(position); if ((m_refFromName != null) && (!m_refFromName.equals(newStat))) { if (LogSettings.DEBUG) Log.i(TAG, "Spinner from changed from " + m_refFromName + " to " + newStat); m_refFromName = newStat; bChanged = true; // we need to update the second spinner m_spinnerToAdapter.filterToSpinner(newStat, this); m_spinnerToAdapter.notifyDataSetChanged(); // select the right element Spinner spinnerStatSampleEnd = (Spinner) findViewById(R.id.spinnerStatSampleEnd); if (spinnerStatSampleEnd.isShown()) { spinnerStatSampleEnd.setSelection(m_spinnerToAdapter.getPosition(m_refToName)); } else { spinnerStatSampleEnd .setSelection(m_spinnerToAdapter.getPosition(Reference.CURRENT_REF_FILENAME)); } } else { return; } } else if (parent == (Spinner) findViewById(R.id.spinnerStatSampleEnd)) { String newStat = (String) ((ReferencesAdapter) parent.getAdapter()).getItemName(position); if ((m_refFromName != null) && (!m_refToName.equals(newStat))) { if (LogSettings.DEBUG) Log.i(TAG, "Spinner to changed from " + m_refToName + " to " + newStat); m_refToName = newStat; bChanged = true; } else { return; } } else if (parent == (Spinner) findViewById(R.id.spinnerStat)) { int iNewStat = position; if (m_iStat != iNewStat) { m_iStat = iNewStat; bChanged = true; } else { return; } } else { Log.e(TAG, "ProcessStatsActivity.onItemSelected error. ID could not be resolved"); Toast.makeText(this, getString(R.string.info_unknown_state), Toast.LENGTH_SHORT).show(); } Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, this); Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, this); TextView tvSince = (TextView) findViewById(R.id.TextViewSince); long sinceMs = StatsProvider.getInstance().getSince(myReferenceFrom, myReferenceTo); if (sinceMs != -1) { String sinceText = DateUtils.formatDuration(sinceMs); sinceText += " " + StatsProvider.getInstance().getBatteryLevelFromTo(myReferenceFrom, myReferenceTo, true); tvSince.setText(sinceText); if (LogSettings.DEBUG) Log.i(TAG, "Since " + sinceText); } else { tvSince.setText("n/a "); if (LogSettings.DEBUG) Log.i(TAG, "Since: n/a "); } // @todo fix this: this method is called twice //m_listViewAdapter.notifyDataSetChanged(); if (bChanged) { // as the source changed fetch the data doRefresh(false); } }
From source file:universe.constellation.orion.viewer.OrionViewerActivity.java
public void initZoomScreen() { //zoom screen final Spinner sp = (Spinner) findMyViewById(R.id.zoom_spinner); final EditText zoomText = (EditText) findMyViewById(R.id.zoom_picker_message); final SeekBar zoomSeek = (SeekBar) findMyViewById(R.id.zoom_picker_seeker); if (zoomSeek != null) { zoomSeek.setMax(300);/* www . j av a 2s . co m*/ zoomSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (zoomInternal != 1) { zoomText.setText("" + progress); if (sp.getSelectedItemPosition() != 0) { int oldInternal = zoomInternal; zoomInternal = 2; sp.setSelection(0); zoomInternal = oldInternal; } } } public void onStartTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) { } }); } getSubscriptionManager().addDocListeners(new DocumentViewAdapter() { @Override public void documentOpened(Controller controller) { updateZoom(); } }); final ImageButton zplus = (ImageButton) findMyViewById(R.id.zoom_picker_plus); zplus.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { zoomSeek.incrementProgressBy(1); } }); final ImageButton zminus = (ImageButton) findMyViewById(R.id.zoom_picker_minus); zminus.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (zoomSeek.getProgress() != 0) { zoomSeek.incrementProgressBy(-1); } } }); ImageButton closeZoomPeeker = (ImageButton) findMyViewById(R.id.zoom_picker_close); closeZoomPeeker.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //main menu onAnimatorCancel(); //updateZoom(); } }); ImageButton zoom_preview = (ImageButton) findMyViewById(R.id.zoom_preview); zoom_preview.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onApplyAction(); int index = sp.getSelectedItemPosition(); controller.changeZoom(index == 0 ? (int) (Float.parseFloat(zoomText.getText().toString()) * 100) : -1 * (index - 1)); updateZoom(); } }); sp.setAdapter(new MyArrayAdapter()); sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { boolean disable = position != 0; int oldZoomInternal = zoomInternal; if (zoomInternal != 2) { zoomInternal = 1; if (disable) { zoomText.setText((String) parent.getAdapter().getItem(position)); } else { zoomText.setText("" + ((int) (controller.getCurrentPageZoom() * 10000)) / 100f); zoomSeek.setProgress((int) (controller.getCurrentPageZoom() * 100)); } zoomInternal = oldZoomInternal; } zminus.setVisibility(disable ? View.GONE : View.VISIBLE); zplus.setVisibility(disable ? View.GONE : View.VISIBLE); zoomText.setFocusable(!disable); zoomText.setFocusableInTouchMode(!disable); final LinearLayout parent1 = (LinearLayout) zoomText.getParent(); parent1.post(new Runnable() { @Override public void run() { parent1.requestLayout(); } }); } public void onNothingSelected(AdapterView<?> parent) { //To change body of implemented methods use File | Settings | File Templates. } }); //by width sp.setSelection(1); }
From source file:org.brandroid.openmanager.fragments.ContentFragment.java
public boolean onItemLongClick(AdapterView<?> list, final View view, int pos, long id) { mMenuContextItemIndex = pos;/*w w w.ja v a 2 s . c o m*/ //view.setBackgroundResource(R.drawable.selector_blue); //list.setSelection(pos); //if(list.showContextMenu()) return true; final OpenPath file = (OpenPath) ((BaseAdapter) list.getAdapter()).getItem(pos); return createContextMenu(file, list, view, pos); }
From source file:com.brandroidtools.filemanager.fragments.NavigationFragment.java
/** * Method that change the view mode./*www. j a v a2 s . c om*/ * * @param newMode The new mode */ @SuppressWarnings({ "unchecked", "null" }) public void changeViewMode(final NavigationLayoutMode newMode) { synchronized (this.mSync) { //Check that it is really necessary change the mode if (this.mCurrentMode != null && this.mCurrentMode.compareTo(newMode) == 0) { return; } // If we should set the listview to response to flinger gesture detection boolean useFlinger = Preferences.getSharedPreferences().getBoolean( FileManagerSettings.SETTINGS_USE_FLINGER.getId(), ((Boolean) FileManagerSettings.SETTINGS_USE_FLINGER.getDefaultValue()).booleanValue()); //Creates the new layout AdapterView<ListAdapter> newView = null; int itemResourceId = -1; if (newMode.compareTo(NavigationLayoutMode.ICONS) == 0) { newView = (AdapterView<ListAdapter>) mNavigationViewHolder.inflate(mActivity, RESOURCE_MODE_ICONS_LAYOUT, null); itemResourceId = RESOURCE_MODE_ICONS_ITEM; } else if (newMode.compareTo(NavigationLayoutMode.SIMPLE) == 0) { newView = (AdapterView<ListAdapter>) mNavigationViewHolder.inflate(mActivity, RESOURCE_MODE_SIMPLE_LAYOUT, null); itemResourceId = RESOURCE_MODE_SIMPLE_ITEM; // Set the flinger listener (only when navigate) if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) { if (useFlinger && newView instanceof FlingerListView) { ((FlingerListView) newView).setOnItemFlingerListener(this.mOnItemFlingerListener); } } } else if (newMode.compareTo(NavigationLayoutMode.DETAILS) == 0) { newView = (AdapterView<ListAdapter>) mNavigationViewHolder.inflate(mActivity, RESOURCE_MODE_DETAILS_LAYOUT, null); itemResourceId = RESOURCE_MODE_DETAILS_ITEM; // Set the flinger listener (only when navigate) if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) { if (useFlinger && newView instanceof FlingerListView) { ((FlingerListView) newView).setOnItemFlingerListener(this.mOnItemFlingerListener); } } } //Get the current adapter and its adapter list List<FileSystemObject> files = new ArrayList<FileSystemObject>(this.mFiles); final AdapterView<ListAdapter> current = (AdapterView<ListAdapter>) getView() .findViewById(RESOURCE_CURRENT_LAYOUT); FileSystemObjectAdapter adapter = new FileSystemObjectAdapter(mActivity, new ArrayList<FileSystemObject>(), itemResourceId, this.mNavigationMode.compareTo(NAVIGATION_MODE.PICKABLE) == 0); adapter.setOnSelectionChangedListener(this); //Remove current layout if (current != null) { if (current.getAdapter() != null) { //Save selected items before dispose adapter FileSystemObjectAdapter currentAdapter = ((FileSystemObjectAdapter) current.getAdapter()); adapter.setSelectedItems(currentAdapter.getSelectedItems()); currentAdapter.dispose(); } mNavigationViewHolder.removeView(current); } this.mFiles = files; adapter.addAll(files); adapter.notifyDataSetChanged(); //Set the adapter this.mAdapter = adapter; newView.setAdapter(this.mAdapter); newView.setOnItemClickListener(NavigationFragment.this); //Add the new layout this.mAdapterView = newView; mNavigationViewHolder.addView(newView, 0); this.mCurrentMode = newMode; // Pick mode doesn't implements the onlongclick if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) { this.mAdapterView.setOnItemLongClickListener(this); } else { this.mAdapterView.setOnItemLongClickListener(null); } //Save the preference (only in navigation browse mode) if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) { try { Preferences.savePreference(FileManagerSettings.SETTINGS_LAYOUT_MODE, newMode, true); } catch (Exception ex) { Log.e(TAG, "Save of view mode preference fails", ex); //$NON-NLS-1$ } } } }
From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java
void setupSettings() { final String[] refreshPreferenceOptions = getResources().getStringArray(R.array.refresh_preference_options); ArrayAdapter<String> refreshOptionsAdapter = new ArrayAdapter<>(this, R.layout.spinner_item, refreshPreferenceOptions);//from w w w. j a v a 2s . c om refreshOptionsAdapter.setDropDownViewResource(R.layout.spinner_drop_down_item); Spinner refreshSpinner = findById(settingsContainer, R.id.spinner_lwq_settings_refresh); refreshSpinner.setAdapter(refreshOptionsAdapter); refreshSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) { // Log refresh rate choice LWQLoggerHelper.get().logRefreshRate((String) adapterView.getAdapter().getItem(index)); final int[] refreshValues = getResources().getIntArray(R.array.refresh_preference_values); LWQPreferences.setRefreshPreference(refreshValues[index]); LWQAlarmController.resetAlarm(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); updateRefreshSpinner(); // Blur if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { findById(settingsContainer, R.id.sb_lwq_settings_blur).setVisibility(View.GONE); } else { SeekBar blurBar = findById(settingsContainer, R.id.sb_lwq_settings_blur); blurBar.setProgress(LWQPreferences.getBlurPreference()); blurBar.setOnSeekBarChangeListener(this); } // Dim SeekBar dimBar = findById(settingsContainer, R.id.sb_lwq_settings_dim); dimBar.setProgress(LWQPreferences.getDimPreference()); dimBar.setOnSeekBarChangeListener(this); AppCompatCheckBox doubleTapCheckbox = findById(this, R.id.check_lwq_settings_double_tap); doubleTapCheckbox.setChecked(LWQPreferences.isDoubleTapEnabled()); // Fonts findById(settingsContainer, R.id.btn_lwq_settings_fonts).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { chooseFontsDialog = new MaterialDialog.Builder(LWQSettingsActivity.this).title("Choose Fonts") .adapter(new FontMultiselectAdapter(LWQSettingsActivity.this), LWQSettingsActivity.this) .alwaysCallMultiChoiceCallback().autoDismiss(false).canceledOnTouchOutside(true) .cancelListener(LWQSettingsActivity.this).build(); chooseFontsDialog.show(); // Log view AnalyticsUtils.trackScreenView(AnalyticsUtils.SCREEN_FONTS); } }); // Images findById(settingsContainer, R.id.btn_lwq_settings_images).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { changeState(stateChooseImageSources); // Log view AnalyticsUtils.trackScreenView(AnalyticsUtils.SCREEN_IMAGES); } }); }
From source file:com.benefit.buy.library.http.query.AbstractAQuery.java
/** * Notify a ListView that the data of it's adapter is changed. * @return self/* w ww .j av a 2 s . c o m*/ */ public T dataChanged() { if (view instanceof AdapterView) { AdapterView<?> av = (AdapterView<?>) view; Adapter a = av.getAdapter(); if (a instanceof BaseAdapter) { BaseAdapter ba = (BaseAdapter) a; ba.notifyDataSetChanged(); } } return self(); }
From source file:com.ymt.demo1.plates.news.FileNoticeFragment.java
protected void initView(View view) { /*/* w ww . java 2 s.c o m*/ *listView */ listView = (PullToRefreshListView) view.findViewById(R.id.pull_to_refresh_list_view); ListView theListView = listView.getRefreshableView(); testArray = new ArrayList<>(); ProgressBar progressBar = new ProgressBar(getActivity()); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); progressBar.setLayoutParams(params); listView.setEmptyView(progressBar); /* ?? */ summaryAdapter = new NewsSummaryAdapter(getActivity()); listView.setAdapter(summaryAdapter); summaryAdapter.setList(testArray); scrollView.setListView(listView); //???listView? /* *?? */ theListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, final View view, final int position, long id) { /* *??? */ String[] actionList = new String[] { "", "?" }; PopActionUtil popActionUtil = PopActionUtil.getInstance(getActivity()); actionListener = new PopActionListener() { @Override public void onAction(String action) { switch (action) { case "": Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT).show(); break; case "?": Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT).show(); break; default: break; } } @Override public void onDismiss() { } }; popActionUtil.setActionListener(actionListener); popActionUtil.setActions(actionList); final PopupWindow itemPopMenu = popActionUtil.getSimpleTxtPopActionMenu(); itemPopMenu.showAsDropDown(view, view.getWidth() - 20, -view.getHeight()); itemPopMenu.update(); return true; } }); /* listView ? */ theListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // //todo bug Intent intent = new Intent(getActivity(), NewsDetailActivity.class); NewsSummary summary = (NewsSummary) (parent.getAdapter()).getItem(position); intent.putExtra("summary", summary); intent.putExtra("type", "notice"); startActivity(intent); } }); /* * */ listView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) { mNews.clear(); startPosition = 1; mQueue.add(summaryRequest(state, start, pagesize)); } @Override public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) { startPosition++; mQueue.add(summaryRequest(state, start, pagesize)); } }); }