diff options
author | Agatha Man <agathaman@google.com> | 2020-04-15 22:11:36 -0700 |
---|---|---|
committer | Agatha Man <agathaman@google.com> | 2020-04-20 20:50:34 -0700 |
commit | 156d741f398ea4cb54c67855c30c08833239551e (patch) | |
tree | 053e9b605acf0b84ac4530ceb88cc05d76f3cbb7 /RotaryPlayground/src/com/android/car | |
parent | 2be92f41098cbce9a3a1412e1c2eb5fc84c23d5e (diff) | |
download | tests-156d741f398ea4cb54c67855c30c08833239551e.tar.gz |
Add rotary reference app
This CL contains the base structure for the app. Rotary demo does not
work yet because FocusArea is not available yet.
Bug: 153470636
Test: make and install
Change-Id: I22ff278fff9ee280cf7f7e040b574ada1b79689a
Diffstat (limited to 'RotaryPlayground/src/com/android/car')
3 files changed, 164 insertions, 0 deletions
diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryActivity.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryActivity.java new file mode 100644 index 0000000..1b44ac6 --- /dev/null +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryActivity.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.car.rotaryplayground; + +import android.os.Bundle; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import android.text.Html; +import android.text.Spanned; +import android.util.Log; +import android.view.View; +import android.widget.Toast; + +/** + * The main activity for Rotary Playground + * + * This activity starts the menu fragment and handles event calls (e.g. android:onClick) from + * elements in fragments. + */ +public class RotaryActivity extends FragmentActivity { + + private static final String TAG = "RotaryActivity"; + private static final String MESSAGE = "Hello there!"; + + private Fragment mMenuFragment = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.rotary_activity); + showMenuFragment(); + } + + /** Event handler for buttons in res/layout/rotary_cards.xml */ + public void onRotaryCardsButtonClick(View v) { + showToast(MESSAGE); + } + + private void showMenuFragment() { + if (mMenuFragment == null) { + mMenuFragment = new RotaryMenu(); + } + getSupportFragmentManager().beginTransaction() + .replace(R.id.rotary_menu, mMenuFragment) + .commit(); + } + + private void showToast(String message) { + Log.d(TAG, "showToast -> " + message); + Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); + } +}
\ No newline at end of file diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java new file mode 100644 index 0000000..28f34a1 --- /dev/null +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.car.rotaryplayground; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +/** Fragment to demo a layout with cards that are FocusArea containers. */ +public class RotaryCards extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.rotary_cards, container, false); + return view; + } +} diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java new file mode 100644 index 0000000..272317d --- /dev/null +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.car.rotaryplayground; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +/** + * Fragment for the menu. + * + * On focus of a menu item, the associated fragment will start in the R.id.rotary_content container. + */ +public class RotaryMenu extends Fragment { + + private Fragment mRotaryCards = null; + + private Button mCardExamplesButton; + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.rotary_menu, container, false); + + mCardExamplesButton = view.findViewById(R.id.cards_example); + mCardExamplesButton.setOnFocusChangeListener((v, hasFocus) -> showRotaryCards(hasFocus)); + mCardExamplesButton.setOnClickListener(v -> showRotaryCards(/* hasFocus= */ true)); + + return view; + } + + private void showRotaryCards(boolean hasFocus) { + if (!hasFocus) { + return; // do nothing if no focus. + } + if (mRotaryCards == null) { + mRotaryCards = new RotaryCards(); + } + showContent(mRotaryCards); + } + + private void showContent(Fragment fragment) { + getFragmentManager().beginTransaction() + .replace(R.id.rotary_content, fragment) + .commit(); + } +} |