Пример #1
1
  private void setPosition(View v, int dx, int dy) {
    int parentWidth = this.getWidth();
    int parentHeight = this.getHeight();
    int l = v.getLeft() + dx;
    int t = v.getTop() + dy;

    if (l < 0) {
      l = 0;
    } else if ((l + v.getWidth()) >= parentWidth) {
      l = parentWidth - v.getWidth();
    }

    if (t < 0) {
      t = 0;
    } else if ((t + v.getHeight()) >= parentHeight) {
      t = parentHeight - v.getHeight();
    }

    int r = l + v.getWidth();
    int b = t + v.getHeight();

    v.layout(l, t, r, b);

    RelativeLayout.LayoutParams params =
        (android.widget.RelativeLayout.LayoutParams) v.getLayoutParams();
    params.leftMargin = l;
    params.topMargin = t;
    v.setLayoutParams(params);
  }
Пример #2
1
  public void onClick(View v, int position, int countitem) {
    ImageView selectedShip = ((MapBuilder) context).getSelectedShip();
    if (selectedShip != null) {
      ShipOnMap som = new ShipOnMap();
      RelativeLayout fl = (RelativeLayout) v;
      RelativeLayout.LayoutParams params =
          new RelativeLayout.LayoutParams(selectedShip.getWidth(), selectedShip.getHeight());
      som.start.x = x;
      som.start.y = y - v.getTop();
      som.time = (countitem - 1 - position) * 3 + 1;
      String[] shipinfo = ((String) selectedShip.getTag()).split(":");
      som.type = shipinfo[0];
      som.weapon = shipinfo[1];
      params.leftMargin = x - (selectedShip.getWidth() / 2);
      params.topMargin = y - v.getTop() - (selectedShip.getHeight() / 2);
      ImageView iv = new ImageView(context);
      iv.setImageDrawable(selectedShip.getDrawable());
      int h = fl.getHeight();
      int w = fl.getWidth();
      if (!ship.containsKey(position)) {
        ship.put(position, new LinkedList<ShipOnMap>());
      }

      som.ship = iv.getDrawable();
      som.param = params;
      List<ShipOnMap> lship = ship.get(position);
      lship.add(som);
      iv.setTag(position + "/" + (lship.size() - 1));
      ((MapBuilder) context).registerForContextMenu(iv);
      fl.addView(iv, params);
      fl.getLayoutParams().height = h;
      fl.getLayoutParams().width = w;
    }
  }
Пример #3
0
  private void moveZoomedView(
      ImmutableViewportMetrics metrics,
      float newLeftMargin,
      float newTopMargin,
      StartPointUpdate animateStartPoint) {
    RelativeLayout.LayoutParams newLayoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
    newLayoutParams.leftMargin = (int) newLeftMargin;
    newLayoutParams.topMargin = (int) newTopMargin;
    int topMarginMin = (int) (layerView.getSurfaceTranslation() + dynamicToolbarOverlap);
    int topMarginMax = layerView.getHeight() - viewContainerHeight;
    int leftMarginMin = 0;
    int leftMarginMax = layerView.getWidth() - viewContainerWidth;

    if (newTopMargin < topMarginMin) {
      newLayoutParams.topMargin = topMarginMin;
    } else if (newTopMargin > topMarginMax) {
      newLayoutParams.topMargin = topMarginMax;
    }

    if (newLeftMargin < leftMarginMin) {
      newLayoutParams.leftMargin = leftMarginMin;
    } else if (newLeftMargin > leftMarginMax) {
      newLayoutParams.leftMargin = leftMarginMax;
    }

    if (newLayoutParams.topMargin < topMarginMin + 1) {
      moveToolbar(false);
    } else if (newLayoutParams.topMargin > topMarginMax - 1) {
      moveToolbar(true);
    }

    if (animateStartPoint == StartPointUpdate.GECKO_POSITION) {
      // Before this point, the animationStart point is relative to the layerView.
      // The value is initialized in startZoomDisplay using the click point position coming from
      // Gecko.
      // The position of the zoomed view is now calculated, so the position of the animation
      // can now be correctly set relative to the zoomed view
      animationStart.x = animationStart.x - newLayoutParams.leftMargin;
      animationStart.y = animationStart.y - newLayoutParams.topMargin;
    } else if (animateStartPoint == StartPointUpdate.CENTER) {
      // At this point, the animationStart point is no more valid probably because
      // the zoomed view has been moved by the user.
      // In this case, the animationStart point is set to the center point of the zoomed view.
      PointF convertedPosition =
          getUnzoomedPositionFromPointInZoomedView(viewContainerWidth / 2, viewContainerHeight / 2);
      animationStart.x = convertedPosition.x - newLayoutParams.leftMargin;
      animationStart.y = convertedPosition.y - newLayoutParams.topMargin;
    }

    setLayoutParams(newLayoutParams);
    PointF convertedPosition =
        getUnzoomedPositionFromPointInZoomedView(0, offsetDueToToolBarPosition);
    lastPosition = PointUtils.round(convertedPosition);
    requestZoomedViewRender();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_measure_reaction);

    arrowImageView = (ImageView) findViewById(R.id.arrowImageView);
    timeCounterTextView = (TextView) findViewById(R.id.timeCounterTextView);
    LinearLayout cameraPreviewLinLayout = (LinearLayout) findViewById(R.id.cameraPreviewLinLayout);

    secondsLeft = 5;
    timeCounterTextView.setText(String.valueOf(secondsLeft));

    dbTopValue =
        getSharedPreferences(Constants.SHARED_PREF_FILENAME, Context.MODE_PRIVATE)
            .getInt(Constants.SHARED_PREF_TOP_DB_VALUE, -1);
    isDbLevelReached = false;
    lastMeterDegree = 0f;
    moveMeterArrow(lastMeterDegree);

    soundLevelValue = new int[7];
    isApplicationInterrupted = false;

    // Create our Preview view and set it as the content of our activity.
    preview = new CameraPreview(this);
    List<Camera.Size> tmpList = preview.getCamera().getParameters().getSupportedPreviewSizes();
    RelativeLayout.LayoutParams cameraLP =
        (RelativeLayout.LayoutParams) cameraPreviewLinLayout.getLayoutParams();
    int maxWidthResolution = tmpList.get(0).width;
    int maxHeightResolution = tmpList.get(0).height;

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int screenWidth = metrics.widthPixels;
    int screenHeight = metrics.heightPixels;

    // calculation of the best height and shift to the left
    float scale = (float) screenHeight / (float) maxHeightResolution;
    cameraLP.height = (int) (maxHeightResolution * scale);
    cameraLP.width = (int) (maxWidthResolution * scale);
    // shift to the left (center camera)
    int halfScreenWidth = screenWidth / 2;
    int shiftPx = cameraLP.width - halfScreenWidth;
    int leftShiftPx = shiftPx / 2; // make right and left invisible area equal size

    cameraLP.leftMargin = (leftShiftPx * -1);

    cameraPreviewLinLayout.setLayoutParams(cameraLP);
    cameraPreviewLinLayout.addView(preview); // add camera

    // center time counter
    RelativeLayout.LayoutParams counterLP =
        (RelativeLayout.LayoutParams) timeCounterTextView.getLayoutParams();
    counterLP.topMargin = (screenHeight / 10) - (counterLP.height / 2);
    counterLP.leftMargin = (screenWidth / 4) - (counterLP.width / 2);
  }
Пример #5
0
 private void moveView(int x, int y) {
   if (touchView == null) return;
   RelativeLayout.LayoutParams params =
       new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
   params.leftMargin = x - startX + startTouchViewLeft;
   params.topMargin = y - startY + startTouchViewTop;
   // 限制子控件移动必须在视图范围内
   if (params.leftMargin < 0 || (params.leftMargin + touchView.getWidth()) > getWidth())
     params.leftMargin = touchView.getLeft();
   if (params.topMargin < 0 || (params.topMargin + touchView.getHeight()) > getHeight())
     params.topMargin = touchView.getTop();
   touchView.setLayoutParams(params);
 }
