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.content.ActivityNotFoundException;
     21 import android.content.Intent;
     22 import android.os.Bundle;
     23 import android.provider.Settings;
     24 import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
     25 import android.support.v17.leanback.widget.GuidedAction;
     26 import android.util.Log;
     27 import com.android.tv.R;
     28 import com.android.tv.dvr.ui.browse.DvrDetailsActivity;
     29 import java.util.List;
     30 
     31 public class DvrMissingStorageErrorFragment extends DvrGuidedStepFragment {
     32     private static final String TAG = "DvrMissingStorageError";
     33 
     34     private static final int ACTION_OK = 1;
     35     private static final int ACTION_OPEN_STORAGE_SETTINGS = 2;
     36 
     37     @Override
     38     public void onCreate(Bundle savedInstanceState) {
     39         super.onCreate(savedInstanceState);
     40     }
     41 
     42     @Override
     43     public Guidance onCreateGuidance(Bundle savedInstanceState) {
     44         String title = getResources().getString(R.string.dvr_error_missing_storage_title);
     45         String description =
     46                 getResources().getString(R.string.dvr_error_missing_storage_description);
     47         return new Guidance(title, description, null, null);
     48     }
     49 
     50     @Override
     51     public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
     52         Activity activity = getActivity();
     53         actions.add(
     54                 new GuidedAction.Builder(activity)
     55                         .id(ACTION_OK)
     56                         .title(android.R.string.ok)
     57                         .build());
     58         actions.add(
     59                 new GuidedAction.Builder(activity)
     60                         .id(ACTION_OPEN_STORAGE_SETTINGS)
     61                         .title(getResources().getString(R.string.dvr_action_error_storage_settings))
     62                         .build());
     63     }
     64 
     65     @Override
     66     public void onTrackedGuidedActionClicked(GuidedAction action) {
     67         Activity activity = getActivity();
     68         if (activity instanceof DvrDetailsActivity) {
     69             activity.finish();
     70         } else {
     71             dismissDialog();
     72         }
     73         if (action.getId() != ACTION_OPEN_STORAGE_SETTINGS) {
     74             return;
     75         }
     76         final Intent intent = new Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
     77         try {
     78             getContext().startActivity(intent);
     79         } catch (ActivityNotFoundException e) {
     80             Log.e(TAG, "Can't start internal storage settings activity", e);
     81         }
     82     }
     83 
     84     @Override
     85     public String getTrackerPrefix() {
     86         return "DvrMissingStorageErrorFragment";
     87     }
     88 
     89     @Override
     90     public String getTrackerLabelForGuidedAction(GuidedAction action) {
     91         long actionId = action.getId();
     92         if (actionId == ACTION_OPEN_STORAGE_SETTINGS) {
     93             return "open-storage-settings";
     94         } else {
     95             return super.getTrackerLabelForGuidedAction(action);
     96         }
     97     }
     98 }
     99