ulfben icon

Virtual keypad (Android)

ulfben | PRO | 02/14/17 10:24:52 PM UTC | 0 ⭐ | 900 👁️ | Never ⏰ | []
Java |

4.22 KB

|

None

|

0 👍

/

0 👎

view_keypad.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_gravity="bottom"
                android:padding="@dimen/keypad_size"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
    android:id="@+id/keypad">
 
    <Button android:id="@+id/keypad_up"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/keypad_left"
            android:layout_width="@dimen/keypad_size"
            android:layout_height="@dimen/keypad_size" />
 
    <Button android:id="@+id/keypad_down"
            android:layout_below="@+id/keypad_left"
            android:layout_toRightOf="@+id/keypad_left"
            android:layout_width="@dimen/keypad_size"
            android:layout_height="@dimen/keypad_size" />
 
    <Button android:id="@+id/keypad_left"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/keypad_up"
            android:layout_width="@dimen/keypad_size"
            android:layout_height="@dimen/keypad_size" />
 
    <Button android:id="@+id/keypad_right"
            android:layout_toRightOf="@+id/keypad_up"
            android:layout_below="@+id/keypad_up"
            android:layout_width="@dimen/keypad_size"
            android:layout_height="@dimen/keypad_size" />
 
    <Button android:id="@+id/keypad_jump"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/keypad_left"
            android:layout_width="@dimen/keypad_size"
            android:layout_height="@dimen/keypad_size" />
</RelativeLayout>
 
 
//update styles.xml with fullscreen-flags
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:immersive">true</item>
 
 
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context="com.ulfben.platformer.MainActivity">
 
    <view class="com.ulfben.platformer.GameView"
          android:id="@+id/gameView"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"/>
 
    <include layout="@layout/view_keypad" />
</FrameLayout>
 
//constructors needed for view-inflation to not crash horribly
public GameView(Context context) {
    super(context);
    init(context);
}
public GameView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context);
}
public GameView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(context);
}
 
 
//BasicInputManager.java
BasicInputManager(View view){
        view.findViewById(R.id.keypad_up).setOnTouchListener(this); 
        view.findViewById(R.id.keypad_down).setOnTouchListener(this);
        view.findViewById(R.id.keypad_left).setOnTouchListener(this);
        view.findViewById(R.id.keypad_right).setOnTouchListener(this);
        view.findViewById(R.id.keypad_jump).setOnTouchListener(this);
    }
    
@Override
public boolean onTouch(final View v, final MotionEvent event) {
    int action = event.getActionMasked();
    int id = v.getId();
    if(action == MotionEvent.ACTION_DOWN){// User started pressing a key
        if(id == R.id.keypad_up){
            mVerticalFactor -= 1;
        }else if (id == R.id.keypad_down) {
            mVerticalFactor += 1;
        }
        if (id == R.id.keypad_left) {
            mHorizontalFactor -= 1;
        } else if(id == R.id.keypad_right) {
            mHorizontalFactor += 1;
        }
        if (id == R.id.keypad_jump) {
            mIsJumping = true;
        }
    } else if(action == MotionEvent.ACTION_UP) {
        if (id == R.id.keypad_up) {
            mVerticalFactor += 1;
        } else if (id == R.id.keypad_down) {
            mVerticalFactor -= 1;
        }
        if (id == R.id.keypad_left) {
            mHorizontalFactor += 1;
        } else if (id == R.id.keypad_right) {
            mHorizontalFactor -= 1;
        }
        if (id == R.id.keypad_jump) {
            mIsJumping = false;
        }
    }
    return false;
}

Comments

  • Gyqizv icon
    04/02/26 05:41:28 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