This repository was archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored Developer Options code (#607)
* Refactored Developer Options code * Reverted MSAA default to 2x * Fixed environments names and replaced by -> x
- Loading branch information
1 parent
0ad0545
commit 4d6344f
Showing
19 changed files
with
1,109 additions
and
1,310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
781 changes: 176 additions & 605 deletions
781
app/src/common/shared/org/mozilla/vrbrowser/ui/DeveloperOptionsWidget.java
Large diffs are not rendered by default.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
app/src/common/shared/org/mozilla/vrbrowser/ui/settings/ButtonSetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.mozilla.vrbrowser.ui.settings; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import org.mozilla.vrbrowser.R; | ||
import org.mozilla.vrbrowser.audio.AudioEngine; | ||
|
||
public class ButtonSetting extends LinearLayout { | ||
|
||
private AudioEngine mAudio; | ||
private String mDescription; | ||
private String mButtonText; | ||
private TextView mButton; | ||
private OnClickListener mListener; | ||
|
||
public ButtonSetting(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public ButtonSetting(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
|
||
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.ButtonSetting, defStyleAttr, 0); | ||
mDescription = attributes.getString(R.styleable.ButtonSetting_description); | ||
mButtonText = attributes.getString(R.styleable.ButtonSetting_buttonText); | ||
attributes.recycle(); | ||
|
||
initialize(context); | ||
} | ||
|
||
private void initialize(Context aContext) { | ||
inflate(aContext, R.layout.setting_button, this); | ||
|
||
mAudio = AudioEngine.fromContext(aContext); | ||
|
||
TextView description = findViewById(R.id.setting_description); | ||
description.setText(mButtonText); | ||
|
||
mButton = findViewById(R.id.button); | ||
mButton.setText(mButtonText); | ||
mButton.setOnClickListener(mInternalClickListener); | ||
} | ||
|
||
private View.OnClickListener mInternalClickListener = new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
onClickListener(v); | ||
} | ||
}; | ||
|
||
protected void onClickListener(View v) { | ||
if (mAudio != null) { | ||
mAudio.playSound(AudioEngine.Sound.CLICK); | ||
} | ||
|
||
if (mListener != null) { | ||
mListener.onClick(v); | ||
} | ||
} | ||
|
||
public void setOnClickListener(OnClickListener aListener) { | ||
mListener = aListener; | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
app/src/common/shared/org/mozilla/vrbrowser/ui/settings/DoubleEditSetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.mozilla.vrbrowser.ui.settings; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
|
||
import org.mozilla.vrbrowser.R; | ||
|
||
public class DoubleEditSetting extends SingleEditSetting { | ||
|
||
private String mBy; | ||
private TextView mText2; | ||
private EditText mEdit2; | ||
|
||
public DoubleEditSetting(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public DoubleEditSetting(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
|
||
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.EditSetting, defStyleAttr, 0); | ||
mBy = attributes.getString(R.styleable.EditSetting_by); | ||
attributes.recycle(); | ||
|
||
initialize(context); | ||
} | ||
|
||
private void initialize(Context aContext) { | ||
TextView by = findViewById(R.id.setting_by); | ||
by.setText(mBy); | ||
by.setVisibility(View.VISIBLE); | ||
|
||
mText2 = findViewById(R.id.text2); | ||
mEdit2 = findViewById(R.id.edit2); | ||
mEdit2.setSoundEffectsEnabled(false); | ||
|
||
mEdit2.setOnEditorActionListener(mInternalEditorActionListener); | ||
} | ||
|
||
protected void onClickListener(View v) { | ||
mText2.setVisibility(mEdit1.getVisibility()); | ||
mEdit2.setVisibility(mEdit1.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); | ||
|
||
super.onClickListener(v); | ||
} | ||
|
||
public String getSecondText() { | ||
return mEdit2.getText().toString(); | ||
} | ||
|
||
public void setSecondText(String text) { | ||
mText2.setText(text); | ||
mEdit2.setText(text); | ||
} | ||
|
||
} |
133 changes: 133 additions & 0 deletions
133
app/src/common/shared/org/mozilla/vrbrowser/ui/settings/RadioGroupSetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.mozilla.vrbrowser.ui.settings; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.support.annotation.IdRes; | ||
import android.util.AttributeSet; | ||
import android.util.TypedValue; | ||
import android.view.ContextThemeWrapper; | ||
import android.widget.LinearLayout; | ||
import android.widget.RadioButton; | ||
import android.widget.RadioGroup; | ||
import android.widget.TextView; | ||
|
||
import org.mozilla.vrbrowser.R; | ||
import org.mozilla.vrbrowser.audio.AudioEngine; | ||
|
||
public class RadioGroupSetting extends LinearLayout { | ||
|
||
public interface OnCheckedChangeListener { | ||
void onCheckedChanged(RadioGroup compoundButton, @IdRes int checkedId, boolean apply); | ||
} | ||
|
||
private AudioEngine mAudio; | ||
private String mDecription; | ||
private CharSequence[] mOptions; | ||
private Object[] mValues; | ||
private RadioGroup mRadioGroup; | ||
private TextView mRadioDescription; | ||
private OnCheckedChangeListener mRadioGroupListener; | ||
|
||
public RadioGroupSetting(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public RadioGroupSetting(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
|
||
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.RadioGroupSetting, defStyleAttr, 0); | ||
mDecription = attributes.getString(R.styleable.RadioGroupSetting_description); | ||
mOptions = attributes.getTextArray(R.styleable.RadioGroupSetting_options); | ||
int id = attributes.getResourceId(R.styleable.RadioGroupSetting_values, 0); | ||
TypedArray array = context.getResources().obtainTypedArray(id); | ||
if (array.getType(0) == TypedValue.TYPE_STRING) { | ||
mValues = getResources().getStringArray(id); | ||
|
||
} else if (array.getType(0) == TypedValue.TYPE_INT_HEX || | ||
array.getType(0) == TypedValue.TYPE_INT_DEC) { | ||
int [] values = getResources().getIntArray(id); | ||
mValues = new Integer[values.length]; | ||
for (int i=0; i<values.length; i++) { | ||
mValues[i] = values[i]; | ||
} | ||
} | ||
attributes.recycle(); | ||
|
||
initialize(context); | ||
} | ||
|
||
private void initialize(Context aContext) { | ||
inflate(aContext, R.layout.setting_radio_group, this); | ||
|
||
mAudio = AudioEngine.fromContext(aContext); | ||
|
||
mRadioDescription = findViewById(R.id.setting_description); | ||
mRadioDescription.setText(mDecription); | ||
|
||
mRadioGroup = findViewById(R.id.radio_group); | ||
mRadioGroup.setSoundEffectsEnabled(false); | ||
|
||
for (int i=0; i<mOptions.length; i++) { | ||
RadioButton button = new RadioButton(new ContextThemeWrapper(getContext(), R.style.radioButtonTheme), null, 0); | ||
button.setClickable(true); | ||
button.setId(i); | ||
button.setText(mOptions[i]); | ||
button.setSoundEffectsEnabled(false); | ||
mRadioGroup.addView(button); | ||
} | ||
|
||
mRadioGroup.setOnCheckedChangeListener(mInternalRadioListener); | ||
} | ||
|
||
private RadioGroup.OnCheckedChangeListener mInternalRadioListener = new RadioGroup.OnCheckedChangeListener() { | ||
@Override | ||
public void onCheckedChanged(RadioGroup compoundButton, @IdRes int checkedId) { | ||
if (mAudio != null) { | ||
mAudio.playSound(AudioEngine.Sound.CLICK); | ||
} | ||
|
||
setChecked(checkedId, true); | ||
} | ||
}; | ||
|
||
public void setChecked(@IdRes int checkedId, boolean doApply) { | ||
mRadioGroup.setOnCheckedChangeListener(null); | ||
for (int i=0; i<mRadioGroup.getChildCount(); i++) { | ||
RadioButton button = (RadioButton) mRadioGroup.getChildAt(i); | ||
if (i == checkedId) { | ||
button.setChecked(true); | ||
|
||
} else { | ||
button.setChecked(false); | ||
} | ||
} | ||
mRadioGroup.setOnCheckedChangeListener(mInternalRadioListener); | ||
|
||
if (mRadioGroupListener != null && doApply) { | ||
mRadioGroupListener.onCheckedChanged(mRadioGroup, checkedId, doApply); | ||
} | ||
} | ||
|
||
public void setOnCheckedChangeListener(OnCheckedChangeListener aListener) { | ||
mRadioGroupListener = aListener; | ||
} | ||
|
||
public Object getValueForId(@IdRes int checkId) { | ||
return mValues[checkId]; | ||
} | ||
|
||
public int getIdForValue(Object value) { | ||
for (int i=0; i<mValues.length; i++) { | ||
if (mValues[i].equals(value)) { | ||
return i; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
public int getCheckedRadioButtonId() { | ||
return mRadioGroup.getCheckedRadioButtonId(); | ||
} | ||
|
||
} |
Oops, something went wrong.