Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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.google.android.car.kitchensink.cluster; |
| 18 | |
| 19 | import android.app.Activity; |
Dean Harding | 8bc0773 | 2018-08-24 16:04:53 -0700 | [diff] [blame] | 20 | import android.car.Car; |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 21 | import android.car.cluster.ClusterActivityState; |
Roberto Perez | 7b494e3 | 2018-12-19 18:19:28 -0800 | [diff] [blame^] | 22 | import android.content.Intent; |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 23 | import android.graphics.Rect; |
| 24 | import android.os.Bundle; |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | import android.widget.ImageView; |
| 27 | import android.widget.RelativeLayout; |
| 28 | |
| 29 | import com.google.android.car.kitchensink.R; |
| 30 | |
| 31 | /** |
| 32 | * Fake navigation activity for instrument cluster. |
| 33 | */ |
Roberto Perez | 7b494e3 | 2018-12-19 18:19:28 -0800 | [diff] [blame^] | 34 | public class FakeClusterNavigationActivity extends Activity { |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 35 | private final static String TAG = FakeClusterNavigationActivity.class.getSimpleName(); |
| 36 | |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 37 | private ImageView mUnobscuredArea; |
| 38 | |
| 39 | @Override |
| 40 | public void onCreate(Bundle savedInstanceState) { |
| 41 | super.onCreate(savedInstanceState); |
| 42 | Log.i(TAG, "onCreate"); |
| 43 | setContentView(R.layout.fake_cluster_navigation_activity); |
| 44 | mUnobscuredArea = findViewById(R.id.unobscuredArea); |
| 45 | |
Roberto Perez | 7b494e3 | 2018-12-19 18:19:28 -0800 | [diff] [blame^] | 46 | handleIntent(getIntent()); |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 49 | @Override |
Roberto Perez | 7b494e3 | 2018-12-19 18:19:28 -0800 | [diff] [blame^] | 50 | protected void onNewIntent(Intent intent) { |
| 51 | super.onNewIntent(intent); |
| 52 | handleIntent(intent); |
| 53 | } |
| 54 | |
| 55 | private void handleIntent(Intent intent) { |
| 56 | if (intent == null) { |
| 57 | Log.w(TAG, "Received a null intent"); |
| 58 | return; |
| 59 | } |
| 60 | Bundle bundle = intent.getBundleExtra(Car.CAR_EXTRA_CLUSTER_ACTIVITY_STATE); |
| 61 | if (bundle == null) { |
| 62 | Log.w(TAG, "Received an intent without " + Car.CAR_EXTRA_CLUSTER_ACTIVITY_STATE); |
| 63 | return; |
| 64 | } |
| 65 | ClusterActivityState state = ClusterActivityState.fromBundle(bundle); |
| 66 | Log.i(TAG, "handling intent with state: " + state); |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 67 | |
| 68 | Rect unobscured = state.getUnobscuredBounds(); |
| 69 | RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( |
| 70 | unobscured.width(), unobscured.height()); |
| 71 | lp.setMargins(unobscured.left, unobscured.top, 0, 0); |
| 72 | mUnobscuredArea.setLayoutParams(lp); |
| 73 | } |
Pavel Maltsev | 905968c | 2017-07-16 19:48:57 -0700 | [diff] [blame] | 74 | } |