android.support.v4.widget.TextViewCompat Java Examples

The following examples show how to use android.support.v4.widget.TextViewCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppDetailsRecyclerViewAdapter.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
private void addLinkItemView(ViewGroup parent, int resIdText, int resIdDrawable, final String url, String formatArg) {
    TextView view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.app_details2_link_item, parent, false);
    if (formatArg == null) {
        view.setText(resIdText);
    } else {
        String text = parent.getContext().getString(resIdText, formatArg);
        view.setText(text);
    }
    TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(view, resIdDrawable, 0, 0, 0);
    parent.addView(view);
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onLinkClicked(url);
        }
    });
}
 
Example #2
Source File: Home.java    From Muslim-Athkar-Islamic-Reminders with MIT License 6 votes vote down vote up
private void initializeAll() {
        autoSizeTv = view.findViewById(R.id.atkharTv);
        createImageRL = view.findViewById(R.id.createImageRL);
        shareIvBtn = view.findViewById(R.id.shareIvBtn);
        createNewImageBtn = view.findViewById(R.id.createNewImageBtn);



        appName = "Muslim Athkar";
        imageDirectory = new File(Environment.getExternalStorageDirectory() + "/"+appName+"/");
        imageName = "Athkar.jpg";

        presenter = new HomePresenter(this);

        shareIvBtn.setOnClickListener(this);
        createNewImageBtn.setOnClickListener(this);
        ring= MediaPlayer.create(getContext(),R.raw.shared_thank_you);
        TextViewCompat.setAutoSizeTextTypeWithDefaults(autoSizeTv, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);

//        LocalBroadcastManager.getInstance(getActivity()).registerReceiver(connectionStatusReceiver
//                ,new IntentFilter(Utils.BROADCAST_CONNECTION_STATUS));
//
        LocalBroadcastManager.getInstance(getContext()).registerReceiver(messageReceiver
                ,new IntentFilter(Utils.BROADCAST_ACTION));

    }
 
Example #3
Source File: ScrollableNumberPicker.java    From ScrollableNumberPicker with MIT License 6 votes vote down vote up
private void initValueView() {
    mValueTextView = (TextView) findViewById(R.id.text_value);

    if (mValueTextAppearanceResId != INVALID_RES) {
        TextViewCompat.setTextAppearance(mValueTextView, mValueTextAppearanceResId);
    }

    if (mValueTextColor != 0) {
        mValueTextView.setTextColor(mValueTextColor);
    }

    if (mValueTextSize != INVALID_RES) {
        mValueTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mValueTextSize);
    }

    LinearLayout.LayoutParams layoutParams = (LayoutParams) mValueTextView.getLayoutParams();
    if (mOrientation == HORIZONTAL) {
        layoutParams.setMargins(mValueMarginStart, 0, mValueMarginEnd, 0);
    } else {
        layoutParams.setMargins(0, mValueMarginStart, 0, mValueMarginEnd);
    }

    mValueTextView.setLayoutParams(layoutParams);

    setValue();
}
 
Example #4
Source File: SwipeMenuView.java    From SwipeRecyclerView-master with Apache License 2.0 6 votes vote down vote up
private TextView createTitle(SwipeMenuItem item) {
    TextView textView = new TextView(getContext());
    textView.setText(item.getText());
    textView.setGravity(Gravity.CENTER);
    int textSize = item.getTextSize();
    if (textSize > 0)
        textView.setTextSize(textSize);
    ColorStateList textColor = item.getTitleColor();
    if (textColor != null)
        textView.setTextColor(textColor);
    int textAppearance = item.getTextAppearance();
    if (textAppearance != 0)
        TextViewCompat.setTextAppearance(textView, textAppearance);
    Typeface typeface = item.getTextTypeface();
    if (typeface != null)
        textView.setTypeface(typeface);
    return textView;
}
 
