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