Move the launch activity button to the toolbar

Test: Manual
Change-Id: I81155492b39d6c72b0976a738a90ed00226bc1e8
This commit is contained in:
Liam Clark
2018-11-27 10:54:27 -08:00
parent b2579ca8d4
commit 64a9fe4304
8 changed files with 112 additions and 157 deletions

View File

@@ -1,7 +1,26 @@
/*
* Copyright (C) 2019 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.example.android.intentplayground;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
@@ -17,17 +36,22 @@ import com.example.android.intentplayground.IntentBuilderView.OnLaunchCallback;
public class LaunchFragment extends Fragment {
private IntentBuilderView mIntentBuilderView;
private BaseActivityViewModel mViewModel;
private OnLaunchCallback mOnLaunchCallback;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
mIntentBuilderView = new IntentBuilderView(getContext(), Mode.LAUNCH);
setOnLaunchCallBack();
FragmentActivity activity = getActivity();
if (activity instanceof OnLaunchCallback) {
mOnLaunchCallback = (OnLaunchCallback) activity;
}
setHasOptionsMenu(true);
return mIntentBuilderView;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
mViewModel = (new ViewModelProvider(getActivity(),
@@ -40,10 +64,19 @@ public class LaunchFragment extends Fragment {
mViewModel.actOnFab(BaseActivityViewModel.FabAction.Hide);
}
private void setOnLaunchCallBack() {
FragmentActivity activity = this.getActivity();
if (activity instanceof OnLaunchCallback) {
mIntentBuilderView.setOnLaunchCallback((OnLaunchCallback) activity);
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.launch_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.app_bar_launch && mOnLaunchCallback != null) {
mOnLaunchCallback.launchActivity(mIntentBuilderView.currentIntent());
}
return super.onOptionsItemSelected(item);
}
}