Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Commit

Permalink
Refactor PrinterSelectScreen.java
Browse files Browse the repository at this point in the history
  • Loading branch information
nleven committed Dec 7, 2012
1 parent 22082bd commit 26e7d5e
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/com/engineering/printer/PrinterSelectScreen.java
Expand Up @@ -29,7 +29,6 @@
public class PrinterSelectScreen extends Activity {
private static final String PRINTER_PREF = "SEASPrintingFavorite";
private static final String PRINTER_HISTORY_KEY = "PrinterHistory";
private String mChosenPrinter;

private Document mDocument;

Expand Down Expand Up @@ -71,6 +70,7 @@ public void onCreate(Bundle savedInstanceState) {
printerHistory = new HistoryManager(PrinterSelectScreen.this, PRINTER_PREF, PRINTER_HISTORY_KEY, 4);

//Set up controls
mSpinner = (Spinner) findViewById(R.id.printer_spinner);
mDuplexCheck = (Checkable) findViewById(R.id.duplex_check);
mFitToPageCheck = (Checkable) findViewById(R.id.fitpage_check);

Expand All @@ -81,10 +81,12 @@ public void onCreate(Bundle savedInstanceState) {
mPrintbutton = (Button) findViewById(R.id.print_button);
mPrintbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
printerHistory.putHistory(mChosenPrinter);
// PRINT
String chosenPrinter = mSpinner.getSelectedItem().toString();
printerHistory.putHistory(chosenPrinter);

PrinterOptions options = new PrinterOptions(mDuplexCheck.isChecked(), mFitToPageCheck.isChecked(), mNumberPicker.value, mPageOrientation.getText().toString(), null);
PrintJobInfo job = new PrintJobInfo(mDocument, mChosenPrinter, options);
PrintJobInfo job = new PrintJobInfo(mDocument, chosenPrinter, options);

if(!mDocument.isRemote())
new UploadFileTask(PrinterSelectScreen.this).execute(job);
Expand Down Expand Up @@ -173,19 +175,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}

public class MyOnItemSelectedListener implements
OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
// PRINTER WAS SELECTED
mChosenPrinter = parent.getItemAtPosition(pos).toString();
}

public void onNothingSelected(AdapterView<?> parent) {
// Do nothing.
}
}

private class EnumeratePrintersTask extends AsyncTask<Void, Void, Boolean> {
private ProgressDialog pd;
private List<String> ps;
Expand Down Expand Up @@ -248,10 +237,8 @@ protected void onPostExecute(Boolean result) {
adp.addSection("RECENT", adpHistories);
adp.addSection("ALL PRINTERS", adpPrinters);


mSpinner = (Spinner) findViewById(R.id.printer_spinner);
mSpinner.setAdapter(adp);
mSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

if(!adpHistories.isEmpty()){
mSpinner.setSelection(1); //Select most recent printer
}
Expand Down

0 comments on commit 26e7d5e

Please sign in to comment.