1
0
Fork 0

PowerEditor: rearranged screen and moved Save button to ActionBar

This commit is contained in:
Carlos Galindo 2015-07-18 19:53:00 +02:00
parent 34b6e52b9f
commit 172d969370
3 changed files with 61 additions and 41 deletions

View file

@ -7,7 +7,8 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
@ -52,6 +53,7 @@ public class PowerEditor extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_power_editor); setContentView(R.layout.activity_power_editor);
//identify toolbar, set it as ActionBar and add the back button to the last activity
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true); getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
@ -123,7 +125,7 @@ public class PowerEditor extends ActionBarActivity {
} }
public void saveClick(View view) { public void save() {
boolean readyToSave = true; boolean readyToSave = true;
for ( int i = 0; i < edits.length; i++ ) { for ( int i = 0; i < edits.length; i++ ) {
@ -175,4 +177,22 @@ public class PowerEditor extends ActionBarActivity {
finish(); finish();
} }
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_save) {
save();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_power_editor, menu);
return super.onCreateOptionsMenu(menu);
}
} }

View file

@ -81,23 +81,35 @@
android:layout_marginRight="10dp" /> android:layout_marginRight="10dp" />
<LinearLayout <LinearLayout
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/keywordsEdit" android:orientation="horizontal"
android:layout_alignParentLeft="true" android:id="@+id/spinnersLayout"
android:layout_alignParentStart="true" android:layout_below="@+id/keywordsEdit">
android:id="@+id/spinnersLayout">
<Spinner <Spinner
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/freqSpinner" android:id="@+id/freqSpinner"
android:layout_weight="1" android:layout_weight="1"
android:spinnerMode="dropdown" /> android:spinnerMode="dropdown" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/actionSpinner"
android:layout_weight="1"
android:spinnerMode="dropdown" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/distanceLayout"
android:layout_below="@+id/spinnersLayout">
<Spinner <Spinner
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/rangeSpinner" android:id="@+id/rangeSpinner"
android:layout_weight="1" android:layout_weight="1"
@ -109,7 +121,7 @@
android:inputType="textCapSentences" android:inputType="textCapSentences"
android:ems="10" android:ems="10"
android:id="@+id/distanceNumEdit" android:id="@+id/distanceNumEdit"
android:layout_weight="0.75" android:layout_weight="1"
android:hint="@string/number10" android:hint="@string/number10"
android:focusableInTouchMode="true" /> android:focusableInTouchMode="true" />
</LinearLayout> </LinearLayout>
@ -117,28 +129,32 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/spinnersLayout" android:layout_below="@+id/objectiveEdit"
android:orientation="horizontal" android:orientation="horizontal"
android:gravity="center" android:gravity="center"
android:id="@+id/vsLayout"> android:id="@+id/vsLayout">
<Spinner <Spinner
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/atkSpinner" android:id="@+id/atkSpinner"
android:spinnerMode="dropdown" /> android:spinnerMode="dropdown"
android:layout_weight="1" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/vs" android:text="@string/vs"
android:id="@+id/vsText" /> android:id="@+id/vsText"
android:layout_weight="1"
android:gravity="center" />
<Spinner <Spinner
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/defSpinner" android:id="@+id/defSpinner"
android:spinnerMode="dropdown" /> android:spinnerMode="dropdown"
android:layout_weight="1" />
</LinearLayout> </LinearLayout>
@ -170,15 +186,6 @@
android:layout_alignBottom="@+id/impactEdit" android:layout_alignBottom="@+id/impactEdit"
android:layout_marginRight="10dp" /> android:layout_marginRight="10dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/actionSpinner"
android:layout_below="@+id/impactEdit"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:spinnerMode="dropdown" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -186,7 +193,7 @@
android:text="@string/objective" android:text="@string/objective"
android:id="@+id/objectiveText" android:id="@+id/objectiveText"
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_below="@+id/actionSpinner" android:layout_below="@+id/distanceLayout"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
@ -197,25 +204,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/objectiveEdit" android:id="@+id/objectiveEdit"
android:hint="@string/objectiveHint" android:hint="@string/objectiveHint"
android:layout_below="@+id/actionSpinner" android:layout_below="@+id/distanceLayout"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:capitalize="sentences" android:capitalize="sentences"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/objectiveText" android:layout_toRightOf="@+id/objectiveText"
android:layout_toEndOf="@+id/objectiveText" /> android:layout_toEndOf="@+id/objectiveText" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:id="@+id/saveButton"
android:layout_below="@+id/objectiveEdit"
android:layout_alignRight="@+id/impactEdit"
android:layout_alignEnd="@+id/impactEdit"
android:background="@android:color/transparent"
android:onClick="saveClick"
android:textColor="@color/primary_dark"/>
</RelativeLayout> </RelativeLayout>
</ScrollView> </ScrollView>

View file

@ -2,4 +2,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:context="com.kauron.dungeonmanager.PowerEditor"> tools:context="com.kauron.dungeonmanager.PowerEditor">
<item
android:id="@+id/action_save"
android:title="@string/save"
app:showAsAction="always"/>
</menu> </menu>