use of android.print.PrintJob in project android_packages_apps_Settings by omnirom.
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());
}
use of android.print.PrintJob in project android_packages_apps_Settings by omnirom.
the class PrintJobPreferenceController method updateUi.
@Override
protected void updateUi() {
final PrintJob printJob = getPrintJob();
if (printJob == null) {
mFragment.finish();
return;
}
if (printJob.isCancelled() || printJob.isCompleted()) {
mFragment.finish();
return;
}
PrintJobInfo info = printJob.getInfo();
switch(info.getState()) {
case PrintJobInfo.STATE_CREATED:
{
mPreference.setTitle(mContext.getString(R.string.print_configuring_state_title_template, info.getLabel()));
}
break;
case PrintJobInfo.STATE_QUEUED:
case PrintJobInfo.STATE_STARTED:
{
if (!printJob.getInfo().isCancelling()) {
mPreference.setTitle(mContext.getString(R.string.print_printing_state_title_template, info.getLabel()));
} else {
mPreference.setTitle(mContext.getString(R.string.print_cancelling_state_title_template, info.getLabel()));
}
}
break;
case PrintJobInfo.STATE_FAILED:
{
mPreference.setTitle(mContext.getString(R.string.print_failed_state_title_template, info.getLabel()));
}
break;
case PrintJobInfo.STATE_BLOCKED:
{
if (!printJob.getInfo().isCancelling()) {
mPreference.setTitle(mContext.getString(R.string.print_blocked_state_title_template, info.getLabel()));
} else {
mPreference.setTitle(mContext.getString(R.string.print_cancelling_state_title_template, info.getLabel()));
}
}
break;
}
mPreference.setSummary(mContext.getString(R.string.print_job_summary, info.getPrinterName(), DateUtils.formatSameDayTime(info.getCreationTime(), info.getCreationTime(), DateFormat.SHORT, DateFormat.SHORT)));
TypedArray a = mContext.obtainStyledAttributes(new int[] { android.R.attr.colorControlNormal });
int tintColor = a.getColor(0, 0);
a.recycle();
switch(info.getState()) {
case PrintJobInfo.STATE_QUEUED:
case PrintJobInfo.STATE_STARTED:
{
Drawable icon = mContext.getDrawable(com.android.internal.R.drawable.ic_print);
icon.setTint(tintColor);
mPreference.setIcon(icon);
break;
}
case PrintJobInfo.STATE_FAILED:
case PrintJobInfo.STATE_BLOCKED:
{
Drawable icon = mContext.getDrawable(com.android.internal.R.drawable.ic_print_error);
icon.setTint(tintColor);
mPreference.setIcon(icon);
break;
}
}
}
use of android.print.PrintJob in project android_packages_apps_Settings by omnirom.
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);
}
}
use of android.print.PrintJob in project android_packages_apps_Settings by omnirom.
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);
}
use of android.print.PrintJob in project android_packages_apps_Settings by omnirom.
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));
}
Aggregations