mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-10-05 20:35:27 -04:00
More little custom controls
This commit is contained in:
1 parent
cff85c1197
commit
4a0505308c
10 files changed
+148
-15
No files matched your search
@@ -1,27 +1,110 @@
|
||||
package net.kdt.pojavlaunch;
|
||||
|
||||
import android.support.v7.app.*;
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.support.design.widget.*;
|
||||
import android.support.v4.widget.*;
|
||||
import android.support.v7.app.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import com.google.gson.*;
|
||||
import net.kdt.pojavlaunch.value.customcontrols.*;
|
||||
|
||||
public class CustomControlsActivity extends AppCompatActivity
|
||||
{
|
||||
private DrawerLayout drawerLayout;
|
||||
private NavigationView navDrawer;
|
||||
|
||||
private String selectedName = "";
|
||||
|
||||
private CustomControls mCtrl;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Menu
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.customctrl_drawerlayout);
|
||||
|
||||
navDrawer = (NavigationView) findViewById(R.id.customctrl_navigation_view);
|
||||
navDrawer.setNavigationItemSelectedListener(
|
||||
new NavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem menuItem) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.menu_ctrl_add:
|
||||
ControlButton ctrlBtn = new ControlButton();
|
||||
ctrlBtn.name = "New";
|
||||
ctrlBtn.x = 100;
|
||||
ctrlBtn.y = 100;
|
||||
mCtrl.button.add(ctrlBtn);
|
||||
|
||||
break;
|
||||
case R.id.menu_ctrl_edit: // openLogOutput();
|
||||
break;
|
||||
case R.id.menu_ctrl_remove: // toggleDebug();
|
||||
break;
|
||||
}
|
||||
//Toast.makeText(MainActivity.this, menuItem.getTitle() + ":" + menuItem.getItemId(), Toast.LENGTH_SHORT).show();
|
||||
|
||||
drawerLayout.closeDrawers();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
CustomControls ctrl = new CustomControls();
|
||||
mCtrl = new CustomControls();
|
||||
|
||||
ControlButton ctrlEx = new ControlButton();
|
||||
ctrlEx.name = "Test";
|
||||
ctrlEx.x = 100;
|
||||
ctrlEx.y = 100;
|
||||
|
||||
ctrl.button = new ControlButton[]{ctrlEx};
|
||||
mCtrl.button.add(ctrlEx);
|
||||
|
||||
ControlsLayout ctrlLayout = new ControlsLayout(this);
|
||||
ctrlLayout.loadLayout(ctrl);
|
||||
ControlsLayout ctrlLayout = (ControlsLayout) findViewById(R.id.customctrl_controllayout);
|
||||
ctrlLayout.loadLayout(mCtrl);
|
||||
ctrlLayout.setCanMove(true);
|
||||
|
||||
setContentView(ctrlLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
final EditText edit = new EditText(this);
|
||||
edit.setSingleLine();
|
||||
edit.setText(selectedName);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.global_save);
|
||||
builder.setView(edit);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
final AlertDialog dialog = builder.create();
|
||||
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
|
||||
@Override
|
||||
public void onShow(DialogInterface dialogInterface) {
|
||||
|
||||
Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (edit.getText().toString().isEmpty()) {
|
||||
edit.setError(getResources().getString(R.string.global_error_field_empty));
|
||||
} else {
|
||||
try {
|
||||
Tools.write(Tools.CTRLMAP_PATH + "/" + edit.getText().toString(), new Gson().toJson(mCtrl));
|
||||
dialog.dismiss();
|
||||
} catch (Throwable th) {
|
||||
Tools.showError(CustomControlsActivity.this, th);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
@@ -464,7 +464,7 @@ public class PojavLoginActivity extends MineActivity
|
||||
|
||||
String text = edit2.getText().toString();
|
||||
if(text.isEmpty()){
|
||||
edit2.setError(getResources().getString(R.string.login_error_empty_username));
|
||||
edit2.setError(getResources().getString(R.string.global_error_field_empty));
|
||||
} else if(text.length() <= 2){
|
||||
edit2.setError(getResources().getString(R.string.login_error_short_username));
|
||||
} else if(new File(Tools.mpProfiles + "/" + text).exists()){
|
||||
|
||||
@@ -32,7 +32,8 @@ public final class Tools
|
||||
public static String APP_NAME = "null";
|
||||
public static String MAIN_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/games/minecraft";
|
||||
public static String ASSETS_PATH = MAIN_PATH + "/assets";
|
||||
|
||||
public static String CTRLMAP_PATH = MAIN_PATH + "/controlmap";
|
||||
|
||||
public static int usingVerCode = 1;
|
||||
public static String usingVerName = "2.4.2";
|
||||
public static String mhomeUrl = "https://khanhduytran0.github.io/PojavLauncher"; // "http://kdtjavacraft.eu5.net";
|
||||
|
||||
@@ -21,7 +21,8 @@ public class ControlView extends Button implements OnTouchListener
|
||||
|
||||
mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm());
|
||||
mProperties = properties;
|
||||
|
||||
// com.android.internal.R.string.delete
|
||||
// android.R.string.
|
||||
setText(properties.name);
|
||||
setTranslationX(moveX = properties.x);
|
||||
setTranslationY(moveY = properties.y);
|
||||
|
||||
@@ -23,10 +23,16 @@ public class ControlsLayout extends FrameLayout
|
||||
for (ControlButton button : controlLayout.button) {
|
||||
ControlView view = new ControlView(getContext(), button);
|
||||
view.setCanMove(mCanMove);
|
||||
view.setLayoutParams(new LayoutParams((int) Tools.dpToPx(getContext(), 50), (int) Tools.dpToPx(getContext(), 50)));
|
||||
addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshLayout() {
|
||||
removeAllViews();
|
||||
loadLayout(mLayout);
|
||||
}
|
||||
|
||||
public void saveLayout(String path) throws Exception {
|
||||
Tools.write(path, new Gson().toJson(mLayout));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.kdt.pojavlaunch.value.customcontrols;
|
||||
import java.util.*;
|
||||
|
||||
public class CustomControls
|
||||
{
|
||||
public ControlButton[] button = new ControlButton[]{};
|
||||
public List<ControlButton> button = new ArrayList<ControlButton>();
|
||||
}
|
||||
Reference in new issue
Block a user