Started working on RadarView
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout 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:orientation="vertical"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
@@ -12,8 +13,7 @@
|
||||
android:id="@+id/gridLayout1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:columnCount="2" >
|
||||
|
||||
<TextView
|
||||
@@ -21,18 +21,19 @@
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_row="0"
|
||||
android:text="Bluetooth LE:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvBluetoothLe"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="1"
|
||||
android:layout_gravity="left"
|
||||
android:layout_marginLeft="28dp"
|
||||
android:layout_row="0"
|
||||
android:gravity="right"
|
||||
android:text="@string/not_supported"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -41,38 +42,64 @@
|
||||
android:layout_gravity="left"
|
||||
android:layout_row="1"
|
||||
android:text="Bluetooth:"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvBluetoothStatus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="1"
|
||||
android:layout_gravity="right|bottom"
|
||||
android:layout_marginLeft="28dp"
|
||||
android:layout_row="1"
|
||||
android:gravity="right"
|
||||
android:text="@string/off"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textSize="12sp" />
|
||||
</GridLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/upperSepparator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_below="@id/gridLayout1"
|
||||
android:background="@android:color/holo_blue_dark" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/upperSepparator" />
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/empty"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/upperSepparator"
|
||||
android:text="@string/no_data" />
|
||||
<LinearLayout
|
||||
android:id="@+id/listContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight=".3"
|
||||
android:orientation="vertical" >
|
||||
|
||||
</RelativeLayout>
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text="@string/no_data" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/lowerSepparator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@android:color/holo_blue_dark" />
|
||||
|
||||
<uk.co.alt236.btlescan.views.RadarView
|
||||
android:id="@+id/radarView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight=".7">
|
||||
</uk.co.alt236.btlescan.views.RadarView>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -5,6 +5,7 @@ import uk.co.alt236.btlescan.R;
|
||||
import uk.co.alt236.btlescan.adapters.LeDeviceListAdapter;
|
||||
import uk.co.alt236.btlescan.util.BluetoothLeScanner;
|
||||
import uk.co.alt236.btlescan.util.BluetoothUtils;
|
||||
import uk.co.alt236.btlescan.views.RadarView;
|
||||
import android.app.ListActivity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
@@ -21,11 +22,12 @@ import butterknife.InjectView;
|
||||
public class MainActivity extends ListActivity {
|
||||
@InjectView(R.id.tvBluetoothLe) TextView mTvBluetoothLeStatus;
|
||||
@InjectView(R.id.tvBluetoothStatus) TextView mTvBluetoothStatus;
|
||||
|
||||
@InjectView(R.id.radarView) RadarView mRadarView;
|
||||
|
||||
private BluetoothUtils mBluetoothUtils;
|
||||
private BluetoothLeScanner mScanner;
|
||||
private LeDeviceListAdapter mLeDeviceListAdapter;
|
||||
|
||||
|
||||
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
|
||||
@Override
|
||||
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
|
||||
@@ -64,7 +66,6 @@ public class MainActivity extends ListActivity {
|
||||
mScanner = new BluetoothLeScanner(mLeScanCallback, mBluetoothUtils);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
|
||||
87
sample_app/src/uk/co/alt236/btlescan/views/RadarView.java
Normal file
87
sample_app/src/uk/co/alt236/btlescan/views/RadarView.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package uk.co.alt236.btlescan.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
public class RadarView extends View{
|
||||
private Paint mRadarBackgroundPaint;
|
||||
private Paint mViewBackgroundPaint;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
|
||||
public RadarView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mRadarBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mRadarBackgroundPaint.setColor(0xff101010);
|
||||
mRadarBackgroundPaint.setStyle(Style.FILL);
|
||||
|
||||
mViewBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mViewBackgroundPaint.setColor(Color.BLACK);
|
||||
mViewBackgroundPaint.setStyle(Style.FILL);
|
||||
}
|
||||
|
||||
public RadarView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public RadarView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
private int getSmallestDimension(){
|
||||
if(mWidth > mHeight){
|
||||
return mHeight;
|
||||
} else {
|
||||
return mWidth;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSizeChanged (int w, int h, int oldw, int oldh){
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
Log.d("TAG", "~ ONDRAW!");
|
||||
|
||||
Log.d("TAG", "~ getLeft! " + getLeft());
|
||||
Log.d("TAG", "~ getTop! " + getTop());
|
||||
Log.d("TAG", "~ getRight! " + getRight());
|
||||
Log.d("TAG", "~ getBottom! " + getBottom());
|
||||
Log.d("TAG", "~ width! " + mWidth);
|
||||
Log.d("TAG", "~ height! " + mHeight);
|
||||
|
||||
final int smallestDim = getSmallestDimension();
|
||||
|
||||
|
||||
canvas.drawRect(
|
||||
getLeft(),
|
||||
getTop(),
|
||||
getRight(),
|
||||
getBottom(),
|
||||
mViewBackgroundPaint);
|
||||
|
||||
canvas.drawCircle(
|
||||
getLeft() + (mWidth / 2f),
|
||||
getTop() + (mHeight / 2f),
|
||||
smallestDim / 2f,
|
||||
mRadarBackgroundPaint);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user