Search in sources :

Example 26 with PrintJob

use of android.print.PrintJob in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PrintSettingsPreferenceControllerTest method updateState_hasActiveJob_shouldSetSummaryToNumberOfJobs.

@Test
public void updateState_hasActiveJob_shouldSetSummaryToNumberOfJobs() {
    final List<PrintJob> printJobs = new ArrayList<>();
    final PrintJob job = mock(PrintJob.class, Mockito.RETURNS_DEEP_STUBS);
    printJobs.add(job);
    when(job.getInfo().getState()).thenReturn(PrintJobInfo.STATE_STARTED);
    when(mPrintManager.getPrintJobs()).thenReturn(printJobs);
    mController.updateState(mPreference);
    assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources().getQuantityString(R.plurals.print_jobs_summary, 1, 1));
}
Also used : PrintJob(android.print.PrintJob) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 27 with PrintJob

use of android.print.PrintJob in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PrintJobMessagePreferenceController method updateUi.

@Override
protected void updateUi() {
    final PrintJob printJob = getPrintJob();
    if (printJob == null) {
        mFragment.finish();
        return;
    }
    if (printJob.isCancelled() || printJob.isCompleted()) {
        mFragment.finish();
        return;
    }
    final PrintJobInfo info = printJob.getInfo();
    final CharSequence status = info.getStatus(mContext.getPackageManager());
    mPreference.setVisible(!TextUtils.isEmpty(status));
    mPreference.setSummary(status);
}
Also used : PrintJob(android.print.PrintJob) PrintJobInfo(android.print.PrintJobInfo)

Example 28 with PrintJob

use of android.print.PrintJob in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PrintJobSettingsFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    final PrintJob printJob = use(PrintJobPreferenceController.class).getPrintJob();
    if (printJob == null) {
        return;
    }
    if (!printJob.getInfo().isCancelling()) {
        MenuItem cancel = menu.add(0, MENU_ITEM_ID_CANCEL, Menu.NONE, getString(R.string.print_cancel));
        cancel.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
    if (printJob.isFailed()) {
        MenuItem restart = menu.add(0, MENU_ITEM_ID_RESTART, Menu.NONE, getString(R.string.print_restart));
        restart.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}
Also used : PrintJob(android.print.PrintJob) MenuItem(android.view.MenuItem)

Example 29 with PrintJob

use of android.print.PrintJob in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PrintSettingPreferenceController method getSummary.

@Override
public CharSequence getSummary() {
    final List<PrintJob> printJobs = mPrintManager.getPrintJobs();
    int numActivePrintJobs = 0;
    if (printJobs != null) {
        for (PrintJob job : printJobs) {
            if (shouldShowToUser(job.getInfo())) {
                numActivePrintJobs++;
            }
        }
    }
    if (numActivePrintJobs > 0) {
        return mContext.getResources().getQuantityString(R.plurals.print_jobs_summary, numActivePrintJobs, numActivePrintJobs);
    } else {
        final List<PrintServiceInfo> services = mPrintManager.getPrintServices(PrintManager.ENABLED_SERVICES);
        if (services == null || services.isEmpty()) {
            return mContext.getText(R.string.print_settings_summary_no_service);
        } else {
            final int count = services.size();
            return mContext.getResources().getQuantityString(R.plurals.print_settings_summary, count, count);
        }
    }
}
Also used : PrintJob(android.print.PrintJob) PrintServiceInfo(android.printservice.PrintServiceInfo)

Example 30 with PrintJob

use of android.print.PrintJob in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PrintJobSettingsActivityTest method viewPrintJobSettings.

@Test
@LargeTest
public void viewPrintJobSettings() throws Exception {
    UUID uuid = UUID.randomUUID();
    Object isWriteCalled = new Object();
    // Create adapter that is good enough to start a print preview
    PrintDocumentAdapter adapter = new PrintDocumentAdapter() {

        @Override
        public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
            callback.onLayoutFinished(new PrintDocumentInfo.Builder(uuid.toString()).build(), true);
        }

        @Override
        public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
            synchronized (isWriteCalled) {
                isWriteCalled.notify();
            }
            callback.onWriteFailed(null);
        }
    };
    Activity activity = mActivityRule.getActivity();
    PrintManager pm = mActivityRule.getActivity().getSystemService(PrintManager.class);
    // Start printing
    PrintJob printJob = pm.print(uuid.toString(), adapter, null);
    // Wait until print preview is up
    synchronized (isWriteCalled) {
        isWriteCalled.wait();
    }
    // Start print job settings
    Intent intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS);
    intent.putExtra(EXTRA_PRINT_JOB_ID, printJob.getId().flattenToString());
    intent.setData(Uri.fromParts("printjob", printJob.getId().flattenToString(), null));
    activity.startActivity(intent);
    UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    UiObject2 printPrefTitle = uiDevice.wait(Until.findObject(By.text("Configuring " + uuid.toString())), 5000);
    assertNotNull(printPrefTitle);
    Log.i(LOG_TAG, "Found " + printPrefTitle.getText());
}
Also used : PrintJob(android.print.PrintJob) Bundle(android.os.Bundle) UiDevice(android.support.test.uiautomator.UiDevice) Activity(android.app.Activity) Intent(android.content.Intent) PrintAttributes(android.print.PrintAttributes) PrintManager(android.print.PrintManager) ParcelFileDescriptor(android.os.ParcelFileDescriptor) UUID(java.util.UUID) PrintDocumentAdapter(android.print.PrintDocumentAdapter) CancellationSignal(android.os.CancellationSignal) UiObject2(android.support.test.uiautomator.UiObject2) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

PrintJob (android.print.PrintJob)31 PrintJobInfo (android.print.PrintJobInfo)11 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 MenuItem (android.view.MenuItem)7 PrintDocumentAdapter (android.print.PrintDocumentAdapter)3 PrintManager (android.print.PrintManager)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 TypedArray (android.content.res.TypedArray)2 Drawable (android.graphics.drawable.Drawable)2 Bundle (android.os.Bundle)2 CancellationSignal (android.os.CancellationSignal)2 ParcelFileDescriptor (android.os.ParcelFileDescriptor)2 PrintAttributes (android.print.PrintAttributes)2 PrintServiceInfo (android.printservice.PrintServiceInfo)2 UiDevice (android.support.test.uiautomator.UiDevice)2 UiObject2 (android.support.test.uiautomator.UiObject2)2 LargeTest (androidx.test.filters.LargeTest)2 UUID (java.util.UUID)2