Java 类android.widget.SimpleCursorAdapter.ViewBinder 实例源码

项目:okwallet    文件:SendingAddressesFragment.java   
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setHasOptionsMenu(true);

    adapter = new SimpleCursorAdapter(activity, R.layout.address_book_row, null,
            new String[] { AddressBookProvider.KEY_LABEL, AddressBookProvider.KEY_ADDRESS },
            new int[] { R.id.address_book_row_label, R.id.address_book_row_address }, 0);
    adapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
            if (!AddressBookProvider.KEY_ADDRESS.equals(cursor.getColumnName(columnIndex)))
                return false;

            ((TextView) view).setText(WalletUtils.formatHash(cursor.getString(columnIndex),
                    Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE));

            return true;
        }
    });
    setListAdapter(adapter);

    loaderManager.initLoader(0, null, this);
}
项目:xDrip-Experimental    文件:AlertList.java   
void FillLists() {
    // We use a - sign to tell that this text should be stiked through
    SimpleAdapter.ViewBinder vb = new SimpleAdapter.ViewBinder() {
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            TextView tv = (TextView) view;
            tv.setText(textRepresentation.substring(1));
            if(textRepresentation.substring(0, 1).equals("-")) {
                tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            }
            return true;
        }
    };

    ArrayList<HashMap<String, String>> feedList;
    feedList = createAlertsMap(false);
    SimpleAdapter simpleAdapterLow = new SimpleAdapter(this, feedList, R.layout.row_alerts, new String[]{"alertName", "alertThreshold", "alertTime", "alertMp3File", "alertOverrideSilenceMode"}, new int[]{R.id.alertName, R.id.alertThreshold, R.id.alertTime, R.id.alertMp3File, R.id.alertOverrideSilent});
    simpleAdapterLow.setViewBinder(vb);

    listViewLow.setAdapter(simpleAdapterLow);

    feedList = createAlertsMap(true);
    SimpleAdapter simpleAdapterHigh = new SimpleAdapter(this, feedList, R.layout.row_alerts, new String[]{"alertName", "alertThreshold", "alertTime", "alertMp3File", "alertOverrideSilenceMode"}, new int[]{R.id.alertName, R.id.alertThreshold, R.id.alertTime, R.id.alertMp3File, R.id.alertOverrideSilent});
    simpleAdapterHigh.setViewBinder(vb);
    listViewHigh.setAdapter(simpleAdapterHigh);
}
项目:AC2RD    文件:Records.java   
public boolean setCursorAdapter()
  {
    try
{
    startManagingCursor(cursor);

    listView = (ListView) findViewById(android.R.id.list);

    simpleCursorAdapter = new SimpleCursorAdapter(this, R.layout.record, cursor, from, to);

    simpleCursorAdapter.setViewBinder(new ViewBinder()
    {
        public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex)
        {
            return setRecordViewValue(aView, aCursor, aColumnIndex);
        }
    });

    listView.setAdapter(simpleCursorAdapter);

    return true;
}
catch (Exception e)
{
    Log.w("Records", "setCursorAdapter : " + getApplicationContext().getString(R.string.log_records_error_set_cursor) + " : " + e);
    databaseManager.insertLog(getApplicationContext(), "" + getApplicationContext().getString(R.string.log_records_error_set_cursor), new Date().getTime(), 2, false);
    return false;
}
  }
项目:AC2RD    文件:TelephoneCallLogger.java   
public boolean setCursorAdapter()
  {
    try
{
    startManagingCursor(cursor);

    listView = (ListView) findViewById(android.R.id.list);

    simpleCursorAdapter = new SimpleCursorAdapter(this, R.layout.log, cursor, from, to);

    simpleCursorAdapter.setViewBinder(new ViewBinder()
    {
        public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex)
        {
            return setLogViewValue(aView, aCursor, aColumnIndex);
        }
    });

    listView.setAdapter(simpleCursorAdapter);

    return true;
}
catch (Exception e)
{
    Log.w("TelephoneCallLogger", "setCursorAdapter : " + getApplicationContext().getString(R.string.log_telephone_call_logger_error_set_cursor) + " : " + e);
    databaseManager.insertLog(getApplicationContext(), "" + getApplicationContext().getString(R.string.log_telephone_call_logger_error_set_cursor), new Date().getTime(), 2, false);
    return false;
}
  }
项目:AC2RD    文件:Filters.java   
public boolean setCursorAdapter()
  {
    try
{
    startManagingCursor(cursor);

    listView = (ListView) findViewById(android.R.id.list);

    simpleCursorAdapter = new SimpleCursorAdapter(this, R.layout.filter, cursor, from, to);

    simpleCursorAdapter.setViewBinder(new ViewBinder()
    {
        public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex)
        {
            return setFilterViewValue(aView, aCursor, aColumnIndex);
        }
    });

    listView.setAdapter(simpleCursorAdapter);

    return true;
}
catch (Exception e)
{
    return false;
}
  }
项目:ombuds-android    文件:SendingAddressesFragment.java   
@Override
public void onCreate(final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setHasOptionsMenu(true);

    adapter = new SimpleCursorAdapter(activity, R.layout.address_book_row, null, new String[] { AddressBookProvider.KEY_LABEL,
            AddressBookProvider.KEY_ADDRESS }, new int[] { R.id.address_book_row_label, R.id.address_book_row_address }, 0);
    adapter.setViewBinder(new ViewBinder()
    {
        @Override
        public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex)
        {
            if (!AddressBookProvider.KEY_ADDRESS.equals(cursor.getColumnName(columnIndex)))
                return false;

            ((TextView) view).setText(WalletUtils.formatHash(cursor.getString(columnIndex), Constants.ADDRESS_FORMAT_GROUP_SIZE,
                    Constants.ADDRESS_FORMAT_LINE_SIZE));

            return true;
        }
    });
    setListAdapter(adapter);

    loaderManager.initLoader(0, null, this);
}
项目:Viz    文件:Favorites.java   
private void fillData() {
    String[] from = new String[] { FavoritesColumns.NAME, FavoritesColumns.FAVICON };
    //String[] from = new String[] { FavoritesColumns.NAME };
    int[] to = new int[] { R.id.favorite_name, R.id.favicon };

    mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.favorites_row,
            null, from, to, CursorAdapter.NO_SELECTION);

    mAdapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (columnIndex == FavoritesQuery.FAVICON) {
                ImageView faviconView = (ImageView) view;
                // views are recycled, so need to reset the image in each
                // one before returning or we'll get the wrong image for a
                // favorite without a favicon
                faviconView.setImageBitmap(null);

                final byte[] blob = cursor.getBlob(FavoritesQuery.FAVICON);
                if (blob == null || blob.length == 0) {
                    faviconView.setVisibility(View.GONE);
                    return true;
                }
                faviconView.setVisibility(View.VISIBLE);
                Bitmap bitmap = BitmapFactory.decodeByteArray(blob, 0, blob.length);
                if (bitmap != null) {
                    faviconView.setImageBitmap(bitmap);
                    faviconView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                }
                return true;
            }
            return false;
        }
    });
}
项目:FullRobolectricTestSample    文件:ShadowSimpleCursorAdapter.java   
/**
 * Binds all of the field names passed into the "to" parameter of the
 * constructor with their corresponding cursor columns as specified in the
 * "from" parameter.
 *
 * Binding occurs in two phases. First, if a
 * {@link org.robolectric.shadows.ShadowSimpleCursorAdapter.ViewBinder} is available,
 * {@link ViewBinder#setViewValue(android.view.View, android.database.Cursor, int)}
 * is invoked. If the returned value is true, binding has occured. If the
 * returned value is false and the view to bind is a TextView,
 * {@link #setViewText(TextView, String)} is invoked. If the returned value is
 * false and the view to bind is an ImageView,
 * {@link #setViewImage(ImageView, String)} is invoked. If no appropriate
 * binding can be found, an {@link IllegalStateException} is thrown.
 *
 * @throws IllegalStateException if binding cannot occur
 *
 * @see android.widget.CursorAdapter#bindView(android.view.View,
 *      android.content.Context, android.database.Cursor)
 * @see #getViewBinder()
 * @see #setViewBinder(org.robolectric.shadows.ShadowSimpleCursorAdapter.ViewBinder)
 * @see #setViewImage(ImageView, String)
 * @see #setViewText(TextView, String)
 */
