Revision a5eac6db

View differences:

res/menu/context.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
3

  
4
    <item
5
        android:id="@+id/by_apk_hash"
6
        android:title="@string/by_apk_hash"/>
7
    <item
8
        android:id="@+id/by_package_name"
9
        android:title="@string/by_package_name"/>
10
    <item
11
        android:id="@+id/by_signing_certificate"
12
        android:title="@string/by_signing_certificate"/>
13

  
14
</menu>
src/info/guardianproject/checkey/AppListFragment.java
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;
31
import android.view.MenuInflater;
32
import android.view.MenuItem;
29 33
import android.view.View;
30 34
import android.webkit.WebView;
31
import android.widget.AdapterView;
32
import android.widget.AdapterView.OnItemLongClickListener;
35
import android.widget.AdapterView.AdapterContextMenuInfo;
33 36
import android.widget.ListView;
34 37

  
35 38
import java.util.List;
36 39

  
37
public class AppListFragment extends ListFragment
38
        implements LoaderCallbacks<List<AppEntry>>, OnItemLongClickListener {
40
public class AppListFragment extends ListFragment implements LoaderCallbacks<List<AppEntry>> {
39 41

  
40 42
    private AppListAdapter adapter;
41 43
    WebView androidObservatoryView;
......
50 52
        setListAdapter(adapter);
51 53
        setListShown(false);
52 54

  
53
        getListView().setOnItemLongClickListener(this);
55
        registerForContextMenu(getListView());
54 56

  
55 57
        // Prepare the loader
56 58
        // either reconnect with an existing one or start a new one
......
58 60
    }
59 61

  
60 62
    @Override
63
    public void onCreateContextMenu(ContextMenu menu, View v,
64
            ContextMenuInfo menuInfo) {
65
        super.onCreateContextMenu(menu, v, menuInfo);
66
        MenuInflater inflater = getActivity().getMenuInflater();
67
        inflater.inflate(R.menu.context, menu);
68
    }
69

  
70
    @Override
71
    public boolean onContextItemSelected(MenuItem item) {
72
        AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
73
        AppEntry appEntry = (AppEntry) adapter.getItem(menuInfo.position);
74
        Intent intent = new Intent(getActivity(), WebViewActivity.class);
75
        switch (item.getItemId()) {
76
            case R.id.by_apk_hash:
77
                byApkHash(appEntry, intent);
78
                break;
79
            case R.id.by_package_name:
80
                byPackageName(appEntry, intent);
81
                break;
82
            case R.id.by_signing_certificate:
83
                bySigningCertificate(appEntry, intent);
84
                break;
85
        }
86
        return true;
87
    }
88

  
89
    @Override
61 90
    public void onListItemClick(ListView l, View v, int position, long id) {
62 91
        AppEntry appEntry = (AppEntry) adapter.getItem(position);
63 92
        Intent intent = new Intent(getActivity(), WebViewActivity.class);
93
        byApkHash(appEntry, intent);
94
    }
95

  
96
    private void byApkHash(AppEntry appEntry, Intent intent) {
64 97
        String urlString = "https://androidobservatory.org/?searchby=binhash&q="
65 98
                + Utils.getBinaryHash(appEntry.getApkFile(), "sha1");
66 99
        intent.setData(Uri.parse(urlString));
......
68 101
        startActivity(intent);
69 102
    }
70 103

  
71
    @Override
72
    public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
73
        AppEntry appEntry = (AppEntry) adapter.getItem(position);
74
        Intent intent = new Intent(getActivity(), WebViewActivity.class);
104
    private void byPackageName(AppEntry appEntry, Intent intent) {
75 105
        String urlString = "https://androidobservatory.org/?searchby=pkg&q="
76 106
                + appEntry.getPackageName();
77 107
        intent.setData(Uri.parse(urlString));
78 108
        intent.putExtra(Intent.EXTRA_TITLE, R.string.by_package_name);
79 109
        startActivity(intent);
80
        return true;
110
    }
111

  
112
    private void bySigningCertificate(AppEntry appEntry, Intent intent) {
113
        String urlString = "https://androidobservatory.org/?searchby=certhash&q="
114
                + Utils.getBinaryHash(appEntry.getApkFile(), "sha1");
115
        intent.setData(Uri.parse(urlString));
116
        intent.putExtra(Intent.EXTRA_TITLE, R.string.by_signing_certificate);
117
        startActivity(intent);
81 118
    }
82 119

  
83 120
    @Override

Also available in: Unified diff