Example usage for android.content Intent getDataString

List of usage examples for android.content Intent getDataString

Introduction

In this page you can find the example usage for android.content Intent getDataString.

Prototype

public @Nullable String getDataString() 

Source Link

Document

The same as #getData() , but returns the URI as an encoded String.

Usage

From source file:com.keepassdroid.fileselect.FileSelectActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    fillData();/*  ww  w.ja v a  2s . c  o m*/

    String filename = null;
    if (requestCode == FILE_BROWSE && resultCode == RESULT_OK) {
        filename = data.getDataString();
        if (filename != null) {
            if (filename.startsWith("file://")) {
                filename = filename.substring(7);
            }

            filename = URLDecoder.decode(filename);
        }

    } else if ((requestCode == GET_CONTENT || requestCode == OPEN_DOC) && resultCode == RESULT_OK) {
        if (data != null) {
            Uri uri = data.getData();
            if (uri != null) {
                if (StorageAF.useStorageFramework(this)) {
                    try {
                        // try to persist read and write permissions
                        ContentResolver resolver = getContentResolver();
                        ContentResolverCompat.takePersistableUriPermission(resolver, uri,
                                Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        ContentResolverCompat.takePersistableUriPermission(resolver, uri,
                                Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    } catch (Exception e) {
                        // nop
                    }
                }
                if (requestCode == GET_CONTENT) {
                    uri = UriUtil.translate(this, uri);
                }
                filename = uri.toString();
            }
        }
    }

    if (filename != null) {
        EditText fn = (EditText) findViewById(R.id.file_filename);
        fn.setText(filename);
    }
}

From source file:cx.ring.fragments.AccountCreationFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case FILE_SELECT_CODE:
        if (resultCode == Activity.RESULT_OK) {
            Log.w(TAG, "onActivityResult " + data.getDataString());
            this.mDataPath = getPath(getActivity(), data.getData());
            if (TextUtils.isEmpty(this.mDataPath))
                Toast.makeText(getActivity(), "Can't read " + data.getData(), Toast.LENGTH_LONG).show();
            else//www .  j  a va2  s  . c o  m
                showImportDialog();
        }
        break;
    }
}

From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_schedule);

    // Pre-process the intent received to open this activity to determine if it was a deep
    // link to a SessionDetail. Typically you wouldn't use this type of logic, but we need to
    // because of the path of session details page on the website is only /schedule and session
    // ids are part of the query parameters (sid).
    Intent intent = getIntent();
    if (intent != null && !TextUtils.isEmpty(intent.getDataString())) {
        // Check format against website format.
        String intentDataString = intent.getDataString();
        try {/*from   www .jav a2  s .c o  m*/
            Uri dataUri = Uri.parse(intentDataString);
            String sessionId = dataUri.getQueryParameter("sid");
            if (!TextUtils.isEmpty(sessionId)) {
                Uri data = ScheduleContract.Sessions.buildSessionUri(sessionId);
                Intent sessionDetailIntent = new Intent(MyScheduleActivity.this, SessionDetailActivity.class);
                sessionDetailIntent.setData(data);
                startActivity(sessionDetailIntent);
                finish();
            }
            LOGD(TAG, "SessionId: " + sessionId);
        } catch (Exception exception) {
            LOGE(TAG, "Data uri existing but wasn't parsable for a session detail deep link");
        }
    }

    // ANALYTICS SCREEN: View the My Schedule screen
    // Contains: Nothing (Page name is a constant)
    AnalyticsHelper.sendScreenView(SCREEN_LABEL);

    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mScrollViewWide = (ScrollView) findViewById(R.id.main_content_wide);
    mWideMode = findViewById(R.id.my_schedule_first_day) != null;

    if (SettingsUtils.isAttendeeAtVenue(this)) {
        mDayZeroAdapter = new MyScheduleAdapter(this, getLUtils());
        prepareDayZeroAdapter();
    }

    for (int i = 0; i < Config.CONFERENCE_DAYS.length; i++) {
        mScheduleAdapters[i] = new MyScheduleAdapter(this, getLUtils());
    }

    mViewPagerAdapter = new OurViewPagerAdapter(getFragmentManager());
    mViewPager.setAdapter(mViewPagerAdapter);

    if (mWideMode) {
        mMyScheduleViewWide[0] = (MyScheduleView) findViewById(R.id.my_schedule_first_day);
        mMyScheduleViewWide[0].setAdapter(mScheduleAdapters[0]);
        mMyScheduleViewWide[1] = (MyScheduleView) findViewById(R.id.my_schedule_second_day);
        mMyScheduleViewWide[1].setAdapter(mScheduleAdapters[1]);

        TextView firstDayHeaderView = (TextView) findViewById(R.id.day_label_first_day);
        TextView secondDayHeaderView = (TextView) findViewById(R.id.day_label_second_day);
        if (firstDayHeaderView != null) {
            firstDayHeaderView.setText(getDayName(0));
        }
        if (secondDayHeaderView != null) {
            secondDayHeaderView.setText(getDayName(1));
        }

        TextView zerothDayHeaderView = (TextView) findViewById(R.id.day_label_zeroth_day);
        MyScheduleView dayZeroView = (MyScheduleView) findViewById(R.id.my_schedule_zeroth_day);
        if (mDayZeroAdapter != null) {
            dayZeroView.setAdapter(mDayZeroAdapter);
            dayZeroView.setVisibility(View.VISIBLE);
            zerothDayHeaderView.setText(getDayName(-1));
            zerothDayHeaderView.setVisibility(View.VISIBLE);
        } else {
            dayZeroView.setVisibility(View.GONE);
            zerothDayHeaderView.setVisibility(View.GONE);
        }
    } else {
        // it's PagerAdapter set.
        mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);

        mTabLayout.setTabsFromPagerAdapter(mViewPagerAdapter);

        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mViewPager.setCurrentItem(tab.getPosition(), true);
                TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition());
                view.setContentDescription(
                        getString(R.string.talkback_selected, getString(R.string.a11y_button, tab.getText())));
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition());
                view.setContentDescription(getString(R.string.a11y_button, tab.getText()));
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                // Do nothing
            }
        });
        mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.my_schedule_page_margin));
        mViewPager.setPageMarginDrawable(R.drawable.page_margin);

        setTabLayoutContentDescriptions();
    }

    mButterBar = findViewById(R.id.butter_bar);
    removeLoginFailed();

    overridePendingTransition(0, 0);
    addDataObservers();
}

From source file:org.opendatakit.survey.activities.MediaCaptureAudioActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    if (resultCode == Activity.RESULT_CANCELED) {
        // request was canceled -- propagate
        setResult(Activity.RESULT_CANCELED);
        finish();/*  w w  w. j  a v  a  2  s  .c  o m*/
        return;
    }

    Uri mediaUri = intent.getData();

    // it is unclear whether getData() always returns a value or if
    // getDataString() does...
    String str = intent.getDataString();
    if (mediaUri == null && str != null) {
        WebLogger.getLogger(appName).w(t, "Attempting to work around null mediaUri");
        mediaUri = Uri.parse(str);
    }

    if (mediaUri == null) {
        // we are in trouble
        WebLogger.getLogger(appName).e(t, "No uri returned from RECORD_SOUND_ACTION!");
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }

    // Remove the current media.
    deleteMedia();

    // get the file path and create a copy in the instance folder
    String binaryPath = MediaUtils.getPathFromUri(this, (Uri) mediaUri, Audio.Media.DATA);
    File source = new File(binaryPath);
    String extension = binaryPath.substring(binaryPath.lastIndexOf("."));

    if (uriFragmentToMedia == null) {
        // use the newFileBase as a starting point...
        uriFragmentToMedia = uriFragmentNewFileBase + extension;
    }

    // adjust the mediaPath (destination) to have the same extension
    // and delete any existing file.
    File f = ODKFileUtils.getRowpathFile(appName, tableId, instanceId, uriFragmentToMedia);
    File sourceMedia = new File(f.getParentFile(),
            f.getName().substring(0, f.getName().lastIndexOf('.')) + extension);
    uriFragmentToMedia = ODKFileUtils.asRowpathUri(appName, tableId, instanceId, sourceMedia);
    deleteMedia();

    try {
        FileUtils.copyFile(source, sourceMedia);
    } catch (IOException e) {
        WebLogger.getLogger(appName).e(t, ERROR_COPY_FILE + sourceMedia.getAbsolutePath());
        Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show();
        deleteMedia();
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }

    if (sourceMedia.exists()) {
        // Add the copy to the content provier
        ContentValues values = new ContentValues(6);
        values.put(Audio.Media.TITLE, sourceMedia.getName());
        values.put(Audio.Media.DISPLAY_NAME, sourceMedia.getName());
        values.put(Audio.Media.DATE_ADDED, System.currentTimeMillis());
        values.put(Audio.Media.DATA, sourceMedia.getAbsolutePath());

        Uri MediaURI = getApplicationContext().getContentResolver().insert(Audio.Media.EXTERNAL_CONTENT_URI,
                values);
        WebLogger.getLogger(appName).i(t, "Inserting AUDIO returned uri = " + MediaURI.toString());
        uriFragmentToMedia = ODKFileUtils.asRowpathUri(appName, tableId, instanceId, sourceMedia);
        WebLogger.getLogger(appName).i(t, "Setting current answer to " + sourceMedia.getAbsolutePath());

        int delCount = getApplicationContext().getContentResolver().delete(mediaUri, null, null);
        WebLogger.getLogger(appName).i(t,
                "Deleting original capture of file: " + mediaUri.toString() + " count: " + delCount);
    } else {
        WebLogger.getLogger(appName).e(t, "Inserting Audio file FAILED");
    }

    /*
     * We saved the audio to the instance directory. Verify that it is there...
     */
    returnResult();
    return;
}

