0

Is there a way that i can "convert" a Viewgroup created programatically to parcelable and then send this ViewGroup through and aidl?

I know that may not be a good design or performance, but is there a way how i can do that?

Thats how my ViewGroup is created:

public ViewGroup getViewGroup(){
        LinearLayout root = new LinearLayout(getContext());
        root.setPadding(getValueinPixels(16),getValueinPixels(16),getValueinPixels(16),getValueinPixels(16));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        root.setLayoutParams(params);
        root.setOrientation(LinearLayout.VERTICAL);

        TextView message = new TextView(getContext());
        message.setText(getMessageCorrespondentToAction());
        message.setTextColor(Color.parseColor(getHexadecimalColorOfMessageView()));
        message.setPadding(getValueinPixels(0),getValueinPixels(8),getValueinPixels(0),getValueinPixels(8));

        TextView action = new TextView(getContext());
        action.setTextColor(Color.parseColor(getHexadecimalColorOfActionView()));
        action.setPadding(getValueinPixels(0),getValueinPixels(8),getValueinPixels(0),getValueinPixels(8));

        root.addView(message);
        root.addView(action);

        return root;

    } 
WitaloBenicio
  • 3,395
  • 5
  • 25
  • 32

1 Answers1

0

Is there a way that i can "convert" a Viewgroup created programatically to parcelable and then send this ViewGroup through and aidl?

You are welcome to construct a UI definition in the form of a RemoteViews, where the recipient can apply() it. RemoteViews is Parcelable already.

You are also welcome to come up with your own RemoteViews replacement, where you create a generic data structure that describes a UI, and write code that can generate the actual widgets and containers from that generic data structure. You can then make that data structure Parcelable.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • But this RemoteViews are only created by a resource file? Its because my View is created programatically...without any resource. – WitaloBenicio Mar 20 '15 at 18:14
  • @WitaloBenicio: "But this RemoteViews are only created by a resource file?" -- it starts with one, and you can attach other `RemoteViews` as needed via `addView()`. "Its because my View is created programatically...without any resource" -- passing UI between processes is not generally supported. `RemoteViews` is the only thing that is part of Android, and it has limitations. – CommonsWare Mar 20 '15 at 18:27
  • What do you think about i create a RemoteView in my app (with the parent View), send to my Service e.g., and then in the Service add the views into this same RemoteView and return to my app? Is that a possible approach? – WitaloBenicio Mar 20 '15 at 18:30
  • @WitaloBenicio: If by "add the views" you mean "add the `RemoteViews`", that could work, though I am not completely clear on what you are trying to accomplish. Bear in mind that a `Service` in your own single-process app is not limited to AIDL. – CommonsWare Mar 20 '15 at 18:32