Example usage for android.support.v4.widget CursorAdapter FLAG_REGISTER_CONTENT_OBSERVER

List of usage examples for android.support.v4.widget CursorAdapter FLAG_REGISTER_CONTENT_OBSERVER

Introduction

In this page you can find the example usage for android.support.v4.widget CursorAdapter FLAG_REGISTER_CONTENT_OBSERVER.

Prototype

int FLAG_REGISTER_CONTENT_OBSERVER

To view the source code for android.support.v4.widget CursorAdapter FLAG_REGISTER_CONTENT_OBSERVER.

Click Source Link

Document

If set the adapter will register a content observer on the cursor and will call #onContentChanged() when a notification comes in.

Usage

From source file:com.kunze.androidlocaltodo.TaskListActivity.java

private void InitializeView() {
    // Set up event handlers for the task list
    ListView listView = (ListView) findViewById(R.id.task_list);
    listView.setOnItemClickListener(this);
    listView.setOnItemLongClickListener(this);
    listView.setLongClickable(true);/*from  www . j  av  a  2s.co m*/

    // Get a cursor to populate the UI
    Cursor cursor = mDB.GetCursor();
    String from[] = { "NAME", "DUE_DATE" };
    int to[] = { R.id.task_name_edit, R.id.task_due_date };

    mAdapter = new SimpleCursorAdapter(this, R.layout.task_list_element, cursor, from, to,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    // Set up a ViewBinder to convert the due date to something more human-friendly
    mAdapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            try {
                if (columnIndex == 2) {
                    Calendar dueDate = TaskDatabase.ConvertIntToDate(cursor.getInt(columnIndex));
                    TextView dueDateView = (TextView) view;
                    SetFriendlyDueDateText(dueDateView, dueDate);
                    return true;
                }
            } catch (Exception e) {
                AlertDialog.Builder builder = new AlertDialog.Builder(TaskListActivity.this);
                AlertDialog dlg = builder.setTitle("Database error!").setMessage(e.getMessage()).create();
                dlg.show();
            }
            return false;
        }
    });
    listView.setAdapter(mAdapter);
}

From source file:com.piusvelte.wapdroid.ManageData.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SimpleCursorAdapter adapter;/*from   www  . jav  a 2 s .c o  m*/

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        adapter = new SimpleCursorAdapter(getActivity(), R.layout.network_row, null,
                new String[] { Networks.SSID, Networks.BSSID, STATUS, Networks.MANAGE },
                new int[] { R.id.network_row_SSID, R.id.network_row_BSSID, R.id.network_row_status,
                        R.id.network_manage });
    } else {
        adapter = new SimpleCursorAdapter(getActivity(), R.layout.network_row, null,
                new String[] { Networks.SSID, Networks.BSSID, STATUS, Networks.MANAGE },
                new int[] { R.id.network_row_SSID, R.id.network_row_BSSID, R.id.network_row_status,
                        R.id.network_manage },
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    }

    adapter.setViewBinder(mViewBinder);
    setListAdapter(adapter);
    getLoaderManager().initLoader(DATA_LOADER, getCursorArguments(), this);
}

From source file:monakhv.android.samlib.AuthorListFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String[] from = { SQLController.COL_NAME, SQLController.COL_mtime, SQLController.COL_isnew,
            SQLController.COL_TGNAMES, SQLController.COL_URL };
    int[] to = { R.id.authorName, R.id.updated, R.id.icon, R.id.tgnames, R.id.authorURL };

    adapter = new SimpleCursorAdapter(getActivity(), R.layout.rowlayout, null, from, to,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    SettingsHelper settings = new SettingsHelper(getActivity().getApplicationContext());

    adapter.setViewBinder(new AuthorViewBinder());
    order = settings.getAuthorSortOrder();
    setListAdapter(adapter);/*w ww  .  j  ava  2s  .  c o  m*/
    getLoaderManager().initLoader(AUTHOR_LIST_LOADER, null, this);
    detector = new GestureDetector(getActivity(), new ListSwipeListener(this));
}

From source file:com.serenegiant.testmediastore.MediaStorePhotoAdapter.java

public MediaStorePhotoAdapter(Context context, int id_layout) {
    super(context, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    mInflater = LayoutInflater.from(context);
    mCr = context.getContentResolver();// w  ww.ja  v a 2  s.co m
    mQueryHandler = new MyAsyncQueryHandler(mCr, this);
    // getMemoryClass return the available memory amounts for app as mega bytes(API >= 5)
    mMemClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    mLayoutId = id_layout;
    onContentChanged();
}

From source file:cm.aptoide.pt.ApkInfo.java

/**
 *
 *//*from   w w  w. ja va 2s  . c  o  m*/
private void loadApkVersions() {
    if (category.equals(Category.INFOXML)) {
        spinner = (Spinner) findViewById(R.id.spinnerMultiVersion);
        adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, null,
                new String[] { "vername", "repo_id" }, new int[] { android.R.id.text1 },
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        adapter.setViewBinder(new ViewBinder() {

            @Override
            public boolean setViewValue(View textView, Cursor cursor, int position) {
                ((android.widget.TextView) textView)
                        .setText(getString(R.string.version) + " " + cursor.getString(position) + " - "
                                + RepoUtils.split(db.getServer(cursor.getLong(3), false).url));
                return true;
            }
        });
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                if (spinnerInstanciated) {
                    if (!download.isNull()) {
                        try {
                            serviceDownloadManager.callUnregisterDownloadObserver(viewApk.hashCode());
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
                    }
                    loadElements(arg3);
                } else {
                    spinnerInstanciated = true;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }
        });

        getSupportLoaderManager().initLoader(0, null, ApkInfo.this);

    }
}

From source file:bf.io.openshop.ux.MainActivity.java

@Override
public void prepareSearchSuggestions(List<DrawerItemCategory> navigation) {
    final String[] from = new String[] { "categories" };
    final int[] to = new int[] { android.R.id.text1 };

    searchSuggestionsAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, from,
            to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    if (navigation != null && !navigation.isEmpty()) {
        for (int i = 0; i < navigation.size(); i++) {
            if (!searchSuggestionsList.contains(navigation.get(i).getName())) {
                searchSuggestionsList.add(navigation.get(i).getName());
            }/*from   w  w w  .  j  a  va  2  s .  c  o m*/

            if (navigation.get(i).hasChildren()) {
                for (int j = 0; j < navigation.get(i).getChildren().size(); j++) {
                    if (!searchSuggestionsList.contains(navigation.get(i).getChildren().get(j).getName())) {
                        searchSuggestionsList.add(navigation.get(i).getChildren().get(j).getName());
                    }
                }
            }
        }
        searchSuggestionsAdapter.notifyDataSetChanged();
    } else {
        Timber.e("Search suggestions loading failed.");
        searchSuggestionsAdapter = null;
    }
}

