0

I am new in learning Android and so far I have been focused on functionality, but now I am starting to work with layouts.

Issue:-- My app has a button and on its click, I send a sms to registered number.But as soon as the button is clicked I want change the user's phone screen background color to red and same with the front notification led.(As soon as the user pushes the button, the app finishes....so my idea is , user should know that button was pushed and message is sent. so the background of scrren should be in alert position.)

Is there a way to do this? I was searching net and found that notification led behaves different for different manufacturers.Is there any generic way to do this, so that the apps behave same in all android phone brands?? Any code snippet or any hits will be highly appreciated.

indi mars
  • 133
  • 3
  • 8

2 Answers2

1
    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/layout"
    android:layout_height="match_parent"
   >
<TextView
        android:id="@+id/save"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@drawable/button"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="10dp"
        android:text="Save"
        android:gravity="center"
        android:textSize="18sp"
        android:textColor="#ffffff"
        android:layout_marginLeft="10dp"/>
</LinearLayout>

In the activity:

LinearLayout layout= (LinearLayout) findViewById(R.id.layout);
TextView save=(TextView) findViewById(R.id.save);

 save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                layout.setBackgroundColor(Color.rgb(255,32,32));
            }
        });
Miriana Itani
  • 865
  • 9
  • 25
0

The notification LEDs are not a standard feature on Android. That said, you can't have a single method which will handle the blinking for all Android devices.

An way to solve this issue is to create a generic method, which will check the brand of the phone, and use the appropriated method to blink the LED. Something like:

private void blinkLED() {
    String man = android.os.Build.MANUFACTURER; 

    if (man.equals("SAMSUNG")) {
        // Do Samsung LED blinking here.
    }
    else if (man.equals("HTC")) {
        // Do HTC LED blinking here.
    }
    else {
        // ...
    }
}

And to change your background color, get the reference for your root layout, and call the setBackgroundColor method, which all objects who inherits from android View have.

RelativeLayout lv = (RelativeLayout) findViewById(R.id.relativelayout);
Button bt = (Button) findViewById(R.id.button);

bt.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View view) {
        lv.setBackgroundColor(Color.rgb(204,0,0));
    }
});

Edit: From what I could understand, you want to notify the user that your message was sent. I can suggest an easy way for you to do it. Use the ProgressDialog and AlertDialog classes. Use it if you want to show the progress of the sending process to the user and notify when the process is done. To start a progress dialog is simple, just add this line:

// this refers to a Context, the second argument is the title of the dialog, the third argument is the body message of the dialog, the fourth argument is whether your dialog is indeterminate or not, the last argument tells if your dialog can be canceled or not.
ProgressDialog pd = ProgressDialog.show(this,"Title of dialog","(Body message) Sending message",true,false); 

And to cancel it, or disable it, just call:

pd.dismiss();

And to show an AlertDialog, just do the following.

new AlertDialog.Builder(getApplicationContext())
                                .setTitle("Title")
                                .setMessage("Your message was sent!")
                                .setPositiveButton("OK",null)
                                .show();

That should do what you want.

Mauker
  • 11,237
  • 7
  • 58
  • 76
  • Thanks for your response. I want to change the screen color not my app's background. Actually as soon as the user push the button, the app finishes....so my idea is , user should know that button was pushed and message is sent. – indi mars Aug 03 '15 at 00:27
  • Thanks for your suggestion, although I am not supposed to change requirements. I can show notification also, but requirement is to alert user by turning his main screen background color. I am just looking for its feasibility. – indi mars Aug 03 '15 at 11:34
  • Can you draw a mockup of the behavior you want? – Mauker Aug 03 '15 at 12:26
  • Its a kind of security app(hidden). So the button click is something like power button click 3 times and alert becomes active. Now whether the alert got active or not....user should have an idea, for this, the screen should show some indications. Notifications are already ruled out.I hope I am able to clarify. – indi mars Aug 04 '15 at 00:17