• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.car.Car;
21 import android.content.Intent;
22 import android.graphics.Rect;
23 import android.os.Bundle;
24 import android.util.Log;
25 import android.widget.ImageView;
26 import android.widget.RelativeLayout;
27 
28 /**
29  * Fake navigation activity used while no other application is providing turn-by-turn driving
30  * directions.
31  */
32 public class FakeFreeNavigationActivity extends Activity {
33     private final static String TAG = FakeFreeNavigationActivity.class.getSimpleName();
34 
35     private ImageView mUnobscuredArea;
36 
37     @Override
onCreate(Bundle savedInstanceState)38     public void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40         Log.i(TAG, "onCreate");
41         setContentView(R.layout.activity_fake_free_navigation);
42         mUnobscuredArea = findViewById(R.id.unobscuredArea);
43 
44         handleIntent(getIntent());
45     }
46 
47     @Override
onNewIntent(Intent intent)48     protected void onNewIntent(Intent intent) {
49         super.onNewIntent(intent);
50         handleIntent(intent);
51     }
52 
handleIntent(Intent intent)53     private void handleIntent(Intent intent) {
54         if (intent == null) {
55             Log.w(TAG, "Received a null intent");
56             return;
57         }
58         Bundle bundle = intent.getBundleExtra(Car.CAR_EXTRA_CLUSTER_ACTIVITY_STATE);
59         if (bundle == null) {
60             Log.w(TAG, "Received an intent without " + Car.CAR_EXTRA_CLUSTER_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 }