コード例 #1
0
  static Rect getWidgetSizeRanges(Launcher launcher, int spanX, int spanY, Rect rect) {
    if (rect == null) {
      rect = new Rect();
    }
    Rect landMetrics = Workspace.getCellLayoutMetrics(launcher, CellLayout.LANDSCAPE);
    Rect portMetrics = Workspace.getCellLayoutMetrics(launcher, CellLayout.PORTRAIT);
    final float density = launcher.getResources().getDisplayMetrics().density;

    // Compute landscape size
    int cellWidth = landMetrics.left;
    int cellHeight = landMetrics.top;
    int widthGap = landMetrics.right;
    int heightGap = landMetrics.bottom;
    int landWidth = (int) ((spanX * cellWidth + (spanX - 1) * widthGap) / density);
    int landHeight = (int) ((spanY * cellHeight + (spanY - 1) * heightGap) / density);

    // Compute portrait size
    cellWidth = portMetrics.left;
    cellHeight = portMetrics.top;
    widthGap = portMetrics.right;
    heightGap = portMetrics.bottom;
    int portWidth = (int) ((spanX * cellWidth + (spanX - 1) * widthGap) / density);
    int portHeight = (int) ((spanY * cellHeight + (spanY - 1) * heightGap) / density);
    rect.set(portWidth, landHeight, landWidth, portHeight);
    return rect;
  }
コード例 #2
0
  /**
   * Used to create a new DragLayer from XML.
   *
   * @param context The application's context.
   */
  public DragController(Launcher launcher) {
    Resources r = launcher.getResources();
    mLauncher = launcher;
    mHandler = new Handler();
    mScrollZone = r.getDimensionPixelSize(R.dimen.scroll_zone);
    mVelocityTracker = VelocityTracker.obtain();

    float density = r.getDisplayMetrics().density;
    mFlingToDeleteThresholdVelocity =
        (int) (r.getInteger(R.integer.config_flingToDeleteMinVelocity) * density);
  }
コード例 #3
0
  public AddAdapter(Launcher launcher) {
    super();

    mInflater = (LayoutInflater) launcher.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Create default actions
    Resources res = launcher.getResources();

    mItems.add(
        new ListItem(
            res, R.string.group_wallpapers, R.mipmap.ic_launcher_wallpaper, ITEM_WALLPAPER));
  }
コード例 #4
0
ファイル: FolderIcon.java プロジェクト: newstein/tpep
    public FolderRingAnimator(Launcher launcher, FolderIcon folderIcon) {
      mFolderIcon = folderIcon;
      Resources res = launcher.getResources();
      mOuterRingDrawable = res.getDrawable(R.drawable.portal_ring_outer_holo);
      mInnerRingDrawable = res.getDrawable(R.drawable.portal_ring_inner_holo);

      // We need to reload the static values when configuration changes in case they are
      // different in another configuration
      if (sStaticValuesDirty) {
        sPreviewSize = res.getDimensionPixelSize(R.dimen.folder_preview_size);
        sPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
        sSharedOuterRingDrawable = res.getDrawable(R.drawable.portal_ring_outer_holo);
        sSharedInnerRingDrawable = res.getDrawable(R.drawable.portal_ring_inner_holo);
        sSharedFolderLeaveBehind = res.getDrawable(R.drawable.portal_ring_rest);
        sStaticValuesDirty = false;
      }
    }
コード例 #5
0
ファイル: FolderIcon.java プロジェクト: wolfsky/KLauncher
  static FolderIcon fromXml(
      int resId, Launcher launcher, ViewGroup group, UserFolderInfo folderInfo) {

    FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false);

    final Resources resources = launcher.getResources();
    Drawable d = resources.getDrawable(R.drawable.ic_launcher_folder);
    d = Utilities.createIconThumbnail(d, launcher);
    icon.mCloseIcon = d;
    icon.mOpenIcon = resources.getDrawable(R.drawable.ic_launcher_folder_open);
    icon.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
    icon.setText(folderInfo.title);
    icon.setTag(folderInfo);
    icon.setOnClickListener(launcher);
    icon.mInfo = folderInfo;
    icon.mLauncher = launcher;

    return icon;
  }
