mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-26 00:58:51 +00:00
Initial Project Import
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
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;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
|
||||
/**
|
||||
* List preference for LED blink pattern notification.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
|
||||
public class LedBlinkPatternListPreference extends ListPreference implements OnSeekBarChangeListener {
|
||||
|
||||
private Context context;
|
||||
private SeekBar seekBarOn;
|
||||
private SeekBar seekBarOff;
|
||||
|
||||
private TextView seekBarOnLabel;
|
||||
private TextView seekBarOffLabel;
|
||||
|
||||
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
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
String blinkPattern = PreferenceManager.getDefaultSharedPreferences(context).getString(ApplicationPreferencesActivity.LED_BLINK_PREF, "500,2000");
|
||||
if (blinkPattern.equals("custom")) showDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeSeekBarValues() {
|
||||
String patternString = PreferenceManager.getDefaultSharedPreferences(context).getString(ApplicationPreferencesActivity.LED_BLINK_PREF_CUSTOM, "500,2000");
|
||||
String[] patternArray = patternString.split(",");
|
||||
seekBarOn.setProgress(Integer.parseInt(patternArray[0]));
|
||||
seekBarOff.setProgress(Integer.parseInt(patternArray[1]));
|
||||
}
|
||||
|
||||
private void initializeDialog(View view) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setIcon(android.R.drawable.ic_dialog_info);
|
||||
builder.setTitle("Set Custom LED Blink Pattern");
|
||||
builder.setView(view);
|
||||
builder.setOnCancelListener(new CustomDialogCancelListener());
|
||||
builder.setNegativeButton(android.R.string.cancel, new CustomDialogCancelListener());
|
||||
builder.setPositiveButton(android.R.string.ok, new CustomDialogClickListener());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
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);
|
||||
dialogInProgress = true;
|
||||
|
||||
dialogInProgress = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
super.onRestoreInstanceState(state);
|
||||
if (dialogInProgress) {
|
||||
showDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
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) {
|
||||
dialogInProgress = false;
|
||||
}
|
||||
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
dialogInProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
private class CustomDialogClickListener implements DialogInterface.OnClickListener {
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String pattern = seekBarOnLabel.getText() + "," + seekBarOffLabel.getText();
|
||||
dialogInProgress = false;
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
preferences.edit().putString(ApplicationPreferencesActivity.LED_BLINK_PREF_CUSTOM, pattern).commit();
|
||||
Toast.makeText(context, "Custom LED blink pattern set!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Dialog preference for encryption passphrase timeout.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
|
||||
public class PassphraseTimeoutPreference extends DialogPreference {
|
||||
|
||||
private Spinner scaleSpinner;
|
||||
private SeekBar seekBar;
|
||||
private TextView timeoutText;
|
||||
|
||||
public PassphraseTimeoutPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.setDialogLayoutResource(R.layout.passphrase_timeout_dialog);
|
||||
this.setPositiveButtonText("Ok");
|
||||
this.setNegativeButtonText("Cancel");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
View dialog = super.onCreateDialogView();
|
||||
this.scaleSpinner = (Spinner)dialog.findViewById(R.id.scale);
|
||||
this.seekBar = (SeekBar)dialog.findViewById(R.id.seekbar);
|
||||
this.timeoutText = (TextView)dialog.findViewById(R.id.timeout_text);
|
||||
|
||||
initializeDefaults();
|
||||
initializeListeners();
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
int interval;
|
||||
|
||||
if (scaleSpinner.getSelectedItemPosition() == 0) {
|
||||
interval = Math.max(seekBar.getProgress(), 1);
|
||||
} else {
|
||||
interval = Math.max(seekBar.getProgress(), 1) * 60;
|
||||
}
|
||||
|
||||
this.getSharedPreferences().edit().putInt(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_INTERVAL_PREF, interval).commit();
|
||||
}
|
||||
|
||||
super.onClick(dialog, which);
|
||||
}
|
||||
|
||||
private void initializeDefaults() {
|
||||
int timeout = this.getSharedPreferences().getInt(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_INTERVAL_PREF, 60 * 5);
|
||||
|
||||
if (timeout > 60) {
|
||||
scaleSpinner.setSelection(1);
|
||||
seekBar.setMax(24);
|
||||
seekBar.setProgress(timeout / 60);
|
||||
timeoutText.setText((timeout / 60) + "");
|
||||
} else {
|
||||
scaleSpinner.setSelection(0);
|
||||
seekBar.setMax(60);
|
||||
seekBar.setProgress(timeout);
|
||||
timeoutText.setText(timeout + "");
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeListeners() {
|
||||
this.seekBar.setOnSeekBarChangeListener(new SeekbarChangedListener());
|
||||
this.scaleSpinner.setOnItemSelectedListener(new ScaleSelectedListener());
|
||||
}
|
||||
|
||||
private class ScaleSelectedListener implements AdapterView.OnItemSelectedListener {
|
||||
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long selected) {
|
||||
if (selected == 0) {
|
||||
seekBar.setMax(60);
|
||||
} else {
|
||||
seekBar.setMax(24);
|
||||
}
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView<?> arg0) {
|
||||
}
|
||||
}
|
||||
|
||||
private class SeekbarChangedListener implements SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (progress < 1)
|
||||
progress = 1;
|
||||
|
||||
timeoutText.setText(progress +"");
|
||||
}
|
||||
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user