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:eu.alefzero.owncloud.ui.fragment.FileDetailFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.fdDownloadBtn: {
        //Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();
        Intent i = new Intent(getActivity(), FileDownloader.class);
        i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
        i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath());
        i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath());
        i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());
        v.setEnabled(false);
        getActivity().startService(i);/*  w  w w  .ja v a2 s .c o m*/
        break;
    }
    case R.id.fdKeepInSync: {
        CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
        mFile.setKeepInSync(cb.isChecked());
        FileDataStorageManager fdsm = new FileDataStorageManager(mAccount,
                getActivity().getApplicationContext().getContentResolver());
        fdsm.saveFile(mFile);
        if (mFile.keepInSync()) {
            onClick(getView().findViewById(R.id.fdDownloadBtn));
        }
        break;
    }
    case R.id.fdRenameBtn: {
        EditNameFragment dialog = EditNameFragment.newInstance(mFile.getFileName());
        dialog.show(getFragmentManager(), "nameeditdialog");
        dialog.setOnDismissListener(this);
        break;
    }
    case R.id.fdRemoveBtn: {
        ConfirmationDialogFragment confDialog = ConfirmationDialogFragment
                .newInstance("to remove " + mFile.getFileName());
        confDialog.setOnConfirmationListener(this);
        confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
        break;
    }
    default:
        Log.e(TAG, "Incorrect view clicked!");
    }

    /* else if (v.getId() == R.id.fdShareBtn) {
    Thread t = new Thread(new ShareRunnable(mFile.getRemotePath()));
    t.start();
    }*/
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

private void displayWidget(LinearLayout widgetLayout, BrandingResult br) {
    final String type = (String) mCurrentMessage.form.get("type");

    widgetLayout.removeAllViews();/*  w  w w .j a v  a2 s  .co  m*/

    final Widget widget = (Widget) getLayoutInflater().inflate(Widget.RESOURCES.get(type), null, false);
    if (br != null) {
        widget.setColorScheme(br.scheme);
    }
    widget.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    widget.setEnabled(widgetLayout.isEnabled());
    widget.loadMessage(mCurrentMessage, this, widgetLayout);

    if (!widgetLayout.isEnabled()) {
        for (int i = 0; i < widget.getChildCount(); i++) {
            View v = widget.getChildAt(i);
            v.setEnabled(false);
        }
    }
    widgetLayout.addView(widget);
}

From source file:com.achep.acdisplay.ui.widgets.notification.NotificationActions.java

/**
 * Sets new actions.//from w  w  w .j a  v  a 2 s . c o  m
 *
 * @param notification the host notification
 * @param actions      the actions to set
 */
public void setActions(@Nullable OpenNotification notification, @Nullable Action[] actions) {
    Check.getInstance().isInMainThread();

    mRemoteInputsMap.clear();
    mActionsMap.clear();
    hideRii();

    if (actions == null) {
        // Free actions' container.
        removeAllViews();
        return;
    } else {
        assert notification != null;
    }

    int count = actions.length;
    View[] views = new View[count];

    // Find available views.
    int childCount = getChildCount();
    int a = Math.min(childCount, count);
    for (int i = 0; i < a; i++) {
        views[i] = getChildAt(i);
    }

    // Remove redundant views.
    for (int i = childCount - 1; i >= count; i--) {
        removeViewAt(i);
    }

    LayoutInflater inflater = null;
    for (int i = 0; i < count; i++) {
        final Action action = actions[i];
        View root = views[i];

        if (root == null) {
            // Initialize layout inflater only when we really need it.
            if (inflater == null) {
                inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                assert inflater != null;
            }

            root = inflater.inflate(getActionLayoutResource(), this, false);
            root = onCreateActionView(root);
            // We need to keep all IDs unique to make
            // TransitionManager.beginDelayedTransition(viewGroup, null)
            // work correctly!
            root.setId(getChildCount() + 1);
            addView(root);
        }

        mActionsMap.put(root, action);

        int style = Typeface.NORMAL;
        root.setOnLongClickListener(null);
        if (action.intent != null) {
            root.setEnabled(true);
            root.setOnClickListener(mActionsOnClick);

            RemoteInput remoteInput = getRemoteInput(action);
            if (remoteInput != null) {
                mRemoteInputsMap.put(action, remoteInput);
                root.setOnLongClickListener(mActionsOnLongClick);

                // Highlight the action
                style = Typeface.ITALIC;
            }
        } else {
            root.setEnabled(false);
            root.setOnClickListener(null);
        }

        // Get message view and apply the content.
        TextView textView = root instanceof TextView ? (TextView) root
                : (TextView) root.findViewById(android.R.id.title);
        textView.setText(action.title);
        if (mTypeface == null)
            mTypeface = textView.getTypeface();
        textView.setTypeface(mTypeface, style);

        Drawable icon = NotificationUtils.getDrawable(getContext(), notification, action.icon);
        if (icon != null)
            icon = onCreateActionIcon(icon);

        if (Device.hasJellyBeanMR1Api()) {
            textView.setCompoundDrawablesRelative(icon, null, null, null);
        } else {
            textView.setCompoundDrawables(icon, null, null, null);
        }
    }
}

From source file:android.support.v7.internal.widget.SpinnerCompat.java

/**
 * Helper for makeAndAddView to set the position of a view and fill out its layout paramters.
 *
 * @param child    The view to position/*from   w w w  .  ja  v  a2 s .c  o m*/
 * @param addChild true if the child should be added to the Spinner during setup
 */
private void setUpChild(View child, boolean addChild) {

    // Respect layout params that are already in the view. Otherwise
    // make some up...
    ViewGroup.LayoutParams lp = child.getLayoutParams();
    if (lp == null) {
        lp = generateDefaultLayoutParams();
    }

    if (addChild) {
        addViewInLayout(child, 0, lp);
    }

    child.setSelected(hasFocus());
    if (mDisableChildrenWhenDisabled) {
        child.setEnabled(isEnabled());
    }

    // Get measure specs
    int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec,
            mSpinnerPadding.top + mSpinnerPadding.bottom, lp.height);
    int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec,
            mSpinnerPadding.left + mSpinnerPadding.right, lp.width);

    // Measure child
    child.measure(childWidthSpec, childHeightSpec);

    int childLeft;
    int childRight;

    // Position vertically based on gravity setting
    int childTop = mSpinnerPadding.top
            + ((getMeasuredHeight() - mSpinnerPadding.bottom - mSpinnerPadding.top - child.getMeasuredHeight())
                    / 2);
    int childBottom = childTop + child.getMeasuredHeight();

    int width = child.getMeasuredWidth();
    childLeft = 0;
    childRight = childLeft + width;

    child.layout(childLeft, childTop, childRight, childBottom);
}

From source file:io.openkit.leaderboards.OKScoresFragment.java

private void getMoreScores(OKLeaderboardTimeRange range, final View v) {
    final OKScoresListAdapter adapter = getAdapterforRange(range);

    // You can't get MORE scores if you don't have any scores to begin with
    if (adapter == null) {
        return;// www.  ja v  a  2s  . co  m
    }

    currentLeaderboard.setDisplayedTimeRange(range);

    // Calculate how many pages of scores have already been loaded
    int numScores = adapter.getCount();
    int currentPageNumber = numScores / OKLeaderboard.NUM_SCORES_PER_PAGE;
    if (currentPageNumber * OKLeaderboard.NUM_SCORES_PER_PAGE < numScores) {
        currentPageNumber++;
    }

    int nextPageNumber = currentPageNumber + 1;

    // Get the next page of scores
    currentLeaderboard.getLeaderboardScores(nextPageNumber, new OKScoresResponseHandler() {

        @Override
        public void onSuccess(List<OKScore> scoresList) {

            //Iterate through and add each score because Android 2.3 doesn't have addAll
            for (int x = 0; x < scoresList.size(); x++) {
                adapter.add(scoresList.get(x));
            }

            v.setEnabled(true);
        }

        @Override
        public void onFailure(Throwable e, JSONObject errorResponse) {
            //Didn't get any more scores, renable the button
            v.setEnabled(true);
        }
    });
}

From source file:openscience.crowdsource.video.experiments.MainActivity.java

