NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.calculator.ayush.testapp;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.content.ContentResolver;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import android.provider.ContactsContract.Contacts;
import android.content.ContentUris;
import java.io.InputStream;
import java.io.ByteArrayInputStream;

public class MainActivity extends ActionBarActivity {
Boolean set[]={false,false,false,false};
String names[]={"","","",""};
String phNo[]={"","","",""};
Drawable icons[]={null,null,null,null};
Boolean callMode=true;

int contactPlace=-1;
Button btn1;
Button btn2;
Button btn3;
Button btn4;
TextView mode;
TextView tv1;
TextView tv2;
TextView tv3;
TextView tv4;
Switch sw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn2=(Button)findViewById(R.id.button2);
btn1=(Button)findViewById(R.id.button);
btn3=(Button)findViewById(R.id.button3);
btn4=(Button)findViewById(R.id.button4);
tv1=(TextView)findViewById(R.id.name1);
tv2=(TextView)findViewById(R.id.name2);
tv3=(TextView)findViewById(R.id.name3);
tv4=(TextView)findViewById(R.id.name4);
sw=(Switch) findViewById(R.id.switch1);
mode=(TextView)findViewById(R.id.mode);
mode.setText("Call Mode");
sw.setChecked(false);
sw.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {

if(isChecked){
mode.setText("What's App Mode");
callMode=false;

}else{
mode.setText("Call Mode");
callMode=true;
}

}
});
}
public void contact1(View v){
if(set[0]){
if(callMode) {
Intent i = new Intent();
i.setAction(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:" + phNo[0]));
startActivity(i);
}else{
Uri mUri = Uri.parse("smsto:"+phNo[0]);
Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri);
mIntent.setPackage("com.whatsapp");
mIntent.putExtra("chat",true);
startActivity(mIntent);
}

}else{
contactPlace=0;
Intent getContactInfo = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(getContactInfo,1);
}

}

public void contact2(View v){
if(set[1]){
if(callMode) {
Intent i = new Intent();
i.setAction(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:" + phNo[1]));
startActivity(i);
}else{
Uri mUri = Uri.parse("smsto:"+phNo[1]);
Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri);
mIntent.setPackage("com.whatsapp");
mIntent.putExtra("chat",true);
startActivity(mIntent);
}

}else{
contactPlace=1;
Intent getContactInfo = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(getContactInfo,1);
}

}

public void contact3(View v){
if(set[2]){
if(callMode) {
Intent i = new Intent();
i.setAction(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:" + phNo[2]));
startActivity(i);
}else{
Uri mUri = Uri.parse("smsto:"+phNo[2]);
Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri);
mIntent.setPackage("com.whatsapp");
mIntent.putExtra("chat",true);
startActivity(mIntent);
}

}else{
contactPlace=2;
Intent getContactInfo = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(getContactInfo,1);
}

}

public void contact4(View v){
if(set[3]){
if(callMode) {
Intent i = new Intent();
i.setAction(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:" + phNo[3]));
startActivity(i);
}else{
Uri mUri = Uri.parse("smsto:"+phNo[3]);
Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri);
mIntent.setPackage("com.whatsapp");
mIntent.putExtra("chat",true);
startActivity(mIntent);
}

}else{
contactPlace=3;
Intent getContactInfo = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(getContactInfo,1);
}

}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case 1:
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(contactData,null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
icons[contactPlace]=Drawable.createFromStream(openPhoto(Long.parseLong(id)), null);
names[contactPlace]= cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
phNo[contactPlace]=pCur.getString(pCur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
pCur.close();
}
}
}
setData();
cur.close();
}
}



}

public void setData(){
switch (contactPlace){
case 0:
if(icons[contactPlace]!=null) {
btn1.setText("");
btn1.setBackground(icons[contactPlace]);
}else{
btn1.setText("No Photo");
}
tv1.setText(names[contactPlace]+" n"+phNo[contactPlace]);
break;
case 1:
if (icons[contactPlace]!=null) {
btn2.setText("");
btn2.setBackground(icons[contactPlace]);
}else{
btn2.setText("No Photo");
}
tv2.setText(names[contactPlace]+" n"+phNo[contactPlace]);
break;
case 2:
if (icons[contactPlace]!=null) {
btn3.setText("");
btn3.setBackground(icons[contactPlace]);
}else{
btn3.setText("No Photo");
}
tv3.setText(names[contactPlace]+" n"+phNo[contactPlace]);
break;
case 3:
if (icons[contactPlace]!=null) {
btn4.setText("");
btn4.setBackground(icons[contactPlace]);
}else{
btn4.setText("No Photo");
}
tv4.setText(names[contactPlace]+" n"+phNo[contactPlace]);
break;
}
set[contactPlace]=true;
contactPlace=-1;
}

public InputStream openPhoto(long contactId) {
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
Cursor cursor = getContentResolver().query(photoUri,
new String[] {Contacts.Photo.PHOTO}, null, null, null);
if (cursor == null) {
return null;
}
try {
if (cursor.moveToFirst()) {
byte[] data = cursor.getBlob(0);
if (data != null) {
return new ByteArrayInputStream(data);
}
}
} finally {
cursor.close();
}
return null;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}


}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.