Example usage for android.view Gravity START

List of usage examples for android.view Gravity START

Introduction

In this page you can find the example usage for android.view Gravity START.

Prototype

int START

To view the source code for android.view Gravity START.

Click Source Link

Document

Push object to x-axis position at the start of its container, not changing its size.

Usage

From source file:gc.david.dfm.ui.MainActivity.java

@Override
public void onBackPressed() {
    Mint.leaveBreadcrumb("MainActivity::onBackPressed");
    if (drawerLayout.isDrawerOpen(Gravity.START)) {
        drawerLayout.closeDrawer(Gravity.START);
    } else {// w  ww .  ja  v  a  2  s  .c o m
        super.onBackPressed();
    }
}

From source file:com.sonymobile.android.media.testmediaplayer.MainActivity.java

@Override
public void onPrepared(MediaPlayer arg0) {
    if (LOGS_ENABLED)
        Log.d(TAG, "onPreparedListener, State: " + mMediaPlayer.getState());
    setTimeOnView(mDurationView, mMediaPlayer.getDuration());
    mDrawerLayout.closeDrawer(Gravity.START);
    onPlayPauseClicked(null);/* w  w w .  ja va2s .com*/
    mIsPrepared = true;
}

From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java

/**
 * Called when Menu option is selected.//from  w ww .  ja v a 2  s. c om
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Pass the event to ActionBarDrawerToggle, if it returns true, then it has handled
    //  the app icon touch event that opens/closes the navigation drawer.
    if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }

    // If a classic options-menu item was selected, close the navigation drawer if it was open.
    if (navigationDrawerLayout.isDrawerOpen(Gravity.START)) {
        navigationDrawerLayout.closeDrawer(Gravity.START);
    }

    // Now handle our menu items.
    switch (item.getItemId()) {

    // Change relative size of panels
    case R.id.change_size_menu_item:
        try {
            // Display dialog to pick new relative size of the panels.
            DialogFragment newFragment = new PanelSizeDialog();
            newFragment.show(getFragmentManager(), "");
        } catch (Exception e) {
            errorMessage(getString(R.string.error_cannotChangeSizes));
        }
        return true;

    // Fullscreen
    case R.id.fullscreen_menu_item:
        // Switch to fullscreen
        switchFullscreen();

        // Build an info dialog.
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.Fullscreen));

        // Add OK and Cancel buttons
        builder.setPositiveButton(getString(R.string.OK), null);
        builder.setNegativeButton(getString(R.string.Cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                switchFullscreen();
            }
        });

        // Create the dialog
        builder.setMessage(R.string.fullscreen_dialog_info_notice);
        builder.create().show();
        return true;

    // Toggle Scroll Sync
    case R.id.scroll_sync_menu_item:
        Boolean newDefaultScrollSyncMethodSet = governor.flipScrollSync();

        if (governor.isScrollSync()) {
            // Display infotext if appropriate.
            InfotextDialog.showIfAppropriate(this, DontShowAgain.SCROLL_SYNC);

            if (newDefaultScrollSyncMethodSet != null && newDefaultScrollSyncMethodSet) {
                Toast.makeText(this, getString(R.string.Activated_Default_Scroll_sync_method),
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(this, getString(R.string.Activated_Scroll_sync), Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(this, getString(R.string.Deactivated_Scroll_sync), Toast.LENGTH_SHORT).show();
        }
        return true;

    // Scroll Sync Options
    case R.id.scroll_sync_options_menu_item:
        new ScrollSyncDialog().show(getFragmentManager(), "ScrollSyncDialog");
        return true;

    // Sync Chapters
    case R.id.sync_chapters_menu_item:
        if (!governor.flipChapterSync()) {
            errorMessage(getString(R.string.error_onlyOneBookOpen));
        }
        if (governor.isChapterSync()) {
            // Display infotext if appropriate.
            if (!InfotextDialog.showIfAppropriate(this, DontShowAgain.CHAPTER_SYNC)) {
                // If infotext was not shown, show at least a toast.
                Toast.makeText(this, getString(R.string.Activated_Chapter_sync), Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(this, getString(R.string.Deactivated_Chapter_sync), Toast.LENGTH_SHORT).show();
        }
        return true;

    // Bilingual ebook
    case R.id.bilingual_ebook_menu_item:
        if (governor.exactlyOneBookOpen() || governor.isReadingBilingualEbook()) {
            if (openBilingualBook(0)) {
                invalidateOptionsMenu();
            }
        }
        return true;

    case R.id.bilingual_ebook_1_menu_item:
        if (openBilingualBook(0)) {
            invalidateOptionsMenu();
        }
        return true;

    case R.id.bilingual_ebook_2_menu_item:
        if (!governor.exactlyOneBookOpen()) {
            if (openBilingualBook(1)) {
                invalidateOptionsMenu();
            }
        } else {
            errorMessage(getString(R.string.error_onlyOneBookOpen));
        }
        return true;

    // Display metadata of the book
    case R.id.metadata_menu_item:
        if (governor.exactlyOneBookOpen() == true || governor.isReadingBilingualEbook() == true) {
            governor.getPanelHolder(0).displayMetadata();
        } else {
        }
        return true;

    case R.id.metadata_1_menu_item:
        if (!governor.getPanelHolder(0).displayMetadata())
            errorMessage(getString(R.string.error_metadataNotFound));
        return true;

    case R.id.metadata_2_menu_item:
        if (!governor.getPanelHolder(1).displayMetadata())
            errorMessage(getString(R.string.error_metadataNotFound));
        return true;

    // Table of contents
    case R.id.table_of_contents_menu_item:
        if (governor.exactlyOneBookOpen() == true || governor.isReadingBilingualEbook() == true) {
            governor.getPanelHolder(0).displayToC();
        }
        return true;

    case R.id.table_of_contents_1_menu_item:
        if (!governor.getPanelHolder(0).displayToC())
            errorMessage(getString(R.string.error_tocNotFound));
        return true;

    case R.id.table_of_contents_2_menu_item:
        if (!governor.getPanelHolder(1).displayToC())
            errorMessage(getString(R.string.error_tocNotFound));
        return true;

    // Change style -- deprecated, replaced by Visual Options button in the navigation drawer.
    case R.id.style_menu_item:
        try {
            // Display the style dialog.
            if (governor.exactlyOneBookOpen() == true) {
                DialogFragment newFragment = new VisualOptionsDialog();
                newFragment.show(getFragmentManager(), "");
                bookSelector = 0;
            }
        } catch (Exception e) {
            errorMessage(getString(R.string.error_CannotChangeStyle));
        }
        return true;

    case R.id.style_1_menu_item:
        try {
            // Display the style dialog.
            DialogFragment newFragment = new VisualOptionsDialog();
            newFragment.show(getFragmentManager(), "");
            bookSelector = 0;
        } catch (Exception e) {
            errorMessage(getString(R.string.error_CannotChangeStyle));
        }
        return true;

    case R.id.style_2_menu_item:
        try {
            // Display the style dialog.
            DialogFragment newFragment = new VisualOptionsDialog();
            newFragment.show(getFragmentManager(), "");
            bookSelector = 1;
        } catch (Exception e) {
            errorMessage(getString(R.string.error_CannotChangeStyle));
        }
        return true;

    // Audio shenanigans.
    case R.id.audio_menu_item:
        if (governor.exactlyOneBookOpen() == true) {
            if (!governor.getPanelHolder(0).extractAudio()) {
                errorMessage(getString(R.string.no_audio));
            }
        }
        return true;

    case R.id.audio_1_menu_item:
        if (!governor.getPanelHolder(0).extractAudio())
            errorMessage(getString(R.string.no_audio));
        return true;

    case R.id.audio_2_menu_item:
        if (!governor.getPanelHolder(1).extractAudio())
            errorMessage(getString(R.string.no_audio));
        return true;

    // And finally, the default option.
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:sharedcode.turboeditor.activity.MainActivity.java

void onEvent(final EventBusEvents.NewFileToOpen event) {

    if (fileOpened && mEditor.canSaveFile()) {
        SaveFileDialog.newInstance(sFilePath, pageSystem.getAllText(mEditor.getText().toString()),
                currentEncoding, true, event.getFile().getAbsolutePath()).show(getFragmentManager(), "dialog");
        return;//from   w  w  w  .ja  v a2  s. c om
    }

    new AsyncTask<Void, Void, Void>() {

        File file;
        String message = "";
        String fileText;
        String encoding;
        ProgressDialog progressDialog;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Close the drawer
            mDrawerLayout.closeDrawer(Gravity.START);
            progressDialog = new ProgressDialog(MainActivity.this);
            progressDialog.setMessage(getString(R.string.please_wait));
            progressDialog.show();

        }

        @Override
        protected Void doInBackground(Void... params) {
            file = event.getFile();
            try {
                if (!file.exists() || !file.isFile()) {
                    fileText = event.getFileText();
                    sFilePath = file.getAbsolutePath();
                    fileExtension = "txt";
                    return null;
                }

                file = file.getCanonicalFile();
                sFilePath = file.getAbsolutePath();
                fileExtension = FilenameUtils.getExtension(sFilePath).toLowerCase();

                boolean isRoot;

                if (!file.canRead()) {
                    Shell shell;
                    shell = Shell.startRootShell();
                    Toolbox tb = new Toolbox(shell);
                    isRoot = tb.isRootAccessGiven();

                    if (isRoot) {
                        File tempFile = new File(getFilesDir(), "temp.root.file");
                        if (!tempFile.exists())
                            tempFile.createNewFile();
                        tb.copyFile(event.getFile().getAbsolutePath(), tempFile.getAbsolutePath(), false,
                                false);
                        file = new File(tempFile.getAbsolutePath());
                    }
                }

                boolean autoencoding = PreferenceHelper.getAutoEncoding(MainActivity.this);
                if (autoencoding) {

                    encoding = FileUtils.getDetectedEncoding(file);
                    if (encoding.isEmpty()) {
                        encoding = PreferenceHelper.getEncoding(MainActivity.this);
                    }
                } else {
                    encoding = PreferenceHelper.getEncoding(MainActivity.this);
                }

                fileText = org.apache.commons.io.FileUtils.readFileToString(file, encoding);
            } catch (Exception e) {
                message = e.getMessage();
                fileText = "";
            }

            while (mDrawerLayout.isDrawerOpen(Gravity.START)) {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            progressDialog.hide();

            if (!message.isEmpty()) {
                Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
                onEvent(new EventBusEvents.CannotOpenAFile());
            } else {

                pageSystem = new PageSystem(MainActivity.this, MainActivity.this, fileText,
                        new File(sFilePath));
                currentEncoding = encoding;

                onEvent(new EventBusEvents.AFileIsSelected(sFilePath));

                showTextEditor();

                String name = FilenameUtils.getName(sFilePath);
                if (name.isEmpty())
                    getSupportActionBar().setTitle(R.string.new_file);
                else
                    getSupportActionBar().setTitle(name);

                if (!name.isEmpty()) {
                    refreshList(sFilePath, true, false);
                }
            }

        }
    }.execute();
}

From source file:com.sonymobile.android.media.testmediaplayer.MainActivity.java

@Override
public void onCompletion(MediaPlayer arg0) {
    if (LOGS_ENABLED)
        Log.d(TAG, "OnCompletion!");
    mSeekBarUpdater.deactivate();//from  ww  w  . j a v  a  2 s.c o  m
    mTimeTracker.stopUpdating();
    mHandler.removeCallbacks(mFadeOutRunnable);
    mHandler.removeCallbacks(mHideNavigationRunnable);
    setTimeOnView(mTimeView, mMediaPlayer.getDuration());
    mDrawerLayout.openDrawer(Gravity.START);
    Boolean b = false;
    mPlayPauseButton.setTag(b);
    mPlayPauseButton.setImageResource(R.drawable.media_player_play_button);
    mPreview.setSystemUiVisibility(0);
    mBottomControls.setVisibility(View.VISIBLE);
    mSeekbar.setVisibility(View.VISIBLE);
    mTimeLayout.setVisibility(View.VISIBLE);
    mSeekbar.setEnabled(true);
}

From source file:com.google.samples.apps.sergio.ui.BaseActivity.java

private void signInOrCreateAnAccount() {
    //Get list of accounts on device.
    AccountManager am = AccountManager.get(BaseActivity.this);
    Account[] accountArray = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    if (accountArray.length == 0) {
        //Send the user to the "Add Account" page.
        Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
        intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES, new String[] { "com.google" });
        startActivity(intent);//from   w w  w.j a  v a2  s .c  o m
    } else {
        //Try to log the user in with the first account on the device.
        startLoginProcess();
        mDrawerLayout.closeDrawer(Gravity.START);
    }
}

From source file:xyz.template.material.menu.ui.BaseActivity.java

private void signInOrCreateAnAccount() {
    //Get list of accounts on device.
    AccountManager am = AccountManager.get(BaseActivity.this);
    Account[] accountArray = am.getAccountsByType("com.google");
    if (accountArray.length == 0) {
        //Send the user to the "Add Account" page.
        Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
        intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES, new String[] { "com.google" });
        startActivity(intent);//w ww  . j a va 2 s . c  om
    } else {
        //Try to log the user in with the first account on the device.
        startLoginProcess();
        mDrawerLayout.closeDrawer(Gravity.START);
    }
}

From source file:com.google.samples.apps.sergio.ui.BaseActivity.java

private void onNavDrawerItemClicked(final int itemId) {
    if (itemId == getSelfNavDrawerItem()) {
        mDrawerLayout.closeDrawer(Gravity.START);
        return;/*from ww  w .ja v  a  2  s .  c om*/
    }

    if (isSpecialItem(itemId)) {
        goToNavDrawerItem(itemId);
    } else {
        // launch the target Activity after a short delay, to allow the close animation to play
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                goToNavDrawerItem(itemId);
            }
        }, NAVDRAWER_LAUNCH_DELAY);

        // change the active item on the list so the user can see the item changed
        setSelectedNavDrawerItem(itemId);
        // fade out the main content
        View mainContent = findViewById(R.id.main_content);
        if (mainContent != null) {
            mainContent.animate().alpha(0).setDuration(MAIN_CONTENT_FADEOUT_DURATION);
        }
    }

    mDrawerLayout.closeDrawer(Gravity.START);
}

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

