Mechele

Untitled

Apr 8th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 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. static View hoursFont;
  27. static View minutesFont;
  28. static View pmAmFont;
  29. final Typeface fontTypeOfTime;
  30. static Context context;
  31. public StyledTimePicker(Context context, AttributeSet attrs) {
  32. super(context, attrs);
  33. this.context=context;
  34. fontTypeOfTime = Typeface.createFromAsset(getResources().getAssets(), "fonts/NeoSans.otf");
  35. Class<?> internalRID = null;
  36. try {
  37. internalRID = Class.forName("com.android.internal.R$id");
  38. } catch (ClassNotFoundException e) {
  39. e.printStackTrace();
  40. }
  41.  
  42. Field month = null;
  43. try {
  44. month = internalRID.getField("hour");
  45. } catch (NoSuchFieldException e) {
  46. e.printStackTrace();
  47. }
  48.  
  49. NumberPicker npMonth = null;
  50. try {
  51. npMonth = (NumberPicker) findViewById(month.getInt(null));
  52. hoursFont=npMonth.getChildAt(0);
  53. //Field wheelpaint_field = null;//add colors
  54. //wheelpaint_field = npMonth.getClass().getDeclaredField("mSelectorWheelPaint");
  55. //wheelpaint_field.setAccessible(true);
  56. /*((Paint)wheelpaint_field.get(number_picker)).setColor(color);
  57. ((EditText)child).setTextColor(color);*/
  58. ((TextView) hoursFont).setTypeface(fontTypeOfTime);
  59. //npMonth.invalidate();
  60. } catch (IllegalArgumentException e) {
  61. e.printStackTrace();
  62. } catch (IllegalAccessException e) {
  63. e.printStackTrace();
  64. }
  65.  
  66. Field day = null;
  67. try {
  68. day = internalRID.getField("minute");
  69. } catch (NoSuchFieldException e) {
  70. e.printStackTrace();
  71. }
  72.  
  73. NumberPicker npDay = null;
  74. try {
  75. npDay = (NumberPicker) findViewById(day.getInt(null));
  76. minutesFont=npDay.getChildAt(0);
  77. ((TextView) minutesFont).setTypeface(fontTypeOfTime);
  78. //npDay.invalidate();
  79. npDay.setMinValue(0);
  80. npDay.setMaxValue((60 / 15) - 1);
  81. List<String> displayedValues = new ArrayList<String>();
  82. for (int i = 0; i < 60; i += 15) {
  83. displayedValues.add(String.format("%02d", i));
  84. }
  85. npDay.setDisplayedValues(displayedValues
  86. .toArray(new String[0]));
  87. npDay.setWrapSelectorWheel(true);
  88. } catch (IllegalAccessException e) {
  89. e.printStackTrace();
  90. }
  91.  
  92. Field year = null;
  93. try {
  94. year = internalRID.getField("amPm");
  95. } catch (NoSuchFieldException e) {
  96. e.printStackTrace();
  97. }
  98.  
  99. NumberPicker npYear = null;
  100. try {
  101. npYear = (NumberPicker) findViewById(year.getInt(null));
  102. pmAmFont=npYear.getChildAt(0);
  103. ((TextView) pmAmFont).setTypeface(fontTypeOfTime);
  104. //npYear.invalidate();
  105. } catch (IllegalArgumentException e) {
  106. e.printStackTrace();
  107. } catch (IllegalAccessException e) {
  108. e.printStackTrace();
  109. }
  110.  
  111. Class<?> numberPickerClass = null;
  112. try {
  113. numberPickerClass = Class.forName("android.widget.NumberPicker");
  114. } catch (ClassNotFoundException e) {
  115. e.printStackTrace();
  116. }
  117.  
  118. Field selectionDivider = null;
  119. try {
  120. selectionDivider = numberPickerClass.getDeclaredField("mSelectionDivider");
  121. } catch (NoSuchFieldException e) {
  122. e.printStackTrace();
  123. }
  124.  
  125. try {
  126. selectionDivider.setAccessible(true);
  127. selectionDivider.set(npMonth, getResources().getDrawable(
  128. R.color.colorSelector));
  129. selectionDivider.set(npDay, getResources().getDrawable(
  130. R.color.colorSelector));
  131. selectionDivider.set(npYear, getResources().getDrawable(
  132. R.color.colorSelector));
  133. } catch (IllegalArgumentException e) {
  134. e.printStackTrace();
  135. } catch (Resources.NotFoundException e) {
  136. e.printStackTrace();
  137. } catch (IllegalAccessException e) {
  138. e.printStackTrace();
  139. }
  140. }
  141. public static String setFont(){
  142. Typeface fontType = Typeface.createFromAsset(context.getResources().getAssets(), "fonts/NeoSans.otf");
  143. ((TextView)hoursFont).setTypeface(fontType);
  144. ((TextView)minutesFont).setTypeface(fontType);
  145. ((TextView)pmAmFont).setTypeface(fontType);
  146.  
  147. String selected=((TextView)hoursFont).getText().toString()+"/"+((TextView)minutesFont).getText().toString();
  148. return selected;
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment