List of usage examples for android.widget CheckedTextView isChecked
@ViewDebug.ExportedProperty public boolean isChecked()
From source file:com.germainz.identiconizer.ContactsListActivity.java
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); CheckedTextView checkedTextView = (CheckedTextView) v.findViewById(R.id.check); boolean isChecked = !checkedTextView.isChecked(); if (isChecked) checkedItems.add(position);//from w w w .ja v a 2 s. c o m else checkedItems.remove((Integer) position); checkedTextView.setChecked(isChecked); }
From source file:com.nextgis.maplibui.util.TrackView.java
private void init(Context context) { mContext = context;/*from www. java 2 s. c om*/ mSelectedIds = new ArrayList<>(); int[] attrs = new int[] { R.attr.ic_action_visibility_on, R.attr.ic_action_visibility_off }; TypedArray ta = mContext.obtainStyledAttributes(attrs); mVisibilityOn = ta.getDrawable(0); mVisibilityOff = ta.getDrawable(1); ta.recycle(); setItemsCanFocus(false); setChoiceMode(CHOICE_MODE_MULTIPLE); if (context instanceof AppCompatActivity) { AppCompatActivity activity = (AppCompatActivity) context; IGISApplication application = (IGISApplication) activity.getApplication(); mContentUriTracks = Uri .parse("content://" + application.getAuthority() + "/" + TrackLayer.TABLE_TRACKS); String[] from = new String[] { TrackLayer.FIELD_NAME, TrackLayer.FIELD_VISIBLE }; int[] to = new int[] { R.id.tv_name, R.id.iv_visibility }; mTrackAdapter = new TrackAdapter(context, R.layout.row_track, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setAdapter(mTrackAdapter); activity.getSupportLoaderManager().initLoader(TRACKS_ID, null, this); } setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { CheckedTextView name = (CheckedTextView) view.findViewById(R.id.tv_name); name.setChecked(!name.isChecked()); if (name.isChecked()) mSelectedIds.add(id + ""); else mSelectedIds.remove(id + ""); if (mCheckedChangeListener != null) mCheckedChangeListener.onCheckedChanged(); } }); }
From source file:com.example.maciej.mytask.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar);//www . j a v a 2s .co m createNotification(); mDateTimeTextView = (TextView) findViewById(R.id.dateTimeTextView); // final Button addTaskBtn = (Button) findViewById(R.id.addTaskBtn); final ListView listview = (ListView) findViewById(R.id.taskListview); // final CheckedTextView listitem = (CheckedTextView) findViewById(R.id.checkedTextView1); mNameList = new ArrayList<String>(); mDescriptionList = new ArrayList<String>(); mDateList = new ArrayList<String>(); String savedNameList = getSharedPreferences(PREFS_TASKS, MODE_PRIVATE).getString(KEY_NAME_LIST, null); if (savedNameList != null) { String[] name_items = savedNameList.split(","); mNameList = new ArrayList<String>(Arrays.asList(name_items)); } String savedDescriptionList = getSharedPreferences(PREFS_TASKS, MODE_PRIVATE) .getString(KEY_DESCRIPTION_LIST, null); if (savedDescriptionList != null) { String[] description_items = savedDescriptionList.split(","); mDescriptionList = new ArrayList<String>(Arrays.asList(description_items)); } String savedDateList = getSharedPreferences(PREFS_TASKS, MODE_PRIVATE).getString(KEY_DATE_LIST, null); if (savedDateList != null) { String[] date_items = savedDateList.split(","); mDateList = new ArrayList<String>(Arrays.asList(date_items)); } mAdapter = new ArrayAdapter<String>(this, R.layout.list_item, mNameList); listview.setAdapter(mAdapter); listview.setItemsCanFocus(false); listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { CheckedTextView item = (CheckedTextView) view; if (item.isChecked()) { Toast.makeText(getApplicationContext(), getString(R.string.checked), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), getString(R.string.unchecked), Toast.LENGTH_SHORT) .show(); } } }); listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { descriptionClicked(view); return true; } }); mTickReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) { mDateTimeTextView.setText(getCurrentTimeStamp()); } } }; }
From source file:com.mk4droid.IMC_Activities.Fragment_Filters.java
@Override public void onClick(View v) { FiltersChangedFlag = true;/*ww w . j a va 2 s. c o m*/ String Tag = (String) v.getTag(); CheckedTextView ctv = (CheckedTextView) v; boolean currState = ctv.isChecked(); ctv.setChecked(!currState); savePreferences(Tag, !currState, "boolean"); }
From source file:com.commonsdroid.fragmentdialog.AlertFragmentDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { setCancelable(isCancelable);//ww w . j a v a 2s .com if (TextUtils.isEmpty(positiveText)) { positiveText = "OK"; Log.d("CHECK", "" + com.commonsdroid.fragmentdialog.R.string.ok); } if (TextUtils.isEmpty(negativeText)) { negativeText = "Cancel"; } switch (type) { case DIALOG_TYPE_OK: /*show dialog with positive button*/ return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(positiveText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onPositiveButtonClick(identifier); } }).create(); case DIALOG_TYPE_YES_NO: /*show dialog with positive and negative button*/ return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(positiveText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onPositiveButtonClick(identifier); } }).setNegativeButton(negativeText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onNegativeButtonClick(identifier); } }).create(); case DATE_DIALOG: /*show date picker dialog*/ return new DatePickerDialog(getActivity(), AlertFragmentDialog.this, sYear, sMonth, sDate); case TIME_DIALOG: /*show time picker dialog*/ return new TimePickerDialog(getActivity(), AlertFragmentDialog.this, sHour, sMinute, true); case SIMPLE_LIST_DIALOG: /** * show simple list dialog */ return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_item).create(); case SINGLE_CHOICE_LIST_DIALOG: /*show single choice list dialog*/ return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_singlechoice).create(); case MULTI_CHOICE_LIST_DIALOG: /*show multichoice list dialog*/ Dialog multipleChoice = new Dialog(getActivity()); multipleChoice.setContentView(R.layout.list_multichoice); multipleChoice.setTitle(title); ListView listView = (ListView) multipleChoice.findViewById(R.id.lstMultichoiceList); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Manage selected items here CheckedTextView textView = (CheckedTextView) view; if (textView.isChecked()) { } else { } Log.e("CHECK", "clicked pos : " + position + " checked : " + textView.isChecked()); } }); final ArrayAdapter<String> arraySingleChoiceAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_multichoice, dialogList); listView.setAdapter(arraySingleChoiceAdapter); multipleChoice.show(); /*multipleChoice.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); multipleChoice.setPositiveButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } });*/ /* multipleChoice.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (alSelectedItem.size() != 0) { sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } } });*/ // multipleChoice.create(); // singleChoiceListDialog.setCancelable(false); /* multipleChoice.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { alSelectedItem.add(items[which]); } else { alSelectedItem.remove(items[which]); } } }); multipleChoice.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); multipleChoice.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (alSelectedItem.size() != 0) { sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } } });*/ return multipleChoice;//.create(); } return null; }
From source file:com.open.file.manager.MainActivity.java
public void onLongclickfile(int position, int fragnum, View item, AdapterView<?> parent) { CheckedTextView tv = ((Gridviewholder) item.getTag()).filename; Gridviewholder holder = ((Gridviewholder) item.getTag()); if (!tv.isChecked()) { selectedfiles.add(holder.associatedfile); tv.setChecked(true);// w ww . j a va2 s .c o m selectedcount++; if (selectedcount == 2) { mMode.getMenu().getItem(Consts.INDEX_RENAME).setVisible(false); mMode.getMenu().getItem(Consts.INDEX_INFO).setVisible(false); } if (mMode == null) { mMode = startActionMode(getCutCopyCallback()); } } else { selectedfiles.remove(holder.associatedfile); tv.setChecked(false); selectedcount--; if (selectedcount == 1) { mMode.getMenu().getItem(Consts.INDEX_RENAME).setVisible(true); mMode.getMenu().getItem(Consts.INDEX_INFO).setVisible(true); } if (selectedcount == 0) { mMode.finish(); mMode = null; } } }
From source file:za.co.neilson.alarm.preferences.AlarmPreferencesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setContentView(R.layout.alarm_preferences); pref = getSharedPreferences("AppPref", MODE_PRIVATE); email = getIntent().getStringExtra("email"); Log.d("? ???!!! ", "" + email); Bundle bundle = getIntent().getExtras(); if (bundle != null && bundle.containsKey("alarm")) { setMathAlarm((Alarm) bundle.getSerializable("alarm")); } else {/*from ww w . jav a 2 s .co m*/ setMathAlarm(new Alarm()); } if (bundle != null && bundle.containsKey("adapter")) { setListAdapter((AlarmPreferenceListAdapter) bundle.getSerializable("adapter")); } else { setListAdapter(new AlarmPreferenceListAdapter(this, getMathAlarm())); } getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> l, View v, int position, long id) { final AlarmPreferenceListAdapter alarmPreferenceListAdapter = (AlarmPreferenceListAdapter) getListAdapter(); final AlarmPreference alarmPreference = (AlarmPreference) alarmPreferenceListAdapter .getItem(position); AlertDialog.Builder alert; v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); switch (alarmPreference.getType()) { case BOOLEAN: CheckedTextView checkedTextView = (CheckedTextView) v; boolean checked = !checkedTextView.isChecked(); ((CheckedTextView) v).setChecked(checked); switch (alarmPreference.getKey()) { case ALARM_ACTIVE: alarm.setAlarmActive(checked); break; case ALARM_VIBRATE: alarm.setVibrate(checked); if (checked) { Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(1000); } break; } alarmPreference.setValue(checked); break; case STRING: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(AlarmPreferencesActivity.this); input.setText(alarmPreference.getValue().toString()); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { alarmPreference.setValue(input.getText().toString()); if (alarmPreference.getKey() == Key.ALARM_NAME) { alarm.setAlarmName(alarmPreference.getValue().toString()); } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] items = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < items.length; i++) items[i] = alarmPreference.getOptions()[i]; alert.setItems(items, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (alarmPreference.getKey()) { case ALARM_DIFFICULTY: Alarm.Difficulty d = Alarm.Difficulty.values()[which]; alarm.setDifficulty(d); break; case ALARM_TONE: alarm.setAlarmTonePath(alarmPreferenceListAdapter.getAlarmTonePaths()[which]); if (alarm.getAlarmTonePath() != null) { if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); } else { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); mediaPlayer.reset(); } try { // mediaPlayer.setVolume(1.0f, 1.0f); mediaPlayer.setVolume(0.2f, 0.2f); mediaPlayer.setDataSource(AlarmPreferencesActivity.this, Uri.parse(alarm.getAlarmTonePath())); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setLooping(false); mediaPlayer.prepare(); mediaPlayer.start(); // Force the mediaPlayer to stop after 3 // seconds... if (alarmToneTimer != null) alarmToneTimer.cancel(); alarmToneTimer = new CountDownTimer(3000, 3000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e) { } } }; alarmToneTimer.start(); } catch (Exception e) { try { if (mediaPlayer.isPlaying()) mediaPlayer.stop(); } catch (Exception e2) { } } } break; default: break; } alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case MULTIPLE_LIST: alert = new AlertDialog.Builder(AlarmPreferencesActivity.this); alert.setTitle(alarmPreference.getTitle()); // alert.setMessage(message); CharSequence[] multiListItems = new CharSequence[alarmPreference.getOptions().length]; for (int i = 0; i < multiListItems.length; i++) multiListItems[i] = alarmPreference.getOptions()[i]; boolean[] checkedItems = new boolean[multiListItems.length]; for (Alarm.Day day : getMathAlarm().getDays()) { checkedItems[day.ordinal()] = true; } alert.setMultiChoiceItems(multiListItems, checkedItems, new OnMultiChoiceClickListener() { @Override public void onClick(final DialogInterface dialog, int which, boolean isChecked) { Alarm.Day thisDay = Alarm.Day.values()[which]; if (isChecked) { alarm.addDay(thisDay); } else { // Only remove the day if there are more than 1 // selected if (alarm.getDays().length > 1) { alarm.removeDay(thisDay); } else { // If the last day was unchecked, re-check // it ((AlertDialog) dialog).getListView().setItemChecked(which, true); } } } }); alert.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }); alert.show(); break; case TIME: TimePickerDialog timePickerDialog = new TimePickerDialog(AlarmPreferencesActivity.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int hours, int minutes) { Calendar newAlarmTime = Calendar.getInstance(); newAlarmTime.set(Calendar.HOUR_OF_DAY, hours); newAlarmTime.set(Calendar.MINUTE, minutes); newAlarmTime.set(Calendar.SECOND, 0); alarm.setAlarmTime(newAlarmTime); alarmPreferenceListAdapter.setMathAlarm(getMathAlarm()); alarmPreferenceListAdapter.notifyDataSetChanged(); } }, alarm.getAlarmTime().get(Calendar.HOUR_OF_DAY), alarm.getAlarmTime().get(Calendar.MINUTE), true); timePickerDialog.setTitle(alarmPreference.getTitle()); timePickerDialog.show(); default: break; } } }); }
From source file:universe.constellation.orion.viewer.OrionViewerActivity.java
public void initRotationScreen() { //if (getDevice() instanceof EdgeDevice) { if (false) {//from w ww. j a v a 2s .c o m final RadioGroup rotationGroup = (RadioGroup) findMyViewById(R.id.rotationGroup); rotationGroup.check(R.id.rotate0); if (Device.Info.NOOK2) { RadioButton r0 = (RadioButton) rotationGroup.findViewById(R.id.rotate0); RadioButton r90 = (RadioButton) rotationGroup.findViewById(R.id.rotate90); RadioButton r270 = (RadioButton) rotationGroup.findViewById(R.id.rotate270); TextView tv = (TextView) findMyViewById(R.id.navigation_title); int color = tv.getTextColors().getDefaultColor(); r0.setTextColor(color); r90.setTextColor(color); r270.setTextColor(color); } getSubscriptionManager().addDocListeners(new DocumentViewAdapter() { @Override public void documentOpened(Controller controller) { updateRotation(); } }); ImageButton apply = (ImageButton) findMyViewById(R.id.rotation_apply); apply.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onApplyAction(true); int id = rotationGroup.getCheckedRadioButtonId(); controller.setRotation(id == R.id.rotate0 ? 0 : id == R.id.rotate90 ? -1 : 1); } }); ListView list = (ListView) findMyViewById(R.id.rotationList); list.setVisibility(View.GONE); } else { RadioGroup rotationGroup = (RadioGroup) findMyViewById(R.id.rotationGroup); rotationGroup.setVisibility(View.GONE); final ListView list = (ListView) findMyViewById(R.id.rotationList); //set choices and replace 0 one with Application Default boolean isLevel9 = getOrionContext().getSdkVersion() >= 9; CharSequence[] values = getResources().getTextArray( isLevel9 ? R.array.screen_orientation_full_desc : R.array.screen_orientation_desc); CharSequence[] newValues = new CharSequence[values.length]; for (int i = 0; i < values.length; i++) { newValues[i] = values[i]; } newValues[0] = getResources().getString(R.string.orientation_default_rotation); list.setAdapter(Device.Info.NOOK2 ? new Nook2ListAdapter(this, android.R.layout.simple_list_item_single_choice, newValues, (TextView) findMyViewById(R.id.navigation_title)) : new ArrayAdapter(this, android.R.layout.simple_list_item_single_choice, newValues)); list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setItemChecked(0, true); list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { public void onItemClick(android.widget.AdapterView parent, View view, int position, long id) { CheckedTextView check = (CheckedTextView) view; check.setChecked(!check.isChecked()); } }); final CharSequence[] ORIENTATION_ARRAY = getResources().getTextArray(R.array.screen_orientation_full); list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { public void onItemClick(android.widget.AdapterView parent, View view, int position, long id) { onApplyAction(true); String orientation = ORIENTATION_ARRAY[position].toString(); controller.changeOrinatation(orientation); } }); ImageButton apply = (ImageButton) findMyViewById(R.id.rotation_apply); apply.setVisibility(View.GONE); // apply.setOnClickListener(new View.OnClickListener() { // public void onClick(View view) { // onApplyAction(true); // } // }); } ImageButton cancel = (ImageButton) findMyViewById(R.id.rotation_close); cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onAnimatorCancel(); updateRotation(); } }); }
From source file:com.sentaroh.android.SMBSync2.ActivityMain.java
private void confirmUseAppSpecificDir(final ArrayList<SyncTaskItem> alp, final NotifyEvent p_ntfy) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); if (!prefs.getBoolean(getString(R.string.settings_suppress_warning_app_specific_dir), false)) { boolean app_specific_used = false; String prof_list = "", sep = ""; for (int i = 0; i < alp.size(); i++) { if (alp.get(i).getTargetFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_INTERNAL) || alp.get(i).getTargetFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_SDCARD)) { if (alp.get(i).getTargetDirectoryName().startsWith(APP_SPECIFIC_DIRECTORY)) { app_specific_used = true; prof_list += sep + alp.get(i).getSyncTaskName(); sep = ","; }/* w w w . java 2s . c o m*/ } } if (app_specific_used) { final Dialog dialog = new Dialog(mActivity);//, android.R.style.Theme_Black); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.confirm_app_specific_dir_dlg); final LinearLayout title_view = (LinearLayout) dialog .findViewById(R.id.confirm_app_specific_dlg_title_view); final TextView title = (TextView) dialog.findViewById(R.id.confirm_app_specific_dlg_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setText(mContext.getString(R.string.msgs_local_mount_point_app_specific_dir_used_title)); title.setTextColor(mGp.themeColorList.text_color_warning); ((TextView) dialog.findViewById(R.id.confirm_app_specific_dlg_msg)) .setText(mContext.getString(R.string.msgs_local_mount_point_app_specific_dir_used_msg) + "\n\n" + prof_list + "\n"); final Button btnOk = (Button) dialog.findViewById(R.id.confirm_app_specific_dlg_ok); final Button btnCancel = (Button) dialog.findViewById(R.id.confirm_app_specific_dlg_cancel); final CheckedTextView ctvSuppr = (CheckedTextView) dialog .findViewById(R.id.confirm_app_specific_dlg_ctv_suppress); CommonUtilities.setCheckedTextView(ctvSuppr); CommonDialog.setDlgBoxSizeCompact(dialog); ctvSuppr.setChecked(false); // OK? btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); if (ctvSuppr.isChecked()) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); prefs.edit().putBoolean(getString(R.string.settings_suppress_warning_app_specific_dir), true).commit(); } p_ntfy.notifyToListener(true, null); } }); // Cancel? btnCancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(false, null); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnOk.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(mContext)); // dialog.setCancelable(false); dialog.show(); } else { p_ntfy.notifyToListener(true, null); } } else { p_ntfy.notifyToListener(true, null); } }
From source file:com.sentaroh.android.Utilities.Dialog.SafFileSelectDialogFragment.java
private void fileSelectEditDialogCreateBtn(final Activity activity, final Context context, final String c_dir, String n_dir, final TreeFilelistAdapter tfa, final NotifyEvent p_ntfy, final ListView lv) { // ??//from w w w .j a v a 2s . c o m mCreateDirDialog = new Dialog(activity); mCreateDirDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); mCreateDirDialog.setContentView(R.layout.single_item_input_dlg); final TextView dlg_title = (TextView) mCreateDirDialog.findViewById(R.id.single_item_input_title); dlg_title.setText(context.getString(R.string.msgs_file_select_edit_dlg_create)); final TextView dlg_msg = (TextView) mCreateDirDialog.findViewById(R.id.single_item_input_msg); final TextView dlg_cmp = (TextView) mCreateDirDialog.findViewById(R.id.single_item_input_name); final CheckedTextView dlg_type = (CheckedTextView) mCreateDirDialog .findViewById(R.id.single_item_input_type); setCheckedTextView(dlg_type); dlg_type.setVisibility(CheckedTextView.VISIBLE); dlg_type.setText(context.getString(R.string.msgs_file_select_edit_dlg_dir_create_file)); final Button btnOk = (Button) mCreateDirDialog.findViewById(R.id.single_item_input_ok_btn); final Button btnCancel = (Button) mCreateDirDialog.findViewById(R.id.single_item_input_cancel_btn); final EditText etDir = (EditText) mCreateDirDialog.findViewById(R.id.single_item_input_dir); dlg_cmp.setText(context.getString(R.string.msgs_file_select_edit_parent_directory) + ":" + c_dir); CommonDialog.setDlgBoxSizeCompact(mCreateDirDialog); etDir.setText(n_dir.replaceAll(c_dir, "")); btnOk.setEnabled(false); etDir.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (s.length() > 0) { // SafFile lf=mSafFileMgr.getSafFileBySdcardPath(mDialogSafRoot, c_dir+"/"+s.toString(), true); SafFile lf = mSafFileMgr.getSafFileBySdcardPath(mDialogSafRoot, c_dir, true); SafFile[] c_fl = lf.listFiles(); boolean found = false; for (SafFile item : c_fl) { if (item.getName().equals(s.toString())) { found = true; break; } } // Log.v("","fp="+lf.getPath()); if (found) { btnOk.setEnabled(false); dlg_msg.setText(context.getString(R.string.msgs_single_item_input_dlg_duplicate_dir)); } else { btnOk.setEnabled(true); dlg_msg.setText(""); } } } }); //OK button btnOk.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // NotifyEvent final String creat_dir = etDir.getText().toString(); final String n_path = c_dir + "/" + creat_dir; NotifyEvent ntfy = new NotifyEvent(context); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { boolean rc_create = false; if (!dlg_type.isChecked()) { Log.v("", "n_path=" + n_path); SafFile sf = mSafFileMgr.getSafFileBySdcardPath(mSafFileMgr.getSdcardSafFile(), n_path, true); rc_create = sf.exists(); } else { SafFile sf = mSafFileMgr.getSafFileBySdcardPath(mSafFileMgr.getSdcardSafFile(), n_path, false); rc_create = sf.exists(); } if (!rc_create) { dlg_msg.setText(String.format( context.getString(R.string.msgs_file_select_edit_dlg_dir_not_created), etDir.getText())); return; } else { // String[] a_dir=creat_dir.startsWith("/")?creat_dir.substring(1).split("/"):creat_dir.split("/"); String[] a_dir = n_path.startsWith("/") ? n_path.substring(1).split("/") : n_path.split("/"); String p_dir = "/", sep = ""; for (int i = 0; i < a_dir.length; i++) { if (a_dir[i] != null && !a_dir[i].equals("")) { // Log.v("","p_dir="+p_dir); updateTreeFileList(p_dir, a_dir[i], c_dir, tfa, lv); p_dir += sep + a_dir[i]; sep = "/"; } } mCreateDirDialog.dismiss(); mCreateDirDialog = null; p_ntfy.notifyToListener(true, new Object[] { etDir.getText().toString() }); } } @Override public void negativeResponse(Context c, Object[] o) { } }); CommonDialog cd = new CommonDialog(context, getFragmentManager()); if (dlg_type.isChecked()) cd.showCommonDialog(true, "W", context.getString(R.string.msgs_file_select_edit_confirm_create_file), n_path, ntfy); else cd.showCommonDialog(true, "W", context.getString(R.string.msgs_file_select_edit_confirm_create_directory), n_path, ntfy); } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { mCreateDirDialog.dismiss(); // Log.v("","cancel create"); mCreateDirDialog = null; p_ntfy.notifyToListener(false, null); } }); mCreateDirDialog.show(); }