mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-18 09:07:48 -04:00
demo buttob
This commit is contained in:
parent
9a64dde80c
commit
cff85c1197
@ -2,6 +2,7 @@ package net.kdt.pojavlaunch;
|
||||
|
||||
import android.support.v7.app.*;
|
||||
import android.os.*;
|
||||
import net.kdt.pojavlaunch.value.customcontrols.*;
|
||||
|
||||
public class CustomControlsActivity extends AppCompatActivity
|
||||
{
|
||||
@ -9,7 +10,18 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
protected void onCreate(Bundle 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() {
|
||||
float leftRightWidth = (float) AndroidDisplay.windowWidth / 100f * 32f;
|
||||
float playButtonWidth = AndroidDisplay.windowWidth - leftRightWidth * 2f;
|
||||
LinearLayout.LayoutParams leftRightParams = new LinearLayout.LayoutParams((int) leftRightWidth, dpToPixel(AndroidDisplay.windowHeight / 9));
|
||||
LinearLayout.LayoutParams playButtonParams = new LinearLayout.LayoutParams((int) playButtonWidth, 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, (int) Tools.dpToPx(this, AndroidDisplay.windowHeight / 9));
|
||||
leftView.setLayoutParams(leftRightParams);
|
||||
rightView.setLayoutParams(leftRightParams);
|
||||
playButton.setLayoutParams(playButtonParams);
|
||||
@ -400,12 +400,6 @@ public class MCLauncherActivity extends AppCompatActivity
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
private int dpToPixel(int sizeInDP)
|
||||
{
|
||||
return (int) TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, sizeInDP, getResources()
|
||||
.getDisplayMetrics());
|
||||
}
|
||||
private boolean canBack = false;
|
||||
private void statusIsLaunching(boolean isLaunching)
|
||||
{
|
||||
@ -848,10 +842,13 @@ public class MCLauncherActivity extends AppCompatActivity
|
||||
case 2:{ // Check update
|
||||
checkUpdate();
|
||||
} 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));
|
||||
} break;
|
||||
case 4:{ // About
|
||||
case 5:{ // About
|
||||
final AlertDialog.Builder aboutB = new AlertDialog.Builder(MCLauncherActivity.this);
|
||||
aboutB.setTitle(R.string.mcl_option_about);
|
||||
try
|
||||
|
@ -1156,18 +1156,10 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
.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) {
|
||||
Button button = (Button) findViewById(id);
|
||||
button.setWidth((int) dpToPx(pxToDp(button.getWidth()) * PojavPreferenceActivity.PREF_BUTTONSIZE));
|
||||
button.setHeight((int) dpToPx(pxToDp(button.getHeight()) * PojavPreferenceActivity.PREF_BUTTONSIZE));
|
||||
button.setWidth((int) Tools.dpToPx(this, Tools.pxToDp(this, button.getWidth()) * PojavPreferenceActivity.PREF_BUTTONSIZE));
|
||||
button.setHeight((int) Tools.dpToPx(this, Tools.pxToDp(this, button.getHeight()) * PojavPreferenceActivity.PREF_BUTTONSIZE));
|
||||
button.setOnTouchListener(this);
|
||||
return button;
|
||||
}
|
||||
|
@ -104,6 +104,13 @@ public final class Tools
|
||||
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
|
||||
{
|
||||
|
@ -16,7 +16,9 @@ public class ControlView extends Button implements OnTouchListener
|
||||
public ControlView(Context ctx, ControlButton properties) {
|
||||
super(ctx);
|
||||
|
||||
setBackgroundResource(R.drawable.control_button);
|
||||
setOnTouchListener(this);
|
||||
|
||||
mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm());
|
||||
mProperties = properties;
|
||||
|
||||
@ -43,7 +45,7 @@ public class ControlView extends Button implements OnTouchListener
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (mGestureDetector.onTouchEvent(event)) {
|
||||
mClickListener.onClick(view);
|
||||
if (mClickListener != null) mClickListener.onClick(view);
|
||||
return true;
|
||||
} else if (!mCanMove) {
|
||||
return false;
|
||||
|
@ -3,9 +3,13 @@ import android.widget.*;
|
||||
import android.content.*;
|
||||
import android.util.*;
|
||||
import android.view.*;
|
||||
import com.google.gson.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
|
||||
public class ControlsLayout extends FrameLayout
|
||||
{
|
||||
private boolean mCanMove;
|
||||
private CustomControls mLayout;
|
||||
public ControlsLayout(Context ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
@ -15,12 +19,20 @@ public class ControlsLayout extends FrameLayout
|
||||
}
|
||||
|
||||
public void loadLayout(CustomControls controlLayout) {
|
||||
mLayout = controlLayout;
|
||||
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) {
|
||||
mCanMove = z;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View v = getChildAt(i);
|
||||
if (v instanceof ControlView) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
<item>@string/mcl_option_modmgr</item>
|
||||
<item>@string/mcl_option_optifineinstall</item>
|
||||
<item>@string/mcl_option_checkupdate</item>
|
||||
<item>@string/mcl_option_customcontrol</item>
|
||||
<item>@string/mcl_option_settings</item>
|
||||
<item>@string/mcl_option_about</item>
|
||||
</string-array>
|
||||
|
@ -82,6 +82,7 @@
|
||||
<string name="mcl_option_modmgr">Mod manager (no function)</string>
|
||||
<string name="mcl_option_optifineinstall">Install OptiFine</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_about">About</string>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user