Example usage for android.content.res Resources getString

List of usage examples for android.content.res Resources getString

Introduction

In this page you can find the example usage for android.content.res Resources getString.

Prototype

@NonNull
public String getString(@StringRes int id) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.codetroopers.betterpickers.calendardatepicker.MonthView.java

public MonthView(Context context) {
    super(context);
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.sans_serif);

    mDayTextColorEnabled = res.getColor(R.color.date_picker_text_normal);
    mDayTextColorDisabled = res.getColor(R.color.date_picker_text_disabled);
    mTodayNumberColor = res.getColor(R.color.bpBlue);
    mDayBackgroundColorDisabled = res.getColor(R.color.bpDarker_red);
    mMonthTitleColor = res.getColor(R.color.date_picker_text_normal);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height) - MONTH_HEADER_SIZE)
            / MAX_NUM_ROWS;/*from  w w  w  . ja  v a 2  s. c  om*/

    // Set up accessibility components.
    mTouchHelper = new MonthViewTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}

From source file:com.chauffeurprive.kronos.time.AmPmCirclesView.java

public void initialize(Context context, TimePickerController controller, int amOrPm) {
    if (mIsInitialized) {
        Log.e(TAG, "AmPmCirclesView may only be initialized once.");
        return;/*ww w.j  a  v  a2 s  .c o m*/
    }

    Resources res = context.getResources();

    mUnselectedColor = ContextCompat.getColor(context, controller.getCircleBackgroundColor());
    mAmPmTextColor = ContextCompat.getColor(context, controller.getTextColor());
    mAmPmDisabledTextColor = ContextCompat.getColor(context, controller.getDisabledTextColor());
    mSelectedAlpha = SELECTED_ALPHA;

    mSelectedColor = ContextCompat.getColor(context, controller.getAccentColor());
    mTouchedColor = ContextCompat.getColor(context, controller.getDisabledTextColor());
    mAmPmSelectedTextColor = ContextCompat.getColor(context, controller.getSelectedTextColor());

    String typefaceFamily = res.getString(R.string.mdtp_sans_serif);
    Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
    mPaint.setTypeface(tf);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);

    mCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string.mdtp_circle_radius_multiplier));
    mAmPmCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string.mdtp_ampm_circle_radius_multiplier));
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mAmDisabled = controller.isAmDisabled();
    mPmDisabled = controller.isPmDisabled();

    setAmOrPm(amOrPm);
    mAmOrPmPressed = -1;

    mIsInitialized = true;
}

