summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/OrientationController.java
blob: e2a4c236b5b19ef571a6c2cdc1c504b81c88cb62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
 * vim: ts=4 sw=4 expandtab:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.geckoview;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import org.mozilla.gecko.util.ThreadUtils;

public class OrientationController {
  private OrientationDelegate mDelegate;

  OrientationController() {}

  /**
   * Sets the {@link OrientationDelegate} for this instance.
   *
   * @param delegate The {@link OrientationDelegate} instance.
   */
  @UiThread
  public void setDelegate(final @Nullable OrientationDelegate delegate) {
    ThreadUtils.assertOnUiThread();
    mDelegate = delegate;
  }

  /**
   * Gets the {@link OrientationDelegate} for this instance.
   *
   * @return delegate The {@link OrientationDelegate} instance.
   */
  @UiThread
  @Nullable
  public OrientationDelegate getDelegate() {
    ThreadUtils.assertOnUiThread();
    return mDelegate;
  }

  /** This delegate will be called whenever an orientation lock is called. */
  @UiThread
  public interface OrientationDelegate {
    /**
     * Called whenever the orientation should be locked.
     *
     * @param aOrientation The desired orientation such as ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
     * @return A {@link GeckoResult} which resolves to a {@link AllowOrDeny}
     */
    @Nullable
    default GeckoResult<AllowOrDeny> onOrientationLock(@NonNull final int aOrientation) {
      return null;
    }

    /** Called whenever the orientation should be unlocked. */
    @Nullable
    default void onOrientationUnlock() {}
  }
}