Example #5
Source File: DrawerListAdapter.java    From monolog-android with MIT License 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LvMenuItem item = mItems.get(position);
    switch (item.type) {
        case LvMenuItem.TYPE_NORMAL:
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.listitem_drawer_menu_item, parent,
                        false);
            }
            TextView itemView = (TextView) convertView;
            itemView.setText(item.name);
            Drawable icon = mContext.getResources().getDrawable(item.icon);
            setIconColor(icon);
            if (icon != null) {
                icon.setBounds(0, 0, mIconSize, mIconSize);
                TextViewCompat.setCompoundDrawablesRelative(itemView, icon, null, null, null);
            }

            break;
        case LvMenuItem.TYPE_NO_ICON:
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.listitem_drawer_subheader,
                        parent, false);
            }
            TextView subHeader = (TextView) convertView;
            subHeader.setText(item.name);
            break;
        case LvMenuItem.TYPE_SEPARATOR:
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.listitem_drawer_seperator,
                        parent, false);
            }
            break;
    }

    return convertView;
}
 
Example #6
Source File: AppDetailsRecyclerViewAdapter.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
NoVersionsViewHolder(View view) {
    super(view);
    headerView = (TextView) view.findViewById(R.id.information);
    TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(headerView, R.drawable.ic_access_time_24dp_grey600, 0, 0, 0);

    itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            explainIncompatibleVersions();
        }
    });
}
 
Example #7
Source File: SwipeMenuView.java    From SwipeRecyclerView with Apache License 2.0 5 votes vote down vote up
private TextView createTitle(SwipeMenuItem item) {
    TextView textView = new TextView(getContext());
    textView.setText(item.getText());
    textView.setGravity(Gravity.CENTER);
    int textSize = item.getTextSize();
    if (textSize > 0) textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    ColorStateList textColor = item.getTitleColor();
    if (textColor != null) textView.setTextColor(textColor);
    int textAppearance = item.getTextAppearance();
    if (textAppearance != 0) TextViewCompat.setTextAppearance(textView, textAppearance);
    Typeface typeface = item.getTextTypeface();
    if (typeface != null) textView.setTypeface(typeface);
    return textView;
}
 
Example #8
Source File: Game.java    From Simple-Solitaire with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a textView and add it to the given layout (game content). Used to add custom texts
 * to a game. This also sets the text apperance to AppCompat and the gravity to center.
 * The width and height is also measured, so you can use it directly.
 *
 * @param width   The width to apply to the
 * @param layout  he textView will be added to this layout
 * @param context Context to create view
 */
protected void addTextViews(int count, int width, RelativeLayout layout, Context context) {

    for (int i = 0; i < count; i++) {
        TextView textView = new TextView(context);
        textView.setWidth(width);
        TextViewCompat.setTextAppearance(textView, R.style.TextAppearance_AppCompat);
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(textViewColor);
        layout.addView(textView);
        textView.measure(0, 0);
        textViews.add(textView);
    }
}
 
Example #9
Source File: PasswordEditText.java    From materialandroid with Apache License 2.0 5 votes vote down vote up
private void setDrawables() {
  Drawable[] drawables = getDrawables();
  if (passwordVisible) {
    drawables[2] = shownIcon;
  } else {
    drawables[2] = hiddenIcon;
  }
  TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(this,
      drawables[0], drawables[1], tintDrawable(drawables[2]), drawables[3]);
}
 
Example #10
Source File: InstructionViewHolder.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void initInstructionAutoSize() {
  TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(primaryText,
    PRIMARY_MIN_TEXT_SIZE_SP, PRIMARY_MAX_TEXT_SIZE_SP, AUTO_SIZE_STEP_GRANULARITY, TypedValue.COMPLEX_UNIT_SP);
  TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(secondaryText,
    SECONDARY_MIN_TEXT_SIZE_SP, SECONDARY_MAX_TEXT_SIZE_SP, AUTO_SIZE_STEP_GRANULARITY, TypedValue.COMPLEX_UNIT_SP);
  TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(distanceText,
    DISTANCE_MIN_TEXT_SIZE_SP, DISTANCE_MAX_TEXT_SIZE_SP, AUTO_SIZE_STEP_GRANULARITY, TypedValue.COMPLEX_UNIT_SP);
}
 
Example #11
Source File: InstructionView.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
/**
 * Called after we bind the views, this will allow the step instruction {@link TextView}
 * to automatically re-size based on the length of the text.
 */
private void initializeInstructionAutoSize() {
  TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(upcomingPrimaryText,
    26, 30, 1, TypedValue.COMPLEX_UNIT_SP);
  TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(upcomingSecondaryText,
    20, 26, 1, TypedValue.COMPLEX_UNIT_SP);
}
 
Example #12
Source File: ItemInfoView.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
public void setContent(CharSequence content, int style, int bg) {
    if (!StringUtils.isEmpty(content)) {
        mContentTv.setVisibility(View.VISIBLE);
        mContentTv.setText(content);
        if (style > 0) {
            TextViewCompat.setTextAppearance(mContentTv, style);
        }
        if (bg > 0) {
            mContentTv.setBackgroundResource(bg);
        }
    } else {
        mContentTv.setVisibility(View.GONE);
    }
}
 
Example #13
Source File: RepoDetailActivity.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
public void populateData(RepoDetail repoModel) {
    if (repoDetailFragmentManager.getRepoDetail() == null) {
        binding.bottom.bottomNavigation.setOnMenuItemClickListener(repoDetailFragmentManager);
        // delay for better activity's start up time
        new Handler(Looper.myLooper()).postDelayed(() -> repoDetailFragmentManager.init(repoModel, viewModel), 300);

    }

    if (repoModel.isHasProjects()) {
        binding.bottom.bottomNavigation.inflateMenu(R.menu.repo_with_project_bottom_nav_menu);
    }

    ///////////// HEADER INFO /////////////////////////////////////////
    if (repoModel.getTopics() != null && !repoModel.getTopics().isEmpty()) {
        headerInfo.tagsIcon.setVisibility(View.VISIBLE);
        if (headerInfo.topicsList.getAdapter() == null) {
            headerInfo.topicsList.setAdapter(topicsAdapter);
        }
    } else {
        headerInfo.tagsIcon.setVisibility(View.GONE);
    }

    headerInfo.detailsIcon.setVisibility(InputHelper.isEmpty(repoModel.getDescription()) ? View.GONE : View.VISIBLE);
    headerInfo.language.setVisibility(InputHelper.isEmpty(repoModel.getLanguage()) ? View.GONE : View.VISIBLE);

    if (!InputHelper.isEmpty(repoModel.getLanguage())) {
        headerInfo.language.setText(repoModel.getLanguage());
        headerInfo.language.setTextColor(ColorsProvider.getColorAsColor(repoModel.getLanguage(), headerInfo.language.getContext()));
    }

    if (repoModel.getOwner() != null) {
        populateUserAvatar(repoModel.getOwner());
    } else if (repoModel.getOrganization() != null) {
        populateUserAvatar(repoModel.getOrganization());
    }

    headerInfo.description.setText(repoModel.getDescription());
    headerInfo.detailsIcon.setVisibility(InputHelper.isEmpty(repoModel.getDescription()) ? View.GONE : View.VISIBLE);

    headerInfo.date.setText(SpannableBuilder.builder()
            .append(ParseDateFormat.getTimeAgo(repoModel.getPushedAt()))
            .append(" ,").append(" ")
            .append(repoModel.getHumanReadableSize()));

    headerInfo.size.setVisibility(View.GONE);
    headerInfo.headerTitle.setText(repoModel.getFullName());
    TextViewCompat.setTextAppearance(headerInfo.headerTitle, R.style.TextAppearance_AppCompat_Medium);
    headerInfo.headerTitle.setTextColor(ViewHelper.getPrimaryTextColor(this));

    ///////////// ICONS /////////////////
    headerIconBinding.setVm(viewModel);
    headerIconBinding.wikiLayout.setVisibility(repoModel.isHasWiki() ? View.VISIBLE : View.GONE);
    headerIconBinding.pinText.setText(R.string.pin);

    headerIconBinding.forkRepo.setText(numberFormat.format(repoModel.getForksCount()));
    headerIconBinding.starRepo.setText(numberFormat.format(repoModel.getStargazersCount()));
    headerIconBinding.watchRepo.setText(numberFormat.format(repoModel.getSubsCount()));

    if (repoModel.getLicense() != null) {
        headerIconBinding.licenseLayout.setVisibility(View.VISIBLE);
        LicenseModel licenseModel = repoModel.getLicense();
        headerIconBinding.license.setText(!InputHelper.isEmpty(licenseModel.getSpdxId()) ? licenseModel.getSpdxId() : licenseModel.getName());
    }

    supportInvalidateOptionsMenu();
    if (!PrefGetter.isRepoGuideShowed()) {}
}
 
