Question

Anybody knows how to make multiple layout in SmartWatch? Currently I have only one layout, when I swipe left, I want to have different layout.

To make first layout, I have already made like this:

public class HelloWatchExtension extends ControlExtension{

int width;
int height;

RelativeLayout layout;
RelativeLayout layut;
Canvas canvas;
Bitmap bitmap;
TextView textView;

public HelloWatchExtension(Context context, String hostAppPackageName) {
    super(context, hostAppPackageName);

    width = getSupportedControlWidth(context);
    height = getSupportedControlHeight(context);

    layout = new RelativeLayout(context);
    textView = new TextView(context);
    textView.setText("Hello watch!");
    textView.setTextSize(9);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(Color.WHITE);
    textView.layout(0, 0, width, height);
    layout.addView(textView);

}

I dont know how to change the layout or add another layout. I tried to use onSwipe (below) but it doesn't work:

public void onSwipe(int direction) {
        switch (direction) {
   case Control.Intents.SWIPE_DIRECTION_UP:
       break;
   case Control.Intents.SWIPE_DIRECTION_LEFT:
                    layut = new RelativeLayout(context);
            textView.setText("Helhuhch!");
            textView.setTextSize(9);
            layut.addView(textView);
       break;
   case Control.Intents.SWIPE_DIRECTION_DOWN:
       break;
   case Control.Intents.SWIPE_DIRECTION_RIGHT:
       break;
   default:
       break;

Anybody knows how to do it?

Was it helpful?

Solution

I assume you are talking about SmartWatch 1, not SmartWatch 2? For SW1 you need to call showBitmap() to draw your layout on the watch. For a complete sample code see the ControlSample project in the /samples folder of the Sony Add-on SDK.

        // Create background bitmap for animation.
        mBackground = Bitmap.createBitmap(width, height, BITMAP_CONFIG);
        // Set default density to avoid scaling.
        mBackground.setDensity(DisplayMetrics.DENSITY_DEFAULT);

        LinearLayout root = new LinearLayout(mContext);
        root.setLayoutParams(new LayoutParams(width, height));

        LinearLayout sampleLayout = (LinearLayout)LinearLayout.inflate(mContext,
                R.layout.sample_control, root);
        ((TextView)sampleLayout.findViewById(R.id.sample_control_text)).setText(packageName);
        sampleLayout.measure(width, height);
        sampleLayout.layout(0, 0, sampleLayout.getMeasuredWidth(),
                sampleLayout.getMeasuredHeight());

        Canvas canvas = new Canvas(mBackground);
        sampleLayout.draw(canvas);

        showBitmap(mBackground);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top