From source file:com.codetroopers.betterpickers.calendardatepicker.CalendarDatePickerDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView: ");
    if (getShowsDialog()) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }//from  w w w. j a v  a 2 s  .c  o m

    View view = inflater.inflate(R.layout.calendar_date_picker_dialog, container, false);

    mSelectedDateLayout = (LinearLayout) view.findViewById(R.id.day_picker_selected_date_layout);
    mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header);
    mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day);
    mMonthAndDayView.setOnClickListener(this);
    mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month);
    mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day);
    mYearView = (TextView) view.findViewById(R.id.date_picker_year);
    mYearView.setOnClickListener(this);

    int listPosition = -1;
    int listPositionOffset = 0;
    int currentView = MONTH_AND_DAY_VIEW;
    if (savedInstanceState != null) {
        mWeekStart = savedInstanceState.getInt(KEY_WEEK_START);
        mMinDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_START));
        mMaxDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_END));
        currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW);
        listPosition = savedInstanceState.getInt(KEY_LIST_POSITION);
        listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET);
        mStyleResId = savedInstanceState.getInt(KEY_THEME);
        mDisabledDays = savedInstanceState.getSparseParcelableArray(KEY_DISABLED_DAYS);
    }

    final Activity activity = getActivity();
    mDayPickerView = new SimpleDayPickerView(activity, this);
    mYearPickerView = new YearPickerView(activity, this);

    Resources res = getResources();
    TypedArray themeColors = getActivity().obtainStyledAttributes(mStyleResId,
            R.styleable.BetterPickersDialogs);
    mDayPickerDescription = res.getString(R.string.day_picker_description);
    mSelectDay = res.getString(R.string.select_day);
    mYearPickerDescription = res.getString(R.string.year_picker_description);
    mSelectYear = res.getString(R.string.select_year);

    int headerBackgroundColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderBackgroundColor,
            ContextCompat.getColor(getActivity(), R.color.bpWhite));
    int preHeaderBackgroundColor = themeColors.getColor(
            R.styleable.BetterPickersDialogs_bpPreHeaderBackgroundColor,
            ContextCompat.getColor(getActivity(), R.color.bpWhite));
    int bodyBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpBodyBackgroundColor,
            ContextCompat.getColor(getActivity(), R.color.bpWhite));
    int buttonBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsBackgroundColor,
            ContextCompat.getColor(getActivity(), R.color.bpWhite));
    int buttonTextColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsTextColor,
            ContextCompat.getColor(getActivity(), R.color.bpBlue));
    mSelectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderSelectedTextColor,
            ContextCompat.getColor(getActivity(), R.color.bpWhite));
    mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderUnselectedTextColor,
            ContextCompat.getColor(getActivity(), R.color.radial_gray_light));

    mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator);
    mAnimator.addView(mDayPickerView);
    mAnimator.addView(mYearPickerView);
    mAnimator.setDateMillis(mCalendar.getTimeInMillis());
    // TODO: Replace with animation decided upon by the design team.
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(ANIMATION_DURATION);
    mAnimator.setInAnimation(animation);
    // TODO: Replace with animation decided upon by the design team.
    Animation animation2 = new AlphaAnimation(1.0f, 0.0f);
    animation2.setDuration(ANIMATION_DURATION);
    mAnimator.setOutAnimation(animation2);

    Button doneButton = (Button) view.findViewById(R.id.done_button);
    if (mDoneText != null) {
        doneButton.setText(mDoneText);
    }
    doneButton.setTextColor(buttonTextColor);
    doneButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tryVibrate();
            if (mCallBack != null) {
                mCallBack.onDateSet(CalendarDatePickerDialogFragment.this, mCalendar.get(Calendar.YEAR),
                        mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
            }
            dismiss();
        }
    });
    Button cancelButton = (Button) view.findViewById(R.id.cancel_button);
    if (mCancelText != null) {
        cancelButton.setText(mCancelText);
    }
    cancelButton.setTextColor(buttonTextColor);
    cancelButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tryVibrate();
            dismiss();
        }
    });
    view.findViewById(R.id.ok_cancel_buttons_layout).setBackgroundColor(buttonBgColor);

    updateDisplay(false);
    setCurrentView(currentView);

    if (listPosition != -1) {
        if (currentView == MONTH_AND_DAY_VIEW) {
            mDayPickerView.postSetSelection(listPosition);
        } else if (currentView == YEAR_VIEW) {
            mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset);
        }
    }

    mHapticFeedbackController = new HapticFeedbackController(activity);

    mDayPickerView.setTheme(themeColors);
    mYearPickerView.setTheme(themeColors);

    mSelectedDateLayout.setBackgroundColor(headerBackgroundColor);
    mYearView.setBackgroundColor(headerBackgroundColor);
    mMonthAndDayView.setBackgroundColor(headerBackgroundColor);

    if (mDayOfWeekView != null) {
        mDayOfWeekView.setBackgroundColor(preHeaderBackgroundColor);
    }
    view.setBackgroundColor(bodyBgColor);
    mYearPickerView.setBackgroundColor(bodyBgColor);
    mDayPickerView.setBackgroundColor(bodyBgColor);

    return view;
}

From source file:com.bangz.smartmute.LocationsMapFragment.java

private String makeTriggerInfoString(Cursor cursor) {
    String strcondition = cursor.getString(cursor.getColumnIndex(RulesColumns.CONDITION));
    LocationCondition condition = new LocationCondition(strcondition);

    float radius = cursor.getFloat(cursor.getColumnIndex(RulesColumns.RADIUS));
    LocationCondition.TriggerCondition tc = condition.getTriggerCondition();
    Resources res = getResources();

    if (tc.getTransitionType() == Geofence.GEOFENCE_TRANSITION_ENTER) {
        return String.format(res.getString(R.string.info_trigger_by_enter), (int) radius);
    } else {/*  ww  w .j a  va 2 s .  co m*/
        return String.format(res.getString(R.string.info_trigger_by_dwell), (int) radius,
                tc.getLoiteringDelay() / Constants.ONE_MINUTE_IN_MS);
    }

}

From source file:com.zia.freshdocs.widget.CMISAdapter.java

protected void startProgressDlg(boolean indeterminate) {
    Context context = getContext();
    Resources res = context.getResources();

    if (_progressDlg == null || !_progressDlg.isShowing()) {
        _progressDlg = new ProgressDialog(context);
        _progressDlg.setProgressStyle(/*w  w w  .  j  av  a  2  s. c o m*/
                indeterminate ? ProgressDialog.STYLE_SPINNER : ProgressDialog.STYLE_HORIZONTAL);
        _progressDlg.setMessage(res.getString(R.string.loading));
        _progressDlg.setTitle("");
        _progressDlg.setCancelable(true);
        _progressDlg.setIndeterminate(indeterminate);
        _progressDlg.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                interrupt();
            }
        });
        _progressDlg.show();
    }
}

From source file:com.betterAlarm.deskclock.timer.TimerFragment.java

private void setTimerViewFabIcon(TimerObj timer) {
    final Context context = getActivity();
    if (context == null || timer == null || mFab == null) {
        return;//from   w ww . j ava2  s .com
    }
    final Resources r = context.getResources();
    switch (timer.mState) {
    case TimerObj.STATE_RUNNING:
        mFab.setVisibility(View.VISIBLE);
        mFab.setContentDescription(r.getString(R.string.timer_stop));
        mFab.setImageResource(R.drawable.ic_fab_pause);
        break;
    case TimerObj.STATE_STOPPED:
    case TimerObj.STATE_RESTART:
        mFab.setVisibility(View.VISIBLE);
        mFab.setContentDescription(r.getString(R.string.timer_start));
        mFab.setImageResource(R.drawable.ic_fab_play);
        break;
    case TimerObj.STATE_DONE: // time-up then stopped
        mFab.setVisibility(View.INVISIBLE);
        break;
    case TimerObj.STATE_TIMESUP: // time-up but didn't stopped, continue negative ticking
        mFab.setVisibility(View.VISIBLE);
        mFab.setContentDescription(r.getString(R.string.timer_stop));
        mFab.setImageResource(R.drawable.ic_fab_stop);
        break;
    default:
    }
}

From source file:com.androidinspain.deskclock.data.TimerNotificationBuilder.java

