Exemplo n.º 1
0
  @SuppressLint("NewApi")
  private void scroll(final float height) {
    if (mType == TYPE_INDICATOR || mType == TYPE_INDICATOR_WITH_HANDLE) {
      float move = height - (mScrollIndicator.getHeight() / 2);

      if (move < 0) move = 0;
      else if (move > getHeight() - mScrollIndicator.getHeight())
        move = getHeight() - mScrollIndicator.getHeight();

      if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        mScrollIndicator.startAnimation(moveCompat(move));
      else mScrollIndicator.setTranslationY(move);
    }

    if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE) {
      mHandlebar.setSelected(true);
      moveHandlebar(height - (mHandlebar.getHeight() / 2));
    }

    int postition = (int) ((height / getHeight()) * mItemCount);
    if (mList instanceof ExpandableListView) {
      final int grouppos =
          ExpandableListView.getPackedPositionGroup(
              ((ExpandableListView) mList).getExpandableListPosition(postition));
      if (grouppos != -1) mGroupPosition = grouppos;
    }

    if (postition < 0) postition = 0;
    else if (postition >= mItemCount) postition = mItemCount - 1;
    mScrollIndicatorText.setText(mScrollable.getIndicatorForPosition(postition, mGroupPosition));
    mList.setSelection(mScrollable.getScrollPosition(postition, mGroupPosition));
  }
