$(function(){
startTimer();
});
function startTimer()
{
document.cookie = 'timer='+60; //Cookie
if(document.cookie.replace(/(?:(?:^|.*;\s*)timer\s*\=\s*([^;]*).*$)|^.*$/, "$1") !== "") //The way to read cookie in javascript
{
var duration = document.cookie.replace(/(?:(?:^|.*;\s*)timer\s*\=\s*([^;]*).*$)|^.*$/, "$1");
var timer = duration, minutes, seconds, hours;
var t = setInterval(function ()
{
hours = parseInt(timer /(60*60),10);
minutes = parseInt((timer / 60) - (hours*60), 10);
seconds = parseInt(timer % 60, 10);
hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
$('.hours').html(hours);
$('.minutes').html(minutes);
$('.seconds').html(seconds);
--timer;
document.cookie = 'timer='+timer;
if(timer < 0)
{
clearInterval(t);
}
}, 1000);
}
}
Sunday, January 24, 2016
Set Timer on Cookie
Wednesday, January 20, 2016
Language Key Generator (Codeigniter)
$str = 'Saya makan nasi ayam bala bala balalalalal';
echo underscore(character_limiter($str,30,'...'));
function character_limiter($str, $n = 500, $end_char = '…')
{
if (strlen($str) < $n)
{
return $str;
}
$str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
if (strlen($str) <= $n)
{
return $str;
}
$out = "";
foreach (explode(' ', trim($str)) as $val)
{
$out .= $val.' ';
if (strlen($out) >= $n)
{
$out = trim($out);
return (strlen($out) == strlen($str)) ? $out : $out.$end_char;
}
}
}
function underscore($str)
{
return preg_replace('/[\s]+/', '.', strtolower(trim($str)));
}
echo underscore(character_limiter($str,30,'...'));
function character_limiter($str, $n = 500, $end_char = '…')
{
if (strlen($str) < $n)
{
return $str;
}
$str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
if (strlen($str) <= $n)
{
return $str;
}
$out = "";
foreach (explode(' ', trim($str)) as $val)
{
$out .= $val.' ';
if (strlen($out) >= $n)
{
$out = trim($out);
return (strlen($out) == strlen($str)) ? $out : $out.$end_char;
}
}
}
function underscore($str)
{
return preg_replace('/[\s]+/', '.', strtolower(trim($str)));
}
Sunday, January 10, 2016
Bootstrap Button Generator
http://blog.koalite.com/bbg/
Saturday, January 9, 2016
How to get my own GPS location in android?
http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/
Video Part 1
https://youtu.be/c_8hyYQdcj4
Video Part 2
https://youtu.be/c_8hyYQdcj4
Video Part 1
https://youtu.be/c_8hyYQdcj4
Video Part 2
https://youtu.be/c_8hyYQdcj4
How To Vibrate The Android Phone
In this tutorial we learn How to Vibrate a phone in default manner or in the pattern you want.
What we learn:
Service
Vibrating the Phone
Requires Knowledge:
Basic Android
To vibrate a phone we need following Permission Do not forget to declare this permission in Manifest.
<uses-permission android:name="android.permission.VIBRATE"/>
We can Vibrate a Phone Using an Activity , Service and Using Threads.
Using Activity will not be a good Idea because it takes time to vibrate the Phone and an Activity always runs in foreground.
We will implement using Service because a Service runs in Background.
for we need to have an Object of Class Vibrator, we do not create the Object directly but we get Vibrate System Service.
Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
Add <uses-permission android:name="android.permission.VIBRATE"/> in Your Manifest
So let's start.
Create a new Android Project "Vibrate Phone".
and edit the manifest and main.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidjuncture.vibrate"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".VibrateMainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Declare the Vibrate Service -->
<service android:name=".VibrateService"/>
</application>
</manifest>
(to be inflated/used in VibrateMainActivity)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#99C2D6"
android:orientation="vertical">
<TextView
android:layout_marginTop="140dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Android Vibrate Service Example" />
<Button
android:id="@+id/buttonVibrate"
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Vibrate" />
</LinearLayout>
When User clicks on Vibrate Button we will start a new Service which will vibrate the phone.
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnVibrate=(Button)findViewById(R.id.buttonVibrate);
// Set on click listener and start vibrate service when clicked on Button Vibrate
btnVibrate.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
// Create a New Intent and start the service
Intent intentVibrate =new Intent(getApplicationContext(),VibrateService.class);
startService(intentVibrate);
}
});
}
}
<service android:name=".VibrateService"/>
public class VibrateService extends Service
{
@Override
public void onStart(Intent intent, int startId)
{
// TODO Auto-generated method stub
super.onStart(intent, startId);
Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
// pass the number of millseconds fro which you want to vibrate the phone here we
// have passed 2000 so phone will vibrate for 2 seconds.
v.vibrate(2000);
// If you want to vibrate in a pattern
// long pattern[]={0,800,200,1200,300,2000,400,4000};
// 2nd argument is for repetition pass -1 if you do not want to repeat the Vibrate
// v.vibrate(pattern,-1);
Toast.makeText(getApplicationContext(), "Phone is Vibrating", Toast.LENGTH_LONG).show();
}
@Override
public IBinder onBind(Intent intent)
{
// TODO Auto-generated method stub
return null;
}
}
long pattern[]={0,800,200,1200,300,2000,400,4000}
this is pattern in which we want to Vibrate the Phone
first 0 means silent for 0 milisecond
800 means vibrate for 800 milisecond
200 means means silent for 200 milisecond
1200 means vibrate for 1200 miliseconds
and So On.
What we learn:
Service
Vibrating the Phone
Requires Knowledge:
Basic Android
To vibrate a phone we need following Permission Do not forget to declare this permission in Manifest.
<uses-permission android:name="android.permission.VIBRATE"/>
We can Vibrate a Phone Using an Activity , Service and Using Threads.
Using Activity will not be a good Idea because it takes time to vibrate the Phone and an Activity always runs in foreground.
We will implement using Service because a Service runs in Background.
for we need to have an Object of Class Vibrator, we do not create the Object directly but we get Vibrate System Service.
Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
Add <uses-permission android:name="android.permission.VIBRATE"/> in Your Manifest
So let's start.
Create a new Android Project "Vibrate Phone".
and edit the manifest and main.xml file
manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidjuncture.vibrate"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".VibrateMainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Declare the Vibrate Service -->
<service android:name=".VibrateService"/>
</application>
</manifest>
main.xml
(to be inflated/used in VibrateMainActivity)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#99C2D6"
android:orientation="vertical">
<TextView
android:layout_marginTop="140dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Android Vibrate Service Example" />
<Button
android:id="@+id/buttonVibrate"
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Vibrate" />
</LinearLayout>
When User clicks on Vibrate Button we will start a new Service which will vibrate the phone.
VibrateMainActivity .java
public class VibrateMainActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnVibrate=(Button)findViewById(R.id.buttonVibrate);
// Set on click listener and start vibrate service when clicked on Button Vibrate
btnVibrate.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
// Create a New Intent and start the service
Intent intentVibrate =new Intent(getApplicationContext(),VibrateService.class);
startService(intentVibrate);
}
});
}
}
And The Service Class
Do Not Forget To Declare the Service in Manifest like<service android:name=".VibrateService"/>
public class VibrateService extends Service
{
@Override
public void onStart(Intent intent, int startId)
{
// TODO Auto-generated method stub
super.onStart(intent, startId);
Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
// pass the number of millseconds fro which you want to vibrate the phone here we
// have passed 2000 so phone will vibrate for 2 seconds.
v.vibrate(2000);
// If you want to vibrate in a pattern
// long pattern[]={0,800,200,1200,300,2000,400,4000};
// 2nd argument is for repetition pass -1 if you do not want to repeat the Vibrate
// v.vibrate(pattern,-1);
Toast.makeText(getApplicationContext(), "Phone is Vibrating", Toast.LENGTH_LONG).show();
}
@Override
public IBinder onBind(Intent intent)
{
// TODO Auto-generated method stub
return null;
}
}
Point To Note:
long pattern[]={0,800,200,1200,300,2000,400,4000}
this is pattern in which we want to Vibrate the Phone
first 0 means silent for 0 milisecond
800 means vibrate for 800 milisecond
200 means means silent for 200 milisecond
1200 means vibrate for 1200 miliseconds
and So On.