Example #14
Source File: BaseTitleActivity.java    From Tok-Android with GNU General Public License v3.0 4 votes vote down vote up
private void setToolBarStyle() {
    int style = getToolBarStyle();
    if (mToolbar != null) {
        int backIconId = -1;
        int mainTitleStyle = -1;
        int subTitleStyle = -1;
        int toolbarBg = -1;
        int menuStyle = -1;
        if (TOOL_BAR_STYLE_WHITE == style) {
            //as default
            backIconId = R.drawable.arrow_back_black;
            mainTitleStyle = R.style.MainTitle;
            subTitleStyle = R.style.SubTitle;
            toolbarBg = R.color.toolbar_bg;
        } else if (TOOL_BAR_STYLE_WHITE_BIG == style) {
            backIconId = R.drawable.arrow_back_black;
            mainTitleStyle = R.style.MainTitleMax;
            toolbarBg = R.color.toolbar_bg;
        } else if (TOOL_BAR_STYLE_BLACK == style) {
            backIconId = R.drawable.arrow_back_white;
        } else if (TOOL_BAR_TRANSLATE == style) {
            backIconId = R.drawable.arrow_back_white;
            toolbarBg = R.color.transparent;
        }
        if (getBackIcon() > 0) {
            backIconId = getBackIcon();
        }
        if (isShowBackIcon()) {
            mBackIv.setImageResource(backIconId);
            mBackIv.setVisibility(View.VISIBLE);
        } else {
            mBackIv.setVisibility(View.GONE);
        }

        if (toolbarBg > 0) {
            mToolbar.setBackgroundResource(toolbarBg);
            try {
                //this method is useful above android 21,but crash at SamSung Galaxy TabA6(from google play console)
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    getWindow().setStatusBarColor(getColor(toolbarBg));
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
        if (mainTitleStyle > 0) {
            TextViewCompat.setTextAppearance(mMainTitle, mainTitleStyle);
        }
        if (subTitleStyle > 0) {
            //setTextAppearance is deprecation,and crash on some device of android 5.0
            //mSubTitle.setTextAppearance(subTitleStyle);
            TextViewCompat.setTextAppearance(mSubTitle, subTitleStyle);
        }
        //TODO how to set menuItem and collsapingLayout color
    }
}
 
Example #15
Source File: SettingsActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        ((IslamicLibraryApplication) getApplication()).refreshLocale(this, false);
        super.onCreate(savedInstanceState);

        // Enable if you use AppCompat 24.1.x.
//        Fixes.updateLayoutInflaterFactory(getLayoutInflater());

        setContentView(R.layout.activity_settings);

        mReplaceFragmentStrategy = new PreferenceScreenNavigationStrategy
                .ReplaceFragment(this,
                R.anim.abc_fade_in,
                R.anim.abc_fade_out,
                R.anim.abc_fade_in,
                R.anim.abc_fade_out);

        if (savedInstanceState == null) {
            mSettingsFragment = SettingsFragment.newInstance(null);
            getSupportFragmentManager().beginTransaction().add(R.id.content, mSettingsFragment, "Settings").commit();
        } else {
            mSettingsFragment = (SettingsFragment) getSupportFragmentManager().findFragmentByTag("Settings");
        }

        getSupportFragmentManager().addOnBackStackChangedListener(this);

        mToolbar = findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        ActionBar ab = getSupportActionBar();


        // Cross-fading title setup.
        mTitle = getTitle();

        mTitleSwitcher = new TextSwitcher(mToolbar.getContext());
        mTitleSwitcher.setFactory(() -> {
            TextView tv = new AppCompatTextView(mToolbar.getContext());
            TextViewCompat.setTextAppearance(tv, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
            return tv;
        });
        mTitleSwitcher.setCurrentText(mTitle);
        if (ab != null) {
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setCustomView(mTitleSwitcher);
            ab.setDisplayShowCustomEnabled(true);
            ab.setDisplayShowTitleEnabled(false);
        }


        // Add to hierarchy before accessing layout params.
        int margin = Util.dpToPxOffset(this, 16);
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mTitleSwitcher.getLayoutParams();
        lp.leftMargin = margin;
        lp.rightMargin = margin;

        mTitleSwitcher.setInAnimation(this, R.anim.abc_fade_in);
        mTitleSwitcher.setOutAnimation(this, R.anim.abc_fade_out);
    }
 
Example #16
Source File: NavListViewActivity.java    From Android_Blog_Demos with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    LvMenuItem item = mItems.get(position);
    switch (item.type)
    {
        case LvMenuItem.TYPE_NORMAL:
            if (convertView == null)
            {
                convertView = mInflater.inflate(R.layout.design_drawer_item, parent,
                        false);
            }
            TextView itemView = (TextView) convertView;
            itemView.setText(item.name);
            Drawable icon = mContext.getResources().getDrawable(item.icon);
            setIconColor(icon);
            if (icon != null)
            {
                icon.setBounds(0, 0, mIconSize, mIconSize);
                TextViewCompat.setCompoundDrawablesRelative(itemView, icon, null, null, null);
            }

            break;
        case LvMenuItem.TYPE_NO_ICON:
            if (convertView == null)
            {
                convertView = mInflater.inflate(R.layout.design_drawer_item_subheader,
                        parent, false);
            }
            TextView subHeader = (TextView) convertView;
            subHeader.setText(item.name);
            break;
        case LvMenuItem.TYPE_SEPARATOR:
            if (convertView == null)
            {
                convertView = mInflater.inflate(R.layout.design_drawer_item_separator,
                        parent, false);
            }
            break;
    }

    return convertView;
}
 
Example #17
Source File: FastScroller.java    From recycler-fast-scroll with Apache License 2.0 4 votes vote down vote up
private void applyStyling() {
    if(bubbleColor!=STYLE_NONE) setBackgroundTint(bubbleTextView, bubbleColor);
    if(handleColor!=STYLE_NONE) setBackgroundTint(handle, handleColor);
    if(bubbleTextAppearance!=STYLE_NONE) TextViewCompat.setTextAppearance(bubbleTextView, bubbleTextAppearance);
}
 
Example #18
Source File: AppDetailsRecyclerViewAdapter.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
HeaderViewHolder(View view) {
    super(view);
    iconView = (ImageView) view.findViewById(R.id.icon);
    titleView = (TextView) view.findViewById(R.id.title);
    authorView = (TextView) view.findViewById(R.id.author);
    lastUpdateView = (TextView) view.findViewById(R.id.text_last_update);
    summaryView = (TextView) view.findViewById(R.id.summary);
    whatsNewView = (TextView) view.findViewById(R.id.whats_new);
    descriptionView = (TextView) view.findViewById(R.id.description);
    descriptionMoreView = (TextView) view.findViewById(R.id.description_more);
    antiFeaturesSectionView =  view.findViewById(R.id.anti_features_section);
    antiFeaturesLabelView = (TextView) view.findViewById(R.id.label_anti_features);
    antiFeaturesWarningView = view.findViewById(R.id.anti_features_warning);
    antiFeaturesListingView = view.findViewById(R.id.anti_features_full_listing);
    buttonLayout = view.findViewById(R.id.button_layout);
    buttonPrimaryView = (Button) view.findViewById(R.id.primaryButtonView);
    buttonSecondaryView = (Button) view.findViewById(R.id.secondaryButtonView);
    progressLayout = view.findViewById(R.id.progress_layout);
    progressBar = (ProgressBar) view.findViewById(R.id.progress_bar);
    progressLabel = (TextView) view.findViewById(R.id.progress_label);
    progressPercent = (TextView) view.findViewById(R.id.progress_percent);
    progressCancel = view.findViewById(R.id.progress_cancel);
    descriptionView.setMaxLines(MAX_LINES);
    descriptionView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
    descriptionMoreView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make this "header section" the focused child, so that RecyclerView will use
            // it as the anchor in the layout process. Otherwise the RV might select another
            // view as the anchor, resulting in that the top of this view is instead scrolled
            // off the screen. Refer to LinearLayoutManager.updateAnchorFromChildren(...).
            recyclerView.requestChildFocus(itemView, itemView);
            if (TextViewCompat.getMaxLines(descriptionView) != MAX_LINES) {
                descriptionView.setMaxLines(MAX_LINES);
                descriptionMoreView.setText(R.string.more);
                descriptionIsExpanded = false;
            } else {
                descriptionView.setMaxLines(Integer.MAX_VALUE);
                descriptionMoreView.setText(R.string.less);
                descriptionIsExpanded = true;
            }
            updateAntiFeaturesWarning();
        }
    });
}
 