Exemplo n.º 2
0
  public void testRatings() {
    titleView = expandableListView.getChildAt(0);
    stars = (RatingBar) titleView.findViewById(R.id.providerpf_comment_stars);
    date = (TextView) titleView.findViewById(R.id.providerpf_comment_date);
    userName = (TextView) titleView.findViewById(R.id.providerpf_user_name);
    assertEquals("By username1", userName.getText());
    assertEquals("2012-12-12 ", date.getText());
    assertEquals(5.0, stars.getRating(), 0.0);

    titleView = expandableListView.getChildAt(1);
    stars = (RatingBar) titleView.findViewById(R.id.providerpf_comment_stars);
    date = (TextView) titleView.findViewById(R.id.providerpf_comment_date);
    userName = (TextView) titleView.findViewById(R.id.providerpf_user_name);
    assertEquals("By username2", userName.getText());
    assertEquals("2012-11-12 ", date.getText());
    assertEquals(3.0, stars.getRating(), 0.0);

    titleView = expandableListView.getChildAt(2);
    stars = (RatingBar) titleView.findViewById(R.id.providerpf_comment_stars);
    date = (TextView) titleView.findViewById(R.id.providerpf_comment_date);
    userName = (TextView) titleView.findViewById(R.id.providerpf_user_name);
    assertEquals("By username3", userName.getText());
    assertEquals("2012-10-12 ", date.getText());
    assertEquals(3.0, stars.getRating(), 0.0);

    titleView = expandableListView.getChildAt(3);
    stars = (RatingBar) titleView.findViewById(R.id.providerpf_comment_stars);
    date = (TextView) titleView.findViewById(R.id.providerpf_comment_date);
    userName = (TextView) titleView.findViewById(R.id.providerpf_user_name);
    assertEquals("By username4", userName.getText());
    assertEquals("2012-09-12 ", date.getText());
    assertEquals(4.0, stars.getRating(), 0.0);

    listAdapter = expandableListView.getExpandableListAdapter();
    listView = listAdapter.getChildView(0, 0, true, null, null);
    tv_provider_summary = (TextView) listView.findViewById(R.id.providerpf_rate_review_summary);
    assertEquals(tv_provider_summary.getText(), "Very Good");
    tv_pro1 = (TextView) listView.findViewById(R.id.providerpf_review_pro1);
    assertEquals(tv_pro1.getText(), "care about patient");
    tv_pro2 = (TextView) listView.findViewById(R.id.providerpf_review_pro2);
    assertEquals(tv_pro2.getText(), "quick diagnosis");
    tv_pro3 = (TextView) listView.findViewById(R.id.providerpf_review_pro3);
    assertEquals(tv_pro3.getText(), "easy for parking");
    tv_con1 = (TextView) listView.findViewById(R.id.providerpf_review_con1);
    assertEquals(tv_con1.getText(), "don't care about patient");
    tv_con2 = (TextView) listView.findViewById(R.id.providerpf_review_con2);
    assertEquals(tv_con2.getText(), "slow diagnosis");
    tv_con3 = (TextView) listView.findViewById(R.id.providerpf_review_con3);
    assertEquals(tv_con3.getText(), "hard for parking");
    tv_provider_desc = (TextView) listView.findViewById(R.id.providerpf_comment_review);
    assertEquals(tv_provider_desc.getText(), "A good doctor!");
    listView = listAdapter.getChildView(1, 0, true, null, null);
    tv_provider_summary = (TextView) listView.findViewById(R.id.providerpf_rate_review_summary);
    assertEquals(tv_provider_summary.getText(), "");
    tv_pro1 = (TextView) listView.findViewById(R.id.providerpf_review_pro1);
    assertEquals(tv_pro1.getText(), "care about patient");
    tv_pro2 = (TextView) listView.findViewById(R.id.providerpf_review_pro2);
    assertEquals(tv_pro2.getText(), "quick diagnosis");
    tv_pro3 = (TextView) listView.findViewById(R.id.providerpf_review_pro3);
    assertEquals(tv_pro3.getText(), "");
    tv_con1 = (TextView) listView.findViewById(R.id.providerpf_review_con1);
    assertEquals(tv_con1.getText(), "don't care about patient");
    tv_con2 = (TextView) listView.findViewById(R.id.providerpf_review_con2);
    assertEquals(tv_con2.getText(), "");
    tv_con3 = (TextView) listView.findViewById(R.id.providerpf_review_con3);
    assertEquals(tv_con3.getText(), "");
    tv_provider_desc = (TextView) listView.findViewById(R.id.providerpf_comment_review);
    assertEquals(tv_provider_desc.getText(), "");
    listView = listAdapter.getChildView(2, 0, true, null, null);
    tv_provider_summary = (TextView) listView.findViewById(R.id.providerpf_rate_review_summary);
    assertEquals(tv_provider_summary.getText(), "Fair");
    tv_pro1 = (TextView) listView.findViewById(R.id.providerpf_review_pro1);
    assertEquals(tv_pro1.getText(), "adequate parking");
    tv_pro2 = (TextView) listView.findViewById(R.id.providerpf_review_pro2);
    assertEquals(tv_pro2.getText(), "availability of appointments");
    tv_pro3 = (TextView) listView.findViewById(R.id.providerpf_review_pro3);
    assertEquals(tv_pro3.getText(), "cleanliness/attractiveness of office");
    tv_con1 = (TextView) listView.findViewById(R.id.providerpf_review_con1);
    assertEquals(tv_con1.getText(), "");
    tv_con2 = (TextView) listView.findViewById(R.id.providerpf_review_con2);
    assertEquals(tv_con2.getText(), "");
    tv_con3 = (TextView) listView.findViewById(R.id.providerpf_review_con3);
    assertEquals(tv_con3.getText(), "");
    tv_provider_desc = (TextView) listView.findViewById(R.id.providerpf_comment_review);
    assertEquals(tv_provider_desc.getText(), "Hard to say - just so so");
    listView = listAdapter.getChildView(3, 0, true, null, null);
    tv_provider_summary = (TextView) listView.findViewById(R.id.providerpf_rate_review_summary);
    assertEquals(tv_provider_summary.getText(), "Good");
    tv_pro1 = (TextView) listView.findViewById(R.id.providerpf_review_pro1);
    assertEquals(tv_pro1.getText(), "");
    tv_pro2 = (TextView) listView.findViewById(R.id.providerpf_review_pro2);
    assertEquals(tv_pro2.getText(), "");
    tv_pro3 = (TextView) listView.findViewById(R.id.providerpf_review_pro3);
    assertEquals(tv_pro3.getText(), "");
    tv_con1 = (TextView) listView.findViewById(R.id.providerpf_review_con1);
    assertEquals(tv_con1.getText(), "");
    tv_con2 = (TextView) listView.findViewById(R.id.providerpf_review_con2);
    assertEquals(tv_con2.getText(), "");
    tv_con3 = (TextView) listView.findViewById(R.id.providerpf_review_con3);
    assertEquals(tv_con3.getText(), "");
    tv_provider_desc = (TextView) listView.findViewById(R.id.providerpf_comment_review);
    assertEquals(tv_provider_desc.getText(), "He is so handsome:)");
  }
