Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
fastllm
Commits
aefd9f11
Commit
aefd9f11
authored
Sep 06, 2023
by
zhouxiang
Browse files
dcu平台fastllm推理框架
parents
Pipeline
#543
failed with stages
in 0 seconds
Changes
186
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
997 additions
and
0 deletions
+997
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/utils/StatusBarUtils.java
...com/doujiao/xiaozhihuiassistant/utils/StatusBarUtils.java
+54
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/utils/UriUtils.java
.../java/com/doujiao/xiaozhihuiassistant/utils/UriUtils.java
+136
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/ChatPromptViewManager.java
...iao/xiaozhihuiassistant/widget/ChatPromptViewManager.java
+42
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/Location.java
...java/com/doujiao/xiaozhihuiassistant/widget/Location.java
+46
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/PromptView.java
...va/com/doujiao/xiaozhihuiassistant/widget/PromptView.java
+147
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/PromptViewHelper.java
.../doujiao/xiaozhihuiassistant/widget/PromptViewHelper.java
+124
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/BottomCenterLocation.java
...zhihuiassistant/widget/location/BottomCenterLocation.java
+18
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/ICalculateLocation.java
...aozhihuiassistant/widget/location/ICalculateLocation.java
+12
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/TopCenterLocation.java
...iaozhihuiassistant/widget/location/TopCenterLocation.java
+18
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/TopLeftLocation.java
.../xiaozhihuiassistant/widget/location/TopLeftLocation.java
+17
-0
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/TopRightLocation.java
...xiaozhihuiassistant/widget/location/TopRightLocation.java
+18
-0
example/Android/LLMAssistant/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
.../app/src/main/res/drawable-v24/ic_launcher_foreground.xml
+31
-0
example/Android/LLMAssistant/app/src/main/res/drawable/btnbg.xml
.../Android/LLMAssistant/app/src/main/res/drawable/btnbg.xml
+15
-0
example/Android/LLMAssistant/app/src/main/res/drawable/editbg.xml
...Android/LLMAssistant/app/src/main/res/drawable/editbg.xml
+15
-0
example/Android/LLMAssistant/app/src/main/res/drawable/ic_launcher_background.xml
...tant/app/src/main/res/drawable/ic_launcher_background.xml
+170
-0
example/Android/LLMAssistant/app/src/main/res/layout/activity_item_left.xml
...MAssistant/app/src/main/res/layout/activity_item_left.xml
+21
-0
example/Android/LLMAssistant/app/src/main/res/layout/activity_item_right.xml
...Assistant/app/src/main/res/layout/activity_item_right.xml
+28
-0
example/Android/LLMAssistant/app/src/main/res/layout/activity_main.xml
...id/LLMAssistant/app/src/main/res/layout/activity_main.xml
+73
-0
example/Android/LLMAssistant/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
...istant/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
+6
-0
example/Android/LLMAssistant/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
.../app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
+6
-0
No files found.
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/utils/StatusBarUtils.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.utils
;
import
android.content.ClipData
;
import
android.content.ClipboardManager
;
import
android.content.Context
;
import
android.graphics.Color
;
import
android.os.Build
;
import
android.support.v7.app.ActionBar
;
import
android.support.v7.app.AppCompatActivity
;
import
android.view.View
;
import
android.view.Window
;
import
android.view.WindowManager
;
public
class
StatusBarUtils
{
public
static
void
setTranslucentStatus
(
AppCompatActivity
activity
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
21
)
{
View
decorView
=
activity
.
getWindow
().
getDecorView
();
int
option
=
View
.
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
View
.
SYSTEM_UI_FLAG_LAYOUT_STABLE
;
decorView
.
setSystemUiVisibility
(
option
);
activity
.
getWindow
().
setStatusBarColor
(
Color
.
TRANSPARENT
);
}
ActionBar
actionBar
=
activity
.
getSupportActionBar
();
actionBar
.
hide
();
}
public
static
void
hideStatusBar
(
Window
window
,
boolean
darkText
)
{
window
.
clearFlags
(
WindowManager
.
LayoutParams
.
FLAG_TRANSLUCENT_STATUS
);
window
.
addFlags
(
WindowManager
.
LayoutParams
.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
);
window
.
setStatusBarColor
(
Color
.
TRANSPARENT
);
int
flag
=
View
.
SYSTEM_UI_FLAG_LAYOUT_STABLE
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
&&
darkText
)
{
flag
=
View
.
SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
;
}
window
.
getDecorView
().
setSystemUiVisibility
(
flag
|
View
.
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);
}
public
static
boolean
copyStr2ClibBoard
(
Context
context
,
String
copyStr
)
{
try
{
//获取剪贴板管理器
ClipboardManager
cm
=
(
ClipboardManager
)
context
.
getSystemService
(
Context
.
CLIPBOARD_SERVICE
);
// 创建普通字符型ClipData
ClipData
mClipData
=
ClipData
.
newPlainText
(
"Label"
,
copyStr
);
// 将ClipData内容放到系统剪贴板里。
cm
.
setPrimaryClip
(
mClipData
);
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/utils/UriUtils.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.utils
;
import
android.content.ContentUris
;
import
android.content.Context
;
import
android.content.CursorLoader
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Environment
;
import
android.provider.DocumentsContract
;
import
android.provider.MediaStore
;
import
android.support.annotation.RequiresApi
;
import
java.io.File
;
public
class
UriUtils
{
/**
* 从Uri获取文件路径,存储路径需要获取
* android.permission.READ_EXTERNAL_STORAGE权限
* 适用于MediaStore和其他基于文件的内容提供
*
* @param context 上下文对象
* @param uri Uri
*/
public
static
String
getPath
(
Context
context
,
Uri
uri
)
{
int
SDK_INT
=
Build
.
VERSION
.
SDK_INT
;
if
(
SDK_INT
<
Build
.
VERSION_CODES
.
HONEYCOMB
)
{
// No longer supported
throw
new
RuntimeException
(
"SDK_INT="
+
SDK_INT
);
}
else
if
(
SDK_INT
<
Build
.
VERSION_CODES
.
KITKAT
)
{
return
getPathFromUri_API11to18
(
context
,
uri
);
}
else
// if(SDK_INT >= Build.VERSION_CODES.KITKAT)
return
getPathFromUri_API19
(
context
,
uri
);
}
private
static
String
getPathFromUri_API11to18
(
Context
context
,
Uri
uri
)
{
String
[]
projection
=
{
MediaStore
.
Images
.
Media
.
DATA
};
String
result
=
null
;
CursorLoader
cursorLoader
=
new
CursorLoader
(
context
,
uri
,
projection
,
null
,
null
,
null
);
Cursor
cursor
=
cursorLoader
.
loadInBackground
();
if
(
cursor
!=
null
)
{
int
column_index
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
);
cursor
.
moveToFirst
();
result
=
cursor
.
getString
(
column_index
);
cursor
.
close
();
}
return
result
;
}
@RequiresApi
(
Build
.
VERSION_CODES
.
KITKAT
)
private
static
String
getPathFromUri_API19
(
Context
context
,
Uri
uri
)
{
String
scheme
=
uri
.
getScheme
();
String
authority
=
uri
.
getAuthority
();
if
(
scheme
==
null
)
return
null
;
// https://stackoverflow.com/questions/18263489/why-doesnt-string-switch-statement-support-a-null-case
// https://stackoverflow.com/questions/27251456/start-browser-via-intent-url-with-schema-http-uppercase-error
scheme
=
scheme
.
toLowerCase
();
// For resiliency, since RFC 2396 says scheme names are lowercase.
if
(
DocumentsContract
.
isDocumentUri
(
context
,
uri
))
{
if
(
"com.android.externalstorage.documents"
.
equals
(
authority
))
{
// ExternalStorageProvider
final
String
documentId
=
DocumentsContract
.
getDocumentId
(
uri
);
final
String
[]
split
=
documentId
.
split
(
":"
);
final
String
type
=
split
[
0
];
if
(
"primary"
.
equalsIgnoreCase
(
type
))
{
return
new
File
(
Environment
.
getExternalStorageDirectory
(),
split
[
1
]).
getPath
();
}
// TODO handle non-primary volumes
}
else
if
(
"com.android.providers.downloads.documents"
.
equals
(
authority
))
{
// DownloadsProvider
return
getDataColumn
(
context
,
uri
,
null
/* selection*/
,
null
/* selectionArgs */
);
}
else
if
(
"com.android.providers.media.documents"
.
equals
(
authority
))
{
// MediaProvider
final
String
documentId
=
DocumentsContract
.
getDocumentId
(
uri
);
final
String
[]
split
=
documentId
.
split
(
":"
);
final
String
type
=
split
[
0
];
final
Uri
contentUri
;
if
(
"image"
.
equals
(
type
))
{
contentUri
=
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
;
}
else
if
(
"video"
.
equals
(
type
))
{
contentUri
=
MediaStore
.
Video
.
Media
.
EXTERNAL_CONTENT_URI
;
}
else
if
(
"audio"
.
equals
(
type
))
{
contentUri
=
MediaStore
.
Audio
.
Media
.
EXTERNAL_CONTENT_URI
;
}
else
{
contentUri
=
null
;
}
final
String
selection
=
"_id=?"
;
final
String
[]
selectionArgs
=
new
String
[]
{
split
[
1
]
};
return
getDataColumn
(
context
,
contentUri
,
selection
,
selectionArgs
);
}
}
else
if
(
"content"
.
equals
(
scheme
))
{
// MediaStore for most cases
// content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F75209/ACTUAL
if
(
"com.google.android.apps.photos.contentprovider"
.
equals
(
uri
.
getAuthority
()))
return
uri
.
getLastPathSegment
();
else
return
getDataColumn
(
context
,
uri
,
null
/* selection*/
,
null
/* selectionArgs */
);
}
else
if
(
"file"
.
equals
(
scheme
))
{
// file
return
uri
.
getPath
();
}
return
null
;
}
/**
* Get the value of the data column for this Uri. This is useful for MediaStore Uris, and other
* file-based ContentProviders.
*
* @param context The context.
* @param uri The Uri to query.
* @param selection (Optional) Filter used in the query.
* @param selectionArgs (Optional) Selection arguments used in the query.
* @return The value of the _data column, which is typically a file path.
*/
private
static
String
getDataColumn
(
Context
context
,
Uri
uri
,
String
selection
,
String
[]
selectionArgs
)
{
// Though MediaStore.Video.Media.DATA is used here, actually "_data" is the key. So DATA
// here can be MediaStore.Images.Media.DATA or MediaStore.Audio.Media.DATA, etc.
final
String
DATA
=
MediaStore
.
Video
.
Media
.
DATA
;
final
String
[]
projection
=
{
DATA
};
Cursor
cursor
=
context
.
getContentResolver
().
query
(
uri
,
projection
,
selection
,
selectionArgs
,
null
/* sortOrder */
);
if
(
cursor
!=
null
)
{
cursor
.
moveToFirst
();
int
index
=
cursor
.
getColumnIndex
(
DATA
);
// if(index >= 0)
String
data
=
cursor
.
getString
(
index
);
cursor
.
close
();
return
data
;
}
return
null
;
}
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/ChatPromptViewManager.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.widget
;
import
android.app.Activity
;
import
android.view.View
;
/**
* Created by chenpengfei on 2016/11/2.
*/
public
class
ChatPromptViewManager
extends
PromptViewHelper
.
PromptViewManager
{
public
ChatPromptViewManager
(
Activity
activity
,
String
[]
dataArray
,
Location
location
)
{
super
(
activity
,
dataArray
,
location
);
}
public
ChatPromptViewManager
(
Activity
activity
)
{
this
(
activity
,
new
String
[]{
"复制"
},
Location
.
TOP_LEFT
);
}
public
ChatPromptViewManager
(
Activity
activity
,
Location
location
)
{
this
(
activity
,
new
String
[]{
"复制"
},
location
);
}
@Override
public
View
inflateView
()
{
return
new
PromptView
(
activity
);
}
@Override
public
void
bindData
(
View
view
,
String
[]
dataArray
)
{
if
(
view
instanceof
PromptView
)
{
PromptView
promptView
=
(
PromptView
)
view
;
promptView
.
setContentArray
(
dataArray
);
promptView
.
setOnItemClickListener
(
new
PromptView
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
int
position
)
{
if
(
onItemClickListener
!=
null
)
onItemClickListener
.
onItemClick
(
position
);
}
});
}
}
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/Location.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.widget
;
import
com.doujiao.xiaozhihuiassistant.widget.location.BottomCenterLocation
;
import
com.doujiao.xiaozhihuiassistant.widget.location.ICalculateLocation
;
import
com.doujiao.xiaozhihuiassistant.widget.location.TopCenterLocation
;
import
com.doujiao.xiaozhihuiassistant.widget.location.TopLeftLocation
;
import
com.doujiao.xiaozhihuiassistant.widget.location.TopRightLocation
;
/**
* Created by chenpengfei on 2016/11/2.
*/
public
enum
Location
{
TOP_LEFT
(
1
),
TOP_CENTER
(
2
),
TOP_RIGHT
(
3
),
BOTTOM_LEFT
(
4
),
BOTTOM_CENTER
(
5
),
BOTTOM_RIGHT
(
6
);
ICalculateLocation
calculateLocation
;
private
Location
(
int
type
)
{
switch
(
type
)
{
case
1
:
calculateLocation
=
new
TopLeftLocation
();
break
;
case
2
:
calculateLocation
=
new
TopCenterLocation
();
break
;
case
3
:
calculateLocation
=
new
TopRightLocation
();
break
;
case
4
:
calculateLocation
=
new
TopLeftLocation
();
break
;
case
5
:
calculateLocation
=
new
BottomCenterLocation
();
break
;
case
6
:
calculateLocation
=
new
TopLeftLocation
();
break
;
}
}
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/PromptView.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.widget
;
import
android.annotation.TargetApi
;
import
android.content.Context
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.Paint
;
import
android.graphics.Path
;
import
android.graphics.Rect
;
import
android.graphics.RectF
;
import
android.os.Build
;
import
android.util.AttributeSet
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Created by chenpengfei on 2016/10/27.
*/
public
class
PromptView
extends
View
{
private
Paint
mPaint
;
private
int
mSingleWidth
=
120
,
mSingleHeight
=
60
;
private
int
mLineWidth
=
1
;
private
int
mArrowWidth
=
45
,
mArrowHeight
=
20
;
private
String
[]
mContentArray
=
null
;
private
List
<
Rect
>
textRectList
=
new
ArrayList
<>();
private
List
<
RectF
>
rectFList
=
new
ArrayList
<>();
private
OnItemClickListener
onItemClickListener
;
public
PromptView
(
Context
context
)
{
super
(
context
);
init
();
}
public
PromptView
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
}
public
PromptView
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
init
();
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
public
PromptView
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
,
int
defStyleRes
)
{
super
(
context
,
attrs
,
defStyleAttr
,
defStyleRes
);
}
private
void
init
()
{
mPaint
=
new
Paint
();
mPaint
.
setAntiAlias
(
true
);
mPaint
.
setStyle
(
Paint
.
Style
.
FILL
);
mPaint
.
setTextSize
(
30
);
}
@Override
protected
void
onMeasure
(
int
widthMeasureSpec
,
int
heightMeasureSpec
)
{
int
width
=
mSingleWidth
*
mContentArray
.
length
+
((
mContentArray
.
length
-
1
)
*
mLineWidth
);
setMeasuredDimension
(
width
,
mSingleHeight
+
mArrowHeight
);
}
public
void
setContentArray
(
String
[]
contentArray
)
{
mContentArray
=
contentArray
;
for
(
int
m
=
0
;
m
<
mContentArray
.
length
;
m
++)
{
Rect
rect
=
new
Rect
();
mPaint
.
getTextBounds
(
mContentArray
[
m
],
0
,
mContentArray
[
m
].
length
(),
rect
);
textRectList
.
add
(
rect
);
}
}
@Override
protected
void
onDraw
(
Canvas
canvas
)
{
if
(
mContentArray
==
null
)
return
;
for
(
int
i
=
0
;
i
<
mContentArray
.
length
;
i
++)
{
drawPromptRect
(
canvas
,
i
);
}
//绘制下面的提示箭头
drawArrow
(
canvas
);
}
private
void
drawPromptRect
(
Canvas
canvas
,
int
i
)
{
mPaint
.
setColor
(
Color
.
BLACK
);
RectF
tipRectF
=
new
RectF
();
tipRectF
.
left
=
mSingleWidth
*
i
+
i
*
mLineWidth
;
tipRectF
.
top
=
0
;
tipRectF
.
right
=
tipRectF
.
left
+
mSingleWidth
;
tipRectF
.
bottom
=
mSingleHeight
;
canvas
.
drawRect
(
tipRectF
,
mPaint
);
rectFList
.
add
(
tipRectF
);
//绘制文本内容
mPaint
.
setColor
(
Color
.
WHITE
);
canvas
.
drawText
(
mContentArray
[
i
],
(
tipRectF
.
right
-
tipRectF
.
left
-
textRectList
.
get
(
i
).
width
())
/
2
+
tipRectF
.
left
,
getFontBaseLine
(),
mPaint
);
if
(
i
==
mContentArray
.
length
-
1
)
return
;
//绘制白线
RectF
lineRectf
=
new
RectF
();
lineRectf
.
left
=
tipRectF
.
right
;
lineRectf
.
top
=
0
;
lineRectf
.
right
=
lineRectf
.
left
+
mLineWidth
;
lineRectf
.
bottom
=
mSingleHeight
;
canvas
.
drawRect
(
lineRectf
,
mPaint
);
}
private
void
drawArrow
(
Canvas
canvas
)
{
mPaint
.
setColor
(
Color
.
BLACK
);
Path
arrowPath
=
new
Path
();
int
start
=
(
getWidth
()
-
mArrowWidth
)
/
2
;
arrowPath
.
moveTo
(
start
,
mSingleHeight
);
arrowPath
.
lineTo
(
start
+
mArrowWidth
/
2
,
mSingleHeight
+
mArrowHeight
);
arrowPath
.
lineTo
(
start
+
mArrowWidth
,
mSingleHeight
);
canvas
.
drawPath
(
arrowPath
,
mPaint
);
}
private
int
getFontBaseLine
()
{
Paint
.
FontMetricsInt
fontMetrics
=
mPaint
.
getFontMetricsInt
();
return
(
getMeasuredHeight
()
-
mArrowHeight
)
/
2
+
(
fontMetrics
.
descent
-
fontMetrics
.
ascent
)
/
2
-
fontMetrics
.
descent
;
}
@Override
public
boolean
onTouchEvent
(
MotionEvent
event
)
{
switch
(
event
.
getAction
())
{
case
MotionEvent
.
ACTION_UP
:
for
(
int
n
=
0
;
n
<
rectFList
.
size
();
n
++)
{
RectF
rect
=
rectFList
.
get
(
n
);
if
(
event
.
getX
()
>
rect
.
left
&&
event
.
getX
()
<
rect
.
right
&&
event
.
getY
()
>
rect
.
top
&&
event
.
getY
()
<
rect
.
bottom
&&
onItemClickListener
!=
null
)
{
onItemClickListener
.
onItemClick
(
n
);
break
;
}
}
break
;
}
return
true
;
}
public
void
setOnItemClickListener
(
OnItemClickListener
onItemClickListener
)
{
this
.
onItemClickListener
=
onItemClickListener
;
}
public
interface
OnItemClickListener
{
void
onItemClick
(
int
position
);
}
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/PromptViewHelper.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.widget
;
import
android.app.Activity
;
import
android.graphics.Color
;
import
android.graphics.drawable.ColorDrawable
;
import
android.view.Gravity
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewTreeObserver
;
import
android.widget.PopupWindow
;
/**
* Created by chenpengfei on 2016/11/2.
*/
public
class
PromptViewHelper
{
private
PromptViewManager
promptViewManager
;
private
Activity
activity
;
private
PopupWindow
popupWindow
;
private
boolean
isShow
;
private
OnItemClickListener
onItemClickListener
;
public
PromptViewHelper
(
Activity
activity
)
{
this
.
activity
=
activity
;
}
public
void
setPromptViewManager
(
PromptViewManager
promptViewManager
)
{
this
.
promptViewManager
=
promptViewManager
;
this
.
promptViewManager
.
setOnItemClickListener
(
new
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
int
position
)
{
if
(
onItemClickListener
!=
null
&&
popupWindow
!=
null
)
{
onItemClickListener
.
onItemClick
(
position
);
popupWindow
.
dismiss
();
}
}
});
}
public
void
addPrompt
(
View
srcView
)
{
srcView
.
setOnLongClickListener
(
new
View
.
OnLongClickListener
()
{
@Override
public
boolean
onLongClick
(
View
v
)
{
createPrompt
(
v
);
return
true
;
}
});
}
private
void
createPrompt
(
final
View
srcView
)
{
final
View
promptView
=
promptViewManager
.
getPromptView
();
if
(
popupWindow
==
null
)
popupWindow
=
new
PopupWindow
(
activity
);
popupWindow
.
setWindowLayoutMode
(
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
);
popupWindow
.
setTouchable
(
true
);
popupWindow
.
setOutsideTouchable
(
true
);
popupWindow
.
setBackgroundDrawable
(
new
ColorDrawable
(
Color
.
TRANSPARENT
));
popupWindow
.
setContentView
(
promptView
);
final
int
[]
location
=
new
int
[
2
];
promptView
.
getViewTreeObserver
().
addOnGlobalLayoutListener
(
new
ViewTreeObserver
.
OnGlobalLayoutListener
()
{
@Override
public
void
onGlobalLayout
()
{
if
(!
isShow
&&
popupWindow
.
isShowing
())
{
popupWindow
.
dismiss
();
show
(
srcView
,
promptView
,
location
);
isShow
=
true
;
}
}
});
srcView
.
getLocationOnScreen
(
location
);
show
(
srcView
,
promptView
,
location
);
}
public
void
show
(
View
srcView
,
View
promptView
,
int
[]
srcViewLocation
)
{
int
[]
xy
=
promptViewManager
.
getLocation
().
calculateLocation
.
calculate
(
srcViewLocation
,
srcView
,
promptView
);
popupWindow
.
showAtLocation
(
srcView
,
Gravity
.
NO_GRAVITY
,
xy
[
0
],
xy
[
1
]);
}
public
static
abstract
class
PromptViewManager
{
private
View
promptView
;
protected
Activity
activity
;
private
String
[]
dataArray
;
private
Location
location
;
public
OnItemClickListener
onItemClickListener
;
public
PromptViewManager
(
Activity
activity
,
String
[]
dataArray
,
Location
location
)
{
this
.
activity
=
activity
;
this
.
dataArray
=
dataArray
;
this
.
location
=
location
;
init
();
}
public
void
setOnItemClickListener
(
OnItemClickListener
onItemClickListener
)
{
this
.
onItemClickListener
=
onItemClickListener
;
}
public
void
init
()
{
promptView
=
inflateView
();
bindData
(
promptView
,
dataArray
);
}
public
abstract
View
inflateView
();
public
abstract
void
bindData
(
View
view
,
String
[]
dataArray
);
public
View
getPromptView
()
{
return
promptView
;
}
public
Location
getLocation
()
{
return
location
;
}
}
public
void
setOnItemClickListener
(
OnItemClickListener
onItemClickListener
)
{
this
.
onItemClickListener
=
onItemClickListener
;
}
public
interface
OnItemClickListener
{
void
onItemClick
(
int
position
);
}
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/BottomCenterLocation.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.widget.location
;
import
android.view.View
;
/**
* Created by chenpengfei on 2016/11/2.
*/
public
class
BottomCenterLocation
implements
ICalculateLocation
{
@Override
public
int
[]
calculate
(
int
[]
srcViewLocation
,
View
srcView
,
View
promptView
)
{
int
[]
location
=
new
int
[
2
];
int
offset
=
(
promptView
.
getWidth
()
-
srcView
.
getWidth
())
/
2
;
location
[
0
]
=
srcViewLocation
[
0
]
-
offset
;
location
[
1
]
=
srcViewLocation
[
1
]
+
promptView
.
getHeight
();
return
location
;
}
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/ICalculateLocation.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.widget.location
;
import
android.view.View
;
/**
* Created by chenpengfei on 2016/11/2.
*/
public
interface
ICalculateLocation
{
int
[]
calculate
(
int
[]
srcViewLocation
,
View
srcView
,
View
promptView
);
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/TopCenterLocation.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.widget.location
;
import
android.view.View
;
/**
* Created by chenpengfei on 2016/11/2.
*/
public
class
TopCenterLocation
implements
ICalculateLocation
{
@Override
public
int
[]
calculate
(
int
[]
srcViewLocation
,
View
srcView
,
View
promptView
)
{
int
[]
location
=
new
int
[
2
];
int
offset
=
(
promptView
.
getWidth
()
-
srcView
.
getWidth
())
/
2
;
location
[
0
]
=
srcViewLocation
[
0
]
-
offset
;
location
[
1
]
=
srcViewLocation
[
1
]
-
promptView
.
getHeight
();
return
location
;
}
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/TopLeftLocation.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.widget.location
;
import
android.view.View
;
/**
* Created by chenpengfei on 2016/11/2.
*/
public
class
TopLeftLocation
implements
ICalculateLocation
{
@Override
public
int
[]
calculate
(
int
[]
srcViewLocation
,
View
srcView
,
View
promptView
)
{
int
[]
location
=
new
int
[
2
];
location
[
0
]
=
srcViewLocation
[
0
];
location
[
1
]
=
srcViewLocation
[
1
]
-
promptView
.
getHeight
();
return
location
;
}
}
example/Android/LLMAssistant/app/src/main/java/com/doujiao/xiaozhihuiassistant/widget/location/TopRightLocation.java
0 → 100644
View file @
aefd9f11
package
com.doujiao.xiaozhihuiassistant.widget.location
;
import
android.view.View
;
/**
* Created by chenpengfei on 2016/11/2.
*/
public
class
TopRightLocation
implements
ICalculateLocation
{
@Override
public
int
[]
calculate
(
int
[]
srcViewLocation
,
View
srcView
,
View
promptView
)
{
int
[]
location
=
new
int
[
2
];
int
offset
=
promptView
.
getWidth
()
-
srcView
.
getWidth
();
location
[
0
]
=
srcViewLocation
[
0
]
-
offset
;
location
[
1
]
=
srcViewLocation
[
1
]
-
promptView
.
getHeight
();
return
location
;
}
}
example/Android/LLMAssistant/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
0 → 100644
View file @
aefd9f11
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:aapt=
"http://schemas.android.com/aapt"
android:width=
"108dp"
android:height=
"108dp"
android:viewportWidth=
"108"
android:viewportHeight=
"108"
>
<path
android:pathData=
"M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"
>
<aapt:attr
name=
"android:fillColor"
>
<gradient
android:endX=
"85.84757"
android:endY=
"92.4963"
android:startX=
"42.9492"
android:startY=
"49.59793"
android:type=
"linear"
>
<item
android:color=
"#44000000"
android:offset=
"0.0"
/>
<item
android:color=
"#00000000"
android:offset=
"1.0"
/>
</gradient>
</aapt:attr>
</path>
<path
android:fillColor=
"#FFFFFF"
android:fillType=
"nonZero"
android:pathData=
"M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth=
"1"
android:strokeColor=
"#00000000"
/>
</vector>
\ No newline at end of file
example/Android/LLMAssistant/app/src/main/res/drawable/btnbg.xml
0 → 100644
View file @
aefd9f11
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item>
<shape
android:shape=
"rectangle"
>
<solid
android:color=
"#4e72b8"
/>
<corners
android:radius=
"10dp"
/>
<stroke
android:width=
"0dp"
android:color=
"#505050"
/>
</shape>
</item>
</layer-list>
\ No newline at end of file
example/Android/LLMAssistant/app/src/main/res/drawable/editbg.xml
0 → 100644
View file @
aefd9f11
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item>
<shape
android:shape=
"rectangle"
>
<solid
android:color=
"@color/gray"
/>
<corners
android:radius=
"10dp"
/>
<stroke
android:width=
"0dp"
android:color=
"#505050"
/>
</shape>
</item>
</layer-list>
\ No newline at end of file
example/Android/LLMAssistant/app/src/main/res/drawable/ic_launcher_background.xml
0 → 100644
View file @
aefd9f11
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:width=
"108dp"
android:height=
"108dp"
android:viewportWidth=
"108"
android:viewportHeight=
"108"
>
<path
android:fillColor=
"#3DDC84"
android:pathData=
"M0,0h108v108h-108z"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M9,0L9,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,0L19,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M29,0L29,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M39,0L39,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M49,0L49,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M59,0L59,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M69,0L69,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M79,0L79,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M89,0L89,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M99,0L99,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,9L108,9"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,19L108,19"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,29L108,29"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,39L108,39"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,49L108,49"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,59L108,59"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,69L108,69"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,79L108,79"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,89L108,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,99L108,99"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,29L89,29"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,39L89,39"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,49L89,49"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,59L89,59"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,69L89,69"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,79L89,79"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M29,19L29,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M39,19L39,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M49,19L49,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M59,19L59,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M69,19L69,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M79,19L79,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
</vector>
example/Android/LLMAssistant/app/src/main/res/layout/activity_item_left.xml
0 → 100644
View file @
aefd9f11
<?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=
"wrap_content"
android:orientation=
"horizontal"
>
<ImageView
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:src=
"@mipmap/me"
/>
<TextView
android:id=
"@+id/textview_content"
android:layout_width=
"270dp"
android:layout_height=
"wrap_content"
android:padding=
"10dp"
android:layout_marginLeft=
"5dp"
android:layout_marginRight=
"60dp"
android:textSize=
"16sp"
/>
</LinearLayout>
example/Android/LLMAssistant/app/src/main/res/layout/activity_item_right.xml
0 → 100644
View file @
aefd9f11
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
>
<ImageView
android:id=
"@+id/tx"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:layout_alignParentRight=
"true"
android:src=
"@mipmap/glm"
/>
<TextView
android:id=
"@+id/textview_content"
android:background=
"@drawable/editbg"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_toLeftOf=
"@id/tx"
android:textAlignment=
"viewStart"
android:gravity=
"right"
android:padding=
"10dp"
android:layout_marginRight=
"5dp"
android:layout_marginLeft=
"60dp"
android:textSize=
"16sp"
tools:ignore=
"RtlCompat"
/>
</RelativeLayout>
example/Android/LLMAssistant/app/src/main/res/layout/activity_main.xml
0 → 100644
View file @
aefd9f11
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:fitsSystemWindows=
"true"
tools:context=
".MainActivity"
>
<LinearLayout
android:id=
"@+id/layout_top"
android:background=
"@color/purple_200"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"5dp"
android:orientation=
"horizontal"
>
<TextView
android:layout_width=
"70dp"
android:layout_height=
"wrap_content"
android:text=
"@string/app_model"
/>
<TextView
android:id=
"@+id/tv_tips"
android:layout_width=
"240dp"
android:layout_height=
"wrap_content"
android:text=
"@string/app_model_tips"
/>
<Button
android:id=
"@+id/btn_sel"
android:layout_width=
"70dp"
android:background=
"@drawable/btnbg"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"10dp"
android:textColor=
"@android:color/white"
android:text=
"@string/app_sel_model"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id=
"@+id/rv_msgs"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:padding=
"5dp"
android:layout_below=
"@+id/layout_top"
android:layout_above=
"@+id/layout_bottom"
/>
<LinearLayout
android:id=
"@+id/layout_bottom"
android:layout_width=
"match_parent"
android:layout_height=
"70dp"
android:layout_marginTop=
"10dp"
android:background=
"@color/gray"
android:layout_alignParentBottom=
"true"
android:orientation=
"horizontal"
>
<EditText
android:background=
"@drawable/editbg"
android:id=
"@+id/edit_input"
android:layout_gravity=
"center_vertical"
android:layout_marginLeft=
"10dp"
android:padding=
"5dp"
android:layout_width=
"300dp"
android:layout_height=
"60dp"
/>
<Button
android:id=
"@+id/btn_send"
android:layout_marginLeft=
"3dp"
android:background=
"@drawable/btnbg"
android:layout_width=
"wrap_content"
android:layout_height=
"50dp"
android:textColor=
"@android:color/white"
android:layout_gravity=
"center_vertical"
android:text=
"发送"
/>
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
example/Android/LLMAssistant/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
0 → 100644
View file @
aefd9f11
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<background
android:drawable=
"@drawable/ic_launcher_background"
/>
<foreground
android:drawable=
"@drawable/ic_launcher_foreground"
/>
</adaptive-icon>
\ No newline at end of file
example/Android/LLMAssistant/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
0 → 100644
View file @
aefd9f11
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<background
android:drawable=
"@drawable/ic_launcher_background"
/>
<foreground
android:drawable=
"@drawable/ic_launcher_foreground"
/>
</adaptive-icon>
\ No newline at end of file
Prev
1
2
3
4
5
6
7
…
10
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment