I like to start a listener; e.g. accelerometer sensor and have it stop after like 20 seconds or so. How can I force it to stop after criteria is reached (e.g 20 seconds is passed)
Here is the base code of what I have:
public class SensorActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//...
//...
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
}
@override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
getAccelerometer(event);
}
}
private void getAccelerometer(SensorEvent event) {
float[] values = event.values.clone();
float x = values[0];
float y = values[1];
float z = values[2];
//...
}
@override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@override
protected void onResume() {
super.onResume();
// register this class as a listener for the accelerometer sensor
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
}
@override
protected void onPause() {
// unregister listener
super.onPause();
sensorManager.unregisterListener(this);
}
}
All help is appreciated.
Thanks
I'm trying to have a profile page kinda of concept for one of my activities. I'm curious if this is the correct form to save the entered info and i would like it to stat whatever text they entered until next time they want to edit it ..
public class MainPage extends Activity implements OnClickListener,
OnItemSelectedListener {
TabHost th;
TextView Uotw, Aotw, Ds, Hmos, Eds, Cl;
Button go, Submit;
EditText Name, Email, Phone, Info;
@override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
Name = (EditText) findViewById(R.id.etNameOfBusiness);
Email = (EditText) findViewById(R.id.etEmail);
Phone = (EditText) findViewById(R.id.etPhone);
Info = (EditText) findViewById(R.id.etAdditionalInfo);
Submit.setOnClickListener(new OnClickListener(){
@override
public void onClick(View v) {
// TODO Auto-generated method stub
{
Log.v("EditText", Name.getText().toString());
Log.v("EditText", Email.getText().toString());
Log.v("EditText", Phone.getText().toString());
Log.v("EditText", Info.getText().toString());
}
i didn't post the whole activity because to much code thats irrelevant to the question
WaitTobi said:
I'm trying to have a profile page kinda of concept for one of my activities. I'm curious if this is the correct form to save the entered info and i would like it to stat whatever text they entered until next time they want to edit it ..
public class MainPage extends Activity implements OnClickListener,
OnItemSelectedListener {
TabHost th;
TextView Uotw, Aotw, Ds, Hmos, Eds, Cl;
Button go, Submit;
EditText Name, Email, Phone, Info;
@override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
Name = (EditText) findViewById(R.id.etNameOfBusiness);
Email = (EditText) findViewById(R.id.etEmail);
Phone = (EditText) findViewById(R.id.etPhone);
Info = (EditText) findViewById(R.id.etAdditionalInfo);
Submit.setOnClickListener(new OnClickListener(){
@override
public void onClick(View v) {
// TODO Auto-generated method stub
{
Log.v("EditText", Name.getText().toString());
Log.v("EditText", Email.getText().toString());
Log.v("EditText", Phone.getText().toString());
Log.v("EditText", Info.getText().toString());
}
i didn't post the whole activity because to much code thats irrelevant to the question
Click to expand...
Click to collapse
Omarkoopa said:
Click to expand...
Click to collapse
sorry maybe i was just rambling and not getting my real question across what I'm trying to do is have my edittexts to b able to save the info thats entered and stays there until a user would like to change it ..kind of like a profile pages you'd enter info and have it permanently save and can be viewed by other users .... i hope this make more sense
a fragment has two views a FrameLayout contains some children views ,below the FrameLayout there has a viewPager . I want to replace the fragment when there has an action like ACTION_MOVE on FrameLayout ,so I add a onTouchListener on FrameLayout but it never work,viewPager works well,and also the FrameLayout's children views has onClick event
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.hall_gift, container,
false);
frameLayout = (FrameLayout)view.findViewById(R.id.fans_body_title);
frameLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN){
Log.i(TAG,"ACTION DOWN");
}
return false;
}
});
return view;
}
Click to expand...
Click to collapse
HUAWEI Awareness Kit provides your app with the ability to obtain contextual information including users' current time, location, behavior, audio device status, ambient light, weather, and nearby beacons.
There are two types of API in awareness Kit - Capture API and Barrier API. The Capture API allows the app to request the current user status and the Barrier API allows the app to set a combination of contextual conditions. In this article we are explaining about Location Awareness, Headset Awareness, Ambient Light Awareness and Bluetooth Car Stereo Awareness.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Steps for developing capture capabilities
1. Obtain the Capture Client object of HUAWEI Awareness Kit.
2. Call the respective query capability API through the Capture Client object to obtain the user's context.
3. Enable your app to listen for the result returned by HUAWEI Awareness Kit for further processing.
Steps for developing barrier capabilities
1. Define the barrier.
2. Define PendingIntent that will be triggered upon a barrier status change, for example, to send a broadcast, and create a broadcast receiver to receive the broadcast.
3. Define the label for the barrier and add the barrier.
4. Define the broadcast receiver to listen for the barrier event for further processing.
In this article we are explaining about Location Awareness, Headset Awareness, Ambient Light Awareness and Bluetooth Car Stereo Awareness.
Headset Awareness
For calling Headset Awareness capability we have to assign the given permissions in the manifest file.
Code:
<uses-permission android:name="android.permission.BLUETOOTH" />
Capture API
We can use the Capture API to detect whether the user currently has their headset connected or disconnected.
To get the headset status from the Capture API we need to call the getHeadsetStatus() method - this will return an instance of the HeadsetStatusResponse class that if successful, will contain information about the devices current headphone status.
Code:
private void getHeadsetStatus() {
// Use the getHeadsetStatus API to get headset connection status.
Awareness.getCaptureClient(this)
.getHeadsetStatus()
.addOnSuccessListener(new OnSuccessListener<HeadsetStatusResponse>() {
@Override
public void onSuccess(HeadsetStatusResponse headsetStatusResponse) {
HeadsetStatus headsetStatus = headsetStatusResponse.getHeadsetStatus();
int status = headsetStatus.getStatus();
String statusStr = "Headset is " +
(status == HeadsetStatus.CONNECTED ? "connected" : "disconnected");
headset_status_capture.setText(statusStr);
if(status==HeadsetStatus.CONNECTED) {
headset_status_capture.setTextColor(getColor(R.color.green));
headset_status_image.setImageDrawable(getDrawable(R.drawable.ic_headset_connected));
}else{
headset_status_capture.setTextColor(getColor(R.color.red));
headset_status_image.setImageDrawable(getDrawable(R.drawable.ic_volume_up));
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
headset_status_capture.setTextColor(getColor(R.color.red));
headset_status_capture.setText("Failed to get the headset capture.");
}
});
}
Barrier API
The given example illustrates how to develop a barrier triggered by the connecting condition. That is, the barrier will be triggered when the headset is connected or plugged in.
Code:
public class HeadsetBarrierActivity extends AppCompatActivity {
private TextView headset_status_barrier;
private ImageView headset_status_barrier_image;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.headset_barrier_activity);
headset_status_barrier=findViewById(R.id.headset_status_barrier);
headset_status_barrier_image=findViewById(R.id.headset_status_barrier_image);
// define PendingIntent that will be triggered upon a barrier status change.
final String BARRIER_RECEIVER_ACTION = getApplication().getPackageName() + "HEADSET_BARRIER_RECEIVER_ACTION";
Intent intent = new Intent(BARRIER_RECEIVER_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
HeadsetBarrierReceiver barrierReceiver = new HeadsetBarrierReceiver();
registerReceiver(barrierReceiver, new IntentFilter(BARRIER_RECEIVER_ACTION));
addbarrier();
}
private void addbarrier() {
//define the barrier
AwarenessBarrier headsetBarrier = HeadsetBarrier.keeping(HeadsetStatus.CONNECTED);
//define the label for the barrier and add the barrier
String headsetBarrierLabel = "headset keeping connected barrier";
//add the barrier
BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
BarrierUpdateRequest request = builder.addBarrier(headsetBarrierLabel, headsetBarrier,pendingIntent).build();
Awareness.getBarrierClient(this).updateBarriers(request)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(), "add headset keeping barrier connected success", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), "add headset keeping barrier connected failed", Toast.LENGTH_SHORT).show();
}
});
}
// define the broadcast receiver to listen for the barrier event.
private class HeadsetBarrierReceiver extends BroadcastReceiver {
private static final String TAG ="Headset Barrier" ;
@Override
public void onReceive(Context context, Intent intent) {
BarrierStatus barrierStatus = BarrierStatus.extract(intent);
String label = barrierStatus.getBarrierLabel();
switch(barrierStatus.getPresentStatus()) {
case BarrierStatus.TRUE:
headset_status_barrier.setTextColor(getColor(R.color.green));
headset_status_barrier.setText("Headset is connected");
headset_status_barrier_image.setImageDrawable(getDrawable(R.drawable.ic_headset_connected));
break;
case BarrierStatus.FALSE:
headset_status_barrier.setTextColor(getColor(R.color.red));
headset_status_barrier.setText("Headset is disconnected");
headset_status_barrier_image.setImageDrawable(getDrawable(R.drawable.ic_volume_up));
break;
case BarrierStatus.UNKNOWN:
headset_status_barrier.setTextColor(getColor(R.color.red));
headset_status_barrier.setText("unknown");
break;
}
}
}
}
Location Awareness
For calling Location Awareness capability we have to assign the given permissions in the manifest file.
Code:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
Capture API
We can use the Capture API to Obtains the latitude and longitude of the current location.
To get the location from the Capture API we need to call the getLocation() method - this will return an instance of the LocationResponse class that if successful, will contain information about the location.
Code:
private void getLocation() {
Awareness.getCaptureClient(this).getLocation()
.addOnSuccessListener(new OnSuccessListener<LocationResponse>() {
@Override
public void onSuccess(LocationResponse locationResponse) {
Location location = locationResponse.getLocation();
Utils.setHomeLatitude(location.getLatitude());
Utils.setHomeLongitude(location.getLongitude());
location_details_capture.setText("Longitude:" + location.getLongitude()
+ ",Latitude:" + location.getLatitude());
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
location_details_capture.setText("Failed to get the location.");
}
});
}
Barrier API
Given an example in which a barrier is triggered by the enter condition. That is, the barrier will be triggered when a user enters his house.
Code:
public class LocationBarrierActivity extends AppCompatActivity {
private TextView location_details_barrier;
private ImageView location_image_barrier;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_barrier_activity);
location_details_barrier=findViewById(R.id.location_details_barrier);
location_image_barrier=findViewById(R.id.location_image_barrier);
// define PendingIntent that will be triggered upon a barrier status change.
final String BARRIER_RECEIVER_ACTION = getApplication().getPackageName() + "LOCATION_BARRIER_RECEIVER_ACTION";
Intent intent = new Intent(BARRIER_RECEIVER_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
LocationBarrierReceiver barrierReceiver = new LocationBarrierReceiver();
registerReceiver(barrierReceiver, new IntentFilter(BARRIER_RECEIVER_ACTION));
addbarrier(this);
}
private void addbarrier(Context context) {
//Home latitude and longitude
double latitude = Utils.getHomeLatitude();
double longitude = Utils.getHomeLongitude();
double radius = 200;
//define the barrier
AwarenessBarrier enterBarrier = LocationBarrier.enter(latitude, longitude, radius);
//define the label for the barrier and add the barrier
String locationBarrierLabel = "Home enter barrier";
//add the barrier
BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
BarrierUpdateRequest request = builder.addBarrier(locationBarrierLabel, enterBarrier,pendingIntent).build();
Awareness.getBarrierClient(context).updateBarriers(request)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(), "add Home enter barrier barrier success", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), "add Home enter barrier barrier failed", Toast.LENGTH_SHORT).show();
}
});
}
// define the broadcast receiver to listen for the barrier event
class LocationBarrierReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
BarrierStatus barrierStatus = BarrierStatus.extract(intent);
String label = barrierStatus.getBarrierLabel();
switch(barrierStatus.getPresentStatus()) {
case BarrierStatus.TRUE:
location_details_barrier.setText("You are at Home");
break;
case BarrierStatus.FALSE:
location_details_barrier.setText("You are away from home");
break;
case BarrierStatus.UNKNOWN:
location_details_barrier.setText("unknown");
break;
}
}
}
}
Ambient Light Awareness
Capture API
We can use the Capture API to obtain the illuminance of the environment where the device is located.
To get the light intensity from the Capture API we need to call the getLightIntensity () method - this will return us and instance of the AmbientLightResponse class that if successful, will contain information about the users light intensity.
Code:
private void getLightIntensity() {
Awareness.getCaptureClient(this).getLightIntensity()
.addOnSuccessListener(new OnSuccessListener<AmbientLightResponse>() {
@Override
public void onSuccess(AmbientLightResponse ambientLightResponse) {
AmbientLightStatus ambientLightStatus = ambientLightResponse.getAmbientLightStatus();
ambientLight_capture.setTextColor(getColor(R.color.green));
ambientLight_capture.setText("Light intensity is " + ambientLightStatus.getLightIntensity() + " lux");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
ambientLight_capture.setTextColor(getColor(R.color.red));
ambientLight_capture.setText("Failed to get the light intensity.");
}
});
}
Barrier API
We can use the Barrier API to set the ambient light barrier. For example, we can set the application to enable the auto flashlight function when the luminance is less than 20 lux. You can see the article "HMS Ambient Light Awareness for building an Auto Flash Light Application” for the reference.
Code:
public class AmbientLightBarrierActivity extends AppCompatActivity {
private TextView ambientLight_barrier;
private ImageView ambientLight_barrier_image;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ambient_light_barrier_activity);
ambientLight_barrier=findViewById(R.id.ambient_light_barrier);
ambientLight_barrier_image=findViewById(R.id.ambient_light_barrier_image);
// define PendingIntent that will be triggered upon a barrier status change.
final String BARRIER_RECEIVER_ACTION = getApplication().getPackageName() + "LIGHT_BARRIER_RECEIVER_ACTION";
Intent intent = new Intent(BARRIER_RECEIVER_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
LightBarrierReceiver barrierReceiver = new LightBarrierReceiver();
registerReceiver(barrierReceiver, new IntentFilter(BARRIER_RECEIVER_ACTION));
addbarrier(this);
}
private void addbarrier(Context context) {
//define lux here
final float luxValue = 60.0f;
//define the barrier
AwarenessBarrier lightAboveBarrier = AmbientLightBarrier.above(luxValue);
//define the label for the barrier and add the barrier
String lightBarrierLabel = "light above barrier";
//add the barrier
BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
BarrierUpdateRequest request = builder.addBarrier(lightBarrierLabel, lightAboveBarrier,pendingIntent).build();
Awareness.getBarrierClient(context).updateBarriers(request)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(), "add light abov barrier success", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), "add light above barrier failed", Toast.LENGTH_SHORT).show();
}
});
}
// define the broadcast receiver to listen for the barrier event.
class LightBarrierReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
BarrierStatus barrierStatus = BarrierStatus.extract(intent);
String label = barrierStatus.getBarrierLabel();
switch(barrierStatus.getPresentStatus()) {
case BarrierStatus.TRUE:
ambientLight_barrier.setTextColor(getColor(R.color.green));
ambientLight_barrier.setText("Room light is sufficient");
break;
case BarrierStatus.FALSE:
ambientLight_barrier.setTextColor(getColor(R.color.red));
ambientLight_barrier.setText("Room light is minimal");
break;
case BarrierStatus.UNKNOWN:
ambientLight_barrier.setTextColor(getColor(R.color.red));
ambientLight_barrier.setText("Unknown");
break;
}
}
}
}
Bluetooth Car Stereo Awareness
For calling Bluetooth Car Stereo Awareness capability we have to assign the given permissions in the manifest file.We have to assign the given permissions in the manifest file.
Code:
<uses-permission android:name="android.permission.BLUETOOTH" />
Capture API
We can use the Capture API to detect whether The Bluetooth car stereo is currently connected or disconnected.
To get the Bluetooth car stereo status from the Capture API we need to call the getBluetoothStatus(0) method - this will return an instance of the BluetoothStatusResponse class that if successful, will contain information about the The Bluetooth car stereo status.
Code:
private void getBluetoothStatus() {
int deviceType = 0; // Value 0 indicates a Bluetooth car stereo.
Awareness.getCaptureClient(this).getBluetoothStatus(deviceType)
.addOnSuccessListener(new OnSuccessListener<BluetoothStatusResponse>() {
@Override
public void onSuccess(BluetoothStatusResponse bluetoothStatusResponse) {
BluetoothStatus bluetoothStatus = bluetoothStatusResponse.getBluetoothStatus();
int status = bluetoothStatus.getStatus();
String statusStr = "The Bluetooth car stereo is " +
(status == BluetoothStatus.CONNECTED ? "connected" : "disconnected");
bluetooth_status_capture.setText(statusStr);
if(status== BluetoothStatus.CONNECTED) {
bluetooth_status_capture.setTextColor(getColor(R.color.green));
bluetooth_status_image.setImageDrawable(getDrawable(R.drawable.bluetooth_connected));
}else{
bluetooth_status_capture.setTextColor(getColor(R.color.red));
bluetooth_status_image.setImageDrawable(getDrawable(R.drawable.bluetooth_disconnected));
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
bluetooth_status_capture.setText("Failed to get Bluetooth status.");
}
});
}
Barrier API
The following example illustrates how to develop a barrier triggered by the connecting condition. That is, the barrier will be triggered when the Bluetooth car stereo is connected.
Code:
public class BluetoothBarrierActivity extends AppCompatActivity {
private TextView bluetooth_status_barrier;
private ImageView bluetooth_status_barrier_image;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bluetooth_barrier_activity);
bluetooth_status_barrier=findViewById(R.id.bluetooth_status_barrier);
bluetooth_status_barrier_image=findViewById(R.id.bluetooth_status_barrier_image);
// define PendingIntent that will be triggered upon a barrier status change.
final String BARRIER_RECEIVER_ACTION = getApplication().getPackageName() + "BLUETOOTH_BARRIER_RECEIVER_ACTION";
Intent intent = new Intent(BARRIER_RECEIVER_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
BluetoothBarrierReceiver barrierReceiver = new BluetoothBarrierReceiver();
registerReceiver(barrierReceiver, new IntentFilter(BARRIER_RECEIVER_ACTION));
addbarrier(this);
}
private void addbarrier(Context context) {
final int deviceType = 0; // Value 0 indicates a Bluetooth car stereo.
//define the barrier
AwarenessBarrier connectingBarrier = BluetoothBarrier.connecting(deviceType);
String bluetoothBarrierLabel = "bluetooth connecting barrier";
//add the barrier
BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
BarrierUpdateRequest request = builder.addBarrier(bluetoothBarrierLabel, connectingBarrier,pendingIntent).build();
Awareness.getBarrierClient(context).updateBarriers(request)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(), "add bluetooth connecting barrier success", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), "add bluetooth connecting barrier failed", Toast.LENGTH_SHORT).show();
}
});
}
// define the broadcast receiver to listen for the barrier event.
class BluetoothBarrierReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
BarrierStatus barrierStatus = BarrierStatus.extract(intent);
String label = barrierStatus.getBarrierLabel();
switch(barrierStatus.getPresentStatus()) {
case BarrierStatus.TRUE:
bluetooth_status_barrier.setTextColor(getColor(R.color.green));
bluetooth_status_barrier.setText("The Bluetooth car stereo is connected");
bluetooth_status_barrier_image.setImageDrawable(getDrawable(R.drawable.bluetooth_connected));
break;
case BarrierStatus.FALSE:
bluetooth_status_barrier.setTextColor(getColor(R.color.red));
bluetooth_status_barrier.setText("The Bluetooth car stereo is not connected");
bluetooth_status_barrier_image.setImageDrawable(getDrawable(R.drawable.bluetooth_disconnected));
break;
case BarrierStatus.UNKNOWN:
bluetooth_status_barrier.setText("Unknown");
break;
}
}
}
}
References:
https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/awareness-introduction
public class MainActivity extends Activity {
MyView myView;
Button mButtonAdd;
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myView = new MyView(this);
myView.setBackgroundColor(Color.WHITE);
setContentView(R.layout.activity_main);
mButtonAdd = findViewById(R.id.buttonAdd);
mButtonAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// do something here
setContentView(myView);
}
});
}
public class MyView extends View {
...
}
}
I have a button, when clicked it should show a view. However, the button seems to disappear 'under' the view shown on click of the button. How to maintain the button fixed, also able to add a view multiple times?