2012-09-08 03:03:23 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-09-08 03:03:23 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-09-08 03:03:23 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms.preferences;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Parcelable;
|
|
|
|
import android.preference.ListPreference;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.SeekBar;
|
2012-09-08 03:03:23 +00:00
|
|
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
2012-09-08 03:03:23 +00:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
|
|
|
import org.thoughtcrime.securesms.R;
|
2013-07-11 21:58:40 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2014-03-01 00:32:00 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Dialogs;
|
2011-12-20 18:20:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List preference for LED blink pattern notification.
|
2012-09-08 03:03:23 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class LedBlinkPatternListPreference extends ListPreference implements OnSeekBarChangeListener {
|
2012-09-08 03:03:23 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private Context context;
|
|
|
|
private SeekBar seekBarOn;
|
|
|
|
private SeekBar seekBarOff;
|
|
|
|
|
|
|
|
private TextView seekBarOnLabel;
|
|
|
|
private TextView seekBarOffLabel;
|
2012-09-08 03:03:23 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private boolean dialogInProgress;
|
|
|
|
|
|
|
|
public LedBlinkPatternListPreference(Context context) {
|
|
|
|
super(context);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LedBlinkPatternListPreference(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-09-08 03:03:23 +00:00
|
|
|
protected void onDialogClosed(boolean positiveResult) {
|
2011-12-20 18:20:44 +00:00
|
|
|
super.onDialogClosed(positiveResult);
|
2012-09-08 03:03:23 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
if (positiveResult) {
|
2013-07-11 21:58:40 +00:00
|
|
|
String blinkPattern = TextSecurePreferences.getNotificationLedPattern(context);
|
2011-12-20 18:20:44 +00:00
|
|
|
if (blinkPattern.equals("custom")) showDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeSeekBarValues() {
|
2013-07-11 21:58:40 +00:00
|
|
|
String patternString = TextSecurePreferences.getNotificationLedPatternCustom(context);
|
2011-12-20 18:20:44 +00:00
|
|
|
String[] patternArray = patternString.split(",");
|
|
|
|
seekBarOn.setProgress(Integer.parseInt(patternArray[0]));
|
|
|
|
seekBarOff.setProgress(Integer.parseInt(patternArray[1]));
|
|
|
|
}
|
2012-09-08 03:03:23 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void initializeDialog(View view) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
2014-03-01 00:32:00 +00:00
|
|
|
builder.setIcon(Dialogs.resolveIcon(context, R.attr.dialog_info_icon));
|
2014-02-25 10:38:31 +00:00
|
|
|
builder.setTitle(R.string.preferences__pref_led_blink_custom_pattern_title);
|
2011-12-20 18:20:44 +00:00
|
|
|
builder.setView(view);
|
|
|
|
builder.setOnCancelListener(new CustomDialogCancelListener());
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, new CustomDialogCancelListener());
|
|
|
|
builder.setPositiveButton(android.R.string.ok, new CustomDialogClickListener());
|
2014-03-19 23:42:27 +00:00
|
|
|
builder.setInverseBackgroundForced(true);
|
2011-12-20 18:20:44 +00:00
|
|
|
builder.show();
|
|
|
|
}
|
2012-09-08 03:03:23 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void showDialog() {
|
|
|
|
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
View view = inflater.inflate(R.layout.led_pattern_dialog, null);
|
|
|
|
|
|
|
|
this.seekBarOn = (SeekBar)view.findViewById(R.id.SeekBarOn);
|
|
|
|
this.seekBarOff = (SeekBar)view.findViewById(R.id.SeekBarOff);
|
|
|
|
this.seekBarOnLabel = (TextView)view.findViewById(R.id.SeekBarOnMsLabel);
|
|
|
|
this.seekBarOffLabel = (TextView)view.findViewById(R.id.SeekBarOffMsLabel);
|
|
|
|
|
|
|
|
this.seekBarOn.setOnSeekBarChangeListener(this);
|
|
|
|
this.seekBarOff.setOnSeekBarChangeListener(this);
|
|
|
|
|
|
|
|
initializeSeekBarValues();
|
|
|
|
initializeDialog(view);
|
2014-08-29 13:33:19 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
dialogInProgress = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-09-08 03:03:23 +00:00
|
|
|
protected void onRestoreInstanceState(Parcelable state) {
|
2011-12-20 18:20:44 +00:00
|
|
|
super.onRestoreInstanceState(state);
|
|
|
|
if (dialogInProgress) {
|
|
|
|
showDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-09-08 03:03:23 +00:00
|
|
|
protected View onCreateDialogView() {
|
2011-12-20 18:20:44 +00:00
|
|
|
dialogInProgress = false;
|
|
|
|
return super.onCreateDialogView();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onProgressChanged(SeekBar seekbar, int progress, boolean fromTouch) {
|
|
|
|
if (seekbar.equals(seekBarOn)) {
|
|
|
|
seekBarOnLabel.setText(Integer.toString(progress));
|
|
|
|
} else if (seekbar.equals(seekBarOff)) {
|
|
|
|
seekBarOffLabel.setText(Integer.toString(progress));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private class CustomDialogCancelListener implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2012-09-08 03:03:23 +00:00
|
|
|
dialogInProgress = false;
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onCancel(DialogInterface dialog) {
|
|
|
|
dialogInProgress = false;
|
2012-09-08 03:03:23 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-09-08 03:03:23 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class CustomDialogClickListener implements DialogInterface.OnClickListener {
|
|
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
String pattern = seekBarOnLabel.getText() + "," + seekBarOffLabel.getText();
|
|
|
|
dialogInProgress = false;
|
2012-09-08 03:03:23 +00:00
|
|
|
|
2013-07-11 21:58:40 +00:00
|
|
|
TextSecurePreferences.setNotificationLedPatternCustom(context, pattern);
|
2014-02-25 10:38:31 +00:00
|
|
|
Toast.makeText(context, R.string.preferences__pref_led_blink_custom_pattern_set, Toast.LENGTH_LONG).show();
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-09-08 03:03:23 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-09-08 03:03:23 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|