• No results found

DESIGN PHASE 13

In document blutooth chat project report (Page 13-58)

The purpose of design phase is to plan a solution of the problem specified by the SRS.There are mainly three phases:-Architecture Design, High level design and Detail design

 Architecture design:- It focuses on looking at a system as a combination of many different components.

DFD of Royal chat:-

 High level design:- It identifies the modules that should be built for developing the

system and the specification of these modules.

Detail design:- In this, the internal logic of each of the modules is specified

DFD of DataBase:-

DFD of Server-Socket:-

DFD of DevicesListActivity:-

Database:-

SQLite is a relational database management system contained in a C programming library. In contrast to other database management systems, SQLite is not a separate process that is accessed from the client application, but an integral part of it.

SQLite is ACID-compliant and implements most of the SQL standard, using a dynamically and weakly typed SQL syntax that does not guarantee the domain integrity.

SQLite is a popular choice as embedded database for local/client storage in application software such as web browsers. It is arguably the most widely deployed database engine, as it is used today by several widespread browsers, operating systems, and embedded systems, among others.

SQLite has many bindings to programming languages.

Features :

SQLite implements most of the SQL-92 standard for SQL but it lacks some features. For example it has partial support for triggers, and it can't write to views (however it supports INSTEAD OF triggers that provide this functionality). While it supports complex queries, it still has limited ALTER TABLE support, as it can't modify or delete columns.

SQLite uses an unusual type system for an SQL-compatible DBMS; instead of assigning a type to a column as in most SQL database systems, types are assigned to individual values; in language terms it is dynamically typed. Moreover, it is weakly typed in some of the same ways that Perl is: one can insert a string into an integer column (although SQLite will try to convert the string to an integer first, if the column's preferred type is integer). This adds flexibility to

columns, especially when bound to a dynamically typed scripting language. However, the technique is not portable to other SQL products. A common criticism is that SQLite's type system lacks the data integrity mechanism provided by statically typed columns in other

products. The SQLite web site describes a "strict affinity" mode, but this feature has not yet been added.However, it can be implemented with constraints like

CHECK(typeof(x)='integer')

.

7. IMPLEMENTATION

Coding:-

SplashScreen.java:

package com.example.splash_screenn;

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

import android.widget.ProgressBar;

public class splash extends Activity { ProgressBar bar;

@Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

setContentView(R.layout.fragment_main);

bar=(ProgressBar) findViewById(R.id.progressBar1);

bar.setVisibility(View.VISIBLE);

public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu);

return true;

style="?android:attr/progressBarStyleLarge"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

</RelativeLayout>

Screen Shots:

NavigationDrawer.java

package com.example.royal_chat;

import android.os.Bundle;

import android.annotation.SuppressLint;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.content.res.Configuration;

import android.support.v4.app.ActionBarDrawerToggle;

import android.support.v4.view.GravityCompat;

import android.support.v4.widget.DrawerLayout;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.TextView;

import android.widget.Toast;

public class NavigationDrawer extends Activity {

private String[] drawerListArray;

// get list items from strings.xml

drawerListArray = getResources().getStringArray(R.array.items);

// get ListView defined in activity_main.xml

drawerlist = (ListView) findViewById(R.id.left_drawer);

// Set the adapter for the list view

drawerlist.setAdapter(new ArrayAdapter<String>(this, R.layout.listcontent, drawerListArray));

// 2. App Icon

drawerlayout = (DrawerLayout) findViewById(R.id.drawer_layout);

// 2.1 create ActionBarDrawerToggle

actionBarDrawerToggle = new ActionBarDrawerToggle(

this, /* host Activity */ drawerlayout.setDrawerListener(actionBarDrawerToggle);

// 2.3 enable and show "up" arrow

getActionBar().setDisplayHomeAsUpEnabled(true);

// just styling option

// drawerlayout.setDrawerShadow(R.drawable., GravityCompat.START);

drawerlist.setOnItemClickListener(new DrawerItemClickListener());

}

@Override

protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState);

// Sync the toggle state after onRestoreInstanceState has occurred.

actionBarDrawerToggle.syncState();

}

actionBarDrawerToggle.onConfigurationChanged(newConfig);

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

// call ActionBarDrawerToggle.onOptionsItemSelected(), if it returns true // then it has handled the app icon touch event

