类androidx.appcompat.widget.TooltipCompat源码实例Demo

下面列出了怎么用androidx.appcompat.widget.TooltipCompat的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: odyssey   文件: NowPlayingView.java
/**
 * Set the viewswitcher of cover/playlist view to the requested state.
 *
 * @param view the view which should be displayed.
 */
public void setViewSwitcherStatus(NowPlayingDragStatusReceiver.VIEW_SWITCHER_STATUS view) {
    int color = 0;

    switch (view) {
        case COVER_VIEW:
            // change the view only if the requested view is not displayed
            if (mViewSwitcher.getCurrentView() != mCoverImage) {
                mViewSwitcher.showNext();
            }
            color = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent);
            TooltipCompat.setTooltipText(mTopPlaylistButton, getResources().getString(R.string.action_npv_show_playlist));
            break;
        case PLAYLIST_VIEW:
            // change the view only if the requested view is not displayed
            if (mViewSwitcher.getCurrentView() != mPlaylistView) {
                mViewSwitcher.showNext();
            }
            color = ThemeUtils.getThemeColor(getContext(), R.attr.colorAccent);
            TooltipCompat.setTooltipText(mTopPlaylistButton, getResources().getString(R.string.action_npv_show_cover));
            break;
    }

    // tint the button according to the requested view
    mTopPlaylistButton.setImageTintList(ColorStateList.valueOf(color));
}
 
@Override
public void initialize(@NonNull MenuItemImpl itemData, int menuType) {
  this.itemData = itemData;
  setCheckable(itemData.isCheckable());
  setChecked(itemData.isChecked());
  setEnabled(itemData.isEnabled());
  setIcon(itemData.getIcon());
  setTitle(itemData.getTitle());
  setId(itemData.getItemId());
  if (!TextUtils.isEmpty(itemData.getContentDescription())) {
    setContentDescription(itemData.getContentDescription());
  }

  CharSequence tooltipText = !TextUtils.isEmpty(itemData.getTooltipText())
      ? itemData.getTooltipText()
      : itemData.getTitle();
  TooltipCompat.setTooltipText(this, tooltipText);
  setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE);
}
 
@Override
public void initialize(@NonNull MenuItemImpl itemData, int menuType) {
  this.itemData = itemData;
  if (itemData.getItemId() > 0) {
    setId(itemData.getItemId());
  }

  setVisibility(itemData.isVisible() ? VISIBLE : GONE);

  if (getBackground() == null) {
    ViewCompat.setBackground(this, createDefaultBackground());
  }

  setCheckable(itemData.isCheckable());
  setChecked(itemData.isChecked());
  setEnabled(itemData.isEnabled());
  setTitle(itemData.getTitle());
  setIcon(itemData.getIcon());
  setActionView(itemData.getActionView());
  setContentDescription(itemData.getContentDescription());
  TooltipCompat.setTooltipText(this, itemData.getTooltipText());
  adjustAppearance();
}
 
@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);

    editText = view.findViewById(R.id.search_string_pref_dlg_editText);
    editText.setText(preference.value);

    final ImageView helpIcon = view.findViewById(R.id.search_string_pref_dlg_helpIcon);
    TooltipCompat.setTooltipText(helpIcon, getString(R.string.help_button_tooltip));
    helpIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String helpString =
                    "\u2022 " + getString(R.string.pref_dlg_info_about_wildcards_1) + "\n" +
                            "\u2022 " + getString(R.string.pref_dlg_info_about_wildcards_5) + "\n" +
                            "\u2022 " + getString(R.string.pref_dlg_info_about_wildcards_2) + " " +
                            getString(R.string.calendar_pref_dlg_info_about_wildcards) + " " +
                            getString(R.string.pref_dlg_info_about_wildcards_6) + ", " +
                            getString(R.string.pref_dlg_info_about_wildcards_3) + "\n" +
                            "\u2022 " + getString(R.string.pref_dlg_info_about_wildcards_4)
                    ;
            DialogHelpPopupWindowX.showPopup(helpIcon, R.string.menu_help, (Activity)prefContext, getDialog(), helpString);
        }
    });

}
 
源代码5 项目: science-journal   文件: ARVelocityActivity.java
public void attachSnapshotButton(View snapshotButton) {
  // Pass in the velocity ID to take a snapshot of just the velocity sensor.
  List<String> ids = new ArrayList<>();
  ids.add(VelocitySensor.ID);

  snapshotButton.setOnClickListener(
      v -> {
        Snapshotter snapshotter =
            new Snapshotter(
                singleton.getRecorderController(appAccount),
                singleton.getDataController(appAccount),
                singleton.getSensorRegistry());
        singleton
            .getRecorderController(appAccount)
            .watchRecordingStatus()
            .firstElement()
            .flatMapSingle(status -> snapshotter.addSnapshotLabel(experimentId, status, ids))
            .subscribe(
                (Label label) -> singleton.onLabelsAdded().onNext(label),
                (Throwable e) -> {
                  if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, Throwables.getStackTraceAsString(e));
                  }
                });
      });
  TooltipCompat.setTooltipText(
      snapshotButton, getResources().getString(R.string.snapshot_button_description));
}
 
源代码6 项目: aptoide-client-v8   文件: OtherVersionWidget.java
@Override public void bindView(OtherVersionDisplayable displayable, int position) {
  this.displayable = displayable;
  setItemBackgroundColor(itemView);
  try {
    final App app = displayable.getPojo();
    appId = app.getId();
    storeName = app.getStore()
        .getName();
    packageName = app.getPackageName();

    version.setText(app.getFile()
        .getVername());
    TooltipCompat.setTooltipText(version, app.getFile()
        .getVername());
    version.setOnClickListener(v -> navigateToAppView());
    setBadge(app);
    date.setText(AptoideUtils.DateTimeU.getInstance(getContext())
        .getTimeDiffString(getContext(), app.getModified()
            .getTime(), getContext().getResources()));
    downloads.setText(String.format(DEFAULT_LOCALE,
        getContext().getString(R.string.other_versions_downloads_count_text),
        AptoideUtils.StringU.withSuffix(app.getStats()
            .getDownloads())));

    ImageLoader.with(getContext())
        .load(app.getStore()
            .getAvatar(), storeIcon);
    storeNameView.setText(app.getStore()
        .getName());
    followers.setText(String.format(DEFAULT_LOCALE,
        getContext().getString(R.string.appview_followers_count_text), app.getStore()
            .getStats()
            .getSubscribers()));
  } catch (NullPointerException e) {
    CrashReport.getInstance()
        .log(e);
  }
}
 
@Override
public void setTitle(CharSequence title) {
  smallLabel.setText(title);
  largeLabel.setText(title);
  if (itemData == null || TextUtils.isEmpty(itemData.getContentDescription())) {
    setContentDescription(title);
  }

  CharSequence tooltipText = itemData == null || TextUtils.isEmpty(itemData.getTooltipText())
      ? title
      : itemData.getTooltipText();
  TooltipCompat.setTooltipText(this, tooltipText);
}
 
@Override
protected void onCreate(Bundle icicle, boolean ready) {
  ApplicationDcContext dcContext = DcHelper.getContext(this);

  // add welcome message
  dcContext.updateDeviceChats();

  // update messages - for new messages, do not reuse or modify strings but create new ones.
  // it is not needed to keep all past update messages, however, when deleted, also the strings should be deleted.
  DcMsg msg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT);
  msg.setText(getString(R.string.update_1_10_android) + "\n\n" + "https://delta.chat/en/2020-06-24-releases");
  dcContext.addDeviceMsg("update_1_10b_android", msg); // addDeviceMessage() makes sure, messages with the same id are not added twice

  // create view
  setContentView(R.layout.conversation_list_activity);

  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  title                    = findViewById(R.id.toolbar_title);
  searchToolbar            = findViewById(R.id.search_toolbar);
  searchAction             = findViewById(R.id.search_action);
  fragmentContainer        = findViewById(R.id.fragment_container);

  Bundle bundle = new Bundle();
  conversationListFragment = initFragment(R.id.fragment_container, new ConversationListFragment(), dynamicLanguage.getCurrentLocale(), bundle);

  initializeSearchListener();

  TooltipCompat.setTooltipText(searchAction, getText(R.string.search_explain));
  refresh();
}
 
@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);

    AppCompatImageButton addButton = view.findViewById(R.id.applications_pref_dlg_add);
    TooltipCompat.setTooltipText(addButton, getString(R.string.applications_pref_dlg_add_button_tooltip));

    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
    applicationsListView = view.findViewById(R.id.applications_pref_dlg_listview);
    //applicationsListView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
    applicationsListView.setLayoutManager(layoutManager);
    applicationsListView.setHasFixedSize(true);

    linlaProgress = view.findViewById(R.id.applications_pref_dlg_linla_progress);
    rellaDialog = view.findViewById(R.id.applications_pref_dlg_rella_dialog);

    listAdapter = new ApplicationsDialogPreferenceAdapterX(prefContext, preference, this);

    // added touch helper for drag and drop items
    ItemTouchHelper.Callback callback = new ItemTouchHelperCallback(listAdapter, false, false);
    itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(applicationsListView);

    addButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            preference.startEditor(null);
        }
    });

    refreshListView(false);
}
 
@SuppressLint("SetTextI18n")
void bindApplication(Application application, int position) {
    this.application = application;
    //PPApplication.logE("ApplicationEditorDialogViewHolder.bindApplication", "this.application="+this.application);

    // Display Application data
    if (dialog.selectedFilter != 2) {
        if (EditorProfilesActivity.getApplicationsCache() != null)
            imageViewIcon.setImageBitmap(EditorProfilesActivity.getApplicationsCache().getApplicationIcon(application, false));
    }
    textViewAppName.setText(application.appLabel);

    if (dialog.selectedPosition == position)
        radioBtn.setChecked(true);
    else
        radioBtn.setChecked(false);
    radioBtn.setTag(position);

    if (imageViewMenu != null) {
        TooltipCompat.setTooltipText(imageViewMenu, dialog.activity.getString(R.string.tooltip_options_menu));
        imageViewMenu.setTag(position);
        imageViewMenu.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                dialog.showEditMenu(imageViewMenu);
            }
        });
    }
}
 
源代码11 项目: mollyim-android   文件: ConversationListFragment.java
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  reminderView       = view.findViewById(R.id.reminder);
  list               = view.findViewById(R.id.list);
  fab                = view.findViewById(R.id.fab);
  cameraFab          = view.findViewById(R.id.camera_fab);
  emptyState         = view.findViewById(R.id.empty_state);
  emptyImage         = view.findViewById(R.id.empty);
  searchEmptyState   = view.findViewById(R.id.search_no_results);
  searchToolbar      = view.findViewById(R.id.search_toolbar);
  searchAction       = view.findViewById(R.id.search_action);
  toolbarShadow      = view.findViewById(R.id.conversation_list_toolbar_shadow);
  megaphoneContainer = view.findViewById(R.id.megaphone_container);

  Toolbar toolbar = view.findViewById(getToolbarRes());
  toolbar.setVisibility(View.VISIBLE);
  ((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);

  fab.show();
  cameraFab.show();

  reminderView.setOnDismissListener(this::updateReminders);

  list.setHasFixedSize(true);
  list.setLayoutManager(new LinearLayoutManager(getActivity()));
  list.setItemAnimator(new DeleteItemAnimator());
  list.addOnScrollListener(new ScrollListener());

  new ItemTouchHelper(new ArchiveListenerCallback()).attachToRecyclerView(list);

  fab.setOnClickListener(v -> startActivity(new Intent(getActivity(), NewConversationActivity.class)));
  cameraFab.setOnClickListener(v -> {
    Permissions.with(requireActivity())
               .request(Manifest.permission.CAMERA)
               .ifNecessary()
               .withRationaleDialog(getString(R.string.ConversationActivity_to_capture_photos_and_video_allow_signal_access_to_the_camera), R.drawable.ic_camera_solid_24)
               .withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_the_camera_permission_to_take_photos_or_video))
               .onAllGranted(() -> startActivity(MediaSendActivity.buildCameraFirstIntent(requireActivity())))
               .onAnyDenied(() -> Toast.makeText(requireContext(), R.string.ConversationActivity_signal_needs_camera_permissions_to_take_photos_or_video, Toast.LENGTH_LONG).show())
               .execute();
  });

  initializeListAdapters();
  initializeViewModel();
  initializeTypingObserver();
  initializeSearchListener();

  TooltipCompat.setTooltipText(searchAction, getText(R.string.SearchToolbar_search_for_conversations_contacts_and_messages));
}
 
源代码12 项目: a   文件: TabLayout.java
private void updateTextAndIcon(@Nullable final TextView textView,
                               @Nullable final ImageView iconView) {
    final Drawable icon = mTab != null ? mTab.getIcon() : null;
    final CharSequence text = mTab != null ? mTab.getText() : null;
    final CharSequence contentDesc = mTab != null ? mTab.getContentDescription() : null;

    if (iconView != null) {
        if (icon != null) {
            iconView.setImageDrawable(icon);
            iconView.setVisibility(VISIBLE);
            setVisibility(VISIBLE);
        } else {
            iconView.setVisibility(GONE);
            iconView.setImageDrawable(null);
        }
        iconView.setContentDescription(contentDesc);
    }

    final boolean hasText = !TextUtils.isEmpty(text);
    if (textView != null) {
        if (hasText) {
            textView.setText(text);
            textView.setVisibility(VISIBLE);
            setVisibility(VISIBLE);
        } else {
            textView.setVisibility(GONE);
            textView.setText(null);
        }
        textView.setContentDescription(contentDesc);
    }

    if (iconView != null) {
        MarginLayoutParams lp = ((MarginLayoutParams) iconView.getLayoutParams());
        int bottomMargin = 0;
        if (hasText && iconView.getVisibility() == VISIBLE) {
            // If we're showing both text and icon, add some margin bottom to the icon
            bottomMargin = dpToPx(DEFAULT_GAP_TEXT_ICON);
        }
        if (bottomMargin != lp.bottomMargin) {
            lp.bottomMargin = bottomMargin;
            iconView.requestLayout();
        }
    }
    TooltipCompat.setTooltipText(this, hasText ? null : contentDesc);
}
 
源代码13 项目: material-components-android   文件: TabLayout.java
private void updateTextAndIcon(
    @Nullable final TextView textView, @Nullable final ImageView iconView) {
  final Drawable icon =
      (tab != null && tab.getIcon() != null)
          ? DrawableCompat.wrap(tab.getIcon()).mutate()
          : null;
  final CharSequence text = tab != null ? tab.getText() : null;

  if (iconView != null) {
    if (icon != null) {
      iconView.setImageDrawable(icon);
      iconView.setVisibility(VISIBLE);
      setVisibility(VISIBLE);
    } else {
      iconView.setVisibility(GONE);
      iconView.setImageDrawable(null);
    }
  }

  final boolean hasText = !TextUtils.isEmpty(text);
  if (textView != null) {
    if (hasText) {
      textView.setText(text);
      if (tab.labelVisibilityMode == TAB_LABEL_VISIBILITY_LABELED) {
        textView.setVisibility(VISIBLE);
      } else {
        textView.setVisibility(GONE);
      }
      setVisibility(VISIBLE);
    } else {
      textView.setVisibility(GONE);
      textView.setText(null);
    }
  }

  if (iconView != null) {
    MarginLayoutParams lp = ((MarginLayoutParams) iconView.getLayoutParams());
    int iconMargin = 0;
    if (hasText && iconView.getVisibility() == VISIBLE) {
      // If we're showing both text and icon, add some margin bottom to the icon
      iconMargin = (int) ViewUtils.dpToPx(getContext(), DEFAULT_GAP_TEXT_ICON);
    }
    if (inlineLabel) {
      if (iconMargin != MarginLayoutParamsCompat.getMarginEnd(lp)) {
        MarginLayoutParamsCompat.setMarginEnd(lp, iconMargin);
        lp.bottomMargin = 0;
        // Calls resolveLayoutParams(), necessary for layout direction
        iconView.setLayoutParams(lp);
        iconView.requestLayout();
      }
    } else {
      if (iconMargin != lp.bottomMargin) {
        lp.bottomMargin = iconMargin;
        MarginLayoutParamsCompat.setMarginEnd(lp, 0);
        // Calls resolveLayoutParams(), necessary for layout direction
        iconView.setLayoutParams(lp);
        iconView.requestLayout();
      }
    }
  }

  final CharSequence contentDesc = tab != null ? tab.contentDesc : null;
  TooltipCompat.setTooltipText(this, hasText ? null : contentDesc);
}
 
@SuppressLint("SetTextI18n")
void bindApplication(Application application) {

    // 4. Bind the data to the ViewHolder
    this.application = application;

    if (this.application.type != Application.TYPE_INTENT) {
        if (EditorProfilesActivity.getApplicationsCache() != null)
            imageViewIcon.setImageBitmap(EditorProfilesActivity.getApplicationsCache().getApplicationIcon(application, false));
    }
    else
        imageViewIcon.setImageResource(R.drawable.ic_profile_pref_run_application);
    String text = application.appLabel;
    if (application.shortcutId > 0) {
        Shortcut shortcut = DatabaseHandler.getInstance(context.getApplicationContext()).getShortcut(application.shortcutId);
        if (shortcut != null)
            text = shortcut._name;
    }
    else
    if (application.intentId > 0) {
        PPIntent intent = DatabaseHandler.getInstance(context.getApplicationContext()).getIntent(application.intentId);
        if (intent != null)
            text = intent._name;
    }
    textViewAppName.setText(text);
    boolean errorColor = false;
    if ((application.type == Application.TYPE_SHORTCUT) && (application.shortcutId == 0))
        errorColor = true;
    if ((application.type == Application.TYPE_INTENT) && (application.intentId == 0))
        errorColor = true;
    setTextStyle(textViewAppName, errorColor);

    switch (application.type) {
        case Application.TYPE_APPLICATION:
            textViewAppType.setText("- "+context.getString(R.string.applications_preference_applicationType_application));
            break;
        case Application.TYPE_SHORTCUT:
            textViewAppType.setText("- "+context.getString(R.string.applications_preference_applicationType_shortcut));
            break;
        case Application.TYPE_INTENT:
            textViewAppType.setText("- "+context.getString(R.string.applications_preference_applicationType_intent));
            break;
    }
    setTextStyle(textViewAppType, errorColor);

    text = context.getString(R.string.applications_editor_dialog_startApplicationDelay);
    text = text + " " + GlobalGUIRoutines.getDurationString(application.startApplicationDelay);
    textViewStartApplicationDelay.setText(text);
    setTextStyle(textViewStartApplicationDelay, errorColor);

    TooltipCompat.setTooltipText(imageViewMenu, context.getString(R.string.tooltip_options_menu));
    imageViewMenu.setTag(application);
    imageViewMenu.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            preference.showEditMenu(imageViewMenu);
        }
    });

}
 
源代码15 项目: PhoneProfilesPlus   文件: NumberPicker.java
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mDivider = findViewById(R.id.divider);
    mError = findViewById(R.id.error);

    Arrays.fill(mInput, -1);

    View v1 = findViewById(R.id.first);
    View v2 = findViewById(R.id.second);
    View v3 = findViewById(R.id.third);
    View v4 = findViewById(R.id.fourth);
    mEnteredNumber = findViewById(R.id.number_text);
    mBackspace = findViewById(R.id.backspace);
    TooltipCompat.setTooltipText(mBackspace, mContext.getString(R.string.backspace_button_tooltip));
    mBackspace.setOnClickListener(this);
    //mDelete.setOnLongClickListener(this);
    mClear = findViewById(R.id.clear);
    TooltipCompat.setTooltipText(mClear, mContext.getString(R.string.clear_button_tooltip));
    mClear.setOnClickListener(this);

    mNumbers[1] = v1.findViewById(R.id.key_left);
    mNumbers[2] = v1.findViewById(R.id.key_middle);
    mNumbers[3] = v1.findViewById(R.id.key_right);

    mNumbers[4] = v2.findViewById(R.id.key_left);
    mNumbers[5] = v2.findViewById(R.id.key_middle);
    mNumbers[6] = v2.findViewById(R.id.key_right);

    mNumbers[7] = v3.findViewById(R.id.key_left);
    mNumbers[8] = v3.findViewById(R.id.key_middle);
    mNumbers[9] = v3.findViewById(R.id.key_right);

    mLeft = v4.findViewById(R.id.key_left);
    mNumbers[0] = v4.findViewById(R.id.key_middle);
    mRight = v4.findViewById(R.id.key_right);
    setLeftRightEnabled();

    for (int i = 0; i < 10; i++) {
        mNumbers[i].setOnClickListener(this);
        mNumbers[i].setText(String.valueOf(i));
        mNumbers[i].setTag(R.id.numbers_key, i);
    }
    updateNumber();

    Resources res = mContext.getResources();
    mLeft.setText(res.getString(R.string.number_picker_plus_minus));
    mRight.setText(res.getString(R.string.number_picker_separator));
    mLeft.setOnClickListener(this);
    mRight.setOnClickListener(this);
    mLabel = findViewById(R.id.label);
    mSign = SIGN_POSITIVE;

    // Set the correct label state
    showLabel();

    restyleViews();
    updateKeypad();
}
 
源代码16 项目: TwistyTimer   文件: TimerGraphFragment.java
/**
 * Since all stats views have the same base layout, they share the same views
 * with the same ids. This function uses the TooltipCompat function added in support library
 * v26 to set a tooltip for an icon in each of the stats tabs.
 *
 * @param viewId
 *      The ID of the view that should receive the tooltip
 * @param tooltipTextRes
 *      The string resource to be displayed
 */
private void setTooltipText(@IdRes int viewId, @StringRes int tooltipTextRes) {
    TooltipCompat.setTooltipText(statsImprovementLayout.findViewById(viewId),
            getString(tooltipTextRes));
    TooltipCompat.setTooltipText(statsAverageLayout.findViewById(viewId),
            getString(tooltipTextRes));
    TooltipCompat.setTooltipText(statsOtherlayout.findViewById(viewId),
            getString(tooltipTextRes));
}