| 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.help; | 5 package org.chromium.chromoting.help; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.ComponentName; | |
| 9 import android.content.Intent; | 8 import android.content.Intent; |
| 10 import android.content.ServiceConnection; | |
| 11 import android.content.pm.PackageInfo; | 9 import android.content.pm.PackageInfo; |
| 12 import android.content.pm.PackageManager; | 10 import android.content.pm.PackageManager; |
| 13 import android.graphics.Bitmap; | 11 import android.graphics.Bitmap; |
| 14 import android.net.Uri; | 12 import android.net.Uri; |
| 15 import android.os.Binder; | |
| 16 import android.os.Bundle; | 13 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.AppCompatActivity; | 14 import android.support.v7.app.AppCompatActivity; |
| 21 import android.support.v7.widget.Toolbar; | 15 import android.support.v7.widget.Toolbar; |
| 22 import android.text.TextUtils; | 16 import android.text.TextUtils; |
| 23 import android.view.Menu; | 17 import android.view.Menu; |
| 24 import android.view.MenuItem; | 18 import android.view.MenuItem; |
| 25 import android.view.View; | 19 import android.view.View; |
| 26 import android.webkit.WebView; | 20 import android.webkit.WebView; |
| 27 import android.webkit.WebViewClient; | 21 import android.webkit.WebViewClient; |
| 28 | 22 |
| 29 import org.chromium.base.Log; | |
| 30 import org.chromium.chromoting.ChromotingUtil; | 23 import org.chromium.chromoting.ChromotingUtil; |
| 31 import org.chromium.chromoting.R; | 24 import org.chromium.chromoting.R; |
| 32 import org.chromium.ui.UiUtils; | 25 import org.chromium.ui.UiUtils; |
| 33 | 26 |
| 34 /** | 27 /** |
| 35 * The Activity for showing the Help screen. | 28 * The Activity for showing the Help screen. |
| 36 */ | 29 */ |
| 37 public class HelpActivity extends AppCompatActivity { | 30 public class HelpActivity extends AppCompatActivity { |
| 38 private static final String TAG = "Chromoting"; | |
| 39 | |
| 40 private static final String PLAY_STORE_URL = "market://details?id="; | 31 private static final String PLAY_STORE_URL = "market://details?id="; |
| 41 | 32 |
| 42 private static final String FEEDBACK_PACKAGE = "com.google.android.gms"; | |
| 43 | |
| 44 private static final String FEEDBACK_CLASS = | |
| 45 "com.google.android.gms.feedback.LegacyBugReportService"; | |
| 46 | |
| 47 /** | 33 /** |
| 48 * Maximum dimension for the screenshot to be sent to the Send Feedback hand
ler. This size | 34 * Maximum dimension for the screenshot to be sent to the Send Feedback hand
ler. This size |
| 49 * ensures the size of bitmap < 1MB, which is a requirement of the handler. | 35 * ensures the size of bitmap < 1MB, which is a requirement of the handler. |
| 50 */ | 36 */ |
| 51 private static final int MAX_FEEDBACK_SCREENSHOT_DIMENSION = 600; | 37 private static final int MAX_FEEDBACK_SCREENSHOT_DIMENSION = 600; |
| 52 | 38 |
| 53 /** | 39 /** |
| 54 * This global variable is used for passing the screenshot from the originat
ing Activity to the | 40 * This global variable is used for passing the screenshot from the originat
ing Activity to the |
| 55 * HelpActivity. There seems to be no better way of doing this. | 41 * HelpActivity. There seems to be no better way of doing this. |
| 56 */ | 42 */ |
| 57 private static Bitmap sScreenshot; | 43 private static Bitmap sScreenshot; |
| 58 | 44 |
| 59 /** WebView used to display help content. */ | 45 /** WebView used to display help content. */ |
| 60 private WebView mWebView; | 46 private WebView mWebView; |
| 61 | 47 |
| 62 /** Constant used to send the feedback parcel to the system feedback service
. */ | |
| 63 private static final int SEND_FEEDBACK_INFO = Binder.FIRST_CALL_TRANSACTION; | |
| 64 | |
| 65 private void sendFeedback() { | |
| 66 Intent intent = new Intent(Intent.ACTION_BUG_REPORT); | |
| 67 intent.setComponent(new ComponentName(FEEDBACK_PACKAGE, FEEDBACK_CLASS))
; | |
| 68 if (getPackageManager().resolveService(intent, 0) == null) { | |
| 69 Log.e(TAG, "Unable to resolve Feedback service."); | |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 ServiceConnection conn = new ServiceConnection() { | |
| 74 @Override | |
| 75 public void onServiceConnected(ComponentName name, IBinder service)
{ | |
| 76 try { | |
| 77 Parcel parcel = Parcel.obtain(); | |
| 78 if (sScreenshot != null) { | |
| 79 sScreenshot.writeToParcel(parcel, 0); | |
| 80 } | |
| 81 service.transact(SEND_FEEDBACK_INFO, parcel, null, 0); | |
| 82 parcel.recycle(); | |
| 83 } catch (RemoteException ex) { | |
| 84 Log.e(TAG, "Unexpected error sending feedback: ", ex); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 @Override | |
| 89 public void onServiceDisconnected(ComponentName name) {} | |
| 90 }; | |
| 91 | |
| 92 bindService(intent, conn, BIND_AUTO_CREATE); | |
| 93 } | |
| 94 | |
| 95 /** Launches the Help activity. */ | 48 /** Launches the Help activity. */ |
| 96 public static void launch(Activity activity, String helpUrl) { | 49 public static void launch(Activity activity, String helpUrl) { |
| 97 View rootView = activity.getWindow().getDecorView().getRootView(); | 50 View rootView = activity.getWindow().getDecorView().getRootView(); |
| 98 sScreenshot = UiUtils.generateScaledScreenshot(rootView, MAX_FEEDBACK_SC
REENSHOT_DIMENSION, | 51 sScreenshot = UiUtils.generateScaledScreenshot(rootView, MAX_FEEDBACK_SC
REENSHOT_DIMENSION, |
| 99 Bitmap.Config.ARGB_8888); | 52 Bitmap.Config.ARGB_8888); |
| 100 | 53 |
| 101 Intent intent = new Intent(activity, HelpActivity.class); | 54 Intent intent = new Intent(activity, HelpActivity.class); |
| 102 intent.setData(Uri.parse(helpUrl)); | 55 intent.setData(Uri.parse(helpUrl)); |
| 103 activity.startActivity(intent); | 56 activity.startActivity(intent); |
| 104 } | 57 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 110 } |
| 158 | 111 |
| 159 @Override | 112 @Override |
| 160 public boolean onOptionsItemSelected(MenuItem item) { | 113 public boolean onOptionsItemSelected(MenuItem item) { |
| 161 int id = item.getItemId(); | 114 int id = item.getItemId(); |
| 162 if (id == android.R.id.home) { | 115 if (id == android.R.id.home) { |
| 163 finish(); | 116 finish(); |
| 164 return true; | 117 return true; |
| 165 } | 118 } |
| 166 if (id == R.id.actionbar_feedback) { | 119 if (id == R.id.actionbar_feedback) { |
| 167 sendFeedback(); | 120 FeedbackSender.sendFeedback(this, sScreenshot); |
| 168 return true; | 121 return true; |
| 169 } | 122 } |
| 170 if (id == R.id.actionbar_play_store) { | 123 if (id == R.id.actionbar_play_store) { |
| 171 ChromotingUtil.openUrl(this, Uri.parse(PLAY_STORE_URL + getPackageNa
me())); | 124 ChromotingUtil.openUrl(this, Uri.parse(PLAY_STORE_URL + getPackageNa
me())); |
| 172 return true; | 125 return true; |
| 173 } | 126 } |
| 174 if (id == R.id.actionbar_credits) { | 127 if (id == R.id.actionbar_credits) { |
| 175 startActivity(new Intent(this, CreditsActivity.class)); | 128 startActivity(new Intent(this, CreditsActivity.class)); |
| 176 return true; | 129 return true; |
| 177 } | 130 } |
| 178 return super.onOptionsItemSelected(item); | 131 return super.onOptionsItemSelected(item); |
| 179 } | 132 } |
| 180 } | 133 } |
| OLD | NEW |