Example usage for android.widget RelativeLayout findViewById

List of usage examples for android.widget RelativeLayout findViewById

Introduction

In this page you can find the example usage for android.widget RelativeLayout findViewById.

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void showAbout() {
    AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

    RelativeLayout about = (RelativeLayout) getLayoutInflater().inflate(R.layout.about, getParentViewGroup(),
            false);//from   ww  w.ja va 2 s .  com

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        TextView version = (TextView) about.findViewById(R.id.version);
        version.setText(pInfo.versionName);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    ((TextView) about.findViewById(R.id.license))
            .setText(Html.fromHtml(getResources().getString(R.string.license)));

    TextView androidVersion = (TextView) about.findViewById(R.id.android_version);
    androidVersion.setText(Build.VERSION.RELEASE);

    TextView lastUpdate = (TextView) about.findViewById(R.id.data_update);
    lastUpdate.setText(DateFormat.getLongDateFormat(TvBrowser.this)
            .format(new Date(PrefUtils.getLongValue(R.string.LAST_DATA_UPDATE, 0))));

    TextView nextUpdate = (TextView) about.findViewById(R.id.next_data_update);

    switch (Integer.parseInt(
            PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_TYPE, R.string.pref_auto_update_type_default))) {
    case 0:
        nextUpdate.setText(R.string.next_data_update_manually);
        break;
    case 1:
        nextUpdate.setText(R.string.next_data_update_connection);
        break;
    case 2: {
        Date date = new Date(PrefUtils.getLongValue(R.string.AUTO_UPDATE_CURRENT_START_TIME, 0));
        nextUpdate.setText(DateFormat.getMediumDateFormat(TvBrowser.this).format(date) + " "
                + DateFormat.getTimeFormat(TvBrowser.this).format(date));
    }
        break;
    }

    ((TextView) about.findViewById(R.id.rundate_value))
            .setText(DateFormat.getLongDateFormat(getApplicationContext()).format(mRundate.getTime()));

    builder.setTitle(R.string.action_about);
    builder.setView(about);

    builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    builder.show();
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void showUserSetting(final String initiateUserName, final String initiatePassword,
        final boolean syncChannels) {
    AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);
    builder.setCancelable(false);/*from   w  w w.j  av a  2 s . c o  m*/

    RelativeLayout username_password_setup = (RelativeLayout) getLayoutInflater()
            .inflate(R.layout.username_password_setup, getParentViewGroup(), false);

    final SharedPreferences pref = getSharedPreferences("transportation", Context.MODE_PRIVATE);

    final EditText userName = (EditText) username_password_setup.findViewById(R.id.username_entry);
    final EditText password = (EditText) username_password_setup.findViewById(R.id.password_entry);

    userName.setText(
            pref.getString(SettingConstants.USER_NAME, initiateUserName != null ? initiateUserName : ""));
    password.setText(
            pref.getString(SettingConstants.USER_PASSWORD, initiatePassword != null ? initiatePassword : ""));

    builder.setView(username_password_setup);

    builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            setUserName(userName.getText().toString().trim(), password.getText().toString().trim(),
                    syncChannels);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (syncChannels) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        showChannelSelectionInternal();
                    }
                });
            }
        }
    });

    AlertDialog d = builder.create();

    d.show();

    ((TextView) d.findViewById(R.id.user_pw_sync_info)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void updateTvData() {
    if (!TvDataUpdateService.IS_RUNNING) {
        Cursor test = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null,
                TvBrowserContentProvider.CHANNEL_KEY_SELECTION + "=1", null, null);

        if (test.getCount() > 0) {
            AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

            RelativeLayout dataDownload = (RelativeLayout) getLayoutInflater()
                    .inflate(R.layout.dialog_data_update_selection, getParentViewGroup(), false);

            final Spinner days = (Spinner) dataDownload
                    .findViewById(R.id.dialog_data_update_selection_download_days);
            final CheckBox pictures = (CheckBox) dataDownload
                    .findViewById(R.id.dialog_data_update_selection_download_picture);

            final Spinner autoUpdate = (Spinner) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type);
            final Spinner frequency = (Spinner) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_frequency);
            final CheckBox onlyWiFi = (CheckBox) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type_connection);
            final TextView timeLabel = (TextView) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time_label);
            final TextView time = (TextView) dataDownload
                    .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time);
            time.setTextColor(onlyWiFi.getTextColors());

            String currentDownloadDays = PrefUtils.getStringValue(R.string.DAYS_TO_DOWNLOAD,
                    R.string.days_to_download_default);

            final String[] possibleDownloadDays = getResources().getStringArray(R.array.download_days);

            for (int i = 0; i < possibleDownloadDays.length; i++) {
                if (currentDownloadDays.equals(possibleDownloadDays[i])) {
                    days.setSelection(i);
                    break;
                }//from   w  ww .j  ava  2s. co  m
            }

            pictures.setChecked(
                    PrefUtils.getBooleanValue(R.string.LOAD_PICTURE_DATA, R.bool.load_picture_data_default));

            String currentAutoUpdateValue = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_TYPE,
                    R.string.pref_auto_update_type_default);
            String currentAutoUpdateFrequency = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_FREQUENCY,
                    R.string.pref_auto_update_frequency_default);

            if (currentAutoUpdateValue.equals("0")) {
                frequency.setEnabled(false);
                onlyWiFi.setEnabled(false);
                timeLabel.setEnabled(false);
                time.setEnabled(false);
                frequency.setVisibility(View.GONE);
                onlyWiFi.setVisibility(View.GONE);
                timeLabel.setVisibility(View.GONE);
                time.setVisibility(View.GONE);
            } else if (currentAutoUpdateValue.equals("1")) {
                autoUpdate.setSelection(1);
                timeLabel.setEnabled(false);
                time.setEnabled(false);
                timeLabel.setVisibility(View.GONE);
                time.setVisibility(View.GONE);
            } else if (currentAutoUpdateValue.equals("2")) {
                autoUpdate.setSelection(2);
            }

            final String[] autoFrequencyPossibleValues = getResources()
                    .getStringArray(R.array.pref_auto_update_frequency_values);

            for (int i = 0; i < autoFrequencyPossibleValues.length; i++) {
                if (autoFrequencyPossibleValues[i].equals(currentAutoUpdateFrequency)) {
                    frequency.setSelection(i);
                    break;
                }
            }

            onlyWiFi.setChecked(PrefUtils.getBooleanValue(R.string.PREF_AUTO_UPDATE_ONLY_WIFI,
                    R.bool.pref_auto_update_only_wifi_default));

            final AtomicInteger currentAutoUpdateTime = new AtomicInteger(PrefUtils.getIntValue(
                    R.string.PREF_AUTO_UPDATE_START_TIME, R.integer.pref_auto_update_start_time_default));

            Calendar now = Calendar.getInstance();

            now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60);
            now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60);
            now.set(Calendar.SECOND, 0);
            now.set(Calendar.MILLISECOND, 0);

            time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime()));

            autoUpdate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    frequency.setEnabled(position != 0);
                    onlyWiFi.setEnabled(position != 0);

                    if (position != 0) {
                        frequency.setVisibility(View.VISIBLE);
                        onlyWiFi.setVisibility(View.VISIBLE);
                    } else {
                        frequency.setVisibility(View.GONE);
                        onlyWiFi.setVisibility(View.GONE);
                    }

                    timeLabel.setEnabled(position == 2);
                    time.setEnabled(position == 2);

                    if (position == 2) {
                        timeLabel.setVisibility(View.VISIBLE);
                        time.setVisibility(View.VISIBLE);
                    } else {
                        timeLabel.setVisibility(View.GONE);
                        time.setVisibility(View.GONE);
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

            View.OnClickListener onClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder b2 = new AlertDialog.Builder(TvBrowser.this);

                    LinearLayout timeSelection = (LinearLayout) getLayoutInflater().inflate(
                            R.layout.dialog_data_update_selection_auto_update_time, getParentViewGroup(),
                            false);

                    final TimePicker timePick = (TimePicker) timeSelection
                            .findViewById(R.id.dialog_data_update_selection_auto_update_selection_time);
                    timePick.setIs24HourView(DateFormat.is24HourFormat(TvBrowser.this));
                    timePick.setCurrentHour(currentAutoUpdateTime.get() / 60);
                    timePick.setCurrentMinute(currentAutoUpdateTime.get() % 60);

                    b2.setView(timeSelection);

                    b2.setPositiveButton(android.R.string.ok, new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            currentAutoUpdateTime
                                    .set(timePick.getCurrentHour() * 60 + timePick.getCurrentMinute());

                            Calendar now = Calendar.getInstance();

                            now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60);
                            now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60);
                            now.set(Calendar.SECOND, 0);
                            now.set(Calendar.MILLISECOND, 0);

                            time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime()));
                        }
                    });
                    b2.setNegativeButton(android.R.string.cancel, null);

                    b2.show();
                }
            };

            time.setOnClickListener(onClickListener);
            timeLabel.setOnClickListener(onClickListener);

            builder.setTitle(R.string.download_data);
            builder.setView(dataDownload);

            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String value = possibleDownloadDays[days.getSelectedItemPosition()];

                    Editor settings = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit();

                    if (PrefUtils.getStringValueAsInt(R.string.PREF_AUTO_UPDATE_RANGE,
                            R.string.pref_auto_update_range_default) < Integer.parseInt(value)) {
                        settings.putString(getString(R.string.PREF_AUTO_UPDATE_RANGE), value);
                    }

                    settings.putString(getString(R.string.DAYS_TO_DOWNLOAD), value);
                    settings.putBoolean(getString(R.string.LOAD_PICTURE_DATA), pictures.isChecked());
                    settings.putString(getString(R.string.PREF_AUTO_UPDATE_TYPE),
                            String.valueOf(autoUpdate.getSelectedItemPosition()));

                    if (autoUpdate.getSelectedItemPosition() == 1
                            || autoUpdate.getSelectedItemPosition() == 2) {
                        settings.putString(getString(R.string.PREF_AUTO_UPDATE_FREQUENCY),
                                autoFrequencyPossibleValues[frequency.getSelectedItemPosition()]);
                        settings.putBoolean(getString(R.string.PREF_AUTO_UPDATE_ONLY_WIFI),
                                onlyWiFi.isChecked());

                        if (autoUpdate.getSelectedItemPosition() == 2) {
                            settings.putInt(getString(R.string.PREF_AUTO_UPDATE_START_TIME),
                                    currentAutoUpdateTime.get());
                        }
                    }

                    settings.commit();

                    IOUtils.handleDataUpdatePreferences(TvBrowser.this);

                    Intent startDownload = new Intent(TvBrowser.this, TvDataUpdateService.class);
                    startDownload.putExtra(TvDataUpdateService.TYPE, TvDataUpdateService.TV_DATA_TYPE);
                    startDownload.putExtra(getResources().getString(R.string.DAYS_TO_DOWNLOAD),
                            Integer.parseInt(value));

                    startService(startDownload);

                    updateProgressIcon(true);
                }
            });
            builder.setNegativeButton(android.R.string.cancel, null);
            builder.show();
        } else {
            Cursor test2 = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null, null,
                    null, null);

            boolean loadAgain = test2.getCount() < 1;

            test2.close();

            selectChannels(loadAgain);
        }

        test.close();
    }
}