Framelayout with sliding drawer.
Sliding Menu has three option
1.custom message and send to one person.
2.custom/non-custom message and send to one person/multiple person.3.Send location (longitude/latitude).
Dashboard-XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bgtwo"
tools:ignore="MergeRootFrame" >
<SlidingDrawer
android:id="@+id/SlidingDrawer01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:content="@+id/LinearLayout01"
android:handle="@+id/Button05"
android:orientation="vertical"
android:padding="10dip" >
<Button
android:id="@+id/Button05"
android:layout_width="100dp"
android:layout_height="90dp"
android:background="@drawable/arrow_up" />
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/sendme"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="@drawable/sendme" />
<Button
android:id="@+id/sendall"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="10dp"
android:background="@drawable/sendall" />
<Button
android:id="@+id/position"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="100dp"
android:background="@drawable/position" />
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
========================================================================
Dashboard-Java Class
==========package com.example.mychoir;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SlidingDrawer;
import android.widget.Toast;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
@SuppressWarnings("deprecation")
public class HomeActivity extends ActionBarActivity {
Button slideButton,sendme,sendall,position;
SlidingDrawer slidingDrawer;
double latitude = 0, longitude = 0;
LocationManager lMan;
String phn ="9605252521";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
initilization();
lMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String provider = null;
if ( lMan.isProviderEnabled(LocationManager.NETWORK_PROVIDER ) )
provider = LocationManager.NETWORK_PROVIDER;
else if (lMan.isProviderEnabled(LocationManager.GPS_PROVIDER ) )
provider = LocationManager.GPS_PROVIDER;
if(provider != null) {
Log.v("lMan", "listener REGISTERED");
lMan.requestLocationUpdates(provider, 10000, 10, lListener);
} else {
Log.e("lMan", "NO PROVIDERS!");
}
position.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
List<Address> addresses = null;
try {
addresses = gcd.getFromLocation(latitude, longitude, 1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
if (addresses != null & addresses.size() > 0){
System.out.println(addresses.get(0).getLocality());
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phn, null, " " +"Right now am in "+addresses.get(0).getLocality(), null, null);
Toast.makeText(getApplicationContext(),
" Message sent... "+addresses.get(0).getLocality(),
Toast.LENGTH_LONG).show();
}
else{
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phn, null, "Traced location via latitude= "+latitude +" longitude= "+longitude+"" , null, null);
Toast.makeText(getApplicationContext(),
"Message sent... = "+latitude +" longitude= "+longitude+"",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild !! LocationService in phone settings, is not configured ",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
sendme.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SmsActivity.class);
intent.putExtra("MSGType","single");
startActivity(intent);
// TODO Auto-generated method stub
}
});
sendall.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SmsActivity.class);
intent.putExtra("MSGType","multiple");
startActivity(intent);
// TODO Auto-generated method stub
}
});
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
public void onDrawerOpened() {
slideButton.setBackgroundResource(R.drawable.arrow_down);
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
public void onDrawerClosed() {
slideButton.setBackgroundResource(R.drawable.arrow_up);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
public void initilization(){
slideButton=(Button)findViewById(R.id.Button05);
sendme=(Button)findViewById(R.id.sendme);
sendall=(Button)findViewById(R.id.sendall);
position=(Button)findViewById(R.id.position);
slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer01);
}
LocationListener lListener = new LocationListener() {
public void onLocationChanged(Location location) {
longitude = location.getLongitude();
latitude = location.getLatitude();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
}
SMS Layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="20dp"
android:background="@drawable/bgtwo"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editTextSMS"
android:layout_width="fill_parent"
android:layout_height="135dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="20dp"
android:background="@drawable/bgsix"
android:hint="Enter SMS Message "
android:inputType="textShortMessage"
android:singleLine="false"
android:text=" "
android:textColor="@color/white"
android:textSize="30dp"
android:textStyle="bold"
android:visibility="gone" >
</EditText>
<Spinner
android:id="@+id/spinnerSMS"
android:layout_width="531dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_marginTop="20dp"
android:background="@drawable/bgfour"
android:gravity="center"
android:textSize="30dp"
android:visibility="visible" >
</Spinner>
<TimePicker
android:id="@+id/spinnerTime"
android:layout_width="531dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:layout_marginTop="20dp"
android:background="@drawable/bgfour"
android:gravity="center"
android:textSize="30dp"
android:visibility="visible"
/>
<Button
android:id="@+id/buttonSend"
android:layout_width="233dp"
android:layout_height="71dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/bgsix"
android:text="Send Message Admin"
android:textColor="@color/white"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
========================================================================
SmS Layout Java Class
========================================================================
package com.example.mychoir;
import java.util.Calendar;
import android.app.Activity;
import android.app.ActionBar.OnNavigationListener;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TimePicker;
import android.widget.Toast;
public class SmsActivity extends Activity{
String phn="9605252521";
Button buttonSend;
EditText editTextSMS;
Spinner spinnerSMS;
TimePicker spinnerTime;
String[]phns={"9605252521"};
String Days[] = {"MonDay", "TuesDay", "WedsDay", "ThursDay", "FriDay", "SaterDay", "SunDay"};
String MsgType="";
private int hour;
private int minute;
String slelectedtime="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.smslayout);
buttonSend=(Button)findViewById(R.id.buttonSend);
editTextSMS=(EditText)findViewById(R.id.editTextSMS);
spinnerSMS=(Spinner)findViewById(R.id.spinnerSMS);
spinnerTime=(TimePicker)findViewById(R.id.spinnerTime);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, Days);
spinnerArrayAdapter.setDropDownViewResource(R.drawable.spinneritem); // The drop down view
spinnerSMS.setAdapter(spinnerArrayAdapter);
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
spinnerTime.setCurrentHour(hour);
spinnerTime.setCurrentMinute(minute);
Bundle extras = getIntent().getExtras();
if (extras != null) {
MsgType = extras.getString("MSGType");
Log.v("MSGType", MsgType);
if (MsgType.equals("single")) {
spinnerSMS.setVisibility(View.GONE);
spinnerTime.setVisibility(View.GONE);
editTextSMS.setVisibility(View.VISIBLE);
}else {
buttonSend.setText("Send to All");
spinnerSMS.setVisibility(View.VISIBLE);
spinnerTime.setVisibility(View.VISIBLE);
editTextSMS.setVisibility(View.GONE);
}
}else {
}
buttonSend.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String message=editTextSMS.getText().toString();
if(MsgType.equals("multiple")){
if(message.equals("")|| message.equals(null)){
for(int i=0;i<phns.length;i++){
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phns[i], null, "", null, null);
Log.v("Sent to", phns[i]);
Toast.makeText(getApplicationContext(),
phns[i]+" Blank Message sent..." ,
Toast.LENGTH_LONG).show();
}
}
else{
for(int i=0;i<phns.length;i++){
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phns[i], null,"The next meeting of the Choir Committee will take place on "+ spinnerSMS.getSelectedItem().toString()+ " in St.Sebastian Church Puranattukara at ."(hour,minute), null, null);
Log.v("Sent to", phns[i]);
Toast.makeText(getApplicationContext(),
phns[i]+" Message sent ..." ,
Toast.LENGTH_LONG).show();
}
}
}
if (MsgType.equals("single")) {
if(message.equals("")|| message.equals(null)){
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phn, null, "", null, null);
Toast.makeText(getApplicationContext(),
phn+" Blank Message sent..." ,
Toast.LENGTH_LONG).show();
}
else{
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phn, null, message, null, null);
Toast.makeText(getApplicationContext(),
phn+" Message sent..." ,
Toast.LENGTH_LONG).show();
}
}
Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(intent);
}
});
}
}
No comments:
Post a Comment