mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Use statelist and onclick listener so the buttons don't bug out
This commit is contained in:
@@ -16,6 +16,7 @@ import android.graphics.BitmapFactory;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.GradientDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
||||||
|
import android.graphics.drawable.StateListDrawable;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@@ -28,7 +29,6 @@ import android.support.v4.content.ContextCompat;
|
|||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
@@ -57,11 +57,12 @@ public class Main extends AndroidApplication {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
boolean permissiongranted = checkPermission();
|
||||||
Gadapter = new AndroidAdapter(this.getContext());
|
Gadapter = new AndroidAdapter(this.getContext());
|
||||||
initForge(Gadapter);
|
initForge(Gadapter, permissiongranted);
|
||||||
|
|
||||||
//permission
|
//permission
|
||||||
if(!checkPermission()){
|
if(!permissiongranted){
|
||||||
//requestPermission();
|
//requestPermission();
|
||||||
displayMessage(Gadapter);
|
displayMessage(Gadapter);
|
||||||
}
|
}
|
||||||
@@ -102,35 +103,26 @@ public class Main extends AndroidApplication {
|
|||||||
gd2.setCornerRadius(100);
|
gd2.setCornerRadius(100);
|
||||||
|
|
||||||
Button button = new Button(this);
|
Button button = new Button(this);
|
||||||
button.setBackground(gd);
|
|
||||||
button.setText("Open App Details");
|
button.setText("Open App Details");
|
||||||
button.setOnTouchListener(new View.OnTouchListener() {
|
|
||||||
|
StateListDrawable states = new StateListDrawable();
|
||||||
|
|
||||||
|
states.addState(new int[] {android.R.attr.state_pressed}, gd2);
|
||||||
|
states.addState(new int[] { }, gd);
|
||||||
|
|
||||||
|
button.setBackground(states);
|
||||||
|
|
||||||
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View arg0, MotionEvent arg1) {
|
public void onClick(View v) {
|
||||||
switch(arg1.getAction()){
|
|
||||||
case MotionEvent.ACTION_DOWN:
|
|
||||||
// Button is pressed. Change the button to pressed state here
|
|
||||||
button.setBackground(gd2);
|
|
||||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||||
intent.setData(uri);
|
intent.setData(uri);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
|
||||||
// Button is being touched and swiped
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_UP:
|
|
||||||
// Button is released. Change the button to unpressed state here.
|
|
||||||
button.setBackground(gd);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
row2.addView(button);
|
row2.addView(button);
|
||||||
row2.setGravity(Gravity.CENTER);
|
row2.setGravity(Gravity.CENTER);
|
||||||
|
|
||||||
@@ -188,7 +180,7 @@ public class Main extends AndroidApplication {
|
|||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initForge(AndroidAdapter adapter){
|
private void initForge(AndroidAdapter adapter, boolean permissiongranted){
|
||||||
//establish assets directory
|
//establish assets directory
|
||||||
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||||
Gdx.app.error("Forge", "Can't access external storage");
|
Gdx.app.error("Forge", "Can't access external storage");
|
||||||
@@ -212,14 +204,19 @@ public class Main extends AndroidApplication {
|
|||||||
//enforce orientation based on whether device is a tablet and user preference
|
//enforce orientation based on whether device is a tablet and user preference
|
||||||
adapter.switchOrientationFile = assetsDir + "switch_orientation.ini";
|
adapter.switchOrientationFile = assetsDir + "switch_orientation.ini";
|
||||||
boolean landscapeMode = adapter.isTablet == !FileUtil.doesFileExist(adapter.switchOrientationFile);
|
boolean landscapeMode = adapter.isTablet == !FileUtil.doesFileExist(adapter.switchOrientationFile);
|
||||||
|
if (permissiongranted){
|
||||||
if (landscapeMode) {
|
if (landscapeMode) {
|
||||||
Main.this.setRequestedOrientation(Build.VERSION.SDK_INT >= 26 ?
|
Main.this.setRequestedOrientation(Build.VERSION.SDK_INT >= 26 ?
|
||||||
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : //Oreo and above has virtual back/menu buttons
|
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : //Oreo and above has virtual back/menu buttons
|
||||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
Main.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
//set current orientation
|
||||||
|
Main.this.setRequestedOrientation(Main.this.getResources().getConfiguration().orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
initialize(Forge.getApp(new AndroidClipboard(), adapter, assetsDir, Build.VERSION.SDK_INT >= 26));
|
initialize(Forge.getApp(new AndroidClipboard(), adapter, assetsDir, Build.VERSION.SDK_INT >= 26));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user