Showing posts with label API. Show all posts
Showing posts with label API. Show all posts

Tuesday, 17 January 2023

How to Integrate ChatGPT In Android With TTS (Text-To-Speech).

AI (Artificial Intelligence) Technology has been progressing towards futuristic ideas on daily basis. OpenAI coming up with their R&D as ChatGPT is prominent development in this field. ChatGPT (Generative Pre-trained Transformer) is a chatbot launched by OpenAI in November 2022. It is built on top of OpenAI's GPT-3 family of large language models, and is fine-tuned with both supervised and reinforcement learning techniques.

Methods-
ChatGPT trained this model using Reinforcement Learning from Human Feedback (RLHF), using the same methods as InstructGPT, but with slight differences in the data collection setup. They trained an initial model using supervised fine-tuning: human AI trainers provided conversations in which they played both sides—the user and an AI assistant. Then provide the trainers access to model-written suggestions to help them compose their responses. They mixed this new dialogue dataset with the InstructGPT dataset, which are transformed into a dialogue format.


ChatGPT is fine-tuned from a model in the GPT-3.5 series, which finished training in early 2022. You can learn more about the 3.5 series here. ChatGPT and GPT 3.5 were trained on an Azure AI supercomputing infrastructure.

We as technophiles strongly believe in ‘Sharing Is Caring’. We have create a sample demo where we will integrate ChatGPT in Android to demonstrate how it works with TTS (Text-To-Speech).


Here, we have asked for food recipe via ChatGPT bot which is read by TTS bot. We can also create a recipe from a list of ingredients. There are unlimited use-cases and ideas that are possible to explore and make life easy and technological advance.

Refer the below link for complete sample code:-

Download Sample Code

Have a look on few code snippets,

//MainActivity.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.elitetechnority.chatgptdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.StrictMode;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.theokanning.openai.OpenAiService;
import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.completion.CompletionResult;

import java.util.Locale;

public class MainActivity extends AppCompatActivity {

    private TextToSpeech textToSpeech;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        OpenAiService service = new OpenAiService("Your Token");
        TextView tv_bot=(TextView)findViewById(R.id.tv_bot);
        EditText et_bot=(EditText)findViewById(R.id.et_bot);
        et_bot.setText("Tell about ChatGPT");
        Button btn_bot=(Button)findViewById(R.id.btn_bot);
        btn_bot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CompletionRequest completionRequest = CompletionRequest.builder()
                        .prompt(et_bot.getText().toString())
                        .model("text-davinci-003")
                        .topP(1.0)
                        .temperature(0.3)
                        .maxTokens(150)
                        .frequencyPenalty(0.0)
                        .presencePenalty(0.0)
                        .build();
                CompletionResult completionResult=service.createCompletion(completionRequest);
                System.out.println(completionResult);
                tv_bot.setText(completionResult.getChoices().get(0).getText());
                String toSpeak = tv_bot.getText().toString();
                textToSpeech.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
            }
        });

         textToSpeech=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if(status != TextToSpeech.ERROR) {
                    textToSpeech.setLanguage(Locale.UK);
                }
            }
        });
    }

    @Override
    protected void onPause() {
        if(textToSpeech !=null){
            textToSpeech.stop();
            textToSpeech.shutdown();
        }
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        if(textToSpeech !=null){
            textToSpeech.stop();
            textToSpeech.shutdown();
        }
        super.onDestroy();
    }
}

Tuesday, 14 May 2019

HB Blog 167: How To Integrate Google Pay Payment Gateway In Android.

Google Pay  is a digital wallet platform and online payment system developed by Google to power in-app and tap-to-pay purchases on mobile devices, enabling users to make payments with Android phones, tablets or watches.

Google Pay uses Near Field Communication (NFC) to transmit card information facilitating funds transfer to the retailer. It replaces the credit or debit card chip and PIN or magnetic stripe transaction at point-of-sale terminals by allowing the user to upload these in the Google Pay wallet. It is similar to contactless payments already used in many countries, with the addition of two-factor authentication. The service lets Android devices wirelessly communicate with point of sale systems using a near field communication (NFC) antenna, host-based card emulation (HCE), and Android's security.

Google Pay takes advantage of physical authentications such as fingerprint ID where available. On devices without fingerprint ID, Google Pay is activated with a passcode. When the user makes a payment to a merchant, Google Pay does not send the credit or debit card number with the payment. Instead it generates a virtual account number representing the user's account information. This service keeps customer payment information private, sending a one-time security code instead of the card or user details.


Refer the below link for complete sample code:-

Download Sample Code

Have a look on few code snippets,

//build.gradle
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.elitetechnologies.googlepay"
        minSdkVersion 20
        targetSdkVersion 28
        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:28.0.0'
    implementation 'com.razorpay:checkout:1.5.1'
}

//activity_main.xml
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00b1e1"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:orientation="vertical"
        android:gravity="center"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="110dp"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:layout_alignParentBottom="true"
                android:background="#E2E2E2"
                android:gravity="center"
                >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingTop="35dp"
                    android:paddingBottom="0dp"
                    android:textSize="12sp"
                    android:text="Order #RZP42"
                    />

            </LinearLayout>

            <ImageView
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_centerHorizontal="true"
                android:background="#FFFFFF"
                android:src="@mipmap/ic_launcher"
                />

        </RelativeLayout>

        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:paddingTop="15dp"
            android:background="#f2f2f2"
            android:gravity="center"
            >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:paddingTop="0dp"
                android:paddingBottom="5dp"
                android:textSize="20sp"
                android:text="Razorpay T-Shirt"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:paddingTop="0dp"
                android:paddingBottom="0dp"
                android:textSize="12sp"
                android:text="INR 1.00"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:paddingTop="5dp"
                android:paddingBottom="0dp"
                android:textSize="12sp"
                android:textStyle="italic"
                android:text="This is a real transaction"
                />

            <Button
                android:id="@+id/btn_pay"
                android:layout_width="wrap_content"
                android:layout_height="36dp"
                android:layout_marginTop="20dp"
                android:layout_marginBottom="20dp"
                android:layout_gravity="center_horizontal"
                android:paddingRight="20dp"
                android:paddingLeft="20dp"
                android:background="@drawable/green_button"
                android:textSize="14sp"
                android:textColor="#fcfcfc"
                android:text="Purchase"
                />

        </LinearLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:background="@drawable/secured_by_bg"
            android:textSize="12sp"
            android:textColor="#a1ddee"
            android:textStyle="italic"
            android:text="Secure Payments by Razorpay"
            />

    </LinearLayout>

</RelativeLayout>

//MainActivity.java
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
package com.elitetechnologies.googlepay;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.razorpay.Checkout;
import com.razorpay.PaymentResultListener;

import org.json.JSONObject;

public class MainActivity extends Activity implements PaymentResultListener {
    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        /*
         To ensure faster loading of the Checkout form,
          call this method as early as possible in your checkout flow.
         */
        Checkout.preload(getApplicationContext());

        // Payment button created by you in XML layout
        Button button = (Button) findViewById(R.id.btn_pay);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startPayment();
            }
        });
    }

    public void startPayment() {
        /*
          You need to pass current activity in order to let Razorpay create CheckoutActivity
         */
        final Activity activity = this;

        final Checkout co = new Checkout();

        try {
            JSONObject options = new JSONObject();
            options.put("name", "Razorpay Corp");
            options.put("description", "Demoing Charges");
            //You can omit the image option to fetch the image from dashboard
            options.put("image", "https://s3.amazonaws.com/rzp-mobile/images/rzp.png");
            options.put("currency", "INR");
            options.put("amount", "100");

            JSONObject preFill = new JSONObject();
            preFill.put("email", "test@razorpay.com");
            preFill.put("contact", "9876543210");

            options.put("prefill", preFill);

            co.open(activity, options);
        } catch (Exception e) {
            Toast.makeText(activity, "Error in payment: " + e.getMessage(), Toast.LENGTH_SHORT)
                    .show();
            e.printStackTrace();
        }
    }

    /**
     * The name of the function has to be
     * onPaymentSuccess
     * Wrap your code in try catch, as shown, to ensure that this method runs correctly
     */
    @SuppressWarnings("unused")
    @Override
    public void onPaymentSuccess(String razorpayPaymentID) {
        try {
            Toast.makeText(this, "Payment Successful: " + razorpayPaymentID, Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Log.e(TAG, "Exception in onPaymentSuccess", e);
        }
    }

    /**
     * The name of the function has to be
     * onPaymentError
     * Wrap your code in try catch, as shown, to ensure that this method runs correctly
     */
    @SuppressWarnings("unused")
    @Override
    public void onPaymentError(int code, String response) {
        try {
            Toast.makeText(this, "Payment failed: " + code + " " + response, Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Log.e(TAG, "Exception in onPaymentError", e);
        }
    }
}

Friday, 15 December 2017

HB Blog 150: ScArcGauge View In Android.

ScArcGauge class is a specialized to create an arc gauge.
By default the arc create a closed circle: from 0° to 360°. Note that all angle is usually expressed in degrees and almost methods need to have an delta angle relative to the start angle.
This class extend the ScGauge class.
ScGauge class is studied to be an "helper class" to facilitate the user to create a gauge. The path is generic and must be defined in a inherited class. In this class are exposed many methods to drive the most used properties from the code or directly from the XML. To manage the features will recognized from the class type and its tag so changing, for example, the color of notches you will change the color of all notches tagged. This is useful when you have a custom features configuration that use one more of feature per type. All the custom features added without a defined tag should be managed by the user by himself.
Refer the below link for complete sample code:-

Download Sample Code

Have a look on few code snippets,

//build.gradle
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.harshalbenake.gaugeview"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.github.paroca72:sc-gauges:2.5.3'
}

//activity_main.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="162dp"
        android:background="#354051">

        <com.sccomponents.gauges.ScArcGauge
            android:id="@+id/gauge"
            xmlns:sc="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:padding="30dp"
            sc:scc_angle_start="-180"
            sc:scc_angle_sweep="180"
            sc:scc_progress_color="#1eff00"
            sc:scc_progress_size="15dp"
            sc:scc_stroke_color="#ffffff"
            sc:scc_stroke_size="30dp"
            sc:scc_notches="3"
            sc:scc_notches_length="32dp"
            sc:scc_notches_size="6dp"
            sc:scc_notches_color="#354051"
            sc:scc_text_tokens="1000|2000|3000"
            sc:scc_stroke_colors="#EC4949|#00B4FF|#F7AD36"
            sc:scc_stroke_colors_mode="solid"
            sc:scc_text_align="center"
            sc:scc_text_position="middle"
            sc:scc_text_color="#354051"/>

        <ImageView
            android:id="@+id/indicator"
            android:layout_width="64dp"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:src="@drawable/indicator"
            android:layout_marginLeft="18dp"
            android:layout_marginBottom="29dp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0000"
            android:layout_marginBottom="2dp"
            android:id="@+id/counter"
            android:layout_gravity="bottom|center_horizontal"
            android:textColor="#ffffff"
            android:textSize="20dp"/>

    </FrameLayout>

</LinearLayout>

//MainActivity.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.harshalbenake.gaugeview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import com.sccomponents.gauges.ScArcGauge;
import com.sccomponents.gauges.ScGauge;

public class MainActivity extends Activity {

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

        // Find the components
        final ScArcGauge gauge = (ScArcGauge) this.findViewById(R.id.gauge);
        assert gauge != null;

        final ImageView indicator = (ImageView) this.findViewById(R.id.indicator);
        assert indicator != null;

        final TextView counter = (TextView) this.findViewById(R.id.counter);
        assert counter != null;

        // Set the center pivot for a right rotation
        indicator.setPivotX(30f);
        indicator.setPivotY(30f);

        // As the progress feature by default the last to be draw I must bring the notches feature
        // on top.
        gauge.bringOnTop(ScGauge.NOTCHES_IDENTIFIER);

        // If you set the value from the xml that not produce an event so I will change the
        // value from code.
        gauge.setHighValue(60);

        // Each time I will change the value I must write it inside the counter text.
        gauge.setOnEventListener(new ScGauge.OnEventListener() {
            @Override
            public void onValueChange(float lowValue, float highValue) {
                // Convert the percentage value in an angle
                float angle = gauge.percentageToAngle(highValue);
                indicator.setRotation(angle);

                // Write the value
                int value = (int) ScGauge.percentageToValue(highValue, 0.0f, 3000.0f);
                counter.setText(value + "");
            }
        });
    }
}

Sunday, 15 October 2017

HB Blog 146: Create Product Counter Used In Android Applications.

In programming world we have very much importance of time and delivery of the product. We need to keep building up pieces so that we can build up complete product in time.
Here, in this tutorial I will show how to create counter that we have seen in many shopping cart and online food delivery Android applications such as Flipkart, Amazon, Zomato, etc.
Refer the below link for complete sample code:-

Download Sample Code

Have a look on few code snippets,

//custom_counter.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="horizontal">
        <ImageView
            android:id="@+id/ib_counterminus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_minus" />
        <EditText
            android:id="@+id/et_countervalue"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:digits="0123456789"
            android:gravity="center"
            android:imeOptions="actionDone"
            android:inputType="number"
            android:singleLine="true" />
        <ImageView
            android:id="@+id/ib_counterplus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_plus" />
    </LinearLayout>
</LinearLayout>

//activity_main.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.harshalbenake.counterview.views.CustomCounter
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
</RelativeLayout>

//CustomCounter.java
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.harshalbenake.counterview.views;

import android.content.Context;
import android.text.method.DigitsKeyListener;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.harshalbenake.counterview.R;

/**
 * This class is used for custom counter.
 */
public class CustomCounter extends LinearLayout implements View.OnClickListener,TextView.OnEditorActionListener {
    private Context mContext;
    private EditText met_countervalue;

    public interface OnConterSubmitListner {
        void onConterSubmit();
    }

    OnConterSubmitListner mOnConterSubmitListner;


    public CustomCounter(Context context) {
        super(context);
        this.mContext = context;
        initlayout();
    }

    public CustomCounter(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initlayout();
    }

    public CustomCounter(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.mContext = context;
        initlayout();
    }

    /**
     * initialize Layout
     */
    private void initlayout() {
        View rootView = inflate(mContext, R.layout.custom_counter, this);
        met_countervalue = (EditText) rootView.findViewById(R.id.et_countervalue);
        ImageView ib_counterminus = (ImageView) rootView.findViewById(R.id.ib_counterminus);
        ImageView ib_counterplus = (ImageView) rootView.findViewById(R.id.ib_counterplus);

        ib_counterminus.setOnClickListener(this);
        ib_counterplus.setOnClickListener(this);
        met_countervalue.setOnEditorActionListener(this);

        met_countervalue.setKeyListener(DigitsKeyListener.getInstance(true,true));

    }

    @Override
    public void onClick(View view) {
        int viewId = view.getId();
        if (viewId == R.id.ib_counterminus) {
            decrementValue();
        } else if (viewId == R.id.ib_counterplus) {
            incrementValue();
        }
    }

    @Override
    public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            if (mOnConterSubmitListner != null) {
                mOnConterSubmitListner.onConterSubmit();
            }
        }
        return false;
    }

    /**
     * increments Value
     */
    private void incrementValue() {
        int counterValue = getValue();
        met_countervalue.setText(String.valueOf(counterValue + 1));
    }

    /**
     * decrements Value
     */
    private void decrementValue() {
        int counterValue = getValue();
        if (counterValue > 0) {
            met_countervalue.setText(String.valueOf(counterValue - 1));
        }
    }

    /**
     * gets Value
     */
    public int getValue() {
        String counterValue = met_countervalue.getText().toString().trim();
        if (counterValue!=null && !counterValue.equalsIgnoreCase("")) {
            return Integer.valueOf(counterValue);
        } else {
            return 0;
        }
    }

    /**
     * sets Value
     */
    public void setValue(String strValue) {
        if (strValue!=null && !strValue.equalsIgnoreCase("")) {
            met_countervalue.setText(Integer.valueOf(strValue)+"");
        }
    }

    /**
     * set On ConterSubmit Listner
     * @param onConterSubmitListner
     */
    public void setOnConterSubmitListner(OnConterSubmitListner onConterSubmitListner) {
        mOnConterSubmitListner = onConterSubmitListner;
    }
}