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;
20 import android.car.Car;
21 import android.car.cluster.ClusterActivityState;
22 import android.content.Intent;
23 import android.graphics.Rect;
24 import android.os.Bundle;
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  */
34 public class FakeClusterNavigationActivity extends Activity {
35     private final static String TAG = FakeClusterNavigationActivity.class.getSimpleName();
36 
37     private ImageView mUnobscuredArea;
38 
39     @Override
onCreate(Bundle savedInstanceState)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 
46         handleIntent(getIntent());
47     }
48 
49     @Override
onNewIntent(Intent intent)50     protected void onNewIntent(Intent intent) {
51         super.onNewIntent(intent);
52         handleIntent(intent);
53     }
54 
handleIntent(Intent intent)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);
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     }
74 }