Saturday, 31 August 2013

android customised dialogue with text view checkbox

package com.example.checkedit;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    private static final String PREFS_NAME = "CheckBoxState";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
       
        customAlertdialog();
   
    }

       public void customAlertdialog(){

            //Inflate layout

            LayoutInflater inflater = getLayoutInflater();

            View dialoglayout = inflater.inflate(R.layout.yourview, (ViewGroup) findViewById(R.id.yourview_root));

            // set data in textview

            TextView text1 = (TextView)dialoglayout.findViewById(R.id.text1);
            final CheckBox che = (CheckBox)dialoglayout.findViewById(R.id.checkBox1);

            text1.setText("Terms and Conditions");
            text1.setOnClickListener(new OnClickListener() {
               
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                   
                     Toast.makeText(getApplicationContext(), "textview msg", Toast.LENGTH_SHORT).show();
                   
                }
            });

            //display alertdialog

            AlertDialog.Builder builder = new AlertDialog.Builder(this);

            builder.setView(dialoglayout).setTitle("Your title")

            .setCancelable(false)

            .setNeutralButton("Close", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {

               
                SharedPreferences settings = getSharedPreferences(
                        PREFS_NAME, 0);
                SharedPreferences.Editor editor = settings.edit();
                editor.putString("skipMessage", String.valueOf(che.isChecked()));
               
                // Commit the edits!
                editor.commit();
            dialog.cancel();

            }

            });

            AlertDialog alert = builder.create();

           
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
            String skipMessage = settings.getString("skipMessage", "NOT checked");
            System.out.println("ischeck is "+che.isChecked());
           
           
            if (!skipMessage.equals("true")) {

                alert.show();

            }
        

            }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}


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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>


yourview.xml


<?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:id="@+id/yourview_root" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/checkBox1"
        android:layout_alignBottom="@+id/checkBox1"
    android:layout_toRightOf="@+id/checkBox1"
        android:text="Do not show again" />

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="18dp"
        android:text="TextView1" />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/text1"
        android:layout_marginTop="20dp" />

    </RelativeLayout>
   

Second highest element in array

import java.util.Arrays;


public class secondlargest {
   
    public static void main(String[] args) {
        int a[] = { 0,80,200,500,900};
        Arrays.sort(a);
        for(int i=0;i<a.length;i++)
        {
        System.out.println("after sorting "+a[i]);
        }

        int largest = a[0];
        int secondlargest = a[0];
        int cmp = 0;
        for (int i = 0; i < a.length; i++) {

            if (largest < a[i]) {
                secondlargest = largest;
                largest = a[i];
               
               
            }
           
            else if(a[i]>secondlargest)
            {
                secondlargest = a[i];
            }

           

        }
        System.out.println("sec lar is "+secondlargest);
        System.out.println("lar is  " + largest);

    }

}

Monday, 12 August 2013

display metrics android(device width zero initially)

Plz add the following to the application oncreate method to get width and height of device




        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
          .getDefaultDisplay().getMetrics(displayMetrics);


DisplayMetrics met =  new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(met);
        System.out.println("here  "+met.widthPixels);
        System.out.println("here height is "+met.heightPixels);

Tuesday, 30 July 2013

Transperency in android canvas

Paint Paint = new Paint();
    Paint.setColor(Color.argb(50, 128, 24, 24));
    Paint.setStyle(Style.FILL);   
    Paint.setAntiAlias(true);


50 is the alpha parameter based on which transperency parameter will vary

Thursday, 25 July 2013

Complete excel to strings.xml and localised.txt is stored in google site(includes arrays also)


Java while running some external library file is missing

Do the following

Go to Project->Properties->Java Build Path than select Order and export tab. Set android-support-v4.jar library checked and up it into top of the list. And clean and rebuild..It works for most of the cases


External library is android-support-v4.jar in this case

Android header footer with scrollable listview



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_color" >

    <include
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="119dp"
        layout="@layout/header_text" />

    <include
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        layout="@layout/mnbuttons"
        android:id="@+id/footer"/>
    <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/footer"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="73dp" >
    </ListView>

</RelativeLayout>

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...