welcome to linkAR technical documentation

next previous

Initiating ARMatcher


In BoxOfficeMatcherActivity we have

  private static final String API_KEY = "0YpBx5XDf09CrCJBvHw=";
  private ARmatcher aRmatcher;			

The API_KEY is only valid for the sample package: com.arlab.boxofficematcher
In the OnCreate of BoxOfficeMatcherActivity we have:

  public void onCreate(Bundle savedInstanceState) {
 
    /**1.- Create an instance of the ARmatcher object. */
    if(((double)screenheight)/((double)screenwidth)>1)
      aRmatcher = new A  Rmatcher(this,API_KEY,ARmatcher.SCREEN_ORIENTATION_PORTRAIT,
                                                             screenwidth,screenheight, true);
    else
      aRmatcher = new ARmatcher(this,API_KEY,ARmatcher.SCREEN_ORIENTATION_LANDSCAPE,
                                                             screenwidth,screenheight, true);
 
    /**2.- Set the type of the matching. */
    aRmatcher.setMatchingType(ARmatcher.IMAGE_MATCHER);
 
    /**3.- Enable median filter ,witch help to reduce noise and mismatches in IMAGE matching .  
    (Optional) */
    aRmatcher.enableMedianFilter(true);
 
    /**4.- Set minimum image quality threshold ,for image to be accepted to the image pool*/
    aRmatcher.setImageQuality(ImagePoolQuality);
 
    /**5.- Set image and QR matching callbacks */
    aRmatcher.setImageRecognitionCallback(this);
 
    /**
    * 6.- Add camera view instance to the matcher tab
    */
    LinearLayout matcherTabLayout = (LinearLayout) findViewById(R.id.matcherTab);
    matcherTabLayout.addView(aRmatcher.getCameraViewInstance());
 
  } // En onCreate method
  1. Initiates the Matcher, setting the screen mode in Portrait orientation. Also we indicate the exact width and height that we want for our matcher view (the library will search for the closest allowed size).
  2. As we do not want QR recognition, we set only Image Matcher.
  3. In this case, we use the camera as input, then the median filter is recommended.
  4. We would like to accept only very good images, so we set the image quality to its best.
  5. Set image and QR matching callbacks
  6. Finally we add the camera view to our view container (R.id.matcherTab).

The method onResume and onPause of BoxOfficeMatcherActivity are crucial in the initialization:

  @Override
  protected void onResume() {
    super.onResume();
 
    /* Start matcher view */
    aRmatcher.start();
  }
 
  @Override
  protected void onPause() {
    super.onPause();
 
    /* Stop matcher view */
    aRmatcher.stop();
  }
 

Also, in this case, as we have different tabs, we need to initiate them:

  /**
  * Initiation of tab views
  */
  private void initTabView()
  {
    //1
    tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setOnTabChangedListener(this);
 
    //2
    View matcherMapView = LayoutInflater.from(this).inflate(R.layout.tab_matcher_layout, null);
    View listView = LayoutInflater.from(this).inflate(R.layout.tab_llist_layout, null);
 
    //3
    TabSpec matcherTabSpec = tabHost.newTabSpec(AR_MATCHER_TAB).
                    setIndicator(matcherMapView).setContent(R.id.matcherTab);
 
    Intent intent = new Intent(this,MovieListView.class);
    TabSpec listTabSpec = tabHost.newTabSpec(MOVIES_LIST_TAB).
                    setIndicator(listView).setContent(intent);
 
    //4
    tabHost.addTab(matcherTabSpec);
    tabHost.addTab(listTabSpec);
 
    tabHost.setCurrentTab(0);
  }
 
  /** Controls the matcher library process*/
  public void onTabChanged(String arg0) {
 
    //5
    if(aRmatcher != null)
    {
      if (arg0.equals(AR_MATCHER_TAB)) {
        aRmatcher.start();
      }
      else if (arg0.equals(MOVIES_LIST_TAB)) {
	popup.setVisibility(View.INVISIBLE);
	aRmatcher.stop();
      }
    }				
  }
  1. We grab the TabHost element and set our activity as the TabChangeListener.
  2. We create (inflate) the two view layouts.
  3. Consider that our BoxOfficeMatcherActivity is Tab Manager and the first Tab option. You can consider MovieListView as a child activity.
  4. We add the tabs into our tab host.
  5. In the OnTabChanged listener method, we manage the library stop and resume.

How we add the poster Images is explained later.

next previous