private void loadData() {
   peripheryAddressTextView.setText("Adres: ");
   peripheryAddressTextView.measure(0, 0);
   int addressLabelTextWidth = peripheryAddressTextView.getMeasuredWidth();
   peripheryNameTextView.setText("Nazwa: ");
   peripheryNameTextView.measure(0, 0);
   int peripheryNameLabelTextWidth = peripheryNameTextView.getMeasuredWidth();
   SharedPreferences sharedPref = getActivity().getSharedPreferences(DATA, Context.MODE_PRIVATE);
   String territorial_code = sharedPref.getString(TERRITORIAL_CODE, "Kod terytorialny: _ _ _ _");
   if (!territorial_code.equalsIgnoreCase("Kod terytorialny: _ _ _ _"))
     territorial_code = "Kod terytorialny: " + territorial_code;
   String periphery_number = sharedPref.getString(PERIPHERY_NUMBER, "Nr obwodu: _ _ _ _");
   if (!periphery_number.equalsIgnoreCase("Nr obwodu: _ _ _ _"))
     periphery_number = "Nr obwodu: " + periphery_number;
   String periphery_name =
       sharedPref.getString(PERIPHERY_NAME, "Nazwa: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _");
   if (!periphery_name.equalsIgnoreCase("Nazwa: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _"))
     periphery_name = "Nazwa: " + periphery_name;
   String periphery_address =
       sharedPref.getString(PERIPHERY_ADDRESS, "Adres: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _");
   if (!periphery_address.equalsIgnoreCase("Adres: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _"))
     periphery_address = "Adres: " + periphery_address;
   Spannable spannable = new SpannableString(territorial_code);
   spannable.setSpan(
       new ForegroundColorSpan(Color.GREEN),
       "Kod terytorialny: ".length(),
       territorial_code.length(),
       Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   territorialCodeTextView.setText(spannable);
   peripheryNumberTextView.setText(periphery_number);
   peripheryNameTextView.setText(
       createIndentedText(periphery_name, 0, peripheryNameLabelTextWidth));
   peripheryAddressTextView.setText(
       createIndentedText(periphery_address, 0, addressLabelTextWidth));
 }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int width = right - left;

    // Take into account left and right padding when laying out the below views.
    mHeaderTextView.layout(
        mHeaderTextIndent + mPaddingLeft,
        0,
        mHeaderTextView.getMeasuredWidth() + mHeaderTextIndent + mPaddingLeft,
        mHeaderBackgroundHeight);

    if (isViewMeasurable(mCountTextView)) {
      mCountTextView.layout(
          width - mPaddingRight - mCountTextView.getMeasuredWidth(),
          0,
          width - mPaddingRight,
          mHeaderBackgroundHeight);
    }

    mHeaderDivider.layout(
        mPaddingLeft,
        mHeaderBackgroundHeight,
        width - mPaddingRight,
        mHeaderBackgroundHeight + mHeaderUnderlineHeight);
  }
예제 #3
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    int nonTextWidth = mAvatarSize + mSpacing * 3 + mButtonSize;

    int ws =
        MeasureSpec.makeMeasureSpec(
            widthSize - nonTextWidth,
            widthMode == MeasureSpec.UNSPECIFIED ? widthMode : MeasureSpec.AT_MOST);
    int hs = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    mNameView.measure(ws, hs);
    mAddressView.measure(ws, hs);

    if (mButton != null)
      mButton.measure(MeasureSpec.makeMeasureSpec(mButtonSize, MeasureSpec.EXACTLY), hs);

    int width =
        widthMode == MeasureSpec.EXACTLY
            ? widthSize
            : Math.max(mNameView.getMeasuredWidth(), mAddressView.getMeasuredWidth())
                + nonTextWidth;
    int height =
        Math.max(
            mAvatarSize + mSpacing * 2,
            mNameView.getMeasuredHeight() + mAddressView.getMeasuredHeight());

    switch (heightMode) {
      case MeasureSpec.EXACTLY:
        height = heightSize;
        break;
      case MeasureSpec.AT_MOST:
        height = Math.min(height, heightSize);
        break;
    }

    height = Math.max(mMinHeight, height);

    if (mButton != null)
      mButton.measure(
          MeasureSpec.makeMeasureSpec(mButtonSize, MeasureSpec.EXACTLY),
          MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));

    setMeasuredDimension(width, height);
  }
예제 #4
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int right = r - l;
    int height = b - t;

    for (int i = 0; i < getChildCount(); i++) {
      // Put all the children outside of the view, then use setPosition
      // to put the ones that need to be seen back. This will be where
      // we set the top and bottom of every view though.
      TextView view = (TextView) getChildAt(i);
      int viewWidth = view.getMeasuredWidth();
      int viewHeight = view.getMeasuredHeight();
      int textTop =
          (height / 2) - (viewHeight - ((view.getLineHeight() * view.getLineCount()) / 2));
      view.layout(right, textTop, right + viewWidth, textTop + viewHeight);
    }
    setPosition(mDisplayedPage, 0, 0);

    mShadow.setBounds(0, 0, right, mShadowHeight);
    mBottomBar.setBounds(0, height - mBottomBarHeight, right, height);

    // Set up the fading edges
    mFadingEdgeLeft.setBounds(0, mShadowHeight, mFadingEdgeLength, height - mBottomBarHeight);
    mFadingEdgeRight.setBounds(
        right - mFadingEdgeLength, mShadowHeight, right, height - mBottomBarHeight);
  }
예제 #5
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthSize = widthMeasureSpec & ~(0x3 << 30);
    final int widthMode = widthMeasureSpec & (0x3 << 30);
    final int heightSize = heightMeasureSpec & ~(0x3 << 30);
    final int heightMode = heightMeasureSpec & (0x3 << 30);

    boolean horizontal = (POSITION_LEFT.equals(mPosition) || POSITION_RIGHT.equals(mPosition));

    if (widthMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.UNSPECIFIED) {
      throw new InflateException("MeasureSpec.UNSPECIFIED is not support.");
    }

    if (mImageHeight > 0
        && mImageWidth > 0
        && mImageHeight < heightSize - verticalPadding() - (horizontal ? 0 : mSpacing)
        && mImageWidth < widthSize - horizontalPadding() - (horizontal ? mSpacing : 0)) {
      // the image's size must not larger than the given size. and if the size is 0, we won't
      // measure it.
      measureChild(mImage, (int) (mImageWidth + widthMode), (int) (mImageHeight + heightMode));
    } else {
      mNeedLayout = false;
    }

    if (horizontal) {
      int textWidth = (int) (widthSize - horizontalPadding() - mSpacing - mImageWidth);
      measureChild(mText, textWidth + widthMode, heightSize + heightMode);
    } else {
      int textHeight = (int) (heightSize - verticalPadding() - mSpacing - mImageHeight);
      measureChild(mText, widthSize + widthMode, textHeight + heightMode);
    }

    int width = 0;
    int height = 0;

    if (widthMode == MeasureSpec.EXACTLY) {
      width = widthSize;
    } else if (widthMode == MeasureSpec.AT_MOST) {
      width =
          (int)
              (mImage.getMeasuredWidth()
                  + mText.getMeasuredWidth()
                  + horizontalPadding()
                  + (horizontal ? mSpacing : 0));
    }

    if (heightMode == MeasureSpec.EXACTLY) {
      height = heightSize;
    } else if (heightMode == MeasureSpec.AT_MOST) {
      height =
          (int)
              (mImage.getMeasuredHeight()
                  + mText.getMeasuredHeight()
                  + verticalPadding()
                  + (horizontal ? 0 : mSpacing));
    }

    setMeasuredDimension(width, height);
  }
예제 #6
0
  private int measureWidth(int widthMeasureSpec) {
    int specMode = MeasureSpec.getMode(widthMeasureSpec);
    int specSize = MeasureSpec.getSize(widthMeasureSpec);

    int result = 0;
    if (specMode == MeasureSpec.EXACTLY) {
      result = specSize;
    } else {
      result = Math.max(mEditText.getMeasuredWidth(), mLabel.getMeasuredWidth());
      result = Math.max(result, getSuggestedMinimumWidth());
      result += getPaddingLeft() + getPaddingRight();
      if (specMode == MeasureSpec.AT_MOST) {
        result = Math.min(result, specSize);
      }
    }

    return result;
  }
예제 #7
0
  private void drawTextCanvas(Canvas canvas, String text) {
    // TODO Auto-generated method stub

    // set color the background
    canvas.drawPaint(paint);

    // Setup textView like your normanlly would with your activity context
    TextView tv = new TextView(mContext);

    tv.setMaxWidth(300);

    // setup Text
    tv.setText(mText);

    // set Textcolor
    tv.setTextColor(Color.BLUE);

    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);

    // enable SetDrawing cache
    tv.setDrawingCacheEnabled(true);

    tv.measure(
        MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(canvas.getHeight(), MeasureSpec.EXACTLY));
    tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

    Bitmap bm =
        BitmapFactory.decodeResource(getResources(), R.drawable.khung_xanh)
            .copy(Bitmap.Config.ARGB_8888, true);
    bm =
        Bitmap.createScaledBitmap(
            bm,
            tv.getMeasuredWidth() + 40,
            (int) ((int) tv.getLineCount() * (tv.getLineHeight() + 8)),
            true);
    canvas.drawBitmap(bm, 0, 0, paint);

    // draw bitmap from drawingcache to the canvas
    canvas.drawBitmap(tv.getDrawingCache(), 20, 20, paint);

    // disable drawing cache
    tv.setDrawingCacheEnabled(false);
  }
예제 #8
0
  void updateTextPositions(int position, float positionOffset) {
    if (position != mLastKnownCurrentPage) {
      updateText(position, mPager.getAdapter());
    } else if (positionOffset == mLastKnownPositionOffset) {
      return;
    }

    mUpdatingPositions = true;

    final int prevWidth = mPrevText.getMeasuredWidth();
    final int currWidth = mCurrText.getMeasuredWidth();
    final int nextWidth = mNextText.getMeasuredWidth();
    final int halfCurrWidth = currWidth / 2;

    final int stripWidth = getWidth();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int textPaddedLeft = paddingLeft + halfCurrWidth;
    final int textPaddedRight = paddingRight + halfCurrWidth;
    final int contentWidth = stripWidth - textPaddedLeft - textPaddedRight;

    float currOffset = positionOffset + 0.5f;
    if (currOffset > 1.f) {
      currOffset -= 1.f;
    }
    final int currCenter = stripWidth - textPaddedRight - (int) (contentWidth * currOffset);
    final int currLeft = currCenter - currWidth / 2;
    final int currRight = currLeft + currWidth;

    mCurrText.layout(currLeft, paddingTop, currRight, paddingTop + mCurrText.getMeasuredHeight());

    final int prevLeft = Math.min(paddingLeft, currLeft - mScaledTextSpacing - prevWidth);
    mPrevText.layout(
        prevLeft, paddingTop, prevLeft + prevWidth, paddingTop + mPrevText.getMeasuredHeight());

    final int nextLeft =
        Math.max(stripWidth - paddingRight - nextWidth, currRight + mScaledTextSpacing);
    mNextText.layout(
        nextLeft, paddingTop, nextLeft + nextWidth, paddingTop + mNextText.getMeasuredHeight());

    mLastKnownPositionOffset = positionOffset;
    mUpdatingPositions = false;
  }
예제 #9
0
  @Override
  public void onPageScrollStateChanged(int state) {
    if (state == ViewPager.SCROLL_STATE_IDLE) {
      mScrolling = false;
      TextView tv = getTabView(mSelectedPosition);
      if (tv != null) updateIndicator(tv.getLeft(), tv.getMeasuredWidth());
    } else mScrolling = true;

    if (mListener != null) mListener.onPageScrollStateChanged(state);
  }
 private int setOverflowWidth() {
   for (int i = 0; i < mListView.getAdapter().getCount(); i++) {
     MenuItem menuItem = (MenuItem) mListView.getAdapter().getItem(i);
     Preconditions.checkNotNull(menuItem);
     mListViewItemWidthCalculator.setText(menuItem.getTitle());
     mListViewItemWidthCalculator.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
     mOverflowWidth = Math.max(mListViewItemWidthCalculator.getMeasuredWidth(), mOverflowWidth);
   }
   return mOverflowWidth;
 }
  /** Redraws default text with circle animation. */
  private void reDrawDefaultLayout() {
    int cx = mDefaultText.getMeasuredWidth() / 2;
    int cy = mDefaultText.getMeasuredHeight() / 2;

    int finalRadius = Math.max(mDefaultText.getWidth(), mDefaultText.getHeight()) / 2;

    Animator anim = ViewAnimationUtils.createCircularReveal(mDefaultText, cx, cy, 0, finalRadius);

    mDefaultText.setVisibility(View.VISIBLE);
    anim.start();
  }
예제 #12
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    measureChildren(widthMeasureSpec, heightMeasureSpec);

    int width = 0;
    int height = 0;

    int maxLabelWidth = 0;

    for (int i = 0; i < mButtonsCount; i++) {
      View child = getChildAt(i);

      switch (mExpandDirection) {
        case EXPAND_UP:
        case EXPAND_DOWN:
          width = Math.max(width, child.getMeasuredWidth());
          height += child.getMeasuredHeight();
          break;
        case EXPAND_LEFT:
        case EXPAND_RIGHT:
          width += child.getMeasuredWidth();
          height = Math.max(height, child.getMeasuredHeight());
          break;
      }

      if (!expandsHorizontally()) {
        TextView label = (TextView) child.getTag(R.id.fab_label);
        if (label != null) {
          maxLabelWidth = Math.max(maxLabelWidth, label.getMeasuredWidth());
        }
      }
    }

    if (!expandsHorizontally()) {
      width += maxLabelWidth + mLabelsMargin;
    }

    switch (mExpandDirection) {
      case EXPAND_UP:
      case EXPAND_DOWN:
        height += mButtonSpacing * (getChildCount() - 1);
        height = adjustForOvershoot(height);
        break;
      case EXPAND_LEFT:
      case EXPAND_RIGHT:
        width += mButtonSpacing * (getChildCount() - 1);
        width = adjustForOvershoot(width);
        break;
    }

    setMeasuredDimension(width, height);
  }
  public int captureBitmapCache(String in) {
    TextView tv = (TextView) MyApp.context.findViewById(R.id.ocrTextview);
    String tvText = tv.getText().toString();
    float tvTextSize = tv.getTextSize();
    int tvColor = tv.getCurrentTextColor();
    Bitmap bitmap = null;

    tv.setTextSize(36);
    tv.setTextColor(Color.CYAN);
    tv.setTypeface(Typeface.SANS_SERIF);

    tv.setText(in);

    while (bitmap == null) {
      // http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null
      tv.measure(
          MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
          MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
      tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

      tv.setDrawingCacheEnabled(true);
      tv.buildDrawingCache(true);
      bitmap = Bitmap.createBitmap(tv.getDrawingCache());
      tv.destroyDrawingCache();
      tv.setDrawingCacheEnabled(false);
    }

    FileOutputStream fos = null;
    int res = -1;
    try {
      fos = new FileOutputStream(currentDirectory() + "/files/" + MyApp.SCREENSHOT_FILENAME);
      if (fos != null) {
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
        fos.close();
        res = 0;
      }
    } catch (Throwable e) {
      Log.i(MyApp.TAG, e.getMessage().toString());
      res = -1;
    }

    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTextSize);
    tv.setTypeface(Typeface.MONOSPACE);
    tv.setText(tvText);
    tv.setTextColor(tvColor);
    return res;
  }
