Merge "Print settings polish" into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
10cbbc5515
@@ -1132,6 +1132,22 @@
|
|||||||
android:resource="@id/development_settings" />
|
android:resource="@id/development_settings" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name="Settings$PrintSettingsActivity"
|
||||||
|
android:label="@string/print_settings"
|
||||||
|
android:taskAffinity="com.android.settings"
|
||||||
|
android:parentActivityName="Settings">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<action android:name="android.settings.ACTION_PRINT_SETTINGS" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
|
android:value="com.android.settings.print.PrintSettingsFragment" />
|
||||||
|
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
|
||||||
|
android:resource="@id/print_settings" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<!-- Keep compatibility with old shortcuts. -->
|
<!-- Keep compatibility with old shortcuts. -->
|
||||||
<activity-alias android:name="DevelopmentSettings"
|
<activity-alias android:name="DevelopmentSettings"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
@@ -15,6 +15,14 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/print_menu_item_search"
|
||||||
|
android:title="@string/print_menu_item_search"
|
||||||
|
android:icon="@*android:drawable/ic_menu_search_holo_dark"
|
||||||
|
android:actionViewClass="android.widget.SearchView"
|
||||||
|
android:showAsAction="ifRoom"
|
||||||
|
android:imeOptions="actionSearch">
|
||||||
|
</item>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/print_menu_item_add_printer"
|
android:id="@+id/print_menu_item_add_printer"
|
||||||
android:title="@string/print_menu_item_add_printer"
|
android:title="@string/print_menu_item_add_printer"
|
||||||
@@ -25,9 +33,4 @@
|
|||||||
android:title="@string/print_menu_item_settings"
|
android:title="@string/print_menu_item_settings"
|
||||||
android:showAsAction="ifRoom">
|
android:showAsAction="ifRoom">
|
||||||
</item>
|
</item>
|
||||||
<item
|
|
||||||
android:id="@+id/print_menu_item_uninstall"
|
|
||||||
android:title="@string/print_menu_item_uninstall"
|
|
||||||
android:showAsAction="never">
|
|
||||||
</item>
|
|
||||||
</menu>
|
</menu>
|
||||||
|
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/print_menu_item_download_print_service"
|
android:id="@+id/print_menu_item_add_service"
|
||||||
android:title="@string/print_menu_item_download_print_service"
|
android:title="@string/print_menu_item_add_service"
|
||||||
android:showAsAction="ifRoom">
|
android:showAsAction="ifRoom">
|
||||||
</item>
|
</item>
|
||||||
</menu>
|
</menu>
|
||||||
|
@@ -3420,13 +3420,13 @@
|
|||||||
<string name="print_feature_state_off">Off</string>
|
<string name="print_feature_state_off">Off</string>
|
||||||
|
|
||||||
<!-- Title of the action bar button to got to Play Store to download a print service. [CHAR LIMIT=25] -->
|
<!-- Title of the action bar button to got to Play Store to download a print service. [CHAR LIMIT=25] -->
|
||||||
<string name="print_menu_item_download_print_service">I don\'t see mine</string>
|
<string name="print_menu_item_add_service">Add service</string>
|
||||||
|
|
||||||
<!-- Title of the action bar button to got to add a printer. [CHAR LIMIT=25] -->
|
<!-- Title of the action bar button to got to add a printer. [CHAR LIMIT=25] -->
|
||||||
<string name="print_menu_item_add_printer">Add printer</string>
|
<string name="print_menu_item_add_printer">Add printer</string>
|
||||||
|
|
||||||
<!-- Title of the action bar button uninstall a print service. [CHAR LIMIT=25] -->
|
<!-- Title for the search action bar menu item. [CHAR LIMIT=20] -->
|
||||||
<string name="print_menu_item_uninstall">Uninstall</string>
|
<string name="print_menu_item_search">Search</string>
|
||||||
|
|
||||||
<!-- Title for the printer categoty showing a list of available printers. [CHAR LIMIT=25] -->
|
<!-- Title for the printer categoty showing a list of available printers. [CHAR LIMIT=25] -->
|
||||||
<string name="category_printers">Printers</string>
|
<string name="category_printers">Printers</string>
|
||||||
|
@@ -962,4 +962,5 @@ public class Settings extends PreferenceActivity
|
|||||||
public static class UsbSettingsActivity extends Settings { /* empty */ }
|
public static class UsbSettingsActivity extends Settings { /* empty */ }
|
||||||
public static class TrustedCredentialsSettingsActivity extends Settings { /* empty */ }
|
public static class TrustedCredentialsSettingsActivity extends Settings { /* empty */ }
|
||||||
public static class PaymentSettingsActivity extends Settings { /* empty */ }
|
public static class PaymentSettingsActivity extends Settings { /* empty */ }
|
||||||
|
public static class PrintSettingsActivity extends Settings { /* empty */ }
|
||||||
}
|
}
|
||||||
|
@@ -50,6 +50,9 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.Filter;
|
||||||
|
import android.widget.Filterable;
|
||||||
|
import android.widget.SearchView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -284,10 +287,20 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
|||||||
menu.removeItem(R.id.print_menu_item_settings);
|
menu.removeItem(R.id.print_menu_item_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItem uninstall = menu.findItem(R.id.print_menu_item_uninstall);
|
MenuItem searchItem = menu.findItem(R.id.print_menu_item_search);
|
||||||
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE,
|
SearchView searchView = (SearchView) searchItem.getActionView();
|
||||||
Uri.parse("package:" + mComponentName.getPackageName()));
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
uninstall.setIntent(uninstallIntent);
|
@Override
|
||||||
|
public boolean onQueryTextSubmit(String query) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextChange(String searchString) {
|
||||||
|
((Filterable) getListView().getAdapter()).getFilter().filter(searchString);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private ToggleSwitch createAndAddActionBarToggleSwitch(Activity activity) {
|
private ToggleSwitch createAndAddActionBarToggleSwitch(Activity activity) {
|
||||||
@@ -325,21 +338,74 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class PrintersAdapter extends BaseAdapter
|
private final class PrintersAdapter extends BaseAdapter
|
||||||
implements LoaderManager.LoaderCallbacks<List<PrinterInfo>>{
|
implements LoaderManager.LoaderCallbacks<List<PrinterInfo>>, Filterable {
|
||||||
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
private final List<PrinterInfo> mPrinters = new ArrayList<PrinterInfo>();
|
private final List<PrinterInfo> mPrinters = new ArrayList<PrinterInfo>();
|
||||||
|
|
||||||
|
private final List<PrinterInfo> mFilteredPrinters = new ArrayList<PrinterInfo>();
|
||||||
|
|
||||||
|
private CharSequence mLastSearchString;
|
||||||
|
|
||||||
public PrintersAdapter() {
|
public PrintersAdapter() {
|
||||||
getLoaderManager().initLoader(LOADER_ID_PRINTERS_LOADER, null, this);
|
getLoaderManager().initLoader(LOADER_ID_PRINTERS_LOADER, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Filter getFilter() {
|
||||||
|
return new Filter() {
|
||||||
|
@Override
|
||||||
|
protected FilterResults performFiltering(CharSequence constraint) {
|
||||||
|
synchronized (mLock) {
|
||||||
|
if (TextUtils.isEmpty(constraint)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
FilterResults results = new FilterResults();
|
||||||
|
List<PrinterInfo> filteredPrinters = new ArrayList<PrinterInfo>();
|
||||||
|
String constraintLowerCase = constraint.toString().toLowerCase();
|
||||||
|
final int printerCount = mPrinters.size();
|
||||||
|
for (int i = 0; i < printerCount; i++) {
|
||||||
|
PrinterInfo printer = mPrinters.get(i);
|
||||||
|
if (printer.getName().toLowerCase().contains(constraintLowerCase)) {
|
||||||
|
filteredPrinters.add(printer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
results.values = filteredPrinters;
|
||||||
|
results.count = filteredPrinters.size();
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
|
synchronized (mLock) {
|
||||||
|
mLastSearchString = constraint;
|
||||||
|
mFilteredPrinters.clear();
|
||||||
|
if (results == null) {
|
||||||
|
mFilteredPrinters.addAll(mPrinters);
|
||||||
|
} else {
|
||||||
|
List<PrinterInfo> printers = (List<PrinterInfo>) results.values;
|
||||||
|
mFilteredPrinters.addAll(printers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return mPrinters.size();
|
synchronized (mLock) {
|
||||||
|
return mFilteredPrinters.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
return mPrinters.get(position);
|
synchronized (mLock) {
|
||||||
|
return mFilteredPrinters.get(position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -391,12 +457,19 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<List<PrinterInfo>> loader,
|
public void onLoadFinished(Loader<List<PrinterInfo>> loader,
|
||||||
List<PrinterInfo> printers) {
|
List<PrinterInfo> printers) {
|
||||||
mPrinters.clear();
|
synchronized (mLock) {
|
||||||
final int printerCount = printers.size();
|
mPrinters.clear();
|
||||||
for (int i = 0; i < printerCount; i++) {
|
final int printerCount = printers.size();
|
||||||
PrinterInfo printer = printers.get(i);
|
for (int i = 0; i < printerCount; i++) {
|
||||||
if (printer.getId().getServiceName().equals(mComponentName)) {
|
PrinterInfo printer = printers.get(i);
|
||||||
mPrinters.add(printer);
|
if (printer.getId().getServiceName().equals(mComponentName)) {
|
||||||
|
mPrinters.add(printer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mFilteredPrinters.clear();
|
||||||
|
mFilteredPrinters.addAll(mPrinters);
|
||||||
|
if (!TextUtils.isEmpty(mLastSearchString)) {
|
||||||
|
getFilter().filter(mLastSearchString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
@@ -404,7 +477,10 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoaderReset(Loader<List<PrinterInfo>> loader) {
|
public void onLoaderReset(Loader<List<PrinterInfo>> loader) {
|
||||||
mPrinters.clear();
|
synchronized (mLock) {
|
||||||
|
mPrinters.clear();
|
||||||
|
mFilteredPrinters.clear();
|
||||||
|
}
|
||||||
notifyDataSetInvalidated();
|
notifyDataSetInvalidated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment implements
|
|||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
inflater.inflate(R.menu.print_settings, menu);
|
inflater.inflate(R.menu.print_settings, menu);
|
||||||
MenuItem menuItem = menu.findItem(R.id.print_menu_item_download_print_service);
|
MenuItem menuItem = menu.findItem(R.id.print_menu_item_add_service);
|
||||||
menuItem.setIntent(new Intent(Intent.ACTION_VIEW,
|
menuItem.setIntent(new Intent(Intent.ACTION_VIEW,
|
||||||
Uri.parse(getString(R.string.download_print_service_query))));
|
Uri.parse(getString(R.string.download_print_service_query))));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user