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