项目作者: justasm

项目描述 :
Joystick widget for Android.
高级语言: Java
项目地址: git://github.com/justasm/Bugstick.git
创建时间: 2015-05-17T00:43:01Z
项目社区:https://github.com/justasm/Bugstick

开源协议:MIT License

下载


Bugstick

Flexible joystick widget for Android.

Sample animated.

Why Bugstick?

Other joystick widgets
are a hassle to include in modern Gradle-based Android projects, support only limited visual
customization, and suffer from overly prescriptive output.

So how does Bugstick solve these issues?

  • Painless Dependency - try it out quickly with a simple Gradle dependency.

  • Configurable Look - the joystick base and stick are a completely decoupled, standard
    ViewGroup - View pair. Use an ImageView, Button, LinearLayout, or any other View as
    the stick, and use standard Drawables to theme Bugstick so it looks at home in your app.

  • Unopinionated Output - the widget reports proportional offset of the stick from its center as
    well as the current angle via a standard listener interface. Choose to interpret these raw outputs
    in the way that suits your use case.

Usage

Add it to your project using Gradle:

  1. compile 'com.jmedeisis:bugstick:0.2.2'

Example XML layout file:

  1. <com.jmedeisis.bugstick.Joystick
  2. android:id="@+id/joystick"
  3. android:layout_width="@dimen/base_size"
  4. android:layout_height="@dimen/base_size"
  5. android:background="@drawable/bg_base">
  6. <!-- You may use any View here. -->
  7. <Button
  8. android:layout_width="@dimen/stick_size"
  9. android:layout_height="@dimen/stick_size"
  10. android:background="@drawable/bg_stick" ></Button>
  11. </com.jmedeisis.bugstick.Joystick>

Note that the Joystick ViewGroup supports only one direct child, but that child can be another
ViewGroup such as a FrameLayout with multiple children.

After inflating the layout, you will typically listen for joystick events using a
JoystickListener:

  1. Joystick joystick = (Joystick) findViewById(R.id.joystick);
  2. joystick.setJoystickListener(new JoystickListener() {
  3. @Override
  4. public void onDown() {
  5. // ..
  6. }
  7. @Override
  8. public void onDrag(float degrees, float offset) {
  9. // ..
  10. }
  11. @Override
  12. public void onUp() {
  13. // ..
  14. }
  15. });

Please refer to the included sample project for a thorough example.

Configuration

You can configure the following attributes for the Joystick class:

  • start_on_first_touch - If true (default), the stick activates immediately on the initial touch.
    If false, the user must begin to drag their finger across the joystick for the stick to activate.

  • force_square - If true (default), the joystick always measures itself to force a square layout.

  • radius - If specified, this is the maximum physical offset from the center that the stick is
    allowed to move. If not specified (default), the radius is determined based on the dimensions of
    the base and the stick.

  • motion_constraint - One of None (default), Horizontal, or Vertical. Specifies whether the
    stick motion should be constrained to a particular direction. If None, the stick is allowed to
    move freely around the center of the base.

Example configuration:

  1. <com.jmedeisis.bugstick.Joystick
  2. android:id="@+id/joystick"
  3. android:layout_width="@dimen/base_width"
  4. android:layout_height="match_parent"
  5. android:background="@drawable/bg_base"
  6. app:start_on_first_touch="false"
  7. app:force_square="false"
  8. app:radius="@dimen/stick_offset_max_radius"
  9. app:motion_constraint="Vertical">
  10. <!-- Any View here. -->
  11. </com.jmedeisis.bugstick.Joystick>

Development

Pull requests are welcome and encouraged for bugfixes and features such as:

  • accessibility support
  • more powerful motion constraints, e.g. constrain to arbitrary path

License

Bugstick is licensed under the terms of the MIT License.