URIResultHandler.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2008 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.google.zxing.client.android.result;
  17. import com.google.zxing.client.result.ParsedResult;
  18. import com.google.zxing.client.result.URIParsedResult;
  19. import com.libs.zxing.R;
  20. import android.app.Activity;
  21. import android.widget.Toast;
  22. import java.util.Locale;
  23. /**
  24. * Offers appropriate actions for URLS.
  25. *
  26. * @author dswitkin@google.com (Daniel Switkin)
  27. */
  28. public final class URIResultHandler extends ResultHandler {
  29. // URIs beginning with entries in this array will not be saved to history or copied to the
  30. // clipboard for security.
  31. private static final String[] SECURE_PROTOCOLS = {
  32. "otpauth:"
  33. };
  34. public URIResultHandler(Activity activity, ParsedResult result) {
  35. super(activity, result);
  36. }
  37. @Override
  38. public int getButtonCount() {
  39. return 1;
  40. }
  41. @Override
  42. public int getButtonText(int index) {
  43. return R.string.button_1;
  44. }
  45. @Override
  46. public void handleButtonPress(int index) {
  47. URIParsedResult uriResult = (URIParsedResult) getResult();
  48. String uri = uriResult.getURI();
  49. //TODO
  50. if(uri.contains ("http://m.muzhiwan.com")){
  51. Toast.makeText (getActivity (), uri, Toast.LENGTH_SHORT).show ();
  52. return;
  53. }
  54. Toast.makeText (getActivity (), uri, Toast.LENGTH_SHORT).show ();
  55. openURL(uri);
  56. }
  57. @Override
  58. public int getDisplayTitle() {
  59. return R.string.result_uri;
  60. }
  61. @Override
  62. public boolean areContentsSecure() {
  63. URIParsedResult uriResult = (URIParsedResult) getResult();
  64. String uri = uriResult.getURI().toLowerCase(Locale.ENGLISH);
  65. for (String secure : SECURE_PROTOCOLS) {
  66. if (uri.startsWith(secure)) {
  67. return true;
  68. }
  69. }
  70. return false;
  71. }
  72. }