mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-21 09:01:56 -07:00
demo buttob
This commit is contained in:
parent
9a64dde80c
commit
cff85c1197
8 changed files with 48 additions and 24 deletions
|
|
@ -2,6 +2,7 @@ package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
import android.support.v7.app.*;
|
import android.support.v7.app.*;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
|
import net.kdt.pojavlaunch.value.customcontrols.*;
|
||||||
|
|
||||||
public class CustomControlsActivity extends AppCompatActivity
|
public class CustomControlsActivity extends AppCompatActivity
|
||||||
{
|
{
|
||||||
|
|
@ -9,7 +10,18 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
CustomControls ctrl = new CustomControls();
|
||||||
|
|
||||||
|
ControlButton ctrlEx = new ControlButton();
|
||||||
|
ctrlEx.name = "Test";
|
||||||
|
ctrlEx.x = 100;
|
||||||
|
ctrlEx.y = 100;
|
||||||
|
|
||||||
|
ctrl.button = new ControlButton[]{ctrlEx};
|
||||||
|
|
||||||
|
ControlsLayout ctrlLayout = new ControlsLayout(this);
|
||||||
|
ctrlLayout.loadLayout(ctrl);
|
||||||
|
ctrlLayout.setCanMove(true);
|
||||||
|
setContentView(ctrlLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -246,8 +246,8 @@ public class MCLauncherActivity extends AppCompatActivity
|
||||||
private float updateWidthHeight() {
|
private float updateWidthHeight() {
|
||||||
float leftRightWidth = (float) AndroidDisplay.windowWidth / 100f * 32f;
|
float leftRightWidth = (float) AndroidDisplay.windowWidth / 100f * 32f;
|
||||||
float playButtonWidth = AndroidDisplay.windowWidth - leftRightWidth * 2f;
|
float playButtonWidth = AndroidDisplay.windowWidth - leftRightWidth * 2f;
|
||||||
LinearLayout.LayoutParams leftRightParams = new LinearLayout.LayoutParams((int) leftRightWidth, dpToPixel(AndroidDisplay.windowHeight / 9));
|
LinearLayout.LayoutParams leftRightParams = new LinearLayout.LayoutParams((int) leftRightWidth, (int) Tools.dpToPx(this, AndroidDisplay.windowHeight / 9));
|
||||||
LinearLayout.LayoutParams playButtonParams = new LinearLayout.LayoutParams((int) playButtonWidth, dpToPixel(AndroidDisplay.windowHeight / 9));
|
LinearLayout.LayoutParams playButtonParams = new LinearLayout.LayoutParams((int) playButtonWidth, (int) Tools.dpToPx(this, AndroidDisplay.windowHeight / 9));
|
||||||
leftView.setLayoutParams(leftRightParams);
|
leftView.setLayoutParams(leftRightParams);
|
||||||
rightView.setLayoutParams(leftRightParams);
|
rightView.setLayoutParams(leftRightParams);
|
||||||
playButton.setLayoutParams(playButtonParams);
|
playButton.setLayoutParams(playButtonParams);
|
||||||
|
|
@ -400,12 +400,6 @@ public class MCLauncherActivity extends AppCompatActivity
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int dpToPixel(int sizeInDP)
|
|
||||||
{
|
|
||||||
return (int) TypedValue.applyDimension(
|
|
||||||
TypedValue.COMPLEX_UNIT_DIP, sizeInDP, getResources()
|
|
||||||
.getDisplayMetrics());
|
|
||||||
}
|
|
||||||
private boolean canBack = false;
|
private boolean canBack = false;
|
||||||
private void statusIsLaunching(boolean isLaunching)
|
private void statusIsLaunching(boolean isLaunching)
|
||||||
{
|
{
|
||||||
|
|
@ -848,10 +842,13 @@ public class MCLauncherActivity extends AppCompatActivity
|
||||||
case 2:{ // Check update
|
case 2:{ // Check update
|
||||||
checkUpdate();
|
checkUpdate();
|
||||||
} break;
|
} break;
|
||||||
case 3:{ // Settings
|
case 3:{ // Custom controls
|
||||||
|
startActivity(new Intent(MCLauncherActivity.this, CustomControlsActivity.class));
|
||||||
|
} break;
|
||||||
|
case 4:{ // Settings
|
||||||
startActivity(new Intent(MCLauncherActivity.this, PojavPreferenceActivity.class));
|
startActivity(new Intent(MCLauncherActivity.this, PojavPreferenceActivity.class));
|
||||||
} break;
|
} break;
|
||||||
case 4:{ // About
|
case 5:{ // About
|
||||||
final AlertDialog.Builder aboutB = new AlertDialog.Builder(MCLauncherActivity.this);
|
final AlertDialog.Builder aboutB = new AlertDialog.Builder(MCLauncherActivity.this);
|
||||||
aboutB.setTitle(R.string.mcl_option_about);
|
aboutB.setTitle(R.string.mcl_option_about);
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -1156,18 +1156,10 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private float pxToDp(float px) {
|
|
||||||
return (px / getResources().getDisplayMetrics().density);
|
|
||||||
}
|
|
||||||
|
|
||||||
private float dpToPx(float dp) {
|
|
||||||
return (dp * getResources().getDisplayMetrics().density);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Button findButton(int id) {
|
private Button findButton(int id) {
|
||||||
Button button = (Button) findViewById(id);
|
Button button = (Button) findViewById(id);
|
||||||
button.setWidth((int) dpToPx(pxToDp(button.getWidth()) * PojavPreferenceActivity.PREF_BUTTONSIZE));
|
button.setWidth((int) Tools.dpToPx(this, Tools.pxToDp(this, button.getWidth()) * PojavPreferenceActivity.PREF_BUTTONSIZE));
|
||||||
button.setHeight((int) dpToPx(pxToDp(button.getHeight()) * PojavPreferenceActivity.PREF_BUTTONSIZE));
|
button.setHeight((int) Tools.dpToPx(this, Tools.pxToDp(this, button.getHeight()) * PojavPreferenceActivity.PREF_BUTTONSIZE));
|
||||||
button.setOnTouchListener(this);
|
button.setOnTouchListener(this);
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,13 @@ public final class Tools
|
||||||
return displayMetrics;
|
return displayMetrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float pxToDp(Context ctx, float px) {
|
||||||
|
return (px / ctx.getResources().getDisplayMetrics().density);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float dpToPx(Context ctx, float dp) {
|
||||||
|
return (dp * ctx.getResources().getDisplayMetrics().density);
|
||||||
|
}
|
||||||
|
|
||||||
public static void copyAssetFile(Context ctx, String fileName, String output, boolean overwrite) throws Exception
|
public static void copyAssetFile(Context ctx, String fileName, String output, boolean overwrite) throws Exception
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@ public class ControlView extends Button implements OnTouchListener
|
||||||
public ControlView(Context ctx, ControlButton properties) {
|
public ControlView(Context ctx, ControlButton properties) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
|
||||||
|
setBackgroundResource(R.drawable.control_button);
|
||||||
setOnTouchListener(this);
|
setOnTouchListener(this);
|
||||||
|
|
||||||
mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm());
|
mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm());
|
||||||
mProperties = properties;
|
mProperties = properties;
|
||||||
|
|
||||||
|
|
@ -43,7 +45,7 @@ public class ControlView extends Button implements OnTouchListener
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View view, MotionEvent event) {
|
public boolean onTouch(View view, MotionEvent event) {
|
||||||
if (mGestureDetector.onTouchEvent(event)) {
|
if (mGestureDetector.onTouchEvent(event)) {
|
||||||
mClickListener.onClick(view);
|
if (mClickListener != null) mClickListener.onClick(view);
|
||||||
return true;
|
return true;
|
||||||
} else if (!mCanMove) {
|
} else if (!mCanMove) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,13 @@ import android.widget.*;
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
import com.google.gson.*;
|
||||||
|
import net.kdt.pojavlaunch.*;
|
||||||
|
|
||||||
public class ControlsLayout extends FrameLayout
|
public class ControlsLayout extends FrameLayout
|
||||||
{
|
{
|
||||||
|
private boolean mCanMove;
|
||||||
|
private CustomControls mLayout;
|
||||||
public ControlsLayout(Context ctx) {
|
public ControlsLayout(Context ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
}
|
}
|
||||||
|
|
@ -15,12 +19,20 @@ public class ControlsLayout extends FrameLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadLayout(CustomControls controlLayout) {
|
public void loadLayout(CustomControls controlLayout) {
|
||||||
|
mLayout = controlLayout;
|
||||||
for (ControlButton button : controlLayout.button) {
|
for (ControlButton button : controlLayout.button) {
|
||||||
addView(new ControlView(getContext(), button));
|
ControlView view = new ControlView(getContext(), button);
|
||||||
|
view.setCanMove(mCanMove);
|
||||||
|
addView(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveLayout(String path) throws Exception {
|
||||||
|
Tools.write(path, new Gson().toJson(mLayout));
|
||||||
|
}
|
||||||
|
|
||||||
public void setCanMove(boolean z) {
|
public void setCanMove(boolean z) {
|
||||||
|
mCanMove = z;
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
View v = getChildAt(i);
|
View v = getChildAt(i);
|
||||||
if (v instanceof ControlView) {
|
if (v instanceof ControlView) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
<item>@string/mcl_option_modmgr</item>
|
<item>@string/mcl_option_modmgr</item>
|
||||||
<item>@string/mcl_option_optifineinstall</item>
|
<item>@string/mcl_option_optifineinstall</item>
|
||||||
<item>@string/mcl_option_checkupdate</item>
|
<item>@string/mcl_option_checkupdate</item>
|
||||||
|
<item>@string/mcl_option_customcontrol</item>
|
||||||
<item>@string/mcl_option_settings</item>
|
<item>@string/mcl_option_settings</item>
|
||||||
<item>@string/mcl_option_about</item>
|
<item>@string/mcl_option_about</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@
|
||||||
<string name="mcl_option_modmgr">Mod manager (no function)</string>
|
<string name="mcl_option_modmgr">Mod manager (no function)</string>
|
||||||
<string name="mcl_option_optifineinstall">Install OptiFine</string>
|
<string name="mcl_option_optifineinstall">Install OptiFine</string>
|
||||||
<string name="mcl_option_checkupdate">Check for update</string>
|
<string name="mcl_option_checkupdate">Check for update</string>
|
||||||
|
<string name="mcl_option_customcontrol">Custom controls</string>
|
||||||
<string name="mcl_option_settings">Settings</string>
|
<string name="mcl_option_settings">Settings</string>
|
||||||
<string name="mcl_option_about">About</string>
|
<string name="mcl_option_about">About</string>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue