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.ComponentName; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.ServiceConnection; | 10 import android.content.ServiceConnection; |
(...skipping 30 matching lines...) Expand all Loading... |
41 /** | 41 /** |
42 * Maximum dimension for the screenshot to be sent to the Send Feedback hand
ler. This size | 42 * Maximum dimension for the screenshot to be sent to the Send Feedback hand
ler. This size |
43 * ensures the size of bitmap < 1MB, which is a requirement of the handler. | 43 * ensures the size of bitmap < 1MB, which is a requirement of the handler. |
44 */ | 44 */ |
45 private static final int MAX_FEEDBACK_SCREENSHOT_DIMENSION = 600; | 45 private static final int MAX_FEEDBACK_SCREENSHOT_DIMENSION = 600; |
46 | 46 |
47 /** | 47 /** |
48 * This global variable is used for passing the screenshot from the originat
ing Activity to the | 48 * This global variable is used for passing the screenshot from the originat
ing Activity to the |
49 * HelpActivity. There seems to be no better way of doing this. | 49 * HelpActivity. There seems to be no better way of doing this. |
50 */ | 50 */ |
51 private static Bitmap mScreenshot; | 51 private static Bitmap sScreenshot; |
52 | 52 |
53 /** Constant used to send the feedback parcel to the system feedback service
. */ | 53 /** Constant used to send the feedback parcel to the system feedback service
. */ |
54 private static final int SEND_FEEDBACK_INFO = Binder.FIRST_CALL_TRANSACTION; | 54 private static final int SEND_FEEDBACK_INFO = Binder.FIRST_CALL_TRANSACTION; |
55 | 55 |
56 /** Launches an external web browser or application. */ | 56 /** Launches an external web browser or application. */ |
57 private void openUrl(String url) { | 57 private void openUrl(String url) { |
58 Uri uri = Uri.parse(url); | 58 Uri uri = Uri.parse(url); |
59 Intent intent = new Intent(Intent.ACTION_VIEW, uri); | 59 Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
60 | 60 |
61 // Verify that the device can launch an application for this intent, oth
erwise | 61 // Verify that the device can launch an application for this intent, oth
erwise |
62 // startActivity() may crash the application. | 62 // startActivity() may crash the application. |
63 if (intent.resolveActivity(getPackageManager()) != null) { | 63 if (intent.resolveActivity(getPackageManager()) != null) { |
64 startActivity(intent); | 64 startActivity(intent); |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 private void sendFeedback() { | 68 private void sendFeedback() { |
69 Intent intent = new Intent(Intent.ACTION_BUG_REPORT); | 69 Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
70 intent.setComponent(new ComponentName(FEEDBACK_PACKAGE, FEEDBACK_CLASS))
; | 70 intent.setComponent(new ComponentName(FEEDBACK_PACKAGE, FEEDBACK_CLASS))
; |
71 if (getPackageManager().resolveService(intent, 0) == null) { | 71 if (getPackageManager().resolveService(intent, 0) == null) { |
72 Log.e("help", "Unable to resolve Feedback service."); | 72 Log.e("help", "Unable to resolve Feedback service."); |
73 return; | 73 return; |
74 } | 74 } |
75 | 75 |
76 ServiceConnection conn = new ServiceConnection() { | 76 ServiceConnection conn = new ServiceConnection() { |
77 @Override | 77 @Override |
78 public void onServiceConnected(ComponentName name, IBinder service)
{ | 78 public void onServiceConnected(ComponentName name, IBinder service)
{ |
79 try { | 79 try { |
80 Parcel parcel = Parcel.obtain(); | 80 Parcel parcel = Parcel.obtain(); |
81 if (mScreenshot != null) { | 81 if (sScreenshot != null) { |
82 mScreenshot.writeToParcel(parcel, 0); | 82 sScreenshot.writeToParcel(parcel, 0); |
83 } | 83 } |
84 service.transact(SEND_FEEDBACK_INFO, parcel, null, 0); | 84 service.transact(SEND_FEEDBACK_INFO, parcel, null, 0); |
85 parcel.recycle(); | 85 parcel.recycle(); |
86 } catch (RemoteException ex) { | 86 } catch (RemoteException ex) { |
87 Log.e("help", "Unexpected error sending feedback: ", ex); | 87 Log.e("help", "Unexpected error sending feedback: ", ex); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 @Override | 91 @Override |
92 public void onServiceDisconnected(ComponentName name) {} | 92 public void onServiceDisconnected(ComponentName name) {} |
93 }; | 93 }; |
94 | 94 |
95 bindService(intent, conn, BIND_AUTO_CREATE); | 95 bindService(intent, conn, BIND_AUTO_CREATE); |
96 } | 96 } |
97 | 97 |
98 /** Launches the Help activity. */ | 98 /** Launches the Help activity. */ |
99 public static void launch(Activity activity, String helpUrl) { | 99 public static void launch(Activity activity, String helpUrl) { |
100 View rootView = activity.getWindow().getDecorView().getRootView(); | 100 View rootView = activity.getWindow().getDecorView().getRootView(); |
101 mScreenshot = UiUtils.generateScaledScreenshot(rootView, MAX_FEEDBACK_SC
REENSHOT_DIMENSION, | 101 sScreenshot = UiUtils.generateScaledScreenshot(rootView, MAX_FEEDBACK_SC
REENSHOT_DIMENSION, |
102 Bitmap.Config.ARGB_8888); | 102 Bitmap.Config.ARGB_8888); |
103 | 103 |
104 Intent intent = new Intent(activity, HelpActivity.class); | 104 Intent intent = new Intent(activity, HelpActivity.class); |
105 intent.setData(Uri.parse(helpUrl)); | 105 intent.setData(Uri.parse(helpUrl)); |
106 activity.startActivity(intent); | 106 activity.startActivity(intent); |
107 } | 107 } |
108 | 108 |
109 @Override | 109 @Override |
110 public void onCreate(Bundle savedInstanceState) { | 110 public void onCreate(Bundle savedInstanceState) { |
111 super.onCreate(savedInstanceState); | 111 super.onCreate(savedInstanceState); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 sendFeedback(); | 148 sendFeedback(); |
149 return true; | 149 return true; |
150 } | 150 } |
151 if (id == R.id.actionbar_play_store) { | 151 if (id == R.id.actionbar_play_store) { |
152 openUrl(PLAY_STORE_URL + getPackageName()); | 152 openUrl(PLAY_STORE_URL + getPackageName()); |
153 return true; | 153 return true; |
154 } | 154 } |
155 return super.onOptionsItemSelected(item); | 155 return super.onOptionsItemSelected(item); |
156 } | 156 } |
157 } | 157 } |
OLD | NEW |