-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vikramjeet Singh
authored and
Vikramjeet Singh
committed
Feb 13, 2015
1 parent
adad6cc
commit dc2bc85
Showing
2 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
173 changes: 173 additions & 0 deletions
173
app/src/main/java/com/example/vikramjeet/fragments/SettingsFilterDialog.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,173 @@ | ||
package com.example.vikramjeet.fragments; | ||
|
||
import android.app.Dialog; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.app.DialogFragment; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.Window; | ||
import android.widget.AdapterView; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Spinner; | ||
import android.widget.TextView; | ||
|
||
import com.example.vikramjeet.gridimagesearch.R; | ||
import com.example.vikramjeet.models.Filter; | ||
|
||
/** | ||
* A simple {@link Fragment} subclass. | ||
* Activities that contain this fragment must implement the | ||
* {@link SettingsFilterDialog.OnFragmentInteractionListener} interface | ||
* to handle interaction events. | ||
* Use the {@link SettingsFilterDialog#newInstance} factory method to | ||
* create an instance of this fragment. | ||
*/ | ||
public class SettingsFilterDialog extends DialogFragment implements TextView.OnClickListener { | ||
|
||
private String imageSize; | ||
private String imageColor; | ||
private String imageType; | ||
private EditText etSiteFilter; | ||
private Button saveButton; | ||
private Button cancelButton; | ||
|
||
|
||
public interface SettingsFilterDialogListener { | ||
void onFinishFilterDialog(Filter filter); | ||
} | ||
|
||
public static SettingsFilterDialog newInstance(String title) { | ||
SettingsFilterDialog frag = new SettingsFilterDialog(); | ||
Bundle args = new Bundle(); | ||
args.putString("title", title); | ||
frag.setArguments(args); | ||
return frag; | ||
} | ||
|
||
public SettingsFilterDialog() { | ||
// Required empty public constructor | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
Dialog dialog = super.onCreateDialog(savedInstanceState); | ||
|
||
// request a window without the title | ||
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); | ||
return dialog; | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
// Inflate the layout for this fragment | ||
View view = inflater.inflate(R.layout.fragment_settings_filter_dialog, container); | ||
|
||
etSiteFilter = (EditText) view.findViewById(R.id.etSiteFilter); | ||
|
||
saveButton = (Button) view.findViewById(R.id.btnSave); | ||
saveButton.setOnClickListener(this); | ||
|
||
cancelButton = (Button) view.findViewById(R.id.btnCancel); | ||
cancelButton.setOnClickListener(this); | ||
|
||
|
||
// String title = getArguments().getString("title"); | ||
// getDialog().setTitle("title"); | ||
|
||
// Load spinner view | ||
Spinner spinnerImageSize = (Spinner) view.findViewById(R.id.spinnerImageSize); | ||
// Create an ArrayAdapter using the string array using custom spinner layout | ||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), | ||
R.array.image_size_array, R.layout.custom_spinner_item); | ||
// Specify the layout to use when the list of choices appears | ||
adapter.setDropDownViewResource(R.layout.custom_spinner_item); | ||
// Apply the adapter to the spinner | ||
spinnerImageSize.setAdapter(adapter); | ||
|
||
spinnerImageSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | ||
@Override | ||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | ||
if (position > 0) { | ||
imageSize = (String) parent.getItemAtPosition(position); | ||
} | ||
} | ||
|
||
@Override | ||
public void onNothingSelected(AdapterView<?> parent) { | ||
|
||
} | ||
}); | ||
|
||
|
||
// Load spinner view | ||
Spinner spinnerColorFilter = (Spinner) view.findViewById(R.id.spinnerColorFilter); | ||
// Create an ArrayAdapter using the string array using custom spinner layout | ||
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(getActivity(), | ||
R.array.image_color_array, R.layout.custom_spinner_item); | ||
// Specify the layout to use when the list of choices appears | ||
adapter.setDropDownViewResource(R.layout.custom_spinner_item); | ||
// Apply the adapter to the spinner | ||
spinnerColorFilter.setAdapter(adapter2); | ||
|
||
spinnerColorFilter.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | ||
@Override | ||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | ||
if (position > 0) { | ||
imageColor = (String) parent.getItemAtPosition(position); | ||
} | ||
} | ||
|
||
@Override | ||
public void onNothingSelected(AdapterView<?> parent) { | ||
|
||
} | ||
}); | ||
|
||
// Load spinner view | ||
Spinner spinnerImageType = (Spinner) view.findViewById(R.id.spinnerImageType); | ||
// Create an ArrayAdapter using the string array using custom spinner layout | ||
ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(getActivity(), | ||
R.array.image_type_array, R.layout.custom_spinner_item); | ||
// Specify the layout to use when the list of choices appears | ||
adapter.setDropDownViewResource(R.layout.custom_spinner_item); | ||
// Apply the adapter to the spinner | ||
spinnerImageType.setAdapter(adapter3); | ||
|
||
spinnerImageSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | ||
@Override | ||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | ||
if (position > 0) { | ||
imageType = (String) parent.getItemAtPosition(position); | ||
} | ||
} | ||
|
||
@Override | ||
public void onNothingSelected(AdapterView<?> parent) { | ||
|
||
} | ||
}); | ||
|
||
return view; | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
if(v == saveButton) { | ||
String siteFilter = etSiteFilter.getText().toString(); | ||
// Create Filter object | ||
Filter filter = new Filter(imageSize, imageColor, imageType, siteFilter); | ||
|
||
// Return Filter to activity | ||
SettingsFilterDialogListener listener = (SettingsFilterDialogListener) getActivity(); | ||
listener.onFinishFilterDialog(filter); | ||
} | ||
dismiss(); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
app/src/main/res/layout/fragment_settings_filter_dialog.xml
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,128 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingBottom="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
tools:context="com.example.vikramjeet.activities.SettingsActivity"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Advanced Filters" | ||
android:id="@+id/tvAdvancedFilters" | ||
android:textStyle="bold" | ||
android:textSize="18dp" | ||
android:layout_alignParentTop="true" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:textColor="#ff000000" | ||
android:gravity="top" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Image Size" | ||
android:id="@+id/tvImageSize" | ||
android:layout_below="@+id/tvAdvancedFilters" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_marginTop="20dp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Color Filter" | ||
android:id="@+id/tvColorFilter" | ||
android:layout_below="@+id/tvImageSize" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_marginTop="20dp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Image Type" | ||
android:id="@+id/tvImageType" | ||
android:layout_below="@+id/tvColorFilter" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_marginTop="20dp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Site filter" | ||
android:id="@+id/tvSiteFilter" | ||
android:layout_below="@+id/tvImageType" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_marginTop="40dp" /> | ||
|
||
<Spinner | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/spinnerImageSize" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentEnd="true" | ||
android:layout_toEndOf="@+id/tvAdvancedFilters" | ||
android:layout_alignBottom="@+id/tvImageSize" | ||
android:layout_below="@+id/tvAdvancedFilters" | ||
android:layout_toRightOf="@+id/tvAdvancedFilters" /> | ||
|
||
<Spinner | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/spinnerColorFilter" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentEnd="true" | ||
android:layout_toEndOf="@+id/tvAdvancedFilters" | ||
android:layout_alignBottom="@+id/tvColorFilter" | ||
android:layout_below="@+id/tvImageSize" | ||
android:layout_toRightOf="@+id/tvAdvancedFilters" | ||
android:layout_alignLeft="@+id/spinnerImageSize" /> | ||
|
||
<Spinner | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/spinnerImageType" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentEnd="true" | ||
android:layout_alignBottom="@+id/tvImageType" | ||
android:layout_below="@+id/tvColorFilter" | ||
android:layout_alignLeft="@+id/spinnerColorFilter" /> | ||
|
||
<EditText | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:hint="Enter site name" | ||
android:id="@+id/etSiteFilter" | ||
android:layout_alignBottom="@+id/tvSiteFilter" | ||
android:layout_alignLeft="@+id/spinnerImageType" | ||
android:layout_alignRight="@+id/spinnerImageType" | ||
android:layout_alignEnd="@+id/spinnerImageType" | ||
android:textSize="12dp" | ||
android:textIsSelectable="false" /> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Save" | ||
android:id="@+id/btnSave" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_below="@+id/tvSiteFilter" | ||
android:layout_marginTop="20dp" /> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Cancel" | ||
android:id="@+id/btnCancel" | ||
android:layout_alignTop="@+id/btnSave" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentEnd="true" /> | ||
|
||
</RelativeLayout> |