Java Code Examples for android.widget.ImageView#setRotation()
The following examples show how to use
android.widget.ImageView#setRotation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageViewSensorAnimationBehavior.java From science-journal with Apache License 2.0 | 6 votes |
@Override public void initializeLargeIcon(RelativeLayout layout, @Nullable Double value) { // Remove previous views. if (layout.getChildCount() > 0) { layout.removeAllViews(); } ImageView largeIcon = new ImageView(layout.getContext()); layout.addView( largeIcon, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); largeIcon.setImageDrawable(getLevelDrawable(largeIcon.getContext())); largeIcon.setRotation(0.0f); // Icon level depends on type -- we want to pick something in the middle to look reasonable. if (behaviorType == TYPE_ACCELEROMETER_SCALE || behaviorType == TYPE_ACCELEROMETER_SCALE_ROTATES) { // Pick the middle icon largeIcon.setImageLevel(2); } else if (behaviorType == TYPE_POSITIVE_RELATIVE_SCALE || behaviorType == TYPE_RELATIVE_SCALE) { // Pick the most exciting icon (the biggest value represented) largeIcon.setImageLevel(3); } }
Example 2
Source File: FirstProvider.java From BaseRecyclerViewAdapterHelper with MIT License | 6 votes |
private void setArrowSpin(BaseViewHolder helper, BaseNode data, boolean isAnimate) { FirstNode entity = (FirstNode) data; ImageView imageView = helper.getView(R.id.iv); if (entity.isExpanded()) { if (isAnimate) { ViewCompat.animate(imageView).setDuration(200) .setInterpolator(new DecelerateInterpolator()) .rotation(0f) .start(); } else { imageView.setRotation(0f); } } else { if (isAnimate) { ViewCompat.animate(imageView).setDuration(200) .setInterpolator(new DecelerateInterpolator()) .rotation(90f) .start(); } else { imageView.setRotation(90f); } } }
Example 3
Source File: EditSpinner.java From EditSpinner with Apache License 2.0 | 6 votes |
private void initView(AttributeSet attrs) { LayoutInflater.from(mContext).inflate(R.layout.edit_spinner, this); editText = (EditText) findViewById(R.id.edit_sipnner_edit); mRightIv = (ImageView) findViewById(R.id.edit_spinner_expand); mRightImageTopView = findViewById(R.id.edit_spinner_expand_above); mRightImageTopView.setOnClickListener(this); mRightImageTopView.setClickable(false); mRightIv.setOnClickListener(this); mRightIv.setRotation(90); editText.addTextChangedListener(this); TypedArray tArray = mContext.obtainStyledAttributes(attrs, R.styleable.EditSpinner); editText.setHint(tArray.getString(R.styleable.EditSpinner_hint)); int imageId = tArray.getResourceId(R.styleable.EditSpinner_rightImage, 0); if (imageId != 0) { mRightIv.setImageResource(imageId); } int bg = tArray.getResourceId(R.styleable.EditSpinner_Background, 0); if (bg != 0) { editText.setBackgroundResource(bg); } maxLine = tArray.getInt(R.styleable.EditSpinner_maxLine, 1); editText.setMaxLines(maxLine); tArray.recycle(); }
Example 4
Source File: MultipleRvFragment.java From ExpandableRecyclerView with Apache License 2.0 | 6 votes |
@Override public void onParentCollapsed(RecyclerView rv, ParentViewHolder pvh, int position, boolean pendingCause, boolean byUser) { Logger.e(TAG, "onParentCollapsed=" + position + ",tag=" + rv.getTag() + ",byUser=" + byUser); if (pvh == null) return; final ImageView arrow = pvh.getView(R.id.arrow); if (arrow.getVisibility() != View.VISIBLE) return; final float currRotate = arrow.getRotation(); float rotate = 360; //未展开完全并且当前旋转角度小于180,逆转回去 if (currRotate < 180) { rotate = 0; } if (pendingCause) { arrow.setRotation(rotate); } else { arrow.animate().rotation(rotate) .setDuration(mItemAnimator.getRemoveDuration() + 180).start(); } }
Example 5
Source File: MultipleRvFragment.java From ExpandableRecyclerView with Apache License 2.0 | 6 votes |
@Override public void onParentExpanded(RecyclerView rv, ParentViewHolder pvh, int position, boolean pendingCause, boolean byUser) { Logger.e(TAG, "onParentExpanded=" + position + "," + rv.getTag() + ",byUser=" + byUser); if (pvh == null) return; ImageView arrow = pvh.getView(R.id.arrow); if (arrow.getVisibility() != View.VISIBLE) return; float currRotate = arrow.getRotation(); //重置为从0开始旋转 if (currRotate == 360) { arrow.setRotation(0); } if (pendingCause) { arrow.setRotation(180); } else { arrow.animate() .rotation(180) .setDuration(mItemAnimator.getAddDuration() + 180) .start(); } }
Example 6
Source File: SingleRvFragment.java From ExpandableRecyclerView with Apache License 2.0 | 6 votes |
@Override public void onParentCollapsed(RecyclerView rv, ParentViewHolder pvh, int position, boolean pendingCause, boolean byUser) { Logger.e(TAG, "onParentCollapsed=" + position + ",tag=" + rv.getTag() + ",byUser=" + byUser); if (pvh == null) return; ImageView arrow = pvh.getView(R.id.arrow); if (arrow.getVisibility() != View.VISIBLE) return; float currRotate = arrow.getRotation(); float rotate = 360; //未展开完全并且当前旋转角度小于180,逆转回去 if (currRotate < 180) { rotate = 0; } if (pendingCause) { arrow.setRotation(rotate); } else { arrow.animate() .rotation(rotate) .setDuration(mItemAnimator.getRemoveDuration() + 180) .start(); } }
Example 7
Source File: ScreenshotFragment.java From DGameDetail with Apache License 2.0 | 6 votes |
/** * 恢复 * * @param img */ private void resumeRotation(ImageView img, boolean useAnim) { int w = AndroidUtils.getWindowWidth(getActivity()), h = AndroidUtils.getWindowHeight(getActivity()); int iw = img.getMeasuredWidth(), ih = img.getMeasuredHeight(); if (useAnim) { ObjectAnimator move = ObjectAnimator.ofFloat(img, "translationY", (h - ih) / 2f, 0); move.setDuration(400); ObjectAnimator scaleX = ObjectAnimator.ofFloat(img, "scaleX", (float) h / iw, 1.0f); ObjectAnimator scaleY = ObjectAnimator.ofFloat(img, "scaleY", (float) w / ih, 1.0f); ObjectAnimator rotation = ObjectAnimator.ofFloat(img, "rotation", 90f, 0f); AnimatorSet set = new AnimatorSet(); set.play(scaleX).with(scaleY).with(rotation).with(move); set.setDuration(600); set.start(); } else { img.setTranslationY(0f); img.setScaleX(1.0f); img.setScaleY(1.0f); img.setRotation(0f); } }
Example 8
Source File: DrawerSubMenuBase.java From edslite with GNU General Public License v2.0 | 6 votes |
@SuppressLint("NewApi") @Override public void updateView(View view, @SuppressWarnings("UnusedParameters") int position) { super.updateView(view, position); TextView tv = (TextView)view.findViewById(android.R.id.text1); tv.setPressed(_isExpanded); Drawable drawable = view.getBackground(); if(drawable!=null) drawable.setState(_isExpanded ? new int[] {android.R.attr.state_expanded} : new int[0]); ImageView iv = (ImageView) view.findViewById(android.R.id.icon); if(iv != null && (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN || !iv.hasTransientState())) { iv.setVisibility(View.VISIBLE); iv.setRotation(isExpanded() ? 180 : 0); } }
Example 9
Source File: CardDataIOView.java From Walrus with GNU General Public License v3.0 | 5 votes |
public void setDirection(boolean reading) { ImageView directionImage = findViewById(R.id.direction); directionImage.setImageDrawable( ContextCompat.getDrawable(getContext(), R.drawable.drawable_card_data_io_direction)); directionImage.setRotation(90 + (reading ? 180 : 0)); directionImage.setContentDescription(getContext().getString( reading ? R.string.read_description : R.string.write_description)); }
Example 10
Source File: MapFragment.java From apollo-DuerOS with Apache License 2.0 | 5 votes |
private void updateCompassView(ImageView v, int changeBearing) { float degrees = changeBearing; String directionString = inWhichDir(changeBearing); v.setRotation(180 - degrees); if (directionView != null) { directionView.setText(directionString); } if (tvDushu != null) { tvDushu.setText((int) degrees + getActivity().getResources().getString(R.string.degree)); } }
Example 11
Source File: CityWeatherActivity.java From LittleFreshWeather with Apache License 2.0 | 5 votes |
@Override public void run() { ++mSpecialWeatherNumRain; if (mSpecialWeatherNumRain <= mSpecialWeatherNumLimitRain) { int screenHeight = DensityUtil.getScreenHeight(CityWeatherActivity.this); int screenWidth = DensityUtil.getScreenWidth(CityWeatherActivity.this); int fX = mRandom.nextInt(screenWidth << 1); int tX = fX - (int)(screenHeight * 0.58); ImageView imageView = new ImageView(CityWeatherActivity.this); imageView.setVisibility(View.VISIBLE); mPresenter.getImageViewSrc(imageView, mRainIconId); //imageView.setImageResource(mRainIconId); imageView.setRotation(30); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(fX, 0, 0, 0); rlBackgroundView.addView(imageView, layoutParams); PropertyValuesHolder holderY = PropertyValuesHolder.ofFloat("translationY", -100, screenHeight + 100); PropertyValuesHolder holderX = PropertyValuesHolder.ofFloat("translationX", fX, tX); ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(imageView, holderX, holderY); if ((mSpecialWeatherNumRain & 0x1) == 0) { animator.setDuration(mSpecialWeatherSpeedLimitRain); } else { animator.setDuration(mSpecialWeatherSpeedLimitRain + RAIN_SPEED_OFFSET); } animator.setRepeatMode(ObjectAnimator.RESTART); animator.setRepeatCount(ObjectAnimator.INFINITE); animator.setInterpolator(new LinearInterpolator()); animator.start(); mHandler.postDelayed(rainProc, RAIN_GEN_INTERVAL); } }
Example 12
Source File: GglMapCustomMarkerView.java From FimiX8-RE with MIT License | 5 votes |
public BitmapDescriptor createPointWithSmallArrow(Context context, int res, float angle, boolean isShow) { View view = LayoutInflater.from(context).inflate(R.layout.x8_map_marker_arrow_view, null); ImageView imageView = (ImageView) view.findViewById(R.id.markerIcon); if (res != 0) { imageView.setBackgroundResource(res); imageView.setRotation(angle); } if (!isShow) { imageView.setVisibility(4); } return BitmapDescriptorFactory.fromBitmap(loadBitmapFromView(view, context)); }
Example 13
Source File: DataPlotFragment.java From OpenLibre with GNU General Public License v3.0 | 5 votes |
private void updateScanData(List<GlucoseData> trend) { if (trend.size() == 0) { Toast.makeText(this.getContext(), "No current data available!", Toast.LENGTH_LONG).show(); return; } mDataPlotView.findViewById(R.id.scan_data).setVisibility(View.VISIBLE); GlucoseData currentGlucose = trend.get(trend.size() - 1); TextView tv_currentGlucose = (TextView) mDataPlotView.findViewById(R.id.tv_glucose_current_value); tv_currentGlucose.setText( String.format(getResources().getString(R.string.glucose_current_value), currentGlucose.glucoseString(), getDisplayUnit()) ); PredictionData predictedGlucose = new PredictionData(trend); TextView tv_predictedGlucose = (TextView) mDataPlotView.findViewById(R.id.tv_glucose_prediction); tv_predictedGlucose.setText(String.valueOf(predictedGlucose.glucoseData.glucoseString())); tv_predictedGlucose.setAlpha((float) min(1, 0.1 + predictedGlucose.confidence())); ImageView iv_unit = (ImageView) mDataPlotView.findViewById(R.id.iv_unit); if (GLUCOSE_UNIT_IS_MMOL) { iv_unit.setImageResource(R.drawable.ic_unit_mmoll); } else { iv_unit.setImageResource(R.drawable.ic_unit_mgdl); } iv_unit.setAlpha((float) min(1, 0.1 + predictedGlucose.confidence())); ImageView iv_predictionArrow = (ImageView) mDataPlotView.findViewById(R.id.iv_glucose_prediction); // rotate trend arrow according to glucose prediction slope float rotationDegrees = -90f * max(-1f, min(1f, (float) (predictedGlucose.glucoseSlopeRaw / TREND_UP_DOWN_LIMIT))); iv_predictionArrow.setRotation(rotationDegrees); // reduce trend arrow visibility according to prediction confidence iv_predictionArrow.setAlpha((float) min(1, 0.1 + predictedGlucose.confidence())); }
Example 14
Source File: CompassView.java From android with Apache License 2.0 | 5 votes |
@Override public void setRotation(float rotation) { final ImageView image = (ImageView) findViewById(getImageId()); if (image != null) { image.setRotation(rotation); if (image.getAlpha() == 0f) { image.setAlpha(1f); } } }
Example 15
Source File: SingleRvFragment.java From ExpandableRecyclerView with Apache License 2.0 | 5 votes |
@Override public void onParentExpanded(RecyclerView rv, ParentViewHolder pvh, int position, boolean pendingCause, boolean byUser) { Logger.e(TAG, "onParentExpanded=" + position + "," + rv.getTag() + ",byUser=" + byUser); if (pvh == null) return; ImageView arrow = pvh.getView(R.id.arrow); if (arrow.getVisibility() != View.VISIBLE) return; float currRotate = arrow.getRotation(); //重置为从0开始旋转 if (currRotate == 360) { arrow.setRotation(0); } if (pendingCause) { arrow.setRotation(180); } else { arrow.animate() .rotation(180) .setDuration(mItemAnimator.getAddDuration() + 180) .start(); } // if (byUser) { // int scrollToPos = // pvh.getAdapterPosition() + ((MyParent) pvh.getParent()).getChildCount(); // rv.scrollToPosition(scrollToPos); // } }
Example 16
Source File: ExpandableAdapter.java From GroupedRecyclerViewAdapter with Apache License 2.0 | 5 votes |
@Override public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition) { ExpandableGroupEntity entity = mGroups.get(groupPosition); holder.setText(R.id.tv_expandable_header, entity.getHeader()); ImageView ivState = holder.get(R.id.iv_state); if(entity.isExpand()){ ivState.setRotation(90); } else { ivState.setRotation(0); } }
Example 17
Source File: MultipleRvFragment.java From ExpandableRecyclerView with Apache License 2.0 | 5 votes |
@Override public void onParentExpandableStateChanged(RecyclerView rv, ParentViewHolder pvh, int position, boolean expandable) { Logger.e(TAG, "onParentExpandableStateChanged=" + position + "," + rv.getTag()); if (pvh == null) return; ImageView arrow = pvh.getView(R.id.arrow); if (expandable && arrow.getVisibility() != View.VISIBLE) { arrow.setVisibility(View.VISIBLE); arrow.setRotation(pvh.isExpanded() ? 180 : 0); } else if (!expandable && arrow.getVisibility() == View.VISIBLE) { arrow.setVisibility(View.GONE); } }
Example 18
Source File: FrameListView.java From PLDroidShortVideo with Apache License 2.0 | 5 votes |
@Override protected void onPostExecute(PLVideoFrame frame) { super.onPostExecute(frame); ImageView mImageView = mImageViewWeakReference.get(); if (mImageView == null) { return; } if (frame != null) { int rotation = frame.getRotation(); Bitmap bitmap = frame.toBitmap(); mImageView.setImageBitmap(bitmap); mImageView.setRotation(rotation); } }
Example 19
Source File: LocationAdapter.java From BackPackTrackII with GNU General Public License v3.0 | 4 votes |
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values final long time = cursor.getLong(colTime); final String provider = cursor.getString(colProvider); final double latitude = cursor.getDouble(colLatitude); final double longitude = cursor.getDouble(colLongitude); final boolean hasAltitude = !cursor.isNull(colAltitude); boolean hasBearing = !cursor.isNull(colBearing); boolean hasAccuracy = !cursor.isNull(colAccuracy); double altitude = cursor.getDouble(colAltitude); double bearing = cursor.getDouble(colBearing); double accuracy = cursor.getDouble(colAccuracy); final String name = cursor.getString(colName); // Calculate distance to last location Location dest = new Location(""); dest.setLatitude(latitude); dest.setLongitude(longitude); double distance = (lastLocation == null ? 0 : lastLocation.distanceTo(dest)); // Get views TextView tvTime = (TextView) view.findViewById(R.id.tvTime); ImageView ivWaypoint = (ImageView) view.findViewById(R.id.ivWaypoint); TextView tvProvider = (TextView) view.findViewById(R.id.tvProvider); TextView tvAltitude = (TextView) view.findViewById(R.id.tvAltitude); ImageView ivBearing = (ImageView) view.findViewById(R.id.ivBearing); TextView tvAccuracy = (TextView) view.findViewById(R.id.tvAccuracy); TextView tvDistance = (TextView) view.findViewById(R.id.tvDistance); // Set values tvTime.setText( new SimpleDateFormat("dd").format(time) + " " + SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT).format(time)); ivWaypoint.setVisibility(name == null ? View.INVISIBLE : View.VISIBLE); int resId = context.getResources().getIdentifier("provider_" + provider, "string", context.getPackageName()); tvProvider.setText(resId == 0 ? "-" : context.getString(resId).substring(0, 1)); tvAltitude.setText(hasAltitude ? Long.toString(Math.round(altitude)) : "?"); if (hasBearing) { ivBearing.setRotation((float) bearing - 90); ivBearing.setVisibility(View.VISIBLE); } else ivBearing.setVisibility(View.INVISIBLE); tvAccuracy.setText(hasAccuracy ? Long.toString(Math.round(accuracy)) : "?"); if (lastLocation != null && distance >= 1e7) tvDistance.setText(Long.toString(Math.round(distance / 1e6)) + "M"); else if (lastLocation != null && distance >= 1e4) tvDistance.setText(Long.toString(Math.round(distance / 1e3)) + "k"); else tvDistance.setText(lastLocation == null ? "?" : Long.toString(Math.round(distance))); }
Example 20
Source File: WeatherAdapter.java From BackPackTrackII with GNU General Public License v3.0 | 4 votes |
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get views TextView tvTime = (TextView) view.findViewById(R.id.tvTime); TextView tvTemperature = (TextView) view.findViewById(R.id.tvTemperature); TextView tvHumidity = (TextView) view.findViewById(R.id.tvHumidity); TextView tvPrecipitation = (TextView) view.findViewById(R.id.tvPrecipitation); TextView tvPrecipitationProbability = (TextView) view.findViewById(R.id.tvPrecipitationProbability); TextView tvWindSpeed = (TextView) view.findViewById(R.id.tvWindSpeed); ImageView ivWindDirection = (ImageView) view.findViewById(R.id.ivWindDirection); TextView tvPressure = (TextView) view.findViewById(R.id.tvPressure); // Time long time = cursor.getLong(colTime); tvTime.setText(SDF.format(time)); // Temperature if (cursor.isNull(colTemperature)) tvTemperature.setText(""); else { float temperature = cursor.getFloat(colTemperature); if ("f".equals(temperature_unit)) temperature = temperature * 9 / 5 + 32; tvTemperature.setText(DF.format(temperature)); } // Humidity if (cursor.isNull(colHumidity)) tvHumidity.setText(""); else { int humidity = Math.round(cursor.getFloat(colHumidity)); if (humidity > 99) humidity = 99; tvHumidity.setText(Long.toString(humidity)); } // Precipitation if (cursor.isNull(colRain1h)) tvPrecipitation.setText(""); else { float rain_1h = cursor.getFloat(colRain1h); if ("in".equals(rain_unit)) { rain_1h = rain_1h / 25.4f; tvPrecipitation.setText(DF2.format(rain_1h)); } else { if (rain_1h < 10) tvPrecipitation.setText(DF.format(rain_1h)); else tvPrecipitation.setText(Integer.toString(Math.round(rain_1h))); } } // Precipitation probability if (cursor.isNull(colRainProbability)) tvPrecipitationProbability.setText(""); else { int probability = Math.round(cursor.getFloat(colRainProbability)); if (probability > 99) probability = 99; tvPrecipitationProbability.setText(Long.toString(probability)); } // Wind speed if (cursor.isNull(colWindSpeed)) tvWindSpeed.setText(""); else { float wind_speed = cursor.getFloat(colWindSpeed); if ("bft".equals(windspeed_unit)) wind_speed = (float) Math.pow(10.0, (Math.log10(wind_speed / 0.836) / 1.5)); else if ("kmh".equals(windspeed_unit)) wind_speed = wind_speed * 3600 / 1000; if ("bft".equals(windspeed_unit)) tvWindSpeed.setText(Long.toString(Math.round(wind_speed))); else tvWindSpeed.setText(DF.format(wind_speed)); } // Wind direction if (cursor.isNull(colWindDirection)) ivWindDirection.setVisibility(View.INVISIBLE); else { float wind_direction = cursor.getFloat(colWindDirection); ivWindDirection.setRotation(wind_direction - 90 + 180); ivWindDirection.setVisibility(View.VISIBLE); } // Pressure if (cursor.isNull(colPressure)) tvPressure.setText(""); else { float pressure = cursor.getFloat(colPressure); if ("mmhg".equals(pressure_unit)) pressure = pressure / 1.33322368f; tvPressure.setText(DF.format(pressure)); } }