• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 package com.android.nearby.halfsheet.fragment;
17 
18 import static com.android.nearby.halfsheet.constants.Constant.TAG;
19 import static com.android.nearby.halfsheet.fragment.HalfSheetModuleFragment.HalfSheetFragmentState.NOT_STARTED;
20 
21 import android.os.Bundle;
22 import android.util.Log;
23 
24 import androidx.annotation.Nullable;
25 import androidx.fragment.app.Fragment;
26 
27 
28 /** Base class for all of the half sheet fragment. */
29 public abstract class HalfSheetModuleFragment extends Fragment {
30 
31     static final int TEXT_ANIMATION_DURATION_MILLISECONDS = 200;
32 
33     HalfSheetFragmentState mFragmentState = NOT_STARTED;
34 
35     @Override
onCreate(@ullable Bundle savedInstanceState)36     public void onCreate(@Nullable Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38     }
39 
40     @Override
onDestroy()41     public void onDestroy() {
42         super.onDestroy();
43     }
44 
45     /** UI states of the half-sheet fragment. */
46     public enum HalfSheetFragmentState {
47         NOT_STARTED, // Initial status
48         FOUND_DEVICE, // When a device is found found from Nearby scan service
49         PAIRING, // When user taps 'Connect' and Fast Pair stars pairing process
50         PAIRED_LAUNCHABLE, // When pair successfully
51         // and we found a launchable companion app installed
52         PAIRED_UNLAUNCHABLE, // When pair successfully
53         // but we cannot find a companion app to launch it
54         FAILED, // When paring was failed
55         FINISHED // When the activity is about to end finished.
56     }
57 
58     /**
59      * Returns the {@link HalfSheetFragmentState} to the parent activity.
60      *
61      * <p>Overrides this method if the fragment's state needs to be preserved in the parent
62      * activity.
63      */
getFragmentState()64     public HalfSheetFragmentState getFragmentState() {
65         return mFragmentState;
66     }
67 
setState(HalfSheetFragmentState state)68     void setState(HalfSheetFragmentState state) {
69         Log.v(TAG, "Settings state from " + mFragmentState + " to " + state);
70         mFragmentState = state;
71     }
72 
73     /**
74      * Populate data to UI widgets according to the latest {@link HalfSheetFragmentState}.
75      */
invalidateState()76     abstract void invalidateState();
77 }
78