@Implementation
public void bindView(View view, Context context, Cursor cursor) {
  final ViewBinder binder = mViewBinder;
  final int count = mTo.length;
  final int[] from = mFrom;
  final int[] to = mTo;

  for (int i = 0; i < count; i++) {
    final View v = view.findViewById(to[i]);
    if (v != null) {
      boolean bound = false;
      if (binder != null) {
        bound = binder.setViewValue(v, cursor, from[i]);
      }

      if (!bound) {
        String text = cursor.getString(from[i]);
        if (text == null) {
          text = "";
        }

        if (v instanceof TextView) {
          setViewText((TextView) v, text);
        } else if (v instanceof ImageView) {
          setViewImage((ImageView) v, text);
        } else {
          throw new IllegalStateException(v.getClass().getName() + " is not a " +
              " view that can be bounds by this SimpleCursorAdapter");
        }
      }
    }
  }
}
项目:budget-counter    文件:WeeksOverviewActivity.java   
private void setupAdapter() {
    String[] columns = new String[]{
        BudgetDbContract.BudgetDbEntry.WEEK_OVERALL_COLUMN,
        BudgetDbContract.BudgetDbEntry.WEEK_START_COLUMN,
        BudgetDbContract.BudgetDbEntry.WEEK_END_COLUMN};

    int[] to = new int[]{
        R.id.textview_week_remaining,
        R.id.textview_week_start,
        R.id.textview_week_end};

    getLoaderManager().initLoader(0, null, this);

    adapter = new SimpleCursorAdapter(
            this, R.layout.week,
            null,
            columns,
            to,
            0);

    adapter.setViewBinder(new ViewBinder() {

        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

            if (columnIndex == cursor.getColumnIndexOrThrow(BudgetDbContract.BudgetDbEntry.WEEK_OVERALL_COLUMN)) {
                double value = cursor.getDouble(cursor.getColumnIndexOrThrow(BudgetDbContract.BudgetDbEntry.WEEK_OVERALL_COLUMN));
                double budget = cursor.getDouble(cursor.getColumnIndexOrThrow(BudgetDbContract.BudgetDbEntry.WEEK_AMOUNT_COLUMN));
                TextView textView = (TextView) view;
                textView.setTextColor(getResources().getColor(PreferenceHelper.calculateColor(value, budget)));
                textView.setText(format.format(value));
                return true;
            }

            return false;
        }
    });

    setListAdapter(adapter);
}
项目:pushetta-android-app    文件:FragmentPushes.java   
private void fillData() {
    ((MainActivity) getActivity()).showProgress();

    // Fields from the database (projection)
    // Must include the _id column for the adapter to work
    String[] from = new String[] { PushMessageTable.COLUMN_CHANNEL_NAME,
            PushMessageTable.COLUMN_CHANNEL_ICON_IMAGE,
            PushMessageTable.COLUMN_BODY,
            PushMessageTable.COLUMN_DATE_EXPIRE,
            PushMessageTable.COLUMN_PREVIEW_URL};
    // Fields on the UI to which we map
    int[] to = new int[] { 
            R.id.textChannelName, 
            R.id.iconChannel,
            R.id.textMessageBody, 
            R.id.txtTimeStamp, 
            R.id.imgPreviewUrl };

    getLoaderManager().initLoader(0, null, this);

    adapter = new PushCursorAdapter(this.getActivity(),
            com.gumino.pushetta.R.layout.listitem_pushes, null, from, to, 0);

    // ViewBinder per gestire in modo custom la visualizzazione della data
    // e dell'anteprima dell'url se presente
    adapter.setViewBinder(new ViewBinder() {

           public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {

               if (aColumnIndex == 5) {
                   String createDate = aCursor.getString(4);
                   Date createdOn = UIHelpers.getDateFromUIString(createDate);

                   String expireDate = aCursor.getString(aColumnIndex);
                   Date expireOn = UIHelpers.getDateFromUIString(expireDate);

                   TextView textView = (TextView) aView;
                   String timeStamp = String.format("Sent %s / expire %s",
                           DateFormat.getMediumDateFormat(getActivity()).format(createdOn),
                           DateFormat.getMediumDateFormat(getActivity()).format(expireOn));

                   textView.setText(timeStamp);
                   return true;
               }


               return false;
           }
       });


    setListAdapter(adapter);

       ((MainActivity) getActivity()).hideProgress();
}
项目:2buntu-android-app    文件:ArticleListFragment.java   
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // Set the Ubuntu font.
    mTypeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Ubuntu.ttf");
    // This fragment has a menu and should be retained during configuration changes.
    setHasOptionsMenu(true);
    setRetainInstance(true);
    // Initialize the cursor adapter.
    mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.listview_text_with_icon,
            null, mColumns, mViews, 0) {

        // We need to do this in order to customize the typeface.
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = super.getView(position, convertView, parent);
            ((TextView)convertView.findViewById(android.R.id.text1)).setTypeface(mTypeface);
            ((TextView)convertView.findViewById(android.R.id.text2)).setTypeface(mTypeface);
            return convertView;
        }
    };
    // Instruct the adapter to load the images asynchronously.
    mAdapter.setViewBinder(new ViewBinder() {

        @SuppressWarnings("deprecation")
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if(view.getId() == android.R.id.icon) {
                ImageView imageView = (ImageView)view.findViewById(android.R.id.icon);
                String url = "http://gravatar.com/avatar/" +
                        cursor.getString(1) + "?s=48&d=identicon";
                DisplayImageOptions options = new DisplayImageOptions.Builder()
                        .showStubImage(R.drawable.ic_gravatar_stub)
                        .cacheInMemory(true)
                        .build();
                ImageLoader.getInstance().displayImage(url, imageView, options);
                return true;
            }
            return false;
        }
    });
    // Set the adapter and begin loading the data.
    setListAdapter(mAdapter);
    setListShown(false);
    getLoaderManager().initLoader(0, null, this);
}
项目:FullRobolectricTestSample    文件:ShadowSimpleCursorAdapter.java   
/**
 * Returns the {@link ViewBinder} used to bind data to views.
 *
 * @return a ViewBinder or null if the binder does not exist
 *
 * @see #bindView(android.view.View, android.content.Context, android.database.Cursor)
 * @see #setViewBinder(org.robolectric.shadows.ShadowSimpleCursorAdapter.ViewBinder)
 */
@Implementation
public ViewBinder getViewBinder() {
  return mViewBinder;
}
项目:FullRobolectricTestSample    文件:ShadowSimpleCursorAdapter.java   
/**
 * Sets the binder used to bind data to views.
 *
 * @param viewBinder the binder used to bind data to views, can be null to
 *        remove the existing binder
 *
 * @see #bindView(android.view.View, android.content.Context, android.database.Cursor)
 * @see #getViewBinder()
 */
@Implementation
public void setViewBinder(ViewBinder viewBinder) {
  mViewBinder = viewBinder;
}