Пример #1
0
  @Test
  public void testOptionScanningEnabled_highlightsMenuButton() {
    mSharedPreferences
        .edit()
        .putString(
            mContext.getString(R.string.pref_scanning_methods_key),
            mContext.getString(R.string.option_scanning_key))
        .commit();
    mOptionManager.onSharedPreferenceChanged(mSharedPreferences, null);
    when(mOverlayController.getMenuButtonLocation()).thenReturn(MENU_BUTTON_BOUNDS);

    /* add a context menu with two items to the tree */
    CharSequence globalActionLabel0 = "global action label 0";
    CharSequence globalActionLabel1 = "global action label 1";
    GlobalActionNode globalNode0 = new GlobalActionNode(0, null, globalActionLabel0);
    GlobalActionNode globalNode1 = new GlobalActionNode(1, null, globalActionLabel1);
    ContextMenuNode contextMenu = new ContextMenuNode(globalNode0, globalNode1);
    mSelectionNode = new OptionScanSelectionNode(mSelectionNode, contextMenu);

    mOptionManager.clearFocusIfNewTree(mSelectionNode);
    mOptionManager.selectOption(0);
    verify(mOverlayController, times(1)).drawMenuButton();

    ShadowHandler.runMainLooperToEndOfTasks();

    verify(mOverlayController, times(2))
        .highlightPerimeterOfRects(mHighlightCaptor.capture(), mPaintCaptor.capture());

    List<Collection<Rect>> capturedHighlights = mHighlightCaptor.getAllValues();
    assertTrue(capturedHighlights.get(0).contains(NODE_BOUNDS_1));
    assertTrue(capturedHighlights.get(0).contains(NODE_BOUNDS_2));
    assertTrue(capturedHighlights.get(1).contains(MENU_BUTTON_BOUNDS));
  }
Пример #2
0
 @Test
 public void testHighlightStylesForOptionScanning_defaultsAreDifferent() {
   mOptionManager.onSharedPreferenceChanged(mSharedPreferences, null);
   mOptionManager.clearFocusIfNewTree(mSelectionNode);
   mOptionManager.selectOption(0);
   verify(mOverlayController, times(2))
       .highlightPerimeterOfRects(mHighlightCaptor.capture(), mPaintCaptor.capture());
   /* The two paint colors should be different */
   List<Paint> capturedPaints = mPaintCaptor.getAllValues();
   assertFalse(capturedPaints.get(0).getColor() == capturedPaints.get(1).getColor());
 }
Пример #3
0
 @Test
 public void testSelectionNodeWithOptionScanning_shouldHighlightTwoOptions() {
   mSharedPreferences
       .edit()
       .putString(
           mContext.getString(R.string.pref_highlight_0_color_key),
           mContext.getString(R.string.material_orange_500))
       .putString(
           mContext.getString(R.string.pref_highlight_0_weight_key),
           mContext.getString(R.string.thickness_4_dp))
       .putString(
           mContext.getString(R.string.pref_highlight_1_color_key),
           mContext.getString(R.string.material_blue_500))
       .putString(
           mContext.getString(R.string.pref_highlight_1_weight_key),
           mContext.getString(R.string.thickness_4_dp))
       .putString(
           mContext.getString(R.string.pref_scanning_methods_key),
           mContext.getString(R.string.option_scanning_key))
       .commit();
   mOptionManager.onSharedPreferenceChanged(mSharedPreferences, null);
   mOptionManager.clearFocusIfNewTree(mSelectionNode);
   mOptionManager.selectOption(0);
   verify(mOverlayController, times(2))
       .highlightPerimeterOfRects(mHighlightCaptor.capture(), mPaintCaptor.capture());
   /* One paint should be blue; the other should be orange */
   List<Collection<Rect>> capturedHighlights = mHighlightCaptor.getAllValues();
   List<Paint> capturedPaints = mPaintCaptor.getAllValues();
   int orangeIndex = 0;
   int blueIndex = 1;
   if (capturedPaints.get(0).getColor() == BLUE_500_COLOR) {
     blueIndex = 0;
     orangeIndex = 1;
   }
   assertEquals(BLUE_500_COLOR, capturedPaints.get(blueIndex).getColor());
   assertEquals(ORANGE_500_COLOR, capturedPaints.get(orangeIndex).getColor());
   assertEquals(0xff, capturedPaints.get(orangeIndex).getAlpha());
   DisplayMetrics dm = mContext.getResources().getDisplayMetrics();
   float expectedStrokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, dm);
   assertEquals(expectedStrokeWidth, capturedPaints.get(orangeIndex).getStrokeWidth(), 0.01);
   assertTrue(capturedHighlights.get(orangeIndex).contains(NODE_BOUNDS_1));
   assertTrue(capturedHighlights.get(blueIndex).contains(NODE_BOUNDS_2));
 }