Skip to content

Commit

Permalink
lastView 为空问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbinary committed Mar 27, 2016
1 parent 9a2b0f2 commit ba6b186
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {

defaultConfig {
applicationId "evilbinary.org.tvwidget"
minSdkVersion 19
targetSdkVersion 19
minSdkVersion 14
targetSdkVersion 14
versionCode 1
versionName "1.0"
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="org.evilbinary.tv">

<application
android:screenOrientation="sensor"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ protected void onCreate(Bundle savedInstanceState) {

GridView gridView = (GridView) findViewById(R.id.gridView);

gridView.getColumnWidth();
gridView.getVerticalSpacing();


MyGridViewAdapter myAdapter = new MyGridViewAdapter(R.layout.item_grid);
gridView.setAdapter(myAdapter);
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/border_shape_with_border.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="@color/greenyellow" android:width="4dp" android:dashWidth="4dp" android:dashGap="4dp"/>
<corners android:radius="4dp"/>
<solid android:color="#2287CEFA" />
</shape>
9 changes: 5 additions & 4 deletions app/src/main/res/layout/custom_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
android:layout_gravity="center"
android:layout_margin="12dp"
android:focusable="true"
android:background="@drawable/border_shape"
android:gravity="center">

android:background="@drawable/border_shape_with_border"
>

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_gravity="top"
android:focusable="false"
android:gravity="center"
android:text="自定义border样式"
android:textAlignment="center"
android:textColor="@color/white"
android:textColor="@color/coral"
android:textSize="20sp" />

</RelativeLayout>
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 19
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
Expand Down
12 changes: 7 additions & 5 deletions lib/src/main/java/org/evilbinary/tv/widget/BorderEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public void onFocusChanged(View oldFocus, View newFocus) {
}
};

private List<AdapterView.OnItemSelectedListener> onItemSelectedListenerList = new ArrayList<>();

public FocusListener absListViewFocusListener = new FocusListener() {
private List<AdapterView.OnItemSelectedListener> onItemSelectedListenerList = new ArrayList<>();
@Override
public void onFocusChanged(View oldFocus, View newFocus) {
for (View attachView : attacheViews) {
Expand All @@ -116,14 +116,16 @@ public void onFocusChanged(View oldFocus, View newFocus) {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
newFocus = view;

newFocus.bringToFront();

int w = view.getMeasuredWidth();
int h = view.getMeasuredHeight();
int ww = View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY);
int hh = View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY);
view.measure(ww,hh);
int ww = View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.AT_MOST);
int hh = View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.AT_MOST);
view.measure(ww, hh);

Log.d(TAG, "onItemSelected:" + newFocus.getMeasuredWidth()+" w:"+w );
ViewGroup vg= (ViewGroup) newFocus.getParent();
Log.d(TAG, "onItemSelected:" +vg.getWidth()+" "+ newFocus.getMeasuredWidth()+" w:"+w );


if (onItemSelectedListener != null) {
Expand Down
6 changes: 5 additions & 1 deletion lib/src/main/java/org/evilbinary/tv/widget/BorderView.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class BorderView<X extends View> implements ViewTreeObserver.OnGlobalFocu
private Effect borderEffect;

private X mView;
private View mLastView;

public interface Effect {
public void onFocusChanged(View target, View oldFocus, View newFocus);
Expand Down Expand Up @@ -93,9 +94,12 @@ public void onTouchModeChanged(boolean isInTouchMode) {

@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {

if(oldFocus==null){
oldFocus=mLastView;
}
if (borderEffect != null)
borderEffect.onFocusChanged(mView, oldFocus, newFocus);
mLastView=newFocus;

}

Expand Down

0 comments on commit ba6b186

Please sign in to comment.