@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);
      }
    }
    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;
    }
Esempio n. 3
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);
  }
Esempio n. 5
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;
    }
Esempio n. 6
0
 @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;
 }
    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);
    }
Esempio n. 8
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);
    fragmentActivity = super.getActivity();

    Bundle args = this.getArguments();
    if (args != null) {
      currentWorkspaceId = args.getInt(DatabaseHandler.KEY_WORKSPACEID);
    }

    icon = (ImageView) getActivity().findViewById(R.id.taskIcon);
    checkList = (ListView) getActivity().findViewById(R.id.ListViewChecklistList);

    checkList.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(fragmentActivity, ChecklistViewActivity.class);
            Bundle extras = new Bundle();
            Cursor c = (Cursor) mAdapterChecklist.getItem(position);
            int checklistIdIndex = c.getColumnIndex(DatabaseHandler.KEY_COLUMNID);
            int checklistId = c.getInt(checklistIdIndex);
            // extras.putInt(ActivityCodeConstants.ACTIVITY_CODE_STRING,
            // ActivityCodeConstants.TASKLIST_VIEW_ACTIVITY);
            extras.putInt(ScratchChecklistColumns._ID, checklistId);
            extras.putString(
                DatabaseHandler.KEY_CHECKLISTNAME,
                c.getString(c.getColumnIndex(DatabaseHandler.KEY_CHECKLISTNAME)));
            extras.putString(
                DatabaseHandler.KEY_NOTE, c.getString(c.getColumnIndex(DatabaseHandler.KEY_NOTE)));
            extras.putString(
                DatabaseHandler.KEY_DUEDATE,
                c.getString(c.getColumnIndex(DatabaseHandler.KEY_DUEDATE)));
            extras.putString(
                DatabaseHandler.KEY_DUETIME,
                c.getString(c.getColumnIndex(DatabaseHandler.KEY_DUETIME)));
            extras.putInt(
                DatabaseHandler.KEY_PRIORITY,
                c.getInt(c.getColumnIndex(DatabaseHandler.KEY_PRIORITY)));
            intent.putExtras(extras);
            startActivity(intent);
          }
        });

    String[] checklistColumns =
        new String[] {
          ScratchChecklistColumns.CHECKLISTNAME,
          ScratchChecklistColumns.CHECKLISTNAME,
          ScratchChecklistColumns.DUEDATE,
          ScratchChecklistColumns.DUEDATE
        };

    boundToChecklist =
        new int[] {R.id.taskIcon, R.id.taskName, R.id.taskDateTop, R.id.taskDateBottom};

    // adapter
    mAdapterChecklist =
        new SimpleCursorAdapter(
            getActivity(),
            R.layout.task_list_view_item,
            null,
            checklistColumns,
            boundToChecklist,
            0);

    // make the adapter use our ViewBinder
    mAdapterChecklist.setViewBinder(new TabCheckListViewBinder());

    // content resolver
    resolver = getActivity().getContentResolver();

    // make the ListView use our mTaskAdapter
    checkList.setAdapter(mAdapterChecklist);

    // loader manager initialization
    getLoaderManager().initLoader(LOADER_ID_CHECKLIST, null, this);

    XGestureListener x = new XGestureListener();
    x.setAdapter(mAdapterChecklist);
    Bundle columns = new Bundle();
    columns.putString("name", DatabaseHandler.KEY_CHECKLISTNAME);
    columns.putString("id", DatabaseHandler.KEY_COLUMNID);
    x.setColumns(columns);
    x.setContentResolver(resolver);
    x.setFragmentActivity(fragmentActivity);
    x.setListView(checkList);
    x.setTargetActivity(fragmentActivity);
    x.setUri(GobiContentProvider.CONTENT_URI_SCRATCH_CHECKLIST);
    x.setBoolean(false);
    // gesture detector
    mGdetector = new GestureDetectorCompat(fragmentActivity.getApplicationContext(), x);
    gestureListener =
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return mGdetector.onTouchEvent(event);
          }
        };

    // make our adapter use our gesture listener
    checkList.setOnTouchListener(gestureListener);
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mRoot = (DisableTouchFrameLayout) inflater.inflate(R.layout.start_fragment, null);

    mProgressBar = (ProgressBar) mRoot.findViewById(R.id.start_fragment_pb);

    mLoginBtn = (LoginButton) mRoot.findViewById(android.R.id.empty);
    mLoginBtn.setFragment(this);

    mAdapter =
        new SimpleCursorAdapter(getActivity(), R.layout.layout_item_friend, null, from, to, 0);
    mAdapter.setViewBinder(
        new ViewBinder() {

          @Override
          public boolean setViewValue(View view, Cursor cursor, int index) {

            int viewId = view.getId();

            if (viewId == R.id.item_friend_image) {

              ImageView avatar = (ImageView) view;

              String photoUrl =
                  cursor.getString(cursor.getColumnIndex(DBHelper.KEY_COLUMN_PICTURE));
              if (mImageLoader != null
                  && mOptions != null
                  && photoUrl != null
                  && !TextUtils.isEmpty(photoUrl))
                mImageLoader.displayImage(
                    photoUrl,
                    avatar,
                    mOptions,
                    new ImageLoadingListener() {

                      @Override
                      public void onLoadingStarted(String arg0, View arg1) {

                        activeDownloaders++;
                        if (!UtilHelper.isImageDownloaded()) {}
                      }

                      @Override
                      public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {

                        activeDownloaders--;
                        if (!UtilHelper.isImageDownloaded() && !mCheckDisableTouch) {

                          checkDisableTouch();
                        }
                      }

                      @Override
                      public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {

                        activeDownloaders--;
                        if (!UtilHelper.isImageDownloaded() && !mCheckDisableTouch) {

                          checkDisableTouch();
                        }
                      }

                      @Override
                      public void onLoadingCancelled(String arg0, View arg1) {

                        activeDownloaders--;
                        if (!UtilHelper.isImageDownloaded() && !mCheckDisableTouch) {

                          checkDisableTouch();
                        }
                      }
                    });

              return true;
            }
            return false;
          }
        });
    setListAdapter(mAdapter);
    getLoaderManager().restartLoader(FRIENDS_LOADER_ID, null, this);

    return mRoot;
  }
