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:org.openhab.habdroid.ui.OpenHABWidgetSettingsAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    /* TODO: This definitely needs some huge refactoring
     *///from   w w  w  . ja v a 2  s. c  o  m
    final int pos = position;

    RelativeLayout widgetView;
    TextView labelTextView;
    ImageView roomEditView;
    int widgetLayout = 0;
    OpenHABWidget openHABWidget = getItem(position);
    switch (this.getItemViewType(position)) {
    case TYPE_FRAME:
        widgetLayout = R.layout.openhabwidgetlist_frameitem;
        break;
    case TYPE_GROUP:
        widgetLayout = R.layout.openhabwidget_settings_item;
        break;

    case TYPE_IMAGE:
        widgetLayout = R.layout.openhabwidgetlist_imageitem;
        break;

    case TYPE_CHART:
        widgetLayout = R.layout.openhabwidgetlist_chartitem;
        break;
    case TYPE_VIDEO:
        widgetLayout = R.layout.openhabwidgetlist_videoitem;
        break;
    case TYPE_WEB:
        widgetLayout = R.layout.openhabwidgetlist_webitem;
        break;
    default:
        widgetLayout = R.layout.openhabwidget_settings_item;
        break;
    }
    if (convertView == null) {
        widgetView = new RelativeLayout(getContext());
        String inflater = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater vi;
        vi = (LayoutInflater) getContext().getSystemService(inflater);
        vi.inflate(widgetLayout, widgetView, true);
    } else {
        widgetView = (RelativeLayout) convertView;
    }
    switch (getItemViewType(position)) {
    case TYPE_FRAME:
        labelTextView = (TextView) widgetView.findViewById(R.id.framelabel);
        if (labelTextView != null)
            labelTextView.setText(openHABWidget.getLabel());
        widgetView.setClickable(false);
        if (openHABWidget.getLabel().length() > 0) { // hide empty frames
            widgetView.setVisibility(View.VISIBLE);
            labelTextView.setVisibility(View.VISIBLE);
        } else {
            widgetView.setVisibility(View.GONE);
            labelTextView.setVisibility(View.GONE);
        }
        break;
    case TYPE_IMAGE:
        MySmartImageView imageImage = (MySmartImageView) widgetView.findViewById(R.id.imageimage);
        imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl, openHABWidget.getUrl()), false);
        if (openHABWidget.getRefresh() > 0) {
            imageImage.setRefreshRate(openHABWidget.getRefresh());
            refreshImageList.add(imageImage);
        }
        break;
    case TYPE_CHART:
        MySmartImageView chartImage = (MySmartImageView) widgetView.findViewById(R.id.chartimage);
        OpenHABItem chartItem = openHABWidget.getItem();
        Random random = new Random();
        String chartUrl = "";
        if (chartItem.getType().equals("GroupItem")) {
            chartUrl = openHABBaseUrl + "rrdchart.png?groups=" + chartItem.getName() + "&period="
                    + openHABWidget.getPeriod() + "&random=" + String.valueOf(random.nextInt());
        }
        Log.i("OpenHABWidgetAdapter", "Chart url = " + chartUrl);
        chartImage.setImageUrl(chartUrl, false);
        // TODO: This is quite dirty fix to make charts look full screen width on all displays
        ViewGroup.LayoutParams chartLayoutParams = chartImage.getLayoutParams();
        int screenWidth = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay().getWidth();
        chartLayoutParams.height = (int) (screenWidth / 1.88);
        chartImage.setLayoutParams(chartLayoutParams);
        if (openHABWidget.getRefresh() > 0) {
            chartImage.setRefreshRate(openHABWidget.getRefresh());
            refreshImageList.add(chartImage);
        }
        Log.i("OpenHABWidgetAdapter",
                "chart size = " + chartLayoutParams.width + " " + chartLayoutParams.height);
        break;
    case TYPE_VIDEO:
        VideoView videoVideo = (VideoView) widgetView.findViewById(R.id.videovideo);
        Log.i("OpenHABWidgetAdapter", "Opening video at " + openHABWidget.getUrl());
        // TODO: This is quite dirty fix to make video look maximum available size on all screens
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        ViewGroup.LayoutParams videoLayoutParams = videoVideo.getLayoutParams();
        videoLayoutParams.height = (int) (wm.getDefaultDisplay().getWidth() / 1.77);
        videoVideo.setLayoutParams(videoLayoutParams);
        // We don't have any event handler to know if the VideoView is on the screen
        // so we manage an array of all videos to stop them when user leaves the page
        if (!videoWidgetList.contains(videoVideo))
            videoWidgetList.add(videoVideo);
        // Start video
        if (!videoVideo.isPlaying()) {
            videoVideo.setVideoURI(Uri.parse(openHABWidget.getUrl()));
            videoVideo.start();
        }
        Log.i("OpenHABWidgetAdapter", "Video height is " + videoVideo.getHeight());
        break;
    case TYPE_WEB:
        WebView webWeb = (WebView) widgetView.findViewById(R.id.webweb);
        if (openHABWidget.getHeight() > 0) {
            ViewGroup.LayoutParams webLayoutParams = webWeb.getLayoutParams();
            webLayoutParams.height = openHABWidget.getHeight() * 80;
            webWeb.setLayoutParams(webLayoutParams);
        }
        webWeb.setWebViewClient(new WebViewClient());
        webWeb.loadUrl(openHABWidget.getUrl());
        break;

    default:
        labelTextView = (TextView) widgetView.findViewById(R.id.itemlabel);
        roomEditView = (ImageView) widgetView.findViewById(R.id.editimg);
        if (null != roomEditView) {
            roomEditView.setVisibility(View.VISIBLE);
            roomEditView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    if (null != listItemListener)
                        listItemListener.onEditClickListener(pos);
                }
            });
        }
        if (labelTextView != null)
            labelTextView.setText(openHABWidget.getLabel());
        MySmartImageView sliderImage = (MySmartImageView) widgetView.findViewById(R.id.itemimage);
        sliderImage.setImageUrl(openHABBaseUrl + "images/" + openHABWidget.getIcon() + ".png");
        break;
    }
    LinearLayout dividerLayout = (LinearLayout) widgetView.findViewById(R.id.listdivider);
    if (dividerLayout != null) {
        if (position < this.getCount() - 1) {
            if (this.getItemViewType(position + 1) == TYPE_FRAME) {
                dividerLayout.setVisibility(View.GONE); // hide dividers before frame widgets
            } else {
                dividerLayout.setVisibility(View.VISIBLE); // show dividers for all others
            }
        } else { // last widget in the list, hide divider
            dividerLayout.setVisibility(View.GONE);
        }
    }
    return widgetView;
}

From source file:br.com.mybaby.contatos.ContactDetailFragment.java

/**
 * Builds a phone  layout/*from ww w.ja  v a  2  s .  com*/
 *
 * @return A LinearLayout from phones
 */
