parent
d353c4a579
commit
75cb7ec7fd
@ -1,199 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.micode.notes.ui;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import net.micode.notes.R;
|
||||
|
||||
/**
|
||||
* 布局设置对话框
|
||||
* <p>
|
||||
* 提供布局类型选择、网格列数和项目间距的配置界面。
|
||||
* 支持实时预览布局效果。
|
||||
* </p>
|
||||
*/
|
||||
public class LayoutSettingsDialog {
|
||||
private Context mContext;
|
||||
private LayoutManagerController mLayoutManagerController;
|
||||
private AlertDialog mDialog;
|
||||
private Spinner mLayoutTypeSpinner;
|
||||
private SeekBar mGridColumnsSeekBar;
|
||||
private SeekBar mItemSpacingSeekBar;
|
||||
private TextView mGridColumnsValue;
|
||||
private TextView mItemSpacingValue;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param context 上下文
|
||||
* @param layoutManagerController 布局管理器
|
||||
*/
|
||||
public LayoutSettingsDialog(Context context, LayoutManagerController layoutManagerController) {
|
||||
mContext = context;
|
||||
mLayoutManagerController = layoutManagerController;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示布局设置对话框
|
||||
*/
|
||||
public void show() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
builder.setTitle(R.string.layout_settings_title);
|
||||
|
||||
View dialogView = LayoutInflater.from(mContext).inflate(R.layout.layout_settings_dialog, null);
|
||||
builder.setView(dialogView);
|
||||
|
||||
initViews(dialogView);
|
||||
setupListeners();
|
||||
|
||||
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
saveSettings();
|
||||
}
|
||||
});
|
||||
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
|
||||
mDialog = builder.create();
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
* @param dialogView 对话框视图
|
||||
*/
|
||||
private void initViews(View dialogView) {
|
||||
mLayoutTypeSpinner = (Spinner) dialogView.findViewById(R.id.layout_type_spinner);
|
||||
mGridColumnsSeekBar = (SeekBar) dialogView.findViewById(R.id.grid_columns_seekbar);
|
||||
mItemSpacingSeekBar = (SeekBar) dialogView.findViewById(R.id.item_spacing_seekbar);
|
||||
mGridColumnsValue = (TextView) dialogView.findViewById(R.id.grid_columns_value);
|
||||
mItemSpacingValue = (TextView) dialogView.findViewById(R.id.item_spacing_value);
|
||||
|
||||
// 设置布局类型选项
|
||||
ArrayAdapter<LayoutType> layoutAdapter = new ArrayAdapter<>(
|
||||
mContext, android.R.layout.simple_spinner_item, LayoutType.values());
|
||||
mLayoutTypeSpinner.setAdapter(layoutAdapter);
|
||||
|
||||
// 设置当前值
|
||||
LayoutType currentLayout = mLayoutManagerController.getCurrentLayoutType();
|
||||
mLayoutTypeSpinner.setSelection(currentLayout.ordinal());
|
||||
|
||||
int gridColumns = mLayoutManagerController.getGridSpanCount();
|
||||
mGridColumnsSeekBar.setProgress(gridColumns - 1);
|
||||
mGridColumnsValue.setText(String.valueOf(gridColumns));
|
||||
|
||||
int itemSpacing = mLayoutManagerController.getItemSpacing();
|
||||
mItemSpacingSeekBar.setProgress(itemSpacing / 2);
|
||||
mItemSpacingValue.setText(String.valueOf(itemSpacing));
|
||||
|
||||
// 根据布局类型启用/禁用控件
|
||||
updateControlStates(currentLayout);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置监听器
|
||||
*/
|
||||
private void setupListeners() {
|
||||
mLayoutTypeSpinner.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
|
||||
LayoutType selectedLayout = (LayoutType) parent.getItemAtPosition(position);
|
||||
updateControlStates(selectedLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(android.widget.AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
mGridColumnsSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
int columns = progress + 1;
|
||||
mGridColumnsValue.setText(String.valueOf(columns));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
|
||||
mItemSpacingSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
int spacing = progress * 2;
|
||||
mItemSpacingValue.setText(String.valueOf(spacing));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新控件状态
|
||||
* @param layoutType 布局类型
|
||||
*/
|
||||
private void updateControlStates(LayoutType layoutType) {
|
||||
switch (layoutType) {
|
||||
case LINEAR:
|
||||
mGridColumnsSeekBar.setEnabled(false);
|
||||
mItemSpacingSeekBar.setEnabled(false);
|
||||
break;
|
||||
case GRID:
|
||||
case STAGGERED:
|
||||
mGridColumnsSeekBar.setEnabled(true);
|
||||
mItemSpacingSeekBar.setEnabled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存设置
|
||||
*/
|
||||
private void saveSettings() {
|
||||
LayoutType selectedLayout = (LayoutType) mLayoutTypeSpinner.getSelectedItem();
|
||||
int gridColumns = mGridColumnsSeekBar.getProgress() + 1;
|
||||
int itemSpacing = mItemSpacingSeekBar.getProgress() * 2;
|
||||
|
||||
mLayoutManagerController.setGridSpanCount(gridColumns);
|
||||
mLayoutManagerController.setItemSpacing(itemSpacing);
|
||||
|
||||
if (selectedLayout != mLayoutManagerController.getCurrentLayoutType()) {
|
||||
mLayoutManagerController.switchLayout(selectedLayout, true);
|
||||
}
|
||||
|
||||
mDialog.dismiss();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<size android:height="1dp" />
|
||||
<solid android:color="#E0E0E0" />
|
||||
</shape>
|
||||
@ -1,19 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<!-- 主内容区域 -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/main_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<!-- 侧栏 -->
|
||||
<fragment
|
||||
android:id="@+id/sidebar_fragment"
|
||||
android:name="net.micode.notes.ui.SidebarFragment"
|
||||
android:layout_width="280dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:tag="sidebar" />
|
||||
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
@ -1,103 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/layout_linear"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="16dp" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/layout_type_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/layout_grid_columns"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginEnd="16dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/grid_columns_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="2"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:minWidth="30dp"
|
||||
android:gravity="center" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/grid_columns_seekbar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:max="3"
|
||||
android:progress="1" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/layout_item_spacing"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginEnd="16dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_spacing_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="16"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:minWidth="30dp"
|
||||
android:gravity="center" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/item_spacing_seekbar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:max="24"
|
||||
android:progress="8" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
Loading…
Reference in new issue