-
Notifications
You must be signed in to change notification settings - Fork 98
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 #5 from nipuns/master
Spinner
- Loading branch information
Showing
10 changed files
with
133 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
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
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
63 changes: 63 additions & 0 deletions
63
library/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.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,63 @@ | ||
package com.vijay.jsonwizard.widgets; | ||
|
||
import android.content.Context; | ||
import android.text.TextUtils; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.AdapterView; | ||
import android.widget.ArrayAdapter; | ||
|
||
import com.rengwuxian.materialedittext.MaterialEditText; | ||
import com.rey.material.util.ViewUtil; | ||
import com.vijay.jsonwizard.R; | ||
import com.vijay.jsonwizard.customviews.GenericTextWatcher; | ||
import com.vijay.jsonwizard.interfaces.CommonListener; | ||
import com.vijay.jsonwizard.interfaces.FormWidgetFactory; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import fr.ganfra.materialspinner.MaterialSpinner; | ||
|
||
/** | ||
* Created by nipun on 30/05/15. | ||
*/ | ||
public class SpinnerFactory implements FormWidgetFactory { | ||
|
||
@Override | ||
public List<View> getViewsFromJson(String stepName, Context context, JSONObject jsonObject, CommonListener listener) throws Exception { | ||
List<View> views = new ArrayList<>(1); | ||
MaterialSpinner spinner = (MaterialSpinner) LayoutInflater.from(context).inflate(R.layout.item_spinner, null); | ||
|
||
String hint = jsonObject.optString("hint"); | ||
if (!TextUtils.isEmpty(hint)) { | ||
spinner.setHint(jsonObject.getString("hint")); | ||
spinner.setFloatingLabelText(jsonObject.getString("hint")); | ||
} | ||
|
||
spinner.setId(ViewUtil.generateViewId()); | ||
|
||
spinner.setTag(R.id.key, jsonObject.getString("key")); | ||
spinner.setTag(R.id.type, jsonObject.getString("type")); | ||
|
||
JSONArray valuesJson = jsonObject.optJSONArray("values"); | ||
String[] values = null; | ||
if (valuesJson != null && valuesJson.length() > 0) { | ||
values = new String[valuesJson.length()]; | ||
for (int i = 0; i < valuesJson.length(); i++) { | ||
values[i] = valuesJson.optString(i); | ||
} | ||
} | ||
|
||
if (values != null) { | ||
spinner.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, values)); | ||
} | ||
|
||
spinner.setOnItemSelectedListener(listener); | ||
views.add(spinner); | ||
return views; | ||
} | ||
} |
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,12 @@ | ||
<fr.ganfra.materialspinner.MaterialSpinner | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
app:ms_multiline="false" | ||
app:ms_typeface="font/Roboto-Regular.ttf" | ||
app:ms_arrowColor="?colorPrimaryDark" | ||
app:ms_arrowSize="16dp" | ||
app:ms_alignLabels="true" | ||
app:ms_floatingLabelColor="@color/secondary_text" | ||
/> |
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