11c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu/* 21c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * Copyright (C) 2013 The Android Open Source Project 31c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * 41c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * Licensed under the Apache License, Version 2.0 (the "License"); 51c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * you may not use this file except in compliance with the License. 61c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * You may obtain a copy of the License at 71c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * 81c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * http://www.apache.org/licenses/LICENSE-2.0 91c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * 101c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * Unless required by applicable law or agreed to in writing, software 111c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * distributed under the License is distributed on an "AS IS" BASIS, 121c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * See the License for the specific language governing permissions and 141c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * limitations under the License. 151c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu */ 161c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 171c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liupackage com.android.camera.ui; 181c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 191c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liuimport android.content.Context; 201c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liuimport android.graphics.Canvas; 2153b3ddbae16c5efbac842e158525720d0b9108cbDoris Liuimport android.graphics.Typeface; 2258ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liuimport android.graphics.drawable.Drawable; 231c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liuimport android.util.AttributeSet; 246ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liuimport android.view.MotionEvent; 251c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liuimport android.widget.FrameLayout; 261c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liuimport android.widget.TextView; 271c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 2853b3ddbae16c5efbac842e158525720d0b9108cbDoris Liuimport com.android.camera.util.ApiHelper; 291c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liuimport com.android.camera2.R; 301c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 3170576b611fddc929abbfb466fa44c396a3a793dbDoris Liu/** 3270576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * This is a package private class, as it is not intended to be visible or used 3370576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * outside of this package. 3470576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * 3570576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * ModeSelectorItem is a FrameLayout that contains an ImageView to display the 3670576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * icon for the corresponding mode, a TextView that explains what the mode is, 3770576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * and a GradientDrawable at the end of the TextView. 3870576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * 3970576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * The purpose of this class is to encapsulate different drawing logic into 40213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * its own class. There are two drawing mode, <code>FLY_IN</code> 41213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * and <code>FLY_OUT</code>. They define how we draw the view when 4270576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * we display the view partially. 4370576b611fddc929abbfb466fa44c396a3a793dbDoris Liu */ 441c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liuclass ModeSelectorItem extends FrameLayout { 451c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu private TextView mText; 46213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu private ModeIconView mIcon; 478676e7802fb40f64a3b465c9b5e1a0a1ada9f699Doris Liu private int mVisibleWidth = 0; 48213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu private final int mMinVisibleWidth; 4969cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu private VisibleWidthChangedListener mListener = null; 501c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 511c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu private int mWidth; 526ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu private int mModeId; 531c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 5469cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu /** 5569cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu * A listener that gets notified when the visible width of the current item 5669cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu * is changed. 5769cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu */ 5869cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu public interface VisibleWidthChangedListener { 5969cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu public void onVisibleWidthChanged(int width); 6069cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu } 6169cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu 621c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu public ModeSelectorItem(Context context, AttributeSet attrs) { 631c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu super(context, attrs); 64213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu setWillNotDraw(false); 656ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu setClickable(true); 66213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu mMinVisibleWidth = getResources() 67213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu .getDimensionPixelSize(R.dimen.mode_selector_icon_block_width); 681c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 691c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 701c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu @Override 711c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu public void onFinishInflate() { 72213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu mIcon = (ModeIconView) findViewById(R.id.selector_icon); 731c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu mText = (TextView) findViewById(R.id.selector_text); 7453b3ddbae16c5efbac842e158525720d0b9108cbDoris Liu Typeface typeface; 75040e3c053cc0d2097332de24cf5328a26a8e7332Doris Liu if (ApiHelper.HAS_ROBOTO_MEDIUM_FONT) { 76040e3c053cc0d2097332de24cf5328a26a8e7332Doris Liu typeface = Typeface.create("sans-serif-medium", Typeface.NORMAL); 7753b3ddbae16c5efbac842e158525720d0b9108cbDoris Liu } else { 7853b3ddbae16c5efbac842e158525720d0b9108cbDoris Liu // Load roboto_light typeface from assets. 7953b3ddbae16c5efbac842e158525720d0b9108cbDoris Liu typeface = Typeface.createFromAsset(getResources().getAssets(), 80040e3c053cc0d2097332de24cf5328a26a8e7332Doris Liu "Roboto-Medium.ttf"); 8153b3ddbae16c5efbac842e158525720d0b9108cbDoris Liu } 8253b3ddbae16c5efbac842e158525720d0b9108cbDoris Liu mText.setTypeface(typeface); 83b6eaa8c70da19fb3233c3c4b1a2625ce90fc35afDoris Liu } 84b6eaa8c70da19fb3233c3c4b1a2625ce90fc35afDoris Liu 85b6eaa8c70da19fb3233c3c4b1a2625ce90fc35afDoris Liu public void setDefaultBackgroundColor(int color) { 86b6eaa8c70da19fb3233c3c4b1a2625ce90fc35afDoris Liu setBackgroundColor(color); 871c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 881c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 8969cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu /** 9069cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu * Sets a listener that receives a callback when the visible width of this 9169cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu * selector item changes. 9269cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu */ 9369cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu public void setVisibleWidthChangedListener(VisibleWidthChangedListener listener) { 9469cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu mListener = listener; 9569cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu } 9669cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu 970496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague @Override 98213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu public void setSelected(boolean selected) { 99213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu mIcon.setSelected(selected); 100b6eaa8c70da19fb3233c3c4b1a2625ce90fc35afDoris Liu } 101b6eaa8c70da19fb3233c3c4b1a2625ce90fc35afDoris Liu 1026ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu @Override 1036ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu public boolean dispatchTouchEvent(MotionEvent ev) { 1046ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu // Do not dispatch any touch event, so that all the events that are received 1056ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu // in onTouchEvent() are only through forwarding. 1066ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu return false; 1076ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu } 1086ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu 1096ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu @Override 1106ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu public boolean onTouchEvent(MotionEvent ev) { 1116ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu super.onTouchEvent(ev); 1126ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu return false; 1136ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu } 1146ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu 11570576b611fddc929abbfb466fa44c396a3a793dbDoris Liu /** 11670576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * When swiping in, we truncate the end of the item if the visible width 11770576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * is not enough to show the whole item. When swiping out, we truncate the 11870576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * front of the text (i.e. offset the text). 11970576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * 12070576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * @param swipeIn whether swiping direction is swiping in (i.e. from left 12170576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * to right) 12270576b611fddc929abbfb466fa44c396a3a793dbDoris Liu */ 1231c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu public void onSwipeModeChanged(boolean swipeIn) { 1241c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu mText.setTranslationX(0); 1251c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 1261c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 1271c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu public void setText(CharSequence text) { 1281c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu mText.setText(text); 1291c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 1301c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 1311c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu @Override 1321c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu public void onLayout(boolean changed, int left, int top, int right, int bottom) { 1331c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu super.onLayout(changed, left, top, right, bottom); 1341c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu mWidth = right - left; 1351c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu if (changed && mVisibleWidth > 0) { 1361c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu // Reset mode list to full screen 1371c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu setVisibleWidth(mWidth); 1381c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 1391c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 1401c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 14170576b611fddc929abbfb466fa44c396a3a793dbDoris Liu /** 14258ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu * Sets image resource as the icon for the mode. By default, all drawables instances 14358ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu * loaded from the same resource share a common state; if you modify the state 14458ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu * of one instance, all the other instances will receive the same modification. 14558ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu * In order to modify properties of this icon drawable without affecting other 14658ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu * drawables, here we use a mutable drawable which is guaranteed to not share 14758ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu * states with other drawables. 14870576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * 149f55f3c461c5a6ae6b61fa75562ca01683aa93f9aDoris Liu * @param resource resource id of the asset to be used as icon 15070576b611fddc929abbfb466fa44c396a3a793dbDoris Liu */ 151f55f3c461c5a6ae6b61fa75562ca01683aa93f9aDoris Liu public void setImageResource(int resource) { 15258ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu Drawable drawableIcon = getResources().getDrawable(resource); 15358ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu if (drawableIcon != null) { 15458ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu drawableIcon = drawableIcon.mutate(); 15558ac7e042e0718e860f9aea6dca3697e1c3d9bb8Doris Liu } 156040e3c053cc0d2097332de24cf5328a26a8e7332Doris Liu mIcon.setIconDrawable(drawableIcon); 1571c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 1581c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 1591c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu /** 1601c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * Sets the visible width preferred for the item. The item can then decide how 1611c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * to draw itself based on the visible width and whether it's being swiped in 1621c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * or out. This function will be called on every frame during animation. It should 1631c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * only do minimal work required to get the animation working. 16470576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * 16570576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * @param newWidth new visible width 1661c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu */ 1671c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu public void setVisibleWidth(int newWidth) { 168213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu int fullyShownIconWidth = getMaxVisibleWidth(); 1691c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu newWidth = Math.max(newWidth, 0); 1701c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu // Visible width should not be greater than view width 171213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu newWidth = Math.min(newWidth, fullyShownIconWidth); 17269cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu 17369cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu if (mVisibleWidth != newWidth) { 17469cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu mVisibleWidth = newWidth; 17569cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu if (mListener != null) { 17669cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu mListener.onVisibleWidthChanged(newWidth); 17769cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu } 17869cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu } 1791c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu invalidate(); 1801c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 1811c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 1821c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu /** 1831c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * Getter for visible width. This function will get called during animation as 1841c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * well. 18570576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * 1861c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu * @return The visible width of this item 1871c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu */ 1881c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu public int getVisibleWidth() { 1891c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu return mVisibleWidth; 1901c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 1911c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu 19270576b611fddc929abbfb466fa44c396a3a793dbDoris Liu /** 19370576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * Draw the view based on the drawing mode. Clip the canvas if necessary. 19470576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * 19570576b611fddc929abbfb466fa44c396a3a793dbDoris Liu * @param canvas The Canvas to which the View is rendered. 19670576b611fddc929abbfb466fa44c396a3a793dbDoris Liu */ 1971c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu @Override 1981c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu public void draw(Canvas canvas) { 1998676e7802fb40f64a3b465c9b5e1a0a1ada9f699Doris Liu float transX = 0f; 2008676e7802fb40f64a3b465c9b5e1a0a1ada9f699Doris Liu // If the given width is less than the icon width, we need to translate icon 2018676e7802fb40f64a3b465c9b5e1a0a1ada9f699Doris Liu if (mVisibleWidth < mMinVisibleWidth + mIcon.getLeft()) { 2028676e7802fb40f64a3b465c9b5e1a0a1ada9f699Doris Liu transX = mMinVisibleWidth + mIcon.getLeft() - mVisibleWidth; 2038676e7802fb40f64a3b465c9b5e1a0a1ada9f699Doris Liu } 2048676e7802fb40f64a3b465c9b5e1a0a1ada9f699Doris Liu canvas.save(); 2058676e7802fb40f64a3b465c9b5e1a0a1ada9f699Doris Liu canvas.translate(-transX, 0); 2061c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu super.draw(canvas); 2078676e7802fb40f64a3b465c9b5e1a0a1ada9f699Doris Liu canvas.restore(); 208213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu } 209213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu 210213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu /** 211213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * Sets the color that will be used in the drawable for highlight state. 212213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * 213213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * @param highlightColor color for the highlight state 214213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu */ 215213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu public void setHighlightColor(int highlightColor) { 216213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu mIcon.setHighlightColor(highlightColor); 217213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu } 218213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu 219213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu /** 2200496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague * @return highlightColor color for the highlight state 2210496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague */ 2220496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague public int getHighlightColor() { 2230496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague return mIcon.getHighlightColor(); 2240496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague } 2250496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague 2260496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague /** 227213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * Gets the maximum visible width of the mode icon. The mode item will be 228213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * full shown when the mode icon has max visible width. 229213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu */ 230213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu public int getMaxVisibleWidth() { 231213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu return mIcon.getLeft() + mMinVisibleWidth; 232213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu } 233213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu 234213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu /** 235213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * Gets the position of the icon center relative to the window. 236213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * 237213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu * @param loc integer array of size 2, to hold the position x and y 238213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu */ 239213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu public void getIconCenterLocationInWindow(int[] loc) { 240213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu mIcon.getLocationInWindow(loc); 241213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu loc[0] += mMinVisibleWidth / 2; 242213a4a086b54904cee543adf60b16fc1a61efe38Doris Liu loc[1] += mMinVisibleWidth / 2; 2431c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu } 2446ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu 2456ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu /** 2466ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu * Sets the mode id of the current item. 2476ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu * 2486ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu * @param modeId id of the mode represented by current item. 2496ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu */ 2506ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu public void setModeId(int modeId) { 2516ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu mModeId = modeId; 2526ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu } 2536ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu 2546ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu /** 2556ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu * Gets the mode id of the current item. 2566ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu */ 2576ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu public int getModeId() { 2586ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu return mModeId; 2596ababe9379ecee4056a415085e28e7eb5e1249bfDoris Liu } 26006e0826c3ae8579bd301040607701e0065aa6848Doris Liu 26106e0826c3ae8579bd301040607701e0065aa6848Doris Liu /** 2620496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague * @return The {@link ModeIconView} attached to this item. 26306e0826c3ae8579bd301040607701e0065aa6848Doris Liu */ 2640496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague public ModeIconView getIcon() { 2650496fcaa51f88f6c753975473b971941e4090cfaSpike Sprague return mIcon; 26606e0826c3ae8579bd301040607701e0065aa6848Doris Liu } 26769cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu 26869cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu /** 26969cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu * Sets the alpha on the mode text. 27069cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu */ 27169cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu public void setTextAlpha(float alpha) { 27269cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu mText.setAlpha(alpha); 27369cb84076c2f290ee2cd782ab668a661c9d5386eDoris Liu } 2741c94b7d0fa0143230d04b9f14c2ff93c6886d6ccDoris Liu} 275