176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell/* 276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * Copyright (C) 2014 The Android Open Source Project 376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * you may not use this file except in compliance with the License. 676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * You may obtain a copy of the License at 776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * http://www.apache.org/licenses/LICENSE-2.0 976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 1076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * Unless required by applicable law or agreed to in writing, software 1176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * distributed under the License is distributed on an "AS IS" BASIS, 1276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * See the License for the specific language governing permissions and 1476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * limitations under the License. 1576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell */ 1676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 1776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 1876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powellpackage android.widget; 1976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 2076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell/** 2176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * RtlSpacingHelper manages the relationship between left/right and start/end for views 2276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * that need to maintain both absolute and relative settings for a form of spacing similar 2376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * to view padding. 2476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell */ 2576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powellclass RtlSpacingHelper { 2676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public static final int UNDEFINED = Integer.MIN_VALUE; 2776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 2876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell private int mLeft = 0; 2976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell private int mRight = 0; 3076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell private int mStart = UNDEFINED; 3176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell private int mEnd = UNDEFINED; 3276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell private int mExplicitLeft = 0; 3376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell private int mExplicitRight = 0; 3476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 3576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell private boolean mIsRtl = false; 3676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell private boolean mIsRelative = false; 3776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 3876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public int getLeft() { 3976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell return mLeft; 4076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 4176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 4276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public int getRight() { 4376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell return mRight; 4476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 4576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 4676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public int getStart() { 4776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell return mIsRtl ? mRight : mLeft; 4876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 4976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 5076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public int getEnd() { 5176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell return mIsRtl ? mLeft : mRight; 5276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 5376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 5476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public void setRelative(int start, int end) { 5576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mStart = start; 5676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mEnd = end; 5776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mIsRelative = true; 5876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (mIsRtl) { 5976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (end != UNDEFINED) mLeft = end; 6076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (start != UNDEFINED) mRight = start; 6176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } else { 6276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (start != UNDEFINED) mLeft = start; 6376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (end != UNDEFINED) mRight = end; 6476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 6576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 6676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 6776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public void setAbsolute(int left, int right) { 6876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mIsRelative = false; 6976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (left != UNDEFINED) mLeft = mExplicitLeft = left; 7076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (right != UNDEFINED) mRight = mExplicitRight = right; 7176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 7276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 7376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public void setDirection(boolean isRtl) { 7476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (isRtl == mIsRtl) { 7576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell return; 7676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 7776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mIsRtl = isRtl; 7876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (mIsRelative) { 7976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (isRtl) { 8076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mLeft = mEnd != UNDEFINED ? mEnd : mExplicitLeft; 8176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mRight = mStart != UNDEFINED ? mStart : mExplicitRight; 8276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } else { 8376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mLeft = mStart != UNDEFINED ? mStart : mExplicitLeft; 8476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mRight = mEnd != UNDEFINED ? mEnd : mExplicitRight; 8576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 8676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } else { 8776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mLeft = mExplicitLeft; 8876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mRight = mExplicitRight; 8976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 9076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 9176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell} 92