private LinearLayout buildPhoneLayout(final Integer id, String number, boolean checked) {
    // Inflates the address layout
    final LinearLayout phoneLayout = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.contatos_phone_detail_item, mDetailsLayout, false);

    // Gets handles to the view objects in the layout
    final TextView headerTextView = (TextView) phoneLayout.findViewById(R.id.contact_phone_detail_header);

    final TextView phoneTextView = (TextView) phoneLayout.findViewById(R.id.contact_phone_detail_item);

    final CheckBox phoneCheckBox = (CheckBox) phoneLayout.findViewById(R.id.checkbox_phone);

    phoneCheckBox.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            CheckBox cb = (CheckBox) v;

            Telefone _tel = new Telefone();
            _tel.setId(cb.getId());

            if (cb.isChecked()) {
                if (telefonesBase.size() == 4) {
                    Toast.makeText(getActivity(), "Mximo de telefones selecionados: 4", Toast.LENGTH_LONG)
                            .show();
                    cb.setChecked(false);
                } else {
                    int posicao = telefonesContatoAtual.indexOf(_tel);
                    contatoParaSalvar.getTelefones().add(telefonesContatoAtual.get(posicao));
                    telefonesBase.add(telefonesContatoAtual.get(posicao));
                }
            } else {
                int posicao = contatoParaSalvar.getTelefones().indexOf(_tel);
                contatoParaSalvar.getTelefones().remove(posicao);
                telefonesBase.remove(posicao);
            }
        }
    });

    if (phoneTextView == null) {
        headerTextView.setVisibility(View.GONE);
        phoneTextView.setText(R.string.no_address);
        phoneCheckBox.setVisibility(View.GONE);

    } else {
        phoneCheckBox.setId(id);
        phoneCheckBox.setChecked(checked);
        phoneTextView.setText(number);
    }

    return phoneLayout;
}

From source file:com.customdatepicker.time.TimePickerDialog.java

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

    int viewRes = mVersion == Version.VERSION_1 ? R.layout.mdtp_time_picker_dialog
            : R.layout.mdtp_time_picker_dialog_v2;
    View view = inflater.inflate(viewRes, container, false);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.mdtp_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  w w  w . 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.mdtp_hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.mdtp_hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.mdtp_minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.mdtp_minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mSecondSpaceView = (TextView) view.findViewById(R.id.mdtp_seconds_space);
    mSecondView = (TextView) view.findViewById(R.id.mdtp_seconds);
    mSecondView.setOnKeyListener(keyboardListener);
    mAmTextView = (TextView) view.findViewById(R.id.mdtp_am_label);
    mAmTextView.setOnKeyListener(keyboardListener);
    mPmTextView = (TextView) view.findViewById(R.id.mdtp_pm_label);
    mPmTextView.setOnKeyListener(keyboardListener);
    mAmPmLayout = view.findViewById(R.id.mdtp_ampm_layout);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());

    if (mTimePicker != null) {
        mInitialTime = new Timepoint(mTimePicker.getHours(), mTimePicker.getMinutes(),
                mTimePicker.getSeconds());
    }

    mInitialTime = roundToNearest(mInitialTime);

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.mdtp_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.mdtp_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.mdtp_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.
    if (mIs24HourMode) {
        mAmPmLayout.setVisibility(View.GONE);
    } else {
        OnClickListener listener = 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);
            }
        };
        mAmTextView.setVisibility(View.GONE);
        mPmTextView.setVisibility(View.VISIBLE);
        mAmPmLayout.setOnClickListener(listener);
        if (mVersion == Version.VERSION_2) {
            mAmTextView.setText(mAmText);
            mPmTextView.setText(mPmText);
            mAmTextView.setVisibility(View.VISIBLE);
        }
        updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);

    }

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

    // Disable minutes picker
    if (!mEnableMinutes) {
        mMinuteSpaceView.setVisibility(View.GONE);
        view.findViewById(R.id.mdtp_separator).setVisibility(View.GONE);
    }

    // Center stuff depending on what's visible
    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    // Landscape layout is radically different
    if (isLandscape) {
        if (!mEnableMinutes && !mEnableSeconds) {
            // Just the hour
            // Put the hour above the center
            RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsHour.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
            paramsHour.addRule(RelativeLayout.CENTER_HORIZONTAL);
            mHourSpaceView.setLayoutParams(paramsHour);
            if (mIs24HourMode) {
                // Hour + Am/Pm indicator
                // Put the am / pm indicator next to the hour
                RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space);
                mAmPmLayout.setLayoutParams(paramsAmPm);
            }
        } else if (!mEnableSeconds && mIs24HourMode) {
            // Hour + Minutes
            // Put the separator above the center
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
        } else if (!mEnableSeconds) {
            // Hour + Minutes + Am/Pm indicator
            // Put separator above the center
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_center_view);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
            // Put the am/pm indicator below the separator
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.CENTER_IN_PARENT);
            paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_center_view);
            mAmPmLayout.setLayoutParams(paramsAmPm);
        } else if (mIs24HourMode) {
            // Hour + Minutes + Seconds
            // Put the separator above the center
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
            // Center the seconds
            RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT);
            mSecondSpaceView.setLayoutParams(paramsSeconds);
        } else {
            // Hour + Minutes + Seconds + Am/Pm Indicator
            // Put the seconds on the center
            RelativeLayout.LayoutParams paramsSeconds = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeconds.addRule(RelativeLayout.CENTER_IN_PARENT);
            mSecondSpaceView.setLayoutParams(paramsSeconds);
            // Put the separator above the seconds
            RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsSeparator.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsSeparator.addRule(RelativeLayout.ABOVE, R.id.mdtp_seconds_space);
            TextView separatorView = (TextView) view.findViewById(R.id.mdtp_separator);
            separatorView.setLayoutParams(paramsSeparator);
            // Put the Am/Pm indicator below the seconds
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.CENTER_HORIZONTAL);
            paramsAmPm.addRule(RelativeLayout.BELOW, R.id.mdtp_seconds_space);
            mAmPmLayout.setLayoutParams(paramsAmPm);
        }
    } else if (mIs24HourMode && !mEnableSeconds && mEnableMinutes) {
        // 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.mdtp_separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else if (!mEnableMinutes && !mEnableSeconds) {
        // center the hour
        RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsHour.addRule(RelativeLayout.CENTER_IN_PARENT);
        mHourSpaceView.setLayoutParams(paramsHour);

        if (!mIs24HourMode) {
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.mdtp_hour_space);
            paramsAmPm.addRule(RelativeLayout.ALIGN_BASELINE, R.id.mdtp_hour_space);
            mAmPmLayout.setLayoutParams(paramsAmPm);
        }
    } else if (mEnableSeconds) {
        // link separator to minutes
        final View separator = view.findViewById(R.id.mdtp_separator);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.mdtp_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.mdtp_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.mdtp_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.
    timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor));
    view.findViewById(R.id.mdtp_time_display_background).setBackgroundColor(mAccentColor);
    view.findViewById(R.id.mdtp_time_display).setBackgroundColor(mAccentColor);

    // Button text can have a different color
    if (mOkColor != -1)
        mOkButton.setTextColor(mOkColor);
    else
        mOkButton.setTextColor(mAccentColor);
    if (mCancelColor != -1)
        mCancelButton.setTextColor(mCancelColor);
    else
        mCancelButton.setTextColor(mAccentColor);

    if (getDialog() == null) {
        view.findViewById(R.id.mdtp_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.mdtp_time_picker_dialog)
            .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor);
    return view;
}

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

private void startBtnClick(final View v) {
    if (mPasscodeOn) {
        LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
        final View layout = inflater.inflate(R.layout.passcode,
                (ViewGroup) findViewById(R.id.layout_root_passcode));
        final MaterialStyledDialog materialStyledDialog = new MaterialStyledDialog(MainActivity.this)
                .setTitle(getString(R.string.dialog_passcode_title))
                .setDescription(getString(R.string.dialog_passcode_description))
                .setIcon(R.drawable.ic_lock_blue_grey_100_48dp).setCustomView(layout).show();

        final PasscodeView passcodeView = (PasscodeView) layout.findViewById(R.id.passcode);
        final PasscodeView passcodeViewConfirm = (PasscodeView) layout.findViewById(R.id.passcodeConfirm);
        final TextView txtPasscodeConfirm = (TextView) layout.findViewById(R.id.txtPasscodeConfirm);
        txtPasscodeConfirm.setText(getString(R.string.dialog_passcode_confirm));
        ((TextView) layout.findViewById(R.id.txtPasscode))
                .setText(getString(R.string.dialog_passcode_passcode));
        passcodeView.setPasscodeEntryListener(new PasscodeView.PasscodeEntryListener() {
            @Override/*ww  w .  j a  v  a 2 s  . c om*/
            public void onPasscodeEntered(String passcode) {
                if (mAlertService != null && mAlertService.IsRunningAlertService()) {
                    if (passcode.equals(mPasscodeConfirm)) {
                        FlurryAgent.logEvent("Passcode Unlocked");

                        setStartButtonFunction(v);
                        materialStyledDialog.dismiss();
                    } else {
                        passcodeView.clearText();
                        passcodeView.requestFocus();
                    }
                } else {
                    passcodeViewConfirm.setVisibility(View.VISIBLE);
                    txtPasscodeConfirm.setVisibility(View.VISIBLE);
                    passcodeViewConfirm.requestFocus();
                    mPasscode = passcode;
                }
            }
        });

        passcodeViewConfirm.setPasscodeEntryListener(new PasscodeView.PasscodeEntryListener() {
            @Override
            public void onPasscodeEntered(String passcode) {
                mPasscodeConfirm = passcodeViewConfirm.getText().toString();
                if (mPasscode.equals(mPasscodeConfirm)) {
                    FlurryAgent.logEvent("Passcode Lock");

                    setStartButtonFunction(v);
                    materialStyledDialog.dismiss();
                } else {
                    passcodeView.clearText();
                    passcodeViewConfirm.clearText();
                    passcodeView.requestFocus();
                    passcodeViewConfirm.setVisibility(View.GONE);
                    txtPasscodeConfirm.setVisibility(View.GONE);
                }
            }
        });

    } else {
        setStartButtonFunction(v);
    }
}

From source file:com.mitre.holdshort.MainActivity.java

private void startMainActivity() {

    // Set screen layout
    setContentView(R.layout.main);/*from  w ww  .j  a va  2s .co m*/
    imageHelper = new ImageHelper();
    summaryGestureDetector = new GestureDetector(new summaryGester());

    // Get Reference to Shared Preferences file
    auralAlerts = settings.getBoolean("auralAlerts", true);
    settings.edit().putBoolean("auralAlerts", auralAlerts);
    announceRWY = settings.getBoolean("announceRWY", true);
    settings.edit().putBoolean("announceRWY", announceRWY);

    // Airport ID
    airportID = (TextView) findViewById(R.id.airportID);
    airportID.setText("K" + airport);

    // SpeechButton
    speechBtn = (ImageView) findViewById(R.id.speechBtn);
    speechBtn.setOnClickListener(speechBtnClickListener);

    // Get open close button
    openClose = (TextView) findViewById(R.id.openClose);
    openClose.setText("close");
    // openClose.setTextColor(Color.argb(200, 255, 255, 255));
    openClose.setOnClickListener(openCloseListener);

    // departure runway button
    depRwyBtn = (TextView) findViewById(R.id.depRwyBtn);
    depRwyBtn.setOnClickListener(depRwyListener);
    depRwyBtn.setText("Departure Rwy");
    depRwyBtn.setBackgroundResource(R.drawable.hatched_small_bg_layer);
    depRwyBtn.setPadding(10, 5, 10, 5);

    // info button - used to start prefs activity
    infoBtn = (ImageButton) findViewById(R.id.info_btn);
    // infoBtn.setBackgroundColor(Color.rgb(0,0,0));
    infoBtn.setOnClickListener(settingsMenuListener);

    // taxi button - used to start Taxi instruction activity
    taxiBtn = (ImageButton) findViewById(R.id.taxi_btn);
    // taxiBtn.setBackgroundColor(Color.rgb(0,0,0));
    taxiBtn.setOnClickListener(taxiBtnListener);

    // summary info - when drawer is closed
    summaryBar = (RelativeLayout) findViewById(R.id.summaryBar);
    summaryBar.setOnTouchListener(summaryTouchListener);
    runwayContainer = (LinearLayout) findViewById(R.id.holder);
    innerHolder = (LinearLayout) findViewById(R.id.innerHolder);
    slidingPanel = (SlidingPanel) findViewById(R.id.slidingDrawer);

    // header
    header = (RelativeLayout) findViewById(R.id.header);
    headerDropShadow = (View) findViewById(R.id.header_drop_shadow);
    slidingPanel.setHeaderDropShadow(headerDropShadow);
    slidingPanel.setRunwayContainer(runwayContainer);
    slidingPanel.setOpenCloseTextView(openClose);
    slidingPanel.setHandler(this.handler);

    summaryInfo = (RelativeLayout) findViewById(R.id.summary_info);
    summary_index = (TextView) findViewById(R.id.summary_index);
    summary_thumb = (TextView) findViewById(R.id.summary_thumb);
    summary_thumb.setWidth(90);

    // Taxi path area
    taxiClearance = (TextView) findViewById(R.id.taxiClearance);
    taxiClearance.setTextSize(12);
    taxiClearance.setPadding(5, 0, 5, 0);
    taxiClearance.setTextColor(Color.WHITE);
    // taxiClearance.setBackgroundColor(Color.rgb(0,0,0));
    taxiClearance.setOnClickListener(taxiPathListener);

    // Airport Diagram
    plateView = (AirportPlateView) findViewById(R.id.plateView);
    // Set up the nav control for the moving map
    // this is used when ownship is off screen
    navControl = (ImageView) findViewById(R.id.showNavBtn);
    plateView.setNavControls(navControl);
    navControl.setVisibility(ImageView.INVISIBLE);
    navControl.setOnClickListener(navControlListener);

    // // Lat/Lon Ref 1 SFO
    Point latLon1 = new Point(37.627827, -122.366794);
    Point latLon2 = new Point(37.606827, -122.380724);
    XYPoint xy1 = new XYPoint(134, 173);
    XYPoint xy2 = new XYPoint(340, 281);

    // Lat/Lon Ref 1 HEF
    // Point latLon1 = new Point(38.727680,-77.518803);
    // Point latLon2 = new Point(38.714041,-77.508976);
    // XYPoint xy1 = new XYPoint(140,187);
    // XYPoint xy2 = new XYPoint(322,513);
    plateView.geoReference(latLon1, latLon2, xy1, xy2);

    Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    plateView.updatePosition(loc.getBearing(), loc.getLatitude(), loc.getLongitude());

    // navView.setScroll(plateView);
    TextView emptyPlate = (TextView) findViewById(R.id.emptyPlate);

    if (!(plateView.setImage(airport))) {
        // Place holder if no plate is available
        emptyPlate.setVisibility(View.VISIBLE);
        plateView.setVisibility(View.GONE);

    } else {
        // Show plate. Hide placeholder
        plateView.setImage(airport);
        emptyPlate.setVisibility(View.GONE);
    }

    // Create logger for alerts
    alertLogger = new AlertLogger(airport, MainActivity.this);

    // Alert Panels
    alertScreen = (RelativeLayout) findViewById(R.id.alertScreen);
    betaControls = (LinearLayout) findViewById(R.id.betaControls);
    goodAlert = (TextView) findViewById(R.id.goodAlert);
    goodAlert.setOnClickListener(alertResponseListener);
    badAlert = (TextView) findViewById(R.id.badAlert);
    badAlert.setOnClickListener(alertResponseListener);
    lateAlert = (TextView) findViewById(R.id.lateAlert);
    lateAlert.setOnClickListener(alertResponseListener);
    earlyAlert = (TextView) findViewById(R.id.earlyAlert);
    earlyAlert.setOnClickListener(alertResponseListener);

    miniAlert = (TextView) findViewById(R.id.miniAlertText);
    miniAlert.setOnClickListener(maximizeAlert);

    holdShort = (LinearLayout) findViewById(R.id.holdShort);
    holdShort.getChildAt(0).setBackgroundDrawable(imageHelper
            .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.alert), 10));
    holdShort.setOnClickListener(minimizeAlert);
    noClearance = (LinearLayout) findViewById(R.id.noClearance);
    noClearance.setOnClickListener(minimizeAlert);
    noClearance.getChildAt(0).setBackgroundDrawable(imageHelper
            .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.alert), 10));
    crossingAlert = (LinearLayout) findViewById(R.id.crossingAlert);
    noTakeoffClearance = (LinearLayout) findViewById(R.id.noTakeoffClearance);
    noTakeoffClearance.getChildAt(0).setBackgroundDrawable(imageHelper
            .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.alert), 10));
    noTakeoffClearance.setOnClickListener(minimizeAlert);
    disabled_gps = (LinearLayout) findViewById(R.id.disabled_gps);
    disabled_gps.getChildAt(0).setBackgroundDrawable(imageHelper
            .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.disabled), 10));
    disabled_gps.setOnClickListener(minimizeAlert);

    disabled_speed = (LinearLayout) findViewById(R.id.disabled_speed);
    disabled_speed.getChildAt(0).setBackgroundDrawable(imageHelper
            .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.disabled), 10));
    disabled_speed.setOnClickListener(minimizeAlert);

    // Instantiate media player & set completion listener
    mp = new MediaPlayer();
    mp.setOnCompletionListener(alertPlaybackListener);

    // Instruction List instantiation
    instructionList = new ArrayList<String>();

    setUpRunways();
    slidingPanel.setOnTouchListener(summaryTouchListener);
    // Instantiate Alert Manager
    alertManager = new AlertManager(rwyMgr);

    allSetUp = true;
}

