font, maxnum 自定义控件
This commit is contained in:
		
							parent
							
								
									94467ea83b
								
							
						
					
					
						commit
						9b71247893
					
				|  | @ -0,0 +1,50 @@ | |||
| package com.remax.visualnovel.ui.chat.ui | ||||
| 
 | ||||
| import android.content.Context | ||||
| import android.util.AttributeSet | ||||
| import android.view.LayoutInflater | ||||
| import android.widget.LinearLayout | ||||
| import com.remax.visualnovel.databinding.LayoutFontSetViewBinding | ||||
| 
 | ||||
| 
 | ||||
| class FontSetView @JvmOverloads constructor( | ||||
|     context: Context, | ||||
|     attrs: AttributeSet? = null, | ||||
|     defStyleAttr: Int = 0 | ||||
| ) : LinearLayout(context, attrs, defStyleAttr) { | ||||
| 
 | ||||
|     companion object { | ||||
|         private var GAP = 1 | ||||
|     } | ||||
| 
 | ||||
|     private var mBinding: LayoutFontSetViewBinding | ||||
| 
 | ||||
|     private var mFontValue = 20 | ||||
| 
 | ||||
|     init { | ||||
|         mBinding = LayoutFontSetViewBinding.inflate(LayoutInflater.from(context), this, true) | ||||
|         setupClickListeners() | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     private fun setupClickListeners() { | ||||
|         with (mBinding) { | ||||
|             ivFontPlus.setOnClickListener { | ||||
|                 mFontValue -= GAP | ||||
|                 tvFontValue.text = mFontValue.toString() | ||||
|             } | ||||
| 
 | ||||
|             ivFontAdd.setOnClickListener { | ||||
|                 mFontValue += GAP | ||||
|                 tvFontValue.text = mFontValue.toString() | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,88 @@ | |||
| package com.remax.visualnovel.ui.chat.ui | ||||
| 
 | ||||
| import android.content.Context | ||||
| import android.util.AttributeSet | ||||
| import android.view.LayoutInflater | ||||
| import android.widget.LinearLayout | ||||
| import com.remax.visualnovel.databinding.LayoutMaxNumViewBinding | ||||
| 
 | ||||
| class MaxNumView @JvmOverloads constructor( | ||||
|     context: Context, | ||||
|     attrs: AttributeSet? = null, | ||||
|     defStyleAttr: Int = 0 | ||||
| ) : LinearLayout(context, attrs, defStyleAttr) { | ||||
| 
 | ||||
|     companion object { | ||||
|         private var GAP = 100 | ||||
|     } | ||||
| 
 | ||||
|     private var mBinding: LayoutMaxNumViewBinding | ||||
| 
 | ||||
|     private var mCurNum = 2500 | ||||
| 
 | ||||
|     init { | ||||
|         mBinding = LayoutMaxNumViewBinding.inflate(LayoutInflater.from(context), this, true) | ||||
|         setupClickListeners() | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     private fun setupClickListeners() { | ||||
|         with (mBinding) { | ||||
|             ivLeftIcon.setOnClickListener { | ||||
|                 mCurNum -= GAP | ||||
|                 tvCenter.text = mCurNum.toString() | ||||
|             } | ||||
| 
 | ||||
|             ivRightIcon.setOnClickListener { | ||||
|                 mCurNum += GAP | ||||
|                 tvCenter.text = mCurNum.toString() | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     /*override fun onTouchEvent(event: MotionEvent): Boolean { | ||||
|         when (event.action) { | ||||
|             MotionEvent.ACTION_DOWN -> { | ||||
|                 val x = event.x | ||||
|                 val y = event.y | ||||
| 
 | ||||
|                 if (mBinding..contains(x, y)) { | ||||
|                     isLeftPressed = true | ||||
|                     startLongPress(false) // 减小 | ||||
|                     return true | ||||
|                 } else if (rightArrowRect.contains(x, y)) { | ||||
|                     isRightPressed = true | ||||
|                     startLongPress(true) // 增大 | ||||
|                     return true | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { | ||||
|                 stopLongPress() | ||||
|             } | ||||
| 
 | ||||
|             MotionEvent.ACTION_MOVE -> { | ||||
|                 val x = event.x | ||||
|                 val y = event.y | ||||
| 
 | ||||
|                 // 如果手指移出按钮区域,停止长按 | ||||
|                 if (!leftArrowRect.contains(x, y) && isLeftPressed) { | ||||
|                     stopLongPress() | ||||
|                 } | ||||
|                 if (!rightArrowRect.contains(x, y) && isRightPressed) { | ||||
|                     stopLongPress() | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         invalidate() | ||||
|         return super.onTouchEvent(event) | ||||
|     }*/ | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | @ -36,6 +36,7 @@ class ExpandSelectView @JvmOverloads constructor( | |||
| 
 | ||||
|     private fun initView(context: Context, attrs: AttributeSet?) { | ||||
|         mBinding = LayoutExpandSelectViewBinding.inflate(LayoutInflater.from(context), this, true) | ||||
|         mBinding.itemsContainer.setBackgroundResource(R.drawable.bg_expand_view_items) | ||||
|         setupAttributes(attrs) | ||||
|         setupClickListeners() | ||||
|     } | ||||
|  |  | |||
|  | @ -193,8 +193,11 @@ | |||
|             android:layout_height="wrap_content" | ||||
|             android:orientation="vertical" | ||||
|             android:layout_marginTop="10dp" > | ||||
| 
 | ||||
| 
 | ||||
|             <com.remax.visualnovel.ui.chat.ui.MaxNumView | ||||
|                 android:id="@+id/max_response_num_view" | ||||
|                 android:layout_width="match_parent" | ||||
|                 android:layout_height="wrap_content" | ||||
|                 /> | ||||
|         </com.remax.visualnovel.widget.uitoken.view.UITokenLinearLayout> | ||||
| 
 | ||||
| 
 | ||||
|  | @ -213,6 +216,11 @@ | |||
|             android:layout_height="wrap_content" | ||||
|             android:orientation="vertical" | ||||
|             android:layout_marginTop="10dp" > | ||||
|             <com.remax.visualnovel.ui.chat.ui.FontSetView | ||||
|                 android:id="@+id/font_set_view" | ||||
|                 android:layout_width="match_parent" | ||||
|                 android:layout_height="wrap_content" | ||||
|                 /> | ||||
| 
 | ||||
|         </com.remax.visualnovel.widget.uitoken.view.UITokenLinearLayout> | ||||
| 
 | ||||
|  |  | |||
|  | @ -47,7 +47,6 @@ | |||
|         android:layout_height="wrap_content" | ||||
|         android:orientation="vertical" | ||||
|         android:layout_marginTop="@dimen/dp_2" | ||||
|         android:background="@drawable/bg_expand_view_items" | ||||
|         android:visibility="gone"/> | ||||
| 
 | ||||
| </LinearLayout> | ||||
|  | @ -0,0 +1,75 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <com.remax.visualnovel.widget.uitoken.view.UITokenRelativeLayout | ||||
|     xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     android:id="@+id/titleLayout" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="wrap_content" | ||||
|     app:backgroundColorToken="@string/color_chat_setting_item_bg" | ||||
|     app:radiusToken="@string/radius_m" | ||||
|     android:paddingVertical="@dimen/dp_12" | ||||
|     android:paddingHorizontal="@dimen/dp_17" | ||||
|     > | ||||
| 
 | ||||
|     <com.remax.visualnovel.widget.uitoken.view.UITokenLinearLayout | ||||
|         android:id="@+id/left_container" | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="match_parent" | ||||
|         android:gravity="center_vertical" | ||||
|         android:orientation="horizontal"> | ||||
|         <com.remax.visualnovel.widget.uitoken.view.UITokenImageView | ||||
|             android:id="@+id/iv_left_icon" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="match_parent" | ||||
|             android:layout_centerVertical="true" | ||||
|             android:src="@mipmap/setting_font_icon"/> | ||||
| 
 | ||||
|         <com.remax.visualnovel.widget.uitoken.view.UITokenTextView | ||||
|             android:id="@+id/tv_title" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_marginStart="@dimen/dp_10" | ||||
|             android:layout_marginEnd="@dimen/dp_50" | ||||
|             android:textSize="@dimen/sp_14" | ||||
|             android:textColor="@color/gray6" | ||||
|             android:gravity="center" | ||||
|             android:textStyle="bold" | ||||
|             android:text="@string/font_size" | ||||
|             /> | ||||
|     </com.remax.visualnovel.widget.uitoken.view.UITokenLinearLayout> | ||||
| 
 | ||||
|     <RelativeLayout | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="match_parent" | ||||
|         android:layout_toEndOf="@+id/left_container"> | ||||
|         <com.remax.visualnovel.widget.uitoken.view.UITokenImageView | ||||
|             android:id="@+id/iv_font_plus" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="match_parent" | ||||
|             android:layout_centerVertical="true" | ||||
|             android:src="@mipmap/setting_font_plus"/> | ||||
| 
 | ||||
|         <com.remax.visualnovel.widget.uitoken.view.UITokenTextView | ||||
|             android:id="@+id/tv_font_value" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_toEndOf="@id/iv_font_plus" | ||||
|             android:layout_toStartOf="@+id/iv_font_add" | ||||
|             android:layout_centerVertical="true" | ||||
|             android:textSize="@dimen/sp_14" | ||||
|             android:textColor="@color/gray6" | ||||
|             android:gravity="center" | ||||
|             android:textStyle="bold" | ||||
|             android:text="20" | ||||
|             /> | ||||
| 
 | ||||
|         <com.remax.visualnovel.widget.uitoken.view.UITokenImageView | ||||
|             android:id="@+id/iv_font_add" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="match_parent" | ||||
|             android:layout_alignParentEnd="true" | ||||
|             android:layout_centerVertical="true" | ||||
|             android:src="@mipmap/setting_font_add"/> | ||||
|     </RelativeLayout> | ||||
| 
 | ||||
| </com.remax.visualnovel.widget.uitoken.view.UITokenRelativeLayout> | ||||
|  | @ -1,53 +1,43 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
| <com.remax.visualnovel.widget.uitoken.view.UITokenRelativeLayout | ||||
|     xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     android:id="@+id/titleLayout" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="wrap_content" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     android:orientation="vertical"> | ||||
|     app:backgroundColorToken="@string/color_chat_setting_item_bg" | ||||
|     app:radiusToken="@string/radius_m" | ||||
|     android:paddingVertical="@dimen/dp_12" | ||||
|     android:paddingHorizontal="@dimen/dp_17" | ||||
|     > | ||||
| 
 | ||||
|     <com.remax.visualnovel.widget.uitoken.view.UITokenRelativeLayout | ||||
|         android:id="@+id/titleLayout" | ||||
|         android:layout_width="match_parent" | ||||
|     <com.remax.visualnovel.widget.uitoken.view.UITokenImageView | ||||
|         android:id="@+id/iv_left_icon" | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="match_parent" | ||||
|         android:layout_centerVertical="true" | ||||
|         android:src="@mipmap/num_setting_left"/> | ||||
| 
 | ||||
|     <com.remax.visualnovel.widget.uitoken.view.UITokenTextView | ||||
|         android:id="@+id/tv_center" | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="wrap_content" | ||||
|         app:backgroundColorToken="@string/color_chat_setting_item_bg" | ||||
|         app:radiusToken="@string/radius_m" | ||||
|         android:padding="@dimen/dp_12" | ||||
|         > | ||||
|         android:layout_toEndOf="@id/iv_left_icon" | ||||
|         android:layout_toStartOf="@+id/iv_right_icon" | ||||
|         android:layout_centerVertical="true" | ||||
|         android:textSize="@dimen/sp_14" | ||||
|         android:textColor="@color/gray6" | ||||
|         android:gravity="center" | ||||
|         android:textStyle="bold" | ||||
|         android:text="2500" | ||||
|         /> | ||||
| 
 | ||||
|         <com.remax.visualnovel.widget.uitoken.view.UITokenImageView | ||||
|             android:id="@+id/icon" | ||||
|             android:layout_width="24dp" | ||||
|             android:layout_height="24dp" | ||||
|             android:layout_centerVertical="true" /> | ||||
|     <com.remax.visualnovel.widget.uitoken.view.UITokenImageView | ||||
|         android:id="@+id/iv_right_icon" | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="match_parent" | ||||
|         android:layout_alignParentEnd="true" | ||||
|         android:layout_centerVertical="true" | ||||
|         android:src="@mipmap/num_setting_right"/> | ||||
| 
 | ||||
|         <com.remax.visualnovel.widget.uitoken.view.UITokenTextView | ||||
|             android:id="@+id/titleText" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_toEndOf="@id/icon" | ||||
|             android:layout_centerVertical="true" | ||||
|             android:layout_marginStart="12dp" | ||||
|             android:textSize="16sp" | ||||
|             android:textColor="#333333" | ||||
|             android:textStyle="normal"/> | ||||
| 
 | ||||
|         <com.remax.visualnovel.widget.uitoken.view.UITokenImageView | ||||
|             android:id="@+id/arrow" | ||||
|             android:layout_width="16dp" | ||||
|             android:layout_height="16dp" | ||||
|             android:layout_alignParentEnd="true" | ||||
|             android:layout_centerVertical="true" | ||||
|             android:src="@mipmap/setting_arrow_right"/> | ||||
| 
 | ||||
|     </com.remax.visualnovel.widget.uitoken.view.UITokenRelativeLayout> | ||||
| 
 | ||||
|     <com.remax.visualnovel.widget.uitoken.view.UITokenLinearLayout | ||||
|         android:id="@+id/itemsContainer" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:orientation="vertical" | ||||
|         android:layout_marginTop="@dimen/dp_2" | ||||
|         android:background="@drawable/bg_expand_view_items" | ||||
|         android:visibility="gone"/> | ||||
| 
 | ||||
| </LinearLayout> | ||||
| </com.remax.visualnovel.widget.uitoken.view.UITokenRelativeLayout> | ||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.1 KiB | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.1 KiB | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.3 KiB | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 628 B | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.2 KiB | 
|  | @ -479,5 +479,6 @@ | |||
|     <string name="short_text_mode">Short Text Mode</string> | ||||
|     <string name="play_dialogue_only">Play dialogue only</string> | ||||
|     <string name="setting_max_response_num">Maximum number of response tokens</string> | ||||
|     <string name="font_size">Font Size</string> | ||||
| 
 | ||||
| </resources> | ||||
		Loading…
	
		Reference in New Issue