1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.graphics.pdf.models.jni;
18 
19 import android.annotation.FlaggedApi;
20 import android.graphics.Point;
21 import android.graphics.pdf.flags.Flags;
22 
23 /** @hide */
24 // TODO(b/324536951): Remove this class after updating the native code to directly use
25 //  android.graphics.pdf.models.SelectionBoundary
26 public class SelectionBoundary {
27     private final int mIndex;
28 
29     private final int mX;
30 
31     private final int mY;
32 
33     private final boolean mIsRtl;
34 
SelectionBoundary(int index, int x, int y, boolean isRtl)35     public SelectionBoundary(int index, int x, int y, boolean isRtl) {
36         mIndex = index;
37         mX = x;
38         mY = y;
39         mIsRtl = isRtl;
40     }
41 
42     /**
43      * Converts the AOSP {@link android.graphics.pdf.models.selection.SelectionBoundary} to
44      * {@link android.graphics.pdf.models.jni.SelectionBoundary}.
45      *
46      * @param selectionBoundary AOSP input
47      * @return JNI output
48      */
49     @FlaggedApi(Flags.FLAG_ENABLE_PDF_VIEWER)
convert( android.graphics.pdf.models.selection.SelectionBoundary selectionBoundary)50     public static SelectionBoundary convert(
51             android.graphics.pdf.models.selection.SelectionBoundary selectionBoundary) {
52         if (selectionBoundary.getIndex() >= 0) {
53             return new SelectionBoundary(
54                     selectionBoundary.getIndex(), -1, -1, selectionBoundary.getIsRtl());
55         }
56         return new SelectionBoundary(-1,
57                 selectionBoundary.getPoint().x, selectionBoundary.getPoint().y,
58                 selectionBoundary.getIsRtl());
59     }
60 
getIndex()61     public int getIndex() {
62         return mIndex;
63     }
64 
getX()65     public int getX() {
66         return mX;
67     }
68 
getY()69     public int getY() {
70         return mY;
71     }
72 
isRtl()73     public boolean isRtl() {
74         return mIsRtl;
75     }
76 
77     /** Converts JNI models to the public class */
78     @FlaggedApi(Flags.FLAG_ENABLE_PDF_VIEWER)
convert()79     public android.graphics.pdf.models.selection.SelectionBoundary convert() {
80         if (mX >= 0 & mY >= 0) {
81             return new android.graphics.pdf.models.selection.SelectionBoundary(
82                     new Point(mX, mY));
83         }
84         return new android.graphics.pdf.models.selection.SelectionBoundary(mIndex);
85     }
86 }
87