一个简单的智能停车APP——抽屉式侧边栏
一个简单的智能停车APP
- 功能介绍
- 代码详解
- 总结
功能介绍
先展示效果图:
侧边栏由MaterialDesign(原质化设计)框架设计而成。
由DrawerLayout+NavigationView组成
需要导入的包如下:
其中circleimageview是将图片放入圆型容器之中
implementation 'com.google.android.material:material:1.1.0-alpha09'implementation 'com.getbase:floatingactionbutton:1.10.1'implementation 'com.google.android.material:material:1.0.0'implementation 'de.hdodenhof:circleimageview:2.1.0'
代码详解
布局文件代码如下:
app:headerLayout:代表头部文件内容
app:menu:代表下面菜单内容
android:layout_gravity=“left” 为侧边栏所在位置以及滑动方向
<com.google.android.material.navigation.NavigationViewandroid:id="@+id/InformationManage"android:layout_width="match_parent"android:layout_height="match_parent"app:headerLayout="@layout/information_head_item"app:menu="@menu/setting_menu"android:layout_gravity="left"/>
其中app:headerLayout代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:circleimageview="http://schemas.android.com/apk/res-auto"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageViewandroid:id="@+id/HeadImage"android:layout_width="100dp"android:layout_height="100dp"android:src="@drawable/user_bule"android:layout_gravity="center"circleimageview:civ_border_color="@android:color/holo_red_light"circleimageview:civ_border_overlay="false"circleimageview:civ_border_width="2dp"circleimageview:civ_fill_color="@android:color/holo_blue_light"/><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_gravity="center"android:layout_margin="@dimen/Small"><TextViewandroid:id="@+id/HeadUserID"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="智能停车账号:"android:singleLine="true"android:textSize="@dimen/text_Medium"/><TextViewandroid:id="@+id/Information_UserName"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="登陆账号"android:singleLine="true"android:textSize="@dimen/text_Medium"/></LinearLayout>
</LinearLayout>
app:menu代码如下:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single"><itemandroid:id="@+id/Personal"android:title="个人信息"android:icon="@drawable/user"/><itemandroid:id="@+id/Pay"android:title="支付管理"android:icon="@drawable/pay1"/><itemandroid:id="@+id/Car"android:title="车辆管理"android:icon="@drawable/cars"/><itemandroid:id="@+id/Collection"android:title="共享车位"android:icon="@drawable/shared"/><itemandroid:id="@+id/File"android:title="提前预定"android:icon="@drawable/booking"/><itemandroid:id="@+id/OrderManagement"android:title="订单管理"android:icon="@drawable/order"/>
</group><item android:title="Setting"><menu ><itemandroid:id="@+id/Setting"android:title="设置"android:icon="@drawable/setting1"/><itemandroid:id="@+id/Version"android:icon="@drawable/version"android:title="版本信息"/></menu></item>
</menu>
在侧边栏我写了三个功能:个人信息,提前预定,共享车位,订单管理
一:个人信息
XML布局文件代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#E0E0E0"android:orientation="vertical"><!--标题栏--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="60dp"android:orientation="horizontal"android:paddingLeft="5dp"android:paddingBottom="20dp"android:paddingTop="10dp"android:background="#fff"><ImageViewandroid:id="@+id/ToSettingInformationGoBack"android:layout_width="20dp"android:layout_height="30dp"android:layout_marginLeft="5dp"android:layout_marginTop="2dp"android:scaleType="fitCenter"android:src="@drawable/goback1" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="账号管理"android:textSize="20sp"android:textColor="#000"android:layout_marginLeft="110dp"android:layout_marginTop="5dp"/></LinearLayout>
<!--信息栏--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:paddingTop="20dp"><!--头像--><LinearLayoutandroid:id="@+id/LayoutIcons"android:layout_width="match_parent"android:layout_height="40dp"android:orientation="horizontal"android:paddingLeft="20dp"android:background="#fff"><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:layout_height="wrap_content"android:text="头像"android:textSize="15sp"android:layout_marginTop="10dp"android:textColor="#000"/><ImageViewandroid:id="@+id/SettingIcons"android:layout_width="30dp"android:layout_height="30dp"android:src="@drawable/icons"android:scaleType="fitCenter"android:layout_marginTop="5dp"android:layout_marginRight="10dp"/><ImageViewandroid:layout_width="20dp"android:layout_height="20dp"android:src="@drawable/right"android:scaleType="fitCenter"android:layout_marginTop="10dp"android:layout_marginRight="10dp"/></LinearLayout><!--昵称--><LinearLayoutandroid:id="@+id/LayoutName"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:paddingLeft="20dp"android:background="#fff"><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:layout_height="wrap_content"android:text="昵称"android:textSize="15sp"android:layout_marginTop="10dp"android:textColor="#000"/><TextViewandroid:id="@+id/SettingName"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="FranzLiszt"android:layout_marginTop="10dp"android:layout_marginRight="10dp"android:textColor="#000" /><ImageViewandroid:layout_width="20dp"android:layout_height="20dp"android:src="@drawable/right"android:scaleType="fitCenter"android:layout_marginTop="10dp"android:layout_marginRight="10dp"/></LinearLayout><!--性别--><LinearLayoutandroid:id="@+id/LayoutSex"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:paddingLeft="20dp"android:background="#fff"><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:layout_height="wrap_content"android:text="性别"android:textSize="15sp"android:layout_marginTop="10dp"android:textColor="#000"/><TextViewandroid:id="@+id/SettingSex"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:layout_marginRight="10dp"android:text="男"android:textColor="#000"android:background="#fff"/><ImageViewandroid:layout_width="20dp"android:layout_height="20dp"android:src="@drawable/right"android:scaleType="fitCenter"android:layout_marginTop="10dp"android:layout_marginRight="10dp"/></LinearLayout><!--等级--><LinearLayoutandroid:id="@+id/LayoutLevel"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:paddingLeft="20dp"android:background="#fff"><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:layout_height="wrap_content"android:text="等级"android:textSize="15sp"android:layout_marginTop="10dp"android:textColor="#000"/><TextViewandroid:id="@+id/SettingLevel"android:layout_width="wrap_content"android:layout_height="30dp"android:text="铜牌会员"android:layout_marginTop="10dp"android:layout_marginRight="10dp"android:textColor="#000"android:background="#fff"/><ImageViewandroid:layout_width="20dp"android:layout_height="20dp"android:src="@drawable/right"android:scaleType="fitCenter"android:layout_marginTop="10dp"android:layout_marginRight="10dp"/></LinearLayout><!--手机号码--><LinearLayoutandroid:id="@+id/LayoutPhoneNumber"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:paddingLeft="20dp"android:background="#fff"><TextViewandroid:layout_weight="1"android:layout_width="0dp"android:layout_height="wrap_content"android:text="手机号码"android:textSize="15sp"android:layout_marginTop="10dp"android:textColor="#000"/><TextViewandroid:id="@+id/SettingPhoneNumber"android:layout_width="wrap_content"android:layout_height="30dp"android:text="去绑定"android:layout_marginTop="10dp"android:layout_marginRight="10dp"android:textColor="#000"android:background="#fff"/><ImageViewandroid:layout_width="20dp"android:layout_height="20dp"android:src="@drawable/right"android:scaleType="fitCenter"android:layout_marginTop="10dp"android:layout_marginRight="10dp"/></LinearLayout></LinearLayout><Buttonandroid:id="@+id/Exit"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="退出登陆"android:background="#fff"android:textColor="#ff0000"android:layout_marginTop="20dp"/>
</LinearLayout>
JAVA代码如下:
public class SettingInformation extends AppCompatActivity {private LinearLayout LayoutImage,LayoutSex;private PopupWindow popupWindow;private TextView SettingName,SettingSex,SettingPhoneNumber,SettingLevel;private View view = null;private View viewSex = null;private Button ToCamera,ToPhoto,ToExit,Exit;private static int REQUEST_CAMERA = 1;private static int REQUEST_CHOOSE_PHOTO = 2;private String PhotoAddress;private ImageView SettingIcons,SettingGoBack;private Bitmap bitmap;private static final String[] sPermissonVal = {Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE};private static final int PERMISSION_CAMERA_REQUEST_CODE = 3;Dao dao = new Dao( SettingInformation.this );@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate( savedInstanceState );setContentView( R.layout.activity_setting_information );InitView();ShowPopupWindows();UpdateLayout();Listener();//GetPhoto();//ShowPopupWindows_Sex();}/****************初始化界面****************/private void InitView() {LayoutImage = findViewById( R.id.LayoutIcons );LayoutSex = findViewById( R.id.LayoutSex );Exit = findViewById( R.id.Exit );SettingIcons = findViewById( R.id.SettingIcons );//CameraActivity.setClipRatio(1, 1);SettingName = findViewById( R.id.SettingName );SettingPhoneNumber = findViewById( R.id.SettingPhoneNumber );SettingSex = findViewById( R.id.SettingSex );SettingGoBack = findViewById( R.id.ToSettingInformationGoBack );SettingLevel = findViewById( R.id.SettingLevel );PhotoAddress = Environment.getExternalStorageDirectory().getPath();//指定路径和获取图片的名称PhotoAddress = PhotoAddress+"/"+"Image.png";}/****************根据注册填写的信息改变此布局内容,传过来一个boolean值进行判断****************/private void UpdateLayout(){if (Login.JudgeLoginStatic == true) {Account account = dao.QueryInformation( Login.Login_Account );String GetSex = account.getSex();String GetPhoneNumber = account.getPhoneNumber();SettingName.setText( Login.Login_Account );SettingPhoneNumber.setText( GetPhoneNumber );SettingSex.setText( GetSex );}}/****************用于点击退出登陆后,清理布局****************/private void DeleteLayout(){SettingIcons.setImageResource( R.drawable.icons );SettingName.setText( "" );SettingSex.setText( "" );SettingPhoneNumber.setText( "" );SettingLevel.setText( "" );Exit.setText( "立即登陆" );Intent intent = new Intent( SettingInformation.this, Login.class );startActivity( intent );}//申请权限/************需要动态申请权限************/private void requestPermission() {// Android6.0开始, 即当API大于等于 23 时,才动态申请权限if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {this.requestPermissions(sPermissonVal, PERMISSION_CAMERA_REQUEST_CODE);}}/****************初始化PopupWindows****************/private void ShowPopupWindows() {//获取布局view = LayoutInflater.from( SettingInformation.this).inflate( R.layout.popup_image,null,false );ToCamera = view.findViewById( R.id.ToCamera ); //跳转相机ToPhoto = view.findViewById( R.id.ToPhoto );//跳转相册ToExit = view.findViewById( R.id.ToExit );//退出popupWindow = new PopupWindow( view, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT );popupWindow.setFocusable( true ); //获取焦点popupWindow.setBackgroundDrawable( new BitmapDrawable( ) );popupWindow.setOutsideTouchable( true ); //点击外面地方,取消popupWindow.setTouchable( true ); //允许点击popupWindow.setAnimationStyle( R.style.MyPopupWindow ); //设置动画ToExit.setOnClickListener( new View.OnClickListener() {@Overridepublic void onClick(View v) {popupWindow.dismiss();}} );/****************打开相机监听事件****************/ToCamera.setOnClickListener( new View.OnClickListener() {@Overridepublic void onClick(View v) {//requestPermission();Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);intent.addCategory(Intent.CATEGORY_DEFAULT);startActivityForResult(intent, 2);}} );/****************打开相册监听事件****************/ToPhoto.setOnClickListener( new View.OnClickListener() {@Overridepublic void onClick(View v) {openGallery();}} );}/****************对返回键进行监听,如果按下popupWindow消失****************/@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (event.getKeyCode() == KeyEvent.KEYCODE_BACK){if (popupWindow != null && popupWindow.isShowing()){popupWindow.dismiss();return true;}}return false;}/****************显示PopupWindows****************/private void ShowPopupWindowsFromButtom(){popupWindow.showAtLocation( view, Gravity.BOTTOM,0,0 );}/****************打开相机****************/private void OpenCamera(){
// Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// intent.addCategory(Intent.CATEGORY_DEFAULT);
//
// // 打开照相机,设置请求码
// intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
// startActivityForResult(intent, 2);// try {
// Intent intent = new Intent();
// intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
// File file = FileManager.createFileIfNeed("filepath.png");
// Uri uri;
// if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
// uri = Uri.fromFile(file);
// } else {
// uri = FileProvider.getUriForFile(this, "link.android.file.provider", file);
// }
// intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
// intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
// startActivityForResult(intent, 1);
// }catch (IOException e){
// e.printStackTrace();
// }}/****************打卡相册****************/private void openGallery() {Intent picture = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);startActivityForResult(picture, 2);}@Overrideprotected void onResume() {super.onResume();//获得相册、相机返回的结果,并显示if (CameraActivity.LISTENING) {Log.e("TAG", "返回的Uri结果:" + CameraActivity.IMG_URI);Log.e("TAG", "返回的File结果:" + CameraActivity.IMG_File.getPath());CameraActivity.LISTENING = false; //关闭获取结果SettingIcons.setImageURI(CameraActivity.IMG_URI); //显示图片到控件}}/********************************/@Overrideprotected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {super.onActivityResult( requestCode, resultCode, data );//判断是否返回数据if (resultCode == RESULT_OK) {//判断返回的类型是否是我们所需if (requestCode == 1) {String state = Environment.getExternalStorageState();if (!state.equals( Environment.MEDIA_MOUNTED ))return;Tiny.FileCompressOptions options = new Tiny.FileCompressOptions();Tiny.getInstance().source( FileManager.readpic() ).asFile().withOptions( options ).compress( new FileWithBitmapCallback() {@Overridepublic void callback(boolean isSuccess, Bitmap bitmap, String outfile, Throwable t) {}} );} else if (requestCode == 2 && resultCode == Activity.RESULT_OK && null != data) {
// try {
// Uri selectedImage = data.getData();
// Tiny.FileCompressOptions options = new Tiny.FileCompressOptions();
// Tiny.getInstance().source( selectedImage ).asFile().withOptions( options ).compress( new FileWithBitmapCallback() {
// @Override
// public void callback(boolean isSuccess, Bitmap bitmap, String outfile, Throwable t) {
// SettingIcons.setImageBitmap( bitmap );
// }
// } );
// } catch (Exception e) {
// e.printStackTrace();
// }Bundle bundle = data.getExtras();Bitmap bitmap = (Bitmap) bundle.get("data");SettingIcons.setImageBitmap(bitmap);}}}private void getPicture() {//获取字符串SharedPreferences sPreferences = getSharedPreferences("Picture", Context.MODE_PRIVATE);String imageBase64 = sPreferences.getString("cameraImage", "");//把字符串解码成Bitmap对象byte[] byte64 = Base64.decode(imageBase64, 0);ByteArrayInputStream bais = new ByteArrayInputStream(byte64);Bitmap bitmap = BitmapFactory.decodeStream(bais);//显示图片SettingIcons.setImageBitmap(bitmap);}private void ToBitmap(){//把Bitmap转码成字符串ByteArrayOutputStream baos = new ByteArrayOutputStream();bitmap.compress( Bitmap.CompressFormat.PNG, 50,baos);String imageBase64 = new String ( Base64.encode(baos.toByteArray(), 0));//把字符串存到SharedPreferences里面SharedPreferences prePicture = getSharedPreferences("Picture", Context.MODE_PRIVATE);SharedPreferences.Editor editor = prePicture.edit();editor.putString("cameraImage", imageBase64);editor.commit();}private void Listener () {OnClick onClick = new OnClick();LayoutImage.setOnClickListener( onClick );LayoutSex.setOnClickListener( onClick );Exit.setOnClickListener( onClick );SettingGoBack.setOnClickListener( onClick );}/**************内部类监听事件**************/class OnClick implements View.OnClickListener {@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.LayoutIcons:ShowPopupWindowsFromButtom();break;case R.id.Exit:DeleteLayout();break;case R.id.ToSettingInformationGoBack:Intent intent = new Intent( SettingInformation.this, Function.class);startActivity( intent );break;}}}}
二:共享车位
步骤:1.选择共享车位类型2.填写相关信息3.审核
三:提前预定
效果图如下:
从右网左侧滑出现提前预定按钮
订单信息
弹出信息确认提示
四:订单管理
当确认订单时,便开始计时:
界面如下:
然后点击结束并缴费,弹出popwindows,订单信息
点击确定之后进入支付界面,依旧是弹出popwindows,界面如下
填写密码之后,点击支付,弹出通知,回执支付成功信息
介绍几个重要的功能
1.计时器
返回系统启动到现在的毫秒数,包含休眠时间。
SystemClock.elapsedRealtime()
Handler handler_time = new Handler( ){@Overridepublic void handleMessage(@NonNull Message msg) {super.handleMessage( msg );mHour.setText( msg.obj.toString() );}};new Timer( ).scheduleAtFixedRate( new TimerTask() {@Overridepublic void run() {int time = (int)((SystemClock.elapsedRealtime() - OrderInterface.this.CurrentTime) / 1000);GetTimeHour = new DecimalFormat("00").format(time / 3600);GetTimeMinute = new DecimalFormat("00").format(time % 3600 / 60);GetTimeSecond = new DecimalFormat("00").format(time % 60);String timeFormat = new String(GetTimeHour + ":" + GetTimeMinute + ":" + GetTimeSecond);Message msg = new Message();msg.obj = timeFormat;handler_time.sendMessage(msg);}},0,1000L );}
2.通知
Android8以上使用通知一定要创建渠道
private void NotificationManagerMethod(){if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//创建通知渠道IDString channelId = "Park";//创建通知渠道名称String channelName = "路边秒停车";//创建通知渠道重要性int importance = NotificationManager.IMPORTANCE_HIGH;createNotificationChannel( channelId, channelName, importance );}}private void InitNotificationManager(){manager = (NotificationManager)getSystemService( NOTIFICATION_SERVICE );Notification builder = new NotificationCompat.Builder(this,"Park").setSmallIcon( R.drawable.stopicon_notfition ).setContentTitle( "支付结果" ).setContentText( "支付成功\n"+"停车时间:"+GetTimeHour+"小时"+GetTimeMinute+"分钟"+"\n"+"支付金额:"+PayTotalMoney+"元" )// 通知首次出现在通知栏,带上升动画效果的.setWhen( System.currentTimeMillis() ).setAutoCancel(true).build();manager.notify( 0,builder);}private void createNotificationChannel(String channelId,String channelName,int importance){NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);notificationManager.createNotificationChannel(channel);}
该类整体代码如下:
package com.example.Order;import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.text.Layout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;import com.example.Imformation.Function;
import com.example.intelligentparking.R;
import com.mob.tools.utils.ResHelper;import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;public class OrderInterface extends AppCompatActivity {private TextView mHour,mMinute,mSecond;private ImageView mOrderGoBack;private Button mToPay;private int CurrentMinute = 0,CurrentHour = 0,CurrentSecond = 0;private Handler handler;private Toast toastPayInformation;private PopupWindow DisplayPayInterface,InputPassWordInterface;private long CurrentTime;private String DEFAULT_TIME_FORMAT = "yyyy-MM-dd hh:mm:ss";public static final int ParkPrice = 5;private String GetTimeHour;private String GetTimeMinute;private String GetTimeSecond;private int PayTotalMoney = 0;/**以下为PopupWindow里面的控件*/private TextView Name,PhoneNumber,ParkedTime,EstimatePayMoney,ReallyPayMoney,OrderTime,OrderNumber;private Button Cancel,Confirm;private View view,view_passWord;private Thread thread;private NotificationManager manager;/**PopupWindow支付并且填写密码界面*/private ImageView GoBackPayInterface;private TextView PayMoney;private EditText PassWord_One,PassWord_Two,PassWord_Three,PassWord_Four,PassWord_Five,PassWord_Six;private Button ConfirmPay;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate( savedInstanceState );//requestWindowFeature( Window.FEATURE_CUSTOM_TITLE );setContentView( R.layout.activity_order_interface );//getWindow().setFeatureInt( Window.FEATURE_CUSTOM_TITLE,R.layout.order_titlebar );OrderInterface.this.CurrentTime = SystemClock.elapsedRealtime();InitView();Listener();DisplayPayInformation();DisplayInputPassWordAndPay();NotificationManagerMethod();Handler handler_time = new Handler( ){@Overridepublic void handleMessage(@NonNull Message msg) {super.handleMessage( msg );mHour.setText( msg.obj.toString() );}};new Timer( ).scheduleAtFixedRate( new TimerTask() {@Overridepublic void run() {/* 返回系统启动到现在的毫秒数,包含休眠时间。*/int time = (int)((SystemClock.elapsedRealtime() - OrderInterface.this.CurrentTime) / 1000);GetTimeHour = new DecimalFormat("00").format(time / 3600);GetTimeMinute = new DecimalFormat("00").format(time % 3600 / 60);GetTimeSecond = new DecimalFormat("00").format(time % 60);String timeFormat = new String(GetTimeHour + ":" + GetTimeMinute + ":" + GetTimeSecond);Message msg = new Message();msg.obj = timeFormat;handler_time.sendMessage(msg);}},0,1000L );}private void InitView(){mHour = findViewById( R.id.Time_Hour );/* mMinute = findViewById( R.id.Time_Minute );mSecond = findViewById( R.id.Time_Second );*/mOrderGoBack = findViewById( R.id. OrderBack);mToPay = findViewById( R.id.ToPay );}private void Listener(){OnClick onClick = new OnClick();mOrderGoBack.setOnClickListener( onClick );mToPay.setOnClickListener( onClick);}private void NotificationManagerMethod(){if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//创建通知渠道IDString channelId = "Park";//创建通知渠道名称String channelName = "路边秒停车";//创建通知渠道重要性int importance = NotificationManager.IMPORTANCE_HIGH;createNotificationChannel( channelId, channelName, importance );}}private void InitNotificationManager(){manager = (NotificationManager)getSystemService( NOTIFICATION_SERVICE );Notification builder = new NotificationCompat.Builder(this,"Park").setSmallIcon( R.drawable.stopicon_notfition ).setContentTitle( "支付结果" ).setContentText( "支付成功\n"+"停车时间:"+GetTimeHour+"小时"+GetTimeMinute+"分钟"+"\n"+"支付金额:"+PayTotalMoney+"元" )// 通知首次出现在通知栏,带上升动画效果的.setWhen( System.currentTimeMillis() ).setAutoCancel(true).build();manager.notify( 0,builder);}private void createNotificationChannel(String channelId,String channelName,int importance){NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);notificationManager.createNotificationChannel(channel);}private void DisplayInputPassWordAndPay(){view_passWord = LayoutInflater.from( OrderInterface.this ).inflate( R.layout.paysystem_interface,null,false );GoBackPayInterface = view_passWord.findViewById( R.id.GoBackPayInterface );PayMoney = view_passWord.findViewById( R.id.PayMoney );PassWord_One = view_passWord.findViewById( R.id.PassWord_one );PassWord_Two = view_passWord.findViewById( R.id.PassWord_two );PassWord_Three = view_passWord.findViewById( R.id.PassWord_three );PassWord_Four = view_passWord.findViewById( R.id.PassWord_four );PassWord_Five = view_passWord.findViewById( R.id.PassWord_five );PassWord_Six = view_passWord.findViewById( R.id.PassWord_six );ConfirmPay = view_passWord.findViewById( R.id.ConfirmPay );InputPassWordInterface = new PopupWindow( view_passWord,ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT );InputPassWordInterface.setFocusable( true ); //获取焦点InputPassWordInterface.setBackgroundDrawable( new BitmapDrawable( ) );InputPassWordInterface.setOutsideTouchable( true ); //点击外面地方,取消InputPassWordInterface.setTouchable( true ); //允许点击InputPassWordInterface.setAnimationStyle( R.style.MyPopupWindow ); //设置动画ConfirmPay.setOnClickListener( new View.OnClickListener() {@Overridepublic void onClick(View v) {InputPassWordInterface.dismiss();InitNotificationManager();}} );GoBackPayInterface.setOnClickListener( new View.OnClickListener() {@Overridepublic void onClick(View v) {InputPassWordInterface.dismiss();}} );}private void DisplayPayInformation(){view = LayoutInflater.from( OrderInterface.this ).inflate( R.layout.display_pay_information,null,false );Name = view.findViewById( R.id.DisplayPay_Name );PhoneNumber = view.findViewById( R.id.DisplayPay_PhoneNumber );ParkedTime = view.findViewById( R.id.DisplayPay_Time );EstimatePayMoney = view.findViewById( R.id.DisplayPay_EstimatePayMoney );ReallyPayMoney = view.findViewById( R.id.DisplayPay_ReallyPayMoney );OrderTime = view.findViewById( R.id.OrderTime );OrderNumber = view.findViewById( R.id.OrderNumber );Cancel = view.findViewById( R.id.CancelToPay );Confirm = view.findViewById( R.id.ConfirmToPay );DisplayPayInterface = new PopupWindow( view, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT );DisplayPayInterface.setFocusable( true ); //获取焦点DisplayPayInterface.setBackgroundDrawable( new BitmapDrawable( ) );DisplayPayInterface.setOutsideTouchable( true ); //点击外面地方,取消DisplayPayInterface.setTouchable( true ); //允许点击DisplayPayInterface.setAnimationStyle( R.style.MyPopupWindow ); //设置动画Cancel.setOnClickListener( new View.OnClickListener() {@Overridepublic void onClick(View v) {DisplayPayInterface.dismiss();}} );Confirm.setOnClickListener( new View.OnClickListener() {@Overridepublic void onClick(View v) {DisplayPayInterface.dismiss();DisplayPayPopWindowsForCenter();}} );}private void DisplayPayPopWindowsForCenter(){InputPassWordInterface.showAtLocation( view,Gravity.BOTTOM,100,50 );}private void DisplayPopWindowsForCenter(){Name.setText( "孙鹏" );PhoneNumber.setText( "17375527572" );int Hour = Integer.parseInt( GetTimeHour );int Minute = Integer.parseInt( GetTimeMinute );int Second = Integer.parseInt( GetTimeSecond );ParkedTime.setText( Hour+"小时"+Minute+"分钟"+Second+"秒" );/*** 停车收费标准如下:* 1.一小时单价5元* 2.大于半小时,不满一小时,归于一小时计* 3.小于半小时,不计收费*/if (Hour > 0 && Minute > 30){PayTotalMoney = (Hour+1)*ParkPrice;}else if (Hour > 0 && Minute < 30){PayTotalMoney = Hour*ParkPrice;}else {PayTotalMoney = 0;}EstimatePayMoney.setText( PayTotalMoney+"元" );ReallyPayMoney.setText( PayTotalMoney+"元" );SimpleDateFormat format = new SimpleDateFormat( DEFAULT_TIME_FORMAT );String Time = format.format( Calendar.getInstance().getTime() );OrderTime.setText( Time );Random random = new Random( );Long OrderNumber_Long = 0L;do {OrderNumber_Long = random.nextLong();}while (OrderNumber_Long < 0);OrderNumber.setText( OrderNumber_Long+"" );DisplayPayInterface.showAtLocation( view,Gravity.CENTER,0,0 );}class OnClick implements View.OnClickListener{@Overridepublic void onClick(View v) {switch (v.getId()){case R.id.OrderBack:startActivity( new Intent( OrderInterface.this, Function.class ) );break;case R.id.ToPay:DisplayPopWindowsForCenter();break;}}}
}
总结
实践出真知
一个简单的智能停车APP——抽屉式侧边栏相关推荐
- Android——一个简单的智能家居系统
一个简单的智能家居系统 效果展示 启动应用界面 登陆界面 导航界面 温度界面 湿度界面 烟雾传感器界面 人体红外传感器界面 效果展示 以下为整个程序的操作流程,因为CSDN不能上传太大文件,所以画质比 ...
- Android——一个简单的记账本APP
一个简单的记账本APP 视频效果预览 添加账目记录 效果预览 添加账目记录实现 简述 实现 获取日期 字符串时间戳转Date Date转星期 获取时间 Switch控制显示和隐藏 更改Switch样式 ...
- 动手做一个简单的智能小车
动手做一个简单的智能小车 来到CNDN一年了,看到了许多大佬的杰出作品.也该写点什么来回馈给大家了前不久接触了单片机,想提前进行实践一下所以有想法做一个实体出来,想来想去难的怕自己搞不定,但是还好找到 ...
- 基于android停车管理app,基于Android的城市智能停车APP设计与研究
摘要: 伴随智慧城市进程的推进,人们追求生活智能化.道路拥堵,交通堵塞以及停车难等城市交通问题让"有车一族"头疼不已,降低了人们的停车体验.本文综合运用了移动定位技术,Androi ...
- Flutter for App——一个简单的BMI计算APP
一个简单的BMI计算APP 效果截图 初始化 布局 顶部区域 标题 计算结果 组合顶部区域 背景 中间区域 输入框 输入行 计算按钮 分界线 组合中间区域 底部区域 页面组合 BMI计算 Toast弹 ...
- 如何制作一个简单的短视频 app
如果想制作一个简单的短视频 app,可以考虑以下步骤: 确定 app 的目标和功能:需要明确 app 的目标受众和提供的功能,以确定 app 的整体设计方向. 选择开发平台:根据自己的技术能力和预算选 ...
- 使用Flutter编写一个简单的天气查询App
使用Flutter编写一个简单的天气查询App Flutter项目目录分析 入口函数 home:主页面 编写天气应用 网络请求 数据解析 布局编写 Flutter里基础的Widget 上 中 下 Fl ...
- Flutter 实现一个简单的音视频App(一)
Flutter 实现一个简单的音视频App(一) 本文由动哒公众号(dongda_5g),QQ群(174353204)提供,欢迎关注获取技术支持,有任何问题群里都会回复. 在app中实现视频功能,是现 ...
- 使用 Python 实现一个简单的智能聊天机器人
使用 Python 实现一个简单的智能聊天机器人 文章目录 使用 Python 实现一个简单的智能聊天机器人 简要说明 总体的思路 需要准备的环境 接收用户的语音输入, 并将其存为音频文件 调用百度A ...
最新文章
- 一次难忘的产品发布经历
- OpenCV2:幼儿园篇 第一章 创建图像并显示
- leetcode111. 二叉树的最小深度(队列)
- python闯关_Day012
- 2.3 Factory Method(工厂方法)
- 《Node.js开发实战详解》学习笔记
- nginx 端口转发_Knative Service 是如何指定端口和协议的
- 评分 9.7!这本 Python 书彻底玩大了?程序员:满分!
- Linux虚拟机之间实现密钥登陆
- 博文视点Open Party第10期:PPT专场
- 最好的年终奖,是你拥有随时跳槽的能力
- 用户反馈驱动抖音产品体验优化实践
- 解决python -m spacy download en_core_web_sm连接不上服务器的方案
- matlab电学成像,利用MATLAB进行电磁学计算及可视化教学.PDF
- python 练习洗牌
- tf.gather_nd用法详解
- 出现错误1327!无效驱动器G的解决
- 全方位解读Web3域名:DID基石、NFT新增长点
- 技术体系构建_构建出色的技术简历的简单指南
- oracle数据库led显示屏,LED导航者通用版(led显示屏控制软件) V3.1 最新官方安装版...
热门文章
- 2022CPA财务与成本管理-成本计算专题【完结】
- 帆软公式如何用数据库字段_如何用WORD书写三角函数公式?如何快速记忆诱导公式?...
- Prometheus 监控体系
- linux中nginx的安装(源码安装)及简单应用(二)
- 图论二分图问题讲解-染色法和匈牙利算法
- 〖Python 数据库开发实战 - Python与MySQL交互篇⑨〗- 项目实战 - 封装数据库连接池与编写第一个业务流程(用户登录即身份校验)
- 读书笔记 - Max-Plus Algorithm
- 5-羟色胺(serotonin)
- 使用Debookee抓取同一网络中中任何设备的报文
- linux4 tick值,详解在 linux 下的时间校对工具 adjtimex 的用法