Koltin48,阿里腾讯PDD等大厂Android面试真题

var typeInfo = “”

when (type) {

OrderObservable.ORDERTYPE_UNPAYMENT -> typeInfo = “未支付”

OrderObservable.ORDERTYPE_SUBMIT -> typeInfo = “已提交订单”

OrderObservable.ORDERTYPE_RECEIVEORDER -> typeInfo = “商家接单”

OrderObservable.ORDERTYPE_DISTRIBUTION -> typeInfo = “配送中”

OrderObservable.ORDERTYPE_SERVED -> typeInfo = “已送达”

OrderObservable.ORDERTYPE_CANCELLEDORDER -> typeInfo = “取消的订单”

}

return typeInfo

}

}

OrderDetailActivity.kt订单详情界面,有一个观察者来接受服务器发来的消息,服务端会发送订单或者骑手的状态来更新对应在地图中的位置

package com.example.takeout.ui.activity

import android.graphics.Color

import android.os.Bundle

import android.view.View

import android.widget.ImageView

import android.widget.TextView

import androidx.appcompat.app.AppCompatActivity

import com.amap.api.maps2d.AMap

import com.amap.api.maps2d.CameraUpdateFactory

import com.amap.api.maps2d.model.BitmapDescriptorFactory

import com.amap.api.maps2d.model.LatLng

import com.amap.api.maps2d.model.Marker

import com.amap.api.maps2d.model.MarkerOptions

import com.example.takeout.R

import com.example.takeout.utils.OrderObservable

import kotlinx.android.synthetic.main.activity_order_detail.*

import java.util.*

import kotlin.collections.ArrayList

//Observer观察者观察推送的变化

class OrderDetailActivity : AppCompatActivity(), Observer {

override fun update(o: Observable?, arg: Any?) {

}

// override fun update(o: Observable?, data: Any?) {

private fun update(orderId: String, types: String, data: Any?) {

// 更新UI

/*接收到服务端的通知发送来的数据更新UI

val jsonObj: JSONObject = JSONObject(data as String)

val pushOrderId = jsonObj.getString(“orderId”)

val pushType = jsonObj.getString(“type”)

*/

val pushOrderId = orderId

val pushType = types

if (orderId.equals(pushOrderId)) {

type = pushType

}

val index = getIndex(type)

(ll_order_detail_type_point_container.getChildAt(index) as ImageView).setImageResource(R.mipmap.order_time_node_disabled)

(ll_order_detail_type_container.getChildAt(index) as TextView).setTextColor(Color.BLUE)

when (type) {

//骑士接单

OrderObservable.ORDERTYPE_RECEIVEORDER -> {

//显示地图

mMapView.visibility = View.VISIBLE

//移动地图

aMap.moveCamera(

CameraUpdateFactory.newLatLngZoom(

LatLng(

22.5757890000,

113.9232180000

), 16f

)

)

//标注买卖家 22.5788300000,113.9216030000

val sellerMarker = aMap.addMarker(

MarkerOptions()

.position(LatLng(22.5788300000, 113.9216030000))

.icon(BitmapDescriptorFactory.fromResource(R.mipmap.order_seller_icon))

.title(“兰州拉面”).snippet(“最美味的面条”)

)

var imageView = ImageView(this)

imageView.setImageResource(R.mipmap.order_buyer_icon)

aMap.moveCamera(

CameraUpdateFactory.newLatLngZoom(

LatLng(

22.5788300000,

113.9216030000

), 16f

)

)

val buyerMarker = aMap.addMarker(

MarkerOptions()

.position(LatLng(22.5765760000, 113.9237870000))

.icon(BitmapDescriptorFactory.fromView(imageView))

.title(“程序员A”).snippet(“SVIP买家”)

)

}

//配送阶段

OrderObservable.ORDERTYPE_DISTRIBUTION -> {

points.add(LatLng(22.5764420000, 113.9208900000))

//骑士登场

var imageView = ImageView(this)

imageView.setImageResource(R.mipmap.order_rider_icon)

riderMarker = aMap.addMarker(

MarkerOptions()

.position(LatLng(22.5764420000, 113.9208900000))

.icon(BitmapDescriptorFactory.fromView(imageView))

.title(“我是外卖骑士”)

)

// .snippet(“我是黑马骑士”))

riderMarker.showInfoWindow()

}

/*更新骑手的位置接单、取餐、送餐

OrderObservable.ORDERTYPE_DISTRIBUTION_RIDER_GIVE_MEAL,

OrderObservable.ORDERTYPE_DISTRIBUTION_RIDER_TAKE_MEAL -> {

if (jsonObj.has(“lat”)) {

val lat = jsonObj.getString(“lat”)

val lng = jsonObj.getString(“lng”)

//移动骑士 22.5739110000,113.9180200000

//更新骑手位置就是用新位置重新标记骑手

riderMarker.hideInfoWindow()

riderMarker.position = LatLng(lat.toDouble(), lng.toDouble())

aMap.moveCamera(

CameraUpdateFactory.newLatLngZoom(

LatLng(

lat.toDouble(),

lng.toDouble()

), 16f

)

)

//测距功能

val distance = AMapUtils.calculateLineDistance(

LatLng(lat.toDouble(), lng.toDouble()),

LatLng(22.5765760000, 113.9237870000)

)

riderMarker.title = “距离您还有” + Math.abs(distance) + “米”

riderMarker.showInfoWindow()

//绘制轨迹

points.add(LatLng(lat.toDouble(), lng.toDouble()))

val polyline = aMap.addPolyline(

PolylineOptions().color(Color.RED).width(3.0f)

.add(points.get(points.size - 1), points.get(points.size - 2))

)

}

}

*/

}

}

var points: ArrayList = ArrayList()

lateinit var riderMarker: Marker

lateinit var aMap: AMap

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_order_detail)

