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" />
|
||||
</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. -->
|
||||
<activity-alias android:name="DevelopmentSettings"
|
||||
android:exported="true"
|
||||
|
@@ -15,6 +15,14 @@
|
||||
-->
|
||||
|
||||
<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
|
||||
android:id="@+id/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:showAsAction="ifRoom">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/print_menu_item_uninstall"
|
||||
android:title="@string/print_menu_item_uninstall"
|
||||
android:showAsAction="never">
|
||||
</item>
|
||||
</menu>
|
||||
|
@@ -16,8 +16,8 @@
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/print_menu_item_download_print_service"
|
||||
android:title="@string/print_menu_item_download_print_service"
|
||||
android:id="@+id/print_menu_item_add_service"
|
||||
android:title="@string/print_menu_item_add_service"
|
||||
android:showAsAction="ifRoom">
|
||||
</item>
|
||||
</menu>
|
||||
|
@@ -3420,13 +3420,13 @@
|
||||
<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] -->
|
||||
<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] -->
|
||||
<string name="print_menu_item_add_printer">Add printer</string>
|
||||
|
||||
<!-- Title of the action bar button uninstall a print service. [CHAR LIMIT=25] -->
|
||||
<string name="print_menu_item_uninstall">Uninstall</string>
|
||||
<!-- Title for the search action bar menu item. [CHAR LIMIT=20] -->
|
||||
<string name="print_menu_item_search">Search</string>
|
||||
|
||||
<!-- Title for the printer categoty showing a list of available printers. [CHAR LIMIT=25] -->
|
||||
<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 TrustedCredentialsSettingsActivity 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.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -284,10 +287,20 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
||||
menu.removeItem(R.id.print_menu_item_settings);
|
||||
}
|
||||
|
||||
MenuItem uninstall = menu.findItem(R.id.print_menu_item_uninstall);
|
||||
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE,
|
||||
Uri.parse("package:" + mComponentName.getPackageName()));
|
||||
uninstall.setIntent(uninstallIntent);
|
||||
MenuItem searchItem = menu.findItem(R.id.print_menu_item_search);
|
||||
SearchView searchView = (SearchView) searchItem.getActionView();
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@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) {
|
||||
@@ -325,21 +338,74 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
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> mFilteredPrinters = new ArrayList<PrinterInfo>();
|
||||
|
||||
private CharSequence mLastSearchString;
|
||||
|
||||
public PrintersAdapter() {
|
||||
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
|
||||
public int getCount() {
|
||||
return mPrinters.size();
|
||||
synchronized (mLock) {
|
||||
return mFilteredPrinters.size();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mPrinters.get(position);
|
||||
synchronized (mLock) {
|
||||
return mFilteredPrinters.get(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -391,6 +457,7 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
||||
@Override
|
||||
public void onLoadFinished(Loader<List<PrinterInfo>> loader,
|
||||
List<PrinterInfo> printers) {
|
||||
synchronized (mLock) {
|
||||
mPrinters.clear();
|
||||
final int printerCount = printers.size();
|
||||
for (int i = 0; i < printerCount; i++) {
|
||||
@@ -399,12 +466,21 @@ public class PrintServiceSettingsFragment extends SettingsPreferenceFragment
|
||||
mPrinters.add(printer);
|
||||
}
|
||||
}
|
||||
mFilteredPrinters.clear();
|
||||
mFilteredPrinters.addAll(mPrinters);
|
||||
if (!TextUtils.isEmpty(mLastSearchString)) {
|
||||
getFilter().filter(mLastSearchString);
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<List<PrinterInfo>> loader) {
|
||||
synchronized (mLock) {
|
||||
mPrinters.clear();
|
||||
mFilteredPrinters.clear();
|
||||
}
|
||||
notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
|
@@ -111,7 +111,7 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment implements
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
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,
|
||||
Uri.parse(getString(R.string.download_print_service_query))));
|
||||
}
|
||||
|
Reference in New Issue
Block a user