Tuesday, 24 September 2013

Calling other App from one App

package com.example.testintaller;

import android.app.Activity;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

    private Button btn;

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

        btn = (Button) findViewById(R.id.button1);

        btn.setOnClickListener(new OnClickListener() {

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

               

                   
                     Intent intent = new Intent(Intent.ACTION_MAIN);
                     intent.setClassName("package", "package.classname");
                     intent.putExtra("name", "xxx");
                     intent.putExtra("password", "yyyy");
                    startActivity(intent);
                   
           

            }
        });

    }

    @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;
    }

}


Note : Activity class of ther App which you are calling should be exported i,e in manifest we should give as android:exported = "true"

Tuesday, 3 September 2013

CustomView (accessing attrs.xml)

package com.example.customviewsecondexampkle;

import android.os.Bundle;

import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

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

    @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;
    }

}


package com.example.customviewsecondexampkle;

import android.content.Context;

import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.TextView;

public class ViewV extends TextView
{
    public ViewV(Context ctx, AttributeSet attrs)
    {
        super(ctx, attrs);

        TypedArray array = ctx.obtainStyledAttributes(attrs, R.styleable.CustomAttrs);
        String text = array.getString(R.styleable.CustomAttrs_xattr);
       
        if(text != null)
        {
          
        }
        array.recycle();
    }

}

activity_main.xml

<LinearLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res/com.example.customviewsecondexampkle"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" >

    <com.example.customviewsecondexampkle.ViewV
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           app:xattr="testing"  />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>

attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="CustomAttrs">
        <attr name="xattr" format="string" />
         <attr name="labelColor" format="color"/>
   
    </declare-styleable>
</resources>

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

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