Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.taxipixi.taxiexchange.widgets;
- /**
- * Created by Administrator on 4/4/2016.
- */
- import android.content.Context;
- import android.content.res.Resources;
- import android.graphics.Typeface;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.View;
- import android.widget.NumberPicker;
- import android.widget.TextView;
- import android.widget.TimePicker;
- import com.taxipixi.taxiexchange.R;
- import java.lang.reflect.Field;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by Administrator on 4/3/2016.
- */
- public class StyledTimePicker extends TimePicker {
- static View hoursFont;
- static View minutesFont;
- static View pmAmFont;
- final Typeface fontTypeOfTime;
- static Context context;
- public StyledTimePicker(Context context, AttributeSet attrs) {
- super(context, attrs);
- this.context=context;
- fontTypeOfTime = Typeface.createFromAsset(getResources().getAssets(), "fonts/NeoSans.otf");
- Class<?> internalRID = null;
- try {
- internalRID = Class.forName("com.android.internal.R$id");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- Field month = null;
- try {
- month = internalRID.getField("hour");
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- NumberPicker npMonth = null;
- try {
- npMonth = (NumberPicker) findViewById(month.getInt(null));
- hoursFont=npMonth.getChildAt(0);
- //Field wheelpaint_field = null;//add colors
- //wheelpaint_field = npMonth.getClass().getDeclaredField("mSelectorWheelPaint");
- //wheelpaint_field.setAccessible(true);
- /*((Paint)wheelpaint_field.get(number_picker)).setColor(color);
- ((EditText)child).setTextColor(color);*/
- ((TextView) hoursFont).setTypeface(fontTypeOfTime);
- //npMonth.invalidate();
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- Field day = null;
- try {
- day = internalRID.getField("minute");
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- NumberPicker npDay = null;
- try {
- npDay = (NumberPicker) findViewById(day.getInt(null));
- minutesFont=npDay.getChildAt(0);
- ((TextView) minutesFont).setTypeface(fontTypeOfTime);
- //npDay.invalidate();
- npDay.setMinValue(0);
- npDay.setMaxValue((60 / 15) - 1);
- List<String> displayedValues = new ArrayList<String>();
- for (int i = 0; i < 60; i += 15) {
- displayedValues.add(String.format("%02d", i));
- }
- npDay.setDisplayedValues(displayedValues
- .toArray(new String[0]));
- npDay.setWrapSelectorWheel(true);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- Field year = null;
- try {
- year = internalRID.getField("amPm");
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- NumberPicker npYear = null;
- try {
- npYear = (NumberPicker) findViewById(year.getInt(null));
- pmAmFont=npYear.getChildAt(0);
- ((TextView) pmAmFont).setTypeface(fontTypeOfTime);
- //npYear.invalidate();
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- Class<?> numberPickerClass = null;
- try {
- numberPickerClass = Class.forName("android.widget.NumberPicker");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- Field selectionDivider = null;
- try {
- selectionDivider = numberPickerClass.getDeclaredField("mSelectionDivider");
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- try {
- selectionDivider.setAccessible(true);
- selectionDivider.set(npMonth, getResources().getDrawable(
- R.color.colorSelector));
- selectionDivider.set(npDay, getResources().getDrawable(
- R.color.colorSelector));
- selectionDivider.set(npYear, getResources().getDrawable(
- R.color.colorSelector));
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (Resources.NotFoundException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- public static String setFont(){
- Typeface fontType = Typeface.createFromAsset(context.getResources().getAssets(), "fonts/NeoSans.otf");
- ((TextView)hoursFont).setTypeface(fontType);
- ((TextView)minutesFont).setTypeface(fontType);
- ((TextView)pmAmFont).setTypeface(fontType);
- String selected=((TextView)hoursFont).getText().toString()+"/"+((TextView)minutesFont).getText().toString();
- return selected;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment