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

Commit 7ae5e836 authored by Ajinkya Chalke's avatar Ajinkya Chalke
Browse files

Update app clips UI to support edge to edge

- Android V is introducing forcing apps to adopt edge to edge display.
- So, updating the app clips UI by following
  https://developer.android.com/develop/ui/views/layout/edge-to-edge.

Bug: 340837939
Flag: EXEMPT bugfix
Test: Launch app clips and manually verify this on device.
Change-Id: Ic081d929bc2f0ef104a83477ff628caad3a400bf
parent 98c094c2
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -46,6 +46,9 @@ import android.widget.ImageView;

import androidx.activity.ComponentActivity;
import androidx.annotation.Nullable;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.lifecycle.ViewModelProvider;

import com.android.internal.logging.UiEventLogger;
@@ -149,6 +152,14 @@ public class AppClipsActivity extends ComponentActivity {
        mLayout = getLayoutInflater().inflate(R.layout.app_clips_screenshot, null);
        mRoot = mLayout.findViewById(R.id.root);

        // Manually handle window insets post Android V to support edge-to-edge display.
        ViewCompat.setOnApplyWindowInsetsListener(mRoot, (v, windowInsets) -> {
            Insets insets = windowInsets.getInsets(
                    WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
            v.setPadding(insets.left, insets.top, insets.right, insets.bottom);
            return WindowInsetsCompat.CONSUMED;
        });

        mSave = mLayout.findViewById(R.id.save);
        mCancel = mLayout.findViewById(R.id.cancel);
        mSave.setOnClickListener(this::onClick);
@@ -217,6 +228,9 @@ public class AppClipsActivity extends ComponentActivity {

        // Screenshot is now available so set content view.
        setContentView(mLayout);

        // Request view to apply insets as it is added late and not when activity was first created.
        mRoot.requestApplyInsets();
    }

    private void onClick(View view) {
@@ -268,7 +282,7 @@ public class AppClipsActivity extends ComponentActivity {
            mResultReceiver.send(Activity.RESULT_OK, data);
            logUiEvent(SCREENSHOT_FOR_NOTE_ACCEPTED);
        } catch (Exception e) {
            // Do nothing.
            Log.e(TAG, "Error while returning data to trampoline activity", e);
        }

        // Nullify the ResultReceiver before finishing to avoid resending the result.