@LargeTest
 public void testClickingHeaderWhenOtherItemHasFocusGivesHeaderFocus() {
   sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
   assertEquals("selected position", 1, mListView.getSelectedItemPosition());
   TouchUtils.clickView(this, mListView.getChildAt(0));
   assertTrue("header does not have focus", mListView.getChildAt(0).isFocused());
   assertEquals(
       "something is selected", AbsListView.INVALID_POSITION, mListView.getSelectedItemPosition());
 }
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();

    int position = mList.getSelectedItemPosition();
    if ((position >= 0) && (position != (mList.getCount() - 1))) {
      // Selected one slide.
      if (position > 0) {
        menu.add(0, MENU_MOVE_UP, 0, R.string.move_up).setIcon(R.drawable.ic_menu_move_up);
      }

      if (position < (mSlideListAdapter.getCount() - 1)) {
        menu.add(0, MENU_MOVE_DOWN, 0, R.string.move_down).setIcon(R.drawable.ic_menu_move_down);
      }
      if (mSlideshowModel.size() < SlideshowEditor.MAX_SLIDE_NUM) {
        menu.add(0, MENU_ADD_SLIDE, 0, R.string.add_slide).setIcon(R.drawable.ic_menu_add_slide);
      }

      menu.add(0, MENU_REMOVE_SLIDE, 0, R.string.remove_slide)
          .setIcon(android.R.drawable.ic_menu_delete);
    } else {
      if (mSlideshowModel.size() < SlideshowEditor.MAX_SLIDE_NUM) {
        menu.add(0, MENU_ADD_SLIDE, 0, R.string.add_slide).setIcon(R.drawable.ic_menu_add_slide);
      }
    }

    menu.add(0, MENU_DISCARD_SLIDESHOW, 0, R.string.discard_slideshow)
        .setIcon(R.drawable.ic_menu_delete_played);

    return true;
  }
  @MediumTest
  public void testMovingToUnFocusableTakesFocusAway() {
    sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);

    assertFalse("focused item should have lost focus", mListView.getChildAt(0).isFocused());
    assertEquals("selected position", 1, mListView.getSelectedItemPosition());
  }
 @FlakyTest(tolerance = 2)
 @LargeTest
 public void testClickingHeaderKeepsFocus() {
   TouchUtils.clickView(this, mListView.getChildAt(0));
   assertTrue("header does not have focus", mListView.getChildAt(0).isFocused());
   assertEquals(
       "something is selected", AbsListView.INVALID_POSITION, mListView.getSelectedItemPosition());
 }
 @MediumTest
 public void testPreconditions() {
   assertEquals(0, mListView.getSelectedItemPosition());
   assertEquals(
       "selected item should be 1.5 times taller than the others",
       mExpandedHeight,
       (int) (mNormalHeight * 1.5));
 }
  @MediumTest
  public void testMoveSelectionDownNotRequiringScroll() {

    sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);

    assertEquals(1, mListView.getSelectedItemPosition());
    assertEquals(
        "first item's top should not have shifted", mListTop, mListView.getChildAt(0).getTop());
  }
  /*
   * (non-Javadoc)
   * @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
   */
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    mState = new Bundle();
    if (mList.getSelectedItemPosition() >= 0) {
      mState.putInt(SLIDE_INDEX, mList.getSelectedItemPosition());
    }

    if (mUri != null) {
      mState.putString(MESSAGE_URI, mUri.toString());
    }

    if (LOCAL_LOGV) {
      Log.v(TAG, "Saving state: " + mState);
    }
    outState.putBundle(STATE, mState);
  }
Example #8
0
 @Override
 public boolean onTrackballEvent(MotionEvent event) {
   int selectedId = myList.getSelectedItemPosition();
   if (selectedId == -1) {
     selectedId = 0;
   }
   if (lastPosition != selectedId) {
     lastPosition = selectedId;
     vibe.vibrate(VIBE_PATTERN, -1);
     String filename = directoryEntries.get(selectedId);
   }
   return super.onTrackballEvent(event);
 }
  @MediumTest
  public void testMoveSelectionUpNotRequiringScroll() {
    sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);

    assertEquals(1, mListView.getSelectedItemPosition());
    final int oldBottom = mListView.getSelectedView().getBottom();

    sendKeys(KeyEvent.KEYCODE_DPAD_UP);

    assertEquals(
        "bottom of 2nd itme should have stayed the same when " + "moving back up",
        oldBottom,
        mListView.getChildAt(1).getBottom());
  }
  @MediumTest
  public void testMoveSelectionDownRequiringScroll() {
    int lastItemIndex = mListView.getChildCount() - 1;

    for (int i = 0; i < lastItemIndex; i++) {
      sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
    }
    getInstrumentation().waitForIdleSync();

    assertEquals("list position", lastItemIndex, mListView.getSelectedItemPosition());
    assertEquals("expanded height", mExpandedHeight, mListView.getSelectedView().getHeight());
    assertEquals(
        "should be above bottom fading edge",
        mListBottom - mListView.getVerticalFadingEdgeLength(),
        mListView.getSelectedView().getBottom());
  }
  @LargeTest
  public void testMoveSelectionUpRequiringScroll() {
    int childrenPerScreen = mListView.getChildCount();

    // go down past last child on screen
    for (int i = 0; i < childrenPerScreen; i++) {
      sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
    }

    // go back up to second to last
    for (int i = 0; i < childrenPerScreen - 1; i++) {
      sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    }
    getInstrumentation().waitForIdleSync();

    assertEquals("list position", 1, mListView.getSelectedItemPosition());
    assertEquals("expanded height", mExpandedHeight, mListView.getSelectedView().getHeight());
    assertEquals(
        "should be below top fading edge",
        mListTop + mListView.getVerticalFadingEdgeLength(),
        mListView.getSelectedView().getTop());
  }
