Ejemplo n.º 1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //		// Test
    //		try {
    //			new XMLTestImageSet(this, R.xml.frigidaire_dryer_faqe7072lw, 0);
    //		} catch (IOException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		} catch (XmlPullParserException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}
    //
    setContentView(R.layout.main);
    // This needs to be done first because many other components
    // depend on this global logger
    new GlobalLogger(this);
    mCV = new ComputerVision(this, this, this);
    mCV.initializeService();

    expandedImage = (ImageView) findViewById(R.id.exp_image);
    expandedImage.setScaleType(ImageView.ScaleType.FIT_CENTER);

    transformButton = (Button) findViewById(R.id.transformButton);
    transformButton.setEnabled(false);
    transformButton.setOnClickListener(this);

    searchButton = (ImageButton) findViewById(R.id.imageRetrieverButton);
    searchButton.setOnClickListener(this);

    ocrButton = (Button) findViewById(R.id.ocrButton);
    ocrButton.setOnClickListener(this);
    ocrButton.setEnabled(false);

    mSeekbarText = (TextView) findViewById(R.id.threshhold_seekbar_textview);
    mExpandedImageText = (TextView) findViewById(R.id.exp_image_text);
    // List of features
    featureDetectorSpinner = (Spinner) findViewById(R.id.features);

    // list of methods
    homoMethodSpinner = (Spinner) findViewById(R.id.homography_methods);

    // Threshold chooser
    threshhold = (SeekBar) findViewById(R.id.threshold_seekbar);
    threshhold.setMax(TransformationBuilder.RANSAC_THRESHHOLD_MAX);
    threshhold.setOnSeekBarChangeListener(this);

    //		(SlidingDrawer) findViewById(R.id.slidingDrawer);

    // Adpater for managing images to be displayed in gallery
    mImageAdapter = new OrganizedImageSelectionAdapter(this);

    // Gallery for displaying images
    mGallery = (Gallery) findViewById(R.id.gallery);
    mGallery.setAdapter(mImageAdapter);

    mGallery.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          @Override
          public boolean onItemLongClick(
              AdapterView<?> listView, View view, int position, long id) {

            boolean isRefOROther = position == 1 || position == 0;
            final int pos = position;
            // If the position is 0,1 or reference or other
            // and if default image
            // Ask to query
            if (isRefOROther && mImageAdapter.isDefaultImage(position)) {
              searchButton.setEnabled(false);
              searchButton.setVisibility(ImageButton.INVISIBLE);
              // If default image => Search needs to occur
              getImageForPosition(pos);
            } else {
              // if reference or other image but currently
              // has another image inside it
              if (isRefOROther) {
                searchButton.setEnabled(true);
                searchButton.setVisibility(ImageButton.VISIBLE);
                searchButton.setOnClickListener(
                    new OnClickListener() {

                      @Override
                      public void onClick(View v) {
                        getImageForPosition(pos);
                      }
                    });
              } // Now we need to bring up the image in expanded view
              Bitmap image = mImageAdapter.getImage(position);
              if (image != null) {
                expandedImage.setImageBitmap(image);
                String message = mImageAdapter.getTitle(image);
                mExpandedImageText.setText(message);
              }
            }
            return false;
          }
        });
  }