From source file:org.sufficientlysecure.donations.DonationsFragment.java

/**
 * Donate with bitcoin by opening a bitcoin: intent if available.
 *
 * @param view/*w  w w. ja  v a  2 s . c o  m*/
 */
public void donateBitcoinOnClick(View view) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse("bitcoin:" + mBitcoinAddress));

    if (mDebug)
        Log.d(TAG, "Attempting to donate bitcoin using URI: " + i.getDataString());

    try {
        startActivity(i);
    } catch (ActivityNotFoundException e) {
        ((Button) view.findViewById(R.id.donations__bitcoin_button)).performLongClick();
    }
}

From source file:jahirfiquitiva.iconshowcase.fragments.DonationsFragment.java

/**
 * Donate with bitcoin by opening a bitcoin: intent if available.
 *//*from   ww w . j  a v a2  s .co  m*/
public void donateBitcoinOnClick(View view) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse("bitcoin:" + mBitcoinAddress));

    if (mDebug)
        Utils.showLog(context, "Attempting to donate bitcoin using URI: " + i.getDataString());

    try {
        startActivity(i);
    } catch (ActivityNotFoundException e) {
        view.findViewById(R.id.donations__bitcoin_button).performLongClick();
    }
}

From source file:com.razza.apps.iosched.myschedule.MyScheduleActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_schedule);

    // Pre-process the intent received to open this activity to determine if it was a deep
    // link to a SessionDetail. Typically you wouldn't use this type of logic, but we need to
    // because of the path of session details page on the website is only /schedule and session
    // ids are part of the query parameters (sid).
    Intent intent = getIntent();
    if (intent != null && !TextUtils.isEmpty(intent.getDataString())) {
        // Check format against website format.
        String intentDataString = intent.getDataString();
        try {/*from  w  ww. j av a 2s  .c om*/
            Uri dataUri = Uri.parse(intentDataString);
            String sessionId = dataUri.getQueryParameter("sid");
            if (!TextUtils.isEmpty(sessionId)) {
                Uri data = ScheduleContract.Sessions.buildSessionUri(sessionId);
                Intent sessionDetailIntent = new Intent(MyScheduleActivity.this, SessionDetailActivity.class);
                sessionDetailIntent.setData(data);
                startActivity(sessionDetailIntent);
                finish();
            }
            LogUtils.LOGD(TAG, "SessionId: " + sessionId);
        } catch (Exception exception) {
            LogUtils.LOGE(TAG, "Data uri existing but wasn't parsable for a session detail deep link");
        }
    }

    // ANALYTICS SCREEN: View the My Schedule screen
    // Contains: Nothing (Page name is a constant)
    AnalyticsHelper.sendScreenView(SCREEN_LABEL);

    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mScrollViewWide = (ScrollView) findViewById(R.id.main_content_wide);
    mWideMode = findViewById(R.id.my_schedule_first_day) != null;

    if (SettingsUtils.isAttendeeAtVenue(this)) {
        mDayZeroAdapter = new MyScheduleAdapter(this, getLUtils());
        prepareDayZeroAdapter();
    }

    for (int i = 0; i < Config.CONFERENCE_DAYS.length; i++) {
        mScheduleAdapters[i] = new MyScheduleAdapter(this, getLUtils());
    }

    mViewPagerAdapter = new OurViewPagerAdapter(getFragmentManager());
    mViewPager.setAdapter(mViewPagerAdapter);

    if (mWideMode) {
        mMyScheduleViewWide[0] = (MyScheduleView) findViewById(R.id.my_schedule_first_day);
        mMyScheduleViewWide[0].setAdapter(mScheduleAdapters[0]);
        mMyScheduleViewWide[1] = (MyScheduleView) findViewById(R.id.my_schedule_second_day);
        mMyScheduleViewWide[1].setAdapter(mScheduleAdapters[1]);

        TextView firstDayHeaderView = (TextView) findViewById(R.id.day_label_first_day);
        TextView secondDayHeaderView = (TextView) findViewById(R.id.day_label_second_day);
        if (firstDayHeaderView != null) {
            firstDayHeaderView.setText(getDayName(0));
        }
        if (secondDayHeaderView != null) {
            secondDayHeaderView.setText(getDayName(1));
        }

        TextView zerothDayHeaderView = (TextView) findViewById(R.id.day_label_zeroth_day);
        MyScheduleView dayZeroView = (MyScheduleView) findViewById(R.id.my_schedule_zeroth_day);
        if (mDayZeroAdapter != null) {
            dayZeroView.setAdapter(mDayZeroAdapter);
            dayZeroView.setVisibility(View.VISIBLE);
            zerothDayHeaderView.setText(getDayName(-1));
            zerothDayHeaderView.setVisibility(View.VISIBLE);
        } else {
            dayZeroView.setVisibility(View.GONE);
            zerothDayHeaderView.setVisibility(View.GONE);
        }
    } else {
        // it's PagerAdapter set.
        mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);

        mTabLayout.setTabsFromPagerAdapter(mViewPagerAdapter);

        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mViewPager.setCurrentItem(tab.getPosition(), true);
                TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition());
                view.setContentDescription(
                        getString(R.string.talkback_selected, getString(R.string.a11y_button, tab.getText())));
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition());
                view.setContentDescription(getString(R.string.a11y_button, tab.getText()));
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                // Do nothing
            }
        });
        mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.my_schedule_page_margin));
        mViewPager.setPageMarginDrawable(R.drawable.page_margin);

        setTabLayoutContentDescriptions();
    }

    mButterBar = findViewById(R.id.butter_bar);
    removeLoginFailed();

    overridePendingTransition(0, 0);
    addDataObservers();
}

