Smoothed progressBar animation
Must be completely corrected
This commit is contained in:
parent
35c8db2c10
commit
99e044dfad
2 changed files with 56 additions and 9 deletions
|
@ -96,7 +96,7 @@ public class Introduction extends ActionBarActivity {
|
||||||
private boolean finished() {
|
private boolean finished() {
|
||||||
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
|
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
|
||||||
SharedPreferences.Editor ed = p.edit();
|
SharedPreferences.Editor ed = p.edit();
|
||||||
String nameString = name.getText().toString();
|
String nameString = name.getText().toString().trim();
|
||||||
int classInt = classSpinner.getSelectedItemPosition();
|
int classInt = classSpinner.getSelectedItemPosition();
|
||||||
int raceInt = raceSpinner.getSelectedItemPosition();
|
int raceInt = raceSpinner.getSelectedItemPosition();
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -19,7 +20,6 @@ import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends ActionBarActivity{
|
public class MainActivity extends ActionBarActivity{
|
||||||
|
|
||||||
public static final int CURRENT_PG = 1, NULL = 0;
|
public static final int CURRENT_PG = 1, NULL = 0;
|
||||||
|
@ -143,8 +143,12 @@ public class MainActivity extends ActionBarActivity{
|
||||||
}
|
}
|
||||||
getSharedPreferences("basics", MODE_PRIVATE)
|
getSharedPreferences("basics", MODE_PRIVATE)
|
||||||
.edit().putInt("px", player.getPx()).apply();
|
.edit().putInt("px", player.getPx()).apply();
|
||||||
((ProgressBar) findViewById(R.id.xpBar))
|
incrementProgressBar(
|
||||||
.setProgress(player.getPx() - Player.LEVEL_PX[player.getLevel() - 1]);
|
(ProgressBar) findViewById(R.id.xpBar),
|
||||||
|
(TextView) findViewById(R.id.currentXp),
|
||||||
|
player.getPx() - Player.LEVEL_PX[player.getLevel() - 1],
|
||||||
|
1
|
||||||
|
);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
getApplicationContext(),
|
getApplicationContext(),
|
||||||
|
@ -198,8 +202,12 @@ public class MainActivity extends ActionBarActivity{
|
||||||
e.putInt("pg", player.getPg());
|
e.putInt("pg", player.getPg());
|
||||||
if(usesEffort) {
|
if(usesEffort) {
|
||||||
e.putInt("curativeEfforts", player.getCurativeEfforts());
|
e.putInt("curativeEfforts", player.getCurativeEfforts());
|
||||||
((ProgressBar) findViewById(R.id.curativeEffortsBar))
|
incrementProgressBar(
|
||||||
.setProgress(player.getCurativeEfforts());
|
(ProgressBar) findViewById(R.id.curativeEffortsBar),
|
||||||
|
(TextView) findViewById(R.id.currentCurativeEfforts),
|
||||||
|
player.getCurativeEfforts(),
|
||||||
|
100
|
||||||
|
);
|
||||||
}
|
}
|
||||||
e.apply();
|
e.apply();
|
||||||
updateCurativeString();
|
updateCurativeString();
|
||||||
|
@ -278,6 +286,12 @@ public class MainActivity extends ActionBarActivity{
|
||||||
int status = player.getState();
|
int status = player.getState();
|
||||||
int lastState = player.getLastState();
|
int lastState = player.getLastState();
|
||||||
ProgressBar pgBar = (ProgressBar) findViewById(R.id.pgBar);
|
ProgressBar pgBar = (ProgressBar) findViewById(R.id.pgBar);
|
||||||
|
incrementProgressBar(
|
||||||
|
pgBar,
|
||||||
|
(TextView) findViewById(R.id.currentPg),
|
||||||
|
Math.abs(player.getPg()),
|
||||||
|
100
|
||||||
|
);
|
||||||
pgBar.setProgress(Math.abs(player.getPg()));
|
pgBar.setProgress(Math.abs(player.getPg()));
|
||||||
Button pg = (Button) findViewById(R.id.pgCurrent);
|
Button pg = (Button) findViewById(R.id.pgCurrent);
|
||||||
pg.setText(String.valueOf(player.getPg()));
|
pg.setText(String.valueOf(player.getPg()));
|
||||||
|
@ -376,7 +390,7 @@ public class MainActivity extends ActionBarActivity{
|
||||||
player.setName(p.getString("playerName", getString(R.string.adventurer_name)));
|
player.setName(p.getString("playerName", getString(R.string.adventurer_name)));
|
||||||
player.setClassInt(p.getInt("classInt", Player.NULL));
|
player.setClassInt(p.getInt("classInt", Player.NULL));
|
||||||
player.setRaceInt(p.getInt("raceInt", Player.NULL));
|
player.setRaceInt(p.getInt("raceInt", Player.NULL));
|
||||||
player.setPx(p.getInt("px", 0));
|
player.setPx(p.getInt("px", player.getPx()));
|
||||||
player.setAtk(new int[]{
|
player.setAtk(new int[]{
|
||||||
p.getInt("fue", 10),
|
p.getInt("fue", 10),
|
||||||
p.getInt("con", 10),
|
p.getInt("con", 10),
|
||||||
|
@ -392,11 +406,11 @@ public class MainActivity extends ActionBarActivity{
|
||||||
}
|
}
|
||||||
player.setCurativeEffort(p.getInt("curativeEfforts", player.getCurativeEfforts()));
|
player.setCurativeEffort(p.getInt("curativeEfforts", player.getCurativeEfforts()));
|
||||||
player.setPg(p.getInt("pg", player.getPg()));
|
player.setPg(p.getInt("pg", player.getPg()));
|
||||||
((ProgressBar) findViewById(R.id.pgBar)).setMax(player.getMaxPg());
|
((ProgressBar) findViewById(R.id.pgBar)).setMax(player.getMaxPg()*100);
|
||||||
((ProgressBar) findViewById(R.id.xpBar))
|
((ProgressBar) findViewById(R.id.xpBar))
|
||||||
.setProgress(player.getPx() - Player.LEVEL_PX[player.getLevel() - 1]);
|
.setProgress(player.getPx() - Player.LEVEL_PX[player.getLevel() - 1]);
|
||||||
ProgressBar curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
|
ProgressBar curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
|
||||||
curativeEffortsBar.setMax(player.getMaxCurativeEfforts());
|
curativeEffortsBar.setMax(player.getMaxCurativeEfforts()*100);
|
||||||
curativeEffortsBar.setProgress(player.getCurativeEfforts());
|
curativeEffortsBar.setProgress(player.getCurativeEfforts());
|
||||||
healthStatusCheck();
|
healthStatusCheck();
|
||||||
updateCurativeString();
|
updateCurativeString();
|
||||||
|
@ -502,6 +516,39 @@ public class MainActivity extends ActionBarActivity{
|
||||||
input.requestFocus();
|
input.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: implement level-up animation and expand the max dynamically
|
||||||
|
private void incrementProgressBar(final ProgressBar progressBar, final TextView textView, final int end, final int factor) {
|
||||||
|
if(progressBar.getProgress() - end == 0) return;
|
||||||
|
final Handler handler = new Handler();
|
||||||
|
final int time = 3000 / Math.abs(progressBar.getProgress() - end);
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
int current = progressBar.getProgress()*factor;
|
||||||
|
boolean bigger = current < end;
|
||||||
|
while ((bigger && current <= end) || (!bigger && current >= end)) {
|
||||||
|
current += bigger ? 1 : -1;
|
||||||
|
// Update the progress bar and display the
|
||||||
|
//current value in the text view
|
||||||
|
final int finalCurrent = current;
|
||||||
|
handler.post(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
progressBar.setProgress(finalCurrent);
|
||||||
|
textView.setText((finalCurrent/factor) +" / "+(progressBar.getMax()/factor));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
// Sleep for 200 milliseconds.
|
||||||
|
//Just to display the progress slowly
|
||||||
|
Thread.sleep(time);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO: show on screen the max pg's
|
//TODO: show on screen the max pg's
|
||||||
//TODO: show in the bars the max and current values
|
//TODO: show in the bars the max and current values
|
||||||
|
|
Reference in a new issue