Android Basic Sample Guide

We present here a coding guide for Android Basic Version's sample project. Please proceed as instructed in the below.

  1. For your first development, add *.so files and mcubemaplib.jar files which you downloaded as in the below image.


     
  2. Create instance of sampleappManager in SampleMapViewApp Class.
    And make it read DB info of MapViewSampleAppManager Class through the instance.
  3.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    /**
     * Created by Maneullab
     */
    public class SampleMapViewApp extends Application {
    
        private static Context mContext;
    
        private static MapViewSampleAppManager mapViewSampleAppManager;
        public static MainActivity mMainActivity = null;
    
        public static DisplayMetrics mDisplayMetrics = null;
        public static float mDensity;
    
        @Override
        public void onCreate(){
            super.onCreate();
    
            mContext = this;
            mapViewSampleAppManager = new MapViewSampleAppManager(this);
    
            // Save display information
            mDisplayMetrics = this.getResources().getDisplayMetrics();
            mDensity = mDisplayMetrics.density;
        }
    
        @Override
        public void onTerminate() {
            super.onTerminate();
        }
    
        public static MapViewSampleAppManager getAppManager() {
            return mapViewSampleAppManager;
        }
    }
    
  4.  
  5. Create MapViewSampleAppManager Class and read map information from DB, and make function which returns map information.
  6.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    /**
     * Created by Maneullab
     */
    public class MapViewSampleAppManager implements DataConst {
        private final String TAG = this.getClass().getName();
    
        private static Context mContext;
        private MCubeDB mMCubeDB;
        private Configuration mConfig;
    
        public MapViewSampleAppManager(Context context) {
            mContext = context;
            // Set DB
            mMCubeDB = new MCubeDB(context);
            Resources standardResources = mContext.getResources();
            mConfig = new Configuration(standardResources.getConfiguration());
        }
        /**
         * Save Map informtation file by Quering in DB.
         */
        public void setMCubeDB() {
            mMCubeDB.queryDB(MCubeMapConfig.MAP_DB_PATH);
        }
        /**
         * Return Map DB information
         */
        public MCubeDB getMapDB() {
            return mMCubeDB;
        }
    
    }
    
  7.  
  8. Re-set the setting file according to user's convenience. Map Data can only be referable if Map Data file route and DB file name are set as previously created by user.
  9.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intro);
    
        mContext = this;
        // Set path for MapViewer user.
        MCubeMapConfig.MAP_ROOT_NAME = "MCubeBasicSample";
        MCubeMapConfig.MAP_DB_NAME = "mcube.db";
        MCubeMapConfig.MAP_ROOT_PATH = Environment.getExternalStorageDirectory() + "/" + MCubeMapConfig.MAP_ROOT_NAME;
        MCubeMapConfig.MAP_DB_PATH = MCubeMapConfig.MAP_ROOT_PATH + "/map/" + MCubeMapConfig.MAP_DB_NAME;
        MCubeMapConfig.MAP_IMAGE_PATH = MCubeMapConfig.MAP_ROOT_PATH + "/image/";
        MCubeMapConfig.MAP_MINIMAP_PATH = MCubeMapConfig.MAP_IMAGE_PATH + "minimap/";
        MCubeMapConfig.MAP_FONT_PATH = MCubeMapConfig.MAP_ROOT_PATH + "/font/";
        mMapDataPath = MCubeMapConfig.MAP_ROOT_PATH +"/";
    
  10.  
  11. Unzip Map Data file in asset, into the path where you previously set in the beginning.
  12.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    /**
     * Unzip Map Data file which is in assests.
     */
    private void MakeMapData() {
        deleteDir(mMapDataPath);
        copyAssertToFiles("Sample.zip");
    
        try {
            doUnzip("Sample.zip");
            File zipFile = new File(mMapDataPath+"/Sample.zip");
            zipFile.delete();
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        mHandler.sendEmptyMessageDelayed(MSG_START_MAP, 2000);
    }
    
  13.  
  14. If you have followed so far, the preparation for MapView is complete.
    Now an explanation for showing 3D Map on screen based on Map Data will be given.
  15. Set a domain for map placement in main.xml file. Control button on MapView can be placed in wherever user wants and events can be registered in it. We will explain again on Control button in the below.
  16. 1
    2
    3
    4
    5
    6
    7
    8
    9
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <com.mnl.mcube.map.MCubeMapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
    
  17.  
  18. Receive instance of appManager which was created in MainActivity as above, and get ready to use DB Data.
  19.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mCubeMapView = (MCubeMapView)findViewById(R.id.mapView);
        mLoadingLayout = (RelativeLayout)findViewById(R.id.loading_layout);
    
        onAutoRotationChange();
    
        SampleMapViewApp.mMainActivity = this;
        mContext = this;
        mAppManager = SampleMapViewApp.getAppManager();
        mAppManager.setMCubeDB();
    
        mMCubeDB = mAppManager.getMapDB();
        mLoadingLayout.setVisibility(View.VISIBLE);
        initView();
    }
    
  20.  
  21. Add MapView event handler and register the handler in MCubeMapView in init() function. Event for control button can also be registered in init() function.
  22.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    private void initView() {
        mCubeMapView.setZOrderOnTop(false);
        mCubeMapView.setListener(mMapViewListener);
    
        Button btnCtrlLeft = (Button)findViewById(R.id.btnCtrlLeft);
        btnCtrlLeft.setOnTouchListener(this);
        Button btnCtrlRight = (Button)findViewById(R.id.btnCtrlRight);
        btnCtrlRight.setOnTouchListener(this);
        Button btnCtrlUp = (Button)findViewById(R.id.btnCtrlUp);
        btnCtrlUp.setOnTouchListener(this);
        Button btnCtrlDown = (Button)findViewById(R.id.btnCtrlDown);
        btnCtrlDown.setOnTouchListener(this);
        Button btnCtrlReset = (Button)findViewById(R.id.btnCtrlReset);
        btnCtrlReset.setOnClickListener(this);
    
        Intent intent = getIntent();
        if (intent.getExtras() != null) {
            mPathPoint = intent.getExtras().getString(EXTRA_POINT);
            mPoiType = intent.getExtras().getInt(EXTRA_POI_TYPE);
        }
    }
    
  23.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    /**
     * MapView Event handler.
     */
    private MCubeMapView.MapViewListener mMapViewListener = new MCubeMapView.MapViewListener() {
        // Process event when Poi is selected.
        @Override
        public boolean onPoiDetected(final int poiSeq) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    final Poi poi = mMCubeDB.getPoi(poiSeq, MCubeDataConst.POI);
    
  24. 1
    2
    3
    4
    5
    6
    7
    // Process event when Label is selected.
    @Override
    public boolean onLabelDetected(final int labelSeq) {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                final Poi poi = mMCubeDB.getPoi(labelSeq, MCubeDataConst.LABEL);
    
  25. 1
    2
    3
    4
    5
    6
    7
    8
    // Process event when Surface View is completed.
    @Override
    public boolean onReadySurface() {
        MCubeJNILib.LicenceResult value = MCubeJNILib.CheckLicence(""); // Input the authentication key issued.
        setPOICoreSetting(true);
        mCubeMapView.LoadFloorNo(1);
        return true;
    }
    
  26.  
  27. Please refer to API documents if you want to see types of MapView events.

    To successfully load MapView, you need to get an authentication through CheckLience(), in onReadySurface(), with the Auth. Key issued in the MCube developers site.

    For control button, you can use something as mCubeMapView.onStartController(MCubeDataConst.CTRL_LEFT); Please call onStartController() and then call onStopController().

    If you want to change Map screen and reset it using Control, please call CameraReset().
     
  28. Users can set freely whether to show Poi image on the MapView. Save the whole Poi in the filter, remove the items required to be, and set as you wished.
  29.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    /**
     * Show/Hide Poi on/from MapView
     * @param set
     */
    private void setPOICoreSetting(boolean set) {
        EnumSet<MCubeJNILib.POIType> filter = EnumSet.allOf(MCubeJNILib.POIType.class);
        if (set == false) {
            filter.remove(MCubeJNILib.POIType.Stair);
            filter.remove(MCubeJNILib.POIType.RestRoom);
            filter.remove(MCubeJNILib.POIType.Chair);
            filter.remove(MCubeJNILib.POIType.VendingMachine);
            filter.remove(MCubeJNILib.POIType.SuperMarket);
            filter.remove(MCubeJNILib.POIType.Escalator);
            filter.remove(MCubeJNILib.POIType.Elevator);
            filter.remove(MCubeJNILib.POIType.Bank);
            filter.remove(MCubeJNILib.POIType.DeliveryService);
            filter.remove(MCubeJNILib.POIType.ATM);
        }
    
        int filterValue = MCubeJNILib.getFilterValue(filter);
        MCubeJNILib.SetPoiTypeFilter(filterValue);
    }
    
  30.  
  31. You can add CubeMapView Instance at onResume(),onPause(),onDestory().
  32.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    @Override
    protected void onResume() {
        super.onResume();
        mCubeMapView.onResume();
    }
    @Override
    public void onPause() {
        super.onPause();
        mCubeMapView.setPreserveEGLContextOnPause(true);
        mCubeMapView.onPause();
    
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        mCubeMapView.DeleteMainScene();
    
        getContentResolver().unregisterContentObserver(m_contentObserver);
    }