List of usage examples for android.widget TextView setCompoundDrawablePadding
@android.view.RemotableViewMethod public void setCompoundDrawablePadding(int pad)
From source file:de.baumann.hhsmoodle.data_schedule.Schedule_Fragment.java
private void setScheduleList() { final int line = sharedPref.getInt("getLine", 1); //display data final int layoutstyle = R.layout.list_item_schedule; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.att_notes, R.id.textView_create_notes }; String[] column = new String[] { "schedule_title", "schedule_content", "schedule_attachment", "schedule_creation" }; final Cursor row = db.fetchAllData(); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override/*from w w w . j a v a2 s. com*/ public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content")); final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon")); final String schedule_attachment = row2 .getString(row2.getColumnIndexOrThrow("schedule_attachment")); final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation")); final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id")); View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); if (position == line) { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent_trans)); } else { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.color_trans)); } if (schedule_title.equals(getActivity().getString(R.string.schedule_weekend)) || schedule_title.equals(getActivity().getString(R.string.schedule_def_title))) { sharedPref.edit().putString("hour_" + schedule_id, "false").apply(); } else { sharedPref.edit().putString("hour_" + schedule_id, "true").apply(); } Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", iv_icon); iv_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red), new helper_main.Item(getString(R.string.subjects_color_pink), R.drawable.circle_pink), new helper_main.Item(getString(R.string.subjects_color_purple), R.drawable.circle_purple), new helper_main.Item(getString(R.string.subjects_color_blue), R.drawable.circle_blue), new helper_main.Item(getString(R.string.subjects_color_teal), R.drawable.circle_teal), new helper_main.Item(getString(R.string.subjects_color_green), R.drawable.circle_green), new helper_main.Item(getString(R.string.subjects_color_lime), R.drawable.circle_lime), new helper_main.Item(getString(R.string.subjects_color_yellow), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.subjects_color_orange), R.drawable.circle_orange), new helper_main.Item(getString(R.string.subjects_color_brown), R.drawable.circle_brown), new helper_main.Item(getString(R.string.subjects_color_grey), R.drawable.circle_grey), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "1", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 1) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "2", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 2) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "3", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 3) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "4", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 4) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "5", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 5) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "6", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 6) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "7", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 7) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "8", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 8) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "9", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 9) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "10", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 10) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "11", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } } }).show(); } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_scheduleBY", "schedule_title"); sharedPref.edit().putString("filter_scheduleBY", "schedule_title").apply(); filter.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final CharSequence[] options = { getString(R.string.schedule_todo), getString(R.string.schedule_notes) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.schedule_todo))) { sharedPref.edit().putString("filter_todo_subject", schedule_title).apply(); new Handler().postDelayed(new Runnable() { public void run() { helper_main.switchToActivity(getActivity(), Popup_todo.class, false); } }, 200); } if (options[item].equals(getString(R.string.schedule_notes))) { sharedPref.edit().putString("filter_note_subject", schedule_title).apply(); new Handler().postDelayed(new Runnable() { public void run() { helper_main.switchToActivity(getActivity(), Popup_note.class, false); } }, 200); } } }).show(); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content")); final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon")); final String schedule_attachment = row2 .getString(row2.getColumnIndexOrThrow("schedule_attachment")); final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation")); final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id")); final CharSequence[] options = { getString(R.string.number_edit_entry), getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu), getString(R.string.bookmark_createNote), getString(R.string.count_create), getString(R.string.bookmark_createEvent) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ConstantConditions") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.number_edit_entry))) { final CharSequence[] options = { getString(R.string.schedule_fromSubjectList), getString(R.string.todo_from_new) }; new AlertDialog.Builder(getActivity()).setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item] .equals(getString(R.string.schedule_fromSubjectList))) { sharedPref.edit().putString("edit_yes", "true") .putInt("scroll", Integer.parseInt(schedule_id)) .putString("handleSubjectCreation", schedule_creation) .putString("handleSubject_id", schedule_id) .putString("handle_id", _id).apply(); helper_main.switchToActivity(getActivity(), Popup_subjects.class, false); } if (options[item].equals(getString(R.string.todo_from_new))) { LayoutInflater inflater = getActivity().getLayoutInflater(); final ViewGroup nullParent = null; View dialogView = inflater .inflate(R.layout.dialog_edit_subject, nullParent); final EditText titleInput = (EditText) dialogView .findViewById(R.id.subject_title_); titleInput.setSelection(titleInput.getText().length()); titleInput.setText(schedule_title); final EditText teacherInput = (EditText) dialogView .findViewById(R.id.subject_teacher); teacherInput.setText(schedule_content); final EditText roomInput = (EditText) dialogView .findViewById(R.id.subject_room); roomInput.setText(schedule_attachment); helper_main.showKeyboard(getActivity(), titleInput); final ImageButton be = (ImageButton) dialogView .findViewById(R.id.imageButtonPri); assert be != null; Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", be); be.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString( R.string.subjects_color_red), R.drawable.circle_red), new helper_main.Item(getString( R.string.subjects_color_pink), R.drawable.circle_pink), new helper_main.Item(getString( R.string.subjects_color_purple), R.drawable.circle_purple), new helper_main.Item(getString( R.string.subjects_color_blue), R.drawable.circle_blue), new helper_main.Item(getString( R.string.subjects_color_teal), R.drawable.circle_teal), new helper_main.Item(getString( R.string.subjects_color_green), R.drawable.circle_green), new helper_main.Item(getString( R.string.subjects_color_lime), R.drawable.circle_lime), new helper_main.Item(getString( R.string.subjects_color_yellow), R.drawable.circle_yellow), new helper_main.Item(getString( R.string.subjects_color_orange), R.drawable.circle_orange), new helper_main.Item(getString( R.string.subjects_color_brown), R.drawable.circle_brown), new helper_main.Item(getString( R.string.subjects_color_grey), R.drawable.circle_grey), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>( getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v .findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds( items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getActivity().getResources() .getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int item) { if (item == 0) { be.setImageResource( R.drawable.circle_red); sharedPref.edit() .putString( "schedule_color", "1") .apply(); } else if (item == 1) { be.setImageResource( R.drawable.circle_pink); sharedPref.edit() .putString( "schedule_color", "2") .apply(); } else if (item == 2) { be.setImageResource( R.drawable.circle_purple); sharedPref.edit() .putString( "schedule_color", "3") .apply(); } else if (item == 3) { be.setImageResource( R.drawable.circle_blue); sharedPref.edit() .putString( "schedule_color", "4") .apply(); } else if (item == 4) { be.setImageResource( R.drawable.circle_teal); sharedPref.edit() .putString( "schedule_color", "5") .apply(); } else if (item == 5) { be.setImageResource( R.drawable.circle_green); sharedPref.edit() .putString( "schedule_color", "6") .apply(); } else if (item == 6) { be.setImageResource( R.drawable.circle_lime); sharedPref.edit() .putString( "schedule_color", "7") .apply(); } else if (item == 7) { be.setImageResource( R.drawable.circle_yellow); sharedPref.edit() .putString( "schedule_color", "8") .apply(); } else if (item == 8) { be.setImageResource( R.drawable.circle_orange); sharedPref.edit() .putString( "schedule_color", "9") .apply(); } else if (item == 9) { be.setImageResource( R.drawable.circle_brown); sharedPref.edit() .putString( "schedule_color", "10") .apply(); } else if (item == 10) { be.setImageResource( R.drawable.circle_grey); sharedPref.edit() .putString( "schedule_color", "11") .apply(); } } }) .show(); } }); android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity()); builder.setTitle(R.string.subjects_edit); builder.setView(dialogView); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTitle = titleInput.getText() .toString().trim(); String inputTeacher = teacherInput.getText() .toString().trim(); String inputRoom = roomInput.getText() .toString().trim(); db.update(Integer.parseInt(_id), inputTitle, inputTeacher, sharedPref.getString( "schedule_color", ""), inputRoom, schedule_creation, schedule_id); dialog.dismiss(); setScheduleList(); lv.setSelection( Integer.parseInt(schedule_id) - 1); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.support.v7.app.AlertDialog dialog2 = builder .create(); dialog2.show(); } } }).show(); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.update(Integer.parseInt(_id), getString(R.string.schedule_def_teacher), getString(R.string.schedule_def_teacher), "11", getString(R.string.schedule_def_teacher), schedule_creation, schedule_id); setScheduleList(); lv.setSelection(Integer.parseInt(schedule_id) - 1); } }); snackbar.show(); } if (options[item].equals(getString(R.string.todo_menu))) { Todo_helper.newTodo(getActivity(), schedule_title, schedule_content, getActivity().getString(R.string.note_content)); } if (options[item].equals(getString(R.string.count_create))) { Count_helper.newCount(getActivity(), schedule_title, schedule_content, getActivity().getString(R.string.note_content), false); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), schedule_title, schedule_content); } if (options[item].equals(getString(R.string.bookmark_createNote))) { Notes_helper.newNote(getActivity(), schedule_title, schedule_content, "", "", "", ""); } } }).show(); return true; } }); scrollToNow(); }
From source file:org.mythdroid.activities.Guide.java
/** * Add a small indicator to the provided TextView based on the Program * recording status/*from w ww. ja va2 s. c o m*/ * @param tv TextView to add an indicator to * @param prog Program to retrieve a recording status from */ private void setStatusDrawable(TextView tv, Program prog) { Drawable icon = null; if (prog.Status == null) return; switch (prog.Status) { case RECORDED: case CURRENT: icon = recordedIcon; break; case WILLRECORD: case RECORDING: case TUNING: case OTHERTUNING: case OTHERRECORDING: icon = willRecordIcon; break; case CANCELLED: case ABORTED: case DONTRECORD: case FAILED: case TUNERBUSY: case MISSED: case MISSEDFUTURE: case LOWSPACE: icon = failedIcon; break; case CONFLICT: icon = conflictIcon; break; case EARLIER: case LATER: case OTHER: icon = otherIcon; break; } if (icon != null) { tv.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); tv.setCompoundDrawablePadding(8); } }
From source file:org.nla.tarotdroid.lib.ui.GameSetHistoryActivity.java
/** * Manage click on GameSet./*from w w w .j av a2s . com*/ * * @param pos */ private void onListItemClick(final int pos) { final GameSet gameSet = (GameSet) getListAdapter().getItem(pos); final Item[] items = AppContext.getApplication().isAppLimited() ? limitedItems : allItems; ListAdapter adapter = new ArrayAdapter<Item>(this, android.R.layout.select_dialog_item, android.R.id.text1, items) { @Override public View getView(int position, View convertView, ViewGroup parent) { // User super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); // Put the image on the TextView tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); // Add margin between image and text (support various screen // densities) int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(String.format(this.getString(R.string.lblGameSetHistoryActivityMenuTitle), new SimpleDateFormat("dd/MM/yy").format(gameSet.getCreationTs()))); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int itemIndex) { Item item = items[itemIndex]; if (item.itemType == Item.ItemTypes.publishOnFacebook) { // check for active internet connexion first // see post // http://stackoverflow.com/questions/2789612/how-can-i-check-whether-an-android-device-is-connected-to-the-web ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { if (gameSet.getGameCount() == 0) { Toast.makeText(GameSetHistoryActivity.this, R.string.lblFacebookImpossibleToPublishGamesetWithNoGame, Toast.LENGTH_SHORT) .show(); } else if (!AppContext.getApplication().getNotificationIds().isEmpty()) { Toast.makeText(GameSetHistoryActivity.this, R.string.lblFacebookGamesetBeingPublished, Toast.LENGTH_SHORT).show(); } else { tempGameSet = gameSet; // // TODO Improve in later version // ShortenUrlTask shortenUrlTask = new // ShortenUrlTask(FacebookHelper.buildGameSetUrl(tempGameSet)); // shortenUrlTask.setCallback(urlShortenedCallback); // shortenUrlTask.execute(); startPostProcess(); } } else { Toast.makeText(GameSetHistoryActivity.this, getString(R.string.titleInternetConnexionNecessary), Toast.LENGTH_LONG).show(); } } else if (item.itemType == Item.ItemTypes.publishOnTwitter) { Toast.makeText(GameSetHistoryActivity.this, "TODO: Publish on twitter", Toast.LENGTH_LONG) .show(); Intent intent = new Intent(GameSetHistoryActivity.this, TwitterConnectActivity.class); startActivity(intent); } else if (item.itemType == Item.ItemTypes.remove) { RemoveGameSetDialogClickListener removeGameSetDialogClickListener = new RemoveGameSetDialogClickListener( gameSet); AlertDialog.Builder builder = new AlertDialog.Builder(GameSetHistoryActivity.this); builder.setTitle(GameSetHistoryActivity.this.getString(R.string.titleRemoveGameSetYesNo)); builder.setMessage(Html.fromHtml( GameSetHistoryActivity.this.getText(R.string.msgRemoveGameSetYesNo).toString())); builder.setPositiveButton(GameSetHistoryActivity.this.getString(R.string.btnOk), removeGameSetDialogClickListener); builder.setNegativeButton(GameSetHistoryActivity.this.getString(R.string.btnCancel), removeGameSetDialogClickListener).show(); builder.setIcon(android.R.drawable.ic_dialog_alert); } else if (item.itemType == Item.ItemTypes.transferOverBluetooth) { if (!GameSetHistoryActivity.this.bluetoothHelper.isBluetoothEnabled()) { Toast.makeText(GameSetHistoryActivity.this, GameSetHistoryActivity.this.getString(R.string.msgActivateBluetooth), Toast.LENGTH_LONG).show(); } try { // make sure at least one device was discovered if (GameSetHistoryActivity.this.bluetoothHelper.getBluetoothDeviceCount() == 0) { Toast.makeText(GameSetHistoryActivity.this, GameSetHistoryActivity.this.getString(R.string.msgRunDiscoverDevicesFirst), Toast.LENGTH_LONG).show(); } // display devices and download final String[] items = GameSetHistoryActivity.this.bluetoothHelper .getBluetoothDeviceNames(); AlertDialog.Builder builder = new AlertDialog.Builder(GameSetHistoryActivity.this); builder.setTitle(GameSetHistoryActivity.this.getString(R.string.lblSelectBluetoothDevice)); builder.setItems(items, new BluetoothDeviceClickListener(gameSet, items)); AlertDialog alert = builder.create(); alert.show(); } catch (Exception e) { AuditHelper.auditError(ErrorTypes.gameSetHistoryActivityError, e, GameSetHistoryActivity.this); } } else if (item.itemType == Item.ItemTypes.exportToExcel) { try { if (!AppContext.getApplication().isAppLimited()) { ExportToExcelTask task = new ExportToExcelTask(GameSetHistoryActivity.this, progressDialog); task.setCallback(excelExportCallback); task.execute(gameSet); } } catch (Exception e) { Toast.makeText( GameSetHistoryActivity.this, AppContext.getApplication().getResources() .getText(R.string.msgGameSetExportError).toString() + e.getMessage(), Toast.LENGTH_LONG).show(); AuditHelper.auditError(ErrorTypes.excelFileStorage, e); } } else if (item.itemType == Item.ItemTypes.edit) { // SharedPreferences preferences = // PreferenceManager.getDefaultSharedPreferences(GameSetHistoryActivity.this); // set selected gameset as session gameset // AppContext.getApplication().getBizService().setGameSet(gameSet); // // Get non DAL stored parameters property from shared // preferences // UIHelper.fillNonComputationPreferences(gameSet.getGameSetParameters(), // preferences); // start tab gameset activity Intent intent = new Intent(GameSetHistoryActivity.this, TabGameSetActivity.class); intent.putExtra(ActivityParams.PARAM_GAMESET_ID, gameSet.getId()); GameSetHistoryActivity.this.startActivityForResult(intent, RequestCodes.DISPLAY_WITH_FACEBOOK); } } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:de.baumann.hhsmoodle.data_subjects.Subjects_Fragment.java
private void setSubjectsList() { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red), new helper_main.Item(getString(R.string.subjects_color_pink), R.drawable.circle_pink), new helper_main.Item(getString(R.string.subjects_color_purple), R.drawable.circle_purple), new helper_main.Item(getString(R.string.subjects_color_blue), R.drawable.circle_blue), new helper_main.Item(getString(R.string.subjects_color_teal), R.drawable.circle_teal), new helper_main.Item(getString(R.string.subjects_color_green), R.drawable.circle_green), new helper_main.Item(getString(R.string.subjects_color_lime), R.drawable.circle_lime), new helper_main.Item(getString(R.string.subjects_color_yellow), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.subjects_color_orange), R.drawable.circle_orange), new helper_main.Item(getString(R.string.subjects_color_brown), R.drawable.circle_brown), new helper_main.Item(getString(R.string.subjects_color_grey), R.drawable.circle_grey), }; //display data final int layoutstyle = R.layout.list_item_schedule; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.att_notes }; String[] column = new String[] { "subject_title", "subject_content", "subject_attachment" }; final Cursor row = db.fetchAllData(); SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override/*from w w w. j a v a 2 s . com*/ public View getView(final int position, View convertView, ViewGroup parent) { Cursor row = (Cursor) lv.getItemAtPosition(position); final String _id = row.getString(row.getColumnIndexOrThrow("_id")); final String subject_title = row.getString(row.getColumnIndexOrThrow("subject_title")); final String subject_content = row.getString(row.getColumnIndexOrThrow("subject_content")); final String subject_icon = row.getString(row.getColumnIndexOrThrow("subject_icon")); final String subject_attachment = row.getString(row.getColumnIndexOrThrow("subject_attachment")); final String subject_creation = row.getString(row.getColumnIndexOrThrow("subject_creation")); View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); Subjects_helper.switchIcon(getActivity(), subject_icon, "subject_color", iv_icon); iv_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { db.update(Integer.parseInt(_id), subject_title, subject_content, "1", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 1) { db.update(Integer.parseInt(_id), subject_title, subject_content, "2", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 2) { db.update(Integer.parseInt(_id), subject_title, subject_content, "3", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 3) { db.update(Integer.parseInt(_id), subject_title, subject_content, "4", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 4) { db.update(Integer.parseInt(_id), subject_title, subject_content, "5", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 5) { db.update(Integer.parseInt(_id), subject_title, subject_content, "6", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 6) { db.update(Integer.parseInt(_id), subject_title, subject_content, "7", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 7) { db.update(Integer.parseInt(_id), subject_title, subject_content, "8", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 8) { db.update(Integer.parseInt(_id), subject_title, subject_content, "9", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 9) { db.update(Integer.parseInt(_id), subject_title, subject_content, "10", subject_attachment, subject_creation); setSubjectsList(); } else if (item == 10) { db.update(Integer.parseInt(_id), subject_title, subject_content, "11", subject_attachment, subject_creation); setSubjectsList(); } } }).show(); } }); return v; } }; lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String subject_title = row2.getString(row2.getColumnIndexOrThrow("subject_title")); final String subject_content = row2.getString(row2.getColumnIndexOrThrow("subject_content")); final CharSequence[] options = { getString(R.string.courseList_todo), getString(R.string.courseList_note), getString(R.string.courseList_random), getString(R.string.courseList_course), getString(R.string.bookmark_createEvent) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.courseList_random))) { android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder( getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null); final EditText edit_title = (EditText) dialogView .findViewById(R.id.note_title_input); edit_title.setHint(R.string.title_hint); edit_title.setText(subject_title); final EditText edit_cont = (EditText) dialogView .findViewById(R.id.note_text_input); edit_cont.setHint(R.string.text_hint); builder.setView(dialogView); builder.setTitle(R.string.number_edit_entry); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.app.AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Do stuff, possibly set wantToCloseDialog to true then... Random_DbAdapter db = new Random_DbAdapter(getActivity()); db.open(); if (db.isExist(subject_title)) { Snackbar.make(edit_title, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { String inputTitle = edit_title.getText().toString().trim(); String inputCont = edit_cont.getText().toString().trim(); db.insert(inputTitle, inputCont, "", "", helper_main.createDate()); dialog2.cancel(); } } }); helper_main.showKeyboard(getActivity(), edit_title); } if (options[item].equals(getString(R.string.courseList_note))) { Notes_helper.newNote(getActivity(), subject_title, subject_content, "", "", "", ""); } if (options[item].equals(getString(R.string.courseList_todo))) { Todo_helper.newTodo(getActivity(), subject_title, subject_content, getActivity().getString(R.string.note_content)); } if (options[item].equals(getString(R.string.courseList_course))) { android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder( getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null); final EditText edit_title = (EditText) dialogView .findViewById(R.id.note_title_input); edit_title.setHint(R.string.title_hint); edit_title.setText(subject_title); final EditText edit_cont = (EditText) dialogView .findViewById(R.id.note_text_input); edit_cont.setHint(R.string.text_hint); builder.setView(dialogView); builder.setTitle(R.string.number_edit_entry); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.app.AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Do stuff, possibly set wantToCloseDialog to true then... Courses_DbAdapter db = new Courses_DbAdapter(getActivity()); db.open(); if (db.isExist(subject_title)) { Snackbar.make(edit_title, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { String inputTitle = edit_title.getText().toString().trim(); String inputCont = edit_cont.getText().toString().trim(); db.insert(inputTitle, inputCont, "", "", helper_main.createDate()); dialog2.cancel(); } } }); helper_main.showKeyboard(getActivity(), edit_title); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), subject_title, subject_content); } } }).show(); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String subject_title = row2.getString(row2.getColumnIndexOrThrow("subject_title")); final String subject_content = row2.getString(row2.getColumnIndexOrThrow("subject_content")); final String subject_icon = row2.getString(row2.getColumnIndexOrThrow("subject_icon")); final String subject_attachment = row2.getString(row2.getColumnIndexOrThrow("subject_attachment")); final String subject_creation = row2.getString(row2.getColumnIndexOrThrow("subject_creation")); final CharSequence[] options = { getString(R.string.number_edit_entry), getString(R.string.subjects_copy), getString(R.string.bookmark_remove_bookmark) }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.number_edit_entry))) { LayoutInflater inflater = getActivity().getLayoutInflater(); final ViewGroup nullParent = null; View dialogView = inflater.inflate(R.layout.dialog_edit_subject, nullParent); titleInput = (EditText) dialogView.findViewById(R.id.subject_title_); titleInput.setSelection(titleInput.getText().length()); titleInput.setText(subject_title); teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher); teacherInput.setText(subject_content); roomInput = (EditText) dialogView.findViewById(R.id.subject_room); roomInput.setText(subject_attachment); helper_main.showKeyboard(getActivity(), titleInput); final ImageButton be = (ImageButton) dialogView .findViewById(R.id.imageButtonPri); assert be != null; Subjects_helper.switchIcon(getActivity(), subject_icon, "subject_color", be); be.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getActivity().getResources() .getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { be.setImageResource(R.drawable.circle_red); sharedPref.edit().putString("subject_color", "1") .apply(); } else if (item == 1) { be.setImageResource(R.drawable.circle_pink); sharedPref.edit().putString("subject_color", "2") .apply(); } else if (item == 2) { be.setImageResource(R.drawable.circle_purple); sharedPref.edit().putString("subject_color", "3") .apply(); } else if (item == 3) { be.setImageResource(R.drawable.circle_blue); sharedPref.edit().putString("subject_color", "4") .apply(); } else if (item == 4) { be.setImageResource(R.drawable.circle_teal); sharedPref.edit().putString("subject_color", "5") .apply(); } else if (item == 5) { be.setImageResource(R.drawable.circle_green); sharedPref.edit().putString("subject_color", "6") .apply(); } else if (item == 6) { be.setImageResource(R.drawable.circle_lime); sharedPref.edit().putString("subject_color", "7") .apply(); } else if (item == 7) { be.setImageResource(R.drawable.circle_yellow); sharedPref.edit().putString("subject_color", "8") .apply(); } else if (item == 8) { be.setImageResource(R.drawable.circle_orange); sharedPref.edit().putString("subject_color", "9") .apply(); } else if (item == 9) { be.setImageResource(R.drawable.circle_brown); sharedPref.edit().putString("subject_color", "10") .apply(); } else if (item == 10) { be.setImageResource(R.drawable.circle_grey); sharedPref.edit().putString("subject_color", "11") .apply(); } } }).show(); } }); android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity()); builder.setTitle(R.string.subjects_edit); builder.setView(dialogView); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Subject_DbAdapter db = new Subject_DbAdapter(getActivity()); db.open(); String inputTitle = titleInput.getText().toString().trim(); String inputTeacher = teacherInput.getText().toString().trim(); String inputRoom = roomInput.getText().toString().trim(); db.update(Integer.parseInt(_id), inputTitle, inputTeacher, sharedPref.getString("subject_color", ""), inputRoom, subject_creation); dialog.dismiss(); setSubjectsList(); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.support.v7.app.AlertDialog dialog2 = builder.create(); dialog2.show(); } if (options[item].equals(getString(R.string.subjects_copy))) { LayoutInflater inflater = getActivity().getLayoutInflater(); final ViewGroup nullParent = null; View dialogView = inflater.inflate(R.layout.dialog_edit_subject, nullParent); titleInput = (EditText) dialogView.findViewById(R.id.subject_title_); titleInput.setSelection(titleInput.getText().length()); titleInput.setText(subject_title); teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher); teacherInput.setText(subject_content); roomInput = (EditText) dialogView.findViewById(R.id.subject_room); roomInput.setText(subject_attachment); helper_main.showKeyboard(getActivity(), titleInput); final ImageButton be = (ImageButton) dialogView .findViewById(R.id.imageButtonPri); Subjects_helper.switchIcon(getActivity(), subject_icon, "subject_color", be); be.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getActivity().getResources() .getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { be.setImageResource(R.drawable.circle_red); sharedPref.edit().putString("subject_color", "1") .apply(); } else if (item == 1) { be.setImageResource(R.drawable.circle_pink); sharedPref.edit().putString("subject_color", "2") .apply(); } else if (item == 2) { be.setImageResource(R.drawable.circle_purple); sharedPref.edit().putString("subject_color", "3") .apply(); } else if (item == 3) { be.setImageResource(R.drawable.circle_blue); sharedPref.edit().putString("subject_color", "4") .apply(); } else if (item == 4) { be.setImageResource(R.drawable.circle_teal); sharedPref.edit().putString("subject_color", "5") .apply(); } else if (item == 5) { be.setImageResource(R.drawable.circle_green); sharedPref.edit().putString("subject_color", "6") .apply(); } else if (item == 6) { be.setImageResource(R.drawable.circle_lime); sharedPref.edit().putString("subject_color", "7") .apply(); } else if (item == 7) { be.setImageResource(R.drawable.circle_yellow); sharedPref.edit().putString("subject_color", "8") .apply(); } else if (item == 8) { be.setImageResource(R.drawable.circle_orange); sharedPref.edit().putString("subject_color", "9") .apply(); } else if (item == 9) { be.setImageResource(R.drawable.circle_brown); sharedPref.edit().putString("subject_color", "10") .apply(); } else if (item == 10) { be.setImageResource(R.drawable.circle_grey); sharedPref.edit().putString("subject_color", "11") .apply(); } } }).show(); } }); android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity()); builder.setTitle(R.string.subjects_edit); builder.setView(dialogView); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Subject_DbAdapter db = new Subject_DbAdapter(getActivity()); db.open(); String inputTitle = titleInput.getText().toString().trim(); String inputTeacher = teacherInput.getText().toString().trim(); String inputRoom = roomInput.getText().toString().trim(); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat( "yy-MM-dd_HH-mm-ss", Locale.getDefault()); String creation = dateFormat.format(date); if (db.isExist(creation)) { Snackbar.make(titleInput, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(inputTitle, inputTeacher, sharedPref.getString("subject_color", creation), inputRoom, helper_main.createDate()); dialog.dismiss(); setSubjectsList(); } } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.support.v7.app.AlertDialog dialog2 = builder.create(); dialog2.show(); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setSubjectsList(); } }); snackbar.show(); } } }).show(); return true; } }); }
From source file:emu.project64.GalleryActivity.java
private void StartGameMenu(boolean ShowSettings) { File InstantSaveDir = new File( NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue())); final File GameSaveDir = new File(InstantSaveDir, NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue())); class Item {/*from w w w .j a va2 s .co m*/ public final String text; public final int icon; public Item(String text, Integer icon) { this.text = text; this.icon = icon; } @Override public String toString() { return text; } } List<Item> menuItemLst = new ArrayList<Item>(); if (ShouldShowSupportWindow()) { menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_lock)); menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_lock)); } else { menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_controller)); menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_play)); } menuItemLst.add(new Item("Restart", R.drawable.ic_refresh)); if (ShowSettings && !NativeExports.SettingsLoadBool(SettingsID.UserInterface_BasicMode.getValue())) { menuItemLst.add(new Item("Settings", R.drawable.ic_sliders)); } Item[] itemsDynamic = new Item[menuItemLst.size()]; itemsDynamic = menuItemLst.toArray(itemsDynamic); final Item[] items = itemsDynamic; final File SaveDir = GameSaveDir; ListAdapter adapter = new ArrayAdapter<Item>(this, android.R.layout.select_dialog_item, android.R.id.text1, items) { public View getView(int position, View convertView, android.view.ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); // Get Drawable icon Drawable d = items[position].icon != 0 ? ResourcesCompat.getDrawable(getResources(), items[position].icon, null) : null; tv.setTextColor(Color.parseColor("#FFFFFF")); if (d != null) { d.setColorFilter(Color.parseColor("#FFFFFF"), android.graphics.PorterDuff.Mode.SRC_ATOP); } if (!isEnabled(position)) { tv.setTextColor(Color.parseColor("#555555")); if (d != null) { d.setColorFilter(Color.parseColor("#555555"), android.graphics.PorterDuff.Mode.SRC_ATOP); } } //Put the image on the TextView tv.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null); //Add margin between image and text (support various screen densities) int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } @Override public boolean areAllItemsEnabled() { return true; } @Override public boolean isEnabled(int position) { if (position == 1 && HasAutoSave(SaveDir) == false) { return false; } if (position == 2 && SaveDir.exists() == false) { return false; } return true; } }; final Context finalContext = this; final Activity finalActivity = this; AlertDialog.Builder GameMenu = new AlertDialog.Builder(finalContext); GameMenu.setTitle(NativeExports.SettingsLoadString(SettingsID.Game_GoodName.getValue())); GameMenu.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if ((item == 0 || item == 1) && ShouldShowSupportWindow()) { ShowSupportWindow(); return; } if (item == 0) { launchGameActivity(); } else if (item == 1) { NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); NativeExports.ExternalEvent(SystemEvent.SysEvent_LoadMachineState.getValue()); launchGameActivity(); } else if (item == 2) { AlertDialog.Builder ResetPrompt = new AlertDialog.Builder(finalContext); ResetPrompt.setTitle(getText(R.string.confirmResetGame_title)) .setMessage(getText(R.string.confirmResetGame_message)) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String[] entries = SaveDir.list(); for (String s : entries) { File currentFile = new File(SaveDir.getPath(), s); currentFile.delete(); } SaveDir.delete(); NativeExports.UISettingsSaveDword(UISettingID.Game_RunCount.getValue(), 0); launchGameActivity(); } }).setNegativeButton(android.R.string.cancel, this).show(); } else if (item == 3) { Intent SettingsIntent = new Intent(finalContext, GameSettingsActivity.class); startActivityForResult(SettingsIntent, RC_SETTINGS); } } }); GameMenu.show(); }
From source file:org.telegram.ui.Components.AudioPlayerAlert.java
public AudioPlayerAlert(final Context context) { super(context, true); MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); if (messageObject != null) { currentAccount = messageObject.currentAccount; } else {//from w w w. j a v a 2 s .co m currentAccount = UserConfig.selectedAccount; } parentActivity = (LaunchActivity) context; noCoverDrawable = context.getResources().getDrawable(R.drawable.nocover).mutate(); noCoverDrawable.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_player_placeholder), PorterDuff.Mode.MULTIPLY)); TAG = DownloadController.getInstance(currentAccount).generateObserverTag(); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStart); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged); NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.musicDidLoad); shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow).mutate(); shadowDrawable.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_player_background), PorterDuff.Mode.MULTIPLY)); paint.setColor(Theme.getColor(Theme.key_player_placeholderBackground)); containerView = new FrameLayout(context) { private boolean ignoreLayout = false; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY && placeholderImageView.getTranslationX() == 0) { dismiss(); return true; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent e) { return !isDismissed() && super.onTouchEvent(e); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); int contentSize = AndroidUtilities.dp(178) + playlist.size() * AndroidUtilities.dp(56) + backgroundPaddingTop + ActionBar.getCurrentActionBarHeight() + AndroidUtilities.statusBarHeight; int padding; heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); if (searching) { padding = AndroidUtilities.dp(178) + ActionBar.getCurrentActionBarHeight() + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0); } else { if (contentSize < height) { padding = height - contentSize; } else { padding = (contentSize < height ? 0 : height - (height / 5 * 3)); } padding += ActionBar.getCurrentActionBarHeight() + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0); } if (listView.getPaddingTop() != padding) { ignoreLayout = true; listView.setPadding(0, padding, 0, AndroidUtilities.dp(8)); ignoreLayout = false; } super.onMeasure(widthMeasureSpec, heightMeasureSpec); inFullSize = getMeasuredHeight() >= height; int availableHeight = height - ActionBar.getCurrentActionBarHeight() - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.dp(120); int maxSize = Math.max(availableHeight, getMeasuredWidth()); thumbMaxX = (getMeasuredWidth() - maxSize) / 2 - AndroidUtilities.dp(17); thumbMaxY = AndroidUtilities.dp(19); panelEndTranslation = getMeasuredHeight() - playerLayout.getMeasuredHeight(); thumbMaxScale = maxSize / (float) placeholderImageView.getMeasuredWidth() - 1.0f; endTranslation = ActionBar.getCurrentActionBarHeight() + AndroidUtilities.dp(5); int scaledHeight = (int) Math .ceil(placeholderImageView.getMeasuredHeight() * (1.0f + thumbMaxScale)); if (scaledHeight > availableHeight) { endTranslation -= (scaledHeight - availableHeight); } } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int y = actionBar.getMeasuredHeight(); shadow.layout(shadow.getLeft(), y, shadow.getRight(), y + shadow.getMeasuredHeight()); updateLayout(); setFullAnimationProgress(fullAnimationProgress); } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override protected void onDraw(Canvas canvas) { shadowDrawable.setBounds(0, Math.max(actionBar.getMeasuredHeight(), scrollOffsetY) - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight()); shadowDrawable.draw(canvas); } }; containerView.setWillNotDraw(false); containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0); actionBar = new ActionBar(context); actionBar.setBackgroundColor(Theme.getColor(Theme.key_player_actionBar)); actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setItemsColor(Theme.getColor(Theme.key_player_actionBarItems), false); actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_player_actionBarSelector), false); actionBar.setTitleColor(Theme.getColor(Theme.key_player_actionBarTitle)); actionBar.setSubtitleColor(Theme.getColor(Theme.key_player_actionBarSubtitle)); actionBar.setAlpha(0.0f); actionBar.setTitle("1"); actionBar.setSubtitle("1"); actionBar.getTitleTextView().setAlpha(0.0f); actionBar.getSubtitleTextView().setAlpha(0.0f); avatarContainer = new ChatAvatarContainer(context, null, false); avatarContainer.setEnabled(false); avatarContainer.setTitleColors(Theme.getColor(Theme.key_player_actionBarTitle), Theme.getColor(Theme.key_player_actionBarSubtitle)); if (messageObject != null) { long did = messageObject.getDialogId(); int lower_id = (int) did; int high_id = (int) (did >> 32); if (lower_id != 0) { if (lower_id > 0) { TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id); if (user != null) { avatarContainer.setTitle(ContactsController.formatName(user.first_name, user.last_name)); avatarContainer.setUserAvatar(user); } } else { TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id); if (chat != null) { avatarContainer.setTitle(chat.title); avatarContainer.setChatAvatar(chat); } } } else { TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount) .getEncryptedChat(high_id); if (encryptedChat != null) { TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id); if (user != null) { avatarContainer.setTitle(ContactsController.formatName(user.first_name, user.last_name)); avatarContainer.setUserAvatar(user); } } } } avatarContainer.setSubtitle(LocaleController.getString("AudioTitle", R.string.AudioTitle)); actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0)); ActionBarMenu menu = actionBar.createMenu(); menuItem = menu.addItem(0, R.drawable.ic_ab_other); menuItem.addSubItem(1, LocaleController.getString("Forward", R.string.Forward)); menuItem.addSubItem(2, LocaleController.getString("ShareFile", R.string.ShareFile)); //menuItem.addSubItem(3, LocaleController.getString("Delete", R.string.Delete)); menuItem.addSubItem(4, LocaleController.getString("ShowInChat", R.string.ShowInChat)); menuItem.setTranslationX(AndroidUtilities.dp(48)); menuItem.setAlpha(0.0f); searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchCollapse() { avatarContainer.setVisibility(View.VISIBLE); if (hasOptions) { menuItem.setVisibility(View.INVISIBLE); } if (searching) { searchWas = false; searching = false; setAllowNestedScroll(true); listAdapter.search(null); } } @Override public void onSearchExpand() { searchOpenPosition = layoutManager.findLastVisibleItemPosition(); View firstVisView = layoutManager.findViewByPosition(searchOpenPosition); searchOpenOffset = ((firstVisView == null) ? 0 : firstVisView.getTop()) - listView.getPaddingTop(); avatarContainer.setVisibility(View.GONE); if (hasOptions) { menuItem.setVisibility(View.GONE); } searching = true; setAllowNestedScroll(false); listAdapter.notifyDataSetChanged(); } @Override public void onTextChanged(EditText editText) { if (editText.length() > 0) { listAdapter.search(editText.getText().toString()); } else { searchWas = false; listAdapter.search(null); } } }); EditTextBoldCursor editText = searchItem.getSearchField(); editText.setHint(LocaleController.getString("Search", R.string.Search)); editText.setTextColor(Theme.getColor(Theme.key_player_actionBarTitle)); editText.setHintTextColor(Theme.getColor(Theme.key_player_time)); editText.setCursorColor(Theme.getColor(Theme.key_player_actionBarTitle)); if (!AndroidUtilities.isTablet()) { actionBar.showActionModeTop(); actionBar.setActionModeTopColor(Theme.getColor(Theme.key_player_actionBarTop)); } actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { dismiss(); } else { onSubItemClick(id); } } }); shadow = new View(context); shadow.setAlpha(0.0f); shadow.setBackgroundResource(R.drawable.header_shadow); shadow2 = new View(context); shadow2.setAlpha(0.0f); shadow2.setBackgroundResource(R.drawable.header_shadow); playerLayout = new FrameLayout(context); playerLayout.setBackgroundColor(Theme.getColor(Theme.key_player_background)); placeholderImageView = new BackupImageView(context) { private RectF rect = new RectF(); @Override protected void onDraw(Canvas canvas) { if (hasNoCover == 1 || hasNoCover == 2 && (!getImageReceiver().hasBitmapImage() || getImageReceiver().getCurrentAlpha() != 1.0f)) { rect.set(0, 0, getMeasuredWidth(), getMeasuredHeight()); canvas.drawRoundRect(rect, getRoundRadius(), getRoundRadius(), paint); float plusScale = thumbMaxScale / getScaleX() / 3; int s = (int) (AndroidUtilities.dp(63) * Math.max(plusScale / thumbMaxScale, 1.0f / thumbMaxScale)); int x = (int) (rect.centerX() - s / 2); int y = (int) (rect.centerY() - s / 2); noCoverDrawable.setBounds(x, y, x + s, y + s); noCoverDrawable.draw(canvas); } if (hasNoCover != 1) { super.onDraw(canvas); } } }; placeholderImageView.setRoundRadius(AndroidUtilities.dp(20)); placeholderImageView.setPivotX(0); placeholderImageView.setPivotY(0); placeholderImageView.setOnClickListener(view -> { if (animatorSet != null) { animatorSet.cancel(); animatorSet = null; } animatorSet = new AnimatorSet(); if (scrollOffsetY <= actionBar.getMeasuredHeight()) { animatorSet.playTogether(ObjectAnimator.ofFloat(AudioPlayerAlert.this, "fullAnimationProgress", isInFullMode ? 0.0f : 1.0f)); } else { animatorSet.playTogether( ObjectAnimator.ofFloat(AudioPlayerAlert.this, "fullAnimationProgress", isInFullMode ? 0.0f : 1.0f), ObjectAnimator.ofFloat(actionBar, "alpha", isInFullMode ? 0.0f : 1.0f), ObjectAnimator.ofFloat(shadow, "alpha", isInFullMode ? 0.0f : 1.0f), ObjectAnimator.ofFloat(shadow2, "alpha", isInFullMode ? 0.0f : 1.0f)); } animatorSet.setInterpolator(new DecelerateInterpolator()); animatorSet.setDuration(250); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (animation.equals(animatorSet)) { if (!isInFullMode) { listView.setScrollEnabled(true); if (hasOptions) { menuItem.setVisibility(View.INVISIBLE); } searchItem.setVisibility(View.VISIBLE); } else { if (hasOptions) { menuItem.setVisibility(View.VISIBLE); } searchItem.setVisibility(View.INVISIBLE); } animatorSet = null; } } }); animatorSet.start(); if (hasOptions) { menuItem.setVisibility(View.VISIBLE); } searchItem.setVisibility(View.VISIBLE); isInFullMode = !isInFullMode; listView.setScrollEnabled(false); if (isInFullMode) { shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(20 + 48)); } else { shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(10)); } }); titleTextView = new TextView(context); titleTextView.setTextColor(Theme.getColor(Theme.key_player_actionBarTitle)); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); titleTextView.setEllipsize(TextUtils.TruncateAt.END); titleTextView.setSingleLine(true); playerLayout.addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 72, 18, 60, 0)); authorTextView = new TextView(context); authorTextView.setTextColor(Theme.getColor(Theme.key_player_time)); authorTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); authorTextView.setEllipsize(TextUtils.TruncateAt.END); authorTextView.setSingleLine(true); playerLayout.addView(authorTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 72, 40, 60, 0)); optionsButton = new ActionBarMenuItem(context, null, 0, Theme.getColor(Theme.key_player_actionBarItems)); optionsButton.setLongClickEnabled(false); optionsButton.setIcon(R.drawable.ic_ab_other); optionsButton.setAdditionalOffset(-AndroidUtilities.dp(120)); playerLayout.addView(optionsButton, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.RIGHT, 0, 19, 10, 0)); optionsButton.addSubItem(1, LocaleController.getString("Forward", R.string.Forward)); optionsButton.addSubItem(2, LocaleController.getString("ShareFile", R.string.ShareFile)); //optionsButton.addSubItem(3, LocaleController.getString("Delete", R.string.Delete)); optionsButton.addSubItem(4, LocaleController.getString("ShowInChat", R.string.ShowInChat)); optionsButton.setOnClickListener(v -> optionsButton.toggleSubMenu()); optionsButton.setDelegate(this::onSubItemClick); seekBarView = new SeekBarView(context); seekBarView.setDelegate(progress -> MediaController.getInstance() .seekToProgress(MediaController.getInstance().getPlayingMessageObject(), progress)); playerLayout.addView(seekBarView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 30, Gravity.TOP | Gravity.LEFT, 8, 62, 8, 0)); progressView = new LineProgressView(context); progressView.setVisibility(View.INVISIBLE); progressView.setBackgroundColor(Theme.getColor(Theme.key_player_progressBackground)); progressView.setProgressColor(Theme.getColor(Theme.key_player_progress)); playerLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 2, Gravity.TOP | Gravity.LEFT, 20, 78, 20, 0)); timeTextView = new SimpleTextView(context); timeTextView.setTextSize(12); timeTextView.setText("0:00"); timeTextView.setTextColor(Theme.getColor(Theme.key_player_time)); playerLayout.addView(timeTextView, LayoutHelper.createFrame(100, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 20, 92, 0, 0)); durationTextView = new TextView(context); durationTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); durationTextView.setTextColor(Theme.getColor(Theme.key_player_time)); durationTextView.setGravity(Gravity.CENTER); playerLayout.addView(durationTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT, 0, 90, 20, 0)); FrameLayout bottomView = new FrameLayout(context) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int dist = ((right - left) - AndroidUtilities.dp(8 + 48 * 5)) / 4; for (int a = 0; a < 5; a++) { int l = AndroidUtilities.dp(4 + 48 * a) + dist * a; int t = AndroidUtilities.dp(9); buttons[a].layout(l, t, l + buttons[a].getMeasuredWidth(), t + buttons[a].getMeasuredHeight()); } } }; playerLayout.addView(bottomView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 66, Gravity.TOP | Gravity.LEFT, 0, 106, 0, 0)); buttons[0] = shuffleButton = new ActionBarMenuItem(context, null, 0, 0); shuffleButton.setLongClickEnabled(false); shuffleButton.setAdditionalOffset(-AndroidUtilities.dp(10)); bottomView.addView(shuffleButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); shuffleButton.setOnClickListener(v -> shuffleButton.toggleSubMenu()); TextView textView = shuffleButton.addSubItem(1, LocaleController.getString("ReverseOrder", R.string.ReverseOrder)); textView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(16), 0); playOrderButtons[0] = context.getResources().getDrawable(R.drawable.music_reverse).mutate(); textView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); textView.setCompoundDrawablesWithIntrinsicBounds(playOrderButtons[0], null, null, null); textView = shuffleButton.addSubItem(2, LocaleController.getString("Shuffle", R.string.Shuffle)); textView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(16), 0); playOrderButtons[1] = context.getResources().getDrawable(R.drawable.pl_shuffle).mutate(); textView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); textView.setCompoundDrawablesWithIntrinsicBounds(playOrderButtons[1], null, null, null); shuffleButton.setDelegate(id -> { MediaController.getInstance().toggleShuffleMusic(id); updateShuffleButton(); listAdapter.notifyDataSetChanged(); }); ImageView prevButton; buttons[1] = prevButton = new ImageView(context); prevButton.setScaleType(ImageView.ScaleType.CENTER); prevButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_previous, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive))); bottomView.addView(prevButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); prevButton.setOnClickListener(v -> MediaController.getInstance().playPreviousMessage()); buttons[2] = playButton = new ImageView(context); playButton.setScaleType(ImageView.ScaleType.CENTER); playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_play, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive))); bottomView.addView(playButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); playButton.setOnClickListener(v -> { if (MediaController.getInstance().isDownloadingCurrentMessage()) { return; } if (MediaController.getInstance().isMessagePaused()) { MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject()); } else { MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject()); } }); ImageView nextButton; buttons[3] = nextButton = new ImageView(context); nextButton.setScaleType(ImageView.ScaleType.CENTER); nextButton.setImageDrawable(Theme.createSimpleSelectorDrawable(context, R.drawable.pl_next, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive))); bottomView.addView(nextButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); nextButton.setOnClickListener(v -> MediaController.getInstance().playNextMessage()); buttons[4] = repeatButton = new ImageView(context); repeatButton.setScaleType(ImageView.ScaleType.CENTER); repeatButton.setPadding(0, 0, AndroidUtilities.dp(8), 0); bottomView.addView(repeatButton, LayoutHelper.createFrame(50, 48, Gravity.LEFT | Gravity.TOP)); repeatButton.setOnClickListener(v -> { SharedConfig.toggleRepeatMode(); updateRepeatButton(); }); listView = new RecyclerListView(context) { boolean ignoreLayout; @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (searchOpenPosition != -1 && !actionBar.isSearchFieldVisible()) { ignoreLayout = true; layoutManager.scrollToPositionWithOffset(searchOpenPosition, searchOpenOffset); super.onLayout(false, l, t, r, b); ignoreLayout = false; searchOpenPosition = -1; } else if (scrollToSong) { scrollToSong = false; boolean found = false; MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject(); if (playingMessageObject != null) { int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof AudioPlayerCell) { if (((AudioPlayerCell) child).getMessageObject() == playingMessageObject) { if (child.getBottom() <= getMeasuredHeight()) { found = true; } break; } } } if (!found) { int idx = playlist.indexOf(playingMessageObject); if (idx >= 0) { ignoreLayout = true; if (SharedConfig.playOrderReversed) { layoutManager.scrollToPosition(idx); } else { layoutManager.scrollToPosition(playlist.size() - idx); } super.onLayout(false, l, t, r, b); ignoreLayout = false; } } } } } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override protected boolean allowSelectChildAtPosition(float x, float y) { float p = playerLayout.getY() + playerLayout.getMeasuredHeight(); return playerLayout == null || y > playerLayout.getY() + playerLayout.getMeasuredHeight(); } @Override public boolean drawChild(Canvas canvas, View child, long drawingTime) { canvas.save(); canvas.clipRect(0, (actionBar != null ? actionBar.getMeasuredHeight() : 0) + AndroidUtilities.dp(50), getMeasuredWidth(), getMeasuredHeight()); boolean result = super.drawChild(canvas, child, drawingTime); canvas.restore(); return result; } }; listView.setPadding(0, 0, 0, AndroidUtilities.dp(8)); listView.setClipToPadding(false); listView.setLayoutManager( layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); listView.setHorizontalScrollBarEnabled(false); listView.setVerticalScrollBarEnabled(false); containerView.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); listView.setAdapter(listAdapter = new ListAdapter(context)); listView.setGlowColor(Theme.getColor(Theme.key_dialogScrollGlow)); listView.setOnItemClickListener((view, position) -> { if (view instanceof AudioPlayerCell) { ((AudioPlayerCell) view).didPressedButton(); } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) { AndroidUtilities.hideKeyboard(getCurrentFocus()); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { updateLayout(); } }); playlist = MediaController.getInstance().getPlaylist(); listAdapter.notifyDataSetChanged(); containerView.addView(playerLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 178)); containerView.addView(shadow2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3)); containerView.addView(placeholderImageView, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.LEFT, 17, 19, 0, 0)); containerView.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3)); containerView.addView(actionBar); updateTitle(false); updateRepeatButton(); updateShuffleButton(); }
From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java
/** * Helper function to add links from mVoteTargetThing to the button * @param linkButton Button that should open list of links *///from w w w .j av a 2 s. c o m private void linkToEmbeddedURLs(Button linkButton) { final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<MarkdownURL> vtUrls = mVoteTargetThing.getUrls(); int urlsCount = vtUrls.size(); for (int i = 0; i < urlsCount; i++) { urls.add(vtUrls.get(i).url); } if (urlsCount == 0) { linkButton.setEnabled(false); } else { linkButton.setEnabled(true); linkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { removeDialog(Constants.DIALOG_COMMENT_CLICK); ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(CommentsListActivity.this, android.R.layout.select_dialog_item, vtUrls) { public View getView(int position, View convertView, ViewGroup parent) { TextView tv; if (convertView == null) { tv = (TextView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(android.R.layout.select_dialog_item, null); } else { tv = (TextView) convertView; } String url = getItem(position).url; String anchorText = getItem(position).anchorText; if (Constants.LOGGING) Log.d(TAG, "links url=" + url + " anchorText=" + anchorText); Drawable d = null; try { d = getPackageManager() .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (NameNotFoundException ignore) { } if (d != null) { d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight()); tv.setCompoundDrawablePadding(10); tv.setCompoundDrawables(d, null, null, null); } final String telPrefix = "tel:"; if (url.startsWith(telPrefix)) { url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length())); } if (anchorText != null) tv.setText(Html.fromHtml( "<span>" + anchorText + "</span><br /><small>" + url + "</small>")); else tv.setText(Html.fromHtml(url)); return tv; } }; AlertDialog.Builder b = new AlertDialog.Builder( new ContextThemeWrapper(CommentsListActivity.this, mSettings.getDialogTheme())); DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { if (which >= 0) { Common.launchBrowser(CommentsListActivity.this, urls.get(which), Util.createThreadUri(getOpThingInfo()).toString(), false, false, mSettings.isUseExternalBrowser(), mSettings.isSaveHistory()); } } }; b.setTitle(R.string.select_link_title); b.setCancelable(true); b.setAdapter(adapter, click); b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); b.show(); } }); } }
From source file:de.baumann.hhsmoodle.data_count.Count_Fragment.java
public void setCountList() { if (isFABOpen) { closeFABMenu();//ww w. j av a 2s . com } //display data final int layoutstyle = R.layout.list_item_notes; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "count_title", "count_content", "count_creation" }; final Cursor row = db.fetchAllData(getActivity()); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String count_title = row2.getString(row2.getColumnIndexOrThrow("count_title")); final String count_content = row2.getString(row2.getColumnIndexOrThrow("count_content")); final String count_icon = row2.getString(row2.getColumnIndexOrThrow("count_icon")); final String count_attachment = row2.getString(row2.getColumnIndexOrThrow("count_attachment")); final String count_creation = row2.getString(row2.getColumnIndexOrThrow("count_creation")); View v = super.getView(position, convertView, parent); final TextView tv = (TextView) v.findViewById(R.id.text); if (count_attachment.isEmpty()) { tv.setText(count_content); new Handler().postDelayed(new Runnable() { public void run() { int n = tv.getLineCount(); StringBuilder sb = new StringBuilder(n); for (int i = 0; i < n; ++i) { sb.append("0" + '\n'); } String result = sb.toString(); db.update(Integer.parseInt(_id), count_title, count_content, count_icon, result, count_creation); setCountList(); } }, 500); } ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); helper_main.switchIcon(getActivity(), count_icon, "count_icon", iv_icon); iv_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green), new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { db.update(Integer.parseInt(_id), count_title, count_content, "3", count_attachment, count_creation); setCountList(); } else if (item == 1) { db.update(Integer.parseInt(_id), count_title, count_content, "2", count_attachment, count_creation); setCountList(); } else if (item == 2) { db.update(Integer.parseInt(_id), count_title, count_content, "1", count_attachment, count_creation); setCountList(); } } }).show(); } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_countBY", "note_title"); sharedPref.edit().putString("filter_countBY", "note_title").apply(); filter.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { if (isFABOpen) { closeFABMenu(); } Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String count_title = row2.getString(row2.getColumnIndexOrThrow("count_title")); final String count_content = row2.getString(row2.getColumnIndexOrThrow("count_content")); final String count_icon = row2.getString(row2.getColumnIndexOrThrow("count_icon")); final String count_attachment = row2.getString(row2.getColumnIndexOrThrow("count_attachment")); final String count_creation = row2.getString(row2.getColumnIndexOrThrow("count_creation")); sharedPref.edit().putString("count_title", count_title).apply(); sharedPref.edit().putString("count_content", count_content).apply(); sharedPref.edit().putString("count_seqno", _id).apply(); sharedPref.edit().putString("count_icon", count_icon).apply(); sharedPref.edit().putString("count_create", count_creation).apply(); sharedPref.edit().putString("count_attachment", count_attachment).apply(); helper_main.switchToActivity(getActivity(), Activity_count.class, false); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (isFABOpen) { closeFABMenu(); } Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String count_title = row2.getString(row2.getColumnIndexOrThrow("count_title")); final String count_content = row2.getString(row2.getColumnIndexOrThrow("count_content")); final String count_icon = row2.getString(row2.getColumnIndexOrThrow("count_icon")); final String count_attachment = row2.getString(row2.getColumnIndexOrThrow("count_attachment")); final String count_creation = row2.getString(row2.getColumnIndexOrThrow("count_creation")); final CharSequence[] options = { getString(R.string.number_edit_entry), getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_share), getString(R.string.bookmark_createNote), getString(R.string.bookmark_createEvent) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.number_edit_entry))) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setHint(R.string.bookmark_edit_title); edit_title.setText(count_title); builder.setView(dialogView); builder.setTitle(R.string.bookmark_edit_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); db.update(Integer.parseInt(_id), inputTag, count_content, count_icon, count_attachment, count_creation); setCountList(); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(getActivity(), edit_title); } if (options[item].equals(getString(R.string.todo_share))) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, count_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, count_content); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.note_share_2)))); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), count_title, count_content); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setCountList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.bookmark_createNote))) { Notes_helper.newNote(getActivity(), count_title, count_content, "", "", "", ""); } } }).show(); return true; } }); }
From source file:org.telegram.ui.ChatActivity.java
private void updateSubtitle() { if (isFinish) { return;/*from ww w .j a va 2s . c o m*/ } if (paused || getActivity() == null) { return; } ActionBar actionBar = parentActivity.getSupportActionBar(); TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title); if (title == null) { final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); title = (TextView) parentActivity.findViewById(subtitleId); } if (currentChat != null) { actionBar.setTitle(currentChat.title); if (title != null) { title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); title.setCompoundDrawablePadding(0); } } else if (currentUser != null) { if (currentUser.id != 333000 && ContactsController.Instance.contactsDict.get(currentUser.id) == null && (ContactsController.Instance.contactsDict.size() != 0 || !ContactsController.Instance.loadingContacts)) { if (currentUser.phone != null && currentUser.phone.length() != 0) { actionBar.setTitle(PhoneFormat.Instance.format("+" + currentUser.phone)); } else { actionBar.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name)); } } else { actionBar.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name)); } if (title != null) { if (currentEncryptedChat != null) { title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0); title.setCompoundDrawablePadding(Utilities.dp(4)); } else { title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); title.setCompoundDrawablePadding(0); } } } CharSequence printString = MessagesController.Instance.printingStrings.get(dialog_id); if (printString == null || printString.length() == 0) { lastPrintString = null; setTypingAnimation(false); if (currentChat != null) { if (currentChat instanceof TLRPC.TL_chatForbidden) { actionBar.setSubtitle(getStringEntry(R.string.YouWereKicked)); } else if (currentChat.left) { actionBar.setSubtitle(getStringEntry(R.string.YouLeft)); } else { if (onlineCount > 0 && currentChat.participants_count != 0) { actionBar.setSubtitle(String.format("%d %s, %d %s", currentChat.participants_count, getStringEntry(R.string.Members), onlineCount, getStringEntry(R.string.Online))); } else { actionBar.setSubtitle(String.format("%d %s", currentChat.participants_count, getStringEntry(R.string.Members))); } } } else if (currentUser != null) { if (currentUser.status == null) { actionBar.setSubtitle(getStringEntry(R.string.Offline)); } else { int currentTime = ConnectionsManager.Instance.getCurrentTime(); if (currentUser.status.expires > currentTime || currentUser.status.was_online > currentTime) { actionBar.setSubtitle(getStringEntry(R.string.Online)); } else { if (currentUser.status.was_online <= 10000 && currentUser.status.expires <= 10000) { actionBar.setSubtitle(getStringEntry(R.string.Invisible)); } else { int value = currentUser.status.was_online; if (value == 0) { value = currentUser.status.expires; } actionBar.setSubtitle(Utilities.formatDateOnline(value)); } } } } } else { lastPrintString = printString; actionBar.setSubtitle(printString); setTypingAnimation(true); } }
From source file:org.telegram.ui.ChatActivity.java
private void fixLayout() { if (chatListView != null) { ViewTreeObserver obs = chatListView.getViewTreeObserver(); obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override/*w w w . java 2 s .c o m*/ public boolean onPreDraw() { if (parentActivity == null) { chatListView.getViewTreeObserver().removeOnPreDrawListener(this); return false; } WindowManager manager = (WindowManager) ApplicationLoader.applicationContext .getSystemService(Activity.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int rotation = display.getRotation(); int height; int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight(); if (currentActionBarHeight != Utilities.dp(48) && currentActionBarHeight != Utilities.dp(40)) { height = currentActionBarHeight; } else { height = Utilities.dp(48); if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) { height = Utilities.dp(40); } } if (avatarImageView != null) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) avatarImageView .getLayoutParams(); params.width = height; params.height = height; avatarImageView.setLayoutParams(params); } chatListView.getViewTreeObserver().removeOnPreDrawListener(this); if (currentEncryptedChat != null) { TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title); if (title == null) { final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); title = (TextView) parentActivity.findViewById(subtitleId); } if (title != null) { title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0); title.setCompoundDrawablePadding(Utilities.dp(4)); } } return false; } }); } }