Ejemplo n.º 2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // open up the DbAdaptor
    db.open();

    // gives us more screen space
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // need to do this because the camera doesn't do portrait mode
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    // initialize all our views.
    LayoutInflater inflater = getLayoutInflater();
    viewCaptureNote = inflater.inflate(R.layout.view_capture_note, null);
    viewNote = inflater.inflate(R.layout.view_note, null);
    viewTagList = inflater.inflate(R.layout.view_tag_list, null);
    viewNoteGallery = inflater.inflate(R.layout.view_note_gallery, null);

    // set the content view initially to save notes
    setContentView(viewCaptureNote);

    // set up the click listeners for the camera preview screen
    CameraPreview cameraPreview = (CameraPreview) findViewById(R.id.surface);
    findViewById(R.id.discard).setOnClickListener(cameraPreview);
    findViewById(R.id.take).setOnClickListener(cameraPreview);
    findViewById(R.id.save_untagged).setOnClickListener(cameraPreview);
    findViewById(R.id.save_and_tag).setOnClickListener(cameraPreview);

    // set up the 'view untagged' option in the list menu
    View someView = viewTagList.findViewById(R.id.tag_list_untagged);
    someView.findViewById(R.id.tag_subtags).setVisibility(View.GONE);
    ((TextView) someView.findViewById(R.id.tag_name)).setText("Click to view untagged notes");
    someView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Gallery g = (Gallery) viewNoteGallery.findViewById(R.id.note_gallery);
            g.setAdapter(new NoteGalleryImageAdaptor(SBActivity.this, db.getUntaggedNotes()));
            setContentView(viewNoteGallery);
          }
        });

    // set the list adaptor for our tag list
    final ListView lv = (ListView) viewTagList.findViewById(R.id.item_list);
    lv.setAdapter(new TagViewListAdaptor(this, db.getTagList()));
    registerForContextMenu(lv);
    lv.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            TextView v = (TextView) view.findViewById(R.id.tag_subtags);
            v.setVisibility(v.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
            long tagId = (Long) view.findViewById(R.id.tag_name).getTag();
            if (v.getVisibility() == View.VISIBLE) {
              int subtagCount = 0;
              StringBuilder subTags = new StringBuilder("Sub-tags: ");
              Cursor c = db.getSubTags(tagId);
              while (c.moveToNext()) {
                subTags.append(c.getString(1) + " ");
                subtagCount++;
              }
              if (subtagCount > 0) v.setText(subTags);
              else v.setText("No sub-tags.");
            }
          }
        });
    lv.setOnCreateContextMenuListener(
        new View.OnCreateContextMenuListener() {
          public void onCreateContextMenu(
              ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            menu.setHeaderIcon(android.R.drawable.ic_menu_info_details);
            ListView lv = (ListView) viewTagList.findViewById(R.id.item_list);
            Cursor listItem =
                (Cursor)
                    lv.getItemAtPosition(((AdapterView.AdapterContextMenuInfo) menuInfo).position);
            String tagName = listItem.getString(1);
            menu.setHeaderTitle("Tag '" + tagName + "'");
            menu.add(0, CONTEXT_VIEW_NOTES, 0, "View notes tagged with '" + tagName + "'");
            menu.add(0, CONTEXT_DELETE_TAG, 0, "Delete tag");
          }
        });

    // set up click listeners for add tag
    viewTagList
        .findViewById(R.id.save_tag)
        .setOnClickListener(
            new View.OnClickListener() {
              public void onClick(View view) {
                EditText editText = (EditText) viewTagList.findViewById(R.id.tag_id);
                if (editText.getText().length() == 0) return;
                db.addNewTag(editText.getText());
                ((TagViewListAdaptor) lv.getAdapter()).refreshData();
                Toast.makeText(
                        SBActivity.this,
                        "Tag '" + editText.getText() + "' added.",
                        Toast.LENGTH_SHORT)
                    .show();
                editText.setText("");
              }
            });
    viewTagList.setOnFocusChangeListener(
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View view, boolean b) {
            Log.i(TAG, "Focus changed innit: " + b);
            if (b) ((TagViewListAdaptor) lv.getAdapter()).refreshData();
          }
        });

    // set up our note viewing gallery
    final Gallery g = (Gallery) viewNoteGallery.findViewById(R.id.note_gallery);
    g.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            // set the note number i.e. 1/3
            ((TextView) viewNoteGallery.findViewById(R.id.gallery_note_number))
                .setText((i + 1) + " / " + g.getCount());

            // set the date field
            Date d = new Date(((Note) view.getTag()).getSaveTime());
            ((TextView) viewNoteGallery.findViewById(R.id.gallery_note_date))
                .setText(DateFormat.getDateTimeInstance().format(d));

            // set the tag field
            Cursor c = db.getTagListForImg(l);
            StringBuilder sb = new StringBuilder();
            while (c.moveToNext()) {
              if (c.getInt(2) == 0) continue;
              sb.append(c.getString(1));
              sb.append(", ");
            }
            // delete the last 2 chars: ", "
            if (sb.length() > 0) sb.delete(sb.length() - 2, sb.length());
            else sb.append("none");
            ((TextView) viewNoteGallery.findViewById(R.id.gallery_note_tags))
                .setText(sb.toString());
          }

          @Override
          public void onNothingSelected(AdapterView<?> adapterView) {}
        });
    g.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {

            return true;
          }
        });
    viewNoteGallery
        .findViewById(R.id.note_gallery_examine)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                Note n = (Note) ((View) g.getSelectedView()).getTag();
                setViewSingleNote(n.getFileName());
              }
            });

    Handler btProgressHandler =
        new Handler() {
          public void handleMessage(Message msg) {
            if (btProgressDialog == null) return;
            switch (msg.what) {
              case BluetoothService.MSG_CONNECTED:
                btProgressDialog.setMessage("Bluetooth connected! Sending updates...");
                break;
              case BluetoothService.MSG_RECEIVING:
                btProgressDialog.setMessage("Receiving updates from computer..");
                break;
              case BluetoothService.MSG_PROGRESS:
                int cur = msg.arg1;
                int max = msg.arg2;
                btProgressDialog.setProgress(cur);
                btProgressDialog.setMax(max);
                break;
              case BluetoothService.MSG_DONE:
                btProgressDialog.dismiss();
                break;
            }
          }
        };
    bService.setProgressHandler(btProgressHandler);
  }
