Example usage for android.widget TextView setVisibility

List of usage examples for android.widget TextView setVisibility

Introduction

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

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

protected void onEditingModeChange(ViewHolder vh, GuidedAction action, boolean editing) {
    action = vh.getAction();/*from w w w .j  a  va 2 s.  c  o  m*/
    TextView titleView = vh.getTitleView();
    TextView descriptionView = vh.getDescriptionView();
    if (editing) {
        CharSequence editTitle = action.getEditTitle();
        if (titleView != null && editTitle != null) {
            titleView.setText(editTitle);
        }
        CharSequence editDescription = action.getEditDescription();
        if (descriptionView != null && editDescription != null) {
            descriptionView.setText(editDescription);
        }
        if (action.isDescriptionEditable()) {
            if (descriptionView != null) {
                descriptionView.setVisibility(View.VISIBLE);
                descriptionView.setInputType(action.getDescriptionEditInputType());
            }
            vh.mEditingMode = EDITING_DESCRIPTION;
        } else if (action.isEditable()) {
            if (titleView != null) {
                titleView.setInputType(action.getEditInputType());
            }
            vh.mEditingMode = EDITING_TITLE;
        } else if (vh.mActivatorView != null) {
            onEditActivatorView(vh, action, editing);
            vh.mEditingMode = EDITING_ACTIVATOR_VIEW;
        }
    } else {
        if (titleView != null) {
            titleView.setText(action.getTitle());
        }
        if (descriptionView != null) {
            descriptionView.setText(action.getDescription());
        }
        if (vh.mEditingMode == EDITING_DESCRIPTION) {
            if (descriptionView != null) {
                descriptionView
                        .setVisibility(TextUtils.isEmpty(action.getDescription()) ? View.GONE : View.VISIBLE);
                descriptionView.setInputType(action.getDescriptionInputType());
            }
        } else if (vh.mEditingMode == EDITING_TITLE) {
            if (titleView != null) {
                titleView.setInputType(action.getInputType());
            }
        } else if (vh.mEditingMode == EDITING_ACTIVATOR_VIEW) {
            if (vh.mActivatorView != null) {
                onEditActivatorView(vh, action, editing);
            }
        }
        vh.mEditingMode = EDITING_NONE;
    }
}

From source file:com.example.fertilizercrm.easemob.chatuidemo.activity.ChatActivity.java

private void setUpView() {
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???//from w  ww .  java2 s. co m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    //TODO 
    Role role = getRoleByUsername(getIntent().getStringExtra("userId"));
    if (role != null) {
        tv_name = (TextView) findViewById(R.id.name2);
        tv_name.setVisibility(View.VISIBLE);

        TextView tv_role = (TextView) findViewById(R.id.tv_role);
        tv_role.setVisibility(View.VISIBLE);
        tv_role.setText(" (" + role.getDescription() + ")");
    } else {
        tv_name.setVisibility(View.VISIBLE);
    }

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
        if (robotMap != null && robotMap.containsKey(toChatUsername)) {
            isRobot = true;
            String nick = robotMap.get(toChatUsername).getNick();
            if (!TextUtils.isEmpty(nick)) {
                tv_name.setText(nick);
            } else {
                tv_name.setText(toChatUsername);
            }
        } else {
            UserUtils.setUserNick(toChatUsername, tv_name);
        }
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        findViewById(R.id.container_video_call).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");

        if (chatType == CHATTYPE_GROUP) {
            onGroupViewCreation();
        } else {
            onChatRoomViewCreation();
        }
    }

    // for chatroom type, we only init conversation and create view adapter on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // show forward message if the message is not null
        String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
        if (forward_msg_id != null) {
            // ?????
            forwardMessage(forward_msg_id);
        }
    }
}

From source file:cm.confide.ex.chips.BaseRecipientAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final RecipientEntry entry = getEntries().get(position);
    String displayName = entry.getDisplayName();
    String destination = entry.getDestination();
    if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) {
        displayName = destination;/*  w ww.  jav  a2s . com*/

        // We only show the destination for secondary entries, so clear it
        // only for the first level.
        if (entry.isFirstLevel()) {
            destination = null;
        }
    }

    final View itemView = convertView != null ? convertView : mInflater.inflate(getItemLayout(), parent, false);
    final TextView displayNameView = (TextView) itemView.findViewById(getDisplayNameId());
    final TextView destinationView = (TextView) itemView.findViewById(getDestinationId());
    final TextView destinationTypeView = (TextView) itemView.findViewById(getDestinationTypeId());
    final ImageView imageView = (ImageView) itemView.findViewById(getPhotoId());
    displayNameView.setText(displayName);
    if (!TextUtils.isEmpty(destination)) {
        destinationView.setText(destination);
    } else {
        destinationView.setText(null);
    }
    if (destinationTypeView != null) {
        final CharSequence destinationType = mQuery
                .getTypeLabel(mContext.getResources(), entry.getDestinationType(), entry.getDestinationLabel())
                .toString().toUpperCase();

        destinationTypeView.setText(destinationType);
    }

    if (entry.isFirstLevel()) {
        displayNameView.setVisibility(View.VISIBLE);
        if (imageView != null) {
            imageView.setVisibility(View.VISIBLE);
            final byte[] photoBytes = entry.getPhotoBytes();
            if (photoBytes != null) {
                final Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length);
                imageView.setImageBitmap(photo);
            } else {
                imageView.setImageResource(getDefaultPhotoResource());
            }
        }
    } else {
        displayNameView.setVisibility(View.GONE);
        if (imageView != null) {
            imageView.setVisibility(View.INVISIBLE);
        }
    }
    return itemView;
}

From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java

@SuppressLint("NewApi")
public View getView(final int position, View convertView, ViewGroup parent) {
    final EMMessage message = getItem(position);
    ChatType chatType = message.getChatType();
    final ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = createViewByMessage(message, position);
        if (message.getType() == EMMessage.Type.IMAGE) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture));
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.percentage);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }/*from w w w .ja v a 2  s  .c  o m*/

        } else if (message.getType() == EMMessage.Type.TXT) {

            try {
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                // 
                holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }

            // ???
            if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)
                    || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) {
                holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon);
                holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent);
            }

        } else if (message.getType() == EMMessage.Type.VOICE) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice));
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.tv_length);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
                holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice);
            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.LOCATION) {
            try {
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.tv_location);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.VIDEO) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv));
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.percentage);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv);
                holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv);
                holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn);
                holder.container_status_btn = (LinearLayout) convertView
                        .findViewById(R.id.container_status_btn);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);

            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.FILE) {
            try {
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name);
                holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state);
                holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container);
                // 
                holder.tv = (TextView) convertView.findViewById(R.id.percentage);
            } catch (Exception e) {
            }
            try {
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }

        }

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // ??????
    if ((chatType == ChatType.GroupChat || chatType == chatType.ChatRoom)
            && message.direct == EMMessage.Direct.RECEIVE) {
        //demousername?nick
        holder.tv_usernick.setText(message.getFrom());
    }
    // ??????textview
    if (!(chatType == ChatType.GroupChat || chatType == chatType.ChatRoom)
            && message.direct == EMMessage.Direct.SEND) {
        holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack);
        holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered);
        if (holder.tv_ack != null) {
            if (message.isAcked) {
                if (holder.tv_delivered != null) {
                    holder.tv_delivered.setVisibility(View.INVISIBLE);
                }
                holder.tv_ack.setVisibility(View.VISIBLE);
            } else {
                holder.tv_ack.setVisibility(View.INVISIBLE);

                // check and display msg delivered ack status
                if (holder.tv_delivered != null) {
                    if (message.isDelivered) {
                        holder.tv_delivered.setVisibility(View.VISIBLE);
                    } else {
                        holder.tv_delivered.setVisibility(View.INVISIBLE);
                    }
                }
            }
        }
    } else {
        // ??group messgae,chatroom message??
        if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked
                && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) {
            // ??
            if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
                try {
                    EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    // ??
                    message.isAcked = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    //?
    setUserAvatar(message, holder.iv_avatar);

    switch (message.getType()) {
    // ??typeitem
    case IMAGE: // 
        handleImageMessage(message, holder, position, convertView);
        break;
    case TXT: // 
        if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)
                || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false))
            // ?
            handleCallMessage(message, holder, position);
        else
            handleTextMessage(message, holder, position);
        break;
    case LOCATION: // ?
        handleLocationMessage(message, holder, position, convertView);
        break;
    case VOICE: // 
        handleVoiceMessage(message, holder, position, convertView);
        break;
    case VIDEO: // 
        handleVideoMessage(message, holder, position, convertView);
        break;
    case FILE: // 
        handleFileMessage(message, holder, position, convertView);
        break;
    default:
        // not supported
    }

    if (message.direct == EMMessage.Direct.SEND) {
        View statusView = convertView.findViewById(R.id.msg_status);
        // ??
        statusView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                // ???alertdialog
                Intent intent = new Intent(activity, AlertDialog.class);
                intent.putExtra("msg", activity.getString(R.string.confirm_resend));
                intent.putExtra("title", activity.getString(R.string.resend));
                intent.putExtra("cancel", true);
                intent.putExtra("position", position);
                if (message.getType() == EMMessage.Type.TXT)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT);
                else if (message.getType() == EMMessage.Type.VOICE)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE);
                else if (message.getType() == EMMessage.Type.IMAGE)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE);
                else if (message.getType() == EMMessage.Type.LOCATION)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION);
                else if (message.getType() == EMMessage.Type.FILE)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE);
                else if (message.getType() == EMMessage.Type.VIDEO)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO);

            }
        });

    } else {
        final String st = context.getResources().getString(R.string.Into_the_blacklist);
        if (chatType != ChatType.ChatRoom) {
            // ????
            holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    Intent intent = new Intent(activity, AlertDialog.class);
                    intent.putExtra("msg", st);
                    intent.putExtra("cancel", true);
                    intent.putExtra("position", position);
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST);
                    return true;
                }
            });
        }
    }

    TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp);

    if (position == 0) {
        timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
        timestamp.setVisibility(View.VISIBLE);
    } else {
        // ???
        EMMessage prevMessage = getItem(position - 1);
        if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) {
            timestamp.setVisibility(View.GONE);
        } else {
            timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
            timestamp.setVisibility(View.VISIBLE);
        }
    }
    return convertView;
}

From source file:com.g11x.checklistapp.ImportantInformationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_important_information);

    // TODO: fetch from content provider
    if (data == null) {
        data = new ArrayList<>();
        data.add("one");
        data.add("two");
        data.add("three");
    }//from w ww  .java2s  .c o  m

    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.important_information_recycler_view);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager layoutManger = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManger);

    FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
    floatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImportantInformationActivity.this.onFloatingActionButtonClick();
        }
    });

    final TextView emptyListInfo = (TextView) findViewById(R.id.important_information_empty);

    Intent intent = getIntent();

    if (intent.getExtras() != null && intent.getExtras().get("title") != null) {
        View view = findViewById(R.id.activity_important_information);
        String message = String.format(getString(R.string.created_important_information_item),
                intent.getExtras().get("title"));
        Snackbar.make(view, message, Snackbar.LENGTH_LONG).show();
    }

    getSupportLoaderManager().initLoader(0, null, new LoaderManager.LoaderCallbacks<Cursor>() {
        @Override
        public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
            return new CursorLoader(ImportantInformationActivity.this,
                    Database.ImportantInformation.CONTENT_URI, PROJECTION, null, null, null);
        }

        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
            refreshUi(cursor.getCount());

            if (adapter == null) {
                if (cursor != null) {
                    adapter = new Adapter(cursor);
                    recyclerView.setAdapter(adapter);
                }
            } else {
                adapter.swapCursor(cursor);
            }
        }

        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            adapter.swapCursor(null);
        }

        private void refreshUi(int itemCount) {
            if (itemCount > 0) {
                recyclerView.setVisibility(View.VISIBLE);
                emptyListInfo.setVisibility(View.GONE);
            } else {
                emptyListInfo.setVisibility(View.VISIBLE);
                recyclerView.setVisibility(View.GONE);
            }

        }
    });
}

From source file:com.bw.luzz.monkeyapplication.View.DateTimePicker.time.TimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.mdtp_time_picker_dialog, container, false);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    // If an accent color has not been set manually, get it from the context
    if (mAccentColor == -1) {
        mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
    }/*from  www .  j  a  v  a 2 s .  c  o  m*/

    // if theme mode has not been set by java code, check if it is specified in Style.xml
    if (!mThemeDarkChanged) {
        mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
    }

    Resources res = getResources();
    Context context = getActivity();
    mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description);
    mSelectHours = res.getString(R.string.mdtp_select_hours);
    mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description);
    mSelectMinutes = res.getString(R.string.mdtp_select_minutes);
    mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description);
    mSelectSeconds = res.getString(R.string.mdtp_select_seconds);
    mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mSecondSpaceView = (TextView) view.findViewById(R.id.seconds_space);
    mSecondView = (TextView) view.findViewById(R.id.seconds);
    mSecondView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());
    mInitialTime = roundToNearest(mInitialTime);

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), this, mInitialTime, mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mSecondView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            setCurrentItemShowing(SECOND_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mOkButton = (Button) view.findViewById(R.id.ok);
    mOkButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            notifyOnDateListener();
            dismiss();
        }
    });
    mOkButton.setOnKeyListener(keyboardListener);
    mOkButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mOkString != null)
        mOkButton.setText(mOkString);
    else
        mOkButton.setText(mOkResid);

    mCancelButton = (Button) view.findViewById(R.id.cancel);
    mCancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryVibrate();
            if (getDialog() != null)
                getDialog().cancel();
        }
    });
    mCancelButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mCancelString != null)
        mCancelButton.setText(mCancelString);
    else
        mCancelButton.setText(mCancelResid);
    mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Don't do anything if either AM or PM are disabled
                if (isAmDisabled() || isPmDisabled())
                    return;

                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    // Disable seconds picker
    if (!mEnableSeconds) {
        mSecondSpaceView.setVisibility(View.GONE);
        view.findViewById(R.id.separator_seconds).setVisibility(View.GONE);
    }

    // Center stuff depending on what's visible
    if (mIs24HourMode && !mEnableSeconds) {
        // center first separator
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else if (mEnableSeconds) {
        // link separator to minutes
        final View separator = view.findViewById(R.id.separator);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.minutes_space);
        paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        separator.setLayoutParams(paramsSeparator);

        if (!mIs24HourMode) {
            // center minutes
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        } else {
            // move minutes to right of center
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.center_view);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        }
    }

    mAllowAutoAdvance = true;
    setHour(mInitialTime.getHour(), true);
    setMinute(mInitialTime.getMinute());
    setSecond(mInitialTime.getSecond());

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.mdtp_deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<>();
    }

    // Set the title (if any)
    TextView timePickerHeader = (TextView) view.findViewById(R.id.time_picker_header);
    if (!mTitle.isEmpty()) {
        timePickerHeader.setVisibility(TextView.VISIBLE);
        timePickerHeader.setText(mTitle.toUpperCase(Locale.getDefault()));
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    mOkButton.setTextColor(mAccentColor);
    mCancelButton.setTextColor(mAccentColor);
    timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor));
    view.findViewById(R.id.time_display_background).setBackgroundColor(mAccentColor);
    view.findViewById(R.id.time_display).setBackgroundColor(mAccentColor);

    if (getDialog() == null) {
        view.findViewById(R.id.done_background).setVisibility(View.GONE);
    }

    int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background);
    int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color);
    int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray);
    int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray);

    mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground);
    view.findViewById(R.id.time_picker_dialog)
            .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor);
    return view;
}

From source file:com.edible.ocr.CaptureActivity.java

/**
 * Displays information relating to the result of OCR, and requests a translation if necessary.
 * /*from   w w w .jav  a2 s.c  o  m*/
 * @param ocrResult Object representing successful OCR results
 * @return True if a non-null result was received for OCR
 */
boolean handleOcrDecode(OcrResult ocrResult) {
    lastResult = ocrResult;

    // Test whether the result is null
    if (ocrResult.getText() == null || ocrResult.getText().equals("")) {
        Toast toast = Toast.makeText(this, "OCR failed. Please try again.", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP, 0, 0);
        toast.show();
        return false;
    }

    // Turn off capture-related UI elements
    shutterButton.setVisibility(View.GONE);
    statusViewBottom.setVisibility(View.GONE);
    statusViewTop.setVisibility(View.GONE);
    cameraButtonView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView bitmapImageView = (ImageView) findViewById(R.id.image_view);
    lastBitmap = ocrResult.getBitmap();
    if (lastBitmap == null) {
        bitmapImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    } else {
        bitmapImageView.setImageBitmap(lastBitmap);
    }

    // Display the recognized text
    TextView sourceLanguageTextView = (TextView) findViewById(R.id.source_language_text_view);
    sourceLanguageTextView.setText(sourceLanguageReadable);
    TextView ocrResultTextView = (TextView) findViewById(R.id.ocr_result_text_view);
    ocrResultTextView.setText(stripNoise(ocrResult.getText()));
    // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
    int scaledSize = Math.max(22, 32 - ocrResult.getText().length() / 4);
    ocrResultTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView translationLanguageLabelTextView = (TextView) findViewById(
            R.id.translation_language_label_text_view);
    TextView translationLanguageTextView = (TextView) findViewById(R.id.translation_language_text_view);
    TextView translationTextView = (TextView) findViewById(R.id.translation_text_view);
    if (isTranslationActive) {
        // Handle translation text fields
        translationLanguageLabelTextView.setVisibility(View.VISIBLE);
        translationLanguageTextView.setText(targetLanguageReadable);
        translationLanguageTextView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL);
        translationLanguageTextView.setVisibility(View.VISIBLE);

        // Activate/re-activate the indeterminate progress indicator
        translationTextView.setVisibility(View.GONE);
        progressView.setVisibility(View.VISIBLE);
        setProgressBarVisibility(true);

        // Get the translation asynchronously
        new TranslateAsyncTask(this, sourceLanguageCodeTranslation, targetLanguageCodeTranslation,
                stripNoise(ocrResult.getText())).execute();
    } else {
        translationLanguageLabelTextView.setVisibility(View.GONE);
        translationLanguageTextView.setVisibility(View.GONE);
        translationTextView.setVisibility(View.GONE);
        progressView.setVisibility(View.GONE);
        setProgressBarVisibility(false);
    }
    return true;
}

From source file:im.vector.util.BugReporter.java

/**
 * Send a bug report either with email or with Vector.
 *///from   w w  w  . j  a v  a2  s .com
