Commit 4a4f324000b89c92b830fecf4c7eb57f31daea79
1 parent
abe316ce
1 搭建设备管理界面
2 自定义switch
Showing
35 changed files
with
2205 additions
and
54 deletions
app/src/main/java/com/cnlive/strike/xiaojiaspeaker/MainActivity.java
| ... | ... | @@ -10,6 +10,7 @@ import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothStep1Activity; |
| 10 | 10 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.BluetoothConnActivity; |
| 11 | 11 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.ConnBluetoothSuccessActivity; |
| 12 | 12 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.DeviceInstructionActivity; |
| 13 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.DeviceManagerActivity; | |
| 13 | 14 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.SearchDeviceActivity; |
| 14 | 15 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.SpeakerMainActivity; |
| 15 | 16 | |
| ... | ... | @@ -24,10 +25,9 @@ public class MainActivity extends AppCompatActivity { |
| 24 | 25 | // startActivity(new Intent(MainActivity.this, BluetoothConnActivity.class)); |
| 25 | 26 | // startActivity(new Intent(MainActivity.this, BlueToothStep1Activity.class)); |
| 26 | 27 | // startActivity(new Intent(MainActivity.this, ConnBluetoothSuccessActivity.class)); |
| 27 | - startActivity(new Intent(MainActivity.this, AllDeviceActivity.class)); | |
| 28 | +// startActivity(new Intent(MainActivity.this, AllDeviceActivity.class)); | |
| 28 | 29 | // startActivity(new Intent(MainActivity.this, DeviceInstructionActivity.class)); |
| 29 | -// | |
| 30 | - | |
| 30 | + startActivity(new Intent(MainActivity.this, DeviceManagerActivity.class)); | |
| 31 | 31 | finish(); |
| 32 | 32 | } |
| 33 | 33 | ... | ... |
module_xiaojiaSoundBox/src/main/AndroidManifest.xml
| ... | ... | @@ -17,7 +17,8 @@ |
| 17 | 17 | <uses-permission android:name="android.permission.INTERNET" /> |
| 18 | 18 | |
| 19 | 19 | <application> |
| 20 | - <activity android:name=".ui.activity.DeviceInstructionActivity"></activity> | |
| 20 | + <activity android:name=".ui.activity.DeviceManagerActivity"></activity> | |
| 21 | + <activity android:name=".ui.activity.DeviceInstructionActivity" /> | |
| 21 | 22 | <activity android:name=".ui.activity.AllDeviceActivity" /> |
| 22 | 23 | <activity android:name=".ui.activity.ConnBluetoothSuccessActivity" /> |
| 23 | 24 | <activity android:name=".ui.activity.SelectWifiActivity" /> | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/presenter/DeviceManagerFragmentPresenter.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.frame.presenter; | |
| 2 | + | |
| 3 | +import com.cnlive.strike.xiaojiaspeaker.frame.view.DeviceManagerFragmentView; | |
| 4 | +import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; | |
| 5 | + | |
| 6 | +public class DeviceManagerFragmentPresenter extends MvpBasePresenter<DeviceManagerFragmentView> { | |
| 7 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/DeviceManagerFragmentView.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.frame.view; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.support.v7.widget.DefaultItemAnimator; | |
| 5 | +import android.support.v7.widget.LinearLayoutManager; | |
| 6 | + | |
| 7 | +import com.cnlive.strike.xiaojiaspeaker.model.DeviceManagerMenu; | |
| 8 | +import com.cnlive.strike.xiaojiaspeaker.ui.adapter.DeviceManagerMenuAdapter; | |
| 9 | +import com.cnlive.strike.xiaojiaspeaker.ui.fragment.DeviceManagerFragment; | |
| 10 | +import com.hannesdorfmann.mosby3.mvp.MvpView; | |
| 11 | + | |
| 12 | +import java.util.ArrayList; | |
| 13 | +import java.util.List; | |
| 14 | + | |
| 15 | +public class DeviceManagerFragmentView implements MvpView { | |
| 16 | + private DeviceManagerFragment fragment; | |
| 17 | + private DeviceManagerMenuAdapter adapter; | |
| 18 | + private List<DeviceManagerMenu> deviceManagerMenuList; | |
| 19 | + | |
| 20 | + public DeviceManagerFragmentView(DeviceManagerFragment fragment) { | |
| 21 | + this.fragment = fragment; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public Activity getContext() { | |
| 25 | + return fragment == null ? null : fragment.getActivity(); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public void initView() { | |
| 29 | + deviceManagerMenuList = new ArrayList<>(); | |
| 30 | + deviceManagerMenuList.add(new DeviceManagerMenu("音箱名称", "as", DeviceManagerMenu.NO_RIGHT_ARROW)); | |
| 31 | + deviceManagerMenuList.add(new DeviceManagerMenu("WIFI设置", "asd", DeviceManagerMenu.NORMAL)); | |
| 32 | + deviceManagerMenuList.add(new DeviceManagerMenu("设备信息", "asd", DeviceManagerMenu.NO_MENU_DETAIL)); | |
| 33 | + deviceManagerMenuList.add(new DeviceManagerMenu("固件升级", "asd", DeviceManagerMenu.NORMAL)); | |
| 34 | + deviceManagerMenuList.add(new DeviceManagerMenu("远程控制", "手机可远程控制音箱播放的内容,但仅限听见中国", DeviceManagerMenu.SWITCH_NORMAL)); | |
| 35 | + deviceManagerMenuList.add(new DeviceManagerMenu("小家音箱播放", "音箱可作为蓝牙音箱,播放手机内所有声音", DeviceManagerMenu.SWITCH_NORMAL)); | |
| 36 | + | |
| 37 | + adapter=new DeviceManagerMenuAdapter(getContext(),deviceManagerMenuList); | |
| 38 | + fragment.binding.rvMenu.setLayoutManager(new LinearLayoutManager(getContext())); | |
| 39 | + fragment.binding.rvMenu.setAdapter(adapter); | |
| 40 | + ((DefaultItemAnimator) fragment.binding.rvMenu.getItemAnimator()).setSupportsChangeAnimations(false); | |
| 41 | + } | |
| 42 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/SearchDevicefragmentView.java
| ... | ... | @@ -21,6 +21,7 @@ import com.clj.fastble.exception.BleException; |
| 21 | 21 | import com.cnlive.strike.xiaojiaspeaker.R; |
| 22 | 22 | import com.cnlive.strike.xiaojiaspeaker.constants.BlufiConstants; |
| 23 | 23 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothHelpActivity; |
| 24 | +import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothStep2Activity; | |
| 24 | 25 | import com.cnlive.strike.xiaojiaspeaker.ui.activity.SelectWifiActivity; |
| 25 | 26 | import com.cnlive.strike.xiaojiaspeaker.ui.adapter.BluetoothDeviceAdapter; |
| 26 | 27 | import com.cnlive.strike.xiaojiaspeaker.ui.fragment.SearchDevicefragment; |
| ... | ... | @@ -70,6 +71,14 @@ public class SearchDevicefragmentView implements MvpView { |
| 70 | 71 | BlueToothHelpActivity.startActivity(getContext()); |
| 71 | 72 | } |
| 72 | 73 | }); |
| 74 | + //上一步按钮 | |
| 75 | + fragment.binding.tvPreviousStep.setOnClickListener(new View.OnClickListener() { | |
| 76 | + @Override | |
| 77 | + public void onClick(View view) { | |
| 78 | + BlueToothStep2Activity.startActivity(getContext()); | |
| 79 | + fragment.getActivity().finish(); | |
| 80 | + } | |
| 81 | + }); | |
| 73 | 82 | //配对按钮点击 |
| 74 | 83 | fragment.binding.btnBondDevice.setOnClickListener(new View.OnClickListener() { |
| 75 | 84 | @Override |
| ... | ... | @@ -137,7 +146,6 @@ public class SearchDevicefragmentView implements MvpView { |
| 137 | 146 | } |
| 138 | 147 | |
| 139 | 148 | |
| 140 | - | |
| 141 | 149 | /** |
| 142 | 150 | * 开始扫描蓝牙设备 |
| 143 | 151 | */ | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/model/DeviceManagerMenu.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.model; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 设备管理菜单 | |
| 5 | + * | |
| 6 | + * @author ys | |
| 7 | + */ | |
| 8 | +public class DeviceManagerMenu { | |
| 9 | + public static final int NO_RIGHT_ARROW = 0;//无箭头 | |
| 10 | + public static final int NORMAL = 1;//普通 | |
| 11 | + public static final int NO_MENU_DETAIL = 2;//没有详细说明 | |
| 12 | + public static final int SWITCH_NORMAL = 3;//有swith | |
| 13 | + | |
| 14 | + | |
| 15 | + private String menuTitle; | |
| 16 | + private String menuDetail; | |
| 17 | + private int type; | |
| 18 | + private boolean swithSelect; | |
| 19 | + | |
| 20 | + public DeviceManagerMenu() { | |
| 21 | + } | |
| 22 | + | |
| 23 | + public DeviceManagerMenu(String menuTitle, String menuDetail, int type) { | |
| 24 | + this.menuTitle = menuTitle; | |
| 25 | + this.menuDetail = menuDetail; | |
| 26 | + this.type = type; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public int getType() { | |
| 30 | + return type; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public void setType(int type) { | |
| 34 | + this.type = type; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public String getMenuTitle() { | |
| 38 | + return menuTitle; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public void setMenuTitle(String menuTitle) { | |
| 42 | + this.menuTitle = menuTitle; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public String getMenuDetail() { | |
| 46 | + return menuDetail; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public void setMenuDetail(String menuDetail) { | |
| 50 | + this.menuDetail = menuDetail; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public boolean isSwithSelect() { | |
| 54 | + return swithSelect; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void setSwithSelect(boolean swithSelect) { | |
| 58 | + this.swithSelect = swithSelect; | |
| 59 | + } | |
| 60 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/SubscriptionRequest.java
| ... | ... | @@ -66,7 +66,7 @@ public class SubscriptionRequest<Observable extends io.reactivex.Observable<Resu |
| 66 | 66 | |
| 67 | 67 | public static <Service, Observable extends io.reactivex.Observable<Result<BaseData>>, BaseData extends BaseInfo> |
| 68 | 68 | SubscriptionRequest<Observable, BaseData> cmccService(Class<Service> clazz, ApiBuild.Api<Service, Observable, BaseData> api) { |
| 69 | - return service(clazz, api, null); | |
| 69 | + return service(clazz, api, new SignEncryptInterceptor()); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | public static <Service> Service service(Class<Service> clazz) { | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/BlueToothStep1Activity.java
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/BlueToothStep2Activity.java
| ... | ... | @@ -127,6 +127,7 @@ public class BlueToothStep2Activity extends AppCompatActivity { |
| 127 | 127 | //判断蓝牙是否打开 |
| 128 | 128 | if (BleManager.getInstance().isBlueEnable()) { |
| 129 | 129 | SearchDeviceActivity.startActivity(BlueToothStep2Activity.this); |
| 130 | + finish(); | |
| 130 | 131 | } else { |
| 131 | 132 | BleManager.getInstance().enableBluetooth(); |
| 132 | 133 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/activity/DeviceManagerActivity.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.activity; | |
| 2 | + | |
| 3 | +import android.databinding.DataBindingUtil; | |
| 4 | +import android.support.v7.app.AppCompatActivity; | |
| 5 | +import android.os.Bundle; | |
| 6 | + | |
| 7 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 8 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ActivityDeviceManagerBinding; | |
| 9 | +import com.cnlive.strike.xiaojiaspeaker.ui.fragment.DeviceManagerFragment; | |
| 10 | +import com.cnlive.strike.xiaojiaspeaker.ui.fragment.SelectWifiFragment; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 设备管理 | |
| 14 | + * | |
| 15 | + * @author ys | |
| 16 | + */ | |
| 17 | +public class DeviceManagerActivity extends AppCompatActivity { | |
| 18 | + | |
| 19 | + @Override | |
| 20 | + protected void onCreate(Bundle savedInstanceState) { | |
| 21 | + super.onCreate(savedInstanceState); | |
| 22 | + setContentView(R.layout.activity_device_manager); | |
| 23 | + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, DeviceManagerFragment.newInstance()).commitAllowingStateLoss(); | |
| 24 | + | |
| 25 | + } | |
| 26 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/AllDeviceAdapter.java
| ... | ... | @@ -30,6 +30,7 @@ public class AllDeviceAdapter extends RecyclerView.Adapter { |
| 30 | 30 | private OnAddClickListener onAddClickListener; |
| 31 | 31 | private String TAG = "AllDeviceAdapter"; |
| 32 | 32 | |
| 33 | + | |
| 33 | 34 | public AllDeviceAdapter(Context context, List<AllDeviceInfo> allDeviceInfos) { |
| 34 | 35 | this.context = context; |
| 35 | 36 | this.allDeviceInfos = allDeviceInfos; |
| ... | ... | @@ -97,7 +98,6 @@ public class AllDeviceAdapter extends RecyclerView.Adapter { |
| 97 | 98 | if (R.id.rl_root == view.getId()) { |
| 98 | 99 | if (null != onItemClickListener) { |
| 99 | 100 | onItemClickListener.onItemClick(getAdapterPosition(), allDeviceInfos.get(getAdapterPosition())); |
| 100 | - | |
| 101 | 101 | } |
| 102 | 102 | Log.e(TAG, "onClick: " + getAdapterPosition()); |
| 103 | 103 | } else if (R.id.ll_add == view.getId()) { |
| ... | ... | @@ -107,21 +107,6 @@ public class AllDeviceAdapter extends RecyclerView.Adapter { |
| 107 | 107 | Log.e(TAG, "onAddClickListener: " + getAdapterPosition()); |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | - | |
| 111 | -// public View.OnClickListener mOnclick = new View.OnClickListener() { | |
| 112 | -// @Override | |
| 113 | -// public void onClick(View view) { | |
| 114 | -// if (R.id.rl_root == view.getId()) { | |
| 115 | -// if (null != onItemClickListener) { | |
| 116 | -// onItemClickListener.onItemClick(getAdapterPosition(), allDeviceInfos.get(getAdapterPosition())); | |
| 117 | -// } | |
| 118 | -// } else if (R.id.ll_add == view.getId()) { | |
| 119 | -// if (null != onAddClickListener) { | |
| 120 | -// onAddClickListener.onAddClick(); | |
| 121 | -// } | |
| 122 | -// } | |
| 123 | -// } | |
| 124 | -// }; | |
| 125 | 110 | } |
| 126 | 111 | |
| 127 | 112 | public interface OnItemClickListener { | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/DeviceManagerMenuAdapter.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.adapter; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.databinding.DataBindingUtil; | |
| 5 | +import android.support.annotation.NonNull; | |
| 6 | +import android.support.v4.content.ContextCompat; | |
| 7 | +import android.support.v7.widget.RecyclerView; | |
| 8 | +import android.view.LayoutInflater; | |
| 9 | +import android.view.View; | |
| 10 | +import android.view.ViewGroup; | |
| 11 | + | |
| 12 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 13 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ItemListMenuSoundBoxNameBinding; | |
| 14 | +import com.cnlive.strike.xiaojiaspeaker.databinding.ItemListMenuSwitchBinding; | |
| 15 | +import com.cnlive.strike.xiaojiaspeaker.model.DeviceManagerMenu; | |
| 16 | + | |
| 17 | +import java.util.List; | |
| 18 | + | |
| 19 | +public class DeviceManagerMenuAdapter extends RecyclerView.Adapter { | |
| 20 | + private Context context; | |
| 21 | + private List<DeviceManagerMenu> deviceManagerMenuList; | |
| 22 | + | |
| 23 | + public DeviceManagerMenuAdapter(Context context, List<DeviceManagerMenu> deviceManagerMenuList) { | |
| 24 | + this.context = context; | |
| 25 | + this.deviceManagerMenuList = deviceManagerMenuList; | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public int getItemViewType(int position) { | |
| 30 | + return deviceManagerMenuList.get(position).getType(); | |
| 31 | + } | |
| 32 | + | |
| 33 | + @NonNull | |
| 34 | + @Override | |
| 35 | + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { | |
| 36 | + LayoutInflater inflater = LayoutInflater.from(context); | |
| 37 | + switch (viewType) { | |
| 38 | + case DeviceManagerMenu.NORMAL: | |
| 39 | + ItemListMenuSoundBoxNameBinding soundBoxNameBinding = DataBindingUtil.inflate(inflater, R.layout.item_list_menu_sound_box_name, viewGroup, false); | |
| 40 | + return new MySoundBoxNameHolder(soundBoxNameBinding); | |
| 41 | + case DeviceManagerMenu.NO_RIGHT_ARROW: | |
| 42 | + ItemListMenuSoundBoxNameBinding soundBoxNameBinding1 = DataBindingUtil.inflate(inflater, R.layout.item_list_menu_sound_box_name, viewGroup, false); | |
| 43 | + soundBoxNameBinding1.ivRight.setVisibility(View.GONE); | |
| 44 | + soundBoxNameBinding1.llRoot.setBackgroundColor(ContextCompat.getColor(context,R.color.white)); | |
| 45 | + return new MySoundBoxNameHolder(soundBoxNameBinding1); | |
| 46 | + case DeviceManagerMenu.NO_MENU_DETAIL: | |
| 47 | + ItemListMenuSoundBoxNameBinding soundBoxNameBinding2 = DataBindingUtil.inflate(inflater, R.layout.item_list_menu_sound_box_name, viewGroup, false); | |
| 48 | + soundBoxNameBinding2.tvMenuDetail.setVisibility(View.GONE); | |
| 49 | + return new MySoundBoxNameHolder(soundBoxNameBinding2); | |
| 50 | + //switch | |
| 51 | + case DeviceManagerMenu.SWITCH_NORMAL: | |
| 52 | + ItemListMenuSwitchBinding switchBinding = DataBindingUtil.inflate(inflater, R.layout.item_list_menu_switch, viewGroup, false); | |
| 53 | + return new MySwitchHolder(switchBinding); | |
| 54 | + | |
| 55 | + } | |
| 56 | + return null; | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Override | |
| 60 | + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) { | |
| 61 | + switch (getItemViewType(i)) { | |
| 62 | + case DeviceManagerMenu.NORMAL: | |
| 63 | + ItemListMenuSoundBoxNameBinding soundBoxNameBinding = ((MySoundBoxNameHolder) viewHolder).getBinding(); | |
| 64 | + soundBoxNameBinding.tvMenuTitle.setText(deviceManagerMenuList.get(i).getMenuTitle()); | |
| 65 | + soundBoxNameBinding.tvMenuDetail.setText(deviceManagerMenuList.get(i).getMenuDetail()); | |
| 66 | + break; | |
| 67 | + case DeviceManagerMenu.NO_RIGHT_ARROW: | |
| 68 | + ItemListMenuSoundBoxNameBinding soundBoxNameBinding1 = ((MySoundBoxNameHolder) viewHolder).getBinding(); | |
| 69 | + soundBoxNameBinding1.tvMenuTitle.setText(deviceManagerMenuList.get(i).getMenuTitle()); | |
| 70 | + soundBoxNameBinding1.tvMenuDetail.setText(deviceManagerMenuList.get(i).getMenuDetail()); | |
| 71 | + break; | |
| 72 | + case DeviceManagerMenu.NO_MENU_DETAIL: | |
| 73 | + ItemListMenuSoundBoxNameBinding soundBoxNameBinding2 = ((MySoundBoxNameHolder) viewHolder).getBinding(); | |
| 74 | + soundBoxNameBinding2.tvMenuTitle.setText(deviceManagerMenuList.get(i).getMenuTitle()); | |
| 75 | + break; | |
| 76 | + case DeviceManagerMenu.SWITCH_NORMAL: | |
| 77 | + ItemListMenuSwitchBinding switchBinding = ((MySwitchHolder) viewHolder).getBinding(); | |
| 78 | + switchBinding.tvMenuTitle.setText(deviceManagerMenuList.get(i).getMenuTitle()); | |
| 79 | + switchBinding.tvMenuDetail.setText(deviceManagerMenuList.get(i).getMenuDetail()); | |
| 80 | +// switchBinding.sbSwitch.setChecked(true); | |
| 81 | + break; | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Override | |
| 86 | + public int getItemCount() { | |
| 87 | + return deviceManagerMenuList.size(); | |
| 88 | + } | |
| 89 | + | |
| 90 | + private class MySoundBoxNameHolder extends RecyclerView.ViewHolder { | |
| 91 | + | |
| 92 | + private ItemListMenuSoundBoxNameBinding binding; | |
| 93 | + | |
| 94 | + public ItemListMenuSoundBoxNameBinding getBinding() { | |
| 95 | + return binding; | |
| 96 | + } | |
| 97 | + | |
| 98 | + public MySoundBoxNameHolder(ItemListMenuSoundBoxNameBinding binding) { | |
| 99 | + super(binding.getRoot()); | |
| 100 | + this.binding = binding; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + private class MySwitchHolder extends RecyclerView.ViewHolder { | |
| 105 | + | |
| 106 | + private ItemListMenuSwitchBinding binding; | |
| 107 | + | |
| 108 | + public ItemListMenuSwitchBinding getBinding() { | |
| 109 | + return binding; | |
| 110 | + } | |
| 111 | + | |
| 112 | + public MySwitchHolder(ItemListMenuSwitchBinding binding) { | |
| 113 | + super(binding.getRoot()); | |
| 114 | + this.binding = binding; | |
| 115 | + } | |
| 116 | + } | |
| 117 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/PopMenuAdapter.java
| ... | ... | @@ -3,7 +3,9 @@ package com.cnlive.strike.xiaojiaspeaker.ui.adapter; |
| 3 | 3 | import android.content.Context; |
| 4 | 4 | import android.databinding.DataBindingUtil; |
| 5 | 5 | import android.support.annotation.NonNull; |
| 6 | +import android.support.v4.content.ContextCompat; | |
| 6 | 7 | import android.support.v7.widget.RecyclerView; |
| 8 | +import android.text.TextUtils; | |
| 7 | 9 | import android.view.LayoutInflater; |
| 8 | 10 | import android.view.View; |
| 9 | 11 | import android.view.ViewGroup; |
| ... | ... | @@ -18,12 +20,37 @@ import java.util.List; |
| 18 | 20 | public class PopMenuAdapter extends RecyclerView.Adapter { |
| 19 | 21 | private Context context; |
| 20 | 22 | private List<PopMenuInfo> popMenuInfoList; |
| 23 | + private int lineColor = -1; | |
| 24 | + private int textColor = -1; | |
| 25 | + private int itemBackGround = -1; | |
| 26 | + private int lineVisible = -1; | |
| 27 | + private OnItemClickListener onItemClickListener; | |
| 28 | + | |
| 29 | + public void setLineVisible(int lineVisible) { | |
| 30 | + this.lineVisible = lineVisible; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { | |
| 34 | + this.onItemClickListener = onItemClickListener; | |
| 35 | + } | |
| 21 | 36 | |
| 22 | 37 | public PopMenuAdapter(Context context, List<PopMenuInfo> popMenuInfoList) { |
| 23 | 38 | this.context = context; |
| 24 | 39 | this.popMenuInfoList = popMenuInfoList; |
| 25 | 40 | } |
| 26 | 41 | |
| 42 | + public void setItemBackGround(int itemBackGround) { | |
| 43 | + this.itemBackGround = itemBackGround; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void setLineColor(int lineColor) { | |
| 47 | + this.lineColor = lineColor; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setTextColor(int textColor) { | |
| 51 | + this.textColor = textColor; | |
| 52 | + } | |
| 53 | + | |
| 27 | 54 | @NonNull |
| 28 | 55 | @Override |
| 29 | 56 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { |
| ... | ... | @@ -36,11 +63,21 @@ public class PopMenuAdapter extends RecyclerView.Adapter { |
| 36 | 63 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) { |
| 37 | 64 | PopItemMenuBinding binding = ((MyViewHolder) viewHolder).getBinding(); |
| 38 | 65 | binding.tvTip.setText(popMenuInfoList.get(i).getTitle()); |
| 39 | - if (i == popMenuInfoList.size() - 1) { | |
| 40 | - binding.viewLine.setVisibility(View.GONE); | |
| 66 | + //隐藏下划线 | |
| 67 | + if (lineVisible == View.VISIBLE) { | |
| 68 | + if (i == popMenuInfoList.size() - 1) { | |
| 69 | + binding.viewLine.setVisibility(View.GONE); | |
| 70 | + } else { | |
| 71 | + binding.viewLine.setVisibility(View.VISIBLE); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + //判断图标是否显示 | |
| 75 | + if (0 == popMenuInfoList.get(i).getImgDraw()) { | |
| 76 | + binding.ivIcon.setVisibility(View.GONE); | |
| 41 | 77 | } else { |
| 42 | - binding.viewLine.setVisibility(View.VISIBLE); | |
| 78 | + binding.ivIcon.setVisibility(View.VISIBLE); | |
| 43 | 79 | } |
| 80 | + //点击 | |
| 44 | 81 | } |
| 45 | 82 | |
| 46 | 83 | @Override |
| ... | ... | @@ -48,7 +85,7 @@ public class PopMenuAdapter extends RecyclerView.Adapter { |
| 48 | 85 | return popMenuInfoList.size(); |
| 49 | 86 | } |
| 50 | 87 | |
| 51 | - private class MyViewHolder extends RecyclerView.ViewHolder { | |
| 88 | + private class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | |
| 52 | 89 | |
| 53 | 90 | private PopItemMenuBinding binding; |
| 54 | 91 | |
| ... | ... | @@ -59,6 +96,36 @@ public class PopMenuAdapter extends RecyclerView.Adapter { |
| 59 | 96 | public MyViewHolder(PopItemMenuBinding binding) { |
| 60 | 97 | super(binding.getRoot()); |
| 61 | 98 | this.binding = binding; |
| 99 | + binding.llRoot.setOnClickListener(this); | |
| 100 | + //判断是否显示线 | |
| 101 | + if (lineVisible == -1) { | |
| 102 | + binding.viewLine.setVisibility(View.GONE); | |
| 103 | + } | |
| 104 | + //设置线的颜色 | |
| 105 | + if (lineColor != -1) { | |
| 106 | + binding.viewLine.setBackgroundColor(ContextCompat.getColor(context, lineColor)); | |
| 107 | + } | |
| 108 | + //设置文字的颜色 | |
| 109 | + if (textColor != -1) { | |
| 110 | + binding.tvTip.setTextColor(ContextCompat.getColor(context, textColor)); | |
| 111 | + } | |
| 112 | + //设置点击颜色 | |
| 113 | + if (itemBackGround != -1) { | |
| 114 | + binding.llRoot.setBackground(ContextCompat.getDrawable(context, itemBackGround)); | |
| 115 | + } | |
| 62 | 116 | } |
| 117 | + | |
| 118 | + @Override | |
| 119 | + public void onClick(View view) { | |
| 120 | + if (view.getId() == R.id.ll_root) { | |
| 121 | + if (null != onItemClickListener) { | |
| 122 | + onItemClickListener.onClick(getAdapterPosition(), popMenuInfoList.get(getAdapterPosition())); | |
| 123 | + } | |
| 124 | + } | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + public interface OnItemClickListener { | |
| 129 | + void onClick(int position, PopMenuInfo popMenuInfo); | |
| 63 | 130 | } |
| 64 | 131 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/AllDeviceFragment.java
| ... | ... | @@ -57,6 +57,7 @@ public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | QMUIAlphaImageButton button; |
| 60 | + QMUIAlphaImageButton button1; | |
| 60 | 61 | |
| 61 | 62 | @Override |
| 62 | 63 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| ... | ... | @@ -73,7 +74,8 @@ public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, |
| 73 | 74 | if (null != binding) { |
| 74 | 75 | binding.topbar.setTitle("所有设备"); |
| 75 | 76 | //设置返回按钮 |
| 76 | - binding.topbar.addLeftImageButton(R.drawable.icon_back, R.id.left_back).setOnClickListener(new View.OnClickListener() { | |
| 77 | + button1 = binding.topbar.addLeftImageButton(R.drawable.icon_back, R.id.left_back); | |
| 78 | + button1.setOnClickListener(new View.OnClickListener() { | |
| 77 | 79 | @Override |
| 78 | 80 | public void onClick(View view) { |
| 79 | 81 | } |
| ... | ... | @@ -83,8 +85,8 @@ public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, |
| 83 | 85 | button.setOnClickListener(new View.OnClickListener() { |
| 84 | 86 | @Override |
| 85 | 87 | public void onClick(View view) { |
| 86 | - BlueToothStep1Activity.startActivity(getActivity()); | |
| 87 | -// AddClick(); | |
| 88 | +// BlueToothStep1Activity.startActivity(getActivity()); | |
| 89 | + AddClick(); | |
| 88 | 90 | } |
| 89 | 91 | }); |
| 90 | 92 | } |
| ... | ... | @@ -93,18 +95,25 @@ public class AllDeviceFragment extends MvpBindingFragment<AllDeviceFragmentView, |
| 93 | 95 | private void AddClick() { |
| 94 | 96 | List<PopMenuInfo> popMenuInfoList = new ArrayList<>(); |
| 95 | 97 | PopMenuInfo popMenuInfo = new PopMenuInfo(); |
| 96 | - popMenuInfo.setTitle("11"); | |
| 98 | + popMenuInfo.setTitle("下载中"); | |
| 97 | 99 | popMenuInfoList.add(popMenuInfo); |
| 98 | 100 | popMenuInfo = new PopMenuInfo(); |
| 99 | - popMenuInfo.setTitle("22"); | |
| 101 | + popMenuInfo.setTitle("历史记录"); | |
| 100 | 102 | popMenuInfoList.add(popMenuInfo); |
| 101 | 103 | popMenuInfo = new PopMenuInfo(); |
| 102 | - popMenuInfo.setTitle("33"); | |
| 104 | + popMenuInfo.setTitle("设备管理"); | |
| 103 | 105 | popMenuInfoList.add(popMenuInfo); |
| 104 | 106 | |
| 105 | 107 | PopMenu mPopMenu = new PopMenu.Builder(getActivity()) |
| 106 | 108 | .addData(popMenuInfoList) |
| 107 | - .setBackgroundColor(Color.GRAY) | |
| 109 | + .setBackgroundColor(Color.parseColor("#FA3a3a3a")) | |
| 110 | + .setLeftAndRightMargin(20) | |
| 111 | + .setHeightMargin(20) | |
| 112 | + .setLineColor(R.color.white_50) | |
| 113 | + .setTextColor(R.color.white) | |
| 114 | + .setLineVisible(View.VISIBLE) | |
| 115 | +// .setArrowHeight(30f) | |
| 116 | +// .setArrowHeight(30f) | |
| 108 | 117 | //.setCancelable(false) |
| 109 | 118 | .setCornerRadius(10f) |
| 110 | 119 | .build(); | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/DeviceManagerFragment.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.fragment; | |
| 2 | + | |
| 3 | +import android.os.Bundle; | |
| 4 | +import android.support.annotation.Nullable; | |
| 5 | +import android.support.v4.content.ContextCompat; | |
| 6 | +import android.view.View; | |
| 7 | + | |
| 8 | +import com.cnlive.libs.base.frame.fragment.MvpBindingFragment; | |
| 9 | +import com.cnlive.libs.base.util.StatusBarUtil; | |
| 10 | +import com.cnlive.libs.base.util.StatusBarUtil2; | |
| 11 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 12 | +import com.cnlive.strike.xiaojiaspeaker.databinding.FragmentDeviceManagerBinding; | |
| 13 | +import com.cnlive.strike.xiaojiaspeaker.frame.presenter.DeviceManagerFragmentPresenter; | |
| 14 | +import com.cnlive.strike.xiaojiaspeaker.frame.view.DeviceManagerFragmentView; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * 设备管理 | |
| 18 | + * | |
| 19 | + * @author ys | |
| 20 | + */ | |
| 21 | +public class DeviceManagerFragment extends MvpBindingFragment<DeviceManagerFragmentView, DeviceManagerFragmentPresenter, Object, FragmentDeviceManagerBinding> { | |
| 22 | + public static DeviceManagerFragment newInstance() { | |
| 23 | + DeviceManagerFragment fragment = new DeviceManagerFragment(); | |
| 24 | + return fragment; | |
| 25 | + } | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + protected int getLayoutId() { | |
| 29 | + return R.layout.fragment_device_manager; | |
| 30 | + } | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |
| 34 | + super.onActivityCreated(savedInstanceState); | |
| 35 | + StatusBarUtil.setStatusBarWrite(getActivity()); | |
| 36 | + StatusBarUtil2.setColor(getActivity(), ContextCompat.getColor(getActivity(), R.color.white), 0); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | |
| 41 | + super.onViewCreated(view, savedInstanceState); | |
| 42 | + initTopBar(); | |
| 43 | + if (null != getMvpView()) { | |
| 44 | + getMvpView().initView(); | |
| 45 | + } | |
| 46 | + } | |
| 47 | + | |
| 48 | + private void initTopBar() { | |
| 49 | + if (null != binding) { | |
| 50 | + binding.topbar.setTitle("设备管理"); | |
| 51 | + //设置返回按钮 | |
| 52 | + binding.topbar.addLeftImageButton(R.drawable.icon_back, R.id.left_back).setOnClickListener(new View.OnClickListener() { | |
| 53 | + @Override | |
| 54 | + public void onClick(View view) { | |
| 55 | + getActivity().finish(); | |
| 56 | + } | |
| 57 | + }); | |
| 58 | + } | |
| 59 | + } | |
| 60 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/popmenu/ArrowDrawable.java
| 1 | 1 | package com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu; |
| 2 | 2 | |
| 3 | +import android.content.Context; | |
| 3 | 4 | import android.graphics.Canvas; |
| 4 | 5 | import android.graphics.Color; |
| 5 | 6 | import android.graphics.ColorFilter; |
| 6 | 7 | import android.graphics.Paint; |
| 7 | 8 | import android.graphics.Path; |
| 8 | 9 | import android.graphics.PixelFormat; |
| 10 | +import android.graphics.PorterDuff; | |
| 11 | +import android.graphics.PorterDuffXfermode; | |
| 9 | 12 | import android.graphics.Rect; |
| 13 | +import android.graphics.Xfermode; | |
| 10 | 14 | import android.graphics.drawable.ColorDrawable; |
| 11 | 15 | import android.support.annotation.ColorInt; |
| 16 | +import android.support.v4.content.ContextCompat; | |
| 12 | 17 | import android.view.Gravity; |
| 13 | 18 | |
| 14 | 19 | /** |
| ... | ... | @@ -25,7 +30,6 @@ final class ArrowDrawable extends ColorDrawable { |
| 25 | 30 | ArrowDrawable(@ColorInt int foregroundColor, int gravity) { |
| 26 | 31 | mGravity = Util.gravityToArrowDirection(gravity); |
| 27 | 32 | mBackgroundColor = Color.TRANSPARENT; |
| 28 | - | |
| 29 | 33 | mPaint.setColor(foregroundColor); |
| 30 | 34 | } |
| 31 | 35 | |
| ... | ... | @@ -82,6 +86,7 @@ final class ArrowDrawable extends ColorDrawable { |
| 82 | 86 | mPaint.setAlpha(alpha); |
| 83 | 87 | } |
| 84 | 88 | |
| 89 | + @Override | |
| 85 | 90 | public void setColor(@ColorInt int color) { |
| 86 | 91 | mPaint.setColor(color); |
| 87 | 92 | } | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/popmenu/PopMenu.java
| ... | ... | @@ -2,6 +2,7 @@ package com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu; |
| 2 | 2 | |
| 3 | 3 | import android.animation.AnimatorSet; |
| 4 | 4 | import android.animation.ObjectAnimator; |
| 5 | +import android.annotation.SuppressLint; | |
| 5 | 6 | import android.content.Context; |
| 6 | 7 | import android.graphics.Color; |
| 7 | 8 | import android.graphics.PointF; |
| ... | ... | @@ -12,9 +13,11 @@ import android.support.annotation.ColorInt; |
| 12 | 13 | import android.support.annotation.DimenRes; |
| 13 | 14 | import android.support.annotation.NonNull; |
| 14 | 15 | import android.support.annotation.Size; |
| 16 | +import android.support.v4.content.ContextCompat; | |
| 15 | 17 | import android.support.v7.widget.LinearLayoutManager; |
| 16 | 18 | import android.support.v7.widget.RecyclerView; |
| 17 | 19 | import android.util.DisplayMetrics; |
| 20 | +import android.util.Log; | |
| 18 | 21 | import android.view.Gravity; |
| 19 | 22 | import android.view.View; |
| 20 | 23 | import android.view.ViewGroup; |
| ... | ... | @@ -24,8 +27,11 @@ import android.widget.ImageView; |
| 24 | 27 | import android.widget.LinearLayout; |
| 25 | 28 | import android.widget.PopupWindow; |
| 26 | 29 | |
| 30 | +import com.cnlive.libs.base.util.AlertUtil; | |
| 31 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 27 | 32 | import com.cnlive.strike.xiaojiaspeaker.model.PopMenuInfo; |
| 28 | 33 | import com.cnlive.strike.xiaojiaspeaker.ui.adapter.PopMenuAdapter; |
| 34 | + | |
| 29 | 35 | import java.util.ArrayList; |
| 30 | 36 | import java.util.List; |
| 31 | 37 | |
| ... | ... | @@ -52,6 +58,8 @@ public final class PopMenu { |
| 52 | 58 | private PopMenu.OnItemClickListener mItemClickListener; |
| 53 | 59 | private PopMenuAdapter mAdapter; |
| 54 | 60 | private List<PopMenuInfo> mData = new ArrayList<>(); |
| 61 | + private String TAG = "PopMenu"; | |
| 62 | + private Builder builder; | |
| 55 | 63 | |
| 56 | 64 | public interface OnItemClickListener { |
| 57 | 65 | // void onItemClickListener(ActionItem item, int position); |
| ... | ... | @@ -74,6 +82,7 @@ public final class PopMenu { |
| 74 | 82 | } |
| 75 | 83 | |
| 76 | 84 | private PopMenu(Builder builder) { |
| 85 | + this.builder = builder; | |
| 77 | 86 | DisplayMetrics dm = builder.mContext.getResources().getDisplayMetrics(); |
| 78 | 87 | mScreenHeightPixels = dm.heightPixels; |
| 79 | 88 | mScreenWidthPixels = dm.widthPixels; |
| ... | ... | @@ -87,15 +96,34 @@ public final class PopMenu { |
| 87 | 96 | mPopupWindow.setOutsideTouchable(builder.isCancelable); |
| 88 | 97 | } |
| 89 | 98 | |
| 99 | + @SuppressLint("WrongConstant") | |
| 90 | 100 | private View getContentView(final Builder builder) { |
| 91 | 101 | GradientDrawable drawable = new GradientDrawable(); |
| 92 | 102 | mBackgroundColor = builder.mBackgroundColor; |
| 93 | 103 | drawable.setColor(mBackgroundColor); |
| 94 | 104 | drawable.setCornerRadius(builder.mCornerRadius); |
| 95 | - | |
| 105 | + //设置颜色为渐变 | |
| 106 | +// drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); | |
| 107 | +// drawable.setColors(new int[]{mBackgroundColor,Color.parseColor("#BF000000")}); | |
| 108 | +// drawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM); | |
| 96 | 109 | mRecyclerView = new RecyclerView(builder.mContext); |
| 97 | 110 | mRecyclerView.setLayoutManager(new LinearLayoutManager(builder.mContext)); |
| 98 | - mAdapter=new PopMenuAdapter(builder.mContext,mData); | |
| 111 | + mRecyclerView.setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER); | |
| 112 | + mAdapter = new PopMenuAdapter(builder.mContext, mData); | |
| 113 | + if (builder.mLineColor != -1) { | |
| 114 | + mAdapter.setLineColor(builder.mLineColor); | |
| 115 | + } | |
| 116 | + if (builder.mTextColor != -1) { | |
| 117 | + mAdapter.setTextColor(builder.mTextColor); | |
| 118 | + } | |
| 119 | + //设置点击颜色 | |
| 120 | + if (builder.itemBackGround != -1) { | |
| 121 | + mAdapter.setItemBackGround(builder.itemBackGround); | |
| 122 | + } | |
| 123 | + //设置线是否显示 | |
| 124 | + if (builder.lineVisible != -1) { | |
| 125 | + mAdapter.setLineVisible(builder.lineVisible); | |
| 126 | + } | |
| 99 | 127 | mData.addAll(builder.mData); |
| 100 | 128 | // mAdapter = new CommonAdapter<ActionItem>(builder.mContext, |
| 101 | 129 | // R.layout.list_item_popmenu, mData) { |
| ... | ... | @@ -127,7 +155,12 @@ public final class PopMenu { |
| 127 | 155 | // } |
| 128 | 156 | // }; |
| 129 | 157 | mRecyclerView.setAdapter(mAdapter); |
| 130 | - | |
| 158 | + mAdapter.setOnItemClickListener(new PopMenuAdapter.OnItemClickListener() { | |
| 159 | + @Override | |
| 160 | + public void onClick(int position, PopMenuInfo popMenuInfo) { | |
| 161 | + AlertUtil.showDeftToast(builder.mContext, position + ""); | |
| 162 | + } | |
| 163 | + }); | |
| 131 | 164 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { |
| 132 | 165 | mRecyclerView.setBackground(drawable); |
| 133 | 166 | } else { |
| ... | ... | @@ -149,7 +182,7 @@ public final class PopMenu { |
| 149 | 182 | mArrowView.setLayoutParams(arrowLayoutParams); |
| 150 | 183 | |
| 151 | 184 | mContentView = new LinearLayout(builder.mContext); |
| 152 | - ViewGroup.LayoutParams contentLayoutParams=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
| 185 | + ViewGroup.LayoutParams contentLayoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); | |
| 153 | 186 | mContentView.setLayoutParams(contentLayoutParams); |
| 154 | 187 | mContentView.setOrientation(LinearLayout.VERTICAL); |
| 155 | 188 | mContentView.addView(mArrowView); |
| ... | ... | @@ -196,11 +229,26 @@ public final class PopMenu { |
| 196 | 229 | break; |
| 197 | 230 | } |
| 198 | 231 | float marginX = Util.dpToPx(2); |
| 232 | + //修改弹窗位置 | |
| 199 | 233 | if (mScreenWidthPixels - location.x - mContentView.getWidth() < marginX) { |
| 200 | - location.x = mScreenWidthPixels - mContentView.getWidth() - marginX; | |
| 234 | + if (null != builder && 0 != builder.LEFT_TO_RIGHT_MARGIN) { | |
| 235 | + location.x = mScreenWidthPixels - mContentView.getWidth() - marginX - builder.LEFT_TO_RIGHT_MARGIN; | |
| 236 | + } else { | |
| 237 | + location.x = mScreenWidthPixels - mContentView.getWidth() - marginX; | |
| 238 | + } | |
| 239 | + } else if (location.x < 0) { | |
| 240 | + if (null != builder && 0 != builder.LEFT_TO_RIGHT_MARGIN) { | |
| 241 | + location.x = marginX + builder.LEFT_TO_RIGHT_MARGIN; | |
| 242 | + } else { | |
| 243 | + location.x = marginX; | |
| 244 | + } | |
| 201 | 245 | } else if (location.x < marginX) { |
| 202 | 246 | location.x = marginX; |
| 203 | 247 | } |
| 248 | + if (null != builder && 0 != builder.HEIGHT_MARGIN) { | |
| 249 | + location.y -= builder.HEIGHT_MARGIN; | |
| 250 | + } | |
| 251 | + | |
| 204 | 252 | return location; |
| 205 | 253 | } |
| 206 | 254 | |
| ... | ... | @@ -221,6 +269,10 @@ public final class PopMenu { |
| 221 | 269 | mContentView.addView(mArrowView); |
| 222 | 270 | } else { |
| 223 | 271 | mContentView.addView(mArrowView); |
| 272 | +// LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mRecyclerView.getLayoutParams()); | |
| 273 | +// lp.setMargins(0, 2, 0, 0); | |
| 274 | +// mRecyclerView.setLayoutParams(lp); | |
| 275 | + | |
| 224 | 276 | mContentView.addView(mRecyclerView); |
| 225 | 277 | } |
| 226 | 278 | PointF location = calculateLocation(); |
| ... | ... | @@ -305,7 +357,7 @@ public final class PopMenu { |
| 305 | 357 | public static final class Builder { |
| 306 | 358 | |
| 307 | 359 | private int mBackgroundColor = Color.BLACK; |
| 308 | - public int mTextColor = Color.LTGRAY; | |
| 360 | + private int mTextColor = -1; | |
| 309 | 361 | private boolean isCancelable = true; |
| 310 | 362 | |
| 311 | 363 | private float mCornerRadius; |
| ... | ... | @@ -314,14 +366,32 @@ public final class PopMenu { |
| 314 | 366 | |
| 315 | 367 | private Context mContext; |
| 316 | 368 | private List<PopMenuInfo> mData = new ArrayList<>(); |
| 317 | - private int mLineColor = Color.GRAY; | |
| 318 | - private int mLineSize = 1; | |
| 369 | + private int mLineColor = -1; | |
| 319 | 370 | private boolean mIsShowImage = true; |
| 371 | + private int LEFT_TO_RIGHT_MARGIN;//弹窗左右边距 | |
| 372 | + private int HEIGHT_MARGIN;//纵坐标边距 | |
| 373 | + private int itemBackGround = -1; | |
| 374 | + private int lineVisible = -1; | |
| 320 | 375 | |
| 321 | 376 | public Builder(@NonNull Context context) { |
| 322 | 377 | mContext = context; |
| 323 | 378 | } |
| 324 | 379 | |
| 380 | + public Builder setLineVisible(int visible) { | |
| 381 | + lineVisible = visible; | |
| 382 | + return this; | |
| 383 | + } | |
| 384 | + | |
| 385 | + public Builder setLeftAndRightMargin(int margin) { | |
| 386 | + LEFT_TO_RIGHT_MARGIN = margin; | |
| 387 | + return this; | |
| 388 | + } | |
| 389 | + | |
| 390 | + public Builder setHeightMargin(int margin) { | |
| 391 | + HEIGHT_MARGIN = margin; | |
| 392 | + return this; | |
| 393 | + } | |
| 394 | + | |
| 325 | 395 | public Builder setCancelable(boolean cancelable) { |
| 326 | 396 | isCancelable = cancelable; |
| 327 | 397 | return this; |
| ... | ... | @@ -332,18 +402,18 @@ public final class PopMenu { |
| 332 | 402 | return this; |
| 333 | 403 | } |
| 334 | 404 | |
| 335 | - public Builder setTextColor(@ColorInt int color) { | |
| 405 | + public Builder setTextColor(int color) { | |
| 336 | 406 | mTextColor = color; |
| 337 | 407 | return this; |
| 338 | 408 | } |
| 339 | 409 | |
| 340 | - public Builder setLineColor(@ColorInt int color) { | |
| 410 | + public Builder setLineColor(int color) { | |
| 341 | 411 | mLineColor = color; |
| 342 | 412 | return this; |
| 343 | 413 | } |
| 344 | 414 | |
| 345 | - public Builder setLineSize(@Size int size) { | |
| 346 | - mLineSize = size; | |
| 415 | + public Builder setItemBackGround(int drawable) { | |
| 416 | + itemBackGround = drawable; | |
| 347 | 417 | return this; |
| 348 | 418 | } |
| 349 | 419 | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/switchbutton/ColorUtils.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.widget.switchbutton; | |
| 2 | + | |
| 3 | +import android.content.res.ColorStateList; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Generate thumb and background color state list use tintColor | |
| 7 | + * Created by kyle on 15/11/4. | |
| 8 | + */ | |
| 9 | +public class ColorUtils { | |
| 10 | + private static final int ENABLE_ATTR = android.R.attr.state_enabled; | |
| 11 | + private static final int CHECKED_ATTR = android.R.attr.state_checked; | |
| 12 | + private static final int PRESSED_ATTR = android.R.attr.state_pressed; | |
| 13 | + | |
| 14 | + static ColorStateList generateThumbColorWithTintColor(final int tintColor) { | |
| 15 | + int[][] states = new int[][]{ | |
| 16 | + {-ENABLE_ATTR, CHECKED_ATTR}, | |
| 17 | + {-ENABLE_ATTR}, | |
| 18 | + {PRESSED_ATTR, -CHECKED_ATTR}, | |
| 19 | + {PRESSED_ATTR, CHECKED_ATTR}, | |
| 20 | + {CHECKED_ATTR}, | |
| 21 | + {-CHECKED_ATTR} | |
| 22 | + }; | |
| 23 | + | |
| 24 | + int[] colors = new int[]{ | |
| 25 | + tintColor - 0xAA000000, | |
| 26 | + 0xFFBABABA, | |
| 27 | + tintColor - 0x99000000, | |
| 28 | + tintColor - 0x99000000, | |
| 29 | + tintColor | 0xFF000000, | |
| 30 | + 0xFFEEEEEE | |
| 31 | + }; | |
| 32 | + return new ColorStateList(states, colors); | |
| 33 | + } | |
| 34 | + | |
| 35 | + static ColorStateList generateBackColorWithTintColor(final int tintColor) { | |
| 36 | + int[][] states = new int[][]{ | |
| 37 | + {-ENABLE_ATTR, CHECKED_ATTR}, | |
| 38 | + {-ENABLE_ATTR}, | |
| 39 | + {CHECKED_ATTR, PRESSED_ATTR}, | |
| 40 | + {-CHECKED_ATTR, PRESSED_ATTR}, | |
| 41 | + {CHECKED_ATTR}, | |
| 42 | + {-CHECKED_ATTR} | |
| 43 | + }; | |
| 44 | + | |
| 45 | + int[] colors = new int[]{ | |
| 46 | + tintColor - 0xE1000000, | |
| 47 | + 0x10000000, | |
| 48 | + tintColor - 0xD0000000, | |
| 49 | + 0x20000000, | |
| 50 | + tintColor - 0xD0000000, | |
| 51 | + 0x20000000 | |
| 52 | + }; | |
| 53 | + return new ColorStateList(states, colors); | |
| 54 | + } | |
| 55 | +} | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/widget/switchbutton/SwitchButton.java
0 → 100644
| 1 | +package com.cnlive.strike.xiaojiaspeaker.ui.widget.switchbutton; | |
| 2 | + | |
| 3 | +import android.animation.ObjectAnimator; | |
| 4 | +import android.annotation.SuppressLint; | |
| 5 | +import android.content.Context; | |
| 6 | +import android.content.res.ColorStateList; | |
| 7 | +import android.content.res.Resources; | |
| 8 | +import android.content.res.TypedArray; | |
| 9 | +import android.graphics.Canvas; | |
| 10 | +import android.graphics.Color; | |
| 11 | +import android.graphics.Paint; | |
| 12 | +import android.graphics.PointF; | |
| 13 | +import android.graphics.RectF; | |
| 14 | +import android.graphics.drawable.Drawable; | |
| 15 | +import android.graphics.drawable.StateListDrawable; | |
| 16 | +import android.os.Parcel; | |
| 17 | +import android.os.Parcelable; | |
| 18 | +import android.support.v4.content.ContextCompat; | |
| 19 | +import android.text.Layout; | |
| 20 | +import android.text.StaticLayout; | |
| 21 | +import android.text.TextPaint; | |
| 22 | +import android.text.TextUtils; | |
| 23 | +import android.util.AttributeSet; | |
| 24 | +import android.util.TypedValue; | |
| 25 | +import android.view.MotionEvent; | |
| 26 | +import android.view.SoundEffectConstants; | |
| 27 | +import android.view.ViewConfiguration; | |
| 28 | +import android.view.ViewParent; | |
| 29 | +import android.view.animation.AccelerateDecelerateInterpolator; | |
| 30 | +import android.widget.CompoundButton; | |
| 31 | + | |
| 32 | +import com.cnlive.strike.xiaojiaspeaker.R; | |
| 33 | + | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * SwitchButton | |
| 37 | + * | |
| 38 | + * @author kyleduo | |
| 39 | + * @since 2014-09-24 | |
| 40 | + */ | |
| 41 | + | |
| 42 | +@SuppressWarnings("unused") | |
| 43 | +public class SwitchButton extends CompoundButton { | |
| 44 | + public static final float DEFAULT_THUMB_RANGE_RATIO = 1.8f; | |
| 45 | + public static final int DEFAULT_THUMB_SIZE_DP = 20; | |
| 46 | + public static final int DEFAULT_THUMB_MARGIN_DP = 2; | |
| 47 | + public static final int DEFAULT_ANIMATION_DURATION = 250; | |
| 48 | + public static final int DEFAULT_TINT_COLOR = 0x327FC2; | |
| 49 | + | |
| 50 | + private static int[] CHECKED_PRESSED_STATE = new int[]{android.R.attr.state_checked, android.R.attr.state_enabled, android.R.attr.state_pressed}; | |
| 51 | + private static int[] UNCHECKED_PRESSED_STATE = new int[]{-android.R.attr.state_checked, android.R.attr.state_enabled, android.R.attr.state_pressed}; | |
| 52 | + | |
| 53 | + private Drawable mThumbDrawable, mBackDrawable; | |
| 54 | + private ColorStateList mBackColor, mThumbColor; | |
| 55 | + private float mThumbRadius, mBackRadius; | |
| 56 | + private RectF mThumbMargin; | |
| 57 | + private float mThumbRangeRatio; | |
| 58 | + private long mAnimationDuration; | |
| 59 | + // fade back drawable or color when dragging or animating | |
| 60 | + private boolean mFadeBack; | |
| 61 | + private int mTintColor; | |
| 62 | + private int mThumbWidth; | |
| 63 | + private int mThumbHeight; | |
| 64 | + private int mBackWidth; | |
| 65 | + private int mBackHeight; | |
| 66 | + | |
| 67 | + private int mCurrThumbColor, mCurrBackColor, mNextBackColor, mOnTextColor, mOffTextColor; | |
| 68 | + private Drawable mCurrentBackDrawable, mNextBackDrawable; | |
| 69 | + private RectF mThumbRectF, mBackRectF, mSafeRectF, mTextOnRectF, mTextOffRectF; | |
| 70 | + private Paint mPaint; | |
| 71 | + // whether using Drawable for thumb or back | |
| 72 | + private boolean mIsThumbUseDrawable, mIsBackUseDrawable; | |
| 73 | + private boolean mDrawDebugRect = false; | |
| 74 | + private ObjectAnimator mProgressAnimator; | |
| 75 | + // animation control | |
| 76 | + private float mProgress; | |
| 77 | + // temp position of thumb when dragging or animating | |
| 78 | + private RectF mPresentThumbRectF; | |
| 79 | + private float mStartX, mStartY, mLastX; | |
| 80 | + private int mTouchSlop; | |
| 81 | + private int mClickTimeout; | |
| 82 | + private Paint mRectPaint; | |
| 83 | + private CharSequence mTextOn; | |
| 84 | + private CharSequence mTextOff; | |
| 85 | + private TextPaint mTextPaint; | |
| 86 | + private Layout mOnLayout; | |
| 87 | + private Layout mOffLayout; | |
| 88 | + private float mTextWidth; | |
| 89 | + private float mTextHeight; | |
| 90 | + private int mTextThumbInset; | |
| 91 | + private int mTextExtra; | |
| 92 | + private int mTextAdjust; | |
| 93 | + // FIX #78,#85 : When restoring saved states, setChecked() called by super. So disable | |
| 94 | + // animation and event listening when restoring. | |
| 95 | + private boolean mRestoring = false; | |
| 96 | + private boolean mReady = false; | |
| 97 | + private boolean mCatch = false; | |
| 98 | + | |
| 99 | + private OnCheckedChangeListener mChildOnCheckedChangeListener; | |
| 100 | + | |
| 101 | + public SwitchButton(Context context, AttributeSet attrs, int defStyle) { | |
| 102 | + super(context, attrs, defStyle); | |
| 103 | + init(attrs); | |
| 104 | + } | |
| 105 | + | |
| 106 | + public SwitchButton(Context context, AttributeSet attrs) { | |
| 107 | + super(context, attrs); | |
| 108 | + init(attrs); | |
| 109 | + } | |
| 110 | + | |
| 111 | + public SwitchButton(Context context) { | |
| 112 | + super(context); | |
| 113 | + init(null); | |
| 114 | + } | |
| 115 | + | |
| 116 | + private void init(AttributeSet attrs) { | |
| 117 | + mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); | |
| 118 | + mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout(); | |
| 119 | + | |
| 120 | + mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
| 121 | + mRectPaint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
| 122 | + mRectPaint.setStyle(Paint.Style.STROKE); | |
| 123 | + mRectPaint.setStrokeWidth(getResources().getDisplayMetrics().density); | |
| 124 | + | |
| 125 | + mTextPaint = getPaint(); | |
| 126 | + | |
| 127 | + mThumbRectF = new RectF(); | |
| 128 | + mBackRectF = new RectF(); | |
| 129 | + mSafeRectF = new RectF(); | |
| 130 | + mThumbMargin = new RectF(); | |
| 131 | + mTextOnRectF = new RectF(); | |
| 132 | + mTextOffRectF = new RectF(); | |
| 133 | + | |
| 134 | + mProgressAnimator = ObjectAnimator.ofFloat(this, "progress", 0, 0).setDuration(DEFAULT_ANIMATION_DURATION); | |
| 135 | + mProgressAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); | |
| 136 | + | |
| 137 | + mPresentThumbRectF = new RectF(); | |
| 138 | + | |
| 139 | + Resources res = getResources(); | |
| 140 | + float density = res.getDisplayMetrics().density; | |
| 141 | + | |
| 142 | + Drawable thumbDrawable = null; | |
| 143 | + ColorStateList thumbColor = null; | |
| 144 | + float margin = density * DEFAULT_THUMB_MARGIN_DP; | |
| 145 | + float marginLeft = 0; | |
| 146 | + float marginRight = 0; | |
| 147 | + float marginTop = 0; | |
| 148 | + float marginBottom = 0; | |
| 149 | + float thumbWidth = 0; | |
| 150 | + float thumbHeight = 0; | |
| 151 | + float thumbRadius = -1; | |
| 152 | + float backRadius = -1; | |
| 153 | + Drawable backDrawable = null; | |
| 154 | + ColorStateList backColor = null; | |
| 155 | + float thumbRangeRatio = DEFAULT_THUMB_RANGE_RATIO; | |
| 156 | + int animationDuration = DEFAULT_ANIMATION_DURATION; | |
| 157 | + boolean fadeBack = true; | |
| 158 | + int tintColor = 0; | |
| 159 | + String textOn = null; | |
| 160 | + String textOff = null; | |
| 161 | + int textThumbInset = 0; | |
| 162 | + int textExtra = 0; | |
| 163 | + int textAdjust = 0; | |
| 164 | + | |
| 165 | + TypedArray ta = attrs == null ? null : getContext().obtainStyledAttributes(attrs, R.styleable.SwitchButton); | |
| 166 | + if (ta != null) { | |
| 167 | + thumbDrawable = ta.getDrawable(R.styleable.SwitchButton_kswThumbDrawable); | |
| 168 | + thumbColor = ta.getColorStateList(R.styleable.SwitchButton_kswThumbColor); | |
| 169 | + margin = ta.getDimension(R.styleable.SwitchButton_kswThumbMargin, margin); | |
| 170 | + marginLeft = ta.getDimension(R.styleable.SwitchButton_kswThumbMarginLeft, margin); | |
| 171 | + marginRight = ta.getDimension(R.styleable.SwitchButton_kswThumbMarginRight, margin); | |
| 172 | + marginTop = ta.getDimension(R.styleable.SwitchButton_kswThumbMarginTop, margin); | |
| 173 | + marginBottom = ta.getDimension(R.styleable.SwitchButton_kswThumbMarginBottom, margin); | |
| 174 | + thumbWidth = ta.getDimension(R.styleable.SwitchButton_kswThumbWidth, thumbWidth); | |
| 175 | + thumbHeight = ta.getDimension(R.styleable.SwitchButton_kswThumbHeight, thumbHeight); | |
| 176 | + thumbRadius = ta.getDimension(R.styleable.SwitchButton_kswThumbRadius, thumbRadius); | |
| 177 | + backRadius = ta.getDimension(R.styleable.SwitchButton_kswBackRadius, backRadius); | |
| 178 | + backDrawable = ta.getDrawable(R.styleable.SwitchButton_kswBackDrawable); | |
| 179 | + backColor = ta.getColorStateList(R.styleable.SwitchButton_kswBackColor); | |
| 180 | + thumbRangeRatio = ta.getFloat(R.styleable.SwitchButton_kswThumbRangeRatio, thumbRangeRatio); | |
| 181 | + animationDuration = ta.getInteger(R.styleable.SwitchButton_kswAnimationDuration, animationDuration); | |
| 182 | + fadeBack = ta.getBoolean(R.styleable.SwitchButton_kswFadeBack, true); | |
| 183 | + tintColor = ta.getColor(R.styleable.SwitchButton_kswTintColor, tintColor); | |
| 184 | + textOn = ta.getString(R.styleable.SwitchButton_kswTextOn); | |
| 185 | + textOff = ta.getString(R.styleable.SwitchButton_kswTextOff); | |
| 186 | + textThumbInset = ta.getDimensionPixelSize(R.styleable.SwitchButton_kswTextThumbInset, 0); | |
| 187 | + textExtra = ta.getDimensionPixelSize(R.styleable.SwitchButton_kswTextExtra, 0); | |
| 188 | + textAdjust = ta.getDimensionPixelSize(R.styleable.SwitchButton_kswTextAdjust, 0); | |
| 189 | + ta.recycle(); | |
| 190 | + } | |
| 191 | + | |
| 192 | + // click | |
| 193 | + ta = attrs == null ? null : getContext().obtainStyledAttributes(attrs, new int[]{android.R.attr.focusable, android.R.attr.clickable}); | |
| 194 | + if (ta != null) { | |
| 195 | + boolean focusable = ta.getBoolean(0, true); | |
| 196 | + //noinspection ResourceType | |
| 197 | + @SuppressLint("ResourceType") | |
| 198 | + boolean clickable = ta.getBoolean(1, focusable); | |
| 199 | + setFocusable(focusable); | |
| 200 | + setClickable(clickable); | |
| 201 | + ta.recycle(); | |
| 202 | + } else { | |
| 203 | + setFocusable(true); | |
| 204 | + setClickable(true); | |
| 205 | + } | |
| 206 | + | |
| 207 | + // text | |
| 208 | + mTextOn = textOn; | |
| 209 | + mTextOff = textOff; | |
| 210 | + mTextThumbInset = textThumbInset; | |
| 211 | + mTextExtra = textExtra; | |
| 212 | + mTextAdjust = textAdjust; | |
| 213 | + | |
| 214 | + // thumb drawable and color | |
| 215 | + mThumbDrawable = thumbDrawable; | |
| 216 | + mThumbColor = thumbColor; | |
| 217 | + mIsThumbUseDrawable = mThumbDrawable != null; | |
| 218 | + mTintColor = tintColor; | |
| 219 | + if (mTintColor == 0) { | |
| 220 | + TypedValue typedValue = new TypedValue(); | |
| 221 | + boolean found = getContext().getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true); | |
| 222 | + if (found) { | |
| 223 | + mTintColor = typedValue.data; | |
| 224 | + } else { | |
| 225 | + mTintColor = DEFAULT_TINT_COLOR; | |
| 226 | + } | |
| 227 | + } | |
| 228 | + if (!mIsThumbUseDrawable && mThumbColor == null) { | |
| 229 | + mThumbColor = ColorUtils.generateThumbColorWithTintColor(mTintColor); | |
| 230 | + mCurrThumbColor = mThumbColor.getDefaultColor(); | |
| 231 | + } | |
| 232 | + | |
| 233 | + // thumbSize | |
| 234 | + mThumbWidth = ceil(thumbWidth); | |
| 235 | + mThumbHeight = ceil(thumbHeight); | |
| 236 | + | |
| 237 | + // back drawable and color | |
| 238 | + mBackDrawable = backDrawable; | |
| 239 | + mBackColor = backColor; | |
| 240 | + mIsBackUseDrawable = mBackDrawable != null; | |
| 241 | + if (!mIsBackUseDrawable && mBackColor == null) { | |
| 242 | + mBackColor = ColorUtils.generateBackColorWithTintColor(mTintColor); | |
| 243 | + mCurrBackColor = mBackColor.getDefaultColor(); | |
| 244 | + mNextBackColor = mBackColor.getColorForState(CHECKED_PRESSED_STATE, mCurrBackColor); | |
| 245 | + } | |
| 246 | + | |
| 247 | + // margin | |
| 248 | + mThumbMargin.set(marginLeft, marginTop, marginRight, marginBottom); | |
| 249 | + | |
| 250 | + // size & measure params must larger than 1 | |
| 251 | + mThumbRangeRatio = mThumbMargin.width() >= 0 ? Math.max(thumbRangeRatio, 1) : thumbRangeRatio; | |
| 252 | + | |
| 253 | + mThumbRadius = thumbRadius; | |
| 254 | + mBackRadius = backRadius; | |
| 255 | + mAnimationDuration = animationDuration; | |
| 256 | + mFadeBack = fadeBack; | |
| 257 | + | |
| 258 | + mProgressAnimator.setDuration(mAnimationDuration); | |
| 259 | + | |
| 260 | + // sync checked status | |
| 261 | + if (isChecked()) { | |
| 262 | + setProgress(1); | |
| 263 | + } | |
| 264 | + } | |
| 265 | + | |
| 266 | + | |
| 267 | + private Layout makeLayout(CharSequence text) { | |
| 268 | + return new StaticLayout(text, mTextPaint, (int) Math.ceil(Layout.getDesiredWidth(text, mTextPaint)), Layout.Alignment.ALIGN_CENTER, 1.f, 0, false); | |
| 269 | + } | |
| 270 | + | |
| 271 | + @Override | |
| 272 | + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
| 273 | + /* | |
| 274 | + * ensure textLayout | |
| 275 | + */ | |
| 276 | + if (mOnLayout == null && !TextUtils.isEmpty(mTextOn)) { | |
| 277 | + mOnLayout = makeLayout(mTextOn); | |
| 278 | + } | |
| 279 | + if (mOffLayout == null && !TextUtils.isEmpty(mTextOff)) { | |
| 280 | + mOffLayout = makeLayout(mTextOff); | |
| 281 | + } | |
| 282 | + | |
| 283 | + float onWidth = mOnLayout != null ? mOnLayout.getWidth() : 0; | |
| 284 | + float offWidth = mOffLayout != null ? mOffLayout.getWidth() : 0; | |
| 285 | + if (onWidth != 0 || offWidth != 0) { | |
| 286 | + mTextWidth = Math.max(onWidth, offWidth); | |
| 287 | + } else { | |
| 288 | + mTextWidth = 0; | |
| 289 | + } | |
| 290 | + | |
| 291 | + float onHeight = mOnLayout != null ? mOnLayout.getHeight() : 0; | |
| 292 | + float offHeight = mOffLayout != null ? mOffLayout.getHeight() : 0; | |
| 293 | + if (onHeight != 0 || offHeight != 0) { | |
| 294 | + mTextHeight = Math.max(onHeight, offHeight); | |
| 295 | + } else { | |
| 296 | + mTextHeight = 0; | |
| 297 | + } | |
| 298 | + | |
| 299 | + setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); | |
| 300 | + } | |
| 301 | + | |
| 302 | + /** | |
| 303 | + * SwitchButton use this formula to determine the final size of thumb, background and itself. | |
| 304 | + * | |
| 305 | + * textWidth = max(onWidth, offWidth) | |
| 306 | + * thumbRange = thumbWidth * rangeRatio | |
| 307 | + * textExtraSpace = textWidth + textExtra - (moveRange - thumbWidth + max(thumbMargin.left, thumbMargin.right) + textThumbInset) | |
| 308 | + * backWidth = thumbRange + thumbMargin.left + thumbMargin.right + max(textExtraSpace, 0) | |
| 309 | + * contentSize = thumbRange + max(thumbMargin.left, 0) + max(thumbMargin.right, 0) + max(textExtraSpace, 0) | |
| 310 | + * | |
| 311 | + * @param widthMeasureSpec widthMeasureSpec | |
| 312 | + * @return measuredWidth | |
| 313 | + */ | |
| 314 | + private int measureWidth(int widthMeasureSpec) { | |
| 315 | + int widthSize = MeasureSpec.getSize(widthMeasureSpec); | |
| 316 | + int widthMode = MeasureSpec.getMode(widthMeasureSpec); | |
| 317 | + int measuredWidth = widthSize; | |
| 318 | + | |
| 319 | + if (mThumbWidth == 0 && mIsThumbUseDrawable) { | |
| 320 | + mThumbWidth = mThumbDrawable.getIntrinsicWidth(); | |
| 321 | + } | |
| 322 | + | |
| 323 | + int moveRange; | |
| 324 | + int textWidth = ceil(mTextWidth); | |
| 325 | + // how much the background should extend to fit text. | |
| 326 | + int textExtraSpace; | |
| 327 | + int contentSize; | |
| 328 | + | |
| 329 | + if (mThumbRangeRatio == 0) { | |
| 330 | + mThumbRangeRatio = DEFAULT_THUMB_RANGE_RATIO; | |
| 331 | + } | |
| 332 | + | |
| 333 | + if (widthMode == MeasureSpec.EXACTLY) { | |
| 334 | + contentSize = widthSize - getPaddingLeft() - getPaddingRight(); | |
| 335 | + | |
| 336 | + if (mThumbWidth != 0) { | |
| 337 | + moveRange = ceil(mThumbWidth * mThumbRangeRatio); | |
| 338 | + textExtraSpace = textWidth + mTextExtra - (moveRange - mThumbWidth + ceil(Math.max(mThumbMargin.left, mThumbMargin.right))); | |
| 339 | + mBackWidth = ceil(moveRange + mThumbMargin.left + mThumbMargin.right + Math.max(textExtraSpace, 0)); | |
| 340 | + if (mBackWidth < 0) { | |
| 341 | + mThumbWidth = 0; | |
| 342 | + } | |
| 343 | + if (moveRange + Math.max(mThumbMargin.left, 0) + Math.max(mThumbMargin.right, 0) + Math.max(textExtraSpace, 0) > contentSize) { | |
| 344 | + mThumbWidth = 0; | |
| 345 | + } | |
| 346 | + } | |
| 347 | + | |
| 348 | + if (mThumbWidth == 0) { | |
| 349 | + contentSize = widthSize - getPaddingLeft() - getPaddingRight(); | |
| 350 | + moveRange = ceil(contentSize - Math.max(mThumbMargin.left, 0) - Math.max(mThumbMargin.right, 0)); | |
| 351 | + if (moveRange < 0) { | |
| 352 | + mThumbWidth = 0; | |
| 353 | + mBackWidth = 0; | |
| 354 | + return measuredWidth; | |
| 355 | + } | |
| 356 | + mThumbWidth = ceil(moveRange / mThumbRangeRatio); | |
| 357 | + mBackWidth = ceil(moveRange + mThumbMargin.left + mThumbMargin.right); | |
| 358 | + if (mBackWidth < 0) { | |
| 359 | + mThumbWidth = 0; | |
| 360 | + mBackWidth = 0; | |
| 361 | + return measuredWidth; | |
| 362 | + } | |
| 363 | + textExtraSpace = textWidth + mTextExtra - (moveRange - mThumbWidth + ceil(Math.max(mThumbMargin.left, mThumbMargin.right))); | |
| 364 | + if (textExtraSpace > 0) { | |
| 365 | + // since backWidth is determined by view width, so we can only reduce thumbSize. | |
| 366 | + mThumbWidth = mThumbWidth - textExtraSpace; | |
| 367 | + } | |
| 368 | + if (mThumbWidth < 0) { | |
| 369 | + mThumbWidth = 0; | |
| 370 | + mBackWidth = 0; | |
| 371 | + return measuredWidth; | |
| 372 | + } | |
| 373 | + } | |
| 374 | + } else { | |
| 375 | + /* | |
| 376 | + If parent view want SwitchButton to determine it's size itself, we calculate the minimal | |
| 377 | + size of it's content. Further more, we ignore the limitation of widthSize since we want | |
| 378 | + to display SwitchButton in its actual size rather than compress the shape. | |
| 379 | + */ | |
| 380 | + if (mThumbWidth == 0) { | |
| 381 | + /* | |
| 382 | + If thumbWidth is not set, use the default one. | |
| 383 | + */ | |
| 384 | + mThumbWidth = ceil(getResources().getDisplayMetrics().density * DEFAULT_THUMB_SIZE_DP); | |
| 385 | + } | |
| 386 | + if (mThumbRangeRatio == 0) { | |
| 387 | + mThumbRangeRatio = DEFAULT_THUMB_RANGE_RATIO; | |
| 388 | + } | |
| 389 | + | |
| 390 | + moveRange = ceil(mThumbWidth * mThumbRangeRatio); | |
| 391 | + textExtraSpace = ceil(textWidth + mTextExtra - (moveRange - mThumbWidth + Math.max(mThumbMargin.left, mThumbMargin.right) + mTextThumbInset)); | |
| 392 | + mBackWidth = ceil(moveRange + mThumbMargin.left + mThumbMargin.right + Math.max(0, textExtraSpace)); | |
| 393 | + if (mBackWidth < 0) { | |
| 394 | + mThumbWidth = 0; | |
| 395 | + mBackWidth = 0; | |
| 396 | + return measuredWidth; | |
| 397 | + } | |
| 398 | + contentSize = ceil(moveRange + Math.max(0, mThumbMargin.left) + Math.max(0, mThumbMargin.right) + Math.max(0, textExtraSpace)); | |
| 399 | + | |
| 400 | + measuredWidth = Math.max(contentSize, contentSize + getPaddingLeft() + getPaddingRight()); | |
| 401 | + } | |
| 402 | + return measuredWidth; | |
| 403 | + } | |
| 404 | + | |
| 405 | + private int measureHeight(int heightMeasureSpec) { | |
| 406 | + int heightSize = MeasureSpec.getSize(heightMeasureSpec); | |
| 407 | + int heightMode = MeasureSpec.getMode(heightMeasureSpec); | |
| 408 | + int measuredHeight = heightSize; | |
| 409 | + | |
| 410 | + if (mThumbHeight == 0 && mIsThumbUseDrawable) { | |
| 411 | + mThumbHeight = mThumbDrawable.getIntrinsicHeight(); | |
| 412 | + } | |
| 413 | + int contentSize; | |
| 414 | + int textExtraSpace; | |
| 415 | + if (heightMode == MeasureSpec.EXACTLY) { | |
| 416 | + if (mThumbHeight != 0) { | |
| 417 | + /* | |
| 418 | + If thumbHeight has been set, we calculate backHeight and check if there is enough room. | |
| 419 | + */ | |
| 420 | + mBackHeight = ceil(mThumbHeight + mThumbMargin.top + mThumbMargin.bottom); | |
| 421 | + mBackHeight = ceil(Math.max(mBackHeight, mTextHeight)); | |
| 422 | + if (mBackHeight + getPaddingTop() + getPaddingBottom() - Math.min(0, mThumbMargin.top) - Math.min(0, mThumbMargin.bottom) > heightSize) { | |
| 423 | + // No enough room, we set thumbHeight to zero to calculate these value again. | |
| 424 | + mThumbHeight = 0; | |
| 425 | + } | |
| 426 | + } | |
| 427 | + | |
| 428 | + if (mThumbHeight == 0) { | |
| 429 | + mBackHeight = ceil(heightSize - getPaddingTop() - getPaddingBottom() + Math.min(0, mThumbMargin.top) + Math.min(0, mThumbMargin.bottom)); | |
| 430 | + if (mBackHeight < 0) { | |
| 431 | + mBackHeight = 0; | |
| 432 | + mThumbHeight = 0; | |
| 433 | + return measuredHeight; | |
| 434 | + } | |
| 435 | + mThumbHeight = ceil(mBackHeight - mThumbMargin.top - mThumbMargin.bottom); | |
| 436 | + } | |
| 437 | + if (mThumbHeight < 0) { | |
| 438 | + mBackHeight = 0; | |
| 439 | + mThumbHeight = 0; | |
| 440 | + return measuredHeight; | |
| 441 | + } | |
| 442 | + } else { | |
| 443 | + if (mThumbHeight == 0) { | |
| 444 | + mThumbHeight = ceil(getResources().getDisplayMetrics().density * DEFAULT_THUMB_SIZE_DP); | |
| 445 | + } | |
| 446 | + mBackHeight = ceil(mThumbHeight + mThumbMargin.top + mThumbMargin.bottom); | |
| 447 | + if (mBackHeight < 0) { | |
| 448 | + mBackHeight = 0; | |
| 449 | + mThumbHeight = 0; | |
| 450 | + return measuredHeight; | |
| 451 | + } | |
| 452 | + textExtraSpace = ceil(mTextHeight - mBackHeight); | |
| 453 | + if (textExtraSpace > 0) { | |
| 454 | + mBackHeight += textExtraSpace; | |
| 455 | + mThumbHeight += textExtraSpace; | |
| 456 | + } | |
| 457 | + contentSize = Math.max(mThumbHeight, mBackHeight); | |
| 458 | + | |
| 459 | + measuredHeight = Math.max(contentSize, contentSize + getPaddingTop() + getPaddingBottom()); | |
| 460 | + measuredHeight = Math.max(measuredHeight, getSuggestedMinimumHeight()); | |
| 461 | + } | |
| 462 | + | |
| 463 | + return measuredHeight; | |
| 464 | + } | |
| 465 | + | |
| 466 | + @Override | |
| 467 | + protected void onSizeChanged(int w, int h, int oldw, int oldh) { | |
| 468 | + super.onSizeChanged(w, h, oldw, oldh); | |
| 469 | + if (w != oldw || h != oldh) { | |
| 470 | + setup(); | |
| 471 | + } | |
| 472 | + } | |
| 473 | + | |
| 474 | + private int ceil(double dimen) { | |
| 475 | + return (int) Math.ceil(dimen); | |
| 476 | + } | |
| 477 | + | |
| 478 | + /** | |
| 479 | + * set up the rect of back and thumb | |
| 480 | + */ | |
| 481 | + private void setup() { | |
| 482 | + if (mThumbWidth == 0 || mThumbHeight == 0 || mBackWidth == 0 || mBackHeight == 0) { | |
| 483 | + return; | |
| 484 | + } | |
| 485 | + | |
| 486 | + if (mThumbRadius == -1) { | |
| 487 | + mThumbRadius = Math.min(mThumbWidth, mThumbHeight) / 2; | |
| 488 | + } | |
| 489 | + if (mBackRadius == -1) { | |
| 490 | + mBackRadius = Math.min(mBackWidth, mBackHeight) / 2; | |
| 491 | + } | |
| 492 | + | |
| 493 | + int contentWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); | |
| 494 | + int contentHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); | |
| 495 | + | |
| 496 | + // max range of drawing content, when thumbMargin is negative, drawing range is larger than backWidth | |
| 497 | + int drawingWidth = ceil(mBackWidth - Math.min(0, mThumbMargin.left) - Math.min(0, mThumbMargin.right)); | |
| 498 | + int drawingHeight = ceil(mBackHeight - Math.min(0, mThumbMargin.top) - Math.min(0, mThumbMargin.bottom)); | |
| 499 | + | |
| 500 | + float thumbTop; | |
| 501 | + if (contentHeight <= drawingHeight) { | |
| 502 | + thumbTop = getPaddingTop() + Math.max(0, mThumbMargin.top); | |
| 503 | + } else { | |
| 504 | + // center vertical in content area | |
| 505 | + thumbTop = getPaddingTop() + Math.max(0, mThumbMargin.top) + (contentHeight - drawingHeight + 1) / 2; | |
| 506 | + } | |
| 507 | + | |
| 508 | + float thumbLeft; | |
| 509 | + if (contentWidth <= mBackWidth) { | |
| 510 | + thumbLeft = getPaddingLeft() + Math.max(0, mThumbMargin.left); | |
| 511 | + } else { | |
| 512 | + thumbLeft = getPaddingLeft() + Math.max(0, mThumbMargin.left) + (contentWidth - drawingWidth + 1) / 2; | |
| 513 | + } | |
| 514 | + | |
| 515 | + mThumbRectF.set(thumbLeft, thumbTop, thumbLeft + mThumbWidth, thumbTop + mThumbHeight); | |
| 516 | + | |
| 517 | + float backLeft = mThumbRectF.left - mThumbMargin.left; | |
| 518 | + mBackRectF.set(backLeft, | |
| 519 | + mThumbRectF.top - mThumbMargin.top, | |
| 520 | + backLeft + mBackWidth, | |
| 521 | + mThumbRectF.top - mThumbMargin.top + mBackHeight); | |
| 522 | + | |
| 523 | + mSafeRectF.set(mThumbRectF.left, 0, mBackRectF.right - mThumbMargin.right - mThumbRectF.width(), 0); | |
| 524 | + | |
| 525 | + float minBackRadius = Math.min(mBackRectF.width(), mBackRectF.height()) / 2.f; | |
| 526 | + mBackRadius = Math.min(minBackRadius, mBackRadius); | |
| 527 | + | |
| 528 | + if (mBackDrawable != null) { | |
| 529 | + mBackDrawable.setBounds((int) mBackRectF.left, (int) mBackRectF.top, ceil(mBackRectF.right), ceil(mBackRectF.bottom)); | |
| 530 | + } | |
| 531 | + | |
| 532 | + if (mOnLayout != null) { | |
| 533 | + float onLeft = mBackRectF.left + (mBackRectF.width() + mTextThumbInset - mThumbWidth - mThumbMargin.right - mOnLayout.getWidth()) / 2f - mTextAdjust; | |
| 534 | + float onTop = mBackRectF.top + (mBackRectF.height() - mOnLayout.getHeight()) / 2; | |
| 535 | + mTextOnRectF.set(onLeft, onTop, onLeft + mOnLayout.getWidth(), onTop + mOnLayout.getHeight()); | |
| 536 | + } | |
| 537 | + | |
| 538 | + if (mOffLayout != null) { | |
| 539 | + float offLeft = mBackRectF.right - (mBackRectF.width() + mTextThumbInset - mThumbWidth - mThumbMargin.left - mOffLayout.getWidth()) / 2f - mOffLayout.getWidth() + mTextAdjust; | |
| 540 | + float offTop = mBackRectF.top + (mBackRectF.height() - mOffLayout.getHeight()) / 2; | |
| 541 | + mTextOffRectF.set(offLeft, offTop, offLeft + mOffLayout.getWidth(), offTop + mOffLayout.getHeight()); | |
| 542 | + } | |
| 543 | + | |
| 544 | + mReady = true; | |
| 545 | + } | |
| 546 | + | |
| 547 | + @Override | |
| 548 | + protected void onDraw(Canvas canvas) { | |
| 549 | + super.onDraw(canvas); | |
| 550 | + | |
| 551 | + if (!mReady) { | |
| 552 | + setup(); | |
| 553 | + } | |
| 554 | + if (!mReady) { | |
| 555 | + return; | |
| 556 | + } | |
| 557 | + | |
| 558 | + // fade back | |
| 559 | + if (mIsBackUseDrawable) { | |
| 560 | + if (mFadeBack && mCurrentBackDrawable != null && mNextBackDrawable != null) { | |
| 561 | + // fix #75, 70%A + 30%B != 30%B + 70%A, order matters when mix two layer of different alpha. | |
| 562 | + // So make sure the order of on/off layers never change during slide from one endpoint to another. | |
| 563 | + Drawable below = isChecked() ? mCurrentBackDrawable : mNextBackDrawable; | |
| 564 | + Drawable above = isChecked() ? mNextBackDrawable : mCurrentBackDrawable; | |
| 565 | + | |
| 566 | + int alpha = (int) (255 * getProgress()); | |
| 567 | + below.setAlpha(alpha); | |
| 568 | + below.draw(canvas); | |
| 569 | + alpha = 255 - alpha; | |
| 570 | + above.setAlpha(alpha); | |
| 571 | + above.draw(canvas); | |
| 572 | + } else { | |
| 573 | + mBackDrawable.setAlpha(255); | |
| 574 | + mBackDrawable.draw(canvas); | |
| 575 | + } | |
| 576 | + } else { | |
| 577 | + if (mFadeBack) { | |
| 578 | + int alpha; | |
| 579 | + int colorAlpha; | |
| 580 | + | |
| 581 | + // fix #75 | |
| 582 | + int belowColor = isChecked() ? mCurrBackColor : mNextBackColor; | |
| 583 | + int aboveColor = isChecked() ? mNextBackColor : mCurrBackColor; | |
| 584 | + | |
| 585 | + // curr back | |
| 586 | + alpha = (int) (255 * getProgress()); | |
| 587 | + colorAlpha = Color.alpha(belowColor); | |
| 588 | + colorAlpha = colorAlpha * alpha / 255; | |
| 589 | + mPaint.setARGB(colorAlpha, Color.red(belowColor), Color.green(belowColor), Color.blue(belowColor)); | |
| 590 | + canvas.drawRoundRect(mBackRectF, mBackRadius, mBackRadius, mPaint); | |
| 591 | + | |
| 592 | + // next back | |
| 593 | + alpha = 255 - alpha; | |
| 594 | + colorAlpha = Color.alpha(aboveColor); | |
| 595 | + colorAlpha = colorAlpha * alpha / 255; | |
| 596 | + mPaint.setARGB(colorAlpha, Color.red(aboveColor), Color.green(aboveColor), Color.blue(aboveColor)); | |
| 597 | + canvas.drawRoundRect(mBackRectF, mBackRadius, mBackRadius, mPaint); | |
| 598 | + | |
| 599 | + mPaint.setAlpha(255); | |
| 600 | + } else { | |
| 601 | + mPaint.setColor(mCurrBackColor); | |
| 602 | + canvas.drawRoundRect(mBackRectF, mBackRadius, mBackRadius, mPaint); | |
| 603 | + } | |
| 604 | + } | |
| 605 | + | |
| 606 | + // text | |
| 607 | + Layout switchText = getProgress() > 0.5 ? mOnLayout : mOffLayout; | |
| 608 | + RectF textRectF = getProgress() > 0.5 ? mTextOnRectF : mTextOffRectF; | |
| 609 | + if (switchText != null && textRectF != null) { | |
| 610 | + int alpha = (int) (255 * (getProgress() >= 0.75 ? getProgress() * 4 - 3 : (getProgress() < 0.25 ? 1 - getProgress() * 4 : 0))); | |
| 611 | + int textColor = getProgress() > 0.5 ? mOnTextColor : mOffTextColor; | |
| 612 | + int colorAlpha = Color.alpha(textColor); | |
| 613 | + colorAlpha = colorAlpha * alpha / 255; | |
| 614 | + switchText.getPaint().setARGB(colorAlpha, Color.red(textColor), Color.green(textColor), Color.blue(textColor)); | |
| 615 | + canvas.save(); | |
| 616 | + canvas.translate(textRectF.left, textRectF.top); | |
| 617 | + switchText.draw(canvas); | |
| 618 | + canvas.restore(); | |
| 619 | + } | |
| 620 | + | |
| 621 | + // thumb | |
| 622 | + mPresentThumbRectF.set(mThumbRectF); | |
| 623 | + mPresentThumbRectF.offset(mProgress * mSafeRectF.width(), 0); | |
| 624 | + if (mIsThumbUseDrawable) { | |
| 625 | + mThumbDrawable.setBounds((int) mPresentThumbRectF.left, (int) mPresentThumbRectF.top, ceil(mPresentThumbRectF.right), ceil(mPresentThumbRectF.bottom)); | |
| 626 | + mThumbDrawable.draw(canvas); | |
| 627 | + } else { | |
| 628 | + mPaint.setColor(mCurrThumbColor); | |
| 629 | + canvas.drawRoundRect(mPresentThumbRectF, mThumbRadius, mThumbRadius, mPaint); | |
| 630 | + } | |
| 631 | + | |
| 632 | + if (mDrawDebugRect) { | |
| 633 | + mRectPaint.setColor(Color.parseColor("#AA0000")); | |
| 634 | + canvas.drawRect(mBackRectF, mRectPaint); | |
| 635 | + mRectPaint.setColor(Color.parseColor("#0000FF")); | |
| 636 | + canvas.drawRect(mPresentThumbRectF, mRectPaint); | |
| 637 | + mRectPaint.setColor(Color.parseColor("#000000")); | |
| 638 | + canvas.drawLine(mSafeRectF.left, mThumbRectF.top, mSafeRectF.right, mThumbRectF.top, mRectPaint); | |
| 639 | + mRectPaint.setColor(Color.parseColor("#00CC00")); | |
| 640 | + canvas.drawRect(getProgress() > 0.5 ? mTextOnRectF : mTextOffRectF, mRectPaint); | |
| 641 | + } | |
| 642 | + } | |
| 643 | + | |
| 644 | + @Override | |
| 645 | + protected void drawableStateChanged() { | |
| 646 | + super.drawableStateChanged(); | |
| 647 | + | |
| 648 | + if (!mIsThumbUseDrawable && mThumbColor != null) { | |
| 649 | + mCurrThumbColor = mThumbColor.getColorForState(getDrawableState(), mCurrThumbColor); | |
| 650 | + } else { | |
| 651 | + setDrawableState(mThumbDrawable); | |
| 652 | + } | |
| 653 | + | |
| 654 | + int[] nextState = isChecked() ? UNCHECKED_PRESSED_STATE : CHECKED_PRESSED_STATE; | |
| 655 | + ColorStateList textColors = getTextColors(); | |
| 656 | + if (textColors != null) { | |
| 657 | + int defaultTextColor = textColors.getDefaultColor(); | |
| 658 | + mOnTextColor = textColors.getColorForState(CHECKED_PRESSED_STATE, defaultTextColor); | |
| 659 | + mOffTextColor = textColors.getColorForState(UNCHECKED_PRESSED_STATE, defaultTextColor); | |
| 660 | + } | |
| 661 | + if (!mIsBackUseDrawable && mBackColor != null) { | |
| 662 | + mCurrBackColor = mBackColor.getColorForState(getDrawableState(), mCurrBackColor); | |
| 663 | + mNextBackColor = mBackColor.getColorForState(nextState, mCurrBackColor); | |
| 664 | + } else { | |
| 665 | + if (mBackDrawable instanceof StateListDrawable && mFadeBack) { | |
| 666 | + mBackDrawable.setState(nextState); | |
| 667 | + mNextBackDrawable = mBackDrawable.getCurrent().mutate(); | |
| 668 | + } else { | |
| 669 | + mNextBackDrawable = null; | |
| 670 | + } | |
| 671 | + setDrawableState(mBackDrawable); | |
| 672 | + if (mBackDrawable != null) { | |
| 673 | + mCurrentBackDrawable = mBackDrawable.getCurrent().mutate(); | |
| 674 | + } | |
| 675 | + } | |
| 676 | + } | |
| 677 | + | |
| 678 | + @Override | |
| 679 | + public boolean onTouchEvent(MotionEvent event) { | |
| 680 | + | |
| 681 | + if (!isEnabled() || !isClickable() || !isFocusable() || !mReady) { | |
| 682 | + return false; | |
| 683 | + } | |
| 684 | + | |
| 685 | + int action = event.getAction(); | |
| 686 | + | |
| 687 | + float deltaX = event.getX() - mStartX; | |
| 688 | + float deltaY = event.getY() - mStartY; | |
| 689 | + | |
| 690 | + switch (action) { | |
| 691 | + case MotionEvent.ACTION_DOWN: | |
| 692 | + mStartX = event.getX(); | |
| 693 | + mStartY = event.getY(); | |
| 694 | + mLastX = mStartX; | |
| 695 | + setPressed(true); | |
| 696 | + break; | |
| 697 | + | |
| 698 | + case MotionEvent.ACTION_MOVE: | |
| 699 | + float x = event.getX(); | |
| 700 | + setProgress(getProgress() + (x - mLastX) / mSafeRectF.width()); | |
| 701 | + if (!mCatch && (Math.abs(deltaX) > mTouchSlop / 2 || Math.abs(deltaY) > mTouchSlop / 2)) { | |
| 702 | + if (deltaY == 0 || Math.abs(deltaX) > Math.abs(deltaY)) { | |
| 703 | + catchView(); | |
| 704 | + } else if (Math.abs(deltaY) > Math.abs(deltaX)) { | |
| 705 | + return false; | |
| 706 | + } | |
| 707 | + } | |
| 708 | + mLastX = x; | |
| 709 | + break; | |
| 710 | + | |
| 711 | + case MotionEvent.ACTION_CANCEL: | |
| 712 | + case MotionEvent.ACTION_UP: | |
| 713 | + mCatch = false; | |
| 714 | + setPressed(false); | |
| 715 | + float time = event.getEventTime() - event.getDownTime(); | |
| 716 | + if (Math.abs(deltaX) < mTouchSlop && Math.abs(deltaY) < mTouchSlop && time < mClickTimeout) { | |
| 717 | + performClick(); | |
| 718 | + } else { | |
| 719 | + boolean nextStatus = getStatusBasedOnPos(); | |
| 720 | + if (nextStatus != isChecked()) { | |
| 721 | + playSoundEffect(SoundEffectConstants.CLICK); | |
| 722 | + setChecked(nextStatus); | |
| 723 | + } else { | |
| 724 | + animateToState(nextStatus); | |
| 725 | + } | |
| 726 | + } | |
| 727 | + break; | |
| 728 | + | |
| 729 | + default: | |
| 730 | + break; | |
| 731 | + } | |
| 732 | + return true; | |
| 733 | + } | |
| 734 | + | |
| 735 | + | |
| 736 | + /** | |
| 737 | + * return the status based on position of thumb | |
| 738 | + * | |
| 739 | + * @return whether checked or not | |
| 740 | + */ | |
| 741 | + private boolean getStatusBasedOnPos() { | |
| 742 | + return getProgress() > 0.5f; | |
| 743 | + } | |
| 744 | + | |
| 745 | + private float getProgress() { | |
| 746 | + return mProgress; | |
| 747 | + } | |
| 748 | + | |
| 749 | + private void setProgress(final float progress) { | |
| 750 | + float tp = progress; | |
| 751 | + if (tp > 1) { | |
| 752 | + tp = 1; | |
| 753 | + } else if (tp < 0) { | |
| 754 | + tp = 0; | |
| 755 | + } | |
| 756 | + this.mProgress = tp; | |
| 757 | + invalidate(); | |
| 758 | + } | |
| 759 | + | |
| 760 | + @Override | |
| 761 | + public boolean performClick() { | |
| 762 | + return super.performClick(); | |
| 763 | + } | |
| 764 | + | |
| 765 | + /** | |
| 766 | + * processing animation | |
| 767 | + * | |
| 768 | + * @param checked checked or unChecked | |
| 769 | + */ | |
| 770 | + protected void animateToState(boolean checked) { | |
| 771 | + if (mProgressAnimator == null) { | |
| 772 | + return; | |
| 773 | + } | |
| 774 | + if (mProgressAnimator.isRunning()) { | |
| 775 | + mProgressAnimator.cancel(); | |
| 776 | + } | |
| 777 | + mProgressAnimator.setDuration(mAnimationDuration); | |
| 778 | + if (checked) { | |
| 779 | + mProgressAnimator.setFloatValues(mProgress, 1f); | |
| 780 | + } else { | |
| 781 | + mProgressAnimator.setFloatValues(mProgress, 0); | |
| 782 | + } | |
| 783 | + mProgressAnimator.start(); | |
| 784 | + } | |
| 785 | + | |
| 786 | + private void catchView() { | |
| 787 | + ViewParent parent = getParent(); | |
| 788 | + if (parent != null) { | |
| 789 | + parent.requestDisallowInterceptTouchEvent(true); | |
| 790 | + } | |
| 791 | + mCatch = true; | |
| 792 | + } | |
| 793 | + | |
| 794 | + @Override | |
| 795 | + public void setChecked(final boolean checked) { | |
| 796 | + // animate before super.setChecked() become user may call setChecked again in OnCheckedChangedListener | |
| 797 | + if (isChecked() != checked) { | |
| 798 | + animateToState(checked); | |
| 799 | + } | |
| 800 | + if (mRestoring) { | |
| 801 | + setCheckedImmediatelyNoEvent(checked); | |
| 802 | + } else { | |
| 803 | + super.setChecked(checked); | |
| 804 | + } | |
| 805 | + } | |
| 806 | + | |
| 807 | + public void setCheckedNoEvent(final boolean checked) { | |
| 808 | + if (mChildOnCheckedChangeListener == null) { | |
| 809 | + setChecked(checked); | |
| 810 | + } else { | |
| 811 | + super.setOnCheckedChangeListener(null); | |
| 812 | + setChecked(checked); | |
| 813 | + super.setOnCheckedChangeListener(mChildOnCheckedChangeListener); | |
| 814 | + } | |
| 815 | + } | |
| 816 | + | |
| 817 | + public void setCheckedImmediatelyNoEvent(boolean checked) { | |
| 818 | + if (mChildOnCheckedChangeListener == null) { | |
| 819 | + setCheckedImmediately(checked); | |
| 820 | + } else { | |
| 821 | + super.setOnCheckedChangeListener(null); | |
| 822 | + setCheckedImmediately(checked); | |
| 823 | + super.setOnCheckedChangeListener(mChildOnCheckedChangeListener); | |
| 824 | + } | |
| 825 | + } | |
| 826 | + | |
| 827 | + public void toggleNoEvent() { | |
| 828 | + if (mChildOnCheckedChangeListener == null) { | |
| 829 | + toggle(); | |
| 830 | + } else { | |
| 831 | + super.setOnCheckedChangeListener(null); | |
| 832 | + toggle(); | |
| 833 | + super.setOnCheckedChangeListener(mChildOnCheckedChangeListener); | |
| 834 | + } | |
| 835 | + } | |
| 836 | + | |
| 837 | + public void toggleImmediatelyNoEvent() { | |
| 838 | + if (mChildOnCheckedChangeListener == null) { | |
| 839 | + toggleImmediately(); | |
| 840 | + } else { | |
| 841 | + super.setOnCheckedChangeListener(null); | |
| 842 | + toggleImmediately(); | |
| 843 | + super.setOnCheckedChangeListener(mChildOnCheckedChangeListener); | |
| 844 | + } | |
| 845 | + } | |
| 846 | + | |
| 847 | + @Override | |
| 848 | + public void setOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) { | |
| 849 | + super.setOnCheckedChangeListener(onCheckedChangeListener); | |
| 850 | + mChildOnCheckedChangeListener = onCheckedChangeListener; | |
| 851 | + } | |
| 852 | + | |
| 853 | + public void setCheckedImmediately(boolean checked) { | |
| 854 | + super.setChecked(checked); | |
| 855 | + if (mProgressAnimator != null && mProgressAnimator.isRunning()) { | |
| 856 | + mProgressAnimator.cancel(); | |
| 857 | + } | |
| 858 | + setProgress(checked ? 1 : 0); | |
| 859 | + invalidate(); | |
| 860 | + } | |
| 861 | + | |
| 862 | + public void toggleImmediately() { | |
| 863 | + setCheckedImmediately(!isChecked()); | |
| 864 | + } | |
| 865 | + | |
| 866 | + private void setDrawableState(Drawable drawable) { | |
| 867 | + if (drawable != null) { | |
| 868 | + int[] myDrawableState = getDrawableState(); | |
| 869 | + drawable.setState(myDrawableState); | |
| 870 | + invalidate(); | |
| 871 | + } | |
| 872 | + } | |
| 873 | + | |
| 874 | + public boolean isDrawDebugRect() { | |
| 875 | + return mDrawDebugRect; | |
| 876 | + } | |
| 877 | + | |
| 878 | + public void setDrawDebugRect(boolean drawDebugRect) { | |
| 879 | + mDrawDebugRect = drawDebugRect; | |
| 880 | + invalidate(); | |
| 881 | + } | |
| 882 | + | |
| 883 | + public long getAnimationDuration() { | |
| 884 | + return mAnimationDuration; | |
| 885 | + } | |
| 886 | + | |
| 887 | + public void setAnimationDuration(long animationDuration) { | |
| 888 | + mAnimationDuration = animationDuration; | |
| 889 | + } | |
| 890 | + | |
| 891 | + public Drawable getThumbDrawable() { | |
| 892 | + return mThumbDrawable; | |
| 893 | + } | |
| 894 | + | |
| 895 | + public void setThumbDrawable(Drawable thumbDrawable) { | |
| 896 | + mThumbDrawable = thumbDrawable; | |
| 897 | + mIsThumbUseDrawable = mThumbDrawable != null; | |
| 898 | + refreshDrawableState(); | |
| 899 | + mReady = false; | |
| 900 | + requestLayout(); | |
| 901 | + invalidate(); | |
| 902 | + } | |
| 903 | + | |
| 904 | + public void setThumbDrawableRes(int thumbDrawableRes) { | |
| 905 | + setThumbDrawable(ContextCompat.getDrawable(getContext(), thumbDrawableRes)); | |
| 906 | + } | |
| 907 | + | |
| 908 | + public Drawable getBackDrawable() { | |
| 909 | + return mBackDrawable; | |
| 910 | + } | |
| 911 | + | |
| 912 | + public void setBackDrawable(Drawable backDrawable) { | |
| 913 | + mBackDrawable = backDrawable; | |
| 914 | + mIsBackUseDrawable = mBackDrawable != null; | |
| 915 | + refreshDrawableState(); | |
| 916 | + mReady = false; | |
| 917 | + requestLayout(); | |
| 918 | + invalidate(); | |
| 919 | + } | |
| 920 | + | |
| 921 | + public void setBackDrawableRes(int backDrawableRes) { | |
| 922 | + setBackDrawable(ContextCompat.getDrawable(getContext(), backDrawableRes)); | |
| 923 | + } | |
| 924 | + | |
| 925 | + public ColorStateList getBackColor() { | |
| 926 | + return mBackColor; | |
| 927 | + } | |
| 928 | + | |
| 929 | + public void setBackColor(ColorStateList backColor) { | |
| 930 | + mBackColor = backColor; | |
| 931 | + if (mBackColor != null) { | |
| 932 | + setBackDrawable(null); | |
| 933 | + } | |
| 934 | + invalidate(); | |
| 935 | + } | |
| 936 | + | |
| 937 | + public void setBackColorRes(int backColorRes) { | |
| 938 | + setBackColor(ContextCompat.getColorStateList(getContext(), backColorRes)); | |
| 939 | + } | |
| 940 | + | |
| 941 | + public ColorStateList getThumbColor() { | |
| 942 | + return mThumbColor; | |
| 943 | + } | |
| 944 | + | |
| 945 | + public void setThumbColor(ColorStateList thumbColor) { | |
| 946 | + mThumbColor = thumbColor; | |
| 947 | + if (mThumbColor != null) { | |
| 948 | + setThumbDrawable(null); | |
| 949 | + } | |
| 950 | + invalidate(); | |
| 951 | + } | |
| 952 | + | |
| 953 | + public void setThumbColorRes(int thumbColorRes) { | |
| 954 | + setThumbColor(ContextCompat.getColorStateList(getContext(), thumbColorRes)); | |
| 955 | + } | |
| 956 | + | |
| 957 | + public float getThumbRangeRatio() { | |
| 958 | + return mThumbRangeRatio; | |
| 959 | + } | |
| 960 | + | |
| 961 | + public void setThumbRangeRatio(float thumbRangeRatio) { | |
| 962 | + mThumbRangeRatio = thumbRangeRatio; | |
| 963 | + // We need to mark "ready" to false since requestLayout may not cause size changed. | |
| 964 | + mReady = false; | |
| 965 | + requestLayout(); | |
| 966 | + } | |
| 967 | + | |
| 968 | + public RectF getThumbMargin() { | |
| 969 | + return mThumbMargin; | |
| 970 | + } | |
| 971 | + | |
| 972 | + public void setThumbMargin(RectF thumbMargin) { | |
| 973 | + if (thumbMargin == null) { | |
| 974 | + setThumbMargin(0, 0, 0, 0); | |
| 975 | + } else { | |
| 976 | + setThumbMargin(thumbMargin.left, thumbMargin.top, thumbMargin.right, thumbMargin.bottom); | |
| 977 | + } | |
| 978 | + } | |
| 979 | + | |
| 980 | + public void setThumbMargin(float left, float top, float right, float bottom) { | |
| 981 | + mThumbMargin.set(left, top, right, bottom); | |
| 982 | + mReady = false; | |
| 983 | + requestLayout(); | |
| 984 | + } | |
| 985 | + | |
| 986 | + public void setThumbSize(int width, int height) { | |
| 987 | + mThumbWidth = width; | |
| 988 | + mThumbHeight = height; | |
| 989 | + mReady = false; | |
| 990 | + requestLayout(); | |
| 991 | + } | |
| 992 | + | |
| 993 | + public float getThumbWidth() { | |
| 994 | + return mThumbWidth; | |
| 995 | + } | |
| 996 | + | |
| 997 | + public float getThumbHeight() { | |
| 998 | + return mThumbHeight; | |
| 999 | + } | |
| 1000 | + | |
| 1001 | + public float getThumbRadius() { | |
| 1002 | + return mThumbRadius; | |
| 1003 | + } | |
| 1004 | + | |
| 1005 | + public void setThumbRadius(float thumbRadius) { | |
| 1006 | + mThumbRadius = thumbRadius; | |
| 1007 | + if (!mIsThumbUseDrawable) { | |
| 1008 | + invalidate(); | |
| 1009 | + } | |
| 1010 | + } | |
| 1011 | + | |
| 1012 | + public PointF getBackSizeF() { | |
| 1013 | + return new PointF(mBackRectF.width(), mBackRectF.height()); | |
| 1014 | + } | |
| 1015 | + | |
| 1016 | + public float getBackRadius() { | |
| 1017 | + return mBackRadius; | |
| 1018 | + } | |
| 1019 | + | |
| 1020 | + public void setBackRadius(float backRadius) { | |
| 1021 | + mBackRadius = backRadius; | |
| 1022 | + if (!mIsBackUseDrawable) { | |
| 1023 | + invalidate(); | |
| 1024 | + } | |
| 1025 | + } | |
| 1026 | + | |
| 1027 | + public boolean isFadeBack() { | |
| 1028 | + return mFadeBack; | |
| 1029 | + } | |
| 1030 | + | |
| 1031 | + public void setFadeBack(boolean fadeBack) { | |
| 1032 | + mFadeBack = fadeBack; | |
| 1033 | + } | |
| 1034 | + | |
| 1035 | + public int getTintColor() { | |
| 1036 | + return mTintColor; | |
| 1037 | + } | |
| 1038 | + | |
| 1039 | + public void setTintColor(@SuppressWarnings("SameParameterValue") int tintColor) { | |
| 1040 | + mTintColor = tintColor; | |
| 1041 | + mThumbColor = ColorUtils.generateThumbColorWithTintColor(mTintColor); | |
| 1042 | + mBackColor = ColorUtils.generateBackColorWithTintColor(mTintColor); | |
| 1043 | + mIsBackUseDrawable = false; | |
| 1044 | + mIsThumbUseDrawable = false; | |
| 1045 | + // call this method to refresh color states | |
| 1046 | + refreshDrawableState(); | |
| 1047 | + invalidate(); | |
| 1048 | + } | |
| 1049 | + | |
| 1050 | + public void setText(CharSequence onText, CharSequence offText) { | |
| 1051 | + mTextOn = onText; | |
| 1052 | + mTextOff = offText; | |
| 1053 | + | |
| 1054 | + mOnLayout = null; | |
| 1055 | + mOffLayout = null; | |
| 1056 | + | |
| 1057 | + mReady = false; | |
| 1058 | + requestLayout(); | |
| 1059 | + invalidate(); | |
| 1060 | + } | |
| 1061 | + | |
| 1062 | + public CharSequence getTextOn() { | |
| 1063 | + return mTextOn; | |
| 1064 | + } | |
| 1065 | + | |
| 1066 | + public CharSequence getTextOff() { | |
| 1067 | + return mTextOff; | |
| 1068 | + } | |
| 1069 | + | |
| 1070 | + public void setTextThumbInset(int textThumbInset) { | |
| 1071 | + mTextThumbInset = textThumbInset; | |
| 1072 | + mReady = false; | |
| 1073 | + requestLayout(); | |
| 1074 | + invalidate(); | |
| 1075 | + } | |
| 1076 | + | |
| 1077 | + public void setTextExtra(int textExtra) { | |
| 1078 | + mTextExtra = textExtra; | |
| 1079 | + mReady = false; | |
| 1080 | + requestLayout(); | |
| 1081 | + invalidate(); | |
| 1082 | + } | |
| 1083 | + | |
| 1084 | + public void setTextAdjust(int textAdjust) { | |
| 1085 | + mTextAdjust = textAdjust; | |
| 1086 | + mReady = false; | |
| 1087 | + requestLayout(); | |
| 1088 | + invalidate(); | |
| 1089 | + } | |
| 1090 | + | |
| 1091 | + @Override | |
| 1092 | + public Parcelable onSaveInstanceState() { | |
| 1093 | + Parcelable superState = super.onSaveInstanceState(); | |
| 1094 | + SavedState ss = new SavedState(superState); | |
| 1095 | + ss.onText = mTextOn; | |
| 1096 | + ss.offText = mTextOff; | |
| 1097 | + return ss; | |
| 1098 | + } | |
| 1099 | + | |
| 1100 | + @Override | |
| 1101 | + public void onRestoreInstanceState(Parcelable state) { | |
| 1102 | + SavedState ss = (SavedState) state; | |
| 1103 | + setText(ss.onText, ss.offText); | |
| 1104 | + mRestoring = true; | |
| 1105 | + super.onRestoreInstanceState(ss.getSuperState()); | |
| 1106 | + mRestoring = false; | |
| 1107 | + } | |
| 1108 | + | |
| 1109 | + static class SavedState extends BaseSavedState { | |
| 1110 | + CharSequence onText; | |
| 1111 | + CharSequence offText; | |
| 1112 | + | |
| 1113 | + SavedState(Parcelable superState) { | |
| 1114 | + super(superState); | |
| 1115 | + } | |
| 1116 | + | |
| 1117 | + private SavedState(Parcel in) { | |
| 1118 | + super(in); | |
| 1119 | + onText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); | |
| 1120 | + offText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); | |
| 1121 | + } | |
| 1122 | + | |
| 1123 | + @Override | |
| 1124 | + public void writeToParcel(Parcel out, int flags) { | |
| 1125 | + super.writeToParcel(out, flags); | |
| 1126 | + TextUtils.writeToParcel(onText, out, flags); | |
| 1127 | + TextUtils.writeToParcel(offText, out, flags); | |
| 1128 | + } | |
| 1129 | + | |
| 1130 | + public static final Creator<SavedState> CREATOR | |
| 1131 | + = new Creator<SavedState>() { | |
| 1132 | + public SavedState createFromParcel(Parcel in) { | |
| 1133 | + return new SavedState(in); | |
| 1134 | + } | |
| 1135 | + | |
| 1136 | + public SavedState[] newArray(int size) { | |
| 1137 | + return new SavedState[size]; | |
| 1138 | + } | |
| 1139 | + }; | |
| 1140 | + } | |
| 1141 | +} | |
| 0 | 1142 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/drawable-v21/ripple_bg.xml
module_xiaojiaSoundBox/src/main/res/drawable/ksw_md_thumb.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + | |
| 4 | + <!-- disable --> | |
| 5 | + <item android:state_checked="true" android:state_enabled="false"> | |
| 6 | + <layer-list> | |
| 7 | + <item> | |
| 8 | + <shape android:shape="oval"> | |
| 9 | + <size | |
| 10 | + android:width="@dimen/ksw_md_thumb_ripple_size" | |
| 11 | + android:height="@dimen/ksw_md_thumb_ripple_size"/> | |
| 12 | + <solid android:color="@android:color/transparent"/> | |
| 13 | + </shape> | |
| 14 | + </item> | |
| 15 | + <item | |
| 16 | + android:bottom="@dimen/ksw_md_thumb_shadow_inset_bottom" | |
| 17 | + android:gravity="center" | |
| 18 | + android:left="@dimen/ksw_md_thumb_shadow_inset" | |
| 19 | + android:right="@dimen/ksw_md_thumb_shadow_inset" | |
| 20 | + android:top="@dimen/ksw_md_thumb_shadow_inset_top"> | |
| 21 | + <shape android:shape="oval"> | |
| 22 | + <solid android:color="@color/ksw_md_solid_shadow"/> | |
| 23 | + </shape> | |
| 24 | + </item> | |
| 25 | + <item | |
| 26 | + android:bottom="@dimen/ksw_md_thumb_solid_inset" | |
| 27 | + android:gravity="center" | |
| 28 | + android:left="@dimen/ksw_md_thumb_solid_inset" | |
| 29 | + android:right="@dimen/ksw_md_thumb_solid_inset" | |
| 30 | + android:top="@dimen/ksw_md_thumb_solid_inset"> | |
| 31 | + <shape android:shape="oval"> | |
| 32 | + <solid android:color="@color/ksw_md_solid_checked_disable"/> | |
| 33 | + </shape> | |
| 34 | + </item> | |
| 35 | + </layer-list> | |
| 36 | + </item> | |
| 37 | + | |
| 38 | + <!-- disable --> | |
| 39 | + <item android:state_enabled="false"> | |
| 40 | + <layer-list> | |
| 41 | + <item> | |
| 42 | + <shape android:shape="oval"> | |
| 43 | + <size | |
| 44 | + android:width="@dimen/ksw_md_thumb_ripple_size" | |
| 45 | + android:height="@dimen/ksw_md_thumb_ripple_size"/> | |
| 46 | + <solid android:color="@android:color/transparent"/> | |
| 47 | + </shape> | |
| 48 | + </item> | |
| 49 | + <item | |
| 50 | + android:bottom="@dimen/ksw_md_thumb_shadow_inset_bottom" | |
| 51 | + android:gravity="center" | |
| 52 | + android:left="@dimen/ksw_md_thumb_shadow_inset" | |
| 53 | + android:right="@dimen/ksw_md_thumb_shadow_inset" | |
| 54 | + android:top="@dimen/ksw_md_thumb_shadow_inset_top"> | |
| 55 | + <shape android:shape="oval"> | |
| 56 | + <solid android:color="@color/ksw_md_solid_shadow"/> | |
| 57 | + </shape> | |
| 58 | + </item> | |
| 59 | + <item | |
| 60 | + android:bottom="@dimen/ksw_md_thumb_solid_inset" | |
| 61 | + android:gravity="center" | |
| 62 | + android:left="@dimen/ksw_md_thumb_solid_inset" | |
| 63 | + android:right="@dimen/ksw_md_thumb_solid_inset" | |
| 64 | + android:top="@dimen/ksw_md_thumb_solid_inset"> | |
| 65 | + <shape android:shape="oval"> | |
| 66 | + <solid android:color="@color/ksw_md_solid_disable"/> | |
| 67 | + </shape> | |
| 68 | + </item> | |
| 69 | + </layer-list> | |
| 70 | + </item> | |
| 71 | + | |
| 72 | + <!-- checked pressed --> | |
| 73 | + <item android:state_checked="true" android:state_pressed="true"> | |
| 74 | + <layer-list> | |
| 75 | + <item> | |
| 76 | + <shape android:shape="oval"> | |
| 77 | + <size | |
| 78 | + android:width="@dimen/ksw_md_thumb_ripple_size" | |
| 79 | + android:height="@dimen/ksw_md_thumb_ripple_size"/> | |
| 80 | + <solid android:color="@color/ksw_md_ripple_checked"/> | |
| 81 | + </shape> | |
| 82 | + </item> | |
| 83 | + <item | |
| 84 | + android:bottom="@dimen/ksw_md_thumb_shadow_inset_bottom" | |
| 85 | + android:gravity="center" | |
| 86 | + android:left="@dimen/ksw_md_thumb_shadow_inset" | |
| 87 | + android:right="@dimen/ksw_md_thumb_shadow_inset" | |
| 88 | + android:top="@dimen/ksw_md_thumb_shadow_inset_top"> | |
| 89 | + <shape android:shape="oval"> | |
| 90 | + <solid android:color="@color/ksw_md_solid_shadow"/> | |
| 91 | + </shape> | |
| 92 | + </item> | |
| 93 | + <item | |
| 94 | + android:bottom="@dimen/ksw_md_thumb_solid_inset" | |
| 95 | + android:gravity="center" | |
| 96 | + android:left="@dimen/ksw_md_thumb_solid_inset" | |
| 97 | + android:right="@dimen/ksw_md_thumb_solid_inset" | |
| 98 | + android:top="@dimen/ksw_md_thumb_solid_inset"> | |
| 99 | + <shape android:shape="oval"> | |
| 100 | + <solid android:color="@color/ksw_md_solid_checked"/> | |
| 101 | + </shape> | |
| 102 | + </item> | |
| 103 | + </layer-list> | |
| 104 | + </item> | |
| 105 | + | |
| 106 | + <!-- unchecked pressed --> | |
| 107 | + <item android:state_checked="false" android:state_pressed="true"> | |
| 108 | + <layer-list> | |
| 109 | + <item> | |
| 110 | + <shape android:shape="oval"> | |
| 111 | + <size | |
| 112 | + android:width="@dimen/ksw_md_thumb_ripple_size" | |
| 113 | + android:height="@dimen/ksw_md_thumb_ripple_size"/> | |
| 114 | + <solid android:color="@color/ksw_md_ripple_normal"/> | |
| 115 | + </shape> | |
| 116 | + </item> | |
| 117 | + <item | |
| 118 | + android:bottom="@dimen/ksw_md_thumb_shadow_inset_bottom" | |
| 119 | + android:gravity="center" | |
| 120 | + android:left="@dimen/ksw_md_thumb_shadow_inset" | |
| 121 | + android:right="@dimen/ksw_md_thumb_shadow_inset" | |
| 122 | + android:top="@dimen/ksw_md_thumb_shadow_inset_top"> | |
| 123 | + <shape android:shape="oval"> | |
| 124 | + <solid android:color="@color/ksw_md_solid_shadow"/> | |
| 125 | + </shape> | |
| 126 | + </item> | |
| 127 | + <item | |
| 128 | + android:bottom="@dimen/ksw_md_thumb_solid_inset" | |
| 129 | + android:gravity="center" | |
| 130 | + android:left="@dimen/ksw_md_thumb_solid_inset" | |
| 131 | + android:right="@dimen/ksw_md_thumb_solid_inset" | |
| 132 | + android:top="@dimen/ksw_md_thumb_solid_inset"> | |
| 133 | + <shape android:shape="oval"> | |
| 134 | + <solid android:color="@color/ksw_md_solid_normal"/> | |
| 135 | + </shape> | |
| 136 | + </item> | |
| 137 | + </layer-list> | |
| 138 | + </item> | |
| 139 | + | |
| 140 | + <!-- checked unpressed --> | |
| 141 | + <item android:state_checked="true" android:state_pressed="false"> | |
| 142 | + <layer-list> | |
| 143 | + <item> | |
| 144 | + <shape android:shape="oval"> | |
| 145 | + <size | |
| 146 | + android:width="@dimen/ksw_md_thumb_ripple_size" | |
| 147 | + android:height="@dimen/ksw_md_thumb_ripple_size"/> | |
| 148 | + <solid android:color="@android:color/transparent"/> | |
| 149 | + </shape> | |
| 150 | + </item> | |
| 151 | + <item | |
| 152 | + android:bottom="@dimen/ksw_md_thumb_shadow_inset_bottom" | |
| 153 | + android:gravity="center" | |
| 154 | + android:left="@dimen/ksw_md_thumb_shadow_inset" | |
| 155 | + android:right="@dimen/ksw_md_thumb_shadow_inset" | |
| 156 | + android:top="@dimen/ksw_md_thumb_shadow_inset_top"> | |
| 157 | + <shape android:shape="oval"> | |
| 158 | + <solid android:color="@color/ksw_md_solid_shadow"/> | |
| 159 | + </shape> | |
| 160 | + </item> | |
| 161 | + <item | |
| 162 | + android:bottom="@dimen/ksw_md_thumb_solid_inset" | |
| 163 | + android:gravity="center" | |
| 164 | + android:left="@dimen/ksw_md_thumb_solid_inset" | |
| 165 | + android:right="@dimen/ksw_md_thumb_solid_inset" | |
| 166 | + android:top="@dimen/ksw_md_thumb_solid_inset"> | |
| 167 | + <shape android:shape="oval"> | |
| 168 | + <solid android:color="@color/ksw_md_solid_checked"/> | |
| 169 | + </shape> | |
| 170 | + </item> | |
| 171 | + </layer-list> | |
| 172 | + </item> | |
| 173 | + | |
| 174 | + <!-- normal --> | |
| 175 | + <item> | |
| 176 | + <layer-list> | |
| 177 | + <item> | |
| 178 | + <shape android:shape="oval"> | |
| 179 | + <size | |
| 180 | + android:width="@dimen/ksw_md_thumb_ripple_size" | |
| 181 | + android:height="@dimen/ksw_md_thumb_ripple_size"/> | |
| 182 | + <solid android:color="@android:color/transparent"/> | |
| 183 | + </shape> | |
| 184 | + </item> | |
| 185 | + <item | |
| 186 | + android:bottom="@dimen/ksw_md_thumb_shadow_inset_bottom" | |
| 187 | + android:gravity="center" | |
| 188 | + android:left="@dimen/ksw_md_thumb_shadow_inset" | |
| 189 | + android:right="@dimen/ksw_md_thumb_shadow_inset" | |
| 190 | + android:top="@dimen/ksw_md_thumb_shadow_inset_top"> | |
| 191 | + <shape android:shape="oval"> | |
| 192 | + <solid android:color="@color/ksw_md_solid_shadow"/> | |
| 193 | + </shape> | |
| 194 | + </item> | |
| 195 | + <item | |
| 196 | + android:bottom="@dimen/ksw_md_thumb_solid_inset" | |
| 197 | + android:gravity="center" | |
| 198 | + android:left="@dimen/ksw_md_thumb_solid_inset" | |
| 199 | + android:right="@dimen/ksw_md_thumb_solid_inset" | |
| 200 | + android:top="@dimen/ksw_md_thumb_solid_inset"> | |
| 201 | + <shape android:shape="oval"> | |
| 202 | + <solid android:color="@color/ksw_md_solid_normal"/> | |
| 203 | + </shape> | |
| 204 | + </item> | |
| 205 | + </layer-list> | |
| 206 | + </item> | |
| 207 | +</selector> | ... | ... |
module_xiaojiaSoundBox/src/main/res/drawable/miui_back_drawable.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <item android:state_checked="false"> | |
| 4 | + <shape> | |
| 5 | + <solid android:color="#CECECE" /> | |
| 6 | + <corners android:radius="99dp" /> | |
| 7 | + <stroke android:width="1px" android:color="#DEDEDE" /> | |
| 8 | + </shape> | |
| 9 | + </item> | |
| 10 | + <item android:state_checked="true"> | |
| 11 | + <shape> | |
| 12 | + <solid android:color="@color/btn_green" /> | |
| 13 | + <corners android:radius="99dp" /> | |
| 14 | + <stroke android:width="1px" android:color="#DEDEDE" /> | |
| 15 | + </shape> | |
| 16 | + </item> | |
| 17 | + | |
| 18 | +</selector> | |
| 0 | 19 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/drawable/miui_thumb_drawable.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <item android:state_checked="false"> | |
| 4 | + <shape android:shape="oval"> | |
| 5 | + <solid android:color="@color/white" /> | |
| 6 | + </shape> | |
| 7 | + </item> | |
| 8 | + <item android:state_checked="true"> | |
| 9 | + <shape android:shape="oval"> | |
| 10 | + <solid android:color="@color/white" /> | |
| 11 | + </shape> | |
| 12 | + </item> | |
| 13 | +</selector> | |
| 0 | 14 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/drawable/selectable_pop_item_background.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <item android:drawable="@color/transparent" android:state_pressed="false" /> | |
| 4 | + <item android:drawable="@color/line_15" android:state_pressed="true" /> | |
| 5 | + | |
| 6 | +</selector> | |
| 0 | 7 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/activity_blue_tooth_help.xml
| ... | ... | @@ -38,6 +38,7 @@ |
| 38 | 38 | android:layout_height="wrap_content" |
| 39 | 39 | android:layout_marginTop="20dp" |
| 40 | 40 | android:layout_marginRight="10dp" |
| 41 | + android:lineSpacingExtra="10dp" | |
| 41 | 42 | android:text="@string/bludeTooth_help" |
| 42 | 43 | android:textColor="@color/color_282828" |
| 43 | 44 | android:textSize="15sp" /> | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/activity_device_manager.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout> | |
| 3 | + | |
| 4 | + <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 5 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 6 | + xmlns:tools="http://schemas.android.com/tools" | |
| 7 | + android:layout_width="match_parent" | |
| 8 | + android:layout_height="match_parent" | |
| 9 | + tools:context=".ui.activity.SearchDeviceActivity"> | |
| 10 | + | |
| 11 | + <RelativeLayout | |
| 12 | + android:id="@+id/fragment_container" | |
| 13 | + android:layout_width="match_parent" | |
| 14 | + android:layout_height="match_parent"></RelativeLayout> | |
| 15 | + </RelativeLayout> | |
| 16 | +</layout> | |
| 0 | 17 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/fragment_device_manager.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + xmlns:app="http://schemas.android.com/apk/res-auto"> | |
| 4 | + | |
| 5 | + <LinearLayout | |
| 6 | + android:layout_width="match_parent" | |
| 7 | + android:layout_height="match_parent" | |
| 8 | + android:background="@color/color_F2F2F2" | |
| 9 | + android:orientation="vertical"> | |
| 10 | + | |
| 11 | + <com.qmuiteam.qmui.widget.QMUITopBar | |
| 12 | + android:id="@+id/topbar" | |
| 13 | + android:layout_width="match_parent" | |
| 14 | + android:layout_height="?attr/qmui_topbar_height" /> | |
| 15 | + | |
| 16 | + <android.support.v7.widget.RecyclerView | |
| 17 | + android:id="@+id/rv_menu" | |
| 18 | + android:layout_width="match_parent" | |
| 19 | + android:layout_height="0dp" | |
| 20 | + android:layout_weight="1" | |
| 21 | + android:overScrollMode="never" /> | |
| 22 | + | |
| 23 | + <View | |
| 24 | + android:layout_width="match_parent" | |
| 25 | + android:layout_height="1dp" | |
| 26 | + android:background="@color/line_15" /> | |
| 27 | + | |
| 28 | + <TextView | |
| 29 | + android:layout_width="match_parent" | |
| 30 | + android:layout_height="60dp" | |
| 31 | + android:background="@drawable/selectable_item_white" | |
| 32 | + android:gravity="center" | |
| 33 | + android:text="删除设备" | |
| 34 | + android:clickable="true" | |
| 35 | + android:textColor="@color/color_EB3D3F" | |
| 36 | + android:textSize="15sp" /> | |
| 37 | + | |
| 38 | + </LinearLayout> | |
| 39 | +</layout> | |
| 0 | 40 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/item_list_menu_sound_box_name.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout> | |
| 3 | + | |
| 4 | + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 5 | + android:layout_width="match_parent" | |
| 6 | + android:layout_height="50dp" | |
| 7 | + android:layout_marginTop="10dp" | |
| 8 | + android:layout_marginBottom="10dp" | |
| 9 | + android:id="@+id/ll_root" | |
| 10 | + android:background="@drawable/selectable_item_white" | |
| 11 | + android:clickable="true"> | |
| 12 | + | |
| 13 | + <LinearLayout | |
| 14 | + android:layout_width="wrap_content" | |
| 15 | + android:layout_height="match_parent" | |
| 16 | + android:gravity="center|left"> | |
| 17 | + | |
| 18 | + <TextView | |
| 19 | + android:id="@+id/tv_menu_title" | |
| 20 | + android:layout_width="wrap_content" | |
| 21 | + android:layout_height="wrap_content" | |
| 22 | + android:layout_centerVertical="true" | |
| 23 | + android:layout_marginLeft="10dp" | |
| 24 | + android:layout_marginRight="10dp" | |
| 25 | + android:maxLines="1" | |
| 26 | + android:textColor="@color/color_282828" | |
| 27 | + android:textSize="16sp" /> | |
| 28 | + </LinearLayout> | |
| 29 | + | |
| 30 | + <LinearLayout | |
| 31 | + android:layout_width="0dp" | |
| 32 | + android:layout_height="match_parent" | |
| 33 | + android:layout_weight="1" | |
| 34 | + android:gravity="center|right"> | |
| 35 | + | |
| 36 | + <TextView | |
| 37 | + android:id="@+id/tv_menu_detail" | |
| 38 | + android:layout_width="wrap_content" | |
| 39 | + android:layout_height="wrap_content" | |
| 40 | + android:layout_centerVertical="true" | |
| 41 | + android:layout_marginLeft="10dp" | |
| 42 | + android:layout_marginRight="10dp" | |
| 43 | + android:layout_toEndOf="@id/iv_right" | |
| 44 | + android:layout_toRightOf="@id/tv_menu_title" | |
| 45 | + android:gravity="center|right" | |
| 46 | + android:maxLines="1" | |
| 47 | + android:textColor="@color/color_C3C3C3" | |
| 48 | + android:textSize="14sp" /> | |
| 49 | + | |
| 50 | + <ImageView | |
| 51 | + android:id="@+id/iv_right" | |
| 52 | + android:layout_width="7dp" | |
| 53 | + android:layout_height="13dp" | |
| 54 | + android:layout_marginRight="10dp" | |
| 55 | + android:background="@drawable/icon_item_right_arrow" /> | |
| 56 | + | |
| 57 | + </LinearLayout> | |
| 58 | + | |
| 59 | + </LinearLayout> | |
| 60 | +</layout> | |
| 0 | 61 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/item_list_menu_switch.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + xmlns:app="http://schemas.android.com/apk/res-auto"> | |
| 4 | + | |
| 5 | + <LinearLayout | |
| 6 | + android:layout_width="match_parent" | |
| 7 | + android:layout_height="90dp" | |
| 8 | + android:layout_marginTop="10dp" | |
| 9 | + android:layout_marginBottom="10dp" | |
| 10 | + android:background="@color/white" | |
| 11 | + android:clickable="true" | |
| 12 | + android:orientation="vertical"> | |
| 13 | + | |
| 14 | + <LinearLayout | |
| 15 | + android:layout_width="match_parent" | |
| 16 | + android:layout_height="wrap_content" | |
| 17 | + android:layout_marginTop="20dp" | |
| 18 | + android:gravity="center_vertical"> | |
| 19 | + | |
| 20 | + <TextView | |
| 21 | + android:id="@+id/tv_menu_title" | |
| 22 | + android:layout_width="0dp" | |
| 23 | + android:layout_height="wrap_content" | |
| 24 | + android:layout_marginLeft="10dp" | |
| 25 | + android:layout_marginRight="10dp" | |
| 26 | + android:layout_weight="1" | |
| 27 | + android:maxLines="1" | |
| 28 | + android:textColor="@color/color_282828" | |
| 29 | + android:textSize="16sp" /> | |
| 30 | + | |
| 31 | + <com.cnlive.strike.xiaojiaspeaker.ui.widget.switchbutton.SwitchButton | |
| 32 | + android:id="@+id/sb_switch" | |
| 33 | + android:layout_width="wrap_content" | |
| 34 | + android:layout_height="wrap_content" | |
| 35 | + android:layout_gravity="right" | |
| 36 | + android:layout_marginRight="10dp" | |
| 37 | + app:kswBackDrawable="@drawable/miui_back_drawable" | |
| 38 | + app:kswThumbDrawable="@drawable/miui_thumb_drawable" | |
| 39 | + app:kswThumbHeight="20dp" | |
| 40 | + app:kswThumbRangeRatio="2.1" | |
| 41 | + app:kswThumbWidth="20dp" /> | |
| 42 | + </LinearLayout> | |
| 43 | + | |
| 44 | + <TextView | |
| 45 | + android:id="@+id/tv_menu_detail" | |
| 46 | + android:layout_width="wrap_content" | |
| 47 | + android:layout_height="wrap_content" | |
| 48 | + android:layout_centerVertical="true" | |
| 49 | + android:layout_marginLeft="10dp" | |
| 50 | + android:layout_marginTop="10dp" | |
| 51 | + android:layout_marginRight="10dp" | |
| 52 | + android:layout_marginBottom="20dp" | |
| 53 | + android:layout_toEndOf="@id/iv_right" | |
| 54 | + android:layout_toRightOf="@id/tv_menu_title" | |
| 55 | + android:gravity="center|right" | |
| 56 | + android:maxLines="1" | |
| 57 | + android:textColor="@color/color_C3C3C3" | |
| 58 | + android:textSize="14sp" /> | |
| 59 | + | |
| 60 | + </LinearLayout> | |
| 61 | + | |
| 62 | +</layout> | |
| 0 | 63 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/layout/pop_item_menu.xml
| ... | ... | @@ -2,20 +2,26 @@ |
| 2 | 2 | <layout> |
| 3 | 3 | |
| 4 | 4 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 5 | + android:id="@+id/ll_root" | |
| 5 | 6 | android:layout_width="wrap_content" |
| 6 | 7 | android:layout_height="wrap_content" |
| 8 | + android:background="@drawable/selectable_pop_item_background" | |
| 7 | 9 | android:gravity="center_vertical" |
| 8 | 10 | android:minWidth="100dp" |
| 11 | + android:clickable="true" | |
| 9 | 12 | android:orientation="vertical"> |
| 10 | 13 | |
| 11 | 14 | <LinearLayout |
| 12 | 15 | android:layout_width="wrap_content" |
| 13 | - android:layout_height="wrap_content"> | |
| 16 | + android:layout_height="wrap_content" | |
| 17 | + android:gravity="center"> | |
| 14 | 18 | |
| 15 | 19 | <ImageView |
| 16 | 20 | android:id="@+id/iv_icon" |
| 17 | 21 | android:layout_width="20dp" |
| 18 | - android:layout_height="20dp" /> | |
| 22 | + android:layout_height="20dp" | |
| 23 | + android:layout_marginLeft="10dp" | |
| 24 | + android:background="@drawable/key_instruction" /> | |
| 19 | 25 | |
| 20 | 26 | <TextView |
| 21 | 27 | android:id="@+id/tv_tip" |
| ... | ... | @@ -24,13 +30,14 @@ |
| 24 | 30 | android:layout_marginLeft="10dp" |
| 25 | 31 | android:gravity="center_vertical" |
| 26 | 32 | android:minHeight="35dp" |
| 27 | - android:textColor="@color/color_282828" /> | |
| 33 | + android:textColor="@color/color_282828" | |
| 34 | + android:textSize="13sp" /> | |
| 28 | 35 | </LinearLayout> |
| 29 | 36 | |
| 30 | 37 | <View |
| 31 | 38 | android:id="@+id/view_line" |
| 32 | 39 | android:layout_width="match_parent" |
| 33 | - android:layout_height="1dp" | |
| 40 | + android:layout_height="0.2dp" | |
| 34 | 41 | android:background="@color/line" /> |
| 35 | 42 | |
| 36 | 43 | </LinearLayout> | ... | ... |
module_xiaojiaSoundBox/src/main/res/values/attrs.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<resources xmlns:tools="http://schemas.android.com/tools"> | |
| 3 | + | |
| 4 | + <declare-styleable name="SwitchButton" tools:ignore="ResourceName"> | |
| 5 | + <attr name="kswThumbDrawable" format="reference"/> | |
| 6 | + <attr name="kswThumbColor" format="color|reference"/> | |
| 7 | + <attr name="kswThumbMargin" format="dimension|reference"/> | |
| 8 | + <attr name="kswThumbMarginTop" format="dimension|reference"/> | |
| 9 | + <attr name="kswThumbMarginBottom" format="dimension|reference"/> | |
| 10 | + <attr name="kswThumbMarginLeft" format="dimension|reference"/> | |
| 11 | + <attr name="kswThumbMarginRight" format="dimension|reference"/> | |
| 12 | + <attr name="kswThumbWidth" format="dimension|reference"/> | |
| 13 | + <attr name="kswThumbHeight" format="dimension|reference"/> | |
| 14 | + <attr name="kswThumbRadius" format="dimension|reference"/> | |
| 15 | + <attr name="kswBackRadius" format="dimension|reference"/> | |
| 16 | + <attr name="kswBackDrawable" format="reference"/> | |
| 17 | + <attr name="kswBackColor" format="color|reference"/> | |
| 18 | + <attr name="kswFadeBack" format="boolean"/> | |
| 19 | + <attr name="kswThumbRangeRatio" format="float"/> | |
| 20 | + <attr name="kswAnimationDuration" format="integer"/> | |
| 21 | + <attr name="kswTintColor" format="color|reference"/> | |
| 22 | + <attr name="kswTextOn" format="string"/> | |
| 23 | + <attr name="kswTextOff" format="string"/> | |
| 24 | + <attr name="kswTextThumbInset" format="dimension"/> | |
| 25 | + <attr name="kswTextExtra" format="dimension"/> | |
| 26 | + <attr name="kswTextAdjust" format="dimension"/> | |
| 27 | + </declare-styleable> | |
| 28 | + | |
| 29 | +</resources> | |
| 0 | 30 | \ No newline at end of file | ... | ... |
module_xiaojiaSoundBox/src/main/res/values/colors.xml
| ... | ... | @@ -4,11 +4,23 @@ |
| 4 | 4 | <color name="colorPrimaryDark">#1976D2</color> |
| 5 | 5 | <color name="colorAccent">#03A9F4</color> |
| 6 | 6 | <color name="white">#FFFFFF</color> |
| 7 | + <color name="white_50">#80FFFFFF</color> | |
| 7 | 8 | <color name="black">#000000</color> |
| 9 | + <!--switch--> | |
| 10 | + <color name="ksw_md_ripple_normal">#1E000000</color> | |
| 11 | + <color name="ksw_md_ripple_checked">#33019285</color> | |
| 12 | + <color name="ksw_md_back_color">#33019285</color> | |
| 8 | 13 | |
| 14 | + | |
| 15 | + <color name="ksw_md_solid_shadow">#33000000</color> | |
| 16 | + <color name="ksw_md_solid_normal">#ECECEC</color> | |
| 17 | + <color name="ksw_md_solid_checked">#019285</color> | |
| 18 | + <color name="ksw_md_solid_disable">#FFFFFF</color> | |
| 19 | + <color name="ksw_md_solid_checked_disable">#aaaaaa</color> | |
| 20 | + <!-- --> | |
| 9 | 21 | <!--自定义对话框的线--> |
| 10 | 22 | <color name="app_color_blue">#FF4081</color> |
| 11 | - <color name="line">#EEEEEE</color> | |
| 23 | + <color name="line">#80EEEEEE</color> | |
| 12 | 24 | <color name="btnPress">#666666</color> |
| 13 | 25 | <color name="btnNoPress">#4A90E2</color> |
| 14 | 26 | <color name="transparent">#00000000</color> |
| ... | ... | @@ -20,5 +32,7 @@ |
| 20 | 32 | <color name="round_rectangle_press">#80CCCCCC</color> |
| 21 | 33 | <color name="color_C3C3C3">#C3C3C3</color> |
| 22 | 34 | <color name="color_F2F2F2">#F2F2F2</color> |
| 35 | + <color name="line_15">#26EEEEEE</color> | |
| 36 | + <color name="color_EB3D3F">#EB3D3F</color> | |
| 23 | 37 | |
| 24 | 38 | </resources> | ... | ... |
module_xiaojiaSoundBox/src/main/res/values/dimens.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<resources> | |
| 3 | + <dimen name="ksw_md_thumb_ripple_size">42dp</dimen> | |
| 4 | + <dimen name="ksw_md_thumb_solid_inset">11dp</dimen> | |
| 5 | + <dimen name="ksw_md_thumb_shadow_inset">11dp</dimen> | |
| 6 | + <dimen name="ksw_md_thumb_shadow_inset_top">11dp</dimen> | |
| 7 | + <dimen name="ksw_md_thumb_shadow_inset_bottom">10dp</dimen> | |
| 8 | + | |
| 9 | + <dimen name="ksw_md_thumb_solid_size">20dp</dimen> | |
| 10 | + <dimen name="ksw_md_thumb_shadow_size">21dp</dimen> | |
| 11 | + <dimen name="ksw_md_thumb_shadow_offset">2dp</dimen> | |
| 12 | +</resources> | ... | ... |
module_xiaojiaSoundBox/src/main/res/values/strings.xml
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | <string name="previous_step">上一步</string> |
| 7 | 7 | <string name="btn_retry">重试</string> |
| 8 | 8 | <string name="no_found_device_tip">请尝试重启设备或重新进入配网模式</string> |
| 9 | - <string name="bludeTooth_help">1.请先检查手机系统版本是否满足最低要求\n(仅支持Android4.4版本以上,ios8.0 iPhone4S以上 的手机)。\n\n2.请确认手机已经打开蓝牙。\n\n3.请确保设备已进入配网模式\n(即听到音箱提示: 进入配网模式,请根据手机APP提示进行配网)。\n\n4.请确保音箱设备是否损坏或连接了其他手机。\n\n5.可尝试关闭手机蓝牙,重新打开手机蓝牙后进 入app重试。\n\n6.重启音箱设备后进行配置。\n\n | |
| 9 | + <string name="bludeTooth_help">1.请先检查手机系统版本是否满足最低要求(仅支持Android4.4版本以上,ios8.0 iPhone4S以上的手机)。\n\n2.请确认手机已经打开蓝牙。\n\n3.请确保设备已进入配网模式(即听到音箱提示: 进入配网模式,请根据手机APP提示进行配网)。\n\n4.请确保音箱设备是否损坏或连接了其他手机。\n\n5.可尝试关闭手机蓝牙,重新打开手机蓝牙后进入app重试。\n\n6.重启音箱设备后进行配置。\n\n | |
| 10 | 10 | </string> |
| 11 | 11 | <string name="previous_step_u"><u>上一步</u></string> |
| 12 | 12 | ... | ... |
module_xiaojiaSoundBox/src/main/res/values/styles.xml
| 1 | -<resources> | |
| 1 | +<resources xmlns:tools="http://schemas.android.com/tools"> | |
| 2 | 2 | |
| 3 | 3 | <!--自定义Dialog背景全透明无边框theme--> |
| 4 | 4 | <style name="MyDialog" parent="android:style/Theme.Dialog"> |
| ... | ... | @@ -15,4 +15,16 @@ |
| 15 | 15 | <item name="android:maxHeight">21dp</item> |
| 16 | 16 | <item name="android:background">@drawable/selector_checkbox</item> |
| 17 | 17 | </style> |
| 18 | + <!-- switch--> | |
| 19 | + <style name="SwitchButtonMD" tools:ignore="ResourceName"> | |
| 20 | + <item name="kswThumbDrawable">@drawable/ksw_md_thumb</item> | |
| 21 | + <item name="kswBackColor">@color/ksw_md_back_color</item> | |
| 22 | + <item name="kswThumbRangeRatio">1.45</item> | |
| 23 | + <item name="kswThumbMarginLeft">-16dp</item> | |
| 24 | + <item name="kswThumbMarginTop">-14dp</item> | |
| 25 | + <item name="kswThumbMarginRight">-16dp</item> | |
| 26 | + <item name="kswThumbMarginBottom">-14dp</item> | |
| 27 | + <item name="kswThumbWidth">@dimen/ksw_md_thumb_ripple_size</item> | |
| 28 | + <item name="kswThumbHeight">@dimen/ksw_md_thumb_ripple_size</item> | |
| 29 | + </style> | |
| 18 | 30 | </resources> | ... | ... |