Ejemplo n.º 3
0
  private void initializeGallery() {
    notificationCounter = Utilities.updateNotificationCounter(getContacts());

    offers_gallery = (Gallery) findViewById(R.id.galleryOffers);
    // image_selected = (ImageView) findViewById(R.id.imageSelected);

    Log.d(TAG, "offers_gallery created");
    ImageAdapterCircleGallery galleryAdapter = new ImageAdapterCircleGallery(this);

    // if (offers_images == null) {
    offers_images = new Drawable[shoppingoffers.size()];
    int i = 0;
    for (Offer offer : shoppingoffers) {
      offers_images[i] = offer.getImageFile();
      // Log.d(TAG, "offers_image " + i + offers_images[i].toString());
      i = i + 1;
    }
    // }

    //		Log.d(TAG, "shopping offers: " + shoppingoffers.size());
    //		Log.d(TAG, "offers images drawables: " + offers_images.length);

    galleryAdapter.setmImageDrawables(offers_images);

    //		Log.d(TAG, "gallery drawables: "
    //				+ galleryAdapter.getmImageDrawables().length);
    offers_gallery.setAdapter(galleryAdapter);
    galleryAdapter.notifyDataSetChanged();

    offers_gallery.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          public void onItemSelected(AdapterView<?> arg0, View v, int position, long id) {
            // Toast.makeText(OffersActivity.this, "" + position,
            // Toast.LENGTH_SHORT).show();

            // image_selected.setImageDrawable(shoppingoffers.get(position).getImageFile());
            TextView message = (TextView) findViewById(R.id.captionOffersText);
            User user = shoppingoffers.get(position).getSharedByUser();
            String username = user.getFullName();
            String text = "Fra " + username + "d. " + shoppingoffers.get(position).getPublished();

            message.setText(text);
            // message.setTextColor(R.color.mygreen);

          }

          public void onNothingSelected(AdapterView<?> arg0) {
            // image_selected.setImageDrawable(shoppingoffers.get(0).getImageFile());

          }
        });

    offers_gallery.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Drawable drawable = (Drawable) parent.getAdapter().getItem(position);

            startFullscreenImageView(drawable);
            return false;
          }
        });
  }