Search in sources :

Example 16 with PrintJob

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

the class PrintJobSettingsFragment method updateUi.

private void updateUi() {
    PrintJob printJob = getPrintJob();
    if (printJob == null) {
        finish();
        return;
    }
    if (printJob.isCancelled() || printJob.isCompleted()) {
        finish();
        return;
    }
    PrintJobInfo info = printJob.getInfo();
    switch(info.getState()) {
        case PrintJobInfo.STATE_QUEUED:
        case PrintJobInfo.STATE_STARTED:
            {
                if (!printJob.getInfo().isCancelling()) {
                    mPrintJobPreference.setTitle(getString(R.string.print_printing_state_title_template, info.getLabel()));
                } else {
                    mPrintJobPreference.setTitle(getString(R.string.print_cancelling_state_title_template, info.getLabel()));
                }
            }
            break;
        case PrintJobInfo.STATE_FAILED:
            {
                mPrintJobPreference.setTitle(getString(R.string.print_failed_state_title_template, info.getLabel()));
            }
            break;
        case PrintJobInfo.STATE_BLOCKED:
            {
                if (!printJob.getInfo().isCancelling()) {
                    mPrintJobPreference.setTitle(getString(R.string.print_blocked_state_title_template, info.getLabel()));
                } else {
                    mPrintJobPreference.setTitle(getString(R.string.print_cancelling_state_title_template, info.getLabel()));
                }
            }
            break;
    }
    mPrintJobPreference.setSummary(getString(R.string.print_job_summary, info.getPrinterName(), DateUtils.formatSameDayTime(info.getCreationTime(), info.getCreationTime(), DateFormat.SHORT, DateFormat.SHORT)));
    switch(info.getState()) {
        case PrintJobInfo.STATE_QUEUED:
        case PrintJobInfo.STATE_STARTED:
            {
                mPrintJobPreference.setIcon(R.drawable.ic_print);
            }
            break;
        case PrintJobInfo.STATE_FAILED:
        case PrintJobInfo.STATE_BLOCKED:
            {
                mPrintJobPreference.setIcon(R.drawable.ic_print_error);
            }
            break;
    }
    CharSequence status = info.getStatus(getPackageManager());
    if (!TextUtils.isEmpty(status)) {
        if (getPreferenceScreen().findPreference(PRINT_JOB_MESSAGE_PREFERENCE) == null) {
            getPreferenceScreen().addPreference(mMessagePreference);
        }
        mMessagePreference.setSummary(status);
    } else {
        getPreferenceScreen().removePreference(mMessagePreference);
    }
    getActivity().invalidateOptionsMenu();
}
Also used : PrintJob(android.print.PrintJob) PrintJobInfo(android.print.PrintJobInfo)

Example 17 with PrintJob

use of android.print.PrintJob in project android_packages_apps_Settings by LineageOS.

the class PrintJobSettingsFragment method updateUi.

private void updateUi() {
    PrintJob printJob = getPrintJob();
    if (printJob == null) {
        finish();
        return;
    }
    if (printJob.isCancelled() || printJob.isCompleted()) {
        finish();
        return;
    }
    PrintJobInfo info = printJob.getInfo();
    switch(info.getState()) {
        case PrintJobInfo.STATE_QUEUED:
        case PrintJobInfo.STATE_STARTED:
            {
                if (!printJob.getInfo().isCancelling()) {
                    mPrintJobPreference.setTitle(getString(R.string.print_printing_state_title_template, info.getLabel()));
                } else {
                    mPrintJobPreference.setTitle(getString(R.string.print_cancelling_state_title_template, info.getLabel()));
                }
            }
            break;
        case PrintJobInfo.STATE_FAILED:
            {
                mPrintJobPreference.setTitle(getString(R.string.print_failed_state_title_template, info.getLabel()));
            }
            break;
        case PrintJobInfo.STATE_BLOCKED:
            {
                if (!printJob.getInfo().isCancelling()) {
                    mPrintJobPreference.setTitle(getString(R.string.print_blocked_state_title_template, info.getLabel()));
                } else {
                    mPrintJobPreference.setTitle(getString(R.string.print_cancelling_state_title_template, info.getLabel()));
                }
            }
            break;
    }
    mPrintJobPreference.setSummary(getString(R.string.print_job_summary, info.getPrinterName(), DateUtils.formatSameDayTime(info.getCreationTime(), info.getCreationTime(), DateFormat.SHORT, DateFormat.SHORT)));
    switch(info.getState()) {
        case PrintJobInfo.STATE_QUEUED:
        case PrintJobInfo.STATE_STARTED:
            {
                mPrintJobPreference.setIcon(R.drawable.ic_print);
            }
            break;
        case PrintJobInfo.STATE_FAILED:
        case PrintJobInfo.STATE_BLOCKED:
            {
                mPrintJobPreference.setIcon(R.drawable.ic_print_error);
            }
            break;
    }
    CharSequence status = info.getStatus(getPackageManager());
    if (!TextUtils.isEmpty(status)) {
        if (getPreferenceScreen().findPreference(PRINT_JOB_MESSAGE_PREFERENCE) == null) {
            getPreferenceScreen().addPreference(mMessagePreference);
        }
        mMessagePreference.setSummary(status);
    } else {
        getPreferenceScreen().removePreference(mMessagePreference);
    }
    getActivity().invalidateOptionsMenu();
}
Also used : PrintJob(android.print.PrintJob) PrintJobInfo(android.print.PrintJobInfo)