コード例 #6
0
ファイル: AddAdapter.java プロジェクト: Raly123/Launcher
  public AddAdapter(Launcher launcher) {
    super();

    mInflater = (LayoutInflater) launcher.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Create default actions
    Resources res = launcher.getResources();

    mItems.add(
        new ListItem(
            res, R.string.group_shortcuts, R.drawable.ic_launcher_shortcut, ITEM_SHORTCUT));

    mItems.add(
        new ListItem(
            res, R.string.group_widgets, R.drawable.ic_launcher_appwidget, ITEM_APPWIDGET));

    mItems.add(
        new ListItem(
            res, R.string.group_live_folders, R.drawable.ic_launcher_add_folder, ITEM_LIVE_FOLDER));

    mItems.add(
        new ListItem(
            res, R.string.group_wallpapers, R.drawable.ic_launcher_wallpaper, ITEM_WALLPAPER));
  }
コード例 #7
0
  public void showLongPressCling(boolean showWelcome) {
    ViewGroup root = (ViewGroup) mLauncher.findViewById(R.id.launcher);
    View cling = mInflater.inflate(R.layout.longpress_cling, root, false);

    cling.setOnLongClickListener(
        new OnLongClickListener() {

          @Override
          public boolean onLongClick(View v) {
            mLauncher.getWorkspace().enterOverviewMode();
            dismissLongPressCling();
            return true;
          }
        });

    final ViewGroup content = (ViewGroup) cling.findViewById(R.id.cling_content);
    mInflater.inflate(
        showWelcome ? R.layout.longpress_cling_welcome_content : R.layout.longpress_cling_content,
        content);
    content.findViewById(R.id.cling_dismiss_longpress_info).setOnClickListener(this);

    if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) {
      Drawable bg =
          new BorderCropDrawable(
              mLauncher.getResources().getDrawable(R.drawable.cling_bg), true, true, true, false);
      content.setBackground(bg);
    }

    root.addView(cling);

    if (showWelcome) {
      // This is the first cling being shown. No need to animate.
      return;
    }

    // Animate
    content
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {

              @Override
              public void onGlobalLayout() {
                content.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                ObjectAnimator anim;
                if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) {
                  content.setTranslationY(-content.getMeasuredHeight());
                  anim = LauncherAnimUtils.ofFloat(content, "translationY", 0);
                } else {
                  content.setScaleX(0);
                  content.setScaleY(0);
                  PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1);
                  PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1);
                  anim = LauncherAnimUtils.ofPropertyValuesHolder(content, scaleX, scaleY);
                }

                anim.setDuration(SHOW_CLING_DURATION);
                anim.setInterpolator(new LogDecelerateInterpolator(100, 0));
                anim.start();
              }
            });
  }
コード例 #8
0
  public AppWidgetResizeFrame(
      Context context,
      LauncherAppWidgetHostView widgetView,
      CellLayout cellLayout,
      DragLayer dragLayer) {

    super(context);
    mLauncher = (Launcher) context;
    mCellLayout = cellLayout;
    mWidgetView = widgetView;
    mResizeMode = widgetView.getAppWidgetInfo().resizeMode;
    mDragLayer = dragLayer;

    final AppWidgetProviderInfo info = widgetView.getAppWidgetInfo();
    int[] result = Launcher.getMinSpanForWidget(mLauncher, info);
    mMinHSpan = result[0];
    mMinVSpan = result[1];

    setBackgroundResource(R.drawable.widget_resize_frame_holo);
    setPadding(0, 0, 0, 0);

    LayoutParams lp;
    mLeftHandle = new ImageView(context);
    mLeftHandle.setImageResource(R.drawable.widget_resize_handle_left);
    lp =
        new LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            Gravity.LEFT | Gravity.CENTER_VERTICAL);
    addView(mLeftHandle, lp);

    mRightHandle = new ImageView(context);
    mRightHandle.setImageResource(R.drawable.widget_resize_handle_right);
    lp =
        new LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            Gravity.RIGHT | Gravity.CENTER_VERTICAL);
    addView(mRightHandle, lp);

    mTopHandle = new ImageView(context);
    mTopHandle.setImageResource(R.drawable.widget_resize_handle_top);
    lp =
        new LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            Gravity.CENTER_HORIZONTAL | Gravity.TOP);
    addView(mTopHandle, lp);

    mBottomHandle = new ImageView(context);
    mBottomHandle.setImageResource(R.drawable.widget_resize_handle_bottom);
    lp =
        new LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    addView(mBottomHandle, lp);

    Rect p =
        AppWidgetHostView.getDefaultPaddingForWidget(
            context, widgetView.getAppWidgetInfo().provider, null);
    mWidgetPaddingLeft = p.left;
    mWidgetPaddingTop = p.top;
    mWidgetPaddingRight = p.right;
    mWidgetPaddingBottom = p.bottom;

    if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) {
      mTopHandle.setVisibility(GONE);
      mBottomHandle.setVisibility(GONE);
    } else if (mResizeMode == AppWidgetProviderInfo.RESIZE_VERTICAL) {
      mLeftHandle.setVisibility(GONE);
      mRightHandle.setVisibility(GONE);
    }

    final float density = mLauncher.getResources().getDisplayMetrics().density;
    mBackgroundPadding = (int) Math.ceil(density * BACKGROUND_PADDING);
    mTouchTargetWidth = 2 * mBackgroundPadding;

    // When we create the resize frame, we first mark all cells as unoccupied. The appropriate
    // cells (same if not resized, or different) will be marked as occupied when the resize
    // frame is dismissed.
    mCellLayout.markCellsAsUnoccupiedForView(mWidgetView);
  }
