private boolean handleResolveInfo(
      ResolveInfo resolveInfo, String urlAsString, long urlLoadStartTime) {
    if (Settings.get().didRecentlyRedirectToApp(urlAsString)) {
      return false;
    }

    boolean isLinkBubble =
        resolveInfo.activityInfo != null
            && resolveInfo.activityInfo.packageName.equals(mAppPackageName);
    if (isLinkBubble == false
        && MainApplication.loadResolveInfoIntent(mContext, resolveInfo, urlAsString, -1)) {
      if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
        finish();
      }

      String title =
          String.format(
              mContext.getString(R.string.link_loaded_with_app),
              resolveInfo.loadLabel(mContext.getPackageManager()));
      MainApplication.saveUrlInHistory(mContext, resolveInfo, urlAsString, title);
      Settings.get().addRedirectToApp(urlAsString);
      Settings.get()
          .trackLinkLoadTime(
              System.currentTimeMillis() - urlLoadStartTime,
              Settings.LinkLoadType.AppRedirectInstant,
              urlAsString);
      return true;
    }

    return false;
  }
  public static void destroy() {
    if (sInstance == null) {
      throw new RuntimeException("No instance to destroy");
    }

    Settings.get().saveData();

    MainApplication app = (MainApplication) sInstance.mContext.getApplicationContext();
    Bus bus = app.getBus();
    bus.unregister(sInstance);

    if (Settings.get().isIncognitoMode()) {
      CookieManager cookieManager = CookieManager.getInstance();
      if (cookieManager != null && cookieManager.hasCookies()) {
        cookieManager.removeAllCookie();
      }
    }

    if (Constant.PROFILE_FPS) {
      sInstance.mWindowManager.removeView(sInstance.mTextView);
    }
    sInstance.mBubbleDraggable.destroy();
    sInstance.mBubbleFlowDraggable.destroy();
    sInstance.mCanvasView.destroy();
    sInstance.mChoreographer.removeFrameCallback(sInstance);
    sInstance.endAppPolling();
    sInstance = null;
  }
  protected void restoreTab(TabView tab) {
    mBubbleFlowDraggable.restoreTab(tab);
    // Only do this if there's just 1 tab open. Fix #446
    if (getActiveTabCount() == 1) {
      // If the bubble was closed when in BubbleView mode, forcibly reset to Bubble mode
      if (mBubbleDraggable.getCurrentMode() == BubbleDraggable.Mode.BubbleView) {
        mBubbleDraggable.setVisibility(View.VISIBLE);
        collapseBubbleFlow(0);
        mBubbleFlowDraggable.setVisibility(View.GONE);

        // Ensure CanvasView has a valid ContentView
        CurrentTabChangedEvent event = new CurrentTabChangedEvent();
        event.mTab = tab;
        MainApplication.postEvent(mContext, event);

        mBubbleDraggable.snapToBubbleView();
      } else {
        final float bubblePeriod = (float) Constant.BUBBLE_ANIM_TIME / 1000.f;
        final float contentPeriod =
            bubblePeriod
                * 0.666667f; // 0.66667 is the normalized t value when f = 1.0f for overshoot
                             // interpolator of 0.5 tension
        expandBubbleFlow((long) (contentPeriod * 1000), false);
        if (Constant.ACTIVITY_WEBVIEW_RENDERING == false) {
          // No need to do this if above is true because it's already done
          showExpandedActivity();
        }
      }
    } else {
      showBadge(true);
    }
    ++mBubblesLoaded;
  }
 public void onOrientationChanged() {
   Config.init(mContext);
   Settings.get().onOrientationChange();
   mBubbleDraggable.onOrientationChanged();
   mBubbleFlowDraggable.onOrientationChanged();
   MainApplication.postEvent(mContext, mOrientationChangedEvent);
 }
  void updateScreenState(String action) {
    // Log.d(SCREEN_LOCK_TAG, "---" + action);
    CrashTracking.log("BubbleFlowView - updateScreenState(): " + action);

    if (action.equals(Intent.ACTION_SCREEN_OFF)) {
      mScreenOn = false;
      setCanDisplay(false);
      MainApplication.postEvent(mContext, mScreenOffEvent);
    } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
      updateKeyguardLocked();
      mScreenOn = true;
      MainApplication.postEvent(mContext, mScreenOnEvent);
    } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
      setCanDisplay(mHiddenByUser ? false : true);
      MainApplication.postEvent(mContext, mUserPresentEvent);
    }
  }
 public void switchToBubbleView() {
   mCanAutoDisplayLink = false;
   if (MainController.get().getActiveTabCount() > 0) {
     mBubbleDraggable.switchToBubbleView();
   } else {
     // If there's no tabs, ensuring pressing Home will cause the CanvasView to go away. Fix #448
     MainApplication.postEvent(mContext, new MainController.EndCollapseTransitionEvent());
   }
 }
 public void setHiddenByUser(boolean hiddenByUser) {
   if (mHiddenByUser != hiddenByUser) {
     mHiddenByUser = hiddenByUser;
     if (mHiddenByUser) {
       switch (mBubbleDraggable.getCurrentMode()) {
         case ContentView:
           mBubbleDraggable.snapToBubbleView();
           break;
       }
       MainApplication.postEvent(mContext, new HideContentEvent());
       MainApplication.postEvent(mContext, new MainService.ShowUnhideNotificationEvent());
     } else {
       MainApplication.postEvent(
           mContext, new CurrentTabChangedEvent(mBubbleFlowDraggable.getCurrentTab()));
       MainApplication.postEvent(mContext, new MainService.ShowDefaultNotificationEvent());
       MainApplication.postEvent(mContext, new UnhideContentEvent());
     }
     setCanDisplay(!mHiddenByUser);
   }
 }
 @SuppressWarnings("unused")
 @Subscribe
 public void onStateChangedEvent(MainApplication.StateChangedEvent event) {
   closeAllBubbles(false);
   final Vector<String> urls = Settings.get().loadCurrentTabs();
   if (urls.size() > 0) {
     for (String url : urls) {
       MainApplication.openLink(mContext, url, null);
     }
   }
 }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView altezza = (TextView) findViewById(R.id.height);
    TextView altdens = (TextView) findViewById(R.id.heightden);
    TextView larghezza = (TextView) findViewById(R.id.width);
    TextView largdens = (TextView) findViewById(R.id.widthden);
    TextView diagonale = (TextView) findViewById(R.id.inches);

    int actionbarheight = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
      ActionBar bar = getActionBar();

      if (bar != null) actionbarheight = bar.getHeight();
    }

    MainApplication.calculateScreenSizeInInches(getWindowManager(), actionbarheight);

    altezza.setText("Altezza (in pixel) = " + MainApplication.getScreenH());
    altdens.setText(
        "Densità altezza (in pollici) = " + String.valueOf(MainApplication.getScreenDh()));
    larghezza.setText("Larghezza (in pixel) = " + MainApplication.getScreenW());
    largdens.setText(
        "Densità larghezza (in pollici) = " + String.valueOf(MainApplication.getScreenDw()));
    diagonale.setText(
        "Diagonale (in pollici) = " + String.valueOf(MainApplication.getScreen_size_in_inches()));
  }
  private void doExpandBubbleFlow(long time, boolean hideDraggable) {
    mBeginExpandTransitionEvent.mPeriod = time / 1000.0f;

    mBubbleFlowDraggable.setVisibility(View.VISIBLE);
    mSetBubbleFlowGone = false; // cancel any pending operation to set visibility to GONE (see #190)
    mBubbleFlowDraggable.expand(time, mOnBubbleFlowExpandFinishedListener);

    MainApplication.postEvent(mContext, mBeginExpandTransitionEvent);

    if (hideDraggable) {
      mBubbleDraggable.postDelayed(mSetBubbleGoneRunnable, 33);
    }
  }
  public boolean reloadAllTabs(Context context) {
    CrashTracking.log("MainController.reloadAllTabs()");
    boolean reloaded = false;
    closeAllBubbles(false);
    final Vector<String> urls = Settings.get().loadCurrentTabs();
    if (urls.size() > 0) {
      for (String url : urls) {
        MainApplication.openLink(context.getApplicationContext(), url, null);
        reloaded = true;
      }
    }

    return reloaded;
  }
Beispiel #12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (MainApplication.isOnline(getApplicationContext())) {
      setContentView(R.layout.activity_store);

      DataManager.fetchStoreData(
          new DataManager.VolleyCallback() {
            @Override
            public void onSuccess(String result) {
              try {
                data = new JSONObject(result);
                populateStore();
              } catch (JSONException e) {
                e.printStackTrace();
              }
            }
          });
    } else {
      setContentView(R.layout.offline_screen);
      Button retryConnectionButton = (Button) findViewById(R.id.retryConnectionButton);
      retryConnectionButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              if (MainApplication.isOnline(getApplicationContext())) {
                setContentView(R.layout.activity_store);
                DataManager.fetchStoreData(
                    new DataManager.VolleyCallback() {
                      @Override
                      public void onSuccess(String result) {
                        try {
                          data = new JSONObject(result);
                          populateStore();
                        } catch (JSONException e) {
                          e.printStackTrace();
                        }
                      }
                    });
              }
            }
          });
    }
  }
Beispiel #13
0
 public void updateTextViews() {
   TextView storeScoreTextView = (TextView) findViewById(R.id.storeScoreTextView);
   storeScoreTextView.setText(String.valueOf(MainApplication.getScore()));
   TextView storeMoneyTextView = (TextView) findViewById(R.id.storeMoneyTextView);
   storeMoneyTextView.setText(MainApplication.getMoney() + "$");
 }
Beispiel #14
0
 @Override
 public void openFile(ActionEvent evt) {
   // TODO Auto-generated method stub
   main.open_board_design_action(evt);
   this.dispose();
 }
 public void startFileBrowser(String[] acceptTypes, ValueCallback<Uri[]> filePathCallback) {
   MainApplication.postEvent(
       mContext, new ExpandedActivity.ShowFileBrowserEvent(acceptTypes, filePathCallback));
 }
  public boolean closeTab(
      TabView tabView,
      Constant.BubbleAction action,
      boolean animateOff,
      boolean canShowUndoPrompt) {

    if (tabView == null) {
      CrashTracking.log("closeTab attempt on null tabView");
      return false;
    }

    // If the tab is already closing, do nothing. Otherwise we could end up in a weird state,
    // where we attempt to show multiple prompts and crashing upon tab restore.
    if (null == tabView || tabView.mIsClosing == true) {
      CrashTracking.log("Ignoring duplicate tabView close request");
      return false;
    }
    if (null != tabView) {
      tabView.mIsClosing = true;
    } else {
      CrashTracking.log("attempt to access on null tabView");
      return false;
    }

    boolean contentViewShowing = contentViewShowing();
    CrashTracking.log(
        "MainController.closeTab(): action:"
            + action.toString()
            + ", contentViewShowing:"
            + contentViewShowing
            + ", visibleTabCount:"
            + getVisibleTabCount()
            + ", activeTabCount:"
            + getActiveTabCount()
            + ", canShowUndoPrompt:"
            + canShowUndoPrompt
            + ", animateOff:"
            + animateOff
            + ", canShowUndoPrompt:"
            + canShowUndoPrompt);
    if (mBubbleFlowDraggable != null) {
      mBubbleFlowDraggable.closeTab(
          tabView, animateOff, action, tabView != null ? tabView.getTotalTrackedLoadTime() : -1);
    }

    int activeTabCount = getActiveTabCount();
    showBadge(activeTabCount > 1 ? true : false);
    if (activeTabCount == 0) {
      hideBubbleDraggable();
      // Ensure BubbleFlowDraggable gets at least 1 update in the event items are animating off
      // screen. See #237.
      scheduleUpdate();

      MainApplication.postEvent(mContext, mMinimizeExpandedActivityEvent);
    }

    if (tabView == null) {
      CrashTracking.logHandledException(new RuntimeException("tabView = null"));
    } else {
      if (canShowUndoPrompt && Settings.get().getShowUndoCloseTab()) {
        showClosePrompt(tabView);
      } else {
        destroyTabOnDelay(tabView);
      }
    }

    return getActiveTabCount() > 0;
  }
  public TabView openUrl(
      final String urlAsString,
      long urlLoadStartTime,
      final boolean setAsCurrentTab,
      String openedFromAppName) {

    Analytics.trackOpenUrl(openedFromAppName);

    if (wasUrlRecentlyLoaded(urlAsString, urlLoadStartTime)
        && !urlAsString.equals(mContext.getString(R.string.empty_bubble_page))) {
      Toast.makeText(mContext, R.string.duplicate_link_will_not_be_loaded, Toast.LENGTH_SHORT)
          .show();
      return null;
    }

    URL url;
    try {
      url = new URL(urlAsString);
    } catch (MalformedURLException e) { // If this is not a valid scheme, back out. #271
      Toast.makeText(mContext, mContext.getString(R.string.unsupported_scheme), Toast.LENGTH_SHORT)
          .show();
      if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
        finish();
      }
      return null;
    }

    if (Settings.get().redirectUrlToBrowser(url)) {
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setData(Uri.parse(urlAsString));
      intent.setFlags(
          Intent.FLAG_ACTIVITY_NEW_TASK
              | Intent.FLAG_ACTIVITY_CLEAR_TOP
              | Intent.FLAG_ACTIVITY_SINGLE_TOP);
      if (MainApplication.openInBrowser(mContext, intent, false)) {
        if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
          finish();
        }

        String title =
            String.format(
                mContext.getString(R.string.link_redirected),
                Settings.get().getDefaultBrowserLabel());
        MainApplication.saveUrlInHistory(mContext, null, urlAsString, title);
        return null;
      }
    }

    boolean showAppPicker = false;

    PackageManager packageManager = mContext.getPackageManager();
    final List<ResolveInfo> resolveInfos =
        Settings.get().getAppsThatHandleUrl(url.toString(), packageManager);
    ResolveInfo defaultAppResolveInfo = Settings.get().getDefaultAppForUrl(url, resolveInfos);
    if (resolveInfos != null && resolveInfos.size() > 0) {
      if (defaultAppResolveInfo != null) {
        if (handleResolveInfo(defaultAppResolveInfo, urlAsString, urlLoadStartTime)) {
          return null;
        }
      } else if (resolveInfos.size() == 1) {
        if (handleResolveInfo(resolveInfos.get(0), urlAsString, urlLoadStartTime)) {
          return null;
        }
      } else {
        // If LinkBubble is a valid resolve target, do not show other options to open the content.
        for (ResolveInfo info : resolveInfos) {
          if (info.activityInfo.packageName.startsWith("com.linkbubble.playstore")) {
            showAppPicker = false;
            break;
          } else {
            showAppPicker = true;
          }
        }
      }
    }

    boolean openedFromItself = false;
    if (null != openedFromAppName
        && (openedFromAppName.equals(Analytics.OPENED_URL_FROM_NEW_TAB)
            || openedFromAppName.equals(Analytics.OPENED_URL_FROM_HISTORY))) {
      showAppPicker = true;
      openedFromItself = true;
    }
    mCanAutoDisplayLink = true;
    final TabView result =
        openUrlInTab(urlAsString, urlLoadStartTime, setAsCurrentTab, showAppPicker);

    // Show app picker after creating the tab to load so that we have the instance to close if
    // redirecting to an app, re #292.
    if (!openedFromItself
        && showAppPicker
        && MainApplication.sShowingAppPickerDialog == false
        && 0 != resolveInfos.size()) {
      AlertDialog dialog =
          ActionItem.getActionItemPickerAlert(
              mContext,
              resolveInfos,
              R.string.pick_default_app,
              new ActionItem.OnActionItemDefaultSelectedListener() {
                @Override
                public void onSelected(ActionItem actionItem, boolean always) {
                  boolean loaded = false;
                  for (ResolveInfo resolveInfo : resolveInfos) {
                    if (resolveInfo.activityInfo.packageName.equals(actionItem.mPackageName)
                        && resolveInfo.activityInfo.name.equals(actionItem.mActivityClassName)) {
                      if (always) {
                        Settings.get().setDefaultApp(urlAsString, resolveInfo);
                      }

                      // Jump out of the loop and load directly via a BubbleView below
                      if (resolveInfo.activityInfo.packageName.equals(mAppPackageName)) {
                        break;
                      }

                      loaded =
                          MainApplication.loadIntent(
                              mContext,
                              actionItem.mPackageName,
                              actionItem.mActivityClassName,
                              urlAsString,
                              -1,
                              true);
                      break;
                    }
                  }

                  if (loaded) {
                    Settings.get().addRedirectToApp(urlAsString);
                    closeTab(result, contentViewShowing(), false);
                    if (getActiveTabCount() == 0 && Prompt.isShowing() == false) {
                      finish();
                    }
                    // L_WATCH: L currently lacks getRecentTasks(), so minimize here
                    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
                      MainController.get().switchToBubbleView();
                    }
                  }
                }
              });

      dialog.setOnDismissListener(
          new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
              MainApplication.sShowingAppPickerDialog = false;
            }
          });

      dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
      Util.showThemedDialog(dialog);
      MainApplication.sShowingAppPickerDialog = true;
    }

    return result;
  }
