Пример #1
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.exit:
       finish();
       return true;
     case R.id.save:
       try {
         Results.getInstance().saveCurrentResults();
         finish();
       } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
       return true;
     case R.id.help:
       new HelpDialog(this, this.getText(R.string.listCreatorHelpMessage).toString()).show();
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
Пример #2
0
  @Override
  public void onCreate(Bundle savedInstance) {

    super.onCreate(savedInstance);
    mContext = this;

    setContentView(R.layout.display_results);
    View v = getLayoutInflater().inflate(R.layout.display_results_buttons_bottom, null);
    mAddItem = (Button) v.findViewById(R.id.addButton);
    mAddItem.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent in = new Intent(ShopAndShare.sContext, AddItem.class);
            startActivity(in);
            finish();
          }
        });
    mShare = (Button) v.findViewById(R.id.shareButton);
    mShare.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // Only allow the user to continue if there is network access
            if (isNetworkAvailable()) {
              if (isResultsPopulated()) {
                Intent in = new Intent(ShopAndShare.sContext, Share.class);
                startActivity(in);
              } else {
                new AlertDialog.Builder(mContext)
                    .setTitle(R.string.emptyResult)
                    .setMessage(mContext.getText(R.string.emptyResultMessage))
                    .show();
              }
            } else
              new AlertDialog.Builder(mContext)
                  .setTitle(R.string.networkDisabled)
                  .setMessage(mContext.getText(R.string.networkDisabledMessage))
                  .show();
          }
        });
    this.getListView().addFooterView(v);

    ArrayList<Item> products = new ArrayList<Item>();

    // If out activity has been started from the Take Photo chain, we should
    // check for an empty result
    if (this.getIntent().getBooleanExtra("Take Photo", false)
        && Results.getInstance().getProducts().isEmpty()) {
      Intent in = new Intent(ShopAndShare.sContext, EmptyResult.class);
      startActivity(in);
      finish();
    }

    Iterator i = Results.getInstance().getProducts().entrySet().iterator();

    while (i.hasNext()) {
      Map.Entry x = (Map.Entry) i.next();
      products.add((Item) x.getValue());
    }

    ItemAdapter adap = new ItemAdapter(this, R.layout.display_results_row, products);
    setListAdapter(adap);
  }
Пример #3
0
 /**
  * Returns a boolean on whether Results is populated or not
  *
  * @return boolean
  */
 private boolean isResultsPopulated() {
   if (Results.getInstance().getProducts().isEmpty()) return false;
   else return true;
 }