1
0
Fork 0

Added negative progress bar for pg

This commit is contained in:
Carlos Galindo 2015-02-27 23:33:10 +01:00
parent 4815aaf12a
commit 381d13c3a0
3 changed files with 58 additions and 10 deletions

View file

@ -92,7 +92,6 @@ public class Introduction extends ActionBarActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
//TODO: fix this
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();

View file

@ -38,6 +38,8 @@ public class MainActivity extends ActionBarActivity{
((ProgressBar) findViewById(R.id.curativeEffortsBar)) ((ProgressBar) findViewById(R.id.curativeEffortsBar))
.getProgressDrawable() .getProgressDrawable()
.setColorFilter(Color.parseColor("#FFD700"), PorterDuff.Mode.SRC_IN); .setColorFilter(Color.parseColor("#FFD700"), PorterDuff.Mode.SRC_IN);
//TODO: use the negative PG bar, not curativeEfforts one
// findViewById(R.id.negCurativeEffortsBar).setRotation(180);
undo = false; undo = false;
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
@ -75,7 +77,6 @@ public class MainActivity extends ActionBarActivity{
} }
return true; return true;
} else if (id == R.id.action_edit_basics) { } else if (id == R.id.action_edit_basics) {
//TODO: try this startChildActivity()
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE); SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
Intent intent = new Intent(this, Introduction.class); Intent intent = new Intent(this, Introduction.class);
startActivity(intent.putExtra( startActivity(intent.putExtra(
@ -257,6 +258,12 @@ public class MainActivity extends ActionBarActivity{
pg.setText( pg.setText(
String.valueOf(player.getPg()) String.valueOf(player.getPg())
); );
incrementProgressBar(
(ProgressBar) findViewById(R.id.pgBar),
(TextView) findViewById(R.id.currentPg),
100, false, 0,
true, player.getPg()
);
//finished correctly, then apply values to undo's //finished correctly, then apply values to undo's
undo = true; undo = true;
undoPreviousValue = preValue; undoPreviousValue = preValue;
@ -362,6 +369,7 @@ public class MainActivity extends ActionBarActivity{
"first_time", "first_time",
!p.getBoolean("saved", false) !p.getBoolean("saved", false)
)); ));
while(!p.getBoolean("saved", false));
} }
if(player == null) { if(player == null) {
player = new Player( player = new Player(
@ -521,7 +529,10 @@ public class MainActivity extends ActionBarActivity{
input.requestFocus(); input.requestFocus();
} }
//TODO: implement level-up animation and expand the max dynamically //TODO: fix the display of maxPg and levelUp
//TODO: use this for px and curativeEfforts
//TODO: set up a partial barCommand to raise only between the ratios, then a manager, then another
//TODO: if pgBar, change color accordingly with the pg
private void incrementProgressBar(final ProgressBar progressBar, final TextView textView, private void incrementProgressBar(final ProgressBar progressBar, final TextView textView,
final int factor, final int factor,
final boolean setMax, int max, final boolean setMax, int max,
@ -531,6 +542,7 @@ public class MainActivity extends ActionBarActivity{
if(progressBar.getProgress() - end*factor == 0) return; if(progressBar.getProgress() - end*factor == 0) return;
final Handler handler = new Handler(); final Handler handler = new Handler();
final int finalEnd = end * factor; final int finalEnd = end * factor;
final boolean negative = finalEnd < 0;
final int time = 2000 / Math.abs(progressBar.getProgress() - finalEnd); final int time = 2000 / Math.abs(progressBar.getProgress() - finalEnd);
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {
@ -539,9 +551,32 @@ public class MainActivity extends ActionBarActivity{
while ((bigger && current < finalEnd) || (!bigger && current > finalEnd)) { while ((bigger && current < finalEnd) || (!bigger && current > finalEnd)) {
if(bigger) current++; if(bigger) current++;
else current--; else current--;
// if(progressBar.getId() == R.id.pgBar) {
// double rate = (double)current / progressBar.getMax() * (negative ? -1:1);
// if (rate <= 0) {
// progressBar.getProgressDrawable()
// .setColorFilter(
// Color.RED,
// PorterDuff.Mode.SRC_IN
// );
// } else if (rate <= 0.5) {
// progressBar.getProgressDrawable()
// .setColorFilter(
// Color.YELLOW,
// PorterDuff.Mode.SRC_IN
// );
// } else {
// progressBar.getProgressDrawable()
// .setColorFilter(
// Color.GREEN,
// PorterDuff.Mode.SRC_IN
// );
// }
// }
// Update the progress bar and display the // Update the progress bar and display the
//current value in the text view //current value in the text view
final int finalCurrent = current; final int finalCurrent = Math.abs(current);
handler.post(new Runnable() { handler.post(new Runnable() {
public void run() { public void run() {
progressBar.setProgress(finalCurrent); progressBar.setProgress(finalCurrent);
@ -549,7 +584,7 @@ public class MainActivity extends ActionBarActivity{
textView.setText( textView.setText(
(finalCurrent + Player.LEVEL_PX[player.getLevel() - 1]) (finalCurrent + Player.LEVEL_PX[player.getLevel() - 1])
+ " / " + + " / " +
(progressBar.getMax() + Player.LEVEL_PX[player.getLevel()]) (progressBar.getMax() + Player.LEVEL_PX[player.getLevel() - 1])
); );
} else { } else {
textView.setText((finalCurrent/factor) +" / "+(progressBar.getMax()/factor)); textView.setText((finalCurrent/factor) +" / "+(progressBar.getMax()/factor));

View file

@ -112,7 +112,6 @@
android:paddingLeft="8dip" android:paddingLeft="8dip"
android:paddingRight="8dip" android:paddingRight="8dip"
android:layout_weight="1"/> android:layout_weight="1"/>
<!--TODO: USE this-->
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -124,11 +123,27 @@
android:layout_weight="1"/> android:layout_weight="1"/>
</LinearLayout> </LinearLayout>
<ProgressBar <LinearLayout
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/pgBar"/> android:orientation="horizontal">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/negCurativeEffortsBar"
android:layout_weight="2"
android:rotation="180"
android:progress="25"/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/pgBar"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -183,7 +198,6 @@
android:paddingLeft="8dip" android:paddingLeft="8dip"
android:paddingRight="8dip" android:paddingRight="8dip"
android:layout_weight="1"/> android:layout_weight="1"/>
<!--TODO: USE this-->
<TextView <TextView
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"