Java Code Examples for android.view.View.post()

The following are Jave code examples for showing how to use post() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: FireFiles   File: ConnectionsFragment.java   Source Code and License Vote up 7 votes
@Override
public void onClick(final View view) {
    switch (view.getId()){
        case R.id.fab:
            addConnection();
            break;
        case R.id.button_popup:
            final int position = mListView.getPositionForView(view);
            if (position != ListView.INVALID_POSITION) {
                view.post(new Runnable() {
                    @Override
                    public void run() {
                        showPopupMenu(view, position);
                    }
                });
            }
            break;
    }
}
 
Example 2
Project: Hotspot-master-devp   File: SavorAnimUtil.java   Source Code and License Vote up 7 votes
public static void shake(final View view, final Animator.AnimatorListener listener) {
        view.clearAnimation();
        view.post(new Runnable() {
            @Override
            public void run() {
                view.setPivotX(view.getWidth()/2);
                view.setPivotY(view.getHeight());
                ObjectAnimator shakeAnim = ObjectAnimator.ofFloat(view, "rotation", 0f,-15f,0f, 15f, 0f).setDuration(1200);
//        shakeAnim.setInterpolator(new AccelerateInterpolator());
                if(listener!=null) {
                    shakeAnim.addListener(listener);
                }
                shakeAnim.setStartDelay(500);
                shakeAnim.start();
            }
        });

    }
 
Example 3
Project: ViewPrinter   File: DocumentPage.java   Source Code and License Vote up 7 votes
private boolean tryPassFirstViewToPrevious(DocumentColumn current, DocumentColumn previous) {
    final View view = current.getViewCount() == 0 ? null : current.getViewAt(0);
    if (view != null && previous.canTake(view, view.getLayoutParams(), false)) {
        mLog.i("tryPassFirstViewToPrevious:", "passing view", Utils.mark(view),
                "from", current.getNumber(), "to", previous.getNumber());
        boolean hasFocus = view.hasFocus();
        current.release(view);
        previous.take(view, view.getLayoutParams());
        if (hasFocus) {
            view.post(new Runnable() {
                @Override
                public void run() {
                    view.requestFocus();
                    Utils.showKeyboard(view);
                }
            });
        }
        return true;
    }
    return false;
}
 
Example 4
Project: simple-share-android   File: ConnectionsFragment.java   Source Code and License Vote up 7 votes
@Override
public void onClick(final View view) {
    switch (view.getId()){
        case R.id.fab:
            addConnection();
            break;
        case R.id.button_popup:
            final int position = mListView.getPositionForView(view);
            if (position != ListView.INVALID_POSITION) {
                view.post(new Runnable() {
                    @Override
                    public void run() {
                        showPopupMenu(view, position);
                    }
                });
            }
            break;
    }
}
 
Example 5
Project: android-project-gallery   File: ViewPropertyAnimatorPreHC.java   Source Code and License Vote up 6 votes
/**
 * Utility function, called by animateProperty() and animatePropertyBy(), which handles the
 * details of adding a pending animation and posting the request to start the animation.
 *
 * @param constantName The specifier for the property being animated
 * @param startValue The starting value of the property
 * @param byValue The amount by which the property will change
 */
private void animatePropertyBy(int constantName, float startValue, float byValue) {
    // First, cancel any existing animations on this property
    if (mAnimatorMap.size() > 0) {
        Animator animatorToCancel = null;
        Set<Animator> animatorSet = mAnimatorMap.keySet();
        for (Animator runningAnim : animatorSet) {
            PropertyBundle bundle = mAnimatorMap.get(runningAnim);
            if (bundle.cancel(constantName)) {
                // property was canceled - cancel the animation if it's now empty
                // Note that it's safe to break out here because every new animation
                // on a property will cancel a previous animation on that property, so
                // there can only ever be one such animation running.
                if (bundle.mPropertyMask == NONE) {
                    // the animation is no longer changing anything - cancel it
                    animatorToCancel = runningAnim;
                    break;
                }
            }
        }
        if (animatorToCancel != null) {
            animatorToCancel.cancel();
        }
    }

    NameValuesHolder nameValuePair = new NameValuesHolder(constantName, startValue, byValue);
    mPendingAnimations.add(nameValuePair);
    View v = mView.get();
    if (v != null) {
        v.removeCallbacks(mAnimationStarter);
        v.post(mAnimationStarter);
    }
}
 
Example 6
Project: From-design-to-Android-part1   File: OrderDialogFragment.java   Source Code and License Vote up 6 votes
private void startCloneAnimation(View clonedView, View targetView) {
    clonedView.post(() -> {
            TransitionManager.beginDelayedTransition(
                (ViewGroup) binding.getRoot(), selectedViewTransition);

            // Fires the transition
            clonedView.setLayoutParams(SelectedParamsFactory
                .endParams(clonedView, targetView));
    });
}
 
