Back to project page BrokenDisplay.
The source code is released under:
Apache License
If you think the Android project BrokenDisplay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.foolish.brokendisplay.picturedialog; /*w ww.j ava2 s . c o m*/ import java.util.ArrayList; import java.util.List; import com.foolish.brokendisplay.R; import android.content.res.Configuration; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; import android.widget.AdapterView; import android.widget.GridView; import android.widget.LinearLayout; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; public class SelectPictureDialog extends DialogFragment { private List<Integer> pictureList; private IOnSelectPictureDialog mCallback; private GridView gridView; @Override public void onCreate(Bundle savedInstanceState) { if (getActivity() instanceof IOnSelectPictureDialog) { mCallback = (IOnSelectPictureDialog) getActivity(); } super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // remove title bar getDialog().setTitle(getResources().getString(R.string.select_picture)); LinearLayout rootView = new LinearLayout(getActivity()); rootView.setOrientation(LinearLayout.VERTICAL); gridView = new GridView(getActivity()); Configuration config = getResources().getConfiguration(); if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { gridView.setNumColumns(3); } else { gridView.setNumColumns(2); } rootView.addView(gridView); pictureList = new ArrayList<Integer>(); pictureList.add(R.drawable.glass1); pictureList.add(R.drawable.glass2); pictureList.add(R.drawable.glass3); pictureList.add(R.drawable.glass4); pictureList.add(R.drawable.glass5); pictureList.add(R.drawable.glass6); gridView.setAdapter(new Picture_GridAdapter(getActivity(), R.layout.fragment_picture_main, pictureList)); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, final int position, long id) { mCallback.onPicture(pictureList.get(position)); getDialog().cancel(); } }); return rootView; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); getDialog().getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); // set dialog to fill whole screen (minus padding) getDialog().getWindow().getAttributes().height = LayoutParams.MATCH_PARENT; getDialog().getWindow().getAttributes().width = LayoutParams.MATCH_PARENT; } }