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

Commit bd32923d authored by Brian Johnson's avatar Brian Johnson Committed by Android (Google) Code Review
Browse files

Merge "Remove all multidisplay functionality in the Touch Latency sample app,...

Merge "Remove all multidisplay functionality in the Touch Latency sample app, for now. Also update to newer gradle versions, to allow editing in Studio." into udc-dev
parents 14537765 019bf00d
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -2,7 +2,6 @@ apply plugin: 'com.android.application'


android {
android {
    compileSdkVersion 33
    compileSdkVersion 33
    buildToolsVersion '28.0.3'


    defaultConfig {
    defaultConfig {
        applicationId "com.prefabulated.touchlatency"
        applicationId "com.prefabulated.touchlatency"
+0 −6
Original line number Original line Diff line number Diff line
@@ -30,12 +30,6 @@
                <category android:name="android.intent.category.LAUNCHER"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            </intent-filter>
        </activity>
        </activity>

        <activity android:name=".TouchLatencyActivityPresentation"
            android:label="@string/app_name"
            android:parentActivityName=".TouchLatencyActivity"
            android:exported="true">
        </activity>
    </application>
    </application>


</manifest>
</manifest>
+0 −21
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


package com.prefabulated.touchlatency;
package com.prefabulated.touchlatency;


import android.app.ActivityOptions;
import android.content.Intent;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
@@ -105,7 +103,6 @@ public class TouchLatencyActivity extends AppCompatActivity {
            updateDisplayMode(menuItem, currentMode);
            updateDisplayMode(menuItem, currentMode);
        }
        }
        updateRefreshRateMenu(mMenu.findItem(R.id.frame_rate));
        updateRefreshRateMenu(mMenu.findItem(R.id.frame_rate));
        updateMultiDisplayMenu(mMenu.findItem(R.id.multi_display));
    }
    }


    @Override
    @Override
@@ -186,20 +183,6 @@ public class TouchLatencyActivity extends AppCompatActivity {
        mCurrentModeIndex = modeIndex;
        mCurrentModeIndex = modeIndex;
    }
    }


    private void changeMultipleDisplays() {
        Intent intent = new Intent(this, TouchLatencyActivityPresentation.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
        ActivityOptions options = ActivityOptions.makeBasic();
        for (int i = 1; i < mDisplayManager.getDisplays().length; ++i) {
            // We assume the first display is already displaying the TouchLatencyActivity
            int displayId = mDisplayManager.getDisplays()[i].getDisplayId();
            options.setLaunchDisplayId(displayId);
            intent.putExtra(TouchLatencyActivityPresentation.DISPLAY_ID, displayId);
            startActivity(intent, options.toBundle());
        }
    }


    @Override
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    public boolean onOptionsItemSelected(MenuItem item) {
        Trace.beginSection("TouchLatencyActivity onOptionsItemSelected");
        Trace.beginSection("TouchLatencyActivity onOptionsItemSelected");
@@ -218,10 +201,6 @@ public class TouchLatencyActivity extends AppCompatActivity {
                changeDisplayMode(item);
                changeDisplayMode(item);
                break;
                break;
            }
            }
            case R.id.multi_display: {
                changeMultipleDisplays();
                break;
            }
        }
        }


        Trace.endSection();
        Trace.endSection();
+0 −128
Original line number Original line Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.prefabulated.touchlatency;

import android.app.Activity;
import android.os.Bundle;
import android.os.Trace;
import android.view.Display;
import android.view.Display.Mode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;

public class TouchLatencyActivityPresentation extends Activity {
    public static final String DISPLAY_ID = "DISPLAY_ID";
    private Mode[] mDisplayModes;
    private int mCurrentModeIndex;
    private int mDisplayId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getIntent().hasExtra(DISPLAY_ID)) {
            mDisplayId = (int) getIntent().getExtras().get(DISPLAY_ID);
        }
        Trace.beginSection(
                "TouchLatencyActivityPresentation::DisplayId::" + mDisplayId + " onCreate");
        setContentView(R.layout.activity_touch_latency);

        mTouchView = findViewById(R.id.canvasView);

        WindowManager wm = getWindowManager();
        Display display = wm.getDefaultDisplay();
        mDisplayModes = display.getSupportedModes();
        Mode currentMode = getWindowManager().getDefaultDisplay().getMode();

        for (int i = 0; i < mDisplayModes.length; i++) {
            if (currentMode.getModeId() == mDisplayModes[i].getModeId()) {
                mCurrentModeIndex = i;
                break;
            }
        }
        Trace.endSection();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        Trace.beginSection(
                "TouchLatencyActivityPresentation::DisplayId:: "
                        + mDisplayId + "  onCreateOptionsMenu");
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_touch_latency, menu);
        if (mDisplayModes.length > 1) {
            MenuItem menuItem = menu.findItem(R.id.display_mode);
            Mode currentMode = getWindowManager().getDefaultDisplay().getMode();
            updateDisplayMode(menuItem, currentMode);
        }
        Trace.endSection();
        return true;
    }

    private void updateDisplayMode(MenuItem menuItem, Mode displayMode) {
        int fps = (int) displayMode.getRefreshRate();
        menuItem.setTitle(fps + "hz");
        menuItem.setVisible(true);
    }

    public void changeDisplayMode(MenuItem item) {
        Window w = getWindow();
        WindowManager.LayoutParams params = w.getAttributes();

        int modeIndex = (mCurrentModeIndex + 1) % mDisplayModes.length;
        params.preferredDisplayModeId = mDisplayModes[modeIndex].getModeId();
        w.setAttributes(params);

        updateDisplayMode(item, mDisplayModes[modeIndex]);
        mCurrentModeIndex = modeIndex;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Trace.beginSection(
                "TouchLatencyActivityPresentation::DisplayId::"
                        + mDisplayId + "  onOptionsItemSelected");
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        switch (id) {
            case R.id.action_settings: {
                mTouchView.changeMode(item);
                break;
            }
            case R.id.display_mode: {
                changeDisplayMode(item);
                break;
            }
        }

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

    private TouchLatencyView mTouchView;
}
+0 −5
Original line number Original line Diff line number Diff line
@@ -30,9 +30,4 @@
        android:title="@string/display_mode"
        android:title="@string/display_mode"
        android:visible="false"
        android:visible="false"
        app:showAsAction="always" />
        app:showAsAction="always" />
    <item
        android:id="@+id/multi_display"
        android:title="@string/multi_display"
        android:visible="false"
        app:showAsAction="ifRoom" />
</menu>
</menu>
Loading