move menu handling to SwapView and SwapWorkflowActivity
The menus originate in the Activity, so avoid pushing it to the Views.
This commit is contained in:
parent
fe59522666
commit
9d6c95d51d
@ -6,8 +6,6 @@ import android.content.res.TypedArray;
|
|||||||
import android.support.annotation.ColorInt;
|
import android.support.annotation.ColorInt;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.views.swap.SwapWorkflowActivity;
|
import org.fdroid.fdroid.views.swap.SwapWorkflowActivity;
|
||||||
@ -25,6 +23,8 @@ public class SwapView extends RelativeLayout {
|
|||||||
|
|
||||||
private int layoutResId;
|
private int layoutResId;
|
||||||
|
|
||||||
|
protected String currentFilterString;
|
||||||
|
|
||||||
public SwapView(Context context) {
|
public SwapView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
@ -48,10 +48,6 @@ public class SwapView extends RelativeLayout {
|
|||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@LayoutRes
|
@LayoutRes
|
||||||
public int getLayoutResId() {
|
public int getLayoutResId() {
|
||||||
return layoutResId;
|
return layoutResId;
|
||||||
@ -61,6 +57,14 @@ public class SwapView extends RelativeLayout {
|
|||||||
this.layoutResId = layoutResId;
|
this.layoutResId = layoutResId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCurrentFilterString() {
|
||||||
|
return this.currentFilterString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentFilterString(String currentFilterString) {
|
||||||
|
this.currentFilterString = currentFilterString;
|
||||||
|
}
|
||||||
|
|
||||||
public SwapWorkflowActivity getActivity() {
|
public SwapWorkflowActivity getActivity() {
|
||||||
return (SwapWorkflowActivity) getContext();
|
return (SwapWorkflowActivity) getContext();
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,9 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -100,22 +95,6 @@ public class JoinWifiView extends SwapView {
|
|||||||
getActivity().startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
|
getActivity().startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
|
|
||||||
inflater.inflate(R.menu.swap_next, menu);
|
|
||||||
MenuItem next = menu.findItem(R.id.action_next);
|
|
||||||
MenuItemCompat.setShowAsAction(next,
|
|
||||||
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
|
||||||
next.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
getActivity().inflateInnerView(R.layout.swap_select_apps);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final BroadcastReceiver onWifiStateChange = new BroadcastReceiver() {
|
private final BroadcastReceiver onWifiStateChange = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
@ -2,12 +2,7 @@ package org.fdroid.fdroid.views.swap;
|
|||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
@ -44,20 +39,4 @@ public class NfcView extends SwapView {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
|
|
||||||
inflater.inflate(R.menu.swap_skip, menu);
|
|
||||||
MenuItem next = menu.findItem(R.id.action_next);
|
|
||||||
MenuItemCompat.setShowAsAction(next,
|
|
||||||
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
|
||||||
next.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
getActivity().inflateInnerView(R.layout.swap_wifi_qr);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,11 @@ import android.support.annotation.Nullable;
|
|||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.support.v4.widget.CursorAdapter;
|
import android.support.v4.widget.CursorAdapter;
|
||||||
import android.support.v7.widget.SearchView;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
@ -37,9 +32,7 @@ import org.fdroid.fdroid.data.Schema.InstalledAppTable;
|
|||||||
import org.fdroid.fdroid.localrepo.SwapService;
|
import org.fdroid.fdroid.localrepo.SwapService;
|
||||||
import org.fdroid.fdroid.localrepo.SwapView;
|
import org.fdroid.fdroid.localrepo.SwapView;
|
||||||
|
|
||||||
public class SelectAppsView extends SwapView implements
|
public class SelectAppsView extends SwapView implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
LoaderManager.LoaderCallbacks<Cursor>,
|
|
||||||
SearchView.OnQueryTextListener {
|
|
||||||
|
|
||||||
public SelectAppsView(Context context) {
|
public SelectAppsView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -62,11 +55,8 @@ public class SelectAppsView extends SwapView implements
|
|||||||
return getActivity().getState();
|
return getActivity().getState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int LOADER_INSTALLED_APPS = 253341534;
|
|
||||||
|
|
||||||
private ListView listView;
|
private ListView listView;
|
||||||
private AppListAdapter adapter;
|
private AppListAdapter adapter;
|
||||||
private String currentFilterString;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFinishInflate() {
|
protected void onFinishInflate() {
|
||||||
@ -80,7 +70,7 @@ public class SelectAppsView extends SwapView implements
|
|||||||
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||||
|
|
||||||
// either reconnect with an existing loader or start a new one
|
// either reconnect with an existing loader or start a new one
|
||||||
getActivity().getSupportLoaderManager().initLoader(LOADER_INSTALLED_APPS, null, this);
|
getActivity().getSupportLoaderManager().initLoader(R.layout.swap_select_apps, null, this);
|
||||||
|
|
||||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
||||||
@ -89,31 +79,6 @@ public class SelectAppsView extends SwapView implements
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
|
|
||||||
|
|
||||||
inflater.inflate(R.menu.swap_next_search, menu);
|
|
||||||
MenuItem nextMenuItem = menu.findItem(R.id.action_next);
|
|
||||||
int flags = MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT;
|
|
||||||
MenuItemCompat.setShowAsAction(nextMenuItem, flags);
|
|
||||||
nextMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
getActivity().onAppsSelected();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
SearchView searchView = new SearchView(getActivity());
|
|
||||||
|
|
||||||
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
|
|
||||||
MenuItemCompat.setActionView(searchMenuItem, searchView);
|
|
||||||
MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
|
||||||
|
|
||||||
searchView.setOnQueryTextListener(this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toggleAppSelected(int position) {
|
private void toggleAppSelected(int position) {
|
||||||
Cursor c = (Cursor) adapter.getItem(position);
|
Cursor c = (Cursor) adapter.getItem(position);
|
||||||
String packageName = c.getString(c.getColumnIndex(InstalledAppTable.Cols.Package.NAME));
|
String packageName = c.getString(c.getColumnIndex(InstalledAppTable.Cols.Package.NAME));
|
||||||
@ -165,26 +130,6 @@ public class SelectAppsView extends SwapView implements
|
|||||||
adapter.swapCursor(null);
|
adapter.swapCursor(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextChange(String newText) {
|
|
||||||
String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
|
|
||||||
if (currentFilterString == null && newFilter == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (currentFilterString != null && currentFilterString.equals(newFilter)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
currentFilterString = newFilter;
|
|
||||||
getActivity().getSupportLoaderManager().restartLoader(LOADER_INSTALLED_APPS, null, this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextSubmit(String query) {
|
|
||||||
// this is not needed since we respond to every change in text
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AppListAdapter extends CursorAdapter {
|
private class AppListAdapter extends CursorAdapter {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -18,15 +18,10 @@ import android.support.v4.app.LoaderManager;
|
|||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.support.v4.widget.CursorAdapter;
|
import android.support.v4.widget.CursorAdapter;
|
||||||
import android.support.v7.widget.SearchView;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -54,9 +49,8 @@ import java.util.List;
|
|||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public class SwapSuccessView extends SwapView implements
|
public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
LoaderManager.LoaderCallbacks<Cursor>,
|
private static final String TAG = "SwapAppsView";
|
||||||
SearchView.OnQueryTextListener {
|
|
||||||
|
|
||||||
public SwapSuccessView(Context context) {
|
public SwapSuccessView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -75,9 +69,6 @@ public class SwapSuccessView extends SwapView implements
|
|||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int LOADER_SWAPABLE_APPS = 759283741;
|
|
||||||
private static final String TAG = "SwapAppsView";
|
|
||||||
|
|
||||||
private Repo repo;
|
private Repo repo;
|
||||||
private AppListAdapter adapter;
|
private AppListAdapter adapter;
|
||||||
private String currentFilterString;
|
private String currentFilterString;
|
||||||
@ -100,7 +91,7 @@ public class SwapSuccessView extends SwapView implements
|
|||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
|
|
||||||
// either reconnect with an existing loader or start a new one
|
// either reconnect with an existing loader or start a new one
|
||||||
getActivity().getSupportLoaderManager().initLoader(LOADER_SWAPABLE_APPS, null, this);
|
getActivity().getSupportLoaderManager().initLoader(R.layout.swap_success, null, this);
|
||||||
|
|
||||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
|
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
|
||||||
pollForUpdatesReceiver, new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
|
pollForUpdatesReceiver, new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
|
||||||
@ -142,21 +133,6 @@ public class SwapSuccessView extends SwapView implements
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
|
|
||||||
|
|
||||||
inflater.inflate(R.menu.swap_search, menu);
|
|
||||||
|
|
||||||
SearchView searchView = new SearchView(getActivity());
|
|
||||||
|
|
||||||
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
|
|
||||||
MenuItemCompat.setActionView(searchMenuItem, searchView);
|
|
||||||
MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
|
||||||
|
|
||||||
searchView.setOnQueryTextListener(this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CursorLoader onCreateLoader(int id, Bundle args) {
|
public CursorLoader onCreateLoader(int id, Bundle args) {
|
||||||
Uri uri = TextUtils.isEmpty(currentFilterString)
|
Uri uri = TextUtils.isEmpty(currentFilterString)
|
||||||
@ -177,26 +153,6 @@ public class SwapSuccessView extends SwapView implements
|
|||||||
adapter.swapCursor(null);
|
adapter.swapCursor(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextChange(String newText) {
|
|
||||||
String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
|
|
||||||
if (currentFilterString == null && newFilter == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (currentFilterString != null && currentFilterString.equals(newFilter)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
currentFilterString = newFilter;
|
|
||||||
getActivity().getSupportLoaderManager().restartLoader(LOADER_SWAPABLE_APPS, null, this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextSubmit(String query) {
|
|
||||||
// this is not needed since we respond to every change in text
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AppListAdapter extends CursorAdapter {
|
private class AppListAdapter extends CursorAdapter {
|
||||||
|
|
||||||
private class ViewHolder {
|
private class ViewHolder {
|
||||||
|
@ -20,13 +20,19 @@ import android.provider.Settings;
|
|||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -228,9 +234,99 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
menu.clear();
|
menu.clear();
|
||||||
boolean parent = super.onPrepareOptionsMenu(menu);
|
|
||||||
boolean inner = currentView != null && currentView.buildMenu(menu, getMenuInflater());
|
MenuInflater menuInflater = getMenuInflater();
|
||||||
return parent || inner;
|
switch (currentView.getLayoutResId()) {
|
||||||
|
case R.layout.swap_select_apps:
|
||||||
|
menuInflater.inflate(R.menu.swap_next_search, menu);
|
||||||
|
setUpNextButton(menu, R.string.next);
|
||||||
|
setUpSearchView(menu);
|
||||||
|
return true;
|
||||||
|
case R.layout.swap_success:
|
||||||
|
menuInflater.inflate(R.menu.swap_search, menu);
|
||||||
|
setUpSearchView(menu);
|
||||||
|
return true;
|
||||||
|
case R.layout.swap_join_wifi:
|
||||||
|
menuInflater.inflate(R.menu.swap_next, menu);
|
||||||
|
setUpNextButton(menu, R.string.next);
|
||||||
|
return true;
|
||||||
|
case R.layout.swap_nfc:
|
||||||
|
menuInflater.inflate(R.menu.swap_next, menu);
|
||||||
|
setUpNextButton(menu, R.string.skip);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onPrepareOptionsMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpNextButton(Menu menu, @StringRes int titleResId) {
|
||||||
|
MenuItem next = menu.findItem(R.id.action_next);
|
||||||
|
CharSequence title = getString(titleResId);
|
||||||
|
next.setTitle(title);
|
||||||
|
next.setTitleCondensed(title);
|
||||||
|
MenuItemCompat.setShowAsAction(next,
|
||||||
|
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
next.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
sendNext();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendNext() {
|
||||||
|
int currentLayoutResId = currentView.getLayoutResId();
|
||||||
|
switch (currentLayoutResId) {
|
||||||
|
case R.layout.swap_select_apps:
|
||||||
|
onAppsSelected();
|
||||||
|
break;
|
||||||
|
case R.layout.swap_join_wifi:
|
||||||
|
inflateSwapView(R.layout.swap_select_apps);
|
||||||
|
break;
|
||||||
|
case R.layout.swap_nfc:
|
||||||
|
inflateSwapView(R.layout.swap_wifi_qr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpSearchView(Menu menu) {
|
||||||
|
SearchView searchView = new SearchView(this);
|
||||||
|
|
||||||
|
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
|
||||||
|
MenuItemCompat.setActionView(searchMenuItem, searchView);
|
||||||
|
MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
||||||
|
|
||||||
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextSubmit(String newText) {
|
||||||
|
String currentFilterString = currentView.getCurrentFilterString();
|
||||||
|
String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
|
||||||
|
if (currentFilterString == null && newFilter == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (currentFilterString != null && currentFilterString.equals(newFilter)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
currentView.setCurrentFilterString(newFilter);
|
||||||
|
if (currentView instanceof SelectAppsView) {
|
||||||
|
getSupportLoaderManager().restartLoader(currentView.getLayoutResId(), null,
|
||||||
|
(SelectAppsView) currentView);
|
||||||
|
} else if (currentView instanceof SwapSuccessView) {
|
||||||
|
getSupportLoaderManager().restartLoader(currentView.getLayoutResId(), null,
|
||||||
|
(SwapSuccessView) currentView);
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException(currentView.getClass() + " does not have Loader!");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextChange(String s) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
xmlns:swap="http://schemas.android.com/apk/res-auto"
|
xmlns:swap="http://schemas.android.com/apk/res-auto"
|
||||||
swap:toolbarColor="@color/swap_bright_blue"
|
swap:toolbarColor="@color/swap_bright_blue"
|
||||||
swap:toolbarTitle="@string/swap_choose_apps"
|
swap:toolbarTitle="@string/swap_choose_apps"
|
||||||
|
android:id="@+id/select_apps"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
xmlns:swap="http://schemas.android.com/apk/res-auto"
|
xmlns:swap="http://schemas.android.com/apk/res-auto"
|
||||||
swap:toolbarColor="@color/swap_bright_blue"
|
swap:toolbarColor="@color/swap_bright_blue"
|
||||||
swap:toolbarTitle="@string/swap_success"
|
swap:toolbarTitle="@string/swap_success"
|
||||||
|
android:id="@+id/swap_success"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_next"
|
|
||||||
android:icon="@drawable/ic_arrow_forward_white"
|
|
||||||
android:title="@string/skip"
|
|
||||||
android:titleCondensed="@string/skip"/>
|
|
||||||
|
|
||||||
<!-- Currently in a style, but that style probably wont work on 8 -> 11 devices -->
|
|
||||||
<!--android:drawable="@drawable/swap_action_button_skin"-->
|
|
||||||
|
|
||||||
</menu>
|
|
Loading…
x
Reference in New Issue
Block a user