List of usage examples for android.support.v4.app Fragment getActivity
public Activity getActivity()
From source file:com.dycode.jepretstory.mediachooser.async.VideoLoadAsync.java
public VideoLoadAsync(Fragment fragment, ImageView imageView, boolean isScrolling, int width, int height) { mImageView = imageView;/* w w w . j a va 2 s. c o m*/ this.fragment = fragment; mWidth = width; mHeight = height; mIsScrolling = isScrolling; FragmentActivity act = fragment.getActivity(); if (act == null) { return; } final int memClass = ((ActivityManager) act.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); final int size = 1024 * 1024 * memClass / 8; // Handle orientation change. GalleryRetainCache c = GalleryRetainCache.getOrCreateRetainableCache(); mCache = c.mRetainedCache; if (mCache == null) { // The maximum bitmap pixels allowed in respective direction. // If exceeding, the cache will automatically scale the // bitmaps. /* final int MAX_PIXELS_WIDTH = 100; final int MAX_PIXELS_HEIGHT = 100;*/ mCache = new GalleryCache(size, mWidth, mHeight); c.mRetainedCache = mCache; } }
From source file:eu.geopaparazzi.library.forms.views.GTimeView.java
/** * @param fragment the fragment.// www .j ava 2 s.c om * @param attrs attributes. * @param parentView parent * @param key key * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GTimeView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String key, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat timeFormatter = TimeUtilities.INSTANCE.TIMEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = timeFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = timeFormatter.parse(dateStr); } catch (ParseException e) { // fallback on current date date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int hourOfDay = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); FormTimePickerFragment newFragment = new FormTimePickerFragment(); newFragment.setAttributes(hourOfDay, minute, true, button); newFragment.show(fragment.getFragmentManager(), "timePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }
From source file:eu.geopaparazzi.library.forms.views.GDateView.java
/** * @param fragment the fragment to use. * @param attrs attributes./* w w w . j a v a 2s . c om*/ * @param parentView parent * @param key key * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GDateView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String key, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat dateFormatter = TimeUtilities.INSTANCE.DATEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = dateFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = dateFormatter.parse(dateStr); } catch (ParseException e) { // fallback on current date date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); FormDatePickerFragment newFragment = new FormDatePickerFragment(year, month, day, button); newFragment.show(fragment.getFragmentManager(), "datePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }
From source file:hku.fyp14017.blencode.ui.dialogs.NewLookDialog.java
public void showDialog(Fragment fragment) { if (!(fragment instanceof LookFragment)) { throw new RuntimeException("This dialog (NewLookDialog) can only be called by the LookFragment."); }//from w w w. jav a 2 s . c om this.fragment = (LookFragment) fragment; show(fragment.getActivity().getSupportFragmentManager(), TAG); }
From source file:br.org.funcate.dynamicforms.views.GTimeView.java
/** * @param fragment the fragment.//from w w w .j a v a 2s. c o m * @param attrs attributes. * @param parentView parent * @param label label * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GTimeView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String label, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); final Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat timeFormatter = TimeUtilities.INSTANCE.TIMEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = timeFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = timeFormatter.parse(dateStr); } catch (ParseException e) { //GPLog.error(this, null, e); Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); // fallback on current date date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int hourOfDay = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); FormTimePickerFragment newFragment = new FormTimePickerFragment(); newFragment.setAttributes(hourOfDay, minute, true, button); //newFragment.show(fragment.getFragmentManager(), "timePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }
From source file:br.org.funcate.dynamicforms.views.GDateView.java
/** * @param fragment the fragment to use. * @param attrs attributes./*from w w w . ja va 2 s .c o m*/ * @param parentView parent * @param label label * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GDateView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String label, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); final Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat dateFormatter = TimeUtilities.INSTANCE.DATEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = dateFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = dateFormatter.parse(dateStr); } catch (ParseException e) { //GPLog.error(this, null, e); Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); FormDatePickerFragment newFragment = new FormDatePickerFragment(); newFragment.setAttributes(year, month, day, button); newFragment.show(fragment.getFragmentManager(), "datePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }
From source file:org.catrobat.catroid.ui.dialogs.NewSoundDialog.java
public void showDialog(Fragment fragment) { if (!(fragment instanceof SoundFragment)) { throw new RuntimeException("This dialog (NewSoundDialog) can only be called by the SoundFragment."); }// w w w . ja v a 2s . com this.fragment = (SoundFragment) fragment; show(fragment.getActivity().getSupportFragmentManager(), TAG); }
From source file:com.normalexception.app.rx8club.dialog.MoveThreadDialog.java
/** * Constructor for method that is used to move a thread from one * forum to another //from w ww. j ava 2 s .c o m * @param ctx The source context/activity * @param securitytoken The security token for the session * @param src_thread The source thread * @param tTitle The new thread title * @param options The options from the move dialog */ public MoveThreadDialog(final Fragment ctx, final String securitytoken, final String src_thread, String tTitle, final Map<String, Integer> options) { builder = new AlertDialog.Builder(ctx.getActivity()); // Set up the input final TextView lbl_title = new TextView(ctx.getActivity()); final EditText title = new EditText(ctx.getActivity()); final TextView lbl_dest = new TextView(ctx.getActivity()); final Spinner destination = new Spinner(ctx.getActivity()); // Lets make sure the user didn't accidentally click this DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: newTitle = title.getText().toString(); String selectText = destination.getSelectedItem().toString(); selection = options.get(selectText); AsyncTask<Void, String, Void> updaterTask = new AsyncTask<Void, String, Void>() { @Override protected Void doInBackground(Void... params) { try { HtmlFormUtils.adminMoveThread(securitytoken, src_thread, newTitle, Integer.toString(selection)); } catch (Exception e) { Log.e(TAG, "Error Submitting Form For Move", e); } return null; } @Override protected void onPostExecute(Void result) { ctx.getFragmentManager().popBackStack(); CategoryFragment cFrag = (CategoryFragment) ((ThreadFragment) ctx).getParentCategory(); cFrag.refreshView(); } }; updaterTask.execute(); break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; // Specify the type of input expected lbl_title.setText("Thread Title"); lbl_title.setTextColor(Color.WHITE); lbl_dest.setText("Desination"); lbl_dest.setTextColor(Color.WHITE); title.setInputType(InputType.TYPE_CLASS_TEXT); title.setText(tTitle); List<String> values = new ArrayList<String>(); values.addAll(options.keySet()); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(ctx.getActivity(), android.R.layout.simple_spinner_item, values); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); destination.setAdapter(dataAdapter); LinearLayout ll = new LinearLayout(ctx.getActivity()); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(lbl_title); ll.addView(title); ll.addView(lbl_dest); ll.addView(destination); builder.setView(ll); builder.setTitle(R.string.dialogMoveThread).setPositiveButton(R.string.Move, dialogClickListener) .setNegativeButton(R.string.cancel, dialogClickListener); }
From source file:com.uphyca.testing.support.v4.FragmentInstrumentation.java
public void callFragmentOnActivityCreated() { assertFragmentManager();//from w ww .ja va 2 s . co m for (Fragment each : mfragmentManager.getFragments().values()) { ShadowFragment shadow = Robolectric.shadowOf(each); Bundle savedInstanceState = shadow.getSavedInstanceState(); View view = each.onCreateView(each.getActivity().getLayoutInflater(), null, savedInstanceState); shadow.setView(view); each.onViewCreated(view, null); each.onActivityCreated(savedInstanceState); } }
From source file:net.lp.actionbarpoirot.helpers.FragmentHelperHoneycomb.java
/** * Start the CAB using the ActionMode.Callback defined above * // ww w.j av a 2s .c o m * @param fragment */ protected void startActionModeInner(Fragment fragment) { mActionMode = fragment.getActivity().startActionMode(this); }