Example usage for android.view View setEnabled

List of usage examples for android.view View setEnabled

Introduction

In this page you can find the example usage for android.view View setEnabled.

Prototype

@RemotableViewMethod
public void setEnabled(boolean enabled) 

Source Link

Document

Set the enabled state of this view.

Usage

From source file:com.jefftharris.passwdsafe.sync.MainActivity.java

/** Update the UI when the OneDrive account is changed */
private void updateOnedriveAccount(Cursor cursor) {
    boolean haveCursor = (cursor != null);
    GuiUtils.setVisible(findViewById(R.id.onedrive_container), haveCursor);
    GuiUtils.setVisible(findViewById(R.id.onedrive_separator), haveCursor);
    if (haveCursor) {
        long id = cursor.getLong(PasswdSafeContract.Providers.PROJECTION_IDX_ID);
        String acct = PasswdSafeContract.Providers.getDisplayName(cursor);
        int freqVal = cursor.getInt(PasswdSafeContract.Providers.PROJECTION_IDX_SYNC_FREQ);
        ProviderSyncFreqPref freq = ProviderSyncFreqPref.freqValueOf(freqVal);
        itsOnedriveUri = ContentUris.withAppendedId(PasswdSafeContract.Providers.CONTENT_URI, id);

        Provider provider = getOnedriveProvider();
        boolean authorized = provider.isAccountAuthorized();

        TextView acctView = (TextView) findViewById(R.id.onedrive_acct);
        assert acctView != null;
        acctView.setText(acct);/*  w  ww . j  a  v  a 2  s  . co  m*/

        GuiUtils.setVisible(findViewById(R.id.onedrive_auth_required), !authorized);

        View freqSpinLabel = findViewById(R.id.onedrive_interval_label);
        assert freqSpinLabel != null;
        Spinner freqSpin = (Spinner) findViewById(R.id.onedrive_interval);
        assert freqSpin != null;
        freqSpin.setSelection(freq.getDisplayIdx());

        freqSpin.setEnabled(true);
        freqSpinLabel.setEnabled(true);
    } else {
        itsOnedriveUri = null;
    }
}

From source file:com.ayuget.redface.ui.activity.TopicsActivity.java

/**
 * Shows the "Go to page" dialog where the user can enter the page he wants to consult.
 * @param topic topic concerned by the action
 *///from  w  w w .  ja  v a  2s.com
public void showGoToPageDialog(final Topic topic) {
    MaterialDialog dialog = new MaterialDialog.Builder(this).customView(R.layout.dialog_go_to_page, true)
            .positiveText(R.string.dialog_go_to_page_positive_text).negativeText(android.R.string.cancel)
            .theme(themeManager.getMaterialDialogTheme()).callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    try {
                        int pageNumber = Integer.valueOf(goToPageEditText.getText().toString());
                        loadTopic(topic, pageNumber, new PagePosition(PagePosition.TOP));
                    } catch (NumberFormatException e) {
                        Log.e(LOG_TAG, String.format("Invalid page number entered : %s",
                                goToPageEditText.getText().toString()), e);
                        SnackbarHelper.makeError(TopicsActivity.this, R.string.invalid_page_number).show();
                    }
                }

                @Override
                public void onNegative(MaterialDialog dialog) {
                }
            }).build();

    final View positiveAction = dialog.getActionButton(DialogAction.POSITIVE);
    goToPageEditText = (MaterialEditText) dialog.getCustomView().findViewById(R.id.page_number);

    goToPageEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.toString().trim().length() > 0) {
                try {
                    int pageNumber = Integer.valueOf(s.toString());
                    positiveAction.setEnabled(pageNumber >= 1 && pageNumber <= topic.getPagesCount());
                } catch (NumberFormatException e) {
                    positiveAction.setEnabled(false);
                }
            } else {
                positiveAction.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    dialog.show();
    positiveAction.setEnabled(false);
}

From source file:com.google.plus.samples.photohunt.ViewImageActivity.java

private void vote(View view) {
    if (!mPlus.isAuthenticated()) {
        requireSignIn();/*from  w  w  w .  ja  v  a  2 s.c o m*/
        mPendingClick = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                vote(view);
            }
        };
        mPendingView = view;
        return;
    }

    if (mPhoto != null && mPhotoUser != null && !mPhoto.hasAuthor(mPhotoUser) && mPhoto.voted) {
        // Submit the vote.
        mPhotoClient.vote(mPhoto.id,
                new ClickCallback<Photo>(this, view, R.string.vote_success, R.string.vote_failure) {
                    @Override
                    public void onError(Photo photo) {
                        super.onError(photo);

                        mPhoto.numVotes -= 1;
                        mPhoto.voted = false;
                        update();
                    }
                });
        view.setEnabled(false);

        // Optimistic update.
        mPhoto.numVotes += 1;
        mPhoto.voted = true;
        update();
    }
}

From source file:com.hughes.android.dictionary.DictionaryManagerActivity.java

private View createDictionaryRow(final DictionaryInfo dictionaryInfo, final ViewGroup parent,
        boolean canLaunch) {

    View row = LayoutInflater.from(parent.getContext()).inflate(R.layout.dictionary_manager_row, parent, false);
    final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
    final TextView details = (TextView) row.findViewById(R.id.dictionaryDetails);
    name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));

    final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
    final Button downloadButton = (Button) row.findViewById(R.id.downloadButton);
    final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
    boolean broken = false;
    if (!dictionaryInfo.isValid()) {
        broken = true;/*from  w ww .j a  va  2 s .co m*/
        canLaunch = false;
    }
    if (downloadable != null && (!canLaunch || updateAvailable)) {
        downloadButton.setText(getString(R.string.downloadButton, downloadable.zipBytes / 1024.0 / 1024.0));
        downloadButton.setMinWidth(application.languageButtonPixels * 3 / 2);
        downloadButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                downloadDictionary(downloadable.downloadUrl, downloadable.zipBytes, downloadButton);
            }
        });
    } else {
        downloadButton.setVisibility(View.INVISIBLE);
    }

    LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
    final List<IndexInfo> sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos);
    final StringBuilder builder = new StringBuilder();
    if (updateAvailable) {
        builder.append(getString(R.string.updateAvailable));
    }
    for (IndexInfo indexInfo : sortedIndexInfos) {
        final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo);
        buttons.addView(button);

        if (canLaunch) {
            button.setOnClickListener(new IntentLauncher(buttons.getContext(),
                    DictionaryActivity.getLaunchIntent(getApplicationContext(),
                            application.getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName,
                            "")));

        } else {
            button.setEnabled(false);
            button.setFocusable(false);
        }
        if (builder.length() != 0) {
            builder.append("; ");
        }
        builder.append(getString(R.string.indexInfo, indexInfo.shortName, indexInfo.mainTokenCount));
    }
    builder.append("; ");
    builder.append(getString(R.string.downloadButton, dictionaryInfo.uncompressedBytes / 1024.0 / 1024.0));
    if (broken) {
        name.setText("Broken: " + application.getDictionaryName(dictionaryInfo.uncompressedFilename));
        builder.append("; Cannot be used, redownload, check hardware/file system");
        // Allow deleting, but cannot open
        row.setLongClickable(true);
    }
    details.setText(builder.toString());

    if (canLaunch) {
        row.setClickable(true);
        row.setOnClickListener(new IntentLauncher(parent.getContext(),
                DictionaryActivity.getLaunchIntent(getApplicationContext(),
                        application.getPath(dictionaryInfo.uncompressedFilename),
                        dictionaryInfo.indexInfos.get(0).shortName, "")));
        // do not setFocusable, for keyboard navigation
        // offering only the index buttons is better.
        row.setLongClickable(true);
    }
    row.setBackgroundResource(android.R.drawable.menuitem_background);

    return row;
}

From source file:org.wikipedia.edit.EditSectionActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_edit_section, menu);
    MenuItem item = menu.findItem(R.id.menu_save_section);

    if (editSummaryFragment.isActive()) {
        item.setTitle(getString(R.string.edit_next));
    } else if (editPreviewFragment.isActive()) {
        item.setTitle(getString(R.string.edit_done));
    } else {//from   www .j  av  a  2 s.  co  m
        item.setTitle(getString(R.string.edit_next));
    }

    if (abusefilterEditResult != null) {
        if (abusefilterEditResult.getType() == EditAbuseFilterResult.TYPE_ERROR) {
            item.setEnabled(false);
        } else {
            item.setEnabled(true);
        }
    } else {
        item.setEnabled(sectionTextModified);
    }

    View v = getLayoutInflater().inflate(R.layout.item_edit_actionbar_button, null);
    item.setActionView(v);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    v.setLayoutParams(params);
    TextView txtView = v.findViewById(R.id.edit_actionbar_button_text);
    txtView.setText(item.getTitle());
    txtView.setTypeface(null, item.isEnabled() ? Typeface.BOLD : Typeface.NORMAL);
    v.setTag(item);
    v.setClickable(true);
    v.setEnabled(item.isEnabled());
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onOptionsItemSelected((MenuItem) view.getTag());
        }
    });

    v.setBackgroundColor(ContextCompat.getColor(this,
            item.isEnabled()
                    ? (editPreviewFragment.isActive() ? R.color.accent50
                            : ResourceUtil.getThemedAttributeId(this, R.attr.colorAccent))
                    : R.color.base50));

    return true;
}

From source file:com.androidquery.simplefeed.fragments.FeedFragment.java

@Override
public void onClick(View view) {

    try {//  w  w  w  .  jav a  2  s . c om

        int id = view.getId();

        FeedItem item = getItem(view);
        AQUtility.debug("click", item);
        if (item == null)
            return;

        actionItem = item;

        switch (id) {
        case R.id.button_like:
            like(item);
            view.setEnabled(false);
            break;
        case R.id.content_tb:
        case R.id.content_name:
            contentClicked(item);
            break;
        case R.id.button_comment:
            comments();
            break;
        case R.id.tb:
        case R.id.name:
        case R.id.button_source1:
            AQUtility.debug("source1");
            userWall(false);
            break;
        case R.id.name2:
        case R.id.button_source2:
            userWall(true);
            break;
        }
    } catch (Exception e) {
        AQUtility.report(e);
    }

}

From source file:org.solovyev.android.messenger.messages.MessagesFragment.java

@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
    super.onViewCreated(root, savedInstanceState);

    final View sendButton = root.findViewById(R.id.mpp_message_bubble_send_button);
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override//from   w  w w  .ja v a 2s .  c o  m
        public void onClick(View v) {
            sendMessage();
        }
    });

    messageBody = (EditText) root.findViewById(R.id.mpp_message_bubble_body_edittext);
    messageBody.setText(getChatService().getDraftMessage(chat));
    messageBody.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (isEmpty(s)) {
                sendButton.setEnabled(false);
            } else {
                sendButton.setEnabled(true);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    final String title;
    if (chat.isPrivate()) {
        title = getString(R.string.mpp_private_chat_title, Users.getDisplayNameFor(chat.getSecondUser()));
    } else {
        title = getString(R.string.mpp_public_chat_title);
    }
    getMultiPaneManager().showTitle(getSherlockActivity(), this, title);
}

From source file:com.battlelancer.seriesguide.ui.OverviewFragment.java

@SuppressLint("NewApi")
private void onPopulateEpisodeData(Cursor episode) {
    mCurrentEpisodeCursor = episode;/* ww  w  . j a va2 s  .  c  om*/

    final TextView episodeTitle = (TextView) getView().findViewById(R.id.episodeTitle);
    final TextView episodeTime = (TextView) getView().findViewById(R.id.episodeTime);
    final TextView episodeSeasonAndNumber = (TextView) getView().findViewById(R.id.episodeInfo);
    final View episodemeta = getView().findViewById(R.id.episode_meta_container);
    final View episodePrimaryContainer = getView().findViewById(R.id.episode_primary_container);
    final View buttons = getView().findViewById(R.id.buttonbar);
    final View ratings = getView().findViewById(R.id.ratingbar);

    if (episode != null && episode.moveToFirst()) {
        // some episode properties
        mCurrentEpisodeTvdbId = episode.getInt(EpisodeQuery._ID);

        // title
        episodeTitle.setText(episode.getString(EpisodeQuery.TITLE));

        // number
        StringBuilder infoText = new StringBuilder();
        infoText.append(getString(R.string.season_number, episode.getInt(EpisodeQuery.SEASON)));
        infoText.append(" ");
        int episodeNumber = episode.getInt(EpisodeQuery.NUMBER);
        infoText.append(getString(R.string.episode_number, episodeNumber));
        int episodeAbsoluteNumber = episode.getInt(EpisodeQuery.ABSOLUTE_NUMBER);
        if (episodeAbsoluteNumber > 0 && episodeAbsoluteNumber != episodeNumber) {
            infoText.append(" (").append(episodeAbsoluteNumber).append(")");
        }
        episodeSeasonAndNumber.setText(infoText);

        // air date
        long releaseTime = episode.getLong(EpisodeQuery.FIRST_RELEASE_MS);
        if (releaseTime != -1) {
            Date actualRelease = TimeTools.getEpisodeReleaseTime(getActivity(), releaseTime);
            // "in 14 mins (Fri)"
            episodeTime.setText(getString(R.string.release_date_and_day,
                    TimeTools.formatToRelativeLocalReleaseTime(getActivity(), actualRelease),
                    TimeTools.formatToLocalReleaseDay(actualRelease)));
        } else {
            episodeTime.setText(null);
        }

        // make title and image clickable
        episodePrimaryContainer.setOnClickListener(new OnClickListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onClick(View view) {
                // display episode details
                Intent intent = new Intent(getActivity(), EpisodesActivity.class);
                intent.putExtra(EpisodesActivity.InitBundle.EPISODE_TVDBID, mCurrentEpisodeTvdbId);

                ActivityCompat.startActivity(getActivity(), intent, ActivityOptionsCompat
                        .makeScaleUpAnimation(view, 0, 0, view.getWidth(), view.getHeight()).toBundle());
            }
        });
        episodePrimaryContainer.setFocusable(true);

        // Button bar
        // check-in button
        View checkinButton = buttons.findViewById(R.id.buttonEpisodeCheckin);
        checkinButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onCheckIn();
            }
        });
        CheatSheet.setup(checkinButton);

        // watched button
        View watchedButton = buttons.findViewById(R.id.buttonEpisodeWatched);
        watchedButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable button, will be re-enabled on data reload once action completes
                v.setEnabled(false);
                onEpisodeWatched();
            }
        });
        watchedButton.setEnabled(true);
        CheatSheet.setup(watchedButton);

        // collected button
        boolean isCollected = episode.getInt(EpisodeQuery.COLLECTED) == 1;
        Button collectedButton = (Button) buttons.findViewById(R.id.buttonEpisodeCollected);
        Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(collectedButton, 0,
                isCollected ? R.drawable.ic_collected
                        : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollect),
                0, 0);
        collectedButton
                .setText(isCollected ? R.string.action_collection_remove : R.string.action_collection_add);
        CheatSheet.setup(collectedButton,
                isCollected ? R.string.action_collection_remove : R.string.action_collection_add);
        collectedButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable button, will be re-enabled on data reload once action completes
                v.setEnabled(false);
                onToggleCollected();
            }
        });
        collectedButton.setEnabled(true);

        // skip button
        View skipButton = buttons.findViewById(R.id.buttonEpisodeSkip);
        skipButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable button, will be re-enabled on data reload once action completes
                v.setEnabled(false);
                onEpisodeSkipped();
            }
        });
        skipButton.setEnabled(true);
        CheatSheet.setup(skipButton);

        // ratings
        ratings.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                rateOnTrakt();
            }
        });
        ratings.setFocusable(true);
        CheatSheet.setup(ratings, R.string.action_rate);

        // load all other info
        onLoadEpisodeDetails(episode);

        // episode image
        onLoadImage(episode.getString(EpisodeQuery.IMAGE));

        // episode actions
        loadEpisodeActionsDelayed();

        episodemeta.setVisibility(View.VISIBLE);
    } else {
        // no next episode: display single line info text, remove other
        // views
        episodeTitle.setText(R.string.no_nextepisode);
        episodeTime.setText(null);
        episodeSeasonAndNumber.setText(null);
        episodePrimaryContainer.setOnClickListener(null);
        episodePrimaryContainer.setClickable(false);
        episodePrimaryContainer.setFocusable(false);
        episodemeta.setVisibility(View.GONE);
        ratings.setOnClickListener(null);
        ratings.setClickable(false);
        ratings.setFocusable(false);
        onLoadImage(null);
    }

    // enable/disable applicable menu items
    getActivity().invalidateOptionsMenu();

    // animate view into visibility
    if (mContainerEpisode.getVisibility() == View.GONE) {
        final View progressContainer = getView().findViewById(R.id.progress_container);
        progressContainer.startAnimation(
                AnimationUtils.loadAnimation(episodemeta.getContext(), android.R.anim.fade_out));
        progressContainer.setVisibility(View.GONE);
        mContainerEpisode
                .startAnimation(AnimationUtils.loadAnimation(episodemeta.getContext(), android.R.anim.fade_in));
        mContainerEpisode.setVisibility(View.VISIBLE);
    }
}