if (actionBarDrawerToggle.onOptionsItemSelected(item)) { return true;

}

return super.onOptionsItemSelected(item);

}

private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override

public void onItemClick(AdapterView parent, View view, int position, long id) {

Toast.makeText(getApplicationContext(), ((TextView)view).getText(), Toast.LENGTH_LONG).show();

// drawerLayout.closeDrawer(drawerlist);

switch (position) { case 0:

alertMessage();

break;

}

drawerLayout.closeDrawer(drawerlist);

}

public void alertMessage() {

// TODO Auto-generated method stub

DialogInterface.OnClickListener dialoginterfc=new DialogInterface.OnClickListener() {

case DialogInterface.BUTTON_NEGATIVE:

//no button is clicked do nothing

Toast.makeText(getApplicationContext(), "Oh! No", Toast.LENGTH_LONG).show();

break;

case DialogInterface.BUTTON_POSITIVE:

//Yes Button is clicked

Toast.makeText(getApplicationContext(), "Oh! Yes", Toast.LENGTH_LONG).show();

AlertDialog.Builder builder=new

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/drawer_layout"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<!-- The main content view -->

BluetoothChat.java

package com.example.bluetoothchat;

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.bluetooth.BluetoothAdapter;

import android.bluetooth.BluetoothDevice;

import android.content.Intent;

import android.os.Handler;

import android.os.Message;

import android.util.Log;

import android.view.KeyEvent;

import android.view.MenuInflater;

import android.view.MenuItem;

import android.view.View;

import android.view.Window;

import android.view.View.OnClickListener;

import android.view.inputmethod.EditorInfo;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ListView;

import android.widget.TextView;

import android.widget.Toast;

/**

* This is the main Activity that displays the current chat session.

*/

public class BluetoothChat extends Activity { // Debugging

private static final String TAG = "BluetoothChat";

private static final boolean D = true;

// Message types sent from the BluetoothChatService Handler public static final int MESSAGE_STATE_CHANGE = 1;

public static final int MESSAGE_READ = 2;

public static final int MESSAGE_WRITE = 3;

public static final int MESSAGE_DEVICE_NAME = 4;

public static final int MESSAGE_TOAST = 5;

// Key names received from the BluetoothChatService Handler public static final String DEVICE_NAME = "device_name";

public static final String TOAST = "toast";

// Intent request codes

private static final int REQUEST_CONNECT_DEVICE = 1;

private static final int REQUEST_ENABLE_BT = 2;

// Layout Views

private TextView mTitle;

private ListView mConversationView;

private EditText mOutEditText;

private Button mSendButton;

// Name of the connected device

private String mConnectedDeviceName = null;

// Array adapter for the conversation thread

private ArrayAdapter<String> mConversationArrayAdapter;

// String buffer for outgoing messages private StringBuffer mOutStringBuffer;

// Local Bluetooth adapter

private BluetoothAdapter mBluetoothAdapter = null;

// Member object for the chat services

private BluetoothChatService mChatService = null;

@Override

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

if(D) Log.e(TAG, "+++ ON CREATE +++");

// Set up the window layout

requestWindowFeature(Window.FEATURE_ACTION_BAR);

setContentView(R.layout.activity_main);

getWindow().setFeatureInt(Window.FEATURE_ACTION_BAR, R.layout.custom_title);

// Set up the custom title

mTitle = (TextView) findViewById(R.id.title_left_text);

//mTitle.setText(R.string.app_name);

mTitle = (TextView) findViewById(R.id.title_right_text);

// If the adapter is null, then Bluetooth is not supported

Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(enableIntent, REQUEST_ENABLE_BT);

// Otherwise, setup the chat session

public synchronized void onResume() { super.onResume();

if(D) Log.e(TAG, "+ ON RESUME +");

// Performing this check in onResume() covers the case in which BT was // not enabled during onStart(), so we were paused to enable it...

// onResume() will be called when ACTION_REQUEST_ENABLE activity returns.

if (mChatService != null) {

mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);

mConversationView = (ListView) findViewById(R.id.in);

mConversationView.setAdapter(mConversationArrayAdapter);

// Initialize the compose field with a listener for the return key mOutEditText = (EditText) findViewById(R.id.edit_text_out);

mOutEditText.setOnEditorActionListener(mWriteListener);

// Initialize the send button with a listener that for click events mSendButton = (Button) findViewById(R.id.button_send);

mSendButton.setOnClickListener(new OnClickListener() { public void onClick(View v) {

// Initialize the BluetoothChatService to perform bluetooth connections mChatService = new BluetoothChatService(this, mHandler);

// Initialize the buffer for outgoing messages

private void ensureDiscoverable() {

if(D) Log.d(TAG, "ensure discoverable");

if (mBluetoothAdapter.getScanMode() !=

BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) { Intent discoverableIntent = new

Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);

startActivity(discoverableIntent);

} } /**

private void sendMessage(String message) {

// Check that we're actually connected before trying anything

if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) { Toast.makeText(this, R.string.not_connected, Toast.LENGTH_SHORT).show();

return;

// The action listener for the EditText widget, to listen for the return key private TextView.OnEditorActionListener mWriteListener =

new TextView.OnEditorActionListener() {

public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { // If the action is a key-up event on the return key, send the message

// The Handler that gets information back from the BluetoothChatService private final Handler mHandler = new Handler() {

break;

public void onActivityResult(int requestCode, int resultCode, Intent data) { if(D) Log.d(TAG, "onActivityResult " + resultCode);

Toast.makeText(this, R.string.bt_not_enabled_leaving,

public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater();

inflater.inflate(R.menu.main, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {

case R.id.scan:

// Launch the DeviceListActivity to see devices and do scan Intent serverIntent = new Intent(this, DeviceListActivity.class);

startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);

return true;

import android.os.Handler;

import android.os.Message;

import android.util.Log;

/**

* This class does all the work for setting up and managing Bluetooth * connections with other devices. It has a thread that listens for * incoming connections, a thread for connecting with a device, and a * thread for performing data transmissions when connected.

*/

public class BluetoothChatService { // Debugging

private static final String TAG = "BluetoothChatService";

private static final boolean D = true;

// Name for the SDP record when creating server socket private static final String NAME = "BluetoothChat";

// Unique UUID for this application

private static final UUID MY_UUID = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");

// Member fields

private final BluetoothAdapter mAdapter;

private final Handler mHandler;

private AcceptThread mAcceptThread;

private ConnectThread mConnectThread;

private ConnectedThread mConnectedThread;

private int mState;

// Constants that indicate the current connection state

public static final int STATE_NONE = 0; // we're doing nothing

public static final int STATE_LISTEN = 1; // now listening for incoming connections

public static final int STATE_CONNECTING = 2; // now initiating an outgoing connection

public static final int STATE_CONNECTED = 3; // now connected to a remote device /**

* Constructor. Prepares a new BluetoothChat session.

* @param context The UI Activity Context

* @param handler A Handler to send messages back to the UI Activity */

public BluetoothChatService(Context context, Handler handler) { mAdapter = BluetoothAdapter.getDefaultAdapter();

mState = STATE_NONE;

mHandler = handler;

} /**

* Set the current state of the chat connection

* @param state An integer defining the current connection state

mState = state;

// Give the new state to the Handler so the UI Activity can update mHandler.obtainMessage(BluetoothChat.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();

* Start the chat service. Specifically start AcceptThread to begin a * session in listening (server) mode. Called by the Activity onResume() */

public synchronized void start() { if (D) Log.d(TAG, "start");

// Cancel any thread attempting to make a connection

if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}

// Cancel any thread currently running a connection

if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}

* Start the ConnectThread to initiate a connection to a remote device.

* @param device The BluetoothDevice to connect */

public synchronized void connect(BluetoothDevice device) { if (D) Log.d(TAG, "connect to: " + device);

if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}

// Start the thread to connect with the given device mConnectThread = new ConnectThread(device);

mConnectThread.start();

setState(STATE_CONNECTING);

} /**

* Start the ConnectedThread to begin managing a Bluetooth connection * @param socket The BluetoothSocket on which the connection was made * @param device The BluetoothDevice that has been connected

*/

public synchronized void connected(BluetoothSocket socket, BluetoothDevice device) {

if (D) Log.d(TAG, "connected");

// Cancel the thread that completed the connection

if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}

// Cancel any thread currently running a connection

if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}

// Cancel the accept thread because we only want to connect to one device if (mAcceptThread != null) {mAcceptThread.cancel(); mAcceptThread = null;}

// Start the thread to manage the connection and perform transmissions mConnectedThread = new ConnectedThread(socket);

mConnectedThread.start();

// Send the name of the connected device back to the UI Activity

Message msg = mHandler.obtainMessage(BluetoothChat.MESSAGE_DEVICE_NAME);

Bundle bundle = new Bundle();

bundle.putString(BluetoothChat.DEVICE_NAME, device.getName());

msg.setData(bundle);

if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}

if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}

if (mAcceptThread != null) {mAcceptThread.cancel(); mAcceptThread = null;}

setState(STATE_NONE);

} /**

* Write to the ConnectedThread in an unsynchronized manner * @param out The bytes to write

* @see ConnectedThread#write(byte[]) */

// Synchronize a copy of the ConnectedThread

* Indicate that the connection attempt failed and notify the UI Activity.

*/

private void connectionFailed() { setState(STATE_LISTEN);

// Send a failure message back to the Activity

Message msg = mHandler.obtainMessage(BluetoothChat.MESSAGE_TOAST);

Bundle bundle = new Bundle();

bundle.putString(BluetoothChat.TOAST, "Unable to connect device");

msg.setData(bundle);

mHandler.sendMessage(msg);

} /**

* Indicate that the connection was lost and notify the UI Activity.

*/

private void connectionLost() { setState(STATE_LISTEN);

// Send a failure message back to the Activity

Message msg = mHandler.obtainMessage(BluetoothChat.MESSAGE_TOAST);

Bundle bundle = new Bundle();

bundle.putString(BluetoothChat.TOAST, "Device connection was lost");

msg.setData(bundle);

mHandler.sendMessage(msg);

} /**

* This thread runs while listening for incoming connections. It behaves * like a server-side client. It runs until a connection is accepted * (or until cancelled).

*/

private class AcceptThread extends Thread { // The local server socket

private final BluetoothServerSocket mmServerSocket;

public AcceptThread() {

mmServerSocket = tmp;

/**

* This thread runs while attempting to make an outgoing connection * with a device. It runs straight through; the connection either * succeeds or fails.

*/

private class ConnectThread extends Thread { private final BluetoothSocket mmSocket;

private final BluetoothDevice mmDevice;

public ConnectThread(BluetoothDevice device) { mmDevice = device;

// Start the connected thread

* It handles all incoming and outgoing transmissions.

*/

private class ConnectedThread extends Thread { private final BluetoothSocket mmSocket;

private final InputStream mmInStream;

private final OutputStream mmOutStream;

public ConnectedThread(BluetoothSocket socket) { Log.d(TAG, "create ConnectedThread");

} catch (IOException e) {

import android.widget.AdapterView;

* This Activity appears as a dialog. It lists any paired devices and * devices detected in the area after discovery. When a device is chosen * by the user, the MAC address of the device is sent back to the parent * Activity in the result Intent.

*/

public class DeviceListActivity extends Activity { // Debugging

private static final String TAG = "DeviceListActivity";

private static final boolean D = true;

// Return Intent extra

public static String EXTRA_DEVICE_ADDRESS = "device_address";

// Member fields

private BluetoothAdapter mBtAdapter;

private ArrayAdapter<String> mPairedDevicesArrayAdapter;

private ArrayAdapter<String> mNewDevicesArrayAdapter;

@Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

// Setup the window

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

setContentView(R.layout.device_list);

// Set result CANCELED incase the user backs out setResult(Activity.RESULT_CANCELED);

// Initialize the button to perform device discovery

Button scanButton = (Button) findViewById(R.id.button_scan);

scanButton.setOnClickListener(new OnClickListener() { public void onClick(View v) {

mPairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);

mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);

pairedListView.setAdapter(mPairedDevicesArrayAdapter);

pairedListView.setOnItemClickListener(mDeviceClickListener);

// Find and set up the ListView for newly discovered devices

ListView newDevicesListView = (ListView) findViewById(R.id.new_devices);

newDevicesListView.setAdapter(mNewDevicesArrayAdapter);

newDevicesListView.setOnItemClickListener(mDeviceClickListener);

// Register for broadcasts when a device is discovered

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

this.registerReceiver(mReceiver, filter);

// Register for broadcasts when discovery has finished

filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);

this.registerReceiver(mReceiver, filter);

// Get the local Bluetooth adapter

mBtAdapter = BluetoothAdapter.getDefaultAdapter();

// Get a set of currently paired devices

Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();

// If there are paired devices, add each one to the ArrayAdapter if (pairedDevices.size() > 0) {

findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);

for (BluetoothDevice device : pairedDevices) { this.unregisterReceiver(mReceiver);

} /**

* Start device discover with the BluetoothAdapter */

private void doDiscovery() {

if (D) Log.d(TAG, "doDiscovery()");

// Indicate scanning in the title

setProgressBarIndeterminateVisibility(true);

setTitle(R.string.scanning);

// Turn on sub-title for new devices

findViewById(R.id.title_new_devices).setVisibility(View.VISIBLE);

// If we're already discovering, stop it

// The on-click listener for all devices in the ListViews

private OnItemClickListener mDeviceClickListener = new OnItemClickListener() { public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) {

// The BroadcastReceiver that listens for discovered devices and // changes the title when discovery is finished

private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override

setProgressBarIndeterminateVisibility(false);

setTitle(R.string.select_device);

if (mNewDevicesArrayAdapter.getCount() == 0) { String noDevices =

getResources().getText(R.string.none_found).toString();

mNewDevicesArrayAdapter.add(noDevices);

} } } };

}

Actionbar.java:-

package com.markupartist.android.widget;

import java.util.LinkedList;

import com.markupartist.android.widget.actionbar.R;

import android.content.ActivityNotFoundException;

import android.content.Context;

import android.content.Intent;

import android.content.res.TypedArray;

import android.util.AttributeSet;

import android.view.LayoutInflater;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.ImageButton;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.ProgressBar;

import android.widget.RelativeLayout;

import android.widget.TextView;

import android.widget.Toast;

public class ActionBar extends RelativeLayout implements OnClickListener {

private LayoutInflater mInflater;

private RelativeLayout mBarView;

private ImageView mLogoView;

private View mBackIndicator;

//private View mHomeView;

private TextView mTitleView;

private LinearLayout mActionsView;

private ImageButton mHomeBtn;

private RelativeLayout mHomeLayout;

private ProgressBar mProgress;

public ActionBar(Context context, AttributeSet attrs) { super(context, attrs);

mInflater = (LayoutInflater)

context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

mBarView = (RelativeLayout) mInflater.inflate(R.layout.actionbar, null);

addView(mBarView);

mLogoView = (ImageView) mBarView.findViewById(R.id.actionbar_home_logo);

mHomeLayout = (RelativeLayout) mBarView.findViewById(R.id.actionbar_home_bg);

mHomeBtn = (ImageButton) mBarView.findViewById(R.id.actionbar_home_btn);

mBackIndicator = mBarView.findViewById(R.id.actionbar_home_is_back);

mTitleView = (TextView) mBarView.findViewById(R.id.actionbar_title);

mActionsView = (LinearLayout) mBarView.findViewById(R.id.actionbar_actions);

mProgress = (ProgressBar) mBarView.findViewById(R.id.actionbar_progress);

TypedArray a = context.obtainStyledAttributes(attrs,

if (title != null) { setTitle(title);

}

a.recycle();

}

public void setHomeAction(Action action) { mHomeBtn.setOnClickListener(this);

mHomeBtn.setTag(action);

mHomeBtn.setImageResource(action.getDrawable());

mHomeLayout.setVisibility(View.VISIBLE);

}

public void clearHomeAction() {

mHomeLayout.setVisibility(View.GONE);

}

/**

* Shows the provided logo to the left in the action bar.

*

* This is ment to be used instead of the setHomeAction and does not draw * a divider to the left of the provided logo.

*

* @param resId The drawable resource id */

public void setHomeLogo(int resId) {

// TODO: Add possibility to add an IntentAction as well.

mLogoView.setImageResource(resId);

mLogoView.setVisibility(View.VISIBLE);

mHomeLayout.setVisibility(View.GONE);

}

/* Emulating Honeycomb, setdisplayHomeAsUpEnabled takes a boolean * and toggles whether the "home" view should have a little triangle * indicating "up" */

public void setDisplayHomeAsUpEnabled(boolean show) {

mBackIndicator.setVisibility(show? View.VISIBLE : View.GONE);

}

public void setTitle(CharSequence title) { mTitleView.setText(title);

}

public void setTitle(int resid) { mTitleView.setText(resid);

}

/**

* Set the enabled state of the progress bar.

*

* @param One of {@link View#VISIBLE}, {@link View#INVISIBLE}, * or {@link View#GONE}.

*/

public void setProgressBarVisibility(int visibility) { mProgress.setVisibility(visibility);

}

/**

* Returns the visibility status for the progress bar.

*

* @param One of {@link View#VISIBLE}, {@link View#INVISIBLE},

public int getProgressBarVisibility() { return mProgress.getVisibility();

}

/**

* Function to set a click listener for Title TextView *

* @param listener the onClickListener */

public void setOnTitleClickListener(OnClickListener listener) { mTitleView.setOnClickListener(listener);

}

@Override

public void onClick(View view) { final Object tag = view.getTag();

if (tag instanceof Action) {

final Action action = (Action) tag;

action.performAction(view);

} }

/**

* Adds a list of {@link Action}s.

* @param actionList the actions to add */

public void addActions(ActionList actionList) { int actions = actionList.size();

for (int i = 0; i < actions; i++) { addAction(actionList.get(i));

} }

/**

* Adds a new {@link Action}.

* @param action the action to add */

public void addAction(Action action) {

final int index = mActionsView.getChildCount();

addAction(action, index);

}

/**

* Adds a new {@link Action} at the specified index.

* @param action the action to add

* @param index the position at which to add the action */

public void addAction(Action action, int index) { mActionsView.addView(inflateAction(action), index);

}

/**

* Removes all action views from this action bar */

public void removeAllActions() { mActionsView.removeAllViews();

}

/**

* Remove a action from the action bar.

* @param index position of action to remove */

}

/**

* Remove a action from the action bar.

* @param action The action to remove */

public void removeAction(Action action) {

int childCount = mActionsView.getChildCount();

for (int i = 0; i < childCount; i++) { View view = mActionsView.getChildAt(i);

if (view != null) {

final Object tag = view.getTag();

if (tag instanceof Action && tag.equals(action)) { mActionsView.removeView(view);

} } } }

/**

* Returns the number of actions currently registered with the action bar.

* @return action count */

public int getActionCount() {

return mActionsView.getChildCount();

}

/**

* Inflates a {@link View} with the given {@link Action}.

* @param action the action to inflate * @return a view

*/

private View inflateAction(Action action) {

View view = mInflater.inflate(R.layout.actionbar_item, mActionsView, false);

ImageButton labelView =

(ImageButton) view.findViewById(R.id.actionbar_item);

labelView.setImageResource(action.getDrawable());

view.setTag(action);

view.setOnClickListener(this);

return view;

}

/**

* A {@link LinkedList} that holds a list of {@link Action}s.

*/

public static class ActionList extends LinkedList<Action> { }

/**

* Definition of an action that could be performed, along with a icon to * show.

*/

public interface Action { public int getDrawable();

public void performAction(View view);

}

public static abstract class AbstractAction implements Action { final private int mDrawable;

}

@Override

public int getDrawable() { return mDrawable;

} }

public static class IntentAction extends AbstractAction { private Context mContext;

private Intent mIntent;

public IntentAction(Context context, Intent intent, int drawable) { super(drawable);

mContext = context;

mIntent = intent;

}

@Override

public void performAction(View view) { try {

mContext.startActivity(mIntent);

} catch (ActivityNotFoundException e) { Toast.makeText(mContext,

mContext.getText(R.string.actionbar_activity_not_found), Toast.LENGTH_SHORT).show();

} } }

/*

public static abstract class SearchAction extends AbstractAction {

public SearchAction() {

super(R.drawable.actionbar_search);

} } */

}

XML Layouts:

Activity_main:-

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<ListView

android:id="@+id/in"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

android:stackFromBottom="true"

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

<EditText

android:id="@+id/title_left_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<TextView

android:id="@+id/title_right_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<TextView android:id="@+id/title_paired_devices"

<TextView android:id="@+id/title_paired_devices"

In document blutooth chat project report (Page 13-58)

Related documents