-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from CaptainHuangsh/13-setting-sum-ui
13 setting sum ui
- Loading branch information
Showing
14 changed files
with
251 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
app/src/main/java/com/example/owenh/alarmo/adapter/ColorAdapter.java
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
app/src/main/java/com/example/owenh/alarmo/adapter/ColorListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.