Example usage for android.support.v4.app FragmentManager addOnBackStackChangedListener

List of usage examples for android.support.v4.app FragmentManager addOnBackStackChangedListener

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager addOnBackStackChangedListener.

Prototype

public abstract void addOnBackStackChangedListener(OnBackStackChangedListener listener);

Source Link

Document

Add a new listener for changes to the fragment back stack.

Usage

From source file:facebook.hellofriends.app.MyFaceBookActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {/*from  w  w w  . ja v  a2 s  .  c  om*/
        PackageInfo info = getPackageManager().getPackageInfo("com.example.in", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            System.out.println("Key hash::::::::::::" + md.digest() + " " + Base64.DEFAULT);
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
    logger = AppEventsLogger.newLogger(this);
    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }

    setContentView(R.layout.main);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            MyFaceBookActivity.this.user = user;
            updateUI();
            System.out.println("hello:::::::::::::" + user);
            logger.logEvent(AppEventsConstants.EVENT_NAME_ACTIVATED_APP);
            logger.logEvent("Login Button pressed By " + user);
            // It's possible that we were waiting for this.user to be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostStatusUpdate();
        }
    });

    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostPhoto();
        }
    });

    pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton);
    pickFriendsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickFriends();
        }
    });

    pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton);
    pickPlaceButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickPlace();
        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:com.tmm.android.facebook.HelloFacebookSampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }/*from   w  w w  . j  av  a  2 s.c o m*/

    setContentView(R.layout.facebook);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            HelloFacebookSampleActivity.this.user = user;
            updateUI();
            // It's possible that we were waiting for this.user to be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostStatusUpdate();
        }
    });
    getpostButton = (Button) findViewById(R.id.getpostButton);
    getpostButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            getpost();
        }
    });

    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostPhoto();
        }
    });

    pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton);
    pickFriendsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickFriends();
        }
    });

    pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton);
    pickPlaceButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickPlace();
        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
}

From source file:com.wicom.magazine.SocialActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    setContentView(R.layout.activity_social);

    imageName = getIntent().getStringExtra(BundleConstants.GALLERY_ITEM_NAME);

    ZipResourceFile expansionFile = ExpansionFileHolder.getInstance(getApplicationContext()).getExpansionFile();
    InputStream fileStream = null;
    if (expansionFile != null) {

        try {//from   www. j  a  v  a  2 s  .co m
            int orientation = getResources().getConfiguration().orientation;

            if (orientation == 1) {
                fileStream = expansionFile.getInputStream("drawable/" + imageName + "v.png");
            }
            if (fileStream == null) {
                fileStream = expansionFile.getInputStream("drawable/" + imageName + ".png");
            }

            ((ImageView) findViewById(R.id.pictureToShare))
                    .setImageBitmap(ImageResizer.decodeSampledBitmapFromResource(fileStream, 800, 600));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }

    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostPhoto();
        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide
        // the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got
    // popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:com.amansoni.tripbook.activity.FacebookActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Add code to print out the key hash
    try {// w  w  w .j  a  v  a 2s. c o m
        PackageInfo info = getPackageManager().getPackageInfo("com.amansoni.tripbook",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }

    setContentView(R.layout.facebook_activity);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            FacebookActivity.this.user = user;
            updateUI();
            // It's possible that we were waiting for this.user to be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostStatusUpdate();
        }
    });

    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostPhoto();
        }
    });

    pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton);
    pickFriendsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickFriends();
        }
    });

    pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton);
    pickPlaceButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickPlace();
        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:com.namnv.project.kidpaint.HelloFacebookSampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Add code to print out the key hash
    try {/*  w w  w . ja v  a 2s.  c o m*/
        PackageInfo info = getPackageManager().getPackageInfo("com.facebook.samples.hellofacebook",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");

            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }

    setContentView(R.layout.sample_main);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            HelloFacebookSampleActivity.this.user = user;
            updateUI();
            // It's possible that we were waiting for this.user to be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostStatusUpdate();
        }
    });

    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostPhoto();
        }
    });

    pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton);
    pickFriendsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickFriends();
        }
    });

    pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton);
    pickPlaceButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickPlace();
        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:util.facebook.FBManager.java