From source file:cm.aptoide.pt.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    AptoideThemePicker.setAptoideTheme(this);
    super.onCreate(savedInstanceState);

    serviceDownloadManagerIntent = new Intent(this, ServiceDownloadManager.class);
    startService(serviceDownloadManagerIntent);
    mContext = this;

    File sdcard_file = new File(SDCARD);
    if (!sdcard_file.exists() || !sdcard_file.canWrite()) {
        View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null);
        Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
        final AlertDialog noSDDialog = dialogBuilder.create();
        noSDDialog.setTitle(getText(R.string.remote_in_noSD_title));
        noSDDialog.setIcon(android.R.drawable.ic_dialog_alert);
        TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
        message.setText(getText(R.string.remote_in_noSD));
        noSDDialog.setCancelable(false);
        noSDDialog.setButton(Dialog.BUTTON_NEUTRAL, getString(android.R.string.ok),
                new Dialog.OnClickListener() {
                    @Override/*from  www  .  jav a2 s  .  c  o m*/
                    public void onClick(DialogInterface arg0, int arg1) {
                        finish();
                    }
                });
        noSDDialog.show();
    } else {
        StatFs stat = new StatFs(sdcard_file.getPath());
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        long availableBlocks = stat.getAvailableBlocks();

        long total = (blockSize * totalBlocks) / 1024 / 1024;
        long avail = (blockSize * availableBlocks) / 1024 / 1024;
        Log.d("Aptoide", "* * * * * * * * * *");
        Log.d("Aptoide", "Total: " + total + " Mb");
        Log.d("Aptoide", "Available: " + avail + " Mb");

        if (avail < 10) {
            Log.d("Aptoide", "No space left on SDCARD...");
            Log.d("Aptoide", "* * * * * * * * * *");
            View simpleView = LayoutInflater.from(this).inflate(R.layout.dialog_simple_layout, null);
            Builder dialogBuilder = new AlertDialog.Builder(this).setView(simpleView);
            final AlertDialog noSpaceDialog = dialogBuilder.create();
            noSpaceDialog.setIcon(android.R.drawable.ic_dialog_alert);
            TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
            message.setText(getText(R.string.remote_in_noSDspace));
            noSpaceDialog.setButton(Dialog.BUTTON_NEUTRAL, getText(android.R.string.ok),
                    new Dialog.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            finish();
                        }
                    });
            noSpaceDialog.show();
        } else {

            SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext);
            editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit();

            if (!sPref.contains("matureChkBox")) {

                editor.putBoolean("matureChkBox", ApplicationAptoide.MATURECONTENTSWITCHVALUE);
                SharedPreferences sPrefOld = getSharedPreferences("aptoide_prefs", MODE_PRIVATE);
                if (sPrefOld.getString("app_rating", "none").equals("Mature")) {
                    editor.putBoolean("matureChkBox", false);
                }

            }

            if (!sPref.contains("version")) {

                ApplicationAptoide.setRestartLauncher(true);
                try {
                    editor.putInt("version",
                            getPackageManager().getPackageInfo(getPackageName(), 0).versionCode);
                } catch (NameNotFoundException e) {
                    e.printStackTrace();
                }

            }

            if (sPref.getString("myId", null) == null) {
                String rand_id = UUID.randomUUID().toString();
                editor.putString("myId", rand_id);
            }

            if (sPref.getInt("scW", 0) == 0 || sPref.getInt("scH", 0) == 0) {
                DisplayMetrics dm = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(dm);
                editor.putInt("scW", dm.widthPixels);
                editor.putInt("scH", dm.heightPixels);
            }
            editor.commit();
            File file = new File(LOCAL_PATH + "/apks");
            if (!file.exists()) {
                file.mkdirs();
            }

            new Thread(new Runnable() {

                @Override
                public void run() {

                    // Note the L that tells the compiler to interpret the
                    // number as a Long
                    final long MAXFILEAGE = 2678400000L; // 1 month in
                    // milliseconds

                    // Get file handle to the directory. In this case the
                    // application files dir
                    File dir = new File(LOCAL_PATH + "/apks");

                    // Optain list of files in the directory.
                    // listFiles() returns a list of File objects to each
                    // file found.
                    File[] files = dir.listFiles();

                    // Loop through all files
                    for (File f : files) {

                        // Get the last modified date. Miliseconds since
                        // 1970
                        long lastmodified = f.lastModified();

                        // Do stuff here to deal with the file..
                        // For instance delete files older than 1 month
                        if (lastmodified + MAXFILEAGE < System.currentTimeMillis()) {
                            f.delete();
                        }
                    }
                }
            }).start();
            db = Database.getInstance();

            Intent i = new Intent(mContext, MainService.class);
            startService(i);
            bindService(i, conn, Context.BIND_AUTO_CREATE);
            order = Order.values()[PreferenceManager.getDefaultSharedPreferences(mContext).getInt("order_list",
                    0)];

            registerReceiver(updatesReceiver, new IntentFilter("update"));
            registerReceiver(statusReceiver, new IntentFilter("status"));
            registerReceiver(loginReceiver, new IntentFilter("login"));
            registerReceiver(storePasswordReceiver, new IntentFilter("401"));
            registerReceiver(redrawInstalledReceiver, new IntentFilter("pt.caixamagica.aptoide.REDRAW"));
            if (!ApplicationAptoide.MULTIPLESTORES) {
                registerReceiver(parseFailedReceiver, new IntentFilter("PARSE_FAILED"));
            }

            registerReceiver(newRepoReceiver, new IntentFilter("pt.caixamagica.aptoide.NEWREPO"));
            registered = true;

            categoriesStrings = new HashMap<String, Integer>();

            //            categoriesStrings.put("Applications", R.string.applications);

            boolean serversFileIsEmpty = true;

            if (sPref.getBoolean("firstrun", true)) {
                // Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
                // shortcutIntent.setClassName("cm.aptoide.pt",
                // "cm.aptoide.pt.Start");
                // final Intent intent = new Intent();
                // intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
                // shortcutIntent);
                //
                // intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                // getString(R.string.app_name));
                // Parcelable iconResource =
                // Intent.ShortcutIconResource.fromContext(this,
                // R.drawable.ic_launcher);
                //
                // intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                // iconResource);
                // intent.putExtra("duplicate", false);
                // intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                // sendBroadcast(intent);

                if (new File(LOCAL_PATH + "/servers.xml").exists()
                        && ApplicationAptoide.DEFAULTSTORENAME == null) {
                    try {

                        SAXParserFactory spf = SAXParserFactory.newInstance();
                        SAXParser sp = spf.newSAXParser();

                        MyappHandler handler = new MyappHandler();

                        sp.parse(new File(LOCAL_PATH + "/servers.xml"), handler);
                        ArrayList<String> server = handler.getServers();
                        if (server.isEmpty()) {
                            serversFileIsEmpty = true;
                        } else {
                            getIntent().putExtra("newrepo", server);
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                editor.putBoolean("firstrun", false);
                editor.putBoolean("orderByCategory", true);
                editor.commit();
            }

            if (getIntent().hasExtra("newrepo")) {
                ArrayList<String> repos = (ArrayList<String>) getIntent().getSerializableExtra("newrepo");
                for (final String uri2 : repos) {
                    View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout,
                            null);
                    Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
                    final AlertDialog addNewRepoDialog = dialogBuilder.create();
                    addNewRepoDialog.setTitle(getString(R.string.add_store));
                    addNewRepoDialog.setIcon(android.R.drawable.ic_menu_add);

                    TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
                    message.setText((getString(R.string.newrepo_alrt) + uri2 + " ?"));

                    addNewRepoDialog.setCancelable(false);
                    addNewRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
                            new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    dialogAddStore(uri2, null, null);
                                }
                            });
                    addNewRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
                            new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int arg1) {
                                    dialog.cancel();
                                }
                            });
                    addNewRepoDialog.show();
                }
            } else if (db.getStores(false).getCount() == 0 && ApplicationAptoide.DEFAULTSTORENAME == null
                    && serversFileIsEmpty) {
                View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null);
                Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView);
                final AlertDialog addAppsRepoDialog = dialogBuilder.create();
                addAppsRepoDialog.setTitle(getString(R.string.add_store));
                addAppsRepoDialog.setIcon(android.R.drawable.ic_menu_add);
                TextView message = (TextView) simpleView.findViewById(R.id.dialog_message);
                message.setText(getString(R.string.myrepo_alrt) + "\n" + "http://apps.store.aptoide.com/");
                addAppsRepoDialog.setCancelable(false);
                addAppsRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes),
                        new Dialog.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                dialogAddStore("http://apps.store.aptoide.com", null, null);
                            }
                        });
                addAppsRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no),
                        new Dialog.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int arg1) {
                                dialog.cancel();
                            }
                        });
                addAppsRepoDialog.show();
            }

            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        getUpdateParameters();
                        if (getPackageManager().getPackageInfo(getPackageName(), 0).versionCode < Integer
                                .parseInt(updateParams.get("versionCode"))) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    requestUpdateSelf();
                                }
                            });
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }

        featuredView = LayoutInflater.from(mContext).inflate(R.layout.page_featured, null);
        availableView = LayoutInflater.from(mContext).inflate(R.layout.page_available, null);
        updateView = LayoutInflater.from(mContext).inflate(R.layout.page_updates, null);
        banner = (LinearLayout) availableView.findViewById(R.id.banner);
        breadcrumbs = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.breadcrumb_container, null);
        installedView = new ListView(mContext);
        updatesListView = (ListView) updateView.findViewById(R.id.updates_list);

        availableListView = (ListView) availableView.findViewById(R.id.available_list);
        joinStores = (CheckBox) availableView.findViewById(R.id.join_stores);

        availableAdapter = new AvailableListAdapter(mContext, null,
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        installedAdapter = new InstalledAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER,
                db);
        updatesAdapter = new UpdatesAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

        pb = (TextView) availableView.findViewById(R.id.loading_pb);
        addStoreButton = availableView.findViewById(R.id.add_store);

        bannerStoreAvatar = (ImageView) banner.findViewById(R.id.banner_store_avatar);
        bannerStoreName = (TextView) banner.findViewById(R.id.banner_store_name);
        bannerStoreDescription = (AutoScaleTextView) banner.findViewById(R.id.banner_store_description);
    }
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

@Override
protected Dialog onCreateDialog(int id, Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    switch (id) {
    case DIALOG_TEMPLATE_NOT_AVAILABLE:
        builder.setTitle(R.string.template_not_present_error_title);
        builder.setMessage(R.string.template_not_present_error);
        return builder.create();

    case DIALOG_TEMPLATE_SELECT:
        builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.template_select);
        mTemplatesCursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null,
                new String[] { Template.TEXT }, new int[] { android.R.id.text1 },
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        builder.setAdapter(mTemplatesCursorAdapter, new DialogInterface.OnClickListener() {
            @Override//from   w w  w .  jav  a 2s  .  com
            public void onClick(DialogInterface dialog, int which) {
                Cursor c = (Cursor) mTemplatesCursorAdapter.getItem(which);
                String text = c.getString(c.getColumnIndex(Template.TEXT));

                // insert selected template text at the cursor location or replace selected
                int start = mTextEditor.getSelectionStart();
                int end = mTextEditor.getSelectionEnd();
                mTextEditor.getText().replace(Math.min(start, end), Math.max(start, end), text);
            }

        });
        return builder.create();
    }
    return super.onCreateDialog(id, args);
}