mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
refactor: implements DrawerMenu with RecyclerView
This commit is contained in:
parent
0c83d4d96a
commit
5f2abf2d85
@ -2,8 +2,8 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Auto.js.iml" filepath="$PROJECT_DIR$/Auto.js.iml" />
|
||||
<module fileurl="file://E:\YiBin\AndroidStudioProjects\NoRootScriptDroid\Auto.js.iml" filepath="E:\YiBin\AndroidStudioProjects\NoRootScriptDroid\Auto.js.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/NoRootScriptDroid.iml" filepath="$PROJECT_DIR$/NoRootScriptDroid.iml" />
|
||||
<module fileurl="file://C:\Users\Stardust\Documents\AndroidProjects\Auto.js\NoRootScriptDroid.iml" filepath="C:\Users\Stardust\Documents\AndroidProjects\Auto.js\NoRootScriptDroid.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/autojs/autojs.iml" filepath="$PROJECT_DIR$/autojs/autojs.iml" />
|
||||
|
||||
@ -6,6 +6,8 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
@ -50,6 +52,9 @@ import org.androidannotations.annotations.ViewById;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
@ -58,43 +63,34 @@ import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/30.
|
||||
* TODO 侧拉菜单用RecyclerView
|
||||
* TODO these codes are so ugly!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*/
|
||||
@EFragment(R.layout.fragment_drawer)
|
||||
public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
|
||||
private static final String URL_SUBLIME_PLUGIN_HELP = "https://github.com/hyb1996/AutoJs-Sublime-Plugin/blob/master/Readme.md";
|
||||
|
||||
@ViewById(R.id.debug)
|
||||
DrawerMenuItem mConnectionItem;
|
||||
|
||||
@ViewById(R.id.accessibility_service)
|
||||
DrawerMenuItem mAccessibilityServiceItem;
|
||||
|
||||
@ViewById(R.id.notification_service)
|
||||
DrawerMenuItem mNotificationPermissionItem;
|
||||
|
||||
@ViewById(R.id.floating_window)
|
||||
DrawerMenuItem mFloatingWindowItem;
|
||||
|
||||
@ViewById(R.id.check_for_updates)
|
||||
DrawerMenuItem mCheckForUpdatesItem;
|
||||
|
||||
@ViewById(R.id.header)
|
||||
View mHeaderView;
|
||||
|
||||
@ViewById(R.id.username)
|
||||
TextView mUserName;
|
||||
|
||||
@ViewById(R.id.avatar)
|
||||
AvatarView mAvatar;
|
||||
|
||||
@ViewById(R.id.shadow)
|
||||
View mShadow;
|
||||
|
||||
@ViewById(R.id.default_cover)
|
||||
View mDefaultCover;
|
||||
@ViewById(R.id.drawer_menu)
|
||||
RecyclerView mDrawerMenu;
|
||||
|
||||
|
||||
private DrawerMenuItem mConnectionItem = new DrawerMenuItem(R.drawable.ic_debug, R.string.debug, 0, this::connectOrDisconnectToRemote);
|
||||
private DrawerMenuItem mAccessibilityServiceItem = new DrawerMenuItem(R.drawable.ic_service_green, R.string.text_accessibility_service, 0, this::enableOrDisableAccessibilityService);
|
||||
private DrawerMenuItem mNotificationPermissionItem = new DrawerMenuItem(R.drawable.ic_ali_notification, R.string.text_notification_permission, 0, this::goToNotificationServiceSettings);
|
||||
private DrawerMenuItem mFloatingWindowItem = new DrawerMenuItem(R.drawable.ic_robot_64, R.string.text_floating_window, 0, this::showOrDismissFloatingWindow);
|
||||
private DrawerMenuItem mCheckForUpdatesItem = new DrawerMenuItem(R.drawable.ic_check_for_updates, R.string.text_check_for_updates, this::checkForUpdates);
|
||||
|
||||
private DrawerMenuAdapter mDrawerMenuAdapter;
|
||||
private Disposable mConnectionStateDisposable;
|
||||
|
||||
|
||||
@ -105,8 +101,8 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(state -> {
|
||||
if (mConnectionItem != null) {
|
||||
mConnectionItem.getSwitchCompat().setChecked(state.getState() == DevPluginClient.State.CONNECTED, false);
|
||||
mConnectionItem.setProgress(state.getState() == DevPluginClient.State.CONNECTING);
|
||||
setChecked(mConnectionItem, state.getState() == DevPluginClient.State.CONNECTED);
|
||||
setProgress(mConnectionItem, state.getState() == DevPluginClient.State.CONNECTING);
|
||||
}
|
||||
if (state.getException() != null) {
|
||||
showMessage(state.getException().getMessage());
|
||||
@ -116,6 +112,162 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
|
||||
}
|
||||
|
||||
@AfterViews
|
||||
void setUpViews() {
|
||||
ThemeColorManager.addViewBackground(mHeaderView);
|
||||
initMenuItems();
|
||||
if (Pref.isFloatingMenuShown()) {
|
||||
setChecked(mFloatingWindowItem, true);
|
||||
}
|
||||
setChecked(mConnectionItem, DevPluginService.getInstance().isConnected());
|
||||
}
|
||||
|
||||
private void initMenuItems() {
|
||||
mDrawerMenuAdapter = new DrawerMenuAdapter(new ArrayList<>(Arrays.asList(
|
||||
new DrawerMenuGroup(R.string.text_service),
|
||||
mAccessibilityServiceItem,
|
||||
new DrawerMenuItem(R.drawable.ic_stable, R.string.text_stable_mode, R.string.key_stable_mode, null),
|
||||
mNotificationPermissionItem,
|
||||
|
||||
new DrawerMenuGroup(R.string.text_script_record),
|
||||
mFloatingWindowItem,
|
||||
new DrawerMenuItem(R.drawable.ic_volume, R.string.text_volume_down_control, R.string.key_use_volume_control_record, null),
|
||||
|
||||
new DrawerMenuGroup(R.string.text_others),
|
||||
mConnectionItem,
|
||||
new DrawerMenuItem(R.drawable.ic_personalize, R.string.text_theme_color, this::openThemeColorSettings),
|
||||
mCheckForUpdatesItem
|
||||
)));
|
||||
mDrawerMenu.setAdapter(mDrawerMenuAdapter);
|
||||
mDrawerMenu.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
}
|
||||
|
||||
|
||||
@Click(R.id.avatar)
|
||||
void loginOrShowUserInfo() {
|
||||
NodeBB.getInstance().getRetrofit()
|
||||
.create(UserApi.class)
|
||||
.me()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe((user ->
|
||||
WebActivity_.intent(this)
|
||||
.extra(WebActivity.EXTRA_URL, NodeBB.url("user/" + user.getUserslug()))
|
||||
.extra(Intent.EXTRA_TITLE, user.getUsername())
|
||||
.start()),
|
||||
error -> LoginActivity_.intent(getActivity()).start());
|
||||
}
|
||||
|
||||
|
||||
void enableOrDisableAccessibilityService(DrawerMenuItemViewHolder holder) {
|
||||
boolean isAccessibilityServiceEnabled = isAccessibilityServiceEnabled();
|
||||
boolean checked = holder.getSwitchCompat().isChecked();
|
||||
if (checked && !isAccessibilityServiceEnabled) {
|
||||
enableAccessibilityService();
|
||||
} else if (!checked && isAccessibilityServiceEnabled) {
|
||||
if (!AccessibilityService.disable()) {
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void goToNotificationServiceSettings(DrawerMenuItemViewHolder holder) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
return;
|
||||
}
|
||||
boolean enabled = NotificationListenerService.getInstance() != null;
|
||||
boolean checked = holder.getSwitchCompat().isChecked();
|
||||
if ((checked && !enabled) || (!checked && enabled)) {
|
||||
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
|
||||
}
|
||||
}
|
||||
|
||||
void showOrDismissFloatingWindow(DrawerMenuItemViewHolder holder) {
|
||||
boolean isFloatingWindowShowing = FloatyWindowManger.isCircularMenuShowing();
|
||||
boolean checked = holder.getSwitchCompat().isChecked();
|
||||
if (getActivity() != null && !getActivity().isFinishing()) {
|
||||
Pref.setFloatingMenuShown(checked);
|
||||
}
|
||||
if (checked && !isFloatingWindowShowing) {
|
||||
FloatyWindowManger.showCircularMenu();
|
||||
enableAccessibilityServiceByRootIfNeeded();
|
||||
} else if (!checked && isFloatingWindowShowing) {
|
||||
FloatyWindowManger.hideCircularMenu();
|
||||
}
|
||||
}
|
||||
|
||||
void openThemeColorSettings(DrawerMenuItemViewHolder holder) {
|
||||
SettingsActivity.selectThemeColor(getActivity());
|
||||
}
|
||||
|
||||
private void enableAccessibilityServiceByRootIfNeeded() {
|
||||
Observable.fromCallable(() -> Pref.shouldEnableAccessibilityServiceByRoot() && !isAccessibilityServiceEnabled())
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(needed -> {
|
||||
if (needed) {
|
||||
enableAccessibilityServiceByRoot();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void connectOrDisconnectToRemote(DrawerMenuItemViewHolder holder) {
|
||||
boolean checked = holder.getSwitchCompat().isChecked();
|
||||
boolean connected = DevPluginService.getInstance().isConnected();
|
||||
if (checked && !connected) {
|
||||
inputRemoteHost();
|
||||
} else if (!checked && connected) {
|
||||
DevPluginService.getInstance().disconnectIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
private void inputRemoteHost() {
|
||||
String host = Pref.getServerAddressOrDefault(WifiTool.getRouterIp(getActivity()));
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.title(R.string.text_server_address)
|
||||
.input("", host, (dialog, input) -> {
|
||||
Pref.saveServerAddress(input.toString());
|
||||
DevPluginService.getInstance().connectToServer(host);
|
||||
})
|
||||
.neutralText(R.string.text_help)
|
||||
.onNeutral((dialog, which) -> {
|
||||
setChecked(mConnectionItem, false);
|
||||
IntentUtil.browse(getActivity(), URL_SUBLIME_PLUGIN_HELP);
|
||||
})
|
||||
.cancelListener(dialog -> setChecked(mConnectionItem, false))
|
||||
.show();
|
||||
}
|
||||
|
||||
void checkForUpdates(DrawerMenuItemViewHolder holder) {
|
||||
setProgress(mCheckForUpdatesItem, true);
|
||||
VersionService.getInstance().checkForUpdates()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new SimpleObserver<VersionInfo>() {
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.annotations.NonNull VersionInfo versionInfo) {
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
if (versionInfo.isNewer()) {
|
||||
new UpdateInfoDialogBuilder(getActivity(), versionInfo)
|
||||
.show();
|
||||
} else {
|
||||
Toast.makeText(App.getApp(), R.string.text_is_latest_version, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
setProgress(mCheckForUpdatesItem, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.annotations.NonNull Throwable e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(App.getApp(), R.string.text_check_update_error, Toast.LENGTH_SHORT).show();
|
||||
setProgress(mCheckForUpdatesItem, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@ -123,15 +275,6 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
syncUserInfo();
|
||||
}
|
||||
|
||||
@AfterViews
|
||||
void setUpViews() {
|
||||
ThemeColorManager.addViewBackground(mHeaderView);
|
||||
if (Pref.isFloatingMenuShown()) {
|
||||
mFloatingWindowItem.getSwitchCompat().setChecked(true);
|
||||
}
|
||||
mConnectionItem.getSwitchCompat().setChecked(DevPluginService.getInstance().isConnected(), false);
|
||||
}
|
||||
|
||||
private void syncUserInfo() {
|
||||
NodeBB.getInstance().getRetrofit()
|
||||
.create(UserApi.class)
|
||||
@ -177,158 +320,10 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Click(R.id.avatar)
|
||||
void loginOrShowUserInfo() {
|
||||
NodeBB.getInstance().getRetrofit()
|
||||
.create(UserApi.class)
|
||||
.me()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe((user -> {
|
||||
WebActivity_.intent(this)
|
||||
.extra(WebActivity.EXTRA_URL, NodeBB.url("user/" + user.getUserslug()))
|
||||
.extra(Intent.EXTRA_TITLE, user.getUsername())
|
||||
.start();
|
||||
}), error -> {
|
||||
LoginActivity_.intent(getActivity()).start();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Click(R.id.accessibility_service)
|
||||
void enableOrDisableAccessibilityService() {
|
||||
boolean isAccessibilityServiceEnabled = isAccessibilityServiceEnabled();
|
||||
boolean checked = mAccessibilityServiceItem.getSwitchCompat().isChecked();
|
||||
if (checked && !isAccessibilityServiceEnabled) {
|
||||
enableAccessibilityService();
|
||||
} else if (!checked && isAccessibilityServiceEnabled) {
|
||||
if (!AccessibilityService.disable()) {
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Click(R.id.notification_service)
|
||||
void goToNotificationServiceSettings() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
return;
|
||||
}
|
||||
boolean enabled = NotificationListenerService.getInstance() != null;
|
||||
boolean checked = mNotificationPermissionItem.getSwitchCompat().isChecked();
|
||||
if ((checked && !enabled) || (!checked && enabled)) {
|
||||
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean isAccessibilityServiceEnabled() {
|
||||
return AccessibilityServiceTool.isAccessibilityServiceEnabled(getActivity());
|
||||
}
|
||||
|
||||
@Click(R.id.floating_window)
|
||||
void showOrDismissFloatingWindow() {
|
||||
boolean isFloatingWindowShowing = FloatyWindowManger.isCircularMenuShowing();
|
||||
boolean checked = mFloatingWindowItem.getSwitchCompat().isChecked();
|
||||
if (getActivity() != null && !getActivity().isFinishing()) {
|
||||
Pref.setFloatingMenuShown(checked);
|
||||
}
|
||||
if (checked && !isFloatingWindowShowing) {
|
||||
FloatyWindowManger.showCircularMenu();
|
||||
enableAccessibilityServiceByRootIfNeeded();
|
||||
} else if (!checked && isFloatingWindowShowing) {
|
||||
FloatyWindowManger.hideCircularMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@Click(R.id.theme_color)
|
||||
void openThemeColorSettings() {
|
||||
SettingsActivity.selectThemeColor(getActivity());
|
||||
}
|
||||
|
||||
private void enableAccessibilityServiceByRootIfNeeded() {
|
||||
Observable.fromCallable(() -> Pref.shouldEnableAccessibilityServiceByRoot() && !isAccessibilityServiceEnabled())
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(needed -> {
|
||||
if (needed) {
|
||||
enableAccessibilityServiceByRoot();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Click(R.id.debug)
|
||||
void connectOrDisconnectToRemote() {
|
||||
boolean checked = mConnectionItem.getSwitchCompat().isChecked();
|
||||
boolean connected = DevPluginService.getInstance().isConnected();
|
||||
if (checked && !connected) {
|
||||
inputRemoteHost();
|
||||
} else if (!checked && connected) {
|
||||
DevPluginService.getInstance().disconnectIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
private void inputRemoteHost() {
|
||||
String host = Pref.getServerAddressOrDefault(WifiTool.getRouterIp(getActivity()));
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.title(R.string.text_server_address)
|
||||
.input("", host, (dialog, input) -> {
|
||||
Pref.saveServerAddress(input.toString());
|
||||
connectToRemote(input.toString());
|
||||
})
|
||||
.neutralText(R.string.text_help)
|
||||
.onNeutral((dialog, which) -> {
|
||||
mConnectionItem.getSwitchCompat().setChecked(false, false);
|
||||
IntentUtil.browse(getActivity(), URL_SUBLIME_PLUGIN_HELP);
|
||||
})
|
||||
.cancelListener(dialog -> mConnectionItem.getSwitchCompat().setChecked(false, false))
|
||||
.show();
|
||||
}
|
||||
|
||||
private void connectToRemote(String host) {
|
||||
DevPluginService.getInstance().connectToServer(host);
|
||||
}
|
||||
|
||||
@Click(R.id.check_for_updates)
|
||||
void checkForUpdates() {
|
||||
mCheckForUpdatesItem.setProgress(true);
|
||||
VersionService.getInstance().checkForUpdates()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new SimpleObserver<VersionInfo>() {
|
||||
|
||||
@Override
|
||||
public void onNext(@io.reactivex.annotations.NonNull VersionInfo versionInfo) {
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
if (versionInfo.isNewer()) {
|
||||
new UpdateInfoDialogBuilder(getActivity(), versionInfo)
|
||||
.show();
|
||||
} else {
|
||||
Toast.makeText(App.getApp(), R.string.text_is_latest_version, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
mCheckForUpdatesItem.setProgress(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.annotations.NonNull Throwable e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(App.getApp(), R.string.text_check_update_error, Toast.LENGTH_SHORT).show();
|
||||
mCheckForUpdatesItem.setProgress(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onCircularMenuStateChange(CircularMenu.StateChangeEvent event) {
|
||||
mFloatingWindowItem.getSwitchCompat().setChecked(event.getCurrentState() != CircularMenu.STATE_CLOSED);
|
||||
}
|
||||
|
||||
|
||||
private void syncSwitchState() {
|
||||
mAccessibilityServiceItem.getSwitchCompat().setChecked(
|
||||
AccessibilityServiceTool.isAccessibilityServiceEnabled(getActivity()));
|
||||
setChecked(mAccessibilityServiceItem, AccessibilityServiceTool.isAccessibilityServiceEnabled(getActivity()));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
mNotificationPermissionItem.getSwitchCompat().setChecked(NotificationListenerService.getInstance() != null);
|
||||
setChecked(mNotificationPermissionItem, NotificationListenerService.getInstance() != null);
|
||||
}
|
||||
|
||||
}
|
||||
@ -342,7 +337,7 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
}
|
||||
|
||||
private void enableAccessibilityServiceByRoot() {
|
||||
mAccessibilityServiceItem.setProgress(true);
|
||||
setProgress(mAccessibilityServiceItem, true);
|
||||
Observable.fromCallable(() -> AccessibilityServiceTool.enableAccessibilityServiceByRootAndWaitFor(4000))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -351,22 +346,44 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
||||
Toast.makeText(getContext(), R.string.text_enable_accessibitliy_service_by_root_failed, Toast.LENGTH_SHORT).show();
|
||||
AccessibilityServiceTool.goToAccessibilitySetting();
|
||||
}
|
||||
mAccessibilityServiceItem.setProgress(false);
|
||||
setProgress(mAccessibilityServiceItem, false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onCircularMenuStateChange(CircularMenu.StateChangeEvent event) {
|
||||
setChecked(mFloatingWindowItem, event.getCurrentState() != CircularMenu.STATE_CLOSED);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mConnectionStateDisposable.dispose();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
|
||||
private void showMessage(CharSequence text) {
|
||||
if (getContext() == null)
|
||||
return;
|
||||
Toast.makeText(getContext(), text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mConnectionStateDisposable.dispose();
|
||||
EventBus.getDefault().unregister(this);
|
||||
|
||||
private void setProgress(DrawerMenuItem item, boolean progress) {
|
||||
item.setProgress(progress);
|
||||
mDrawerMenuAdapter.notifyItemChanged(item);
|
||||
}
|
||||
|
||||
private void setChecked(DrawerMenuItem item, boolean checked) {
|
||||
item.setChecked(checked);
|
||||
mDrawerMenuAdapter.notifyItemChanged(item);
|
||||
}
|
||||
|
||||
private boolean isAccessibilityServiceEnabled() {
|
||||
return AccessibilityServiceTool.isAccessibilityServiceEnabled(getActivity());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
package com.stardust.scriptdroid.ui.main.drawer;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.widget.BindableViewHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/12/10.
|
||||
*/
|
||||
|
||||
public class DrawerMenuAdapter extends RecyclerView.Adapter<BindableViewHolder<DrawerMenuItem>> {
|
||||
|
||||
|
||||
private static final int VIEW_TYPE_ITEM = 0;
|
||||
private static final int VIEW_TYPE_GROUP = 1;
|
||||
|
||||
|
||||
private List<DrawerMenuItem> mDrawerMenuItems;
|
||||
|
||||
public DrawerMenuAdapter(List<DrawerMenuItem> drawerMenuItems) {
|
||||
mDrawerMenuItems = drawerMenuItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindableViewHolder<DrawerMenuItem> onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == VIEW_TYPE_GROUP) {
|
||||
return new DrawerMenuGroupViewHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.drawer_menu_group, parent, false));
|
||||
} else {
|
||||
return new DrawerMenuItemViewHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.drawer_menu_item, parent, false));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(BindableViewHolder<DrawerMenuItem> holder, int position) {
|
||||
holder.bind(mDrawerMenuItems.get(position), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDrawerMenuItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return mDrawerMenuItems.get(position) instanceof DrawerMenuGroup ?
|
||||
VIEW_TYPE_GROUP : VIEW_TYPE_ITEM;
|
||||
}
|
||||
|
||||
public void notifyItemChanged(DrawerMenuItem item) {
|
||||
int pos = mDrawerMenuItems.indexOf(item);
|
||||
notifyItemChanged(pos);
|
||||
}
|
||||
}
|
||||
@ -1,65 +1,13 @@
|
||||
package com.stardust.scriptdroid.ui.main.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/8/25.
|
||||
*/
|
||||
|
||||
public class DrawerMenuGroup extends LinearLayout {
|
||||
public class DrawerMenuGroup extends DrawerMenuItem {
|
||||
|
||||
private TextView mTitle;
|
||||
|
||||
public DrawerMenuGroup(Context context) {
|
||||
super(context);
|
||||
init(null);
|
||||
}
|
||||
|
||||
public DrawerMenuGroup(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
public DrawerMenuGroup(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public DrawerMenuGroup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
private void init(AttributeSet attrs) {
|
||||
setOrientation(VERTICAL);
|
||||
addTitleView();
|
||||
if (attrs == null) {
|
||||
return;
|
||||
}
|
||||
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DrawerMenuItem);
|
||||
mTitle.setText(a.getString(R.styleable.DrawerMenuItem_title));
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
private void addTitleView() {
|
||||
mTitle = new TextView(getContext());
|
||||
int padding = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
|
||||
mTitle.setPadding(padding, padding, padding, padding);
|
||||
mTitle.setTextColor(0xff999999);
|
||||
mTitle.setTextSize(12);
|
||||
addView(mTitle, 0);
|
||||
public DrawerMenuGroup(int title) {
|
||||
super(0, title, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
package com.stardust.scriptdroid.ui.main.drawer;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.widget.BindableViewHolder;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/12/10.
|
||||
*/
|
||||
|
||||
public class DrawerMenuGroupViewHolder extends BindableViewHolder<DrawerMenuItem> {
|
||||
|
||||
private TextView mTextView;
|
||||
|
||||
public DrawerMenuGroupViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mTextView = (TextView) itemView.findViewById(R.id.title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DrawerMenuItem data, int position) {
|
||||
mTextView.setText(data.getTitle());
|
||||
int padding = itemView.getResources().getDimensionPixelOffset(R.dimen.divider_drawer_menu_group);
|
||||
itemView.setPadding(0, position == 0 ? 0 : padding, 0, 0);
|
||||
}
|
||||
}
|
||||
@ -1,135 +1,80 @@
|
||||
package com.stardust.scriptdroid.ui.main.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.widget.PrefSwitch;
|
||||
import com.stardust.scriptdroid.ui.widget.SwitchCompat;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/8/25.
|
||||
*/
|
||||
public class DrawerMenuItem extends FrameLayout {
|
||||
|
||||
private static final long CLICK_TIMEOUT = 1000;
|
||||
|
||||
@BindView(R.id.sw)
|
||||
PrefSwitch mSwitchCompat;
|
||||
|
||||
@BindView(R.id.progress_bar)
|
||||
MaterialProgressBar mProgressBar;
|
||||
|
||||
@BindView(R.id.icon)
|
||||
ImageView mIcon;
|
||||
|
||||
@BindView(R.id.title)
|
||||
TextView mTitle;
|
||||
public class DrawerMenuItem {
|
||||
|
||||
|
||||
private OnClickListener mOnClickListener;
|
||||
private boolean mAntiShake = false;
|
||||
private long mLastClickMillis;
|
||||
|
||||
public DrawerMenuItem(Context context) {
|
||||
super(context);
|
||||
init(null);
|
||||
public interface Action {
|
||||
void onClick(DrawerMenuItemViewHolder holder);
|
||||
}
|
||||
|
||||
public DrawerMenuItem(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(attrs);
|
||||
private int mIcon;
|
||||
private int mTitle;
|
||||
private boolean mAntiShake;
|
||||
private boolean mSwitchEnabled;
|
||||
private int mPrefKey;
|
||||
private Action mAction;
|
||||
private boolean mSwitchChecked;
|
||||
private boolean mOnProgress;
|
||||
|
||||
public DrawerMenuItem(int icon, int title, Action action) {
|
||||
mIcon = icon;
|
||||
mTitle = title;
|
||||
mAction = action;
|
||||
}
|
||||
|
||||
public DrawerMenuItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public DrawerMenuItem(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
private void init(AttributeSet attrs) {
|
||||
inflate(getContext(), R.layout.drawer_menu_item, this);
|
||||
ButterKnife.bind(this, this);
|
||||
if (attrs == null)
|
||||
return;
|
||||
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DrawerMenuItem);
|
||||
mIcon.setImageResource(a.getResourceId(R.styleable.DrawerMenuItem_icon, 0));
|
||||
mTitle.setText(a.getString(R.styleable.DrawerMenuItem_title));
|
||||
mAntiShake = a.getBoolean(R.styleable.DrawerMenuItem_anti_shake, false);
|
||||
if (a.getBoolean(R.styleable.DrawerMenuItem_with_switch, false)) {
|
||||
enableSwitch(a.getString(R.styleable.DrawerMenuItem_pref_key));
|
||||
public DrawerMenuItem(int icon, int title, int prefKey, Action action) {
|
||||
mIcon = icon;
|
||||
mTitle = title;
|
||||
mAction = action;
|
||||
if (prefKey == 0) {
|
||||
mAntiShake = true;
|
||||
}
|
||||
a.recycle();
|
||||
mPrefKey = prefKey;
|
||||
mSwitchEnabled = true;
|
||||
}
|
||||
|
||||
private void enableSwitch(String prefKey) {
|
||||
mSwitchCompat.setVisibility(VISIBLE);
|
||||
if (prefKey != null) {
|
||||
mSwitchCompat.setPrefKey(prefKey);
|
||||
}
|
||||
mSwitchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
onClick();
|
||||
}
|
||||
});
|
||||
super.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mSwitchCompat.toggle();
|
||||
}
|
||||
});
|
||||
public int getIcon() {
|
||||
return mIcon;
|
||||
}
|
||||
|
||||
private void onClick() {
|
||||
if (mAntiShake && (System.currentTimeMillis() - mLastClickMillis < CLICK_TIMEOUT)) {
|
||||
Toast.makeText(getContext(), R.string.text_click_too_frequently, Toast.LENGTH_SHORT).show();
|
||||
mSwitchCompat.setChecked(!mSwitchCompat.isChecked(), false);
|
||||
return;
|
||||
}
|
||||
mLastClickMillis = System.currentTimeMillis();
|
||||
if (mOnClickListener != null) {
|
||||
mOnClickListener.onClick(DrawerMenuItem.this);
|
||||
}
|
||||
public int getTitle() {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public boolean antiShake() {
|
||||
return mAntiShake;
|
||||
}
|
||||
|
||||
public boolean isSwitchEnabled() {
|
||||
return mSwitchEnabled;
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
mSwitchChecked = checked;
|
||||
}
|
||||
|
||||
public boolean isChecked() {
|
||||
return mSwitchChecked;
|
||||
}
|
||||
|
||||
|
||||
public boolean isProgress() {
|
||||
return mOnProgress;
|
||||
}
|
||||
|
||||
public void setProgress(boolean onProgress) {
|
||||
mProgressBar.setVisibility(onProgress ? VISIBLE : GONE);
|
||||
mIcon.setVisibility(onProgress ? GONE : VISIBLE);
|
||||
mSwitchCompat.setEnabled(!onProgress);
|
||||
setEnabled(!onProgress);
|
||||
|
||||
mOnProgress = onProgress;
|
||||
}
|
||||
|
||||
public SwitchCompat getSwitchCompat() {
|
||||
return mSwitchCompat;
|
||||
public int getPrefKey() {
|
||||
return mPrefKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnClickListener(OnClickListener onClickListener) {
|
||||
if (mSwitchCompat.getVisibility() == VISIBLE) {
|
||||
mOnClickListener = onClickListener;
|
||||
} else {
|
||||
super.setOnClickListener(onClickListener);
|
||||
}
|
||||
public void performAction(DrawerMenuItemViewHolder holder) {
|
||||
if (mAction != null)
|
||||
mAction.onClick(holder);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,102 @@
|
||||
package com.stardust.scriptdroid.ui.main.drawer;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.widget.BindableViewHolder;
|
||||
import com.stardust.scriptdroid.ui.widget.PrefSwitch;
|
||||
import com.stardust.scriptdroid.ui.widget.SwitchCompat;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/12/10.
|
||||
*/
|
||||
|
||||
public class DrawerMenuItemViewHolder extends BindableViewHolder<DrawerMenuItem> {
|
||||
|
||||
private static final long CLICK_TIMEOUT = 1000;
|
||||
@BindView(R.id.sw)
|
||||
PrefSwitch mSwitchCompat;
|
||||
|
||||
@BindView(R.id.progress_bar)
|
||||
MaterialProgressBar mProgressBar;
|
||||
|
||||
@BindView(R.id.icon)
|
||||
ImageView mIcon;
|
||||
|
||||
@BindView(R.id.title)
|
||||
TextView mTitle;
|
||||
private boolean mAntiShake;
|
||||
private long mLastClickMillis;
|
||||
private DrawerMenuItem mDrawerMenuItem;
|
||||
|
||||
public DrawerMenuItemViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
mSwitchCompat.setOnCheckedChangeListener((buttonView, isChecked) -> onClick());
|
||||
itemView.setOnClickListener(v -> {
|
||||
if (mSwitchCompat.getVisibility() == VISIBLE) {
|
||||
mSwitchCompat.toggle();
|
||||
} else {
|
||||
onClick();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DrawerMenuItem item, int position) {
|
||||
mDrawerMenuItem = item;
|
||||
mIcon.setImageResource(item.getIcon());
|
||||
mTitle.setText(item.getTitle());
|
||||
mAntiShake = item.antiShake();
|
||||
setSwitch(item);
|
||||
setProgress(item.isProgress());
|
||||
}
|
||||
|
||||
private void setSwitch(DrawerMenuItem item) {
|
||||
if (!item.isSwitchEnabled()) {
|
||||
mSwitchCompat.setVisibility(GONE);
|
||||
return;
|
||||
}
|
||||
mSwitchCompat.setVisibility(VISIBLE);
|
||||
int prefKey = item.getPrefKey();
|
||||
if (prefKey != 0) {
|
||||
mSwitchCompat.setPrefKey(itemView.getResources().getString(prefKey));
|
||||
}
|
||||
mSwitchCompat.setChecked(item.isChecked());
|
||||
}
|
||||
|
||||
private void onClick() {
|
||||
if (mAntiShake && (System.currentTimeMillis() - mLastClickMillis < CLICK_TIMEOUT)) {
|
||||
Toast.makeText(itemView.getContext(), R.string.text_click_too_frequently, Toast.LENGTH_SHORT).show();
|
||||
mSwitchCompat.setChecked(!mSwitchCompat.isChecked(), false);
|
||||
return;
|
||||
}
|
||||
mLastClickMillis = System.currentTimeMillis();
|
||||
if (mDrawerMenuItem != null) {
|
||||
mDrawerMenuItem.performAction(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void setProgress(boolean onProgress) {
|
||||
mProgressBar.setVisibility(onProgress ? VISIBLE : GONE);
|
||||
mIcon.setVisibility(onProgress ? GONE : VISIBLE);
|
||||
mSwitchCompat.setEnabled(!onProgress);
|
||||
itemView.setEnabled(!onProgress);
|
||||
}
|
||||
|
||||
public SwitchCompat getSwitchCompat() {
|
||||
return mSwitchCompat;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<size
|
||||
android:width="100dp"
|
||||
android:height="6dp"/>
|
||||
|
||||
<solid android:color="#f0f1f5"/>
|
||||
</shape>
|
||||
@ -1,110 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="@drawable/drawer_menu_divider"
|
||||
android:orientation="vertical"
|
||||
android:showDividers="middle">
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/text_service">
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuItem
|
||||
android:id="@+id/accessibility_service"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:anti_shake="true"
|
||||
app:icon="@drawable/ic_service_green"
|
||||
app:title="@string/text_accessibility_service"
|
||||
app:with_switch="true"/>
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuItem
|
||||
android:id="@+id/stable_mode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_stable"
|
||||
app:pref_key="@string/key_stable_mode"
|
||||
app:title="@string/text_stable_mode"
|
||||
app:with_switch="true"/>
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuItem
|
||||
android:id="@+id/notification_service"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_ali_notification"
|
||||
app:title="@string/text_notification_permission"
|
||||
app:with_switch="true"/>
|
||||
|
||||
|
||||
</com.stardust.scriptdroid.ui.main.drawer.DrawerMenuGroup>
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/text_script_record">
|
||||
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuItem
|
||||
android:id="@+id/floating_window"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:anti_shake="true"
|
||||
app:icon="@drawable/ic_robot_64"
|
||||
app:title="@string/text_floating_window"
|
||||
app:with_switch="true"/>
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuItem
|
||||
android:id="@+id/volume_down_control"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_volume"
|
||||
app:pref_key="@string/key_use_volume_control_record"
|
||||
app:title="@string/text_volume_down_control"
|
||||
app:with_switch="true"/>
|
||||
|
||||
|
||||
</com.stardust.scriptdroid.ui.main.drawer.DrawerMenuGroup>
|
||||
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:title="@string/text_others">
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuItem
|
||||
android:id="@+id/debug"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:anti_shake="true"
|
||||
app:icon="@drawable/ic_debug"
|
||||
app:title="@string/debug"
|
||||
app:with_switch="true"/>
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuItem
|
||||
android:id="@+id/theme_color"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_personalize"
|
||||
app:title="@string/text_theme_color"/>
|
||||
|
||||
<com.stardust.scriptdroid.ui.main.drawer.DrawerMenuItem
|
||||
android:id="@+id/check_for_updates"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_check_for_updates"
|
||||
app:title="@string/text_check_for_updates"/>
|
||||
|
||||
</com.stardust.scriptdroid.ui.main.drawer.DrawerMenuGroup>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</ScrollView>
|
||||
18
app/src/main/res/layout/drawer_menu_group.xml
Normal file
18
app/src/main/res/layout/drawer_menu_group.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#f0f1f5"
|
||||
android:paddingTop="@dimen/divider_drawer_menu_group">
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#ffffff"
|
||||
android:padding="8dp"
|
||||
android:textColor="#999999"
|
||||
android:textSize="12sp">
|
||||
|
||||
</TextView>
|
||||
</FrameLayout>
|
||||
@ -1,60 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.stardust.scriptdroid.ui.edit.EditorView_
|
||||
android:id="@+id/editor_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.stardust.scriptdroid.ui.widget.ToolbarMenuItem
|
||||
android:id="@+id/close"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="match_parent"
|
||||
app:icon="@drawable/ic_close_white_48dp"
|
||||
app:text="@string/text_close"/>
|
||||
|
||||
<com.stardust.scriptdroid.ui.widget.ToolbarMenuItem
|
||||
android:id="@+id/move_or_resize"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="match_parent"
|
||||
app:icon="@drawable/ic_settings_ethernet_white_24dp"
|
||||
app:text="@string/text_adjust"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/resizer"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="@drawable/circle_cool_black"
|
||||
android:padding="6dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_resizer"
|
||||
android:tint="@android:color/white"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/move_cursor"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="@drawable/circle_cool_black"
|
||||
android:padding="5dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_move_cursor"
|
||||
android:tint="@android:color/white"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</RelativeLayout>
|
||||
@ -63,12 +63,13 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
layout="@layout/drawer_menu"
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/drawer_menu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
|
||||
@ -5,10 +5,6 @@
|
||||
android:id="@+id/run_repeatedly"
|
||||
android:title="@string/text_run_repeatedly"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/floating_edit"
|
||||
android:title="@string/text_floating_edit"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/create_shortcut"
|
||||
android:title="@string/text_send_shortcut"/>
|
||||
|
||||
@ -26,10 +26,6 @@
|
||||
android:id="@+id/timed_task"
|
||||
android:title="@string/text_timed_task"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/floating_edit"
|
||||
android:title="@string/text_floating_edit"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/create_shortcut"
|
||||
android:title="@string/text_send_shortcut"/>
|
||||
|
||||
@ -88,7 +88,6 @@
|
||||
<string name="text_help">Help</string>
|
||||
<string name="text_no_floating_window_permission">No floating window permission</string>
|
||||
<string name="text_no_accessibility_permission_to_capture">Accessibility service is not activated</string>
|
||||
<string name="text_reset_background">Reset background settings</string>
|
||||
<string name="text_record_msg">Recording Prompt</string>
|
||||
<string name="text_text_changed">Text Changed</string>
|
||||
<string name="text_scrolled">Scrolled</string>
|
||||
@ -116,7 +115,6 @@
|
||||
<string name="text_processing">Processing</string>
|
||||
<string name="text_pre_execute_script">Pre-execute script</string>
|
||||
<string name="text_check_for_updates">Check for updates</string>
|
||||
<string name="text_already_reset">已重置</string>
|
||||
<string name="text_layout_inspector_is_dumping">布局分析中,请稍后点击</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@ -7,6 +7,6 @@
|
||||
<dimen name="script_and_folder_list_divider_left_margin">0dp</dimen>
|
||||
<dimen name="script_and_folder_list_divider_right_margin">0dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<dimen name="padding_item_property">8dp</dimen>
|
||||
<dimen name="textSize_item_property">14sp</dimen>
|
||||
<dimen name="divider_drawer_menu_group">6dp</dimen>
|
||||
</resources>
|
||||
|
||||
@ -91,7 +91,6 @@
|
||||
<string name="text_help">帮助</string>
|
||||
<string name="text_no_floating_window_permission">没有悬浮窗权限</string>
|
||||
<string name="text_no_accessibility_permission_to_capture">无障碍服务未启动</string>
|
||||
<string name="text_reset_background">重置背景图片设置</string>
|
||||
<string name="text_record_msg">录制提示</string>
|
||||
<string name="text_text_changed">文字改变</string>
|
||||
<string name="text_scrolled">滑动</string>
|
||||
@ -133,7 +132,6 @@
|
||||
<string name="text_do_not_ask_again_for_this_version">此版本不再提示</string>
|
||||
<string name="text_code_beautify">格式化代码</string>
|
||||
<string name="text_processing">处理中</string>
|
||||
<string name="text_already_reset">已重置</string>
|
||||
<string name="text_guard_mode">保护模式</string>
|
||||
<string name="summary_guard_mode">在本软件界面无法运行自动操作命令以免误触</string>
|
||||
<string name="key_guard_mode">key_guard_mode</string>
|
||||
@ -230,10 +228,7 @@
|
||||
<string name="text_refactor">重构</string>
|
||||
<string name="text_select_variable">选择变量</string>
|
||||
<string name="text_show_type">显示变量类型</string>
|
||||
<string name="text_close">关闭</string>
|
||||
<string name="text_adjust">调整</string>
|
||||
<string name="text_exit_floating_window">退出悬浮窗</string>
|
||||
<string name="text_save_and_edit">下载并编辑</string>
|
||||
<string name="text_select_save_path">保存到</string>
|
||||
<string name="text_cancel_download">取消下载</string>
|
||||
<string name="text_download">下载</string>
|
||||
@ -259,7 +254,6 @@
|
||||
<string name="apk_builder_clean">清理临时文件</string>
|
||||
<string name="text_source_file_path">脚本文件路径</string>
|
||||
<string name="text_search">搜索</string>
|
||||
<string name="text_floating_edit">悬浮编辑</string>
|
||||
<string name="text_select_icon">选择图标</string>
|
||||
<string name="text_use_android_n_shortcut">添加到安卓7.0 Shortcut</string>
|
||||
<string name="text_login_succeed">登录成功</string>
|
||||
@ -300,7 +294,6 @@
|
||||
<string name="text_using_text_selector">使用文本选择(text)</string>
|
||||
<string name="text_using_desc_selector">使用描述选择(desc)</string>
|
||||
<string name="text_generate">生成</string>
|
||||
<string name="text_generate_and_open_editor">生成并打开编辑器</string>
|
||||
<string name="text_generate_fail">生成失败了o(╥﹏╥)o</string>
|
||||
<string name="key_documentation_source">key_documentation_source</string>
|
||||
<string name="text_documentation_source">文档源</string>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user