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.
5 package org
.chromium
.chromoting
;
7 import android
.app
.Activity
;
8 import android
.content
.ComponentName
;
9 import android
.content
.Intent
;
10 import android
.content
.ServiceConnection
;
11 import android
.content
.pm
.PackageInfo
;
12 import android
.content
.pm
.PackageManager
;
13 import android
.graphics
.Bitmap
;
14 import android
.net
.Uri
;
15 import android
.os
.Binder
;
16 import android
.os
.Bundle
;
17 import android
.os
.IBinder
;
18 import android
.os
.Parcel
;
19 import android
.os
.RemoteException
;
20 import android
.support
.v7
.app
.ActionBarActivity
;
21 import android
.text
.TextUtils
;
22 import android
.util
.Log
;
23 import android
.view
.Menu
;
24 import android
.view
.MenuItem
;
25 import android
.view
.View
;
26 import android
.webkit
.WebView
;
27 import android
.webkit
.WebViewClient
;
29 import org
.chromium
.ui
.UiUtils
;
32 * The Activity for showing the Help screen.
34 public class HelpActivity
extends ActionBarActivity
{
35 private static final String PLAY_STORE_URL
= "market://details?id=";
37 private static final String FEEDBACK_PACKAGE
= "com.google.android.gms";
39 private static final String FEEDBACK_CLASS
=
40 "com.google.android.gms.feedback.LegacyBugReportService";
43 * Maximum dimension for the screenshot to be sent to the Send Feedback handler. This size
44 * ensures the size of bitmap < 1MB, which is a requirement of the handler.
46 private static final int MAX_FEEDBACK_SCREENSHOT_DIMENSION
= 600;
49 * This global variable is used for passing the screenshot from the originating Activity to the
50 * HelpActivity. There seems to be no better way of doing this.
52 private static Bitmap sScreenshot
;
54 /** Constant used to send the feedback parcel to the system feedback service. */
55 private static final int SEND_FEEDBACK_INFO
= Binder
.FIRST_CALL_TRANSACTION
;
57 /** Launches an external web browser or application. */
58 private void openUrl(String url
) {
59 Uri uri
= Uri
.parse(url
);
60 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uri
);
62 // Verify that the device can launch an application for this intent, otherwise
63 // startActivity() may crash the application.
64 if (intent
.resolveActivity(getPackageManager()) != null) {
65 startActivity(intent
);
69 private void sendFeedback() {
70 Intent intent
= new Intent(Intent
.ACTION_BUG_REPORT
);
71 intent
.setComponent(new ComponentName(FEEDBACK_PACKAGE
, FEEDBACK_CLASS
));
72 if (getPackageManager().resolveService(intent
, 0) == null) {
73 Log
.e("help", "Unable to resolve Feedback service.");
77 ServiceConnection conn
= new ServiceConnection() {
79 public void onServiceConnected(ComponentName name
, IBinder service
) {
81 Parcel parcel
= Parcel
.obtain();
82 if (sScreenshot
!= null) {
83 sScreenshot
.writeToParcel(parcel
, 0);
85 service
.transact(SEND_FEEDBACK_INFO
, parcel
, null, 0);
87 } catch (RemoteException ex
) {
88 Log
.e("help", "Unexpected error sending feedback: ", ex
);
93 public void onServiceDisconnected(ComponentName name
) {}
96 bindService(intent
, conn
, BIND_AUTO_CREATE
);
99 /** Launches the Help activity. */
100 public static void launch(Activity activity
, String helpUrl
) {
101 View rootView
= activity
.getWindow().getDecorView().getRootView();
102 sScreenshot
= UiUtils
.generateScaledScreenshot(rootView
, MAX_FEEDBACK_SCREENSHOT_DIMENSION
,
103 Bitmap
.Config
.ARGB_8888
);
105 Intent intent
= new Intent(activity
, HelpActivity
.class);
106 intent
.setData(Uri
.parse(helpUrl
));
107 activity
.startActivity(intent
);
111 public void onCreate(Bundle savedInstanceState
) {
112 super.onCreate(savedInstanceState
);
114 WebView webView
= new WebView(this);
115 setContentView(webView
);
117 getSupportActionBar().setTitle(getString(R
.string
.actionbar_help_title
));
119 CharSequence appName
= getTitle();
120 CharSequence versionName
= null;
122 PackageInfo info
= getPackageManager().getPackageInfo(getPackageName(), 0);
123 versionName
= info
.versionName
;
124 } catch (PackageManager
.NameNotFoundException ex
) {
125 throw new RuntimeException("Unable to get version: " + ex
);
128 CharSequence subtitle
= TextUtils
.concat(appName
, " ", versionName
);
129 getSupportActionBar().setSubtitle(subtitle
);
131 // This line ensures the WebView remains embedded in this activity and doesn't launch an
132 // external Chrome browser.
133 webView
.setWebViewClient(new WebViewClient());
134 webView
.getSettings().setJavaScriptEnabled(true);
135 String url
= getIntent().getDataString();
136 webView
.loadUrl(url
);
140 public boolean onCreateOptionsMenu(Menu menu
) {
141 getMenuInflater().inflate(R
.menu
.help_actionbar
, menu
);
142 return super.onCreateOptionsMenu(menu
);
146 public boolean onOptionsItemSelected(MenuItem item
) {
147 int id
= item
.getItemId();
148 if (id
== R
.id
.actionbar_feedback
) {
152 if (id
== R
.id
.actionbar_play_store
) {
153 openUrl(PLAY_STORE_URL
+ getPackageName());
156 return super.onOptionsItemSelected(item
);