parent
10cd25385a
commit
2036b565f1
Binary file not shown.
@ -0,0 +1,245 @@
|
|||||||
|
package com.github.rosjava.android_remocons.rocon_remocon.stranger_detect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by lcp on 2021/4/19.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.widget.DrawerLayout;
|
||||||
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.animation.AccelerateInterpolator;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import com.github.rosjava.android_remocons.rocon_remocon.R;
|
||||||
|
import com.github.rosjava.android_remocons.rocon_remocon.fall_dectect.fragment.ContentFragment;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.codetail.animation.SupportAnimator;
|
||||||
|
import io.codetail.animation.ViewAnimationUtils;
|
||||||
|
import yalantis.com.sidemenu.interfaces.Resourceble;
|
||||||
|
import yalantis.com.sidemenu.interfaces.ScreenShotable;
|
||||||
|
import yalantis.com.sidemenu.model.SlideMenuItem;
|
||||||
|
import yalantis.com.sidemenu.util.ViewAnimator;
|
||||||
|
|
||||||
|
public class StrangerlDetectedActivity extends AppCompatActivity implements ViewAnimator.ViewAnimatorListener {
|
||||||
|
private DrawerLayout drawerLayout; //抽屉布局
|
||||||
|
private ActionBarDrawerToggle drawerToggle;
|
||||||
|
private List<SlideMenuItem> list = new ArrayList<>();
|
||||||
|
private ContentFragment contentFragment;
|
||||||
|
private ViewAnimator viewAnimator;
|
||||||
|
private int res = R.drawable.fall_pic2;//设置图片
|
||||||
|
private LinearLayout linearLayout;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.stranger_detect);//启动摔倒检测的界面
|
||||||
|
contentFragment = ContentFragment.newInstance(R.drawable.fall_pic2);
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.replace(R.id.content_frame, contentFragment)
|
||||||
|
.commit();
|
||||||
|
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
|
drawerLayout.setScrimColor(Color.TRANSPARENT);
|
||||||
|
linearLayout = (LinearLayout) findViewById(R.id.left_drawer);
|
||||||
|
linearLayout.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
drawerLayout.closeDrawers();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setActionBar();
|
||||||
|
createMenuList();
|
||||||
|
viewAnimator = new ViewAnimator<>(this, list, contentFragment, drawerLayout, this);
|
||||||
|
|
||||||
|
Button buttonStartDetect=(Button)findViewById(R.id.StartFallDetect);
|
||||||
|
buttonStartDetect.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
AlertDialog.Builder alertdialogbuilder=new AlertDialog.Builder(StrangerlDetectedActivity.this);
|
||||||
|
alertdialogbuilder.setMessage("您确定开启摔倒检测吗?");
|
||||||
|
alertdialogbuilder.setPositiveButton("我确定", click1);
|
||||||
|
alertdialogbuilder.setNegativeButton("再考虑一下", click2);
|
||||||
|
AlertDialog alertdialog1=alertdialogbuilder.create();
|
||||||
|
alertdialog1.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Button buttonStopDetect=(Button)findViewById(R.id.CloseFallDetect);
|
||||||
|
buttonStopDetect.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
AlertDialog.Builder alertdialogbuilder=new AlertDialog.Builder(StrangerlDetectedActivity.this);
|
||||||
|
alertdialogbuilder.setMessage("您确定关闭摔倒检测吗?");
|
||||||
|
alertdialogbuilder.setPositiveButton("我确定", click2);
|
||||||
|
alertdialogbuilder.setNegativeButton("再考虑一下", click2);
|
||||||
|
AlertDialog alertdialog1=alertdialogbuilder.create();
|
||||||
|
alertdialog1.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
private DialogInterface.OnClickListener click1=new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface arg0,int arg1)
|
||||||
|
{
|
||||||
|
Intent intent = new Intent(StrangerlDetectedActivity.this, NewListener.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private DialogInterface.OnClickListener click2=new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface arg0,int arg1)
|
||||||
|
{
|
||||||
|
arg0.cancel();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private void createMenuList() {//设置侧边菜单栏的布局和图片
|
||||||
|
SlideMenuItem menuItem0 = new SlideMenuItem(ContentFragment.CLOSE, R.drawable.icn_close);
|
||||||
|
list.add(menuItem0);
|
||||||
|
SlideMenuItem menuItem = new SlideMenuItem(ContentFragment.BUILDING, R.drawable.icn_1);
|
||||||
|
list.add(menuItem);
|
||||||
|
SlideMenuItem menuItem2 = new SlideMenuItem(ContentFragment.BOOK, R.drawable.icn_2);
|
||||||
|
list.add(menuItem2);
|
||||||
|
SlideMenuItem menuItem3 = new SlideMenuItem(ContentFragment.PAINT, R.drawable.icn_3);
|
||||||
|
list.add(menuItem3);
|
||||||
|
SlideMenuItem menuItem4 = new SlideMenuItem(ContentFragment.CASE, R.drawable.icn_4);
|
||||||
|
list.add(menuItem4);
|
||||||
|
SlideMenuItem menuItem5 = new SlideMenuItem(ContentFragment.SHOP, R.drawable.icn_5);
|
||||||
|
list.add(menuItem5);
|
||||||
|
SlideMenuItem menuItem6 = new SlideMenuItem(ContentFragment.PARTY, R.drawable.icn_6);
|
||||||
|
list.add(menuItem6);
|
||||||
|
SlideMenuItem menuItem7 = new SlideMenuItem(ContentFragment.MOVIE, R.drawable.icn_7);
|
||||||
|
list.add(menuItem7);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setActionBar() {//设置活动Bar
|
||||||
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
drawerToggle = new ActionBarDrawerToggle(
|
||||||
|
this, /* host Activity */
|
||||||
|
drawerLayout, /* DrawerLayout object */
|
||||||
|
toolbar, /* nav drawer icon to replace 'Up' caret */
|
||||||
|
R.string.drawer_open, /* "open drawer" description */
|
||||||
|
R.string.drawer_close /* "close drawer" description */
|
||||||
|
) {
|
||||||
|
|
||||||
|
/** Called when a drawer has settled in a completely closed state. */
|
||||||
|
public void onDrawerClosed(View view) {
|
||||||
|
super.onDrawerClosed(view);
|
||||||
|
linearLayout.removeAllViews();
|
||||||
|
linearLayout.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDrawerSlide(View drawerView, float slideOffset) {
|
||||||
|
super.onDrawerSlide(drawerView, slideOffset);
|
||||||
|
if (slideOffset > 0.6 && linearLayout.getChildCount() == 0)
|
||||||
|
viewAnimator.showMenuContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Called when a drawer has settled in a completely open state. */
|
||||||
|
public void onDrawerOpened(View drawerView) {
|
||||||
|
super.onDrawerOpened(drawerView);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
drawerLayout.setDrawerListener(drawerToggle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostCreate(Bundle savedInstanceState) {
|
||||||
|
super.onPostCreate(savedInstanceState);
|
||||||
|
drawerToggle.syncState();
|
||||||
|
}
|
||||||
|
|
||||||
|
//配置改变的响应
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
super.onConfigurationChanged(newConfig);
|
||||||
|
drawerToggle.onConfigurationChanged(newConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
//选择设置的菜单
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//菜单选择操作
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (drawerToggle.onOptionsItemSelected(item)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.action_settings:
|
||||||
|
return true;
|
||||||
|
// wyj
|
||||||
|
case android.R.id.home:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScreenShotable replaceFragment(ScreenShotable screenShotable, int topPosition) {
|
||||||
|
this.res = this.res == R.drawable.fall_pic2 ? R.drawable.fall_pic: R.drawable.fall_pic2;
|
||||||
|
View view = findViewById(R.id.content_frame);
|
||||||
|
int finalRadius = Math.max(view.getWidth(), view.getHeight());
|
||||||
|
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(view, 0, topPosition, 0, finalRadius);
|
||||||
|
animator.setInterpolator(new AccelerateInterpolator());
|
||||||
|
animator.setDuration(ViewAnimator.CIRCULAR_REVEAL_ANIMATION_DURATION);
|
||||||
|
|
||||||
|
findViewById(R.id.content_overlay).setBackgroundDrawable(new BitmapDrawable(getResources(), screenShotable.getBitmap()));
|
||||||
|
animator.start();
|
||||||
|
ContentFragment contentFragment = ContentFragment.newInstance(this.res);
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, contentFragment).commit();
|
||||||
|
return contentFragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScreenShotable onSwitch(Resourceble slideMenuItem, ScreenShotable screenShotable, int position) {
|
||||||
|
switch (slideMenuItem.getName()) {
|
||||||
|
case ContentFragment.CLOSE:
|
||||||
|
return screenShotable;
|
||||||
|
default:
|
||||||
|
return replaceFragment(screenShotable, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disableHomeButton() {
|
||||||
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enableHomeButton() {
|
||||||
|
getSupportActionBar().setHomeButtonEnabled(false);
|
||||||
|
drawerLayout.closeDrawers();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addViewToContainer(View view) {
|
||||||
|
linearLayout.addView(view);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,135 @@
|
|||||||
|
package com.github.rosjava.android_remocons.rocon_remocon.stranger_detect;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.github.rosjava.android_remocons.common_tools.apps.RosAppActivity;
|
||||||
|
import com.github.rosjava.android_remocons.rocon_remocon.R;
|
||||||
|
|
||||||
|
import org.ros.android.view.RosTextView;
|
||||||
|
import org.ros.node.ConnectedNode;
|
||||||
|
import org.ros.node.NodeConfiguration;
|
||||||
|
import org.ros.node.NodeMainExecutor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import std_msgs.String;
|
||||||
|
|
||||||
|
public class listener extends RosAppActivity
|
||||||
|
{
|
||||||
|
private Toast lastToast;
|
||||||
|
private ConnectedNode node;
|
||||||
|
private RosTextView<String> rosTextView;
|
||||||
|
//private subscriber sb;
|
||||||
|
|
||||||
|
public listener()
|
||||||
|
{
|
||||||
|
super("listener", "listener");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Called when the activity is first created. */
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
setDefaultMasterName(getString(R.string.default_robot));
|
||||||
|
setDashboardResource(R.id.top_bar);
|
||||||
|
setMainWindowResource(R.layout.listener);
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init(NodeMainExecutor nodeMainExecutor)
|
||||||
|
{
|
||||||
|
//String chatterTopic = remaps.get(getString(R.string.chatter_topic));
|
||||||
|
super.init(nodeMainExecutor);
|
||||||
|
|
||||||
|
/*rosTextView = (RosTextView<std_msgs.String>) findViewById(R.id.text);
|
||||||
|
rosTextView.setTopicName(getMasterNameSpace().resolve(chatterTopic).toString());
|
||||||
|
rosTextView.setMessageType(std_msgs.String._TYPE);
|
||||||
|
rosTextView.setMessageToStringCallable(new MessageCallable<String, std_msgs.String>() {
|
||||||
|
@Override
|
||||||
|
public java.lang.String call(std_msgs.String message) {
|
||||||
|
Log.e("Listener", "received a message [" + message.getData() + "]");
|
||||||
|
return message.getData();
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
try {
|
||||||
|
// Really horrible hack till I work out exactly the root cause and fix for
|
||||||
|
// https://github.com/rosjava/android_remocons/issues/47
|
||||||
|
Thread.sleep(1000);
|
||||||
|
java.net.Socket socket = new java.net.Socket(getMasterUri().getHost(), getMasterUri().getPort());
|
||||||
|
java.net.InetAddress local_network_address = socket.getLocalAddress();
|
||||||
|
socket.close();
|
||||||
|
Log.i("123", "I heard msg from ubuntu : \" \"");
|
||||||
|
// sb = new subscriber();
|
||||||
|
|
||||||
|
NodeConfiguration nodeConfiguration =
|
||||||
|
NodeConfiguration.newPublic(local_network_address.getHostAddress(), getMasterUri());
|
||||||
|
//nodeMainExecutor.execute(sb, nodeConfiguration);
|
||||||
|
|
||||||
|
/*boolean flag = true;
|
||||||
|
while(flag){
|
||||||
|
if(sb.getAlertText()==null) {
|
||||||
|
/*new AlertDialog.Builder(listener.this)
|
||||||
|
.setTitle("确认")
|
||||||
|
.setMessage("确定吗?")
|
||||||
|
.setPositiveButton("是", null)
|
||||||
|
.setNegativeButton("否", null)
|
||||||
|
.show();
|
||||||
|
flag = false;
|
||||||
|
Intent intent = new Intent(listener.this, NewListener.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
} catch(InterruptedException e) {
|
||||||
|
// Thread interruption
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Socket problem
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
|
{
|
||||||
|
menu.add(0,0,0,R.string.stop_app);
|
||||||
|
return super.onCreateOptionsMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
|
{
|
||||||
|
super.onOptionsItemSelected(item);
|
||||||
|
switch (item.getItemId()){
|
||||||
|
case 0:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Call Toast on UI thread.
|
||||||
|
// * @param message Message to show on toast.
|
||||||
|
// */
|
||||||
|
// private void showToast(final String message)
|
||||||
|
// {
|
||||||
|
// runOnUiThread(new Runnable()
|
||||||
|
// {
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
// if (lastToast != null)
|
||||||
|
// lastToast.cancel();
|
||||||
|
//
|
||||||
|
// lastToast = Toast.makeText(getBaseContext(), message, Toast.LENGTH_LONG);
|
||||||
|
// lastToast.show();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
<android.support.v4.widget.DrawerLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/drawer_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
|
||||||
|
<io.codetail.widget.RevealFrameLayout
|
||||||
|
android:id="@+id/container_frame"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/content_overlay"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/content_frame"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/CloseFallDetect"
|
||||||
|
android:layout_width="205dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|left"
|
||||||
|
android:background="@color/cardview_light_background"
|
||||||
|
android:text="关闭陌生人检测" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/StartFallDetect"
|
||||||
|
android:layout_width="205dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|right"
|
||||||
|
android:background="@color/cardview_light_background"
|
||||||
|
android:text="开启陌生人检测" />
|
||||||
|
|
||||||
|
|
||||||
|
<android.support.v7.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:minHeight="?attr/actionBarSize"
|
||||||
|
android:background="?attr/colorPrimary"/>
|
||||||
|
|
||||||
|
</io.codetail.widget.RevealFrameLayout>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scrollView"
|
||||||
|
android:scrollbarThumbVertical="@android:color/transparent"
|
||||||
|
android:layout_width="80dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="start|bottom">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/left_drawer"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="80dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:divider="@android:color/transparent"
|
||||||
|
android:background="@android:color/transparent">
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
</android.support.v4.widget.DrawerLayout>
|
Loading…
Reference in new issue