Compare commits
19 Commits
Author | SHA1 | Date |
---|---|---|
qc | d2772ee560 | 1 year ago |
qc | 400c6a4b60 | 1 year ago |
qc | 69ba695361 | 1 year ago |
qc | ecef8e71a7 | 1 year ago |
qc | c50ea20511 | 1 year ago |
qc | d0b6199575 | 2 years ago |
qc | 01051f865c | 2 years ago |
qc | 3b94bf9412 | 2 years ago |
qc | 883f4573cc | 2 years ago |
pta4rcy27 | ae2dfb5c3e | 2 years ago |
qc | 7de90ce525 | 2 years ago |
qc | 3b74da9d9d | 2 years ago |
qc | bf14fc1f8c | 2 years ago |
qc | 82ec6bd612 | 2 years ago |
qc | 0ca3b02b63 | 2 years ago |
qc | 259ad381ac | 2 years ago |
qc | de17a897d1 | 2 years ago |
qc | cf12a2e6e0 | 2 years ago |
qc | 91a7b1b13f | 2 years ago |
After Width: | Height: | Size: 63 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 9.3 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 55 KiB |
@ -0,0 +1,161 @@
|
||||
package net.micode.notes.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import net.micode.notes.R;
|
||||
import net.micode.notes.model.SkinInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 换肤功能实现
|
||||
*/
|
||||
public class SkinActivity extends Activity {
|
||||
private SharedPreferences mSharedPreferences;
|
||||
private SkinListAdapter mListAdapter;
|
||||
private GridView gridView;
|
||||
private List<SkinInfo> mSkinInfoList = new ArrayList<>();
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_skin);
|
||||
gridView = (GridView) findViewById(R.id.gridView);
|
||||
mSharedPreferences = getSharedPreferences("skin_info", MODE_PRIVATE);
|
||||
|
||||
|
||||
|
||||
//定义皮肤
|
||||
mSkinInfoList.add(new SkinInfo(0, getResources().getColor(R.color.color_4963F4)));
|
||||
mSkinInfoList.add(new SkinInfo(0, getResources().getColor( R.color.color_3372e4)));
|
||||
mSkinInfoList.add(new SkinInfo(0, getResources().getColor(R.color.color_673AB7)));
|
||||
mSkinInfoList.add(new SkinInfo(0, getResources().getColor( R.color.color_4CAF50)));
|
||||
mSkinInfoList.add(new SkinInfo(0, getResources().getColor(R.color.color_00BCD4)));
|
||||
mSkinInfoList.add(new SkinInfo(0, getResources().getColor( R.color.color_9C27B0)));
|
||||
mSkinInfoList.add(new SkinInfo(0, getResources().getColor( R.color.color_3F51B5)));
|
||||
mSkinInfoList.add(new SkinInfo(0, getResources().getColor(R.color.color_009688)));
|
||||
mSkinInfoList.add(new SkinInfo(0, getResources().getColor(R.color.color_FF9800)));
|
||||
|
||||
|
||||
|
||||
//初始化适配器
|
||||
mListAdapter =new SkinListAdapter(SkinActivity.this);
|
||||
|
||||
//设置adapter
|
||||
gridView.setAdapter(mListAdapter);
|
||||
|
||||
//设置数据
|
||||
mListAdapter.setList(mSkinInfoList);
|
||||
|
||||
|
||||
//选中
|
||||
int current_position = mSharedPreferences.getInt("current_position", 0);
|
||||
if (current_position != 0) {
|
||||
mListAdapter.setCurrentIndex(current_position);
|
||||
}
|
||||
|
||||
|
||||
//点击事件处理选中的颜色
|
||||
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, final int position, long l) {
|
||||
final SkinInfo skinInfo = (SkinInfo) gridView.getAdapter().getItem(position);
|
||||
mListAdapter.setCurrentIndex(position);
|
||||
AlertDialog.Builder builder =new AlertDialog.Builder(SkinActivity.this);
|
||||
builder.setTitle("操作");
|
||||
builder.setMessage("确定一键换肤吗?");
|
||||
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
//实现换肤
|
||||
SharedPreferences.Editor edit = mSharedPreferences.edit();
|
||||
edit.putInt("skin_mode", skinInfo.getColorId());
|
||||
edit.putInt("current_position", position);
|
||||
edit.commit();
|
||||
setResult(2000);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
builder.show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class SkinListAdapter extends BaseAdapter{
|
||||
|
||||
private int currentIndex = 0;
|
||||
private List<SkinInfo> mSkinInfoList=new ArrayList<>();
|
||||
private LayoutInflater mLayoutInflater;
|
||||
public SkinListAdapter(Context context){
|
||||
mLayoutInflater =LayoutInflater.from(context);
|
||||
|
||||
}
|
||||
|
||||
public void setList(List<SkinInfo> list){
|
||||
this.mSkinInfoList =list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mSkinInfoList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkinInfo getItem(int i) {
|
||||
return mSkinInfoList.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
view =mLayoutInflater.inflate(R.layout.skin_list_item,viewGroup,false);
|
||||
RelativeLayout checkbox = (RelativeLayout) view.findViewById(R.id.checkbox);
|
||||
View color_line =view.findViewById(R.id.color_line);
|
||||
SkinInfo item = getItem(i);
|
||||
color_line.setBackgroundColor(item.getColorId());
|
||||
|
||||
if (currentIndex ==i){
|
||||
checkbox.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
checkbox.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void setCurrentIndex(int position) {
|
||||
this.currentIndex = position;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|