From source file:es.upv.riromu.arbre.main.MainActivity.java

private void updateVisibility()

{
    Boolean done = false;/*from   www  . j  a v a2 s  . com*/
    TextView imc = (TextView) findViewById(R.id.textView);
    //   imc.setBackgroundColor(Color.rgb(255, 255, 255));
    RangeSeekBar<Integer> rangeSeekBar = (RangeSeekBar<Integer>) findViewById(R.id.rangeseekbar);
    rangeSeekBar.setSelectedMinValue(MIN_TH);
    rangeSeekBar.setSelectedMaxValue(MAX_TH);

    ImageView imv = (ImageView) findViewById(R.id.image_intro);

    if (state[CROP_IMAGE]) {
        rangeSeekBar.setVisibility(View.VISIBLE);
    }
    if (!state[CROP_IMAGE]) {
        rangeSeekBar.setVisibility(View.GONE);
    }

    if (state[TREAT_IMAGE] && state[CROP_IMAGE] && (!state[SHOW_HISTOGRAM])) {
        state[TREAT_IMAGE] = false;
        imv.setImageBitmap(croppedimage);
        done = true;
    }

    if (state[TREAT_IMAGE] && (!state[CROP_IMAGE]) && (!state[SHOW_HISTOGRAM]) && (!done)) {
        state[TREAT_IMAGE] = false;

        imv.setImageBitmap(image);
        ImageButton cropButton = (ImageButton) findViewById(R.id.button_crop);
        cropButton.setVisibility(View.VISIBLE);
        imc.setVisibility(View.GONE);
        ImageButton sendButton = (ImageButton) findViewById(R.id.button_send);
        sendButton.setVisibility(View.GONE);
        ImageButton histButton = (ImageButton) findViewById(R.id.button_histogram);
        histButton.setVisibility(View.GONE);
        ImageButton revertButton = (ImageButton) findViewById(R.id.button_revert);
        revertButton.setVisibility(View.GONE);
        ImageView imagePalette = (ImageView) findViewById(R.id.palette);
        imagePalette.setVisibility(View.GONE);
        done = true;
    }
    if ((!state[TREAT_IMAGE]) && state[CROP_IMAGE] && (!state[SHOW_HISTOGRAM]) && (!done)) {
        state[CROP_IMAGE] = false;
        try {
            InputStream is = getContentResolver().openInputStream(image_uri);
            imv.setImageBitmap(BitmapFactory.decodeStream(is));
            is.close();
        } catch (FileNotFoundException e) {
            Log.e(TAG, "File not found" + e.getMessage());
        } catch (IOException e) {
            Log.e(TAG, "File not found" + e.getMessage());
        }
        croppedimage.recycle();
        done = true;
    }
    if ((!state[TREAT_IMAGE]) && (!state[CROP_IMAGE]) && (!state[SHOW_HISTOGRAM]) && (!done)) {
        image.recycle();
        image_uri = null;
        imv.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.platanus_hispanica));
        done = true;
    }
    if ((state[SHOW_HISTOGRAM]) && (!done)) {
        state[SHOW_HISTOGRAM] = false;
        rangeSeekBar.setVisibility(View.VISIBLE);
        imv.setImageBitmap(treatedimage);
        imc.setVisibility(View.VISIBLE);
        //                imc.setBackgroundColor(Color.rgb(colours[COLOUR_R], colours[COLOUR_G], colours[COLOUR_B]));

    }
}

