private void ShowRemoveButtons(boolean show) {
   if (show) {
     // Enable the Remove button and the End Remove Button
     for (int i = 0; i < favList.getChildCount(); i++) {
       favList.getChildAt(i).findViewById(R.id.UnfavoriteBtn).setVisibility(View.VISIBLE);
     }
   } else {
     // Disable the Remove button
     for (int i = 0; i < favList.getChildCount(); i++) {
       favList.getChildAt(i).findViewById(R.id.UnfavoriteBtn).setVisibility(View.INVISIBLE);
     }
   }
 }
Example #2
0
 @Override
 public void onScroll(
     AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
   int topRowVerticalPosition =
       (listView == null || listView.getChildCount() == 0) ? 0 : listView.getChildAt(0).getTop();
   swipeRefreshLayout.setEnabled(firstVisibleItem == 0 && topRowVerticalPosition >= 0);
 }
 private void unbindListItems() {
   final ListView listView = getListView();
   final int count = listView.getChildCount();
   for (int i = 0; i < count; i++) {
     mListAdapter.unbindView(listView.getChildAt(i));
   }
 }
  private void hideListItemsMenu(View v, boolean close) {
    boolean toBeHidden = false;
    for (int index = 0; index < list.getChildCount(); index++) {
      View view = list.getChildAt(index);
      if (view instanceof ViewSwitcher && ((ViewSwitcher) view).getDisplayedChild() == 1) {
        ((ViewSwitcher) view).showPrevious();
        toBeHidden = true;
        getPoiAdapter().setElementSelected(-1);
        postitionSelected = -1;
      }
    }
    if (!toBeHidden && v != null && v.getTag() != null && !close) {
      // no items needed to be flipped, fill and open details page
      FragmentTransaction fragmentTransaction =
          getSherlockActivity().getSupportFragmentManager().beginTransaction();
      PoiDetailsFragment fragment = new PoiDetailsFragment();

      Bundle args = new Bundle();
      args.putString(PoiDetailsFragment.ARG_POI_ID, ((PoiPlaceholder) v.getTag()).poi.getId());
      fragment.setArguments(args);

      fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
      // fragmentTransaction.detach(this);
      fragmentTransaction.replace(R.id.fragment_container, fragment, "pois");
      fragmentTransaction.addToBackStack(fragment.getTag());
      fragmentTransaction.commit();
    }
  }
Example #5
0
 /** 截图listview * */
 public static Bitmap getbBitmap(ListView listView) {
   int h = 0;
   Bitmap bitmap = null;
   // 获取listView实际高度
   for (int i = 0; i < listView.getChildCount(); i++) {
     h += listView.getChildAt(i).getHeight();
   }
   Log.d(TAG, "实际高度:" + h);
   Log.d(TAG, "list 高度:" + listView.getHeight());
   // 创建对应大小的bitmap
   bitmap = Bitmap.createBitmap(listView.getWidth(), h, Bitmap.Config.ARGB_8888);
   final Canvas canvas = new Canvas(bitmap);
   listView.draw(canvas);
   // 测试输出
   FileOutputStream out = null;
   try {
     out = new FileOutputStream("/sdcard/screen_test.png");
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
   try {
     if (null != out) {
       bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
       out.flush();
       out.close();
     }
   } catch (IOException e) {
     // TODO: handle exception
   }
   return bitmap;
 }
Example #6
0
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    int count = lv.getChildCount();
    for (int i = 0; i < count; i++) {
      LinearLayout linearLayout = (LinearLayout) lv.getChildAt(i);
      LinearLayout linearLayoutChild = (LinearLayout) linearLayout.getChildAt(0);
      EditText editText = (EditText) linearLayoutChild.getChildAt(1);
      if (editText.isShown()) {
        String value = editText.getText().toString();
        EnterCompanyListAdapter.ViewHolder viewHolder = (ViewHolder) linearLayout.getTag();
        viewHolder.fieldAndAnswer.set(1, value);
      }
    }

    @SuppressWarnings("unused")
    int count2 = epla.getCount();
    for (int i = 0; i < epla.getCount(); i++) {
      @SuppressWarnings("unchecked")
      ArrayList<String> fieldAndAnswer = (ArrayList<String>) epla.getItem(i);
      String fieldName = fieldAndAnswer.get(0);
      String value = fieldAndAnswer.get(1);
      company.set(fieldName, value);
    }

    outState.putSerializable("company", company);
    outState.putSerializable("person", person);
    outState.putBoolean("personLinked", personLinked);
  }
 @Override
 public PhotoViewer.PlaceProviderObject getPlaceForPhoto(
     MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
   if (fileLocation == null) {
     return null;
   }
   TLRPC.User user = MessagesController.getInstance().users.get(user_id);
   if (user != null && user.photo != null && user.photo.photo_big != null) {
     TLRPC.FileLocation photoBig = user.photo.photo_big;
     if (photoBig.local_id == fileLocation.local_id
         && photoBig.volume_id == fileLocation.volume_id
         && photoBig.dc_id == fileLocation.dc_id) {
       int count = listView.getChildCount();
       for (int a = 0; a < count; a++) {
         View view = listView.getChildAt(a);
         BackupImageView avatarImage =
             (BackupImageView) view.findViewById(R.id.settings_avatar_image);
         if (avatarImage != null) {
           int coords[] = new int[2];
           avatarImage.getLocationInWindow(coords);
           PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
           object.viewX = coords[0];
           object.viewY = coords[1] - Utilities.statusBarHeight;
           object.parentView = listView;
           object.imageReceiver = avatarImage.imageReceiver;
           object.user_id = user_id;
           object.thumb = object.imageReceiver.getBitmap();
           object.size = -1;
           return object;
         }
       }
     }
   }
   return null;
 }
Example #8
0
  public void animateListClearing() {
    final ListView listView = getListView();
    final int visibleChildCount = listView.getChildCount();

    Animation lastAnimation = null;

    for (int index = 0; index < visibleChildCount; index++) {
      final View view = listView.getChildAt(index);
      final Animation animation = createAnimation(index);

      view.startAnimation(animation);

      lastAnimation = animation;
    }

    if (lastAnimation != null) {
      lastAnimation.setAnimationListener(
          AnimationUtil.newOnAnimationEndListener(
              new Runnable() {
                @Override
                public void run() {
                  listAdapter.clear();
                  onListBecameEmpty();
                }
              }));
    }
  }
        @Override
        public void onPanelSlide(View panel, float slideOffset) {
          // For every 1 percent that the panel is slid upwards, clip 1 percent off the top
          // edge of the shortcut card, to achieve the animated effect of the shortcut card
          // being pushed out of view when the panel is slid upwards. slideOffset is 1 when
          // the shortcut card is fully exposed, and 0 when completely hidden.
          float ratioCardHidden = (1 - slideOffset);
          if (mShortcutCardsListView.getChildCount() > 0) {
            final SwipeableShortcutCard v =
                (SwipeableShortcutCard) mShortcutCardsListView.getChildAt(0);
            v.clipCard(ratioCardHidden);
          }

          if (mActionBar != null) {
            // Amount of available space that is not being hidden by the bottom pane
            final int topPaneHeight = (int) (slideOffset * mShortcutCardsListView.getHeight());

            final int availableActionBarHeight = Math.min(mActionBar.getHeight(), topPaneHeight);
            ((HostInterface) getActivity())
                .setActionBarHideOffset(mActionBar.getHeight() - availableActionBarHeight);

            if (!mActionBar.isShowing()) {
              mActionBar.show();
            }
          }
        }
Example #10
0
  public void onClickNewCategory(View v) {
    // Toast.makeText(this, "onClickCategoryItem",  Toast.LENGTH_SHORT).show();

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    // アラートダイアログのタイトルを設定します
    alertDialogBuilder.setTitle("編集");

    // アラートダイアログのメッセージを設定します
    // alertDialogBuilder.setMessage(textview.getText().toString());

    edittext = new EditText(this);
    edittext.setText("(カテゴリー)");
    alertDialogBuilder.setView(edittext);
    Activity activity = (Activity) v.getContext();
    // LinearLayout linearLayout = (LinearLayout)v.getParent();
    ListView listview = (ListView) activity.findViewById(R.id.list_category);

    final ArrayAdapter<CategoryInfo> adapter = arrayAdapter;
    final int listsize = listview.getChildCount();
    // アラートダイアログの肯定ボタンがクリックされた時に呼び出されるコールバックリスナーを登録します
    alertDialogBuilder.setPositiveButton(
        "追加",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {

            TaskTimeDatabaseHelper dbHelper = new TaskTimeDatabaseHelper(getBaseContext());
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            CategoryEditDao dao = new CategoryEditDao(db);

            CategoryInfo categoryInfo = new CategoryInfo();
            // categoryInfo.setId(listsize+1);
            categoryInfo.setCategory(edittext.getText().toString());

            long result = dao.insert(categoryInfo);
            db.close();

            adapter.add(categoryInfo);
            adapter.notifyDataSetChanged();
            // finish();
            // startActivity(getIntent());
          }
        });

    // アラートダイアログの否定ボタンがクリックされた時に呼び出されるコールバックリスナーを登録します
    alertDialogBuilder.setNegativeButton(
        "戻る",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {}
        });
    // アラートダイアログのキャンセルが可能かどうかを設定します
    alertDialogBuilder.setCancelable(true);
    AlertDialog alertDialog = alertDialogBuilder.create();
    // アラートダイアログを表示します
    alertDialog.show();
  }
 private void showFooterViewText(String footerText) {
   for (int i = contentList.getChildCount() - 1; i > 0; i--) {
     View v = contentList.getChildAt(i);
     if (Button.class.isInstance(v)) {
       Button bt = (Button) v;
       bt.setText(footerText);
       break;
     }
   }
 }
Example #12
0
 private boolean isBottom() {
   if (mListView.getCount() > 0) {
     if (mListView.getLastVisiblePosition() == mListView.getAdapter().getCount() - 1
         && mListView.getChildAt(mListView.getChildCount() - 1).getBottom()
             <= mListView.getHeight()) {
       return true;
     }
   }
   return false;
 }
  public View getViewByPosition(int pos, ListView listView) {
    final int firstListItemPosition = listView.getFirstVisiblePosition();
    final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

    if (pos < firstListItemPosition || pos > lastListItemPosition) {
      return listView.getAdapter().getView(pos, null, listView);
    } else {
      final int childIndex = pos - firstListItemPosition;
      return listView.getChildAt(childIndex);
    }
  }
  public void showRemoveView(boolean show) {
    mRemoveViewContent.setVisibility(show ? View.VISIBLE : View.GONE);
    mRemoveView.setAlpha(show ? 0 : 1);
    mRemoveView.animate().alpha(show ? 1 : 0).start();

    if (mShortcutCardsListView.getChildCount() > 0) {
      View v = mShortcutCardsListView.getChildAt(0);
      v.animate()
          .withLayer()
          .alpha(show ? REMOVE_VIEW_SHOWN_ALPHA : REMOVE_VIEW_HIDDEN_ALPHA)
          .start();
    }
  }
        @Override
        public boolean getIsListViewToBottom() {
          if ((singleChatLv.getChildAt(-1 + singleChatLv.getChildCount()).getBottom()
                  > singleChatLv.getHeight())
              || (singleChatLv.getLastVisiblePosition()
                  != -1 + singleChatLv.getAdapter().getCount())) {

            return false;
          } else {

            return true;
          }
        }
	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		float oldLastY = mInterceptY;
		mInterceptY = ev.getY();
		
		switch (ev.getAction()) {
		case MotionEvent.ACTION_DOWN:
			if (mList.getFirstVisiblePosition() == 0 && getScrollY() <= mHeaderContainer.getBottom()
					&& (mList.getChildCount() == 0 || mList.getChildAt(0).getTop() == 0)) {
				// We are already scrolled into the header.
				return super.onInterceptTouchEvent(ev);
			} else {
				// Check in MOVE for what we want to do.
				return false;
			}
			
		case MotionEvent.ACTION_MOVE:
			if (mList.getFirstVisiblePosition() == 0 && getScrollY() >= mHeaderContainer.getBottom()
					&& (mList.getChildCount() == 0 || mList.getChildAt(0).getTop() == 0)) {
				if (mInterceptY > oldLastY) {
					mScrollingList = false;
					return super.onInterceptTouchEvent(ev);
				} else {
					mScrollingList = true;
					return false;
				}
			} else if (mScrollingList) {
				return false;
			} else {
				return super.onInterceptTouchEvent(ev);
			}
		
		case MotionEvent.ACTION_UP:
			return !mScrollingList;
			
		default:
			return super.onInterceptTouchEvent(ev);
		}
	}
Example #17
0
  private void updateFavicons() {
    ListView listView = getListView();
    for (int i = 0; i < listView.getChildCount(); i++) {
      final View view = listView.getChildAt(i);
      final Object tag = view.getTag();

      if (tag == null || !(tag instanceof AwesomeEntryViewHolder)) continue;

      final AwesomeEntryViewHolder viewHolder = (AwesomeEntryViewHolder) tag;
      displayFavicon(viewHolder);
    }

    mView.invalidate();
  }
Example #18
0
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    selectedItemName = (String) getListAdapter().getItem(position);
    int childCount = l.getChildCount();
    for (int i = 0; i < childCount; i++) {
      View childAt = l.getChildAt(i);
      if (childAt instanceof TextView) {
        TextView textView = (TextView) childAt;
        textView.setTypeface(null, Typeface.NORMAL);
      }
    }
    if (v instanceof TextView) {
      TextView textView = (TextView) v;
      textView.setTypeface(null, Typeface.BOLD_ITALIC);
      // textView.setTextColor(v.getResources().getColor(R.color.formcolorselected));
    }

    JSONObject sectionObject = activity.getSectionObject();
    FragmentDetail oldFragment =
        (FragmentDetail) getFragmentManager().findFragmentById(R.id.detailFragment);
    if (oldFragment != null) { // && oldFragment.isInLayout()) {
      try {
        oldFragment.storeFormItems(false);
      } catch (Exception e) {
        e.printStackTrace();
        Utilities.messageDialog(activity, R.string.error_while_storing_form_data, null);
      }
      // FragmentActivity activity2 = oldFragment.getActivity();
      // int id2 = oldFragment.getId();

      FragmentDetail newFragment = new FragmentDetail();
      newFragment.setForm(selectedItemName, sectionObject);
      FragmentTransaction transaction = getFragmentManager().beginTransaction();
      transaction.remove(oldFragment);
      transaction.add(R.id.detailFragment, newFragment);
      // transaction.replace(R.id.detailFragment, newFragment);
      // transaction.addToBackStack(null); // Ads FirstFragment to the back-stack
      transaction.commit();
    } else {
      // String sectionName = activity.getSectionName();
      Intent intent =
          new Intent(getActivity().getApplicationContext(), FragmentDetailActivity.class);
      intent.putExtra(FormUtilities.ATTR_FORMNAME, selectedItemName);
      intent.putExtra(FormUtilities.ATTR_SECTIONOBJECTSTR, sectionObject.toString());
      intent.putExtra(LibraryConstants.LONGITUDE, activity.getLongitude());
      intent.putExtra(LibraryConstants.LATITUDE, activity.getLatitude());
      startActivityForResult(intent, RETURNCODE_DETAILACTIVITY);
    }
  }
  @Override
  public void onScroll(
      AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

    boolean enable = false;
    if (lvSN != null && lvSN.getChildCount() > 0) {
      // check if the first item of the list is visible
      boolean firstItemVisible = lvSN.getFirstVisiblePosition() == 0;
      // check if the top of the first item is visible
      boolean topOfFirstItemVisible = lvSN.getChildAt(0).getTop() == 0;
      // enabling or disabling the refresh layout
      enable = firstItemVisible && topOfFirstItemVisible;
    }
    refreshLayout.setEnabled(enable);
  }
  @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());
  }
  public void testNXTMotorActionBrick() {
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount());
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull(
        "TextView does not exist.", solo.getText(solo.getString(R.string.nxt_brick_motor_move)));
    assertNotNull(
        "TextView does not exist.", solo.getText(solo.getString(R.string.nxt_motor_speed_to)));

    UiTestUtils.testBrickWithFormulaEditor(
        solo,
        ProjectManager.getInstance().getCurrentSprite(),
        R.id.motor_action_speed_edit_text,
        SET_SPEED,
        Brick.BrickField.LEGO_NXT_SPEED,
        motorBrick);

    String[] motors = getActivity().getResources().getStringArray(R.array.nxt_motor_chooser);
    assertTrue("Spinner items list too short!", motors.length == 4);

    int legoSpinnerIndex = 0;

    Spinner currentSpinner = solo.getCurrentViews(Spinner.class).get(legoSpinnerIndex);
    solo.pressSpinnerItem(legoSpinnerIndex, 0);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[0], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(legoSpinnerIndex, 1);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[1], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(legoSpinnerIndex, 1);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[2], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(legoSpinnerIndex, 1);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[3], currentSpinner.getSelectedItem());
  }
 // originally:
 // http://stackoverflow.com/questions/5418510/disable-the-touch-events-for-all-the-views
 // modified for the needs here
 public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
   int childCount = viewGroup.getChildCount();
   for (int i = 0; i < childCount; i++) {
     View view = viewGroup.getChildAt(i);
     if (view.isFocusable()) view.setEnabled(enabled);
     if (view instanceof ViewGroup) {
       enableDisableViewGroup((ViewGroup) view, enabled);
     } else if (view instanceof ListView) {
       if (view.isFocusable()) view.setEnabled(enabled);
       ListView listView = (ListView) view;
       int listChildCount = listView.getChildCount();
       for (int j = 0; j < listChildCount; j++) {
         if (view.isFocusable()) listView.getChildAt(j).setEnabled(false);
       }
     }
   }
 }
Example #23
0
  public void testHideBrick() {
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount());
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull("TextView does not exist.", solo.getText(solo.getString(R.string.brick_hide)));
  }
Example #24
0
  public void commitCompany(View arg0) {

    // print out all of the properties of this Company
    Log.v("TeamLeader", "results \n" + company.toString());

    // go through and make sure we got all of the showing fields entered
    for (int i = 0; i < lv.getChildCount(); i++) {
      LinearLayout tempLL = (LinearLayout) lv.getChildAt(i);
      LinearLayout innerLL = (LinearLayout) tempLL.getChildAt(0);
      EditText tempEditText = (EditText) innerLL.getChildAt(1);
      EnterCompanyListAdapter.ViewHolder viewHolder = (ViewHolder) tempLL.getTag();
      ((ArrayList<String>) (viewHolder.fieldAndAnswer)).remove(1);
      viewHolder.fieldAndAnswer.add(tempEditText.getText().toString());
    }

    for (int i = 0; i < epla.getCount(); i++) {

      //			LinearLayout tempLL = (LinearLayout)lv.getChildAt(i);
      //			LinearLayout innerLL = (LinearLayout)tempLL.getChildAt(0);
      //			EditText tempEditText = (EditText)innerLL.getChildAt(1);

      @SuppressWarnings("unchecked")
      ArrayList<String> fieldAndAnswer = (ArrayList<String>) epla.getItem(i);
      String fieldName = fieldAndAnswer.get(0);
      String answer = fieldAndAnswer.get(1);
      company.set(fieldName, answer);
    }

    progressDialog = new ProgressDialog(this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage("Communicating with server");
    progressDialog.setCancelable(true);

    // send the instruction to add the Company with the TeamLeader API

    RESTfulAPI restAPI = new RESTfulAPI(this, null, progressDialog);
    try {
      personLinked = false;
      restAPI.addCompany(company);
      if (!personLinked && person != null) finish();
    } catch (IncompleteCompanyException e) {
      Toast.makeText(this, "Incomplete Company: required - name ", Toast.LENGTH_LONG).show();
    }
  }
  public void testChangeYByNBrick() {
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount());
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull(
        "TextView does not exist.", solo.getText(solo.getString(R.string.brick_change_y_by)));

    UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, Y_TO_CHANGE, "yMovement", changeYByNBrick);
  }
  @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 #27
