Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Moved search to action bar
Browse files Browse the repository at this point in the history
Fixes #1918
  • Loading branch information
M66B committed Aug 30, 2014
1 parent c141db8 commit 054c651
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 110 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Version 3.x will be available with a [pro license](http://www.xprivacy.eu/) only
* Moved flush button to expert mode section ([issue](/../../issues/1934))
* Added category merge/reset ([issue](/../../issues/1909))
* Display introductory tutorial only on first run after *About* ([issue](/../../issues/1942))
* Moved search to action bar ([issue](/../../issues/1918))
* Updated simplified Chinese translation

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)
Expand Down
Binary file removed res/drawable/cross_grayed_out_holo_dark.png
Binary file not shown.
Binary file removed res/drawable/cross_grayed_out_holo_light.png
Binary file not shown.
Binary file removed res/drawable/cross_holo_dark.png
Binary file not shown.
Binary file removed res/drawable/cross_holo_light.png
Binary file not shown.
75 changes: 15 additions & 60 deletions res/layout/mainlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,74 +22,29 @@
android:layout_marginBottom="3dip"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="?attr/drawable_card"
android:orientation="vertical"
android:orientation="horizontal"
android:paddingBottom="6dip"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="6dip" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
<Spinner
android:id="@+id/spRestriction"
android:layout_width="0dip"
android:layout_height="37dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:orientation="horizontal" >

<Spinner
android:id="@+id/spRestriction"
android:layout_width="0dip"
android:layout_height="37dip"
android:layout_weight="1" />

<ImageView
android:id="@+id/imgInfo"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_gravity="center_vertical"
android:clickable="true"
android:contentDescription="@string/help_application"
android:focusable="true"
android:src="?attr/icon_info" />
</LinearLayout>

<!-- Filters -->
android:layout_weight="1" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="3dip"
<ImageView
android:id="@+id/imgInfo"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_gravity="center_vertical"
android:layout_marginRight="3dip"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" >

<requestFocus />
</LinearLayout>

<EditText
android:id="@+id/etFilter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/help_application"
android:inputType="textNoSuggestions"
android:textAppearance="?android:attr/textAppearanceSmall" />

<ImageView
android:id="@+id/imgClear"
android:layout_width="24dip"
android:layout_height="24dip"
android:layout_alignRight="@id/etFilter"
android:layout_centerVertical="true"
android:clickable="true"
android:contentDescription="@string/help_application"
android:focusable="true"
android:src="?attr/icon_clear_grayed" />
</RelativeLayout>
android:clickable="true"
android:contentDescription="@string/help_application"
android:focusable="true"
android:src="?attr/icon_info" />
</LinearLayout>

<ScrollView
Expand Down
7 changes: 7 additions & 0 deletions res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >

<item
android:id="@+id/menu_search"
android:actionViewClass="android.widget.SearchView"
android:icon="@android:drawable/ic_menu_search"
android:queryHint="@string/help_application"
android:showAsAction="collapseActionView|always"
android:title="@android:string/search_go"/>
<item
android:id="@+id/menu_sort"
android:icon="@drawable/icon_sort"
Expand Down
4 changes: 0 additions & 4 deletions res/values-v14/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<item name="icon_expander_maximized">@drawable/expander_ic_maximized_holo_dark</item>
<item name="icon_launcher">@drawable/ic_launcher_holo_dark</item>
<item name="icon_restricted">@drawable/check_holo_dark</item>
<item name="icon_clear">@drawable/cross_holo_dark</item>
<item name="icon_clear_grayed">@drawable/cross_grayed_out_holo_dark</item>
<item name="icon_frozen">@drawable/frozen_holo_dark</item>
<item name="icon_unsafe">@drawable/padlock_question_dark</item>
<item name="drawable_background">@android:color/black</item>
Expand All @@ -41,8 +39,6 @@
<item name="icon_expander_maximized">@drawable/expander_ic_maximized_holo_light</item>
<item name="icon_launcher">@drawable/ic_launcher_holo_light</item>
<item name="icon_restricted">@drawable/check_holo_light</item>
<item name="icon_clear">@drawable/cross_holo_light</item>
<item name="icon_clear_grayed">@drawable/cross_grayed_out_holo_light</item>
<item name="icon_frozen">@drawable/frozen_holo_light</item>
<item name="icon_unsafe">@drawable/padlock_question_light</item>
<item name="drawable_background">@color/color_home_background_light</item>
Expand Down
81 changes: 36 additions & 45 deletions src/biz/bokhorst/xprivacy/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import android.os.Environment;
import android.os.Handler;
import android.os.Process;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -60,7 +58,6 @@
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.Filter;
import android.widget.ImageView;
Expand All @@ -70,13 +67,16 @@
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.SearchView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class ActivityMain extends ActivityBase implements OnItemSelectedListener {
private Spinner spRestriction = null;
private AppListAdapter mAppAdapter = null;

private String searchQuery = "";
private int mSortMode;
private boolean mSortInvert;
private int mProgressWidth = 0;
Expand All @@ -101,7 +101,6 @@ public class ActivityMain extends ActivityBase implements OnItemSelectedListener
private static final int ERROR_NON_MATCHING_UID = 0x103;

public static final Uri cProUri = Uri.parse("http://www.xprivacy.eu/");
public static final String cRefreshUI = "RefreshUI";

private static ExecutorService mExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(),
new PriorityThreadFactory());
Expand Down Expand Up @@ -221,35 +220,6 @@ public void onClick(View view) {
mSortMode = Integer.parseInt(PrivacyManager.getSetting(userId, PrivacyManager.cSettingSortMode, "0"));
mSortInvert = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingSortInverted, false);

// Setup name filter
final EditText etFilter = (EditText) findViewById(R.id.etFilter);
etFilter.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String text = etFilter.getText().toString();
ImageView imgClear = (ImageView) findViewById(R.id.imgClear);
imgClear.setImageDrawable(getResources().getDrawable(
getThemed(text.equals("") ? R.attr.icon_clear_grayed : R.attr.icon_clear)));
applyFilter();
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void afterTextChanged(Editable s) {
}
});

ImageView imgClear = (ImageView) findViewById(R.id.imgClear);
imgClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
etFilter.setText("");
}
});

// Start task to get app list
AppListTask appListTask = new AppListTask();
appListTask.executeOnExecutor(mExecutor, (Object) null);
Expand Down Expand Up @@ -355,17 +325,13 @@ protected void onResume() {

@Override
protected void onNewIntent(Intent intent) {
// Refresh application list
if (mAppAdapter != null)
mAppAdapter.notifyDataSetChanged();

// Import pro license
if (Intent.ACTION_VIEW.equals(intent.getAction()))
Util.importProLicense(new File(intent.getData().getPath()));

// Handle clear XPrivacy data (needs UI refresh)
if (intent.hasExtra(cRefreshUI)) {
((EditText) findViewById(R.id.etFilter)).setText("");
recreate();
}
}

@Override
Expand Down Expand Up @@ -448,7 +414,6 @@ private void selectRestriction(int pos) {

private void applyFilter() {
if (mAppAdapter != null) {
EditText etFilter = (EditText) findViewById(R.id.etFilter);
ProgressBar pbFilter = (ProgressBar) findViewById(R.id.pbFilter);
TextView tvStats = (TextView) findViewById(R.id.tvStats);
TextView tvState = (TextView) findViewById(R.id.tvState);
Expand All @@ -466,9 +431,8 @@ private void applyFilter() {
boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true);
boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false);

String filter = String.format("%s\n%b\n%b\n%b\n%b\n%b\n%b\n%b\n%b\n%b", etFilter.getText().toString(),
fUsed, fInternet, fRestriction, fRestrictionNot, fPermission, fOnDemand, fOnDemandNot, fUser,
fSystem);
String filter = String.format("%s\n%b\n%b\n%b\n%b\n%b\n%b\n%b\n%b\n%b", searchQuery, fUsed, fInternet,
fRestriction, fRestrictionNot, fPermission, fOnDemand, fOnDemandNot, fUser, fSystem);
pbFilter.setVisibility(ProgressBar.VISIBLE);
tvStats.setVisibility(TextView.GONE);

Expand All @@ -477,8 +441,6 @@ private void applyFilter() {
tvStateLayout.addRule(RelativeLayout.LEFT_OF, R.id.pbFilter);

mAppAdapter.getFilter().filter(filter);

invalidateOptionsMenu();
}
}

Expand All @@ -493,7 +455,35 @@ private void applySort() {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
if (inflater != null && PrivacyService.checkClient()) {
// Inflate menu
inflater.inflate(R.menu.main, menu);

// Searchable
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
searchQuery = newText;
applyFilter();
return true;
}

@Override
public boolean onQueryTextSubmit(String query) {
searchQuery = query;
applyFilter();
return true;
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
searchQuery = "";
applyFilter();
return true;
}
});

return true;
} else
return false;
Expand Down Expand Up @@ -820,6 +810,7 @@ public void onClick(DialogInterface dialog, int which) {
PrivacyManager.setSetting(userId, PrivacyManager.cSettingFSystem,
Boolean.toString(cbFSystem.isChecked()));

invalidateOptionsMenu();
applyFilter();
}
});
Expand Down
1 change: 0 additions & 1 deletion src/biz/bokhorst/xprivacy/ActivitySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ public void onClick(DialogInterface dialog, int which) {

// Refresh main UI
Intent intent = new Intent(ActivitySettings.this, ActivityMain.class);
intent.putExtra(ActivityMain.cRefreshUI, true);
startActivity(intent);
}
});

This comment has been minimized.

Copy link
@tonymanou

tonymanou Aug 30, 2014

Contributor

If we remove this as well as L367 of ActivityMain, main UI is not refreshed (filter is not reset, and "first run" info are not displayed) after clearing all XPrivacy data.

Expand Down

1 comment on commit 054c651

@M66B
Copy link
Owner Author

@M66B M66B commented on 054c651 Aug 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, thanks.
Fixed in 9de1990 and 58c9831

Please sign in to comment.