Пример #6
0
  public void setSelected(int newState) {
    RelativeLayout.LayoutParams lp =
        (RelativeLayout.LayoutParams) mToggleSelector.getLayoutParams();
    lp.topMargin = (mTableLayout.getMeasuredHeight() - heightItem) / 2;
    lp.leftMargin = newState * widthItem + mTableLayout.getPaddingLeft();
    mToggleSelector.setLayoutParams(lp);

    if (Build.VERSION.SDK_INT < 11) {
      AlphaAnimation animation = new AlphaAnimation((float) 0.2, (float) 0.2);
      animation.setDuration(0);
      animation.setFillAfter(true);
      for (ImageView view : buttonList) {
        view.startAnimation(animation);
      }
      currentState = newState;
      animation = new AlphaAnimation(1, 1);
      animation.setDuration(0);
      animation.setFillAfter(true);
      buttonList.get(currentState).startAnimation(animation);
    } else {
      for (ImageView view : buttonList) {
        view.setAlpha((float) 0.2);
      }
      currentState = newState;
      buttonList.get(currentState).setAlpha((float) 1);
    }
  }
  public void displayAjustView(RecyclingBitmapDrawable value) {
    if (value != null && value.getBitmap() != null) {
      this.value = value;
      adjustView =
          new AdjustView(
              context, value.getBitmap().getWidth(), value.getBitmap().getHeight(), value);
      adjustView.setBackgroundColor(Color.TRANSPARENT);
      //			adjustView.setImageBitmap(bitmap);

      relayout.removeAllViews();
      RelativeLayout.LayoutParams params =
          new RelativeLayout.LayoutParams(
              android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
              android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);

      Tools.initWidth = value.getBitmap().getWidth();
      Tools.initHeight = value.getBitmap().getHeight();

      params.topMargin = (int) (screenHeight * 0.5 - value.getBitmap().getHeight() * 0.5);
      params.leftMargin = (int) (screenWidth * 0.5 - value.getBitmap().getWidth() * 0.5);
      relayout.addView(adjustView, params);

      float rate = (float) viewWidth / viewHeight;
      int mheight = (int) (value.getBitmap().getHeight() * 0.5);
      int mwidth = (int) (mheight * rate);

      adjustView.auto_setAdjustImg(0, 0, mwidth, mheight);
    } else relayout.removeAllViews();
  }
 public void drawAnnotations() {
   mAnnotationLabelOverlay.removeAllViews();
   if (mQueryResult == null) {
     return;
   }
   int[] actImageRect = getBitmapPositionInsideImageView(mImageView);
   List<Annotation> annotations = mQueryResult.annotations;
   int index = -1;
   for (Annotation anno : annotations) {
     index++;
     LabelView label = new LabelView(getActivity());
     label.mLabelText.setVisibility(View.VISIBLE);
     label.mLabelText.setText(anno.text);
     label.mPosition = index;
     float padding = 100;
     float cx = anno.getCenterX() * actImageRect[2];
     float cy = anno.getCenterY() * actImageRect[3];
     if (cx > actImageRect[2] - padding) {
       cx = actImageRect[2] - padding + randomInt(-30, 30);
     } else if (cx < padding) {
       cx = padding + randomInt(-30, 30);
     }
     if (cy > actImageRect[3] - padding) {
       cy = actImageRect[3] - padding + randomInt(-30, 30);
     } else if (cy < padding) {
       cy = padding + randomInt(-30, 30);
     }
     RelativeLayout.LayoutParams params =
         new RelativeLayout.LayoutParams(
             ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
     params.leftMargin = (int) cx + actImageRect[0];
     params.topMargin = (int) cy + actImageRect[1];
     mAnnotationLabelOverlay.addView(label, params);
     label.setOnClickListener(
         new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             LabelView view = (LabelView) v;
             Log.d("label position: ", "" + view.mPosition);
             int position = view.mPosition;
             if (position >= 0 && position < mAnnotationList.size()) {
               mLinearLayoutManager.scrollToPosition(position);
             }
             //                    String text = view.mLabelText.getText().toString();
             //                    AnnotationDetailFragment fragment = new
             // AnnotationDetailFragment();
             //                    Bundle args = new Bundle();
             //                    args.putString("annotation_text", text);
             //                    fragment.setArguments(args);
             //
             // getFragmentManager().beginTransaction().replace(R.id.frame_container,
             // fragment).addToBackStack(null).commit();
           }
         });
     if (mLabels == null) {
       mLabels = new ArrayList<>();
     }
     mLabels.add(label);
   }
 }
