forked from FlyingRadish/Leamonax
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sort note by UpdateTime,CreateTime, Title
- Loading branch information
Showing
10 changed files
with
307 additions
and
2 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
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
115 changes: 115 additions & 0 deletions
115
app/src/main/java/org/houxg/leamonax/widget/SelectPopupWindow.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,115 @@ | ||
package org.houxg.leamonax.widget; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.support.v7.widget.ListPopupWindow; | ||
import android.view.Gravity; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.AdapterView; | ||
import android.widget.BaseAdapter; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import org.houxg.leamonax.R; | ||
import org.houxg.leamonax.utils.DisplayUtils; | ||
import org.houxg.leamonax.utils.SharedPreferenceUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class SelectPopupWindow extends ListPopupWindow { | ||
public static final String SP_SORT_TYPE = "sp_sort_type"; | ||
private Context mContext; | ||
private OnItemClickListener mOnItemClickListener; | ||
private Adapter mAdapter; | ||
private int mChecked = -1; | ||
|
||
public void setOnItemClickListener(OnItemClickListener onItemClickListener) { | ||
this.mOnItemClickListener = onItemClickListener; | ||
} | ||
|
||
public SelectPopupWindow(Context context) { | ||
super(context); | ||
this.mContext = context; | ||
} | ||
|
||
@SuppressLint("RestrictedApi") | ||
public void showPopWindow(View anchorView) { | ||
String[] selectKey = mContext.getResources().getStringArray(R.array.select_key); | ||
final String[] selectValue = mContext.getResources().getStringArray(R.array.select_value); | ||
mAdapter = new Adapter(); | ||
mAdapter.setDatas(new ArrayList<>(Arrays.asList(selectKey))); | ||
mChecked = SharedPreferenceUtils.read(SharedPreferenceUtils.CONFIG, SP_SORT_TYPE, mChecked); | ||
mAdapter.setChecked(mChecked); | ||
setAdapter(mAdapter); | ||
setWidth(DisplayUtils.dp2px(180)); | ||
setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | ||
setDropDownGravity(Gravity.END); | ||
setAnchorView(anchorView); | ||
setOverlapAnchor(true); | ||
setModal(true); | ||
setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | ||
int value = Integer.valueOf(selectValue[position]); | ||
SharedPreferenceUtils.write(SharedPreferenceUtils.CONFIG, SP_SORT_TYPE, value); | ||
if (mOnItemClickListener != null) { | ||
mOnItemClickListener.onItemClick(parent, view, value); | ||
} | ||
} | ||
}); | ||
show(); | ||
} | ||
|
||
class Adapter extends BaseAdapter { | ||
List<String> datas = new ArrayList<>(); | ||
private int checked = -1; | ||
|
||
void setDatas(List<String> datas) { | ||
this.datas = datas; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return datas.size(); | ||
} | ||
|
||
@Override | ||
public String getItem(int position) { | ||
return datas.get(position); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return position; | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
if (convertView == null) { | ||
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.simple_list_item_1, parent, false); | ||
} | ||
ImageView checkView = convertView.findViewById(R.id.check); | ||
TextView textView = convertView.findViewById(android.R.id.text1); | ||
if (checked == (position + 1)) { | ||
checkView.setVisibility(View.VISIBLE); | ||
} else { | ||
checkView.setVisibility(View.INVISIBLE); | ||
} | ||
textView.setText(getItem(position)); | ||
return convertView; | ||
} | ||
|
||
public void setChecked(int checked) { | ||
this.checked = checked; | ||
} | ||
} | ||
|
||
public interface OnItemClickListener { | ||
void onItemClick(AdapterView<?> parent, View view, int value); | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
|
||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
|
||
<ImageView | ||
android:id="@+id/check" | ||
android:layout_width="36dp" | ||
android:scaleType="center" | ||
android:src="@drawable/ic_pop_checked" | ||
android:layout_height="match_parent" /> | ||
|
||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@android:id/text1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical" | ||
android:minHeight="36dp" | ||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" | ||
android:textAppearance="?android:attr/textAppearanceListItemSmall" /> | ||
|
||
</LinearLayout> | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string-array name="select_key"> | ||
<item>按创建时间-升序</item> | ||
<item>按创建时间-降序</item> | ||
<item>按更新时间-升序</item> | ||
<item>按更新时间-降序</item> | ||
<item>按标题-升序</item> | ||
<item>按标题-降序</item> | ||
</string-array> | ||
|
||
<string-array name="select_value"> | ||
<item>1</item> | ||
<item>2</item> | ||
<item>3</item> | ||
<item>4</item> | ||
<item>5</item> | ||
<item>6</item> | ||
</string-array> | ||
</resources> |
Oops, something went wrong.