Example usage for android.widget ViewAnimator setDisplayedChild

List of usage examples for android.widget ViewAnimator setDisplayedChild

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setDisplayedChild(int whichChild) 

Source Link

Document

Sets which child view will be displayed.

Usage

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//  ww w . j  a  v  a  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.doplgangr.secrecy.views.VaultsListFragment.java

void switchView(final View parentView, final int showView) {
    getActivity().runOnUiThread(new Runnable() {
        @Override//from   w ww .j ava  2s  .  c  om
        public void run() {
            EditText passwordView = (EditText) parentView.findViewById(R.id.open_password);
            final View renameView = parentView.findViewById(R.id.rename_name);
            ViewAnimator viewAnimator = (ViewAnimator) parentView.findViewById(R.id.viewAnimator);
            viewAnimator.setInAnimation(context, R.anim.slide_down);

            int viewIndex = 0;
            switch (showView) {
            case R.id.vault_name_layout:
                viewIndex = 0;
                break;
            case R.id.vault_decrypt_layout:
                viewIndex = 1;
                if (passwordView != null) {
                    passwordView.requestFocus();
                    passwordView.setText(""); //Reset password field everytime
                }

                // Only one vault selected at that time
                passwordView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (!hasFocus) {
                            ViewAnimator viewAnimator = (ViewAnimator) parentView
                                    .findViewById(R.id.viewAnimator);
                            viewAnimator.setDisplayedChild(0);
                        }
                    }
                });
                kbdView = passwordView;
                imm.showSoftInput(passwordView, InputMethodManager.SHOW_IMPLICIT);
                break;
            case R.id.vault_delete_layout:
                viewIndex = 2;
                break;
            case R.id.vault_rename_layout:
                viewIndex = 3;
                if (renameView != null)
                    renameView.requestFocus();

                // Only one vault selected at that time
                renameView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (!hasFocus) {
                            ViewAnimator viewAnimator = (ViewAnimator) parentView
                                    .findViewById(R.id.viewAnimator);
                            viewAnimator.setDisplayedChild(0);
                        }
                    }
                });
                kbdView = renameView;
                imm.showSoftInput(renameView, InputMethodManager.SHOW_IMPLICIT);
                break;
            }

            viewAnimator.setDisplayedChild(viewIndex);
        }
    });
}

From source file:org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView vName = (TextView) view.findViewById(R.id.user_id_item_name);
    TextView vAddress = (TextView) view.findViewById(R.id.user_id_item_address);
    TextView vComment = (TextView) view.findViewById(R.id.user_id_item_comment);
    ImageView vVerified = (ImageView) view.findViewById(R.id.user_id_item_certified);
    ViewAnimator vVerifiedLayout = (ViewAnimator) view.findViewById(R.id.user_id_icon_animator);

    ImageView vDeleteButton = (ImageView) view.findViewById(R.id.user_id_item_delete_button);
    vDeleteButton.setVisibility(View.GONE); // not used

    String userId = cursor.getString(INDEX_USER_ID);
    OpenPgpUtils.UserId splitUserId = KeyRing.splitUserId(userId);
    if (splitUserId.name != null) {
        vName.setText(splitUserId.name);
    } else {//  www .  j  a v a 2  s . c o m
        vName.setText(R.string.user_id_no_name);
    }
    if (splitUserId.email != null) {
        vAddress.setText(splitUserId.email);
        vAddress.setVisibility(View.VISIBLE);
    } else {
        vAddress.setVisibility(View.GONE);
    }
    if (splitUserId.comment != null) {
        vComment.setText(splitUserId.comment);
        vComment.setVisibility(View.VISIBLE);
    } else {
        vComment.setVisibility(View.GONE);
    }

    boolean isPrimary = cursor.getInt(INDEX_IS_PRIMARY) != 0;
    boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;

    // for edit key
    if (mSaveKeyringParcel != null) {
        boolean changeAnyPrimaryUserId = (mSaveKeyringParcel.mChangePrimaryUserId != null);
        boolean changeThisPrimaryUserId = (mSaveKeyringParcel.mChangePrimaryUserId != null
                && mSaveKeyringParcel.mChangePrimaryUserId.equals(userId));
        boolean revokeThisUserId = (mSaveKeyringParcel.mRevokeUserIds.contains(userId));

        // only if primary user id will be changed
        // (this is not triggered if the user id is currently the primary one)
        if (changeAnyPrimaryUserId) {
            // change _all_ primary user ids and set new one to true
            isPrimary = changeThisPrimaryUserId;
        }

        if (revokeThisUserId) {
            if (!isRevoked) {
                isRevoked = true;
            }
        }

        vVerifiedLayout.setDisplayedChild(2);
    } else {
        vVerifiedLayout.setDisplayedChild(mShowStatusImages ? 1 : 0);
    }

    if (isRevoked) {
        // set revocation icon (can this even be primary?)
        KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.REVOKED, R.color.key_flag_gray);

        // disable revoked user ids
        vName.setEnabled(false);
        vAddress.setEnabled(false);
        vComment.setEnabled(false);
    } else {
        vName.setEnabled(true);
        vAddress.setEnabled(true);
        vComment.setEnabled(true);

        if (isPrimary) {
            vName.setTypeface(null, Typeface.BOLD);
            vAddress.setTypeface(null, Typeface.BOLD);
        } else {
            vName.setTypeface(null, Typeface.NORMAL);
            vAddress.setTypeface(null, Typeface.NORMAL);
        }

        int isVerified = cursor.getInt(INDEX_VERIFIED);
        switch (isVerified) {
        case Certs.VERIFIED_SECRET:
            KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.VERIFIED,
                    KeyFormattingUtils.DEFAULT_COLOR);
            break;
        case Certs.VERIFIED_SELF:
            KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.UNVERIFIED,
                    KeyFormattingUtils.DEFAULT_COLOR);
            break;
        default:
            KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.INVALID,
                    KeyFormattingUtils.DEFAULT_COLOR);
            break;
        }
    }
}