use of android.support.v7.widget.helper.ItemTouchHelper.UP in project WordPress-Android by wordpress-mobile.
the class NotificationsDetailActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((WordPress) getApplication()).component().inject(this);
AppLog.i(AppLog.T.NOTIFS, "Creating NotificationsDetailActivity");
setContentView(R.layout.notifications_detail_activity);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
if (savedInstanceState == null) {
mNoteId = getIntent().getStringExtra(NotificationsListFragment.NOTE_ID_EXTRA);
} else {
if (savedInstanceState.containsKey(ARG_TITLE) && getSupportActionBar() != null) {
getSupportActionBar().setTitle(StringUtils.notNullStr(savedInstanceState.getString(ARG_TITLE)));
}
mNoteId = savedInstanceState.getString(NotificationsListFragment.NOTE_ID_EXTRA);
}
if (mNoteId == null) {
showErrorToastAndFinish();
return;
}
final Note note = NotificationsTable.getNoteById(mNoteId);
if (note == null) {
showErrorToastAndFinish();
return;
}
// If `note.getTimestamp()` is not the most recent seen note, the server will discard the value.
NotificationsActions.updateSeenTimestamp(note);
Map<String, String> properties = new HashMap<>();
properties.put("notification_type", note.getType());
AnalyticsTracker.track(AnalyticsTracker.Stat.NOTIFICATIONS_OPENED_NOTIFICATION_DETAILS, properties);
//set up the viewpager and adapter for lateral navigation
mViewPager = (WPViewPager) findViewById(R.id.viewpager);
mViewPager.setPageTransformer(false, new WPViewPagerTransformer(WPViewPagerTransformer.TransformType.SLIDE_OVER));
NotesAdapter.FILTERS filter = NotesAdapter.FILTERS.FILTER_ALL;
if (getIntent().hasExtra(NotificationsListFragment.NOTE_CURRENT_LIST_FILTER_EXTRA)) {
filter = (NotesAdapter.FILTERS) getIntent().getSerializableExtra(NotificationsListFragment.NOTE_CURRENT_LIST_FILTER_EXTRA);
}
mAdapter = buildNoteListAdapterAndSetPosition(note, filter);
//set title
setActionBarTitleForNote(note);
markNoteAsRead(note);
mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
AnalyticsTracker.track(AnalyticsTracker.Stat.NOTIFICATION_SWIPE_PAGE_CHANGED);
AppPrefs.setNotificationsSwipeToNavigateShown(true);
//change the action bar title for the current note
Note currentNote = mAdapter.getNoteAtPosition(position);
if (currentNote != null) {
setActionBarTitleForNote(currentNote);
markNoteAsRead(currentNote);
}
}
});
// Hide the keyboard, unless we arrived here from the 'Reply' action in a push notification
if (!getIntent().getBooleanExtra(NotificationsListFragment.NOTE_INSTANT_REPLY_EXTRA, false)) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project WordPress-Android by wordpress-mobile.
the class EditPostSettingsFragment method initLocation.
/*
* called when activity is created to initialize the location provider, show views related
* to location if enabled for this blog, and retrieve the current location if necessary
*/
private void initLocation(ViewGroup rootView) {
if (!mPost.supportsLocation())
return;
// show the location views if a provider was found and this is a post on a blog that has location enabled
View locationRootView = ((ViewStub) rootView.findViewById(R.id.stub_post_location_settings)).inflate();
TextView locationLabel = ((TextView) locationRootView.findViewById(R.id.locationLabel));
locationLabel.setText(getResources().getString(R.string.location).toUpperCase());
mLocationText = (TextView) locationRootView.findViewById(R.id.locationText);
mLocationText.setOnClickListener(this);
mLocationAddSection = locationRootView.findViewById(R.id.sectionLocationAdd);
mLocationSearchSection = locationRootView.findViewById(R.id.sectionLocationSearch);
mLocationViewSection = locationRootView.findViewById(R.id.sectionLocationView);
Button addLocation = (Button) locationRootView.findViewById(R.id.addLocation);
addLocation.setOnClickListener(this);
mButtonSearchLocation = (Button) locationRootView.findViewById(R.id.searchLocation);
mButtonSearchLocation.setOnClickListener(this);
mLocationEditText = (EditText) locationRootView.findViewById(R.id.searchLocationText);
mLocationEditText.setOnEditorActionListener(this);
mLocationEditText.addTextChangedListener(mLocationEditTextWatcher);
Button updateLocation = (Button) locationRootView.findViewById(R.id.updateLocation);
Button removeLocation = (Button) locationRootView.findViewById(R.id.removeLocation);
updateLocation.setOnClickListener(this);
removeLocation.setOnClickListener(this);
// if this post has location attached to it, look up the location address
if (mPost.hasLocation()) {
showLocationView();
PostLocation location = mPost.getLocation();
setLocation(location.getLatitude(), location.getLongitude());
} else {
showLocationAdd();
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Lightning-Browser by anthonycr.
the class DownloadHandler method onDownloadStartNoStream.
/**
* Notify the host application a download should be done, even if there is a
* streaming viewer available for thise type.
*
* @param context The context in which the download is requested.
* @param url The full url to the content that should be downloaded
* @param userAgent User agent of the downloading application.
* @param contentDisposition Content-disposition http header, if present.
* @param mimetype The mimetype of the content reported by the server
*/
/* package */
private static void onDownloadStartNoStream(@NonNull final Activity context, @NonNull PreferenceManager preferences, String url, String userAgent, String contentDisposition, @Nullable String mimetype) {
final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
// Check to see if we have an SDCard
String status = Environment.getExternalStorageState();
if (!status.equals(Environment.MEDIA_MOUNTED)) {
int title;
String msg;
// Check to see if the SDCard is busy, same as the music app
if (status.equals(Environment.MEDIA_SHARED)) {
msg = context.getString(R.string.download_sdcard_busy_dlg_msg);
title = R.string.download_sdcard_busy_dlg_title;
} else {
msg = context.getString(R.string.download_no_sdcard_dlg_msg);
title = R.string.download_no_sdcard_dlg_title;
}
Dialog dialog = new AlertDialog.Builder(context).setTitle(title).setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg).setPositiveButton(R.string.action_ok, null).show();
BrowserDialog.setDialogSize(context, dialog);
return;
}
// java.net.URI is a lot stricter than KURL so we have to encode some
// extra characters. Fix for b 2538060 and b 1634719
WebAddress webAddress;
try {
webAddress = new WebAddress(url);
webAddress.setPath(encodePath(webAddress.getPath()));
} catch (Exception e) {
// This only happens for very bad urls, we want to catch the
// exception here
Log.e(TAG, "Exception while trying to parse url '" + url + '\'', e);
Utils.showSnackbar(context, R.string.problem_download);
return;
}
String addressString = webAddress.toString();
Uri uri = Uri.parse(addressString);
final DownloadManager.Request request;
try {
request = new DownloadManager.Request(uri);
} catch (IllegalArgumentException e) {
Utils.showSnackbar(context, R.string.cannot_download);
return;
}
// set downloaded file destination to /sdcard/Download.
// or, should it be set to one of several Environment.DIRECTORY* dirs
// depending on mimetype?
String location = preferences.getDownloadDirectory();
Uri downloadFolder;
location = addNecessarySlashes(location);
downloadFolder = Uri.parse(location);
File dir = new File(downloadFolder.getPath());
if (!dir.isDirectory() && !dir.mkdirs()) {
// Cannot make the directory
Utils.showSnackbar(context, R.string.problem_location_download);
return;
}
if (!isWriteAccessAvailable(downloadFolder)) {
Utils.showSnackbar(context, R.string.problem_location_download);
return;
}
String newMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(Utils.guessFileExtension(filename));
Log.d(TAG, "New mimetype: " + newMimeType);
request.setMimeType(newMimeType);
request.setDestinationUri(Uri.parse(Constants.FILE + location + filename));
// let this downloaded file be scanned by MediaScanner - so that it can
// show up in Gallery app, for example.
request.setVisibleInDownloadsUi(true);
request.allowScanningByMediaScanner();
request.setDescription(webAddress.getHost());
// XXX: Have to use the old url since the cookies were stored using the
// old percent-encoded url.
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader(COOKIE_REQUEST_HEADER, cookies);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
//noinspection VariableNotUsedInsideIf
if (mimetype == null) {
Log.d(TAG, "Mimetype is null");
if (TextUtils.isEmpty(addressString)) {
return;
}
// We must have long pressed on a link or image to download it. We
// are not sure of the mimetype in this case, so do a head request
new FetchUrlMimeType(context, request, addressString, cookies, userAgent).start();
} else {
Log.d(TAG, "Valid mimetype, attempting to download");
final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
try {
manager.enqueue(request);
} catch (IllegalArgumentException e) {
// Probably got a bad URL or something
Log.e(TAG, "Unable to enqueue request", e);
Utils.showSnackbar(context, R.string.cannot_download);
} catch (SecurityException e) {
// TODO write a download utility that downloads files rather than rely on the system
// because the system can only handle Environment.getExternal... as a path
Utils.showSnackbar(context, R.string.problem_location_download);
}
Utils.showSnackbar(context, context.getString(R.string.download_pending) + ' ' + filename);
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project StylishMusicPlayer by ryanhoo.
the class BaseActivity method supportActionBar.
/**
* An easy way to set up non-home(no back button on the toolbar) activity to enable
* go back action.
*
* @param toolbar The toolbar with go back button
* @return ActionBar
*/
protected ActionBar supportActionBar(Toolbar toolbar) {
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
return actionBar;
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Shuttle by timusus.
the class NavigationDrawerFragment method setup.
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
* @param drawerLayout The DrawerLayout containing this fragment's UI.
*/
public void setup(DrawerLayout drawerLayout) {
mDrawerLayout = drawerLayout;
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
// ActionBarDrawerToggle ties together the the proper interactions
// between the navigation drawer and the action bar app icon.
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close) {
/* "close drawer" description for accessibility */
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) {
return;
}
// calls onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) {
return;
}
if (!mUserLearnedDrawer) {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
}
// calls onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// which is the only view which should cause animation)
if (drawerView != null) {
slideOffset = 0;
}
// this disables the animation
super.onDrawerSlide(drawerView, slideOffset);
}
};
// per the navigation drawer design guidelines.
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(GravityCompat.START);
}
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(() -> mDrawerToggle.syncState());
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
Aggregations