Skip to content

Commit

Permalink
Merge pull request #33 from CaptainHuangsh/13-setting-sum-ui
Browse files Browse the repository at this point in the history
13 setting sum ui
  • Loading branch information
CaptainHuangsh authored May 14, 2017
2 parents 235b5e6 + 4a9e1e7 commit 8c8879c
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 115 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "com.example.owenh.alarmo"
minSdkVersion 15
targetSdkVersion 23
versionCode 2
versionName "1.0.09.20170504beta"
versionCode 3
versionName "1.1.01.20170513"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
19 changes: 3 additions & 16 deletions app/src/main/java/com/example/owenh/alarmo/activity/AlarmMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Switch;
import android.widget.Toast;

import com.example.owenh.alarmo.R;
import com.example.owenh.alarmo.services.RingService;
Expand All @@ -29,13 +30,11 @@ public class AlarmMain extends AppCompatActivity implements
private Switch mSwitch;
private int isChecked = 0;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alram_main);
setTitle("Alarmo");
// VibrateUtil.vibrate(AlarmMain.this,100);
init();
findView();
setListener();
Expand Down Expand Up @@ -97,29 +96,17 @@ public void onClick(View view) {
case R.id.on_off_service2:
Intent serviceIntent = new Intent(AlarmMain.this, RingService.class);
if (isChecked == 0) {
Log.i("huangshaohuaSwitch", "on");
startService(serviceIntent);
Toast.makeText(AlarmMain.this,"打开整点报时",Toast.LENGTH_SHORT).show();
isChecked++;
} else {
Log.i("huangshaohuaSwitch", "off");
stopService(serviceIntent);
Toast.makeText(AlarmMain.this,"关闭整点报时",Toast.LENGTH_SHORT).show();
isChecked = 0;
}
break;
default:
break;
}
}


/**
* 获取系统铃声
*/
private Uri getSystemDefultRingtoneUri() {

return RingtoneManager.getActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_NOTIFICATION);
}


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.example.owenh.alarmo.adapter;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.example.owenh.alarmo.R;
import com.example.owenh.alarmo.domain.AColor;

import java.util.HashMap;
import java.util.List;

/**
* Created by owen on 2017/5/10.
*/

public class ColorListAdapter extends ArrayAdapter<AColor> {

private int resourceId;
HashMap<String, Boolean> states = new HashMap<String, Boolean>();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());

public ColorListAdapter(Context context, int resourceId, List<AColor> colors) {
super(context, resourceId, colors);
this.resourceId = resourceId;
}

@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
AColor color = getItem(position);
View view;
ViewHolder viewHolder;
if (convertView == null) {
view = LayoutInflater.from(getContext()).inflate(resourceId, null);
viewHolder = new ViewHolder();
viewHolder.colorImg = (ImageView) view.findViewById(R.id.items_take_color_value);
viewHolder.colorText = (TextView) view.findViewById(R.id.item_take_color_string);
view.setTag(viewHolder);//将viewHolder存储在view中
} else {
view = convertView;
viewHolder = (ViewHolder) view.getTag();//重新获取viewHolder
}
final RadioButton radio=(RadioButton) view.findViewById(R.id.color_radio);
final SharedPreferences finalPreferences = preferences;
viewHolder.rb_state = radio;
viewHolder.rb_state.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finalPreferences.edit().putString("pref_text_color", getItem(position).getColorValue()).apply();
// 重置,确保最多只有一项被选中
for (String key : states.keySet()) {
states.put(key, false);
}
states.put(String.valueOf(position), radio.isChecked());
ColorListAdapter.this.notifyDataSetChanged();
}
});

boolean res = false;
if (states.get(String.valueOf(position)) == null
|| states.get(String.valueOf(position)) == false) {
res = false;
states.put(String.valueOf(position), false);
} else
res = true;

viewHolder.rb_state.setChecked(res);

viewHolder.colorImg.setBackgroundColor(Color.parseColor(color.getColorValue()));
viewHolder.colorText.setText(color.getColorString());
return view;
}

class ViewHolder {
ImageView colorImg;
TextView colorText;
RadioButton rb_state;
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/example/owenh/alarmo/common/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

public class C {
public static HashMap<String, String> colorMap = new HashMap<String
, String>() {
{
public static HashMap<String, String> colorMap = new HashMap<>();

static {
colorMap.put("#0000FF", "蓝色");
colorMap.put("#008000", "绿色");
colorMap.put("#008B8B","暗青色");
Expand All @@ -25,6 +25,6 @@ public class C {
colorMap.put("#FFFF00", "黄色");
colorMap.put("", "请选择要显示的颜色");
}
};


}
65 changes: 56 additions & 9 deletions app/src/main/java/com/example/owenh/alarmo/dialog/ColorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.owenh.alarmo.R;
import com.example.owenh.alarmo.adapter.ColorAdapter;
import com.example.owenh.alarmo.common.C;
import com.example.owenh.alarmo.adapter.ColorListAdapter;
import com.example.owenh.alarmo.domain.AColor;

import java.util.ArrayList;
Expand All @@ -30,9 +26,11 @@
public class ColorDialog extends Dialog {

private Context mContext;

public ListView listView;
private Button yes, no;
private List<AColor> colors = new ArrayList<AColor>();
private onNoOnclickListener noOnclickListener;//取消按钮被点击了的监听器
private onYesOnclickListener yesOnclickListener;//确定按钮被点击了的监听器

public ColorDialog(@NonNull Context context) {
super(context);
Expand All @@ -44,21 +42,53 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_take_color);
initColor();
initView();
initEvent();
PreferenceManager.setDefaultValues(getContext(), R.xml.pref_settings, false);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
ColorAdapter mAdapter = new ColorAdapter(getContext(), R.layout.items_take_color, colors);
ListView listView = (ListView) findViewById(R.id.main_color_list);
ColorListAdapter mAdapter = new ColorListAdapter(getContext(), R.layout.items_take_color, colors);
listView = (ListView) findViewById(R.id.main_color_list);
listView.setAdapter(mAdapter);
final SharedPreferences finalPreferences = preferences;
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
/*listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
finalPreferences.edit().putString("pref_text_color", colors.get(position).getColorValue()).apply();
dismiss();
}
});*/
}

/**
* 初始化界面的确定和取消监听器
*/
private void initEvent() {
//设置确定按钮被点击后,向外界提供监听
yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (yesOnclickListener != null) {
yesOnclickListener.onYesClick();
}
}
});
//设置取消按钮被点击后,向外界提供监听
no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (noOnclickListener != null) {
noOnclickListener.onNoClick();
}
}
});
}

private void initView() {
yes = (Button) findViewById(R.id.yes);
no = (Button) findViewById(R.id.no);
}


//设置中的内置颜色选项
private void initColor() {
//http://blog.csdn.net/u013058160/article/details/49158779
Expand Down Expand Up @@ -91,4 +121,21 @@ private void initColor() {


}

public void setYesOnclickListener(onYesOnclickListener onYesOnclickListener) {
this.yesOnclickListener = onYesOnclickListener;
}

public void setNoOnclickListener(onNoOnclickListener onNoOnclickListener) {
this.noOnclickListener = onNoOnclickListener;
}


public interface onYesOnclickListener {
public void onYesClick();
}

public interface onNoOnclickListener {
public void onNoClick();
}
}
Loading

0 comments on commit 8c8879c

Please sign in to comment.