Añadir botón cerrar app cuando está en modo de fullscreen en Android Wear
Last active
November 26, 2016 14:06
-
-
Save webserveis/49dcce9c36300cdf0283ffa13400f264 to your computer and use it in GitHub Desktop.
Add Dismiss Action in Android Wear
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<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" | |
tools:context=".MainActivity"> | |
<TextView | |
android:id="@+id/text" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Long Press to dismiss" /> | |
<android.support.wearable.view.DismissOverlayView | |
android:id="@+id/dismiss_overlay" | |
android:layout_height="match_parent" | |
android:layout_width="match_parent"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.webserveis.app.testandroidwear; | |
import android.nfc.Tag; | |
import android.os.Bundle; | |
import android.support.wearable.activity.WearableActivity; | |
import android.support.wearable.view.BoxInsetLayout; | |
import android.support.wearable.view.DismissOverlayView; | |
import android.util.Log; | |
import android.view.GestureDetector; | |
import android.view.MotionEvent; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.Locale; | |
public class MainActivity extends WearableActivity { | |
private static final SimpleDateFormat AMBIENT_DATE_FORMAT = | |
new SimpleDateFormat("HH:mm", Locale.US); | |
private static final String TAG = MainActivity.class.getSimpleName(); | |
private DismissOverlayView mDismissOverlay; | |
private GestureDetector mDetector; | |
private BoxInsetLayout mContainerView; | |
private TextView mTextView; | |
private TextView mClockView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
setAmbientEnabled(); | |
// Obtain the DismissOverlayView element | |
mDismissOverlay = (DismissOverlayView) findViewById(R.id.dismiss_overlay); | |
mDismissOverlay.setIntroText("Long Press to dismiss"); | |
mDismissOverlay.showIntroIfNecessary(); | |
// Configure a gesture detector | |
mDetector = new GestureDetector(MainActivity.this, new GestureDetector.SimpleOnGestureListener() { | |
@Override | |
public boolean onDown(MotionEvent ev) { | |
float x = ev.getX(); | |
float y = ev.getY(); | |
Log.d(TAG, "onDown at: (" + x + "," + y + ")"); | |
return true; | |
} | |
public void onLongPress(MotionEvent ev) { | |
float x = ev.getX(); | |
float y = ev.getY(); | |
mDismissOverlay.show(); | |
Log.d(TAG, "onLongPress at: (" + x + "," + y + ")"); | |
} | |
@Override | |
public boolean onDoubleTap(MotionEvent ev) { | |
float x = ev.getX(); | |
float y = ev.getY(); | |
Log.d(TAG, "onDoubleTap at: (" + x + "," + y + ")"); | |
//mDismissOverlay.show(); | |
return true; | |
} | |
}); | |
mContainerView = (BoxInsetLayout) findViewById(R.id.container); | |
mTextView = (TextView) findViewById(R.id.text); | |
mClockView = (TextView) findViewById(R.id.clock); | |
Button myButton1 = (Button) findViewById(R.id.button2); | |
if (myButton1 != null) { | |
myButton1.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
//TODO click Event | |
Toast.makeText(MainActivity.this, "onClick", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
} | |
// Capture long presses | |
@Override | |
public boolean onTouchEvent(MotionEvent ev) { | |
return mDetector.onTouchEvent(ev) || super.onTouchEvent(ev); | |
} | |
@Override | |
public void onEnterAmbient(Bundle ambientDetails) { | |
super.onEnterAmbient(ambientDetails); | |
updateDisplay(); | |
} | |
@Override | |
public void onUpdateAmbient() { | |
super.onUpdateAmbient(); | |
updateDisplay(); | |
} | |
@Override | |
public void onExitAmbient() { | |
updateDisplay(); | |
super.onExitAmbient(); | |
} | |
private void updateDisplay() { | |
if (isAmbient()) { | |
mContainerView.setBackgroundColor(getResources().getColor(android.R.color.black)); | |
mTextView.setTextColor(getResources().getColor(android.R.color.white)); | |
mClockView.setVisibility(View.VISIBLE); | |
mClockView.setText(AMBIENT_DATE_FORMAT.format(new Date())); | |
} else { | |
mContainerView.setBackground(null); | |
mTextView.setTextColor(getResources().getColor(android.R.color.black)); | |
mClockView.setVisibility(View.GONE); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Light"> | |
<item name="android:windowSwipeToDismiss">false</item> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment