/**
   * Called when the BroadcastReceiver receives an Intent broadcast. Checks to see whether the
   * intent's action is _listClickAction. If it is, the app widget displays a Toast message for the
   * current item.
   */
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(_listClickAction)) {
      // ---Launch video search in the browser---
      String searchText = intent.getStringExtra("search_text");
      String linkScheme1 = intent.getStringExtra("scheme1");
      String linkScheme2 = intent.getStringExtra("scheme2");
      Intent browserIntent = null; // new Intent(_listClickAction);
      try {
        browserIntent =
            new Intent(
                Intent.ACTION_VIEW,
                Uri.parse(linkScheme1 + URLEncoder.encode(searchText, "UTF-8") + linkScheme2));
      } catch (UnsupportedEncodingException e) {
        BugSenseHandler.sendExceptionMessage("Widget4x4Provider", "onReceive", e);
        Crashlytics.setString("Widget4x4Provider", "onReceive");
        Crashlytics.logException(e);

        if (ApplicationContext.DEBUG_MODE) e.printStackTrace();
      }

      browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      browserIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
      context.startActivity(browserIntent);
    } else if (intent.getAction().equals("android.appwidget.action.APPWIDGET_UPDATE")) {
      // ---Update the widget with latest search---
      final AppWidgetManager mgr = AppWidgetManager.getInstance(context);
      onUpdate(context, mgr, appWidgetIds);
    }
    super.onReceive(context, intent);
  }
    public void handleLetterPress(
        KeyEvent event, int keyCode, Device.DeviceType mDeviceType, IBinder windowToken) {
      if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
        // ---Done/Enter button was pressed---
        InputMethodManager keyboard =
            (InputMethodManager)
                ApplicationContext.getInstance().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (keyboard != null) {
          try {
            keyboard.hideSoftInputFromWindow(windowToken, 0);
          } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage(
                "KeyBindings", "KeyEventHandlers.handleLetterPress", e);
            Crashlytics.setString("KeyBindings", "KeyEventHandlers.handleLetterPress");
            Crashlytics.logException(e);

            if (ApplicationContext.DEBUG_MODE) e.printStackTrace();
          }
        }
      } else if (event.getKeyCode() != KeyEvent.KEYCODE_MENU) {
        if (!SearchFragmentTab.ENGLISH_KBD_BACKSPACE) {
          if (mDeviceType == Device.DeviceType.Google_TV) {
            // *---Goog TV custom keys mappings!---
            handleGoogTvKeyPress(event, keyCode);
          } else {
            handleNonGoogTvKeyPress(event, keyCode);
          }
        } else {
          SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false;
        }
      }
    }
Ejemplo n.º 3
0
 private void init() {
   try {
     jsonObject = new JSONObject(this.serverResponse.responseData);
     checkErrors();
     if (!serverResponse.isResponseOk()) {
       jsonObject = null;
     }
   } catch (Exception e) {
     if (SettingsManager.DEBUG()) Log.e(LOG_TAG, "JSONUtility " + e.getMessage());
     if (SettingsManager.DEBUG()) Log.e(LOG_TAG, "JSONUtility :: Failed to parse json");
     Crashlytics.setString("response message", serverResponse.responseMessage);
     Crashlytics.setString("response data", serverResponse.responseData);
     Crashlytics.setInt("response code", serverResponse.code);
     Crashlytics.setString("request url", serverResponse.request);
     Crashlytics.logException(e);
   }
 }
Ejemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Crashlytics
    Fabric.with(this, new Crashlytics());
    Crashlytics.setString("git_sha", BuildConfig.GIT_SHA);
    // Adding Toolbar to Main screen
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Setting ViewPager for each Tabs
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);
    // Set Tabs inside Toolbar
    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
    tabs.setupWithViewPager(viewPager);
    // Create Navigation drawer and inflate layout
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
      supportActionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
      supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
    // Set behavior of Navigation drawer
    navigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          // This method will trigger on item Click of navigation menu
          @Override
          public boolean onNavigationItemSelected(MenuItem menuItem) {
            // Set item in checked state
            menuItem.setChecked(true);

            // TODO: add navigation

            // Closing drawer on item click
            mDrawerLayout.closeDrawers();
            return true;
          }
        });
    // Adding Floating Action Button to bottom right of main view
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Snackbar.make(v, "Snackbar!", Snackbar.LENGTH_LONG).show();
          }
        });
  }
    private void handleGoogTvKeyPress(KeyEvent event, int keyCode) {
      int hash;
      String charLabel = "";

      if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN
          || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP
          || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT
          || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {
        // ---Navigate with DPad---
        Log.i("KeyBindings", event.toString());
      } else {
        if (event.getKeyCode()
            == KeyEvent.KEYCODE_UNKNOWN) { // key was pressed on soft (on-screen) keyboard
          hash = BasicOnKeyboardActionListener.KEY_PRESSED;
          SearchFragmentTab.PHYSICAL_KEY = false;
        } else { // key was pressed on physical keyboard for Goog TV
          SearchFragmentTab.PHYSICAL_KEY = true;
          hash = event.getKeyCode();

          if (event.isLongPress() && event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
            SearchFragmentTab.backSpaceLong();
          }
        }

        switch (hash) {
          case 0: // A letter was pressed on the English keyboard
            SearchFragmentTab.retainSearch();
            break;
        }

        ApplicationContext.getInstance().readyToSearch = true;

        // Russian Keyboard
        if (ApplicationContext.getInstance().keyboardType.equals("Russian")) {
          if (event.getKeyCode()
              == KeyEvent.KEYCODE_UNKNOWN) { // key was pressed on soft (on-screen) keyboard
            charLabel = sparseArrRussian.get(hash);
          } else { // key was pressed on the physical keyboard (for GoogTV)
            charLabel = sparseArrRussian_GoogTV.get(hash);
          }

          // Hybrid Keyboard
        } else if (ApplicationContext.getInstance()
            .keyboardType
            .equals("Hybrid")) { // Hybrid keyboard
          if (ApplicationContext.getInstance()
              .getHybridKeyboardMode()
              .equals("Hybrid_English_To_Russ")) {
            if (event.getKeyCode()
                != KeyEvent
                    .KEYCODE_UNKNOWN) { // key was pressed on the physical keyboard (for GoogTV)
              charLabel = sparseArrHybridEngToRuss_GoogTV.get(hash);
            } else { // key was pressed on the soft (on-screen) keyboard (for GoogTV)
              ApplicationContext.getInstance().readyToSearch = true;
              charLabel = sparseArrHybrid_EngToRuss.get(hash);
            }
          } else if (ApplicationContext.getInstance()
              .getHybridKeyboardMode()
              .equals("Hybrid_Russian_To_Eng")) {
            if (event.getKeyCode()
                != KeyEvent
                    .KEYCODE_UNKNOWN) { // key was pressed on the physical keyboard (for GoogTV)
              charLabel = sparseArrHybrid_RussToEng_GoogTV.get(hash);
            } else { // key was pressed on the soft (on-screen) keyboard (for GoogTV)
              ApplicationContext.getInstance().readyToSearch = true;
              charLabel = sparseArrHybrid_RussToEng.get(hash);
            }
          }
        }

        // English Keyboard
        else if (ApplicationContext.getInstance().keyboardType.equals("English")) {
          try {
            charLabel = sparseArrEnglish.get(hash);
          } catch (Exception e) {
            BugSenseHandler.addCrashExtraData(
                "KeyBindings", "Exception in dispatchKeyEvent: " + e.getMessage());
            BugSenseHandler.leaveBreadcrumb("KeyBindings.keyboardType.equals(\"English\")");
            BugSenseHandler.sendException(e);
            Crashlytics.setString("KeyBindings", "keyboardType.equals(\"English\")");
            Crashlytics.logException(e);
          }
        }

        if (event.getKeyCode()
            != KeyEvent.KEYCODE_UNKNOWN) { // physical key was pressed on physical GoogTV keyboard
          if (event.getAction() == KeyEvent.ACTION_UP) {
            if (keyCode == KeyEvent.KEYCODE_DEL) {
              SearchFragmentTab.backSpace(true);
            } else {
              if (event.getAction() == KeyEvent.ACTION_UP)
                if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                  Intent intent = new Intent("key_bindings_event");
                  intent.putExtra("message", "onBackPressed");
                  LocalBroadcastManager.getInstance(ApplicationContext.getInstance())
                      .sendBroadcast(intent);
                } else {
                  SearchFragmentTab.typeText(charLabel);
                  // ---keep track of key presses to avoid double-typing on Goog TV---
                  SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false;
                }
            }
          }
        } else { // soft input key was pressed on IMM keyboard
          SearchFragmentTab.typeText(charLabel);
          SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false;
        }
      }
    }
    /** Keyboard event processing for non-Google TV devices */
    private void handleNonGoogTvKeyPress(KeyEvent event, int keyCode) {
      int hash;
      String charLabel = "";

      hash = BasicOnKeyboardActionListener.KEY_PRESSED;
      if (hash == 3) {
        // Space key
        try {
          SearchFragmentTab.typeText(" ");
          SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false;
        } catch (Exception e) {
          BugSenseHandler.addCrashExtraData(
              "KeyBindings", "dispatchKeyEvent (not google tv)" + e.getMessage());
          BugSenseHandler.leaveBreadcrumb("KeyBindings.handleNonGoogTvKeyPress");
          BugSenseHandler.sendException(e);
          Crashlytics.setString("KeyBindings", "dispatchKeyEvent (not google tv)");
          Crashlytics.logException(e);
        }
      } else if (hash == 591) {
        // Shift button was pressed on the Russian keyboard
        // do what?
      } else if (hash == 0) {
        // ---A letter was pressed on the English keyboard---
        SearchFragmentTab.retainSearch();
      } else {
        // ---Regular key was pressed---
        ApplicationContext.getInstance().readyToSearch = true;

        if (ApplicationContext.getInstance().keyboardType.equals("Russian")) {
          charLabel = sparseArrRussian.get(hash);
        } else if (ApplicationContext.getInstance().keyboardType.equals("Hybrid")) {
          if (ApplicationContext.getInstance()
              .getHybridKeyboardMode()
              .equals("Hybrid_English_To_Russ")) {
            charLabel = sparseArrHybrid_EngToRuss.get(hash);
          } else if (ApplicationContext.getInstance()
              .getHybridKeyboardMode()
              .equals("Hybrid_Russian_To_Eng")) {
            charLabel = sparseArrHybrid_RussToEng.get(hash);
          }
        } else if (ApplicationContext.getInstance().keyboardType.equals("English")) {
          try {
            if (sparseArrEnglish != null) charLabel = sparseArrEnglish.get(hash);
          } catch (Exception e) {
            BugSenseHandler.addCrashExtraData(
                "KeyBindings", "regular key was pressed" + e.getMessage());
            BugSenseHandler.leaveBreadcrumb("KeyBindings.handleNonGoogTvKeyPress");
            BugSenseHandler.sendException(e);
            Crashlytics.setString("KeyBindings", "regular key was pressed");
            Crashlytics.logException(e);
          }
        }

        if (keyCode != KeyEvent.KEYCODE_BACK
            && keyCode != KeyEvent.KEYCODE_POWER
            && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN) {
          if (keyCode == KeyEvent.KEYCODE_DEL) {
            SearchFragmentTab.backSpace(true);
          } else {
            SearchFragmentTab.typeText(charLabel);
          }
        }
        SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false;
      }
    }
Ejemplo n.º 7
0
 /**
  * Upload the customized string information to fabric
  *
  * @param key The information mapping key.
  * @param str The information value of mapping key.
  */
 public static void logString(String key, String str) {
   Crashlytics.setString(key, str);
 }
Ejemplo n.º 8
0
 public static void setString(String key, String string) {
   Crashlytics.setString(key, string);
 }
 @Override
 public void call(JSONArray args) throws JSONException {
   Crashlytics.setString(args.getString(0), args.getString(1));
 }