Skip to content

Commit

Permalink
icon list item click now leads to icon features activity (sample)
Browse files Browse the repository at this point in the history
  • Loading branch information
atermenji committed Apr 8, 2013
1 parent 9c38c38 commit 75552e2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
Expand All @@ -24,14 +26,25 @@ public class SimpleSampleActivity extends Activity {
private static final int ICON_PADDING_MAX = 500;
private static final int ICON_CONTOUR_WIDTH = 10;

private View mIconButton;
private static final String EXTRA_ICON = "extra_icon";

private View mIconView;
private Spinner mIconsSpinner;
private SeekBar mPaddingSeekBar;
private Button mChangeColorButton;
private TextView mCurPaddingTextView;
private CheckBox mDrawContourCheckBox;

private IconicFontDrawable mIconicFontDrawable;
private Icon mIcon;

private boolean firstSelect;

public static Intent createIntent(final Context context, final Icon icon) {
Intent intent = new Intent(context, SimpleSampleActivity.class);
intent.putExtra(EXTRA_ICON, icon);
return intent;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -40,42 +53,56 @@ protected void onCreate(Bundle savedInstanceState) {
setTitle("Simple Sample");
setContentView(R.layout.activity_simple_sample);

mIconButton = findViewById(R.id.view_icon);
mIconView = findViewById(R.id.view_icon);
mIconsSpinner = (Spinner) findViewById(R.id.sp_icons);
mPaddingSeekBar = (SeekBar) findViewById(R.id.sb_size);
mChangeColorButton = (Button) findViewById(R.id.bt_change_color);
mCurPaddingTextView = (TextView) findViewById(R.id.tv_size);
mDrawContourCheckBox = (CheckBox) findViewById(R.id.cb_draw_stroke);

Bundle extras = getIntent().getExtras();
if (extras != null) {
mIcon = (Icon) extras.getSerializable(EXTRA_ICON);
}

initSimpleSample();
}

private void initSimpleSample() {
mIconicFontDrawable = new IconicFontDrawable(this);
mIconButton.setBackground(mIconicFontDrawable);
mIconView.setBackground(mIconicFontDrawable);

if (mIcon != null) {
mIconicFontDrawable.setIcon(mIcon);
firstSelect = true;
}

List<Icon> icons = new ArrayList<Icon>();
icons.addAll(Arrays.asList(EntypoIcon.values()));
icons.addAll(Arrays.asList(EntypoSocialIcon.values()));
icons.addAll(Arrays.asList(FontAwesomeIcon.values()));
icons.addAll(Arrays.asList(IconicIcon.values()));
final ArrayAdapter<Icon> adapter =

final ArrayAdapter<Icon> adapter =
new ArrayAdapter<Icon>(this, android.R.layout.simple_spinner_item, icons);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mIconsSpinner.setAdapter(adapter);

mIconsSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Icon icon = adapter.getItem(pos);
mIconicFontDrawable.setIcon(icon);
if (!firstSelect) {
Icon icon = adapter.getItem(pos);
mIconicFontDrawable.setIcon(icon);
} else {
firstSelect = false;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});

mIconicFontDrawable.setIconColor(Utils.randomColor());

mCurPaddingTextView.setText("Padding: " + 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.atermenji.android.iconictextview.IconicFontDrawable;
Expand All @@ -30,7 +31,9 @@ public class TypefaceSampleActivity extends ListActivity {
public static final int ICON_TYPE_ENTYPO_SOCIAL = 1002;
public static final int ICON_TYPE_FONT_AWESOME = 1003;
public static final int ICON_TYPE_ICONIC = 1004;


private SampleIconsAdapter mAdapter;

public static Intent createIntent(final Context context, final int iconType) {
Intent intent = new Intent(context, TypefaceSampleActivity.class);
intent.putExtra(EXTRA_ICON_TYPE, iconType);
Expand All @@ -45,6 +48,13 @@ protected void onCreate(Bundle savedInstanceState) {
initIconsList(iconType);
}

@Override
protected void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
Icon icon = (Icon) listView.getAdapter().getItem(position);
startActivity(SimpleSampleActivity.createIntent(this, icon));
}

private void initIconsList(int iconType) {
List<Icon> values = new ArrayList<Icon>();
Icon[] valuesArray = null;
Expand Down Expand Up @@ -74,8 +84,8 @@ private void initIconsList(int iconType) {

values.addAll(Arrays.asList(valuesArray));

SampleIconsAdapter adapter = new SampleIconsAdapter(this, values);
getListView().setAdapter(adapter);
mAdapter = new SampleIconsAdapter(this, values);
getListView().setAdapter(mAdapter);
}

private class SampleIconsAdapter extends ArrayAdapter<Icon> {
Expand Down

0 comments on commit 75552e2

Please sign in to comment.