I'll start with an example
ImageButton {
defaultImageSource: "asset:///images/test_p.png"
pressedImageSource: "asset:///images/test_p_pressed.png"
attachedObjects: [
OrientationHandler { //gives "orientation"
onOrientationAboutToChange: {
if (orientation == UIOrientation.Landscape) {
defaultImageSource = "asset:///images/test_l.png"
pressedImageSource = "asset:///images/test_l_pressed.png"
} else {
defaultImageSource = "asset:///images/test_p.png"
pressedImageSource = "asset:///images/test_p_pressed.png"
}
}
}
]
}
Screen rotation works just fine, when it's landscape it uses _l, when it's portrait it uses _p image. The problem is, when I start app in landscape, it will show _p, not _l image (because it's default). How do I check orientation in onCreationCompleted?
I figured it out, it's an obvious one really. You put id to your OrientationHandler, and then you use it in onCreationCompleted.
ImageButton {
defaultImageSource: "asset:///images/test_p.png" //do I still need this?
pressedImageSource: "asset:///images/test_p_pressed.png"
attachedObjects: [
OrientationHandler { //gives "orientation"
id: orientationHandler //make id so you can call it
onOrientationAboutToChange: {
changeImages(orientation);
}
}
]
function changeImages(orientation){
if (orientation == UIOrientation.Landscape) {
defaultImageSource = "asset:///images/test_l.png"
pressedImageSource = "asset:///images/test_l_pressed.png"
} else {
defaultImageSource = "asset:///images/test_p.png"
pressedImageSource = "asset:///images/test_p_pressed.png"
}
}
onCreationCompleted: {
changeImages(orientationHandler.orientation); //call it here
}
}
Related
While scrolling moveable columns cell renderer is getting re-initialized due to which the value in ag grid are getting reset. I need solution for this as I am not able to save row data as values gets reset on scrolling.
agInit(params): void {
this.params = params.data;
this.rowIndex = params.rowIndex;
this.selectedReason = params.data;
if (this.params.proposedCompletionDateInFormat) {
this.calender.selectedDateTime.startDate = new Date(params.data.proposedCompletionDateInFormat);
} else {
this.calender.selectedDateTime = null;
}
if(params.data.taskProgressState === "COMPLETED") {
this.disableField = true;
} else {
this.disableField = false;
}
}
refresh(params?: any): boolean {
this.formGroup = params.context.formGroup;
return true;
}
}
add
[suppressColumnVirtualisation]="true" flag
I have a Kotlin jetpack composable box item that I set to be able to click and drag. It outputs all the real time coordinates of the box, but is there a way to output only the last value the moment I lift my fingers and dropping the box?
#Composable
fun createDragImage(){
MaterialTheme{
val count = remember { mutableStateOf(0) }
val context = LocalContext.current
Row(
modifier = Modifier
.padding(20.dp)
.border(border = BorderStroke(width = 1.dp, color = Color.Red)),
verticalAlignment = Alignment.CenterVertically,
) {
Box() {
var offsetX by remember { mutableStateOf(0f) }
var offsetY by remember { mutableStateOf(0f) }
Box(
Modifier
.offset { IntOffset(offsetX.roundToInt(), offsetY.roundToInt()) }
.background(Color.Transparent)
.size(150.dp)
.border(BorderStroke(4.dp, SolidColor(Color.Red)))
.pointerInput(Unit) {
detectDragGestures { change, dragAmount ->
change.consumeAllChanges()
offsetX = box1.toFloat()
offsetY += dragAmount.y
}
}
)
}
You can use the onDragEnd parameter.
Something like:
var offsetX by remember { mutableStateOf(0f) }
var offsetY by remember { mutableStateOf(0f) }
var offsetDraggingX by remember { mutableStateOf(0f) }
var offsetDraggingY by remember { mutableStateOf(0f) }
Box(
Modifier
.offset { IntOffset(offsetX.roundToInt(), offsetY.roundToInt()) }
.pointerInput(Unit) {
detectDragGestures(
onDragEnd = {
offsetX = offsetDraggingX
offsetY = offsetDraggingY
}
) { change, dragAmount ->
//change.consumeAllChanges()
offsetDraggingX += dragAmount.x
offsetDraggingY += dragAmount.y
}
}
)
I want to render this card and the first time it's loaded, the animation start once. What I want is the default there is no animation happen. Does anyone know how to make this happen?
class Card extends AnimationComponent {
Card(width, height)
: super.sequenced(width, height, 'card.png', 5,
textureWidth: 144.0, textureHeight: 220.0, loop: false);
}
class GameScreen extends BaseGame {
GameScreen({#required this.size}) {
add(Card(0,0));
}
}
According to the source code, you'll able to use Animation to control the frame.
For simple, just don't call update and keep rendering, the frame index will not be updated.
void update(double dt) {
clock += dt;
elapsed += dt;
if (isSingleFrame) {
return;
}
if (!loop && isLastFrame) {
onCompleteAnimation?.call();
return;
}
while (clock > currentFrame.stepTime) {
if (!isLastFrame) {
clock -= currentFrame.stepTime;
currentIndex++;
} else if (loop) {
clock -= currentFrame.stepTime;
currentIndex = 0;
} else {
break;
}
}
}
So you could just override the update method to get the controll of sprite animations.
Can I somehow find out is it the first frame the user click on rotater, last frame or middle?
Handles.RotationHandle(...)
or
Handles.PositionHandle(...)
I need to know when the user start rotating/moving and when stop it.
Then you just need to add a variable to save the state. Something like this:
bool rotating;
void Update () {
if (rotating != Handles.RotationHandle(..)) {
rotating = !rotating;
if (rotating) {
//start rotation
} else {
//just stopped
}
} else if (rotating) {
//in rotating
}
}
i have a image view and i need to rotate(with IOS like animation) the image view on orientation change in android(portrait,landscape,reverse portrait and reverse landscape).
please advice
void rotateAndSet(int angle) {
if (currentAngle != angle || currentImage != currentBaseImage) { // This
// is
// to
// remove
// unnecessary
// drawing
currentAngle = angle;
currentImage = currentBaseImage;
myImg = decodeBase64(currentBaseImage);
matrix = new Matrix();
matrix.postRotate(angle);
Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(),
myImg.getHeight(), matrix, true);
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
param.addRule(RelativeLayout.ALIGN_PARENT_TOP);
/*RotateAnimation animation = new RotateAnimation(0, 90,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setInterpolator(new LinearInterpolator());
animation.setFillAfter(true);
animation.setDuration(800);
ivFullScreen.startAnimation(animation); */
ivFullScreen.setLayoutParams(param);
ivFullScreen.setImageBitmap(rotated);
}
}
i got it
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
RotateAnimation animation = null;
if (event.values[0] < 4 && event.values[0] > -4) {
if (event.values[1] > 0 && orientation != ExifInterface.ORIENTATION_ROTATE_90) {
// UP
orientation = ExifInterface.ORIENTATION_ROTATE_90;
Log.i("testme","up");
animation = getRotateAnimation(0);
degrees = 0;
} else if (event.values[1] < 0 && orientation != ExifInterface.ORIENTATION_ROTATE_270) {
// UP SIDE DOWN
Log.i("testme","up side down");
orientation = ExifInterface.ORIENTATION_ROTATE_270;
animation = getRotateAnimation(180);
degrees = 180;
}
} else if (event.values[1] < 4 && event.values[1] > -4) {
if (event.values[0] > 0 && orientation != ExifInterface.ORIENTATION_NORMAL) {
// LEFT
Log.i("testme","left");
orientation = ExifInterface.ORIENTATION_NORMAL;
animation = getRotateAnimation(-270);
degrees =-270;
} else if (event.values[0] < 0 && orientation != ExifInterface.ORIENTATION_ROTATE_180) {
// RIGHT
Log.i("testme","right");
orientation = ExifInterface.ORIENTATION_ROTATE_180;
animation = getRotateAnimation(270);
degrees = 270;
}
}
if (animation != null) {
ivFullScreen.startAnimation(animation);
}
}
}
}