Пример #9
0
  private void initView(View layout) {
    lamp = layout.findViewById(R.id.v_lamp);
    menuLv = (ListView) layout.findViewById(R.id.lv_menu);
    subjectLv = (ListView) layout.findViewById(R.id.lv_subject);
    foldBtn = layout.findViewById(R.id.ll_title_sp);
    foldContent = layout.findViewById(R.id.ll_lv_sp);
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) foldBtn.getLayoutParams();
    lp.leftMargin = location[0];
    lp.topMargin = location[1];
    foldBtn.setLayoutParams(lp);
    foldBtn.setOnClickListener(this);
    lamp.setOnClickListener(this);
    menuAdapter = new DataAdapter(getActivity().getBaseContext());

    menuAdapter.setData(allocateData());
    menuLv.setAdapter(menuAdapter);
    menuLv.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            menuAdapter.checked(i);
            subjectAdapter.setData(allocateSubject());
            subjectAdapter.notifyDataSetChanged();
          }
        });
    subjectAdapter = new DataAdapter(getActivity().getBaseContext());
    subjectAdapter.checked(-1);
    subjectAdapter.setData(allocateSubject());
    subjectLv.setAdapter(subjectAdapter);
  }
  private void setLinePositions(GridLayoutView glv) {

    // extend imgageView to bounds
    Bitmap bitmapy = BitmapFactory.decodeResource(getResources(), R.drawable.line_y);
    bitmapy = Bitmap.createScaledBitmap(bitmapy, glWidth, bitmapy.getHeight(), true);
    lineY.setImageBitmap(bitmapy);

    Bitmap bitmapx = BitmapFactory.decodeResource(getResources(), R.drawable.line_x);
    bitmapx = Bitmap.createScaledBitmap(bitmapx, bitmapx.getWidth(), glHeight, true);
    lineX.setImageBitmap(bitmapx);

    xParams = (RelativeLayout.LayoutParams) lineX.getLayoutParams();
    yParams = (RelativeLayout.LayoutParams) lineY.getLayoutParams();

    int positionLineXCentre = glv.getAxisXlines().get(glv.getGridSize() / 2).x;
    xParams.leftMargin =
        shapeStartPointX(glv.getZeroPosX(), glv.getLineSpacingX(), lineStartCoordX)
            - bitmapx.getWidth() / 2;
    lineX.setLayoutParams(xParams);

    int positionLineYCentre = glv.getAxisYlines().get(glv.getGridSize() / 2).y;
    yParams.topMargin =
        shapeStartPointY(glv.getZeroPosY(), glv.getLineSpacingY(), lineStartCoordY)
            - bitmapy.getHeight() / 2;
    lineY.setLayoutParams(yParams);
  }
Пример #11
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // Open app in fullscreen mode
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

    noteLayout = (RelativeLayout) findViewById(R.id.notePanel);

    canvasView = new CanvasView(this);
    switchy = new Switch(this);
    switchy = (Switch) findViewById(R.id.switch1);
    switchy.setOnCheckedChangeListener(this);

    inkRegion = new ArrayList<InkRegion>();
    inkRegion.add(new InkRegion(this, 0));
    inkRegion.add(new InkRegion(this, 1));
    inkRegion.get(0).setBackgroundColor(Color.YELLOW);
    inkRegion.get(1).setBackgroundColor(Color.CYAN);

    // noteLayout.addView(canvasView);
    noteLayout.addView(canvasView);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(200, 200);
    params.leftMargin = 300;
    params.topMargin = 200;
    inkRegion.get(0).setBackgroundColor(Color.GREEN);
    inkRegion.get(0).setPivotX(0);
    inkRegion.get(0).setPivotY(0);
    inkRegion.get(0).setRotation(45);
    inkRegion.get(0).setScaleX((float) 0.2);
    inkRegion.get(0).setScaleY((float) 0.3);
    noteLayout.addView(inkRegion.get(0), params);

    RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(200, 200);
    params1.leftMargin = 300;
    params1.topMargin = 200;
    inkRegion.get(1).setBackgroundColor(Color.BLUE);
    inkRegion.get(1).setPivotX(0);
    inkRegion.get(1).setPivotY(0);
    inkRegion.get(1).setRotation(90);
    inkRegion.get(1).setScaleX((float) 0.2);
    inkRegion.get(1).setScaleY((float) 0.2);
    noteLayout.addView(inkRegion.get(1), params1);
  }
 public void setX(float x) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
     super.setX(x);
   } else {
     RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
     params.leftMargin = (int) x;
     setLayoutParams(params);
   }
 }
