Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a79b94a3 authored by Ady Abraham's avatar Ady Abraham Committed by Android (Google) Code Review
Browse files

Merge changes I389ba9bc,I65f52605 into main

* changes:
  TouchLatency: add a new menu for supported refresh rates
  TouchLatency: upgrade to gradle 8.12.0
parents 26a0508d 905a4d3f
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -13,7 +13,10 @@ android_test {
    manifest: "app/src/main/AndroidManifest.xml",
    // omit gradle 'build' dir
    srcs: ["app/src/main/java/**/*.java"],
    static_libs: ["com.google.android.material_material"],
    static_libs: [
        "com.google.android.material_material",
        "androidx.appcompat_appcompat",
    ],
    resource_dirs: ["app/src/main/res"],
    aaptflags: ["--auto-add-overlay"],
    sdk_version: "current",
+3 −2
Original line number Diff line number Diff line
apply plugin: 'com.android.application'

android {
    compileSdkVersion 33
    compileSdkVersion 36

    defaultConfig {
        applicationId "com.prefabulated.touchlatency"
        minSdkVersion 30
        targetSdkVersion 33
        targetSdkVersion 36
        versionCode 1
        versionName "1.0"
    }
@@ -21,4 +21,5 @@ android {
        implementation 'androidx.appcompat:appcompat:1.5.1'
        implementation 'com.google.android.material:material:1.6.0'
    }
    namespace 'com.prefabulated.touchlatency'
}
+38 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.prefabulated.touchlatency;

import android.app.AlertDialog;
import android.hardware.display.DisplayManager;
import android.os.Bundle;
import android.os.Handler;
@@ -29,6 +30,8 @@ import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.WindowCompat;

import com.google.android.material.slider.RangeSlider;
import com.google.android.material.slider.RangeSlider.OnChangeListener;
@@ -59,8 +62,11 @@ public class TouchLatencyActivity extends AppCompatActivity {

        @Override
        public void onDisplayChanged(int i) {
            boolean hasArrSupport = getWindowManager().getDefaultDisplay().hasArrSupport();
            if (!hasArrSupport) {
                updateOptionsMenu();
            }
        }
    };

    private final RangeSlider.OnChangeListener mRefreshRateSliderListener = new OnChangeListener() {
@@ -78,9 +84,12 @@ public class TouchLatencyActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

        Trace.beginSection("TouchLatencyActivity onCreate");
        setContentView(R.layout.activity_touch_latency);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        mTouchView = findViewById(R.id.canvasView);

        configureDisplayListener();
@@ -95,6 +104,7 @@ public class TouchLatencyActivity extends AppCompatActivity {
                break;
            }
        }

        Trace.endSection();
    }

@@ -159,10 +169,6 @@ public class TouchLatencyActivity extends AppCompatActivity {
        slider.setValues(mSliderPreferredRefreshRate);
    }

    private void updateMultiDisplayMenu(MenuItem item) {
        item.setVisible(mDisplayManager.getDisplays().length > 1);
    }

    private void configureDisplayListener() {
        mDisplayManager = getSystemService(DisplayManager.class);
        mDisplayManager.registerDisplayListener(mDisplayListener, new Handler());
@@ -212,12 +218,39 @@ public class TouchLatencyActivity extends AppCompatActivity {
                changeDisplayMode(item);
                break;
            }
            case R.id.supported_refresh_rates: {
                showSupportedRefreshRates();
                break;
            }
        }

        Trace.endSection();
        return super.onOptionsItemSelected(item);
    }

    private void showSupportedRefreshRates() {
        Display display = getWindowManager().getDefaultDisplay();
        boolean hasArrSupport = display.hasArrSupport();
        final float[] refreshRates = display.getSupportedRefreshRates();
        String[] refreshRatesStr = new String[refreshRates.length + 1];
        refreshRatesStr[0] = "ARR Supported: " + (hasArrSupport ? "Yes" : "No");
        for (int i = 0; i < refreshRates.length; i++) {
            refreshRatesStr[i + 1] = String.format("%.2f", refreshRates[i]);
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Supported Refresh Rates");
        builder.setItems(refreshRatesStr, (dialog, which) -> {
            if (which == 0) {
                // Do nothing for the ARR support item
                return;
            }
            float selectedRefreshRate = refreshRates[which - 1];
            mTouchView.setRequestedFrameRate(selectedRefreshRate);
        });
        builder.create().show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
+4 −0
Original line number Diff line number Diff line
@@ -204,6 +204,10 @@ class TouchLatencyView extends View implements View.OnTouchListener {
        Trace.endSection();
    }

    public void setRequestedFrameRate(float requestedFrameRate) {
        super.setRequestedFrameRate(requestedFrameRate);
    }

    private final Paint mBluePaint, mGreenPaint, mYellowPaint, mRedPaint, mTextPaint;
    private int mMode;
    public static final String ACTION_MODES[] = {"Touch", "Ball"};
+26 −11
Original line number Diff line number Diff line
@@ -13,17 +13,32 @@
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:keepScreenOn="true"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".TouchLatencyActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TouchLatencyActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </com.google.android.material.appbar.AppBarLayout>

    <com.prefabulated.touchlatency.TouchLatencyView
        android:id="@+id/canvasView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
 No newline at end of file
Loading