/** @see android.app.Activity#onCreate(android.os.Bundle) */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    if (Log.DEBUG) {
      Log.v("GoogleContactsActivity: onCreate()  start");
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gcontactlist);
    mSyncCounter = (TextView) findViewById(R.id.sync_google_counter);

    Button syncButton = (Button) findViewById(R.id.start_sync_button);
    syncButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            sync();
          }
        });

    mDb = new DbAdapter(this);
    mDb.open(false);

    transport.setVersionHeader(GoogleContacts.VERSION);
    AtomParser atomParser = new AtomParser();
    atomParser.namespaceDictionary = GoogleContactsAtom.NAMESPACE_DICTIONARY;
    transport.addParser(atomParser);
    transport.applicationName = APP_NAME;
    HttpTransport.setLowLevelHttpTransport(ApacheHttpTransport.INSTANCE);
    Intent intent = getIntent();
    if (Intent.ACTION_SEND.equals(intent.getAction())) {
      if (Log.DEBUG) {
        Log.v("Intent.ACTION_SEND.equals( intent.getAction() )");
      }
      sendData = new SendData(intent, getContentResolver());
    } else if (Intent.ACTION_MAIN.equals(intent.getAction())) {
      if (Log.DEBUG) {
        Log.v("Intent.ACTION_MAIN.equals( intent.getAction() )");
      }
      sendData = null;
    }
    gotAccount(false);
    if (Log.DEBUG) {
      Log.v("GoogleContactsActivity: onCreate() stop");
    }
  }
示例#2
0
 public Shortener() {
   // setup up the HTTP transport
   HttpTransport transport = GoogleTransport.create();
   // add default headers
   GoogleHeaders defaultHeaders = new GoogleHeaders();
   transport.defaultHeaders = defaultHeaders;
   transport.defaultHeaders.put("Content-Type", "application/json");
   transport.addParser(new JsonHttpParser());
   request = transport.buildPostRequest();
   request.setUrl(GOOGL_URL);
 }
 private void authenticated() {
   if (Log.DEBUG) {
     Log.v("start authenticated");
   }
   if (sendData != null) {
     try {
       if (sendData.fileName != null) {
         boolean success = false;
         try {
           HttpRequest request = transport.buildPostRequest();
           request.url = new GenericUrl(GoogleContacts.ROOT_URL);
           GoogleHeaders.setSlug(request.headers, sendData.fileName);
           InputStreamContent content = new InputStreamContent();
           content.inputStream = getContentResolver().openInputStream(sendData.uri);
           content.type = sendData.contentType;
           content.length = sendData.contentLength;
           request.content = content;
           request.execute().ignore();
           success = true;
         } catch (IOException e) {
           handleException(e);
         }
         setListAdapter(
             new ArrayAdapter<String>(
                 this,
                 android.R.layout.simple_list_item_1,
                 new String[] {success ? "OK" : "ERROR"}));
       }
     } finally {
       sendData = null;
     }
   } else {
     fileList();
   }
   fillList();
   if (Log.DEBUG) {
     Log.v("end authenticated");
   }
 }