List of usage examples for android.widget ListView ListView
public ListView(Context context)
From source file:de.spiritcroc.ownlog.ui.fragment.MultiSelectTagDialog.java
private View createView() { mTagListView = new ListView(getActivity()); return mTagListView; }
From source file:com.fibrobook.viewpager.custom.CardFragment.java
public void dayView(LinearLayout l) { LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT, Gravity.TOP); ListView eventList = new ListView(getActivity()); eventList.setLayoutParams(params);/*from w w w .j a v a 2 s .c o m*/ ArrayAdapter<DailyEvent> adapter = new ArrayAdapter<DailyEvent>(getActivity(), android.R.layout.simple_list_item_1, dailyEvents); eventList.setAdapter(adapter); eventList.setClickable(true); eventList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View v, int position, long id) { ratingDialog = new Dialog(getActivity(), com.fibrobook.R.style.FullHeightDialog); ratingDialog.setContentView(com.fibrobook.R.layout.rating_dialog); ratingDialog.setCancelable(true); RatingBar ratingBar = (RatingBar) ratingDialog.findViewById(com.fibrobook.R.id.dialog_ratingbar); int i = 0; boolean exists = false; while (i < des.size()) { if (dailyEvents.get(position).getId() == des.get(i).getDailyEvent().getId()) { aes = des.get(i); ratingBar.setRating(aes.getIntensity()); exists = true; break; } i++; } if (!exists) aes = new DailyEventSummary(MainActivity.user, dailyEvents.get(position), MainActivity.date); Button updateButton = (Button) ratingDialog.findViewById(com.fibrobook.R.id.rank_dialog_button); updateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { RatingBar ratingBar = (RatingBar) ratingDialog .findViewById(com.fibrobook.R.id.dialog_ratingbar); aes.setIntensity(ratingBar.getRating()); DailyEventSummaryDAO dao = new DailyEventSummaryDAO(getActivity()); dao.save(aes); des = dao.getDailySummary(MainActivity.date); dao.close(); ratingDialog.dismiss(); } }); ratingDialog.show(); } }); l.addView(eventList); }
From source file:org.dkf.jmule.util.UIUtils.java
public static void showYesNoDialog(Context context, int iconId, String message, int titleId, List<String> bullets, OnClickListener positiveListener, OnClickListener negativeListener, AdapterView.OnItemClickListener bulletsClickListener) { if (bullets == null || bullets.isEmpty()) { LOG.warn("showYesNoDialog() - aborting bullet dialog, no bullets to show."); return;//from www .j a v a 2 s . c o m } AlertDialog.Builder builder = new AlertDialog.Builder(context); // show all bullets pre-checked, prepend for (int i = 0; i < bullets.size(); i++) { bullets.set(i, String.valueOf(Html.fromHtml("• " + bullets.get(i)))); } ArrayAdapter bulletsAdapter; bulletsAdapter = new ArrayAdapter(context, R.layout.dialog_update_bullet, R.id.dialog_update_bullets_checked_text_view, bullets); ListView bulletsListView = new ListView(context); bulletsListView.setAdapter(bulletsAdapter); bulletsListView.setOnItemClickListener(bulletsClickListener); builder.setIcon(iconId).setTitle(titleId).setMessage(message).setView(bulletsListView).setCancelable(false) .setPositiveButton(android.R.string.yes, positiveListener) .setNegativeButton(android.R.string.no, negativeListener).create().show(); }
From source file:org.telegram.ui.PrivacyControlActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); if (isGroup) { actionBar.setTitle(LocaleController.getString("GroupsAndChannels", R.string.GroupsAndChannels)); } else {/*from ww w. j av a 2 s . com*/ actionBar.setTitle(LocaleController.getString("PrivacyLastSeen", R.string.PrivacyLastSeen)); } actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (getParentActivity() == null) { return; } if (currentType != 0 && !isGroup) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); boolean showed = preferences.getBoolean("privacyAlertShowed", false); if (!showed) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); if (isGroup) { builder.setMessage( LocaleController.getString("WhoCanAddMeInfo", R.string.WhoCanAddMeInfo)); } else { builder.setMessage(LocaleController.getString("CustomHelp", R.string.CustomHelp)); } builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { applyCurrentPrivacySettings(); preferences.edit().putBoolean("privacyAlertShowed", true).commit(); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); return; } } applyCurrentPrivacySettings(); } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); doneButton.setVisibility(View.GONE); listAdapter = new ListAdapter(context); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); ListView listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; listView.setLayoutParams(layoutParams); listView.setAdapter(listAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == nobodyRow || i == everybodyRow || i == myContactsRow) { int newType = currentType; if (i == nobodyRow) { newType = 1; } else if (i == everybodyRow) { newType = 0; } else if (i == myContactsRow) { newType = 2; } if (newType == currentType) { return; } enableAnimation = true; doneButton.setVisibility(View.VISIBLE); lastCheckedType = currentType; currentType = newType; updateRows(); } else if (i == neverShareRow || i == alwaysShareRow) { ArrayList<Integer> createFromArray; if (i == neverShareRow) { createFromArray = currentMinus; } else { createFromArray = currentPlus; } if (createFromArray.isEmpty()) { Bundle args = new Bundle(); args.putBoolean(i == neverShareRow ? "isNeverShare" : "isAlwaysShare", true); args.putBoolean("isGroup", isGroup); GroupCreateActivity fragment = new GroupCreateActivity(args); fragment.setDelegate(new GroupCreateActivity.GroupCreateActivityDelegate() { @Override public void didSelectUsers(ArrayList<Integer> ids) { if (i == neverShareRow) { currentMinus = ids; for (int a = 0; a < currentMinus.size(); a++) { currentPlus.remove(currentMinus.get(a)); } } else { currentPlus = ids; for (int a = 0; a < currentPlus.size(); a++) { currentMinus.remove(currentPlus.get(a)); } } doneButton.setVisibility(View.VISIBLE); lastCheckedType = -1; listAdapter.notifyDataSetChanged(); } }); presentFragment(fragment); } else { PrivacyUsersActivity fragment = new PrivacyUsersActivity(createFromArray, isGroup, i == alwaysShareRow); fragment.setDelegate(new PrivacyUsersActivity.PrivacyActivityDelegate() { @Override public void didUpdatedUserList(ArrayList<Integer> ids, boolean added) { if (i == neverShareRow) { currentMinus = ids; if (added) { for (int a = 0; a < currentMinus.size(); a++) { currentPlus.remove(currentMinus.get(a)); } } } else { currentPlus = ids; if (added) { for (int a = 0; a < currentPlus.size(); a++) { currentMinus.remove(currentPlus.get(a)); } } } doneButton.setVisibility(View.VISIBLE); listAdapter.notifyDataSetChanged(); } }); presentFragment(fragment); } } } }); return fragmentView; }
From source file:widgets.Graphical_List.java
@SuppressLint("HandlerLeak") public Graphical_List(tracerengine Trac, Activity context, int id, int dev_id, String name, String type, String address, final String state_key, String url, final String usage, int period, int update, int widgetSize, int session_type, final String parameters, String model_id, int place_id, String place_type, SharedPreferences params) { super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container); this.Tracer = Trac; this.context = context; this.dev_id = dev_id; this.id = id; this.usage = usage; this.address = address; //this.type = type; this.state_key = state_key; this.update = update; this.wname = name; this.url = url; String[] model = model_id.split("\\."); this.type = model[0]; this.place_id = place_id; this.place_type = place_type; this.params = params; packageName = context.getPackageName(); this.myself = this; this.session_type = session_type; this.parameters = parameters; setOnLongClickListener(this); setOnClickListener(this); mytag = "Graphical_List (" + dev_id + ")"; login = params.getString("http_auth_username", null); password = params.getString("http_auth_password", null); //state key/*from ww w .j a v a 2 s. co m*/ state_key_view = new TextView(context); state_key_view.setText(state_key); state_key_view.setTextColor(Color.parseColor("#333333")); //value value = new TextView(context); value.setTextSize(28); value.setTextColor(Color.BLACK); animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(1000); if (with_list) { //Exploit parameters JSONObject jparam = null; String command; JSONArray commandValues = null; try { jparam = new JSONObject(parameters.replaceAll(""", "\"")); command = jparam.getString("command"); commandValues = jparam.getJSONArray("commandValues"); Tracer.e(mytag, "Json command :" + commandValues); } catch (Exception e) { command = ""; commandValues = null; Tracer.e(mytag, "Json command error " + e.toString()); } if (commandValues != null) { if (commandValues.length() > 0) { if (known_values != null) known_values = null; known_values = new String[commandValues.length()]; for (int i = 0; i < commandValues.length(); i++) { try { known_values[i] = commandValues.getString(i); } catch (Exception e) { known_values[i] = "???"; } } } } //list of choices listeChoices = new ListView(context); listItem = new ArrayList<HashMap<String, String>>(); list_usable_choices = new Vector<String>(); for (int i = 0; i < known_values.length; i++) { list_usable_choices.add(getStringResourceByName(known_values[i])); HashMap<String, String> map = new HashMap<String, String>(); map.put("choice", getStringResourceByName(known_values[i])); map.put("cmd_to_send", known_values[i]); listItem.add(map); } SimpleAdapter adapter_map = new SimpleAdapter(getContext(), listItem, R.layout.item_choice, new String[] { "choice", "cmd_to_send" }, new int[] { R.id.choice, R.id.cmd_to_send }); listeChoices.setAdapter(adapter_map); listeChoices.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if ((position < listItem.size()) && (position > -1)) { //process selected command HashMap<String, String> map = new HashMap<String, String>(); map = listItem.get(position); cmd_requested = map.get("cmd_to_send"); Tracer.d(mytag, "command selected at Position = " + position + " Commande = " + cmd_requested); new CommandeThread().execute(); } } }); listeChoices.setScrollingCacheEnabled(false); //feature panel 2 which will contain list of selectable choices featurePan2 = new LinearLayout(context); featurePan2.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); featurePan2.setGravity(Gravity.CENTER_VERTICAL); featurePan2.setPadding(5, 10, 5, 10); featurePan2.addView(listeChoices); } LL_featurePan.addView(value); handler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == 2) { Toast.makeText(getContext(), "Command Failed", Toast.LENGTH_SHORT).show(); } else if (msg.what == 9999) { //Message from cache engine //state_engine send us a signal to notify value changed if (session == null) return; String loc_Value = session.getValue(); Tracer.d(mytag, "Handler receives a new value <" + loc_Value + ">"); value.setText(getStringResourceByName(loc_Value)); //To have the icon colored as it has no state IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 2)); } else if (msg.what == 9998) { // state_engine send us a signal to notify it'll die ! Tracer.d(mytag, "cache engine disappeared ===> Harakiri !"); session = null; realtime = false; removeView(LL_background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } } }; //End of handler //================================================================================ /* * New mechanism to be notified by widgetupdate engine when our value is changed * */ WidgetUpdate cache_engine = WidgetUpdate.getInstance(); if (cache_engine != null) { session = new Entity_client(dev_id, state_key, mytag, handler, session_type); if (tracerengine.get_engine().subscribe(session)) { realtime = true; //we're connected to engine //each time our value change, the engine will call handler handler.sendEmptyMessage(9999); //Force to consider current value in session } } //================================================================================ //updateTimer(); //Don't use anymore cyclic refresh.... }
From source file:widgets.Graphical_History.java
private void getlastvalue() { //TODO add something in the view //add last 5 values with their dates //featurePan2.addView(); JSONObject json_LastValues = null;/*from w ww. j ava 2 s. c o m*/ JSONArray itemArray = null; listeChoices = new ListView(context); ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>(); try { json_LastValues = Rest_com.connect(url + "stats/" + dev_id + "/" + state_key + "/last/5/", login, password); itemArray = json_LastValues.getJSONArray("stats"); for (int i = itemArray.length(); i >= 0; i--) { try { HashMap<String, String> map = new HashMap<String, String>(); map.put("value", itemArray.getJSONObject(i).getString("value")); map.put("date", itemArray.getJSONObject(i).getString("date")); listItem.add(map); Tracer.d(mytag, map.toString()); } catch (Exception e) { Tracer.e(mytag, "Error getting json value"); } } } catch (Exception e) { //return null; Tracer.e(mytag, "Error getting json object"); } SimpleAdapter adapter_feature = new SimpleAdapter(this.context, listItem, R.layout.item_phone, new String[] { "value", "date" }, new int[] { R.id.phone_value, R.id.phone_date }); listeChoices.setAdapter(adapter_feature); listeChoices.setScrollingCacheEnabled(false); }
From source file:org.mariotaku.twidere.fragment.support.BaseSupportListFragment.java
/** * Provide default implementation to return a simple list view. Subclasses * can override to replace with their own layout. If doing so, the returned * view hierarchy <em>must</em> have a ListView whose id is * {@link android.R.id#list android.R.id.list} and can optionally have a * sibling view id {@link android.R.id#empty android.R.id.empty} that is to * be shown when the list is empty.//from w ww. j av a2 s . co m * * <p> * If you are overriding this method with your own custom content, consider * including the standard layout {@link android.R.layout#list_content} in * your layout file, so that you continue to retain all of the standard * behavior of ListFragment. In particular, this is currently the only way * to have the built-in indeterminant progress state be shown. */ @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final Context context = getActivity(); final FrameLayout root = new FrameLayout(context); // ------------------------------------------------------------------ final LinearLayout pframe = new LinearLayout(context); pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID); pframe.setOrientation(LinearLayout.VERTICAL); pframe.setVisibility(View.GONE); pframe.setGravity(Gravity.CENTER); final ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge); pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // ------------------------------------------------------------------ final FrameLayout lframe = new FrameLayout(context); lframe.setId(INTERNAL_LIST_CONTAINER_ID); final TextView tv = new TextView(getActivity()); tv.setTextAppearance(context, ThemeUtils.getTextAppearanceLarge(context)); tv.setId(INTERNAL_EMPTY_ID); tv.setGravity(Gravity.CENTER); lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); final ListView lv = new ListView(getActivity()); lv.setId(android.R.id.list); lv.setDrawSelectorOnTop(false); lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // ------------------------------------------------------------------ root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return root; }
From source file:org.telegram.ui.NotificationsSettingsActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override// w w w.j a v a2s . c o m public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new FrameLayout(context); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); FrameLayout frameLayout = (FrameLayout) fragmentView; listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); frameLayout.addView(listView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setAdapter(new ListAdapter(context)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, final View view, final int i, long l) { boolean enabled = false; if (i == messageAlertRow || i == groupAlertRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (i == messageAlertRow) { enabled = preferences.getBoolean("EnableAll", true); editor.putBoolean("EnableAll", !enabled); } else if (i == groupAlertRow) { enabled = preferences.getBoolean("EnableGroup", true); editor.putBoolean("EnableGroup", !enabled); } editor.commit(); updateServerNotificationsSettings(i == groupAlertRow); } else if (i == messagePreviewRow || i == groupPreviewRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (i == messagePreviewRow) { enabled = preferences.getBoolean("EnablePreviewAll", true); editor.putBoolean("EnablePreviewAll", !enabled); } else if (i == groupPreviewRow) { enabled = preferences.getBoolean("EnablePreviewGroup", true); editor.putBoolean("EnablePreviewGroup", !enabled); } editor.commit(); updateServerNotificationsSettings(i == groupPreviewRow); } else if (i == messageSoundRow || i == groupSoundRow) { try { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); Uri currentSound = null; String defaultPath = null; Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI; if (defaultUri != null) { defaultPath = defaultUri.getPath(); } if (i == messageSoundRow) { String path = preferences.getString("GlobalSoundPath", defaultPath); if (path != null && !path.equals("NoSound")) { if (path.equals(defaultPath)) { currentSound = defaultUri; } else { currentSound = Uri.parse(path); } } } else if (i == groupSoundRow) { String path = preferences.getString("GroupSoundPath", defaultPath); if (path != null && !path.equals("NoSound")) { if (path.equals(defaultPath)) { currentSound = defaultUri; } else { currentSound = Uri.parse(path); } } } tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound); startActivityForResult(tmpIntent, i); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == resetNotificationsRow) { if (reseting) { return; } reseting = true; TLRPC.TL_account_resetNotifySettings req = new TLRPC.TL_account_resetNotifySettings(); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { MessagesController.getInstance().enableJoined = true; reseting = false; SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); if (listView != null) { listView.invalidateViews(); } if (getParentActivity() != null) { Toast toast = Toast .makeText(getParentActivity(), LocaleController.getString("ResetNotificationsText", R.string.ResetNotificationsText), Toast.LENGTH_SHORT); toast.show(); } } }); } }); } else if (i == inappSoundRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInAppSounds", true); editor.putBoolean("EnableInAppSounds", !enabled); editor.commit(); } else if (i == inappVibrateRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInAppVibrate", true); editor.putBoolean("EnableInAppVibrate", !enabled); editor.commit(); } else if (i == inappPreviewRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInAppPreview", true); editor.putBoolean("EnableInAppPreview", !enabled); editor.commit(); } else if (i == inchatSoundRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInChatSound", true); editor.putBoolean("EnableInChatSound", !enabled); editor.commit(); NotificationsController.getInstance().setInChatSoundEnabled(!enabled); } else if (i == inappPriorityRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableInAppPriority", false); editor.putBoolean("EnableInAppPriority", !enabled); editor.commit(); } else if (i == contactJoinedRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableContactJoined", true); MessagesController.getInstance().enableJoined = !enabled; editor.putBoolean("EnableContactJoined", !enabled); editor.commit(); } else if (i == pinnedMessageRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("PinnedMessages", true); editor.putBoolean("PinnedMessages", !enabled); editor.commit(); } else if (i == androidAutoAlertRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("EnableAutoNotifications", false); editor.putBoolean("EnableAutoNotifications", !enabled); editor.commit(); } else if (i == badgeNumberRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); enabled = preferences.getBoolean("badgeNumber", true); editor.putBoolean("badgeNumber", !enabled); editor.commit(); NotificationsController.getInstance().setBadgeEnabled(!enabled); } else if (i == notificationsServiceConnectionRow) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); enabled = preferences.getBoolean("pushConnection", true); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("pushConnection", !enabled); editor.commit(); if (!enabled) { ConnectionsManager.getInstance().setPushConnectionEnabled(true); } else { ConnectionsManager.getInstance().setPushConnectionEnabled(false); } } else if (i == notificationsServiceRow) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); enabled = preferences.getBoolean("pushService", true); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("pushService", !enabled); editor.commit(); if (!enabled) { ApplicationLoader.startPushService(); } else { ApplicationLoader.stopPushService(); } /*if (!enabled) { } else { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("NotificationsServiceDisableInfo", R.string.NotificationsServiceDisableInfo)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { final SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("pushService", false); editor.commit(); listView.invalidateViews(); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ((TextCheckCell) view).setChecked(true); } }); showDialog(builder.create()); }*/ } else if (i == messageLedRow || i == groupLedRow) { if (getParentActivity() == null) { return; } LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity()); linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (i == messageLedRow) { colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00)); } else if (i == groupLedRow) { colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00)); } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); TextColorCell textCell = (TextColorCell) view; if (i == messageLedRow) { editor.putInt("MessagesLed", colorPickerView.getColor()); textCell.setTextAndColor( LocaleController.getString("LedColor", R.string.LedColor), colorPickerView.getColor(), true); } else if (i == groupLedRow) { editor.putInt("GroupLed", colorPickerView.getColor()); textCell.setTextAndColor( LocaleController.getString("LedColor", R.string.LedColor), colorPickerView.getColor(), true); } editor.commit(); } }); builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); TextColorCell textCell = (TextColorCell) view; if (i == messageLedRow) { editor.putInt("MessagesLed", 0); textCell.setTextAndColor( LocaleController.getString("LedColor", R.string.LedColor), 0, true); } else if (i == groupLedRow) { editor.putInt("GroupLed", 0); textCell.setTextAndColor( LocaleController.getString("LedColor", R.string.LedColor), 0, true); } editor.commit(); listView.invalidateViews(); } }); showDialog(builder.create()); } else if (i == messagePopupNotificationRow || i == groupPopupNotificationRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification)); builder.setItems( new CharSequence[] { LocaleController.getString("NoPopup", R.string.NoPopup), LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn), LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff), LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (i == messagePopupNotificationRow) { editor.putInt("popupAll", which); } else if (i == groupPopupNotificationRow) { editor.putInt("popupGroup", which); } editor.commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == messageVibrateRow || i == groupVibrateRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate)); builder.setItems( new CharSequence[] { LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled), LocaleController.getString("VibrationDefault", R.string.VibrationDefault), LocaleController.getString("Short", R.string.Short), LocaleController.getString("Long", R.string.Long), LocaleController.getString("OnlyIfSilent", R.string.OnlyIfSilent) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); String param = "vibrate_messages"; if (i == groupVibrateRow) { param = "vibrate_group"; } if (which == 0) { editor.putInt(param, 2); } else if (which == 1) { editor.putInt(param, 0); } else if (which == 2) { editor.putInt(param, 1); } else if (which == 3) { editor.putInt(param, 3); } else if (which == 4) { editor.putInt(param, 4); } editor.commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == messagePriorityRow || i == groupPriorityRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority)); builder.setItems(new CharSequence[] { LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault), LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh), LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (i == messagePriorityRow) { preferences.edit().putInt("priority_messages", which).commit(); } else if (i == groupPriorityRow) { preferences.edit().putInt("priority_group", which).commit(); } if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == repeatRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications)); builder.setItems( new CharSequence[] { LocaleController.getString("RepeatDisabled", R.string.RepeatDisabled), LocaleController.formatPluralString("Minutes", 5), LocaleController.formatPluralString("Minutes", 10), LocaleController.formatPluralString("Minutes", 30), LocaleController.formatPluralString("Hours", 1), LocaleController.formatPluralString("Hours", 2), LocaleController.formatPluralString("Hours", 4) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int minutes = 0; if (which == 1) { minutes = 5; } else if (which == 2) { minutes = 10; } else if (which == 3) { minutes = 30; } else if (which == 4) { minutes = 60; } else if (which == 5) { minutes = 60 * 2; } else if (which == 6) { minutes = 60 * 4; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("repeat_messages", minutes).commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(!enabled); } } }); return fragmentView; }
From source file:org.telegram.ui.SessionsActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("SessionsTitle", R.string.SessionsTitle)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/* ww w. ja v a 2 s . co m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); listAdapter = new ListAdapter(context); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); emptyLayout = new LinearLayout(context); emptyLayout.setOrientation(LinearLayout.VERTICAL); emptyLayout.setGravity(Gravity.CENTER); //emptyLayout.setBackgroundResource(R.drawable.greydivider_bottom); emptyLayout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight())); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.devices); emptyLayout.addView(imageView); LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; imageView.setLayoutParams(layoutParams2); TextView textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setText(LocaleController.getString("NoOtherSessions", R.string.NoOtherSessions)); emptyLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.topMargin = AndroidUtilities.dp(16); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER; textView.setLayoutParams(layoutParams2); textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0); textView.setText(LocaleController.getString("NoOtherSessionsInfo", R.string.NoOtherSessionsInfo)); emptyLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.topMargin = AndroidUtilities.dp(14); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER; textView.setLayoutParams(layoutParams2); FrameLayout progressView = new FrameLayout(context); frameLayout.addView(progressView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; progressView.setLayoutParams(layoutParams); progressView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); ProgressBar progressBar = new ProgressBar(context); progressView.addView(progressBar); layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER; progressView.setLayoutParams(layoutParams); ListView listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); listView.setEmptyView(progressView); frameLayout.addView(listView); layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; listView.setLayoutParams(layoutParams); listView.setAdapter(listAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == terminateAllSessionsRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage( LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations(); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (getParentActivity() == null) { return; } if (error == null && response instanceof TLRPC.TL_boolTrue) { Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT); toast.show(); } else { Toast toast = Toast .makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT); toast.show(); } finishFragment(); } }); UserConfig.registeredForPush = false; UserConfig.saveConfig(false); MessagesController.getInstance().registerForPush(UserConfig.pushString); ConnectionsManager.getInstance() .setUserId(UserConfig.getClientUserId()); } }); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i >= otherSessionsStartRow && i < otherSessionsEndRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("TerminateSessionQuestion", R.string.TerminateSessionQuestion)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int option) { final ProgressDialog progressDialog = new ProgressDialog(getParentActivity()); progressDialog .setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.show(); final TLRPC.TL_authorization authorization = sessions .get(i - otherSessionsStartRow); TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization(); req.hash = authorization.hash; ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { try { progressDialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } if (error == null) { sessions.remove(authorization); updateRows(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } } } }); } }); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); return fragmentView; }
From source file:ua.com.spacetv.mycookbook.dialogs.FragDialog.java
private void initAllViewsInDialog() { adb = new AlertDialog.Builder(getActivity()); input = new EditText(getActivity()); listView = new ListView(getActivity()); textView = new TextView(getActivity()); int paddingH = (int) getResources().getDimension(R.dimen.dialog_padding_left_right); int paddingV = (int) getResources().getDimension(R.dimen.dialog_padding_up_down); int textColor; if (Build.VERSION.SDK_INT >= 21) { //Getting color from current theme TypedValue typedValue = new TypedValue(); mContext.getTheme().resolveAttribute(android.R.attr.colorPrimary, typedValue, true); int barColor = typedValue.data; textView.setBackgroundColor(barColor); textColor = ContextCompat.getColor(mContext, R.color.colorWhite); } else {/* w ww .j a v a 2 s . c o m*/ textColor = ContextCompat.getColor(mContext, R.color.colorBlack); } if (Build.VERSION.SDK_INT < 23) { textView.setTextAppearance(mContext, android.R.style.TextAppearance_Large); } else { textView.setTextAppearance(android.R.style.TextAppearance_Large); } textView.setTextColor(textColor); textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setPadding(paddingH, paddingV, paddingH, paddingV); input.setPadding(paddingH, paddingV, paddingH, paddingV); listView.setSelected(true); listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); listView.setSelector(R.drawable.list_color_selector); listView.setOnItemClickListener(this); listView.requestFocus(); }