Question

I'm trying to implement a custom JoystickView for my project and through my search I found this library : https://github.com/zerokol/JoystickView

I've added the jar to the lib folder and added the jar file to the build path. The problem is when I try to add it on my screen it doesn't work. I'm new to android and I'm stuck now. Can you tell me where I'm wrong?

The following code is same on the links example code except the xml file

My main class : package com.example.joystickdeneme;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

import com.zerokol.views.JoystickView;
import com.zerokol.views.JoystickView.OnJoystickMoveListener;

public class MainActivity extends Activity {



private TextView angleTextView;
private TextView powerTextView;
private TextView directionTextView;
// Importing as others views
private JoystickView joystick;

@Override
public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);

     angleTextView = (TextView) findViewById(R.id.angleTextView);
     powerTextView = (TextView) findViewById(R.id.powerTextView);
     directionTextView = (TextView) findViewById(R.id.directionTextView);
     // referring as others views
     joystick = (JoystickView) findViewById(R.id.joystickView);

     // Listener of events, it'll return the angle in graus and power in percents
     // return to the direction of the moviment
     joystick.setOnJoystickMoveListener(new OnJoystickMoveListener() {
          @Override
          public void onValueChanged(int angle, int power, int direction) {
               angleTextView.setText(" " + String.valueOf(angle) + "°");
               powerTextView.setText(" " + String.valueOf(power) + "%");
               switch (direction) {
                    case JoystickView.FRONT:
                         directionTextView.setText(R.string.front_lab);
                         break;

                    case JoystickView.FRONT_RIGHT:
                         directionTextView.setText(R.string.front_right_lab);
                         break;

                    case JoystickView.RIGHT:
                         directionTextView.setText(R.string.right_lab);
                          break;

                    case JoystickView.RIGHT_BOTTOM:
                         directionTextView.setText(R.string.right_bottom_lab);
                         break;

                    case JoystickView.BOTTOM:
                         directionTextView.setText(R.string.bottom_lab);
                         break; 

                    case JoystickView.BOTTOM_LEFT:
                         directionTextView.setText(R.string.bottom_left_lab);
                         break;

                    case JoystickView.LEFT:
                         directionTextView.setText(R.string.left_lab);
                         break;

                    case JoystickView.LEFT_FRONT:
                         directionTextView.setText(R.string.left_front_lab);
                         break;

                    default:
                         directionTextView.setText(R.string.center_lab);
               }
          }
     }, JoystickView.DEFAULT_LOOP_INTERVAL);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

and my xml file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    android:id="@+id/angleTextView" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" 
    android:id="@+id/powerTextView" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    android:id="@+id/directionTextView" />


<com.example.joystickdeneme

     zerokol.views.joystickview=".zerokol.views.joystickview"
     android:id="@+id/joystickView"
     android:layout_height="wrap_content"
     android:layout_width="wrap_content" >
</com.example.joystickdeneme>

</LinearLayout>
Was it helpful?

Solution

I learned where my mistake is in layout file where I call the joystick it should be : <com.zerokol.views.JoystickView android:id="@+id/joystickView" android:layout_width="150dp" android:layout_height="150dp" />

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top