예제 #1
0
  Description parseValue(TypedValue value) {
    Description d = new Description();
    if (value == null) {
      d.type = ABSOLUTE;
      d.value = 0;
    } else {
      if (value.type == TypedValue.TYPE_FRACTION) {
        d.type =
            (value.data & TypedValue.COMPLEX_UNIT_MASK) == TypedValue.COMPLEX_UNIT_FRACTION_PARENT
                ? RELATIVE_TO_PARENT
                : RELATIVE_TO_SELF;
        d.value = TypedValue.complexToFloat(value.data);
        return d;
      } else if (value.type == TypedValue.TYPE_FLOAT) {
        d.type = ABSOLUTE;
        d.value = value.getFloat();
        return d;
      } else if (value.type >= TypedValue.TYPE_FIRST_INT
          && value.type <= TypedValue.TYPE_LAST_INT) {
        d.type = ABSOLUTE;
        d.value = value.data;
        return d;
      }
    }

    d.type = ABSOLUTE;
    d.value = 0.0f;

    return d;
  }
예제 #2
0
  public LcSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

    super(context, attrs, defStyleAttr);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.lc_search_view, this, true);
    mSearchTrack = findViewById(R.id.lc_search_plate);
    mTitleIcon = (ImageView) findViewById(R.id.lc_search_icon);
    mEditorTextView = (SearchAutoComplete) findViewById(R.id.lc_search_src_text);
    mClearBtn = (ImageView) findViewById(R.id.lc_search_clear_btn);
    mCancelTextView = (TextView) findViewById(R.id.lc_search_text_cancel);

    mTitleIcon.setOnClickListener(mOnClickListener);
    mClearBtn.setOnClickListener(mOnClickListener);
    mCancelTextView.setOnClickListener(mOnClickListener);
    mEditorTextView.setOnClickListener(mOnClickListener);
    mEditorTextView.setOnEditorActionListener(mOnEditorActionListener);
    mEditorTextView.setOnItemClickListener(mOnItemClickListener);
    mEditorTextView.addTextChangedListener(mTextWatcher);
    mEditorTextView.setSearchView(this);
    mEditorTextView.ensureImeVisible(true);
    // Inform any listener of focus changes
    mEditorTextView.setOnFocusChangeListener(
        new OnFocusChangeListener() {
          public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
              mTitleIcon.setAlpha(unfocusAlpha);
              mEditorTextView.setAlpha(unfocusAlpha);
            } else {
              mTitleIcon.setAlpha(1.0f);
              mEditorTextView.setAlpha(1.0f);
            }

            if (mOnTextFocusChangeListener != null) {
              mOnTextFocusChangeListener.onFocusChange(LcSearchView.this, hasFocus);
            }
          }
        });

    mDropDownAnchor = findViewById(mEditorTextView.getDropDownAnchor());
    if (mDropDownAnchor != null) {
      mDropDownAnchor.addOnLayoutChangeListener(
          new OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(
                View v,
                int left,
                int top,
                int right,
                int bottom,
                int oldLeft,
                int oldTop,
                int oldRight,
                int oldBottom) {
              adjustDropDownSizeAndPosition();
            }
          });
    }

    int maxWidth = -1;
    CharSequence cancelText = null;
    CharSequence queryHintText = null;
    int clearBtnResId = R.drawable.lc_icon_search_view_clear_light;
    int titleIconId = R.drawable.lc_icon_search_view_search_light;
    int searchBgId = R.drawable.lc_selector_search_view_frame_light;
    int imeOptions = -1;
    int inputType = -1;
    boolean focusable = true;

    final Resources res = getResources();

    TypedValue out = new TypedValue();
    res.getValue(R.dimen.lc_search_view_default_text_alpha, out, true);
    unfocusAlpha = out.getFloat();

    int queryTextSize = res.getDimensionPixelSize(R.dimen.lc_default_search_query_text_size);
    ColorStateList queryTextColor =
        res.getColorStateList(R.color.lc_search_view_query_text_color_light);
    ColorStateList queryHintTextColor =
        res.getColorStateList(R.color.lc_search_view_query_hint_text_color_light);
    int cancelTextSize = res.getDimensionPixelSize(R.dimen.lc_default_search_query_text_size);
    ColorStateList cancelTextColor = null;

    int mTrackMarginLeft = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_left);
    mTrackMarginRight = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_right);
    int mTrackMarginTop = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_top);
    int mTrackMarginBottom = res.getDimensionPixelSize(R.dimen.lc_search_track_margin_bottom);
    int mTrackPaddingLeft = res.getDimensionPixelSize(R.dimen.lc_search_track_padding_left);
    int mTrackPaddingRight = res.getDimensionPixelSize(R.dimen.lc_search_track_padding_right);

    mMatchColor = res.getColor(R.color.lc_search_view_drop_down_match_text_color_light);
    mCursorResId = R.drawable.lc_shape_search_view_cursor_light;
    mDropDownBg = res.getDrawable(R.drawable.lc_search_drop_down_bg);
    mDropDownBlurRadius = 10;
    mPopupItemLayoutResId = R.layout.lc_search_dropdown_item_icons_2line_light;
    mAlwaysShowCancel = true;
    Drawable popupDivider = res.getDrawable(R.drawable.lc_search_drop_down_divider);

    TypedArray a =
        context.obtainStyledAttributes(attrs, R.styleable.LcSearchView, defStyleAttr, defStyleRes);

    a.getValue(R.styleable.LcSearchView_lcSearchUnfocusAlpha, out);
    unfocusAlpha = out.getFloat();

    queryTextSize =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcQueryTextSize, queryTextSize);
    cancelTextSize =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcCancelTextSize, cancelTextSize);
    if (a.hasValue(R.styleable.LcSearchView_lcQueryTextColor)) {
      queryTextColor = a.getColorStateList(R.styleable.LcSearchView_lcQueryTextColor);
    }

    if (a.hasValue(R.styleable.LcSearchView_lcQueryHintColor)) {
      queryHintTextColor = a.getColorStateList(R.styleable.LcSearchView_lcQueryHintColor);
    }
    if (a.hasValue(R.styleable.LcSearchView_lcCancelTextColor)) {
      cancelTextColor = a.getColorStateList(R.styleable.LcSearchView_lcCancelTextColor);
    } else {
      cancelTextColor = queryTextColor;
    }

    mTrackMarginBottom =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginBottom, mTrackMarginBottom);
    mTrackMarginLeft =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginLeft, mTrackMarginLeft);
    mTrackMarginRight =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginRight, mTrackMarginRight);
    mTrackMarginTop =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcInputMarginTop, mTrackMarginTop);

    maxWidth = a.getDimensionPixelSize(R.styleable.LcSearchView_android_maxWidth, maxWidth);
    queryHintText = a.getText(R.styleable.LcSearchView_lcQueryHint);
    clearBtnResId = a.getResourceId(R.styleable.LcSearchView_lcClearIcon, clearBtnResId);
    titleIconId = a.getResourceId(R.styleable.LcSearchView_lcSearchIcon, titleIconId);
    searchBgId = a.getResourceId(R.styleable.LcSearchView_lcBackground, searchBgId);
    imeOptions = a.getInt(R.styleable.LcSearchView_android_imeOptions, imeOptions);
    inputType = a.getInt(R.styleable.LcSearchView_android_inputType, inputType);
    focusable = a.getBoolean(R.styleable.LcSearchView_android_focusable, focusable);

    mMatchColor = a.getColor(R.styleable.LcSearchView_lcMatchColor, mMatchColor);
    mCursorResId =
        a.getResourceId(R.styleable.LcSearchView_android_textCursorDrawable, mCursorResId);

    if (a.hasValue(R.styleable.LcSearchView_lcCancelText)) {
      cancelText = a.getString(R.styleable.LcSearchView_lcCancelText);
    }

    if (a.hasValue(R.styleable.LcSearchView_lcPopupBackground)) {
      mDropDownBg = a.getDrawable(R.styleable.LcSearchView_lcPopupBackground);
    }

    if (a.hasValue(R.styleable.LcSearchView_lcPopupListDivider)) {
      popupDivider = a.getDrawable(R.styleable.LcSearchView_lcPopupListDivider);
    }
    mDropDownBlurRadius =
        a.getDimensionPixelSize(R.styleable.LcSearchView_lcPopupBlurRadius, mDropDownBlurRadius);
    mPopupItemLayoutResId =
        a.getResourceId(R.styleable.LcSearchView_lcPopupItemLayout, mPopupItemLayoutResId);

    final int completeThreshold = a.getInt(R.styleable.LcSearchView_android_completionThreshold, 2);

    mAlwaysShowCancel =
        a.getBoolean(R.styleable.LcSearchView_lcAlwaysShowCancel, mAlwaysShowCancel);
    a.recycle();

    mEditorTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, queryTextSize);
    mEditorTextView.setTextColor(queryTextColor);
    mEditorTextView.setHintTextColor(queryHintTextColor);
    HIDDEN_METHOD.setCursorDrawableRes(mEditorTextView, mCursorResId);
    mEditorTextView.setPopupBackground(mDropDownBg);
    mEditorTextView.setPopupListDivider(popupDivider);
    mEditorTextView.setPopupBlurRadius(mDropDownBlurRadius);
    mEditorTextView.setThreshold(completeThreshold);

    if (mEditorTextView.hasFocus()) {
      mTitleIcon.setAlpha(1.0f);
      mEditorTextView.setAlpha(1.0f);
    } else {
      mTitleIcon.setAlpha(unfocusAlpha);
      mEditorTextView.setAlpha(unfocusAlpha);
    }

    mCancelTextView.setTextColor(cancelTextColor);
    mCancelTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, cancelTextSize);
    if (mAlwaysShowCancel) {
      mCancelTextView.setVisibility(View.VISIBLE);
    }
    mClearBtn.setImageResource(clearBtnResId);
    mTitleIcon.setImageResource(titleIconId);

    mSearchTrack.setBackgroundResource(searchBgId);
    LinearLayout.LayoutParams plateParams =
        (LinearLayout.LayoutParams) mSearchTrack.getLayoutParams();
    plateParams.topMargin = mTrackMarginTop;
    plateParams.bottomMargin = mTrackMarginBottom;
    plateParams.leftMargin = mTrackMarginLeft;
    plateParams.rightMargin = mAlwaysShowCancel ? 0 : mTrackMarginRight;

    LinearLayout.LayoutParams params = (LayoutParams) mTitleIcon.getLayoutParams();
    params.leftMargin = mTrackPaddingLeft;
    params = (LayoutParams) mClearBtn.getLayoutParams();
    params.rightMargin = mTrackPaddingRight;

    mCancelTextView.setPadding(mTrackMarginRight, 0, mTrackMarginRight, 0);

    if (maxWidth != -1) {
      setMaxWidth(maxWidth);
    }

    if (!TextUtils.isEmpty(queryHintText)) {
      setQueryHint(queryHintText);
    }

    if (imeOptions != -1) {
      setImeOptions(imeOptions);
    }
    if (inputType != -1) {
      setInputType(inputType);
    }

    if (cancelText != null) {
      mCancelTextView.setText(cancelText);
    }

    setFocusable(focusable);

    updateQueryHint();
  }
