Exemplo n.º 1
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    this.deviceInfo = getDeviceInfoFromApplicationContext();

    StopWatch sw = new StopWatch();
    sw.start("create activity");

    createAnimation();
    buildFadeInPageViewAnimation();
    buildFadeOutPageViewAnimation();

    setProgressBarIndeterminateVisibility(false);
    System.out.println("debug on create");

    executor =
        new ThreadPoolExecutor(
            0, Integer.MAX_VALUE, 10L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
    sourceDB = new SourceDB(this);
    alarmSender = new AlarmSender(this);

    //        sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    //        acceleromererSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    //        createShakeListener();

    Cursor sourceCursor = sourceDB.findAll();

    startManagingCursor(sourceCursor);

    sourceAdapter =
        new SourceItemArrayAdapter<SourceItem>(this, R.layout.source_item, sourceDB, deviceInfo);

    TelephonyManager tManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    deviceId = tManager.getDeviceId();
    inflater = LayoutInflater.from(this);
    accountType = (String) getIntent().getExtras().get("type");
    sourceId = (String) getIntent().getExtras().get("sourceId");
    sourceImageURL = (String) getIntent().getExtras().get("sourceImage");
    sourceName = (String) getIntent().getExtras().get("sourceName");
    contentUrl = (String) getIntent().getExtras().get("contentUrl");

    //// System.out.println("sourceImageURL:" + sourceImageURL);
    setContentView(R.layout.main);
    container = (ViewGroup) findViewById(R.id.pageContainer);
    pageIndexView = (PageIndexView) findViewById(R.id.pageIndex);
    ViewSwitcher headerSwitcher = (ViewSwitcher) findViewById(R.id.flipper);
    header = (HeaderView) findViewById(R.id.header);
    contentImageButton = (ImageButton) findViewById(R.id.content);
    contentImageButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            overridePendingTransition(android.R.anim.slide_in_left, R.anim.fade);
            PageActivity.this.finish();
          }
        });
    //        pageInfo = (TextView)header.findViewById(R.id.pageInfo);
    headerText = (TextView) findViewById(R.id.headerText);
    headerImageView = (WebImageView) findViewById(R.id.headerImage);

    pageViewFactory = new WeiboPageViewFactory();

    preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    this.browseMode = getBrowseMode();
    //        this.animationMode = getAnimationMode();
    refreshingSemaphore = new Semaphore(1, true);
    Log.v("accountType", accountType);
    reload();
  }
Exemplo n.º 2
0
  protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    switch (id) {
      case PROMPT_OAUTH:
        builder
            .setMessage(R.string.commentneedsinaoauth)
            .setCancelable(false)
            .setPositiveButton(
                R.string.ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                    FlipdroidApplications application = (FlipdroidApplications) getApplication();
                    OAuth oauth = new OAuth();
                    application.setOauth(oauth);
                    //// System.out.println("OAuthHolder.oauth" + application + oauth);
                    oauth.RequestAccessToken(PageActivity.this, "flipdroid://SinaAccountSaver");
                  }
                })
            .setNegativeButton(
                R.string.cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {}
                });
        this.dialog = builder.create();
        break;
      case NAVIGATION:
        LayoutInflater li = LayoutInflater.from(this);
        View v = li.inflate(R.layout.dialog_nav_title_view, null);

        // builder.setView(v);
        builder.setCustomTitle(v);

        builder.setAdapter(
            sourceAdapter,
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = new Intent(PageActivity.this, PageActivity.class);
                SourceItem cursor = sourceAdapter.getItem(i);
                intent.putExtra("type", cursor.getSourceType());
                intent.putExtra("sourceId", cursor.getSourceId());
                intent.putExtra("sourceImage", cursor.getSourceImage());
                intent.putExtra("sourceName", cursor.getSourceName());
                intent.putExtra("contentUrl", cursor.getSourceURL());
                if (dialog != null) dialog.dismiss();
                startActivity(intent);
                finishActivity();
              }
            });

        this.dialog = builder.create();
        Button btn_addshortcut = (Button) v.findViewById(R.id.btnaddshortcut);
        btn_addshortcut.setText("add shortcut");

        btn_addshortcut.setOnClickListener(
            new Button.OnClickListener() {
              public void onClick(View v) {
                addShortcut();
                dialog.cancel();
              }
            });

        dialog.setOnKeyListener(
            new DialogInterface.OnKeyListener() {
              public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_MENU) {
                  if (dialog != null) {
                    dialog.dismiss();
                    return true;
                  }
                }

                return false;
              }
            });
        break;
      default:
        this.dialog = null;
    }
    if (dialog != null) {
      dialog.setOnDismissListener(
          new DialogInterface.OnDismissListener() {
            public void onDismiss(DialogInterface dialogInterface) {
              dialog = null;
            }
          });
    }
    return this.dialog;
  }