Skip to content

Choice mode #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# svn
*.svn*

# built application files
*.apk
*.ap_
Expand All @@ -8,9 +11,29 @@
# Java class files
*.class

# generated files
bin/
gen/
# generated GUI files
*/R.java

# generated folder
bin
gen

# Local configuration file (sdk path, etc)
# local
local.properties
proguard.cfg

# log files
log*.txt

# archives
*.gz
*.tar
*.zip

# eclipse
*.metadata
*.settings

#idea
*.idea
*.iml
7 changes: 7 additions & 0 deletions Demo/res/drawable/bg_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bg_item_activated" android:state_checked="true"/>
<item android:drawable="@drawable/bg_item_activated" android:state_activated="true"/>
<item android:drawable="@drawable/bg_item_normal"/>
</selector>
7 changes: 7 additions & 0 deletions Demo/res/drawable/bg_item_activated.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"
android:shape="rectangle">
<solid android:color="@android:color/black"/>
</shape>
7 changes: 7 additions & 0 deletions Demo/res/drawable/bg_item_normal.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"
android:shape="rectangle">
<solid android:color="@android:color/white"/>
</shape>
10 changes: 4 additions & 6 deletions Demo/res/layout/view1.xml → Demo/res/layout/list_item.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<it.sephiroth.android.sample.horizontalvariablelistviewdemo.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="true"
android:gravity="center_horizontal|bottom"
android:padding="10dip"
android:background="@drawable/bg_item"
android:orientation="vertical" >

<ImageView
s <ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/text"
android:layout_centerHorizontal="true"
android:clickable="true"
android:src="@drawable/image"
android:scaleType="centerInside" />

Expand All @@ -25,7 +24,6 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:clickable="true"
android:text="@android:string/ok" />

</RelativeLayout>
</it.sephiroth.android.sample.horizontalvariablelistviewdemo.CheckableLinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package it.sephiroth.android.sample.horizontalvariablelistviewdemo;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Checkable;
import android.widget.LinearLayout;

/**
* Copyright /(c/) 2013 Quotient Solutions. All rights reserved.
*/
public class CheckableLinearLayout extends LinearLayout implements Checkable {

private boolean isChecked;

public CheckableLinearLayout(Context context) {
super(context);
}

public CheckableLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

public CheckableLinearLayout(Context context, AttributeSet attrs, int defStyleRes) {
super(context, attrs, defStyleRes);
}

@Override
public void setChecked(boolean checked) {
isChecked = checked;
refreshDrawableState();
}

@Override
public boolean isChecked() {
return isChecked;
}

@Override
public void toggle() {
setChecked(!isChecked);
}

private static final int[] CHECKED_STATE_SET = {
android.R.attr.state_checked,
};


@Override
protected int[] onCreateDrawableState(int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked()) {
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
}
return drawableState;
}

@Override
public boolean performClick() {
toggle();
return super.performClick();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package it.sephiroth.android.sample.horizontalvariablelistviewdemo;

import it.sephiroth.android.library.widget.HorizontalVariableListView;
import it.sephiroth.android.library.widget.HorizontalVariableListView.OnLayoutChangeListener;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.view.*;
import android.widget.*;
import it.sephiroth.android.library.widget.HorizontalVariableListView;
import it.sephiroth.android.library.widget.HorizontalVariableListView.OnLayoutChangeListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {

Expand All @@ -32,10 +28,18 @@ public void onCreate( Bundle savedInstanceState ) {
data.add( String.valueOf( i ) );
}

ListAdapter adapter = new ListAdapter( this, R.layout.view1, R.layout.divider, data );
ListAdapter adapter = new ListAdapter( this, R.layout.list_item, R.layout.divider, data );
mList.setOverScrollMode( View.OVER_SCROLL_ALWAYS );
mList.setEdgeGravityY( Gravity.BOTTOM );
mList.setAdapter( adapter );
mList.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
mList.setItemChecked(3, true);
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "Clicked on # "+String.valueOf(position), Toast.LENGTH_SHORT).show();
}
});

}

Expand Down
Loading