trustedintents / app / src / main / java / info / guardianproject / trustedintents / MainActivity.java @ 9f5bcd3f
History | View | Annotate | Download (2.79 KB)
1 |
package info.guardianproject.trustedintents; |
---|---|
2 |
|
3 |
import android.app.Activity; |
4 |
import android.content.ActivityNotFoundException; |
5 |
import android.content.Intent; |
6 |
import android.os.Bundle; |
7 |
import android.support.design.widget.FloatingActionButton; |
8 |
import android.support.design.widget.Snackbar; |
9 |
import android.support.v7.app.AppCompatActivity; |
10 |
import android.support.v7.widget.Toolbar; |
11 |
import android.view.Menu; |
12 |
import android.view.MenuItem; |
13 |
import android.view.View; |
14 |
import android.widget.Toast; |
15 |
|
16 |
import org.torproject.TorProjectRSA1024; |
17 |
|
18 |
import java.security.cert.CertificateException; |
19 |
|
20 |
import info.guardianproject.GuardianProjectRSA1024; |
21 |
|
22 |
public class MainActivity extends AppCompatActivity { |
23 |
|
24 |
private static TrustedIntents trustedIntents; |
25 |
|
26 |
@Override
|
27 |
protected void onCreate(Bundle savedInstanceState) { |
28 |
super.onCreate(savedInstanceState);
|
29 |
|
30 |
trustedIntents = TrustedIntents.get(this);
|
31 |
trustedIntents.addTrustedSigner(GuardianProjectRSA1024.class); |
32 |
|
33 |
setContentView(R.layout.activity_main); |
34 |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
35 |
setSupportActionBar(toolbar); |
36 |
|
37 |
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); |
38 |
fab.setOnClickListener(new View.OnClickListener() { |
39 |
@Override
|
40 |
public void onClick(View view) { |
41 |
final Activity activity = MainActivity.this;
|
42 |
try {
|
43 |
Intent intent = new Intent(Intent.ACTION_VIEW);
|
44 |
intent.setClassName("info.guardianproject.gpg",
|
45 |
"info.guardianproject.gpg.MainActivity");
|
46 |
trustedIntents.startActivity(activity, intent); |
47 |
} catch (ActivityNotFoundException e) {
|
48 |
e.printStackTrace(); |
49 |
Toast.makeText(activity, e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); |
50 |
} catch (CertificateException e) { |
51 |
e.printStackTrace(); |
52 |
Toast.makeText(activity, e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); |
53 |
} |
54 |
} |
55 |
}); |
56 |
} |
57 |
|
58 |
@Override
|
59 |
public boolean onCreateOptionsMenu(Menu menu) { |
60 |
// Inflate the menu; this adds items to the action bar if it is present.
|
61 |
getMenuInflater().inflate(R.menu.menu_main, menu); |
62 |
return true; |
63 |
} |
64 |
|
65 |
@Override
|
66 |
public boolean onOptionsItemSelected(MenuItem item) { |
67 |
// Handle action bar item clicks here. The action bar will
|
68 |
// automatically handle clicks on the Home/Up button, so long
|
69 |
// as you specify a parent activity in AndroidManifest.xml.
|
70 |
int id = item.getItemId();
|
71 |
|
72 |
//noinspection SimplifiableIfStatement
|
73 |
if (id == R.id.action_settings) {
|
74 |
return true; |
75 |
} |
76 |
|
77 |
return super.onOptionsItemSelected(item); |
78 |
} |
79 |
} |