Exemplo n.º 3
0
 @SuppressWarnings("ConstantConditions")
 public static void setEventListener(
     Object handler,
     ViewFinder finder,
     DoubleKeyValueMap<Object, Annotation, Method> value_annotation_method_map) {
   for (Object value : value_annotation_method_map.getFirstKeys()) {
     ConcurrentHashMap<Annotation, Method> annotation_method_map =
         value_annotation_method_map.get(value);
     for (Annotation annotation : annotation_method_map.keySet()) {
       try {
         Method method = annotation_method_map.get(annotation);
         if (annotation.annotationType().equals(OnClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnLongClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnLongClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnFocusChange.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnFocusChangeListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnKey.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnKeyListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnTouch.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnTouchListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnItemClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((AdapterView<?>) view)
               .setOnItemClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnItemLongClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((AdapterView<?>) view)
               .setOnItemLongClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnChildClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((ExpandableListView) view)
               .setOnChildClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnGroupClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((ExpandableListView) view)
               .setOnGroupClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnGroupCollapse.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((ExpandableListView) view)
               .setOnGroupCollapseListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnGroupExpand.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((ExpandableListView) view)
               .setOnGroupExpandListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnCheckedChange.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           if (view instanceof RadioGroup) {
             ((RadioGroup) view)
                 .setOnCheckedChangeListener(new ViewCommonEventListener(handler, method));
           } else if (view instanceof CompoundButton) {
             ((CompoundButton) view)
                 .setOnCheckedChangeListener(new ViewCommonEventListener(handler, method));
           }
         } else if (annotation.annotationType().equals(OnPreferenceClick.class)) {
           Preference preference = finder.findPreference(value.toString());
           if (preference == null) break;
           preference.setOnPreferenceClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnPreferenceChange.class)) {
           Preference preference = finder.findPreference(value.toString());
           if (preference == null) break;
           preference.setOnPreferenceChangeListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnTabChange.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((TabHost) view).setOnTabChangedListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnScrollChanged.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.getViewTreeObserver()
               .addOnScrollChangedListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnScrollStateChanged.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           Method method0 = null, method1 = null;
           ConcurrentHashMap<Annotation, Method> a_m_map = value_annotation_method_map.get(value);
           for (Annotation a : a_m_map.keySet()) {
             if (a.annotationType().equals(OnScrollStateChanged.class)) {
               method0 = a_m_map.get(a);
             } else if (a.annotationType().equals(OnScroll.class)) {
               method1 = a_m_map.get(a);
             }
           }
           ((AbsListView) view)
               .setOnScrollListener(new ViewCommonEventListener(handler, method0, method1));
         } else if (annotation.annotationType().equals(OnItemSelected.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           Method method0 = null, method1 = null;
           ConcurrentHashMap<Annotation, Method> a_m_map = value_annotation_method_map.get(value);
           for (Annotation a : a_m_map.keySet()) {
             if (a.annotationType().equals(OnItemSelected.class)) {
               method0 = a_m_map.get(a);
             } else if (a.annotationType().equals(OnNothingSelected.class)) {
               method1 = a_m_map.get(a);
             }
           }
           ((AdapterView<?>) view)
               .setOnItemSelectedListener(new ViewCommonEventListener(handler, method0, method1));
         } else if (annotation.annotationType().equals(OnProgressChanged.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           Method method0 = null, method1 = null, method2 = null;
           ConcurrentHashMap<Annotation, Method> a_m_map = value_annotation_method_map.get(value);
           for (Annotation a : a_m_map.keySet()) {
             if (a.annotationType().equals(OnProgressChanged.class)) {
               method0 = a_m_map.get(a);
             } else if (a.annotationType().equals(OnStartTrackingTouch.class)) {
               method1 = a_m_map.get(a);
             } else if (a.annotationType().equals(OnStopTrackingTouch.class)) {
               method2 = a_m_map.get(a);
             }
           }
           ((SeekBar) view)
               .setOnSeekBarChangeListener(
                   new ViewCommonEventListener(handler, method0, method1, method2));
         }
       } catch (Throwable e) {
         LogUtils.e(e.getMessage(), e);
       }
     }
   }
 }
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final ExpandableListAdapter adapter =
        new BaseExpandableListAdapter() {
          private String[] ArticlesPark =
              new String[] {
                "前言", "FormWidget", "Layout", "Picker",
              };
          private String[][] Articles =
              new String[][] {
                {"写在前面的话", "一些好的和“好的”品质"},
                {"TextView", "EditText", "Button", "Switch"},
                {"LinearLayout", "RelativeLayout", "TableLayout", "GridLayout"},
                {"TimePicker", "DatePicker", "NumberPicker"},
              };

          TextView getTextView() {
            AbsListView.LayoutParams lp =
                new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 64);
            TextView textView = new TextView(MainActivity.this);
            textView.setLayoutParams(lp);
            textView.setGravity(Gravity.CENTER_HORIZONTAL);
            textView.setPadding(36, 0, 0, 0);
            textView.setTextSize(20);
            textView.setTextColor(Color.BLACK);
            return textView;
          }

          @Override
          public int getGroupCount() {
            return ArticlesPark.length;
          }

          @Override
          public Object getGroup(int groupPosition) {
            return ArticlesPark[groupPosition];
          }

          @Override
          public long getGroupId(int groupPosition) {
            return groupPosition;
          }

          @Override
          public int getChildrenCount(int groupPosition) {
            return Articles[groupPosition].length;
          }

          @Override
          public Object getChild(int groupPosition, int childPosition) {
            return Articles[groupPosition][childPosition];
          }

          @Override
          public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
          }

          @Override
          public boolean hasStableIds() {
            return true;
          }

          @Override
          public View getGroupView(
              int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
            LinearLayout ll = new LinearLayout(MainActivity.this);
            ll.setOrientation(0);
            ImageView logo = new ImageView(MainActivity.this);
            logo.setPadding(50, 0, 0, 0);
            ll.addView(logo);
            TextView textView = getTextView();
            textView.setTextColor(Color.BLACK);
            textView.setText(getGroup(groupPosition).toString());
            ll.addView(textView);
            return ll;
          }

          @Override
          public View getChildView(
              int groupPosition,
              int childPosition,
              boolean isLastChild,
              View convertView,
              ViewGroup parent) {
            LinearLayout ll = new LinearLayout(MainActivity.this);
            ll.setOrientation(0);
            ImageView generallogo = new ImageView(MainActivity.this);
            ll.addView(generallogo);
            TextView textView = getTextView();
            textView.setText(getChild(groupPosition, childPosition).toString());
            ll.addView(textView);
            return ll;
          }

          @Override
          public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
          }
        };
    ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.list);
    expandableListView.setAdapter(adapter);
    expandableListView.setOnChildClickListener(
        new OnChildClickListener() {
          @Override
          public boolean onChildClick(
              ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            // Toast.makeText(MainActivity.this,"你点击了" +
            // adapter.getChild(groupPosition,
            // childPosition),Toast.LENGTH_SHORT).show();
            /*
             * if(groupPosition==0) { if(childPosition==0) { to = new
             * Intent(
             * MainActivity.this,com.geno.tutorial.articles.foreword.Foreword
             * .class); startActivity(to); } else if(child) { to = new
             * Intent
             * (MainActivity.this,com.geno.tutorial.articles.foreword.Goodhabit
             * .class); startActivity(to); } }
             */
            switch (groupPosition) {
              case 0:
                switch (childPosition) {
                  case 0:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.foreword.Foreword.class);
                    startActivity(p);
                    break;
                  case 1:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.foreword.Goodhabit.class);
                    startActivity(p);
                    break;
                }
                break;
              case 1:
                switch (childPosition) {
                  case 0:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.formwidget.Text.class);
                    startActivity(p);
                    break;
                  case 1:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.formwidget.Edit.class);
                    startActivity(p);
                    break;
                  case 2:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.formwidget.Buttonn.class);
                    startActivity(p);
                    break;
                  case 3:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.formwidget.Switchh.class);
                    startActivity(p);
                    break;
                }
                break;
              case 2:
                switch (childPosition) {
                  case 0:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.layout.Linear.class);
                    startActivity(p);
                    break;
                  case 1:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.layout.Relative.class);
                    startActivity(p);
                    break;
                  case 2:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.layout.Table.class);
                    startActivity(p);
                    break;
                  case 3:
                    p = new Intent(MainActivity.this, com.geno.tutorial.articles.layout.Grid.class);
                    startActivity(p);
                    break;
                }
                break;
              case 3:
                switch (childPosition) {
                  case 0:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.picker.TimeP.class);
                    startActivity(p);
                    break;
                  case 1:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.picker.DateP.class);
                    startActivity(p);
                    break;
                  case 2:
                    p =
                        new Intent(
                            MainActivity.this, com.geno.tutorial.articles.picker.NumberP.class);
                    startActivity(p);
                    break;
                }
                break;
            }
            return false;
          }
        });
  }