From source file:org.lol.reddit.activities.ImageViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences);

    if (solidblack)
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    final Intent intent = getIntent();

    mUrl = General.uriFromString(intent.getDataString());
    final RedditPost src_post = intent.getParcelableExtra("post");

    if (mUrl == null) {
        General.quickToast(this, "Invalid URL. Trying web browser.");
        revertToWeb();/*  w  w  w . j ava2  s .  c  om*/
        return;
    }

    Log.i("ImageViewActivity", "Loading URL " + mUrl.toString());

    final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);

    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(progressBar);

    CacheManager.getInstance(this)
            .makeRequest(new CacheRequest(mUrl, RedditAccountManager.getAnon(), null,
                    Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY,
                    Constants.FileType.IMAGE, false, false, false, this) {

                private void setContentView(View v) {
                    layout.removeAllViews();
                    layout.addView(v);
                    v.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                    v.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                }

                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(context.getApplicationContext(),
                            new RRError(null, null, t));
                }

                @Override
                protected void onDownloadNecessary() {
                    General.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            progressBar.setIndeterminate(true);
                        }
                    });
                }

                @Override
                protected void onDownloadStarted() {
                }

                @Override
                protected void onFailure(final RequestFailureType type, Throwable t, StatusLine status,
                        final String readableMessage) {

                    final RRError error = General.getGeneralErrorForFailure(context, type, t, status,
                            url.toString());

                    General.UI_THREAD_HANDLER.post(new Runnable() {
                        public void run() {
                            // TODO handle properly
                            progressBar.setVisibility(View.GONE);
                            layout.addView(new ErrorView(ImageViewActivity.this, error));
                        }
                    });
                }

                @Override
                protected void onProgress(final long bytesRead, final long totalBytes) {
                    General.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            progressBar.setIndeterminate(false);
                            progressBar.setProgress((int) ((100 * bytesRead) / totalBytes));
                        }
                    });
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, final String mimetype) {

                    if (mimetype == null || !Constants.Mime.isImage(mimetype)) {
                        revertToWeb();
                        return;
                    }

                    final InputStream cacheFileInputStream;
                    try {
                        cacheFileInputStream = cacheFile.getInputStream();
                    } catch (IOException e) {
                        notifyFailure(RequestFailureType.PARSE, e, null,
                                "Could not read existing cached image.");
                        return;
                    }

                    if (cacheFileInputStream == null) {
                        notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image");
                        return;
                    }

                    if (Constants.Mime.isImageGif(mimetype)) {

                        if (AndroidApi.isIceCreamSandwichOrLater()) {

                            General.UI_THREAD_HANDLER.post(new Runnable() {
                                public void run() {
                                    try {
                                        final GIFView gifView = new GIFView(ImageViewActivity.this,
                                                cacheFileInputStream);
                                        setContentView(gifView);
                                        gifView.setOnClickListener(new View.OnClickListener() {
                                            public void onClick(View v) {
                                                finish();
                                            }
                                        });

                                    } catch (OutOfMemoryError e) {
                                        General.quickToast(context, R.string.imageview_oom);
                                        revertToWeb();

                                    } catch (Throwable e) {
                                        General.quickToast(context, R.string.imageview_invalid_gif);
                                        revertToWeb();
                                    }
                                }
                            });

                        } else {

                            gifThread = new GifDecoderThread(cacheFileInputStream,
                                    new GifDecoderThread.OnGifLoadedListener() {

                                        public void onGifLoaded() {
                                            General.UI_THREAD_HANDLER.post(new Runnable() {
                                                public void run() {
                                                    imageView = new ImageView(context);
                                                    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                                    setContentView(imageView);
                                                    gifThread.setView(imageView);

                                                    imageView.setOnClickListener(new View.OnClickListener() {
                                                        public void onClick(View v) {
                                                            finish();
                                                        }
                                                    });
                                                }
                                            });
                                        }

                                        public void onOutOfMemory() {
                                            General.quickToast(context, R.string.imageview_oom);
                                            revertToWeb();
                                        }

                                        public void onGifInvalid() {
                                            General.quickToast(context, R.string.imageview_invalid_gif);
                                            revertToWeb();
                                        }
                                    });

                            gifThread.start();

                        }

                    } else {

                        final long bytes = cacheFile.getSize();
                        final byte[] buf = new byte[(int) bytes];

                        try {
                            new DataInputStream(cacheFileInputStream).readFully(buf);
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }

                        final ImageTileSource imageTileSource;
                        try {
                            imageTileSource = new ImageTileSourceWholeBitmap(buf);

                        } catch (OutOfMemoryError e) {
                            General.quickToast(context, R.string.imageview_oom);
                            revertToWeb();
                            return;

                        } catch (Throwable t) {
                            Log.e("ImageViewActivity", "Exception when creating ImageTileSource", t);
                            General.quickToast(context, R.string.imageview_decode_failed);
                            revertToWeb();
                            return;
                        }

                        General.UI_THREAD_HANDLER.post(new Runnable() {
                            public void run() {

                                surfaceView = new RRGLSurfaceView(ImageViewActivity.this,
                                        new ImageViewDisplayListManager(imageTileSource,
                                                ImageViewActivity.this));
                                setContentView(surfaceView);

                                surfaceView.setOnClickListener(new View.OnClickListener() {
                                    public void onClick(View v) {
                                        finish();
                                    }
                                });

                                if (mIsPaused) {
                                    surfaceView.onPause();
                                } else {
                                    surfaceView.onResume();
                                }
                            }
                        });
                    }
                }
            });

    final RedditPreparedPost post = src_post == null ? null
            : new RedditPreparedPost(this, CacheManager.getInstance(this), 0, src_post, -1, false, false, false,
                    false, RedditAccountManager.getInstance(this).getDefaultAccount(), false);

    final FrameLayout outerFrame = new FrameLayout(this);
    outerFrame.addView(layout);

    if (post != null) {

        final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(this);

        final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(this,
                new BezelSwipeOverlay.BezelSwipeListener() {

                    public boolean onSwipe(BezelSwipeOverlay.SwipeEdge edge) {

                        toolbarOverlay.setContents(
                                post.generateToolbar(ImageViewActivity.this, false, toolbarOverlay));
                        toolbarOverlay.show(edge == BezelSwipeOverlay.SwipeEdge.LEFT
                                ? SideToolbarOverlay.SideToolbarPosition.LEFT
                                : SideToolbarOverlay.SideToolbarPosition.RIGHT);
                        return true;
                    }

                    public boolean onTap() {

                        if (toolbarOverlay.isShown()) {
                            toolbarOverlay.hide();
                            return true;
                        }

                        return false;
                    }
                });

        outerFrame.addView(bezelOverlay);
        outerFrame.addView(toolbarOverlay);

        bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

        toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

    }

    setContentView(outerFrame);
}

