convert main menu to appcompat ActionBar style

This allows the main menu to act like a proper ActionBar using appcompat.
It also allows for making the search happen live on the ListView, rather
than having to launch a separate Activity to show the results.
This commit is contained in:
Hans-Christoph Steiner 2014-07-10 18:14:31 -04:00
parent b06792524e
commit cba8f3b68f
2 changed files with 125 additions and 103 deletions
res/menu
src/org/fdroid/fdroid

40
res/menu/main.xml Normal file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_search"
android:title="@string/menu_search"
app:showAsAction="always"/>
<item
android:id="@+id/action_update_repo"
android:icon="@drawable/ic_menu_refresh"
android:title="@string/menu_update_repo"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_local_repo"
android:title="@string/local_repo"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_manage_repos"
android:icon="@android:drawable/ic_menu_agenda"
android:title="@string/menu_manage"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_bluetooth_apk"
android:icon="@android:drawable/stat_sys_data_bluetooth"
android:title="@string/menu_send_apk_bt"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_settings"
android:icon="@android:drawable/ic_menu_preferences"
android:title="@string/menu_preferences"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_about"
android:icon="@android:drawable/ic_menu_help"
android:title="@string/menu_about"
app:showAsAction="ifRoom"/>
</menu>

@ -32,7 +32,6 @@ import android.database.ContentObserver;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
@ -42,6 +41,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import org.fdroid.fdroid.compat.TabManager;
import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.views.AppListFragmentPageAdapter;
@ -56,14 +56,6 @@ public class FDroid extends ActionBarActivity {
public static final String EXTRA_TAB_UPDATE = "extraTab";
private static final int UPDATE_REPO = Menu.FIRST;
private static final int MANAGE_REPO = Menu.FIRST + 1;
private static final int PREFERENCES = Menu.FIRST + 2;
private static final int ABOUT = Menu.FIRST + 3;
private static final int SEARCH = Menu.FIRST + 4;
private static final int BLUETOOTH_APK = Menu.FIRST + 5;
private static final int LOCAL_REPO = Menu.FIRST + 6;
private FDroidApp fdroidApp = null;
private ViewPager viewPager;
@ -124,23 +116,13 @@ public class FDroid extends ActionBarActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(Menu.NONE, UPDATE_REPO, 1, R.string.menu_update_repo).setIcon(
android.R.drawable.ic_menu_rotate);
menu.add(Menu.NONE, MANAGE_REPO, 2, R.string.menu_manage).setIcon(
android.R.drawable.ic_menu_agenda);
MenuItem search = menu.add(Menu.NONE, SEARCH, 3, R.string.menu_search).setIcon(
android.R.drawable.ic_menu_search);
if (fdroidApp.bluetoothAdapter != null) // ignore on devices without Bluetooth
menu.add(Menu.NONE, BLUETOOTH_APK, 3, R.string.menu_send_apk_bt);
menu.add(Menu.NONE, LOCAL_REPO, 4, R.string.local_repo);
menu.add(Menu.NONE, PREFERENCES, 4, R.string.menu_preferences).setIcon(
android.R.drawable.ic_menu_preferences);
menu.add(Menu.NONE, ABOUT, 5, R.string.menu_about).setIcon(
android.R.drawable.ic_menu_help);
MenuItemCompat.setShowAsAction(search, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
return true;
getMenuInflater().inflate(R.menu.main, menu);
if (fdroidApp.bluetoothAdapter == null) {
// ignore on devices without Bluetooth
MenuItem btItem = menu.findItem(R.id.action_bluetooth_apk);
btItem.setVisible(false);
}
return super.onCreateOptionsMenu(menu);
}
@Override
@ -148,91 +130,91 @@ public class FDroid extends ActionBarActivity {
switch (item.getItemId()) {
case UPDATE_REPO:
updateRepos();
return true;
case R.id.action_update_repo:
updateRepos();
return true;
case MANAGE_REPO:
Intent i = new Intent(this, ManageRepo.class);
startActivityForResult(i, REQUEST_MANAGEREPOS);
return true;
case R.id.action_manage_repos:
Intent i = new Intent(this, ManageRepo.class);
startActivityForResult(i, REQUEST_MANAGEREPOS);
return true;
case PREFERENCES:
Intent prefs = new Intent(getBaseContext(), PreferencesActivity.class);
startActivityForResult(prefs, REQUEST_PREFS);
return true;
case R.id.action_settings:
Intent prefs = new Intent(getBaseContext(), PreferencesActivity.class);
startActivityForResult(prefs, REQUEST_PREFS);
return true;
case LOCAL_REPO:
startActivity(new Intent(this, LocalRepoActivity.class));
return true;
case R.id.action_local_repo:
startActivity(new Intent(this, LocalRepoActivity.class));
return true;
case SEARCH:
onSearchRequested();
return true;
case R.id.action_search:
onSearchRequested();
return true;
case BLUETOOTH_APK:
/*
* If Bluetooth has not been enabled/turned on, then
* enabling device discoverability will automatically enable Bluetooth
*/
Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121);
startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH);
// if this is successful, the Bluetooth transfer is started
return true;
case R.id.action_bluetooth_apk:
/*
* If Bluetooth has not been enabled/turned on, then enabling
* device discoverability will automatically enable Bluetooth
*/
Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121);
startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH);
// if this is successful, the Bluetooth transfer is started
return true;
case ABOUT:
View view = null;
if (Build.VERSION.SDK_INT >= 11) {
LayoutInflater li = LayoutInflater.from(this);
view = li.inflate(R.layout.about, null);
} else {
view = View.inflate(
new ContextThemeWrapper(this, R.style.AboutDialogLight),
R.layout.about, null);
}
case R.id.action_about:
View view = null;
if (Build.VERSION.SDK_INT >= 11) {
LayoutInflater li = LayoutInflater.from(this);
view = li.inflate(R.layout.about, null);
} else {
view = View.inflate(
new ContextThemeWrapper(this, R.style.AboutDialogLight),
R.layout.about, null);
}
// Fill in the version...
try {
PackageInfo pi = getPackageManager()
.getPackageInfo(getApplicationContext()
.getPackageName(), 0);
((TextView) view.findViewById(R.id.version))
.setText(pi.versionName);
} catch (Exception e) {
}
// Fill in the version...
try {
PackageInfo pi = getPackageManager()
.getPackageInfo(getApplicationContext()
.getPackageName(), 0);
((TextView) view.findViewById(R.id.version))
.setText(pi.versionName);
} catch (Exception e) {
}
Builder p = null;
if (Build.VERSION.SDK_INT >= 11) {
p = new AlertDialog.Builder(this).setView(view);
} else {
p = new AlertDialog.Builder(
new ContextThemeWrapper(
this, R.style.AboutDialogLight)
).setView(view);
}
final AlertDialog alrt = p.create();
alrt.setIcon(R.drawable.ic_launcher);
alrt.setTitle(getString(R.string.about_title));
alrt.setButton(AlertDialog.BUTTON_NEUTRAL,
getString(R.string.about_website),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
Uri uri = Uri.parse("https://f-droid.org");
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
});
alrt.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
alrt.show();
return true;
Builder p = null;
if (Build.VERSION.SDK_INT >= 11) {
p = new AlertDialog.Builder(this).setView(view);
} else {
p = new AlertDialog.Builder(
new ContextThemeWrapper(
this, R.style.AboutDialogLight)
).setView(view);
}
final AlertDialog alrt = p.create();
alrt.setIcon(R.drawable.ic_launcher);
alrt.setTitle(getString(R.string.about_title));
alrt.setButton(AlertDialog.BUTTON_NEUTRAL,
getString(R.string.about_website),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
Uri uri = Uri.parse("https://f-droid.org");
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
});
alrt.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
alrt.show();
return true;
}
return super.onOptionsItemSelected(item);
}