0
  @Smoke
  public void testIfBrick() {
    ListView view = UiTestUtils.getScriptListView(solo);
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) view.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();

    UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, 5, "ifCondition", ifBrick);

    assertEquals(
        "Incorrect number of bricks.",
        6,
        dragDropListView.getChildCount()); // don't forget the footer
    assertEquals("Incorrect number of bricks.", 0, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 4, projectBrickList.size());

    assertTrue("Wrong Brick instance.", projectBrickList.get(0) instanceof IfLogicBeginBrick);
    assertNotNull(
        "TextView does not exist", solo.getText(getActivity().getString(R.string.brick_if_begin)));
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
      if (getItemViewType(position) == 0) {
        viewHolder = new ViewHolder();
        convertView = mLayoutInflater.inflate(R.layout.chat_item_in, null);
        viewHolder.mIcon = (ImageView) convertView.findViewById(R.id.icon_in);
        viewHolder.mMessage = (TextView) convertView.findViewById(R.id.chat_message_in);
      } else {
        viewHolder = new ViewHolder();
        convertView = mLayoutInflater.inflate(R.layout.chat_item_out, null);
        viewHolder.mIcon = (ImageView) convertView.findViewById(R.id.icon_out);
        viewHolder.mMessage = (TextView) convertView.findViewById(R.id.chat_message_out);
      }
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }

    int count = mListView.getChildCount();
    for (int i = 0; i < count; i++) {
      View childView = mListView.getChildAt(i);
      childView.clearAnimation();
    }
    if (mIsScrollDown) {
      convertView.startAnimation(mAnimation);
      Log.i("sh", "onScrollDown &&&&&&&&&&&&&&&&&&&&&&&");
    } else {
      Log.i("sh", "onScrollUp");
    }

    viewHolder.mIcon.setImageBitmap(mData.get(position).getmIcon());
    viewHolder.mMessage.setText(mData.get(position).getmMessage());

    return convertView;
  }
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
      mViewWidth = mListView.getWidth();
    }

    switch (motionEvent.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (mPaused) {
            return false;
          }

          if (mSwiping) {
            return true;
          }

          // TODO: ensure this is a finger, and set a flag

          // Find the child view that was touched (perform a hit test)
          Rect rect = new Rect();
          int childCount = mListView.getChildCount();
          int headerCount = mListView.getHeaderViewsCount();
          int footerCount = mListView.getFooterViewsCount();
          int[] listViewCoords = new int[2];
          mListView.getLocationOnScreen(listViewCoords);
          int x = (int) motionEvent.getRawX() - listViewCoords[0];
          int y = (int) motionEvent.getRawY() - listViewCoords[1];
          View child = null;
          for (int i = headerCount; i < (childCount - footerCount); i++) {
            child = mListView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
              mDownView = child;
              break;
            }
          }

          if (mDownView != null) {

            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mListView.getPositionForView(mDownView);
            if (mDownPosition != ListView.INVALID_POSITION
                && mDownPosition < mListView.getAdapter().getCount()) {
              if (mListView.getAdapter().getItem(mDownPosition) instanceof Card) {
                if (mCallbacks.canDismiss(
                    mDownPosition, (Card) mListView.getAdapter().getItem(mDownPosition))) {
                  mVelocityTracker = VelocityTracker.obtain();
                  mVelocityTracker.addMovement(motionEvent);
                } else {
                  mDownView = null;
                }
              } else {
                mDownView = null;
              }
            } else {
              mDownView = null;
            }
          }
          view.onTouchEvent(motionEvent);
          return true;
          // return false;
        }

      case MotionEvent.ACTION_UP:
        {
          if (mVelocityTracker == null) {
            break;
          }

          float deltaX = motionEvent.getRawX() - mDownX;
          mVelocityTracker.addMovement(motionEvent);
          mVelocityTracker.computeCurrentVelocity(1000);
          float velocityX = mVelocityTracker.getXVelocity();
          float absVelocityX = Math.abs(velocityX);
          float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
          boolean dismiss = false;
          boolean dismissRight = false;
          if (Math.abs(deltaX) > mViewWidth / swipeDistanceDivisor && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
          } else if (mMinFlingVelocity <= absVelocityX
              && absVelocityX <= mMaxFlingVelocity
              && absVelocityY < absVelocityX
              && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
          }
          if (dismiss && mDownPosition != ListView.INVALID_POSITION) {
            // dismiss
            dismiss(mDownView, mDownPosition - mListView.getHeaderViewsCount(), dismissRight);

          } else {
            // cancel
            mDownView
                .animate()
                .translationX(0)
                .alpha(1)
                .setDuration(mAnimationTime)
                .setListener(null);
          }

          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          if (mSwiping) {
            // To prevent onClick event with a fast swipe
            mSwiping = false;
            return true;
          }
          mSwiping = false;
          break;
        }

      case MotionEvent.ACTION_CANCEL:
        {
          if (mVelocityTracker == null) {
            break;
          }

          if (mDownView != null) {
            // cancel
            mDownView
                .animate()
                .translationX(0)
                .alpha(1)
                .setDuration(mAnimationTime)
                .setListener(null);
          }
          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          mSwiping = false;
          break;
        }

      case MotionEvent.ACTION_MOVE:
        {
          if (mVelocityTracker == null || mPaused) {
            break;
          }

          mVelocityTracker.addMovement(motionEvent);
          float deltaX = motionEvent.getRawX() - mDownX;
          float deltaY = motionEvent.getRawY() - mDownY;
          boolean movementAllowed = isSwipeMovementAllowed(deltaX);
          if (Math.abs(deltaX) > mSlop
              && Math.abs(deltaY) < Math.abs(deltaX) / 2
              && movementAllowed) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
            mListView.requestDisallowInterceptTouchEvent(true);

            // Cancel ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(
                MotionEvent.ACTION_CANCEL
                    | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
            mListView.onTouchEvent(cancelEvent);
            view.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
          }

          if (mSwiping) {
            mDownView.setTranslationX(deltaX - mSwipingSlop);
            mDownView.setAlpha(Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
          }
          break;
        }
    }
    return false;
  }
