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

    // --------- auth ----------
    // We create a new AuthSession so that we can use the Dropbox API.
    AndroidAuthSession session = buildSession();
    mApi = new DropboxAPI<AndroidAuthSession>(session);

    // Basic Android widgets
    setContentView(R.layout.main);

    checkAppKeySetup();

    if (mApi.getSession().isLinked() == false) {
      Toast.makeText(this, "starting auth", Toast.LENGTH_LONG).show();
      mApi.getSession().startAuthentication(PhotoShareActivity.this);
    } else {
      // -------- upload -----------
      uploadFiles();
    }

    // Display the proper UI state if logged in or not
    //        setLoggedIn(mApi.getSession().isLinked());
  }
 /*
    Dropbox account connection initialization
 */
 private void linkDropbox() {
   if (mLoggedIn) {
     logOut();
   } else {
     if (USE_OAUTH1) {
       mApi.getSession().startAuthentication(activity);
     } else {
       mApi.getSession().startOAuth2Authentication(activity);
     }
   }
 }
示例#3
0
  DropboxAPI<AndroidAuthSession> getAPI(Activity activity) {
    AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session = new AndroidAuthSession(appKeys, AccessType.APP_FOLDER);
    DropboxAPI<AndroidAuthSession> mDBApi = new DropboxAPI<AndroidAuthSession>(session);

    AccessTokenPair token = getStoredKeys();
    if (token != null) {
      mDBApi.getSession().setAccessTokenPair(token);
    } else {
      mDBApi.getSession().startAuthentication(activity);
    }
    return mDBApi;
  }
  public void onResume() {
    super.onResume();

    if (mDBApi.getSession().authenticationSuccessful()) {
      try {
        // Required to complete auth, sets the access token on the session
        mDBApi.getSession().finishAuthentication();

        // tokens = mDBApi.getSession().getAccessTokenPair();
      } catch (IllegalStateException e) {
        Log.i("DbAuthLog", "Error authenticating", e);
      }
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_back_up, container, false);

    AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
    mDBApi = new DropboxAPI<AndroidAuthSession>(session);
    Button backUp = (Button) rootView.findViewById(R.id.btn_upload);
    Button restoreBackUp = (Button) rootView.findViewById(R.id.btn_download);

    backUp.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            doBackUp(v.getContext());
          }
        });

    restoreBackUp.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            restoreBackUp(v.getContext());
          }
        });
    // MyActivity below should be your activity class name
    mDBApi.getSession().startAuthentication(rootView.getContext());

    return rootView;
  }
 @Override
 protected void onPostExecute(String s) {
   super.onPostExecute(s);
   progressDialog.dismiss();
   api.getSession().unlink();
   Toast.makeText(context, context.getString(R.string.dropbox_backup), Toast.LENGTH_LONG).show();
 }
 @Override
 public void onResume() {
   super.onResume();
   // refresh login state when coming back to the fragment
   refreshLoginState();
   // if already loggedin we don't need to continue
   if (authenticating) {
     // The next part must be inserted in the onResume() method of the
     // fragment from which session.startAuthentication() was called, so
     // that Dropbox authentication completes properly.
     AndroidAuthSession session = mApi.getSession();
     if (session.authenticationSuccessful()) {
       authenticating = false;
       try {
         // Mandatory call to complete the auth
         session.finishAuthentication();
         // Store it locally in the app for later use
         TokenPair tokens = session.getAccessTokenPair();
         storeKeys(tokens.key, tokens.secret);
         // set the preference flag
         setLoggedin(true);
         getDropboxAccountInfo();
       } catch (IllegalStateException e) {
         Toast.makeText(parentActivity, "Couldn't authenticate with Dropbox:", Toast.LENGTH_LONG)
             .show();
       }
     } // end of if authentication successful
   } else {
     // refresh Menu
     refreshMenus();
   }
 }
示例#8
0
  public void UnLink() {
    // Remove credentials from the session
    dropboxApi.getSession().unlink();

    // Clear our stored keys
    clearKeys();
  }
 @Override
 protected void onResume() {
   super.onResume();
   // Toast.makeText(ActivityTracksListView.this, "After onResume", Toast.LENGTH_SHORT).show();
   if (dropboxAuthenticationTry) {
     AndroidAuthSession session = dropbox.getSession();
     if (session.authenticationSuccessful()) {
       try {
         // Required to complete auth, sets the access token on the session
         session.finishAuthentication();
         TokenPair tokens = session.getAccessTokenPair();
         // String accessToken = dropbox.getSession().getOAuth2AccessToken();
         SharedPreferences prefs = getSharedPreferences(DROPBOX_PREF, 0);
         SharedPreferences.Editor editor = prefs.edit();
         editor.putString(APP_KEY, tokens.key);
         editor.putString(APP_SECRET, tokens.secret);
         editor.apply();
         Toast.makeText(
                 ActivityTracksListView.this, "Authentication successful", Toast.LENGTH_LONG)
             .show();
         // dropboxLoggedIn = true;
         uploadToDropbox();
       } catch (IllegalStateException e) {
         Log.i("DbAuthLog", "Error authenticating", e);
         Toast.makeText(
                 getApplicationContext(),
                 "Error during Dropbox authentication",
                 Toast.LENGTH_SHORT)
             .show();
       }
     }
     dropboxAuthenticationTry = false;
   }
 }
示例#10
0
  @Override
  protected void onResume() {
    super.onResume();
    Toast.makeText(this, "PhotoShareActivity.onResume", Toast.LENGTH_SHORT).show();

    AndroidAuthSession session = mApi.getSession();

    // The next part must be inserted in the onResume() method of the
    // activity from which session.startAuthentication() was called, so
    // that Dropbox authentication completes properly.
    if (session.authenticationSuccessful()) {
      try {
        // Mandatory call to complete the auth
        session.finishAuthentication();

        // Store it locally in our app for later use
        TokenPair tokens = session.getAccessTokenPair();
        storeKeys(tokens.key, tokens.secret);

        uploadFiles();
        setLoggedIn(true);
      } catch (IllegalStateException e) {
        showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
        Log.i(TAG, "Error authenticating", e);
      }
    } else {
      Toast.makeText(this, "PhotoShareActivity.onResume: failed to auth", Toast.LENGTH_LONG).show();
    }
  }
示例#11
0
 // Dropbox API
 public void logOut() {
   // Remove credentials from the session
   mApi.getSession().unlink();
   // Clear our stored keys
   clearKeys();
   // Change UI state to display logged out version
   setLoggedIn(false);
 }
示例#12
0
  void finishAuthentication(DropboxAPI<AndroidAuthSession> mDBApi) {
    if (mDBApi.getSession().authenticationSuccessful()) {
      try {
        // MANDATORY call to complete auth.
        // Sets the access token on the session
        mDBApi.getSession().finishAuthentication();

        AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair();

        // Provide your own storeKeys to persist the access token pair
        // A typical way to store tokens is using SharedPreferences
        storeKeys(tokens.key, tokens.secret);
        Log.i("DbAuthLog", "Authenticated");
      } catch (IllegalStateException e) {
        Log.i("DbAuthLog", "Error authenticating", e);
      }
    }
  }
  @SuppressLint("ValidFragment")
  public DropboxFilePickerFragment(final DropboxAPI<AndroidAuthSession> api) {
    super();
    if (api == null) {
      throw new NullPointerException("FileSystem may not be null");
    } else if (!api.getSession().isLinked()) {
      throw new IllegalArgumentException("Must be linked with Dropbox");
    }

    this.dbApi = api;
  }
  /**
   * This handles authentication if the user's token & secret are stored locally, so we don't have
   * to store user-name & password and re-send every time.
   */
  private void connect() {

    AndroidAuthSession session = buildSession();
    dropboxApi = new DropboxAPI<AndroidAuthSession>(session);
    if (!dropboxApi.getSession().isLinked()) {
      isLoggedIn = false;
      Log.d("MobileOrg", "Dropbox account was unlinked...");
      // throw new IOException("Dropbox Authentication Failed, re-run setup wizard");
    } else {
      isLoggedIn = true;
    }
  }
  private void logOutDropbox() {
    // Remove credentials from the session
    mApi.getSession().unlink();
    // Clear our stored keys
    clearKeys();

    if (dataSourceNames != null) {
      dataSourceNames[0] = "Dropbox";
      refreshMenus();
    }
    authenticating = false;
  }
示例#16
0
  protected void onResume() {
    super.onResume();

    if (mDBApi.getSession().authenticationSuccessful()) {
      try {
        // Required to complete auth, sets the access token on the session
        mDBApi.getSession().finishAuthentication();

        AccessTokenPair accessToken = mDBApi.getSession().getAccessTokenPair();
        Log.e("log_tag", "Accesstoken key : " + accessToken.key.toString());
        Log.e("log_tag", "Accesstoken secret : " + accessToken.secret.toString());
        SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
        Editor edit = prefs.edit();
        edit.putString(ACCESS_KEY_NAME, accessToken.key);
        edit.putString(ACCESS_SECRET_NAME, accessToken.secret);
        edit.commit();
      } catch (IllegalStateException e) {
        Log.i("DbAuthLog", "Error authenticating", e);
      }
    }
  }
示例#17
0
  public boolean FinishAuthorization() {
    AndroidAuthSession session = dropboxApi.getSession();
    if (!session.isLinked() && session.authenticationSuccessful()) {
      // Mandatory call to complete the auth
      session.finishAuthentication();

      // Store it locally in our app for later use
      TokenPair tokens = session.getAccessTokenPair();
      storeKeys(tokens.key, tokens.secret);
      return true;
    }

    return false;
  }
示例#18
0
 public void receiveTokenAndConnect() {
   // Dropbox API - recibe el token y se conecta
   AndroidAuthSession session = mApi.getSession();
   if (session.authenticationSuccessful()) {
     try {
       // Mandatory call to complete the auth
       session.finishAuthentication();
       // Store it locally in our app for later use
       TokenPair tokens = session.getAccessTokenPair();
       storeKeys(tokens.key, tokens.secret);
       setLoggedIn(true);
       // showToast("Logueado bien" + tokens.key + " - " + tokens.secret);
     } catch (IllegalStateException e) {
       showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
       Log.i(DropboxUtil.TAG, "Error authenticating", e);
     }
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    init();

    // Basic Android widgets

    checkAppKeySetup();

    totalSize = (TextView) findViewById(R.id.totalSize);
    usedSize = (TextView) findViewById(R.id.usedSize);
    availableSize = (TextView) findViewById(R.id.availableSize);

    // Display the proper UI state if logged in or not
    setLoggedIn(mApi.getSession().isLinked());
  }
示例#20
0
  @Override
  protected void onResume() {
    super.onResume();
    AndroidAuthSession session = mApi.getSession();

    // The next part must be inserted in the onResume() method of the
    // activity from which session.startAuthentication() was called, so
    // that Dropbox authentication completes properly.
    if (session.authenticationSuccessful()) {
      try {
        // Mandatory call to complete the auth
        session.finishAuthentication();

        // Store it locally in our app for later use
        storeAuth(session);
        setLoggedIn(true);
      } catch (IllegalStateException e) {
        showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
        Log.i(TAG, "Error authenticating", e);
      }
    }
  }
  private boolean dropboxAuthentication() {
    dropboxAuthenticationTry = true;
    AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session;

    SharedPreferences prefs = getSharedPreferences(DROPBOX_PREF, 0);
    String key = prefs.getString(APP_KEY, null);
    String secret = prefs.getString(APP_SECRET, null);

    if (key != null && secret != null) {
      AccessTokenPair token = new AccessTokenPair(key, secret);
      session = new AndroidAuthSession(appKeys, token);
      dropbox = new DropboxAPI<>(session);
      return true;

    } else {
      session = new AndroidAuthSession(appKeys);
      dropbox = new DropboxAPI<>(session);
      dropbox.getSession().startAuthentication(ActivityTracksListView.this);
      return false;
    }
  }
示例#22
0
  @Override
  protected void onResume() {
    super.onResume();

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onResume();

    try {
      /* Only activate FaceBook publish install if the user has the FaceBook app installed */
      if (com.facebook.Settings.getAttributionId(getContentResolver()) != null) {
        com.facebook.AppEventsLogger.activateApp(this);
      }
    } catch (IllegalStateException e) {
      Log.d(TAG, "Facebook Setting Exception again!");
    }

    AndroidAuthSession session = mApi.getSession();

    // The next part must be inserted in the onResume() method of the
    // activity from which session.startAuthentication() was called, so
    // that Dropbox authentication completes properly.
    if (session.authenticationSuccessful()) {
      try {
        // Mandatory call to complete the auth
        session.finishAuthentication();

        // Store it locally in our app for later use
        TokenPair tokens = session.getAccessTokenPair();
        storeKeys(tokens.key, tokens.secret);
        setLoggedIn(true);
      } catch (IllegalStateException e) {
        showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
        Log.i(TAG, "Error authenticating", e);
      }
    }
  }
示例#23
0
  public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == android.R.id.home) {
      Intent intent = new Intent(this, ListActivity.class);
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(intent);

    } else if (item.getTitle().toString() == "DropBox") {

      mDBApi.getSession().startAuthentication(ListActivity.this);

    } else if (item.getTitle().toString() == "Google Drive") {

    } else if (item.getTitle().toString() == "Search") {

    } else if (item.getTitle().toString() == "My Profile") {

    } else if (item.getTitle().toString() == "Settings") {

    } else if (item.getTitle().toString() == "Log Out") {

    }
    return true;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    PhoneStateListener phoneStateListener =
        new PhoneStateListener() {
          public void onCallForwardingIndicatorChanged(boolean cfi) {}

          public void onCallStateChanged(int state, String incomingNumber) {}

          public void onCellLocationChanged(CellLocation location) {}

          public void onDataActivity(int direction) {}

          public void onDataConnectionStateChanged(int state) {}

          public void onMessageWaitingIndicatorChanged(boolean mwi) {}

          public void onServiceStateChanged(ServiceState serviceState) {}
          // Deprecated
          // public void onSignalStrengthChanged(int asu)
          public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            threeGSignalStrength = signalStrength.getEvdoDbm();
            /*Context context = getApplicationContext();
            CharSequence text = "Signal strength changed: " + signalStrength.getEvdoDbm();
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();*/
          }
        };

    TelephonyManager telephonyManager =
        (TelephonyManager) getSystemService(getApplicationContext().TELEPHONY_SERVICE);
    telephonyManager.listen(
        phoneStateListener,
        PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR
            | PhoneStateListener.LISTEN_CALL_STATE
            | PhoneStateListener.LISTEN_CELL_LOCATION
            | PhoneStateListener.LISTEN_DATA_ACTIVITY
            | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
            | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR
            | PhoneStateListener.LISTEN_SERVICE_STATE
            | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

    Button saveButton = (Button) findViewById(R.id.saveButton);
    saveButton.setOnClickListener(saveButtonHandler);

    Button exportButton = (Button) findViewById(R.id.exportButton);
    exportButton.setOnClickListener(exportButtonHandler);

    AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session = new AndroidAuthSession(appKeys);
    mDBApi = new DropboxAPI<>(session);
    mDBApi.getSession().startOAuth2Authentication(getApplicationContext());

    Button collectButton = (Button) findViewById(R.id.collectButton);
    collectButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            collectData();
          }
        });
  }