processIntent()

OrderObservable.instance.addObserver(this)

mMapView.onCreate(savedInstanceState)// 此方法必须重写

aMap = mMapView.map

update(orderId, type, 0)

}

override fun onDestroy() {

super.onDestroy()

//在activity执行onDestroy时执行mMapView.onDestroy(),销毁地图

mMapView.onDestroy()

}

override fun onResume() {

super.onResume()

//在activity执行onResume时执行mMapView.onResume (),重新绘制加载地图

mMapView.onResume()

}

override fun onPause() {

super.onPause()

//在activity执行onPause时执行mMapView.onPause (),暂停地图的绘制

mMapView.onPause()

}

override fun onSaveInstanceState(outState: Bundle) {

super.onSaveInstanceState(outState)

//在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState),保存地图当前的状态

mMapView.onSaveInstanceState(outState)

}

lateinit var orderId: String

lateinit var type: String

private fun processIntent() {

if (intent.hasExtra(“orderId”)) {

orderId = intent.getStringExtra(“orderId”)

type = intent.getStringExtra(“type”)

val index = getIndex(type)

(ll_order_detail_type_point_container.getChildAt(index) as ImageView).setImageResource(R.mipmap.order_time_node_disabled)

(ll_order_detail_type_container.getChildAt(index) as TextView).setTextColor(Color.BLUE)

}

}

private fun getIndex(type: String): Int {

var index = -1

// String typeInfo = “”;

when (type) {

OrderObservable.ORDERTYPE_UNPAYMENT -> {

}

OrderObservable.ORDERTYPE_SUBMIT ->

// typeInfo = “已提交订单”;

index = 0

OrderObservable.ORDERTYPE_RECEIVEORDER ->

// typeInfo = “商家接单”;

index = 1

OrderObservable.ORDERTYPE_DISTRIBUTION,

OrderObservable.ORDERTYPE_DISTRIBUTION_RIDER_GIVE_MEAL,

OrderObservable.ORDERTYPE_DISTRIBUTION_RIDER_TAKE_MEAL,

OrderObservable.ORDERTYPE_DISTRIBUTION_RIDER_RECEIVE ->

// typeInfo = “配送中”;

index = 2

OrderObservable.ORDERTYPE_SERVED ->

// typeInfo = “已送达”;

index = 3

OrderObservable.ORDERTYPE_CANCELLEDORDER -> {

}

}// typeInfo = “未支付”;

// typeInfo = “取消的订单”;

return index

}

}

activity_order_detail.xml订单详情界面的布局文件

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background=“#3090E6”

android:orientation=“vertical”>

<RelativeLayout

android:layout_width=“match_parent”

android:layout_height=“40dp”

android:layout_marginTop=“30dp”>

<ImageView

android:id=“@+id/iv_order_detail_back”

android:layout_width=“25dp”

android:layout_height=“25dp”

android:layout_centerVertical=“true”

android:layout_marginLeft=“18dp”

android:src=“@mipmap/go_back” />

<TextView

android:id=“@+id/tv_seller_name”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_centerVertical=“true”

android:layout_marginLeft=“22dp”

android:layout_toRightOf=“@+id/iv_order_detail_back”

android:text=“订单详情界面”

android:textColor=“#FFF”

android:textSize=“18sp” />

<ImageView

android:layout_width=“20dp”

android:layout_height=“20dp”

android:layout_alignParentRight=“true”

android:layout_centerVertical=“true”

android:layout_marginRight=“15dp”

android:src=“@mipmap/order_action_contact” />

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_margin=“6dp”

android:background=“@drawable/shape_background_solid_white”

android:orientation=“vertical”>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”>

<ImageView

android:layout_width=“50dp”

android:layout_height=“50dp”

android:layout_marginBottom=“8dp”

android:layout_marginLeft=“8dp”

android:layout_marginRight=“8dp”

android:layout_marginTop=“20dp”

android:src=“@mipmap/a” />

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

ght=“8dp”

android:layout_marginTop=“20dp”

android:src=“@mipmap/a” />

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-mlHjXmDT-1710927028830)]
[外链图片转存中…(img-FDmMmIg1-1710927028831)]
[外链图片转存中…(img-ukGkbBSg-1710927028831)]
[外链图片转存中…(img-2YaKl6MX-1710927028831)]

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
[外链图片转存中…(img-h9qfo6PC-1710927028832)]

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值