Example #30
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.chat_fragment_layout, container, false);
    backlogList = (ListView) root.findViewById(R.id.chat_backlog_list_view);
    inputField = (EditText) root.findViewById(R.id.chat_input_view);
    topicView = (TextView) root.findViewById(R.id.chat_topic_view);
    topicViewFull = (TextView) root.findViewById(R.id.chat_topic_view_full);
    OnClickListener topicListener =
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (topicView.isShown()) {
              topicView.setVisibility(View.GONE);
              topicViewFull.setVisibility(View.VISIBLE);
            } else {
              topicViewFull.setVisibility(View.GONE);
              topicView.setVisibility(View.VISIBLE);
            }
          }
        };
    topicView.setOnClickListener(topicListener);
    topicViewFull.setOnClickListener(topicListener);
    autoCompleteButton = (ImageButton) root.findViewById(R.id.chat_auto_complete_button);

    backlogList.setAdapter(adapter);
    backlogList.setOnScrollListener(new BacklogScrollListener(5));
    backlogList.setSelection(backlogList.getChildCount());

    autoCompleteButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            nickCompletionHelper.completeNick(inputField);
          }
        });

    inputField.setOnEditorActionListener(
        new OnEditorActionListener() {

          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND
                || (event != null
                    && event.getAction() == KeyEvent.ACTION_DOWN
                    && ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
                        || (event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_ENTER)))) {
              String inputText = inputField.getText().toString();

              if (!"".equals(inputText)) {
                BusProvider.getInstance()
                    .post(new SendMessageEvent(adapter.buffer.getInfo().id, inputText));
                InputHistoryHelper.addHistoryEntry(inputText);
                inputField.setText("");
                InputHistoryHelper.tempStoreCurrentEntry("");
              }

              return true;
            }
            return false;
          }
        });

    inputField.setOnKeyListener(
        new View.OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_TAB && event.getAction() == KeyEvent.ACTION_DOWN) {
              onNickComplete();
              return true;
            }
            if (keyCode == KeyEvent.KEYCODE_DPAD_UP && event.getAction() == KeyEvent.ACTION_DOWN) {
              EditText text = (EditText) v;
              InputHistoryHelper.tempStoreCurrentEntry(text.getText().toString());
              text.setText(InputHistoryHelper.getNextHistoryEntry());
              text.setSelection(text.getText().length());
              return true;
            }
            if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN
                && event.getAction() == KeyEvent.ACTION_DOWN) {
              EditText text = (EditText) v;
              if (InputHistoryHelper.isViewingHistory()) {
                // Currently viewing history, so progress back down towards "entry zero"
                text.setText(InputHistoryHelper.getPreviousHistoryEntry());
              } else if (!text.getText().toString().equals("")) {
                // Not viewing history, so push the current input text into the history and clear
                // the input
                InputHistoryHelper.addHistoryEntry(text.getText().toString());
                text.setText("");
              }
              text.setSelection(text.getText().length());
              return true;
            }
            return false;
          }
        });

    return root;
  }