示例#25
0
 public void StartAuthentication(DropboxAuthorizationFragment dropboxAuthorizationFragment) {
   // Start the remote authentication
   dropboxApi.getSession().startAuthentication(dropboxAuthorizationFragment.getActivity());
 }
示例#26
0
 /**
  * Whether the user has authorized GPSLogger with DropBox
  *
  * @return True/False
  */
 public boolean IsLinked() {
   return dropboxApi.getSession().isLinked();
 }
示例#27
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final MediaPlayer mp = MediaPlayer.create(this, R.raw.press);
    mp.setVolume(0.3f, 0.3f);

    //   uiHelper = new UiLifecycleHelper(this, callback);

    AppRater.app_launched(this);

    if (savedInstanceState != null) {
      mCameraFileName = savedInstanceState.getString("mCameraFileName");
    }
    // We create a new AuthSession so that we can use the Dropbox API.
    AndroidAuthSession session = buildSession();
    mApi = new DropboxAPI<AndroidAuthSession>(session);

    // Basic Android widgets
    setContentView(R.layout.main);

    RevMob revmob =
        RevMob.start(this); // RevMob Media ID configured in the AndroidManifest.xml file
    RevMobBanner banner = revmob.createBanner(this);
    ViewGroup view = (ViewGroup) findViewById(R.id.banner);

    // align bottom

    view.addView(banner);

    GridView gridview = (GridView) findViewById(R.id.gridview);
    myImageAdapter = new ImageAdapter(this);
    gridview.setAdapter(myImageAdapter);

    gridview.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            fullscreen.show();
          }
        });

    final String ExternalStorageDirectoryPath =
        Environment.getExternalStorageDirectory().getAbsolutePath();

    String targetPath = ExternalStorageDirectoryPath + PHOTO_DIR;

    Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG).show();

    File targetDirector = new File(targetPath);

    File dir = new File(ExternalStorageDirectoryPath + PHOTO_DIR);
    try {
      if (dir.mkdir()) {
        System.out.println("Directory created");
      } else {
        System.out.println("Directory is not created");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    File[] files = targetDirector.listFiles();

    for (File file : files) {

      myImageAdapter.add(file.getAbsolutePath());
      gridview.setFocusable(true);
    }

    fullscreen = revmob.createFullscreen(this, null); // pre-load it without showing it
    //    ViewGroup view = (ViewGroup) findViewById(R.id.banner);
    //    view.addView(banner);

    checkAppKeySetup();

    final AlphaAnimation alphaDown3, alphaUp3;

    mSubmit = (Button) findViewById(R.id.auth_button);
    // set animation
    alphaDown3 = new AlphaAnimation(1.0f, 0.5f);
    alphaUp3 = new AlphaAnimation(0.5f, 1.0f);
    alphaDown3.setDuration(100);
    alphaUp3.setDuration(100);
    alphaDown3.setFillAfter(true);
    alphaUp3.setFillAfter(true);

    // set OnTouchListener
    mSubmit.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if (event.getAction() == MotionEvent.ACTION_DOWN) mSubmit.startAnimation(alphaDown3);
            alphaDown3.setFillAfter(false);

            if (event.getAction() == MotionEvent.ACTION_UP) mSubmit.startAnimation(alphaUp3);
            alphaUp3.setFillAfter(false);

            return false;
          }
        });

    mSubmit = (Button) findViewById(R.id.auth_button);

    mSubmit.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            mp.start();

            // This logs you out if you're logged in, or vice versa
            if (mLoggedIn) {

              logOut();
            }
          }
        });

    final AlphaAnimation alphaDown2, alphaUp2;

    Gallery = (Button) findViewById(R.id.gall);
    // set animation

    alphaDown2 = new AlphaAnimation(1.0f, 0.5f);
    alphaUp2 = new AlphaAnimation(0.5f, 1.0f);
    alphaDown2.setDuration(100);
    alphaUp2.setDuration(100);
    alphaDown2.setFillAfter(true);
    alphaUp2.setFillAfter(true);

    // set OnTouchListener
    Gallery.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            // TODO Auto-generated method stub
            if (event.getAction() == MotionEvent.ACTION_DOWN) Gallery.startAnimation(alphaDown2);

            alphaDown2.setFillAfter(false);

            if (event.getAction() == MotionEvent.ACTION_UP) Gallery.startAnimation(alphaUp2);

            alphaUp2.setFillAfter(false);

            //    Gallery.clearAnimation();

            return false;
          }
        });

    Gallery = (Button) findViewById(R.id.gall);

    Gallery.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {

            mp.start();

            fullscreen.show();

            Intent photoPickerIntent = new Intent(Intent.ACTION_VIEW);
            photoPickerIntent.setType("image/*");
            startActivity(photoPickerIntent);
          }
        });

    final AlphaAnimation alphaDown, alphaUp;

    box = (Button) findViewById(R.id.dropbox);
    // set animation
    alphaDown = new AlphaAnimation(1.0f, 0.5f);
    alphaUp = new AlphaAnimation(0.5f, 1.0f);
    alphaDown.setDuration(100);
    alphaUp.setDuration(100);
    alphaDown.setFillAfter(true);
    alphaUp.setFillAfter(true);

    // set OnTouchListener
    box.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if (event.getAction() == MotionEvent.ACTION_DOWN) box.startAnimation(alphaDown);

            alphaDown.setFillAfter(false);

            if (event.getAction() == MotionEvent.ACTION_UP) box.startAnimation(alphaUp);

            alphaUp.setFillAfter(false);

            return false;
          }
        });

    box = (Button) findViewById(R.id.dropbox);

    box.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {

            mp.start();

            Intent intent = new Intent(Intent.CATEGORY_LAUNCHER);
            // intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // NB: has no effect!

            // See if official Facebook app is found
            boolean facebookAppFound = false;
            List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
            for (ResolveInfo info : matches) {
              if (info.activityInfo.packageName.toLowerCase().startsWith("com.dropbox.android")) {
                intent.setPackage(info.activityInfo.packageName);
                facebookAppFound = true;
                break;
              }
            }
            // As fallback, launch sharer.php in a browser
            if (!facebookAppFound) {
              String sharerUrl = "http://www.dropbox.com";
              intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
            }

            startActivity(intent);

            try {

              PackageManager manager = getPackageManager();
              Intent i = manager.getLaunchIntentForPackage("com.dropbox.android");
              i.addCategory(Intent.CATEGORY_LAUNCHER);
              startActivity(i);
            } catch (ActivityNotFoundException e) {
              startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://dropbox.com/")));
            }
          }
        });

    loginbutton = (Button) findViewById(R.id.log_in);

    loginbutton.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            mp.start();

            // Start the remote authentication
            mApi.getSession().startAuthentication(CloudCam.this);
          }
        });

    final AlphaAnimation alphaDown1, alphaUp1;

    Kill = (Button) findViewById(R.id.Exit);
    // set animation
    alphaDown1 = new AlphaAnimation(1.0f, 0.5f);
    alphaUp1 = new AlphaAnimation(0.5f, 1.0f);
    alphaDown1.setDuration(100);
    alphaUp1.setDuration(100);
    alphaDown1.setFillAfter(true);
    alphaUp1.setFillAfter(true);

    // set OnTouchListener
    Kill.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            // TODO Auto-generated method stub
            if (event.getAction() == MotionEvent.ACTION_DOWN) Kill.startAnimation(alphaDown1);

            alphaDown1.setFillAfter(false);

            if (event.getAction() == MotionEvent.ACTION_UP) Kill.startAnimation(alphaUp1);

            alphaUp1.setFillAfter(false);

            return false;
          }
        });

    Kill = (Button) findViewById(R.id.Exit);

    Kill.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {

            mp.start();

            // Create custom dialog object
            final Dialog dialog = new Dialog(CloudCam.this);
            // Include dialog.xml file
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.dialog);
            // Set dialog title
            //        dialog.setTitle(" ✈ Cloud Cam ☁");
            TextView text = (TextView) dialog.findViewById(R.id.txt_dia);
            TextView text2 = (TextView) dialog.findViewById(R.id.lpt2);
            ImageView image2 = (ImageView) dialog.findViewById(R.id.vix);

            //     text.setText("\n Custom dialog Android example.");
            ImageView image = (ImageView) dialog.findViewById(R.id.imageDialog);
            image.setImageResource(R.drawable.cloud);

            Button buttonl = (Button) dialog.findViewById(R.id.Like);
            buttonl.setOnClickListener(
                new OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    // Perform action on click
                    mp.start();

                    try {
                      Intent intent =
                          new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/1638346363055062"));
                      startActivity(intent);
                    } catch (Exception e) {
                      startActivity(
                          new Intent(
                              Intent.ACTION_VIEW,
                              Uri.parse(
                                  "https://www.facebook.com/pages/Vixel-Interactive/1638346363055062")));
                    }

                    dialog.dismiss();
                  }
                });

            ImageView buttonv = (ImageView) dialog.findViewById(R.id.vix);
            buttonv.setOnClickListener(
                new OnClickListener() {
                  @Override
                  public void onClick(View v) {

                    mp.start();

                    // Perform action on click

                    try {
                      Intent intent =
                          new Intent(
                              Intent.ACTION_VIEW, Uri.parse("http://www.vixelinteractive.com"));
                      startActivity(intent);
                    } catch (Exception e) {
                    }

                    dialog.dismiss();
                  }
                });

            Button button69 = (Button) dialog.findViewById(R.id.insta);
            button69.setOnClickListener(
                new OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    // Perform action on click
                    mp.start();

                    Uri uri = Uri.parse("http://instagram.com/_u/vixel_interactive");
                    Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);

                    likeIng.setPackage("com.instagram.android");

                    try {
                      startActivity(likeIng);
                    } catch (ActivityNotFoundException e) {
                      startActivity(
                          new Intent(
                              Intent.ACTION_VIEW,
                              Uri.parse("https://instagram.com/vixel_interactive")));
                    }

                    dialog.dismiss();
                  }
                });

            Button button = (Button) dialog.findViewById(R.id.Rate);
            button.setOnClickListener(
                new OnClickListener() {
                  @Override
                  public void onClick(View v) {

                    mp.start();

                    // Perform action on click

                    startActivity(
                        new Intent(
                            Intent.ACTION_VIEW,
                            Uri.parse("market://details?id=" + getPackageName())));

                    dialog.dismiss();
                  }
                });

            Button button3 = (Button) dialog.findViewById(R.id.Share);
            button3.setOnClickListener(
                new OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    // Perform action on click

                    mp.start();

                    String urlToShare =
                        "https://play.google.com/store/apps/details?id=" + getPackageName();
                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    // intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // NB: has no effect!
                    intent.putExtra(Intent.EXTRA_TEXT, urlToShare);

                    // See if official Facebook app is found
                    boolean facebookAppFound = false;
                    List<ResolveInfo> matches =
                        getPackageManager().queryIntentActivities(intent, 0);
                    for (ResolveInfo info : matches) {
                      if (info.activityInfo
                          .packageName
                          .toLowerCase()
                          .startsWith("com.facebook.katana")) {
                        intent.setPackage(info.activityInfo.packageName);
                        facebookAppFound = true;
                        break;
                      }
                    }
                    // https://play.google.com/store/apps/details?id=" + getPackageName();
                    // As fallback, launch sharer.php in a browser
                    if (!facebookAppFound) {
                      String sharerUrl =
                          "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
                      intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
                    }

                    startActivity(intent);

                    dialog.dismiss();
                  }
                });

            // Typecasting the Animation Drawable

            dialog.show();
          }
        });

    mDisplay = (LinearLayout) findViewById(R.id.logged_in_display);

    Start1 = (TextView) findViewById(R.id.lpt2);

    asd = (GridView) findViewById(R.id.gridview);

    dropbox = (Button) findViewById(R.id.dropbox);

    gallbutton = (Button) findViewById(R.id.gall);

    vtext = (TextView) findViewById(R.id.tmt1);

    vmix = (ImageView) findViewById(R.id.tmt2);

    //   Start2 = (TextView)findViewById(R.id.lpt3);

    Start4 = (ImageView) findViewById(R.id.vix);

    Start5 = (ImageView) findViewById(R.id.cc);

    // Dropbox = (Button)findViewById(R.id.dropbox);

    final AlphaAnimation alphaDown4, alphaUp4;

    mPhoto = (Button) findViewById(R.id.photo_button);
    // set animation
    alphaDown4 = new AlphaAnimation(1.0f, 0.5f);
    alphaUp4 = new AlphaAnimation(0.5f, 1.0f);
    alphaDown4.setDuration(100);
    alphaUp4.setDuration(100);
    alphaDown4.setFillAfter(true);
    alphaUp4.setFillAfter(true);

    // set OnTouchListener
    mPhoto.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            // TODO Auto-generated method stub
            if (event.getAction() == MotionEvent.ACTION_DOWN) mPhoto.startAnimation(alphaDown4);

            alphaDown4.setFillAfter(false);

            if (event.getAction() == MotionEvent.ACTION_UP) mPhoto.startAnimation(alphaUp4);

            alphaUp4.setFillAfter(false);

            return false;
          }
        });

    // This is where a photo is displayed
    //    mImage = (ImageView)findViewById(R.id.image_view);

    // This is the button to take a photo
    mPhoto = (Button) findViewById(R.id.photo_button);
    mPhoto.bringToFront();
    mPhoto.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {

            mp.start();
            fullscreen.show();

            Intent intent = new Intent();

            // Picture from camera
            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);

            // This is not the right way to do this, but for some reason, having
            // it store it in
            // MediaStore.Images.Media.EXTERNAL_CONTENT_URI isn't working right.

            Date date = new Date();
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd-kk-mm-ss");

            String newPicFile = df.format(date) + ".jpg";
            String outPath =
                Environment.getExternalStorageDirectory()
                    + File.separator
                    + "CloudCameraBackup"
                    + File.separator
                    + newPicFile;
            File outFile = new File(outPath);

            mCameraFileName = outFile.toString();
            Uri outuri = Uri.fromFile(outFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outuri);
            Log.i(TAG, "Importing New Picture: " + mCameraFileName);
            try {
              startActivityForResult(intent, NEW_PICTURE);
            } catch (ActivityNotFoundException e) {
              showToast("There doesn't seem to be a camera.");
            }
          }
        });

    // This is the button to take a photo

    // Display the proper UI state if logged in or not
    setLoggedIn(mApi.getSession().isLinked());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
      mCameraFileName = savedInstanceState.getString("mCameraFileName");
    }

    // We create a new AuthSession so that we can use the Dropbox API.
    AndroidAuthSession session = buildSession();
    mApi = new DropboxAPI<AndroidAuthSession>(session);

    // Basic Android widgets
    setContentView(R.layout.main);

    checkAppKeySetup();

    mSubmit = (Button) findViewById(R.id.auth_button);

    mSubmit.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            // This logs you out if you're logged in, or vice versa
            if (mLoggedIn) {
              logOut();
            } else {
              // Start the remote authentication
              mApi.getSession().startAuthentication(DBRoulette.this);
            }
          }
        });

    mDisplay = (LinearLayout) findViewById(R.id.logged_in_display);

    // This is where a photo is displayed
    mImage = (ImageView) findViewById(R.id.image_view);

    // This is the button to take a photo
    mPhoto = (Button) findViewById(R.id.photo_button);

    mPhoto.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Intent intent = new Intent();
            // Picture from camera
            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);

            // This is not the right way to do this, but for some reason,
            // having
            // it store it in
            // MediaStore.Images.Media.EXTERNAL_CONTENT_URI isn't working
            // right.

            Date date = new Date();
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd-kk-mm-ss");

            String newPicFile = df.format(date) + ".jpg";
            String outPath = "/sdcard/" + newPicFile;
            File outFile = new File(outPath);

            mCameraFileName = outFile.toString();
            Uri outuri = Uri.fromFile(outFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outuri);
            Log.i(TAG, "Importing New Picture: " + mCameraFileName);
            try {
              startActivityForResult(intent, NEW_PICTURE);
            } catch (ActivityNotFoundException e) {
              showToast("There doesn't seem to be a camera.");
            }
          }
        });

    // This is the button to take a photo
    mRoulette = (Button) findViewById(R.id.roulette_button);

    mRoulette.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            DownloadRandomPicture download =
                new DownloadRandomPicture(DBRoulette.this, mApi, PHOTO_DIR, mImage);
            download.execute();
          }
        });

    // Display the proper UI state if logged in or not
    setLoggedIn(mApi.getSession().isLinked());
  }