protected static String getId(ListView l, int position) {
   // Get the cursor and fetch the stop ID from that.
   SimpleCursorAdapter cursorAdapter = (SimpleCursorAdapter) l.getAdapter();
   Cursor c = cursorAdapter.getCursor();
   c.moveToPosition(position - l.getHeaderViewsCount());
   return c.getString(Columns.COL_ID);
 }
    public static SimpleCursorAdapter newAdapter(Context context) {
      String[] from =
          new String[] {
            ObaContract.Stops.UI_NAME, ObaContract.Stops.DIRECTION, ObaContract.Stops.FAVORITE
          };
      int[] to = new int[] {R.id.stop_name, R.id.direction, R.id.stop_name};
      SimpleCursorAdapter simpleAdapter =
          new SimpleCursorAdapter(context, R.layout.stop_list_item, null, from, to, 0);

      // We need to convert the direction text (N/NW/E/etc)
      // to user level text (North/Northwest/etc..)
      simpleAdapter.setViewBinder(
          new SimpleCursorAdapter.ViewBinder() {
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
              if (columnIndex == Columns.COL_FAVORITE) {
                TextView favorite = (TextView) view.findViewById(R.id.stop_name);
                int icon = (cursor.getInt(columnIndex) == 1) ? R.drawable.star_on : 0;
                favorite.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
                return true;
              } else if (columnIndex == Columns.COL_DIRECTION) {
                UIHelp.setStopDirection(
                    view.findViewById(R.id.direction), cursor.getString(columnIndex), true);
                return true;
              }
              return false;
            }
          });
      return simpleAdapter;
    }
    @Override
    protected void onPostExecute(Cursor result) {

      if (mListView != null && result != null) {

        setHeaderPinned(!result.moveToFirst());

        if (mListView.getAdapter() != null) {

          // Just update existing adapter
          getAdapter().changeCursor(result);
          return;
        }

        String[] from = {
          TransactionEntry.COLUMN_NAME_JSON, TransactionEntry.COLUMN_NAME_JSON,
          TransactionEntry.COLUMN_NAME_JSON, TransactionEntry.COLUMN_NAME_JSON
        };
        int[] to = {
          R.id.transaction_title, R.id.transaction_amount,
          R.id.transaction_status, R.id.transaction_currency
        };
        SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(
                mParent, R.layout.fragment_transactions_item, result, from, to, 0);
        adapter.setViewBinder(new TransactionViewBinder());
        mListView.setAdapter(adapter);
      }
    }
 /**
  * Updates the spinner to the selected transfer account
  *
  * @param accountId Database ID of the transfer account
  */
 private void setSelectedTransferAccount(long accountId, final Spinner accountsSpinner) {
   for (int pos = 0; pos < mCursorAdapter.getCount(); pos++) {
     if (mCursorAdapter.getItemId(pos) == accountId) {
       accountsSpinner.setSelection(pos);
       break;
     }
   }
 }
 @Override
 public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
   final SimpleCursorAdapter adapter = getAdapter();
   adapter.swapCursor(data);
   if (data != null && data.getCount() > 0) {
     showContent();
   } else {
     showEmpty(R.drawable.ic_info_volume_off, getString(R.string.no_rule));
   }
 }
 @Override
 public void onLoaderReset(Loader<Cursor> cursorLoader) {
   final int id = cursorLoader.getId();
   switch (id) {
     case PriorityLoaderId:
       adPriority.swapCursor(null);
       return;
     case StatusLoaderId:
       adStatus.swapCursor(null);
       return;
     default:
   }
 }
 @Override
 public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
   final int lid = cursorLoader.getId();
   switch (lid) {
     case PriorityLoaderId:
       adPriority.swapCursor(cursor);
       getSupportLoaderManager().initLoader(StatusLoaderId, null, this);
       return;
     case StatusLoaderId:
       adStatus.swapCursor(cursor);
       if (id != null) {
         getSupportLoaderManager().initLoader(ItemLoaderId, null, this);
       }
       return;
     case ItemLoaderId:
       if (cursor.moveToFirst()) {
         setTitle(R.string.ui_edit_item);
         edName.setText(cursor.getString(0));
         edDesc.setText(cursor.getString(1));
         SetupSpinner(cursor.getInt(2), sPriority);
         SetupSpinner(cursor.getInt(3), sStatus);
         String time = cursor.getString(4);
         Calendar cal = Calendar.getInstance();
         try {
           cal.setTime(sdf.parse(time));
         } catch (ParseException e) {
           e.printStackTrace();
         }
         tStartDate.setTag(cal);
         tStartDate.setText(sdfdate.format(cal.getTime()));
         tStartTime.setTag(cal);
         tStartTime.setText(sdftime.format(cal.getTime()));
         time = cursor.getString(5);
         cal = Calendar.getInstance();
         try {
           cal.setTime(sdf.parse(time));
         } catch (ParseException e) {
           e.printStackTrace();
         }
         tEndDate.setTag(cal);
         tEndDate.setText(sdfdate.format(cal.getTime()));
         tEndTime.setTag(cal);
         tEndTime.setText(sdftime.format(cal.getTime()));
       } else {
         finish();
       }
       return;
     default:
   }
 }
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mNavigationAdapter.swapCursor(data);
    mPagerAdapter.swapCursor(data);

    selectTraining(mPosition);
  }
  /** Set up spinner navigation with swiped pages */
  private void setUpNavigation() {
    // Navigation spinner in toolbar for trainings selection
    LayoutInflater.from(mToolbar.getContext()).inflate(R.layout.navigation_spinner, mToolbar, true);
    mNavigationSpinner = (Spinner) mToolbar.findViewById(R.id.navigation_spinner);
    mNavigationSpinner.setOnItemSelectedListener(this);
    mNavigationSpinner.setSelection(mPosition);

    String[] from = new String[] {Trainings.EXERCISE};
    int[] to = new int[] {R.id.title};
    mNavigationAdapter =
        new NavigationAdapter(
            mToolbar.getContext(), R.layout.navigation_spinner_item, null, from, to, 0);
    mNavigationAdapter.setDropDownViewResource(R.layout.navigation_spinner_dropdown_item);
    mNavigationSpinner.setAdapter(mNavigationAdapter);

    // ViewPager for swipe navigation and animation on training select
    mViewPager.setOnPageChangeListener(this);
    mPagerAdapter = new TrainingPagerAdapter(getChildFragmentManager(), null);
    mViewPager.setAdapter(mPagerAdapter);

    Loader<Cursor> loader = getLoaderManager().getLoader(0);
    if (loader != null && !loader.isReset()) {
      getLoaderManager().restartLoader(0, null, this);
    } else {
      getLoaderManager().initLoader(0, null, this);
    }
  }
