| /* |
| * Copyright (C) 2015 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.android.tv.settings.device.storage; |
| |
| import android.os.Bundle; |
| import android.os.storage.DiskInfo; |
| |
| import androidx.annotation.NonNull; |
| import androidx.leanback.app.GuidedStepSupportFragment; |
| import androidx.leanback.widget.GuidanceStylist; |
| import androidx.leanback.widget.GuidedAction; |
| |
| import com.android.tv.settings.R; |
| |
| import java.util.List; |
| |
| public class FormatAsPrivateStepFragment extends GuidedStepSupportFragment { |
| |
| private static final int ACTION_ID_FORMAT = 1; |
| // private static final int ACTION_ID_LEARN_MORE = 2; |
| |
| public interface Callback { |
| void onRequestFormatAsPrivate(String diskId); |
| void onCancelFormatDialog(); |
| } |
| |
| public static FormatAsPrivateStepFragment newInstance(String diskId) { |
| final FormatAsPrivateStepFragment fragment = new FormatAsPrivateStepFragment(); |
| final Bundle b = new Bundle(1); |
| b.putString(DiskInfo.EXTRA_DISK_ID, diskId); |
| fragment.setArguments(b); |
| return fragment; |
| } |
| |
| @Override |
| public @NonNull GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) { |
| return new GuidanceStylist.Guidance( |
| getString(R.string.storage_wizard_format_as_private_title), |
| getString(R.string.storage_wizard_format_as_private_description), "", |
| getActivity().getDrawable(R.drawable.ic_warning_132dp)); |
| } |
| |
| @Override |
| public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) { |
| actions.add(new GuidedAction.Builder(getContext()) |
| .clickAction(GuidedAction.ACTION_ID_CANCEL) |
| .build()); |
| actions.add(new GuidedAction.Builder(getContext()) |
| .id(ACTION_ID_FORMAT) |
| .title(getString(R.string.storage_wizard_format_action)) |
| .build()); |
| // TODO: enable this when we have something useful to link to |
| /* actions.add(new GuidedAction.Builder() |
| .id(ACTION_ID_LEARN_MORE) |
| .title(getString(R.string.learn_more_action)) |
| .build()); */ |
| } |
| |
| @Override |
| public void onGuidedActionClicked(GuidedAction action) { |
| final long id = action.getId(); |
| |
| if (id == GuidedAction.ACTION_ID_CANCEL) { |
| final Callback callback = (Callback) getActivity(); |
| callback.onCancelFormatDialog(); |
| } else if (id == ACTION_ID_FORMAT) { |
| final Callback callback = (Callback) getActivity(); |
| callback.onRequestFormatAsPrivate(getArguments().getString(DiskInfo.EXTRA_DISK_ID)); |
| } /* else if (id == ACTION_ID_LEARN_MORE) { |
| // todo |
| } */ |
| } |
| } |