Example 18 with PrintJob

use of android.print.PrintJob in project android_packages_apps_Settings by omnirom.

the class PrintJobSettingsFragment method updateUi.

private void updateUi() {
    PrintJob printJob = getPrintJob();
    if (printJob == null) {
        finish();
        return;
    }
    if (printJob.isCancelled() || printJob.isCompleted()) {
        finish();
        return;
    }
    PrintJobInfo info = printJob.getInfo();
    switch(info.getState()) {
        case PrintJobInfo.STATE_QUEUED:
        case PrintJobInfo.STATE_STARTED:
            {
                if (!printJob.getInfo().isCancelling()) {
                    mPrintJobPreference.setTitle(getString(R.string.print_printing_state_title_template, info.getLabel()));
                } else {
                    mPrintJobPreference.setTitle(getString(R.string.print_cancelling_state_title_template, info.getLabel()));
                }
            }
            break;
        case PrintJobInfo.STATE_FAILED:
            {
                mPrintJobPreference.setTitle(getString(R.string.print_failed_state_title_template, info.getLabel()));
            }
            break;
        case PrintJobInfo.STATE_BLOCKED:
            {
                if (!printJob.getInfo().isCancelling()) {
                    mPrintJobPreference.setTitle(getString(R.string.print_blocked_state_title_template, info.getLabel()));
                } else {
                    mPrintJobPreference.setTitle(getString(R.string.print_cancelling_state_title_template, info.getLabel()));
                }
            }
            break;
    }
    mPrintJobPreference.setSummary(getString(R.string.print_job_summary, info.getPrinterName(), DateUtils.formatSameDayTime(info.getCreationTime(), info.getCreationTime(), DateFormat.SHORT, DateFormat.SHORT)));
    switch(info.getState()) {
        case PrintJobInfo.STATE_QUEUED:
        case PrintJobInfo.STATE_STARTED:
            {
                mPrintJobPreference.setIcon(R.drawable.ic_print);
            }
            break;
        case PrintJobInfo.STATE_FAILED:
        case PrintJobInfo.STATE_BLOCKED:
            {
                mPrintJobPreference.setIcon(R.drawable.ic_print_error);
            }
            break;
    }
    CharSequence status = info.getStatus(getPackageManager());
    if (!TextUtils.isEmpty(status)) {
        if (getPreferenceScreen().findPreference(PRINT_JOB_MESSAGE_PREFERENCE) == null) {
            getPreferenceScreen().addPreference(mMessagePreference);
        }
        mMessagePreference.setSummary(status);
    } else {
        getPreferenceScreen().removePreference(mMessagePreference);
    }
    getActivity().invalidateOptionsMenu();
}
Also used : PrintJob(android.print.PrintJob) PrintJobInfo(android.print.PrintJobInfo)

Example 19 with PrintJob

use of android.print.PrintJob in project android_packages_apps_Settings by omnirom.

the class PrintSettingsFragmentTest method testSummary_hasActiveJob_shouldSetSummaryToNumberOfJobs.

@Test
public void testSummary_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);
    mSummaryProvider.setListening(true);
    verify(mRes).getQuantityString(R.plurals.print_jobs_summary, 1, 1);
}
Also used : PrintJob(android.print.PrintJob) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 20 with PrintJob

use of android.print.PrintJob in project android_packages_apps_Settings by DirtyUnicorns.

the class PrintJobSettingsFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    PrintJob printJob = 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)

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