void newFileToOpen(final GreatUri newUri, final String newFileText) {

    if (fileOpened && mEditor != null && mEditor.canSaveFile() && greatUri != null && pageSystem != null
            && currentEncoding != null) {
        new SaveFileDialog(greatUri, pageSystem.getAllText(mEditor.getText().toString()), currentEncoding, true,
                newUri).show(getFragmentManager(), "dialog");
        return;/*from   ww  w  .ja va2s  .c o  m*/
    }

    new AsyncTask<Void, Void, Void>() {

        String message = "";
        String fileText = "";
        String fileName = "";
        String encoding = "UTF-16";
        boolean isRootRequired = false;
        ProgressDialog progressDialog;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Close the drawer
            mDrawerLayout.closeDrawer(Gravity.START);
            progressDialog = new ProgressDialog(MainActivity.this);
            progressDialog.setMessage(getString(R.string.please_wait));
            progressDialog.show();

        }

        @Override
        protected Void doInBackground(Void... params) {
            try {
                // if no new uri
                if (newUri == null || newUri.getUri() == null || newUri.getUri() == Uri.EMPTY) {
                    fileExtension = "txt";
                    fileText = newFileText;
                } else {
                    String filePath = newUri.getFilePath();

                    // if the uri has no path
                    if (TextUtils.isEmpty(filePath)) {
                        fileName = newUri.getFileName();
                        fileExtension = FilenameUtils.getExtension(fileName).toLowerCase();

                        readUri(newUri.getUri(), filePath, false);
                    }
                    // if the uri has a path
                    else {
                        fileName = FilenameUtils.getName(filePath);
                        fileExtension = FilenameUtils.getExtension(fileName).toLowerCase();

                        isRootRequired = !newUri.isReadable();
                        // if we cannot read the file, root permission required
                        if (isRootRequired) {
                            readUri(newUri.getUri(), filePath, true);
                        }
                        // if we can read the file associated with the uri
                        else {
                            readUri(newUri.getUri(), filePath, false);
                        }
                    }

                }

                greatUri = newUri;
            } catch (Exception e) {
                message = e.getMessage();
                fileText = "";
            }

            while (mDrawerLayout.isDrawerOpen(Gravity.START)) {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return null;
        }

        private void readUri(Uri uri, String path, boolean asRoot) throws IOException {

            BufferedReader buffer = null;
            StringBuilder stringBuilder = new StringBuilder();
            String line;

            if (asRoot) {

                encoding = "UTF-8";

                // Connect the shared connection
                if (RootFW.connect()) {
                    FileReader reader = RootFW.getFileReader(path);
                    buffer = new BufferedReader(reader);
                }
            } else {

                boolean autoencoding = PreferenceHelper.getAutoEncoding(MainActivity.this);
                if (autoencoding) {
                    encoding = FileUtils.getDetectedEncoding(getContentResolver().openInputStream(uri));
                    if (encoding.isEmpty()) {
                        encoding = PreferenceHelper.getEncoding(MainActivity.this);
                    }
                } else {
                    encoding = PreferenceHelper.getEncoding(MainActivity.this);
                }

                InputStream inputStream = getContentResolver().openInputStream(uri);
                if (inputStream != null) {
                    buffer = new BufferedReader(new InputStreamReader(inputStream, encoding));
                }
            }

            if (buffer != null) {
                while ((line = buffer.readLine()) != null) {
                    stringBuilder.append(line);
                    stringBuilder.append("\n");
                }
                buffer.close();
                fileText = stringBuilder.toString();
            }

            if (isRootRequired)
                RootFW.disconnect();
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            progressDialog.hide();

            if (!TextUtils.isEmpty(message)) {
                Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
                cannotOpenFile();
            } else {

                pageSystem = new PageSystem(MainActivity.this, MainActivity.this, fileText);
                currentEncoding = encoding;

                aFileWasSelected(greatUri);

                showTextEditor();

                if (fileName.isEmpty())
                    getSupportActionBar().setTitle(R.string.new_file);
                else
                    getSupportActionBar().setTitle(fileName);

                if (greatUri != null) {
                    refreshList(greatUri, true, false);
                }
            }

        }
    }.execute();
}

From source file:com.saarang.samples.apps.iosched.ui.BaseActivity.java

private void onNavDrawerItemClicked(final int itemId) {
    if (itemId == getSelfNavDrawerItem()) {
        mDrawerLayout.closeDrawer(Gravity.START);
        return;/*from   www .  j  a  va 2 s  .c o m*/
    }

    if (isSpecialItem(itemId)) {
        goToNavDrawerItem(itemId);
    } else {
        // launch the target Activity after a short delay, to allow the close animation to play
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                goToNavDrawerItem(itemId);
            }
        }, NAVDRAWER_LAUNCH_DELAY);

        // change the active item on the list so the user can see the item changed
        setSelectedNavDrawerItem(itemId);
        // fade out the main content
        View mainContent = findViewById(com.saarang.samples.apps.iosched.R.id.main_content);
        if (mainContent != null) {
            mainContent.animate().alpha(0).setDuration(MAIN_CONTENT_FADEOUT_DURATION);
        }
    }

    mDrawerLayout.closeDrawer(Gravity.START);
}