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 android.car.cluster;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.graphics.Rect;
22 import android.os.Bundle;
23 import android.util.Log;
24 import android.widget.ImageView;
25 import android.widget.RelativeLayout;
26 
27 /**
28  * Fake navigation activity used while no other application is providing turn-by-turn driving
29  * directions.
30  */
31 public class FakeFreeNavigationActivity extends Activity {
32     private final static String TAG = FakeFreeNavigationActivity.class.getSimpleName();
33 
34     private ImageView mUnobscuredArea;
35 
36     @Override
onCreate(Bundle savedInstanceState)37     public void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39         Log.i(TAG, "onCreate");
40         setContentView(R.layout.activity_fake_free_navigation);
41         mUnobscuredArea = findViewById(R.id.unobscuredArea);
42 
43         handleIntent(getIntent());
44     }
45 
46     @Override
onNewIntent(Intent intent)47     protected void onNewIntent(Intent intent) {
48         super.onNewIntent(intent);
49         handleIntent(intent);
50     }
51 
handleIntent(Intent intent)52     private void handleIntent(Intent intent) {
53         if (intent == null) {
54             Log.w(TAG, "Received a null intent");
55             return;
56         }
57         Bundle bundle = intent.getBundleExtra(CarInstrumentClusterManager.KEY_EXTRA_ACTIVITY_STATE);
58         if (bundle == null) {
59             Log.w(TAG, "Received an intent without " + CarInstrumentClusterManager
60                     .KEY_EXTRA_ACTIVITY_STATE);
61             return;
62         }
63         ClusterActivityState state = ClusterActivityState.fromBundle(bundle);
64         Log.i(TAG, "handling intent with state: " + state);
65 
66         Rect unobscured = state.getUnobscuredBounds();
67         RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
68                 unobscured.width(), unobscured.height());
69         lp.setMargins(unobscured.left, unobscured.top, 0, 0);
70         mUnobscuredArea.setLayoutParams(lp);
71     }
72 }