Use actions instead of buttons
* res/layout/add.xml: Remove save_button. * res/layout/main.xml: Remove add_button. * res/menu/add_activity.xml: * res/menu/main_activity.xml: New menus. * res/values/strings.xml: Rename `add_button' to `main_menu_add' and `save_button' to `add_menu_save'. * src/ryuslash/org/dvdroid/AddDVDActivity.java (createDVD): Renamed from `saveDVD', no longer takes a `View' as an argument. Don't call finish in this function. (onCreateOptionsMenu): (onOptionsItemSelected): New overrides. * src/ryuslash/org/dvdroid/DVDroidActivity.java (onCreateOptionsMenu): (onOptionsItemsSelected): New overrides. (showAddDVD): Renamed from `addDVD', no longer takes a `View' as an argument.
This commit is contained in:
parent
fa6291ef31
commit
e8df341197
7 changed files with 70 additions and 27 deletions
|
@ -20,11 +20,4 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watched_entry" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/save_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save_button"
|
||||
android:onClick="saveDVD" />
|
||||
</LinearLayout>
|
||||
|
|
|
@ -3,13 +3,6 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<Button
|
||||
android:id="@+id/add_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_button"
|
||||
android:onClick="addDVD" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
6
res/menu/add_activity.xml
Normal file
6
res/menu/add_activity.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/add_menu_save"
|
||||
android:title="@string/add_menu_save"
|
||||
android:showAsAction="ifRoom|withText" />
|
||||
</menu>
|
6
res/menu/main_activity.xml
Normal file
6
res/menu/main_activity.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/main_menu_add"
|
||||
android:title="@string/main_menu_add"
|
||||
android:showAsAction="ifRoom|withText" />
|
||||
</menu>
|
|
@ -4,6 +4,6 @@
|
|||
<string name="name_entry">Title...</string>
|
||||
<string name="wishlist_entry">On wishlist</string>
|
||||
<string name="watched_entry">Watched</string>
|
||||
<string name="add_button">Add</string>
|
||||
<string name="save_button">Save</string>
|
||||
<string name="main_menu_add">Add</string>
|
||||
<string name="add_menu_save">Save</string>
|
||||
</resources>
|
||||
|
|
|
@ -3,6 +3,9 @@ package ryuslash.org.dvdroid;
|
|||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
|
@ -21,7 +24,7 @@ public class AddDVDActivity extends Activity
|
|||
datasource.open();
|
||||
}
|
||||
|
||||
public void saveDVD(View view)
|
||||
public void createDVD()
|
||||
{
|
||||
EditText name_entry = (EditText)findViewById(R.id.name_entry);
|
||||
CheckBox watched_entry =
|
||||
|
@ -32,8 +35,6 @@ public class AddDVDActivity extends Activity
|
|||
datasource.createDVD(name_entry.getText().toString(),
|
||||
watched_entry.isChecked() ? 1 : 0,
|
||||
wishlist_entry.isChecked() ? 1 : 0);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,4 +57,25 @@ public class AddDVDActivity extends Activity
|
|||
datasource.close();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.add_activity, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
switch (item.getItemId()) {
|
||||
case R.id.add_menu_save:
|
||||
createDVD();
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@ import android.app.ListActivity;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
|
@ -15,14 +18,6 @@ public class DVDroidActivity extends ListActivity
|
|||
{
|
||||
private DVDDataSource datasource;
|
||||
|
||||
public void addDVD(View view)
|
||||
{
|
||||
Intent intent = new Intent(this, AddDVDActivity.class);
|
||||
|
||||
datasource.close();
|
||||
startActivityForResult(intent, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode,
|
||||
int resultCode,
|
||||
|
@ -58,6 +53,26 @@ public class DVDroidActivity extends ListActivity
|
|||
setListAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.main_activity, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
switch (item.getItemId()) {
|
||||
case R.id.main_menu_add:
|
||||
showAddDVD();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause()
|
||||
{
|
||||
|
@ -71,4 +86,12 @@ public class DVDroidActivity extends ListActivity
|
|||
datasource.open();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
public void showAddDVD()
|
||||
{
|
||||
Intent intent = new Intent(this, AddDVDActivity.class);
|
||||
|
||||
datasource.close();
|
||||
startActivityForResult(intent, 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue