Home | History | Annotate | Download | only in storage
      1 /*
      2  * Copyright (C) 2015 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.settings.device.storage;
     18 
     19 import android.os.Bundle;
     20 import android.os.storage.DiskInfo;
     21 import android.support.annotation.NonNull;
     22 import android.support.v17.leanback.app.GuidedStepFragment;
     23 import android.support.v17.leanback.widget.GuidanceStylist;
     24 import android.support.v17.leanback.widget.GuidedAction;
     25 
     26 import com.android.tv.settings.R;
     27 
     28 import java.util.List;
     29 
     30 public class FormatAsPrivateStepFragment extends GuidedStepFragment {
     31 
     32     private static final int ACTION_ID_FORMAT = 1;
     33 //    private static final int ACTION_ID_LEARN_MORE = 2;
     34 
     35     public interface Callback {
     36         void onRequestFormatAsPrivate(String diskId);
     37         void onCancelFormatDialog();
     38     }
     39 
     40     public static FormatAsPrivateStepFragment newInstance(String diskId) {
     41         final FormatAsPrivateStepFragment fragment = new FormatAsPrivateStepFragment();
     42         final Bundle b = new Bundle(1);
     43         b.putString(DiskInfo.EXTRA_DISK_ID, diskId);
     44         fragment.setArguments(b);
     45         return fragment;
     46     }
     47 
     48     @Override
     49     public @NonNull GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
     50         return new GuidanceStylist.Guidance(
     51                 getString(R.string.storage_wizard_format_as_private_title),
     52                 getString(R.string.storage_wizard_format_as_private_description), "",
     53                 getActivity().getDrawable(R.drawable.ic_warning_132dp));
     54     }
     55 
     56     @Override
     57     public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
     58         actions.add(new GuidedAction.Builder(getContext())
     59                 .clickAction(GuidedAction.ACTION_ID_CANCEL)
     60                 .build());
     61         actions.add(new GuidedAction.Builder(getContext())
     62                 .id(ACTION_ID_FORMAT)
     63                 .title(getString(R.string.storage_wizard_format_action))
     64                 .build());
     65         // TODO: enable this when we have something useful to link to
     66         /* actions.add(new GuidedAction.Builder()
     67                 .id(ACTION_ID_LEARN_MORE)
     68                 .title(getString(R.string.learn_more_action))
     69                 .build()); */
     70     }
     71 
     72     @Override
     73     public void onGuidedActionClicked(GuidedAction action) {
     74         final long id = action.getId();
     75 
     76         if (id == GuidedAction.ACTION_ID_CANCEL) {
     77             final Callback callback = (Callback) getActivity();
     78             callback.onCancelFormatDialog();
     79         } else if (id == ACTION_ID_FORMAT) {
     80             final Callback callback = (Callback) getActivity();
     81             callback.onRequestFormatAsPrivate(getArguments().getString(DiskInfo.EXTRA_DISK_ID));
     82         } /* else if (id == ACTION_ID_LEARN_MORE) {
     83             // todo
     84         } */
     85     }
     86 }
     87