Android Open Source - Smartlab Persian Date Picker






From Project

Back to project page Smartlab.

License

The source code is released under:

Apache License

If you think the Android project Smartlab listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.persiandatepicker;
//from   w w  w  .  jav a  2  s . c o  m
import java.util.Date;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.NumberPicker.OnValueChangeListener;
import android.widget.Toast;

public class PersianDatePicker extends LinearLayout {

  private NumberPicker yearNumberPicker, monthNumberPicker, dayNumberPicker;

  public PersianDatePicker(Context context, AttributeSet attrs) {
    this(context, attrs, -1);
  }

  public PersianDatePicker(Context context) {
    this(context, null, -1);
  }

  public PersianDatePicker(final Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View root = inflater.inflate(R.layout.pdp, this);
    yearNumberPicker = (NumberPicker) root
        .findViewById(R.id.yearNumberPicker);
    monthNumberPicker = (NumberPicker) root
        .findViewById(R.id.monthNumberPicker);
    dayNumberPicker = (NumberPicker) root
        .findViewById(R.id.dayNumberPicker);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersianDatePicker, 0, 0);
    int year = 1393,month=6,day=19;
    
    year = a.getInteger(R.styleable.PersianDatePicker_year, 1393);
    month = a.getInteger(R.styleable.PersianDatePicker_month, 6);
    day = a.getInteger(R.styleable.PersianDatePicker_day, 19);
    
    a.recycle();

    yearNumberPicker.setMinValue(1380);
    yearNumberPicker.setMaxValue(1400);
    yearNumberPicker.setValue(year);

    monthNumberPicker.setMinValue(1);
    monthNumberPicker.setMaxValue(12);
    monthNumberPicker.setValue(month);

    dayNumberPicker.setMaxValue(31);
    dayNumberPicker.setMinValue(1);
    dayNumberPicker.setValue(day);
    
    yearNumberPicker.setOnValueChangedListener(new OnValueChangeListener() {
      
      @Override
      public void onValueChange(NumberPicker np, int oldValue, int newValue) {
        Toast.makeText(context, "Year changed:" + oldValue + " -> " + newValue, Toast.LENGTH_LONG).show();
      }
    });
  }

  public Date getSelectedDate() {
    return null;
  }

  public void setSelectedDate(Date date) {

  }

}




Java Source Code List

com.example.activitylifecycletest.MainActivity.java
com.example.activitylifecycletest.SecondActivity.java
com.example.analyticstest.MainActivity.java
com.example.androidgraphic.MainActivity.java
com.example.animationexample.MainActivity.java
com.example.animationexample.SecondActivity.java
com.example.compassview.CompassView.java
com.example.compassview.MainActivity.java
com.example.databasetest.BookListActivity.java
com.example.databasetest.MainActivity.java
com.example.databasetest.data.Book.java
com.example.databasetest.data.DatabaseAdapter.java
com.example.fragmentexample.BookDetailsFragment.java
com.example.fragmentexample.BookListFragment.java
com.example.fragmentexample.MainActivity.java
com.example.fragmentexample.data.BookListAdapter.java
com.example.fragmentexample.data.Book.java
com.example.fragmentexample.data.DatabaseAdapter.java
com.example.listviewexample.MainActivity.java
com.example.listviewexample.data.BookListAdapter.java
com.example.listviewexample.data.Book.java
com.example.listviewexample.data.DatabaseAdapter.java
com.example.persiandatepicker.MainActivity.java
com.example.persiandatepicker.PersianDatePicker.java
com.example.preferencesexample.MainActivity.java
com.example.sqlitetestapp.MainActivity.java
com.example.sqlitetestapp.PersonListActivity.java
com.example.sqlitetestapp.data.DatabaseAdapter.java
com.example.sqlitetestapp.data.PersonListAdapter.java
com.example.sqlitetestapp.data.model.Person.java
com.example.viewpagerexample.MainActivity.java
ir.smartlab.android.broadcast.MainActivity.java
ir.smartlab.android.broadcast.WifiStateChangeReceiver.java
ir.smartlab.android.downloadasynctask.MainActivity.java
ir.smartlab.android.helloworld.MainActivity.java
ir.smartlab.audiorecord.MainActivity.java
ir.smartlab.audiotest.MainActivity.java
ir.smartlab.camera.MainActivity.java
ir.smartlab.captureimage.MainActivity.java
ir.smartlab.customaudiorecorder.MainActivity.java
ir.smartlab.java.ch04.firstcup.FisrtCup.java
ir.smartlab.java.ch05.circlesample.Circle.java
ir.smartlab.java.ch05.circlesample.Main.java
ir.smartlab.java.ch06.simplecalculator.SimpleCalculator.java
ir.smartlab.java.ch06.variablescope.VariableScopeTest.java
ir.smartlab.java.persiancalendar.Main.java
ir.smartlab.musicplayer.MainActivity.java
ir.smartlab.musicplayerservice.MainActivity.java
ir.smartlab.musicplayerservice.PlayerService.java
ir.smartlab.personlist.MainActivity.java
ir.smartlab.personlist.PersonListActivity.java
ir.smartlab.personlist.data.DatabaseAdapter.java
ir.smartlab.personlist.data.PersonListAdapter.java
ir.smartlab.personlist.data.Person.java