Пример #1
0
 private void setControls() {
   layout = (CupsTableLayout) findViewById(R.id.printjobLayout);
   layout.reset();
   layout.setShowName(false);
   for (PpdSectionList group : cupsppd.getPpdRec().getStdList()) {
     layout.addSection(group);
   }
   layout.addView(
       buttonRow,
       new TableLayout.LayoutParams(
           ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
   uiSet = true;
 }
Пример #2
0
  private void setStdOpts() {

    for (PpdSectionList group : cupsppd.getPpdRec().getStdList()) {
      for (PpdItemList section : group) {
        if (section.getName().equals("fit-to-page")) {
          if (isImage) section.setSavedValue("true");
        } else if (section.getName().equals("orientation-requested")) {
          if (!(printerConfig.orientation.equals(""))) {
            section.setSavedValue(printerConfig.orientation);
            section.setDefaultValue("-1");
          }
        }
      }
    }
  }
Пример #3
0
 private void setPrint(String stdAttrs) {
   String ppdAttrs = "";
   if (moreClicked) {
     if (cupsppd != null) ppdAttrs = cupsppd.getCupsExtraString();
   }
   if (!(stdAttrs.equals("")) && !(ppdAttrs.equals(""))) {
     stdAttrs = stdAttrs + "#" + ppdAttrs;
   } else {
     stdAttrs = stdAttrs + ppdAttrs;
   }
   if (!(stdAttrs.equals(""))) {
     attributes = new HashMap<String, String>();
     attributes.put("job-attributes", stdAttrs);
   }
   AuthInfo auth = null;
   if (!(printerConfig.password).equals("")) {
     auth = new AuthInfo(printerConfig.userName, printerConfig.password);
   }
   doPrint(auth);
 }
Пример #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_print_job);
    Intent intent = getIntent();
    String type = intent.getStringExtra("type");
    String sPrinter;
    if (type.equals("static")) {
      sPrinter = intent.getStringExtra("printer");
      PrintQueueIniHandler ini = new PrintQueueIniHandler(getBaseContext());
      printerConfig = ini.getPrinter(sPrinter);
    } else {
      sPrinter = intent.getStringExtra("name");
      printerConfig =
          new PrintQueueConfig(
              intent.getStringExtra("name"),
              intent.getStringExtra("protocol"),
              intent.getStringExtra("host"),
              intent.getStringExtra("port"),
              intent.getStringExtra("queue"));
      printerConfig.userName = "******";
      printerConfig.password = "";
    }
    if (printerConfig == null) {
      new AlertDialog.Builder(this)
          .setTitle("Error")
          .setMessage("Config for " + sPrinter + " not found")
          .setIcon(android.R.drawable.ic_dialog_alert)
          .setPositiveButton(
              android.R.string.ok,
              new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                  finish();
                }
              })
          .show();
      return;
    }
    data = intent.getData();
    if (data == null) {
      this.doFinish("File URI is null");
      return;
    }
    fileName = getFileName();
    String[] fileParts = fileName.split("\\.");
    String ext = "";
    if (fileParts.length > 1) {
      ext = fileParts[fileParts.length - 1].toLowerCase(Locale.ENGLISH);
    }
    if (!ext.equals("")) {
      mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
    }
    if (mimeType == null) {
      mimeType = "";
    }
    if (mimeType.equals("")) {
      mimeType = intent.getStringExtra("mimeType");
    }
    try {
      cupsClient = new CupsClient(Util.getClientURL(printerConfig));
    } catch (Exception e) {
      this.doFinish("Invalid ULR " + Util.getClientUrlStr(printerConfig));
      return;
    }
    cupsClient.setUserName(printerConfig.userName);
    AuthInfo auth = null;
    if (!(printerConfig.password.equals(""))) {
      auth = new AuthInfo(printerConfig.userName, printerConfig.password);
    }
    getPrinterTask = new GetPrinterTask(cupsClient, auth, Util.getQueue(printerConfig), true);
    getPrinterTask.setListener(this);
    try {
      getPrinterTask.execute().get(5000, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
      doFinish(e.toString());
      return;
    }

    cupsPrinter = getPrinterTask.getPrinter();
    getPrinterTask = null;
    if (cupsPrinter == null) {
      doFinish("Get printer failed");
      return;
    }

    if (!cupsPrinter.mimeTypeSupported(mimeType)) {
      setAcceptMimeType(mimeType, extension);
    } else {
      mimeTypeSupported = true;
    }
    if (mimeType.contains("image")) isImage = true;
    else isImage = false;

    auth = null;
    if (!(printerConfig.password.equals(""))) {
      auth = new AuthInfo(printerConfig.userName, printerConfig.password);
    }
    cupsppd = new CupsPpd(auth);
    if (printerConfig.noOptions) {
      if (mimeTypeSupported) {
        setStdOpts();
        setPrint(cupsppd.getCupsStdString());
        return;
      }
    }

    printButton = getButton("Print");
    printButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            printButton.setFocusableInTouchMode(true);
            printButton.requestFocus();
            if (!layout.update()) return;
            String stdAttrs = cupsppd.getCupsStdString();
            setPrint(stdAttrs);
          }
        });

    moreButton = getButton("More...");
    moreButton.setEnabled(true);
    moreButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            doGroup();
          }
        });
    byte[] md5 = null;
    GetPpdTask getPpdTask = new GetPpdTask(cupsPrinter, cupsppd, md5);
    getPpdTask.get(Thread.NORM_PRIORITY);
    // should check exception here
    setStdOpts();
    buttonRow = new TableRow(this);
    buttonRow.addView(moreButton);
    buttonRow.addView(printButton);
    setControls();
  }