Пример #13
0
 /**
  * 添加标签项
  *
  * @param x
  * @param y
  */
 private void addItem(int x, int y) {
   view = null;
   RelativeLayout.LayoutParams params =
       new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
   if (x > getWidth() * 0.5) {
     params.leftMargin = x - PictureTagView.getViewWidth();
     view = new PictureTagView(getContext(), Direction.Right);
   } else {
     params.leftMargin = x;
     view = new PictureTagView(getContext(), Direction.Left);
   }
   params.topMargin = y;
   // 上下位置在视图内
   if (params.topMargin < 0) params.topMargin = 0;
   else if ((params.topMargin + PictureTagView.getViewHeight()) > getHeight())
     params.topMargin = getHeight() - PictureTagView.getViewHeight();
   this.addView(view, params);
 }
Пример #14
0
  /**
   * Moves a view to a screen position. Position is from 0 to 1 and converted to screen pixel.
   * Alignment is top left.
   *
   * @param view View to move
   * @param x X position from 0 to 1
   * @param y Y position from 0 to 1
   */
  public static void setLayoutPosition(Activity a, View view, double x, double y) {
    DisplayMetrics displayMetrics = a.getResources().getDisplayMetrics();
    float screenWidthDp = displayMetrics.widthPixels / displayMetrics.density;
    float screenHeightDp = displayMetrics.heightPixels / displayMetrics.density;

    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.leftMargin = Helper.getPixels(a, screenWidthDp * x);
    params.topMargin = Helper.getPixels(a, screenHeightDp * y);
    view.setLayoutParams(params);
  }
 private void setViewForMiddle() {
   ImageView v = (ImageView) mMiddle.findViewById(R.id.long_bar);
   v.setImageResource(mid_image_selected_list[mSelectedPosition % mid_image_selected_list.length]);
   int t = v.getTop();
   int height = v.getHeight();
   int l = mSelectedPosition % ITEM_NUM * 240;
   int width = v.getWidth();
   RelativeLayout.LayoutParams lp = (LayoutParams) v.getLayoutParams();
   lp.leftMargin = mSelectedPosition % ITEM_NUM * 240;
   v.setLayoutParams(lp);
 }
 private void a(int paramInt1, int paramInt2, int paramInt3)
 {
   float f1 = q().getDisplayMetrics().density;
   RelativeLayout.LayoutParams localLayoutParams = (RelativeLayout.LayoutParams)this.as.getLayoutParams();
   localLayoutParams.topMargin = (int)(0.5F + f1 * paramInt1);
   localLayoutParams.bottomMargin = (int)(0.5F + f1 * paramInt2);
   localLayoutParams.leftMargin = (int)(0.5F + f1 * paramInt3);
   localLayoutParams.rightMargin = localLayoutParams.leftMargin;
   this.as.setLayoutParams(localLayoutParams);
   this.as.requestLayout();
 }
Пример #17
0
  /** 当页面正在滚动时 position 当前选中的是哪个页面 positionOffset 比例 positionOffsetPixels 偏移像素 */
  @Override
  public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    System.out.println("position: " + position + ", positionOffset: " + positionOffset);

    // 20 * (1 + 0.99) = 38
    int leftMargin = (int) (basicWidth * (position + positionOffset));

    RelativeLayout.LayoutParams params =
        (android.widget.RelativeLayout.LayoutParams) mSelectPointView.getLayoutParams();
    params.leftMargin = leftMargin;
    mSelectPointView.setLayoutParams(params);
  }
 public void updateProgress(int progress) {
   final int fairyEndX = mContentView.getWidth() / 2;
   final int fairyStartX = mImageViewFairy.getWidth() / 2;
   final int maxTravelDistance =
       Math.min(fairyEndX - fairyStartX, mContentView.getWidth() - mFairyContainer.getWidth());
   final float translateX = maxTravelDistance * ((float) progress / 100);
   RelativeLayout.LayoutParams lp =
       (android.widget.RelativeLayout.LayoutParams) mFairyContainer.getLayoutParams();
   lp.leftMargin = (int) translateX;
   mFairyContainer.setLayoutParams(lp);
   mProgressBar.setProgress(progress);
 }
