Example usage for android.widget Button Button

List of usage examples for android.widget Button Button

Introduction

In this page you can find the example usage for android.widget Button Button.

Prototype

public Button(Context context, AttributeSet attrs, int defStyleAttr) 

Source Link

Document

This constructor allows a Button subclass to use its own class-specific base style from a theme attribute when inflating.

Usage

From source file:com.mishiranu.dashchan.ui.navigator.page.PostsPage.java

@Override
protected void onCreate() {
    Activity activity = getActivity();/*from  www  . j  a va 2s  . co  m*/
    PullableListView listView = getListView();
    PageHolder pageHolder = getPageHolder();
    UiManager uiManager = getUiManager();
    hidePerformer = new HidePerformer();
    PostsExtra extra = getExtra();
    listView.setDivider(ResourceUtils.getDrawable(activity, R.attr.postsDivider, 0));
    ChanConfiguration.Board board = getChanConfiguration().safe().obtainBoard(pageHolder.boardName);
    if (board.allowPosting) {
        replyable = data -> getUiManager().navigator().navigatePosting(pageHolder.chanName,
                pageHolder.boardName, pageHolder.threadNumber, data);
    }
    PostsAdapter adapter = new PostsAdapter(activity, pageHolder.chanName, pageHolder.boardName, uiManager,
            replyable, hidePerformer, extra.userPostNumbers, listView);
    initAdapter(adapter, adapter);
    ImageLoader.getInstance().observable().register(this);
    listView.getWrapper().setPullSides(PullableWrapper.Side.BOTH);
    uiManager.observable().register(this);
    hidePerformer.setPostsProvider(adapter);

    Context darkStyledContext = new ContextThemeWrapper(activity, R.style.Theme_General_Main_Dark);
    searchController = new LinearLayout(darkStyledContext);
    searchController.setOrientation(LinearLayout.HORIZONTAL);
    searchController.setGravity(Gravity.CENTER_VERTICAL);
    float density = ResourceUtils.obtainDensity(getResources());
    int padding = (int) (10f * density);
    searchTextResult = new Button(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
    searchTextResult.setTextSize(11f);
    if (!C.API_LOLLIPOP) {
        searchTextResult.setTypeface(null, Typeface.BOLD);
    }
    searchTextResult.setPadding((int) (14f * density), 0, (int) (14f * density), 0);
    searchTextResult.setMinimumWidth(0);
    searchTextResult.setMinWidth(0);
    searchTextResult.setOnClickListener(v -> showSearchDialog());
    searchController.addView(searchTextResult, LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    ImageView backButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
    backButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    backButtonView.setImageResource(obtainIcon(R.attr.actionBack));
    backButtonView.setPadding(padding, padding, padding, padding);
    backButtonView.setOnClickListener(v -> findBack());
    searchController.addView(backButtonView, (int) (48f * density), (int) (48f * density));
    ImageView forwardButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
    forwardButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    forwardButtonView.setImageResource(obtainIcon(R.attr.actionForward));
    forwardButtonView.setPadding(padding, padding, padding, padding);
    forwardButtonView.setOnClickListener(v -> findForward());
    searchController.addView(forwardButtonView, (int) (48f * density), (int) (48f * density));
    if (C.API_LOLLIPOP) {
        for (int i = 0, last = searchController.getChildCount() - 1; i <= last; i++) {
            View view = searchController.getChildAt(i);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            if (i == 0) {
                layoutParams.leftMargin = (int) (-6f * density);
            }
            if (i == last) {
                layoutParams.rightMargin = (int) (6f * density);
            } else {
                layoutParams.rightMargin = (int) (-6f * density);
            }
        }
    }

    scrollToPostNumber = pageHolder.initialPostNumber;
    FavoritesStorage.getInstance().getObservable().register(this);
    LocalBroadcastManager.getInstance(activity).registerReceiver(galleryPagerReceiver,
            new IntentFilter(C.ACTION_GALLERY_NAVIGATE_POST));
    boolean hasNewPostDatas = handleNewPostDatas();
    extra.forceRefresh = hasNewPostDatas || !pageHolder.initialFromCache;
    if (extra.cachedPosts != null && extra.cachedPostItems.size() > 0) {
        onDeserializePostsCompleteInternal(true, extra.cachedPosts, new ArrayList<>(extra.cachedPostItems),
                true);
    } else {
        deserializeTask = new DeserializePostsTask(this, pageHolder.chanName, pageHolder.boardName,
                pageHolder.threadNumber, extra.cachedPosts);
        deserializeTask.executeOnExecutor(DeserializePostsTask.THREAD_POOL_EXECUTOR);
        getListView().getWrapper().startBusyState(PullableWrapper.Side.BOTH);
        switchView(ViewType.PROGRESS, null);
    }
    pageHolder.setInitialPostsData(false, null);
}