Skip to content

Commit

Permalink
Merge branch 'master' into remember-server
Browse files Browse the repository at this point in the history
  • Loading branch information
ShootingKing-AM committed Apr 14, 2024
2 parents b6121ad + 29850b6 commit 022f50e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import androidx.test.core.graphics.writeToTestStorage
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.pressBack
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
Expand Down Expand Up @@ -154,6 +156,10 @@ class ALVRActivityTest : PVRInstrumentationBase() {
sendADBCommand("sensor set acceleration 0:0:9.77622")
}

private fun lookFrontDown() {
sendADBCommand("sensor set acceleration 9.3:0:3.8")
}

private fun rotateAVDLandscape() {
// set gravity acceleration g in Y Direction - real Mock
sendADBCommand("sensor set acceleration 9.77622:0:0")
Expand Down Expand Up @@ -189,12 +195,23 @@ class ALVRActivityTest : PVRInstrumentationBase() {
}
takeScreenshot().writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")

lookDown()
onView(withId(R.id.ui_settings_button)).perform(click())
sleep(1000)
takeScreenshot().writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}_Popup")
onView(isRoot()).perform(pressBack()) // Close popup

lookFrontDown()
waitForADBTelnetServer() // Wait for ADBTelnetServer to execute rotation
sleep(1000)
takeScreenshot()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}_LookingFrontDown")

lookDown()
waitForADBTelnetServer() // Wait for ADBTelnetServer to execute rotation
sleep(1000)
takeScreenshot()
.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}_LookingDown")

// shutdownADBTelnetServer()
}
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import java.util.Objects;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

Expand All @@ -44,10 +45,10 @@ public class ALVRActivity extends AppCompatActivity

private GLSurfaceView glView;

private BatteryMonitor bMonitor = new BatteryMonitor(this);
private final BatteryMonitor bMonitor = new BatteryMonitor(this);

public class BatteryMonitor extends BroadcastReceiver {
private BatteryLevelListener listener;
public static class BatteryMonitor extends BroadcastReceiver {
private final BatteryLevelListener listener;

public BatteryMonitor(BatteryLevelListener listener) {
this.listener = listener;
Expand All @@ -66,7 +67,7 @@ public void stopMonitoring(Context context) {

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
if (Objects.equals(intent.getAction(), Intent.ACTION_BATTERY_CHANGED)) {
// Get the current battery level and scale
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
Expand Down Expand Up @@ -123,9 +124,13 @@ public void onCreate(Bundle savedInstance) {
});

// Forces screen to max brightness.
WindowManager.LayoutParams layout = getWindow().getAttributes();
layout.screenBrightness = 1.f;
getWindow().setAttributes(layout);
// get setting max_brightness boolean and set brightness to max if required
SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE);
if (prefs.getBoolean("max_brightness", true)) {
WindowManager.LayoutParams layout = getWindow().getAttributes();
layout.screenBrightness = 1.f;
getWindow().setAttributes(layout);
}

// Prevents screen from dimming/locking.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Expand Down Expand Up @@ -206,6 +211,13 @@ public void showSettings(View view) {
PopupMenu popup = new PopupMenu(this, view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.settings_menu, popup.getMenu());

MenuItem toggleBrightness = popup.getMenu().findItem(R.id.max_brightness_toggle);
// get setting max_brightness boolean from settings
SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE);
boolean isChecked = prefs.getBoolean("max_brightness", true);
toggleBrightness.setChecked(isChecked);

popup.setOnMenuItemClickListener(this);
popup.show();
}
Expand All @@ -225,6 +237,13 @@ public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(this, InitActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else if (item.getItemId() == R.id.max_brightness_toggle) {
// Save app setting boolean max_brightness == true
item.setChecked(!item.isChecked());
SharedPreferences.Editor editor = getSharedPreferences("settings", MODE_PRIVATE).edit();
editor.putBoolean("max_brightness", item.isChecked());
editor.apply();
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
android:title="@string/switch_viewer" />
<item android:id="@+id/switch_server"
android:title="@string/switch_phonevr_server" />
<item
android:id="@+id/max_brightness_toggle"
android:title="@string/max_brightness"
android:checkable="true"/>
</menu>
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
</string>
<string name="switch_phonevr_server">Switch PhoneVR Server</string>
<string name="remember_choice">Remember choice</string>
<string name="max_brightness">Max Brightness</string>
</resources>

0 comments on commit 022f50e

Please sign in to comment.