private void updateControlStatusPreloading(boolean isEnable) {
    startStopCam.setEnabled(isEnable);//from w w  w . j  a  v  a  2  s.co m
    recognize.setEnabled(isEnable);
    btnOpenImage.setEnabled(isEnable);
    View selectedScenarioTopBar = findViewById(R.id.selectedScenarioTopBar);
    if (isEnable && RecognitionScenarioService.isRecognitionScenariosLoaded()) {
        selectedScenarioTopBar.setEnabled(true);
        consoleEditText.setVisibility(View.GONE);
        recognize.setVisibility(View.VISIBLE);
        startStopCam.setVisibility(View.VISIBLE);
        btnOpenImage.setVisibility(View.VISIBLE);

        ImageView downArrowSelectedScenarioTopBar = (ImageView) findViewById(R.id.ico_scenarioInfo);
        downArrowSelectedScenarioTopBar.setVisibility(View.VISIBLE);
    } else {
        TextView selectScenarioText = (TextView) findViewById(R.id.selectedScenarioText);
        if (isEnable) {
            selectScenarioText.setText(RecognitionScenarioService.NOT_FOUND_TEXT);
        }

    }
    final TextView resultPreviewText = (TextView) findViewById(R.id.resultPreviewtText);
    if (!isEnable) {
        consoleEditText.setVisibility(View.VISIBLE);
        recognize.setVisibility(View.GONE);
        startStopCam.setVisibility(View.GONE);
        btnOpenImage.setVisibility(View.GONE);
        resultPreviewText.setText(AppConfigService.PLEASE_WAIT);
        AppConfigService.updatePreviewRecognitionText(AppConfigService.PLEASE_WAIT);
        ImageView downArrowSelectedScenarioTopBar = (ImageView) findViewById(R.id.ico_scenarioInfo);
        downArrowSelectedScenarioTopBar.setVisibility(View.GONE);
    } else {
        resultPreviewText.setText("");
        AppConfigService.updatePreviewRecognitionText(null);
    }
}

From source file:dev.dworks.apps.anexplorer.fragment.DirectoryFragment.java

private void setEnabledRecursive(View v, boolean enabled) {
    if (v == null)
        return;//from w w  w  .  j av  a  2 s  . c  o  m
    if (v.isEnabled() == enabled)
        return;
    v.setEnabled(enabled);

    if (v instanceof ViewGroup) {
        final ViewGroup vg = (ViewGroup) v;
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            setEnabledRecursive(vg.getChildAt(i), enabled);
        }
    }
}

