Monday, 22 July 2013

Intoducing TextView in alertdialogue and Onclicklistener on that

import android.app.Activity;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    public static final String PREFS_NAME = "MyPrefsFile1";
    public CheckBox dontShowAgain;

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

        final CheckBox dontShowAgain = new CheckBox(this);

        TextView textViewTerms = new TextView(this);

        textViewTerms.setText("Terms & Conditions   ");

        TextView textView = new TextView(this);

        textView.setText(Html.fromHtml("<u>Details</u>"));
        textView.setTextColor(Color.BLUE);
       
       
       
       
        textView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "clicked",
                        Toast.LENGTH_LONG).show();

            }
        });

        LinearLayout checkBoxLayout = new LinearLayout(this);
        checkBoxLayout.setLayoutParams(new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));

        checkBoxLayout.addView(dontShowAgain);
        checkBoxLayout.addView(textViewTerms);
        checkBoxLayout.addView(textView);

        AlertDialog.Builder altDialog = new AlertDialog.Builder(this);
        altDialog.setCancelable(false);
        altDialog.setView(checkBoxLayout);
        altDialog.setMessage("Do not Show Again");
        altDialog.setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                   

                        String checkBoxResult = "NOT checked";
                        if (dontShowAgain.isChecked())
                            checkBoxResult = "checked";
                        SharedPreferences settings = getSharedPreferences(
                                PREFS_NAME, 0);
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putString("skipMessage", checkBoxResult);
                        // Commit the edits!
                        editor.commit();
                        return;

                    }
                });

        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        String skipMessage = settings.getString("skipMessage", "NOT checked");
        if (skipMessage != "checked") {

            altDialog.show();
           
        }

       
   
    }
   
   
   
}

Sunday, 21 July 2013

Alert dialogue with checkbox should appear only when check box is unchecked

package com.example.callingintent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

    public String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    protected static final int REQUEST_CODE = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EditText edt1 = (EditText) findViewById(R.id.editText1);
        Button button1 = (Button) findViewById(R.id.button1);
        EditText et1 = (EditText) findViewById(R.id.editText1);
        et1.setText(getName());
        button1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                Intent myintent = new Intent(MainActivity.this,
                        secondActivity.class);
                myintent.putExtra("name", "namratha");
                myintent.putExtra("Id", 1);
                // startActivity(myintent);
                startActivityForResult(myintent, REQUEST_CODE);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        String returnString;
        if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
            if (data.hasExtra("returnString1")) {
                returnString = data.getExtras().getString("returnString1");
                System.out.println("return string is   " + returnString);
                setName(returnString);

            }
        }

    }

}




package com.example.callingintent;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;

public class secondActivity extends Activity {
    public static final String PREFS_NAME = "MyPrefsFile1";
    public CheckBox dontShowAgain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
        EditText et1 = (EditText) findViewById(R.id.editText1);
        EditText et2 = (EditText) findViewById(R.id.editText2);
        Bundle mydata = getIntent().getExtras();
        if (mydata != null) {
            String name = mydata.getString("name");
            int id = mydata.getInt("Id");
            System.out.println("id is " + id);

            et1.setText(name);
            // et1.setText(id);

        }

        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        LayoutInflater adbInflater = LayoutInflater.from(this);
        View eulaLayout = adbInflater.inflate(R.layout.checkbox, null);
        dontShowAgain = (CheckBox) eulaLayout.findViewById(R.id.skip);
        adb.setView(eulaLayout);
        adb.setTitle("Attention");
        adb.setMessage(Html.fromHtml("Message"));
        adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                String checkBoxResult = "NOT checked";
                if (dontShowAgain.isChecked())
                    checkBoxResult = "checked";
                SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                SharedPreferences.Editor editor = settings.edit();
                editor.putString("skipMessage", checkBoxResult);
                // Commit the edits!
                editor.commit();
                return;
            }
        });
        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        String skipMessage = settings.getString("skipMessage", "NOT checked");
        if (skipMessage != "checked")
            adb.show();

    }

    public void finish() {
        Intent data = new Intent();

        data.putExtra("returnString1", "Message to parent activity");
        setResult(RESULT_OK, data);
        super.finish();

    }

}



activity_main.xml
-------------------------
<RelativeLayout 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" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="44dp"
        android:text="Button" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_marginTop="33dp"
        android:layout_toLeftOf="@+id/textView1"
        android:ems="10" >

        <requestFocus />
    </EditText>

</RelativeLayout>


checkbox.xml
-------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="10dp" >

    <CheckBox
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/skip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Do not show again" >
    </CheckBox>

</LinearLayout>

second.xml
--------------------------
<RelativeLayout 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" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Hello Second Activity"
        tools:context=".MainActivity" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="36dp"
        android:layout_marginTop="36dp"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:layout_marginLeft="21dp"
        android:layout_marginTop="20dp"
        android:ems="10" />

</RelativeLayout>

Wednesday, 17 July 2013

Delete DataBase android sqllite

// TODO Auto-generated method stub
         public void deleteDatabase() {
             System.out.println("delete deleteDatabase calleds");
             mHelper = new MyDbHelper(context,
                      "dbname");
                 SQLiteDatabase db = mHelper.getWritableDatabase();
           
                 mHelper.close();
                 db.close();
              if (this.context().deleteDatabase("dbname") {
              System.out.println("db deleted");
              } else {
                System.out.println("not deleted");
              }
            }

InsertList RemoveList Easy Approach


import java.util.ArrayList;
import java.util.List;

public class ListCompApa {
    public static void main(String[] args) {
       
       
           

         final List<String> gatewaylist = new ArrayList<String>();
   
         gatewaylist.add("namea");
         gatewaylist.add("sam");
         final List<String> dblist = new ArrayList<String>();
         dblist.add("ddd");
         dblist.add("lll");
         dblist.add("namea");
       
         final List<String> insertList = new ArrayList<String>(gatewaylist);
         insertList.removeAll(dblist);
         final List<String> removeList = new ArrayList<String>(dblist);
         removeList.removeAll(gatewaylist);
         System.out.println("gatewaylist ins "+insertList);
         System.out.println("dblist rem "+removeList);
       
    }

}

Tuesday, 9 July 2013

list compare

import java.util.ArrayList;

public class SampleList {
    public static void main(String[] args) {
         ArrayList<String> arl=new ArrayList<String>();
       
       
         ArrayList<String> first=new ArrayList<String>();
         ArrayList<String> second=new ArrayList<String>();
       
         first.add("checkthis");
         first.add("cat");
         first.add("dog");
         first.add("mat");
         second.add("checkthis");
         second.add("hello");
         second.add("haio");
         second.add("nameghj");
       
       
       
         for (String a : first)
            {
                for (String b : second)
                {
                    if (a.equals(b))
                    {
                        System.out.println("Equals " + a);
                       
                    }
                }
            }
       
       
       
       
       
       
         if(second.contains("checkthis"))
             System.out.println("true");
         else
             System.out.println("false");
       
         ArrayList<String> dup=new ArrayList<String>();
         String name = "abcd";
         String test ;
       
         arl.add("namratha");
         arl.add("sonu");
       
         if(arl.contains("namratha"))
         {
             System.out.println("exe");
             arl.remove("namratha");
             arl.add("namratha");
         }
       
       
         for(String sample : arl)
         {
             System.out.println("list items are "+sample);
         }
       
         dup.addAll(arl);
         for(String dupsam : dup)
         {
             System.out.println("Dup list "+dupsam);
         }
       
         if(!(name.equals(null))){
             System.out.println("executed");
         }
//         try {
//            if(test.equals(null))
//             {
//                 System.out.println("test is null");
//               
//             }
//             else
//             {
//                 System.out.println("space is executed");
//             }
//        } catch (NullPointerException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
       
       
       
       
    }

}



example 2 :
package com.sam;

import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;

public class listcompare {
    public static void main(String[] args) {
        Collection listOne = new ArrayList(Arrays.asList("milan", "dingo",
                "elpha", "hafil", "meat", "iga", "neeta.peeta"));
        Collection listTwo = new ArrayList(Arrays.asList("hafil", "iga",
                "binga", "mike", "dingo"));
        listOne.retainAll(listTwo);
        System.out.println("********************"+listOne);
       
       
        //my trial
       
       
        Collection first = new ArrayList<>();
        Collection second = new ArrayList<>();
        first.add("check");
        first.add("conn");
        first.add("dog");
       
        second.add("jkl");
        second.add("check");
        second.add("name");
       
        if(first.retainAll(second))
            System.out.println("first list "+first);
        System.out.println("second list "+second);
       
        System.out.println("first list after "+first);
       
       
    }
}



example 3
package com.sam;

import java.util.*;

public class compareobj {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        List<String> al1 = new ArrayList();
        al1.add("a1");
        al1.add("a2");
        al1.add("a3");
        al1.add("a5");
        al1.add("a6");
        List<String> al2 = new ArrayList();
        al2.add("a1");
        al2.add("a2");
        al2.add("a3");
        al2.add("a4");
       
       

        for (Object objList : al1) {
            if (al2.contains(objList)) {
                System.out.println("print same "+al2.toString());
                al2.remove(objList);
            }
            else
            {
                System.out.println("diff are "+al2);
            }
        }
        System.out.println("length" + al2.size());
        System.out.println("Value in list" + al2);

    }

}

Sunday, 30 June 2013

Country Codes

CS - Czechoslovakia
BE - Belgium
ET - Ethiopia
HU - Hungary
IT - Italy
LT - Lithuania
LV - Latvia
PL - Poland
RO - Romania
RU - Russian Federation
SK - Slovak Republic
UK - United Kingdom
NL - Netherlands
SV - El Salvador

Tuesday, 18 June 2013

OnClickListener for the item in the expandable listview

public void onGroupExpand(int groupPosition) {
        try {

            if (groupPosition == 1) {

              //Do your action
            }

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...