Skip to content

Commit

Permalink
Store last used URI and restore it on application start.
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Mar 16, 2012
1 parent 20c9ca4 commit 4a893e8
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/com/uploadedlobster/PwdHash/Constants.java
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* PwdHash, Constants.java
* A password hash implementation for Android.
*
* Copyright (c) 2012 Philipp Wolfer
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the RBrainz project nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Philipp Wolfer <ph.wolfer@googlemail.com>
*/

package com.uploadedlobster.PwdHash;

public final class Constants {

public static final String PREFERENCES_NAME = "com.uploadedlobster.pwdhash.preferences";

public static final String PREFERENCE_SAVED_SITE_ADDRESS = "saved_uri";
}
56 changes: 56 additions & 0 deletions src/com/uploadedlobster/PwdHash/Preferences.java
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* PwdHash, Preferences.java
* A password hash implementation for Android.
*
* Copyright (c) 2012 Philipp Wolfer
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the RBrainz project nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Philipp Wolfer <ph.wolfer@googlemail.com>
*/

package com.uploadedlobster.PwdHash;

import android.content.Context;
import android.content.SharedPreferences;

public class Preferences {
private SharedPreferences mSettings;

public Preferences(Context packageContext) {
mSettings = packageContext.getSharedPreferences(
Constants.PREFERENCES_NAME, Context.MODE_PRIVATE);
}

public String getSavedSiteAddress() {
return mSettings.getString(Constants.PREFERENCE_SAVED_SITE_ADDRESS, "");
}

public void setSavedSiteAddress(String siteAddress) {
SharedPreferences.Editor editor = mSettings.edit();
editor.putString(Constants.PREFERENCE_SAVED_SITE_ADDRESS, siteAddress);
editor.commit();
}
}
19 changes: 19 additions & 0 deletions src/com/uploadedlobster/PwdHash/PwdHashApp.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* *
*/ */
public class PwdHashApp extends Activity { public class PwdHashApp extends Activity {
private Preferences mPreferences;
private EditText mSiteAddress; private EditText mSiteAddress;
private EditText mPassword; private EditText mPassword;
private TextView mHashedPassword; private TextView mHashedPassword;
Expand All @@ -70,11 +71,20 @@ public void onCreate(Bundle savedInstanceState) {
mHashedPassword = (TextView) findViewById(R.id.hashedPassword); mHashedPassword = (TextView) findViewById(R.id.hashedPassword);
mCopyBtn = (Button) findViewById(R.id.copyBtn); mCopyBtn = (Button) findViewById(R.id.copyBtn);


mPreferences = new Preferences(this);

setWindowGeometry(); setWindowGeometry();
restoreSavedState();
handleIntents(); handleIntents();
registerEventListeners(); registerEventListeners();
} }


@Override
protected void onStop() {
super.onStop();
mPreferences.setSavedSiteAddress(mSiteAddress.getText().toString());
}

private void setWindowGeometry() { private void setWindowGeometry() {
Window window = getWindow(); Window window = getWindow();
window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
Expand All @@ -89,6 +99,15 @@ private void setWindowGeometry() {
} }
} }


private void restoreSavedState() {
String savedSiteAddress = mPreferences.getSavedSiteAddress();

if (!savedSiteAddress.equals("")) {
mSiteAddress.setText(savedSiteAddress);
mSiteAddress.selectAll();
}
}

private void handleIntents() { private void handleIntents() {
Intent intent = getIntent(); Intent intent = getIntent();
if (intent.getAction().equals(Intent.ACTION_SEND)) { if (intent.getAction().equals(Intent.ACTION_SEND)) {
Expand Down

0 comments on commit 4a893e8

Please sign in to comment.