[Android] Simplify instantiations of OverlayConfigButton.java. Also simplified resizeDrawable even more. We just acquire the resource instance and then get the display metrics directly.
This commit is contained in:
parent
5635c94a30
commit
e6497bca5a
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
package org.dolphinemu.dolphinemu.settings.input.overlayconfig;
|
package org.dolphinemu.dolphinemu.settings.input.overlayconfig;
|
||||||
|
|
||||||
import android.view.WindowManager;
|
|
||||||
import org.dolphinemu.dolphinemu.R;
|
import org.dolphinemu.dolphinemu.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
@ -23,18 +22,16 @@ public final class OverlayConfigActivity extends Activity
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
WindowManager wm = getWindowManager();
|
|
||||||
|
|
||||||
// Initialize all of the buttons to add.
|
// Initialize all of the buttons to add.
|
||||||
final OverlayConfigButton buttonA = new OverlayConfigButton(wm, this, "gcpad_a", R.drawable.gcpad_a);
|
final OverlayConfigButton buttonA = new OverlayConfigButton(this, "gcpad_a", R.drawable.gcpad_a);
|
||||||
final OverlayConfigButton buttonB = new OverlayConfigButton(wm, this, "gcpad_b", R.drawable.gcpad_b);
|
final OverlayConfigButton buttonB = new OverlayConfigButton(this, "gcpad_b", R.drawable.gcpad_b);
|
||||||
final OverlayConfigButton buttonX = new OverlayConfigButton(wm, this, "gcpad_x", R.drawable.gcpad_x);
|
final OverlayConfigButton buttonX = new OverlayConfigButton(this, "gcpad_x", R.drawable.gcpad_x);
|
||||||
final OverlayConfigButton buttonY = new OverlayConfigButton(wm, this, "gcpad_y", R.drawable.gcpad_y);
|
final OverlayConfigButton buttonY = new OverlayConfigButton(this, "gcpad_y", R.drawable.gcpad_y);
|
||||||
final OverlayConfigButton buttonZ = new OverlayConfigButton(wm, this, "gcpad_z", R.drawable.gcpad_z);
|
final OverlayConfigButton buttonZ = new OverlayConfigButton(this, "gcpad_z", R.drawable.gcpad_z);
|
||||||
final OverlayConfigButton buttonS = new OverlayConfigButton(wm, this, "gcpad_start", R.drawable.gcpad_start);
|
final OverlayConfigButton buttonS = new OverlayConfigButton(this, "gcpad_start", R.drawable.gcpad_start);
|
||||||
final OverlayConfigButton buttonL = new OverlayConfigButton(wm, this, "gcpad_l", R.drawable.gcpad_l);
|
final OverlayConfigButton buttonL = new OverlayConfigButton(this, "gcpad_l", R.drawable.gcpad_l);
|
||||||
final OverlayConfigButton buttonR = new OverlayConfigButton(wm, this, "gcpad_r", R.drawable.gcpad_r);
|
final OverlayConfigButton buttonR = new OverlayConfigButton(this, "gcpad_r", R.drawable.gcpad_r);
|
||||||
final OverlayConfigButton joystick = new OverlayConfigButton(wm, this, "gcpad_joystick_range", R.drawable.gcpad_joystick_range);
|
final OverlayConfigButton joystick = new OverlayConfigButton(this, "gcpad_joystick_range", R.drawable.gcpad_joystick_range);
|
||||||
|
|
||||||
// Add the buttons to the layout
|
// Add the buttons to the layout
|
||||||
final RelativeLayout configLayout = new RelativeLayout(this);
|
final RelativeLayout configLayout = new RelativeLayout(this);
|
||||||
|
|
|
@ -16,7 +16,6 @@ import android.util.DisplayMetrics;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnTouchListener;
|
import android.view.View.OnTouchListener;
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import org.dolphinemu.dolphinemu.R;
|
import org.dolphinemu.dolphinemu.R;
|
||||||
|
|
||||||
|
@ -42,11 +41,10 @@ public final class OverlayConfigButton extends Button implements OnTouchListener
|
||||||
// float buttonY = sPrefs.getFloat(buttonId+"-Y", -1f);
|
// float buttonY = sPrefs.getFloat(buttonId+"-Y", -1f);
|
||||||
//
|
//
|
||||||
private final String buttonId;
|
private final String buttonId;
|
||||||
private Drawable resizeDrawable(WindowManager wm, Drawable image, float scale)
|
private Drawable resizeDrawable(Drawable image, float scale)
|
||||||
{
|
{
|
||||||
// Retrieve screen dimensions.
|
// Retrieve screen dimensions.
|
||||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
||||||
wm.getDefaultDisplay().getMetrics(displayMetrics);
|
|
||||||
|
|
||||||
Bitmap b = ((BitmapDrawable)image).getBitmap();
|
Bitmap b = ((BitmapDrawable)image).getBitmap();
|
||||||
Bitmap bitmapResized = Bitmap.createScaledBitmap(b,
|
Bitmap bitmapResized = Bitmap.createScaledBitmap(b,
|
||||||
|
@ -64,7 +62,7 @@ public final class OverlayConfigButton extends Button implements OnTouchListener
|
||||||
* @param buttonId the String ID for this button.
|
* @param buttonId the String ID for this button.
|
||||||
* @param drawableId the Drawable ID for the image to represent this OverlayConfigButton.
|
* @param drawableId the Drawable ID for the image to represent this OverlayConfigButton.
|
||||||
*/
|
*/
|
||||||
public OverlayConfigButton(WindowManager wm, Context context, String buttonId, int drawableId)
|
public OverlayConfigButton(Context context, String buttonId, int drawableId)
|
||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
|
@ -75,7 +73,7 @@ public final class OverlayConfigButton extends Button implements OnTouchListener
|
||||||
setOnTouchListener(this);
|
setOnTouchListener(this);
|
||||||
|
|
||||||
// Set the button's icon that represents it.
|
// Set the button's icon that represents it.
|
||||||
setBackground(resizeDrawable(wm, getResources().getDrawable(drawableId),
|
setBackground(resizeDrawable(getResources().getDrawable(drawableId),
|
||||||
drawableId == R.drawable.gcpad_joystick_range ? 0.30f : 0.20f));
|
drawableId == R.drawable.gcpad_joystick_range ? 0.30f : 0.20f));
|
||||||
|
|
||||||
// Get the SharedPreferences instance.
|
// Get the SharedPreferences instance.
|
||||||
|
|
Loading…
Reference in New Issue