[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:
Lioncash 2014-01-02 12:23:17 -05:00
parent 5635c94a30
commit e6497bca5a
2 changed files with 13 additions and 18 deletions

View File

@ -6,7 +6,6 @@
package org.dolphinemu.dolphinemu.settings.input.overlayconfig;
import android.view.WindowManager;
import org.dolphinemu.dolphinemu.R;
import android.app.Activity;
@ -23,18 +22,16 @@ public final class OverlayConfigActivity extends Activity
{
super.onCreate(savedInstanceState);
WindowManager wm = getWindowManager();
// Initialize all of the buttons to add.
final OverlayConfigButton buttonA = new OverlayConfigButton(wm, this, "gcpad_a", R.drawable.gcpad_a);
final OverlayConfigButton buttonB = new OverlayConfigButton(wm, this, "gcpad_b", R.drawable.gcpad_b);
final OverlayConfigButton buttonX = new OverlayConfigButton(wm, this, "gcpad_x", R.drawable.gcpad_x);
final OverlayConfigButton buttonY = new OverlayConfigButton(wm, this, "gcpad_y", R.drawable.gcpad_y);
final OverlayConfigButton buttonZ = new OverlayConfigButton(wm, this, "gcpad_z", R.drawable.gcpad_z);
final OverlayConfigButton buttonS = new OverlayConfigButton(wm, this, "gcpad_start", R.drawable.gcpad_start);
final OverlayConfigButton buttonL = new OverlayConfigButton(wm, this, "gcpad_l", R.drawable.gcpad_l);
final OverlayConfigButton buttonR = new OverlayConfigButton(wm, this, "gcpad_r", R.drawable.gcpad_r);
final OverlayConfigButton joystick = new OverlayConfigButton(wm, this, "gcpad_joystick_range", R.drawable.gcpad_joystick_range);
final OverlayConfigButton buttonA = new OverlayConfigButton(this, "gcpad_a", R.drawable.gcpad_a);
final OverlayConfigButton buttonB = new OverlayConfigButton(this, "gcpad_b", R.drawable.gcpad_b);
final OverlayConfigButton buttonX = new OverlayConfigButton(this, "gcpad_x", R.drawable.gcpad_x);
final OverlayConfigButton buttonY = new OverlayConfigButton(this, "gcpad_y", R.drawable.gcpad_y);
final OverlayConfigButton buttonZ = new OverlayConfigButton(this, "gcpad_z", R.drawable.gcpad_z);
final OverlayConfigButton buttonS = new OverlayConfigButton(this, "gcpad_start", R.drawable.gcpad_start);
final OverlayConfigButton buttonL = new OverlayConfigButton(this, "gcpad_l", R.drawable.gcpad_l);
final OverlayConfigButton buttonR = new OverlayConfigButton(this, "gcpad_r", R.drawable.gcpad_r);
final OverlayConfigButton joystick = new OverlayConfigButton(this, "gcpad_joystick_range", R.drawable.gcpad_joystick_range);
// Add the buttons to the layout
final RelativeLayout configLayout = new RelativeLayout(this);

View File

@ -16,7 +16,6 @@ import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.Button;
import org.dolphinemu.dolphinemu.R;
@ -42,11 +41,10 @@ public final class OverlayConfigButton extends Button implements OnTouchListener
// float buttonY = sPrefs.getFloat(buttonId+"-Y", -1f);
//
private final String buttonId;
private Drawable resizeDrawable(WindowManager wm, Drawable image, float scale)
private Drawable resizeDrawable(Drawable image, float scale)
{
// Retrieve screen dimensions.
DisplayMetrics displayMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(displayMetrics);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
Bitmap b = ((BitmapDrawable)image).getBitmap();
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 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);
@ -75,7 +73,7 @@ public final class OverlayConfigButton extends Button implements OnTouchListener
setOnTouchListener(this);
// 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));
// Get the SharedPreferences instance.