Search in sources :

Example 31 with DataSetObserver

use of android.database.DataSetObserver in project android_frameworks_base by ParanoidAndroid.

the class CalendarView method setUpAdapter.

/**
     * Creates a new adapter if necessary and sets up its parameters.
     */
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);
    }
    // refresh the view with the new parameters
    mAdapter.notifyDataSetChanged();
}
Also used : Calendar(java.util.Calendar) DataSetObserver(android.database.DataSetObserver)

Example 32 with DataSetObserver

use of android.database.DataSetObserver in project material-intro-screen by TangoAgency.

the class InkPageIndicator method setViewPager.

public void setViewPager(final SwipeableViewPager viewPager) {
    this.viewPager = viewPager;
    viewPager.addOnPageChangeListener(this);
    setPageCount(getCount());
    viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() {

        @Override
        public void onChanged() {
            setPageCount(getCount());
        }
    });
    setCurrentPageImmediate();
}
Also used : DataSetObserver(android.database.DataSetObserver)

Example 33 with DataSetObserver

use of android.database.DataSetObserver in project android_frameworks_base by AOSPA.

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();
            }
        }
    }
}
Also used : PrintManager(android.print.PrintManager) DataSetObserver(android.database.DataSetObserver) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) PrintServiceInfo(android.printservice.PrintServiceInfo) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView) PrinterInfo(android.print.PrinterInfo)

Example 34 with DataSetObserver

use of android.database.DataSetObserver in project AntennaPod by AntennaPod.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(UserPreferences.getNoTitleTheme());
    super.onCreate(savedInstanceState);
    StorageUtils.checkStorageAvailability(this);
    setContentView(R.layout.main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        findViewById(R.id.shadow).setVisibility(View.GONE);
        int elevation = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
        getSupportActionBar().setElevation(elevation);
    }
    currentTitle = getTitle();
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    navList = (ListView) findViewById(R.id.nav_list);
    navDrawer = findViewById(R.id.nav_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close);
    if (savedInstanceState != null) {
        int backstackCount = savedInstanceState.getInt(SAVE_BACKSTACK_COUNT, 0);
        drawerToggle.setDrawerIndicatorEnabled(backstackCount == 0);
    }
    drawerLayout.setDrawerListener(drawerToggle);
    final FragmentManager fm = getSupportFragmentManager();
    fm.addOnBackStackChangedListener(() -> drawerToggle.setDrawerIndicatorEnabled(fm.getBackStackEntryCount() == 0));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    navAdapter = new NavListAdapter(itemAccess, this);
    navList.setAdapter(navAdapter);
    navList.setOnItemClickListener(navListClickListener);
    navList.setOnItemLongClickListener(newListLongClickListener);
    registerForContextMenu(navList);
    navAdapter.registerDataSetObserver(new DataSetObserver() {

        @Override
        public void onChanged() {
            selectedNavListIndex = getSelectedNavListIndex();
        }
    });
    findViewById(R.id.nav_settings).setOnClickListener(v -> {
        drawerLayout.closeDrawer(navDrawer);
        startActivity(new Intent(MainActivity.this, PreferenceController.getPreferenceActivity()));
    });
    FragmentTransaction transaction = fm.beginTransaction();
    Fragment mainFragment = fm.findFragmentByTag("main");
    if (mainFragment != null) {
        transaction.replace(R.id.main_view, mainFragment);
    } else {
        String lastFragment = getLastNavFragment();
        if (ArrayUtils.contains(NAV_DRAWER_TAGS, lastFragment)) {
            loadFragment(lastFragment, null);
        } else {
            try {
                loadFeedFragmentById(Integer.parseInt(lastFragment), null);
            } catch (NumberFormatException e) {
                // it's not a number, this happens if we removed
                // a label from the NAV_DRAWER_TAGS
                // give them a nice default...
                loadFragment(QueueFragment.TAG, null);
            }
        }
    }
    externalPlayerFragment = new ExternalPlayerFragment();
    transaction.replace(R.id.playerFragment, externalPlayerFragment, ExternalPlayerFragment.TAG);
    transaction.commit();
    checkFirstLaunch();
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) NavListAdapter(de.danoeh.antennapod.adapter.NavListAdapter) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ExternalPlayerFragment(de.danoeh.antennapod.fragment.ExternalPlayerFragment) Intent(android.content.Intent) DataSetObserver(android.database.DataSetObserver) QueueFragment(de.danoeh.antennapod.fragment.QueueFragment) Fragment(android.support.v4.app.Fragment) DownloadsFragment(de.danoeh.antennapod.fragment.DownloadsFragment) ItemlistFragment(de.danoeh.antennapod.fragment.ItemlistFragment) ExternalPlayerFragment(de.danoeh.antennapod.fragment.ExternalPlayerFragment) SubscriptionFragment(de.danoeh.antennapod.fragment.SubscriptionFragment) PlaybackHistoryFragment(de.danoeh.antennapod.fragment.PlaybackHistoryFragment) EpisodesFragment(de.danoeh.antennapod.fragment.EpisodesFragment) AddFeedFragment(de.danoeh.antennapod.fragment.AddFeedFragment)

Example 35 with DataSetObserver

use of android.database.DataSetObserver in project android_frameworks_base by ResurrectionRemix.

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();
            }
        }
    }
}
Also used : PrintManager(android.print.PrintManager) DataSetObserver(android.database.DataSetObserver) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) PrintServiceInfo(android.printservice.PrintServiceInfo) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView) PrinterInfo(android.print.PrinterInfo)

Aggregations

DataSetObserver (android.database.DataSetObserver)36 View (android.view.View)14 AdapterView (android.widget.AdapterView)9 ImageView (android.widget.ImageView)9 TextView (android.widget.TextView)9 OnClickListener (android.view.View.OnClickListener)8 ListView (android.widget.ListView)8 Calendar (android.icu.util.Calendar)5 PrintManager (android.print.PrintManager)5 PrinterInfo (android.print.PrinterInfo)5 PrintServiceInfo (android.printservice.PrintServiceInfo)5 SearchView (android.widget.SearchView)5 Intent (android.content.Intent)3 Calendar (java.util.Calendar)3 Bitmap (android.graphics.Bitmap)2 DisplayMetrics (android.util.DisplayMetrics)2 ViewGroup (android.view.ViewGroup)2 ScrollView (android.widget.ScrollView)2 HowaboutApplication (io.recom.howabout.HowaboutApplication)2 ArrayList (java.util.ArrayList)2