Esempio n. 1
0
  /**
   * 设置view的监听器.
   *
   * @param field the field
   * @param methodName the method name
   * @param method the method
   * @throws Exception the exception
   */
  private void setListener(Field field, String methodName, int method) throws Exception {
    if (methodName == null || methodName.trim().length() == 0) return;

    Object obj = field.get(this);

    switch (method) {
      case AbIocEventListener.CLICK:
        if (obj instanceof View) {
          ((View) obj).setOnClickListener(new AbIocEventListener(this).click(methodName));
        }
        break;
      case AbIocEventListener.ITEMCLICK:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemClickListener(new AbIocEventListener(this).itemClick(methodName));
        }
        break;
      case AbIocEventListener.LONGCLICK:
        if (obj instanceof View) {
          ((View) obj).setOnLongClickListener(new AbIocEventListener(this).longClick(methodName));
        }
        break;
      case AbIocEventListener.ITEMLONGCLICK:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemLongClickListener(new AbIocEventListener(this).itemLongClick(methodName));
        }
        break;
      default:
        break;
    }
  }
Esempio n. 2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_item, container, false);

    // Set the adapter
    if (mAdapter != null) {
      if (isNewData()) {
        createNewAdapter();
      }
      mListView = (AbsListView) view.findViewById(android.R.id.list);
      mListView.setAdapter(mAdapter);
      // Set OnItemClickListener so we can be notified on item clicks
      mListView.setOnItemClickListener(this);
    } else {
      TextView noRestaurantView = (TextView) view.findViewById(R.id.noRestaurantView);
      noRestaurantView.setText("There aren't  any restaurants.");
    }

    FloatingActionButton addRestaurantButton =
        (FloatingActionButton) view.findViewById(R.id.addRestaurant);
    addRestaurantButton.setOnClickListener(this);
    mListener = (OnFragmentInteractionListener) getActivity();
    return view;
  }
 public ViewHolderHelper setClickListener(
     int viewId, AdapterView.OnItemClickListener listener, Object tag) {
   AbsListView absListView = findViewById(viewId);
   absListView.setOnItemClickListener(listener);
   absListView.setTag(tag);
   return this;
 }
  private static void setListener(
      Object injectedSource, Field field, String methodName, Method method) throws Exception {
    if (methodName == null || methodName.trim().length() == 0) return;

    Object obj = field.get(injectedSource);

    switch (method) {
      case Click:
        if (obj instanceof View) {
          ((View) obj).setOnClickListener(new EventListener(injectedSource).click(methodName));
        }
        break;
      case ItemClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemClickListener(new EventListener(injectedSource).itemClick(methodName));
        }
        break;
      case LongClick:
        if (obj instanceof View) {
          ((View) obj)
              .setOnLongClickListener(new EventListener(injectedSource).longClick(methodName));
        }
        break;
      case itemLongClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemLongClickListener(
                  new EventListener(injectedSource).itemLongClick(methodName));
        }
        break;
      default:
        break;
    }
  }
Esempio n. 5
0
 public void handleItemClickListener(AbsListView absListView, IOnItemClickListener listener) {
   mIOnItemClickListener = listener;
   mListView = absListView;
   if (mListView != null && mIOnItemClickListener != null) {
     mListView.setOnItemClickListener(this);
   }
 }
 public DropdownContainer(
     Context context,
     int layout_id,
     Drawable background,
     DropdownAdapter adapter,
     OnItemClickListener listener) {
   super(context);
   int m = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
   AbsListView content = (AbsListView) LayoutInflater.from(context).inflate(layout_id, null);
   if (content instanceof ListView) {
     ((ListView) content).setAdapter((BaseAdapter) adapter);
   } else if (content instanceof GridView) {
     ((GridView) content).setAdapter((BaseAdapter) adapter);
   }
   content.setOnItemClickListener(listener);
   content.measure(m, m);
   if (adapter.getRows() > adapter.getWrapRow()) {
     init(
         content,
         LayoutParams.WRAP_CONTENT,
         content.getMeasuredHeight() * adapter.getWrapRow(),
         R.style.drop_down_anim,
         background);
   } else {
     init(
         content,
         LayoutParams.WRAP_CONTENT,
         LayoutParams.WRAP_CONTENT,
         R.style.drop_down_anim,
         background);
   }
 }
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    if (currentView == null) return;

    NodesAdapter nodesAdapter = new NodesAdapter(getActivity(), nodes, pickedFiles);

    if (viewType.equals(THUMBNAILS_VIEW)) nodesAdapter.setThumbnail(true);

    currentView.setAdapter(nodesAdapter);

    currentView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            // Clicked node object
            Node node = (Node) parent.getAdapter().getItem(position);

            // If node is dir then open it
            if (node.isDir) {
              getContract().showNextNode(node);
            }
          }
        });

    currentView.setVisibility(View.VISIBLE);

    // Form consists of input for name, text with extension and save button
    initForm();
  }
