It works when I convert from Fahrenheit to Celsius but it doesn't work when I try to convert it back from Celsius into Fahrenheit. I've tried for so many times but it still doesn't work for me.
Here's my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.converter_second);
rb_celcius = (RadioButton) findViewById(R.id.radioButton_celcius);
rb_fahrenheit = (RadioButton) findViewById(R.id.radioButton2_fahrenheit);
btn_convert = (Button) findViewById(R.id.button3_convert);
btn_clear = (Button) findViewById(R.id.button5_clear);
edTxt_amount = (EditText) findViewById(R.id.editText_amount);
txtVw_answer = (TextView) findViewById(R.id.textView7_answer);
btn_convert.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
double dblFahrenheit = 0;
double dblCelcius = (5.0 / 9) * (dblFahrenheit - 32);
double dblConvertedTemp = 0;
double dblFahConversion;
if (v == btn_convert) {
if (rb_celcius.isChecked()) {
String strFah = edTxt_amount.getText().toString();
if (!strFah.isEmpty()) {
{
dblFahrenheit = Double.parseDouble(strFah);
}
if (dblFahrenheit <= 212) {
dblConvertedTemp = (5.0 / 9.0) * (dblFahrenheit - 32);
txtVw_answer.setText("The answer is " + dblConvertedTemp);
} if (rb_fahrenheit.isChecked()) {
String strCel = edTxt_amount.getText().toString();
if (!strCel.isEmpty()) {
{
dblCelcius = Double.parseDouble(strCel);
}
if (dblCelcius <= 100) {
dblFahConversion = dblCelcius * (9.0 / 5.0) + 32;
txtVw_answer.setText("The answer is" + dblFahConversion);
}
}
else if (v == btn_clear){
rg_group.clearCheck();
txtVw_answer.setText("");
}
}
}
}
}
}
});
}
}
I can't say if the logic is correct, but from what I see, the braces are all wrong. This is also not the best way of writing this solution, I will leave that to you.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.converter_second);
rb_celcius = (RadioButton) findViewById(R.id.radioButton_celcius);
rb_fahrenheit = (RadioButton) findViewById(R.id.radioButton2_fahrenheit);
btn_convert = (Button) findViewById(R.id.button3_convert);
btn_clear = (Button) findViewById(R.id.button5_clear);
edTxt_amount = (EditText) findViewById(R.id.editText_amount);
txtVw_answer = (TextView) findViewById(R.id.textView7_answer);
btn_convert.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
double dblFahrenheit = 0;
double dblCelcius = (5.0 / 9) * (dblFahrenheit - 32);
double dblConvertedTemp = 0;
double dblFahConversion;
if (v == btn_convert) {
if (rb_celcius.isChecked()) {
String strFah = edTxt_amount.getText().toString();
if (!strFah.isEmpty()) {
dblFahrenheit = Double.parseDouble(strFah);
}
if (dblFahrenheit <= 212) {
dblConvertedTemp = (5.0 / 9.0) * (dblFahrenheit - 32);
txtVw_answer.setText("The answer is " + dblConvertedTemp);
}
}
if (rb_fahrenheit.isChecked()) {
String strCel = edTxt_amount.getText().toString();
if (!strCel.isEmpty()) {
dblCelcius = Double.parseDouble(strCel);
}
if (dblCelcius <= 100) {
dblFahConversion = dblCelcius * (9.0 / 5.0) + 32;
txtVw_answer.setText("The answer is" + dblFahConversion);
} else if (v == btn_clear){
rg_group.clearCheck();
txtVw_answer.setText("");
}
}
}
}
}
});
}
Your indentation and use of braces makes it quite hard to see the problem. If I fix the indentation, I get the following code:
public void onClick(View v) {
double dblFahrenheit = 0;
double dblCelcius = (5.0 / 9) * (dblFahrenheit - 32);
double dblConvertedTemp = 0;
double dblFahConversion;
if (v == btn_convert) {
if (rb_celcius.isChecked()) {
String strFah = edTxt_amount.getText().toString();
if (!strFah.isEmpty()) {
{
dblFahrenheit = Double.parseDouble(strFah);
}
if (dblFahrenheit <= 212) {
dblConvertedTemp = (5.0 / 9.0) * (dblFahrenheit - 32);
txtVw_answer.setText("The answer is " + dblConvertedTemp);
}
if (rb_fahrenheit.isChecked()) {
String strCel = edTxt_amount.getText().toString();
if (!strCel.isEmpty()) {
{
dblCelcius = Double.parseDouble(strCel);
}
if (dblCelcius <= 100) {
dblFahConversion = dblCelcius * (9.0 / 5.0) + 32;
txtVw_answer.setText("The answer is" + dblFahConversion);
}
}
else if (v == btn_clear){
rg_group.clearCheck();
txtVw_answer.setText("");
}
}
}
}
}
}
I think it does not work because you check if rb_fahrenheit is checked within the if block that is executed when rb_celcius is checked. Given the fact that these views are radiobuttons, I assume that they reside in the same RadioGroup in which case both radiobuttons have to be checked. This is impossible for a RadioGroup. This explains why the other way around does not work. From the looks of it, the code itself should work.
Related
i have created a survey layout with a question and then you can select below avg, avg or above avg. a score is at the bottom of the page and it updates on click via listener.
I have a problem with the customer changing their answer and it not removing the pervious value.
so below is 1 and avg is 2 and above is 3. if you click above it adds 3 and then you change your mind and want to pick avg and you click it and it adds 2 but never removes then pervious 3.
help
below32 = (CheckBox) findViewById(R.id.below32);
below32.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (below32.isChecked()) {
sum += 1; double total = 100*sum/69;
result.setText(String.format("%.1f", total) + "%");
avg32.setChecked(false);
above32.setChecked(false);
}
else {
sum -= 1; double total = 100*sum/69;
result.setText(String.format("%.1f", total) + "%");
}
}
});
avg32 = (CheckBox) findViewById(R.id.avg32);
avg32.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (avg32.isChecked()) {
sum += 2; double total = 100*sum/69;
result.setText(String.format("%.1f", total) + "%");
below32.setChecked(false);
above32.setChecked(false);
}
else {
sum -= 2; double total = 100*sum/69;
result.setText(String.format("%.1f", total) + "%");
}
}
});
above32 = (CheckBox) findViewById(R.id.above32);
above32.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (above32.isChecked()) {
sum += 3; double total = 100*sum/69;
result.setText(String.format("%.1f", total) + "%");
below32.setChecked(false);
avg32.setChecked(false);
}
else {
sum -= 3; double total = 100*sum/69;
result.setText(String.format("%.1f", total) + "%");
}
}
});
what do i need to change or do to make it work? all other attempts have failed.
I am trying to simulate a buoyant force behavior on a 2D object of an Android application, there is no friction involved. Something is not working correctly: the height of the "bounce" changes in an irregular manner, I think the error should be in the update of the speed but I'm not sure.
Can anyone see the error in my code?
public class MainActivity extends Activity {
Semaphore moveSemaphore = new Semaphore(1);
static WindowManager.LayoutParams params;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
params = new WindowManager.LayoutParams( 80, 80,
WindowManager.LayoutParams.TYPE_APPLICATION,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSPARENT);
final BallView ball = new BallView(this);
addContentView(ball, params);
ball.setX(100);
ball.setY(50);
final Thread move = new Thread(new Runnable(){
double speed = 0;
double G = 9;
double fullBuoyancy = -G * 10;
double prevtime = System.currentTimeMillis();
double elapsed;
double fluidstart = 300;
double objectHeight = 100;
double currPosy = 50;
double p;
#Override
public void run() {
while(true){
try {
moveSemaphore.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
#Override
public void run() {
double currDepth = 0;
long currtime = System.currentTimeMillis();
elapsed = (currtime - prevtime) * 0.01;
prevtime = currtime;
currPosy = ball.getY();
// COMPUTE HOW MUCH OF THE BALL IS INSIDE OF THE FLUID
if (currPosy > (fluidstart + objectHeight/2)){
currDepth = objectHeight;
} else if (currPosy > (fluidstart - objectHeight/2)) {
currDepth = currPosy - fluidstart;
}
p = currDepth / objectHeight; // PERCENTAGE OF THE FULL BUOYANT FORCE TO BE APPLIED
speed = speed + (G + fullBuoyancy * p) * elapsed;
currPosy += speed * elapsed;
ball.setY((float)currPosy);
moveSemaphore.release();
}
});
}
}
});
move.start();
}
}
The problem was in the if-statement, this is the correct solution:
if (currPosy > (fluidstart + objectHeight/2)){//complete submersion
currDepth = objectHeight;
} else if (currPosy > (fluidstart - objectHeight/2)) {//partial submersion
currDepth = (currPosy + objectHeight/2) - fluidstart;
}
The if-statement logic is incorrect.
double emerge = fluidstart - (currPosy - (objectHeight / 2));
if (emerge <= 0) { // complete submersion
currDepth = objectHeight;
} else {
currDepth = objectHeight - emerge;
}
I have 2 Edittext which only accepts numbers.
I want to make sure that the fields are not empty before the submit button is pressed to stop the application from crashing.
These are the 2 edittext fields i have.
EditText weightText = (EditText)findViewById(R.id.WeightText);
EditText heightText = (EditText)findViewById(R.id.Heighttext);
Code:
public class BMI extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bmi);
}
public void calculateHandler(View view) {
// make sure we handle the click of the calculator button
if (view.getId() == R.id.calculate) {
// get the references to the widgets
EditText weightText = (EditText)findViewById(R.id.WeightText);
EditText heightText = (EditText)findViewById(R.id.Heighttext);
TextView resultText = (TextView)findViewById(R.id.resultLabel);
// get the users values from the widget references
float weight = Float.parseFloat(weightText.getText().toString());
float height = Float.parseFloat(heightText.getText().toString());
// calculate the bmi value
float bmiValue = calculateBMI(weight, height);
// interpret the meaning of the bmi value
String bmiInterpretation = interpretBMI(bmiValue);
// now set the value in the result text
resultText.setText(bmiValue + " = " + bmiInterpretation);
}
}
private float calculateBMI (float weight, float height) {
return (float)Math.round((weight / (height * height)) * 100) / 100 ;
}
// interpret what BMI means
private String interpretBMI(float bmiValue) {
if (bmiValue < 16) {
return "Severely underweight";
} else if (bmiValue < 18.5) {
return "Underweight";
} else if (bmiValue < 25) {
return "Normal";
} else if (bmiValue < 30) {
return "Overweight";
} else {
return "Obese";
}
}
}
You can check that your EditTexts are not empty like below:
weightText.getText().length() != 0 && heightText.getText().length() != 0
And you can use this condition inside the onClick(View) method, which is called when your button is clicked like below:
yourButton.setOnClickListener( new OnClickListener(){
public void onClick(){
if(weightText.getText().length() != 0 && heightText.getText().length() != 0){
//do sth
}
});
The second way, you can create TextWatcher which set to both EditTexts and in onTextChanged() you can check that both EditTexts are not empty like below:
private class YourTextWatcher implements TextWatcher{
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
yourButton.setEnabled(weightText.getText().length() != 0 && heightText.getText().length() != 0)
}
#Override
public void afterTextChanged(Editable editable) {
}
}
you can set this TextWatcher for your EditText like below:
weightText.addTextChangedListener(new YourTextWatcher());
heightText.addTextChangedListener(new YourTextWatcher());
Here is code that your Activity should look like:
public class BMI extends Activity {
EditText weightText;
EditText heightText;
TextView resultText;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bmi);
weightText = (EditText) findViewById(R.id.WeightText);
heightText = (EditText) findViewById(R.id.Heighttext);
resultText = (TextView) findViewById(R.id.resultLabel);
Button button = (Button) findViewById(R.id.calulate);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
calculateHandler();
}
});
}
public void calculateHandler() {
// make sure we handle the click of the calculator button
if (weightText.getText().length() == 0 || heightText.getText().length() == 0) {
return;
}
// get the users values from the widget references
float weight = Float.parseFloat(weightText.getText().toString());
float height = Float.parseFloat(heightText.getText().toString());
// calculate the bmi value
float bmiValue = calculateBMI(weight, height);
// interpret the meaning of the bmi value
String bmiInterpretation = interpretBMI(bmiValue);
// now set the value in the result text
resultText.setText(bmiValue + " = " + bmiInterpretation);
// display toast additionally to example
Toast.makeText(this, bmiValue + " = " + bmiInterpretation, Toast.LENGTH_LONG).show();
}
private float calculateBMI(float weight, float height) {
return (float) Math.round((weight / (height * height)) * 100) / 100;
}
// interpret what BMI means
private String interpretBMI(float bmiValue) {
if (bmiValue < 16) {
return "Severely underweight";
} else if (bmiValue < 18.5) {
return "Underweight";
} else if (bmiValue < 25) {
return "Normal";
} else if (bmiValue < 30) {
return "Overweight";
} else {
return "Obese";
}
}
}
Calculate method
public void calculateHandler() {
// make sure we handle the click of the calculator button
if (weightText.getText().toString().trim().length() == 0 || heightText.getText().toString().trim().length() == 0) {
Toast.makeText(this, "Please fill all field by numbers", Toast.LENGTH_LONG).show();
return;
}
// get the users values from the widget references
float weight = Float.parseFloat(weightText.getText().toString());
float height = Float.parseFloat(heightText.getText().toString());
// calculate the bmi value
float bmiValue = calculateBMI(weight, height);
// interpret the meaning of the bmi value
String bmiInterpretation = interpretBMI(bmiValue);
// now set the value in the result text
resultText.setText(bmiValue + " = " + bmiInterpretation);
// display toast additionally to example
}
weightText.getText().toString().isEmpty();
try like this..
String weight = weightText.getText().toString();
String height = heightText.getText().toString();
if((Integer.parseInt(weight)!=null) && (Integer.parseInt(height)!=null)){
//Not an empty
}
else{
//empty
}
I have the following code and i need to change a little bit the procedure. As it is it works and when i press b1 button returns me on text field et3 a calculation of 3 other text fields. I need to return the calculation on text field et3 without pressing the button. I think i need to add a watcher on text field et4 and when this is not empty then to return me the calculation on et3. The code is this
package com.example.b15_calc;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText et1, et2, et3, et4;
Button b1, b2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1 = (EditText) findViewById(R.id.editText1);
et2 = (EditText) findViewById(R.id.editText2);
et3 = (EditText) findViewById(R.id.editText3);
et4 = (EditText) findViewById(R.id.editText4);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
//step3 : write add functionality.
b2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
et1.setText("");
et2.setText("");
et3.setText("");
et4.setText("");
}
});
//step3 : ΜΕΤΑΒΛΗΤΕΣ
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String f = et1.getText().toString();
double i = Double.parseDouble(f);
String s = et2.getText().toString();
double j = Double.parseDouble(s);
String w = et4.getText().toString();
double q = Double.parseDouble(w);
double price_gold = 10;
double fpa = 1.23;
double fpol = 0.10;
double fpolam = 999;
double isot = 100;
double sint_ker = 10;
double result1 = (i * price_gold) + (j * 1000) + (q * isot);
double result2 = result1 / 340.75;
int gap;
if (result2 >= fpolam){
double result = (result2 * fpol);
double result3 = ((result2 * sint_ker) * fpa) + result;
if(result3 < 1000)
{
gap = 10;
}
else if(result3 < 5000)
{
gap = 50;
}
else //5000+
{
gap = 100;
}
int total = (int) Math.ceil(result3 / gap) * gap;
String res = String.valueOf(total);
et3.setText(res);
} else{
double result3 = ((result2 * sint_ker) * fpa);
if(result3 < 1000)
{
gap = 10;
}
else if(result3 < 5000)
{
gap = 50;
}
else //5000+
{
gap = 100;
}
int total = (int) Math.ceil(result3 / gap) * gap;
String res = String.valueOf(total);
et3.setText(res);
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
You can use TextWatcher
et4.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
// make the calculation here and set the result to et3
String f = et1.getText().toString();
double i = Double.parseDouble(f);
String s = et2.getText().toString();
double j = Double.parseDouble(s);
String w = s.toString();
double q = Double.parseDouble(w);
double price_gold = 10;
double fpa = 1.23;
double fpol = 0.10;
double fpolam = 999;
double isot = 100;
double sint_ker = 10;
double result1 = (i * price_gold) + (j * 1000) + (q * isot);
double result2 = result1 / 340.75;
int gap;
if (result2 >= fpolam){
double result = (result2 * fpol);
double result3 = ((result2 * sint_ker) * fpa) + result;
if(result3 < 1000)
{
gap = 10;
}
else if(result3 < 5000)
{
gap = 50;
}
else //5000+
{
gap = 100;
}
int total = (int) Math.ceil(result3 / gap) * gap;
String res = String.valueOf(total);
et3.setText(res);
} else{
double result3 = ((result2 * sint_ker) * fpa);
if(result3 < 1000)
{
gap = 10;
}
else if(result3 < 5000)
{
gap = 50;
}
else //5000+
{
gap = 100;
}
int total = (int) Math.ceil(result3 / gap) * gap;
String res = String.valueOf(total);
et3.setText(res);
}
}
});
I need to move circles along a circular path for that i am using Object Animator and Path evaluator.All the information is dynamic means it is changing when i receive response so that total number of circles can be changed at runtime.Here is the 1 part of method where all circles are positioning themselves according to their position on screen that is if user release the touch then this method gets called -:
public void slideDownSetToCenter() {
for (int i = 0; i < leftCurrentRunningAnimation.length; i++) {
Logger.i(TAG, "in slide down animation");
if (leftReadyToMove[i]) {
if (leftUpQueue.contains(i)) {
leftUpQueue.remove(i);
}
leftAngle = leftSlice * ++leftAllCirclesAngles[i];
Logger.i("circle leftAngle points of curve down", String.valueOf(leftAllCirclesAngles[i]));
if (leftAngle > leftAngleTop) {
if (i < leftCurrentRunningAnimation.length - 1) {
leftReadyToMove[i + 1] = true; // set next circle to
// move
}
}
Arrays.fill(leftCurrentRunningAnimation, false);
leftCurrentRunningAnimation[i] = true;
Logger.i(TAG, "leftAngle" + leftAngle);
if (leftReadyToMove[i] == true && leftAngle == leftAngleDownOut) {
leftReadyToMove[i] = false;
leftDownStack.add(i);
}
xPosition = (int) (leftCircleCenterX + leftCircleX * Math.cos(leftAngle));
yPosition = (int) (leftCircleCenterY + leftCircleY * Math.sin(leftAngle));
Path = new AnimatorPath();
Path.moveTo(xPosition, yPosition);
Path.lineTo(xPosition, yPosition);
while (true) {
if (leftAngle == leftAngleDownOut) {
break;
}
leftAngle = leftSlice * ++leftAllCirclesAngles[i];
xPosition = (int) (leftCircleCenterX + leftCircleX * Math.cos(leftAngle));
yPosition = (int) (leftCircleCenterY + leftCircleY * Math.sin(leftAngle));
Path.lineTo(xPosition, yPosition);
Logger.i(TAG, "path.........");
}
slideCircleAnimator = ObjectAnimator.ofObject(DynamicCircleSwipeAnimation.this, "leftButtonLocationDynamic", new PathEvaluator(), Path.getPoints().toArray());
slideCircleAnimator.setInterpolator(linearInterpolator);
slideCircleAnimator.setDuration(500);
context.runOnUiThread(new Runnable() {
#Override
public void run() {
slideCircleAnimator.start();
}
});
}
break;
}
}
Here is the Object animator's animation method -:
public void setLeftButtonLocationDynamic(final PathPoint newLoc) {
for (int i = 0; i < leftCurrentRunningAnimation.length; i++) {
if (leftCurrentRunningAnimation[i] == true) {
Logger.i("current button id", String.valueOf(i));
leftArrayOfButtons[i].setTranslationX(newLoc.mX);
leftArrayOfButtons[i].setTranslationY(newLoc.mY);
break;
}
}
}
Here my animation is not happening in correct way that' why i need to pass my view reference from Object.OfObject() method so that i can get it in setLeftButtonLocationDynamic(final PathPoint newLoc,View v).Is anyone has any idea how can i do this?I searched a lot and tried to develop custom class of ObjectAnimator,ValueAnimator and ProperyViewHolder classes but when i copied it from google open source then i get errors in that.Any help is appreciable?
Here to achieve this i changed the approach to move all circles.Previously, i was using ObjectAnimator to move circles one by one and now i am using Animator set for x position and y position.I play both animation together.
Here is the example -:
public void SlideDownFromRightAnimation() {
int rightArrayOfButtonsLength = rightArrayOfButtons.length;
Logger.i(TAG, "queue " + rightUpQueue.size() + "= stack " + rightDownStack.size());
if (rightUpQueue.size() == rtNumberOfButtons) {
Arrays.fill(rightReadyToMove, false);
rightReadyToMove[0] = true;
rightUpQueue.poll();
} else if (rightDownStack.size() == rtNumberOfButtons) {
rightUpQueue.clear();
for (int i = 0; i < rightArrayOfButtonsLength; i++) {
rightUpQueue.add(rightDownStack.pop());
rightAllCirclesAngles[i] = rightCircleUpOutPosition;
}
Arrays.fill(rightReadyToMove, false);
rightReadyToMove[0] = true;
}
for (int i = 0; i < rightArrayOfButtonsLength; i++) {
Logger.i(TAG, "in slide down animation");
if (rightReadyToMove[i]) {
if (rightUpQueue.contains(rightArrayOfButtons[i].getTag())) {
rightUpQueue.remove(i);
}
rightAngle = rightSlice * --rightAllCirclesAngles[i];
Logger.i("circle rightAngle points of curve down", String.valueOf(rightAllCirclesAngles[i]));
if (rightAngle <= rightAngleTop) {
if (i < rightArrayOfButtonsLength - 1) {
rightReadyToMove[i + 1] = true; // set next circle to
// move
}
}
Logger.i(TAG, "rightAngle" + rightAngle);
if (rightAngle <= rightAngleDownOut) {
rightReadyToMove[i] = false;
rightDownStack.add((Integer)rightArrayOfButtons[i].getTag());
rightAllCirclesAngles[i] = rightCircleDownOutPosition;
rightStartAnimation(rightAngle, null, i);
} else {
double rightAngleNext = rightSlice * rightAllCirclesAngles[i];
if (rightAngleNext <= rightAngleDownOut) {
rightReadyToMove[i] = false;
rightDownStack.add((Integer)rightArrayOfButtons[i].getTag());
}
rightStartAnimation(rightAngle, rightAngleNext, i);
}
}
}
}
and here is the right wheels animation function -:
public void rightStartAnimation(Double rightAngle, Double rightAngleNext, int bttnId) {
xPosition = (int) (rightCircleCenterX + rightCircleX * Math.cos(rightAngle));
yPosition = (int) (rightCircleCenterY + rightCircleY * Math.sin(rightAngle));
if (rightAngleNext != null) {
xPosition = (int) (rightCircleCenterX + rightCircleX * Math.cos(rightAngleNext));
yPosition = (int) (rightCircleCenterY + rightCircleY * Math.sin(rightAngleNext));
}
final ObjectAnimator animation1 = ObjectAnimator.ofFloat(rightArrayOfButtons[bttnId], "x", rightArrayOfButtons[bttnId].getX(), xPosition);
animation1.setDuration(0);
animation1.setInterpolator(linearInterpolator);
final ObjectAnimator animation2 = ObjectAnimator.ofFloat(rightArrayOfButtons[bttnId], "y", rightArrayOfButtons[bttnId].getY(), yPosition);
animation2.setDuration(0);
animation2.setInterpolator(linearInterpolator);
final AnimatorSet set = new AnimatorSet();
set.setInterpolator(linearInterpolator);
context.runOnUiThread(new Runnable() {
#Override
public void run() {
set.playTogether(animation1, animation2);
set.start();
}
});
}