use of android.app.Dialog in project Shuttle by timusus.
the class DialogUtils method showBlacklistDialog.
public static void showBlacklistDialog(final Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.dialog_blacklist, null);
final MaterialDialog.Builder builder = getBuilder(context).title(R.string.blacklist_title).customView(view, false).positiveText(R.string.close).negativeText(R.string.pref_title_clear_blacklist).onNegative((materialDialog, dialogAction) -> {
BlacklistHelper.deleteAllSongs();
Toast.makeText(context, R.string.blacklist_deleted, Toast.LENGTH_SHORT).show();
});
final Dialog dialog = builder.build();
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
final BlacklistAdapter blacklistAdapter = new BlacklistAdapter();
blacklistAdapter.setBlackListListener((v, position, song) -> {
BlacklistHelper.deleteSong(song.id);
if (blacklistAdapter.items.size() == 0) {
dialog.dismiss();
}
});
recyclerView.setAdapter(blacklistAdapter);
Observable<List<Song>> songsObservable = SqlBriteUtils.createContinuousQuery(ShuttleApplication.getInstance(), Song::new, Song.getQuery()).first();
Observable<List<BlacklistedSong>> blacklistObservable = BlacklistHelper.getBlacklistSongsObservable();
Subscription subscription = Observable.combineLatest(songsObservable, blacklistObservable, (songs, blacklistedSongs) -> Stream.of(songs).filter(song -> Stream.of(blacklistedSongs).anyMatch(blacklistedSong -> blacklistedSong.songId == song.id)).sorted((a, b) -> ComparisonUtils.compare(a.albumArtistName, b.albumArtistName)).sorted((a, b) -> ComparisonUtils.compareInt(b.year, a.year)).sorted((a, b) -> ComparisonUtils.compareInt(a.track, b.track)).sorted((a, b) -> ComparisonUtils.compareInt(a.discNumber, b.discNumber)).sorted((a, b) -> ComparisonUtils.compare(a.albumName, b.albumName)).map(song -> (AdaptableItem) new BlacklistView(song)).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(blacklistViews -> {
if (blacklistViews.size() == 0) {
blacklistAdapter.addItem(0, new EmptyView(R.string.blacklist_empty));
} else {
blacklistAdapter.setItems(blacklistViews);
}
});
dialog.setOnDismissListener(dialogInterface -> subscription.unsubscribe());
dialog.show();
}
use of android.app.Dialog in project Shuttle by timusus.
the class DialogUtils method showColorPickerDialog.
public static void showColorPickerDialog(SettingsFragment fragment, int selectedColor, int[] mainColors, int[][] subColors, ColorSelectionListener listener) {
View customView = LayoutInflater.from(fragment.getActivity()).inflate(R.layout.dialog_color_picker, null);
RecyclerView recyclerView = (RecyclerView) customView.findViewById(R.id.recyclerView);
GridLayoutManager gridLayoutManager = new GridLayoutManager(fragment.getActivity(), 5);
recyclerView.setLayoutManager(gridLayoutManager);
ThemeUtils.themeRecyclerView(recyclerView);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
ThemeUtils.themeRecyclerView(recyclerView);
super.onScrollStateChanged(recyclerView, newState);
}
});
ColorAdapter colorAdapter = new ColorAdapter();
List<AdaptableItem> colorViews = new ArrayList<>();
for (int i = 0, length = mainColors.length; i < length; i++) {
ColorView colorView = new ColorView(mainColors[i]);
boolean selected = false;
//If the sub colors array contains our selected color, then we set this colorView to selected.
for (int j = 0, jLength = subColors[i].length; j < jLength; j++) {
if (subColors[i][j] == selectedColor) {
selected = true;
}
}
colorView.selected = selected;
colorViews.add(colorView);
}
colorAdapter.setItems(colorViews);
recyclerView.setAdapter(colorAdapter);
colorAdapter.setColorListener((position, color, isSubColor) -> {
if (isSubColor) {
colorAdapter.setSelectedPosition(position);
} else {
List<AdaptableItem> subColorViews = new ArrayList<>();
for (int i = 0, length = subColors[position].length; i < length; i++) {
ColorView colorView = new ColorView(subColors[position][i]);
colorView.selected = colorView.color == selectedColor;
subColorViews.add(colorView);
colorAdapter.isSubColor = true;
}
colorAdapter.setItems(subColorViews);
}
});
int neutralTextResId;
TextView textView = (TextView) customView.findViewById(R.id.text1);
if (ShuttleUtils.isUpgraded()) {
textView.setVisibility(View.GONE);
neutralTextResId = R.string.dialog_custom;
} else {
textView.setVisibility(View.VISIBLE);
if (ShuttleUtils.isAmazonBuild()) {
neutralTextResId = R.string.get_pro_button_amazon;
} else {
neutralTextResId = R.string.btn_upgrade;
}
}
getBuilder(fragment.getActivity()).title(fragment.getActivity().getString(R.string.color_pick)).negativeText(R.string.cancel).onNegative((dialog, which) -> dialog.dismiss()).positiveText(R.string.button_done).onPositive((dialog, which) -> {
int color = selectedColor;
for (AdaptableItem item : colorAdapter.items) {
if (((ColorView) item).selected) {
color = ((ColorView) item).color;
break;
}
}
listener.colorSelected(color);
dialog.dismiss();
}).neutralText(neutralTextResId).autoDismiss(false).onNeutral((dialog, which) -> {
if (ShuttleUtils.isUpgraded()) {
showCustomColorPickerDialog(fragment.getActivity(), selectedColor, listener);
dialog.dismiss();
} else {
showUpgradeDialog(fragment.getActivity(), (upgradeDialog, which1) -> {
if (ShuttleUtils.isAmazonBuild()) {
ShuttleUtils.openShuttleLink(fragment.getActivity(), "com.simplecity.amp_pro");
} else {
AnalyticsManager.logUpgrade(AnalyticsManager.UpgradeType.COLORS);
((SettingsActivity) fragment.getActivity()).purchasePremiumUpgrade();
}
});
}
}).customView(customView, false).show();
}
use of android.app.Dialog in project Shuttle by timusus.
the class PlaylistUtils method renamePlaylistDialog.
public static void renamePlaylistDialog(final Context context, final Playlist playlist, final MaterialDialog.SingleButtonCallback listener) {
View customView = LayoutInflater.from(context).inflate(R.layout.dialog_playlist, null);
final CustomEditText editText = (CustomEditText) customView.findViewById(R.id.editText);
editText.setText(playlist.name);
MaterialDialog.Builder builder = DialogUtils.getBuilder(context).title(R.string.create_playlist_create_text_prompt).customView(customView, false).positiveText(R.string.save).onPositive((materialDialog, dialogAction) -> {
String name = editText.getText().toString();
if (name.length() > 0) {
ContentResolver resolver = context.getContentResolver();
ContentValues values = new ContentValues(1);
values.put(MediaStore.Audio.Playlists.NAME, name);
resolver.update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values, MediaStore.Audio.Playlists._ID + "=?", new String[] { Long.valueOf(playlist.id).toString() });
playlist.name = name;
Toast.makeText(context, R.string.playlist_renamed_message, Toast.LENGTH_SHORT).show();
}
if (listener != null) {
listener.onClick(materialDialog, dialogAction);
}
}).negativeText(R.string.cancel);
final MaterialDialog dialog = builder.build();
TextWatcher textWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// check if playlist with current name exists already, and warn the user if so.
setSaveButton(dialog, playlist, editText.getText().toString());
}
public void afterTextChanged(Editable s) {
}
};
editText.addTextChangedListener(textWatcher);
dialog.show();
}
use of android.app.Dialog in project platform_frameworks_base by android.
the class FakeApp method onCreate.
@Override
public void onCreate() {
String processName = ActivityThread.currentProcessName();
Slog.i("FakeOEMFeatures", "Creating app in process: " + processName);
if (!getApplicationInfo().packageName.equals(processName)) {
// our extra overhead stuff.
return;
}
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
// is a user build, WARN! Do not want!
if ("user".equals(android.os.Build.TYPE)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Should not be on user build");
builder.setMessage("The app Fake OEM Features should not be installed on a " + "user build. Please remove this .apk before shipping this build to " + " your customers!");
builder.setCancelable(false);
builder.setPositiveButton("I understand", null);
Dialog dialog = builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
}
// Make a fake window that is always around eating graphics resources.
FakeView view = new FakeView(this);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
if (ActivityManager.isHighEndGfx()) {
lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
}
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
int maxSize = display.getMaximumSizeDimension();
maxSize *= 2;
lp.x = maxSize;
lp.y = maxSize;
lp.setTitle(getPackageName());
wm.addView(view, lp);
// Bind to a fake service we want to keep running in another process.
bindService(new Intent(this, FakeCoreService.class), mServiceConnection, Context.BIND_AUTO_CREATE);
bindService(new Intent(this, FakeCoreService2.class), mServiceConnection2, Context.BIND_AUTO_CREATE);
bindService(new Intent(this, FakeCoreService3.class), mServiceConnection3, Context.BIND_AUTO_CREATE);
// Start to a fake service that should run in the background of
// another process.
mHandler.sendEmptyMessage(MSG_TICK);
// Make a fake allocation to consume some RAM.
mStuffing = new int[STUFFING_SIZE_INTS];
for (int i = 0; i < STUFFING_SIZE_BYTES / PAGE_SIZE; i++) {
// Fill each page with a unique value.
final int VAL = i * 2 + 100;
final int OFF = (i * PAGE_SIZE) / 4;
for (int j = 0; j < (PAGE_SIZE / 4); j++) {
mStuffing[OFF + j] = VAL;
}
}
}
use of android.app.Dialog in project platform_frameworks_base by android.
the class FakeBackgroundService method onCreate.
@Override
public void onCreate() {
super.onCreate();
mHandler.sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY);
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
// Make a fake window that is always around eating graphics resources.
FakeView view = new FakeView(this);
Dialog dialog = new Dialog(this, android.R.style.Theme_Holo_Dialog);
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED | WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.getWindow().setDimAmount(0);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
int maxSize = display.getMaximumSizeDimension();
maxSize *= 2;
lp.x = maxSize;
lp.y = maxSize;
lp.setTitle(getPackageName() + ":background");
dialog.getWindow().setAttributes(lp);
dialog.getWindow().setContentView(view);
dialog.show();
}
Aggregations