List of usage examples for android.support.v4.app DialogFragment show
public int show(FragmentTransaction transaction, String tag)
From source file:de.eidottermihi.rpicheck.activity.MainActivity.java
private void doQuery(boolean initByPullToRefresh) { if (currentDevice == null) { // no device available, show hint for user Toast.makeText(this, R.string.no_device_available, Toast.LENGTH_LONG).show(); // stop refresh animation from pull-to-refresh swipeRefreshLayout.setRefreshing(false); return;//from w w w . j a v a 2 s . c om } ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { // get connection settings from shared preferences String host = currentDevice.getHost(); String user = currentDevice.getUser(); String port = currentDevice.getPort() + ""; String pass = null; // reading process preference final Boolean hideRoot = sharedPrefs.getBoolean(SettingsActivity.KEY_PREF_QUERY_HIDE_ROOT_PROCESSES, true); String keyPath = null; String keyPass = null; boolean canConnect = false; // check authentification method final String authMethod = currentDevice.getAuthMethod(); if (authMethod.equals(NewRaspiAuthActivity.SPINNER_AUTH_METHODS[0])) { // only ssh password pass = currentDevice.getPass(); if (pass != null) { canConnect = true; } else { Toast.makeText(this, R.string.no_password_specified, Toast.LENGTH_LONG).show(); } } else if (authMethod.equals(NewRaspiAuthActivity.SPINNER_AUTH_METHODS[1])) { // keyfile must be present final String keyfilePath = currentDevice.getKeyfilePath(); if (keyfilePath != null) { final File privateKey = new File(keyfilePath); if (privateKey.exists()) { keyPath = keyfilePath; canConnect = true; } else { Toast.makeText(this, "Cannot find keyfile at location: " + keyfilePath, Toast.LENGTH_LONG) .show(); } } else { Toast.makeText(this, "No keyfile specified!", Toast.LENGTH_LONG).show(); } } else if (authMethod.equals(NewRaspiAuthActivity.SPINNER_AUTH_METHODS[2])) { // keyfile and keypass must be present final String keyfilePath = currentDevice.getKeyfilePath(); if (keyfilePath != null) { final File privateKey = new File(keyfilePath); if (privateKey.exists()) { keyPath = keyfilePath; final String keyfilePass = currentDevice.getKeyfilePass(); if (keyfilePass != null) { canConnect = true; keyPass = keyfilePass; } else { final DialogFragment newFragment = new PassphraseDialog(); final Bundle args = new Bundle(); args.putString(PassphraseDialog.KEY_TYPE, PassphraseDialog.SSH_QUERY); newFragment.setArguments(args); newFragment.setCancelable(false); newFragment.show(getSupportFragmentManager(), "passphrase"); canConnect = false; } } else { Toast.makeText(this, "Cannot find keyfile at location: " + keyfilePath, Toast.LENGTH_LONG) .show(); } } else { Toast.makeText(this, "No keyfile specified!", Toast.LENGTH_LONG).show(); } } if (host == null) { Toast.makeText(this, R.string.no_hostname_specified, Toast.LENGTH_LONG).show(); canConnect = false; } else if (user == null) { Toast.makeText(this, R.string.no_username_specified, Toast.LENGTH_LONG).show(); canConnect = false; } if (canConnect) { // disable pullToRefresh (if refresh initiated by action bar) if (!initByPullToRefresh) { // show hint for pull-to-refresh this.showPullToRefreshHint(); } // execute query new SSHQueryTask(this, getLoadAveragePreference()).execute(host, user, pass, port, hideRoot.toString(), keyPath, keyPass); } } else { Toast.makeText(this, R.string.no_connection, Toast.LENGTH_SHORT).show(); // stop refresh animation from pull-to-refresh swipeRefreshLayout.setRefreshing(false); } }
From source file:edu.princeton.jrpalmer.asmlibrary.Settings.java
@Override protected void onResume() { if (Util.trafficCop(this)) finish();/* w w w . j av a 2s. c o m*/ IntentFilter uploadFilter; uploadFilter = new IntentFilter( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_UPLOADED); uploadReceiver = new UploadReceiver(); registerReceiver(uploadReceiver, uploadFilter); IntentFilter fixFilter; fixFilter = new IntentFilter( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_RECORDED); fixReceiver = new FixReceiver(); registerReceiver(fixReceiver, fixFilter); shareMyData = PropertyHolder.getShareData(); toggleParticipationViews(shareMyData); int nUploads = PropertyHolder.getNUploads(); final long participationTime = PropertyHolder.ptCheck(); participationTimeText.setBase(SystemClock.elapsedRealtime() - participationTime); // service button boolean isServiceOn = PropertyHolder.isServiceOn(); mServiceButton.setChecked(isServiceOn); mServiceButton.setOnClickListener(new ToggleButton.OnClickListener() { public void onClick(View view) { if (view.getId() != R.id.service_button) return; Context context = view.getContext(); boolean on = ((ToggleButton) view).isChecked(); String schedule = on ? Util.MESSAGE_SCHEDULE : Util.MESSAGE_UNSCHEDULE; // Log.e(TAG, schedule + on); // now schedule or unschedule Intent intent = new Intent(getString(R.string.internal_message_id) + schedule); context.sendBroadcast(intent); showSpinner(on, storeMyData); if (on && shareMyData) { final long ptNow = PropertyHolder.ptStart(); participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow); participationTimeText.start(); ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF", "on," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow)); } else { final long ptNow = PropertyHolder.ptStop(); participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow); participationTimeText.stop(); // stop uploader Intent stopUploaderIntent = new Intent(Settings.this, FileUploader.class); // Stop service if it is currently running stopService(stopUploaderIntent); if (shareMyData) { ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF", "off," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow)); } } // If user turns CountdownDisplay on but GPS is not on, remind // user to turn // GPS on if (on) { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { if (!manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { buildAlertMessageNoGpsNoNet(); } else buildAlertMessageNoGps(); } } return; } }); // interval spinner int intspinner_item = android.R.layout.simple_spinner_item; int dropdown_item = android.R.layout.simple_spinner_dropdown_item; ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.interval_array, intspinner_item); adapter.setDropDownViewResource(dropdown_item); mIntervalSpinner.setAdapter(adapter); mIntervalSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { int parentId = parent.getId(); if (parentId != R.id.spinner_interval) return; if (pos > mInterval.length) return; if (!PropertyHolder.isServiceOn()) { PropertyHolder.setAlarmInterval(mInterval[pos]); return; } PropertyHolder.setAlarmInterval(mInterval[pos]); mServiceButton.setChecked(true); Intent intent = new Intent(getString(R.string.internal_message_id) + Util.MESSAGE_SCHEDULE); Context context = getApplicationContext(); context.sendBroadcast(intent); showSpinner(true, storeMyData); if (shareMyData) { ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("INT", Util.iso8601(System.currentTimeMillis()) + "," + mInterval[pos])); } } public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); int pos = ai2pos(PropertyHolder.getAlarmInterval()); mIntervalSpinner.setSelection(pos); showSpinner(isServiceOn, storeMyData); // mydata buttons // storage spinner storageDays = PropertyHolder.getStorageDays(); mStorageSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { int parentId = parent.getId(); if (parentId != R.id.spinner_mydata) return; if (pos > MAX_STORAGE - MIN_STORAGE) return; PropertyHolder.setStorageDays(pos + MIN_STORAGE); PropertyHolder.setStoreMyData((pos + MIN_STORAGE) > 0); } public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); int storagepos = storageDays - MIN_STORAGE; mStorageSpinner.setSelection(storagepos); // NEW STUFF mToggleSatRadioGroup = (RadioGroup) findViewById(R.id.toggleSatRadioGroup); mToggleIconsRadioGroup = (RadioGroup) findViewById(R.id.toggleIconsRadioGroup); mToggleAccRadioGroup = (RadioGroup) findViewById(R.id.toggleAccRadioGroup); mLimitStartDateRadioGroup = (RadioGroup) findViewById(R.id.limitStartDateRadioGroup); mLimitEndDateRadioGroup = (RadioGroup) findViewById(R.id.limitEndDateRadioGroup); Intent i = getIntent(); if (i.getBooleanExtra(MapMyData.DATES_BUTTON_MESSAGE, false)) { RelativeLayout dateSettingsArea = (RelativeLayout) findViewById(R.id.dateSettingsArea); dateSettingsArea.setFocusable(true); dateSettingsArea.setFocusableInTouchMode(true); dateSettingsArea.requestFocus(); } if (shareMyData && isServiceOn) { participationTimeText.setBase(SystemClock.elapsedRealtime() - PropertyHolder.ptStart()); participationTimeText.start(); } nUploadsText.setText(String.valueOf(nUploads)); if (nUploads >= Util.UPLOADS_TO_PRO && !PropertyHolder.getProVersion() && participationTime >= Util.TIME_TO_PRO) { Util.createProNotification(context); PropertyHolder.setProVersion(true); PropertyHolder.setNeedsDebriefingSurvey(true); } boolean proV = PropertyHolder.getProVersion(); // 19 December 2013: end of research changes mShareDataRadioGroup.check(R.id.sharedataNo); mShareDataRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.sharedataYes) { buildSharingOverAnnouncement(); } mShareDataRadioGroup.check(R.id.sharedataNo); } }); /* * if (proV) { * * if (shareMyData) { mShareDataRadioGroup.check(R.id.sharedataYes); if * (PropertyHolder.isRegistered() == false || * PropertyHolder.hasConsented() == false) { send2Intro(context); } } * else { mShareDataRadioGroup.check(R.id.sharedataNo); } * * mShareDataRadioGroup .setOnCheckedChangeListener(new * OnCheckedChangeListener() { * * @Override public void onCheckedChanged(RadioGroup group, int * checkedId) { shareMyData = (checkedId == R.id.sharedataYes); * PropertyHolder.setShareData(shareMyData); * toggleParticipationViews(shareMyData); final boolean on = * PropertyHolder.isServiceOn(); if (shareMyData) { if * (PropertyHolder.isRegistered() == false || * PropertyHolder.hasConsented() == false) { send2Intro(context); * * } if (on) { * * final long ptNow = PropertyHolder.ptStart(); * participationTimeText.setBase(SystemClock .elapsedRealtime() - * ptNow); * * participationTimeText.start(); * * ContentResolver ucr = getContentResolver(); * * ucr.insert( Util.getUploadQueueUri(context), * UploadContentValues.createUpload( "ONF", "on," + Util.iso8601(System * .currentTimeMillis()) + "," + ptNow)); * * } } else { * * final long ptNow = PropertyHolder.ptStop(); * participationTimeText.setBase(SystemClock .elapsedRealtime() - * ptNow); participationTimeText.stop(); // stop uploader Intent i = new * Intent(Settings.this, FileUploader.class); // Stop service if it is * currently running stopService(i); * * if (on) { ContentResolver ucr = getContentResolver(); * * ucr.insert( Util.getUploadQueueUri(context), * UploadContentValues.createUpload( "ONF", "off," + Util.iso8601(System * .currentTimeMillis()) + "," + ptNow)); * * } * * } * * } }); } else { mShareDataRadioGroup.check(R.id.sharedataYes); * mShareDataRadioGroup .setOnCheckedChangeListener(new * OnCheckedChangeListener() { * * @Override public void onCheckedChanged(RadioGroup group, int * checkedId) { if (checkedId == R.id.sharedataNo) { * mShareDataRadioGroup.check(R.id.sharedataYes); * showCurrentlySharingDialog(); } } }); * * } */ new CheckPendingUploadsSizeTask().execute(context); new CheckUserDbSizeTask().execute(context); deletePendingUploadsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ContentResolver cr = getContentResolver(); final int nDeleted = cr.delete(Util.getUploadQueueUri(context), "1", null); // Log.i("Settings", "number of rows deleted=" + nDeleted); Util.toast(context, String.valueOf(nDeleted) + " " + getResources().getString(R.string.locations_deleted) + "."); updateStorageSizes(); } }); deleteUserDbButton = (ImageButton) findViewById(R.id.deleteMyDbButton); deleteUserDbButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ContentResolver cr = getContentResolver(); final int nDeleted = cr.delete(Util.getFixesUri(context), "1", null); Util.toast(context, String.valueOf(nDeleted) + " " + getResources().getString(R.string.locations_deleted) + "."); updateStorageSizes(); } }); uploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Util.isOnline(context)) { Intent i = new Intent(Settings.this, FileUploader.class); startService(i); new UploadMessageTask().execute(context); } else { Util.toast(context, getResources().getString(R.string.offline_warning)); } } }); mToggleSatRadioGroup.check(PropertyHolder.getMapSat() ? R.id.toggleSatYes : R.id.toggleSatNo); mToggleSatRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapSat(checkedId == R.id.toggleSatYes); } }); mToggleIconsRadioGroup.check(PropertyHolder.getMapIcons() ? R.id.toggleIconsYes : R.id.toggleIconsNo); mToggleIconsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapIcons(checkedId == R.id.toggleIconsYes); } }); mToggleAccRadioGroup.check(PropertyHolder.getMapAcc() ? R.id.toggleAccYes : R.id.toggleAccNo); mToggleAccRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapAcc(checkedId == R.id.toggleAccYes); } }); mStartDateButton = (Button) findViewById(R.id.startDateButton); mEndDateButton = (Button) findViewById(R.id.endDateButton); boolean limitStartDate = PropertyHolder.getLimitStartDate(); boolean limitEndDate = PropertyHolder.getLimitEndDate(); if (!limitStartDate) mStartDateButton.setVisibility(View.GONE); else { mStartDateButton.setVisibility(View.VISIBLE); } if (!limitEndDate) mEndDateButton.setVisibility(View.GONE); else { mEndDateButton.setVisibility(View.VISIBLE); } mLimitStartDateRadioGroup.check(limitStartDate ? R.id.limitStartDateYes : R.id.limitStartDateNo); mLimitStartDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setLimitStartDate(checkedId == R.id.limitStartDateYes); if (checkedId != R.id.limitStartDateYes) mStartDateButton.setVisibility(View.GONE); else { mStartDateButton.setVisibility(View.VISIBLE); } } }); mLimitEndDateRadioGroup.check(limitEndDate ? R.id.limitEndDateYes : R.id.limitEndDateNo); mLimitEndDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setLimitEndDate(checkedId == R.id.limitEndDateYes); if (checkedId != R.id.limitEndDateYes) mEndDateButton.setVisibility(View.GONE); else { mEndDateButton.setVisibility(View.VISIBLE); } } }); mStartDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapStartDate())); mStartDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new StartDatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); mEndDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapEndDate())); mEndDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new EndDatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); if (PropertyHolder.getNeedsDebriefingSurvey()) { buildProAnnouncement(); PropertyHolder.setNeedsDebriefingSurvey(false); } super.onResume(); }
From source file:it.mb.whatshare.Dialogs.java
/** * Shows a prompt to the user to rename the argument <tt>device</tt>. * // w ww . j av a 2s . c o m * @param device * the device to be renamed * @param activity * the parent activity */ public static void promptForNewDeviceName(final PairedDevice device, final MainActivity activity) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { DialogFragment prompt = new PatchedDialogFragment() { public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = getBuilder(activity); final EditText input = new EditText(getContext()); input.setInputType(InputType.TYPE_CLASS_TEXT); input.setText(device.name); input.setSelection(device.name.length()); // @formatter:off builder.setTitle(R.string.device_name_chooser_title).setView(input) .setPositiveButton(android.R.string.ok, null); // @formatter:on final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener( new DeviceNameChooserPrompt(alertDialog, input, activity, new Callback<String>() { @Override public void run() { // @formatter:off device.rename(getParam()); activity.onSelectedDeviceRenamed(); ((InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); // @formatter:on } })); return alertDialog; } }; prompt.show(activity.getSupportFragmentManager(), "chooseName"); } }); }
From source file:com.android.gallery3d.filtershow.FilterShowActivity.java
private void showExportOptionsDialog() { DialogFragment dialog = new ExportDialog(); dialog.show(getSupportFragmentManager(), "ExportDialogFragment"); }
From source file:com.hpush.app.activities.MainActivity.java
/** * Show {@link android.support.v4.app.DialogFragment}. * * @param _dlgFrg//from w w w . ja va2 s . c om * An instance of {@link android.support.v4.app.DialogFragment}. * @param _tagName * Tag name for dialog, default is "dlg". To grantee that only one instance of {@link * android.support.v4.app.DialogFragment} can been seen. */ protected void showDialogFragment(DialogFragment _dlgFrg, String _tagName) { try { if (_dlgFrg != null) { DialogFragment dialogFragment = _dlgFrg; FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); // Ensure that there's only one dialog to the user. Fragment prev = getSupportFragmentManager().findFragmentByTag("dlg"); if (prev != null) { ft.remove(prev); } try { if (TextUtils.isEmpty(_tagName)) { dialogFragment.show(ft, "dlg"); } else { dialogFragment.show(ft, _tagName); } } catch (Exception _e) { } } } catch (Exception _e) { } }
From source file:com.android.gallery3d.filtershow.FilterShowActivity.java
public void addNewPreset() { DialogFragment dialog = new PresetManagementDialog(); dialog.show(getSupportFragmentManager(), "NoticeDialogFragment"); }
From source file:com.android.gallery3d.filtershow.FilterShowActivity.java
private void manageUserPresets() { DialogFragment dialog = new PresetManagementDialog(); dialog.show(getSupportFragmentManager(), "NoticeDialogFragment"); }
From source file:it.mb.whatshare.Dialogs.java
/** * Shows a dialog to get a name for the inbound device being paired and * starts a new {@link CallGooGlInbound} action if the chosen name is valid. * /*from w w w . j a v a 2s .c o m*/ * @param deviceType * the model of the device being paired as suggested by the * device itself * @param sharedSecret * the keys used when encrypting the message between devices * @param activity * the caller activity */ public static void promptForInboundName(final String deviceType, final int[] sharedSecret, final MainActivity activity) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { DialogFragment prompt = new PatchedDialogFragment() { public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = getBuilder(activity); final EditText input = new EditText(getContext()); input.setInputType(InputType.TYPE_CLASS_TEXT); input.setText(deviceType); input.setSelection(deviceType.length()); // @formatter:off builder.setTitle(R.string.device_name_chooser_title).setView(input) .setPositiveButton(android.R.string.ok, null); // @formatter:on final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener( new DeviceNameChooserPrompt(alertDialog, input, activity, new Callback<String>() { @Override public void run() { // @formatter:off new CallGooGlInbound(activity, getParam(), deviceType) .execute(sharedSecret); ((InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); // @formatter:on } })); return alertDialog; } }; prompt.show(activity.getSupportFragmentManager(), "chooseName"); } }); }
From source file:com.djkim.slap.createGroup.CreateGroupActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.create_group_layout); FacebookSdk.sdkInitialize(this.getApplicationContext()); callbackManager = CallbackManager.Factory.create(); createAppGroupDialog = new CreateAppGroupDialog(this); createAppGroupDialog.registerCallback(callbackManager, new FacebookCallback<CreateAppGroupDialog.Result>() { public void onSuccess(CreateAppGroupDialog.Result result) { String id = result.getId(); group.set_facebookGroupId(id); group.saveInBackground(new GroupCallback() { @Override/*from ww w. ja v a 2 s .co m*/ public void done() { Toast.makeText(CreateGroupActivity.this, "Successfully created the group!", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(); intent.putExtra(CREATE_GROUP_EXTRA, group); setResult(RESULT_OK, intent); finish(); } }); } public void onCancel() { group.saveInBackground(new GroupCallback() { @Override public void done() { Toast.makeText(CreateGroupActivity.this, "Failed to create the group!", Toast.LENGTH_SHORT) .show(); Intent intent = new Intent(); intent.putExtra(CREATE_GROUP_EXTRA, group); setResult(RESULT_OK, intent); finish(); } }); } public void onError(FacebookException error) { } }); if (savedInstanceState != null) { mWizardModel.load(savedInstanceState.getBundle("model")); } mWizardModel.registerListener(this); mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mPagerAdapter); mStepPagerStrip = (StepPagerStrip) findViewById(R.id.strip); mStepPagerStrip.setOnPageSelectedListener(new StepPagerStrip.OnPageSelectedListener() { @Override public void onPageStripSelected(int position) { position = Math.min(mPagerAdapter.getCount() - 1, position); if (mPager.getCurrentItem() != position) { mPager.setCurrentItem(position); } } }); mNextButton = (Button) findViewById(R.id.next_button); mPrevButton = (Button) findViewById(R.id.prev_button); mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { mStepPagerStrip.setCurrentPage(position); if (mConsumePageSelectedEvent) { mConsumePageSelectedEvent = false; return; } mEditingAfterReview = false; updateBottomBar(); } }); mNextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mPager.getCurrentItem() == mCurrentPageSequence.size()) { DialogFragment dg = new DialogFragment() { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setMessage(R.string.submit_confirm_message) .setPositiveButton(R.string.submit_confirm_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { createGroup(); onClickCreateButton(); } }) .setNegativeButton(android.R.string.cancel, null).create(); } }; dg.show(getSupportFragmentManager(), "place_order_dialog"); } else { if (mEditingAfterReview) { mPager.setCurrentItem(mPagerAdapter.getCount() - 1); } else { mPager.setCurrentItem(mPager.getCurrentItem() + 1); } } } }); mPrevButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mPager.getCurrentItem() == 0) { setResult(RESULT_CANCELED); finish(); } else { mPager.setCurrentItem(mPager.getCurrentItem() - 1); } } }); onPageTreeChanged(); updateBottomBar(); }
From source file:com.nbplus.vbroadlauncher.fragment.LauncherFragment.java
/** * when click right panel shortcdddut button ... * @param view/*from w w w . j a v a 2s . c om*/ */ @Override public void onClick(View view) { ShortcutData data = (ShortcutData) view.getTag(); VBroadcastServer serverData = LauncherSettings.getInstance(getActivity()).getServerInformation(); Intent intent; if (!NetworkUtils.isConnected(getActivity())) { ((BaseActivity) getActivity()).showNetworkConnectionAlertDialog(); return; } // push notification badge . if (data.getPushType() != null) { TextView badgeView = (TextView) view.findViewById(R.id.launcher_menu_badge); if (badgeView != null) { badgeView.setVisibility(View.GONE); } } switch (data.getType()) { case Constants.SHORTCUT_TYPE_WEB_INTERFACE_SERVER: BaseServerApiAsyncTask task; if (StringUtils.isEmptyString(serverData.getApiServer())) { showIncorrectServerInformation(); break; } data.setDomain(serverData.getApiServer()); try { task = (BaseServerApiAsyncTask) data.getNativeClass().newInstance(); if (task != null) { showProgressDialog(); task.setBroadcastApiData(getActivity(), mHandler, data.getDomain() + data.getPath()); task.execute(); } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (java.lang.InstantiationException e) { e.printStackTrace(); } break; case Constants.SHORTCUT_TYPE_WEB_DOCUMENT_SERVER: if (StringUtils.isEmptyString(serverData.getDocServer())) { showIncorrectServerInformation(); break; } intent = new Intent(getActivity(), BroadcastWebViewActivity.class); data.setDomain(serverData.getDocServer()); intent.putExtra(Constants.EXTRA_NAME_SHORTCUT_DATA, data); startActivity(intent); break; case Constants.SHORTCUT_TYPE_NATIVE_INTERFACE: if (StringUtils.isEmptyString(serverData.getDocServer())) { showIncorrectServerInformation(); break; } switch (data.getNativeType()) { case 0: // activity intent = new Intent(getActivity(), data.getNativeClass()); data.setDomain(serverData.getDocServer()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(Constants.EXTRA_NAME_SHORTCUT_DATA, data); startActivity(intent); break; case 1: // fragment break; case 2: // dialog fragment FragmentManager fm = getActivity().getSupportFragmentManager(); //no paramater //Class noparams[] = {}; //String parameter Class[] param = new Class[1]; param[0] = ShortcutData.class; DialogFragment fragment = null; try { Object obj = data.getNativeClass().newInstance(); Method method = data.getNativeClass().getDeclaredMethod("newInstance", param); data.setDomain(serverData.getDocServer()); fragment = (DialogFragment) method.invoke(obj, data); } catch (Exception e) { e.printStackTrace(); } if (fragment != null) { fragment.show(fm, "fragment_dialog_radio"); } break; } break; default: Log.d(TAG, "Unknown shortcut type !!!"); } }