Skip to content

Commit 212cc8c

Browse files
author
James
committed
Merge branch 'release/2.0.6'
Fixed problem with importing rdfs that don't have a default profile, and profiles that weren't visible to the user was used. Changed how the UI worked a tad to hopefully help out on usage
2 parents efd0723 + b6dd2f5 commit 212cc8c

File tree

12 files changed

+144
-44
lines changed

12 files changed

+144
-44
lines changed

passwordmaker/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ dependencies {
107107
compile fileTree(dir: 'libs', include: ['*.jar'])
108108
// You must install or update the Support Repository through the SDK manager to use this dependency.
109109
compile 'com.intellij:annotations:12.0@jar'
110-
compile 'org.passwordmaker:passwordmaker-je-lib:0.9.6'
110+
compile 'org.passwordmaker:passwordmaker-je-lib:0.9.8'
111111
compile 'com.madgag.spongycastle:core:1.50.0.0'
112112
compile 'com.madgag.spongycastle:prov:1.50.0.0'
113113
androidTestCompile 'junit:junit:4.8.1'

passwordmaker/src/main/java/org/passwordmaker/android/AccountListActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void onFocusChange(View v, boolean hasFocus) {
172172
* indicating that the item with the given ID was selected.
173173
*/
174174
@Override
175-
public void onItemSelected(Account account) {
175+
public void onItemView(Account account) {
176176
if (mTwoPane) {
177177
// In two-pane mode, show the detail view in this activity by
178178
// adding or replacing the detail fragment using a
@@ -201,7 +201,7 @@ public void onFolderSelected(Account account) {
201201
}
202202

203203
@Override
204-
public void onItemLongSelected(Account account) {
204+
public void onItemManuallySelected(Account account) {
205205
PwmApplication.getInstance().getAccountManager().selectAccountById(account.getId());
206206
NavUtils.navigateUpFromSameTask(this);
207207
Toast.makeText(this, "Manually selected '" + account.getName() + "'", Toast.LENGTH_SHORT).show();

passwordmaker/src/main/java/org/passwordmaker/android/AccountListFragment.java

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class AccountListFragment extends ListFragment {
4848
private Callbacks mCallbacks = sDummyCallbacks;
4949

5050
private ActionMode mActionMode;
51+
private Menu mActionMenu;
5152

5253
private boolean autoActivateMode = false;
5354

@@ -68,9 +69,9 @@ public interface Callbacks {
6869
/**
6970
* Callback for when an item has been selected.
7071
*/
71-
public void onItemSelected(Account account);
72+
public void onItemView(Account account);
7273
public void onFolderSelected(Account account);
73-
public void onItemLongSelected(Account account);
74+
public void onItemManuallySelected(Account account);
7475
}
7576

7677
/**
@@ -79,7 +80,7 @@ public interface Callbacks {
7980
*/
8081
private final static Callbacks sDummyCallbacks = new Callbacks() {
8182
@Override
82-
public void onItemSelected(Account account) {
83+
public void onItemView(Account account) {
8384
}
8485

8586
@Override
@@ -88,7 +89,7 @@ public void onFolderSelected(Account account) {
8889
}
8990

9091
@Override
91-
public void onItemLongSelected(Account account) {
92+
public void onItemManuallySelected(Account account) {
9293

9394
}
9495
};
@@ -123,23 +124,6 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
123124
&& savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
124125
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
125126
}
126-
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
127-
@Override
128-
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
129-
if (mActionMode != null) {
130-
return false;
131-
}
132-
133-
if ( ! autoActivateMode ) {
134-
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
135-
}
136-
getListView().setItemChecked(position, true);
137-
138-
// Start the CAB using the ActionMode.Callback defined above
139-
mActionMode = getActivity().startActionMode(mActionModeCallback);
140-
return true;
141-
}
142-
});
143127
}
144128

145129
private void loadIncomingAccount() {
@@ -175,7 +159,7 @@ public void onAttach(Activity activity) {
175159
if ( loadedAccount != null ) {
176160
Account acc = loadedAccount;
177161
loadedAccount = null;
178-
mCallbacks.onItemSelected(acc);
162+
mCallbacks.onItemView(acc);
179163
}
180164

181165
}
@@ -197,7 +181,23 @@ public void onListItemClick(ListView listView, View view, int position, long id)
197181
if ( selected.hasChildren() ) {
198182
goIntoFolder(selected);
199183
} else {
200-
mCallbacks.onItemSelected(selected);
184+
if (mActionMode != null ) {
185+
if (mActionMenu != null) {
186+
if (getCheckedAccount().isDefault()) {
187+
mActionMenu.findItem(R.id.menu_item_delete).setVisible(false);
188+
} else {
189+
mActionMenu.findItem(R.id.menu_item_delete).setVisible(true);
190+
}
191+
}
192+
return;
193+
}
194+
if ( ! autoActivateMode ) {
195+
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
196+
}
197+
getListView().setItemChecked(position, true);
198+
199+
// Start the CAB using the ActionMode.Callback defined above
200+
mActionMode = getActivity().startActionMode(mActionModeCallback);
201201
}
202202
}
203203

@@ -266,7 +266,7 @@ public void createNewAccount(String accountName) {
266266
account.getPatterns().clear();
267267
accountManager.getPwmProfiles().addAccount(accountStack.getCurrentAccount(), account);
268268
getCurrentAccountList().notifyDataSetChanged();
269-
mCallbacks.onItemSelected(account);
269+
mCallbacks.onItemView(account);
270270
} catch (Exception e) {
271271
throw new RuntimeException(e);
272272
}
@@ -398,6 +398,7 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
398398
} else {
399399
menu.findItem(R.id.menu_item_delete).setVisible(true);
400400
}
401+
mActionMenu = menu;
401402
return true;
402403
}
403404

@@ -413,13 +414,17 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
413414
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
414415
switch (item.getItemId()) {
415416
case R.id.menu_item_select:
416-
mCallbacks.onItemLongSelected(getCheckedAccount());
417+
mCallbacks.onItemManuallySelected(getCheckedAccount());
417418
mode.finish(); // Action picked, so close the CAB
418419
return true;
419420
case R.id.menu_item_delete:
420421
deleteAccount(getCheckedAccount());
421422
mode.finish();
422423
return true;
424+
case R.id.menu_item_view:
425+
mCallbacks.onItemView(getCheckedAccount());
426+
mode.finish();
427+
return true;
423428
default:
424429
return false;
425430
}
@@ -429,13 +434,14 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
429434
@Override
430435
public void onDestroyActionMode(ActionMode mode) {
431436
mActionMode = null;
437+
mActionMenu = null;
432438
clearAllChecked();
433439
}
440+
};
434441

435442

436-
public Account getCheckedAccount() {
437-
return getCurrentAccountList().getItem(getListView().getCheckedItemPosition());
438-
}
439-
};
440443

444+
public Account getCheckedAccount() {
445+
return getCurrentAccountList().getItem(getListView().getCheckedItemPosition());
446+
}
441447
}

passwordmaker/src/main/java/org/passwordmaker/android/MainActivity.java

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
import android.view.MenuItem;
1717
import android.view.View;
1818
import android.widget.*;
19+
import com.google.common.base.Function;
20+
import com.google.common.base.Predicate;
21+
import com.google.common.collect.FluentIterable;
22+
import com.google.common.collect.ImmutableList;
23+
import com.google.common.collect.Iterables;
1924
import org.daveware.passwordmaker.*;
2025
import org.passwordmaker.android.adapters.SubstringArrayAdapter;
2126

22-
import java.util.ArrayList;
23-
import java.util.Calendar;
24-
import java.util.HashSet;
25-
import java.util.Set;
27+
import java.util.*;
2628

2729
import static java.lang.String.format;
2830

@@ -41,13 +43,16 @@ public class MainActivity extends ActionBarActivity implements AccountManagerLis
4143
private static final int UPDATE_VER_CODE = 0xccaabb;
4244
private static final int VER_CODE_DELAY = 600;
4345
private ImageButton btnClearSelectedProfile;
46+
private Spinner spinAccount;
47+
private List<Account> accounts = new ArrayList<Account>();
4448

4549
private ArrayAdapter<String> favoritesAdapter;
4650
private final ArrayList<String> favoritesList = new ArrayList<String>();
4751

4852
@Override
4953
protected void onCreate(Bundle savedInstanceState) {
5054
super.onCreate(savedInstanceState);
55+
5156
accountManager = PwmApplication.getInstance().getAccountManager();
5257
setContentView(R.layout.activity_main);
5358

@@ -69,12 +74,16 @@ protected void onCreate(Bundle savedInstanceState) {
6974
text.addTextChangedListener(createUpdatePasswordKeyListener());
7075
if (text != null)
7176
text.setOnFocusChangeListener(mUpdatePasswordFocusListener);
72-
Button button = (Button) findViewById(R.id.btnCopy);
77+
ImageButton button = (ImageButton) findViewById(R.id.btnCopy);
7378
if (button != null)
7479
button.setOnClickListener(mCopyButtonClick);
7580

7681
btnClearSelectedProfile = (ImageButton)findViewById(R.id.btnClearSelected);
7782
btnClearSelectedProfile.setOnClickListener(mClearProfileButtonClick);
83+
84+
85+
spinAccount = (Spinner)findViewById(R.id.spinProfile);
86+
spinAccount.setOnItemSelectedListener(mSpinAccountOnProfileSelect);
7887
}
7988

8089
@Override
@@ -105,12 +114,42 @@ private void createFavoritesList() {
105114
protected void onResume() {
106115
super.onResume();
107116
loadDefaultValueForFields();
117+
updateProfileDropDown();
108118
showUsernameBasedOnPreference();
109119
showPassStrengthBasedOnPreference();
110120
favoritesAdapter.notifyDataSetChanged();
111121
updateSelectedProfileText();
112122
}
113123

124+
private void updateProfileDropDown() {
125+
accounts = accountManager.getPwmProfiles().getAllAccounts();
126+
List<String> names = ImmutableList.<String>builder().add("Auto-select").addAll(FluentIterable.from(accounts)
127+
.transform(new Function<Account, String>() {
128+
@Override
129+
public String apply(Account input) {
130+
return input.getName();
131+
}
132+
})).build();
133+
spinAccount.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names));
134+
135+
setProfileDropdownBySelectedAccount();
136+
}
137+
138+
private void setProfileDropdownBySelectedAccount() {
139+
final Account selected = PwmApplication.getInstance().getAccountManager().getSelectedProfile();
140+
if ( selected == null ) {
141+
spinAccount.setSelection(0);
142+
} else {
143+
int index = Iterables.indexOf(accounts, new Predicate<Account>() {
144+
@Override
145+
public boolean apply(Account input) {
146+
return selected.getId().equals(input.getId());
147+
}
148+
}) + 1;
149+
spinAccount.setSelection(index);
150+
}
151+
}
152+
114153
@Override
115154
protected void onStop() {
116155
super.onStop();
@@ -280,6 +319,7 @@ protected void updateSelectedProfileText() {
280319

281320
@SuppressWarnings("UnusedDeclaration")
282321
public void setCurrentProfile(String profileId) {
322+
Log.i(LOG_TAG, "scp: " + profileId);
283323
accountManager.selectAccountById(profileId);
284324
}
285325

@@ -389,6 +429,7 @@ private void setInputText(String value) {
389429
public void onSelectedProfileChange(Account newProfile) {
390430
TextView text = (TextView) findViewById(R.id.lblCurrentProfile);
391431
text.setText(newProfile.getName());
432+
updatePassword(false);
392433
}
393434

394435

@@ -495,6 +536,7 @@ public void onClick(View v) {
495536
@SuppressWarnings("deprecation")
496537
public void onClick(View v) {
497538
accountManager.clearSelectedAccount();
539+
setProfileDropdownBySelectedAccount();
498540
updatePassword(true);
499541
Toast.makeText(MainActivity.this, "Cleared manually selected account", Toast.LENGTH_SHORT).show();
500542
}
@@ -512,4 +554,23 @@ public boolean handleMessage(Message msg) {
512554
return true;
513555
}
514556
});
557+
558+
private final AdapterView.OnItemSelectedListener mSpinAccountOnProfileSelect = new AdapterView.OnItemSelectedListener() {
559+
@Override
560+
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
561+
if ( position == 0 ) {
562+
accountManager.clearSelectedAccount();
563+
updatePassword(false);
564+
} else {
565+
Account account = accounts.get(position - 1);
566+
accountManager.selectAccountById(account.getId());
567+
onSelectedProfileChange(account);
568+
}
569+
}
570+
571+
@Override
572+
public void onNothingSelected(AdapterView<?> parent) {
573+
574+
}
575+
};
515576
}
199 Bytes
Loading
161 Bytes
Loading
252 Bytes
Loading
1.25 KB
Loading

