Search in sources :

Example 21 with UP

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);
    }
}
Also used : NotesAdapter(org.wordpress.android.ui.notifications.adapters.NotesAdapter) WPViewPagerTransformer(org.wordpress.android.widgets.WPViewPagerTransformer) HashMap(java.util.HashMap) Note(org.wordpress.android.models.Note) ViewPager(android.support.v4.view.ViewPager) WPViewPager(org.wordpress.android.widgets.WPViewPager) ActionBar(android.support.v7.app.ActionBar)

Example 22 with UP

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();
    }
}
Also used : ViewStub(android.view.ViewStub) PostLocation(org.wordpress.android.fluxc.model.post.PostLocation) Button(android.widget.Button) AppCompatButton(android.support.v7.widget.AppCompatButton) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) NetworkImageView(com.android.volley.toolbox.NetworkImageView)

Example 23 with UP

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);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Uri(android.net.Uri) DownloadManager(android.app.DownloadManager) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) File(java.io.File)

Example 24 with UP

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;
}
Also used : ActionBar(android.support.v7.app.ActionBar)

Example 25 with UP

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);
}
Also used : SharedPreferences(android.content.SharedPreferences) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) AnimatedExpandableListView(com.simplecity.amp_library.ui.views.AnimatedExpandableListView) View(android.view.View) ActionBar(android.support.v7.app.ActionBar)

Aggregations

View (android.view.View)135 RecyclerView (android.support.v7.widget.RecyclerView)97 TextView (android.widget.TextView)69 Toolbar (android.support.v7.widget.Toolbar)50 ActionBar (android.support.v7.app.ActionBar)49 Intent (android.content.Intent)44 ImageView (android.widget.ImageView)41 AdapterView (android.widget.AdapterView)33 ArrayList (java.util.ArrayList)30 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)29 DialogInterface (android.content.DialogInterface)25 AlertDialog (android.support.v7.app.AlertDialog)25 ListView (android.widget.ListView)25 Bundle (android.os.Bundle)22 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)22 SharedPreferences (android.content.SharedPreferences)21 Preference (android.support.v7.preference.Preference)20 GridLayoutManager (android.support.v7.widget.GridLayoutManager)19 SuppressLint (android.annotation.SuppressLint)16 Point (android.graphics.Point)16