OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chromoting; | 5 package org.chromium.chromoting; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.ComponentName; |
8 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.ServiceConnection; |
9 import android.content.pm.PackageInfo; | 11 import android.content.pm.PackageInfo; |
10 import android.content.pm.PackageManager; | 12 import android.content.pm.PackageManager; |
| 13 import android.graphics.Bitmap; |
11 import android.net.Uri; | 14 import android.net.Uri; |
| 15 import android.os.Binder; |
12 import android.os.Bundle; | 16 import android.os.Bundle; |
| 17 import android.os.IBinder; |
| 18 import android.os.Parcel; |
| 19 import android.os.RemoteException; |
13 import android.text.TextUtils; | 20 import android.text.TextUtils; |
| 21 import android.util.Log; |
14 import android.view.Menu; | 22 import android.view.Menu; |
15 import android.view.MenuItem; | 23 import android.view.MenuItem; |
| 24 import android.view.View; |
16 import android.webkit.WebView; | 25 import android.webkit.WebView; |
17 import android.webkit.WebViewClient; | 26 import android.webkit.WebViewClient; |
18 | 27 |
| 28 import org.chromium.ui.UiUtils; |
| 29 |
19 /** | 30 /** |
20 * The Activity for showing the Help screen. | 31 * The Activity for showing the Help screen. |
21 */ | 32 */ |
22 public class HelpActivity extends Activity { | 33 public class HelpActivity extends Activity { |
23 private static final String PLAY_STORE_URL = "market://details?id="; | 34 private static final String PLAY_STORE_URL = "market://details?id="; |
24 | 35 |
| 36 /** |
| 37 * Maximum dimension for the screenshot to be sent to the Send Feedback hand
ler. This size |
| 38 * ensures the size of bitmap < 1MB, which is a requirement of the handler. |
| 39 */ |
| 40 private static final int MAX_FEEDBACK_SCREENSHOT_DIMENSION = 600; |
| 41 |
| 42 /** |
| 43 * This global variable is used for passing the screenshot from the originat
ing Activity to the |
| 44 * HelpActivity. There seems to be no better way of doing this. |
| 45 */ |
| 46 private static Bitmap mScreenshot; |
| 47 |
| 48 /** Constant used to send the feedback parcel to the system feedback service
. */ |
| 49 private static final int SEND_FEEDBACK_INFO = Binder.FIRST_CALL_TRANSACTION; |
| 50 |
25 /** Launches an external web browser or application. */ | 51 /** Launches an external web browser or application. */ |
26 private void openUrl(String url) { | 52 private void openUrl(String url) { |
27 Uri uri = Uri.parse(url); | 53 Uri uri = Uri.parse(url); |
28 Intent intent = new Intent(Intent.ACTION_VIEW, uri); | 54 Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
29 | 55 |
30 // Verify that the device can launch an application for this intent, oth
erwise | 56 // Verify that the device can launch an application for this intent, oth
erwise |
31 // startActivity() may crash the application. | 57 // startActivity() may crash the application. |
32 if (intent.resolveActivity(getPackageManager()) != null) { | 58 if (intent.resolveActivity(getPackageManager()) != null) { |
33 startActivity(intent); | 59 startActivity(intent); |
34 } | 60 } |
35 } | 61 } |
36 | 62 |
| 63 private void sendFeedback() { |
| 64 Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
| 65 ServiceConnection conn = new ServiceConnection() { |
| 66 @Override |
| 67 public void onServiceConnected(ComponentName name, IBinder service)
{ |
| 68 try { |
| 69 Parcel parcel = Parcel.obtain(); |
| 70 if (mScreenshot != null) { |
| 71 mScreenshot.writeToParcel(parcel, 0); |
| 72 } |
| 73 service.transact(SEND_FEEDBACK_INFO, parcel, null, 0); |
| 74 parcel.recycle(); |
| 75 } catch (RemoteException ex) { |
| 76 Log.e("help", "Unexpected error sending feedback: ", ex); |
| 77 } |
| 78 } |
| 79 |
| 80 @Override |
| 81 public void onServiceDisconnected(ComponentName name) {} |
| 82 }; |
| 83 |
| 84 bindService(intent, conn, BIND_AUTO_CREATE); |
| 85 } |
| 86 |
| 87 /** Launches the Help activity. */ |
| 88 public static void launch(Activity activity, String helpUrl) { |
| 89 View rootView = activity.getWindow().getDecorView().getRootView(); |
| 90 mScreenshot = UiUtils.generateScaledScreenshot(rootView, MAX_FEEDBACK_SC
REENSHOT_DIMENSION, |
| 91 Bitmap.Config.ARGB_8888); |
| 92 |
| 93 Intent intent = new Intent(activity, HelpActivity.class); |
| 94 intent.setData(Uri.parse(helpUrl)); |
| 95 activity.startActivity(intent); |
| 96 } |
| 97 |
37 @Override | 98 @Override |
38 public void onCreate(Bundle savedInstanceState) { | 99 public void onCreate(Bundle savedInstanceState) { |
39 super.onCreate(savedInstanceState); | 100 super.onCreate(savedInstanceState); |
40 | 101 |
41 WebView webView = new WebView(this); | 102 WebView webView = new WebView(this); |
42 setContentView(webView); | 103 setContentView(webView); |
43 | 104 |
44 getActionBar().setTitle(getString(R.string.actionbar_help_title)); | 105 getActionBar().setTitle(getString(R.string.actionbar_help_title)); |
45 | 106 |
46 CharSequence appName = getTitle(); | 107 CharSequence appName = getTitle(); |
(...skipping 18 matching lines...) Expand all Loading... |
65 | 126 |
66 @Override | 127 @Override |
67 public boolean onCreateOptionsMenu(Menu menu) { | 128 public boolean onCreateOptionsMenu(Menu menu) { |
68 getMenuInflater().inflate(R.menu.help_actionbar, menu); | 129 getMenuInflater().inflate(R.menu.help_actionbar, menu); |
69 return super.onCreateOptionsMenu(menu); | 130 return super.onCreateOptionsMenu(menu); |
70 } | 131 } |
71 | 132 |
72 @Override | 133 @Override |
73 public boolean onOptionsItemSelected(MenuItem item) { | 134 public boolean onOptionsItemSelected(MenuItem item) { |
74 switch (item.getItemId()) { | 135 switch (item.getItemId()) { |
| 136 case R.id.actionbar_feedback: |
| 137 sendFeedback(); |
| 138 return true; |
| 139 |
75 case R.id.actionbar_play_store: | 140 case R.id.actionbar_play_store: |
76 openUrl(PLAY_STORE_URL + getPackageName()); | 141 openUrl(PLAY_STORE_URL + getPackageName()); |
77 return true; | 142 return true; |
78 | 143 |
79 default: | 144 default: |
80 return super.onOptionsItemSelected(item); | 145 return super.onOptionsItemSelected(item); |
81 } | 146 } |
82 } | 147 } |
83 } | 148 } |
OLD | NEW |