passwordmaker/src/main/res/layout/activity_main.xml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
android:visibility="gone"/>
2323

2424
</LinearLayout>
25+
26+
<Spinner
27+
android:layout_height="wrap_content"
28+
android:layout_width="match_parent"
29+
android:id="@+id/spinProfile"
30+
android:entries="@array/HashAlgos"
31+
/>
32+
2533
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
2634
android:textAppearance="?android:attr/textAppearanceSmall"
2735
android:text="@string/Input" android:id="@+id/lblInputText"/>
@@ -62,10 +70,30 @@
6270
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
6371
android:textAppearance="?android:attr/textAppearanceSmall" android:text="@string/Password"
6472
android:id="@+id/lblPassword"/>
73+
<LinearLayout
74+
android:id="@+id/layPassfield"
75+
android:orientation="horizontal"
76+
android:layout_width="match_parent"
77+
android:layout_height="wrap_content">
78+
6579
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
6680
android:id="@+id/txtPassword" android:singleLine="true"
67-
android:inputType="textVisiblePassword"/>
81+
android:inputType="textVisiblePassword"
82+
android:layout_gravity="left"
83+
android:layout_weight="1"
84+
/>
6885

86+
<ImageButton
87+
android:layout_width="wrap_content"
88+
android:layout_height="fill_parent"
89+
android:id="@+id/btnCopy"
90+
android:src="@drawable/ic_menu_copy_holo_light"
91+
android:contentDescription="@string/LblCopy"
92+
android:layout_weight="1"
93+
android:minWidth="82dp"
94+
android:baselineAlignBottom="false"
95+
/>
96+
</LinearLayout>
6997
<LinearLayout
7098
android:id="@+id/layPassStrength"
7199
android:orientation="horizontal"
@@ -89,7 +117,4 @@
89117
/>
90118
</LinearLayout>
91119

92-
<Button android:text="@string/LblCopy" android:layout_height="wrap_content"
93-
android:layout_width="fill_parent" android:id="@+id/btnCopy"/>
94-
95120
</LinearLayout>

passwordmaker/src/main/res/menu/account_list_menu.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
3+
<!-- menu_item_view -->
34

5+
<item android:id="@+id/menu_item_view"
6+
android:icon="@android:drawable/ic_menu_view"
7+
android:showAsAction="ifRoom|withText"
8+
android:title="@string/ViewAccount"
9+
android:titleCondensed="@string/ViewAccountShort" />
410
<item android:id="@+id/menu_item_select"
511
android:icon="@android:drawable/ic_input_get"
612
android:showAsAction="ifRoom|withText"

0 commit comments

Comments
 (0)