OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chromoting; | |
6 | |
7 import android.app.Activity; | |
8 import android.content.Intent; | |
9 import android.content.pm.PackageInfo; | |
10 import android.content.pm.PackageManager; | |
11 import android.net.Uri; | |
12 import android.os.Bundle; | |
13 import android.text.TextUtils; | |
14 import android.view.Menu; | |
15 import android.view.MenuItem; | |
16 import android.webkit.WebView; | |
17 import android.webkit.WebViewClient; | |
18 | |
19 /** | |
20 * The Activity for showing the Help screen. | |
21 */ | |
22 public class HelpActivity extends Activity { | |
23 private static final String PLAY_STORE_URL = "market://details?id="; | |
24 | |
25 /** Launches an external web browser or application. */ | |
26 private void openUrl(String url) { | |
27 Uri uri = Uri.parse(url); | |
28 Intent intent = new Intent(Intent.ACTION_VIEW, uri); | |
29 | |
30 // Verify that the device can launch an application for this intent, oth erwise | |
31 // startActivity() may crash the application. | |
32 if (intent.resolveActivity(getPackageManager()) != null) { | |
Jamie
2014/02/25 22:01:18
Is this scenario common enough that it's worth mak
Lambros
2014/02/26 21:15:45
I can't see any supported device being unable to l
| |
33 startActivity(intent); | |
34 } | |
35 } | |
36 | |
37 @Override | |
38 public void onCreate(Bundle savedInstanceState) { | |
39 super.onCreate(savedInstanceState); | |
40 | |
41 WebView webView = new WebView(this); | |
42 setContentView(webView); | |
43 | |
44 getActionBar().setTitle(getString(R.string.actionbar_help_title)); | |
45 | |
46 CharSequence appName = getTitle(); | |
47 CharSequence versionName = null; | |
48 try { | |
49 PackageInfo info = getPackageManager().getPackageInfo(getPackageName (), 0); | |
50 versionName = info.versionName; | |
51 } catch (PackageManager.NameNotFoundException ex) { | |
52 throw new RuntimeException("Unable to get version: " + ex); | |
53 } | |
54 | |
55 CharSequence subtitle = TextUtils.concat(appName, " ", versionName); | |
56 getActionBar().setSubtitle(subtitle); | |
57 | |
58 // This line ensures the WebView remains embedded in this activity and d oesn't launch an | |
59 // external Chrome browser. | |
60 webView.setWebViewClient(new WebViewClient()); | |
61 webView.getSettings().setJavaScriptEnabled(true); | |
62 String url = getIntent().getDataString(); | |
63 webView.loadUrl(url); | |
64 } | |
65 | |
66 @Override | |
67 public boolean onCreateOptionsMenu(Menu menu) { | |
68 getMenuInflater().inflate(R.menu.help_actionbar, menu); | |
69 return super.onCreateOptionsMenu(menu); | |
70 } | |
71 | |
72 @Override | |
73 public boolean onOptionsItemSelected(MenuItem item) { | |
74 switch (item.getItemId()) { | |
75 case R.id.actionbar_play_store: | |
76 openUrl(PLAY_STORE_URL + getPackageName()); | |
Jamie
2014/02/25 22:01:18
Will this open in the web browser or in the Google
Lambros
2014/02/26 21:15:45
It opens the Play Store app.
| |
77 return true; | |
78 | |
79 default: | |
80 return super.onOptionsItemSelected(item); | |
81 } | |
82 } | |
83 } | |
OLD | NEW |