예제 #3
0
 public float getFloatValueFromResourses(int res) {
   TypedValue outValue = new TypedValue();
   getResources().getValue(res, outValue, true);
   return outValue.getFloat();
 }
예제 #4
0
  /** Updates the state, given the specified context */
  void update(Context context) {
    SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0);
    Resources res = context.getResources();
    DisplayMetrics dm = res.getDisplayMetrics();

    // Debug mode
    debugModeEnabled = settings.getBoolean(Constants.Values.App.Key_DebugModeEnabled, false);
    if (debugModeEnabled) {
      Console.Enabled = true;
    }

    // Layout
    isLandscape = res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    hasTransposedSearchBar = res.getBoolean(R.bool.recents_has_transposed_search_bar);
    hasTransposedNavBar = res.getBoolean(R.bool.recents_has_transposed_nav_bar);

    // Insets
    displayRect.set(0, 0, dm.widthPixels, dm.heightPixels);

    // Animations
    animationPxMovementPerSecond =
        res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second);

    // Filtering
    filteringCurrentViewsAnimDuration =
        res.getInteger(R.integer.recents_filter_animate_current_views_duration);
    filteringNewViewsAnimDuration =
        res.getInteger(R.integer.recents_filter_animate_new_views_duration);

    // Loading
    maxNumTasksToLoad = ActivityManager.getMaxRecentTasksStatic();

    // Search Bar
    searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height);
    searchBarAppWidgetId = settings.getInt(Constants.Values.App.Key_SearchAppWidgetId, -1);

    // Task stack
    taskStackScrollDuration = res.getInteger(R.integer.recents_animate_task_stack_scroll_duration);
    TypedValue widthPaddingPctValue = new TypedValue();
    res.getValue(R.dimen.recents_stack_width_padding_percentage, widthPaddingPctValue, true);
    taskStackWidthPaddingPct = widthPaddingPctValue.getFloat();
    TypedValue stackOverscrollPctValue = new TypedValue();
    res.getValue(R.dimen.recents_stack_overscroll_percentage, stackOverscrollPctValue, true);
    taskStackOverscrollPct = stackOverscrollPctValue.getFloat();
    taskStackMaxDim = res.getInteger(R.integer.recents_max_task_stack_view_dim);
    taskStackTopPaddingPx = res.getDimensionPixelSize(R.dimen.recents_stack_top_padding);

    // Transition
    transitionEnterFromAppDelay =
        res.getInteger(R.integer.recents_enter_from_app_transition_duration);
    transitionEnterFromHomeDelay =
        res.getInteger(R.integer.recents_enter_from_home_transition_duration);

    // Task view animation and styles
    taskViewEnterFromAppDuration = res.getInteger(R.integer.recents_task_enter_from_app_duration);
    taskViewEnterFromHomeDuration = res.getInteger(R.integer.recents_task_enter_from_home_duration);
    taskViewEnterFromHomeStaggerDelay =
        res.getInteger(R.integer.recents_task_enter_from_home_stagger_delay);
    taskViewExitToAppDuration = res.getInteger(R.integer.recents_task_exit_to_app_duration);
    taskViewExitToHomeDuration = res.getInteger(R.integer.recents_task_exit_to_home_duration);
    taskViewRemoveAnimDuration =
        res.getInteger(R.integer.recents_animate_task_view_remove_duration);
    taskViewRemoveAnimTranslationXPx =
        res.getDimensionPixelSize(R.dimen.recents_task_view_remove_anim_translation_x);
    taskViewRoundedCornerRadiusPx =
        res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius);
    taskViewHighlightPx = res.getDimensionPixelSize(R.dimen.recents_task_view_highlight);
    taskViewTranslationZMinPx = res.getDimensionPixelSize(R.dimen.recents_task_view_z_min);
    taskViewTranslationZMaxPx = res.getDimensionPixelSize(R.dimen.recents_task_view_z_max);
    taskViewAffiliateGroupEnterOffsetPx =
        res.getDimensionPixelSize(R.dimen.recents_task_view_affiliate_group_enter_offset);
    TypedValue thumbnailAlphaValue = new TypedValue();
    res.getValue(R.dimen.recents_task_view_thumbnail_alpha, thumbnailAlphaValue, true);
    taskViewThumbnailAlpha = thumbnailAlphaValue.getFloat();

    // Task bar colors
    taskBarViewDefaultBackgroundColor =
        res.getColor(R.color.recents_task_bar_default_background_color);
    taskBarViewLightTextColor = res.getColor(R.color.recents_task_bar_light_text_color);
    taskBarViewDarkTextColor = res.getColor(R.color.recents_task_bar_dark_text_color);
    taskBarViewHighlightColor = res.getColor(R.color.recents_task_bar_highlight_color);
    TypedValue affMinAlphaPctValue = new TypedValue();
    res.getValue(
        R.dimen.recents_task_affiliation_color_min_alpha_percentage, affMinAlphaPctValue, true);
    taskBarViewAffiliationColorMinAlpha = affMinAlphaPctValue.getFloat();

    // Task bar size & animations
    taskBarHeight = res.getDimensionPixelSize(R.dimen.recents_task_bar_height);
    taskBarDismissDozeDelaySeconds =
        res.getInteger(R.integer.recents_task_bar_dismiss_delay_seconds);

    // Nav bar scrim
    navBarScrimEnterDuration = res.getInteger(R.integer.recents_nav_bar_scrim_enter_duration);

    // Misc
    useHardwareLayers = res.getBoolean(R.bool.config_recents_use_hardware_layers);
    altTabKeyDelay = res.getInteger(R.integer.recents_alt_tab_key_delay);
    fakeShadows = res.getBoolean(R.bool.config_recents_fake_shadows);
    svelteLevel = res.getInteger(R.integer.recents_svelte_level);
  }