1 /* 2 * Copyright 2017 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.example.androidx.car; 18 19 import android.content.Context; 20 import android.os.Bundle; 21 import android.view.View; 22 import android.widget.ImageButton; 23 24 import androidx.annotation.DrawableRes; 25 import androidx.car.widget.ActionBar; 26 import androidx.fragment.app.FragmentActivity; 27 28 /** 29 * Demo activity for ActionBar 30 */ 31 public class ActionBarActivity extends FragmentActivity { 32 private ActionBar mActionPanel; 33 34 @Override 35 protected void onCreate(Bundle savedInstanceState) { 36 super.onCreate(savedInstanceState); 37 setContentView(R.layout.activity_action_bar); 38 mActionPanel = findViewById(R.id.action_panel); 39 mActionPanel.setView(createButton(this, R.drawable.ic_play), 40 ActionBar.SLOT_MAIN); 41 ImageButton skpPrevious = createButton(this, R.drawable.ic_skip_next); 42 skpPrevious.setVisibility(View.GONE); 43 mActionPanel.setView(skpPrevious, ActionBar.SLOT_LEFT); 44 mActionPanel.setView(createButton(this, R.drawable.ic_skip_next), 45 ActionBar.SLOT_RIGHT); 46 mActionPanel.setViews(new ImageButton[]{ 47 createButton(this, R.drawable.ic_queue_music), 48 createButton(this, R.drawable.ic_overflow), 49 createButton(this, R.drawable.ic_overflow), 50 createButton(this, R.drawable.ic_overflow), 51 createButton(this, R.drawable.ic_overflow), 52 createButton(this, R.drawable.ic_overflow) 53 }); 54 } 55 56 private ImageButton createButton(Context context, @DrawableRes int iconResId) { 57 ImageButton button = new ImageButton(context, null, 58 androidx.car.R.style.Widget_Car_Button_ActionBar); 59 button.setImageDrawable(context.getDrawable(iconResId)); 60 return button; 61 } 62 } 63