Esempio n. 10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    listView = (ListView) findViewById(R.id.listView1);
    keywordView = (EditText) findViewById(R.id.editText1);
    String[] from = {Contacts._ID, Contacts.DISPLAY_NAME};
    int[] to = {R.id.photo, R.id.name_view};
    mAdapter = new SimpleCursorAdapter(this, R.layout.contacts_item_layout, null, from, to, 0);
    mAdapter.setViewBinder(
        new ViewBinder() {

          @Override
          public boolean setViewValue(View view, Cursor c, int columnIndex) {
            if (idColumnIndex == columnIndex) {

              QuickContactBadge badge = (QuickContactBadge) view;
              long id = c.getLong(columnIndex);
              Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
              badge.assignContactUri(uri);
              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(Contacts.CONTENT_URI, id);
          }
        });

    keywordView.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            String keyword = s.toString();
            if (keyword != null && !keyword.equals("")) {
              searchContacts(keyword);
            } else {
              initData();
            }
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

          }

          @Override
          public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

          }
        });

    Button btn = (Button) findViewById(R.id.button1);
    btn.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            String keyword = keywordView.getText().toString();
            if (keyword != null && !keyword.equals("")) {
              searchContacts(keyword);
            } else {
              initData();
            }
          }
        });

    initData();
  }
Esempio n. 11
0
  /* (non-Javadoc)
   * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
   */
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    itsProviderAdapter =
        new SimpleCursorAdapter(
            getActivity(),
            R.layout.sync_provider_list_item,
            null,
            new String[] {
              PasswdSafeContract.Providers.COL_ACCT,
              PasswdSafeContract.Providers.COL_TYPE,
              PasswdSafeContract.Providers.COL_TYPE
            },
            new int[] {android.R.id.text1, android.R.id.text2, R.id.icon},
            0);
    itsProviderAdapter.setViewBinder(
        new SimpleCursorAdapter.ViewBinder() {
          @Override
          public boolean setViewValue(View view, Cursor cursor, int colIdx) {
            int id = view.getId();
            switch (id) {
              case android.R.id.text1:
                {
                  String displayName = PasswdSafeContract.Providers.getDisplayName(cursor);
                  TextView tv = (TextView) view;
                  tv.setText(displayName);
                  return true;
                }
              case android.R.id.text2:
              case R.id.icon:
                {
                  try {
                    String typeStr = cursor.getString(colIdx);
                    ProviderType type = ProviderType.valueOf(typeStr);
                    switch (id) {
                      case android.R.id.text2:
                        {
                          type.setText((TextView) view);
                          break;
                        }
                      case R.id.icon:
                        {
                          type.setIcon((ImageView) view);
                          break;
                        }
                    }
                    return true;
                  } catch (IllegalArgumentException e) {
                    return false;
                  }
                }
            }
            return false;
          }
        });
    setListAdapter(itsProviderAdapter);

    itsHasProvider = checkProvider();
    getLoaderManager().initLoader(0, null, this);
  }
 StudyRoomAdapter(Cursor studyRoomCursor) {
   mCursorAdapter = createStudyRoomCursorAdapter(studyRoomCursor);
   mCursorAdapter.setViewBinder(StudyRoomGroupDetailsFragment.this);
 }