Exemple #10
0
  private void initData() {
    ContentResolver resolver = getContentResolver();

    mCursor = resolver.query(Contacts.CONTENT_URI, projection, selection, selectionArgs, sortOrder);
    idColumnIndex = mCursor.getColumnIndex(Contacts._ID);
    mAdapter.swapCursor(mCursor);
  }
Exemple #11
0
  private void searchContacts(String keyword) {
    Uri uri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(keyword));
    ContentResolver resolver = getContentResolver();

    mCursor = resolver.query(uri, projection, selection, selectionArgs, sortOrder);
    idColumnIndex = mCursor.getColumnIndex(Contacts._ID);
    mAdapter.swapCursor(mCursor);
  }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
      mCursorAdapter.getCursor().moveToPosition(position);
      mCursorAdapter.bindView(holder.itemView, getContext(), mCursorAdapter.getCursor());

      CardView cardView = (CardView) holder.itemView.findViewById(R.id.card_view);
      TextView text = (TextView) holder.itemView.findViewById(android.R.id.text2);

      int color;
      if (text.getText().toString().contains(getString(R.string.free))) {
        color = Color.rgb(200, 230, 201);
      } else {
        color = Color.rgb(255, 205, 210);
      }

      cardView.setCardBackgroundColor(color);
    }
Exemple #13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    listView = (ListView) findViewById(R.id.listView1);
    centerView = (ImageView) findViewById(R.id.imageView1);
    centerView.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            centerView.setVisibility(View.GONE);
          }
        });
    mAdapter =
        new SimpleCursorAdapter(
            this,
            R.layout.item_layout,
            null,
            columns,
            new int[] {R.id.iconView, R.id.titleView},
            0);
    mAdapter.setViewBinder(
        new ViewBinder() {

          @Override
          public boolean setViewValue(View view, Cursor c, int columnIndex) {
            if (idIndex == NOT_FIXED) {
              idIndex = c.getColumnIndex(MediaStore.Images.Media._ID);
            }
            if (idIndex == columnIndex) {
              long id = c.getLong(columnIndex);
              ImageView iv = (ImageView) view;
              Bitmap bm =
                  MediaStore.Images.Thumbnails.getThumbnail(
                      getContentResolver(), id, MediaStore.Images.Thumbnails.MINI_KIND, null);
              iv.setImageBitmap(bm);
              return true;
            }
            return false;
          }
        });
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
            centerView.setImageURI(uri);
            centerView.setVisibility(View.VISIBLE);
            Cursor c = (Cursor) listView.getItemAtPosition(position);
          }
        });
    getSupportLoaderManager().initLoader(0, null, this);
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    setHasOptionsMenu(true);

    if (getTag() == "order-history-fragment") {
      clientId = getArguments().getLong(ClientDetailActivity.EXTRA_MESSAGE);
      rowLayout = R.layout.row_order_history_item;
      from =
          new String[] {
            DataContract.Orders.ORDERS_KEY_PRODUCT, DataContract.Orders.ORDERS_KEY_DATE, "debt"
          };
      to = new int[] {R.id.orderItemProduct, R.id.orderItemDate, R.id.orderItemDebt};
    } else {
      rowLayout = R.layout.row_order_item;
      from =
          new String[] {
            DataContract.Orders.ORDERS_KEY_PRODUCT,
            DataContract.Orders.ORDERS_KEY_DATE,
            DataContract.Clients.CLIENTS_KEY_NAME,
            "debt"
          };
      to =
          new int[] {
            R.id.orderItemProduct, R.id.orderItemDate, R.id.orderItemClient, R.id.orderItemDebt
          };
    }

    mAdapter = new SimpleCursorAdapter(getActivity(), rowLayout, null, from, to, 0);

    mAdapter.setViewBinder(
        new SimpleCursorAdapter.ViewBinder() {
          public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
            TextView textView = (TextView) aView;
            if (aColumnIndex == 5) {
              Long dateinMillis = aCursor.getLong(aColumnIndex);
              String dateTimeString = DateFormat.getDateInstance().format(new Date(dateinMillis));
              textView.setText(dateTimeString);
              return true;
            } else if (aColumnIndex == 9) {
              Float debt = aCursor.getFloat(aColumnIndex);
              String currencySymbol = sharedPref.getString(SettingsActivity.KEY_PREF_CURRENCY, "");
              textView.setText(currencySymbol + debt.toString());
              return true;
            }
            return false;
          }
        });

    setListAdapter(mAdapter);

    getLoaderManager().initLoader(0, null, this);
  }
 @Override
 public void changeCursor(Cursor cursor) {
   if (mCursorClosed) return;
   if (cursor != null) {
     mProfileImageUrlIdx = cursor.getColumnIndexOrThrow(Statuses.PROFILE_IMAGE_URL);
     mScreenNameIdx = cursor.getColumnIndexOrThrow(CachedUsers.SCREEN_NAME);
   }
   mCursor = cursor;
   super.changeCursor(mCursor);
 }
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

    if (loader.getId() == FRIENDS_LOADER_ID) {

      mAdapter.swapCursor(cursor);
      setListShown(false);
      setCreatePhotoVisible(cursor != null && cursor.getCount() > 0);
    }
  }
Exemple #17
0
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_main, container, false);
      gridView = (GridView) rootView.findViewById(R.id.gridView1);
      String[] from = {MediaStore.Images.Media._ID};
      int[] to = {R.id.imageContent};
      mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.cursor_layout, null, from, to, 0);

      mAdapter.setViewBinder(
          new ViewBinder() {

            @Override
            public boolean setViewValue(View view, Cursor c, int columnIndex) {
              if (mIdColumnIndex == columnIndex) {
                ImageView imageView = (ImageView) view;
                long id = c.getLong(columnIndex);
                Bitmap bm =
                    MediaStore.Images.Thumbnails.getThumbnail(
                        getActivity().getContentResolver(),
                        id,
                        MediaStore.Images.Thumbnails.MINI_KIND,
                        null);
                imageView.setImageBitmap(bm);
                return true;
              }
              return false;
            }
          });

      gridView.setAdapter(mAdapter);
      gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE);
      Button btn = (Button) rootView.findViewById(R.id.button1);
      btn.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              ArrayList<Uri> uris = new ArrayList<Uri>();
              SparseBooleanArray selectlist = gridView.getCheckedItemPositions();
              for (int i = 0; i < selectlist.size(); i++) {
                int position = selectlist.keyAt(i);
                if (selectlist.get(position)) {
                  uris.add(
                      ContentUris.withAppendedId(
                          MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                          gridView.getItemIdAtPosition(position)));
                }
              }
            }
          });
      getLoaderManager().initLoader(0, null, this);
      return rootView;
    }
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   Cursor cursor = mCursorAdapter.getCursor();
   cursor.moveToPosition(position);
   String email = cursor.getString(EMAIL_ADDRESS_INDEX);
   Intent intent = new Intent(getActivity(), MoneyActivity.class);
   intent.putExtra(Intent.EXTRA_TEXT, email);
   getActivity().setResult(ListActivity.ResultCode.SELECT_EMAIL_SUCCESS, intent);
   getActivity().finish();
   getActivity().overridePendingTransition(R.anim.slide_right_enter, R.anim.slide_right_leave);
 }
 @Override
 public void bindView(
     @NonNull final View view, final Context context, @NonNull final Cursor cursor) {
   super.bindView(view, context, cursor);
   final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
   final long userId = cursor.getLong(mUserIdIdx);
   final String name = cursor.getString(mNameIdx);
   final String screenName = cursor.getString(mScreenNameIdx);
   final String displayName =
       mUserColorNameManager.getDisplayName(userId, name, screenName, mNameFirst, false);
   text1.setText(displayName);
 }
  public void onLoadFinished(Loader<Cursor> loader, Cursor institutions) {
    adapterInst.swapCursor(institutions);
    Log.d(TAG, "loader is done and we have our cursor.");

    // Notify the ParentActivity we need it's data if any.
    sendInstitutionData();

    // Set the Institutions spinner to the proper location or default of zero.
    // spinInstitutions.setSelection(setInstitution(institutionSelected, columnUsed));

    updateUIElements();
  }
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   View v = inflater.inflate(R.layout.templates_list, null, false);
   ListView lv = (ListView) v.findViewById(R.id.list);
   mManager = getLoaderManager();
   mManager.initLoader(0, null, this);
   // Create an array to specify the fields we want to display in the list
   String[] from = new String[] {DatabaseConstants.KEY_TITLE, DatabaseConstants.KEY_PLANID};
   // and an array of the fields we want to bind those fields to
   int[] to = new int[] {R.id.title, R.id.plan};
   mAdapter =
       new SimpleCursorAdapter(getActivity(), R.layout.template_row, null, from, to, 0) {
         @Override
         public View getView(int position, View convertView, ViewGroup parent) {
           convertView = super.getView(position, convertView, parent);
           convertView.findViewById(R.id.apply).setTag(getItemId(position));
           Cursor c = getCursor();
           c.moveToPosition(position);
           int color = c.getInt(c.getColumnIndex("color"));
           convertView.findViewById(R.id.colorAccount).setBackgroundColor(color);
           return convertView;
         }
       };
   mAdapter.setViewBinder(
       new SimpleCursorAdapter.ViewBinder() {
         public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
           if (view.getId() == R.id.plan) {
             view.setVisibility(
                 (DbUtils.getLongOrNull(cursor, DatabaseConstants.KEY_PLANID) == null)
                     ? View.INVISIBLE
                     : View.VISIBLE);
             return true;
           }
           return false;
         }
       });
   lv.setAdapter(mAdapter);
   lv.setEmptyView(v.findViewById(R.id.empty));
   // requires using activity (ManageTemplates) to implement OnChildClickListener
   // lv.setOnChildClickListener((OnChildClickListener) getActivity());
   lv.setOnItemClickListener(
       new OnItemClickListener() {
         @Override
         public void onItemClick(AdapterView<?> a, View v, int position, long id) {
           TemplateDetailFragment.newInstance(id)
               .show(getActivity().getSupportFragmentManager(), "TEMPLATE_DETAIL");
         }
       });
   registerForContextMenu(lv);
   return v;
 }
 @Override
 public void setViewText(TextView v, String text) {
   if (v != null) {
     try {
       v.setTypeface(RobotoView.obtainTypeface(mContext, RobotoView.getUserFont()));
     } catch (Exception e) {
       Log.e(LOGCAT, e.getMessage());
     }
     super.setViewText(v, text);
     // check if highlight text
     if (!TextUtils.isEmpty(getHighlightFilter())) {
       v.setText(mCore.highlight(getHighlightFilter(), v.getText().toString()));
     }
   }
 }
 @Override
 public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
   if (cursor != null) {
     Log.e(
         TAG,
         String.format(
             "Report list Cursor size: %d. Cursor columns: %s. Cursor column count: %d",
             cursor.getCount(), Arrays.toString(cursor.getColumnNames()), cursor.getCount()));
     mAdapter.swapCursor(cursor);
     if (isResumed()) {
       setListShown(true);
     } else {
       setListShownNoAnimation(true);
     }
   }
   setListShown(true);
 }
    OpeningHoursDetailAdapter(Cursor c) {
      cursorAdapter =
          new SimpleCursorAdapter(
              getActivity(),
              R.layout.two_line_list_item,
              c,
              c.getColumnNames(),
              new int[] {android.R.id.text1, android.R.id.text2, R.id.text3},
              0) {

            @Override
            public boolean isEnabled(int position) {
              // disable onclick
              return false;
            }
          };

      cursorAdapter.setViewBinder(OpeningHoursDetailFragment.this);
    }
  private int setInstitution(String institution, int columUsed) {
    int i = 0;
    Cursor c = adapterInst.getCursor();
    c.moveToFirst();

    if (institution != null) {
      while (!institution.equals(c.getString(columUsed))) {
        c.moveToNext();

        // check to see if we have moved past the last item in the cursor, if so return current i.
        if (c.isAfterLast()) return i;

        i++;
      }
    }

    // Always set the columnUsed back to using the Name, columnUsed = 1
    columnUsed = 1;
    return i;
  }
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    if (mCursorClosed) return;

    final ImageView image_view = (ImageView) view.findViewById(android.R.id.icon);
    image_view.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
    if (mDisplayProfileImage && mProfileImageLoader != null) {
      final String profile_image_url_string = cursor.getString(mProfileImageUrlIdx);
      mProfileImageLoader.displayImage(parseURL(cursor.getString(mProfileImageUrlIdx)), image_view);
      if (mDisplayHiResProfileImage) {
        mProfileImageLoader.displayImage(
            parseURL(getBiggerTwitterProfileImage(profile_image_url_string, mForceSSLConnection)),
            image_view);
      } else {
        mProfileImageLoader.displayImage(
            parseURL(getNormalTwitterProfileImage(profile_image_url_string, mForceSSLConnection)),
            image_view);
      }
    }
    super.bindView(view, context, cursor);
  }
  @Override
  public void onLoaderReset(Loader<Cursor> loader) {
    // Delete the reference to the existing Cursor

    mCursorAdapter.swapCursor(null);
  }
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    // Put the result Cursor in the adapter for the ListView

    mCursorAdapter.swapCursor(cursor);
  }
 @Override
 public void onLoaderReset(Loader<Cursor> loader) {
   mAdapter.swapCursor(null);
 }
 @Override
 public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
   mAdapter.swapCursor(data);
 }