Esempio n. 8
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the view and assign to property
    mView = inflater.inflate(R.layout.fragment_litter_list, container, false);

    // Get the litters
    getLastestLitters();

    // Components

    mLitterMessage = (EditText) mView.findViewById(R.id.litterMessage);
    mTakePictureButton = (ImageButton) mView.findViewById(R.id.takePicture);
    mPostLitterPanel = mView.findViewById(R.id.postLitter);
    mCancelLitterPanel = mView.findViewById(R.id.cancelLitter);

    mListView = (AbsListView) mView.findViewById(android.R.id.list);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);

    // Listeners for buttons
    mTakePictureButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            ViewUtils.animateButtonPress(v);
          }
        });

    mPostLitterPanel.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            ViewUtils.animateButtonPress(v);

            mListener.postLitterPressed(mLitterMessage.getText().toString());
          }
        });

    mCancelLitterPanel.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mListener.cancelLitterPressed();
          }
        });

    // Make the post section "gone" (this is only done here so the file can be easily edited in the
    // view editor)
    View litterLayout = mView.findViewById(R.id.litterLayout);
    litterLayout.setVisibility(View.GONE);

    return mView;
  }
Esempio n. 9
0
 /**
  * Sets up various helpers for both the list and grid
  *
  * @param list The list or grid
  */
 private void initAbsListView(final AbsListView list) {
   // Release any references to the recycled Views
   list.setRecyclerListener(new RecycleHolder());
   // Listen for ContextMenus to be created
   list.setOnCreateContextMenuListener(this);
   // Show the albums and songs from the selected artist
   list.setOnItemClickListener(this);
   // To help make scrolling smooth
   list.setOnScrollListener(this);
 }
Esempio n. 10
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_recipeoverview_list, container, false);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);

    return view;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_posterlist, container, false);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(R.id.grid_view);
    mListView.setAdapter(mAdapter);
    Log.i(LOG_TAG, "Set adapter in onCreateView");

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);

    return view;
  }
Esempio n. 12
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_log, container, false);

    setHasOptionsMenu(true);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);

    View emptyView = view.findViewById(R.id.internalEmpty);
    mListView.setEmptyView(emptyView);

    mListContainer = view.findViewById(R.id.listContainer);
    mProgressContainer = view.findViewById(R.id.progressContainer);
    mListShown = true;
    return view;
  }
Esempio n. 13
0
 @Override
 public void receiveAbsListView(AbsListView listView) {
   listView.setAdapter(pcGridAdapter);
   listView.setOnItemClickListener(
       new OnItemClickListener() {
         @Override
         public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long id) {
           ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(pos);
           if (computer.details.reachability == ComputerDetails.Reachability.UNKNOWN
               || computer.details.reachability == ComputerDetails.Reachability.OFFLINE) {
             // Open the context menu if a PC is offline or refreshing
             openContextMenu(arg1);
           } else if (computer.details.pairState != PairState.PAIRED) {
             // Pair an unpaired machine by default
             doPair(computer.details);
           } else {
             doAppList(computer.details);
           }
         }
       });
   registerForContextMenu(listView);
 }
  /**
   * 设置view的监听器
   *
   * @param field the field
   * @param methodName the method name
   * @param method the method
   * @throws Exception the exception
   */
  public void setListener(Field field, String methodName, EmMethod method) throws Exception {
    if (methodName == null || methodName.trim().length() == 0) return;

    Object obj = field.get(mActivity);

    switch (method) {
      case Click:
        if (obj instanceof View) {
          ((View) obj).setOnClickListener(new AbIocEventListener(mActivity).click(methodName));
        }
        break;

      case ItemClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemClickListener(new AbIocEventListener(mActivity).itemClick(methodName));
        }
        break;

      case LongClick:
        if (obj instanceof View) {
          ((View) obj)
              .setOnLongClickListener(new AbIocEventListener(mActivity).longClick(methodName));
        }
        break;

      case itemLongClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemLongClickListener(
                  new AbIocEventListener(mActivity).itemLongClick(methodName));
        }
        break;

      default:
        break;
    }
  }