Пример #19
0
  public int processJson(String json) {
    courseContainer.removeAllViews();
    int len = 0;
    try {
      L.d("解析所有课程", json);
      JSONArray jsonArray;
      jsonArray = new JSONArray(json);
      len = jsonArray.length();

      for (int i = 0; i < len; i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        Course course = new Course(jsonObject);

        // 将dp转换成px,因为设置RelativeLayout.LayoutParams 的margin只能传入px
        int _60dp = dpToPx(getActivity(), 60);
        int marginDp = dpToPx(getActivity(), 1.5f);

        int colWidth = courseContainer.getWidth() / 7;
        int xStartOffset = (Integer.valueOf(course.getLessonsBegin()) - 1) * (_60dp + marginDp);
        int xEndOffset = (Integer.valueOf(course.getLessonsEnd()) - 1) * (_60dp + marginDp);
        int yStartOffset = (Integer.valueOf(course.getDayOfWeek()) - 1) * colWidth;

        LinearLayout ll =
            (LinearLayout)
                LayoutInflater.from(getActivity()).inflate(R.layout.layout_onecourse, null);

        TextView courseName = (TextView) ll.findViewById(R.id.courseName);
        //				TextView detail = (TextView) ll.findViewById(R.id.detail);
        //				TextView teacher = (TextView) ll.findViewById(R.id.teacher);
        TextView room = (TextView) ll.findViewById(R.id.room);

        courseName.setText(course.getCourseName());
        // detail.setText(course.getDetail());
        // teacher.setText(course.getTeacher());
        room.setText(course.getRoom());

        RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(colWidth, xEndOffset - xStartOffset + _60dp);
        params.leftMargin = yStartOffset;
        params.topMargin = xStartOffset;

        courseContainer.addView(ll, params);

        ll.setOnClickListener(new CourseOnClickListener(course));
      }

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return len;
  }
Пример #20
0
  /**
   * Show this SnackBar. Make sure it already attached to a parent view or this method will do
   * nothing.
   */
  public void show() {
    ViewGroup parent = (ViewGroup) getParent();
    if (parent == null || mState == STATE_SHOWING || mState == STATE_DISMISSING) return;

    if (parent instanceof FrameLayout) {
      LayoutParams params = (LayoutParams) getLayoutParams();

      params.width = mWidth;
      params.height = mHeight;
      params.gravity = Gravity.START | Gravity.BOTTOM;
      if (mIsRtl) params.rightMargin = mMarginStart;
      else params.leftMargin = mMarginStart;
      params.bottomMargin = mMarginBottom;
    } else if (parent instanceof RelativeLayout) {
      RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();

      params.width = mWidth;
      params.height = mHeight;
      params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
      params.addRule(RelativeLayout.ALIGN_PARENT_START);
      if (mIsRtl) params.rightMargin = mMarginStart;
      else params.leftMargin = mMarginStart;
      params.bottomMargin = mMarginBottom;
    }

    if (mInAnimationId != 0 && mState != STATE_SHOWN) {
      Animation anim = AnimationUtils.loadAnimation(getContext(), mInAnimationId);
      anim.setAnimationListener(
          new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
              setState(STATE_SHOWING);
              setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {}

            @Override
            public void onAnimationEnd(Animation animation) {
              setState(STATE_SHOWN);
              startTimer();
            }
          });
      startAnimation(anim);
    } else {
      setVisibility(View.VISIBLE);
      setState(STATE_SHOWN);
      startTimer();
    }
  }
  public void setProgressViewHidden(boolean hidden) {
    RelativeLayout.LayoutParams layoutParams =
        new RelativeLayout.LayoutParams(mTextView.getLayoutParams());
    layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    layoutParams.addRule(
        RelativeLayout.LEFT_OF, hidden ? mLearningStatisticImageView.getId() : mImageView.getId());
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    layoutParams.leftMargin = (int) (10 * mScale);
    layoutParams.rightMargin = (int) (20 * mScale);
    layoutParams.bottomMargin = (int) (20 * mScale);
    layoutParams.topMargin = (int) (20 * mScale);
    mWrapper.setLayoutParams(layoutParams);

    mProgressBar.setVisibility(hidden ? View.GONE : View.VISIBLE);
  }