コード例 #9
0
  public void layout(Launcher launcher) {
    FrameLayout.LayoutParams lp;
    Resources res = launcher.getResources();
    boolean hasVerticalBarLayout = isVerticalBarLayout();

    // Layout the search bar space
    View searchBar = launcher.getSearchBar();
    lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
    if (hasVerticalBarLayout) {
      // Vertical search bar space
      lp.gravity = Gravity.TOP | Gravity.LEFT;
      lp.width = searchBarSpaceHeightPx;
      lp.height = LayoutParams.WRAP_CONTENT;

      LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar);
      targets.setOrientation(LinearLayout.VERTICAL);
    } else {
      // Horizontal search bar space
      lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
      lp.width = searchBarSpaceWidthPx;
      lp.height = searchBarSpaceHeightPx;
    }
    searchBar.setLayoutParams(lp);

    // Layout the workspace
    PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
    lp = (FrameLayout.LayoutParams) workspace.getLayoutParams();
    lp.gravity = Gravity.CENTER;
    int orientation = isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT;
    Rect padding = getWorkspacePadding(orientation);
    workspace.setLayoutParams(lp);
    workspace.setPadding(padding.left, padding.top, padding.right, padding.bottom);
    workspace.setPageSpacing(getWorkspacePageSpacing(orientation));

    // Layout the hotseat
    View hotseat = launcher.findViewById(R.id.hotseat);
    lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
    if (hasVerticalBarLayout) {
      // Vertical hotseat
      lp.gravity = Gravity.END;
      lp.width = hotseatBarHeightPx;
      lp.height = LayoutParams.MATCH_PARENT;
      hotseat.findViewById(R.id.layout).setPadding(0, 2 * edgeMarginPx, 0, 2 * edgeMarginPx);
    } else if (isTablet()) {
      // Pad the hotseat with the workspace padding calculated above
      lp.gravity = Gravity.BOTTOM;
      lp.width = LayoutParams.MATCH_PARENT;
      lp.height = hotseatBarHeightPx;
      hotseat.setPadding(
          edgeMarginPx + padding.left, 0, edgeMarginPx + padding.right, 2 * edgeMarginPx);
    } else {
      // For phones, layout the hotseat without any bottom margin
      // to ensure that we have space for the folders
      lp.gravity = Gravity.BOTTOM;
      lp.width = LayoutParams.MATCH_PARENT;
      lp.height = hotseatBarHeightPx;
      hotseat.findViewById(R.id.layout).setPadding(2 * edgeMarginPx, 0, 2 * edgeMarginPx, 0);
    }
    hotseat.setLayoutParams(lp);

    // Layout the page indicators
    View pageIndicator = launcher.findViewById(R.id.page_indicator);
    if (pageIndicator != null) {
      if (hasVerticalBarLayout) {
        // Hide the page indicators when we have vertical search/hotseat
        pageIndicator.setVisibility(View.GONE);
      } else {
        // Put the page indicators above the hotseat
        lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
        lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
        lp.width = LayoutParams.WRAP_CONTENT;
        lp.height = LayoutParams.WRAP_CONTENT;
        lp.bottomMargin = hotseatBarHeightPx;
        pageIndicator.setLayoutParams(lp);
      }
    }

    // Layout AllApps
    AppsCustomizeTabHost host =
        (AppsCustomizeTabHost) launcher.findViewById(R.id.apps_customize_pane);
    if (host != null) {
      // Center the all apps page indicator
      int pageIndicatorHeight =
          (int)
              (pageIndicatorHeightPx
                  * Math.min(1f, (allAppsIconSizePx / DynamicGrid.DEFAULT_ICON_SIZE_PX)));
      pageIndicator = host.findViewById(R.id.apps_customize_page_indicator);
      if (pageIndicator != null) {
        LinearLayout.LayoutParams lllp =
            (LinearLayout.LayoutParams) pageIndicator.getLayoutParams();
        lllp.width = LayoutParams.WRAP_CONTENT;
        lllp.height = pageIndicatorHeight;
        pageIndicator.setLayoutParams(lllp);
      }

      AppsCustomizePagedView pagedView =
          (AppsCustomizePagedView) host.findViewById(R.id.apps_customize_pane_content);

      FrameLayout fakePageContainer = (FrameLayout) host.findViewById(R.id.fake_page_container);
      FrameLayout fakePage = (FrameLayout) host.findViewById(R.id.fake_page);

      padding = new Rect();
      if (pagedView != null) {
        // Constrain the dimensions of all apps so that it does not span the full width
        int paddingLR =
            (availableWidthPx - (allAppsCellWidthPx * allAppsNumCols)) / (2 * (allAppsNumCols + 1));
        int paddingTB =
            (availableHeightPx - (allAppsCellHeightPx * allAppsNumRows))
                / (2 * (allAppsNumRows + 1));
        paddingLR = Math.min(paddingLR, (int) ((paddingLR + paddingTB) * 0.75f));
        paddingTB = Math.min(paddingTB, (int) ((paddingLR + paddingTB) * 0.75f));
        int maxAllAppsWidth = (allAppsNumCols * (allAppsCellWidthPx + 2 * paddingLR));
        int gridPaddingLR = (availableWidthPx - maxAllAppsWidth) / 2;
        // Only adjust the side paddings on landscape phones, or tablets
        if ((isTablet() || isLandscape) && gridPaddingLR > (allAppsCellWidthPx / 4)) {
          padding.left = padding.right = gridPaddingLR;
        }

        // The icons are centered, so we can't just offset by the page indicator height
        // because the empty space will actually be pageIndicatorHeight + paddingTB
        padding.bottom = Math.max(0, pageIndicatorHeight - paddingTB);

        pagedView.setWidgetsPageIndicatorPadding(pageIndicatorHeight);
        fakePage.setBackground(res.getDrawable(R.drawable.quantum_panel));

        // Horizontal padding for the whole paged view
        int pagedFixedViewPadding =
            res.getDimensionPixelSize(R.dimen.apps_customize_horizontal_padding);

        padding.left += pagedFixedViewPadding;
        padding.right += pagedFixedViewPadding;

        pagedView.setPadding(padding.left, padding.top, padding.right, padding.bottom);
        fakePageContainer.setPadding(padding.left, padding.top, padding.right, padding.bottom);
      }
    }

    // Layout the Overview Mode
    ViewGroup overviewMode = launcher.getOverviewPanel();
    if (overviewMode != null) {
      Rect r = getOverviewModeButtonBarRect();
      lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
      lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;

      int visibleChildCount = getVisibleChildCount(overviewMode);
      int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
      int maxWidth = totalItemWidth + (visibleChildCount - 1) * overviewModeBarSpacerWidthPx;

      lp.width = Math.min(availableWidthPx, maxWidth);
      lp.height = r.height();
      overviewMode.setLayoutParams(lp);

      if (lp.width > totalItemWidth && visibleChildCount > 1) {
        // We have enough space. Lets add some margin too.
        int margin = (lp.width - totalItemWidth) / (visibleChildCount - 1);
        View lastChild = null;

        // Set margin of all visible children except the last visible child
        for (int i = 0; i < visibleChildCount; i++) {
          if (lastChild != null) {
            MarginLayoutParams clp = (MarginLayoutParams) lastChild.getLayoutParams();
            if (isLayoutRtl) {
              clp.leftMargin = margin;
            } else {
              clp.rightMargin = margin;
            }
            lastChild.setLayoutParams(clp);
            lastChild = null;
          }
          View thisChild = overviewMode.getChildAt(i);
          if (thisChild.getVisibility() != View.GONE) {
            lastChild = thisChild;
          }
        }
      }
    }
  }