From source file:com.juick.android.UserCenterActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    JuickAdvancedApplication.setupTheme(this);
    handler = new Handler();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.user_center);
    final ListView list = (ListView) findViewById(R.id.list);
    final View listWait = findViewById(R.id.list_wait);
    final TextView userRealName = (TextView) findViewById(R.id.user_realname);
    final ImageView userPic = (ImageView) findViewById(R.id.userpic);
    final TextView userName = (TextView) findViewById(R.id.username);
    search = findViewById(R.id.search);/*from ww  w .  j  av  a2 s. c  o  m*/
    final View stats = findViewById(R.id.stats);
    userRealName.setText("...");
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        finish();
        return;
    }
    uname = extras.getString("uname");
    final int uid = extras.getInt("uid");

    final MessageID mid = (MessageID) extras.getSerializable("mid");
    final MessagesSource messagesSource = (MessagesSource) extras.getSerializable("messagesSource");
    if (uname == null || mid == null) {
        finish();
        return;
    }
    int height = getWindow().getWindowManager().getDefaultDisplay().getHeight();
    final int userpicSize = height <= 320 ? 32 : 96;
    float scaledDensity = getResources().getDisplayMetrics().scaledDensity;
    userPic.setMinimumHeight((int) (scaledDensity * userpicSize));
    userPic.setMinimumWidth((int) (scaledDensity * userpicSize));
    stats.setEnabled(false);
    userName.setText("@" + uname);
    final boolean russian = Locale.getDefault().getLanguage().equals("ru");
    new Thread() {
        @Override
        public void run() {
            final Utils.RESTResponse json = Utils.getJSON(UserCenterActivity.this,
                    "http://" + Utils.JA_ADDRESS + "/api/userinfo?uname=" + Uri.encode(uname), null);
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    stats.setEnabled(true);
                    if (json.getErrorText() != null) {
                        Toast.makeText(UserCenterActivity.this, "JA server: " + json.getErrorText(),
                                Toast.LENGTH_LONG).show();
                        listWait.setVisibility(View.GONE);
                    } else {
                        final UserInfo userInfo = new Gson().fromJson(json.getResult(), UserInfo.class);
                        if (userInfo == null) {
                            Toast.makeText(UserCenterActivity.this, "Unable to parse JSON", Toast.LENGTH_LONG)
                                    .show();
                            listWait.setVisibility(View.GONE);
                        } else {
                            userRealName.setText(userInfo.fullName);
                            listWait.setVisibility(View.GONE);
                            list.setVisibility(View.VISIBLE);
                            list.setAdapter(new BaseAdapter() {
                                @Override
                                public int getCount() {
                                    return userInfo.getExtraInfo().size();
                                }

                                @Override
                                public Object getItem(int position) {
                                    return userInfo.getExtraInfo().get(position);
                                }

                                @Override
                                public long getItemId(int position) {
                                    return position;
                                }

                                @Override
                                public View getView(int position, View convertView, ViewGroup parent) {
                                    if (convertView == null) {
                                        convertView = getLayoutInflater().inflate(R.layout.listitem_userinfo,
                                                null);
                                    }
                                    TextView text = (TextView) convertView.findViewById(R.id.text);
                                    TextView text2 = (TextView) convertView.findViewById(R.id.text2);
                                    String info = userInfo.getExtraInfo().get(position);
                                    int ix = info.indexOf("|");
                                    if (ix == -1) {
                                        text.setText(info);
                                        if (russian && UserInfo.translations.containsKey(info)) {
                                            info = UserInfo.translations.get(info);
                                        }
                                        text2.setText("");
                                    } else {
                                        String theInfo = info.substring(0, ix);
                                        if (russian && UserInfo.translations.containsKey(theInfo)) {
                                            theInfo = UserInfo.translations.get(theInfo);
                                        }
                                        text.setText(theInfo);
                                        String value = info.substring(ix + 1);
                                        if (value.startsWith("Date:")) {
                                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                            value = value.substring(5);
                                            value = sdf.format(new Date(Long.parseLong(value)));
                                        }
                                        text2.setText(value);
                                    }
                                    return convertView;
                                }
                            });
                        }
                    }
                }
            });
        }

    }.start();

    View subscribe_user = findViewById(R.id.subscribe_user);
    View unsubscribe_user = findViewById(R.id.unsubscribe_user);
    View subscribe_comments = findViewById(R.id.subscribe_comments);
    View unsubscribe_comments = findViewById(R.id.unsubscribe_comments);
    View filter_user = findViewById(R.id.filter_user);
    View blacklist_user = findViewById(R.id.blacklist_user);
    View show_blog = findViewById(R.id.show_blog);
    MicroBlog microBlog = MainActivity.getMicroBlog(mid.getMicroBlogCode());
    final MessageMenu mm = microBlog.getMessageMenu(this, messagesSource, null, null);
    JuickMessage message = microBlog.createMessage();
    mm.listSelectedItem = message;
    message.User = new JuickUser();
    message.User.UName = uname;
    message.User.UID = uid;
    message.setMID(mid);
    final UserpicStorage.AvatarID avatarID = microBlog.getAvatarID(message);

    final UserpicStorage.Listener userpicListener = new UserpicStorage.Listener() {
        @Override
        public void onUserpicReady(UserpicStorage.AvatarID id, int size) {
            final UserpicStorage.Listener thiz = this;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    UserpicStorage.instance.removeListener(avatarID, userpicSize, thiz);
                    final Bitmap userpic = UserpicStorage.instance.getUserpic(UserCenterActivity.this, avatarID,
                            userpicSize, thiz);
                    userPic.setImageBitmap(userpic); // can be null
                }
            });
        }
    };
    Bitmap userpic = UserpicStorage.instance.getUserpic(this, avatarID, userpicSize, userpicListener);
    userPic.setImageBitmap(userpic); // can be null

    subscribe_user.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mm.actionSubscribeUser();
        }
    });
    show_blog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mm.listSelectedItem.User.UID == 0) {
                JuickMicroBlog.obtainProperUserIdByName(UserCenterActivity.this, mm.listSelectedItem.User.UName,
                        "Getting Juick User Id", new Utils.Function<Void, Pair<String, String>>() {
                            @Override
                            public Void apply(Pair<String, String> cred) {
                                mm.listSelectedItem.User.UID = Integer.parseInt(cred.first);
                                mm.actionUserBlog();
                                return null;
                            }
                        });
            } else {
                mm.actionUserBlog();
            }
        }
    });
    search.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            search.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
                @Override
                public void onCreateContextMenu(ContextMenu menu, View v,
                        ContextMenu.ContextMenuInfo menuInfo) {
                    menu.add(0, SEARCH_PAST_CONVERSATIONS, 0, "My dialogs with user");
                    menu.add(0, SEARCH_MORE, 1, "More");
                }
            });
            search.showContextMenu();
        }
    });
    stats.setOnClickListener(new View.OnClickListener() {

        NewJuickPreferenceActivity.MenuItem[] items = new NewJuickPreferenceActivity.MenuItem[] {
                new NewJuickPreferenceActivity.MenuItem(R.string.UserAllTimeActivityReport,
                        R.string.UserAllTimeActivityReport2, new Runnable() {
                            @Override
                            public void run() {
                                NewJuickPreferenceActivity.showChart(UserCenterActivity.this,
                                        "USER_ACTIVITY_VOLUME", "uid=" + uid);
                            }
                        }),
                new NewJuickPreferenceActivity.MenuItem(R.string.UserHoursReport, R.string.UserHoursReport2,
                        new Runnable() {
                            @Override
                            public void run() {
                                NewJuickPreferenceActivity.showChart(UserCenterActivity.this,
                                        "USER_HOURS_ACTIVITY", "uid=" + uid + "&tzoffset="
                                                + TimeZone.getDefault().getRawOffset() / 1000 / 60 / 60);
                            }
                        }) };

        @Override
        public void onClick(View v) {
            list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    items[position].action.run();
                }
            });
            list.setAdapter(new BaseAdapter() {
                @Override
                public int getCount() {
                    return items.length;
                }

                @Override
                public Object getItem(int position) {
                    return items[position];
                }

                @Override
                public long getItemId(int position) {
                    return position;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    LayoutInflater layoutInflater = getLayoutInflater();
                    View listItem = layoutInflater.inflate(android.R.layout.simple_list_item_2, null);
                    TextView text = (TextView) listItem.findViewById(android.R.id.text1);
                    text.setText(items[position].labelId);
                    TextView text2 = (TextView) listItem.findViewById(android.R.id.text2);
                    text2.setText(items[position].label2Id);
                    return listItem;
                }
            });
        }
    });
    blacklist_user.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mm.actionBlacklistUser();
        }
    });
    filter_user.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mm.actionFilterUser(uname);
        }
    });
    unsubscribe_user.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mm.actionUnsubscribeUser();
        }
    });
    subscribe_comments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            enableJAM(new Runnable() {
                @Override
                public void run() {
                    JAMService.instance.client.subscribeToComments(uname);
                }
            });
        }
    });
    unsubscribe_comments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            enableJAM(new Runnable() {
                @Override
                public void run() {
                    JAMService.instance.client.unsubscribeFromComments(uname);
                }
            });
        }
    });
}

From source file:com.davis.kangpinhui.views.HorizontalListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        for (View view : mConflictViews) {
            if (view == null) {
                continue;
            }//from w w w  .j  a va2 s.c  om
            if (view instanceof ViewPager) {
                ((ViewPager) view).requestDisallowInterceptTouchEvent(true);
            }

            if (view instanceof SwipeRefreshLayout) {
                view.setEnabled(false);
                ((SwipeRefreshLayout) view).requestDisallowInterceptTouchEvent(true);
            }
        }
        break;

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        for (View view : mConflictViews) {
            if (view == null) {
                continue;
            }
            view.setEnabled(true);
        }
        break;

    }
    return super.dispatchTouchEvent(ev);
}

From source file:android.support.v7.preference.Preference.java

/**
 * Makes sure the view (and any children) get the enabled state changed.
 */// ww  w . ja v  a  2  s .c  om
private void setEnabledStateOnViews(View v, boolean enabled) {
    v.setEnabled(enabled);

    if (v instanceof ViewGroup) {
        final ViewGroup vg = (ViewGroup) v;
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            setEnabledStateOnViews(vg.getChildAt(i), enabled);
        }
    }
}