Esempio n. 15
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_item, container, false);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);

    View addButton = view.findViewById(R.id.add_button);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      setMaterialLayout(addButton);
    } else {
      addButton.setBackgroundResource(R.drawable.oval);
    }

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);
    mListView.setOnItemLongClickListener(this);
    mListView.setOnScrollListener(mOnScrollListener);

    return view;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_news, container, false);

    switch (mTableContentType) {
      case 1:
        ArrayList<HashMap<String, String>> companyList = DB.getCompanyList();
        mAdapter =
            new SimpleAdapter(
                getActivity(),
                companyList,
                R.layout.fragment_news_entry,
                new String[] {"id", "name"},
                new int[] {R.id.entry_id, R.id.entry_name});
        mListView = (AbsListView) view.findViewById(android.R.id.list);
        ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);

        mListView.setOnItemClickListener(
            new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectedID = (TextView) view.findViewById(R.id.entry_id);
                String entryID = selectedID.getText().toString();
                NewsFragment fragment1 = NewsFragment.newInstance(2, entryID);
                android.app.FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.container, fragment1).commit();
              }
            });
        break;
      case 2:
        ArrayList<HashMap<String, String>> departmentList = DB.getDepartmentList(mCompanyID);
        mAdapter =
            new SimpleAdapter(
                getActivity(),
                departmentList,
                R.layout.fragment_news_entry,
                new String[] {"id", "name"},
                new int[] {R.id.entry_id, R.id.entry_name});
        mListView = (AbsListView) view.findViewById(android.R.id.list);
        ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);

        mListView.setOnItemClickListener(
            new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectedID = (TextView) view.findViewById(R.id.entry_id);
                String entryID = selectedID.getText().toString();
                fragment = Description.newInstance(2, entryID);
                android.app.FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
              }
            });

        break;
      case 3:
        ArrayList<HashMap<String, String>> newsList = DB.getNewsList();
        mAdapter =
            new SimpleAdapter(
                getActivity(),
                newsList,
                R.layout.fragment_news_entry,
                new String[] {"id", "name"},
                new int[] {R.id.entry_id, R.id.entry_name});
        mListView = (AbsListView) view.findViewById(android.R.id.list);
        ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);

        mListView.setOnItemClickListener(
            new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectedID = (TextView) view.findViewById(R.id.entry_id);
                String entryID = selectedID.getText().toString();
                fragment = Description.newInstance(3, entryID);
                android.app.FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
              }
            });
        break;
    }

    return view;
  }
Esempio n. 17
0
  /** Show lines in a list dialog * */
  private void showLines() {
    LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = li.inflate(R.layout.list, null, false);

    TextView titleText = (TextView) v.findViewById(R.id.title);
    titleText.setVisibility(View.GONE);
    TextView helpText = (TextView) v.findViewById(R.id.help);
    helpText.setVisibility(View.GONE);

    final Dialog listDialog = new Dialog(this);
    listDialog.setTitle(getString(R.string.choose_line));
    listDialog.setContentView(v);
    listDialog.setCancelable(true);

    // Get all stations in the cursor
    final Cursor l = helper.getLinesByName("");
    startManagingCursor(l);

    // Set up a list adapter with two fields
    final CursorAdapter lAdapter =
        new SimpleCursorAdapter(
            this, R.layout.row_alt, l, fields, new int[] {R.id.itemId, R.id.itemName});

    AbsListView list = (AbsListView) listDialog.findViewById(android.R.id.list);
    list.setAdapter(lAdapter);
    list.setFastScrollEnabled(true);

    // Listen for clicks on items in the list
    list.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            // Get id of line clicked
            Cursor cursor = (Cursor) lAdapter.getItem(arg2);
            final String lineId = cursor.getString(cursor.getColumnIndex("_id"));
            final String lineName = cursor.getString(cursor.getColumnIndex("name"));
            final String lineDescA = cursor.getString(cursor.getColumnIndex("desc_a"));
            final String lineDescB = cursor.getString(cursor.getColumnIndex("desc_b"));

            // Build and show direction dialog
            AlertDialog.Builder builder = new AlertDialog.Builder(arg1.getContext());
            builder
                .setTitle(getString(R.string.choose_direction) + " " + lineName)
                .setMessage("(A) " + lineDescA + "\n\n" + "(B) " + lineDescB)
                .setPositiveButton(
                    "A",
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        listDialog.dismiss();
                        stopManagingCursor(l);
                        l.close();

                        lineSummary = lineDescA;

                        // Draw line markers in direction "A"
                        drawLineMarkers(lineId, "A");
                      }
                    })
                .setNegativeButton(
                    "B",
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        listDialog.dismiss();
                        stopManagingCursor(l);
                        l.close();

                        lineSummary = lineDescB;

                        // Draw line markers in direction "B"
                        drawLineMarkers(lineId, "B");
                      }
                    });
            AlertDialog alert = builder.create();
            alert.show();
          }
        });

    listDialog.show();
  }
  @Override
  protected void onFinishInflate() {

    mFilterList = (AbsListView) findViewById(R.id.filteredList);
    mFilterList.setTextFilterEnabled(true);

    mEmptyView = (TextView) findViewById(R.id.empty);

    mFilterList.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor c = (Cursor) mFilterList.getItemAtPosition(position);

            if (mListener != null) mListener.openChat(c);
          }
        });

    mFilterList.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          @Override
          public boolean onItemLongClick(
              AdapterView<?> arg0, View arg1, final int position, long arg3) {

            String[] contactOptions = {
              //        mContext.getString(R.string.menu_verify),
              mContext.getString(R.string.menu_contact_nickname),
              mContext.getString(R.string.menu_remove_contact)
            };
            //      mContext.getString(R.string.menu_block_contact)};

            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setItems(
                contactOptions,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    // The 'which' argument contains the index position
                    // of the selected item

                    if (which == 0) setContactNickname(position);
                    else if (which == 1) removeContactAtPosition(position);
                    else if (which == 2) blockContactAtPosition(position);
                  }
                });

            builder.create().show();

            return true;
          }
        });

    /**
     * mEtSearch = (EditText)findViewById(R.id.contactSearch);
     *
     * <p>mEtSearch.addTextChangedListener(new TextWatcher() { @Override public void
     * afterTextChanged(Editable s) {
     *
     * <p>} @Override public void beforeTextChanged(CharSequence s, int start, int count, int after)
     * {
     *
     * <p>} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {
     *
     * <p>ContactListFilterView.this.doFilter(mEtSearch.getText().toString());
     *
     * <p>}
     *
     * <p>});
     *
     * <p>mEtSearch.setOnKeyListener(new OnKeyListener () { @Override public boolean onKey(View v,
     * int keyCode, KeyEvent event) {
     *
     * <p>ContactListFilterView.this.doFilter(mEtSearch.getText().toString()); return false; }
     *
     * <p>});
     */

    /*
        mFilterList.setItemActionListener(new ListView.OnActionClickListener() {

            @Override
            public void onClick(View listView, View buttonview, int position) {

                Cursor c = (Cursor) mFilterList.getItemAtPosition(position);
                if (mListener != null)
                    if (buttonview.getId() == R.id.btnExListChat)
                        mListener.startChat(c);
                    else if (buttonview.getId() == R.id.btnExListProfile)
                        mListener.showProfile(c);

            }
    }, R.id.btnExListChat, R.id.btnExListProfile);
    */

    //

    // if (!isInEditMode())
    //  mPresenceView = (UserPresenceView) findViewById(R.id.userPresence);

  }