Search code examples
androidcordova-pluginssurfaceview

Where to write code for design in Cordova plugin


I'm trying to build a custom Cordova plugin for android platform. As of now i'm able to write the activity code in .java file but i don't know where and how i have to write design code (XML layout) in plugin. My layout code is as follows

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="dev.edmt.androidcamerarecognitiontext.MainActivity">

  <SurfaceView
      android:id="@+id/surface_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

    <TextView
        android:id="@+id/text_view"
        android:text="No Text"
        android:layout_alignParentBottom="true"
        android:textColor="@android:color/white"
        android:textSize="20sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</RelativeLayout>

Please give me ideas about this...


Solution

  • @Ben Morris, Thank you for your suggestion.

    I think this solution may help others, I have checked lot of forums to add the design in plugin but i didn't get proper solution so i have implemented SurfaceView in the .java (Which extends from CordovaPlugin) file as bellow

      Context activity = this.cordova.getActivity().getApplicationContext();
    
    
      SurfaceView surfaceView = new SurfaceView(activity);
      FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT,
            Gravity.CENTER);
    
      cordova.getActivity().addContentView(surfaceView, params);