use of android.support.v4.app.NotificationCompat.Builder in project XPrivacy by M66B.
the class UpdateService method notifyProgress.
private static void notifyProgress(Context context, int id, String format, int percentage) {
String message = String.format(format, String.format("%d %%", percentage));
Util.log(null, Log.WARN, message);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle(context.getString(R.string.app_name));
builder.setContentText(message);
builder.setWhen(System.currentTimeMillis());
builder.setAutoCancel(percentage == 100);
builder.setOngoing(percentage < 100);
Notification notification = builder.build();
notificationManager.notify(id, notification);
}
use of android.support.v4.app.NotificationCompat.Builder in project XPrivacy by M66B.
the class UpdateService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Check if work
if (intent == null) {
stopSelf();
return 0;
}
// Flush
if (cFlush.equals(intent.getAction())) {
try {
PrivacyService.getClient().flush();
XApplication.manage(this, 0, XApplication.cActionFlush);
} catch (Throwable ex) {
Util.bug(null, ex);
}
stopSelf();
return 0;
}
// Update
if (cUpdate.equals(intent.getAction())) {
if (Util.hasProLicense(this) != null) {
int userId = Util.getUserId(Process.myUid());
boolean updates = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingUpdates, false);
if (updates)
new ActivityShare.UpdateTask(this).execute();
}
stopSelf();
return 0;
}
// Check action
Bundle extras = intent.getExtras();
if (extras.containsKey(cAction)) {
final int action = extras.getInt(cAction);
Util.log(null, Log.WARN, "Service received action=" + action + " flags=" + flags);
// Check service
if (PrivacyService.getClient() == null) {
Util.log(null, Log.ERROR, "Service not available");
stopSelf();
return 0;
}
// Start foreground service
NotificationCompat.Builder builder = new NotificationCompat.Builder(UpdateService.this);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle(getString(R.string.app_name));
builder.setContentText(getString(R.string.msg_service));
builder.setWhen(System.currentTimeMillis());
builder.setAutoCancel(false);
builder.setOngoing(true);
Notification notification = builder.build();
startForeground(Util.NOTIFY_SERVICE, notification);
// Start worker
mWorkerThread = new Thread(new Runnable() {
@Override
public void run() {
try {
// Check action
if (action == cActionBoot) {
// Boot received
migrate(UpdateService.this);
upgrade(UpdateService.this);
randomize(UpdateService.this);
} else if (action == cActionUpdated) {
// Self updated
upgrade(UpdateService.this);
} else
Util.log(null, Log.ERROR, "Unknown action=" + action);
// Done
stopForeground(true);
stopSelf();
} catch (Throwable ex) {
Util.bug(null, ex);
// Leave service running
}
}
});
mWorkerThread.start();
} else
Util.log(null, Log.ERROR, "Action missing");
return START_STICKY;
}
use of android.support.v4.app.NotificationCompat.Builder in project remusic by aa112901.
the class MediaService method getNotification.
private Notification getNotification() {
RemoteViews remoteViews;
final int PAUSE_FLAG = 0x1;
final int NEXT_FLAG = 0x2;
final int STOP_FLAG = 0x3;
final String albumName = getAlbumName();
final String artistName = getArtistName();
final boolean isPlaying = isPlaying();
remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification);
String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;
remoteViews.setTextViewText(R.id.title, getTrackName());
remoteViews.setTextViewText(R.id.text, text);
//此处action不能是一样的 如果一样的 接受的flag参数只是第一个设置的值
Intent pauseIntent = new Intent(TOGGLEPAUSE_ACTION);
pauseIntent.putExtra("FLAG", PAUSE_FLAG);
PendingIntent pausePIntent = PendingIntent.getBroadcast(this, 0, pauseIntent, 0);
remoteViews.setImageViewResource(R.id.iv_pause, isPlaying ? R.drawable.note_btn_pause : R.drawable.note_btn_play);
remoteViews.setOnClickPendingIntent(R.id.iv_pause, pausePIntent);
Intent nextIntent = new Intent(NEXT_ACTION);
nextIntent.putExtra("FLAG", NEXT_FLAG);
PendingIntent nextPIntent = PendingIntent.getBroadcast(this, 0, nextIntent, 0);
remoteViews.setOnClickPendingIntent(R.id.iv_next, nextPIntent);
Intent preIntent = new Intent(STOP_ACTION);
preIntent.putExtra("FLAG", STOP_FLAG);
PendingIntent prePIntent = PendingIntent.getBroadcast(this, 0, preIntent, 0);
remoteViews.setOnClickPendingIntent(R.id.iv_stop, prePIntent);
// PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0,
// new Intent(this.getApplicationContext(), PlayingActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
final Intent nowPlayingIntent = new Intent();
//nowPlayingIntent.setAction("com.wm.remusic.LAUNCH_NOW_PLAYING_ACTION");
nowPlayingIntent.setComponent(new ComponentName("com.wm.remusic", "com.wm.remusic.activity.PlayingActivity"));
nowPlayingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent clickIntent = PendingIntent.getBroadcast(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent click = PendingIntent.getActivity(this, 0, nowPlayingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
final Bitmap bitmap = ImageUtils.getArtworkQuick(this, getAlbumId(), 160, 160);
if (bitmap != null) {
remoteViews.setImageViewBitmap(R.id.image, bitmap);
// remoteViews.setImageViewUri(R.id.image, MusicUtils.getAlbumUri(this, getAudioId()));
mNoBit = null;
} else if (!isTrackLocal()) {
if (mNoBit != null) {
remoteViews.setImageViewBitmap(R.id.image, mNoBit);
mNoBit = null;
} else {
Uri uri = null;
if (getAlbumPath() != null) {
try {
uri = Uri.parse(getAlbumPath());
} catch (Exception e) {
e.printStackTrace();
}
}
if (getAlbumPath() == null || uri == null) {
mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
updateNotification();
} else {
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri).setProgressiveRenderingEnabled(true).build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, MediaService.this);
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
// No need to do any cleanup.
if (bitmap != null) {
mNoBit = bitmap;
}
updateNotification();
}
@Override
public void onFailureImpl(DataSource dataSource) {
// No cleanup required here.
mNoBit = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210);
updateNotification();
}
}, CallerThreadExecutor.getInstance());
}
}
} else {
remoteViews.setImageViewResource(R.id.image, R.drawable.placeholder_disk_210);
}
if (mNotificationPostTime == 0) {
mNotificationPostTime = System.currentTimeMillis();
}
if (mNotification == null) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(remoteViews).setSmallIcon(R.drawable.ic_notification).setContentIntent(click).setWhen(mNotificationPostTime);
if (CommonUtils.isJellyBeanMR1()) {
builder.setShowWhen(false);
}
mNotification = builder.build();
} else {
mNotification.contentView = remoteViews;
}
return mNotification;
}
use of android.support.v4.app.NotificationCompat.Builder in project actor-platform by actorapp.
the class CallFragment method onPause.
@Override
public void onPause() {
super.onPause();
disableWakeLock();
if (peer.getPeerType() == PeerType.PRIVATE) {
if (localTrack != null) {
localTrack.removeRenderer(localRender);
localRender.dispose();
localRender = null;
localTrack = null;
}
if (isLocalViewConfigured) {
localVideoView.release();
isLocalViewConfigured = false;
}
if (remoteTrack != null) {
remoteTrack.removeRenderer(remoteRender);
remoteRender.dispose();
remoteRender = null;
remoteTrack = null;
}
if (isRemoteViewConfigured) {
remoteVideoView.release();
isRemoteViewConfigured = false;
}
}
//
// Unbind call streams
//
ACTIVITY_BINDER.unbindAll();
//
if (call != null && call.getState().get() != CallState.ENDED) {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity());
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.ic_app_notify);
builder.setPriority(NotificationCompat.PRIORITY_MAX);
builder.setContentTitle(getActivity().getString(R.string.call_notification));
Intent intent = new Intent(getActivity(), CallActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("callId", callId);
builder.setContentIntent(PendingIntent.getActivity(getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
Notification n = builder.build();
n.flags += Notification.FLAG_ONGOING_EVENT;
manager.notify(NOTIFICATION_ID, n);
}
}
use of android.support.v4.app.NotificationCompat.Builder in project actor-platform by actorapp.
the class ProfileFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
uid = getArguments().getInt(EXTRA_UID);
final UserVM user = users().get(uid);
ArrayList<UserPhone> phones = user.getPhones().get();
ArrayList<UserEmail> emails = user.getEmails().get();
String about = user.getAbout().get();
final String userName = user.getNick().get();
final View res = inflater.inflate(R.layout.fragment_profile, container, false);
//
// Style Background
//
res.findViewById(R.id.container).setBackgroundColor(style.getMainBackgroundColor());
res.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
//
// User Avatar
//
avatarView = (AvatarView) res.findViewById(R.id.avatar);
avatarView.init(Screen.dp(48), 22);
avatarView.bind(user.getAvatar().get(), user.getName().get(), user.getId());
avatarView.setOnClickListener(v -> {
startActivity(ViewAvatarActivity.viewAvatar(user.getId(), getActivity()));
});
//
// User Name
//
TextView nameText = (TextView) res.findViewById(R.id.name);
nameText.setTextColor(style.getProfileTitleColor());
bind(nameText, user.getName());
//
// User Last Seen
//
TextView lastSeen = (TextView) res.findViewById(R.id.lastSeen);
lastSeen.setTextColor(style.getProfileSubtitleColor());
bind(lastSeen, user);
//
// Fab
//
FloatingActionButton fab = (FloatingActionButton) res.findViewById(R.id.fab);
fab.setBackgroundTintList(new ColorStateList(new int[][] { new int[] { android.R.attr.state_pressed }, StateSet.WILD_CARD }, new int[] { ActorSDK.sharedActor().style.getFabPressedColor(), ActorSDK.sharedActor().style.getFabColor() }));
fab.setRippleColor(ActorSDK.sharedActor().style.getFabPressedColor());
fab.setOnClickListener(v -> startActivity(new Intent(getActivity(), ComposeActivity.class)));
//
// Remove Contact
//
final View removeContact = res.findViewById(R.id.addContact);
final TextView addContactTitle = (TextView) removeContact.findViewById(R.id.addContactTitle);
addContactTitle.setText(getString(R.string.profile_contacts_added));
addContactTitle.setTextColor(style.getTextPrimaryColor());
removeContact.setOnClickListener(v -> {
execute(ActorSDK.sharedActor().getMessenger().removeContact(user.getId()));
});
bind(user.isContact(), (isContact, valueModel) -> {
if (isContact) {
removeContact.setVisibility(View.VISIBLE);
//fab
fab.setImageResource(R.drawable.ic_message_white_24dp);
fab.setOnClickListener(view -> startActivity(Intents.openPrivateDialog(user.getId(), true, getActivity())));
} else {
removeContact.setVisibility(View.GONE);
//fab
fab.setImageResource(R.drawable.ic_person_add_white_24dp);
fab.setOnClickListener(view -> execute(ActorSDK.sharedActor().getMessenger().addContact(user.getId())));
}
});
//
// New Message
//
View newMessageView = res.findViewById(R.id.newMessage);
ImageView newMessageIcon = (ImageView) newMessageView.findViewById(R.id.newMessageIcon);
TextView newMessageTitle = (TextView) newMessageView.findViewById(R.id.newMessageText);
{
Drawable drawable = getResources().getDrawable(R.drawable.ic_chat_black_24dp);
drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
newMessageIcon.setImageDrawable(drawable);
newMessageTitle.setTextColor(style.getTextPrimaryColor());
}
newMessageView.setOnClickListener(v -> {
startActivity(Intents.openPrivateDialog(user.getId(), true, getActivity()));
});
//
// Voice Call
//
View voiceCallDivider = res.findViewById(R.id.voiceCallDivider);
View voiceCallView = res.findViewById(R.id.voiceCall);
if (ActorSDK.sharedActor().isCallsEnabled() && !user.isBot()) {
ImageView voiceViewIcon = (ImageView) voiceCallView.findViewById(R.id.actionIcon);
TextView voiceViewTitle = (TextView) voiceCallView.findViewById(R.id.actionText);
Drawable drawable = getResources().getDrawable(R.drawable.ic_phone_white_24dp);
drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
voiceViewIcon.setImageDrawable(drawable);
voiceViewTitle.setTextColor(style.getTextPrimaryColor());
voiceCallView.setOnClickListener(v -> {
execute(ActorSDK.sharedActor().getMessenger().doCall(user.getId()));
});
} else {
voiceCallView.setVisibility(View.GONE);
voiceCallDivider.setVisibility(View.GONE);
}
//
// Video Call
//
View videoCallDivider = res.findViewById(R.id.videoCallDivider);
View videoCallView = res.findViewById(R.id.videoCall);
if (ActorSDK.sharedActor().isCallsEnabled() && !user.isBot()) {
ImageView voiceViewIcon = (ImageView) videoCallView.findViewById(R.id.videoCallIcon);
TextView voiceViewTitle = (TextView) videoCallView.findViewById(R.id.videoCallText);
Drawable drawable = getResources().getDrawable(R.drawable.ic_videocam_white_24dp);
drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
voiceViewIcon.setImageDrawable(drawable);
voiceViewTitle.setTextColor(style.getTextPrimaryColor());
videoCallView.setOnClickListener(v -> {
execute(ActorSDK.sharedActor().getMessenger().doVideoCall(user.getId()));
});
} else {
videoCallView.setVisibility(View.GONE);
videoCallDivider.setVisibility(View.GONE);
}
//
// Contact Information
//
final LinearLayout contactsContainer = (LinearLayout) res.findViewById(R.id.contactsContainer);
String aboutString = user.getAbout().get();
boolean isFirstContact = aboutString == null || aboutString.isEmpty();
//
// About
//
bind(user.getAbout(), new ValueChangedListener<String>() {
private View userAboutRecord;
@Override
public void onChanged(final String newUserAbout, Value<String> valueModel) {
if (newUserAbout != null && newUserAbout.length() > 0) {
if (userAboutRecord == null) {
userAboutRecord = buildRecordBig(newUserAbout, R.drawable.ic_info_outline_black_24dp, true, false, inflater, contactsContainer);
} else {
((TextView) userAboutRecord.findViewById(R.id.value)).setText(newUserAbout);
}
if (recordFieldWithIcon != null) {
recordFieldWithIcon.findViewById(R.id.recordIcon).setVisibility(View.INVISIBLE);
}
}
}
});
if (!ActorSDK.sharedActor().isOnClientPrivacyEnabled() || user.isInPhoneBook().get()) {
for (int i = 0; i < phones.size(); i++) {
final UserPhone userPhone = phones.get(i);
// Formatting Phone Number
String _phoneNumber;
try {
Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + userPhone.getPhone(), "us");
_phoneNumber = PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
} catch (NumberParseException e) {
e.printStackTrace();
_phoneNumber = "+" + userPhone.getPhone();
}
final String phoneNumber = _phoneNumber;
String phoneTitle = userPhone.getTitle();
// Trying to localize this
if (phoneTitle.toLowerCase().equals("mobile phone")) {
phoneTitle = getString(R.string.settings_mobile_phone);
}
View view = buildRecord(phoneTitle, phoneNumber, R.drawable.ic_import_contacts_black_24dp, isFirstContact, false, inflater, contactsContainer);
if (isFirstContact) {
recordFieldWithIcon = view;
}
view.setOnClickListener(v -> {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.phone_menu_call).replace("{0}", phoneNumber), getString(R.string.phone_menu_sms).replace("{0}", phoneNumber), getString(R.string.phone_menu_share).replace("{0}", phoneNumber), getString(R.string.phone_menu_copy) }, (dialog, which) -> {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_DIAL).setData(Uri.parse("tel:+" + userPhone.getPhone())));
} else if (which == 1) {
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("sms:+" + userPhone.getPhone())));
} else if (which == 2) {
startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text).replace("{0}", phoneNumber).replace("{1}", user.getName().get())));
} else if (which == 3) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", phoneNumber);
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_phone_copied, Snackbar.LENGTH_SHORT).show();
}
}).show().setCanceledOnTouchOutside(true);
});
view.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Phone number", "+" + userPhone.getPhone());
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_phone_copied, Snackbar.LENGTH_SHORT).show();
return true;
});
isFirstContact = false;
}
for (int i = 0; i < emails.size(); i++) {
final UserEmail userEmail = emails.get(i);
View view = buildRecord(userEmail.getTitle(), userEmail.getEmail(), R.drawable.ic_import_contacts_black_24dp, isFirstContact, false, inflater, contactsContainer);
if (isFirstContact) {
recordFieldWithIcon = view;
}
view.setOnClickListener(v -> {
new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.email_menu_email).replace("{0}", userEmail.getEmail()), getString(R.string.phone_menu_copy) }, (dialog, which) -> {
if (which == 0) {
startActivity(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", userEmail.getEmail(), null)));
} else if (which == 1) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", userEmail.getEmail());
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_email_copied, Snackbar.LENGTH_SHORT).show();
}
}).show().setCanceledOnTouchOutside(true);
});
view.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Email", "+" + userEmail.getEmail());
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_email_copied, Snackbar.LENGTH_SHORT).show();
return true;
});
isFirstContact = false;
}
}
//
// Username
//
final boolean finalIsFirstContact = isFirstContact;
bind(user.getNick(), new ValueChangedListener<String>() {
private View userNameRecord;
@Override
public void onChanged(final String newUserName, Value<String> valueModel) {
if (newUserName != null && newUserName.length() > 0) {
if (userNameRecord == null) {
userNameRecord = buildRecord(getString(R.string.nickname), "@" + newUserName, R.drawable.ic_import_contacts_black_24dp, finalIsFirstContact, false, inflater, contactsContainer);
} else {
((TextView) userNameRecord.findViewById(R.id.value)).setText(newUserName);
}
userNameRecord.setOnLongClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Username", newUserName);
clipboard.setPrimaryClip(clip);
Snackbar.make(res, R.string.toast_nickname_copied, Snackbar.LENGTH_SHORT).show();
return true;
});
if (finalIsFirstContact) {
recordFieldWithIcon = userNameRecord;
}
}
}
});
//
// Settings
//
{
//
// Notifications
//
View notificationContainer = res.findViewById(R.id.notificationsCont);
View notificationPickerContainer = res.findViewById(R.id.notificationsPickerCont);
((TextView) notificationContainer.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
final SwitchCompat notificationEnable = (SwitchCompat) res.findViewById(R.id.enableNotifications);
Peer peer = Peer.user(user.getId());
notificationEnable.setChecked(messenger().isNotificationsEnabled(peer));
if (messenger().isNotificationsEnabled(peer)) {
ViewUtils.showView(notificationPickerContainer, false);
} else {
ViewUtils.goneView(notificationPickerContainer, false);
}
notificationEnable.setOnCheckedChangeListener((buttonView, isChecked) -> {
messenger().changeNotificationsEnabled(Peer.user(user.getId()), isChecked);
if (isChecked) {
ViewUtils.showView(notificationPickerContainer, false);
} else {
ViewUtils.goneView(notificationPickerContainer, false);
}
});
notificationContainer.setOnClickListener(v -> notificationEnable.setChecked(!notificationEnable.isChecked()));
ImageView iconView = (ImageView) res.findViewById(R.id.settings_notification_icon);
Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_list_black_24dp));
drawable.mutate();
DrawableCompat.setTint(drawable, style.getSettingsIconColor());
iconView.setImageDrawable(drawable);
((TextView) notificationPickerContainer.findViewById(R.id.settings_notifications_picker_title)).setTextColor(style.getTextPrimaryColor());
notificationPickerContainer.setOnClickListener(view -> {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.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();
}
String path = messenger().getPreferences().getString("userNotificationSound_" + uid);
if (path == null) {
path = defaultPath;
}
if (path != null && !path.equals("none")) {
if (path.equals(defaultPath)) {
currentSound = defaultUri;
} else {
currentSound = Uri.parse(path);
}
}
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
startActivityForResult(intent, SOUND_PICKER_REQUEST_CODE);
});
//
// Block
//
View blockContainer = res.findViewById(R.id.blockCont);
final TextView blockTitle = (TextView) blockContainer.findViewById(R.id.settings_block_title);
blockTitle.setTextColor(style.getTextPrimaryColor());
bind(user.getIsBlocked(), (val, valueModel) -> {
blockTitle.setText(val ? R.string.profile_settings_unblock : R.string.profile_settings_block);
});
blockContainer.setOnClickListener(v -> {
if (!user.getIsBlocked().get()) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.profile_settings_block_confirm).replace("{user}", user.getName().get())).setPositiveButton(R.string.dialog_yes, (dialog, which) -> {
execute(messenger().blockUser(user.getId()));
dialog.dismiss();
}).setNegativeButton(R.string.dialog_cancel, (dialog, which) -> {
dialog.dismiss();
}).show();
} else {
execute(messenger().unblockUser(user.getId()));
}
});
ImageView blockIconView = (ImageView) res.findViewById(R.id.settings_block_icon);
Drawable blockDrawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_block_white_24dp));
drawable.mutate();
DrawableCompat.setTint(blockDrawable, style.getSettingsIconColor());
blockIconView.setImageDrawable(blockDrawable);
}
//
// Scroll Coordinate
//
final ScrollView scrollView = ((ScrollView) res.findViewById(R.id.scrollContainer));
scrollView.getViewTreeObserver().addOnScrollChangedListener(() -> updateBar(scrollView.getScrollY()));
updateBar(scrollView.getScrollY());
return res;
}
Aggregations