Beispiel #18
0
  @Override
  public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Bundle bundle = intent.getExtras();
    Log.e("NaviGuidanceReceiver", action);
    if (action.equals(ACTION)) {

      if (bundle != null) {

        int type = bundle.getInt(ACTION_TYPE);

        switch (type) {
          case MSG_ID_GUIDANCEINFO:
            stringArray = bundle.getStringArray(GUIDANCE_ARRAY_PARAM);
            Log.e("NaviGuidanceReceiver", stringArray[0]);
            if (ScrrenoffActivity.screen != null) {
              // ScrrenoffActivity.screen.currentRoad.setText(stringArray[6]);
              ScrrenoffActivity.screen.nextRoad.setText(stringArray[7]);
              long next_road_distance = Long.parseLong(stringArray[1]);
              int road_icon = Integer.parseInt(stringArray[0]);
              switch (road_icon) {
                case 0:
                  ScrrenoffActivity.screen.maneuverImage.setBackgroundResource(R.drawable.ar_1);
                  break;
                case 1:
                  ScrrenoffActivity.screen.maneuverImage.setBackgroundResource(R.drawable.ar_5);
                  break;
                case 2:
                  ScrrenoffActivity.screen.maneuverImage.setBackgroundResource(R.drawable.ar_3);
                  break;
                case 4:
                  ScrrenoffActivity.screen.maneuverImage.setBackgroundResource(R.drawable.ar_8);
                  break;
                case 5:
                  ScrrenoffActivity.screen.maneuverImage.setBackgroundResource(R.drawable.ar_2);
                  break;
                case 6:
                  ScrrenoffActivity.screen.maneuverImage.setBackgroundResource(R.drawable.ar_4);
                  break;
                default:
                  ScrrenoffActivity.screen.maneuverImage.setBackgroundResource(R.drawable.ar_1);
                  break;
              }
              ScrrenoffActivity.screen.distanceText.setText(
                  GaoDeBroadCast.getDidistance((int) next_road_distance));
              long total_remain_distance = Long.parseLong(stringArray[2]);
              long arrived_time = Long.parseLong(stringArray[4]);
              ScrrenoffActivity.screen.remainDistanceText.setText(
                  GaoDeBroadCast.getRemainDidistance(
                      (int) total_remain_distance, System.currentTimeMillis() + arrived_time));
              MainApplication.gaodeisnavi = true;
              MainApplication.getHander().removeMessages(2);
              MainApplication.getHander().sendEmptyMessageDelayed(2, 20000);
            }
            break;

          default:
            break;
        }
      }
    }
  }
  protected MainController(Context context, EventHandler eventHandler) {
    Util.Assert(sInstance == null, "non-null instance");
    sInstance = this;
    mContext = context;
    mAppPackageName = mContext.getPackageName();
    mEventHandler = eventHandler;

    mAppPoller = new AppPoller(context);
    mAppPoller.setListener(mAppPollerListener);

    mCanAutoDisplayLink = true;

    mCanDisplay = true;

    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    if (Constant.PROFILE_FPS) {
      mTextView = new TextView(mContext);
      mTextView.setTextColor(0xff00ffff);
      mTextView.setTextSize(32.0f);
      mWindowManagerParams.gravity = Gravity.TOP | Gravity.LEFT;
      mWindowManagerParams.x = 500;
      mWindowManagerParams.y = 16;
      mWindowManagerParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
      mWindowManagerParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
      mWindowManagerParams.type = WindowManager.LayoutParams.TYPE_PHONE;
      mWindowManagerParams.flags =
          WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
              | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
      mWindowManagerParams.format = PixelFormat.TRANSPARENT;
      mWindowManagerParams.setTitle("LinkBubble: Debug Text");
      mWindowManager.addView(mTextView, mWindowManagerParams);
    }

    mUpdateScheduled = false;
    mChoreographer = Choreographer.getInstance();
    mCanvasView = new CanvasView(mContext);

    MainApplication app = (MainApplication) mContext.getApplicationContext();
    Bus bus = app.getBus();
    bus.register(this);

    updateIncognitoMode(Settings.get().isIncognitoMode());

    LayoutInflater inflater = LayoutInflater.from(mContext);

    mBubbleDraggable = (BubbleDraggable) inflater.inflate(R.layout.view_bubble_draggable, null);
    Point bubbleRestingPoint = Settings.get().getBubbleRestingPoint();
    int fromX = Settings.get().getBubbleStartingX(bubbleRestingPoint);
    mBubbleDraggable.configure(
        fromX,
        bubbleRestingPoint.y,
        bubbleRestingPoint.x,
        bubbleRestingPoint.y,
        Constant.BUBBLE_SLIDE_ON_SCREEN_TIME,
        mCanvasView);

    mBubbleDraggable.setOnUpdateListener(
        new BubbleDraggable.OnUpdateListener() {
          @Override
          public void onUpdate(Draggable draggable, float dt) {
            if (!draggable.isDragging()) {
              mBubbleFlowDraggable.syncWithBubble(draggable);
            }
          }
        });

    mBubbleFlowDraggable = (BubbleFlowDraggable) inflater.inflate(R.layout.view_bubble_flow, null);
    mBubbleFlowDraggable.configure(null);
    mBubbleFlowDraggable.collapse(0, null);
    mBubbleFlowDraggable.setBubbleDraggable(mBubbleDraggable);
    mBubbleFlowDraggable.setVisibility(View.GONE);

    mBubbleDraggable.setBubbleFlowDraggable(mBubbleFlowDraggable);
  }