Пример #22
0
 public static void resetRL(View... view) {
   float rote = Handler_System.getWidthRoate(ApplicationBean.getApplication().getMode_w());
   if (view == null || rote == 1) {
     return;
   }
   for (View view2 : view) {
     RelativeLayout.LayoutParams layoutParams =
         (RelativeLayout.LayoutParams) view2.getLayoutParams();
     layoutParams.leftMargin = (int) (layoutParams.leftMargin * rote);
     layoutParams.rightMargin = (int) (layoutParams.rightMargin * rote);
     layoutParams.topMargin = (int) (layoutParams.topMargin * rote);
     layoutParams.bottomMargin = (int) (layoutParams.bottomMargin * rote);
     view2.setLayoutParams(layoutParams);
   }
 }
Пример #23
0
  private void updateSelection() {
    if (mSelectedPlanet != null && mSelectionView != null) {
      mSelectionView.setVisibility(View.VISIBLE);

      RelativeLayout.LayoutParams params =
          (RelativeLayout.LayoutParams) mSelectionView.getLayoutParams();
      params.width =
          (int) ((((mSelectedPlanet.planet.getSize() - 10.0) / 8.0) + 4.0) * 10.0)
              + (int) (40 * getPixelScale());
      params.height = params.width;
      params.leftMargin = (int) (getLeft() + mSelectedPlanet.centre.x - (params.width / 2));
      params.topMargin = (int) (getTop() + mSelectedPlanet.centre.y - (params.height / 2));
      mSelectionView.setLayoutParams(params);
    }
  }
 private void showImagesOnScreen() {
   int coordY = getInitialY();
   for (int i = 0; i < 2; i++) {
     int coordX = getInitialX();
     for (int j = 0; j < 3; j++) {
       ImageView image = new ImageView(this);
       image.setImageResource(R.drawable.ball_white);
       RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(100, 100);
       lp.leftMargin = coordX;
       lp.topMargin = coordY;
       layout.addView(image, lp);
       coordX = coordX + 120;
     }
     coordY = coordY + 120;
   }
 }
Пример #25
0
  /**
   * @Description: 添加视图到动画层
   *
   * @param @param vg
   * @param @param view
   * @param @param location
   * @param @return
   * @return View
   * @throws
   */
  public View addViewToAnimLayout(final View view, int[] location, int height, int width) {
    int x = location[0];
    int y = location[1];
    if (aniViewGroup == null) {
      aniViewGroup = createAnimLayout();
    }
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width, height);
    lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    lp.leftMargin = x;
    lp.topMargin = y;

    view.setLayoutParams(lp);
    aniViewGroup.addView(view);
    return view;
  }