@Override
public void onCreate(Bundle savedInstanceState) {
    if (Define.g_bDebugTest) {
        try {//from   w w w . ja  v  a2s.c  om
            PackageInfo info = getApplicationContext().getPackageManager()
                    .getPackageInfo("com.wh.BluffingGirlEN", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.d("GameApp", "GameApp:" + Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (NameNotFoundException e) {
            Log.e("GameApp:" + "name not found", "GameApp:" + e.toString());
        } catch (NoSuchAlgorithmException e) {
            Log.e("GameApp:" + "no such an algorithm", "GameApp:" + e.toString());
        }
    }

    super.onCreate(savedInstanceState);
    //here to change  fb application id for new session,
    //Define.MyLog(m_strAppID);
    //Session l_NewSession = new Session.Builder(getBaseContext()).setApplicationId(m_strAppID).build();
    //Session.setActiveSession(l_NewSession);

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }
    setContentView(R.layout.fbmanagerlayout);
    loginButton = (LoginButton) findViewById(R.id.login_button);
    if (loginButton != null) {
        loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
            @Override
            public void onUserInfoFetched(GraphUser user) {
                FBManager.this.user = user;
                updateUI();
                // It's possible that we were waiting for this.user to be populated in order to post a
                // status update.
                handlePendingAction();
            }
        });
    }

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostStatusUpdate();
        }
    });

    //postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    //postPhotoButton.setOnClickListener(new View.OnClickListener() {
    //    public void onClick(View view) {
    //        onClickPostPhoto();
    //    }
    //});

    //pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton);
    //pickFriendsButton.setOnClickListener(new View.OnClickListener() {
    //    public void onClick(View view) {
    //        onClickPickFriends();
    //    }
    //});

    //pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton);
    //pickPlaceButton.setOnClickListener(new View.OnClickListener() {
    //    public void onClick(View view) {
    //        onClickPickPlace();
    //    }
    //});

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:com.example.android.threadsample.DisplayActivity.java

@Override
public void onCreate(Bundle stateBundle) {
    // Sets fullscreen-related flags for the display
    getWindow().setFlags(/*from  ww w  .  j  a  v a2  s. com*/
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);

    // Calls the super method (required)
    super.onCreate(stateBundle);

    // Inflates the main View, which will be the host View for the fragments
    mMainView = getLayoutInflater().inflate(R.layout.fragmenthost, null);

    // Sets the content view for the Activity
    setContentView(mMainView);

    /*
     * Creates an intent filter for DownloadStateReceiver that intercepts broadcast Intents
     */

    // The filter's action is BROADCAST_ACTION
    IntentFilter statusIntentFilter = new IntentFilter(Constants.BROADCAST_ACTION);

    // Sets the filter's category to DEFAULT
    statusIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);

    // Instantiates a new DownloadStateReceiver
    mDownloadStateReceiver = new DownloadStateReceiver();

    // Registers the DownloadStateReceiver and its intent filters
    LocalBroadcastManager.getInstance(this).registerReceiver(mDownloadStateReceiver, statusIntentFilter);

    /*
     * Creates intent filters for the FragmentDisplayer
     */

    // One filter is for the action ACTION_VIEW_IMAGE
    IntentFilter displayerIntentFilter = new IntentFilter(Constants.ACTION_VIEW_IMAGE);

    // Adds a data filter for the HTTP scheme
    displayerIntentFilter.addDataScheme("http");

    // Registers the receiver
    LocalBroadcastManager.getInstance(this).registerReceiver(mFragmentDisplayer, displayerIntentFilter);

    // Creates a second filter for ACTION_ZOOM_IMAGE
    displayerIntentFilter = new IntentFilter(Constants.ACTION_ZOOM_IMAGE);

    // Registers the receiver
    LocalBroadcastManager.getInstance(this).registerReceiver(mFragmentDisplayer, displayerIntentFilter);

    // Gets an instance of the support library FragmentManager
    FragmentManager localFragmentManager = getSupportFragmentManager();

    /*
     * Detects if side-by-side display should be enabled. It's only available on xlarge and
     * sw600dp devices (for example, tablets). The setting in res/values/ is "false", but this
     * is overridden in values-xlarge and values-sw600dp.
     */
    mSideBySide = getResources().getBoolean(R.bool.sideBySide);

    /*
     * Detects if hiding navigation controls should be enabled. On xlarge andsw600dp, it should
     * be false, to avoid having the user enter an additional tap.
     */
    mHideNavigation = getResources().getBoolean(R.bool.hideNavigation);

    /*
     * Adds the back stack change listener defined in this Activity as the listener for the
     * FragmentManager. See the method onBackStackChanged().
     */
    localFragmentManager.addOnBackStackChangedListener(this);

    // If the incoming state of the Activity is null, sets the initial view to be thumbnails
    if (null == stateBundle) {

        // Starts a Fragment transaction to track the stack
        FragmentTransaction localFragmentTransaction = localFragmentManager.beginTransaction();

        // Adds the PhotoThumbnailFragment to the host View
        localFragmentTransaction.add(R.id.fragmentHost, new PhotoThumbnailFragment(),
                Constants.THUMBNAIL_FRAGMENT_TAG);

        // Commits this transaction to display the Fragment
        localFragmentTransaction.commit();

        // The incoming state of the Activity isn't null.
    } else {

        // Gets the previous state of the fullscreen indicator
        mFullScreen = stateBundle.getBoolean(Constants.EXTENDED_FULLSCREEN);

        // Sets the fullscreen flag to its previous state
        setFullScreen(mFullScreen);

        // Gets the previous backstack entry count.
        mPreviousStackCount = localFragmentManager.getBackStackEntryCount();
    }
}