From source file:org.span.manager.MainActivity.java

/** Called when the activity is first created. */
@Override//w  ww . ja  v  a  2  s.co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate()"); // DEBUG

    setContentView(R.layout.main);

    app = (ManetManagerApp) getApplication();
    app.manet.registerObserver(this);

    // init table rows
    startTblRow = (TableRow) findViewById(R.id.startAdhocRow);
    stopTblRow = (TableRow) findViewById(R.id.stopAdhocRow);
    radioModeImage = (ImageView) findViewById(R.id.radioModeImage);
    batteryTemperatureLayout = (RelativeLayout) findViewById(R.id.layoutBatteryTemp);
    headerMainLayout = (RelativeLayout) findViewById(R.id.layoutHeaderMain);

    batteryTemperature = (TextView) findViewById(R.id.batteryTempText);
    tvIP = (TextView) findViewById(R.id.tvIP);
    tvSSID = (TextView) findViewById(R.id.tvSSID);

    // Update the IP and SSID display immediate when the Activity is shown and
    // when the orientation is changed.
    app.manet.sendManetConfigQuery();

    // define animation
    animation = new ScaleAnimation(0.9f, 1, 0.9f, 1, // From x, to x, from y, to y
            ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(600);
    animation.setFillAfter(true);
    animation.setStartOffset(0);
    animation.setRepeatCount(1);
    animation.setRepeatMode(Animation.REVERSE);

    // start button
    startBtn = (ImageView) findViewById(R.id.startAdhocBtn);
    startBtnListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d(TAG, "StartBtn pressed ...");
            showDialog(ID_DIALOG_STARTING);
            currDialogId = ID_DIALOG_STARTING;
            app.manet.sendStartAdhocCommand();
        }
    };
    startBtn.setOnClickListener(this.startBtnListener);

    // stop button
    stopBtn = (ImageView) findViewById(R.id.stopAdhocBtn);
    stopBtnListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d(TAG, "StopBtn pressed ...");
            showDialog(ID_DIALOG_STOPPING);
            currDialogId = ID_DIALOG_STOPPING;
            app.manet.sendStopAdhocCommand();
        }
    };
    stopBtn.setOnClickListener(this.stopBtnListener);

    // start messenger service so that it runs even if no active activities are bound to it
    startService(new Intent(this, MessageService.class));
    Intent theIntent = getIntent();
    String action = theIntent.getAction();

    String intentData = theIntent.getDataString();
    if (action != null && action.equals(Intent.ACTION_VIEW)) {
        Bundle bundle = new Bundle(1);
        bundle.putString("filepath", intentData);
        showDialog(ID_DIALOG_CONFIG, bundle);
    }

    EulaHelper eula = new EulaHelper(this, this);
    eula.showDialog();
}