From source file:universe.constellation.orion.viewer.OrionViewerActivity.java

public void initCropScreen() {
    TableLayout cropTable = (TableLayout) findMyViewById(R.id.crop_borders);

    getSubscriptionManager().addDocListeners(new DocumentViewAdapter() {
        @Override// w  w w  . j  ava  2s.c  o m
        public void documentOpened(Controller controller) {
            updateCrops();
        }
    });

    for (int i = 0; i < cropTable.getChildCount(); i++) {
        TableRow row = (TableRow) cropTable.getChildAt(i);
        row.findViewById(R.id.crop_plus);

        TextView valueView = (TextView) row.findViewById(R.id.crop_value);
        ImageButton plus = (ImageButton) row.findViewById(R.id.crop_plus);
        ImageButton minus = (ImageButton) row.findViewById(R.id.crop_minus);
        linkCropButtonsAndText(minus, plus, valueView, i);
    }

    //even cropping
    int index = 4;
    final TableLayout cropTable2 = (TableLayout) findMyViewById(R.id.crop_borders_even);
    for (int i = 0; i < cropTable2.getChildCount(); i++) {
        View child = cropTable2.getChildAt(i);
        if (child instanceof TableRow) {
            TableRow row = (TableRow) child;
            row.findViewById(R.id.crop_plus);
            TextView valueView = (TextView) row.findViewById(R.id.crop_value);
            ImageButton plus = (ImageButton) row.findViewById(R.id.crop_plus);
            ImageButton minus = (ImageButton) row.findViewById(R.id.crop_minus);
            linkCropButtonsAndText(minus, plus, valueView, index);
            index++;
            for (int j = 0; j < row.getChildCount(); j++) {
                View v = row.getChildAt(j);
                v.setEnabled(false);
            }
        }
    }

    final ImageButton switchEven = (ImageButton) findMyViewById(R.id.crop_even_button);
    if (switchEven != null) {
        final ViewAnimator cropAnim = (ViewAnimator) findMyViewById(R.id.crop_animator);
        switchEven.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                cropAnim.setDisplayedChild((cropAnim.getDisplayedChild() + 1) % 2);
                switchEven.setImageResource(
                        cropAnim.getDisplayedChild() == 0 ? R.drawable.next : R.drawable.prev);
            }
        });
    }

    final CheckBox checkBox = (CheckBox) findMyViewById(R.id.crop_even_flag);
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            for (int i = 0; i < cropTable2.getChildCount(); i++) {
                View child = cropTable2.getChildAt(i);
                if (child instanceof TableRow) {
                    TableRow row = (TableRow) child;
                    for (int j = 0; j < row.getChildCount(); j++) {
                        View rowChild = row.getChildAt(j);
                        rowChild.setEnabled(isChecked);
                    }
                }
            }
        }
    });

    //        if (Device.Info.NOOK2) {
    //            TextView tv = (TextView) findMyViewById(R.id.navigation_title);
    //            int color = tv.getTextColors().getDefaultColor();
    //            checkBox.setTextColor(color);
    //        }

    ImageButton preview = (ImageButton) findMyViewById(R.id.crop_preview);
    preview.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            onApplyAction();
            controller.changeMargins(cropBorders[0], cropBorders[2], cropBorders[1], cropBorders[3],
                    checkBox.isChecked(), cropBorders[4], cropBorders[5]);
        }
    });

    ImageButton close = (ImageButton) findMyViewById(R.id.crop_close);
    close.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //main menu
            onAnimatorCancel();
            //reset if canceled
            updateCrops();
        }
    });
}

From source file:com.vest.album.fragment.CameraBasicFragment.java

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.camera_picture: {
        takePicture();/*from  ww  w.j  av a  2  s. c  o  m*/
        view.setVisibility(View.GONE);
        break;
    }
    case R.id.camera_cancel_btn: {
        callback.onPhotoError("1");
    }
        break;
    case R.id.camera_sure_btn: {
        view.setClickable(false);
        view.setFocusable(false);
        view.setEnabled(false);
        sureSave();
    }
        break;
    }
}