예제 #14
0
  @Override
  protected void onDraw(Canvas c, OpenStreetMapView osmv) {
    if (this.mLocation != null) {
      mT.setText(mDescr);
      mT.measure(0, 0);
      mT.layout(0, 0, mT.getMeasuredWidth(), mT.getMeasuredHeight());

      final OpenStreetMapViewProjection pj = osmv.getProjection();
      final Point screenCoords = new Point();
      pj.toPixels(this.mLocation, screenCoords);

      c.save();
      c.rotate(osmv.getBearing(), screenCoords.x, screenCoords.y);
      c.translate(screenCoords.x - 12, screenCoords.y - mT.getMeasuredHeight() + 2);
      mT.draw(c);
      c.restore();
    }
  }
예제 #15
0
파일: PVOFragment.java 프로젝트: jankit/pvo
  /**
   * Add TextView IN LinearLayout
   *
   * @param parentll
   * @param tv
   * @param mContext
   */
  private void addTextViewINLinearLayout(LinearLayout parentll, TextView tv, Context mContext) {

    int widthSoFar = 0;
    int maxWidth = 0;
    tv.measure(0, 0);
    tv.setTextSize(20);
    tv.setPadding(5, 5, 5, 5);
    tv.setTextColor(Color.BLACK);
    tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.selected_location_tv_border));

    LinearLayout currentLL;
    ll = parentll;

    if (parentll.getChildAt(parentll.getChildCount() - 1) != null) {
      parentll.getChildAt(parentll.getChildCount() - 1).measure(0, 0);
      widthSoFar =
          (parentll.getChildAt(parentll.getChildCount() - 1).getMeasuredWidth())
              + tv.getMeasuredWidth();
    }

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    maxWidth = display.getWidth() - 100;

    // Check if parent Liner Layout has child
    if (parentll.getChildCount() == 0 || widthSoFar >= maxWidth) {

      // Create a liner layout and add
      currentLL = new LinearLayout(mContext);

      currentLL.setLayoutParams(
          new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

      // currentLL.setGravity(Gravity.LEFT);
      currentLL.setOrientation(LinearLayout.HORIZONTAL); // vertical

      parentll.addView(currentLL);
    }

    currentLL = (LinearLayout) parentll.getChildAt(parentll.getChildCount() - 1);

    currentLL.addView(tv);
  }