Example 7
Project: login   File: BottomSheetMenuDialog.java   Source Code and License Vote up 6 votes
private void fixLandscapePeekHeight(final View sheet) {
    // On landscape, we shouldn't use the 16:9 keyline alignment
    sheet.post(new Runnable() {
        @Override
        public void run() {
            mBehavior.setPeekHeight(sheet.getHeight() / 2);
        }
    });
}
 
Example 8
Project: Camera-Roll-Android-App   File: Util.java   Source Code and License Vote up 6 votes
public static void setLightStatusBarIcons(final View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        v.post(new Runnable() {
            @Override
            public void run() {
                v.setSystemUiVisibility(0);
            }
        });
    }
}
 
Example 9
Project: weex-uikit   File: WXSliderNeighbor.java   Source Code and License Vote up 6 votes
private void updateAdapterScaleAndAlpha(final float alpha, final float scale) {
    final List<View> pageViews = mAdapter.getViews();
    final int curPos = mViewPager.getCurrentItem();

    if(pageViews.size() > 0) {
        final View currentPage = pageViews.get(curPos);
        updateScaleAndAlpha(((ViewGroup)currentPage).getChildAt(0),1.0F,WX_DEFAULT_MAIN_NEIGHBOR_SCALE);

        if(pageViews.size() < 2) {
            return;
        }
        //make sure View's width & height are measured.
        currentPage.post(WXThread.secure(new Runnable() {
            @Override
            public void run() {
                //change left and right page's translation
                updateNeighbor(currentPage, alpha, scale);

            }
        }));

        // make sure only display view current, left, right.
        int left = (curPos == 0) ? pageViews.size()-1 : curPos-1;
        int right = (curPos == pageViews.size()-1) ? 0 : curPos+1;
        for(int i =0; i<mAdapter.getRealCount(); i++) {
            if(i != left && i != curPos && i != right) {
                ((ViewGroup)pageViews.get(i)).getChildAt(0).setAlpha(0F);
            }
        }
    }
}
 
Example 10
Project: Orin   File: AlbumDetailActivity.java   Source Code and License Vote up 6 votes
private void setUpRecyclerView() {
        setUpRecyclerViewPadding();
        recyclerView.setScrollViewCallbacks(observableScrollViewCallbacks);
        final View contentView = getWindow().getDecorView().findViewById(android.R.id.content);
        contentView.post(new Runnable() {
            @Override
            public void run() {
                songsBackgroundView.getLayoutParams().height = contentView.getHeight();
                observableScrollViewCallbacks.onScrollChanged(-(albumArtViewHeight + titleViewHeight), false, false);
                // necessary to fix a bug
                recyclerView.scrollBy(0, 1);
                recyclerView.scrollBy(0, -1);

//                if (getAlbum().getSongCount() > 10) {
//                    ViewGroup.LayoutParams params = recyclerView.getLayoutParams();
//                    params.height = contentView.getHeight() * 3;
//                    recyclerView.setLayoutParams(params);
//                    recyclerView.requestLayout();
//                }else {
//                    ViewGroup.LayoutParams params = recyclerView.getLayoutParams();
//                    params.height = (int) (contentView.getHeight());
//                    recyclerView.setLayoutParams(params);
//                    recyclerView.requestLayout();
//                }
//
//                recyclerView.setTranslationY(-(albumArtViewHeight + getResources().getDimensionPixelSize(R.dimen.thirthy_dp)));
            }
        });
    }
 
Example 11
Project: JBase   File: VDHLayout.java   Source Code and License Vote up 6 votes
/**
 * 设置需要松开回弹的view
 *
 * @param view        view
 * @param isFillAfter true需要,false不需要(用于清除)
 */
public void setResetAfter(final View view, boolean isFillAfter) {
    boolean hasKey = fillAfterMap.containsKey(view);
    //需要添加
    if (isFillAfter) {
        if (hasKey) {
            return;//已经存在直接返回
        } else {
            //不存在,进行添加
            view.post(new Runnable() {
                @Override
                public void run() {
                    if (view == null)
                        return;
                    Point point = new Point();
                    point.x = view.getLeft();
                    point.y = view.getTop();
                    fillAfterMap.put(view, point);
                }
            });
        }
    } else {
        //不添加
        if (hasKey) {
            //有数据,进行删除
            fillAfterMap.remove(view);
        } else {
            return;
        }
    }
}
 
Example 12
Project: mupdf-android-viewer-nui   File: ProofActivity.java   Source Code and License Vote up 6 votes
private void gotoPage(View v, final int pageNum)
{
	spinner = createAndShowWaitSpinner(this);
	mWaitingForIdle = true;
	v.post(new Runnable() {
		@Override
		public void run() {
			mDocView.setCurrentPage(pageNum);
		}
	});
}
 
Example 13
Project: fancyDialog   File: MainActivity.java   Source Code and License Vote up 6 votes
private void setupDialogToSustainAfterRotation(View viewToPostAfter) {
    // REMEMBER to dismiss dialog in onPause method
    // Make sure that all views are drawn
    viewToPostAfter.post(new Runnable() {
        @Override
        public void run() {
            // then check if dialog was previously opened
            if (((CustomApplication) getApplication()).wasDialogOpened()) {
                buildAndShowDialog();
            }
        }
    });
}
 
Example 14
Project: TestChat   File: BaseItemClickListener.java   Source Code and License Vote up 6 votes
private void resetView(final View childView) {
                        childView.post(new Runnable() {
                                @Override
                                public void run() {
                                        if (childView != null) {
                                                childView.setPressed(false);
                                        }
                                }
                        });
                        isPressing = false;
//                        置空,防止内存泄漏
                        mPressedView = null;
                }
 
Example 15
Project: FTC2016   File: SensorMRColor.java   Source Code and License Vote up 5 votes
@Override
public void runOpMode() {

  // hsvValues is an array that will hold the hue, saturation, and value information.
  float hsvValues[] = {0F,0F,0F};

  // values is a reference to the hsvValues array.
  final float values[] = hsvValues;

  // get a reference to the RelativeLayout so we can change the background
  // color of the Robot Controller app to match the hue detected by the RGB sensor.
  final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(R.id.RelativeLayout);

  // bPrevState and bCurrState represent the previous and current state of the button.
  boolean bPrevState = false;
  boolean bCurrState = false;

  // bLedOn represents the state of the LED.
  boolean bLedOn = true;

  // get a reference to our ColorSensor object.
  colorSensor = hardwareMap.colorSensor.get("sensor_color");

  // Set the LED in the beginning
  colorSensor.enableLed(bLedOn);

  // wait for the start button to be pressed.
  waitForStart();

  // while the op mode is active, loop and read the RGB data.
  // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
  while (opModeIsActive()) {

    // check the status of the x button on either gamepad.
    bCurrState = gamepad1.x;

    // check for button state transitions.
    if ((bCurrState == true) && (bCurrState != bPrevState))  {

      // button is transitioning to a pressed state. So Toggle LED
      bLedOn = !bLedOn;
      colorSensor.enableLed(bLedOn);
    }

    // update previous state variable.
    bPrevState = bCurrState;

    // convert the RGB values to HSV values.
    Color.RGBToHSV(colorSensor.red() * 8, colorSensor.green() * 8, colorSensor.blue() * 8, hsvValues);

    // send the info back to driver station using telemetry function.
    telemetry.addData("LED", bLedOn ? "On" : "Off");
    telemetry.addData("Clear", colorSensor.alpha());
    telemetry.addData("Red  ", colorSensor.red());
    telemetry.addData("Green", colorSensor.green());
    telemetry.addData("Blue ", colorSensor.blue());
    telemetry.addData("Hue", hsvValues[0]);

    // change the background color to match the color detected by the RGB sensor.
    // pass a reference to the hue, saturation, and value array as an argument
    // to the HSVToColor method.
    relativeLayout.post(new Runnable() {
      public void run() {
        relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
      }
    });

    telemetry.update();
  }
}
 
Example 16
Project: Auto.js   File: ConsoleFloaty.java   Source Code and License Vote up 5 votes
private void setInitialMeasure(final View view) {
    view.post(() -> ViewUtil.setViewMeasure(view, ScreenMetrics.getDeviceScreenWidth() * 2 / 3,
            ScreenMetrics.getDeviceScreenHeight() / 3));
}
 
Example 17
Project: Ftc2018RelicRecovery   File: SensorREVColorDistance.java   Source Code and License Vote up 5 votes
@Override
public void runOpMode() {

    // get a reference to the color sensor.
    sensorColor = hardwareMap.get(ColorSensor.class, "sensor_color_distance");

    // get a reference to the distance sensor that shares the same name.
    sensorDistance = hardwareMap.get(DistanceSensor.class, "sensor_color_distance");

    // hsvValues is an array that will hold the hue, saturation, and value information.
    float hsvValues[] = {0F, 0F, 0F};

    // values is a reference to the hsvValues array.
    final float values[] = hsvValues;

    // sometimes it helps to multiply the raw RGB values with a scale factor
    // to amplify/attentuate the measured values.
    final double SCALE_FACTOR = 255;

    // get a reference to the RelativeLayout so we can change the background
    // color of the Robot Controller app to match the hue detected by the RGB sensor.
    int relativeLayoutId = hardwareMap.appContext.getResources().getIdentifier("RelativeLayout", "id", hardwareMap.appContext.getPackageName());
    final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(relativeLayoutId);

    // wait for the start button to be pressed.
    waitForStart();

    // loop and read the RGB and distance data.
    // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
    while (opModeIsActive()) {
        // convert the RGB values to HSV values.
        // multiply by the SCALE_FACTOR.
        // then cast it back to int (SCALE_FACTOR is a double)
        Color.RGBToHSV((int) (sensorColor.red() * SCALE_FACTOR),
                (int) (sensorColor.green() * SCALE_FACTOR),
                (int) (sensorColor.blue() * SCALE_FACTOR),
                hsvValues);

        // send the info back to driver station using telemetry function.
        telemetry.addData("Distance (cm)",
                String.format(Locale.US, "%.02f", sensorDistance.getDistance(DistanceUnit.CM)));
        telemetry.addData("Alpha", sensorColor.alpha());
        telemetry.addData("Red  ", sensorColor.red());
        telemetry.addData("Green", sensorColor.green());
        telemetry.addData("Blue ", sensorColor.blue());
        telemetry.addData("Hue", hsvValues[0]);

        // change the background color to match the color detected by the RGB sensor.
        // pass a reference to the hue, saturation, and value array as an argument
        // to the HSVToColor method.
        relativeLayout.post(new Runnable() {
            public void run() {
                relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
            }
        });

        telemetry.update();
    }

    // Set the panel back to the default color
    relativeLayout.post(new Runnable() {
        public void run() {
            relativeLayout.setBackgroundColor(Color.WHITE);
        }
    });
}
 
Example 18
Project: FanChat   File: PhotoViewAttacher.java   Source Code and License Vote up 5 votes
@Override
public final boolean onTouch(View v, MotionEvent ev) {
	boolean handled = false;

	if (mZoomEnabled) {
		switch (ev.getAction()) {
		case MotionEvent.ACTION_DOWN:
			// First, disable the Parent from intercepting the touch
			// event
			v.getParent().requestDisallowInterceptTouchEvent(true);

			// If we're flinging, and the user presses down, cancel
			// fling
			cancelFling();
			break;

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			// If the user has zoomed less than min scale, zoom back
			// to min scale
			if (getScale() < mMinScale) {
				RectF rect = getDisplayRect();
				if (null != rect) {
					v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
					handled = true;
				}
			}
			break;
		}

		// Check to see if the user double tapped
		if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
			handled = true;
		}

		// Finally, try the Scale/Drag detector
		if (null != mScaleDragDetector && mScaleDragDetector.onTouchEvent(ev)) {
			handled = true;
		}
	}

	return handled;
}
 
Example 19
Project: AndroidThemeChange   File: SizeUtils.java   Source Code and License Vote up 4 votes
/**
 * 在onCreate中获取视图的尺寸
 * <p>需回调onGetSizeListener接口,在onGetSize中获取view宽高</p>
 * <p>用法示例如下所示</p>
 * <pre>
 * SizeUtils.forceGetViewSize(view, new SizeUtils.onGetSizeListener() {
 *     Override
 *     public void onGetSize(View view) {
 *         view.getWidth();
 *     }
 * });
 * </pre>
 *
 * @param view     视图
 * @param listener 监听器
 */
public static void forceGetViewSize(final View view, final onGetSizeListener listener) {
    view.post(new Runnable() {
        @Override
        public void run() {
            if (listener != null) {
                listener.onGetSize(view);
            }
        }
    });
}
 
Example 20
Project: AndroidThemeChange   File: SizeUtils.java   Source Code and License Vote up 4 votes
/**
 * 在onCreate中获取视图的尺寸
 * <p>需回调onGetSizeListener接口,在onGetSize中获取view宽高</p>
 * <p>用法示例如下所示</p>
 * <pre>
 * SizeUtils.forceGetViewSize(view, new SizeUtils.onGetSizeListener() {
 *     Override
 *     public void onGetSize(View view) {
 *         view.getWidth();
 *     }
 * });
 * </pre>
 *
 * @param view     视图
 * @param listener 监听器
 */
public static void forceGetViewSize(final View view, final onGetSizeListener listener) {
    view.post(new Runnable() {
        @Override
        public void run() {
            if (listener != null) {
                listener.onGetSize(view);
            }
        }
    });
}