Skip to content

Commit 945a220

Browse files
ldjcmudsn5ft
authored andcommitted
Include separator characters for Samsung devices in MaterialDatePicker
Resolves #682 PiperOrigin-RevId: 279146671 (cherry picked from commit 62a2164)
1 parent cc1cfd7 commit 945a220

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

lib/java/com/google/android/material/datepicker/RangeDateSelector.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
import androidx.annotation.RestrictTo.Scope;
2929
import androidx.core.util.Pair;
3030
import androidx.core.util.Preconditions;
31+
import android.text.InputType;
3132
import android.util.DisplayMetrics;
3233
import android.view.LayoutInflater;
3334
import android.view.View;
3435
import android.view.ViewGroup;
3536
import android.widget.EditText;
37+
import com.google.android.material.internal.ManufacturerUtils;
3638
import com.google.android.material.internal.ViewUtils;
3739
import com.google.android.material.resources.MaterialAttributes;
3840
import com.google.android.material.textfield.TextInputLayout;
@@ -178,6 +180,12 @@ public View onCreateTextInputView(
178180
final TextInputLayout endTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_end);
179181
EditText startEditText = startTextInput.getEditText();
180182
EditText endEditText = endTextInput.getEditText();
183+
// The date inputType for Samsung does not include any separator characters
184+
if (ManufacturerUtils.isSamsungDevice()) {
185+
// Using the URI variation places the '/' and '.' in more prominent positions
186+
startEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
187+
endEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
188+
}
181189

182190
invalidRangeStartError = root.getResources().getString(R.string.mtrl_picker_invalid_range);
183191

lib/java/com/google/android/material/datepicker/SingleDateSelector.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
import androidx.annotation.RestrictTo;
2828
import androidx.annotation.RestrictTo.Scope;
2929
import androidx.core.util.Pair;
30+
import android.text.InputType;
3031
import android.view.LayoutInflater;
3132
import android.view.View;
3233
import android.view.ViewGroup;
3334
import android.widget.EditText;
35+
import com.google.android.material.internal.ManufacturerUtils;
3436
import com.google.android.material.internal.ViewUtils;
3537
import com.google.android.material.resources.MaterialAttributes;
3638
import com.google.android.material.textfield.TextInputLayout;
@@ -100,6 +102,11 @@ public View onCreateTextInputView(
100102

101103
TextInputLayout dateTextInput = root.findViewById(R.id.mtrl_picker_text_input_date);
102104
EditText dateEditText = dateTextInput.getEditText();
105+
// The date inputType for Samsung does not include any separator characters
106+
if (ManufacturerUtils.isSamsungDevice()) {
107+
// Using the URI variation places the '/' and '.' in more prominent positions
108+
dateEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
109+
}
103110
SimpleDateFormat format = UtcDates.getTextInputFormat();
104111
String formatHint = UtcDates.getTextInputHint(root.getResources(), format);
105112

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.android.material.internal;
17+
18+
import com.google.android.material.R;
19+
20+
import android.os.Build;
21+
import androidx.annotation.RestrictTo;
22+
import androidx.annotation.RestrictTo.Scope;
23+
24+
/** Utils to determine device manufacturers for special handling. */
25+
@RestrictTo(Scope.LIBRARY_GROUP)
26+
public class ManufacturerUtils {
27+
28+
private ManufacturerUtils() {}
29+
30+
/** Returns true if the device manufacturer is Samsung. */
31+
public static boolean isSamsungDevice() {
32+
return Build.MANUFACTURER.equalsIgnoreCase("samsung");
33+
}
34+
}

0 commit comments

Comments
 (0)