public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) {
    final Timer timer = unexpired.get(0);
    final int count = unexpired.size();

    // Compute some values required below.
    final boolean running = timer.isRunning();
    final Resources res = context.getResources();

    final long base = getChronometerBase(timer);
    final String pname = context.getPackageName();

    final List<Action> actions = new ArrayList<>(2);

    final CharSequence stateText;
    if (count == 1) {
        if (running) {
            // Single timer is running.
            if (TextUtils.isEmpty(timer.getLabel())) {
                stateText = res.getString(com.androidinspain.deskclock.R.string.timer_notification_label);
            } else {
                stateText = timer.getLabel();
            }//w  ww.ja v  a 2  s  .c o  m

            // Left button: Pause
            final Intent pause = new Intent(context, TimerService.class)
                    .setAction(TimerService.ACTION_PAUSE_TIMER)
                    .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId());

            @DrawableRes
            final int icon1 = com.androidinspain.deskclock.R.drawable.ic_pause_24dp;
            final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_pause);
            final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause);
            actions.add(new Action.Builder(icon1, title1, intent1).build());

            // Right Button: +1 Minute
            final Intent addMinute = new Intent(context, TimerService.class)
                    .setAction(TimerService.ACTION_ADD_MINUTE_TIMER)
                    .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId());

            @DrawableRes
            final int icon2 = com.androidinspain.deskclock.R.drawable.ic_add_24dp;
            final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.timer_plus_1_min);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute);
            actions.add(new Action.Builder(icon2, title2, intent2).build());

        } else {
            // Single timer is paused.
            stateText = res.getString(com.androidinspain.deskclock.R.string.timer_paused);

            // Left button: Start
            final Intent start = new Intent(context, TimerService.class)
                    .setAction(TimerService.ACTION_START_TIMER)
                    .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId());

            @DrawableRes
            final int icon1 = com.androidinspain.deskclock.R.drawable.ic_start_24dp;
            final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.sw_resume_button);
            final PendingIntent intent1 = Utils.pendingServiceIntent(context, start);
            actions.add(new Action.Builder(icon1, title1, intent1).build());

            // Right Button: Reset
            final Intent reset = new Intent(context, TimerService.class)
                    .setAction(TimerService.ACTION_RESET_TIMER)
                    .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId());

            @DrawableRes
            final int icon2 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp;
            final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.sw_reset_button);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset);
            actions.add(new Action.Builder(icon2, title2, intent2).build());
        }
    } else {
        if (running) {
            // At least one timer is running.
            stateText = res.getString(com.androidinspain.deskclock.R.string.timers_in_use, count);
        } else {
            // All timers are paused.
            stateText = res.getString(com.androidinspain.deskclock.R.string.timers_stopped, count);
        }

        final Intent reset = TimerService.createResetUnexpiredTimersIntent(context);

        @DrawableRes
        final int icon1 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp;
        final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_reset_all);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);
        actions.add(new Action.Builder(icon1, title1, intent1).build());
    }

    // Intent to load the app and show the timer when the notification is tapped.
    final Intent showApp = new Intent(context, TimerService.class).setAction(TimerService.ACTION_SHOW_TIMER)
            .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId())
            .putExtra(Events.EXTRA_EVENT_LABEL, com.androidinspain.deskclock.R.string.label_notification);

    final PendingIntent pendingShowApp = PendingIntent.getService(context, REQUEST_CODE_UPCOMING, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    final Builder notification = new NotificationCompat.Builder(context).setOngoing(true).setLocalOnly(true)
            .setShowWhen(false).setAutoCancel(false).setContentIntent(pendingShowApp)
            .setPriority(Notification.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM)
            .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_timer)
            .setSortKey(nm.getTimerNotificationSortKey()).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
            .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background));

    for (Action action : actions) {
        notification.addAction(action);
    }

    if (Utils.isNOrLater()) {
        notification.setCustomContentView(buildChronometer(pname, base, running, stateText))
                .setGroup(nm.getTimerNotificationGroupKey());
    } else {
        final CharSequence contentTextPreN;
        if (count == 1) {
            contentTextPreN = TimerStringFormatter.formatTimeRemaining(context, timer.getRemainingTime(),
                    false);
        } else if (running) {
            final String timeRemaining = TimerStringFormatter.formatTimeRemaining(context,
                    timer.getRemainingTime(), false);
            contentTextPreN = context.getString(com.androidinspain.deskclock.R.string.next_timer_notif,
                    timeRemaining);
        } else {
            contentTextPreN = context.getString(com.androidinspain.deskclock.R.string.all_timers_stopped_notif);
        }

        notification.setContentTitle(stateText).setContentText(contentTextPreN);

        final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        final Intent updateNotification = TimerService.createUpdateNotificationIntent(context);
        final long remainingTime = timer.getRemainingTime();
        if (timer.isRunning() && remainingTime > MINUTE_IN_MILLIS) {
            // Schedule a callback to update the time-sensitive information of the running timer
            final PendingIntent pi = PendingIntent.getService(context, REQUEST_CODE_UPCOMING,
                    updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

            final long nextMinuteChange = remainingTime % MINUTE_IN_MILLIS;
            final long triggerTime = SystemClock.elapsedRealtime() + nextMinuteChange;
            TimerModel.schedulePendingIntent(am, triggerTime, pi);
        } else {
            // Cancel the update notification callback.
            final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification,
                    PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE);
            if (pi != null) {
                am.cancel(pi);
                pi.cancel();
            }
        }
    }

    return notification.build();
}

From source file:org.thomnichols.android.gmarks.GmarksProvider.java

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    // Validate the requested uri
    if (sUriMatcher.match(uri) != BOOKMARKS_URI) {
        throw new IllegalArgumentException("Unknown URI " + uri);
    }/*w  w w  .j  a v  a 2s  .  co m*/

    ContentValues values;
    if (initialValues != null) {
        values = new ContentValues(initialValues);
    } else {
        values = new ContentValues();
    }

    Long now = Long.valueOf(System.currentTimeMillis());

    // Make sure that the fields are all set
    if (values.containsKey(Bookmark.Columns.CREATED_DATE) == false) {
        values.put(Bookmark.Columns.CREATED_DATE, now);
    }

    if (values.containsKey(Bookmark.Columns.MODIFIED_DATE) == false) {
        values.put(Bookmark.Columns.MODIFIED_DATE, now);
    }

    if (values.containsKey(Bookmark.Columns.TITLE) == false) {
        Resources r = Resources.getSystem();
        values.put(Bookmark.Columns.TITLE, r.getString(android.R.string.untitled));
    }

    if (values.containsKey(Bookmark.Columns.DESCRIPTION) == false) {
        values.put(Bookmark.Columns.DESCRIPTION, "");
    }

    SQLiteDatabase db = dbHelper.getWritableDatabase();
    long rowId = db.insert(BOOKMARKS_TABLE_NAME, "", values);
    if (rowId > 0) {
        Uri noteUri = ContentUris.withAppendedId(Bookmark.CONTENT_URI, rowId);
        getContext().getContentResolver().notifyChange(noteUri, null);
        return noteUri;
    }

    throw new SQLException("Failed to insert row into " + uri);
}