Пример #26
0
  /*
   * 真正的实现方法
   */
  private void handleOpen(Message msg) {

    MLog.getIns().d("start");

    String[] params = msg.getData().getStringArray(EBaiduMapUtils.MAP_FUN_PARAMS_KEY);
    if (params == null || (params.length != 4 && params.length != 6)) {
      return;
    }

    int x = 0, y = 0, w = 0, h = 0;
    double lng = 0.0, lat = 0.0;
    boolean isUseLngLat = false;

    try {
      // 修复了前端调用open方法时传入小数时抛出NumberFormatException的问题 by waka 2016/01/23
      x = (int) Double.parseDouble(params[0]);
      y = (int) Double.parseDouble(params[1]);
      w = (int) Double.parseDouble(params[2]);
      h = (int) Double.parseDouble(params[3]);

      if (params.length == 6) {
        lng = Double.parseDouble(params[4]);
        lat = Double.parseDouble(params[5]);
        isUseLngLat = true;
      }
      if (mMapBaseFragment != null) {
        MLog.getIns().e("mMapBaseFragment != null");
        return;
      }
      mMapBaseFragment = new EBaiduMapBaseFragment();
      mMapBaseFragment.setBaseObj(this);
      if (isUseLngLat) {
        LatLng center = new LatLng(lat, lng);
        mMapBaseFragment.setStartCenter(center);
      }

      String activityId = EBaiduMapUtils.MAP_ACTIVITY_ID + EUExBaiduMap.this.hashCode();
      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(w, h);
      lp.leftMargin = x;
      lp.topMargin = y;
      addFragmentToCurrentWindow(mMapBaseFragment, lp, activityId);

    } catch (Exception e) {
      e.printStackTrace();
      MLog.getIns().e(e);
    }
  }
Пример #27
0
 @Override
 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
   System.out.println(
       "position:"
           + position
           + ":positionOffset:"
           + positionOffset
           + ":positionOffsetPixels:"
           + positionOffsetPixels);
   // 计算红点移动的距离= 手指移动的距离/屏幕的宽度 * 灰点的间距 = positionOffset * 灰点的间距
   int redPointX = (int) ((position + positionOffset) * dp2px(20));
   // 通过设置红点的左边距,实现红点的移动
   android.widget.RelativeLayout.LayoutParams layoutParams =
       (android.widget.RelativeLayout.LayoutParams) iv_guide_redPoint.getLayoutParams();
   layoutParams.leftMargin = redPointX;
   iv_guide_redPoint.setLayoutParams(layoutParams);
 }
Пример #28
0
  protected void moveAlphaCursor() {
    final int measuredHeight = this.viewAlphaCheckered.getMeasuredHeight();
    float y = measuredHeight - ((this.getAlpha() * measuredHeight) / 255.f);
    final RelativeLayout.LayoutParams layoutParams =
        (RelativeLayout.LayoutParams) this.viewAlphaCursor.getLayoutParams();
    layoutParams.leftMargin =
        (int)
            (this.viewAlphaCheckered.getLeft()
                - Math.floor(this.viewAlphaCursor.getMeasuredWidth() / 2)
                - this.viewContainer.getPaddingLeft());
    layoutParams.topMargin =
        (int)
            ((this.viewAlphaCheckered.getTop() + y)
                - Math.floor(this.viewAlphaCursor.getMeasuredHeight() / 2)
                - this.viewContainer.getPaddingTop());

    this.viewAlphaCursor.setLayoutParams(layoutParams);
  }
Пример #29
0
 protected void moveCursor() {
   float y = viewHue.getMeasuredHeight() - (getHue() * viewHue.getMeasuredHeight() / 360.f);
   if (y == viewHue.getMeasuredHeight()) y = 0.f;
   RelativeLayout.LayoutParams layoutParams =
       (RelativeLayout.LayoutParams) viewCursor.getLayoutParams();
   layoutParams.leftMargin =
       (int)
           (viewHue.getLeft()
               - Math.floor(viewCursor.getMeasuredWidth() / 2)
               - viewContainer.getPaddingLeft());
   layoutParams.topMargin =
       (int)
           (viewHue.getTop()
               + y
               - Math.floor(viewCursor.getMeasuredHeight() / 2)
               - viewContainer.getPaddingTop());
   viewCursor.setLayoutParams(layoutParams);
 }
  private void addpartialView(int index) {
    ViewBundle spot = gridBundle.get(index);
    if (spot == null) return; // should not be
    View displayed = spot.displayed;
    if (displayed == null) return;

    RelativeLayout.LayoutParams rlp = spot.rlp;
    int x = index % col;
    int y = index / col;
    rlp.leftMargin = x * colStep;
    rlp.topMargin = y * rowStep;
    rlp.height = (int) (rowStep * 1.1);
    rlp.width = colStep;

    ViewGroup vg = (ViewGroup) displayed.getParent();
    if (vg != null) vg.removeView(displayed);
    super.addView(displayed, rlp);
  }