use of android.content.DialogInterface in project actor-platform by actorapp.
the class AddContactActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setDisplayShowCustomEnabled(false);
getSupportActionBar().setTitle(R.string.add_contact_title);
helper = new KeyboardHelper(this);
setContentView(R.layout.activity_add);
findViewById(R.id.container).setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
searchQuery = (EditText) findViewById(R.id.searchField);
searchQuery.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
searchQuery.setHintTextColor(ActorSDK.sharedActor().style.getTextHintColor());
findViewById(R.id.dividerTop).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
findViewById(R.id.dividerBot).setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
((TextView) findViewById(R.id.cancel)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
((TextView) findViewById(R.id.ok)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String query = searchQuery.getText().toString();
if (query.length() == 0) {
return;
}
execute(messenger().findUsers(query), R.string.progress_common, new CommandCallback<UserVM[]>() {
@Override
public void onResult(final UserVM[] res) {
if (res.length == 0) {
new AlertDialog.Builder(AddContactActivity.this).setMessage(getString(R.string.alert_invite_text).replace("{0}", query).replace("{appName}", ActorSDK.sharedActor().getAppName())).setPositiveButton(R.string.alert_invite_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String inviteMessage = getString(R.string.invite_message).replace("{inviteUrl}", ActorSDK.sharedActor().getInviteUrl()).replace("{appName}", ActorSDK.sharedActor().getAppName());
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:" + query));
sendIntent.putExtra("sms_body", inviteMessage);
startActivity(sendIntent);
finish();
}
}).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
} else {
execute(messenger().addContact(res[0].getId()), R.string.progress_common, new CommandCallback<Boolean>() {
@Override
public void onResult(Boolean res2) {
startActivity(Intents.openPrivateDialog(res[0].getId(), true, AddContactActivity.this));
finish();
}
@Override
public void onError(Exception e) {
startActivity(Intents.openPrivateDialog(res[0].getId(), true, AddContactActivity.this));
finish();
}
});
}
}
@Override
public void onError(Exception e) {
// Never happens
}
});
}
});
}
use of android.content.DialogInterface in project actor-platform by actorapp.
the class TakePhotoActivity method onResume.
@Override
protected void onResume() {
super.onResume();
if (!isPerformedAction) {
CharSequence[] args;
if (isAllowDelete) {
args = new CharSequence[] { getString(R.string.pick_photo_camera), getString(R.string.pick_photo_gallery), getString(R.string.pick_photo_remove) };
} else {
args = new CharSequence[] { getString(R.string.pick_photo_camera), getString(R.string.pick_photo_gallery) };
}
dialog = new AlertDialog.Builder(this).setItems(args, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog2, int which) {
if (which == 0) {
externalFile = Files.getExternalTempFile("capture", "jpg");
if (externalFile == null) {
Toast.makeText(getApplicationContext(), R.string.toast_no_sdcard, Toast.LENGTH_LONG).show();
return;
}
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(externalFile))), REQUEST_PHOTO);
} else if (which == 1) {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("image/*");
startActivityForResult(i, REQUEST_GALLERY);
} else if (which == 2) {
setResult(RESULT_OK, new Intent().putExtra(Intents.EXTRA_RESULT, Intents.RESULT_DELETE));
finish();
}
isPerformedAction = true;
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
}).show();
dialog.setCanceledOnTouchOutside(true);
}
}
use of android.content.DialogInterface in project NewPipe by TeamNewPipe.
the class VideoItemDetailFragment method playVideo.
public void playVideo(final StreamInfo info) {
// ----------- THE MAGIC MOMENT ---------------
VideoStream selectedVideoStream = info.video_streams.get(actionBarHandler.getSelectedVideoStream());
if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(activity.getString(R.string.use_external_video_player_key), false)) {
// External Player
Intent intent = new Intent();
try {
intent.setAction(Intent.ACTION_VIEW).setDataAndType(Uri.parse(selectedVideoStream.url), MediaFormat.getMimeById(selectedVideoStream.format)).putExtra(Intent.EXTRA_TITLE, info.title).putExtra("title", info.title);
// HERE !!!
activity.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(R.string.no_player_found).setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent().setAction(Intent.ACTION_VIEW).setData(Uri.parse(activity.getString(R.string.fdroid_vlc_url)));
activity.startActivity(intent);
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
}
} else {
if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(activity.getString(R.string.use_exoplayer_key), false)) {
// TODO: Fix this mess
if (streamThumbnail != null)
ActivityCommunicator.getCommunicator().backgroundPlayerThumbnail = streamThumbnail;
if (info.dashMpdUrl != null && !info.dashMpdUrl.isEmpty()) {
// try dash
Intent intent = new Intent(activity, ExoPlayerActivity.class).setData(Uri.parse(info.dashMpdUrl));
//.putExtra(ExoPlayerActivity.CONTENT_TYPE_EXTRA, Util.TYPE_DASH);
startActivity(intent);
} else if ((info.audio_streams != null && !info.audio_streams.isEmpty()) && (info.video_only_streams != null && !info.video_only_streams.isEmpty())) {
// try smooth streaming
} else {
//default streaming
Intent intent = new Intent(activity, ExoPlayerActivity.class).setDataAndType(Uri.parse(selectedVideoStream.url), MediaFormat.getMimeById(selectedVideoStream.format)).putExtra(ExoPlayerActivity.VIDEO_TITLE, info.title).putExtra(ExoPlayerActivity.CHANNEL_NAME, info.uploader);
//.putExtra(ExoPlayerActivity.CONTENT_TYPE_EXTRA, Util.TYPE_OTHER);
// HERE !!!
activity.startActivity(intent);
}
//-------------
} else {
// Internal Player
Intent intent = new Intent(activity, PlayVideoActivity.class).putExtra(PlayVideoActivity.VIDEO_TITLE, info.title).putExtra(PlayVideoActivity.STREAM_URL, selectedVideoStream.url).putExtra(PlayVideoActivity.VIDEO_URL, info.webpage_url).putExtra(PlayVideoActivity.START_POSITION, info.start_position);
//also HERE !!!
activity.startActivity(intent);
}
}
// --------------------------------------------
}
use of android.content.DialogInterface in project NewPipe by TeamNewPipe.
the class SettingsFragment method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
final Activity activity = getActivity();
defaultPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
// get keys
DEFAULT_RESOLUTION_PREFERENCE = getString(R.string.default_resolution_key);
DEFAULT_AUDIO_FORMAT_PREFERENCE = getString(R.string.default_audio_format_key);
SEARCH_LANGUAGE_PREFERENCE = getString(R.string.search_language_key);
DOWNLOAD_PATH_PREFERENCE = getString(R.string.download_path_key);
DOWNLOAD_PATH_AUDIO_PREFERENCE = getString(R.string.download_path_audio_key);
THEME = getString(R.string.theme_key);
USE_TOR_KEY = getString(R.string.use_tor_key);
// get pref objects
defaultResolutionPreference = (ListPreference) findPreference(DEFAULT_RESOLUTION_PREFERENCE);
defaultAudioFormatPreference = (ListPreference) findPreference(DEFAULT_AUDIO_FORMAT_PREFERENCE);
searchLanguagePreference = (ListPreference) findPreference(SEARCH_LANGUAGE_PREFERENCE);
downloadPathPreference = findPreference(DOWNLOAD_PATH_PREFERENCE);
downloadPathAudioPreference = findPreference(DOWNLOAD_PATH_AUDIO_PREFERENCE);
themePreference = findPreference(THEME);
final String currentTheme = defaultPreferences.getString(THEME, "Light");
prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Activity a = getActivity();
if (a == null) {
return;
}
if (key == USE_TOR_KEY) {
if (defaultPreferences.getBoolean(USE_TOR_KEY, false)) {
if (OrbotHelper.isOrbotInstalled(a)) {
App.configureTor(true);
OrbotHelper.requestStartTor(a);
} else {
Intent intent = OrbotHelper.getOrbotInstallIntent(a);
a.startActivityForResult(intent, REQUEST_INSTALL_ORBOT);
}
} else {
App.configureTor(false);
}
} else if (key == DOWNLOAD_PATH_PREFERENCE) {
String downloadPath = sharedPreferences.getString(DOWNLOAD_PATH_PREFERENCE, getString(R.string.download_path_summary));
downloadPathPreference.setSummary(downloadPath);
} else if (key == DOWNLOAD_PATH_AUDIO_PREFERENCE) {
String downloadPath = sharedPreferences.getString(DOWNLOAD_PATH_AUDIO_PREFERENCE, getString(R.string.download_path_audio_summary));
downloadPathAudioPreference.setSummary(downloadPath);
} else if (key == THEME) {
String selectedTheme = sharedPreferences.getString(THEME, "Light");
themePreference.setSummary(selectedTheme);
if (!selectedTheme.equals(currentTheme)) {
// If it's not the current theme
new AlertDialog.Builder(activity).setTitle(R.string.restart_title).setMessage(R.string.msg_restart).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intentToMain = new Intent(activity, MainActivity.class);
intentToMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.startActivity(intentToMain);
activity.finish();
Runtime.getRuntime().exit(0);
}
}).setNegativeButton(R.string.later, null).create().show();
}
}
updateSummary();
}
};
defaultPreferences.registerOnSharedPreferenceChangeListener(prefListener);
updateSummary();
}
use of android.content.DialogInterface in project atlas by alibaba.
the class InstrumentationHook method asyncStartActivity.
private void asyncStartActivity(final Context context, final String bundleName, final Intent intent, final int requestCode, final String component, final ExecStartActivityCallback callback) {
final Activity current = ActivityTaskMgr.getInstance().peekTopActivity();
final Dialog dialog = current != null ? RuntimeVariables.alertDialogUntilBundleProcessed(current, bundleName) : null;
if (current != null && dialog == null) {
throw new RuntimeException("alertDialogUntilBundleProcessed can not return null");
}
final int activitySize = ActivityTaskMgr.getInstance().sizeOfActivityStack();
final BundleUtil.CancelableTask successTask = new BundleUtil.CancelableTask(new Runnable() {
@Override
public void run() {
Log.e("InstrumentationHook", "async startActivity");
// if (current == ActivityTaskMgr.getInstance().peekTopActivity() || activitySize == ActivityTaskMgr.getInstance().sizeOfActivityStack()+1) {
if (context instanceof Activity) {
callback.execStartActivity();
((Activity) context).overridePendingTransition(0, 0);
} else {
context.startActivity(intent);
}
if (dialog != null && current != null && !current.isFinishing()) {
try {
if (dialog.isShowing())
dialog.dismiss();
} catch (Throwable e) {
}
}
}
});
final BundleUtil.CancelableTask failedTask = new BundleUtil.CancelableTask(new Runnable() {
@Override
public void run() {
if (current == ActivityTaskMgr.getInstance().peekTopActivity()) {
fallBackToClassNotFoundCallback(context, intent, component);
// Toast.makeText(RuntimeVariables.androidApplication, "install error", Toast.LENGTH_SHORT).show();
}
if (dialog != null && current != null && !current.isFinishing()) {
try {
if (dialog.isShowing())
dialog.dismiss();
} catch (Throwable e) {
}
}
}
});
if (dialog != null) {
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
successTask.cancel();
failedTask.cancel();
}
});
BundleUtil.checkBundleStateAsync(bundleName, successTask, failedTask);
if (Atlas.getInstance().getBundle(bundleName) == null || Build.VERSION.SDK_INT < 22) {
if (dialog != null && current != null && !current.isFinishing() && !dialog.isShowing()) {
try {
dialog.show();
} catch (Throwable e) {
}
}
}
}
}
Aggregations