From source file:com.stikyhive.stikyhive.ChattingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().setBackgroundDrawableResource(R.drawable.chat_bg);
    // this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    recipientStkid = getIntent().getExtras().getString("recipientStkid");
    chatRecipient = getIntent().getExtras().getString("chatRecipient");
    chatRecipientUrl = getIntent().getExtras().getString("chatRecipientUrl");
    senderToken = getIntent().getExtras().getString("senderToken");
    recipientToken = getIntent().getExtras().getString("recipientToken");
    noti = getIntent().getExtras().getBoolean("noti");
    message = getIntent().getExtras().getString("message");
    rows = getIntent().getExtras().getInt("rows");
    flagChatting = true;/*from  w w  w  . j  a  v  a 2s. c o m*/
    pref = PreferenceManager.getDefaultSharedPreferences(this);
    offerId = 0;
    offerStatus = 0;
    ws = new JsonWebService();
    dbHelper = new DBHelper(this);
    dialog = new ProgressDialog(this);
    listChatContact = new ArrayList<>();
    listChatContact = dbHelper.getChatContact();
    Log.i(" Chat Contact ", " " + listChatContact.size());
    metrics = this.getResources().getDisplayMetrics();
    //to change font
    faceSemi_bold = Typeface.createFromAsset(getAssets(), fontOSSemi_bold);
    Typeface faceLight = Typeface.createFromAsset(getAssets(), fontOSLight);
    faceRegular = Typeface.createFromAsset(getAssets(), fontOSRegular);

    imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited()) {
        imageLoader.init(ImageLoaderConfiguration.createDefault(this));
    }

    start = new Date();
    SimpleDateFormat oFormat = new SimpleDateFormat("dd MMM HH:mm");
    timeSend = oFormat.format(start);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.chat);

    layoutTalk = (LinearLayout) findViewById(R.id.layoutTalk);
    txtUserName = (TextView) findViewById(R.id.txtChatName);
    edTxtMsg = (EditText) findViewById(R.id.edTxtMsg);
    imgViewProfile = (ImageView) findViewById(R.id.imgViewChat);
    imgViewAddCon = (ImageView) findViewById(R.id.imgAddContact);
    lv = (ListView) findViewById(R.id.listView1);
    layoutLabel = (LinearLayout) findViewById(R.id.layoutLabel);
    txtLabel1 = (TextView) findViewById(R.id.txtLabel1);
    txtLabel2 = (TextView) findViewById(R.id.txtLabel2);
    txtLabel3 = (TextView) findViewById(R.id.txtLabel3);
    txtLabel2.setText(" " + chatRecipient + " ");
    txtLabel1.setTypeface(faceLight);
    txtLabel2.setTypeface(faceRegular);
    txtLabel3.setTypeface(faceLight);

    for (ChatContact contact : listChatContact) {
        if (contact.getContactId().equals(recipientStkid)) {
            imgViewAddCon.setVisibility(View.INVISIBLE);
            layoutLabel.setVisibility(View.GONE);
            break;
        }
    }
    Log.i(TAG, " come back again");
    adapter = new ChatArrayAdapter(this, R.layout.chatting_listview, faceSemi_bold, faceRegular, recipientStkid,
            senderToken, recipientToken);
    lv.setAdapter(adapter);
    // adapter.add(new StikyChat(chatRecipientUrl, "Hello", false, "12.10.2015", "12.1.2014"));

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    // BEGIN_INCLUDE (change_colors)
    // Set the color scheme of the SwipeRefreshLayout by providing 4 color resource ids
    swipeRefreshLayout.setColorScheme(R.color.swipe_color_1, R.color.swipe_color_2, R.color.swipe_color_3,
            R.color.swipe_color_4);
    limitMsg = 7;
    // END_INCLUDE (change_colors)
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Log.i(" Refresh Layout ", "onRefresh called from SwipeRefreshLayout");
            if (limitMsg < rows) {
                Log.i("Limit Message ", " " + limitMsg);
                limitMsg *= 2;
                fetchRecords();
            } else if ((!(rows <= 7)) && limitMsg > rows && (limitMsg - rows < 7)) {
                fetchRecords();
            } else {
                Log.i("No data ", "to refresh");
                swipeRefreshLayout.setRefreshing(false);
                Toast.makeText(getApplicationContext(), "No data to refresh!", Toast.LENGTH_SHORT).show();
            }
            // initiateRefresh();
        }
    });

    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout headerLayout = (LinearLayout) findViewById(R.id.header);
    View header = inflator.inflate(R.layout.header, null);

    TextView textView = (TextView) header.findViewById(R.id.textView1);
    textView.setText("StikyChat");
    textView.setTypeface(faceSemi_bold);
    textView.setVisibility(View.VISIBLE);
    headerLayout.addView(header);
    LinearLayout layoutRight = (LinearLayout) header.findViewById(R.id.layoutRight);
    layoutRight.setVisibility(View.GONE);

    txtUserName.setText(chatRecipient);
    Log.i(TAG, "Activity Name " + txtUserName.getText().toString());
    txtUserName.setTypeface(faceSemi_bold);

    String url = "";

    Log.i(TAG, " ^^^ " + chatRecipientUrl + " ");
    if (chatRecipientUrl != null) {
        if (chatRecipientUrl.contains("http")) {
            url = chatRecipientUrl;
        } else if (chatRecipientUrl != "null") {
            url = this.getResources().getString(R.string.url) + "/" + chatRecipientUrl;
        }
    }
    addAndroidUniversalImageLoader(imgViewProfile, url);
    //        if (noti && (!message.equals(""))) {
    //            adapter.add(new StikyChat(chatRecipientUrl, message, true, timeSend, ""));
    //            lv.smoothScrollToPosition(adapter.getCount() - 1);
    //        }

    //to show history chats between two users(sender & recipient)
    dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat2 = new SimpleDateFormat("dd MMM HH:mm");
    listHistory = dbHelper.getStikyChat();
    if (listHistory.size() > 0) {
        Collections.reverse(listHistory);
        for (final StikyChatTb chatTb : listHistory) {
            String getDate = chatTb.getSendDate();
            String durationStr = null;
            String fromStikyBee = chatTb.getSender();
            try {
                final String createDate = dateFormat2.format(dateFormat.parse(getDate));
                if (chatTb.getFileName().contains("voice")) {
                    MediaPlayer mPlayer = new MediaPlayer();
                    String voiceFileName = getResources().getString(R.string.url) + "/" + chatTb.getFileName();
                    try {
                        mPlayer.setDataSource(voiceFileName);
                        mPlayer.prepare();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    //mPlayer.start();
                    int duration = mPlayer.getDuration();
                    mPlayer.release();
                    duration = (int) Math.ceil(duration / 1024);

                    if (duration < 10) {
                        durationStr = "00:0" + duration;
                    } else {
                        durationStr = "00:" + duration;
                    }
                    // Log.i(TAG, "Duration Srt " + durationStr);
                }
                if (fromStikyBee.equals(pref.getString("stkid", ""))) {
                    //String url1 = getResources().getString(R.string.url) + "/" + chatTb.getFileName();
                    // Log.i(TAG, " Offer Id " + chatTb.getOfferId() + " Price " + chatTb.getPrice() + " Name " + chatTb.getName());
                    //first false = right, second false = Offer
                    //  Log.i(TAG, " Duration " + chatTb.getRate() + " File Name " + chatTb.getFileName());
                    if (!chatTb.getFileName().contains("voice")) {
                        Log.i(TAG, " Voice is not ");
                        adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), false, createDate,
                                chatTb.getFileName(), chatTb.getOfferId(), chatTb.getOfferStatus(),
                                chatTb.getPrice(), chatTb.getRate(), chatTb.getName(), null,
                                chatTb.getOriFName()));
                    } else {
                        Log.i(TAG, " Voice is ");
                        adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), false, createDate,
                                chatTb.getFileName(), chatTb.getOfferId(), chatTb.getOfferStatus(),
                                chatTb.getPrice(), chatTb.getRate(), durationStr, null, chatTb.getOriFName()));
                    }
                } else {
                    /* Bitmap bmImg = BitmapFactory.decodeFile(getResources().getString(R.string.url) + "/" + chatTb.getFileName());
                     Bitmap resBm = getResizedBitmap(bmImg, 500);*/
                    // String url1 = getResources().getString(R.string.url) + "/" + chatTb.getFileName();
                    if (!chatTb.getFileName().contains("voice")) {
                        adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), true, createDate,
                                chatTb.getFileName(), chatTb.getOfferId(), chatTb.getOfferStatus(),
                                chatTb.getPrice(), chatTb.getRate(), chatTb.getName(), null,
                                chatTb.getOriFName()));
                    } else {
                        adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), true, createDate,
                                chatTb.getFileName(), chatTb.getOfferId(), chatTb.getOfferStatus(),
                                chatTb.getPrice(), chatTb.getRate(), durationStr, null, chatTb.getOriFName()));
                    }
                }
                lv.smoothScrollToPosition(adapter.getCount() - 1);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }

    mRegistrationBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            fileNameGCM = sharedPreferences.getString("fileName", "");
            messageGCM = sharedPreferences.getString("message", "");
            offerIdGCM = sharedPreferences.getInt("offerId", 0);
            offerStatusGCM = sharedPreferences.getInt("offerStatus", 0);
            priceGCM = sharedPreferences.getString("price", "");
            rateGCM = sharedPreferences.getString("rate", "");
            nameGCM = sharedPreferences.getString("name", "");
            recipientProfileGCM = sharedPreferences.getString("chatRecipientUrl", "");
            recipientNameGCM = sharedPreferences.getString("chatRecipientName", "");
            recipientStkidGCM = sharedPreferences.getString("recipientStkid", "");
            recipientTokenGCM = sharedPreferences.getString("recipientToken", "");
            senderTokenGCM = sharedPreferences.getString("senderToken", "");

            Log.i(TAG, " FileName GCM " + fileNameGCM + " " + " Name Rate Price &&&&& *** " + messageGCM + " "
                    + priceGCM + " " + rateGCM);
            if (firstConnect) {
                if (recipientStkidGCM.trim() == recipientStkid.trim()
                        || recipientStkidGCM.equals(recipientStkid)) {
                    MyGcmListenerService.flagSendNoti = false;
                    Log.i(TAG, " " + message);
                    // (1) get today's date
                    start = new Date();
                    SimpleDateFormat oFormat = new SimpleDateFormat("dd MMM HH:mm");
                    timeSend = oFormat.format(start);

                    Log.i(TAG, "First connect " + firstConnect);
                    Log.i(TAG, " File Name GCMMMMMM " + fileNameGCM);
                    /*if (!fileNameGCM.equals("") && !fileNameGCM.equals("null") && !fileNameGCM.equals(null)) {
                    oriFName = saveFileAndImage(fileNameGCM);
                    }*/
                    /*if (fileNameGCM.contains("voice")) {
                    String durationStr;
                    MediaPlayer mPlayer = new MediaPlayer();
                    String voiceFileName = getResources().getString(R.string.url) + "/" + fileNameGCM;
                    try {
                        mPlayer.setDataSource(voiceFileName);
                        mPlayer.prepare();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                            
                    //mPlayer.start();
                    int duration = mPlayer.getDuration();
                    mPlayer.release();
                    duration = (int) Math.ceil(duration / 1024);
                            
                    if (duration < 10) {
                        durationStr = "00:0" + duration;
                    } else {
                        durationStr = "00:" + duration;
                    }
                    StikyChat stikyChat = new StikyChat(recipientProfileGCM, messageGCM, true, timeSend, fileNameGCM.trim(), offerIdGCM, offerStatusGCM, priceGCM, rateGCM, durationStr, null, oriFName);
                    adapter.add(stikyChat);
                    } else {*/
                    StikyChat stikyChat = new StikyChat(recipientProfileGCM, messageGCM, true, timeSend,
                            fileNameGCM.trim(), offerIdGCM, offerStatusGCM, priceGCM, rateGCM, nameGCM, null,
                            oriFName);
                    adapter.add(stikyChat);
                    //  }
                    Log.i(TAG, " First " + message + " " + recipientProfileGCM + " " + timeSend);
                    Log.i(TAG, "User " + txtUserName.getText().toString());

                    adapter.notifyDataSetChanged();
                    lv.setSelection(adapter.getCount() - 1);
                    new regTask2().execute("Obj ");
                } else {
                    /* if (!fileNameGCM.equals("") && !fileNameGCM.equals("null") && !fileNameGCM.equals(null)) {
                    saveFileAndImage(fileNameGCM);
                     }*/
                    Log.i(TAG, "..." + recipientStkidGCM.trim());
                    Log.i(TAG, "&&&" + recipientStkid.trim());
                    Log.i(TAG, "else casee");
                    //notificaton send
                    flagNotifi = true;
                    new regTask2().execute("Notification");
                }
                firstConnect = false;
            }
            lv.setSelection(adapter.getCount() - 1);
        }
    };

    /*edTxtMsg.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        layoutTalk.setLayoutParams(params);
        layoutTalk.setGravity(Gravity.CENTER);
      Toast.makeText(getBaseContext(),
                ((EditText) v).getId() + " has focus - " + hasFocus,
                Toast.LENGTH_LONG).show();
    }
    });*/
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    edTxtMsg.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 0);
            params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            layoutTalk.setLayoutParams(params);
            layoutTalk.setGravity(Gravity.CENTER);
            flagRecord = false;
            /*getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
            );*/
            Toast.makeText(getBaseContext(), "Touch ...", Toast.LENGTH_LONG).show();
            return false;
        }
    });
}

From source file:com.android.gallery3d.filtershow.info.InfoPanel.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getDialog() != null) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }//  w w w  . ja  v a  2s  . c o m

    mMainView = (LinearLayout) inflater.inflate(R.layout.filtershow_info_panel, null, false);

    mImageThumbnail = (ImageView) mMainView.findViewById(R.id.imageThumbnail);
    Bitmap bitmap = MasterImage.getImage().getFilteredImage();
    mImageThumbnail.setImageBitmap(bitmap);

    mImageName = (TextView) mMainView.findViewById(R.id.imageName);
    mImageSize = (TextView) mMainView.findViewById(R.id.imageSize);
    mExifData = (TextView) mMainView.findViewById(R.id.exifData);
    TextView exifLabel = (TextView) mMainView.findViewById(R.id.exifLabel);

    HistogramView histogramView = (HistogramView) mMainView.findViewById(R.id.histogramView);
    histogramView.setBitmap(bitmap);

    Uri uri = MasterImage.getImage().getUri();
    String path = ImageLoader.getLocalPathFromUri(getActivity(), uri);
    Uri localUri = null;
    if (path != null) {
        localUri = Uri.parse(path);
    }

    if (localUri != null) {
        mImageName.setText(localUri.getLastPathSegment());
    }
    Rect originalBounds = MasterImage.getImage().getOriginalBounds();
    mImageSize.setText("" + originalBounds.width() + " x " + originalBounds.height());

    List<ExifTag> exif = MasterImage.getImage().getEXIF();
    String exifString = "";
    boolean hasExifData = false;
    if (exif != null) {
        for (ExifTag tag : exif) {
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_MODEL, R.string.filtershow_exif_model);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_APERTURE_VALUE,
                    R.string.filtershow_exif_aperture);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_FOCAL_LENGTH,
                    R.string.filtershow_exif_focal_length);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_ISO_SPEED_RATINGS,
                    R.string.filtershow_exif_iso);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_SUBJECT_DISTANCE,
                    R.string.filtershow_exif_subject_distance);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_DATE_TIME_ORIGINAL,
                    R.string.filtershow_exif_date);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_F_NUMBER,
                    R.string.filtershow_exif_f_stop);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_EXPOSURE_TIME,
                    R.string.filtershow_exif_exposure_time);
            exifString += createStringFromIfFound(tag, ExifInterface.TAG_COPYRIGHT,
                    R.string.filtershow_exif_copyright);
            hasExifData = true;
        }
    }
    if (hasExifData) {
        exifLabel.setVisibility(View.VISIBLE);
        mExifData.setText(Html.fromHtml(exifString));
    } else {
        exifLabel.setVisibility(View.GONE);
    }
    return mMainView;
}