public static void sendBugReport() {
    final Activity currentActivity = VectorApp.getCurrentActivity();

    // no current activity so cannot display an alert
    if (null == currentActivity) {
        sendBugReport(VectorApp.getInstance().getApplicationContext(), true, true, "", null);
        return;
    }

    final Context appContext = currentActivity.getApplicationContext();
    LayoutInflater inflater = currentActivity.getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.dialog_bug_report, null);

    final AlertDialog.Builder dialog = new AlertDialog.Builder(currentActivity);
    dialog.setTitle(R.string.send_bug_report);
    dialog.setView(dialogLayout);

    final EditText bugReportText = (EditText) dialogLayout.findViewById(R.id.bug_report_edit_text);
    final CheckBox includeLogsButton = (CheckBox) dialogLayout
            .findViewById(R.id.bug_report_button_include_logs);
    final CheckBox includeCrashLogsButton = (CheckBox) dialogLayout
            .findViewById(R.id.bug_report_button_include_crash_logs);

    final ProgressBar progressBar = (ProgressBar) dialogLayout.findViewById(R.id.bug_report_progress_view);
    final TextView progressTextView = (TextView) dialogLayout.findViewById(R.id.bug_report_progress_text_view);

    dialog.setPositiveButton(R.string.send, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // will be overridden to avoid dismissing the dialog while displaying the progress
        }
    });

    dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // will be overridden to avoid dismissing the dialog while displaying the progress
        }
    });

    //
    final AlertDialog bugReportDialog = dialog.show();
    final Button cancelButton = bugReportDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
    final Button sendButton = bugReportDialog.getButton(AlertDialog.BUTTON_POSITIVE);

    if (null != cancelButton) {
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // check if there is no upload in progress
                if (includeLogsButton.isEnabled()) {
                    bugReportDialog.dismiss();
                } else {
                    mIsCancelled = true;
                    cancelButton.setEnabled(false);
                }
            }
        });
    }

    if (null != sendButton) {
        sendButton.setEnabled(false);

        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable the active area while uploading the bug report
                bugReportText.setEnabled(false);
                sendButton.setEnabled(false);
                includeLogsButton.setEnabled(false);
                includeCrashLogsButton.setEnabled(false);

                progressTextView.setVisibility(View.VISIBLE);
                progressTextView.setText(appContext.getString(R.string.send_bug_report_progress, 0 + ""));

                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(0);

                sendBugReport(VectorApp.getInstance(), includeLogsButton.isChecked(),
                        includeCrashLogsButton.isChecked(), bugReportText.getText().toString(),
                        new IMXBugReportListener() {
                            @Override
                            public void onUploadFailed(String reason) {
                                try {
                                    if (null != VectorApp.getInstance() && !TextUtils.isEmpty(reason)) {
                                        Toast.makeText(VectorApp.getInstance(),
                                                VectorApp.getInstance()
                                                        .getString(R.string.send_bug_report_failed, reason),
                                                Toast.LENGTH_LONG).show();
                                    }
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadFailed() : failed to display the toast "
                                            + e.getMessage());
                                }

                                try {
                                    // restore the dialog if the upload failed
                                    bugReportText.setEnabled(true);
                                    sendButton.setEnabled(true);
                                    includeLogsButton.setEnabled(true);
                                    includeCrashLogsButton.setEnabled(true);
                                    cancelButton.setEnabled(true);

                                    progressTextView.setVisibility(View.GONE);
                                    progressBar.setVisibility(View.GONE);
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadFailed() : failed to restore the dialog button "
                                            + e.getMessage());

                                    try {
                                        bugReportDialog.dismiss();
                                    } catch (Exception e2) {
                                        Log.e(LOG_TAG, "## onUploadFailed() : failed to dismiss the dialog "
                                                + e2.getMessage());
                                    }
                                }

                                mIsCancelled = false;
                            }

                            @Override
                            public void onUploadCancelled() {
                                onUploadFailed(null);
                            }

                            @Override
                            public void onProgress(int progress) {
                                if (progress > 100) {
                                    Log.e(LOG_TAG, "## onProgress() : progress > 100");
                                    progress = 100;
                                } else if (progress < 0) {
                                    Log.e(LOG_TAG, "## onProgress() : progress < 0");
                                    progress = 0;
                                }

                                progressBar.setProgress(progress);
                                progressTextView.setText(
                                        appContext.getString(R.string.send_bug_report_progress, progress + ""));
                            }

                            @Override
                            public void onUploadSucceed() {
                                try {
                                    if (null != VectorApp.getInstance()) {
                                        Toast.makeText(VectorApp.getInstance(),
                                                VectorApp.getInstance().getString(
                                                        R.string.send_bug_report_sent),
                                                Toast.LENGTH_LONG).show();
                                    }
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the toast "
                                            + e.getMessage());
                                }

                                try {
                                    bugReportDialog.dismiss();
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the dialog "
                                            + e.getMessage());
                                }
                            }
                        });
            }
        });
    }

    bugReportText.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 (null != sendButton) {
                sendButton.setEnabled(bugReportText.getText().toString().length() > 10);
            }
        }

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

