Revision 61b66389
| app/AndroidManifest.xml | ||
|---|---|---|
| 55 | 55 |
<activity |
| 56 | 56 |
android:name=".Settings" |
| 57 | 57 |
android:label="@string/settings" |
| 58 |
android:screenOrientation="portrait" |
|
| 58 |
android:screenOrientation="portrait" |
|
| 59 |
android:parentActivityName="info.guardianproject.notepadbot.NoteCipher" |
|
| 59 | 60 |
android:configChanges="orientation|keyboardHidden" > |
| 60 |
<meta-data |
|
| 61 |
android:name="android.support.PARENT_ACTIVITY" |
|
| 62 |
android:value=".NoteCipher" /> |
|
| 63 | 61 |
</activity> |
| 64 | 62 |
|
| 65 | 63 |
<service |
| app/res/values/strings.xml | ||
|---|---|---|
| 57 | 57 |
<string name="change_timeout_prompt">After how many minutes of inactivity should NoteCipher lock itself?</string> |
| 58 | 58 |
<string name="use_lines_in_notes">Use lines in notes</string> |
| 59 | 59 |
<string name="use_lines_in_notes_summ">If enabled, empty lines will be displayed on all notes to resemble a notepad</string> |
| 60 |
<string name="vibrate_when_unlocked">Vibrate when unlocked</string> |
|
| 61 |
<string name="vibrate_when_unlocked_summ">If enabled, the device will vibrate every time NoteCipher is unlocked with a passphrase</string> |
|
| 60 | 62 |
|
| 61 | 63 |
</resources> |
| app/res/xml/settings.xml | ||
|---|---|---|
| 10 | 10 |
android:title="@string/use_lines_in_notes" |
| 11 | 11 |
android:summary="@string/use_lines_in_notes_summ" |
| 12 | 12 |
android:defaultValue="@bool/notecipher_uselines_default" /> |
| 13 |
<CheckBoxPreference |
|
| 14 |
android:key="cacheword_vibrate" |
|
| 15 |
android:title="@string/vibrate_when_unlocked" |
|
| 16 |
android:summary="@string/vibrate_when_unlocked_summ" |
|
| 17 |
android:defaultValue="@bool/cacheword_vibrate_default" /> |
|
| 13 | 18 |
</PreferenceCategory> |
| 14 | 19 |
</PreferenceScreen> |
| app/src/info/guardianproject/notepadbot/NoteCipher.java | ||
|---|---|---|
| 49 | 49 |
import info.guardianproject.cacheword.CacheWordActivityHandler; |
| 50 | 50 |
import info.guardianproject.cacheword.ICacheWordSubscriber; |
| 51 | 51 |
|
| 52 |
import net.simonvt.numberpicker.NumberPicker; |
|
| 53 | 52 |
import net.sqlcipher.database.SQLiteDatabase; |
| 54 | 53 |
|
| 55 | 54 |
import java.io.FileNotFoundException; |
| ... | ... | |
| 57 | 56 |
import java.io.InputStream; |
| 58 | 57 |
|
| 59 | 58 |
public class NoteCipher extends SherlockFragmentActivity implements ICacheWordSubscriber {
|
| 59 |
|
|
| 60 | 60 |
private static final int ACTIVITY_CREATE = 0; |
| 61 | 61 |
private static final int ACTIVITY_EDIT = 1; |
| 62 | 62 |
|
| ... | ... | |
| 89 | 89 |
if (getIntent() != null) {
|
| 90 | 90 |
if (getIntent().hasExtra(Intent.EXTRA_STREAM)) {
|
| 91 | 91 |
dataStream = (Uri) getIntent().getExtras().get(Intent.EXTRA_STREAM); |
| 92 |
} else |
|
| 92 |
} else {
|
|
| 93 | 93 |
dataStream = getIntent().getData(); |
| 94 |
|
|
| 94 |
} |
|
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 | 97 |
SQLiteDatabase.loadLibs(this); |
| ... | ... | |
| 236 | 236 |
mCacheWord.manuallyLock(); |
| 237 | 237 |
return true; |
| 238 | 238 |
case SETTINGS_ID: |
| 239 |
//changeTimeoutPrompt(); |
|
| 240 | 239 |
startActivity(new Intent(this, Settings.class)); |
| 241 | 240 |
return true; |
| 242 | 241 |
} |
| ... | ... | |
| 478 | 477 |
b.show(); |
| 479 | 478 |
} |
| 480 | 479 |
|
| 481 |
void changeTimeoutPrompt() {
|
|
| 482 |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
|
| 483 |
builder.setTitle(R.string.change_timeout_prompt_title); |
|
| 484 |
builder.setMessage(R.string.change_timeout_prompt); |
|
| 485 |
final NumberPicker input = new NumberPicker(this); |
|
| 486 |
input.setMinValue(1); |
|
| 487 |
input.setMaxValue(60); |
|
| 488 |
input.setValue( mCacheWord.getTimeoutMinutes() ); |
|
| 489 |
builder.setView(input); |
|
| 490 |
|
|
| 491 |
builder.setPositiveButton("OK",
|
|
| 492 |
new DialogInterface.OnClickListener() {
|
|
| 493 |
@Override |
|
| 494 |
public void onClick(DialogInterface dialog, int which) {
|
|
| 495 |
int timeout = input.getValue(); |
|
| 496 |
mCacheWord.setTimeoutMinutes(timeout); |
|
| 497 |
dialog.dismiss(); |
|
| 498 |
} |
|
| 499 |
}); |
|
| 500 |
builder.setNegativeButton("Cancel",
|
|
| 501 |
new DialogInterface.OnClickListener() {
|
|
| 502 |
@Override |
|
| 503 |
public void onClick(DialogInterface dialog, int which) {
|
|
| 504 |
dialog.cancel(); |
|
| 505 |
} |
|
| 506 |
}); |
|
| 507 |
|
|
| 508 |
builder.show(); |
|
| 509 |
} |
|
| 510 |
|
|
| 511 | 480 |
void showLockScreen() {
|
| 512 | 481 |
Intent intent = new Intent(this, LockScreenActivity.class); |
| 513 | 482 |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| app/src/info/guardianproject/notepadbot/Settings.java | ||
|---|---|---|
| 1 | 1 |
package info.guardianproject.notepadbot; |
| 2 | 2 |
|
| 3 | 3 |
|
| 4 |
import net.simonvt.numberpicker.NumberPicker; |
|
| 5 |
import info.guardianproject.cacheword.CacheWordActivityHandler; |
|
| 4 | 6 |
import info.guardianproject.cacheword.Constants; |
| 7 |
import info.guardianproject.cacheword.ICacheWordSubscriber; |
|
| 5 | 8 |
|
| 6 | 9 |
import android.annotation.SuppressLint; |
| 10 |
import android.app.AlertDialog; |
|
| 7 | 11 |
import android.content.Context; |
| 12 |
import android.content.DialogInterface; |
|
| 13 |
import android.content.Intent; |
|
| 8 | 14 |
import android.os.Build; |
| 9 | 15 |
import android.os.Bundle; |
| 10 | 16 |
import android.preference.Preference; |
| 17 |
import android.preference.Preference.OnPreferenceChangeListener; |
|
| 11 | 18 |
import android.preference.PreferenceFragment; |
| 12 | 19 |
import android.preference.PreferenceManager; |
| 13 | 20 |
import android.support.v4.app.NavUtils; |
| 21 |
import android.util.Log; |
|
| 14 | 22 |
|
| 15 | 23 |
import com.actionbarsherlock.app.SherlockPreferenceActivity; |
| 16 | 24 |
import com.actionbarsherlock.view.MenuItem; |
| 17 | 25 |
|
| 18 | 26 |
@SuppressLint("NewApi")
|
| 19 | 27 |
@SuppressWarnings("deprecation")
|
| 20 |
public class Settings extends SherlockPreferenceActivity {
|
|
| 28 |
public class Settings extends SherlockPreferenceActivity implements ICacheWordSubscriber {
|
|
| 21 | 29 |
|
| 22 | 30 |
public static final String LANG_SEL_KEY = "langSelected"; |
| 23 | 31 |
|
| 32 |
private CacheWordActivityHandler mCacheWord; |
|
| 33 |
|
|
| 24 | 34 |
@Override |
| 25 | 35 |
public void onCreate(Bundle savedInstanceState) {
|
| 26 | 36 |
super.onCreate(savedInstanceState); |
| 27 | 37 |
getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
| 28 |
|
|
| 38 |
|
|
| 39 |
mCacheWord = new CacheWordActivityHandler(this, ((App)getApplication()).getCWSettings()); |
|
| 40 |
|
|
| 29 | 41 |
// If in android 3+ use a preference fragment which is the new recommended way |
| 30 | 42 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
| 31 | 43 |
getFragmentManager().beginTransaction() |
| ... | ... | |
| 36 | 48 |
addPreferencesFromResource(R.xml.settings); |
| 37 | 49 |
findPreference(Constants.SHARED_PREFS_TIMEOUT) |
| 38 | 50 |
.setOnPreferenceClickListener(changeLockTimeoutListener); |
| 51 |
findPreference(Constants.SHARED_PREFS_VIBRATE) |
|
| 52 |
.setOnPreferenceChangeListener(vibrateChangeListener); |
|
| 39 | 53 |
} |
| 40 | 54 |
}) |
| 41 | 55 |
.commit(); |
| 42 | 56 |
} else {
|
| 43 | 57 |
// Otherwise load the preferences.xml in the Activity like in previous android versions |
| 44 | 58 |
addPreferencesFromResource(R.xml.settings); |
| 45 |
findPreference(Constants.SHARED_PREFS_TIMEOUT).setOnPreferenceClickListener(changeLockTimeoutListener); |
|
| 59 |
findPreference(Constants.SHARED_PREFS_TIMEOUT) |
|
| 60 |
.setOnPreferenceClickListener(changeLockTimeoutListener); |
|
| 61 |
findPreference(Constants.SHARED_PREFS_VIBRATE) |
|
| 62 |
.setOnPreferenceChangeListener(vibrateChangeListener); |
|
| 46 | 63 |
} |
| 47 | 64 |
} |
| 48 | 65 |
|
| 66 |
|
|
| 67 |
|
|
| 49 | 68 |
@Override |
| 50 | 69 |
public boolean onOptionsItemSelected(MenuItem item) {
|
| 51 | 70 |
switch (item.getItemId()) {
|
| ... | ... | |
| 75 | 94 |
new Preference.OnPreferenceClickListener() {
|
| 76 | 95 |
@Override |
| 77 | 96 |
public boolean onPreferenceClick(Preference pref) {
|
| 78 |
|
|
| 97 |
changeTimeoutPrompt(); |
|
| 79 | 98 |
return true; |
| 80 | 99 |
} |
| 81 | 100 |
}; |
| 82 | 101 |
|
| 102 |
private Preference.OnPreferenceChangeListener vibrateChangeListener = |
|
| 103 |
new OnPreferenceChangeListener(){
|
|
| 104 |
@Override |
|
| 105 |
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
|
| 106 |
// save option internally in cacheword as well |
|
| 107 |
mCacheWord.setVibrateSetting((Boolean) newValue); |
|
| 108 |
return true; |
|
| 109 |
} |
|
| 110 |
}; |
|
| 111 |
|
|
| 83 | 112 |
public static final boolean getNoteLinesOption(Context context) {
|
| 84 | 113 |
boolean defValue = context.getResources().getBoolean(R.bool.notecipher_uselines_default); |
| 85 | 114 |
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(NConstants.SHARED_PREFS_NOTELINES, defValue); |
| 86 | 115 |
} |
| 116 |
|
|
| 117 |
private void changeTimeoutPrompt() {
|
|
| 118 |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
|
| 119 |
builder.setTitle(R.string.change_timeout_prompt_title); |
|
| 120 |
builder.setMessage(R.string.change_timeout_prompt); |
|
| 121 |
final NumberPicker input = new NumberPicker(this); |
|
| 122 |
input.setMinValue(1); |
|
| 123 |
input.setMaxValue(60); |
|
| 124 |
input.setValue( mCacheWord.getTimeoutMinutes() ); |
|
| 125 |
builder.setView(input); |
|
| 126 |
|
|
| 127 |
builder.setPositiveButton("OK",
|
|
| 128 |
new DialogInterface.OnClickListener() {
|
|
| 129 |
@Override |
|
| 130 |
public void onClick(DialogInterface dialog, int which) {
|
|
| 131 |
int timeout = input.getValue(); |
|
| 132 |
mCacheWord.setTimeoutMinutes(timeout); |
|
| 133 |
dialog.dismiss(); |
|
| 134 |
} |
|
| 135 |
}); |
|
| 136 |
builder.setNegativeButton("Cancel",
|
|
| 137 |
new DialogInterface.OnClickListener() {
|
|
| 138 |
@Override |
|
| 139 |
public void onClick(DialogInterface dialog, int which) {
|
|
| 140 |
dialog.cancel(); |
|
| 141 |
} |
|
| 142 |
}); |
|
| 143 |
|
|
| 144 |
builder.show(); |
|
| 145 |
} |
|
| 146 |
|
|
| 147 |
@Override |
|
| 148 |
public void onCacheWordUninitialized() {
|
|
| 149 |
Log.d(NConstants.TAG, "onCacheWordUninitialized"); |
|
| 150 |
System.gc(); |
|
| 151 |
showLockScreen(); |
|
| 152 |
} |
|
| 153 |
|
|
| 154 |
@Override |
|
| 155 |
public void onCacheWordLocked() {
|
|
| 156 |
Log.d(NConstants.TAG, "onCacheWordLocked"); |
|
| 157 |
System.gc(); |
|
| 158 |
showLockScreen(); |
|
| 159 |
} |
|
| 160 |
|
|
| 161 |
@Override |
|
| 162 |
public void onCacheWordOpened() {
|
|
| 163 |
Log.d(NConstants.TAG, "onCacheWordOpened"); |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
@Override |
|
| 167 |
protected void onPause() {
|
|
| 168 |
super.onPause(); |
|
| 169 |
mCacheWord.onPause(); |
|
| 170 |
} |
|
| 171 |
|
|
| 172 |
@Override |
|
| 173 |
protected void onResume() {
|
|
| 174 |
super.onResume(); |
|
| 175 |
mCacheWord.onResume(); |
|
| 176 |
} |
|
| 177 |
|
|
| 178 |
void showLockScreen() {
|
|
| 179 |
Intent intent = new Intent(this, LockScreenActivity.class); |
|
| 180 |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); |
|
| 181 |
intent.putExtra("originalIntent", getIntent());
|
|
| 182 |
startActivity(intent); |
|
| 183 |
finish(); |
|
| 184 |
} |
|
| 87 | 185 |
} |
Also available in: Unified diff