Loading packages/PrintSpooler/res/layout/no_print_services_message.xml 0 → 100644 +42 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeightSmall" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:orientation="horizontal" android:gravity="start|center_vertical"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginStart="32dip"> <HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceListItem" android:text="@string/print_no_print_services" android:scrollHorizontally="true" android:singleLine="true" /> </HorizontalScrollView> </RelativeLayout> </LinearLayout> packages/PrintSpooler/src/com/android/printspooler/ui/AddPrinterActivity.java +93 −6 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.Loader; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.DataSetObserver; import android.net.Uri; Loading Loading @@ -95,20 +96,39 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt */ private RecommendedServicesAdapter mRecommendedServicesAdapter; private static final String PKG_NAME_VENDING = "com.android.vending"; private boolean mHasVending; private NoPrintServiceMessageAdapter mNoPrintServiceMessageAdapter; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_printer_activity); try { getPackageManager().getPackageInfo(PKG_NAME_VENDING, 0); mHasVending = true; } catch (PackageManager.NameNotFoundException e) { mHasVending = false; } mEnabledServicesAdapter = new EnabledServicesAdapter(); mDisabledServicesAdapter = new DisabledServicesAdapter(); if (mHasVending) { mRecommendedServicesAdapter = new RecommendedServicesAdapter(); } else { mNoPrintServiceMessageAdapter = new NoPrintServiceMessageAdapter(); } ArrayList<ActionAdapter> adapterList = new ArrayList<>(3); adapterList.add(mEnabledServicesAdapter); if (mHasVending) { adapterList.add(mRecommendedServicesAdapter); } adapterList.add(mDisabledServicesAdapter); if (!mHasVending) { adapterList.add(mNoPrintServiceMessageAdapter); } setListAdapter(new CombinedAdapter(adapterList)); Loading @@ -119,8 +139,10 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt getLoaderManager().initLoader(LOADER_ID_ENABLED_SERVICES, null, printServiceLoaderCallbacks); getLoaderManager().initLoader(LOADER_ID_DISABLED_SERVICES, null, printServiceLoaderCallbacks); if (mHasVending) { getLoaderManager().initLoader(LOADER_ID_RECOMMENDED_SERVICES, null, new PrintServicePrintServiceRecommendationLoaderCallbacks()); } getLoaderManager().initLoader(LOADER_ID_ALL_SERVICES, null, printServiceLoaderCallbacks); } Loading Loading @@ -162,7 +184,11 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt mDisabledServicesAdapter.updateData(data); break; case LOADER_ID_ALL_SERVICES: if (mHasVending) { mRecommendedServicesAdapter.updateInstalledServices(data); } else { mNoPrintServiceMessageAdapter.updateInstalledServices(data); } default: // not reached } Loading @@ -179,7 +205,11 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt mDisabledServicesAdapter.updateData(null); break; case LOADER_ID_ALL_SERVICES: if (mHasVending) { mRecommendedServicesAdapter.updateInstalledServices(null); } else { mNoPrintServiceMessageAdapter.updateInstalledServices(null); } break; default: // not reached Loading Loading @@ -788,4 +818,61 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt filterRecommendations(); } } private class NoPrintServiceMessageAdapter extends ActionAdapter { private boolean mHasPrintService; void updateInstalledServices(@Nullable List<PrintServiceInfo> services) { if (services == null || services.isEmpty()) { mHasPrintService = false; } else { mHasPrintService = true; } notifyDataSetChanged(); } @Override public int getCount() { return mHasPrintService ? 0 : 1; } @Override public int getViewTypeCount() { return 1; } @Override public int getItemViewType(int position) { return 0; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = getLayoutInflater().inflate(R.layout.no_print_services_message, parent, false); } return convertView; } @Override public boolean isEnabled(int position) { return position != 0; } @Override public void performAction(@IntRange(from = 0) int position) { return; } } } Loading
packages/PrintSpooler/res/layout/no_print_services_message.xml 0 → 100644 +42 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeightSmall" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:orientation="horizontal" android:gravity="start|center_vertical"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginStart="32dip"> <HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceListItem" android:text="@string/print_no_print_services" android:scrollHorizontally="true" android:singleLine="true" /> </HorizontalScrollView> </RelativeLayout> </LinearLayout>
packages/PrintSpooler/src/com/android/printspooler/ui/AddPrinterActivity.java +93 −6 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.Loader; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.DataSetObserver; import android.net.Uri; Loading Loading @@ -95,20 +96,39 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt */ private RecommendedServicesAdapter mRecommendedServicesAdapter; private static final String PKG_NAME_VENDING = "com.android.vending"; private boolean mHasVending; private NoPrintServiceMessageAdapter mNoPrintServiceMessageAdapter; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_printer_activity); try { getPackageManager().getPackageInfo(PKG_NAME_VENDING, 0); mHasVending = true; } catch (PackageManager.NameNotFoundException e) { mHasVending = false; } mEnabledServicesAdapter = new EnabledServicesAdapter(); mDisabledServicesAdapter = new DisabledServicesAdapter(); if (mHasVending) { mRecommendedServicesAdapter = new RecommendedServicesAdapter(); } else { mNoPrintServiceMessageAdapter = new NoPrintServiceMessageAdapter(); } ArrayList<ActionAdapter> adapterList = new ArrayList<>(3); adapterList.add(mEnabledServicesAdapter); if (mHasVending) { adapterList.add(mRecommendedServicesAdapter); } adapterList.add(mDisabledServicesAdapter); if (!mHasVending) { adapterList.add(mNoPrintServiceMessageAdapter); } setListAdapter(new CombinedAdapter(adapterList)); Loading @@ -119,8 +139,10 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt getLoaderManager().initLoader(LOADER_ID_ENABLED_SERVICES, null, printServiceLoaderCallbacks); getLoaderManager().initLoader(LOADER_ID_DISABLED_SERVICES, null, printServiceLoaderCallbacks); if (mHasVending) { getLoaderManager().initLoader(LOADER_ID_RECOMMENDED_SERVICES, null, new PrintServicePrintServiceRecommendationLoaderCallbacks()); } getLoaderManager().initLoader(LOADER_ID_ALL_SERVICES, null, printServiceLoaderCallbacks); } Loading Loading @@ -162,7 +184,11 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt mDisabledServicesAdapter.updateData(data); break; case LOADER_ID_ALL_SERVICES: if (mHasVending) { mRecommendedServicesAdapter.updateInstalledServices(data); } else { mNoPrintServiceMessageAdapter.updateInstalledServices(data); } default: // not reached } Loading @@ -179,7 +205,11 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt mDisabledServicesAdapter.updateData(null); break; case LOADER_ID_ALL_SERVICES: if (mHasVending) { mRecommendedServicesAdapter.updateInstalledServices(null); } else { mNoPrintServiceMessageAdapter.updateInstalledServices(null); } break; default: // not reached Loading Loading @@ -788,4 +818,61 @@ public class AddPrinterActivity extends ListActivity implements AdapterView.OnIt filterRecommendations(); } } private class NoPrintServiceMessageAdapter extends ActionAdapter { private boolean mHasPrintService; void updateInstalledServices(@Nullable List<PrintServiceInfo> services) { if (services == null || services.isEmpty()) { mHasPrintService = false; } else { mHasPrintService = true; } notifyDataSetChanged(); } @Override public int getCount() { return mHasPrintService ? 0 : 1; } @Override public int getViewTypeCount() { return 1; } @Override public int getItemViewType(int position) { return 0; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = getLayoutInflater().inflate(R.layout.no_print_services_message, parent, false); } return convertView; } @Override public boolean isEnabled(int position) { return position != 0; } @Override public void performAction(@IntRange(from = 0) int position) { return; } } }