From source file:com.android.tv.menu.MenuLayoutManager.java

/**
 * Move the current selection to the given {@code position} with animation.
 * The animation specification is included in http://b/21069476
 *///  w  w  w  .  j a  va2  s .c  om
public void setSelectedPositionSmooth(final int position) {
    if (DEBUG) {
        Log.d(TAG, "setSelectedPositionSmooth(position=" + position + ") {previousPosition=" + mSelectedPosition
                + "}");
    }
    if (mMenuView.getVisibility() != View.VISIBLE) {
        setSelectedPosition(position);
        return;
    }
    if (mSelectedPosition == position) {
        return;
    }
    boolean oldIndexValid = Utils.isIndexValid(mMenuRowViews, mSelectedPosition);
    SoftPreconditions.checkState(oldIndexValid, TAG, "No previous selection: " + mSelectedPosition);
    if (!oldIndexValid) {
        return;
    }
    boolean newIndexValid = Utils.isIndexValid(mMenuRowViews, position);
    SoftPreconditions.checkArgument(newIndexValid, TAG, "position " + position);
    if (!newIndexValid) {
        return;
    }
    MenuRow row = mMenuRows.get(position);
    if (!row.isVisible()) {
        Log.e(TAG, "Moving to the invisible row: " + position);
        return;
    }
    if (mAnimatorSet != null) {
        // Do not cancel the animation here. The property values should be set to the end values
        // when the animation finishes.
        mAnimatorSet.end();
    }
    if (mTitleFadeOutAnimator != null) {
        // Cancel the animation instead of ending it in order that the title animation starts
        // again from the intermediate state.
        mTitleFadeOutAnimator.cancel();
    }
    final int oldPosition = mSelectedPosition;
    mSelectedPosition = position;
    if (DEBUG)
        dumpChildren("startRowAnimation()");

    MenuRowView currentView = mMenuRowViews.get(position);
    // Show the children of the next row.
    currentView.getTitleView().setVisibility(View.VISIBLE);
    currentView.getContentsView().setVisibility(View.VISIBLE);
    // Request focus after the new contents view shows up.
    mMenuView.requestFocus();
    if (mTempTitleViewForOld == null) {
        // Initialize here because we don't know when the views are inflated.
        mTempTitleViewForOld = (TextView) mMenuView.findViewById(R.id.temp_title_for_old);
        mTempTitleViewForCurrent = (TextView) mMenuView.findViewById(R.id.temp_title_for_current);
    }

    // Animations.
    mPropertyValuesAfterAnimation.clear();
    List<Animator> animators = new ArrayList<>();
    boolean scrollDown = position > oldPosition;
    List<Rect> layouts = getViewLayouts(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(),
            mMenuView.getBottom());

    // Old row.
    MenuRow oldRow = mMenuRows.get(oldPosition);
    MenuRowView oldView = mMenuRowViews.get(oldPosition);
    View oldContentsView = oldView.getContentsView();
    // Old contents view.
    animators.add(createAlphaAnimator(oldContentsView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn)
            .setDuration(mOldContentsFadeOutDuration));
    final TextView oldTitleView = oldView.getTitleView();
    setTempTitleView(mTempTitleViewForOld, oldTitleView);
    Rect oldLayoutRect = layouts.get(oldPosition);
    if (scrollDown) {
        // Old title view.
        if (oldRow.hideTitleWhenSelected() && oldTitleView.getVisibility() != View.VISIBLE) {
            // This case is not included in the animation specification.
            mTempTitleViewForOld.setScaleX(1.0f);
            mTempTitleViewForOld.setScaleY(1.0f);
            animators.add(createAlphaAnimator(mTempTitleViewForOld, 0.0f, oldView.getTitleViewAlphaDeselected(),
                    mFastOutLinearIn));
            int offset = oldLayoutRect.top - mTempTitleViewForOld.getTop();
            animators.add(createTranslationYAnimator(mTempTitleViewForOld, offset + mRowScrollUpAnimationOffset,
                    offset));
        } else {
            animators
                    .add(createScaleXAnimator(mTempTitleViewForOld, oldView.getTitleViewScaleSelected(), 1.0f));
            animators
                    .add(createScaleYAnimator(mTempTitleViewForOld, oldView.getTitleViewScaleSelected(), 1.0f));
            animators.add(createAlphaAnimator(mTempTitleViewForOld, oldTitleView.getAlpha(),
                    oldView.getTitleViewAlphaDeselected(), mLinearOutSlowIn));
            animators.add(createTranslationYAnimator(mTempTitleViewForOld, 0,
                    oldLayoutRect.top - mTempTitleViewForOld.getTop()));
        }
        oldTitleView.setAlpha(oldView.getTitleViewAlphaDeselected());
        oldTitleView.setVisibility(View.INVISIBLE);
    } else {
        Rect currentLayoutRect = new Rect(layouts.get(position));
        // Old title view.
        // The move distance in the specification is 32dp(mRowScrollUpAnimationOffset).
        // But if the height of the upper row is small, the upper row will move down a lot. In
        // this case, this row needs to move more than the specification to avoid the overlap of
        // the two titles.
        // The maximum is to the top of the start position of mTempTitleViewForOld.
        int distanceCurrentTitle = currentLayoutRect.top - currentView.getTop();
        int distance = Math.max(mRowScrollUpAnimationOffset, distanceCurrentTitle);
        int distanceToTopOfSecondTitle = oldLayoutRect.top - mRowScrollUpAnimationOffset - oldView.getTop();
        animators.add(
                createTranslationYAnimator(oldTitleView, 0.0f, Math.min(distance, distanceToTopOfSecondTitle)));
        animators.add(createAlphaAnimator(oldTitleView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn)
                .setDuration(mOldContentsFadeOutDuration));
        animators.add(createScaleXAnimator(oldTitleView, oldView.getTitleViewScaleSelected(), 1.0f));
        animators.add(createScaleYAnimator(oldTitleView, oldView.getTitleViewScaleSelected(), 1.0f));
        mTempTitleViewForOld.setScaleX(1.0f);
        mTempTitleViewForOld.setScaleY(1.0f);
        animators.add(createAlphaAnimator(mTempTitleViewForOld, 0.0f, oldView.getTitleViewAlphaDeselected(),
                mFastOutLinearIn));
        int offset = oldLayoutRect.top - mTempTitleViewForOld.getTop();
        animators.add(
                createTranslationYAnimator(mTempTitleViewForOld, offset - mRowScrollUpAnimationOffset, offset));
    }
    // Current row.
    Rect currentLayoutRect = new Rect(layouts.get(position));
    TextView currentTitleView = currentView.getTitleView();
    View currentContentsView = currentView.getContentsView();
    currentContentsView.setAlpha(0.0f);
    if (scrollDown) {
        // Current title view.
        setTempTitleView(mTempTitleViewForCurrent, currentTitleView);
        // The move distance in the specification is 32dp(mRowScrollUpAnimationOffset).
        // But if the height of the upper row is small, the upper row will move up a lot. In
        // this case, this row needs to start the move from more than the specification to avoid
        // the overlap of the two titles.
        // The maximum is to the top of the end position of mTempTitleViewForCurrent.
        int distanceOldTitle = oldView.getTop() - oldLayoutRect.top;
        int distance = Math.max(mRowScrollUpAnimationOffset, distanceOldTitle);
        int distanceTopOfSecondTitle = currentView.getTop() - mRowScrollUpAnimationOffset
                - currentLayoutRect.top;
        animators.add(createTranslationYAnimator(currentTitleView, Math.min(distance, distanceTopOfSecondTitle),
                0.0f));
        currentView.setTop(currentLayoutRect.top);
        ObjectAnimator animator = createAlphaAnimator(currentTitleView, 0.0f, 1.0f, mFastOutLinearIn)
                .setDuration(mCurrentContentsFadeInDuration);
        animator.setStartDelay(mOldContentsFadeOutDuration);
        currentTitleView.setAlpha(0.0f);
        animators.add(animator);
        animators.add(createScaleXAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected()));
        animators.add(createScaleYAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected()));
        animators.add(createTranslationYAnimator(mTempTitleViewForCurrent, 0.0f, -mRowScrollUpAnimationOffset));
        animators.add(createAlphaAnimator(mTempTitleViewForCurrent, currentView.getTitleViewAlphaDeselected(),
                0, mLinearOutSlowIn));
        // Current contents view.
        animators.add(createTranslationYAnimator(currentContentsView, mRowScrollUpAnimationOffset, 0.0f));
        animator = createAlphaAnimator(currentContentsView, 0.0f, 1.0f, mFastOutLinearIn)
                .setDuration(mCurrentContentsFadeInDuration);
        animator.setStartDelay(mOldContentsFadeOutDuration);
        animators.add(animator);
    } else {
        currentView.setBottom(currentLayoutRect.bottom);
        // Current title view.
        int currentViewOffset = currentLayoutRect.top - currentView.getTop();
        animators.add(createTranslationYAnimator(currentTitleView, 0, currentViewOffset));
        animators.add(createAlphaAnimator(currentTitleView, currentView.getTitleViewAlphaDeselected(), 1.0f,
                mFastOutSlowIn));
        animators.add(createScaleXAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected()));
        animators.add(createScaleYAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected()));
        // Current contents view.
        animators.add(createTranslationYAnimator(currentContentsView,
                currentViewOffset - mRowScrollUpAnimationOffset, currentViewOffset));
        ObjectAnimator animator = createAlphaAnimator(currentContentsView, 0.0f, 1.0f, mFastOutLinearIn)
                .setDuration(mCurrentContentsFadeInDuration);
        animator.setStartDelay(mOldContentsFadeOutDuration);
        animators.add(animator);
    }
    // Next row.
    int nextPosition;
    if (scrollDown) {
        nextPosition = findNextVisiblePosition(position);
        if (nextPosition != -1) {
            MenuRowView nextView = mMenuRowViews.get(nextPosition);
            Rect nextLayoutRect = layouts.get(nextPosition);
            animators.add(createTranslationYAnimator(nextView,
                    nextLayoutRect.top + mRowScrollUpAnimationOffset - nextView.getTop(),
                    nextLayoutRect.top - nextView.getTop()));
            animators.add(createAlphaAnimator(nextView, 0.0f, 1.0f, mFastOutLinearIn));
        }
    } else {
        nextPosition = findNextVisiblePosition(oldPosition);
        if (nextPosition != -1) {
            MenuRowView nextView = mMenuRowViews.get(nextPosition);
            animators.add(createTranslationYAnimator(nextView, 0, mRowScrollUpAnimationOffset));
            animators.add(createAlphaAnimator(nextView, nextView.getTitleViewAlphaDeselected(), 0.0f, 1.0f,
                    mLinearOutSlowIn));
        }
    }
    // Other rows.
    int count = mMenuRowViews.size();
    for (int i = 0; i < count; ++i) {
        MenuRowView view = mMenuRowViews.get(i);
        if (view.getVisibility() == View.VISIBLE && i != oldPosition && i != position && i != nextPosition) {
            Rect rect = layouts.get(i);
            animators.add(createTranslationYAnimator(view, 0, rect.top - view.getTop()));
        }
    }
    // Run animation.
    final List<ViewPropertyValueHolder> propertyValuesAfterAnimation = new ArrayList<>();
    propertyValuesAfterAnimation.addAll(mPropertyValuesAfterAnimation);
    mAnimatorSet = new AnimatorSet();
    mAnimatorSet.playTogether(animators);
    mAnimatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            if (DEBUG)
                dumpChildren("onRowAnimationEndBefore");
            mAnimatorSet = null;
            // The property values which are different from the end values and need to be
            // changed after the animation are set here.
            // e.g. setting translationY to 0, alpha of the contents view to 1.
            for (ViewPropertyValueHolder holder : propertyValuesAfterAnimation) {
                holder.property.set(holder.view, holder.value);
            }
            oldTitleView.setVisibility(View.VISIBLE);
            mMenuRowViews.get(oldPosition).onDeselected();
            mMenuRowViews.get(position).onSelected(true);
            mTempTitleViewForOld.setVisibility(View.GONE);
            mTempTitleViewForCurrent.setVisibility(View.GONE);
            layout(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(), mMenuView.getBottom());
            if (DEBUG)
                dumpChildren("onRowAnimationEndAfter");

            MenuRow currentRow = mMenuRows.get(position);
            if (currentRow.hideTitleWhenSelected()) {
                View titleView = mMenuRowViews.get(position).getTitleView();
                mTitleFadeOutAnimator = createAlphaAnimator(titleView, titleView.getAlpha(), 0.0f,
                        mLinearOutSlowIn);
                mTitleFadeOutAnimator.setStartDelay(TITLE_SHOW_DURATION_BEFORE_HIDDEN_MS);
                mTitleFadeOutAnimator.addListener(new AnimatorListenerAdapter() {
                    private boolean mCanceled;

                    @Override
                    public void onAnimationCancel(Animator animator) {
                        mCanceled = true;
                    }

                    @Override
                    public void onAnimationEnd(Animator animator) {
                        mTitleFadeOutAnimator = null;
                        if (!mCanceled) {
                            mMenuRowViews.get(position).onSelected(false);
                        }
                    }
                });
                mTitleFadeOutAnimator.start();
            }
        }
    });
    mAnimatorSet.start();
    if (DEBUG)
        dumpChildren("startedRowAnimation()");
}

From source file:android_network.hetnet.vpn_service.AdapterLog.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views//from  ww  w . j ava 2 s  .  c o m
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol);
    TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
    TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr);
    TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr);
    TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization);
    ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
    TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
    TextView tvData = (TextView) view.findViewById(R.id.tvData);
    ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false));

    // SHow TCP flags
    tvFlags.setText(flags);
    tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    if (info == null)
        ivIcon.setImageDrawable(null);
    else if (info.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
    else {
        Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon);
    }

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (resolve && !isKnownAddress(daddr))
        if (dname == null) {
            tvDaddr.setText(daddr);
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvDaddr, true);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return InetAddress.getByName(args[0]).getHostName();
                    } catch (UnknownHostException ignored) {
                        return args[0];
                    }
                }

                @Override
                protected void onPostExecute(String name) {
                    tvDaddr.setText(">" + name);
                    ViewCompat.setHasTransientState(tvDaddr, false);
                }
            }.execute(daddr);
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (organization) {
        if (!isKnownAddress(daddr))
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvOrganization, true);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    if (organization != null) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    ViewCompat.setHasTransientState(tvOrganization, false);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}