From source file:com.amazon.appstream.sampleclient.SampleClientActivity.java

@Override
public void onDialogConnectClick(String address, String appid, String userid, boolean hardwareEnabled) {

    Resources r = getResources();

    if (hardwareEnabled) {
        attemptEnableHardwareDecode();//  w  w w  .jav  a2s .  co  m
    } else {
        disableHardwareDecode();
    }

    mStopped = false;

    if (address == null || address.isEmpty()) {
        openConnectDialog(r.getString(R.string.no_address));
    } else if (appid == null) {
        if (!address.matches("\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}")) {
            openConnectDialog(r.getString(R.string.invalid_address));
            return;
        }

        mServerAddress = address;
        mUseAppServer = true;

        String url = String.format(Locale.US, "ssm://%s:%d?sessionId=%s", address, 80, "9070-0");
        AppStreamInterface.connect(url);
        AppStreamInterface.newFrame();

        savePrefs();
        return;
    } else if (address != null && address.matches(
            "^(http[s]?://)?([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}(:[0-9]+)?(/.*)?$")
            || address.matches("^(http[s]?://)?\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}(:[0-9]+)?(/.*)?$")) {
        if (userid == null || (userid.isEmpty())) {
            openConnectDialog(r.getString(R.string.user_id_required));
            return;
        } else if (appid.isEmpty()) {
            openConnectDialog(r.getString(R.string.app_id_required));
            return;
        }
        mUseAppServer = false;
        mDESServerAddress = address;
        mAppId = appid;
        mUserId = userid;
        savePrefs();

        // we've received an entitlement server + path
        mDesQuery.setActivity(this);
        mDesQuery.setListener(this);
        mDesQuery.makeQuery(address, appid, userid);
    } else {
        openConnectDialog(r.getString(R.string.invalid_address));
    }
}

From source file:com.amazon.appstream.fireclient.FireClientActivity.java

@Override
public void onDialogConnectClick(String address, String appid, String userid, boolean hardwareEnabled) {

    Resources r = getResources();

    if (hardwareEnabled) {
        attemptEnableHardwareDecode();//  w  ww. j ava2s.co m
    } else {
        disableHardwareDecode();
    }

    mStopped = false;

    if (address == null) {
        openConnectDialog(r.getString(R.string.invalid_address));
    } else if (appid == null) {
        if (!address.matches("\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}")) {
            openConnectDialog(r.getString(R.string.invalid_address));
            return;
        }

        mServerAddress = address;
        mUseAppServer = true;

        String url = String.format(Locale.US, "ssm://%s:%d?sessionId=%s", address, 80, "9070-0");
        AppStreamInterface.connect(url);
        AppStreamInterface.newFrame();

        savePrefs();
        return;
    } else if (address != null && address.matches(
            "^(http[s]?://)?([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}(:[0-9]+)?(/.*)?$")
            || address.matches("^(http[s]?://)?\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}(:[0-9]+)?(/.*)?$")) {
        if (userid == null || (userid.isEmpty())) {
            openConnectDialog(r.getString(R.string.user_id_required));
            return;
        } else if (appid.isEmpty()) {
            openConnectDialog(r.getString(R.string.app_id_required));
            return;
        }
        mUseAppServer = false;
        mDESServerAddress = address;
        mAppId = appid;
        mUserId = userid;
        savePrefs();

        // we've received an entitlement server + path
        mDesQuery.setActivity(this);
        mDesQuery.setListener(this);
        mDesQuery.makeQuery(address, appid, userid);
    } else {
        openConnectDialog(r.getString(R.string.invalid_address));
    }
}