use of android.database.DataSetObserver in project android_frameworks_base by crdroidandroid.
the class SelectPrinterActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setIcon(R.drawable.ic_print);
setContentView(R.layout.select_printer_activity);
mEnabledPrintServices = new ArrayMap<>();
mPrinterRegistry = new PrinterRegistry(this, null, LOADER_ID_PRINT_REGISTRY, LOADER_ID_PRINT_REGISTRY_INT);
// Hook up the list view.
mListView = (ListView) findViewById(android.R.id.list);
final DestinationAdapter adapter = new DestinationAdapter();
adapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
if (!isFinishing() && adapter.getCount() <= 0) {
updateEmptyView(adapter);
}
}
@Override
public void onInvalidated() {
if (!isFinishing()) {
updateEmptyView(adapter);
}
}
});
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (!((DestinationAdapter) mListView.getAdapter()).isActionable(position)) {
return;
}
PrinterInfo printer = (PrinterInfo) mListView.getAdapter().getItem(position);
if (printer == null) {
startAddPrinterActivity();
} else {
onPrinterSelected(printer);
}
}
});
findViewById(R.id.button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startAddPrinterActivity();
}
});
registerForContextMenu(mListView);
getLoaderManager().initLoader(LOADER_ID_ENABLED_PRINT_SERVICES, null, this);
// If some are disabled and some are enabled show a toast to notify the user
if (savedInstanceState == null || !savedInstanceState.getBoolean(KEY_NOT_FIRST_CREATE)) {
List<PrintServiceInfo> allServices = ((PrintManager) getSystemService(Context.PRINT_SERVICE)).getPrintServices(PrintManager.ALL_SERVICES);
boolean hasEnabledServices = false;
boolean hasDisabledServices = false;
if (allServices != null) {
final int numServices = allServices.size();
for (int i = 0; i < numServices; i++) {
if (allServices.get(i).isEnabled()) {
hasEnabledServices = true;
} else {
hasDisabledServices = true;
}
}
}
if (!hasEnabledServices) {
startAddPrinterActivity();
} else if (hasDisabledServices) {
String disabledServicesSetting = Settings.Secure.getString(getContentResolver(), Settings.Secure.DISABLED_PRINT_SERVICES);
if (!TextUtils.isEmpty(disabledServicesSetting)) {
Toast.makeText(this, getString(R.string.print_services_disabled_toast), Toast.LENGTH_LONG).show();
}
}
}
}
use of android.database.DataSetObserver in project android_frameworks_base by crdroidandroid.
the class CalendarViewLegacyDelegate method setUpAdapter.
/**
* Creates a new adapter if necessary and sets up its parameters.
*/
private void setUpAdapter() {
if (mAdapter == null) {
mAdapter = new WeeksAdapter(mContext);
mAdapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
if (mOnDateChangeListener != null) {
Calendar selectedDay = mAdapter.getSelectedDay();
mOnDateChangeListener.onSelectedDayChange(mDelegator, selectedDay.get(Calendar.YEAR), selectedDay.get(Calendar.MONTH), selectedDay.get(Calendar.DAY_OF_MONTH));
}
}
});
mListView.setAdapter(mAdapter);
}
// refresh the view with the new parameters
mAdapter.notifyDataSetChanged();
}
use of android.database.DataSetObserver in project little-bear-dictionary by daimajia.
the class CalendarView method setUpAdapter.
private void setUpAdapter() {
if (mAdapter == null) {
mAdapter = new WeeksAdapter(getContext());
mAdapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
if (mOnDateChangeListener != null) {
Calendar selectedDay = mAdapter.getSelectedDay();
mOnDateChangeListener.onSelectedDayChange(CalendarView.this, selectedDay.get(Calendar.YEAR), selectedDay.get(Calendar.MONTH), selectedDay.get(Calendar.DAY_OF_MONTH));
}
}
});
mListView.setAdapter(mAdapter);
}
mAdapter.notifyDataSetChanged();
}
use of android.database.DataSetObserver in project android_frameworks_base by DirtyUnicorns.
the class CalendarViewLegacyDelegate method setUpAdapter.
/**
* Creates a new adapter if necessary and sets up its parameters.
*/
private void setUpAdapter() {
if (mAdapter == null) {
mAdapter = new WeeksAdapter(mContext);
mAdapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
if (mOnDateChangeListener != null) {
Calendar selectedDay = mAdapter.getSelectedDay();
mOnDateChangeListener.onSelectedDayChange(mDelegator, selectedDay.get(Calendar.YEAR), selectedDay.get(Calendar.MONTH), selectedDay.get(Calendar.DAY_OF_MONTH));
}
}
});
mListView.setAdapter(mAdapter);
}
// refresh the view with the new parameters
mAdapter.notifyDataSetChanged();
}
use of android.database.DataSetObserver in project qualitymatters by artem-zinnatullin.
the class DeveloperSettingsSpinnerAdapterTest method setSelectableOptions_shouldNotifyObservers.
@Test
public void setSelectableOptions_shouldNotifyObservers() {
DataSetObserver dataSetObserver = mock(DataSetObserver.class);
adapter.registerDataSetObserver(dataSetObserver);
verifyZeroInteractions(dataSetObserver);
adapter.setSelectionOptions(emptyList());
verify(dataSetObserver).onChanged();
}
Aggregations