예제 #16
0
  @Override
  protected void onLayout(
      final boolean changed, final int left, final int top, final int right, final int bottom) {
    final int cellWidth = getMeasuredWidth() / GRID_WIDTH;
    final int cellHeight = getMeasuredHeight() / GRID_HEIGHT;
    final int padding =
        getResources().getDimensionPixelOffset(R.dimen.multiple_attachment_preview_padding);
    final int count = mPreviewViews.size();
    for (int i = 0; i < count; i++) {
      final ViewWrapper viewWrapper = mPreviewViews.get(i);
      final View view = viewWrapper.view;
      final Tile imageTile = mCurrentLayout.tiles.get(i);
      final int tileLeft = imageTile.startX * cellWidth;
      final int tileTop = imageTile.startY * cellHeight;
      view.layout(
          tileLeft + padding,
          tileTop + padding,
          tileLeft + view.getMeasuredWidth(),
          tileTop + view.getMeasuredHeight());
      if (viewWrapper.needsSlideAnimation) {
        trySlideAttachmentView(viewWrapper);
        viewWrapper.needsSlideAnimation = false;
      } else {
        viewWrapper.prevLeft = view.getLeft();
        viewWrapper.prevTop = view.getTop();
        viewWrapper.prevWidth = view.getWidth();
        viewWrapper.prevHeight = view.getHeight();
      }

      if (i == count - 1 && mPlusTextView != null) {
        // The plus text view always covers the last attachment.
        mPlusTextView.layout(
            tileLeft + padding,
            tileTop + padding,
            tileLeft + mPlusTextView.getMeasuredWidth(),
            tileTop + mPlusTextView.getMeasuredHeight());
      }
    }
  }
  /**
   * Function used to ensure that the items of a given list row gets wrapped up and do not extend
   * the UI width and height
   */
  private void populateLinks(
      LinearLayout ll, ArrayList<RouteStep> collection, Route route, TextView realTimeText) {

    Display display = activity.getWindowManager().getDefaultDisplay();
    int maxWidth = display.getWidth() - 100;

    /*
    Only if route object contains steps array, allow wrap content
     */
    if (collection.size() > 0) {
      LinearLayout llAlso = new LinearLayout(activity.getApplicationContext());
      llAlso.setLayoutParams(
          new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
      llAlso.setOrientation(LinearLayout.HORIZONTAL);

      int widthSoFar = 0;
      for (int pos = 0; pos < collection.size(); pos++) {
        RouteStep samItem = collection.get(pos);

        TextView image = new TextView(activity.getApplicationContext());
        if (samItem.isTransit()) {
          image.setText(samItem.getDeparture().getTravelTime());

          /*
          Assign an ID to the textview so that when application
          gets the real time data, it can strike off the scheduled arrival time
           */
          image.setId(pos);

          /*
          If the route step is the BUS, check if its the first public transport
          step of the journey, then strike the scheduled bus arrival time
          with the actual arrival time of the BUS retrieved from our application
          server.
           */
          if (samItem.getTransportName() == R.string.tr_bus
              && (pos == 0 || (pos > 0 && !collection.get(pos - 1).isTransit()))
              && !TextUtils.isEmpty(realTimeText.getText())
              && realTimeText.getText().toString().compareTo("Not Available") != 0) {
            image.setPaintFlags(image.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
          }
        } else {
          /*
          Display the time when the user has to start this particular step
          of the journey.
           */
          if (pos == 0) {
            image.setText(route.getDeparture().getTravelTime());
          } else {
            RouteStep item = collection.get(pos - 1);
            image.setText(item.getArrival().getTravelTime());
          }

          // image = new ImageView(activity.getApplicationContext());
          // ((ImageView)image).setImageResource(samItem.getIconId());
          // image.measure(0, 0);
        }

        /*
        display an image corresponding to the mode of travel.
         */
        int id = samItem.getIconId();
        image.setCompoundDrawablesWithIntrinsicBounds(
            0, // left
            0, // top
            0, // right
            id); // bottom);
        image.setTextColor(Color.parseColor("#996633"));
        image.setTypeface(null, Typeface.BOLD);
        image.measure(0, 0);
        widthSoFar += image.getMeasuredWidth();

        /*
        if the components added so far has extended the UI width, wrap
        the contents of the corresponding list row
         */
        if (widthSoFar >= maxWidth) {
          ll.addView(llAlso);

          llAlso = new LinearLayout(activity.getApplicationContext());
          llAlso.setLayoutParams(
              new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
          llAlso.setOrientation(LinearLayout.HORIZONTAL);

          llAlso.addView(image);
          widthSoFar = image.getMeasuredWidth();
        } else {
          llAlso.addView(image);
        }

        /*
        Display the transit vehicle line number and check if
        the components added so far has not extended the UI width. If yes then wrap
        the contents of the corresponding list row
         */
        if (samItem.getShortName() != "" && !samItem.getShortName().equals("")) {
          TextView name = new TextView(activity.getApplicationContext());
          name.setText(samItem.getShortName());
          LinearLayout.LayoutParams params =
              new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
          params.setMargins(0, 50, 0, 0);
          name.setLayoutParams(params);
          name.setTextColor(Color.parseColor("#FFA500"));
          name.setTypeface(null, Typeface.BOLD);

          name.measure(0, 0);
          widthSoFar += name.getMeasuredWidth();

          if (widthSoFar >= maxWidth) {
            ll.addView(llAlso);

            llAlso = new LinearLayout(activity.getApplicationContext());
            llAlso.setLayoutParams(
                new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            llAlso.setOrientation(LinearLayout.HORIZONTAL);

            llAlso.addView(name);
            widthSoFar = name.getMeasuredWidth();
          } else {
            llAlso.addView(name);
          }
        }
        if (pos < collection.size() - 1) {
          ImageView next = new ImageView(activity.getApplicationContext());
          next.setImageResource(R.drawable.ic_action_next_item);
          next.measure(0, 0);
          widthSoFar += next.getMeasuredWidth();

          if (widthSoFar >= maxWidth) {
            ll.addView(llAlso);

            llAlso = new LinearLayout(activity.getApplicationContext());
            llAlso.setLayoutParams(
                new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            llAlso.setOrientation(LinearLayout.HORIZONTAL);

            llAlso.addView(next);
            widthSoFar = next.getMeasuredWidth();
          } else {
            llAlso.addView(next);
          }
        }
      }

      ll.addView(llAlso);
    }
  }
예제 #18
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int width = r - l;
    final int height = b - t;
    final int imageWidth = mImage.getMeasuredWidth();
    final int imageHeight = mImage.getMeasuredHeight();
    final int textWidth = mText.getMeasuredWidth();
    final int textHeight = mText.getMeasuredHeight();
    int left = getPaddingLeft();
    int top = getPaddingTop();
    int right = r - getPaddingRight();
    int bottom = b - getPaddingBottom();

    /*added by chengran sun for better performing*/
    int widthNoPadding = width - getPaddingLeft() - getPaddingRight();
    int heightNoPadding = height - getPaddingTop() - getPaddingBottom();

    if (POSITION_LEFT.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            left,
            (heightNoPadding - textHeight) / 2,
            left += textWidth,
            (heightNoPadding + textHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left += textWidth, top + textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(left, bottom - textHeight, left += textWidth, bottom);
      }

      if (!mNeedLayout) {
        return;
      }

      left += mSpacing;

      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            left,
            (heightNoPadding - imageHeight) / 2,
            left += imageWidth,
            (heightNoPadding + imageHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left += imageWidth, top + imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(left, bottom - imageHeight, left += imageWidth, bottom);
      }
    } else if (POSITION_RIGHT.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            left,
            (heightNoPadding - imageHeight) / 2,
            left += imageWidth,
            (heightNoPadding + imageHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left += imageWidth, top + imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(left, bottom - imageHeight, left += imageWidth, bottom);
      }

      if (!mNeedLayout) {
        return;
      }

      left += mSpacing;

      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            left,
            (heightNoPadding - textHeight) / 2,
            left += textWidth,
            (heightNoPadding + textHeight) / 2);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left += textWidth, top + textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(left, bottom - textHeight, left += textWidth, bottom);
      }
    } else if (POSITION_TOP.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            (widthNoPadding - textWidth) / 2,
            top,
            (widthNoPadding + textWidth) / 2,
            top += textHeight);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left + textWidth, top += textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(right - textWidth, top, right, top += textHeight);
      }

      if (!mNeedLayout) {
        return;
      }

      top += mSpacing;

      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            (widthNoPadding - imageWidth) / 2,
            top,
            (widthNoPadding + imageWidth) / 2,
            top += imageHeight);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left + imageWidth, top += imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(right - imageWidth, top, right, top += imageHeight);
      }
    } else if (POSITION_BOTTOM.equals(mPosition)) {
      if (GRAVITY_CENTER.equals(mImageGravity)) {
        mImage.layout(
            (widthNoPadding - imageWidth) / 2,
            top,
            (widthNoPadding + imageWidth) / 2,
            top += imageHeight);
      } else if (GRAVITY_HEAD.equals(mImageGravity)) {
        mImage.layout(left, top, left + imageWidth, top += imageHeight);
      } else if (GRAVITY_TAIL.equals(mImageGravity)) {
        mImage.layout(right - imageWidth, top, right, top += imageHeight);
      }

      if (!mNeedLayout) {
        return;
      }

      top += mSpacing;

      if (GRAVITY_CENTER.equals(mTextGravity)) {
        mText.layout(
            (widthNoPadding - textWidth) / 2,
            top,
            (widthNoPadding + textWidth) / 2,
            top += textHeight);
      } else if (GRAVITY_HEAD.equals(mTextGravity)) {
        mText.layout(left, top, left + textWidth, top += textHeight);
      } else if (GRAVITY_TAIL.equals(mTextGravity)) {
        mText.layout(right - textWidth, top, right, top += textHeight);
      }
    }
  }