From source file:org.technovanza.technovanza14.HelloFacebookSampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Parse.initialize(this, "jWNXwn3j7fmaub8bFMWYy3sRWJgXCMaqCljKOUyn",
            "AmQgVA2i3Gc45vHfYwqfPcJJzAyvwihvmgYcRx86");

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    try {/*from   w  w  w.j  av a2s  .  c  o m*/
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String sign = Base64.encodeToString(md.digest(), Base64.DEFAULT);
            Log.e("MY KEY HASH:", sign);
            Toast.makeText(getApplicationContext(), sign, Toast.LENGTH_LONG).show();
            Log.d("mohit", "Signature" + sign);
            System.out.println("Signature" + sign);

            //  TextView tvmyName = (TextView)findViewById(R.id.txtv);
            //    /tvmyName.setText(Base64.encodeToString((md.digest()));

        }
    } catch (NameNotFoundException e) {
        Log.d("mohit", "Exception 1" + e);
    } catch (NoSuchAlgorithmException e) {
        Log.d("mohit", "Exception 2" + e);

    }

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }

    setContentView(R.layout.main);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            HelloFacebookSampleActivity.this.user = user;
            updateUI();
            // It's possible that we were waiting for this.user to be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });
    inviteFriends = (Button) findViewById(R.id.inviteFriends);
    inviteFriends.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickInviteFriends();
        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostStatusUpdate();
        }
    });

    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostPhoto();
        }
    });
    technoPage = (Button) findViewById(R.id.TechnoPage);
    technoPage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //TODO Auto-generated method stub

            Intent facebookIntent = getOpenFacebookIntent(HelloFacebookSampleActivity.this);
            startActivity(facebookIntent);
        }
    });

    pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton);
    pickFriendsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickFriends();
        }
    });

    pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton);
    pickPlaceButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickPlace();
        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:selfie.time.HelloFacebookSampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }//from   www. jav  a  2 s.co  m
    context = this;
    setContentView(R.layout.main);
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo("selfie.time",
                PackageManager.GET_SIGNATURES); //Your package name here
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }
    final Typeface mFont = Typeface.createFromAsset(getAssets(), "bg.otf");
    final ViewGroup mContainer = (ViewGroup) findViewById(android.R.id.content).getRootView();
    Util.setAppFont(mContainer, mFont, false);

    et = (EditText) findViewById(R.id.editText1);
    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            HelloFacebookSampleActivity.this.user = user;
            updateUI();
            handlePendingAction();
        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Session session = Session.getActiveSession();
            if (session != null)
                onClickPostStatusUpdate();
            else
                Util.showInfoDialog(context, "Please login with Facebook first.");
        }
    });

    postPhotoButton = (Button) findViewById(R.id.postPhotoButton);
    postPhotoButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostPhoto();
        }
    });

    pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton);
    pickFriendsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPickFriends();
        }
    });

    postSelfieButton = (Button) findViewById(R.id.postSelfieButton);
    postSelfieButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Session session = Session.getActiveSession();
            if (!Util.isNetworkAvailable(context))
                Util.showWifiDialog(context);
            else if (et.getText().toString().length() == 0)
                Util.showInfoDialog(context, "Please enter text to share with this selfie.");
            else if (session == null || !session.isOpened())
                Util.showInfoDialog(context, "Please login with Facebook first.");
            else
                initCapturePhoto(REQUEST_IMAGE_CAPTURE);
        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:com.nijie.samples.facebookfoo.FacebookFooMainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    Log.d("facebookfoo ###############", "FacebookFooMainActivity create!");
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }//  w ww .  j ava 2s .c o  m

    setContentView(R.layout.main);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setPublishPermissions(PAGE_PERMISSION);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            FacebookFooMainActivity.this.user = user;
            Log.d("facebookfoo ###############", "onUserInfoFetched!");
            updateUI();
            // It's possible that we were waiting for this.user to be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    postRegularPostButton = (Button) findViewById(R.id.regularPostUpdateButton);
    postRegularPostButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostRegularPost();
        }
    });

    postUnpublishedPostButton = (Button) findViewById(R.id.postUnpublishedPostButton);
    postUnpublishedPostButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostUnpublishedPost();
        }
    });

    listAllPostsButton = (Button) findViewById(R.id.listAllPostsButton);
    listAllPostsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickListAllPosts();
        }
    });

    showStatisticsButton = (Button) findViewById(R.id.showStatisticsButton);
    showStatisticsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickShowStatistics();
        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    if (fragment != null) {
        // If we're being re-created and have a fragment, we need to a) hide the main UI controls and
        // b) hook up its listeners again.
        controlsContainer.setVisibility(View.GONE);
        if (fragment instanceof FriendPickerFragment) {
            setFriendPickerListeners((FriendPickerFragment) fragment);
        } else if (fragment instanceof PlacePickerFragment) {
            setPlacePickerListeners((PlacePickerFragment) fragment);
        }
    }

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);

    Log.d("facebookfoo ###############", "OnCreate Exit!");
}