blob: 1ef544972cc0dbab592394032aae8d17136891f7 [file] [log] [blame]
Pavel Maltsev905968c2017-07-16 19:48:57 -07001/*
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
17package com.google.android.car.kitchensink.cluster;
18
19import android.app.Activity;
Dean Harding8bc07732018-08-24 16:04:53 -070020import android.car.Car;
Pavel Maltsev905968c2017-07-16 19:48:57 -070021import android.car.cluster.ClusterActivityState;
Roberto Perez7b494e32018-12-19 18:19:28 -080022import android.content.Intent;
Pavel Maltsev905968c2017-07-16 19:48:57 -070023import android.graphics.Rect;
24import android.os.Bundle;
Pavel Maltsev905968c2017-07-16 19:48:57 -070025import android.util.Log;
26import android.widget.ImageView;
27import android.widget.RelativeLayout;
28
29import com.google.android.car.kitchensink.R;
30
31/**
32 * Fake navigation activity for instrument cluster.
33 */
Roberto Perez7b494e32018-12-19 18:19:28 -080034public class FakeClusterNavigationActivity extends Activity {
Pavel Maltsev905968c2017-07-16 19:48:57 -070035 private final static String TAG = FakeClusterNavigationActivity.class.getSimpleName();
36
Pavel Maltsev905968c2017-07-16 19:48:57 -070037 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 Perez7b494e32018-12-19 18:19:28 -080046 handleIntent(getIntent());
Pavel Maltsev905968c2017-07-16 19:48:57 -070047 }
48
Pavel Maltsev905968c2017-07-16 19:48:57 -070049 @Override
Roberto Perez7b494e32018-12-19 18:19:28 -080050 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 Maltsev905968c2017-07-16 19:48:57 -070067
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 Maltsev905968c2017-07-16 19:48:57 -070074}