Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2016 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 com.android.tv.dvr.ui;
     18 
     19 import android.app.Activity;
     20 import android.os.Bundle;
     21 import android.support.v17.leanback.app.GuidedStepFragment;
     22 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
     23 import android.support.v17.leanback.widget.GuidedAction;
     24 import android.text.TextUtils;
     25 
     26 import com.android.tv.R;
     27 import com.android.tv.common.SoftPreconditions;
     28 
     29 import java.util.List;
     30 
     31 public class DvrMissingStorageErrorFragment extends DvrGuidedStepFragment {
     32     private static final int ACTION_CANCEL = 1;
     33     private static final int ACTION_FORGET_STORAGE = 2;
     34     private String mInputId;
     35 
     36     @Override
     37     public void onCreate(Bundle savedInstanceState) {
     38         Bundle args = getArguments();
     39         if (args != null) {
     40             mInputId = args.getString(DvrHalfSizedDialogFragment.KEY_INPUT_ID);
     41         }
     42         SoftPreconditions.checkArgument(!TextUtils.isEmpty(mInputId));
     43         super.onCreate(savedInstanceState);
     44     }
     45 
     46     @Override
     47     public Guidance onCreateGuidance(Bundle savedInstanceState) {
     48         String title = getResources().getString(R.string.dvr_error_missing_storage_title);
     49         String description = getResources().getString(
     50                 R.string.dvr_error_missing_storage_description);
     51         return new Guidance(title, description, null, null);
     52     }
     53 
     54     @Override
     55     public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
     56         Activity activity = getActivity();
     57         actions.add(new GuidedAction.Builder(activity)
     58                 .id(ACTION_CANCEL)
     59                 .title(getResources().getString(R.string.dvr_action_error_cancel))
     60                 .build());
     61         actions.add(new GuidedAction.Builder(activity)
     62                 .id(ACTION_FORGET_STORAGE)
     63                 .title(getResources().getString(R.string.dvr_action_error_forget_storage))
     64                 .build());
     65     }
     66 
     67     @Override
     68     public void onGuidedActionClicked(GuidedAction action) {
     69         if (action.getId() == ACTION_FORGET_STORAGE) {
     70             DvrForgetStorageErrorFragment fragment = new DvrForgetStorageErrorFragment();
     71             Bundle args = new Bundle();
     72             args.putString(DvrHalfSizedDialogFragment.KEY_INPUT_ID, mInputId);
     73             fragment.setArguments(args);
     74             GuidedStepFragment.add(getFragmentManager(), fragment, R.id.halfsized_dialog_host);
     75             return;
     76         }
     77         dismissDialog();
     78     }
     79 }