From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final RecipientEntry entry = mEntries.get(position);
    switch (entry.getEntryType()) {
    case RecipientEntry.ENTRY_TYPE_WAITING_FOR_DIRECTORY_SEARCH: {
        return convertView != null ? convertView
                : mInflater.inflate(getWaitingForDirectorySearchLayout(), parent, false);
    }//ww  w.  ja  v  a2s . c  om
    default: {
        String displayName = entry.getDisplayName();
        String destination = entry.getDestination();
        if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) {
            displayName = destination;
            destination = null;
        }

        final View itemView = convertView != null ? convertView
                : mInflater.inflate(getItemLayout(), parent, false);
        final TextView displayNameView = (TextView) itemView.findViewById(getDisplayNameId());
        final TextView destinationView = (TextView) itemView.findViewById(getDestinationId());
        final TextView destinationTypeView = (TextView) itemView.findViewById(getDestinationTypeId());
        final ImageView imageView = (ImageView) itemView.findViewById(getPhotoId());
        displayNameView.setText(displayName);
        if (!TextUtils.isEmpty(destination)) {
            destinationView.setText(destination);
        } else {
            destinationView.setText(null);
        }
        if (destinationTypeView != null) {
            final CharSequence destinationType = Email.getTypeLabel(mContext.getResources(),
                    entry.getDestinationType(), entry.getDestinationLabel()).toString().toUpperCase();

            destinationTypeView.setText(destinationType);
        }

        if (entry.isFirstLevel()) {
            displayNameView.setVisibility(View.VISIBLE);
            if (imageView != null) {
                imageView.setVisibility(View.VISIBLE);
                final byte[] photoBytes = entry.getPhotoBytes();
                if (photoBytes != null && imageView != null) {
                    final Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length);
                    imageView.setImageBitmap(photo);
                } else {
                    imageView.setImageResource(getDefaultPhotoResource());
                }
            }
        } else {
            displayNameView.setVisibility(View.GONE);
            if (imageView != null) {
                imageView.setVisibility(View.INVISIBLE);
            }
        }
        return itemView;
    }
    }
}

From source file:com.google.samples.apps.sergio.ui.BaseActivity.java

/**
 * Sets up the account box. The account box is the area at the top of the nav drawer that
 * shows which account the user is logged in as, and lets them switch accounts. It also
 * shows the user's Google+ cover photo as background.
 */// w  w  w.j a va  2 s.c  om
private void setupAccountBox() {
    mAccountListContainer = (LinearLayout) findViewById(R.id.account_list);

    if (mAccountListContainer == null) {
        //This activity does not have an account box
        return;
    }

    final View chosenAccountView = findViewById(R.id.chosen_account_view);
    Account chosenAccount = AccountUtils.getActiveAccount(this);
    if (chosenAccount == null) {
        // No account logged in; hide account box
        chosenAccountView.setVisibility(View.GONE);
        mAccountListContainer.setVisibility(View.GONE);
        return;
    } else {
        chosenAccountView.setVisibility(View.VISIBLE);
        mAccountListContainer.setVisibility(View.INVISIBLE);
    }

    AccountManager am = AccountManager.get(this);
    Account[] accountArray = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    List<Account> accounts = new ArrayList<Account>(Arrays.asList(accountArray));
    accounts.remove(chosenAccount);

    ImageView coverImageView = (ImageView) chosenAccountView.findViewById(R.id.profile_cover_image);
    ImageView profileImageView = (ImageView) chosenAccountView.findViewById(R.id.profile_image);
    TextView nameTextView = (TextView) chosenAccountView.findViewById(R.id.profile_name_text);
    TextView email = (TextView) chosenAccountView.findViewById(R.id.profile_email_text);
    mExpandAccountBoxIndicator = (ImageView) findViewById(R.id.expand_account_box_indicator);

    String name = AccountUtils.getPlusName(this);
    if (name == null) {
        nameTextView.setVisibility(View.GONE);
    } else {
        nameTextView.setVisibility(View.VISIBLE);
        nameTextView.setText(name);
    }

    String imageUrl = AccountUtils.getPlusImageUrl(this);
    if (imageUrl != null) {
        mImageLoader.loadImage(imageUrl, profileImageView);
    }

    String coverImageUrl = AccountUtils.getPlusCoverUrl(this);
    if (coverImageUrl != null) {
        mImageLoader.loadImage(coverImageUrl, coverImageView);
    } else {
        coverImageView.setImageResource(R.drawable.default_cover);
    }

    email.setText(chosenAccount.name);

    if (accounts.isEmpty()) {
        // There's only one account on the device, so no need for a switcher.
        mExpandAccountBoxIndicator.setVisibility(View.GONE);
        mAccountListContainer.setVisibility(View.GONE);
        chosenAccountView.setEnabled(false);
        return;
    }

    chosenAccountView.setEnabled(true);

    mExpandAccountBoxIndicator.setVisibility(View.VISIBLE);
    chosenAccountView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mAccountBoxExpanded = !mAccountBoxExpanded;
            setupAccountBoxToggle();
        }
    });
    setupAccountBoxToggle();

    populateAccountList(accounts);
}