26 |
26 |
import android.support.v4.app.ListFragment;
|
27 |
27 |
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
28 |
28 |
import android.support.v4.content.Loader;
|
29 |
|
import android.view.ContextMenu;
|
30 |
|
import android.view.ContextMenu.ContextMenuInfo;
|
|
29 |
import android.support.v7.app.ActionBarActivity;
|
|
30 |
import android.support.v7.view.ActionMode;
|
|
31 |
import android.view.Menu;
|
31 |
32 |
import android.view.MenuInflater;
|
32 |
33 |
import android.view.MenuItem;
|
33 |
34 |
import android.view.View;
|
34 |
35 |
import android.webkit.WebView;
|
35 |
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
36 |
36 |
import android.widget.ListView;
|
37 |
37 |
import android.widget.Toast;
|
38 |
38 |
|
... | ... | |
42 |
42 |
public class AppListFragment extends ListFragment implements LoaderCallbacks<List<AppEntry>> {
|
43 |
43 |
|
44 |
44 |
private AppListAdapter adapter;
|
|
45 |
private ActionMode actionMode;
|
|
46 |
private ListView listView;
|
|
47 |
private int selectedItem = -1;
|
|
48 |
private static final String STATE_CHECKED = "info.guardianproject.checkey.STATE_CHECKED";
|
45 |
49 |
WebView androidObservatoryView;
|
46 |
50 |
|
47 |
51 |
@Override
|
... | ... | |
54 |
58 |
setListAdapter(adapter);
|
55 |
59 |
setListShown(false);
|
56 |
60 |
|
57 |
|
registerForContextMenu(getListView());
|
|
61 |
listView = getListView();
|
|
62 |
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
|
63 |
|
|
64 |
if (savedInstanceState != null) {
|
|
65 |
int position = savedInstanceState.getInt(STATE_CHECKED, -1);
|
|
66 |
if (position > -1) {
|
|
67 |
listView.setItemChecked(position, true);
|
|
68 |
}
|
|
69 |
}
|
58 |
70 |
|
59 |
71 |
// Prepare the loader
|
60 |
72 |
// either reconnect with an existing one or start a new one
|
... | ... | |
62 |
74 |
}
|
63 |
75 |
|
64 |
76 |
@Override
|
65 |
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
66 |
|
ContextMenuInfo menuInfo) {
|
67 |
|
super.onCreateContextMenu(menu, v, menuInfo);
|
68 |
|
MenuInflater inflater = getActivity().getMenuInflater();
|
69 |
|
inflater.inflate(R.menu.context, menu);
|
|
77 |
public void onSaveInstanceState(Bundle savedInstanceState) {
|
|
78 |
super.onSaveInstanceState(savedInstanceState);
|
|
79 |
savedInstanceState.putInt(STATE_CHECKED, selectedItem);
|
70 |
80 |
}
|
71 |
81 |
|
72 |
82 |
@Override
|
73 |
|
public boolean onContextItemSelected(MenuItem item) {
|
74 |
|
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
|
75 |
|
AppEntry appEntry = (AppEntry) adapter.getItem(menuInfo.position);
|
76 |
|
Intent intent = new Intent(getActivity(), WebViewActivity.class);
|
77 |
|
switch (item.getItemId()) {
|
78 |
|
case R.id.by_apk_hash:
|
79 |
|
byApkHash(appEntry, intent);
|
80 |
|
break;
|
81 |
|
case R.id.by_package_name:
|
82 |
|
byPackageName(appEntry, intent);
|
83 |
|
break;
|
84 |
|
case R.id.by_signing_certificate:
|
85 |
|
bySigningCertificate(appEntry, intent);
|
86 |
|
break;
|
|
83 |
public void onListItemClick(ListView l, View v, int position, long id) {
|
|
84 |
if (actionMode != null) {
|
|
85 |
return;
|
87 |
86 |
}
|
88 |
|
return true;
|
89 |
|
}
|
90 |
87 |
|
91 |
|
@Override
|
92 |
|
public void onListItemClick(ListView l, View v, int position, long id) {
|
93 |
|
AppEntry appEntry = (AppEntry) adapter.getItem(position);
|
94 |
|
Intent intent = new Intent(getActivity(), WebViewActivity.class);
|
95 |
|
byApkHash(appEntry, intent);
|
|
88 |
// Start the CAB using the ActionMode.Callback defined above
|
|
89 |
ActionBarActivity activity = (ActionBarActivity) getActivity();
|
|
90 |
actionMode = activity.startSupportActionMode(mActionModeCallback);
|
|
91 |
selectedItem = position;
|
96 |
92 |
}
|
97 |
93 |
|
98 |
94 |
private void byApkHash(AppEntry appEntry, Intent intent) {
|
... | ... | |
150 |
146 |
// Clear the data in the adapter
|
151 |
147 |
adapter.setData(null);
|
152 |
148 |
}
|
|
149 |
|
|
150 |
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
|
|
151 |
|
|
152 |
// Called when the action mode is created; startActionMode() was called
|
|
153 |
@Override
|
|
154 |
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
155 |
// Inflate a menu resource providing context menu items
|
|
156 |
MenuInflater inflater = mode.getMenuInflater();
|
|
157 |
inflater.inflate(R.menu.context, menu);
|
|
158 |
return true;
|
|
159 |
}
|
|
160 |
|
|
161 |
@Override
|
|
162 |
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
163 |
return false;
|
|
164 |
}
|
|
165 |
|
|
166 |
// Called when the user selects a contextual menu item
|
|
167 |
@Override
|
|
168 |
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
169 |
AppEntry appEntry = (AppEntry) adapter.getItem(selectedItem);
|
|
170 |
Intent intent = new Intent(getActivity(), WebViewActivity.class);
|
|
171 |
switch (item.getItemId()) {
|
|
172 |
case R.id.by_apk_hash:
|
|
173 |
byApkHash(appEntry, intent);
|
|
174 |
break;
|
|
175 |
case R.id.by_package_name:
|
|
176 |
byPackageName(appEntry, intent);
|
|
177 |
break;
|
|
178 |
case R.id.by_signing_certificate:
|
|
179 |
bySigningCertificate(appEntry, intent);
|
|
180 |
break;
|
|
181 |
|
|
182 |
default:
|
|
183 |
return false;
|
|
184 |
}
|
|
185 |
return true;
|
|
186 |
}
|
|
187 |
|
|
188 |
// Called when the user exits the action mode
|
|
189 |
@Override
|
|
190 |
public void onDestroyActionMode(ActionMode mode) {
|
|
191 |
listView.setItemChecked(selectedItem, false);
|
|
192 |
listView.clearChoices();
|
|
193 |
selectedItem = -1;
|
|
194 |
actionMode = null;
|
|
195 |
}
|
|
196 |
};
|
153 |
197 |
}
|