parent
c39174e409
commit
3601b83c9f
@ -0,0 +1,38 @@
|
||||
package com.example.adapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.example.smartglasses.R;
|
||||
import com.xuexiang.xui.adapter.recyclerview.BaseRecyclerAdapter;
|
||||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
|
||||
import com.xuexiang.xui.adapter.simple.AdapterItem;
|
||||
import com.xuexiang.xui.widget.imageview.ImageLoader;
|
||||
import com.xuexiang.xui.widget.imageview.RadiusImageView;
|
||||
|
||||
public class CommonGridAdapter extends BaseRecyclerAdapter<AdapterItem> {
|
||||
private boolean mIsCircle;
|
||||
|
||||
public CommonGridAdapter(boolean isCircle) {
|
||||
super();
|
||||
mIsCircle = isCircle;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getItemLayoutId(int viewType) {
|
||||
return R.layout.adapter_common_grid_item;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void bindData(@NonNull RecyclerViewHolder holder, int position, AdapterItem item) {
|
||||
if (item != null) {
|
||||
RadiusImageView imageView = holder.findViewById(R.id.riv_item);
|
||||
imageView.setCircle(mIsCircle);
|
||||
ImageLoader.get().loadImage(imageView, item.getIcon());
|
||||
|
||||
holder.text(R.id.tv_title, item.getTitle().toString().substring(0, 1));
|
||||
holder.text(R.id.tv_sub_title, item.getTitle());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.example.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.smartglasses.R;
|
||||
import com.example.smartglasses.databinding.FragmentDeviseBinding;
|
||||
|
||||
public class DeviseFragment extends Fragment {
|
||||
|
||||
FragmentDeviseBinding binding;
|
||||
private String jumpPage;
|
||||
private static final String ARG_PARAM1 = "jumpPage";
|
||||
|
||||
public DeviseFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
jumpPage = getArguments().getString(ARG_PARAM1);
|
||||
Log.i("devise", "onCreate: 在碎片中获得devise" + jumpPage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentDeviseBinding.inflate(inflater, container, false);
|
||||
binding.cardView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.i("devise", "onClick: 我点击了");
|
||||
if (jumpPage.equals("location")) {
|
||||
LocationFragment fragment = new LocationFragment();
|
||||
getFragmentManager().beginTransaction().replace(R.id.frag_layout, fragment).commit();
|
||||
} else if (jumpPage.equals("trace")) {
|
||||
TraceFragment fragment = new TraceFragment();
|
||||
getFragmentManager().beginTransaction().replace(R.id.frag_layout, fragment).commit();
|
||||
}
|
||||
}
|
||||
});
|
||||
return binding.getRoot();
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package com.example.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.example.activity.BarActivity;
|
||||
import com.example.smartglasses.MainActivity;
|
||||
import com.example.smartglasses.R;
|
||||
import com.example.otherclass.StereoBMUtil;
|
||||
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
|
||||
|
||||
|
||||
private ImageView imageViewResult;
|
||||
private StereoBMUtil stereoBMUtil;
|
||||
private TextView textView;
|
||||
private Bitmap leftBitmap;
|
||||
private Bitmap rightBitmap;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
}
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view=inflater.inflate(R.layout.fragment_home, container, false);
|
||||
//初始化
|
||||
if (OpenCVLoader.initDebug()) {
|
||||
Log.d("TAG", "OpenCVLoader初始化成功");
|
||||
}
|
||||
|
||||
stereoBMUtil = new StereoBMUtil();
|
||||
ImageView imageViewLeft = view.findViewById(R.id.imageViewLeft);
|
||||
ImageView imageViewRight = view.findViewById(R.id.imageViewRight);
|
||||
imageViewResult = view.findViewById(R.id.imageViewResult);
|
||||
textView = view.findViewById(R.id.result_tv);
|
||||
Button button = view.findViewById(R.id.button);
|
||||
Button button1 = view.findViewById(R.id.button1);
|
||||
|
||||
// 加载图片
|
||||
try {
|
||||
leftBitmap = BitmapFactory.decodeStream(getContext().getAssets().open("Left3.bmp"));
|
||||
rightBitmap = BitmapFactory.decodeStream(getContext().getAssets().open("Right3.bmp"));
|
||||
imageViewLeft.setImageBitmap(leftBitmap);
|
||||
imageViewRight.setImageBitmap(rightBitmap);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 执行StereoBM算法
|
||||
button.setOnClickListener(v -> {
|
||||
try {
|
||||
Bitmap result = stereoBMUtil.compute(leftBitmap, rightBitmap);
|
||||
imageViewResult.setImageBitmap(result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
// 打开相机activity
|
||||
button1.setOnClickListener(v -> {
|
||||
// Intent intent = new Intent(MainActivity.this, CameraActivity.class);
|
||||
Log.d("Test", "启动C活动");
|
||||
BarActivity activity = (BarActivity) getActivity();
|
||||
// startActivity(intent);
|
||||
activity.setCurrentFragment(4);
|
||||
});
|
||||
|
||||
// 点击计算后的图片,获取三维坐标数据
|
||||
imageViewResult.setOnTouchListener((v, event) -> {
|
||||
// 获取触摸点的坐标 x, y
|
||||
float x = event.getX();
|
||||
float y = event.getY();
|
||||
// 目标点的坐标
|
||||
float[] dst = new float[2];
|
||||
Matrix imageMatrix = imageViewResult.getImageMatrix();
|
||||
Matrix inverseMatrix = new Matrix();
|
||||
imageMatrix.invert(inverseMatrix);
|
||||
inverseMatrix.mapPoints(dst, new float[]{x, y});
|
||||
int dstX = (int) dst[0];
|
||||
int dstY = (int) dst[1];
|
||||
// 获取该点的三维坐标
|
||||
double[] c = stereoBMUtil.getCoordinate(dstX, dstY);
|
||||
String s = String.format("点(%d, %d) 三维坐标:[%.2f, %.2f, %.2f]", dstX, dstY, c[0], c[1], c[2]);
|
||||
// Log.d(TAG, s);
|
||||
textView.setText(s);
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.example.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.smartglasses.R;
|
||||
|
||||
|
||||
public class LocationFragment extends Fragment {
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
public LocationFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment LocationFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static LocationFragment newInstance(String param1, String param2) {
|
||||
LocationFragment fragment = new LocationFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_location, container, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.example.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.adapter.CommonGridAdapter;
|
||||
import com.example.smartglasses.R;
|
||||
import com.example.smartglasses.databinding.FragmentMineBinding;
|
||||
import com.xuexiang.xui.adapter.simple.AdapterItem;
|
||||
import com.xuexiang.xui.utils.ResUtils;
|
||||
import com.xuexiang.xui.utils.WidgetUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MineFragment extends Fragment {
|
||||
RecyclerView recyclerHead;
|
||||
FragmentMineBinding binding;
|
||||
private CommonGridAdapter mGridAdapter;
|
||||
|
||||
public MineFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentMineBinding.inflate(inflater, container, false);
|
||||
recyclerHead = binding.recyclerHead;
|
||||
initTools();
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
public void initTools(){
|
||||
WidgetUtils.initGridRecyclerView(recyclerHead, 4, 0);
|
||||
recyclerHead.setAdapter(mGridAdapter = new CommonGridAdapter(true));
|
||||
mGridAdapter.refresh(getGridItems(this.getActivity(),R.array.grid_titles_entry,R.array.grid_icons_entry));
|
||||
}
|
||||
|
||||
private static List<AdapterItem> getGridItems(Context context, int titleArrayId, int iconArrayId) {
|
||||
List<AdapterItem> list = new ArrayList<>();
|
||||
String[] titles = ResUtils.getStringArray(titleArrayId);
|
||||
Drawable[] icons = ResUtils.getDrawableArray(context, iconArrayId);
|
||||
for (int i = 0; i < titles.length; i++) {
|
||||
list.add(new AdapterItem(titles[i], icons[i]));
|
||||
}
|
||||
Log.i("TAB", "getGridItems: "+list.size());
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.example;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.xuexiang.xui.XUI;
|
||||
|
||||
public class MyApplication extends Application {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
XUI.init(this);
|
||||
XUI.debug(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.example.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.smartglasses.R;
|
||||
import com.example.smartglasses.databinding.FragmentTraceBinding;
|
||||
|
||||
|
||||
public class TraceFragment extends Fragment {
|
||||
FragmentTraceBinding binding;
|
||||
private String[] titles = {"今天","昨天"};
|
||||
public TraceFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentTraceBinding.inflate(inflater, container, false);
|
||||
binding.easyIndicator2.setTabTitles(titles);
|
||||
return binding.getRoot();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue