Simplify Zen mode voice activity.

Zen mode voice activity now only sets the notification mode to alarms mode
or off. A duration may be specified if it was in the original intent.

Change-Id: Ica472ca9c6dcbce473832f4f922baf225df4951b
Bug: 21024455
This commit is contained in:
Barnaby James
2015-05-10 16:24:05 -07:00
parent 69a03f7517
commit 0474b723e1
10 changed files with 31 additions and 634 deletions

View File

@@ -1,74 +0,0 @@
/*
* 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.settings.utils;
import android.app.VoiceInteractor.PickOptionRequest.Option;
import android.os.Bundle;
import android.text.TextUtils;
/**
* Model for a single item that can be selected by a {@link VoiceSelectionFragment}.
* Each item consists of a visual label and several alternative synonyms for the item
* that can be used to identify the item by voice.
*/
public class VoiceSelection {
final CharSequence mLabel;
final CharSequence[] mSynonyms;
/**
* Created a new selectable item with a visual label and a set of synonyms.
*/
public VoiceSelection(CharSequence label, CharSequence synonyms) {
mLabel = label;
mSynonyms = TextUtils.split(synonyms.toString(), ",");
}
/**
* Created a new selectable item with a visual label and no synonyms.
*/
public VoiceSelection(CharSequence label) {
mLabel = label;
mSynonyms = null;
}
public CharSequence getLabel() {
return mLabel;
}
public CharSequence[] getSynonyms() {
return mSynonyms;
}
Option toOption(int index) {
Option result = new Option(mLabel);
Bundle extras = new Bundle();
extras.putInt("index", index);
result.setExtras(extras);
for (CharSequence synonym : mSynonyms) {
result.addSynonym(synonym);
}
return result;
}
/**
* Listener interface for when an item is selected.
*/
public interface OnItemSelectedListener {
abstract void onItemSelected(int position, VoiceSelection selection);
};
}

View File

@@ -1,63 +0,0 @@
/*
* 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.settings.utils;
import android.content.Context;
import android.widget.ArrayAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.app.Activity;
import com.android.settings.R;
import java.util.List;
import android.util.Log;
/**
* Array adapter for selecting an item by voice interaction. Each row includes a visual
* indication of the 1-indexed position of the item so that a user can easily say
* "number 4" to select it.
*/
public class VoiceSelectionAdapter extends ArrayAdapter<VoiceSelection> {
public VoiceSelectionAdapter(Context context, int resource, List<VoiceSelection> objects) {
super(context, resource, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
VoiceSelection item = getItem(position);
View row = convertView;
if (row == null) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
row = inflater.inflate(R.layout.voice_item_row, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.voice_item_label);
if (label != null) {
label.setText(item.getLabel());
}
TextView positionLabel = (TextView) row.findViewById(R.id.voice_item_position);
if (positionLabel != null) {
positionLabel.setText(Integer.toString(position + 1));
}
return row;
}
};

View File

@@ -1,133 +0,0 @@
/*
* 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.settings.utils;
import android.app.ListFragment;
import android.app.VoiceInteractor;
import android.app.VoiceInteractor.PickOptionRequest;
import android.app.VoiceInteractor.PickOptionRequest.Option;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import java.util.List;
/**
* An Activity fragment that presents a set of options as a visual list and also allows
* items to be selected by the users voice.
*/
public class VoiceSelectionFragment extends ListFragment {
private static final String EXTRA_SELECTION_PROMPT = "selection_prompt";
private CharSequence mPrompt = null;
private VoiceInteractor.Request mRequest = null;
private VoiceInteractor mVoiceInteractor = null;
private VoiceSelection.OnItemSelectedListener mOnItemSelectedListener = null;
/**
* No-args ctor required for fragment.
*/
public VoiceSelectionFragment() {}
@Override
public void onCreate(Bundle args) {
super.onCreate(args);
mPrompt = getArguments().getCharSequence(EXTRA_SELECTION_PROMPT);
}
/**
* Set the prompt spoken when the fragment is presented.
*/
static public Bundle createArguments(CharSequence prompt) {
Bundle args = new Bundle();
args.putCharSequence(EXTRA_SELECTION_PROMPT, prompt);
return args;
}
private VoiceSelection getSelectionAt(int position) {
return ((ArrayAdapter<VoiceSelection>) getListAdapter()).getItem(position);
}
@Override
public void onStart() {
super.onStart();
final int numItems = getListAdapter().getCount();
if (numItems <= 0) {
return;
}
Option[] options = new Option[numItems];
for (int idx = 0; idx < numItems; idx++) {
options[idx] = getSelectionAt(idx).toOption(idx);
}
mRequest = new PickOptionRequest(mPrompt, options, null) {
@Override
public void onPickOptionResult(boolean isComplete, Option[] options, Bundle args) {
if (!isComplete || options == null) {
return;
}
if (options.length == 1 && mOnItemSelectedListener != null) {
int idx = options[0].getExtras().getInt("index", -1);
mOnItemSelectedListener.onItemSelected(idx, getSelectionAt(idx));
} else {
onCancel();
}
}
};
mVoiceInteractor = getActivity().getVoiceInteractor();
if (mVoiceInteractor != null) {
mVoiceInteractor.submitRequest(mRequest);
}
}
@Override
public void onDetach() {
super.onDetach();
mVoiceInteractor = null;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
if (mRequest != null) {
mRequest.cancel();
mRequest = null;
}
if (mOnItemSelectedListener != null) {
mOnItemSelectedListener.onItemSelected(position, getSelectionAt(position));
}
}
/**
* Sets the selection handler for an item either by voice or by touch.
*/
public void setOnItemSelectedHandler(VoiceSelection.OnItemSelectedListener listener) {
mOnItemSelectedListener = listener;
}
/**
* Called when the user cancels the interaction. The default implementation is to
* finish the activity.
*/
public void onCancel() {
getActivity().finish();
}
};

View File

@@ -16,8 +16,6 @@
package com.android.settings.utils;
import com.android.settings.R;
import android.app.Activity;
import android.app.Fragment;
import android.app.VoiceInteractor;
@@ -27,7 +25,6 @@ import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;
/**
@@ -67,45 +64,17 @@ abstract public class VoiceSettingsActivity extends Activity {
* not null, then it will be read to the user.
*/
protected void notifySuccess(CharSequence prompt) {
if (prompt != null) {
Toast.makeText(this, prompt, Toast.LENGTH_LONG).show();
}
if (getVoiceInteractor() != null) {
getVoiceInteractor().submitRequest(new CompleteVoiceRequest(prompt, null));
}
}
protected void setHeader(String label) {
TextView header = (TextView) findViewById(R.id.voice_fragment_header);
if (header != null) {
if (label != null) {
header.setText(label);
header.setVisibility(View.VISIBLE);
} else {
header.setVisibility(View.GONE);
}
}
}
/**
* Indicates when the setting could not be changed.
*/
protected void notifyFailure(CharSequence prompt) {
if (prompt != null) {
Toast.makeText(this, prompt, Toast.LENGTH_LONG).show();
}
if (getVoiceInteractor() != null) {
getVoiceInteractor().submitRequest(new AbortVoiceRequest(prompt, null));
}
}
protected void showFragment(Fragment fragment, String tag) {
getFragmentManager()
.beginTransaction()
.replace(R.id.voice_fragment_root, fragment, tag)
.commit();
}
}