1 /* 2 * Copyright 2021 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 com.android.launcher3.taskbar; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.View; 22 import android.widget.RelativeLayout; 23 24 import com.android.launcher3.views.ActivityContext; 25 26 public class ImeBarView extends RelativeLayout { 27 28 private ButtonProvider mButtonProvider; 29 private View mImeView; 30 ImeBarView(Context context)31 public ImeBarView(Context context) { 32 this(context, null); 33 } 34 ImeBarView(Context context, AttributeSet attrs)35 public ImeBarView(Context context, AttributeSet attrs) { 36 this(context, attrs, 0); 37 } 38 ImeBarView(Context context, AttributeSet attrs, int defStyleAttr)39 public ImeBarView(Context context, AttributeSet attrs, int defStyleAttr) { 40 super(context, attrs, defStyleAttr); 41 } 42 init(ButtonProvider buttonProvider)43 public void init(ButtonProvider buttonProvider) { 44 mButtonProvider = buttonProvider; 45 46 ActivityContext context = getActivityContext(); 47 RelativeLayout.LayoutParams imeParams = new RelativeLayout.LayoutParams( 48 context.getDeviceProfile().iconSizePx, 49 context.getDeviceProfile().iconSizePx 50 ); 51 RelativeLayout.LayoutParams downParams = new RelativeLayout.LayoutParams(imeParams); 52 53 imeParams.addRule(ALIGN_PARENT_END); 54 imeParams.setMarginEnd(context.getDeviceProfile().iconSizePx); 55 downParams.setMarginStart(context.getDeviceProfile().iconSizePx); 56 downParams.addRule(ALIGN_PARENT_START); 57 58 // Down Arrow 59 View downView = mButtonProvider.getDown(); 60 downView.setLayoutParams(downParams); 61 downView.setRotation(-90); 62 addView(downView); 63 64 // IME switcher button 65 mImeView = mButtonProvider.getImeSwitcher(); 66 mImeView.setLayoutParams(imeParams); 67 addView(mImeView); 68 } 69 setImeSwitcherVisibility(boolean show)70 public void setImeSwitcherVisibility(boolean show) { 71 mImeView.setVisibility(show ? VISIBLE : GONE); 72 } 73 getActivityContext()74 private <T extends Context & ActivityContext> T getActivityContext() { 75 return ActivityContext.lookupContext(getContext()); 76 } 77 } 78