Example #12
0
  private void initMsgContents() {
    msgContentList.clear();
    WeChatDB weChatDB = WeChatDB.getInstance(MainActivity.this);
    List<MsgContent> list = weChatDB.loadMsg(userName);
    for (MsgContent msgContent : list) {
      msgContentList.add(msgContent);
    }
    adapter.notifyDataSetChanged();
    msgListView.setSelection(msgContentList.size() - 1);
    LogUtil.d("Size", msgContentList.size() + "");
    LogUtil.d("Current Selected", msgListView.getSelectedItemPosition() + "");

    //        MsgContent msgContent1 = new MsgContent(MsgContent.Type.TYPE_RECEIVED, new Date(),
    // "Hello");
    //        msgContentList.add(msgContent1);
    //        MsgContent msgContent2 = new MsgContent(MsgContent.Type.TYPE_RECEIVED, new Date(),
    // "Hello");
    //        msgContentList.add(msgContent2);
    //        MsgContent msgContent3 = new MsgContent(MsgContent.Type.TYPE_SENT, new Date(),
    // "Hello");
    //        msgContentList.add(msgContent3);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int position = mList.getSelectedItemPosition();

    switch (item.getItemId()) {
      case MENU_MOVE_UP:
        if ((position > 0) && (position < mSlideshowModel.size())) {
          mSlideshowEditor.moveSlideUp(position);
          mSlideListAdapter.notifyDataSetChanged();
          mList.setSelection(position - 1);
        }
        break;
      case MENU_MOVE_DOWN:
        if ((position >= 0) && (position < mSlideshowModel.size() - 1)) {
          mSlideshowEditor.moveSlideDown(position);
          mSlideListAdapter.notifyDataSetChanged();
          mList.setSelection(position + 1);
        }
        break;
      case MENU_REMOVE_SLIDE:
        if ((position >= 0) && (position < mSlideshowModel.size())) {
          mSlideshowEditor.removeSlide(position);
          mSlideListAdapter.notifyDataSetChanged();
        }
        break;
      case MENU_ADD_SLIDE:
        addNewSlide();
        break;
      case MENU_DISCARD_SLIDESHOW:
        // delete all slides from slideshow.
        mSlideshowEditor.removeAllSlides();
        mSlideListAdapter.notifyDataSetChanged();
        finish();
        break;
    }

    return true;
  }
 /** Get the position of the currently selected list item. */
 public int getSelectedItemPosition() {
   ensureList();
   return mList.getSelectedItemPosition();
 }
  private void updateModelList(String brandName) {
    Brand brandEnum = Brand.getEnum(brandName);

    switch (brandEnum) {
      case BAT:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_bat_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case BRENNENSTUHL:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_brennenstuhl_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case ELRO:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_elro_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case HAMA:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_hama_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case INTERTECHNO:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_intertechno_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case INTERTEK:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_intertek_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case MUMBI:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_mumbi_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case POLLIN_ELECTRONIC:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_pollin_electronic_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case REV:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_rev_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case ROHRMOTOR24:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_rohrmotor24_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case UNIVERSAL:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_universal_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      case VIVANCO:
        {
          modelNamesAdapter.clear();
          String[] array = getResources().getStringArray(R.array.model_vivanco_array);
          modelNamesAdapter.addAll(array);

          setModelVisibility(View.VISIBLE);
          break;
        }
      default:
        setModelVisibility(View.GONE);
        break;
    }

    if (modelNamesAdapter.getCount() > modelListView.getSelectedItemPosition()) {
      modelListView.setItemChecked(0, true);
      modelListView.smoothScrollToPosition(0);
    }

    modelNamesAdapter.notifyDataSetChanged();
  }
 /** Get the position of the currently selected list item. */
 public int getSelectedItemPosition() {
   return mList.getSelectedItemPosition();
 }
 public void testKeyEvents() {
   sendKeys("4*DPAD_DOWN");
   assertEquals(list.getSelectedItemPosition(), 4);
 }
 @MediumTest
 public void testPreconditions() {
   assertEquals("selected position", 0, mListView.getSelectedItemPosition());
   assertTrue(mListView.getChildAt(0).isFocused());
   assertFalse(mListView.getChildAt(1).isFocusable());
 }