Saturday, 26 March 2016

How to convert UTC time stamp to PST time.

Here I am going to write how to convert UTC time zone to PST time zone.

private void convertUtcTimeToPstTimeZone() {
        String utcTime = "2016-08-14T22:56:02.038Z";
        SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
        utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            Date date = utcFormat.parse(utcTime);
            DateFormat pstFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.getDefault());
            pstFormat.setTimeZone(TimeZone.getTimeZone("PST"));
            System.out.println(pstFormat.format(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

Result is: 14-08-2016 22:56:02

How to install google play services on Genymotion and Android Studio Plugin

Genymotion emulator provides Google services easily like GCM push notification and Google maps etc.
Follow the below steps easily you can make available Google services on Genymotion with the help of CyanogenMod's gapps. In genymotion there are so many features available you can use easily like GPS sensor , camera and Gyroscope etc..
For more information follow Genymotion details.


InstallationGenymotion operation depends upon use of Oracle VM Virtual Box in the background.
To install Genymotion, follow the steps corresponding to your operating system.


To download Genymotion for Windows:


1. Go to the Genymotion download page.
2. Save and run the .exe file.
3. Click Install and Finish.
4. Start Genymotion now you will be able to see below screen.


5. Click + Add button now you will be able to see this screen and select virtual devices tap on Next Button.

6. Retrieve and Deploy the new virtual devices.

7. Select downloaded device and tap on start button now you will be able to see Genymotion Emulator.

8. To install download Genymotion-ARM-Translation_v1.1zip and then drag and drop the downloaded file to opened Genymotion virtual device. When installation is done then you will be able to see confirmation dialog like given below. Click on OK button.

Then again you will see dialog File installation result is done.

9. You need to reboot the virtual device using below command.

adb reboot

10. Now Install gapps. Here most of gapps link given below according to your device android version you can download it.

Android 5.0.x
Android 4.4.x
Android 4.3.x
Android 4.2.x

Drag and drop the downloaded file to a virtual device and wait till installation process.

Reboot device once again with the same command. Once device is booted up you will be able to see all the Google play services available in your virtual device.
Now you will be able to run all the application to Genymotion virtual device which is using google services.


Install Genymotion Plugin:

1. Open Android Studio.
2. Go to File => Setting=> Plugin
3. Search Genymotion if not found click on Search repository.
4. Tap on Install Button and Restart Android Studio.

5. Now you will be able to see Genymotion icon in android studio.

6. You can open Genymotion directly from android studio.


if any thing you find gap please mark me correct.

Thanks,



Tuesday, 22 March 2016

How to design EditText Border


A EditText is an overlay over TextView that configures itself to be editable. It is the predefined subclass of TextView that includes rich editing capabilities.




MainActivity.java

package com.test.border;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:orientation="vertical"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.test.border.MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:background="@drawable/first_name_edit_text_border"
        android:hint="@string/fName"
        android:gravity="center_vertical"
        android:paddingLeft="10dp"
        android:layout_height="40dp" />


    <EditText
    android:layout_width="match_parent"
    android:background="@drawable/last_name_edit_text_border"
    android:hint="@string/lName"
    android:gravity="center_vertical"
    android:layout_marginTop="10dp"
    android:paddingLeft="10dp"
    android:layout_height="40dp" />

    <EditText
        android:layout_width="match_parent"
        android:background="@drawable/age_edit_text_border"
        android:hint="@string/age"
        android:gravity="center_vertical"
        android:layout_marginTop="10dp"
        android:paddingLeft="10dp"
        android:layout_height="40dp" />

    <EditText
        android:layout_width="match_parent"
        android:hint="@string/without_border"
        android:gravity="center_vertical"
        android:layout_marginTop="10dp"
        android:paddingLeft="10dp"
        android:layout_height="40dp" />

</LinearLayout>

Create selector xml file and keep inside drawable directory which will show you as a border of the edittext. Use below xml file as a background of the edittext.

first_name_edit_text_border.xml

First Name EditText Border result given below.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#fffae5"/>
            <stroke
                android:color="@color/colorAccent"
                android:width="1dp"
                />
            <corners android:radius="7dp"/>
        </shape>
    </item>
</selector>


last_name_edit_text_border.xml

Last Name EditText Border result given below.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">

            <solid android:color="@color/last_name_background_white" />
            <stroke android:width="2dp" android:color="@color/colorAccent" />
            <corners android:radius="7dp" />
        </shape>
    </item>
</selector>


age_edit_text_border.xml

Age EditText Border result given below.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">

            <solid android:color="@color/age_edit_text_background_color" />
            <stroke android:width="2dp" android:color="@color/age_border_color" />
            <corners android:radius="0dp" />
        </shape>
    </item>
</selector>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="age_border_color">#FF00FF</color>
    <color name="last_name_background_white">#FFFFFF</color>
    <color name="age_edit_text_background_color">#ffffffff</color>
</resources>

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Please comment in case of any issues.