Example #19
Source File: ActivitySettings.java    From fingen with Apache License 2.0 4 votes vote down vote up
@SuppressLint("PrivateResource")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        switch (Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "0"))) {
            case ActivityMain.THEME_LIGHT : setTheme(R.style.AppThemeLight); break;
            case ActivityMain.THEME_DARK : setTheme(R.style.AppThemeDark); break;
            default: setTheme(R.style.AppThemeLight); break;
        }
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        mReplaceFragmentStrategy = new PreferenceScreenNavigationStrategy.ReplaceFragment(this, R.anim.abc_fade_in, R.anim.abc_fade_out, R.anim.abc_fade_in, R.anim.abc_fade_out);

        if (savedInstanceState == null) {
            mSettingsFragment = FragmentSettings.newInstance(null);
            getSupportFragmentManager().beginTransaction().add(R.id.content, mSettingsFragment, "Settings").commit();
        } else {
            mSettingsFragment = (FragmentSettings) getSupportFragmentManager().findFragmentByTag("Settings");
        }

        getSupportFragmentManager().addOnBackStackChangedListener(this);

        mToolbar = findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        ActionBar ab = getSupportActionBar();
        if (ab != null) {
            ab.setDisplayHomeAsUpEnabled(true);
        }

        // Cross-fading title setup.
        mTitle = getTitle();

        mTitleSwitcher = new TextSwitcher(mToolbar.getContext());
        mTitleSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                TextView tv = new AppCompatTextView(mToolbar.getContext());
                TextViewCompat.setTextAppearance(tv, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
                return tv;
            }
        });
        mTitleSwitcher.setCurrentText(mTitle);

        if (ab != null) {
            ab.setCustomView(mTitleSwitcher);
            ab.setDisplayShowCustomEnabled(true);
            ab.setDisplayShowTitleEnabled(false);
        }

        // Add to hierarchy before accessing layout params.
//        int margin = Util.dpToPxOffset(this, 16);
//        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mTitleSwitcher.getLayoutParams();
//        lp.leftMargin = margin;
//        lp.rightMargin = margin;

        mTitleSwitcher.setInAnimation(this, R.anim.abc_fade_in);
        mTitleSwitcher.setOutAnimation(this, R.anim.abc_fade_out);

        android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
    }
 
Example #20
Source File: AppDetailsRecyclerViewAdapter.java    From fdroidclient with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Depending on whether we are expanded or not, update the icon which indicates whether the
 * user can expand/collapse this item.
 */
protected void updateExpandableItem(boolean isExpanded) {
    TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(headerView, getIcon(), 0, isExpanded ? R.drawable.ic_expand_less_grey600 : R.drawable.ic_expand_more_grey600, 0);
}