Mechele

Untitled

Apr 8th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. package com.taxipixi.taxiexchange.widgets;
  2.  
  3. /**
  4. * Created by Administrator on 4/4/2016.
  5. */
  6. import android.content.Context;
  7. import android.content.res.Resources;
  8. import android.graphics.Typeface;
  9. import android.util.AttributeSet;
  10. import android.util.Log;
  11. import android.view.View;
  12. import android.widget.NumberPicker;
  13. import android.widget.TextView;
  14. import android.widget.TimePicker;
  15.  
  16. import com.taxipixi.taxiexchange.R;
  17.  
  18. import java.lang.reflect.Field;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21.  
  22. /**
  23. * Created by Administrator on 4/3/2016.
  24. */
  25. public class StyledTimePicker extends TimePicker {
  26.  
  27. public StyledTimePicker(Context context, AttributeSet attrs) {
  28. super(context, attrs);
  29.  
  30. Class<?> internalRID = null;
  31. try {
  32. internalRID = Class.forName("com.android.internal.R$id");
  33. } catch (ClassNotFoundException e) {
  34. e.printStackTrace();
  35. }
  36.  
  37. Field month = null;
  38. try {
  39. month = internalRID.getField("hour");
  40. } catch (NoSuchFieldException e) {
  41. e.printStackTrace();
  42. }
  43. final Typeface fontTypeOfTime = Typeface.createFromAsset(getResources().getAssets(), "fonts/NeoSans.otf");
  44. NumberPicker npMonth = null;
  45. try {
  46. npMonth = (NumberPicker) findViewById(month.getInt(null));
  47. View child=npMonth.getChildAt(0);
  48. ((TextView) child).setTypeface(fontTypeOfTime);
  49. npMonth.invalidate();
  50. } catch (IllegalArgumentException e) {
  51. e.printStackTrace();
  52. } catch (IllegalAccessException e) {
  53. e.printStackTrace();
  54. }
  55.  
  56. Field day = null;
  57. try {
  58. day = internalRID.getField("minute");
  59. } catch (NoSuchFieldException e) {
  60. e.printStackTrace();
  61. }
  62.  
  63. NumberPicker npDay = null;
  64. try {
  65. npDay = (NumberPicker) findViewById(day.getInt(null));
  66. View child=npDay.getChildAt(0);
  67. ((TextView) child).setTypeface(fontTypeOfTime);
  68. npDay.invalidate();
  69. npDay.setMinValue(0);
  70. npDay.setMaxValue((60 / 15) - 1);
  71. List<String> displayedValues = new ArrayList<String>();
  72. for (int i = 0; i < 60; i += 15) {
  73. displayedValues.add(String.format("%02d", i));
  74. }
  75. npDay.setDisplayedValues(displayedValues
  76. .toArray(new String[0]));
  77. npDay.setWrapSelectorWheel(true);
  78. } catch (IllegalAccessException e) {
  79. e.printStackTrace();
  80. }
  81.  
  82. Field year = null;
  83. try {
  84. year = internalRID.getField("amPm");
  85. } catch (NoSuchFieldException e) {
  86. e.printStackTrace();
  87. }
  88.  
  89. NumberPicker npYear = null;
  90. try {
  91. npYear = (NumberPicker) findViewById(year.getInt(null));
  92. View child=npYear.getChildAt(0);
  93. ((TextView) child).setTypeface(fontTypeOfTime);
  94. npYear.invalidate();
  95. } catch (IllegalArgumentException e) {
  96. e.printStackTrace();
  97. } catch (IllegalAccessException e) {
  98. e.printStackTrace();
  99. }
  100.  
  101. Class<?> numberPickerClass = null;
  102. try {
  103. numberPickerClass = Class.forName("android.widget.NumberPicker");
  104. } catch (ClassNotFoundException e) {
  105. e.printStackTrace();
  106. }
  107.  
  108. Field selectionDivider = null;
  109. try {
  110. selectionDivider = numberPickerClass.getDeclaredField("mSelectionDivider");
  111. } catch (NoSuchFieldException e) {
  112. e.printStackTrace();
  113. }
  114.  
  115. try {
  116. selectionDivider.setAccessible(true);
  117. selectionDivider.set(npMonth, getResources().getDrawable(
  118. R.color.colorSelector));
  119. selectionDivider.set(npDay, getResources().getDrawable(
  120. R.color.colorSelector));
  121. selectionDivider.set(npYear, getResources().getDrawable(
  122. R.color.colorSelector));
  123. } catch (IllegalArgumentException e) {
  124. e.printStackTrace();
  125. } catch (Resources.NotFoundException e) {
  126. e.printStackTrace();
  127. } catch (IllegalAccessException e) {
  128. e.printStackTrace();
  129. }
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment