Mechele

Untitled

Apr 9th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. package com.taxipixi.taxiexchange.widgets.timepicker;
  2.  
  3. import android.content.Context;
  4. import android.content.res.Resources;
  5. import android.graphics.Color;
  6. import android.graphics.Typeface;
  7. import android.util.AttributeSet;
  8. import android.view.View;
  9. import android.widget.EditText;
  10. import android.widget.NumberPicker;
  11.  
  12. import com.taxipixi.taxiexchange.R;
  13.  
  14. import java.lang.reflect.Field;
  15.  
  16. /**
  17. * Created by Administrator on 4/9/2016.
  18. */
  19. public class HourNumberPicker extends NumberPicker {
  20. Typeface type;
  21. public HourNumberPicker(Context context, AttributeSet attrs) {
  22. super(context, attrs);
  23. processAttributeSet(attrs);
  24. Class<?> numberPickerClass = null;
  25. try {
  26. numberPickerClass = Class.forName("android.widget.NumberPicker");
  27. } catch (ClassNotFoundException e) {
  28. e.printStackTrace();
  29. }
  30.  
  31. Field selectionDivider = null;
  32. try {
  33. selectionDivider = numberPickerClass.getDeclaredField("mSelectionDivider");
  34. } catch (NoSuchFieldException e) {
  35. e.printStackTrace();
  36. }
  37.  
  38. try {
  39. selectionDivider.setAccessible(true);
  40. selectionDivider.set(this, getResources().getDrawable(R.color.colorSelector));
  41. } catch (IllegalArgumentException e) {
  42. e.printStackTrace();
  43. } catch (Resources.NotFoundException e) {
  44. e.printStackTrace();
  45. } catch (IllegalAccessException e) {
  46. e.printStackTrace();
  47. }
  48. }
  49. private void processAttributeSet(AttributeSet attrs) {
  50. //This method reads the parameters given in the xml file and sets the properties according to it
  51. this.setMinValue(attrs.getAttributeIntValue(null, "min", 0));
  52. this.setMaxValue(attrs.getAttributeIntValue(null, "max", 0));
  53. }
  54. @Override
  55. public void addView(View child) {
  56. super.addView(child);
  57. updateView(child);
  58. }
  59.  
  60. @Override
  61. public void addView(View child, int index,
  62. android.view.ViewGroup.LayoutParams params) {
  63. super.addView(child, index, params);
  64. type = Typeface.createFromAsset(getContext().getAssets(),
  65. "fonts/NeoSansCyr-Light.ttf");
  66. updateView(child);
  67. }
  68.  
  69. @Override
  70. public void addView(View child, android.view.ViewGroup.LayoutParams params) {
  71. super.addView(child, params);
  72.  
  73. type = Typeface.createFromAsset(getContext().getAssets(),
  74. "fonts/NeoSansCyr-Light.ttf");
  75. updateView(child);
  76. }
  77.  
  78. private void updateView(View view) {
  79.  
  80. if (view instanceof EditText) {
  81. ((EditText) view).setTypeface(type);
  82. ((EditText) view).setTextSize(30);
  83. //((EditText) view).setTextColor(getResources().getColor(R.color.colorPrimary));
  84. ((EditText) view).setTextColor(Color.BLACK);
  85. ((EditText) view).setFocusable(false);
  86. }
  87.  
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment