1
0
Fork 0

Better colors display, edition and deletion

This commit is contained in:
Carlos Galindo 2015-04-23 19:25:35 +02:00
parent 2fc2ff61ba
commit 943d98f867
11 changed files with 191 additions and 115 deletions

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -36,6 +37,8 @@ class AttackAdapter extends ArrayAdapter<Power> {
((TextView) mView.findViewById(R.id.keywords)).setText(attack.getKeywords());
((TextView) mView.findViewById(R.id.frequency)).setText(attack.getFrequencyString());
((TextView) mView.findViewById(R.id.extra)).setText(attack.getRangeString() + " " + attack.getDistance());
mView.setBackgroundColor(attack.getFreqColor(getContext()));
mView.getBackground().setAlpha((position % 2) * 127 + 128);
}
return mView;
}

View file

@ -1,5 +1,6 @@
package com.kauron.dungeonmanager;
import android.content.Context;
import android.content.SharedPreferences;
import java.io.Serializable;
@ -236,4 +237,15 @@ class Player implements Serializable {
static int getModifier(int i) {
return i / 2 - 5;
}
int getStatusColor(Context context) {
if (pg > maxPg / 2)
return context.getResources().getColor(R.color.green);
else if (pg > 0)
return context.getResources().getColor(R.color.yellow);
else if (pg > - maxPg / 2)
return context.getResources().getColor(R.color.red);
else
return context.getResources().getColor(R.color.black);
}
}

View file

@ -42,16 +42,9 @@ class PlayerAdapter extends ArrayAdapter<Player> {
neg.setProgress(pg < 0 ? -pg : 0);
pos.setProgress(pg > 0 ? pg : 0);
int c;
if ( pg <= 0 )
c = getContext().getResources().getColor(R.color.red);
else if ( pg <= maxPg / 2 )
c = getContext().getResources().getColor(R.color.yellow);
else
c = getContext().getResources().getColor(R.color.green);
neg.getProgressDrawable().setColorFilter(c, PorterDuff.Mode.SRC_IN);
pos.getProgressDrawable().setColorFilter(c, PorterDuff.Mode.SRC_IN);
int color = player.getStatusColor(getContext());
neg.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
pos.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
return mView;

View file

@ -136,7 +136,8 @@ public class PlayerEditor extends ActionBarActivity {
int i = p.getInt("players", 0);
String saveName = nameString;
for (int j = 0; j < i; j++) {
saveName += p.getString("player" + j, "").equals(saveName) ? "2" : "";
if (p.getString("player" + j, "").equals(saveName))
saveName += "2";
}
p.edit().putString("player" + i, saveName).putInt("players", i + 1).apply();
SharedPreferences.Editor ed = getSharedPreferences(saveName, MODE_PRIVATE).edit();

View file

@ -1,5 +1,6 @@
package com.kauron.dungeonmanager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
@ -77,4 +78,17 @@ class Power implements Serializable{
void recover(int type){
if(this.freq <= type) used = false;
}
int getFreqColor(Context context) {
switch (freq) {
case DIARIO:
return context.getResources().getColor(R.color.daily);
case ENCUENTRO:
return context.getResources().getColor(R.color.encounter);
case A_VOLUNTAD:
return context.getResources().getColor(R.color.at_will);
default:
return context.getResources().getColor(R.color.green); //TODO: find other color
}
}
}

View file

@ -1,6 +1,7 @@
package com.kauron.dungeonmanager;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
@ -20,13 +21,19 @@ public class PowerEditor extends ActionBarActivity {
private String[] strings = new String[5];
private int[] ints = new int[5];
private String originalName;
private int power;
private SharedPreferences p;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_power_editor);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
power = getIntent().getIntExtra("power", -1);
p = getSharedPreferences(getIntent().getStringExtra("player"), MODE_PRIVATE);
//EditText
edits[0] = (EditText) findViewById(R.id.nameEdit);
@ -78,6 +85,16 @@ public class PowerEditor extends ActionBarActivity {
)
);
if (power != -1) {
SharedPreferences pp = getSharedPreferences(p.getString("power" + power, ""), MODE_PRIVATE);
for ( int i = 0; i < spinners.length; i++ )
spinners[i].setSelection(pp.getInt("i" + i, 0));
for ( int i = 0; i < edits.length; i++ )
edits[i].setText(pp.getString("s" + i, ""));
originalName = edits[0].getText().toString();
}
}
@ -85,42 +102,45 @@ public class PowerEditor extends ActionBarActivity {
//TODO: change strings per resources
boolean readyToSave = true;
for ( int i = 0; i < edits.length; i++ )
if ( edits[i].getText().toString().trim().length() == 0 ) {
for ( int i = 0; i < edits.length; i++ ) {
String s = edits[i].getText().toString().trim();
if (s.length() == 0) {
edits[i].setError("This field is required");
readyToSave = false;
} else {
strings[i] = edits[i].getText().toString().trim();
strings[i] = s;
}
}
for ( int i = 0; i < spinners.length; i++)
if ( spinners[i].getSelectedItemPosition() == 0 ) {
for ( int i = 0; i < spinners.length; i++) {
int n = spinners[i].getSelectedItemPosition();
if ( n == 0) {
spinners[i].setBackgroundColor(getResources().getColor(R.color.red));
readyToSave = false;
//TODO: remove the color when the user has made a choice
} else {
ints[i] = spinners[i].getSelectedItemPosition();
spinners[i].setBackgroundColor(getResources().getColor(R.color.green));
ints[i] = n;
}
}
if ( readyToSave ) {
String player = getIntent().getStringExtra("player");
SharedPreferences p = getSharedPreferences(player, MODE_PRIVATE);
int powers = p.getInt("powers", 0);
String saveName;
if ( originalName == null ) {
saveName = strings[0];
for (int i = 0; i < powers; i++) {
if ( p.getString("power" + i, "") == strings[0] ) {
edits[0].setError("This power has already been defined. Use another name.");
return;
if (p.getString("power" + power, "").equals(saveName)) saveName += "2";
}
} else {
saveName = originalName;
}
p.edit().putString("power" + powers, strings[0])
p.edit().putString("power" + powers, saveName)
.putInt("powers", powers + 1)
.apply();
SharedPreferences.Editor ed = getSharedPreferences(strings[0], MODE_PRIVATE).edit();
SharedPreferences.Editor ed = getSharedPreferences( saveName, MODE_PRIVATE).edit();
for (int i = 0; i < strings.length; i++)
ed.putString("s" + i, strings[i]);

View file

@ -7,17 +7,19 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.InputType;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;
@ -28,6 +30,8 @@ import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import com.nispok.snackbar.listeners.ActionClickListener;
import java.io.File;
public class ShowPlayer extends ActionBarActivity {
public static final int CURRENT_PG = 1, NULL = 0;
@ -37,7 +41,7 @@ public class ShowPlayer extends ActionBarActivity {
//TODO: fix undo (show snackbar with button in each case, without timing).
private int undoObject, undoPreviousValue;
private ProgressBar pgBar, negPgBar, xpBar, curativeEffortsBar;
private ProgressBar posPgBar, negPgBar, xpBar, curativeEffortsBar;
private TextView currentPg, currentXp, currentCurativeEfforts;
private SharedPreferences p;
private Toolbar toolbar;
@ -64,7 +68,7 @@ public class ShowPlayer extends ActionBarActivity {
//Performing all the findViewById commands
xpBar = (ProgressBar) findViewById(R.id.xpBar);
curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
pgBar = (ProgressBar) findViewById(R.id.pgBar);
posPgBar = (ProgressBar) findViewById(R.id.pgBar);
negPgBar = (ProgressBar) findViewById(R.id.negPgBar);
currentPg = (TextView) findViewById(R.id.currentPg);
@ -151,7 +155,8 @@ public class ShowPlayer extends ActionBarActivity {
alert.show();
input.requestFocus();
return true;
//TODO: the player no longer contains the powers, therefore the
//TODO: the player no longer contains the powers, therefore the resting action affects the array of powers
//TODO: fix restoring powers
// } else if (id == R.id.action_time_long_rest) {
// player.rest(true);
// SnackbarManager.show(
@ -299,31 +304,14 @@ public class ShowPlayer extends ActionBarActivity {
private void pgUpdate() {
int status = player.getState();
int pg = player.getPg();
if (pg < 0) {
if (status == Player.MUERTO)
negPgBar.setProgress(negPgBar.getMax());
else
negPgBar.setProgress(-pg);
pgBar.setProgress(0);
} else {
pgBar.setProgress(pg);
negPgBar.setProgress(0);
}
negPgBar.setProgress(pg < 0 ? -pg : 0);
posPgBar.setProgress(pg > 0 ? pg : 0);
currentPg.setText(player.getPg() + " / " + player.getMaxPg());
if (status == Player.MUERTO) {
pgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.black), PorterDuff.Mode.SRC_IN);
} else if (status == Player.DEBILITADO) {
pgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_IN);
negPgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_IN);
} else if (status == Player.MALHERIDO) {
pgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.yellow), PorterDuff.Mode.SRC_IN);
negPgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.yellow), PorterDuff.Mode.SRC_IN);
} else {
pgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.green), PorterDuff.Mode.SRC_IN);
negPgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.green), PorterDuff.Mode.SRC_IN);
}
int color = player.getStatusColor(getApplicationContext());
posPgBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
negPgBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
private void restoreData(){
@ -343,7 +331,7 @@ public class ShowPlayer extends ActionBarActivity {
player.setCurativeEffort(p.getInt("curativeEfforts", player.getMaxCurativeEfforts()));
player.setPg(p.getInt("pg", player.getMaxPg()));
pgBar.setMax(player.getMaxPg());
posPgBar.setMax(player.getMaxPg());
negPgBar.setMax(player.getMaxPg() / 2);
curativeEffortsBar.setMax(player.getMaxCurativeEfforts());
pgUpdate();
@ -455,7 +443,16 @@ public class ShowPlayer extends ActionBarActivity {
input.requestFocus();
}
public void addToList (View view) { startActivity(new Intent(this, PowerEditor.class).putExtra("player", player.getName())); }
public void addToList (View view) {
startActivity(
new Intent(
this,
PowerEditor.class
)
.putExtra("player", player.getName())
.putExtra("power", -1)
);
}
private void refreshList() {
//TODO: check which is active (now there is only a power list), so there is only one possibility
@ -480,12 +477,12 @@ public class ShowPlayer extends ActionBarActivity {
}
attackList.setAdapter(new AttackAdapter(this, powers));
final Activity thisActivity = this;
attackList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Dialog dialog = new Dialog(ShowPlayer.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.attack_display);
// set the custom dialog components - text, image and button
// Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
@ -498,21 +495,10 @@ public class ShowPlayer extends ActionBarActivity {
// });
//identify all the elements from the VIEW and then add LISTENERS
Power power = (Power) parent.getItemAtPosition(position);
final Power power = (Power) parent.getItemAtPosition(position);
View nameText = dialog.findViewById(R.id.nameText);
switch(power.getFreq()){
case Power.A_VOLUNTAD:
nameText.setBackgroundColor(getResources().getColor(R.color.at_will));
break;
case Power.ENCUENTRO:
nameText.setBackgroundColor(getResources().getColor(R.color.encounter));
break;
case Power.DIARIO:
nameText.setBackgroundColor(getResources().getColor(R.color.daily));
break;
default:
nameText.setBackgroundColor(getResources().getColor(R.color.green));
}
int color = power.getFreqColor(getApplicationContext());
nameText.setBackgroundColor(color);
//TODO: fix the title gap
((TextView) nameText) .setText(power.getName());
((TextView) dialog.findViewById(R.id.typeText)) .setText(power.getTypeString());
@ -526,38 +512,70 @@ public class ShowPlayer extends ActionBarActivity {
String[] attack = getResources().getStringArray(R.array.attack_array);
String[] defense = getResources().getStringArray(R.array.defense_array);
//TODO: add attack and defense array
((TextView) dialog.findViewById(R.id.attackText)).setText(attack[power.getAtk()]
+ " " + getResources().getString(R.string.vs)
+ " " + defense[power.getDef()]);
dialog.findViewById(R.id.useButton).setOnClickListener(new View.OnClickListener() {
Button useButton = (Button) dialog.findViewById(R.id.useButton);
useButton.setBackgroundColor(color);
useButton.setTextColor(getResources().getColor(R.color.white));
useButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO: use power
Toast.makeText(getApplicationContext(), "Use it", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Power used!", Toast.LENGTH_LONG).show();
power.use();
}
});
dialog.findViewById(R.id.deleteButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO: delete power
Toast.makeText(getApplicationContext(), "Delete it", Toast.LENGTH_LONG).show();
}
});
dialog.findViewById(R.id.editButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO: edit power
Toast.makeText(getApplicationContext(), "Edit it", Toast.LENGTH_LONG).show();
}
});
dialog.show();
}
});
}
final Activity thisActivity = this;
attackList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {
AlertDialog.Builder alert = new AlertDialog.Builder(thisActivity);
alert.setItems(new String[]{"Delete", "Edit"}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if ( which == 0 ) {
//delete the item
String name = p.getString("power" + position, "");
if (name != null && !name.isEmpty()) {
getSharedPreferences(name, MODE_PRIVATE).edit().clear().apply();
Log.d("Tag", thisActivity.getApplicationContext().getFilesDir().getParent()
+ File.separator + "shared_prefs" + File.separator + name + ".xml");
try {
if(!new File(thisActivity.getApplicationContext().getFilesDir().getParent()
+ File.separator + "shared_prefs" + File.separator + name + ".xml").delete())
throw new Exception();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error deleting attack files", Toast.LENGTH_SHORT).show();
}
int max = p.getInt("powers", 0);
SharedPreferences.Editor ed = p.edit();
for (int i = position; i < max - 1; i++)
ed.putString("power" + i, p.getString("power" + (i + 1), "max"));
ed.putInt("powers", max - 1).apply();
refreshList();
ed.remove("power" + (max - 1)).apply();
}
} else {
//edit the item
startActivity(
new Intent(getApplicationContext(), PowerEditor.class)
.putExtra("power", position)
.putExtra("player", player.getName())
);
}
}
});
alert.show();
return true;
}
});
}
}

View file

@ -5,6 +5,8 @@
android:layout_height="match_parent"
android:orientation="vertical">
<!--TODO: organize the input similarly to the output-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
@ -28,7 +30,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nameEdit"
android:capitalize="words"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
@ -40,7 +41,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/keywordsEdit"
android:capitalize="words"
android:layout_below="@+id/nameEdit"
android:layout_alignRight="@+id/nameEdit"
android:layout_alignEnd="@+id/nameEdit"
@ -190,7 +190,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/objectiveEdit"
android:capitalize="words"
android:hint="@string/objectiveHint"
android:layout_below="@+id/actionTypeSpinner"
android:layout_alignParentRight="true"

View file

@ -192,7 +192,7 @@
android:id="@+id/listSelectButton"
android:textColor="@color/primary"
android:background="@android:color/transparent"
tools:text="Go to abilities"/>
android:text="Go to abilities"/>
</LinearLayout>

View file

@ -9,7 +9,7 @@
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/at_will"
android:background="@color/encounter"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
@ -160,34 +160,44 @@
android:layout_below="@+id/impact"
tools:text="If you are reading this the description has been displayed"
android:layout_alignParentLeft="true"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/otherText">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Use"
android:background="@android:color/transparent"
android:layout_weight="1"
android:id="@+id/useButton" />
<Button
android:layout_width="wrap_content"
android:textStyle="bold"
android:id="@+id/useButton"
android:layout_below="@+id/linearLayout"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/delete"
android:layout_weight="1"
android:background="@android:color/transparent"
android:id="@+id/deleteButton" />
android:layout_below="@+id/otherText"
android:id="@+id/linearLayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit"
android:visibility="gone"
android:layout_weight="1"
android:textStyle="bold"
android:background="@android:color/transparent"
android:id="@+id/editButton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/delete"
android:textColor="#ff0000"
android:visibility="gone"
android:textStyle="bold"
android:layout_weight="1"
android:background="@android:color/transparent"
android:id="@+id/deleteButton" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View file

@ -1,14 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
tools:background="@color/at_will">
<TextView
tools:text="Happiness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/name" />
@ -18,6 +21,7 @@
tools:text="Melee 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/extra"
android:textColor="@android:color/white"
android:layout_below="@+id/name"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
@ -28,6 +32,7 @@
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/keywords"
tools:text="(fire, explosion)"
android:textColor="@android:color/white"
android:paddingLeft="10dp"
android:layout_alignBottom="@id/extra"
android:layout_toRightOf="@+id/extra"
@ -38,6 +43,7 @@
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/frequency"
android:textColor="@android:color/white"
android:layout_alignBottom="@+id/name"
android:layout_toRightOf="@+id/name"
android:layout_toEndOf="@+id/name"