Skip to content

Commit

Permalink
appcompat-v7:27.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamadian committed Nov 11, 2017
0 parents commit 241aef8
Show file tree
Hide file tree
Showing 53 changed files with 3,004 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# PersianJodaTime
JodaTime with Persian/Solar calendar

## Usage

### Download

1) Add JitPack repository in your root `build.gradle` at the end of `repositories` :

```java

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

```

2) Add dependency to your root `build.gradle` :

```java
dependencies {
...
compile 'com.github.mohamadian:PersianJodaTime:1.2'
}
```

### Call JodaTimeAndroid.init()
You must initialize the library before using it by calling `JodaTimeAndroid.init()`. I suggest putting this code in `Application.onCreate()` :

```java
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
JodaTimeAndroid.init(this);
}
}
```

and use `MyApplication` class in `AndroidManifest.xml` like this:
```java
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mohamadian.testapp">

<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
```

### How to create Persian DateTime and how to use it
Ok, just create a `PersianChronology` object and pass it to `DateTime` class, all done:

```java

PersianChronology perChr = PersianChronologyKhayyam.getInstance(DateTimeZone.forID("Asia/Tehran"));
DateTime now = new DateTime(perChr);

DateTime dt = new DateTime(1396, 8, 2, 0, 0, perChr);
```

### Credits
This libary is based on [joda-time](https://github.com/JodaOrg/joda-time) and [zubinkavarana/joda-time](https://github.com/zubinkavarana/joda-time).

### Thanks
Special thanks to [zubinkavarana](https://github.com/zubinkavarana).
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
29 changes: 29 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mohamadian.persianjodatimeexample"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
compile project(path: ':persianjodatime')
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mohamadian.persianjodatimeexample;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.mohamadian.persianjodatimeexample", appContext.getPackageName());
}
}
22 changes: 22 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mohamadian.persianjodatimeexample">

<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.mohamadian.persianjodatimeexample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.chrono.PersianChronology;
import org.joda.time.chrono.PersianChronologyKhayyam;

public class MainActivity extends AppCompatActivity {
private TextView textView;
private PersianChronology perChr;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

perChr = PersianChronologyKhayyam.getInstance(DateTimeZone.forID("Asia/Tehran"));
DateTime now = new DateTime(perChr);

textView = (TextView) findViewById(R.id.text_view);
textView.setText("Today is : "+ Integer.toString(now.getYear())+"/"+ Integer.toString(now.getMonthOfYear())+"/"+ Integer.toString(now.getDayOfMonth()));

findViewById(R.id.next_month).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DateTime dt = new DateTime(perChr).plusMonths(1);
textView.setText("Next month : "+ Integer.toString(dt.getYear())+"/"+ Integer.toString(dt.getMonthOfYear())+"/"+ Integer.toString(dt.getDayOfMonth()));
}
});

findViewById(R.id.specific_date).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DateTime dt = new DateTime(1398, 12, 25, 0, 0, perChr);
textView.setText("Specific date : "+ Integer.toString(dt.getYear())+"/"+ Integer.toString(dt.getMonthOfYear())+"/"+ Integer.toString(dt.getDayOfMonth()));
}
});
}
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/mohamadian/persianjodatimeexample/MyApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mohamadian.persianjodatimeexample;

import android.app.Application;
import android.content.Context;

import net.danlew.android.joda.JodaTimeAndroid;

/**
* Created by Tasnim on 10/29/2017.
*/

public class MyApp extends Application {
private static Context mContext;

@Override
public void onCreate() {
super.onCreate();
JodaTimeAndroid.init(this);
mContext = getApplicationContext();
}

public static Context getContext() {
return mContext;
}
}
Loading

0 comments on commit 241aef8

Please sign in to comment.