1 /* 2 * Copyright (C) 2006 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; 18 19 @android.ravenwood.annotation.RavenwoodKeepWholeClass 20 public class RegionIterator { 21 22 /** 23 * Construct an iterator for all of the rectangles in a region. This 24 * effectively makes a private copy of the region, so any subsequent edits 25 * to region will not affect the iterator. 26 * 27 * @param region the region that will be iterated 28 */ RegionIterator(Region region)29 public RegionIterator(Region region) { 30 mNativeIter = nativeConstructor(region.ni()); 31 } 32 33 /** 34 * Return the next rectangle in the region. If there are no more rectangles 35 * this returns false and r is unchanged. If there is at least one more, 36 * this returns true and r is set to that rectangle. 37 */ next(Rect r)38 public final boolean next(Rect r) { 39 if (r == null) { 40 throw new NullPointerException("The Rect must be provided"); 41 } 42 return nativeNext(mNativeIter, r); 43 } 44 finalize()45 protected void finalize() throws Throwable { 46 nativeDestructor(mNativeIter); 47 mNativeIter = 0; // Other finalizers can still call us. 48 } 49 nativeConstructor(long native_region)50 private static native long nativeConstructor(long native_region); nativeDestructor(long native_iter)51 private static native void nativeDestructor(long native_iter); nativeNext(long native_iter, Rect r)52 private static native boolean nativeNext(long native_iter, Rect r); 53 54 private long mNativeIter; 55 } 56 57